Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Fatfs example does not work with every sd card?

Hi, I am working on application where I need to store some bigger files. I chose to use sdcard, but I get weird behaviour. Some sd cards, this looks like totaly random ones are working and other are not with fatfs on nrf52. I was trying few cards with fatfs example from SDK and one was working while all other seems to hang up at disk_initialization:

 0> <info> app: FATFS example.
 0> <info> app: Initializing disk 0 (SDC)...
 0> <info> spi: Init
 0> <info> spi: Function: nrf_drv_spi_init, error code: NRF_SUCCESS.
 0> <info> spi: Transfer tx_len:1, rx_len:10.
 0> <info> spi: Function: spim_xfer, error code: NRF_SUCCESS.
 0> <info> spi: Transfer completed rx_len:10.
 0> <info> spi: Transfer tx_len:6, rx_len:15.
 0> <info> spi: Function: spim_xfer, error code: NRF_SUCCESS.
 0> <info> spi: Transfer completed rx_len:15.
 0> <info> spi: Transfer tx_len:6, rx_len:15.

I tried making changes as suggested here: https://devzone.nordicsemi.com/f/nordic-q-a/25951/sd-card-example-not-working-fine but it wont help. I can work with that few are not working but it looks like most of them is not working. Is there recommended sdcard size/type/manufacturer to be used with nrf52?

Regards,

Michał

  • The low-level diskio_* functions know to send the CMD55 before all ACMD* commands, so CMD55 won't show up in logs unless one monitors SPI directly.

  • Thanks Turbo J, indeed in app_sdcard in lines 320-330 there is check for ACMD and prefix to every of these commands... Honestly that is a pitty I was hoping there is bug somewhere here.

  • After some more debugging the difference between working and not working cards is response to CMD58 (app_sdcard.c :600). The working card returns 0xC0FF8000, which is seen as SDHC card while the other card responds with 0x81FE0003 which not match SDC_HCS_FLAG_MASK and in result this card is not seen as SDHC card. I am not sure what it should retun in response but I think it should be marked as SDHC.

    EDIT: Of sd card spec it comes out that I have 2 SD HC UHS-I cards and both of them are not working while the working one is just SD HC.

  • The default SPI settings use standard drive for the SCK and MOSI pins; it's perhaps worth checking whether they simply need to be set to high drive (typically required only at higher clock frequencies). Offhand I don't know whether the FATFS example already does that, but most examples do not. Here's an example, must be set after SPI initialise (or change within SPI init):

        nrf_gpio_cfg(SCK_PIN,
                     NRF_GPIO_PIN_DIR_OUTPUT,
                     NRF_GPIO_PIN_INPUT_DISCONNECT,
                     NRF_GPIO_PIN_NOPULL,
                     NRF_GPIO_PIN_H0H1,       // Require High Drive low/high level
                     NRF_GPIO_PIN_NOSENSE);
    

  • Thanks hmoolesworth ! It indeed was my case. I suspect that UHS-I cards that have higher max transfer speed has higher drives on SD card side so that is why I needed higher drive on nrf side.

    Can someone from Nordic confirm this may be right solution and also maybe you can fix this in newer versions of sdk ?

    EDIT: I will wait for confirmation before approving answer.

    EDIT: No response from Nordic, but it is working so I am closing this. Also for whoever may read this: I also edited gpio configuration for mosi line, the same way.

Related