aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-06-22 23:33:29 +0000
committerGitHub <[email protected]>2022-06-22 23:33:29 +0000
commitcf69f78162cb60e436789c446209fb6e51c77b48 (patch)
treedbc332ca590262e20ac1bb4ef034584542e39b27 /examples
parent4a6f69e2d9e1c18ff5999a6aa049c280a6b8dcc4 (diff)
parent88c37377228f824a09a22b2f49900dd0ec8b72bb (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.rs35
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
5use defmt::*;
6use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer};
8use embassy_stm32::pwm::simple_pwm::SimplePwm;
9use embassy_stm32::pwm::Channel;
10use embassy_stm32::time::U32Ext;
11use embassy_stm32::Peripherals;
12use {defmt_rtt as _, panic_probe as _};
13
14#[embassy::main]
15async 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}