115 lines
5.0 KiB
C
115 lines
5.0 KiB
C
#pragma once
|
|
|
|
// ============================================================================
|
|
// Storage configuration
|
|
// ============================================================================
|
|
//
|
|
// This header is the single place to configure how the Hub talks to the
|
|
// SD card. Two hardware interfaces are supported by the Arduino-ESP32
|
|
// framework, and both are implemented behind the StorageBackend interface
|
|
// in sd_manager.cpp:
|
|
//
|
|
// STORAGE_IFACE_SPI - Uses the `SD` library (SPI protocol). This is the
|
|
// bring-up path for the current breakout module,
|
|
// which only breaks out the 4 SPI lines.
|
|
// Max practical throughput: ~1-2 MB/s. NOT enough
|
|
// for the 6-8 MB/s audio logging target.
|
|
//
|
|
// STORAGE_IFACE_SDMMC - Uses the `SD_MMC` library (SDIO protocol, the
|
|
// SDMMC peripheral). This is the production path.
|
|
// 4-bit mode @ 40 MHz (SDMMC_FREQ_HIGHSPEED) gives
|
|
// roughly 8-12 MB/s, which comfortably meets the
|
|
// target. REQUIRED for the final design.
|
|
//
|
|
// TO MIGRATE TO SDIO (the new SDIO-capable board that is being shipped):
|
|
//
|
|
// 1. Change STORAGE_IFACE below from STORAGE_IFACE_SPI to
|
|
// STORAGE_IFACE_SDMMC.
|
|
//
|
|
// 2. Wire the SD card to the SDIO lines listed in the STORAGE_SDMMC_*
|
|
// defines below. On the classic ESP32 the SDMMC peripheral is routed
|
|
// through the GPIO matrix, so these pins can be changed to any free
|
|
// GPIO simply by editing the defines.
|
|
//
|
|
// 3. Keep STORAGE_SDMMC_MODE_1BIT as `false` (4-bit bus is required for
|
|
// the write throughput) and keep STORAGE_SDMMC_FORMAT_IF_FAILED as
|
|
// `false` (a foreign/unformatted card must never be auto-formatted).
|
|
//
|
|
// 4. Everything downstream (StorageTask, SDManager, and the future
|
|
// DataLogger) talks only through the `fs::FS` interface, so no other
|
|
// code changes are needed.
|
|
// ============================================================================
|
|
|
|
// --- Backend selection ------------------------------------------------------
|
|
|
|
#define STORAGE_IFACE_SPI 1
|
|
#define STORAGE_IFACE_SDMMC 2
|
|
|
|
// SPI until the SDIO-capable board arrives.
|
|
#ifndef STORAGE_IFACE
|
|
#define STORAGE_IFACE STORAGE_IFACE_SPI
|
|
#endif
|
|
|
|
// --- Common -----------------------------------------------------------------
|
|
|
|
// Single canonical mount point so file paths never change when the backend
|
|
// is switched (the SD lib defaults to "/sd", SD_MMC to "/sdcard").
|
|
#define STORAGE_MOUNT_POINT "/sdcard"
|
|
|
|
#define STORAGE_MAX_OPEN_FILES 5
|
|
|
|
// --- SPI (bring-up only) ----------------------------------------------------
|
|
|
|
// Default VSPI pins on the classic ESP32 DevKitC (variant/pins_arduino.h).
|
|
#define STORAGE_SPI_CS 5
|
|
#define STORAGE_SPI_SCK 18
|
|
#define STORAGE_SPI_MOSI 23
|
|
#define STORAGE_SPI_MISO 19
|
|
|
|
// 10 MHz is a reliable default for breadboard/jumper-wire bring-up. The SD
|
|
// init handshake always runs at 400 kHz regardless (see sd_diskio.cpp), so a
|
|
// mount failure is NOT a frequency problem - check power, wiring, pull-ups
|
|
// and card seating first. Raise to 20 MHz once the wiring is proven.
|
|
#define STORAGE_SPI_FREQ 10000000UL
|
|
|
|
// --- SDIO / SD_MMC (production, 4-bit) --------------------------------------
|
|
|
|
// Default ESP32 SDMMC slot-1 pins (GPIO matrix, freely re-routable).
|
|
#define STORAGE_SDMMC_CLK 6
|
|
#define STORAGE_SDMMC_CMD 11
|
|
#define STORAGE_SDMMC_D0 7
|
|
#define STORAGE_SDMMC_D1 8
|
|
#define STORAGE_SDMMC_D2 9
|
|
#define STORAGE_SDMMC_D3 10
|
|
|
|
// false = 4-bit wide bus (required for >8 MB/s). Do NOT enable 1-bit mode.
|
|
#define STORAGE_SDMMC_MODE_1BIT false
|
|
|
|
// NEVER auto-format: an unformatted/foreign card must never be destroyed.
|
|
#define STORAGE_SDMMC_FORMAT_IF_FAILED false
|
|
|
|
// 40 MHz == SDMMC_FREQ_HIGHSPEED. Written as a literal to keep this header
|
|
// free of driver includes.
|
|
#define STORAGE_SDMMC_FREQ_HZ 40000000
|
|
|
|
// --- Boot-time file listing -------------------------------------------------
|
|
|
|
// Maximum directory depth printed during the recursive boot listing. Guards
|
|
// the StorageTask stack against pathological directory nesting.
|
|
#define STORAGE_LIST_MAX_DEPTH 10
|
|
|
|
// --- Write-speed estimation -------------------------------------------------
|
|
|
|
// Path of the temporary scratch file used to measure write throughput. It is
|
|
// created, written, measured, then deleted, so it never appears in listings.
|
|
#define STORAGE_SPEED_MEASURE_PATH STORAGE_MOUNT_POINT "/.writespeed.tmp"
|
|
|
|
// Size of the scratch file written per measurement (bytes).
|
|
#define STORAGE_SPEED_MEASURE_BYTES (0.5 * 1024 * 1024)
|
|
|
|
// How often to re-measure write speed (ms). This is a bring-up ESTIMATE only:
|
|
// it writes STORAGE_SPEED_MEASURE_BYTES to the card on every tick. Once real
|
|
// logging exists, throughput should be derived from actual logging writes and
|
|
// this benchmark disabled by setting the interval to 0 (measure once at boot).
|
|
#define STORAGE_SPEED_MEASURE_INTERVAL_MS 0
|