Skip to content

Conversation

@Holt-Sun
Copy link
Contributor

Implement proper STOP mode support with partial stop options, add power state timing characteristics, and enable LPTMR-based wake-up for KE1xZ SoC family.

  • Fix STOP mode entry with correct SLEEPDEEP and PSTOPO configuration
  • Add min-residency-us/exit-latency-us to all power states
  • Use LPTMR as cortex-m-idle-timer for low-power operation
  • Add power_mgmt_soc test support for FRDM-KE17Z

@Holt-Sun
Copy link
Contributor Author

The run log:


[16:40:32.929]收←◆*** Booting Zephyr OS build v4.3.0-2768-gf297cb54b620 ***
Running TESTSUITE power_mgmt
===================================================================
START - test_pm_dummyinit
I: PM dummy single-thread test started for one cycle
I: About to enter light sleep
PM >
I: Wake from Light Sleep
PM <
I: PM sleep residency 0.005 seconds
I: About to enter deep Sleep
PM >

[16:40:33.696]收←◆I: Wake from Deep Sleep
PM <
I: PM sleep residency 1.105 seconds
I: PM dummy single-thread completed
 PASS - test_pm_dummyinit in 1.140 seconds
===================================================================
START - test_pm_multithread
I: Thread task A init
I: Thread task B init
I: PM multi-thread test started for cycles: 2
I: Suspend...
I: About to enter light sleep
PM >
I: Wake from Light Sleep
PM <
I: PM sleep residency 0.005 seconds
I: Resume
I: Suspend...
I: About to enter deep sleep
PM >

[16:40:34.473]收←◆I: Wake from Deep Sleep
PM <
I: PM sleep residency 1.105 seconds
I: Resume
I: Suspend...
I: About to enter light sleep
PM >
I: Wake from Light Sleep
PM <
I: PM sleep residency 0.005 seconds
I: Resume
I: Suspend...
I: About to enter deep sleep
PM >

[16:40:35.228]收←◆I: Wake from Deep Sleep
PM <
I: PM sleep residency 1.105 seconds
I: Resume
I: PM multi-thread completed
I: PM state[0] entry counter 0

I: PM state[0] exit counter 0

I: PM state[1] entry counter 4

I: PM state[1] exit counter 4

I: PM state[2] entry counter 8

I: PM state[2] exit counter 8

I: PM state[3] entry counter 0

I: PM state[3] exit counter 0

I: PM state[4] entry counter 0

I: PM state[4] exit counter 0

I: PM state[5] entry counter 0

I: PM state[5] exit counter 0

I: PM state[6] entry counter 0

I: PM state[6] exit counter 0

 PASS - test_pm_multithread in 2.346 seconds
===================================================================
START - test_pm_singlethread
I: PM single-thread test started for cycles: 2
I: About to enter light sleep
PM >
I: Wake from Light Sleep
PM <
I: PM sleep residency 0.005 seconds
I: About to enter deep Sleep
PM >

[16:40:36.041]收←◆I: Wake from Deep Sleep
PM <
I: PM sleep residency 1.105 seconds
I: About to enter light sleep
PM >
I: Wake from Light Sleep
PM <
I: PM sleep residency 0.005 seconds
I: About to enter deep Sleep
PM >

[16:40:36.789]收←◆I: Wake from Deep Sleep
PM <
I: PM sleep residency 1.105 seconds
I: PM single-thread completed
I: PM state[0] entry counter 0

I: PM state[0] exit counter 0

I: PM state[1] entry counter 4

I: PM state[1] exit counter 4

I: PM state[2] entry counter 8

I: PM state[2] exit counter 8

I: PM state[3] entry counter 0

I: PM state[3] exit counter 0

I: PM state[4] entry counter 0

I: PM state[4] exit counter 0

I: PM state[5] entry counter 0

I: PM state[5] exit counter 0

I: PM state[6] entry counter 0

I: PM state[6] exit counter 0

 PASS - test_pm_singlethread in 2.327 seconds
===================================================================
TESTSUITE power_mgmt succeeded

