Skip to content

Commit 7735ad8

Browse files
committed
Fix warnings for hrtim
1 parent f8f429b commit 7735ad8

File tree

11 files changed

+164
-112
lines changed

11 files changed

+164
-112
lines changed

examples/hrtim/adc-trigger.rs

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,41 @@
22
#![no_main]
33

44
use cortex_m_rt::entry;
5-
use hal::adc::{self, config::ExternalTrigger12};
6-
7-
use crate::hal::{
8-
adc::{
9-
config::{Continuous, Dma as AdcDma, SampleTime, Sequence},
10-
AdcClaim, ClockSource, Temperature, Vref,
11-
},
12-
delay::SYSTDelayExt,
13-
dma::{self, config::DmaConfig, stream::DMAExt, TransferExt},
14-
gpio::{gpioa::PA8, gpioa::PA9, Alternate, GpioExt, AF13},
15-
hrtim::control::HrControltExt,
16-
hrtim::output::HrOutput,
17-
hrtim::HrPwmAdvExt,
18-
hrtim::{control::Adc13Trigger, Pscl4},
19-
pwr::PwrExt,
20-
rcc::{self, RccExt},
21-
stm32::Peripherals,
22-
};
23-
use stm32g4xx_hal as hal;
24-
25-
use defmt::info;
265

276
use defmt_rtt as _; // global logger
287
use panic_probe as _;
298

