PlatformIO Community

Error on uploading to stm32 through st-link

Hello everyone, I recently started working on a nucleo F091rc. My problem is that at the moment I cannot flash it using a st-link v2 with platformio on VSCode.

From the command line, platformio does not list the device (platformio device list). Instead with (st-info --probe) I get some informations:

Found 1 stlink programmers
version: V2J40S7
serial: 53FF6A068389505228432467
flash: 262144 (pagesize: 2048)
sram: 32768
chipid: 0x0442
descr: F09X

I am using a Mac m1 with MacOS Ventura. This is the list I get from the dependencies section:

Resolving nucleo_f091rc dependencies…
Platform ststm32 @ 15.4.1 (required: ststm32)
├── framework-arduinoststm32 @ 4.20200.221104 (required: platformio/framework-arduinoststm32 @ ~4.20200.0)
├── framework-cmsis @ 2.50700.210515 (required: platformio/framework-cmsis @ ~2.50700.0)
├── framework-cmsis-stm32f0 @ 2.3.4 (required: platformio/framework-cmsis-stm32f0 @ ~2.3.4)
├── framework-stm32cubef0 @ 1.11.3 (required: platformio/framework-stm32cubef0 @ ~1.11.0)
├── framework-stm32cubef1 @ 1.8.4 (required: platformio/framework-stm32cubef1 @ ~1.8.0)
├── framework-stm32cubef2 @ 1.9.3 (required: platformio/framework-stm32cubef2 @ ~1.9.0)
├── framework-stm32cubef4 @ 1.26.2 (required: platformio/framework-stm32cubef4 @ ~1.26.0)
├── tool-dfuutil @ 1.11.0 (required: platformio/tool-dfuutil @ ~1.11.0)
├── tool-ldscripts-ststm32 @ 0.2.0 (required: platformio/tool-ldscripts-ststm32 @ ~0.2.0)
├── tool-openocd @ 2.1100.211028 (required: platformio/tool-openocd @ ~2.1100.0)
├── tool-stm32duino @ 1.0.1 (required: platformio/tool-stm32duino @ ~1.0.1)
└── toolchain-gccarmnoneeabi @ 1.90201.191206 (required: platformio/toolchain-gccarmnoneeabi @ ~1.90201.0)

└── STM32duino FreeRTOS @ 10.3.1 (required: stm32duino/STM32duino FreeRTOS @ ^10.3.1)

The following is the error that I get from flashing the device. When flashing the light on the st-link blinks yellow and red.

Executing task: platformio run --verbose --target upload --environment nucleo_f091rc

Processing nucleo_f091rc (upload_speed: 9600; board: nucleo_f091rc; lib_deps: stm32duino/STM32duino FreeRTOS@^10.3.1; upload_protocol: stlink; debug_tool: stlink; platform: ststm32; framework: arduino; monitor_speed: 115200; upload_flags: -c, reset_config none separate)

