Skip to content

Commit 29e2aba

Browse files
authored
Merge pull request #131 from fpistm/stm32wl3_support
feat(wl3): add STM32WL3x support
2 parents bff6e41 + 6b49ad9 commit 29e2aba

File tree

4 files changed

+82
-10
lines changed

4 files changed

+82
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ enable an I2C peripheral in low power mode. See board documentation for low powe
5858
> * The board will restart when exit shutdown mode.
5959
6060
> [!Important]
61-
> For STM32WB0x:
61+
> For STM32WB0x and STM32WL3x:
6262
> * board will restart when exit shutdown mode and deep sleep.
6363
> * Shutdown wakeup only with reset pin.
6464
> * Wakeup from UART not supported.

src/STM32LowPower.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ void STM32LowPower::idle(uint32_t ms)
6868
if ((ms != 0) || _rtc_wakeup) {
6969
programRtcWakeUp(ms, IDLE_MODE);
7070
}
71+
#if defined(PWR_MAINREGULATOR_ON)
7172
LowPower_sleep(PWR_MAINREGULATOR_ON);
73+
#else
74+
LowPower_sleep(0);
75+
#endif
7276
}
7377

7478
/**
@@ -84,8 +88,10 @@ void STM32LowPower::sleep(uint32_t ms)
8488
}
8589
#if defined(PWR_LOWPOWERREGULATOR_ON)
8690
LowPower_sleep(PWR_LOWPOWERREGULATOR_ON);
87-
#else
91+
#elif defined(PWR_MAINREGULATOR_ON)
8892
LowPower_sleep(PWR_MAINREGULATOR_ON);
93+
#else
94+
LowPower_sleep(0);
8995
#endif
9096

9197
}
@@ -110,7 +116,7 @@ void STM32LowPower::deepSleep(uint32_t ms)
110116
* @param ms: optional delay before leave the shutdown mode (default: 0).
111117
* @retval None
112118
*/
113-
#if defined(STM32WB0x)
119+
#if defined(STM32WB0x) || defined(STM32WL3x)
114120
void STM32LowPower::shutdown(void)
115121
{
116122
LowPower_shutdown(false);
@@ -144,9 +150,9 @@ void STM32LowPower::attachInterruptWakeup(uint32_t pin, voidFuncPtrVoid callback
144150
attachInterrupt(pin, callback, mode);
145151

146152
if ((LowPowerMode == SHUTDOWN_MODE)
147-
#if defined(PWR_WAKEUP_PA0)
153+
#if defined(PWR_WAKEUP_PA0) || defined(PWR_WAKEUP_PORTA)
148154
|| (LowPowerMode == DEEP_SLEEP_MODE)
149-
#endif /* PWR_WAKEUP1_SOURCE_SELECTION_0 */
155+
#endif /* PWR_WAKEUP1_SOURCE_SELECTION_0 || PWR_WAKEUP_PORTA */
150156
) {
151157
// If Gpio is a Wake up pin activate it for shutdown (standby or shutdown stm32)
152158
LowPower_EnableWakeUpPin(pin, mode);
@@ -204,7 +210,7 @@ void STM32LowPower::programRtcWakeUp(uint32_t ms, LP_Mode lp_mode)
204210
break;
205211
// LSI or LSE must be selected as clock source to wakeup the device.
206212
case DEEP_SLEEP_MODE:
207-
#if defined(RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048)
213+
#if defined(RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048) || defined(RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512)
208214
clkSrc = (clkSrc == STM32RTC::HSI_CLOCK) ? STM32RTC::LSI_CLOCK : clkSrc;
209215
#else
210216
clkSrc = (clkSrc == STM32RTC::HSE_CLOCK) ? STM32RTC::LSI_CLOCK : clkSrc;

src/STM32LowPower.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class STM32LowPower {
8080
{
8181
deepSleep((uint32_t)ms);
8282
}
83-
#if defined(STM32WB0x)
83+
#if defined(STM32WB0x) || defined(STM32WL3x)
8484
void shutdown(void);
8585
#else
8686
void shutdown(uint32_t ms = 0);

src/low_power.c

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,72 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
388388
HAL_PWR_EnableWakeUpPin(wkup_pin, ((mode == RISING) || (mode == HIGH)) ? PWR_WUP_FALLEDG : PWR_WUP_RISIEDG);
389389
}
390390
}
391+
#elif defined(PWR_WAKEUP_PORTA)
392+
/* Get GPIO port from pinname*/
393+
GPIO_TypeDef *port = get_GPIO_Port(STM_PORT(p));
394+
uint32_t wkup_pin = 0;
395+
uint32_t wkup_port = 0;
396+
switch (STM_PIN(p)) {
397+
case 0:
398+
wkup_pin = PWR_WAKEUP_PIN0;
399+
break;
400+
case 1:
401+
wkup_pin = PWR_WAKEUP_PIN1;
402+
break;
403+
case 2:
404+
wkup_pin = PWR_WAKEUP_PIN2;
405+
break;
406+
case 3:
407+
wkup_pin = PWR_WAKEUP_PIN3;
408+
break;
409+
case 4:
410+
wkup_pin = PWR_WAKEUP_PIN4;
411+
break;
412+
case 5:
413+
wkup_pin = PWR_WAKEUP_PIN5;
414+
break;
415+
case 6:
416+
wkup_pin = PWR_WAKEUP_PIN6;
417+
break;
418+
case 7:
419+
wkup_pin = PWR_WAKEUP_PIN7;
420+
break;
421+
case 8:
422+
wkup_pin = PWR_WAKEUP_PIN8;
423+
break;
424+
case 9:
425+
wkup_pin = PWR_WAKEUP_PIN9;
426+
break;
427+
case 10:
428+
wkup_pin = PWR_WAKEUP_PIN10;
429+
break;
430+
case 11:
431+
wkup_pin = PWR_WAKEUP_PIN11;
432+
break;
433+
case 12:
434+
wkup_pin = PWR_WAKEUP_PIN12;
435+
break;
436+
case 13:
437+
wkup_pin = PWR_WAKEUP_PIN13;
438+
break;
439+
case 14:
440+
wkup_pin = PWR_WAKEUP_PIN14;
441+
break;
442+
case 15:
443+
wkup_pin = PWR_WAKEUP_PIN15;
444+
break;
445+
default:
446+
port = NULL;
447+
break;
448+
}
449+
if (port == (GPIO_TypeDef *)GPIOA_BASE) {
450+
wkup_port = PWR_WAKEUP_PORTA;
451+
} else if (port == (GPIO_TypeDef *)GPIOB_BASE) {
452+
wkup_port = PWR_WAKEUP_PORTB;
453+
}
454+
if (IS_PWR_WAKEUP_SOURCE(wkup_pin)) {
455+
HAL_PWR_EnableWakeUpPin(wkup_port, wkup_pin, ((mode == RISING) || (mode == HIGH)) ? PWR_WUP_FALLEDG : PWR_WUP_RISIEDG);
456+
}
391457
#else
392458
#if !defined(PWR_WAKEUP_PIN1_HIGH)
393459
UNUSED(mode);
@@ -701,7 +767,7 @@ void LowPower_stop(serial_t *obj)
701767
HAL_UARTEx_EnableStopMode(WakeUpUart);
702768
}
703769
#endif
704-
#if defined(STM32WB0x)
770+
#if defined(STM32WB0x) || defined(STM32WL3x)
705771
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_DEEPSTOPF);
706772
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
707773
PWR_DEEPSTOPTypeDef configDEEPSTOP;
@@ -812,7 +878,7 @@ void LowPower_stop(serial_t *obj)
812878
*/
813879
void LowPower_standby()
814880
{
815-
#if !defined(STM32WB0x)
881+
#if !defined(STM32WB0x) && !defined(STM32WL3x)
816882
__disable_irq();
817883

818884
/* Clear wakeup flags */
@@ -844,7 +910,7 @@ void LowPower_standby()
844910
LL_C2_PWR_SetPowerMode(LL_PWR_MODE_STANDBY);
845911
#endif
846912
HAL_PWR_EnterSTANDBYMode();
847-
#endif /* !STM32WB0x */
913+
#endif /* !STM32WB0x || STM32WL3x */
848914
}
849915

850916
/**

0 commit comments

Comments
 (0)