Multithreading on STM32WB55RG with arduino framework

i need to use multithreading (should be possible it has 2 cores) on my nucleo-wb55rg with the grumpyoldpizza arduino framework modified by @maxgerhardt

But isn’t the second core (Cortex-M0+) explicitly running the BLE Firmware / Stack from a pre-provided firmware? That’s how I read the datasheet and these files. So if you want to use the normal BLE libraries this core cannot be used directly by your application.

But you should get multithreading (not: Multiprocessing) with a e.g. preemptive realt-time operating system, like FreeRTOS, if that’s what you’re asking.

And actually instead of FreeRTOS, it already seems to have CMSIS-RTOS2, with usages like

with API in here.

thankyou but can you write me a example for this api?

I do not have real hardware to test on, but from my general experience with RTOS sytems (FreeRTOS, CMSIS-OS,…) I came up with this:

#include <Arduino.h>

static k_task_t myTaskHandle;
static __attribute__((aligned(8))) uint8_t myTaskStack[1024];

void myTaskFunction(void *context) {
    (void) context; // ignore unused variable
    while(true) {
        Serial.println("Hello from second task!");
        delay(1000); // internally remaps to k_task_delay()
    // should not be reached, but if it is, cleanly exit.

void setup() {

    int ret = k_task_create(
        &myTaskHandle, /* ptr to task handle for later control */ 
        "My Task",  /* task name */
        myTaskFunction, /* task function */
        NULL, /* context ptr */
        15, /* task priority, from K_PRIORITY_MIN=15 to K_PRIORITY_MAX=255 */
        &myTaskStack[0], /* ptr to task stack memory */ 
        sizeof(myTaskStack), /* size of task stack memory */
        0 /* additional options */
    if(ret == K_NO_ERROR) {
        Serial.println("Task created successfully!");
    } else {
        Serial.println("Failed to create task: " + String(ret));
void loop() {
    digitalWrite(LED_BUILTIN, LOW);
    digitalWrite(LED_BUILTIN, HIGH);

    // grab some task info for the task
    k_task_info_t taskInfo;
    if(k_task_info(&myTaskHandle, &taskInfo) == K_NO_ERROR) {
        String txt = "Task Name: " + String(;
        txt += "\nPrio: " + String(taskInfo.priority);
        txt += "\nState: " + String(taskInfo.state); // K_STATE_INACTIVE, K_STATE_READY, ..
        txt += "\nWait: " + String(taskInfo.wait); // special wait bitmask, e.g., K_TASK_STATE_WAIT_SLEEP,...
    } else {
        Serial.println("Failed to get task info.");

Many RTOSes offer the same functionality, just in a slightly different API. In reference to the more well-known FreeRTOS e.g., you could say that xTaskCreate() is k_task_create(), k_task_delay is vTaskDelay(), k_task_info() is vTaskGetInfo(), et cetera.

This example does not touch on other RTOS features like semaphores, mutexes, queues, thread signaling, et cetera. Just tries to get a second task up and running.

it works flawlessley thankyou