In this exercise, the goal is to get the application building after getting an error related to the devicetree.
Open the code base of the exercise by navigating to Create a new application in the nRF Connect for VS Code extension, select Copy a sample, and search for Lesson 2 – Exercise 3. Make sure to use the version directory that matches the SDK version you are using. This is a simple application that prints a message every time button 1 is pressed.
Alternatively, in the GitHub repository for this course, go to the base code for this exercise, found in l2/l2_e3
of whichever version directory you are using.
1. Build the application.
This build should fail and give an error similar to below:
error: '__device_dts_ord_11' undeclared here (not in a function); did you mean '__device_dts_ord_15'?
85 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
| ^~~~~~~~~
ncs/v2.5.0/zephyr/include/zephyr/toolchain/common.h:132:26: note: in definition of macro '_DO_CONCAT'
132 | #define _DO_CONCAT(x, y) x ## y
| ^
ncs/v2.5.0/zephyr/include/zephyr/device.h:85:33: note: in expansion of macro '_CONCAT'
85 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
| ^~~~~~~
ncs/v2.5.0/zephyr/include/zephyr/device.h:211:37: note: in expansion of macro 'DEVICE_NAME_GET'
211 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))
| ^~~~~~~~~~~~~~~
ncs/v2.5.0/zephyr/include/zephyr/device.h:228:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
228 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
| ^~~~~~~~~~~~~~~~~~
ncs/v2.5.0/zephyr/include/zephyr/drivers/gpio.h:331:25: note: in expansion of macro 'DEVICE_DT_GET'
331 | .port = DEVICE_DT_GET(DT_GPIO_CTLR_BY_IDX(node_id, prop, idx)),\
| ^~~~~~~~~~~~~
ncs/v2.5.0/zephyr/include/zephyr/drivers/gpio.h:367:9: note: in expansion of macro 'GPIO_DT_SPEC_GET_BY_IDX'
367 | GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, 0)
| ^~~~~~~~~~~~~~~~~~~~~~~
lesson2/Exercise3/src/main.c:15:40: note: in expansion of macro 'GPIO_DT_SPEC_GET'
15 | static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
Terminal2. Find the ID in the error message.
The build log shows we have a device error seen by __device_dts_ord_11
The “11” Node identifier. This node identifier can say something about the devicetree instance that is at fault. When you have the node identifier, you can look it up in <build>l2_e3/zephyr/include/generated/devicetree_generated.h
and find the ID found in the error message.
3. Investigate the reason for the build failure.
In the devicetree_generated.h we can see the following:
*
* Generated by gen_defines.py
*
* DTS input file:
* /home/rusi/Documents/ncs-inter/lesson2/Exercise1/Lesson2_exercise1/build/zephyr/zephyr.dts.pre
*
* Directories with bindings:
* /home/rusi/ncs/v2.5.0/nrf/dts/bindings, $ZEPHYR_BASE/dts/bindings
*
* Node dependency ordering (ordinal and path):
* 0 /
* 1 /aliases
* 2 /analog-connector
* 3 /chosen
* 4 /connector
* 5 /entropy_bt_hci
* 6 /soc
* 7 /soc/interrupt-controller@e000e100
* 8 /soc/timer@40009000
* 9 /sw-pwm
* 10 /buttons
* 11 /soc/gpio@50000000
* 12 /buttons/button_0
* 13 /buttons/button_1
* 14 /buttons/button_2
* 15 /buttons/button_3
* 16 /cpus
* 17 /cpus/cpu@0
* 18 /cpus/cpu@0/itm@e0000000
* 19 /leds
.....
DevicetreeOur error message said the error was related to device id 11. In this case we can see it the /soc/gpio@50000000. The next step then should be to look at this module and ask the following questions:
CONFIG_GPIO=y
4. Fix the issue by enabling gpio0.
By now, the error should be clear. As we can see in zephyr.dts
, the gpio0 is disabled
gpio0: gpio@50000000 {
compatible = "nordic,nrf-gpio";
gpio-controller;
reg = <0x50000000 0x200
0x50000500 0x300>;
#gpio-cells = <2>;
status = "disabled";
port = <0>;
};
DevicetreeAnd in the overlay for the selected device, we can see the following:
&gpio0 {
status = "disabled";
};
DevicetreeTo fix the application, enable gpio0
by changing the overlay file of your build target to the following
&gpio0 {
status = "okay";
};
Devicetree5. Pristine build the application.
Do a pristine build since we have made changes to our overlay. The application should now build.
The devicetree can be overwhelming when moving from a bare metal environment but should give some clues on how to solve potential errors you might face during development.
In this exercise, the goal is to get the application building after getting an error related to the devicetree.
Open the code base of the exercise by navigating to Create a new application in the nRF Connect for VS Code extension, select Copy a sample, and search for Lesson 2 – Exercise 3. Make sure to use the version directory that matches the SDK version you are using. This is a simple application that prints a message every time button 1 is pressed.
Alternatively, in the GitHub repository for this course, go to the base code for this exercise, found in l2/l2_e3
of whichever version directory you are using.
1. Build the application.
This build should fail and give an error similar to below:
error: '__device_dts_ord_11' undeclared here (not in a function); did you mean '__device_dts_ord_15'?
85 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
| ^~~~~~~~~
ncs/v2.5.0/zephyr/include/zephyr/toolchain/common.h:132:26: note: in definition of macro '_DO_CONCAT'
132 | #define _DO_CONCAT(x, y) x ## y
| ^
ncs/v2.5.0/zephyr/include/zephyr/device.h:85:33: note: in expansion of macro '_CONCAT'
85 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
| ^~~~~~~
ncs/v2.5.0/zephyr/include/zephyr/device.h:211:37: note: in expansion of macro 'DEVICE_NAME_GET'
211 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))
| ^~~~~~~~~~~~~~~
ncs/v2.5.0/zephyr/include/zephyr/device.h:228:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
228 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
| ^~~~~~~~~~~~~~~~~~
ncs/v2.5.0/zephyr/include/zephyr/drivers/gpio.h:331:25: note: in expansion of macro 'DEVICE_DT_GET'
331 | .port = DEVICE_DT_GET(DT_GPIO_CTLR_BY_IDX(node_id, prop, idx)),\
| ^~~~~~~~~~~~~
ncs/v2.5.0/zephyr/include/zephyr/drivers/gpio.h:367:9: note: in expansion of macro 'GPIO_DT_SPEC_GET_BY_IDX'
367 | GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, 0)
| ^~~~~~~~~~~~~~~~~~~~~~~
lesson2/Exercise3/src/main.c:15:40: note: in expansion of macro 'GPIO_DT_SPEC_GET'
15 | static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
Terminal2. Find the ID in the error message.
The build log shows we have a device error seen by __device_dts_ord_11
The “11” Node identifier. This node identifier can say something about the devicetree instance that is at fault. When you have the node identifier, you can look it up in <build>/zephyr/include/generated/devicetree_generated.h
and find the ID found in the error message.
3. Investigate the reason for the build failure.
In the devicetree_generated.h we can see the following:
*
* Generated by gen_defines.py
*
* DTS input file:
* /home/rusi/Documents/ncs-inter/lesson2/Exercise1/Lesson2_exercise1/build/zephyr/zephyr.dts.pre
*
* Directories with bindings:
* /home/rusi/ncs/v2.5.0/nrf/dts/bindings, $ZEPHYR_BASE/dts/bindings
*
* Node dependency ordering (ordinal and path):
* 0 /
* 1 /aliases
* 2 /analog-connector
* 3 /chosen
* 4 /connector
* 5 /entropy_bt_hci
* 6 /soc
* 7 /soc/interrupt-controller@e000e100
* 8 /soc/timer@40009000
* 9 /sw-pwm
* 10 /buttons
* 11 /soc/gpio@50000000
* 12 /buttons/button_0
* 13 /buttons/button_1
* 14 /buttons/button_2
* 15 /buttons/button_3
* 16 /cpus
* 17 /cpus/cpu@0
* 18 /cpus/cpu@0/itm@e0000000
* 19 /leds
.....
DevicetreeOur error message said the error was related to device id 11. In this case we can see it the /soc/gpio@50000000. The next step then should be to look at this module and ask the following questions:
CONFIG_GPIO=y
4. Fix the issue by enabling gpio0.
By now, the error should be clear. As we can see in zephyr.dts
, the gpio0 is disabled
gpio0: gpio@50000000 {
compatible = "nordic,nrf-gpio";
gpio-controller;
reg = <0x50000000 0x200
0x50000500 0x300>;
#gpio-cells = <2>;
status = "disabled";
port = <0>;
};
DevicetreeAnd in the overlay for the selected device, we can see the following:
&gpio0 {
status = "disabled";
};
DevicetreeTo fix the application, enable gpio0
by changing the overlay file of your build target to the following
&gpio0 {
status = "okay";
};
Devicetree5. Pristine build the application.
Do a pristine build since we have made changes to our overlay. The application should now build.
The devicetree can be overwhelming when moving from a bare metal environment but should give some clues on how to solve potential errors you might face during development.