Skip to content

Commit

Permalink
Moved SPI outputs to VSPI
Browse files Browse the repository at this point in the history
Updates to use SdFat 2.2.3 - Fixes issue that caused the SD card to stop working
  • Loading branch information
MartinMueller2003 committed Jul 13, 2024
1 parent 270ef0a commit 7ee99f3
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 18 deletions.
24 changes: 15 additions & 9 deletions ESPixelStick/src/FileMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@
#include "FileMgr.hpp"
#include "network/NetworkMgr.hpp"

SdFat sd;
SdFs sd;
const int8_t DISABLE_CS_PIN = -1;

#if HAS_SDIO_CLASS
#define SD_CONFIG SdioConfig(FIFO_SDIO)
#elif ENABLE_DEDICATED_SPI
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SD_SCK_MHZ(16))
#else // HAS_SDIO_CLASS
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SD_SCK_MHZ(16))
#endif // HAS_SDIO_CLASS

oflag_t XlateFileMode[3] = { O_READ , O_WRITE | O_CREAT, O_WRITE | O_APPEND };
#ifdef SUPPORT_FTP
Expand Down Expand Up @@ -373,16 +382,13 @@ void c_FileMgr::SetSpiIoPins ()
// DEBUG_V();
pinMode(miso_pin, INPUT);
# endif // def USE_MISO_PULLUP
SPI.begin (clk_pin, miso_pin, mosi_pin, cs_pin);
SPI.begin (clk_pin, miso_pin, mosi_pin, cs_pin); // uses HSPI by default
# else // ESP8266
SPI.end ();
SPI.begin ();
# endif // ! ARDUINO_ARCH_ESP32
// DEBUG_V();
ResetSdCard();

