/** ****************************************************************************** * @file tick.c * @author MCD Application Team * @brief Tick implementation without tick interrupt ****************************************************************************** * @attention * *

© Copyright (c) 2020 STMicroelectronics. * All rights reserved.

* * This software component is licensed by ST under BSD 3-Clause license, * the "License"; You may not use this file except in compliance with the * License. You may obtain a copy of the License at: * opensource.org/licenses/BSD-3-Clause * ****************************************************************************** */ #include "stm32hal.h" #include "tick_device.h" /** * @brief This function configures the source of the time base: * The time source is configured to have 1ms time base with a dedicated * Tick interrupt priority. * @note This function overwrites the one declared as __weak in HAL. * In this implementation, nothing is done. * @retval HAL status */ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { /* load 1Hz for timeout 1 second */ uint32_t ticks = SystemCoreClock ; SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */ SysTick->VAL = 0UL; /* Load the SysTick Counter Value */ SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk; return HAL_OK; } /** * @brief Provide a tick value in millisecond. * @note This function overwrites the one declared as __weak in HAL. * In this implementation, time is counted without using SysTick timer interrupts. * @retval tick value */ uint32_t HAL_GetTick(void) { static uint32_t m_uTick = 0U; static uint32_t t1 = 0U, tdelta = 0U; uint32_t t2; /* device specific behaviour for HAL_GetTick */ DEVICE_GET_TICK; t2 = SysTick->VAL; if (t2 <= t1) { tdelta += t1 - t2; } else { tdelta += t1 + SysTick->LOAD - t2; } if (tdelta > (SystemCoreClock / (1000U))) { tdelta = 0U; m_uTick ++; } t1 = t2; return m_uTick; }