FreeRTOS with CMSIS API - calling osSignalWait after osMailPut result in Hard Fault

arenalor wrote on Sunday, May 05, 2019:

I am working on a project using an STM32F446 with a boilerplate code generated using STM32CubeMX with freeRTOS added as middleware with the CMSIS interface.
I have two threads which communicate using mailboxes. I tried adding an osSignalWait in the first like

// Send parameters to the Dispatcher thread
osMailPut(commandMailHandle, commandData);

// Wait for signal from the UART
event = osSignalWait(UART1MessageReceivedSignal, 200);

when calling the osSignalWait function and soon as it call the xTaskNotifyWait it goes into hard fault. What could be the cause?

rtel wrote on Sunday, May 05, 2019:

I am working on a project using an STM32F446 with a boilerplate code
generated using STM32CubeMX with freeRTOS added as middleware with the
CMSIS interface.
I have two threads which communicate using mailboxes. I tried adding an
osSignalWait in the first like

// Send parameters to the Dispatcher thread
osMailPut(commandMailHandle, commandData);

// Wait for signal from the UART
event = osSignalWait(UART1MessageReceivedSignal, 200);

Unfortunately these are not functions provided by us, so we only have
any visibility into the native API calls that are embedded within these
wrappers.

when calling the osSignalWait function and soon as it call the
xTaskNotifyWait it goes into hard fault. What could be the cause?

Quite a few things depending on your configuration, or where in the
function it hard faults. Please step into the function to see where the
hard fault occurs, then if it is not clear to you why the hard fault
occurs please report back with a little more detail. The following page
may also help:

arenalor wrote on Monday, May 06, 2019:

After some reading and some attempts I found that it seems related to the amount of stack given to the thread; I initially allocated 128 bytes for each, I then tried with 512 bytes and it works correcly. Are there any principles to choose how much stack to allocate for each thread?

richarddamon wrote on Monday, May 06, 2019:

You can often figure an estimate by looking at how many local variables you have in the code to implement the task. Some compilars also have the ability to show the stack requirements for various functions, which a number of limitiations.

rtel wrote on Monday, May 06, 2019:

During development I recommend having stack overflow checking turned on,
and having configASSERT() defined. The newer your version of FreeRTOS
the more helpful these developer aids will be.