Skip to content

Commit afebaaf

Browse files
authored
Merge pull request tock#4811 from tock/rp2040-fixed-clocks
rp2040, rp2350: Remove `resolve_dependencies()`
2 parents 3806ce0 + e22945b commit afebaaf

18 files changed

Lines changed: 203 additions & 289 deletions

File tree

boards/nano_rp2040_connect/src/io.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use kernel::hil::uart::{Configure, Parameters, Parity, StopBits, Width};
1111
use kernel::utilities::cells::OptionalCell;
1212
use kernel::utilities::io_write::IoWrite;
1313

14+
use rp2040::clocks::Clocks;
1415
use rp2040::gpio::{GpioFunction, RPGpio, RPGpioPin};
1516
use rp2040::uart::Uart;
1617

@@ -48,7 +49,8 @@ impl IoWrite for Writer {
4849
self.uart.map_or_else(
4950
|| {
5051
// If no UART is configured for panic print, use UART0
51-
let uart0 = &Uart::new_uart0();
52+
let clocks = &Clocks::new();
53+
let uart0 = &Uart::new_uart0(clocks);
5254

5355
if !uart0.is_configured() {
5456
let parameters = Parameters {

boards/nano_rp2040_connect/src/main.rs

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -177,26 +177,26 @@ pub unsafe extern "C" fn jump_to_bootloader() {
177177
);
178178
}
179179

180-
fn init_clocks(peripherals: &Rp2040DefaultPeripherals) {
180+
fn init_clocks(
181+
peripherals: &Rp2040DefaultPeripherals,
182+
clocks: &'static rp2040::clocks::Clocks,
183+
resets: &'static rp2040::resets::Resets,
184+
) {
181185
// Start tick in watchdog
182186
peripherals.watchdog.start_tick(12);
183187

184188
// Disable the Resus clock
185-
peripherals.clocks.disable_resus();
189+
clocks.disable_resus();
186190

187191
// Setup the external Osciallator
188192
peripherals.xosc.init();
189193

190194
// disable ref and sys clock aux sources
191-
peripherals.clocks.disable_sys_aux();
192-
peripherals.clocks.disable_ref_aux();
195+
clocks.disable_sys_aux();
196+
clocks.disable_ref_aux();
193197

194-
peripherals
195-
.resets
196-
.reset(&[Peripheral::PllSys, Peripheral::PllUsb]);
197-
peripherals
198-
.resets
199-
.unreset(&[Peripheral::PllSys, Peripheral::PllUsb], true);
198+
resets.reset(&[Peripheral::PllSys, Peripheral::PllUsb]);
199+
resets.unreset(&[Peripheral::PllSys, Peripheral::PllUsb], true);
200200

201201
// Configure PLLs (from Pico SDK)
202202
// REF FBDIV VCO POSTDIV
@@ -205,45 +205,33 @@ fn init_clocks(peripherals: &Rp2040DefaultPeripherals) {
205205

206206
// It seems that the external osciallator is clocked at 12 MHz
207207

208-
peripherals
209-
.clocks
210-
.pll_init(PllClock::Sys, 12, 1, 1500 * 1000000, 6, 2);
211-
peripherals
212-
.clocks
213-
.pll_init(PllClock::Usb, 12, 1, 480 * 1000000, 5, 2);
208+
clocks.pll_init(PllClock::Sys, 12, 1, 1500 * 1000000, 6, 2);
209+
clocks.pll_init(PllClock::Usb, 12, 1, 480 * 1000000, 5, 2);
214210

215211
// pico-sdk: // CLK_REF = XOSC (12MHz) / 1 = 12MHz
216-
peripherals.clocks.configure_reference(
212+
clocks.configure_reference(
217213
ReferenceClockSource::Xosc,
218214
ReferenceAuxiliaryClockSource::PllUsb,
219215
12000000,
220216
12000000,
221217
);
222218
// pico-sdk: CLK SYS = PLL SYS (125MHz) / 1 = 125MHz
223-
peripherals.clocks.configure_system(
219+
clocks.configure_system(
224220
SystemClockSource::Auxiliary,
225221
SystemAuxiliaryClockSource::PllSys,
226222
125000000,
227223
125000000,
228224
);
229225
// pico-sdk: CLK USB = PLL USB (48MHz) / 1 = 48MHz
230-
peripherals
231-
.clocks
232-
.configure_usb(UsbAuxiliaryClockSource::PllSys, 48000000, 48000000);
226+
clocks.configure_usb(UsbAuxiliaryClockSource::PllSys, 48000000, 48000000);
233227
// pico-sdk: CLK ADC = PLL USB (48MHZ) / 1 = 48MHz
234-
peripherals
235-
.clocks
236-
.configure_adc(AdcAuxiliaryClockSource::PllUsb, 48000000, 48000000);
228+
clocks.configure_adc(AdcAuxiliaryClockSource::PllUsb, 48000000, 48000000);
237229
// pico-sdk: CLK RTC = PLL USB (48MHz) / 1024 = 46875Hz
238-
peripherals
239-
.clocks
240-
.configure_rtc(RtcAuxiliaryClockSource::PllSys, 48000000, 46875);
230+
clocks.configure_rtc(RtcAuxiliaryClockSource::PllSys, 48000000, 46875);
241231
// pico-sdk:
242232
// CLK PERI = clk_sys. Used as reference clock for Peripherals. No dividers so just select and enable
243233
// Normally choose clk_sys or clk_usb
244-
peripherals
245-
.clocks
246-
.configure_peripheral(PeripheralAuxiliaryClockSource::System, 125000000);
234+
clocks.configure_peripheral(PeripheralAuxiliaryClockSource::System, 125000000);
247235
}
248236

249237
/// This is in a separate, inline(never) function so that its stack frame is
@@ -269,11 +257,16 @@ pub unsafe fn start() -> (
269257
PanicResources::new(),
270258
);
271259

272-
let peripherals = static_init!(Rp2040DefaultPeripherals, Rp2040DefaultPeripherals::new());
273-
peripherals.resolve_dependencies();
260+
let clocks = static_init!(rp2040::clocks::Clocks, rp2040::clocks::Clocks::new());
261+
let resets = static_init!(rp2040::resets::Resets, rp2040::resets::Resets::new());
262+
let peripherals = static_init!(
263+
Rp2040DefaultPeripherals,
264+
Rp2040DefaultPeripherals::new(clocks, resets)
265+
);
266+
peripherals.init();
274267

275268
// Reset all peripherals except QSPI (we might be booting from Flash), PLL USB and PLL SYS
276-
peripherals.resets.reset_all_except(&[
269+
resets.reset_all_except(&[
277270
Peripheral::IOQSpi,
278271
Peripheral::PadsQSpi,
279272
Peripheral::PllUsb,
@@ -282,7 +275,7 @@ pub unsafe fn start() -> (
282275

283276
// Unreset all the peripherals that do not require clock setup as they run using the sys_clk or ref_clk
284277
// Wait for the peripherals to reset
285-
peripherals.resets.unreset_all_except(
278+
resets.unreset_all_except(
286279
&[
287280
Peripheral::Adc,
288281
Peripheral::Rtc,
@@ -295,10 +288,10 @@ pub unsafe fn start() -> (
295288
true,
296289
);
297290

298-
init_clocks(peripherals);
291+
init_clocks(peripherals, clocks, resets);
299292

300293
// Unreset all peripherals
301-
peripherals.resets.unreset_all_except(&[], true);
294+
resets.unreset_all_except(&[], true);
302295

303296
// Set the UART used for panic
304297
(*addr_of_mut!(io::WRITER)).set_uart(&peripherals.uart0);

boards/pico_explorer_base/src/io.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use kernel::hil::uart::{Configure, Parameters, Parity, StopBits, Width};
1111
use kernel::utilities::cells::OptionalCell;
1212
use kernel::utilities::io_write::IoWrite;
1313

14+
use rp2040::clocks::Clocks;
1415
use rp2040::gpio::{GpioFunction, RPGpio, RPGpioPin};
1516
use rp2040::uart::Uart;
1617

@@ -66,7 +67,8 @@ impl IoWrite for Writer {
6667
fn write(&mut self, buf: &[u8]) -> usize {
6768
self.uart.map_or_else(
6869
|| {
69-
let uart = Uart::new_uart0();
70+
let clocks = Clocks::new();
71+
let uart = Uart::new_uart0(&clocks);
7072
self.configure_uart(&uart);
7173
self.write_to_uart(&uart, buf);
7274
},

boards/pico_explorer_base/src/main.rs

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -189,26 +189,26 @@ pub unsafe extern "C" fn jump_to_bootloader() {
189189
);
190190
}
191191

192-
fn init_clocks(peripherals: &Rp2040DefaultPeripherals) {
192+
fn init_clocks(
193+
peripherals: &Rp2040DefaultPeripherals,
194+
clocks: &'static rp2040::clocks::Clocks,
195+
resets: &'static rp2040::resets::Resets,
196+
) {
193197
// Start tick in watchdog
194198
peripherals.watchdog.start_tick(12);
195199

196200
// Disable the Resus clock
197-
peripherals.clocks.disable_resus();
201+
clocks.disable_resus();
198202

199203
// Setup the external Oscillator
200204
peripherals.xosc.init();
201205

202206
// disable ref and sys clock aux sources
203-
peripherals.clocks.disable_sys_aux();
204-
peripherals.clocks.disable_ref_aux();
207+
clocks.disable_sys_aux();
208+
clocks.disable_ref_aux();
205209

206-
peripherals
207-
.resets
208-
.reset(&[Peripheral::PllSys, Peripheral::PllUsb]);
209-
peripherals
210-
.resets
211-
.unreset(&[Peripheral::PllSys, Peripheral::PllUsb], true);
210+
resets.reset(&[Peripheral::PllSys, Peripheral::PllUsb]);
211+
resets.unreset(&[Peripheral::PllSys, Peripheral::PllUsb], true);
212212

213213
// Configure PLLs (from Pico SDK)
214214
// REF FBDIV VCO POSTDIV
@@ -217,45 +217,33 @@ fn init_clocks(peripherals: &Rp2040DefaultPeripherals) {
217217

218218
// It seems that the external osciallator is clocked at 12 MHz
219219

220-
peripherals
221-
.clocks
222-
.pll_init(PllClock::Sys, 12, 1, 1500 * 1000000, 6, 2);
223-
peripherals
224-
.clocks
225-
.pll_init(PllClock::Usb, 12, 1, 480 * 1000000, 5, 2);
220+
clocks.pll_init(PllClock::Sys, 12, 1, 1500 * 1000000, 6, 2);
221+
clocks.pll_init(PllClock::Usb, 12, 1, 480 * 1000000, 5, 2);
226222

227223
// pico-sdk: // CLK_REF = XOSC (12MHz) / 1 = 12MHz
228-
peripherals.clocks.configure_reference(
224+
clocks.configure_reference(
229225
ReferenceClockSource::Xosc,
230226
ReferenceAuxiliaryClockSource::PllUsb,
231227
12000000,
232228
12000000,
233229
);
234230
// pico-sdk: CLK SYS = PLL SYS (125MHz) / 1 = 125MHz
235-
peripherals.clocks.configure_system(
231+
clocks.configure_system(
236232
SystemClockSource::Auxiliary,
237233
SystemAuxiliaryClockSource::PllSys,
238234
125000000,
239235
125000000,
240236
);
241237
// pico-sdk: CLK USB = PLL USB (48MHz) / 1 = 48MHz
242-
peripherals
243-
.clocks
244-
.configure_usb(UsbAuxiliaryClockSource::PllSys, 48000000, 48000000);
238+
clocks.configure_usb(UsbAuxiliaryClockSource::PllSys, 48000000, 48000000);
245239
// pico-sdk: CLK ADC = PLL USB (48MHZ) / 1 = 48MHz
246-
peripherals
247-
.clocks
248-
.configure_adc(AdcAuxiliaryClockSource::PllUsb, 48000000, 48000000);
240+
clocks.configure_adc(AdcAuxiliaryClockSource::PllUsb, 48000000, 48000000);
249241
// pico-sdk: CLK RTC = PLL USB (48MHz) / 1024 = 46875Hz
250-
peripherals
251-
.clocks
252-
.configure_rtc(RtcAuxiliaryClockSource::PllSys, 48000000, 46875);
242+
clocks.configure_rtc(RtcAuxiliaryClockSource::PllSys, 48000000, 46875);
253243
// pico-sdk:
254244
// CLK PERI = clk_sys. Used as reference clock for Peripherals. No dividers so just select and enable
255245
// Normally choose clk_sys or clk_usb
256-
peripherals
257-
.clocks
258-
.configure_peripheral(PeripheralAuxiliaryClockSource::System, 125000000);
246+
clocks.configure_peripheral(PeripheralAuxiliaryClockSource::System, 125000000);
259247
}
260248

261249
/// This is in a separate, inline(never) function so that its stack frame is
@@ -281,11 +269,16 @@ pub unsafe fn start() -> (
281269
PanicResources::new(),
282270
);
283271

284-
let peripherals = static_init!(Rp2040DefaultPeripherals, Rp2040DefaultPeripherals::new());
285-
peripherals.resolve_dependencies();
272+
let clocks = static_init!(rp2040::clocks::Clocks, rp2040::clocks::Clocks::new());
273+
let resets = static_init!(rp2040::resets::Resets, rp2040::resets::Resets::new());
274+
let peripherals = static_init!(
275+
Rp2040DefaultPeripherals,
276+
Rp2040DefaultPeripherals::new(clocks, resets)
277+
);
278+
peripherals.init();
286279

287280
// Reset all peripherals except QSPI (we might be booting from Flash), PLL USB and PLL SYS
288-
peripherals.resets.reset_all_except(&[
281+
resets.reset_all_except(&[
289282
Peripheral::IOQSpi,
290283
Peripheral::PadsQSpi,
291284
Peripheral::PllUsb,
@@ -294,7 +287,7 @@ pub unsafe fn start() -> (
294287

295288
// Unreset all the peripherals that do not require clock setup as they run using the sys_clk or ref_clk
296289
// Wait for the peripherals to reset
297-
peripherals.resets.unreset_all_except(
290+
resets.unreset_all_except(
298291
&[
299292
Peripheral::Adc,
300293
Peripheral::Rtc,
@@ -307,10 +300,10 @@ pub unsafe fn start() -> (
307300
true,
308301
);
309302

310-
init_clocks(peripherals);
303+
init_clocks(peripherals, clocks, resets);
311304

312305
// Unreset all peripherals
313-
peripherals.resets.unreset_all_except(&[], true);
306+
resets.unreset_all_except(&[], true);
314307

315308
//set RX and TX pins in UART mode
316309
let gpio_tx = peripherals.pins.get_pin(RPGpio::GPIO0);
@@ -723,7 +716,7 @@ pub unsafe fn start() -> (
723716

724717
let mut pio: Pio = Pio::new_pio0();
725718

726-
let _pio_pwm = PioPwm::new(&mut pio, &peripherals.clocks);
719+
let _pio_pwm = PioPwm::new(&mut pio, clocks);
727720
// This will start a PWM with PIO with the set frequency and duty cycle on the specified pin.
728721
// pio_pwm
729722
// .start(

boards/raspberry_pi_pico/src/io.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use kernel::hil::uart::{Configure, Parameters, Parity, StopBits, Width};
1111
use kernel::utilities::cells::OptionalCell;
1212
use kernel::utilities::io_write::IoWrite;
1313

14+
use rp2040::clocks::Clocks;
1415
use rp2040::gpio::{GpioFunction, RPGpio, RPGpioPin};
1516
use rp2040::uart::Uart;
1617

@@ -66,7 +67,8 @@ impl IoWrite for Writer {
6667
fn write(&mut self, buf: &[u8]) -> usize {
6768
self.uart.map_or_else(
6869
|| {
69-
let uart = Uart::new_uart0();
70+
let clocks = Clocks::new();
71+
let uart = Uart::new_uart0(&clocks);
7072
self.configure_uart(&uart);
7173
self.write_to_uart(&uart, buf);
7274
},

0 commit comments

Comments
 (0)