Example of using external flash that is on nRF5340dk ?

Im having trouble setting up and using flash on nRF5340dk. 

Is there any example on how to use LittleFS on external flash that is on the dev kit?

Parents
  • Hi, 

    Here is the example https://github.com/nrfconnect/sdk-zephyr/tree/main/samples/subsys/fs/littlefs.  

    Please duplicate this https://github.com/nrfconnect/sdk-zephyr/blob/main/samples/subsys/fs/littlefs/boards/nrf52840dk_nrf52840_qspi.conf  config file and rename it to nrf5340dk_nrf5340_cpuapp.conf.

    Duplicate https://github.com/nrfconnect/sdk-zephyr/blob/main/samples/subsys/fs/littlefs/boards/nrf52840dk_nrf52840_qspi.overlay overlay file, rename it to nrf5340dk_nrf5340_cpuapp.overlay and update with the following content:

    /*
     * Copyright (c) 2019 Peter Bigot Consulting, LLC
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    /delete-node/ &storage_partition;
    
    / {
    	chosen {
    		nordic,pm-ext-flash = &mx25r64;
    	};
    	
    	fstab {
    		compatible = "zephyr,fstab";
    		lfs1: lfs1 {
    			compatible = "zephyr,fstab,littlefs";
    			mount-point = "/lfs1";
    			partition = <&lfs1_part>;
    			automount;
    			read-size = <16>;
    			prog-size = <16>;
    			cache-size = <64>;
    			lookahead-size = <32>;
    			block-cycles = <512>;
    		};
    	};
    };
    
    &mx25r64 {
    	partitions {
    		compatible = "fixed-partitions";
    		#address-cells = <1>;
    		#size-cells = <1>;
    
    		lfs1_part: partition@0 {
    			label = "storage";
    			reg = <0x00000000 0x00010000>;
    		};
    	};
    };
    

    Then, you could get the output like this

    Regards,
    Amanda H.

  • Ok, an Update. As soon as I add 

    CONFIG_BT=y to nrf5340dk_nrf5340_cpuapp.conf
    the example stops working.
    Been testing for hours now removing and adding line by line and as soon BT is enabled the example falls apart.
  • nrf5340dk_nrf5340_cpuapp.overlay

    /delete-node/ &storage_partition;
    
    / {
    	chosen {
    		nordic,pm-ext-flash = &mx25r64;
    	};
    
    	fstab {
    		compatible = "zephyr,fstab";
    		lfs1: lfs1 {
    			compatible = "zephyr,fstab,littlefs";
    			mount-point = "/lfs1";
    			partition = <&lfs1_part>;
    			automount;
    			read-size = <16>;
    			prog-size = <16>;
    			cache-size = <64>;
    			lookahead-size = <32>;
    			block-cycles = <512>;
    		};
    	};
    };
    
    &mx25r64 {
    	partitions {
    		compatible = "fixed-partitions";
    		#address-cells = <1>;
    		#size-cells = <1>;
    
    		lfs1_part: partition@0 {
    			label = "storage";
    			reg = <0x00000000 0x00800000>;
    		};
    	};
    };

    added CONFIG_PM_PARTITION.... to prj.conf

    CONFIG_MAIN_STACK_SIZE=2048
    
    # Let __ASSERT do its job
    CONFIG_DEBUG=y
    
    CONFIG_LOG=y
    CONFIG_LOG_MODE_MINIMAL=y
    
    CONFIG_FLASH=y
    CONFIG_FLASH_MAP=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    
    CONFIG_FILE_SYSTEM=y
    CONFIG_FILE_SYSTEM_LITTLEFS=y
    
    CONFIG_PM_PARTITION_REGION_LITTLEFS_EXTERNAL=y

    pm_static.yml is:

    littlefs_storage:
    address: 0
    end_address: 0x800000
    placement:
    before:
    - end
    region: external_flash
    size: 0x800000
    

    Now Im getting:

    I: LittleFS version 2.5, disk version 2.0
    I: FS at mx25r6435f@0:0x0 is 6 0x1000-byte blocks with 512 cycle
    I: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
    I: /lfs1 mounted
    I: Automount /lfs1 succeeded
    *** Booting Zephyr OS build v3.2.99-ncs2 ***
    Sample program to r/w files on littlefs
    Area 1 at 0x0 on mx25r6435f@0 for 24576 bytes
    /lfs1 automounted
    /lfs1: bsize = 16 ; frsize = 4096 ; blocks = 6 ; bfree = 3

    at least its on mx25, but the size is wrong, it should be 8mb

  • found what was wrong. There were several issues. First and most stupid was that directive in CMakeLists.txt was set to root of project and not to boards folder.

    set(PM_STATIC_YML_FILE ${CMAKE_CURRENT_SOURCE_DIR}/boards/pm_static.yml).
    Next it could not find where the partition was so the device was added to pm_static.yml
    littlefs_storage:
      address: 0x0
      end_address: 0x800000
      placement:
        before:
          - end
      device: mx25r64
      region: external_flash
      size: 0x800000
      filesystem: littlefs
    And at the end the the 
    CONFIG_PM_PARTITION_REGION_LITTLEFS_EXTERNAL=y 
    was removed from prj.conf. 
    Now it works....
Reply
  • found what was wrong. There were several issues. First and most stupid was that directive in CMakeLists.txt was set to root of project and not to boards folder.

    set(PM_STATIC_YML_FILE ${CMAKE_CURRENT_SOURCE_DIR}/boards/pm_static.yml).
    Next it could not find where the partition was so the device was added to pm_static.yml
    littlefs_storage:
      address: 0x0
      end_address: 0x800000
      placement:
        before:
          - end
      device: mx25r64
      region: external_flash
      size: 0x800000
      filesystem: littlefs
    And at the end the the 
    CONFIG_PM_PARTITION_REGION_LITTLEFS_EXTERNAL=y 
    was removed from prj.conf. 
    Now it works....
Children
No Data
Related