diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-07-10 19:45:26 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-07-10 19:45:26 +0200 |
| commit | e560415fde967483573d42f628e52501768584e0 (patch) | |
| tree | 864f2141d7351b0f1940ee2015d1c7d5c3d37ad1 /examples | |
:rainbow:
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/rpi-pico-w/.cargo/config.toml | 8 | ||||
| -rw-r--r-- | examples/rpi-pico-w/Cargo.toml | 59 | ||||
| -rw-r--r-- | examples/rpi-pico-w/build.rs | 36 | ||||
| -rw-r--r-- | examples/rpi-pico-w/memory.x | 5 | ||||
| -rw-r--r-- | examples/rpi-pico-w/src/main.rs | 39 |
5 files changed, 147 insertions, 0 deletions
diff --git a/examples/rpi-pico-w/.cargo/config.toml b/examples/rpi-pico-w/.cargo/config.toml new file mode 100644 index 000000000..18bd4dfe8 --- /dev/null +++ b/examples/rpi-pico-w/.cargo/config.toml | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | ||
| 2 | runner = "probe-run --chip RP2040" | ||
| 3 | |||
| 4 | [build] | ||
| 5 | target = "thumbv6m-none-eabi" | ||
| 6 | |||
| 7 | [env] | ||
| 8 | DEFMT_LOG = "trace" | ||
diff --git a/examples/rpi-pico-w/Cargo.toml b/examples/rpi-pico-w/Cargo.toml new file mode 100644 index 000000000..8dbcb20d4 --- /dev/null +++ b/examples/rpi-pico-w/Cargo.toml | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | [package] | ||
| 2 | name = "cyw43-example-rpi-pico-w" | ||
| 3 | version = "0.1.0" | ||
| 4 | edition = "2021" | ||
| 5 | |||
| 6 | |||
| 7 | [dependencies] | ||
| 8 | cyw43 = { path = "../../", features = ["defmt"]} | ||
| 9 | embassy = { version = "0.1.0", features = ["defmt", "defmt-timestamp-uptime"] } | ||
| 10 | embassy-rp = { version = "0.1.0", features = ["defmt", "unstable-traits", "nightly", "unstable-pac"] } | ||
| 11 | atomic-polyfill = "0.1.5" | ||
| 12 | |||
| 13 | defmt = "0.3" | ||
| 14 | defmt-rtt = "0.3" | ||
| 15 | panic-probe = { version = "0.3", features = ["print-defmt"] } | ||
| 16 | |||
| 17 | cortex-m = "0.7.3" | ||
| 18 | cortex-m-rt = "0.7.0" | ||
| 19 | futures = { version = "0.3.17", default-features = false, features = ["async-await", "cfg-target-has-atomic", "unstable"] } | ||
| 20 | |||
| 21 | embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8" } | ||
| 22 | embedded-hal-async = { version = "0.1.0-alpha.1" } | ||
| 23 | |||
| 24 | |||
| 25 | [patch.crates-io] | ||
| 26 | embassy = { git = "https://github.com/embassy-rs/embassy", rev = "5f43c1d37e9db847c7861fe0bd821db62edba9f6" } | ||
| 27 | embassy-rp = { git = "https://github.com/embassy-rs/embassy", rev = "5f43c1d37e9db847c7861fe0bd821db62edba9f6" } | ||
| 28 | #embassy = { path = "/home/dirbaio/embassy/embassy/embassy" } | ||
| 29 | #embassy-rp = { path = "/home/dirbaio/embassy/embassy/embassy-rp" } | ||
| 30 | |||
| 31 | [profile.dev] | ||
| 32 | debug = 2 | ||
| 33 | debug-assertions = true | ||
| 34 | opt-level = 1 | ||
| 35 | overflow-checks = true | ||
| 36 | |||
| 37 | [profile.release] | ||
| 38 | codegen-units = 1 | ||
| 39 | debug = 2 | ||
| 40 | debug-assertions = false | ||
| 41 | incremental = false | ||
| 42 | lto = 'fat' | ||
| 43 | opt-level = 'z' | ||
| 44 | overflow-checks = false | ||
| 45 | |||
| 46 | # do not optimize proc-macro crates = faster builds from scratch | ||
| 47 | [profile.dev.build-override] | ||
| 48 | codegen-units = 8 | ||
| 49 | debug = false | ||
| 50 | debug-assertions = false | ||
| 51 | opt-level = 0 | ||
| 52 | overflow-checks = false | ||
| 53 | |||
| 54 | [profile.release.build-override] | ||
| 55 | codegen-units = 8 | ||
| 56 | debug = false | ||
| 57 | debug-assertions = false | ||
| 58 | opt-level = 0 | ||
| 59 | overflow-checks = false | ||
diff --git a/examples/rpi-pico-w/build.rs b/examples/rpi-pico-w/build.rs new file mode 100644 index 000000000..3f915f931 --- /dev/null +++ b/examples/rpi-pico-w/build.rs | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | //! This build script copies the `memory.x` file from the crate root into | ||
| 2 | //! a directory where the linker can always find it at build time. | ||
| 3 | //! For many projects this is optional, as the linker always searches the | ||
| 4 | //! project root directory -- wherever `Cargo.toml` is. However, if you | ||
| 5 | //! are using a workspace or have a more complicated build setup, this | ||
| 6 | //! build script becomes required. Additionally, by requesting that | ||
| 7 | //! Cargo re-run the build script whenever `memory.x` is changed, | ||
| 8 | //! updating `memory.x` ensures a rebuild of the application with the | ||
| 9 | //! new memory settings. | ||
| 10 | |||
| 11 | use std::env; | ||
| 12 | use std::fs::File; | ||
| 13 | use std::io::Write; | ||
| 14 | use std::path::PathBuf; | ||
| 15 | |||
| 16 | fn main() { | ||
| 17 | // Put `memory.x` in our output directory and ensure it's | ||
| 18 | // on the linker search path. | ||
| 19 | let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
| 20 | File::create(out.join("memory.x")) | ||
| 21 | .unwrap() | ||
| 22 | .write_all(include_bytes!("memory.x")) | ||
| 23 | .unwrap(); | ||
| 24 | println!("cargo:rustc-link-search={}", out.display()); | ||
| 25 | |||
| 26 | // By default, Cargo will re-run a build script whenever | ||
| 27 | // any file in the project changes. By specifying `memory.x` | ||
| 28 | // here, we ensure the build script is only re-run when | ||
| 29 | // `memory.x` is changed. | ||
| 30 | println!("cargo:rerun-if-changed=memory.x"); | ||
| 31 | |||
| 32 | println!("cargo:rustc-link-arg-bins=--nmagic"); | ||
| 33 | println!("cargo:rustc-link-arg-bins=-Tlink.x"); | ||
| 34 | println!("cargo:rustc-link-arg-bins=-Tlink-rp.x"); | ||
| 35 | println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); | ||
| 36 | } | ||
diff --git a/examples/rpi-pico-w/memory.x b/examples/rpi-pico-w/memory.x new file mode 100644 index 000000000..eb8c1731d --- /dev/null +++ b/examples/rpi-pico-w/memory.x | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | MEMORY { | ||
| 2 | BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100 | ||
| 3 | FLASH : ORIGIN = 0x10000100, LENGTH = 1024K - 0x100 | ||
| 4 | RAM : ORIGIN = 0x20000000, LENGTH = 256K | ||
| 5 | } \ No newline at end of file | ||
diff --git a/examples/rpi-pico-w/src/main.rs b/examples/rpi-pico-w/src/main.rs new file mode 100644 index 000000000..de8c5a2ba --- /dev/null +++ b/examples/rpi-pico-w/src/main.rs | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait, concat_bytes)] | ||
| 4 | |||
| 5 | use core::slice; | ||
| 6 | |||
| 7 | use defmt::{assert, assert_eq, panic, *}; | ||
| 8 | use embassy::executor::Spawner; | ||
| 9 | use embassy_rp::gpio::{Flex, Level, Output, Pin}; | ||
| 10 | use embassy_rp::Peripherals; | ||
| 11 | use {defmt_rtt as _, panic_probe as _}; | ||
| 12 | |||
| 13 | |||
| 14 | macro_rules! forever { | ||
| 15 | ($val:expr) => {{ | ||
| 16 | type T = impl Sized; | ||
| 17 | static FOREVER: Forever<T> = Forever::new(); | ||
| 18 | FOREVER.put_with(move || $val) | ||
| 19 | }}; | ||
| 20 | } | ||
| 21 | |||
| 22 | #[embassy::main] | ||
| 23 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 24 | info!("Hello World!"); | ||
| 25 | |||
| 26 | let (pwr, cs, clk, dio) = (p.PIN_23, p.PIN_25, p.PIN_29, p.PIN_24); | ||
| 27 | //let (pwr, cs, clk, dio) = (p.PIN_23, p.PIN_0, p.PIN_1, p.PIN_2); | ||
| 28 | |||
| 29 | let mut driver = cyw43::Driver::new( | ||
| 30 | Output::new(pwr, Level::Low), | ||
| 31 | Output::new(cs, Level::High), | ||
| 32 | Output::new(clk, Level::Low), | ||
| 33 | Flex::new(dio), | ||
| 34 | ); | ||
| 35 | |||
| 36 | driver.init().await; | ||
| 37 | |||
| 38 | loop {} | ||
| 39 | } | ||
