Problems driving a GPIO pin directly

When I follow the use_gpio_pin_directly manual I get a compilation error:

```

/home/gal/dev/ism330bx_driver_contribution/zephyr/include/zephyr/devicetree.h:196:36: error: 'DT_N_NODELABEL_user_dbg_pin_P_gpios_IDX_0_VAL_pin' undeclared (first use in this function)
196 | #define DT_NODELABEL(label) DT_CAT(DT_N_NODELABEL_, label)

```

Why doesn't it find the gpios?

Here's a small main():

int main(void)
{
int cnt = 0;
char out_str[64];
struct sensor_value odr_attr;
const struct device *const ism330bx_dev = DEVICE_DT_GET_ONE(st_ism330bx);

if (!device_is_ready(ism330bx_dev)) {
printk("sensor: device not ready.\n");
return 0;
}

static const struct gpio_dt_spec ism330bx_power =
GPIO_DT_SPEC_GET(DT_NODELABEL(user_dbg_pin), gpios);
}

Here's my DTS:

#include <zephyr/dt-bindings/sensor/ism330bx.h>
// /home/gal/dev/ism330bx_driver_contribution/zephyr/include/zephyr/dt-bindings/sensor/ism330bx.h
/ {
model = "ISM sample board";

ism330bx_on: ism330bx-on {
compatible = "nordic,gpio-pins";
gpios = <&gpio1 1 GPIO_ACTIVE_LOW>;
status = "okay";
};
};


&gpio1 {
status = "okay";
};

&spi1 {
status = "okay";
pinctrl-0 = <&ism330bx_default>;
pinctrl-1 = <&ism330bx_sleep>;
pinctrl-names = "default", "sleep";
compatible = "nordic,nrf-spim";
cs-gpios = <&gpio1 10 GPIO_ACTIVE_LOW>;
ism330bx@0 {
compatible = "st,ism330bx";
reg = <0>;
accel-range = <ISM330BX_ACCL_DT_FS_2G>;
accel-odr = <ISM330BX_ACCL_DT_ODR_OFF>;
gyro-range = <ISM330BX_GYRO_DT_FS_125DPS>;
gyro-odr = <ISM330BX_GYRO_DT_ODR_OFF>;

int1-gpios = <&gpio1 14 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>;
// int2-gpios = <&gpio1 5 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>; // TODO: Disable this pin in the driver init()
// power_resources = <&ism330bx_on>;
spi-max-frequency = <8000000>;
};
};


&pinctrl {
// ism330bx
ism330bx_default: ism330bx_default {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 1, 11)>,
<NRF_PSEL(SPIM_MOSI, 1, 12)>,
<NRF_PSEL(SPIM_MISO, 1, 13)>;
};
};

ism330bx_sleep: ism330bx_sleep {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 1, 11)>,
<NRF_PSEL(SPIM_MOSI, 1, 12)>,
<NRF_PSEL(SPIM_MISO, 1, 13)>;
low-power-enable;
};
};
};

