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

Make sure clocks are initialized before creating a Timer #618

Merged
merged 2 commits into from
May 21, 2023
Merged
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
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