SD Card: Error mounting file System error: -134

Hello,

I am trying to use an sdcard with the nrf54l15 DK board with the 2.9.1 sdk. However I encounter "<err> fatfs: Storage init ERROR! error: -134" when calling the disk_access_init() function

My code described below is based on the fatfs example

#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/logging/log.h>
#include <zephyr/fs/fs.h>
#include <ff.h>
#include <zephyr/pm/device.h>
#include <zephyr/pm/device_runtime.h>
#include <zephyr/drivers/spi.h>
#include <zephyr/drivers/gpio.h>
#include "hardware/gpio.h"
#include "sdcard/sdcard.h"

#define DISK_DRIVE_NAME "SD"
#define DISK_MOUNT_PT "/SD:"
#define FS_RET_OK FR_OK

LOG_MODULE_REGISTER(main);

static const char *disk_mount_pt = DISK_MOUNT_PT;

static FATFS fat_fs;
static struct fs_mount_t mp = {
	.type = FS_FATFS,
	.fs_data = &fat_fs,
};

struct gpio_dt_spec sd_gpio = GPIO_DT_SPEC_GET(SD_ENABLE_NODE, gpios);

int main(void)
{
	LOG_INF("Starting program");
	set_power_on_sd(&sd_gpio, 1);
	int ret_pinConfig = gpio_pin_configure_dt(&sd_gpio, GPIO_OUTPUT_INACTIVE);
	k_msleep(250);
	LOG_INF("Pin Config status Code %d",ret_pinConfig);
	
	sdcard_disc_init();
	mp.mnt_point = disk_mount_pt;

	int res = fs_mount(&mp);


	if (res == FS_RET_OK) {
		LOG_INF("Disk mounted.\n");
		/* Try to unmount and remount the disk */
		res = fs_unmount(&mp);
		if (res != FS_RET_OK) {
			LOG_INF("Error unmounting disk\n");
			return res;
		}
		res = fs_mount(&mp);
		if (res != FS_RET_OK) {
			LOG_INF("Error remounting disk\n");
			return res;
		}

		if (lsdir(disk_mount_pt) == 0) {
			if (create_some_entries(disk_mount_pt)) {
				lsdir(disk_mount_pt);
			}
		}
	} else {
		LOG_INF("Error mounting disk.\n");
	}

	fs_unmount(&mp);
	LOG_INF("Exiting program. \n");
	return 0;
}

The associated function for the sdcard_disc_init(void)

int sdcard_disc_init(void) 
{
	/* raw disk i/o */
	static const char* disk_pdrv = "SD";
	uint64_t memory_size_mb;
	uint32_t block_count;
	uint32_t block_size;

	// Re initialize the SD Card
	int status = disk_access_status(disk_pdrv);
	LOG_INF("Disk Status: %d", status);
	int res = FR_OK;

	if (status == 1){
		res = disk_access_init(disk_pdrv);
		LOG_INF("DISK Acces init code %d",res);

	}
	if (res == FR_OK) {	
		res = disk_access_ioctl(disk_pdrv, DISK_IOCTL_GET_SECTOR_COUNT, &block_count);
		if (res == FR_OK) {
			LOG_INF("Block count %u", block_count);
			res = disk_access_ioctl(disk_pdrv, DISK_IOCTL_GET_SECTOR_SIZE, &block_size);
			if (res == FR_OK) {
				LOG_INF("Sector size %u", block_size);
				memory_size_mb = (uint64_t)block_count*  block_size;
				LOG_INF("Memory Size(MB) %u\n", (uint32_t)(memory_size_mb >> 20));
			} else {
				LOG_ERR("Unable to get sector size. error: %d", res);
			}
		} else {
			LOG_ERR("Unable to get sector count. error: %d", res);
		}
	} else {
		LOG_ERR("Storage init ERROR! error: %d", res);
	}
	return res;
}

Here is the prj.conf

CONFIG_LOG=y
CONFIG_PRINTK=y
CONFIG_GPIO=y

#Sd logs
CONFIG_SDHC_LOG_LEVEL_DBG=y
CONFIG_SD_LOG_LEVEL_DBG=n

CONFIG_SPI=y

