cancel
Showing results for 
Search instead for 
Did you mean: 

Generated HAL Timer Tick generated code has an error - F7

tec683
Associate III

I am using STM32CubeIDE 1.13.2 with STM32CubeMX 6.9.2-RC4.  It is an STM32F746 processor.  I'm using STM32Cube_FW_F7_V1.17.1 libraries.  I'm using Azure RTOS and selected TIM12 for the HAL tick time base.

This is a side issue.  When TIM12 was selected, the TIM12 IRQ priority is set to 15 in the NVIC settings. I found Azure to mess with how often the TIM12 period expired interrupt would actually occur.  While trying to figure that out, I discovered the other issue discussed next.  That issue was needing to set the interrupt priority high enough it always happened. I set it to 0 and that made the HAL timer tick work properly.  Why isn't this automatic or at least flagged when a TIM is used?

I'm also using the Register Callback option for my code. This is in CubeMX, project manager, 'Advanced Settings' on the column, TIM set to enable. I was curious if the HAL timer would adapt.

This is the generated code in stm32f7xx_hal_timebase_tim.c.  The function is HAL_InitTick.

 

  status = HAL_TIM_Base_Init(&htim12);
  if (status == HAL_OK)
  {
    /* Start the TIM time Base generation in interrupt mode */
    status = HAL_TIM_Base_Start_IT(&htim12);
    if (status == HAL_OK)
    {
    /* Enable the TIM12 global Interrupt */
        HAL_NVIC_EnableIRQ(TIM8_BRK_TIM12_IRQn);
      /* Configure the SysTick IRQ priority */
      if (TickPriority < (1UL << __NVIC_PRIO_BITS))
      {
        /* Configure the TIM IRQ priority */
        HAL_NVIC_SetPriority(TIM8_BRK_TIM12_IRQn, TickPriority, 0U);
        uwTickPrio = TickPriority;
      }
      else
      {
        status = HAL_ERROR;
      }
    }
  }

  HAL_TIM_RegisterCallback(&htim12, HAL_TIM_PERIOD_ELAPSED_CB_ID, TimeBase_TIM_PeriodElapsedCallback);

 

The generated code attempts to do the right thing by using HAL_TIM_RegisterCallback to use a call back to increment the tick.  Unfortunately, the way the code is sequenced, this call actually fails because the above code already starts the timer with HAL_TIM_Base_Start_IT.  This leaves the TIM in a "busy" state so returns an error when the callback is attempted to be registered.  The HAL ticks still increment because the generic callback for a TIM device still calls the tick increment function.

If this had been coded to check the return status for all calls, it would have been caught during development. That would seem like a basic code review item as this is supposed to be production worthy code.

1 ACCEPTED SOLUTION

Accepted Solutions
Haithem Rahmani
ST Employee

Hi @tec683 ,

Thanks for the detailed analysis., the issue is confirmed and will be reported internally to be fixed.

regards
Haithem.

View solution in original post

1 REPLY 1
Haithem Rahmani
ST Employee

Hi @tec683 ,

Thanks for the detailed analysis., the issue is confirmed and will be reported internally to be fixed.

regards
Haithem.