STM32 code works in Arduino IDE but not PIO

[cross-posted from the Electrosmith forum Code runs in Arduino IDE but not Platformio - Software Development - Daisy Forums]

TL;DR: code built in PIO does not run as expected.

I built a drum machine/sequencer using Teensy and VS1053 which I am now trying to move to Daisy Seed. The new code is here: GitHub - ukmaker/BassMate

My issue is that the code so far (which does nothing useful yet) works in Arduino IDE, but in PlatformIO it does not. Specifically

  • it runs more slowly
  • after the first time the I2C input device is sampled that code somehow creates a fault and never runs again

Additionally, it is impossible to create a new Arduino project using PlatformIO which either builds correctly or can be debugged using PlatformIO. I can add some defines to platformio.ini to make it build, but to debug I have to launch an ST-Link session from VSCode directly. I get the same results on Windows and Mac.

Anyone know how to get PlatformIO to work? I could really do with having the debugger work!

What version of the Arduino-STM32 core are you using in the Arudino IDE?

Can you post a screenshot of the Tools submenu that shows all your Arduino IDE settings for the sketch?

Have you tried pinning the exact used versions in

so, a removal of the ^ operator to get the exact version (instead of minor + patch being able to go higher)

STM32 is 2.2.0

I have tried adding various things to my platformio.ini to no effect. It currently looks like this:

platform = ststm32
board = electrosmith_daisy
framework = arduino
lib_extra_dirs = ~/Documents/Arduino/libraries
build_flags = -w
    --param max-inline-insns-single=500
debug_port = COM8
debug_tool = stlink
build_type = debug

And as you can see, I’m pointing directly at the Arduino libs from platformio (not quite what is in github, sorry)

8 days ago platform-ststm32 was updated to support core 2.2.0. Can you do a CLIpio platform update ststm32 and rebuild the project, and make sure that the PLATFORM version in the output is 15.3.0?

That prevents debugging, no port is needed when debug_tool is STLink, debugging goes over the USB device, not a COM port.

Good call! Fixes the debugging issue.

I’ve just run pio update and got new versions (I was sure I’d done that before… hey ho) - but the code still doesn’t run properly.

$ pio platform update ststm32
Platform ststm32

Updating platformio/ststm32 15.3.0 [Up-to-date]
Updating platformio/toolchain-gccarmnoneeabi 1.70201.0 @ >=1.60301.0,<1.80000.0 [Up-to-date]
Updating platformio/framework-cmsis 2.50501.200527 @ ~2.50501.0 [Up-to-date]
Updating platformio/framework-arduinoststm32 4.20200.220204 @ ~4.20200.0 [Up-to-date]
Updating platformio/framework-stm32cubeh7 1.9.0 @ ~1.9.0 [Up-to-date]
Updating platformio/tool-stm32duino 1.0.2 @ ~1.0.1 [Up-to-date]
Updating platformio/tool-openocd 2.1100.211028 @ ~2.1100.0 [Up-to-date]
Updating platformio/tool-jlink 1.75001.0 @ ^1.63208.0 [Up-to-date]
Updating platformio/tool-dfuutil 1.9.200310 @ ~1.9.190708 [Up-to-date]
Updating platformio/tool-ldscripts-ststm32 0.2.0 @ ~0.2.0 [Up-to-date]

when I paus the debugger once the code has started misbehaving (i.e. I’ve clicked the button once) I generally see this


I see a suspicous looking fix commit in Wire: implement Clear Bus sequence to recover I2C bus. · stm32duino/Arduino_Core_STM32@51fc604 · GitHub.

Can you add

platform_packages =

to your platformio.ini so that it pulls the current git version of the core? Is it still buggy?

EDIT Typo fixed

and looking at i2c_master_write the local tickstart will be stuck at one value between pause/unpause - i.e. it looks like the underlying timer has stopped for some reason

doesn’t build

There’s an i missing in the package name, please see updated code above.

I saw that. The name seems to be cached somewhere

Try removing the framework-ardunoststm32 folder from <home folder>/.platformio/packages. If in doubt, remove every folder in there and rebuild.

Deleted the entire folder. Uninstalled and reinstalled VSCode and platformio. No change.

That’s weird, remove the C:\Users\<user>\.platformio folder, then it should 100% be clean and recovered after a VSCode restart. Or it’s the C:\Users\<user>\.platformio\.cache folder.

Tried that :frowning: really tried to clean everything.
I’m now firing up a Linux VM to see what happens

o_O That can’t be. If you uninstalled the PlatformIO VSCode extension, removed the .platformio folder, reinstalled the VSCode extension you should be back to a clean PlatformIO installation that can at least build an Arduino Uno blinky firmware.

it’ll build and run blinky OK, just not run my code properly

Okay well then we’re back to the start where we can build but have the same bugs.

I noticed you have

Which will cause debug optimization (-Og) and can definitely slow things down. Is it the same when you remove that line?

If not, revert back to platformio.ini

platform = ststm32
board = electrosmith_daisy
framework = arduino
lib_extra_dirs = ~/Documents/Arduino/libraries
build_flags =
debug_tool = stlink

In your Arduino IDE, can you go File → Preferences → Tick “Verbose Compilation” + “Verbose Upload”, then recompile the sketch. (Might need cleaning out %TEMP% files to trigger rebuild).

Then copy all compiler output in a textfile and upload it somewhere (, github,…).

Then go in a CLI and do

pio run -t clean
pio run -v > build.log 2>&1 

(assuming Windows.) and upload that build.log too.