Threading & Queues - At a loss

I’ve been attempting to thread a highly interrupt driven programme and bashing my head against a wall failing to get anything working. So today I decided to reduce it right down to its simplest form. Blinky. Well ain’t nothin blinky about this. Nothing happens. I can add function calls to the main thread (such as printf) and they run. But nothing ever happens on the queue:

Device in question is a Nucleo-F303.

/* mbed Microcontroller Library
 * Copyright (c) 2019 ARM Limited
 * SPDX-License-Identifier: Apache-2.0
 */

#include "mbed.h"

Thread tOutput;

DigitalOut led1(LED1);

EventQueue outputQueue(32 * EVENTS_EVENT_SIZE);



void blink(){
        led1 = !led1;
    };


int main(){
    tOutput.start(callback(&outputQueue, &EventQueue::dispatch_forever));

    outputQueue.call_every(500ms, blink);

    thread_sleep_for(osWaitForever);
};

Please help before the last of my grey matter disintegrates.

Hi,

I am not 100% sure if I understand your issue correctly, because your code worked fine (the LED is blinking).
If you need to use EventQueue only (without thread), you need to use dispatch function.

int main(){
    outputQueue.call_every(500ms, blink);
    outputQueue.dispatch();
    thread_sleep_for(osWaitForever);
}

the issue is that the LED is /not/ blinking on 6.16 (weirdly I get an OOM error on 6.13)

Also yes unfortunately I do need threading, this is a supersimplification of the actual program in question that is dealing with CAN messages coming in and out in millisecond timings.

Hi,

the issue is that the LED is /not/ blinking on 6.16 (weirdly I get an OOM error on 6.13)

Sorry, I was using different target board. I got same issue if I used the NUCLEO_F303K8.

This is probably related to small memory issue for this paticular target. The blinky worked fine if I added following config in the mbed_app.json.

{
    "target_overrides": {
        "*": {
            "rtos.main-thread-stack-size"   : 2048,
            "rtos.thread-stack-size"        : 2048
        }
    }
}

Default value is 4096 for both.

Alos, see:
https://os.mbed.com/docs/mbed-os/v6.15/apis/scheduling-options-and-config.html

Thankyou! You’ve saved me some grey matter!