ncs 2.7.0 SPI nor flash build error

I got below build error:, actually I referred C:\ncs\v2.7.0\zephyr\samples\drivers\jesd216; my externl SPI NOR flash is p25q32h and my target is to build a file system such as fatfs on the flash. I also checked the sample under  C:\ncs\v2.7.0\zephyr\samples\drivers\spi_flash\boards and set CONFIG_NORDIC_QSPI_NOR, it has the same build exception.

c:/ncs/toolchains/ce3b5ff664/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: zephyr/drivers/flash/libdrivers__flash.a(spi_nor.c.obj):(.rodata.spi_nor_0_config+0x0): undefined reference to `__device_dts_ord_85'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

1. DTS

&pinctrl {
	i2c0_default: i2c0_default {
		group1 {
			psels = <NRF_PSEL(TWIM_SCL, 0, 10)>, <NRF_PSEL(TWIM_SDA, 0, 9)>;
		};
	};

	spi1_default: spi1_default {
		group1 {
			psels = <NRF_PSEL(SPIM_MISO, 0, 14)>,
					<NRF_PSEL(SPIM_MOSI, 0, 15)>,
					<NRF_PSEL(SPIM_SCK, 0, 17)>;
		};
	};
};


&spi1 {
	status = "okay";
	pinctrl-0 = <&spi1_default>;
	pinctrl-names = "default";
	p25q32h: p25q32h@0 {
        compatible = "jedec,spi-nor";
        reg = <0>;  // SPI Flash 从设备地址
        spi-max-frequency = <8000000>;  // SPI 最大频率
        label = "p25q32h";
        size = <0x2000000>;  // 32MB
		jedec-id = [85 60 16];
    };
	cs-gpios = <&gpio0 16 0>;
};

2. prj.conf

CONFIG_FLASH=y
CONFIG_FLASH_JESD216_API=y

# Assume the standard SPI NOR flash driver.  If the device uses
# another driver add an override configuration in boards/.
CONFIG_SPI=y
CONFIG_SPI_NOR=y

Parents
  • Hi Hugh,

    Just letting you know I have started looking into this. My first guess is that something like below is missing from the main.c::main() function:

    const struct device *flash_dev = DEVICE_DT_GET(DT_NODELABEL(p25q32h)); 

    Please let me know if the above does not work, and I will look deeper into this tomorrow. Check out this in the meantime:  Troubleshooting undefined reference to __device_dts_ord_<N>.

  • It doesn't work, I put the code in main() function.according to the error, it has relation with libdrivers__flash & spi_nor

  • Thank you for giving it a try. I think we need to look for something else.

    Which board are you building for? building for nrf52dk you will need to set both pinctrl names:

    pinctrl-names = "default", "sleep";

    Check zephyr\boards\nordic\nrf52dk\nrf52dk_nrf52832-pinctrl.dtsi for an example showing how to set both default and sleep.

  • Hi helsing: I got the same exception.

    c:/ncs/toolchains/ce3b5ff664/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: zephyr/drivers/flash/libdrivers__flash.a(spi_nor.c.obj):(.rodata.spi_nor_0_config+0x0): undefined reference to `__device_dts_ord_84'

    Below is the dts config

    &pinctrl {
    	i2c0_default: i2c0_default {
    		group1 {
    			psels = <NRF_PSEL(TWIM_SCL, 0, 10)>, <NRF_PSEL(TWIM_SDA, 0, 9)>;
    			bias-pull-up;
    		};
    	};
    
    	spi1_default: spi1_default {
    		group1 {
    			psels = <NRF_PSEL(SPIM_MISO, 0, 14)>,
    					<NRF_PSEL(SPIM_MOSI, 0, 15)>,
    					<NRF_PSEL(SPIM_SCK, 0, 17)>;
    		};
    	};
    	spi1_sleep: spi1_sleep {
    		group1 {
    			psels = <NRF_PSEL(SPIM_MISO, 0, 14)>,
    					<NRF_PSEL(SPIM_MOSI, 0, 15)>,
    					<NRF_PSEL(SPIM_SCK, 0, 17)>;
    			low-power-enable;
    		};
    	};
    };
    
    
    &spi1 {
    	status = "okay";
    	pinctrl-0 = <&spi1_default>;
    	pinctrl-1 = <&spi1_sleep>;
    	pinctrl-names = "default", "sleep";
    	p25q32h: p25q32h@0 {
            compatible = "jedec,spi-nor";
            reg = <0>;  // SPI Flash 从设备地址
            spi-max-frequency = <8000000>;  // SPI 最大频率
            label = "p25q32h";
            size = <0x2000000>;  // 32MB
    		jedec-id = [85 60 16];
        };
    	cs-gpios = <&gpio0 16 0>;
    };
    

    main.c

    int main(void)
    {
            int err;
            const struct device *flash_dev = DEVICE_DT_GET(DT_NODELABEL(p25q32h));
            return 0;
    }

Reply
  • Hi helsing: I got the same exception.

    c:/ncs/toolchains/ce3b5ff664/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: zephyr/drivers/flash/libdrivers__flash.a(spi_nor.c.obj):(.rodata.spi_nor_0_config+0x0): undefined reference to `__device_dts_ord_84'

    Below is the dts config

    &pinctrl {
    	i2c0_default: i2c0_default {
    		group1 {
    			psels = <NRF_PSEL(TWIM_SCL, 0, 10)>, <NRF_PSEL(TWIM_SDA, 0, 9)>;
    			bias-pull-up;
    		};
    	};
    
    	spi1_default: spi1_default {
    		group1 {
    			psels = <NRF_PSEL(SPIM_MISO, 0, 14)>,
    					<NRF_PSEL(SPIM_MOSI, 0, 15)>,
    					<NRF_PSEL(SPIM_SCK, 0, 17)>;
    		};
    	};
    	spi1_sleep: spi1_sleep {
    		group1 {
    			psels = <NRF_PSEL(SPIM_MISO, 0, 14)>,
    					<NRF_PSEL(SPIM_MOSI, 0, 15)>,
    					<NRF_PSEL(SPIM_SCK, 0, 17)>;
    			low-power-enable;
    		};
    	};
    };
    
    
    &spi1 {
    	status = "okay";
    	pinctrl-0 = <&spi1_default>;
    	pinctrl-1 = <&spi1_sleep>;
    	pinctrl-names = "default", "sleep";
    	p25q32h: p25q32h@0 {
            compatible = "jedec,spi-nor";
            reg = <0>;  // SPI Flash 从设备地址
            spi-max-frequency = <8000000>;  // SPI 最大频率
            label = "p25q32h";
            size = <0x2000000>;  // 32MB
    		jedec-id = [85 60 16];
        };
    	cs-gpios = <&gpio0 16 0>;
    };
    

    main.c

    int main(void)
    {
            int err;
            const struct device *flash_dev = DEVICE_DT_GET(DT_NODELABEL(p25q32h));
            return 0;
    }

Children
Related