SPI Flash writing support.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Sat, 18 Jul 2009 15:54:22 +0000 (15:54 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Sat, 18 Jul 2009 15:54:22 +0000 (15:54 +0000)
Does not quite behave properly.  Maybe the block size isn't negotiable?

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

firmware/apps/spi/spi.c

index 785c476..0a15799 100644 (file)
@@ -69,7 +69,10 @@ unsigned char spitrans8(unsigned char byte){
 //! Enable SPI writing
 void spiflash_wrten(){
     P5OUT&=~SS; //Drop !SS to begin transaction.
-    spitrans8(0x06);//Chip Erase
+    spitrans8(0x04);//Write Disable
+    P5OUT|=SS;  //Raise !SS to end transaction.
+    P5OUT&=~SS; //Drop !SS to begin transaction.
+    spitrans8(0x06);//Write Enable
     P5OUT|=SS;  //Raise !SS to end transaction.
 }
 
@@ -110,7 +113,15 @@ void spihandle(unsigned char app,
     P5OUT|=SS;  //Raise !SS to end transaction.
     break;
   case POKE://Poke up bytes from an SPI Flash ROM.
+    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; //Drop !SS to begin transaction.
+    txdata(app,verb,len);
     break;
   case SPI_ERASE://Erase the SPI Flash ROM.
     spiflash_wrten();