Skip to content

fix wake lockup and bus stall #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/RTCZero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,13 @@ void RTCZero::standbyMode()
{
// Entering standby mode when connected
// via the native USB port causes issues.
// Disable systick interrupt: See https://www.avrfreaks.net/forum/samd21-samd21e16b-sporadically-locks-and-does-not-wake-standby-sleep-mode
SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
__DSB();
__WFI();
// Enable systick interrupt
SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk;
}

/*
Expand Down Expand Up @@ -405,9 +409,22 @@ void RTCZero::setAlarmEpoch(uint32_t ts)

time_t t = ts;
struct tm* tmp = gmtime(&t);
RTC_MODE2_CLOCK_Type alarmTime;

setAlarmDate(tmp->tm_mday, tmp->tm_mon + 1, tmp->tm_year - EPOCH_TIME_YEAR_OFF);
setAlarmTime(tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
alarmTime.bit.YEAR = tmp->tm_year - EPOCH_TIME_YEAR_OFF;
alarmTime.bit.MONTH = tmp->tm_mon + 1;
alarmTime.bit.DAY = tmp->tm_mday;
alarmTime.bit.HOUR = tmp->tm_hour;
alarmTime.bit.MINUTE = tmp->tm_min;
alarmTime.bit.SECOND = tmp->tm_sec;

RTC->MODE2.Mode2Alarm[0].ALARM.reg = alarmTime.reg;

while (RTCisSyncing())
;

// setAlarmDate(tmp->tm_mday, tmp->tm_mon + 1, tmp->tm_year - EPOCH_TIME_YEAR_OFF);
// setAlarmTime(tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
}
}

Expand Down