Skip to content

Commit

Permalink
Move RP2 clock settings into structure, with machine default
Browse files Browse the repository at this point in the history
* Addresses #4673: input oscillator frequency can be changed for
  an individual board by filling in a custom PLL configuration
  • Loading branch information
cibomahto committed Jan 6, 2025
1 parent b700e4b commit 586c88e
Show file tree
Hide file tree
Showing 27 changed files with 110 additions and 109 deletions.
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 @@ const (
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
28 changes: 15 additions & 13 deletions src/machine/machine_rp2_2040.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,20 @@ const (
fnXIP pinFunc = 0
)

// System clock configuration
const (
pllSysFreq uint32 = 125 * MHz
pllSysVcoFreq = 1500 * MHz
pllSysPostDiv1 = 6
pllSysPostDiv2 = 2

pllUSBFreq uint32 = 48 * MHz
pllUSBVcoFreq = 480 * MHz
pllUSBPostDiv1 = 5
pllUSBPostDiv2 = 2
)
// 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) {
Expand Down Expand Up @@ -197,7 +199,7 @@ func (clks *clocksType) initRTC() {
crtc := clks.clock(clkRTC)
crtc.configure(0, // No GLMUX
rp.CLOCKS_CLK_RTC_CTRL_AUXSRC_CLKSRC_PLL_USB,
pllUSBFreq,
clockCfg.pllUSBFreq,
46875)
}

Expand Down
27 changes: 14 additions & 13 deletions src/machine/machine_rp2_2350.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,20 @@ const (
fnNULL pinFunc = 0x1f
)

// System clock configuration
// Note that VcoFreq, PostDiv1, and PostDiv2 must be manually calculated to achive desired output frequency.
const (
pllSysFreq uint32 = 150 * MHz
pllSysVcoFreq = 1500 * MHz
pllSysPostDiv1 = 5
pllSysPostDiv2 = 2

pllUSBFreq uint32 = 48 * MHz
pllUSBVcoFreq = 480 * MHz
pllUSBPostDiv1 = 5
pllUSBPostDiv2 = 2
)
// 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) {
Expand Down
Loading

0 comments on commit 586c88e

Please sign in to comment.