Skip to content

Commit 0541e89

Browse files
committed
configure and set the AlarmB to use in MIX mode
Directly call the RTC functions from the STM32duino RTC library Let the IsEnabled.RtcFeatures be handled by the RTC library
1 parent 0368da7 commit 0541e89

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

src/BSP/timer_if.c

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle)
4646
{
4747
Error_Handler();
4848
}
49+
/* give init value for the RtcFeatures enable */
50+
rtcHandle->IsEnabled.RtcFeatures = 0;
4951

5052
/* RTC interrupt Init */
5153
HAL_NVIC_SetPriority(TAMP_STAMP_LSECSS_SSRU_IRQn, 0, 0);
@@ -224,17 +226,8 @@ UTIL_TIMER_Status_t TIMER_IF_Init(void)
224226
/* USER CODE END TIMER_IF_Init */
225227
if (RTC_Initialized == false)
226228
{
227-
/* RTC is already Initialized by the LoRaWan::begin */
228-
RtcHandle.IsEnabled.RtcFeatures = UINT32_MAX;
229-
230-
/** Enable the Alarm B just after the HAL_RTC_Init */
231-
RTC_StartAlarm(RTC_ALARM_B, 0, 0, 0, 0, 0, RTC_HOURFORMAT12_PM, 32UL);
232-
233-
/*Stop Timer */
234-
TIMER_IF_StopTimer();
235-
236-
/*overload RTC feature enable*/
237-
RtcHandle.IsEnabled.RtcFeatures = UINT32_MAX;
229+
/*Stop Timer : Disable the Alarm B interrupt */
230+
RTC_StopAlarm(RTC_ALARM_B);
238231

239232
/*Initialize MSB ticks*/
240233
TIMER_IF_BkUp_Write_MSBticks(0);
@@ -259,13 +252,15 @@ UTIL_TIMER_Status_t TIMER_IF_StartTimer(uint32_t timeout)
259252
/* USER CODE BEGIN TIMER_IF_StartTimer */
260253

261254
/* USER CODE END TIMER_IF_StartTimer */
255+
262256
/*Stop timer if one is already started*/
263-
TIMER_IF_StopTimer();
257+
RTC_StopAlarm(RTC_ALARM_B);
258+
264259
timeout += RtcTimerContext;
265260

266-
TIMER_IF_DBG_PRINTF("Start timer: time=%d, alarm=%d\n\r", GetTimerTicks(), timeout);
261+
TIMER_IF_DBG_PRINTF("Start timer: time=%d, alarm=%d\n\r", GetTimerTicks(), timeout);
267262

268-
/* Program ALARM B on subsecond, mask is 32 (and fixed to RTC_ALARMMASK_NONE for calendar) */
263+
/* Program ALARM B on subsecond, mask is 32 (and fixed to RTC_ALARMMASK_ALL for calendar) */
269264
RTC_StartAlarm(RTC_ALARM_B, 0, 0, 0, 0, UINT32_MAX - timeout, RTC_HOURFORMAT12_PM, 32UL);
270265

271266
/* USER CODE BEGIN TIMER_IF_StartTimer_Last */
@@ -284,8 +279,6 @@ UTIL_TIMER_Status_t TIMER_IF_StopTimer(void)
284279
/* Disable the Alarm B interrupt */
285280
RTC_StopAlarm(RTC_ALARM_B);
286281

287-
/*overload RTC feature enable*/
288-
RtcHandle.IsEnabled.RtcFeatures = UINT32_MAX;
289282
/* USER CODE BEGIN TIMER_IF_StopTimer_Last */
290283

291284
/* USER CODE END TIMER_IF_StopTimer_Last */

0 commit comments

Comments
 (0)