nrf: Add stop_rx() and flush_rx() to NRF UART#5460
nrf: Add stop_rx() and flush_rx() to NRF UART#5460de-vri-es wants to merge 2 commits intoembassy-rs:mainfrom
stop_rx() and flush_rx() to NRF UART#5460Conversation
|
Needs some transforms added to nrf-pac to correct the register names perhaps? https://github.com/embassy-rs/nrf-pac/blob/main/transform-extra.yaml (or maybe not available on all chip families, I haven't looked in detail). |
053807b to
f2e106f
Compare
Yes, this is exactly the reason. I think in this case, what's happening is that it's rewriting the nrf52 flushrx accidentally (https://github.com/embassy-rs/nrf-pac/blob/main/transform-extra.yaml#L219 - only run for non-nrf54), so that regex need to be adjusted. |
5934e1c to
962ade8
Compare
|
Ok, opened a PR here to adjust the generated bindings: embassy-rs/nrf-pac#16 In the mean time, I also adjusted this PR to expose Also adjusted this PR to use the updated PAC already, but I assume that should be merged first ^_^ /edit: Updated to use the merge commit from the main branch now. |
|
Hmm, the CI failure seems odd: "No I don't see how my changes could have caused that :o The /edit: Ah, it must be some other command in the 58712 chars passed to cargo batch :] /edit: I get the feeling that CI is running |
962ade8 to
5fb5726
Compare
5fb5726 to
2a9d9de
Compare
replace nrf-pac to the exact same git version in all cargo.tomls in this repo, then it'll work. |
2a9d9de to
2e389bc
Compare
|
Yay, that worked! Thanks! |
flush_rx to NRF UARTstop_rx() and flush_rx() to NRF UART
|
Note: it seems that the RXTO event is not guaranteed to fire if the receiver was already off when you trigger the STOPRX task. But there is also no status flag to see if the receiver is currently on or off..
It was both. |
f0b100c to
b4003a1
Compare
|
Ok, also adjusted the UARTE driver now to preserve the status of the receiver in the RXTO bit: it will be 1 if the receiver is off. The bit is now cleared when the driver starts the receiver, and set by the hardware. Additionally, there's a This prevents |
b4003a1 to
45ac48e
Compare
| r: pac::uarte::Uarte, | ||
| state: &'static State, | ||
| _p: PhantomData<&'d ()>, | ||
| rx_on: bool, |
There was a problem hiding this comment.
Not too happy to add this, but I don't see a way to avoid this:
Even if you only clear RXTO when starting the receiver, the initial state of the RXTO bit does not match the state of the receiver. I tried manually fixing the RXTO bit on startupt, but writing a 1 is ignored.
So the only way to avoid stop_rx() from hanging if the receiver is already off, is to remember ourselves that it is off :(




This PR exposes the ability to flush the internal UART RX FIFO without enabling the receiver (by doing a read).
This can be useful to either retrieve the last bit of data that you already received, or to purge the RX FIFO.
I want to do that latter in this case, because I have a half-duplex serial bus and all data that gets send is also seen on the RX pin. I want to purge the RX FIFO of any data that was accidentally written to ourselves before activating the receiver (which can also happen because the receiver can still read 4 bytes after being stopped).