labels missing from DTS in nRF Connect SDK 2.1.0

In nRF Connect SDK 2.1.0 the devices in the DTS file are missing the "label".

For example, in nRF Connect SDK 2.0.0:

gpio0: gpio@842500 {

        compatible = "nordic,nrf-gpio";

        gpio-controller;

        reg = <0x842500 0x300>;

        #gpio-cells = <2>;

        label = "GPIO_0";

        status = "disabled";

        port = <0>;

};

But in nRF Connect SDK 2.1.0:

gpio0: gpio@842500 {

        compatible = "nordic,nrf-gpio";

        gpio-controller;

        reg = <0x842500 0x300>;

        #gpio-cells = <2>;

        status = "disabled";

        port = <0>;

};

This breaks code that does dynamic lookup of the device using the function device_get_binding (in my case passing in a string that is constructed at run time).

Parents Reply Children
  • As I noted in my original post, I'm forming the string to lookup the device at runtime.  So I can't use the hard coded form you suggested above.

    I ended up adding the old lables back in my custom board dts so that things still work.

    Do you know why the old labels were removed from v2.1.0?  Is that bug or was it intentional?  If so why?

  • Hi,

    You are correct that this does not solve the issue, since giving the node label at runtime does not work.

    I am not sure why the old labels were removed, as I see no reason why keeping them should be an issue. It does seem to have been intentional, yes. I found the commit (which you can see here), and that only says it was removed because the label properties are not required, no other reasoning. I agree that this is an issue, as even if it is a small change it is still a change which might break projects, as is the case here. This has been reported, and I will keep you informed if the developers provide any other reasons for the removal.

    I can think of two possible workarounds. One is to add the labels in an overlay or in your devicetree as you have done. The other is to use the entire device name in the string you form at runtime. This is most likely not a good workaround though, as the name will be something like "gpio@50000000".

    Best regards,

    Marte

  • Hi,

    The main reason the labels were removed is that they were, in most cases, incorrectly used as node labels. 

    The developers recommend not using device_get_binding() when wanting an application to have access to devices by some sort of name or similar. It is better to implement a custom solution, for example something like this:

    struct gpios {
       const char *name;
       const struct device *dev;
    }
    
    const struct gpios my_gpios = {
       { .name = "GPIO0", .dev = DEVICE_DT_GET(DT_NODELABEL(gpio0)) },
       { .name = "GPIO1", .dev = DEVICE_DT_GET(DT_NODELABEL(gpio1)) }
    };

    They do not recommend relying on the label property, nor using a workaround where this is added in devicetree.

    Is there any specific reason why you are using the ports directly in your code? You could also implement something that uses devicetree to describe devices properly (with gpio specs, etc.), use the device model, etc. 

    Best regards,

    Marte

  • The developers recommend not using device_get_binding()

    However, it is strange that the Zephyr examples use strings with device_get_binding.

    For example:

    samples\boards\nrf\nrf53_sync_rtc\net\src\main.c
    67: ipm_dev = device_get_binding("IPM_2");

    samples\drivers\flash_shell\src\main.c
    const char *name;
    name = argv[1];
    714: dev = device_get_binding(name);

    samples\drivers\i2s\litex\src\main.c
    37: host_i2s_rx_dev = device_get_binding("i2s_rx");

    samples\sensor\thermometer\src\main.c
    17: temp_dev = device_get_binding("TEMP_0");

    samples\subsys\usb\hid\src\main.c
    154: hdev = device_get_binding("HID_0");

    samples\subsys\usb\hid-cdc\src\main.c
    550: hid0_dev = device_get_binding("HID_0");
    556: hid1_dev = device_get_binding("HID_1");

    samples\subsys\usb\hid-mouse\src\main.c
    249: hid_dev = device_get_binding("HID_0");

Related