Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USART hangs on read overrun #107

Closed
ctz opened this issue Mar 6, 2015 · 5 comments
Closed

USART hangs on read overrun #107

ctz opened this issue Mar 6, 2015 · 5 comments

Comments

@ctz
Copy link
Contributor

ctz commented Mar 6, 2015

I have a program which alternately communicates on uart1 and bit-bangs GPIO to talk a certain protocol. When doing the bit-banging, interrupts are turned off.

This hangs very occasionally (~once an hour) on maple mini.

I attached a debugger and caught the hang in action: it's an interrupt flood to USART1 because usart_irq doesn't handle all the exceptions it enables.

The datasheet says:

Bit 3 ORE: Overrun error
This bit is set by hardware when the word currently being received in the shift register is
ready to be transferred into the RDR register while RXNE=1. An interrupt is generated if
RXNEIE=1 in the USART_CR1 register. It is cleared by a software sequence (an read to the
USART_SR register followed by a read to the USART_DR register).

So while the current code will read DR and therefore clear RXNE, it never reads SR to clear ORE. If there is an overrun it will never clear that exception and it will be continually reasserted forever. This is the cause of the hang I saw.

(Obviously this means I'm losing bytes sometimes, and that's fine for my application. YMMV, which is why this is an issue and not a pull request.)

@ctz
Copy link
Contributor Author

ctz commented Mar 6, 2015

https://gist.github.com/ctz/86b63fa8d95b42d04245

Patch which Works For Me™

@mbolivar
Copy link
Contributor

mbolivar commented Mar 8, 2015

Thanks for this! Mind submitting a PR?

On Fri, Mar 6, 2015 at 6:56 PM, ctz [email protected] wrote:

https://gist.github.com/ctz/86b63fa8d95b42d04245

Patch which Works For Me™


Reply to this email directly or view it on GitHub
#107 (comment).

ctz added a commit to ctz/libmaple that referenced this issue Mar 10, 2015
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.
ctz added a commit to ctz/libmaple that referenced this issue Mar 10, 2015
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]>
@madias123
Copy link

ctz: How about join the new STM32-arduino community: http://stm32duino.com/ ?

@bnewbold
Copy link
Contributor

@mbolivar patch was merged, so this ticket should be closed now

@mbolivar
Copy link
Contributor

done, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants