High current draw in STOP mode when RTC Alarm has been used
We have a very weird behavior in a battery powered IoT device. We should have a very low STOP mode current draw of 1.4 uA @ 3 VCC. The problem is, as soon as we use the RTC Alarm just once and although the alarm already fired during NORMAL operation, the current consumption is ~20 uA in STOP mode. The use of the wake up feature of the RTC does not cause this behavior, it's just alarms. Here is an example to reproduce this:
// Globals
volatile int alarmVal = 0;
void HAL_RTC_AlarmAEventCallback( RTC_HandleTypeDef *hrtc ) {
alarmVal = 1;
}
// Event Loop
while(1) {
RTC_AlarmTypeDef alarm;
RTC_TimeTypeDef ts;
RTC_DateTypeDef ds;
// Disable Alarm
HAL_RTC_DeactivateAlarm(&hrtc, RTC_ALARM_A); // Disable Interrupt
__HAL_RTC_ALARM_CLEAR_FLAG(&hrtc, RTC_FLAG_ALRAF); // Clear Flag (RTC ALARM A)
__HAL_RTC_ALARM_EXTI_CLEAR_FLAG(); // Clear Flag (EXTI)
// Get Time
do {
HAL_RTC_GetTime(&hrtc, &ts, FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &ds, FORMAT_BIN);
} while(ts.Seconds == 59); // cheat: Increment second without care of real clock
// Set Alarm
alarm.AlarmTime.SubSeconds = ts.SubSeconds; // 210
alarm.AlarmSubSecondMask = 8 << RTC_ALRMASSR_MASKSS_Pos; // 0x8000000
alarm.AlarmTime.Seconds = ts.Seconds + 1; // 27
alarm.AlarmTime.Minutes = ts.Minutes; // 0
alarm.AlarmTime.Hours = ts.Hours; // 0
alarm.AlarmDateWeekDay = ds.WeekDay; // 1
alarm.AlarmTime.TimeFormat = ts.TimeFormat; // 0
alarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE; // 0
alarm.AlarmMask = RTC_ALARMMASK_NONE; // 0
alarm.Alarm = RTC_ALARM_A; // 0x100
alarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; // 0
alarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET; // 0
HAL_RTC_SetAlarm_IT(&hrtc, &alarm, RTC_FORMAT_BIN);
// Wait Alarm
for(alarmVal = 0; !alarmVal;);
HAL_RTC_DeactivateAlarm(&hrtc, RTC_ALARM_A);
__HAL_RTC_ALARM_CLEAR_FLAG(&hrtc, RTC_FLAG_ALRAF);
__HAL_RTC_ALARM_EXTI_CLEAR_FLAG();
// Stop Mode
HAL_RTC_MspDeInit(&hrtc);
HW_EnterStopMode();
HAL_RTC_MspInit(&hrtc);
}
We are using the LSE clock for the RTC
We have tried multiple ways to de-init the RTC before going to STOP mode but nothing helps.
How can this be explained and resolved?
BG
