From c1647d9f3412a0020d60961b52ccef0606dddfd9 Mon Sep 17 00:00:00 2001 From: 9names <60134748+9names@users.noreply.github.com> Date: Tue, 26 Nov 2024 19:08:03 +1100 Subject: [PATCH] Use cyw43 FW file size instead of magic numbers --- examples/rp/src/bin/bluetooth.rs | 10 +++++++--- examples/rp/src/bin/wifi_ap_tcp_server.rs | 11 +++++++---- examples/rp/src/bin/wifi_blinky.rs | 11 +++++++---- examples/rp/src/bin/wifi_scan.rs | 11 +++++++---- examples/rp/src/bin/wifi_tcp_server.rs | 11 +++++++---- examples/rp/src/bin/wifi_webrequest.rs | 12 ++++++++---- tests/rp/src/bin/cyw43-perf.rs | 13 ++++++++++--- 7 files changed, 53 insertions(+), 26 deletions(-) diff --git a/examples/rp/src/bin/bluetooth.rs b/examples/rp/src/bin/bluetooth.rs index 7524e79293..358ee87a94 100644 --- a/examples/rp/src/bin/bluetooth.rs +++ b/examples/rp/src/bin/bluetooth.rs @@ -44,9 +44,13 @@ async fn main(spawner: Spawner) { // probe-rs download 43439A0.bin --format bin --chip RP2040 --base-address 0x10100000 // probe-rs download 43439A0_clm.bin --format bin --chip RP2040 --base-address 0x10140000 // probe-rs download 43439A0_btfw.bin --format bin --chip RP2040 --base-address 0x10141400 - //let fw = unsafe { core::slice::from_raw_parts(0x10100000 as *const u8, 224190) }; - //let clm = unsafe { core::slice::from_raw_parts(0x10140000 as *const u8, 4752) }; - //let btfw = unsafe { core::slice::from_raw_parts(0x10141400 as *const u8, 6164) }; + // + //const FW_SZ:usize = include_bytes!("../../../../cyw43-firmware/43439A0.bin").len(); + //const CLM_SZ:usize = include_bytes!("../../../../cyw43-firmware/43439A0_clm.bin").len(); + //const BTFW_SZ:usize = include_bytes!("../../../../cyw43-firmware/43439A0_btfw.bin").len(); + //let fw = unsafe { core::slice::from_raw_parts(0x10100000 as *const u8, FW_SZ) }; + //let clm = unsafe { core::slice::from_raw_parts(0x10140000 as *const u8, CLM_SZ) }; + //let btfw = unsafe { core::slice::from_raw_parts(0x10141400 as *const u8, BTFW_SZ) }; let pwr = Output::new(p.PIN_23, Level::Low); let cs = Output::new(p.PIN_25, Level::High); diff --git a/examples/rp/src/bin/wifi_ap_tcp_server.rs b/examples/rp/src/bin/wifi_ap_tcp_server.rs index 4c96514330..abc48cc710 100644 --- a/examples/rp/src/bin/wifi_ap_tcp_server.rs +++ b/examples/rp/src/bin/wifi_ap_tcp_server.rs @@ -49,10 +49,13 @@ async fn main(spawner: Spawner) { // 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 43439A0.bin --binary-format bin --chip RP2040 --base-address 0x10100000 - // probe-rs download 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) }; + // probe-rs download 43439A0.bin --binary-format bin --chip RP2040 --base-address 0x101b0000 + // probe-rs download 43439A0_clm.bin --binary-format bin --chip RP2040 --base-address 0x101f8000 + // + //const FW_SZ: usize = include_bytes!("../../../../cyw43-firmware/43439A0.bin").len(); + //const CLM_SZ: usize = include_bytes!("../../../../cyw43-firmware/43439A0_clm.bin").len(); + //let fw = unsafe { core::slice::from_raw_parts(0x101b0000 as *const u8, FW_SZ) }; + //let clm = unsafe { core::slice::from_raw_parts(0x101f8000 as *const u8, CLM_SZ) }; let pwr = Output::new(p.PIN_23, Level::Low); let cs = Output::new(p.PIN_25, Level::High); diff --git a/examples/rp/src/bin/wifi_blinky.rs b/examples/rp/src/bin/wifi_blinky.rs index 0107a2326e..b309b90e6b 100644 --- a/examples/rp/src/bin/wifi_blinky.rs +++ b/examples/rp/src/bin/wifi_blinky.rs @@ -33,10 +33,13 @@ async fn main(spawner: Spawner) { // 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) }; + // probe-rs download 43439A0.bin --binary-format bin --chip RP2040 --base-address 0x101b0000 + // probe-rs download 43439A0_clm.bin --binary-format bin --chip RP2040 --base-address 0x101f8000 + // + //const FW_SZ: usize = include_bytes!("../../../../cyw43-firmware/43439A0.bin").len(); + //const CLM_SZ: usize = include_bytes!("../../../../cyw43-firmware/43439A0_clm.bin").len(); + //let fw = unsafe { core::slice::from_raw_parts(0x101b0000 as *const u8, FW_SZ) }; + //let clm = unsafe { core::slice::from_raw_parts(0x101f8000 as *const u8, CLM_SZ) }; let pwr = Output::new(p.PIN_23, Level::Low); let cs = Output::new(p.PIN_25, Level::High); diff --git a/examples/rp/src/bin/wifi_scan.rs b/examples/rp/src/bin/wifi_scan.rs index 434f0074cb..0c73a89894 100644 --- a/examples/rp/src/bin/wifi_scan.rs +++ b/examples/rp/src/bin/wifi_scan.rs @@ -42,10 +42,13 @@ async fn main(spawner: Spawner) { // 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 43439A0.bin --binary-format bin --chip RP2040 --base-address 0x10100000 - // probe-rs download 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) }; + // probe-rs download 43439A0.bin --binary-format bin --chip RP2040 --base-address 0x101b0000 + // probe-rs download 43439A0_clm.bin --binary-format bin --chip RP2040 --base-address 0x101f8000 + // + //const FW_SZ: usize = include_bytes!("../../../../cyw43-firmware/43439A0.bin").len(); + //const CLM_SZ: usize = include_bytes!("../../../../cyw43-firmware/43439A0_clm.bin").len(); + //let fw = unsafe { core::slice::from_raw_parts(0x101b0000 as *const u8, FW_SZ) }; + //let clm = unsafe { core::slice::from_raw_parts(0x101f8000 as *const u8, CLM_SZ) }; let pwr = Output::new(p.PIN_23, Level::Low); let cs = Output::new(p.PIN_25, Level::High); diff --git a/examples/rp/src/bin/wifi_tcp_server.rs b/examples/rp/src/bin/wifi_tcp_server.rs index 7bf546e011..5718ac978e 100644 --- a/examples/rp/src/bin/wifi_tcp_server.rs +++ b/examples/rp/src/bin/wifi_tcp_server.rs @@ -53,10 +53,13 @@ async fn main(spawner: Spawner) { // 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 43439A0.bin --binary-format bin --chip RP2040 --base-address 0x10100000 - // probe-rs download 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) }; + // probe-rs download 43439A0.bin --binary-format bin --chip RP2040 --base-address 0x101b0000 + // probe-rs download 43439A0_clm.bin --binary-format bin --chip RP2040 --base-address 0x101f8000 + // + //const FW_SZ: usize = include_bytes!("../../../../cyw43-firmware/43439A0.bin").len(); + //const CLM_SZ: usize = include_bytes!("../../../../cyw43-firmware/43439A0_clm.bin").len(); + //let fw = unsafe { core::slice::from_raw_parts(0x101b0000 as *const u8, FW_SZ) }; + //let clm = unsafe { core::slice::from_raw_parts(0x101f8000 as *const u8, CLM_SZ) }; let pwr = Output::new(p.PIN_23, Level::Low); let cs = Output::new(p.PIN_25, Level::High); diff --git a/examples/rp/src/bin/wifi_webrequest.rs b/examples/rp/src/bin/wifi_webrequest.rs index 1ae9099175..3044cb2c85 100644 --- a/examples/rp/src/bin/wifi_webrequest.rs +++ b/examples/rp/src/bin/wifi_webrequest.rs @@ -53,12 +53,16 @@ async fn main(spawner: Spawner) { 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 43439A0.bin --binary-format bin --chip RP2040 --base-address 0x10100000 - // probe-rs download 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) }; + // probe-rs download 43439A0.bin --binary-format bin --chip RP2040 --base-address 0x101b0000 + // probe-rs download 43439A0_clm.bin --binary-format bin --chip RP2040 --base-address 0x101f8000 + // + //const FW_SZ: usize = include_bytes!("../../../../cyw43-firmware/43439A0.bin").len(); + //const CLM_SZ: usize = include_bytes!("../../../../cyw43-firmware/43439A0_clm.bin").len(); + //let fw = unsafe { core::slice::from_raw_parts(0x101b0000 as *const u8, FW_SZ) }; + //let clm = unsafe { core::slice::from_raw_parts(0x101f8000 as *const u8, CLM_SZ) }; let pwr = Output::new(p.PIN_23, Level::Low); let cs = Output::new(p.PIN_25, Level::High); diff --git a/tests/rp/src/bin/cyw43-perf.rs b/tests/rp/src/bin/cyw43-perf.rs index 30e4afb077..d16312ea04 100644 --- a/tests/rp/src/bin/cyw43-perf.rs +++ b/tests/rp/src/bin/cyw43-perf.rs @@ -4,7 +4,7 @@ teleprobe_meta::target!(b"rpi-pico"); use cyw43::JoinOptions; use cyw43_pio::PioSpi; -use defmt::{panic, *}; +use defmt::{assert, panic, info, unwrap}; use embassy_executor::Spawner; use embassy_net::{Config, StackResources}; use embassy_rp::gpio::{Level, Output}; @@ -48,8 +48,15 @@ async fn main(spawner: Spawner) { // cyw43 firmware needs to be flashed manually: // probe-rs download 43439A0.bin --binary-format bin --chip RP2040 --base-address 0x101b0000 // probe-rs download 43439A0_clm.bin --binary-format bin --chip RP2040 --base-address 0x101f8000 - let fw = unsafe { core::slice::from_raw_parts(0x101b0000 as *const u8, 230321) }; - let clm = unsafe { core::slice::from_raw_parts(0x101f8000 as *const u8, 4752) }; + + const FW_ADDR: usize = 0x101b0000; + const CLM_ADDR: usize = 0x101f8000; + const FW_SZ: usize = include_bytes!("../../../../cyw43-firmware/43439A0.bin").len(); + const CLM_SZ: usize = include_bytes!("../../../../cyw43-firmware/43439A0_clm.bin").len(); + // ensure that FW and CLM do not overlap + crate::assert!(CLM_ADDR < (FW_ADDR + FW_SZ)); + let fw = unsafe { core::slice::from_raw_parts(FW_ADDR as *const u8, FW_SZ) }; + let clm = unsafe { core::slice::from_raw_parts(CLM_ADDR as *const u8, CLM_SZ) }; let pwr = Output::new(p.PIN_23, Level::Low); let cs = Output::new(p.PIN_25, Level::High);