Using SD card on nRF9161 DK

Hello, we've a nRF9161 DK board a we saw on the back side a footprint for mounting an SD card holder and we found the SD card holder component in the BOM.

Unfortunately there is no mention about the usage of the SD card in for the nRF9161 DK anywhere in the documentation.

Is there any problem on using the SD card on nRF9161 DK (trough SPI I guess) ?

What do we have to do to connect the SD card to the nRF9161 module (excluding the soldering of the card holder)?

Thanks in advance for the support,

Joel

Parents
  • I was talking about J8 on the bottom side of the board listed on the BOM as "microSD Card Connector"...

  • Hello... I'm a little confused ... mass storage example is building with success when i set nrf52840dk/nrf52840 as board (which has its dt overlay under boards).

    west build -b nrf52840dk/nrf52840 -d build -- -DCONFIG_APP_MSC_STORAGE_SDCARD=y is ok

    If I set nrf9161dk/nrf9161 the build ends with errors ... 

    west build -b nrf9161dk/nrf9161 -d build -- -DCONFIG_APP_MSC_STORAGE_SDCARD=y fails

    C:/ncs/v3.0.2/zephyr/samples/subsys/usb/mass/src/main.c:36:2: error: #error No supported disk driver enabled
       36 | #error No supported disk driver enabled

    Joel

  • You need to copy the nrf52840-related overlay file and rename it for the board you are building for (nrf9161dk_nrf9161_cpuapp.overlay).

    Best regards,

    Edvin

  • Ok, of course this makes the sample building with success ... but nrf52840dk_nrf52840.overlay  maps storage_partition onto the mx25r64 serial SPI flash ... not to the SD card .

    Which changes are needed to set storage_partition being pointing to the SD card ?

    Joel

  • Hi Joel,

    Edvin is out of office on PTO so I'll be handling this case for this week (lets hope we can resolve it by Friday before I also leave for PTO..).

    If I understand you correct, what you're missing now is to port the solution so that it works on a 9161dk, right? 

    If so, then what we're missing should be the following.

    You're correct that this specific configuration maps to the SPI flash, which is due to the nRF52840DK not having a SD card reader on board so it requires the additional hardware mentioned in the build command here:

    But lets stick to making this sample work for the nRF9160DK before we look into the SD card implenation (divide and conquer the problem).

    It also mentions the additional config in the last build argument and since you're working with NCS, you still need to have a pm_static.yml for your partitioning as well as an overlay tailored to the board you're using, which brings us to the last problem.

    Edvin says that you can copy the nrf52840 related overlay and rename it for the board you're building for, which is correct, but you also have to make a modification to the external flash device that you're using. The nRF9161  uses the GD25WB256 flash, which you can see in an overlay file here: https://github.com/NordicDeveloperAcademy/ncs-inter/blob/main/l9/l9_e3_sol/spi/app_gd.overlay and/or in any cellular samples in nrf/samples where the external flash is enabled or the board files within zephyr/boards/nordic/ in the SDK.

    I.e change your overlay (which should be) for

    nrf52840dk_nrf52840.overlay:

    /*
     * Copyright (c) 2019 Peter Bigot Consulting, LLC
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    /delete-node/ &storage_partition;
    
    &mx25r64 {
    	partitions {
    		compatible = "fixed-partitions";
    		#address-cells = <1>;
    		#size-cells = <1>;
    
    		storage_partition: partition@0 {
    			label = "storage";
    			reg = <0x00000000 0x00020000>;
    		};
    	};
    };
    
    / {
    	msc_disk0 {
    		compatible = "zephyr,flash-disk";
    		partition = <&storage_partition>;
    		disk-name = "NAND";
    		cache-size = <4096>;
    	};
    };

    to 

    nrf9160dk_nrf9160.overlay (or the target you're building for as listed: 

    and do something like (I've merged the app_gd.overlay and the 52840 overlay, there might be something wrong so check when building if it behaves as expected)

    /*
     * Copyright (c) 2019 Peter Bigot Consulting, LLC
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    /delete-node/ &storage_partition;
    
    &gd25wb256 {
    	status = "okay";
    };
    
    / {
    	chosen {
    		nordic,pm-ext-flash = &gd25wb256;
    	};
    };
    
    
    &gd25wb256 {
    	partitions {
    		compatible = "fixed-partitions";
    		#address-cells = <1>;
    		#size-cells = <1>;
    
    		storage_partition: partition@0 {
    			label = "storage";
    			reg = <0x00000000 0x00020000>;
    		};
    	};
    };
    
    / {
    	msc_disk0 {
    		compatible = "zephyr,flash-disk";
    		partition = <&storage_partition>;
    		disk-name = "NAND";
    		cache-size = <4096>;
    	};
    };

    After we've succeeded with this, we should have a emulated SD card in SPI external flash for the 9161DK which is good, because now we now that the sample works and compiles for the nRF9160DK and we can exclude quite a bit of uncertainties.

    The next task is to port it to an SD card.

    To do this we need some more modifications (or additional hardware). "west build -b nrf52840dk/nrf52840 --shield waveshare_epaper_gdeh0154a07 samples/subsys/usb/mass -- -DCONFIG_APP_MSC_STORAGE_SDCARD=y" handles the extra hardware since it uses a shield that has an SD card reader, and it adds the extra configuration.

    In addition https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/samples/subsys/usb/mass/README.html#sd_card_example takes us to modifications that you need to do yourself, i.e https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/services/storage/disk/access.html#disk-access-api and to add a SPI (I assume that this is the peripheral you will be using) that can do SD card https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/services/storage/disk/access.html#disk-access-api. An example can be seen in the latter link for how to set this up:

    &spi1 {
            status = "okay";
            cs-gpios = <&porta 27 GPIO_ACTIVE_LOW>;
    
            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>;
            };
    };

    Kind regards,
    Andreas

  • Many thanks for the detailed procedure... It remains unclear to me how this particular example can successfully build for a nRF9161 target which do not has a USB controller on chip. 

    Joel

Reply Children
  • Happy to help,

    JOEBRE said:
    It remains unclear to me how this particular example can successfully build for a nRF9161 target which do not has a USB controller on chip. 

    Hmm... If you aim to use the SD card through USB in any ways, I guess the answer is that it won't work, but if you intend to use the SD card through SPI only as shown in some of the links below it should work. The usb/mass sample is a Zephyr sample that intends to show both how to use it as a USB storage device (and thus also with the SD card overlay to be used as something where you can load/unload data to the SD card with USB), whereas the SPI SD card configuration is just to set up an SPI communication to read/write to the SD card. That's at least how I understand it.

    You may find some more information on the Zephyr discord forums w.r.t this sample. Since it's a Zephyr sample, the support for the sample is somewhat limited (such as it not building out of the box due to that nRF Connect SDK uses Partition Manager and Zephyr does not).

    Kind regards,
    Andreas

  • No, as stated initially, I just need to have SD card running with LittleFS on my application. My initial starting point was the format sample ... which was building and running correctly on nRF9161 target with exception of the LittleFS stuff ... then Edvin told me to use the mass sample as starting point and build it for nRF9161... I personally just need the SD card working on whatever sample which is buildable for  the nRF9161 target.

    Joel

  • Noted,

    I can't promise anything but I will see if I can get it compiling. But yeah, since I guess both Edvin and I missed that fact that there's no USB controller, then the best way might still be to base it on the usb/mass implementation and dissect out the USB parts and implement the SPI solution in the resources I posted.

    There's no other samples that might be working as a foundation within the SDK.

    Kind regards,
    Andreas

Related