Looking for USB MSC + nRF52840 internal flash + FATFS sample

Hi, DEVZONE, 

nRF52840DK

nRF connect SDK,  v3.0.1

sample :    ~~\ncs\v3.0.1\zephyr\samples\subsys\usb\mass

it has    internal ram-based FAT,  external-Flash FAT configuration, but it doesn't have internal-Flash + FAT configuration.

Can someone suggest any sample for it ?

Or can someone teach me how to update the sample code to use internal flash ?


Regards,

Parents
  • USB MSC with nRF52840 Internal Flash and FATFS Sample

    Based on your request for a USB Mass Storage Class (MSC) sample using nRF52840's internal flash with FATFS in nRF Connect SDK v3.0.1, here's what I can tell you:

    Current Situation

    The mass storage sample in `ncs\v3.0.1\zephyr\samples\subsys\usb\mass` indeed provides configurations for:
    - RAM-based FAT (virtual disk)
    - External flash (like SPI NOR flash) with FATFS

    But it doesn't include a configuration for internal flash (the nRF52840's 1MB flash) with FATFS.

    How to Modify for Internal Flash

    To adapt the sample to use internal flash, you'll need to:

    1. Configure the storage partition in your devicetree overlay:
    ```dts
    / {
    chosen {
    zephyr,flash-controller = &flash_controller;
    zephyr,storage-partition = &storage_partition;
    };

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

    storage_partition: partition@F0000 {
    label = "storage";
    reg = <0x000F0000 0x00010000>;
    };
    };
    };
    ```

    2. Modify prj.conf to use internal flash:
    ```
    CONFIG_DISK_DRIVER_FLASH=y
    CONFIG_FLASH=y
    CONFIG_FLASH_MAP=y
    CONFIG_FILE_SYSTEM=y
    CONFIG_FAT_FILESYSTEM_ELM=y
    ```

    3. Update the code to use the internal flash driver instead of external flash.

    Alternative Solutions

    1. Check newer SDK versions: nRF Connect SDK v3.1.0+ might have better support for this configuration.

    2. Nordic DevZone examples: Search for "USB MSC internal flash" on Nordic's DevZone for community examples.

    3. Zephyr documentation: Refer to Zephyr's USB and filesystem documentation for guidance on combining these features.

  • Hi Jim, 

    With your comment, I successfully compiled the code and mounted internal flash to USB MSC. 
    Thanks. 

    But, unfortunately, to compile successfully, I had to put   sysbuild.conf  file. 
    Filename :    sysbuild.conf
    content :       SB_CONFIG_PARTITION_MANAGER=n

    Is there way that I can remove this configuration ? 


    If I remove sysbuild.conf file, I get following error message, 

    [23/193] Building C object CMakeFiles/app.dir/src/main.c.obj
    FAILED: CMakeFiles/app.dir/src/main.c.obj
    ~~~~
    In file included from C:/ncs/v3.0.1/zephyr/include/zephyr/storage/flash_map.h:330,
    from P:/ws_USB_MSC__1st/src/main.c:21:
    P:/ws_USB_MSC__1st/src/main.c: In function 'setup_flash':
    C:/ncs/v3.0.1/nrf/include/flash_map_pm.h:47:22: error: 'PM_storage_partition_ID' undeclared (first use in this function)
    47 | #define PM_ID(label) PM_##label##_ID
    | ^~~
    C:/ncs/v3.0.1/nrf/include/flash_map_pm.h:52:35: note: in expansion of macro 'PM_ID'
    52 | #define FIXED_PARTITION_ID(label) PM_ID(label)
    | ^~~~~
    P:/ws_USB_MSC__1st/src/main.c:40:41: note: in expansion of macro 'FIXED_PARTITION_ID'
    40 | #define STORAGE_PARTITION_ID FIXED_PARTITION_ID(STORAGE_PARTITION)
    | ^~~~~~~~~~~~~~~~~~
    P:/ws_USB_MSC__1st/src/main.c:88:36: note: in expansion of macro 'STORAGE_PARTITION_ID'
    88 | mnt->storage_dev = (void *)STORAGE_PARTITION_ID;
    | ^~~~~~~~~~~~~~~~~~~~
    C:/ncs/v3.0.1/nrf/include/flash_map_pm.h:47:22: note: each undeclared identifier is reported only once for each function it appears in
    47 | #define PM_ID(label) PM_##label##_ID
    | ^~~
    C:/ncs/v3.0.1/nrf/include/flash_map_pm.h:52:35: note: in expansion of macro 'PM_ID'
    52 | #define FIXED_PARTITION_ID(label) PM_ID(label)
    | ^~~~~
    P:/ws_USB_MSC__1st/src/main.c:40:41: note: in expansion of macro 'FIXED_PARTITION_ID'
    40 | #define STORAGE_PARTITION_ID FIXED_PARTITION_ID(STORAGE_PARTITION)
    | ^~~~~~~~~~~~~~~~~~
    P:/ws_USB_MSC__1st/src/main.c:88:36: note: in expansion of macro 'STORAGE_PARTITION_ID'
    88 | mnt->storage_dev = (void *)STORAGE_PARTITION_ID;
    | ^~~~~~~~~~~~~~~~~~~~
    [40/193] Building C object zephyr/CMakeFiles/zephyr.dir/subsys/logging/log_core.c.obj
    ninja: build stopped: subcommand failed.

    My code.

            based on nrf connect sdk 3.0.1 sample code. 
            \ncs\v3.0.1\zephyr\samples\subsys\usb\mass

    ws_USB_MSC__1st__03__sysbuild_off__OK__KEEP__.zip

    Regards, 
    Kenny

Reply Children
No Data
Related