USB MSC example with SD Card fails during initialization

Hello, and thanks for reading.

I am trying to get your example for USB mass storage class working with my NRF52840 dongle and an SD card. I have wired the SD card to the dongle and want to use SPI to communicate with it, with the goal of having it show up to my computer as a 32Gb usb drive. This will then be part of a larger project.

I get the following error message when I try to run the example:

[00:00:00.425,964] <err> sd: Failed to query card OCR
[00:00:00.425,964] <err> usb_msc: Storage init ERROR !!!! - Aborting USB init

This is especially odd, because a few moments later I get:

[00:00:03.475,097] <inf> main: Block count 62357504
Sector size 512
Memory Size(MB) 30448
Disk mounted.

Listing dir /SD: ...
[DIR ] SYSTEM~1

This information is correct, so clearly I have the correct settings and overlay for the SD card and it is mounting correctly.

I have zipped and attached the entire project, and would be much obliged if you could take a look and try to see why its not working. To the best of my knowledge it's your example as it should be, with the only additions being related to routing the debug to usb.

Thank you!

MSC_Testing.zip

  • Hi,

    Which version of nRF Connect SDK are you using to build this?

    How is the SD card connected to the dongle? It looks like one of the default pins for spi1 node for nrf52840dongle_nrf52840 target (P0.30) is not mapped out to any pin on the dongle. I could not see any pin changes in your overlay file, but the compiled dts file (build/zephyr/zephyr.dts) suggests you have changed this somewhere. Have you modified the board files in Zephyr directly?

    Best regards,
    Jørgen

  • Hello and thanks for answering.

    Firstly, please accept my apologies, I accidentally uploaded the wrong zip file. Please find attached the correct file.

    3426.MSC_Testing.zip

    I have indeed made the changes for the pins for SPI directly; Please see the image below from the Devicetree GUI tool:

    EDIT: As an experiment, I tried commenting out

    //  / {
    //      msc_disk0 {
    //          status="okay";
    //          compatible = "zephyr,flash-disk";
    //          partition = <&storage_partition>;
    //          disk-name = "SD";
    //          /* cache-size == page erase size */
    //          cache-size = <4096>;
    //      };
    //  };

    And got a slightly different error message:

    *** Booting nRF Connect SDK v2.5.0 ***
    [00:00:00.634,338] <err> usb_msc: Storage init ERROR !!!! - Aborting USB init
    [00:00:03.482,604] <inf> sd: Maximum SD clock is under 25MHz, using clock of 400000Hz
    Mount /SD:: 0
    /SD:: bsize = 512 ; frsize = 32768 ; blocks = 973952 ; bfree = 973948
    /SD: opendir: 0
      D 0 SYSTEM~1
    End of files
    [00:00:13.608,551] <err> main: Failed to enable USB -120

  • Sorry to bump you, im sure you're busy, but Id really appreciate some help. Thanks!

  • Have you tried scoping the pins between the dongle and the SD card? Do they toggle as expected?

    Have you tried building the unmodified sample following the instructions in the documentation? I tried to build this and connected the SD card to the same pins used for the shield (spi3 default pins on nRF52840 DK):

    west build -b nrf52840dk_nrf52840 samples/subsys/usb/mass -- -DSHIELD=waveshare_epaper_gdeh0154a07 -DCONFIG_APP_MSC_STORAGE_SDCARD=y

    spi3_default: spi3_default {
    	group1 {
    		psels = <NRF_PSEL(SPIM_SCK, 1, 15)>,
    			<NRF_PSEL(SPIM_MISO, 1, 14)>,
    			<NRF_PSEL(SPIM_MOSI, 1, 13)>;
    	};
    };

    I could not get the CS pin working correctly, but if I connect the CS pin directly to GND on the DK, the sample seems to be working correctly.

    Can you also print the error code that are reported in disk_access_init() in your build? E.g:

    int disk_access_init(const char *pdrv)
    {
    	struct disk_info *disk = disk_access_get_di(pdrv);
    	int rc = -EINVAL;
    
    	if ((disk != NULL) && (disk->ops != NULL) &&
    				(disk->ops->init != NULL)) {
    		rc = disk->ops->init(disk);
    	}
        printk("disk_access_init: %d\n", rc);
    
    	return rc;
    }

    Best regards,
    Jørgen

  • Hello, and thank you for your reply.

    I have played around a bit with my code, please find the latest attached here.

    Here is the output from the console, including the new error message:

    USB Debug ready
    *** Booting nRF Connect SDK v2.5.0 ***
    [00:00:02.419,128] <err> sd: Card never left busy state
    [00:00:02.419,158] <err> sd: Failed to query card OCR
    [00:00:02.419,158] <err> usb_msc: Storage init ERROR !!!! - Aborting USB init
    [00:00:03.866,699] <inf> sd: Maximum SD clock is under 25MHz, using clock of 400000Hz
    Mount /SD:: 0
    /SD:: bsize = 512 ; frsize = 32768 ; blocks = 973952 ; bfree = 973948
    /SD: opendir: 0
      D 0 SYSTEM~1
    End of files

    I seems odd to me that there might be a hardware or low-level problem with the SD card, given that the code correctly identifies the SD card size and free space.

    If it somehow helps you, please recall that I am using the NRF52840 Dongle, and am also using the USB for console debugging.

    To answer your questions:

    1) I have indeed put my logic analyzer on the SD card lines, everything looks good, all the traces are moving up and down. Here is an image of the capture, from top to bottom the traces are clock, CS, MOSI, MISO.

    2) I tried the example with the internal ram when I was first starting out, and that appeared to work. I have not tried that recently though, I will retry it and report back.

    3) The error code is -120. This means "Socket already connected", but I dont fully understand this error; does it mean something else is monopolizing the USB drivers? I cant seem to find the function "disk_access_init"...

    Thank you for your time and your help!

    MSC_SDCARD_Testing.zip

    EDIT:

    As a further experiment, I tried calling setup_disk() before starting the USB debug console, and now Ive got a slightly different error message:

    USB Debug ready
    *** Booting nRF Connect SDK v2.5.0 ***
    [00:00:00.431,030] <err> sd: Failed to query card OCR
    [00:00:00.431,030] <err> usb_msc: Storage init ERROR !!!! - Aborting USB init
    [00:00:00.529,388] <err> sd: Failed to query card OCR
    [00:00:00.529,388] <err> fs: fs mount error (-5)
    [00:00:00.529,418] <err> main: Failed to mount filesystem
    [00:00:03.130,859] <err> main: Failed to enable USB -120

    Notice how in this case the SD Card has not mounted properly either. Im not sure if this helps you in some way.

Related