Skip to content

Commit e0ce4e6

Browse files
committed
Add correct low-power code to RTC/WDT examples
1 parent 350a1db commit e0ce4e6

File tree

5 files changed

+18
-21
lines changed

5 files changed

+18
-21
lines changed

Diff for: libraries/RTC/examples/Example6_LowPower_Alarm/Example6_LowPower_Alarm.ino

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
Author: Adam Garbo and Nathan Seidle
3-
Created: June 3rd, 2020
2+
Author: Adam Garbo
3+
Created: March 27th, 2021
44
License: MIT. See SparkFun Arduino Apollo3 Project for more information
55
66
This example demonstrates how to set an RTC alarm and enter deep sleep.
@@ -88,12 +88,10 @@ void goToSleep()
8888
for (int x = 0 ; x < 50 ; x++)
8989
am_hal_gpio_pinconfig(x, g_AM_HAL_GPIO_DISABLE);
9090

91-
//Power down Flash, SRAM, cache
92-
am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_CACHE); // Turn off CACHE
93-
am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_FLASH_512K); // Turn off everything but lower 512k
94-
am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_SRAM_64K_DTCM); // Turn off everything but lower 64k
95-
//am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_ALL); //Turn off all memory (doesn't recover)
96-
91+
//Power down flash, SRAM, cache
92+
am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_ALL); // Power down all cache and flash (~110 uA)
93+
am_hal_pwrctrl_memory_deepsleep_retain(AM_HAL_PWRCTRL_MEM_SRAM_384K); // Retain all SRAM (~0.6 uA)
94+
9795
// Keep the 32kHz clock running for RTC
9896
am_hal_stimer_config(AM_HAL_STIMER_CFG_CLEAR | AM_HAL_STIMER_CFG_FREEZE);
9997
am_hal_stimer_config(AM_HAL_STIMER_XTAL_32KHZ);
@@ -107,9 +105,6 @@ void goToSleep()
107105
// Power up gracefully
108106
void wakeUp()
109107
{
110-
// Power up SRAM, turn on entire Flash
111-
am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_MAX);
112-
113108
// Go back to using the main clock
114109
am_hal_stimer_config(AM_HAL_STIMER_CFG_CLEAR | AM_HAL_STIMER_CFG_FREEZE);
115110
am_hal_stimer_config(AM_HAL_STIMER_HFRC_3MHZ);

Diff for: libraries/RTC/keywords.txt

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ setAlarm KEYWORD2
2424
setAlarmMode KEYWORD2
2525
attachInterrupt KEYWORD2
2626
detachInterrupt KEYWORD2
27+
clearInterrupt KEYWORD2
2728

2829
weekday KEYWORD2
2930
textWeekday KEYWORD2

Diff for: libraries/RTC/src/RTC.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ void APM3_RTC::detachInterrupt()
213213
am_hal_rtc_int_disable(AM_HAL_RTC_INT_ALM);
214214
}
215215

216+
void Apollo3RTC::clearInterrupt() {
217+
// Clear the RTC alarm interrupt
218+
am_hal_rtc_int_clear(AM_HAL_RTC_INT_ALM);
219+
}
220+
216221
// mthToIndex() converts a string indicating a month to an index value.
217222
// The return value is a value 0-12, with 0-11 indicating the month given
218223
// by the string, and 12 indicating that the string is not a month.

Diff for: libraries/RTC/src/RTC.h

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class APM3_RTC
2121
void setAlarmMode(uint8_t mode); //Set the RTC alarm repeat interval
2222
void attachInterrupt(); //Attach the RTC alarm interrupt
2323
void detachInterrupt(); //Detach the RTC alarm interrupt
24+
void clearInterrupt(); //Clear RTC alarm interrupt
2425

2526
uint32_t weekday; //0 to 6 representing the day of the week
2627
uint32_t century;

Diff for: libraries/WDT/examples/Example3_WDT_LowPower/Example3_WDT_LowPower.ino

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Author: Adam Garbo
3-
Created: August 1st, 2020
3+
Created: March 27th, 2021
44
License: MIT. See SparkFun Arduino Apollo3 Project for more information
55
66
This example demonstrates the combined use of the Artemis Watchdog Timer (WDT)
@@ -106,12 +106,10 @@ void goToSleep()
106106
for (int x = 0 ; x < 50 ; x++)
107107
am_hal_gpio_pinconfig(x, g_AM_HAL_GPIO_DISABLE);
108108

109-
//Power down Flash, SRAM, cache
110-
am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_CACHE); // Turn off CACHE
111-
am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_FLASH_512K); // Turn off everything but lower 512k
112-
am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_SRAM_64K_DTCM); // Turn off everything but lower 64k
113-
//am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_ALL); //Turn off all memory (doesn't recover)
114-
109+
//Power down flash, SRAM, cache
110+
am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_ALL); // Power down all cache and flash (~110 uA)
111+
am_hal_pwrctrl_memory_deepsleep_retain(AM_HAL_PWRCTRL_MEM_SRAM_384K); // Retain all SRAM (~0.6 uA)
112+
115113
// Keep the 32kHz clock running for RTC
116114
am_hal_stimer_config(AM_HAL_STIMER_CFG_CLEAR | AM_HAL_STIMER_CFG_FREEZE);
117115
am_hal_stimer_config(AM_HAL_STIMER_XTAL_32KHZ);
@@ -125,9 +123,6 @@ void goToSleep()
125123
// Power up gracefully
126124
void wakeUp()
127125
{
128-
// Power up SRAM, turn on entire Flash
129-
am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_MAX);
130-
131126
// Go back to using the main clock
132127
am_hal_stimer_config(AM_HAL_STIMER_CFG_CLEAR | AM_HAL_STIMER_CFG_FREEZE);
133128
am_hal_stimer_config(AM_HAL_STIMER_HFRC_3MHZ);

0 commit comments

Comments
 (0)