Using RTOS with VS Code and PlatformIO

I’m on Linux, using VS Code, PlatformIO, and the latest version of mbed. I’ve got basic compilation/uploading working, but I can’t seem to get rtos working.

I need to
#include “rtos/rtos.h”
in order that
ThisThread::sleep_for(500);
is found.

I’m not sure if I’m supposed to include the include line or not. When I try to build, the compilation fails with

undefined reference to `rtos::ThisThread::sleep_for(unsigned long)’

I presume I need to add some kind of configuration option to some json or ini file. What do I need to do?

sounds more like a problem with platformIO, current Mbed has rtos included.

I think I do have rtos with mbed. It’s a fairly recent version.

I tried adding the following lines to platform.ini

lib_deps = rtos/source

lib_extra_dirs = rtos/source

but it didn’t help. The sources do exist. It just doesn’t seem to want to compile them.

Undoubtedly it’s simple to fix, if only I knew what that something was. As a newbie to all this, there’s so many unfathomable layers of complexity, with build tools, directories and configuration files all over the place.

I did notice some output:

    Library Manager: Installing rtos/source
    Warning! Could not find the package with 'rtos/source' requirements for your system 'linux_x86_64'
    Found 5 compatible libraries

Doesn’t help that much, though.

I am using mbed with platformio with no problem. By default it comes with mbed-os 6.2. I do not have lib_deps or lib_extra_dirs in my platformio.ini files.

It looks like you are using the baremetal version of mbed-os to me. What’s the content of the mbed-app.json? (and what do you mean by “latest version of mbed” in the context of platformio? )

Can you compile any of the platformio’s mbed-os example? (especially this one?

David

mbed_app.json:

{
"requires": ["bare-metal"],
"target_overrides": {
  "*": {
    "target.c_lib": "small",
    "target.printf_lib": "minimal-printf",
    "platform.minimal-printf-enable-floating-point": false,
    "platform.stdio-minimal-console-only": true
  }
}

}

I’ll try the example you gave shortly.

OK … some follow-up. The example you gave compiles successfully.

There’s a couple of caveats:

When I replace platformio.ini with my own board details:

[env:genericSTM32F103C8]
platform = ststm32
board = genericSTM32F103C8
framework = mbed
upload_protocol = stlink

I get the compilation error:

PACKAGES: 
 - framework-mbed 6.51504.200716 (5.15.4) 
 - toolchain-gccarmnoneeabi 1.90201.191206 (9.2.1)
Collecting mbed sources...
mbed build API internal error
Attempt to override undefined parameter 'platform.callback-nontrivial' in 'application[*]'

Also, if I go back to my original project, and edit the file mbed_app.json to remove the “requires” entry, I still get the same compilation error as before. Maybe there’s a stale build environment somehow (??).

Hmm. For a minute there I thought I had cracked it, but it appears not to be.

I guess I don’t actually need threading at this stage. I did spot an interesting async library online which looks interesting if I wanted to go down the concurrency route.

Still, it’s disappointing that mbed’s threading doesn’t seem to build for mcu. It’s difficult to ascertain what the problem is: a configuration problem, board incompatibility, or something else.

Ok first: where does this genericSTM32F103C8 board comes from? Where is it defined?

Does it work ok with the NUCLEO_F103RB? (I see no ready-to-use board listed in targets for the F103C8 in mbed 6.5 at least)

(and why do you use MBed 5?)

It’s difficult to give answers to some of these questions, as a lot of it was set up automagically by PlatformIO.

I don’t have a NUCLEO_F103RB itself. BUT, looking at mbed online, selecting NUCLEO_F103RB seems to be compatible with the STM32 blue pill (although I don’t know the full extent of compatibility)

I tried mbed online using ThisThread and NUCLEO_F103RB. When I uploaded the binary to my blue pill, it worked as expected.

I’ll tinker around and see if I can cajole PlatformIO to compile on mbed 6. Then I should be able to compile for NUCLEO_F103RB and have it work on the blue pill.

“In theory”.