Fixed bugs in flash programming.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Sat, 20 Jun 2009 19:43:27 +0000 (19:43 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Sat, 20 Jun 2009 19:43:27 +0000 (19:43 +0000)
Moved pulses into jtag430asm.S for an implementation without C compiler headaches.

git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@46 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

firmware/Makefile
firmware/apps/jtag/jtag.c
firmware/apps/jtag/jtag430.c
firmware/apps/jtag/jtag430asm.S [new file with mode: 0644]

index 8e7d7ff..b3be6d4 100644 (file)
@@ -11,7 +11,7 @@ GCCINC=-T ldscripts/161x.x
 CC=msp430-gcc -g -mmcu=$(mcu) -DGCC $(GCCINC) -I include
 
 apps= apps/monitor/monitor.o apps/spi/spi.o apps/i2c/i2c.o apps/chipcon/chipcon.o apps/jtag/jtag.o apps/jtag/jtag430.o
 CC=msp430-gcc -g -mmcu=$(mcu) -DGCC $(GCCINC) -I include
 
 apps= apps/monitor/monitor.o apps/spi/spi.o apps/i2c/i2c.o apps/chipcon/chipcon.o apps/jtag/jtag.o apps/jtag/jtag430.o
-libs= lib/msp430f1612.o lib/command.o
+libs= lib/msp430f1612.o lib/command.o apps/jtag/jtag430asm.o
 app=goodfet
 
 all: $(app).hex
 app=goodfet
 
 all: $(app).hex
index cffec3d..bafd01e 100644 (file)
@@ -27,9 +27,9 @@ unsigned char jtagtrans8(unsigned char byte){
   for (bit = 0; bit < 8; bit++) {
     /* write MOSI on trailing edge of previous clock */
     if (byte & 0x80)
   for (bit = 0; bit < 8; bit++) {
     /* write MOSI on trailing edge of previous clock */
     if (byte & 0x80)
-      SETMOSI;
+      {SETMOSI;}
     else
     else
-      CLRMOSI;
+      {CLRMOSI;}
     byte <<= 1;
     
     if(bit==7)
     byte <<= 1;
     
     if(bit==7)
@@ -61,9 +61,9 @@ unsigned int jtagtrans16(unsigned int word){
   for (bit = 0; bit < 16; bit++) {
     /* write MOSI on trailing edge of previous clock */
     if (word & 0x8000)
   for (bit = 0; bit < 16; bit++) {
     /* write MOSI on trailing edge of previous clock */
     if (word & 0x8000)
-      SETMOSI;
+      {SETMOSI;}
     else
     else
-      CLRMOSI;
+      {CLRMOSI;}
     word <<= 1;
     
     if(bit==15)
     word <<= 1;
     
     if(bit==15)
index cc2ecc2..081fb52 100644 (file)
@@ -79,30 +79,30 @@ void jtag430_writemem(unsigned int adr, unsigned int data){
   SETTCLK;
 }
 
   SETTCLK;
 }
 
-//! Pulse TCLK at 350kHz +/- 100kHz
-void jtag430_tclk_flashpulses(unsigned int i){
-  //TODO check this on a scope.
+//! Defined in jtag430asm.S
+void jtag430_tclk_flashpulses(int);
+/* //! Pulse TCLK at 350kHz +/- 100kHz */
+/* void jtag430_tclk_flashpulses(register i){ */
+/*   //TODO check this on a scope. */
+/*   register j=0; */
   
   
-  //At 2MHz, 350kHz is obtained with 5 clocks of delay
+/*   //At 2MHz, 350kHz is obtained with 5 clocks of delay */
   
   
-  /** Pondering:
-      What happens if the frequency is too low or to high?
-      Is there any risk of damaging the chip, or only of a poor write?
-  */
-  while(i--){
-    SETTCLK;
-    _NOP();
-    _NOP();
-    _NOP();
-    _NOP();
-    _NOP();
-    CLRTCLK;
-  }
-}
+/*   /\** Pondering: */
+/*       What happens if the frequency is too low or to high? */
+/*       Is there any risk of damaging the chip, or only of a poor write? */
+/*   *\/ */
+/*   while(j++!=i){ */
+/*     SETTCLK; */
+/*     _NOP(); */
+/*     _NOP(); */
+/*     _NOP(); */
+/*     CLRTCLK; */
+/*   } */
+/* } */
 
 //! Write data to flash memory.  Must be preconfigured.
 void jtag430_writeflashword(unsigned int adr, unsigned int data){
 
 //! Write data to flash memory.  Must be preconfigured.
 void jtag430_writeflashword(unsigned int adr, unsigned int data){
-  //jtag430_haltcpu();
   /*
   CLRTCLK;
   jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
   /*
   CLRTCLK;
   jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
@@ -124,10 +124,9 @@ void jtag430_writeflashword(unsigned int adr, unsigned int data){
   jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
   jtag_dr_shift16(0x2409);
   
   jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
   jtag_dr_shift16(0x2409);
   
-  
   //Pulse TCLK
   //Pulse TCLK
-  jtag430_tclk_flashpulses(35);
-  //jtag430_releasecpu();
+  jtag430_tclk_flashpulses(35); //35 standard
+  
 }
 
 //! Configure flash, then write a word.
 }
 
 //! Configure flash, then write a word.
@@ -297,6 +296,8 @@ void jtag430handle(unsigned char app,
     txdata(app,verb,2);
     break;
   case JTAG430_ERASEFLASH:
     txdata(app,verb,2);
     break;
   case JTAG430_ERASEFLASH:
+    jtag430_eraseflash(ERASE_MASS,0xFFFE,0xFFFF);
+    jtag430_eraseflash(ERASE_MASS,0xFFFE,0xFFFF);
     jtag430_eraseflash(ERASE_MASS,0xFFFE,0xFFFF);
     txdata(app,verb,0);
     break;
     jtag430_eraseflash(ERASE_MASS,0xFFFE,0xFFFF);
     txdata(app,verb,0);
     break;
diff --git a/firmware/apps/jtag/jtag430asm.S b/firmware/apps/jtag/jtag430asm.S
new file mode 100644 (file)
index 0000000..2477016
--- /dev/null
@@ -0,0 +1,14 @@
+.globl jtag430_tclk_flashpulses
+.type jtag430_tclk_flashpulses,@function    /* declare main as a function */
+       
+jtag430_tclk_flashpulses:
+       sub #1, r15
+       bis.b #2, &0x0031       ;SETTCLK
+       nop
+       nop
+       nop
+       bic.b #2, &0x0031       ;CLRTCLK
+       tst r15
+       jnz jtag430_tclk_flashpulses
+       ret
+