4 years, 8 months ago.

mbedOS error (Mutex: 0x2000477C, Not allowed in ISR context)

Target system=NUCLEO_L476RG

I have a project that works fine with older mbedOS5 .. Using the latest firmware cause the mbed to fail to start. The strange thing is compiling the code using online IDE gives a binary file that the error is not the same as if I locally compile the same code with eclipse. The binary from online compiler gives this error:

-- MbedOS Error Info --

= System will be rebooted due to a fatal error =
= Reboot count(=5) reached maximum, system will halt after rebooting
++ MbedOS Fault Handler ++

FaultType: HardFault

Context:
R0   : 00000004
R1   : 0000000D
R2   : 08000000
R3   : 00000004
R4   : 20000C6A
R5   : 08038984
R6   : 00000000
R7   : 00000000
R8   : 00000000
R9   : 00000000
R10  : 00000000
R11  : 00000000
R12  : 00000001
SP   : 200025C0
LR   : 0800A319
PC   : 0800A328
xPSR : 01000000
PSP  : 20002558
MSP  : 20017FC0
CPUID: 410FC241
HFSR : 40000000
MMFSR: 00000082
BFSR : 00000000
UFSR : 00000000
DFSR : 00000008
AFSR : 00000000
MMFAR: 00000004
Mode : Thread
Priv : Privileged
Stack: PSP

-- MbedOS Fault Handler --

Now, using eclipse and ARM GNU compiler the fault report is as bellow:

-- MbedOS Error Info --

= System will be rebooted due to a fatal error =
= Reboot count(=1) reached maximum, system will halt after rebooting

++ MbedOS Error Info ++
Error Status: 0x80010133 Code: 307 Module: 1
Error Message: Mutex: 0x2000477C, Not allowed in ISR context
Location: 0x800852F
Error Value: 0x2000477C
Current Thread: main  Id: 0x20001338 Entry: 0x800845F StackSize: 0x1000 StackMem: 0x20003748 SP: 0x100004E0
For more info, visit: https://mbed.com/s/error?error=0x80010133&tgt=NUCLEO_L476RG

Knowing that my code just works fine with older mbedos.

I have thread, SDBlockdevice and serial interrupt. I used even RawSerial without any success.

I don't know what causes the Mutex error. Why different problems and what is the problem? Thanks.

Here is some more details about the problem.. This is from gdb call stacks. :

It is clear that the problem happens with the default console.

serial_putc() at serial_device.c:231 0x800f254	
DirectSerial::write() at mbed_retarget.cpp:187 0x800760c	
write() at mbed_retarget.cpp:685 0x80079c2	
mbed_error_puts() at mbed_board.c:111 0x8006fca	
mbed_error_vprintf() at mbed_board.c:71 0x8007000	
mbed_error_printf() at mbed_board.c:55 0x800701c	
print_error_report() at mbed_error.c:474 0x8007186	
mbed_error() at mbed_error.c:283 0x800739c	
trap_rtx_error() at mbed_rtx_handlers.c:118 0x8008506	
osMutexAcquire() at rtx_mutex.c:483 0x800957c	
__cxa_guard_acquire() at mbed_retarget.cpp:1,505 0x8007876	
default_console() at mbed_retarget.cpp:276 0x8007920	
get_console() at mbed_retarget.cpp:295 0x8007920	
mbed::mbed_file_handle() at mbed_retarget.cpp:306 0x8007920	
write() at mbed_retarget.cpp:679 0x80079a6	
mbed_error_puts() at mbed_board.c:97 0x8006fb6	
mbed_error_vprintf() at mbed_board.c:71 0x8007000	
mbed_error_printf() at mbed_board.c:55 0x800701c	
mbed_fault_handler() at mbed_fault_handler.c:48 0x8006e66	
Fault_Handler() at except.S:187 0x8006d6a	

posted by M J. 27 Aug 2019

And I enabled some more info about the problem :

++ MbedOS Error Info ++
Error Status: 0x80010133 Code: 307 Module: 1
Error Message: Mutex: 0x20004884, Not allowed in ISR context
Location: 0x8008639
File: mbed_rtx_handlers.c+118
Error Value: 0x20004884
Current Thread: main  Id: 0x20001440 Entry: 0x800855F StackSize: 0x1000 StackMem: 0x20003850 SP: 0x100004D0
Next:
main  State: 0x2 Entry: 0x0800855F Stack Size: 0x00001000 Mem: 0x20003850 SP: 0x20004810
Ready:
rtx_idle  State: 0x1 Entry: 0x08008649 Stack Size: 0x00000300 Mem: 0x20001910 SP: 0x20001BD0
Wait:
rtx_timer  State: 0x83 Entry: 0x0800A3D5 Stack Size: 0x00000300 Mem: 0x20001610 SP: 0x200018A8
Delay:
For more info, visit: https://mbed.com/s/error?error=0x80010133&tgt=NUCLEO_L476RG
-- MbedOS Error Info --

I think the problem is with the default console .. It fails to get it working for some reason.

posted by M J. 28 Aug 2019

2 Answers

4 years, 8 months ago.

Hi Mariwan,

We add flag "-DMBED_TRAP_ERRORS_ENABLED=1" to develop profile as well in Mbed OS 5.13, so if you use functions not allowed in ISR, you will have this failure.

Please check the functions in ISR or use release profile but this is not recommended because there might be some potential issues.

Regards, Desmond

Where can I find the definition of this function that is called during the sequence of getting a Mutex?

static __inline char __get_mode(void) {
    return (char)(__get_CPSR() & 0x1f);
}

I cannot find it.

posted by M J. 27 Aug 2019
4 years, 8 months ago.

Hi there,

The mutex error is probably caused by the serial interupt. Just comment the serial interupt or change it to polling method and you will see.

Edit:

  • What was the latest functional version for you?

Best regards J.

Here is what I find in mbed.h

#if MBED_CONF_RTOS_PRESENT
// RTOS present, this is valid only for mbed OS 5
#define MBED_MAJOR_VERSION 5
#define MBED_MINOR_VERSION 8
#define MBED_PATCH_VERSION 6

#else
// mbed 2
#define MBED_MAJOR_VERSION 2

#define MBED_MINOR_VERSION 0
#define MBED_PATCH_VERSION MBED_LIBRARY_VERSION
#endif

I even removed the interrupt from the code ..but still it crashes. Note: I have 2 threads. First thread run the normal code, second thread will wait for the interrupt to change a value.. That is all what the interrupt do. As I said, I even disabled the interrupt but still the problem occurred I wounder it if the problem is not in the SDBlockDevice?

In the local version, I have the old SDBlockDevice library.

posted by M J. 27 Aug 2019

The problem is still there. sorry

posted by M J. 27 Aug 2019

So if I understand correctly your last working version of MbedOS is 5.8.6 and all newer ones don't work, correct? You can check or change that when you click on Mbed lib in the tree of the online compiler and hit the revision button.

My point is about a change in version 5.10 if I remmember correctly. From this version the serial.attach(...), can.attach(...) methods not working, probably for some or all ST boards.

However, you need to find a part of code where you call a method of some class in interupt context and where is the mutex called. Without see the code or its a simplest version no one can help you I think.

J.

posted by Jan Kamidra 27 Aug 2019