diff --git a/src/FSCommon.cpp b/src/FSCommon.cpp index df46c19412..f9c96931af 100644 --- a/src/FSCommon.cpp +++ b/src/FSCommon.cpp @@ -14,13 +14,20 @@ #ifdef HAS_SDCARD #include #include - #ifdef SDCARD_USE_SPI1 +#ifdef ARCH_ESP32 SPIClass SPI1(HSPI); -#define SDHandler SPI1 +#endif // ARCH_ESP32 +#ifdef ARCH_NRF52 +#define SDCARD_SPI SPI1 +#endif // NRF52 +#define SDHandler SPI1 // only used for esp32 #else -#define SDHandler SPI -#endif +#ifdef ARCH_NRF52 +#define SDCARD_SPI SPI +#endif // NRF52 +#define SDHandler SPI // only used for esp32 +#endif // SDCARD_USE_SPI1 #endif // HAS_SDCARD @@ -46,7 +53,7 @@ void OSFS::writeNBytes(uint16_t address, unsigned int num, const byte *input) input++; } } -#endif +#endif // ARCH_STM32WL bool lfs_assert_failed = false; // Note: we use this global on all platforms, though it can only be set true on nrf52 (in our modified lfs_util.h) @@ -356,9 +363,11 @@ void fsInit() void setupSDCard() { #ifdef HAS_SDCARD +#if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) +#if (defined(ARCH_ESP32)) SDHandler.begin(SPI_SCK, SPI_MISO, SPI_MOSI); - - if (!SD.begin(SDCARD_CS, SDHandler)) { +#endif + if (!SD.begin(SDCARD_CS, SDHandler)) { // param SDHandler only used for esp32 LOG_DEBUG("No SD_MMC card detected"); return; } @@ -381,6 +390,9 @@ void setupSDCard() uint64_t cardSize = SD.cardSize() / (1024 * 1024); LOG_DEBUG("SD Card Size: %lu MB", (uint32_t)cardSize); LOG_DEBUG("Total space: %lu MB", (uint32_t)(SD.totalBytes() / (1024 * 1024))); +#if (defined(ARCH_ESP32)) // not implemented in arduino sd library LOG_DEBUG("Used space: %lu MB", (uint32_t)(SD.usedBytes() / (1024 * 1024))); #endif -} \ No newline at end of file +#endif +#endif +} diff --git a/src/memGet.cpp b/src/memGet.cpp index 33fb94e1c0..c7078fac4d 100644 --- a/src/memGet.cpp +++ b/src/memGet.cpp @@ -57,7 +57,7 @@ uint32_t MemGet::getFreePsram() { #ifdef ARCH_ESP32 return ESP.getFreePsram(); -#elif defined(HAS_SDCARD) +#elif (defined(HAS_SDCARD) && defined(ARCH_ESP32)) return SD.totalBytes() - SD.usedBytes(); #elif defined(ARCH_PORTDUINO) return 4194252; @@ -75,7 +75,7 @@ uint32_t MemGet::getPsramSize() { #ifdef ARCH_ESP32 return ESP.getPsramSize(); -#elif defined(HAS_SDCARD) +#elif (defined(HAS_SDCARD) && defined(ARCH_ESP32)) return SD.totalBytes(); #elif defined(ARCH_PORTDUINO) return 4194252; diff --git a/src/modules/StoreForwardModule.cpp b/src/modules/StoreForwardModule.cpp index 4a762a1c3c..928f116430 100644 --- a/src/modules/StoreForwardModule.cpp +++ b/src/modules/StoreForwardModule.cpp @@ -98,6 +98,7 @@ void StoreForwardModule::populatePSRAM() void StoreForwardModule::populateSDCard() { #if defined(HAS_SDCARD) +#if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) if (SD.cardType() != CARD_NONE) { if (!SD.exists("/storeforward")) { LOG_INFO("Creating StoreForward directory"); @@ -109,7 +110,8 @@ void StoreForwardModule::populateSDCard() this->packetHistory = (PacketHistoryStruct *)malloc(sizeof(PacketHistoryStruct)); LOG_DEBUG("numberOfPackets for packetHistory - %u", numberOfPackets); } -#endif +#endif // ARCH_ESP32 || ARCH_NRF52 +#endif // HAS_SDCARD } /** @@ -166,6 +168,7 @@ uint32_t StoreForwardModule::getNumAvailablePackets(NodeNum dest, uint32_t last_ } } else if (this->storageType == StorageType::ST_SDCARD) { #if defined(HAS_SDCARD) +#if defined(ARCH_ESP32) || defined(ARCH_NRF52) auto handler = SD.open("/storeforward/" + String(i), FILE_READ); if (handler) { handler.read((uint8_t *)&this->packetHistory[0], sizeof(PacketHistoryStruct)); @@ -178,6 +181,7 @@ uint32_t StoreForwardModule::getNumAvailablePackets(NodeNum dest, uint32_t last_ } } } +#endif #endif } else { LOG_ERROR("S&F: Unknown storage type"); @@ -248,6 +252,7 @@ void StoreForwardModule::historyAdd(const meshtastic_MeshPacket &mp) } else if (this->storageType == StorageType::ST_SDCARD) { // Save to SDCARD #if defined(HAS_SDCARD) +#if defined(ARCH_ESP32) || defined(ARCH_NRF52) this->packetHistory[0].time = getTime(); this->packetHistory[0].to = mp.to; this->packetHistory[0].channel = mp.channel; @@ -260,6 +265,7 @@ void StoreForwardModule::historyAdd(const meshtastic_MeshPacket &mp) auto handler = SD.open("/storeforward/" + String(this->packetHistoryTotalCount), FILE_WRITE); handler.write((uint8_t *)&this->packetHistory, sizeof(PacketHistoryStruct)); handler.close(); +#endif #endif } else { LOG_ERROR("S&F: Unknown storage type"); @@ -346,6 +352,7 @@ meshtastic_MeshPacket *StoreForwardModule::preparePayload(NodeNum dest, uint32_t } } else if (this->storageType == StorageType::ST_SDCARD) { #if defined(HAS_SDCARD) +#if defined(ARCH_ESP32) || defined(ARCH_NRF52) auto handler = SD.open("/storeforward/" + String(i), FILE_READ); if (handler) { handler.read((uint8_t *)&this->packetHistory[0], sizeof(PacketHistoryStruct)); @@ -389,6 +396,7 @@ meshtastic_MeshPacket *StoreForwardModule::preparePayload(NodeNum dest, uint32_t } } } +#endif #endif } else { LOG_ERROR("S&F: Unknown storage type"); diff --git a/src/xmodem.h b/src/xmodem.h index 4cfcb43e18..ae1cca7cb7 100644 --- a/src/xmodem.h +++ b/src/xmodem.h @@ -62,7 +62,7 @@ class XModemAdapter uint16_t packetno = 0; #if defined(ARCH_NRF52) || defined(ARCH_STM32WL) - File file = File(FSCom); + Adafruit_LittleFS_Namespace::File file = Adafruit_LittleFS_Namespace::File(FSCom); #else File file; #endif diff --git a/variants/rak4631/platformio.ini b/variants/rak4631/platformio.ini index ced93df66f..c423264fee 100644 --- a/variants/rak4631/platformio.ini +++ b/variants/rak4631/platformio.ini @@ -20,6 +20,7 @@ lib_deps = https://github.com/RAKWireless/RAK13800-W5100S.git#1.0.2 rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2 https://github.com/RAKWireless/RAK12034-BMX160.git#dcead07ffa267d3c906e9ca4a1330ab989e957e2 + https://github.com/Woutvstk/arduino_SD.git#909c2a4a14f5b053bb69958709f0c874aa358c38 ;library to acces SD card ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ; Note: as of 6/2013 the serial/bootloader based programming takes approximately 30 seconds diff --git a/variants/rak4631/variant.h b/variants/rak4631/variant.h index bc55413368..f5a60fdeed 100644 --- a/variants/rak4631/variant.h +++ b/variants/rak4631/variant.h @@ -122,6 +122,19 @@ static const uint8_t MOSI = PIN_SPI_MOSI; static const uint8_t MISO = PIN_SPI_MISO; static const uint8_t SCK = PIN_SPI_SCK; +// SD card SPI pin definitions + +#define HAS_SDCARD 1 +#define SDCARD_USE_SPI1 1 + +#ifdef SDCARD_USE_SPI1 +#define SDCARD_SPI SPI1 +#endif +#define SPI_MOSI PIN_SPI1_MOSI +#define SPI_SCK PIN_SPI1_SCK +#define SPI_MISO PIN_SPI1_MISO +#define SDCARD_CS (26) + /* * eink display pins */