cancel
Showing results for 
Search instead for 
Did you mean: 

SysTick does not update during init

'SMike
Associate III

If Azure ThreadX is enabled, Systick no longer updates; HAL_IncTick() is no longer called from the interrupt, and initialization fails.

1 ACCEPTED SOLUTION

Accepted Solutions
'SMike
Associate III

I was able to fix this and move forward.

So ThreadX "steals" the SysTick interrupt from the HAL. The priorities seem fine. But the HAL interrupt handler calls HAL_IncTick, and when ThreadX is enabled, it no longer gets called (ThreadX has it's own version of SysTick interrupt handler). So I enabled TIM2. You have to move the init code for TIM2 above the rest of the HAL init:

/* USER CODE END Boot_Mode_Sequence_2 */
 
  /* USER CODE BEGIN SysInit */
 
	MX_TIM2_Init(); // timer must be started before using HAL, it replaces SysTick
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DSIHOST_DSI_Init();
  MX_FMC_Init();

and start the timer in MX_TIM2_Init():

  /* USER CODE BEGIN TIM2_Init 2 */
 
  HAL_TIM_Base_Start_IT(&htim2); // Enable the interrupt & start the timer
  /* USER CODE END TIM2_Init 2 *

then call the SysTick function from the interrupt:

void TIM2_IRQHandler(void)
{
  /* USER CODE BEGIN TIM2_IRQn 0 */
 
  /* USER CODE END TIM2_IRQn 0 */
  HAL_TIM_IRQHandler(&htim2);
  /* USER CODE BEGIN TIM2_IRQn 1 */
 
  HAL_IncTick();	// Need to emulate the SysTick to enable HAL initialization
  /* USER CODE END TIM2_IRQn 1 */
}

HTH someone...

View solution in original post

3 REPLIES 3
Javier1
Principal

check your NVIC preemption

HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);

and your systick priority

HAL_InitTick(TICK_INT_PRIORITY);

speciall atention to this part inside HAL_InitTick

/* Configure the SysTick IRQ priority */
  if (TickPriority < (1UL << __NVIC_PRIO_BITS))
  {
    HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
    uwTickPrio = TickPriority;
  }
  else
  {
    return HAL_ERROR;
  }

, there is a good chance threadX NVIC setup is bullying your systick interruption setup.

we dont need to firmware by ourselves, lets talk
'SMike
Associate III

I was able to fix this and move forward.

So ThreadX "steals" the SysTick interrupt from the HAL. The priorities seem fine. But the HAL interrupt handler calls HAL_IncTick, and when ThreadX is enabled, it no longer gets called (ThreadX has it's own version of SysTick interrupt handler). So I enabled TIM2. You have to move the init code for TIM2 above the rest of the HAL init:

/* USER CODE END Boot_Mode_Sequence_2 */
 
  /* USER CODE BEGIN SysInit */
 
	MX_TIM2_Init(); // timer must be started before using HAL, it replaces SysTick
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DSIHOST_DSI_Init();
  MX_FMC_Init();

and start the timer in MX_TIM2_Init():

  /* USER CODE BEGIN TIM2_Init 2 */
 
  HAL_TIM_Base_Start_IT(&htim2); // Enable the interrupt & start the timer
  /* USER CODE END TIM2_Init 2 *

then call the SysTick function from the interrupt:

void TIM2_IRQHandler(void)
{
  /* USER CODE BEGIN TIM2_IRQn 0 */
 
  /* USER CODE END TIM2_IRQn 0 */
  HAL_TIM_IRQHandler(&htim2);
  /* USER CODE BEGIN TIM2_IRQn 1 */
 
  HAL_IncTick();	// Need to emulate the SysTick to enable HAL initialization
  /* USER CODE END TIM2_IRQn 1 */
}

HTH someone...

youre the best answer then! congrats

we dont need to firmware by ourselves, lets talk