aboutsummaryrefslogtreecommitdiff
path: root/examples/mimxrt6
diff options
context:
space:
mode:
authorFelipe Balbi <[email protected]>2025-04-03 08:47:25 -0700
committerFelipe Balbi <[email protected]>2025-04-09 09:37:45 -0700
commitaa9a16e569dfb56ce2b689733975f4d854af0b00 (patch)
tree865ae0aa84bcb4c438463d34dd567ea07abe98e3 /examples/mimxrt6
parent0ec3e78c1bb0cdb20749cca4b294cb8a16e7fd43 (diff)
Add embassy-imxrt
Adds initial support for MIMXRT600 series MCUs from NXP. Subsequent PRs will add more drivers.
Diffstat (limited to 'examples/mimxrt6')
-rw-r--r--examples/mimxrt6/.cargo/config.toml17
-rw-r--r--examples/mimxrt6/.gitignore14
-rw-r--r--examples/mimxrt6/Cargo.toml60
-rw-r--r--examples/mimxrt6/README.md18
-rw-r--r--examples/mimxrt6/build.rs45
-rw-r--r--examples/mimxrt6/memory.x34
-rw-r--r--examples/mimxrt6/src/bin/blinky.rs29
-rw-r--r--examples/mimxrt6/src/bin/hello.rs17
-rw-r--r--examples/mimxrt6/src/lib.rs20
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]
2runner = 'probe-rs run --chip MIMXRT685SFVKB'
3
4rustflags = [
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]
14target = "thumbv8m.main-none-eabihf" # Cortex-M33
15
16[env]
17DEFMT_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
8Cargo.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]
2name = "embassy-imxrt-examples"
3version = "0.1.0"
4edition = "2021"
5license = "MIT or Apache-2.0"
6
7[dependencies]
8cortex-m = { version = "0.7.7", features = ["inline-asm", "critical-section-single-core"] }
9cortex-m-rt = "0.7.3"
10defmt = "1.0"
11defmt-rtt = "1.0"
12
13embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] }
14embassy-futures = { version = "0.1.1", path = "../../embassy-futures" }
15embassy-imxrt = { version = "0.1.0", path = "../../embassy-imxrt", features = ["defmt", "mimxrt685s", "unstable-pac"] }
16embassy-sync = { version = "0.6.2", path = "../../embassy-sync", features = ["defmt"] }
17embedded-hal-1 = { package = "embedded-hal", version = "1.0" }
18embedded-hal-async = "1.0.0"
19
20mimxrt600-fcb = "0.1.0"
21panic-probe = { version = "0.3", features = ["print-defmt"] }
22rand = { version = "0.8.5", default-features = false }
23
24# cargo build/run
25[profile.dev]
26codegen-units = 1
27debug = 2
28debug-assertions = true # <-
29incremental = false
30opt-level = 3 # <-
31overflow-checks = true # <-
32
33# cargo test
34[profile.test]
35codegen-units = 1
36debug = 2
37debug-assertions = true # <-
38incremental = false
39opt-level = 3 # <-
40overflow-checks = true # <-
41
42# cargo build/run --release
43[profile.release]
44codegen-units = 1
45debug = 2
46debug-assertions = false # <-
47incremental = false
48lto = 'fat'
49opt-level = 3 # <-
50overflow-checks = false # <-
51
52# cargo test --release
53[profile.bench]
54codegen-units = 1
55debug = 2
56debug-assertions = false # <-
57incremental = false
58lto = 'fat'
59opt-level = 3 # <-
60overflow-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
5These examples illustrates how to use the embassy-imxrt HAL.
6
7## Adding Examples
8Add 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
15Assuming 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 @@
1use std::env;
2use std::fs::File;
3use std::io::Write;
4use std::path::PathBuf;
5
6fn 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]
30static 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 @@
1MEMORY {
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
10SECTIONS {
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
4extern crate embassy_imxrt_examples;
5
6use defmt::info;
7use embassy_executor::Spawner;
8use embassy_imxrt::gpio;
9
10#[embassy_executor::main]
11async 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
4extern crate embassy_imxrt_examples;
5
6use defmt::info;
7use embassy_executor::Spawner;
8use {defmt_rtt as _, panic_probe as _};
9
10#[embassy_executor::main]
11async 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
3use mimxrt600_fcb::FlexSPIFlashConfigurationBlock;
4use {defmt_rtt as _, panic_probe as _};
5
6// auto-generated version information from Cargo.toml
7include!(concat!(env!("OUT_DIR"), "/biv.rs"));
8
9#[link_section = ".otfad"]
10#[used]
11static OTFAD: [u8; 256] = [0; 256];
12
13#[rustfmt::skip]
14#[link_section = ".fcb"]
15#[used]
16static FCB: FlexSPIFlashConfigurationBlock = FlexSPIFlashConfigurationBlock::build();
17
18#[link_section = ".keystore"]
19#[used]
20static KEYSTORE: [u8; 2048] = [0; 2048];