结论:延时时间太短,复位两次
# 问题描述
打印两次
# 问题查找
找了半天,我用别人的代码,就打印一次,然后,一行一行复制,排查问题
结果,代码都一样,还是输出两次
后来,试着试着,会不会是标准库的问题?
结果将别人的标准库,全复制过去,结果:打印一次,好了 !!!
经排查,是 `Firmware/CMSIS/GD/GD32F4xx/Source/system_gd32f4xx.c` 文件
我的版本:`GD32F4xx_Firmware_Library_V3.2.0.7z`
## 之前
```c
#define RCU_MODIFY {volatile uint32_t i; \
RCU_CFG0 |= RCU_AHB_CKSYS_DIV2; \
for(i=0;i<50000;i++); \
RCU_CFG0 |= RCU_AHB_CKSYS_DIV4; \
for(i=0;i<50000;i++);}
void SystemInit (void)
{
/* FPU settings */
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
#endif
/* Reset the RCU clock configuration to the default reset state */
/* Set IRC16MEN bit */
RCU_CTL |= RCU_CTL_IRC16MEN;
RCU_MODIFY
```
## 现在
```c
#define RCU_MODIFY(__delay) do{ \
volatile uint32_t i; \
if(0 != __delay){ \
RCU_CFG0 |= RCU_AHB_CKSYS_DIV2; \
for(i=0; i<__delay; i++){ \
} \
RCU_CFG0 |= RCU_AHB_CKSYS_DIV4; \
for(i=0; i<__delay; i++){ \
} \
} \
}while(0)
void SystemInit (void)
{
/* FPU settings */
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
#endif
/* Reset the RCU clock configuration to the default reset state */
/* Set IRC16MEN bit */
RCU_CTL |= RCU_CTL_IRC16MEN;
while(0U == (RCU_CTL & RCU_CTL_IRC16MSTB)){
}
RCU_MODIFY(0x50);
```
可以看到,之前是 50000,后来改成 0x50,延时时间变小 |