val&0xff, (val&0xff00)>>8];
self.writecmd(self.MSP430APP,0xE1,6,self.data);
return ord(self.data[0])+(ord(self.data[1])<<8);
-
+ def MSP430pokeflashblock(self,adr,data):
+ """Write many words to flash memory at an address."""
+ self.data=[adr&0xff, (adr&0xff00)>>8,
+ (adr&0xff0000)>>16,(adr&0xff000000)>>24]+data;
+ #print "Writing %i bytes to %x" % (len(data),adr);
+ #print "%2x %2x %2x %2x ..." % (data[0], data[1], data[2], data[3]);
+ self.writecmd(self.MSP430APP,0xE1,len(self.data),self.data);
+ return ord(self.data[0])+(ord(self.data[1])<<8);
def MSP430start(self):
"""Start debugging."""
self.writecmd(self.MSP430APP,0x20,0,self.data);
h = IntelHex16bit(f);
+ #Should this be default?
+ #Makes flashing multiple images inconvenient.
client.MSP430masserase();
+
+ count=0; #Bytes in commit.
+ first=0;
+ vals=[];
+ last=0; #Last address committed.
for i in h._buf.keys():
- #print "%04x: %04x"%(i,h[i>>1]);
+ if((count>0x40 or last+2!=i) and count>0 and i&1==0):
+ #print "%i, %x, %x" % (len(vals), last, i);
+ client.MSP430pokeflashblock(first,vals);
+ count=0;
+ first=0;
+ last=0;
+ vals=[];
if(i>=start and i<stop and i&1==0):
val=h[i>>1];
- val2=client.MSP430pokeflash(i,val);
- if(val!=val2):
- print "Write error at %04x, %04x!=%04x." %(
- i, val, val2);
+ if(count==0):
+ first=i;
+ last=i;
+ count+=2;
+ #val2=client.MSP430pokeflash(i,val);
+ #if(val!=val2):
+ # print "Write error at %04x, %04x!=%04x." %(
+ # i, val, val2);
+ vals+=[val&0xff,(val&0xff00)>>8];
if(i%0x100==0):
print "%04x" % i;
+ if count>0: #last commit, ivt
+ client.MSP430pokeflashblock(first,vals);
if(sys.argv[1]=="verify"):
f=sys.argv[2];
start=0;
case JTAG430_WRITEFLASH:
at=cmddataword[0];
- for(i=2;i<(len>>1);i++){
+ for(i=0;i<(len>>1)-2;i++){
//debugstr("Poking flash memory.");
- jtag430_writeflash(at,cmddataword[i]);
+ jtag430_writeflash(at+(i<<1),cmddataword[i+2]);
+ //Reflash if needed. Try this twice to save grace?
if(cmddataword[i]!=jtag430_readmem(at))
- jtag430_writeflash(at,cmddataword[i]);
+ jtag430_writeflash(at+(i<<1),cmddataword[i+2]);
}
-
+
//Return result of first write as a word.
cmddataword[0]=jtag430_readmem(cmddataword[0]);