Use of Zephyr inbuilt APIs to Use External Flash with nRF9160

I am using MX25 external flash with nRF9160. I am unable to find the configuration to use the Zephyr APIs to access the flash. I am able to access it when I am using 

spi_write_dt funtion but for this I have to do some SPI configuration using the following structs
struct spi_config spi_cfg;
struct spi_cs_control cs_control;
My configuration for Flash in prj.conf

# SPI
CONFIG_SPI=y
CONFIG_SPI_NOR=y

# FLASH
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
Need some insight on how to use the zephyr-based APIs without doing any other configuration other than DT.
Parents
  • Hi

    You might want to look at Zephyr Flash sample that demonstrates the use of flash API:

    Zephyr Flash Sample

  • I have checked this example but it didn't worked for me. When I was calling the flash_erase I was getting some wierd observation. 

    This functions calls the following code:

    static inline int z_impl_flash_erase(const struct device *dev, off_t offset,
                         size_t size)
    {
        const struct flash_driver_api *api =
            (const struct flash_driver_api *)dev->api;
        int rc;

        rc = api->erase(dev, offset, size);

        return rc;
    }
    but here I see that no function is assigned to api->erase 
  • I am using the following to the flash device from DT:

    #define SPI_FLASH DEVICE_DT_GET(DT_ALIAS(ext_flash))
    The aliases where I have used ext_flash:
  • what error you are getting now?

    defining aliases for instances is fine.

    you can do the debugging to see what is causing the issue.

  • . You can see in the above image when I execute line 242, I am getting exceptions and that could be because of the erase is not pointing to any valid function (as seen in watch)

  • Hi Amit,

    I have tested on nrf52840dk, and I do not get any problem

    I can see the correct functionality as well.

    Just for reference, I am putting the nrf52840DK overlay here which is based on your overlay, the sample output dts, and the information from the DK guide.

    /delete-node/ &mx25r64;
    &qspi{
        status = "disabled";
        
    };
    &spi3{
        compatible = "nordic,nrf-spim";
        status = "okay";
        pinctrl-0 = < &spi3_default >;
        pinctrl-1 = < &spi3_sleep >;
        pinctrl-names = "default", "sleep";
        cs-gpios = <&gpio0 17 GPIO_ACTIVE_LOW>; /* D10 */
        mx25r64: mx25r6435f@0 {
            compatible = "jedec,spi-nor";
            reg = < 0x0 >;
            spi-max-frequency = < 8000000 >;
            status = "okay";
            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 = < 0x4000000 >;
            has-dpd;
            t-enter-dpd = < 0x2710 >;
            t-exit-dpd = < 0x88b8 >;
        };
    };
    
    &pinctrl{
        spi3_default: spi3_default {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 19)>,
    				<NRF_PSEL(SPIM_MISO, 0, 21)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 20)>;
    		};
    	};
    
    	spi3_sleep: spi3_sleep {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 19)>,
    				<NRF_PSEL(SPIM_MISO, 0, 21)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 20)>;
    			low-power-enable;
    		};
    	};
    };
    
    /{
        aliases{
            spi-flash0 = &mx25r64;
        };
    };

    I am using the exact sample without modifying anything in the main except including a header file for the spi.

    In the project configurations, SPI is enabled and QSPI is disabled; similarly in the overlay.

Reply
  • Hi Amit,

    I have tested on nrf52840dk, and I do not get any problem

    I can see the correct functionality as well.

    Just for reference, I am putting the nrf52840DK overlay here which is based on your overlay, the sample output dts, and the information from the DK guide.

    /delete-node/ &mx25r64;
    &qspi{
        status = "disabled";
        
    };
    &spi3{
        compatible = "nordic,nrf-spim";
        status = "okay";
        pinctrl-0 = < &spi3_default >;
        pinctrl-1 = < &spi3_sleep >;
        pinctrl-names = "default", "sleep";
        cs-gpios = <&gpio0 17 GPIO_ACTIVE_LOW>; /* D10 */
        mx25r64: mx25r6435f@0 {
            compatible = "jedec,spi-nor";
            reg = < 0x0 >;
            spi-max-frequency = < 8000000 >;
            status = "okay";
            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 = < 0x4000000 >;
            has-dpd;
            t-enter-dpd = < 0x2710 >;
            t-exit-dpd = < 0x88b8 >;
        };
    };
    
    &pinctrl{
        spi3_default: spi3_default {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 19)>,
    				<NRF_PSEL(SPIM_MISO, 0, 21)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 20)>;
    		};
    	};
    
    	spi3_sleep: spi3_sleep {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 19)>,
    				<NRF_PSEL(SPIM_MISO, 0, 21)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 20)>;
    			low-power-enable;
    		};
    	};
    };
    
    /{
        aliases{
            spi-flash0 = &mx25r64;
        };
    };

    I am using the exact sample without modifying anything in the main except including a header file for the spi.

    In the project configurations, SPI is enabled and QSPI is disabled; similarly in the overlay.

Children
No Data
Related