xPortPendSVHandler cause HardFault issue

rosslee wrote on Tuesday, September 17, 2019:

I used Cubemx to generate a project which contain FreeRTOS(V10.0.1) and emWin for STM32F429 board.

In this project I created two tasks, one is for GUI and the other is for Touch Screen. I used TIM2 for STM32 timebase and left SysTick for FreeRTOS.

The issue is everytime when I run this project, it will run into HardFault_Handler. Then I check the caller stacks and find the caller is xPortPendSVHandler (as showed in attached image).

I’m not sure what reasons may cause this issue. Can you give me some hints or suggestions about debugging this issue? Thank you.

rtel wrote on Tuesday, September 17, 2019:

Looks like it is the ‘switch context’ function, which actually selects
the next task to run (switch context not being a good name for the
function).

Have you looked through the list here:
https://www.freertos.org/FAQHelp.html - especially the part about
having configASSERT() defined?

If nothing there helps try this page:
https://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html

rosslee wrote on Tuesday, September 17, 2019:

Thanks for your reply.

I just solve the problem by enlarge the stack size from 128byte to 20kbyte. This solution is the same as the 2nd suggestion in the FAQ link you provide. I will follow the suggestions in this link next time when I face a FreeRTOS issue.