ST-LINK Interface
The ST-LINK Interface is used to connect to a physical ST-LINK debugger and is used mainly for flashing firmware.
Provide an interface to interact with ST-LINK using STM32CubeProgrammer CLI through a Python interface
STLinkInterface
Represents an instance of a ST-LINK Debugger
Methods:
Name | Description |
---|---|
__init__ |
Create a new ST-LINK instance. Note that this constructor does not attempt to communicate to the ST-LINK; that is done |
download |
Download a file onto the target device via the ST-LINK. |
erase_all |
Erase the entire flash of the target device. |
erase_sector_range |
Erase a range of sectors on the target device. |
erase_sectors |
Erase a list of sectors on the target device. |
run_commands |
Run a series of STM32CubeProgrammer CLI commands as you would find in a script file. |
start |
Enables execution of the device memory starting from the specified address. |
__init__(port='SWD', freq=4000, reset='SWrst', mode='NORMAL')
Create a new ST-LINK instance. Note that this constructor does not attempt to communicate to the ST-LINK; that is done on subsequent function calls.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
port
|
str
|
Interface via which to connect to the target (defaults to SWD) |
'SWD'
|
freq
|
int
|
Frequency (in kHz) used in connection (defaults to 4000 KHz for SWD port) |
4000
|
reset
|
str
|
Reset mode. Possible values are {SWrst/HWrst/Crst} (defaults to SWrst). When using UR connection mode, the reset mode is HWrst. |
'SWrst'
|
mode
|
str
|
Connection mode. Possible values are {NORMAL/UR/HOTPLUG} (defaults to NORMAL). |
'NORMAL'
|
download(file_path, start_address, verify=False, reset=None, mode=None, logfile=None)
Download a file onto the target device via the ST-LINK. require an offset address. Note that this function only supports .bin files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str
|
Path of the file to be downloaded |
required |
start_address
|
int
|
Start address of download |
required |
verify
|
bool
|
Whether to verify the download after completion |
False
|
reset
|
str
|
Optional reset mode to override the default (SWrst). Possible values are {SWrst/HWrst/Crst}. When using UR connection mode, the reset mode is HWrst. |
None
|
mode
|
str
|
Optional connection mode to override the default (NORMAL). Possible values are {NORMAL/UR/HOTPLUG}. |
None
|
logfile
|
str
|
Optional path to a file to log the output of the commands |
None
|
Returns:
Type | Description |
---|---|
bool
|
Status of operation (True on success, False otherwise) |
erase_all(reset=None, mode=None, logfile=None)
Erase the entire flash of the target device.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reset
|
str
|
Optional reset mode to override the default (SWrst). Possible values are {SWrst/HWrst/Crst}. When using UR connection mode, the reset mode is HWrst. |
None
|
mode
|
str
|
Optional connection mode to override the default (NORMAL). Possible values are {NORMAL/UR/HOTPLUG}. |
None
|
logfile
|
str
|
Optional path to a file to log the output of the commands |
None
|
Returns:
Type | Description |
---|---|
bool
|
Status of operation (True on success, False otherwise) |
erase_sector_range(start, end, reset=None, mode=None, logfile=None)
Erase a range of sectors on the target device.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
int
|
Start sector to erase |
required |
end
|
int
|
End sector to erase |
required |
reset
|
str
|
Optional reset mode to override the default (SWrst). Possible values are {SWrst/HWrst/Crst}. When using UR connection mode, the reset mode is HWrst. |
None
|
mode
|
str
|
Optional connection mode to override the default (NORMAL). Possible values are {NORMAL/UR/HOTPLUG}. |
None
|
logfile
|
str
|
Optional path to a file to log the output of the commands |
None
|
Returns:
Type | Description |
---|---|
bool
|
Status of operation (True on success, False otherwise) |
erase_sectors(sectors, reset=None, mode=None, logfile=None)
Erase a list of sectors on the target device.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sectors
|
list[int]
|
List of sectors to erase |
required |
reset
|
str
|
Optional reset mode to override the default (SWrst). Possible values are {SWrst/HWrst/Crst}. When using UR connection mode, the reset mode is HWrst. |
None
|
mode
|
str
|
Optional connection mode to override the default (NORMAL). Possible values are {NORMAL/UR/HOTPLUG}. |
None
|
logfile
|
str
|
Optional path to a file to log the output of the commands |
None
|
Returns:
Type | Description |
---|---|
bool
|
Status of operation (True on success, False otherwise) |
run_commands(commands, logfile=None)
Run a series of STM32CubeProgrammer CLI commands as you would find in a script file. Example commands are -c, -e, -w, etc. Each element in the array is a command and its arguments, for example: commands = ['-c port=SWD freq=4000', '-e 0 1', '-w32 0x08000000 0xAAAAAAAA']
Commands can be found at https://www.st.com/resource/en/user_manual/um2237-stm32cubeprogrammer-software-description-stmicroelectronics.pdf.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
commands
|
list[str]
|
List of commands to execute |
required |
logfile
|
str
|
Optional path to a file to log the output of the commands |
None
|
Returns:
Type | Description |
---|---|
bool
|
Status of operation (True on success, False otherwise) |
start(start_address, reset=None, mode=None, logfile=None)
Enables execution of the device memory starting from the specified address.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_address
|
int
|
Start address of application to be executed. |
required |
reset
|
str
|
Optional reset mode to override the default (SWrst). Possible values are {SWrst/HWrst/Crst}. When using UR connection mode, the reset mode is HWrst. |
None
|
mode
|
str
|
Optional connection mode to override the default (NORMAL). Possible values are {NORMAL/UR/HOTPLUG}. Default value is NORMAL. |
None
|
logfile
|
str
|
Optional path to a file to log the output of the commands |
None
|
Returns:
Type | Description |
---|---|
bool
|
Status of operation (True on success, False otherwise) |