diff options
Diffstat (limited to 'embassy-nrf/src/lib.rs')
| -rw-r--r-- | embassy-nrf/src/lib.rs | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index 44990ed85..8a88051b4 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs | |||
| @@ -584,6 +584,8 @@ pub mod config { | |||
| 584 | #[allow(unused)] | 584 | #[allow(unused)] |
| 585 | mod consts { | 585 | 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_HFXOSRC: *mut u32 = 0x00FF801C as *mut u32; | ||
| 588 | pub const UICR_HFXOCNT: *mut u32 = 0x00FF8020 as *mut u32; | ||
| 587 | pub const UICR_SECUREAPPROTECT: *mut u32 = 0x00FF802C as *mut u32; | 589 | pub const UICR_SECUREAPPROTECT: *mut u32 = 0x00FF802C as *mut u32; |
| 588 | pub const APPROTECT_ENABLED: u32 = 0x0000_0000; | 590 | pub const APPROTECT_ENABLED: u32 = 0x0000_0000; |
| 589 | #[cfg(feature = "_nrf9120")] | 591 | #[cfg(feature = "_nrf9120")] |
| @@ -650,13 +652,18 @@ unsafe fn uicr_write_masked(address: *mut u32, value: u32, mask: u32) -> WriteRe | |||
| 650 | return WriteResult::Failed; | 652 | return WriteResult::Failed; |
| 651 | } | 653 | } |
| 652 | 654 | ||
| 653 | let nvmc = pac::NVMC; | 655 | // Nrf9151 errata 7, need to disable interrups + use DSB https://docs.nordicsemi.com/bundle/errata_nRF9151_Rev2/page/ERR/nRF9151/Rev2/latest/anomaly_151_7.html |
| 654 | nvmc.config().write(|w| w.set_wen(pac::nvmc::vals::Wen::WEN)); | 656 | cortex_m::interrupt::free(|_cs| { |
| 655 | while !nvmc.ready().read().ready() {} | 657 | let nvmc = pac::NVMC; |
| 656 | address.write_volatile(value | !mask); | 658 | |
| 657 | while !nvmc.ready().read().ready() {} | 659 | nvmc.config().write(|w| w.set_wen(pac::nvmc::vals::Wen::WEN)); |
| 658 | nvmc.config().write(|_| {}); | 660 | while !nvmc.ready().read().ready() {} |
| 659 | while !nvmc.ready().read().ready() {} | 661 | address.write_volatile(value | !mask); |
| 662 | cortex_m::asm::dsb(); | ||
| 663 | while !nvmc.ready().read().ready() {} | ||
| 664 | nvmc.config().write(|_| {}); | ||
| 665 | while !nvmc.ready().read().ready() {} | ||
| 666 | }); | ||
| 660 | 667 | ||
| 661 | WriteResult::Written | 668 | WriteResult::Written |
| 662 | } | 669 | } |
| @@ -674,6 +681,28 @@ pub fn init(config: config::Config) -> Peripherals { | |||
| 674 | #[allow(unused_mut)] | 681 | #[allow(unused_mut)] |
| 675 | let mut needs_reset = false; | 682 | let mut needs_reset = false; |
| 676 | 683 | ||
| 684 | // Workaround used in the nrf mdk: file system_nrf91.c , function SystemInit(), after `#if !defined(NRF_SKIP_UICR_HFXO_WORKAROUND)` | ||
| 685 | #[cfg(all(feature = "_nrf91", feature = "_s"))] | ||
| 686 | { | ||
| 687 | let uicr = pac::UICR_S; | ||
| 688 | let hfxocnt = uicr.hfxocnt().read().hfxocnt().to_bits(); | ||
| 689 | let hfxosrc = uicr.hfxosrc().read().hfxosrc().to_bits(); | ||
| 690 | |||
| 691 | if hfxosrc == 1 { | ||
| 692 | unsafe { | ||
| 693 | let _ = uicr_write(consts::UICR_HFXOSRC, 0); | ||
| 694 | } | ||
| 695 | needs_reset = true; | ||
| 696 | } | ||
| 697 | |||
| 698 | if hfxocnt == 255 { | ||
| 699 | unsafe { | ||
| 700 | let _ = uicr_write(consts::UICR_HFXOCNT, 32); | ||
| 701 | } | ||
| 702 | needs_reset = true; | ||
| 703 | } | ||
| 704 | } | ||
| 705 | |||
| 677 | // Setup debug protection. | 706 | // Setup debug protection. |
| 678 | #[cfg(not(feature = "_nrf51"))] | 707 | #[cfg(not(feature = "_nrf51"))] |
| 679 | match config.debug { | 708 | match config.debug { |
