First steps with STEM32F401 and PlatformIO not working

Hello!

Until now, I’ve developed my programs using the Arduino IDE and an ESP32 or Arduino UNO. Now I have a custom board with an ST32F401RDT6 and want to work with PlatformIO on it in the future.

To test the toolchain, I first tried it out using the Arduino IDE.
(I can’t paste more than one picture, since I am new here)

With this configuration, I can compile and load the typical Blink program. It runs.

Now I’ve closed the Arduino IDE and repeated the process with PlatformIO.
It doesn’t run, but with the information I have, I can’t find any errors.

Processing genericSTM32F401RC (platform: ststm32; board: genericSTM32F401RC; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/genericSTM32F401RC.html
PLATFORM: ST STM32 (19.4.0) > STM32F401RC (64k RAM. 256k Flash)
HARDWARE: STM32F401RCT6 84MHz, 64KB RAM, 256KB Flash
DEBUG: Current (stlink) External (blackmagic, jlink, stlink)
PACKAGES:
 - framework-arduinoststm32 @ 4.21100.0 (2.11.0)
 - framework-cmsis @ 2.50900.0 (5.9.0)
 - tool-dfuutil @ 1.11.0
 - tool-dfuutil-arduino @ 1.11.0
 - tool-openocd @ 3.1200.0 (12.0)
 - tool-stm32duino @ 1.0.2
 - tool-stm32flash @ 0.7.0
 - toolchain-gccarmnoneeabi @ 1.120301.0 (12.3.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 15 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio\build\genericSTM32F401RC\src\main.cpp.o
Checking size .pio\build\genericSTM32F401RC\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   1.8% (used 1156 bytes from 65536 bytes)
Flash: [          ]   4.4% (used 11656 bytes from 262144 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, dfu, jlink, serial, stlink
CURRENT: upload_protocol = stlink
Uploading .pio\build\genericSTM32F401RC\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
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 1

hla_swd
[stm32f4x.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x1fff4346 msp: 0x20002560
** Programming Started **
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
shutdown command invoked
============================================================================== [SUCCESS] Took 3.93 seconds ==============================================================================
 *  Terminal will be reused by tasks, press any key to close it.

The LED isn’t blinking. I also tried testing it in debug mode. I get a debug window, but no way to run the code.

Does anyone have any idea what could be causing this?
Thanks and regards, Hans-Joachim

Continue
here the configuration of the ARDUINO IDE:

Press the “Pause” button there. Where does it stop? What’s the call stack?

Is it a RDT6 (doesn’t exist?) or a RCT6?

Hello maxgerhardt,

sorry, I had a typo: STM32F401RCT6 is the uP type.

After pressing “Start Debugging” the code is compiled and uploaded. Than the dissassembly window pops up, for a short time I can see a yellow corsor left to line 61.

The call stack window is empty, there ist a hint: Pases on exception.

After pressing stop in the debug window the callstack window shows “unknown source”. After this I can perfom a single step - but I assume the processor is not running a normal program, I can see adresses around 0x1fff0610.

Regards
Hans-Joachim

That would mean your microcontroller is running the builtin bootloader code from system memory.

Did you use a pullup or pulldown on the BOOT0 and BOOT1 pins of the STM32 chip on your custom board, or are they just floating in the wind, unconnected? What voltage are these pins on with respect to GND at the moment? They should all be 0V to run the regular flash firmware after a reset.

:cry: :cry: :cry:
I have a resistor connected to ground at BOOT0 and a jumper to connect it to Vcc.

This jumper was already in place—I didn’t change it.

First, I tested it with the Arduino environment—everything worked perfectly, and the test program functioned as expected.

However, the test with PlatformIO didn’t work.

That was my mistake; I hadn’t checked that pin. After removing the jumper, everything worked as expected. What I’ll never understand is why it worked with the Arduino environment even though the jumper was incorrectly set. I tried switching it back and forth at least two or three times.

Thank you so much for your help!

Best regards, Hans-Joachim

Remember, in the Arduino IDE you selected the upload method “STM32CubeProgrammer (SWD)”, but PlatformIO is using OpenOCD. The STM32CubeProgrammer uploader might reset the STM32 chip in a different way, such as directly setting the PC to 0x8000000 (flash) and letting it run, while OpenOCD is configured for a software reset via SWD (essentially NVIC_SystemReset()) or a hardware reset; With that reset method, the BOOT0 and BOOT1 pin might get evaluated and the chip might go into bootloader mode.

1 Like