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

Clocks/Delay papercut. #138

Closed
jonathanpallant opened this issue Sep 27, 2021 · 5 comments
Closed

Clocks/Delay papercut. #138

jonathanpallant opened this issue Sep 27, 2021 · 5 comments

Comments

@jonathanpallant
Copy link
Contributor

You have the system clock speed in the results of hal::clocks::init_clocks_and_plls. But you can't just pass it to cortex_m::delay::Delay. And it feels like you should be able to.

@jannic
Copy link
Member

jannic commented Oct 1, 2021

What's wrong with the current situation?

      let clocks = init_clocks_and_plls( [...] ).ok().unwrap();
      let sys_hz: u32 = clocks.system_clock.freq().integer();
      let mut delay = cortex_m::delay::Delay::new(core.SYST, sys_hz);

Too complicated?

@jonathanpallant
Copy link
Contributor Author

Yes. At worst it should be:

      let clocks = init_clocks_and_plls( [...] ).ok().unwrap();
      let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.into());

Don't forget your example requires I think two traits to be in scope.

@jannic
Copy link
Member

jannic commented Feb 16, 2022

Looking at other HALs, one option is to just not use cortex_m::delay::Delay but implement our own Delay, like here:

Interestingly, I found those by searching for Delay::new in the https://github.com/rust-embedded organization, the very one where the cortex_m crate also lives. Perhaps cortex_m::delay::Delay is just too low-level?

Also noteworthy: rust-embedded/embedded-hal#103

@jannic
Copy link
Member

jannic commented May 29, 2023

@jonathanpallant: Now that Timer implements the delay traits, it shouldn't be necessary to use cortex_m::delay::Delay. Can we close this ticket, or do you think it's still worth improving the usability of cortex_m::delay::Delay?

The usage with Timer is now:

let clocks = init_clocks_and_plls( [...] ).ok().unwrap();
let mut timer = rp2040_hal::Timer::new(pac.TIMER, &mut pac.RESETS, &clocks);
timer.delay_ms(500);

@jannic
Copy link
Member

jannic commented Jul 5, 2024

As mentioned above, I think this is solved with the current API. Timer should be the common delay implementation, so the usability of cortex_m::delay::Delay isn't as important as before.

@thejpster, feel free to reopen if you disagree.

@jannic jannic closed this as completed Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants