NRF Connect GPIO access with gpio_dt_spec

Is there a working example with using gpio_dt_spec for accessing gpios?

I used the code provided from https://docs.zephyrproject.org/latest/reference/peripherals/gpio.html#c.GPIO_DT_SPEC_GET_BY_IDX 

But it can not resolve the macros for the Devicetree.

Parents
  • In file included from /home/rico/projects/mst/firmware-ncs/zephyr/include/toolchain/gcc.h:66,
    from /home/rico/projects/mst/firmware-ncs/zephyr/include/toolchain.h:50,
    from /home/rico/projects/mst/firmware-ncs/zephyr/include/kernel_includes.h:19,
    from /home/rico/projects/mst/firmware-ncs/zephyr/include/kernel.h:17,
    from /home/rico/projects/mst/firmware-ncs/zephyr/include/zephyr.h:18,
    from /home/rico/projects/mst/firmware-ncs/application/src/main.c:7:
    /home/rico/projects/mst/firmware-ncs/zephyr/include/device.h:81:39: error: '__device_dts_ord_DT_N_S_node_P_foo_gpios_IDX_1_PH_ORD' undeclared here (not in a function)
    81 | #define DEVICE_NAME_GET(name) _CONCAT(__device_, name)
    | ^~~~~~~~~
    /home/rico/projects/mst/firmware-ncs/zephyr/include/toolchain/common.h:124:26: note: in definition of macro '_DO_CONCAT'
    124 | #define _DO_CONCAT(x, y) x ## y
    | ^
    /home/rico/projects/mst/firmware-ncs/zephyr/include/device.h:81:31: note: in expansion of macro '_CONCAT'
    81 | #define DEVICE_NAME_GET(name) _CONCAT(__device_, name)
    | ^~~~~~~
    /home/rico/projects/mst/firmware-ncs/zephyr/include/device.h:233:37: note: in expansion of macro 'DEVICE_NAME_GET'
    233 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_NAME(node_id))
    | ^~~~~~~~~~~~~~~
    /home/rico/projects/mst/firmware-ncs/zephyr/include/device.h:247:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
    247 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
    | ^~~~~~~~~~~~~~~~~~
    /home/rico/projects/mst/firmware-ncs/zephyr/include/drivers/gpio.h:363:11: note: in expansion of macro 'DEVICE_DT_GET'
    363 | .port = DEVICE_DT_GET(DT_GPIO_CTLR_BY_IDX(node_id, prop, idx)),\
    | ^~~~~~~~~~~~~
    /home/rico/projects/mst/firmware-ncs/application/src/main.c:37:35: note: in expansion of macro 'GPIO_DT_SPEC_GET_BY_IDX'
    37 | const struct gpio_dt_spec spec = GPIO_DT_SPEC_GET_BY_IDX(DT_NODELABEL(n),
    |

Reply
  • In file included from /home/rico/projects/mst/firmware-ncs/zephyr/include/toolchain/gcc.h:66,
    from /home/rico/projects/mst/firmware-ncs/zephyr/include/toolchain.h:50,
    from /home/rico/projects/mst/firmware-ncs/zephyr/include/kernel_includes.h:19,
    from /home/rico/projects/mst/firmware-ncs/zephyr/include/kernel.h:17,
    from /home/rico/projects/mst/firmware-ncs/zephyr/include/zephyr.h:18,
    from /home/rico/projects/mst/firmware-ncs/application/src/main.c:7:
    /home/rico/projects/mst/firmware-ncs/zephyr/include/device.h:81:39: error: '__device_dts_ord_DT_N_S_node_P_foo_gpios_IDX_1_PH_ORD' undeclared here (not in a function)
    81 | #define DEVICE_NAME_GET(name) _CONCAT(__device_, name)
    | ^~~~~~~~~
    /home/rico/projects/mst/firmware-ncs/zephyr/include/toolchain/common.h:124:26: note: in definition of macro '_DO_CONCAT'
    124 | #define _DO_CONCAT(x, y) x ## y
    | ^
    /home/rico/projects/mst/firmware-ncs/zephyr/include/device.h:81:31: note: in expansion of macro '_CONCAT'
    81 | #define DEVICE_NAME_GET(name) _CONCAT(__device_, name)
    | ^~~~~~~
    /home/rico/projects/mst/firmware-ncs/zephyr/include/device.h:233:37: note: in expansion of macro 'DEVICE_NAME_GET'
    233 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_NAME(node_id))
    | ^~~~~~~~~~~~~~~
    /home/rico/projects/mst/firmware-ncs/zephyr/include/device.h:247:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
    247 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
    | ^~~~~~~~~~~~~~~~~~
    /home/rico/projects/mst/firmware-ncs/zephyr/include/drivers/gpio.h:363:11: note: in expansion of macro 'DEVICE_DT_GET'
    363 | .port = DEVICE_DT_GET(DT_GPIO_CTLR_BY_IDX(node_id, prop, idx)),\
    | ^~~~~~~~~~~~~
    /home/rico/projects/mst/firmware-ncs/application/src/main.c:37:35: note: in expansion of macro 'GPIO_DT_SPEC_GET_BY_IDX'
    37 | const struct gpio_dt_spec spec = GPIO_DT_SPEC_GET_BY_IDX(DT_NODELABEL(n),
    |

Children
Related