Communication with SD Card with nRF54L15DK

Hello,

I am trying to communicate with an SD Card with a NRF54L15DK but it doesn't work.
Here is my different files :

&spi21 {
    compatible = "nordic,nrf-spim";
    status = "okay";
    pinctrl-0 = <&spi21_default>;
    pinctrl-names = "default";
    cs-gpios = <&gpio2 5 GPIO_ACTIVE_LOW>;

    sdhc0: sdhc@0 {
        compatible = "zephyr,mmc-spi-slot";
        reg = <0>;
        status = "okay";
        label = "SDHC0";
        spi-max-frequency = <400000>; /* fréquence d'initialisation */
    };
};

&pinctrl {
    spi21_default: spi21_default {
        group1 {
            psels = <NRF_PSEL(SPIM_SCK, 2, 1)>,   /* P2.01 */
                    <NRF_PSEL(SPIM_MOSI, 2, 2)>,  /* P2.02 */
                    <NRF_PSEL(SPIM_MISO, 2, 4)>;  /* P2.04 */
        };
    };
};
# SPI et périphériques
CONFIG_SPI=y
CONFIG_DISK_ACCESS=y

# Système de fichiers
CONFIG_FILE_SYSTEM=y
CONFIG_FAT_FILESYSTEM_ELM=y
CONFIG_FS_FATFS_LFN=y          # (optionnel) support des noms longs
CONFIG_FS_LOG_LEVEL_DBG=y

# Logs et debug
CONFIG_LOG=y
CONFIG_LOG_DEFAULT_LEVEL=3
CONFIG_STDOUT_CONSOLE=y
CONFIG_PRINTK=y

# Stack principale un peu plus grande
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_SPI_NRFX_RAM_BUFFER_SIZE=8
CONFIG_GPIO=y

/*
 * Copyright (c) 2019 Tavish Naruka <[email protected]>
 *
 * SPDX-License-Identifier: Apache-2.0
 */

/* Sample which uses the filesystem API and SDHC driver */

#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/storage/disk_access.h>
#include <zephyr/fs/fs.h>
#include <ff.h>     /* Fournit FATFS, FIL, FRESULT, FR_OK, etc. */
#include <zephyr/logging/log.h>

LOG_MODULE_REGISTER(main);

static int lsdir(const char *path);

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

struct device *gpio0dev;

/*
*  Note the fatfs library is able to mount only strings inside _VOLUME_STRS
*  in ffconf.h
*/
static const char *disk_mount_pt = "/SD:";

void main(void)
{
gpio0dev = DEVICE_DT_GET(DT_NODELABEL(gpio0));
if (!device_is_ready(gpio0dev)) {
    printk("GPIO0 not ready!\n");
}

    /* raw disk i/o */
    do {
        static const char *disk_pdrv = "SD";
        uint64_t memory_size_mb;
        uint32_t block_count;
        uint32_t block_size;

        if (disk_access_init(disk_pdrv) != 0) {
            LOG_ERR("Storage init ERROR!");
            break;
        }

        if (disk_access_ioctl(disk_pdrv,
                DISK_IOCTL_GET_SECTOR_COUNT, &block_count)) {
            LOG_ERR("Unable to get sector count");
            break;
        }
        LOG_INF("Block count %u", block_count);

        if (disk_access_ioctl(disk_pdrv,
                DISK_IOCTL_GET_SECTOR_SIZE, &block_size)) {
            LOG_ERR("Unable to get sector size");
            break;
        }
        printk("Sector size %u\n", block_size);

        memory_size_mb = (uint64_t)block_count * block_size;
        printk("Memory Size(MB) %u\n", (uint32_t)(memory_size_mb >> 20));
    } while (0);

    mp.mnt_point = disk_mount_pt;

    int res = fs_mount(&mp);

    if (res == FR_OK) {
        printk("Disk mounted.\n");
        lsdir(disk_mount_pt);
    } else {
        printk("Error mounting disk.\n");
    }

    while (1) {
        k_sleep(K_MSEC(1000));
    }
}