9+
#[cfg(not(any(feature = "stm32g474", feature = "stm32g484")))]
3010
#[entry]
3111
fn main() -> ! {
12+
#[allow(clippy::empty_loop)]
13+
loop {}
14+
}
15+
16+
#[cfg(any(feature = "stm32g474", feature = "stm32g484"))]
17+
#[entry]
18+
fn main() -> ! {
19+
use hal::adc::{self, config::ExternalTrigger12};
20+
use stm32g4xx_hal as hal;
21+
22+
use defmt::info;
23+
use hal::{
24+
adc::{
25+
config::{Continuous, Dma as AdcDma, SampleTime, Sequence},
26+
AdcClaim, ClockSource, Temperature, Vref,
27+
},
28+
delay::SYSTDelayExt,
29+
dma::{self, config::DmaConfig, stream::DMAExt, TransferExt},
30+
gpio::{gpioa::PA8, gpioa::PA9, Alternate, GpioExt, AF13},
31+
hrtim::control::HrControltExt,
32+
hrtim::output::HrOutput,
33+
hrtim::HrPwmAdvExt,
34+
hrtim::{control::Adc13Trigger, Pscl4},
35+
pwr::PwrExt,
36+
rcc::{self, RccExt},
37+
stm32::Peripherals,
38+
};
39+
3240
info!("start");
3341

3442
let dp = Peripherals::take().unwrap();

examples/hrtim/eev-comp.rs

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,41 @@
33
#![no_std]
44

55
use cortex_m_rt::entry;
6-
use hal::comparator;
7-
use hal::comparator::{ComparatorExt, ComparatorSplit, Hysteresis};
8-
use hal::dac::{self, DacExt, DacOut};
9-
use hal::gpio::gpioa::PA8;
10-
use hal::gpio::Alternate;
11-
use hal::gpio::SignalEdge;
12-
use hal::gpio::AF13;
13-
use hal::hrtim::compare_register::HrCompareRegister;
14-
use hal::hrtim::external_event::{self, ToExternalEventSource};
15-
use hal::hrtim::timer::HrTimer;
16-
use hal::hrtim::timer_eev_cfg::{EevCfg, EevCfgs};
17-
use hal::hrtim::HrPwmAdvExt;
18-
use hal::hrtim::Pscl4;
19-
use hal::hrtim::{control::HrControltExt, output::HrOutput};
20-
use hal::prelude::*;
21-
use hal::pwm;
22-
use hal::pwr::PwrExt;
23-
use hal::rcc;
24-
use hal::stm32;
25-
use stm32g4xx_hal as hal;
266

277
use defmt_rtt as _; // global logger
288
use panic_probe as _;
299

10+
#[cfg(not(any(feature = "stm32g474", feature = "stm32g484")))]
3011
#[entry]
3112
fn main() -> ! {
13+
#[allow(clippy::empty_loop)]
14+
loop {}
15+
}
16+
17+
#[cfg(any(feature = "stm32g474", feature = "stm32g484"))]
18+
#[entry]
19+
fn main() -> ! {
20+
use hal::comparator;
21+
use hal::comparator::{ComparatorExt, ComparatorSplit, Hysteresis};
22+
use hal::dac::{self, DacExt, DacOut};
23+
use hal::gpio::gpioa::PA8;
24+
use hal::gpio::Alternate;
25+
use hal::gpio::SignalEdge;
26+
use hal::gpio::AF13;
27+
use hal::hrtim::compare_register::HrCompareRegister;
28+
use hal::hrtim::external_event::{self, ToExternalEventSource};
29+
use hal::hrtim::timer::HrTimer;
30+
use hal::hrtim::timer_eev_cfg::{EevCfg, EevCfgs};
31+
use hal::hrtim::HrPwmAdvExt;
32+
use hal::hrtim::Pscl4;
33+
use hal::hrtim::{control::HrControltExt, output::HrOutput};
34+
use hal::prelude::*;
35+
use hal::pwm;
36+
use hal::pwr::PwrExt;
37+
use hal::rcc;
38+
use hal::stm32;
39+
use stm32g4xx_hal as hal;
40+
3241
let dp = stm32::Peripherals::take().expect("cannot take peripherals");
3342
let cp = stm32::CorePeripherals::take().expect("cannot take core");
3443
// Set system frequency to 16MHz * 75/4/2 = 150MHz

examples/hrtim/eev.rs

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,40 @@
33
#![no_std]
44

55
use cortex_m_rt::entry;
6-
use hal::gpio::gpioa::PA8;
7-
use hal::gpio::Alternate;
8-
use hal::gpio::AF13;
9-
use hal::hrtim::compare_register::HrCompareRegister;
10-
use hal::hrtim::external_event;
11-
use hal::hrtim::external_event::ToExternalEventSource;
12-
use hal::hrtim::timer::HrTimer;
13-
use hal::hrtim::timer_eev_cfg::EevCfgs;
14-
use hal::hrtim::HrPwmAdvExt;
15-
use hal::hrtim::Pscl4;
16-
use hal::hrtim::{control::HrControltExt, output::HrOutput};
17-
use hal::prelude::*;
18-
use hal::pwm;
19-
use hal::pwr::PwrExt;
20-
use hal::rcc;
21-
use hal::stm32;
22-
use stm32g4xx_hal as hal;
6+
237
//mod utils;
248

259
use defmt_rtt as _; // global logger
2610
use panic_probe as _;
2711

12+
#[cfg(not(any(feature = "stm32g474", feature = "stm32g484")))]
13+
#[entry]
14+
fn main() -> ! {
15+
#[allow(clippy::empty_loop)]
16+
loop {}
17+
}
18+
19+
#[cfg(any(feature = "stm32g474", feature = "stm32g484"))]
2820
#[entry]
2921
fn main() -> ! {
22+
use hal::gpio::gpioa::PA8;
23+
use hal::gpio::Alternate;
24+
use hal::gpio::AF13;
25+
use hal::hrtim::compare_register::HrCompareRegister;
26+
use hal::hrtim::external_event;
27+
use hal::hrtim::external_event::ToExternalEventSource;
28+
use hal::hrtim::timer::HrTimer;
29+
use hal::hrtim::timer_eev_cfg::EevCfgs;
30+
use hal::hrtim::HrPwmAdvExt;
31+
use hal::hrtim::Pscl4;
32+
use hal::hrtim::{control::HrControltExt, output::HrOutput};
33+
use hal::prelude::*;
34+
use hal::pwm;
35+
use hal::pwr::PwrExt;
36+
use hal::rcc;
37+
use hal::stm32;
38+
use stm32g4xx_hal as hal;
39+
3040
let dp = stm32::Peripherals::take().expect("cannot take peripherals");
3141
// Set system frequency to 16MHz * 75/4/2 = 150MHz
3242
// This would lead to HrTim running at 150MHz * 32 = 4.8GHz...
@@ -97,5 +107,7 @@ fn main() -> ! {
97107

98108
defmt::info!("Started");
99109

100-
loop {}
110+
loop {
111+
cortex_m::asm::nop()
112+
}
101113
}

examples/hrtim/flt-comp.rs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,39 @@
33
#![no_std]
44

55
use cortex_m_rt::entry;
6-
use hal::comparator::{ComparatorExt, ComparatorSplit, Config, Hysteresis};
7-
use hal::dac::{Dac3IntSig1, DacExt, DacOut};
8-
use hal::gpio::gpioa::PA8;
9-
use hal::gpio::Alternate;
10-
use hal::gpio::AF13;
11-
use hal::hrtim::compare_register::HrCompareRegister;
12-
use hal::hrtim::fault::FaultAction;
13-
use hal::hrtim::timer::HrTimer;
14-
use hal::hrtim::HrPwmAdvExt;
15-
use hal::hrtim::Pscl4;
16-
use hal::hrtim::{control::HrControltExt, output::HrOutput};
17-
use hal::prelude::*;
18-
use hal::pwm::FaultMonitor;
19-
use hal::rcc;
20-
use hal::stm32;
21-
use stm32g4xx_hal as hal;
22-
use stm32g4xx_hal::pwr::PwrExt;
236
//mod utils;
247

258
use defmt_rtt as _; // global logger
269
use panic_probe as _;
2710

11+
#[cfg(not(any(feature = "stm32g474", feature = "stm32g484")))]
2812
#[entry]
2913
fn main() -> ! {
14+
#[allow(clippy::empty_loop)]
15+
loop {}
16+
}
17+
18+
#[cfg(any(feature = "stm32g474", feature = "stm32g484"))]
19+
#[entry]
20+
fn main() -> ! {
21+
use hal::comparator::{ComparatorExt, ComparatorSplit, Config, Hysteresis};
22+
use hal::dac::{Dac3IntSig1, DacExt, DacOut};
23+
use hal::gpio::gpioa::PA8;
24+
use hal::gpio::Alternate;
25+
use hal::gpio::AF13;
26+
use hal::hrtim::compare_register::HrCompareRegister;
27+
use hal::hrtim::fault::FaultAction;
28+
use hal::hrtim::timer::HrTimer;
29+
use hal::hrtim::HrPwmAdvExt;
30+
use hal::hrtim::Pscl4;
31+
use hal::hrtim::{control::HrControltExt, output::HrOutput};
32+
use hal::prelude::*;
33+
use hal::pwm::FaultMonitor;
34+
use hal::rcc;
35+
use hal::stm32;
36+
use stm32g4xx_hal as hal;
3037
use stm32g4xx_hal::adc::AdcClaim;
38+
use stm32g4xx_hal::pwr::PwrExt;
3139

3240
let dp = stm32::Peripherals::take().expect("cannot take peripherals");
3341
let cp = stm32::CorePeripherals::take().expect("cannot take core");

examples/hrtim/flt.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,38 @@
33
#![no_std]
44

55
use cortex_m_rt::entry;
6-
use hal::gpio::gpioa::PA8;
7-
use hal::gpio::Alternate;
8-
use hal::gpio::AF13;
9-
use hal::hrtim::compare_register::HrCompareRegister;
10-
use hal::hrtim::fault::FaultAction;
11-
use hal::hrtim::timer::HrTimer;
12-
use hal::hrtim::HrPwmAdvExt;
13-
use hal::hrtim::Pscl4;
14-
use hal::hrtim::{control::HrControltExt, output::HrOutput};
15-
use hal::prelude::*;
16-
use hal::pwm::FaultMonitor;
17-
use hal::pwr::PwrExt;
18-
use hal::rcc;
19-
use hal::stm32;
20-
use hal::time::ExtU32;
21-
use stm32g4xx_hal as hal;
226
//mod utils;
237

248
use defmt_rtt as _; // global logger
259
use panic_probe as _;
2610

11+
#[cfg(not(any(feature = "stm32g474", feature = "stm32g484")))]
2712
#[entry]
2813
fn main() -> ! {
14+
#[allow(clippy::empty_loop)]
15+
loop {}
16+
}
17+
18+
#[cfg(any(feature = "stm32g474", feature = "stm32g484"))]
19+
#[entry]
20+
fn main() -> ! {
21+
use hal::gpio::gpioa::PA8;
22+
use hal::gpio::Alternate;
23+
use hal::gpio::AF13;
24+
use hal::hrtim::compare_register::HrCompareRegister;
25+
use hal::hrtim::fault::FaultAction;
26+
use hal::hrtim::timer::HrTimer;
27+
use hal::hrtim::HrPwmAdvExt;
28+
use hal::hrtim::Pscl4;
29+
use hal::hrtim::{control::HrControltExt, output::HrOutput};
30+
use hal::prelude::*;
31+
use hal::pwm::FaultMonitor;
32+
use hal::pwr::PwrExt;
33+
use hal::rcc;
34+
use hal::stm32;
35+
use hal::time::ExtU32;
36+
use stm32g4xx_hal as hal;
37+
2938
let dp = stm32::Peripherals::take().expect("cannot take peripherals");
3039
let cp = stm32::CorePeripherals::take().expect("cannot take core");
3140
// Set system frequency to 16MHz * 75/4/2 = 150MHz

src/hrtim/external_event.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ pub struct EevInput<const N: u8> {
7070
_x: PhantomData<()>,
7171
}
7272

73+
/// # Safety
74+
/// Only implement for types that can be used as sources to eev number `EEV_N` with src bits `SRC_BITS`
7375
pub unsafe trait EevSrcBits<const EEV_N: u8>: Sized {
7476
const SRC_BITS: u8;
7577
fn cfg(self) {}
@@ -109,16 +111,16 @@ macro_rules! impl_eev_input {
109111
};
110112
}
111113

112-
impl_eev_input!(1: COMP=[COMP2], PINS=[(PC12, AF3)]);
113-
impl_eev_input!(2: COMP=[COMP4], PINS=[(PC11, AF3)]);
114-
impl_eev_input!(3: COMP=[COMP6], PINS=[(PB7, AF13)]);
115-
impl_eev_input!(4: COMP=[COMP1, (COMP5, 0b10)], PINS=[(PB6, AF13)]);
116-
impl_eev_input!(5: COMP=[COMP3, (COMP7, 0b10)], PINS=[(PB9, AF13)]);
117-
impl_eev_input!(6: COMP=[COMP2, (COMP1, 0b10)], PINS=[(PB5, AF13)]);
118-
impl_eev_input!(7: COMP=[COMP4], PINS=[(PB4, AF13)]);
119-
impl_eev_input!(8: COMP=[COMP6, (COMP3, 0b10)], PINS=[(PB8, AF13)]);
120-
impl_eev_input!(9: COMP=[COMP5, (COMP4, 0b11)], PINS=[(PB3, AF13)]);
121-
impl_eev_input!(10: COMP=[COMP7], PINS=[(PC5, AF13), (PC6, AF3)]);
114+
impl_eev_input!(1: COMP = [COMP2], PINS = [(PC12, AF3)]);
115+
impl_eev_input!(2: COMP = [COMP4], PINS = [(PC11, AF3)]);
116+
impl_eev_input!(3: COMP = [COMP6], PINS = [(PB7, AF13)]);
117+
impl_eev_input!(4: COMP = [COMP1, (COMP5, 0b10)], PINS = [(PB6, AF13)]);
118+
impl_eev_input!(5: COMP = [COMP3, (COMP7, 0b10)], PINS = [(PB9, AF13)]);
119+
impl_eev_input!(6: COMP = [COMP2, (COMP1, 0b10)], PINS = [(PB5, AF13)]);
120+
impl_eev_input!(7: COMP = [COMP4], PINS = [(PB4, AF13)]);
121+
impl_eev_input!(8: COMP = [COMP6, (COMP3, 0b10)], PINS = [(PB8, AF13)]);
122+
impl_eev_input!(9: COMP = [COMP5, (COMP4, 0b11)], PINS = [(PB3, AF13)]);
123+
impl_eev_input!(10: COMP = [COMP7], PINS = [(PC5, AF13), (PC6, AF3)]);
122124

123125
pub enum EdgeOrPolarity {
124126
Edge(Edge),

src/hrtim/fault.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ pub enum FaultAction {
2323
Floating = 0b11,
2424
}
2525

26+
/// # Safety
27+
/// Only implement for actual fault sources with correct `ENABLE_BITS`
2628
pub unsafe trait FaultSource: Copy {
2729
const ENABLE_BITS: u8;
2830
}

src/hrtim/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,8 @@ hrtim_pin_hal! {
863863
HRTIM_TIMF: (CH2, perfr, cmp3fr, cmp3x, cmp3, tf2oen, tf2odis),
864864
}
865865

866+
/// # Safety
867+
/// Only implement for valid prescalers with correct values
866868
pub unsafe trait HrtimPrescaler: Default {
867869
const BITS: u8;
868870
const VALUE: u8;

src/hrtim/output.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::hrtim::external_event::ExternalEventSource;
2-
use core::marker::PhantomData;
3-
use stm32g4::stm32g474::{
2+
use crate::stm32::{
43
HRTIM_MASTER, HRTIM_TIMA, HRTIM_TIMB, HRTIM_TIMC, HRTIM_TIMD, HRTIM_TIME, HRTIM_TIMF,
54
};
5+
use core::marker::PhantomData;
66

77
use super::event::{EevFastOrNormal, EventSource, NeighborTimerEventSource};
88
use crate::{

src/hrtim/timer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use core::marker::PhantomData;
2-
use stm32g4::stm32g474::{
1+
use crate::stm32::{
32
HRTIM_MASTER, HRTIM_TIMA, HRTIM_TIMB, HRTIM_TIMC, HRTIM_TIMD, HRTIM_TIME, HRTIM_TIMF,
43
};
4+
use core::marker::PhantomData;
55

66
use super::{
77
control::HrPwmControl,

0 commit comments

Comments
 (0)