Page 1 of 1

SDCard card detect and write protect pins

Posted: Thu Feb 23, 2017 10:58 pm
by KanyeKanye
How to use gpio_cd and gpio_wp?
I am unable to find it anywhere else but inside sdmmc_host_init_slot.

Re: SDCard card detect and write protect pins

Posted: Thu Feb 23, 2017 11:47 pm
by ESP_Angus
If you set these pin numbers in the sdmcc_slot_config_t structure which is used to initialise the SDMMC host, then they will be used for these functions. Otherwise these functions are not used by the host.

Refer to this comment in the SDMMC example:
https://github.com/espressif/esp-idf/bl ... card.c#L31

And the relevant section in the documentation:
http://esp-idf.readthedocs.io/en/latest ... river-apis

If set, these pins will be configured as GPIO inputs by the driver during intialisation. There is not need to do separate pin configuration.

Re: SDCard card detect and write protect pins

Posted: Fri Feb 24, 2017 7:14 am
by WiFive
Within the driver will a specific error be thrown if a write operation is called and wp is on? There is an interrupt for card detect but I don't think any user callback.

Re: SDCard card detect and write protect pins

Posted: Fri Feb 24, 2017 7:25 am
by ESP_igrr
Hmm, i think we should handle WP in software, but i have just checked the code and I don't see that happening anywhere. Need to fix this, thanks for pointing this out. As a temporary workaround, please check the state of WP pin in the application before calling sdmmc driver write function.

Regarding card detect, there's no interrupt at this point. I think the application can configure an interrupt using the gpio driver (which will not interfere with SDMMC peripheral, because unlike other pins, card detect is routed via gpio mux).
Also good point on adding specific error codes for both errors.

Re: SDCard card detect and write protect pins

Posted: Fri Feb 24, 2017 8:53 am
by WiFive
https://github.com/espressif/esp-idf/bl ... ost.c#L254
https://github.com/espressif/esp-idf/bl ... ion.c#L174

But yes it could be useful as a separate gpio interrupt, although may be nice if driver detects card is removed and gracefully aborts.

Re: SDCard card detect and write protect pins

Posted: Fri Feb 24, 2017 9:10 am
by ESP_igrr
What I meant was "no interrupt callback exposed to the application", sorry for not making this clear.

I think at this point if you unplug the card during the transfer, you will eventually get a transfer timeout reported by the SD host. Handling the CD interrupt properly will make the transfer bail out faster, and we can potentially give a better error code.

Re: SDCard card detect and write protect pins

Posted: Fri Nov 09, 2018 3:00 pm
by snahmad75
Hi,

I need to detect sd card is plug out while application is running. Do we have event or interrupt handler.
I can detect using mount failure on startup. I wonder is there any method to detect failure of sd card during application is running.

Thanks,
Naeem