README.rst
1.. _samples_boards_nrf_dynamic_pinctrl:
2
3Dynamic Pin Control (nRF)
4#########################
5
6The Dynamic Pin Control (nRF) sample demonstrates how to change ``uart0`` at
7early boot stages, depending on the input level on a pin connected to a
8push-button.
9
10Overview
11********
12
13Slightly different board revisions that implement just small changes (like
14improving the PCB layout or changing components to new equivalents) do not
15necessarily require changes to the firmware. As such, one firmware image can be
16able to boot onto multiple board revisions.
17
18However, if a certain peripheral is routed to different sets of pins between
19revisions, the firmware needs to select the appropriate routing when the
20system is initialized.
21
22The Dynamic Pin Control (nRF) sample allows you to select the appropriate routing.
23
24If the push button is not pressed, the system does nothing and continues with
25the default configuration. If the button is pressed, the alternative
26configuration is applied.
27
28Alternative configurations can only be applied if the device driver using the
29associated pins has not been initialized yet. Therefore, pay attention to the
30initialization priorities set in the :file:`prj.conf` file.
31
32nRF52840 DK
33===========
34
35The diagram below shows the pins assigned to the default and alternative
36configurations.
37
38.. figure:: images/nrf52840dk-dynamic-pinctrl.png
39
40 Configuration for nRF52840 DK
41
42If you power on the board, the ``uart0`` peripheral is routed to the default
43set of pins. The default set of pins is also exposed through the left USB
44connector as a virtual COM port.
45
46If you power on the board while holding Button 1, the ``uart0`` peripheral is
47routed to the alternative set of pins.
48
49Building and Running
50********************
51
52You can build this application for the nRF52840 DK as follows:
53
54.. zephyr-app-commands::
55 :zephyr-app: samples/boards/nrf/dynamic_pinctrl
56 :board: nrf52840dk_nrf52840
57 :goals: build
58 :compact:
59
60The sample can also support other nRF based boards if you provide a Devicetree
61overlay file with an alternative configuration for ``uart0``. Select ``uart0``
62for ``zephyr,console`` to make the sample work as expected.
63
64Sample Output
65=============
66
67Follow these steps to test the two configurations :
68
691. Connect a USB-to-UART adapter to both sets of pins. If the board routes the
70 default configuration to a virtual COM port (as in the nRF52840 DK), you can
71 directly use that port.
72
73#. Open two serial terminals, one connected to the default set of pins and the
74 other connected to the alternative set of pins.
75
76 .. figure:: images/terminals-empty.png
77
78 Two serial terminals (left: default, right: alternative).
79
80#. Turn on the board. You should see a ``Hello World!`` message printed on
81 the first terminal.
82
83 .. figure:: images/terminals-default.png
84
85 ``Hello World!`` printed on the default set of pins.
86
87#. Press and hold the configuration-selection push-button (button 1 on the
88 nRF52840 DK) and press the board reset button. You now should see a
89 ``Hello World!`` message on the second terminal.
90
91 .. figure:: images/terminals-alt.png
92
93 ``Hello World!`` printed on the alternative set of pins.
94