Skip to content
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

[WIP] Separate system clock config for rp2xxx devices #4674

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions src/machine/board_ae_rp2040.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ const (
GP27 Pin = GPIO27
GP28 Pin = GPIO28
GP29 Pin = GPIO29

// Onboard crystal oscillator frequency, in MHz.
xoscFreq = 12 // MHz
)

// System clock configuration
var clockCfg = defaultSystemClockCfg

// I2C Default pins on Raspberry Pico.
const (
I2C0_SDA_PIN = GP4
Expand Down
6 changes: 2 additions & 4 deletions src/machine/board_badger2040-w.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ SPI0_CS_PIN Pin = QSPI_CS
*/
)

// Onboard crystal oscillator frequency, in MHz.
const (
xoscFreq = 12 // MHz
)
// System clock configuration
var clockCfg = defaultSystemClockCfg

// USB CDC identifiers
const (
Expand Down
6 changes: 2 additions & 4 deletions src/machine/board_badger2040.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ SPI0_CS_PIN Pin = QSPI_CS
*/
)

// Onboard crystal oscillator frequency, in MHz.
const (
xoscFreq = 12 // MHz
)
// System clock configuration
var clockCfg = defaultSystemClockCfg

// USB CDC identifiers
const (
Expand Down
6 changes: 3 additions & 3 deletions src/machine/board_challenger_rp2040.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ package machine

const (
LED = GPIO24

// Onboard crystal oscillator frequency, in MHz.
xoscFreq = 12 // MHz
)

// System clock configuration
var clockCfg = defaultSystemClockCfg

// GPIO Pins
const (
D5 = GPIO2
Expand Down
4 changes: 2 additions & 2 deletions src/machine/board_feather_rp2040.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

package machine

// Onboard crystal oscillator frequency, in MHz.
const xoscFreq = 12 // MHz
// System clock configuration
var clockCfg = defaultSystemClockCfg

// GPIO Pins
const (
Expand Down
6 changes: 2 additions & 4 deletions src/machine/board_gopher-badge.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@
SPI1_SDI_PIN Pin = NoPin
)

// Onboard crystal oscillator frequency, in MHz.
const (
xoscFreq = 12 // MHz
)
// System clock configuration
var clockCfg = defaultSystemClockCfg

Check failure on line 65 in src/machine/board_gopher-badge.go

View workflow job for this annotation

GitHub Actions / assert-test-linux

undefined: defaultSystemClockCfg

Check failure on line 65 in src/machine/board_gopher-badge.go

View workflow job for this annotation

GitHub Actions / build-macos (macos-14)

undefined: defaultSystemClockCfg

// USB CDC identifiers
const (
Expand Down
4 changes: 2 additions & 2 deletions src/machine/board_kb2040.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

package machine

// Onboard crystal oscillator frequency, in MHz.
const xoscFreq = 12 // MHz
// System clock configuration
var clockCfg = defaultSystemClockCfg

// GPIO Pins
const (
Expand Down
6 changes: 3 additions & 3 deletions src/machine/board_macropad-rp2040.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ package machine

const (
NeopixelCount = 12

// Onboard crystal oscillator frequency, in MHz.
xoscFreq = 12 // MHz
)

// System clock configuration
var clockCfg = defaultSystemClockCfg

const (
SWITCH = GPIO0
BUTTON = GPIO0
Expand Down
6 changes: 2 additions & 4 deletions src/machine/board_nano-rp2040.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,8 @@ const (
NINA_SOFT_FLOWCONTROL = false
)

// Onboard crystal oscillator frequency, in MHz.
const (
xoscFreq = 12 // MHz
)
// System clock configuration
var clockCfg = defaultSystemClockCfg

// USB CDC identifiers
// https://github.com/arduino/ArduinoCore-mbed/blob/master/variants/NANO_RP2040_CONNECT/pins_arduino.h
Expand Down
6 changes: 3 additions & 3 deletions src/machine/board_pico.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ const (

// Onboard LED
LED Pin = GPIO25

// Onboard crystal oscillator frequency, in MHz.
xoscFreq = 12 // MHz
)

// System clock configuration
var clockCfg = defaultSystemClockCfg

// I2C Default pins on Raspberry Pico.
const (
I2C0_SDA_PIN = GP4
Expand Down
6 changes: 3 additions & 3 deletions src/machine/board_pico2.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ const (

// Onboard LED
LED Pin = GPIO25

// Onboard crystal oscillator frequency, in MHz.
xoscFreq = 12 // MHz
)

// System clock configuration
var clockCfg = defaultSystemClockCfg

// I2C Default pins on Raspberry Pico.
const (
I2C0_SDA_PIN = GP4
Expand Down
4 changes: 2 additions & 2 deletions src/machine/board_qtpy_rp2040.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

package machine

// Onboard crystal oscillator frequency, in MHz.
const xoscFreq = 12 // MHz
// System clock configuration
var clockCfg = defaultSystemClockCfg

// GPIO Pins
const (
Expand Down
4 changes: 2 additions & 2 deletions src/machine/board_thingplus_rp2040.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

package machine

// Onboard crystal oscillator frequency, in MHz.
const xoscFreq = 12 // MHz
// System clock configuration
var clockCfg = defaultSystemClockCfg

// GPIO Pins
const (
Expand Down
6 changes: 2 additions & 4 deletions src/machine/board_thumby.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ const (
SPI1_SDI_PIN = NoPin
)

// Onboard crystal oscillator frequency, in MHz.
const (
xoscFreq = 12 // MHz
)
// System clock configuration
var clockCfg = defaultSystemClockCfg

// USB CDC identifiers
const (
Expand Down
6 changes: 3 additions & 3 deletions src/machine/board_tiny2350.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ const (
LED_GREEN Pin = GPIO19
LED_BLUE Pin = GPIO20
LED = LED_RED

// Onboard crystal oscillator frequency, in MHz.
xoscFreq = 12 // MHz
)

// System clock configuration
var clockCfg = defaultSystemClockCfg

// I2C Default pins on Tiny2350.
const (
I2C0_SDA_PIN = GP12
Expand Down
4 changes: 2 additions & 2 deletions src/machine/board_trinkey_qt2040.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

package machine

// Onboard crystal oscillator frequency, in MHz
const xoscFreq = 12 // MHz
// System clock configuration
var clockCfg = defaultSystemClockCfg

// Onboard LEDs
const (
Expand Down
6 changes: 2 additions & 4 deletions src/machine/board_tufty2040.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ const (
SPI1_SDI_PIN Pin = NoPin
)

// Onboard crystal oscillator frequency, in MHz.
const (
xoscFreq = 12 // MHz
)
// System clock configuration
var clockCfg = defaultSystemClockCfg

// USB CDC identifiers
const (
Expand Down
6 changes: 2 additions & 4 deletions src/machine/board_waveshare-rp2040-zero.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,8 @@ const (
SPI1_SDI_PIN Pin = D12
)

// Onboard crystal oscillator frequency, in MHz.
const (
xoscFreq = 12 // MHz
)
// System clock configuration
var clockCfg = defaultSystemClockCfg

// UART pins
const (
Expand Down
6 changes: 2 additions & 4 deletions src/machine/board_xiao-rp2040.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ const (
SPI1_SDI_PIN Pin = NoPin
)

// Onboard crystal oscillator frequency, in MHz.
const (
xoscFreq = 12 // MHz
)
// System clock configuration
var clockCfg = defaultSystemClockCfg

// UART pins
const (
Expand Down
19 changes: 16 additions & 3 deletions src/machine/machine_rp2_2040.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,21 @@ const (
fnXIP pinFunc = 0
)

// Clock frequency and PLL configuration
var defaultSystemClockCfg = systemClockCfg{
xoscFreq: 12,

pllSysFreq: 125 * MHz,
pllSysVcoFreq: 1500 * MHz,
pllSysPostDiv1: 6,
pllSysPostDiv2: 2,

pllUSBFreq: 48 * MHz,
pllUSBVcoFreq: 480 * MHz,
pllUSBPostDiv1: 5,
pllUSBPostDiv2: 2,
}

// Configure configures the gpio pin as per mode.
func (p Pin) Configure(config PinConfig) {
if p == NoPin {
Expand Down Expand Up @@ -184,12 +199,10 @@ func (clks *clocksType) initRTC() {
crtc := clks.clock(clkRTC)
crtc.configure(0, // No GLMUX
rp.CLOCKS_CLK_RTC_CTRL_AUXSRC_CLKSRC_PLL_USB,
48*MHz,
clockCfg.pllUSBFreq,
46875)
}

func (clks *clocksType) initTicks() {} // No ticks on RP2040

// startTick starts the watchdog tick.
// cycles needs to be a divider that when applied to the xosc input,
// produces a 1MHz clock. So if the xosc frequency is 12MHz,
Expand Down
25 changes: 19 additions & 6 deletions src/machine/machine_rp2_2350.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@ const (
fnNULL pinFunc = 0x1f
)

// Clock frequency and PLL configuration
var defaultSystemClockCfg = systemClockCfg{
xoscFreq: 12,

pllSysFreq: 150 * MHz,
pllSysVcoFreq: 1500 * MHz,
pllSysPostDiv1: 5,
pllSysPostDiv2: 2,

pllUSBFreq: 48 * MHz,
pllUSBVcoFreq: 480 * MHz,
pllUSBPostDiv1: 5,
pllUSBPostDiv2: 2,
}

// Configure configures the gpio pin as per mode.
func (p Pin) Configure(config PinConfig) {
if p == NoPin {
Expand Down Expand Up @@ -199,12 +214,6 @@ func irqSet(num uint32, enabled bool) {

func (clks *clocksType) initRTC() {} // No RTC on RP2350.

func (clks *clocksType) initTicks() {
rp.TICKS.SetTIMER0_CTRL_ENABLE(0)
rp.TICKS.SetTIMER0_CYCLES(12)
rp.TICKS.SetTIMER0_CTRL_ENABLE(1)
}

func EnterBootloader() {
enterBootloader()
}
Expand All @@ -213,5 +222,9 @@ func EnterBootloader() {
// On RP2040, the watchdog contained a tick generator used to generate a 1μs tick for the watchdog. This was also
// distributed to the system timer. On RP2350, the watchdog instead takes a tick input from the system-level ticks block. See Section 8.5.
func (wd *watchdogImpl) startTick(cycles uint32) {
rp.TICKS.SetTIMER0_CTRL_ENABLE(0)
rp.TICKS.SetTIMER0_CYCLES(cycles)
rp.TICKS.SetTIMER0_CTRL_ENABLE(1)

rp.TICKS.WATCHDOG_CTRL.SetBits(1)
}
Loading
Loading