Hi I have a few sensors that I've wired up on a breadboard, and I want to connect one to a simple GPIO RX pin and another to a pair of UART RX/TX lines on a STM32L496G-Disco board. I'm utilizing Zephyr OS, and thus DeviceTree.
However, the STM32L496G-Disco seems to only have an Arduino shield header for it's I/O ports. When trying to create a device overlay to set a single pin (specifically A0 as a GPIO) I get a cascade of errors due to not setting the full thing up as an Arduino shield.
Is there something I'm missing when creating a DTS for only a single pin, and not creating a full on shield?
Tried creating a simple GPIO Tx with an overlay as such...
/{
leds{
compatible = "gpio-keys";
led0: led_0 {
gpios = <&gpioc 4 GPIO_ACTIVE_HIGH>;
};
};
};
but gets errors when initializing it with....
#include <zephyr/device.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#define LED0_NODE DT_NODELABEL(led0)
#define LED_GPIO DT_GPIO_LABEL(LED0_NODE, gpios)
#define LED_PIN DT_GPIO_PIN(LED0_NODE, gpios)
#define LED_FLAGS DT_GPIO_FLAGS(LED0_NODE, gpios)
void main(void) {
// get the GPIO device
const struct device * dev = device_get_binding(LED_GPIO);
// configure the LED pin as output
gpio_pin_configure(dev, LED_PIN, GPIO_OUTPUT | LED_FLAGS);
// loop forever
while (1) {
gpio_pin_toggle(dev, LED_PIN);
k_msleep(1000);
}
}
Specific Error:
/Zephyr/zephyrproject/build/zephyr/include/generated/devicetree_generated.h:14695:83: error: 'DT_N_S_soc_S_pin_controller_48000000_S_gpio_48000800_P_label' undeclared (first use in this function); did you mean 'DT_N_S_soc_S_pin_controller_48000000_S_gpio_48000800_P_reg'?
14695 | #define DT_N_S_soc_S_pin_controller_48000000_S_gpio_keys_S_led_0_P_gpios_IDX_0_PH DT_N_S_soc_S_pin_controller_48000000_S_gpio_48000800
Thank you!
According to the documentation for the latest version of Zephyr,
DT_GPIO_LABELis deprecated (https://docs.zephyrproject.org/3.3.0/build/dts/api/api.html#c.DT_GPIO_LABEL), you should replace your use of it withDEVICE_DT_NAME(DT_GPIO_CTLR(LED0_NODE, gpios)); or better, replacedevice_get_binding()entirely withDEVICE_DT_GET(DT_GPIO_CTLR(LED0_NODE, gpios))to get the device structure pointer at compile time instead of runtime.The reason why
DT_GPIO_LABELdoes not work is that it explicitly attempts to get thelabelproperty from the GPIO controller node given in the devicetree; but Zephyr is moving away from specifying device names using thelabelproperty, instead using the node's full name (likegpio@48000800) for device names instead. The deprecated macro does not attempt to get the full name and sincegpiocdoes not supply alabelproperty, the compilation fails. See a bit more of an explanation on device names, full names, etc in this other answer: Cannot get device binding in Zephyr