Skip to content

Commit 35ca5a1

Browse files
committed
move stop_in_debug to independent trait
1 parent 3ccc4fc commit 35ca5a1

File tree

3 files changed

+110
-46
lines changed

3 files changed

+110
-46
lines changed

src/rcc.rs

Lines changed: 6 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;
@@ -545,6 +545,11 @@ pub trait Reset: RccBus {
545545
}
546546
}
547547

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+
548553
#[derive(Clone, Copy, Debug, PartialEq)]
549554
pub struct RawConfig {
550555
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! {

src/timer.rs

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ pub use pac::tim1::cr1::CMS as CenterAlignedMode;
354354
mod sealed {
355355
use super::{
356356
CaptureFilter, CaptureMode, CapturePolarity, CapturePrescaler, CenterAlignedMode, Event,
357-
IdleState, Ocm, Polarity, DBG,
357+
IdleState, Ocm, Polarity,
358358
};
359359
pub trait General {
360360
type Width: Into<u32> + From<u16>;
@@ -376,7 +376,6 @@ mod sealed {
376376
fn start_one_pulse(&mut self);
377377
fn cr1_reset(&mut self);
378378
fn cnt_reset(&mut self);
379-
fn stop_in_debug(&mut self, dbg: &mut DBG, state: bool);
380379
}
381380

382381
pub trait WithChannel: General {
@@ -422,15 +421,14 @@ mod sealed {
422421
pub(crate) use sealed::{Advanced, General, MasterTimer, WithCapture, WithChannel, WithPwm};
423422

424423
pub trait Instance:
425-
crate::Sealed + rcc::Enable + rcc::Reset + rcc::BusTimerClock + General
424+
crate::Sealed + rcc::Enable + rcc::Reset + rcc::BusTimerClock + rcc::StopInDebug + General
426425
{
427426
}
428427

429428
macro_rules! hal {
430429
($TIM:ty: [
431430
$Timer:ident,
432431
$bits:ty,
433-
$dbg_timX_stop:ident,
434432
$(c: ($cnum:tt, $ncnum:tt $(, $aoe:ident)?),)?
435433
$(m: $timbase:ident,)?
436434
]) => {
@@ -529,10 +527,6 @@ macro_rules! hal {
529527
fn cnt_reset(&mut self) {
530528
self.cnt().reset();
531529
}
532-
#[inline(always)]
533-
fn stop_in_debug(&mut self, dbg: &mut DBG, state: bool) {
534-
dbg.cr().modify(|_, w| w.$dbg_timX_stop().bit(state));
535-
}
536530
}
537531
$(
538532
impl WithChannel for $TIM {
@@ -933,62 +927,46 @@ const fn compute_arr_presc(freq: u32, clock: u32) -> (u16, u32) {
933927
}
934928

935929
#[cfg(any(feature = "stm32f100", feature = "stm32f103", feature = "connectivity"))]
936-
hal!(pac::TIM1: [Timer1, u16, dbg_tim1_stop, c: (4, 4, _aoe), m: tim1,]);
930+
hal!(pac::TIM1: [Timer1, u16, c: (4, 4, _aoe), m: tim1,]);
937931

938-
hal!(pac::TIM2: [Timer2, u16, dbg_tim2_stop, c: (4, 0), m: tim2,]);
939-
hal!(pac::TIM3: [Timer3, u16, dbg_tim3_stop, c: (4, 0), m: tim2,]);
932+
hal!(pac::TIM2: [Timer2, u16, c: (4, 0), m: tim2,]);
933+
hal!(pac::TIM3: [Timer3, u16, c: (4, 0), m: tim2,]);
940934

941935
#[cfg(feature = "medium")]
942-
hal!(pac::TIM4: [Timer4, u16, dbg_tim4_stop, c: (4, 0), m: tim2,]);
936+
hal!(pac::TIM4: [Timer4, u16, c: (4, 0), m: tim2,]);
943937

944938
#[cfg(any(feature = "high", feature = "connectivity"))]
945-
hal!(pac::TIM5: [Timer5, u16, dbg_tim5_stop, c: (4, 0), m: tim2,]);
939+
hal!(pac::TIM5: [Timer5, u16, c: (4, 0), m: tim2,]);
946940

947941
#[cfg(any(feature = "stm32f100", feature = "high", feature = "connectivity"))]
948-
hal!(pac::TIM6: [Timer6, u16, dbg_tim6_stop, m: tim6,]);
942+
hal!(pac::TIM6: [Timer6, u16, m: tim6,]);
949943

950944
#[cfg(any(
951945
all(feature = "high", any(feature = "stm32f101", feature = "stm32f103")),
952946
any(feature = "stm32f100", feature = "connectivity")
953947
))]
954-
hal!(pac::TIM7: [Timer7, u16, dbg_tim7_stop, m: tim6,]);
948+
hal!(pac::TIM7: [Timer7, u16, m: tim6,]);
955949

956950
#[cfg(all(feature = "stm32f103", feature = "high"))]
957-
hal!(pac::TIM8: [Timer8, u16, dbg_tim8_stop, c: (4, 4, _aoe), m: tim1,]);
951+
hal!(pac::TIM8: [Timer8, u16, c: (4, 4, _aoe), m: tim1,]);
958952

959-
//TODO: restore these timers once stm32-rs has been updated
960-
// dbg_tim(12-13)_stop fields missing from 103 xl in stm32-rs
961-
// dbg_tim(9-10)_stop fields missing from 101 xl in stm32-rs
962-
/*
963953
#[cfg(feature = "xl")]
964-
hal!(pac::TIM9: [Timer9, u16, dbg_tim9_stop, c: (2, 2),]);
954+
hal!(pac::TIM9: [Timer9, u16, c: (2, 2),]);
965955
#[cfg(feature = "xl")]
966-
hal!(pac::TIM10: [Timer10, u16, dbg_tim10_stop, c: (1, 1),]);
956+
hal!(pac::TIM10: [Timer10, u16, c: (1, 1),]);
967957
#[cfg(feature = "xl")]
968-
hal!(pac::TIM11: [Timer11, u16, dbg_tim11_stop, c: (1, 1),]);
969-
*/
970-
#[cfg(any(
971-
all(feature = "stm32f100", feature = "high"),
972-
all(feature = "stm32f101", feature = "xl"),
973-
//all(feature = "stm32f103", feature = "xl"),
974-
))]
975-
hal!(pac::TIM12: [Timer12, u16, dbg_tim12_stop, c: (2, 2),]);
976-
#[cfg(any(
977-
all(feature = "stm32f100", feature = "high"),
978-
all(feature = "stm32f101", feature = "xl"),
979-
//all(feature = "stm32f103", feature = "xl"),
980-
))]
981-
hal!(pac::TIM13: [Timer13, u16, dbg_tim13_stop, c: (1, 1),]);
982-
#[cfg(any(
983-
all(feature = "stm32f100", feature = "high"),
984-
all(feature = "stm32f101", feature = "xl"),
985-
//all(feature = "stm32f103", feature = "xl"),
986-
))]
987-
hal!(pac::TIM14: [Timer14, u16, dbg_tim14_stop, c: (1, 1),]);
958+
hal!(pac::TIM11: [Timer11, u16, c: (1, 1),]);
959+
960+
#[cfg(any(feature = "xl", all(feature = "stm32f100", feature = "high")))]
961+
hal!(pac::TIM12: [Timer12, u16, c: (2, 2),]);
962+
#[cfg(any(feature = "xl", all(feature = "stm32f100", feature = "high")))]
963+
hal!(pac::TIM13: [Timer13, u16, c: (1, 1),]);
964+
#[cfg(any(feature = "xl", all(feature = "stm32f100", feature = "high")))]
965+
hal!(pac::TIM14: [Timer14, u16, c: (1, 1),]);
988966

989967
#[cfg(feature = "stm32f100")]
990-
hal!(pac::TIM15: [Timer15, u16, dbg_tim15_stop, c: (2, 2),]);
968+
hal!(pac::TIM15: [Timer15, u16, c: (2, 2),]);
991969
#[cfg(feature = "stm32f100")]
992-
hal!(pac::TIM16: [Timer16, u16, dbg_tim16_stop, c: (1, 1),]);
970+
hal!(pac::TIM16: [Timer16, u16, c: (1, 1),]);
993971
#[cfg(feature = "stm32f100")]
994-
hal!(pac::TIM17: [Timer17, u16, dbg_tim17_stop, c: (1, 1),]);
972+
hal!(pac::TIM17: [Timer17, u16, c: (1, 1),]);

0 commit comments

Comments
 (0)