-
Notifications
You must be signed in to change notification settings - Fork 618
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
Fix uart::flush with FIFO at Half-Duplex mode #2895
Conversation
56d81f3
to
9b1e7e6
Compare
embassy-stm32/src/usart/mod.rs
Outdated
@@ -502,6 +515,10 @@ impl<'d, T: BasicInstance> UartRx<'d, T, Async> { | |||
) -> Result<ReadCompletionEvent, Error> { | |||
let r = T::regs(); | |||
|
|||
if r.cr3().read().hdsel() { | |||
r.cr1().modify(|reg| reg.set_re(false)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be true?
I think with Option 2 you can still receive your own bytes if you do |
I didn't quite understand your point. |
no. call |
9b1e7e6
to
d5f0bce
Compare
Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you!
CC #2875
The problem (
STM32G030C8
,usart_v4
, FIFO always enabled)I make Uart with Half-Duplex mode,
write
~16 bytes, then callblocking_flush
, then callread_until_idle
. No other side, only pull up.As result I get ~7 last bytes which was sent over
uart.write
.I did a little research and found out that the TC flag works correctly. It this is confirmed by tests also.
Possible it is errate, but I not found it within official errata.
Solution
Now I clear cr1.re flag before
write
, this solves the problem.The ideal cycle read-write in Half-Duplex master mode:
write - write - ... - flush - read
Then we can clear
cr1.re
beforewrite
, and set afterflush
.But we should call
flush
beforeread
, but it is impossible with current API.I propose two variants (only for half-duplex):
flush
to start ofread
, clearcr1.re
beforewrite
, and set afterflush
.It requires the real
async flush
, which I can add some later.cr1.re
beforewrite
, and set afterflush
, and set beforeread
.It is some not obvious because after flush the some bytes can be read before we call
read
. But withoutflush
the receiver will be disabled untilread
.It implement variant
1
in this PR, and wait any ideas and discussion.