@@ -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_BinaryConf
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
/**
@@ -463,6 +492,10 @@ bool RTC_init(hourFormat_t format, binaryMode_t mode, sourceClock_t source, bool
463
492
RTC_initClock (source );
464
493
RTC_getPrediv (& (RtcHandle .Init .AsynchPrediv ), & (RtcHandle .Init .SynchPrediv ));
465
494
#if defined(RTC_BINARY_NONE )
495
+ /*
496
+ * If RTC BIN mode changed, calling the HAL_RTC_Init will
497
+ * force the update of the BIN register in the RTC_ICSR
498
+ */
466
499
RTC_BinaryConf (mode );
467
500
#endif /* RTC_BINARY_NONE */
468
501
#endif // STM32F1xx
@@ -527,11 +560,11 @@ bool RTC_init(hourFormat_t format, binaryMode_t mode, sourceClock_t source, bool
527
560
#else
528
561
RTC_getPrediv (& (RtcHandle .Init .AsynchPrediv ), & (RtcHandle .Init .SynchPrediv ));
529
562
#endif
563
+ #if defined(RTC_BINARY_NONE )
530
564
/*
531
- * TODO: RTC is already initialized, but RTC BIN mode is changed
565
+ * If RTC BIN mode changed, calling the HAL_RTC_Init will
532
566
* force the update of the BIN register in the RTC_ICSR
533
567
*/
534
- #if defined(RTC_BINARY_NONE )
535
568
RTC_BinaryConf (mode );
536
569
#endif /* RTC_BINARY_NONE */
537
570
HAL_RTC_Init (& RtcHandle );
@@ -558,6 +591,13 @@ bool RTC_init(hourFormat_t format, binaryMode_t mode, sourceClock_t source, bool
558
591
#endif
559
592
#if defined(RTC_BINARY_NONE )
560
593
RTC_BinaryConf (mode );
594
+ /*
595
+ * RTC is already initialized, but RTC BIN mode is changed :
596
+ * force the update of the BIN register and BCDu in the RTC_ICSR
597
+ * by the RTC_SetBinaryConf function
598
+ */
599
+ RTC_SetBinaryConf ();
600
+
561
601
#endif /* RTC_BINARY_NONE */
562
602
#if defined(STM32F1xx )
563
603
memcpy (& RtcHandle .DateToUpdate , & BackupDate , 4 );
0 commit comments