self.serialport.write(chr(app));
self.serialport.write(chr(verb));
-
+
+ #print "TX %02x %02x" % (app,verb);
+
#little endian 16-bit length
self.serialport.write(chr(count&0xFF));
self.serialport.write(chr(count>>8));
if count!=0:
for d in data:
self.serialport.write(chr(d));
-
- #self.serialport.flushOutput();
- #self.serialport.flushInput();
-
-
if not self.besilent:
self.readcmd();
"""Grab an SPI Flash ROM's JEDEC bytes."""
data=[0x9f, 0, 0, 0];
data=self.SPItrans(data);
+
self.JEDECmanufacturer=ord(data[1]);
self.JEDECtype=ord(data[2]);
self.JEDECcapacity=ord(data[3]);
def SPIpokebyte(self,adr,val):
self.SPIpokebytes(adr,[val]);
def SPIpokebytes(self,adr,data):
- #self.SPIwriteenable();
- adranddata=[(adr&0xFF0000)>>16,
- (adr&0xFF00)>>8,
- adr&0xFF
- ]+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;
+
self.writecmd(0x01,0x03,
len(adranddata),adranddata);
chars=list(file.read());
#N.B., chunksize must be an even fraction of 0x100.
- chunksize=0x100;
+ #Increasing above 0x200 doesn't help, 0x100 might be good enough.
+ chunksize=0x200;
- #client.silent(1);
while i<=stop:
bytes=range(0,chunksize);
for j in range(0,chunksize):
i+=chunksize;
if(i%0x1000==0):
print "Flashed %06x."%i;
- print "Done, ending silence.";
- #client.silent(0);
+
+
file.close()
#include `uname`.mak
-
GOODFET?=/dev/ttyUSB0
GCCINC=-T ldscripts/$(mcu).x
CCEXTRA?=
-CC=msp430-gcc -Wall -g -mmcu=$(mcu) -DGCC $(GCCINC) -I include $(CCEXTRA)
+CC=msp430-gcc -Wall -Os -g -mmcu=$(mcu) -DGCC $(GCCINC) -I include $(CCEXTRA)
#Define extra modules here.
moreapps?=
//! Read and write an SPI byte.
unsigned char spitrans8(unsigned char byte){
- unsigned int bit;
+ register unsigned int bit;
//This function came from the SPI Wikipedia article.
//Minor alterations.
CLRMOSI;
byte <<= 1;
- /* half a clock cycle before leading/rising edge */
- SPIDELAY(SPISPEED/2);
SETCLK;
-
- /* half a clock cycle before trailing/falling edge */
- SPIDELAY(SPISPEED/2);
-
+
/* read MISO on trailing edge */
byte |= READMISO;
CLRCLK;
SETSS; //Raise !SS to end transaction.
}
+//! Write many blocks to the SPI Flash.
+void spiflash_pokeblocks(unsigned long adr,
+ unsigned char *buf,
+ unsigned int len){
+ 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
+ blen=(len-off>0x100?0x100:len-off);
+ //write the block
+ spiflash_pokeblock(adr+off,
+ buf+off,
+ blen);
+ //add offset
+ off+=blen;
+ }
+}
//! Read a block to a buffer.
void spiflash_pokeblock(unsigned long adr,
unsigned char *buf,
unsigned int len){
- unsigned char i;
+ unsigned int i;
SETSS;
- spiflash_setstatus(0x02);
- spiflash_wrten();
+ //while(spiflash_status()&0x01);//minor performance impact
+
+ //Are these necessary?
+ //spiflash_setstatus(0x02);
+ //spiflash_wrten();
CLRSS; //Drop !SS to begin transaction.
spitrans8(0x02); //Poke command.
spitrans8(buf[i]);
SETSS; //Raise !SS to end transaction.
- while(spiflash_status()&0x01);
-
+ while(spiflash_status()&0x01);//minor performance impact
return;
}
case POKE://Poke up bytes from an SPI Flash ROM.
- spiflash_setstatus(0x02);
- spiflash_wrten();
-
- P5OUT&=~SS; //Drop !SS to begin transaction.
- spitrans8(0x02); //Poke command.
-
- //First three bytes are address, then data.
- for(i=0;i<len;i++)
- spitrans8(cmddata[i]);
- P5OUT|=SS; //Raise !SS to end transaction.
-
-
- while(spiflash_status()&0x01)
- P1OUT^=1;
-
- P1OUT&=~1;
+ spiflash_pokeblocks(cmddatalong[0],//adr
+ cmddata+4,//buf
+ len-4);//len
txdata(app,verb,len);
break;
//! Global data buffer.
#ifndef CMDDATALEN
-#define CMDDATALEN 0x200
+#define CMDDATALEN 0x0x204
#endif
extern unsigned char cmddata[CMDDATALEN];