aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-nrf/src/lib.rs76
-rw-r--r--examples/nrf54l15/.cargo/config.toml2
2 files changed, 68 insertions, 10 deletions
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs
index ec5e9f864..faef44d1b 100644
--- a/embassy-nrf/src/lib.rs
+++ b/embassy-nrf/src/lib.rs
@@ -507,7 +507,6 @@ pub fn init(config: config::Config) -> Peripherals {
507 let mut needs_reset = false; 507 let mut needs_reset = false;
508 508
509 // Setup debug protection. 509 // Setup debug protection.
510 #[cfg(not(feature = "_nrf54l"))] // TODO
511 #[cfg(not(feature = "_nrf51"))] 510 #[cfg(not(feature = "_nrf51"))]
512 match config.debug { 511 match config.debug {
513 config::Debug::Allowed => { 512 config::Debug::Allowed => {
@@ -549,18 +548,77 @@ pub fn init(config: config::Config) -> Peripherals {
549 } 548 }
550 } 549 }
551 550
551 // TAMPC is only accessible for secure code
552 #[cfg(all(feature = "_nrf54l", feature = "_s"))]
553 {
554 use crate::pac::tampc::vals;
555
556 // UICR cannot be written here, because it can only be written once after an erase all.
557 // The erase all value means that debug access is allowed if permitted by the firmware.
558
559 // Write to TAMPC to permit debug access
560 //
561 // See https://docs.nordicsemi.com/bundle/ps_nrf54L15/page/debug.html#ariaid-title6
562
563 let p = pac::TAMPC;
564
565 // Unlock dbgen
566 p.protect().domain(0).dbgen().ctrl().write(|w| {
567 w.set_key(vals::DomainDbgenCtrlKey::KEY);
568 w.set_writeprotection(vals::DomainDbgenCtrlWriteprotection::CLEAR);
569 });
570 p.protect().domain(0).dbgen().ctrl().write(|w| {
571 w.set_key(vals::DomainDbgenCtrlKey::KEY);
572 w.set_value(vals::DomainDbgenCtrlValue::HIGH);
573 });
574
575 // Unlock niden
576 p.protect().domain(0).niden().ctrl().write(|w| {
577 w.set_key(vals::NidenCtrlKey::KEY);
578 w.set_writeprotection(vals::NidenCtrlWriteprotection::CLEAR);
579 });
580 p.protect().domain(0).niden().ctrl().write(|w| {
581 w.set_key(vals::NidenCtrlKey::KEY);
582 w.set_value(vals::NidenCtrlValue::HIGH);
583 });
584
585 p.protect().domain(0).spiden().ctrl().write(|w| {
586 w.set_key(vals::SpidenCtrlKey::KEY);
587 w.set_writeprotection(vals::SpidenCtrlWriteprotection::CLEAR);
588 });
589 p.protect().domain(0).spiden().ctrl().write(|w| {
590 w.set_key(vals::SpidenCtrlKey::KEY);
591 w.set_value(vals::SpidenCtrlValue::HIGH);
592 });
593
594 p.protect().domain(0).spniden().ctrl().write(|w| {
595 w.set_key(vals::SpnidenCtrlKey::KEY);
596 w.set_writeprotection(vals::SpnidenCtrlWriteprotection::CLEAR);
597 });
598 p.protect().domain(0).spniden().ctrl().write(|w| {
599 w.set_key(vals::SpnidenCtrlKey::KEY);
600 w.set_value(vals::SpnidenCtrlValue::HIGH);
601 });
602 }
603
552 // nothing to do on the nrf9160, debug is allowed by default. 604 // nothing to do on the nrf9160, debug is allowed by default.
553 } 605 }
554 config::Debug::Disallowed => unsafe { 606 config::Debug::Disallowed => {
555 // UICR.APPROTECT = Enabled 607 // TODO: Handle nRF54L
556 let res = uicr_write(consts::UICR_APPROTECT, consts::APPROTECT_ENABLED); 608 // By default, debug access is not allowed if the firmware doesn't allow it.
557 needs_reset |= res == WriteResult::Written; 609 // Code could be added here to disable debug access in UICR as well.
558 #[cfg(any(feature = "_nrf5340-app", feature = "_nrf91"))] 610 #[cfg(not(feature = "_nrf54l"))]
559 { 611 unsafe {
560 let res = uicr_write(consts::UICR_SECUREAPPROTECT, consts::APPROTECT_ENABLED); 612 // UICR.APPROTECT = Enabled
613 let res = uicr_write(consts::UICR_APPROTECT, consts::APPROTECT_ENABLED);
561 needs_reset |= res == WriteResult::Written; 614 needs_reset |= res == WriteResult::Written;
615 #[cfg(any(feature = "_nrf5340-app", feature = "_nrf91"))]
616 {
617 let res = uicr_write(consts::UICR_SECUREAPPROTECT, consts::APPROTECT_ENABLED);
618 needs_reset |= res == WriteResult::Written;
619 }
562 } 620 }
563 }, 621 }
564 config::Debug::NotConfigured => {} 622 config::Debug::NotConfigured => {}
565 } 623 }
566 624
diff --git a/examples/nrf54l15/.cargo/config.toml b/examples/nrf54l15/.cargo/config.toml
index 4a026ebbd..443bd7418 100644
--- a/examples/nrf54l15/.cargo/config.toml
+++ b/examples/nrf54l15/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace nRF82840_xxAA with your chip as listed in `probe-rs chip list` 2# replace nRF82840_xxAA with your chip as listed in `probe-rs chip list`
3runner = "../../sshprobe.sh" 3runner = "probe-rs run --chip nrf54l15"
4 4
5[build] 5[build]
6target = "thumbv8m.main-none-eabihf" 6target = "thumbv8m.main-none-eabihf"