diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/mimxrt6/.cargo/config.toml | 17 | ||||
| -rw-r--r-- | examples/mimxrt6/.gitignore | 14 | ||||
| -rw-r--r-- | examples/mimxrt6/Cargo.toml | 60 | ||||
| -rw-r--r-- | examples/mimxrt6/README.md | 18 | ||||
| -rw-r--r-- | examples/mimxrt6/build.rs | 45 | ||||
| -rw-r--r-- | examples/mimxrt6/memory.x | 34 | ||||
| -rw-r--r-- | examples/mimxrt6/src/bin/blinky.rs | 29 | ||||
| -rw-r--r-- | examples/mimxrt6/src/bin/hello.rs | 17 | ||||
| -rw-r--r-- | examples/mimxrt6/src/lib.rs | 20 |
9 files changed, 254 insertions, 0 deletions
diff --git a/examples/mimxrt6/.cargo/config.toml b/examples/mimxrt6/.cargo/config.toml new file mode 100644 index 000000000..db42be81d --- /dev/null +++ b/examples/mimxrt6/.cargo/config.toml | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | [target.thumbv8m.main-none-eabihf] | ||
| 2 | runner = 'probe-rs run --chip MIMXRT685SFVKB' | ||
| 3 | |||
| 4 | rustflags = [ | ||
| 5 | "-C", "linker=flip-link", | ||
| 6 | "-C", "link-arg=-Tlink.x", | ||
| 7 | "-C", "link-arg=-Tdefmt.x", | ||
| 8 | # This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x | ||
| 9 | # See https://github.com/rust-embedded/cortex-m-quickstart/pull/95 | ||
| 10 | "-C", "link-arg=--nmagic", | ||
| 11 | ] | ||
| 12 | |||
| 13 | [build] | ||
| 14 | target = "thumbv8m.main-none-eabihf" # Cortex-M33 | ||
| 15 | |||
| 16 | [env] | ||
| 17 | DEFMT_LOG = "trace" | ||
diff --git a/examples/mimxrt6/.gitignore b/examples/mimxrt6/.gitignore new file mode 100644 index 000000000..418e01907 --- /dev/null +++ b/examples/mimxrt6/.gitignore | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | # Generated by Cargo | ||
| 2 | # will have compiled files and executables | ||
| 3 | /debug | ||
| 4 | /target | ||
| 5 | |||
| 6 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
| 7 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
| 8 | Cargo.lock | ||
| 9 | |||
| 10 | # These are backup files generated by rustfmt | ||
| 11 | **/*.rs.bk | ||
| 12 | |||
| 13 | # MSVC Windows builds of rustc generate these, which store debugging information | ||
| 14 | *.pdb | ||
diff --git a/examples/mimxrt6/Cargo.toml b/examples/mimxrt6/Cargo.toml new file mode 100644 index 000000000..894ce174c --- /dev/null +++ b/examples/mimxrt6/Cargo.toml | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | [package] | ||
| 2 | name = "embassy-imxrt-examples" | ||
| 3 | version = "0.1.0" | ||
| 4 | edition = "2021" | ||
| 5 | license = "MIT or Apache-2.0" | ||
| 6 | |||
| 7 | [dependencies] | ||
| 8 | cortex-m = { version = "0.7.7", features = ["inline-asm", "critical-section-single-core"] } | ||
| 9 | cortex-m-rt = "0.7.3" | ||
| 10 | defmt = "1.0" | ||
| 11 | defmt-rtt = "1.0" | ||
| 12 | |||
| 13 | embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] } | ||
| 14 | embassy-futures = { version = "0.1.1", path = "../../embassy-futures" } | ||
| 15 | embassy-imxrt = { version = "0.1.0", path = "../../embassy-imxrt", features = ["defmt", "mimxrt685s", "unstable-pac"] } | ||
| 16 | embassy-sync = { version = "0.6.2", path = "../../embassy-sync", features = ["defmt"] } | ||
| 17 | embedded-hal-1 = { package = "embedded-hal", version = "1.0" } | ||
| 18 | embedded-hal-async = "1.0.0" | ||
| 19 | |||
| 20 | mimxrt600-fcb = "0.1.0" | ||
| 21 | panic-probe = { version = "0.3", features = ["print-defmt"] } | ||
| 22 | rand = { version = "0.8.5", default-features = false } | ||
| 23 | |||
| 24 | # cargo build/run | ||
| 25 | [profile.dev] | ||
| 26 | codegen-units = 1 | ||
| 27 | debug = 2 | ||
| 28 | debug-assertions = true # <- | ||
| 29 | incremental = false | ||
| 30 | opt-level = 3 # <- | ||
| 31 | overflow-checks = true # <- | ||
| 32 | |||
| 33 | # cargo test | ||
| 34 | [profile.test] | ||
| 35 | codegen-units = 1 | ||
| 36 | debug = 2 | ||
| 37 | debug-assertions = true # <- | ||
| 38 | incremental = false | ||
| 39 | opt-level = 3 # <- | ||
| 40 | overflow-checks = true # <- | ||
| 41 | |||
| 42 | # cargo build/run --release | ||
| 43 | [profile.release] | ||
| 44 | codegen-units = 1 | ||
| 45 | debug = 2 | ||
| 46 | debug-assertions = false # <- | ||
| 47 | incremental = false | ||
| 48 | lto = 'fat' | ||
| 49 | opt-level = 3 # <- | ||
| 50 | overflow-checks = false # <- | ||
| 51 | |||
| 52 | # cargo test --release | ||
| 53 | [profile.bench] | ||
| 54 | codegen-units = 1 | ||
| 55 | debug = 2 | ||
| 56 | debug-assertions = false # <- | ||
| 57 | incremental = false | ||
| 58 | lto = 'fat' | ||
| 59 | opt-level = 3 # <- | ||
| 60 | overflow-checks = false # <- | ||
diff --git a/examples/mimxrt6/README.md b/examples/mimxrt6/README.md new file mode 100644 index 000000000..6d5031cf9 --- /dev/null +++ b/examples/mimxrt6/README.md | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | # embassy-imxrt-examples | ||
| 2 | |||
| 3 | ## Introduction | ||
| 4 | |||
| 5 | These examples illustrates how to use the embassy-imxrt HAL. | ||
| 6 | |||
| 7 | ## Adding Examples | ||
| 8 | Add uniquely named example to `src/bin` like `adc.rs` | ||
| 9 | |||
| 10 | ## Build | ||
| 11 | `cd` to examples folder | ||
| 12 | `cargo build --bin <example_name>` for example, `cargo build --bin adc` | ||
| 13 | |||
| 14 | ## Run | ||
| 15 | Assuming RT685 is powered and connected to Jlink debug probe and the latest probe-rs is installed via | ||
| 16 | `$ cargo install probe-rs-tools --git https://github.com/probe-rs/probe-rs --locked` | ||
| 17 | `cd` to examples folder | ||
| 18 | `cargo run --bin <example_name>` for example, `cargo run --bin adc` \ No newline at end of file | ||
diff --git a/examples/mimxrt6/build.rs b/examples/mimxrt6/build.rs new file mode 100644 index 000000000..9c0ed3213 --- /dev/null +++ b/examples/mimxrt6/build.rs | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | use std::env; | ||
| 2 | use std::fs::File; | ||
| 3 | use std::io::Write; | ||
| 4 | use std::path::PathBuf; | ||
| 5 | |||
| 6 | fn main() { | ||
| 7 | // Put `memory.x` in our output directory and ensure it's | ||
| 8 | // on the linker search path. | ||
| 9 | let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
| 10 | File::create(out.join("memory.x")) | ||
| 11 | .unwrap() | ||
| 12 | .write_all(include_bytes!("memory.x")) | ||
| 13 | .unwrap(); | ||
| 14 | println!("cargo:rustc-link-search={}", out.display()); | ||
| 15 | |||
| 16 | // By default, Cargo will re-run a build script whenever | ||
| 17 | // any file in the project changes. By specifying `memory.x` | ||
| 18 | // here, we ensure the build script is only re-run when | ||
| 19 | // `memory.x` is changed. | ||
| 20 | println!("cargo:rerun-if-changed=memory.x"); | ||
| 21 | |||
| 22 | // Inject crate version into the .biv section. | ||
| 23 | File::create(out.join("biv.rs")) | ||
| 24 | .unwrap() | ||
| 25 | .write_all( | ||
| 26 | format!( | ||
| 27 | r##" | ||
| 28 | #[link_section = ".biv"] | ||
| 29 | #[used] | ||
| 30 | static BOOT_IMAGE_VERSION: u32 = 0x{:02x}{:02x}{:02x}00; | ||
| 31 | "##, | ||
| 32 | env!("CARGO_PKG_VERSION_MAJOR") | ||
| 33 | .parse::<u8>() | ||
| 34 | .expect("should have major version"), | ||
| 35 | env!("CARGO_PKG_VERSION_MINOR") | ||
| 36 | .parse::<u8>() | ||
| 37 | .expect("should have minor version"), | ||
| 38 | env!("CARGO_PKG_VERSION_PATCH") | ||
| 39 | .parse::<u8>() | ||
| 40 | .expect("should have patch version"), | ||
| 41 | ) | ||
| 42 | .as_bytes(), | ||
| 43 | ) | ||
| 44 | .unwrap(); | ||
| 45 | } | ||
diff --git a/examples/mimxrt6/memory.x b/examples/mimxrt6/memory.x new file mode 100644 index 000000000..5ea82fd71 --- /dev/null +++ b/examples/mimxrt6/memory.x | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | MEMORY { | ||
| 2 | OTFAD : ORIGIN = 0x08000000, LENGTH = 256 | ||
| 3 | FCB : ORIGIN = 0x08000400, LENGTH = 512 | ||
| 4 | BIV : ORIGIN = 0x08000600, LENGTH = 4 | ||
| 5 | KEYSTORE : ORIGIN = 0x08000800, LENGTH = 2K | ||
| 6 | FLASH : ORIGIN = 0x08001000, LENGTH = 1M | ||
| 7 | RAM : ORIGIN = 0x20080000, LENGTH = 1536K | ||
| 8 | } | ||
| 9 | |||
| 10 | SECTIONS { | ||
| 11 | .otfad : { | ||
| 12 | . = ALIGN(4); | ||
| 13 | KEEP(* (.otfad)) | ||
| 14 | . = ALIGN(4); | ||
| 15 | } > OTFAD | ||
| 16 | |||
| 17 | .fcb : { | ||
| 18 | . = ALIGN(4); | ||
| 19 | KEEP(* (.fcb)) | ||
| 20 | . = ALIGN(4); | ||
| 21 | } > FCB | ||
| 22 | |||
| 23 | .biv : { | ||
| 24 | . = ALIGN(4); | ||
| 25 | KEEP(* (.biv)) | ||
| 26 | . = ALIGN(4); | ||
| 27 | } > BIV | ||
| 28 | |||
| 29 | .keystore : { | ||
| 30 | . = ALIGN(4); | ||
| 31 | KEEP(* (.keystore)) | ||
| 32 | . = ALIGN(4); | ||
| 33 | } > KEYSTORE | ||
| 34 | } | ||
diff --git a/examples/mimxrt6/src/bin/blinky.rs b/examples/mimxrt6/src/bin/blinky.rs new file mode 100644 index 000000000..e40e71e6f --- /dev/null +++ b/examples/mimxrt6/src/bin/blinky.rs | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | extern crate embassy_imxrt_examples; | ||
| 5 | |||
| 6 | use defmt::info; | ||
| 7 | use embassy_executor::Spawner; | ||
| 8 | use embassy_imxrt::gpio; | ||
| 9 | |||
| 10 | #[embassy_executor::main] | ||
| 11 | async fn main(_spawner: Spawner) { | ||
| 12 | let p = embassy_imxrt::init(Default::default()); | ||
| 13 | |||
| 14 | info!("Initializing GPIO"); | ||
| 15 | |||
| 16 | let mut led = gpio::Output::new( | ||
| 17 | p.PIO0_26, | ||
| 18 | gpio::Level::Low, | ||
| 19 | gpio::DriveMode::PushPull, | ||
| 20 | gpio::DriveStrength::Normal, | ||
| 21 | gpio::SlewRate::Standard, | ||
| 22 | ); | ||
| 23 | |||
| 24 | loop { | ||
| 25 | info!("Toggling LED"); | ||
| 26 | led.toggle(); | ||
| 27 | cortex_m::asm::delay(5_000_000); | ||
| 28 | } | ||
| 29 | } | ||
diff --git a/examples/mimxrt6/src/bin/hello.rs b/examples/mimxrt6/src/bin/hello.rs new file mode 100644 index 000000000..c640241ce --- /dev/null +++ b/examples/mimxrt6/src/bin/hello.rs | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | extern crate embassy_imxrt_examples; | ||
| 5 | |||
| 6 | use defmt::info; | ||
| 7 | use embassy_executor::Spawner; | ||
| 8 | use {defmt_rtt as _, panic_probe as _}; | ||
| 9 | |||
| 10 | #[embassy_executor::main] | ||
| 11 | async fn main(_spawner: Spawner) -> ! { | ||
| 12 | let _p = embassy_imxrt::init(Default::default()); | ||
| 13 | loop { | ||
| 14 | info!("Hello"); | ||
| 15 | cortex_m::asm::delay(5_000_000); | ||
| 16 | } | ||
| 17 | } | ||
diff --git a/examples/mimxrt6/src/lib.rs b/examples/mimxrt6/src/lib.rs new file mode 100644 index 000000000..da6e14427 --- /dev/null +++ b/examples/mimxrt6/src/lib.rs | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | #![no_std] | ||
| 2 | |||
| 3 | use mimxrt600_fcb::FlexSPIFlashConfigurationBlock; | ||
| 4 | use {defmt_rtt as _, panic_probe as _}; | ||
| 5 | |||
| 6 | // auto-generated version information from Cargo.toml | ||
| 7 | include!(concat!(env!("OUT_DIR"), "/biv.rs")); | ||
| 8 | |||
| 9 | #[link_section = ".otfad"] | ||
| 10 | #[used] | ||
| 11 | static OTFAD: [u8; 256] = [0; 256]; | ||
| 12 | |||
| 13 | #[rustfmt::skip] | ||
| 14 | #[link_section = ".fcb"] | ||
| 15 | #[used] | ||
| 16 | static FCB: FlexSPIFlashConfigurationBlock = FlexSPIFlashConfigurationBlock::build(); | ||
| 17 | |||
| 18 | #[link_section = ".keystore"] | ||
| 19 | #[used] | ||
| 20 | static KEYSTORE: [u8; 2048] = [0; 2048]; | ||
