application: add mechanism to remain in standby
This commit is contained in:
parent
34f6b52969
commit
27d97f565c
|
@ -37,6 +37,7 @@
|
|||
#include <libopencm3/stm32/dbgmcu.h> // debug utilities
|
||||
#include <libopencm3/stm32/desig.h> // design utilities
|
||||
#include <libopencm3/stm32/flash.h> // flash utilities
|
||||
#include <libopencm3/stm32/f1/bkp.h> // access to backup registers
|
||||
|
||||
/* own libraries */
|
||||
#include "global.h" // board definitions
|
||||
|
@ -1221,9 +1222,21 @@ void main(void)
|
|||
DBGMCU_CR |= DBGMCU_CR_STOP; // allow debug also in stop mode (keep clock powered)
|
||||
DBGMCU_CR |= DBGMCU_CR_SLEEP; // allow debug also in sleep mode (keep clock powered)
|
||||
#else
|
||||
RCC_APB1ENR |= RCC_APB1ENR_BKPEN | RCC_APB1ENR_PWREN; // enable access to power register
|
||||
if (RCC_CSR & RCC_CSR_IWDGRSTF && 0x22 == BKP_DR1) { // we have been woken up by independent watchdog but actually want to stay in standby mode
|
||||
RCC_CSR |= RCC_CSR_RMVF; // clear reset flags
|
||||
// the reset will have clearer the software set watchdog
|
||||
while (true) { // go to standby
|
||||
SCB_SCR |= SCB_SCR_SLEEPDEEP; // Cortex-M3 standby setting
|
||||
pwr_set_standby_mode(); // power setting
|
||||
pwr_clear_wakeup_flag(); // clear wake-up flag to be able to sleep
|
||||
__WFI(); // go to standby (e.g. shut down)
|
||||
}
|
||||
}
|
||||
// setup watchdog to reset in case we get stuck (i.e. when an error occurred)
|
||||
iwdg_set_period_ms(WATCHDOG_PERIOD); // set independent watchdog period
|
||||
iwdg_start(); // start independent watchdog
|
||||
BKP_DR1 = 0; // clear backup register to not indicate we want to stay in stand by
|
||||
#endif
|
||||
|
||||
board_setup(); // setup board
|
||||
|
@ -1335,6 +1348,9 @@ void main(void)
|
|||
rtc_internal_tick_flag = false; // reset flag
|
||||
action = true; // action has been performed
|
||||
while (!interactive && rtc_get_counter_val() >= last_connect_time + SHUTDOWN_TIMEOUT) { // time to shut down
|
||||
#if !DEBUG
|
||||
BKP_DR1 = 0x22; // indicate we want to stay in standby mode
|
||||
#endif
|
||||
display_off(); // cut power to displays (at stop D+ pull-up to indicate disconnect)
|
||||
SCB_SCR |= SCB_SCR_SLEEPDEEP; // Cortex-M3 standby setting
|
||||
pwr_set_standby_mode(); // power setting
|
||||
|
|
Loading…
Reference in New Issue