Skip to content

Commit

Permalink
Merge pull request #618 from jannic/timer-needs-clocks
Browse files Browse the repository at this point in the history
Make sure clocks are initialized before creating a Timer
  • Loading branch information
jannic authored May 21, 2023
2 parents c9ffba0 + c9244f1 commit 4f97282
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions rp2040-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- This doubles the flash access speed to the value used by the C SDK by
default. So it should usually be safe. However, if you are overclocking
the RP2040, you might need to lower the flash speed accordingly.
- timer: Make sure clocks are initialized before creating a timer - #618 @jannic

## [0.8.1] - 2023-05-05

Expand Down
4 changes: 2 additions & 2 deletions rp2040-hal/examples/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn main() -> ! {
let mut watchdog = hal::Watchdog::new(pac.WATCHDOG);

// Configure the clocks
let _clocks = hal::clocks::init_clocks_and_plls(
let clocks = hal::clocks::init_clocks_and_plls(
XTAL_FREQ_HZ,
pac.XOSC,
pac.CLOCKS,
Expand All @@ -64,7 +64,7 @@ fn main() -> ! {
.ok()
.unwrap();

let mut timer = rp2040_hal::Timer::new(pac.TIMER, &mut pac.RESETS);
let mut timer = rp2040_hal::Timer::new(pac.TIMER, &mut pac.RESETS, &clocks);

// The single-cycle I/O block controls our GPIO pins
let sio = hal::Sio::new(pac.SIO);
Expand Down
2 changes: 1 addition & 1 deletion rp2040-hal/examples/vector_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn main() -> ! {
// Configure GPIO25 as an output
let led_pin = pins.gpio25.into_push_pull_output();

let mut timer = hal::Timer::new(pac.TIMER, &mut pac.RESETS);
let mut timer = hal::Timer::new(pac.TIMER, &mut pac.RESETS, &clocks);
critical_section::with(|cs| {
let mut alarm = timer.alarm_0().unwrap();
// Schedule an alarm in 1 second
Expand Down
7 changes: 4 additions & 3 deletions rp2040-hal/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use fugit::{MicrosDurationU32, MicrosDurationU64, TimerInstantU64};

use crate::atomic_register_access::{write_bitmask_clear, write_bitmask_set};
use crate::clocks::ClocksManager;
use crate::pac::{RESETS, TIMER};
use crate::resets::SubsystemReset;
use crate::typelevel::Sealed;
Expand Down Expand Up @@ -56,7 +57,7 @@ impl Timer {
/// Make sure that clocks and watchdog are configured, so
/// that timer ticks happen at a frequency of 1MHz.
/// Otherwise, `Timer` won't work as expected.
pub fn new(timer: TIMER, resets: &mut RESETS) -> Self {
pub fn new(timer: TIMER, resets: &mut RESETS, _clocks: &ClocksManager) -> Self {
timer.reset_bring_down(resets);
timer.reset_bring_up(resets);
Self { _private: () }
Expand Down Expand Up @@ -180,9 +181,9 @@ impl eh1_0_alpha::delay::DelayUs for Timer {
/// let mut pac = rp2040_hal::pac::Peripherals::take().unwrap();
/// // Make sure to initialize clocks, otherwise the timer wouldn't work
/// // properly. Omitted here for terseness.
/// let _clocks: rp2040_hal::clocks::ClocksManager = todo!();
/// let clocks: rp2040_hal::clocks::ClocksManager = todo!();
/// // Configure the Timer peripheral in count-down mode
/// let timer = rp2040_hal::Timer::new(pac.TIMER, &mut pac.RESETS);
/// let timer = rp2040_hal::Timer::new(pac.TIMER, &mut pac.RESETS, &clocks);
/// let mut count_down = timer.count_down();
/// // Create a count_down timer for 500 milliseconds
/// count_down.start(500.millis());
Expand Down

0 comments on commit 4f97282

Please sign in to comment.