cancel
Showing results for 
Search instead for 
Did you mean: 

Problem changing to alternative timer for HAL system tic.

mads.l
Associate II

Changing HAL SysTic from default timer1 to timer15 or timer16 in CubeMx introduced a problem in the code generator. I am using timer1 in my application, and noticed an unexpected interrupt at startup, and it looks like the Systic interrupt fires before my timer1 initialization code has executed. Below is the IRQ handler which serves both tim1 and tim15 (stm32lxx_it.c):

void TIM1_BRK_TIM15_IRQHandler(void)

{

 /* USER CODE BEGIN TIM1_BRK_TIM15_IRQn 0 */

 /* USER CODE END TIM1_BRK_TIM15_IRQn 0 */

 HAL_TIM_IRQHandler(&htim1);

 HAL_TIM_IRQHandler(&htim15);

 /* USER CODE BEGIN TIM1_BRK_TIM15_IRQn 1 */

 /* USER CODE END TIM1_BRK_TIM15_IRQn 1 */

}

When entering the interrupthandler during the first Systic from tim15, the Instance pointer in htim1 is a null pointer, leading to unpredictable interrupt handling in the HAL_TIM_IRQHANDLER. I can get around this by modifying the handler:

void TIM1_BRK_TIM15_IRQHandler(void)

{

 /* USER CODE BEGIN TIM1_BRK_TIM15_IRQn 0 */

 if (htim1.Instance != 0)

  HAL_TIM_IRQHandler(&htim1);

 HAL_TIM_IRQHandler(&htim15);

#ifdef xxxyyy

 /* USER CODE END TIM1_BRK_TIM15_IRQn 0 */

 HAL_TIM_IRQHandler(&htim1);

 HAL_TIM_IRQHandler(&htim15);

 /* USER CODE BEGIN TIM1_BRK_TIM15_IRQn 1 */

#endif

 /* USER CODE END TIM1_BRK_TIM15_IRQn 1 */

}

Any better and more portable way to fix this without a change in the CubeMX code generator?

0 REPLIES 0