Dionysus
Active member
Good afternoon! I'm using a Teensy 4.0 with the Audio shield (rev D) and I've just tried to attach a W25Q128JVSIQ-ND flash memory chip. This was unlike any soldering I've ever done before, so I'm quite willing to believe that I'd attached it pooorly or somehow destroyed it in the process, but I'm not sure how to go about debugging that.
I've been trying the verious SerialFlash examples. Starting with EraseEverything, which returns:
And then the RawHardwareTest, which gives me:
In a previous post, Paul said that all zeroes for the ID line indicated a faulty chip and, indeed, I was getting all zeroes. I went back and poked at the solder a bit, though, and now it's giving me 6F 40 18. Is that a good sign? I'm not sure how to know if the hardware is working, let alone the software.
Finally, I tried the CopyFromSD code, which was able to read the SD card, but said, "unable to create file" every time. I'll attach my version of that here—I did (eventually) remember to change the SCK to 13 and the MOSI to 11, but there might be a ton of other things that I'm missing. I'm also attaching a photo, but I'm not sure if itwill be useful.
Thank you in advance for any suggestions!
I've been trying the verious SerialFlash examples. Starting with EraseEverything, which returns:
Code:
Flash Memory has 16777216 bytes.
Erasing ALL Flash Memory:
estimated wait: 52 seconds.
Yes, full chip erase is SLOW!
Erase completed
actual wait: 0 seconds.
And then the RawHardwareTest, which gives me:
Code:
Raw SerialFlash Hardware Test
Read Chip Identification:
JEDEC ID: 6F 40 18
Part Nummber: (unknown chip)
Memory Size: 16777216 bytes
Block Size: 65536 bytes
Reading Chip...
Previous data found at address 0
You must fully erase the chip before this test
found this: 7F FF 7F FF 7F FF 7F FF
correct: 00 00 00 00 15 F5 95 4B
Tests Failed :{
The flash chip may be left in an improper state.
You might need to power cycle to return to normal.
In a previous post, Paul said that all zeroes for the ID line indicated a faulty chip and, indeed, I was getting all zeroes. I went back and poked at the solder a bit, though, and now it's giving me 6F 40 18. Is that a good sign? I'm not sure how to know if the hardware is working, let alone the software.
Finally, I tried the CopyFromSD code, which was able to read the SD card, but said, "unable to create file" every time. I'll attach my version of that here—I did (eventually) remember to change the SCK to 13 and the MOSI to 11, but there might be a ton of other things that I'm missing. I'm also attaching a photo, but I'm not sure if itwill be useful.
Thank you in advance for any suggestions!
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 = 6; // digital pin for flash chip CS pin
//const int FlashChipSelect = 21; // Arduino 101 built-in SPI Flash
void setup() {
//uncomment these if using Teensy audio shield
SPI.setSCK(13); // Audio shield has SCK on pin 14
SPI.setMOSI(11); // Audio shield has MOSI on pin 7
//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);
Serial.begin(9600);
// 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");
}
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);
}
}