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

I have a problem!!!

Hello.

This is my code to "wait until micro sd card is pluged".

while(1)
{
	disk_state =disk_initialize(0); 
	if(disk_state==RES_OK) 
	{
		NRF_LOG_INFO("Initialize Successful \r\n");
		break;
	}
	else
	{
		disk_uninitialize(0);
		disk_state = STA_NOINIT;
		diskio_blkdev_t drives[] =
		{
			DISKIO_BLOCKDEV_CONFIG(NRF_BLOCKDEV_BASE_ADDR(m_block_dev_sdc, block_dev), NULL)
		};
		diskio_blockdev_register(drives, ARRAY_SIZE(drives));
		NRF_LOG_INFO("ReInit one more time\r\n");
		delay();
	}
}

But It seems not work. Have any idea for me ?

  • What seems to not work? Could you give a more detailed explanation on what happens when you use this code?

  • Hi,

    The issue seems to be related to the SD card initialization and the communication between nrf_block_dev_sdc and app_sdcard. When you call disk_initialize(), block_dev_sdc_init() will be called, which again calls app_sdc_init(). This call will succeed the first time, as the SPI interface is only initialized and a transfer is started, before a success error code is returned. app_sdcard will try to initialize the card, and when this fails, it will uninit itself. Unfortunately, no event is passed to nrf_block_dev_sdc to signalize this, so this module is still initialized. This will result in m_active_sdc_dev being set, even though no SD card is enabled, giving wrong error code returns when you have connected the SD card.

    [EDIT:] After talking to the developer, we came up with a better solution to this issue. There is in fact an event passed from app_sdcard to nrf_block_dev_sdc when the init of the SD card fails. This event contains an error code/result field, but block_dev_sdc is not uninitialized if field containt an error. The error is however passed to block_dev, where an error reported back to your disk_initializecall. The result of this is block_dev_sdc will be left inited even if an error occurred, causing the issue you are seeing.

    To solve this issue, you need to do the following changes:

    1. Between line 83 and 84 of the file nrf_block_dev_sdc.c, add the following code:

      if(p_event->result != SDC_SUCCESS) { nrf_block_dev_t const * block_dev = &(p_sdc_dev->block_dev); ret_code_t err_code = block_dev_sdc_uninit(block_dev); APP_ERROR_CHECK(err_code); }

    2. In file app_sdcard.c, remove the call to APP_ERROR_CHECK(app_sdc_uninit()); on line 951.

    I will report this bug internally to have it fixed in future SDK releases.

    Best regards,

    Jørgen

  • Thanks you for your suggestion. I am going to test it when I go home and report my result for you. if you have any other solution please tell me!

  • thanks you for your support! I was implemented your code and my project was run correctly.

Related