@@ -272,6 +272,16 @@ impl<'d, T: CoreInstance> Timer<'d, T> {
272272 self . regs_core ( ) . cr1 ( ) . modify ( |r| r. set_cen ( true ) ) ;
273273 }
274274
275+ /// Generate timer update event from software.
276+ ///
277+ /// Set URS to avoid generating interrupt or DMA request. This update event is only
278+ /// used to load value from pre-load registers.
279+ pub fn generate_update_event ( & self ) {
280+ self . regs_core ( ) . cr1 ( ) . modify ( |r| r. set_urs ( vals:: Urs :: COUNTER_ONLY ) ) ;
281+ self . regs_core ( ) . egr ( ) . write ( |r| r. set_ug ( true ) ) ;
282+ self . regs_core ( ) . cr1 ( ) . modify ( |r| r. set_urs ( vals:: Urs :: ANY_EVENT ) ) ;
283+ }
284+
275285 /// Stop the timer.
276286 pub fn stop ( & self ) {
277287 self . regs_core ( ) . cr1 ( ) . modify ( |r| r. set_cen ( false ) ) ;
@@ -322,10 +332,6 @@ impl<'d, T: CoreInstance> Timer<'d, T> {
322332 let regs = self . regs_core ( ) ;
323333 regs. psc ( ) . write_value ( psc) ;
324334 regs. arr ( ) . write ( |r| r. set_arr ( arr) ) ;
325-
326- regs. cr1 ( ) . modify ( |r| r. set_urs ( vals:: Urs :: COUNTER_ONLY ) ) ;
327- regs. egr ( ) . write ( |r| r. set_ug ( true ) ) ;
328- regs. cr1 ( ) . modify ( |r| r. set_urs ( vals:: Urs :: ANY_EVENT ) ) ;
329335 }
330336 #[ cfg( not( stm32l0) ) ]
331337 TimerBits :: Bits32 => {
@@ -335,10 +341,6 @@ impl<'d, T: CoreInstance> Timer<'d, T> {
335341 let regs = self . regs_gp32_unchecked ( ) ;
336342 regs. psc ( ) . write_value ( psc) ;
337343 regs. arr ( ) . write_value ( arr) ;
338-
339- regs. cr1 ( ) . modify ( |r| r. set_urs ( vals:: Urs :: COUNTER_ONLY ) ) ;
340- regs. egr ( ) . write ( |r| r. set_ug ( true ) ) ;
341- regs. cr1 ( ) . modify ( |r| r. set_urs ( vals:: Urs :: ANY_EVENT ) ) ;
342344 }
343345 }
344346 }
0 commit comments