aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple
diff options
context:
space:
mode:
authorJoseph Birr-Pixton <jpixton@gmail.com>2015-03-10 19:47:07 +0000
committerbnewbold <bnewbold@robocracy.org>2015-05-27 20:49:27 -0700
commit97aa002c9d268c30a13b308e7138ad2c41fde7c6 (patch)
tree20bc0f8eb74f6b1bfe23ae4df146f24854b8f721 /libmaple
parent160d861ba3fe50c30891d1abcb2c520be84aaa85 (diff)
downloadlibrambutan-97aa002c9d268c30a13b308e7138ad2c41fde7c6.tar.gz
librambutan-97aa002c9d268c30a13b308e7138ad2c41fde7c6.zip
Fix hang on usart read overrun.
This is improved on the previous patch: if we get an ORE without RXNE when we don't write a junk byte to our buffer. It also avoids the strange-looking blind read. See issue #107 for more info. Signed-off-by: Joseph Birr-Pixton <jpixton@gmail.com>
Diffstat (limited to 'libmaple')
-rw-r--r--libmaple/usart_private.h17
1 files changed, 12 insertions, 5 deletions
diff --git a/libmaple/usart_private.h b/libmaple/usart_private.h
index 8e8e11b..9bc0527 100644
--- a/libmaple/usart_private.h
+++ b/libmaple/usart_private.h
@@ -38,14 +38,21 @@
#include <libmaple/usart.h>
static __always_inline void usart_irq(ring_buffer *rb, usart_reg_map *regs) {
+ /* We can get RXNE and ORE interrupts here. Only RXNE signifies
+ * availability of a byte in DR.
+ *
+ * See table 198 (sec 27.4, p809) in STM document RM0008 rev 15.
+ * We enable RXNEIE. */
+ if (regs->SR & USART_SR_RXNE) {
#ifdef USART_SAFE_INSERT
- /* If the buffer is full and the user defines USART_SAFE_INSERT,
- * ignore new bytes. */
- rb_safe_insert(rb, (uint8)regs->DR);
+ /* If the buffer is full and the user defines USART_SAFE_INSERT,
+ * ignore new bytes. */
+ rb_safe_insert(rb, (uint8)regs->DR);
#else
- /* By default, push bytes around in the ring buffer. */
- rb_push_insert(rb, (uint8)regs->DR);
+ /* By default, push bytes around in the ring buffer. */
+ rb_push_insert(rb, (uint8)regs->DR);
#endif
+ }
}
uint32 _usart_clock_freq(usart_dev *dev);