Skip to content
This repository was archived by the owner on May 15, 2021. It is now read-only.

serial::Write implementation is blocking #4

Closed
Nemo157 opened this issue Mar 19, 2018 · 3 comments
Closed

serial::Write implementation is blocking #4

Nemo157 opened this issue Mar 19, 2018 · 3 comments

Comments

@Nemo157
Copy link
Contributor

Nemo157 commented Mar 19, 2018

Opening this issue to avoid polluting rust-embedded/nb#13 with too much device specific discussion.


The current impl embedded_hal::serial::Write for Tx<UART0> is blocking, the easy implementation of

fn write(&mut self, byte: u8) -> nb::Result<(), !> {
    let uart = unsafe { &*UART0::ptr() };
    if uart.events_txdrdy.read().bits() == 1 {
         uart.events_txdrdy.reset();
         uart.txd.write(|w| unsafe { w.bits(u32::from(byte)) });
         Ok(())
    } else {
        Err(nb::Error::WouldBlock)
    }
}

doesn't work because events_txdrdy is only set after a byte is transmitted, not when the peripheral is first enabled. It doesn't appear to be possible to manually set event registers as well.

@therealprof
Copy link
Collaborator

Thanks for the ticket. I'll have a look.

@therealprof
Copy link
Collaborator

Turns out it was rather easy to address by just pumping in a \0 byte during initialisation even before enabling the UART.

@Nemo157
Copy link
Contributor Author

Nemo157 commented Mar 19, 2018

I’m surprised that works, but happy to hear it :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants