Skip to content

Commit 407216b

Browse files
Desvauxm-stcarlescufi
authored andcommitted
soc: arm: st_stm32: stm32l4: power.c standby shutdownn mode
STM32L4x power management stop mode modification Signed-off-by: Marc Desvaux <[email protected]>
1 parent d638811 commit 407216b

File tree

1 file changed

+52
-41
lines changed

1 file changed

+52
-41
lines changed

soc/arm/st_stm32/stm32l4/power.c

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,82 +27,93 @@ LOG_MODULE_DECLARE(soc, CONFIG_SOC_LOG_LEVEL);
2727
#define RCC_STOP_WAKEUPCLOCK_SELECTED LL_RCC_STOP_WAKEUPCLOCK_HSI
2828
#endif
2929

30-
/* Invoke Low Power/System Off specific Tasks */
31-
__weak void pm_state_set(enum pm_state state, uint8_t substate_id)
30+
void set_mode_stop(uint8_t substate_id)
3231
{
33-
if (state != PM_STATE_SUSPEND_TO_IDLE) {
34-
LOG_DBG("Unsupported power state %u", state);
35-
return;
36-
}
32+
/* ensure the proper wake-up system clock */
33+
LL_RCC_SetClkAfterWakeFromStop(RCC_STOP_WAKEUPCLOCK_SELECTED);
3734

3835
switch (substate_id) {
3936
case 1: /* this corresponds to the STOP0 mode: */
40-
/* ensure the proper wake-up system clock */
41-
LL_RCC_SetClkAfterWakeFromStop(RCC_STOP_WAKEUPCLOCK_SELECTED);
4237
/* enter STOP0 mode */
4338
LL_PWR_SetPowerMode(LL_PWR_MODE_STOP0);
44-
LL_LPM_EnableDeepSleep();
45-
/* enter SLEEP mode : WFE or WFI */
46-
k_cpu_idle();
4739
break;
4840
case 2: /* this corresponds to the STOP1 mode: */
49-
/* ensure the proper wake-up system clock */
50-
LL_RCC_SetClkAfterWakeFromStop(RCC_STOP_WAKEUPCLOCK_SELECTED);
5141
/* enter STOP1 mode */
5242
LL_PWR_SetPowerMode(LL_PWR_MODE_STOP1);
53-
LL_LPM_EnableDeepSleep();
54-
/* enter SLEEP mode : WFE or WFI */
55-
k_cpu_idle();
5643
break;
5744
case 3: /* this corresponds to the STOP2 mode: */
58-
/* ensure the proper wake-up system clock */
59-
LL_RCC_SetClkAfterWakeFromStop(RCC_STOP_WAKEUPCLOCK_SELECTED);
6045
#ifdef PWR_CR1_RRSTP
6146
LL_PWR_DisableSRAM3Retention();
6247
#endif /* PWR_CR1_RRSTP */
6348
/* enter STOP2 mode */
6449
LL_PWR_SetPowerMode(LL_PWR_MODE_STOP2);
50+
break;
51+
default:
52+
LOG_DBG("Unsupported power state substate-id %u", substate_id);
53+
break;
54+
}
55+
}
56+
57+
/* Invoke Low Power/System Off specific Tasks */
58+
__weak void pm_state_set(enum pm_state state, uint8_t substate_id)
59+
{
60+
switch (state) {
61+
case PM_STATE_SUSPEND_TO_IDLE:
62+
set_mode_stop(substate_id);
63+
/* Set SLEEPDEEP bit of Cortex System Control Register */
6564
LL_LPM_EnableDeepSleep();
66-
/* enter SLEEP mode : WFE or WFI */
65+
/* Select mode entry : WFE or WFI and enter the CPU selected mode */
6766
k_cpu_idle();
6867
break;
68+
case PM_STATE_STANDBY:
69+
__fallthrough;
70+
case PM_STATE_SOFT_OFF:
71+
__fallthrough;
6972
default:
70-
LOG_DBG("Unsupported power state substate-id %u",
71-
substate_id);
72-
break;
73+
LOG_DBG("Unsupported power state %u", state);
74+
return;
7375
}
76+
7477
}
7578

7679
/* Handle SOC specific activity after Low Power Mode Exit */
7780
__weak void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id)
7881
{
79-
if (state != PM_STATE_SUSPEND_TO_IDLE) {
80-
LOG_DBG("Unsupported power substate-id %u", state);
81-
} else {
82-
switch (substate_id) {
83-
case 1: /* STOP0 */
84-
__fallthrough;
85-
case 2: /* STOP1 */
86-
__fallthrough;
87-
case 3: /* STOP2 */
82+
switch (state) {
83+
case PM_STATE_SUSPEND_TO_IDLE:
84+
if (substate_id <= 3) {
8885
LL_LPM_DisableSleepOnExit();
8986
LL_LPM_EnableSleep();
90-
break;
91-
default:
87+
} else {
9288
LOG_DBG("Unsupported power substate-id %u",
93-
substate_id);
94-
break;
89+
substate_id);
9590
}
9691
/* need to restore the clock */
9792
stm32_clock_control_init(NULL);
93+
94+
/*
95+
* System is now in active mode.
96+
* Reenable interrupts which were disabled
97+
* when OS started idling code.
98+
*/
99+
irq_unlock(0);
100+
break;
101+
case PM_STATE_STANDBY:
102+
__fallthrough;
103+
case PM_STATE_SOFT_OFF:
104+
/* We should not get there */
105+
__fallthrough;
106+
case PM_STATE_ACTIVE:
107+
__fallthrough;
108+
case PM_STATE_SUSPEND_TO_RAM:
109+
__fallthrough;
110+
case PM_STATE_SUSPEND_TO_DISK:
111+
__fallthrough;
112+
default:
113+
LOG_DBG("Unsupported power state %u", state);
114+
break;
98115
}
99116

100-
/*
101-
* System is now in active mode.
102-
* Reenable interrupts which were disabled
103-
* when OS started idling code.
104-
*/
105-
irq_unlock(0);
106117
}
107118

108119
/* Initialize STM32 Power */

0 commit comments

Comments
 (0)