koendv/STM32duino-Semihosting

possible with st-link and platformio

zerog2k opened this issue · 7 comments

I can get swd debugging working (I think it's though openocd?) in vscode + platformio, using an st-link adapter.

I'm using

[env:genericSTM32F103C8]
platform = ststm32
board = genericSTM32F103C8
framework = arduino
lib_deps = 
    STM32duino-Semihosting
debug_tool = stlink
upload_protocol = stlink

in my platformio.ini along with the example blink sketch in this repo.
I'm not sure if there are other steps required here to get this working. Wondering if anyone has ideas or pointers?

ok this might be related
platformio/platformio-core#3516

ok confirming that this works using the workarounds on
platformio/platform-ststm32#272
specifically, running separate openocd (can be run via tasks in one of the pio terminal windows as discussed in the issue), and using this config:

[env:genericSTM32F103C8]
platform = ststm32
board = genericSTM32F103C8
framework = arduino

lib_deps = 
    STM32duino-Semihosting
upload_protocol = stlink
debug_extra_cmds =
    monitor arm semihosting enable
;debug_tool = stlink    
debug_tool = custom
debug_port = :3333

Glad to hear it works.

I created a very simple and easy to use pre-configured project to make semihosting work for an STM32 bluepill board.
Please have a look https://github.com/mohalsa/STM32_BluePill_Semihosting

This is the wiring diagram. Just ignore the optional "Enable hardware reset mode" line!
Also, I noticed that sometimes the debugging session becomes unreliable, glitchy and might not even work, In such cases try to connect the 5V power line from the Stlink debugger to the 5V Vcc of the bluepill and don't use the 3.3V Vcc to power the bluepill. I don't know what might be the reason, probably insufficient power or ripples etc. please do not connect them both at once, It might damage your board!

bluepill_connections_stlink

(Image credits: https://www.onetransistor.eu/2020/01/stm32-bluepill-arduino-support.html)