Skip to content

Commit 502752b

Browse files
Bobo1239burrbull
authored andcommitted
Don't overwrite other bits when enabling a PWM timer
In practice the only bit we set is CR1.ARPE which enables preloading/buffering of the timer auto reload value. Before this patch we set the bit (`tim.enable_preload(true)`) but then immediately unset the bit again when enabling PWM.
1 parent 4fb91ea commit 502752b

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
4040
- `Serial::usart1/2/3` -> `Serial::new`.
4141
- `Serial` implements `Write<WORD>` and `Read<WORD>` for `WORD` simultaneously as u8 and u16.
4242
- Bump bxcan version to [v0.7.0](https://github.com/stm32-rs/bxcan/releases/tag/v0.7.0)
43+
- PWM timer auto reload value is now preloaded/buffered
4344

4445
### Added
4546

src/timer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ macro_rules! hal {
400400
}
401401
#[inline(always)]
402402
fn start_one_pulse(&mut self) {
403-
self.cr1.write(|w| unsafe { w.bits(1 << 3) }.cen().set_bit());
403+
self.cr1.modify(|_, w| w.opm().set_bit().cen().set_bit());
404404
}
405405
#[inline(always)]
406406
fn cr1_reset(&mut self) {
@@ -460,7 +460,7 @@ macro_rules! with_pwm {
460460

461461
#[inline(always)]
462462
fn start_pwm(&mut self) {
463-
self.cr1.write(|w| w.cen().set_bit());
463+
self.cr1.modify(|_, w| w.cen().set_bit());
464464
}
465465

466466
#[inline(always)]
@@ -512,7 +512,7 @@ macro_rules! with_pwm {
512512

513513
#[inline(always)]
514514
fn start_pwm(&mut self) {
515-
self.cr1.write(|w| w.cen().set_bit());
515+
self.cr1.modify(|_, w| w.cen().set_bit());
516516
}
517517

518518
#[inline(always)]
@@ -565,7 +565,7 @@ macro_rules! with_pwm {
565565
#[inline(always)]
566566
fn start_pwm(&mut self) {
567567
$(let $aoe = self.bdtr.modify(|_, w| w.aoe().set_bit());)?
568-
self.cr1.write(|w| w.cen().set_bit());
568+
self.cr1.modify(|_, w| w.cen().set_bit());
569569
}
570570

571571
#[inline(always)]

0 commit comments

Comments
 (0)