fix f4 standby (#3894)

* fix the bug

* wake on PD0 = CAN RX

* cleanup
This commit is contained in:
Matthew Kennedy 2022-02-05 04:25:09 -08:00 committed by GitHub
parent 409d05ace4
commit 2f8acb13be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 21 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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

View File

@ -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();
}