Skip to content

Enable poweroff feature on NXP MCXA and MCXN series MCUs. #92844

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

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions boards/nxp/frdm_mcxa153/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include <zephyr/dt-bindings/clock/mcux_lpc_syscon_clock.h>
#include <fsl_clock.h>
#include <fsl_spc.h>
#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF)
#include <fsl_vbat.h>
#endif
#include <soc.h>

/* Core clock frequency: 96MHz */
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion boards/nxp/frdm_mcxa156/board.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
/*
* Copyright 2024 NXP
* Copyright 2024-2025 NXP
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/init.h>
#include <zephyr/device.h>
#include <zephyr/dt-bindings/clock/mcux_lpc_syscon_clock.h>
#include <fsl_clock.h>
#include <fsl_spc.h>
#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF)
#include <fsl_vbat.h>
#endif
#include <soc.h>

/* Core clock frequency: 96MHz */
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions boards/nxp/frdm_mcxa166/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include <zephyr/dt-bindings/clock/mcux_lpc_syscon_clock.h>
#include <fsl_clock.h>
#include <fsl_spc.h>
#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF)
#include <fsl_vbat.h>
#endif
#include <soc.h>

/* Core clock frequency: 180MHz */
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions boards/nxp/frdm_mcxa276/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include <zephyr/dt-bindings/clock/mcux_lpc_syscon_clock.h>
#include <fsl_clock.h>
#include <fsl_spc.h>
#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF)
#include <fsl_vbat.h>
#endif
#include <soc.h>

/* Core clock frequency: 180MHz */
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion boards/nxp/frdm_mcxn236/board.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 NXP
* Copyright 2024-2025 NXP
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/init.h>
Expand All @@ -8,6 +8,10 @@
#include <fsl_clock.h>
#include <fsl_spc.h>
#include <soc.h>
#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF)
#include <fsl_vbat.h>
#endif

#if CONFIG_USB_DC_NXP_EHCI
#include "usb_phy.h"
#include "usb.h"
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion boards/nxp/frdm_mcxn236/frdm_mcxn236-pinctrl.dtsi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 NXP
* Copyright 2024-2025 NXP
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -14,6 +14,7 @@
slew-rate = "fast";
drive-strength = "low";
input-enable;
bias-pull-up;
};
};

Expand Down Expand Up @@ -48,6 +49,7 @@
slew-rate = "fast";
drive-strength = "low";
input-enable;
bias-pull-up;
};
};

Expand Down
9 changes: 8 additions & 1 deletion boards/nxp/frdm_mcxn947/board.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 NXP
* Copyright 2024-2025 NXP
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/init.h>
Expand All @@ -8,6 +8,10 @@
#include <fsl_clock.h>
#include <fsl_spc.h>
#include <soc.h>
#if defined(CONFIG_PM) || defined(CONFIG_POWEROFF)
#include <fsl_vbat.h>
#endif

#if CONFIG_USB_DC_NXP_EHCI
#include "usb_phy.h"
#include "usb.h"
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion boards/nxp/frdm_mcxn947/frdm_mcxn947-pinctrl.dtsi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 NXP
* Copyright 2024-2025 NXP
* SPDX-License-Identifier: Apache-2.0
*/

Expand Down Expand Up @@ -62,6 +62,7 @@
slew-rate = "fast";
drive-strength = "low";
input-enable;
bias-pull-up;
};
};

Expand All @@ -72,6 +73,7 @@
slew-rate = "fast";
drive-strength = "low";
input-enable;
bias-pull-up;
};
};

Expand Down
5 changes: 5 additions & 0 deletions modules/hal_nxp/mcux/mcux-sdk-ng/drivers/drivers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions samples/boards/nxp/mcx/poweroff/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions samples/boards/nxp/mcx/poweroff/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright 2025 NXP
# SPDX-License-Identifier: Apache-2.0

mainmenu "NXP MCXA/N SERIES POWER OFF DEMO"

source "Kconfig.zephyr"
85 changes: 85 additions & 0 deletions samples/boards/nxp/mcx/poweroff/README.rst
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions samples/boards/nxp/mcx/poweroff/app.overlay
Original file line number Diff line number Diff line change
@@ -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;
};
7 changes: 7 additions & 0 deletions samples/boards/nxp/mcx/poweroff/prj.conf
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions samples/boards/nxp/mcx/poweroff/sample.yaml
Original file line number Diff line number Diff line change
@@ -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
51 changes: 51 additions & 0 deletions samples/boards/nxp/mcx/poweroff/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2025 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <stdio.h>
#include <zephyr/drivers/counter.h>
#include <zephyr/sys/poweroff.h>
#include <zephyr/sys_clock.h>
#include <zephyr/console/console.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/printk.h>

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;
}
Loading
Loading