From ca0565835a87e8773c71eb82da3f53b8ae498fcf Mon Sep 17 00:00:00 2001 From: Steven Slupsky Date: Thu, 23 May 2019 13:02:16 -0600 Subject: [PATCH 1/2] fix wake lockup and bus stall --- src/RTCZero.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/RTCZero.cpp b/src/RTCZero.cpp index e00fba2..827e40e 100644 --- a/src/RTCZero.cpp +++ b/src/RTCZero.cpp @@ -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; } /* @@ -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); } } From 1381b182243b0d1c65f32ab2ae3048e008059d55 Mon Sep 17 00:00:00 2001 From: Steven Slupsky Date: Fri, 24 May 2019 11:51:54 -0600 Subject: [PATCH 2/2] fix formatting --- src/RTCZero.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/RTCZero.cpp b/src/RTCZero.cpp index 827e40e..94329a8 100644 --- a/src/RTCZero.cpp +++ b/src/RTCZero.cpp @@ -147,13 +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; + // 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; + // Enable systick interrupt + SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk; } /* @@ -423,8 +423,6 @@ void RTCZero::setAlarmEpoch(uint32_t ts) 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); } }