USB MASS sample and partition manager build issues

I have my application code which builds and runs on my nrf5340DK. The project files were based on the zephyr sample for multi-advertising BLE.

Right now I'm building the 'secure' app version (board target nrf5340dk_nrf5340_cpuapp)

I now want to add a file system, in the external flash, and enable USB access to it (objective is to have a way to give files to the application firmware over USB)

I took the code & dts/Kconfig from the USB 'mass' zephyr sample to use as a base for this, however the project will not compile, failing at flashdisk.c in the zephyr installation:

[11/142] Building C object zephyr/drivers/disk/CMakeFiles/drivers__disk.dir/flashdisk.c.obj
FAILED: zephyr/drivers/disk/CMakeFiles/drivers__disk.dir/flashdisk.c.obj
C:\ncs\toolchains\cf2149caf2\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe -DKERNEL -DNRF5340_XXAA_APPLICATION -DNRF_SKIP_FICR_NS_COPY_TO_RAM -DPICOLIBC_LONG_LONG_PRINTF_SCANF -DUSE_PARTITION_MANAGER=1 -D_FORTIFY_SOURCE=1 -D_POSIX_C_SOURCE=200809 -D__LINUX_ERRNO_EXTENSIONS__ -D__PROGRAM_START -D__ZEPHYR_SUPERVISOR__ -D__ZEPHYR__=1 -IC:/work/dev/nordic_connect/zephyr/include -IC:/work/dev/if-device-nrf53/cc1-med/build/zephyr/include/generated -IC:/work/dev/nordic_connect/zephyr/soc/arm/nordic_nrf/nrf53 -IC:/work/dev/nordic_connect/zephyr/soc/common/nordic_nrf/. -IC:/work/dev/nordic_connect/zephyr/soc/arm/nordic_nrf/common/. -IC:/work/dev/nordic_connect/zephyr/subsys/usb/device -IC:/work/dev/nordic_connect/zephyr/subsys/bluetooth -IC:/work/dev/nordic_connect/zephyr/drivers/usb/common/nrf_usbd_common/. -IC:/work/dev/nordic_connect/nrf/include -IC:/work/dev/nordic_connect/nrf/subsys/app_event_manager/. -IC:/work/dev/nordic_connect/nrf/subsys/app_event_manager_profiler_tracer/. -IC:/work/dev/nordic_connect/nrf/tests/include -IC:/work/dev/nordic_connect/modules/lib/cjson -IC:/work/dev/nordic_connect/nrf/modules/cjson/include -IC:/work/dev/nordic_connect/modules/hal/cmsis/CMSIS/Core/Include -IC:/work/dev/nordic_connect/zephyr/modules/cmsis/. -IC:/work/dev/nordic_connect/modules/hal/nordic/nrfx -IC:/work/dev/nordic_connect/modules/hal/nordic/nrfx/drivers/include -IC:/work/dev/nordic_connect/modules/hal/nordic/nrfx/mdk -IC:/work/dev/nordic_connect/zephyr/modules/hal_nordic/nrfx/. -IC:/work/dev/if-device-nrf53/cc1-med/build/modules/libmetal/libmetal/lib/include -IC:/work/dev/nordic_connect/modules/lib/open-amp/open-amp/lib/include -IC:/work/dev/nordic_connect/modules/crypto/tinycrypt/lib/include -IC:/work/dev/nordic_connect/nrfxlib/softdevice_controller/include -isystem C:/work/dev/nordic_connect/zephyr/lib/libc/common/include -isystem C:/work/dev/nordic_connect/nrfxlib/crypto/nrf_cc312_platform/include -Wshadow -fno-strict-aliasing -Os -imacros C:/work/dev/if-device-nrf53/cc1-med/build/zephyr/include/generated/autoconf.h -fno-printf-return-value -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m33 -mthumb -mabi=aapcs -mfp16-format=ieee -mtp=soft --sysroot=C:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi -imacros C:/work/dev/nordic_connect/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -ftls-model=local-exec -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=C:/work/dev/if-device-nrf53/cc1-med=CMAKE_SOURCE_DIR -fmacro-prefix-map=C:/work/dev/nordic_connect/zephyr=ZEPHYR_BASE -fmacro-prefix-map=C:/work/dev/nordic_connect=WEST_TOPDIR -ffunction-sections -fdata-sections --specs=picolibc.specs -std=c99 -MD -MT zephyr/drivers/disk/CMakeFiles/drivers__disk.dir/flashdisk.c.obj -MF zephyr\drivers\disk\CMakeFiles\drivers__disk.dir\flashdisk.c.obj.d -o zephyr/drivers/disk/CMakeFiles/drivers__disk.dir/flashdisk.c.obj -c C:/work/dev/nordic_connect/zephyr/drivers/disk/flashdisk.c
C:/work/dev/nordic_connect/zephyr/drivers/disk/flashdisk.c:484:1: error: return type defaults to 'int' [-Werror=implicit-int]
484 | PM_FOREACH_AFFILIATED_TO_disk(DEFINE_FLASHDISKS_CACHE)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/work/dev/nordic_connect/zephyr/drivers/disk/flashdisk.c: In function 'PM_FOREACH_AFFILIATED_TO_disk':
C:/work/dev/nordic_connect/zephyr/drivers/disk/flashdisk.c:523:30: error: storage class specified for parameter 'flash_disks'
523 | static struct flashdisk_data flash_disks[] = {
| ^~~~~~~~~~~
C:/work/dev/nordic_connect/zephyr/drivers/disk/flashdisk.c:523:15: error: parameter 'flash_disks' is initialized
523 | static struct flashdisk_data flash_disks[] = {
| ^~~~~~~~~~~~~~
C:/work/dev/nordic_connect/zephyr/drivers/disk/flashdisk.c:524:39: error: 'DEFINE_FLASHDISKS_DEVICE' undeclared (first use in this function)
524 | PM_FOREACH_AFFILIATED_TO_disk(DEFINE_FLASHDISKS_DEVICE)
| ^~~~~~~~~~~~~~~~~~~~~~~~

etc etc as ever when one of these macros has an issue its very tricky to work out why....

Looking at the flashdisk.c code it seems to be in the USE_PARTITION_MANAGER case, so I guess its not finding some PM config to define the flash disk parameters?

Q: do I need to use the Partition Manager sub system? The DTS files appear to define the partitions required just fine...The mass example does not have a pm.yml either?

If I have to use PM (my reading implies 'yes', because the nrf5340 requires a multi-image hex due to the 2 processors?), where, how to configure its partitions if not in the DTS?

I tried to build the 'mass' sample standalone copied directly from the NCS; but it also fails to compile with this error:

CMake Error at CMakeLists.txt:10 (message):
No disk access settings detected.

Any ideas what I'm doing wrong?

Thanks

Brian

full compile output for 'mass' sample:

C:\work\dev\if-device-nrf53\mass>west build -p
-- west build: generating a build system
Loading Zephyr default modules (Zephyr base).
-- Application: C:/work/dev/if-device-nrf53/mass
-- CMake version: 3.21.0
-- Using NCS Toolchain 2.6.20240304.889616714482 for building. (C:/ncs/toolchains/cf2149caf2/cmake)
-- Found Python3: C:/ncs/toolchains/cf2149caf2/opt/bin/python.exe (found suitable version "3.9.13", minimum required is "3.8") found components: Interpreter
-- Cache files will be written to: C:/work/dev/nordic_connect/zephyr/.cache
-- Zephyr version: 3.5.99 (C:/work/dev/nordic_connect/zephyr)
-- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
-- Board: nrf5340dk_nrf5340_cpuapp
-- Found host-tools: zephyr 0.16.5 (C:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk)
-- Found toolchain: zephyr 0.16.5 (C:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk)
-- Found Dtc: C:/ncs/toolchains/cf2149caf2/opt/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6")
-- Found BOARD.dts: C:/work/dev/nordic_connect/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp.dts
-- Found devicetree overlay: C:/work/dev/if-device-nrf53/mass/boards/nrf5340dk_nrf5340_cpuapp.overlay
-- Generated zephyr.dts: C:/work/dev/if-device-nrf53/mass/build/zephyr/zephyr.dts
-- Generated devicetree_generated.h: C:/work/dev/if-device-nrf53/mass/build/zephyr/include/generated/devicetree_generated.h
-- Including generated dts.cmake file: C:/work/dev/if-device-nrf53/mass/build/zephyr/dts.cmake
Parsing C:/work/dev/if-device-nrf53/mass/Kconfig
Loaded configuration 'C:/work/dev/nordic_connect/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp_defconfig'
Merged configuration 'C:/work/dev/if-device-nrf53/mass/prj.conf'
Configuration saved to 'C:/work/dev/if-device-nrf53/mass/build/zephyr/.config'
Kconfig header saved to 'C:/work/dev/if-device-nrf53/mass/build/zephyr/include/generated/autoconf.h'
-- Found GnuLd: c:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe (found version "2.38")
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- The ASM compiler identification is GNU
-- Found assembler: C:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc.exe
CMake Warning at C:/work/dev/nordic_connect/zephyr/subsys/usb/device/CMakeLists.txt:22 (message):
CONFIG_USB_DEVICE_VID has default value 0x2FE3.

This value is only for testing and MUST be configured for USB products.


CMake Warning at C:/work/dev/nordic_connect/zephyr/CMakeLists.txt:862 (message):
No SOURCES given to Zephyr library: drivers__disk

Excluding target from build.


CMake Error at CMakeLists.txt:10 (message):
No disk access settings detected.


-- Configuring incomplete, errors occurred!
See also "C:/work/dev/if-device-nrf53/mass/build/CMakeFiles/CMakeOutput.log".
See also "C:/work/dev/if-device-nrf53/mass/build/CMakeFiles/CMakeError.log".
FATAL ERROR: command exited with status 1: 'C:\ncs\toolchains\cf2149caf2\opt\bin\cmake.EXE' -DWEST_PYTHON=C:/ncs/toolchains/cf2149caf2/opt/bin/python.exe '-BC:\work\dev\if-device-nrf53\mass\build' -GNinja -DBOARD=nrf5340dk_nrf5340_cpuapp '-SC:\work\dev\if-device-nrf53\mass'

  • Hi BrianW,

    Looking at the flashdisk.c code it seems to be in the USE_PARTITION_MANAGER case, so I guess its not finding some PM config to define the flash disk parameters?

    Q: do I need to use the Partition Manager sub system? The DTS files appear to define the partitions required just fine...The mass example does not have a pm.yml either?

    If I have to use PM (my reading implies 'yes', because the nrf5340 requires a multi-image hex due to the 2 processors?),

    Yes, you guessed right. You need to use the Partition Manager because you are building a multi-image application. This is the case up to nRF Connect SDK (NCS) v2.6.1.
    (From NCs v2.7.0, the build system changes quite a bit, and I honestly haven't caught up on that, so I refrain from commenting about v2.7.0 here.)

    If I understand correctly, you are using FAT FS, right? This issue happens mostly with FAT FS.

    where, how to configure its partitions if not in the DTS?

    The Partition Manager dynamically resolve all partition requirement during compile time. You can add a requirement for the FAT FS partition.

    The format of the file and how to use it are documented here: https://docs.nordicsemi.com/bundle/ncs-2.6.1/page/nrf/scripts/partition_manager/partition_manager.html

    I tested in the past with NCS v2.5.0, and this worked:

    app:
      address: 0x00000000
      end_address: 0x000f0000
      region: flash_primary
      size: 0x000f0000
    storage:
      address: 0x000f0000
      end_address: 0x00100000
      region: flash_primary
      size: 0x00010000
      
      affiliation: 
        - disk
      extra_params: {
        disk_name: "SD",
        disk_cache_size: 4096,
        disk_sector_size: 512,
        disk_read_only: 0
      }

    Alternatively, you could also provide a static configuration of the entire flash memory partitioning. The details are also included in the document page I linked above.

    A quick way to get a starting point with static configurations is to copy the result of a dynamic Partition Manager run. It is located at: $BUILD_DIR/partitions.yml.

    Hieu

  • Yes, you guessed right. You need to use the Partition Manager because you are building a multi-image application. This is the case up to nRF Connect SDK (NCS) v2.6.1.

    Ok. The partition manger doc (which I have read but haven't managed to map onto my project...) says:

    Note

    When you build a multi-image application using the Partition Manager, the devicetree source flash partitions are ignored.

    So why do the nrf5340 DTS board board files all include partition definitions in nrf5340_cpuapp_partition_conf.dtsi, and then in nrf5340_cpuapp_common.dtsi for &flash0? are these just ignored? the build/partitions.yml file doesn't seem to include them... 

    For the FAT-FS in external flash then:

    The PM doc includes a snippet for defining a fat-fs partition - where do I put the pm.yml file? The doc says it is ignored if its in the root application dir (which seems to be true!).

    here's what I put in it:

    fatfs_storage:
        region: external_flash
        affiliation: disk
        extra_params: {
            disk_name: "NAND",
            disk_cache_size: 4096,
            disk_sector_size: 512,
            disk_read_only: 0
        }
        placement:
            after: [start]
            align: {start: 4096}
        # 2Mb size, external flash is 8Mb total
        size: 0x200000
     
    But no fastfs_storage partition is in build/partitions.yml, and the compilation of flashdisk.c fails in the same way.
    since I put
    / {
       chosen {
            nordic,pm-ext-flash = &mx25r64;
        };
    }; 
    into my dts overlay, an "external-flash" region now appears in build/regions.yml, as well as a partition called 'external-flash' in build/partitions.yml, which uses all the region...
     
    I feel its not far away but just stuck with the PM...
  • I tried to build the 'mass' sample standalone copied directly from the NCS; but it also fails to compile with this error:

    CMake Error at CMakeLists.txt:10 (message):
    No disk access settings detected.

    Any ideas what I'm doing wrong?

    Ok, so this error is due to not giving the  -DCONFIG_APP_MSC_STORAGE_FLASH_FATFS=y option on the build line (which only works if you build from the parent directory as

    west build --build-dir mass/build mass --pristine=auto -DCONFIG_APP_MSC_STORAGE_FLASH_FATFS=y

    as otherwise the -D... is taken as the application name).

    And this builds ok as the PM is NOT enabled - if I force the PM with 

    CONFIG_PM_SINGLE_IMAGE=y
    then it fails to compile also....
     
  • The PM doc includes a snippet for defining a fat-fs partition - where do I put the pm.yml file? The doc says it is ignored if its in the root application dir (which seems to be true!).

    More reading tells me that in a multi-image application on a nrf5340, the 'app' is always the 'root' application. The image for the cpu-net (Bluetooth HCI RPMsg from the sample/...) is a 'child-image', witha "child_image" subfolder and a hci_rpmsg.conf file. 

    But since the app, which is the bit that needs the pm.yml, is the root, and the root's pm.yml is ignored, how to build a nrf5340 bluetooth application with any partition configuration????

    This all seems excessively complex.... and the documentation is a maze of twisty litle configuration options....

  • Hi,

    I understand that this is complex and there is quite a few configuration options to navigate through..

    A couple of thoughts here:

    1.  APP_MSC_STORAGE_FLASH_FATFS != APP_MSC_STORAGE_FLASH_LITTLEFS, while our pm.yml.file_system concerns littlefs
    2. Partition manager does not seem to have out of the box support for that specific FAT filesystem
    3. As you've stated you're already attempting, you'll have to use static partitioning

    Instead, lets take a step back and check something that should be verified support for: Could you try to test with APP_MSCC_STORAGE_FLASH_LITTLEFS instead? This 

    Kind regards,
    Andreas

Related