Inhoudsopgave:

Selecteer SD-interface voor ESP32: 12 stappen (met afbeeldingen)
Selecteer SD-interface voor ESP32: 12 stappen (met afbeeldingen)

Video: Selecteer SD-interface voor ESP32: 12 stappen (met afbeeldingen)

Video: Selecteer SD-interface voor ESP32: 12 stappen (met afbeeldingen)
Video: Home Assistant - подключаем адресную ленту WS2812B через ESP8266 с прошивкой WLED 2024, Juli-
Anonim
Selecteer SD-interface voor ESP32
Selecteer SD-interface voor ESP32

Deze instructables laten iets zien over het selecteren van een SD-interface voor uw ESP32-project.

Stap 1: SD-interface

In de originele Arduino SD-bibliotheek gebruikt de SD-interface de SD SPI-busoverdrachtsmodus.

SD heeft eigenlijk meer overdrachtsmodus:

  • SPI-busmodus: ESP32 heeft meer dan 1 SPI-bus, deze kan worden aangepast tijdens initialisatie
  • 1-bit / 4-bit SD-busmodus: ESP32 wijdt een andere bibliotheek genaamd SD_MMC aan om de SD-busmodus-API te implementeren
  • SD UHS-II-modus: ESP32 niet ondersteund

ref.:

www.arduino.cc/en/reference/SD

en.wikipedia.org/wiki/SD_card

docs.espressif.com/projects/esp-idf/en/lat…

Stap 2: ESP32 GPIO-pinnen in kaart brengen

Dit zijn de standaard ESP32 GPIO-pinnentoewijzing:

SD-kaartpin MicroSD-pin Naam 4-bit SD-bus 1-bit SD-bus SPI-bus (HSPI / VSPInative pinnen)
1 2 D3 13 - RVS (15 / 5)
2 3 CMD 15 15 MOSI (13 / 23)
3 - VSS GND GND GND
4 4 VDD 3,3V 3,3V 3,3V
5 5 CLK 14 14 SCK (14 / 18)
6 6 VSS GND GND GND
7 7 D0 2 2 MISO (12 / 19)
8 8 D1 4 - -
9 1 D2 12 - -

De GPIO-pinnentoewijzing van de 1-bit / 4-bit SD-bus kan niet worden gewijzigd.

Eenvoudige oproep SD_MMC begin() naar initiële 4-bit SD-busmodus:

SD_MMC.begin();

1-bit SD-busmodus kan worden geselecteerd bij de SD_MMC begin()-methode, b.v.

SD_MMC.begin("/cdcard", true);

De SPI-bus (HSPI of VSPI) kan worden geselecteerd tijdens het maken van de SPIClass-instantie, b.v.

SPIKlasse spi = SPIKlasse(HSPI);

Zoals u kunt zien, deelt u 1-bit / 4-bit SD-buspin-pinnen met HSPI, maar de toewijzing van SD-kaartpinnen is niet hetzelfde. Dus als de hardware is aangesloten volgens de SD-bus-pinkaart, kan deze geen directe HSPI-native pinnen gebruiken. De GPIO-pinnen kunnen worden overschreven bij de SPIClass begin()-methode, b.v.

SPIKlasse spi = SPIKlasse(HSPI);

spi.begin (14 /* SCK */, 2 /* MISO */, 15 /* MOSI */, 13 /* SS */);

En ook de SD-bibliotheek kan de SS-pin, SPI-bus en busfrequentie overschrijven bij de SD begin()-methode, b.v.

SD.begin(13 /* SS */, spi, 80000000);

Stap 3: SD Pull-up-vereisten

Als u de 4-bit SD-busmodus wilt gebruiken, volg dan de ESP32 SD Pull-up-vereisten, met name:

  • Pull-upconflicten op GPIO13
  • Conflicten tussen Bootstrap en SDIO op DAT2

ref.:

docs.espressif.com/projects/esp-idf/en/lat…

Stap 4: Diverse hardware

Diverse hardware
Diverse hardware

ESP32 heeft tonnen dev-kit en dev-board, sommige hebben een ingebouwde MicroSD-kaartsleuf.

