@@ -700,7 +700,7 @@ void RTC_SetTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSe
700
700
*/
701
701
void RTC_GetTime (uint8_t * hours , uint8_t * minutes , uint8_t * seconds , uint32_t * subSeconds , hourAM_PM_t * period )
702
702
{
703
- RTC_TimeTypeDef RTC_TimeStruct ;
703
+ RTC_TimeTypeDef RTC_TimeStruct = { 0 }; /* in BIN mode, only the subseco is used */
704
704
705
705
if ((hours != NULL ) && (minutes != NULL ) && (seconds != NULL )) {
706
706
#if defined(STM32F1xx )
@@ -723,7 +723,7 @@ void RTC_GetTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *s
723
723
}
724
724
#if defined(RTC_SSR_SS )
725
725
if (subSeconds != NULL ) {
726
- if (initMode == MODE_BINARY_MIX ) {
726
+ if (( initMode == MODE_BINARY_MIX ) || ( initMode == MODE_BINARY_ONLY ) ) {
727
727
/* The subsecond is the free-running downcounter, to be converted in milliseconds */
728
728
* subSeconds = (((UINT32_MAX - RTC_TimeStruct .SubSeconds + 1 ) & UINT32_MAX )
729
729
* 1000 ) / fqce_apre ; /* give one more to compensate the 3.9ms uncertainty */
@@ -782,7 +782,7 @@ void RTC_SetDate(uint8_t year, uint8_t month, uint8_t day, uint8_t wday)
782
782
*/
783
783
void RTC_GetDate (uint8_t * year , uint8_t * month , uint8_t * day , uint8_t * wday )
784
784
{
785
- RTC_DateTypeDef RTC_DateStruct ;
785
+ RTC_DateTypeDef RTC_DateStruct = { 0 }; /* in BIN mode, the date is not used */
786
786
787
787
if ((year != NULL ) && (month != NULL ) && (day != NULL ) && (wday != NULL )) {
788
788
HAL_RTC_GetDate (& RtcHandle , & RTC_DateStruct , RTC_FORMAT_BIN );
@@ -828,14 +828,16 @@ void RTC_StartAlarm(alarm_t name, uint8_t day, uint8_t hours, uint8_t minutes, u
828
828
#if defined(RTC_SSR_SS )
829
829
if (subSeconds < 1000 ) {
830
830
#ifdef RTC_ALARM_B
831
- if (name == ALARM_B ) {
831
+ if (name == ALARM_B )
832
+ {
832
833
RTC_AlarmStructure .AlarmSubSecondMask = predivSync_bits << RTC_ALRMBSSR_MASKSS_Pos ;
833
834
} else
834
835
#endif
835
836
{
836
837
RTC_AlarmStructure .AlarmSubSecondMask = predivSync_bits << RTC_ALRMASSR_MASKSS_Pos ;
837
838
}
838
- if (initMode == MODE_BINARY_MIX ) {
839
+ /* in MIX or BCD Mode, the subsecond param is a nb of milliseconds */
840
+ if ((initMode == MODE_BINARY_MIX ) || (initMode == MODE_BINARY_NONE )) {
839
841
/* the subsecond is the millisecond to be converted in a subsecond downcounter value */
840
842
RTC_AlarmStructure .AlarmTime .SubSeconds = UINT32_MAX - ((subSeconds * fqce_apre ) / 1000 + 1 );
841
843
} else {
@@ -886,7 +888,7 @@ void RTC_StartAlarm(alarm_t name, uint8_t day, uint8_t hours, uint8_t minutes, u
886
888
HAL_NVIC_SetPriority (RTC_Alarm_IRQn , RTC_IRQ_PRIO , RTC_IRQ_SUBPRIO );
887
889
HAL_NVIC_EnableIRQ (RTC_Alarm_IRQn );
888
890
#if defined(RTC_ICSR_BIN )
889
- } else if (RtcHandle . Init . BinMode != RTC_BINARY_NONE ) {
891
+ } else if (( initMode == MODE_BINARY_MIX ) || ( initMode == MODE_BINARY_ONLY ) ) {
890
892
/* We have an SubSecond alarm to set in RTC_BINARY_MIX or RTC_BINARY_ONLY mode */
891
893
#else
892
894
} else {
@@ -913,6 +915,37 @@ void RTC_StartAlarm(alarm_t name, uint8_t day, uint8_t hours, uint8_t minutes, u
913
915
RTC_AlarmStructure .AlarmTime .SubSeconds = UINT32_MAX - (subSeconds * fqce_apre ) / 1000 ;
914
916
}
915
917
918
+ #else
919
+ UNUSED (subSeconds );
920
+ #endif /* RTC_SSR_SS */
921
+ /* Set RTC_Alarm */
922
+ HAL_RTC_SetAlarm_IT (& RtcHandle , & RTC_AlarmStructure , RTC_FORMAT_BIN );
923
+ HAL_NVIC_SetPriority (RTC_Alarm_IRQn , RTC_IRQ_PRIO , RTC_IRQ_SUBPRIO );
924
+ HAL_NVIC_EnableIRQ (RTC_Alarm_IRQn );
925
+ #if defined(RTC_ICSR_BIN )
926
+ } else {
927
+ /* We have an SubSecond alarm to set in BCD (RTC_BINARY_NONE) mode */
928
+ #if defined(RTC_SSR_SS )
929
+ {
930
+ #if defined(RTC_ALRMASSR_SSCLR )
931
+ RTC_AlarmStructure .BinaryAutoClr = RTC_ALARMSUBSECONDBIN_AUTOCLR_NO ;
932
+ #endif /* RTC_ALRMASSR_SSCLR */
933
+ RTC_AlarmStructure .AlarmMask = RTC_ALARMMASK_ALL ;
934
+
935
+ #ifdef RTC_ALARM_B
936
+ if (name == ALARM_B )
937
+ {
938
+ /* Expecting RTC_ALARMSUBSECONDBINMASK_NONE for the subsecond mask on ALARM B */
939
+ RTC_AlarmStructure .AlarmSubSecondMask = mask << RTC_ALRMBSSR_MASKSS_Pos ;
940
+ } else
941
+ #endif
942
+ {
943
+ /* Expecting RTC_ALARMSUBSECONDBINMASK_NONE for the subsecond mask on ALARM A */
944
+ RTC_AlarmStructure .AlarmSubSecondMask = mask << RTC_ALRMASSR_MASKSS_Pos ;
945
+ }
946
+ RTC_AlarmStructure .AlarmTime .SubSeconds = subSeconds * fqce_apre / 1000 ;
947
+ }
948
+
916
949
#else
917
950
UNUSED (subSeconds );
918
951
#endif /* RTC_SSR_SS */
@@ -921,6 +954,8 @@ void RTC_StartAlarm(alarm_t name, uint8_t day, uint8_t hours, uint8_t minutes, u
921
954
HAL_NVIC_SetPriority (RTC_Alarm_IRQn , RTC_IRQ_PRIO , RTC_IRQ_SUBPRIO );
922
955
HAL_NVIC_EnableIRQ (RTC_Alarm_IRQn );
923
956
}
957
+ #endif /* RTC_ICSR_BIN */
958
+
924
959
}
925
960
926
961
/**
@@ -1006,7 +1041,7 @@ void RTC_GetAlarm(alarm_t name, uint8_t *day, uint8_t *hours, uint8_t *minutes,
1006
1041
}
1007
1042
#if defined(RTC_SSR_SS )
1008
1043
if (subSeconds != NULL ) {
1009
- if (initMode == MODE_BINARY_MIX ) {
1044
+ if (( initMode == MODE_BINARY_MIX ) || ( initMode == MODE_BINARY_ONLY ) ) {
1010
1045
/*
1011
1046
* The subsecond is the bit SS[14:0] of the ALARM SSR register (not ALARMxINR)
1012
1047
* to be converted in milliseconds
0 commit comments