cancel
Showing results for 
Search instead for 
Did you mean: 

FileX SD card insertion/removal handling

Pajaka
Associate III

Hi,

how am I supposed so handle the reinsertion event while using the FileX with an SD card? All the examples I saw assume the SD card cannot be ejected while in use which is obviously unrealistic.

I tried to do it according to the official docs and when the ejection is detected I call the fx_media_abort and fx_stm32_sd_deinit. But during the reinsertion when I call the fx_media_open again I get the FX_IO_ERROR. At this point the driver should be in an uninitialized state and the fx_media_open should call the fx_stm32_sd_init function.

Can anyone relate to this problem? Here is the code example. The FX_STM32_SD_INIT macro is defined.

 

if(card_insertion_flag.Get(0x03, EventGroup::Access::bit_or_clear, TX_WAIT_FOREVER,flag))
{
	if(flag & 0x01)
	{
		//Card inserted
		uint8_t cntr = 0;
		do
		{
			status = fx_media_open(&this->sdio_disk, (char* )"SD card", fx_stm32_sd_driver, 0, (VOID *) media_memory, this->media_memory_size);
			HAL_Delay(50);
		}
		while(cntr++ < 50 && status != FX_SUCCESS);

		if(status != FX_SUCCESS)
		{
			Error_Handler();
		}

		status = fx_file_open(...
	}
	else
	{
		//Here I tried all this and its combinations
		//status = fx_media_abort(&this->sdio_disk);
		//status = fx_media_close(&this->sdio_disk);
		//fx_stm32_sd_deinit(0);
	}
}

 

 

10 REPLIES 10

Thank you @Pajaka , 
i had the same problem and your workaround fixed it for me.