#sdcard
#CONFIG_DISK_DRIVER_SDMMC=y
CONFIG_DISK_ACCESS=y
CONFIG_FILE_SYSTEM=y
CONFIG_FAT_FILESYSTEM_ELM=y
CONFIG_MAIN_STACK_SIZE=8192
CONFIG_SDHC=y

And the overlay used to configure the SPI node

&pinctrl {
    spi20_default: spi20_default {
        group1 {
            psels = <
            NRF_PSEL(SPIM_SCK,  1, 4)
            NRF_PSEL(SPIM_MOSI, 1, 3)
            NRF_PSEL(SPIM_MISO, 1, 5)
            >;
        };
    };

    spi20_sleep: spi20_sleep {
        group1 {
            psels = <
            NRF_PSEL(SPIM_SCK,  1, 4)
            NRF_PSEL(SPIM_MOSI, 1, 3)
            NRF_PSEL(SPIM_MISO, 1, 5)
            >;
            low-power-enable;
        };
    };
};
/ {
    sdcard_gpio{
        compatible = "gpio-keys";
        sm: sd_mic_enable_0 {
            gpios = <&gpio1 2 GPIO_ACTIVE_LOW>;
            label = "SD Card Switch";
        };
    };

    aliases {
        sm01 = &sm;
    };
};

&spi20 {
    status = "okay";
    compatible = "nordic,nrf-spim";
    pinctrl-0 = <&spi20_default>;
    pinctrl-1 = <&spi20_sleep>;
    pinctrl-names = "default", "sleep";

    cs-gpios = <&gpio1 6 GPIO_ACTIVE_LOW>; // P1.06 - SD_nCS
    sdhc0: sdhc@0 {
        compatible = "zephyr,sdhc-spi-slot";
        reg = <0>;
        status = "okay";
        mmc {
            compatible = "zephyr,sdmmc-disk";
            status = "okay";
        };
        spi-max-frequency = <DT_FREQ_M(25)>;
    };

};

&gpiote20 {
    status = "okay";
};

// Disable NFC to use NFC pins as GPIOs
&nfct {
    status = "disabled";
};
&uicr {
    nfct-pins-as-gpios;
    status = "disabled";
};
// Disable UART to use UART pins as GPIOs
&uart20 {
    status = "disabled";
};
// Redirect logs (printk) to UART 30
&uart30 {
    status = "okay";
    current-speed = <115200>;
    pinctrl-0 = <&uart30_default>;
    pinctrl-1 = <&uart30_sleep>;
    pinctrl-names = "default", "sleep";
};
&{/chosen} {
    zephyr,console = &uart30;
    zephyr,shell-uart = &uart30;
    zephyr,uart-mcumgr = &uart30;
};

And When activating the SD logs these are the logs generated

