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;                         /*Control and status register*/
  __IO uint32_t LOAD;                         /*Reload value register*/
  __IO uint32_t VAL;                          /*Current value register*/
  __I  uint32_t CALIB;                        /*Check register*/
} SysTick_Type;
static __INLINE uint32_t SysTick_Config(uint32_t ticks)
{ 
    // Judge if the value passed in is greater than the maximum value of the decrement counter, return 1!
  if (ticks > SysTick_LOAD_RELOAD_Msk)  return (1);            /* Reload value impossible */

    //Set the initial value of reload register!
  SysTick->LOAD  = (ticks & SysTick_LOAD_RELOAD_Msk) - 1;      /* set reload register */

    //Set kernel interrupt priority. Its packet is the same as peripheral packet. Here it is set to 15, i.e. 1111, with the lowest interrupt priority!
    NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1);  /* set Priority for Cortex-M0 System Interrupts */

    //Set decrement counter current value to 0
    SysTick->VAL   = 0;                                         /* Load the SysTick Counter Value */

    // The received clock signal is AHB clock signal 72M
    // Enable interrupt, count to 0, trigger interrupt
    // Enable count digit in sysTick register!
    SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk | 
                   SysTick_CTRL_TICKINT_Msk   | 
                   SysTick_CTRL_ENABLE_Msk;                    /* Enable SysTick IRQ and SysTick Timer */
  return (0);                                                  /* Function successful */
}
  • 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