Is there a Library connect MicroSDHC via SPI

Hi,

i want/need to connect & access a microSD Card (32GB) on an breakout board via SPI (technical reasons) and want to use the suggested PINS (28-31) as in the intermediate lesson 5 exercise 1.

Is there a separate library (except the described spi, gios, devicetree) available/required, like an SD.h?

Thanks for hints/suggestions

  • Hello,

    ''Is there a separate library (except the described spi, gios, devicetree) available/required, like an SD.h?''

    There is no separate Arduino-style SD.h-like library for NCS. 

    As you are on dev academy intermediate course (lesson 5 exercise 1), so you know how to enable SPI and GPIO over the driver. You have to enable the follwoing config in prj.conf file

    CONFIG_GPIO=y
    CONFIG_SPI=y

    You can add sd card following way (https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/services/storage/disk/access.html#sd_card_support_via_spi)

    &spi1 {
        status = "okay";
        cs-gpios = <&gpio0 27 GPIO_ACTIVE_LOW>;  /* example CS pin */
    
        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>;
        };
    };

    For the nRF5SDK. there is SD card library that communicates SD over SPI (nRF5 SD card lib) but not on NCS.

    Thanks.

    BR

    Kazi

  • Hi,

    ok, i assumed it, but thanks for the suggestion. Compiling works, initialization of the microSD not yet.

    But what means NCS?

  • Hello,

    NCS means nRF Connect for SDK.

    ''Compiling works, initialization of the microSD not yet.''

    Can you show me the board files?

  • // nrf52dk_nrf52832.overlay:

    &spi0 { status = "disabled";};
    &i2c1 { status = "disabled";};

    &spi1 {
    /* What about this property?? */
    //compatible = "nordic,nrf-spi";//using SPI as per ERRATA 58
    status = "okay";
    pinctrl-0 = <&spi1_default>;
    pinctrl-1 = <&spi1_sleep>;
    pinctrl-names="default", "sleep";
    cs-gpios = <&gpio0 31 GPIO_ACTIVE_LOW>;
    sdhc0: sdhc@0 {
    compatible = "zephyr,sdhc-spi-slot";
    status = "okay";
    reg = <0>;
    mmc {
    compatible = "zephyr,sdmmc-disk";
    status = "okay";
    disk-name = "MMC SD";
    };
    spi-max-frequency = <24000000>; //max frequency up to 25MHZ
    };
    };

    /* Change the pin configuration */
    &pinctrl{
    spi1_default: spi1_default{
    group1{
    psels=<NRF_PSEL(SPIM_SCK, 0, 28)>,
    <NRF_PSEL(SPIM_MOSI, 0, 29)>,
    <NRF_PSEL(SPIM_MISO, 0, 30)>;
    };
    };
    spi1_sleep: spi1_sleep{
    group1{
    psels=<NRF_PSEL(SPIM_SCK, 0, 28)>,
    <NRF_PSEL(SPIM_MOSI, 0, 29)>,
    <NRF_PSEL(SPIM_MISO, 0, 30)>;
    low-power-enable;
    };
    };

    };
  • Hello,

    Try to set SPI max frequency 400 kHz

    spi-max-frequency = <400000>;

    The overlay file based on your overlay be like this:

    &spi1 {
        compatible = "nordic,nrf-spim";   /* enable SPIM driver */
        status = "okay";
        pinctrl-0 = <&spi1_default>;
        pinctrl-1 = <&spi1_sleep>;
        pinctrl-names = "default", "sleep";
        cs-gpios = <&gpio0 31 GPIO_ACTIVE_LOW>;
    
        sdhc0: sdhc@0 {
            compatible = "zephyr,sdhc-spi-slot";
            reg = <0>;
            status = "okay";
            spi-max-frequency = <400000>; /* start low */
    
            mmc {
                compatible = "zephyr,sdmmc-disk";
                status = "okay";
                disk-name = "MMC SD";
            };
        };
    };

Related