Ika Shouyu Poppoyaki - LPC82x supported

Dependencies:   MODSERIAL mbed

Fork of ika_shouyu_poppoyaki by Tedd OKANO

Files at this revision

API Documentation at this revision

Comitter:
okano
Date:
Wed Sep 25 04:00:04 2013 +0000
Parent:
32:3700d5df4e18
Child:
34:eaca33d3e632
Commit message:
options of "ENABLE_VERIFYING" and "CHECK_CRP_CODE" are added in _user_settings.h.

Changed in this revision

_user_settings.h 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
isp.h Show annotated file Show diff for this revision Revisions of this file
--- a/_user_settings.h	Tue Sep 24 21:35:25 2013 +0000
+++ b/_user_settings.h	Wed Sep 25 04:00:04 2013 +0000
@@ -7,15 +7,25 @@
 //  "ISP_BAUD_RATE" is baud rate for ISP operation
 #define     ISP_BAUD_RATE       115200
 
+
 //  "TARGET_OPERATION_BAUD_RATE" is baud rate for USB-serial bridge operation after 
 //  ISP completion. 
 //  if the target application uses serial(UART) and you use the bridge feature, 
 //  please set this value correctly. 
 #define     TARGET_OPERATION_BAUD_RATE  9600
 
+
 //  enable "AUTO_PROGRAM_START" to let target starts the program after flash writing complete
 #define     AUTO_PROGRAM_START
 
 
+//  enable "ENABLE_VERIFYING" to let perform verification by comparing "bin" file and flash read data.
+#define     ENABLE_VERIFYING
 
-#endif  //  MBED_ISP___USER_SETTINGS__
\ No newline at end of file
+
+//  enable "CHECK_CRP_CODE" to check the CRP (Code Read Protection). The ISP writing will be ignored if "bin" file has CRP code. 
+#define     CHECK_CRP_CODE
+
+
+#endif  //  MBED_ISP___USER_SETTINGS__
+
--- a/isp.cpp	Tue Sep 24 21:35:25 2013 +0000
+++ b/isp.cpp	Wed Sep 25 04:00:04 2013 +0000
@@ -16,9 +16,11 @@
 
 
 int             file_size( FILE *fp );
+unsigned int    read_crp( FILE *fp );
 unsigned int    crp_check( FILE *fp );
 void            success_indicator();
 
+
 int isp_flash_write( char *file_name )
 {
     FILE            *fp;
@@ -45,10 +47,17 @@
 
     data_size   = file_size( fp );
     last_sector = data_size / tpp->sector_size;
-    
-    if ( crp_check( fp ) )
-    {
-        //  warn CRP
+
+    if ( crp_check( fp ) ) {
+        printf( "  the CRP is enabled in the data source file\r\n" );
+
+#ifdef CHECK_CRP_CODE
+        printf( "  aborting execution by CRP warning\r\n" );
+
+        return ( WARNING_CRP_CODE_DETECTED );
+#else
+        printf( "  this program continues to write the CRP enabled binary into the target flash\r\n" );
+#endif
     }
 
     printf( "  data size = %d bytes, it takes %d secotrs in flash area\r\n", data_size, last_sector + 1 );
@@ -64,13 +73,16 @@
 
     printf( "  -- %d bytes data are written\r\n", transferred_size );
 
-
+#ifdef ENABLE_VERIFYING
     printf( "\r\n  ==== flash reading and verifying ====\r\n" );
 
     if ( err    = verify_flash( fp, tpp, &transferred_size ) )
         return ( err );
 
     printf( "  -- %d bytes data are read and verified\r\n", transferred_size );
+#else
+    printf( "\r\n  ==== verifying has been skipped ====\r\n\r\n" );
+#endif
 
     fclose( fp );
 
@@ -96,6 +108,32 @@
 {
     unsigned int    crp;
 
+    switch ( crp    = read_crp( fp ) ) {
+        case NO_ISP :
+            printf( "\r\n  WARNING : CRP code detected 0x%08X (NO_ISP)\r\n", crp );
+            break;
+        case CRP1 :
+            printf( "\r\n  WARNING : CRP code detected 0x%08X (CRP1)\r\n", crp );
+            break;
+        case CRP2 :
+            printf( "\r\n  WARNING : CRP code detected 0x%08X (CRP2)\r\n", crp );
+            break;
+        case CRP3 :
+            printf( "\r\n  WARNING : CRP code detected 0x%08X (CRP3)\r\n", crp );
+            break;
+        default :
+            crp = 0x0;  //  no CRP code detected
+            break;
+    }
+    
+    return ( crp );
+}
+
+
+unsigned int read_crp( FILE *fp )
+{
+    unsigned int    crp;
+
     fseek( fp, 0x2FC, SEEK_SET ); // seek back to beginning of file
 
     if ( 1 != fread( &crp, sizeof( crp ), 1, fp ) )
@@ -103,17 +141,6 @@
 
     fseek( fp, 0, SEEK_SET ); // seek back to beginning of file
 
-    switch ( crp ) {
-        case NO_ISP :
-        case CRP1 :
-        case CRP2 :
-        case CRP3 :
-            /*  do nothing  */
-            break;
-        default :
-            crp = 0x0;
-    }
-
     return ( crp );
 }
 
--- a/isp.h	Tue Sep 24 21:35:25 2013 +0000
+++ b/isp.h	Wed Sep 25 04:00:04 2013 +0000
@@ -25,7 +25,9 @@
     ERROR_AT_MALLOC_FOR_VERIFY_DATA_BUFF,
     ERROR_AT_READ_COMMAND,
 
-    ERROR_DATA_DOES_NOT_MATCH
+    ERROR_DATA_DOES_NOT_MATCH, 
+    
+    WARNING_CRP_CODE_DETECTED
 };