static int lsdir(const char *path)
{
    int res;
    struct fs_dir_t dirp;
    static struct fs_dirent entry;

    fs_dir_t_init(&dirp);

    /* Verify fs_opendir() */
    res = fs_opendir(&dirp, path);
    if (res) {
        printk("Error opening dir %s [%d]\n", path, res);
        return res;
    }

    printk("\nListing dir %s ...\n", path);
    for (;;) {
        /* Verify fs_readdir() */
        res = fs_readdir(&dirp, &entry);

        /* entry.name[0] == 0 means end-of-dir */
        if (res || entry.name[0] == 0) {
            break;
        }

        if (entry.type == FS_DIR_ENTRY_DIR) {
            printk("[DIR ] %s\n", entry.name);
        } else {
            printk("[FILE] %s (size = %zu)\n",
                entry.name, entry.size);
        }
    }

    /* Verify fs_closedir() */
    fs_closedir(&dirp);

    return res;
}

and it retursn me always this error : [00:00:00.430,124] <dbg> fs: fs_register: fs register 0: 0
*** Booting nRF Connect SDK v2.9.2-4ab7b98fc76f ***
*** Using Zephyr OS v3.7.99-aa34a5632971 ***
[00:00:00.430,166] <err> main: Storage init ERROR!
[00:00:00.430,182] <err> fs: fs mount error (-5)
Error mounting disk

