This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to get started with zephyr fs on external NOR flash

Hi,

I have gone through the lfs file system from zephyr samples but I could not find any solid documentation for fs and spi flash drivers available. 

I have written the  flash driver codes based on SPI and now i want to use the littlefs file system on this. How do I enable lfs by using SPI drivers?

Since most of the initialization is static and adds before main(), I couldn't figure out how to integrate the SPI read/write functions to the file system.

  • You should be able to use the littlefs sample with external flash over SPI. You need to do the following:

    CONFIG_SPI_NOR=y
    CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096

    Comment out these lines, and add the following:

    &qspi {
    	status = "disabled";
    };
    
    &spi3 {
    	status = "okay";
        mosi-pin = <20>;
        miso-pin = <21>;
        sck-pin = <19>;
    	cs-gpios = <&gpio0 17 GPIO_ACTIVE_LOW >;
        mx25r64: mx25r6435f@0  {
            compatible = "jedec,spi-nor";
            label = "MX25R64";
            reg = <0>;
            spi-max-frequency = <8000000>;
            jedec-id = [c2 28 17];
            size = <67108864>;
            has-be32k;
            has-dpd;
            t-enter-dpd = <10000>;
            t-exit-dpd = <35000>;
        };
    };

    This demonstrates how to use the nRF52840 DK onboard mx25r64 flash. If you're using a different flash device, you would need to modify the overlay file accordingly. I have not tested this, so I may have missed out on something

    This case may be helpful, even thought it's about qspi, I explain in some detail how stuff works in Zephyr and how everything is coupled together.

    https://devzone.nordicsemi.com/f/nordic-q-a/72045/flash-filing-system-for-nrf-connect-sdk

    Best regards,

    Simon

Related