diff --git a/README.md b/README.md index 0b3db4d..73149f0 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ enable an I2C peripheral in low power mode. See board documentation for low powe > * The board will restart when exit shutdown mode. > [!Important] -> For STM32WB0x: +> For STM32WB0x and STM32WL3x: > * board will restart when exit shutdown mode and deep sleep. > * Shutdown wakeup only with reset pin. > * Wakeup from UART not supported. diff --git a/src/STM32LowPower.cpp b/src/STM32LowPower.cpp index 84cb7f6..d3abfe8 100644 --- a/src/STM32LowPower.cpp +++ b/src/STM32LowPower.cpp @@ -68,7 +68,11 @@ void STM32LowPower::idle(uint32_t ms) if ((ms != 0) || _rtc_wakeup) { programRtcWakeUp(ms, IDLE_MODE); } +#if defined(PWR_MAINREGULATOR_ON) LowPower_sleep(PWR_MAINREGULATOR_ON); +#else + LowPower_sleep(0); +#endif } /** @@ -84,8 +88,10 @@ void STM32LowPower::sleep(uint32_t ms) } #if defined(PWR_LOWPOWERREGULATOR_ON) LowPower_sleep(PWR_LOWPOWERREGULATOR_ON); -#else +#elif defined(PWR_MAINREGULATOR_ON) LowPower_sleep(PWR_MAINREGULATOR_ON); +#else + LowPower_sleep(0); #endif } @@ -110,7 +116,7 @@ void STM32LowPower::deepSleep(uint32_t ms) * @param ms: optional delay before leave the shutdown mode (default: 0). * @retval None */ -#if defined(STM32WB0x) +#if defined(STM32WB0x) || defined(STM32WL3x) void STM32LowPower::shutdown(void) { LowPower_shutdown(false); @@ -144,9 +150,9 @@ void STM32LowPower::attachInterruptWakeup(uint32_t pin, voidFuncPtrVoid callback attachInterrupt(pin, callback, mode); if ((LowPowerMode == SHUTDOWN_MODE) -#if defined(PWR_WAKEUP_PA0) +#if defined(PWR_WAKEUP_PA0) || defined(PWR_WAKEUP_PORTA) || (LowPowerMode == DEEP_SLEEP_MODE) -#endif /* PWR_WAKEUP1_SOURCE_SELECTION_0 */ +#endif /* PWR_WAKEUP1_SOURCE_SELECTION_0 || PWR_WAKEUP_PORTA */ ) { // If Gpio is a Wake up pin activate it for shutdown (standby or shutdown stm32) LowPower_EnableWakeUpPin(pin, mode); @@ -204,7 +210,7 @@ void STM32LowPower::programRtcWakeUp(uint32_t ms, LP_Mode lp_mode) break; // LSI or LSE must be selected as clock source to wakeup the device. case DEEP_SLEEP_MODE: -#if defined(RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048) +#if defined(RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048) || defined(RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512) clkSrc = (clkSrc == STM32RTC::HSI_CLOCK) ? STM32RTC::LSI_CLOCK : clkSrc; #else clkSrc = (clkSrc == STM32RTC::HSE_CLOCK) ? STM32RTC::LSI_CLOCK : clkSrc; diff --git a/src/STM32LowPower.h b/src/STM32LowPower.h index bc0d3bb..9737522 100644 --- a/src/STM32LowPower.h +++ b/src/STM32LowPower.h @@ -80,7 +80,7 @@ class STM32LowPower { { deepSleep((uint32_t)ms); } -#if defined(STM32WB0x) +#if defined(STM32WB0x) || defined(STM32WL3x) void shutdown(void); #else void shutdown(uint32_t ms = 0); diff --git a/src/low_power.c b/src/low_power.c index 99a52df..4072118 100644 --- a/src/low_power.c +++ b/src/low_power.c @@ -388,6 +388,72 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode) HAL_PWR_EnableWakeUpPin(wkup_pin, ((mode == RISING) || (mode == HIGH)) ? PWR_WUP_FALLEDG : PWR_WUP_RISIEDG); } } +#elif defined(PWR_WAKEUP_PORTA) + /* Get GPIO port from pinname*/ + GPIO_TypeDef *port = get_GPIO_Port(STM_PORT(p)); + uint32_t wkup_pin = 0; + uint32_t wkup_port = 0; + switch (STM_PIN(p)) { + case 0: + wkup_pin = PWR_WAKEUP_PIN0; + break; + case 1: + wkup_pin = PWR_WAKEUP_PIN1; + break; + case 2: + wkup_pin = PWR_WAKEUP_PIN2; + break; + case 3: + wkup_pin = PWR_WAKEUP_PIN3; + break; + case 4: + wkup_pin = PWR_WAKEUP_PIN4; + break; + case 5: + wkup_pin = PWR_WAKEUP_PIN5; + break; + case 6: + wkup_pin = PWR_WAKEUP_PIN6; + break; + case 7: + wkup_pin = PWR_WAKEUP_PIN7; + break; + case 8: + wkup_pin = PWR_WAKEUP_PIN8; + break; + case 9: + wkup_pin = PWR_WAKEUP_PIN9; + break; + case 10: + wkup_pin = PWR_WAKEUP_PIN10; + break; + case 11: + wkup_pin = PWR_WAKEUP_PIN11; + break; + case 12: + wkup_pin = PWR_WAKEUP_PIN12; + break; + case 13: + wkup_pin = PWR_WAKEUP_PIN13; + break; + case 14: + wkup_pin = PWR_WAKEUP_PIN14; + break; + case 15: + wkup_pin = PWR_WAKEUP_PIN15; + break; + default: + port = NULL; + break; + } + if (port == (GPIO_TypeDef *)GPIOA_BASE) { + wkup_port = PWR_WAKEUP_PORTA; + } else if (port == (GPIO_TypeDef *)GPIOB_BASE) { + wkup_port = PWR_WAKEUP_PORTB; + } + if (IS_PWR_WAKEUP_SOURCE(wkup_pin)) { + HAL_PWR_EnableWakeUpPin(wkup_port, wkup_pin, ((mode == RISING) || (mode == HIGH)) ? PWR_WUP_FALLEDG : PWR_WUP_RISIEDG); + } #else #if !defined(PWR_WAKEUP_PIN1_HIGH) UNUSED(mode); @@ -701,7 +767,7 @@ void LowPower_stop(serial_t *obj) HAL_UARTEx_EnableStopMode(WakeUpUart); } #endif -#if defined(STM32WB0x) +#if defined(STM32WB0x) || defined(STM32WL3x) __HAL_PWR_CLEAR_FLAG(PWR_FLAG_DEEPSTOPF); __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); PWR_DEEPSTOPTypeDef configDEEPSTOP; @@ -812,7 +878,7 @@ void LowPower_stop(serial_t *obj) */ void LowPower_standby() { -#if !defined(STM32WB0x) +#if !defined(STM32WB0x) && !defined(STM32WL3x) __disable_irq(); /* Clear wakeup flags */ @@ -844,7 +910,7 @@ void LowPower_standby() LL_C2_PWR_SetPowerMode(LL_PWR_MODE_STANDBY); #endif HAL_PWR_EnterSTANDBYMode(); -#endif /* !STM32WB0x */ +#endif /* !STM32WB0x || STM32WL3x */ } /**