Skip to content

Commit

Permalink
Correct the reset registers, and separate rp2040 from rp2350
Browse files Browse the repository at this point in the history
  • Loading branch information
cibomahto committed Nov 30, 2024
1 parent fbb5234 commit 96bb225
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
9 changes: 2 additions & 7 deletions src/machine/machine_rp2.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,15 @@ func machineInit() {
// except for QSPI pads and the XIP IO bank, as this is fatal if running from flash
// and the PLLs, as this is fatal if clock muxing has not been reset on this boot
// and USB, syscfg, as this disturbs USB-to-SWD on core 1
bits := ^uint32(rp.RESETS_RESET_IO_QSPI |
rp.RESETS_RESET_PADS_QSPI |
rp.RESETS_RESET_PLL_USB |
rp.RESETS_RESET_USBCTRL |
rp.RESETS_RESET_SYSCFG |
rp.RESETS_RESET_PLL_SYS)
bits := ^uint32(initDontReset)
resetBlock(bits)

// Remove reset from peripherals which are clocked only by clkSys and
// clkRef. Other peripherals stay in reset until we've configured clocks.
bits = ^uint32(initUnreset)
unresetBlockWait(bits)

// clocks.init()
//clocks.init()

// Peripheral clocks should now all be running
unresetBlockWait(RESETS_RESET_Msk)
Expand Down
15 changes: 7 additions & 8 deletions src/machine/machine_rp2350_resets.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import (
// RESETS_RESET_Msk is bitmask to reset all peripherals
//
// TODO: This field is not available in the device file.
const RESETS_RESET_Msk = 0x01ffffff
const RESETS_RESET_Msk = 0x1fffffff

type resetsType struct {
frceOn volatile.Register32
frceOff volatile.Register32
reset volatile.Register32
wdSel volatile.Register32
resetDone volatile.Register32
}
Expand All @@ -25,20 +24,20 @@ var resets = (*resetsType)(unsafe.Pointer(rp.RESETS))
// resetBlock resets hardware blocks specified
// by the bit pattern in bits.
func resetBlock(bits uint32) {
// resets.frceOff.Set(bits)
resets.reset.SetBits(bits)
}

// unresetBlock brings hardware blocks specified by the
// bit pattern in bits out of reset.
func unresetBlock(bits uint32) {
// resets.frceOn.Set(bits)
resets.reset.ClearBits(bits)
}

// unresetBlockWait brings specified hardware blocks
// specified by the bit pattern in bits
// out of reset and wait for completion.
func unresetBlockWait(bits uint32) {
// unresetBlock(bits)
// for !resets.resetDone.HasBits(bits) {
// }
unresetBlock(bits)
for !resets.resetDone.HasBits(bits) {
}
}
6 changes: 6 additions & 0 deletions src/machine/machine_rp2_2040.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ const (
_NUMBANK0_GPIOS = 30
_NUMBANK0_IRQS = 4
rp2350ExtraReg = 0
initDontReset = rp.RESETS_RESET_IO_QSPI |
rp.RESETS_RESET_PADS_QSPI |
rp.RESETS_RESET_PLL_USB |
rp.RESETS_RESET_USBCTRL |
rp.RESETS_RESET_SYSCFG |
rp.RESETS_RESET_PLL_SYS
initUnreset = rp.RESETS_RESET_ADC |
rp.RESETS_RESET_RTC |
rp.RESETS_RESET_SPI0 |
Expand Down
7 changes: 7 additions & 0 deletions src/machine/machine_rp2_2350.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ const (
xoscFreq = 12 // Pico 2 Crystal oscillator Abracon ABM8-272-T3 frequency in MHz
rp2350ExtraReg = 1
notimpl = "rp2350: not implemented"
initDontReset =
rp.RESETS_RESET_USBCTRL |
rp.RESETS_RESET_SYSCFG |
rp.RESETS_RESET_PLL_USB |
rp.RESETS_RESET_PLL_SYS |
rp.RESETS_RESET_PADS_QSPI |
rp.RESETS_RESET_IO_QSPI
initUnreset = rp.RESETS_RESET_ADC |
rp.RESETS_RESET_SPI0 |
rp.RESETS_RESET_SPI1 |
Expand Down

0 comments on commit 96bb225

Please sign in to comment.