4 years, 7 months ago.

Error Message: Mutex: 0x2000168C, Not allowed in ISR context

Regarding my prvious question at the linke bellow : https://os.mbed.com/questions/86839/mbedOS-error-Mutex-0x2000477C-Not-allowe/

I can regenerate similar error using a sample code available on the mbedos home site.

The link is down bellow: https://os.mbed.com/cookbook/Serial-Interrupts

There must be away that you disable the interrupt when happens to do a critical stuff and reactivate it. I cannot figure out how to do so. Since the example is not working either .. I don't know what is the problem.

Target: Nucleo-L476RG

Take this simple example .. It works just fine with mbed 2 but not with mbedos5 (latest ver).

#include "mbed.h"
 
DigitalOut led1(LED1);
DigitalOut led2(LED2);
 
Serial pc(USBTX, USBRX);
 
void callback() {
    // Note: you need to actually read from the serial to clear the RX interrupt
    printf("%c\n", pc.getc());
    led2 = !led2;
}
 
int main() {
    pc.attach(&callback);
    
    while (1) {
        led1 = !led1;
        wait(0.5);
    }
}
posted by M J. 02 Sep 2019

1 Answer

4 years, 7 months ago.

Hi Mariwan,

I told you about, in your previous qvestion, the serial interupt is probably the issue, you told me that is ok.

However, the example works with the MbedOs2 because the MbedOS2 is without a RTOS functions = no threads = no mutex. It is same as MbedOS5 with the "bare metal profile" .

The interupts can be disabled by these calls for example check bellow, but this will not help you because of mutex...

Disable/Enable Interupts

__disable_irq();  
 // do something magic
__enable_irq(); 

You can found many topics on the github about this issue. For example here.

You can try to use last example of RawSerial on its page.

Best regards J.

The shown code dosen't contain any interrupt manupulation inside the interrupt function. So why it is not working? There is only one putc.

if you mean this example? ( https://os.mbed.com/cookbook/Serial-Interrupts):

I asked how to be able to disable the interrupt when it occurs so you do some critical stuff and re-enable it. None of the ways you mentioned works. I used the RawSerial also .. nothing worked for me ..

Please consider giving me an example code that disable the interrupt at the time it occurs to the time you enable it manually. It doesn't work any way. I understand that you cannot do any change in the interrupt function .. but I have other example that I do that in another function in another thread than main .. but when I have any attach command or disable/enable command .. the program either crashes or just dosen't show anything on the terminal. I put these examples just to show you the problem.

posted by M J. 02 Sep 2019