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

Fatfs Example Bug

Hi!

I was testing the SD Card example that is available on the SDK 13.00 in the following path: "nRF5SDK1300/examples/peripheral/fatfs". I checked SDK 16.0 and the code is exactly the same, so I presume this bug is still there.

So i checked with the scope the initialization signal sent to the card and realized that even though the function is called three times in the code below, the initialization SPI attempt is sent only once:

    for (uint32_t retries = 3; retries && disk_state; --retries)
    {
        NRF_LOG_INFO("Initializing disk 0 (SDC)...\r\n");
        disk_state = disk_initialize(0);
    }

So I debugged the "disk_initialize" function inside "$(SDK_ROOT)/external/fatfs/port/diskio_blkdev.c \" and found out the "nrf_blk_dev_init" returns 17 (or 0x11) if called twice. 

    err_code = nrf_blk_dev_init(m_drives[drv].config.p_block_device,
                                           block_dev_handler,
                                           (void *) (uint32_t) drv);

My workaround: I added "nrf_blk_dev_uninit" before calling "nrf_blk_dev_init". "nrf_blk_dev_uninit" returns 0x11 at the first attempt, because I'm trying to unitialize something that was never initialized, but it does not seem to be a problem. On the second and third attempt, it runs smoothly and tries to connect to the card as expected.

    err_code = nrf_blk_dev_uninit(m_drives[drv].config.p_block_device);

Hint: in order to test that, one can simply take the card away, because in this condition it will never be initialized. I also used another pin from uC as trigger to the scope Slight smile

I just wanted to report that to help other developers that might find this problem in the future.

Best Regards

Related