Content originally posted in LPCWare by capiman on Tue Nov 05 04:40:50 MST 2013
I think you must prepare before erase (what you are already doing),
and then prepare again, before copy RAM to flash.
You have at the bottom a "blank check" which still uses sector 5, but i think does not matter at the moment.
Try to delete the following in your code:
int javab =0 ;
int *a[256];
Both are not used and especially "a" can make problems. You have a second one, which is ok.
for (b=0;b<256;b++)
a[ b ]=b;
a[ b ]=b;
Could be a cut&paste error, but the second "a[ b ]=b;" can make problems, because at the end of the loop b = 256 (to abort the loop),
so when you do the second "a[ b ]=b;" (which is behind/outside the loop), it is
a[256] = 256;
which is writing behind the variable "a". This can destroy any other variable (random, what is behind "a").