B4R Library rSD32 library

it is a wrapper based on SD library in esp32 package for arduino.
SPI configuration is depending of esp32 version:
ESP32:
- FSPI = 1, SPI attached To flash / normally Not used
- HSPI = 2, uses SPI2 => MOSI (13), SCK (14), MISO (12), SS (15)
- VSPI = 3, uses SPI3 => MOSI (23), SCK (18), MISO (19), SS (5)
- VSPI is SPI by default

ESP32-S2:
- FSPI = 1, uses SPI2 =>MOSI (13), SCK (14), MISO (15) And SS (12) / 6 SS lines any other pin
- HSPI = 2, uses SPI3 =>MOSI (35), SCK (36), MISO (37) And SS (34) / 3 SS lines at any other pin
- VSPI Not defined

ESP32 C3:
- FSPI = 0, uses SPIx =>MOSI (5), SCK (6), MISO (7) And SS (10) / 6 SS lines any other pin
- HSPI Not defined
- VSPI Not defined


' * SPI Standard case: Connect the SD card To the following pins:
' *
' * SD Card | ESP32 | HSPI | VSPI
' * D2 -
' * D3 SS 15 5
' * CMD MOSI 13 23
' * VSS GND
' * VDD 3.3V
' * CLK SCK 14 18
' * VSS GND
' * D0 MISO 12 19
' * D1 -
' */
a personal configuration is also possible when pins are added in begin.

new functions in esp32 package are added:
byte getcardType();
ULong getcardSize();
ULong gettotalBytes();
ULong getusedBytes();
bool readRAW(ArrayByte* buffer, ULong sector);
bool writeRAW(ArrayByte* buffer, ULong sector);
 

Attachments

  • rSD32_1.1.zip
    8.1 KB · Views: 39
Last edited:

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
Version ESP32 2.0.2

1643481222079.png
 

sasetcolombia

Member
Licensed User
Longtime User
I have tested rDS32 and it generates this error...

Debug:
[cc.arduino.packages.discoverers.serial.SerialDiscovery] Fail to get the Vid Pid information from the builder response code=404
D:\rSD32\B4R\Objects\bin\sketch\rSD32.cpp: In member function 'bool B4R::B4RSD32::Initialize1(uint8_t, uint8_t, ULong, byte, bool)':
rSD32.cpp:17:82: error: no matching function for call to 'fs::SDFS::begin(uint8_t&, SPIClass&, ULong&, const char [4], byte&, bool&)'
        return SD.begin(SDss, sd_SPI, frequency, "/sd", max_files, format_if_empty); 
                                                                                  ^
In file included from D:\rSD32\B4R\Objects\bin\sketch\rSD32.cpp:2:0:
C:\Users\saset\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\SD\src/SD.h:31:10: note: candidate: bool fs::SDFS::begin(uint8_t, SPIClass&, uint32_t, const char*, uint8_t)
     bool begin(uint8_t ssPin=SS, SPIClass &spi=SPI, uint32_t frequency=4000000, const char * mountpoint="/sd", uint8_t max_files=5);
          ^
C:\Users\saset\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\SD\src/SD.h:31:10: note:   candidate expects 5 arguments, 6 provided
D:\rSD32\B4R\Objects\bin\sketch\rSD32.cpp: In member function 'bool B4R::B4RSD32::Initialize3(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, ULong, byte, bool)':
rSD32.cpp:29:82: error: no matching function for call to 'fs::SDFS::begin(uint8_t&, SPIClass&, ULong&, const char [4], byte&, bool&)'
        return SD.begin(SDss, sd_SPI, frequency, "/sd", max_files, format_if_empty); 
                                                                                  ^
In file included from D:\rSD32\B4R\Objects\bin\sketch\rSD32.cpp:2:0:
C:\Users\saset\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\SD\src/SD.h:31:10: note: candidate: bool fs::SDFS::begin(uint8_t, SPIClass&, uint32_t, const char*, uint8_t)
     bool begin(uint8_t ssPin=SS, SPIClass &spi=SPI, uint32_t frequency=4000000, const char * mountpoint="/sd", uint8_t max_files=5);
          ^
C:\Users\saset\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\SD\src/SD.h:31:10: note:   candidate expects 5 arguments, 6 provided
D:\rSD32\B4R\Objects\bin\sketch\rSD32.cpp: In member function 'bool B4R::B4RSD32::readRAW(B4R::ArrayByte*, ULong)':
rSD32.cpp:61:19: error: 'class fs::SDFS' has no member named 'readRAW'
         return SD.readRAW((uint8_t*)buff->data, sector);
                   ^
D:\rSD32\B4R\Objects\bin\sketch\rSD32.cpp: In member function 'bool B4R::B4RSD32::writeRAW(B4R::ArrayByte*, ULong)':
rSD32.cpp:65:19: error: 'class fs::SDFS' has no member named 'writeRAW'
         return SD.writeRAW((uint8_t*)buff->data, sector);
                   ^
D:\rSD32\B4R\Objects\bin\sketch\b4r_main.cpp: In static member function 'static void b4r_main::_appstart()':
b4r_main.cpp:73:58: error: invalid conversion from 'void (*)()' to 'B4R::SubVoidByte {aka void (*)(unsigned char)}' [-fpermissive]
 B4R::__c->CallSubPlus(_check_sd,(ULong) (5000),(Byte) (0));
                                                          ^
In file included from D:\rSD32\B4R\Objects\bin\sketch\B4RDefines.h:24:0,
                 from D:\rSD32\B4R\Objects\bin\sketch\b4r_main.cpp:1:
