Skip to content

Instantly share code, notes, and snippets.

@MichaelBell
Created December 1, 2024 22:39
Show Gist options
  • Save MichaelBell/c413356f4c45bf9aef98cd23ceb83057 to your computer and use it in GitHub Desktop.
Save MichaelBell/c413356f4c45bf9aef98cd23ceb83057 to your computer and use it in GitHub Desktop.
RP2350 overclocking in Micropython
import machine
import time
machine.freq(100000000)
# Enable powman
machine.mem32[0x40100004] = 0x5AFEA050
def set_09():
# Reduce brownout
machine.mem32[0x4010001c] = 0x5AFE0061
time.sleep_ms(100)
# 0.9V
machine.mem32[0x4010000c] = 0x5AFE0070
time.sleep_ms(100)
machine.freq(170000000)
def set_10():
# Reduce brownout
machine.mem32[0x4010001c] = 0x5AFE0071
time.sleep_ms(100)
# 1.0V
machine.mem32[0x4010000c] = 0x5AFE0090
time.sleep_ms(100)
machine.freq(236000000)
def set_11():
# Normal brownout
machine.mem32[0x4010001c] = 0x5AFE0091
time.sleep_ms(100)
# 1.1V
machine.mem32[0x4010000c] = 0x5AFE00b0
time.sleep_ms(100)
machine.freq(276000000)
def set_115():
# Normal brownout
machine.mem32[0x4010001c] = 0x5AFE0091
time.sleep_ms(100)
# 1.15V
machine.mem32[0x4010000c] = 0x5AFE00c0
time.sleep_ms(100)
machine.freq(312000000)
def set_120():
# Normal brownout
machine.mem32[0x4010001c] = 0x5AFE0091
time.sleep_ms(100)
# 1.2V
machine.mem32[0x4010000c] = 0x5AFE00d0
time.sleep_ms(100)
machine.freq(332000000)
def set_125():
# Normal brownout
machine.mem32[0x4010001c] = 0x5AFE0091
time.sleep_ms(100)
# 1.25V
machine.mem32[0x4010000c] = 0x5AFE00e0
time.sleep_ms(100)
machine.freq(360000000)
def set_130():
# Normal brownout
machine.mem32[0x4010001c] = 0x5AFE0091
time.sleep_ms(100)
# 1.3V
machine.mem32[0x4010000c] = 0x5AFE00f0
time.sleep_ms(100)
machine.freq(384000000)
def set_135():
# Normal brownout
machine.mem32[0x4010001c] = 0x5AFE0091
time.sleep_ms(100)
# More forgiving flash timing
machine.mem32[0x400d000c] = 0x60007304
# Unlock VREG CTRL
machine.mem32[0x40100004] = 0x5AFEA150
# 1.35V
machine.mem32[0x4010000c] = 0x5AFE0100
time.sleep_ms(100)
machine.freq(408000000)
def set_140():
# Normal brownout
machine.mem32[0x4010001c] = 0x5AFE0091
time.sleep_ms(100)
# More forgiving flash timing
machine.mem32[0x400d000c] = 0x60007304
# Unlock VREG CTRL
machine.mem32[0x40100004] = 0x5AFEA150
# 1.4V
machine.mem32[0x4010000c] = 0x5AFE0110
time.sleep_ms(100)
machine.freq(424000000)
def set_150():
# Normal brownout
machine.mem32[0x4010001c] = 0x5AFE0091
time.sleep_ms(100)
# More forgiving flash timing
machine.mem32[0x400d000c] = 0x60007304
# Unlock VREG CTRL
machine.mem32[0x40100004] = 0x5AFEA150
# 1.5V
machine.mem32[0x4010000c] = 0x5AFE0120
time.sleep_ms(100)
machine.freq(472000000)
def set_160():
# Normal brownout
machine.mem32[0x4010001c] = 0x5AFE0091
time.sleep_ms(100)
# More forgiving flash timing
machine.mem32[0x400d000c] = 0x60007304
# Unlock VREG CTRL
machine.mem32[0x40100004] = 0x5AFEA150
# 1.6V
machine.mem32[0x4010000c] = 0x5AFE0130
time.sleep_ms(100)
machine.freq(500000000)
def set_170():
# Normal brownout
machine.mem32[0x4010001c] = 0x5AFE0091
time.sleep_ms(100)
# More forgiving flash timing
machine.mem32[0x400d000c] = 0x60007304
# Unlock VREG CTRL
machine.mem32[0x40100004] = 0x5AFEA150
# 1.7V
machine.mem32[0x4010000c] = 0x5AFE0150
time.sleep_ms(100)
machine.freq(532000000)
def set_180():
# Normal brownout
machine.mem32[0x4010001c] = 0x5AFE0091
time.sleep_ms(100)
# More forgiving flash timing
machine.mem32[0x400d000c] = 0x60007405
# Unlock VREG CTRL
machine.mem32[0x40100004] = 0x5AFEA150
# 1.8V
machine.mem32[0x4010000c] = 0x5AFE0160
time.sleep_ms(100)
machine.freq(564000000)
def set_190():
# Normal brownout
machine.mem32[0x4010001c] = 0x5AFE0091
time.sleep_ms(100)
# More forgiving flash timing
machine.mem32[0x400d000c] = 0x60007405
# Unlock VREG CTRL
machine.mem32[0x40100004] = 0x5AFEA150
# 1.9V
machine.mem32[0x4010000c] = 0x5AFE0170
time.sleep_ms(100)
machine.freq(582000000)
def set_200():
# Normal brownout
machine.mem32[0x4010001c] = 0x5AFE0091
time.sleep_ms(100)
# More forgiving flash timing
machine.mem32[0x400d000c] = 0x60007405
# Unlock VREG CTRL
machine.mem32[0x40100004] = 0x5AFEA150
# 2.0V
machine.mem32[0x4010000c] = 0x5AFE0180
time.sleep_ms(100)
machine.freq(600000000)
def set_235():
# Normal brownout
machine.mem32[0x4010001c] = 0x5AFE0091
time.sleep_ms(100)
# More forgiving flash timing
machine.mem32[0x400d000c] = 0x60007505
# Unlock VREG CTRL
machine.mem32[0x40100004] = 0x5AFEA150
# 2.35V (eek!)
machine.mem32[0x4010000c] = 0x5AFE0190
time.sleep_ms(100)
machine.freq(630000000)
def set_250():
# Normal brownout
machine.mem32[0x4010001c] = 0x5AFE0091
time.sleep_ms(100)
# More forgiving flash timing
machine.mem32[0x400d000c] = 0x60007505
# Unlock VREG CTRL
machine.mem32[0x40100004] = 0x5AFEA150
# 2.5V (eek!!)
machine.mem32[0x4010000c] = 0x5AFE01a0
time.sleep_ms(100)
machine.freq(630000000)
def seek_max_freq_lo():
for i in range(150,266,2):
machine.freq(i * 1000000)
time.sleep_ms(10)
j = 1
for k in range(1,100):
j *= k
assert j == 933262154439441526816992388562667004907159682643816214685929638952175999932299156089414639761565182862536979208272237582511852109168640000000000000000000000
print(f"OK at {i}MHz")
def seek_max_freq_mid():
for i in range(264,532,4):
machine.freq(i * 1000000)
time.sleep_ms(10)
j = 1
for k in range(1,100):
j *= k
assert j == 933262154439441526816992388562667004907159682643816214685929638952175999932299156089414639761565182862536979208272237582511852109168640000000000000000000000
print(f"OK at {i}MHz")
def seek_max_freq_hi():
for i in range(528,700,6):
machine.freq(i * 1000000)
time.sleep_ms(10)
j = 1
for k in range(1,100):
j *= k
assert j == 933262154439441526816992388562667004907159682643816214685929638952175999932299156089414639761565182862536979208272237582511852109168640000000000000000000000
print(f"OK at {i}MHz")
def seek_max_freq_and_check_glitch():
machine.mem32[0x40158008] = 0xde001be4
for i in range(120,300,4):
machine.mem32[0x40158010] = 0xf
machine.freq(i * 1000000)
time.sleep_ms(10)
j = 1
for k in range(1,100):
j *= k
assert j == 933262154439441526816992388562667004907159682643816214685929638952175999932299156089414639761565182862536979208272237582511852109168640000000000000000000000
print(f"OK at {i}MHz")
glitch = machine.mem32[0x40158010]
if glitch != 0:
print(f"Glitch {glitch:08x}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment