SdFat: Example build error on Raspberry Pico (earlephilhover core for Arduino IDE)

Hello, I am using the latest SDFat 2.2.0 with Arduino IDE 1.8.19.

Board is Raspberry Pico (RP2040); I am using the “Arduino-Pico” core board package from earlephilhover (https://github.com/earlephilhower/arduino-pico), latest version 2.4.1

When trying to build SDFat examples (here I’m trying “bench” but I get the same error with every example I try), I get this build error:



F:\Arduino\libraries\SdFat\src/SdFat.h:452:2: warning: #warning File not defined because __has_include(FS.h) [-Wcpp]
  452 | #warning File not defined because __has_include(FS.h)
      |  ^~~~~~~
bench:69:1: error: 'File' does not name a type; did you mean 'SdFile'?
   69 | File file;
      | ^~~~
      | SdFile
F:\Arduino\libraries\SdFat\examples\bench\bench.ino: In function 'void loop()':
bench:170:8: error: 'file' was not declared in this scope
  170 |   if (!file.open("bench.dat", O_RDWR | O_CREAT | O_TRUNC)) {
      |        ^~~~
bench:193:5: error: 'file' was not declared in this scope
  193 |     file.truncate(0);
      |     ^~~~
bench:236:5: error: 'file' was not declared in this scope
  236 |     file.rewind();
      |     ^~~~
bench:272:3: error: 'file' was not declared in this scope
  272 |   file.close();
      |   ^~~~


About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 21 (9 by maintainers)

Most upvoted comments

Looks like my test driver might work with Pico. I attached a zip with SdSpiLibDriver.h. You need to replace the file located at:

libraries/SdFat/src/SpiDriver/SdSpiLibDriver.h

Then edit libraries/SdFat/src/SdFatConfig.h and change USE_SPI_ARRAY_TRANSFER to two.

/**
 * If USE_SPI_ARRAY_TRANSFER is non-zero and the standard SPI library is
 * use, the array transfer function, transfer(buf, size), will be used.
 * This option will allocate up to a 512 byte temporary buffer for send.
 * This may be faster for some boards.  Do not use this with AVR boards.
 */
#ifndef USE_SPI_ARRAY_TRANSFER
#define USE_SPI_ARRAY_TRANSFER 2  // <<----------------------- was zero
#endif  // USE_SPI_ARRAY_TRANSFER

I have implemented three new choices for USE_SPI_ARRAY_TRANSFER. First try two, this will use a nullptr for both array send and receive. If two doesn’t work try three this uses a dummy array for rxBuf in send. Three is needed for the Feather M4. Finally four uses dummy buffers for both receive and send. Four is needed for STM32.

Here is the improvement I get on Feather M4:

With single byte transfer:

write speed and latency speed,max,min,avg KB/Sec,usec,usec,usec 1347.71,3454,378,379 1348.07,395,378,379

read speed and latency speed,max,min,avg KB/Sec,usec,usec,usec 1323.10,388,385,386 1322.75,388,385,386

With USE_SPI_ARRAY_TRANSFER set to three:

write speed and latency speed,max,min,avg KB/Sec,usec,usec,usec 2791.74,199,182,182 2791.74,198,182,182

read speed and latency speed,max,min,avg KB/Sec,usec,usec,usec 2812.15,183,181,181 2812.15,183,181,181

Click on this to download the patch.

SdSpiLibDriver.zip

Edit: looks like @earlephilhower already has a version with the change. Wow I often fight for months to get changes/fixes with SPI libraries.

Could you do an experiment to see how fast the three argument SPI will be.

Set USE_SPI_ARRAY_TRANSFER to two and change these two lines in SdSpiLibDriver.h

Line 70 from: m_spi->transfer(nullptr, buf, count); To: SPI.transfer(nullptr, buf, count);

Line 105 from: m_spi->transfer(buf, nullptr, count); to: SPI.transfer(buf, nullptr, count);

I use a pointer since many boards including Pico have more than one SPI port. This allows dedicating a second port to the SD.

This should allow access to the three argument transfer.

If a different version is used by the board package there could still be problems. Philhower depends on internals of SdFat I never intended users to access.

I would move the current version from the library folder and try an unzipped version from github.