Hard Fault at prvTaskCheckFreeStackSpace

Hello everyone!

Could anybody please kindly help me investigate the issue with hard fault exception at marked code line.

I know that the exception had place at this line by the pc register which were saved in the HardFault_Handler routine before watchdog rebooted MCU.

I got tens of devices that are randomly reporting about the issue couple times a day.

This whole thing started when I added the periodically deletion (and then creation) flow of the task, which stack I periodically measure with uxTaskGetStackHighWaterMark function call (it is prvTaskCheckFreeStackSpace wrapper).

Adding the condition statement:
if(eTaskGetState(taskHandle) == eDeleted) (1)
return;
before calling the uxTaskGetStackHighWaterMark didn’t help.

So I guess there could be race condition of the task that I’m periodically deleting and the other task that is measuring the all tasks’ stacks. But where it leads? To uxTaskGetStackHighWaterMark call with deleted task as the argumet? I did it and nothing happens there just random value of the bytes not equal to the tskSTACK_FILL_BYTE.

Anyway, does anyone see what goes wrong?

Platform? Port? IDE?

Hi @RAc ,

Thank you for the quick response!

ARM Cortex-M3, Atollic TrueStudio.

well Alex,

you need to reveal the code that does the periodic checking. Assuming that code runs in a task of its own, have you checked that that task itself is sound (ie doesn’t run out of stack and checks the return values of all calls)?

It looks as if the TCB is broken and its stack pointer points to an invalid address. You could copy the parameter passed into prvTaskCheckFreeStackSpace() to a global location prior to trying to dereference it. At fault time you would then know what that address is, then work your way back, do the same with the last TCB examined and so on.