darioconcilio
Well-known member
Hi to all,
I'm trying CopyFromSD with S25FL256S Flash.
I'm not sure if I connected correctly flash and SD shield (Sparkfun with red shield)
Flash to Teensy 3.2:
CS => 9
SCK => 14
SO => 7
SI => 8
SD to Teensy 3.2:
CS => 10
SCK => 13
DO => 12
DI => 11
Now:
EraseEverything : OK
Output:
Flash Memory has 33554432 bytes.
Erasing ALL Flash Memory:
estimated wait: 67 seconds.
Yes, full chip erase is SLOW!
............................................................
Erase completed
actual wait: 62 seconds.
RawHardwareTest: OK
Raw SerialFlash Hardware Test
Read Chip Identification:
JEDEC ID: 1 2 19
Part Nummber: S25FL256S
Memory Size: 33554432 bytes
Block Size: 65536 bytes
Reading Chip...
Writing 16384 signatures
Double Checking All Signatures:
all 16384 signatures read ok
Checking Signature Pairs
all 8191 signature pairs read ok
Checking Read-While-Write (Program Suspend)
write 256 bytes at 256
write time was 418 microseconds.
read-while-writing: 00 00 00 00 15 F5 95 4B
test passed, good read while writing
Checking Read-While-Erase (Erase Suspend)
erase time was 108330 microseconds.
erase correctly erased 65536 bytes
read-while-erasing: 00 00 00 00 15 F5 95 4B
test passed, good read while erasing
All Tests Passed
Test data was written to your chip. You must run
EraseEverything before using this chip for files.
CardInfo: OK
Initializing SD card...Wiring is correct and a card is present.
Card type: SD2
Volume type is FAT16
Volume size (bytes): 2032271360
Volume size (Kbytes): 1984640
Volume size (Mbytes): 1938
Files found on the card (name, date and size in bytes):
SETUP.CFG 2000-01-01 01:00:00 81
FOLDER1/ 2016-02-12 14:24:18
FILE1.RAW 2016-05-21 16:52:26 2887332
FILE2.RAW 2016-05-31 20:15:46 97180
FILE3.RAW 2016-05-31 20:15:54 41448
[...]
Now I would to exec CopyFromSD:
One question: I think that SD could contains a list of file without folders, is it correct? Or does it keep creation folder also? (I think no.)
Now I try to exec and it responses this:
Copy all files from SD Card to SPI Flash
Unable to access SD card
Unable to access SD card
Where I wrong?
I'm trying CopyFromSD with S25FL256S Flash.
I'm not sure if I connected correctly flash and SD shield (Sparkfun with red shield)
Flash to Teensy 3.2:
CS => 9
SCK => 14
SO => 7
SI => 8
SD to Teensy 3.2:
CS => 10
SCK => 13
DO => 12
DI => 11
Now:
EraseEverything : OK
Output:
Flash Memory has 33554432 bytes.
Erasing ALL Flash Memory:
estimated wait: 67 seconds.
Yes, full chip erase is SLOW!
............................................................
Erase completed
actual wait: 62 seconds.
RawHardwareTest: OK
Raw SerialFlash Hardware Test
Read Chip Identification:
JEDEC ID: 1 2 19
Part Nummber: S25FL256S
Memory Size: 33554432 bytes
Block Size: 65536 bytes
Reading Chip...
Writing 16384 signatures
Double Checking All Signatures:
all 16384 signatures read ok
Checking Signature Pairs
all 8191 signature pairs read ok
Checking Read-While-Write (Program Suspend)
write 256 bytes at 256
write time was 418 microseconds.
read-while-writing: 00 00 00 00 15 F5 95 4B
test passed, good read while writing
Checking Read-While-Erase (Erase Suspend)
erase time was 108330 microseconds.
erase correctly erased 65536 bytes
read-while-erasing: 00 00 00 00 15 F5 95 4B
test passed, good read while erasing
All Tests Passed
Test data was written to your chip. You must run
EraseEverything before using this chip for files.
CardInfo: OK
Initializing SD card...Wiring is correct and a card is present.
Card type: SD2
Volume type is FAT16
Volume size (bytes): 2032271360
Volume size (Kbytes): 1984640
Volume size (Mbytes): 1938
Files found on the card (name, date and size in bytes):
SETUP.CFG 2000-01-01 01:00:00 81
FOLDER1/ 2016-02-12 14:24:18
FILE1.RAW 2016-05-21 16:52:26 2887332
FILE2.RAW 2016-05-31 20:15:46 97180
FILE3.RAW 2016-05-31 20:15:54 41448
[...]
Now I would to exec CopyFromSD:
One question: I think that SD could contains a list of file without folders, is it correct? Or does it keep creation folder also? (I think no.)
Now I try to exec and it responses this:
Copy all files from SD Card to SPI Flash
Unable to access SD card
Unable to access SD card
Code:
#include <SerialFlash.h>
#include <SD.h>
#include <SPI.h>
const int SDchipSelect = 10; // Audio Shield has SD card CS on pin 10
const int FlashChipSelect = 9; // digital pin for flash chip CS pin
void setup() {
//uncomment these if using Teensy audio shield
SPI.setSCK(14); // Audio shield has SCK on pin 14
SPI.setMOSI(7); // Audio shield has MOSI on pin 7
SPI.setMISO(8);
//uncomment these if you have other SPI chips connected
//to keep them disabled while using only SerialFlash
//pinMode(4, INPUT_PULLUP);
//pinMode(10, INPUT_PULLUP);
// wait up to 10 seconds for Arduino Serial Monitor
unsigned long startMillis = millis();
while (!Serial && (millis() - startMillis < 10000)) ;
delay(100);
Serial.println("Copy all files from SD Card to SPI Flash");
if (!SD.begin(SDchipSelect)) {
error("Unable to access SD card");
}
if (!SerialFlash.begin(FlashChipSelect)) {
error("Unable to access SPI Flash chip");
}
int count = 0;
File rootdir = SD.open("/");
while (1) {
// open a file from the SD card
Serial.println();
File f = rootdir.openNextFile();
if (!f) break;
const char *filename = f.name();
Serial.print(filename);
Serial.print(" ");
unsigned long length = f.size();
Serial.println(length);
// check if this file is already on the Flash chip
if (SerialFlash.exists(filename)) {
Serial.println(" already exists on the Flash chip");
SerialFlashFile ff = SerialFlash.open(filename);
if (ff && ff.size() == f.size()) {
Serial.println(" size is the same, comparing data...");
if (compareFiles(f, ff) == true) {
Serial.println(" files are identical :)");
f.close();
ff.close();
continue; // advance to next file
} else {
Serial.println(" files are different");
}
} else {
Serial.print(" size is different, ");
Serial.print(ff.size());
Serial.println(" bytes");
}
// delete the copy on the Flash chip, if different
Serial.println(" delete file from Flash chip");
SerialFlash.remove(filename);
}
// create the file on the Flash chip and copy data
if (SerialFlash.create(filename, length)) {
SerialFlashFile ff = SerialFlash.open(filename);
if (ff) {
Serial.print(" copying");
// copy data loop
unsigned long count = 0;
unsigned char dotcount = 9;
while (count < length) {
char buf[256];
unsigned int n;
n = f.read(buf, 256);
ff.write(buf, n);
count = count + n;
Serial.print(".");
if (++dotcount > 100) {
Serial.println();
dotcount = 0;
}
}
ff.close();
if (dotcount > 0) Serial.println();
} else {
Serial.println(" error opening freshly created file!");
}
} else {
Serial.println(" unable to create file");
}
f.close();
}
rootdir.close();
delay(10);
Serial.println("Finished All Files");
}
bool compareFiles(File &file, SerialFlashFile &ffile) {
file.seek(0);
ffile.seek(0);
unsigned long count = file.size();
while (count > 0) {
char buf1[128], buf2[128];
unsigned long n = count;
if (n > 128) n = 128;
file.read(buf1, n);
ffile.read(buf2, n);
if (memcmp(buf1, buf2, n) != 0) return false; // differ
count = count - n;
}
return true; // all data identical
}
void loop() {
}
void error(const char *message) {
while (1) {
Serial.println(message);
delay(2500);
}
}
Where I wrong?