Code runs in Arduino IDE but not Platformio

I built a drum machine/sequencer using Teenst 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!

I have made this work, and in the process discovered a few things. Now sure where to report them so I’ll put everything here (@shensley anywhere else I should post this?)

  1. The default configuration when a new arduino project is created with PlatformIO does not work. It is necessary to add some configuration to platformio.ini. The key to getting debugging working was adjusting the level of optimization in a debug build.

  2. PlatformIO itself packages a very old version of the toolchain by default. This is no addressed by following the Daisy Wiki instructions to install the Daisy toolchain - more configuration in platformio.ini is needed.

  3. The board definition files are incorrect - the sizes of RAM and Flash are swapped. E.g. see .platformio/platforms/stm32/boards/electrosmith_daisy.json
    I’ll post an issue in Issues · platformio/platform-ststm32 · GitHub to cover this

For 1. and 2. your platformio.ini should look like the following

  • remove the USB lines if you don’t need USB serial suport
  • check the latest toolchain at PlatformIO Registry for version

---- platformio.ini ----

[env:electrosmith_daisy]

platform = ststm32

board = electrosmith_daisy

framework = arduino

lib_deps =

    Wire

build_flags = -w

    -D HAL_SDRAM_MODULE_ENABLED

    -D HAL_MDMA_MODULE_ENABLED

    -D HAL_DMA_MODULE_ENABLED

    -D INSTRUCTION_CACHE_ENABLE

    -D USBD_USE_CDC

    -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC

debug_build_flags =

    -Os -ggdb2 -g2

platform_packages =

    platformio/toolchain-gccarmnoneeabi@^1.100301.220327
1 Like

I have been able to get at least many of the DaisyDuino examples working in PlatformIO with this platform.ini which is a little bit simpler.

[env:electrosmith_daisy]
platform = ststm32
board = electrosmith_daisy
framework = arduino
; ----------
; Everything(?) below this needs to be added to use DaisyDuino in PlatformIO.
; Setting up a new project or importing from Arduino does not add any of this.
; ----------
lib_deps = electro-smith/DaisyDuino@^1.5.2
build_flags = 
    ; -w                            ; optional - to suppress redundant definition warnings
    -D HAL_SDRAM_MODULE_ENABLED     ; required? build fails without this one
    ; These flags enable serial monitor over USB UART
    -D USBD_USE_CDC                 ; Define USB Communications Device Class (for serial I/O)
    -D USBCON                       ; Enable USB connection in Arduino (?)
; This is not documented on PlatformIO website but
; enables the DFU firmware upload (over USB)
upload_protocol = dfu

The last two flags were both required for me to get the USB serial monitoring working. Without them, attempting to use Arduino Serial interface eventually causes the program to crash/hang.

I’m not totally sure about the necessity of some of the other HAL flags as well as the instruction cache flag. At least the examples I’ve tried so far from DaisyDuino’s built in examples seem to work :man_shrugging: