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 cc9fdd9757
commit 90f4306c4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 19 deletions

View File

@ -177,10 +177,16 @@ void sys_dual_bank(void) {
void stm32_stop() {
SysTick->CTRL = 0;
__disable_irq();
RCC->AHB1RSTR = RCC_AHB1RSTR_GPIOERST;
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
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_FPDS; // turn off flash 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
// enable Deepsleep mode
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
__WFE();
__disable_irq();
__WFI();
// Lastly, reboot
NVIC_SystemReset();
@ -198,18 +203,11 @@ void stm32_stop() {
void stm32_standby() {
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;
// Wait for event - this should never return as it kills the chip until a reset
__WFE();
// Lastly, reboot
NVIC_SystemReset();
PWR->CR1 |= PWR_CR1_PDDS; // PDDS = use standby mode (not stop mode)
PWR->CSR2 |= PWR_CSR2_EWUP1; //EWUP1: Enable Wakeup pin for PA0
PWR->CR2 |= PWR_CR2_CWUPF1; //Clear Wakeup Pin flag for PA0
PWR->CR1 |= PWR_CR1_CSBF; //Clear standby flag
__disable_irq();
__WFI();
}