diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-06-22 23:33:29 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-06-22 23:33:29 +0000 |
| commit | cf69f78162cb60e436789c446209fb6e51c77b48 (patch) | |
| tree | dbc332ca590262e20ac1bb4ef034584542e39b27 /examples | |
| parent | 4a6f69e2d9e1c18ff5999a6aa049c280a6b8dcc4 (diff) | |
| parent | 88c37377228f824a09a22b2f49900dd0ec8b72bb (diff) | |
Merge #827
827: Fix PWM for advanced timers r=Dirbaio a=chemicstry
Advanced timers have additional BDTR register, which has a global output enable bit and it is disabled by default.
Also added an example for F4, but it will only work once https://github.com/embassy-rs/stm32-data/pull/149 is merged. We can also move it to some other chip, but I don't have anything else to test on atm.
Co-authored-by: chemicstry <[email protected]>
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32f4/src/bin/pwm.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/stm32f4/src/bin/pwm.rs b/examples/stm32f4/src/bin/pwm.rs new file mode 100644 index 000000000..cd20c68bb --- /dev/null +++ b/examples/stm32f4/src/bin/pwm.rs | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::*; | ||
| 6 | use embassy::executor::Spawner; | ||
| 7 | use embassy::time::{Duration, Timer}; | ||
| 8 | use embassy_stm32::pwm::simple_pwm::SimplePwm; | ||
| 9 | use embassy_stm32::pwm::Channel; | ||
| 10 | use embassy_stm32::time::U32Ext; | ||
| 11 | use embassy_stm32::Peripherals; | ||
| 12 | use {defmt_rtt as _, panic_probe as _}; | ||
| 13 | |||
| 14 | #[embassy::main] | ||
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 16 | info!("Hello World!"); | ||
| 17 | |||
| 18 | let mut pwm = SimplePwm::new_1ch(p.TIM1, p.PE9, 10000.hz()); | ||
| 19 | let max = pwm.get_max_duty(); | ||
| 20 | pwm.enable(Channel::Ch1); | ||
| 21 | |||
| 22 | info!("PWM initialized"); | ||
| 23 | info!("PWM max duty {}", max); | ||
| 24 | |||
| 25 | loop { | ||
| 26 | pwm.set_duty(Channel::Ch1, 0); | ||
| 27 | Timer::after(Duration::from_millis(300)).await; | ||
| 28 | pwm.set_duty(Channel::Ch1, max / 4); | ||
| 29 | Timer::after(Duration::from_millis(300)).await; | ||
| 30 | pwm.set_duty(Channel::Ch1, max / 2); | ||
| 31 | Timer::after(Duration::from_millis(300)).await; | ||
| 32 | pwm.set_duty(Channel::Ch1, max - 1); | ||
| 33 | Timer::after(Duration::from_millis(300)).await; | ||
| 34 | } | ||
| 35 | } | ||
