Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion docs/fs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,19 @@ The included ``SD`` library is the Arduino standard one. Please refer to
the [Arduino SD reference](https://www.arduino.cc/en/reference/SD) for
more information.

Using Second SPI port for SD
----------------------------
The ``SD`` library ``begin()`` has been modified to allow you to use the
second SPI port, ``SPI1``. Just use the following call in place of
``SD.begin(cspin)``

.. code:: cpp

SD.begin(cspin, SPI1);


File system object (LittleFS/SD/SDFS)
--------------------------------------------
-------------------------------------

setConfig
~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion docs/ota.rst
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ A firmware file is uploaded via any method (Ethernet, WiFi, serial ZModem, etc.)

The ROM layout consists of:

... code:
.. code:: cpp

[boot2.S] [OTA Bootloader] [0-pad] [OTA partition table] [Main sketch] [LittleFS filesystem] [EEPROM]

8 changes: 6 additions & 2 deletions libraries/SD/src/SD.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@

class SDClass {
public:
boolean begin(uint8_t csPin, uint32_t cfg = SPI_HALF_SPEED) {
SDFS.setConfig(SDFSConfig(csPin, cfg));
boolean begin(uint8_t csPin, HardwareSPI &spi) {
SDFS.setConfig(SDFSConfig(csPin, SPI_HALF_SPEED, spi));
return (boolean)SDFS.begin();
}
boolean begin(uint8_t csPin, uint32_t cfg = SPI_HALF_SPEED, HardwareSPI &spi = SPI) {
SDFS.setConfig(SDFSConfig(csPin, cfg, spi));
return (boolean)SDFS.begin();
}

Expand Down
14 changes: 10 additions & 4 deletions libraries/SDFS/src/SDFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class SDFSConfig : public FSConfig {
public:
static constexpr uint32_t FSId = 0x53444653;

SDFSConfig(uint8_t csPin = 4, uint32_t spi = SD_SCK_MHZ(10)) : FSConfig(FSId, false), _csPin(csPin), _part(0), _spiSettings(spi) { }
SDFSConfig(uint8_t csPin = 4, uint32_t spi = SD_SCK_MHZ(10), HardwareSPI &port = SPI) : FSConfig(FSId, false), _csPin(csPin), _part(0), _spiSettings(spi), _spi(&port) { }

SDFSConfig setAutoFormat(bool val = true) {
_autoFormat = val;
Expand All @@ -55,10 +55,14 @@ class SDFSConfig : public FSConfig {
_csPin = pin;
return *this;
}
SDFSConfig setSPI(uint32_t spi) {
SDFSConfig setSPISpeed(uint32_t spi) {
_spiSettings = spi;
return *this;
}
SDFSConfig setSPI(HardwareSPI &spi) {
_spi = &spi;
return true;
}
SDFSConfig setPart(uint8_t part) {
_part = part;
return *this;
Expand All @@ -68,6 +72,7 @@ class SDFSConfig : public FSConfig {
uint8_t _csPin;
uint8_t _part;
uint32_t _spiSettings;
HardwareSPI *_spi;
};

class SDFSImpl : public FSImpl {
Expand Down Expand Up @@ -146,10 +151,11 @@ class SDFSImpl : public FSImpl {
if (_mounted) {
return true;
}
_mounted = _fs.begin(_cfg._csPin, _cfg._spiSettings);
SdSpiConfig ssc(_cfg._csPin, SHARED_SPI, _cfg._spiSettings, _cfg._spi);
_mounted = _fs.begin(ssc);
if (!_mounted && _cfg._autoFormat) {
format();
_mounted = _fs.begin(_cfg._csPin, _cfg._spiSettings);
_mounted = _fs.begin(ssc);
}
FsDateTime::setCallback(dateTimeCB);
return _mounted;
Expand Down