aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorXudong Zheng <[email protected]>2024-02-01 12:54:58 -0500
committerRon Evans <[email protected]>2024-02-11 11:59:54 +0100
commitf5e933cd4d418b0dffdbc4e795a417026ced778a (patch)
tree6a8b291ff6dc1b6c883b0012f2197a2f85d3bd45
parent0952b1b98440eca0a9b5c1a1b136f9bee28096d5 (diff)
downloadtinygo-f5e933cd4d418b0dffdbc4e795a417026ced778a.tar.gz
tinygo-f5e933cd4d418b0dffdbc4e795a417026ced778a.zip
machine/rp2040: set XOSC startup delay multiplier
XOSC requires additional time to stablize on certain RP2040 boards. Signed-off-by: Xudong Zheng <[email protected]>
-rw-r--r--src/machine/machine_rp2040_xosc.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/machine/machine_rp2040_xosc.go b/src/machine/machine_rp2040_xosc.go
index c3d6d713a..0acac1f1e 100644
--- a/src/machine/machine_rp2040_xosc.go
+++ b/src/machine/machine_rp2040_xosc.go
@@ -8,6 +8,11 @@ import (
"unsafe"
)
+// On some boards, the XOSC can take longer than usual to stabilize. On such
+// boards, this is needed to avoid a hard fault on boot/reset. Refer to
+// PICO_XOSC_STARTUP_DELAY_MULTIPLIER in the Pico SDK for additional details.
+const XOSC_STARTUP_DELAY_MULTIPLIER = 64
+
type xoscType struct {
ctrl volatile.Register32
status volatile.Register32
@@ -30,7 +35,7 @@ func (osc *xoscType) init() {
osc.ctrl.Set(rp.XOSC_CTRL_FREQ_RANGE_1_15MHZ)
// Set xosc startup delay
- delay := (((xoscFreq * MHz) / 1000) + 128) / 256
+ delay := (((xoscFreq * MHz) / 1000) + 128) / 256 * XOSC_STARTUP_DELAY_MULTIPLIER
osc.startup.Set(uint32(delay))
// Set the enable bit now that we have set freq range and startup delay