This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Need a working example of using an SD card with FAT filesystem on the nRF9160.

There is a demo zephyr/samples/subsys/fa/fat_fs.
This purports to mount an SD card.

Is this for the unpopulated SD socket on the nRF9160 board?

The ticket https://devzone.nordicsemi.com/f/nordic-q-a/58558/reading-sd-card-on-nrf9160dk
talks about using an Adafruit SD breakout board over SPI.
These issues seem to be with earlier versions of the SDK.

It says..

Hi,

I am using adafruit micro-sd breakout board and kingston micro sd card 8GB which is formatted to FAT32 Filesystem.
Connections are as follow:
SCK (Pin 11) -> CLK
MOSI (Pin 12) -> DI
MISO (Pin 13) -> DO
CS (Pin 10) -> CS

It also includes an image and it appears to match these connections.
However, the overlay file listed later in the same ticket has different pins.



There are two versions of the overlay file...

Hello,

Attached is a working project using SPI3. The output is shown in the image.

&spi3 {
        compatible = "nordic,nrf-spim";
        status = "okay";
        sck-pin = <10>;
        mosi-pin = <11>;
        miso-pin = <12>;

        cs-gpios = <&gpio0 13 0>;

        sdhc0: sdhc@0 {
                compatible = "zephyr,mmc-spi-slot";
                reg = <0>;
                status = "okay";
                label = "SDHC0";
                spi-max-frequency = <24000000>;
        };
};

But earlier in the same file it has:
/*
 * Copyright (c) 2019 Tavish Naruka <[email protected]>
 *
 * SPDX-License-Identifier: Apache-2.0
 */

&spi3 {
        status = "okay";
        cs-gpios = <&gpio0 16 0>;

        sdhc0: sdhc@0 {
                compatible = "zephyr,mmc-spi-slot";
                reg = <0>;
                status = "okay";
                label = "SDHC0";
                spi-max-frequency = <24000000>;
        };
};

&spi3 {
        status = "okay";
        sck-pin = <19>;
        mosi-pin = <18>;
        miso-pin = <17>;
};


At the end there is a link to another ticket https://devzone.nordicsemi.com/f/nordic-q-a/59430/nrf9160-sd-card-access-via-spi/242347#242347
that says "The solution to this problem is to set the "Size of RAM buffers for SPIM peripherals" to some number. If the size is set to 0, the SPI transceive function will always return error."
However, my SDK (v1.5) has this set properly.

Has anyone at Nordic got this working?

