SPI flash Sample: undefined reference to `__device_dts_ord_77'

Hello,

I have modified the SPI flash AT45 Sample (which compiles fine) to work with a AT25 model, the problem is it doesn't compile and it gives undefined reference to `__device_dts_ord_77'.

I know that errors of that kind are related to a missing Kconfig line or badly written DTS file, but I can't find the issue:

// Copyright (c) 2024 Nordic Semiconductor ASA
// SPDX-License-Identifier: Apache-2.0

/dts-v1/;
#include <nordic/nrf52833_qiaa.dtsi>

/ {
	model = "mouse";
	compatible = "mouse";

	chosen {
		zephyr,sram = &sram0;
		zephyr,flash = &flash0;
		zephyr,code-partition = &slot0_partition;
	};
};

&flash0 {
	partitions {
		compatible = "fixed-partitions";
		#address-cells = <1>;
		#size-cells = <1>;

		boot_partition: partition@0 {
			label = "mcuboot";
			reg = <0x0 0xc000>;
		};
		slot0_partition: partition@c000 {
			label = "image-0";
			reg = <0xc000 0x32000>;
		};
		slot1_partition: partition@3e000 {
			label = "image-1";
			reg = <0x3e000 0x32000>;
		};
		scratch_partition: partition@70000 {
			label = "image-scratch";
			reg = <0x70000 0xa000>;
		};
		storage_partition: partition@7a000 {
			label = "storage";
			reg = <0x7a000 0x6000>;
		};
	};
};

&pinctrl {
	spi0_default: spi0_default {
		group1 {
			psels = <NRF_PSEL(SPIM_SCK, 0, 0)>,
			        <NRF_PSEL(SPIM_MOSI, 0, 1)>,
			        <NRF_PSEL(SPIM_MISO, 0, 4)>;
		};
	};

	spi0_sleep: spi0_sleep {
		group1 {
			psels = <NRF_PSEL(SPIM_SCK, 0, 0)>,
			        <NRF_PSEL(SPIM_MOSI, 0, 1)>,
			        <NRF_PSEL(SPIM_MISO, 0, 4)>;
			low-power-enable;
		};
	};
};

&spi0 {
	status = "okay";
	pinctrl-0 = <&spi0_default>;
	pinctrl-1 = <&spi0_sleep>;
	pinctrl-names = "default", "sleep";
	max-frequency = <DT_FREQ_M(10)>;
	interrupts = <11>, <NRF_DEFAULT_IRQ_PRIORITY>;
	cs-gpios = <&gpio0 11 0>;
	at25@0 {
		status = "okay";
		compatible = "atmel,at25";
		reg = <0>;
		size = <125>;
		pagesize = <8>;
		spi-max-frequency = <DT_FREQ_M(10)>;
		address-width = <8>;
		timeout = <5>;
	};
};

&gpio0 {
	status = "okay";
};

CONFIG_STDOUT_CONSOLE=y
CONFIG_LOG=y
CONFIG_LOG_MODE_IMMEDIATE=y

CONFIG_SPI=y
CONFIG_FLASH=y
CONFIG_PM_DEVICE=y

CONFIG_PINCTRL=y
CONFIG_GPIO=y
CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y # needed for my board

Also I changed atmel_45 to atmel_25 in the following source code line:

const struct device *const flash_dev = DEVICE_DT_GET_ONE(atmel_at25);

Can anyone spot the error?

