Browse Source

Merge pull request #18 from helen-fornazier/master

Bugfix blockSize (Spansion chip, model with 256K sector size)
main
Paul Stoffregen 8 years ago
parent
commit
615aec66a8
3 changed files with 10 additions and 6 deletions
  1. +8
    -4
      SerialFlashChip.cpp
  2. +1
    -1
      examples/CopyFromSerial/CopyFromSerial.ino
  3. +1
    -1
      examples/EraseEverything/EraseEverything.ino

+ 8
- 4
SerialFlashChip.cpp View File

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]);

+ 1
- 1
examples/CopyFromSerial/CopyFromSerial.ino View File

SerialFlash.begin(CSPIN); SerialFlash.begin(CSPIN);


//We start by formatting the flash... //We start by formatting the flash...
uint8_t id[3];
uint8_t id[5];
SerialFlash.readID(id); SerialFlash.readID(id);
SerialFlash.eraseAll(); SerialFlash.eraseAll();

+ 1
- 1
examples/EraseEverything/EraseEverything.ino View File

delay(100); delay(100);


SerialFlash.begin(FlashChipSelect); SerialFlash.begin(FlashChipSelect);
unsigned char id[3];
unsigned char id[5];
SerialFlash.readID(id); SerialFlash.readID(id);
unsigned long size = SerialFlash.capacity(id); unsigned long size = SerialFlash.capacity(id);



Loading…
Cancel
Save