Hi Alessandro,
you are right. This situation is not fully covered by MQX SDcard driver.
In fact, you can detect SDcard by switch at SDcard holder (as GPIO) or potentially you can use a pull-up resistor on DAT[3] to detect card insertion.
Unfortunately second option is quite difficult because pull-up resistor has to be disabled during data transfer…
From this point of view your propose looks reasonable.
In fact CMD13 should be common for both accesses (SD card and SPI).
Therefore we could use some code like:
command.COMMAND = ESDHC_CREATE_CMD(13, ESDHC_COMMAND_TYPE_NORMAL, ESDHC_COMMAND_RESPONSE_R2, ESDHC_COMMAND_NONE_FLAG);
command.ARGUMENT = 0;
command.BLOCKS = 0;
if (ESDHC_OK != ioctl (sdcard_ptr->COM_DEVICE, IO_IOCTL_ESDHC_SEND_COMMAND, &command))
{
return IO_ERROR;
}
Unfortunately I am not expert for SD card communication. It just shot from hip.
Additionally I would like to recommend use it only in case when ESDHC is not used. For that case we should use sdcard semaphore:
_lwsem_wait(&sdcard_ptr->LWSEM);
//check SDcard status code
_lwsem_post(&sdcard_ptr->LWSEM);
I hope it helps you.
Have a great day,
RadekS
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------