diff options
| author | Ulf Lilleengen <[email protected]> | 2025-12-04 12:50:17 +0100 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2025-12-04 12:50:17 +0100 |
| commit | c02441837f433c44154b9634180ecc0c88b7c21c (patch) | |
| tree | fd2c92de1a8d7bbd0c7ca5009697a88e558f70b9 /embassy-nrf | |
| parent | 336db1b0aa7d9180968a82e6e23ce68da53e3947 (diff) | |
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.
Diffstat (limited to 'embassy-nrf')
| -rw-r--r-- | embassy-nrf/src/lib.rs | 15 |
1 files 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 { | |||
| 667 | pub const APPROTECT_DISABLED: u32 = 0x0000_005a; | 667 | pub const APPROTECT_DISABLED: u32 = 0x0000_005a; |
| 668 | } | 668 | } |
| 669 | 669 | ||
| 670 | /// Result from writing UICR. | ||
| 670 | #[cfg(not(any(feature = "_nrf51", feature = "_nrf54l")))] | 671 | #[cfg(not(any(feature = "_nrf51", feature = "_nrf54l")))] |
| 671 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] | 672 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] |
| 672 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 673 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 673 | enum WriteResult { | 674 | pub enum WriteResult { |
| 674 | /// Word was written successfully, needs reset. | 675 | /// Word was written successfully, needs reset. |
| 675 | Written, | 676 | Written, |
| 676 | /// Word was already set to the value we wanted to write, nothing was done. | 677 | /// Word was already set to the value we wanted to write, nothing was done. |
| @@ -679,13 +680,21 @@ enum WriteResult { | |||
| 679 | Failed, | 680 | Failed, |
| 680 | } | 681 | } |
| 681 | 682 | ||
| 683 | /// Write the UICR value at the provided address, ensuring that flash | ||
| 684 | /// settings are correctly apply to persist the value. | ||
| 685 | /// | ||
| 686 | /// Safety: the address must be a valid UICR register. | ||
| 682 | #[cfg(not(any(feature = "_nrf51", feature = "_nrf54l")))] | 687 | #[cfg(not(any(feature = "_nrf51", feature = "_nrf54l")))] |
| 683 | unsafe fn uicr_write(address: *mut u32, value: u32) -> WriteResult { | 688 | pub unsafe fn uicr_write(address: *mut u32, value: u32) -> WriteResult { |
| 684 | uicr_write_masked(address, value, 0xFFFF_FFFF) | 689 | uicr_write_masked(address, value, 0xFFFF_FFFF) |
| 685 | } | 690 | } |
| 686 | 691 | ||
| 687 | #[cfg(not(any(feature = "_nrf51", feature = "_nrf54l")))] | 692 | #[cfg(not(any(feature = "_nrf51", feature = "_nrf54l")))] |
| 688 | unsafe fn uicr_write_masked(address: *mut u32, value: u32, mask: u32) -> WriteResult { | 693 | /// Write the UICR value at the provided address, ensuring that flash |
| 694 | /// settings are correctly apply to persist the value. | ||
| 695 | /// | ||
| 696 | /// Safety: the address must be a valid UICR register. | ||
| 697 | pub unsafe fn uicr_write_masked(address: *mut u32, value: u32, mask: u32) -> WriteResult { | ||
| 689 | let curr_val = address.read_volatile(); | 698 | let curr_val = address.read_volatile(); |
| 690 | if curr_val & mask == value & mask { | 699 | if curr_val & mask == value & mask { |
| 691 | return WriteResult::Noop; | 700 | return WriteResult::Noop; |
