From 5d8afa25b863015e6cace675b5155fb64fe16631 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Tue, 16 Sep 2025 17:48:45 -0400 Subject: [PATCH] fix(rp2): disable DBGPAUSE on startup --- src/machine/machine_rp2.go | 4 ++++ src/machine/machine_rp2_timer.go | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/machine/machine_rp2.go b/src/machine/machine_rp2.go index 9afefa538..edf49c53a 100644 --- a/src/machine/machine_rp2.go +++ b/src/machine/machine_rp2.go @@ -58,6 +58,10 @@ func machineInit() { // Peripheral clocks should now all be running unresetBlockWait(RESETS_RESET_Msk) + + // DBGPAUSE pauses the timer when a debugger is connected. This prevents + // sleep functions from ever returning, so disable it. + timer.setDbgPause(false) } //go:linkname ticks runtime.machineTicks diff --git a/src/machine/machine_rp2_timer.go b/src/machine/machine_rp2_timer.go index a78ed70bb..b0649f91e 100644 --- a/src/machine/machine_rp2_timer.go +++ b/src/machine/machine_rp2_timer.go @@ -101,3 +101,15 @@ func (tmr *timerType) lightSleep(us uint64) { // Disable interrupt intr.Disable() } + +// setDbgPause sets whether this timer is paused when a debugger is connected. +func (tmr *timerType) setDbgPause(enable bool) { + const bitPos = 1 + const bitMask = 0b11 + val := uint32(0b00) + if enable { + // Disable timer when debugger is connected to either core. + val = 0b11 + } + tmr.dbgPause.ReplaceBits(val, bitMask, bitPos) +}