From 660fc4f7602c0be689e2c6cb4b20e55a26127636 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 26 Nov 2025 14:35:18 +0100 Subject: feat: support nrf54 GRTC as time-driver * Refactor GRTC peripheral splitting it into multiple channels * Reserve channel 1 for time-driver if enabled * Implement time-driver using GRTC (RTC peripheral is now removed). * Add timer example to nrf54l15 --- examples/nrf54l15/Cargo.toml | 2 +- examples/nrf54l15/src/bin/rtc.rs | 56 -------------------------------------- examples/nrf54l15/src/bin/timer.rs | 30 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 57 deletions(-) delete mode 100644 examples/nrf54l15/src/bin/rtc.rs create mode 100644 examples/nrf54l15/src/bin/timer.rs (limited to 'examples') diff --git a/examples/nrf54l15/Cargo.toml b/examples/nrf54l15/Cargo.toml index 4ef77279f..f34df0f26 100644 --- a/examples/nrf54l15/Cargo.toml +++ b/examples/nrf54l15/Cargo.toml @@ -10,7 +10,7 @@ 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", "nrf54l15-app-s", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] } +embassy-nrf = { version = "0.8.0", path = "../../embassy-nrf", features = ["defmt", "nrf54l15-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"] } diff --git a/examples/nrf54l15/src/bin/rtc.rs b/examples/nrf54l15/src/bin/rtc.rs deleted file mode 100644 index a45aaca52..000000000 --- a/examples/nrf54l15/src/bin/rtc.rs +++ /dev/null @@ -1,56 +0,0 @@ -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use embassy_executor::Spawner; -use embassy_nrf::gpio::{Level, Output, OutputDrive}; -use embassy_nrf::interrupt; -use embassy_nrf::rtc::Rtc; -use embassy_sync::blocking_mutex::Mutex; -use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; -use portable_atomic::AtomicU64; -use {defmt_rtt as _, panic_probe as _}; - -// 64 bit counter which will never overflow. -static TICK_COUNTER: AtomicU64 = AtomicU64::new(0); -static RTC: Mutex>>> = Mutex::new(RefCell::new(None)); - -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - defmt::println!("nRF54L15 RTC example"); - let p = embassy_nrf::init(Default::default()); - let mut led = Output::new(p.P2_09, Level::High, OutputDrive::Standard); - // Counter resolution is 125 ms. - let mut rtc = Rtc::new(p.RTC10, (1 << 12) - 1).unwrap(); - rtc.enable_interrupt(embassy_nrf::rtc::Interrupt::Tick, true); - rtc.enable_event(embassy_nrf::rtc::Interrupt::Tick); - rtc.enable(); - RTC.lock(|r| { - let mut rtc_borrow = r.borrow_mut(); - *rtc_borrow = Some(rtc); - }); - - let mut last_counter_val = 0; - loop { - let current = TICK_COUNTER.load(core::sync::atomic::Ordering::Relaxed); - if current != last_counter_val { - led.toggle(); - last_counter_val = current; - } - } -} - -#[interrupt] -fn RTC10() { - // For 64-bit, we do not need to worry about overflowing, at least not for realistic program - // lifetimes. - TICK_COUNTER.fetch_add(1, core::sync::atomic::Ordering::Relaxed); - RTC.lock(|r| { - let mut rtc_borrow = r.borrow_mut(); - rtc_borrow - .as_mut() - .unwrap() - .reset_event(embassy_nrf::rtc::Interrupt::Tick); - }); -} diff --git a/examples/nrf54l15/src/bin/timer.rs b/examples/nrf54l15/src/bin/timer.rs new file mode 100644 index 000000000..68acc91c1 --- /dev/null +++ b/examples/nrf54l15/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 From e5651b8644877969859505efc6d6c872b5c71b7a Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Thu, 27 Nov 2025 14:21:09 +0100 Subject: chore: release embassy-rp, cyw43 and cyw43-pio --- examples/boot/application/rp/Cargo.toml | 4 ++-- examples/rp/Cargo.toml | 6 +++--- examples/rp235x/Cargo.toml | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'examples') diff --git a/examples/boot/application/rp/Cargo.toml b/examples/boot/application/rp/Cargo.toml index 70a2c28c3..292d1abec 100644 --- a/examples/boot/application/rp/Cargo.toml +++ b/examples/boot/application/rp/Cargo.toml @@ -9,8 +9,8 @@ publish = false embassy-sync = { version = "0.7.2", path = "../../../../embassy-sync" } embassy-executor = { version = "0.9.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread"] } embassy-time = { version = "0.5.0", path = "../../../../embassy-time", features = [] } -embassy-rp = { version = "0.8.0", path = "../../../../embassy-rp", features = ["time-driver", "rp2040"] } -embassy-boot-rp = { version = "0.8.0", path = "../../../../embassy-boot-rp", features = [] } +embassy-rp = { version = "0.9.0", path = "../../../../embassy-rp", features = ["time-driver", "rp2040"] } +embassy-boot-rp = { version = "0.9.0", path = "../../../../embassy-boot-rp", features = [] } embassy-embedded-hal = { version = "0.5.0", path = "../../../../embassy-embedded-hal" } defmt = "1.0.1" diff --git a/examples/rp/Cargo.toml b/examples/rp/Cargo.toml index 9d7d99259..e247f6f7a 100644 --- a/examples/rp/Cargo.toml +++ b/examples/rp/Cargo.toml @@ -11,14 +11,14 @@ embassy-embedded-hal = { version = "0.5.0", path = "../../embassy-embedded-hal", embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt"] } 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-rp = { version = "0.8.0", path = "../../embassy-rp", features = ["defmt", "unstable-pac", "time-driver", "critical-section-impl", "rp2040"] } +embassy-rp = { version = "0.9.0", path = "../../embassy-rp", features = ["defmt", "unstable-pac", "time-driver", "critical-section-impl", "rp2040"] } embassy-usb = { version = "0.5.1", path = "../../embassy-usb", features = ["defmt"] } embassy-net = { version = "0.7.1", path = "../../embassy-net", features = ["defmt", "icmp", "tcp", "udp", "raw", "dhcpv4", "medium-ethernet", "dns", "proto-ipv4", "proto-ipv6", "multicast"] } embassy-net-wiznet = { version = "0.2.1", path = "../../embassy-net-wiznet", features = ["defmt"] } embassy-futures = { version = "0.1.2", path = "../../embassy-futures" } embassy-usb-logger = { version = "0.5.1", path = "../../embassy-usb-logger" } -cyw43 = { version = "0.5.0", path = "../../cyw43", features = ["defmt", "firmware-logs"] } -cyw43-pio = { version = "0.8.0", path = "../../cyw43-pio", features = ["defmt"] } +cyw43 = { version = "0.6.0", path = "../../cyw43", features = ["defmt", "firmware-logs"] } +cyw43-pio = { version = "0.9.0", path = "../../cyw43-pio", features = ["defmt"] } defmt = "1.0.1" defmt-rtt = "1.0.0" diff --git a/examples/rp235x/Cargo.toml b/examples/rp235x/Cargo.toml index ad396275b..16dfb5b77 100644 --- a/examples/rp235x/Cargo.toml +++ b/examples/rp235x/Cargo.toml @@ -11,14 +11,14 @@ embassy-embedded-hal = { version = "0.5.0", path = "../../embassy-embedded-hal", embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt"] } 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-rp = { version = "0.8.0", path = "../../embassy-rp", features = ["defmt", "unstable-pac", "time-driver", "critical-section-impl", "rp235xa", "binary-info"] } +embassy-rp = { version = "0.9.0", path = "../../embassy-rp", features = ["defmt", "unstable-pac", "time-driver", "critical-section-impl", "rp235xa", "binary-info"] } embassy-usb = { version = "0.5.1", path = "../../embassy-usb", features = ["defmt"] } embassy-net = { version = "0.7.1", path = "../../embassy-net", features = ["defmt", "icmp", "tcp", "udp", "raw", "dhcpv4", "medium-ethernet", "dns"] } embassy-net-wiznet = { version = "0.2.1", path = "../../embassy-net-wiznet", features = ["defmt"] } embassy-futures = { version = "0.1.2", path = "../../embassy-futures" } embassy-usb-logger = { version = "0.5.1", path = "../../embassy-usb-logger" } -cyw43 = { version = "0.5.0", path = "../../cyw43", features = ["defmt", "firmware-logs"] } -cyw43-pio = { version = "0.8.0", path = "../../cyw43-pio", features = ["defmt"] } +cyw43 = { version = "0.6.0", path = "../../cyw43", features = ["defmt", "firmware-logs"] } +cyw43-pio = { version = "0.9.0", path = "../../cyw43-pio", features = ["defmt"] } defmt = "1.0.1" defmt-rtt = "1.0.0" -- cgit