Translating Arduino settings for STM32 board

Hey All,
I have been moving all my projects from Arduino over to PIO on mac. What an awesome IDE! I hit a bit of an issue with my STM32 project. In Arduino I can send code via the usb cabe to several devices. One over cu.SLAB_USBtoUART and the other is cu.usbserial-144220. When I get to PIO no matter what I add or remove from the platformio.ini file, I am unable to get code to my devices.

Use manually specified: /dev/cu.usbserial-144220
Uploading .pio/build/rak811_tracker/firmware.bin
Failed to init device.
stm32flash Arduino_STM32_0.9

Below are the setting in Arduino I would like to transfer over to PIO
Screen Shot 2020-04-20 at 9.46.27 AM

Any help would be greatly appreciated!

What have you tried? Full platformio.ini?

PlatformIO also knows the upload_protocol = serial switch which attempts to program it via the builtin STM32 bootloader. For that the target chip has to be reset in bootloader mode (BOOT0 pin to 1).

1 Like

Thanks for the quick response! Below is my platformio.ini. I have been trying to send code with the devices in boot mode and regular mode. Should I be specifying an external bootloader?

platform = ststm32
board = rak811_tracker
framework = arduino
; change microcontroller
board_build.mcu = stm32l151rbt6

; change MCU frequency
board_build.f_cpu = 32000000L

upload_protocol = serial
upload_port = /dev/cu.usbserial-144220

;upload_port = /dev/cu.SLAB_USBtoUART
;debug_port = /dev/cu.SLAB_USBtoUART
;monitor_speed = 115200
;upload_protocol = stlink

Can you show the output of a “Verbose Upload” (pio run -v -t upload) at the start of the flasher invocation? Also enable “Verbose Upload” in the Arduino IDE settings and copy the log output from the flashing process there?

Apologies as the code block sections got messed up.
It looks like there is a discrepancy between the upload tools.
Arduino - …/STM32Tools/1.3.2/tools/macosx/stm32Cube
PIO - …/tool-stm32duino”/stm32flash/stm32flash

Is it possible to use the platformio.ini to point the builder at the STM32 Cube Programmer?

Arduino Upload:

        Sketch uses 32332 bytes (24%) of program storage space. Maximum is 131072 bytes.
        Global variables use 2164 bytes (13%) of dynamic memory, leaving 14220 bytes for local variables. Maximum is 16384 bytes.
        /Users/jandolina/Library/Arduino15/packages/STM32/tools/STM32Tools/1.3.2/tools/macosx/stm32CubeProg 1 /var/folders/k7/65ny6s4s5pd65s0twl6j4bgm0000gp/T/arduino_build_72294/Arduino_RAK811_LoRaWAN.ino.bin cu.usbserial-144220 -s 
                                STM32CubeProgrammer v2.4.0                  

    Serial Port cu.usbserial-144220 is successfully opened.
    Port configuration: parity = even, baudrate = 115200, data-bit = 8,
                         stop-bit = 1.0, flow-control = off
    Activating device: OK
    Chip ID: 0x429 
    BootLoader protocol version: 3.1
    Device name : STM32L100x6xxA/STM32L100x8xxA/STM32L100xBxxA/STM32L15xx6xxA/STM32L15xx8xxA/STM32L15xxBxxA
    Flash size  : 128 KBytes (default)
    Device type : MCU
    Device CPU  : Cortex-M3

    Memory Programming ...
    Opening and parsing file: Arduino_RAK811_LoRaWAN.ino.bin
      File          : Arduino_RAK811_LoRaWAN.ino.bin
      Size          : 32708 Bytes
      Address       : 0x08000000 

    Erasing memory corresponding to segment 0:
    Erasing internal memory sectors [0 127]
    Download in Progress:

    File download complete
    Time elapsed during download operation: 00:00:05.827

    RUNNING Program ... 
      Address:      : 0x8000000
    Start operation achieved successfully

