Do we have any example for use flash as usb mass storage on Zephyr?

I am trying to use Xiao BLE Sence QSPI flash as a storage, but got error like this
Any one can help?

/home/wols/Documents/Wols/zephyrproject/zephyr/samples/subsys/usb/mass/src/main.c:36:2: error: #error No supported disk driver enabled
   36 | #error No supported disk driver enabled
      |  ^~~~~
[17/106] Building C object zephyr/lib/libc/common/CMakeFiles/lib__libc__common.dir/source/stdlib/malloc.c.obj
ninja: build stopped: subcommand failed.

Here is build cmd

west build -b xiao_ble/nrf52840/sense zephyr/samples/subsys/usb/mass -DCONFIG_APP_MSC_STORAGE_FLASH_FATFS=y

Here is overlay

/delete-node/ &storage_partition;
/ {
    chosen {
        zephyr,ieee802154 = &ieee802154;
    };

};
&p25q16h{
    partitions {
        compatible = "fixed-partitions";
        #address-cells = <1>;
        #size-cells = <1>;

        storage_partition: partition@0 {
            label = "storage";
            reg = <0x00000000 0x00020000>;
        };
    };
};
1 Like

Hi there,

So which Toolchain are you using, and Did you run the Kconfig,to enable the driver. for QSPI look into that.

HTH
GL :slight_smile: PJ :v:

Hi PJ_Glasso
Here is build info

$ west build -p always --pristine -b xiao_ble/nrf52840/sense zephyr/samples/subsys/usb/mass 
-- west build: making build dir /home/wols/Documents/Wols/zephyrproject/build pristine
-- west build: generating a build system
Loading Zephyr default modules (Zephyr base).
-- Application: /home/wols/Documents/Wols/zephyrproject/zephyr/samples/subsys/usb/mass
-- CMake version: 3.20.5
-- Found Python3: /home/wols/Documents/Wols/zephyrproject/.venv/bin/python3 (found suitable version "3.10.12", minimum required is "3.10") found components: Interpreter 
-- Cache files will be written to: /home/wols/.cache/zephyr
-- Zephyr version: 4.1.0-rc2 (/home/wols/Documents/Wols/zephyrproject/zephyr)
-- Found west (found suitable version "1.3.0", minimum required is "0.14.0")
-- Board: xiao_ble, qualifiers: nrf52840/sense
-- ZEPHYR_TOOLCHAIN_VARIANT not set, trying to locate Zephyr SDK
-- Found host-tools: zephyr 0.17.0 (/home/wols/zephyr-sdk-0.17.0)
-- Found toolchain: zephyr 0.17.0 (/home/wols/zephyr-sdk-0.17.0)
-- Found Dtc: /home/wols/zephyr-sdk-0.17.0/sysroots/x86_64-pokysdk-linux/usr/bin/dtc (found suitable version "1.6.0", minimum required is "1.4.6") 
-- Found BOARD.dts: /home/wols/Documents/Wols/zephyrproject/zephyr/boards/seeed/xiao_ble/xiao_ble_nrf52840_sense.dts
-- Generated zephyr.dts: /home/wols/Documents/Wols/zephyrproject/build/zephyr/zephyr.dts
-- Generated pickled edt: /home/wols/Documents/Wols/zephyrproject/build/zephyr/edt.pickle
-- Generated devicetree_generated.h: /home/wols/Documents/Wols/zephyrproject/build/zephyr/include/generated/zephyr/devicetree_generated.h
-- Including generated dts.cmake file: /home/wols/Documents/Wols/zephyrproject/build/zephyr/dts.cmake

warning: DISK_DRIVER_FLASH (defined at drivers/disk/Kconfig.flash:4) was assigned the value 'y' but
got the value 'n'. Check these unsatisfied dependencies: DT_HAS_ZEPHYR_FLASH_DISK_ENABLED (=n). See
http://docs.zephyrproject.org/latest/kconfig.html#CONFIG_DISK_DRIVER_FLASH and/or look up
DISK_DRIVER_FLASH in the menuconfig/guiconfig interface. The Application Development Primer, Setting
Configuration Values, and Kconfig - Tips and Best Practices sections of the manual might be helpful
too.

