-
Notifications
You must be signed in to change notification settings - Fork 184
Adds some simple methods to Timer. #52
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
Conversation
Looks okay to me but there's no need to release |
It makes sense, I did not realize that before. I have changed that bit in the new commit. |
src/timer.rs
Outdated
self.tim.disable_counter(); | ||
} | ||
|
||
/// Releases the SYST and clocks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Releases the SYST and clocks | |
/// Releases the SYST |
src/timer.rs
Outdated
|
||
/// Releases the TIM Peripheral and clocks | ||
pub fn release(self) -> $TIMX { | ||
self.tim.cr1.modify(|_, w| w.cen().clear_bit()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we simply call stop()
from above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add an entry to CHANGELOG.md.
@TheZoq2 Any comments from your side?
Looks good to me |
I updated the Changelog, don't know if I over-explained it, feel free to modify. |
Looks good to me, though I did think of another improvement which would be nice. Could you replace the already existing calls to Also, I would argue that calling that function |
How about |
Yea, that is probably even better! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, will use it as soon as it's published!
CHANGELOG.md
Outdated
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). | |||
- Add feature for using STM32F101 chip | |||
- Add gpio pins corresponding to LQFP-100 package | |||
- Implement `core::fmt::Write` for `serial::Tx` | |||
- Add methods `stop`, `release` and `clear_uif` to `Timer` (`clear_uif` only on `Timer<TIMX>`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unsync
src/timer.rs
Outdated
|
||
/// Releases the SYST | ||
pub fn release(mut self) -> SYST { | ||
self.tim.disable_counter(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: better to self.stop()
as any bug on stop must be propagated here.
I will modify the code to use the new methods as proposed and I think I will write an example for the Timer interrupt with rtfm and add it to the PR. |
464309c
to
ba8717b
Compare
I ended up getting some spare time today, so there you go. Sorry for the bunch of commits, but I guess you gonna squash them all anyways. |
Thanks, looks good to me! @therealprof What's our policy on adding dependencies for examples, #2 didn't really come to a conclusion. I believe that rtfm was originally removed because it didn't compile on stable, but that's solved now. I'm fine with having rtfm as a dependency since it's a pretty common crate in the embedded rust world, but at the same time, adding a bunch of dependencies might be a bad idea for compilation times and security. |
I kinda understand the dependencies for examples thing, but in the present scenario I would think that it is somewhat bad to push newcomers to implement interrupts (with handlers and stuff) without rtfm. |
@TheZoq2 I'm generally not too hot on having examples in this crate (apart from in the docs). Ideally we should have BSP crates which go nuts on examples. I do have a a basic https://github.com/therealprof/nucleo-f103rb crate, if people are interested I could make this free for all, or just create a new blue pill crate. However for now it's okay for me to just add back the RTFM dependency. |
@thalesfragoso The problem is that a universal HAL crate is somewhat tricky to use anyway, especially for beginners; so instead of dragging newcomers into examples in here we really should demonstrate how to get properly started with your own projects by having a proper BSP crate. |
Yea, eventually we should probably take care of this example stuff, and a BSP with examples does sound like a good idea. I do agree that having a RTFM example for interrupts is much better than one without RTFM :) I guess all that's left to do then is to merge this, thanks for the help! @thalesfragoso |
resources.LED.set_high(); | ||
*resources.LED_STATE = false; | ||
} else { | ||
resources.LED.set_low(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can call resources.LED.toggle();
and remove LED_STATE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does PC13<Output<MODE>>
have toggle ? I remember looking at the docs when I was writing other code and could not find it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've used it in the past https://github.com/TeXitoi/blue-pill-quickstart/blob/master/src/main.rs#L41
|
||
loop { | ||
// Waits for interrupt | ||
wfi(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just not define an idle()
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it automatically call wfi() ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://japaric.github.io/cortex-m-rtfm/book/en/by-example/app.html#idle
When no idle function is declared, the runtime sets the SLEEPONEXIT bit and then sends the microcontroller to sleep after running init.
Very simple methods but potentially useful, especially the one to clear the update interrupt flag.
I was having trouble using the timer with interrupts, because the Timer takes ownership of the registers and the
tim
field is private.Sorry if I got something wrong, I am kinda new to rust.