[Ovmsdev] SD CARD

Mark Webb-Johnson mark at webb-johnson.net
Thu Oct 26 22:26:01 HKT 2017


Any electronics guys out there can help out with SD CARD? It is frustrating as hell. The last part of the hardware puzzle. Once we solve this, we can hit the button to start making these. China and I have been struggling with this for the last month, with little progress.

We are just following the standard Espressif schematics for this. Here is Espressif’s master document on it:

https://github.com/espressif/esp-idf/tree/master/examples/storage/sd_card <https://github.com/espressif/esp-idf/tree/master/examples/storage/sd_card>

Our circuit has been built for 4 wire SD mode, using the standard pins and pullups (as documented by Espressif). Result is that it is unreliable. Fails to mount 90% of SD CARDS, and those that do mount fail and corrupt data when writing lots of data out.

The core problem (we think) is that the GPIO2 and GPIO12 pins used for SD CARD are also required to be at specific values during boot (to select different boot modes). Espressif suggest to work around this using the transistor logic they have for controlling boot mode pins using the USB-to-serial converter and DTR + RTS async control pins.

We want 4-wire, but let’s start with a simple 1-wire diagram on a breadboard (as per Espressif instructions):

ESP32 pin	SD card pin	SPI pin	Notes
GPIO14 (MTMS)	CLK	SCK	10k pullup in SD mode
GPIO15 (MTDO)	CMD	MOSI	10k pullup, both in SD and SPI modes
GPIO2	D0	MISO	10k pullup in SD mode, pull low to go into download mode (see note below!)
GPIO4	D1	N/C	not used in 1-line SD mode; 10k pullup in 4-line SD mode
GPIO12 (MTDI)	D2	N/C	not used in 1-line SD mode; 10k pullup in 4-line SD mode (see note below!)
GPIO13 (MTCK)	D3	CS	not used in 1-line SD mode, but card's D3 pin must have a 10k pullup
N/C	CD		optional, not used in the example
N/C	WP		optional, not used in the example

Also:
Connect GPIO0 and GPIO2 using a jumper (so transistors drive GPIO2 and GPIO0 low when entering download mode (10K pullup otherwise)
3.3V connect to SDCARD
GND connect to SDCARD

We have a variety of ESP32 development modules to try this with. Espressif said that the original DEVKIT C had a problem with the boot pin control lines and transistor logic (but never said what exactly that problem was).

With original (old) ESP32 DEVKIT C, I can’t get it to work reliably at all. Sometimes ok. Sometimes not. With OVMS test code (that writes a lot of data), it never works.

With our OVMS boards, all versions, I can’t get it to work reliably at all. Sometimes ok. Sometimes not. With OVMS test code (that writes a lot of data), it never works.

I don’t think it ever worked. Just before our test was so simple that it didn’t show the problem.

So, I just purchased one of these:

https://www.banggood.com/ESP32-Development-Board-WiFiBluetooth-Ultra-Low-Power-Consumption-Dual-Cores-ESP-32-ESP-32S-Board-p-1109512.html <https://www.banggood.com/ESP32-Development-Board-WiFiBluetooth-Ultra-Low-Power-Consumption-Dual-Cores-ESP-32-ESP-32S-Board-p-1109512.html>

Geekcreit® ESP32 Development Board WiFi+Bluetooth Ultra Low Power Consumption Dual Cores ESP-32 ESP-32S Board

(Very similar to DEVKIT C, but more modern)

It works 100%. Although after flashing it cannot boot (waiting for download) - need to disconnect GPIO0 - GPIO2 link, reset, then reconnect GPIO0-GPIO2 link. Then perfect.

I think our problem is related to that transistor auto-flash reset circuitry. GPIO2 is the line for data transfer, so if problem will cause data corruption and unreliable (like we are seeing).

Espressif SD CARD notes here:

https://github.com/espressif/esp-idf/tree/master/examples/storage/sd_card <https://github.com/espressif/esp-idf/tree/master/examples/storage/sd_card>

Schematic for Geekcreit board is here:

https://www.dropbox.com/s/jefwxxtufgwg0ex/esp32_Schematic%20Prints.pdf?dl=0 <https://www.dropbox.com/s/jefwxxtufgwg0ex/esp32_Schematic%20Prints.pdf?dl=0>



Schematic for latest version of Espressif DEVKIT C board is here:

http://espressif.com/sites/default/files/documentation/esp32_hardware_design_guidelines_en.pdf <http://espressif.com/sites/default/files/documentation/esp32_hardware_design_guidelines_en.pdf>



The original DEVKIT C (v1) had 1K resistors on that circuit. This is the version I have.

The Geekcreit has 10K resistors on that circuit.

OVMS has 10K resistors on that circuit.

The latest DEVKIT C (v3) has 12K resistors on that circuit.

DEVKIT C v1 schematic is here: http://dl.espressif.com/dl/schematics/ESP32-DevKitJ-v1_sch.pdf <http://dl.espressif.com/dl/schematics/ESP32-DevKitJ-v1_sch.pdf>
DEVKIT C v2 schematic is here: http://dl.espressif.com/dl/schematics/ESP-WROVER-KIT_SCH-2.pdf <http://dl.espressif.com/dl/schematics/ESP-WROVER-KIT_SCH-2.pdf>

The latest Espressif ROVER KIT development board schematic is here:

https://dl.espressif.com/dl/schematics/ESP-WROVER-KIT_SCH-3.pdf <https://dl.espressif.com/dl/schematics/ESP-WROVER-KIT_SCH-3.pdf>





Note that they are now using 100K resistors, and a separate transistor on IO0 (to allow it to be independently controlled after boot).

I am reasonably certain our SD CARD problem concerns the GPIO0-GPIO2 link.

Can you look at these, and see if you can find the difference? Apart from resistor sizes (which Espressif keep messing around with), I can’t see the practical difference.

Regards, Mark.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openvehicles.com/pipermail/ovmsdev/attachments/20171026/0794c84d/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PastedGraphic-4.tiff
Type: image/tiff
Size: 133904 bytes
Desc: not available
URL: <http://lists.openvehicles.com/pipermail/ovmsdev/attachments/20171026/0794c84d/attachment-0008.tiff>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PastedGraphic-5.tiff
Type: image/tiff
Size: 249576 bytes
Desc: not available
URL: <http://lists.openvehicles.com/pipermail/ovmsdev/attachments/20171026/0794c84d/attachment-0009.tiff>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PastedGraphic-6.tiff
Type: image/tiff
Size: 406092 bytes
Desc: not available
URL: <http://lists.openvehicles.com/pipermail/ovmsdev/attachments/20171026/0794c84d/attachment-0010.tiff>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PastedGraphic-7.tiff
Type: image/tiff
Size: 130884 bytes
Desc: not available
URL: <http://lists.openvehicles.com/pipermail/ovmsdev/attachments/20171026/0794c84d/attachment-0011.tiff>


More information about the OvmsDev mailing list