Skip to content

machine: bump rp2040 to 200MHz #4768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/machine/machine_rp2_2040.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

const (
cpuFreq = 125 * MHz
cpuFreq = 200 * MHz
_NUMBANK0_GPIOS = 30
_NUMBANK0_IRQS = 4
_NUMIRQ = 32
Expand Down Expand Up @@ -208,3 +208,16 @@ func (clks *clocksType) initTicks() {} // No ticks on RP2040
func (wd *watchdogImpl) startTick(cycles uint32) {
rp.WATCHDOG.TICK.Set(cycles | rp.WATCHDOG_TICK_ENABLE)
}

func adjustCoreVoltage() bool {
if cpuFreq <= 133*MHz {
return false
}
// The rp2040 is certified to run at 200MHz with the
// core voltage set to 1150mV.
const targetVoltage = 1150
// 0b0101 maps to 800mV and each step is 50mV.
const vreg = 0b0101 + (targetVoltage-800)/50
rp.VREG_AND_CHIP_RESET.SetVREG_VSEL(vreg)
return true
}
4 changes: 4 additions & 0 deletions src/machine/machine_rp2_2350.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,7 @@ func EnterBootloader() {
func (wd *watchdogImpl) startTick(cycles uint32) {
rp.TICKS.WATCHDOG_CTRL.SetBits(1)
}

func adjustCoreVoltage() bool {
return false
}
12 changes: 12 additions & 0 deletions src/machine/machine_rp2_clocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ type clock struct {
cix clockIndex
}

// The delay in seconds for core voltage adjustments to
// settle. Taken from the Pico SDK.
const _VREG_VOLTAGE_AUTO_ADJUST_DELAY = 1 / 1e3

// clock returns the clock identified by cix.
func (clks *clocksType) clock(cix clockIndex) clock {
return clock{
Expand Down Expand Up @@ -188,6 +192,14 @@ func (clks *clocksType) init() {
xoscFreq,
xoscFreq)

if adjustCoreVoltage() {
// Wait for the voltage to settle.
const cycles = _VREG_VOLTAGE_AUTO_ADJUST_DELAY * xoscFreq * MHz
for i := 0; i < cycles; i++ {
arm.Asm("nop")
}
}

// clkSys = pllSys (125MHz) / 1 = 125MHz
csys := clks.clock(clkSys)
csys.configure(rp.CLOCKS_CLK_SYS_CTRL_SRC_CLKSRC_CLK_SYS_AUX,
Expand Down
Loading