SDCard card detect and write protect pins

KanyeKanye
Posts: 54
Joined: Mon Dec 05, 2016 12:34 am

SDCard card detect and write protect pins

Postby KanyeKanye » Thu Feb 23, 2017 10:58 pm

How to use gpio_cd and gpio_wp?
I am unable to find it anywhere else but inside sdmmc_host_init_slot.

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: SDCard card detect and write protect pins

Postby ESP_Angus » Thu Feb 23, 2017 11:47 pm

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.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: SDCard card detect and write protect pins

Postby WiFive » Fri Feb 24, 2017 7:14 am

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.

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: SDCard card detect and write protect pins

Postby ESP_igrr » Fri Feb 24, 2017 7:25 am

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.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: SDCard card detect and write protect pins

Postby WiFive » Fri Feb 24, 2017 8:53 am

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.

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: SDCard card detect and write protect pins

Postby ESP_igrr » Fri Feb 24, 2017 9:10 am

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.

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Re: SDCard card detect and write protect pins

Postby snahmad75 » Fri Nov 09, 2018 3:00 pm

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

Who is online

Users browsing this forum: No registered users and 148 guests