|
|
|
|
|
|
|
|
void SerialFlashChip::eraseAll() |
|
|
void SerialFlashChip::eraseAll() |
|
|
{ |
|
|
{ |
|
|
if (busy) wait(); |
|
|
if (busy) wait(); |
|
|
uint8_t id[3]; |
|
|
|
|
|
|
|
|
uint8_t id[5]; |
|
|
readID(id); |
|
|
readID(id); |
|
|
//Serial.printf("ID: %02X %02X %02X\n", id[0], id[1], id[2]); |
|
|
//Serial.printf("ID: %02X %02X %02X\n", id[0], id[1], id[2]); |
|
|
if (id[0] == 0x20 && id[2] >= 0x20 && id[2] <= 0x22) { |
|
|
if (id[0] == 0x20 && id[2] >= 0x20 && id[2] <= 0x22) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool SerialFlashChip::begin(uint8_t pin) |
|
|
bool SerialFlashChip::begin(uint8_t pin) |
|
|
{ |
|
|
{ |
|
|
uint8_t id[3]; |
|
|
|
|
|
|
|
|
uint8_t id[5]; |
|
|
uint8_t f; |
|
|
uint8_t f; |
|
|
uint32_t size; |
|
|
uint32_t size; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (id[0] == ID0_SPANSION) { |
|
|
if (id[0] == ID0_SPANSION) { |
|
|
// Spansion has separate suspend commands |
|
|
// Spansion has separate suspend commands |
|
|
f |= FLAG_DIFF_SUSPEND; |
|
|
f |= FLAG_DIFF_SUSPEND; |
|
|
if (size >= 67108864) { |
|
|
|
|
|
// Spansion chips >= 512 mbit use 256K sectors |
|
|
|
|
|
|
|
|
if (!id[4]) { |
|
|
|
|
|
// Spansion chips with id[4] == 0 use 256K sectors |
|
|
f |= FLAG_256K_BLOCKS; |
|
|
f |= FLAG_256K_BLOCKS; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
buf[0] = SPI.transfer(0); // manufacturer ID |
|
|
buf[0] = SPI.transfer(0); // manufacturer ID |
|
|
buf[1] = SPI.transfer(0); // memory type |
|
|
buf[1] = SPI.transfer(0); // memory type |
|
|
buf[2] = SPI.transfer(0); // capacity |
|
|
buf[2] = SPI.transfer(0); // capacity |
|
|
|
|
|
if (buf[0] == ID0_SPANSION) { |
|
|
|
|
|
buf[3] = SPI.transfer(0); // ID-CFI |
|
|
|
|
|
buf[4] = SPI.transfer(0); // sector size |
|
|
|
|
|
} |
|
|
CSRELEASE(); |
|
|
CSRELEASE(); |
|
|
SPI.endTransaction(); |
|
|
SPI.endTransaction(); |
|
|
//Serial.printf("ID: %02X %02X %02X\n", buf[0], buf[1], buf[2]); |
|
|
//Serial.printf("ID: %02X %02X %02X\n", buf[0], buf[1], buf[2]); |