Skip to content

Commit 35da749

Browse files
committed
export the RTC Handle as a global
Set the subsecond for the alarm value. Add the HAL_MSP_Init/DeInit function from the rtc library. Signed-off-by: Francois Ramu <[email protected]>
1 parent 2ea1ffc commit 35da749

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

src/rtc.c

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ extern "C" {
5656
/* Private define ------------------------------------------------------------*/
5757
/* Private macro -------------------------------------------------------------*/
5858
/* Private variables ---------------------------------------------------------*/
59-
static RTC_HandleTypeDef RtcHandle = {0};
6059
static voidCallbackPtr RTCUserCallback = NULL;
6160
static void *callbackUserData = NULL;
6261
#ifdef RTC_ALARM_B
@@ -94,8 +93,56 @@ static inline int _log2(int x)
9493
return (x > 0) ? (sizeof(int) * 8 - __builtin_clz(x) - 1) : 0;
9594
}
9695

96+
/* Exported variable --------------------------------------------------------*/
97+
RTC_HandleTypeDef RtcHandle = {0};
98+
9799
/* Exported functions --------------------------------------------------------*/
98100

101+
/* HAL MSP function used for RTC_Init */
102+
void HAL_RTC_MspInit(RTC_HandleTypeDef *rtcHandle)
103+
{
104+
#if defined(STM32WLxx)
105+
/* Only the STM32WLxx series has a TAMP_STAMP_LSECSS_SSRU_IRQn */
106+
if (rtcHandle->Instance == RTC)
107+
{
108+
if (HAL_RTCEx_SetSSRU_IT(rtcHandle) != HAL_OK) {
109+
Error_Handler();
110+
}
111+
/* Give init value for the RtcFeatures enable */
112+
rtcHandle->IsEnabled.RtcFeatures = 0;
113+
114+
/* RTC interrupt Init */
115+
HAL_NVIC_SetPriority(TAMP_STAMP_LSECSS_SSRU_IRQn, 0, 0);
116+
HAL_NVIC_EnableIRQ(TAMP_STAMP_LSECSS_SSRU_IRQn);
117+
118+
}
119+
#else
120+
UNUSED(rtcHandle);
121+
#endif /* STM32WLxx */
122+
/* RTC_Alarm_IRQn is enabled when enabling Alarm */
123+
}
124+
125+
void HAL_RTC_MspDeInit(RTC_HandleTypeDef *rtcHandle)
126+
{
127+
128+
if (rtcHandle->Instance == RTC)
129+
{
130+
/* USER CODE BEGIN RTC_MspDeInit 0 */
131+
132+
/* USER CODE END RTC_MspDeInit 0 */
133+
/* Peripheral clock disable */
134+
__HAL_RCC_RTC_DISABLE();
135+
__HAL_RCC_RTCAPB_CLK_DISABLE();
136+
137+
/* RTC interrupt Deinit */
138+
HAL_NVIC_DisableIRQ(TAMP_STAMP_LSECSS_SSRU_IRQn);
139+
HAL_NVIC_DisableIRQ(RTC_Alarm_IRQn);
140+
/* USER CODE BEGIN RTC_MspDeInit 1 */
141+
142+
/* USER CODE END RTC_MspDeInit 1 */
143+
}
144+
}
145+
99146
/**
100147
* @brief Set RTC clock source
101148
* @param source: RTC clock source: LSE, LSI or HSE
@@ -737,7 +784,7 @@ void RTC_GetDate(uint8_t *year, uint8_t *month, uint8_t *day, uint8_t *wday)
737784
*/
738785
void RTC_StartAlarm(alarm_t name, uint8_t day, uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, hourAM_PM_t period, uint8_t mask)
739786
{
740-
RTC_AlarmTypeDef RTC_AlarmStructure;
787+
RTC_AlarmTypeDef RTC_AlarmStructure = {0};
741788

742789
/* Ignore time AM PM configuration if in 24 hours format */
743790
if (initFormat == HOUR_FORMAT_24) {

0 commit comments

Comments
 (0)