Hier zijn enkele voorbeelden in mijn hand:

  • TTGO T-Watch, het is verbonden met GPIO-pinnen 2, 13, 14 en 15 volgens 1-bit SD-busmodus, dus het kan 1-bit SD-busmodus en SPI-busmodus gebruiken
  • M5Stack-serie, het is aangesloten op GPIO-pinnen 4, 18, 19 en 23 volgens VSPI-native pinnen, zodat het standaard SD-bibliotheekinstellingen kan gebruiken [SD.begin(4)]
  • ODROID-GO, het is aangesloten op GPIO-pinnen 18, 19, 22 en 23 volgens VSPI-native pinnen, dus het kan standaard SD-bibliotheekinstellingen gebruiken [SD.begin (22)]
  • ESP32-CAM, het is aangesloten op GPIO-pinnen 2, 4, 12, 13, 14 en 15 volgens 4-bit SD-busmodus, dus het kan alle 4-bit / 1-bit SD-busmodus en SPI-busmodus gebruiken
  • TTGO T8-ontwikkelbord, het is aangesloten op GPIO-pinnen 2, 13, 14 en 15 volgens 1-bit SD-busmodus, dus het kan 1-bit SD-busmodus en SPI-busmodus gebruiken

www.lilygo.cn/prod_view.aspx?Id=1123

docs.m5stack.com/

wiki.odroid.com/odroid_go/odroid_go

wiki.ai-thinker.com/esp32-cam

github.com/LilyGO/TTGO-T8-ESP32

Stap 5: SD-kaartsleuf Breakout Board

Breakout-kaart voor SD-kaartsleuf
Breakout-kaart voor SD-kaartsleuf
Breakout-kaart voor SD-kaartsleuf
Breakout-kaart voor SD-kaartsleuf

Dev-kaart met ingebouwde MicroSD-kaartsleuf is mogelijk niet op alle pinnen aangesloten en de meeste kunnen geen 4-bit SD-busmodus gebruiken. Een afzonderlijk breakout-bord voor SD-kaartslots zorgt voor meer flexibiliteit.

Tegelijkertijd breken veel LCD-breakoutboards ook een SD-kaartsleuf van volledige grootte uit. De meeste van hen breken echter alleen de SPI-moduspinnen uit. Het is niet voldoende om als 4-bit SD-busmodus te gebruiken, maar u kunt het nog steeds gebruiken als 1-bit SD-busmodus door deze verbindingstoewijzing:

LCD -> ESP32

SD_CS -> nul SD_MOSI -> 15 SD_MISO -> 2 SD_SCK -> 14

Stap 6: GPIO 2 loskoppelen tijdens het programma

GPIO 2 loskoppelen tijdens programma
GPIO 2 loskoppelen tijdens programma

De 4-bit SD-busmodusverbinding zorgde ervoor dat ESP32 niet in de programmeermodus kon komen. Onthoud dat u de GPIO 2 loskoppelt van de SD-kaartsleuf-breakout-kaart DAT0 voordat u een nieuw programma uploadt.

Stap 7: Benchmark

Benchmark
Benchmark
Benchmark
Benchmark

Ik heb een eenvoudig Arduino-programma geschreven voor de benchmark:

github.com/moononournation/ESP32_SD_Benchm…

Hier zijn de hardware voor de benchmark:

ESP32

NodeMCU ESP32-32S V1.1 (WROOM-32)

SD-kaartsleuf

Een MicroSD-kaartslot breakout-kaart

SD-kaart

Ik heb een SanDisk 8 GB MicroSD en een oude 128 MB MicroSD in de hand.

Stap 8: SD_MMC 4-bits modusbenchmark

SanDisk 8 GB MicroSD

20:27:46.000 -> Test schrijven /test_1k.bin

