FreeRTOS critical section causes hard fault

I have a custom board running code (RA6M5/FSP4.5.0/FreeRTOS) which can occasionally generate a hard-fault.

The hard-fault is related to memory access performed inside a critical section. When the system operates solely using taskENTER_CRITICAL() or taskENTER_CRITICAL_FROM_ISR() everything works fine. But mixing the two will eventually cause a hard fault.

The debugger when the hard fault occurs makes the call stack look nonsensical. Its hard to get insight once you are in the hard fault handler.

Investigating taskENTER_CRITICAL I saw this on line 198:

```NOTE: This may alter the stack (depending on the portable implementation)
so must be used with care!```

This lead me to assume this was the case and try to use methods that might fix the issue. In particular I added calls to __DSB() at the beginning of each critical section. These seem to work but only when I run the program using the debugger.

I'm open to trying different primitive instead of a critical section. Inside that critical section is access to a simple circular buffer.

Parents Reply
  • I've switched to running both the bootloader and application with 0x800, the bootloader/tinycrypt library warns when you build with a stack smaller than this. I've been running for a while without issue. I'll report back when a number of hours has passed. Usually in the setup I have it fails in < 1000 seconds.

Children