2023-05-21 12:18 AM
Hi, I need to control Stlink form python code.
1) On some PC I am not able to connect with STLink to my MCU - I tried STM32CubeProg and ST-Link utility. The Error is UR connection mode is defined with the HWrst reset mode.
But why on the same PC the STM32CubeIde can without problem load the program to the MCU? What kinds of "API" STM32CubeIde use? I want these API - because always works!
I have not connected RESET pin - but it should not be problem hope
2) On the PC when I am able to connect to MCU VIA STM32CubeProgrammer - I also can use STM32CubeProg cli interface to conrol it via python. But is not there something different? Because STM32Cubeprogrammer is too large (about 700 MB on disk?) I also tried ST_Link utitliy - cli, but it was not much reliable.
Thank you very much.
Solved! Go to Solution.
2023-06-01 11:43 AM - edited 2023-11-20 05:00 AM
Sometimes an STLink is able to identify the chip it is connected to, and sometimes not. I think it only works for STLinks that are embedded into a dev board, like one of the Nucleo boards.
For instance, I have an NUG431KB Nucleo board. When I plug it into my computer via USB (and thus am using its embedded STLink), I can get the following:
pyocd pack install stm32g4
# Lots of output, errors and warnings are usually fine
pyocd list
# Probe/Board Unique ID Target
# ------------------------------------------------------------------
# 0 STLINK-V3 002700044D4B500A20373831 ✔︎
# stm32g431kbtx
# NUCLEO-G431KB
2023-05-21 05:59 PM
What are you trying to do with the STLink from Python? Depending on your use case, pyOCD can be a great option. https://pyocd.io/
2023-05-22 12:58 AM
>I have not connected RESET pin - but it should not be problem hope
no problem, but you have to set "software system reset" .
>Error is UR connection mode is defined with the HWrst reset mode
set software system reset !
2023-05-22 01:05 AM
Yes I did it, but nothing changed
2023-05-23 02:34 AM
Looks good, Is there any nice example (I didn't find much)? I just want to erase and load new .bin file to the flash memory of STM32
2023-05-27 05:49 AM
Hi thank you, I want to use pyOCD but I really do not understand the doccumentaion:
1) How to check if any MCU is connected to the STlink? Would be great if it returns me specifi name of the MCU like STM32F303RBTx
really do not why it does not know command status
2) I Want to erase and flash MCU
3) I want to read and write to the specific memory location
There is list of all commands, which I found: https://pyocd.io/docs/command_reference.html
Can you help with it please?
2023-06-01 11:43 AM - edited 2023-11-20 05:00 AM
Sometimes an STLink is able to identify the chip it is connected to, and sometimes not. I think it only works for STLinks that are embedded into a dev board, like one of the Nucleo boards.
For instance, I have an NUG431KB Nucleo board. When I plug it into my computer via USB (and thus am using its embedded STLink), I can get the following:
pyocd pack install stm32g4
# Lots of output, errors and warnings are usually fine
pyocd list
# Probe/Board Unique ID Target
# ------------------------------------------------------------------
# 0 STLINK-V3 002700044D4B500A20373831 ✔︎
# stm32g431kbtx
# NUCLEO-G431KB
2023-06-01 11:47 AM
If you give pyocd an object file, like an Intel `.hex` file or an ELF file, it can figure out at which addresses to write automatically. When using a binary file, you need to supply a base address manually. Take a look at the help output of `pyocd flash --help`. The relevant argument is:
-a ADDR, --base-address ADDR
Base address used for the address where to write a binary. Defaults to
start of flash. Only allowed if a single binary file is being loaded.
So you will need to use the `-a` argument if you want to write the binary somewhere other than address `0`.
2023-06-01 11:49 PM
Thank you. I see my STlink is not able to recognize connected mcu.
The flashing seems to work!
2023-06-09 02:24 AM
Intersting:
I have Jlink and STlink, I loaded hex file to the STM32 like that: pyocd load -t STM32h743zGTx ADC7771.hex
1) thorough Jlink - it erase, flash and finally run the code
2) thorought STlink - it erase, flash but finally the code is not running - why?
I still do not understand the documentation well. E.G. I want to find out status of target:
So i tried pyocd --target st - but it does not work, so how should the command looks like?
like is writte here: https://pyocd.io/docs/command_reference.html#status