Maybe I am missing something obvious here but I can only erase and rewrite to sectors 0 to 31. From sector 32 I can only write once after a complete chip erase.
Any idea what I am doing wrong?
I wrote a little test program to recreate the problem:
using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
namespace FlashTest
{
public partial class Program
{
void ProgramStarted()
{
//flash.EraseChip();
for (int i = 30; i < 34; i++)
{
TestSector(i);
}
}
void TestSector(int sector)
{
bool resultOK = true;
int sectorSize = 4 * 1024;
byte[] b;
// erase sector
flash.EraseSector(sector, 1);
// test whether all bytes in sector equal 255
b = flash.ReadData(sector * sectorSize, sectorSize);
for (int i = 0; i < sectorSize; i++)
{
if (b[i] != 255)
{
Debug.Print("ERROR: not all bytes equal 255 in sector " + sector);
resultOK = false;
break;
}
}
// write to sector
// set all bytes in sector to 111
b = new byte[sectorSize];
for (int i = 0; i < sectorSize; i++)
{
b[i] = 111;
}
flash.WriteData(sector * sectorSize, b);
// test whether all bytes in sector are 111
b = flash.ReadData(sector * sectorSize, sectorSize);
for (int i = 0; i < sectorSize; i++)
{
if (b[i] != 111)
{
Debug.Print("ERROR: not all bytes equal 111 in sector " + sector);
resultOK = false;
break;
}
}
if (resultOK)
{
Debug.Print("Sector " + sector + " OK");
}
else
{
Debug.Print("Sector " + sector + " ERROR");
}
}
}
}
Test results from first run after chip erase:
Sector 30 OK
Sector 31 OK
Sector 32 OK
Sector 33 OK
Test results from second run after chip erase:
Sector 30 OK
Sector 31 OK
ERROR: not all bytes equal 255 in sector 32
Sector 32 ERROR
ERROR: not all bytes equal 255 in sector 33
Sector 33 ERROR