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::*;
|
2023-09-10 20:33:17 +02:00
|
|
|
use embassy_stm32::rcc::HrtimClockSource;
|
2023-07-02 04:47:44 +02:00
|
|
|
use embassy_stm32::time::{khz, mhz};
|
|
|
|
use embassy_stm32::Config;
|
2023-10-15 01:57:25 +02:00
|
|
|
use embassy_time::Timer;
|
2023-06-28 03:30:58 +02:00
|
|
|
use {defmt_rtt as _, panic_probe as _};
|
|
|
|
|
|
|
|
#[embassy_executor::main]
|
|
|
|
async fn main(_spawner: Spawner) {
|
2023-07-02 04:47:44 +02:00
|
|
|
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));
|
2023-09-10 20:33:17 +02:00
|
|
|
config.rcc.hrtim = HrtimClockSource::PllClk;
|
2023-07-02 04:47:44 +02:00
|
|
|
|
|
|
|
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,
|
|
|
|
);
|
|
|
|
|
2023-07-02 04:47:44 +02:00
|
|
|
info!("pwm constructed");
|
2023-06-28 03:30:58 +02:00
|
|
|
|
2023-07-02 04:47:44 +02:00
|
|
|
let mut buck_converter = BridgeConverter::new(pwm.ch_a, khz(5));
|
2023-06-28 03:30:58 +02:00
|
|
|
|
2023-07-02 04:47:44 +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
|
|
|
//
|
2023-10-15 01:57:25 +02:00
|
|
|
// Timer::after_millis(500).await;
|
2023-06-28 03:30:58 +02:00
|
|
|
//
|
2023-07-02 04:47:44 +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();
|
|
|
|
|
2023-10-15 01:57:25 +02:00
|
|
|
Timer::after_millis(500).await;
|
2023-07-02 04:47:44 +02:00
|
|
|
|
|
|
|
info!("end program");
|
|
|
|
|
|
|
|
cortex_m::asm::bkpt();
|
2023-06-28 03:30:58 +02:00
|
|
|
}
|