[Ovmsdev] SD CARD

Mark Webb-Johnson mark at webb-johnson.net
Tue Nov 7 21:11:46 HKT 2017


Edward, Steve: thanks for your feedback.

I made some progress. It turns out that the stuck-in-download-mode-after-flashing issue is caused by the SD CARD itself (not GPIO0 as I had thought). If I flash with the SD CARD inserted, I get that issue. If I remove the SD CARD, then reset, the module boots fine. I can then re-insert the SD CARD and everything is fine until next time I flash.

So, something in the SD CARD itself is pulling down GPIO2, after flashing. That is D0, and very bizarre.

However, I think that is a workable compromise; we can’t flash with an SD CARD inserted.

I guess I can play around with the pull-up resistor size on D0 to see if I can improve on this, but I’m willing to live with that compromise.

So, it is working now on breadboard in 1 line mode.

I’m now going to move on to trying to get it to work with our external SPI flash arrangement, and 1 line mode. I have a breadboard already setup for that - just some re-wiring to be done.

If that works, I’ll try 4 line mode.

Onwards…

Mark.

> On 6 Nov 2017, at 1:27 PM, Mark Webb-Johnson <mark at webb-johnson.net> wrote:
> 
> Some more notes on this:
> 
> Back to basics. I made a simple breadboard using standard Espressif code (attached) and a Geikcreit development board.
> 
> Wiring is GPIO14 -> CLK, GPIO15->CMD, CPIO2->D0, GPIO0->GPIO2 link, GND and 3.3V. 10K Pullups on CLK, CMD, D0 and D3. Software is set to 1bit SD mode.
> 
> If I plug-in USB power, start monitor terminal, all works perfectly:
> 
> I (276) example: Initializing SD card
> I (276) example: Using SDMMC peripheral
> Name: SC16G
> Type: SDHC/SDXC
> Speed: default speed
> Size: 15193MB
> CSD: ver=1, sector_size=512, capacity=31116288 read_bl_len=9
> SCR: sd_spec=2, bus_width=5
> I (356) example: Opening file
> I (366) example: File written
> I (376) example: Renaming file
> I (376) example: Reading file
> I (376) example: Read from file: 'Hello SC16G!'
> I (376) example: SD CARD test starts...
> I (386) example: SD CARD written 0/2048
> I (526) example: SD CARD written 128/2048
> I (676) example: SD CARD written 256/2048
> I (816) example: SD CARD written 384/2048
> I (956) example: SD CARD written 512/2048
> I (1106) example: SD CARD written 640/2048
> I (1246) example: SD CARD written 768/2048
> I (1386) example: SD CARD written 896/2048
> I (1526) example: SD CARD written 1024/2048
> I (1676) example: SD CARD written 1152/2048
> I (1816) example: SD CARD written 1280/2048
> I (1966) example: SD CARD written 1408/2048
> I (2106) example: SD CARD written 1536/2048
> I (2246) example: SD CARD written 1664/2048
> I (2396) example: SD CARD written 1792/2048
> I (2546) example: SD CARD written 1920/2048
> I (2686) example: Cleaning up
> I (2696) example: Card unmounted
> 
> In that case, GPIO0/GPIO2 has 2.567v. Pressing BOOT key brings GPIO0/GPIO2 to 0v, and back to 2.567v when release the button. During SDCARD test, GPIO0/GPIO2 is at around 0.682v.
> 
> With monitor connected, if I flash, GPIO0/GPIO2 is 0.323v. Screen says:
> 
> rst:0x1 (POWERON_RESET),boot:0x3 (DOWNLOAD_BOOT(UART0/UART1/SDIO_REI_REO_V2))
> waiting for download
> 
> Pressing boot key goes to 0v, then releasing it goes back to 0.323v.
> 
> Pressing RESET key, no change. Stuck.
> 
> Disconnecting terminal monitor, no change. Stuck.
> 
> Reconnecting terminal monitor, no change. Stuck.
> 
> Removed link between GPIO0 and GPIO2. Now GPIO0 measures 3.3v and GPIO2 measures 0v.
> 
> Reconnection link between GPIO0 and GPIO2. Now GPIO0/GPIO2 measures 3.3v, boot ok, and SDCARD test runs ok.
> 
> So, it seems the transistor reset circuitry is not working correctly. I have tried asking on the esp32.com <http://esp32.com/> forums, but nobody answering.
> 
> Any ideas?
> 
> Regards, Mark.
> 
>> Begin forwarded message:
>> 
>> From: Mark Webb-Johnson <mark at webb-johnson.net <mailto:mark at webb-johnson.net>>
>> Subject: SD CARD
>> Date: 26 October 2017 at 10:26:01 PM HKT
>> 
>> 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>
>> 
>> <PastedGraphic-4.tiff>
>> 
>> 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>
>> 
>> <PastedGraphic-5.tiff>
>> 
>> 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>
>> 
>> <PastedGraphic-6.tiff>
>> 
>> <PastedGraphic-7.tiff>
>> 
>> 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.
> 
> _______________________________________________
> OvmsDev mailing list
> OvmsDev at lists.teslaclub.hk
> http://lists.teslaclub.hk/mailman/listinfo/ovmsdev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openvehicles.com/pipermail/ovmsdev/attachments/20171107/b49042eb/attachment.htm>


More information about the OvmsDev mailing list