56
56
use core:: marker:: PhantomData ;
57
57
use core:: mem;
58
58
59
- use cast:: { u16, u32} ;
60
59
use crate :: hal;
61
- #[ cfg( any(
62
- feature = "stm32f100" ,
63
- feature = "stm32f103" ,
64
- feature = "stm32f105" ,
65
- ) ) ]
60
+ #[ cfg( any( feature = "stm32f100" , feature = "stm32f103" , feature = "stm32f105" , ) ) ]
66
61
use crate :: pac:: TIM1 ;
67
- use crate :: pac:: { TIM2 , TIM3 } ;
68
62
#[ cfg( feature = "medium" ) ]
69
63
use crate :: pac:: TIM4 ;
64
+ use crate :: pac:: { TIM2 , TIM3 } ;
65
+ use cast:: { u16, u32} ;
70
66
71
67
use crate :: afio:: MAPR ;
72
68
use crate :: bb;
@@ -82,7 +78,7 @@ pub trait Pins<REMAP, P> {
82
78
type Channels ;
83
79
}
84
80
85
- use crate :: timer:: sealed:: { Remap , Ch1 , Ch2 , Ch3 , Ch4 } ;
81
+ use crate :: timer:: sealed:: { Ch1 , Ch2 , Ch3 , Ch4 , Remap } ;
86
82
macro_rules! pins_impl {
87
83
( $( ( $( $PINX: ident) ,+ ) , ( $( $TRAIT: ident) ,+ ) , ( $( $ENCHX: ident) ,* ) ; ) + ) => {
88
84
$(
@@ -117,37 +113,27 @@ pins_impl!(
117
113
( P4 ) , ( Ch4 ) , ( C4 ) ;
118
114
) ;
119
115
120
- #[ cfg( any(
121
- feature = "stm32f100" ,
122
- feature = "stm32f103" ,
123
- feature = "stm32f105" ,
124
- ) ) ]
116
+ #[ cfg( any( feature = "stm32f100" , feature = "stm32f103" , feature = "stm32f105" , ) ) ]
125
117
impl Timer < TIM1 > {
126
- pub fn pwm < REMAP , P , PINS , T > (
127
- self ,
128
- _pins : PINS ,
129
- mapr : & mut MAPR ,
130
- freq : T ,
131
- ) -> PINS :: Channels
118
+ pub fn pwm < REMAP , P , PINS , T > ( self , _pins : PINS , mapr : & mut MAPR , freq : T ) -> PINS :: Channels
132
119
where
133
120
REMAP : Remap < Periph = TIM1 > ,
134
121
PINS : Pins < REMAP , P > ,
135
122
T : Into < Hertz > ,
136
123
{
137
124
mapr. modify_mapr ( |_, w| unsafe { w. tim1_remap ( ) . bits ( REMAP :: REMAP ) } ) ;
138
125
126
+ // TIM1 has a break function that deactivates the outputs, this bit automatically activates
127
+ // the output when no break input is present
128
+ self . tim . bdtr . modify ( |_, w| w. aoe ( ) . set_bit ( ) ) ;
129
+
139
130
let Self { tim, clk } = self ;
140
131
tim1 ( tim, _pins, freq. into ( ) , clk)
141
132
}
142
133
}
143
134
144
135
impl Timer < TIM2 > {
145
- pub fn pwm < REMAP , P , PINS , T > (
146
- self ,
147
- _pins : PINS ,
148
- mapr : & mut MAPR ,
149
- freq : T ,
150
- ) -> PINS :: Channels
136
+ pub fn pwm < REMAP , P , PINS , T > ( self , _pins : PINS , mapr : & mut MAPR , freq : T ) -> PINS :: Channels
151
137
where
152
138
REMAP : Remap < Periph = TIM2 > ,
153
139
PINS : Pins < REMAP , P > ,
@@ -161,12 +147,7 @@ impl Timer<TIM2> {
161
147
}
162
148
163
149
impl Timer < TIM3 > {
164
- pub fn pwm < REMAP , P , PINS , T > (
165
- self ,
166
- _pins : PINS ,
167
- mapr : & mut MAPR ,
168
- freq : T ,
169
- ) -> PINS :: Channels
150
+ pub fn pwm < REMAP , P , PINS , T > ( self , _pins : PINS , mapr : & mut MAPR , freq : T ) -> PINS :: Channels
170
151
where
171
152
REMAP : Remap < Periph = TIM3 > ,
172
153
PINS : Pins < REMAP , P > ,
@@ -181,12 +162,7 @@ impl Timer<TIM3> {
181
162
182
163
#[ cfg( feature = "medium" ) ]
183
164
impl Timer < TIM4 > {
184
- pub fn pwm < REMAP , P , PINS , T > (
185
- self ,
186
- _pins : PINS ,
187
- mapr : & mut MAPR ,
188
- freq : T ,
189
- ) -> PINS :: Channels
165
+ pub fn pwm < REMAP , P , PINS , T > ( self , _pins : PINS , mapr : & mut MAPR , freq : T ) -> PINS :: Channels
190
166
where
191
167
REMAP : Remap < Periph = TIM4 > ,
192
168
PINS : Pins < REMAP , P > ,
@@ -247,6 +223,12 @@ macro_rules! hal {
247
223
let arr = u16 ( ticks / u32 ( psc + 1 ) ) . unwrap( ) ;
248
224
tim. arr. write( |w| w. arr( ) . bits( arr) ) ;
249
225
226
+ // The psc register is buffered, so we trigger an update event to update it
227
+ // Sets the URS bit to prevent an interrupt from being triggered by the UG bit
228
+ tim. cr1. modify( |_, w| w. urs( ) . set_bit( ) ) ;
229
+ tim. egr. write( |w| w. ug( ) . set_bit( ) ) ;
230
+ tim. cr1. modify( |_, w| w. urs( ) . clear_bit( ) ) ;
231
+
250
232
tim. cr1. write( |w|
251
233
w. cms( )
252
234
. bits( 0b00 )
@@ -360,11 +342,7 @@ macro_rules! hal {
360
342
}
361
343
}
362
344
363
- #[ cfg( any(
364
- feature = "stm32f100" ,
365
- feature = "stm32f103" ,
366
- feature = "stm32f105" ,
367
- ) ) ]
345
+ #[ cfg( any( feature = "stm32f100" , feature = "stm32f103" , feature = "stm32f105" , ) ) ]
368
346
hal ! {
369
347
TIM1 : ( tim1) ,
370
348
}
0 commit comments