Parents
  • Hi,

    In general you won't be able to replace the device simply changing the device that DEVICE_DT_GET_ONE() fetches. You also need to set it up in your projects .yaml file as well as defining it properly in your overlays. I recommend that you look into https://docs.zephyrproject.org/latest/build/dts/howtos.html as well as investigating the sample.yaml that is located in the src folder of the spi_flash_at45 sample to get a better understanding of this, and I'll try to reach out to you again next week with some more input if you're unable to resolve it using this information

    Kind regards,
    Andreas

  • Thanks for the quick answer.

    You also need to set it up in your projects .yaml file

    I followed the dev accademy course on the nRF Connect fundamentals and I never had to touch the projects .yaml file, so I'm a bit lost. Can you elaborate?

    as well as defining it properly in your overlays.

    My understanding is that an overlay file is used to override a device tree configuration made in a board file without chaning it. In my case I made the board file and defined the flash memory there. Isn't this correct? I don't see a need for an overlay file.

    Thanks.

  • StefanoN said:
    I followed the dev accademy course on the nRF Connect fundamentals and I never had to touch the projects .yaml file, so I'm a bit lost. Can you elaborate?

    The upcoming devacademy course will cover this to more extent than the current ones, so I agree that they are somewhat limited in explaining how to do this.

    Regarding your error, did you investigate the link I sent you? There is a reference to the undefined reference error you get there.

    StefanoN said:
    My understanding is that an overlay file is used to override a device tree configuration made in a board file without chaning it. In my case I made the board file and defined the flash memory there. Isn't this correct? I don't see a need for an overlay file.

    Your understanding is correct, but by changing it in the board file located in the SDK you will change this for all subsequent builds that uses that board and not just for your project. It's fine to do it this way, specially if you're using a custom board, but if you change for instance something for an nRF52DK, which has configurations for multiple samples and applications in the SDK, you should make the changes in an .overlay file that is dedicated to that specific project. 

    So to sum up, it's just a standard preference that may save you time down the line if you have multiple projects with different configurations based on the same board

    Kind regards,
    Andreas

  • I fixed it by using the troubleshooting guide in the link you provided, it gave me the hint that the issue was in proj.conf, which ended up being a missing CONFIG_EEPROM=y.

    Now the project builds fine, but I get an error that makes the MCU reset:

    00> *** Booting Zephyr OS build v3.3.99-ncs1-1 ***
    00> DataFlash sample on mouse
    00> [00:00:00.000,549] <err> os: ***** BUS FAULT *****
    00> [00:00:00.000,946] <err> os:   Instruction bus error
    00> [00:00:00.001,373] <err> os: r0/a1:  0x00009174  r1/a2:  0x20002084  r2/a3:  0x20002080
    00> [00:00:00.002,014] <err> os: r3/a4:  0x656e6769 r12/ip:  0x0000000a r14/lr:  0x00007f57
    00> [00:00:00.002,593] <err> os:  xpsr:  0x01000000
    00> [00:00:00.003,021] <err> os: Faulting instruction address (r15/pc): 0x656e6768
    00> [00:00:00.003,570] <err> os: >>> ZEPHYR FATAL ERROR 27: Unknown error on CPU 0
    00> [00:00:00.004,089] <err> os: Current thread: 0x20000268 (main)
    00> [00:00:00.009,582] [1;31m<err> fatal_error: Resetting system

    I checked with the debugger: starting from the Sample at45 main method, the highlighted line gives the error:

    To be more precise, the error occurs inside z_impl_flash_get_page_count() in flash_page_layout.c.

    The line

    api->page_layout(dev, &layout, &layout_size);

    triggers the error, meaning the MCU resets when executing it.

    Reading bus error makes me think of an hw error, so I checked my PCB and it looks fine:

    The "unknown error" comes from this code in the zephyr fatal.c file:

    Being a run time error would suggest that the configuration of the EEPROM is correct, but the software is attempting to do something illegal.

    How can I start debugging this issue?

Reply
  • I fixed it by using the troubleshooting guide in the link you provided, it gave me the hint that the issue was in proj.conf, which ended up being a missing CONFIG_EEPROM=y.

    Now the project builds fine, but I get an error that makes the MCU reset:

    00> *** Booting Zephyr OS build v3.3.99-ncs1-1 ***
    00> DataFlash sample on mouse
    00> [00:00:00.000,549] <err> os: ***** BUS FAULT *****
    00> [00:00:00.000,946] <err> os:   Instruction bus error
    00> [00:00:00.001,373] <err> os: r0/a1:  0x00009174  r1/a2:  0x20002084  r2/a3:  0x20002080
    00> [00:00:00.002,014] <err> os: r3/a4:  0x656e6769 r12/ip:  0x0000000a r14/lr:  0x00007f57
    00> [00:00:00.002,593] <err> os:  xpsr:  0x01000000
    00> [00:00:00.003,021] <err> os: Faulting instruction address (r15/pc): 0x656e6768
    00> [00:00:00.003,570] <err> os: >>> ZEPHYR FATAL ERROR 27: Unknown error on CPU 0
    00> [00:00:00.004,089] <err> os: Current thread: 0x20000268 (main)
    00> [00:00:00.009,582] [1;31m<err> fatal_error: Resetting system

    I checked with the debugger: starting from the Sample at45 main method, the highlighted line gives the error:

    To be more precise, the error occurs inside z_impl_flash_get_page_count() in flash_page_layout.c.

    The line

    api->page_layout(dev, &layout, &layout_size);

    triggers the error, meaning the MCU resets when executing it.

    Reading bus error makes me think of an hw error, so I checked my PCB and it looks fine:

    The "unknown error" comes from this code in the zephyr fatal.c file:

    Being a run time error would suggest that the configuration of the EEPROM is correct, but the software is attempting to do something illegal.

    How can I start debugging this issue?

Children
  • To add more context, this is the situation before crashing:

    Going into the definition of page_layout, I see that it needs CONFIG_FLASH_PAGE_LAYOUT=y, which I confirmed is enabled by default with my proj.config, which so far looks like:

    CONFIG_LOG=y
    CONFIG_LOG_MODE_IMMEDIATE=y
    CONFIG_USE_SEGGER_RTT=y
    
    CONFIG_SPI=y
    CONFIG_FLASH=y
    CONFIG_EEPROM=y
    CONFIG_PM_DEVICE=y
    
    CONFIG_PINCTRL=y
    CONFIG_GPIO=y
    CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y # needed for my board

Related