From 8da8ad3e37a14f5d29e10045e84c9d8c594c5571 Mon Sep 17 00:00:00 2001 From: Zhaoxiang Jin Date: Tue, 8 Jul 2025 19:38:09 +0800 Subject: [PATCH 1/7] modules: hal_nxp: Pulling cmc, vbat, wuu driver Pulling MCUX SDK cmc, vbat, wuu driver to Zephyr build tree. Signed-off-by: Zhaoxiang Jin --- modules/hal_nxp/mcux/mcux-sdk-ng/drivers/drivers.cmake | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/hal_nxp/mcux/mcux-sdk-ng/drivers/drivers.cmake b/modules/hal_nxp/mcux/mcux-sdk-ng/drivers/drivers.cmake index b794013ca972c..dc4a4efa961ac 100644 --- a/modules/hal_nxp/mcux/mcux-sdk-ng/drivers/drivers.cmake +++ b/modules/hal_nxp/mcux/mcux-sdk-ng/drivers/drivers.cmake @@ -164,6 +164,11 @@ endif() if(CONFIG_SOC_SERIES_MCXN OR CONFIG_SOC_SERIES_MCXA) set(CONFIG_MCUX_COMPONENT_driver.mcx_spc ON) + if(CONFIG_PM OR CONFIG_POWEROFF) + set(CONFIG_MCUX_COMPONENT_driver.mcx_cmc ON) + set(CONFIG_MCUX_COMPONENT_driver.mcx_vbat ON) + set(CONFIG_MCUX_COMPONENT_driver.wuu ON) + endif() endif() if(CONFIG_BT_NXP AND CONFIG_SOC_SERIES_MCXW OR CONFIG_IEEE802154_MCXW) From b15818b0642cb17025d810f1343928e17061b0df Mon Sep 17 00:00:00 2001 From: Zhaoxiang Jin Date: Mon, 14 Jul 2025 21:14:40 +0800 Subject: [PATCH 2/7] boards/nxp: mcxn: Enable LPUART pin internal pullup resistor This commit enables MCXN236, MCXN947 LPUART pin internal pullup resistor. For MCXN947 and MCXN236, during LPUAR initialization, the RX pin is pulled down internally and STAT [RAF] is set to one. In this state, attempting to enter low power mode will trigger LPACK reset and therefore cannot truly enter low power mode. The correct setting should be to enable LPUART pin internal pullup resistor. Signed-off-by: Zhaoxiang Jin --- boards/nxp/frdm_mcxn236/frdm_mcxn236-pinctrl.dtsi | 4 +++- boards/nxp/frdm_mcxn947/frdm_mcxn947-pinctrl.dtsi | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/boards/nxp/frdm_mcxn236/frdm_mcxn236-pinctrl.dtsi b/boards/nxp/frdm_mcxn236/frdm_mcxn236-pinctrl.dtsi index 19a06b8453fed..d970f0ad28370 100644 --- a/boards/nxp/frdm_mcxn236/frdm_mcxn236-pinctrl.dtsi +++ b/boards/nxp/frdm_mcxn236/frdm_mcxn236-pinctrl.dtsi @@ -1,5 +1,5 @@ /* - * Copyright 2024 NXP + * Copyright 2024-2025 NXP * SPDX-License-Identifier: Apache-2.0 */ @@ -14,6 +14,7 @@ slew-rate = "fast"; drive-strength = "low"; input-enable; + bias-pull-up; }; }; @@ -48,6 +49,7 @@ slew-rate = "fast"; drive-strength = "low"; input-enable; + bias-pull-up; }; }; diff --git a/boards/nxp/frdm_mcxn947/frdm_mcxn947-pinctrl.dtsi b/boards/nxp/frdm_mcxn947/frdm_mcxn947-pinctrl.dtsi index b2597191d55a1..f2c6718b5cf62 100644 --- a/boards/nxp/frdm_mcxn947/frdm_mcxn947-pinctrl.dtsi +++ b/boards/nxp/frdm_mcxn947/frdm_mcxn947-pinctrl.dtsi @@ -1,5 +1,5 @@ /* - * Copyright 2024 NXP + * Copyright 2024-2025 NXP * SPDX-License-Identifier: Apache-2.0 */ @@ -62,6 +62,7 @@ slew-rate = "fast"; drive-strength = "low"; input-enable; + bias-pull-up; }; }; @@ -72,6 +73,7 @@ slew-rate = "fast"; drive-strength = "low"; input-enable; + bias-pull-up; }; }; From 6418646bf1358844601f78681673c1412ac62618 Mon Sep 17 00:00:00 2001 From: Zhaoxiang Jin Date: Tue, 8 Jul 2025 20:19:47 +0800 Subject: [PATCH 3/7] soc: nxp: mcx/mcxa: Enable poweroff for mcxa series This commit introduced the following changes: 1. Selected kconfig option 'HAS_POWEROFF' for NXP MCXA series. 2. Added power.c for NXP MCXA series, in this file, we currently implemented 'z_sys_poweroff()' function. 3. For the MCXA series, after waking up from the deep power down mode, the reset handler will be executed, and we need to release the I/O pads and certain peripheral devices to normal operating mode in 'soc_reset_hook'. Signed-off-by: Zhaoxiang Jin --- soc/nxp/mcx/mcxa/CMakeLists.txt | 6 +++++- soc/nxp/mcx/mcxa/Kconfig | 1 + soc/nxp/mcx/mcxa/power.c | 28 ++++++++++++++++++++++++++++ soc/nxp/mcx/mcxa/soc.c | 15 ++++++++++++++- 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 soc/nxp/mcx/mcxa/power.c diff --git a/soc/nxp/mcx/mcxa/CMakeLists.txt b/soc/nxp/mcx/mcxa/CMakeLists.txt index 34a926751a7ba..4d600b37e1328 100644 --- a/soc/nxp/mcx/mcxa/CMakeLists.txt +++ b/soc/nxp/mcx/mcxa/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2024 NXP +# Copyright 2024-2025 NXP # # SPDX-License-Identifier: Apache-2.0 # @@ -8,3 +8,7 @@ zephyr_sources(soc.c) zephyr_include_directories(.) set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/arm/cortex_m/scripts/linker.ld CACHE INTERNAL "") + +if(CONFIG_POWEROFF) + zephyr_sources(power.c) +endif() diff --git a/soc/nxp/mcx/mcxa/Kconfig b/soc/nxp/mcx/mcxa/Kconfig index ba6b74c44500d..6b6cea8924556 100644 --- a/soc/nxp/mcx/mcxa/Kconfig +++ b/soc/nxp/mcx/mcxa/Kconfig @@ -9,6 +9,7 @@ config SOC_SERIES_MCXA select CPU_CORTEX_M_HAS_SYSTICK select CPU_CORTEX_M_HAS_DWT select SOC_RESET_HOOK + select HAS_POWEROFF config SOC_MCXA153 select CPU_CORTEX_M33 diff --git a/soc/nxp/mcx/mcxa/power.c b/soc/nxp/mcx/mcxa/power.c new file mode 100644 index 0000000000000..77920e9b4c3a1 --- /dev/null +++ b/soc/nxp/mcx/mcxa/power.c @@ -0,0 +1,28 @@ +/* + * Copyright 2025 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include "fsl_cmc.h" +#include "fsl_spc.h" +#include "fsl_vbat.h" +#include "fsl_wuu.h" + +void z_sys_poweroff(void) +{ + cmc_power_domain_config_t cmc_config = { + .clock_mode = kCMC_GateAllSystemClocksEnterLowPowerMode, + .main_domain = kCMC_DeepPowerDown, + }; + + WUU_SetInternalWakeUpModulesConfig(WUU0, 6U, kWUU_InternalModuleInterrupt); + SPC_SetLowPowerWakeUpDelay(SPC0, 0x5B); + + CMC_SetPowerModeProtection(CMC, kCMC_AllowDeepPowerDownMode); + CMC_EnterLowPowerMode(CMC, &cmc_config); + + CODE_UNREACHABLE; +} diff --git a/soc/nxp/mcx/mcxa/soc.c b/soc/nxp/mcx/mcxa/soc.c index 363a9dad44e01..dde940a92828f 100644 --- a/soc/nxp/mcx/mcxa/soc.c +++ b/soc/nxp/mcx/mcxa/soc.c @@ -1,5 +1,5 @@ /* - * Copyright 2024 NXP + * Copyright 2024-2025 NXP * * SPDX-License-Identifier: Apache-2.0 */ @@ -16,10 +16,23 @@ #include #include #include +#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF) +#include +#include +#endif #ifdef CONFIG_SOC_RESET_HOOK void soc_reset_hook(void) { +#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF) + /* Release the I/O pads and certain peripherals to normal run mode state, + * for in Power Down mode they will be in a latched state. + */ + if ((CMC_GetSystemResetStatus(CMC) & kCMC_WakeUpReset) != 0UL) { + SPC_ClearPeriphIOIsolationFlag(SPC0); + } +#endif + SystemInit(); } #endif From 507a2574eab3fc61237b354fc528d1fd31238d18 Mon Sep 17 00:00:00 2001 From: Zhaoxiang Jin Date: Mon, 14 Jul 2025 22:06:40 +0800 Subject: [PATCH 4/7] soc: nxp: mcx/mcxn: Enable poweroff for mcxn series This commit introduced the following changes: 1. Selected kconfig option 'HAS_POWEROFF' for NXP MCXN series. 2. Added power.c for NXP MCXN series, in this file, we currently implemented 'z_sys_poweroff()' function. 3. For the MCXN series, after waking up from the deep power down mode, the reset handler will be executed, and we need to release the I/O pads and certain peripheral devices to normal operating mode in 'soc_reset_hook'. Signed-off-by: Zhaoxiang Jin --- soc/nxp/mcx/mcxn/CMakeLists.txt | 4 ++++ soc/nxp/mcx/mcxn/Kconfig | 1 + soc/nxp/mcx/mcxn/power.c | 29 +++++++++++++++++++++++++++++ soc/nxp/mcx/mcxn/soc.c | 12 ++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 soc/nxp/mcx/mcxn/power.c diff --git a/soc/nxp/mcx/mcxn/CMakeLists.txt b/soc/nxp/mcx/mcxn/CMakeLists.txt index e432bad982f82..42c25c0f06fac 100644 --- a/soc/nxp/mcx/mcxn/CMakeLists.txt +++ b/soc/nxp/mcx/mcxn/CMakeLists.txt @@ -34,3 +34,7 @@ endif() zephyr_include_directories(.) set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/arm/cortex_m/scripts/linker.ld CACHE INTERNAL "") + +if(CONFIG_POWEROFF) + zephyr_sources(power.c) +endif() diff --git a/soc/nxp/mcx/mcxn/Kconfig b/soc/nxp/mcx/mcxn/Kconfig index 0a771aafac8ae..f82627d9c6914 100644 --- a/soc/nxp/mcx/mcxn/Kconfig +++ b/soc/nxp/mcx/mcxn/Kconfig @@ -10,6 +10,7 @@ config SOC_SERIES_MCXN select CPU_CORTEX_M_HAS_SYSTICK select CPU_CORTEX_M_HAS_DWT select HAS_MCUX_MCX_CMC + select HAS_POWEROFF config SOC_MCXN947_CPU0 select CPU_CORTEX_M33 diff --git a/soc/nxp/mcx/mcxn/power.c b/soc/nxp/mcx/mcxn/power.c new file mode 100644 index 0000000000000..07d941b3cef74 --- /dev/null +++ b/soc/nxp/mcx/mcxn/power.c @@ -0,0 +1,29 @@ +/* + * Copyright 2025 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include "fsl_cmc.h" +#include "fsl_spc.h" +#include "fsl_vbat.h" +#include "fsl_wuu.h" + +void z_sys_poweroff(void) +{ + cmc_power_domain_config_t cmc_config = { + .clock_mode = kCMC_GateAllSystemClocksEnterLowPowerMode, + .main_domain = kCMC_DeepPowerDown, + .wake_domain = kCMC_DeepPowerDown, + }; + + WUU_SetInternalWakeUpModulesConfig(WUU0, 6U, kWUU_InternalModuleInterrupt); + SPC_SetLowPowerWakeUpDelay(SPC0, 0x637); + + CMC_SetPowerModeProtection(CMC0, kCMC_AllowDeepPowerDownMode); + CMC_EnterLowPowerMode(CMC0, &cmc_config); + + CODE_UNREACHABLE; +} diff --git a/soc/nxp/mcx/mcxn/soc.c b/soc/nxp/mcx/mcxn/soc.c index 91156e1c2f291..f2b752be54129 100644 --- a/soc/nxp/mcx/mcxn/soc.c +++ b/soc/nxp/mcx/mcxn/soc.c @@ -16,11 +16,23 @@ #include #include #include +#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF) +#include +#include +#endif #ifdef CONFIG_SOC_RESET_HOOK void soc_reset_hook(void) { +#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF) + /* Release the I/O pads and certain peripherals to normal run mode state, + * for in Power Down mode they will be in a latched state. + */ + if ((CMC_GetSystemResetStatus(CMC0) & kCMC_WakeUpReset) != 0UL) { + SPC_ClearPeriphIOIsolationFlag(SPC0); + } +#endif SystemInit(); } From 86ba10a74fe3f89fde896303d5207717242e131d Mon Sep 17 00:00:00 2001 From: Zhaoxiang Jin Date: Tue, 8 Jul 2025 20:30:40 +0800 Subject: [PATCH 5/7] boards: nxp: mcxa series: Enable FRO16k for LPTMR Enabled FRO16k for LPTMR when LPTMR clock source is set to 0x1. Signed-off-by: Zhaoxiang Jin --- boards/nxp/frdm_mcxa153/board.c | 6 ++++++ boards/nxp/frdm_mcxa156/board.c | 8 +++++++- boards/nxp/frdm_mcxa166/board.c | 6 ++++++ boards/nxp/frdm_mcxa276/board.c | 6 ++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/boards/nxp/frdm_mcxa153/board.c b/boards/nxp/frdm_mcxa153/board.c index 52968d73fabb6..b2376eebbef7b 100644 --- a/boards/nxp/frdm_mcxa153/board.c +++ b/boards/nxp/frdm_mcxa153/board.c @@ -7,6 +7,9 @@ #include #include #include +#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF) +#include +#endif #include /* Core clock frequency: 96MHz */ @@ -151,6 +154,9 @@ void board_early_init_hook(void) */ #if DT_PROP(DT_NODELABEL(lptmr0), clk_source) == 0x1 CLOCK_SetupFRO16KClocking(kCLKE_16K_SYSTEM | kCLKE_16K_COREMAIN); +#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF) + VBAT_EnableFRO16k(VBAT0, true); +#endif #elif DT_PROP(DT_NODELABEL(lptmr0), clk_source) == 0x3 CLOCK_SetClockDiv(kCLOCK_DivLPTMR0, 1u); CLOCK_AttachClk(kFRO12M_to_LPTMR0); diff --git a/boards/nxp/frdm_mcxa156/board.c b/boards/nxp/frdm_mcxa156/board.c index deb6f0eec4499..f7170b62e9e6d 100644 --- a/boards/nxp/frdm_mcxa156/board.c +++ b/boards/nxp/frdm_mcxa156/board.c @@ -1,5 +1,5 @@ /* - * Copyright 2024 NXP + * Copyright 2024-2025 NXP * SPDX-License-Identifier: Apache-2.0 */ #include @@ -7,6 +7,9 @@ #include #include #include +#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF) +#include +#endif #include /* Core clock frequency: 96MHz */ @@ -227,6 +230,9 @@ void board_early_init_hook(void) * 3 <- Combination of clocks configured in MRCC_LPTMR0_CLKSEL[MUX] field */ #if DT_PROP(DT_NODELABEL(lptmr0), clk_source) == 0x1 +#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF) + VBAT_EnableFRO16k(VBAT0, true); +#endif CLOCK_SetupFRO16KClocking(kCLKE_16K_SYSTEM | kCLKE_16K_COREMAIN); #elif DT_PROP(DT_NODELABEL(lptmr0), clk_source) == 0x3 CLOCK_SetClockDiv(kCLOCK_DivLPTMR0, 1u); diff --git a/boards/nxp/frdm_mcxa166/board.c b/boards/nxp/frdm_mcxa166/board.c index 44af603388f79..d339ff9a97f19 100644 --- a/boards/nxp/frdm_mcxa166/board.c +++ b/boards/nxp/frdm_mcxa166/board.c @@ -7,6 +7,9 @@ #include #include #include +#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF) +#include +#endif #include /* Core clock frequency: 180MHz */ @@ -250,6 +253,9 @@ void board_early_init_hook(void) */ #if DT_PROP(DT_NODELABEL(lptmr0), clk_source) == 0x1 CLOCK_SetupFRO16KClocking(kCLKE_16K_SYSTEM | kCLKE_16K_COREMAIN); +#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF) + VBAT_EnableFRO16k(VBAT0, true); +#endif #elif DT_PROP(DT_NODELABEL(lptmr0), clk_source) == 0x3 CLOCK_AttachClk(kFRO_LF_DIV_to_LPTMR0); CLOCK_SetClockDiv(kCLOCK_DivLPTMR0, 1u); diff --git a/boards/nxp/frdm_mcxa276/board.c b/boards/nxp/frdm_mcxa276/board.c index 56f551552dd4f..7a61da389e30a 100644 --- a/boards/nxp/frdm_mcxa276/board.c +++ b/boards/nxp/frdm_mcxa276/board.c @@ -7,6 +7,9 @@ #include #include #include +#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF) +#include +#endif #include /* Core clock frequency: 180MHz */ @@ -255,6 +258,9 @@ void board_early_init_hook(void) */ #if DT_PROP(DT_NODELABEL(lptmr0), clk_source) == 0x1 CLOCK_SetupFRO16KClocking(kCLKE_16K_SYSTEM | kCLKE_16K_COREMAIN); +#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF) + VBAT_EnableFRO16k(VBAT0, true); +#endif #elif DT_PROP(DT_NODELABEL(lptmr0), clk_source) == 0x3 CLOCK_AttachClk(kFRO_LF_DIV_to_LPTMR0); CLOCK_SetClockDiv(kCLOCK_DivLPTMR0, 1u); From a7444d53f43ef743666868dcc514b777336df1cf Mon Sep 17 00:00:00 2001 From: Zhaoxiang Jin Date: Mon, 14 Jul 2025 22:07:19 +0800 Subject: [PATCH 6/7] boards: nxp: mcxn series: Enable FRO16k for LPTMR Enabled FRO16k for LPTMR when LPTMR clock source is set to 0x1. Signed-off-by: Zhaoxiang Jin --- boards/nxp/frdm_mcxn236/board.c | 9 ++++++++- boards/nxp/frdm_mcxn947/board.c | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/boards/nxp/frdm_mcxn236/board.c b/boards/nxp/frdm_mcxn236/board.c index f990251a4f335..7fcd31fd7e303 100644 --- a/boards/nxp/frdm_mcxn236/board.c +++ b/boards/nxp/frdm_mcxn236/board.c @@ -1,5 +1,5 @@ /* - * Copyright 2024 NXP + * Copyright 2024-2025 NXP * SPDX-License-Identifier: Apache-2.0 */ #include @@ -8,6 +8,10 @@ #include #include #include +#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF) +#include +#endif + #if CONFIG_USB_DC_NXP_EHCI #include "usb_phy.h" #include "usb.h" @@ -289,6 +293,9 @@ void board_early_init_hook(void) CLOCK_SetupClockCtrl(kCLOCK_FRO12MHZ_ENA); #elif DT_PROP(DT_NODELABEL(lptmr0), clk_source) == 0x1 CLOCK_SetupClk16KClocking(kCLOCK_Clk16KToVsys); +#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF) + VBAT_EnableFRO16k(VBAT0, true); +#endif #elif DT_PROP(DT_NODELABEL(lptmr0), clk_source) == 0x2 CLOCK_SetupOsc32KClocking(kCLOCK_Osc32kToVsys); #elif DT_PROP(DT_NODELABEL(lptmr0), clk_source) == 0x3 diff --git a/boards/nxp/frdm_mcxn947/board.c b/boards/nxp/frdm_mcxn947/board.c index aa399db64ed8b..7781b8c7ede78 100644 --- a/boards/nxp/frdm_mcxn947/board.c +++ b/boards/nxp/frdm_mcxn947/board.c @@ -1,5 +1,5 @@ /* - * Copyright 2024 NXP + * Copyright 2024-2025 NXP * SPDX-License-Identifier: Apache-2.0 */ #include @@ -8,6 +8,10 @@ #include #include #include +#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF) +#include +#endif + #if CONFIG_USB_DC_NXP_EHCI #include "usb_phy.h" #include "usb.h" @@ -365,6 +369,9 @@ void board_early_init_hook(void) CLOCK_SetupClockCtrl(kCLOCK_FRO12MHZ_ENA); #elif DT_PROP(DT_NODELABEL(lptmr0), clk_source) == 0x1 CLOCK_SetupClk16KClocking(kCLOCK_Clk16KToVsys); +#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF) + VBAT_EnableFRO16k(VBAT0, true); +#endif #elif DT_PROP(DT_NODELABEL(lptmr0), clk_source) == 0x2 CLOCK_SetupOsc32KClocking(kCLOCK_Osc32kToVsys); #elif DT_PROP(DT_NODELABEL(lptmr0), clk_source) == 0x3 From fce2e0165cda20b62de8d13639d6981bb0b7dcbe Mon Sep 17 00:00:00 2001 From: Zhaoxiang Jin Date: Tue, 8 Jul 2025 20:34:54 +0800 Subject: [PATCH 7/7] samples: nxp/mcx: Enable poweroff for MCXA/N series This commit enabled poweroff case for NXP MCXA and MCXN series MCUs. Signed-off-by: Zhaoxiang Jin --- .../boards/nxp/mcx/poweroff/CMakeLists.txt | 8 ++ samples/boards/nxp/mcx/poweroff/Kconfig | 6 ++ samples/boards/nxp/mcx/poweroff/README.rst | 85 +++++++++++++++++++ samples/boards/nxp/mcx/poweroff/app.overlay | 14 +++ samples/boards/nxp/mcx/poweroff/prj.conf | 7 ++ samples/boards/nxp/mcx/poweroff/sample.yaml | 16 ++++ samples/boards/nxp/mcx/poweroff/src/main.c | 51 +++++++++++ 7 files changed, 187 insertions(+) create mode 100644 samples/boards/nxp/mcx/poweroff/CMakeLists.txt create mode 100644 samples/boards/nxp/mcx/poweroff/Kconfig create mode 100644 samples/boards/nxp/mcx/poweroff/README.rst create mode 100644 samples/boards/nxp/mcx/poweroff/app.overlay create mode 100644 samples/boards/nxp/mcx/poweroff/prj.conf create mode 100644 samples/boards/nxp/mcx/poweroff/sample.yaml create mode 100644 samples/boards/nxp/mcx/poweroff/src/main.c diff --git a/samples/boards/nxp/mcx/poweroff/CMakeLists.txt b/samples/boards/nxp/mcx/poweroff/CMakeLists.txt new file mode 100644 index 0000000000000..7ba7517a83f4b --- /dev/null +++ b/samples/boards/nxp/mcx/poweroff/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright 2025 NXP +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(frdm_mcx_poweroff) + +target_sources(app PRIVATE src/main.c) diff --git a/samples/boards/nxp/mcx/poweroff/Kconfig b/samples/boards/nxp/mcx/poweroff/Kconfig new file mode 100644 index 0000000000000..d6a5a0567bea5 --- /dev/null +++ b/samples/boards/nxp/mcx/poweroff/Kconfig @@ -0,0 +1,6 @@ +# Copyright 2025 NXP +# SPDX-License-Identifier: Apache-2.0 + +mainmenu "NXP MCXA/N SERIES POWER OFF DEMO" + +source "Kconfig.zephyr" diff --git a/samples/boards/nxp/mcx/poweroff/README.rst b/samples/boards/nxp/mcx/poweroff/README.rst new file mode 100644 index 0000000000000..701ac45277ca6 --- /dev/null +++ b/samples/boards/nxp/mcx/poweroff/README.rst @@ -0,0 +1,85 @@ +.. zephyr:code-sample:: nxp_mcx_poweroff + :name: NXP MCXA/N Series MCUs Poweroff + :relevant-api: sys_poweroff + + Use poweroff on NXP MCXA/N series MCUs. + +Overview +******** + +This example demonstrates how to power off NXP MCXA/N series MCUs. + +Building, Flashing and Running +****************************** + +Building and Running for NXP FRDM-MCXA153 +========================================= +Build the application for the :zephyr:board:`frdm_mcxa153` board. + +.. zephyr-app-commands:: + :zephyr-app: samples/boards/nxp/mcx/poweroff + :board: frdm_mcxa153 + :goals: build flash + :compact: + +Building and Running for NXP FRDM-MCXA156 +========================================= +Build the application for the :zephyr:board:`frdm_mcxa156` board. + +.. zephyr-app-commands:: + :zephyr-app: samples/boards/nxp/mcx/poweroff + :board: frdm_mcxa156 + :goals: build flash + :compact: + +Building and Running for NXP FRDM-MCXA166 +========================================= +Build the application for the :zephyr:board:`frdm_mcxa166` board. + +.. zephyr-app-commands:: + :zephyr-app: samples/boards/nxp/mcx/poweroff + :board: frdm_mcxa166 + :goals: build flash + :compact: + +Building and Running for NXP FRDM-MCXA276 +========================================= +Build the application for the :zephyr:board:`frdm_mcxa276` board. + +.. zephyr-app-commands:: + :zephyr-app: samples/boards/nxp/mcx/poweroff + :board: frdm_mcxa276 + :goals: build flash + :compact: + +Building and Running for NXP FRDM-MCXN236 +========================================= +Build the application for the :zephyr:board:`frdm_mcxn236/mcxn236` board. + +.. zephyr-app-commands:: + :zephyr-app: samples/boards/nxp/mcx/poweroff + :board: frdm_mcxn236/mcxn236 + :goals: build flash + :compact: + +Building and Running for NXP FRDM-MCXN947 +========================================= +Build the application for the :zephyr:board:`frdm_mcxn947/mcxn947/cpu0` board. + +.. zephyr-app-commands:: + :zephyr-app: samples/boards/nxp/mcx/poweroff + :board: frdm_mcxn947/mcxn947/cpu0 + :goals: build flash + :compact: + +Sample Output +============= +FRDM-MCXA153, FRDM-MCXA156, FRDM-MCXA166, FRDM-MCXA276 FRDM-MCXN236, FRDM-MCXN947 output +---------------------------------------------------------------------------------------- + +.. code-block:: console + + *** Booting Zephyr OS build v4.2.0-rc1-255-gf71b531cb990 *** + Will wakeup after 5 seconds + Press key to power off the system + Powering off diff --git a/samples/boards/nxp/mcx/poweroff/app.overlay b/samples/boards/nxp/mcx/poweroff/app.overlay new file mode 100644 index 0000000000000..8623076f6fdb5 --- /dev/null +++ b/samples/boards/nxp/mcx/poweroff/app.overlay @@ -0,0 +1,14 @@ +/* + * Copyright 2025 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&lptmr0 { + status = "okay"; + timer-mode-sel = <0>; + clk-source = <1>; + clock-frequency = <16384>; + resolution = <32>; + wakeup-source; +}; diff --git a/samples/boards/nxp/mcx/poweroff/prj.conf b/samples/boards/nxp/mcx/poweroff/prj.conf new file mode 100644 index 0000000000000..da097b4d6e289 --- /dev/null +++ b/samples/boards/nxp/mcx/poweroff/prj.conf @@ -0,0 +1,7 @@ +# Copyright 2025 NXP +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_POWEROFF=y +CONFIG_COUNTER=y +CONFIG_CONSOLE_SUBSYS=y +CONFIG_CONSOLE_GETCHAR=y diff --git a/samples/boards/nxp/mcx/poweroff/sample.yaml b/samples/boards/nxp/mcx/poweroff/sample.yaml new file mode 100644 index 0000000000000..598ba4b86df25 --- /dev/null +++ b/samples/boards/nxp/mcx/poweroff/sample.yaml @@ -0,0 +1,16 @@ +# Copyright 2025 NXP +# SPDX-License-Identifier: Apache-2.0 + +sample: + name: Poweroff demo for NXP MCXA/N series +common: + tags: power +tests: + sample.boards.nxp.mcx.poweroff: + platform_allow: + - frdm_mcxa156 + - frdm_mcxa153 + - frdm_mcxa166 + - frdm_mcxa276 + - frdm_mcxn236/mcxn236 + - frdm_mcxn947/mcxn947/cpu0 \ No newline at end of file diff --git a/samples/boards/nxp/mcx/poweroff/src/main.c b/samples/boards/nxp/mcx/poweroff/src/main.c new file mode 100644 index 0000000000000..a422d24af7f15 --- /dev/null +++ b/samples/boards/nxp/mcx/poweroff/src/main.c @@ -0,0 +1,51 @@ +/* + * Copyright 2025 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include + +int main(void) +{ + int ret; + const struct device *dev = DEVICE_DT_GET(DT_NODELABEL(lptmr0)); + + struct counter_top_cfg top_cfg = { + .ticks = counter_us_to_ticks(dev, 5000000), + .callback = NULL, + .user_data = NULL, + .flags = 0, + }; + + console_init(); + + if (!device_is_ready(dev)) { + printf("Counter device not ready\n"); + return 0; + } + + ret = counter_set_top_value(dev, &top_cfg); + + printf("Will wakeup after 5 seconds\n"); + printf("Press key to power off the system\n"); + console_getchar(); + + ret = counter_start(dev); + if (ret < 0) { + printf("Could not start wakeup counter (%d)\n", ret); + return 0; + } + + printf("Powering off\n"); + + sys_poweroff(); + + return 0; +}