RTOS not working on PIO on nucleo boards


Hi guys,

I am trying to use Threads in my nucleo rb072rb, but it seems it is not working, when I compile project from PIO.

When I try to compile the same code over Mbed online compiler - it works great.

Could you please assist?

Here is my code:

#include "mbed.h"

const size_t a_stk_size = 1024;
uint8_t a_stk[a_stk_size];
Thread a_thread(osPriorityNormal, a_stk_size, &a_stk[0]);

const size_t b_stk_size = 1024;
uint8_t b_stk[b_stk_size];
Thread b_thread(osPriorityNormal, b_stk_size, &b_stk[0]);

const size_t c_stk_size = 1024;
uint8_t c_stk[c_stk_size];
Thread c_thread(osPriorityNormal, c_stk_size, &c_stk[0]);

const size_t d_stk_size = 1024;
uint8_t d_stk[d_stk_size];
Thread d_thread(osPriorityNormal, d_stk_size, &d_stk[0]);

Serial pc_serial(USBTX,USBRX);

static void thread_a(void)
    uint32_t execs = 0;
    printf("## started thread_a execution! ##\n\r");
    for(;;) {
        printf("## thread_a executed %d times! ##\n\r", execs);


static void thread_b(void)
    uint32_t execs = 0;
    printf("## started thread_b execution! ##\n\r");
    for(;;) {

        printf("## thread_b executed %d times! ##\n\r", execs);

static void thread_c(void)
    uint32_t execs = 0;
    printf("## started thread_b execution! ##\n\r");
    for(;;) {
        /* adds dummy processing */
        printf("## thread_c executed %d times! ##\n\r", execs);

static void thread_d(void)
    uint32_t execs = 0;
    printf("## started thread_a execution! ##\n\r");
    for(;;) {
        printf("## thread_d executed %d times! ##\n\r", execs);


int main(void) 


I tried to use several mbed/ststm32 versions and result is the same.

Processing nucleo_f072rb (platform: ststm32@4.4.0; board: nucleo_f072rb; framework: mbed)
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/nucleo_f072rb.html
HARDWARE: STM32F072RBT6 48MHz 16KB RAM (128KB Flash)
DEBUG: CURRENT(stlink) ON-BOARD(stlink) EXTERNAL(blackmagic, jlink)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
Collected 26 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <mbed-rtos>
|-- <mbed-mbedtls>
Checking size .pioenvs/nucleo_f072rb/firmware.elf
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [========= ]  93.3% (used 15280 bytes from 16384 bytes)
PROGRAM: [=====     ]  51.0% (used 66896 bytes from 131072 bytes)
====================================================================================================== [SUCCESS] Took 4.31 seconds ======================================================================================================

Terminal will be reused by tasks, press any key to close it.


The firmware build process went through. If you build the project without changing the code PIO will not recompile any source code but will just give you memory usage and exit with success.


Agree. But still can’t get it work on nucleo. Firmware comiled on online compiler, works great.

Any suggestions?


Elaborate. What exactly does “doesn’t work” mean? No serial output at all? Not the expected output?


When I flash firmware to board, there is no any output info over serial, and integrated LED blinking 4 short - 4 long lights.

When I use the same code, and compile over online compiler, program works great, and I get appropriate info in serial (integrated LED not blinking)

Tried the same on several other machines (osx, win).


Your board is stuck in mbed_error because of a fatal runtime error. Maybe out of RAM or heap allocation failed. Debug it using openocd.

I also noticed that it’s compiling in mbed-mbedtls. Add that to lib_ignore maybe in the platformio.ini?


Thank you. Will try in the morning.

But, I just woundering, why online compiler works as expected? Is there some different build flags?

When I compile both way (online, platformio), I get the same RAM/Flash usage… And values is less then half of all RAM/Flash


try ‘platform = ststm32@4.4.0’ in your platformio.ini

My nucleo boards wouldn’t compile but my discovery boards did. The older version of mbed worked fine.


I didn’t try add option to lib_ignore yet, but I tried downgrade ststm32 from 4.5.0 to 4.1.0 (over platformio.ini) each minor version. Still no luck.


I just tried
lib_ignore = mbed-mbedtls

but still no luck.

Also tried different mbed-os version, and I’ve got the same mbed error. Will try to debug using openocd.

Thank you in advice


Also I would like to highlight (i miss that point in first message), when I use only one thread, its works…


Any change to the platform.ini file will trigger a rebuild. He did an edit to use a different mbed version. It would recompile everything.


Hi guys.

I tried following:

  1. download latest mbed-os from mbed git
  2. copied package.json and platformio folder from current framework-mbed folder (.platformio/packages)
  3. run tox in platformio folder
  4. replaced framework-mbed folder in .platformio/packages

Now all working great.

Actually, I don’t like this workaround, and I am ready to investigate something to fix problem in platformio/mbed core. Any suggestions?


Any updates here? @ivankravets, could you please assist?


Have you verified where your board is stuck in your first scenario with openocd + arm-none-eabi-gdb? I wrote a tutorial here with which you can setup debugging in eclipse without needing PIO Plus. (Debugging STM32 and ESP32 targets in an IDE)


@valeros could you help here?


Hi @LvivEchoes! I couldn’t reproduce the issue with nucleo-f401re. Are there any special flags in your platformio.ini? Could you try the latest ststm32 from the dev branch?