Skip to content

Commit 9a26cc0

Browse files
authored
Merge pull request #553 from stm32-rs/timer-refac
timer macro/private trait refactoring
2 parents de6d81a + 35ca5a1 commit 9a26cc0

File tree

6 files changed

+553
-297
lines changed

6 files changed

+553
-297
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- `timer.rs` refactoring
13+
1014
## [v0.11.0] - 2025-09-09
1115

1216
### Breaking changes

src/rcc.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use core::ops::{Deref, DerefMut};
44

55
use crate::pac::{
66
rcc::{self, RegisterBlock as RccRB},
7-
BKP, PWR, RCC,
7+
BKP, DBGMCU, PWR, RCC,
88
};
99

1010
use crate::flash::ACR;
@@ -207,6 +207,7 @@ impl Rcc {
207207
/// let clocks = rcc.freeze(rcc::Config::default(), &mut flash.acr);
208208
/// ```
209209
#[inline(always)]
210+
#[allow(unused)]
210211
pub fn freeze(self, cfg: impl Into<RawConfig>, acr: &mut ACR) -> Self {
211212
let cfg = cfg.into();
212213
let clocks = cfg.get_clocks();
@@ -544,6 +545,11 @@ pub trait Reset: RccBus {
544545
}
545546
}
546547

548+
/// Stop peripheral when Core is halted
549+
pub trait StopInDebug {
550+
fn stop_in_debug(&mut self, dbg: &mut DBGMCU, state: bool);
551+
}
552+
547553
#[derive(Clone, Copy, Debug, PartialEq)]
548554
pub struct RawConfig {
549555
pub hse: Option<u32>,

src/rcc/enable.rs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,43 @@ macro_rules! bus {
5454
}
5555
}
5656

57+
macro_rules! dbgstop {
58+
($($PER:ident => ($bit:literal),)+) => {
59+
$(
60+
impl StopInDebug for crate::pac::$PER {
61+
#[inline(always)]
62+
fn stop_in_debug(&mut self, dbg: &mut DBGMCU, state: bool) {
63+
unsafe {
64+
bb::write(dbg.cr(), $bit, state);
65+
}
66+
}
67+
}
68+
)+
69+
}
70+
}
71+
5772
#[cfg(feature = "stm32f103")]
5873
bus! {
5974
ADC2 => (APB2, 10),
6075
CAN => (APB1, 25),
6176
}
77+
#[cfg(feature = "stm32f103")]
78+
dbgstop! {
79+
CAN => (14), // dbg_can1_stop
80+
}
81+
6282
#[cfg(feature = "connectivity")]
6383
bus! {
6484
ADC2 => (APB2, 10),
6585
CAN1 => (APB1, 25),
6686
CAN2 => (APB1, 26),
6787
}
88+
#[cfg(feature = "connectivity")]
89+
dbgstop! {
90+
CAN1 => (14), // dbg_can1_stop
91+
CAN2 => (21), // dbg_can2_stop
92+
}
93+
6894
#[cfg(feature = "has-dac")]
6995
bus! {
7096
DAC => (APB1, 29),
@@ -94,6 +120,12 @@ bus! {
94120
USART3 => (APB1, 18),
95121
WWDG => (APB1, 11),
96122
}
123+
dbgstop! {
124+
IWDG => (8), // dbg_iwdg_stop
125+
WWDG => (9), // dbg_wwdg_stop
126+
I2C1 => (15), // dbg_i2c1_smbus_timeout
127+
I2C2 => (16), // dbg_i2c2_smbus_timeout
128+
}
97129

98130
#[cfg(any(feature = "xl", feature = "high"))]
99131
bus! {
@@ -130,16 +162,28 @@ bus! {
130162
TIM2 => (APB1, 0),
131163
TIM3 => (APB1, 1),
132164
}
165+
dbgstop! {
166+
TIM2 => (11), // dbg_tim2_stop
167+
TIM3 => (12), // dbg_tim3_stop
168+
}
133169

134170
#[cfg(any(feature = "stm32f100", feature = "stm32f103", feature = "connectivity"))]
135171
bus! {
136172
TIM1 => (APB2, 11),
137173
}
174+
#[cfg(any(feature = "stm32f100", feature = "stm32f103", feature = "connectivity"))]
175+
dbgstop! {
176+
TIM1 => (10), // dbg_tim1_stop
177+
}
138178

139179
#[cfg(any(feature = "stm32f100", feature = "high", feature = "connectivity"))]
140180
bus! {
141181
TIM6 => (APB1, 4),
142182
}
183+
#[cfg(any(feature = "stm32f100", feature = "high", feature = "connectivity"))]
184+
dbgstop! {
185+
TIM6 => (19), // dbg_tim6_stop
186+
}
143187

144188
#[cfg(any(
145189
all(feature = "high", any(feature = "stm32f101", feature = "stm32f103")),
@@ -148,42 +192,79 @@ bus! {
148192
bus! {
149193
TIM7 => (APB1, 5),
150194
}
195+
#[cfg(any(
196+
all(feature = "high", any(feature = "stm32f101", feature = "stm32f103")),
197+
any(feature = "stm32f100", feature = "connectivity")
198+
))]
199+
dbgstop! {
200+
TIM7 => (20), // dbg_tim7_stop
201+
}
151202

152203
#[cfg(feature = "stm32f100")]
153204
bus! {
154205
TIM15 => (APB2, 16),
155206
TIM16 => (APB2, 17),
156207
TIM17 => (APB2, 18),
157208
}
209+
#[cfg(feature = "stm32f100")]
210+
dbgstop! {
211+
TIM15 => (22), // dbg_tim15_stop
212+
TIM16 => (23), // dbg_tim16_stop
213+
TIM17 => (24), // dbg_tim17_stop
214+
}
158215

159216
#[cfg(feature = "medium")]
160217
bus! {
161218
TIM4 => (APB1, 2),
162219
}
220+
#[cfg(feature = "medium")]
221+
dbgstop! {
222+
TIM4 => (13), // dbg_tim4_stop
223+
}
163224

164225
#[cfg(any(feature = "high", feature = "connectivity"))]
165226
bus! {
166227
TIM5 => (APB1, 3),
167228
}
229+
#[cfg(any(feature = "high", feature = "connectivity"))]
230+
dbgstop! {
231+
TIM5 => (18), // dbg_tim5_stop
232+
}
168233

169234
#[cfg(any(feature = "xl", all(feature = "stm32f100", feature = "high")))]
170235
bus! {
171236
TIM12 => (APB1, 6),
172237
TIM13 => (APB1, 7),
173238
TIM14 => (APB1, 8),
174239
}
240+
#[cfg(any(feature = "xl", all(feature = "stm32f100", feature = "high")))]
241+
dbgstop! {
242+
TIM12 => (25), // dbg_tim12_stop
243+
TIM13 => (26), // dbg_tim13_stop
244+
TIM14 => (27), // dbg_tim14_stop
245+
}
175246

176247
#[cfg(all(feature = "stm32f103", feature = "high"))]
177248
bus! {
178249
TIM8 => (APB2, 13),
179250
}
251+
#[cfg(all(feature = "stm32f103", feature = "high"))]
252+
dbgstop! {
253+
TIM8 => (17), // dbg_tim8_stop
254+
}
180255

181256
#[cfg(feature = "xl")]
182257
bus! {
183258
TIM9 => (APB2, 19),
184259
TIM10 => (APB2, 20),
185260
TIM11 => (APB2, 21),
186261
}
262+
#[cfg(feature = "xl")]
263+
dbgstop! {
264+
TIM9 => (28), // dbg_tim9_stop
265+
TIM10 => (29), // dbg_tim10_stop
266+
TIM11 => (30), // dbg_tim11_stop
267+
}
187268

188269
#[cfg(feature = "stm32f103")] // feature = "stm32f102"
189270
bus! {

0 commit comments

Comments
 (0)