aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorjrmoulton <[email protected]>2025-06-10 15:47:54 -0600
committerjrmoulton <[email protected]>2025-06-10 15:48:36 -0600
commitcfad9798ff99d4de0571a512d156b5fe1ef1d427 (patch)
treefc3bf670f82d139de19466cddad1e909db7f3d2e /tests
parentfc342915e6155dec7bafa3e135da7f37a9a07f5c (diff)
parent6186d111a5c150946ee5b7e9e68d987a38c1a463 (diff)
merge new embassy changes
Diffstat (limited to 'tests')
-rw-r--r--tests/mspm0/.cargo/config.toml8
-rw-r--r--tests/mspm0/Cargo.toml58
-rw-r--r--tests/mspm0/build.rs26
-rw-r--r--tests/mspm0/memory_g3507.x6
-rw-r--r--tests/mspm0/src/bin/uart.rs83
-rw-r--r--tests/nrf/Cargo.toml25
-rw-r--r--tests/nrf/src/bin/buffered_uart.rs14
-rw-r--r--tests/nrf/src/bin/buffered_uart_full.rs2
-rw-r--r--tests/nrf/src/bin/buffered_uart_halves.rs16
-rw-r--r--tests/nrf/src/bin/buffered_uart_spam.rs20
-rw-r--r--tests/nrf/src/bin/ethernet_enc28j60_perf.rs11
-rw-r--r--tests/nrf/src/bin/gpio.rs2
-rw-r--r--tests/nrf/src/bin/spim.rs42
-rw-r--r--tests/nrf/src/bin/uart_halves.rs14
-rw-r--r--tests/nrf/src/bin/uart_split.rs6
-rw-r--r--tests/nrf/src/bin/wifi_esp_hosted_perf.rs13
-rw-r--r--tests/nrf/src/common.rs35
-rw-r--r--tests/perf-client/Cargo.toml6
-rw-r--r--tests/perf-client/src/lib.rs9
-rw-r--r--tests/riscv32/Cargo.toml6
-rw-r--r--tests/rp/.cargo/config.toml7
-rw-r--r--tests/rp/Cargo.toml54
-rw-r--r--tests/rp/readme.md8
-rw-r--r--tests/rp/src/bin/adc.rs50
-rw-r--r--tests/rp/src/bin/bootsel.rs5
-rw-r--r--tests/rp/src/bin/cyw43-perf.rs46
-rw-r--r--tests/rp/src/bin/dma_copy_async.rs3
-rw-r--r--tests/rp/src/bin/ethernet_w5100s_perf.rs14
-rw-r--r--tests/rp/src/bin/flash.rs19
-rw-r--r--tests/rp/src/bin/gpio.rs84
-rw-r--r--tests/rp/src/bin/gpio_async.rs27
-rw-r--r--tests/rp/src/bin/gpio_multicore.rs10
-rw-r--r--tests/rp/src/bin/i2c.rs25
-rw-r--r--tests/rp/src/bin/multicore.rs3
-rw-r--r--tests/rp/src/bin/overclock.rs69
-rw-r--r--tests/rp/src/bin/pio_irq.rs6
-rw-r--r--tests/rp/src/bin/pio_multi_load.rs19
-rw-r--r--tests/rp/src/bin/pwm.rs61
-rw-r--r--tests/rp/src/bin/spi.rs3
-rw-r--r--tests/rp/src/bin/spi_async.rs3
-rw-r--r--tests/rp/src/bin/spinlock_mutex_multicore.rs54
-rw-r--r--tests/rp/src/bin/timer.rs3
-rw-r--r--tests/rp/src/bin/uart.rs23
-rw-r--r--tests/rp/src/bin/uart_buffered.rs47
-rw-r--r--tests/rp/src/bin/uart_dma.rs47
-rw-r--r--tests/rp/src/bin/uart_upgrade.rs3
-rw-r--r--tests/stm32/.cargo/config.toml1
-rw-r--r--tests/stm32/Cargo.toml44
-rw-r--r--tests/stm32/src/bin/can.rs2
-rw-r--r--tests/stm32/src/bin/cordic.rs4
-rw-r--r--tests/stm32/src/bin/dac.rs3
-rw-r--r--tests/stm32/src/bin/dac_l1.rs3
-rw-r--r--tests/stm32/src/bin/eeprom.rs30
-rw-r--r--tests/stm32/src/bin/eth.rs19
-rw-r--r--tests/stm32/src/bin/gpio.rs44
-rw-r--r--tests/stm32/src/bin/hash.rs3
-rw-r--r--tests/stm32/src/bin/sdmmc.rs50
-rw-r--r--tests/stm32/src/bin/spi.rs106
-rw-r--r--tests/stm32/src/bin/spi_dma.rs134
-rw-r--r--tests/stm32/src/bin/ucpd.rs14
-rw-r--r--tests/stm32/src/bin/usart.rs13
-rw-r--r--tests/stm32/src/bin/usart_dma.rs17
-rw-r--r--tests/stm32/src/bin/usart_rx_ringbuffered.rs3
-rw-r--r--tests/stm32/src/common.rs4
-rw-r--r--tests/utils/Cargo.toml2
65 files changed, 1146 insertions, 445 deletions
diff --git a/tests/mspm0/.cargo/config.toml b/tests/mspm0/.cargo/config.toml
new file mode 100644
index 000000000..825bf3ae9
--- /dev/null
+++ b/tests/mspm0/.cargo/config.toml
@@ -0,0 +1,8 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2runner = "teleprobe local run --chip MSPM0G3507 --protocol swd --elf"
3
4[build]
5target = "thumbv6m-none-eabi"
6
7[env]
8DEFMT_LOG = "trace,embassy_hal_internal=debug"
diff --git a/tests/mspm0/Cargo.toml b/tests/mspm0/Cargo.toml
new file mode 100644
index 000000000..298522d09
--- /dev/null
+++ b/tests/mspm0/Cargo.toml
@@ -0,0 +1,58 @@
1[package]
2edition = "2021"
3name = "embassy-mspm0-tests"
4version = "0.1.0"
5license = "MIT OR Apache-2.0"
6
7[features]
8mspm0g3507 = [ "embassy-mspm0/mspm0g3507pm" ]
9
10[dependencies]
11teleprobe-meta = "1.1"
12
13embassy-sync = { version = "0.7.0", path = "../../embassy-sync", features = [ "defmt" ] }
14embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = [ "arch-cortex-m", "executor-thread", "defmt" ] }
15embassy-time = { version = "0.4.0", path = "../../embassy-time", features = [ "defmt" ] }
16embassy-mspm0 = { version = "0.1.0", path = "../../embassy-mspm0", features = [ "rt", "defmt", "unstable-pac", "time-driver-any" ] }
17embassy-embedded-hal = { version = "0.3.0", path = "../../embassy-embedded-hal/"}
18
19defmt = "1.0.1"
20defmt-rtt = "1.0.0"
21
22cortex-m = { version = "0.7.6", features = [ "inline-asm", "critical-section-single-core" ]}
23cortex-m-rt = "0.7.0"
24embedded-hal = { package = "embedded-hal", version = "1.0" }
25embedded-hal-async = { version = "1.0" }
26panic-probe = { version = "1.0.0", features = ["print-defmt"] }
27static_cell = "2"
28portable-atomic = { version = "1.5", features = ["critical-section"] }
29
30[profile.dev]
31debug = 2
32debug-assertions = true
33opt-level = 's'
34overflow-checks = true
35
36[profile.release]
37codegen-units = 1
38debug = 2
39debug-assertions = false
40incremental = false
41lto = "fat"
42opt-level = 's'
43overflow-checks = false
44
45# do not optimize proc-macro crates = faster builds from scratch
46[profile.dev.build-override]
47codegen-units = 8
48debug = false
49debug-assertions = false
50opt-level = 0
51overflow-checks = false
52
53[profile.release.build-override]
54codegen-units = 8
55debug = false
56debug-assertions = false
57opt-level = 0
58overflow-checks = false
diff --git a/tests/mspm0/build.rs b/tests/mspm0/build.rs
new file mode 100644
index 000000000..0b58fb9e9
--- /dev/null
+++ b/tests/mspm0/build.rs
@@ -0,0 +1,26 @@
1use std::error::Error;
2use std::path::PathBuf;
3use std::{env, fs};
4
5fn main() -> Result<(), Box<dyn Error>> {
6 let out = PathBuf::from(env::var("OUT_DIR").unwrap());
7
8 #[cfg(feature = "mspm0g3507")]
9 let memory_x = include_bytes!("memory_g3507.x");
10
11 fs::write(out.join("memory.x"), memory_x).unwrap();
12
13 println!("cargo:rustc-link-search={}", out.display());
14 println!("cargo:rerun-if-changed=link_ram.x");
15 // copy main linker script.
16 fs::write(out.join("link_ram.x"), include_bytes!("../link_ram_cortex_m.x")).unwrap();
17
18 println!("cargo:rustc-link-arg-bins=--nmagic");
19 println!("cargo:rustc-link-arg-bins=-Tlink_ram.x");
20 println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
21 println!("cargo:rustc-link-arg-bins=-Tteleprobe.x");
22 // You must tell cargo to link interrupt groups if the rt feature is enabled.
23 println!("cargo:rustc-link-arg-bins=-Tinterrupt_group.x");
24
25 Ok(())
26}
diff --git a/tests/mspm0/memory_g3507.x b/tests/mspm0/memory_g3507.x
new file mode 100644
index 000000000..37e381fbd
--- /dev/null
+++ b/tests/mspm0/memory_g3507.x
@@ -0,0 +1,6 @@
1MEMORY
2{
3 FLASH : ORIGIN = 0x00000000, LENGTH = 128K
4 /* Select non-parity range of SRAM due to SRAM_ERR_01 errata in SLAZ758 */
5 RAM : ORIGIN = 0x20200000, LENGTH = 32K
6}
diff --git a/tests/mspm0/src/bin/uart.rs b/tests/mspm0/src/bin/uart.rs
new file mode 100644
index 000000000..458129d44
--- /dev/null
+++ b/tests/mspm0/src/bin/uart.rs
@@ -0,0 +1,83 @@
1#![no_std]
2#![no_main]
3
4#[cfg(feature = "mspm0g3507")]
5teleprobe_meta::target!(b"lp-mspm0g3507");
6
7use defmt::{assert_eq, unwrap, *};
8use embassy_executor::Spawner;
9use embassy_mspm0::mode::Blocking;
10use embassy_mspm0::uart::{ClockSel, Config, Error, Uart};
11use {defmt_rtt as _, panic_probe as _};
12
13fn read<const N: usize>(uart: &mut Uart<'_, Blocking>) -> Result<[u8; N], Error> {
14 let mut buf = [255; N];
15 uart.blocking_read(&mut buf)?;
16 Ok(buf)
17}
18
19#[embassy_executor::main]
20async fn main(_spawner: Spawner) {
21 let p = embassy_mspm0::init(Default::default());
22 info!("Hello World!");
23
24 // TODO: Allow creating a looped-back UART (so pins are not needed).
25 // Do not select default UART since the virtual COM port is attached to UART0.
26 #[cfg(feature = "mspm0g3507")]
27 let (mut tx, mut rx, mut uart) = (p.PA8, p.PA9, p.UART1);
28
29 const MFCLK_BUAD_RATES: &[u32] = &[1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200];
30
31 for &rate in MFCLK_BUAD_RATES {
32 info!("{} baud using MFCLK", rate);
33
34 let mut config = Config::default();
35 // MSPM0 hardware supports a loopback mode to allow self test.
36 config.loop_back_enable = true;
37 config.baudrate = rate;
38
39 let mut uart = unwrap!(Uart::new_blocking(
40 uart.reborrow(),
41 rx.reborrow(),
42 tx.reborrow(),
43 config
44 ));
45
46 // We can't send too many bytes, they have to fit in the FIFO.
47 // This is because we aren't sending+receiving at the same time.
48
49 let data = [0xC0, 0xDE];
50 unwrap!(uart.blocking_write(&data));
51 assert_eq!(unwrap!(read(&mut uart)), data);
52 }
53
54 // 9600 is the maximum possible value for 32.768 kHz.
55 const LFCLK_BAUD_RATES: &[u32] = &[1200, 2400, 4800, 9600];
56
57 for &rate in LFCLK_BAUD_RATES {
58 info!("{} baud using LFCLK", rate);
59
60 let mut config = Config::default();
61 // MSPM0 hardware supports a loopback mode to allow self test.
62 config.loop_back_enable = true;
63 config.baudrate = rate;
64 config.clock_source = ClockSel::LfClk;
65
66 let mut uart = expect!(Uart::new_blocking(
67 uart.reborrow(),
68 rx.reborrow(),
69 tx.reborrow(),
70 config,
71 ));
72
73 // We can't send too many bytes, they have to fit in the FIFO.
74 // This is because we aren't sending+receiving at the same time.
75
76 let data = [0xC0, 0xDE];
77 unwrap!(uart.blocking_write(&data));
78 assert_eq!(unwrap!(read(&mut uart)), data);
79 }
80
81 info!("Test OK");
82 cortex_m::asm::bkpt();
83}
diff --git a/tests/nrf/Cargo.toml b/tests/nrf/Cargo.toml
index f666634d5..30c4223b7 100644
--- a/tests/nrf/Cargo.toml
+++ b/tests/nrf/Cargo.toml
@@ -8,25 +8,25 @@ license = "MIT OR Apache-2.0"
8teleprobe-meta = "1" 8teleprobe-meta = "1"
9 9
10embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } 10embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
11embassy-sync = { version = "0.6.0", path = "../../embassy-sync", features = ["defmt", ] } 11embassy-sync = { version = "0.7.0", path = "../../embassy-sync", features = ["defmt", ] }
12embassy-executor = { version = "0.6.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "task-arena-size-16384", "integrated-timers"] } 12embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt"] }
13embassy-time = { version = "0.3.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } 13embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
14embassy-nrf = { version = "0.2.0", path = "../../embassy-nrf", features = ["defmt", "time-driver-rtc1", "gpiote", "unstable-pac"] } 14embassy-nrf = { version = "0.3.1", path = "../../embassy-nrf", features = ["defmt", "time-driver-rtc1", "gpiote", "unstable-pac"] }
15embedded-io-async = { version = "0.6.1", features = ["defmt-03"] } 15embedded-io-async = { version = "0.6.1", features = ["defmt-03"] }
16embassy-net = { version = "0.4.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", ] } 16embassy-net = { version = "0.7.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", ] }
17embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-hosted", features = ["defmt"] } 17embassy-net-esp-hosted = { version = "0.2.0", path = "../../embassy-net-esp-hosted", features = ["defmt"] }
18embassy-net-enc28j60 = { version = "0.1.0", path = "../../embassy-net-enc28j60", features = ["defmt"] } 18embassy-net-enc28j60 = { version = "0.2.0", path = "../../embassy-net-enc28j60", features = ["defmt"] }
19embedded-hal-async = { version = "1.0" } 19embedded-hal-async = { version = "1.0" }
20embedded-hal-bus = { version = "0.1", features = ["async"] } 20embedded-hal-bus = { version = "0.1", features = ["async"] }
21static_cell = "2" 21static_cell = "2"
22perf-client = { path = "../perf-client" } 22perf-client = { path = "../perf-client" }
23 23
24defmt = "0.3" 24defmt = "1.0.1"
25defmt-rtt = "0.4" 25defmt-rtt = "1.0.0"
26 26
27cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } 27cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
28cortex-m-rt = "0.7.0" 28cortex-m-rt = "0.7.0"
29panic-probe = { version = "0.3", features = ["print-defmt"] } 29panic-probe = { version = "1.0.0", features = ["print-defmt"] }
30portable-atomic = { version = "1.6.0" } 30portable-atomic = { version = "1.6.0" }
31 31
32[features] 32[features]
@@ -87,6 +87,11 @@ path = "src/bin/gpiote.rs"
87required-features = [] 87required-features = []
88 88
89[[bin]] 89[[bin]]
90name = "spim"
91path = "src/bin/spim.rs"
92required-features = [ "easydma",]
93
94[[bin]]
90name = "timer" 95name = "timer"
91path = "src/bin/timer.rs" 96path = "src/bin/timer.rs"
92required-features = [] 97required-features = []
diff --git a/tests/nrf/src/bin/buffered_uart.rs b/tests/nrf/src/bin/buffered_uart.rs
index 04f32832f..8c4827464 100644
--- a/tests/nrf/src/bin/buffered_uart.rs
+++ b/tests/nrf/src/bin/buffered_uart.rs
@@ -25,14 +25,14 @@ async fn main(_spawner: Spawner) {
25 // test teardown + recreate of the buffereduarte works fine. 25 // test teardown + recreate of the buffereduarte works fine.
26 for _ in 0..2 { 26 for _ in 0..2 {
27 let u = BufferedUarte::new( 27 let u = BufferedUarte::new(
28 &mut peri!(p, UART0), 28 peri!(p, UART0).reborrow(),
29 &mut p.TIMER0, 29 p.TIMER0.reborrow(),
30 &mut p.PPI_CH0, 30 p.PPI_CH0.reborrow(),
31 &mut p.PPI_CH1, 31 p.PPI_CH1.reborrow(),
32 &mut p.PPI_GROUP0, 32 p.PPI_GROUP0.reborrow(),
33 peri!(p, PIN_A).reborrow(),
34 peri!(p, PIN_B).reborrow(),
33 irqs!(UART0_BUFFERED), 35 irqs!(UART0_BUFFERED),
34 &mut peri!(p, PIN_A),
35 &mut peri!(p, PIN_B),
36 config.clone(), 36 config.clone(),
37 &mut rx_buffer, 37 &mut rx_buffer,
38 &mut tx_buffer, 38 &mut tx_buffer,
diff --git a/tests/nrf/src/bin/buffered_uart_full.rs b/tests/nrf/src/bin/buffered_uart_full.rs
index 09353bbe8..e0f41b891 100644
--- a/tests/nrf/src/bin/buffered_uart_full.rs
+++ b/tests/nrf/src/bin/buffered_uart_full.rs
@@ -28,9 +28,9 @@ async fn main(_spawner: Spawner) {
28 p.PPI_CH0, 28 p.PPI_CH0,
29 p.PPI_CH1, 29 p.PPI_CH1,
30 p.PPI_GROUP0, 30 p.PPI_GROUP0,
31 irqs!(UART0_BUFFERED),
32 peri!(p, PIN_A), 31 peri!(p, PIN_A),
33 peri!(p, PIN_B), 32 peri!(p, PIN_B),
33 irqs!(UART0_BUFFERED),
34 config.clone(), 34 config.clone(),
35 &mut rx_buffer, 35 &mut rx_buffer,
36 &mut tx_buffer, 36 &mut tx_buffer,
diff --git a/tests/nrf/src/bin/buffered_uart_halves.rs b/tests/nrf/src/bin/buffered_uart_halves.rs
index bdf5ad726..e6debd76e 100644
--- a/tests/nrf/src/bin/buffered_uart_halves.rs
+++ b/tests/nrf/src/bin/buffered_uart_halves.rs
@@ -27,21 +27,21 @@ async fn main(_spawner: Spawner) {
27 const COUNT: usize = 40_000; 27 const COUNT: usize = 40_000;
28 28
29 let mut tx = BufferedUarteTx::new( 29 let mut tx = BufferedUarteTx::new(
30 &mut peri!(p, UART1), 30 peri!(p, UART1).reborrow(),
31 peri!(p, PIN_A).reborrow(),
31 irqs!(UART1_BUFFERED), 32 irqs!(UART1_BUFFERED),
32 &mut peri!(p, PIN_A),
33 config.clone(), 33 config.clone(),
34 &mut tx_buffer, 34 &mut tx_buffer,
35 ); 35 );
36 36
37 let mut rx = BufferedUarteRx::new( 37 let mut rx = BufferedUarteRx::new(
38 &mut peri!(p, UART0), 38 peri!(p, UART0).reborrow(),
39 &mut p.TIMER0, 39 p.TIMER0.reborrow(),
40 &mut p.PPI_CH0, 40 p.PPI_CH0.reborrow(),
41 &mut p.PPI_CH1, 41 p.PPI_CH1.reborrow(),
42 &mut p.PPI_GROUP0, 42 p.PPI_GROUP0.reborrow(),
43 irqs!(UART0_BUFFERED), 43 irqs!(UART0_BUFFERED),
44 &mut peri!(p, PIN_B), 44 peri!(p, PIN_B).reborrow(),
45 config.clone(), 45 config.clone(),
46 &mut rx_buffer, 46 &mut rx_buffer,
47 ); 47 );
diff --git a/tests/nrf/src/bin/buffered_uart_spam.rs b/tests/nrf/src/bin/buffered_uart_spam.rs
index e8fca452e..24ddd06f3 100644
--- a/tests/nrf/src/bin/buffered_uart_spam.rs
+++ b/tests/nrf/src/bin/buffered_uart_spam.rs
@@ -27,7 +27,11 @@ async fn main(_spawner: Spawner) {
27 27
28 let mut rx_buffer = [0u8; 1024]; 28 let mut rx_buffer = [0u8; 1024];
29 29
30 mem::forget(Output::new(&mut peri!(p, PIN_A), Level::High, OutputDrive::Standard)); 30 mem::forget(Output::new(
31 peri!(p, PIN_A).reborrow(),
32 Level::High,
33 OutputDrive::Standard,
34 ));
31 35
32 let mut u = BufferedUarteRx::new( 36 let mut u = BufferedUarteRx::new(
33 peri!(p, UART0), 37 peri!(p, UART0),
@@ -50,15 +54,15 @@ async fn main(_spawner: Spawner) {
50 const NSPAM: usize = 17; 54 const NSPAM: usize = 17;
51 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];
52 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());
53 let spam_peri: pac::UARTE1 = unsafe { mem::transmute(()) }; 57 let spam_peri = pac::UARTE1;
54 let event = unsafe { Event::new_unchecked(NonNull::new_unchecked(&spam_peri.events_endtx as *const _ as _)) }; 58 let event = unsafe { Event::new_unchecked(NonNull::new_unchecked(spam_peri.events_endtx().as_ptr())) };
55 let task = unsafe { Task::new_unchecked(NonNull::new_unchecked(&spam_peri.tasks_starttx as *const _ as _)) }; 59 let task = unsafe { Task::new_unchecked(NonNull::new_unchecked(spam_peri.tasks_starttx().as_ptr())) };
56 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);
57 spam_ppi.enable(); 61 spam_ppi.enable();
58 let p = unsafe { TX_BUF.as_mut_ptr() }; 62 let p = (&raw mut TX_BUF) as *mut u8;
59 spam_peri.txd.ptr.write(|w| unsafe { w.ptr().bits(p as u32) }); 63 spam_peri.txd().ptr().write_value(p as u32);
60 spam_peri.txd.maxcnt.write(|w| unsafe { w.maxcnt().bits(NSPAM as _) }); 64 spam_peri.txd().maxcnt().write(|w| w.set_maxcnt(NSPAM as _));
61 spam_peri.tasks_starttx.write(|w| unsafe { w.bits(1) }); 65 spam_peri.tasks_starttx().write_value(1);
62 66
63 let mut i = 0; 67 let mut i = 0;
64 let mut total = 0; 68 let mut total = 0;
diff --git a/tests/nrf/src/bin/ethernet_enc28j60_perf.rs b/tests/nrf/src/bin/ethernet_enc28j60_perf.rs
index 304754c0e..ed58627f1 100644
--- a/tests/nrf/src/bin/ethernet_enc28j60_perf.rs
+++ b/tests/nrf/src/bin/ethernet_enc28j60_perf.rs
@@ -6,7 +6,7 @@ teleprobe_meta::timeout!(120);
6 6
7use defmt::{info, unwrap}; 7use defmt::{info, unwrap};
8use embassy_executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_net::{Stack, StackResources}; 9use embassy_net::StackResources;
10use embassy_net_enc28j60::Enc28j60; 10use embassy_net_enc28j60::Enc28j60;
11use embassy_nrf::gpio::{Level, Output, OutputDrive}; 11use embassy_nrf::gpio::{Level, Output, OutputDrive};
12use embassy_nrf::rng::Rng; 12use embassy_nrf::rng::Rng;
@@ -25,8 +25,8 @@ bind_interrupts!(struct Irqs {
25type MyDriver = Enc28j60<ExclusiveDevice<Spim<'static, peripherals::SPI3>, Output<'static>, Delay>, Output<'static>>; 25type MyDriver = Enc28j60<ExclusiveDevice<Spim<'static, peripherals::SPI3>, Output<'static>, Delay>, Output<'static>>;
26 26
27#[embassy_executor::task] 27#[embassy_executor::task]
28async fn net_task(stack: &'static Stack<MyDriver>) -> ! { 28async fn net_task(mut runner: embassy_net::Runner<'static, MyDriver>) -> ! {
29 stack.run().await 29 runner.run().await
30} 30}
31 31
32#[embassy_executor::main] 32#[embassy_executor::main]
@@ -65,11 +65,10 @@ async fn main(spawner: Spawner) {
65 let seed = u64::from_le_bytes(seed); 65 let seed = u64::from_le_bytes(seed);
66 66
67 // Init network stack 67 // Init network stack
68 static STACK: StaticCell<Stack<MyDriver>> = StaticCell::new();
69 static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new(); 68 static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
70 let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed)); 69 let (stack, runner) = embassy_net::new(device, config, RESOURCES.init(StackResources::new()), seed);
71 70
72 unwrap!(spawner.spawn(net_task(stack))); 71 unwrap!(spawner.spawn(net_task(runner)));
73 72
74 perf_client::run( 73 perf_client::run(
75 stack, 74 stack,
diff --git a/tests/nrf/src/bin/gpio.rs b/tests/nrf/src/bin/gpio.rs
index 9e809a694..4995d244c 100644
--- a/tests/nrf/src/bin/gpio.rs
+++ b/tests/nrf/src/bin/gpio.rs
@@ -17,10 +17,12 @@ async fn main(_spawner: Spawner) {
17 let mut output = Output::new(peri!(p, PIN_B), Level::Low, OutputDrive::Standard); 17 let mut output = Output::new(peri!(p, PIN_B), Level::Low, OutputDrive::Standard);
18 18
19 output.set_low(); 19 output.set_low();
20 assert!(output.is_set_low());
20 Timer::after_millis(10).await; 21 Timer::after_millis(10).await;
21 assert!(input.is_low()); 22 assert!(input.is_low());
22 23
23 output.set_high(); 24 output.set_high();
25 assert!(output.is_set_high());
24 Timer::after_millis(10).await; 26 Timer::after_millis(10).await;
25 assert!(input.is_high()); 27 assert!(input.is_high());
26 28
diff --git a/tests/nrf/src/bin/spim.rs b/tests/nrf/src/bin/spim.rs
new file mode 100644
index 000000000..2b38f0409
--- /dev/null
+++ b/tests/nrf/src/bin/spim.rs
@@ -0,0 +1,42 @@
1// required-features: easydma
2#![no_std]
3#![no_main]
4
5#[path = "../common.rs"]
6mod common;
7
8use defmt::{assert_eq, *};
9use embassy_executor::Spawner;
10use embassy_nrf::spim::Spim;
11use embassy_nrf::{peripherals, spim};
12use {defmt_rtt as _, panic_probe as _};
13
14#[embassy_executor::main]
15async fn main(_spawner: Spawner) {
16 let mut p = embassy_nrf::init(Default::default());
17 let mut config = spim::Config::default();
18 config.frequency = spim::Frequency::M1;
19 let mut spim = Spim::new(
20 peri!(p, SPIM0).reborrow(),
21 irqs!(SPIM0),
22 peri!(p, PIN_X).reborrow(),
23 peri!(p, PIN_A).reborrow(), // MISO
24 peri!(p, PIN_B).reborrow(), // MOSI
25 config.clone(),
26 );
27 let data = [
28 0x42, 0x43, 0x44, 0x45, 0x66, 0x12, 0x23, 0x34, 0x45, 0x19, 0x91, 0xaa, 0xff, 0xa5, 0x5a, 0x77,
29 ];
30 let mut buf = [0u8; 16];
31
32 buf.fill(0);
33 spim.blocking_transfer(&mut buf, &data).unwrap();
34 assert_eq!(data, buf);
35
36 buf.fill(0);
37 spim.transfer(&mut buf, &data).await.unwrap();
38 assert_eq!(data, buf);
39
40 info!("Test OK");
41 cortex_m::asm::bkpt();
42}
diff --git a/tests/nrf/src/bin/uart_halves.rs b/tests/nrf/src/bin/uart_halves.rs
index f48ea43a1..a462f80ce 100644
--- a/tests/nrf/src/bin/uart_halves.rs
+++ b/tests/nrf/src/bin/uart_halves.rs
@@ -19,8 +19,18 @@ async fn main(_spawner: Spawner) {
19 config.parity = uarte::Parity::EXCLUDED; 19 config.parity = uarte::Parity::EXCLUDED;
20 config.baudrate = uarte::Baudrate::BAUD1M; 20 config.baudrate = uarte::Baudrate::BAUD1M;
21 21
22 let mut tx = UarteTx::new(&mut peri!(p, UART0), irqs!(UART0), &mut peri!(p, PIN_A), config.clone()); 22 let mut tx = UarteTx::new(
23 let mut rx = UarteRx::new(&mut peri!(p, UART1), irqs!(UART1), &mut peri!(p, PIN_B), config.clone()); 23 peri!(p, UART0).reborrow(),
24 irqs!(UART0),
25 peri!(p, PIN_A).reborrow(),
26 config.clone(),
27 );
28 let mut rx = UarteRx::new(
29 peri!(p, UART1).reborrow(),
30 irqs!(UART1),
31 peri!(p, PIN_B).reborrow(),
32 config.clone(),
33 );
24 34
25 let data = [ 35 let data = [
26 0x42, 0x43, 0x44, 0x45, 0x66, 0x12, 0x23, 0x34, 0x45, 0x19, 0x91, 0xaa, 0xff, 0xa5, 0x5a, 0x77, 36 0x42, 0x43, 0x44, 0x45, 0x66, 0x12, 0x23, 0x34, 0x45, 0x19, 0x91, 0xaa, 0xff, 0xa5, 0x5a, 0x77,
diff --git a/tests/nrf/src/bin/uart_split.rs b/tests/nrf/src/bin/uart_split.rs
index 70d8b2e33..8fe710068 100644
--- a/tests/nrf/src/bin/uart_split.rs
+++ b/tests/nrf/src/bin/uart_split.rs
@@ -21,10 +21,10 @@ async fn main(_spawner: Spawner) {
21 config.baudrate = uarte::Baudrate::BAUD9600; 21 config.baudrate = uarte::Baudrate::BAUD9600;
22 22
23 let uarte = Uarte::new( 23 let uarte = Uarte::new(
24 &mut peri!(p, UART0), 24 peri!(p, UART0).reborrow(),
25 peri!(p, PIN_A).reborrow(),
26 peri!(p, PIN_B).reborrow(),
25 irqs!(UART0), 27 irqs!(UART0),
26 &mut peri!(p, PIN_A),
27 &mut peri!(p, PIN_B),
28 config.clone(), 28 config.clone(),
29 ); 29 );
30 let (mut tx, mut rx) = uarte.split(); 30 let (mut tx, mut rx) = uarte.split();
diff --git a/tests/nrf/src/bin/wifi_esp_hosted_perf.rs b/tests/nrf/src/bin/wifi_esp_hosted_perf.rs
index 6632442f1..34fb8103b 100644
--- a/tests/nrf/src/bin/wifi_esp_hosted_perf.rs
+++ b/tests/nrf/src/bin/wifi_esp_hosted_perf.rs
@@ -6,7 +6,7 @@ teleprobe_meta::timeout!(120);
6 6
7use defmt::{info, unwrap}; 7use defmt::{info, unwrap};
8use embassy_executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_net::{Config, Stack, StackResources}; 9use embassy_net::{Config, StackResources};
10use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; 10use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull};
11use embassy_nrf::rng::Rng; 11use embassy_nrf::rng::Rng;
12use embassy_nrf::spim::{self, Spim}; 12use embassy_nrf::spim::{self, Spim};
@@ -40,8 +40,8 @@ async fn wifi_task(
40type MyDriver = hosted::NetDriver<'static>; 40type MyDriver = hosted::NetDriver<'static>;
41 41
42#[embassy_executor::task] 42#[embassy_executor::task]
43async fn net_task(stack: &'static Stack<MyDriver>) -> ! { 43async fn net_task(mut runner: embassy_net::Runner<'static, MyDriver>) -> ! {
44 stack.run().await 44 runner.run().await
45} 45}
46 46
47#[embassy_executor::main] 47#[embassy_executor::main]
@@ -86,16 +86,15 @@ async fn main(spawner: Spawner) {
86 let seed = u64::from_le_bytes(seed); 86 let seed = u64::from_le_bytes(seed);
87 87
88 // Init network stack 88 // Init network stack
89 static STACK: StaticCell<Stack<MyDriver>> = StaticCell::new();
90 static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new(); 89 static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
91 let stack = &*STACK.init(Stack::new( 90 let (stack, runner) = embassy_net::new(
92 device, 91 device,
93 Config::dhcpv4(Default::default()), 92 Config::dhcpv4(Default::default()),
94 RESOURCES.init(StackResources::new()), 93 RESOURCES.init(StackResources::new()),
95 seed, 94 seed,
96 )); 95 );
97 96
98 unwrap!(spawner.spawn(net_task(stack))); 97 unwrap!(spawner.spawn(net_task(runner)));
99 98
100 perf_client::run( 99 perf_client::run(
101 stack, 100 stack,
diff --git a/tests/nrf/src/common.rs b/tests/nrf/src/common.rs
index ff5299b0f..ebd332d15 100644
--- a/tests/nrf/src/common.rs
+++ b/tests/nrf/src/common.rs
@@ -52,51 +52,66 @@ define_peris!(PIN_A = P0_13, PIN_B = P0_14,);
52#[cfg(feature = "nrf52832")] 52#[cfg(feature = "nrf52832")]
53define_peris!( 53define_peris!(
54 PIN_A = P0_11, PIN_B = P0_12, 54 PIN_A = P0_11, PIN_B = P0_12,
55 PIN_X = P0_13,
55 UART0 = UARTE0, 56 UART0 = UARTE0,
56 @irq UART0 = {UARTE0_UART0 => uarte::InterruptHandler<peripherals::UARTE0>;}, 57 SPIM0 = TWISPI0,
57 @irq UART0_BUFFERED = {UARTE0_UART0 => buffered_uarte::InterruptHandler<peripherals::UARTE0>;}, 58 @irq UART0 = {UARTE0 => uarte::InterruptHandler<peripherals::UARTE0>;},
59 @irq UART0_BUFFERED = {UARTE0 => buffered_uarte::InterruptHandler<peripherals::UARTE0>;},
60 @irq SPIM0 = {TWISPI0 => spim::InterruptHandler<peripherals::TWISPI0>;},
58); 61);
59 62
60#[cfg(feature = "nrf52833")] 63#[cfg(feature = "nrf52833")]
61define_peris!( 64define_peris!(
62 PIN_A = P1_01, PIN_B = P1_02, 65 PIN_A = P1_01, PIN_B = P1_02,
66 PIN_X = P1_03,
63 UART0 = UARTE0, 67 UART0 = UARTE0,
64 UART1 = UARTE1, 68 UART1 = UARTE1,
65 @irq UART0 = {UARTE0_UART0 => uarte::InterruptHandler<peripherals::UARTE0>;}, 69 SPIM0 = TWISPI0,
70 @irq UART0 = {UARTE0 => uarte::InterruptHandler<peripherals::UARTE0>;},
66 @irq UART1 = {UARTE1 => uarte::InterruptHandler<peripherals::UARTE1>;}, 71 @irq UART1 = {UARTE1 => uarte::InterruptHandler<peripherals::UARTE1>;},
67 @irq UART0_BUFFERED = {UARTE0_UART0 => buffered_uarte::InterruptHandler<peripherals::UARTE0>;}, 72 @irq UART0_BUFFERED = {UARTE0 => buffered_uarte::InterruptHandler<peripherals::UARTE0>;},
68 @irq UART1_BUFFERED = {UARTE1 => buffered_uarte::InterruptHandler<peripherals::UARTE1>;}, 73 @irq UART1_BUFFERED = {UARTE1 => buffered_uarte::InterruptHandler<peripherals::UARTE1>;},
74 @irq SPIM0 = {TWISPI0 => spim::InterruptHandler<peripherals::TWISPI0>;},
69); 75);
70 76
71#[cfg(feature = "nrf52840")] 77#[cfg(feature = "nrf52840")]
72define_peris!( 78define_peris!(
73 PIN_A = P1_02, PIN_B = P1_03, 79 PIN_A = P1_02, PIN_B = P1_03,
80 PIN_X = P1_04,
74 UART0 = UARTE0, 81 UART0 = UARTE0,
75 UART1 = UARTE1, 82 UART1 = UARTE1,
76 @irq UART0 = {UARTE0_UART0 => uarte::InterruptHandler<peripherals::UARTE0>;}, 83 SPIM0 = TWISPI0,
84 @irq UART0 = {UARTE0 => uarte::InterruptHandler<peripherals::UARTE0>;},
77 @irq UART1 = {UARTE1 => uarte::InterruptHandler<peripherals::UARTE1>;}, 85 @irq UART1 = {UARTE1 => uarte::InterruptHandler<peripherals::UARTE1>;},
78 @irq UART0_BUFFERED = {UARTE0_UART0 => buffered_uarte::InterruptHandler<peripherals::UARTE0>;}, 86 @irq UART0_BUFFERED = {UARTE0 => buffered_uarte::InterruptHandler<peripherals::UARTE0>;},
79 @irq UART1_BUFFERED = {UARTE1 => buffered_uarte::InterruptHandler<peripherals::UARTE1>;}, 87 @irq UART1_BUFFERED = {UARTE1 => buffered_uarte::InterruptHandler<peripherals::UARTE1>;},
88 @irq SPIM0 = {TWISPI0 => spim::InterruptHandler<peripherals::TWISPI0>;},
80); 89);
81 90
82#[cfg(feature = "nrf5340")] 91#[cfg(feature = "nrf5340")]
83define_peris!( 92define_peris!(
84 PIN_A = P1_08, PIN_B = P1_09, 93 PIN_A = P1_08, PIN_B = P1_09,
94 PIN_X = P1_10,
85 UART0 = SERIAL0, 95 UART0 = SERIAL0,
86 UART1 = SERIAL1, 96 UART1 = SERIAL1,
97 SPIM0 = SERIAL0,
87 @irq UART0 = {SERIAL0 => uarte::InterruptHandler<peripherals::SERIAL0>;}, 98 @irq UART0 = {SERIAL0 => uarte::InterruptHandler<peripherals::SERIAL0>;},
88 @irq UART1 = {SERIAL1 => uarte::InterruptHandler<peripherals::SERIAL1>;}, 99 @irq UART1 = {SERIAL1 => uarte::InterruptHandler<peripherals::SERIAL1>;},
89 @irq UART0_BUFFERED = {SERIAL0 => buffered_uarte::InterruptHandler<peripherals::SERIAL0>;}, 100 @irq UART0_BUFFERED = {SERIAL0 => buffered_uarte::InterruptHandler<peripherals::SERIAL0>;},
90 @irq UART1_BUFFERED = {SERIAL1 => buffered_uarte::InterruptHandler<peripherals::SERIAL1>;}, 101 @irq UART1_BUFFERED = {SERIAL1 => buffered_uarte::InterruptHandler<peripherals::SERIAL1>;},
102 @irq SPIM0 = {SERIAL0 => spim::InterruptHandler<peripherals::SERIAL0>;},
91); 103);
92 104
93#[cfg(feature = "nrf9160")] 105#[cfg(feature = "nrf9160")]
94define_peris!( 106define_peris!(
95 PIN_A = P0_00, PIN_B = P0_01, 107 PIN_A = P0_00, PIN_B = P0_01,
108 PIN_X = P0_02,
96 UART0 = SERIAL0, 109 UART0 = SERIAL0,
97 UART1 = SERIAL1, 110 UART1 = SERIAL1,
98 @irq UART0 = {UARTE0_SPIM0_SPIS0_TWIM0_TWIS0 => uarte::InterruptHandler<peripherals::SERIAL0>;}, 111 SPIM0 = SERIAL0,
99 @irq UART1 = {UARTE1_SPIM1_SPIS1_TWIM1_TWIS1 => uarte::InterruptHandler<peripherals::SERIAL1>;}, 112 @irq UART0 = {SERIAL0 => uarte::InterruptHandler<peripherals::SERIAL0>;},
100 @irq UART0_BUFFERED = {UARTE0_SPIM0_SPIS0_TWIM0_TWIS0 => buffered_uarte::InterruptHandler<peripherals::SERIAL0>;}, 113 @irq UART1 = {SERIAL1 => uarte::InterruptHandler<peripherals::SERIAL1>;},
101 @irq UART1_BUFFERED = {UARTE1_SPIM1_SPIS1_TWIM1_TWIS1 => buffered_uarte::InterruptHandler<peripherals::SERIAL1>;}, 114 @irq UART0_BUFFERED = {SERIAL0 => buffered_uarte::InterruptHandler<peripherals::SERIAL0>;},
115 @irq UART1_BUFFERED = {SERIAL1 => buffered_uarte::InterruptHandler<peripherals::SERIAL1>;},
116 @irq SPIM0 = {SERIAL0 => spim::InterruptHandler<peripherals::SERIAL0>;},
102); 117);
diff --git a/tests/perf-client/Cargo.toml b/tests/perf-client/Cargo.toml
index eb2a33a30..e31d6361b 100644
--- a/tests/perf-client/Cargo.toml
+++ b/tests/perf-client/Cargo.toml
@@ -4,7 +4,7 @@ version = "0.1.0"
4edition = "2021" 4edition = "2021"
5 5
6[dependencies] 6[dependencies]
7embassy-net = { version = "0.4.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4"] } 7embassy-net = { version = "0.7.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4"] }
8embassy-time = { version = "0.3.2", path = "../../embassy-time", features = ["defmt", ] } 8embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt", ] }
9embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } 9embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
10defmt = "0.3.0" 10defmt = "1.0.1"
diff --git a/tests/perf-client/src/lib.rs b/tests/perf-client/src/lib.rs
index 54762379a..4bd9e5674 100644
--- a/tests/perf-client/src/lib.rs
+++ b/tests/perf-client/src/lib.rs
@@ -2,7 +2,6 @@
2 2
3use defmt::{assert, *}; 3use defmt::{assert, *};
4use embassy_futures::join::join; 4use embassy_futures::join::join;
5use embassy_net::driver::Driver;
6use embassy_net::tcp::TcpSocket; 5use embassy_net::tcp::TcpSocket;
7use embassy_net::{Ipv4Address, Stack}; 6use embassy_net::{Ipv4Address, Stack};
8use embassy_time::{with_timeout, Duration, Timer}; 7use embassy_time::{with_timeout, Duration, Timer};
@@ -13,7 +12,7 @@ pub struct Expected {
13 pub updown_kbps: usize, 12 pub updown_kbps: usize,
14} 13}
15 14
16pub async fn run<D: Driver>(stack: &Stack<D>, expected: Expected) { 15pub async fn run(stack: Stack<'_>, expected: Expected) {
17 info!("Waiting for DHCP up..."); 16 info!("Waiting for DHCP up...");
18 while stack.config_v4().is_none() { 17 while stack.config_v4().is_none() {
19 Timer::after_millis(100).await; 18 Timer::after_millis(100).await;
@@ -38,7 +37,7 @@ const DOWNLOAD_PORT: u16 = 4321;
38const UPLOAD_PORT: u16 = 4322; 37const UPLOAD_PORT: u16 = 4322;
39const UPLOAD_DOWNLOAD_PORT: u16 = 4323; 38const UPLOAD_DOWNLOAD_PORT: u16 = 4323;
40 39
41async fn test_download<D: Driver>(stack: &Stack<D>) -> usize { 40async fn test_download(stack: Stack<'_>) -> usize {
42 info!("Testing download..."); 41 info!("Testing download...");
43 42
44 let mut rx_buffer = [0; RX_BUFFER_SIZE]; 43 let mut rx_buffer = [0; RX_BUFFER_SIZE];
@@ -78,7 +77,7 @@ async fn test_download<D: Driver>(stack: &Stack<D>) -> usize {
78 kbps 77 kbps
79} 78}
80 79
81async fn test_upload<D: Driver>(stack: &Stack<D>) -> usize { 80async fn test_upload(stack: Stack<'_>) -> usize {
82 info!("Testing upload..."); 81 info!("Testing upload...");
83 82
84 let mut rx_buffer = [0; RX_BUFFER_SIZE]; 83 let mut rx_buffer = [0; RX_BUFFER_SIZE];
@@ -118,7 +117,7 @@ async fn test_upload<D: Driver>(stack: &Stack<D>) -> usize {
118 kbps 117 kbps
119} 118}
120 119
121async fn test_upload_download<D: Driver>(stack: &Stack<D>) -> usize { 120async fn test_upload_download(stack: Stack<'_>) -> usize {
122 info!("Testing upload+download..."); 121 info!("Testing upload+download...");
123 122
124 let mut rx_buffer = [0; RX_BUFFER_SIZE]; 123 let mut rx_buffer = [0; RX_BUFFER_SIZE];
diff --git a/tests/riscv32/Cargo.toml b/tests/riscv32/Cargo.toml
index ae2b0e180..c5f6a1194 100644
--- a/tests/riscv32/Cargo.toml
+++ b/tests/riscv32/Cargo.toml
@@ -6,9 +6,9 @@ license = "MIT OR Apache-2.0"
6 6
7[dependencies] 7[dependencies]
8critical-section = { version = "1.1.1", features = ["restore-state-bool"] } 8critical-section = { version = "1.1.1", features = ["restore-state-bool"] }
9embassy-sync = { version = "0.6.0", path = "../../embassy-sync" } 9embassy-sync = { version = "0.7.0", path = "../../embassy-sync" }
10embassy-executor = { version = "0.6.0", path = "../../embassy-executor", features = ["arch-riscv32", "executor-thread"] } 10embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-riscv32", "executor-thread"] }
11embassy-time = { version = "0.3.2", path = "../../embassy-time" } 11embassy-time = { version = "0.4.0", path = "../../embassy-time" }
12embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } 12embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
13 13
14riscv-rt = "0.12.2" 14riscv-rt = "0.12.2"
diff --git a/tests/rp/.cargo/config.toml b/tests/rp/.cargo/config.toml
index de7bb0e56..649c15048 100644
--- a/tests/rp/.cargo/config.toml
+++ b/tests/rp/.cargo/config.toml
@@ -5,18 +5,19 @@
5#build-std-features = ["panic_immediate_abort"] 5#build-std-features = ["panic_immediate_abort"]
6 6
7[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 7[target.'cfg(all(target_arch = "arm", target_os = "none"))']
8runner = "teleprobe client run" 8#runner = "teleprobe client run"
9#runner = "teleprobe local run --chip RP2040 --elf" 9#runner = "teleprobe local run --chip RP2040 --elf"
10runner = "teleprobe local run --chip RP235X --elf"
10 11
11rustflags = [ 12rustflags = [
12 # Code-size optimizations. 13 # Code-size optimizations.
13 #"-Z", "trap-unreachable=no", 14 #"-Z", "trap-unreachable=no",
14 "-C", "inline-threshold=5",
15 "-C", "no-vectorize-loops", 15 "-C", "no-vectorize-loops",
16] 16]
17 17
18[build] 18[build]
19target = "thumbv6m-none-eabi" 19#target = "thumbv6m-none-eabi"
20target = "thumbv8m.main-none-eabihf"
20 21
21[env] 22[env]
22DEFMT_LOG = "trace,embassy_hal_internal=debug,embassy_net_esp_hosted=debug,cyw43=info,cyw43_pio=info,smoltcp=info" 23DEFMT_LOG = "trace,embassy_hal_internal=debug,embassy_net_esp_hosted=debug,cyw43=info,cyw43_pio=info,smoltcp=info"
diff --git a/tests/rp/Cargo.toml b/tests/rp/Cargo.toml
index 12f1ec3ce..2be37f525 100644
--- a/tests/rp/Cargo.toml
+++ b/tests/rp/Cargo.toml
@@ -4,23 +4,28 @@ name = "embassy-rp-tests"
4version = "0.1.0" 4version = "0.1.0"
5license = "MIT OR Apache-2.0" 5license = "MIT OR Apache-2.0"
6 6
7[features]
8rp2040 = ["embassy-rp/rp2040"]
9rp235xa = ["embassy-rp/rp235xa"]
10rp235xb = ["embassy-rp/rp235xb"]
11
7[dependencies] 12[dependencies]
8teleprobe-meta = "1.1" 13teleprobe-meta = "1.1"
9 14
10embassy-sync = { version = "0.6.0", path = "../../embassy-sync", features = ["defmt"] } 15embassy-sync = { version = "0.7.0", path = "../../embassy-sync", features = ["defmt"] }
11embassy-executor = { version = "0.6.0", path = "../../embassy-executor", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 16embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt"] }
12embassy-time = { version = "0.3.2", path = "../../embassy-time", features = ["defmt", ] } 17embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt", ] }
13embassy-rp = { version = "0.2.0", path = "../../embassy-rp", features = [ "defmt", "unstable-pac", "time-driver", "critical-section-impl", "intrinsics", "rom-v2-intrinsics", "run-from-ram", "rp2040"] } 18embassy-rp = { version = "0.4.0", path = "../../embassy-rp", features = [ "defmt", "unstable-pac", "time-driver", "critical-section-impl", "intrinsics", "rom-v2-intrinsics", "run-from-ram"] }
14embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } 19embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
15embassy-net = { version = "0.4.0", path = "../../embassy-net", features = ["defmt", "tcp", "udp", "dhcpv4", "medium-ethernet"] } 20embassy-net = { version = "0.7.0", path = "../../embassy-net", features = ["defmt", "tcp", "udp", "dhcpv4", "medium-ethernet"] }
16embassy-net-wiznet = { version = "0.1.0", path = "../../embassy-net-wiznet", features = ["defmt"] } 21embassy-net-wiznet = { version = "0.2.0", path = "../../embassy-net-wiznet", features = ["defmt"] }
17embassy-embedded-hal = { version = "0.2.0", path = "../../embassy-embedded-hal/"} 22embassy-embedded-hal = { version = "0.3.0", path = "../../embassy-embedded-hal/"}
18cyw43 = { path = "../../cyw43", features = ["defmt", "firmware-logs"] } 23cyw43 = { path = "../../cyw43", features = ["defmt", "firmware-logs"] }
19cyw43-pio = { path = "../../cyw43-pio", features = ["defmt", "overclock"] } 24cyw43-pio = { path = "../../cyw43-pio", features = ["defmt"] }
20perf-client = { path = "../perf-client" } 25perf-client = { path = "../perf-client" }
21 26
22defmt = "0.3.0" 27defmt = "1.0.1"
23defmt-rtt = "0.4" 28defmt-rtt = "1.0.0"
24 29
25cortex-m = { version = "0.7.6" } 30cortex-m = { version = "0.7.6" }
26cortex-m-rt = "0.7.0" 31cortex-m-rt = "0.7.0"
@@ -28,14 +33,35 @@ embedded-hal = "0.2.6"
28embedded-hal-1 = { package = "embedded-hal", version = "1.0" } 33embedded-hal-1 = { package = "embedded-hal", version = "1.0" }
29embedded-hal-async = { version = "1.0" } 34embedded-hal-async = { version = "1.0" }
30embedded-hal-bus = { version = "0.1", features = ["async"] } 35embedded-hal-bus = { version = "0.1", features = ["async"] }
31panic-probe = { version = "0.3.0", features = ["print-defmt"] } 36panic-probe = { version = "1.0.0", features = ["print-defmt"] }
32embedded-io-async = { version = "0.6.1" } 37embedded-io-async = { version = "0.6.1" }
33embedded-storage = { version = "0.3" } 38embedded-storage = { version = "0.3" }
34static_cell = "2" 39static_cell = "2"
35portable-atomic = { version = "1.5", features = ["critical-section"] } 40portable-atomic = { version = "1.5", features = ["critical-section"] }
36pio = "0.2" 41
37pio-proc = "0.2" 42# bootsel not currently supported on 2350
38rand = { version = "0.8.5", default-features = false } 43[[bin]]
44name = "bootsel"
45path = "src/bin/bootsel.rs"
46required-features = [ "rp2040",]
47
48# 2350 devboard isn't a W
49[[bin]]
50name = "cyw43-perf"
51path = "src/bin/cyw43-perf.rs"
52required-features = [ "rp2040",]
53
54# Eth test only for the w5100s-evb-pico
55[[bin]]
56name = "ethernet_w5100s_perf"
57path = "src/bin/ethernet_w5100s_perf.rs"
58required-features = [ "rp2040",]
59
60# Float intrinsics are only relevant for the 2040
61[[bin]]
62name = "float"
63path = "src/bin/float.rs"
64required-features = [ "rp2040",]
39 65
40[profile.dev] 66[profile.dev]
41debug = 2 67debug = 2
diff --git a/tests/rp/readme.md b/tests/rp/readme.md
new file mode 100644
index 000000000..f8192a95a
--- /dev/null
+++ b/tests/rp/readme.md
@@ -0,0 +1,8 @@
1# Pico and Pico 2 Plus connections
2
3GP0-GP1
4GP3-GP4
5GP6-GP9
6GP7-GP11
7GP18-GP20 with 10k pullup
8GP19-GP21 with 10k pullup
diff --git a/tests/rp/src/bin/adc.rs b/tests/rp/src/bin/adc.rs
index 65c246472..c2175bc03 100644
--- a/tests/rp/src/bin/adc.rs
+++ b/tests/rp/src/bin/adc.rs
@@ -1,6 +1,9 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3#[cfg(feature = "rp2040")]
3teleprobe_meta::target!(b"rpi-pico"); 4teleprobe_meta::target!(b"rpi-pico");
5#[cfg(feature = "rp235xb")]
6teleprobe_meta::target!(b"pimoroni-pico-plus-2");
4 7
5use defmt::*; 8use defmt::*;
6use embassy_executor::Spawner; 9use embassy_executor::Spawner;
@@ -20,14 +23,19 @@ async fn main(_spawner: Spawner) {
20 let _wifi_off = Output::new(p.PIN_25, Level::High); 23 let _wifi_off = Output::new(p.PIN_25, Level::High);
21 let mut adc = Adc::new(p.ADC, Irqs, Config::default()); 24 let mut adc = Adc::new(p.ADC, Irqs, Config::default());
22 25
26 #[cfg(any(feature = "rp2040", feature = "rp235xa"))]
27 let (mut a, mut b, mut c, mut d) = (p.PIN_26, p.PIN_27, p.PIN_28, p.PIN_29);
28 #[cfg(feature = "rp235xb")]
29 let (mut a, mut b, mut c, mut d) = (p.PIN_44, p.PIN_45, p.PIN_46, p.PIN_47);
30
23 { 31 {
24 { 32 {
25 let mut p = Channel::new_pin(&mut p.PIN_26, Pull::Down); 33 let mut p = Channel::new_pin(a.reborrow(), Pull::Down);
26 defmt::assert!(adc.blocking_read(&mut p).unwrap() < 0b01_0000_0000); 34 defmt::assert!(adc.blocking_read(&mut p).unwrap() < 0b01_0000_0000);
27 defmt::assert!(adc.read(&mut p).await.unwrap() < 0b01_0000_0000); 35 defmt::assert!(adc.read(&mut p).await.unwrap() < 0b01_0000_0000);
28 } 36 }
29 { 37 {
30 let mut p = Channel::new_pin(&mut p.PIN_26, Pull::Up); 38 let mut p = Channel::new_pin(a.reborrow(), Pull::Up);
31 defmt::assert!(adc.blocking_read(&mut p).unwrap() > 0b11_0000_0000); 39 defmt::assert!(adc.blocking_read(&mut p).unwrap() > 0b11_0000_0000);
32 defmt::assert!(adc.read(&mut p).await.unwrap() > 0b11_0000_0000); 40 defmt::assert!(adc.read(&mut p).await.unwrap() > 0b11_0000_0000);
33 } 41 }
@@ -35,21 +43,21 @@ async fn main(_spawner: Spawner) {
35 // not bothering with async reads from now on 43 // not bothering with async reads from now on
36 { 44 {
37 { 45 {
38 let mut p = Channel::new_pin(&mut p.PIN_27, Pull::Down); 46 let mut p = Channel::new_pin(b.reborrow(), Pull::Down);
39 defmt::assert!(adc.blocking_read(&mut p).unwrap() < 0b01_0000_0000); 47 defmt::assert!(adc.blocking_read(&mut p).unwrap() < 0b01_0000_0000);
40 } 48 }
41 { 49 {
42 let mut p = Channel::new_pin(&mut p.PIN_27, Pull::Up); 50 let mut p = Channel::new_pin(b.reborrow(), Pull::Up);
43 defmt::assert!(adc.blocking_read(&mut p).unwrap() > 0b11_0000_0000); 51 defmt::assert!(adc.blocking_read(&mut p).unwrap() > 0b11_0000_0000);
44 } 52 }
45 } 53 }
46 { 54 {
47 { 55 {
48 let mut p = Channel::new_pin(&mut p.PIN_28, Pull::Down); 56 let mut p = Channel::new_pin(c.reborrow(), Pull::Down);
49 defmt::assert!(adc.blocking_read(&mut p).unwrap() < 0b01_0000_0000); 57 defmt::assert!(adc.blocking_read(&mut p).unwrap() < 0b01_0000_0000);
50 } 58 }
51 { 59 {
52 let mut p = Channel::new_pin(&mut p.PIN_28, Pull::Up); 60 let mut p = Channel::new_pin(c.reborrow(), Pull::Up);
53 defmt::assert!(adc.blocking_read(&mut p).unwrap() > 0b11_0000_0000); 61 defmt::assert!(adc.blocking_read(&mut p).unwrap() > 0b11_0000_0000);
54 } 62 }
55 } 63 }
@@ -57,15 +65,15 @@ async fn main(_spawner: Spawner) {
57 // gp29 is connected to vsys through a 200k/100k divider, 65 // gp29 is connected to vsys through a 200k/100k divider,
58 // adding pulls should change the value 66 // adding pulls should change the value
59 let low = { 67 let low = {
60 let mut p = Channel::new_pin(&mut p.PIN_29, Pull::Down); 68 let mut p = Channel::new_pin(d.reborrow(), Pull::Down);
61 adc.blocking_read(&mut p).unwrap() 69 adc.blocking_read(&mut p).unwrap()
62 }; 70 };
63 let none = { 71 let none = {
64 let mut p = Channel::new_pin(&mut p.PIN_29, Pull::None); 72 let mut p = Channel::new_pin(d.reborrow(), Pull::None);
65 adc.blocking_read(&mut p).unwrap() 73 adc.blocking_read(&mut p).unwrap()
66 }; 74 };
67 let up = { 75 let up = {
68 let mut p = Channel::new_pin(&mut p.PIN_29, Pull::Up); 76 let mut p = Channel::new_pin(d.reborrow(), Pull::Up);
69 adc.blocking_read(&mut p).unwrap() 77 adc.blocking_read(&mut p).unwrap()
70 }; 78 };
71 defmt::assert!(low < none); 79 defmt::assert!(low < none);
@@ -73,7 +81,7 @@ async fn main(_spawner: Spawner) {
73 } 81 }
74 { 82 {
75 let temp = convert_to_celsius( 83 let temp = convert_to_celsius(
76 adc.read(&mut Channel::new_temp_sensor(&mut p.ADC_TEMP_SENSOR)) 84 adc.read(&mut Channel::new_temp_sensor(p.ADC_TEMP_SENSOR.reborrow()))
77 .await 85 .await
78 .unwrap(), 86 .unwrap(),
79 ); 87 );
@@ -90,26 +98,26 @@ async fn main(_spawner: Spawner) {
90 let mut none = [0u8; 16]; 98 let mut none = [0u8; 16];
91 let mut up = [Sample::default(); 16]; 99 let mut up = [Sample::default(); 16];
92 adc.read_many( 100 adc.read_many(
93 &mut Channel::new_pin(&mut p.PIN_29, Pull::Down), 101 &mut Channel::new_pin(d.reborrow(), Pull::Down),
94 &mut low, 102 &mut low,
95 1, 103 1,
96 &mut p.DMA_CH0, 104 p.DMA_CH0.reborrow(),
97 ) 105 )
98 .await 106 .await
99 .unwrap(); 107 .unwrap();
100 adc.read_many( 108 adc.read_many(
101 &mut Channel::new_pin(&mut p.PIN_29, Pull::None), 109 &mut Channel::new_pin(d.reborrow(), Pull::None),
102 &mut none, 110 &mut none,
103 1, 111 1,
104 &mut p.DMA_CH0, 112 p.DMA_CH0.reborrow(),
105 ) 113 )
106 .await 114 .await
107 .unwrap(); 115 .unwrap();
108 adc.read_many_raw( 116 adc.read_many_raw(
109 &mut Channel::new_pin(&mut p.PIN_29, Pull::Up), 117 &mut Channel::new_pin(d.reborrow(), Pull::Up),
110 &mut up, 118 &mut up,
111 1, 119 1,
112 &mut p.DMA_CH0, 120 p.DMA_CH0.reborrow(),
113 ) 121 )
114 .await; 122 .await;
115 defmt::assert!(low.iter().zip(none.iter()).all(|(l, n)| *l >> 4 < *n as u16)); 123 defmt::assert!(low.iter().zip(none.iter()).all(|(l, n)| *l >> 4 < *n as u16));
@@ -119,10 +127,10 @@ async fn main(_spawner: Spawner) {
119 { 127 {
120 let mut temp = [0u16; 16]; 128 let mut temp = [0u16; 16];
121 adc.read_many( 129 adc.read_many(
122 &mut Channel::new_temp_sensor(&mut p.ADC_TEMP_SENSOR), 130 &mut Channel::new_temp_sensor(p.ADC_TEMP_SENSOR.reborrow()),
123 &mut temp, 131 &mut temp,
124 1, 132 1,
125 &mut p.DMA_CH0, 133 p.DMA_CH0.reborrow(),
126 ) 134 )
127 .await 135 .await
128 .unwrap(); 136 .unwrap();
@@ -133,10 +141,10 @@ async fn main(_spawner: Spawner) {
133 { 141 {
134 let mut multi = [0u16; 2]; 142 let mut multi = [0u16; 2];
135 let mut channels = [ 143 let mut channels = [
136 Channel::new_pin(&mut p.PIN_26, Pull::Up), 144 Channel::new_pin(a.reborrow(), Pull::Up),
137 Channel::new_temp_sensor(&mut p.ADC_TEMP_SENSOR), 145 Channel::new_temp_sensor(p.ADC_TEMP_SENSOR.reborrow()),
138 ]; 146 ];
139 adc.read_many_multichannel(&mut channels, &mut multi, 1, &mut p.DMA_CH0) 147 adc.read_many_multichannel(&mut channels, &mut multi, 1, p.DMA_CH0.reborrow())
140 .await 148 .await
141 .unwrap(); 149 .unwrap();
142 defmt::assert!(multi[0] > 3_000); 150 defmt::assert!(multi[0] > 3_000);
diff --git a/tests/rp/src/bin/bootsel.rs b/tests/rp/src/bin/bootsel.rs
index e88d8bf6c..aa123ab03 100644
--- a/tests/rp/src/bin/bootsel.rs
+++ b/tests/rp/src/bin/bootsel.rs
@@ -4,12 +4,13 @@ teleprobe_meta::target!(b"rpi-pico");
4 4
5use defmt::{assert_eq, *}; 5use defmt::{assert_eq, *};
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_rp::bootsel::is_bootsel_pressed;
7use embassy_time::Timer; 8use embassy_time::Timer;
8use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
9 10
10#[embassy_executor::main] 11#[embassy_executor::main]
11async fn main(_spawner: Spawner) { 12async fn main(_spawner: Spawner) {
12 let mut p = embassy_rp::init(Default::default()); 13 let p = embassy_rp::init(Default::default());
13 info!("Hello World!"); 14 info!("Hello World!");
14 15
15 // add some delay to give an attached debug probe time to parse the 16 // add some delay to give an attached debug probe time to parse the
@@ -18,7 +19,7 @@ async fn main(_spawner: Spawner) {
18 // https://github.com/knurling-rs/defmt/pull/683 19 // https://github.com/knurling-rs/defmt/pull/683
19 Timer::after_millis(10).await; 20 Timer::after_millis(10).await;
20 21
21 assert_eq!(p.BOOTSEL.is_pressed(), false); 22 assert_eq!(is_bootsel_pressed(p.BOOTSEL), false);
22 23
23 info!("Test OK"); 24 info!("Test OK");
24 cortex_m::asm::bkpt(); 25 cortex_m::asm::bkpt();
diff --git a/tests/rp/src/bin/cyw43-perf.rs b/tests/rp/src/bin/cyw43-perf.rs
index 38fbde7c1..dba1058a8 100644
--- a/tests/rp/src/bin/cyw43-perf.rs
+++ b/tests/rp/src/bin/cyw43-perf.rs
@@ -2,10 +2,11 @@
2#![no_main] 2#![no_main]
3teleprobe_meta::target!(b"rpi-pico"); 3teleprobe_meta::target!(b"rpi-pico");
4 4
5use cyw43_pio::PioSpi; 5use cyw43::JoinOptions;
6use cyw43_pio::{PioSpi, DEFAULT_CLOCK_DIVIDER};
6use defmt::{panic, *}; 7use defmt::{panic, *};
7use embassy_executor::Spawner; 8use embassy_executor::Spawner;
8use embassy_net::{Config, Stack, StackResources}; 9use embassy_net::{Config, StackResources};
9use embassy_rp::gpio::{Level, Output}; 10use embassy_rp::gpio::{Level, Output};
10use embassy_rp::peripherals::{DMA_CH0, PIO0}; 11use embassy_rp::peripherals::{DMA_CH0, PIO0};
11use embassy_rp::pio::{InterruptHandler, Pio}; 12use embassy_rp::pio::{InterruptHandler, Pio};
@@ -20,7 +21,7 @@ bind_interrupts!(struct Irqs {
20teleprobe_meta::timeout!(120); 21teleprobe_meta::timeout!(120);
21 22
22// Test-only wifi network, no internet access! 23// Test-only wifi network, no internet access!
23const WIFI_NETWORK: &str = "EmbassyTest"; 24const WIFI_NETWORK: &str = "EmbassyTestWPA2";
24const WIFI_PASSWORD: &str = "V8YxhKt5CdIAJFud"; 25const WIFI_PASSWORD: &str = "V8YxhKt5CdIAJFud";
25 26
26#[embassy_executor::task] 27#[embassy_executor::task]
@@ -29,8 +30,8 @@ async fn wifi_task(runner: cyw43::Runner<'static, Output<'static>, PioSpi<'stati
29} 30}
30 31
31#[embassy_executor::task] 32#[embassy_executor::task]
32async fn net_task(stack: &'static Stack<cyw43::NetDriver<'static>>) -> ! { 33async fn net_task(mut runner: embassy_net::Runner<'static, cyw43::NetDriver<'static>>) -> ! {
33 stack.run().await 34 runner.run().await
34} 35}
35 36
36#[embassy_executor::main] 37#[embassy_executor::main]
@@ -46,14 +47,25 @@ async fn main(spawner: Spawner) {
46 47
47 // cyw43 firmware needs to be flashed manually: 48 // cyw43 firmware needs to be flashed manually:
48 // probe-rs download 43439A0.bin --binary-format bin --chip RP2040 --base-address 0x101b0000 49 // probe-rs download 43439A0.bin --binary-format bin --chip RP2040 --base-address 0x101b0000
50 // probe-rs download 43439A0_btfw.bin --binary-format bin --chip RP2040 --base-address 0x101f0000
49 // probe-rs download 43439A0_clm.bin --binary-format bin --chip RP2040 --base-address 0x101f8000 51 // probe-rs download 43439A0_clm.bin --binary-format bin --chip RP2040 --base-address 0x101f8000
50 let fw = unsafe { core::slice::from_raw_parts(0x101b0000 as *const u8, 230321) }; 52 let fw = unsafe { core::slice::from_raw_parts(0x101b0000 as *const u8, 231077) };
51 let clm = unsafe { core::slice::from_raw_parts(0x101f8000 as *const u8, 4752) }; 53 let _btfw = unsafe { core::slice::from_raw_parts(0x101f0000 as *const u8, 6164) };
54 let clm = unsafe { core::slice::from_raw_parts(0x101f8000 as *const u8, 984) };
52 55
53 let pwr = Output::new(p.PIN_23, Level::Low); 56 let pwr = Output::new(p.PIN_23, Level::Low);
54 let cs = Output::new(p.PIN_25, Level::High); 57 let cs = Output::new(p.PIN_25, Level::High);
55 let mut pio = Pio::new(p.PIO0, Irqs); 58 let mut pio = Pio::new(p.PIO0, Irqs);
56 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(
60 &mut pio.common,
61 pio.sm0,
62 DEFAULT_CLOCK_DIVIDER,
63 pio.irq0,
64 cs,
65 p.PIN_24,
66 p.PIN_29,
67 p.DMA_CH0,
68 );
57 69
58 static STATE: StaticCell<cyw43::State> = StaticCell::new(); 70 static STATE: StaticCell<cyw43::State> = StaticCell::new();
59 let state = STATE.init(cyw43::State::new()); 71 let state = STATE.init(cyw43::State::new());
@@ -69,19 +81,21 @@ async fn main(spawner: Spawner) {
69 let seed = 0x0123_4567_89ab_cdef; // chosen by fair dice roll. guarenteed to be random. 81 let seed = 0x0123_4567_89ab_cdef; // chosen by fair dice roll. guarenteed to be random.
70 82
71 // Init network stack 83 // Init network stack
72 static STACK: StaticCell<Stack<cyw43::NetDriver<'static>>> = StaticCell::new();
73 static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new(); 84 static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
74 let stack = &*STACK.init(Stack::new( 85 let (stack, runner) = embassy_net::new(
75 net_device, 86 net_device,
76 Config::dhcpv4(Default::default()), 87 Config::dhcpv4(Default::default()),
77 RESOURCES.init(StackResources::new()), 88 RESOURCES.init(StackResources::new()),
78 seed, 89 seed,
79 )); 90 );
80 91
81 unwrap!(spawner.spawn(net_task(stack))); 92 unwrap!(spawner.spawn(net_task(runner)));
82 93
83 loop { 94 loop {
84 match control.join_wpa2(WIFI_NETWORK, WIFI_PASSWORD).await { 95 match control
96 .join(WIFI_NETWORK, JoinOptions::new(WIFI_PASSWORD.as_bytes()))
97 .await
98 {
85 Ok(_) => break, 99 Ok(_) => break,
86 Err(err) => { 100 Err(err) => {
87 panic!("join failed with status={}", err.status); 101 panic!("join failed with status={}", err.status);
@@ -92,9 +106,9 @@ async fn main(spawner: Spawner) {
92 perf_client::run( 106 perf_client::run(
93 stack, 107 stack,
94 perf_client::Expected { 108 perf_client::Expected {
95 down_kbps: 300, 109 down_kbps: 200,
96 up_kbps: 300, 110 up_kbps: 200,
97 updown_kbps: 300, 111 updown_kbps: 200,
98 }, 112 },
99 ) 113 )
100 .await; 114 .await;
diff --git a/tests/rp/src/bin/dma_copy_async.rs b/tests/rp/src/bin/dma_copy_async.rs
index 7c64bc396..3dcf4f4d8 100644
--- a/tests/rp/src/bin/dma_copy_async.rs
+++ b/tests/rp/src/bin/dma_copy_async.rs
@@ -1,6 +1,9 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3#[cfg(feature = "rp2040")]
3teleprobe_meta::target!(b"rpi-pico"); 4teleprobe_meta::target!(b"rpi-pico");
5#[cfg(feature = "rp235xb")]
6teleprobe_meta::target!(b"pimoroni-pico-plus-2");
4 7
5use defmt::{assert_eq, *}; 8use defmt::{assert_eq, *};
6use embassy_executor::Spawner; 9use embassy_executor::Spawner;
diff --git a/tests/rp/src/bin/ethernet_w5100s_perf.rs b/tests/rp/src/bin/ethernet_w5100s_perf.rs
index f15f33743..89e0ad32e 100644
--- a/tests/rp/src/bin/ethernet_w5100s_perf.rs
+++ b/tests/rp/src/bin/ethernet_w5100s_perf.rs
@@ -5,7 +5,7 @@ teleprobe_meta::timeout!(120);
5 5
6use defmt::*; 6use defmt::*;
7use embassy_executor::Spawner; 7use embassy_executor::Spawner;
8use embassy_net::{Stack, StackResources}; 8use embassy_net::StackResources;
9use embassy_net_wiznet::chip::W5100S; 9use embassy_net_wiznet::chip::W5100S;
10use embassy_net_wiznet::*; 10use embassy_net_wiznet::*;
11use embassy_rp::clocks::RoscRng; 11use embassy_rp::clocks::RoscRng;
@@ -14,7 +14,6 @@ use embassy_rp::peripherals::SPI0;
14use embassy_rp::spi::{Async, Config as SpiConfig, Spi}; 14use embassy_rp::spi::{Async, Config as SpiConfig, Spi};
15use embassy_time::Delay; 15use embassy_time::Delay;
16use embedded_hal_bus::spi::ExclusiveDevice; 16use embedded_hal_bus::spi::ExclusiveDevice;
17use rand::RngCore;
18use static_cell::StaticCell; 17use static_cell::StaticCell;
19use {defmt_rtt as _, panic_probe as _}; 18use {defmt_rtt as _, panic_probe as _};
20 19
@@ -32,8 +31,8 @@ async fn ethernet_task(
32} 31}
33 32
34#[embassy_executor::task] 33#[embassy_executor::task]
35async fn net_task(stack: &'static Stack<Device<'static>>) -> ! { 34async fn net_task(mut runner: embassy_net::Runner<'static, Device<'static>>) -> ! {
36 stack.run().await 35 runner.run().await
37} 36}
38 37
39#[embassy_executor::main] 38#[embassy_executor::main]
@@ -67,17 +66,16 @@ async fn main(spawner: Spawner) {
67 let seed = rng.next_u64(); 66 let seed = rng.next_u64();
68 67
69 // Init network stack 68 // Init network stack
70 static STACK: StaticCell<Stack<Device<'static>>> = StaticCell::new();
71 static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new(); 69 static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
72 let stack = &*STACK.init(Stack::new( 70 let (stack, runner) = embassy_net::new(
73 device, 71 device,
74 embassy_net::Config::dhcpv4(Default::default()), 72 embassy_net::Config::dhcpv4(Default::default()),
75 RESOURCES.init(StackResources::new()), 73 RESOURCES.init(StackResources::new()),
76 seed, 74 seed,
77 )); 75 );
78 76
79 // Launch network task 77 // Launch network task
80 unwrap!(spawner.spawn(net_task(&stack))); 78 unwrap!(spawner.spawn(net_task(runner)));
81 79
82 perf_client::run( 80 perf_client::run(
83 stack, 81 stack,
diff --git a/tests/rp/src/bin/flash.rs b/tests/rp/src/bin/flash.rs
index 310f0d586..548a6ee72 100644
--- a/tests/rp/src/bin/flash.rs
+++ b/tests/rp/src/bin/flash.rs
@@ -1,6 +1,9 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3#[cfg(feature = "rp2040")]
3teleprobe_meta::target!(b"rpi-pico"); 4teleprobe_meta::target!(b"rpi-pico");
5#[cfg(feature = "rp235xb")]
6teleprobe_meta::target!(b"pimoroni-pico-plus-2");
4 7
5use defmt::*; 8use defmt::*;
6use embassy_executor::Spawner; 9use embassy_executor::Spawner;
@@ -24,13 +27,19 @@ async fn main(_spawner: Spawner) {
24 let mut flash = embassy_rp::flash::Flash::<_, Async, { 2 * 1024 * 1024 }>::new(p.FLASH, p.DMA_CH0); 27 let mut flash = embassy_rp::flash::Flash::<_, Async, { 2 * 1024 * 1024 }>::new(p.FLASH, p.DMA_CH0);
25 28
26 // Get JEDEC id 29 // Get JEDEC id
27 let jedec = defmt::unwrap!(flash.blocking_jedec_id()); 30 #[cfg(feature = "rp2040")]
28 info!("jedec id: 0x{:x}", jedec); 31 {
32 let jedec = defmt::unwrap!(flash.blocking_jedec_id());
33 info!("jedec id: 0x{:x}", jedec);
34 }
29 35
30 // Get unique id 36 // Get unique id
31 let mut uid = [0; 8]; 37 #[cfg(feature = "rp2040")]
32 defmt::unwrap!(flash.blocking_unique_id(&mut uid)); 38 {
33 info!("unique id: {:?}", uid); 39 let mut uid = [0; 8];
40 defmt::unwrap!(flash.blocking_unique_id(&mut uid));
41 info!("unique id: {:?}", uid);
42 }
34 43
35 let mut buf = [0u8; ERASE_SIZE]; 44 let mut buf = [0u8; ERASE_SIZE];
36 defmt::unwrap!(flash.blocking_read(ADDR_OFFSET, &mut buf)); 45 defmt::unwrap!(flash.blocking_read(ADDR_OFFSET, &mut buf));
diff --git a/tests/rp/src/bin/gpio.rs b/tests/rp/src/bin/gpio.rs
index e0c309887..8bd0df8d8 100644
--- a/tests/rp/src/bin/gpio.rs
+++ b/tests/rp/src/bin/gpio.rs
@@ -1,10 +1,15 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3#[cfg(feature = "rp2040")]
3teleprobe_meta::target!(b"rpi-pico"); 4teleprobe_meta::target!(b"rpi-pico");
5#[cfg(feature = "rp235xb")]
6teleprobe_meta::target!(b"pimoroni-pico-plus-2");
4 7
5use defmt::{assert, *}; 8use defmt::{assert, *};
6use embassy_executor::Spawner; 9use embassy_executor::Spawner;
7use embassy_rp::gpio::{Flex, Input, Level, Output, OutputOpenDrain, Pull}; 10#[cfg(feature = "rp2040")]
11use embassy_rp::gpio::OutputOpenDrain;
12use embassy_rp::gpio::{Flex, Input, Level, Output, Pull};
8use {defmt_rtt as _, panic_probe as _}; 13use {defmt_rtt as _, panic_probe as _};
9 14
10#[embassy_executor::main] 15#[embassy_executor::main]
@@ -16,10 +21,10 @@ async fn main(_spawner: Spawner) {
16 21
17 // Test initial output 22 // Test initial output
18 { 23 {
19 let b = Input::new(&mut b, Pull::None); 24 let b = Input::new(b.reborrow(), Pull::None);
20 25
21 { 26 {
22 let a = Output::new(&mut a, Level::Low); 27 let a = Output::new(a.reborrow(), Level::Low);
23 delay(); 28 delay();
24 assert!(b.is_low()); 29 assert!(b.is_low());
25 assert!(!b.is_high()); 30 assert!(!b.is_high());
@@ -27,7 +32,7 @@ async fn main(_spawner: Spawner) {
27 assert!(!a.is_set_high()); 32 assert!(!a.is_set_high());
28 } 33 }
29 { 34 {
30 let mut a = Output::new(&mut a, Level::High); 35 let mut a = Output::new(a.reborrow(), Level::High);
31 delay(); 36 delay();
32 assert!(!b.is_low()); 37 assert!(!b.is_low());
33 assert!(b.is_high()); 38 assert!(b.is_high());
@@ -62,12 +67,46 @@ async fn main(_spawner: Spawner) {
62 } 67 }
63 } 68 }
64 69
70 // Test input inversion
71 {
72 let mut b = Input::new(b.reborrow(), Pull::None);
73 b.set_inversion(true);
74 // no pull, the status is undefined
75
76 let mut a = Output::new(a.reborrow(), Level::Low);
77 delay();
78 assert!(b.is_high());
79 a.set_high();
80 delay();
81 assert!(b.is_low());
82
83 b.set_inversion(false);
84 a.set_inversion(true);
85
86 a.set_low();
87 delay();
88 assert!(b.is_high());
89
90 a.set_high();
91 delay();
92 assert!(b.is_low());
93
94 b.set_inversion(true);
95 a.set_high();
96 delay();
97 assert!(b.is_high());
98
99 a.set_high();
100 delay();
101 assert!(b.is_high());
102 }
103
65 // Test input no pull 104 // Test input no pull
66 { 105 {
67 let b = Input::new(&mut b, Pull::None); 106 let b = Input::new(b.reborrow(), Pull::None);
68 // no pull, the status is undefined 107 // no pull, the status is undefined
69 108
70 let mut a = Output::new(&mut a, Level::Low); 109 let mut a = Output::new(a.reborrow(), Level::Low);
71 delay(); 110 delay();
72 assert!(b.is_low()); 111 assert!(b.is_low());
73 a.set_high(); 112 a.set_high();
@@ -76,12 +115,13 @@ async fn main(_spawner: Spawner) {
76 } 115 }
77 116
78 // Test input pulldown 117 // Test input pulldown
118 #[cfg(feature = "rp2040")]
79 { 119 {
80 let b = Input::new(&mut b, Pull::Down); 120 let b = Input::new(b.reborrow(), Pull::Down);
81 delay(); 121 delay();
82 assert!(b.is_low()); 122 assert!(b.is_low());
83 123
84 let mut a = Output::new(&mut a, Level::Low); 124 let mut a = Output::new(a.reborrow(), Level::Low);
85 delay(); 125 delay();
86 assert!(b.is_low()); 126 assert!(b.is_low());
87 a.set_high(); 127 a.set_high();
@@ -91,11 +131,11 @@ async fn main(_spawner: Spawner) {
91 131
92 // Test input pullup 132 // Test input pullup
93 { 133 {
94 let b = Input::new(&mut b, Pull::Up); 134 let b = Input::new(b.reborrow(), Pull::Up);
95 delay(); 135 delay();
96 assert!(b.is_high()); 136 assert!(b.is_high());
97 137
98 let mut a = Output::new(&mut a, Level::Low); 138 let mut a = Output::new(a.reborrow(), Level::Low);
99 delay(); 139 delay();
100 assert!(b.is_low()); 140 assert!(b.is_low());
101 a.set_high(); 141 a.set_high();
@@ -104,9 +144,10 @@ async fn main(_spawner: Spawner) {
104 } 144 }
105 145
106 // OUTPUT OPEN DRAIN 146 // OUTPUT OPEN DRAIN
147 #[cfg(feature = "rp2040")]
107 { 148 {
108 let mut b = OutputOpenDrain::new(&mut b, Level::High); 149 let mut b = OutputOpenDrain::new(b.reborrow(), Level::High);
109 let mut a = Flex::new(&mut a); 150 let mut a = Flex::new(a.reborrow());
110 a.set_as_input(); 151 a.set_as_input();
111 152
112 // When an OutputOpenDrain is high, it doesn't drive the pin. 153 // When an OutputOpenDrain is high, it doesn't drive the pin.
@@ -163,12 +204,12 @@ async fn main(_spawner: Spawner) {
163 // Test initial output 204 // Test initial output
164 { 205 {
165 //Flex pin configured as input 206 //Flex pin configured as input
166 let mut b = Flex::new(&mut b); 207 let mut b = Flex::new(b.reborrow());
167 b.set_as_input(); 208 b.set_as_input();
168 209
169 { 210 {
170 //Flex pin configured as output 211 //Flex pin configured as output
171 let mut a = Flex::new(&mut a); //Flex pin configured as output 212 let mut a = Flex::new(a.reborrow()); //Flex pin configured as output
172 a.set_low(); // Pin state must be set before configuring the pin, thus we avoid unknown state 213 a.set_low(); // Pin state must be set before configuring the pin, thus we avoid unknown state
173 a.set_as_output(); 214 a.set_as_output();
174 delay(); 215 delay();
@@ -176,7 +217,7 @@ async fn main(_spawner: Spawner) {
176 } 217 }
177 { 218 {
178 //Flex pin configured as output 219 //Flex pin configured as output
179 let mut a = Flex::new(&mut a); 220 let mut a = Flex::new(a.reborrow());
180 a.set_high(); 221 a.set_high();
181 a.set_as_output(); 222 a.set_as_output();
182 223
@@ -187,10 +228,10 @@ async fn main(_spawner: Spawner) {
187 228
188 // Test input no pull 229 // Test input no pull
189 { 230 {
190 let mut b = Flex::new(&mut b); 231 let mut b = Flex::new(b.reborrow());
191 b.set_as_input(); // no pull by default. 232 b.set_as_input(); // no pull by default.
192 233
193 let mut a = Flex::new(&mut a); 234 let mut a = Flex::new(a.reborrow());
194 a.set_low(); 235 a.set_low();
195 a.set_as_output(); 236 a.set_as_output();
196 237
@@ -202,14 +243,15 @@ async fn main(_spawner: Spawner) {
202 } 243 }
203 244
204 // Test input pulldown 245 // Test input pulldown
246 #[cfg(feature = "rp2040")]
205 { 247 {
206 let mut b = Flex::new(&mut b); 248 let mut b = Flex::new(b.reborrow());
207 b.set_as_input(); 249 b.set_as_input();
208 b.set_pull(Pull::Down); 250 b.set_pull(Pull::Down);
209 delay(); 251 delay();
210 assert!(b.is_low()); 252 assert!(b.is_low());
211 253
212 let mut a = Flex::new(&mut a); 254 let mut a = Flex::new(a.reborrow());
213 a.set_low(); 255 a.set_low();
214 a.set_as_output(); 256 a.set_as_output();
215 delay(); 257 delay();
@@ -221,13 +263,13 @@ async fn main(_spawner: Spawner) {
221 263
222 // Test input pullup 264 // Test input pullup
223 { 265 {
224 let mut b = Flex::new(&mut b); 266 let mut b = Flex::new(b.reborrow());
225 b.set_as_input(); 267 b.set_as_input();
226 b.set_pull(Pull::Up); 268 b.set_pull(Pull::Up);
227 delay(); 269 delay();
228 assert!(b.is_high()); 270 assert!(b.is_high());
229 271
230 let mut a = Flex::new(&mut a); 272 let mut a = Flex::new(a.reborrow());
231 a.set_high(); 273 a.set_high();
232 a.set_as_output(); 274 a.set_as_output();
233 delay(); 275 delay();
diff --git a/tests/rp/src/bin/gpio_async.rs b/tests/rp/src/bin/gpio_async.rs
index 40a304464..72fb0910d 100644
--- a/tests/rp/src/bin/gpio_async.rs
+++ b/tests/rp/src/bin/gpio_async.rs
@@ -1,6 +1,9 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3#[cfg(feature = "rp2040")]
3teleprobe_meta::target!(b"rpi-pico"); 4teleprobe_meta::target!(b"rpi-pico");
5#[cfg(feature = "rp235xb")]
6teleprobe_meta::target!(b"pimoroni-pico-plus-2");
4 7
5use defmt::{assert, *}; 8use defmt::{assert, *};
6use embassy_executor::Spawner; 9use embassy_executor::Spawner;
@@ -19,8 +22,8 @@ async fn main(_spawner: Spawner) {
19 22
20 { 23 {
21 info!("test wait_for_high"); 24 info!("test wait_for_high");
22 let mut output = Output::new(&mut output_pin, Level::Low); 25 let mut output = Output::new(output_pin.reborrow(), Level::Low);
23 let mut input = Input::new(&mut input_pin, Pull::None); 26 let mut input = Input::new(input_pin.reborrow(), Pull::None);
24 27
25 assert!(input.is_low(), "input was expected to be low"); 28 assert!(input.is_low(), "input was expected to be low");
26 29
@@ -40,8 +43,8 @@ async fn main(_spawner: Spawner) {
40 43
41 { 44 {
42 info!("test wait_for_low"); 45 info!("test wait_for_low");
43 let mut output = Output::new(&mut output_pin, Level::High); 46 let mut output = Output::new(output_pin.reborrow(), Level::High);
44 let mut input = Input::new(&mut input_pin, Pull::None); 47 let mut input = Input::new(input_pin.reborrow(), Pull::None);
45 48
46 assert!(input.is_high(), "input was expected to be high"); 49 assert!(input.is_high(), "input was expected to be high");
47 50
@@ -60,8 +63,8 @@ async fn main(_spawner: Spawner) {
60 63
61 { 64 {
62 info!("test wait_for_rising_edge"); 65 info!("test wait_for_rising_edge");
63 let mut output = Output::new(&mut output_pin, Level::Low); 66 let mut output = Output::new(output_pin.reborrow(), Level::Low);
64 let mut input = Input::new(&mut input_pin, Pull::None); 67 let mut input = Input::new(input_pin.reborrow(), Pull::None);
65 68
66 assert!(input.is_low(), "input was expected to be low"); 69 assert!(input.is_low(), "input was expected to be low");
67 70
@@ -80,8 +83,8 @@ async fn main(_spawner: Spawner) {
80 83
81 { 84 {
82 info!("test wait_for_falling_edge"); 85 info!("test wait_for_falling_edge");
83 let mut output = Output::new(&mut output_pin, Level::High); 86 let mut output = Output::new(output_pin.reborrow(), Level::High);
84 let mut input = Input::new(&mut input_pin, Pull::None); 87 let mut input = Input::new(input_pin.reborrow(), Pull::None);
85 88
86 assert!(input.is_high(), "input was expected to be high"); 89 assert!(input.is_high(), "input was expected to be high");
87 90
@@ -100,8 +103,8 @@ async fn main(_spawner: Spawner) {
100 103
101 { 104 {
102 info!("test wait_for_any_edge (falling)"); 105 info!("test wait_for_any_edge (falling)");
103 let mut output = Output::new(&mut output_pin, Level::High); 106 let mut output = Output::new(output_pin.reborrow(), Level::High);
104 let mut input = Input::new(&mut input_pin, Pull::None); 107 let mut input = Input::new(input_pin.reborrow(), Pull::None);
105 108
106 assert!(input.is_high(), "input was expected to be high"); 109 assert!(input.is_high(), "input was expected to be high");
107 110
@@ -120,8 +123,8 @@ async fn main(_spawner: Spawner) {
120 123
121 { 124 {
122 info!("test wait_for_any_edge (rising)"); 125 info!("test wait_for_any_edge (rising)");
123 let mut output = Output::new(&mut output_pin, Level::Low); 126 let mut output = Output::new(output_pin.reborrow(), Level::Low);
124 let mut input = Input::new(&mut input_pin, Pull::None); 127 let mut input = Input::new(input_pin.reborrow(), Pull::None);
125 128
126 assert!(input.is_low(), "input was expected to be low"); 129 assert!(input.is_low(), "input was expected to be low");
127 130
diff --git a/tests/rp/src/bin/gpio_multicore.rs b/tests/rp/src/bin/gpio_multicore.rs
index e9c6f3122..857f36975 100644
--- a/tests/rp/src/bin/gpio_multicore.rs
+++ b/tests/rp/src/bin/gpio_multicore.rs
@@ -1,12 +1,16 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3#[cfg(feature = "rp2040")]
3teleprobe_meta::target!(b"rpi-pico"); 4teleprobe_meta::target!(b"rpi-pico");
5#[cfg(feature = "rp235xb")]
6teleprobe_meta::target!(b"pimoroni-pico-plus-2");
4 7
5use defmt::{info, unwrap}; 8use defmt::{info, unwrap};
6use embassy_executor::Executor; 9use embassy_executor::Executor;
7use embassy_rp::gpio::{Input, Level, Output, Pull}; 10use embassy_rp::gpio::{Input, Level, Output, Pull};
8use embassy_rp::multicore::{spawn_core1, Stack}; 11use embassy_rp::multicore::{spawn_core1, Stack};
9use embassy_rp::peripherals::{PIN_0, PIN_1}; 12use embassy_rp::peripherals::{PIN_0, PIN_1};
13use embassy_rp::Peri;
10use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; 14use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
11use embassy_sync::channel::Channel; 15use embassy_sync::channel::Channel;
12use static_cell::StaticCell; 16use static_cell::StaticCell;
@@ -34,7 +38,7 @@ fn main() -> ! {
34} 38}
35 39
36#[embassy_executor::task] 40#[embassy_executor::task]
37async fn core0_task(p: PIN_0) { 41async fn core0_task(p: Peri<'static, PIN_0>) {
38 info!("CORE0 is running"); 42 info!("CORE0 is running");
39 43
40 let mut pin = Output::new(p, Level::Low); 44 let mut pin = Output::new(p, Level::Low);
@@ -51,12 +55,12 @@ async fn core0_task(p: PIN_0) {
51} 55}
52 56
53#[embassy_executor::task] 57#[embassy_executor::task]
54async fn core1_task(p: PIN_1) { 58async fn core1_task(p: Peri<'static, PIN_1>) {
55 info!("CORE1 is running"); 59 info!("CORE1 is running");
56 60
57 CHANNEL0.receive().await; 61 CHANNEL0.receive().await;
58 62
59 let mut pin = Input::new(p, Pull::Down); 63 let mut pin = Input::new(p, Pull::None);
60 let wait = pin.wait_for_rising_edge(); 64 let wait = pin.wait_for_rising_edge();
61 65
62 CHANNEL1.send(()).await; 66 CHANNEL1.send(()).await;
diff --git a/tests/rp/src/bin/i2c.rs b/tests/rp/src/bin/i2c.rs
index 9615007bd..2c835bd5a 100644
--- a/tests/rp/src/bin/i2c.rs
+++ b/tests/rp/src/bin/i2c.rs
@@ -1,23 +1,21 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3#[cfg(feature = "rp2040")]
3teleprobe_meta::target!(b"rpi-pico"); 4teleprobe_meta::target!(b"rpi-pico");
5#[cfg(feature = "rp235xb")]
6teleprobe_meta::target!(b"pimoroni-pico-plus-2");
4 7
5use defmt::{assert_eq, info, panic, unwrap}; 8use defmt::{assert_eq, info, panic};
6use embassy_embedded_hal::SetConfig; 9use embassy_embedded_hal::SetConfig;
7use embassy_executor::{Executor, Spawner}; 10use embassy_executor::Spawner;
8use embassy_rp::clocks::{PllConfig, XoscConfig}; 11use embassy_rp::clocks::{PllConfig, XoscConfig};
9use embassy_rp::config::Config as rpConfig; 12use embassy_rp::config::Config as rpConfig;
10use embassy_rp::multicore::{spawn_core1, Stack};
11use embassy_rp::peripherals::{I2C0, I2C1}; 13use embassy_rp::peripherals::{I2C0, I2C1};
12use embassy_rp::{bind_interrupts, i2c, i2c_slave}; 14use embassy_rp::{bind_interrupts, i2c, i2c_slave};
13use embedded_hal_1::i2c::Operation; 15use embedded_hal_1::i2c::Operation;
14use embedded_hal_async::i2c::I2c; 16use embedded_hal_async::i2c::I2c;
15use static_cell::StaticCell;
16use {defmt_rtt as _, panic_probe as _, panic_probe as _, panic_probe as _}; 17use {defmt_rtt as _, panic_probe as _, panic_probe as _, panic_probe as _};
17 18
18static mut CORE1_STACK: Stack<1024> = Stack::new();
19static EXECUTOR1: StaticCell<Executor> = StaticCell::new();
20
21use crate::i2c::AbortReason; 19use crate::i2c::AbortReason;
22 20
23bind_interrupts!(struct Irqs { 21bind_interrupts!(struct Irqs {
@@ -106,7 +104,7 @@ async fn device_task(mut dev: i2c_slave::I2cSlave<'static, I2C1>) -> ! {
106} 104}
107 105
108async fn controller_task(con: &mut i2c::I2c<'static, I2C0, i2c::Async>) { 106async fn controller_task(con: &mut i2c::I2c<'static, I2C0, i2c::Async>) {
109 info!("Device start"); 107 info!("Controller start");
110 108
111 { 109 {
112 let buf = [0xCA, 0x11]; 110 let buf = [0xCA, 0x11];
@@ -180,7 +178,7 @@ async fn controller_task(con: &mut i2c::I2c<'static, I2C0, i2c::Async>) {
180 } 178 }
181 179
182 #[embassy_executor::main] 180 #[embassy_executor::main]
183 async fn main(_core0_spawner: Spawner) { 181 async fn main(spawner: Spawner) {
184 let mut config = rpConfig::default(); 182 let mut config = rpConfig::default();
185 // Configure clk_sys to 48MHz to support 1kHz scl. 183 // Configure clk_sys to 48MHz to support 1kHz scl.
186 // In theory it can go lower, but we won't bother to test below 1kHz. 184 // In theory it can go lower, but we won't bother to test below 1kHz.
@@ -210,14 +208,7 @@ async fn controller_task(con: &mut i2c::I2c<'static, I2C0, i2c::Async>) {
210 config.addr = DEV_ADDR as u16; 208 config.addr = DEV_ADDR as u16;
211 let device = i2c_slave::I2cSlave::new(p.I2C1, d_sda, d_scl, Irqs, config); 209 let device = i2c_slave::I2cSlave::new(p.I2C1, d_sda, d_scl, Irqs, config);
212 210
213 spawn_core1( 211 spawner.must_spawn(device_task(device));
214 p.CORE1,
215 unsafe { &mut *core::ptr::addr_of_mut!(CORE1_STACK) },
216 move || {
217 let executor1 = EXECUTOR1.init(Executor::new());
218 executor1.run(|spawner| unwrap!(spawner.spawn(device_task(device))));
219 },
220 );
221 212
222 let c_sda = p.PIN_21; 213 let c_sda = p.PIN_21;
223 let c_scl = p.PIN_20; 214 let c_scl = p.PIN_20;
diff --git a/tests/rp/src/bin/multicore.rs b/tests/rp/src/bin/multicore.rs
index 783ea0f27..902169c40 100644
--- a/tests/rp/src/bin/multicore.rs
+++ b/tests/rp/src/bin/multicore.rs
@@ -1,6 +1,9 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3#[cfg(feature = "rp2040")]
3teleprobe_meta::target!(b"rpi-pico"); 4teleprobe_meta::target!(b"rpi-pico");
5#[cfg(feature = "rp235xb")]
6teleprobe_meta::target!(b"pimoroni-pico-plus-2");
4 7
5use defmt::{info, unwrap}; 8use defmt::{info, unwrap};
6use embassy_executor::Executor; 9use embassy_executor::Executor;
diff --git a/tests/rp/src/bin/overclock.rs b/tests/rp/src/bin/overclock.rs
new file mode 100644
index 000000000..167a26eb2
--- /dev/null
+++ b/tests/rp/src/bin/overclock.rs
@@ -0,0 +1,69 @@
1#![no_std]
2#![no_main]
3
4#[cfg(feature = "rp2040")]
5teleprobe_meta::target!(b"rpi-pico");
6#[cfg(feature = "rp235xb")]
7teleprobe_meta::target!(b"pimoroni-pico-plus-2");
8
9use defmt::info;
10use embassy_executor::Spawner;
11use embassy_rp::clocks::{clk_sys_freq, core_voltage, ClockConfig, CoreVoltage};
12use embassy_rp::config::Config;
13use embassy_time::Instant;
14use {defmt_rtt as _, panic_probe as _};
15
16const COUNT_TO: i64 = 10_000_000;
17
18#[embassy_executor::main]
19async fn main(_spawner: Spawner) {
20 let mut config = Config::default();
21
22 // Initialize with 200MHz clock configuration
23 config.clocks = ClockConfig::system_freq(200_000_000).unwrap();
24
25 // if we are rp235x, we need to manually set the core voltage. rp2040 should do this automatically
26 #[cfg(feature = "rp235xb")]
27 {
28 config.clocks.core_voltage = CoreVoltage::V1_15;
29 }
30
31 let _p = embassy_rp::init(config);
32
33 // We should be at core voltage of 1.15V
34 assert_eq!(core_voltage().unwrap(), CoreVoltage::V1_15, "Core voltage is not 1.15V");
35 // We should be at 200MHz
36 assert_eq!(clk_sys_freq(), 200_000_000, "System clock frequency is not 200MHz");
37
38 // Test the system speed
39 let time_elapsed = {
40 let mut counter = 0;
41 let start = Instant::now();
42 while counter < COUNT_TO {
43 counter += 1;
44 }
45 let elapsed = Instant::now() - start;
46
47 elapsed.as_millis()
48 };
49
50 // Tests will fail if unused variables are detected:
51 // Report the elapsed time, so that the compiler doesn't optimize it away for the chip not on test
52 info!(
53 "At {}Mhz: Elapsed time to count to {}: {}ms",
54 clk_sys_freq() / 1_000_000,
55 COUNT_TO,
56 time_elapsed
57 );
58
59 // Check if the elapsed time is within expected limits
60 // for rp2040 we expect about 600ms
61 #[cfg(feature = "rp2040")]
62 // allow 1% error
63 assert!(time_elapsed < 606, "Elapsed time is too long");
64 // for rp235x we expect about 450ms
65 #[cfg(feature = "rp235xb")]
66 assert!(time_elapsed < 455, "Elapsed time is too long");
67
68 cortex_m::asm::bkpt();
69}
diff --git a/tests/rp/src/bin/pio_irq.rs b/tests/rp/src/bin/pio_irq.rs
index 33cdaaac9..dc37dd83d 100644
--- a/tests/rp/src/bin/pio_irq.rs
+++ b/tests/rp/src/bin/pio_irq.rs
@@ -1,11 +1,15 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3#[cfg(feature = "rp2040")]
3teleprobe_meta::target!(b"rpi-pico"); 4teleprobe_meta::target!(b"rpi-pico");
5#[cfg(feature = "rp235xb")]
6teleprobe_meta::target!(b"pimoroni-pico-plus-2");
4 7
5use defmt::info; 8use defmt::info;
6use embassy_executor::Spawner; 9use embassy_executor::Spawner;
7use embassy_rp::bind_interrupts; 10use embassy_rp::bind_interrupts;
8use embassy_rp::peripherals::PIO0; 11use embassy_rp::peripherals::PIO0;
12use embassy_rp::pio::program::pio_asm;
9use embassy_rp::pio::{Config, InterruptHandler, Pio}; 13use embassy_rp::pio::{Config, InterruptHandler, Pio};
10use {defmt_rtt as _, panic_probe as _}; 14use {defmt_rtt as _, panic_probe as _};
11 15
@@ -24,7 +28,7 @@ async fn main(_spawner: Spawner) {
24 .. 28 ..
25 } = Pio::new(pio, Irqs); 29 } = Pio::new(pio, Irqs);
26 30
27 let prg = pio_proc::pio_asm!( 31 let prg = pio_asm!(
28 "irq set 0", 32 "irq set 0",
29 "irq wait 0", 33 "irq wait 0",
30 "irq set 1", 34 "irq set 1",
diff --git a/tests/rp/src/bin/pio_multi_load.rs b/tests/rp/src/bin/pio_multi_load.rs
index cd28f99b6..aca476d56 100644
--- a/tests/rp/src/bin/pio_multi_load.rs
+++ b/tests/rp/src/bin/pio_multi_load.rs
@@ -1,11 +1,15 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3#[cfg(feature = "rp2040")]
3teleprobe_meta::target!(b"rpi-pico"); 4teleprobe_meta::target!(b"rpi-pico");
5#[cfg(feature = "rp235xb")]
6teleprobe_meta::target!(b"pimoroni-pico-plus-2");
4 7
5use defmt::info; 8use defmt::info;
6use embassy_executor::Spawner; 9use embassy_executor::Spawner;
7use embassy_rp::bind_interrupts; 10use embassy_rp::bind_interrupts;
8use embassy_rp::peripherals::PIO0; 11use embassy_rp::peripherals::PIO0;
12use embassy_rp::pio::program::pio_asm;
9use embassy_rp::pio::{Config, InterruptHandler, LoadError, Pio}; 13use embassy_rp::pio::{Config, InterruptHandler, LoadError, Pio};
10use {defmt_rtt as _, panic_probe as _}; 14use {defmt_rtt as _, panic_probe as _};
11 15
@@ -27,7 +31,7 @@ async fn main(_spawner: Spawner) {
27 } = Pio::new(pio, Irqs); 31 } = Pio::new(pio, Irqs);
28 32
29 // load with explicit origin works 33 // load with explicit origin works
30 let prg1 = pio_proc::pio_asm!( 34 let prg1 = pio_asm!(
31 ".origin 4" 35 ".origin 4"
32 "nop", 36 "nop",
33 "nop", 37 "nop",
@@ -46,15 +50,14 @@ async fn main(_spawner: Spawner) {
46 assert_eq!(loaded1.wrap.target, 4); 50 assert_eq!(loaded1.wrap.target, 4);
47 51
48 // load without origin chooses a free space 52 // load without origin chooses a free space
49 let prg2 = pio_proc::pio_asm!("nop", "nop", "nop", "nop", "nop", "nop", "nop", "irq 1", "nop", "nop",); 53 let prg2 = pio_asm!("nop", "nop", "nop", "nop", "nop", "nop", "nop", "irq 1", "nop", "nop",);
50 let loaded2 = common.load_program(&prg2.program); 54 let loaded2 = common.load_program(&prg2.program);
51 assert_eq!(loaded2.origin, 14); 55 assert_eq!(loaded2.origin, 14);
52 assert_eq!(loaded2.wrap.source, 23); 56 assert_eq!(loaded2.wrap.source, 23);
53 assert_eq!(loaded2.wrap.target, 14); 57 assert_eq!(loaded2.wrap.target, 14);
54 58
55 // wrapping around the end of program space automatically works 59 // wrapping around the end of program space automatically works
56 let prg3 = 60 let prg3 = pio_asm!("nop", "nop", "nop", "nop", "nop", "nop", "nop", "nop", "nop", "nop", "nop", "irq 2",);
57 pio_proc::pio_asm!("nop", "nop", "nop", "nop", "nop", "nop", "nop", "nop", "nop", "nop", "nop", "irq 2",);
58 let loaded3 = common.load_program(&prg3.program); 61 let loaded3 = common.load_program(&prg3.program);
59 assert_eq!(loaded3.origin, 24); 62 assert_eq!(loaded3.origin, 24);
60 assert_eq!(loaded3.wrap.source, 3); 63 assert_eq!(loaded3.wrap.source, 3);
@@ -88,13 +91,13 @@ async fn main(_spawner: Spawner) {
88 91
89 // instruction memory is full now. all loads should fail. 92 // instruction memory is full now. all loads should fail.
90 { 93 {
91 let prg = pio_proc::pio_asm!(".origin 0", "nop"); 94 let prg = pio_asm!(".origin 0", "nop");
92 match common.try_load_program(&prg.program) { 95 match common.try_load_program(&prg.program) {
93 Err(LoadError::AddressInUse(0)) => (), 96 Err(LoadError::AddressInUse(0)) => (),
94 _ => panic!("program loaded when it shouldn't"), 97 _ => panic!("program loaded when it shouldn't"),
95 }; 98 };
96 99
97 let prg = pio_proc::pio_asm!("nop"); 100 let prg = pio_asm!("nop");
98 match common.try_load_program(&prg.program) { 101 match common.try_load_program(&prg.program) {
99 Err(LoadError::InsufficientSpace) => (), 102 Err(LoadError::InsufficientSpace) => (),
100 _ => panic!("program loaded when it shouldn't"), 103 _ => panic!("program loaded when it shouldn't"),
@@ -106,13 +109,13 @@ async fn main(_spawner: Spawner) {
106 common.free_instr(loaded3.used_memory); 109 common.free_instr(loaded3.used_memory);
107 } 110 }
108 { 111 {
109 let prg = pio_proc::pio_asm!(".origin 0", "nop"); 112 let prg = pio_asm!(".origin 0", "nop");
110 match common.try_load_program(&prg.program) { 113 match common.try_load_program(&prg.program) {
111 Ok(_) => (), 114 Ok(_) => (),
112 _ => panic!("program didn't loaded when it shouldn"), 115 _ => panic!("program didn't loaded when it shouldn"),
113 }; 116 };
114 117
115 let prg = pio_proc::pio_asm!("nop"); 118 let prg = pio_asm!("nop");
116 match common.try_load_program(&prg.program) { 119 match common.try_load_program(&prg.program) {
117 Ok(_) => (), 120 Ok(_) => (),
118 _ => panic!("program didn't loaded when it shouldn"), 121 _ => panic!("program didn't loaded when it shouldn"),
diff --git a/tests/rp/src/bin/pwm.rs b/tests/rp/src/bin/pwm.rs
index c05197000..5f890cd50 100644
--- a/tests/rp/src/bin/pwm.rs
+++ b/tests/rp/src/bin/pwm.rs
@@ -1,10 +1,15 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3#[cfg(feature = "rp2040")]
3teleprobe_meta::target!(b"rpi-pico"); 4teleprobe_meta::target!(b"rpi-pico");
5#[cfg(feature = "rp235xb")]
6teleprobe_meta::target!(b"pimoroni-pico-plus-2");
4 7
5use defmt::{assert, assert_eq, assert_ne, *}; 8use defmt::{assert, assert_eq, assert_ne, *};
6use embassy_executor::Spawner; 9use embassy_executor::Spawner;
7use embassy_rp::gpio::{Input, Level, Output, Pull}; 10use embassy_rp::gpio::{Input, Pull};
11#[cfg(feature = "rp2040")]
12use embassy_rp::gpio::{Level, Output};
8use embassy_rp::pwm::{Config, InputMode, Pwm}; 13use embassy_rp::pwm::{Config, InputMode, Pwm};
9use embassy_time::Timer; 14use embassy_time::Timer;
10use {defmt_rtt as _, panic_probe as _}; 15use {defmt_rtt as _, panic_probe as _};
@@ -28,7 +33,7 @@ async fn main(_spawner: Spawner) {
28 33
29 // Test free-running clock 34 // Test free-running clock
30 { 35 {
31 let pwm = Pwm::new_free(&mut p.PWM_SLICE3, cfg.clone()); 36 let pwm = Pwm::new_free(p.PWM_SLICE3.reborrow(), cfg.clone());
32 cortex_m::asm::delay(125); 37 cortex_m::asm::delay(125);
33 let ctr = pwm.counter(); 38 let ctr = pwm.counter();
34 assert!(ctr > 0); 39 assert!(ctr > 0);
@@ -45,8 +50,8 @@ async fn main(_spawner: Spawner) {
45 50
46 // Test output from A 51 // Test output from A
47 { 52 {
48 let pin1 = Input::new(&mut p9, Pull::None); 53 let pin1 = Input::new(p9.reborrow(), Pull::None);
49 let _pwm = Pwm::new_output_a(&mut p.PWM_SLICE3, &mut p6, cfg.clone()); 54 let _pwm = Pwm::new_output_a(p.PWM_SLICE3.reborrow(), p6.reborrow(), cfg.clone());
50 Timer::after_millis(1).await; 55 Timer::after_millis(1).await;
51 assert_eq!(pin1.is_low(), invert_a); 56 assert_eq!(pin1.is_low(), invert_a);
52 Timer::after_millis(5).await; 57 Timer::after_millis(5).await;
@@ -59,8 +64,8 @@ async fn main(_spawner: Spawner) {
59 64
60 // Test output from B 65 // Test output from B
61 { 66 {
62 let pin2 = Input::new(&mut p11, Pull::None); 67 let pin2 = Input::new(p11.reborrow(), Pull::None);
63 let _pwm = Pwm::new_output_b(&mut p.PWM_SLICE3, &mut p7, cfg.clone()); 68 let _pwm = Pwm::new_output_b(p.PWM_SLICE3.reborrow(), p7.reborrow(), cfg.clone());
64 Timer::after_millis(1).await; 69 Timer::after_millis(1).await;
65 assert_ne!(pin2.is_low(), invert_a); 70 assert_ne!(pin2.is_low(), invert_a);
66 Timer::after_millis(5).await; 71 Timer::after_millis(5).await;
@@ -73,9 +78,9 @@ async fn main(_spawner: Spawner) {
73 78
74 // Test output from A+B 79 // Test output from A+B
75 { 80 {
76 let pin1 = Input::new(&mut p9, Pull::None); 81 let pin1 = Input::new(p9.reborrow(), Pull::None);
77 let pin2 = Input::new(&mut p11, Pull::None); 82 let pin2 = Input::new(p11.reborrow(), Pull::None);
78 let _pwm = Pwm::new_output_ab(&mut p.PWM_SLICE3, &mut p6, &mut p7, cfg.clone()); 83 let _pwm = Pwm::new_output_ab(p.PWM_SLICE3.reborrow(), p6.reborrow(), p7.reborrow(), cfg.clone());
79 Timer::after_millis(1).await; 84 Timer::after_millis(1).await;
80 assert_eq!(pin1.is_low(), invert_a); 85 assert_eq!(pin1.is_low(), invert_a);
81 assert_ne!(pin2.is_low(), invert_a); 86 assert_ne!(pin2.is_low(), invert_a);
@@ -92,9 +97,16 @@ async fn main(_spawner: Spawner) {
92 } 97 }
93 98
94 // Test level-gated 99 // Test level-gated
100 #[cfg(feature = "rp2040")]
95 { 101 {
96 let mut pin2 = Output::new(&mut p11, Level::Low); 102 let mut pin2 = Output::new(p11.reborrow(), Level::Low);
97 let pwm = Pwm::new_input(&mut p.PWM_SLICE3, &mut p7, Pull::None, InputMode::Level, cfg.clone()); 103 let pwm = Pwm::new_input(
104 p.PWM_SLICE3.reborrow(),
105 p7.reborrow(),
106 Pull::None,
107 InputMode::Level,
108 cfg.clone(),
109 );
98 assert_eq!(pwm.counter(), 0); 110 assert_eq!(pwm.counter(), 0);
99 Timer::after_millis(5).await; 111 Timer::after_millis(5).await;
100 assert_eq!(pwm.counter(), 0); 112 assert_eq!(pwm.counter(), 0);
@@ -102,17 +114,19 @@ async fn main(_spawner: Spawner) {
102 Timer::after_millis(1).await; 114 Timer::after_millis(1).await;
103 pin2.set_low(); 115 pin2.set_low();
104 let ctr = pwm.counter(); 116 let ctr = pwm.counter();
117 info!("ctr: {}", ctr);
105 assert!(ctr >= 1000); 118 assert!(ctr >= 1000);
106 Timer::after_millis(1).await; 119 Timer::after_millis(1).await;
107 assert_eq!(pwm.counter(), ctr); 120 assert_eq!(pwm.counter(), ctr);
108 } 121 }
109 122
110 // Test rising-gated 123 // Test rising-gated
124 #[cfg(feature = "rp2040")]
111 { 125 {
112 let mut pin2 = Output::new(&mut p11, Level::Low); 126 let mut pin2 = Output::new(p11.reborrow(), Level::Low);
113 let pwm = Pwm::new_input( 127 let pwm = Pwm::new_input(
114 &mut p.PWM_SLICE3, 128 p.PWM_SLICE3.reborrow(),
115 &mut p7, 129 p7.reborrow(),
116 Pull::None, 130 Pull::None,
117 InputMode::RisingEdge, 131 InputMode::RisingEdge,
118 cfg.clone(), 132 cfg.clone(),
@@ -129,11 +143,12 @@ async fn main(_spawner: Spawner) {
129 } 143 }
130 144
131 // Test falling-gated 145 // Test falling-gated
146 #[cfg(feature = "rp2040")]
132 { 147 {
133 let mut pin2 = Output::new(&mut p11, Level::High); 148 let mut pin2 = Output::new(p11.reborrow(), Level::High);
134 let pwm = Pwm::new_input( 149 let pwm = Pwm::new_input(
135 &mut p.PWM_SLICE3, 150 p.PWM_SLICE3.reborrow(),
136 &mut p7, 151 p7.reborrow(),
137 Pull::None, 152 Pull::None,
138 InputMode::FallingEdge, 153 InputMode::FallingEdge,
139 cfg.clone(), 154 cfg.clone(),
@@ -151,10 +166,10 @@ async fn main(_spawner: Spawner) {
151 166
152 // pull-down 167 // pull-down
153 { 168 {
154 let pin2 = Input::new(&mut p11, Pull::None); 169 let pin2 = Input::new(p11.reborrow(), Pull::None);
155 Pwm::new_input( 170 Pwm::new_input(
156 &mut p.PWM_SLICE3, 171 p.PWM_SLICE3.reborrow(),
157 &mut p7, 172 p7.reborrow(),
158 Pull::Down, 173 Pull::Down,
159 InputMode::FallingEdge, 174 InputMode::FallingEdge,
160 cfg.clone(), 175 cfg.clone(),
@@ -165,10 +180,10 @@ async fn main(_spawner: Spawner) {
165 180
166 // pull-up 181 // pull-up
167 { 182 {
168 let pin2 = Input::new(&mut p11, Pull::None); 183 let pin2 = Input::new(p11.reborrow(), Pull::None);
169 Pwm::new_input( 184 Pwm::new_input(
170 &mut p.PWM_SLICE3, 185 p.PWM_SLICE3.reborrow(),
171 &mut p7, 186 p7.reborrow(),
172 Pull::Up, 187 Pull::Up,
173 InputMode::FallingEdge, 188 InputMode::FallingEdge,
174 cfg.clone(), 189 cfg.clone(),
diff --git a/tests/rp/src/bin/spi.rs b/tests/rp/src/bin/spi.rs
index 4b02942a7..6802bfc99 100644
--- a/tests/rp/src/bin/spi.rs
+++ b/tests/rp/src/bin/spi.rs
@@ -1,6 +1,9 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3#[cfg(feature = "rp2040")]
3teleprobe_meta::target!(b"rpi-pico"); 4teleprobe_meta::target!(b"rpi-pico");
5#[cfg(feature = "rp235xb")]
6teleprobe_meta::target!(b"pimoroni-pico-plus-2");
4 7
5use defmt::{assert_eq, *}; 8use defmt::{assert_eq, *};
6use embassy_executor::Spawner; 9use embassy_executor::Spawner;
diff --git a/tests/rp/src/bin/spi_async.rs b/tests/rp/src/bin/spi_async.rs
index efdc80b53..e50667435 100644
--- a/tests/rp/src/bin/spi_async.rs
+++ b/tests/rp/src/bin/spi_async.rs
@@ -3,7 +3,10 @@
3//! 3//!
4#![no_std] 4#![no_std]
5#![no_main] 5#![no_main]
6#[cfg(feature = "rp2040")]
6teleprobe_meta::target!(b"rpi-pico"); 7teleprobe_meta::target!(b"rpi-pico");
8#[cfg(feature = "rp235xb")]
9teleprobe_meta::target!(b"pimoroni-pico-plus-2");
7 10
8use defmt::{assert_eq, *}; 11use defmt::{assert_eq, *};
9use embassy_executor::Spawner; 12use embassy_executor::Spawner;
diff --git a/tests/rp/src/bin/spinlock_mutex_multicore.rs b/tests/rp/src/bin/spinlock_mutex_multicore.rs
new file mode 100644
index 000000000..ebcf1ca32
--- /dev/null
+++ b/tests/rp/src/bin/spinlock_mutex_multicore.rs
@@ -0,0 +1,54 @@
1#![no_std]
2#![no_main]
3#[cfg(feature = "rp2040")]
4teleprobe_meta::target!(b"rpi-pico");
5#[cfg(feature = "rp235xb")]
6teleprobe_meta::target!(b"pimoroni-pico-plus-2");
7
8use defmt::{info, unwrap};
9use embassy_executor::Executor;
10use embassy_rp::multicore::{spawn_core1, Stack};
11use embassy_rp::spinlock_mutex::SpinlockRawMutex;
12use embassy_sync::channel::Channel;
13use static_cell::StaticCell;
14use {defmt_rtt as _, panic_probe as _};
15
16static mut CORE1_STACK: Stack<1024> = Stack::new();
17static EXECUTOR0: StaticCell<Executor> = StaticCell::new();
18static EXECUTOR1: StaticCell<Executor> = StaticCell::new();
19static CHANNEL0: Channel<SpinlockRawMutex<0>, bool, 1> = Channel::new();
20static CHANNEL1: Channel<SpinlockRawMutex<1>, bool, 1> = Channel::new();
21
22#[cortex_m_rt::entry]
23fn main() -> ! {
24 let p = embassy_rp::init(Default::default());
25 spawn_core1(
26 p.CORE1,
27 unsafe { &mut *core::ptr::addr_of_mut!(CORE1_STACK) },
28 move || {
29 let executor1 = EXECUTOR1.init(Executor::new());
30 executor1.run(|spawner| unwrap!(spawner.spawn(core1_task())));
31 },
32 );
33 let executor0 = EXECUTOR0.init(Executor::new());
34 executor0.run(|spawner| unwrap!(spawner.spawn(core0_task())));
35}
36
37#[embassy_executor::task]
38async fn core0_task() {
39 info!("CORE0 is running");
40 let ping = true;
41 CHANNEL0.send(ping).await;
42 let pong = CHANNEL1.receive().await;
43 assert_eq!(ping, pong);
44
45 info!("Test OK");
46 cortex_m::asm::bkpt();
47}
48
49#[embassy_executor::task]
50async fn core1_task() {
51 info!("CORE1 is running");
52 let ping = CHANNEL0.receive().await;
53 CHANNEL1.send(ping).await;
54}
diff --git a/tests/rp/src/bin/timer.rs b/tests/rp/src/bin/timer.rs
index be9242144..12a4d7daa 100644
--- a/tests/rp/src/bin/timer.rs
+++ b/tests/rp/src/bin/timer.rs
@@ -1,6 +1,9 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3#[cfg(feature = "rp2040")]
3teleprobe_meta::target!(b"rpi-pico"); 4teleprobe_meta::target!(b"rpi-pico");
5#[cfg(feature = "rp235xb")]
6teleprobe_meta::target!(b"pimoroni-pico-plus-2");
4 7
5use defmt::{assert, *}; 8use defmt::{assert, *};
6use embassy_executor::Spawner; 9use embassy_executor::Spawner;
diff --git a/tests/rp/src/bin/uart.rs b/tests/rp/src/bin/uart.rs
index 6e6e5517b..80230f3fe 100644
--- a/tests/rp/src/bin/uart.rs
+++ b/tests/rp/src/bin/uart.rs
@@ -1,21 +1,24 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3#[cfg(feature = "rp2040")]
3teleprobe_meta::target!(b"rpi-pico"); 4teleprobe_meta::target!(b"rpi-pico");
5#[cfg(feature = "rp235xb")]
6teleprobe_meta::target!(b"pimoroni-pico-plus-2");
4 7
5use defmt::{assert_eq, *}; 8use defmt::{assert_eq, *};
6use embassy_executor::Spawner; 9use embassy_executor::Spawner;
7use embassy_rp::gpio::{Level, Output}; 10use embassy_rp::gpio::{Level, Output};
8use embassy_rp::uart::{Blocking, Config, Error, Instance, Parity, Uart, UartRx}; 11use embassy_rp::uart::{Blocking, Config, Error, Parity, Uart, UartRx};
9use embassy_time::Timer; 12use embassy_time::Timer;
10use {defmt_rtt as _, panic_probe as _}; 13use {defmt_rtt as _, panic_probe as _};
11 14
12fn read<const N: usize>(uart: &mut Uart<'_, impl Instance, Blocking>) -> Result<[u8; N], Error> { 15fn read<const N: usize>(uart: &mut Uart<'_, Blocking>) -> Result<[u8; N], Error> {
13 let mut buf = [255; N]; 16 let mut buf = [255; N];
14 uart.blocking_read(&mut buf)?; 17 uart.blocking_read(&mut buf)?;
15 Ok(buf) 18 Ok(buf)
16} 19}
17 20
18fn read1<const N: usize>(uart: &mut UartRx<'_, impl Instance, Blocking>) -> Result<[u8; N], Error> { 21fn read1<const N: usize>(uart: &mut UartRx<'_, Blocking>) -> Result<[u8; N], Error> {
19 let mut buf = [255; N]; 22 let mut buf = [255; N];
20 uart.blocking_read(&mut buf)?; 23 uart.blocking_read(&mut buf)?;
21 Ok(buf) 24 Ok(buf)
@@ -53,7 +56,7 @@ async fn main(_spawner: Spawner) {
53 56
54 { 57 {
55 let config = Config::default(); 58 let config = Config::default();
56 let mut uart = Uart::new_blocking(&mut uart, &mut tx, &mut rx, config); 59 let mut uart = Uart::new_blocking(uart.reborrow(), tx.reborrow(), rx.reborrow(), config);
57 60
58 // We can't send too many bytes, they have to fit in the FIFO. 61 // We can't send too many bytes, they have to fit in the FIFO.
59 // This is because we aren't sending+receiving at the same time. 62 // This is because we aren't sending+receiving at the same time.
@@ -66,7 +69,7 @@ async fn main(_spawner: Spawner) {
66 info!("test overflow detection"); 69 info!("test overflow detection");
67 { 70 {
68 let config = Config::default(); 71 let config = Config::default();
69 let mut uart = Uart::new_blocking(&mut uart, &mut tx, &mut rx, config); 72 let mut uart = Uart::new_blocking(uart.reborrow(), tx.reborrow(), rx.reborrow(), config);
70 73
71 let data = [ 74 let data = [
72 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 75 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
@@ -90,7 +93,7 @@ async fn main(_spawner: Spawner) {
90 info!("test break detection"); 93 info!("test break detection");
91 { 94 {
92 let config = Config::default(); 95 let config = Config::default();
93 let mut uart = Uart::new_blocking(&mut uart, &mut tx, &mut rx, config); 96 let mut uart = Uart::new_blocking(uart.reborrow(), tx.reborrow(), rx.reborrow(), config);
94 97
95 // break on empty fifo 98 // break on empty fifo
96 uart.send_break(20).await; 99 uart.send_break(20).await;
@@ -110,11 +113,11 @@ async fn main(_spawner: Spawner) {
110 // parity detection. here we bitbang to not require two uarts. 113 // parity detection. here we bitbang to not require two uarts.
111 info!("test parity error detection"); 114 info!("test parity error detection");
112 { 115 {
113 let mut pin = Output::new(&mut tx, Level::High); 116 let mut pin = Output::new(tx.reborrow(), Level::High);
114 let mut config = Config::default(); 117 let mut config = Config::default();
115 config.baudrate = 1000; 118 config.baudrate = 1000;
116 config.parity = Parity::ParityEven; 119 config.parity = Parity::ParityEven;
117 let mut uart = UartRx::new_blocking(&mut uart, &mut rx, config); 120 let mut uart = UartRx::new_blocking(uart.reborrow(), rx.reborrow(), config);
118 121
119 async fn chr(pin: &mut Output<'_>, v: u8, parity: u8) { 122 async fn chr(pin: &mut Output<'_>, v: u8, parity: u8) {
120 send(pin, v, Some(parity != 0)).await; 123 send(pin, v, Some(parity != 0)).await;
@@ -137,10 +140,10 @@ async fn main(_spawner: Spawner) {
137 // framing error detection. here we bitbang because there's no other way. 140 // framing error detection. here we bitbang because there's no other way.
138 info!("test framing error detection"); 141 info!("test framing error detection");
139 { 142 {
140 let mut pin = Output::new(&mut tx, Level::High); 143 let mut pin = Output::new(tx.reborrow(), Level::High);
141 let mut config = Config::default(); 144 let mut config = Config::default();
142 config.baudrate = 1000; 145 config.baudrate = 1000;
143 let mut uart = UartRx::new_blocking(&mut uart, &mut rx, config); 146 let mut uart = UartRx::new_blocking(uart.reborrow(), rx.reborrow(), config);
144 147
145 async fn chr(pin: &mut Output<'_>, v: u8, good: bool) { 148 async fn chr(pin: &mut Output<'_>, v: u8, good: bool) {
146 if good { 149 if good {
diff --git a/tests/rp/src/bin/uart_buffered.rs b/tests/rp/src/bin/uart_buffered.rs
index d68c23cbd..cb78fc142 100644
--- a/tests/rp/src/bin/uart_buffered.rs
+++ b/tests/rp/src/bin/uart_buffered.rs
@@ -1,13 +1,16 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3#[cfg(feature = "rp2040")]
3teleprobe_meta::target!(b"rpi-pico"); 4teleprobe_meta::target!(b"rpi-pico");
5#[cfg(feature = "rp235xb")]
6teleprobe_meta::target!(b"pimoroni-pico-plus-2");
4 7
5use defmt::{assert_eq, panic, *}; 8use defmt::{assert_eq, panic, *};
6use embassy_executor::Spawner; 9use embassy_executor::Spawner;
7use embassy_rp::bind_interrupts; 10use embassy_rp::bind_interrupts;
8use embassy_rp::gpio::{Level, Output}; 11use embassy_rp::gpio::{Level, Output};
9use embassy_rp::peripherals::UART0; 12use embassy_rp::peripherals::UART0;
10use embassy_rp::uart::{BufferedInterruptHandler, BufferedUart, BufferedUartRx, Config, Error, Instance, Parity}; 13use embassy_rp::uart::{BufferedInterruptHandler, BufferedUart, BufferedUartRx, Config, Error, Parity};
11use embassy_time::Timer; 14use embassy_time::Timer;
12use embedded_io_async::{Read, ReadExactError, Write}; 15use embedded_io_async::{Read, ReadExactError, Write};
13use {defmt_rtt as _, panic_probe as _}; 16use {defmt_rtt as _, panic_probe as _};
@@ -16,7 +19,7 @@ bind_interrupts!(struct Irqs {
16 UART0_IRQ => BufferedInterruptHandler<UART0>; 19 UART0_IRQ => BufferedInterruptHandler<UART0>;
17}); 20});
18 21
19async fn read<const N: usize>(uart: &mut BufferedUart<'_, impl Instance>) -> Result<[u8; N], Error> { 22async fn read<const N: usize>(uart: &mut BufferedUart) -> Result<[u8; N], Error> {
20 let mut buf = [255; N]; 23 let mut buf = [255; N];
21 match uart.read_exact(&mut buf).await { 24 match uart.read_exact(&mut buf).await {
22 Ok(()) => Ok(buf), 25 Ok(()) => Ok(buf),
@@ -26,7 +29,7 @@ async fn read<const N: usize>(uart: &mut BufferedUart<'_, impl Instance>) -> Res
26 } 29 }
27} 30}
28 31
29async fn read1<const N: usize>(uart: &mut BufferedUartRx<'_, impl Instance>) -> Result<[u8; N], Error> { 32async fn read1<const N: usize>(uart: &mut BufferedUartRx) -> Result<[u8; N], Error> {
30 let mut buf = [255; N]; 33 let mut buf = [255; N];
31 match uart.read_exact(&mut buf).await { 34 match uart.read_exact(&mut buf).await {
32 Ok(()) => Ok(buf), 35 Ok(()) => Ok(buf),
@@ -70,7 +73,15 @@ async fn main(_spawner: Spawner) {
70 let config = Config::default(); 73 let config = Config::default();
71 let tx_buf = &mut [0u8; 16]; 74 let tx_buf = &mut [0u8; 16];
72 let rx_buf = &mut [0u8; 16]; 75 let rx_buf = &mut [0u8; 16];
73 let mut uart = BufferedUart::new(&mut uart, Irqs, &mut tx, &mut rx, tx_buf, rx_buf, config); 76 let mut uart = BufferedUart::new(
77 uart.reborrow(),
78 tx.reborrow(),
79 rx.reborrow(),
80 Irqs,
81 tx_buf,
82 rx_buf,
83 config,
84 );
74 85
75 // Make sure we send more bytes than fits in the FIFO, to test the actual 86 // Make sure we send more bytes than fits in the FIFO, to test the actual
76 // bufferedUart. 87 // bufferedUart.
@@ -90,7 +101,15 @@ async fn main(_spawner: Spawner) {
90 let config = Config::default(); 101 let config = Config::default();
91 let tx_buf = &mut [0u8; 16]; 102 let tx_buf = &mut [0u8; 16];
92 let rx_buf = &mut [0u8; 16]; 103 let rx_buf = &mut [0u8; 16];
93 let mut uart = BufferedUart::new(&mut uart, Irqs, &mut tx, &mut rx, tx_buf, rx_buf, config); 104 let mut uart = BufferedUart::new(
105 uart.reborrow(),
106 tx.reborrow(),
107 rx.reborrow(),
108 Irqs,
109 tx_buf,
110 rx_buf,
111 config,
112 );
94 113
95 // Make sure we send more bytes than fits in the FIFO, to test the actual 114 // Make sure we send more bytes than fits in the FIFO, to test the actual
96 // bufferedUart. 115 // bufferedUart.
@@ -125,7 +144,15 @@ async fn main(_spawner: Spawner) {
125 config.baudrate = 1000; 144 config.baudrate = 1000;
126 let tx_buf = &mut [0u8; 16]; 145 let tx_buf = &mut [0u8; 16];
127 let rx_buf = &mut [0u8; 16]; 146 let rx_buf = &mut [0u8; 16];
128 let mut uart = BufferedUart::new(&mut uart, Irqs, &mut tx, &mut rx, tx_buf, rx_buf, config); 147 let mut uart = BufferedUart::new(
148 uart.reborrow(),
149 tx.reborrow(),
150 rx.reborrow(),
151 Irqs,
152 tx_buf,
153 rx_buf,
154 config,
155 );
129 156
130 // break on empty buffer 157 // break on empty buffer
131 uart.send_break(20).await; 158 uart.send_break(20).await;
@@ -153,13 +180,13 @@ async fn main(_spawner: Spawner) {
153 // parity detection. here we bitbang to not require two uarts. 180 // parity detection. here we bitbang to not require two uarts.
154 info!("test parity error detection"); 181 info!("test parity error detection");
155 { 182 {
156 let mut pin = Output::new(&mut tx, Level::High); 183 let mut pin = Output::new(tx.reborrow(), Level::High);
157 // choose a very slow baud rate to make tests reliable even with O0 184 // choose a very slow baud rate to make tests reliable even with O0
158 let mut config = Config::default(); 185 let mut config = Config::default();
159 config.baudrate = 1000; 186 config.baudrate = 1000;
160 config.parity = Parity::ParityEven; 187 config.parity = Parity::ParityEven;
161 let rx_buf = &mut [0u8; 16]; 188 let rx_buf = &mut [0u8; 16];
162 let mut uart = BufferedUartRx::new(&mut uart, Irqs, &mut rx, rx_buf, config); 189 let mut uart = BufferedUartRx::new(uart.reborrow(), Irqs, rx.reborrow(), rx_buf, config);
163 190
164 async fn chr(pin: &mut Output<'_>, v: u8, parity: u32) { 191 async fn chr(pin: &mut Output<'_>, v: u8, parity: u32) {
165 send(pin, v, Some(parity != 0)).await; 192 send(pin, v, Some(parity != 0)).await;
@@ -201,12 +228,12 @@ async fn main(_spawner: Spawner) {
201 // framing error detection. here we bitbang because there's no other way. 228 // framing error detection. here we bitbang because there's no other way.
202 info!("test framing error detection"); 229 info!("test framing error detection");
203 { 230 {
204 let mut pin = Output::new(&mut tx, Level::High); 231 let mut pin = Output::new(tx.reborrow(), Level::High);
205 // choose a very slow baud rate to make tests reliable even with O0 232 // choose a very slow baud rate to make tests reliable even with O0
206 let mut config = Config::default(); 233 let mut config = Config::default();
207 config.baudrate = 1000; 234 config.baudrate = 1000;
208 let rx_buf = &mut [0u8; 16]; 235 let rx_buf = &mut [0u8; 16];
209 let mut uart = BufferedUartRx::new(&mut uart, Irqs, &mut rx, rx_buf, config); 236 let mut uart = BufferedUartRx::new(uart.reborrow(), Irqs, rx.reborrow(), rx_buf, config);
210 237
211 async fn chr(pin: &mut Output<'_>, v: u8, good: bool) { 238 async fn chr(pin: &mut Output<'_>, v: u8, good: bool) {
212 if good { 239 if good {
diff --git a/tests/rp/src/bin/uart_dma.rs b/tests/rp/src/bin/uart_dma.rs
index edc87175a..a7af81f5f 100644
--- a/tests/rp/src/bin/uart_dma.rs
+++ b/tests/rp/src/bin/uart_dma.rs
@@ -1,13 +1,16 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3#[cfg(feature = "rp2040")]
3teleprobe_meta::target!(b"rpi-pico"); 4teleprobe_meta::target!(b"rpi-pico");
5#[cfg(feature = "rp235xb")]
6teleprobe_meta::target!(b"pimoroni-pico-plus-2");
4 7
5use defmt::{assert_eq, *}; 8use defmt::{assert_eq, *};
6use embassy_executor::Spawner; 9use embassy_executor::Spawner;
7use embassy_rp::bind_interrupts; 10use embassy_rp::bind_interrupts;
8use embassy_rp::gpio::{Level, Output}; 11use embassy_rp::gpio::{Level, Output};
9use embassy_rp::peripherals::UART0; 12use embassy_rp::peripherals::UART0;
10use embassy_rp::uart::{Async, Config, Error, Instance, InterruptHandler, Parity, Uart, UartRx}; 13use embassy_rp::uart::{Async, Config, Error, InterruptHandler, Parity, Uart, UartRx};
11use embassy_time::Timer; 14use embassy_time::Timer;
12use {defmt_rtt as _, panic_probe as _}; 15use {defmt_rtt as _, panic_probe as _};
13 16
@@ -15,13 +18,13 @@ bind_interrupts!(struct Irqs {
15 UART0_IRQ => InterruptHandler<UART0>; 18 UART0_IRQ => InterruptHandler<UART0>;
16}); 19});
17 20
18async fn read<const N: usize>(uart: &mut Uart<'_, impl Instance, Async>) -> Result<[u8; N], Error> { 21async fn read<const N: usize>(uart: &mut Uart<'_, Async>) -> Result<[u8; N], Error> {
19 let mut buf = [255; N]; 22 let mut buf = [255; N];
20 uart.read(&mut buf).await?; 23 uart.read(&mut buf).await?;
21 Ok(buf) 24 Ok(buf)
22} 25}
23 26
24async fn read1<const N: usize>(uart: &mut UartRx<'_, impl Instance, Async>) -> Result<[u8; N], Error> { 27async fn read1<const N: usize>(uart: &mut UartRx<'_, Async>) -> Result<[u8; N], Error> {
25 let mut buf = [255; N]; 28 let mut buf = [255; N];
26 uart.read(&mut buf).await?; 29 uart.read(&mut buf).await?;
27 Ok(buf) 30 Ok(buf)
@@ -62,12 +65,12 @@ async fn main(_spawner: Spawner) {
62 { 65 {
63 let config = Config::default(); 66 let config = Config::default();
64 let mut uart = Uart::new( 67 let mut uart = Uart::new(
65 &mut uart, 68 uart.reborrow(),
66 &mut tx, 69 tx.reborrow(),
67 &mut rx, 70 rx.reborrow(),
68 Irqs, 71 Irqs,
69 &mut p.DMA_CH0, 72 p.DMA_CH0.reborrow(),
70 &mut p.DMA_CH1, 73 p.DMA_CH1.reborrow(),
71 config, 74 config,
72 ); 75 );
73 76
@@ -83,12 +86,12 @@ async fn main(_spawner: Spawner) {
83 { 86 {
84 let config = Config::default(); 87 let config = Config::default();
85 let mut uart = Uart::new( 88 let mut uart = Uart::new(
86 &mut uart, 89 uart.reborrow(),
87 &mut tx, 90 tx.reborrow(),
88 &mut rx, 91 rx.reborrow(),
89 Irqs, 92 Irqs,
90 &mut p.DMA_CH0, 93 p.DMA_CH0.reborrow(),
91 &mut p.DMA_CH1, 94 p.DMA_CH1.reborrow(),
92 config, 95 config,
93 ); 96 );
94 97
@@ -112,12 +115,12 @@ async fn main(_spawner: Spawner) {
112 { 115 {
113 let config = Config::default(); 116 let config = Config::default();
114 let (mut tx, mut rx) = Uart::new( 117 let (mut tx, mut rx) = Uart::new(
115 &mut uart, 118 uart.reborrow(),
116 &mut tx, 119 tx.reborrow(),
117 &mut rx, 120 rx.reborrow(),
118 Irqs, 121 Irqs,
119 &mut p.DMA_CH0, 122 p.DMA_CH0.reborrow(),
120 &mut p.DMA_CH1, 123 p.DMA_CH1.reborrow(),
121 config, 124 config,
122 ) 125 )
123 .split(); 126 .split();
@@ -153,12 +156,12 @@ async fn main(_spawner: Spawner) {
153 // parity detection. here we bitbang to not require two uarts. 156 // parity detection. here we bitbang to not require two uarts.
154 info!("test parity error detection"); 157 info!("test parity error detection");
155 { 158 {
156 let mut pin = Output::new(&mut tx, Level::High); 159 let mut pin = Output::new(tx.reborrow(), Level::High);
157 // choose a very slow baud rate to make tests reliable even with O0 160 // choose a very slow baud rate to make tests reliable even with O0
158 let mut config = Config::default(); 161 let mut config = Config::default();
159 config.baudrate = 1000; 162 config.baudrate = 1000;
160 config.parity = Parity::ParityEven; 163 config.parity = Parity::ParityEven;
161 let mut uart = UartRx::new(&mut uart, &mut rx, Irqs, &mut p.DMA_CH0, config); 164 let mut uart = UartRx::new(uart.reborrow(), rx.reborrow(), Irqs, p.DMA_CH0.reborrow(), config);
162 165
163 async fn chr(pin: &mut Output<'_>, v: u8, parity: u32) { 166 async fn chr(pin: &mut Output<'_>, v: u8, parity: u32) {
164 send(pin, v, Some(parity != 0)).await; 167 send(pin, v, Some(parity != 0)).await;
@@ -199,11 +202,11 @@ async fn main(_spawner: Spawner) {
199 // framing error detection. here we bitbang because there's no other way. 202 // framing error detection. here we bitbang because there's no other way.
200 info!("test framing error detection"); 203 info!("test framing error detection");
201 { 204 {
202 let mut pin = Output::new(&mut tx, Level::High); 205 let mut pin = Output::new(tx.reborrow(), Level::High);
203 // choose a very slow baud rate to make tests reliable even with O0 206 // choose a very slow baud rate to make tests reliable even with O0
204 let mut config = Config::default(); 207 let mut config = Config::default();
205 config.baudrate = 1000; 208 config.baudrate = 1000;
206 let mut uart = UartRx::new(&mut uart, &mut rx, Irqs, &mut p.DMA_CH0, config); 209 let mut uart = UartRx::new(uart.reborrow(), rx.reborrow(), Irqs, p.DMA_CH0.reborrow(), config);
207 210
208 async fn chr(pin: &mut Output<'_>, v: u8, good: bool) { 211 async fn chr(pin: &mut Output<'_>, v: u8, good: bool) {
209 if good { 212 if good {
diff --git a/tests/rp/src/bin/uart_upgrade.rs b/tests/rp/src/bin/uart_upgrade.rs
index 603e20f2f..f658b6b8c 100644
--- a/tests/rp/src/bin/uart_upgrade.rs
+++ b/tests/rp/src/bin/uart_upgrade.rs
@@ -1,6 +1,9 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3#[cfg(feature = "rp2040")]
3teleprobe_meta::target!(b"rpi-pico"); 4teleprobe_meta::target!(b"rpi-pico");
5#[cfg(feature = "rp235xb")]
6teleprobe_meta::target!(b"pimoroni-pico-plus-2");
4 7
5use defmt::{assert_eq, *}; 8use defmt::{assert_eq, *};
6use embassy_executor::Spawner; 9use embassy_executor::Spawner;
diff --git a/tests/stm32/.cargo/config.toml b/tests/stm32/.cargo/config.toml
index 8752da59b..d94342598 100644
--- a/tests/stm32/.cargo/config.toml
+++ b/tests/stm32/.cargo/config.toml
@@ -9,7 +9,6 @@ runner = "teleprobe client run"
9rustflags = [ 9rustflags = [
10 # Code-size optimizations. 10 # Code-size optimizations.
11 #"-Z", "trap-unreachable=no", 11 #"-Z", "trap-unreachable=no",
12 "-C", "inline-threshold=5",
13 "-C", "no-vectorize-loops", 12 "-C", "no-vectorize-loops",
14] 13]
15 14
diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml
index 2eac636e5..8d10f6593 100644
--- a/tests/stm32/Cargo.toml
+++ b/tests/stm32/Cargo.toml
@@ -12,19 +12,19 @@ stm32f207zg = ["embassy-stm32/stm32f207zg", "spi-v1", "chrono", "not-gpdma", "et
12stm32f303ze = ["embassy-stm32/stm32f303ze", "chrono", "not-gpdma"] 12stm32f303ze = ["embassy-stm32/stm32f303ze", "chrono", "not-gpdma"]
13stm32f429zi = ["embassy-stm32/stm32f429zi", "spi-v1", "chrono", "eth", "stop", "can", "not-gpdma", "dac", "rng"] 13stm32f429zi = ["embassy-stm32/stm32f429zi", "spi-v1", "chrono", "eth", "stop", "can", "not-gpdma", "dac", "rng"]
14stm32f446re = ["embassy-stm32/stm32f446re", "spi-v1", "chrono", "stop", "can", "not-gpdma", "dac", "sdmmc"] 14stm32f446re = ["embassy-stm32/stm32f446re", "spi-v1", "chrono", "stop", "can", "not-gpdma", "dac", "sdmmc"]
15stm32f767zi = ["embassy-stm32/stm32f767zi", "chrono", "not-gpdma", "eth", "rng"] 15stm32f767zi = ["embassy-stm32/stm32f767zi", "chrono", "not-gpdma", "eth", "rng", "single-bank"]
16stm32g071rb = ["embassy-stm32/stm32g071rb", "cm0", "not-gpdma", "dac", "ucpd"] 16stm32g071rb = ["embassy-stm32/stm32g071rb", "cm0", "not-gpdma", "dac", "ucpd"]
17stm32g491re = ["embassy-stm32/stm32g491re", "chrono", "stop", "not-gpdma", "rng", "fdcan", "cordic"] 17stm32g491re = ["embassy-stm32/stm32g491re", "chrono", "stop", "not-gpdma", "rng", "fdcan", "cordic"]
18stm32h563zi = ["embassy-stm32/stm32h563zi", "spi-v345", "chrono", "eth", "rng", "fdcan", "hash", "cordic", "stop"] 18stm32h563zi = ["embassy-stm32/stm32h563zi", "spi-v345", "chrono", "eth", "rng", "fdcan", "hash", "cordic", "stop"]
19stm32h753zi = ["embassy-stm32/stm32h753zi", "spi-v345", "chrono", "not-gpdma", "eth", "rng", "fdcan", "hash", "cryp"] 19stm32h753zi = ["embassy-stm32/stm32h753zi", "spi-v345", "chrono", "not-gpdma", "eth", "rng", "fdcan", "hash", "cryp"]
20stm32h755zi = ["embassy-stm32/stm32h755zi-cm7", "spi-v345", "chrono", "not-gpdma", "eth", "dac", "rng", "fdcan", "hash", "cryp"] 20stm32h755zi = ["embassy-stm32/stm32h755zi-cm7", "spi-v345", "chrono", "not-gpdma", "eth", "dac", "rng", "fdcan", "hash", "cryp"]
21stm32h7a3zi = ["embassy-stm32/stm32h7a3zi", "spi-v345", "not-gpdma", "rng", "fdcan"] 21stm32h7a3zi = ["embassy-stm32/stm32h7a3zi", "spi-v345", "not-gpdma", "rng", "fdcan"]
22stm32l073rz = ["embassy-stm32/stm32l073rz", "cm0", "not-gpdma", "rng"] 22stm32l073rz = ["embassy-stm32/stm32l073rz", "cm0", "not-gpdma", "rng", "eeprom"]
23stm32l152re = ["embassy-stm32/stm32l152re", "spi-v1", "chrono", "not-gpdma"] 23stm32l152re = ["embassy-stm32/stm32l152re", "spi-v1", "chrono", "not-gpdma", "eeprom"]
24stm32l496zg = ["embassy-stm32/stm32l496zg", "not-gpdma", "rng"] 24stm32l496zg = ["embassy-stm32/stm32l496zg", "not-gpdma", "rng"]
25stm32l4a6zg = ["embassy-stm32/stm32l4a6zg", "chrono", "not-gpdma", "rng", "hash"] 25stm32l4a6zg = ["embassy-stm32/stm32l4a6zg", "chrono", "not-gpdma", "rng", "hash"]
26stm32l4r5zi = ["embassy-stm32/stm32l4r5zi", "chrono", "not-gpdma", "rng"] 26stm32l4r5zi = ["embassy-stm32/stm32l4r5zi", "chrono", "not-gpdma", "rng", "dual-bank"]
27stm32l552ze = ["embassy-stm32/stm32l552ze", "not-gpdma", "rng", "hash"] 27stm32l552ze = ["embassy-stm32/stm32l552ze", "not-gpdma", "rng", "hash", "dual-bank"]
28stm32u585ai = ["embassy-stm32/stm32u585ai", "spi-v345", "chrono", "rng", "hash", "cordic"] 28stm32u585ai = ["embassy-stm32/stm32u585ai", "spi-v345", "chrono", "rng", "hash", "cordic"]
29stm32u5a5zj = ["embassy-stm32/stm32u5a5zj", "spi-v345", "chrono", "rng", "hash"] # FIXME: cordic test cause it crash 29stm32u5a5zj = ["embassy-stm32/stm32u5a5zj", "spi-v345", "chrono", "rng", "hash"] # FIXME: cordic test cause it crash
30stm32wb55rg = ["embassy-stm32/stm32wb55rg", "chrono", "not-gpdma", "ble", "mac" , "rng"] 30stm32wb55rg = ["embassy-stm32/stm32wb55rg", "chrono", "not-gpdma", "ble", "mac" , "rng"]
@@ -39,7 +39,7 @@ spi-v1 = []
39spi-v345 = [] 39spi-v345 = []
40cryp = [] 40cryp = []
41hash = [] 41hash = []
42eth = ["embassy-executor/task-arena-size-16384"] 42eth = []
43rng = [] 43rng = []
44sdmmc = [] 44sdmmc = []
45stop = ["embassy-stm32/low-power", "embassy-stm32/low-power-debug-with-sleep"] 45stop = ["embassy-stm32/low-power", "embassy-stm32/low-power-debug-with-sleep"]
@@ -53,23 +53,26 @@ not-gpdma = []
53dac = [] 53dac = []
54ucpd = [] 54ucpd = []
55cordic = ["dep:num-traits"] 55cordic = ["dep:num-traits"]
56dual-bank = ["embassy-stm32/dual-bank"]
57single-bank = ["embassy-stm32/single-bank"]
58eeprom = []
56 59
57cm0 = ["portable-atomic/unsafe-assume-single-core"] 60cm0 = ["portable-atomic/unsafe-assume-single-core"]
58 61
59[dependencies] 62[dependencies]
60teleprobe-meta = "1" 63teleprobe-meta = "1"
61 64
62embassy-sync = { version = "0.6.0", path = "../../embassy-sync", features = ["defmt"] } 65embassy-sync = { version = "0.7.0", path = "../../embassy-sync", features = ["defmt"] }
63embassy-executor = { version = "0.6.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 66embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt"] }
64embassy-time = { version = "0.3.2", path = "../../embassy-time", features = ["defmt", "tick-hz-131_072", "defmt-timestamp-uptime"] } 67embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt", "tick-hz-131_072", "defmt-timestamp-uptime"] }
65embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "unstable-pac", "memory-x", "time-driver-any"] } 68embassy-stm32 = { version = "0.2.0", path = "../../embassy-stm32", features = [ "defmt", "unstable-pac", "memory-x", "time-driver-any"] }
66embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } 69embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
67embassy-stm32-wpan = { version = "0.1.0", path = "../../embassy-stm32-wpan", optional = true, features = ["defmt", "stm32wb55rg", "ble"] } 70embassy-stm32-wpan = { version = "0.1.0", path = "../../embassy-stm32-wpan", optional = true, features = ["defmt", "stm32wb55rg", "ble"] }
68embassy-net = { version = "0.4.0", path = "../../embassy-net", features = ["defmt", "tcp", "udp", "dhcpv4", "medium-ethernet"] } 71embassy-net = { version = "0.7.0", path = "../../embassy-net", features = ["defmt", "tcp", "udp", "dhcpv4", "medium-ethernet"] }
69perf-client = { path = "../perf-client" } 72perf-client = { path = "../perf-client" }
70 73
71defmt = "0.3.0" 74defmt = "1.0.1"
72defmt-rtt = "0.4" 75defmt-rtt = "1.0.0"
73 76
74cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } 77cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
75cortex-m-rt = "0.7.0" 78cortex-m-rt = "0.7.0"
@@ -78,17 +81,17 @@ embedded-hal-1 = { package = "embedded-hal", version = "1.0" }
78embedded-hal-async = { version = "1.0" } 81embedded-hal-async = { version = "1.0" }
79embedded-can = { version = "0.4" } 82embedded-can = { version = "0.4" }
80micromath = "2.0.0" 83micromath = "2.0.0"
81panic-probe = { version = "0.3.0", features = ["print-defmt"] } 84panic-probe = { version = "1.0.0", features = ["print-defmt"] }
82rand_core = { version = "0.6", default-features = false } 85rand_core = { version = "0.9.1", default-features = false }
83rand_chacha = { version = "0.3", default-features = false } 86rand_chacha = { version = "0.9.0", default-features = false }
84static_cell = "2" 87static_cell = "2"
85portable-atomic = { version = "1.5", features = [] } 88portable-atomic = { version = "1.5", features = [] }
86 89
87chrono = { version = "^0.4", default-features = false, optional = true} 90chrono = { version = "^0.4", default-features = false, optional = true}
88sha2 = { version = "0.10.8", default-features = false } 91sha2 = { version = "0.10.8", default-features = false }
89hmac = "0.12.1" 92hmac = "0.12.1"
90aes-gcm = {version = "0.10.3", default-features = false, features = ["aes", "heapless"] } 93aes-gcm = { version = "0.10.3", default-features = false, features = ["aes", "heapless"] }
91num-traits = {version="0.2", default-features = false,features = ["libm"], optional = true} 94num-traits = { version="0.2", default-features = false,features = ["libm"], optional = true}
92 95
93# BEGIN TESTS 96# BEGIN TESTS
94# Generated by gen_test.py. DO NOT EDIT. 97# Generated by gen_test.py. DO NOT EDIT.
@@ -118,6 +121,11 @@ path = "src/bin/dac_l1.rs"
118required-features = [ "stm32l152re",] 121required-features = [ "stm32l152re",]
119 122
120[[bin]] 123[[bin]]
124name = "eeprom"
125path = "src/bin/eeprom.rs"
126required-features = [ "eeprom",]
127
128[[bin]]
121name = "eth" 129name = "eth"
122path = "src/bin/eth.rs" 130path = "src/bin/eth.rs"
123required-features = [ "eth",] 131required-features = [ "eth",]
diff --git a/tests/stm32/src/bin/can.rs b/tests/stm32/src/bin/can.rs
index 85a5f8d83..778d88a7b 100644
--- a/tests/stm32/src/bin/can.rs
+++ b/tests/stm32/src/bin/can.rs
@@ -43,7 +43,7 @@ async fn main(_spawner: Spawner) {
43 // To synchronise to the bus the RX input needs to see a high level. 43 // To synchronise to the bus the RX input needs to see a high level.
44 // Use `mem::forget()` to release the borrow on the pin but keep the 44 // Use `mem::forget()` to release the borrow on the pin but keep the
45 // pull-up resistor enabled. 45 // pull-up resistor enabled.
46 let rx_pin = Input::new(&mut rx, Pull::Up); 46 let rx_pin = Input::new(rx.reborrow(), Pull::Up);
47 core::mem::forget(rx_pin); 47 core::mem::forget(rx_pin);
48 48
49 let mut can = embassy_stm32::can::Can::new(can, rx, tx, Irqs); 49 let mut can = embassy_stm32::can::Can::new(can, rx, tx, Irqs);
diff --git a/tests/stm32/src/bin/cordic.rs b/tests/stm32/src/bin/cordic.rs
index 879ad56b6..e86eea58b 100644
--- a/tests/stm32/src/bin/cordic.rs
+++ b/tests/stm32/src/bin/cordic.rs
@@ -82,8 +82,8 @@ async fn main(_spawner: Spawner) {
82 let cnt1 = defmt::unwrap!( 82 let cnt1 = defmt::unwrap!(
83 cordic 83 cordic
84 .async_calc_32bit( 84 .async_calc_32bit(
85 &mut write_dma, 85 write_dma.reborrow(),
86 &mut read_dma, 86 read_dma.reborrow(),
87 &input_q1_31[2..], 87 &input_q1_31[2..],
88 &mut output_q1_31[cnt0..], 88 &mut output_q1_31[cnt0..],
89 true, 89 true,
diff --git a/tests/stm32/src/bin/dac.rs b/tests/stm32/src/bin/dac.rs
index 88e661525..d34bbb255 100644
--- a/tests/stm32/src/bin/dac.rs
+++ b/tests/stm32/src/bin/dac.rs
@@ -12,7 +12,6 @@ use defmt::assert;
12use embassy_executor::Spawner; 12use embassy_executor::Spawner;
13use embassy_stm32::adc::Adc; 13use embassy_stm32::adc::Adc;
14use embassy_stm32::dac::{DacCh1, Value}; 14use embassy_stm32::dac::{DacCh1, Value};
15use embassy_stm32::dma::NoDma;
16use embassy_time::Timer; 15use embassy_time::Timer;
17use micromath::F32Ext; 16use micromath::F32Ext;
18use {defmt_rtt as _, panic_probe as _}; 17use {defmt_rtt as _, panic_probe as _};
@@ -27,7 +26,7 @@ async fn main(_spawner: Spawner) {
27 let dac_pin = peri!(p, DAC_PIN); 26 let dac_pin = peri!(p, DAC_PIN);
28 let mut adc_pin = unsafe { core::ptr::read(&dac_pin) }; 27 let mut adc_pin = unsafe { core::ptr::read(&dac_pin) };
29 28
30 let mut dac = DacCh1::new(dac, NoDma, dac_pin); 29 let mut dac = DacCh1::new_blocking(dac, dac_pin);
31 let mut adc = Adc::new(adc); 30 let mut adc = Adc::new(adc);
32 31
33 #[cfg(feature = "stm32h755zi")] 32 #[cfg(feature = "stm32h755zi")]
diff --git a/tests/stm32/src/bin/dac_l1.rs b/tests/stm32/src/bin/dac_l1.rs
index 925db617d..e6400f28e 100644
--- a/tests/stm32/src/bin/dac_l1.rs
+++ b/tests/stm32/src/bin/dac_l1.rs
@@ -12,7 +12,6 @@ use defmt::assert;
12use embassy_executor::Spawner; 12use embassy_executor::Spawner;
13use embassy_stm32::adc::Adc; 13use embassy_stm32::adc::Adc;
14use embassy_stm32::dac::{DacCh1, Value}; 14use embassy_stm32::dac::{DacCh1, Value};
15use embassy_stm32::dma::NoDma;
16use embassy_stm32::{bind_interrupts, peripherals}; 15use embassy_stm32::{bind_interrupts, peripherals};
17use embassy_time::Timer; 16use embassy_time::Timer;
18use micromath::F32Ext; 17use micromath::F32Ext;
@@ -32,7 +31,7 @@ async fn main(_spawner: Spawner) {
32 let dac_pin = peri!(p, DAC_PIN); 31 let dac_pin = peri!(p, DAC_PIN);
33 let mut adc_pin = unsafe { core::ptr::read(&dac_pin) }; 32 let mut adc_pin = unsafe { core::ptr::read(&dac_pin) };
34 33
35 let mut dac = DacCh1::new(dac, NoDma, dac_pin); 34 let mut dac = DacCh1::new_blocking(dac, dac_pin);
36 let mut adc = Adc::new(adc, Irqs); 35 let mut adc = Adc::new(adc, Irqs);
37 36
38 #[cfg(feature = "stm32h755zi")] 37 #[cfg(feature = "stm32h755zi")]
diff --git a/tests/stm32/src/bin/eeprom.rs b/tests/stm32/src/bin/eeprom.rs
new file mode 100644
index 000000000..61d249fd7
--- /dev/null
+++ b/tests/stm32/src/bin/eeprom.rs
@@ -0,0 +1,30 @@
1#![no_std]
2#![no_main]
3
4// required-features: eeprom
5
6#[path = "../common.rs"]
7mod common;
8
9use common::*;
10use defmt::assert_eq;
11use embassy_executor::Spawner;
12use embassy_stm32::flash::Flash;
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 mut f = Flash::new_blocking(p.FLASH);
21 const ADDR: u32 = 0x0;
22
23 unwrap!(f.eeprom_write_slice(ADDR, &[1, 2, 3, 4, 5, 6, 7, 8]));
24 let mut buf = [0u8; 8];
25 unwrap!(f.eeprom_read_slice(ADDR, &mut buf));
26 assert_eq!(&buf[..], &[1, 2, 3, 4, 5, 6, 7, 8]);
27
28 info!("Test OK");
29 cortex_m::asm::bkpt();
30}
diff --git a/tests/stm32/src/bin/eth.rs b/tests/stm32/src/bin/eth.rs
index 9da514881..bcb362b42 100644
--- a/tests/stm32/src/bin/eth.rs
+++ b/tests/stm32/src/bin/eth.rs
@@ -6,13 +6,11 @@
6mod common; 6mod common;
7use common::*; 7use common::*;
8use embassy_executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_net::{Stack, StackResources}; 9use embassy_net::StackResources;
10use embassy_stm32::eth::generic_smi::GenericSMI; 10use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue};
11use embassy_stm32::eth::{Ethernet, PacketQueue};
12use embassy_stm32::peripherals::ETH; 11use embassy_stm32::peripherals::ETH;
13use embassy_stm32::rng::Rng; 12use embassy_stm32::rng::Rng;
14use embassy_stm32::{bind_interrupts, eth, peripherals, rng}; 13use embassy_stm32::{bind_interrupts, eth, peripherals, rng};
15use rand_core::RngCore;
16use static_cell::StaticCell; 14use static_cell::StaticCell;
17use {defmt_rtt as _, panic_probe as _}; 15use {defmt_rtt as _, panic_probe as _};
18 16
@@ -29,11 +27,11 @@ bind_interrupts!(struct Irqs {
29 RNG => rng::InterruptHandler<peripherals::RNG>; 27 RNG => rng::InterruptHandler<peripherals::RNG>;
30}); 28});
31 29
32type Device = Ethernet<'static, ETH, GenericSMI>; 30type Device = Ethernet<'static, ETH, GenericPhy>;
33 31
34#[embassy_executor::task] 32#[embassy_executor::task]
35async fn net_task(stack: &'static Stack<Device>) -> ! { 33async fn net_task(mut runner: embassy_net::Runner<'static, Device>) -> ! {
36 stack.run().await 34 runner.run().await
37} 35}
38 36
39#[embassy_executor::main] 37#[embassy_executor::main]
@@ -87,7 +85,7 @@ async fn main(spawner: Spawner) {
87 #[cfg(feature = "stm32h563zi")] 85 #[cfg(feature = "stm32h563zi")]
88 p.PB15, 86 p.PB15,
89 p.PG11, 87 p.PG11,
90 GenericSMI::new(0), 88 GenericPhy::new_auto(),
91 mac_addr, 89 mac_addr,
92 ); 90 );
93 91
@@ -99,12 +97,11 @@ async fn main(spawner: Spawner) {
99 //}); 97 //});
100 98
101 // Init network stack 99 // Init network stack
102 static STACK: StaticCell<Stack<Device>> = StaticCell::new();
103 static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new(); 100 static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
104 let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed)); 101 let (stack, runner) = embassy_net::new(device, config, RESOURCES.init(StackResources::new()), seed);
105 102
106 // Launch network task 103 // Launch network task
107 unwrap!(spawner.spawn(net_task(&stack))); 104 unwrap!(spawner.spawn(net_task(runner)));
108 105
109 perf_client::run( 106 perf_client::run(
110 stack, 107 stack,
diff --git a/tests/stm32/src/bin/gpio.rs b/tests/stm32/src/bin/gpio.rs
index 4a2584b4e..40b03201c 100644
--- a/tests/stm32/src/bin/gpio.rs
+++ b/tests/stm32/src/bin/gpio.rs
@@ -20,10 +20,10 @@ async fn main(_spawner: Spawner) {
20 20
21 // Test initial output 21 // Test initial output
22 { 22 {
23 let b = Input::new(&mut b, Pull::None); 23 let b = Input::new(b.reborrow(), Pull::None);
24 24
25 { 25 {
26 let a = Output::new(&mut a, Level::Low, Speed::Low); 26 let a = Output::new(a.reborrow(), Level::Low, Speed::Low);
27 delay(); 27 delay();
28 assert!(b.is_low()); 28 assert!(b.is_low());
29 assert!(!b.is_high()); 29 assert!(!b.is_high());
@@ -31,7 +31,7 @@ async fn main(_spawner: Spawner) {
31 assert!(!a.is_set_high()); 31 assert!(!a.is_set_high());
32 } 32 }
33 { 33 {
34 let mut a = Output::new(&mut a, Level::High, Speed::Low); 34 let mut a = Output::new(a.reborrow(), Level::High, Speed::Low);
35 delay(); 35 delay();
36 assert!(!b.is_low()); 36 assert!(!b.is_low());
37 assert!(b.is_high()); 37 assert!(b.is_high());
@@ -68,10 +68,10 @@ async fn main(_spawner: Spawner) {
68 68
69 // Test input no pull 69 // Test input no pull
70 { 70 {
71 let b = Input::new(&mut b, Pull::None); 71 let b = Input::new(b.reborrow(), Pull::None);
72 // no pull, the status is undefined 72 // no pull, the status is undefined
73 73
74 let mut a = Output::new(&mut a, Level::Low, Speed::Low); 74 let mut a = Output::new(a.reborrow(), Level::Low, Speed::Low);
75 delay(); 75 delay();
76 assert!(b.is_low()); 76 assert!(b.is_low());
77 a.set_high(); 77 a.set_high();
@@ -81,11 +81,11 @@ async fn main(_spawner: Spawner) {
81 81
82 // Test input pulldown 82 // Test input pulldown
83 { 83 {
84 let b = Input::new(&mut b, Pull::Down); 84 let b = Input::new(b.reborrow(), Pull::Down);
85 delay(); 85 delay();
86 assert!(b.is_low()); 86 assert!(b.is_low());
87 87
88 let mut a = Output::new(&mut a, Level::Low, Speed::Low); 88 let mut a = Output::new(a.reborrow(), Level::Low, Speed::Low);
89 delay(); 89 delay();
90 assert!(b.is_low()); 90 assert!(b.is_low());
91 a.set_high(); 91 a.set_high();
@@ -95,11 +95,11 @@ async fn main(_spawner: Spawner) {
95 95
96 // Test input pullup 96 // Test input pullup
97 { 97 {
98 let b = Input::new(&mut b, Pull::Up); 98 let b = Input::new(b.reborrow(), Pull::Up);
99 delay(); 99 delay();
100 assert!(b.is_high()); 100 assert!(b.is_high());
101 101
102 let mut a = Output::new(&mut a, Level::Low, Speed::Low); 102 let mut a = Output::new(a.reborrow(), Level::Low, Speed::Low);
103 delay(); 103 delay();
104 assert!(b.is_low()); 104 assert!(b.is_low());
105 a.set_high(); 105 a.set_high();
@@ -109,10 +109,10 @@ async fn main(_spawner: Spawner) {
109 109
110 // Test output open drain 110 // Test output open drain
111 { 111 {
112 let b = Input::new(&mut b, Pull::Down); 112 let b = Input::new(b.reborrow(), Pull::Down);
113 // no pull, the status is undefined 113 // no pull, the status is undefined
114 114
115 let mut a = OutputOpenDrain::new(&mut a, Level::Low, Speed::Low); 115 let mut a = OutputOpenDrain::new(a.reborrow(), Level::Low, Speed::Low);
116 delay(); 116 delay();
117 assert!(b.is_low()); 117 assert!(b.is_low());
118 a.set_high(); // High-Z output 118 a.set_high(); // High-Z output
@@ -124,12 +124,12 @@ async fn main(_spawner: Spawner) {
124 // Test initial output 124 // Test initial output
125 { 125 {
126 //Flex pin configured as input 126 //Flex pin configured as input
127 let mut b = Flex::new(&mut b); 127 let mut b = Flex::new(b.reborrow());
128 b.set_as_input(Pull::None); 128 b.set_as_input(Pull::None);
129 129
130 { 130 {
131 //Flex pin configured as output 131 //Flex pin configured as output
132 let mut a = Flex::new(&mut a); //Flex pin configured as output 132 let mut a = Flex::new(a.reborrow()); //Flex pin configured as output
133 a.set_low(); // Pin state must be set before configuring the pin, thus we avoid unknown state 133 a.set_low(); // Pin state must be set before configuring the pin, thus we avoid unknown state
134 a.set_as_output(Speed::Low); 134 a.set_as_output(Speed::Low);
135 delay(); 135 delay();
@@ -137,7 +137,7 @@ async fn main(_spawner: Spawner) {
137 } 137 }
138 { 138 {
139 //Flex pin configured as output 139 //Flex pin configured as output
140 let mut a = Flex::new(&mut a); 140 let mut a = Flex::new(a.reborrow());
141 a.set_high(); 141 a.set_high();
142 a.set_as_output(Speed::Low); 142 a.set_as_output(Speed::Low);
143 143
@@ -148,10 +148,10 @@ async fn main(_spawner: Spawner) {
148 148
149 // Test input no pull 149 // Test input no pull
150 { 150 {
151 let mut b = Flex::new(&mut b); 151 let mut b = Flex::new(b.reborrow());
152 b.set_as_input(Pull::None); // no pull, the status is undefined 152 b.set_as_input(Pull::None); // no pull, the status is undefined
153 153
154 let mut a = Flex::new(&mut a); 154 let mut a = Flex::new(a.reborrow());
155 a.set_low(); 155 a.set_low();
156 a.set_as_output(Speed::Low); 156 a.set_as_output(Speed::Low);
157 157
@@ -164,12 +164,12 @@ async fn main(_spawner: Spawner) {
164 164
165 // Test input pulldown 165 // Test input pulldown
166 { 166 {
167 let mut b = Flex::new(&mut b); 167 let mut b = Flex::new(b.reborrow());
168 b.set_as_input(Pull::Down); 168 b.set_as_input(Pull::Down);
169 delay(); 169 delay();
170 assert!(b.is_low()); 170 assert!(b.is_low());
171 171
172 let mut a = Flex::new(&mut a); 172 let mut a = Flex::new(a.reborrow());
173 a.set_low(); 173 a.set_low();
174 a.set_as_output(Speed::Low); 174 a.set_as_output(Speed::Low);
175 delay(); 175 delay();
@@ -181,12 +181,12 @@ async fn main(_spawner: Spawner) {
181 181
182 // Test input pullup 182 // Test input pullup
183 { 183 {
184 let mut b = Flex::new(&mut b); 184 let mut b = Flex::new(b.reborrow());
185 b.set_as_input(Pull::Up); 185 b.set_as_input(Pull::Up);
186 delay(); 186 delay();
187 assert!(b.is_high()); 187 assert!(b.is_high());
188 188
189 let mut a = Flex::new(&mut a); 189 let mut a = Flex::new(a.reborrow());
190 a.set_high(); 190 a.set_high();
191 a.set_as_output(Speed::Low); 191 a.set_as_output(Speed::Low);
192 delay(); 192 delay();
@@ -198,10 +198,10 @@ async fn main(_spawner: Spawner) {
198 198
199 // Test output open drain 199 // Test output open drain
200 { 200 {
201 let mut b = Flex::new(&mut b); 201 let mut b = Flex::new(b.reborrow());
202 b.set_as_input(Pull::Down); 202 b.set_as_input(Pull::Down);
203 203
204 let mut a = Flex::new(&mut a); 204 let mut a = Flex::new(a.reborrow());
205 a.set_low(); 205 a.set_low();
206 a.set_as_input_output(Speed::Low); 206 a.set_as_input_output(Speed::Low);
207 delay(); 207 delay();
diff --git a/tests/stm32/src/bin/hash.rs b/tests/stm32/src/bin/hash.rs
index bdb3c9a69..52b84a499 100644
--- a/tests/stm32/src/bin/hash.rs
+++ b/tests/stm32/src/bin/hash.rs
@@ -6,7 +6,6 @@
6mod common; 6mod common;
7use common::*; 7use common::*;
8use embassy_executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_stm32::dma::NoDma;
10use embassy_stm32::hash::*; 9use embassy_stm32::hash::*;
11use embassy_stm32::{bind_interrupts, hash, peripherals}; 10use embassy_stm32::{bind_interrupts, hash, peripherals};
12use hmac::{Hmac, Mac}; 11use hmac::{Hmac, Mac};
@@ -36,7 +35,7 @@ bind_interrupts!(struct Irqs {
36#[embassy_executor::main] 35#[embassy_executor::main]
37async fn main(_spawner: Spawner) { 36async fn main(_spawner: Spawner) {
38 let p: embassy_stm32::Peripherals = init(); 37 let p: embassy_stm32::Peripherals = init();
39 let mut hw_hasher = Hash::new(p.HASH, NoDma, Irqs); 38 let mut hw_hasher = Hash::new_blocking(p.HASH, Irqs);
40 39
41 let test_1: &[u8] = b"as;dfhaslfhas;oifvnasd;nifvnhasd;nifvhndlkfghsd;nvfnahssdfgsdafgsasdfasdfasdfasdfasdfghjklmnbvcalskdjghalskdjgfbaslkdjfgbalskdjgbalskdjbdfhsdfhsfghsfghfgh"; 40 let test_1: &[u8] = b"as;dfhaslfhas;oifvnasd;nifvnhasd;nifvhndlkfghsd;nvfnahssdfgsdafgsasdfasdfasdfasdfasdfghjklmnbvcalskdjghalskdjgfbaslkdjfgbalskdjgbalskdjbdfhsdfhsfghsfghfgh";
42 let test_2: &[u8] = b"fdhalksdjfhlasdjkfhalskdjfhgal;skdjfgalskdhfjgalskdjfglafgadfgdfgdafgaadsfgfgdfgadrgsyfthxfgjfhklhjkfgukhulkvhlvhukgfhfsrghzdhxyfufynufyuszeradrtydyytserr"; 41 let test_2: &[u8] = b"fdhalksdjfhlasdjkfhalskdjfhgal;skdjfgalskdhfjgalskdjfglafgadfgdfgdafgaadsfgfgdfgadrgsyfthxfgjfhklhjkfgukhulkvhlvhukgfhfsrghzdhxyfufynufyuszeradrtydyytserr";
diff --git a/tests/stm32/src/bin/sdmmc.rs b/tests/stm32/src/bin/sdmmc.rs
index a6bc117c0..34a53a725 100644
--- a/tests/stm32/src/bin/sdmmc.rs
+++ b/tests/stm32/src/bin/sdmmc.rs
@@ -34,27 +34,29 @@ async fn main(_spawner: Spawner) {
34 pattern1[i] = i as u8; 34 pattern1[i] = i as u8;
35 pattern2[i] = !i as u8; 35 pattern2[i] = !i as u8;
36 } 36 }
37 let patterns = [pattern1.clone(), pattern2.clone()];
37 38
38 let mut block = DataBlock([0u8; 512]); 39 let mut block = DataBlock([0u8; 512]);
40 let mut blocks = [DataBlock([0u8; 512]), DataBlock([0u8; 512])];
39 41
40 // ======== Try 4bit. ============== 42 // ======== Try 4bit. ==============
41 info!("initializing in 4-bit mode..."); 43 info!("initializing in 4-bit mode...");
42 let mut s = Sdmmc::new_4bit( 44 let mut s = Sdmmc::new_4bit(
43 &mut sdmmc, 45 sdmmc.reborrow(),
44 Irqs, 46 Irqs,
45 &mut dma, 47 dma.reborrow(),
46 &mut clk, 48 clk.reborrow(),
47 &mut cmd, 49 cmd.reborrow(),
48 &mut d0, 50 d0.reborrow(),
49 &mut d1, 51 d1.reborrow(),
50 &mut d2, 52 d2.reborrow(),
51 &mut d3, 53 d3.reborrow(),
52 Default::default(), 54 Default::default(),
53 ); 55 );
54 56
55 let mut err = None; 57 let mut err = None;
56 loop { 58 loop {
57 match s.init_card(mhz(24)).await { 59 match s.init_sd_card(mhz(24)).await {
58 Ok(_) => break, 60 Ok(_) => break,
59 Err(e) => { 61 Err(e) => {
60 if err != Some(e) { 62 if err != Some(e) {
@@ -84,23 +86,30 @@ async fn main(_spawner: Spawner) {
84 s.read_block(block_idx, &mut block).await.unwrap(); 86 s.read_block(block_idx, &mut block).await.unwrap();
85 assert_eq!(block, pattern2); 87 assert_eq!(block, pattern2);
86 88
89 info!("writing blocks [pattern1, pattern2]...");
90 s.write_blocks(block_idx, &patterns).await.unwrap();
91
92 info!("reading blocks...");
93 s.read_blocks(block_idx, &mut blocks).await.unwrap();
94 assert_eq!(&blocks, &patterns);
95
87 drop(s); 96 drop(s);
88 97
89 // ======== Try 1bit. ============== 98 // ======== Try 1bit. ==============
90 info!("initializing in 1-bit mode..."); 99 info!("initializing in 1-bit mode...");
91 let mut s = Sdmmc::new_1bit( 100 let mut s = Sdmmc::new_1bit(
92 &mut sdmmc, 101 sdmmc.reborrow(),
93 Irqs, 102 Irqs,
94 &mut dma, 103 dma.reborrow(),
95 &mut clk, 104 clk.reborrow(),
96 &mut cmd, 105 cmd.reborrow(),
97 &mut d0, 106 d0.reborrow(),
98 Default::default(), 107 Default::default(),
99 ); 108 );
100 109
101 let mut err = None; 110 let mut err = None;
102 loop { 111 loop {
103 match s.init_card(mhz(24)).await { 112 match s.init_sd_card(mhz(24)).await {
104 Ok(_) => break, 113 Ok(_) => break,
105 Err(e) => { 114 Err(e) => {
106 if err != Some(e) { 115 if err != Some(e) {
@@ -116,9 +125,9 @@ async fn main(_spawner: Spawner) {
116 info!("Card: {:#?}", Debug2Format(card)); 125 info!("Card: {:#?}", Debug2Format(card));
117 info!("Clock: {}", s.clock()); 126 info!("Clock: {}", s.clock());
118 127
119 info!("reading pattern2 written in 4bit mode..."); 128 info!("reading pattern1 written in 4bit mode...");
120 s.read_block(block_idx, &mut block).await.unwrap(); 129 s.read_block(block_idx, &mut block).await.unwrap();
121 assert_eq!(block, pattern2); 130 assert_eq!(block, pattern1);
122 131
123 info!("writing pattern1..."); 132 info!("writing pattern1...");
124 s.write_block(block_idx, &pattern1).await.unwrap(); 133 s.write_block(block_idx, &pattern1).await.unwrap();
@@ -134,6 +143,13 @@ async fn main(_spawner: Spawner) {
134 s.read_block(block_idx, &mut block).await.unwrap(); 143 s.read_block(block_idx, &mut block).await.unwrap();
135 assert_eq!(block, pattern2); 144 assert_eq!(block, pattern2);
136 145
146 info!("writing blocks [pattern1, pattern2]...");
147 s.write_blocks(block_idx, &patterns).await.unwrap();
148
149 info!("reading blocks...");
150 s.read_blocks(block_idx, &mut blocks).await.unwrap();
151 assert_eq!(&blocks, &patterns);
152
137 drop(s); 153 drop(s);
138 154
139 info!("Test OK"); 155 info!("Test OK");
diff --git a/tests/stm32/src/bin/spi.rs b/tests/stm32/src/bin/spi.rs
index 53d44a94a..e8310866a 100644
--- a/tests/stm32/src/bin/spi.rs
+++ b/tests/stm32/src/bin/spi.rs
@@ -7,7 +7,8 @@ use common::*;
7use defmt::assert_eq; 7use 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::spi::{self, Spi}; 10use embassy_stm32::mode::Blocking;
11use embassy_stm32::spi::{self, Spi, Word};
11use embassy_stm32::time::Hertz; 12use embassy_stm32::time::Hertz;
12 13
13#[embassy_executor::main] 14#[embassy_executor::main]
@@ -24,18 +25,65 @@ async fn main(_spawner: Spawner) {
24 spi_config.frequency = Hertz(1_000_000); 25 spi_config.frequency = Hertz(1_000_000);
25 26
26 let mut spi = Spi::new_blocking( 27 let mut spi = Spi::new_blocking(
27 &mut spi_peri, 28 spi_peri.reborrow(),
28 &mut sck, // Arduino D13 29 sck.reborrow(), // Arduino D13
29 &mut mosi, // Arduino D11 30 mosi.reborrow(), // Arduino D11
30 &mut miso, // Arduino D12 31 miso.reborrow(), // Arduino D12
31 spi_config, 32 spi_config,
32 ); 33 );
33 34
34 let data: [u8; 9] = [0x00, 0xFF, 0xAA, 0x55, 0xC0, 0xFF, 0xEE, 0xC0, 0xDE]; 35 test_txrx::<u8>(&mut spi);
36 test_txrx::<u16>(&mut spi);
37
38 // Assert the RCC bit gets disabled on drop.
39 #[cfg(feature = "stm32f429zi")]
40 defmt::assert!(embassy_stm32::pac::RCC.apb2enr().read().spi1en());
41 drop(spi);
42 #[cfg(feature = "stm32f429zi")]
43 defmt::assert!(!embassy_stm32::pac::RCC.apb2enr().read().spi1en());
44
45 // test rx-only configuration
46 let mut spi = Spi::new_blocking_rxonly(spi_peri.reborrow(), sck.reborrow(), miso.reborrow(), spi_config);
47 let mut mosi_out = Output::new(mosi.reborrow(), Level::Low, Speed::VeryHigh);
48
49 test_rx::<u8>(&mut spi, &mut mosi_out);
50 test_rx::<u16>(&mut spi, &mut mosi_out);
51 drop(spi);
52 drop(mosi_out);
53
54 let mut spi = Spi::new_blocking_txonly(spi_peri.reborrow(), sck.reborrow(), mosi.reborrow(), spi_config);
55 test_tx::<u8>(&mut spi);
56 test_tx::<u16>(&mut spi);
57 drop(spi);
58
59 let mut spi = Spi::new_blocking_txonly_nosck(spi_peri.reborrow(), mosi.reborrow(), spi_config);
60 test_tx::<u8>(&mut spi);
61 test_tx::<u16>(&mut spi);
62 drop(spi);
63
64 info!("Test OK");
65 cortex_m::asm::bkpt();
66}
67
68fn test_txrx<W: Word + From<u8> + defmt::Format + Eq>(spi: &mut Spi<'_, Blocking>)
69where
70 W: core::ops::Not<Output = W>,
71{
72 let data: [W; 9] = [
73 0x00u8.into(),
74 0xFFu8.into(),
75 0xAAu8.into(),
76 0x55u8.into(),
77 0xC0u8.into(),
78 0xFFu8.into(),
79 0xEEu8.into(),
80 0xC0u8.into(),
81 0xDEu8.into(),
82 ];
35 83
36 // Arduino pins D11 and D12 (MOSI-MISO) are connected together with a 1K resistor. 84 // Arduino pins D11 and D12 (MOSI-MISO) are connected together with a 1K resistor.
37 // so we should get the data we sent back. 85 // so we should get the data we sent back.
38 let mut buf = [0; 9]; 86 let mut buf = [W::default(); 9];
39 spi.blocking_transfer(&mut buf, &data).unwrap(); 87 spi.blocking_transfer(&mut buf, &data).unwrap();
40 assert_eq!(buf, data); 88 assert_eq!(buf, data);
41 89
@@ -59,47 +107,33 @@ async fn main(_spawner: Spawner) {
59 spi.blocking_transfer_in_place::<u8>(&mut []).unwrap(); 107 spi.blocking_transfer_in_place::<u8>(&mut []).unwrap();
60 spi.blocking_read::<u8>(&mut []).unwrap(); 108 spi.blocking_read::<u8>(&mut []).unwrap();
61 spi.blocking_write::<u8>(&[]).unwrap(); 109 spi.blocking_write::<u8>(&[]).unwrap();
110}
62 111
63 // Assert the RCC bit gets disabled on drop. 112fn test_rx<W: Word + From<u8> + defmt::Format + Eq>(spi: &mut Spi<'_, Blocking>, mosi_out: &mut Output<'_>)
64 #[cfg(feature = "stm32f429zi")] 113where
65 defmt::assert!(embassy_stm32::pac::RCC.apb2enr().read().spi1en()); 114 W: core::ops::Not<Output = W>,
66 drop(spi); 115{
67 #[cfg(feature = "stm32f429zi")] 116 let mut buf = [W::default(); 9];
68 defmt::assert!(!embassy_stm32::pac::RCC.apb2enr().read().spi1en());
69 117
70 // test rx-only configuration
71 let mut spi = Spi::new_blocking_rxonly(&mut spi_peri, &mut sck, &mut miso, spi_config);
72 let mut mosi_out = Output::new(&mut mosi, Level::Low, Speed::VeryHigh);
73 mosi_out.set_high(); 118 mosi_out.set_high();
74 spi.blocking_read(&mut buf).unwrap(); 119 spi.blocking_read(&mut buf).unwrap();
75 assert_eq!(buf, [0xff; 9]); 120 assert_eq!(buf, [!W::default(); 9]);
76 mosi_out.set_low(); 121 mosi_out.set_low();
77 spi.blocking_read(&mut buf).unwrap(); 122 spi.blocking_read(&mut buf).unwrap();
78 assert_eq!(buf, [0x00; 9]); 123 assert_eq!(buf, [W::default(); 9]);
79 spi.blocking_read::<u8>(&mut []).unwrap(); 124 spi.blocking_read::<u8>(&mut []).unwrap();
80 spi.blocking_read::<u8>(&mut []).unwrap(); 125 spi.blocking_read::<u8>(&mut []).unwrap();
81 drop(mosi_out); 126}
82 drop(spi); 127
128fn test_tx<W: Word + From<u8> + defmt::Format + Eq>(spi: &mut Spi<'_, Blocking>)
129where
130 W: core::ops::Not<Output = W>,
131{
132 let buf = [W::default(); 9];
83 133
84 // Test tx-only. Just check it doesn't hang, not much else we can do without using SPI slave. 134 // Test tx-only. Just check it doesn't hang, not much else we can do without using SPI slave.
85 let mut spi = Spi::new_blocking_txonly(&mut spi_peri, &mut sck, &mut mosi, spi_config);
86 spi.blocking_transfer(&mut buf, &data).unwrap();
87 spi.blocking_transfer_in_place(&mut buf).unwrap();
88 spi.blocking_write(&buf).unwrap(); 135 spi.blocking_write(&buf).unwrap();
89 spi.blocking_read(&mut buf).unwrap();
90 spi.blocking_transfer::<u8>(&mut [], &[]).unwrap();
91 spi.blocking_transfer_in_place::<u8>(&mut []).unwrap();
92 spi.blocking_read::<u8>(&mut []).unwrap();
93 spi.blocking_write::<u8>(&[]).unwrap(); 136 spi.blocking_write::<u8>(&[]).unwrap();
94 drop(spi);
95
96 // Test tx-only nosck.
97 let mut spi = Spi::new_blocking_txonly_nosck(&mut spi_peri, &mut mosi, spi_config);
98 spi.blocking_write(&buf).unwrap(); 137 spi.blocking_write(&buf).unwrap();
99 spi.blocking_write::<u8>(&[]).unwrap(); 138 spi.blocking_write::<u8>(&[]).unwrap();
100 spi.blocking_write(&buf).unwrap();
101 drop(spi);
102
103 info!("Test OK");
104 cortex_m::asm::bkpt();
105} 139}
diff --git a/tests/stm32/src/bin/spi_dma.rs b/tests/stm32/src/bin/spi_dma.rs
index a1cbc0ed1..b4fdb8faa 100644
--- a/tests/stm32/src/bin/spi_dma.rs
+++ b/tests/stm32/src/bin/spi_dma.rs
@@ -7,7 +7,8 @@ use common::*;
7use defmt::assert_eq; 7use 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::spi::{self, Spi}; 10use embassy_stm32::mode::Async;
11use embassy_stm32::spi::{self, Spi, Word};
11use embassy_stm32::time::Hertz; 12use embassy_stm32::time::Hertz;
12 13
13#[embassy_executor::main] 14#[embassy_executor::main]
@@ -26,20 +27,76 @@ async fn main(_spawner: Spawner) {
26 spi_config.frequency = Hertz(1_000_000); 27 spi_config.frequency = Hertz(1_000_000);
27 28
28 let mut spi = Spi::new( 29 let mut spi = Spi::new(
29 &mut spi_peri, 30 spi_peri.reborrow(),
30 &mut sck, // Arduino D13 31 sck.reborrow(), // Arduino D13
31 &mut mosi, // Arduino D11 32 mosi.reborrow(), // Arduino D11
32 &mut miso, // Arduino D12 33 miso.reborrow(), // Arduino D12
33 &mut tx_dma, 34 tx_dma.reborrow(),
34 &mut rx_dma, 35 rx_dma.reborrow(),
35 spi_config, 36 spi_config,
36 ); 37 );
37 38
38 let data: [u8; 9] = [0x00, 0xFF, 0xAA, 0x55, 0xC0, 0xFF, 0xEE, 0xC0, 0xDE]; 39 test_txrx::<u8>(&mut spi).await;
40 test_txrx::<u16>(&mut spi).await;
41 drop(spi);
42
43 // test rx-only configuration
44 let mut spi = Spi::new_rxonly(
45 spi_peri.reborrow(),
46 sck.reborrow(),
47 miso.reborrow(),
48 // SPIv1/f1 requires txdma even if rxonly.
49 #[cfg(not(feature = "spi-v345"))]
50 tx_dma.reborrow(),
51 rx_dma.reborrow(),
52 spi_config,
53 );
54 let mut mosi_out = Output::new(mosi.reborrow(), Level::Low, Speed::VeryHigh);
55
56 test_rx::<u8>(&mut spi, &mut mosi_out).await;
57 test_rx::<u16>(&mut spi, &mut mosi_out).await;
58 drop(spi);
59 drop(mosi_out);
60
61 let mut spi = Spi::new_txonly(
62 spi_peri.reborrow(),
63 sck.reborrow(),
64 mosi.reborrow(),
65 tx_dma.reborrow(),
66 spi_config,
67 );
68 test_tx::<u8>(&mut spi).await;
69 test_tx::<u16>(&mut spi).await;
70 drop(spi);
71
72 let mut spi = Spi::new_txonly_nosck(spi_peri.reborrow(), mosi.reborrow(), tx_dma.reborrow(), spi_config);
73 test_tx::<u8>(&mut spi).await;
74 test_tx::<u16>(&mut spi).await;
75 drop(spi);
76
77 info!("Test OK");
78 cortex_m::asm::bkpt();
79}
80
81async fn test_txrx<W: Word + From<u8> + defmt::Format + Eq>(spi: &mut Spi<'_, Async>)
82where
83 W: core::ops::Not<Output = W>,
84{
85 let data: [W; 9] = [
86 0x00u8.into(),
87 0xFFu8.into(),
88 0xAAu8.into(),
89 0x55u8.into(),
90 0xC0u8.into(),
91 0xFFu8.into(),
92 0xEEu8.into(),
93 0xC0u8.into(),
94 0xDEu8.into(),
95 ];
39 96
40 // Arduino pins D11 and D12 (MOSI-MISO) are connected together with a 1K resistor. 97 // Arduino pins D11 and D12 (MOSI-MISO) are connected together with a 1K resistor.
41 // so we should get the data we sent back. 98 // so we should get the data we sent back.
42 let mut buf = [0; 9]; 99 let mut buf = [W::default(); 9];
43 spi.transfer(&mut buf, &data).await.unwrap(); 100 spi.transfer(&mut buf, &data).await.unwrap();
44 assert_eq!(buf, data); 101 assert_eq!(buf, data);
45 102
@@ -83,56 +140,41 @@ async fn main(_spawner: Spawner) {
83 spi.blocking_write(&buf).unwrap(); 140 spi.blocking_write(&buf).unwrap();
84 spi.blocking_read(&mut buf).unwrap(); 141 spi.blocking_read(&mut buf).unwrap();
85 spi.write(&buf).await.unwrap(); 142 spi.write(&buf).await.unwrap();
143}
86 144
87 core::mem::drop(spi); 145async fn test_rx<W: Word + From<u8> + defmt::Format + Eq>(spi: &mut Spi<'_, Async>, mosi_out: &mut Output<'_>)
146where
147 W: core::ops::Not<Output = W>,
148{
149 let mut buf = [W::default(); 9];
88 150
89 // test rx-only configuration
90 let mut spi = Spi::new_rxonly(
91 &mut spi_peri,
92 &mut sck,
93 &mut miso,
94 // SPIv1/f1 requires txdma even if rxonly.
95 #[cfg(not(feature = "spi-v345"))]
96 &mut tx_dma,
97 &mut rx_dma,
98 spi_config,
99 );
100 let mut mosi_out = Output::new(&mut mosi, Level::Low, Speed::VeryHigh);
101 mosi_out.set_high(); 151 mosi_out.set_high();
102 spi.read(&mut buf).await.unwrap(); 152 spi.read(&mut buf).await.unwrap();
103 assert_eq!(buf, [0xff; 9]); 153 assert_eq!(buf, [!W::default(); 9]);
104 spi.blocking_read(&mut buf).unwrap(); 154 spi.blocking_read(&mut buf).unwrap();
105 assert_eq!(buf, [0xff; 9]); 155 assert_eq!(buf, [!W::default(); 9]);
106 spi.read(&mut buf).await.unwrap(); 156 spi.read(&mut buf).await.unwrap();
107 assert_eq!(buf, [0xff; 9]); 157 assert_eq!(buf, [!W::default(); 9]);
108 spi.read(&mut buf).await.unwrap(); 158 spi.read(&mut buf).await.unwrap();
109 assert_eq!(buf, [0xff; 9]); 159 assert_eq!(buf, [!W::default(); 9]);
110 spi.blocking_read(&mut buf).unwrap(); 160 spi.blocking_read(&mut buf).unwrap();
111 assert_eq!(buf, [0xff; 9]); 161 assert_eq!(buf, [!W::default(); 9]);
112 spi.blocking_read(&mut buf).unwrap(); 162 spi.blocking_read(&mut buf).unwrap();
113 assert_eq!(buf, [0xff; 9]); 163 assert_eq!(buf, [!W::default(); 9]);
114 mosi_out.set_low(); 164 mosi_out.set_low();
115 spi.read(&mut buf).await.unwrap(); 165 spi.read(&mut buf).await.unwrap();
116 assert_eq!(buf, [0x00; 9]); 166 assert_eq!(buf, [W::default(); 9]);
117 spi.read::<u8>(&mut []).await.unwrap(); 167 spi.read::<u8>(&mut []).await.unwrap();
118 spi.blocking_read::<u8>(&mut []).unwrap(); 168 spi.blocking_read::<u8>(&mut []).unwrap();
119 drop(mosi_out); 169}
120 drop(spi);
121 170
122 // Test tx-only. Just check it doesn't hang, not much else we can do without using SPI slave. 171async fn test_tx<W: Word + From<u8> + defmt::Format + Eq>(spi: &mut Spi<'_, Async>)
123 let mut spi = Spi::new_txonly(&mut spi_peri, &mut sck, &mut mosi, &mut tx_dma, spi_config); 172where
124 spi.blocking_write(&buf).unwrap(); 173 W: core::ops::Not<Output = W>,
125 spi.write(&buf).await.unwrap(); 174{
126 spi.blocking_write(&buf).unwrap(); 175 let buf = [W::default(); 9];
127 spi.blocking_write(&buf).unwrap();
128 spi.write(&buf).await.unwrap();
129 spi.write(&buf).await.unwrap();
130 spi.write::<u8>(&[]).await.unwrap();
131 spi.blocking_write::<u8>(&[]).unwrap();
132 drop(spi);
133 176
134 // Test tx-only nosck. 177 // Test tx-only. Just check it doesn't hang, not much else we can do without using SPI slave.
135 let mut spi = Spi::new_txonly_nosck(&mut spi_peri, &mut mosi, &mut tx_dma, spi_config);
136 spi.blocking_write(&buf).unwrap(); 178 spi.blocking_write(&buf).unwrap();
137 spi.write(&buf).await.unwrap(); 179 spi.write(&buf).await.unwrap();
138 spi.blocking_write(&buf).unwrap(); 180 spi.blocking_write(&buf).unwrap();
@@ -141,8 +183,4 @@ async fn main(_spawner: Spawner) {
141 spi.write(&buf).await.unwrap(); 183 spi.write(&buf).await.unwrap();
142 spi.write::<u8>(&[]).await.unwrap(); 184 spi.write::<u8>(&[]).await.unwrap();
143 spi.blocking_write::<u8>(&[]).unwrap(); 185 spi.blocking_write::<u8>(&[]).unwrap();
144 drop(spi);
145
146 info!("Test OK");
147 cortex_m::asm::bkpt();
148} 186}
diff --git a/tests/stm32/src/bin/ucpd.rs b/tests/stm32/src/bin/ucpd.rs
index a6d13b34a..97aefe1a0 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}; 12use embassy_stm32::{bind_interrupts, peripherals, Peri};
13use embassy_time::Timer; 13use embassy_time::Timer;
14 14
15bind_interrupts!(struct Irqs { 15bind_interrupts!(struct Irqs {
@@ -28,8 +28,8 @@ async fn wait_for_vstate<T: ucpd::Instance>(cc_phy: &mut CcPhy<'_, T>, vstate: C
28 28
29async fn source( 29async fn source(
30 mut ucpd: Ucpd<'static, peripherals::UCPD1>, 30 mut ucpd: Ucpd<'static, peripherals::UCPD1>,
31 rx_dma: peripherals::DMA1_CH1, 31 rx_dma: Peri<'static, peripherals::DMA1_CH1>,
32 tx_dma: peripherals::DMA1_CH2, 32 tx_dma: Peri<'static, peripherals::DMA1_CH2>,
33) { 33) {
34 debug!("source: setting default current pull-up"); 34 debug!("source: setting default current pull-up");
35 ucpd.cc_phy().set_pull(CcPull::SourceDefaultUsb); 35 ucpd.cc_phy().set_pull(CcPull::SourceDefaultUsb);
@@ -65,8 +65,8 @@ async fn source(
65 65
66async fn sink( 66async fn sink(
67 mut ucpd: Ucpd<'static, peripherals::UCPD2>, 67 mut ucpd: Ucpd<'static, peripherals::UCPD2>,
68 rx_dma: peripherals::DMA1_CH3, 68 rx_dma: Peri<'static, peripherals::DMA1_CH3>,
69 tx_dma: peripherals::DMA1_CH4, 69 tx_dma: Peri<'static, peripherals::DMA1_CH4>,
70) { 70) {
71 debug!("sink: setting pull down"); 71 debug!("sink: setting pull down");
72 ucpd.cc_phy().set_pull(CcPull::Sink); 72 ucpd.cc_phy().set_pull(CcPull::Sink);
@@ -106,8 +106,8 @@ async fn main(_spawner: Spawner) {
106 info!("Hello World!"); 106 info!("Hello World!");
107 107
108 // Wire between PD0 and PA8 108 // Wire between PD0 and PA8
109 let ucpd1 = Ucpd::new(p.UCPD1, Irqs {}, p.PA8, p.PB15); 109 let ucpd1 = Ucpd::new(p.UCPD1, Irqs {}, p.PA8, p.PB15, Default::default());
110 let ucpd2 = Ucpd::new(p.UCPD2, Irqs {}, p.PD0, p.PD2); 110 let ucpd2 = Ucpd::new(p.UCPD2, Irqs {}, p.PD0, p.PD2, Default::default());
111 111
112 join( 112 join(
113 source(ucpd1, p.DMA1_CH1, p.DMA1_CH2), 113 source(ucpd1, p.DMA1_CH1, p.DMA1_CH2),
diff --git a/tests/stm32/src/bin/usart.rs b/tests/stm32/src/bin/usart.rs
index 53da30fff..129c7b692 100644
--- a/tests/stm32/src/bin/usart.rs
+++ b/tests/stm32/src/bin/usart.rs
@@ -22,7 +22,7 @@ async fn main(_spawner: Spawner) {
22 22
23 { 23 {
24 let config = Config::default(); 24 let config = Config::default();
25 let mut usart = Uart::new_blocking(&mut usart, &mut rx, &mut tx, config).unwrap(); 25 let mut usart = Uart::new_blocking(usart.reborrow(), rx.reborrow(), tx.reborrow(), config).unwrap();
26 26
27 // We can't send too many bytes, they have to fit in the FIFO. 27 // We can't send too many bytes, they have to fit in the FIFO.
28 // This is because we aren't sending+receiving at the same time. 28 // This is because we aren't sending+receiving at the same time.
@@ -33,12 +33,19 @@ async fn main(_spawner: Spawner) {
33 let mut buf = [0; 2]; 33 let mut buf = [0; 2];
34 usart.blocking_read(&mut buf).unwrap(); 34 usart.blocking_read(&mut buf).unwrap();
35 assert_eq!(buf, data); 35 assert_eq!(buf, data);
36
37 // Test flush doesn't hang.
38 usart.blocking_write(&data).unwrap();
39 usart.blocking_flush().unwrap();
40
41 // Test flush doesn't hang if there's nothing to flush
42 usart.blocking_flush().unwrap();
36 } 43 }
37 44
38 // Test error handling with with an overflow error 45 // Test error handling with with an overflow error
39 { 46 {
40 let config = Config::default(); 47 let config = Config::default();
41 let mut usart = Uart::new_blocking(&mut usart, &mut rx, &mut tx, config).unwrap(); 48 let mut usart = Uart::new_blocking(usart.reborrow(), rx.reborrow(), tx.reborrow(), config).unwrap();
42 49
43 // Send enough bytes to fill the RX FIFOs off all USART versions. 50 // Send enough bytes to fill the RX FIFOs off all USART versions.
44 let data = [0; 64]; 51 let data = [0; 64];
@@ -68,7 +75,7 @@ async fn main(_spawner: Spawner) {
68 75
69 let mut config = Config::default(); 76 let mut config = Config::default();
70 config.baudrate = baudrate; 77 config.baudrate = baudrate;
71 let mut usart = match Uart::new_blocking(&mut usart, &mut rx, &mut tx, config) { 78 let mut usart = match Uart::new_blocking(usart.reborrow(), rx.reborrow(), tx.reborrow(), config) {
72 Ok(x) => x, 79 Ok(x) => x,
73 Err(ConfigError::BaudrateTooHigh) => { 80 Err(ConfigError::BaudrateTooHigh) => {
74 info!("baudrate too high"); 81 info!("baudrate too high");
diff --git a/tests/stm32/src/bin/usart_dma.rs b/tests/stm32/src/bin/usart_dma.rs
index 266b81809..a34498376 100644
--- a/tests/stm32/src/bin/usart_dma.rs
+++ b/tests/stm32/src/bin/usart_dma.rs
@@ -51,6 +51,23 @@ async fn main(_spawner: Spawner) {
51 assert_eq!(tx_buf, rx_buf); 51 assert_eq!(tx_buf, rx_buf);
52 } 52 }
53 53
54 // Test flush doesn't hang. Check multiple combinations of async+blocking.
55 tx.write(&tx_buf).await.unwrap();
56 tx.flush().await.unwrap();
57 tx.flush().await.unwrap();
58
59 tx.write(&tx_buf).await.unwrap();
60 tx.blocking_flush().unwrap();
61 tx.flush().await.unwrap();
62
63 tx.blocking_write(&tx_buf).unwrap();
64 tx.blocking_flush().unwrap();
65 tx.flush().await.unwrap();
66
67 tx.blocking_write(&tx_buf).unwrap();
68 tx.flush().await.unwrap();
69 tx.blocking_flush().unwrap();
70
54 info!("Test OK"); 71 info!("Test OK");
55 cortex_m::asm::bkpt(); 72 cortex_m::asm::bkpt();
56} 73}
diff --git a/tests/stm32/src/bin/usart_rx_ringbuffered.rs b/tests/stm32/src/bin/usart_rx_ringbuffered.rs
index 98c7ef312..83c0887ac 100644
--- a/tests/stm32/src/bin/usart_rx_ringbuffered.rs
+++ b/tests/stm32/src/bin/usart_rx_ringbuffered.rs
@@ -43,8 +43,7 @@ async fn main(spawner: Spawner) {
43 let usart = Uart::new(usart, rx, tx, irq, tx_dma, rx_dma, config).unwrap(); 43 let usart = Uart::new(usart, rx, tx, irq, tx_dma, rx_dma, config).unwrap();
44 let (tx, rx) = usart.split(); 44 let (tx, rx) = usart.split();
45 static mut DMA_BUF: [u8; DMA_BUF_SIZE] = [0; DMA_BUF_SIZE]; 45 static mut DMA_BUF: [u8; DMA_BUF_SIZE] = [0; DMA_BUF_SIZE];
46 let dma_buf = unsafe { DMA_BUF.as_mut() }; 46 let rx = rx.into_ring_buffered(unsafe { &mut *core::ptr::addr_of_mut!(DMA_BUF) });
47 let rx = rx.into_ring_buffered(dma_buf);
48 47
49 info!("Spawning tasks"); 48 info!("Spawning tasks");
50 spawner.spawn(transmit_task(tx)).unwrap(); 49 spawner.spawn(transmit_task(tx)).unwrap();
diff --git a/tests/stm32/src/common.rs b/tests/stm32/src/common.rs
index 935a41ed2..829f2cff0 100644
--- a/tests/stm32/src/common.rs
+++ b/tests/stm32/src/common.rs
@@ -284,7 +284,9 @@ pub fn config() -> Config {
284 284
285 #[cfg(feature = "stm32g071rb")] 285 #[cfg(feature = "stm32g071rb")]
286 { 286 {
287 config.rcc.hsi = true; 287 config.rcc.hsi = Some(Hsi {
288 sys_div: HsiSysDiv::DIV1,
289 });
288 config.rcc.pll = Some(Pll { 290 config.rcc.pll = Some(Pll {
289 source: PllSource::HSI, 291 source: PllSource::HSI,
290 prediv: PllPreDiv::DIV1, 292 prediv: PllPreDiv::DIV1,
diff --git a/tests/utils/Cargo.toml b/tests/utils/Cargo.toml
index 7b54a4f52..bda55ad32 100644
--- a/tests/utils/Cargo.toml
+++ b/tests/utils/Cargo.toml
@@ -4,5 +4,5 @@ version = "0.1.0"
4edition = "2021" 4edition = "2021"
5 5
6[dependencies] 6[dependencies]
7rand = "0.8" 7rand = "0.9"
8serial = "0.4" 8serial = "0.4"