nrf53 USB as mass storage with SDCARD enable ok but doesn't work


I am here, again! I am trying to use the USB of nfr5340dk or my custom board as mass storage with SDCard.

I am sure the SDCard works... in the same project I can read and write files without problems, but when I enable the usb, the USB_enable() function returns that there is not a problem, but from the PC I can't see the device, and no enumeration too.

The first question is: How does USB bind with SDCard? I saw that for internal flash, the overlay file contains these rows that I don't have:

/delete-node/ &storage_partition;

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

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

/ {
	msc_disk0 {
		compatible = "zephyr,flash-disk";
		partition = <&storage_partition>;
		disk-name = "NAND";
		cache-size = <4096>;

second question: The application must exit from the main to works like in this other post?



  • Hi Marco 

    Does the error happen only if the SD card is connected, or will it happen also without an SD card in place?

    If it happens without the SD card present would you be able to share the project with me so I can try to reproduce the issue here?

    Best regards

  • Hi Torbjørn,

    whitout the SD card present, there isn't the fault. The log is:

    *** Booting Zephyr OS build v3.1.99-ncs1-1  ***
    [00:00:02.481,658] [1B][1;31m<err> sd: Card error on CMD0[1B][0m
    [00:00:02.481,689] [1B][1;31m<err> usb_msc: Storage init ERROR !!!! - Aborting USB init[1B][0m
    [00:00:04.485,412] [1B][1;31m<err> sd: Card error on CMD0[1B][0m
    [00:00:04.485,443] [1B][1;31m<err> fs: fs mount error (-5)[1B][0m
    [00:00:04.485,473] [1B][1;31m<err> main: Failed to mount filesystem[1B][0m
    [00:00:04.485,595] [1B][0m<inf> main: The device is put in USB mass storage mode.

    Anyway, in attach you can find the project.


  • Hi Marco

    I found a similar sounding case where the issue was the size of the mass storage stack size rather than the main or idle stacks. 

    Could you try one more time, but change CONFIG_MASS_STORAGE_STACK_SIZE instead? 

    Try 4096 or 8129 and see if it fixes the issue. 

    If you still can't make it work I will hook up an SD card to a DK so I can do some testing on my side. 

    Best regards

  • Hi Torbjørn,

    I added into the prj.conf file the following line 


    But the compiler reply in this way:

    d:/Workspace/vsc_ncs_2.1.2/usb_mass_test/prj.conf:29: warning: attempt to assign the value ' 8192' to the undefined symbol MASS_STORAGE_STACK_SIZE 
    Parsing D:/Workspace/vsc_ncs_2.1.2/usb_mass_test/Kconfig
    Loaded configuration 'D:/SDK/ncs/v2.1.2/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp_defconfig'
    Merged configuration 'd:/Workspace/vsc_ncs_2.1.2/usb_mass_test/prj.conf'
    error: Aborting due to Kconfig warnings
    CMake Error at D:/SDK/ncs/v2.1.2/zephyr/cmake/modules/kconfig.cmake:293 (message):
      command failed with return code: 1
    Call Stack (most recent call first):
      D:/SDK/ncs/v2.1.2/zephyr/cmake/modules/zephyr_default.cmake:121 (include)
      D:/SDK/ncs/v2.1.2/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
      D:/SDK/ncs/v2.1.2/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate)
      CMakeLists.txt:4 (find_package)
    -- Configuring incomplete, errors occurred!
    FATAL ERROR: command exited with status 1: 'd:\SDK\ncs\toolchains\v2.1.2\opt\bin\cmake.EXE' '-DWEST_PYTHON=d:\SDK\ncs\toolchains\v2.1.2\opt\bin\python.exe' '-Bd:\Workspace\vsc_ncs_2.1.2\usb_mass_test\build' -GNinja -DBOARD=nrf5340dk_nrf5340_cpuapp -DNCS_TOOLCHAIN_VERSION:STRING=NONE '-DBOARD_ROOT:STRING=d:/Workspace/vsc_ncs_2.1.2/prova_adc;d:/Workspace/vsc_ncs_2.1.2/usb_mass_test' -DDTC_OVERLAY_FILE:STRING=d:/Workspace/vsc_ncs_2.1.2/usb_mass_test/boards/nrf5340dk_nrf5340_cpuapp.overlay -DCONF_FILE:STRING=d:/Workspace/vsc_ncs_2.1.2/usb_mass_test/prj.conf '-Sd:\Workspace\vsc_ncs_2.1.2\usb_mass_test'


    To avoid this, I changed the value into Kconfig.msc... now the project compile, the stack overflow is disappered, but the PC doesn't see the USB and the SDCard. 

    I tried to go back to the previous value of stack size, but now the stack overflow is no more present! I'm going crazy!



  • Hi  ,

    what do you think about this point: "To avoid this, I changed the value into Kconfig.msc... now the project compile, the stack overflow is disappered, but the PC doesn't see the USB and the SDCard."?

    I don't understand why I need to change the Kconfig.msg and not the prj.conf?