Interfacing FLASH with SPI instead of QSPI

Hi

I am working with nrf52840dk- nrf52840 board to interface the  flash(mx25r64) using spi_flash example code. I wants to use  SPI instead of QSPI in nrf connect sdk .
But I am facing error.

Below I have attached the overlay file I created for SPI flash pin mapping. I haven't changed anything in the main.c and I didn't changed anything in the prj.confg file also.

In the main.c there is if condition

if (!device_is_ready(flash_dev)) {
printk("%s: device not ready.\n", flash_dev->name);
return;
}

When I buid my code and try to debug the code it is coming into this if condition and shows device is not ready.  Can Someone help me with this.

Note:I didn't changed anything in the main.c

OVERLAY FILE:

&qspi {
    status ="disabled";
};

arduino_i2c: &i2c0 {
    status ="disabled";
};

/{
    aliases{
        spi-flash0 = &mx25r641;
    };
};

&spi0 {
    compatible = "nordic,nrf-spi";
    /* Cannot be used together with i2c0. */
    status = "okay";
    pinctrl-0 = <&spi0_default>;
    pinctrl-1 = <&spi0_sleep>;
    pinctrl-names = "default", "sleep";
    cs-gpios = < &gpio0 16 GPIO_ACTIVE_LOW >;
    mx25r641: mx25r641@0{
        compatible = "jedec,spi-nor";
        reg =<0x0>;
        spi-max-frequency = < 100000 >;
        label = "mx25r64";
        jedec-id = [c2 28 17];
        sfdp-bfp = [
            e5 20 f1 ff  ff ff ff 03  44 eb 08 6b  08 3b 04 bb
            ee ff ff ff  ff ff 00 ff  ff ff 00 ff  0c 20 0f 52
            10 d8 00 ff  23 72 f5 00  82 ed 04 cc  44 83 68 44
            30 b0 30 b0  f7 c4 d5 5c  00 be 29 ff  f0 d0 ff ff
        ];
        size = <67108864>;
        has-dpd;
        t-enter-dpd = <10000>;
        t-exit-dpd = <35000>;
    };
};

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

    spi0_sleep: spi0_sleep {
        group1 {
            psels = <NRF_PSEL(SPIM_SCK, 0, 15)>,
                    <NRF_PSEL(SPIM_MOSI, 0, 14)>,
                    <NRF_PSEL(SPIM_MISO, 0, 13)>;
            low-power-enable;
        };
    };
};
In nrf52840dk_nrf52840.dts there is a node for qspi when I use spi-flash0 = &mx25r64 aliases it is redirecting to the qspi but I want the flash in spi so created above node in the overlay file 
mx25r641: mx25r641@0{
        compatible = "jedec,spi-nor";
        reg =<0x0>;
        spi-max-frequency = < 100000 >;
        label = "mx25r64";
        jedec-id = [c2 28 17];
        sfdp-bfp = [
            e5 20 f1 ff  ff ff ff 03  44 eb 08 6b  08 3b 04 bb
            ee ff ff ff  ff ff 00 ff  ff ff 00 ff  0c 20 0f 52
            10 d8 00 ff  23 72 f5 00  82 ed 04 cc  44 83 68 44
            30 b0 30 b0  f7 c4 d5 5c  00 be 29 ff  f0 d0 ff ff
        ];
        size = <67108864>;
        has-dpd;
        t-enter-dpd = <10000>;
        t-exit-dpd = <35000>;
    };
by changing the label name from mx25r64 to mx25r641 and compatible to jedec,spi-nor.
 
