self.serialport.write(chr(count>>8));
#print "count=%02x, len(data)=%04x" % (count,len(data));
+
if count!=0:
- for d in data:
- self.serialport.write(chr(d));
+ for i in range(0,count):
+ #print "Converting %02x at %i" % (data[i],i)
+ data[i]=chr(data[i]);
+ outstr=''.join(data);
+ self.serialport.write(outstr);
if not self.besilent:
self.readcmd();
self.SPIpokebytes(adr,[val]);
def SPIpokebytes(self,adr,data):
#Used to be 24 bits, BE, not 32 bits, LE.
-# adranddata=[(adr&0xFF0000)>>16,
-# (adr&0xFF00)>>8,
-# adr&0xFF
-# ]+data;
adranddata=[adr&0xFF,
(adr&0xFF00)>>8,
(adr&0xFF0000)>>16,
0, #MSB
]+data;
-
+ #print "%06x: poking %i bytes" % (adr,len(data));
self.writecmd(0x01,0x03,
len(adranddata),adranddata);
file = open(f, mode='rb')
i=start;
- bits=0;
+ bytes=0;
while i<=stop:
- data=client.SPIpeekblock(i,255);
+ data=client.SPIpeekblock(i);
print "Verified %06x." % i;
for j in data:
if i<stop:
- bits|=ord(file.read(1))^ord(j);
+ #bits|=ord(file.read(1))^ord(j);
+ a=ord(file.read(1));
+ b=ord(j);
+ if a!=b:
+ print "%06x: %02x/%02x" % (i,a,b);
+ bytes+=1;
i+=1;
- if bits!=0:
- print "Bits don't match."
+ if bytes!=0:
+ print "%i bytes don't match." % bytes
file.close()
#N.B., chunksize must be an even fraction of 0x100.
#Increasing above 0x200 doesn't help, 0x100 might be good enough.
- chunksize=0x200;
+ chunksize=0x100;
+ #chunksize=0x1000;
while i<=stop:
bytes=range(0,chunksize);
SETSS;
- //while(spiflash_status()&0x01);//minor performance impact
+ //if(len!=0x100)
+ // debugstr("Non-standard block size.");
+
+ while(spiflash_status()&0x01);//minor performance impact
+
+ spiflash_setstatus(0x02);
+ spiflash_wrten();
//Are these necessary?
//spiflash_setstatus(0x02);
long off=0;//offset of this block
int blen;//length of this block
SETSS;
- spiflash_setstatus(0x02);
- spiflash_wrten();
while(off<len){
//calculate block length
P5OUT|=SS; //Raise !SS to end transaction.
}
+
+//! Erase a sector.
+void spiflash_erasesector(unsigned long adr){
+ //debugstr("Erasing a 4kB sector.");
+
+ //Write enable.
+ spiflash_wrten();
+
+ //Begin
+ CLRSS;
+
+ //Second command.
+ spitrans8(0x20);
+ //Send address
+ spitrans8((adr&0xFF0000)>>16);
+ spitrans8((adr&0xFF00)>>8);
+ spitrans8(adr&0xFF);
+
+ SETSS;
+ while(spiflash_status()&0x01);//while busy
+ //debugstr("Erased.");
+}
+
+
//! Handles a monitor command.
void spihandle(unsigned char app,
unsigned char verb,
cmddata+4,//buf
len-4);//len
- txdata(app,verb,len);
+ txdata(app,verb,0);
break;
#define u16 unsigned int
#define u32 unsigned long
-
#ifndef CMDDATALEN
+//512 bytes
#define CMDDATALEN 0x204
+//4k
+//#define CMDDATALEN 0x1004
#endif
//! Global data buffer.
void spiflash_pokeblocks(unsigned long adr,
unsigned char *buf,
unsigned int len);
+
+
+//! Enable SPI writing
+void spiflash_wrten();
+
+//! Read and write an SPI byte.
+unsigned char spitrans8(unsigned char byte);
+//! Grab the SPI flash status byte.
+unsigned char spiflash_status();
+//! Erase a sector.
+void spiflash_erasesector(unsigned long adr);