cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F401RETx HardFault in HAL_Init() for TIM4/TIM5 Timebase source

jlaufer
Associate III

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?

jlaufer_0-1746472715317.png

 

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();

}

 

 

3 REPLIES 3
KnarfB
Principal III

 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

TDK
Guru

Ensure SCB->VTOR is correctly initialized and pointing to 0x08000000.

If you feel a post has answered your question, please click "Accept as Solution".

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..