nRF54L15: SD card over SPI works on SPIM20 but fails on SPIM00 (nrfx_spim_init error)

I am trying to interface an SD card over SPI on nRF54L15 using nRF Connect SDK.

I started from Nordic’s fs_sample, which by default uses SPIM20 on Port 1 pins, and this configuration works correctly (SD card initializes, filesystem mounts, displays files).

However, when I try to use SPIM00 mapped to Port 2 pins keeping everything else the same, SPI initialization fails.

Overlay FIle -:

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

    spi00_sleep: spi00_sleep {
        group1 {
            psels = <NRF_PSEL(SPIM_SCK, 2, 1)>,
                    <NRF_PSEL(SPIM_MOSI, 2, 2)>,
                    <NRF_PSEL(SPIM_MISO, 2, 4)>;
            low-power-enable;
        };
    };
};

&spi00 {
    status = "okay";
    compatible = "nordic,nrf-spim";
    pinctrl-0 = <&spi00_default>;
    pinctrl-1 = <&spi00_sleep>;
    pinctrl-names = "default", "sleep";
    cs-gpios = <&gpio2 5 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;

    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>;
    };
};


prj.conf -:

CONFIG_DISK_ACCESS=y
CONFIG_DISK_DRIVER_SDMMC=y
CONFIG_FILE_SYSTEM=y
CONFIG_FAT_FILESYSTEM_ELM=y

CONFIG_LOG=y
CONFIG_PRINTK=y
CONFIG_LOG_BACKEND_UART=n
CONFIG_LOG_BACKEND_RTT=y

CONFIG_RTT_CONSOLE=y
CONFIG_UART_CONSOLE=n

CONFIG_MAIN_STACK_SIZE=2048
CONFIG_USE_SEGGER_RTT=y



Output logs -:
*** Booting My Application v1.0.0-9484be88f466 ***
*** Using nRF Connect SDK v3.0.2-89ba1294ac9b ***
*** Using Zephyr OS v4.0.99-f791c49f492c ***

[00:00:00.059,702] <err> main: Storage init---------
[00:00:00.060,819] <err> spi_nrfx_spim: Failed to initialize nrfx driver: 0bad0004
[00:00:00.060,836] <err> sdhc_spi: Card SCLK init sequence failed
[00:00:00.060,841] <err> sd: Could not disable card power via SDHC
[00:00:00.060,848] <err> main: Storage init ERROR!

[00:00:00.061,964] <err> spi_nrfx_spim: Failed to initialize nrfx driver: 0bad0004
[00:00:00.061,970] <err> sdhc_spi: Card SCLK init sequence failed
[00:00:00.061,975] <err> sd: Could not disable card power via SDHC
[00:00:00.061,983] <err> fs: fs mount error (-5)
Error mounting disk.
[00:00:00.062,006] <err> fs: fs not mounted (mp == 0x200004c0)



  • Hi,

    It looks that SD cards over SPI are initialized at a low clock (400 kHz). SPIM00 is a high-speed SPI instance clocked at 128 MHz and cannot generate such a low frequency, so the nrfx driver rejects the configuration and returns 0bad0004. This could causes the SD SCLK init sequence to fail whereas other SPIM instances (example SPIM20) support low SPI frequencies and therefore work correctly.

    So the recommendation is to use SPIM20/21/22/30 for SD cards.

    Using SPIM00 would require starting SD init at a higher frequency which you can try by adding your own configuration in the driver or board code to choose another sdhc_clock_speed value (e.g. SD_CLOCK_25MHZ). Or you could also modify the definition of 'SDMMC_CLOCK_400KHZ' to any larger frequencies like 2Mhz (However please note this is not a recommended and standard way so it could be unreliable). Currently SDMMC_CLOCK_400KHZ is defined in the Zephyr’s SD spec header in the following way:

    enum sdhc_clock_speed {
        SDMMC_CLOCK_400KHZ = KHZ(400),
        SD_CLOCK_25MHZ     = MHZ(25),
        ...
    };

    Best Regards,
    Syed Maysum

Related