From 6648c78f1f6eca1ff5bc477d10b12c2125f31285 Mon Sep 17 00:00:00 2001 From: travisutk Date: Sun, 22 Nov 2009 20:56:44 +0000 Subject: [PATCH] Fast MSP430 Flash writes. git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@232 12e2690d-a6be-4b82-a7b7-67c4a43b65c8 --- client/GoodFETMSP430.py | 9 ++++++++- client/goodfet.msp430 | 30 +++++++++++++++++++++++++----- firmware/apps/jtag/jtag430.c | 9 +++++---- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/client/GoodFETMSP430.py b/client/GoodFETMSP430.py index 4ee6e4f..d5e5f8f 100644 --- a/client/GoodFETMSP430.py +++ b/client/GoodFETMSP430.py @@ -65,7 +65,14 @@ class GoodFETMSP430(GoodFET): 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); diff --git a/client/goodfet.msp430 b/client/goodfet.msp430 index d012728..9fcb68f 100755 --- a/client/goodfet.msp430 +++ b/client/goodfet.msp430 @@ -77,17 +77,37 @@ if(sys.argv[1]=="flash"): 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>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; diff --git a/firmware/apps/jtag/jtag430.c b/firmware/apps/jtag/jtag430.c index 18a7c38..50fc70d 100644 --- a/firmware/apps/jtag/jtag430.c +++ b/firmware/apps/jtag/jtag430.c @@ -363,13 +363,14 @@ void jtag430handle(unsigned char app, 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]); -- 2.20.1