From 8cf8b2406d4be014d466a9318303a65c5c7ff076 Mon Sep 17 00:00:00 2001 From: Haobo Gu Date: Mon, 8 Dec 2025 17:21:27 +0800 Subject: feat: add nRF54LM20A support Signed-off-by: Haobo Gu --- examples/nrf54lm20/.cargo/config.toml | 10 ++++++ examples/nrf54lm20/Cargo.toml | 37 +++++++++++++++++++++ examples/nrf54lm20/build.rs | 35 ++++++++++++++++++++ examples/nrf54lm20/memory.x | 5 +++ examples/nrf54lm20/run.sh | 15 +++++++++ examples/nrf54lm20/src/bin/blinky.rs | 23 +++++++++++++ examples/nrf54lm20/src/bin/gpio.rs | 23 +++++++++++++ examples/nrf54lm20/src/bin/gpiote_channel.rs | 49 ++++++++++++++++++++++++++++ examples/nrf54lm20/src/bin/gpiote_port.rs | 33 +++++++++++++++++++ examples/nrf54lm20/src/bin/timer.rs | 30 +++++++++++++++++ 10 files changed, 260 insertions(+) create mode 100644 examples/nrf54lm20/.cargo/config.toml create mode 100644 examples/nrf54lm20/Cargo.toml create mode 100644 examples/nrf54lm20/build.rs create mode 100644 examples/nrf54lm20/memory.x create mode 100755 examples/nrf54lm20/run.sh create mode 100644 examples/nrf54lm20/src/bin/blinky.rs create mode 100644 examples/nrf54lm20/src/bin/gpio.rs create mode 100644 examples/nrf54lm20/src/bin/gpiote_channel.rs create mode 100644 examples/nrf54lm20/src/bin/gpiote_port.rs create mode 100644 examples/nrf54lm20/src/bin/timer.rs (limited to 'examples') diff --git a/examples/nrf54lm20/.cargo/config.toml b/examples/nrf54lm20/.cargo/config.toml new file mode 100644 index 000000000..e26853bef --- /dev/null +++ b/examples/nrf54lm20/.cargo/config.toml @@ -0,0 +1,10 @@ +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +# runner = "probe-rs run --chip nrf54lm20" +# probe-rs doesn't support nRF54LM20A right now, so jlink is needed +runner = "./run.sh" + +[build] +target = "thumbv8m.main-none-eabihf" + +[env] +DEFMT_LOG = "trace" diff --git a/examples/nrf54lm20/Cargo.toml b/examples/nrf54lm20/Cargo.toml new file mode 100644 index 000000000..5482fc77a --- /dev/null +++ b/examples/nrf54lm20/Cargo.toml @@ -0,0 +1,37 @@ +[package] +edition = "2024" +name = "embassy-nrf54lm20-examples" +version = "0.1.0" +license = "MIT OR Apache-2.0" +publish = false + +[dependencies] +embassy-futures = { version = "0.1.2", path = "../../embassy-futures" } +embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] } +embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } +embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt"] } +embassy-nrf = { version = "0.8.0", path = "../../embassy-nrf", features = ["defmt", "nrf54lm20-app-s", "time-driver-grtc", "gpiote", "unstable-pac", "time"] } +embedded-io = { version = "0.6.0", features = ["defmt-03"] } +embedded-io-async = { version = "0.6.1", features = ["defmt-03"] } + +rand = { version = "0.9.0", default-features = false } + +defmt = "1.0.1" +defmt-rtt = "1.0.0" +panic-probe = { version = "1.0.0", features = ["print-defmt"] } + +cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } +cortex-m-rt = "0.7.0" + +embedded-storage = "0.3.1" +portable-atomic = "1" + +static_cell = "2" + +[profile.release] +debug = 2 + +[package.metadata.embassy] +build = [ + { target = "thumbv8m.main-none-eabihf", artifact-dir = "out/examples/nrf54lm20" } +] diff --git a/examples/nrf54lm20/build.rs b/examples/nrf54lm20/build.rs new file mode 100644 index 000000000..30691aa97 --- /dev/null +++ b/examples/nrf54lm20/build.rs @@ -0,0 +1,35 @@ +//! This build script copies the `memory.x` file from the crate root into +//! a directory where the linker can always find it at build time. +//! For many projects this is optional, as the linker always searches the +//! project root directory -- wherever `Cargo.toml` is. However, if you +//! are using a workspace or have a more complicated build setup, this +//! build script becomes required. Additionally, by requesting that +//! Cargo re-run the build script whenever `memory.x` is changed, +//! updating `memory.x` ensures a rebuild of the application with the +//! new memory settings. + +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"); + + println!("cargo:rustc-link-arg-bins=--nmagic"); + println!("cargo:rustc-link-arg-bins=-Tlink.x"); + println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); +} diff --git a/examples/nrf54lm20/memory.x b/examples/nrf54lm20/memory.x new file mode 100644 index 000000000..564f488ac --- /dev/null +++ b/examples/nrf54lm20/memory.x @@ -0,0 +1,5 @@ +MEMORY +{ + FLASH : ORIGIN = 0x00000000, LENGTH = 2036K + RAM : ORIGIN = 0x20000000, LENGTH = 512K +} diff --git a/examples/nrf54lm20/run.sh b/examples/nrf54lm20/run.sh new file mode 100755 index 000000000..2386163a7 --- /dev/null +++ b/examples/nrf54lm20/run.sh @@ -0,0 +1,15 @@ +cp $1 $1.elf + +ELF_FILE="$1.elf" + +JLinkExe <) { + loop { + pin.wait_for_low().await; + info!("Button {:?} pressed!", n); + pin.wait_for_high().await; + info!("Button {:?} released!", n); + } +} + +#[embassy_executor::main] +async fn main(spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); + info!("Starting!"); + + let btn1 = Input::new(p.P1_26, Pull::Up); + let btn2 = Input::new(p.P1_09, Pull::Up); + let btn3 = Input::new(p.P1_08, Pull::Up); + let btn4 = Input::new(p.P0_05, Pull::Up); + + spawner.spawn(unwrap!(button_task(1, btn1))); + spawner.spawn(unwrap!(button_task(2, btn2))); + spawner.spawn(unwrap!(button_task(3, btn3))); + spawner.spawn(unwrap!(button_task(4, btn4))); +} diff --git a/examples/nrf54lm20/src/bin/timer.rs b/examples/nrf54lm20/src/bin/timer.rs new file mode 100644 index 000000000..68acc91c1 --- /dev/null +++ b/examples/nrf54lm20/src/bin/timer.rs @@ -0,0 +1,30 @@ +#![no_std] +#![no_main] + +use defmt::{info, unwrap}; +use embassy_executor::Spawner; +use embassy_time::Timer; +use {defmt_rtt as _, panic_probe as _}; + +#[embassy_executor::task] +async fn run1() { + loop { + info!("BIG INFREQUENT TICK"); + Timer::after_secs(10).await; + } +} + +#[embassy_executor::task] +async fn run2() { + loop { + info!("tick"); + Timer::after_secs(1).await; + } +} + +#[embassy_executor::main] +async fn main(spawner: Spawner) { + let _p = embassy_nrf::init(Default::default()); + spawner.spawn(unwrap!(run1())); + spawner.spawn(unwrap!(run2())); +} -- cgit