Code to load a LPC1114 over tx/rx. I have only tested with a 1114 chip but it should work with other LPC uControllers

Dependencies:   DirectoryList MODSERIAL mbed

Fork of ika_shouyu_poppoyaki by Tedd OKANO

Files at this revision

API Documentation at this revision

Comitter:
okano
Date:
Tue Jan 06 11:05:29 2015 +0000
Parent:
46:fe8ca451abcb
Child:
48:99cfe3a929ea
Commit message:
progress display (during writing/verifying) option added

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
main.cpp Show annotated file Show diff for this revision Revisions of this file
verification.cpp Show annotated file Show diff for this revision Revisions of this file
verification.h Show annotated file Show diff for this revision Revisions of this file
writing.cpp Show annotated file Show diff for this revision Revisions of this file
writing.h Show annotated file Show diff for this revision Revisions of this file
--- a/_user_settings.h	Wed Dec 10 09:42:12 2014 +0000
+++ b/_user_settings.h	Tue Jan 06 11:05:29 2015 +0000
@@ -34,6 +34,10 @@
 #define     ENABLE_VERIFYING
 
 
+//  enable "ENABLR_PROGRESS_DISPLAY" to let display data write/verify progress.
+#define     ENABLE_PROGRESS_DISPLAY
+
+
 //  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
 
--- a/isp.cpp	Wed Dec 10 09:42:12 2014 +0000
+++ b/isp.cpp	Tue Jan 06 11:05:29 2015 +0000
@@ -79,7 +79,7 @@
 
     printf( "\r\n  ==== flash writing ====\r\n" );
 
-    if ( err    = write_flash( fp, tpp, &transferred_size ) )
+    if ( err    = write_flash( fp, tpp, &transferred_size, data_size ) )
         return ( err );
 
     printf( "  -- %d bytes data are written\r\n", transferred_size );
