我用的GD32F405单片机,移植了rtthread系统,移植后建立了一个线程可以正常运行,但我启动定时器后,定时器可以触发中断,但线程就不运行了,有谁知道是什么问题么?下面是定时器的初始化,另外定时器触发中断的时间间隔只有0.1us,也太奇怪了。定时器初始化是timer2_init(83,5000);
168MHz / 84=2MHz
5000 / 2000000=2.5ms
void timer2_init(uint16_t arr,uint16_t psc)
{
timer_parameter_struct timer_initpara;
rcu_periph_clock_enable(RCU_TIMER2); /* 使能TIMER2时钟 */
/* TIMER2 初始化配置 */
timer_deinit(TIMER2);
timer_initpara.prescaler = psc; /* 时钟预分频系数 */
timer_initpara.period = arr; /* 自动重装载值 */
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER2,&timer_initpara);
timer_enable(TIMER2);
nvic_irq_enable(TIMER2_IRQn, 3, 3); /* TIMER2中断设置,抢占优先级3,子优先级3 */
timer_interrupt_enable(TIMER2,TIMER_INT_UP); /* 使能更新中断 */
}
unsigned int timer_cnt_test = 0;
void TIMER2_IRQHandler(void)
{
timer_cnt_test++;
if (timer_cnt_test == 1000)
{
/* turn on LED1 */
gpio_bit_set(GPIOB, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2);
}
else if (timer_cnt_test == 2000)
{
/* turn off LED1 */
gpio_bit_reset(GPIOB, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2);
}
else if (timer_cnt_test >= 2000)
{
timer_cnt_test = 0;
}
}
|