Skip to content

Commit 7a44bfc

Browse files
committed
stm32duino RTC add a subsecond mask to configure the alarm
configure the Alarm with Second mask --> trigs IRQHandler The Autoclear bit field depends on the RTC ALARM SSR register. Signed-off-by: Francois Ramu <francois.ramu@st.com>
1 parent b0adb67 commit 7a44bfc

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

src/STM32RTC.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ void STM32RTC::enableAlarm(Alarm_Match match, Alarm name)
243243
case MATCH_HHMMSS:
244244
case MATCH_MMSS:
245245
case MATCH_SS:
246+
case MATCH_SUBSEC:
246247
#ifdef RTC_ALARM_B
247248
if (name == ALARM_B) {
248249
RTC_StartAlarm(::ALARM_B, _alarmBDay, _alarmBHours, _alarmBMinutes, _alarmBSeconds,

src/STM32RTC.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class STM32RTC {
9393

9494
enum Alarm_Match : uint8_t {
9595
MATCH_OFF = OFF_MSK, // Never
96+
MATCH_SUBSEC = SUBSEC_MSK, // Every Subsecond
9697
MATCH_SS = SS_MSK, // Every Minute
9798
MATCH_MMSS = SS_MSK | MM_MSK, // Every Hour
9899
MATCH_HHMMSS = SS_MSK | MM_MSK | HH_MSK, // Every Day

src/rtc.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,11 +701,12 @@ void RTC_StartAlarm(alarm_t name, uint8_t day, uint8_t hours, uint8_t minutes, u
701701
period = HOUR_AM;
702702
}
703703

704+
/* Use alarm A by default because it is common to all STM32 HAL */
705+
RTC_AlarmStructure.Alarm = name;
706+
704707
if ((((initFormat == HOUR_FORMAT_24) && IS_RTC_HOUR24(hours)) || IS_RTC_HOUR12(hours))
705708
&& IS_RTC_DATE(day) && IS_RTC_MINUTES(minutes) && IS_RTC_SECONDS(seconds)) {
706709
/* Set RTC_AlarmStructure with calculated values*/
707-
/* Use alarm A by default because it is common to all STM32 HAL */
708-
RTC_AlarmStructure.Alarm = name;
709710
RTC_AlarmStructure.AlarmTime.Seconds = seconds;
710711
RTC_AlarmStructure.AlarmTime.Minutes = minutes;
711712
RTC_AlarmStructure.AlarmTime.Hours = hours;
@@ -761,6 +762,38 @@ void RTC_StartAlarm(alarm_t name, uint8_t day, uint8_t hours, uint8_t minutes, u
761762
UNUSED(mask);
762763
#endif /* !STM32F1xx */
763764

765+
/* Set RTC_Alarm */
766+
HAL_RTC_SetAlarm_IT(&RtcHandle, &RTC_AlarmStructure, RTC_FORMAT_BIN);
767+
HAL_NVIC_SetPriority(RTC_Alarm_IRQn, RTC_IRQ_PRIO, RTC_IRQ_SUBPRIO);
768+
HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);
769+
} else {
770+
/* We have an SubSecond alarm to set in RTC_BINARY_MIX mode */
771+
#if defined(RTC_SSR_SS)
772+
{
773+
#if defined(RTC_ALRMASSR_SSCLR)
774+
RTC_AlarmStructure.BinaryAutoClr = RTC_ALARMSUBSECONDBIN_AUTOCLR_NO;
775+
#endif /* RTC_ALRMASSR_SSCLR */
776+
RTC_AlarmStructure.AlarmMask = RTC_ALARMMASK_NONE;
777+
778+
#ifdef RTC_ALARM_B
779+
if (name == ALARM_B) {
780+
/* Expecting RTC_ALARMSUBSECONDBINMASK_NONE for the subsecond mask on ALARM B */
781+
RTC_AlarmStructure.AlarmMask = RTC_ALARMMASK_ALL;
782+
RTC_AlarmStructure.AlarmSubSecondMask = mask << RTC_ALRMBSSR_MASKSS_Pos;
783+
} else
784+
#endif
785+
{
786+
/* Expecting RTC_ALARMSUBSECONDBINMASK_NONE for the subsecond mask on ALARM A */
787+
RTC_AlarmStructure.AlarmMask = RTC_ALARMMASK_ALL;
788+
RTC_AlarmStructure.AlarmSubSecondMask = mask << RTC_ALRMASSR_MASKSS_Pos;
789+
}
790+
/* Special case for ALARM B configuration for stm32WL Lorawan */
791+
RTC_AlarmStructure.AlarmTime.SubSeconds = subSeconds;
792+
}
793+
794+
#else
795+
UNUSED(subSeconds);
796+
#endif /* RTC_SSR_SS */
764797
/* Set RTC_Alarm */
765798
HAL_RTC_SetAlarm_IT(&RtcHandle, &RTC_AlarmStructure, RTC_FORMAT_BIN);
766799
HAL_NVIC_SetPriority(RTC_Alarm_IRQn, RTC_IRQ_PRIO, RTC_IRQ_SUBPRIO);

src/rtc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ typedef enum {
7676
/* NOTE: STM32 RTC can't assign a month or a year to an alarm. Those enum
7777
are kept for compatibility but are ignored inside enableAlarm(). */
7878
M_MSK = 16,
79-
Y_MSK = 32
79+
Y_MSK = 32,
80+
SUBSEC_MSK = 64
8081
} alarmMask_t;
8182

8283
typedef enum {

0 commit comments

Comments
 (0)