RTOS not working for stm32f303K8

Hi again, in my continuing saga of trying to get my stm32 Nano to work, I tried a couple of things using rtos, however all the examples give a load of warnings about duplicate #defines as shown below (this is only one of many) followed by a fatal error: osKernelGetTickCount not defined in this scope. What do I need to do to get around this? The reason I’m looking at rtos is because the mbed documentation recommends using RtosTimer rather than Timer or Timeout or any of the API functions, and it’s the only thing that appears to support a “one shot” pulse, so I thought I’d give it a go. I found the example quoted below in the mbed documentation, but it didn’t work either.

In file included from /home/ian/.platformio/packages/framework-mbed/rtos/TARGET_CORTEX/mbed_rtos_storage.h:44:0,
from /home/ian/.platformio/packages/framework-mbed/rtos/TARGET_CORTEX/mbed_boot.c:167:
/home/ian/.platformio/packages/framework-mbed/rtos/TARGET_CORTEX/mbed_rtx_conf.h:71:0: warning: “OS_TIMER_THREAD_TZ_MOD_ID” redefined
#define OS_TIMER_THREAD_TZ_MOD_ID 1

In file included from /home/ian/.platformio/packages/framework-mbed/rtos/TARGET_CORTEX/rtx5/RTX/Source/rtx_lib.h:37:0,
from /home/ian/.platformio/packages/framework-mbed/rtos/TARGET_CORTEX/mbed_rtos_storage.h:43,
from /home/ian/.platformio/packages/framework-mbed/rtos/TARGET_CORTEX/mbed_boot.c:167:
/home/ian/.platformio/packages/framework-mbed/rtos/TARGET_CORTEX/rtx5/RTX/Config/RTX_Config.h:270:0: note: this is the location of the previous definition
#define OS_TIMER_THREAD_TZ_MOD_ID 0

Compiling .pioenvs/nucleo_f303k8/lib7ad/rtos/TARGET_CORTEX/mbed_rtx_idle.o
/home/ian/.platformio/packages/framework-mbed/rtos/TARGET_CORTEX/mbed_rtx_handlers.c: In function ‘osRtxErrorNotify’:
/home/ian/.platformio/packages/framework-mbed/rtos/TARGET_CORTEX/mbed_rtx_handlers.c:44:18: warning: unused variable ‘tid’ [-Wunused-variable]
osThreadId_t tid = osThreadGetId();
^~~
/home/ian/.platformio/packages/framework-mbed/rtos/Kernel.cpp: In function ‘uint64_t rtos::Kernel::get_ms_count()’:
/home/ian/.platformio/packages/framework-mbed/rtos/Kernel.cpp:37:16: error: ‘osKernelGetTickCount’ was not declared in this scope
if (sizeof osKernelGetTickCount() == sizeof(uint64_t)) {
^~~~~~~~~~~~~~~~~~~~
Compiling .pioenvs/nucleo_f303k8/lib7ad/rtos/TARGET_CORTEX/rtx4/cmsis_os1.o
Compiling .pioenvs/nucleo_f303k8/lib7ad/rtos/TARGET_CORTEX/rtx5/RTX/Config/RTX_Config.o
*** [.pioenvs/nucleo_f303k8/lib7ad/rtos/Kernel.o] Error 1
============================================== [ERROR] Took 3.59 seconds ==============================================

This is the example from mbed documentation:

#include "mbed.h"
#include "rtos.h"
 
DigitalOut LEDs[4] = {
    DigitalOut(LED1), DigitalOut(LED2), DigitalOut(LED3), DigitalOut(LED4)
};
 
void blink(void const *n) {
    LEDs[(int)n] = !LEDs[(int)n];
}
 
int main(void) {
    RtosTimer led_1_timer(blink, osTimerPeriodic, (void *)0);
    RtosTimer led_2_timer(blink, osTimerPeriodic, (void *)1);
    RtosTimer led_3_timer(blink, osTimerPeriodic, (void *)2);
    RtosTimer led_4_timer(blink, osTimerPeriodic, (void *)3);
    
    led_1_timer.start(2000);
    led_2_timer.start(1000);
    led_3_timer.start(500);
    led_4_timer.start(250);
    
    Thread::wait(osWaitForever);
}

The redefines are weird, but the main issue here should be that the RTOS component of mbedos is not activated.

For that, you’ll have to modify your platformio.ini as follows:

  • add lib_deps = mbed-rtos
  • add build_flags = -D PIO_FRAMEWORK_MBED_RTOS_PRESENT

as documented per Mbed — PlatformIO latest documentation

1 Like

Thank you Max, once again you’ve solved my problem.
:slight_smile: