USB Mass Storage sample not building with LittleFS on SDK 2.9 (nrf52840)

I'm trying to get the USB Mass Storage sample working on the nRF52840 using SDK 2.9. I followed the official guide here:
https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/samples/subsys/usb/mass/README.html

My goal is to use LittleFS as the storage backend for the USB Mass Storage device. However, when I try to build the sample using the following command:

west build -b nrf52840dk/nrf52840 samples/subsys/usb/mass -- -DCONFIG_APP_MSC_STORAGE_FLASH_LITTLEFS=y

I get a build error. I also tried with SDK 2.7 just in case, but I ran into the same issue.


I came across a similar question on the forums:
https://devzone.nordicsemi.com/f/nordic-q-a/117539/fs_sample-doesn-t-work-in-my-nrf52840-dk
But in that case, the suggested workaround was to use RAM instead of flash for storage, which doesn't quite fit my use case.

Am I missing something in the configuration? Is LittleFS currently supported as a backend for the USB MSC sample on nRF52840?

Thanks in advance

Parents
  • The specific error is:

     
    C:/ncs/v2.9.0-nRF54H20-1-rc2/zephyr/drivers/disk/flashdisk.c:533:1: error: return type defaults to 'int' [-Werror=implicit-int]
    533 | PM_FOREACH_AFFILIATED_TO_disk(DEFINE_FLASHDISKS_CACHE)
    | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.9.0-nRF54H20-1-rc2/zephyr/drivers/disk/flashdisk.c: In function 'PM_FOREACH_AFFILIATED_TO_disk':
    C:/ncs/v2.9.0-nRF54H20-1-rc2/zephyr/drivers/disk/flashdisk.c:572:30: error: storage class specified for parameter 'flash_disks'
    572 | static struct flashdisk_data flash_disks[] = {
    | ^~~~~~~~~~~
    C:/ncs/v2.9.0-nRF54H20-1-rc2/zephyr/drivers/disk/flashdisk.c:572:15: error: parameter 'flash_disks' is initialized
    572 | static struct flashdisk_data flash_disks[] = {
    | ^~~~~~~~~~~~~~
    C:/ncs/v2.9.0-nRF54H20-1-rc2/zephyr/drivers/disk/flashdisk.c:573:39: error: 'DEFINE_FLASHDISKS_DEVICE' undeclared (first use in this function)
    573 | PM_FOREACH_AFFILIATED_TO_disk(DEFINE_FLASHDISKS_DEVICE)
    | ^~~~~~~~~~~~~~~~~~~~~~~~

    ....

  • Hello Rodrigo,

    Could you please share your compiled partitions.yml file?

    Hieu

  • Hello Hieu,
    This is the content of  build/partitions.yml :

    app:
      address: 0x0
      end_address: 0xfa000
      region: flash_primary
      size: 0xfa000
    littlefs_storage:
      address: 0xfa000
      end_address: 0x100000
      placement:
        before:
        - end
      region: flash_primary
      size: 0x6000
    sram_primary:
      address: 0x20000000
      end_address: 0x20040000
      region: sram_primary
      size: 0x40000
Reply
  • Hello Hieu,
    This is the content of  build/partitions.yml :

    app:
      address: 0x0
      end_address: 0xfa000
      region: flash_primary
      size: 0xfa000
    littlefs_storage:
      address: 0xfa000
      end_address: 0x100000
      placement:
        before:
        - end
      region: flash_primary
      size: 0x6000
    sram_primary:
      address: 0x20000000
      end_address: 0x20040000
      region: sram_primary
      size: 0x40000
Children
  • Hello Rodrigo,

    Could you please add the following under your littlefs_storage node?

    littlefs_storage:
      affiliation:
      - disk

    The background is explained here: https://docs.nordicsemi.com/bundle/ncs-2.9.1/page/nrf/scripts/partition_manager/partition_manager.html#configuration_file_format

  • Thank you for your response. However, I’m not sure where exactly I should add the littlefs_storage node.

    I haven’t defined the littlefs_storage node in my configuration, and I could not find it in the available overlays in the sample I’m using.

    Could you please clarify whether I need to create a new Device Tree overlay or modify an existing one? If you could point me to the specific file or location where this should be added, it would be very helpful.

  • You will need to use a static Partition Manager configuration file. The simplest way to do so is copy partitions.yml to the root of your project and rename it pm_static.yml.

    Then subsequent build will refer to that files for all the partitioning configurations.

    In that file, you add the affiliation key and value under the littlefs_storage node.

    For more information, please refer to https://docs.nordicsemi.com/bundle/ncs-2.9.1/page/nrf/scripts/partition_manager/partition_manager.html.

  • Hello,

    I created the pm_static.yml file with the following contents, as you suggested:

    littlefs_storage:
      affiliation:
      - disk
      address: 0xfa000
      end_address: 0x100000
      placement:
        before:
        - end
      region: flash_primary
      size: 0x6000
      cache-size: 0x1000

    It seems that the file is correctly detected during the build.

    -- Found partition manager static configuration : C:/ncs/v2.9.0-nRF54H20-1-rc2/zephyr/samples/subsys/usb/mass/pm_static.yml Partition 'littlefs_storage' is not included in the dynamic resolving since it is statically defined.

    However, the build fails with the following error:

    C:/ncs/v2.9.0-nRF54H20-1-rc2/zephyr/drivers/disk/flashdisk.c:519:54: error: 'PM_LITTLEFS_STORAGE_EXTRA_PARAM_disk_cache_siz' undeclared here (not in a function)
    519 | #define PM_FLASH_DISK_ENTRY_EXTRA_PARAM(name, param) PM_##name##_EXTRA_PARAM_disk_##param
    | ^~~
    C:/ncs/v2.9.0-nRF54H20-1-rc2/zephyr/drivers/disk/flashdisk.c:529:24: note: in expansion of macro 'PM_FLASH_DISK_ENTRY_EXTRA_PARAM'
    529 | PM_FLASH_DISK_ENTRY_EXTRA_PARAM(n, cache_size))
    | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.9.0-nRF54H20-1-rc2/zephyr/drivers/disk/flashdisk.c:531:69: note: in expansion of macro 'CACHE_SIZE'
    531 | static uint8_t __aligned(4) PM_FLASH_DISK_CACHE_VARIABLE(n)[CACHE_SIZE(n)];
    .....

    This looks like a missing or undefined macro.

    Shouldn’t this sample build out of the box without requiring extra configuration or changes like this?

    If additional setup is indeed required for littlefs_storage, could you clarify the correct steps or provide a working example?

  • I finally get my sample to build by changing the pm_static.yaml as follows:

    littlefs_storage:
      affiliation: disk
      extra_params: {
          disk_name: "littlefs",
          disk_cache_size: 4096,
          disk_sector_size: 512,
          disk_read_only: 0
        }
      address: 0xfa000
      end_address: 0x100000
      placement:
        before:
        - end
      region: flash_primary
      size: 0x6000

Related