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 
  • AKO said:
    I have checked this example but it didn't worked for me

    What do you mean by "did not work"? Did it not compile well? Were you able to flash it? Did you get runtime error?

    AKO said:
    but here I see that no function is assigned to api->erase 

    In the main, you will see that we are getting the flash device from the devicetree by calling DEVICE_DT_GET().

    Therefore, the drivers configured for that device in the DTS would be used to connect to the flash api.

    I have compiled the example for NRF52840, and I can see (in the DTS) that spi-flash0 is using QSPI-NOR driver from NORDIC (see compatible), and in the NRF_QSPI_NOR.C file we see that:

    Hence the flash erase would eventually connect with qspi_nor_erase from this driver.

    If you are unfamiliar with this then I would recommend you to go through the DevAcademy courses that would quickly ramp up expertise working with NCS/Zephyr. 

    Warm regards,

    Naeem

Reply
  • AKO said:
    I have checked this example but it didn't worked for me

    What do you mean by "did not work"? Did it not compile well? Were you able to flash it? Did you get runtime error?

    AKO said:
    but here I see that no function is assigned to api->erase 

    In the main, you will see that we are getting the flash device from the devicetree by calling DEVICE_DT_GET().

    Therefore, the drivers configured for that device in the DTS would be used to connect to the flash api.

    I have compiled the example for NRF52840, and I can see (in the DTS) that spi-flash0 is using QSPI-NOR driver from NORDIC (see compatible), and in the NRF_QSPI_NOR.C file we see that:

    Hence the flash erase would eventually connect with qspi_nor_erase from this driver.

    If you are unfamiliar with this then I would recommend you to go through the DevAcademy courses that would quickly ramp up expertise working with NCS/Zephyr. 

    Warm regards,

    Naeem

Children
Related