aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/mspm0/Cargo.toml2
-rw-r--r--tests/mspm0/src/bin/dma.rs2
-rw-r--r--tests/nrf/.cargo/config.toml4
-rw-r--r--tests/nrf/Cargo.toml4
-rw-r--r--tests/nrf/src/bin/buffered_uart_spam.rs10
-rw-r--r--tests/nrf/src/bin/wifi_esp_hosted_perf.rs15
-rw-r--r--tests/perf-client/Cargo.toml2
-rw-r--r--tests/perf-client/src/lib.rs2
-rw-r--r--tests/perf-server/Cargo.toml2
-rw-r--r--tests/riscv32/Cargo.toml2
-rw-r--r--tests/rp/Cargo.toml4
-rw-r--r--tests/rp/src/bin/cyw43-perf.rs4
-rw-r--r--tests/rp/src/bin/gpio_multicore.rs4
-rw-r--r--tests/rp/src/bin/multicore.rs2
-rw-r--r--tests/rp/src/bin/overclock.rs2
-rw-r--r--tests/rp/src/bin/pio_multi_load.rs4
-rw-r--r--tests/rp/src/bin/rtc.rs2
-rw-r--r--tests/rp/src/bin/spinlock_mutex_multicore.rs2
-rw-r--r--tests/stm32/Cargo.toml29
-rw-r--r--tests/stm32/src/bin/adc.rs39
-rw-r--r--tests/stm32/src/bin/afio.rs2
-rw-r--r--tests/stm32/src/bin/cryp.rs2
-rw-r--r--tests/stm32/src/bin/dac.rs9
-rw-r--r--tests/stm32/src/bin/dac_l1.rs11
-rw-r--r--tests/stm32/src/bin/eth.rs13
-rw-r--r--tests/stm32/src/bin/fdcan.rs2
-rw-r--r--tests/stm32/src/bin/hsem.rs50
-rw-r--r--tests/stm32/src/bin/rtc.rs23
-rw-r--r--tests/stm32/src/bin/sdmmc.rs92
-rw-r--r--tests/stm32/src/bin/spi.rs7
-rw-r--r--tests/stm32/src/bin/spi_dma.rs7
-rw-r--r--tests/stm32/src/bin/stop.rs29
-rw-r--r--tests/stm32/src/bin/ucpd.rs2
-rw-r--r--tests/stm32/src/bin/usart.rs46
-rw-r--r--tests/stm32/src/bin/usart_dma.rs18
-rw-r--r--tests/stm32/src/bin/wpan_ble.rs124
-rw-r--r--tests/stm32/src/bin/wpan_mac.rs31
-rw-r--r--tests/stm32/src/common.rs5
-rw-r--r--tests/utils/Cargo.toml2
-rw-r--r--tests/utils/src/bin/saturate_serial.rs2
40 files changed, 394 insertions, 220 deletions
diff --git a/tests/mspm0/Cargo.toml b/tests/mspm0/Cargo.toml
index 227d898d5..df52b538d 100644
--- a/tests/mspm0/Cargo.toml
+++ b/tests/mspm0/Cargo.toml
@@ -1,5 +1,5 @@
1[package] 1[package]
2edition = "2021" 2edition = "2024"
3name = "embassy-mspm0-tests" 3name = "embassy-mspm0-tests"
4version = "0.1.0" 4version = "0.1.0"
5license = "MIT OR Apache-2.0" 5license = "MIT OR Apache-2.0"
diff --git a/tests/mspm0/src/bin/dma.rs b/tests/mspm0/src/bin/dma.rs
index 6fd973a18..9c56acadc 100644
--- a/tests/mspm0/src/bin/dma.rs
+++ b/tests/mspm0/src/bin/dma.rs
@@ -11,8 +11,8 @@ use core::slice;
11 11
12use defmt::{assert, assert_eq, *}; 12use defmt::{assert, assert_eq, *};
13use embassy_executor::Spawner; 13use embassy_executor::Spawner;
14use embassy_mspm0::dma::{Channel, Transfer, TransferMode, TransferOptions, Word};
15use embassy_mspm0::Peri; 14use embassy_mspm0::Peri;
15use embassy_mspm0::dma::{Channel, Transfer, TransferMode, TransferOptions, Word};
16use {defmt_rtt as _, panic_probe as _}; 16use {defmt_rtt as _, panic_probe as _};
17 17
18#[embassy_executor::main] 18#[embassy_executor::main]
diff --git a/tests/nrf/.cargo/config.toml b/tests/nrf/.cargo/config.toml
index 8f9bccbc0..0192c10ae 100644
--- a/tests/nrf/.cargo/config.toml
+++ b/tests/nrf/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2#runner = "teleprobe local run --chip nRF52840_xxAA --elf" 2runner = "teleprobe local run --chip nRF52840_xxAA --elf"
3runner = "teleprobe client run" 3#runner = "teleprobe client run"
4 4
5[build] 5[build]
6#target = "thumbv6m-none-eabi" 6#target = "thumbv6m-none-eabi"
diff --git a/tests/nrf/Cargo.toml b/tests/nrf/Cargo.toml
index 8acf27ce7..50f059b34 100644
--- a/tests/nrf/Cargo.toml
+++ b/tests/nrf/Cargo.toml
@@ -1,5 +1,5 @@
1[package] 1[package]
2edition = "2021" 2edition = "2024"
3name = "embassy-nrf-examples" 3name = "embassy-nrf-examples"
4version = "0.1.0" 4version = "0.1.0"
5license = "MIT OR Apache-2.0" 5license = "MIT OR Apache-2.0"
@@ -12,7 +12,7 @@ embassy-futures = { version = "0.1.2", path = "../../embassy-futures" }
12embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt", ] } 12embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt", ] }
13embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt"] } 13embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt"] }
14embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } 14embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
15embassy-nrf = { version = "0.8.0", path = "../../embassy-nrf", features = ["defmt", "time-driver-rtc1", "gpiote", "unstable-pac"] } 15embassy-nrf = { version = "0.9.0", path = "../../embassy-nrf", features = ["defmt", "time-driver-rtc1", "gpiote", "unstable-pac"] }
16embedded-io-async = { version = "0.6.1", features = ["defmt-03"] } 16embedded-io-async = { version = "0.6.1", features = ["defmt-03"] }
17embassy-net = { version = "0.7.1", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", ] } 17embassy-net = { version = "0.7.1", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", ] }
18embassy-net-esp-hosted = { version = "0.2.1", path = "../../embassy-net-esp-hosted", features = ["defmt"] } 18embassy-net-esp-hosted = { version = "0.2.1", path = "../../embassy-net-esp-hosted", features = ["defmt"] }
diff --git a/tests/nrf/src/bin/buffered_uart_spam.rs b/tests/nrf/src/bin/buffered_uart_spam.rs
index 24ddd06f3..6d862e19d 100644
--- a/tests/nrf/src/bin/buffered_uart_spam.rs
+++ b/tests/nrf/src/bin/buffered_uart_spam.rs
@@ -55,14 +55,14 @@ async fn main(_spawner: Spawner) {
55 static mut TX_BUF: [u8; NSPAM] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; 55 static mut TX_BUF: [u8; NSPAM] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
56 let _spam = UarteTx::new(peri!(p, UART1), irqs!(UART1), peri!(p, PIN_A), config.clone()); 56 let _spam = UarteTx::new(peri!(p, UART1), irqs!(UART1), peri!(p, PIN_A), config.clone());
57 let spam_peri = pac::UARTE1; 57 let spam_peri = pac::UARTE1;
58 let event = unsafe { Event::new_unchecked(NonNull::new_unchecked(spam_peri.events_endtx().as_ptr())) }; 58 let event = unsafe { Event::new_unchecked(NonNull::new_unchecked(spam_peri.events_dma().tx().end().as_ptr())) };
59 let task = unsafe { Task::new_unchecked(NonNull::new_unchecked(spam_peri.tasks_starttx().as_ptr())) }; 59 let task = unsafe { Task::new_unchecked(NonNull::new_unchecked(spam_peri.tasks_dma().tx().start().as_ptr())) };
60 let mut spam_ppi = Ppi::new_one_to_one(p.PPI_CH2, event, task); 60 let mut spam_ppi = Ppi::new_one_to_one(p.PPI_CH2, event, task);
61 spam_ppi.enable(); 61 spam_ppi.enable();
62 let p = (&raw mut TX_BUF) as *mut u8; 62 let p = (&raw mut TX_BUF) as *mut u8;
63 spam_peri.txd().ptr().write_value(p as u32); 63 spam_peri.dma().tx().ptr().write_value(p as u32);
64 spam_peri.txd().maxcnt().write(|w| w.set_maxcnt(NSPAM as _)); 64 spam_peri.dma().tx().maxcnt().write(|w| w.set_maxcnt(NSPAM as _));
65 spam_peri.tasks_starttx().write_value(1); 65 spam_peri.tasks_dma().tx().start().write_value(1);
66 66
67 let mut i = 0; 67 let mut i = 0;
68 let mut total = 0; 68 let mut total = 0;
diff --git a/tests/nrf/src/bin/wifi_esp_hosted_perf.rs b/tests/nrf/src/bin/wifi_esp_hosted_perf.rs
index 091a70ce9..ac082dbb8 100644
--- a/tests/nrf/src/bin/wifi_esp_hosted_perf.rs
+++ b/tests/nrf/src/bin/wifi_esp_hosted_perf.rs
@@ -29,8 +29,7 @@ const WIFI_PASSWORD: &str = "V8YxhKt5CdIAJFud";
29async fn wifi_task( 29async fn wifi_task(
30 runner: hosted::Runner< 30 runner: hosted::Runner<
31 'static, 31 'static,
32 ExclusiveDevice<Spim<'static>, Output<'static>, Delay>, 32 hosted::SpiInterface<ExclusiveDevice<Spim<'static>, Output<'static>, Delay>, Input<'static>>,
33 Input<'static>,
34 Output<'static>, 33 Output<'static>,
35 >, 34 >,
36) -> ! { 35) -> ! {
@@ -64,15 +63,11 @@ async fn main(spawner: Spawner) {
64 let spi = spim::Spim::new(p.SPI3, Irqs, sck, miso, mosi, config); 63 let spi = spim::Spim::new(p.SPI3, Irqs, sck, miso, mosi, config);
65 let spi = ExclusiveDevice::new(spi, cs, Delay); 64 let spi = ExclusiveDevice::new(spi, cs, Delay);
66 65
66 let iface = hosted::SpiInterface::new(spi, handshake, ready);
67
67 static STATE: StaticCell<embassy_net_esp_hosted::State> = StaticCell::new(); 68 static STATE: StaticCell<embassy_net_esp_hosted::State> = StaticCell::new();
68 let (device, mut control, runner) = embassy_net_esp_hosted::new( 69 let (device, mut control, runner) =
69 STATE.init(embassy_net_esp_hosted::State::new()), 70 embassy_net_esp_hosted::new(STATE.init(embassy_net_esp_hosted::State::new()), iface, reset).await;
70 spi,
71 handshake,
72 ready,
73 reset,
74 )
75 .await;
76 71
77 spawner.spawn(unwrap!(wifi_task(runner))); 72 spawner.spawn(unwrap!(wifi_task(runner)));
78 73
diff --git a/tests/perf-client/Cargo.toml b/tests/perf-client/Cargo.toml
index c426fdd74..3756046fa 100644
--- a/tests/perf-client/Cargo.toml
+++ b/tests/perf-client/Cargo.toml
@@ -1,7 +1,7 @@
1[package] 1[package]
2name = "perf-client" 2name = "perf-client"
3version = "0.1.0" 3version = "0.1.0"
4edition = "2021" 4edition = "2024"
5license = "MIT OR Apache-2.0" 5license = "MIT OR Apache-2.0"
6publish = false 6publish = false
7 7
diff --git a/tests/perf-client/src/lib.rs b/tests/perf-client/src/lib.rs
index 4bd9e5674..1ba071e8d 100644
--- a/tests/perf-client/src/lib.rs
+++ b/tests/perf-client/src/lib.rs
@@ -4,7 +4,7 @@ use defmt::{assert, *};
4use embassy_futures::join::join; 4use embassy_futures::join::join;
5use embassy_net::tcp::TcpSocket; 5use embassy_net::tcp::TcpSocket;
6use embassy_net::{Ipv4Address, Stack}; 6use embassy_net::{Ipv4Address, Stack};
7use embassy_time::{with_timeout, Duration, Timer}; 7use embassy_time::{Duration, Timer, with_timeout};
8 8
9pub struct Expected { 9pub struct Expected {
10 pub down_kbps: usize, 10 pub down_kbps: usize,
diff --git a/tests/perf-server/Cargo.toml b/tests/perf-server/Cargo.toml
index f048eade2..72f92ed8d 100644
--- a/tests/perf-server/Cargo.toml
+++ b/tests/perf-server/Cargo.toml
@@ -1,7 +1,7 @@
1[package] 1[package]
2name = "perf-server" 2name = "perf-server"
3version = "0.1.0" 3version = "0.1.0"
4edition = "2021" 4edition = "2024"
5license = "MIT OR Apache-2.0" 5license = "MIT OR Apache-2.0"
6publish = false 6publish = false
7 7
diff --git a/tests/riscv32/Cargo.toml b/tests/riscv32/Cargo.toml
index c441e8ed3..935c6a2ee 100644
--- a/tests/riscv32/Cargo.toml
+++ b/tests/riscv32/Cargo.toml
@@ -1,5 +1,5 @@
1[package] 1[package]
2edition = "2021" 2edition = "2024"
3name = "embassy-riscv-tests" 3name = "embassy-riscv-tests"
4version = "0.1.0" 4version = "0.1.0"
5license = "MIT OR Apache-2.0" 5license = "MIT OR Apache-2.0"
diff --git a/tests/rp/Cargo.toml b/tests/rp/Cargo.toml
index 19461520a..4dfe6904e 100644
--- a/tests/rp/Cargo.toml
+++ b/tests/rp/Cargo.toml
@@ -1,5 +1,5 @@
1[package] 1[package]
2edition = "2021" 2edition = "2024"
3name = "embassy-rp-tests" 3name = "embassy-rp-tests"
4version = "0.1.0" 4version = "0.1.0"
5license = "MIT OR Apache-2.0" 5license = "MIT OR Apache-2.0"
@@ -16,7 +16,7 @@ teleprobe-meta = "1.1"
16embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt"] } 16embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt"] }
17embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt"] } 17embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt"] }
18embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", ] } 18embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", ] }
19embassy-rp = { version = "0.8.0", path = "../../embassy-rp", features = [ "defmt", "unstable-pac", "time-driver", "critical-section-impl", "intrinsics", "rom-v2-intrinsics", "run-from-ram"] } 19embassy-rp = { version = "0.9.0", path = "../../embassy-rp", features = [ "defmt", "unstable-pac", "time-driver", "critical-section-impl", "intrinsics", "rom-v2-intrinsics", "run-from-ram"] }
20embassy-futures = { version = "0.1.2", path = "../../embassy-futures" } 20embassy-futures = { version = "0.1.2", path = "../../embassy-futures" }
21embassy-net = { version = "0.7.1", path = "../../embassy-net", features = ["defmt", "tcp", "udp", "dhcpv4", "medium-ethernet"] } 21embassy-net = { version = "0.7.1", path = "../../embassy-net", features = ["defmt", "tcp", "udp", "dhcpv4", "medium-ethernet"] }
22embassy-net-wiznet = { version = "0.2.1", path = "../../embassy-net-wiznet", features = ["defmt"] } 22embassy-net-wiznet = { version = "0.2.1", path = "../../embassy-net-wiznet", features = ["defmt"] }
diff --git a/tests/rp/src/bin/cyw43-perf.rs b/tests/rp/src/bin/cyw43-perf.rs
index 555134ffd..1ef9cf066 100644
--- a/tests/rp/src/bin/cyw43-perf.rs
+++ b/tests/rp/src/bin/cyw43-perf.rs
@@ -3,7 +3,7 @@
3teleprobe_meta::target!(b"rpi-pico"); 3teleprobe_meta::target!(b"rpi-pico");
4 4
5use cyw43::JoinOptions; 5use cyw43::JoinOptions;
6use cyw43_pio::{PioSpi, DEFAULT_CLOCK_DIVIDER}; 6use cyw43_pio::{DEFAULT_CLOCK_DIVIDER, PioSpi};
7use defmt::{panic, *}; 7use defmt::{panic, *};
8use embassy_executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_net::{Config, StackResources}; 9use embassy_net::{Config, StackResources};
@@ -98,7 +98,7 @@ async fn main(spawner: Spawner) {
98 { 98 {
99 Ok(_) => break, 99 Ok(_) => break,
100 Err(err) => { 100 Err(err) => {
101 panic!("join failed with status={}", err.status); 101 panic!("join failed: {:?}", err);
102 } 102 }
103 } 103 }
104 } 104 }
diff --git a/tests/rp/src/bin/gpio_multicore.rs b/tests/rp/src/bin/gpio_multicore.rs
index f48dd207b..6abcba590 100644
--- a/tests/rp/src/bin/gpio_multicore.rs
+++ b/tests/rp/src/bin/gpio_multicore.rs
@@ -7,10 +7,10 @@ teleprobe_meta::target!(b"pimoroni-pico-plus-2");
7 7
8use defmt::{info, unwrap}; 8use defmt::{info, unwrap};
9use embassy_executor::Executor; 9use embassy_executor::Executor;
10use embassy_rp::Peri;
10use embassy_rp::gpio::{Input, Level, Output, Pull}; 11use embassy_rp::gpio::{Input, Level, Output, Pull};
11use embassy_rp::multicore::{spawn_core1, Stack}; 12use embassy_rp::multicore::{Stack, spawn_core1};
12use embassy_rp::peripherals::{PIN_0, PIN_1}; 13use embassy_rp::peripherals::{PIN_0, PIN_1};
13use embassy_rp::Peri;
14use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; 14use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
15use embassy_sync::channel::Channel; 15use embassy_sync::channel::Channel;
16use static_cell::StaticCell; 16use static_cell::StaticCell;
diff --git a/tests/rp/src/bin/multicore.rs b/tests/rp/src/bin/multicore.rs
index 11b03cfea..7e34bc778 100644
--- a/tests/rp/src/bin/multicore.rs
+++ b/tests/rp/src/bin/multicore.rs
@@ -7,7 +7,7 @@ teleprobe_meta::target!(b"pimoroni-pico-plus-2");
7 7
8use defmt::{info, unwrap}; 8use defmt::{info, unwrap};
9use embassy_executor::Executor; 9use embassy_executor::Executor;
10use embassy_rp::multicore::{spawn_core1, Stack}; 10use embassy_rp::multicore::{Stack, spawn_core1};
11use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; 11use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
12use embassy_sync::channel::Channel; 12use embassy_sync::channel::Channel;
13use static_cell::StaticCell; 13use static_cell::StaticCell;
diff --git a/tests/rp/src/bin/overclock.rs b/tests/rp/src/bin/overclock.rs
index 167a26eb2..87a03b5e2 100644
--- a/tests/rp/src/bin/overclock.rs
+++ b/tests/rp/src/bin/overclock.rs
@@ -8,7 +8,7 @@ teleprobe_meta::target!(b"pimoroni-pico-plus-2");
8 8
9use defmt::info; 9use defmt::info;
10use embassy_executor::Spawner; 10use embassy_executor::Spawner;
11use embassy_rp::clocks::{clk_sys_freq, core_voltage, ClockConfig, CoreVoltage}; 11use embassy_rp::clocks::{ClockConfig, CoreVoltage, clk_sys_freq, core_voltage};
12use embassy_rp::config::Config; 12use embassy_rp::config::Config;
13use embassy_time::Instant; 13use embassy_time::Instant;
14use {defmt_rtt as _, panic_probe as _}; 14use {defmt_rtt as _, panic_probe as _};
diff --git a/tests/rp/src/bin/pio_multi_load.rs b/tests/rp/src/bin/pio_multi_load.rs
index aca476d56..82bbab272 100644
--- a/tests/rp/src/bin/pio_multi_load.rs
+++ b/tests/rp/src/bin/pio_multi_load.rs
@@ -57,7 +57,9 @@ async fn main(_spawner: Spawner) {
57 assert_eq!(loaded2.wrap.target, 14); 57 assert_eq!(loaded2.wrap.target, 14);
58 58
59 // wrapping around the end of program space automatically works 59 // wrapping around the end of program space automatically works
60 let prg3 = pio_asm!("nop", "nop", "nop", "nop", "nop", "nop", "nop", "nop", "nop", "nop", "nop", "irq 2",); 60 let prg3 = pio_asm!(
61 "nop", "nop", "nop", "nop", "nop", "nop", "nop", "nop", "nop", "nop", "nop", "irq 2",
62 );
61 let loaded3 = common.load_program(&prg3.program); 63 let loaded3 = common.load_program(&prg3.program);
62 assert_eq!(loaded3.origin, 24); 64 assert_eq!(loaded3.origin, 24);
63 assert_eq!(loaded3.wrap.source, 3); 65 assert_eq!(loaded3.wrap.source, 3);
diff --git a/tests/rp/src/bin/rtc.rs b/tests/rp/src/bin/rtc.rs
index c66981d95..e1def7b5b 100644
--- a/tests/rp/src/bin/rtc.rs
+++ b/tests/rp/src/bin/rtc.rs
@@ -5,7 +5,7 @@ teleprobe_meta::target!(b"rpi-pico");
5 5
6use defmt::{assert, *}; 6use defmt::{assert, *};
7use embassy_executor::Spawner; 7use embassy_executor::Spawner;
8use embassy_futures::select::{select, Either}; 8use embassy_futures::select::{Either, select};
9use embassy_rp::bind_interrupts; 9use embassy_rp::bind_interrupts;
10use embassy_rp::rtc::{DateTime, DateTimeFilter, DayOfWeek, Rtc}; 10use embassy_rp::rtc::{DateTime, DateTimeFilter, DayOfWeek, Rtc};
11use embassy_time::{Duration, Instant, Timer}; 11use embassy_time::{Duration, Instant, Timer};
diff --git a/tests/rp/src/bin/spinlock_mutex_multicore.rs b/tests/rp/src/bin/spinlock_mutex_multicore.rs
index c56d43ade..25c4faf37 100644
--- a/tests/rp/src/bin/spinlock_mutex_multicore.rs
+++ b/tests/rp/src/bin/spinlock_mutex_multicore.rs
@@ -7,7 +7,7 @@ teleprobe_meta::target!(b"pimoroni-pico-plus-2");
7 7
8use defmt::{info, unwrap}; 8use defmt::{info, unwrap};
9use embassy_executor::Executor; 9use embassy_executor::Executor;
10use embassy_rp::multicore::{spawn_core1, Stack}; 10use embassy_rp::multicore::{Stack, spawn_core1};
11use embassy_rp::spinlock_mutex::SpinlockRawMutex; 11use embassy_rp::spinlock_mutex::SpinlockRawMutex;
12use embassy_sync::channel::Channel; 12use embassy_sync::channel::Channel;
13use static_cell::StaticCell; 13use static_cell::StaticCell;
diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml
index 891ec93fd..6ee7f8e84 100644
--- a/tests/stm32/Cargo.toml
+++ b/tests/stm32/Cargo.toml
@@ -1,5 +1,5 @@
1[package] 1[package]
2edition = "2021" 2edition = "2024"
3name = "embassy-stm32-tests" 3name = "embassy-stm32-tests"
4version = "0.1.0" 4version = "0.1.0"
5license = "MIT OR Apache-2.0" 5license = "MIT OR Apache-2.0"
@@ -31,9 +31,9 @@ stm32l4r5zi = ["embassy-stm32/stm32l4r5zi", "chrono", "not-gpdma", "rng", "dual-
31stm32l552ze = ["embassy-stm32/stm32l552ze", "not-gpdma", "rng", "hash", "dual-bank"] 31stm32l552ze = ["embassy-stm32/stm32l552ze", "not-gpdma", "rng", "hash", "dual-bank"]
32stm32u585ai = ["embassy-stm32/stm32u585ai", "spi-v345", "chrono", "rng", "hash", "cordic"] 32stm32u585ai = ["embassy-stm32/stm32u585ai", "spi-v345", "chrono", "rng", "hash", "cordic"]
33stm32u5a5zj = ["embassy-stm32/stm32u5a5zj", "spi-v345", "chrono", "rng", "hash"] # FIXME: cordic test cause it crash 33stm32u5a5zj = ["embassy-stm32/stm32u5a5zj", "spi-v345", "chrono", "rng", "hash"] # FIXME: cordic test cause it crash
34stm32wb55rg = ["embassy-stm32/stm32wb55rg", "chrono", "not-gpdma", "ble", "mac" , "rng"] 34stm32wb55rg = ["embassy-stm32/stm32wb55rg", "chrono", "not-gpdma", "ble", "mac" , "rng", "hsem", "stop"]
35stm32wba52cg = ["embassy-stm32/stm32wba52cg", "spi-v345", "chrono", "rng", "hash"] 35stm32wba52cg = ["embassy-stm32/stm32wba52cg", "spi-v345", "chrono", "rng", "hash", "adc"]
36stm32wl55jc = ["embassy-stm32/stm32wl55jc-cm4", "not-gpdma", "rng", "chrono"] 36stm32wl55jc = ["embassy-stm32/stm32wl55jc-cm4", "not-gpdma", "rng", "chrono", "hsem"]
37stm32f091rc = ["embassy-stm32/stm32f091rc", "cm0", "not-gpdma", "chrono"] 37stm32f091rc = ["embassy-stm32/stm32f091rc", "cm0", "not-gpdma", "chrono"]
38stm32h503rb = ["embassy-stm32/stm32h503rb", "spi-v345", "rng", "stop"] 38stm32h503rb = ["embassy-stm32/stm32h503rb", "spi-v345", "rng", "stop"]
39stm32h7s3l8 = ["embassy-stm32/stm32h7s3l8", "spi-v345", "rng", "cordic", "hash-v34"] # TODO: fdcan crashes, cryp dma hangs. 39stm32h7s3l8 = ["embassy-stm32/stm32h7s3l8", "spi-v345", "rng", "cordic", "hash-v34"] # TODO: fdcan crashes, cryp dma hangs.
@@ -51,13 +51,15 @@ stop = ["embassy-stm32/low-power", "embassy-stm32/low-power-debug-with-sleep"]
51chrono = ["embassy-stm32/chrono", "dep:chrono"] 51chrono = ["embassy-stm32/chrono", "dep:chrono"]
52can = [] 52can = []
53fdcan = [] 53fdcan = []
54ble = ["dep:embassy-stm32-wpan", "embassy-stm32-wpan/ble"] 54ble = ["dep:embassy-stm32-wpan", "embassy-stm32-wpan/wb55_ble"]
55mac = ["dep:embassy-stm32-wpan", "embassy-stm32-wpan/mac"] 55mac = ["dep:embassy-stm32-wpan", "embassy-stm32-wpan/wb55_mac"]
56embassy-stm32-wpan = [] 56embassy-stm32-wpan = []
57not-gpdma = [] 57not-gpdma = []
58dac = [] 58dac = []
59adc = []
59ucpd = [] 60ucpd = []
60cordic = ["dep:num-traits"] 61cordic = ["dep:num-traits"]
62hsem = []
61dual-bank = ["embassy-stm32/dual-bank"] 63dual-bank = ["embassy-stm32/dual-bank"]
62single-bank = ["embassy-stm32/single-bank"] 64single-bank = ["embassy-stm32/single-bank"]
63eeprom = [] 65eeprom = []
@@ -73,9 +75,9 @@ teleprobe-meta = "1"
73embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt"] } 75embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt"] }
74embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt"] } 76embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt"] }
75embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "tick-hz-131_072", "defmt-timestamp-uptime"] } 77embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "tick-hz-131_072", "defmt-timestamp-uptime"] }
76embassy-stm32 = { version = "0.4.0", path = "../../embassy-stm32", features = [ "defmt", "unstable-pac", "memory-x", "time-driver-any"] } 78embassy-stm32 = { version = "0.4.0", path = "../../embassy-stm32", features = [ "defmt", "unstable-pac", "memory-x", "time-driver-any", "_allow-disable-rtc"] }
77embassy-futures = { version = "0.1.2", path = "../../embassy-futures" } 79embassy-futures = { version = "0.1.2", path = "../../embassy-futures" }
78embassy-stm32-wpan = { version = "0.1.0", path = "../../embassy-stm32-wpan", optional = true, features = ["defmt", "stm32wb55rg", "ble"] } 80embassy-stm32-wpan = { version = "0.1.0", path = "../../embassy-stm32-wpan", optional = true, features = ["defmt", "stm32wb55rg", "wb55_ble"] }
79embassy-net = { version = "0.7.1", path = "../../embassy-net", features = ["defmt", "tcp", "udp", "dhcpv4", "medium-ethernet"] } 81embassy-net = { version = "0.7.1", path = "../../embassy-net", features = ["defmt", "tcp", "udp", "dhcpv4", "medium-ethernet"] }
80perf-client = { path = "../perf-client" } 82perf-client = { path = "../perf-client" }
81 83
@@ -94,6 +96,7 @@ rand_core = { version = "0.9.1", default-features = false }
94rand_chacha = { version = "0.9.0", default-features = false } 96rand_chacha = { version = "0.9.0", default-features = false }
95static_cell = "2" 97static_cell = "2"
96portable-atomic = { version = "1.5", features = [] } 98portable-atomic = { version = "1.5", features = [] }
99critical-section = "1.1"
97 100
98chrono = { version = "^0.4", default-features = false, optional = true} 101chrono = { version = "^0.4", default-features = false, optional = true}
99sha2 = { version = "0.10.8", default-features = false } 102sha2 = { version = "0.10.8", default-features = false }
@@ -109,6 +112,11 @@ path = "src/bin/afio.rs"
109required-features = [ "afio",] 112required-features = [ "afio",]
110 113
111[[bin]] 114[[bin]]
115name = "adc"
116path = "src/bin/adc.rs"
117required-features = [ "adc",]
118
119[[bin]]
112name = "can" 120name = "can"
113path = "src/bin/can.rs" 121path = "src/bin/can.rs"
114required-features = [ "can",] 122required-features = [ "can",]
@@ -223,6 +231,11 @@ name = "wpan_mac"
223path = "src/bin/wpan_mac.rs" 231path = "src/bin/wpan_mac.rs"
224required-features = [ "mac",] 232required-features = [ "mac",]
225 233
234[[bin]]
235name = "hsem"
236path = "src/bin/hsem.rs"
237required-features = [ "hsem",]
238
226# END TESTS 239# END TESTS
227 240
228[profile.dev] 241[profile.dev]
diff --git a/tests/stm32/src/bin/adc.rs b/tests/stm32/src/bin/adc.rs
new file mode 100644
index 000000000..6cedc6498
--- /dev/null
+++ b/tests/stm32/src/bin/adc.rs
@@ -0,0 +1,39 @@
1#![no_std]
2#![no_main]
3
4// required-features: dac
5
6#[path = "../common.rs"]
7mod common;
8
9use common::*;
10use embassy_executor::Spawner;
11use embassy_stm32::adc::{Adc, SampleTime};
12use embassy_time::Timer;
13use {defmt_rtt as _, panic_probe as _};
14
15#[embassy_executor::main]
16async fn main(_spawner: Spawner) {
17 // Initialize the board and obtain a Peripherals instance
18 let p: embassy_stm32::Peripherals = init();
19
20 let adc = peri!(p, ADC);
21 let mut adc_pin = peri!(p, DAC_PIN);
22
23 let mut adc = Adc::new_adc4(adc);
24
25 // Now wait a little to obtain a stable value
26 Timer::after_millis(30).await;
27 let _ = adc.blocking_read(&mut adc_pin, SampleTime::from_bits(0));
28
29 for _ in 0..=255 {
30 // Now wait a little to obtain a stable value
31 Timer::after_millis(30).await;
32
33 // Need to steal the peripherals here because PA4 is obviously in use already
34 let _ = adc.blocking_read(&mut adc_pin, SampleTime::from_bits(0));
35 }
36
37 info!("Test OK");
38 cortex_m::asm::bkpt();
39}
diff --git a/tests/stm32/src/bin/afio.rs b/tests/stm32/src/bin/afio.rs
index 81d50874b..d88765717 100644
--- a/tests/stm32/src/bin/afio.rs
+++ b/tests/stm32/src/bin/afio.rs
@@ -16,7 +16,7 @@ use embassy_stm32::timer::qei::Qei;
16use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; 16use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm};
17use embassy_stm32::timer::{Ch1, Ch2}; 17use embassy_stm32::timer::{Ch1, Ch2};
18use embassy_stm32::usart::{Uart, UartRx, UartTx}; 18use embassy_stm32::usart::{Uart, UartRx, UartTx};
19use embassy_stm32::{bind_interrupts, Peripherals}; 19use embassy_stm32::{Peripherals, bind_interrupts};
20 20
21#[cfg(not(feature = "afio-connectivity-line"))] 21#[cfg(not(feature = "afio-connectivity-line"))]
22bind_interrupts!(struct Irqs { 22bind_interrupts!(struct Irqs {
diff --git a/tests/stm32/src/bin/cryp.rs b/tests/stm32/src/bin/cryp.rs
index f54c99cc3..640de50e3 100644
--- a/tests/stm32/src/bin/cryp.rs
+++ b/tests/stm32/src/bin/cryp.rs
@@ -5,9 +5,9 @@
5#[path = "../common.rs"] 5#[path = "../common.rs"]
6mod common; 6mod common;
7 7
8use aes_gcm::Aes128Gcm;
8use aes_gcm::aead::heapless::Vec; 9use aes_gcm::aead::heapless::Vec;
9use aes_gcm::aead::{AeadInPlace, KeyInit}; 10use aes_gcm::aead::{AeadInPlace, KeyInit};
10use aes_gcm::Aes128Gcm;
11use common::*; 11use common::*;
12use embassy_executor::Spawner; 12use embassy_executor::Spawner;
13use embassy_stm32::cryp::{self, *}; 13use embassy_stm32::cryp::{self, *};
diff --git a/tests/stm32/src/bin/dac.rs b/tests/stm32/src/bin/dac.rs
index d34bbb255..747b11e7f 100644
--- a/tests/stm32/src/bin/dac.rs
+++ b/tests/stm32/src/bin/dac.rs
@@ -10,7 +10,7 @@ use core::f32::consts::PI;
10use common::*; 10use common::*;
11use defmt::assert; 11use defmt::assert;
12use embassy_executor::Spawner; 12use embassy_executor::Spawner;
13use embassy_stm32::adc::Adc; 13use embassy_stm32::adc::{Adc, SampleTime};
14use embassy_stm32::dac::{DacCh1, Value}; 14use embassy_stm32::dac::{DacCh1, Value};
15use embassy_time::Timer; 15use embassy_time::Timer;
16use micromath::F32Ext; 16use micromath::F32Ext;
@@ -37,7 +37,7 @@ async fn main(_spawner: Spawner) {
37 dac.set(Value::Bit8(0)); 37 dac.set(Value::Bit8(0));
38 // Now wait a little to obtain a stable value 38 // Now wait a little to obtain a stable value
39 Timer::after_millis(30).await; 39 Timer::after_millis(30).await;
40 let offset = adc.blocking_read(&mut adc_pin); 40 let offset = adc.blocking_read(&mut adc_pin, SampleTime::from_bits(0));
41 41
42 for v in 0..=255 { 42 for v in 0..=255 {
43 // First set the DAC output value 43 // First set the DAC output value
@@ -48,7 +48,10 @@ async fn main(_spawner: Spawner) {
48 Timer::after_millis(30).await; 48 Timer::after_millis(30).await;
49 49
50 // Need to steal the peripherals here because PA4 is obviously in use already 50 // Need to steal the peripherals here because PA4 is obviously in use already
51 let measured = adc.blocking_read(&mut unsafe { embassy_stm32::Peripherals::steal() }.PA4); 51 let measured = adc.blocking_read(
52 &mut unsafe { embassy_stm32::Peripherals::steal() }.PA4,
53 SampleTime::from_bits(0),
54 );
52 // Calibrate and normalize the measurement to get close to the dac_output_val 55 // Calibrate and normalize the measurement to get close to the dac_output_val
53 let measured_normalized = ((measured as i32 - offset as i32) / normalization_factor) as i16; 56 let measured_normalized = ((measured as i32 - offset as i32) / normalization_factor) as i16;
54 57
diff --git a/tests/stm32/src/bin/dac_l1.rs b/tests/stm32/src/bin/dac_l1.rs
index e6400f28e..2fe0cf1f1 100644
--- a/tests/stm32/src/bin/dac_l1.rs
+++ b/tests/stm32/src/bin/dac_l1.rs
@@ -10,7 +10,7 @@ use core::f32::consts::PI;
10use common::*; 10use common::*;
11use defmt::assert; 11use defmt::assert;
12use embassy_executor::Spawner; 12use embassy_executor::Spawner;
13use embassy_stm32::adc::Adc; 13use embassy_stm32::adc::{Adc, SampleTime};
14use embassy_stm32::dac::{DacCh1, Value}; 14use embassy_stm32::dac::{DacCh1, Value};
15use embassy_stm32::{bind_interrupts, peripherals}; 15use embassy_stm32::{bind_interrupts, peripherals};
16use embassy_time::Timer; 16use embassy_time::Timer;
@@ -47,7 +47,7 @@ async fn main(_spawner: Spawner) {
47 dac.set(Value::Bit8(0)); 47 dac.set(Value::Bit8(0));
48 // Now wait a little to obtain a stable value 48 // Now wait a little to obtain a stable value
49 Timer::after_millis(30).await; 49 Timer::after_millis(30).await;
50 let offset = adc.read(&mut adc_pin).await; 50 let offset = adc.read(&mut adc_pin, SampleTime::from_bits(0)).await;
51 51
52 for v in 0..=255 { 52 for v in 0..=255 {
53 // First set the DAC output value 53 // First set the DAC output value
@@ -58,7 +58,12 @@ async fn main(_spawner: Spawner) {
58 Timer::after_millis(30).await; 58 Timer::after_millis(30).await;
59 59
60 // Need to steal the peripherals here because PA4 is obviously in use already 60 // Need to steal the peripherals here because PA4 is obviously in use already
61 let measured = adc.read(&mut unsafe { embassy_stm32::Peripherals::steal() }.PA4).await; 61 let measured = adc
62 .read(
63 &mut unsafe { embassy_stm32::Peripherals::steal() }.PA4,
64 SampleTime::from_bits(0),
65 )
66 .await;
62 // Calibrate and normalize the measurement to get close to the dac_output_val 67 // Calibrate and normalize the measurement to get close to the dac_output_val
63 let measured_normalized = ((measured as i32 - offset as i32) / normalization_factor) as i16; 68 let measured_normalized = ((measured as i32 - offset as i32) / normalization_factor) as i16;
64 69
diff --git a/tests/stm32/src/bin/eth.rs b/tests/stm32/src/bin/eth.rs
index a65682a02..ffc76b96f 100644
--- a/tests/stm32/src/bin/eth.rs
+++ b/tests/stm32/src/bin/eth.rs
@@ -7,8 +7,8 @@ mod common;
7use common::*; 7use common::*;
8use embassy_executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_net::StackResources; 9use embassy_net::StackResources;
10use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue}; 10use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue, Sma};
11use embassy_stm32::peripherals::ETH; 11use embassy_stm32::peripherals::{ETH, ETH_SMA};
12use embassy_stm32::rng::Rng; 12use embassy_stm32::rng::Rng;
13use embassy_stm32::{bind_interrupts, eth, peripherals, rng}; 13use embassy_stm32::{bind_interrupts, eth, peripherals, rng};
14use static_cell::StaticCell; 14use static_cell::StaticCell;
@@ -27,7 +27,7 @@ bind_interrupts!(struct Irqs {
27 RNG => rng::InterruptHandler<peripherals::RNG>; 27 RNG => rng::InterruptHandler<peripherals::RNG>;
28}); 28});
29 29
30type Device = Ethernet<'static, ETH, GenericPhy>; 30type Device = Ethernet<'static, ETH, GenericPhy<Sma<'static, ETH_SMA>>>;
31 31
32#[embassy_executor::task] 32#[embassy_executor::task]
33async fn net_task(mut runner: embassy_net::Runner<'static, Device>) -> ! { 33async fn net_task(mut runner: embassy_net::Runner<'static, Device>) -> ! {
@@ -69,13 +69,12 @@ async fn main(spawner: Spawner) {
69 const PACKET_QUEUE_SIZE: usize = 4; 69 const PACKET_QUEUE_SIZE: usize = 4;
70 70
71 static PACKETS: StaticCell<PacketQueue<PACKET_QUEUE_SIZE, PACKET_QUEUE_SIZE>> = StaticCell::new(); 71 static PACKETS: StaticCell<PacketQueue<PACKET_QUEUE_SIZE, PACKET_QUEUE_SIZE>> = StaticCell::new();
72
72 let device = Ethernet::new( 73 let device = Ethernet::new(
73 PACKETS.init(PacketQueue::<PACKET_QUEUE_SIZE, PACKET_QUEUE_SIZE>::new()), 74 PACKETS.init(PacketQueue::<PACKET_QUEUE_SIZE, PACKET_QUEUE_SIZE>::new()),
74 p.ETH, 75 p.ETH,
75 Irqs, 76 Irqs,
76 p.PA1, 77 p.PA1,
77 p.PA2,
78 p.PC1,
79 p.PA7, 78 p.PA7,
80 p.PC4, 79 p.PC4,
81 p.PC5, 80 p.PC5,
@@ -85,8 +84,10 @@ async fn main(spawner: Spawner) {
85 #[cfg(feature = "stm32h563zi")] 84 #[cfg(feature = "stm32h563zi")]
86 p.PB15, 85 p.PB15,
87 p.PG11, 86 p.PG11,
88 GenericPhy::new_auto(),
89 mac_addr, 87 mac_addr,
88 p.ETH_SMA,
89 p.PA2,
90 p.PC1,
90 ); 91 );
91 92
92 let config = embassy_net::Config::dhcpv4(Default::default()); 93 let config = embassy_net::Config::dhcpv4(Default::default());
diff --git a/tests/stm32/src/bin/fdcan.rs b/tests/stm32/src/bin/fdcan.rs
index c2a1a7bb8..d97f493df 100644
--- a/tests/stm32/src/bin/fdcan.rs
+++ b/tests/stm32/src/bin/fdcan.rs
@@ -8,7 +8,7 @@ mod common;
8use common::*; 8use common::*;
9use embassy_executor::Spawner; 9use embassy_executor::Spawner;
10use embassy_stm32::peripherals::*; 10use embassy_stm32::peripherals::*;
11use embassy_stm32::{bind_interrupts, can, Config}; 11use embassy_stm32::{Config, bind_interrupts, can};
12use embassy_time::Duration; 12use embassy_time::Duration;
13use {defmt_rtt as _, panic_probe as _}; 13use {defmt_rtt as _, panic_probe as _};
14 14
diff --git a/tests/stm32/src/bin/hsem.rs b/tests/stm32/src/bin/hsem.rs
new file mode 100644
index 000000000..fa69f22b2
--- /dev/null
+++ b/tests/stm32/src/bin/hsem.rs
@@ -0,0 +1,50 @@
1// required-features: hsem
2#![no_std]
3#![no_main]
4
5#[path = "../common.rs"]
6mod common;
7
8use common::*;
9use embassy_executor::Spawner;
10use embassy_stm32::bind_interrupts;
11use embassy_stm32::hsem::{HardwareSemaphore, HardwareSemaphoreInterruptHandler};
12use embassy_stm32::peripherals::HSEM;
13
14bind_interrupts!(struct Irqs{
15 HSEM => HardwareSemaphoreInterruptHandler<HSEM>;
16});
17
18#[embassy_executor::main]
19async fn main(_spawner: Spawner) {
20 let p: embassy_stm32::Peripherals = init();
21
22 let hsem = HardwareSemaphore::new(p.HSEM, Irqs);
23
24 // if hsem.channel_for(SemaphoreNumber::Channel5).is_semaphore_locked() {
25 // defmt::panic!("Semaphore 5 already locked!")
26 // }
27 //
28 // hsem.channel_for(SemaphoreNumber::Channel5).one_step_lock().unwrap();
29 // hsem.channel_for(SemaphoreNumber::Channel1).two_step_lock(0).unwrap();
30 //
31 // hsem.channel_for(SemaphoreNumber::Channel5).unlock(0);
32
33 #[cfg(feature = "stm32wb55rg")]
34 let [_channel1, _channel2, mut channel5, _channel6] = hsem.split();
35 #[cfg(not(feature = "stm32wb55rg"))]
36 let [_channel1, _channel2, _channel3, _channel4, mut channel5, _channel6] = hsem.split();
37
38 info!("Locking channel 5");
39
40 let mutex = channel5.lock(0).await;
41
42 info!("Locked channel 5");
43
44 drop(mutex);
45
46 info!("Unlocked channel 5");
47
48 info!("Test OK");
49 cortex_m::asm::bkpt();
50}
diff --git a/tests/stm32/src/bin/rtc.rs b/tests/stm32/src/bin/rtc.rs
index 5fe98d807..eb27af4ca 100644
--- a/tests/stm32/src/bin/rtc.rs
+++ b/tests/stm32/src/bin/rtc.rs
@@ -10,13 +10,19 @@ use common::*;
10use defmt::assert; 10use defmt::assert;
11use embassy_executor::Spawner; 11use embassy_executor::Spawner;
12use embassy_stm32::rcc::LsConfig; 12use embassy_stm32::rcc::LsConfig;
13#[cfg(feature = "stop")]
14use embassy_stm32::rtc::Rtc;
15#[cfg(not(feature = "stop"))]
13use embassy_stm32::rtc::{Rtc, RtcConfig}; 16use embassy_stm32::rtc::{Rtc, RtcConfig};
14use embassy_time::Timer; 17use embassy_time::Timer;
15
16#[embassy_executor::main] 18#[embassy_executor::main]
17async fn main(_spawner: Spawner) { 19async fn main(_spawner: Spawner) {
18 let mut config = config(); 20 let mut config = config();
19 config.rcc.ls = LsConfig::default_lse(); 21 config.rcc.ls = LsConfig::default_lse();
22 #[cfg(feature = "stop")]
23 {
24 config.rtc._disable_rtc = false;
25 }
20 26
21 let p = init_with_config(config); 27 let p = init_with_config(config);
22 info!("Hello World!"); 28 info!("Hello World!");
@@ -26,14 +32,25 @@ async fn main(_spawner: Spawner) {
26 .and_hms_opt(10, 30, 15) 32 .and_hms_opt(10, 30, 15)
27 .unwrap(); 33 .unwrap();
28 34
29 let mut rtc = Rtc::new(p.RTC, RtcConfig::default()); 35 #[cfg(not(feature = "stop"))]
36 let (mut rtc, time_provider) = Rtc::new(p.RTC, RtcConfig::default());
37
38 #[cfg(feature = "stop")]
39 let (rtc, time_provider) = Rtc::new(p.RTC);
30 40
41 #[cfg(not(feature = "stop"))]
31 rtc.set_datetime(now.into()).expect("datetime not set"); 42 rtc.set_datetime(now.into()).expect("datetime not set");
32 43
44 #[cfg(feature = "stop")]
45 critical_section::with(|cs| {
46 rtc.borrow_mut(cs).set_datetime(now.into()).expect("datetime not set");
47 });
48
33 info!("Waiting 5 seconds"); 49 info!("Waiting 5 seconds");
34 Timer::after_millis(5000).await; 50 Timer::after_millis(5000).await;
35 51
36 let then: NaiveDateTime = rtc.now().unwrap().into(); 52 let then: NaiveDateTime = time_provider.now().unwrap().into();
53
37 let seconds = (then - now).num_seconds(); 54 let seconds = (then - now).num_seconds();
38 55
39 info!("measured = {}", seconds); 56 info!("measured = {}", seconds);
diff --git a/tests/stm32/src/bin/sdmmc.rs b/tests/stm32/src/bin/sdmmc.rs
index 9f9c526e1..07422c42e 100644
--- a/tests/stm32/src/bin/sdmmc.rs
+++ b/tests/stm32/src/bin/sdmmc.rs
@@ -7,7 +7,8 @@ mod common;
7use common::*; 7use common::*;
8use defmt::assert_eq; 8use defmt::assert_eq;
9use embassy_executor::Spawner; 9use embassy_executor::Spawner;
10use embassy_stm32::sdmmc::{DataBlock, Sdmmc}; 10use embassy_stm32::sdmmc::Sdmmc;
11use embassy_stm32::sdmmc::sd::{CmdBlock, DataBlock, StorageDevice};
11use embassy_stm32::time::mhz; 12use embassy_stm32::time::mhz;
12use embassy_stm32::{bind_interrupts, peripherals, sdmmc}; 13use embassy_stm32::{bind_interrupts, peripherals, sdmmc};
13use {defmt_rtt as _, panic_probe as _}; 14use {defmt_rtt as _, panic_probe as _};
@@ -28,16 +29,16 @@ async fn main(_spawner: Spawner) {
28 // Arbitrary block index 29 // Arbitrary block index
29 let block_idx = 16; 30 let block_idx = 16;
30 31
31 let mut pattern1 = DataBlock([0u8; 512]); 32 let mut pattern1 = DataBlock::new();
32 let mut pattern2 = DataBlock([0u8; 512]); 33 let mut pattern2 = DataBlock::new();
33 for i in 0..512 { 34 for i in 0..512 {
34 pattern1[i] = i as u8; 35 pattern1[i] = i as u8;
35 pattern2[i] = !i as u8; 36 pattern2[i] = !i as u8;
36 } 37 }
37 let patterns = [pattern1.clone(), pattern2.clone()]; 38 let patterns = [pattern1.clone(), pattern2.clone()];
38 39
39 let mut block = DataBlock([0u8; 512]); 40 let mut block = DataBlock::new();
40 let mut blocks = [DataBlock([0u8; 512]), DataBlock([0u8; 512])]; 41 let mut blocks = [DataBlock::new(), DataBlock::new()];
41 42
42 // ======== Try 4bit. ============== 43 // ======== Try 4bit. ==============
43 info!("initializing in 4-bit mode..."); 44 info!("initializing in 4-bit mode...");
@@ -54,43 +55,80 @@ async fn main(_spawner: Spawner) {
54 Default::default(), 55 Default::default(),
55 ); 56 );
56 57
57 let mut err = None; 58 let mut cmd_block = CmdBlock::new();
58 loop {
59 match s.init_sd_card(mhz(24)).await {
60 Ok(_) => break,
61 Err(e) => {
62 if err != Some(e) {
63 info!("waiting for card: {:?}", e);
64 err = Some(e);
65 }
66 }
67 }
68 }
69 59
70 let card = unwrap!(s.card()); 60 let mut storage = loop {
71 61 if let Ok(storage) = StorageDevice::new_sd_card(&mut s, &mut cmd_block, mhz(24)).await {
72 info!("Card: {:#?}", Debug2Format(card)); 62 break storage;
73 info!("Clock: {}", s.clock()); 63 }
64 };
65
66 let card = storage.card();
67
68 info!("Card: {:#?}", Debug2Format(&card));
69 info!("Clock: {}", storage.sdmmc.clock());
70
71 // card_type: HighCapacity,
72 // ocr: OCR: Operation Conditions Register {
73 // Voltage Window (mV): (2700, 3600),
74 // S18A (UHS-I only): true,
75 // Over 2TB flag (SDUC only): false,
76 // UHS-II Card: false,
77 // Card Capacity Status (CSS): \"SDHC/SDXC/SDUC\",
78 // Busy: false },
79 // rca: 43690,
80 // cid: CID: Card Identification { Manufacturer ID: 3,
81 // OEM ID: \"SD\",
82 // Product Name: \"SL08G\",
83 // Product Revision: 128,
84 // Product Serial Number: 701445767,
85 // Manufacturing Date: (9,
86 // 2015) },
87 // csd: CSD: Card Specific Data { Transfer Rate: 50,
88 // Block Count: 15523840,
89 // Card Size (bytes): 7948206080,
90 // Read I (@min VDD): 100 mA,
91 // Write I (@min VDD): 10 mA,
92 // Read I (@max VDD): 5 mA,
93 // Write I (@max VDD): 45 mA,
94 // Erase Size (Blocks): 1 },
95 // scr: SCR: SD CARD Configuration Register { Version: Unknown,
96 // 1-bit width: false,
97 // 4-bit width: true },
98 // status: SD Status { Bus Width: One,
99 // Secured Mode: false,
100 // SD Memory Card Type: 0,
101 // Protected Area Size (B): 0,
102 // Speed Class: 0,
103 // Video Speed Class: 0,
104 // Application Performance Class: 0,
105 // Move Performance (MB/s): 0,
106 // AU Size: 0,
107 // Erase Size (units of AU): 0,
108 // Erase Timeout (s): 0,
109 // Discard Support: false } }
110
111 defmt::assert!(card.scr.bus_width_four());
74 112
75 info!("writing pattern1..."); 113 info!("writing pattern1...");
76 s.write_block(block_idx, &pattern1).await.unwrap(); 114 storage.write_block(block_idx, &pattern1).await.unwrap();
77 115
78 info!("reading..."); 116 info!("reading...");
79 s.read_block(block_idx, &mut block).await.unwrap(); 117 storage.read_block(block_idx, &mut block).await.unwrap();
80 assert_eq!(block, pattern1); 118 assert_eq!(block, pattern1);
81 119
82 info!("writing pattern2..."); 120 info!("writing pattern2...");
83 s.write_block(block_idx, &pattern2).await.unwrap(); 121 storage.write_block(block_idx, &pattern2).await.unwrap();
84 122
85 info!("reading..."); 123 info!("reading...");
86 s.read_block(block_idx, &mut block).await.unwrap(); 124 storage.read_block(block_idx, &mut block).await.unwrap();
87 assert_eq!(block, pattern2); 125 assert_eq!(block, pattern2);
88 126
89 info!("writing blocks [pattern1, pattern2]..."); 127 info!("writing blocks [pattern1, pattern2]...");
90 s.write_blocks(block_idx, &patterns).await.unwrap(); 128 storage.write_blocks(block_idx, &patterns).await.unwrap();
91 129
92 info!("reading blocks..."); 130 info!("reading blocks...");
93 s.read_blocks(block_idx, &mut blocks).await.unwrap(); 131 storage.read_blocks(block_idx, &mut blocks).await.unwrap();
94 assert_eq!(&blocks, &patterns); 132 assert_eq!(&blocks, &patterns);
95 133
96 drop(s); 134 drop(s);
diff --git a/tests/stm32/src/bin/spi.rs b/tests/stm32/src/bin/spi.rs
index e8310866a..cedff772c 100644
--- a/tests/stm32/src/bin/spi.rs
+++ b/tests/stm32/src/bin/spi.rs
@@ -8,6 +8,7 @@ use defmt::assert_eq;
8use embassy_executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::mode::Blocking; 10use embassy_stm32::mode::Blocking;
11use embassy_stm32::spi::mode::Master;
11use embassy_stm32::spi::{self, Spi, Word}; 12use embassy_stm32::spi::{self, Spi, Word};
12use embassy_stm32::time::Hertz; 13use embassy_stm32::time::Hertz;
13 14
@@ -65,7 +66,7 @@ async fn main(_spawner: Spawner) {
65 cortex_m::asm::bkpt(); 66 cortex_m::asm::bkpt();
66} 67}
67 68
68fn test_txrx<W: Word + From<u8> + defmt::Format + Eq>(spi: &mut Spi<'_, Blocking>) 69fn test_txrx<W: Word + From<u8> + defmt::Format + Eq>(spi: &mut Spi<'_, Blocking, Master>)
69where 70where
70 W: core::ops::Not<Output = W>, 71 W: core::ops::Not<Output = W>,
71{ 72{
@@ -109,7 +110,7 @@ where
109 spi.blocking_write::<u8>(&[]).unwrap(); 110 spi.blocking_write::<u8>(&[]).unwrap();
110} 111}
111 112
112fn test_rx<W: Word + From<u8> + defmt::Format + Eq>(spi: &mut Spi<'_, Blocking>, mosi_out: &mut Output<'_>) 113fn test_rx<W: Word + From<u8> + defmt::Format + Eq>(spi: &mut Spi<'_, Blocking, Master>, mosi_out: &mut Output<'_>)
113where 114where
114 W: core::ops::Not<Output = W>, 115 W: core::ops::Not<Output = W>,
115{ 116{
@@ -125,7 +126,7 @@ where
125 spi.blocking_read::<u8>(&mut []).unwrap(); 126 spi.blocking_read::<u8>(&mut []).unwrap();
126} 127}
127 128
128fn test_tx<W: Word + From<u8> + defmt::Format + Eq>(spi: &mut Spi<'_, Blocking>) 129fn test_tx<W: Word + From<u8> + defmt::Format + Eq>(spi: &mut Spi<'_, Blocking, Master>)
129where 130where
130 W: core::ops::Not<Output = W>, 131 W: core::ops::Not<Output = W>,
131{ 132{
diff --git a/tests/stm32/src/bin/spi_dma.rs b/tests/stm32/src/bin/spi_dma.rs
index b4fdb8faa..c8cd92401 100644
--- a/tests/stm32/src/bin/spi_dma.rs
+++ b/tests/stm32/src/bin/spi_dma.rs
@@ -8,6 +8,7 @@ use defmt::assert_eq;
8use embassy_executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::mode::Async; 10use embassy_stm32::mode::Async;
11use embassy_stm32::spi::mode::Master;
11use embassy_stm32::spi::{self, Spi, Word}; 12use embassy_stm32::spi::{self, Spi, Word};
12use embassy_stm32::time::Hertz; 13use embassy_stm32::time::Hertz;
13 14
@@ -78,7 +79,7 @@ async fn main(_spawner: Spawner) {
78 cortex_m::asm::bkpt(); 79 cortex_m::asm::bkpt();
79} 80}
80 81
81async fn test_txrx<W: Word + From<u8> + defmt::Format + Eq>(spi: &mut Spi<'_, Async>) 82async fn test_txrx<W: Word + From<u8> + defmt::Format + Eq>(spi: &mut Spi<'_, Async, Master>)
82where 83where
83 W: core::ops::Not<Output = W>, 84 W: core::ops::Not<Output = W>,
84{ 85{
@@ -142,7 +143,7 @@ where
142 spi.write(&buf).await.unwrap(); 143 spi.write(&buf).await.unwrap();
143} 144}
144 145
145async fn test_rx<W: Word + From<u8> + defmt::Format + Eq>(spi: &mut Spi<'_, Async>, mosi_out: &mut Output<'_>) 146async fn test_rx<W: Word + From<u8> + defmt::Format + Eq>(spi: &mut Spi<'_, Async, Master>, mosi_out: &mut Output<'_>)
146where 147where
147 W: core::ops::Not<Output = W>, 148 W: core::ops::Not<Output = W>,
148{ 149{
@@ -168,7 +169,7 @@ where
168 spi.blocking_read::<u8>(&mut []).unwrap(); 169 spi.blocking_read::<u8>(&mut []).unwrap();
169} 170}
170 171
171async fn test_tx<W: Word + From<u8> + defmt::Format + Eq>(spi: &mut Spi<'_, Async>) 172async fn test_tx<W: Word + From<u8> + defmt::Format + Eq>(spi: &mut Spi<'_, Async, Master>)
172where 173where
173 W: core::ops::Not<Output = W>, 174 W: core::ops::Not<Output = W>,
174{ 175{
diff --git a/tests/stm32/src/bin/stop.rs b/tests/stm32/src/bin/stop.rs
index 8119c1f39..83c375bc5 100644
--- a/tests/stm32/src/bin/stop.rs
+++ b/tests/stm32/src/bin/stop.rs
@@ -7,21 +7,12 @@ mod common;
7 7
8use chrono::NaiveDate; 8use chrono::NaiveDate;
9use common::*; 9use common::*;
10use cortex_m_rt::entry;
11use embassy_executor::Spawner; 10use embassy_executor::Spawner;
12use embassy_stm32::low_power::{stop_ready, stop_with_rtc, Executor, StopMode}; 11use embassy_stm32::low_power::{StopMode, stop_ready};
13use embassy_stm32::rcc::LsConfig; 12use embassy_stm32::rcc::LsConfig;
14use embassy_stm32::rtc::{Rtc, RtcConfig}; 13use embassy_stm32::rtc::Rtc;
15use embassy_stm32::Config; 14use embassy_stm32::{Config, low_power};
16use embassy_time::Timer; 15use embassy_time::Timer;
17use static_cell::StaticCell;
18
19#[entry]
20fn main() -> ! {
21 Executor::take().run(|spawner| {
22 spawner.spawn(unwrap!(async_main(spawner)));
23 });
24}
25 16
26#[embassy_executor::task] 17#[embassy_executor::task]
27async fn task_1() { 18async fn task_1() {
@@ -44,12 +35,13 @@ async fn task_2() {
44 cortex_m::asm::bkpt(); 35 cortex_m::asm::bkpt();
45} 36}
46 37
47#[embassy_executor::task] 38#[embassy_executor::main(executor = "low_power::Executor")]
48async fn async_main(spawner: Spawner) { 39async fn async_main(spawner: Spawner) {
49 let _ = config(); 40 let _ = config();
50 41
51 let mut config = Config::default(); 42 let mut config = Config::default();
52 config.rcc.ls = LsConfig::default_lse(); 43 config.rcc.ls = LsConfig::default_lse();
44 config.rtc._disable_rtc = false;
53 45
54 // System Clock seems cannot be greater than 16 MHz 46 // System Clock seems cannot be greater than 16 MHz
55 #[cfg(any(feature = "stm32h563zi", feature = "stm32h503rb"))] 47 #[cfg(any(feature = "stm32h563zi", feature = "stm32h503rb"))]
@@ -66,14 +58,11 @@ async fn async_main(spawner: Spawner) {
66 .and_hms_opt(10, 30, 15) 58 .and_hms_opt(10, 30, 15)
67 .unwrap(); 59 .unwrap();
68 60
69 let mut rtc = Rtc::new(p.RTC, RtcConfig::default()); 61 let (rtc, _time_provider) = Rtc::new(p.RTC);
70 62
71 rtc.set_datetime(now.into()).expect("datetime not set"); 63 critical_section::with(|cs| {
72 64 rtc.borrow_mut(cs).set_datetime(now.into()).expect("datetime not set");
73 static RTC: StaticCell<Rtc> = StaticCell::new(); 65 });
74 let rtc = RTC.init(rtc);
75
76 stop_with_rtc(rtc);
77 66
78 spawner.spawn(task_1().unwrap()); 67 spawner.spawn(task_1().unwrap());
79 spawner.spawn(task_2().unwrap()); 68 spawner.spawn(task_2().unwrap());
diff --git a/tests/stm32/src/bin/ucpd.rs b/tests/stm32/src/bin/ucpd.rs
index 97aefe1a0..c794afff8 100644
--- a/tests/stm32/src/bin/ucpd.rs
+++ b/tests/stm32/src/bin/ucpd.rs
@@ -9,7 +9,7 @@ use defmt::{assert, assert_eq};
9use embassy_executor::Spawner; 9use embassy_executor::Spawner;
10use embassy_futures::join::join; 10use embassy_futures::join::join;
11use embassy_stm32::ucpd::{self, CcPhy, CcPull, CcSel, CcVState, RxError, Ucpd}; 11use embassy_stm32::ucpd::{self, CcPhy, CcPull, CcSel, CcVState, RxError, Ucpd};
12use embassy_stm32::{bind_interrupts, peripherals, Peri}; 12use embassy_stm32::{Peri, bind_interrupts, peripherals};
13use embassy_time::Timer; 13use embassy_time::Timer;
14 14
15bind_interrupts!(struct Irqs { 15bind_interrupts!(struct Irqs {
diff --git a/tests/stm32/src/bin/usart.rs b/tests/stm32/src/bin/usart.rs
index 129c7b692..ef7efe96a 100644
--- a/tests/stm32/src/bin/usart.rs
+++ b/tests/stm32/src/bin/usart.rs
@@ -6,8 +6,9 @@ mod common;
6use common::*; 6use common::*;
7use defmt::{assert, assert_eq, unreachable}; 7use defmt::{assert, assert_eq, unreachable};
8use embassy_executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_stm32::mode::Blocking;
9use embassy_stm32::usart::{Config, ConfigError, Error, Uart}; 10use embassy_stm32::usart::{Config, ConfigError, Error, Uart};
10use embassy_time::{block_for, Duration, Instant}; 11use embassy_time::{Duration, Instant, block_for};
11 12
12#[embassy_executor::main] 13#[embassy_executor::main]
13async fn main(_spawner: Spawner) { 14async fn main(_spawner: Spawner) {
@@ -24,22 +25,41 @@ async fn main(_spawner: Spawner) {
24 let config = Config::default(); 25 let config = Config::default();
25 let mut usart = Uart::new_blocking(usart.reborrow(), rx.reborrow(), tx.reborrow(), config).unwrap(); 26 let mut usart = Uart::new_blocking(usart.reborrow(), rx.reborrow(), tx.reborrow(), config).unwrap();
26 27
27 // We can't send too many bytes, they have to fit in the FIFO. 28 let test_usart = async |usart: &mut Uart<'_, Blocking>| -> Result<(), Error> {
28 // This is because we aren't sending+receiving at the same time. 29 // We can't send too many bytes, they have to fit in the FIFO.
30 // This is because we aren't sending+receiving at the same time.
29 31
30 let data = [0xC0, 0xDE]; 32 let data = [0xC0, 0xDE];
31 usart.blocking_write(&data).unwrap(); 33 usart.blocking_write(&data)?;
32 34
33 let mut buf = [0; 2]; 35 let mut buf = [0; 2];
34 usart.blocking_read(&mut buf).unwrap(); 36 usart.blocking_read(&mut buf)?;
35 assert_eq!(buf, data); 37 assert_eq!(buf, data);
36 38
37 // Test flush doesn't hang. 39 // Test flush doesn't hang.
38 usart.blocking_write(&data).unwrap(); 40 usart.blocking_write(&data)?;
39 usart.blocking_flush().unwrap(); 41 usart.blocking_flush()?;
40 42
41 // Test flush doesn't hang if there's nothing to flush 43 // Test flush doesn't hang if there's nothing to flush
42 usart.blocking_flush().unwrap(); 44 usart.blocking_flush()?;
45
46 Ok(())
47 };
48
49 let mut is_ok = false;
50 for _ in 0..3 {
51 match test_usart(&mut usart).await {
52 Ok(()) => is_ok = true,
53 Err(Error::Noise) => is_ok = false,
54 Err(e) => defmt::panic!("{}", e),
55 }
56
57 if is_ok {
58 break;
59 }
60 }
61
62 assert!(is_ok);
43 } 63 }
44 64
45 // Test error handling with with an overflow error 65 // Test error handling with with an overflow error
diff --git a/tests/stm32/src/bin/usart_dma.rs b/tests/stm32/src/bin/usart_dma.rs
index a34498376..9f610739d 100644
--- a/tests/stm32/src/bin/usart_dma.rs
+++ b/tests/stm32/src/bin/usart_dma.rs
@@ -7,7 +7,7 @@ use common::*;
7use defmt::assert_eq; 7use defmt::assert_eq;
8use embassy_executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_futures::join::join; 9use embassy_futures::join::join;
10use embassy_stm32::usart::{Config, Uart}; 10use embassy_stm32::usart::{Config, Error, Uart};
11 11
12#[embassy_executor::main] 12#[embassy_executor::main]
13async fn main(_spawner: Spawner) { 13async fn main(_spawner: Spawner) {
@@ -32,6 +32,7 @@ async fn main(_spawner: Spawner) {
32 32
33 let (mut tx, mut rx) = usart.split(); 33 let (mut tx, mut rx) = usart.split();
34 34
35 let mut noise_count = 0;
35 for n in 0..42 { 36 for n in 0..42 {
36 for i in 0..LEN { 37 for i in 0..LEN {
37 tx_buf[i] = (i ^ n) as u8; 38 tx_buf[i] = (i ^ n) as u8;
@@ -40,17 +41,30 @@ async fn main(_spawner: Spawner) {
40 let tx_fut = async { 41 let tx_fut = async {
41 tx.write(&tx_buf).await.unwrap(); 42 tx.write(&tx_buf).await.unwrap();
42 }; 43 };
44
45 let mut is_noisy = false;
43 let rx_fut = async { 46 let rx_fut = async {
44 rx.read(&mut rx_buf).await.unwrap(); 47 match rx.read(&mut rx_buf).await {
48 Ok(()) => {}
49 Err(Error::Noise) => is_noisy = true,
50 _ => defmt::panic!(),
51 }
45 }; 52 };
46 53
47 // note: rx needs to be polled first, to workaround this bug: 54 // note: rx needs to be polled first, to workaround this bug:
48 // https://github.com/embassy-rs/embassy/issues/1426 55 // https://github.com/embassy-rs/embassy/issues/1426
49 join(rx_fut, tx_fut).await; 56 join(rx_fut, tx_fut).await;
50 57
58 if is_noisy {
59 noise_count += 1;
60 continue;
61 }
62
51 assert_eq!(tx_buf, rx_buf); 63 assert_eq!(tx_buf, rx_buf);
52 } 64 }
53 65
66 defmt::assert!(noise_count < 3);
67
54 // Test flush doesn't hang. Check multiple combinations of async+blocking. 68 // Test flush doesn't hang. Check multiple combinations of async+blocking.
55 tx.write(&tx_buf).await.unwrap(); 69 tx.write(&tx_buf).await.unwrap();
56 tx.flush().await.unwrap(); 70 tx.flush().await.unwrap();
diff --git a/tests/stm32/src/bin/wpan_ble.rs b/tests/stm32/src/bin/wpan_ble.rs
index 8957bfc04..b4c0cbf56 100644
--- a/tests/stm32/src/bin/wpan_ble.rs
+++ b/tests/stm32/src/bin/wpan_ble.rs
@@ -12,16 +12,16 @@ use embassy_executor::Spawner;
12use embassy_stm32::bind_interrupts; 12use embassy_stm32::bind_interrupts;
13use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; 13use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
14use embassy_stm32::rcc::WPAN_DEFAULT; 14use embassy_stm32::rcc::WPAN_DEFAULT;
15use embassy_stm32_wpan::TlMbox;
16use embassy_stm32_wpan::hci::BdAddr;
15use embassy_stm32_wpan::hci::host::uart::UartHci; 17use embassy_stm32_wpan::hci::host::uart::UartHci;
16use embassy_stm32_wpan::hci::host::{AdvertisingFilterPolicy, EncryptionKey, HostHci, OwnAddressType}; 18use embassy_stm32_wpan::hci::host::{AdvertisingFilterPolicy, EncryptionKey, HostHci, OwnAddressType};
17use embassy_stm32_wpan::hci::types::AdvertisingType; 19use embassy_stm32_wpan::hci::types::AdvertisingType;
18use embassy_stm32_wpan::hci::vendor::command::gap::{AdvertisingDataType, DiscoverableParameters, GapCommands, Role}; 20use embassy_stm32_wpan::hci::vendor::command::gap::{AdvertisingDataType, DiscoverableParameters, GapCommands, Role};
19use embassy_stm32_wpan::hci::vendor::command::gatt::GattCommands; 21use embassy_stm32_wpan::hci::vendor::command::gatt::GattCommands;
20use embassy_stm32_wpan::hci::vendor::command::hal::{ConfigData, HalCommands, PowerLevel}; 22use embassy_stm32_wpan::hci::vendor::command::hal::{ConfigData, HalCommands, PowerLevel};
21use embassy_stm32_wpan::hci::BdAddr;
22use embassy_stm32_wpan::lhci::LhciC1DeviceInformationCcrp; 23use embassy_stm32_wpan::lhci::LhciC1DeviceInformationCcrp;
23use embassy_stm32_wpan::sub::mm; 24use embassy_stm32_wpan::sub::mm;
24use embassy_stm32_wpan::TlMbox;
25use {defmt_rtt as _, panic_probe as _}; 25use {defmt_rtt as _, panic_probe as _};
26 26
27bind_interrupts!(struct Irqs{ 27bind_interrupts!(struct Irqs{
@@ -32,7 +32,7 @@ bind_interrupts!(struct Irqs{
32const BLE_GAP_DEVICE_NAME_LENGTH: u8 = 7; 32const BLE_GAP_DEVICE_NAME_LENGTH: u8 = 7;
33 33
34#[embassy_executor::task] 34#[embassy_executor::task]
35async fn run_mm_queue(memory_manager: mm::MemoryManager) { 35async fn run_mm_queue(mut memory_manager: mm::MemoryManager<'static>) {
36 memory_manager.run_queue().await; 36 memory_manager.run_queue().await;
37} 37}
38 38
@@ -45,14 +45,13 @@ async fn main(spawner: Spawner) {
45 info!("Hello World!"); 45 info!("Hello World!");
46 46
47 let config = Config::default(); 47 let config = Config::default();
48 let mut mbox = TlMbox::init(p.IPCC, Irqs, config); 48 let mbox = TlMbox::init(p.IPCC, Irqs, config).await;
49 let mut sys = mbox.sys_subsystem;
50 let mut ble = mbox.ble_subsystem;
49 51
50 spawner.spawn(run_mm_queue(mbox.mm_subsystem).unwrap()); 52 spawner.spawn(run_mm_queue(mbox.mm_subsystem).unwrap());
51 53
52 let sys_event = mbox.sys_subsystem.read().await; 54 let fw_info = sys.wireless_fw_info().unwrap();
53 info!("sys event: {}", sys_event.payload());
54
55 let fw_info = mbox.sys_subsystem.wireless_fw_info().unwrap();
56 let version_major = fw_info.version_major(); 55 let version_major = fw_info.version_major();
57 let version_minor = fw_info.version_minor(); 56 let version_minor = fw_info.version_minor();
58 let subversion = fw_info.subversion(); 57 let subversion = fw_info.subversion();
@@ -65,121 +64,108 @@ async fn main(spawner: Spawner) {
65 version_major, version_minor, subversion, sram2a_size, sram2b_size 64 version_major, version_minor, subversion, sram2a_size, sram2b_size
66 ); 65 );
67 66
68 let _ = mbox.sys_subsystem.shci_c2_ble_init(Default::default()).await; 67 let _ = sys.shci_c2_ble_init(Default::default()).await;
69 68
70 info!("resetting BLE..."); 69 info!("resetting BLE...");
71 mbox.ble_subsystem.reset().await; 70 ble.reset().await;
72 let response = mbox.ble_subsystem.read().await.unwrap(); 71 let response = ble.read().await.unwrap();
73 info!("{}", response); 72 info!("{}", response);
74 73
75 info!("config public address..."); 74 info!("config public address...");
76 mbox.ble_subsystem 75 ble.write_config_data(&ConfigData::public_address(get_bd_addr()).build())
77 .write_config_data(&ConfigData::public_address(get_bd_addr()).build())
78 .await; 76 .await;
79 let response = mbox.ble_subsystem.read().await.unwrap(); 77 let response = ble.read().await.unwrap();
80 info!("{}", response); 78 info!("{}", response);
81 79
82 info!("config random address..."); 80 info!("config random address...");
83 mbox.ble_subsystem 81 ble.write_config_data(&ConfigData::random_address(get_random_addr()).build())
84 .write_config_data(&ConfigData::random_address(get_random_addr()).build())
85 .await; 82 .await;
86 let response = mbox.ble_subsystem.read().await.unwrap(); 83 let response = ble.read().await.unwrap();
87 info!("{}", response); 84 info!("{}", response);
88 85
89 info!("config identity root..."); 86 info!("config identity root...");
90 mbox.ble_subsystem 87 ble.write_config_data(&ConfigData::identity_root(&get_irk()).build())
91 .write_config_data(&ConfigData::identity_root(&get_irk()).build())
92 .await; 88 .await;
93 let response = mbox.ble_subsystem.read().await.unwrap(); 89 let response = ble.read().await.unwrap();
94 info!("{}", response); 90 info!("{}", response);
95 91
96 info!("config encryption root..."); 92 info!("config encryption root...");
97 mbox.ble_subsystem 93 ble.write_config_data(&ConfigData::encryption_root(&get_erk()).build())
98 .write_config_data(&ConfigData::encryption_root(&get_erk()).build())
99 .await; 94 .await;
100 let response = mbox.ble_subsystem.read().await.unwrap(); 95 let response = ble.read().await.unwrap();
101 info!("{}", response); 96 info!("{}", response);
102 97
103 info!("config tx power level..."); 98 info!("config tx power level...");
104 mbox.ble_subsystem.set_tx_power_level(PowerLevel::ZerodBm).await; 99 ble.set_tx_power_level(PowerLevel::ZerodBm).await;
105 let response = mbox.ble_subsystem.read().await.unwrap(); 100 let response = ble.read().await.unwrap();
106 info!("{}", response); 101 info!("{}", response);
107 102
108 info!("GATT init..."); 103 info!("GATT init...");
109 mbox.ble_subsystem.init_gatt().await; 104 ble.init_gatt().await;
110 let response = mbox.ble_subsystem.read().await.unwrap(); 105 let response = ble.read().await.unwrap();
111 info!("{}", response); 106 info!("{}", response);
112 107
113 info!("GAP init..."); 108 info!("GAP init...");
114 mbox.ble_subsystem 109 ble.init_gap(Role::PERIPHERAL, false, BLE_GAP_DEVICE_NAME_LENGTH).await;
115 .init_gap(Role::PERIPHERAL, false, BLE_GAP_DEVICE_NAME_LENGTH) 110 let response = ble.read().await.unwrap();
116 .await;
117 let response = mbox.ble_subsystem.read().await.unwrap();
118 info!("{}", response); 111 info!("{}", response);
119 112
120 // info!("set scan response..."); 113 // info!("set scan response...");
121 // mbox.ble_subsystem.le_set_scan_response_data(&[]).await.unwrap(); 114 // ble.le_set_scan_response_data(&[]).await.unwrap();
122 // let response = mbox.ble_subsystem.read().await.unwrap(); 115 // let response = ble.read().await.unwrap();
123 // info!("{}", response); 116 // info!("{}", response);
124 117
125 info!("set discoverable..."); 118 info!("set discoverable...");
126 mbox.ble_subsystem 119 ble.set_discoverable(&DiscoverableParameters {
127 .set_discoverable(&DiscoverableParameters { 120 advertising_type: AdvertisingType::NonConnectableUndirected,
128 advertising_type: AdvertisingType::NonConnectableUndirected, 121 advertising_interval: Some((Duration::from_millis(250), Duration::from_millis(250))),
129 advertising_interval: Some((Duration::from_millis(250), Duration::from_millis(250))), 122 address_type: OwnAddressType::Public,
130 address_type: OwnAddressType::Public, 123 filter_policy: AdvertisingFilterPolicy::AllowConnectionAndScan,
131 filter_policy: AdvertisingFilterPolicy::AllowConnectionAndScan, 124 local_name: None,
132 local_name: None, 125 advertising_data: &[],
133 advertising_data: &[], 126 conn_interval: (None, None),
134 conn_interval: (None, None), 127 })
135 }) 128 .await
136 .await 129 .unwrap();
137 .unwrap(); 130
138 131 let response = ble.read().await;
139 let response = mbox.ble_subsystem.read().await;
140 info!("{}", response); 132 info!("{}", response);
141 133
142 // remove some advertisement to decrease the packet size 134 // remove some advertisement to decrease the packet size
143 info!("delete tx power ad type..."); 135 info!("delete tx power ad type...");
144 mbox.ble_subsystem 136 ble.delete_ad_type(AdvertisingDataType::TxPowerLevel).await;
145 .delete_ad_type(AdvertisingDataType::TxPowerLevel) 137 let response = ble.read().await.unwrap();
146 .await;
147 let response = mbox.ble_subsystem.read().await.unwrap();
148 info!("{}", response); 138 info!("{}", response);
149 139
150 info!("delete conn interval ad type..."); 140 info!("delete conn interval ad type...");
151 mbox.ble_subsystem 141 ble.delete_ad_type(AdvertisingDataType::PeripheralConnectionInterval)
152 .delete_ad_type(AdvertisingDataType::PeripheralConnectionInterval)
153 .await; 142 .await;
154 let response = mbox.ble_subsystem.read().await.unwrap(); 143 let response = ble.read().await.unwrap();
155 info!("{}", response); 144 info!("{}", response);
156 145
157 info!("update advertising data..."); 146 info!("update advertising data...");
158 mbox.ble_subsystem 147 ble.update_advertising_data(&eddystone_advertising_data())
159 .update_advertising_data(&eddystone_advertising_data())
160 .await 148 .await
161 .unwrap(); 149 .unwrap();
162 let response = mbox.ble_subsystem.read().await.unwrap(); 150 let response = ble.read().await.unwrap();
163 info!("{}", response); 151 info!("{}", response);
164 152
165 info!("update advertising data type..."); 153 info!("update advertising data type...");
166 mbox.ble_subsystem 154 ble.update_advertising_data(&[3, AdvertisingDataType::UuidCompleteList16 as u8, 0xaa, 0xfe])
167 .update_advertising_data(&[3, AdvertisingDataType::UuidCompleteList16 as u8, 0xaa, 0xfe])
168 .await 155 .await
169 .unwrap(); 156 .unwrap();
170 let response = mbox.ble_subsystem.read().await.unwrap(); 157 let response = ble.read().await.unwrap();
171 info!("{}", response); 158 info!("{}", response);
172 159
173 info!("update advertising data flags..."); 160 info!("update advertising data flags...");
174 mbox.ble_subsystem 161 ble.update_advertising_data(&[
175 .update_advertising_data(&[ 162 2,
176 2, 163 AdvertisingDataType::Flags as u8,
177 AdvertisingDataType::Flags as u8, 164 (0x02 | 0x04) as u8, // BLE general discoverable, without BR/EDR support
178 (0x02 | 0x04) as u8, // BLE general discoverable, without BR/EDR support 165 ])
179 ]) 166 .await
180 .await 167 .unwrap();
181 .unwrap(); 168 let response = ble.read().await.unwrap();
182 let response = mbox.ble_subsystem.read().await.unwrap();
183 info!("{}", response); 169 info!("{}", response);
184 170
185 info!("Test OK"); 171 info!("Test OK");
diff --git a/tests/stm32/src/bin/wpan_mac.rs b/tests/stm32/src/bin/wpan_mac.rs
index 79e13d524..42db39e7e 100644
--- a/tests/stm32/src/bin/wpan_mac.rs
+++ b/tests/stm32/src/bin/wpan_mac.rs
@@ -10,13 +10,13 @@ use embassy_executor::Spawner;
10use embassy_stm32::bind_interrupts; 10use embassy_stm32::bind_interrupts;
11use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; 11use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
12use embassy_stm32::rcc::WPAN_DEFAULT; 12use embassy_stm32::rcc::WPAN_DEFAULT;
13use embassy_stm32_wpan::TlMbox;
13use embassy_stm32_wpan::mac::commands::{AssociateRequest, GetRequest, ResetRequest, SetRequest}; 14use embassy_stm32_wpan::mac::commands::{AssociateRequest, GetRequest, ResetRequest, SetRequest};
14use embassy_stm32_wpan::mac::event::MacEvent; 15use embassy_stm32_wpan::mac::event::MacEvent;
15use embassy_stm32_wpan::mac::typedefs::{ 16use embassy_stm32_wpan::mac::typedefs::{
16 AddressMode, Capabilities, KeyIdMode, MacAddress, MacChannel, PanId, PibId, SecurityLevel, 17 AddressMode, Capabilities, KeyIdMode, MacAddress, MacChannel, PanId, PibId, SecurityLevel,
17}; 18};
18use embassy_stm32_wpan::sub::mm; 19use embassy_stm32_wpan::sub::mm;
19use embassy_stm32_wpan::TlMbox;
20use {defmt_rtt as _, panic_probe as _}; 20use {defmt_rtt as _, panic_probe as _};
21 21
22bind_interrupts!(struct Irqs{ 22bind_interrupts!(struct Irqs{
@@ -25,7 +25,7 @@ bind_interrupts!(struct Irqs{
25}); 25});
26 26
27#[embassy_executor::task] 27#[embassy_executor::task]
28async fn run_mm_queue(memory_manager: mm::MemoryManager) { 28async fn run_mm_queue(mut memory_manager: mm::MemoryManager<'static>) {
29 memory_manager.run_queue().await; 29 memory_manager.run_queue().await;
30} 30}
31 31
@@ -38,20 +38,17 @@ async fn main(spawner: Spawner) {
38 info!("Hello World!"); 38 info!("Hello World!");
39 39
40 let config = Config::default(); 40 let config = Config::default();
41 let mbox = TlMbox::init(p.IPCC, Irqs, config); 41 let mbox = TlMbox::init(p.IPCC, Irqs, config).await;
42 let mut sys = mbox.sys_subsystem;
43 let (mut mac_rx, mut mac_tx) = mbox.mac_subsystem.split();
42 44
43 spawner.spawn(run_mm_queue(mbox.mm_subsystem).unwrap()); 45 spawner.spawn(run_mm_queue(mbox.mm_subsystem).unwrap());
44 46
45 let sys_event = mbox.sys_subsystem.read().await; 47 let result = sys.shci_c2_mac_802_15_4_init().await;
46 info!("sys event: {}", sys_event.payload());
47
48 core::mem::drop(sys_event);
49
50 let result = mbox.sys_subsystem.shci_c2_mac_802_15_4_init().await;
51 info!("initialized mac: {}", result); 48 info!("initialized mac: {}", result);
52 49
53 info!("resetting"); 50 info!("resetting");
54 mbox.mac_subsystem 51 mac_tx
55 .send_command(&ResetRequest { 52 .send_command(&ResetRequest {
56 set_default_pib: true, 53 set_default_pib: true,
57 ..Default::default() 54 ..Default::default()
@@ -59,13 +56,13 @@ async fn main(spawner: Spawner) {
59 .await 56 .await
60 .unwrap(); 57 .unwrap();
61 { 58 {
62 let evt = mbox.mac_subsystem.read().await.unwrap(); 59 let evt = mac_rx.read().await.unwrap();
63 info!("{:#x}", evt); 60 info!("{:#x}", evt);
64 } 61 }
65 62
66 info!("setting extended address"); 63 info!("setting extended address");
67 let extended_address: u64 = 0xACDE480000000002; 64 let extended_address: u64 = 0xACDE480000000002;
68 mbox.mac_subsystem 65 mac_tx
69 .send_command(&SetRequest { 66 .send_command(&SetRequest {
70 pib_attribute_ptr: &extended_address as *const _ as *const u8, 67 pib_attribute_ptr: &extended_address as *const _ as *const u8,
71 pib_attribute: PibId::ExtendedAddress, 68 pib_attribute: PibId::ExtendedAddress,
@@ -73,12 +70,12 @@ async fn main(spawner: Spawner) {
73 .await 70 .await
74 .unwrap(); 71 .unwrap();
75 { 72 {
76 let evt = mbox.mac_subsystem.read().await.unwrap(); 73 let evt = mac_rx.read().await.unwrap();
77 info!("{:#x}", evt); 74 info!("{:#x}", evt);
78 } 75 }
79 76
80 info!("getting extended address"); 77 info!("getting extended address");
81 mbox.mac_subsystem 78 mac_tx
82 .send_command(&GetRequest { 79 .send_command(&GetRequest {
83 pib_attribute: PibId::ExtendedAddress, 80 pib_attribute: PibId::ExtendedAddress,
84 ..Default::default() 81 ..Default::default()
@@ -87,7 +84,7 @@ async fn main(spawner: Spawner) {
87 .unwrap(); 84 .unwrap();
88 85
89 { 86 {
90 let evt = mbox.mac_subsystem.read().await.unwrap(); 87 let evt = mac_rx.read().await.unwrap();
91 info!("{:#x}", evt); 88 info!("{:#x}", evt);
92 89
93 if let MacEvent::MlmeGetCnf(evt) = evt { 90 if let MacEvent::MlmeGetCnf(evt) = evt {
@@ -113,8 +110,8 @@ async fn main(spawner: Spawner) {
113 key_index: 152, 110 key_index: 152,
114 }; 111 };
115 info!("{}", a); 112 info!("{}", a);
116 mbox.mac_subsystem.send_command(&a).await.unwrap(); 113 mac_tx.send_command(&a).await.unwrap();
117 let short_addr = if let MacEvent::MlmeAssociateCnf(conf) = mbox.mac_subsystem.read().await.unwrap() { 114 let short_addr = if let MacEvent::MlmeAssociateCnf(conf) = mac_rx.read().await.unwrap() {
118 conf.assoc_short_address 115 conf.assoc_short_address
119 } else { 116 } else {
120 defmt::panic!() 117 defmt::panic!()
diff --git a/tests/stm32/src/common.rs b/tests/stm32/src/common.rs
index f800769ab..9f88b182a 100644
--- a/tests/stm32/src/common.rs
+++ b/tests/stm32/src/common.rs
@@ -1,11 +1,11 @@
1#![macro_use] 1#![macro_use]
2 2
3pub use defmt::*; 3pub use defmt::*;
4use embassy_stm32::Config;
4#[allow(unused)] 5#[allow(unused)]
5use embassy_stm32::rcc::*; 6use embassy_stm32::rcc::*;
6#[allow(unused)] 7#[allow(unused)]
7use embassy_stm32::time::Hertz; 8use embassy_stm32::time::Hertz;
8use embassy_stm32::Config;
9use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
10 10
11#[cfg(feature = "stm32f103c8")] 11#[cfg(feature = "stm32f103c8")]
@@ -259,6 +259,7 @@ define_peris!(
259define_peris!( 259define_peris!(
260 UART = LPUART1, UART_TX = PB5, UART_RX = PA10, UART_TX_DMA = GPDMA1_CH0, UART_RX_DMA = GPDMA1_CH1, 260 UART = LPUART1, UART_TX = PB5, UART_RX = PA10, UART_TX_DMA = GPDMA1_CH0, UART_RX_DMA = GPDMA1_CH1,
261 SPI = SPI1, SPI_SCK = PB4, SPI_MOSI = PA15, SPI_MISO = PB3, SPI_TX_DMA = GPDMA1_CH0, SPI_RX_DMA = GPDMA1_CH1, 261 SPI = SPI1, SPI_SCK = PB4, SPI_MOSI = PA15, SPI_MISO = PB3, SPI_TX_DMA = GPDMA1_CH0, SPI_RX_DMA = GPDMA1_CH1,
262 ADC = ADC4, DAC_PIN = PA0,
262 @irq UART = {LPUART1 => embassy_stm32::usart::InterruptHandler<embassy_stm32::peripherals::LPUART1>;}, 263 @irq UART = {LPUART1 => embassy_stm32::usart::InterruptHandler<embassy_stm32::peripherals::LPUART1>;},
263); 264);
264#[cfg(feature = "stm32h7s3l8")] 265#[cfg(feature = "stm32h7s3l8")]
@@ -468,6 +469,8 @@ pub fn config() -> Config {
468 config.rcc.apb3_pre = APBPrescaler::DIV1; 469 config.rcc.apb3_pre = APBPrescaler::DIV1;
469 config.rcc.sys = Sysclk::PLL1_P; 470 config.rcc.sys = Sysclk::PLL1_P;
470 config.rcc.voltage_scale = VoltageScale::Scale0; 471 config.rcc.voltage_scale = VoltageScale::Scale0;
472
473 config.rtc._disable_rtc = true;
471 } 474 }
472 475
473 #[cfg(feature = "stm32h503rb")] 476 #[cfg(feature = "stm32h503rb")]
diff --git a/tests/utils/Cargo.toml b/tests/utils/Cargo.toml
index ddb990e0f..da04a1f5d 100644
--- a/tests/utils/Cargo.toml
+++ b/tests/utils/Cargo.toml
@@ -1,7 +1,7 @@
1[package] 1[package]
2name = "test-utils" 2name = "test-utils"
3version = "0.1.0" 3version = "0.1.0"
4edition = "2021" 4edition = "2024"
5license = "MIT OR Apache-2.0" 5license = "MIT OR Apache-2.0"
6publish = false 6publish = false
7 7
diff --git a/tests/utils/src/bin/saturate_serial.rs b/tests/utils/src/bin/saturate_serial.rs
index 85676b106..1c8a8b322 100644
--- a/tests/utils/src/bin/saturate_serial.rs
+++ b/tests/utils/src/bin/saturate_serial.rs
@@ -2,7 +2,7 @@ use std::path::Path;
2use std::time::Duration; 2use std::time::Duration;
3use std::{env, io, process, thread}; 3use std::{env, io, process, thread};
4 4
5use rand::{rng, Rng}; 5use rand::{Rng, rng};
6use serial::SerialPort; 6use serial::SerialPort;
7 7
8pub fn main() { 8pub fn main() {