1203030117的个人空间 https://bbs.21ic.com/?1552054 [收藏] [复制] [RSS]

日志

stm32f030f4串口与flash读写一起使用时出现卡死现象

已有 324 次阅读2016-10-12 10:14 |系统分类:单片机| flash, stm32, f030

 在使用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 = 1in the USARTx_CR1 register.
 0: No overrun error
 1: Overrun error is detected
 Note: When this bit is set, the RDR register content is not lost but the shift register is
 overwritten. An interrupt is generated if the ORE flag is set during multibuffer
communication if the EIE bit is set.
 This bit is permanently forced to 0 (no overrun detection) when the OVRDIS bit is set in
the USARTx_CR3 register.
 

 通过上面红色字体我们可以发现,当RXNEIE
= 1 OR EIE =1时,会只要出现Overrun情况,就能产生一个中断!刚好串口接收中断开启条件符合!也就是说当我们开启串口接收中断后,

只要出现Overrun现象,就会产生一个ORE中断,而其标志位OREVCF是通过software清0的,而这个标志位我并没有在程序中清0!这个就是问题所在。

  在中断中清除ORE标志位后,程序终于正常。

  在上面说明中可以注意到,通过置位OVERDIS标志位,就能强制清除ORE标志位。

 
最后需要说明的是,ORE中断其实和RXNE中断是一样的,都是void
USART1_IRQHandler(void);这个也是通过测试发现的。这也是为什么之前一开始没有怀疑中断卡死的情
况,因为最开始测试时发现每次都能进入到void
USART1_IRQHandler(void)中,但没想到是那时进入的ORE中断,而不是RXNE中断产生的。

   最开始也测试到卡死时RXNEIE会被清零,所以很长时间一直纠结在重启RXNEIE上面,而这个是没有效果的。

就这么多吧

路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)