sytem clock for ctrl ms task and us/ms delay

Cortex-M3 的内核中包含一个 SysTick 时钟。SysTick 为一个 24 位递减计数器,SysTick 设定初值并使能后,每经过 1 个系统时钟周期,计数值就减 1。计数到 0 时,SysTick 计数器自动重装初值并继续计数,同时内部的 COUNTFLAG 标志会置位,触发中断 (如果中断使能情况下)。
sytem clock for ctrl ms task and us/ms delay_第1张图片
sytem clock for ctrl ms task and us/ms delay_第2张图片

  1. ms clock setting:
    1.1 Set 1ms interrupt
    sytem clock for ctrl ms task and us/ms delay_第3张图片

    1.2 ISR
    sytem clock for ctrl ms task and us/ms delay_第4张图片

    1.3 ISR called
    sytem clock for ctrl ms task and us/ms delay_第5张图片

  2. us Delay

/**

  • @brief us级延时,滴答定时器为向下计数

  • @param count: 延时us数

  • @retval None
    */
    void bsp_delay_us(uint32_t count)
    {
    uint32_t now_cnt;
    uint32_t target_cnt;

    now_cnt = SysTick->VAL;
    target_cnt = __modulus_us * count;

    if (now_cnt > target_cnt)
    {
    target_cnt = now_cnt - target_cnt;
    }
    else
    {
    target_cnt = SysTick->LOAD - (target_cnt - now_cnt);
    }
    while (target_cnt <= SysTick->VAL);
    }

    /* 滴答定时器时钟源为AHB的1/8,同时转化为us /
    __modulus_us = SystemCoreClock / 1000000;
    /
    configure the systick handler priority */
    NVIC_SetPriority(SysTick_IRQn, 0x00U);

你可能感兴趣的:(FW,stm32)