1.. _npm6001_ek_sample:
2
3nPM6001 EK sample
4#################
5
6Overview
7********
8
9This sample is provided as an example to test the :ref:`npm6001_ek`. The sample
10provides a shell interface that allows to test multiple functionalities offered
11by the nPM6001 PMIC, including:
12
13- Regulators (BUCK0/1/2/3 and LDO0/1)
14- GPIO
15- Watchdog
16
17Requirements
18************
19
20The shield needs to be wired to a host board supporting the Arduino connector.
21Below you can find a wiring example for the nRF52840 DK:
22
23.. figure:: nrf52840dk_wiring.jpg
24   :alt: nRF52840DK + nPM6001-EK wiring example
25   :align: center
26
27   nRF52840DK + nPM6001-EK wiring example
28
29Building and Running
30********************
31
32The sample is designed so that it can run on any platform. For example, when
33building for the nRF52840 DK, the following command can be used:
34
35.. zephyr-app-commands::
36   :zephyr-app: samples/shields/npm6001_ek
37   :board: nrf52840dk_nrf52840
38   :goals: build
39   :compact:
40
41Note that this sample automatically sets ``SHIELD`` to ``npm6001_ek``. Once
42flashed, you should boot into the shell interface. The ``npm6001`` command is
43provided to test the PMIC. Below you can find details for each subcommand.
44
45Regulators
46==========
47
48The ``npm6001`` shell interface provides the ``regulator`` subcommand to test
49the regulators embedded in the PMIC (BUCK0/1/2/3 and LDO0/1). Below you can
50find some command examples.
51
52.. code-block:: bash
53
54   # list all the available regulators
55   npm6001 regulator list
56   BUCK0
57   BUCK1
58   BUCK2
59   BUCK3
60   LDO0
61   LDO1
62
63.. code-block:: bash
64
65   # list all the supported voltages by BUCK2
66   npm6001 regulator voltages BUCK2
67   1200 mV
68   1250 mV
69   1300 mV
70   1350 mV
71   1400 mV
72
73.. code-block:: bash
74
75   # enable BUCK3
76   npm6001 regulator enable BUCK3
77   # disable BUCK3
78   npm6001 regulator disable BUCK3
79
80.. code-block:: bash
81
82   # set BUCK3 voltage to exactly 3000 mV
83   npm6001 regulator set BUCK3 3000
84   # obtain the actual BUCK3 configured voltage
85   npm6001 regulator get BUCK3
86   3000 mV
87   # set BUCK0 voltage to a value between 2350 mV and 2450 mV
88   npm6001 regulator set BUCK0 2350 2450
89   # obtain the actual BUCK0 configured voltage
90   npm6001 regulator get BUCK3
91   2400 mV
92
93.. code-block:: bash
94
95   # set BUCK0 to hysteretic mode
96   npm6001 regulator modeset BUCK0 hys
97   # set BUCK0 to PWM mode
98   npm6001 regulator modeset BUCK0 pwm
99
100.. code-block:: bash
101
102   # get BUCK0 mode
103   npm6001 regulator modeget BUCK0
104   Hysteretic
105
106.. code-block:: bash
107
108   # get active errors on BUCK0
109   npm6001 regulator errors BUCK0
110   Overcurrent:    [ ]
111   Overtemp.:      [ ]
112
113GPIO
114====
115
116The ``npm6001`` shell interface provides the ``gpio`` subcommand to test the
117GPIO functionality offered by the PMIC. Below you can find some command
118examples.
119
120.. code-block:: bash
121
122   # configure GPIO 0 as output
123   npm6001 gpio configure -p 0 -d out
124   # configure GPIO 0 as output (init high)
125   npm6001 gpio configure -p 0 -d outh
126   # configure GPIO 0 as output (init low)
127   npm6001 gpio configure -p 0 -d outl
128   # configure GPIO 0 as output with high-drive mode enabled
129   npm6001 gpio configure -p 0 -d out --high-drive
130   # configure GPIO 1 as input
131   npm6001 gpio configure -p 1 -d input
132   # configure GPIO 1 as input with pull-down enabled
133   npm6001 gpio configure -p 1 -d input --pull-down
134   # configure GPIO 1 as input with CMOS mode enabled
135   npm6001 gpio configure -p 1 -d input --cmos
136
137.. code-block:: bash
138
139   # get GPIO 1 level
140   npm6001 gpio get 1
141
142.. code-block:: bash
143
144   # set GPIO 0 high
145   npm6001 gpio set 0 1
146   # set GPIO 0 low
147   npm6001 gpio set 0 0
148
149.. code-block:: bash
150
151   # toggle GPIO 0
152   npm6001 gpio toggle 0
153
154Watchdog
155========
156
157The ``npm6001`` shell interface provides the ``wdt`` subcommand to test the
158Watchdog functionality offered by the PMIC. Below you can find some command
159examples.
160
161.. code-block:: bash
162
163   # enable watchdog, timeout set to 8 seconds. Timeout will be rounded up to
164   # the resolution of the watchdog, e.g. 10s -> 12s.
165   npm6001 wdt enable 8000
166   # disable watchdog
167   npm6001 wdt disable
168   # kick/feed watchdog
169   npm6001 wdt kick
170
171.. note::
172   When the watchdog reset pin is connected to your board reset, you will see
173   how Zephyr reboots after the watchdog timeout expires.
174