Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
daugihao
Date:
Thu Sep 29 11:32:52 2011 +0000
Parent:
0:15536fa79743
Child:
2:9e3ee0c6536b
Commit message:
Now no need to update main.cpp. Will load the first .lpc file it finds on the local filesystem.

Changed in this revision

ID.cpp Show annotated file Show diff for this revision Revisions of this file
ISP.cpp Show annotated file Show diff for this revision Revisions of this file
LPC.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/ID.cpp	Tue Sep 27 15:44:55 2011 +0000
+++ b/ID.cpp	Thu Sep 29 11:32:52 2011 +0000
@@ -4,144 +4,21 @@
 int SerialBuffered::IDCheck(int idcode) {
     switch (idcode) {
         //Cortex M3 - LPC17xx
-        case 638664503:
-            strcpy(strChipType, "LPC1769 - Cortex M3");
-            lastSector = 29;
-            break;
         case 637615927:
-            strcpy(strChipType, "LPC1768 - Cortex M3");
-            lastSector = 29;
-            break;
-        case 637610039:
-            strcpy(strChipType, "LPC1767 - Cortex M3");
-            lastSector = 29;
-            break;
-        case 637615923:
-            strcpy(strChipType, "LPC1766 - Cortex M3");
-            lastSector = 21;
-            break;
-        case 637613875:
-            strcpy(strChipType, "LPC1765 - Cortex M3");
-            lastSector = 21;
-            break;
-        case 637606178:
-            strcpy(strChipType, "LPC1764 - Cortex M3");
-            lastSector = 17;
-            break;
-        case 621885239:
-            strcpy(strChipType, "LPC1759 - Cortex M3");
-            lastSector = 29;
-            break;
-        case 620838711:
-            strcpy(strChipType, "LPC1758 - Cortex M3");
-            lastSector = 29;
-            break;
-        case 620828451:
-            strcpy(strChipType, "LPC1756 - Cortex M3");
-            lastSector = 21;
-            break;
-        case 620828450:
-            strcpy(strChipType, "LPC1754 - Cortex M3");
-            lastSector = 17;
-            break;
-        case 620761377:
-            strcpy(strChipType, "LPC1752 - Cortex M3");
-            lastSector = 15;
-            break;
-        case 620761368:
-            strcpy(strChipType, "LPC1751 - Cortex M3");
-            lastSector = 7;
-            break;
-        case 620761131:
-            strcpy(strChipType, "LPC1102 - Cortex M0");
-            lastSector = 7;
-            break;
-        //Cortex M0 - LPC111x 
-        case 0x041E502B:
-            strcpy(strChipType, "LPC1111FHN33/101 - Cortex M0");
-            lastSector = 1;
-            break;
-        case 0x2516D02B:
-            strcpy(strChipType, "LPC1111FHN33/102 - Cortex M0");
-            lastSector = 1;
-            break;
-        case 0x0416502B:
-            strcpy(strChipType, "LPC1111FHN33/201 - Cortex M0");
-            lastSector = 1;
+            strcpy(strChipType, "LPC1768 - Cortex M3");  //Chip name
+            lastSector = 29;                             //Last available sector in Flash
+            RAM = 268435968;                             //First RAM address
             break;
-        case 0x2516902B:
-            strcpy(strChipType, "LPC1111FHN33/202 - Cortex M0");
-            lastSector = 1;
-            break;
-        case 0x042D502B:
-            strcpy(strChipType, "LPC1112FHN33/101 - Cortex M0");
-            lastSector = 3;
-            break;
-        case 0x2524D02B:
-            strcpy(strChipType, "LPC1112FHN33/102 - Cortex M0");
-            lastSector = 3;
-            break;
-        case 0x0425502B:
-            strcpy(strChipType, "LPC1112FHN33/201 - Cortex M0");
-            lastSector = 3;
-            break;
-        case 0x2524902B:
-            strcpy(strChipType, "LPC1112FHN33/202 - Cortex M0");
-            lastSector = 3;
-            break;
-        case 0x0434502B:
-            strcpy(strChipType, "LPC1113FHN33/201 - Cortex M0");
-            lastSector = 5;
-            break;
-        case 0x2532902B:
-            strcpy(strChipType, "LPC1113FHN33/202 - Cortex M0");
-            lastSector = 5;
-            break;
-        case 0x0434102B:
-            strcpy(strChipType, "LPC1113FHN33/301 OR LPC1113FBD48/301 - Cortex M0");
-            lastSector = 5;
-            break;
-        case 0x2532102B:
-            strcpy(strChipType, "LPC1113FHN33/302 OR LPC1113FBD48/302 - Cortex M0");
-            lastSector = 5;
-            break;
-        case 0x0444502B:
-            strcpy(strChipType, "LPC1114FHN33/201 - Cortex M0");
-            lastSector = 7;
-            break;
-        case 0x2540902B:
-            strcpy(strChipType, "LPC1114FHN33/202 - Cortex M0");
-            lastSector = 7;
-            break;
-        case 0x0444102B:
-            strcpy(strChipType, "LPC1114FHN33/301 OR LPC1114FBD48/301 OR LPC1114FA44/301 - Cortex M0");
-            lastSector = 7;
-            break;
-        case 0x2540102B:
-            strcpy(strChipType, "LPC1114FHN33/302 OR LPC1114FBD48/302 OR LPC1114FA44/302 - Cortex M0");
-            lastSector = 7;
-            break;
-       //Cortex M0 - LPC11Cxx
-        case 0x1421102B:
-            strcpy(strChipType, "LPC11C12FBD48/301 - Cortex M0");
-            lastSector = 3;
-            break;
-        case 0x1440102B:
-            strcpy(strChipType, "LPC11C14FBD48/301 - Cortex M0");
-            lastSector = 7;
-            break;
-        case 0x1431102B:
-            strcpy(strChipType, "LPC11C22FBD48/301 - Cortex M0");
-            lastSector = 3;
-            break;
-        case 0x1430102B:
-            strcpy(strChipType, "LPC11C24FBD48/301 - Cortex M0");
-            lastSector = 7;
+        //ARM7
+        case 117702437:
+            strcpy(strChipType, "LPC2387 - ARM7");
+            lastSector = 27;
+            RAM = 0x40000200;
             break;
             
         default:
             strcpy(strChipType, "\n\rUnrecognised chip! Please add into the \"CheckTargetPresent\" function the chip's relevant information.\r\n\n");
-            exit(0);
+            return(2);
     }
     return 0;
 }
