Skip to content

Commit 3b99512

Browse files
committed
Try to support stm32f334
1 parent 7ae2b32 commit 3b99512

13 files changed

+428
-124
lines changed

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ edition = "2021"
55

66
[dependencies]
77

8+
stm32f3 = { git = "https://github.com/stm32-rs/stm32-rs-nightlies", optional = true }
9+
#stm32h7 = { git = "", optional = true }
10+
#stm32g4 = { git = "", optional = true }
11+
812
stm32f3xx-hal = { version = "0.10.0", optional = true }
913
stm32h7xx-hal = { version = "0.16.0", optional = true }
1014
#stm32g4xx-hal = { version = "0.0.1", optional = true }
@@ -20,7 +24,7 @@ hrtim_v1 = []
2024
hrtim_v1_1 = []
2125
hrtim_v2 = []
2226

23-
stm32f3 = []
27+
stm32f3 = ["stm32f3/stm32f3x4"]
2428
stm32h7 = []
2529
stm32g4 = []
2630

src/adc_trigger.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
use core::marker::PhantomData;
22

3+
#[cfg(feature = "stm32g4")]
34
pub trait Adc13Trigger {
45
const BITS: u32;
56
}
67

8+
#[cfg(feature = "stm32g4")]
79
pub trait Adc24Trigger {
810
const BITS: u32;
911
}
1012

13+
#[cfg(feature = "stm32g4")]
1114
pub trait Adc579Trigger {
1215
const BITS: u32;
1316
}
1417

18+
#[cfg(feature = "stm32g4")]
1519
pub trait Adc6810Trigger {
1620
const BITS: u32;
1721
}

src/capture.rs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
use crate::{hal, stm32};
1+
use crate::stm32;
22

33
use super::timer;
4+
5+
#[cfg(feature = "stm32g4")]
46
use crate::mcu::DmaMuxResources;
5-
use hal::dma::traits::TargetAddress;
6-
use hal::dma::PeripheralToMemory;
7-
use stm32::{HRTIM_TIMA, HRTIM_TIMB, HRTIM_TIMC, HRTIM_TIMD, HRTIM_TIME, HRTIM_TIMF};
7+
#[cfg(feature = "stm32g4")]
8+
use crate::hal::dma::PeripheralToMemory;
9+
810
use core::marker::PhantomData;
11+
#[cfg(feature = "hrtim_v2")]
12+
use stm32::HRTIM_TIMF;
13+
use stm32::{HRTIM_TIMA, HRTIM_TIMB, HRTIM_TIMC, HRTIM_TIMD, HRTIM_TIME};
914

