aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src/lib.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-12-26 11:20:36 +0000
committerGitHub <[email protected]>2024-12-26 11:20:36 +0000
commitb71696c8f54edba664e9bfe77a1d86d09d88f52c (patch)
tree75dc82fc0308d6188836f7029f8f8424d30a58ec /embassy-nrf/src/lib.rs
parent5cbd520ba92dade7c574cd6a44b5cce5f0fa5a5e (diff)
parent19203c706f4b317a92bd47d946b32e3799ef9467 (diff)
Merge pull request #3685 from Tiwalun/nrf54l-debug-unlock
nrf54l: Allow debug access from firmware side
Diffstat (limited to 'embassy-nrf/src/lib.rs')
-rw-r--r--embassy-nrf/src/lib.rs76
1 files changed, 67 insertions, 9 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