aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-nrf/src/lib.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs
index 9d44ae7e6..44990ed85 100644
--- a/embassy-nrf/src/lib.rs
+++ b/embassy-nrf/src/lib.rs
@@ -586,6 +586,8 @@ mod consts {
586 pub const UICR_APPROTECT: *mut u32 = 0x00FF8000 as *mut u32; 586 pub const UICR_APPROTECT: *mut u32 = 0x00FF8000 as *mut u32;
587 pub const UICR_SECUREAPPROTECT: *mut u32 = 0x00FF802C as *mut u32; 587 pub const UICR_SECUREAPPROTECT: *mut u32 = 0x00FF802C as *mut u32;
588 pub const APPROTECT_ENABLED: u32 = 0x0000_0000; 588 pub const APPROTECT_ENABLED: u32 = 0x0000_0000;
589 #[cfg(feature = "_nrf9120")]
590 pub const APPROTECT_DISABLED: u32 = 0x50FA50FA;
589} 591}
590 592
591#[cfg(feature = "_nrf5340-app")] 593#[cfg(feature = "_nrf5340-app")]
@@ -768,6 +770,28 @@ pub fn init(config: config::Config) -> Peripherals {
768 } 770 }
769 771
770 // nothing to do on the nrf9160, debug is allowed by default. 772 // nothing to do on the nrf9160, debug is allowed by default.
773
774 // nrf9151, nrf9161 use the new-style approtect that requires writing a register.
775 #[cfg(feature = "nrf9120-s")]
776 unsafe {
777 let p = pac::APPROTECT_S;
778
779 let res = uicr_write(consts::UICR_APPROTECT, consts::APPROTECT_DISABLED);
780 needs_reset |= res == WriteResult::Written;
781 p.approtect()
782 .disable()
783 .write(|w| w.set_disable(pac::approtect::vals::ApprotectDisableDisable::SW_UNPROTECTED));
784
785 let res = uicr_write(consts::UICR_SECUREAPPROTECT, consts::APPROTECT_DISABLED);
786 needs_reset |= res == WriteResult::Written;
787 p.secureapprotect()
788 .disable()
789 .write(|w| w.set_disable(pac::approtect::vals::SecureapprotectDisableDisable::SW_UNPROTECTED));
790
791 // TODO: maybe add workaround for this errata
792 // It uses extra power, not sure how to let the user choose.
793 // https://docs.nordicsemi.com/bundle/errata_nRF9151_Rev1/page/ERR/nRF9151/Rev1/latest/anomaly_151_36.html#anomaly_151_36
794 }
771 } 795 }
772 config::Debug::Disallowed => { 796 config::Debug::Disallowed => {
773 // TODO: Handle nRF54L 797 // TODO: Handle nRF54L
@@ -783,6 +807,13 @@ pub fn init(config: config::Config) -> Peripherals {
783 let res = uicr_write(consts::UICR_SECUREAPPROTECT, consts::APPROTECT_ENABLED); 807 let res = uicr_write(consts::UICR_SECUREAPPROTECT, consts::APPROTECT_ENABLED);
784 needs_reset |= res == WriteResult::Written; 808 needs_reset |= res == WriteResult::Written;
785 } 809 }
810
811 #[cfg(feature = "nrf9120-s")]
812 {
813 let p = pac::APPROTECT_S;
814 p.approtect().forceprotect().write(|w| w.set_forceprotect(true));
815 p.secureapprotect().forceprotect().write(|w| w.set_forceprotect(true));
816 }
786 } 817 }
787 } 818 }
788 config::Debug::NotConfigured => {} 819 config::Debug::NotConfigured => {}