I’ve created this thread based on an ongoing issue [[Workaround] Library uncompilable for mbed 5 platformIO because of yield() function · Issue #17 · davetcc/TaskManagerIO · GitHub] where we’ve been discussing mbed bare-metal behaviour WRT mbed RTOS behaviour for ThisThread
.
According to the mbed documentation, most functions on ThisThread
, such as yield()
for example should be available in all contexts, regardless of RTOS being enabled. Given this, I would expect a program that used ThisThread::yield()
for example to compile regardless. However, I’ve found this not to be the case, and in fact the issue below points directly to this.
After looking at the cmake files generated by platformIO for CLion, it looks like the rtos
pacakges are not included, and my understanding is that they should always be included with V5 & V6, there’s conditional blocks to protect RTOS parts. Does anyone know if mbed CLI / Web IDE if works differently here? As after looking at the rtos source code I suspect it does.
Further, I find that when I use PlatformIO with Clion, the build libraries are wrongly setup. In order for auto-complete to work with RTOS, I need to enable the mbed level RTOS flags manually - not just the platformIO ones, see [tcLibraryDev/platformio.ini at master · davetcc/tcLibraryDev · GitHub] for the STM439 environment. This may well be a Clion issue that’s completely separate from the above compilation problem, and maybe should be moved to another disussion (or just ignored as it’s not a big deal really).
Here is an example non-rtos program that does not compile, you don’t need to have the board to hand in order to test it, it fails during compilation / linkage. IDE used to compile - CLion 2020.3 with plugin version 203.5981.106
Program main.cpp source:
#include "mbed.h"
#include "rtos.h" // <<<< I think this should work
#include "rtos/rtos.h" // <<< Don't this should not be needed
DigitalOut led4(LED4);
DigitalOut led3(LED3);
bool running = true;
int main() {
while(running) {
led4.write(0);
led3.write(1);
ThisThread::yield(); // <<< linker error here
//main.cpp:16: undefined reference to `rtos::ThisThread::yield()'
led4.write(1);
led3.write(0);
}
}
Build ini file:
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:disco_f051r8]
platform = ststm32
board = disco_f051r8
framework = mbed
.mbedignore file:
FrameworkMbed/features/cellular/*
FrameworkMbed/features/FEATURE_UVISOR/*
FrameworkMbed/features/frameworks/greentea-client/*
FrameworkMbed/features/frameworks/mbed-client-randlib/*
FrameworkMbed/features/frameworks/mbed-coap/*
FrameworkMbed/features/frameworks/unity/*
FrameworkMbed/features/frameworks/utest/*
FrameworkMbed/features/nanostack/*
FrameworkMbed/features/netsocket/*
FrameworkMbed/features/nvstore/*
FrameworkMbed/features/storage/*
FrameworkMbed/features/device_key/*
Just to update, adding this line to the generated cmake file for CLion
include_directories("$ENV{HOMEDRIVE}$ENV{HOMEPATH}/.platformio/packages/framework-mbed/rtos")
fixes the situation from an IDE standpoint. So that I CAN access ThisThread
from rtos.h
but I CANNOT access RTOS constructs such as Thread
.