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) +}