Browse Source

samples: shields: npm2100_ek sample

A sample show-casing the core functionalities of the nPM2100 PMIC using
the nPM2100 EK as a shield.

Signed-off-by: Sergei Ovchinnikov <sergei.ovchinnikov@nordicsemi.no>
pull/90054/head
Sergei Ovchinnikov 5 months ago committed by Benjamin Cabé
parent
commit
05c7fadf95
  1. 6
      boards/shields/npm2100_ek/npm2100_ek.overlay
  2. 12
      samples/shields/npm2100_ek/CMakeLists.txt
  3. 10
      samples/shields/npm2100_ek/boards/nrf52840dk_nrf52840.overlay
  4. 10
      samples/shields/npm2100_ek/boards/nrf5340dk_nrf5340_cpuapp.overlay
  5. 147
      samples/shields/npm2100_ek/doc/index.rst
  6. 14
      samples/shields/npm2100_ek/npm2100_ek_buttons.overlay
  7. 17
      samples/shields/npm2100_ek/prj.conf
  8. 10
      samples/shields/npm2100_ek/sample.yaml
  9. 86
      samples/shields/npm2100_ek/src/main.c

6
boards/shields/npm2100_ek/npm2100_ek.overlay

@ -43,13 +43,15 @@ @@ -43,13 +43,15 @@
npm2100_buttons: buttons {
compatible = "gpio-keys";
pmic_button0: pmic_button_0 {
gpios = < &npm2100_gpio 0 GPIO_ACTIVE_LOW>;
gpios = <&npm2100_gpio 0 GPIO_ACTIVE_LOW>;
label = "Pmic button switch 0";
zephyr,code = <INPUT_KEY_0>;
};
pmic_button1: pmic_button_1 {
gpios = < &npm2100_gpio 1 GPIO_ACTIVE_LOW>;
gpios = <&npm2100_gpio 1 GPIO_ACTIVE_LOW>;
label = "Pmic button switch 1";
zephyr,code = <INPUT_KEY_1>;
};

12
samples/shields/npm2100_ek/CMakeLists.txt

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
# Copyright (c) 2025 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.20.0)
set(SHIELD npm2100_ek)
set(EXTRA_DTC_OVERLAY_FILE npm2100_ek_buttons.overlay)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(npm2100_ek)
target_sources(app PRIVATE src/main.c)

10
samples/shields/npm2100_ek/boards/nrf52840dk_nrf52840.overlay

@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
/*
* Copyright (C) 2025 Nordic Semiconductor ASA
* SPDX-License-Identifier: Apache-2.0
*/
&i2c0_default {
group1 {
bias-pull-up;
};
};

10
samples/shields/npm2100_ek/boards/nrf5340dk_nrf5340_cpuapp.overlay

@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
/*
* Copyright (C) 2025 Nordic Semiconductor ASA
* SPDX-License-Identifier: Apache-2.0
*/
&i2c1_default {
group1 {
bias-pull-up;
};
};

147
samples/shields/npm2100_ek/doc/index.rst

@ -0,0 +1,147 @@ @@ -0,0 +1,147 @@
.. zephyr:code-sample:: npm2100_ek
:name: nPM2100 EK
Interact with the nPM2100 PMIC using the EK buttons and the shell interface.
Overview
********
This sample is provided for evaluation of the :ref:`npm2100_ek`.
It is an example of how the nPM2100 GPIO pins and the shell
interface can be used to control the following features:
- Regulators (BOOST, LDOSW)
- GPIO
Requirements
************
The sample supports the following boards: :zephyr:board:`nrf52840dk`, :zephyr:board:`nrf5340dk`
The sample also requires an nPM2100 Evaluation Kit (EK) that you need to connect to the
development kit as described in `Wiring`_.
Wiring
******
With this configuration, the nPM2100 EK is wired to supply power to the DK.
This ensures that the TWI communication is at compatible voltage level, and represents a realistic use case for the nPM2100 PMIC.
.. note::
To prevent leakage currents and program the DK, do not remove the USB connection.
Unplug the battery from the nPM2100 EK and set the DK power switch to "OFF" while
applying the wiring.
If you have issues communicating with the DK or programming it after applying the wiring, try to power cycle the DK and EK.
To connect your DK to the nPM2100 EK, complete the following steps:
#. Prepare the DK for being powered by the nPM2100 EK:
- Set switch **SW9** ("nRF power source") to position "VDD".
- Set switch **SW10** ("VEXT -> VnRF") to position "ON".
#. Connect the TWI interface and power supply between the chosen DK and the nPM2100 EK
as described in the following table:
+------------------+-------+-------+-----------------------+-----+
| nPM2100 EK pins | SDA | SCL | VOUT | GND |
+------------------+-------+-------+-----------------------+-----+
| nRF52840 DK pins | P0.26 | P0.27 | P21 External supply + | GND |
+------------------+-------+-------+-----------------------+-----+
| nRF5340 DK pins | P1.02 | P1.03 | P21 External supply + | GND |
+------------------+-------+-------+-----------------------+-----+
#. Make the following connections on the nPM2100 EK:
- Remove the USB power supply from the **J4** connector.
- On the **P6** pin header, connect pins 1 and 2 with a jumper.
- On the **BOOTMON** pin header, select **OFF** with a jumper.
- On the **VSET** pin header, select **3.0V** with a jumper.
- On the **VBAT SEL** switch, select **VBAT** position.
- Connect a battery board to the **BATTERY INPUT** connector.
Building and Running
********************
To build the sample use the following command:
.. zephyr-app-commands::
:zephyr-app: samples/shields/npm2100_ek
:board: nrf52840dk/nrf52840
:goals: build
:compact:
.. note::
This sample automatically sets the ``SHIELD`` to ``npm2100_ek``.
Once you have flashed the software to your device, boot into the shell interface.
Use the ``regulator`` command to test the PMIC.
See the following section for details on the subcommands.
Regulator control
*****************
If the initialization was successful, the terminal displays the following message
with status information:
.. code-block:: console
PMIC device ok
The sample also reports the battery and boost output voltages as well as the die
temperature measured every two seconds.
Use the buttons on the EK to control the regulators as follows:
+---------------------------+----------------------------------+
| Operation | Outcome |
+---------------------------+----------------------------------+
| Button **GPIO0** pressed | BOOST output forced into HP mode |
+---------------------------+----------------------------------+
| Button **GPIO0** released | BOOST output operates in LP mode |
+---------------------------+----------------------------------+
| Button **GPIO1** pressed | Load Switch on |
+---------------------------+----------------------------------+
| Button **GPIO1** released | Load Switch off |
+---------------------------+----------------------------------+
The ``regulator`` shell interface provides several subcommand to test
the regulators embedded in the PMIC.
To list all supported voltages for a regulator, run the following command:
.. code-block:: console
uart:~$ regulator vlist BOOST
1.800000 V
1.850000 V
...
To enable or disable a regulator, run the following commands:
.. code-block:: console
uart:~$ regulator enable LDOSW
uart:~$ regulator disable LDOSW
.. note::
The BOOST regulator is always enabled.
To set the output voltage of a regulator, run the following command:
.. code-block:: console
uart:~$ regulator vset BOOST 2.5v
uart:~$ regulator vget BOOST
2.500000 V
.. note::
The BOOST regulator cannot provide a voltage lower than the battery voltage.
To get the GPIO status, run the following command:
.. code-block:: console
uart:~$ gpio get npm2100_gpio 0
0

14
samples/shields/npm2100_ek/npm2100_ek_buttons.overlay

@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
/*
* Copyright (C) 2025 Nordic Semiconductor ASA
* SPDX-License-Identifier: Apache-2.0
*/
/* Set GPIO pins as inputs controlling features of the respective regulators */
&npm2100_boost {
mode-gpios = <&npm2100_gpio 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
};
&npm2100_ldosw {
mode-gpios = <&npm2100_gpio 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
};

17
samples/shields/npm2100_ek/prj.conf

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
# Copyright (c) 2025 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
CONFIG_SHELL=y
CONFIG_LOG=y
CONFIG_LOG_CMDS=y
CONFIG_GPIO=y
CONFIG_GPIO_SHELL=y
CONFIG_REGULATOR=y
CONFIG_REGULATOR_SHELL=y
CONFIG_WATCHDOG=y
CONFIG_WDT_SHELL=y
CONFIG_SENSOR=y
CONFIG_SENSOR_SHELL=y
CONFIG_I2C=y
CONFIG_I2C_SHELL=y
CONFIG_I2C_LOG_LEVEL_WRN=y

10
samples/shields/npm2100_ek/sample.yaml

@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
# Copyright (c) 2025 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
sample:
name: nPM2100 EK
tests:
sample.shields.npm2100_ek:
harness: shield
tags: shield
depends_on: arduino_i2c

86
samples/shields/npm2100_ek/src/main.c

@ -0,0 +1,86 @@ @@ -0,0 +1,86 @@
/*
* Copyright (c) 2025 Nordic Semiconductor ASA
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/device.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/regulator.h>
#include <zephyr/drivers/sensor.h>
#include <zephyr/dt-bindings/regulator/npm2100.h>
#define UPDATE_TIME_MS 2000
static const struct device *boost = DEVICE_DT_GET(DT_NODELABEL(npm2100_boost));
static const struct device *ldosw = DEVICE_DT_GET(DT_NODELABEL(npm2100_ldosw));
static const struct device *vbat = DEVICE_DT_GET(DT_NODELABEL(npm2100_vbat));
int setup_regulators(void)
{
int err;
/* boost to operate in Low Power mode by default, force High Power on GPIO0 active */
err = regulator_set_mode(boost, NPM2100_REG_OPER_LP | NPM2100_REG_FORCE_HP);
if (err != 0) {
return err;
}
/* LDOSW to operate as a Load Switch: off by default, on when GPIO1 active */
err = regulator_set_mode(ldosw,
NPM2100_REG_OPER_OFF | NPM2100_REG_FORCE_HP | NPM2100_REG_LDSW_EN);
if (err != 0) {
return err;
}
return regulator_enable(ldosw);
}
void display_sensor_values(void)
{
struct sensor_value v_battery;
struct sensor_value v_out;
struct sensor_value temp;
sensor_sample_fetch(vbat);
sensor_channel_get(vbat, SENSOR_CHAN_GAUGE_VOLTAGE, &v_battery);
sensor_channel_get(vbat, SENSOR_CHAN_VOLTAGE, &v_out);
sensor_channel_get(vbat, SENSOR_CHAN_DIE_TEMP, &temp);
printk("VBat: %d.%03d ", v_battery.val1, v_battery.val2 / 1000);
printk("VOut: %d.%03d ", v_out.val1, v_out.val2 / 1000);
printk("T: %s%d.%02d\n", ((temp.val1 < 0) || (temp.val2 < 0)) ? "-" : "", abs(temp.val1),
abs(temp.val2) / 10000);
}
int main(void)
{
int err;
if (!device_is_ready(ldosw)) {
printk("Error: LDOSW device is not ready\n");
return -ENODEV;
}
if (!device_is_ready(boost)) {
printk("Error: BOOST device is not ready\n");
return -ENODEV;
}
if (!device_is_ready(vbat)) {
printk("Error: vbat device is not ready\n");
return -ENODEV;
}
err = setup_regulators();
if (err != 0) {
printk("Error: failed to set regulator modes\n");
return err;
}
printk("PMIC device ok\n");
while (1) {
display_sensor_values();
k_msleep(UPDATE_TIME_MS);
}
}
Loading…
Cancel
Save