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

  • 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.

Related