Can't load to Nucleo_f303k8

Trying out PlatformIO for the 1st time I am having problems uploading to a module. No doubt I am missing some setting.

ST-Link seems correctly connected, and COM4 appears to work. The test program compiles. This board works ok on the ARM compiler IDE.

Any suggestion would be appreeciated.

Terminal output is:

Uploading .pio\build\nucleo_f303k8\firmware.elf
xPack Open On-Chip Debugger 0.12.0-01004-g9ea7f3d64-dirty (2023-01-30-15:04)
Licensed under GNU GPL v2
For bug reports, read
OpenOCD: Bug Reporting
debug_level: 1

srst_only separate srst_nogate srst_open_drain connect_deassert_srst

[stm32f3x.cpu] halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08000300 msp: 0x20003000
** Programming Started **
Warn : Adding extra erase range, 0x08007c30 … 0x08007fff
Error: error writing to flash at address 0x08000000 at offset 0x00000000
embedded:startup.tcl:1516: Error: ** Programming Failed **
in procedure ‘program’
in procedure ‘program_error’ called at file “embedded:startup.tcl”, line 1581
at file “embedded:startup.tcl”, line 1516
*** [upload] Error 1
=========================== [FAILED] Took 7.87 seconds ===========================

Can you unprotect the whole flash just to be sure? Use How to unlock STM32F0x using OpenOCD - TechOverflow but with target/stm32f3x.cfg instead. The stm32f1x unlock 0 part has to stay the same however.

Thanks. openocd gives the following. What actually is the idcode?

Info : clock speed 1000 kHz
Info : STLINK V2J42M27 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.240000
Warn : UNEXPECTED idcode: 0x2ba01477
Error: expected 1 of 1: 0x0bb11477

Usually that’s a –

can you show a picture of your board?

I got this board from Mouser!
Thanks for your help. I will order one from ST.

Hi there,

I also got the Nucleo_f303k8 board with legit STM32F103 STLink, but the same error message, if I use upload_protocol = stlink.
Error: error writing to flash at address 0x08000000 at offset 0x00000000.
The adress changes dependet if the code changes.

I didnt got the unexpected idcode, because I cant reproduce the unlocking procedure.

I can at least upload programms to the board via:

[env:nucleo_f303k8]
platform = ststm32
board = nucleo_f303k8
framework = arduino
upload_protocol = mbed

A new question rises: How to debug using the onboard STLink. If I append debug_tool = stlink the programm compiles successful, but the terminal wont show the mbed upload procedure unlike in “regulare” Upload. 3 seconds later the STLink LEDs blink like in the programming procedure but stops 1 sec after it. No Debugger window (Step into, Step over,…) ever appear.

Anyone ideas how to start the Debugger?

I gave up on PlatformIO for this application. Mbed Studio works ok.

Hi there,

I have the same issue, but only on my Ubuntu setup (VScode with latest pio --dev) it uses OpenOCD v12 as described in the first post of this thread.
Only upload_protocol = mbed works

I have another setup on MacOS, but it uses OpenOCD v11, and it works great with upload_protocol = stlink

(I am using f303k8 too)

I have the same issue:

** Programming Started **
Warn : Adding extra erase range, 0x0800325c .. 0x080037ff
Error: error writing to flash at address 0x08000000 at offset 0x00000000
embedded:startup.tcl:1516: Error: ** Programming Failed **
in procedure 'program'
in procedure 'program_error' called at file "embedded:startup.tcl", line 1581
at file "embedded:startup.tcl", line 1516
*** [upload] Error 1

If I take the firmware.elf and upload it via STM32CubeProgrammer it works fine.

I replaced everything in .platformio\packages\tool-openocd with the v11 release from here, it works now.