Skip to content
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
18 changes: 17 additions & 1 deletion samples/boards/nxp/mimxrt595_evk/system_off/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,23 @@ sample:
name: Deep Power Down State Sample for mimxrt595_evk
common:
tags: power
harness: power
harness_config:
fixture: pm_probe
pytest_dut_scope: session
power_measurements:
elements_to_trim: 100
min_peak_distance: 40
min_peak_height: 0.008
peak_padding: 40
measurement_duration: 20
num_of_transitions: 6
expected_rms_values: []
tolerance_percentage: 20
record:
regex:
- "not used"
as_json: ['metrics']
tests:
sample.boards.mimxrt595_evk.system_off:
build_only: true
platform_allow: mimxrt595_evk/mimxrt595s/cm33
8 changes: 8 additions & 0 deletions samples/drivers/adc/adc_power_shield/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(ADC)

target_sources(app PRIVATE src/main.c)
15 changes: 15 additions & 0 deletions samples/drivers/adc/adc_power_shield/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) 2024 Centro de Inovacao EDGE.
# SPDX-License-Identifier: Apache-2.0

config SEQUENCE_SAMPLES
int "Number of samples to be made on the sequence for each channel."
default 5

config SEQUENCE_RESOLUTION
int "Set the resolution of the sequence readings."
default 12

config SEQUENCE_32BITS_REGISTERS
bool "ADC data sequences are on 32bits"

source "Kconfig.zephyr"
80 changes: 80 additions & 0 deletions samples/drivers/adc/adc_power_shield/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
.. zephyr:code-sample:: adc_power_shield
:name: Analog-to-Digital Converter (ADC) power shield sample
:relevant-api: adc_interface

Read analog inputs from ADC channels, using a sequence.

Overview
********

This sample is to enable general power shield for platfroms that have ADC support.


Building and Running
********************

Make sure that the ADC is enabled (``status = "okay";``) and has each channel as a
child node, with your desired settings like gain, reference, or acquisition time and
oversampling setting (if used). It is also needed to provide an alias ``adc0`` for the
desired adc. See :zephyr_file:`boards/nrf52840dk_nrf52840.overlay
<samples/drivers/adc/adc_dt/boards/nrf52840dk_nrf52840.overlay>` for an example of
such setup.
Comment on lines +2 to +21
Copy link
Contributor

@kartben kartben Sep 4, 2025

Choose a reason for hiding this comment

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

All of this is very stale and copied from the original sample (related: do you really need to duplicate the 100s of overlays too??). I have to admit I don't really understand what this is trying to accomplish and the fact that the README hasn't been updated is not really helping.
Just a thought but, if you are calling this a "shield" then maybe you want to create an actual shield (or snippet?), and not a sample?

Copy link
Contributor Author

@hakehuang hakehuang Sep 5, 2025

Choose a reason for hiding this comment

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

@kartben, the sample application is modified from adc_sequence sample. The idea here is to create a general power shield, which means any adc featured zephyr platform can be used as a power shield. so we can take any of those 100s boards and flashed with this sample, you can use them as general_power_shield fixture for measuring power, see the https://github.com/zephyrproject-rtos/zephyr/blob/af6248f8b7509f505982b8fe5d6e9a6efd8bc0f5/scripts/pylib/power-twister-harness/README.rst this is a full picture for the usage.
the sample readme is just describe how the sample runs.

Copy link
Contributor Author

@hakehuang hakehuang Sep 5, 2025

Choose a reason for hiding this comment

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

I want to provide a platform agonic solution, such as any same feature Zephyr platform can function as the same.

image image the is a demo setup for general power measurement.

Copy link
Contributor

Choose a reason for hiding this comment

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

This comment thread still applies IMO. I am sorry if I am missing something but simply copying an existing code sample (and its dozens of overlays!) and then calling this a "shield" while shields are something completely different in Zephyr is really incredibly confusing.
Please don't ask for re-review when comments havne't been addressed - the README being an exact copy-paste of the original sample is also pretty problematic. Thanks!


Building and Running for Nordic nRF52840
========================================

The sample can be built and executed for the
:zephyr:board:`nrf52840dk` as follows:

.. zephyr-app-commands::
:zephyr-app: samples/drivers/adc/adc_sequence
:board: nrf52840dk/nrf52840
:goals: build flash
:compact:

To build for another board, change "nrf52840dk/nrf52840" above to that board's name
and provide a corresponding devicetree overlay.

Sample output
=============

the output as below, repeated every time you input any char in the console:

.. code-block:: console

ADC sequence reading [1]:
- ADC_0, channel 0, 5 sequence samples:
- - 36 = 65mV
- - 35 = 63mV
- - 36 = 65mV
- - 35 = 63mV
- - 36 = 65mV
- ADC_0, channel 1, 5 sequence samples:
- - 0 = 0mV
- - 0 = 0mV
- - 1 = 1mV
- - 0 = 0mV
- - 1 = 1mV

.. note:: If the ADC is not supported, the output will be an error message.

You should get similar output as below, if you input a return:

.. code-block:: console

==== start of adc features ===
CHANNEL_COUNT: 4
Resolution: 12
channel_id 0 features:
- is single mode
- verf is 3300 mv
channel_id 3 features:
- is single mode
- verf is 3300 mv
channel_id 4 features:
- is single mode
- verf is 3300 mv
channel_id 7 features:
- is single mode
- verf is 3300 mv
==== end of adc features ===
44 changes: 44 additions & 0 deletions samples/drivers/adc/adc_power_shield/boards/arduino_due.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2024 Centro de Inovacao EDGE
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
aliases {
adc0 = &adc0;
};
};

