Skip to content

Commit

Permalink
HRTIM - Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
usbalbin committed Nov 9, 2024
1 parent b988a2e commit bb961cb
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 76 deletions.
10 changes: 5 additions & 5 deletions examples/hrtim/adc-trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand All @@ -72,8 +72,8 @@ fn main() -> ! {
let gpioa = dp.GPIOA.split(&mut rcc);
let pa0 = gpioa.pa0.into_analog();

let pin_a: PA8<Alternate<AF13>> = gpioa.pa8.into_alternate();
let pin_b: PA9<Alternate<AF13>> = 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...
Expand Down Expand Up @@ -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];
Expand Down
6 changes: 3 additions & 3 deletions examples/hrtim/capture-dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -56,7 +56,7 @@ fn main() -> ! {
let gpiob = dp.GPIOB.split(&mut rcc);

// PA8 (D7 on Nucleo G474RE)
let pin_a: PA8<Alternate<AF13>> = gpioa.pa8.into_alternate();
let pin_a = gpioa.pa8;

// PB5 (D4 on Nucleo G474RE)
let input = gpiob.pb5.into_pull_down_input();
Expand Down Expand Up @@ -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);
Expand Down
29 changes: 13 additions & 16 deletions examples/hrtim/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand All @@ -55,7 +55,7 @@ fn main() -> ! {
let gpiob = dp.GPIOB.split(&mut rcc);

// PA8 (D7 on Nucleo G474RE)
let pin_a: PA8<Alternate<AF13>> = gpioa.pa8.into_alternate();
let pin_a = gpioa.pa8;

// PB5 (D4 on Nucleo G474RE)
let input = gpiob.pb5.into_pull_down_input();
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}
}
}
9 changes: 3 additions & 6 deletions examples/hrtim/eev-comp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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),
Expand All @@ -61,7 +58,7 @@ fn main() -> ! {
let gpioa = dp.GPIOA.split(&mut rcc);

let input = gpioa.pa1.into_analog();
let pin_a: PA8<Alternate<AF13>> = 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();
Expand Down Expand Up @@ -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");

Expand Down
9 changes: 3 additions & 6 deletions examples/hrtim/eev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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),
Expand Down Expand Up @@ -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<Alternate<AF13>> = gpioa.pa8.into_alternate();
let pin_a = gpioa.pa8;

// . . * .
// . 33% . * . . .
Expand Down Expand Up @@ -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");

Expand Down
12 changes: 4 additions & 8 deletions examples/hrtim/flt-comp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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),
Expand Down Expand Up @@ -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<Alternate<AF13>> = gpioa.pa8.into_alternate();
let pin_a = gpioa.pa8;

// . . . *
// . 33% . . * . .
Expand Down Expand Up @@ -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");

Expand Down
12 changes: 4 additions & 8 deletions examples/hrtim/flt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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),
Expand All @@ -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<Alternate<AF13>> = gpioa.pa8.into_alternate();
let pin_a = gpioa.pa8;

// . . . *
// . 33% . . * . .
Expand Down Expand Up @@ -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");

Expand Down
10 changes: 3 additions & 7 deletions examples/hrtim/hrtim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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),
Expand All @@ -59,8 +55,8 @@ fn main() -> ! {
let prescaler = Pscl4;

let gpioa = dp.GPIOA.split(&mut rcc);
let pin_a: PA8<Alternate<AF13>> = gpioa.pa8.into_alternate();
let pin_b: PA9<Alternate<AF13>> = gpioa.pa9.into_alternate();
let pin_a = gpioa.pa8;
let pin_b = gpioa.pa9;

// . . . .
// . 30% . . .
Expand Down
17 changes: 3 additions & 14 deletions examples/hrtim/master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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),
Expand All @@ -58,8 +54,8 @@ fn main() -> ! {
let prescaler = Pscl4;

let gpioa = dp.GPIOA.split(&mut rcc);
let pin_a: PA8<Alternate<AF13>> = gpioa.pa8.into_alternate();
let pin_b: PA9<Alternate<AF13>> = gpioa.pa9.into_alternate();
let pin_a = gpioa.pa8;
let pin_b = gpioa.pa9;

// . . . .
// . 30% . . .
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions examples/hrtim/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -46,8 +45,8 @@ fn main() -> ! {
);

let gpioa = dp.GPIOA.split(&mut rcc);
let pin_a: PA8<Alternate<AF13>> = gpioa.pa8.into_alternate();
let pin_b: PA9<Alternate<AF13>> = gpioa.pa9.into_alternate();
let pin_a = gpioa.pa8;
let pin_b = gpioa.pa9;

// . . .
// . 33% . .
Expand Down

0 comments on commit bb961cb

Please sign in to comment.