@@ -63,8 +63,12 @@ static void *callbackUserData = NULL;
63
63
static voidCallbackPtr RTCUserCallbackB = NULL ;
64
64
static void * callbackUserDataB = NULL ;
65
65
#endif
66
+ #ifdef ONESECOND_IRQn
66
67
static voidCallbackPtr RTCSecondsIrqCallback = NULL ;
67
-
68
+ #endif
69
+ #ifdef STM32WLxx
70
+ static voidCallbackPtr RTCSubSecondsUnderflowIrqCallback = NULL ;
71
+ #endif
68
72
static sourceClock_t clkSrc = LSI_CLOCK ;
69
73
static uint32_t clkVal = LSI_VALUE ;
70
74
static uint8_t HSEDiv = 0 ;
@@ -97,55 +101,6 @@ static inline int _log2(int x)
97
101
}
98
102
99
103
/* Exported functions --------------------------------------------------------*/
100
-
101
- /* HAL MSP function used for RTC_Init */
102
- void HAL_RTC_MspInit (RTC_HandleTypeDef * rtcHandle )
103
- {
104
- #if defined(RTC_SCR_CSSRUF )
105
- if (rtcHandle -> Instance == RTC ) {
106
- /* In BINARY mode (MIX or ONLY), set the SSR Underflow interrupt */
107
- if (rtcHandle -> Init .BinMode != RTC_BINARY_NONE ) {
108
- #if defined(STM32WLxx )
109
- /* Only the STM32WLxx series has a TAMP_STAMP_LSECSS_SSRU_IRQn */
110
- if (HAL_RTCEx_SetSSRU_IT (rtcHandle ) != HAL_OK ) {
111
- Error_Handler ();
112
- }
113
- /* Give init value for the RtcFeatures enable */
114
- rtcHandle -> IsEnabled .RtcFeatures = 0 ;
115
-
116
- /* RTC interrupt Init */
117
- HAL_NVIC_SetPriority (TAMP_STAMP_LSECSS_SSRU_IRQn , 0 , 0 );
118
- HAL_NVIC_EnableIRQ (TAMP_STAMP_LSECSS_SSRU_IRQn );
119
- #else
120
- /* The STM32U5, STM32H5, STM32L4plus have common RTC interrupt and a SSRU flag */
121
- __HAL_RTC_SSRU_ENABLE_IT (rtcHandle , RTC_IT_SSRU );
122
- #endif /* STM32WLxx */
123
- }
124
- }
125
- #else /* RTC_SCR_CSSRUF */
126
- UNUSED (rtcHandle );
127
- #endif /* RTC_SCR_CSSRUF */
128
- /* RTC_Alarm_IRQn is enabled when enabling Alarm */
129
- }
130
-
131
- void HAL_RTC_MspDeInit (RTC_HandleTypeDef * rtcHandle )
132
- {
133
-
134
- if (rtcHandle -> Instance == RTC ) {
135
- /* Peripheral clock disable */
136
- __HAL_RCC_RTC_DISABLE ();
137
- #ifdef __HAL_RCC_RTCAPB_CLK_DISABLE
138
- __HAL_RCC_RTCAPB_CLK_DISABLE ();
139
- #endif
140
- /* RTC interrupt Deinit */
141
- #if defined(STM32WLxx )
142
- /* Only the STM32WLxx series has a TAMP_STAMP_LSECSS_SSRU_IRQn */
143
- HAL_NVIC_DisableIRQ (TAMP_STAMP_LSECSS_SSRU_IRQn );
144
- #endif /* STM32WLxx */
145
- HAL_NVIC_DisableIRQ (RTC_Alarm_IRQn );
146
- }
147
- }
148
-
149
104
/**
150
105
* @brief Get pointer to RTC_HandleTypeDef
151
106
* @param None
@@ -635,14 +590,31 @@ bool RTC_init(hourFormat_t format, binaryMode_t mode, sourceClock_t source, bool
635
590
void RTC_DeInit (bool reset_cb )
636
591
{
637
592
HAL_RTC_DeInit (& RtcHandle );
593
+ /* Peripheral clock disable */
594
+ __HAL_RCC_RTC_DISABLE ();
595
+ #ifdef __HAL_RCC_RTCAPB_CLK_DISABLE
596
+ __HAL_RCC_RTCAPB_CLK_DISABLE ();
597
+ #endif
598
+ HAL_NVIC_DisableIRQ (RTC_Alarm_IRQn );
599
+ #ifdef ONESECOND_IRQn
600
+ HAL_NVIC_DisableIRQ (ONESECOND_IRQn );
601
+ #endif
602
+ #ifdef STM32WLxx
603
+ HAL_NVIC_DisableIRQ (TAMP_STAMP_LSECSS_SSRU_IRQn );
604
+ #endif
638
605
if (reset_cb ) {
639
606
RTCUserCallback = NULL ;
640
607
callbackUserData = NULL ;
641
608
#ifdef RTC_ALARM_B
642
609
RTCUserCallbackB = NULL ;
643
610
callbackUserDataB = NULL ;
644
611
#endif
612
+ #ifdef ONESECOND_IRQn
645
613
RTCSecondsIrqCallback = NULL ;
614
+ #endif
615
+ #ifdef STM32WLxx
616
+ RTCSubSecondsUnderflowIrqCallback = NULL ;
617
+ #endif
646
618
}
647
619
}
648
620
@@ -1260,6 +1232,48 @@ void RTC_WKUP_IRQHandler(void)
1260
1232
#endif /* STM32F1xx */
1261
1233
#endif /* ONESECOND_IRQn */
1262
1234
1235
+ #ifdef STM32WLxx
1236
+ /**
1237
+ * @brief Attach SubSeconds underflow interrupt callback.
1238
+ * @param func: pointer to the callback
1239
+ * @retval None
1240
+ */
1241
+ void attachSubSecondsUnderflowIrqCallback (voidCallbackPtr func )
1242
+ {
1243
+ /* Callback called on SSRU interrupt */
1244
+ RTCSubSecondsUnderflowIrqCallback = func ;
1245
+
1246
+ /* Enable the IRQ that will trig the one-second interrupt */
1247
+ if (HAL_RTCEx_SetSSRU_IT (& RtcHandle ) != HAL_OK ) {
1248
+ Error_Handler ();
1249
+ }
1250
+ HAL_NVIC_SetPriority (TAMP_STAMP_LSECSS_SSRU_IRQn , RTC_IRQ_SSRU_PRIO , RTC_IRQ_SSRU_SUBPRIO );
1251
+ HAL_NVIC_EnableIRQ (TAMP_STAMP_LSECSS_SSRU_IRQn );
1252
+ }
1253
+
1254
+ /**
1255
+ * @brief Detach SubSeconds underflow interrupt callback.
1256
+ * @param None
1257
+ * @retval None
1258
+ */
1259
+ void detachSubSecondsUnderflowIrqCallback (void )
1260
+ {
1261
+ RTCSubSecondsUnderflowIrqCallback = NULL ;
1262
+ if (HAL_RTCEx_DeactivateSSRU (& RtcHandle ) != HAL_OK ) {
1263
+ Error_Handler ();
1264
+ }
1265
+ HAL_NVIC_DisableIRQ (TAMP_STAMP_LSECSS_SSRU_IRQn );
1266
+ }
1267
+
1268
+ void HAL_RTCEx_SSRUEventCallback (RTC_HandleTypeDef * hrtc )
1269
+ {
1270
+ (void )hrtc ;
1271
+ if (RTCSubSecondsUnderflowIrqCallback != NULL ) {
1272
+ RTCSubSecondsUnderflowIrqCallback (NULL );
1273
+ }
1274
+ }
1275
+ #endif /* STM32WLxx */
1276
+
1263
1277
#if defined(STM32F1xx )
1264
1278
void RTC_StoreDate (void )
1265
1279
{
0 commit comments