Direct address of samples on flash chip

Status
Not open for further replies.

FRS

Active member
If I transfer RAW samples from SD card to the flash chip, then use the ListFiles examples to read what is on the flash chip it serial prints the sample name and file size.

My question is how to determine the beginning address of each sample on the flash chip?

It is my understanding that the flash allocation table takes up the first 4096 byte addresses of the flash chip.
So when I do a ListFiles on flash chip, is it correct that the first sample/or file listed has a begin address of 4096, while the second file listed will have a start address of 4096 + length of first sample?

Is there any easy way to serial print the start address of each file along with the file size when doing ListFiles example?

I'm wanting to hardcode the start and length of each sample into code, to eliminate the use of filenames to look up this information at sample Play time.
 
That does help, but I don't think I'm coding it correctly. I can't seem to get the code to compile.

My code:

#include <ParallelFlash.h>

void setup() {

// wait for Arduino Serial Monitor
while (!Serial) ;
delay(100);
Serial.println("All Files on Flash chip:");

if (!ParallelFlash.begin()) {
error("Unable to access Flash chip");
}

ParallelFlash.opendir();
unsigned int count = 0;
uint32_t fileStartsAt; //I ADDED THIS VARIABLE


while (1) {
char filename[64];
unsigned long filesize;

if (ParallelFlash.readdir(filename, sizeof(filename), filesize)) {
Serial.print(" ");
Serial.print(filename);
spaces(20 - strlen(filename));
Serial.print(" ");
Serial.print(filesize);
Serial.print(" bytes");
//THE FOLLOWING I HAVE ADDED TO TRY TO PASS THE SAMLE/FILE START ADDRESS TO PRINT IT OUT
//BUT THE CODE FAILS TO COMPILE
// fileStartsAt = file.getFlashAddress();
// fileStartsAt = ParallelFlash.getFlashAddress();
fileStartsAt = ParallelFlashFile.getFlashAddress();
Serial.print(" ");
Serial.print("Start Address: ");
Serial.print(fileStartsAt);
Serial.println();
} else {
break; // no more files
}
}
}

void spaces(int num) {
for (int i=0; i < num; i++) {
Serial.print(" ");
}
}

void loop() {
}

void error(const char *message) {
while (1) {
Serial.println(message);
delay(2500);
}
}
 
use it like this (for example):
Code:
SerialFlashFile file = SerialFlash.open(filename);
  uint32_t sz = file.size();
  uint32_t pos = file.getFlashAddress();
 
Status
Not open for further replies.
Back
Top