Slow USB MSC transfer speed on nRF5340 with SD card

In our design, we wired the SD card in SPI mode on SPI bus 4 wich a maximum SPI frequency of 50 MHz or 25 MHz as these are supported by the SD card. We used FAT32 file system, but later enabled support for exFAT and formated the SD card with exFAT. For internal logging from our device to the SD card, there is no issue. However, when we try to offload the data from SD card to a host machine, we are having an extremely slow transfer speed: When offloading a 10.5 MB binary file, it takes around 420 seconds, which effectively is only 90 KB/s. We have tried both 25 and 50 MHz SPI frequency but the result is very similar.

We are using USB legacy stack with NCS 3.0.2. I attached here our Kconfigs related to USB.

# Configure USB device
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="BORUS"
CONFIG_USB_DEVICE_PID=0x0001
CONFIG_USB_DEVICE_VID=0x0001
CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y
CONFIG_USB_DEVICE_LOG_LEVEL_ERR=y
CONFIG_SERIAL=n
CONFIG_USB_CDC_ACM=n
CONFIG_UART_INTERRUPT_DRIVEN=n
CONFIG_UART_LINE_CTRL=n
CONFIG_BOARD_SERIAL_BACKEND_CDC_ACM=n
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n

# Configure USB device to appear as DFU class
# Configure DFU autoupdate and reset
CONFIG_USB_DFU_CLASS=y
CONFIG_USB_REQUEST_BUFFER_SIZE=128
CONFIG_USB_DFU_ENABLE_UPLOAD=y
CONFIG_USB_DFU_PERMANENT_DOWNLOAD=y
CONFIG_USB_DFU_REBOOT=y
CONFIG_IMG_MANAGER=y
CONFIG_STREAM_FLASH=y
CONFIG_BOOTLOADER_MCUBOOT=y

# Configure file system 
CONFIG_FLASH_MAP=y
CONFIG_FLASH=y
CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_LITTLEFS=n
CONFIG_FAT_FILESYSTEM_ELM=y
CONFIG_FS_FATFS_LFN=y
CONFIG_FS_FATFS_EXFAT=y
CONFIG_FS_LOG_LEVEL_INF=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y
CONFIG_NORDIC_QSPI_NOR=y
CONFIG_NORDIC_QSPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096

# Configure mass storage
CONFIG_USB_MASS_STORAGE=y
CONFIG_DISK_ACCESS=y
CONFIG_USB_MASS_STORAGE_LOG_LEVEL_ERR=y
CONFIG_DISK_LOG_LEVEL_DBG=y
CONFIG_DISK_DRIVERS=y
CONFIG_DISK_DRIVER_SDMMC=y
CONFIG_DISK_DRIVER_FLASH=y
CONFIG_MASS_STORAGE_DISK_NAME="SD"

Parents
  • Hi,

    Which SD card do you use?

    Can you show your SPI related configuration?

    You can try to increase the value of CONFIG_SPI_NRFX_RAM_BUFFER_SIZE. What is the result?

    Best regards,
    Dejan

  • Hi,

    We are using the ZDSD32 (this one here). It is basically a SD card without being able to plug in or out. 

    Below is our current SPI configuration on the SPI4 bus in device tree

    &spi4 {
        compatible = "nordic,nrf-spim";
        status = "okay";
        pinctrl-0 = <&spi4_default>;
        pinctrl-1 = <&spi4_sleep>;
        pinctrl-names = "default", "sleep";
        cs-gpios = <&gpio0 11 GPIO_ACTIVE_LOW>;
    
        sdhc0: sdhc@0 {
            compatible = "zephyr,sdhc-spi-slot";
            reg = <0>;
            status = "okay";
            mmc {
                compatible = "zephyr,sdmmc-disk";
                status = "okay";
                disk-name = "SD"; 
            };
            spi-max-frequency = <50000000>;
        };
    };
    and the pin control 
    	spi4_default: spi4_default {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 8)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 9)>,
    				<NRF_PSEL(SPIM_MISO, 0, 10)>;
    			nordic,drive-mode = <NRF_DRIVE_H0H1>;
    		};
    	};
    
    	spi4_sleep: spi4_sleep {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 8)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 9)>,
    				<NRF_PSEL(SPIM_MISO, 0, 10)>;
    			low-power-enable;
    		};
    	};
     

    We will try to increase the buffer size as you recommended tmr to test the result.

    Best

    Shuhao

Reply
  • Hi,

    We are using the ZDSD32 (this one here). It is basically a SD card without being able to plug in or out. 

    Below is our current SPI configuration on the SPI4 bus in device tree

    &spi4 {
        compatible = "nordic,nrf-spim";
        status = "okay";
        pinctrl-0 = <&spi4_default>;
        pinctrl-1 = <&spi4_sleep>;
        pinctrl-names = "default", "sleep";
        cs-gpios = <&gpio0 11 GPIO_ACTIVE_LOW>;
    
        sdhc0: sdhc@0 {
            compatible = "zephyr,sdhc-spi-slot";
            reg = <0>;
            status = "okay";
            mmc {
                compatible = "zephyr,sdmmc-disk";
                status = "okay";
                disk-name = "SD"; 
            };
            spi-max-frequency = <50000000>;
        };
    };
    and the pin control 
    	spi4_default: spi4_default {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 8)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 9)>,
    				<NRF_PSEL(SPIM_MISO, 0, 10)>;
    			nordic,drive-mode = <NRF_DRIVE_H0H1>;
    		};
    	};
    
    	spi4_sleep: spi4_sleep {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 8)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 9)>,
    				<NRF_PSEL(SPIM_MISO, 0, 10)>;
    			low-power-enable;
    		};
    	};
     

    We will try to increase the buffer size as you recommended tmr to test the result.

    Best

    Shuhao

Children
No Data
Related