// DEBUG_V();
if (!ESP_SD.begin (SdSpiConfig(cs_pin, SHARED_SPI, SD_CARD_CLK_MHZ, &SPI)))
if (!ESP_SD.begin (SdSpiConfig(cs_pin, SHARED_SPI, SD_SCK_MHZ(16))))
#endif // !def SUPPORT_SD_MMC
{
// DEBUG_V();
Expand Down Expand Up @@ -1192,11 +1198,11 @@ bool c_FileMgr::OpenSdFile (const String & FileName, FileMode Mode, FileId & Fil

// DEBUG_V ();

// DEBUG_V (String("FileName: '") + FileNamePrefix + FileName + "'");
// DEBUG_V (String("FileName: '") + FileName + "'");

if (FileMode::FileRead == Mode)
{
// DEBUG_V (String("Read FIle"));
// DEBUG_V (String("Read mode"));
if (false == ESP_SD.exists (FileName))
{
logcon (String (F ("ERROR: Cannot find '")) + FileName + F ("' for reading. File does not exist."));
Expand All @@ -1221,7 +1227,7 @@ bool c_FileMgr::OpenSdFile (const String & FileName, FileMode Mode, FileId & Fil
FileHandle = FileList[FileListIndex].handle;
}

// did we get an index
// DEBUG_V("did we get an index");
if (-1 != FileListIndex)
{
// DEBUG_V(String("Valid FileListIndex: ") + String(FileListIndex));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#define SUPPORT_SPI_OUTPUT
#define DEFAULT_SPI_DATA_GPIO gpio_num_t::GPIO_NUM_27
#define DEFAULT_SPI_CLOCK_GPIO gpio_num_t::GPIO_NUM_32
#define DEFAULT_SPI_DEVICE HSPI_HOST
#define DEFAULT_SPI_DEVICE VSPI_HOST

#define DEFAULT_I2C_SDA gpio_num_t::GPIO_NUM_3
#define DEFAULT_I2C_SCL gpio_num_t::GPIO_NUM_5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#define SUPPORT_SPI_OUTPUT
#define DEFAULT_SPI_DATA_GPIO gpio_num_t::GPIO_NUM_15
#define DEFAULT_SPI_CLOCK_GPIO gpio_num_t::GPIO_NUM_25
#define DEFAULT_SPI_DEVICE HSPI_HOST
#define DEFAULT_SPI_DEVICE VSPI_HOST

#define DEFAULT_I2C_SDA gpio_num_t::GPIO_NUM_21
#define DEFAULT_I2C_SCL gpio_num_t::GPIO_NUM_22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#define SUPPORT_SPI_OUTPUT
#define DEFAULT_SPI_DATA_GPIO gpio_num_t::GPIO_NUM_15
#define DEFAULT_SPI_CLOCK_GPIO gpio_num_t::GPIO_NUM_25
#define DEFAULT_SPI_DEVICE HSPI_HOST
#define DEFAULT_SPI_DEVICE VSPI_HOST

#include <ETH.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#define SUPPORT_SPI_OUTPUT
#define DEFAULT_SPI_DATA_GPIO gpio_num_t::GPIO_NUM_16
#define DEFAULT_SPI_CLOCK_GPIO gpio_num_t::GPIO_NUM_17
#define DEFAULT_SPI_DEVICE HSPI_HOST
#define DEFAULT_SPI_DEVICE VSPI_HOST

#define DEFAULT_I2C_SDA gpio_num_t::GPIO_NUM_3
#define DEFAULT_I2C_SCL gpio_num_t::GPIO_NUM_5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#define SUPPORT_SPI_OUTPUT
#define DEFAULT_SPI_DATA_GPIO gpio_num_t::GPIO_NUM_15
#define DEFAULT_SPI_CLOCK_GPIO gpio_num_t::GPIO_NUM_25
#define DEFAULT_SPI_DEVICE HSPI_HOST
#define DEFAULT_SPI_DEVICE VSPI_HOST

#define DEFAULT_I2C_SDA gpio_num_t::GPIO_NUM_21
#define DEFAULT_I2C_SCL gpio_num_t::GPIO_NUM_22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#define SUPPORT_SPI_OUTPUT
#define DEFAULT_SPI_DATA_GPIO gpio_num_t::GPIO_NUM_27
#define DEFAULT_SPI_CLOCK_GPIO gpio_num_t::GPIO_NUM_32
#define DEFAULT_SPI_DEVICE HSPI_HOST
#define DEFAULT_SPI_DEVICE VSPI_HOST

#define DEFAULT_I2C_SDA gpio_num_t::GPIO_NUM_3
#define DEFAULT_I2C_SCL gpio_num_t::GPIO_NUM_5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#define SUPPORT_SPI_OUTPUT
#define DEFAULT_SPI_DATA_GPIO gpio_num_t::GPIO_NUM_16
#define DEFAULT_SPI_CLOCK_GPIO gpio_num_t::GPIO_NUM_17
#define DEFAULT_SPI_DEVICE HSPI_HOST
#define DEFAULT_SPI_DEVICE VSPI_HOST

#define DEFAULT_I2C_SDA gpio_num_t::GPIO_NUM_21
#define DEFAULT_I2C_SCL gpio_num_t::GPIO_NUM_22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#define SUPPORT_SPI_OUTPUT
#define DEFAULT_SPI_DATA_GPIO gpio_num_t::GPIO_NUM_15
#define DEFAULT_SPI_CLOCK_GPIO gpio_num_t::GPIO_NUM_25
#define DEFAULT_SPI_DEVICE HSPI_HOST
#define DEFAULT_SPI_DEVICE VSPI_HOST

#define DEFAULT_I2C_SDA gpio_num_t::GPIO_NUM_21
#define DEFAULT_I2C_SCL gpio_num_t::GPIO_NUM_22
Expand Down
9 changes: 8 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,20 @@ lib_deps =
https://github.com/MartinMueller2003/Artnet
https://github.com/MartinMueller2003/Espalexa ; pull latest
https://github.com/PaulStoffregen/Time
https://github.com/greiman/SdFat
https://github.com/greiman/SdFat @ 2.2.3
https://github.com/MartinMueller2003/SimpleFTPServer
extra_scripts =
.scripts/download_fs.py
.scripts/CopyTargets.py
pre:.scripts/pio-version.py
build_flags =
; -D ENABLE_DEDICATED_SPI=1 ; instruct SdFat to take ownership of the spi device
-D SDFAT_FILE_TYPE=3 ; SdFat full support
-D USE_LONG_FILE_NAMES=1 ; SdFat
-D MAINTAIN_FREE_CLUSTER_COUNT=1 ; SdFat
-D CHECK_FLASH_PROGRAMMING=0 ; SdFat
-D INCLUDE_SDIOS=1 ; SdFat
; -D USE_DBG_MACROS=2 ; SdFat
-D SUPPORT_FTP
; -D FTP_SERVER_DEBUG
; -D FTP_ADDITIONAL_DEBUG
Expand Down

0 comments on commit 7ee99f3

Please sign in to comment.