embassy/examples/stm32f334/src/bin/pwm.rs

72 lines
1.7 KiB
Rust
Raw Normal View History

2023-06-28 03:30:58 +02:00
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
use defmt::*;
use embassy_executor::Spawner;
2023-07-29 00:07:08 +02:00
use embassy_stm32::hrtim::*;
use embassy_stm32::time::{khz, mhz};
use embassy_stm32::Config;
use embassy_time::{Duration, Timer};
2023-06-28 03:30:58 +02:00
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let mut config: Config = Default::default();
config.rcc.sysclk = Some(mhz(64));
config.rcc.hclk = Some(mhz(64));
config.rcc.pclk1 = Some(mhz(32));
config.rcc.pclk2 = Some(mhz(64));
let p = embassy_stm32::init(config);
2023-06-28 03:30:58 +02:00
info!("Hello World!");
let ch1 = PwmPin::new_cha(p.PA8);
let ch1n = ComplementaryPwmPin::new_cha(p.PA9);
2023-07-01 01:33:22 +02:00
let pwm = AdvancedPwm::new(
2023-06-28 03:30:58 +02:00
p.HRTIM1,
Some(ch1),
Some(ch1n),
None,
None,
None,
None,
None,
None,
None,
None,
);
info!("pwm constructed");
2023-06-28 03:30:58 +02:00
let mut buck_converter = BridgeConverter::new(pwm.ch_a, khz(5));
2023-06-28 03:30:58 +02:00
// embassy_stm32::pac::HRTIM1
// .tim(0)
// .setr(0)
// .modify(|w| w.set_sst(Activeeffect::SETACTIVE));
2023-06-28 03:30:58 +02:00
//
// Timer::after(Duration::from_millis(500)).await;
2023-06-28 03:30:58 +02:00
//
// embassy_stm32::pac::HRTIM1
// .tim(0)
// .rstr(0)
// .modify(|w| w.set_srt(Inactiveeffect::SETINACTIVE));
let max_duty = buck_converter.get_max_compare_value();
info!("max compare value: {}", max_duty);
buck_converter.set_dead_time(max_duty / 20);
buck_converter.set_primary_duty(max_duty / 2);
buck_converter.set_secondary_duty(3 * max_duty / 4);
buck_converter.start();
Timer::after(Duration::from_millis(500)).await;
info!("end program");
cortex_m::asm::bkpt();
2023-06-28 03:30:58 +02:00
}