-->
Page 1 of 2

ESP + SD Card + Long Names

PostPosted: Mon Jul 27, 2015 11:52 am
by Artur Gaspar
I wonder if anyone has ever managed to use long names witch SD card .
I'm looking on the internet and found the SdFat . I noticed that the files in this library are also inside the SD library directory.
But I could not figure out how to use , not found any examples .
Thank You.

Re: ESP + SD Card + Long Names

PostPosted: Mon Jul 27, 2015 1:44 pm
by martinayotte
Don't confuse between SD library and SdFat library, they are not the same.
The SdFat library can be found at https://github.com/greiman/SdFat .
I've just gave it a try, and it seems to work, although small changes need to be done to get it compiled under ESP.
First, the config, SD_SPI_CONFIGURATION needs to be 1 for using the SPI already present under ESP.
Second, the memchr() doesn't seem to be part of SDK, so I added one by calling memchr2() to avoid conflict with headers.
And last, I've commented thru #ifdef ESP8266 the function SdFatUtil::FreeRam().
In my sketch, I've written a file using long filename and re-read it and print directory listing.

Re: ESP + SD Card + Long Names

PostPosted: Mon Jul 27, 2015 2:22 pm
by Artur Gaspar
Tanks! The SD_SPI_CONFIGURATION=1 reduces the lines of errors ;)

Now I have:
Code: Select allArduino: 1.6.5 (Linux), Board: "NodeMCU (ESP8266 ESP-12 Module), 80 MHz, 115200"

/home/porcao/Documents/Arduino-esp8266-sdk-1.0/arduino-1.6.5/libraries/SdFat/utility/StdioStream.cpp: In member function 'size_t StdioStream::print(const __FlashStringHelper*)':
/home/porcao/Documents/Arduino-esp8266-sdk-1.0/arduino-1.6.5/libraries/SdFat/utility/StdioStream.cpp:285:39: warning: 'section' attribute does not apply to types [-Wattributes]
   const char *p = (const char PROGMEM *)str;
                                       ^
/home/porcao/Documents/Arduino-esp8266-sdk-1.0/arduino-1.6.5/libraries/SdFat/utility/StdioStream.cpp:293:34: warning: 'section' attribute does not apply to types [-Wattributes]
   return p - (const char PROGMEM *)str;
                                  ^
SdFat/SdFatUtil.cpp.o:(.text+0x0): undefined reference to `__brkval'
SdFat/SdFatUtil.cpp.o:(.text+0x4): undefined reference to `__bss_end'
SdFat/utility/StdioStream.cpp.o: In function `StdioStream::fillBuf()':
StdioStream.cpp:(.text+0x4d8): undefined reference to `memchr'
StdioStream.cpp:(.text+0x527): undefined reference to `memchr'
collect2: error: ld returned 1 exit status
Error compiling.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.


I believe it is memchr() fault.
But I have not found a way to fix it.
Again , thank you for your help.

Re: ESP + SD Card + Long Names

PostPosted: Mon Jul 27, 2015 5:51 pm
by martinayotte
Yes, that's what I got before fix the last errors.
For the memchr() issue, the quick hack/fix is to add memchr2() function at the beginning of SdFat/utility/StdioStream.cpp and change memchr() to memchr2() around line 77 :

Code: Select alluint8_t *memchr2(uint8_t *ptr, uint8_t ch, size_t size)
{
  for (int i = 0; i < size; i++)
    if (*ptr++ == ch)
      return ptr;
  return NULL;
}


The other fix is to have an empty SdFatUtil::FreeRam() for ESP8266 in SdFat/SdFatUtil.cpp (check the added + lines, but don't leave the + ;) ):

Code: Select all#ifdef __arm__
extern "C" char* sbrk(int incr);
int SdFatUtil::FreeRam() {
  char top;
  return &top - reinterpret_cast<char*>(sbrk(0));
}
#else  // __arm__
+#ifdef ESP8266
+#else
extern char *__brkval;
extern char __bss_end;
/** Amount of free RAM
 * \return The number of free bytes.
 */
int SdFatUtil::FreeRam() {
  char top;
  return __brkval ? &top - __brkval : &top - &__bss_end;
}
+#endif
#endif  // __arm