PIO Output:

Processing rak811_tracker (platform: ststm32; board: rak811_tracker; framework: arduino; board_build.mcu: stm32l151rbt6; board_build.f_cpu: 32000000L; upload_protocol: serial; upload_port: /dev/cu.usbserial-144220)`
PLATFORM: ST STM32 6.1.0 > RAK811 LoRa Tracker
HARDWARE: STM32L151RBT6 32MHz, 16KB RAM, 128KB Flash
DEBUG: Current (blackmagic) External (blackmagic, jlink, stlink)
 - framework-arduinoststm32 4.10800.200207 (1.8.0) 
 - tool-dfuutil 1.9.200310 
 - tool-openocd 2.1000.190707 (10.0) 
 - tool-stm32duino 1.0.1 
 - toolchain-gccarmnoneeabi 1.90201.191206 (9.2.1)
LDF: Library Dependency Finder ->
LDF Modes: Finder ~ chain, Compatibility ~ soft
Platform incompatible library .platformio/lib/Ticker-esp32_ID1938
More details about "Library Compatibility Mode": docs.platformin/page/librarymanager/ldf.html#ldf-compat-mode
Found 19 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <SPI> 1.0 (/Users/jandolina/.platformio/packages/framework-arduinoststm32/libraries/SPI)
|-- <MCCI LoRaWAN LMIC library> 3.1.0 (/Users/jandolina/.platformio/lib/MCCI LoRaWAN LMIC library_ID5774)
|   |-- <SPI> 1.0 (/Users/jandolina/.platformio/packages/framework-arduinoststm32/libraries/SPI)
Building in release mode
MethodWrapper(["checkprogsize"], [".pio/build/rak811_tracker/firmware.elf"])
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  12.8% (used 2092 bytes from 16384 bytes)
Flash: [==        ]  22.9% (used 30020 bytes from 131072 bytes)
.pio/build/rak811_tracker/firmware.elf  :
section              size        addr
.isr_vector           316   134217728
.text               27492   134218044
.rodata              2372   134245536
.ARM                    8   134247908
.init_array            24   134247916
.fini_array             8   134247940
.data                 156   536870912
.bss                 1936   536871068
._user_heap_stack    1540   536873004
.ARM.attributes        41           0
.comment              102           0
.debug_frame         1100           0
Total               35095
<lambda>(["upload"], [".pio/build/rak811_tracker/firmware.bin"])
AVAILABLE: blackmagic, jlink, serial, stlink
CURRENT: upload_protocol = serial
MethodWrapper(["upload"], [".pio/build/rak811_tracker/firmware.bin"])
Use manually specified: /dev/cu.usbserial-144220
"/Users/jandolina/.platformio/packages/tool-stm32duino"/stm32flash/stm32flash -g 0x08000000 -b 115200 -w ".pio/build/rak811_tracker/firmware.bin" "/dev/cu.usbserial-144220"
Failed to init device.
stm32flash Arduino_STM32_0.9


Using Parser : Raw BINARY
Interface serial_posix: 115200 8E1

*** [upload] Error 1

@maxgerhardt is it possible to point at an alternative stm32 programmer?

I don’t know why the stm32flash flasher fails to talk to the UART bootloader while the STM32CubeProgrammer succeeds… with the same settings and target bootloader. Absolutely not.

But yes redirecting the upload command is possible and documented with upload_command.

You can try to add

upload_port = cu.usbserial-144220
upload_command = /Users/jandolina/Library/Arduino15/packages/STM32/tools/STM32Tools/1.3.2/tools/macosx/stm32CubeProg 1 $SOURCE $UPLOAD_PORT -s

And check with a pio run -v -t upload command whether it produces the exact same invocation as with Arduino IDE, maybe it needs some tweaking.


That was it! The chip is acting funny, but I am able to push code from PIO to the STM devices.


1 Like