20:27:59.399 -> Gebruikt schrijfbestand: 13404 ms, 312.914368 KB/s 20:27:59.399 -> Test schrijven /test_2k.bin 20:28:17.248 -> Gebruikt schrijfbestand: 17834 ms, 235.185822 KB/s 20:28:17.248 -> Test schrijven /test_4k.bin 20:28:21.122 -> Gebruikt schrijfbestand: 3873 ms, 1082.959961 KB/s 20:28:21.122 -> Test schrijven /test_8k.bin 20:28:23.147 -> Gebruikt schrijfbestand: 2024 ms, 2072.284668 KB/s 20:28:23.147 -> Test schrijven /test_16k.bin 20:28:27.237 -> Gebruikt schrijfbestand: 4097 ms, 1023.750061 KB/s 20:28:27.237 -> Test schrijven /test_32k.bin 20:28:30.088 -> Gebruikt schrijfbestand: 2842 ms, 1475.828247 KB/s 20:28:30.088 -> Test schrijven /test_64k.bin 20:28:31.882 -> Gebruikt schrijfbestand: 1811 ms, 2316.015381 KB/s 20:28:31.882 -> Test lezen /test_1k.bin 20:28:35.422 -> Leesbestand gebruikt: 3520 ms, 1191.563599 KB/s 20:28:35.422 -> Test lezen /test_2k.bin 20: 28:38.813 -> Lees bestand gebruikt: 3389 ms, 1237.622925 KB/s 20:28:38.813 -> Test lees /test_4k.bin 20:28:42.273 -> Lees bestand gebruikt: 3474 ms, 1207.341431 KB/s 20:28:42.273 -> Test lezen /test_8k.bin 20:28:45.752 - > Gebruikt bestand lezen: 3487 ms, 1202.840210 KB/s 20:28:45.752 -> Test lezen /test_16k.bin 20:28:48.988 -> Gebruikt bestand lezen: 3213 ms, 1305.416748 KB/s 20:28:48.988 -> Test lezen /test_32k.bin 20:28:52.077 -> Lees bestand gebruikt: 3093 ms, 1356.063354 KB/s 20:28:52.077 -> Test lezen /test_64k.bin 20:28:55.141 -> Lees bestand gebruikt: 3080 ms, 1361,786987 KB/s

Oude 128 MB MicroSD

20:30:43.309 -> E (274) sdmmc_sd: sdmmc_check_scr: send_scr geretourneerd 0x109

20:30:43.309 -> Kaart koppelen mislukt

Stap 9: SD_MMC 1-bit modusbenchmark

SanDisk 8 GB MicroSD

20:31:45.194 -> Test schrijven /test_1k.bin

20:31:59.506 -> Gebruikt schrijfbestand: 14325 ms, 292.796082 KB/s 20:31:59.506 -> Test schrijven /test_2k.bin 20:32:17.686 -> Gebruikt schrijfbestand: 18163 ms, 230.925735 KB/s 20:32:17.686 -> Test schrijven /test_4k.bin 20:32:21.291 -> Gebruikt schrijfbestand: 3611 ms, 1161.535278 KB/s 20:32:21.291 -> Test schrijven /test_8k.bin 20:32:23.939 -> Gebruikt schrijfbestand: 2652 ms, 1581.562622 KB/s 20:32:23.939 -> Test schrijven /test_16k.bin 20:32:28.397 -> Gebruikt schrijfbestand: 4448 ms, 942.964050 KB/s 20:32:28.397 -> Test schrijven /test_32k.bin 20:32:31.835 -> Gebruikt schrijfbestand: 3429 ms, 1223.185791 KB/s 20:32:31.835 -> Test schrijven /test_64k.bin 20:32:33.882 -> Gebruikt schrijfbestand: 2058 ms, 2038.048584 KB/s 20:32:33.882 -> Test lezen /test_1k.bin 20:32:38.031 -> Lees bestand gebruikt: 4146 ms, 1011.650757 KB/s 20:32:38.031 -> Test lezen /test_2k.bin 20: 32:42.062 -> Gebruikt bestand lezen: 4019 ms, 1043.618774 KB/s 20:32:42.062 -> Test lezen /test_4k.bin 20:32:46.170 -> Gebruikt bestand lezen: 4106 ms, 1021.506104 KB/s 20:32:46.170 -> Test lezen /test_8k.bin 20:32:50.288 -> Gebruikt bestand lezen: 4121 ms, 1017.787903 KB/s 20:32:50.288 -> Test lezen /test_16k.bin 20:32:54.112 -> Gebruikt bestand lezen: 3840 ms, 1092.266724 KB/s 20:32:54.112 -> Test read /test_32k.bin 20:32:57.840 -> Lees bestand gebruikt: 3739 ms, 1121.771606 KB/s 20:32:57.840 -> Test lees /test_64k.bin 20:33:01.568 -> Lees bestand gebruikt: 3711 ms, 1130.235474 KB/s

Oude 128 MB MicroSD

