[Ovmsdev] SD CARD
Mark Webb-Johnson
mark at webb-johnson.net
Sat Nov 25 18:38:50 HKT 2017
Not sure about speed of the chip itself. Communications bus is the same as the flash memory (40Mhz), and caching arrangement the same.
I think speed should be comparable to flash used for program storage. But really depends on cachability.
Regards, Mark
> On 25 Nov 2017, at 2:47 PM, Stephen Casner <casner at acm.org> wrote:
>
> Mark,
>
> I presume the SPIRAM is slower. How much?
>
> -- Steve
>
>> On Thu, 23 Nov 2017, Mark Webb-Johnson wrote:
>>
>>
>> For those of you who’ve hit RAM limits, does this interest you?
>>
>> I (707) cpu_start: PSRAM mode: flash 40m sram 40m
>> I (721) cpu_start: PSRAM initialized, cache is in even/odd (2-core) mode.
>>
>> I (3512) heap_alloc_caps: SPI SRAM memory test OK
>> I (3513) heap_alloc_caps: Initializing. RAM available for dynamic allocation:
>> I (3518) heap_alloc_caps: At 3F800000 len 00400000 (4096 KiB): SPIRAM
>> I (3540) heap_alloc_caps: At 3FFAE2A0 len 00001D60 (7 KiB): DRAM
>> I (3561) heap_alloc_caps: At 3FFB2378 len 0000DC88 (55 KiB): DRAM
>> I (3582) heap_alloc_caps: At 3FFC0000 len 00008000 (32 KiB): DMAONLY
>> I (3603) heap_alloc_caps: At 3FFC8000 len 00018000 (96 KiB): DRAM
>> I (3624) heap_alloc_caps: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
>> I (3646) heap_alloc_caps: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
>> I (3667) heap_alloc_caps: At 40089434 len 00016BCC (90 KiB): IRAM
>>
>> A normal ESP32 looks like this:
>>
>> I (777) heap_alloc_caps: Initializing. RAM available for dynamic allocation:
>> I (799) heap_alloc_caps: At 3FFAE2A0 len 00001D60 (7 KiB): DRAM
>> I (819) heap_alloc_caps: At 3FFB23E0 len 0002DC20 (183 KiB): DRAM
>> I (840) heap_alloc_caps: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
>> I (861) heap_alloc_caps: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
>> I (882) heap_alloc_caps: At 400874D0 len 00018B30 (98 KiB): IRAM
>>
>> Note: Some differences caused by ESP IDF v2.1 vs v3.x.
>>
>> There are still lots of restrictions (such as stacks only being in internal RAM unless the task doesn’t use wifi, bluetooth, rom routines, etc). But, for things like CAN bus RE, logging, etc, it could be pretty useful. Now, on to wire-up a SD CARD and see if it works. Should know in a few hours...
>>
>> Regards, Mark
>>
>>> On 23 Nov 2017, at 1:50 PM, Mark Webb-Johnson <mark at webb-johnson.net> wrote:
>>>
>>> An update on SD card issues.
>>>
>>> We’ve (finally) narrowed down the problem. It seems our wiring is fine, pull-ups are fine, and software is as expected. No problem with interference, or power supply.
>>>
>>> The issue seems to be a conflict in the ESP IDF (probably bootloader, or ESP hardware) when using our external 16MB flash. Flash memory in the ESP32 is controlled over an SPI bus. We use the same SPI bus pins as the standard on-board flash, but a different CS (Chip Select) line (GPIO22 vs SD3 pin #19 for the standard 4MB flash chip). We burn fuses to tell the ESP32 to use our flash CS line (rather than the built-in one). That’s it. Nothing special, and no pin conflicts. We think some other conflict between the SD CARD and SPI hardware in the ESP-32 chip (perhaps requiring special handling in the bootloader / library code).
>>>
>>> Now, when OVMS is using this external flash, and accessing SD CARD, it becomes unreliable. It may seem fine, but read/write a lot and it fails. Replace the WROOM-32 module with one without efuses burnt (using internal 4MB flash), and the SD CARD goes back to working normally.
>>>
>>> I’ve finally (god, this has been frustrating) got someone at Espressif to recognise the problem and they are trying to re-create. The solution may be resolvable in bootloader code (best case), or may require a hardware fix. Whichever, we are close.
>>>
>>> While researching workarounds, and bearing in mind the latest ESP32 WROVER modules offering external PSRAM (SPI RAM; to expand RAM space in a similar way to external flash expands code space), I found a company called AnalogLamb <https://www.analoglamb.com/product/alb32-wrover-esp32-module-with-64mb-flash-and-32mb-psram/> These guys make a pin-compatible WROOM32 module including different size FLASH and PSRAM chips. We can get a module with 16MB flash and 4MB PSRAM - giving us the flash space we need, and another 4MB of heap space in RAM. It is not quite a drop-in replacement, as GPIO16+17 are used for the PSRAM (so we would have to move the GPIOs used for our modem), and the PSRAM requires the latest ESP IDF version (which brings other issues with it), but it seems to be a workable solution. I’ve gotten a hold of two sample modules (just arrived today) and will be trying them tonight. I’ll let you know how it works out.
>>>
>>> Regards, Mark.
>>>
>>> <IMG_5655.jpeg>
>>>
>>>> On 7 Nov 2017, at 9:11 PM, Mark Webb-Johnson <mark at webb-johnson.net <mailto:mark at webb-johnson.net>> wrote:
>>>>
>>>> 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 <mailto: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 <mailto:OvmsDev at lists.teslaclub.hk>
>>>>> http://lists.teslaclub.hk/mailman/listinfo/ovmsdev <http://lists.teslaclub.hk/mailman/listinfo/ovmsdev>
>>>>
>>>> _______________________________________________
>>>> OvmsDev mailing list
>>>> OvmsDev at lists.teslaclub.hk <mailto:OvmsDev at lists.teslaclub.hk>
>>>> http://lists.teslaclub.hk/mailman/listinfo/ovmsdev
>>>
>>
> _______________________________________________
> OvmsDev mailing list
> OvmsDev at lists.teslaclub.hk
> http://lists.teslaclub.hk/mailman/listinfo/ovmsdev
More information about the OvmsDev
mailing list