Current debugging
2022-11-05 SAT
Contents
^ Overview
In our current debugging we want to make sure we understand Zephyr device tree macros, and in particular how to use these macros to obtain device tree nodes which can be correctly passed to C based, Zephyr sensor API functions. It appears that there are at least some use cases where a pair of macros is needed, and these must be called out in a certain order so that macro expansions take place soon enough to provide correct device tree source tokens for use in the code.
A couple of things we'll want to cover -- not covered yet -- include (1) Zephyr's small set of macros to obtain a device tree node: DT_ALIAS, DT_NODELABEL, DT_PATH, DT_INST, and (2) use of device status or node property tests, as in:
#define SENSOR_INT1_NODE DT_ALIAS(sensorinterrupt1) #if !DT_NODE_HAS_STATUS(SENSOR_INT1_NODE, okay)
Code excerpt from ~11/7, Zephyr device initialization failing before void main(void) yet sensor returns data later:
[00:00:00.009,000] <err> IIS2DH: iis2dh@18: device ������rF����� is not ready [00:00:00.017,000] <err> IIS2DH: Failed to initialize interrupts *** Booting Zephyr OS build zephyr-v3.2.0 *** - scoreboard - in setter function test val holds 0, - scoreboard - setting test val to 5, - DEV 1028 - symbol ST_IIS2DH got assigned 'DT_N_S_soc_S_peripheral_50000000_S_flexcomm_8a000_S_iis2dh_18' - kd_thread_iis2dh - Success finding iis2dh device, - kd_thread_iis2dh - WARNING - sensor device 'iis2dh@18' is not ready! - kd_thread_iis2dh - INFO: device name (Zephyr compile time setting) found to be 'iis2dh@18' - kd_thread_iis2dh - INFO: boot time Zephyr init result value holds 5, - DEV 1101 - WHO_AM_I register 0x0F holds 0x33 - DEV 1101 - config register 0x22 holds 0x10 - FIFO control reg holds 0x4f - updating this value to set watermark at 16 data entries . . . - write_register() returns status of 0,./tests/subsys/pm/device_power_domains/src/main.c:14: const struct device *const reg_0 = DEVICE_DT_GET(DT_NODELABEL(test_reg_0)); ./tests/subsys/pm/device_power_domains/src/main.c:15: const struct device *const reg_1 = DEVICE_DT_GET(DT_NODELABEL(test_reg_1)); ./tests/subsys/pm/device_power_domains/src/main.c:16: const struct device *const reg_chained = DEVICE_DT_GET(DT_NODELABEL(test_reg_chained)); - following update, FIFO control reg holds 0x4f - updating FIFO ctrl register to enable FIFO mode . . . - reading back vale . . . - FIFO ctrl register now holds 0x4F. - kd_thread_iis2dh - unconditionally attempting to configure data ready (drdy-gpios) interrupt, Waiting for triggers - whoami register, ODR register, and ctrl reg 5 hold 0x33, 0x57, 0x40 - whoami register, ODR register, and ctrl reg 5 hold 0x33, 0x57, 0x40 - whoami register, ODR register, and ctrl reg 5 hold 0x33, 0x57, 0x40
^ Device Tree syntax and Undocumented DTS
Examples from Zephyr 3.2.0 of device structure pointer assignments:
./tests/subsys/pm/device_power_domains/src/main.c:14: const struct device *const reg_0 = DEVICE_DT_GET(DT_NODELABEL(test_reg_0)); ./tests/subsys/pm/device_power_domains/src/main.c:15: const struct device *const reg_1 = DEVICE_DT_GET(DT_NODELABEL(test_reg_1)); ./tests/subsys/pm/device_power_domains/src/main.c:16: const struct device *const reg_chained = DEVICE_DT_GET(DT_NODELABEL(test_reg_chained));
Excerpt from Nordic sample source code:
1 /* 2 * Copyright (c) 2019 Nordic Semiconductor ASA. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */[[#top|^]] 6 7 #include <zephyr/drivers/gpio.h> 8 #include <zephyr/drivers/uart.h> 9 #include <zephyr/device.h> 10 #include <zephyr/devicetree.h> 11 12 #define RESET_NODE DT_NODELABEL(nrf52840_reset) 13 14 #if DT_NODE_HAS_STATUS(RESET_NODE, okay) 15 16 #define RESET_GPIO_CTRL DT_GPIO_CTLR(RESET_NODE, gpios) 17 #define RESET_GPIO_PIN DT_GPIO_PIN(RESET_NODE, gpios) 18 #define RESET_GPIO_FLAGS DT_GPIO_FLAGS(RESET_NODE, gpios) 19 20 int bt_hci_transport_setup(const struct device *h4) 21 { 22 int err; 23 char c; 24 const struct device *const port = DEVICE_DT_GET(RESET_GPIO_CTRL); 25 26 if (!device_is_ready(port)) { 27 return -EIO; 28 } 29 30 /* Configure pin as output and initialize it to inactive state. */ 31 err = gpio_pin_configure(port, RESET_GPIO_PIN, 32 RESET_GPIO_FLAGS | GPIO_OUTPUT_INACTIVE); 33 if (err) { 34 return err; 35 } 36 37 /* Reset the nRF52840 and let it wait until the pin is inactive again 38 * before running to main to ensure that it won't send any data until 39 * the H4 device is setup and ready to receive. 40 */ 41 err = gpio_pin_set(port, RESET_GPIO_PIN, 1); 42 if (err) { 43 return err; 44 } 45 46 /* Wait for the nRF52840 peripheral to stop sending data. "./boards/arm/nrf9160dk_nrf9160/nrf52840_reset.c" 67L, 1609C
^ C preprocessor macros and macro expansion rules
C preprocessor macros, macro stringification . . .
C preprocessor tokenization . . .
^ Zephyr dts macros
125 #define SENSOR_INT1_NODE DT_ALIAS(sensorinterrupt1) 126 #if !DT_NODE_HAS_STATUS(SENSOR_INT1_NODE, okay) 127 #error "- DEV 1108 - Could not find in device tree source any sensor interrupt type node!" 128 #endif
^ Zephyr sample apps
Zephyr sample apps to showcase use of dts macros to obtain device nodes at run time . . .
1 /home/ted/projects-sandbox/workspace-for-nexus 2 /home/ted/projects-sandbox/workspace-for-nexus/zephyr 3 /home/ted/projects-sandbox/workspace-for-nexus/zephyr/samples 4 /home/ted/projects-sandbox/workspace-for-nexus/zephyr/samples/basic 5 /home/ted/projects-sandbox/workspace-for-nexus/zephyr/samples/basic/blinky_pwm 6 /home/ted/projects-sandbox/workspace-for-nexus/zephyr/drivers/sensor/iis2dh 7 /home/ted/projects-sandbox/workspace-for-nexus/zephyr/samples/drivers/uart/stm32/single_wire