5 years, 11 months ago.

Mutex lock failed with serial interrupt

Hello,

I use mbed os 5 with a STM32 Nucleo-L073RZ card.

I have a problem with serial interrupts, I want to do something pretty simple I think, but I have a crash of mbed os.

My code creates two serial ports:

  • the standard stdio serial interface used with the ST-link ("serial_pc" in my code)
  • a second serial interface on port serial4 (TX: PA_0, RX: PA_1) with receving interrupt enabled ("uart" in my code)

code

#include "mbed.h"

Serial serial_pc(SERIAL_TX, SERIAL_RX, 115200);

Serial uart(PA_0, PA_1,9600);

char c;

void isr_uart() {
    
    c = uart.getc();
    return;
}

int main() {

    serial_pc.printf("\n\n*** UART TEST ***\n");
    
    uart.attach(&isr_uart,Serial::RxIrq);
}

This code compiles and runs fine until I send a char on the serial port named "uart" here (Serial4 on my board), then I get this error :

++ MbedOS Error Info ++
Error Status: 0x80020115 Code: 277 Module: 2
Error Message: Mutex lock failed
Location: 0x8005F15
Error Value: 0xFFFFFFFA
Current Thread: rtx_idle  Id: 0x20000374 Entry: 0x8008041 StackSize: 0x300 StackMem: 0x20000400 SP: 0x20004F08 
For more info, visit: https://armmbed.github.io/mbedos-error/?error=0x80020115
-- MbedOS Error Info --

I just want to use a simple Rx interrupt, but I must have missed something right ?

Thank you in advance for you help.

ps: I have tested my code and I don't get this error with mbed 2

1 Answer

5 years, 11 months ago.

Try making that a RawSerial object rather than regular Serial object. Every Serial method is wrapped with mutexes which are unusable in ISR (at least last time I checked). RawSerial does not have mutexes and can be used in ISR. Would be nice if they could fix this in standard Serial class, as it's obviously a super common requirement.