Open japaric opened 3 years ago
Hmm, does the hardware not detect overrun? I'd expect the read_timeout
to fail with an error, ideally.
I'd expect the read_timeout to fail with an error, ideally.
Now that you mention it. That would be better, yeah.
Hmm, does the hardware not detect overrun?
Not familiar with this peripheral or the implementation but perhaps it doesn't detect overrun when there's no configured DMA transfer?
I think the "correct" solution with nrf52 is to use hardware flow control. Which of course needs extra wires and depends on the other end...
I mean, normally it is configurable whether it should override the old contents of the buffer or throw away the new ones. I would not argue in favor of either. I am not sure how embedded-hal intends this to function, but I think both behaviors are perfectly valid! If you have let's say some sensory data that is transmitted via UART and you feed it into a control loop, you are never interested in the old value. Only ever in the new one. Your UART example @japaric of course has the opposite requirement :)
Sadly, I fear, for the nRF52 series this is not configurable and data is ALWAYS lost when an overrun occurs accoding to section 6.33.10.15 ERRORSRC in the ref man: https://infocenter.nordicsemi.com/pdf/nRF52840_PS_v1.1.pdf . We could flag a proper error and know that the previous data would be lost but I think there is no way to retain it.
I don't consider this a bug per se but I find the behavior surprising so I think it (the issue title) should be documented in the API docs.
Steps to reproduce
Running this program
And performing these serial operations:
Produces this output:
[121, 111, 13, 10]
=b"yo\r\n"
The data sent by the firstecho
command (b"hi\r\n"
) is discarded -- I guess at the hardware level -- so it's never returned by theread_timeout
operation The same behavior is observed with theread
API.This is different from other HALs / microcontrollers where incoming serial data is stored in a hardware buffer and
embedded_hal::serial::Read
implementations can still return that old data (module overrun errors)P.S. this behavior may be present in other
read
APIs (I2C)? I haven't tested thatInitialization code