mbed assertation failed: _id, file: ../mbed-os/rtos/Mutex.cpp, line 50

13 Jun 2018

This problem happened when I tried to define an analog GPIO. It happens now when I try to open a file for write. There is no reason for this to occur. I don't use Mutex by myself .. I have two threads, one is the main and the other is just for sending DEBUG messages to the terminal. The Debug thread doesn't use the SD card .. Why do this happen .? Any one know the answer? thanks.

NUCLEO-L476RG Up-to-date mbed-os

19 Jun 2018

I believe I know why this happen. Inside an interrupt I was trying to open a file for writing.

Mutex class says:

class Mutex : private mbed::NonCopyable<Mutex> {
public:
    /** Create and Initialize a Mutex object
     *
     * @note You cannot call this function from ISR context.
    */
    Mutex();

    /** Create and Initialize a Mutex object

     @param name name to be used for this mutex. It has to stay allocated for the lifetime of the thread.

     @note You cannot call this function from ISR context.
...
    */

the SD-card was trying to create a mutex. This is weird since you don't know why this happen.

Solution:

To let a function execute after getting an interrupt, you have to create a thread that check a flag (bool variable) and change the variable inside the interrupt. Inside that thread run the function you want.

Please let me know if you think I made a mistake in this solution.

REF: https://github.com/ARMmbed/mbed-os/blob/master/rtos/Mutex.h