Events + semihosting

I really am loving the API for the mbed-os Events; one thing though, it seems like one cannot safely do semihosting printfs from within the callbacks.

When I attempt this on a STM32F303K8 nucleo, the device will lock up within about 1-3 minutes

Is this expected behavior? I’ve had to go direct to USB before for debug, which is no problem if that’s a requirement.

Also, I assume it’s safe to queue a new event from within an event callback. Specifically:

void blink()
{
    counter++;
    //printf("Toggling stuff\r\n");

    led1 = !led1;

    queue.call_in(250, blink);
}

Is safe, correct?

Interesting. Events are always executed in a ‘normal’ context - no ISRs or other special contextes - so there should be literally no difference between calling a semihosting call from your main function or through the event queue. I have reported your findings here, let’s see if core OS team has an idea.

Regarding:

Also, I assume it’s safe to queue a new event from within an event callback. Specifically:

Yep. That’s fine.

Thank you!

Hi Malachi
Sorry for not answering ealier.
F303K8 doesn’t support MBED5, so I have run the below test on F091RC, F446RE and L476RG.
All run fine for 20 minutes and mode. Maybe things have been fixed since report (there has been a fix on tickers) or the test code is different. So please either provide a way to reproduce otherwise let’s close it.

#include "mbed.h"
#include "rtos.h"

#define TEST_EQUEUE_SIZE 1024
EventQueue queue(TEST_EQUEUE_SIZE);
DigitalOut led1(LED1);

static int counter = 0;

void blink()
{
    counter++;
    //printf("Toggling stuff, counter=%d\r\n", counter);
    led1 = !led1;
    queue.call_in(250, blink);
}

int main() {
    printf("Toggling stuff test\r\n");
    queue.call_in(250, blink);
    queue.dispatch();
    while(1){
    }
}

Thanks for getting back to me

I believe there was a bug that did get fixed in the events system

Using .mbedignore to exclude the RTOS component yields compilation (thanks to janjongboom for that one!) for the STM32F303K8, though I am not sure how supported this configuration is.