&adc0 {
#address-cells = <1>;
#size-cells = <0>;
status = "okay";

pinctrl-0 = <&adc0_default>;
pinctrl-names = "default";

prescaler = <9>;
startup-time = <64>;
settling-time = <3>;
tracking-time = <2>;

/* External ADC(+) */
channel@6 { // Connector A1
reg = <6>;
zephyr,gain = "ADC_GAIN_1";
zephyr,reference = "ADC_REF_EXTERNAL0";
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
zephyr,input-positive = <6>;
zephyr,vref-mv = <3300>;
};

channel@7 { // Connector A0
reg = <7>;
zephyr,gain = "ADC_GAIN_1";
zephyr,reference = "ADC_REF_EXTERNAL0";
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
zephyr,input-positive = <7>;
zephyr,vref-mv = <3300>;
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2024 Nordic Semiconductor ASA
* Copyright (c) 2025 Ezurio LLC
*/

/ {
zephyr,user {
io-channels = <&adc 0>, <&adc 1>, <&adc 2>, <&adc 7>;
};
};

/ {
aliases {
adc0 = &adc;
};
};

&adc {
#address-cells = <1>;
#size-cells = <0>;

channel@0 {
reg = <0>;
zephyr,gain = "ADC_GAIN_1";
zephyr,reference = "ADC_REF_INTERNAL";
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
zephyr,input-positive = <NRF_SAADC_AIN4>; /* P1.11 */
zephyr,resolution = <10>;
};

channel@1 {
reg = <1>;
zephyr,gain = "ADC_GAIN_1";
zephyr,reference = "ADC_REF_INTERNAL";
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
zephyr,input-positive = <NRF_SAADC_AIN2>; /* P1.06 */
zephyr,resolution = <12>;
zephyr,oversampling = <8>;
};

channel@2 {
reg = <2>;
zephyr,gain = "ADC_GAIN_1";
zephyr,reference = "ADC_REF_INTERNAL";
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
zephyr,input-positive = <NRF_SAADC_DVDD>; /* 0.9 V internal */
zephyr,resolution = <12>;
zephyr,oversampling = <8>;
};

channel@7 {
reg = <7>;
zephyr,gain = "ADC_GAIN_1";
zephyr,reference = "ADC_REF_INTERNAL";
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
zephyr,input-positive = <NRF_SAADC_AIN6>; /* P1.13 */
zephyr,input-negative = <NRF_SAADC_AIN7>; /* P1.14 */
zephyr,resolution = <12>;
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2024 Nordic Semiconductor ASA
* Copyright (c) 2025 Ezurio LLC
*/

/ {
zephyr,user {
io-channels = <&adc 0>, <&adc 1>, <&adc 2>, <&adc 7>;
};
};

/ {
aliases {
adc0 = &adc;
};
};

&adc {
#address-cells = <1>;
#size-cells = <0>;

channel@0 {
reg = <0>;
zephyr,gain = "ADC_GAIN_1";
zephyr,reference = "ADC_REF_INTERNAL";
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
zephyr,input-positive = <NRF_SAADC_AIN4>; /* P1.11 */
zephyr,resolution = <10>;
};

channel@1 {
reg = <1>;
zephyr,gain = "ADC_GAIN_1";
zephyr,reference = "ADC_REF_INTERNAL";
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
zephyr,input-positive = <NRF_SAADC_AIN2>; /* P1.06 */
zephyr,resolution = <12>;
zephyr,oversampling = <8>;
};

channel@2 {
reg = <2>;
zephyr,gain = "ADC_GAIN_1";
zephyr,reference = "ADC_REF_INTERNAL";
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
zephyr,input-positive = <NRF_SAADC_DVDD>; /* 0.9 V internal */
zephyr,resolution = <12>;
zephyr,oversampling = <8>;
};

channel@7 {
reg = <7>;
zephyr,gain = "ADC_GAIN_1";
zephyr,reference = "ADC_REF_INTERNAL";
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
zephyr,input-positive = <NRF_SAADC_AIN6>; /* P1.13 */
zephyr,input-negative = <NRF_SAADC_AIN7>; /* P1.14 */
zephyr,resolution = <12>;
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_SEQUENCE_RESOLUTION=12
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2024 Centro de Inovacao EDGE
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/dt-bindings/adc/adc.h>

/ {
aliases {
adc0 = &adc0;
};
};

&adc0 {
status = "okay";
#address-cells = <1>;
#size-cells = <0>;

channel@0 {
reg = <0>;
zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 1)>;
zephyr,gain = "ADC_GAIN_1";
zephyr,reference = "ADC_REF_INTERNAL";
zephyr,input-positive = <0>; /* P10.0 */
};

channel@1 {
reg = <1>;
zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 1)>;
zephyr,gain = "ADC_GAIN_1";
zephyr,reference = "ADC_REF_INTERNAL";
zephyr,input-positive = <1>; /* P10.1 */
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_SEQUENCE_RESOLUTION=12
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2024 Centro de Inovacao EDGE
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/dt-bindings/adc/adc.h>

/ {
aliases {
adc0 = &adc0;
};
};

&adc0 {
status = "okay";
#address-cells = <1>;
#size-cells = <0>;

channel@0 {
reg = <0>;
zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 1)>;
zephyr,gain = "ADC_GAIN_1";
zephyr,reference = "ADC_REF_INTERNAL";
zephyr,input-positive = <2>; /* P10.2 */
};

channel@1 {
reg = <1>;
zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 1)>;
zephyr,gain = "ADC_GAIN_1";
zephyr,reference = "ADC_REF_INTERNAL";
zephyr,input-positive = <3>; /* P10.3 */
};
};
1 change: 1 addition & 0 deletions samples/drivers/adc/adc_power_shield/boards/frdm_k64f.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_ADC_MCUX_ADC16_VREF_ALTERNATE=y
Loading
Loading