From f9099f8a0e59cd93ba5a8e674828c11fee00dc8e Mon Sep 17 00:00:00 2001 From: Albin Hedman Date: Thu, 7 Nov 2024 23:59:37 +0100 Subject: [PATCH] HRTIM - Update examples --- examples/hrtim/adc-trigger.rs | 10 +++++----- examples/hrtim/capture-dma.rs | 6 +++--- examples/hrtim/capture.rs | 29 +++++++++++++---------------- examples/hrtim/eev-comp.rs | 9 +++------ examples/hrtim/eev.rs | 9 +++------ examples/hrtim/flt-comp.rs | 12 ++++-------- examples/hrtim/flt.rs | 12 ++++-------- examples/hrtim/hrtim.rs | 10 +++------- examples/hrtim/master.rs | 17 +++-------------- examples/hrtim/simple.rs | 5 ++--- 10 files changed, 43 insertions(+), 76 deletions(-) diff --git a/examples/hrtim/adc-trigger.rs b/examples/hrtim/adc-trigger.rs index 7c6facb9..e2e4d5e3 100644 --- a/examples/hrtim/adc-trigger.rs +++ b/examples/hrtim/adc-trigger.rs @@ -25,7 +25,7 @@ fn main() -> ! { }, delay::SYSTDelayExt, dma::{self, config::DmaConfig, stream::DMAExt, TransferExt}, - gpio::{gpioa::PA8, gpioa::PA9, Alternate, GpioExt, AF13}, + gpio::GpioExt, hrtim::compare_register::HrCompareRegister, hrtim::control::HrControltExt, hrtim::output::HrOutput, @@ -50,7 +50,7 @@ fn main() -> ! { let pwr = dp.PWR.constrain().freeze(); let mut rcc = dp.RCC.freeze( rcc::Config::pll().pll_cfg(rcc::PllConfig { - mux: rcc::PLLSrc::HSI, + mux: rcc::PllSrc::HSI, n: rcc::PllNMul::MUL_15, m: rcc::PllMDiv::DIV_1, r: Some(rcc::PllRDiv::DIV_2), @@ -72,8 +72,8 @@ fn main() -> ! { let gpioa = dp.GPIOA.split(&mut rcc); let pa0 = gpioa.pa0.into_analog(); - let pin_a: PA8> = gpioa.pa8.into_alternate(); - let pin_b: PA9> = gpioa.pa9.into_alternate(); + let pin_a = gpioa.pa8; + let pin_b = gpioa.pa9; // ...with a prescaler of 4 this gives us a HrTimer with a tick rate of 960MHz // With max the max period set, this would be 960MHz/2^16 ~= 15kHz... @@ -140,7 +140,7 @@ fn main() -> ! { out1.enable(); out2.enable(); - timer.start(&mut hr_control); + timer.start(&mut hr_control.control); loop { let mut b = [0_u16; 4]; diff --git a/examples/hrtim/capture-dma.rs b/examples/hrtim/capture-dma.rs index 3e513ebf..ade47443 100644 --- a/examples/hrtim/capture-dma.rs +++ b/examples/hrtim/capture-dma.rs @@ -19,7 +19,7 @@ fn main() -> ! { use hal::{ dma::{config::DmaConfig, stream::DMAExt, TransferExt}, - gpio::{gpioa::PA8, Alternate, GpioExt, AF13}, + gpio::{GpioExt, AF13}, hrtim::{ capture, compare_register::HrCompareRegister, control::HrControltExt, external_event, external_event::ToExternalEventSource, output::HrOutput, timer::HrSlaveTimerCpt, @@ -56,7 +56,7 @@ fn main() -> ! { let gpiob = dp.GPIOB.split(&mut rcc); // PA8 (D7 on Nucleo G474RE) - let pin_a: PA8> = gpioa.pa8.into_alternate(); + let pin_a = gpioa.pa8; // PB5 (D4 on Nucleo G474RE) let input = gpiob.pb5.into_pull_down_input(); @@ -98,7 +98,7 @@ fn main() -> ! { cr1.set_duty(period / 2); let (mut timer, mut capture, _capture_ch2) = timer.split_capture(); - timer.start(&mut hr_control); + timer.start(&mut hr_control.control); out1.enable(); capture.enable_interrupt(true, &mut hr_control); diff --git a/examples/hrtim/capture.rs b/examples/hrtim/capture.rs index c62e84c5..1e0c2c46 100644 --- a/examples/hrtim/capture.rs +++ b/examples/hrtim/capture.rs @@ -18,7 +18,7 @@ fn main() -> ! { use stm32g4xx_hal as hal; use hal::{ - gpio::{gpioa::PA8, Alternate, GpioExt, AF13}, + gpio::GpioExt, hrtim::{ capture::HrCapture, compare_register::HrCompareRegister, control::HrControltExt, external_event, external_event::ToExternalEventSource, output::HrOutput, @@ -40,7 +40,7 @@ fn main() -> ! { let pwr = dp.PWR.constrain().freeze(); let mut rcc = dp.RCC.freeze( rcc::Config::pll().pll_cfg(rcc::PllConfig { - mux: rcc::PLLSrc::HSI, + mux: rcc::PllSrc::HSI, n: rcc::PllNMul::MUL_15, m: rcc::PllMDiv::DIV_1, r: Some(rcc::PllRDiv::DIV_2), @@ -55,7 +55,7 @@ fn main() -> ! { let gpiob = dp.GPIOB.split(&mut rcc); // PA8 (D7 on Nucleo G474RE) - let pin_a: PA8> = gpioa.pa8.into_alternate(); + let pin_a = gpioa.pa8; // PB5 (D4 on Nucleo G474RE) let input = gpiob.pb5.into_pull_down_input(); @@ -94,7 +94,7 @@ fn main() -> ! { out1.enable_set_event(&timer); // Set high at new period cr1.set_duty(period / 2); - timer.start(&mut hr_control); + timer.start(&mut hr_control.control); out1.enable(); let capture = timer.capture_ch1(); @@ -104,19 +104,16 @@ fn main() -> ! { let mut old_duty = 0; loop { for duty in (u32::from(period) / 10)..(9 * u32::from(period) / 10) { - if !capture.is_pending() { - continue; + if let Some(value) = capture.get_signed(period) { + info!( + "Capture: {:?}, duty: {}, diff: {}", + value, + old_duty, + value - old_duty as i32 + ); + cr1.set_duty(duty as u16); + old_duty = duty; } - let value = capture.get_signed(); - cr1.set_duty(duty as u16); - capture.clear_interrupt(); - info!( - "Capture: {:?}, duty: {}, diff: {}", - value, - old_duty, - value - old_duty as i32 - ); - old_duty = duty; } } } diff --git a/examples/hrtim/eev-comp.rs b/examples/hrtim/eev-comp.rs index c4a7ee06..329779de 100644 --- a/examples/hrtim/eev-comp.rs +++ b/examples/hrtim/eev-comp.rs @@ -19,10 +19,7 @@ fn main() -> ! { use hal::comparator; use hal::comparator::{ComparatorExt, ComparatorSplit, Hysteresis}; use hal::dac::{self, DacExt, DacOut}; - use hal::gpio::gpioa::PA8; - use hal::gpio::Alternate; use hal::gpio::SignalEdge; - use hal::gpio::AF13; use hal::hrtim::compare_register::HrCompareRegister; use hal::hrtim::external_event::{self, ToExternalEventSource}; use hal::hrtim::timer::HrTimer; @@ -45,7 +42,7 @@ fn main() -> ! { let mut rcc = dp.RCC.freeze( rcc::Config::pll().pll_cfg(rcc::PllConfig { - mux: rcc::PLLSrc::HSI, + mux: rcc::PllSrc::HSI, n: rcc::PllNMul::MUL_75, m: rcc::PllMDiv::DIV_4, r: Some(rcc::PllRDiv::DIV_2), @@ -61,7 +58,7 @@ fn main() -> ! { let gpioa = dp.GPIOA.split(&mut rcc); let input = gpioa.pa1.into_analog(); - let pin_a: PA8> = gpioa.pa8.into_alternate(); + let pin_a = gpioa.pa8; let dac1ch1 = dp.DAC1.constrain(dac::Dac1IntSig1, &mut rcc); let mut dac = dac1ch1.calibrate_buffer(&mut delay).enable(); @@ -128,7 +125,7 @@ fn main() -> ! { cr1.set_duty(timer.get_period() / 3); out1.enable(); - timer.start(&mut hr_control); + timer.start(&mut hr_control.control); info!("Started"); diff --git a/examples/hrtim/eev.rs b/examples/hrtim/eev.rs index 636564bc..a8a3e662 100644 --- a/examples/hrtim/eev.rs +++ b/examples/hrtim/eev.rs @@ -16,9 +16,6 @@ use utils::logger::info; #[entry] fn main() -> ! { - use hal::gpio::gpioa::PA8; - use hal::gpio::Alternate; - use hal::gpio::AF13; use hal::hrtim::compare_register::HrCompareRegister; use hal::hrtim::external_event; use hal::hrtim::external_event::ToExternalEventSource; @@ -41,7 +38,7 @@ fn main() -> ! { let mut rcc = dp.RCC.freeze( rcc::Config::pll().pll_cfg(rcc::PllConfig { - mux: rcc::PLLSrc::HSI, + mux: rcc::PllSrc::HSI, n: rcc::PllNMul::MUL_75, m: rcc::PllMDiv::DIV_4, r: Some(rcc::PllRDiv::DIV_2), @@ -70,7 +67,7 @@ fn main() -> ! { // With max the max period set, this would be 1.2GHz/2^16 ~= 18kHz... let prescaler = Pscl4; - let pin_a: PA8> = gpioa.pa8.into_alternate(); + let pin_a = gpioa.pa8; // . . * . // . 33% . * . . . @@ -100,7 +97,7 @@ fn main() -> ! { cr1.set_duty(timer.get_period() / 3); out1.enable(); - timer.start(&mut hr_control); + timer.start(&mut hr_control.control); info!("Started"); diff --git a/examples/hrtim/flt-comp.rs b/examples/hrtim/flt-comp.rs index 9131f42f..235bceb2 100644 --- a/examples/hrtim/flt-comp.rs +++ b/examples/hrtim/flt-comp.rs @@ -18,17 +18,13 @@ use utils::logger::info; fn main() -> ! { use hal::comparator::{ComparatorExt, ComparatorSplit, Config, Hysteresis}; use hal::dac::{Dac3IntSig1, DacExt, DacOut}; - use hal::gpio::gpioa::PA8; - use hal::gpio::Alternate; - use hal::gpio::AF13; use hal::hrtim::compare_register::HrCompareRegister; - use hal::hrtim::fault::FaultAction; + use hal::hrtim::fault::{FaultAction, FaultMonitor}; use hal::hrtim::timer::HrTimer; use hal::hrtim::HrPwmAdvExt; use hal::hrtim::Pscl4; use hal::hrtim::{control::HrControltExt, output::HrOutput}; use hal::prelude::*; - use hal::pwm::FaultMonitor; use hal::rcc; use hal::stm32; use stm32g4xx_hal as hal; @@ -42,7 +38,7 @@ fn main() -> ! { let pwr = dp.PWR.constrain().freeze(); let mut rcc = dp.RCC.freeze( rcc::Config::pll().pll_cfg(rcc::PllConfig { - mux: rcc::PLLSrc::HSI, + mux: rcc::PllSrc::HSI, n: rcc::PllNMul::MUL_15, m: rcc::PllMDiv::DIV_1, r: Some(rcc::PllRDiv::DIV_2), @@ -100,7 +96,7 @@ fn main() -> ! { // With max the max period set, this would be 1.2GHz/2^16 ~= 18kHz... let prescaler = Pscl4; - let pin_a: PA8> = gpioa.pa8.into_alternate(); + let pin_a = gpioa.pa8; // . . . * // . 33% . . * . . @@ -131,7 +127,7 @@ fn main() -> ! { cr1.set_duty(timer.get_period() / 3); //unsafe {((HRTIM_COMMON::ptr() as *mut u8).offset(0x14) as *mut u32).write_volatile(1); } out1.enable(); - timer.start(&mut hr_control); + timer.start(&mut hr_control.control); info!("Started"); diff --git a/examples/hrtim/flt.rs b/examples/hrtim/flt.rs index a1a6879e..990c7e79 100644 --- a/examples/hrtim/flt.rs +++ b/examples/hrtim/flt.rs @@ -16,17 +16,13 @@ use utils::logger::info; #[entry] fn main() -> ! { - use hal::gpio::gpioa::PA8; - use hal::gpio::Alternate; - use hal::gpio::AF13; use hal::hrtim::compare_register::HrCompareRegister; - use hal::hrtim::fault::FaultAction; + use hal::hrtim::fault::{FaultAction, FaultMonitor}; use hal::hrtim::timer::HrTimer; use hal::hrtim::HrPwmAdvExt; use hal::hrtim::Pscl4; use hal::hrtim::{control::HrControltExt, output::HrOutput}; use hal::prelude::*; - use hal::pwm::FaultMonitor; use hal::pwr::PwrExt; use hal::rcc; use hal::stm32; @@ -40,7 +36,7 @@ fn main() -> ! { let pwr = dp.PWR.constrain().freeze(); let mut rcc = dp.RCC.freeze( rcc::Config::pll().pll_cfg(rcc::PllConfig { - mux: rcc::PLLSrc::HSI, + mux: rcc::PllSrc::HSI, n: rcc::PllNMul::MUL_75, m: rcc::PllMDiv::DIV_4, r: Some(rcc::PllRDiv::DIV_2), @@ -66,7 +62,7 @@ fn main() -> ! { // With max the max period set, this would be 1.2GHz/2^16 ~= 18kHz... let prescaler = Pscl4; - let pin_a: PA8> = gpioa.pa8.into_alternate(); + let pin_a = gpioa.pa8; // . . . * // . 33% . . * . . @@ -105,7 +101,7 @@ fn main() -> ! { cr1.set_duty(timer.get_period() / 3); //unsafe {((HRTIM_COMMON::ptr() as *mut u8).offset(0x14) as *mut u32).write_volatile(1); } out1.enable(); - timer.start(&mut hr_control); + timer.start(&mut hr_control.control); info!("Started"); diff --git a/examples/hrtim/hrtim.rs b/examples/hrtim/hrtim.rs index b29ceffe..845b0f34 100644 --- a/examples/hrtim/hrtim.rs +++ b/examples/hrtim/hrtim.rs @@ -16,10 +16,6 @@ use utils::logger::info; #[entry] fn main() -> ! { use fugit::ExtU32; - use hal::gpio::gpioa::PA8; - use hal::gpio::gpioa::PA9; - use hal::gpio::Alternate; - use hal::gpio::AF13; use hal::hrtim::compare_register::HrCompareRegister; use hal::hrtim::control::HrControltExt; use hal::hrtim::output::HrOutput; @@ -42,7 +38,7 @@ fn main() -> ! { let pwr = dp.PWR.constrain().freeze(); let mut rcc = dp.RCC.freeze( rcc::Config::pll().pll_cfg(rcc::PllConfig { - mux: rcc::PLLSrc::HSI, + mux: rcc::PllSrc::HSI, n: rcc::PllNMul::MUL_15, m: rcc::PllMDiv::DIV_1, r: Some(rcc::PllRDiv::DIV_2), @@ -59,8 +55,8 @@ fn main() -> ! { let prescaler = Pscl4; let gpioa = dp.GPIOA.split(&mut rcc); - let pin_a: PA8> = gpioa.pa8.into_alternate(); - let pin_b: PA9> = gpioa.pa9.into_alternate(); + let pin_a = gpioa.pa8; + let pin_b = gpioa.pa9; // . . . . // . 30% . . . diff --git a/examples/hrtim/master.rs b/examples/hrtim/master.rs index a74dafff..b707de08 100644 --- a/examples/hrtim/master.rs +++ b/examples/hrtim/master.rs @@ -16,10 +16,6 @@ use utils::logger::info; #[entry] fn main() -> ! { use fugit::ExtU32; - use hal::gpio::gpioa::PA8; - use hal::gpio::gpioa::PA9; - use hal::gpio::Alternate; - use hal::gpio::AF13; use hal::hrtim::compare_register::HrCompareRegister; use hal::hrtim::control::HrControltExt; use hal::hrtim::output::HrOutput; @@ -41,7 +37,7 @@ fn main() -> ! { let pwr = dp.PWR.constrain().freeze(); let mut rcc = dp.RCC.freeze( rcc::Config::pll().pll_cfg(rcc::PllConfig { - mux: rcc::PLLSrc::HSI, + mux: rcc::PllSrc::HSI, n: rcc::PllNMul::MUL_15, m: rcc::PllMDiv::DIV_1, r: Some(rcc::PllRDiv::DIV_2), @@ -58,8 +54,8 @@ fn main() -> ! { let prescaler = Pscl4; let gpioa = dp.GPIOA.split(&mut rcc); - let pin_a: PA8> = gpioa.pa8.into_alternate(); - let pin_b: PA9> = gpioa.pa9.into_alternate(); + let pin_a = gpioa.pa8; + let pin_b = gpioa.pa9; // . . . . // . 30% . . . @@ -108,13 +104,6 @@ fn main() -> ! { out1.enable(); out2.enable(); - let tima = unsafe { &*stm32g4xx_hal::stm32::HRTIM_TIMA::ptr() }; - info!("set1r: {}", tima.seta1r.read().bits()); - info!("rst1r: {}", tima.rsta1r.read().bits()); - - info!("set2r: {}", tima.seta2r.read().bits()); - info!("rst2r: {}", tima.rsta2r.read().bits()); - info!("Running"); loop { diff --git a/examples/hrtim/simple.rs b/examples/hrtim/simple.rs index e493adac..d89c8774 100644 --- a/examples/hrtim/simple.rs +++ b/examples/hrtim/simple.rs @@ -17,7 +17,6 @@ use utils::logger::info; fn main() -> ! { use hal::gpio::gpioa::PA8; use hal::gpio::gpioa::PA9; - use hal::gpio::Alternate; use hal::gpio::AF13; use hal::hrtim::{control::HrControltExt, HrPwmExt}; use hal::prelude::*; @@ -46,8 +45,8 @@ fn main() -> ! { ); let gpioa = dp.GPIOA.split(&mut rcc); - let pin_a: PA8> = gpioa.pa8.into_alternate(); - let pin_b: PA9> = gpioa.pa9.into_alternate(); + let pin_a = gpioa.pa8; + let pin_b = gpioa.pa9; // . . . // . 33% . .