diff options
| author | Tyler <[email protected]> | 2023-07-16 19:08:01 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-07-16 19:08:01 -0500 |
| commit | 6d8a5c6c20953c998df6ddd26906abe520df946d (patch) | |
| tree | 32cfdf85a1aa132cb0f1aac56a934ceed93fc597 /tests | |
| parent | 3aedbce5c2775ff1ab10c3ca95ea1311043f4be4 (diff) | |
| parent | c7ec45a004750f590c1d9ea4a721972efe133b8e (diff) | |
Merge pull request #2 from embassy-rs/main
Pull changes from base embassy repo
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/nrf/Cargo.toml | 4 | ||||
| -rw-r--r-- | tests/nrf/src/bin/wifi_esp_hosted_perf.rs | 6 | ||||
| -rw-r--r-- | tests/riscv32/Cargo.toml | 2 | ||||
| -rw-r--r-- | tests/rp/Cargo.toml | 8 | ||||
| -rw-r--r-- | tests/rp/src/bin/adc.rs | 86 | ||||
| -rw-r--r-- | tests/rp/src/bin/cyw43-perf.rs | 10 | ||||
| -rw-r--r-- | tests/rp/src/bin/gpio.rs | 36 | ||||
| -rw-r--r-- | tests/rp/src/bin/pio_irq.rs | 55 | ||||
| -rw-r--r-- | tests/stm32/Cargo.toml | 30 | ||||
| -rw-r--r-- | tests/stm32/src/bin/can.rs | 7 | ||||
| -rw-r--r-- | tests/stm32/src/bin/gpio.rs | 36 | ||||
| -rw-r--r-- | tests/stm32/src/bin/rtc.rs | 2 | ||||
| -rw-r--r-- | tests/stm32/src/bin/wpan_ble.rs (renamed from tests/stm32/src/bin/tl_mbox.rs) | 2 | ||||
| -rw-r--r-- | tests/stm32/src/bin/wpan_mac.rs | 108 |
14 files changed, 360 insertions, 32 deletions
diff --git a/tests/nrf/Cargo.toml b/tests/nrf/Cargo.toml index 4f9ecc47a..7ce51aa5e 100644 --- a/tests/nrf/Cargo.toml +++ b/tests/nrf/Cargo.toml | |||
| @@ -10,12 +10,12 @@ teleprobe-meta = "1" | |||
| 10 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } | 10 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } |
| 11 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt", "nightly"] } | 11 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt", "nightly"] } |
| 12 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "nightly", "integrated-timers"] } | 12 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "nightly", "integrated-timers"] } |
| 13 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "nightly", "defmt-timestamp-uptime"] } | 13 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "nightly", "unstable-traits", "defmt-timestamp-uptime"] } |
| 14 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nightly", "unstable-traits", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } | 14 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nightly", "unstable-traits", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } |
| 15 | embedded-io = { version = "0.4.0", features = ["async"] } | 15 | embedded-io = { version = "0.4.0", features = ["async"] } |
| 16 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "nightly"] } | 16 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "nightly"] } |
| 17 | embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-hosted", features = ["defmt"] } | 17 | embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-hosted", features = ["defmt"] } |
| 18 | embedded-hal-async = { version = "0.2.0-alpha.1" } | 18 | embedded-hal-async = { version = "0.2.0-alpha.2" } |
| 19 | static_cell = { version = "1.1", features = [ "nightly" ] } | 19 | static_cell = { version = "1.1", features = [ "nightly" ] } |
| 20 | 20 | ||
| 21 | defmt = "0.3" | 21 | defmt = "0.3" |
diff --git a/tests/nrf/src/bin/wifi_esp_hosted_perf.rs b/tests/nrf/src/bin/wifi_esp_hosted_perf.rs index 277b985c5..398ab9d27 100644 --- a/tests/nrf/src/bin/wifi_esp_hosted_perf.rs +++ b/tests/nrf/src/bin/wifi_esp_hosted_perf.rs | |||
| @@ -14,7 +14,7 @@ use embassy_nrf::gpio::{AnyPin, Input, Level, Output, OutputDrive, Pin, Pull}; | |||
| 14 | use embassy_nrf::rng::Rng; | 14 | use embassy_nrf::rng::Rng; |
| 15 | use embassy_nrf::spim::{self, Spim}; | 15 | use embassy_nrf::spim::{self, Spim}; |
| 16 | use embassy_nrf::{bind_interrupts, peripherals}; | 16 | use embassy_nrf::{bind_interrupts, peripherals}; |
| 17 | use embassy_time::{with_timeout, Duration, Timer}; | 17 | use embassy_time::{with_timeout, Delay, Duration, Timer}; |
| 18 | use embedded_hal_async::spi::ExclusiveDevice; | 18 | use embedded_hal_async::spi::ExclusiveDevice; |
| 19 | use static_cell::make_static; | 19 | use static_cell::make_static; |
| 20 | use {defmt_rtt as _, embassy_net_esp_hosted as hosted, panic_probe as _}; | 20 | use {defmt_rtt as _, embassy_net_esp_hosted as hosted, panic_probe as _}; |
| @@ -30,7 +30,7 @@ bind_interrupts!(struct Irqs { | |||
| 30 | async fn wifi_task( | 30 | async fn wifi_task( |
| 31 | runner: hosted::Runner< | 31 | runner: hosted::Runner< |
| 32 | 'static, | 32 | 'static, |
| 33 | ExclusiveDevice<Spim<'static, peripherals::SPI3>, Output<'static, peripherals::P0_31>>, | 33 | ExclusiveDevice<Spim<'static, peripherals::SPI3>, Output<'static, peripherals::P0_31>, Delay>, |
| 34 | Input<'static, AnyPin>, | 34 | Input<'static, AnyPin>, |
| 35 | Output<'static, peripherals::P1_05>, | 35 | Output<'static, peripherals::P1_05>, |
| 36 | >, | 36 | >, |
| @@ -63,7 +63,7 @@ async fn main(spawner: Spawner) { | |||
| 63 | config.frequency = spim::Frequency::M32; | 63 | config.frequency = spim::Frequency::M32; |
| 64 | config.mode = spim::MODE_2; // !!! | 64 | config.mode = spim::MODE_2; // !!! |
| 65 | let spi = spim::Spim::new(p.SPI3, Irqs, sck, miso, mosi, config); | 65 | let spi = spim::Spim::new(p.SPI3, Irqs, sck, miso, mosi, config); |
| 66 | let spi = ExclusiveDevice::new(spi, cs); | 66 | let spi = ExclusiveDevice::new(spi, cs, Delay); |
| 67 | 67 | ||
| 68 | let (device, mut control, runner) = embassy_net_esp_hosted::new( | 68 | let (device, mut control, runner) = embassy_net_esp_hosted::new( |
| 69 | make_static!(embassy_net_esp_hosted::State::new()), | 69 | make_static!(embassy_net_esp_hosted::State::new()), |
diff --git a/tests/riscv32/Cargo.toml b/tests/riscv32/Cargo.toml index 81bfdfab6..61f886c0c 100644 --- a/tests/riscv32/Cargo.toml +++ b/tests/riscv32/Cargo.toml | |||
| @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" | |||
| 8 | critical-section = { version = "1.1.1", features = ["restore-state-bool"] } | 8 | critical-section = { version = "1.1.1", features = ["restore-state-bool"] } |
| 9 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync" } | 9 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync" } |
| 10 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-riscv32", "nightly", "executor-thread"] } | 10 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-riscv32", "nightly", "executor-thread"] } |
| 11 | embassy-time = { version = "0.1.0", path = "../../embassy-time" } | 11 | embassy-time = { version = "0.1.2", path = "../../embassy-time" } |
| 12 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } | 12 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } |
| 13 | 13 | ||
| 14 | riscv-rt = "0.11" | 14 | riscv-rt = "0.11" |
diff --git a/tests/rp/Cargo.toml b/tests/rp/Cargo.toml index 180d0ebbe..f2c902787 100644 --- a/tests/rp/Cargo.toml +++ b/tests/rp/Cargo.toml | |||
| @@ -9,7 +9,7 @@ teleprobe-meta = "1.1" | |||
| 9 | 9 | ||
| 10 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 10 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 11 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 11 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 12 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt"] } | 12 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt"] } |
| 13 | embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["nightly", "defmt", "unstable-pac", "unstable-traits", "time-driver", "critical-section-impl", "intrinsics", "rom-v2-intrinsics", "run-from-ram"] } | 13 | embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["nightly", "defmt", "unstable-pac", "unstable-traits", "time-driver", "critical-section-impl", "intrinsics", "rom-v2-intrinsics", "run-from-ram"] } |
| 14 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } | 14 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } |
| 15 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "udp", "dhcpv4", "medium-ethernet"] } | 15 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "udp", "dhcpv4", "medium-ethernet"] } |
| @@ -22,13 +22,15 @@ defmt-rtt = "0.4" | |||
| 22 | cortex-m = { version = "0.7.6" } | 22 | cortex-m = { version = "0.7.6" } |
| 23 | cortex-m-rt = "0.7.0" | 23 | cortex-m-rt = "0.7.0" |
| 24 | embedded-hal = "0.2.6" | 24 | embedded-hal = "0.2.6" |
| 25 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.10" } | 25 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.11" } |
| 26 | embedded-hal-async = { version = "=0.2.0-alpha.1" } | 26 | embedded-hal-async = { version = "=0.2.0-alpha.2" } |
| 27 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } | 27 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } |
| 28 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 28 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
| 29 | embedded-io = { version = "0.4.0", features = ["async"] } | 29 | embedded-io = { version = "0.4.0", features = ["async"] } |
| 30 | embedded-storage = { version = "0.3" } | 30 | embedded-storage = { version = "0.3" } |
| 31 | static_cell = { version = "1.1", features = ["nightly"]} | 31 | static_cell = { version = "1.1", features = ["nightly"]} |
| 32 | pio = "0.2" | ||
| 33 | pio-proc = "0.2" | ||
| 32 | 34 | ||
| 33 | [profile.dev] | 35 | [profile.dev] |
| 34 | debug = 2 | 36 | debug = 2 |
diff --git a/tests/rp/src/bin/adc.rs b/tests/rp/src/bin/adc.rs new file mode 100644 index 000000000..e659844ae --- /dev/null +++ b/tests/rp/src/bin/adc.rs | |||
| @@ -0,0 +1,86 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | #[path = "../common.rs"] | ||
| 5 | mod common; | ||
| 6 | |||
| 7 | use defmt::*; | ||
| 8 | use embassy_executor::Spawner; | ||
| 9 | use embassy_rp::adc::{Adc, Config, InterruptHandler, Pin}; | ||
| 10 | use embassy_rp::bind_interrupts; | ||
| 11 | use embassy_rp::gpio::Pull; | ||
| 12 | use {defmt_rtt as _, panic_probe as _}; | ||
| 13 | |||
| 14 | bind_interrupts!(struct Irqs { | ||
| 15 | ADC_IRQ_FIFO => InterruptHandler; | ||
| 16 | }); | ||
| 17 | |||
| 18 | #[embassy_executor::main] | ||
| 19 | async fn main(_spawner: Spawner) { | ||
| 20 | let mut p = embassy_rp::init(Default::default()); | ||
| 21 | let mut adc = Adc::new(p.ADC, Irqs, Config::default()); | ||
| 22 | |||
| 23 | { | ||
| 24 | { | ||
| 25 | let mut p = Pin::new(&mut p.PIN_26, Pull::Down); | ||
| 26 | defmt::assert!(adc.blocking_read(&mut p).unwrap() < 0b01_0000_0000); | ||
| 27 | defmt::assert!(adc.read(&mut p).await.unwrap() < 0b01_0000_0000); | ||
| 28 | } | ||
| 29 | { | ||
| 30 | let mut p = Pin::new(&mut p.PIN_26, Pull::Up); | ||
| 31 | defmt::assert!(adc.blocking_read(&mut p).unwrap() > 0b11_0000_0000); | ||
| 32 | defmt::assert!(adc.read(&mut p).await.unwrap() > 0b11_0000_0000); | ||
| 33 | } | ||
| 34 | } | ||
| 35 | // not bothering with async reads from now on | ||
| 36 | { | ||
| 37 | { | ||
| 38 | let mut p = Pin::new(&mut p.PIN_27, Pull::Down); | ||
| 39 | defmt::assert!(adc.blocking_read(&mut p).unwrap() < 0b01_0000_0000); | ||
| 40 | } | ||
| 41 | { | ||
| 42 | let mut p = Pin::new(&mut p.PIN_27, Pull::Up); | ||
| 43 | defmt::assert!(adc.blocking_read(&mut p).unwrap() > 0b11_0000_0000); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | { | ||
| 47 | { | ||
| 48 | let mut p = Pin::new(&mut p.PIN_28, Pull::Down); | ||
| 49 | defmt::assert!(adc.blocking_read(&mut p).unwrap() < 0b01_0000_0000); | ||
| 50 | } | ||
| 51 | { | ||
| 52 | let mut p = Pin::new(&mut p.PIN_28, Pull::Up); | ||
| 53 | defmt::assert!(adc.blocking_read(&mut p).unwrap() > 0b11_0000_0000); | ||
| 54 | } | ||
| 55 | } | ||
| 56 | { | ||
| 57 | // gp29 is connected to vsys through a 200k/100k divider, | ||
| 58 | // adding pulls should change the value | ||
| 59 | let low = { | ||
| 60 | let mut p = Pin::new(&mut p.PIN_29, Pull::Down); | ||
| 61 | adc.blocking_read(&mut p).unwrap() | ||
| 62 | }; | ||
| 63 | let none = { | ||
| 64 | let mut p = Pin::new(&mut p.PIN_29, Pull::None); | ||
| 65 | adc.blocking_read(&mut p).unwrap() | ||
| 66 | }; | ||
| 67 | let up = { | ||
| 68 | let mut p = Pin::new(&mut p.PIN_29, Pull::Up); | ||
| 69 | adc.blocking_read(&mut p).unwrap() | ||
| 70 | }; | ||
| 71 | defmt::assert!(low < none); | ||
| 72 | defmt::assert!(none < up); | ||
| 73 | } | ||
| 74 | |||
| 75 | let temp = convert_to_celsius(adc.read_temperature().await.unwrap()); | ||
| 76 | defmt::assert!(temp > 0.0); | ||
| 77 | defmt::assert!(temp < 60.0); | ||
| 78 | |||
| 79 | info!("Test OK"); | ||
| 80 | cortex_m::asm::bkpt(); | ||
| 81 | } | ||
| 82 | |||
| 83 | fn convert_to_celsius(raw_temp: u16) -> f32 { | ||
| 84 | // According to chapter 4.9.5. Temperature Sensor in RP2040 datasheet | ||
| 85 | 27.0 - (raw_temp as f32 * 3.3 / 4096.0 - 0.706) / 0.001721 as f32 | ||
| 86 | } | ||
diff --git a/tests/rp/src/bin/cyw43-perf.rs b/tests/rp/src/bin/cyw43-perf.rs index 1ecaab266..bc127e2e5 100644 --- a/tests/rp/src/bin/cyw43-perf.rs +++ b/tests/rp/src/bin/cyw43-perf.rs | |||
| @@ -12,12 +12,16 @@ use embassy_net::tcp::TcpSocket; | |||
| 12 | use embassy_net::{Config, Ipv4Address, Stack, StackResources}; | 12 | use embassy_net::{Config, Ipv4Address, Stack, StackResources}; |
| 13 | use embassy_rp::gpio::{Level, Output}; | 13 | use embassy_rp::gpio::{Level, Output}; |
| 14 | use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0}; | 14 | use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0}; |
| 15 | use embassy_rp::pio::Pio; | 15 | use embassy_rp::pio::{InterruptHandler, Pio}; |
| 16 | use embassy_rp::rom_data; | 16 | use embassy_rp::{bind_interrupts, rom_data}; |
| 17 | use embassy_time::{with_timeout, Duration, Timer}; | 17 | use embassy_time::{with_timeout, Duration, Timer}; |
| 18 | use static_cell::make_static; | 18 | use static_cell::make_static; |
| 19 | use {defmt_rtt as _, panic_probe as _}; | 19 | use {defmt_rtt as _, panic_probe as _}; |
| 20 | 20 | ||
| 21 | bind_interrupts!(struct Irqs { | ||
| 22 | PIO0_IRQ_0 => InterruptHandler<PIO0>; | ||
| 23 | }); | ||
| 24 | |||
| 21 | teleprobe_meta::timeout!(120); | 25 | teleprobe_meta::timeout!(120); |
| 22 | 26 | ||
| 23 | #[embassy_executor::task] | 27 | #[embassy_executor::task] |
| @@ -51,7 +55,7 @@ async fn main(spawner: Spawner) { | |||
| 51 | 55 | ||
| 52 | let pwr = Output::new(p.PIN_23, Level::Low); | 56 | let pwr = Output::new(p.PIN_23, Level::Low); |
| 53 | let cs = Output::new(p.PIN_25, Level::High); | 57 | let cs = Output::new(p.PIN_25, Level::High); |
| 54 | let mut pio = Pio::new(p.PIO0); | 58 | let mut pio = Pio::new(p.PIO0, Irqs); |
| 55 | let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); | 59 | let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); |
| 56 | 60 | ||
| 57 | let state = make_static!(cyw43::State::new()); | 61 | let state = make_static!(cyw43::State::new()); |
diff --git a/tests/rp/src/bin/gpio.rs b/tests/rp/src/bin/gpio.rs index 51112d319..946b7dc88 100644 --- a/tests/rp/src/bin/gpio.rs +++ b/tests/rp/src/bin/gpio.rs | |||
| @@ -21,14 +21,46 @@ async fn main(_spawner: Spawner) { | |||
| 21 | let b = Input::new(&mut b, Pull::None); | 21 | let b = Input::new(&mut b, Pull::None); |
| 22 | 22 | ||
| 23 | { | 23 | { |
| 24 | let _a = Output::new(&mut a, Level::Low); | 24 | let a = Output::new(&mut a, Level::Low); |
| 25 | delay(); | 25 | delay(); |
| 26 | assert!(b.is_low()); | 26 | assert!(b.is_low()); |
| 27 | assert!(!b.is_high()); | ||
| 28 | assert!(a.is_set_low()); | ||
| 29 | assert!(!a.is_set_high()); | ||
| 27 | } | 30 | } |
| 28 | { | 31 | { |
| 29 | let _a = Output::new(&mut a, Level::High); | 32 | let mut a = Output::new(&mut a, Level::High); |
| 30 | delay(); | 33 | delay(); |
| 34 | assert!(!b.is_low()); | ||
| 31 | assert!(b.is_high()); | 35 | assert!(b.is_high()); |
| 36 | assert!(!a.is_set_low()); | ||
| 37 | assert!(a.is_set_high()); | ||
| 38 | |||
| 39 | // Test is_set_low / is_set_high | ||
| 40 | a.set_low(); | ||
| 41 | delay(); | ||
| 42 | assert!(b.is_low()); | ||
| 43 | assert!(a.is_set_low()); | ||
| 44 | assert!(!a.is_set_high()); | ||
| 45 | |||
| 46 | a.set_high(); | ||
| 47 | delay(); | ||
| 48 | assert!(b.is_high()); | ||
| 49 | assert!(!a.is_set_low()); | ||
| 50 | assert!(a.is_set_high()); | ||
| 51 | |||
| 52 | // Test toggle | ||
| 53 | a.toggle(); | ||
| 54 | delay(); | ||
| 55 | assert!(b.is_low()); | ||
| 56 | assert!(a.is_set_low()); | ||
| 57 | assert!(!a.is_set_high()); | ||
| 58 | |||
| 59 | a.toggle(); | ||
| 60 | delay(); | ||
| 61 | assert!(b.is_high()); | ||
| 62 | assert!(!a.is_set_low()); | ||
| 63 | assert!(a.is_set_high()); | ||
| 32 | } | 64 | } |
| 33 | } | 65 | } |
| 34 | 66 | ||
diff --git a/tests/rp/src/bin/pio_irq.rs b/tests/rp/src/bin/pio_irq.rs new file mode 100644 index 000000000..45004424a --- /dev/null +++ b/tests/rp/src/bin/pio_irq.rs | |||
| @@ -0,0 +1,55 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | #[path = "../common.rs"] | ||
| 5 | mod common; | ||
| 6 | |||
| 7 | use defmt::info; | ||
| 8 | use embassy_executor::Spawner; | ||
| 9 | use embassy_rp::bind_interrupts; | ||
| 10 | use embassy_rp::peripherals::PIO0; | ||
| 11 | use embassy_rp::pio::{Config, InterruptHandler, Pio}; | ||
| 12 | use embassy_rp::relocate::RelocatedProgram; | ||
| 13 | use {defmt_rtt as _, panic_probe as _}; | ||
| 14 | |||
| 15 | bind_interrupts!(struct Irqs { | ||
| 16 | PIO0_IRQ_0 => InterruptHandler<PIO0>; | ||
| 17 | }); | ||
| 18 | |||
| 19 | #[embassy_executor::main] | ||
| 20 | async fn main(_spawner: Spawner) { | ||
| 21 | let p = embassy_rp::init(Default::default()); | ||
| 22 | let pio = p.PIO0; | ||
| 23 | let Pio { | ||
| 24 | mut common, | ||
| 25 | sm0: mut sm, | ||
| 26 | irq_flags, | ||
| 27 | .. | ||
| 28 | } = Pio::new(pio, Irqs); | ||
| 29 | |||
| 30 | let prg = pio_proc::pio_asm!( | ||
| 31 | "irq set 0", | ||
| 32 | "irq wait 0", | ||
| 33 | "irq set 1", | ||
| 34 | // pause execution here | ||
| 35 | "irq wait 1", | ||
| 36 | ); | ||
| 37 | |||
| 38 | let relocated = RelocatedProgram::new(&prg.program); | ||
| 39 | let mut cfg = Config::default(); | ||
| 40 | cfg.use_program(&common.load_program(&relocated), &[]); | ||
| 41 | sm.set_config(&cfg); | ||
| 42 | sm.set_enable(true); | ||
| 43 | |||
| 44 | // not using the wait futures on purpose because they clear the irq bits, | ||
| 45 | // and we want to see in which order they are set. | ||
| 46 | while !irq_flags.check(0) {} | ||
| 47 | cortex_m::asm::nop(); | ||
| 48 | assert!(!irq_flags.check(1)); | ||
| 49 | irq_flags.clear(0); | ||
| 50 | cortex_m::asm::nop(); | ||
| 51 | assert!(irq_flags.check(1)); | ||
| 52 | |||
| 53 | info!("Test OK"); | ||
| 54 | cortex_m::asm::bkpt(); | ||
| 55 | } | ||
diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml index c2422f7bc..3007cd1e6 100644 --- a/tests/stm32/Cargo.toml +++ b/tests/stm32/Cargo.toml | |||
| @@ -12,14 +12,16 @@ stm32g071rb = ["embassy-stm32/stm32g071rb", "not-gpdma"] # Nucleo | |||
| 12 | stm32c031c6 = ["embassy-stm32/stm32c031c6", "not-gpdma"] # Nucleo | 12 | stm32c031c6 = ["embassy-stm32/stm32c031c6", "not-gpdma"] # Nucleo |
| 13 | stm32g491re = ["embassy-stm32/stm32g491re", "not-gpdma"] # Nucleo | 13 | stm32g491re = ["embassy-stm32/stm32g491re", "not-gpdma"] # Nucleo |
| 14 | stm32h755zi = ["embassy-stm32/stm32h755zi-cm7", "not-gpdma"] # Nucleo | 14 | stm32h755zi = ["embassy-stm32/stm32h755zi-cm7", "not-gpdma"] # Nucleo |
| 15 | stm32wb55rg = ["embassy-stm32/stm32wb55rg", "not-gpdma", "ble" ] # Nucleo | 15 | stm32wb55rg = ["embassy-stm32/stm32wb55rg", "not-gpdma", "ble", "mac" ] # Nucleo |
| 16 | stm32h563zi = ["embassy-stm32/stm32h563zi"] # Nucleo | 16 | stm32h563zi = ["embassy-stm32/stm32h563zi"] # Nucleo |
| 17 | stm32u585ai = ["embassy-stm32/stm32u585ai"] # IoT board | 17 | stm32u585ai = ["embassy-stm32/stm32u585ai"] # IoT board |
| 18 | 18 | ||
| 19 | sdmmc = [] | 19 | sdmmc = [] |
| 20 | chrono = ["embassy-stm32/chrono", "dep:chrono"] | 20 | chrono = ["embassy-stm32/chrono", "dep:chrono"] |
| 21 | can = [] | 21 | can = [] |
| 22 | ble = ["dep:embassy-stm32-wpan"] | 22 | ble = ["dep:embassy-stm32-wpan", "embassy-stm32-wpan/ble"] |
| 23 | mac = ["dep:embassy-stm32-wpan", "embassy-stm32-wpan/mac"] | ||
| 24 | embassy-stm32-wpan = [] | ||
| 23 | not-gpdma = [] | 25 | not-gpdma = [] |
| 24 | 26 | ||
| 25 | [dependencies] | 27 | [dependencies] |
| @@ -27,7 +29,7 @@ teleprobe-meta = "1" | |||
| 27 | 29 | ||
| 28 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 30 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 29 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 31 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 30 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "tick-hz-32_768", "defmt-timestamp-uptime"] } | 32 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "tick-hz-32_768", "defmt-timestamp-uptime"] } |
| 31 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "memory-x", "time-driver-any"] } | 33 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "memory-x", "time-driver-any"] } |
| 32 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } | 34 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } |
| 33 | embassy-stm32-wpan = { version = "0.1.0", path = "../../embassy-stm32-wpan", optional = true, features = ["defmt", "stm32wb55rg", "ble"] } | 35 | embassy-stm32-wpan = { version = "0.1.0", path = "../../embassy-stm32-wpan", optional = true, features = ["defmt", "stm32wb55rg", "ble"] } |
| @@ -38,25 +40,17 @@ defmt-rtt = "0.4" | |||
| 38 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } | 40 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } |
| 39 | cortex-m-rt = "0.7.0" | 41 | cortex-m-rt = "0.7.0" |
| 40 | embedded-hal = "0.2.6" | 42 | embedded-hal = "0.2.6" |
| 41 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.10" } | 43 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.11" } |
| 42 | embedded-hal-async = { version = "=0.2.0-alpha.1" } | 44 | embedded-hal-async = { version = "=0.2.0-alpha.2" } |
| 43 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } | 45 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } |
| 44 | rand_core = { version = "0.6", default-features = false } | 46 | rand_core = { version = "0.6", default-features = false } |
| 45 | rand_chacha = { version = "0.3", default-features = false } | 47 | rand_chacha = { version = "0.3", default-features = false } |
| 46 | 48 | ||
| 47 | chrono = { version = "^0.4", default-features = false, optional = true} | 49 | chrono = { version = "^0.4", default-features = false, optional = true} |
| 48 | 50 | ||
| 49 | [patch.crates-io] | ||
| 50 | stm32wb-hci = { git = "https://github.com/OueslatiGhaith/stm32wb-hci", rev = "9f663be"} | ||
| 51 | |||
| 52 | # BEGIN TESTS | 51 | # BEGIN TESTS |
| 53 | # Generated by gen_test.py. DO NOT EDIT. | 52 | # Generated by gen_test.py. DO NOT EDIT. |
| 54 | [[bin]] | 53 | [[bin]] |
| 55 | name = "tl_mbox" | ||
| 56 | path = "src/bin/tl_mbox.rs" | ||
| 57 | required-features = [ "ble",] | ||
| 58 | |||
| 59 | [[bin]] | ||
| 60 | name = "can" | 54 | name = "can" |
| 61 | path = "src/bin/can.rs" | 55 | path = "src/bin/can.rs" |
| 62 | required-features = [ "can",] | 56 | required-features = [ "can",] |
| @@ -106,6 +100,16 @@ name = "usart_rx_ringbuffered" | |||
| 106 | path = "src/bin/usart_rx_ringbuffered.rs" | 100 | path = "src/bin/usart_rx_ringbuffered.rs" |
| 107 | required-features = [ "not-gpdma",] | 101 | required-features = [ "not-gpdma",] |
| 108 | 102 | ||
| 103 | [[bin]] | ||
| 104 | name = "wpan_ble" | ||
| 105 | path = "src/bin/wpan_ble.rs" | ||
| 106 | required-features = [ "ble",] | ||
| 107 | |||
| 108 | [[bin]] | ||
| 109 | name = "wpan_mac" | ||
| 110 | path = "src/bin/wpan_mac.rs" | ||
| 111 | required-features = [ "mac",] | ||
| 112 | |||
| 109 | # END TESTS | 113 | # END TESTS |
| 110 | 114 | ||
| 111 | [profile.dev] | 115 | [profile.dev] |
diff --git a/tests/stm32/src/bin/can.rs b/tests/stm32/src/bin/can.rs index 33d63d546..8bdd3c24f 100644 --- a/tests/stm32/src/bin/can.rs +++ b/tests/stm32/src/bin/can.rs | |||
| @@ -43,10 +43,13 @@ async fn main(_spawner: Spawner) { | |||
| 43 | 43 | ||
| 44 | info!("Configuring can..."); | 44 | info!("Configuring can..."); |
| 45 | 45 | ||
| 46 | can.modify_filters().enable_bank(0, Fifo::Fifo0, Mask32::accept_all()); | 46 | can.as_mut() |
| 47 | .modify_filters() | ||
| 48 | .enable_bank(0, Fifo::Fifo0, Mask32::accept_all()); | ||
| 47 | 49 | ||
| 48 | can.set_bitrate(1_000_000); | 50 | can.set_bitrate(1_000_000); |
| 49 | can.modify_config() | 51 | can.as_mut() |
| 52 | .modify_config() | ||
| 50 | .set_loopback(true) // Receive own frames | 53 | .set_loopback(true) // Receive own frames |
| 51 | .set_silent(true) | 54 | .set_silent(true) |
| 52 | // .set_bit_timing(0x001c0003) | 55 | // .set_bit_timing(0x001c0003) |
diff --git a/tests/stm32/src/bin/gpio.rs b/tests/stm32/src/bin/gpio.rs index 67f44317e..aad174431 100644 --- a/tests/stm32/src/bin/gpio.rs +++ b/tests/stm32/src/bin/gpio.rs | |||
| @@ -40,14 +40,46 @@ async fn main(_spawner: Spawner) { | |||
| 40 | let b = Input::new(&mut b, Pull::None); | 40 | let b = Input::new(&mut b, Pull::None); |
| 41 | 41 | ||
| 42 | { | 42 | { |
| 43 | let _a = Output::new(&mut a, Level::Low, Speed::Low); | 43 | let a = Output::new(&mut a, Level::Low, Speed::Low); |
| 44 | delay(); | 44 | delay(); |
| 45 | assert!(b.is_low()); | 45 | assert!(b.is_low()); |
| 46 | assert!(!b.is_high()); | ||
| 47 | assert!(a.is_set_low()); | ||
| 48 | assert!(!a.is_set_high()); | ||
| 46 | } | 49 | } |
| 47 | { | 50 | { |
| 48 | let _a = Output::new(&mut a, Level::High, Speed::Low); | 51 | let mut a = Output::new(&mut a, Level::High, Speed::Low); |
| 49 | delay(); | 52 | delay(); |
| 53 | assert!(!b.is_low()); | ||
| 50 | assert!(b.is_high()); | 54 | assert!(b.is_high()); |
| 55 | assert!(!a.is_set_low()); | ||
| 56 | assert!(a.is_set_high()); | ||
| 57 | |||
| 58 | // Test is_set_low / is_set_high | ||
| 59 | a.set_low(); | ||
| 60 | delay(); | ||
| 61 | assert!(b.is_low()); | ||
| 62 | assert!(a.is_set_low()); | ||
| 63 | assert!(!a.is_set_high()); | ||
| 64 | |||
| 65 | a.set_high(); | ||
| 66 | delay(); | ||
| 67 | assert!(b.is_high()); | ||
| 68 | assert!(!a.is_set_low()); | ||
| 69 | assert!(a.is_set_high()); | ||
| 70 | |||
| 71 | // Test toggle | ||
| 72 | a.toggle(); | ||
| 73 | delay(); | ||
| 74 | assert!(b.is_low()); | ||
| 75 | assert!(a.is_set_low()); | ||
| 76 | assert!(!a.is_set_high()); | ||
| 77 | |||
| 78 | a.toggle(); | ||
| 79 | delay(); | ||
| 80 | assert!(b.is_high()); | ||
| 81 | assert!(!a.is_set_low()); | ||
| 82 | assert!(a.is_set_high()); | ||
| 51 | } | 83 | } |
| 52 | } | 84 | } |
| 53 | 85 | ||
diff --git a/tests/stm32/src/bin/rtc.rs b/tests/stm32/src/bin/rtc.rs index 582df5753..194b153d5 100644 --- a/tests/stm32/src/bin/rtc.rs +++ b/tests/stm32/src/bin/rtc.rs | |||
| @@ -1,3 +1,5 @@ | |||
| 1 | // required-features: chrono | ||
| 2 | |||
| 1 | #![no_std] | 3 | #![no_std] |
| 2 | #![no_main] | 4 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 5 | #![feature(type_alias_impl_trait)] |
diff --git a/tests/stm32/src/bin/tl_mbox.rs b/tests/stm32/src/bin/wpan_ble.rs index af3832709..3ad8aca4e 100644 --- a/tests/stm32/src/bin/tl_mbox.rs +++ b/tests/stm32/src/bin/wpan_ble.rs | |||
| @@ -64,7 +64,7 @@ async fn main(spawner: Spawner) { | |||
| 64 | version_major, version_minor, subversion, sram2a_size, sram2b_size | 64 | version_major, version_minor, subversion, sram2a_size, sram2b_size |
| 65 | ); | 65 | ); |
| 66 | 66 | ||
| 67 | mbox.sys_subsystem.shci_c2_ble_init(Default::default()).await; | 67 | let _ = mbox.sys_subsystem.shci_c2_ble_init(Default::default()).await; |
| 68 | 68 | ||
| 69 | info!("resetting BLE..."); | 69 | info!("resetting BLE..."); |
| 70 | mbox.ble_subsystem.reset().await; | 70 | mbox.ble_subsystem.reset().await; |
diff --git a/tests/stm32/src/bin/wpan_mac.rs b/tests/stm32/src/bin/wpan_mac.rs new file mode 100644 index 000000000..cfa0aca3b --- /dev/null +++ b/tests/stm32/src/bin/wpan_mac.rs | |||
| @@ -0,0 +1,108 @@ | |||
| 1 | // required-features: mac | ||
| 2 | |||
| 3 | #![no_std] | ||
| 4 | #![no_main] | ||
| 5 | #![feature(type_alias_impl_trait)] | ||
| 6 | #[path = "../common.rs"] | ||
| 7 | mod common; | ||
| 8 | |||
| 9 | use common::*; | ||
| 10 | use embassy_executor::Spawner; | ||
| 11 | use embassy_stm32::bind_interrupts; | ||
| 12 | use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; | ||
| 13 | use embassy_stm32_wpan::mac::commands::{AssociateRequest, GetRequest, ResetRequest, SetRequest}; | ||
| 14 | use embassy_stm32_wpan::mac::event::MacEvent; | ||
| 15 | use embassy_stm32_wpan::mac::typedefs::{ | ||
| 16 | AddressMode, Capabilities, KeyIdMode, MacAddress, MacChannel, PanId, PibId, SecurityLevel, | ||
| 17 | }; | ||
| 18 | use embassy_stm32_wpan::sub::mm; | ||
| 19 | use embassy_stm32_wpan::TlMbox; | ||
| 20 | use {defmt_rtt as _, panic_probe as _}; | ||
| 21 | |||
| 22 | bind_interrupts!(struct Irqs{ | ||
| 23 | IPCC_C1_RX => ReceiveInterruptHandler; | ||
| 24 | IPCC_C1_TX => TransmitInterruptHandler; | ||
| 25 | }); | ||
| 26 | |||
| 27 | #[embassy_executor::task] | ||
| 28 | async fn run_mm_queue(memory_manager: mm::MemoryManager) { | ||
| 29 | memory_manager.run_queue().await; | ||
| 30 | } | ||
| 31 | |||
| 32 | #[embassy_executor::main] | ||
| 33 | async fn main(spawner: Spawner) { | ||
| 34 | let p = embassy_stm32::init(config()); | ||
| 35 | info!("Hello World!"); | ||
| 36 | |||
| 37 | let config = Config::default(); | ||
| 38 | let mbox = TlMbox::init(p.IPCC, Irqs, config); | ||
| 39 | |||
| 40 | spawner.spawn(run_mm_queue(mbox.mm_subsystem)).unwrap(); | ||
| 41 | |||
| 42 | let sys_event = mbox.sys_subsystem.read().await; | ||
| 43 | info!("sys event: {}", sys_event.payload()); | ||
| 44 | |||
| 45 | core::mem::drop(sys_event); | ||
| 46 | |||
| 47 | let result = mbox.sys_subsystem.shci_c2_mac_802_15_4_init().await; | ||
| 48 | info!("initialized mac: {}", result); | ||
| 49 | |||
| 50 | info!("resetting"); | ||
| 51 | mbox.mac_subsystem | ||
| 52 | .send_command(&ResetRequest { set_default_pib: true }) | ||
| 53 | .await | ||
| 54 | .unwrap(); | ||
| 55 | let evt = mbox.mac_subsystem.read().await; | ||
| 56 | info!("{:#x}", evt); | ||
| 57 | |||
| 58 | info!("setting extended address"); | ||
| 59 | let extended_address: u64 = 0xACDE480000000002; | ||
| 60 | mbox.mac_subsystem | ||
| 61 | .send_command(&SetRequest { | ||
| 62 | pib_attribute_ptr: &extended_address as *const _ as *const u8, | ||
| 63 | pib_attribute: PibId::ExtendedAddress, | ||
| 64 | }) | ||
| 65 | .await | ||
| 66 | .unwrap(); | ||
| 67 | let evt = mbox.mac_subsystem.read().await; | ||
| 68 | info!("{:#x}", evt); | ||
| 69 | |||
| 70 | info!("getting extended address"); | ||
| 71 | mbox.mac_subsystem | ||
| 72 | .send_command(&GetRequest { | ||
| 73 | pib_attribute: PibId::ExtendedAddress, | ||
| 74 | }) | ||
| 75 | .await | ||
| 76 | .unwrap(); | ||
| 77 | let evt = mbox.mac_subsystem.read().await; | ||
| 78 | info!("{:#x}", evt); | ||
| 79 | |||
| 80 | if let Ok(MacEvent::MlmeGetCnf(evt)) = evt { | ||
| 81 | if evt.pib_attribute_value_len == 8 { | ||
| 82 | let value = unsafe { core::ptr::read_unaligned(evt.pib_attribute_value_ptr as *const u64) }; | ||
| 83 | |||
| 84 | info!("value {:#x}", value) | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | info!("assocation request"); | ||
| 89 | let a = AssociateRequest { | ||
| 90 | channel_number: MacChannel::Channel16, | ||
| 91 | channel_page: 0, | ||
| 92 | coord_addr_mode: AddressMode::Short, | ||
| 93 | coord_address: MacAddress { short: [34, 17] }, | ||
| 94 | capability_information: Capabilities::ALLOCATE_ADDRESS, | ||
| 95 | coord_pan_id: PanId([0x1A, 0xAA]), | ||
| 96 | security_level: SecurityLevel::Unsecure, | ||
| 97 | key_id_mode: KeyIdMode::Implicite, | ||
| 98 | key_source: [0; 8], | ||
| 99 | key_index: 152, | ||
| 100 | }; | ||
| 101 | info!("{}", a); | ||
| 102 | mbox.mac_subsystem.send_command(&a).await.unwrap(); | ||
| 103 | let evt = mbox.mac_subsystem.read().await; | ||
| 104 | info!("{:#x}", evt); | ||
| 105 | |||
| 106 | info!("Test OK"); | ||
| 107 | cortex_m::asm::bkpt(); | ||
| 108 | } | ||