When I change 
CONFIG_NORDIC_QSPI_NOR=y this to 
CONFIG_NORDIC_QSPI_NOR=n and adds CONFIG_SPI_NOR =y in nrf52840dk_nrf52840.conf file It is throwing error like this "Aborting the code due to kconfig".
If someone finds the  process what I am doing wrong please correct me with the right process and help to interface the flash with spi.
Parents
  • Hmm, you can try to remove the old mx25r64 node before adding your own, try the following:

    #include "nrf52840.dtsi"
    /{
        &soc {
            &qspi{
                /delete-node/ &mx25r64;
            };
        };
    };
    
    &qspi {
        status ="disabled";
    };
    
    arduino_i2c: &i2c0 {
        status ="disabled";
    };
    
    &spi0 {
        compatible = "nordic,nrf-spim"; // use the nrfx spim driver for async api
        /* Cannot be used together with i2c0. */
        status = "okay";
        pinctrl-0 = <&spi0_default>;
        pinctrl-1 = <&spi0_sleep>;
        pinctrl-names = "default", "sleep";
        cs-gpios = < &gpio0 16 GPIO_ACTIVE_LOW >;
        mx25r64: mx25r64@0{
            compatible = "jedec,spi-nor";
            reg =<0x0>;
            spi-max-frequency = < 100000 >;
            label = "mx25r64";
            jedec-id = [c2 28 17];
            sfdp-bfp = [
                e5 20 f1 ff  ff ff ff 03  44 eb 08 6b  08 3b 04 bb
                ee ff ff ff  ff ff 00 ff  ff ff 00 ff  0c 20 0f 52
                10 d8 00 ff  23 72 f5 00  82 ed 04 cc  44 83 68 44
                30 b0 30 b0  f7 c4 d5 5c  00 be 29 ff  f0 d0 ff ff
            ];
            size = <67108864>;
            has-dpd;
            t-enter-dpd = <10000>;
            t-exit-dpd = <35000>;
        };
    };
    
    &pinctrl {
        spi0_default: spi0_default {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 15)>,
                        <NRF_PSEL(SPIM_MOSI, 0, 14)>,
                        <NRF_PSEL(SPIM_MISO, 0, 13)>;
            };
        };
    
        spi0_sleep: spi0_sleep {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 15)>,
                        <NRF_PSEL(SPIM_MOSI, 0, 14)>,
                        <NRF_PSEL(SPIM_MISO, 0, 13)>;
                low-power-enable;
            };
        };
    };

    If that does not work, try this: 

    #include "nrf52840.dtsi"
    
    /delete-node/ &mx25r64;
    
    &qspi {
        status ="disabled";
    };
    
    arduino_i2c: &i2c0 {
        status ="disabled";
    };
    
    &spi0 {
        compatible = "nordic,nrf-spim"; // use the nrfx spim driver for async api
        /* Cannot be used together with i2c0. */
        status = "okay";
        pinctrl-0 = <&spi0_default>;
        pinctrl-1 = <&spi0_sleep>;
        pinctrl-names = "default", "sleep";
        cs-gpios = < &gpio0 16 GPIO_ACTIVE_LOW >;
        mx25r64: mx25r64@0{
            compatible = "jedec,spi-nor";
            reg =<0x0>;
            spi-max-frequency = < 100000 >;
            label = "mx25r64";
            jedec-id = [c2 28 17];
            sfdp-bfp = [
                e5 20 f1 ff  ff ff ff 03  44 eb 08 6b  08 3b 04 bb
                ee ff ff ff  ff ff 00 ff  ff ff 00 ff  0c 20 0f 52
                10 d8 00 ff  23 72 f5 00  82 ed 04 cc  44 83 68 44
                30 b0 30 b0  f7 c4 d5 5c  00 be 29 ff  f0 d0 ff ff
            ];
            size = <67108864>;
            has-dpd;
            t-enter-dpd = <10000>;
            t-exit-dpd = <35000>;
        };
    };
    
    &pinctrl {
        spi0_default: spi0_default {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 15)>,
                        <NRF_PSEL(SPIM_MOSI, 0, 14)>,
                        <NRF_PSEL(SPIM_MISO, 0, 13)>;
            };
        };
    
        spi0_sleep: spi0_sleep {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 15)>,
                        <NRF_PSEL(SPIM_MOSI, 0, 14)>,
                        <NRF_PSEL(SPIM_MISO, 0, 13)>;
                low-power-enable;
            };
        };
    };

  • The solution you have suggested was not working

    I have tried both the overlays you have shared, with and without changing the CONFIG_NORDIC_QSPI_NOR=y this to CONFIG_NORDIC_QSPI_NOR=n and adds CONFIG_SPI_NOR =y in nrf52840dk_nrf52840.conf file 

    When I change  CONFIG_NORDIC_QSPI_NOR=y to CONFIG_NORDIC_QSPI_NOR=n I got these errors

    1. error: Aborting due to Kconfig warnings
    2. CMake Error at C:/ncs/v2.3.0/zephyr/cmake/modules/kconfig.cmake:328 (message): command failed with return code: 1
    3. -- Configuring incomplete, errors occurred!

    FATAL ERROR: command exited with status 1: 'c:\ncs\toolchains\v2.3.0\opt\bin\cmake.EXE' '-DWEST_PYTHON=c:\ncs\toolchains\v2.3.0\opt\bin\python.exe' '-Bc:\nrf_workspace\spi_flash\build' -GNinja -DBOARD=nrf52840dk_nrf52840 -DNCS_TOOLCHAIN_VERSION:STRING=NONE -DBOARD_ROOT:STRING=c:/nrf_workspace/spi_flash '-DCONF_FILE:STRING=c:/nrf_workspace/spi_flash/prj.conf;c:/nrf_workspace/spi_flash/boards/nrf52840dk_nrf52840.conf' -DDTC_OVERLAY_FILE:STRING=c:/nrf_workspace/spi_flash/nrf52840dk_nrf52840.overlay '-Sc:\nrf_workspace\spi_flash'

    Without any changes in nrf52840dk_nrf52840.conf file also I got cmake error and -- Configuring incomplete, errors occurred!

  • The only obvious issue i see here is that you need to change the spi2's compatible field from:

    compatible = "nordic,nrf-spi",

    to:

    compatible = "nordic,nrf-spim";.

    And you need to make sure that CONFIG_SPI=y and CONFIG_NRFX_SPIM2 is set. 

  • I have changed the compatible = "nordic,nrf-spi" to compatible = "nordic,nrf-spim" in my dts file


    below is my proj.conf file 

    CONFIG_STDOUT_CONSOLE=y
    CONFIG_FLASH=y
    CONFIG_SPI=y
    CONFIG_NRFX_SPIM2=y
     
    still it is coming into this if condition and shows device is not ready.
     
  • I want to try to build your project on my computer, can you share your project files? At least the ones relevant for accessing the QSPI flash device, your new board files, as well as configs and overlays. 

  • spi_flash_v1.zip

    In This I have changed the DTS, proj.config file as per your suggestion.

    I have also changed CONFIG_NORDIC_QSPI_NOR=y to CONFIG_NORDIC_QSPI_NOR=n and add on this CONFIG_SPI_NOR=y in nrf52840dk_nrf52840.conf file.

  • I think the project you shared is an older version as it does not contain the changes you listed.

Reply Children
Related