D:\rSD32\B4R\Objects\bin\sketch\rCore.h:443:15: note:   initializing argument 1 of 'static void B4R::Common::CallSubPlus(B4R::SubVoidByte, ULong, Byte)'
   static void CallSubPlus(SubVoidByte SubName,ULong DelayMs, Byte Tag);
               ^
Se encontraron varias bibliotecas para "SD.h"
Usado: C:\Users\saset\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\SD
 No usado: C:\Arduino\libraries\SD
Se encontraron varias bibliotecas para "WiFi.h"
Usado: C:\Users\saset\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi
 No usado: C:\Arduino\libraries\WiFi
exit status 1
DEBUG StatusLogger Stopping LoggerContext[name=1e6f5c3, org.apache.logging.log4j.core.LoggerContext@165f390]
DEBUG StatusLogger Stopping LoggerContext[name=1e6f5c3, org.apache.logging.log4j.core.LoggerContext@165f390]...
TRACE StatusLogger Unregistering 1 MBeans: [org.apache.logging.log4j2:type=1e6f5c3]
TRACE StatusLogger Unregistering 1 MBeans: [org.apache.logging.log4j2:type=1e6f5c3,component=StatusLogger]
TRACE StatusLogger Unregistering 1 MBeans: [org.apache.logging.log4j2:type=1e6f5c3,component=ContextSelector]
TRACE StatusLogger Unregistering 1 MBeans: [org.apache.logging.log4j2:type=1e6f5c3,component=Loggers,name=]
TRACE StatusLogger Unregistering 2 MBeans: [org.apache.logging.log4j2:type=1e6f5c3,component=Appenders,name=RollingFile, org.apache.logging.log4j2:type=1e6f5c3,component=Appenders,name=Console]
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=1e6f5c3,component=AsyncAppenders,name=*'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=1e6f5c3,component=AsyncLoggerRingBuffer'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=1e6f5c3,component=Loggers,name=*,subtype=RingBuffer'
TRACE StatusLogger Stopping XmlConfiguration[location=jar:file:/C:/Arduino/lib/pde.jar!/log4j2.xml]...
TRACE StatusLogger XmlConfiguration notified 2 ReliabilityStrategies that config will be stopped.
TRACE StatusLogger XmlConfiguration stopping 1 LoggerConfigs.
TRACE StatusLogger XmlConfiguration stopping root LoggerConfig.
TRACE StatusLogger XmlConfiguration notifying ReliabilityStrategies that appenders will be stopped.
TRACE StatusLogger XmlConfiguration stopping remaining Appenders.
DEBUG StatusLogger Shutting down RollingFileManager C:\Users\saset\AppData\Local\Arduino15/logs/application.log
DEBUG StatusLogger Shutting down RollingFileManager C:\Users\saset\AppData\Local\Arduino15/logs/application.log
DEBUG StatusLogger All asynchronous threads have terminated
DEBUG StatusLogger RollingFileManager shutdown completed with status true
DEBUG StatusLogger Shut down RollingFileManager C:\Users\saset\AppData\Local\Arduino15/logs/application.log, all resources released: true
DEBUG StatusLogger Appender RollingFile stopped with status true
DEBUG StatusLogger Shutting down OutputStreamManager SYSTEM_ERR.false.false
DEBUG StatusLogger Shut down OutputStreamManager SYSTEM_ERR.false.false, all resources released: true
DEBUG StatusLogger Appender Console stopped with status true
TRACE StatusLogger XmlConfiguration stopped 2 remaining Appenders.
TRACE StatusLogger XmlConfiguration cleaning Appenders from 2 LoggerConfigs.
DEBUG StatusLogger Stopped XmlConfiguration[location=jar:file:/C:/Arduino/lib/pde.jar!/log4j2.xml] OK
DEBUG StatusLogger Stopped LoggerContext[name=1e6f5c3, org.apache.logging.log4j.core.LoggerContext@165f390] with status true
 

candide

Active Member
Licensed User
i think it is an issue due to esp32 package used:
C:\Users\saset\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\SD\src/SD.h:31:10: note: candidate: bool fs::SDFS::begin(uint8_t, SPIClass&, uint32_t, const char*, uint8_t)
=> esp32 v1.0.4 is used in your example

in my case, compilation is done with esp32 v2.0.2 and it is OK.
Also, If i look at esp32 SD library, we have a lot of differences between both releases, and it can explain your compilation issue.

Please to test compilation with last release esp32 v2.0.2 and we will see
 
Thanks for sharing library but confused as it is v1.1 but in post #4 there is also mentioned a library v2.0.2...
Which one to use or please share both. Thanks.
 

Mostez

Well-Known Member
Licensed User
Longtime User
I'd like to thank you so much for sharing this great lib.
If I customized pin configs (sd.Initialize2) instead of using hardware SPI port, does it affect read/write speed or overall performance?
 

candide

Active Member
Licensed User
with a google search "arduino esp32 change spi pins" you will have your answer :

standard pins used are depending of SPI interface used :
ESP32:
- FSPI = 1, SPI attached To flash / normally Not used
- HSPI = 2, uses SPI2 => MOSI (13), SCK (14), MISO (12), SS (15)
- VSPI = 3, uses SPI3 => MOSI (23), SCK (18), MISO (19), SS (5)
- VSPI is SPI by default

after you can change pins used :
If you use the pins shown in the table, you can achieve SPI speeds of up to 80 MHz.
If you use other pins, then you are limited 40 MHz. (in fact, most peripherals have a maximum SPI speed less than 40 MHz)
 
Top