Add embassy-imxrt

Adds initial support for MIMXRT600 series MCUs from NXP. Subsequent
PRs will add more drivers.
This commit is contained in:
Felipe Balbi
2025-04-03 08:47:25 -07:00
parent 0ec3e78c1b
commit aa9a16e569
21 changed files with 5041 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
[target.thumbv8m.main-none-eabihf]
runner = 'probe-rs run --chip MIMXRT685SFVKB'
rustflags = [
"-C", "linker=flip-link",
"-C", "link-arg=-Tlink.x",
"-C", "link-arg=-Tdefmt.x",
# This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x
# See https://github.com/rust-embedded/cortex-m-quickstart/pull/95
"-C", "link-arg=--nmagic",
]
[build]
target = "thumbv8m.main-none-eabihf" # Cortex-M33
[env]
DEFMT_LOG = "trace"

14
examples/mimxrt6/.gitignore vendored Normal file
View File

@@ -0,0 +1,14 @@
# Generated by Cargo
# will have compiled files and executables
/debug
/target
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

View File

@@ -0,0 +1,60 @@
[package]
name = "embassy-imxrt-examples"
version = "0.1.0"
edition = "2021"
license = "MIT or Apache-2.0"
[dependencies]
cortex-m = { version = "0.7.7", features = ["inline-asm", "critical-section-single-core"] }
cortex-m-rt = "0.7.3"
defmt = "1.0"
defmt-rtt = "1.0"
embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] }
embassy-futures = { version = "0.1.1", path = "../../embassy-futures" }
embassy-imxrt = { version = "0.1.0", path = "../../embassy-imxrt", features = ["defmt", "mimxrt685s", "unstable-pac"] }
embassy-sync = { version = "0.6.2", path = "../../embassy-sync", features = ["defmt"] }
embedded-hal-1 = { package = "embedded-hal", version = "1.0" }
embedded-hal-async = "1.0.0"
mimxrt600-fcb = "0.1.0"
panic-probe = { version = "0.3", features = ["print-defmt"] }
rand = { version = "0.8.5", default-features = false }
# cargo build/run
[profile.dev]
codegen-units = 1
debug = 2
debug-assertions = true # <-
incremental = false
opt-level = 3 # <-
overflow-checks = true # <-
# cargo test
[profile.test]
codegen-units = 1
debug = 2
debug-assertions = true # <-
incremental = false
opt-level = 3 # <-
overflow-checks = true # <-
# cargo build/run --release
[profile.release]
codegen-units = 1
debug = 2
debug-assertions = false # <-
incremental = false
lto = 'fat'
opt-level = 3 # <-
overflow-checks = false # <-
# cargo test --release
[profile.bench]
codegen-units = 1
debug = 2
debug-assertions = false # <-
incremental = false
lto = 'fat'
opt-level = 3 # <-
overflow-checks = false # <-

View File

@@ -0,0 +1,18 @@
# embassy-imxrt-examples
## Introduction
These examples illustrates how to use the embassy-imxrt HAL.
## Adding Examples
Add uniquely named example to `src/bin` like `adc.rs`
## Build
`cd` to examples folder
`cargo build --bin <example_name>` for example, `cargo build --bin adc`
## Run
Assuming RT685 is powered and connected to Jlink debug probe and the latest probe-rs is installed via
`$ cargo install probe-rs-tools --git https://github.com/probe-rs/probe-rs --locked`
`cd` to examples folder
`cargo run --bin <example_name>` for example, `cargo run --bin adc`

45
examples/mimxrt6/build.rs Normal file
View File

@@ -0,0 +1,45 @@
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
fn main() {
// Put `memory.x` in our output directory and ensure it's
// on the linker search path.
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
File::create(out.join("memory.x"))
.unwrap()
.write_all(include_bytes!("memory.x"))
.unwrap();
println!("cargo:rustc-link-search={}", out.display());
// By default, Cargo will re-run a build script whenever
// any file in the project changes. By specifying `memory.x`
// here, we ensure the build script is only re-run when
// `memory.x` is changed.
println!("cargo:rerun-if-changed=memory.x");
// Inject crate version into the .biv section.
File::create(out.join("biv.rs"))
.unwrap()
.write_all(
format!(
r##"
#[link_section = ".biv"]
#[used]
static BOOT_IMAGE_VERSION: u32 = 0x{:02x}{:02x}{:02x}00;
"##,
env!("CARGO_PKG_VERSION_MAJOR")
.parse::<u8>()
.expect("should have major version"),
env!("CARGO_PKG_VERSION_MINOR")
.parse::<u8>()
.expect("should have minor version"),
env!("CARGO_PKG_VERSION_PATCH")
.parse::<u8>()
.expect("should have patch version"),
)
.as_bytes(),
)
.unwrap();
}

34
examples/mimxrt6/memory.x Normal file
View File

@@ -0,0 +1,34 @@
MEMORY {
OTFAD : ORIGIN = 0x08000000, LENGTH = 256
FCB : ORIGIN = 0x08000400, LENGTH = 512
BIV : ORIGIN = 0x08000600, LENGTH = 4
KEYSTORE : ORIGIN = 0x08000800, LENGTH = 2K
FLASH : ORIGIN = 0x08001000, LENGTH = 1M
RAM : ORIGIN = 0x20080000, LENGTH = 1536K
}
SECTIONS {
.otfad : {
. = ALIGN(4);
KEEP(* (.otfad))
. = ALIGN(4);
} > OTFAD
.fcb : {
. = ALIGN(4);
KEEP(* (.fcb))
. = ALIGN(4);
} > FCB
.biv : {
. = ALIGN(4);
KEEP(* (.biv))
. = ALIGN(4);
} > BIV
.keystore : {
. = ALIGN(4);
KEEP(* (.keystore))
. = ALIGN(4);
} > KEYSTORE
}

View File

@@ -0,0 +1,29 @@
#![no_std]
#![no_main]
extern crate embassy_imxrt_examples;
use defmt::info;
use embassy_executor::Spawner;
use embassy_imxrt::gpio;
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_imxrt::init(Default::default());
info!("Initializing GPIO");
let mut led = gpio::Output::new(
p.PIO0_26,
gpio::Level::Low,
gpio::DriveMode::PushPull,
gpio::DriveStrength::Normal,
gpio::SlewRate::Standard,
);
loop {
info!("Toggling LED");
led.toggle();
cortex_m::asm::delay(5_000_000);
}
}

View File

@@ -0,0 +1,17 @@
#![no_std]
#![no_main]
extern crate embassy_imxrt_examples;
use defmt::info;
use embassy_executor::Spawner;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
async fn main(_spawner: Spawner) -> ! {
let _p = embassy_imxrt::init(Default::default());
loop {
info!("Hello");
cortex_m::asm::delay(5_000_000);
}
}

View File

@@ -0,0 +1,20 @@
#![no_std]
use mimxrt600_fcb::FlexSPIFlashConfigurationBlock;
use {defmt_rtt as _, panic_probe as _};
// auto-generated version information from Cargo.toml
include!(concat!(env!("OUT_DIR"), "/biv.rs"));
#[link_section = ".otfad"]
#[used]
static OTFAD: [u8; 256] = [0; 256];
#[rustfmt::skip]
#[link_section = ".fcb"]
#[used]
static FCB: FlexSPIFlashConfigurationBlock = FlexSPIFlashConfigurationBlock::build();
#[link_section = ".keystore"]
#[used]
static KEYSTORE: [u8; 2048] = [0; 2048];