thank you in advance!
Parents Reply Children
  • Hello,

    What DK revision does the sticker on your board show? Does it say "1.0.0" like the log output? Reason for asking is that prior versions required soldering and cutting of solderbridges to do the same.

  • Thanks for confirming. Then it should have worked. I have not seen this error reported by this app before either. Please open the full log file and post it here so we can check if it provides any other clues.

  • Hello,
    I tried a new time this morning and it works one time but after it returns me the same error.

    Here is the log file : 

    2025-10-30T08:34:09.021Z DEBUG Rendering SidePanel
    2025-10-30T08:34:09.113Z INFO Initialising the bundled nrfutil device
    2025-10-30T08:34:09.152Z DEBUG Application data folder: C:\Users\jade.mouillot\AppData\Roaming\nrfconnect\pc-nrfconnect-board-configurator
    2025-10-30T08:34:09.340Z DEBUG Sending event "board-configurator: running nrfutil device"
    2025-10-30T08:34:09.391Z DEBUG App pc-nrfconnect-board-configurator v0.5.0 (official)
    2025-10-30T08:34:09.391Z DEBUG App path: C:\Users\jade.mouillot\.nrfconnect-apps\node_modules\pc-nrfconnect-board-configurator
    2025-10-30T08:34:09.392Z DEBUG nRFConnect 5.2.0, required by the app is (>=5.2.0)
    2025-10-30T08:34:09.392Z DEBUG nRFConnect path: C:\Users\jade.mouillot\AppData\Local\Programs\nrfconnect\resources\app.asar
    2025-10-30T08:34:09.392Z DEBUG HomeDir: C:\Users\jade.mouillot
    2025-10-30T08:34:09.392Z DEBUG TmpDir: C:\Users\JADE~1.MOU\AppData\Local\Temp
    2025-10-30T08:34:09.459Z DEBUG Showing BoardController pane
    2025-10-30T08:34:09.487Z DEBUG Sending event "board-configurator: running nrfutil device"
    2025-10-30T08:34:09.487Z DEBUG Sending event "board-configurator: running nrfutil device"
    2025-10-30T08:34:09.500Z DEBUG Sending event "board-configurator: running nrfutil device"
    2025-10-30T08:34:09.607Z INFO Using the bundled core version for nrfutil device: 8.1.1
    2025-10-30T08:34:09.711Z INFO Using nrfutil-device version: 2.12.3
    2025-10-30T08:34:09.711Z INFO Using nrf-device-lib version: 0.17.81
    2025-10-30T08:34:09.712Z INFO Using nrf-probe version: 0.40.1
    2025-10-30T08:34:09.712Z INFO Using JLink version: JLink_V8.18
    2025-10-30T08:34:17.706Z INFO Getting serial port options from the persistent store for 001057762330.pc-nrfconnect-board-configurator
    2025-10-30T08:34:17.708Z INFO Device connected with the serial number 001057762330
    2025-10-30T08:34:17.710Z DEBUG Sending event "board-configurator: device connected"
    2025-10-30T08:34:20.278Z INFO Selecting device with the serial number 001057762330
    2025-10-30T08:34:20.280Z DEBUG Rendering SidePanel
    2025-10-30T08:34:20.281Z DEBUG Got device {"devkit":{"boardVersion":"PCA10156","deviceFamily":"NRF54L_FAMILY"},"id":5,"probe":{},"serialNumber":"001057762330","serialPorts":[{"comName":"COM7","manufacturer":"Microsoft","path":"\\\\?\\USB#VID_1366&PID_1069&MI_00#6&423E80E&0&0000#{86E0D1E0-8089-11D0-9CE4-08003E301F73}","productId":"1069","serialNumber":"001057762330","vcom":0,"vendorId":"1366"},{"comName":"COM8","manufacturer":"Microsoft","path":"\\\\?\\USB#VID_1366&PID_1069&MI_02#6&423E80E&0&0002#{86E0D1E0-8089-11D0-9CE4-08003E301F73}","productId":"1069","serialNumber":"001057762330","vcom":1,"vendorId":"1366"}],"traits":{"boardController":false,"broken":false,"devkit":true,"jlink":true,"mcuBoot":false,"modem":false,"nordicDfu":false,"nordicUsb":false,"seggerUsb":true,"serialPorts":true,"usb":true},"usb":{"device":{"address":4,"busNumber":2,"descriptor":{"bDescriptorType":1,"bcdDevice":256,"idProduct":4201,"idVendor":4966}},"manufacturer":"SEGGER","osDevicePath":"\\\\?\\USB#VID_1366&PID_1069#001057762330#{A5DCBF10-6530-11D2-901F-00C04FB951ED}","product":"J-Link","serialNumber":"001057762330"},"favorite":true,"nickname":""} undefined
    2025-10-30T08:34:20.282Z DEBUG Device with boardVersion: "PCA10156"
    2025-10-30T08:34:20.283Z DEBUG buildGui() for board definition pins: [{"type":"vcom","id":"vcom0","name":"VCOM0","enable":{"pin":42},"hwfc":{"pin":20}},{"type":"vcom","id":"vcom1","name":"VCOM1","enable":{"pin":22},"hwfc":{"pin":23}},{"type":"switch","id":"ledcontrol","title":"Power to LEDs","label":"Disable to have LEDs unpowered (and kept off).","tooltip":"Enabling this option provides LEDs from LED0 to LED3 with 3.3 V of power.","enable":{"pin":45}},{"type":"switch","id":"swd-control","title":"Software Debugger (SWD)","label":"Disable to use an external debugger on the target chip.","tooltip":"When enabled, the SWD is connected and the IMCU is acting as the debugger. When disabled, the SWD is disconnected and you can use an external debugger connected to the Debug In header.","enable":{"pin":6}},{"type":"switch","id":"swo-control","title":"SWO Control","label":"Connect or disconnect the SWO signal","tooltip":"When enabled, connects the SWO signal connection to the SWO P2.07 pin on nRF54L15. When disabled, the SWO signal is disconnected.","enable":{"pin":9,"invert":true}},{"type":"switch","id":"qspi-control","title":"External memory","label":"Enable external flash","tooltip":"When enabled, the QSPI pins (P2.00-P2.05) are connected to the external memory. When disabled, the QSPI pins are routed to the PORT2 header (P2).","enable":{"pin":47}}]
    2025-10-30T08:34:20.283Z INFO Rendering for nRF54L15 PDK (rev. 1.0.0)
    2025-10-30T08:34:20.284Z DEBUG Got device {"devkit":{"boardVersion":"PCA10156","deviceFamily":"NRF54L_FAMILY"},"id":5,"probe":{},"serialNumber":"001057762330","serialPorts":[{"comName":"COM7","manufacturer":"Microsoft","path":"\\\\?\\USB#VID_1366&PID_1069&MI_00#6&423E80E&0&0000#{86E0D1E0-8089-11D0-9CE4-08003E301F73}","productId":"1069","serialNumber":"001057762330","vcom":0,"vendorId":"1366"},{"comName":"COM8","manufacturer":"Microsoft","path":"\\\\?\\USB#VID_1366&PID_1069&MI_02#6&423E80E&0&0002#{86E0D1E0-8089-11D0-9CE4-08003E301F73}","productId":"1069","serialNumber":"001057762330","vcom":1,"vendorId":"1366"}],"traits":{"boardController":false,"broken":false,"devkit":true,"jlink":true,"mcuBoot":false,"modem":false,"nordicDfu":false,"nordicUsb":false,"seggerUsb":true,"serialPorts":true,"usb":true},"usb":{"device":{"address":4,"busNumber":2,"descriptor":{"bDescriptorType":1,"bcdDevice":256,"idProduct":4201,"idVendor":4966}},"manufacturer":"SEGGER","osDevicePath":"\\\\?\\USB#VID_1366&PID_1069#001057762330#{A5DCBF10-6530-11D2-901F-00C04FB951ED}","product":"J-Link","serialNumber":"001057762330"},"favorite":true,"nickname":""} undefined
    2025-10-30T08:34:20.284Z DEBUG Device with boardVersion: "PCA10156"
    2025-10-30T08:34:20.284Z DEBUG buildGui() for board definition pins: [{"type":"vcom","id":"vcom0","name":"VCOM0","enable":{"pin":42},"hwfc":{"pin":20}},{"type":"vcom","id":"vcom1","name":"VCOM1","enable":{"pin":22},"hwfc":{"pin":23}},{"type":"switch","id":"ledcontrol","title":"Power to LEDs","label":"Disable to have LEDs unpowered (and kept off).","tooltip":"Enabling this option provides LEDs from LED0 to LED3 with 3.3 V of power.","enable":{"pin":45}},{"type":"switch","id":"swd-control","title":"Software Debugger (SWD)","label":"Disable to use an external debugger on the target chip.","tooltip":"When enabled, the SWD is connected and the IMCU is acting as the debugger. When disabled, the SWD is disconnected and you can use an external debugger connected to the Debug In header.","enable":{"pin":6}},{"type":"switch","id":"swo-control","title":"SWO Control","label":"Connect or disconnect the SWO signal","tooltip":"When enabled, connects the SWO signal connection to the SWO P2.07 pin on nRF54L15. When disabled, the SWO signal is disconnected.","enable":{"pin":9,"invert":true}},{"type":"switch","id":"qspi-control","title":"External memory","label":"Enable external flash","tooltip":"When enabled, the QSPI pins (P2.00-P2.05) are connected to the external memory. When disabled, the QSPI pins are routed to the PORT2 header (P2).","enable":{"pin":47}}]
    2025-10-30T08:34:20.284Z INFO Rendering for nRF54L15 PDK (rev. 1.0.0)
    2025-10-30T08:34:20.285Z DEBUG Rendering VCOMConfiguration for VCOM0
    2025-10-30T08:34:20.287Z DEBUG Rendering VCOMConfiguration for VCOM1
    2025-10-30T08:34:20.295Z DEBUG Rendering SidePanel
    2025-10-30T08:34:20.323Z DEBUG Sending event "board-configurator: running nrfutil device"
    2025-10-30T08:34:21.856Z DEBUG Rendering SidePanel
    2025-10-30T08:34:23.370Z DEBUG Rendering SidePanel
    2025-10-30T08:34:34.752Z INFO Selected device with the serial number 001057762330
    2025-10-30T08:34:34.761Z DEBUG Sending event "board-configurator: device selected"
    2025-10-30T08:34:34.761Z DEBUG Sending event "board-configurator: running nrfutil device"
    2025-10-30T08:34:44.879Z DEBUG Rendering SidePanel
    2025-10-30T08:34:44.892Z DEBUG Sending event "board-configurator: running nrfutil device"
    2025-10-30T08:34:49.775Z ERROR Error: Failed with exit code 1.
    One or more batch tasks failed:
    * 1057762330: The operation you tried to run is not available for the selected device.

    The operation is either not supported for this type of device or the device has issues and it cannot be recognized (NotFound)


    Message: Batch task smp failed, The operation you tried to run is not available for the selected device.

    The operation is either not supported for this type of device or the device has issues and it cannot be recognized.
    2025-10-30T08:34:59.762Z ERROR Error: Failed with exit code 1.
    One or more batch tasks failed:
    * 1057762330: The operation you tried to run is not available for the selected device.

    The operation is either not supported for this type of device or the device has issues and it cannot be recognized (NotFound)


    Message: Batch task smp failed, The operation you tried to run is not available for the selected device.

    The operation is either not supported for this type of device or the device has issues and it cannot be recognized.

    I tried to change the VDD the 3.3V also to make work the SD Module.

  • I try to reconnect me to BoardConfigurator and the good parameters were put.

    But I have always this error on the terminal.

    [00:00:00.429,109] <dbg> fs: fs_register: fs register 0: 0
    *** Booting nRF Connect SDK v2.9.2-4ab7b98fc76f ***
    *** Using Zephyr OS v3.7.99-aa34a5632971 ***
    [00:00:00.429,150] <err> main: Storage init ERROR!
    [00:00:00.429,166] <err> fs: fs mount error (-5)
    Error mounting disk.

Related