Does HAL_GetTick() return ticks or milliseconds? (and how to measure in microseconds)

后端 未结 6 1235
一整个雨季
一整个雨季 2021-02-07 11:56

I\'m new to using HAL functions. The description of the function HAL_GetTick() says that it \"provides a tick value in millisecond

6条回答
  •  情书的邮戳
    2021-02-07 12:45

    Although the question was already answered, I think it would be helpful to see how HAL uses HAL_GetTick() to count milliseconds. This can be seen in HAL's function HAL_Delay(uint32_t Delay).

    Implementation of HAL_Delay(uint32_t Delay) from stm32l0xx_hal.c:

    /**
      * @brief This function provides minimum delay (in milliseconds) based
      *        on variable incremented.
      * @note In the default implementation , SysTick timer is the source of time base.
      *       It is used to generate interrupts at regular time intervals where uwTick
      *       is incremented.
      * @note This function is declared as __weak to be overwritten in case of other
      *       implementations in user file.
      * @param Delay specifies the delay time length, in milliseconds.
      * @retval None
      */
    __weak void HAL_Delay(uint32_t Delay)
    {
      uint32_t tickstart = HAL_GetTick();
      uint32_t wait = Delay;
    
      /* Add a period to guaranty minimum wait */
      if (wait < HAL_MAX_DELAY)
      {
        wait++;
      }
    
      while((HAL_GetTick() - tickstart) < wait)
      {
      }
    }
    

提交回复
热议问题