And folder tree

$ tree zephyr/samples/subsys/usb/mass 
zephyr/samples/subsys/usb/mass
├── boards
│   ├── adafruit_feather_nrf52840_sense.overlay
│   ├── nrf52840dk_nrf52840.overlay
│   ├── nrf5340dk_nrf5340_cpuapp.overlay
│   ├── rpi_pico.overlay
│   ├── sensortile_box_pro.conf
│   ├── stm32l562e_dk_stm32l562xx_ns.conf
│   ├── xiao_ble_nrf25840_sence.conf
│   └── xiao_ble_nrf25840_sence.overlay
├── CMakeLists.txt
├── Kconfig
├── prj.conf
├── ramdisk.overlay
├── README.rst
├── src
│   └── main.c
└── usbd_next_prj.conf

2 directories, 15 files

xiao_ble_nrf25840_sence.conf

CONFIG_MAIN_STACK_SIZE=2048
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=8192

CONFIG_DISK_ACCESS=y
CONFIG_DISK_DRIVERS=y

CONFIG_FILE_SYSTEM=y
CONFIG_FAT_FILESYSTEM_ELM=y
CONFIG_DISK_DRIVER_FLASH=y

Hi there,

So , You would benefit from watching the Webinars on the Dev academy training , It’s free. Number 8 shows what you are stuck at.
The message at the bottom(warning) telling you the issue, DID you open the Kconfig menu? Did you navigate to Drivers, and select the QSPI for the flash ? Probably NOT?
Your closer though, Keep going. I see this was a pristine build so that a start. You’ll need a build that includes the boot loader and the QSPI flash drivers too. Did you make a Partition manager . yaml file for the build ? Looks like your short a few steps.
hit this link and See where it went sideways…

HTH
GL :slight_smile: PJ :v:

The error:

#error No supported disk driver enabled

indicates that Zephyr’s Mass Storage Class (MSC) sample is missing a proper disk driver — in this case, it’s trying to use QSPI Flash with FATFS, but the configuration or overlay likely doesn’t correctly set up the flash as a usable disk device.
Enable the CONFIG_DISK_ACCESS_FLASH and related FATFS options.

Hi there,

SO , In Zephyr Kconfig, dependencies override your direct config choice.
So even if you manually write CONFIG_DISK_DRIVER_FLASH=y, it gets turned off (n) if its dependency like DT_HAS_ZEPHYR_FLASH_DISK_ENABLED is n.

This is why he sees the warning — not an error, but a heads-up that the config request was ignored.

The unmet dependency is:

DT_HAS_ZEPHYR_FLASH_DISK_ENABLED (=n)

This means that the device tree does not define a “flash-disk” node (usually under /flash, or some partition label).

What’s Missing / Likely Cause:

  • The user did not enable or define a proper flash partition (storage node) in their Device Tree overlay (DTS).
  • They may also have missed enabling:
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_FLASH_PAGE_LAYOUT=y
  • Without the correct partition label (like "storage") or disk definition, Zephyr’s auto-detection fails to turn on DT_HAS_ZEPHYR_FLASH_DISK_ENABLED.

Example of a Correct Setup:

Device Tree fragment (often in boards/*.overlay):

/ {
    storage_partition: partition@00030000 {
        label = "storage";
        reg = <0x00030000 0x00010000>;  // Start address and size
    };
};

and the supporting prj…

prj.conf example:

CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_DISK_DRIVER_FLASH=y
CONFIG_FILE_SYSTEM=y
CONFIG_FAT_FILESYSTEM_ELM=y

bottom line… You need to make sure your Device Tree defines a flash partition (label “storage”) and enable the following configs:

CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_DISK_DRIVER_FLASH=y

Use menuconfig or guiconfig to confirm these.
Also make sure your DTS overlay includes a properly defined storage partition.

HTH
GL :slight_smile: PJ :v:

Listen to your compiler…LOL :+1: