Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Added more features and sped up the write function by streaming the bytes verbatim rather than as decimal text values.
  • Loading branch information
danriches authored Sep 21, 2022
1 parent 691c4cc commit d27e3a2
Showing 1 changed file with 93 additions and 26 deletions.
119 changes: 93 additions & 26 deletions sketch_sst39sf040_flash/sketch_sst39sf040_flash.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//Written poorly by mikemint64 - Then modified heavily by Dan Riches
//visit at mint64.home.blog
//Written by Dan Riches - 2022


#define WE 2
#define OE 3
Expand All @@ -10,7 +10,7 @@
#define RD0 44
#define RD7 51

#define debugOutput 0
#define debugOutput 1

void setCtrlPins(); //Setup control signals
void setAddrPinsOut(); //Setup address signals
Expand Down Expand Up @@ -38,36 +38,63 @@ long endAddressFromPC = 0;
int byteFromPC = 0;
boolean commandValid = 0;

long writeAddressCounter = 0;
long bytesWrittenCounter = 0;
boolean StreamMode = 0; //Set to 1 when the serial data isn't formatted and just a stream of 2048 bytes
long bytesToWrite = 0;

void recvWithStartEndMarkers()
{
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;

byte bc[256]; //Our byte buffer which needs to be bigger, say 256 bytes
//We need to check StreamMode == 1 and then ignore the start and end markers
// if (Serial.available() > 0) {
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();

if (recvInProgress == true) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
if(StreamMode == 0)
rc = Serial.read();
else
Serial.readBytes(bc, bytesToWrite);

else if (rc == startMarker) {
recvInProgress = true;
if(StreamMode == 1)
{
//Write each byte in the bc array using bytesToWrite as the max count
for(int c = 0; c < bytesToWrite; c++)
{
programData(bc[c], writeAddressCounter);
writeAddressCounter++;
}
Serial.println("Flash Written Successfully.");
StreamMode = 0;

} else
{
if (recvInProgress == true)
{
if (rc != endMarker)
{
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars)
{
ndx = numChars - 1;
}
}
else
{
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker)
{
recvInProgress = true;
}
}
}
}
Expand Down Expand Up @@ -131,7 +158,7 @@ void showNewData()

//parse the second paramter which is the byte value, or the end address in the case of a read (R) or dump (D)
strtokIndx = strtok(NULL, ",");
if(messageFromPC[0] == 'R' || messageFromPC[0] == 'D')
if(messageFromPC[0] == 'R' || messageFromPC[0] == 'D' || messageFromPC[0] == 'Y')
endAddressFromPC = atol(strtokIndx);
else
byteFromPC = atoi(strtokIndx);
Expand Down Expand Up @@ -190,11 +217,17 @@ void showNewData()
//Read Chip ID
if(messageFromPC[0] == 'I')
{
Serial.println("Reading Chip ID...");
Serial.print("Reading Chip ID... ");
EnterIDMode();
byte id = ReadID();
Serial.println(id, HEX);
ExitIDMode();

if(id != 0xB5 && id != 0xB6 && id != 0xB7)
{
Serial.println("Device is not made by SST, proceed with caution!");
}

if(id == 0xB5)
{
Serial.println("Device ID: SST39SF010A");
Expand Down Expand Up @@ -253,6 +286,36 @@ void showNewData()
printdump(i, j);
}
commandValid = 1;
Serial.println("");
Serial.println("Flash Dump Successful!");
}

//Set the write address counter
if(messageFromPC[0] == 'X')
{
//Reset Counters
writeAddressCounter = addressFromPC;
bytesWrittenCounter = 0;
Serial.print("SET Write Counters, start from ");
Serial.print(addressFromPC, HEX);
Serial.println(" - Done.");
commandValid = 1;
}

//Start the flash stream off (16 byte chunks)
if(messageFromPC[0] == 'Y')
{
Serial.println("Start of stream:");
StreamMode = 1;
commandValid = 1;
}

//Set the bytes to write counter
if(messageFromPC[0] == 'Z')
{
bytesToWrite = addressFromPC;
writeAddressCounter = 0;
commandValid = 1;
}

//Leave this part at the end, ie add new commands above this line
Expand All @@ -271,7 +334,7 @@ void setup()
setCtrlPins();
setAddrPinsOut();

Serial.begin(2000000);
Serial.begin(115200);
delay(2);
Serial.println("Arduino Flash Programmer Started");
Serial.println("Commands available are as follows:");
Expand Down Expand Up @@ -370,6 +433,10 @@ byte ReadID()
byte deviceID;

manufacturer = readData(0x00);
//if(manufacturer != 0xBF)
// return 0;
Serial.print("Manufacturer ID: ");
Serial.println(manufacturer);
deviceID = readData(0x01);

return deviceID;
Expand Down

0 comments on commit d27e3a2

Please sign in to comment.