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

Two SD card interfaces over SPI.

I have a working code to get FatFs running with SD card over SPI0 interface on a nRF52840 DK. I wanted to know if it is possible to add another SD card with FatFs on SPI2 interface and access the cards in the same firmware. The file, nrf_block_dev_sdc.h has the following at line 54.

/**
 * @brief Active SDC block device handle. Only one instance.
 * */
static nrf_block_dev_sdc_t const * m_active_sdc_dev;

Is it possible to work around this?

Parents Reply Children
  • It is not certain you need to do this. Perhaps you should either use one instance of nrf_block_dev_sdc_t and switch it between the SD card readers that you are using?

    I think I would start by expanding:

        // Initialize FATFS disk I/O interface by providing the block device.
        static diskio_blkdev_t drives[] =
        {
                DISKIO_BLOCKDEV_CONFIG(NRF_BLOCKDEV_BASE_ADDR(m_block_dev_sdc, block_dev), NULL)
        };

    To contain twi DISKIO_BLOCKDEV_CONFIG().

    Then, in order to use the other disk, you would e.g. call disk_initialize(1), which will point to the other disk.

    But from there I am not certain. The fatfs is an external library, so I am not familiar with it. It looks like one instance of FATFS fs, which is used in f_mount(&fs, ...) mounts one drive, so you need to figure out how to make this mount drive 1 instead of drive 0. I see that FATFS has a member called drv, but I don't see how this opens drive 0 by default.

  • Hi Edvin.

    Thanks for your answer. I went ahead and duplicated the files, app_sdcard.c/.h and nrf_block_dev_sdc.c/.h and other data structures in nrf_block_dev.h . It seems to work fine for now. This will need some thorough testing though.

Related