diff options
| author | xoviat <[email protected]> | 2023-06-27 20:30:58 -0500 |
|---|---|---|
| committer | xoviat <[email protected]> | 2023-06-30 18:21:59 -0500 |
| commit | 3252eaa060d8efb79f99511ac40a26be9cf287f9 (patch) | |
| tree | 8c7cbad841e2a7433146aed520a35d8087b3ec16 /examples/stm32f334/src/bin | |
| parent | 348019e37f0ff5716d80199e33244c0a1a59b360 (diff) | |
stm32/hrtim: add example impl.
Diffstat (limited to 'examples/stm32f334/src/bin')
| -rw-r--r-- | examples/stm32f334/src/bin/hello.rs | 23 | ||||
| -rw-r--r-- | examples/stm32f334/src/bin/pwm.rs | 63 |
2 files changed, 86 insertions, 0 deletions
diff --git a/examples/stm32f334/src/bin/hello.rs b/examples/stm32f334/src/bin/hello.rs new file mode 100644 index 000000000..65773210d --- /dev/null +++ b/examples/stm32f334/src/bin/hello.rs | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::info; | ||
| 6 | use embassy_executor::Spawner; | ||
| 7 | use embassy_stm32::time::Hertz; | ||
| 8 | use embassy_stm32::Config; | ||
| 9 | use embassy_time::{Duration, Timer}; | ||
| 10 | use {defmt_rtt as _, panic_probe as _}; | ||
| 11 | |||
| 12 | #[embassy_executor::main] | ||
| 13 | async fn main(_spawner: Spawner) -> ! { | ||
| 14 | let mut config = Config::default(); | ||
| 15 | config.rcc.hse = Some(Hertz(8_000_000)); | ||
| 16 | config.rcc.sysclk = Some(Hertz(16_000_000)); | ||
| 17 | let _p = embassy_stm32::init(config); | ||
| 18 | |||
| 19 | loop { | ||
| 20 | info!("Hello World!"); | ||
| 21 | Timer::after(Duration::from_secs(1)).await; | ||
| 22 | } | ||
| 23 | } | ||
diff --git a/examples/stm32f334/src/bin/pwm.rs b/examples/stm32f334/src/bin/pwm.rs new file mode 100644 index 000000000..cc2ea8617 --- /dev/null +++ b/examples/stm32f334/src/bin/pwm.rs | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::*; | ||
| 6 | use embassy_executor::Spawner; | ||
| 7 | use embassy_stm32::pwm::advanced_pwm::*; | ||
| 8 | use embassy_stm32::pwm::Channel; | ||
| 9 | use embassy_stm32::time::khz; | ||
| 10 | use embassy_time::{Duration, Timer}; | ||
| 11 | use {defmt_rtt as _, panic_probe as _}; | ||
| 12 | |||
| 13 | #[embassy_executor::main] | ||
| 14 | async fn main(_spawner: Spawner) { | ||
| 15 | let p = embassy_stm32::init(Default::default()); | ||
| 16 | info!("Hello World!"); | ||
| 17 | |||
| 18 | let ch1 = PwmPin::new_cha(p.PA8); | ||
| 19 | let ch1n = ComplementaryPwmPin::new_cha(p.PA9); | ||
| 20 | let mut pwm = AdvancedPwm::new( | ||
| 21 | p.HRTIM1, | ||
| 22 | Some(ch1), | ||
| 23 | Some(ch1n), | ||
| 24 | None, | ||
| 25 | None, | ||
| 26 | None, | ||
| 27 | None, | ||
| 28 | None, | ||
| 29 | None, | ||
| 30 | None, | ||
| 31 | None, | ||
| 32 | ); | ||
| 33 | |||
| 34 | pwm.set_dead_time(0); | ||
| 35 | |||
| 36 | let mut buck_converter = BridgeConverter::new(pwm.ch_a, khz(100)); | ||
| 37 | |||
| 38 | buck_converter.set_duty(0, u16::MAX); | ||
| 39 | |||
| 40 | // note: if the pins are not passed into the advanced pwm struct, they will not be output | ||
| 41 | let mut boost_converter = BridgeConverter::new(pwm.ch_b, khz(100)); | ||
| 42 | |||
| 43 | boost_converter.set_duty(0, 0); | ||
| 44 | |||
| 45 | // let max = pwm.get_max_duty(); | ||
| 46 | // pwm.set_dead_time(max / 1024); | ||
| 47 | // | ||
| 48 | // pwm.enable(Channel::Ch1); | ||
| 49 | // | ||
| 50 | // info!("PWM initialized"); | ||
| 51 | // info!("PWM max duty {}", max); | ||
| 52 | // | ||
| 53 | // loop { | ||
| 54 | // pwm.set_duty(Channel::Ch1, 0); | ||
| 55 | // Timer::after(Duration::from_millis(300)).await; | ||
| 56 | // pwm.set_duty(Channel::Ch1, max / 4); | ||
| 57 | // Timer::after(Duration::from_millis(300)).await; | ||
| 58 | // pwm.set_duty(Channel::Ch1, max / 2); | ||
| 59 | // Timer::after(Duration::from_millis(300)).await; | ||
| 60 | // pwm.set_duty(Channel::Ch1, max - 1); | ||
| 61 | // Timer::after(Duration::from_millis(300)).await; | ||
| 62 | // } | ||
| 63 | } | ||
