Skip to content

Commit a99e520

Browse files
committed
samples: nxp/mcxa: Enable poweroff for MCXA series
This commit enabled poweroff case for NXP MCXA series. Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
1 parent 8b051b5 commit a99e520

File tree

7 files changed

+165
-0
lines changed

7 files changed

+165
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright 2025 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.20.0)
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(frdm_mcxa_poweroff)
7+
8+
target_sources(app PRIVATE src/main.c)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright 2025 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
mainmenu "NXP MCXA SERIES POWER OFF DEMO"
5+
6+
source "Kconfig.zephyr"
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
.. zephyr:code-sample:: nxp_mcx_mcxa_poweroff
2+
:name: NXP MCXA Series MCUs Poweroff
3+
:relevant-api: sys_poweroff
4+
5+
Use poweroff on NXP MCXA series MCUs.
6+
7+
Overview
8+
********
9+
10+
This example demonstrates how to power off NXP MCXA series MCUs.
11+
12+
Building, Flashing and Running
13+
******************************
14+
15+
Building and Running for NXP FRDM-MCXA153
16+
=========================================
17+
Build the application for the :zephyr:board:`frdm_mcxa153` board.
18+
19+
.. zephyr-app-commands::
20+
:zephyr-app: samples/boards/nxp/mcx/mcxa/poweroff
21+
:board: frdm_mcxa153
22+
:goals: build flash
23+
:compact:
24+
25+
Building and Running for NXP FRDM-MCXA156
26+
=========================================
27+
Build the application for the :zephyr:board:`frdm_mcxa156` board.
28+
29+
.. zephyr-app-commands::
30+
:zephyr-app: samples/boards/nxp/mcx/mcxa/poweroff
31+
:board: frdm_mcxa156
32+
:goals: build flash
33+
:compact:
34+
35+
Building and Running for NXP FRDM-MCXA166
36+
=========================================
37+
Build the application for the :zephyr:board:`frdm_mcxa166` board.
38+
39+
.. zephyr-app-commands::
40+
:zephyr-app: samples/boards/nxp/mcx/mcxa/poweroff
41+
:board: frdm_mcxa166
42+
:goals: build flash
43+
:compact:
44+
45+
Building and Running for NXP FRDM-MCXA276
46+
=========================================
47+
Build the application for the :zephyr:board:`frdm_mcxa276` board.
48+
49+
.. zephyr-app-commands::
50+
:zephyr-app: samples/boards/nxp/mcx/mcxa/poweroff
51+
:board: frdm_mcxa276
52+
:goals: build flash
53+
:compact:
54+
55+
Sample Output
56+
=================
57+
FRDM-MCXA153, FRDM-MCXA156, FRDM-MCXA166, FRDM-MCXA276 output
58+
-------------------------------------------------------------
59+
60+
.. code-block:: console
61+
62+
*** Booting Zephyr OS build v4.2.0-rc1-255-gf71b531cb990 ***
63+
Will wakeup after 5 seconds
64+
Press key to power off the system
65+
Powering off
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
&lptmr0 {
8+
status = "okay";
9+
timer-mode-sel = <0>;
10+
clk-source = <1>;
11+
clock-frequency = <16384>;
12+
resolution = <32>;
13+
wakeup-source;
14+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright 2025 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_POWEROFF=y
5+
CONFIG_COUNTER=y
6+
CONFIG_CONSOLE_SUBSYS=y
7+
CONFIG_CONSOLE_GETCHAR=y
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2025 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
sample:
5+
name: Poweroff demo for NXP MCXA series
6+
common:
7+
tags: power
8+
tests:
9+
sample.boards.nxp.mcx.mcxa.poweroff:
10+
platform_allow:
11+
- frdm_mcxa156
12+
- frdm_mcxa153
13+
- frdm_mcxa166
14+
- frdm_mcxa276
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <stdio.h>
8+
#include <zephyr/drivers/counter.h>
9+
#include <zephyr/sys/poweroff.h>
10+
#include <zephyr/sys_clock.h>
11+
#include <zephyr/console/console.h>
12+
#include <zephyr/kernel.h>
13+
#include <zephyr/sys/printk.h>
14+
15+
int main(void)
16+
{
17+
int ret;
18+
const struct device *dev = DEVICE_DT_GET(DT_NODELABEL(lptmr0));
19+
20+
struct counter_top_cfg top_cfg = {
21+
.ticks = counter_us_to_ticks(dev, 5000000),
22+
.callback = NULL,
23+
.user_data = NULL,
24+
.flags = 0,
25+
};
26+
27+
console_init();
28+
29+
if (!device_is_ready(dev)) {
30+
printf("Counter device not ready\n");
31+
return 0;
32+
}
33+
34+
ret = counter_set_top_value(dev, &top_cfg);
35+
36+
printf("Will wakeup after 5 seconds\n");
37+
printf("Press key to power off the system\n");
38+
console_getchar();
39+
40+
ret = counter_start(dev);
41+
if (ret < 0) {
42+
printf("Could not start wakeup counter (%d)\n", ret);
43+
return 0;
44+
}
45+
46+
printf("Powering off\n");
47+
48+
sys_poweroff();
49+
50+
return 0;
51+
}

0 commit comments

Comments
 (0)