CONFIGURATION: Redirecting...
PLATFORM: ST STM32 (15.4.1) > ST Nucleo F091RC
HARDWARE: STM32F091RCT6 48MHz, 32KB RAM, 256KB Flash
DEBUG: Current (stlink) On-board (stlink) External (blackmagic, cmsis-dap, jlink)

  • framework-arduinoststm32 @ 4.20200.221104 (2.2.0)
  • framework-cmsis @ 2.50700.210515 (5.7.0)
  • tool-dfuutil @ 1.11.0
  • tool-openocd @ 2.1100.211028 (11.0)
  • tool-stm32duino @ 1.0.1
  • toolchain-gccarmnoneeabi @ 1.90201.191206 (9.2.1)
    LDF: Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 13 compatible libraries
    Scanning dependencies…
    Dependency Graph
    |-- STM32duino FreeRTOS @ 10.3.1 (License: Unknown, Path: /Users/beppemarinelli/Documents/PlatformIO/Projects/Freerduino_try1/.pio/libdeps/nucleo_f091rc/STM32duino FreeRTOS)
    Building in release mode
    MethodWrapper([“checkprogsize”], [".pio/build/nucleo_f091rc/firmware.elf"])
    Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
    RAM: [ ] 4.2% (used 1376 bytes from 32768 bytes)
    Flash: [= ] 7.8% (used 20500 bytes from 262144 bytes)
    .pio/build/nucleo_f091rc/firmware.elf :
    section size addr
    .isr_vector 188 134217728
    .text 18180 134217920
    .rodata 2176 134236100
    .ARM.extab 0 134238276
    .ARM 0 134238276
    .preinit_array 0 134238276
    .init_array 16 134238276
    .fini_array 8 134238292
    .data 144 536870912
    .bss 1232 536871056
    .noinit 0 536872288
    ._user_heap_stack 1536 536872288
    .ARM.attributes 40 0
    .comment 102 0
    .debug_frame 1076 0
    Total 24698
    ([“upload”], [".pio/build/nucleo_f091rc/firmware.elf"])
    AVAILABLE: blackmagic, cmsis-dap, jlink, mbed, stlink
    CURRENT: upload_protocol = stlink
    openocd -c “reset_config none separate” -d2 -s /Users/beppemarinelli/.platformio/packages/tool-openocd/scripts -f board/st_nucleo_f0.cfg -c “program {.pio/build/nucleo_f091rc/firmware.elf} verify reset; shutdown;”
    xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-10-17-00:18)
    Licensed under GNU GPL v2
    For bug reports, read
    debug_level: 2

none separate

Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
srst_only separate srst_nogate srst_open_drain connect_deassert_srst

Info : clock speed 1000 kHz
Info : STLINK V2J40S7 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.229062
Info : stm32f0x.cpu: Cortex-M0 r0p0 processor detected
Info : stm32f0x.cpu: target has 4 breakpoints, 2 watchpoints
Info : starting gdb server for stm32f0x.cpu on 3333
Info : Listening on port 3333 for gdb connections
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Error: timed out while waiting for target halted
embedded:startup.tcl:1070: Error: ** Unable to reset target **
in procedure ‘program’
in procedure ‘program_error’ called at file “embedded:startup.tcl”, line 1107
at file “embedded:startup.tcl”, line 1070
*** [upload] Error 1

This is my platformio.ini:

platform = ststm32
framework = arduino

board = nucleo_f091rc
lib_deps = stm32duino/STM32duino FreeRTOS@^10.3.1
upload_protocol = stlink
debug_tool = stlink

I am really stuck and everything I try doesn’t seem to get me anywhere. Any help is really appreciated!

But the st_nucleo_f0.cfg already says

Is this default wrong for your board? It still does not work when you remove the upload_flags from your platformio.ini?

hey max, thanks for the fast reply. I was in the middle of modifying that part in my post.
tbh I added that just in case.
Indeed, also removing that doesn’t seem to flash. Same error :frowning:

Quick sanity check: If you have st-flash globally installed, add

upload_protocol = custom
upload_command = st-flash write $SOURCE 0x8000000

to the platformio.ini. Does flashing work now?

1 Like

This works!! Thank you so much Max :slight_smile:
Could you explain me a little bit more what is going on in your opinion?

I’m not sure. That was only supposed to be a test though.

Does your firmware use the SWD pins of the MCU? (PA14 + PA15 I think)

Does your firmware immediately go into a deep-sleep mode?

Since this morning I have been running few tests and I have not been able to do much. The custom board with the Nucleo does not have a build in led, and all scripts I am flashing don’t really seem to work. Serial monitor is always empty.

Does your firmware use the SWD pins of the MCU? (PA14 + PA15 I think)


Does your firmware immediately go into a deep-sleep mode?

I have a feeling it does but how could I check for this?
Thank you for your help!!

Well that’s not good if your firmware reconfigures them for GPIO. Can you chose different pins?

Thanks @maxgerhardt for the help. I think I will first try to understand the board better. It seems to flash in the right address but now I need to check the pins and try to get some serial back. I discovered the pins for the SWD are PA13 and PA14.
Again, thanks for the help and I will come back here if I find a solution! :slight_smile: