@@ -58,6 +58,7 @@ extern "C" {
58
58
static RTC_HandleTypeDef RtcHandle = {0 };
59
59
static voidCallbackPtr RTCUserCallback = NULL ;
60
60
static void * callbackUserData = NULL ;
61
+ static voidCallbackPtr RTCSecondsIrqCallback = NULL ;
61
62
62
63
static sourceClock_t clkSrc = LSI_CLOCK ;
63
64
static uint8_t HSEDiv = 0 ;
@@ -388,6 +389,7 @@ void RTC_DeInit(void)
388
389
HAL_RTC_DeInit (& RtcHandle );
389
390
RTCUserCallback = NULL ;
390
391
callbackUserData = NULL ;
392
+ RTCSecondsIrqCallback = NULL ;
391
393
}
392
394
393
395
/**
@@ -731,6 +733,107 @@ void RTC_Alarm_IRQHandler(void)
731
733
HAL_RTC_AlarmIRQHandler (& RtcHandle );
732
734
}
733
735
736
+ #ifdef ONESECOND_IRQn
737
+ /**
738
+ * @brief Attach Seconds interrupt callback.
739
+ * @note stm32F1 has a second interrupt capability
740
+ * other MCUs map this on their WakeUp feature
741
+ * @param func: pointer to the callback
742
+ * @retval None
743
+ */
744
+ void attachSecondsIrqCallback (voidCallbackPtr func )
745
+ {
746
+ #if defined(STM32F1xx )
747
+ /* callback called on Seconds interrupt */
748
+ RTCSecondsIrqCallback = func ;
749
+
750
+ HAL_RTCEx_SetSecond_IT (& RtcHandle );
751
+ __HAL_RTC_SECOND_CLEAR_FLAG (& RtcHandle , RTC_FLAG_SEC );
752
+ #else
753
+ /* callback called on wakeUp interrupt for One-Second purpose*/
754
+ RTCSecondsIrqCallback = func ;
755
+
756
+ /* for MCUs using the wakeup feature : irq each second */
757
+ #if defined(RTC_WUTR_WUTOCLR )
758
+ HAL_RTCEx_SetWakeUpTimer_IT (& RtcHandle , 0 , RTC_WAKEUPCLOCK_CK_SPRE_16BITS , 0 );
759
+ #else
760
+ HAL_RTCEx_SetWakeUpTimer_IT (& RtcHandle , 0 , RTC_WAKEUPCLOCK_CK_SPRE_16BITS );
761
+ #endif /* RTC_WUTR_WUTOCLR */
762
+
763
+ #endif /* STM32F1xx */
764
+ /* enable the IRQ that will trig the one-second interrupt */
765
+ HAL_NVIC_EnableIRQ (ONESECOND_IRQn );
766
+ }
767
+
768
+ /**
769
+ * @brief Detach Seconds interrupt callback.
770
+ * @param None
771
+ * @retval None
772
+ */
773
+ void detachSecondsIrqCallback (void )
774
+ {
775
+ #if defined(STM32F1xx )
776
+ HAL_RTCEx_DeactivateSecond (& RtcHandle );
777
+ #else
778
+ /* for MCUs using the wakeup feature : do not deactivate the WakeUp
779
+ as it might be used for another reason than the One-Second purpose */
780
+ // HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle);
781
+ #endif /* STM32F1xx */
782
+ RTCSecondsIrqCallback = NULL ;
783
+ }
784
+
785
+ #if defined(STM32F1xx )
786
+ /**
787
+ * @brief Seconds interrupt callback.
788
+ * @param hrtc RTC handle
789
+ * @retval None
790
+ */
791
+ void HAL_RTCEx_RTCEventCallback (RTC_HandleTypeDef * hrtc )
792
+ {
793
+ UNUSED (hrtc );
794
+
795
+ if (RTCSecondsIrqCallback != NULL ) {
796
+ RTCSecondsIrqCallback (NULL );
797
+ }
798
+ }
799
+
800
+ /**
801
+ * @brief This function handles RTC Seconds interrupt request.
802
+ * @param None
803
+ * @retval None
804
+ */
805
+ void RTC_IRQHandler (void )
806
+ {
807
+ HAL_RTCEx_RTCIRQHandler (& RtcHandle );
808
+ }
809
+
810
+ #else
811
+ /**
812
+ * @brief WakeUp event mapping the Seconds interrupt callback.
813
+ * @param hrtc RTC handle
814
+ * @retval None
815
+ */
816
+ void HAL_RTCEx_WakeUpTimerEventCallback (RTC_HandleTypeDef * hrtc )
817
+ {
818
+ UNUSED (hrtc );
819
+
820
+ if (RTCSecondsIrqCallback != NULL ) {
821
+ RTCSecondsIrqCallback (NULL );
822
+ }
823
+ }
824
+
825
+ /**
826
+ * @brief This function handles RTC Seconds through wakeup interrupt request.
827
+ * @param None
828
+ * @retval None
829
+ */
830
+ void RTC_WKUP_IRQHandler (void )
831
+ {
832
+ HAL_RTCEx_WakeUpTimerIRQHandler (& RtcHandle );
833
+ }
834
+ #endif /* STM32F1xx */
835
+ #endif /* ONESECOND_IRQn */
836
+
734
837
#ifdef __cplusplus
735
838
}
736
839
#endif
0 commit comments