Skip to main content
Visitor II
August 30, 2022
Solved

SysTick does not update during init

  • August 30, 2022
  • 2 replies
  • 1254 views

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

    This topic has been closed for replies.
    Best answer by 'SMike

    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...

    2 replies

    Graduate II
    August 31, 2022

    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.

    'SMikeAuthorAnswer
    Visitor II
    August 31, 2022

    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...

    Graduate II
    September 1, 2022

    youre the best answer then! congrats