diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/rp/src/bin/gpio_multicore.rs | 63 | ||||
| -rw-r--r-- | tests/rp/src/bin/uart_dma.rs | 4 | ||||
| -rw-r--r-- | tests/stm32/Cargo.toml | 1 | ||||
| -rw-r--r-- | tests/stm32/build.rs | 13 | ||||
| -rw-r--r-- | tests/stm32/src/bin/spi.rs | 1 | ||||
| -rw-r--r-- | tests/stm32/src/bin/usart.rs | 77 | ||||
| -rw-r--r-- | tests/stm32/src/bin/usart_dma.rs | 3 | ||||
| -rw-r--r-- | tests/stm32/src/bin/usart_rx_ringbuffered.rs | 7 | ||||
| -rw-r--r-- | tests/stm32/src/example_common.rs | 5 |
9 files changed, 143 insertions, 31 deletions
diff --git a/tests/rp/src/bin/gpio_multicore.rs b/tests/rp/src/bin/gpio_multicore.rs new file mode 100644 index 000000000..6c13ccaae --- /dev/null +++ b/tests/rp/src/bin/gpio_multicore.rs | |||
| @@ -0,0 +1,63 @@ | |||
| 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::gpio::{Input, Level, Output, Pull}; | ||
| 9 | use embassy_rp::multicore::{spawn_core1, Stack}; | ||
| 10 | use embassy_rp::peripherals::{PIN_0, PIN_1}; | ||
| 11 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | ||
| 12 | use embassy_sync::channel::Channel; | ||
| 13 | use {defmt_rtt as _, panic_probe as _}; | ||
| 14 | |||
| 15 | static mut CORE1_STACK: Stack<1024> = Stack::new(); | ||
| 16 | static EXECUTOR0: StaticCell<Executor> = StaticCell::new(); | ||
| 17 | static EXECUTOR1: StaticCell<Executor> = StaticCell::new(); | ||
| 18 | static CHANNEL0: Channel<CriticalSectionRawMutex, (), 1> = Channel::new(); | ||
| 19 | static CHANNEL1: Channel<CriticalSectionRawMutex, (), 1> = Channel::new(); | ||
| 20 | |||
| 21 | #[cortex_m_rt::entry] | ||
| 22 | fn main() -> ! { | ||
| 23 | let p = embassy_rp::init(Default::default()); | ||
| 24 | spawn_core1(p.CORE1, unsafe { &mut CORE1_STACK }, move || { | ||
| 25 | let executor1 = EXECUTOR1.init(Executor::new()); | ||
| 26 | executor1.run(|spawner| unwrap!(spawner.spawn(core1_task(p.PIN_1)))); | ||
| 27 | }); | ||
| 28 | let executor0 = EXECUTOR0.init(Executor::new()); | ||
| 29 | executor0.run(|spawner| unwrap!(spawner.spawn(core0_task(p.PIN_0)))); | ||
| 30 | } | ||
| 31 | |||
| 32 | #[embassy_executor::task] | ||
| 33 | async fn core0_task(p: PIN_0) { | ||
| 34 | info!("CORE0 is running"); | ||
| 35 | |||
| 36 | let mut pin = Output::new(p, Level::Low); | ||
| 37 | |||
| 38 | CHANNEL0.send(()).await; | ||
| 39 | CHANNEL1.recv().await; | ||
| 40 | |||
| 41 | pin.set_high(); | ||
| 42 | |||
| 43 | CHANNEL1.recv().await; | ||
| 44 | |||
| 45 | info!("Test OK"); | ||
| 46 | cortex_m::asm::bkpt(); | ||
| 47 | } | ||
| 48 | |||
| 49 | #[embassy_executor::task] | ||
| 50 | async fn core1_task(p: PIN_1) { | ||
| 51 | info!("CORE1 is running"); | ||
| 52 | |||
| 53 | CHANNEL0.recv().await; | ||
| 54 | |||
| 55 | let mut pin = Input::new(p, Pull::Down); | ||
| 56 | let wait = pin.wait_for_rising_edge(); | ||
| 57 | |||
| 58 | CHANNEL1.send(()).await; | ||
| 59 | |||
| 60 | wait.await; | ||
| 61 | |||
| 62 | CHANNEL1.send(()).await; | ||
| 63 | } | ||
diff --git a/tests/rp/src/bin/uart_dma.rs b/tests/rp/src/bin/uart_dma.rs index 92aa205c9..52f42e582 100644 --- a/tests/rp/src/bin/uart_dma.rs +++ b/tests/rp/src/bin/uart_dma.rs | |||
| @@ -53,10 +53,6 @@ async fn main(_spawner: Spawner) { | |||
| 53 | let (mut tx, mut rx, mut uart) = (p.PIN_0, p.PIN_1, p.UART0); | 53 | let (mut tx, mut rx, mut uart) = (p.PIN_0, p.PIN_1, p.UART0); |
| 54 | let mut irq = interrupt::take!(UART0_IRQ); | 54 | let mut irq = interrupt::take!(UART0_IRQ); |
| 55 | 55 | ||
| 56 | // TODO | ||
| 57 | // nuclear error reporting. just abort the entire transfer and invalidate the | ||
| 58 | // dma buffer, buffered buffer, fifo etc. | ||
| 59 | |||
| 60 | // We can't send too many bytes, they have to fit in the FIFO. | 56 | // We can't send too many bytes, they have to fit in the FIFO. |
| 61 | // This is because we aren't sending+receiving at the same time. | 57 | // This is because we aren't sending+receiving at the same time. |
| 62 | { | 58 | { |
diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml index 5cd949661..83bf1e9c9 100644 --- a/tests/stm32/Cargo.toml +++ b/tests/stm32/Cargo.toml | |||
| @@ -3,6 +3,7 @@ edition = "2021" | |||
| 3 | name = "embassy-stm32-tests" | 3 | name = "embassy-stm32-tests" |
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | autobins = false | ||
| 6 | 7 | ||
| 7 | [features] | 8 | [features] |
| 8 | stm32f103c8 = ["embassy-stm32/stm32f103c8", "not-gpdma"] # Blue Pill | 9 | stm32f103c8 = ["embassy-stm32/stm32f103c8", "not-gpdma"] # Blue Pill |
diff --git a/tests/stm32/build.rs b/tests/stm32/build.rs index 3e67a7392..7ae311778 100644 --- a/tests/stm32/build.rs +++ b/tests/stm32/build.rs | |||
| @@ -6,15 +6,16 @@ fn main() -> Result<(), Box<dyn Error>> { | |||
| 6 | let out = PathBuf::from(env::var("OUT_DIR").unwrap()); | 6 | let out = PathBuf::from(env::var("OUT_DIR").unwrap()); |
| 7 | fs::write(out.join("link_ram.x"), include_bytes!("link_ram.x")).unwrap(); | 7 | fs::write(out.join("link_ram.x"), include_bytes!("link_ram.x")).unwrap(); |
| 8 | println!("cargo:rustc-link-search={}", out.display()); | 8 | println!("cargo:rustc-link-search={}", out.display()); |
| 9 | println!("cargo:rerun-if-changed=link_ram.x"); | ||
| 10 | |||
| 11 | println!("cargo:rustc-link-arg-bins=--nmagic"); | 9 | println!("cargo:rustc-link-arg-bins=--nmagic"); |
| 12 | 10 | ||
| 13 | // too little RAM to run from RAM. | 11 | // too little RAM to run from RAM. |
| 14 | #[cfg(any(feature = "stm32c031c6"))] | 12 | if cfg!(any(feature = "stm32f103c8", feature = "stm32c031c6")) { |
| 15 | println!("cargo:rustc-link-arg-bins=-Tlink.x"); | 13 | println!("cargo:rustc-link-arg-bins=-Tlink.x"); |
| 16 | #[cfg(not(any(feature = "stm32c031c6")))] | 14 | println!("cargo:rerun-if-changed=link.x"); |
| 17 | println!("cargo:rustc-link-arg-bins=-Tlink_ram.x"); | 15 | } else { |
| 16 | println!("cargo:rustc-link-arg-bins=-Tlink_ram.x"); | ||
| 17 | println!("cargo:rerun-if-changed=link_ram.x"); | ||
| 18 | } | ||
| 18 | 19 | ||
| 19 | println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); | 20 | println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); |
| 20 | 21 | ||
diff --git a/tests/stm32/src/bin/spi.rs b/tests/stm32/src/bin/spi.rs index 0f5e563b1..a87ac3237 100644 --- a/tests/stm32/src/bin/spi.rs +++ b/tests/stm32/src/bin/spi.rs | |||
| @@ -35,7 +35,6 @@ async fn main(_spawner: Spawner) { | |||
| 35 | #[cfg(feature = "stm32c031c6")] | 35 | #[cfg(feature = "stm32c031c6")] |
| 36 | let (spi, sck, mosi, miso) = (p.SPI1, p.PA5, p.PA7, p.PA6); | 36 | let (spi, sck, mosi, miso) = (p.SPI1, p.PA5, p.PA7, p.PA6); |
| 37 | 37 | ||
| 38 | info!("asdfa;"); | ||
| 39 | let mut spi = Spi::new( | 38 | let mut spi = Spi::new( |
| 40 | spi, | 39 | spi, |
| 41 | sck, // Arduino D13 | 40 | sck, // Arduino D13 |
diff --git a/tests/stm32/src/bin/usart.rs b/tests/stm32/src/bin/usart.rs index cca8c42ee..bda2ce9c2 100644 --- a/tests/stm32/src/bin/usart.rs +++ b/tests/stm32/src/bin/usart.rs | |||
| @@ -9,6 +9,7 @@ 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::interrupt; |
| 11 | use embassy_stm32::usart::{Config, Uart}; | 11 | use embassy_stm32::usart::{Config, Uart}; |
| 12 | use embassy_time::{Duration, Instant}; | ||
| 12 | use example_common::*; | 13 | use example_common::*; |
| 13 | 14 | ||
| 14 | #[embassy_executor::main] | 15 | #[embassy_executor::main] |
| @@ -19,36 +20,76 @@ async fn main(_spawner: Spawner) { | |||
| 19 | // Arduino pins D0 and D1 | 20 | // Arduino pins D0 and D1 |
| 20 | // They're connected together with a 1K resistor. | 21 | // They're connected together with a 1K resistor. |
| 21 | #[cfg(feature = "stm32f103c8")] | 22 | #[cfg(feature = "stm32f103c8")] |
| 22 | let (tx, rx, usart, irq) = (p.PA9, p.PA10, p.USART1, interrupt::take!(USART1)); | 23 | let (mut tx, mut rx, mut usart, mut irq) = (p.PA9, p.PA10, p.USART1, interrupt::take!(USART1)); |
| 23 | #[cfg(feature = "stm32g491re")] | 24 | #[cfg(feature = "stm32g491re")] |
| 24 | let (tx, rx, usart, irq) = (p.PC4, p.PC5, p.USART1, interrupt::take!(USART1)); | 25 | let (mut tx, mut rx, mut usart, mut irq) = (p.PC4, p.PC5, p.USART1, interrupt::take!(USART1)); |
| 25 | #[cfg(feature = "stm32g071rb")] | 26 | #[cfg(feature = "stm32g071rb")] |
| 26 | let (tx, rx, usart, irq) = (p.PC4, p.PC5, p.USART1, interrupt::take!(USART1)); | 27 | let (mut tx, mut rx, mut usart, mut irq) = (p.PC4, p.PC5, p.USART1, interrupt::take!(USART1)); |
| 27 | #[cfg(feature = "stm32f429zi")] | 28 | #[cfg(feature = "stm32f429zi")] |
| 28 | let (tx, rx, usart, irq) = (p.PG14, p.PG9, p.USART6, interrupt::take!(USART6)); | 29 | let (mut tx, mut rx, mut usart, mut irq) = (p.PG14, p.PG9, p.USART6, interrupt::take!(USART6)); |
| 29 | #[cfg(feature = "stm32wb55rg")] | 30 | #[cfg(feature = "stm32wb55rg")] |
| 30 | let (tx, rx, usart, irq) = (p.PA2, p.PA3, p.LPUART1, interrupt::take!(LPUART1)); | 31 | let (mut tx, mut rx, mut usart, mut irq) = (p.PA2, p.PA3, p.LPUART1, interrupt::take!(LPUART1)); |
| 31 | #[cfg(feature = "stm32h755zi")] | 32 | #[cfg(feature = "stm32h755zi")] |
| 32 | let (tx, rx, usart, irq) = (p.PB6, p.PB7, p.USART1, interrupt::take!(USART1)); | 33 | let (mut tx, mut rx, mut usart, mut irq) = (p.PB6, p.PB7, p.USART1, interrupt::take!(USART1)); |
| 33 | #[cfg(feature = "stm32u585ai")] | 34 | #[cfg(feature = "stm32u585ai")] |
| 34 | let (tx, rx, usart, irq) = (p.PD8, p.PD9, p.USART3, interrupt::take!(USART3)); | 35 | let (mut tx, mut rx, mut usart, mut irq) = (p.PD8, p.PD9, p.USART3, interrupt::take!(USART3)); |
| 35 | #[cfg(feature = "stm32h563zi")] | 36 | #[cfg(feature = "stm32h563zi")] |
| 36 | let (tx, rx, usart, irq) = (p.PB6, p.PB7, p.LPUART1, interrupt::take!(LPUART1)); | 37 | let (mut tx, mut rx, mut usart, mut irq) = (p.PB6, p.PB7, p.LPUART1, interrupt::take!(LPUART1)); |
| 37 | #[cfg(feature = "stm32c031c6")] | 38 | #[cfg(feature = "stm32c031c6")] |
| 38 | let (tx, rx, usart, irq) = (p.PB6, p.PB7, p.USART1, interrupt::take!(USART1)); | 39 | let (mut tx, mut rx, mut usart, mut irq) = (p.PB6, p.PB7, p.USART1, interrupt::take!(USART1)); |
| 39 | 40 | ||
| 40 | let config = Config::default(); | 41 | { |
| 41 | let mut usart = Uart::new(usart, rx, tx, irq, NoDma, NoDma, config); | 42 | let config = Config::default(); |
| 43 | let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, &mut irq, NoDma, NoDma, config); | ||
| 42 | 44 | ||
| 43 | // We can't send too many bytes, they have to fit in the FIFO. | 45 | // We can't send too many bytes, they have to fit in the FIFO. |
| 44 | // This is because we aren't sending+receiving at the same time. | 46 | // This is because we aren't sending+receiving at the same time. |
| 45 | 47 | ||
| 46 | let data = [0xC0, 0xDE]; | 48 | let data = [0xC0, 0xDE]; |
| 47 | usart.blocking_write(&data).unwrap(); | 49 | usart.blocking_write(&data).unwrap(); |
| 48 | 50 | ||
| 49 | let mut buf = [0; 2]; | 51 | let mut buf = [0; 2]; |
| 50 | usart.blocking_read(&mut buf).unwrap(); | 52 | usart.blocking_read(&mut buf).unwrap(); |
| 51 | assert_eq!(buf, data); | 53 | assert_eq!(buf, data); |
| 54 | } | ||
| 55 | |||
| 56 | // Test that baudrate divider is calculated correctly. | ||
| 57 | // Do it by comparing the time it takes to send a known number of bytes. | ||
| 58 | for baudrate in [ | ||
| 59 | 300, | ||
| 60 | 9600, | ||
| 61 | 115200, | ||
| 62 | 250_000, | ||
| 63 | 337_934, | ||
| 64 | #[cfg(not(feature = "stm32f103c8"))] | ||
| 65 | 1_000_000, | ||
| 66 | #[cfg(not(feature = "stm32f103c8"))] | ||
| 67 | 2_000_000, | ||
| 68 | ] { | ||
| 69 | info!("testing baudrate {}", baudrate); | ||
| 70 | |||
| 71 | let mut config = Config::default(); | ||
| 72 | config.baudrate = baudrate; | ||
| 73 | let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, &mut irq, NoDma, NoDma, config); | ||
| 74 | |||
| 75 | let n = (baudrate as usize / 100).max(64); | ||
| 76 | |||
| 77 | let start = Instant::now(); | ||
| 78 | for _ in 0..n { | ||
| 79 | usart.blocking_write(&[0x00]).unwrap(); | ||
| 80 | } | ||
| 81 | let dur = Instant::now() - start; | ||
| 82 | let want_dur = Duration::from_micros(n as u64 * 10 * 1_000_000 / (baudrate as u64)); | ||
| 83 | let fuzz = want_dur / 5; | ||
| 84 | if dur < want_dur - fuzz || dur > want_dur + fuzz { | ||
| 85 | defmt::panic!( | ||
| 86 | "bad duration for baudrate {}: got {:?} want {:?}", | ||
| 87 | baudrate, | ||
| 88 | dur, | ||
| 89 | want_dur | ||
| 90 | ); | ||
| 91 | } | ||
| 92 | } | ||
| 52 | 93 | ||
| 53 | info!("Test OK"); | 94 | info!("Test OK"); |
| 54 | cortex_m::asm::bkpt(); | 95 | cortex_m::asm::bkpt(); |
diff --git a/tests/stm32/src/bin/usart_dma.rs b/tests/stm32/src/bin/usart_dma.rs index de6cd41d1..62444f0a8 100644 --- a/tests/stm32/src/bin/usart_dma.rs +++ b/tests/stm32/src/bin/usart_dma.rs | |||
| @@ -94,6 +94,9 @@ async fn main(_spawner: Spawner) { | |||
| 94 | let rx_fut = async { | 94 | let rx_fut = async { |
| 95 | rx.read(&mut rx_buf).await.unwrap(); | 95 | rx.read(&mut rx_buf).await.unwrap(); |
| 96 | }; | 96 | }; |
| 97 | |||
| 98 | // note: rx needs to be polled first, to workaround this bug: | ||
| 99 | // https://github.com/embassy-rs/embassy/issues/1426 | ||
| 97 | join(rx_fut, tx_fut).await; | 100 | join(rx_fut, tx_fut).await; |
| 98 | 101 | ||
| 99 | assert_eq!(tx_buf, rx_buf); | 102 | assert_eq!(tx_buf, rx_buf); |
diff --git a/tests/stm32/src/bin/usart_rx_ringbuffered.rs b/tests/stm32/src/bin/usart_rx_ringbuffered.rs index 2c4a8fdf4..9d75dbe55 100644 --- a/tests/stm32/src/bin/usart_rx_ringbuffered.rs +++ b/tests/stm32/src/bin/usart_rx_ringbuffered.rs | |||
| @@ -145,13 +145,16 @@ async fn main(spawner: Spawner) { | |||
| 145 | 145 | ||
| 146 | #[embassy_executor::task] | 146 | #[embassy_executor::task] |
| 147 | async fn transmit_task(mut tx: UartTx<'static, board::Uart, board::TxDma>) { | 147 | async fn transmit_task(mut tx: UartTx<'static, board::Uart, board::TxDma>) { |
| 148 | // workaround https://github.com/embassy-rs/embassy/issues/1426 | ||
| 149 | Timer::after(Duration::from_millis(100) as _).await; | ||
| 150 | |||
| 148 | let mut rng = ChaCha8Rng::seed_from_u64(1337); | 151 | let mut rng = ChaCha8Rng::seed_from_u64(1337); |
| 149 | 152 | ||
| 150 | info!("Starting random transmissions into void..."); | 153 | info!("Starting random transmissions into void..."); |
| 151 | 154 | ||
| 152 | let mut i: u8 = 0; | 155 | let mut i: u8 = 0; |
| 153 | loop { | 156 | loop { |
| 154 | let mut buf = [0; 32]; | 157 | let mut buf = [0; 256]; |
| 155 | let len = 1 + (rng.next_u32() as usize % buf.len()); | 158 | let len = 1 + (rng.next_u32() as usize % buf.len()); |
| 156 | for b in &mut buf[..len] { | 159 | for b in &mut buf[..len] { |
| 157 | *b = i; | 160 | *b = i; |
| @@ -172,7 +175,7 @@ async fn receive_task(mut rx: RingBufferedUartRx<'static, board::Uart, board::Rx | |||
| 172 | let mut i = 0; | 175 | let mut i = 0; |
| 173 | let mut expected = 0; | 176 | let mut expected = 0; |
| 174 | loop { | 177 | loop { |
| 175 | let mut buf = [0; 100]; | 178 | let mut buf = [0; 256]; |
| 176 | let max_len = 1 + (rng.next_u32() as usize % buf.len()); | 179 | let max_len = 1 + (rng.next_u32() as usize % buf.len()); |
| 177 | let received = match rx.read(&mut buf[..max_len]).await { | 180 | let received = match rx.read(&mut buf[..max_len]).await { |
| 178 | Ok(r) => r, | 181 | Ok(r) => r, |
diff --git a/tests/stm32/src/example_common.rs b/tests/stm32/src/example_common.rs index a4f8668c7..3d150da60 100644 --- a/tests/stm32/src/example_common.rs +++ b/tests/stm32/src/example_common.rs | |||
| @@ -16,5 +16,10 @@ pub fn config() -> Config { | |||
| 16 | config.rcc.pll1.q_ck = Some(Hertz(100_000_000)); | 16 | config.rcc.pll1.q_ck = Some(Hertz(100_000_000)); |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | #[cfg(feature = "stm32u585ai")] | ||
| 20 | { | ||
| 21 | config.rcc.mux = embassy_stm32::rcc::ClockSrc::MSI(embassy_stm32::rcc::MSIRange::Range48mhz); | ||
| 22 | } | ||
| 23 | |||
| 19 | config | 24 | config |
| 20 | } | 25 | } |
