@@ -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 );
@@ -835,7 +835,8 @@ void RTC_StartAlarm(alarm_t name, uint8_t day, uint8_t hours, uint8_t minutes, u
835
835
{
836
836
RTC_AlarmStructure .AlarmSubSecondMask = predivSync_bits << RTC_ALRMASSR_MASKSS_Pos ;
837
837
}
838
- if (initMode == MODE_BINARY_MIX ) {
838
+ /* in MIX or BCD Mode, the subsecond param is a nb of milliseconds */
839
+ if ((initMode == MODE_BINARY_MIX ) || (initMode == MODE_BINARY_NONE )) {
839
840
/* the subsecond is the millisecond to be converted in a subsecond downcounter value */
840
841
RTC_AlarmStructure .AlarmTime .SubSeconds = UINT32_MAX - ((subSeconds * fqce_apre ) / 1000 + 1 );
841
842
} else {
@@ -886,7 +887,7 @@ void RTC_StartAlarm(alarm_t name, uint8_t day, uint8_t hours, uint8_t minutes, u
886
887
HAL_NVIC_SetPriority (RTC_Alarm_IRQn , RTC_IRQ_PRIO , RTC_IRQ_SUBPRIO );
887
888
HAL_NVIC_EnableIRQ (RTC_Alarm_IRQn );
888
889
#if defined(RTC_ICSR_BIN )
889
- } else if (RtcHandle . Init . BinMode != RTC_BINARY_NONE ) {
890
+ } else if (( initMode == MODE_BINARY_MIX ) || ( initMode == MODE_BINARY_ONLY ) ) {
890
891
/* We have an SubSecond alarm to set in RTC_BINARY_MIX or RTC_BINARY_ONLY mode */
891
892
#else
892
893
} else {
@@ -913,6 +914,36 @@ void RTC_StartAlarm(alarm_t name, uint8_t day, uint8_t hours, uint8_t minutes, u
913
914
RTC_AlarmStructure .AlarmTime .SubSeconds = UINT32_MAX - (subSeconds * fqce_apre ) / 1000 ;
914
915
}
915
916
917
+ #else
918
+ UNUSED (subSeconds );
919
+ #endif /* RTC_SSR_SS */
920
+ /* Set RTC_Alarm */
921
+ HAL_RTC_SetAlarm_IT (& RtcHandle , & RTC_AlarmStructure , RTC_FORMAT_BIN );
922
+ HAL_NVIC_SetPriority (RTC_Alarm_IRQn , RTC_IRQ_PRIO , RTC_IRQ_SUBPRIO );
923
+ HAL_NVIC_EnableIRQ (RTC_Alarm_IRQn );
924
+ #if defined(RTC_ICSR_BIN )
925
+ } else {
926
+ /* We have an SubSecond alarm to set in BCD (RTC_BINARY_NONE) mode */
927
+ #if defined(RTC_SSR_SS )
928
+ {
929
+ #if defined(RTC_ALRMASSR_SSCLR )
930
+ RTC_AlarmStructure .BinaryAutoClr = RTC_ALARMSUBSECONDBIN_AUTOCLR_NO ;
931
+ #endif /* RTC_ALRMASSR_SSCLR */
932
+ RTC_AlarmStructure .AlarmMask = RTC_ALARMMASK_ALL ;
933
+
934
+ #ifdef RTC_ALARM_B
935
+ if (name == ALARM_B ) {
936
+ /* Expecting RTC_ALARMSUBSECONDBINMASK_NONE for the subsecond mask on ALARM B */
937
+ RTC_AlarmStructure .AlarmSubSecondMask = mask << RTC_ALRMBSSR_MASKSS_Pos ;
938
+ } else
939
+ #endif
940
+ {
941
+ /* Expecting RTC_ALARMSUBSECONDBINMASK_NONE for the subsecond mask on ALARM A */
942
+ RTC_AlarmStructure .AlarmSubSecondMask = mask << RTC_ALRMASSR_MASKSS_Pos ;
943
+ }
944
+ RTC_AlarmStructure .AlarmTime .SubSeconds = subSeconds * fqce_apre / 1000 ;
945
+ }
946
+
916
947
#else
917
948
UNUSED (subSeconds );
918
949
#endif /* RTC_SSR_SS */
@@ -921,6 +952,8 @@ void RTC_StartAlarm(alarm_t name, uint8_t day, uint8_t hours, uint8_t minutes, u
921
952
HAL_NVIC_SetPriority (RTC_Alarm_IRQn , RTC_IRQ_PRIO , RTC_IRQ_SUBPRIO );
922
953
HAL_NVIC_EnableIRQ (RTC_Alarm_IRQn );
923
954
}
955
+ #endif /* RTC_ICSR_BIN */
956
+
924
957
}
925
958
926
959
/**
@@ -1006,7 +1039,7 @@ void RTC_GetAlarm(alarm_t name, uint8_t *day, uint8_t *hours, uint8_t *minutes,
1006
1039
}
1007
1040
#if defined(RTC_SSR_SS )
1008
1041
if (subSeconds != NULL ) {
1009
- if (initMode == MODE_BINARY_MIX ) {
1042
+ if (( initMode == MODE_BINARY_MIX ) || ( initMode == MODE_BINARY_ONLY ) ) {
1010
1043
/*
1011
1044
* The subsecond is the bit SS[14:0] of the ALARM SSR register (not ALARMxINR)
1012
1045
* to be converted in milliseconds
0 commit comments