Nano 33 ble: SDfat issues on SPI - Whats working and whats not. [SOLVED: HW MAX SPI CLOCK = 8 MHZ!!!!!)
mjs513 opened this issue · 2 comments
By defining legacy pins for the Nano 33 variants was able to get SDfat semi working. Some things works some don;t
SDinfo.ino: works
Custom List files on disk: works:
#include "SPI.h" // Only required if you use features in the SPI library.
#include "SdFat.h"
#include "sdios.h"
// Set DISABLE_CHIP_SELECT to disable a second SPI device.
// For example, with the Ethernet shield, set DISABLE_CHIP_SELECT
// to 10 to disable the Ethernet controller.
const int8_t DISABLE_CHIP_SELECT = -1;
// SD_FAT_TYPE = 0 for SdFat/File as defined in SdFatConfig.h,
// 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT.
#define SD_FAT_TYPE 3
// SD chip select pin.
#define SD_CS_PIN 9
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SD_SCK_MHZ(50))
//#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SD_SCK_MHZ(24))
//------------------------------------------------------------------------------
#if SD_FAT_TYPE == 0
SdFat sd;
File file;
File root;
#elif SD_FAT_TYPE == 1
SdFat32 sd;
File32 file;
File32 root;
#elif SD_FAT_TYPE == 2
SdExFat sd;
ExFile file;
ExFile root;
#elif SD_FAT_TYPE == 3
SdFs sd;
FsFile file;
FsFile root;
#endif // SD_FAT_TYPE
// Create a Serial output stream.
ArduinoOutStream cout(Serial);
//------------------------------------------------------------------------------
// Store error strings in flash to save RAM.
#define error(s) sd.errorHalt(&Serial, F(s))
//------------------------------------------------------------------------------
void setup() {
Serial.begin(9600);
// Wait for USB Serial
while (!Serial) {
yield();
}
delay(1000);
cout << F("Type any character to start\n");
while (!Serial.available()) {
yield();
}
// Initialize the SD card.
if (!sd.begin(SD_CONFIG)) {
sd.initErrorHalt(&Serial);
}
cout << F("\nList of files on the SD.\n");
sd.ls("/", LS_R);
}
//------------------------------------------------------------------------------
// Nothing happens in loop.
void loop() {}
bench.ino:
recognizes the card but hangs (too late now to debug) using array = 0
Use a freshly formatted SD for best performance.
Type any character to start
Type is FAT32
Card size: 15.93 GB (GB = 1E9 bytes)
Manufacturer ID: 0X3
OEM ID: SD
Product: SL16G
Revision: 8.0
Serial number: 0XE32D48F9
Manufacturing date: 4/2017
FILE_SIZE_MB = 5
BUF_SIZE = 512 bytes
Starting write test, please wait.
write speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec <================ hangs here. writing to sd card hangs.
if I set #define USE_SPI_ARRAY_TRANSFER 1 in sdfat_config.h same hang happens as if set to 0
Doing more debugging using spi driver = 1 and use array = 0 and 50mhz clock showed that the sketch was not really hanging but writes to the sdcard was extremely slow - to the point of making it useless. As a result changed write size to 1mb for the benchmark shows:
se a freshly formatted SD for best performance.
Type any character to start
Type is FAT32
Card size: 15.93 GB (GB = 1E9 bytes)
Manufacturer ID: 0X3
OEM ID: SD
Product: SL16G
Revision: 8.0
Serial number: 0XE32D48F9
Manufacturing date: 4/2017
FILE_SIZE_MB = 1
BUF_SIZE = 512 bytes
Starting write test, please wait.
write speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
1.23,417511,415069,415082
1.23,415405,415069,415081
Starting read test, please wait.
read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
1.24,413544,413482,413510
error: data check error
trying 1/1 for driver/array keeps giving me
Type any character to start
begin() failed
Do not reformat the SD.
SdError: 0X17,0XFF
same thing for 0/0 at 50mhz
ok. Found that the MAX SPI CLOCK FREQ Supported on the NRF52840 is 8Mhz.
Just remembered seeing that in one of the dts files but its a hardware limitation so you can not change. See: https://learn.adafruit.com/adafruit-itsybitsy-nrf52840-express/caution-using-spi-on-battery-power
also had put a LA on SPI when set to 50 Mhz:

Re-did testing with driver=1 and array=1 and got better performance:
write speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
81.40,8698,6256,6285
81.40,8697,6256,6285
Starting read test, please wait.
read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
109.70,4670,4638,4665
109.61,4670,4638,4668
Done