20:33:27.366 -> Test schrijven /test_1k.bin

20:33:42.386 -> Gebruikt schrijfbestand: 15020 ms, 279.247925 KB/s 20:33:42.386 -> Test schrijven /test_2k.bin 20:33:57.927 -> Gebruikt schrijfbestand: 15515 ms, 270.338654 KB/s 20:33:57.927 -> Test schrijven /test_4k.bin 20:34:13.108 -> Gebruikt schrijfbestand: 15195 ms, 276.031860 KB/s 20:34:13.108 -> Test schrijven /test_8k.bin 20:34:28.162 -> Gebruikt schrijfbestand: 15048 ms, 278.728333 KB/s 20:34:28.162 -> Test schrijven /test_16k.bin 20:34:43.287 -> Gebruikt schrijfbestand: 15142 ms, 276.998016 KB/s 20:34:43.287 -> Test schrijven /test_32k.bin 20:34:58.278 -> Gebruikt schrijfbestand: 14964 ms, 280.292969 KB/s 20:34:58.278 -> Test schrijven /test_64k.bin 20:35:13.370 -> Gebruikt schrijfbestand: 15101 ms, 277.750092 KB/s 20:35:13.370 -> Test lezen /test_1k.bin 20:35:17.563 -> Lees bestand gebruikt: 4197 ms, 999.357666 KB/s 20:35:17.563 -> Test lezen /test_2k.bin 20: 35:21.746 -> Gebruikt bestand lezen: 4191 ms, 1000.788330 KB/s 20:35:21.746 -> Test lezen /test_4k.bin 20:35:25.942 -> Gebruikt bestand lezen: 4181 ms, 1003.182007 KB/s 20:35:25.942 -> Test lezen /test_8k.bin 20:35:30.101 -> Gebruikt bestand lezen: 4176 ms, 1004.383118 KB/s 20:35:30.101 -> Test lezen /test_16k.bin 20:35:34.279 -> Gebruikt bestand lezen: 4174 ms, 1004.864380 KB/s 20:35:34.279 -> Test lezen /test_32k.bin 20:35:38.462 -> Gebruikt bestand lezen: 4173 ms, 1005.105225 KB/s 20:35:38.462 -> Test lezen /test_64k.bin 20:35:42.612 -> Gebruikt bestand lezen: 4173 ms, 1005.105225 KB/s

Stap 10: SD SPI-modus bij HSPI Bus Benchmark

SanDisk 8 GB MicroSD

08:41:19.703 -> Test schrijven /test_1k.bin

08:41:53.458 -> Gebruikt schrijfbestand: 33743 ms, 124.301453 KB/s 08:41:53.458 -> Test schrijven /test_2k.bin 08:42:10.000 -> Gebruikt schrijfbestand: 16540 ms, 253.585495 KB/s 08:42:10.000 -> Test schrijven /test_4k.bin 08:42:17.269 -> Gebruikt schrijfbestand: 7298 ms, 574.719666 KB/s 08:42:17.308 -> Test schrijven /test_8k.bin 08:42:22.640 -> Gebruikt schrijfbestand: 5345 ms, 784.715454 KB/s 08:42:22.640 -> Test schrijven /test_16k.bin 08:42:32.285 -> Gebruikt schrijfbestand: 9662 ms, 434.103088 KB/s 08:42:32.285 -> Test schrijven /test_32k.bin 08:42:36.659 -> Gebruikt schrijfbestand: 4355 ms, 963.10830 KB/s 08:42:36.659 -> Test schrijven /test_64k.bin 08:42:39.594 -> Gebruikt schrijfbestand: 2949 ms, 1422.280151 KB/s 08:42:39.594 -> Test lezen /test_1k.bin 08:42:44.774 -> Lees bestand gebruikt: 5192 ms, 807.839783 KB/s 08:42:44.774 -> Test lezen /test_2k.bin 08: 42:49.969 -> Leesbestand gebruikt: 5189 ms, 808.306824 KB/s 08:42:49.969 -> Test lezen /test_4k.bin 08:42:55.123 -> Leesbestand gebruikt: 5161 ms, 812.692139 KB/s 08:42:55.158 -> Test lezen /test_8k.bin 08:43:00.300 -> Lezen gebruikt bestand: 5176 ms, 810.336914 KB/s 08:43:00.334 -> Test lezen /test_16k.bin 08:43:05.277 -> Lees bestand gebruikt: 4948 ms, 847.676636 KB/s 08:43:05.277 -> Test lezen /test_32k.bin 08:43:10.028 -> Gebruikt bestand lezen: 4773 ms, 878.756348 KB/s 08:43:10.028 -> Lezen testen /test_64k.bin 08:43:14.760 -> Gebruikt bestand lezen: 4731 ms, 886.557617 KB/s

