diff options
| author | Mathias <[email protected]> | 2023-02-13 14:55:15 +0100 |
|---|---|---|
| committer | Mathias <[email protected]> | 2023-02-13 14:55:15 +0100 |
| commit | 218b44652c149f895919b606a660b6eff30e8177 (patch) | |
| tree | 5f985f6edd12926a6f374c17a3a0c3a4226088e7 /tests | |
| parent | 86113e199f37fe0888979608a08bfdaf21bff19a (diff) | |
| parent | 41a563aae3e474955892b27487e185f5f486f525 (diff) | |
Rebase on master
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/rp/Cargo.toml | 11 | ||||
| -rw-r--r-- | tests/rp/src/bin/flash.rs | 54 | ||||
| -rw-r--r-- | tests/rp/src/bin/gpio.rs | 28 | ||||
| -rw-r--r-- | tests/rp/src/bin/multicore.rs | 47 | ||||
| -rw-r--r-- | tests/rp/src/bin/uart_buffered.rs | 13 | ||||
| -rw-r--r-- | tests/stm32/Cargo.toml | 4 | ||||
| -rw-r--r-- | tests/stm32/src/bin/usart.rs | 17 | ||||
| -rw-r--r-- | tests/stm32/src/bin/usart_dma.rs | 48 |
8 files changed, 188 insertions, 34 deletions
diff --git a/tests/rp/Cargo.toml b/tests/rp/Cargo.toml index d6770d6e9..572a9ce88 100644 --- a/tests/rp/Cargo.toml +++ b/tests/rp/Cargo.toml | |||
| @@ -8,20 +8,21 @@ license = "MIT OR Apache-2.0" | |||
| 8 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } | 8 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } | 9 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt"] } | 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt"] } |
| 11 | embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["nightly", "defmt", "unstable-pac", "unstable-traits", "time-driver"] } | 11 | embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["nightly", "defmt", "unstable-pac", "unstable-traits", "time-driver", "critical-section-impl"] } |
| 12 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } | 12 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } |
| 13 | 13 | ||
| 14 | defmt = "0.3.0" | 14 | defmt = "0.3.0" |
| 15 | defmt-rtt = "0.3.0" | 15 | defmt-rtt = "0.4" |
| 16 | 16 | ||
| 17 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } | 17 | cortex-m = { version = "0.7.6" } |
| 18 | cortex-m-rt = "0.7.0" | 18 | cortex-m-rt = "0.7.0" |
| 19 | embedded-hal = "0.2.6" | 19 | embedded-hal = "0.2.6" |
| 20 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" } | 20 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" } |
| 21 | embedded-hal-async = { version = "=0.1.0-alpha.2" } | 21 | embedded-hal-async = { version = "=0.2.0-alpha.0" } |
| 22 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } | 22 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } |
| 23 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 23 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
| 24 | embedded-io = { version = "0.3.0", features = ["async"] } | 24 | embedded-io = { version = "0.4.0", features = ["async"] } |
| 25 | embedded-storage = { version = "0.3" } | ||
| 25 | 26 | ||
| 26 | [profile.dev] | 27 | [profile.dev] |
| 27 | debug = 2 | 28 | debug = 2 |
diff --git a/tests/rp/src/bin/flash.rs b/tests/rp/src/bin/flash.rs new file mode 100644 index 000000000..897e3804f --- /dev/null +++ b/tests/rp/src/bin/flash.rs | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::*; | ||
| 6 | use embassy_executor::Spawner; | ||
| 7 | use embassy_rp::flash::{ERASE_SIZE, FLASH_BASE}; | ||
| 8 | use embassy_time::{Duration, Timer}; | ||
| 9 | use {defmt_rtt as _, panic_probe as _}; | ||
| 10 | |||
| 11 | const ADDR_OFFSET: u32 = 0x4000; | ||
| 12 | |||
| 13 | #[embassy_executor::main] | ||
| 14 | async fn main(_spawner: Spawner) { | ||
| 15 | let p = embassy_rp::init(Default::default()); | ||
| 16 | info!("Hello World!"); | ||
| 17 | |||
| 18 | // add some delay to give an attached debug probe time to parse the | ||
| 19 | // defmt RTT header. Reading that header might touch flash memory, which | ||
| 20 | // interferes with flash write operations. | ||
| 21 | // https://github.com/knurling-rs/defmt/pull/683 | ||
| 22 | Timer::after(Duration::from_millis(10)).await; | ||
| 23 | |||
| 24 | let mut flash = embassy_rp::flash::Flash::<_, { 2 * 1024 * 1024 }>::new(p.FLASH); | ||
| 25 | |||
| 26 | let mut buf = [0u8; ERASE_SIZE]; | ||
| 27 | defmt::unwrap!(flash.read(ADDR_OFFSET, &mut buf)); | ||
| 28 | |||
| 29 | info!("Addr of flash block is {:x}", ADDR_OFFSET + FLASH_BASE as u32); | ||
| 30 | info!("Contents start with {=[u8]}", buf[0..4]); | ||
| 31 | |||
| 32 | defmt::unwrap!(flash.erase(ADDR_OFFSET, ADDR_OFFSET + ERASE_SIZE as u32)); | ||
| 33 | |||
| 34 | defmt::unwrap!(flash.read(ADDR_OFFSET, &mut buf)); | ||
| 35 | info!("Contents after erase starts with {=[u8]}", buf[0..4]); | ||
| 36 | if buf.iter().any(|x| *x != 0xFF) { | ||
| 37 | defmt::panic!("unexpected"); | ||
| 38 | } | ||
| 39 | |||
| 40 | for b in buf.iter_mut() { | ||
| 41 | *b = 0xDA; | ||
| 42 | } | ||
| 43 | |||
| 44 | defmt::unwrap!(flash.write(ADDR_OFFSET, &mut buf)); | ||
| 45 | |||
| 46 | defmt::unwrap!(flash.read(ADDR_OFFSET, &mut buf)); | ||
| 47 | info!("Contents after write starts with {=[u8]}", buf[0..4]); | ||
| 48 | if buf.iter().any(|x| *x != 0xDA) { | ||
| 49 | defmt::panic!("unexpected"); | ||
| 50 | } | ||
| 51 | |||
| 52 | info!("Test OK"); | ||
| 53 | cortex_m::asm::bkpt(); | ||
| 54 | } | ||
diff --git a/tests/rp/src/bin/gpio.rs b/tests/rp/src/bin/gpio.rs index af22fe27d..80e92d0fd 100644 --- a/tests/rp/src/bin/gpio.rs +++ b/tests/rp/src/bin/gpio.rs | |||
| @@ -78,6 +78,7 @@ async fn main(_spawner: Spawner) { | |||
| 78 | a.set_as_input(); | 78 | a.set_as_input(); |
| 79 | 79 | ||
| 80 | // When an OutputOpenDrain is high, it doesn't drive the pin. | 80 | // When an OutputOpenDrain is high, it doesn't drive the pin. |
| 81 | b.set_high(); | ||
| 81 | a.set_pull(Pull::Up); | 82 | a.set_pull(Pull::Up); |
| 82 | delay(); | 83 | delay(); |
| 83 | assert!(a.is_high()); | 84 | assert!(a.is_high()); |
| @@ -85,9 +86,8 @@ async fn main(_spawner: Spawner) { | |||
| 85 | delay(); | 86 | delay(); |
| 86 | assert!(a.is_low()); | 87 | assert!(a.is_low()); |
| 87 | 88 | ||
| 88 | b.set_low(); | ||
| 89 | |||
| 90 | // When an OutputOpenDrain is low, it drives the pin low. | 89 | // When an OutputOpenDrain is low, it drives the pin low. |
| 90 | b.set_low(); | ||
| 91 | a.set_pull(Pull::Up); | 91 | a.set_pull(Pull::Up); |
| 92 | delay(); | 92 | delay(); |
| 93 | assert!(a.is_low()); | 93 | assert!(a.is_low()); |
| @@ -95,14 +95,36 @@ async fn main(_spawner: Spawner) { | |||
| 95 | delay(); | 95 | delay(); |
| 96 | assert!(a.is_low()); | 96 | assert!(a.is_low()); |
| 97 | 97 | ||
| 98 | // Check high again | ||
| 98 | b.set_high(); | 99 | b.set_high(); |
| 99 | |||
| 100 | a.set_pull(Pull::Up); | 100 | a.set_pull(Pull::Up); |
| 101 | delay(); | 101 | delay(); |
| 102 | assert!(a.is_high()); | 102 | assert!(a.is_high()); |
| 103 | a.set_pull(Pull::Down); | 103 | a.set_pull(Pull::Down); |
| 104 | delay(); | 104 | delay(); |
| 105 | assert!(a.is_low()); | 105 | assert!(a.is_low()); |
| 106 | |||
| 107 | // When an OutputOpenDrain is high, it reads the input value in the pin. | ||
| 108 | b.set_high(); | ||
| 109 | a.set_as_input(); | ||
| 110 | a.set_pull(Pull::Up); | ||
| 111 | delay(); | ||
| 112 | assert!(b.is_high()); | ||
| 113 | a.set_as_output(); | ||
| 114 | a.set_low(); | ||
| 115 | delay(); | ||
| 116 | assert!(b.is_low()); | ||
| 117 | |||
| 118 | // When an OutputOpenDrain is low, it always reads low. | ||
| 119 | b.set_low(); | ||
| 120 | a.set_as_input(); | ||
| 121 | a.set_pull(Pull::Up); | ||
| 122 | delay(); | ||
| 123 | assert!(b.is_low()); | ||
| 124 | a.set_as_output(); | ||
| 125 | a.set_low(); | ||
| 126 | delay(); | ||
| 127 | assert!(b.is_low()); | ||
| 106 | } | 128 | } |
| 107 | 129 | ||
| 108 | // FLEX | 130 | // FLEX |
diff --git a/tests/rp/src/bin/multicore.rs b/tests/rp/src/bin/multicore.rs new file mode 100644 index 000000000..da78e887a --- /dev/null +++ b/tests/rp/src/bin/multicore.rs | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::{info, unwrap}; | ||
| 6 | use embassy_executor::Executor; | ||
| 7 | use embassy_executor::_export::StaticCell; | ||
| 8 | use embassy_rp::multicore::{spawn_core1, Stack}; | ||
| 9 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | ||
| 10 | use embassy_sync::channel::Channel; | ||
| 11 | use {defmt_rtt as _, panic_probe as _}; | ||
| 12 | |||
| 13 | static mut CORE1_STACK: Stack<1024> = Stack::new(); | ||
| 14 | static EXECUTOR0: StaticCell<Executor> = StaticCell::new(); | ||
| 15 | static EXECUTOR1: StaticCell<Executor> = StaticCell::new(); | ||
| 16 | static CHANNEL0: Channel<CriticalSectionRawMutex, bool, 1> = Channel::new(); | ||
| 17 | static CHANNEL1: Channel<CriticalSectionRawMutex, bool, 1> = Channel::new(); | ||
| 18 | |||
| 19 | #[cortex_m_rt::entry] | ||
| 20 | fn main() -> ! { | ||
| 21 | let p = embassy_rp::init(Default::default()); | ||
| 22 | spawn_core1(p.CORE1, unsafe { &mut CORE1_STACK }, move || { | ||
| 23 | let executor1 = EXECUTOR1.init(Executor::new()); | ||
| 24 | executor1.run(|spawner| unwrap!(spawner.spawn(core1_task()))); | ||
| 25 | }); | ||
| 26 | let executor0 = EXECUTOR0.init(Executor::new()); | ||
| 27 | executor0.run(|spawner| unwrap!(spawner.spawn(core0_task()))); | ||
| 28 | } | ||
| 29 | |||
| 30 | #[embassy_executor::task] | ||
| 31 | async fn core0_task() { | ||
| 32 | info!("CORE0 is running"); | ||
| 33 | let ping = true; | ||
| 34 | CHANNEL0.send(ping).await; | ||
| 35 | let pong = CHANNEL1.recv().await; | ||
| 36 | assert_eq!(ping, pong); | ||
| 37 | |||
| 38 | info!("Test OK"); | ||
| 39 | cortex_m::asm::bkpt(); | ||
| 40 | } | ||
| 41 | |||
| 42 | #[embassy_executor::task] | ||
| 43 | async fn core1_task() { | ||
| 44 | info!("CORE1 is running"); | ||
| 45 | let ping = CHANNEL0.recv().await; | ||
| 46 | CHANNEL1.send(ping).await; | ||
| 47 | } | ||
diff --git a/tests/rp/src/bin/uart_buffered.rs b/tests/rp/src/bin/uart_buffered.rs index 9cc20bb98..bea9283e7 100644 --- a/tests/rp/src/bin/uart_buffered.rs +++ b/tests/rp/src/bin/uart_buffered.rs | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | use defmt::{assert_eq, *}; | 5 | use defmt::{assert_eq, *}; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_rp::interrupt; | 7 | use embassy_rp::interrupt; |
| 8 | use embassy_rp::uart::{BufferedUart, Config, State, Uart}; | 8 | use embassy_rp::uart::{BufferedUart, Config}; |
| 9 | use embedded_io::asynch::{Read, Write}; | 9 | use embedded_io::asynch::{Read, Write}; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | 11 | ||
| @@ -17,25 +17,22 @@ async fn main(_spawner: Spawner) { | |||
| 17 | let (tx, rx, uart) = (p.PIN_0, p.PIN_1, p.UART0); | 17 | let (tx, rx, uart) = (p.PIN_0, p.PIN_1, p.UART0); |
| 18 | 18 | ||
| 19 | let config = Config::default(); | 19 | let config = Config::default(); |
| 20 | let uart = Uart::new_blocking(uart, tx, rx, config); | ||
| 21 | |||
| 22 | let irq = interrupt::take!(UART0_IRQ); | 20 | let irq = interrupt::take!(UART0_IRQ); |
| 23 | let tx_buf = &mut [0u8; 16]; | 21 | let tx_buf = &mut [0u8; 16]; |
| 24 | let rx_buf = &mut [0u8; 16]; | 22 | let rx_buf = &mut [0u8; 16]; |
| 25 | let mut state = State::new(); | 23 | let mut uart = BufferedUart::new(uart, irq, tx, rx, tx_buf, rx_buf, config); |
| 26 | let mut uart = BufferedUart::new(&mut state, uart, irq, tx_buf, rx_buf); | ||
| 27 | 24 | ||
| 28 | // Make sure we send more bytes than fits in the FIFO, to test the actual | 25 | // Make sure we send more bytes than fits in the FIFO, to test the actual |
| 29 | // bufferedUart. | 26 | // bufferedUart. |
| 30 | 27 | ||
| 31 | let data = [ | 28 | let data = [ |
| 32 | 1_u8, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, | 29 | 1u8, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, |
| 33 | 30, 31, 32, | 30 | 30, 31, |
| 34 | ]; | 31 | ]; |
| 35 | uart.write_all(&data).await.unwrap(); | 32 | uart.write_all(&data).await.unwrap(); |
| 36 | info!("Done writing"); | 33 | info!("Done writing"); |
| 37 | 34 | ||
| 38 | let mut buf = [0; 32]; | 35 | let mut buf = [0; 31]; |
| 39 | uart.read_exact(&mut buf).await.unwrap(); | 36 | uart.read_exact(&mut buf).await.unwrap(); |
| 40 | assert_eq!(buf, data); | 37 | assert_eq!(buf, data); |
| 41 | 38 | ||
diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml index bebbf557e..08a775eae 100644 --- a/tests/stm32/Cargo.toml +++ b/tests/stm32/Cargo.toml | |||
| @@ -20,13 +20,13 @@ embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["de | |||
| 20 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "memory-x", "time-driver-tim2"] } | 20 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "memory-x", "time-driver-tim2"] } |
| 21 | 21 | ||
| 22 | defmt = "0.3.0" | 22 | defmt = "0.3.0" |
| 23 | defmt-rtt = "0.3.0" | 23 | defmt-rtt = "0.4" |
| 24 | 24 | ||
| 25 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } | 25 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } |
| 26 | cortex-m-rt = "0.7.0" | 26 | cortex-m-rt = "0.7.0" |
| 27 | embedded-hal = "0.2.6" | 27 | embedded-hal = "0.2.6" |
| 28 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" } | 28 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" } |
| 29 | embedded-hal-async = { version = "=0.1.0-alpha.2" } | 29 | embedded-hal-async = { version = "=0.2.0-alpha.0" } |
| 30 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } | 30 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } |
| 31 | 31 | ||
| 32 | [profile.dev] | 32 | [profile.dev] |
diff --git a/tests/stm32/src/bin/usart.rs b/tests/stm32/src/bin/usart.rs index 7673bfe6d..af55867f2 100644 --- a/tests/stm32/src/bin/usart.rs +++ b/tests/stm32/src/bin/usart.rs | |||
| @@ -7,6 +7,7 @@ mod example_common; | |||
| 7 | use defmt::assert_eq; | 7 | use defmt::assert_eq; |
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_stm32::dma::NoDma; | 9 | use embassy_stm32::dma::NoDma; |
| 10 | use embassy_stm32::interrupt; | ||
| 10 | use embassy_stm32::usart::{Config, Uart}; | 11 | use embassy_stm32::usart::{Config, Uart}; |
| 11 | use example_common::*; | 12 | use example_common::*; |
| 12 | 13 | ||
| @@ -18,22 +19,22 @@ async fn main(_spawner: Spawner) { | |||
| 18 | // Arduino pins D0 and D1 | 19 | // Arduino pins D0 and D1 |
| 19 | // They're connected together with a 1K resistor. | 20 | // They're connected together with a 1K resistor. |
| 20 | #[cfg(feature = "stm32f103c8")] | 21 | #[cfg(feature = "stm32f103c8")] |
| 21 | let (tx, rx, usart) = (p.PA9, p.PA10, p.USART1); | 22 | let (tx, rx, usart, irq) = (p.PA9, p.PA10, p.USART1, interrupt::take!(USART1)); |
| 22 | #[cfg(feature = "stm32g491re")] | 23 | #[cfg(feature = "stm32g491re")] |
| 23 | let (tx, rx, usart) = (p.PC4, p.PC5, p.USART1); | 24 | let (tx, rx, usart, irq) = (p.PC4, p.PC5, p.USART1, interrupt::take!(USART1)); |
| 24 | #[cfg(feature = "stm32g071rb")] | 25 | #[cfg(feature = "stm32g071rb")] |
| 25 | let (tx, rx, usart) = (p.PC4, p.PC5, p.USART1); | 26 | let (tx, rx, usart, irq) = (p.PC4, p.PC5, p.USART1, interrupt::take!(USART1)); |
| 26 | #[cfg(feature = "stm32f429zi")] | 27 | #[cfg(feature = "stm32f429zi")] |
| 27 | let (tx, rx, usart) = (p.PG14, p.PG9, p.USART6); | 28 | let (tx, rx, usart, irq) = (p.PG14, p.PG9, p.USART6, interrupt::take!(USART6)); |
| 28 | #[cfg(feature = "stm32wb55rg")] | 29 | #[cfg(feature = "stm32wb55rg")] |
| 29 | let (tx, rx, usart) = (p.PA2, p.PA3, p.LPUART1); | 30 | let (tx, rx, usart, irq) = (p.PA2, p.PA3, p.LPUART1, interrupt::take!(LPUART1)); |
| 30 | #[cfg(feature = "stm32h755zi")] | 31 | #[cfg(feature = "stm32h755zi")] |
| 31 | let (tx, rx, usart) = (p.PB6, p.PB7, p.USART1); | 32 | let (tx, rx, usart, irq) = (p.PB6, p.PB7, p.USART1, interrupt::take!(USART1)); |
| 32 | #[cfg(feature = "stm32u585ai")] | 33 | #[cfg(feature = "stm32u585ai")] |
| 33 | let (tx, rx, usart) = (p.PD8, p.PD9, p.USART3); | 34 | let (tx, rx, usart, irq) = (p.PD8, p.PD9, p.USART3, interrupt::take!(USART3)); |
| 34 | 35 | ||
| 35 | let config = Config::default(); | 36 | let config = Config::default(); |
| 36 | let mut usart = Uart::new(usart, rx, tx, NoDma, NoDma, config); | 37 | let mut usart = Uart::new(usart, rx, tx, irq, NoDma, NoDma, config); |
| 37 | 38 | ||
| 38 | // We can't send too many bytes, they have to fit in the FIFO. | 39 | // We can't send too many bytes, they have to fit in the FIFO. |
| 39 | // This is because we aren't sending+receiving at the same time. | 40 | // This is because we aren't sending+receiving at the same time. |
diff --git a/tests/stm32/src/bin/usart_dma.rs b/tests/stm32/src/bin/usart_dma.rs index e0389446f..d12605a9a 100644 --- a/tests/stm32/src/bin/usart_dma.rs +++ b/tests/stm32/src/bin/usart_dma.rs | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | mod example_common; | 6 | mod example_common; |
| 7 | use defmt::assert_eq; | 7 | use defmt::assert_eq; |
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_stm32::interrupt; | ||
| 9 | use embassy_stm32::usart::{Config, Uart}; | 10 | use embassy_stm32::usart::{Config, Uart}; |
| 10 | use example_common::*; | 11 | use example_common::*; |
| 11 | 12 | ||
| @@ -17,22 +18,53 @@ async fn main(_spawner: Spawner) { | |||
| 17 | // Arduino pins D0 and D1 | 18 | // Arduino pins D0 and D1 |
| 18 | // They're connected together with a 1K resistor. | 19 | // They're connected together with a 1K resistor. |
| 19 | #[cfg(feature = "stm32f103c8")] | 20 | #[cfg(feature = "stm32f103c8")] |
| 20 | let (tx, rx, usart, tx_dma, rx_dma) = (p.PA9, p.PA10, p.USART1, p.DMA1_CH4, p.DMA1_CH5); | 21 | let (tx, rx, usart, irq, tx_dma, rx_dma) = ( |
| 22 | p.PA9, | ||
| 23 | p.PA10, | ||
| 24 | p.USART1, | ||
| 25 | interrupt::take!(USART1), | ||
| 26 | p.DMA1_CH4, | ||
| 27 | p.DMA1_CH5, | ||
| 28 | ); | ||
| 21 | #[cfg(feature = "stm32g491re")] | 29 | #[cfg(feature = "stm32g491re")] |
| 22 | let (tx, rx, usart, tx_dma, rx_dma) = (p.PC4, p.PC5, p.USART1, p.DMA1_CH1, p.DMA1_CH2); | 30 | let (tx, rx, usart, irq, tx_dma, rx_dma) = |
| 31 | (p.PC4, p.PC5, p.USART1, interrupt::take!(USART1), p.DMA1_CH1, p.DMA1_CH2); | ||
| 23 | #[cfg(feature = "stm32g071rb")] | 32 | #[cfg(feature = "stm32g071rb")] |
| 24 | let (tx, rx, usart, tx_dma, rx_dma) = (p.PC4, p.PC5, p.USART1, p.DMA1_CH1, p.DMA1_CH2); | 33 | let (tx, rx, usart, irq, tx_dma, rx_dma) = |
| 34 | (p.PC4, p.PC5, p.USART1, interrupt::take!(USART1), p.DMA1_CH1, p.DMA1_CH2); | ||
| 25 | #[cfg(feature = "stm32f429zi")] | 35 | #[cfg(feature = "stm32f429zi")] |
| 26 | let (tx, rx, usart, tx_dma, rx_dma) = (p.PG14, p.PG9, p.USART6, p.DMA2_CH6, p.DMA2_CH1); | 36 | let (tx, rx, usart, irq, tx_dma, rx_dma) = ( |
| 37 | p.PG14, | ||
| 38 | p.PG9, | ||
| 39 | p.USART6, | ||
| 40 | interrupt::take!(USART6), | ||
| 41 | p.DMA2_CH6, | ||
| 42 | p.DMA2_CH1, | ||
| 43 | ); | ||
| 27 | #[cfg(feature = "stm32wb55rg")] | 44 | #[cfg(feature = "stm32wb55rg")] |
| 28 | let (tx, rx, usart, tx_dma, rx_dma) = (p.PA2, p.PA3, p.LPUART1, p.DMA1_CH1, p.DMA1_CH2); | 45 | let (tx, rx, usart, irq, tx_dma, rx_dma) = ( |
| 46 | p.PA2, | ||
| 47 | p.PA3, | ||
| 48 | p.LPUART1, | ||
| 49 | interrupt::take!(LPUART1), | ||
| 50 | p.DMA1_CH1, | ||
| 51 | p.DMA1_CH2, | ||
| 52 | ); | ||
| 29 | #[cfg(feature = "stm32h755zi")] | 53 | #[cfg(feature = "stm32h755zi")] |
| 30 | let (tx, rx, usart, tx_dma, rx_dma) = (p.PB6, p.PB7, p.USART1, p.DMA1_CH0, p.DMA1_CH1); | 54 | let (tx, rx, usart, irq, tx_dma, rx_dma) = |
| 55 | (p.PB6, p.PB7, p.USART1, interrupt::take!(USART1), p.DMA1_CH0, p.DMA1_CH1); | ||
| 31 | #[cfg(feature = "stm32u585ai")] | 56 | #[cfg(feature = "stm32u585ai")] |
| 32 | let (tx, rx, usart, tx_dma, rx_dma) = (p.PD8, p.PD9, p.USART3, p.GPDMA1_CH0, p.GPDMA1_CH1); | 57 | let (tx, rx, usart, irq, tx_dma, rx_dma) = ( |
| 58 | p.PD8, | ||
| 59 | p.PD9, | ||
| 60 | p.USART3, | ||
| 61 | interrupt::take!(USART3), | ||
| 62 | p.GPDMA1_CH0, | ||
| 63 | p.GPDMA1_CH1, | ||
| 64 | ); | ||
| 33 | 65 | ||
| 34 | let config = Config::default(); | 66 | let config = Config::default(); |
| 35 | let mut usart = Uart::new(usart, rx, tx, tx_dma, rx_dma, config); | 67 | let mut usart = Uart::new(usart, rx, tx, irq, tx_dma, rx_dma, config); |
| 36 | 68 | ||
| 37 | // We can't send too many bytes, they have to fit in the FIFO. | 69 | // We can't send too many bytes, they have to fit in the FIFO. |
| 38 | // This is because we aren't sending+receiving at the same time. | 70 | // This is because we aren't sending+receiving at the same time. |
