@@ -272,6 +272,17 @@ 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. If called when the timer is running,
279+ /// it may disrupt the output waveform.
280+ pub fn generate_update_event ( & self ) {
281+ self . regs_core ( ) . cr1 ( ) . modify ( |r| r. set_urs ( vals:: Urs :: COUNTER_ONLY ) ) ;
282+ self . regs_core ( ) . egr ( ) . write ( |r| r. set_ug ( true ) ) ;
283+ self . regs_core ( ) . cr1 ( ) . modify ( |r| r. set_urs ( vals:: Urs :: ANY_EVENT ) ) ;
284+ }
285+
275286 /// Stop the timer.
276287 pub fn stop ( & self ) {
277288 self . regs_core ( ) . cr1 ( ) . modify ( |r| r. set_cen ( false ) ) ;
@@ -322,10 +333,6 @@ impl<'d, T: CoreInstance> Timer<'d, T> {
322333 let regs = self . regs_core ( ) ;
323334 regs. psc ( ) . write_value ( psc) ;
324335 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 ) ) ;
329336 }
330337 #[ cfg( not( stm32l0) ) ]
331338 TimerBits :: Bits32 => {
@@ -335,10 +342,6 @@ impl<'d, T: CoreInstance> Timer<'d, T> {
335342 let regs = self . regs_gp32_unchecked ( ) ;
336343 regs. psc ( ) . write_value ( psc) ;
337344 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 ) ) ;
342345 }
343346 }
344347 }
0 commit comments