Oude 128 MB MicroSD

08:43:47.777 -> Test schrijven /test_1k.bin

08:44:04.148 -> Gebruikt schrijfbestand: 16390 ms, 255.906281 KB/s 08:44:04.183 -> Test schrijven /test_2k.bin 08:44:20.648 -> Gebruikt schrijfbestand: 16494 ms, 254.292709 KB/s 08:44:20.648 -> Test schrijven /test_4k.bin 08:44:36.674 -> Gebruikt schrijfbestand: 16001 ms, 262.127625 KB/s 08:44:36.674 -> Test schrijven /test_8k.bin 08:44:52.849 -> Gebruikt schrijfbestand: 16175 ms, 259.307831 KB/s 08:44:52.849 -> Test schrijven /test_16k.bin 08:45:09.225 -> Gebruikt schrijfbestand: 16397 ms, 255.797043 KB/s 08:45:09.225 -> Test schrijven /test_32k.bin 08:45:25.363 -> Gebruikt schrijfbestand: 16143 ms, 259.821838 KB/s 08:45:25.397 -> Test schrijven /test_64k.bin 08:45:41.632 -> Gebruikt schrijfbestand: 16263 ms, 257.904694 KB/s 08:45:41.632 -> Test lezen /test_1k.bin 08:45:46.488 -> Lees bestand gebruikt: 4856 ms, 863.736389 KB/s 08:45:46.488 -> Test lezen /test_2k.bin 08: 45:51.332 -> Gebruikt bestand lezen: 4840 ms, 866.591736 KB/s 08:45:51.332 -> Test lezen /test_4k.bin 08:45:56.163 -> Gebruikt bestand lezen: 4834 ms, 867.667358 KB/s 08:45:56.163 -> Test lezen /test_8k.bin 08:46:00.998 -> R ead-bestand gebruikt: 4827 ms, 868.925598 KB/s 08:46:00.998 -> Test lezen /test_16k.bin 08:46:05.808 -> Leesbestand gebruikt: 4825 ms, 869.285828 KB/s 08:46:05.843 -> Test read /test_32k.bin 08:46:10.637 -> Gebruikt bestand lezen: 4824 ms, 869.466003 KB/s 08:46:10.637 -> Test lezen /test_64k.bin 08:46:15.478 -> Gebruikt bestand lezen: 4825 ms, 869,285828 KB/s

Stap 11: SD SPI-modus bij VSPI Bus Benchmark

SanDisk 8 GB MicroSD

08:54:17.412 -> Test schrijven /test_1k.bin

08:54:48.398 -> Gebruikt schrijfbestand: 30994 ms, 135.326324 KB/s 08:54:48.398 -> Test schrijven /test_2k.bin 08:55:06.079 -> Gebruikt schrijfbestand: 17677 ms, 237.274658 KB/s 08:55:06.079 -> Test schrijven /test_4k.bin 08:55:13.357 -> Gebruikt schrijfbestand: 7274 ms, 576.615906 KB/s 08:55:13.357 -> Test schrijven /test_8k.bin 08:55:18.691 -> Gebruikt schrijfbestand: 5323 ms, 787.958679 KB/s 08:55:18.691 -> Test schrijven /test_16k.bin 08:55:28.336 -> Gebruikt schrijfbestand: 9669 ms, 433.788818 KB/s 08:55:28.336 -> Test schrijven /test_32k.bin 08:55:32.646 -> Gebruikt schrijfbestand: 4309 ms, 973.382202 KB/s 08:55:32.646 -> Test schrijven /test_64k.bin 08:55:35.551 -> Gebruikt schrijfbestand: 2915 ms, 1438.869263 KB/s 08:55:35.584 -> Test lezen /test_1k.bin 08:55:40.745 -> Lees bestand gebruikt: 5183 ms, 809.242554 KB/s 08:55:40.745 -> Test lezen /test_2k.bin 08: 55:45.916 -> Gebruikt bestand lezen: 5182 ms, 809.398682 KB/s 08:55:45.949 -> Test lezen /test_4k.bin 08:55:51.091 -> Gebruikt bestand lezen: 5162 ms, 812.534668 KB/s 08:55:51.091 -> Test lezen /test_8k.bin 08:55:56.257 -> Lezen gebruikt bestand: 5177 ms, 810.180420 KB/s 08:55:56.293 -> Test lezen /test_16k.bin 08:56:01.244 -> Lezen gebruikt bestand: 4956 ms, 846.308289 KB/s 08:56:01.244 -> Test lezen /test_32k.bin 08:56:06.006 -> Gebruikt bestand lezen: 4764 ms, 880.416443 KB/s 08:56:06.006 -> Lezen testen /test_64k.bin 08:56:10.716 -> Gebruikt bestand lezen: 4728 ms, 887.120117 KB/s