------ TESTSUITE SUMMARY START ------

SUITE PASS - 100.00% [power_mgmt]: pass = 3, fail = 0, skip = 0, total = 3 duration = 5.813 seconds
 - PASS - [power_mgmt.test_pm_dummyinit] duration = 1.140 seconds
 - PASS - [power_mgmt.test_pm_multithread] duration = 2.346 seconds
 - PASS - [power_mgmt.test_pm_singlethread] duration = 2.327 seconds

------ TESTSUITE SUMMARY END ------

===================================================================
PROJECT EXECUTION SUCCESSFUL

Implement proper STOP mode support with partial stop options,
add power state timing characteristics, and enable LPTMR-based
wake-up for KE1xZ SoC family.

- Fix STOP mode entry with correct SLEEPDEEP and PSTOPO configuration
- Add min-residency-us/exit-latency-us to all power states
- Use LPTMR as cortex-m-idle-timer for low-power operation
- Add power_mgmt_soc test support for FRDM-KE17Z

Signed-off-by: Holt Sun <[email protected]>
@Holt-Sun Holt-Sun force-pushed the nxp-mcux-enable-system-power-management-for-KE branch from 0c07f90 to 6d98c26 Compare December 23, 2025 09:12
@sonarqubecloud
Copy link

@Holt-Sun
Copy link
Contributor Author

@Albort12138 @ZhaoxiangJin , please help review.

Copy link
Contributor

@bjarki-andreasen bjarki-andreasen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but I'm suspicious of the __enable_irq()


void pm_state_set(enum pm_state state, uint8_t substate_id)
{
__enable_irq();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
__enable_irq();
__disable_irq();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The interrupt is necessary for waking up(recovery):
image

}

/* Ensure STOPM is set to normal STOP (not VLPS/VLLS families), if present. */
SMC->PMCTRL = (SMC->PMCTRL & ~SMC_PMCTRL_STOPM_MASK) | SMC_PMCTRL_STOPM(0U);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SMC->PMCTRL = (SMC->PMCTRL & ~SMC_PMCTRL_STOPM_MASK) | SMC_PMCTRL_STOPM(0U);
SMC->PMCTRL &= ~SMC_PMCTRL_STOPM_MASK;

@@ -1,5 +1,5 @@
/*
* Copyright 2024 NXP
* Copyright 2024, 2025 NXP
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2024-2025, also other files.


# Keep LPTMR as wake/idle timer via counter API
CONFIG_COUNTER=y
CONFIG_COUNTER_MCUX_LPTMR=y
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONFIG_COUNTER_MCUX_LPTMR not needed manually set to y here guess.

config MCUX_LPTMR_TIMER
default y if PM

config CORTEX_M_SYSTICK
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can change it to configdefault CORTEX_M_SYSTICK at the same time?

idle: idle {
compatible = "zephyr,power-state";
power-state-name = "runtime-idle";
min-residency-us = <10>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the clock frequency of the LPTMR? I think the min-residency-us value needs careful consideration, as 10us may not be sufficient for even one hardware cycle of the LPTMR.

compatible = "arm,cortex-m0+";
clock-frequency = <DT_FREQ_M(48)>;
reg = <0>;
cpu-power-states = <&idle &stop &pstop1 &pstop2>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cpu-power-states = <&idle &pstop2 &pstop1 &stop>;

Based on this order, to find the appropriate mode more efficiently

compatible = "zephyr,power-state";
power-state-name = "suspend-to-idle";
substate-id = <1>;
min-residency-us = <60>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where residency come from?

power-state-name = "runtime-idle";
min-residency-us = <10>;
/* 0.7 µs rounded */
exit-latency-us = <1>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exit-latency-us value should be incremented across different power modes.

@ZhaoxiangJin
Copy link
Contributor

To be honest, I'm not sure if your MCU has actually gone to low power mode. Look here: LPTMR can only be correctly configured as the wake-up source when exit_latency_ticks is greater than 0. And looking at the power mode nodes in the devicetree, their min-residency-us values ​​are very low, possibly less than one kernel tick under the default transition strategy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants