@@ -69,7 +69,7 @@ use fugit::RateExtU32;
6969
7070/// Hardware timers
7171pub struct Timer < TIM > {
72- clocks : Clocks ,
72+ clock : Hertz ,
7373 tim : TIM ,
7474 timeout : Hertz ,
7575}
@@ -81,7 +81,7 @@ pub enum Event {
8181}
8282
8383macro_rules! hal {
84- ( $( $TIM: ident: ( $tim: ident, $frname: ident, $apb: ident, $width: ident) , ) +) => {
84+ ( $( $TIM: ident: ( $tim: ident, $frname: ident, $apb: ident, $width: ident, $timclk : ident ) , ) +) => {
8585 $(
8686 impl Periodic for Timer <$TIM> { }
8787
@@ -98,7 +98,7 @@ macro_rules! hal {
9898 self . pause( ) ;
9999
100100 self . timeout = timeout. into( ) ;
101- let ticks = self . clocks . pclk1 ( ) / self . timeout; // TODO: Check pclk that timer is on.
101+ let ticks = self . clock / self . timeout; // TODO check pclk that timer is on
102102 let psc = u16 ( ( ticks - 1 ) / ( 1 << 16 ) ) . unwrap( ) ;
103103
104104 self . tim. psc. write( |w| unsafe { w. psc( ) . bits( psc) } ) ;
@@ -150,8 +150,10 @@ macro_rules! hal {
150150 <$TIM>:: enable( apb) ;
151151 <$TIM>:: reset( apb) ;
152152
153+ let clock = clocks. $timclk( ) ;
154+
153155 let mut timer = Timer {
154- clocks ,
156+ clock ,
155157 tim,
156158 timeout: 0 . Hz ( ) ,
157159 } ;
@@ -173,9 +175,11 @@ macro_rules! hal {
173175 <$TIM>:: enable( apb) ;
174176 <$TIM>:: reset( apb) ;
175177
176- let psc = clocks. pclk1( ) / frequency - 1 ;
178+ let clock = clocks. $timclk( ) ;
179+
180+ let psc = clock / frequency - 1 ;
177181
178- debug_assert!( clocks . pclk1 ( ) >= frequency) ;
182+ debug_assert!( clock >= frequency) ;
179183 debug_assert!( frequency. raw( ) > 0 ) ;
180184 debug_assert!( psc <= core:: u16 :: MAX . into( ) ) ;
181185
@@ -206,7 +210,7 @@ macro_rules! hal {
206210 } ) ;
207211
208212 Timer {
209- clocks ,
213+ clock ,
210214 tim,
211215 timeout: frequency,
212216 }
@@ -277,11 +281,11 @@ macro_rules! hal {
277281}
278282
279283hal ! {
280- TIM2 : ( tim2, free_running_tim2, APB1R1 , u32 ) ,
281- TIM6 : ( tim6, free_running_tim6, APB1R1 , u16 ) ,
282- //TIM7: (tim7, free_running_tim7, APB1R1, u16),
283- TIM15 : ( tim15, free_running_tim15, APB2 , u16 ) ,
284- TIM16 : ( tim16, free_running_tim16, APB2 , u16 ) ,
284+ TIM2 : ( tim2, free_running_tim2, APB1R1 , u32 , timclk1 ) ,
285+ TIM6 : ( tim6, free_running_tim6, APB1R1 , u16 , timclk1 ) ,
286+ //TIM7: (tim7, free_running_tim7, APB1R1, u16, timclk1 ),
287+ TIM15 : ( tim15, free_running_tim15, APB2 , u16 , timclk2 ) ,
288+ TIM16 : ( tim16, free_running_tim16, APB2 , u16 , timclk2 ) ,
285289}
286290
287291#[ cfg( any(
@@ -305,7 +309,7 @@ hal! {
305309 // feature = "stm32l4s9",
306310) ) ]
307311hal ! {
308- TIM3 : ( tim3, free_running_tim3, APB1R1 , u16 ) ,
312+ TIM3 : ( tim3, free_running_tim3, APB1R1 , u16 , timclk1 ) ,
309313}
310314
311315#[ cfg( not( any(
@@ -316,7 +320,7 @@ hal! {
316320 feature = "stm32l462" ,
317321) ) ) ]
318322hal ! {
319- TIM7 : ( tim7, free_running_tim7, APB1R1 , u16 ) ,
323+ TIM7 : ( tim7, free_running_tim7, APB1R1 , u16 , timclk1 ) ,
320324}
321325
322326#[ cfg( any(
@@ -336,7 +340,7 @@ hal! {
336340 // feature = "stm32l4s9",
337341) ) ]
338342hal ! {
339- TIM4 : ( tim4, free_running_tim4, APB1R1 , u16 ) ,
340- TIM5 : ( tim5, free_running_tim5, APB1R1 , u32 ) ,
341- TIM17 : ( tim17, free_running_tim17, APB2 , u16 ) ,
343+ TIM4 : ( tim4, free_running_tim4, APB1R1 , u16 , timclk1 ) ,
344+ TIM5 : ( tim5, free_running_tim5, APB1R1 , u32 , timclk1 ) ,
345+ TIM17 : ( tim17, free_running_tim17, APB2 , u16 , timclk2 ) ,
342346}
0 commit comments