Systick——系统定时器
core_cm4.h中关于SysTick_Config的描述
__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
{
/* 如果加载值大于最大值返回1 */
if ((ticks - 1) > SysTick_LOAD_RELOAD_Msk) return (1);
/* 将加载值写入重装载寄存器 */
SysTick->LOAD = ticks - 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);
}
misc.c中关于定时器时钟选择的描述
/***选择时钟
SysTick_CLKSource_HCLK_Div8 168/8
SysTick_CLKSource_HCLK 168
***/
void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)
{
/* Check the parameters */
assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource));
if (SysTick_CLKSource == SysTick_CLKSource_HCLK)
{
SysTick->CTRL |= SysTick_CLKSource_HCLK;
}
else
{
SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;
}
}