From c9fa78dd91736cd5004d23fd9535c30be4f978ff Mon Sep 17 00:00:00 2001 From: travisutk Date: Tue, 1 Dec 2009 07:48:10 +0000 Subject: [PATCH] Quantitative tests of AVR power stability, working toward glitching. git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@245 12e2690d-a6be-4b82-a7b7-67c4a43b65c8 --- client/GoodFET.py | 2 +- client/GoodFETCC.py | 13 +++++++++--- client/goodfet.cc | 6 +++--- firmware/apps/avr/avr.c | 3 ++- firmware/apps/chipcon/chipcon.c | 1 + firmware/apps/glitch/glitch.c | 36 ++++++++++++++++++++++++++++++++- firmware/goodfet.c | 1 + 7 files changed, 53 insertions(+), 9 deletions(-) diff --git a/client/GoodFET.py b/client/GoodFET.py index 63e38e9..cfc2079 100755 --- a/client/GoodFET.py +++ b/client/GoodFET.py @@ -103,7 +103,7 @@ class GoodFET: #Debugging string; print, but wait. if self.app==0xFF and self.verb==0xFF: - print "DEBUG %s" % self.serialport.read(self.count); + print "# DEBUG %s" % self.serialport.read(self.count); else: self.data=self.serialport.read(self.count); return self.data; diff --git a/client/GoodFETCC.py b/client/GoodFETCC.py index e2f28e6..3f4d1d9 100644 --- a/client/GoodFETCC.py +++ b/client/GoodFETCC.py @@ -53,7 +53,7 @@ class GoodFETCC(GoodFET): self.CCstop(); print "Done."; - def CCsetup(self): + def setup(self): """Move the FET into the CC2430/CC2530 application.""" #print "Initializing Chipcon."; self.writecmd(0x30,0x10,0,self.data); @@ -111,6 +111,13 @@ class GoodFETCC(GoodFET): self.data=[adr&0xff]; self.writecmd(0x30,0x02, 1, self.data); return ord(self.data[0]); + def CCpeekiramword(self,adr): + """Read the little-endian contents of IRAM at an address.""" + return self.CCpeekirambyte(adr)+( + self.CCpeekirambyte(adr+1)<<8); + def CCpokeiramword(self,adr,val): + self.CCpokeirambyte(adr,val&0xff); + self.CCpokeirambyte(adr+1,(val>>8)&0xff); def CCpokeirambyte(self,adr,val): """Write the contents of IRAM at an address.""" self.data=[adr&0xff, val&0xff]; @@ -156,7 +163,7 @@ class GoodFETCC(GoodFET): str="%s %s" %(self.CCstatusbits[i],str); i*=2; return str; - def CCstart(self): + def start(self): """Start debugging.""" self.writecmd(0x30,0x20,0,self.data); ident=self.CCidentstr(); @@ -166,7 +173,7 @@ class GoodFETCC(GoodFET): self.CChaltcpu(); #print "Status: %s." % self.CCstatusstr(); - def CCstop(self): + def stop(self): """Stop debugging.""" self.writecmd(0x30,0x21,0,self.data); def CCstep_instr(self): diff --git a/client/goodfet.cc b/client/goodfet.cc index 3f2860d..2905eb5 100755 --- a/client/goodfet.cc +++ b/client/goodfet.cc @@ -33,8 +33,8 @@ client=GoodFETCC(); client.serInit() #Connect to target -client.CCsetup(); -client.CCstart(); +client.setup(); +client.start(); if(sys.argv[1]=="test"): client.CCtest(); @@ -238,4 +238,4 @@ if(sys.argv[1]=="pokedata"): print "Poking %04x to become %02x." % (start,val); client.CCpokedatabyte(start,val); -client.CCstop(); +client.stop(); diff --git a/firmware/apps/avr/avr.c b/firmware/apps/avr/avr.c index a4ba6fd..a127ea2 100644 --- a/firmware/apps/avr/avr.c +++ b/firmware/apps/avr/avr.c @@ -106,7 +106,6 @@ u8 avr_lockbits(){ } //! Write lock bits. void avr_setlock(u8 bits){ - debugstr("Setting lock bits."); avrexchange(0xAC,0xE0,0x00, bits); } @@ -138,8 +137,10 @@ void avrhandle(unsigned char app, unsigned int at; static u8 connected=0; + /* if(!avr_isready() && connected) debugstr("AVR is not yet ready."); + */ switch(verb){ case READ: diff --git a/firmware/apps/chipcon/chipcon.c b/firmware/apps/chipcon/chipcon.c index 478e877..135d2a6 100644 --- a/firmware/apps/chipcon/chipcon.c +++ b/firmware/apps/chipcon/chipcon.c @@ -150,6 +150,7 @@ void cchandle(unsigned char app, txdata(app,verb,0); break; case START://enter debugger + ccsetup(); ccdebuginit(); txdata(app,verb,0); break; diff --git a/firmware/apps/glitch/glitch.c b/firmware/apps/glitch/glitch.c index e125544..e3b226d 100644 --- a/firmware/apps/glitch/glitch.c +++ b/firmware/apps/glitch/glitch.c @@ -23,6 +23,13 @@ void glitchsetup(){ P6OUT|=0x40; glitchsetupdac(); + + WDTCTL = WDTPW + WDTHOLD; // Stop WDT + TACTL = TASSEL1 + TACLR; // SMCLK, clear TAR + CCTL0 = CCIE; // CCR0 interrupt enabled + CCR0 = glitchcount; + TACTL |= MC1; // Start Timer_A in continuous mode + _EINT(); // Enable interrupts #endif } @@ -31,14 +38,41 @@ void glitchsetupdac(){ glitchvoltages(glitchL,glitchH); } +// Timer A0 interrupt service routine +interrupt(TIMERA0_VECTOR) Timer_A (void) +{ + + switch(glitchstate){ + case 0: + P1OUT|=1; + glitchstate=1; + DAC12_0DAT = glitchH; + break; + case 1: + P1OUT|=1; + glitchstate=0; + DAC12_0DAT = glitchL; + break; + default: + P1OUT&=~1; + //Do nothing. + break; + } + CCR0 += glitchcount; // Add Offset to CCR0 +} + + + u16 glitchH=0xfff, glitchL=0xfff, - glitchstate, glitchcount; + glitchstate=2, glitchcount=0; //! Glitch an application. void glitchapp(u8 app){ debugstr("That app is not yet supported."); } + + //! Set glitching voltages. void glitchvoltages(u16 low, u16 high){ int i; diff --git a/firmware/goodfet.c b/firmware/goodfet.c index b08313f..ee97ebb 100644 --- a/firmware/goodfet.c +++ b/firmware/goodfet.c @@ -38,6 +38,7 @@ void handle(unsigned char app, unsigned char verb, unsigned long len){ //debugstr("GoodFET"); + P1OUT&=~1; switch(app){ case GLITCH: glitchhandle(app,verb,len); -- 2.20.1