Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix erase sector failure on S25FL127S #101

Merged
merged 4 commits into from
Nov 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 51 additions & 42 deletions examples/TestFlash/TestFlash.ino
Original file line number Diff line number Diff line change
Expand Up @@ -337,22 +337,25 @@ void loop() {
}
addr = Serial.parseInt();
Serial.println(addr);
flash.eraseSector(addr);
clearprintBuffer();
sprintf(printBuffer, "A 4KB sector containing address %d has been erased", addr);
Serial.println(printBuffer);
printReadChoice();
while (!Serial.available()) {
}
uint8_t choice = Serial.parseInt();
Serial.println(choice);
if (choice == 1) {
printOutputChoice();
if (flash.eraseSector(addr)) {
clearprintBuffer();
sprintf(printBuffer, "A 4KB sector containing address %d has been erased", addr);
Serial.println(printBuffer);
printReadChoice();
while (!Serial.available()) {
}
uint8_t outputType = Serial.parseInt();
Serial.println(outputType);
printPage(addr, outputType);
uint8_t choice = Serial.parseInt();
Serial.println(choice);
if (choice == 1) {
printOutputChoice();
while (!Serial.available()) {
}
uint8_t outputType = Serial.parseInt();
Serial.println(outputType);
printPage(addr, outputType);
}
} else {
Serial.println("Erasing sector failed");
}
printLine();
printNextCMD();
Expand All @@ -368,22 +371,25 @@ void loop() {
}
addr = Serial.parseInt();
Serial.println(addr);
flash.eraseBlock32K(addr);
clearprintBuffer();
sprintf(printBuffer, "A 32KB block containing address %d has been erased", addr);
Serial.println(printBuffer);
printReadChoice();
while (!Serial.available()) {
}
uint8_t choice = Serial.parseInt();
Serial.println(choice);
if (choice == 1) {
printOutputChoice();
if (flash.eraseBlock32K(addr)) {
clearprintBuffer();
sprintf(printBuffer, "A 32KB block containing address %d has been erased", addr);
Serial.println(printBuffer);
printReadChoice();
while (!Serial.available()) {
}
uint8_t outputType = Serial.parseInt();
Serial.println(outputType);
printPage(addr, outputType);
uint8_t choice = Serial.parseInt();
Serial.println(choice);
if (choice == 1) {
printOutputChoice();
while (!Serial.available()) {
}
uint8_t outputType = Serial.parseInt();
Serial.println(outputType);
printPage(addr, outputType);
}
} else {
Serial.println("Erasing block 32K failed");
}
printLine();
printNextCMD();
Expand All @@ -399,22 +405,25 @@ void loop() {
}
addr = Serial.parseInt();
Serial.println(addr);
flash.eraseBlock64K(addr);
clearprintBuffer();
sprintf(printBuffer, "A 64KB block containing address %d has been erased", addr);
Serial.println(printBuffer);
printReadChoice();
while (!Serial.available()) {
}
uint8_t choice = Serial.parseInt();
Serial.println(choice);
if (choice == 1) {
printOutputChoice();
if (flash.eraseBlock64K(addr)) {
clearprintBuffer();
sprintf(printBuffer, "A 64KB block containing address %d has been erased", addr);
Serial.println(printBuffer);
printReadChoice();
while (!Serial.available()) {
}
uint8_t outputType = Serial.parseInt();
Serial.println(outputType);
printPage(addr, outputType);
uint8_t choice = Serial.parseInt();
Serial.println(choice);
if (choice == 1) {
printOutputChoice();
while (!Serial.available()) {
}
uint8_t outputType = Serial.parseInt();
Serial.println(outputType);
printPage(addr, outputType);
}
} else {
Serial.println("Erasing block 64K failed");
}
printLine();
printNextCMD();
Expand Down
6 changes: 5 additions & 1 deletion src/FLASHIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,22 @@ bool SPIFlash::_beginSPI(uint8_t opcode) {
_nextByte(WRITE, opcode);
_nextByte(WRITE, DUMMYBYTE);
_transferAddress();
break;

case SECTORERASE:
_nextByte(WRITE, opcode);
_transferAddress();
break;

case BLOCK32ERASE:
_nextByte(WRITE, opcode);
_transferAddress();
break;

case BLOCK64ERASE:
_nextByte(WRITE, opcode);
_transferAddress();
break;

default:
_nextByte(WRITE, opcode);
Expand Down Expand Up @@ -397,7 +401,7 @@ bool SPIFlash::_notBusy(uint32_t timeout) {
}
_time++;
} while ((micros() - _time) < timeout);
if ((micros() - _time) == timeout) {
if (timeout <= (micros() - _time)) {
return false;
}
return true;
Expand Down
6 changes: 3 additions & 3 deletions src/SPIFlash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ bool SPIFlash::eraseSector(uint32_t _addr) {
_beginSPI(SECTORERASE); //The address is transferred as a part of this function
_endSPI();

if(!_notBusy(500L)) {
if(!_notBusy(500 * 1000L)) {
return false; //Datasheet says erasing a sector takes 400ms max
}
//_writeDisable();
Expand All @@ -753,7 +753,7 @@ bool SPIFlash::eraseBlock32K(uint32_t _addr) {
_beginSPI(BLOCK32ERASE);
_endSPI();

if(!_notBusy(1*S)) {
if(!_notBusy(1000 * 1000L)) {
return false; //Datasheet says erasing a sector takes 400ms max
}
_writeDisable();
Expand All @@ -777,7 +777,7 @@ bool SPIFlash::eraseBlock64K(uint32_t _addr) {
_beginSPI(BLOCK64ERASE);
_endSPI();

if(!_notBusy(1200L)) {
if(!_notBusy(1200 * 1000L)) {
return false; //Datasheet says erasing a sector takes 400ms max
}
#ifdef RUNDIAGNOSTIC
Expand Down