diff options
| author | Curly <[email protected]> | 2025-02-23 07:37:34 -0800 |
|---|---|---|
| committer | Curly <[email protected]> | 2025-02-23 07:37:34 -0800 |
| commit | 2d0e0f51f84bd5a2de9cbb82b6fc17d946299172 (patch) | |
| tree | 9ecc417d8fea6d1e1387dc468b6313b692400822 /examples | |
| parent | 3932835998802fc3abf7cce4f736e072858ebfd1 (diff) | |
add `rp235x` blinky_wifi.rs` to support RPi Pico 2 W
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/rp235x/src/bin/blinky_wifi.rs | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/examples/rp235x/src/bin/blinky_wifi.rs b/examples/rp235x/src/bin/blinky_wifi.rs new file mode 100644 index 000000000..7aeb38f1e --- /dev/null +++ b/examples/rp235x/src/bin/blinky_wifi.rs | |||
| @@ -0,0 +1,89 @@ | |||
| 1 | //! This example tests the RP Pico 2 W onboard LED. | ||
| 2 | //! | ||
| 3 | //! It does not work with the RP Pico 2 board. See `blinky.rs`. | ||
| 4 | |||
| 5 | #![no_std] | ||
| 6 | #![no_main] | ||
| 7 | |||
| 8 | use cyw43_pio::{PioSpi, DEFAULT_CLOCK_DIVIDER}; | ||
| 9 | use defmt::*; | ||
| 10 | use embassy_executor::Spawner; | ||
| 11 | use embassy_rp::bind_interrupts; | ||
| 12 | use embassy_rp::gpio::{Level, Output}; | ||
| 13 | use embassy_rp::peripherals::{DMA_CH0, PIO0}; | ||
| 14 | use embassy_rp::pio::{InterruptHandler, Pio}; | ||
| 15 | use embassy_time::{Duration, Timer}; | ||
| 16 | use static_cell::StaticCell; | ||
| 17 | use {defmt_rtt as _, panic_probe as _}; | ||
| 18 | |||
| 19 | // Program metadata for `picotool info`. | ||
| 20 | // This isn't needed, but it's recommended to have these minimal entries. | ||
| 21 | #[link_section = ".bi_entries"] | ||
| 22 | #[used] | ||
| 23 | pub static PICOTOOL_ENTRIES: [embassy_rp::binary_info::EntryAddr; 4] = [ | ||
| 24 | embassy_rp::binary_info::rp_program_name!(c"Blinky Example"), | ||
| 25 | embassy_rp::binary_info::rp_program_description!( | ||
| 26 | c"This example tests the RP Pico 2 W's onboard LED, connected to GPIO 0 of the cyw43 \ | ||
| 27 | (WiFi chip) via PIO 0 over the SPI bus." | ||
| 28 | ), | ||
| 29 | embassy_rp::binary_info::rp_cargo_version!(), | ||
| 30 | embassy_rp::binary_info::rp_program_build_attribute!(), | ||
| 31 | ]; | ||
| 32 | |||
| 33 | bind_interrupts!(struct Irqs { | ||
| 34 | PIO0_IRQ_0 => InterruptHandler<PIO0>; | ||
| 35 | }); | ||
| 36 | |||
| 37 | #[embassy_executor::task] | ||
| 38 | async fn cyw43_task(runner: cyw43::Runner<'static, Output<'static>, PioSpi<'static, PIO0, 0, DMA_CH0>>) -> ! { | ||
| 39 | runner.run().await | ||
| 40 | } | ||
| 41 | |||
| 42 | #[embassy_executor::main] | ||
| 43 | async fn main(spawner: Spawner) { | ||
| 44 | let p = embassy_rp::init(Default::default()); | ||
| 45 | let fw = include_bytes!("../../../../cyw43-firmware/43439A0.bin"); | ||
| 46 | let clm = include_bytes!("../../../../cyw43-firmware/43439A0_clm.bin"); | ||
| 47 | |||
| 48 | // To make flashing faster for development, you may want to flash the firmwares independently | ||
| 49 | // at hardcoded addresses, instead of baking them into the program with `include_bytes!`: | ||
| 50 | // probe-rs download ../../cyw43-firmware/43439A0.bin --binary-format bin --chip RP2040 --base-address 0x10100000 | ||
| 51 | // probe-rs download ../../cyw43-firmware/43439A0_clm.bin --binary-format bin --chip RP2040 --base-address 0x10140000 | ||
| 52 | //let fw = unsafe { core::slice::from_raw_parts(0x10100000 as *const u8, 230321) }; | ||
| 53 | //let clm = unsafe { core::slice::from_raw_parts(0x10140000 as *const u8, 4752) }; | ||
| 54 | |||
| 55 | let pwr = Output::new(p.PIN_23, Level::Low); | ||
| 56 | let cs = Output::new(p.PIN_25, Level::High); | ||
| 57 | let mut pio = Pio::new(p.PIO0, Irqs); | ||
| 58 | let spi = PioSpi::new( | ||
| 59 | &mut pio.common, | ||
| 60 | pio.sm0, | ||
| 61 | DEFAULT_CLOCK_DIVIDER, | ||
| 62 | pio.irq0, | ||
| 63 | cs, | ||
| 64 | p.PIN_24, | ||
| 65 | p.PIN_29, | ||
| 66 | p.DMA_CH0, | ||
| 67 | ); | ||
| 68 | |||
| 69 | static STATE: StaticCell<cyw43::State> = StaticCell::new(); | ||
| 70 | let state = STATE.init(cyw43::State::new()); | ||
| 71 | let (_net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; | ||
| 72 | unwrap!(spawner.spawn(cyw43_task(runner))); | ||
| 73 | |||
| 74 | control.init(clm).await; | ||
| 75 | control | ||
| 76 | .set_power_management(cyw43::PowerManagementMode::PowerSave) | ||
| 77 | .await; | ||
| 78 | |||
| 79 | let delay = Duration::from_millis(250); | ||
| 80 | loop { | ||
| 81 | info!("led on!"); | ||
| 82 | control.gpio_set(0, true).await; | ||
| 83 | Timer::after(delay).await; | ||
| 84 | |||
| 85 | info!("led off!"); | ||
| 86 | control.gpio_set(0, false).await; | ||
| 87 | Timer::after(delay).await; | ||
| 88 | } | ||
| 89 | } | ||
