LinuxCommandLibrary

st-util

Debug and flash STM32 microcontrollers

TLDR

Run GDB server on port 4500

$ st-util [[-p|--listen_port]] [4500]
copy

Connect to GDB server
$ (gdb) target extended-remote [localhost]:[4500]
copy

Write firmware to device
$ (gdb) load [firmware.elf]
copy

SYNOPSIS

st-util [options]

PARAMETERS

-h, --help
    Help: Displays the usage information.

-v, --version
    Version: Shows the version of the st-util program.

-c , --connect=
    Connect: Connect to a specific ST-LINK debugger.
id is the serial number of the ST-LINK.

-p , --port=
    Port: Specifies the TCP port for the GDB server (default: 4242).

-n, --no-reset
    No Reset: Prevents the target device from being reset after connecting.

-w , --flash=
    Flash: Flashes the specified (usually a .bin or .hex file) to the target device.

-s

, --start=

    Start: Sets the starting address for execution after flashing.
address specifies the address in memory.

-r, --reset
    Reset: Resets the target device after programming.

-l , --verbose=
    Verbose: Sets the verbosity level. Higher values provide more detailed output.

-m, --disable-hla
    Disable HLA: Disables Hardware Lockup Avoidance.

--verbose
    Verbose: Enables verbose mode.

DESCRIPTION

The `st-util` command provides a command-line interface (CLI) for interacting with STMicroelectronics ST-LINK debuggers/programmers. It facilitates tasks like flashing firmware to STM32 microcontrollers, debugging, reading/writing memory, and performing other device-specific operations. It's a crucial tool for developers working with STM32 embedded systems, enabling them to program, test, and debug their applications efficiently. This utility typically communicates with the target device through the ST-LINK hardware interface, and is often used as a standalone tool or integrated into build and debugging workflows.

CAVEATS

Proper ST-LINK drivers and the st-util package need to be installed for the tool to function correctly. The address specified by `-s` must be a valid address in the target's memory map. When using `--flash` or similar options, ensure the file format is compatible with the target device.

GDB SERVER

st-util runs a GDB server, allowing a GDB client to connect and debug the target device. The GDB server listens on a TCP port (default: 4242). GDB can be connected using `target remote localhost:4242`.

FLASHING CONSIDERATIONS

When flashing, st-util automatically handles erasing the necessary flash sectors before writing the new firmware. However, for more complex scenarios, manually erasing sectors might be necessary using other utilities or through custom scripting.

HISTORY

The `st-util` utility is part of the larger ST-LINK software ecosystem developed by STMicroelectronics. It evolved to provide a more flexible and scriptable alternative to GUI-based tools for programming and debugging STM32 microcontrollers. Over time, it has been improved with enhanced debugging capabilities, support for newer ST-LINK versions, and improved command-line options. It's widely used in embedded development environments, especially within open-source projects and CI/CD pipelines.

SEE ALSO

gdb(1)

Copied to clipboard