This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

mBed's Thread::wait() causes interrupts to stop working

Hi,

We have issues with mBed's Thread::wait() in mBed 5.7.2, which causes our interrupts to stop working. Below is a small example that can be used to test this. By removing Thread::wait(), the code works. It does however work with Thread::wait() for a small time, before it hangs (deadlock?)

#include "mbed.h"

DigitalOut led1(LED1);


#define SIGNAL_EVENT_TIMEOUT        0x0200

static osThreadId  sThreadId = NULL;
static Timeout     sTimeOut;

static void myWaitCallback()
{
    osSignalSet(sThreadId, SIGNAL_EVENT_TIMEOUT);  // Notify thread that the timer has expired
}

static void myWait(float timeOut)
{
    sThreadId = osThreadGetId();
    bool exit = false;
    sTimeOut.attach(myWaitCallback, timeOut);
    while (!exit) {
        osEvent event = osSignalWait(SIGNAL_EVENT_TIMEOUT, osWaitForever);
        if (event.status == osEventSignal) {
            if (event.value.signals & SIGNAL_EVENT_TIMEOUT) {
                exit = true;
            }
        }
    }
    sTimeOut.detach();
}



// main() runs in its own thread in the OS
int main() {
    while (true) {
        led1 = !led1;
        //wait(0.5);
        myWait(0.5);
        Thread::wait(500);
    }
}
Parents
  • Hi,

    I tried to reproduce this issue in mbed CLI v1.2.2 with mbed-os v5.7.2, GCC_ARM compiler, and NRF52_DK targe, but I'm not able to reproduce this issue (deadlock). The LED have been blinking for a an hour now without issues. Which compiler and target are you using? Have you tried with another version of mbed-os? How long does it take before the issue occurs?

    Best regards,
    Jørgen

Reply
  • Hi,

    I tried to reproduce this issue in mbed CLI v1.2.2 with mbed-os v5.7.2, GCC_ARM compiler, and NRF52_DK targe, but I'm not able to reproduce this issue (deadlock). The LED have been blinking for a an hour now without issues. Which compiler and target are you using? Have you tried with another version of mbed-os? How long does it take before the issue occurs?

    Best regards,
    Jørgen

Children
  • Hi,

    We see the problem after about 4-5 blinks. It's 100% reproduceable for us, sometimes it happens quicker and sometimes takes a little bit longer times for it stops blinking.

    We are using this compiler:
    arm-none-eabi-c++ (GNU Tools for ARM Embedded Processors) 5.4.1 20160919 (release) [ARM/embedded-5-branch revision 240496]

  • Could you try this compiled HEX file to make sure there is no HW issues?

     mbed-thread-wait-test.hex

  • Hi,

    This is very strange. Your hex file does not blink at all when flashing it on a 52840 PDK.

    Status on our own board
    Mbed 5.7.2 (with minor modifications): Hangs blinking within 2s.

    Status when flashing on 52840 PDK:
    Mbed 5.7.2 (clean OS, without any modifications): Hangs blinking within 2s.
    Mbed 5.7.6 (clean OS, without any modifications): Seems to be working fine

    With 5.7.6 it seems to be working as expected. It has been blinking for a couple of minutes now.

  • No, it will not blink on nRF52840 PDK, as it is compiled for NRF52_DK target. This is compiled for NRF52840_DK target: 

    mbed-thread-wait-test_NRF52840_DK.hex

    I'm not seeing issues on nRF52840-PDK either when running this HEX-file.

    Hopefully it will continue to work with mbed-os-5.7.6 then!

  • Hi,

    Tested your file mbed-thread-wait-test_NRF52840_DK.hex and it blinks fine.

    Have been running it for a minute now. I don't understand your hex-file is working and mine isn't.

    What compiler version and Mbed version are you using?
    Are you building from Linux, Mac or Windows, or perhaps using the Mbed online compiler?