1015
pub struct Ch1;
1116
pub struct Ch2;
@@ -27,6 +32,7 @@ pub struct HrCapt<TIM, PSCL, CH, DMA> {
2732
#[derive(Copy, Clone, Debug)]
2833
pub enum CountingDirection {
2934
Up = 0,
35+
#[cfg(feature = "hrtim_v2")]
3036
Down = 1,
3137
}
3238

@@ -129,6 +135,7 @@ pub trait HrCapture {
129135
// The capture counter always counts up and restarts at period
130136
match dir {
131137
CountingDirection::Up => i32::from(value),
138+
#[cfg(feature = "hrtim_v2")]
132139
CountingDirection::Down => i32::from(value) - i32::from(period),
133140
}
134141
}
@@ -140,10 +147,14 @@ pub trait HrCapture {
140147

141148
pub fn dma_value_to_dir_and_value(x: u32) -> (u16, CountingDirection) {
142149
let value = (x & 0xFFFF) as u16;
150+
#[cfg(feature = "hrtim_v2")]
143151
match x & (1 << 16) != 0 {
144152
true => (value, CountingDirection::Down),
145153
false => (value, CountingDirection::Up),
146154
}
155+
156+
#[cfg(any(feature = "hrtim_v1", feature = "hrtim_v1_1"))]
157+
(value, CountingDirection::Up)
147158
}
148159

149160
pub fn dma_value_to_signed(x: u32, period: u16) -> i32 {
@@ -152,6 +163,7 @@ pub fn dma_value_to_signed(x: u32, period: u16) -> i32 {
152163
// The capture counter always counts up and restarts at period
153164
match dir {
154165
CountingDirection::Up => i32::from(value),
166+
#[cfg(feature = "hrtim_v2")]
155167
CountingDirection::Down => i32::from(value) - i32::from(period),
156168
}
157169
}
@@ -219,10 +231,14 @@ macro_rules! impl_capture {
219231
let tim = unsafe { &*$TIMX::ptr() };
220232
let data = tim.$cptXr().read();
221233

234+
#[cfg(feature = "hrtim_v2")]
222235
let dir = match data.dir().bit() {
223236
true => CountingDirection::Down,
224237
false => CountingDirection::Up,
225238
};
239+
#[cfg(any(feature = "hrtim_v1", feature = "hrtim_v1_1"))]
240+
let dir = CountingDirection::Up;
241+
226242
let value = data.cpt().bits();
227243

228244
(value, dir)
@@ -243,7 +259,8 @@ macro_rules! impl_capture {
243259
}
244260
}
245261

246-
unsafe impl<PSCL> TargetAddress<PeripheralToMemory> for HrCapt<$TIMX, PSCL, $CH, Dma> {
262+
#[cfg(feature = "stm32g4")]
263+
unsafe impl<PSCL> crate::hal::dma::traits::TargetAddress<PeripheralToMemory> for HrCapt<$TIMX, PSCL, $CH, Dma> {
247264
#[inline(always)]
248265
fn address(&self) -> u32 {
249266
let tim = unsafe { &*$TIMX::ptr() };
@@ -262,6 +279,10 @@ impl_capture! {
262279
HRTIM_TIMB,
263280
HRTIM_TIMC,
264281
HRTIM_TIMD,
265-
HRTIM_TIME,
282+
HRTIM_TIME
283+
}
284+
285+
#[cfg(feature = "hrtim_v2")]
286+
impl_capture! {
266287
HRTIM_TIMF
267288
}

src/compare_register.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use core::marker::PhantomData;
22

33
use crate::stm32::{
4-
HRTIM_MASTER, HRTIM_TIMA, HRTIM_TIMB, HRTIM_TIMC, HRTIM_TIMD, HRTIM_TIME, HRTIM_TIMF,
4+
HRTIM_MASTER, HRTIM_TIMA, HRTIM_TIMB, HRTIM_TIMC, HRTIM_TIMD, HRTIM_TIME,
55
};
6+
#[cfg(feature = "hrtim_v2")]
7+
use crate::stm32::HRTIM_TIMF;
68

79
pub trait HrCompareRegister {
810
fn get_duty(&self) -> u16;
@@ -14,11 +16,16 @@ pub struct HrCr2<TIM, PSCL>(PhantomData<(TIM, PSCL)>);
1416
pub struct HrCr3<TIM, PSCL>(PhantomData<(TIM, PSCL)>);
1517
pub struct HrCr4<TIM, PSCL>(PhantomData<(TIM, PSCL)>);
1618

19+
#[cfg(feature = "stm32g4")]
1720
use super::adc_trigger::Adc13Trigger as Adc13;
21+
#[cfg(feature = "stm32g4")]
1822
use super::adc_trigger::Adc24Trigger as Adc24;
23+
#[cfg(feature = "stm32g4")]
1924
use super::adc_trigger::Adc579Trigger as Adc579;
25+
#[cfg(feature = "stm32g4")]
2026
use super::adc_trigger::Adc6810Trigger as Adc6810;
2127

28+
#[cfg(feature = "stm32g4")]
2229
macro_rules! hrtim_cr_helper {
2330
(HRTIM_MASTER: $cr_type:ident:
2431
$cmpXYr:ident,
@@ -71,6 +78,7 @@ macro_rules! hrtim_cr_helper {
7178
};
7279
}
7380

81+
#[cfg(feature = "stm32g4")]
7482
macro_rules! hrtim_cr {
7583
($($TIMX:ident: [
7684
[$(($cr1_trigger:ident: $cr1_trigger_bits:expr)),*], [$(($cr1_event_dst:ident, $cr1_tim_event_index:expr)),*],
@@ -86,6 +94,7 @@ macro_rules! hrtim_cr {
8694
}
8795

8896
// See RM0440 Table 218. 'Events mapping across timer A to F'
97+
#[cfg(feature = "stm32g4")]
8998
hrtim_cr! {
9099
HRTIM_MASTER: [
91100
[(Adc13: 1 << 0), (Adc24: 1 << 0), (Adc579: 0), (Adc6810: 0) ], [],
@@ -179,8 +188,11 @@ hrtim_timer_rst! {
179188
HRTIM_TIMD: HrCr4: 3,
180189

181190
HRTIM_TIME: HrCr2: 2,
182-
HRTIM_TIME: HrCr4: 3,
191+
HRTIM_TIME: HrCr4: 3
192+
}
183193

194+
#[cfg(feature = "hrtim_v2")]
195+
hrtim_timer_rst! {
184196
HRTIM_TIMF: HrCr2: 2,
185197
HRTIM_TIMF: HrCr4: 3
186-
}
198+
}

0 commit comments

Comments
 (0)