stm32/usart: return error instead of panicking on bad baudrate.

This commit is contained in:
Dario Nieuwenhuis
2023-09-26 00:14:52 +02:00
parent c79a84a98a
commit 5d8817d109
22 changed files with 94 additions and 75 deletions

View File

@ -25,7 +25,7 @@ async fn main(_spawner: Spawner) {
{
let config = Config::default();
let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, irq, NoDma, NoDma, config);
let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, irq, NoDma, NoDma, config).unwrap();
// We can't send too many bytes, they have to fit in the FIFO.
// This is because we aren't sending+receiving at the same time.
@ -41,7 +41,7 @@ async fn main(_spawner: Spawner) {
// Test error handling with with an overflow error
{
let config = Config::default();
let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, irq, NoDma, NoDma, config);
let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, irq, NoDma, NoDma, config).unwrap();
// Send enough bytes to fill the RX FIFOs off all USART versions.
let data = [0xC0, 0xDE, 0x12, 0x23, 0x34];
@ -75,7 +75,7 @@ async fn main(_spawner: Spawner) {
let mut config = Config::default();
config.baudrate = baudrate;
let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, irq, NoDma, NoDma, config);
let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, irq, NoDma, NoDma, config).unwrap();
let n = (baudrate as usize / 100).max(64);

View File

@ -25,7 +25,7 @@ async fn main(_spawner: Spawner) {
let irq = irqs!(UART);
let config = Config::default();
let usart = Uart::new(usart, rx, tx, irq, tx_dma, rx_dma, config);
let usart = Uart::new(usart, rx, tx, irq, tx_dma, rx_dma, config).unwrap();
const LEN: usize = 128;
let mut tx_buf = [0; LEN];

View File

@ -40,7 +40,7 @@ async fn main(spawner: Spawner) {
config.stop_bits = StopBits::STOP1;
config.parity = Parity::ParityNone;
let usart = Uart::new(usart, rx, tx, irq, tx_dma, rx_dma, config);
let usart = Uart::new(usart, rx, tx, irq, tx_dma, rx_dma, config).unwrap();
let (tx, rx) = usart.split();
static mut DMA_BUF: [u8; DMA_BUF_SIZE] = [0; DMA_BUF_SIZE];
let dma_buf = unsafe { DMA_BUF.as_mut() };