···11+[package]
22+name = "embassy_rp_w_template"
33+version = "0.1.0"
44+edition = "2021"
55+66+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77+88+[dependencies]
99+embassy-embedded-hal = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy.git", rev = "2b031756c6d705f58de972de48f7300b4fdc673c", features = [
1010+ "defmt",
1111+] }
1212+embassy-sync = { version = "0.6.0", git = "https://github.com/embassy-rs/embassy.git", rev = "2b031756c6d705f58de972de48f7300b4fdc673c", features = [
1313+ "defmt",
1414+] }
1515+embassy-executor = { version = "0.5.0", git = "https://github.com/embassy-rs/embassy.git", rev = "2b031756c6d705f58de972de48f7300b4fdc673c", features = [
1616+ "task-arena-size-98304",
1717+ "arch-cortex-m",
1818+ "executor-thread",
1919+ "executor-interrupt",
2020+ "defmt",
2121+ "integrated-timers",
2222+] }
2323+embassy-time = { version = "0.3.1", git = "https://github.com/embassy-rs/embassy.git", rev = "2b031756c6d705f58de972de48f7300b4fdc673c", features = [
2424+ "defmt",
2525+ "defmt-timestamp-uptime",
2626+] }
2727+embassy-rp = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy.git", rev = "2b031756c6d705f58de972de48f7300b4fdc673c", features = [
2828+ "defmt",
2929+ "unstable-pac",
3030+ "time-driver",
3131+ "critical-section-impl",
3232+] }
3333+embassy-usb = { version = "0.2.0", git = "https://github.com/embassy-rs/embassy.git", rev = "2b031756c6d705f58de972de48f7300b4fdc673c", features = [
3434+ "defmt",
3535+] }
3636+embassy-net = { version = "0.4.0", git = "https://github.com/embassy-rs/embassy.git", rev = "2b031756c6d705f58de972de48f7300b4fdc673c", features = [
3737+ "defmt",
3838+ "tcp",
3939+ "udp",
4040+ "raw",
4141+ "dhcpv4",
4242+ "medium-ethernet",
4343+ "dns",
4444+] }
4545+embassy-net-wiznet = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy.git", rev = "2b031756c6d705f58de972de48f7300b4fdc673c", features = [
4646+ "defmt",
4747+] }
4848+embassy-futures = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy.git" }
4949+embassy-usb-logger = { version = "0.2.0", git = "https://github.com/embassy-rs/embassy.git" }
5050+cyw43 = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy.git", rev = "2b031756c6d705f58de972de48f7300b4fdc673c", features = [
5151+ "defmt",
5252+ "firmware-logs",
5353+] }
5454+cyw43-pio = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy.git", rev = "2b031756c6d705f58de972de48f7300b4fdc673c", features = [
5555+ "defmt",
5656+ "overclock",
5757+] }
5858+5959+defmt = "0.3"
6060+defmt-rtt = "0.4"
6161+fixed = "1.23.1"
6262+fixed-macro = "1.2"
6363+6464+# for web request example
6565+reqwless = { version = "0.12.0", features = ["defmt"] }
6666+serde = { version = "1.0.203", default-features = false, features = ["derive"] }
6767+serde-json-core = "0.5.1"
6868+6969+assign-resources = { git = "https://github.com/adamgreig/assign-resources", rev = "94ad10e2729afdf0fd5a77cd12e68409a982f58a" }
7070+7171+# for assign resources example
7272+#cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
7373+cortex-m = { version = "0.7.6", features = ["inline-asm"] }
7474+cortex-m-rt = "0.7.0"
7575+critical-section = "1.1"
7676+panic-probe = { version = "0.3", features = ["print-defmt"] }
7777+display-interface-spi = "0.4.1"
7878+embedded-graphics = "0.7.1"
7979+st7789 = "0.6.1"
8080+display-interface = "0.4.1"
8181+byte-slice-cast = { version = "1.2.0", default-features = false }
8282+smart-leds = "0.3.0"
8383+heapless = { version = "0.8", features = ["serde"] }
8484+usbd-hid = "0.8.1"
8585+8686+embedded-hal-1 = { package = "embedded-hal", version = "1.0" }
8787+embedded-hal-async = "1.0"
8888+embedded-hal-bus = { version = "0.1", features = ["async"] }
8989+embedded-io-async = { version = "0.6.1", features = ["defmt-03"] }
9090+embedded-storage = { version = "0.3" }
9191+static_cell = "2"
9292+portable-atomic = { version = "1.5", features = ["critical-section"] }
9393+log = "0.4"
9494+pio-proc = "0.2"
9595+pio = "0.2.1"
9696+rand = { version = "0.8.5", default-features = false }
9797+embedded-sdmmc = "0.7.0"
9898+9999+[profile.release]
100100+debug = 2
101101+102102+[profile.dev]
103103+lto = true
104104+opt-level = "z"
+21
LICENSE
···11+MIT License
22+33+Copyright (c) 2024 Bailey Townsend
44+55+Permission is hereby granted, free of charge, to any person obtaining a copy
66+of this software and associated documentation files (the "Software"), to deal
77+in the Software without restriction, including without limitation the rights
88+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99+copies of the Software, and to permit persons to whom the Software is
1010+furnished to do so, subject to the following conditions:
1111+1212+The above copyright notice and this permission notice shall be included in all
1313+copies or substantial portions of the Software.
1414+1515+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121+SOFTWARE.
+13
README.md
···11+## Raspberry Pico W Embassy Template
22+33+This is just a simple template for setting up a project using [embassy_rp](https://github.com/embassy-rs/embassy/tree/2d678d695637ed1023fd80fea482d60a288e4343/embassy-rp). This currently pulls all dependencies from the embassy repo because I found some of the examples not working with the latest versions of the dependencies on crates.io. Currently pulling commit `2b031756c6d705f58de972de48f7300b4fdc673c` of the embassy repo. Also will notice the `cargo.toml` has everything including the kitchen sink. Trim what you don't need, this is mostly for beginners(me) to get started with.
44+55+Will notice this is the Wifi Blinky example. I did this so I can include the cyw43 firmware and an example of how to load it onto the pico.
66+77+## Setup
88+99+Refer to [embassy](https://github.com/embassy-rs/embassy). Feel free to leave a issue though if you would like help setting up.
1010+1111+## How do I do xyz?
1212+1313+Check the the [embassy_rp examples](https://github.com/embassy-rs/embassy/tree/2d678d695637ed1023fd80fea482d60a288e4343/examples/rp). Should ideally be able to take any of those and run it inside of this template, this is what it is based off of.
+36
build.rs
···11+//! This build script copies the `memory.x` file from the crate root into
22+//! a directory where the linker can always find it at build time.
33+//! For many projects this is optional, as the linker always searches the
44+//! project root directory -- wherever `Cargo.toml` is. However, if you
55+//! are using a workspace or have a more complicated build setup, this
66+//! build script becomes required. Additionally, by requesting that
77+//! Cargo re-run the build script whenever `memory.x` is changed,
88+//! updating `memory.x` ensures a rebuild of the application with the
99+//! new memory settings.
1010+1111+use std::env;
1212+use std::fs::File;
1313+use std::io::Write;
1414+use std::path::PathBuf;
1515+1616+fn main() {
1717+ // Put `memory.x` in our output directory and ensure it's
1818+ // on the linker search path.
1919+ let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
2020+ File::create(out.join("memory.x"))
2121+ .unwrap()
2222+ .write_all(include_bytes!("memory.x"))
2323+ .unwrap();
2424+ println!("cargo:rustc-link-search={}", out.display());
2525+2626+ // By default, Cargo will re-run a build script whenever
2727+ // any file in the project changes. By specifying `memory.x`
2828+ // here, we ensure the build script is only re-run when
2929+ // `memory.x` is changed.
3030+ println!("cargo:rerun-if-changed=memory.x");
3131+3232+ println!("cargo:rustc-link-arg-bins=--nmagic");
3333+ println!("cargo:rustc-link-arg-bins=-Tlink.x");
3434+ println!("cargo:rustc-link-arg-bins=-Tlink-rp.x");
3535+ println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
3636+}
cyw43-firmware/43439A0.bin
This is a binary file and will not be displayed.
cyw43-firmware/43439A0_clm.bin
This is a binary file and will not be displayed.
+17
memory.x
···11+MEMORY {
22+ BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100
33+ FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100
44+55+ /* Pick one of the two options for RAM layout */
66+77+ /* OPTION A: Use all RAM banks as one big block */
88+ /* Reasonable, unless you are doing something */
99+ /* really particular with DMA or other concurrent */
1010+ /* access that would benefit from striping */
1111+ RAM : ORIGIN = 0x20000000, LENGTH = 264K
1212+1313+ /* OPTION B: Keep the unstriped sections separate */
1414+ /* RAM: ORIGIN = 0x20000000, LENGTH = 256K */
1515+ /* SCRATCH_A: ORIGIN = 0x20040000, LENGTH = 4K */
1616+ /* SCRATCH_B: ORIGIN = 0x20041000, LENGTH = 4K */
1717+}
+57
src/control_driver.rs
···11+use cyw43::Control;
22+use cyw43_pio::PioSpi;
33+use defmt::unwrap;
44+use embassy_executor::Spawner;
55+use embassy_rp::bind_interrupts;
66+use embassy_rp::gpio::{Level, Output};
77+use embassy_rp::peripherals::{DMA_CH0, PIO0};
88+use embassy_rp::peripherals::{PIN_23, PIN_24, PIN_25, PIN_29};
99+use embassy_rp::pio::{InterruptHandler, Pio};
1010+use static_cell::StaticCell;
1111+1212+bind_interrupts!(struct Irqs {
1313+ PIO0_IRQ_0 => InterruptHandler<PIO0>;
1414+});
1515+1616+#[embassy_executor::task]
1717+async fn wifi_task(
1818+ runner: cyw43::Runner<'static, Output<'static>, PioSpi<'static, PIO0, 0, DMA_CH0>>,
1919+) -> ! {
2020+ runner.run().await
2121+}
2222+2323+pub async fn setup_control<'a>(
2424+ pio0: PIO0,
2525+ p_23: PIN_23,
2626+ p_24: PIN_24,
2727+ p_25: PIN_25,
2828+ p_29: PIN_29,
2929+ dma_ch0: DMA_CH0,
3030+ spawner: Spawner,
3131+) -> Control<'a> {
3232+ let fw = include_bytes!("../cyw43-firmware/43439A0.bin");
3333+ let clm = include_bytes!("../cyw43-firmware/43439A0_clm.bin");
3434+3535+ // To make flashing faster for development, you may want to flash the firmwares independently
3636+ // at hardcoded addresses, instead of baking them into the program with `include_bytes!`:
3737+ // probe-rs download 43439A0.bin --binary-format bin --chip RP2040 --base-address 0x10100000
3838+ // probe-rs download 43439A0_clm.bin --binary-format bin --chip RP2040 --base-address 0x10140000
3939+ // let clm = unsafe { core::slice::from_raw_parts(0x10140000 as *const u8, 4752) };
4040+ // let fw = unsafe { core::slice::from_raw_parts(0x10100000 as *const u8, 230321) };
4141+4242+ let pwr = Output::new(p_23, Level::Low);
4343+ let cs = Output::new(p_25, Level::High);
4444+ let mut pio = Pio::new(pio0, Irqs);
4545+ let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p_24, p_29, dma_ch0);
4646+4747+ static STATE: StaticCell<cyw43::State> = StaticCell::new();
4848+ let state = STATE.init(cyw43::State::new());
4949+ let (_net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await;
5050+ unwrap!(spawner.spawn(wifi_task(runner)));
5151+5252+ control.init(clm).await;
5353+ control
5454+ .set_power_management(cyw43::PowerManagementMode::PowerSave)
5555+ .await;
5656+ control
5757+}
+35
src/main.rs
···11+//! This example test the RP Pico W on board LED.
22+//!
33+//! It does not work with the RP Pico board.
44+55+#![no_std]
66+#![no_main]
77+88+use control_driver::setup_control;
99+use defmt::*;
1010+use embassy_executor::Spawner;
1111+use embassy_time::{Duration, Timer};
1212+use {defmt_rtt as _, panic_probe as _};
1313+1414+mod control_driver;
1515+#[embassy_executor::main]
1616+async fn main(spawner: Spawner) {
1717+ let p = embassy_rp::init(Default::default());
1818+ let mut control = setup_control(
1919+ p.PIO0, p.PIN_23, p.PIN_24, p.PIN_25, p.PIN_29, p.DMA_CH0, spawner,
2020+ )
2121+ .await;
2222+2323+ let delay = Duration::from_secs(1);
2424+2525+ loop {
2626+ info!("led on!");
2727+ control.gpio_set(0, true).await;
2828+ Timer::after(delay).await;
2929+3030+ info!("led off!");
3131+ control.gpio_set(0, false).await;
3232+3333+ Timer::after(delay).await;
3434+ }
3535+}