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

  • Hello Nabil,

    Thanks for confirming that you see the same with 3.3v. I have tried this on my desk now and confirmed that it works here. Please try with the hex file below and see that you get the same result as well. The difference is that I assigned MISO to P1.7 because P1.3 is not routed to the pin header by default (see Configuring NFC pins as GPIOs).

    Hex file

    fs_sample.hex

    Test project

    fs_sample.zip

    Pinout

    Best regards,

    Vidar

  • Hello Vidar,
    After inspecting the overlay file i noticed that the disk-name property inside the mmc node is not allowed, and generates a build error

    devicetree error: 'disk-name' appears in /soc/peripheral@50000000/spi@c6000/sdhc@0/mmc 
    in C:/****/fs_sample/build/fs_sample/zephyr/zephyr.dts.pre, 
    but is not declared in 'properties:' in C:/ncs/v2.9.1/zephyr/dts/bindings\sd\zephyr,sdmmc-disk.yaml


    Just to make it clear i'm building for the nrf54l15dk/nrf54l15/cpuapp using the 2.9.1 sdk.

    Also i forgot to mention in my original post that my board is reconfigured to use the NFC pins as GPIOs

    (And checked with an Analog discovery tool)

    Thanks

Reply
  • Hello Vidar,
    After inspecting the overlay file i noticed that the disk-name property inside the mmc node is not allowed, and generates a build error

    devicetree error: 'disk-name' appears in /soc/peripheral@50000000/spi@c6000/sdhc@0/mmc 
    in C:/****/fs_sample/build/fs_sample/zephyr/zephyr.dts.pre, 
    but is not declared in 'properties:' in C:/ncs/v2.9.1/zephyr/dts/bindings\sd\zephyr,sdmmc-disk.yaml


    Just to make it clear i'm building for the nrf54l15dk/nrf54l15/cpuapp using the 2.9.1 sdk.

    Also i forgot to mention in my original post that my board is reconfigured to use the NFC pins as GPIOs

    (And checked with an Analog discovery tool)

    Thanks

Children
Related