配置
main.c
void SYSTICK_Init_Config(u_int64_t ticks)
{
SysTick->SR &= ~(1 << 0);//clear State flag
SysTick->CMP = ticks - 1;
SysTick->CNT = 0;
SysTick->CTLR = 0xF;
NVIC_SetPriority(SysTicK_IRQn, 15);
NVIC_EnableIRQ(SysTicK_IRQn);
}
中断计数
main.c
uint32_t counter = 0;
void SysTick_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void SysTick_Handler(void)
{
if(SysTick->SR == 1)
{
SysTick->SR = 0;//clear State flag
counter++;
printf("Counter:%d\r\n",counter);
}
}
周期配置
main.c
秒
SYSTICK_Init_Config(SystemCoreClock);
毫秒
SYSTICK_Init_Config(SystemCoreClock/1000);