stm32f1xx-hal icon indicating copy to clipboard operation
stm32f1xx-hal copied to clipboard

serial::{Tx, Rx}::{listen, unlisten} are unsafe

Open AndreySmirnov81 opened this issue 3 years ago • 2 comments

And also Rx::{listen_idle, unlisten_idle} are unsafe.

They all use unsafe { (*USART::ptr()).cr1.modify(|_, w| w. ...) };.

It is non-atomic read-modify-write.

Tx and Rx can be used simultaneously from different execution threads. At the same time, they do not provide thread-safe access.

AndreySmirnov81 avatar Feb 22 '22 18:02 AndreySmirnov81

technically we could rewrite those with bit-banding (bb::set)

burrbull avatar Feb 22 '22 18:02 burrbull

I think this will be the most optimal solution.

AndreySmirnov81 avatar Feb 22 '22 18:02 AndreySmirnov81