diff options
| -rw-r--r-- | tests/stm32/src/bin/usart.rs | 53 | ||||
| -rw-r--r-- | tests/stm32/src/bin/usart_dma.rs | 53 |
2 files changed, 106 insertions, 0 deletions
diff --git a/tests/stm32/src/bin/usart.rs b/tests/stm32/src/bin/usart.rs new file mode 100644 index 000000000..f887b084a --- /dev/null +++ b/tests/stm32/src/bin/usart.rs | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | #[path = "../example_common.rs"] | ||
| 6 | mod example_common; | ||
| 7 | use defmt::assert_eq; | ||
| 8 | use embassy::executor::Spawner; | ||
| 9 | use embassy_stm32::dma::NoDma; | ||
| 10 | use embassy_stm32::usart::{Config, Uart}; | ||
| 11 | use embassy_stm32::Peripherals; | ||
| 12 | use embedded_hal::blocking::serial::Write; | ||
| 13 | use example_common::*; | ||
| 14 | |||
| 15 | #[embassy::main(config = "config()")] | ||
| 16 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 17 | info!("Hello World!"); | ||
| 18 | |||
| 19 | #[cfg(feature = "stm32wb55rg")] | ||
| 20 | { | ||
| 21 | info!("Test SKIPPED"); | ||
| 22 | cortex_m::asm::bkpt(); | ||
| 23 | } | ||
| 24 | |||
| 25 | // Arduino pins D0 and D1 | ||
| 26 | // They're connected together with a 1K resistor. | ||
| 27 | #[cfg(feature = "stm32g491re")] | ||
| 28 | let (tx, rx, usart) = (p.PC4, p.PC5, p.USART1); | ||
| 29 | #[cfg(feature = "stm32g071rb")] | ||
| 30 | let (tx, rx, usart) = (p.PC4, p.PC5, p.USART1); | ||
| 31 | #[cfg(feature = "stm32f429zi")] | ||
| 32 | let (tx, rx, usart) = (p.PG14, p.PG9, p.USART6); | ||
| 33 | #[cfg(feature = "stm32wb55rg")] | ||
| 34 | let (tx, rx, usart) = (p.PA9, p.PA10, p.USART1); // TODO this is wrong | ||
| 35 | #[cfg(feature = "stm32h755zi")] | ||
| 36 | let (tx, rx, usart) = (p.PB6, p.PB7, p.USART1); | ||
| 37 | |||
| 38 | let config = Config::default(); | ||
| 39 | let mut usart = Uart::new(usart, rx, tx, NoDma, NoDma, config); | ||
| 40 | |||
| 41 | // We can't send too many bytes, they have to fit in the FIFO. | ||
| 42 | // This is because we aren't sending+receiving at the same time. | ||
| 43 | |||
| 44 | let data = [0xC0, 0xDE]; | ||
| 45 | usart.bwrite_all(&data).unwrap(); | ||
| 46 | |||
| 47 | let mut buf = [0; 2]; | ||
| 48 | usart.read_blocking(&mut buf).unwrap(); | ||
| 49 | assert_eq!(buf, data); | ||
| 50 | |||
| 51 | info!("Test OK"); | ||
| 52 | cortex_m::asm::bkpt(); | ||
| 53 | } | ||
diff --git a/tests/stm32/src/bin/usart_dma.rs b/tests/stm32/src/bin/usart_dma.rs new file mode 100644 index 000000000..96c6a6640 --- /dev/null +++ b/tests/stm32/src/bin/usart_dma.rs | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | #[path = "../example_common.rs"] | ||
| 6 | mod example_common; | ||
| 7 | use defmt::assert_eq; | ||
| 8 | use embassy::executor::Spawner; | ||
| 9 | use embassy_stm32::usart::{Config, Uart}; | ||
| 10 | use embassy_stm32::Peripherals; | ||
| 11 | use embassy_traits::uart::{Read, Write}; | ||
| 12 | use example_common::*; | ||
| 13 | |||
| 14 | #[embassy::main(config = "config()")] | ||
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 16 | info!("Hello World!"); | ||
| 17 | |||
| 18 | #[cfg(feature = "stm32wb55rg")] | ||
| 19 | { | ||
| 20 | info!("Test SKIPPED"); | ||
| 21 | cortex_m::asm::bkpt(); | ||
| 22 | } | ||
| 23 | |||
| 24 | // Arduino pins D0 and D1 | ||
| 25 | // They're connected together with a 1K resistor. | ||
| 26 | #[cfg(feature = "stm32g491re")] | ||
| 27 | let (tx, rx, usart, tx_dma, rx_dma) = (p.PC4, p.PC5, p.USART1, p.DMA1_CH0, p.DMA1_CH1); | ||
| 28 | #[cfg(feature = "stm32g071rb")] | ||
| 29 | let (tx, rx, usart, tx_dma, rx_dma) = (p.PC4, p.PC5, p.USART1, p.DMA1_CH0, p.DMA1_CH1); | ||
| 30 | #[cfg(feature = "stm32f429zi")] | ||
| 31 | let (tx, rx, usart, tx_dma, rx_dma) = (p.PG14, p.PG9, p.USART6, p.DMA2_CH6, p.DMA2_CH1); | ||
| 32 | #[cfg(feature = "stm32wb55rg")] | ||
| 33 | let (tx, rx, usart, tx_dma, rx_dma) = (p.PA9, p.PA10, p.USART1, p.DMA1_CH0, p.DMA1_CH1); // TODO this is wrong | ||
| 34 | #[cfg(feature = "stm32h755zi")] | ||
| 35 | let (tx, rx, usart, tx_dma, rx_dma) = (p.PB6, p.PB7, p.USART1, p.DMA1_CH0, p.DMA1_CH1); | ||
| 36 | |||
| 37 | let config = Config::default(); | ||
| 38 | let mut usart = Uart::new(usart, rx, tx, tx_dma, rx_dma, config); | ||
| 39 | |||
| 40 | // We can't send too many bytes, they have to fit in the FIFO. | ||
| 41 | // This is because we aren't sending+receiving at the same time. | ||
| 42 | // For whatever reason, blocking works with 2 bytes but DMA only with 1?? | ||
| 43 | |||
| 44 | let data = [0x42]; | ||
| 45 | usart.write(&data).await.unwrap(); | ||
| 46 | |||
| 47 | let mut buf = [0; 1]; | ||
| 48 | usart.read(&mut buf).await.unwrap(); | ||
| 49 | assert_eq!(buf, data); | ||
| 50 | |||
| 51 | info!("Test OK"); | ||
| 52 | cortex_m::asm::bkpt(); | ||
| 53 | } | ||
