@@ -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,104 @@ void RTC_Alarm_IRQHandler(void)
731
733
HAL_RTC_AlarmIRQHandler (& RtcHandle );
732
734
}
733
735
736
+ /**
737
+ * @brief Attach Seconds interrupt callback.
738
+ * @note stm32F1 has a second interrupt capability
739
+ * other MCUs map this on their WakeUp feature
740
+ * @param func: pointer to the callback
741
+ * @retval None
742
+ */
743
+ void attachSecondsIrqCallback (voidCallbackPtr func )
744
+ {
745
+ RTCSecondsIrqCallback = func ;
746
+
747
+ #if defined(STM32F1xx )
748
+ HAL_RTCEx_SetSecond_IT (& RtcHandle );
749
+ __HAL_RTC_SECOND_CLEAR_FLAG (& RtcHandle , RTC_FLAG_SEC );
750
+ #else
751
+ /* for MCUs using the wakeup feature : irq each second */
752
+ HAL_RTCEx_SetWakeUpTimer_IT (& RtcHandle , 0 , RTC_WAKEUPCLOCK_CK_SPRE_16BITS );
753
+ #endif /* STM32F1xx */
754
+
755
+ /* enable the IRQ that will trig the one-second interrupt */
756
+ HAL_NVIC_EnableIRQ (ONESECOND_IRQn );
757
+ }
758
+
759
+ /**
760
+ * @brief Detach Seconds interrupt callback.
761
+ * @param None
762
+ * @retval None
763
+ */
764
+ void detachSecondsIrqCallback (void )
765
+ {
766
+ #if defined(STM32F1xx )
767
+ HAL_RTCEx_DeactivateSecond (& RtcHandle );
768
+ #else
769
+ /* for MCUs using the wakeup feature */
770
+ HAL_RTCEx_DeactivateWakeUpTimer (& RtcHandle );
771
+ #endif /* STM32F1xx */
772
+ RTCSecondsIrqCallback = NULL ;
773
+ }
774
+
775
+ #if defined(STM32F1xx )
776
+ /**
777
+ * @brief Seconds interrupt callback.
778
+ * @param hrtc RTC handle
779
+ * @retval None
780
+ */
781
+ void HAL_RTCEx_RTCEventCallback (RTC_HandleTypeDef * hrtc )
782
+ {
783
+ UNUSED (hrtc );
784
+
785
+ if (RTCSecondsIrqCallback != NULL ) {
786
+ RTCSecondsIrqCallback (NULL );
787
+ }
788
+ }
789
+ #else
790
+ /**
791
+ * @brief WakeUp event mapping the Seconds interrupt callback.
792
+ * @param hrtc RTC handle
793
+ * @retval None
794
+ */
795
+ void HAL_RTCEx_WakeUpTimerEventCallback (RTC_HandleTypeDef * hrtc )
796
+ {
797
+ UNUSED (hrtc );
798
+
799
+ if (RTCSecondsIrqCallback != NULL ) {
800
+ RTCSecondsIrqCallback (NULL );
801
+ }
802
+ }
803
+
804
+ #endif /* STM32F1xx */
805
+
806
+ #if defined(STM32F1xx )
807
+ /**
808
+ * @brief This function handles RTC Seconds interrupt request.
809
+ * @param None
810
+ * @retval None
811
+ */
812
+ void RTC_IRQHandler (void )
813
+ {
814
+ HAL_RTCEx_RTCIRQHandler (& RtcHandle );
815
+
816
+ }
817
+ #else
818
+ /**
819
+ * @brief This function handles RTC Seconds through wakeup interrupt request.
820
+ * @param None
821
+ * @retval None
822
+ */
823
+ void RTC_WKUP_IRQHandler (void )
824
+ {
825
+ HAL_RTCEx_WakeUpTimerIRQHandler (& RtcHandle );
826
+
827
+ }
828
+
829
+ #endif /* STM32F1xx */
830
+
831
+ #ifdef __cplusplus
832
+ }
833
+ #endif
734
834
#ifdef __cplusplus
735
835
}
736
836
#endif
0 commit comments