Mbed OS Multi-threading

Hi,

Does mbed OS supports multi-threading now ?

Hi,

No, it doesn’t. mbed OS uses an event-based scheduler, called MINAR, which does not support multi-threading.

What about rtos ? Also, I’ve seen some changes within uVisor to support mullti-threading.

Hi,

I am not familiar with uVisor. But, as I know, currently, RTOS is not yet implemented in mbed OS.
You can also refer the discussion in this thread. @janjongboom mentioned that RTOS support will come soon.

I’ve tried cmsis rtos with mbed OS and it looks working fine, I just tested with a simple thread led example, I’ll try to go a bit deeper and keep you update.

Oh, I am interested in it. Could you share what you found on this thread? Thank you.

Yes, the feature is coming soon.
As the overview says:
Core OS principles

For most IoT applications, an event-driven paradigm is a very natural fit. However, for those applications that do require multithreading functionality, we intend to re-introduce it in 2016, after integrating it with our security and power management components.

1 Like

So, first i downloaded the rtos module using yotta
yt install rtos
if you try to build your project you encounter some errors.
now you go to rtos folder.
the first thing i did if i remember well, i added this line in module.json
“extraIncludes”: [
“rtos”
]

if you build you will get new errors, why? because the rtx library wasn’t build, so what i did i lokkend into the right folder, actually i’m working on a CORTEX M3 so i choose the mbed-rtos-dfc27975e193/rtx/TARGET_CORTEX_M
and i copied all the source files and headers in .project/yotta_modules/rtos/source/rtx
don’t forget to copy the right toolchain too.
then you edit your module.json
“extraIncludes”: [
“rtos”,
“source/rtx”
]

next step is to port your board if its not, mine wasn’t so i added some configurations in the following files:

.project\yotta_modules\rtos\source\rtx\cmsis_os.h:

114 #define osKernelSystemId “RTX V4.61” ///< RTOS identification string
115
116: #define TARGET_MAX32550_evkit 1 // add this line for your board
117
118 #define CMSIS_OS_RTX

.project\yotta_modules\rtos\source\rtx\RTX_CM_lib.h:
344 #define INITIAL_SP (0x20008000UL)
345
346: #elif defined(TARGET_MAX32550_evkit)
347 #define INITIAL_SP (0x20040000UL) // define the top of your SRAM
348

.project\yotta_modules\rtos\source\rtx\RTX_Conf_CM.c: add all needed configuration of your board here

52 # if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC4088) || defined(TARGET_LPC4088_DM) || defined(TARGET_LPC4330) || defined(TARGET_LPC4337) || defined(TARGET_LPC1347) || defined(TARGET_K64F) || defined(TARGET_STM32F401RE)
53 || defined(TARGET_STM32F410RB) || defined(TARGET_KL46Z) || defined(TARGET_KL43Z) || defined(TARGET_STM32F407) || defined(TARGET_F407VG) || defined(TARGET_STM32F303VC) || defined(TARGET_LPC1549) || defined(TARGET_LPC11U68)
54: || defined(TARGET_STM32F411RE) || defined(TARGET_STM32F405RG) || defined(TARGET_K22F) || defined(TARGET_STM32F429ZI) || defined(TARGET_STM32F401VC) || defined(TARGET_MAX32550_evkit) || defined(TARGET_MAX32610) || defined(TARGET_MAX32600) || defined(TARGET_TEENSY3_1)
55 || defined(TARGET_STM32L152RE) || defined(TARGET_STM32F446RE) || defined(TARGET_STM32F446VE) || defined(TARGET_STM32L476VG) || defined(TARGET_STM32L476RG) || defined(TARGET_STM32F469NI) || defined(TARGET_STM32F746NG) || defined(TARGET_STM32F746ZG) || defined(TARGET_STM32L152RC)
56 # define OS_TASKCNT 14

70 # if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC4088) || defined(TARGET_LPC4088_DM) || defined(TARGET_LPC4330) || defined(TARGET_LPC4337) || defined(TARGET_LPC1347) || defined(TARGET_K64F) || defined(TARGET_STM32F401RE)
71 || defined(TARGET_STM32F410RB) || defined(TARGET_KL46Z) || defined(TARGET_KL43Z) || defined(TARGET_STM32F407) || defined(TARGET_F407VG) || defined(TARGET_STM32F303VC) || defined(TARGET_LPC1549) || defined(TARGET_LPC11U68)
72: || defined(TARGET_STM32F411RE) || defined(TARGET_STM32F405RG) || defined(TARGET_K22F) || defined(TARGET_STM32F429ZI) || defined(TARGET_STM32F401VC) || defined(TARGET_MAX32550_evkit) || defined(TARGET_MAX32610) || defined(TARGET_MAX32600) || defined(TARGET_TEENSY3_1)
73 || defined(TARGET_STM32L152RE) || defined(TARGET_STM32F446RE) || defined(TARGET_STM32F446VE) || defined(TARGET_STM32L476VG) || defined(TARGET_STM32L476RG) || defined(TARGET_STM32F469NI) || defined(TARGET_STM32F746NG) || defined(TARGET_STM32F746ZG) || defined(TARGET_STM32L152RC)
74 # define OS_SCHEDULERSTKSIZE 256

209 # define OS_CLOCK 24000000
210
211: #elif defined(TARGET_MAX32550_evkit)
212 # define OS_CLOCK 108000000

Once you configure your board, maybe you will encounter a problem with the cmsis file in the following file :
.project\yotta_modules\rtos\source\rtx\rt_CMSIS.c
chose the right cmsis file you need for your board then build your project.
I don’t remember If there is any other error but i tried to cover all of them.
then i tried with this example :

DigitalOut led(LED2);
DigitalOut led2(LED1);


void led_thread(void const *args) {
    while (true) {
        led = !led;
        Thread::wait(1000);
    }
}

void led2_thread(void const *args) {
    while (true) {
        led2 = !led2;
        Thread::wait(500);
    }
}
 


void app_start(int, char**)
{
  Thread thread(led_thread, NULL, osPriorityNormal, DEFAULT_STACK_SIZE);
  Thread thread_2(led2_thread, NULL, osPriorityNormal, DEFAULT_STACK_SIZE);

  while(1);    
}

yes one other thing, disable uVisor from your target.json, the version you install with yotta is not compatible with rtos.

I hope it’s helpful.

FYI, mbed OS 5.1 has been released, which contains mbed RTOS (built on Keil RTX) at it’s core.