Skip to content

Commit 7bc500e

Browse files
committed
More cleanup of G4 and H7 examples
1 parent 3b8bbb6 commit 7bc500e

File tree

4 files changed

+11
-20
lines changed

4 files changed

+11
-20
lines changed

examples/stm32g4/flt-comp.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/// Example showcasing the use of the HRTIM peripheral together with a comparator to implement a current fault.
55
/// Once the comparator input exceeds the reference set by the DAC, the output is forced low and put into a fault state.
66
use cortex_m_rt::entry;
7+
use fugit::ExtU32 as _;
78
use panic_probe as _;
89
use stm32_hrtim::{
910
compare_register::HrCompareRegister,
@@ -18,7 +19,7 @@ use stm32g4xx_hal::{
1819
adc::AdcClaim,
1920
comparator::{self, ComparatorExt, ComparatorSplit},
2021
dac::{Dac3IntSig1, DacExt, DacOut},
21-
delay::SYSTDelayExt,
22+
delay::{DelayExt as _, SYSTDelayExt},
2223
gpio::GpioExt,
2324
pwr::PwrExt,
2425
rcc::{self, RccExt},
@@ -88,8 +89,8 @@ fn main() -> ! {
8889
.polarity(hal::pwm::Polarity::ActiveHigh)
8990
.finalize(&mut hr_control);
9091

91-
// ...with a prescaler of 4 this gives us a HrTimer with a tick rate of 1.2GHz
92-
// With max the max period set, this would be 1.2GHz/2^16 ~= 18kHz...
92+
// ...with a prescaler of 4 this gives us a HrTimer with a tick rate of 960MHz
93+
// With max the max period set, this would be 960MHz/2^16 ~= 15kHz...
9394
let prescaler = Pscl4;
9495

9596
let pin_a = gpioa.pa8;
@@ -126,15 +127,15 @@ fn main() -> ! {
126127
out1.enable_rst_event(&cr1); // Set low on compare match with cr1
127128
out1.enable_set_event(&timer); // Set high at new period
128129
cr1.set_duty(timer.get_period() / 3);
129-
//unsafe {((HRTIM_COMMON::ptr() as *mut u8).offset(0x14) as *mut u32).write_volatile(1); }
130+
130131
out1.enable();
131132
timer.start(&mut hr_control.control);
132133

133134
defmt::info!("Started");
134135

135136
loop {
136137
for _ in 0..5 {
137-
//delay.delay(500_u32.millis());
138+
delay.delay(500_u32.millis());
138139
defmt::info!(
139140
"State: {:?}, comp: {}, is_fault_active: {}, pc1: {}",
140141
out1.get_state(),

examples/stm32g4/flt.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,15 @@ fn main() -> ! {
8484
.pwm_advanced(pin_a)
8585
.prescaler(prescaler)
8686
.period(0xFFFF)
87-
//.with_fault_source(fault_source1)
88-
//.with_fault_source(fault_source2)
89-
.with_fault_source(fault_source3) // Set fault source
90-
//.with_fault_source(fault_source4)
91-
//.with_fault_source(fault_source5)
92-
//.with_fault_source(fault_source6)
87+
.with_fault_source(fault_source3)
9388
.fault_action1(FaultAction::ForceInactive)
9489
.fault_action2(FaultAction::ForceInactive)
95-
// alternated every period with one being
96-
// inactive and the other getting to output its wave form
97-
// as normal
9890
.finalize(&mut hr_control);
9991

10092
out.enable_rst_event(&cr1); // Set low on compare match with cr1
10193
out.enable_set_event(&timer); // Set high at new period
10294
cr1.set_duty(timer.get_period() / 3);
103-
//unsafe {((HRTIM_COMMON::ptr() as *mut u8).offset(0x14) as *mut u32).write_volatile(1); }
95+
10496
out.enable();
10597
timer.start(&mut hr_control.control);
10698

examples/stm32g4/master.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ fn main() -> ! {
107107
defmt::info!("Running");
108108

109109
loop {
110-
// Step frequency from 18kHz to about 180kHz(half of that when only looking at one pin)
111-
for i in 1..10 {
110+
// Step frequency from 15kHz to about 146kHz(half of that when only looking at one pin)
111+
for i in 1..=10 {
112112
let new_period = u16::MAX / i;
113113

114114
mcr1.set_duty(new_period / 3);

examples/stm32h7/hrtim.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ fn main() -> ! {
3636
// since HRTIMSEL is set to take the HRTIM's clock directly from the core clock. The
3737
// stm32h7 devices' HRTIM does not have a DLL, also leading to an effective HRTIM
3838
// frequency of 240MHz...
39-
let ccdr = rcc
40-
.sys_ck(240.MHz())
41-
.freeze(pwrcfg, &dp.SYSCFG);
39+
let ccdr = rcc.sys_ck(240.MHz()).freeze(pwrcfg, &dp.SYSCFG);
4240

4341
// Acquire the GPIO peripherals. This also enables the clock for
4442
// the GPIOs in the RCC register.

0 commit comments

Comments
 (0)