diff --git a/firmware/config/boards/hellen/alphax-2chan/board_configuration.cpp b/firmware/config/boards/hellen/alphax-2chan/board_configuration.cpp index 927f4a21ef..afc2872205 100644 --- a/firmware/config/boards/hellen/alphax-2chan/board_configuration.cpp +++ b/firmware/config/boards/hellen/alphax-2chan/board_configuration.cpp @@ -184,3 +184,8 @@ void setSdCardConfigurationOverrides() { engineConfiguration->sdCardCsPin = H_SPI2_CS; engineConfiguration->is_enabled_spi_2 = true; } + +void boardPrepareForStop() { + // Wake on the CAN RX pin + palEnableLineEvent(PAL_LINE(GPIOD, 0), PAL_EVENT_MODE_RISING_EDGE); +} diff --git a/firmware/config/boards/proteus/board_configuration.cpp b/firmware/config/boards/proteus/board_configuration.cpp index cc6cadbc25..92179f7e75 100644 --- a/firmware/config/boards/proteus/board_configuration.cpp +++ b/firmware/config/boards/proteus/board_configuration.cpp @@ -214,17 +214,6 @@ void setBoardDefaultConfiguration() { } void boardPrepareForStop() { - #ifdef STM32F7XX - // enable EXTI on PD0 - CAN RX pin - palSetPadMode(GPIOD, 0, PAL_MODE_INPUT); //Select Pin 0 on D Port - PD0, CAN RX as input - palEnableLineEvent(PAL_LINE(GPIOD, 0), PAL_EVENT_MODE_RISING_EDGE); // Set PD0 to interrupt on rising edge - #endif - - #ifdef STM32F4XX - // enable EXTI on PA0 - The only WKUP pin F4 has. - PWR->CR |= PWR_CR_CWUF; //Clear Wakeup Pin flag for PA0 - palSetPadMode(GPIOA, 0, PAL_MODE_INPUT); //Select Pin 0 on A Port - PA0, Wkup - palEnableLineEvent(PAL_LINE(GPIOA, 0), PAL_EVENT_MODE_RISING_EDGE); // Set PA0 to interrupt on rising edge - - #endif + // Wake on the CAN RX pin + palEnableLineEvent(PAL_LINE(GPIOD, 0), PAL_EVENT_MODE_RISING_EDGE); } diff --git a/firmware/hw_layer/ports/stm32/stm32_common.cpp b/firmware/hw_layer/ports/stm32/stm32_common.cpp index 8197f52a53..10647fc1f3 100644 --- a/firmware/hw_layer/ports/stm32/stm32_common.cpp +++ b/firmware/hw_layer/ports/stm32/stm32_common.cpp @@ -808,8 +808,12 @@ __attribute__((weak)) void boardPrepareForStop() { void boardPreparePA0ForStandby() { #ifdef STM32F4XX + //Enable Wakeup Pin for PA0 + PWR->CSR |= PWR_CSR_EWUP; + + // Clear wakeup flag - it may be set if PA0 is already + // high when we enable it as a wake source PWR->CR |= PWR_CR_CWUF; //Clear Wakeup Pin flag for PA0 - PWR->CSR |= PWR_CSR_EWUP; //Enable Wakeup Pin for PA0 #endif #ifdef STM32F7XX diff --git a/firmware/hw_layer/ports/stm32/stm32f4/mpu_util.cpp b/firmware/hw_layer/ports/stm32/stm32f4/mpu_util.cpp index 2810b62f5c..a39347bba6 100644 --- a/firmware/hw_layer/ports/stm32/stm32f4/mpu_util.cpp +++ b/firmware/hw_layer/ports/stm32/stm32f4/mpu_util.cpp @@ -36,6 +36,9 @@ However, for F40X & F42X this may be useless. STOP in itself eats more current t With F4 only having PA0 available for wakeup, this negates its need. */ void stm32_stop() { + // Don't get bothered by interrupts + __disable_irq(); + SysTick->CTRL = 0; SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; enginePins.errorLedPin.setValue(0); @@ -43,10 +46,6 @@ void stm32_stop() { enginePins.communicationLedPin.setValue(0); enginePins.warningLedPin.setValue(0); - - // Do anything the board wants to prepare for stop mode - enabling wakeup sources! - - boardPrepareForStop(); PWR->CR &= ~PWR_CR_PDDS; // cleared PDDS means stop mode (not standby) PWR->CR |= PWR_CR_FPDS; // turn off flash in stop mode #ifdef STM32F429xx //F40X Does not have these regulators available. @@ -55,9 +54,10 @@ void stm32_stop() { #endif PWR->CR |= PWR_CR_LPDS; // regulator in low power mode + // Do anything the board wants to prepare for stop mode - enabling wakeup sources! + boardPrepareForStop(); // enable Deepsleep mode - __disable_irq(); __WFI(); // Lastly, reboot @@ -68,15 +68,16 @@ Standby for both F4 & F7 works perfectly, with very little curent consumption. D Cannot be used for CAN wakeup without hardware modificatinos. */ void stm32_standby() { + // Don't get bothered by interrupts + __disable_irq(); + SysTick->CTRL = 0; SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; PWR->CR |= PWR_CR_PDDS; // PDDS = use standby mode (not stop mode) PWR->CR |= PWR_CR_CSBF; // Clear standby flag - // Do anything the board wants to prepare for standby mode - enabling wakeup sources! boardPrepareForStandby(); - __disable_irq(); __WFI(); }