Parents
  • Hi,

    In your code you're referencing a node named 'user_dbg_pin' but this is not included in the devictree you posted, hence the build error. Maybe you meant to reference 'ism330bx_on'? 

    Best regards,

    Vidar

  • A stupid copy-paste mistake by me :(

    Update: when getting the right node from the dts:


    int main(void)
    {
    int cnt = 0;
    char out_str[64];
    struct sensor_value odr_attr;
    const struct device *const ism330bx_dev = DEVICE_DT_GET_ONE(st_ism330bx);

    if (!device_is_ready(ism330bx_dev)) {
    printk("sensor: device not ready.\n");
    return 0;
    }

    static const struct gpio_dt_spec ism330bx_power =
    GPIO_DT_SPEC_GET(DT_NODELABEL(ism330bx_on), gpios);
    if (!device_is_ready(&ism330bx_power)) {
    printk("power: device not ready.\n");
    return 0;
    }
    gpio_pin_configure_dt(&ism330bx_power, GPIO_OUTPUT_INACTIVE);
    int ret = gpio_pin_set_dt(&ism330bx_power, 0);
    if (ret < 0) {
    printk("Error %d: Failed to set pin %d to high\n", ret, ism330bx_power.pin);
    // Handle error
    } else {
    printk("Successfully set pin %d to high (1)\n", ism330bx_power.pin);
    }
    }
     

    It is still failing to compile:

    /home/gal/dev/ism330bx_driver_contribution/zephyr/samples/sensor/ism330bx/build_nrf52840dk/ism330bx/zephyr/include/generated/zephyr/devicetree_generated.h:762:38: error: 'DT_N_S_ism330bx_on_P_gpios_IDX_0_VAL_pin' undeclared (first use in this function); did you mean 'DT_N_S_leds_S_led_1_P_gpios_IDX_0_VAL_pin'?
    762 | #define DT_N_NODELABEL_ism330bx_on DT_N_S_ism330bx_on

    Thanks, Gal

  • Hello,

    I'm not able to spot what the error is now. To help troubleshoot this, please check if the generated zephyr.dts in build_nrf52840dk/ism330bx/zephyr/ actually contains the ism330bx_on node. Also, if there are any references to 'ism330bx_on' in build_nrf52840dk/ism330bx/zephyr/include/generated/zephyr/devicetree_generated.h.

    Best regards.

    Vidar

  • Yes it appears, here's a fractions of it:

    Generated by gen_defines.py
    *
    * DTS input file:
    * /home/gal/dev/ism330bx_driver_contribution/zephyr/samples/sensor/ism330bx/build_nrf52840dk/ism330bx/zephyr/zephyr.dts.pre
    *
    * Directories with 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 /ism330bx-on <-------------------------
    * 7 /soc
    * 8 /soc/interrupt-controller@e000e100
    ...
    ...
    /*
    * Devicetree node: /ism330bx-on
    *
    * Node identifier: DT_N_S_ism330bx_on
    */

    /* Node's full path: */
    #define DT_N_S_ism330bx_on_PATH "/ism330bx-on"

    /* Node's name with unit-address: */
    #define DT_N_S_ism330bx_on_FULL_NAME "ism330bx-on"
    #define DT_N_S_ism330bx_on_FULL_NAME_UNQUOTED ism330bx-on
    #define DT_N_S_ism330bx_on_FULL_NAME_TOKEN ism330bx_on
    #define DT_N_S_ism330bx_on_FULL_NAME_UPPER_TOKEN ISM330BX_ON

    /* Node parent (/) identifier: */
    #define DT_N_S_ism330bx_on_PARENT DT_N

    /* Node's index in its parent's list of children: */
    #define DT_N_S_ism330bx_on_CHILD_IDX 13

    /* Helpers for dealing with node labels: */
    #define DT_N_S_ism330bx_on_NODELABEL_NUM 1
    #define DT_N_S_ism330bx_on_FOREACH_NODELABEL(fn) fn(ism330bx_on)
    #define DT_N_S_ism330bx_on_FOREACH_NODELABEL_VARGS(fn, ...) fn(ism330bx_on, __VA_ARGS__)
    #define DT_N_S_ism330bx_on_FOREACH_ANCESTOR(fn) fn(DT_N)

    /* Helper macros for child nodes of this node. */
    #define DT_N_S_ism330bx_on_CHILD_NUM 0
    #define DT_N_S_ism330bx_on_CHILD_NUM_STATUS_OKAY 0
    #define DT_N_S_ism330bx_on_FOREACH_CHILD(fn)
    #define DT_N_S_ism330bx_on_FOREACH_CHILD_SEP(fn, sep)
    #define DT_N_S_ism330bx_on_FOREACH_CHILD_VARGS(fn, ...)
    #define DT_N_S_ism330bx_on_FOREACH_CHILD_SEP_VARGS(fn, sep, ...)
    #define DT_N_S_ism330bx_on_FOREACH_CHILD_STATUS_OKAY(fn)
    #define DT_N_S_ism330bx_on_FOREACH_CHILD_STATUS_OKAY_SEP(fn, sep)
    #define DT_N_S_ism330bx_on_FOREACH_CHILD_STATUS_OKAY_VARGS(fn, ...)
    #define DT_N_S_ism330bx_on_FOREACH_CHILD_STATUS_OKAY_SEP_VARGS(fn, sep, ...)

    /* Node's hash: */
    #define DT_N_S_ism330bx_on_HASH RK7rhp0es0wa45nQAzQVLQIhlYlTg93LHE8rLVlodbE

    /* Node's dependency ordinal: */
    #define DT_N_S_ism330bx_on_ORD 6
    #define DT_N_S_ism330bx_on_ORD_STR_SORTABLE 00006

    /* Ordinals for what this node depends on directly: */
    #define DT_N_S_ism330bx_on_REQUIRES_ORDS \
    0, /* / */

    /* Ordinals for what depends directly on this node: */
    #define DT_N_S_ism330bx_on_SUPPORTS_ORDS /* nothing */

    /* Existence and alternate IDs: */
    #define DT_N_S_ism330bx_on_EXISTS 1
    #define DT_N_INST_0_nordic_gpio_pins DT_N_S_ism330bx_on
    #define DT_N_NODELABEL_ism330bx_on DT_N_S_ism330bx_on

    /* Macros for properties that are special in the specification: */
    #define DT_N_S_ism330bx_on_REG_NUM 0
    #define DT_N_S_ism330bx_on_RANGES_NUM 0
    #define DT_N_S_ism330bx_on_FOREACH_RANGE(fn)
    #define DT_N_S_ism330bx_on_IRQ_NUM 0
    #define DT_N_S_ism330bx_on_IRQ_LEVEL 0
    #define DT_N_S_ism330bx_on_COMPAT_MATCHES_nordic_gpio_pins 1
    #define DT_N_S_ism330bx_on_COMPAT_VENDOR_IDX_0_EXISTS 1
    #define DT_N_S_ism330bx_on_COMPAT_VENDOR_IDX_0 "Nordic Semiconductor"
    #define DT_N_S_ism330bx_on_COMPAT_MODEL_IDX_0_EXISTS 1
    #define DT_N_S_ism330bx_on_COMPAT_MODEL_IDX_0 "gpio-pins"
    #define DT_N_S_ism330bx_on_STATUS_okay 1

    /* Pin control (pinctrl-<i>, pinctrl-names) properties: */
    #define DT_N_S_ism330bx_on_PINCTRL_NUM 0

    /* Generic property macros: */
    #define DT_N_S_ism330bx_on_P_compatible {"nordic,gpio-pins"}
    #define DT_N_S_ism330bx_on_P_compatible_IDX_0_EXISTS 1
    #define DT_N_S_ism330bx_on_P_compatible_IDX_0 "nordic,gpio-pins"
    #define DT_N_S_ism330bx_on_P_compatible_IDX_0_STRING_UNQUOTED nordic,gpio-pins
    #define DT_N_S_ism330bx_on_P_compatible_IDX_0_STRING_TOKEN nordic_gpio_pins
    #define DT_N_S_ism330bx_on_P_compatible_IDX_0_STRING_UPPER_TOKEN NORDIC_GPIO_PINS
    #define DT_N_S_ism330bx_on_P_compatible_FOREACH_PROP_ELEM(fn) fn(DT_N_S_ism330bx_on, compatible, 0)
    #define DT_N_S_ism330bx_on_P_compatible_FOREACH_PROP_ELEM_SEP(fn, sep) fn(DT_N_S_ism330bx_on, compatible, 0)
    #define DT_N_S_ism330bx_on_P_compatible_FOREACH_PROP_ELEM_VARGS(fn, ...) fn(DT_N_S_ism330bx_on, compatible, 0, __VA_ARGS__)
    #define DT_N_S_ism330bx_on_P_compatible_FOREACH_PROP_ELEM_SEP_VARGS(fn, sep, ...) fn(DT_N_S_ism330bx_on, compatible, 0, __VA_ARGS__)
    #define DT_N_S_ism330bx_on_P_compatible_LEN 1
    #define DT_N_S_ism330bx_on_P_compatible_EXISTS 1
    #define DT_N_S_ism330bx_on_P_status "okay"
    #define DT_N_S_ism330bx_on_P_status_STRING_UNQUOTED okay
    #define DT_N_S_ism330bx_on_P_status_STRING_TOKEN okay
    #define DT_N_S_ism330bx_on_P_status_STRING_UPPER_TOKEN OKAY
    #define DT_N_S_ism330bx_on_P_status_IDX_0 "okay"
    #define DT_N_S_ism330bx_on_P_status_IDX_0_EXISTS 1
    #define DT_N_S_ism330bx_on_P_status_IDX_0_ENUM_IDX 1
    #define DT_N_S_ism330bx_on_P_status_IDX_0_ENUM_VAL_okay_EXISTS 1
    #define DT_N_S_ism330bx_on_P_status_ENUM_VAL_okay_EXISTS 1
    #define DT_N_S_ism330bx_on_P_status_FOREACH_PROP_ELEM(fn) fn(DT_N_S_ism330bx_on, status, 0)
    #define DT_N_S_ism330bx_on_P_status_FOREACH_PROP_ELEM_SEP(fn, sep) fn(DT_N_S_ism330bx_on, status, 0)
    #define DT_N_S_ism330bx_on_P_status_FOREACH_PROP_ELEM_VARGS(fn, ...) fn(DT_N_S_ism330bx_on, status, 0, __VA_ARGS__)
    #define DT_N_S_ism330bx_on_P_status_FOREACH_PROP_ELEM_SEP_VARGS(fn, sep, ...) fn(DT_N_S_ism330bx_on, status, 0, __VA_ARGS__)
    #define DT_N_S_ism330bx_on_P_status_LEN 1
    #define DT_N_S_ism330bx_on_P_status_EXISTS 1
    I really dont see DT_N_S_ism330bx_on_P_gpios_IDX_0_VAL_pin in the devicetree_generated.h
    Also, here it is from the /home/gal/dev/ism330bx_driver_contribution/zephyr/samples/sensor/ism330bx/build_nrf52840dk/ism330bx/zephyr/zephyr.dts file:

    /* node '/ism330bx-on' defined in zephyr/samples/sensor/ism330bx/boards/nrf52840dk_nrf52840.overlay:6 */
    ism330bx_on: ism330bx-on {
    compatible = "nordic,gpio-pins"; /* in zephyr/samples/sensor/ism330bx/boards/nrf52840dk_nrf52840.overlay:7 */
    gpios = < &gpio1 0x1 0x1 >; /* in zephyr/samples/sensor/ism330bx/boards/nrf52840dk_nrf52840.overlay:8 */
    status = "okay"; /* in zephyr/samples/sensor/ism330bx/boards/nrf52840dk_nrf52840.overlay:9 */
    };
    In addition:
    NCS sdk version: 3.1.0
    Zephyr version: 4.2.99 
    Hope it helps. Please help me figure this out Pray
  • I've not been able to reproduce this build error here even though I copied the code from your post here. Please try to build the project attached below for nrf52840dk/nrf52840 and see if you get the same result. 

    direct_gpio.zip

Reply Children
No Data
Related