improve sd-card MMC handling

This commit is contained in:
cyberman54 2022-02-28 22:39:25 +01:00
parent 59d468bb1e
commit 7c056bdea9
3 changed files with 28 additions and 17 deletions

View File

@ -11,17 +11,8 @@
#define MOUNT_POINT "/sdcard" #define MOUNT_POINT "/sdcard"
#if HAS_SDCARD == 1 #if HAS_SDCARD == 1 // SPI interface
#include "driver/sdspi_host.h" #include "driver/sdspi_host.h"
#elif HAS_SDCARD == 2
#include "driver/sdmmc_host.h"
#else
#error HAS_SDCARD unknown card reader value, must be either 1 or 2
#endif
#ifdef HAS_SDS011
#include "sds011read.h"
#endif
#ifndef SDCARD_CS #ifndef SDCARD_CS
#define SDCARD_CS SS #define SDCARD_CS SS
@ -39,6 +30,25 @@
#define SDCARD_SCLK SCK #define SDCARD_SCLK SCK
#endif #endif
#elif HAS_SDCARD == 2 // MMC interface
#include "driver/sdmmc_host.h"
#ifndef SDCARD_SLOTWIDTH
#define SDCARD_SLOTWIDTH 1
#endif
#ifndef SDCARD_PULLUP
#define SDCARD_PULLUP SDMMC_SLOT_FLAG_INTERNAL_PULLUP
#endif
#else
#error HAS_SDCARD unknown card reader value, must be either 1 or 2
#endif
#ifdef HAS_SDS011
#include "sds011read.h"
#endif
#define SDCARD_FILE_NAME clientId #define SDCARD_FILE_NAME clientId
#define SDCARD_FILE_HEADER "timestamp,wifi,ble" #define SDCARD_FILE_HEADER "timestamp,wifi,ble"

View File

@ -9,14 +9,15 @@
/* Hardware related definitions for TTGO V2.1 Board /* Hardware related definitions for TTGO V2.1 Board
// ATTENTION: check your board version! // ATTENTION: check your board version!
// This settings are for boards labeled v1.6 on pcb, NOT for v1.5 or older // This settings are for boards labeled v1.6 or v1.6.1 on pcb, NOT for v1.5 or older
*/ */
#define HAS_LORA 1 // comment out if device shall not send data via LoRa #define HAS_LORA 1 // comment out if device shall not send data via LoRa
#define CFG_sx1276_radio 1 // HPD13A LoRa SoC #define CFG_sx1276_radio 1 // HPD13A LoRa SoC
// enable only if you want to store a local paxcount table on the device // enable only if you want to store a local paxcount table on the device
#define HAS_SDCARD 2 // this board has a SDMMC card-reader/writer #define HAS_SDCARD 2 // this board has a SD MMC card-reader/writer
#define SDCARD_SLOTWIDTH 4 // 4-line interface
#define HAS_DISPLAY 1 #define HAS_DISPLAY 1
#define HAS_LED (25) // green on board LED #define HAS_LED (25) // green on board LED

View File

@ -140,13 +140,13 @@ bool sdcard_init(bool create) {
// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/sdmmc_host.html // https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/sdmmc_host.html
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT(); sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
// To use 4-line SD mode, change this to 4: // Set 1-line or 4-line SD mode (default is 1-line)
slot_config.width = 1; slot_config.width = SDCARD_SLOTWIDTH;
// Enable internal pullups on enabled pins. The internal pullups // Enable internal pullups on enabled pins. The internal pullups
// are insufficient however, please make sure 10k external pullups are // are insufficient however, please make sure 10k external pullups are
// connected on the bus. This is for debug / example purpose only. // connected on the bus. This is for debug / example purpose only.
slot_config.flags |= SDMMC_SLOT_FLAG_INTERNAL_PULLUP; slot_config.flags |= SDCARD_PULLUP;
// Use settings defined above to initialize SD card and mount FAT filesystem. // Use settings defined above to initialize SD card and mount FAT filesystem.
esp_err_t ret = esp_vfs_fat_sdmmc_mount(mount_point, &host, &slot_config, esp_err_t ret = esp_vfs_fat_sdmmc_mount(mount_point, &host, &slot_config,
@ -180,7 +180,7 @@ bool sdcard_init(bool create) {
fgetpos(data_file, &position); fgetpos(data_file, &position);
// empty file? then we write a header line // empty file? then we write a header line
if (position = 0) { if (position == 0) {
fprintf(data_file, "%s", SDCARD_FILE_HEADER); fprintf(data_file, "%s", SDCARD_FILE_HEADER);
#if (defined BAT_MEASURE_ADC || defined HAS_PMU) #if (defined BAT_MEASURE_ADC || defined HAS_PMU)
fprintf(data_file, "%s", SDCARD_FILE_HEADER_VOLTAGE); fprintf(data_file, "%s", SDCARD_FILE_HEADER_VOLTAGE);
@ -188,8 +188,8 @@ bool sdcard_init(bool create) {
#if (HAS_SDS011) #if (HAS_SDS011)
fprintf(data_file, "%s", SDCARD_FILE_HEADER_SDS011); fprintf(data_file, "%s", SDCARD_FILE_HEADER_SDS011);
#endif #endif
fprintf(data_file, "\n");
} }
fprintf(data_file, "\n");
} else { } else {
useSDCard = false; useSDCard = false;