From c02441837f433c44154b9634180ecc0c88b7c21c Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Thu, 4 Dec 2025 12:50:17 +0100 Subject: chore: expose uicr write functions Applications may need to write UICR registers independently of the HAL (for instance, softdevice-specific registers). Exposing these functions will allow that to be done in the correct way. --- embassy-nrf/src/lib.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index 4cb291626..b3a9c19d1 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs @@ -667,10 +667,11 @@ mod consts { pub const APPROTECT_DISABLED: u32 = 0x0000_005a; } +/// Result from writing UICR. #[cfg(not(any(feature = "_nrf51", feature = "_nrf54l")))] #[derive(Debug, Copy, Clone, Eq, PartialEq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -enum WriteResult { +pub enum WriteResult { /// Word was written successfully, needs reset. Written, /// Word was already set to the value we wanted to write, nothing was done. @@ -679,13 +680,21 @@ enum WriteResult { Failed, } +/// Write the UICR value at the provided address, ensuring that flash +/// settings are correctly apply to persist the value. +/// +/// Safety: the address must be a valid UICR register. #[cfg(not(any(feature = "_nrf51", feature = "_nrf54l")))] -unsafe fn uicr_write(address: *mut u32, value: u32) -> WriteResult { +pub unsafe fn uicr_write(address: *mut u32, value: u32) -> WriteResult { uicr_write_masked(address, value, 0xFFFF_FFFF) } #[cfg(not(any(feature = "_nrf51", feature = "_nrf54l")))] -unsafe fn uicr_write_masked(address: *mut u32, value: u32, mask: u32) -> WriteResult { +/// Write the UICR value at the provided address, ensuring that flash +/// settings are correctly apply to persist the value. +/// +/// Safety: the address must be a valid UICR register. +pub unsafe fn uicr_write_masked(address: *mut u32, value: u32, mask: u32) -> WriteResult { let curr_val = address.read_volatile(); if curr_val & mask == value & mask { return WriteResult::Noop; -- cgit From cf33f6fa76aad06837b2de900959ebbb33c96775 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Thu, 4 Dec 2025 13:00:21 +0100 Subject: chore: add changelog entry for uicr write --- embassy-nrf/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/embassy-nrf/CHANGELOG.md b/embassy-nrf/CHANGELOG.md index d26671674..2524464b0 100644 --- a/embassy-nrf/CHANGELOG.md +++ b/embassy-nrf/CHANGELOG.md @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - added: expose PPI events available on SPIS peripheral - added: add basic GRTC time driver support for nRF54L * added: support for nrf54l10 and nrf54l05 +* added: expose uicr write functions ## 0.8.0 - 2025-09-30 -- cgit