2025-05-05 12:27 PM
Hello! I'm working with FreeRTOS for the first time and am getting a HardFault during the call HAL_NVIC_EnableIRQ(TIM4_IRQn); call inside of HAL_InitTick(); from HAL_Init();
I am currently testing with a Nucleo board with MCU STM32F401RET6U and have configured the project as such - the startup file is startup_stm32f401retx.s.
I've tried both TIM4 and TIM5 for the Timebase Source and have had the same results. Nowhere else in the code is TIM4 used or initialized I'm confused why it is hanging on the HAL_NVIC_EnableIRQ call.
Does anyone know what the issue could be or how I can further debug the issue?
int main(void)
{
//Segger SystemView initialization
//Enable the CYCCNT counter
DWT_CTRL |= ( 1 << 0);
SEGGER_SYSVIEW_Conf();
SEGGER_SYSVIEW_Start();
// Also tried above SEGGER Init and result hangs and disconnects instead of Hard Fault
HAL_Init();
CppMain();
}
2025-05-05 1:06 PM
HAL_NVIC_EnableIRQ is a thin wrapper for the CMSIS NVIC_EnableIRQ which wraps few register-level instructions. You might debug-step into it.
What makes me nervous is the DWT_CTRL macro which is not CMSIS like (it would be DWT->CTRL). Maybe you have additional macro definitions which collide with the existing ones. I would remove all unneccesary stuff, like the SEGGER while debugging that hard fault.
hth
KnarfB
2025-05-05 1:42 PM
Ensure SCB->VTOR is correctly initialized and pointing to 0x08000000.
2025-05-05 2:13 PM - edited 2025-05-05 2:17 PM
Determine what exactly is Hard Faulting, perhaps by having the handler output actionable data, and look at the faulting instructions and registers.
Make sure you don't use un-initialized structures, or start/interaction with tasks that are not up yet.
Perhaps use boolean flags to identify the point at which structures/tasks are viable so as not to create race conditions. The TIM IRQHandlers will get an "Update" when the TIM first starts, so BE READY, BE PREPARED