\ No newline at end of file
--- a/ISP.cpp	Tue Sep 27 15:44:55 2011 +0000
+++ b/ISP.cpp	Thu Sep 29 11:32:52 2011 +0000
@@ -4,10 +4,10 @@
 Serial pc(USBTX, USBRX);
 LocalFileSystem local("fs");
 
-int SerialBuffered::ProgramFile(char *fname) {
+int SerialBuffered::ProgramFile() {
     sum20 = 0; readAll = false; bytesfilled=45; lines=1; firstencode = true;
     char str0[] = "0";  //Command success string
-    char strRAM[] = "W 268435968 1024";  //Command to state that the following 1024 bytes should be written to RAM
+    char strRAM[40];
     
     //Following arrays contain addresses and the size of the addresses 
     int sector[30] = {4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768};
@@ -19,6 +19,20 @@
         exit(0);
     }
     
+    sprintf(strRAM, "W %d 1024", RAM);
+    
+    DIR *d = opendir("/fs");               // Opens the root directory of the local file system
+    struct dirent *p;
+    
+    fname[0] = 0;
+    while((p = readdir(d)) != NULL) {         // Print the names of the files in the local file system
+        if ( strcmp(p->d_name+strlen(p->d_name)-3,"LPC") == 0 )
+        {
+            strcpy(fname,"/fs/");
+            strcat(fname,p->d_name);
+        }
+    }
+    
     f = fopen(fname, "r");  //Opens the binary file for reading
     if (f == NULL) {
         pc.printf("ERROR: File not found. Ensure file exists in the mbed's local filesystem and is spelt correctly in the main.cpp\n\n\r");
@@ -72,9 +86,10 @@
 }
 
 int SerialBuffered::SectorFill(int add) {
-    char strRAM[] = "W 268435968 1024";
     char sendStr[64];
     char str0[] = "0";
+    char strRAM[40];
+    sprintf(strRAM, "W %d 1024", RAM);
         
     if (!firstencode) {
         TargetSendStringAndCR(strRAM);
@@ -86,9 +101,10 @@
         if (bytesfilled>=990) {        //If not enough room for a full UUEncoded line use EndUUEncode()
             EndUUEncode();
             TargetSendString(enduuline);
-            sprintf(sendStr, "%d\0", sum20);
+            sprintf(sendStr, "%d", sum20);      //Checksum
             TargetSendStringAndCR(sendStr);
-            readBytes(buf, 10);
+            readBytes(buf, 4);
+            sum20=0; lines=0;
             pc.printf(".");
             break;
         }
@@ -97,7 +113,7 @@
         bytesfilled+=45;
         lines++;
         if (lines==20) {
-            sprintf(sendStr, "%d\0", sum20);      //Checksum
+            sprintf(sendStr, "%d", sum20);      //Checksum
             TargetSendStringAndCR(sendStr);
             readBytes(buf, 4);
             sum20=0; lines=0;
@@ -110,7 +126,7 @@
     if (strncmp(buf,str0,1)!=0)
         return 0;
     
-    sprintf(sendStr, "C %d 268435968 1024", add);  //Copies data from the RAM to FLASH
+    sprintf(sendStr, "C %d %d 1024", add, RAM);  //Copies data from the RAM to FLASH
     TargetSendStringAndCR(sendStr);
     readBytes(buf, 3);
     bytesfilled = 0; lines=0; sum20=0;
@@ -155,8 +171,9 @@
     for (int i=0; i<9; i++)
         id = (id*10)+buf[i]-'0';
     
-    IDCheck(id);
+    int finish = IDCheck(id);
     pc.printf("Chip to bootload: %s\n\r", strChipType);
+    if (finish==2) exit(0);
         
     TargetSendStringAndCR(strUnlock);           //Unlocks the Flash for writing to
     readBytes(buf, 3);
--- a/LPC.h	Tue Sep 27 15:44:55 2011 +0000
+++ b/LPC.h	Thu Sep 29 11:32:52 2011 +0000
@@ -16,7 +16,7 @@
     void TargetSendString(char string[]);                   //Sends a string to the board
     void TargetSendStringAndCR(char string[]);              //Sends a string to the board followed by a carriage return character
     int CheckTargetPresent(void);                           //Starts the handshaking and then verifies the type of chip from a returned ID code
-    int ProgramFile(char *fname);                           //Programs the UUEncoded data onto the RAM and the copies into the flash
+    int ProgramFile(void);                           //Programs the UUEncoded data onto the RAM and the copies into the flash
     int UUEncode(void);                                     //Encodes the file into UU-encoded format
     int Encode3(void);                                      //Sub-function to UUEncode which encodes the 3 raw bytes into 4 UU-encoded bytes
     int FirstEncode(void);                                  //Encodes the first UUEncoded line which needs the first checksum added to it as the 8th DWORD
@@ -44,6 +44,7 @@
     bool firstencode;                                       //True if no encoding of the file has been done
     int maxsector;                                          //Number of sectors required in order to accommodate the program, based on filesize
     long int filesize;                                      //Filesize is the...file...size (number of bytes in the file to load to the chip)
+    int RAM;
     
     //Serial Buffered
     void handleInterrupt();
--- a/main.cpp	Tue Sep 27 15:44:55 2011 +0000
+++ b/main.cpp	Thu Sep 29 11:32:52 2011 +0000
@@ -6,7 +6,7 @@
 int main() {
     //RESET CHIP TO LOAD TO BEFORE RUNNING PROGRAM!!!
     lpc.InitUART(230400);                   //Specified limit of 230400 baud
-    lpc.ProgramFile("/fs/t.bin");           //Write your program name in this box with the prefix /fs/ (sometimes unstable with special characters and long names)
+    lpc.ProgramFile();           //Write your program name in this box with the prefix /fs/ (sometimes unstable with special characters and long names)
 }
 
 //To add new chips to load to, add a case to the switch function in ID.cpp, using the ID code and last sector number information
\ No newline at end of file