Analysis of initialization structure of system clock tick timer (sysTick register), i.e. initialization firmware library function
System clock timer – SYSTICK
How sysTick works:
-sysTick interrupt obtains the system clock (AHB or AHB/8), By reloading the register, the initial value is stored in the decrement counter. When the decrement counter value is 0, the relevant interrupt is triggered. We can also determine whether the count is completed by accessing the 16th bit of sysTick - > Ctrl register (when the current value of decrement counter is 0, the position 1 will be automatically cleared when the bit is read)
- sysTick interrupt is a kernel level peripheral. Its library functions are written in the core ﹣ cm3. H file. The decrement counter and overload register are only available for 24 bits, that is, the maximum value is * 2 ^ 24 *!
- The kernel peripheral interrupt priority is not necessarily higher than the normal peripheral interrupt priority. For example, the system clock tick interrupt. In the following function, set the priority to 15, i.e. 1111, and the priority is the lowest! The priority group of kernel peripheral interrupt is the same as that of general peripheral interrupt, that is, as long as you only need to set the priority group of general peripheral interrupt, it means that the priority group of kernel interrupt is set!
- Initializing the system tick register is to configure the following structure!
typedef struct
{
__IO uint32_t CTRL;
__IO uint32_t LOAD;
__IO uint32_t VAL;
__I uint32_t CALIB;
} SysTick_Type;
static __INLINE uint32_t SysTick_Config(uint32_t ticks)
{
if (ticks > SysTick_LOAD_RELOAD_Msk) return (1);
SysTick->LOAD = (ticks & SysTick_LOAD_RELOAD_Msk) - 1;
NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1);
SysTick->VAL = 0;
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
SysTick_CTRL_TICKINT_Msk |
SysTick_CTRL_ENABLE_Msk;
return (0);
}
- System interrupt tick, the timing formula is: t = reload * (1 / clk); if clk = 72M, then
- reload = 72, t = 1us
- reload = 72000, t = 1ms
Posted by Jakehh on Tue, 31 Mar 2020 03:38:48 -0700