Oude 128 MB MicroSD

08:51:01.939 -> Test schrijven /test_1k.bin

08:51:18.358 -> Gebruikt schrijfbestand: 16422 ms, 255.407623 KB/s 08:51:18.358 -> Test schrijven /test_2k.bin 08:51:34.529 -> Gebruikt schrijfbestand: 16173 ms, 259.339874 KB/s 08:51:34.529 -> Test schrijven /test_4k.bin 08:51:50.911 -> Gebruikt schrijfbestand: 16372 ms, 256.187653 KB/s 08:51:50.911 -> Test schrijven /test_8k.bin 08:52:07.056 -> Gebruikt schrijfbestand: 16137 ms, 259.918457 KB/s 08:52:07.056 -> Test schrijven /test_16k.bin 08:52:23.383 -> Gebruikt schrijfbestand: 16351 ms, 256.516663 KB/s 08:52:23.383 -> Test schrijven /test_32k.bin 08:52:39.533 -> Gebruikt schrijfbestand: 16128 ms, 260.063507 KB/s 08:52:39.533 -> Test schrijven /test_64k.bin 08:52:55.764 -> Gebruikt schrijfbestand: 16250 ms, 258.111023 KB/s 08:52:55.764 -> Test lezen /test_1k.bin 08:53:00.645 -> Lees bestand gebruikt: 4855 ms, 863.914307 KB/s 08:53:00.645 -> Test lezen /test_2k.bin 08: 53:05.459 -> Gebruikt bestand lezen: 4839 ms, 866.770813 KB/s 08:53:05.459 -> Test lezen /test_4k.bin 08:53:10.306 -> Gebruikt bestand lezen: 4833 ms, 867.846863 KB/s 08:53:10.306 -> Test lezen /test_8k.bin 08:53:15.127 -> R ead-bestand gebruikt: 4827 ms, 868.925598 KB/s 08:53:15.127 -> Test lezen /test_16k.bin 08:53:19.963 -> Gebruikt bestand lezen: 4826 ms, 869.105652 KB/s 08:53:19.963 -> Test lees /test_32k.bin 08:53:24.758 -> Lees bestand gebruikt: 4824 ms, 869.466003 KB/s 08:53:24.792 -> Test lees /test_64k.bin 08:53:29.592 -> Lees bestand gebruikt: 4824 ms, 869.466003 KB/s

Stap 12: naar boven afronden

4-bit SD-busmodus heeft de beste prestaties, 1-bit SD-busmodus is ongeveer 20% langzamer en SPI-modus is ongeveer 50% langzamer. Een van de belangrijkste redenen is dat de SD_MMC-protocollaag geen enkele vorm van vergrendeling implementeert, maar SPI wel. En ook de 4-bit SD-busmodus heeft dubbele datalijnen, dus theoretisch de dubbele snelheid. Maar mijn oude MicroSD ondersteunt geen 4-bit SD-busmodus.

Ik zal in de meeste gevallen de 1-bit SD-busmodus aanbevelen, omdat:

  • goed optreden
  • betere compatibiliteit met SD-kaarten
  • lossere vereisten voor SD Pull-up
  • slechts 3 GPIO-pinnen vereist
  • configuratie van kleinere code
  • veel dev kit, dev board en breakout board kunnen deze modus gebruiken

Aanbevolen: