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

  • 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

  • Hi Rodrigo,

    I am glad you figured out the extra params. My apology that I missed it initially.

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

    So, there are two parts to this.

    Firstly, Partition Manager was created to address RAM and ROM partitioning needs in the early days of Zephyr, when Zephyr didn't have a native solution for those. It then soon got tightly entangled with the SDK.

    Secondly, both the USB samples and LittleFS samples come from the Zephyr upstream, so they are created for Zephyr in general and naturally do not have consideration for NCS. So, adaptation to work in NCS environment is necessary.
    You might find other Zephyr samples having issues working in NCS or with nRF boards too for this reason. Sometimes it is because of Partition Manager, sometimes it's because the samples are created specifically for another board vendor.

    Please feel free to close the case at your convenience then.

  • Hi Hieu,

    Thanks for your previous support.

    Despite all my efforts, I’m still unable to get the USB Mass Storage sample to work properly on my target. After a successful build and flash, I get the following output in the logs:

    *** Using Zephyr OS v3.7.99-706ab3d781e4 *** [00:00:00.265,777]
    <err> usb_msc: Storage init ERROR !!!! - Aborting USB init Area 1 at 0xfa000 on flash-controller@4001e000 for 24576 bytes [00:00:00.265,838] <inf> littlefs: LittleFS version 2.9, disk version 2.1 [00:00:00.266,052] <inf> littlefs: FS at flash-controller@4001e000:0xfa000 is 6 0x1000-byte blocks with 512 cycle [00:00:00.266,082] <inf> littlefs: sizes: rd 16 ; pr 16 ; ca 64 ; la 32 Mount /lfs: 0 /lfs: bsize = 16 ; frsize = 4096 ; blocks = 6 ; bfree = 4 /lfs opendir: 0 End of files [00:00:00.317,291] <inf> main: The device is put in USB mass storage mode.

    On the host side (Ubuntu), I see that the device is detected but unmountable:

    usb-storage 1-1:1.0: USB Mass Storage device detected scsi 1:0:0:0: Direct-Access Zephyr FlashDisk 0.00 PQ: 0 ANSI: 4 sd 1:0:0:0: [sda] Media removed, stopped polling

    From the log, LittleFS seems to be mounting fine, and the device appears as /lfs. However, the usb_msc: Storage init ERROR message is confusing—especially since it later proceeds to "put the device in USB mass storage mode."

    Should I open a new ticket for this new issue?  

  • Hi Rodrigo,

    Perhaps a new ticket is applicable here, since the original question is about building.

    However, before you do, please check if this is what TurboJ mentioned in his reply. PC OSes don't support LittleFS out of the box, so you can't expect default file browsing programs to just work with your LittleFS USB device. You need drivers or a special USB host program.

  • Check out how the zephyr log stuff works, the log message identified the source file (msc.c). You could also just grep the message itself.

    Looking through the code for 20 sec I would suggest checking CONFIG_MASS_STORAGE_DISK_NAME because that determines what the code uses as storage backend for USB MSC.

Reply Children
No Data
Related