cancel
Showing results for 
Search instead for 
Did you mean: 

Using a timer for systick which shares an IRQ with another timer creates a null pointer exception

Johannes
Senior

I use

  • STM32F205
  • CubeIDE 1.5.0
  • MCU package for STM32F2 V1.9.2

I tried to assign systic to timer 14

I wanted to use timer8 for something else.

I enabled "HAL_REGISTER_CALLBACK" for timers.

When the system starts, during "HAL_Init()" timer14 is initialized as systic timer and immediately started with IRQ service. HAL_TIM_Base_Start_IT(&htim14);

But TIM14 shares IRQ with Timer 8 and timer 8 is not initialized yet.

So the IRQ handler is called, and it calls

void TIM8_TRG_COM_TIM14_IRQHandler(void)
{
  /* USER CODE BEGIN TIM8_TRG_COM_TIM14_IRQn 0 */
 
	/* USER CODE END TIM8_TRG_COM_TIM14_IRQn 0 */
  HAL_TIM_IRQHandler(&htim8);
  HAL_TIM_IRQHandler(&htim14);
  /* USER CODE BEGIN TIM8_TRG_COM_TIM14_IRQn 1 */
 
  /* USER CODE END TIM8_TRG_COM_TIM14_IRQn 1 */
}

But Timer 8 is not initialized yet.

In HAL_TIM_IRQHandler for timer 8, callback functions are called, which are not initialized. (=NULL) which causes a Null Pointer Exception.

What is the correct setting to avoid this? I see no way to move the timer initialisation before HAL Systick initialization.

I use a workaround like this:

void TIM8_TRG_COM_TIM14_IRQHandler(void)
{
  /* USER CODE BEGIN TIM8_TRG_COM_TIM14_IRQn 0 */
 
	if(htim8.State!=HAL_TIM_STATE_RESET)
		HAL_TIM_IRQHandler(&htim8);
	if(htim14.State!=HAL_TIM_STATE_RESET)
		HAL_TIM_IRQHandler(&htim14);
	return;
 
	/* USER CODE END TIM8_TRG_COM_TIM14_IRQn 0 */
  HAL_TIM_IRQHandler(&htim8);
  HAL_TIM_IRQHandler(&htim14);
  /* USER CODE BEGIN TIM8_TRG_COM_TIM14_IRQn 1 */
 
  /* USER CODE END TIM8_TRG_COM_TIM14_IRQn 1 */
}

What do I miss out?

Thank you for your help

Johannes

0 REPLIES 0