@@ -93,6 +93,7 @@ static void RTC_computePrediv(uint32_t *asynch, uint32_t *synch);
93
93
#endif /* !STM32F1xx */
94
94
#if defined(RTC_BINARY_NONE )
95
95
static void RTC_BinaryConf (binaryMode_t mode );
96
+ static void RTC_SetBinaryConf (void );
96
97
#endif
97
98
98
99
static inline int _log2 (int x )
@@ -383,6 +384,34 @@ static void RTC_BinaryConf(binaryMode_t mode)
383
384
}
384
385
}
385
386
}
387
+
388
+ /*
389
+ * Function to check if the RTC ICSR register must be updated with new bit
390
+ * field BIN and BCDU. To be called just after the RTC_SetBinaryConf
391
+ * Map the LL RTC bin mode to the corresponding RtcHandle.Init.BinMode values
392
+ * assuming the LL_RTC_BINARY_xxx is identical to RTC_BINARY_xxx (RTC_ICSR_BIN_xxx)
393
+ * Idem for the LL_RTC_BINARY_MIX_BCDU_n and RTC_BINARY_MIX_BCDU_n
394
+ */
395
+ #if (RTC_BINARY_MIX != LL_RTC_BINARY_MIX )
396
+ #error "RTC_BINARY_MIX and LL_RTC_BINARY_MIX do not match"
397
+ #endif
398
+ #if (RTC_BINARY_MIX_BCDU_7 != LL_RTC_BINARY_MIX_BCDU_7 )
399
+ #error "RTC_BINARY_MIX_BCDU_n and LL_RTC_BINARY_MIX_BCDU_n do not match"
400
+ #endif
401
+ static void RTC_SetBinaryConf (void )
402
+ {
403
+ if (LL_RTC_GetBinaryMode (RtcHandle .Instance ) != RtcHandle .Init .BinMode ) {
404
+ LL_RTC_DisableWriteProtection (RtcHandle .Instance );
405
+ LL_RTC_EnableInitMode (RtcHandle .Instance );
406
+
407
+ LL_RTC_SetBinaryMode (RtcHandle .Instance , RtcHandle .Init .BinMode );
408
+ if (RtcHandle .Init .BinMode == RTC_BINARY_MIX ) {
409
+ LL_RTC_SetBinMixBCDU (RtcHandle .Instance , RtcHandle .Init .BinMixBcdU );
410
+ }
411
+ LL_RTC_ExitInitMode (RtcHandle .Instance );
412
+ LL_RTC_EnableWriteProtection (RtcHandle .Instance );
413
+ }
414
+ }
386
415
#endif /* RTC_BINARY_NONE */
387
416
388
417
/**
@@ -462,6 +491,10 @@ bool RTC_init(hourFormat_t format, binaryMode_t mode, sourceClock_t source, bool
462
491
RTC_initClock (source );
463
492
RTC_getPrediv (& (RtcHandle .Init .AsynchPrediv ), & (RtcHandle .Init .SynchPrediv ));
464
493
#if defined(RTC_BINARY_NONE )
494
+ /*
495
+ * If RTC BIN mode changed, calling the HAL_RTC_Init will
496
+ * force the update of the BIN register in the RTC_ICSR
497
+ */
465
498
RTC_BinaryConf (mode );
466
499
#endif /* RTC_BINARY_NONE */
467
500
#endif // STM32F1xx
@@ -526,11 +559,11 @@ bool RTC_init(hourFormat_t format, binaryMode_t mode, sourceClock_t source, bool
526
559
#else
527
560
RTC_getPrediv (& (RtcHandle .Init .AsynchPrediv ), & (RtcHandle .Init .SynchPrediv ));
528
561
#endif
562
+ #if defined(RTC_BINARY_NONE )
529
563
/*
530
- * TODO: RTC is already initialized, but RTC BIN mode is changed
564
+ * If RTC BIN mode changed, calling the HAL_RTC_Init will
531
565
* force the update of the BIN register in the RTC_ICSR
532
566
*/
533
- #if defined(RTC_BINARY_NONE )
534
567
RTC_BinaryConf (mode );
535
568
#endif /* RTC_BINARY_NONE */
536
569
HAL_RTC_Init (& RtcHandle );
@@ -557,6 +590,13 @@ bool RTC_init(hourFormat_t format, binaryMode_t mode, sourceClock_t source, bool
557
590
#endif
558
591
#if defined(RTC_BINARY_NONE )
559
592
RTC_BinaryConf (mode );
593
+ /*
594
+ * RTC is already initialized, but RTC BIN mode is changed :
595
+ * force the update of the BIN register and BCDu in the RTC_ICSR
596
+ * by the RTC_SetBinaryConf function
597
+ */
598
+ RTC_SetBinaryConf ();
599
+
560
600
#endif /* RTC_BINARY_NONE */
561
601
#if defined(STM32F1xx )
562
602
memcpy (& RtcHandle .DateToUpdate , & BackupDate , 4 );
0 commit comments