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

Hello,

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?

Thank

Marco

  • A small update.

    After some tries with both dk and custom board, with DK now the PC start the enumeration but in a terminal I can read a fault message and the board reset.

    *** Booting Zephyr OS build v3.1.99-ncs1-1
    Mount /SD:: 0
    /SD:: bsize = 512 ; frsize = 32768 ; blocks = 238304 ; bfree = 236871
    /SD: opendir: 0
      D 0 EXAMPLE
    End of files
    [00:00:02.259,338] <inf> sd: Detected SD card
    [00:00:02.278,381] <inf> sd: Maximum SD clock is under 25MHz, using clock of 2000000Hz
    [00:00:02.364,013] <inf> main: The device is put in USB mass storage mode.
    
    [00:00:03.770,263] <err> os: ***** USAGE FAULT *****
    [00:00:03.770,294] <err> os:   Stack overflow (context area not valid)
    [00:00:03.770,294] <err> os: r0/a1:  0xfbd35e65  r1/a2:  0x247882c0  r2/a3:  0x0000a2d0
    [00:00:03.770,294] <err> os: r3/a4:  0x61000000 r12/ip:  0x20000224 r14/lr:  0x00000009
    [00:00:03.770,324] <err> os:  xpsr:  0x00000000
    [00:00:03.770,324] <err> os: Faulting instruction address (r15/pc): 0x20000224
    [00:00:03.770,355] <err> os: >>> ZEPHYR FATAL ERROR 2: Stack overflow on CPU 0
    [00:00:03.770,355] <err> os: Current thread: 0x200009b0 (unknown)
    [00:00:03.828,186] <err> fatal_error: Resetting system

    It is the mass storage example and I don't touch anything! I just added the SPI configuration for the sd card.

    Best

    Marco

  • Hi Marco

    Could you try to build the sample again with the following debugging options set?

    CONFIG_DEBUG=y
    CONFIG_DEBUG_THREAD_INFO=y

    Then you should get a bit more info about where the issue happens. 

    Possibly you just need to increase the size of the main stack or the idle stack, which can be configured through the CONFIG_MAIN_STACK_SIZE or CONFIG_IDLE_STACK_SIZE parameters. 

    If you test it again with the debug options set can you share the log with me, and also the zephyr.map file from your build directory?

    The map file will show where the various stacks are located in memory, making it easier to identify the cause of the issue. 

    Best regards
    Torbjørn

  • Hi Torbjørn,

    I added the two options that you suggest me, but the log is the same.

    You can find the .map file in attach!

    Thanks

    Marco

    1033.zephyr.map

  • Hi Marco

    Most likely the issue is that your main stack is too small. 

    Could you try to increase the size of your main stack and see if the program will run without crashing? 

    For instance, try to set the stack size to 4096 or 8192 and see when it works (or not). 

    CONFIG_MAIN_STACK_SIZE=4096

    Best regards
    Torbjørn

  • Hi Torbjørn

    I have increased the main stack size and idle stack size to the following value:

    CONFIG_MAIN_STACK_SIZE=16384
    CONFIG_IDLE_STACK_SIZE=4096

    But the error is the same! nothing change!

    Best

    Marco

Related