@@ -231,7 +231,7 @@ impl Rcc {
231
231
}
232
232
}
233
233
234
- pub fn unlock_rtc ( & mut self ) {
234
+ pub fn unlock_rtc_old ( & mut self ) {
235
235
self . rb . apb1enr1 . modify ( |_, w| w. pwren ( ) . set_bit ( ) ) ;
236
236
let pwr = unsafe { & ( * PWR :: ptr ( ) ) } ;
237
237
pwr. cr1 . modify ( |_, w| w. dbp ( ) . set_bit ( ) ) ;
@@ -457,6 +457,46 @@ impl Rcc {
457
457
pub fn clear_reset_reason ( & mut self ) {
458
458
self . rb . csr . modify ( |_, w| w. rmvf ( ) . set_bit ( ) ) ;
459
459
}
460
+
461
+ pub ( crate ) fn unlock_rtc ( & self ) {
462
+ self . rb . apb1enr1 . modify ( |_, w| w. pwren ( ) . set_bit ( ) ) ;
463
+ let pwr = unsafe { & ( * PWR :: ptr ( ) ) } ;
464
+ pwr. cr1 . modify ( |_, w| w. dbp ( ) . set_bit ( ) ) ;
465
+ while pwr. cr1 . read ( ) . dbp ( ) . bit_is_clear ( ) { }
466
+ }
467
+
468
+ pub ( crate ) fn enable_rtc ( & self , src : RTCSrc ) {
469
+ self . unlock_rtc ( ) ;
470
+ self . rb
471
+ . apb1enr1
472
+ . modify ( |_, w| w. rtcapben ( ) . set_bit ( ) . pwren ( ) . set_bit ( ) ) ;
473
+ self . rb . apb1smenr1 . modify ( |_, w| w. rtcapbsmen ( ) . set_bit ( ) ) ;
474
+ self . rb . bdcr . modify ( |_, w| w. bdrst ( ) . set_bit ( ) ) ;
475
+
476
+ let rtc_sel = match src {
477
+ RTCSrc :: LSE | RTCSrc :: LSE_BYPASS => 0b01 ,
478
+ RTCSrc :: LSI => 0b10 ,
479
+ RTCSrc :: HSE | RTCSrc :: HSE_BYPASS => 0b11 ,
480
+ } ;
481
+
482
+ self . rb . bdcr . modify ( |_, w| {
483
+ w. rtcsel ( )
484
+ . bits ( rtc_sel)
485
+ . rtcen ( )
486
+ . set_bit ( )
487
+ . bdrst ( )
488
+ . clear_bit ( )
489
+ } ) ;
490
+
491
+ self . unlock_rtc ( ) ;
492
+ match src {
493
+ RTCSrc :: LSE => self . enable_lse ( false ) ,
494
+ RTCSrc :: LSE_BYPASS => self . enable_lse ( true ) ,
495
+ RTCSrc :: LSI => self . enable_lsi ( ) ,
496
+ RTCSrc :: HSE => self . enable_hse ( false ) ,
497
+ RTCSrc :: HSE_BYPASS => self . enable_hse ( true ) ,
498
+ } ;
499
+ }
460
500
}
461
501
462
502
pub struct ResetReason {
0 commit comments