Browse Source

Fix program/erase suspend on Spansion chips

main
PaulStoffregen 9 years ago
parent
commit
b2cbd9da94
2 changed files with 25 additions and 8 deletions
  1. +15
    -5
      SerialFlashChip.cpp
  2. +10
    -3
      examples/RawHardwareTest/RawHardwareTest.ino

+ 15
- 5
SerialFlashChip.cpp View File

@@ -80,7 +80,7 @@ void SerialFlashChip::wait(void)
void SerialFlashChip::read(uint32_t addr, void *buf, uint32_t len)
{
uint8_t *p = (uint8_t *)buf;
uint8_t b, f, status;
uint8_t b, f, status, cmd;

memset(p, 0, len);
f = flags;
@@ -110,8 +110,11 @@ void SerialFlashChip::read(uint32_t addr, void *buf, uint32_t len)
SPI.transfer(0x06); // write enable (Micron req'd)
CSRELEASE();
delayMicroseconds(1);
cmd = 0x75; //Suspend program/erase for almost all chips
// but Spansion just has to be different for program suspend!
if ((f & FLAG_DIFF_SUSPEND) && (b == 1)) cmd = 0x85;
CSASSERT();
SPI.transfer(0x75); // Suspend program/erase
SPI.transfer(cmd); // Suspend command
CSRELEASE();
if (f & FLAG_STATUS_CMD70) {
// Micron chips don't actually suspend until flags read
@@ -122,7 +125,12 @@ void SerialFlashChip::read(uint32_t addr, void *buf, uint32_t len)
} while (!(status & 0x80));
CSRELEASE();
} else {
delayMicroseconds(20); // Tsus = 20us (Winbond)
CSASSERT();
SPI.transfer(0x05);
do {
status = SPI.transfer(0);
} while ((status & 0x01));
CSRELEASE();
}
} else {
// chip is busy with an operation that can not suspend
@@ -157,11 +165,13 @@ void SerialFlashChip::read(uint32_t addr, void *buf, uint32_t len)
} while (len > 0);
if (b) {
CSASSERT();
SPI.transfer(0x06); // write enable (Micro req'd)
SPI.transfer(0x06); // write enable (Micron req'd)
CSRELEASE();
delayMicroseconds(1);
cmd = 0x7A;
if ((f & FLAG_DIFF_SUSPEND) && (b == 1)) cmd = 0x8A;
CSASSERT();
SPI.transfer(0x7A); // Resume program/erase
SPI.transfer(cmd); // Resume program/erase
CSRELEASE();
}
SPI.endTransaction();

+ 10
- 3
examples/RawHardwareTest/RawHardwareTest.ino View File

@@ -38,7 +38,16 @@ void setup() {
Serial.println("Raw SerialFlash Hardware Test");
SerialFlash.begin();

test();
if (test()) {
Serial.println();
Serial.println("All Tests Passed :-)");
} else {
Serial.println();
Serial.println("Tests Failed :{");
Serial.println();
Serial.println("The flash chip may be left in an improper state.");
Serial.println("You might need to power cycle to return to normal.");
}
}


@@ -355,8 +364,6 @@ bool test() {



Serial.println();
Serial.println("All Tests Passed :-)");
return true;
}


Loading…
Cancel
Save