Skip to content

Commit 59bb877

Browse files
committed
Cleanup after rabase
1 parent 76222c3 commit 59bb877

File tree

3 files changed

+28
-73
lines changed

3 files changed

+28
-73
lines changed

examples/utils/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
//! Utilities for examples
22
33
pub mod logger;
4-
pub mod test;

examples/utils/test.rs

Lines changed: 0 additions & 49 deletions
This file was deleted.

tests/nucleo-g474_w_jumpers-hrtim.rs

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#[path = "../examples/utils/mod.rs"]
77
mod utils;
88

9+
mod common;
10+
911
use core::ops::Sub;
1012

1113
use fugit::{ExtU32, HertzU32, MicrosDurationU32};
@@ -34,6 +36,7 @@ use stm32g4xx_hal::stasis::{Freeze, Frozen};
3436

3537
pub const F_SYS: HertzU32 = HertzU32::MHz(120);
3638
pub const CYCLES_PER_US: u32 = F_SYS.raw() / 1_000_000;
39+
type Timer = crate::common::Timer<CYCLES_PER_US>;
3740

3841
pub fn enable_timer(cp: &mut stm32::CorePeripherals) {
3942
cp.DCB.enable_trace();
@@ -54,9 +57,7 @@ mod tests {
5457
use stm32g4xx_hal::{dac::DacOut, stm32::GPIOA};
5558

5659
use crate::{
57-
abs_diff, now,
58-
utils::test::{await_hi, await_lo},
59-
F_SYS,
60+
abs_diff, common::{await_hi, await_lo}, now, F_SYS
6061
};
6162

6263
/// | \
@@ -78,7 +79,7 @@ mod tests {
7879
let cr2_ticks_per_dac_trigger = 1024;
7980

8081
let crate::Peripherals {
81-
mut timer,
82+
mut hrtimer,
8283
mut hr_control,
8384
eev_input4,
8485
comp,
@@ -88,22 +89,24 @@ mod tests {
8889
pa2,
8990
rcc,
9091
delay,
92+
timer
9193
} = super::setup(
9294
prescaler,
9395
period,
9496
dac_step_per_trigger,
9597
cr2_ticks_per_dac_trigger,
9698
);
99+
let pin_num = 8;
97100

98-
timer.cr1.set_duty(period / 10); // Set blanking window to give the ref_dac time to reset
101+
hrtimer.cr1.set_duty(period / 10); // Set blanking window to give the ref_dac time to reset
99102
//out.enable_rst_event(&cr1); // Set low on compare match with cr1
100-
timer.out.enable_rst_event(&eev_input4); // Set low on compare match with cr1
101-
timer.out.enable_set_event(&timer.timer); // Set high at new period
103+
hrtimer.out.enable_rst_event(&eev_input4); // Set low on compare match with cr1
104+
hrtimer.out.enable_set_event(&hrtimer.timer); // Set high at new period
102105

103-
timer.out.enable();
104-
timer.timer.start(&mut hr_control.control);
106+
hrtimer.out.enable();
107+
hrtimer.timer.start(&mut hr_control.control);
105108

106-
defmt::println!("state: {}", timer.out.get_state());
109+
defmt::println!("state: {}", hrtimer.out.get_state());
107110

108111
//out.enable_rst_event(&eev_input4);
109112

@@ -120,7 +123,7 @@ mod tests {
120123
let out = comp.output();
121124
let ref_dac = ref_dac.get_value();
122125
let value_dac = value_dac.get_value();
123-
let cnt = timer.timer.get_counter_value();
126+
let cnt = hrtimer.timer.get_counter_value();
124127
defmt::println!(
125128
"out: {}, ref: {}, val: {}, cnt: {}",
126129
out,
@@ -151,12 +154,12 @@ mod tests {
151154
let out = comp.output();
152155
defmt::println!("out: {}", out);
153156
}
154-
let duration_until_lo = await_lo(gpioa, 8, timeout, now).unwrap();
155-
let first_lo_duration = await_hi(gpioa, 8, timeout, now);
157+
let duration_until_lo = await_lo(&timer, pin_num, timeout).unwrap();
158+
let first_lo_duration = await_hi(&timer, pin_num, timeout);
156159

157160
let (period, duty) = match first_lo_duration {
158161
Ok(lo_duration) => {
159-
let duty = await_lo(gpioa, 8, timeout, now).unwrap();
162+
let duty = await_lo(&timer, pin_num, timeout).unwrap();
160163
let period = lo_duration + duty;
161164
(period, duty)
162165
}
@@ -194,7 +197,7 @@ fn abs_diff<T: Ord + Sub + Copy>(a: T, b: T) -> T::Output {
194197
const VREF_ADC_BITS: u16 = 1504;
195198

196199
struct Peripherals<PSCL> {
197-
timer:
200+
hrtimer:
198201
HrParts<HRTIM_TIMA, PSCL, HrOut1<HRTIM_TIMA, PSCL, DacResetOnCounterReset, DacStepOnCmp2>, DacResetOnCounterReset, DacStepOnCmp2>,
199202
hr_control: HrPwmControl,
200203
eev_input4: ExternalEventSource<4, false>,
@@ -205,6 +208,7 @@ struct Peripherals<PSCL> {
205208
pa2: gpio::gpioa::PA2<gpio::Analog>,
206209
rcc: rcc::Rcc,
207210
delay: delay::SystDelay,
211+
timer: Timer,
208212
}
209213

210214
fn setup<PSCL: HrtimPrescaler>(
@@ -217,8 +221,9 @@ fn setup<PSCL: HrtimPrescaler>(
217221
//DAC1_OUT1 PA4 -> A2
218222

219223
// TODO: Is it ok to steal these?
220-
let mut cp = unsafe { stm32::CorePeripherals::steal() };
221-
let dp = unsafe { stm32::Peripherals::steal() };
224+
let mut cp = stm32::CorePeripherals::take().unwrap();
225+
let dp = stm32::Peripherals::take().unwrap();
226+
let timer = Timer::enable_timer(&mut cp);
222227
// Set system frequency to 16MHz * 15/1/2 = 120MHz
223228
// This would lead to HrTim running at 120MHz * 32 = 3.84...
224229
defmt::info!("rcc");
@@ -281,7 +286,7 @@ fn setup<PSCL: HrtimPrescaler>(
281286
let mut hr_control = hr_control.constrain();
282287
let eev_cfgs =
283288
EevCfgs::default().eev4(EevCfg::default().filter(EventFilter::BlankingResetToCmp1));
284-
let mut timer: HrParts<_, PSCL, HrOut1<_, PSCL, DacResetOnCounterReset, DacStepOnCmp2>, DacResetOnCounterReset, DacStepOnCmp2> = dp
289+
let mut hrtimer: HrParts<_, PSCL, HrOut1<_, PSCL, DacResetOnCounterReset, DacStepOnCmp2>, DacResetOnCounterReset, DacStepOnCmp2> = dp
285290
.HRTIM_TIMA
286291
.pwm_advanced(pa8)
287292
.prescaler(prescaler)
@@ -290,14 +295,14 @@ fn setup<PSCL: HrtimPrescaler>(
290295
.eev_cfg(eev_cfgs)
291296
.finalize(&mut hr_control);
292297

293-
timer.cr2.set_duty(cr2_ticks_per_dac_trigger);
298+
hrtimer.cr2.set_duty(cr2_ticks_per_dac_trigger);
294299
let ref_dac = ref_dac.enable_sawtooth_generator(
295300
SawtoothConfig::with_slope(
296301
stm32g4xx_hal::dac::CountingDirection::Decrement,
297302
dac_step_per_trigger,
298303
)
299-
.inc_trigger(&timer.cr2)
300-
.reset_trigger(&timer.timer),
304+
.inc_trigger(&hrtimer.cr2)
305+
.reset_trigger(&hrtimer.timer),
301306
&mut rcc,
302307
);
303308

@@ -306,9 +311,8 @@ fn setup<PSCL: HrtimPrescaler>(
306311
.comparator(pa1, comp_ref, comparator::Config::default(), &rcc.clocks)
307312
.enable();
308313

309-
let timer: HrParts<_, _, HrOut1<_, _, DacResetOnCounterReset, DacStepOnCmp2>, _, _> = timer;
310314
Peripherals {
311-
timer,
315+
hrtimer,
312316
hr_control,
313317
eev_input4,
314318
comp,
@@ -318,5 +322,6 @@ fn setup<PSCL: HrtimPrescaler>(
318322
pa2,
319323
rcc,
320324
delay,
325+
timer,
321326
}
322327
}

0 commit comments

Comments
 (0)