From 56f9296581800dca70474459debf4a429b312e50 Mon Sep 17 00:00:00 2001 From: Bailey Townsend Date: Fri, 27 Dec 2024 12:29:17 -0600 Subject: [PATCH 1/5] Added a new rm2 feature flag --- cyw43-pio/Cargo.toml | 2 ++ cyw43-pio/src/lib.rs | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cyw43-pio/Cargo.toml b/cyw43-pio/Cargo.toml index 4e21c255f..794bf2479 100644 --- a/cyw43-pio/Cargo.toml +++ b/cyw43-pio/Cargo.toml @@ -13,6 +13,8 @@ documentation = "https://docs.embassy.dev/cyw43-pio" # If disabled, SPI runs at 31.25MHz # If enabled, SPI runs at 62.5MHz, which is 25% higher than 50Mhz which is the maximum according to the CYW43439 datasheet. overclock = [] +# If enabled the PIO runs at a speed that works with the rm2 module +rm2 = [] [dependencies] cyw43 = { version = "0.2.0", path = "../cyw43" } diff --git a/cyw43-pio/src/lib.rs b/cyw43-pio/src/lib.rs index 40cf63a17..1280e2059 100644 --- a/cyw43-pio/src/lib.rs +++ b/cyw43-pio/src/lib.rs @@ -120,7 +120,7 @@ where cfg.clock_divider = FixedU32::from_bits(0x0100); } - #[cfg(not(feature = "overclock"))] + #[cfg(not(any(feature = "overclock", feature = "rm2")))] { // same speed as pico-sdk, 62.5Mhz // This is actually the fastest we can go without overclocking. @@ -132,6 +132,12 @@ where cfg.clock_divider = FixedU32::from_bits(0x0200); } + #[cfg(feature = "rm2")] + { + // This is found to work better with the RM2 module which is found on the Pimoroni Pico Plus 2 W + cfg.clock_divider = FixedU32::from_bits(0x0300); + } + sm.set_config(&cfg); sm.set_pin_dirs(Direction::Out, &[&pin_clk, &pin_io]); From dd31ffadfbd145f26b6bb54cf2036cb54149aefe Mon Sep 17 00:00:00 2001 From: Bailey Townsend Date: Fri, 27 Dec 2024 23:43:38 -0600 Subject: [PATCH 2/5] Work done --- cyw43-pio/Cargo.toml | 2 -- cyw43-pio/src/lib.rs | 48 +++++++++++++++++++++----------------------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/cyw43-pio/Cargo.toml b/cyw43-pio/Cargo.toml index 794bf2479..4e21c255f 100644 --- a/cyw43-pio/Cargo.toml +++ b/cyw43-pio/Cargo.toml @@ -13,8 +13,6 @@ documentation = "https://docs.embassy.dev/cyw43-pio" # If disabled, SPI runs at 31.25MHz # If enabled, SPI runs at 62.5MHz, which is 25% higher than 50Mhz which is the maximum according to the CYW43439 datasheet. overclock = [] -# If enabled the PIO runs at a speed that works with the rm2 module -rm2 = [] [dependencies] cyw43 = { version = "0.2.0", path = "../cyw43" } diff --git a/cyw43-pio/src/lib.rs b/cyw43-pio/src/lib.rs index 1280e2059..abf3830d9 100644 --- a/cyw43-pio/src/lib.rs +++ b/cyw43-pio/src/lib.rs @@ -10,6 +10,7 @@ use embassy_rp::dma::Channel; use embassy_rp::gpio::{Drive, Level, Output, Pull, SlewRate}; use embassy_rp::pio::{instr, Common, Config, Direction, Instance, Irq, PioPin, ShiftDirection, StateMachine}; use embassy_rp::{Peripheral, PeripheralRef}; +use fixed::types::extra::U8; use fixed::FixedU32; use pio_proc::pio_asm; @@ -22,6 +23,26 @@ pub struct PioSpi<'d, PIO: Instance, const SM: usize, DMA> { wrap_target: u8, } +/// The default clock divider that works for Pico 1 and 2 W. As well as the RM2 on rp2040 devices. +/// same speed as pico-sdk, 62.5Mhz +/// This is actually the fastest we can go without overclocking. +/// According to data sheet, the theoretical maximum is 100Mhz Pio => 50Mhz SPI Freq. +/// However, the PIO uses a fractional divider, which works by introducing jitter when +/// the divider is not an integer. It does some clocks at 125mhz and others at 62.5mhz +/// so that it averages out to the desired frequency of 100mhz. The 125mhz clock cycles +/// violate the maximum from the data sheet. +pub const DEFAULT_CLOCK_DIVIDER: FixedU32 = FixedU32::from_bits(0x0200); + +/// The overclock clock divider for the Pico 1 W. Does not work on any known RM2 devices. +/// 125mhz Pio => 62.5Mhz SPI Freq. 25% higher than theoretical maximum according to +/// data sheet, but seems to work fine. +pub const OVERCLOCK_CLOCK_DIVIDER: FixedU32 = FixedU32::from_bits(0x0100); + +/// The clock divider for the RM2 module. Found to be needed for the Pimoroni Pico Plus 2 W, +/// Pico Plus 2 Non w with the RM2 breakout module, and the Pico 2 with the RM2 breakout module. +/// Does not work with the feature "overclock". +pub const RM2_CLOCK_DIVIDER: FixedU32 = FixedU32::from_bits(0x0300); + impl<'d, PIO, const SM: usize, DMA> PioSpi<'d, PIO, SM, DMA> where DMA: Channel, @@ -31,6 +52,7 @@ where pub fn new( common: &mut Common<'d, PIO>, mut sm: StateMachine<'d, PIO, SM>, + clock_divider: FixedU32, irq: Irq<'d, PIO, 0>, cs: Output<'d>, dio: DIO, @@ -112,31 +134,7 @@ where cfg.shift_in.direction = ShiftDirection::Left; cfg.shift_in.auto_fill = true; //cfg.shift_in.threshold = 32; - - #[cfg(feature = "overclock")] - { - // 125mhz Pio => 62.5Mhz SPI Freq. 25% higher than theoretical maximum according to - // data sheet, but seems to work fine. - cfg.clock_divider = FixedU32::from_bits(0x0100); - } - - #[cfg(not(any(feature = "overclock", feature = "rm2")))] - { - // same speed as pico-sdk, 62.5Mhz - // This is actually the fastest we can go without overclocking. - // According to data sheet, the theoretical maximum is 100Mhz Pio => 50Mhz SPI Freq. - // However, the PIO uses a fractional divider, which works by introducing jitter when - // the divider is not an integer. It does some clocks at 125mhz and others at 62.5mhz - // so that it averages out to the desired frequency of 100mhz. The 125mhz clock cycles - // violate the maximum from the data sheet. - cfg.clock_divider = FixedU32::from_bits(0x0200); - } - - #[cfg(feature = "rm2")] - { - // This is found to work better with the RM2 module which is found on the Pimoroni Pico Plus 2 W - cfg.clock_divider = FixedU32::from_bits(0x0300); - } + cfg.clock_divider = clock_divider; sm.set_config(&cfg); From 8243a8a3892dc499be560a0bf2134e641b856760 Mon Sep 17 00:00:00 2001 From: Bailey Townsend Date: Sat, 28 Dec 2024 00:07:14 -0600 Subject: [PATCH 3/5] Added new param to examples and created a pico plus 2 w example --- examples/rp/src/bin/wifi_ap_tcp_server.rs | 13 ++- examples/rp/src/bin/wifi_blinky.rs | 13 ++- examples/rp/src/bin/wifi_scan.rs | 13 ++- examples/rp/src/bin/wifi_tcp_server.rs | 13 ++- examples/rp/src/bin/wifi_webrequest.rs | 13 ++- .../rp23/src/bin/wifi_blinky_pico_plus_2.rs | 94 +++++++++++++++++++ 6 files changed, 149 insertions(+), 10 deletions(-) create mode 100644 examples/rp23/src/bin/wifi_blinky_pico_plus_2.rs diff --git a/examples/rp/src/bin/wifi_ap_tcp_server.rs b/examples/rp/src/bin/wifi_ap_tcp_server.rs index 4c9651433..e97ddb4c1 100644 --- a/examples/rp/src/bin/wifi_ap_tcp_server.rs +++ b/examples/rp/src/bin/wifi_ap_tcp_server.rs @@ -7,7 +7,7 @@ use core::str::from_utf8; -use cyw43_pio::PioSpi; +use cyw43_pio::{PioSpi, DEFAULT_CLOCK_DIVIDER}; use defmt::*; use embassy_executor::Spawner; use embassy_net::tcp::TcpSocket; @@ -57,7 +57,16 @@ async fn main(spawner: Spawner) { let pwr = Output::new(p.PIN_23, Level::Low); let cs = Output::new(p.PIN_25, Level::High); let mut pio = Pio::new(p.PIO0, Irqs); - let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); + let spi = PioSpi::new( + &mut pio.common, + pio.sm0, + DEFAULT_CLOCK_DIVIDER, + pio.irq0, + cs, + p.PIN_24, + p.PIN_29, + p.DMA_CH0, + ); static STATE: StaticCell = StaticCell::new(); let state = STATE.init(cyw43::State::new()); diff --git a/examples/rp/src/bin/wifi_blinky.rs b/examples/rp/src/bin/wifi_blinky.rs index 0107a2326..6e91ce167 100644 --- a/examples/rp/src/bin/wifi_blinky.rs +++ b/examples/rp/src/bin/wifi_blinky.rs @@ -5,7 +5,7 @@ #![no_std] #![no_main] -use cyw43_pio::PioSpi; +use cyw43_pio::{PioSpi, DEFAULT_CLOCK_DIVIDER}; use defmt::*; use embassy_executor::Spawner; use embassy_rp::bind_interrupts; @@ -41,7 +41,16 @@ async fn main(spawner: Spawner) { let pwr = Output::new(p.PIN_23, Level::Low); let cs = Output::new(p.PIN_25, Level::High); let mut pio = Pio::new(p.PIO0, Irqs); - let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); + let spi = PioSpi::new( + &mut pio.common, + pio.sm0, + DEFAULT_CLOCK_DIVIDER, + pio.irq0, + cs, + p.PIN_24, + p.PIN_29, + p.DMA_CH0, + ); static STATE: StaticCell = StaticCell::new(); let state = STATE.init(cyw43::State::new()); diff --git a/examples/rp/src/bin/wifi_scan.rs b/examples/rp/src/bin/wifi_scan.rs index 2ef899080..fe9c363d9 100644 --- a/examples/rp/src/bin/wifi_scan.rs +++ b/examples/rp/src/bin/wifi_scan.rs @@ -7,7 +7,7 @@ use core::str; -use cyw43_pio::PioSpi; +use cyw43_pio::{PioSpi, DEFAULT_CLOCK_DIVIDER}; use defmt::*; use embassy_executor::Spawner; use embassy_rp::bind_interrupts; @@ -45,7 +45,16 @@ async fn main(spawner: Spawner) { let pwr = Output::new(p.PIN_23, Level::Low); let cs = Output::new(p.PIN_25, Level::High); let mut pio = Pio::new(p.PIO0, Irqs); - let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); + let spi = PioSpi::new( + &mut pio.common, + pio.sm0, + DEFAULT_CLOCK_DIVIDER, + pio.irq0, + cs, + p.PIN_24, + p.PIN_29, + p.DMA_CH0, + ); static STATE: StaticCell = StaticCell::new(); let state = STATE.init(cyw43::State::new()); diff --git a/examples/rp/src/bin/wifi_tcp_server.rs b/examples/rp/src/bin/wifi_tcp_server.rs index 7bf546e01..14dbf4552 100644 --- a/examples/rp/src/bin/wifi_tcp_server.rs +++ b/examples/rp/src/bin/wifi_tcp_server.rs @@ -8,7 +8,7 @@ use core::str::from_utf8; use cyw43::JoinOptions; -use cyw43_pio::PioSpi; +use cyw43_pio::{PioSpi, DEFAULT_CLOCK_DIVIDER}; use defmt::*; use embassy_executor::Spawner; use embassy_net::tcp::TcpSocket; @@ -61,7 +61,16 @@ async fn main(spawner: Spawner) { let pwr = Output::new(p.PIN_23, Level::Low); let cs = Output::new(p.PIN_25, Level::High); let mut pio = Pio::new(p.PIO0, Irqs); - let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); + let spi = PioSpi::new( + &mut pio.common, + pio.sm0, + DEFAULT_CLOCK_DIVIDER, + pio.irq0, + cs, + p.PIN_24, + p.PIN_29, + p.DMA_CH0, + ); static STATE: StaticCell = StaticCell::new(); let state = STATE.init(cyw43::State::new()); diff --git a/examples/rp/src/bin/wifi_webrequest.rs b/examples/rp/src/bin/wifi_webrequest.rs index 1ae909917..f1b398b65 100644 --- a/examples/rp/src/bin/wifi_webrequest.rs +++ b/examples/rp/src/bin/wifi_webrequest.rs @@ -8,7 +8,7 @@ use core::str::from_utf8; use cyw43::JoinOptions; -use cyw43_pio::PioSpi; +use cyw43_pio::{PioSpi, DEFAULT_CLOCK_DIVIDER}; use defmt::*; use embassy_executor::Spawner; use embassy_net::dns::DnsSocket; @@ -63,7 +63,16 @@ async fn main(spawner: Spawner) { let pwr = Output::new(p.PIN_23, Level::Low); let cs = Output::new(p.PIN_25, Level::High); let mut pio = Pio::new(p.PIO0, Irqs); - let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); + let spi = PioSpi::new( + &mut pio.common, + pio.sm0, + DEFAULT_CLOCK_DIVIDER, + pio.irq0, + cs, + p.PIN_24, + p.PIN_29, + p.DMA_CH0, + ); static STATE: StaticCell = StaticCell::new(); let state = STATE.init(cyw43::State::new()); diff --git a/examples/rp23/src/bin/wifi_blinky_pico_plus_2.rs b/examples/rp23/src/bin/wifi_blinky_pico_plus_2.rs new file mode 100644 index 000000000..240588762 --- /dev/null +++ b/examples/rp23/src/bin/wifi_blinky_pico_plus_2.rs @@ -0,0 +1,94 @@ +//! This example test the Pimoroni Pico Plus 2 on board LED. +//! +//! It does not work with the RP Pico board. See blinky.rs. + +#![no_std] +#![no_main] + +use cyw43_pio::{PioSpi, RM2_CLOCK_DIVIDER}; +use defmt::*; +use embassy_executor::Spawner; +use embassy_rp::block::ImageDef; +use embassy_rp::gpio; +use embassy_rp::peripherals::{DMA_CH0, PIO0}; +use embassy_rp::pio::Pio; +use embassy_rp::{bind_interrupts, pio::InterruptHandler}; +use embassy_time::{Duration, Timer}; +use gpio::{Level, Output}; +use static_cell::StaticCell; +use {defmt_rtt as _, panic_probe as _}; + +#[link_section = ".start_block"] +#[used] +pub static IMAGE_DEF: ImageDef = ImageDef::secure_exe(); + +// Program metadata for `picotool info`. +// This isn't needed, but it's recomended to have these minimal entries. +#[link_section = ".bi_entries"] +#[used] +pub static PICOTOOL_ENTRIES: [embassy_rp::binary_info::EntryAddr; 4] = [ + embassy_rp::binary_info::rp_program_name!(c"Blinky Example"), + embassy_rp::binary_info::rp_program_description!( + c"This example tests the RP Pico on board LED, connected to gpio 25" + ), + embassy_rp::binary_info::rp_cargo_version!(), + embassy_rp::binary_info::rp_program_build_attribute!(), +]; + +bind_interrupts!(struct Irqs { + PIO0_IRQ_0 => InterruptHandler; +}); + +#[embassy_executor::task] +async fn cyw43_task(runner: cyw43::Runner<'static, Output<'static>, PioSpi<'static, PIO0, 0, DMA_CH0>>) -> ! { + runner.run().await +} + +#[embassy_executor::main] +async fn main(spawner: Spawner) { + let p = embassy_rp::init(Default::default()); + let fw = include_bytes!("../../../../cyw43-firmware/43439A0.bin"); + let clm = include_bytes!("../../../../cyw43-firmware/43439A0_clm.bin"); + + // To make flashing faster for development, you may want to flash the firmwares independently + // at hardcoded addresses, instead of baking them into the program with `include_bytes!`: + // probe-rs download ../../cyw43-firmware/43439A0.bin --binary-format bin --chip RP2040 --base-address 0x10100000 + // probe-rs download ../../cyw43-firmware/43439A0_clm.bin --binary-format bin --chip RP2040 --base-address 0x10140000 + //let fw = unsafe { core::slice::from_raw_parts(0x10100000 as *const u8, 230321) }; + //let clm = unsafe { core::slice::from_raw_parts(0x10140000 as *const u8, 4752) }; + + let pwr = Output::new(p.PIN_23, Level::Low); + let cs = Output::new(p.PIN_25, Level::High); + let mut pio = Pio::new(p.PIO0, Irqs); + let spi = PioSpi::new( + &mut pio.common, + pio.sm0, + RM2_CLOCK_DIVIDER, + pio.irq0, + cs, + p.PIN_24, + p.PIN_29, + p.DMA_CH0, + ); + + static STATE: StaticCell = StaticCell::new(); + let state = STATE.init(cyw43::State::new()); + let (_net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; + unwrap!(spawner.spawn(cyw43_task(runner))); + + control.init(clm).await; + control + .set_power_management(cyw43::PowerManagementMode::PowerSave) + .await; + + let delay = Duration::from_secs(1); + loop { + info!("led on!"); + control.gpio_set(0, true).await; + Timer::after(delay).await; + + info!("led off!"); + control.gpio_set(0, false).await; + Timer::after(delay).await; + } +} From 388103275e8648492e27514e00048492a55a931c Mon Sep 17 00:00:00 2001 From: Bailey Townsend Date: Sat, 28 Dec 2024 00:40:52 -0600 Subject: [PATCH 4/5] Fixes ci (hopefully) --- examples/rp23/src/bin/wifi_blinky_pico_plus_2.rs | 5 ++--- tests/rp/src/bin/cyw43-perf.rs | 13 +++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/examples/rp23/src/bin/wifi_blinky_pico_plus_2.rs b/examples/rp23/src/bin/wifi_blinky_pico_plus_2.rs index 240588762..ebb3c4373 100644 --- a/examples/rp23/src/bin/wifi_blinky_pico_plus_2.rs +++ b/examples/rp23/src/bin/wifi_blinky_pico_plus_2.rs @@ -9,10 +9,9 @@ use cyw43_pio::{PioSpi, RM2_CLOCK_DIVIDER}; use defmt::*; use embassy_executor::Spawner; use embassy_rp::block::ImageDef; -use embassy_rp::gpio; use embassy_rp::peripherals::{DMA_CH0, PIO0}; -use embassy_rp::pio::Pio; -use embassy_rp::{bind_interrupts, pio::InterruptHandler}; +use embassy_rp::pio::{InterruptHandler, Pio}; +use embassy_rp::{bind_interrupts, gpio}; use embassy_time::{Duration, Timer}; use gpio::{Level, Output}; use static_cell::StaticCell; diff --git a/tests/rp/src/bin/cyw43-perf.rs b/tests/rp/src/bin/cyw43-perf.rs index 30e4afb07..34119722b 100644 --- a/tests/rp/src/bin/cyw43-perf.rs +++ b/tests/rp/src/bin/cyw43-perf.rs @@ -3,7 +3,7 @@ teleprobe_meta::target!(b"rpi-pico"); use cyw43::JoinOptions; -use cyw43_pio::PioSpi; +use cyw43_pio::{PioSpi, DEFAULT_CLOCK_DIVIDER}; use defmt::{panic, *}; use embassy_executor::Spawner; use embassy_net::{Config, StackResources}; @@ -54,7 +54,16 @@ async fn main(spawner: Spawner) { let pwr = Output::new(p.PIN_23, Level::Low); let cs = Output::new(p.PIN_25, Level::High); let mut pio = Pio::new(p.PIO0, Irqs); - let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); + let spi = PioSpi::new( + &mut pio.common, + pio.sm0, + DEFAULT_CLOCK_DIVIDER, + pio.irq0, + cs, + p.PIN_24, + p.PIN_29, + p.DMA_CH0, + ); static STATE: StaticCell = StaticCell::new(); let state = STATE.init(cyw43::State::new()); From 147fd60255a94292a2e0e685c0cad068cc7760e7 Mon Sep 17 00:00:00 2001 From: Bailey Townsend Date: Sat, 28 Dec 2024 17:31:14 -0600 Subject: [PATCH 5/5] Removed the cyw43-pio overclock feature --- ci.sh | 2 +- cyw43-pio/Cargo.toml | 5 --- cyw43-pio/src/lib.rs | 87 ++++++++++++++++++++++---------------------- tests/rp/Cargo.toml | 2 +- 4 files changed, 46 insertions(+), 50 deletions(-) diff --git a/ci.sh b/ci.sh index e7f1504aa..2bfe082cf 100755 --- a/ci.sh +++ b/ci.sh @@ -178,7 +178,7 @@ cargo batch \ --- build --release --manifest-path cyw43/Cargo.toml --target thumbv6m-none-eabi --features 'log,firmware-logs,bluetooth' \ --- build --release --manifest-path cyw43/Cargo.toml --target thumbv6m-none-eabi --features 'defmt,firmware-logs,bluetooth' \ --- build --release --manifest-path cyw43-pio/Cargo.toml --target thumbv6m-none-eabi --features 'embassy-rp/rp2040' \ - --- build --release --manifest-path cyw43-pio/Cargo.toml --target thumbv6m-none-eabi --features 'embassy-rp/rp2040,overclock' \ + --- build --release --manifest-path cyw43-pio/Cargo.toml --target thumbv6m-none-eabi --features 'embassy-rp/rp2040' \ --- build --release --manifest-path embassy-boot-nrf/Cargo.toml --target thumbv7em-none-eabi --features embassy-nrf/nrf52840 \ --- build --release --manifest-path embassy-boot-nrf/Cargo.toml --target thumbv8m.main-none-eabihf --features embassy-nrf/nrf9160-ns \ --- build --release --manifest-path embassy-boot-nrf/Cargo.toml --target thumbv8m.main-none-eabihf --features embassy-nrf/nrf9120-ns \ diff --git a/cyw43-pio/Cargo.toml b/cyw43-pio/Cargo.toml index 4e21c255f..e400d95ea 100644 --- a/cyw43-pio/Cargo.toml +++ b/cyw43-pio/Cargo.toml @@ -9,11 +9,6 @@ license = "MIT OR Apache-2.0" repository = "https://github.com/embassy-rs/embassy" documentation = "https://docs.embassy.dev/cyw43-pio" -[features] -# If disabled, SPI runs at 31.25MHz -# If enabled, SPI runs at 62.5MHz, which is 25% higher than 50Mhz which is the maximum according to the CYW43439 datasheet. -overclock = [] - [dependencies] cyw43 = { version = "0.2.0", path = "../cyw43" } embassy-rp = { version = "0.2.0", path = "../embassy-rp" } diff --git a/cyw43-pio/src/lib.rs b/cyw43-pio/src/lib.rs index abf3830d9..5fe7af95d 100644 --- a/cyw43-pio/src/lib.rs +++ b/cyw43-pio/src/lib.rs @@ -40,7 +40,6 @@ pub const OVERCLOCK_CLOCK_DIVIDER: FixedU32 = FixedU32::from_bits(0x0100); /// The clock divider for the RM2 module. Found to be needed for the Pimoroni Pico Plus 2 W, /// Pico Plus 2 Non w with the RM2 breakout module, and the Pico 2 with the RM2 breakout module. -/// Does not work with the feature "overclock". pub const RM2_CLOCK_DIVIDER: FixedU32 = FixedU32::from_bits(0x0300); impl<'d, PIO, const SM: usize, DMA> PioSpi<'d, PIO, SM, DMA> @@ -63,53 +62,56 @@ where DIO: PioPin, CLK: PioPin, { - #[cfg(feature = "overclock")] - let program = pio_asm!( - ".side_set 1" + let loaded_program = if clock_divider < DEFAULT_CLOCK_DIVIDER { + let overclock_program = pio_asm!( + ".side_set 1" - ".wrap_target" - // write out x-1 bits - "lp:" - "out pins, 1 side 0" - "jmp x-- lp side 1" - // switch directions - "set pindirs, 0 side 0" - "nop side 1" // necessary for clkdiv=1. - "nop side 0" - // read in y-1 bits - "lp2:" - "in pins, 1 side 1" - "jmp y-- lp2 side 0" + ".wrap_target" + // write out x-1 bits + "lp:" + "out pins, 1 side 0" + "jmp x-- lp side 1" + // switch directions + "set pindirs, 0 side 0" + "nop side 1" // necessary for clkdiv=1. + "nop side 0" + // read in y-1 bits + "lp2:" + "in pins, 1 side 1" + "jmp y-- lp2 side 0" - // wait for event and irq host - "wait 1 pin 0 side 0" - "irq 0 side 0" + // wait for event and irq host + "wait 1 pin 0 side 0" + "irq 0 side 0" - ".wrap" - ); - #[cfg(not(feature = "overclock"))] - let program = pio_asm!( - ".side_set 1" + ".wrap" + ); + common.load_program(&overclock_program.program) + } else { + let default_program = pio_asm!( + ".side_set 1" - ".wrap_target" - // write out x-1 bits - "lp:" - "out pins, 1 side 0" - "jmp x-- lp side 1" - // switch directions - "set pindirs, 0 side 0" - "nop side 0" - // read in y-1 bits - "lp2:" - "in pins, 1 side 1" - "jmp y-- lp2 side 0" + ".wrap_target" + // write out x-1 bits + "lp:" + "out pins, 1 side 0" + "jmp x-- lp side 1" + // switch directions + "set pindirs, 0 side 0" + "nop side 0" + // read in y-1 bits + "lp2:" + "in pins, 1 side 1" + "jmp y-- lp2 side 0" - // wait for event and irq host - "wait 1 pin 0 side 0" - "irq 0 side 0" + // wait for event and irq host + "wait 1 pin 0 side 0" + "irq 0 side 0" - ".wrap" - ); + ".wrap" + ); + common.load_program(&default_program.program) + }; let mut pin_io: embassy_rp::pio::Pin = common.make_pio_pin(dio); pin_io.set_pull(Pull::None); @@ -123,7 +125,6 @@ where pin_clk.set_slew_rate(SlewRate::Fast); let mut cfg = Config::default(); - let loaded_program = common.load_program(&program.program); cfg.use_program(&loaded_program, &[&pin_clk]); cfg.set_out_pins(&[&pin_io]); cfg.set_in_pins(&[&pin_io]); diff --git a/tests/rp/Cargo.toml b/tests/rp/Cargo.toml index d5aabc6ac..842cdf51d 100644 --- a/tests/rp/Cargo.toml +++ b/tests/rp/Cargo.toml @@ -16,7 +16,7 @@ embassy-net = { version = "0.5.0", path = "../../embassy-net", features = ["defm embassy-net-wiznet = { version = "0.1.0", path = "../../embassy-net-wiznet", features = ["defmt"] } embassy-embedded-hal = { version = "0.2.0", path = "../../embassy-embedded-hal/"} cyw43 = { path = "../../cyw43", features = ["defmt", "firmware-logs"] } -cyw43-pio = { path = "../../cyw43-pio", features = ["defmt", "overclock"] } +cyw43-pio = { path = "../../cyw43-pio", features = ["defmt"] } perf-client = { path = "../perf-client" } defmt = "0.3.0"