Stop & wakeup working on rising edge (#3747)

* Stop & wakeup working on rising edge

* Standby & Sleep mode working Using PA0 only.

* Stop & standby works with wake from PA0.
Added alternative interrupt method to STOP

* Removed hand screwery on registers
This commit is contained in:
NMSTEC 2022-01-07 13:46:28 -08:00 committed by GitHub
parent 4ee1a6b751
commit 1bde061b2d
1 changed files with 17 additions and 19 deletions

View File

@ -177,10 +177,16 @@ void sys_dual_bank(void) {
void stm32_stop() { void stm32_stop() {
SysTick->CTRL = 0; SysTick->CTRL = 0;
__disable_irq(); SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
RCC->AHB1RSTR = RCC_AHB1RSTR_GPIOERST; enginePins.errorLedPin.setValue(0);
enginePins.runningLedPin.setValue(0);
enginePins.communicationLedPin.setValue(0);
enginePins.warningLedPin.setValue(0);
// configure mode bits
palEnableLineEvent(PAL_LINE(GPIOA, 0), PAL_EVENT_MODE_RISING_EDGE);
PWR->CSR1 |= PWR_CSR1_WUIF;
PWR->CR1 &= ~PWR_CR1_PDDS; // cleared PDDS means stop mode (not standby) PWR->CR1 &= ~PWR_CR1_PDDS; // cleared PDDS means stop mode (not standby)
PWR->CR1 |= PWR_CR1_FPDS; // turn off flash in stop mode PWR->CR1 |= PWR_CR1_FPDS; // turn off flash in stop mode
PWR->CR1 |= PWR_CR1_UDEN; // regulator underdrive in stop mode PWR->CR1 |= PWR_CR1_UDEN; // regulator underdrive in stop mode
@ -188,9 +194,8 @@ void stm32_stop() {
PWR->CR1 |= PWR_CR1_LPDS; // regulator in low power mode PWR->CR1 |= PWR_CR1_LPDS; // regulator in low power mode
// enable Deepsleep mode // enable Deepsleep mode
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; __disable_irq();
__WFI();
__WFE();
// Lastly, reboot // Lastly, reboot
NVIC_SystemReset(); NVIC_SystemReset();
@ -198,18 +203,11 @@ void stm32_stop() {
void stm32_standby() { void stm32_standby() {
SysTick->CTRL = 0; SysTick->CTRL = 0;
__disable_irq();
RCC->AHB1RSTR = RCC_AHB1RSTR_GPIOERST;
// configure mode bits
PWR->CR1 |= PWR_CR1_PDDS; // PDDS = use standby mode (not stop mode)
// enable Deepsleep mode
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
PWR->CR1 |= PWR_CR1_PDDS; // PDDS = use standby mode (not stop mode)
// Wait for event - this should never return as it kills the chip until a reset PWR->CSR2 |= PWR_CSR2_EWUP1; //EWUP1: Enable Wakeup pin for PA0
__WFE(); PWR->CR2 |= PWR_CR2_CWUPF1; //Clear Wakeup Pin flag for PA0
PWR->CR1 |= PWR_CR1_CSBF; //Clear standby flag
// Lastly, reboot __disable_irq();
NVIC_SystemReset(); __WFI();
} }