Skip to content

Avoid data loss with serial interrupt used at high baudrates #4734

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

Merged
merged 2 commits into from
Jul 24, 2017

Conversation

LMESTM
Copy link
Contributor

@LMESTM LMESTM commented Jul 11, 2017

Description

There was a hidden bug in the uart irq handler that was seen when reaching high baud rates as described in details in #4722 . The RXE flags shouldn't be erased in the uart_irq as erasing the flag is actually done when reading the data in the data register. At low baudrate, this has usually not effect, but at igh baud rates, this can actually erase a new newly arrived data, not yet read by application. This would cause data loss at application layer.

The 2nd commit of this PR consist in using TXE (room in byte FIFO for posting next data) flag instead of TC (transmission complete), in order to improve overall performance. Also this is now in line with TxIrq definition from SerialBAse.h : TxIrq for transmit buffer empty

Status

READY

Related PRs

Dependency to #4707

Testing

@LMESTM LMESTM changed the title Do not erwase flasgs in stm32 uart irq handler Do not erase flags in stm32 uart irq handler Jul 11, 2017
@LMESTM LMESTM changed the title Do not erase flags in stm32 uart irq handler Avoid data loss with serial interrupt used at high baudrates Jul 11, 2017
Copy link
Contributor

@kjbracey kjbracey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems correct to me. Only thing that makes me nervous is the question "what if the IRQ handler doesn't transfer data"?

Previously (at least on this platform) they could have gotten away with just not reading - it would have meant the data being thrown away. Or they could have gotten away with not writing - the transmit empty interrupt would clear and not retrigger. The UARTSerial IRQ handlers take great care to try to clear the interrupt condition, but other users might not.

So could break some ST-specific applications, but any portable applications should be correctly clearing already.

@LMESTM
Copy link
Contributor Author

LMESTM commented Jul 13, 2017

I agree that possible application that were not enabling / disabling interrupts on a need basis may encounter issues and will need update, not sure how to avoid this risk :-(

@0xc0170
Copy link
Contributor

0xc0170 commented Jul 13, 2017

/morph test

@mbed-bot
Copy link

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test

@0xc0170
Copy link
Contributor

0xc0170 commented Jul 14, 2017

@LMESTM Can you please resolve the conflicts with a rebase?

LMESTM added 2 commits July 17, 2017 08:46
The RXNE flag is getting cleared when reading Data Register so it should
not be cleared here. Especially in case of high data rate, another byte of
data could have received during irq_handler call and clearing the flag
would read and discard this data which would be lost for application.
TXE indicates that a byte can be written to UART register for sending,
while TC indicates that last byte was completely sent. So the TXE flag
can be used in case of interrupt based Serial communication, to allow
faster and efficient application buffer emptying.

Also TXE flag will be erased from the interrupt when writing to register.
In case there is nothing to write in the register, the application is
expected to disable the interrupt.
@LMESTM
Copy link
Contributor Author

LMESTM commented Jul 17, 2017

@0xc0170 - rebased

@0xc0170
Copy link
Contributor

0xc0170 commented Jul 17, 2017

/morph test

@mbed-bot
Copy link

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 820

Test failed!

@studavekar
Copy link
Contributor

tests-mbedmicro-rtos-mbed-signals,tests-mbedmicro-rtos-mbed-mail failed in connection process.

/morph test

@mbed-bot
Copy link

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 824

All builds and test passed!

@LMESTM
Copy link
Contributor Author

LMESTM commented Jul 19, 2017

@0xc0170 please don't merge - this needs rework as suggested in #4780
hmm - after sutying the remarks, I don't think there is a need for rework after all - see #4780 (comment)

Waiting for confirmation from @betzw anyway

@betzw
Copy link
Contributor

betzw commented Jul 21, 2017

OK for me!

@LMESTM
Copy link
Contributor Author

LMESTM commented Jul 21, 2017

@betzw Thanks for your quick feedback !

@LMESTM
Copy link
Contributor Author

LMESTM commented Jul 21, 2017

@0xc0170 thanks for waiting - nothing has changed, so this can be moved back to ready_for_merge :-)

@theotherjimmy theotherjimmy merged commit 9e443e9 into ARMmbed:master Jul 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants