I’ve been working on getting the zephyr/samples/subsys/fs/littlefs sample working with the onboard external 4MB flash but can’t seem to make it work.

I’ve followed Jared’s issue on devzone (https://devzone.nordicsemi.com/f/nordic-q-a/62212/external-spi-flash-to-use-with-littlefs-on-nrf9160-w-mcuboot), but it still does not work.

Here is my prj.conf

# Filesystem
CONFIG_SPI=y
CONFIG_SPI_NOR=y
CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096

# Enable flash operations.
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_FLASH_PAGE_LAYOUT=y

# Enable the LittleFS file system.
CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_LITTLEFS=y

# CONFIG_APP_WIPE_STORAGE=y

# Nordic specific external flash stuff
CONFIG_PM_EXTERNAL_FLASH=y
CONFIG_PM_EXTERNAL_FLASH_DEV_NAME="W25Q32JV"
CONFIG_PM_EXTERNAL_FLASH_BASE=0x0
CONFIG_PM_EXTERNAL_FLASH_SIZE=0x2000000

and my .overlay

/delete-node/ &w25q16jv;

&spi3 {
	compatible = "nordic,nrf-spim";
	status = "okay";
	sck-pin = <11>;
	mosi-pin = <9>;
	miso-pin = <28>;
	cs-gpios = <&gpio0 7 GPIO_ACTIVE_LOW>;
	w25q32jv: w25q32jv@0 {
		compatible = "jedec,spi-nor";
		label = "W25Q32JV";
		reg = <0>;
		spi-max-frequency = <40000000>;
		wp-gpios = <&gpio0 8 GPIO_ACTIVE_LOW>;
		hold-gpios = <&gpio0 10 GPIO_ACTIVE_LOW>;
		size = <0x2000000>;
		has-dpd;
		t-enter-dpd = <4000>;
		t-exit-dpd = <25000>;
		jedec-id = [ef 40 16];
		has-be32k;
	};
};

The source code is the sample’s main.c

This is what I get:

Area 3 at 0xfa000 on NRF_FLASH_DRV_NAME for 24576 bytes
[00:00:01.588,348] [0m<inf> littlefs: LittleFS version 2.2, disk version 2.0[0m
[00:00:01.588,562] [0m<inf> littlefs: FS at NRF_FLASH_DRV_NAME:0xfa000 is 6 0x1000-byte blocks with 512 cycle[0m
[00:00:01.588,562] [0m<inf> littlefs: sizes: rd 16 ; pr 16 ; ca 64 ; la 32[0m
[00:00:01.588,714] [1;31m<err> littlefs: WEST_TOPDIR/modules/fs/littlefs/lfs.c:997: Corrupted dir pair at {0x0, 0x1}[0m
[00:00:01.588,714] [1;33m<wrn> littlefs: can't mount (LFS -84); formatting[0m
[00:00:01.588,775] [1;31m<err> os: ***** MPU FAULT *****[0m
[00:00:01.588,806] [1;31m<err> os:   Data Access Violation[0m
[00:00:01.588,806] [1;31m<err> os:   MMFAR Address: 0xfa000[0m
[00:00:01.588,867] [1;31m<err> os: r0/a1:  0x00000001  r1/a2:  0x00001000  r2/a3:  0x00000002[0m
[00:00:01.588,867] [1;31m<err> os: r3/a4:  0xffffffff r12/ip:  0x00000010 r14/lr:  0x0001fdfb[0m
[00:00:01.588,928] [1;31m<err> os:  xpsr:  0x01000000[0m
[00:00:01.588,958] [1;31m<err> os: s[ 0]:  0x00000000  s[ 1]:  0x00000000  s[ 2]:  0x00000000  s[ 3]:  0x00000000[0m
[00:00:01.588,989] [1;31m<err> os: s[ 4]:  0x00000000  s[ 5]:  0x00000000  s[ 6]:  0x00000000  s[ 7]:  0x00000000[0m
[00:00:01.589,019] [1;31m<err> os: s[ 8]:  0x00000000  s[ 9]:  0x00000000  s[10]:  0x00000000  s[11]:  0x00000000[0m
[00:00:01.589,050] [1;31m<err> os: s[12]:  0x00000000  s[13]:  0x00000000  s[14]:  0x00000000  s[15]:  0x00000000[0m
[00:00:01.589,050] [1;31m<err> os: fpscr:  0x00000000[0m
[00:00:01.589,050] [1;31m<err> os: Faulting instruction address (r15/pc): 0x0001fdfe[0m
[00:00:01.589,080] [1;31m<err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0[0m
[00:00:01.589,080] [1;31m<err> os: Current thread: 0x20020c38 (unknown)[0m
[00:00:01.762,664] [1;31m<err> os: Halting system[0m

Any ideas?

  • jaredwolff replied to this.
  • Hey imoon. Hmm that’s funky.

    Check out the example in this repository. You can clone it and place it in the ncs root folder. You should be able to do a west build in samples/external_flash/

    What’ you’ve done above is correct though. Make sure that when initializing the flash inside you’re code you’re using FLASH_AREA_ID (external_flash)

    FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(storage);
    static struct fs_mount_t lfs_storage_mnt = {
    		.type = FS_LITTLEFS,
    		.fs_data = &storage,
    		.storage_dev = (void *)FLASH_AREA_ID(external_flash),
    		.mnt_point = "/lfs",
    };
    imoon changed the title to littlefs on external flash not working - MPU FAULT .

    Hey imoon. Hmm that’s funky.

    Check out the example in this repository. You can clone it and place it in the ncs root folder. You should be able to do a west build in samples/external_flash/

    What’ you’ve done above is correct though. Make sure that when initializing the flash inside you’re code you’re using FLASH_AREA_ID (external_flash)

    FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(storage);
    static struct fs_mount_t lfs_storage_mnt = {
    		.type = FS_LITTLEFS,
    		.fs_data = &storage,
    		.storage_dev = (void *)FLASH_AREA_ID(external_flash),
    		.mnt_point = "/lfs",
    };

      jaredwolff YES - FLASH_AREA_ID (external_flash) was it! It was set to storage in the sample code.

      I get this now:

      Area 0 at 0x0 on W25Q32JV for 33554432 bytes
      /lfs mount: 0/lfs: bsize = 16 ; frsize = 4096 ; blocks = 8192 ; bfree = 8190
      /lfs/boot_count stat: -2
      /lfs/boot_count read count 0: 0
      /lfs/boot_count seek start: 0
      /lfs/boot_count write new boot count 1: 4
      /lfs/boot_count close: 0
      /lfs opendir: 0
        F 4 boot_count
      End of files
      /lfs unmount: 0
      [00:00:01.709,106] [0m<inf> littlefs: LittleFS version 2.2, disk version 2.0[0m
      [00:00:01.710,113] [0m<inf> littlefs: FS at W25Q32JV:0x0 is 8192 0x1000-byte blocks with 512 cycle[0m
      [00:00:01.710,113] [0m<inf> littlefs: sizes: rd 16 ; pr 16 ; ca 64 ; la 32[0m
      [00:00:01.710,998] [0m<inf> littlefs: /lfs mounted[0m
      [00:00:01.719,726] [1;31m<err> fs: failed get file or dir stat (-2)[0m
      [00:00:01.743,499] [0m<inf> littlefs: /lfs unmounted[0m

      Thank you very much

      @jaredwolff - Also a big thank you for the samples repo! Very helpful. I’ve been figuring most of those out on my own over the past few weeks so this is a very nice addition to the community!

        imoon Sorry it took so long. The explanation is going up on Nordic’s Devzone Blog very soon.

        11 days later
        a year later

        Hi Jared, I just purchased a few of your fine devices, and was trying each of the sample applications. A couple of notes.

        1. The serial terminal defaults to 1MBit/s Based on what the bootloader is set to, so when you try and debug something at 115k it appears as junk.

        2. The external flash example didn’t compile out of the box, it was missing the following #defines in prj.conf

        https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/how-to-use-the-nrf9160-feather

        # Nordic specific external flash stuff
        CONFIG_PM_EXTERNAL_FLASH=y
        CONFIG_PM_EXTERNAL_FLASH_DEV_NAME="W25Q32JV"
        CONFIG_PM_EXTERNAL_FLASH_BASE=0x0
        #CONFIG_PM_EXTERNAL_FLASH_SIZE=0x2000000
        CONFIG_PM_EXTERNAL_FLASH_SIZE=0x400000

        also the flash size was set to 32MBYTES, rather than 32MBits. so it wouldn’t compile.

        With the version of samples that I had, I didn’t need to modify the .overlay of main.c files as you have all this sorted already.

        Hopefully this helps someone out.

        Here’s the log (at 1MBit/s)

        *** Booting Zephyr OS build v2.6.99-ncs1-1  ***
        Area 0 at 0x0 on W25Q32JV for 4194304 bytes
        [00:00:00.003,753] <inf> littlefs: LittleFS version 2.2, disk version 2.0
        [00:00:00.005,889] <inf> littlefs: FS at W25Q32JV:0x0 is 1024 0x1000-byte blocks with 512 cycle
        [00:00:00.007,476] <inf> littlefs: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
        [00:00:00.010,101] <inf> littlefs: /lfs mounted
        /lfs mount: 0
        /lfs: bsize = 16 ; frsize = 4096 ; blocks = 1024 ; bfree = 1022
        /lfs/boot_count stat: -2
        FAIL: open /lfs/boot_count: -16
        [00:00:00.014,739] <inf> littlefs: /lfs unmounted
        /lfs unmount: 0

          marshallbrown123 The serial terminal defaults to 1MBit/s Based on what the bootloader is set to, so when you try and debug something at 115k it appears as junk.

          That is expected. Needs the 1M in order to transfer via the bootloader. Otherwise it takes 2 minutes + every time you want load a new firmware over USB. 😅

          Thanks for the notes on the external flash sample. What branch were you using for NFED? Current supported is v1.7.x which does not use those config variables anymore.

          Terms and Conditions | Privacy Policy