*** Booting nRF Connect SDK v2.9.1-60d0d6c8d42d ***
*** Using Zephyr OS v3.7.99-ca954a6216c9 ***
[00:00:00.429,620] <inf> main: Starting program
[00:00:00.429,626] <inf> hardware: Power on mic and SD card is set !
[00:00:00.429,634] <inf> fatfs: Disk Status: 1
[00:00:00.433,221] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd0 arg 0x0
[00:00:00.454,282] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd8 arg 0x1aa
[00:00:00.455,001] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd0 arg 0x0
[00:00:00.455,716] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd8 arg 0x1aa
[00:00:00.476,960] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd0 arg 0x0
[00:00:00.477,688] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd8 arg 0x1aa
[00:00:00.478,404] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd0 arg 0x0
[00:00:00.499,401] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd8 arg 0x1aa
[00:00:00.500,130] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd0 arg 0x0
[00:00:00.500,844] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd8 arg 0x1aa
[00:00:00.522,123] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd0 arg 0x0
[00:00:00.522,854] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd8 arg 0x1aa
[00:00:00.523,573] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd0 arg 0x0
[00:00:00.544,587] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd8 arg 0x1aa
[00:00:00.545,306] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd0 arg 0x0
[00:00:00.546,023] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd8 arg 0x1aa
[00:00:00.567,294] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd0 arg 0x0
[00:00:00.568,011] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd8 arg 0x1aa
[00:00:00.568,730] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd0 arg 0x0
[00:00:00.589,739] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd8 arg 0x1aa
[00:00:00.590,461] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd0 arg 0x0
[00:00:00.591,178] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd8 arg 0x1aa
[00:00:00.612,440] <inf> sd: Card does not support CMD8, assuming legacy card
[00:00:00.612,457] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd0 arg 0x0
[00:00:00.613,173] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd58 arg 0x0
[00:00:00.613,988] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd55 arg 0x0
[00:00:00.635,017] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd41 arg 0x0
[00:00:00.635,733] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd58 arg 0x0
[00:00:00.636,444] <inf> fatfs: DISK Acces init code -134
[00:00:00.636,450] <err> fatfs: Storage init ERROR! error: -134
[00:00:00.640,102] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd0 arg 0x0
[00:00:00.671,241] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd8 arg 0x1aa
[00:00:00.671,958] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd0 arg 0x0
[00:00:00.672,675] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd8 arg 0x1aa
[00:00:00.693,923] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd0 arg 0x0
[00:00:00.694,636] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd8 arg 0x1aa
[00:00:00.695,352] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd0 arg 0x0
[00:00:00.716,393] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd8 arg 0x1aa
[00:00:00.717,112] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd0 arg 0x0
[00:00:00.717,827] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd8 arg 0x1aa
[00:00:00.739,104] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd0 arg 0x0
[00:00:00.739,819] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd8 arg 0x1aa
[00:00:00.740,533] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd0 arg 0x0
[00:00:00.761,545] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd8 arg 0x1aa
[00:00:00.762,260] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd0 arg 0x0
[00:00:00.762,977] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd8 arg 0x1aa
[00:00:00.784,227] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd0 arg 0x0
[00:00:00.784,942] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd8 arg 0x1aa
[00:00:00.785,660] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd0 arg 0x0
[00:00:00.806,698] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd8 arg 0x1aa
[00:00:00.807,412] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd0 arg 0x0
[00:00:00.808,126] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd8 arg 0x1aa
[00:00:00.829,370] <inf> sd: Card does not support CMD8, assuming legacy card
[00:00:00.829,387] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd0 arg 0x0
[00:00:00.830,104] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd58 arg 0x0
[00:00:00.830,921] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd55 arg 0x0
[00:00:00.851,978] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd41 arg 0x0
[00:00:00.852,692] <dbg> sdhc_spi: sdhc_spi_send_cmd: cmd58 arg 0x0
[00:00:00.853,403] <err> fs: fs mount error (-5)
[00:00:00.853,411] <inf> main: Error mounting disk.

[00:00:00.853,423] <err> fs: fs not mounted (mp == 0x20000008)
[00:00:00.853,429] <inf> main: Exiting program. 

Your help is kindly appreciated,

thanks in advance for your help.

NBH

