11/*
22 Author: Adam Garbo
3- Created: February 1st , 2021
3+ Created: March 26 , 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)
99 Both RTC and WDT interrupts will wake the system, print the date and time,
1010 and then re-enter deep sleep.
1111
12- The WDT is configured to trigger every 10 seconds. If the WDT is not "pet"
12+ The WDT is configured to trigger every 10 seconds. If the WDT is not "pet"
1313 after 100 seconds, a system reset will be triggered.
14-
15- The RTC alarm is configured to trigger every minute and enter deep sleep
14+
15+ The RTC alarm is configured to trigger every minute and enter deep sleep
1616 between interrupts. Alarm interuptswill also restart the WDT and reset
1717 the watchdog interrput counter.
1818*/
@@ -104,11 +104,9 @@ void goToSleep()
104104 for (int x = 0 ; x < 50 ; x++)
105105 am_hal_gpio_pinconfig (x, g_AM_HAL_GPIO_DISABLE);
106106
107- // Power down Flash, SRAM, cache
108- am_hal_pwrctrl_memory_deepsleep_powerdown (AM_HAL_PWRCTRL_MEM_CACHE); // Turn off CACHE
109- am_hal_pwrctrl_memory_deepsleep_powerdown (AM_HAL_PWRCTRL_MEM_FLASH_512K); // Turn off everything but lower 512k
110- // am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_SRAM_64K_DTCM); // Turn off everything but lower 64k
111- // am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_ALL); //Turn off all memory (doesn't recover)
107+ // Power down CACHE, flashand SRAM
108+ am_hal_pwrctrl_memory_deepsleep_powerdown (AM_HAL_PWRCTRL_MEM_ALL); // Turn off CACHE and flash
109+ am_hal_pwrctrl_memory_deepsleep_retain (AM_HAL_PWRCTRL_MEM_SRAM_384K); // Retain all SRAM (0.6 uA)
112110
113111 // Keep the 32kHz clock running for RTC
114112 am_hal_stimer_config (AM_HAL_STIMER_CFG_CLEAR | AM_HAL_STIMER_CFG_FREEZE);
@@ -123,9 +121,6 @@ void goToSleep()
123121// Power up gracefully
124122void wakeUp ()
125123{
126- // Power up SRAM, turn on entire Flash
127- am_hal_pwrctrl_memory_deepsleep_powerdown (AM_HAL_PWRCTRL_MEM_MAX);
128-
129124 // Go back to using the main clock
130125 am_hal_stimer_config (AM_HAL_STIMER_CFG_CLEAR | AM_HAL_STIMER_CFG_FREEZE);
131126 am_hal_stimer_config (AM_HAL_STIMER_HFRC_3MHZ);
@@ -136,10 +131,10 @@ void wakeUp()
136131
137132 // Renable power to UART0
138133 am_hal_pwrctrl_periph_enable (AM_HAL_PWRCTRL_PERIPH_UART0);
139-
134+
140135 // Enable ADC
141136 initializeADC ();
142-
137+
143138 // Enable ADC
144139 initializeADC ();
145140
@@ -168,7 +163,7 @@ extern "C" void am_watchdog_isr(void)
168163 wdt.restart (); // "Pet" the dog
169164 }
170165 else {
171- digitalWrite (LED_BUILTIN, HIGH ); // Visual indication of system reset trigger
166+ while ( 1 ); // Wait for reset to occur
172167 }
173168
174169 watchdogFlag = true ; // Set the watchdog flag
0 commit comments