在使用stm32f030f4芯片时,用到串口和内部flash读写。无论串口(中断方式和查询方式)还是flash读写,在单独使用时都没有问题。可一旦两者一起使用,便会出现芯片卡死现象。
通过测试发现,一旦出现卡死现象,就无法完成flash擦除函数,因此首先推断是在flash擦除函数FLASH_ErasePage(Erase_FlashAddr)内部出现死机现象,在进入该函数内部后,发现没有任何语句会产生死机,与此发现推断错误。
突然想到flash操作需要一定的时间完成,如果有中断不停的产生,也会出现卡机现象,而且flash操作也将无法进行。于是开始检查是否有相关中断没有关闭。
终于发现下面这个USART1->ISR寄存器中的ORE位:
Bit 3 ORE: Overrun error
This bit is set by hardware when the data currently being received in the shift register is
ready to be transferred into the RDR register while RXNE=1. It is cleared by a software,
writing 1 to the ORECF, in the USARTx_ICR register.
An interrupt is generated if RXNEIE=1 or EIE = 1