Parents
  • Hello,

    Before I try to reproduce this on my desk, please try increasing the IO voltage to 3.3v if you haven't done so already. The default voltage is 1.8v and may not be supported by your SD card. The IO voltage is adjusted by changing the VDD in the board configurator app in nRF Connect for Desktop:

    Best regards,

    Vidar

  • Hello thank you for your answer, as you predicted the default volatage was indeed set 1.8V.

    However i still encounter the same issue after setting the voltage to 3.3V as described in the logs of the original post.

    Thanks

    Nabil

  • Hi Vidar,

    I'm Patrice, working at the School of Engineering of Sion, and I'm trying to support Nabil in his work dealing witn nrf54L15 and SD card...

    I took the fs_sample project you provided and ran it on the nrf54L15 development board I have in the office. It's a version 0.9.2

    I've checked that the nrf54l15's GPIOs are set to 3.3V. I'm having the same problems as with the hardware used by Nabil (see RTT output 54l15).
    I also tested your .hex file and got the same behavior!

    I then compiled the project for an nrf5340 board and everything works (cf. RTT output 5340).

    For the 2 builds, I'm using the same toolchains, same external hardware and the same SD card:
    - ncs 3.0.0
    - ncs toolchain 3.0.1

    Any ideas ?


    Here is the project with the overlay and conf files:

    fs_sample_54l15_and_5340.zip

  • Hi,

    Could you please try with the .hex I uploaded earlier and with this pinout:

    Best regards,

    Vidar

  • Hi Vidar,

    I already did, but here is the RTT output with the .hex and pinout provided:

  • Hi,

    I was hoping testing with my FW would help narrow down the problem. The error indicates that the SD card is not responding to the commands.

    So to summarize:

    1. The same SD card works with the nRF5340 DK which confirms that the card is compatible with the driver.

    2. Both setups are operating at the same IO voltage level.

    3. The identical firmware works on my desk.

    From the board picture you posted it looks like you have changed which pins are connected to the SD card module compared to the overlay Nabil included in the initial post? Have you tried to probe the lines with a scope or logic analyzer?

  • Hi Vidar,

    It seems that the pins are well configured, according to the .overlay.

    • P1.04 : SD_SCK
    • P1.05 : SD_MISO
    • P1.07 : SD_MOSI
    • P1.06 : SD_nCS

    &spi20 {
        status = "okay";
        compatible = "nordic,nrf-spim";
        pinctrl-0 = <&spi20_default>;
        pinctrl-1 = <&spi20_sleep>;
        pinctrl-names = "default", "sleep";
        cs-gpios = <&gpio1 6 GPIO_ACTIVE_LOW>; // P1.06 - SD_nCS
    	sdhc0: sdhc@0 {
    		compatible = "zephyr,sdhc-spi-slot";
    		reg = <0>;
    		status = "okay";
    		mmc {
    			compatible = "zephyr,sdmmc-disk";
    			disk-name = "SD";
    			status = "okay";
    		};
    		spi-max-frequency = <24000000>;
    	};
    };
    
    &uart20 {
    	status = "disabled";
    };
    
    &pinctrl {
        spi20_default: spi20_default {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK,  1, 4)>,
                        <NRF_PSEL(SPIM_MOSI, 1, 7)>,
                        <NRF_PSEL(SPIM_MISO, 1, 5)>;
            };
        };
    
        spi20_sleep: spi20_sleep {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK,  1, 4)>,
                        <NRF_PSEL(SPIM_MOSI, 1, 7)>,
                        <NRF_PSEL(SPIM_MISO, 1, 5)>;
                low-power-enable;
            };
        };
    };

    With the logic analyzer :

    • nrf54L15

    • nrf5340

    The GPIOs seem to be correctly assigned. However, the SPI frames are not the same.

    • Is there anything special to do with the nRF54L15 in terms of hardware?
    • Or a special configuration to put in the prj.conf?

    Kind Regards
    Patrice

Reply
  • Hi Vidar,

    It seems that the pins are well configured, according to the .overlay.

    • P1.04 : SD_SCK
    • P1.05 : SD_MISO
    • P1.07 : SD_MOSI
    • P1.06 : SD_nCS

    &spi20 {
        status = "okay";
        compatible = "nordic,nrf-spim";
        pinctrl-0 = <&spi20_default>;
        pinctrl-1 = <&spi20_sleep>;
        pinctrl-names = "default", "sleep";
        cs-gpios = <&gpio1 6 GPIO_ACTIVE_LOW>; // P1.06 - SD_nCS
    	sdhc0: sdhc@0 {
    		compatible = "zephyr,sdhc-spi-slot";
    		reg = <0>;
    		status = "okay";
    		mmc {
    			compatible = "zephyr,sdmmc-disk";
    			disk-name = "SD";
    			status = "okay";
    		};
    		spi-max-frequency = <24000000>;
    	};
    };
    
    &uart20 {
    	status = "disabled";
    };
    
    &pinctrl {
        spi20_default: spi20_default {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK,  1, 4)>,
                        <NRF_PSEL(SPIM_MOSI, 1, 7)>,
                        <NRF_PSEL(SPIM_MISO, 1, 5)>;
            };
        };
    
        spi20_sleep: spi20_sleep {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK,  1, 4)>,
                        <NRF_PSEL(SPIM_MOSI, 1, 7)>,
                        <NRF_PSEL(SPIM_MISO, 1, 5)>;
                low-power-enable;
            };
        };
    };

    With the logic analyzer :

    • nrf54L15

    • nrf5340

    The GPIOs seem to be correctly assigned. However, the SPI frames are not the same.

    • Is there anything special to do with the nRF54L15 in terms of hardware?
    • Or a special configuration to put in the prj.conf?

    Kind Regards
    Patrice

Children
No Data
Related