How to debug undefined reference to __device_dts_ord_XX errors?

Hi!

Currently, I'm trying to create a new board. I have a source code for the Thingy52 board and the code just compiles. With my own board I get __device_dts_ord_10 linker errors. And I don't know, why. I have no idea how to debug such errors since the errors are completely useless.

It says, the error is in some line

if (btn_prs) {

where btn_prs is just a boolean variable and why the linker error should be there? It doesn't make sense.

However, I somewhat found out where the problematic code segments are. They are as follows:

static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(DT_ALIAS(led0), gpios);
static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET(DT_ALIAS(sw0), gpios);
If I remove some parts like this
static const struct gpio_dt_spec led
the code compiles.
And now I don't see where the problem with this is. Why it works with the Thingy52 board but not with mine? The led0 alias is defined and the led also like this
aliases {
led0 = &led0;
sw0 = &button0;
};

leds {
compatible = "gpio-leds";
led0: led_0 {
gpios = <&gpio0 7 GPIO_ACTIVE_LOW>;
label = "Red LED";
};
};

buttons {
compatible = "gpio-keys";
button0: button_0 {
gpios = <&gpio0 11 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
label = "Button";
};
};
 
Maybe, you can help me or give me a hint where to search for such errors.
In another project I cannot upgrade the NRF Connect SDK since such errors appear with newer versions. There is nothing documented!
  • Hello!

    Could you please share the error output?

    Other than that:

    how have you defined btn_prs?

    where did you get the idea of defining "led" as static const struct gpio_dt_spec?

    normally I would expect to see something like #define LED DT_ALIAS(led0), i've also seen struct gpio_dt_spec led.

    I assume this devicetree code you've shared is in an overlay file that gets picked up by the build system?

    Best regards,

    Einar

  • Hi, Thanks for your reply.

    Yes, btn_prs is defined. As I noted, the code does work with the Thingy52 (and with the nrf52 DK). There is one further difference. The board I created is based on the nRF52810 and the others on the nRF52832. But why these errors appear? And is there a guide how to debug such errors?

    The static const struct gpio_dt_spec led is from the esb_ptx example (https://github.com/nrfconnect/sdk-nrf/blob/main/samples/esb/ptx/src/main.c). Since I only use one LED, I removed the other 3 of them.

    The dts part of my question is from the board dts file. Here is the complete file:

    /dts-v1/; #include <nordic/nrf52810_qfaa.dtsi> / { model = "XXX"; compatible = "xxx,example"; chosen { zephyr,sram = &sram0; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; }; aliases { led0 = &led0; sw0 = &button0; }; leds { compatible = "gpio-leds"; led0: led_0 { gpios = <&gpio0 7 GPIO_ACTIVE_LOW>; label = "Red LED"; }; }; buttons { compatible = "gpio-keys"; button0: button_0 { gpios = <&gpio0 11 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; label = "Button"; }; }; }; &gpio0 { status = "okay"; }; &flash0 { partitions { compatible = "fixed-partitions"; #address-cells = ; #size-cells = ; boot_partition: partition@0 { label = "mcuboot"; reg = ; }; slot0_partition: partition@c000 { label = "image-0"; reg = ; }; slot1_partition: partition@16000 { label = "image-1"; reg = ; }; scratch_partition: partition@20000 { label = "image-scratch"; reg = ; }; storage_partition: partition@2a000 { label = "storage"; reg = ; }; }; };

    Here is the error message:

    [146/157] Linking C static library app/libapp.a
    [147/157] Linking C executable zephyr/zephyr_pre0.elf
    FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map
    : && ccache /opt/nordic/ncs/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr/zephyr_pre0.elf -fuse-ld=bfd -Wl,-T zephyr/linker_zephyr_pre0.cmd -Wl,-Map=xxx/build/zephyr/zephyr_pre0.map -Wl,--whole-archive app/libapp.a zephyr/libzephyr.a zephyr/arch/common/libarch__common.a zephyr/arch/arch/arm/core/aarch32/libarch__arm__core__aarch32.a zephyr/arch/arch/arm/core/aarch32/cortex_m/libarch__arm__core__aarch32__cortex_m.a zephyr/arch/arch/arm/core/aarch32/mpu/libarch__arm__core__aarch32__mpu.a zephyr/lib/libc/minimal/liblib__libc__minimal.a zephyr/lib/posix/liblib__posix.a zephyr/soc/arm/common/cortex_m/libsoc__arm__common__cortex_m.a zephyr/soc/arm/nordic_nrf/nrf52/libsoc__arm__nordic_nrf__nrf52.a zephyr/drivers/clock_control/libdrivers__clock_control.a zephyr/drivers/console/libdrivers__console.a zephyr/drivers/timer/libdrivers__timer.a modules/nrf/lib/fatal_error/lib..__nrf__lib__fatal_error.a modules/nrf/subsys/esb/lib..__nrf__subsys__esb.a modules/hal_nordic/nrfx/libmodules__hal_nordic__nrfx.a modules/segger/libmodules__segger.a -Wl,--no-whole-archive zephyr/kernel/libkernel.a zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj -L"/opt/nordic/ncs/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/thumb/v7e-m/nofp" -Lxxx/build/zephyr -lgcc zephyr/arch/common/libisr_tables.a -no-pie -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfp16-format=ieee -Wl,--gc-sections -Wl,--build-id=none -Wl,--sort-common=descending -Wl,--sort-section=alignment -Wl,-u,_OffsetAbsSyms -Wl,-u,_ConfigAbsSyms -nostdlib -static -Wl,-X -Wl,-N -Wl,--orphan-handling=warn && cd xxx/build/zephyr && /opt/nordic/ncs/toolchains/v2.0.0/Cellar/cmake/3.20.5/bin/cmake -E echo
    /opt/nordic/ncs/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/bin/ld.bfd: app/libapp.a(main.c.obj): in function `button_pressed':
    xxx/src/main.c:179: undefined reference to `__device_dts_ord_10'
    /opt/nordic/ncs/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/bin/ld.bfd: app/libapp.a(main.c.obj): in function `main':
    xxx/src/main.c:254: undefined reference to `__device_dts_ord_10'
    collect2: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: /opt/nordic/ncs/toolchains/v2.0.0/bin/cmake --build xxx/build

    That is the error message. Fun fact: The second error at line 254 cannot happen there because there is no line 254 in main.c. There are only 249 lines.

    Thank you very much and best regards

    Jan

  • Thank you!

    I would suspect the error to be caused by something in your 'button_pressed' function unsuccessfully accessing the devicetree.

    Could you please share your main c file?

    If there's a zephyr.dts file generated in your build/zephyr directory, this could also be interesting to have a look at.

    -Einar

  • Maybe, it  is the easiest way to share the repository.

    https://github.com/oMtQB4/nrf52-shockburst-3d-touch-probe

    There are two projects in the project. Currently, I'm only trying to get the ESB_ptx working. Furthermore, there is the board in the repository.

    The current error message is as follows (the lines have changed due to changes in the code.

    [3/13] Linking C executable zephyr/zephyr_pre0.elf
    FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map xxx/build/zephyr/zephyr_pre0.map
    : && ccache /opt/nordic/ncs/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr/zephyr_pre0.elf zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj -fuse-ld=bfd -Wl,-T zephyr/linker_zephyr_pre0.cmd -Wl,-Map=xxx/ESB_ptx/build/zephyr/zephyr_pre0.map -Wl,--whole-archive app/libapp.a zephyr/libzephyr.a zephyr/arch/common/libarch__common.a zephyr/arch/arch/arm/core/aarch32/libarch__arm__core__aarch32.a zephyr/arch/arch/arm/core/aarch32/cortex_m/libarch__arm__core__aarch32__cortex_m.a zephyr/arch/arch/arm/core/aarch32/mpu/libarch__arm__core__aarch32__mpu.a zephyr/lib/libc/minimal/liblib__libc__minimal.a zephyr/lib/posix/liblib__posix.a zephyr/soc/arm/common/cortex_m/libsoc__arm__common__cortex_m.a zephyr/soc/arm/nordic_nrf/nrf52/libsoc__arm__nordic_nrf__nrf52.a zephyr/drivers/clock_control/libdrivers__clock_control.a zephyr/drivers/console/libdrivers__console.a zephyr/drivers/timer/libdrivers__timer.a modules/nrf/lib/fatal_error/lib..__nrf__lib__fatali_error.a modules/nrf/subsys/esb/lib..__nrf__subsys__esb.a modules/hal_nordic/nrfx/libmodules__hal_nordic__nrfx.a modules/segger/libmodules__segger.a -Wl,--no-whole-archive zephyr/kernel/libkernel.a -L"/opt/nordic/ncs/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/thumb/v7e-m/nofp" -Lxxx/ESB_ptx/build/zephyr -lgcc zephyr/arch/common/libisr_tables.a -no-pie -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfp16-format=ieee -Wl,--gc-sections -Wl,--build-id=none -Wl,--sort-common=descending -Wl,--sort-section=alignment -Wl,-u,_OffsetAbsSyms -Wl,-u,_ConfigAbsSyms -nostdlib -static -Wl,-X -Wl,-N -Wl,--orphan-handling=warn && cd xxx/ESB_ptx/build/zephyr && /opt/homebrew/Cellar/cmake/3.23.2/bin/cmake -E echo
    /opt/nordic/ncs/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/bin/ld.bfd: app/libapp.a(main.c.obj): in function `button_pressed_cb':
    xxx/ESB_ptx/src/main.c:170: undefined reference to `__device_dts_ord_10'
    /opt/nordic/ncs/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/bin/ld.bfd: app/libapp.a(main.c.obj): in function `main':
    xxx/ESB_ptx/src/main.c:245: undefined reference to `__device_dts_ord_10'
    collect2: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: /opt/nordic/ncs/toolchains/v2.0.0/bin/cmake --build xxx/ESB_ptx/build

    Currently, NRF Connect SDK 2.0.0 is used.

Related