21ic问答首页 - GD32F30X timer8 timer 11初始化问题
GD32F30X timer8 timer 11初始化问题
有哪位大佬知道,GD32F30X的 系统库函数timer_init()里没有对TIMER8/TIMER11的处理, 是什么原因?void timer_init(uint32_t timer_periph, timer_parameter_struct* initpara){
/* configure the counter prescaler value */
TIMER_PSC(timer_periph) = (uint16_t)initpara->prescaler;
/* configure the counter direction and aligned mode */
if((TIMER0 == timer_periph) || (TIMER1 == timer_periph) || (TIMER2 == timer_periph)
|| (TIMER3 == timer_periph) || (TIMER4 == timer_periph) || (TIMER7 == timer_periph)){
TIMER_CTL0(timer_periph) &= ~(uint32_t)(TIMER_CTL0_DIR|TIMER_CTL0_CAM);
TIMER_CTL0(timer_periph) |= (uint32_t)initpara->alignedmode;
TIMER_CTL0(timer_periph) |= (uint32_t)initpara->counterdirection;
}
/* configure the autoreload value */
TIMER_CAR(timer_periph) = (uint32_t)initpara->period;
if((TIMER5 != timer_periph) && (TIMER6 != timer_periph)){
/* reset the CKDIV bit */
TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_CKDIV;
TIMER_CTL0(timer_periph) |= (uint32_t)initpara->clockdivision;
}
if((TIMER0 == timer_periph) || (TIMER7 == timer_periph)){
/* configure the repetition counter value */
TIMER_CREP(timer_periph) = (uint32_t)initpara->repetitioncounter;
}
/* generate an update event */
TIMER_SWEVG(timer_periph) |= (uint32_t)TIMER_SWEVG_UPG;
}
/* configure the counter prescaler value */
TIMER_PSC(timer_periph) = (uint16_t)initpara->prescaler;
/* configure the counter direction and aligned mode */
if((TIMER0 == timer_periph) || (TIMER1 == timer_periph) || (TIMER2 == timer_periph)
|| (TIMER3 == timer_periph) || (TIMER4 == timer_periph) || (TIMER7 == timer_periph)){
TIMER_CTL0(timer_periph) &= ~(uint32_t)(TIMER_CTL0_DIR|TIMER_CTL0_CAM);
TIMER_CTL0(timer_periph) |= (uint32_t)initpara->alignedmode;
TIMER_CTL0(timer_periph) |= (uint32_t)initpara->counterdirection;
}
/* configure the autoreload value */
TIMER_CAR(timer_periph) = (uint32_t)initpara->period;
if((TIMER5 != timer_periph) && (TIMER6 != timer_periph)){
/* reset the CKDIV bit */
TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_CKDIV;
TIMER_CTL0(timer_periph) |= (uint32_t)initpara->clockdivision;
}
if((TIMER0 == timer_periph) || (TIMER7 == timer_periph)){
/* configure the repetition counter value */
TIMER_CREP(timer_periph) = (uint32_t)initpara->repetitioncounter;
}
/* generate an update event */
TIMER_SWEVG(timer_periph) |= (uint32_t)TIMER_SWEVG_UPG;
}
赞0
评论
2025-07-31
赞0
你是根据timer_init如何判断出没有对TIMER8/TIMER11进行处理的呢?我的看法是函数里面的各种if应该是针对有些定时器做特殊处理吧。
24869688b32acb9600.png (143.14 KB )
下载附件
2025-7-31 17:09 上传
比如TIMER1~TIMER4的控制寄存器0,有CAM位和DIR位,但TIMER8和TIMER11的控制寄存器0没有这些位,所以就根据定时器的实际情况来判断是否操作下面的代码:
48716688b34d774be7.png (73.82 KB )
下载附件
2025-7-31 17:18 上传
82598688b34e7d64da.png (90.96 KB )
下载附件
2025-7-31 17:18 上传
49513688b34f076342.png (96.25 KB )
下载附件
2025-7-31 17:18 上传
现在理解了吧。
评论
2025-07-31
赞0
评论
2025-07-31
赞0
评论
2025-07-31
赞0
评论
2025-07-31
赞0
评论
2025-07-31
您需要登录后才可以回复 登录 | 注册