-
Notifications
You must be signed in to change notification settings - Fork 8.3k
STM32F3x power management #100246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
albayenes
wants to merge
1
commit into
zephyrproject-rtos:main
Choose a base branch
from
albayenes:stm32f3_pm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+179
−2
Open
STM32F3x power management #100246
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
samples/boards/st/power_mgmt/wkup_pins/boards/nucleo_f302r8.overlay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* | ||
| * Copyright (c) 2025 Enes Albay <[email protected]> | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| / { | ||
| aliases { | ||
| wkup-src = &wkup_button; | ||
| }; | ||
|
|
||
| gpio_keys { | ||
| wkup_button: wkup { | ||
| label = "WKUP"; | ||
| /* | ||
| * PA0 is not connected to any button: you must connect it to VDD (+3.3V) | ||
| * using a jumper wire. For example, wiring PA0 CN7[28] (PA0) to VDD CN7[16] | ||
| */ | ||
| gpios = <&gpioa 0 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>; | ||
| zephyr,code = <INPUT_KEY_POWER>; | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
| &pwr { | ||
| status = "okay"; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* | ||
| * Copyright (c) 2025 Enes Albay <[email protected]> | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <clock_control/clock_stm32_ll_common.h> | ||
| #include <stm32_ll_bus.h> | ||
| #include <stm32_ll_cortex.h> | ||
| #include <stm32_ll_pwr.h> | ||
| #include <zephyr/kernel.h> | ||
| #include <zephyr/logging/log.h> | ||
| #include <zephyr/pm/pm.h> | ||
|
|
||
| LOG_MODULE_DECLARE(soc, CONFIG_SOC_LOG_LEVEL); | ||
|
|
||
| void pm_state_set(enum pm_state state, uint8_t substate_id) | ||
| { | ||
| switch (state) { | ||
|
Check warning on line 19 in soc/st/stm32/stm32f3x/power.c
|
||
| case PM_STATE_SUSPEND_TO_IDLE: | ||
| LL_LPM_DisableEventOnPend(); | ||
| LL_PWR_ClearFlag_WU(); | ||
|
|
||
| if (substate_id == 0) { | ||
etienne-lms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| LL_PWR_SetPowerMode(LL_PWR_MODE_STOP_MAINREGU); | ||
| } else { | ||
| LL_PWR_SetPowerMode(LL_PWR_MODE_STOP_LPREGU); | ||
| } | ||
|
|
||
| LL_LPM_EnableDeepSleep(); | ||
| k_cpu_idle(); | ||
| break; | ||
|
|
||
| default: | ||
| LOG_DBG("Unsupported power state %u", state); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id) | ||
| { | ||
| ARG_UNUSED(substate_id); | ||
|
|
||
| switch (state) { | ||
|
Check warning on line 44 in soc/st/stm32/stm32f3x/power.c
|
||
| case PM_STATE_SUSPEND_TO_IDLE: | ||
| LL_LPM_DisableSleepOnExit(); | ||
| LL_LPM_EnableSleep(); | ||
|
|
||
| /* Restore the clock setup. */ | ||
| stm32_clock_control_init(NULL); | ||
| break; | ||
|
|
||
| default: | ||
| LOG_DBG("Unsupported power substate-id %u", state); | ||
| break; | ||
| } | ||
|
|
||
| /* | ||
| * System is now in active mode. Reenable interrupts which were | ||
| * disabled when OS started idling code. | ||
| */ | ||
| irq_unlock(0); | ||
| } | ||
|
|
||
| void stm32_power_init(void) | ||
| { | ||
| /* Enable Power clock. It should by done by default, but make sure to | ||
| * enable it for all STM32F3x chips. | ||
| */ | ||
| LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /* | ||
| * Copyright (c) 2025 Enes Albay <[email protected]> | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <stm32_common.h> | ||
| #include <stm32_ll_pwr.h> | ||
|
|
||
| void z_sys_poweroff(void) | ||
| { | ||
| LL_PWR_ClearFlag_SB(); | ||
| LL_PWR_ClearFlag_WU(); | ||
|
|
||
| LL_PWR_SetPowerMode(LL_PWR_MODE_STANDBY); | ||
|
|
||
| stm32_enter_poweroff(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.