rust-exercises
rust-exercises copied to clipboard
Add buffered UART exercise
I'd like to see an exercise for building a fully buffered, interrupt-driven UART, as an extension to the UART exercise.
We should probably do this on a Cortex-M target, as interrupt handling on Cortex-R is not as well handled (the interrupt controllers aren't standardised, and we don't have good drivers for them).
- Make a blocking UART (existing exercise)
- Make it global (needs to be
Mutex<RefCell<Option<Uart>>>) - Give it a one-byte buffer (an
Option<u8>) and make it interrupt driven. - Replace the
Option<u8>with some kind of heapless queue - Use a bbqueue and DMA the data into the UART rather than copying a byte at a time
- Set up a second UART
QEMU probably makes sense (assuming the simulated UART has working interrupts and FIFO and DMA)
MPS3-AN505 (Cortex-M33) apparently has a PL081 DMA controller and five CMSDK UARTs
MPS3-AN536 (Dual Cortex-R52) should also work
QEMU doesn't do flow control though (although I think that's OK): https://github.com/qemu/qemu/blob/e8aa7fdcddfc8589bdc7c973a052e76e8f999455/hw/char/cmsdk-apb-uart.c#L344
We have https://rust-exercises.ferrous-systems.com/latest/book/realtime-v8r-uart to make the UART global, and we have https://github.com/ferrous-systems/rust-training/tree/main/example-code/qemu-common/src/cmsdk_uart, which walks through the various implementations. That's probably enough.