-
Notifications
You must be signed in to change notification settings - Fork 8.4k
soc: stm32f7: add power management support #99157
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ | |
| chosen { | ||
| zephyr,entropy = &rng; | ||
| zephyr,flash-controller = &flash; | ||
| zephyr,cortex-m-idle-timer = &rtc; | ||
| }; | ||
|
|
||
| cpus { | ||
|
|
@@ -38,13 +39,24 @@ | |
| device_type = "cpu"; | ||
| compatible = "arm,cortex-m7"; | ||
| reg = <0>; | ||
| cpu-power-states = <&stop>; | ||
| #address-cells = <1>; | ||
| #size-cells = <1>; | ||
|
|
||
| mpu: mpu@e000ed90 { | ||
| compatible = "arm,armv7m-mpu"; | ||
| reg = <0xe000ed90 0x40>; | ||
| }; | ||
| }; | ||
|
|
||
|
|
||
| power-states { | ||
| stop: stop { | ||
| compatible = "zephyr,power-state"; | ||
| power-state-name = "suspend-to-idle"; | ||
| min-residency-us = <400>; | ||
| exit-latency-us = <300>; | ||
| }; | ||
|
Comment on lines
+53
to
+59
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation issue + missing
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @erwango If there are missing }; the dts-linter would complain so I do not believe we have any missing };
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's rather the indentation that is fuzzy. Indeed compiling this DTS is valid. But CI DTS linter compliance test obviously complains. |
||
| }; | ||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* | ||
| * Copyright (c) 2025 Ac6 | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <clock_control/clock_stm32_ll_common.h> | ||
| #include <soc.h> | ||
|
|
||
| #include <stm32f7xx_ll_bus.h> | ||
| #include <stm32f7xx_ll_cortex.h> | ||
| #include <stm32f7xx_ll_pwr.h> | ||
| #include <stm32f7xx.h> | ||
|
Comment on lines
+10
to
+13
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #99012 |
||
|
|
||
| #include <zephyr/drivers/clock_control/stm32_clock_control.h> | ||
| #include <zephyr/drivers/counter.h> | ||
| #include <zephyr/drivers/interrupt_controller/gic.h> | ||
| #include <zephyr/kernel.h> | ||
| #include <zephyr/logging/log.h> | ||
| #include <zephyr/pm/pm.h> | ||
| #include <zephyr/init.h> | ||
|
Comment on lines
+15
to
+21
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion -#include <zephyr/drivers/clock_control/stm32_clock_control.h>
-#include <zephyr/drivers/counter.h>
-#include <zephyr/drivers/interrupt_controller/gic.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <zephyr/pm/pm.h>
-#include <zephyr/init.h> |
||
|
|
||
| LOG_MODULE_DECLARE(soc, CONFIG_SOC_LOG_LEVEL); | ||
|
|
||
| BUILD_ASSERT(DT_SAME_NODE(DT_CHOSEN(zephyr_cortex_m_idle_timer), DT_NODELABEL(rtc)), | ||
| "STM32Fx series needs RTC as an additional IDLE timer for power management"); | ||
|
|
||
| void pm_state_set(enum pm_state state, uint8_t substate_id) | ||
| { | ||
| ARG_UNUSED(substate_id); | ||
|
|
||
| switch (state) { | ||
| case PM_STATE_SUSPEND_TO_IDLE: | ||
| /* Prepare STOP mode with low-power regulator */ | ||
| LL_LPM_DisableEventOnPend(); | ||
| LL_PWR_ClearFlag_WU1(); | ||
| LL_PWR_ClearFlag_WU2(); | ||
| LL_PWR_ClearFlag_WU3(); | ||
| LL_PWR_ClearFlag_WU4(); | ||
| LL_PWR_ClearFlag_WU5(); | ||
| LL_PWR_ClearFlag_WU6(); | ||
|
|
||
| /* Use low-power regulator in STOP to reduce consumption */ | ||
| 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) { | ||
| case PM_STATE_SUSPEND_TO_IDLE: | ||
| /* Back to normal sleep and restore clocks after STOP */ | ||
| LL_LPM_DisableSleepOnExit(); | ||
| LL_LPM_EnableSleep(); | ||
|
|
||
| /* Restore the clock setup after STOP mode */ | ||
| stm32_clock_control_init(NULL); | ||
| break; | ||
|
|
||
| default: | ||
| LOG_DBG("Unsupported power substate-id %u", state); | ||
| break; | ||
| } | ||
|
|
||
| /* System is now active, re-enable interrupts disabled on entry */ | ||
| irq_unlock(0); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is suspicious...