From cf87950e27ec9752bb276127f425428f7f78a549 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 31 Oct 2020 12:05:26 +0100 Subject: [PATCH] SDMMC fix (PR #665, activating pullups) --- include/sdcard.h | 19 +++++++++++++++++++ src/hal/ttgov21new.h | 2 +- src/sdcard.cpp | 14 ++++++++------ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/include/sdcard.h b/include/sdcard.h index 669cebc7..5c34dc11 100644 --- a/include/sdcard.h +++ b/include/sdcard.h @@ -35,6 +35,25 @@ #define SDCARD_SCLK SCK #endif +// Default config for SDMMC_HOST_DEFAULT (4-bit bus width, slot 1) +// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/sdmmc_host.html + +#ifndef SDCARD_DATA0 +#define SDCARD_DATA0 2 +#endif + +#ifndef SDCARD_DATA1 +#define SDCARD_DATA1 4 +#endif + +#ifndef SDCARD_DATA2 +#define SDCARD_DATA2 12 +#endif + +#ifndef SDCARD_DATA3 +#define SDCARD_DATA3 13 +#endif + #define SDCARD_FILE_NAME "/paxcount.%02d" #define SDCARD_FILE_HEADER "date, time, wifi, bluet" diff --git a/src/hal/ttgov21new.h b/src/hal/ttgov21new.h index 4b08748d..71c22bca 100644 --- a/src/hal/ttgov21new.h +++ b/src/hal/ttgov21new.h @@ -16,7 +16,7 @@ #define CFG_sx1276_radio 1 // HPD13A LoRa SoC // enable only if you want to store a local paxcount table on the device -#define HAS_SDCARD 1 // this board has an SD-card-reader/writer +#define HAS_SDCARD 2 // // this board has a SDMMC card-reader/writer #define HAS_DISPLAY 1 #define HAS_LED (25) // green on board LED diff --git a/src/sdcard.cpp b/src/sdcard.cpp index 57fc5b81..197edcfd 100644 --- a/src/sdcard.cpp +++ b/src/sdcard.cpp @@ -22,11 +22,12 @@ bool sdcard_init() { #if HAS_SDCARD == 1 // use SD SPI host driver useSDCard = SD.begin(SDCARD_CS, SDCARD_MOSI, SDCARD_MISO, SDCARD_SCLK); - //SPI.begin(SDCARD_SCLK, SDCARD_MSO, SDCARD_MOSI, SDCARD_CS); - //delay(10); - //useSDCard = SD.begin(SDCARD_CS, SPI, 40000000, "/sd"); - #elif HAS_SDCARD == 2 // use SD MMC host driver + // enable internal pullups of sd-data lines + gpio_set_pull_mode(gpio_num_t(SDCARD_DATA0), GPIO_PULLUP_ONLY); + gpio_set_pull_mode(gpio_num_t(SDCARD_DATA1), GPIO_PULLUP_ONLY); + gpio_set_pull_mode(gpio_num_t(SDCARD_DATA2), GPIO_PULLUP_ONLY); + gpio_set_pull_mode(gpio_num_t(SDCARD_DATA3), GPIO_PULLUP_ONLY); useSDCard = SD_MMC.begin(); #endif @@ -38,7 +39,8 @@ bool sdcard_init() { return useSDCard; } -void sdcardWriteData(uint16_t noWifi, uint16_t noBle, __attribute__((unused)) uint16_t noBleCWA) { +void sdcardWriteData(uint16_t noWifi, uint16_t noBle, + __attribute__((unused)) uint16_t noBleCWA) { static int counterWrites = 0; char tempBuffer[12 + 1]; time_t t = now(); @@ -103,7 +105,7 @@ void createFile(void) { ESP_LOGD(TAG, "SD: name opened: <%s>", bufferFilename); fileSDCard.print(SDCARD_FILE_HEADER); #if (COUNT_ENS) - fileSDCard.print(SDCARD_FILE_HEADER_CWA); // for Corona-data (CWA) + fileSDCard.print(SDCARD_FILE_HEADER_CWA); // for Corona-data (CWA) #endif #if (HAS_SDS011) fileSDCard.print(SDCARD_FILE_HEADER_SDS011);