aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-07-10 19:45:26 +0200
committerDario Nieuwenhuis <[email protected]>2022-07-10 19:45:26 +0200
commite560415fde967483573d42f628e52501768584e0 (patch)
tree864f2141d7351b0f1940ee2015d1c7d5c3d37ad1 /examples
:rainbow:
Diffstat (limited to 'examples')
-rw-r--r--examples/rpi-pico-w/.cargo/config.toml8
-rw-r--r--examples/rpi-pico-w/Cargo.toml59
-rw-r--r--examples/rpi-pico-w/build.rs36
-rw-r--r--examples/rpi-pico-w/memory.x5
-rw-r--r--examples/rpi-pico-w/src/main.rs39
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"))']
2runner = "probe-run --chip RP2040"
3
4[build]
5target = "thumbv6m-none-eabi"
6
7[env]
8DEFMT_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]
2name = "cyw43-example-rpi-pico-w"
3version = "0.1.0"
4edition = "2021"
5
6
7[dependencies]
8cyw43 = { path = "../../", features = ["defmt"]}
9embassy = { version = "0.1.0", features = ["defmt", "defmt-timestamp-uptime"] }
10embassy-rp = { version = "0.1.0", features = ["defmt", "unstable-traits", "nightly", "unstable-pac"] }
11atomic-polyfill = "0.1.5"
12
13defmt = "0.3"
14defmt-rtt = "0.3"
15panic-probe = { version = "0.3", features = ["print-defmt"] }
16
17cortex-m = "0.7.3"
18cortex-m-rt = "0.7.0"
19futures = { version = "0.3.17", default-features = false, features = ["async-await", "cfg-target-has-atomic", "unstable"] }
20
21embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8" }
22embedded-hal-async = { version = "0.1.0-alpha.1" }
23
24
25[patch.crates-io]
26embassy = { git = "https://github.com/embassy-rs/embassy", rev = "5f43c1d37e9db847c7861fe0bd821db62edba9f6" }
27embassy-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]
32debug = 2
33debug-assertions = true
34opt-level = 1
35overflow-checks = true
36
37[profile.release]
38codegen-units = 1
39debug = 2
40debug-assertions = false
41incremental = false
42lto = 'fat'
43opt-level = 'z'
44overflow-checks = false
45
46# do not optimize proc-macro crates = faster builds from scratch
47[profile.dev.build-override]
48codegen-units = 8
49debug = false
50debug-assertions = false
51opt-level = 0
52overflow-checks = false
53
54[profile.release.build-override]
55codegen-units = 8
56debug = false
57debug-assertions = false
58opt-level = 0
59overflow-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
11use std::env;
12use std::fs::File;
13use std::io::Write;
14use std::path::PathBuf;
15
16fn 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 @@
1MEMORY {
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
5use core::slice;
6
7use defmt::{assert, assert_eq, panic, *};
8use embassy::executor::Spawner;
9use embassy_rp::gpio::{Flex, Level, Output, Pin};
10use embassy_rp::Peripherals;
11use {defmt_rtt as _, panic_probe as _};
12
13
14macro_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]
23async 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}