Skip to content

Commit

Permalink
Fix hang on usart read overrun.
Browse files Browse the repository at this point in the history
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 leaflabs#107 for more info.

Signed-off-by: Joseph Birr-Pixton <[email protected]>
  • Loading branch information
ctz committed Mar 10, 2015
1 parent da261d5 commit e1314f6
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions libmaple/usart_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e1314f6

Please sign in to comment.