External Flash using SPI on nRF5340 DK

I want to use the external flash on the nRF5340 DK using SPI as the board I'm developing for will not have QSPI. I used the littlefs sample which has a lot of the settings I need, like those in the spi_flash sample:

CONFIG_STDOUT_CONSOLE=y
CONFIG_FLASH=y
CONFIG_SPI=y

Which gives me:

*** Booting nRF Connect SDK v3.5.99-ncs1-1 ***

mx25r6435f@0 SPI flash testing
==========================

Perform test on single sector
Test 1: Flash erase
Flash erase succeeded!

Test 2: Flash write
Attempting to write 4 bytes
Data read matches data written. Good!!

I see it's using external flash because of the flash_dev->name print.

Now if I add add CONFIG_SPI=y to the littlefs sample I get:

*** Booting nRF Connect SDK v3.5.99-ncs1-1 ***
Sample program to r/w files on littlefs
Area 5 at 0xf8000 on flash-controller@39000 for 32768 bytes
I: LittleFS version 2.5, disk version 2.0
I: FS at flash-controller@39000:0xf8000 is 8 0x1000-byte blocks with 512 cycle
I: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
/lfs mount: 0
/lfs: bsize = 16 ; frsize = 4096 ; blocks = 8 ; bfree = 5

Listing dir /lfs ...
[FILE] boot_count (size = 1)
[FILE] pattern.bin (size = 547)
/lfs/boot_count read count:11 (bytes: 1)
/lfs/boot_count write new boot count 12: [wr:1]
------ FILE: /lfs/pattern.bin ------
0c 55 55 55 55 55 55 55 0d 55 55 55 55 55 55 55

I've got another ticket open for a number of things I'm trying to do but just wanted to see if I could get external flash using spi and littlefs and I'm having trouble with this.

Parents
  • Hi,

     

    Have you followed the guide explained here?

    https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/scripts/partition_manager/partition_manager.html#external_flash_memory_partitions

     

    You will need to add a pm_static.yml file with the following (change sizes etc. to your liking):

    littlefs_storage:
      address: 0x0
      device: mx25r6435f
      region: external_flash
      size: 0x400000
    external_flash:
      address: 0x400000
      device: mx25r6435f
      region: external_flash
      size: 0x400000

     

    Then add your overlay:

    /delete-node/ &storage_partition;
    
    / {
    	chosen {
    		nordic,pm-ext-flash = &mx25r64;
    	};
    };
    
    &mx25r64 {
        status = "okay";
    	partitions {
    		compatible = "fixed-partitions";
    		#address-cells = <1>;
    		#size-cells = <1>;
    
    		storage_partition: partition@0 {
    			label = "storage";
    			reg = <0x00000000 0x00010000>;
    		};
    	};
    };

     

    And the corresponding config:

    CONFIG_SPI=y
    CONFIG_SPI_NOR=y
    CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
    CONFIG_FLASH=y
    CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y
    CONFIG_PM_PARTITION_REGION_LITTLEFS_EXTERNAL=y

     

    Then it should run towards ext flash:

    *** Booting nRF Connect SDK v2.8.0-a2386bfc8401 ***
    *** Using Zephyr OS v3.7.99-0bc3393fb112 ***
    Sample program to r/w files on littlefs
    Area 0 at 0x0 on mx25r6435f@1 for 4194304 bytes
    I: LittleFS version 2.9, disk version 2.1
    I: FS at mx25r6435f@1:0x0 is 1024 0x1000-byte blocks with 512 cycle
    I: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
    E: WEST_TOPDIR/modules/fs/littlefs/lfs.c:1374: Corrupted dir pair at {0x1, 0x0}
    W: can't mount (LFS -84); formatting
    I: /lfs mounted
    /lfs mount: 0
    /lfs: bsize = 16 ; frsize = 4096 ; blocks = 1024 ; bfree = 1022
    
    Listing dir /lfs ...
    /lfs/boot_count read count:0 (bytes: 0)
    /lfs/boot_count write new boot count 1: [wr:1]
    I: Test file: /lfs/pattern.bin not found, create one!
    ...

     

    Kind regards,

    Håkon

Reply
  • Hi,

     

    Have you followed the guide explained here?

    https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/scripts/partition_manager/partition_manager.html#external_flash_memory_partitions

     

    You will need to add a pm_static.yml file with the following (change sizes etc. to your liking):

    littlefs_storage:
      address: 0x0
      device: mx25r6435f
      region: external_flash
      size: 0x400000
    external_flash:
      address: 0x400000
      device: mx25r6435f
      region: external_flash
      size: 0x400000

     

    Then add your overlay:

    /delete-node/ &storage_partition;
    
    / {
    	chosen {
    		nordic,pm-ext-flash = &mx25r64;
    	};
    };
    
    &mx25r64 {
        status = "okay";
    	partitions {
    		compatible = "fixed-partitions";
    		#address-cells = <1>;
    		#size-cells = <1>;
    
    		storage_partition: partition@0 {
    			label = "storage";
    			reg = <0x00000000 0x00010000>;
    		};
    	};
    };

     

    And the corresponding config:

    CONFIG_SPI=y
    CONFIG_SPI_NOR=y
    CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
    CONFIG_FLASH=y
    CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y
    CONFIG_PM_PARTITION_REGION_LITTLEFS_EXTERNAL=y

     

    Then it should run towards ext flash:

    *** Booting nRF Connect SDK v2.8.0-a2386bfc8401 ***
    *** Using Zephyr OS v3.7.99-0bc3393fb112 ***
    Sample program to r/w files on littlefs
    Area 0 at 0x0 on mx25r6435f@1 for 4194304 bytes
    I: LittleFS version 2.9, disk version 2.1
    I: FS at mx25r6435f@1:0x0 is 1024 0x1000-byte blocks with 512 cycle
    I: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
    E: WEST_TOPDIR/modules/fs/littlefs/lfs.c:1374: Corrupted dir pair at {0x1, 0x0}
    W: can't mount (LFS -84); formatting
    I: /lfs mounted
    /lfs mount: 0
    /lfs: bsize = 16 ; frsize = 4096 ; blocks = 1024 ; bfree = 1022
    
    Listing dir /lfs ...
    /lfs/boot_count read count:0 (bytes: 0)
    /lfs/boot_count write new boot count 1: [wr:1]
    I: Test file: /lfs/pattern.bin not found, create one!
    ...

     

    Kind regards,

    Håkon

Children
No Data
Related