Parents
  • Please see
    https://devzone.nordicsemi.com/f/nordic-q-a/71843/how-to-setup-sd-card-reader-with-nrf9160-for-reading-and-writing-files
    It talks about using a readily-available Adafruit SD SPI Breakout board.
    The unpopulated SD is single-source product with a 5,000-piece minimum buy and 180-day lead-time.

    The ticket I linked seems to say this works and someone at Nordic knows about it.
    Can you do a bit of research and determine if we  can get the prj.conf and overlay files that work with that.
    Our FEA Mike Sly said he has acquired one of the Adafruit adapters and is ready to work in parallel.

  • Hi Håkon,

    I am running into the same issue as Keith on the build.

    I am using the master branch.

    This is for the nRF9160DK Rev 1.0.0 which has the External Flash installed so I changed the prj.conf slightly to match the SPI pins used for EXT_MEM (namely MOSI P0.11, MISO P0.12, SCK P0.13, CS* P0.10). 

    Here is the prj.conf

    #CONFIG_DISK_ACCESS=y
    #CONFIG_LOG=y
    #CONFIG_FILE_SYSTEM=y
    #CONFIG_FAT_FILESYSTEM_ELM=y
    #CONFIG_PRINTK=y
    #CONFIG_MAIN_STACK_SIZE=2048
    
    #MS
    CONFIG_DISK_DRIVER_SDMMC=y
    CONFIG_SPI=y
    CONFIG_SPI_3=y
    CONFIG_DISK_ACCESS_SDHC=y
    CONFIG_DISK_ACCESS_SPI_SDHC=y
    CONFIG_LOG=y
    CONFIG_FILE_SYSTEM=y
    CONFIG_FAT_FILESYSTEM_ELM=y
    CONFIG_NRFX_SPIM=y
    CONFIG_SPI_NRFX_RAM_BUFFER_SIZE=64
    CONFIG_MAIN_STACK_SIZE=2048
    CONFIG_GPIO=y

    Here is nrf9160dk_nrf9160ns.overlay

    /*
     * Copyright (c) 2019 Tavish Naruka <[email protected]>
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    &spi3 {
            compatible = "nordic,nrf-spim";
            status = "okay";
            sck-pin = <13>;
            mosi-pin = <11>;
            miso-pin = <12>;
    
            cs-gpios = <&gpio0 10 GPIO_ACTIVE_LOW>;
    
            sdhc0: sdhc@0 {
                    compatible = "zephyr,mmc-spi-slot";
                    reg = <0>;
                    status = "okay";
                    label = "SDHC0";
                    spi-max-frequency = <24000000>;
            };
    };

    I am not 100% sure the prj.conf settings above are correct.

    Here is the build output

    It is appears that Keith is correct that we may need to use Zephyr Project 2.6 instead of 2.5.99.

    Can you confirm that you can build on your side?

    I now have the Adafruit micro-SD board so I can test the functionality once it successfully builds.

    Thank you for the guidance,

    Mike

Reply
  • Hi Håkon,

    I am running into the same issue as Keith on the build.

    I am using the master branch.

    This is for the nRF9160DK Rev 1.0.0 which has the External Flash installed so I changed the prj.conf slightly to match the SPI pins used for EXT_MEM (namely MOSI P0.11, MISO P0.12, SCK P0.13, CS* P0.10). 

    Here is the prj.conf

    #CONFIG_DISK_ACCESS=y
    #CONFIG_LOG=y
    #CONFIG_FILE_SYSTEM=y
    #CONFIG_FAT_FILESYSTEM_ELM=y
    #CONFIG_PRINTK=y
    #CONFIG_MAIN_STACK_SIZE=2048
    
    #MS
    CONFIG_DISK_DRIVER_SDMMC=y
    CONFIG_SPI=y
    CONFIG_SPI_3=y
    CONFIG_DISK_ACCESS_SDHC=y
    CONFIG_DISK_ACCESS_SPI_SDHC=y
    CONFIG_LOG=y
    CONFIG_FILE_SYSTEM=y
    CONFIG_FAT_FILESYSTEM_ELM=y
    CONFIG_NRFX_SPIM=y
    CONFIG_SPI_NRFX_RAM_BUFFER_SIZE=64
    CONFIG_MAIN_STACK_SIZE=2048
    CONFIG_GPIO=y

    Here is nrf9160dk_nrf9160ns.overlay

    /*
     * Copyright (c) 2019 Tavish Naruka <[email protected]>
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    &spi3 {
            compatible = "nordic,nrf-spim";
            status = "okay";
            sck-pin = <13>;
            mosi-pin = <11>;
            miso-pin = <12>;
    
            cs-gpios = <&gpio0 10 GPIO_ACTIVE_LOW>;
    
            sdhc0: sdhc@0 {
                    compatible = "zephyr,mmc-spi-slot";
                    reg = <0>;
                    status = "okay";
                    label = "SDHC0";
                    spi-max-frequency = <24000000>;
            };
    };

    I am not 100% sure the prj.conf settings above are correct.

    Here is the build output

    It is appears that Keith is correct that we may need to use Zephyr Project 2.6 instead of 2.5.99.

    Can you confirm that you can build on your side?

    I now have the Adafruit micro-SD board so I can test the functionality once it successfully builds.

    Thank you for the guidance,

    Mike

Children
Related