@@ -102,7 +102,7 @@
     } else {
         printf( "\r\n  ==== flash reading and verifying ====\r\n" );
 
-        if ( err    = verify_flash( fp, tpp, &transferred_size ) )
+        if ( err    = verify_flash( fp, tpp, &transferred_size, data_size ) )
             return ( err );
 
         printf( "  -- %d bytes data are read and verified\r\n", transferred_size );
@@ -204,3 +204,9 @@
 {
     leds    = 0x0;
 }
+
+void show_progress( int total_size, int file_size )
+{
+    printf( "  -- %5.1f%%\r", ((float)total_size/(float)file_size) * 100.0 );
+    fflush( stdout );
+}
--- a/isp.h	Wed Dec 10 09:42:12 2014 +0000
+++ b/isp.h	Tue Jan 06 11:05:29 2015 +0000
@@ -7,6 +7,7 @@
 void    start_success_indicator( void );
 void    toggle_led( char v );
 void    leds_off( void );
+void    show_progress( int total_size, int file_size );
 
 
 enum {
--- a/main.cpp	Wed Dec 10 09:42:12 2014 +0000
+++ b/main.cpp	Tue Jan 06 11:05:29 2015 +0000
@@ -2,8 +2,8 @@
  *  Sample of ISP operation for NXP MCUs
  *
  *  @author  Tedd OKANO
- *  @version 1.1
- *  @date    Dec-2014
+ *  @version 1.1.1
+ *  @date    Jan-2015
  *
  *  This program programs MCU flash memory through UART. It uses
  *  "In-System Programming (ISP)" interface in target MCU (NXP LPC micro-
@@ -36,7 +36,7 @@
 {
     int     err;
 
-    printf( "\r\n\r\n\r\nmbed ISP program : programming LPC device from mbed (v1.0)\r\n" );
+    printf( "\r\n\r\n\r\nmbed ISP program : programming LPC device from mbed (v1.1.1)\r\n" );
 
     err     = isp_flash_write( SOURCE_FILE );
 
--- a/verification.cpp	Wed Dec 10 09:42:12 2014 +0000
+++ b/verification.cpp	Tue Jan 06 11:05:29 2015 +0000
@@ -5,23 +5,25 @@
 #include    "serial_utilities.h"
 #include    "writing.h"
 #include    "isp.h"
+#include    "_user_settings.h"
 
 
-int     verify_binary_data( FILE *fp, int *transferred_size_p );
-int     verify_uucoded_data( FILE *fp, int *transferred_size_p );
+
+int     verify_binary_data( FILE *fp, int *transferred_size_p, int file_size );
+int     verify_uucoded_data( FILE *fp, int *transferred_size_p, int file_size );
 void    get_binary_from_uucode_str( char *b, int size );
 
 
-int verify_flash( FILE *fp, target_param *tpp, int *transferred_size_p )
+int verify_flash( FILE *fp, target_param *tpp, int *transferred_size_p, int file_size )
 {
     if ( tpp->write_type == BINARY )
-        return ( verify_binary_data( fp, transferred_size_p ) );
+        return ( verify_binary_data( fp, transferred_size_p, file_size ) );
     else
-        return ( verify_uucoded_data( fp, transferred_size_p ) );
+        return ( verify_uucoded_data( fp, transferred_size_p, file_size ) );
 }
 
 
-int verify_binary_data( FILE *fp, int *read_size_p )
+int verify_binary_data( FILE *fp, int *read_size_p, int file_size )
 {
     char    command_str[ STR_BUFF_SIZE ];
     int     read_size   = 0;
@@ -82,6 +84,10 @@
             break;
 
         read_size   += size;
+
+#ifdef ENABLE_PROGRESS_DISPLAY
+        show_progress( read_size, file_size );
+#endif
     }
 
     free( bf );
@@ -98,7 +104,7 @@
 #define     READ_SIZE   (LINE_BYTES * N_OF_LINES)
 
 
-int verify_uucoded_data( FILE *fp, int *read_size_p )
+int verify_uucoded_data( FILE *fp, int *read_size_p, int file_size )
 {
     char    command_str[ STR_BUFF_SIZE ];
     int     read_size   = 0;
@@ -146,6 +152,10 @@
             break;
 
         read_size   += size;
+
+#ifdef ENABLE_PROGRESS_DISPLAY
+        show_progress( read_size, file_size );
+#endif
     }
 
     free( bf );
--- a/verification.h	Wed Dec 10 09:42:12 2014 +0000
+++ b/verification.h	Tue Jan 06 11:05:29 2015 +0000
@@ -1,5 +1,5 @@
 #include    "target_table.h"
 
 
-int     verify_flash( FILE *fp, target_param *tpp, int *transferred_size_p );
+int     verify_flash( FILE *fp, target_param *tpp, int *transferred_size_p, int file_size );
 
--- a/writing.cpp	Wed Dec 10 09:42:12 2014 +0000
+++ b/writing.cpp	Tue Jan 06 11:05:29 2015 +0000
@@ -5,26 +5,28 @@
 #include    "uu_coding.h"
 #include    "serial_utilities.h"
 #include    "isp.h"
-
-
-int     write_uuencoded_data( FILE *fp, target_param *tpp, int *total_size_p );
-int     write_binary_data( FILE *fp, int ram_size, int sector_size, unsigned int ram_start, int *total_size_p );
-int     get_flash_writing_size( int ram_size, unsigned int ram_start );
+#include    "_user_settings.h"
 
 
-int write_flash( FILE *fp, target_param *tpp, int *transferred_size_p )
+int     write_uuencoded_data( FILE *fp, target_param *tpp, int *total_size_p, int file_size );
+int     write_binary_data( FILE *fp, int ram_size, int sector_size, unsigned int ram_start, int *total_size_p, int file_size );
+int     get_flash_writing_size( int ram_size, unsigned int ram_start );
+void    show_progress( int total_size, int file_size );
+
+
+int write_flash( FILE *fp, target_param *tpp, int *transferred_size_p, int file_size )
 {
     if ( tpp->write_type == BINARY )
-        return ( write_binary_data(  fp, tpp->ram_size, tpp->sector_size, tpp->ram_start_address, transferred_size_p ) );
+        return ( write_binary_data(  fp, tpp->ram_size, tpp->sector_size, tpp->ram_start_address, transferred_size_p, file_size ) );
     else // UUENCODE
-        return ( write_uuencoded_data( fp, tpp, transferred_size_p ) );
+        return ( write_uuencoded_data( fp, tpp, transferred_size_p, file_size ) );
 }
 
 
 
 
 
-int write_uuencoded_data( FILE *fp, target_param *tpp, int *total_size_p )
+int write_uuencoded_data( FILE *fp, target_param *tpp, int *total_size_p, int file_size )
 {
 #define     BYTES_PER_LINE      45
 
@@ -39,7 +41,7 @@
     int     transfer_size;
 
     char    *b;
-    
+
     int ram_size            = tpp->ram_size;
     unsigned int ram_start  = tpp->ram_start_address;
 
@@ -94,7 +96,7 @@
 
         sector_number   = find_sector( total_size, tpp );
         sprintf( command_str, "P %d %d\r\n", sector_number, sector_number );
-        
+
         if ( try_and_check( command_str, "0" ) )
             return ( ERROR_AT_PREPARE_COMMAND );
 
@@ -103,6 +105,10 @@
             return ( ERROR_AT_COPY_COMMAND );
 
         total_size  += size;
+
+#ifdef ENABLE_PROGRESS_DISPLAY
+        show_progress( total_size, file_size );
+#endif
     }
 
     free( b );
@@ -112,7 +118,7 @@
 }
 
 
-int write_binary_data( FILE *fp, int ram_size, int sector_size, unsigned int ram_start, int *total_size_p )
+int write_binary_data( FILE *fp, int ram_size, int sector_size, unsigned int ram_start, int *total_size_p, int file_size )
 {
     char    command_str[ STR_BUFF_SIZE ];
     int     total_size  = 0;
@@ -151,6 +157,9 @@
         total_size  += size;
         //printf( "  total %d bytes transferred\r", total_size );
 
+#ifdef ENABLE_PROGRESS_DISPLAY
+        show_progress( total_size, file_size );
+#endif
     }
 
     free( b );
@@ -211,4 +220,3 @@
     else
         return ( 0 );
 }
-
--- a/writing.h	Wed Dec 10 09:42:12 2014 +0000
+++ b/writing.h	Tue Jan 06 11:05:29 2015 +0000
@@ -1,7 +1,7 @@
 #include    "target_table.h"
 
 
-int     write_flash( FILE *fp, target_param *tpp, int *transferred_size );
+int     write_flash( FILE *fp, target_param *tpp, int *transferred_size, int file_size );
 void    add_isp_checksum( char *b );
 int     post_writing_process( target_param *tpp );