Add to 11U68 11E68

Dependencies:   DirectoryList MODSERIAL mbed

Fork of ika_shouyu_poppoyaki by Tedd OKANO

Files at this revision

API Documentation at this revision

Comitter:
okano
Date:
Fri Sep 13 12:56:23 2013 +0000
Parent:
25:33cb5ad8ae24
Child:
27:2b5c1eb39bb5
Commit message:
code is still dirty but it works. I hope I will have chance to clean up some day...

Changed in this revision

_user_settings.h Show annotated file Show diff for this revision Revisions of this file
command_interface.cpp Show annotated file Show diff for this revision Revisions of this file
command_interface.h Show annotated file Show diff for this revision Revisions of this file
ika.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
serial_utilities.cpp Show annotated file Show diff for this revision Revisions of this file
serial_utilities.h Show annotated file Show diff for this revision Revisions of this file
target_handling.cpp Show annotated file Show diff for this revision Revisions of this file
target_handling.h Show annotated file Show diff for this revision Revisions of this file
target_table.cpp Show annotated file Show diff for this revision Revisions of this file
target_table.h 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
--- a/_user_settings.h	Fri Sep 13 03:51:14 2013 +0000
+++ b/_user_settings.h	Fri Sep 13 12:56:23 2013 +0000
@@ -1,14 +1,17 @@
+
+
 #define     SOURCE_FILE         "/local/bin"
 
 //  "ISP_BAUD_RATE" is baud rate for ISP operation
-
 #define     ISP_BAUD_RATE       115200
-//#define     ISP_BAUD_RATE       57600
-//#define     ISP_BAUD_RATE       9600
 
 //  "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
 
-#define     TARGET_OPERATION_BAUD_RATE  9600
+//  enable "AUTO_PROGRAM_START" to let target starts the program after flash writing complete
+#define     AUTO_PROGRAM_START
+
+
--- a/command_interface.cpp	Fri Sep 13 03:51:14 2013 +0000
+++ b/command_interface.cpp	Fri Sep 13 12:56:23 2013 +0000
@@ -77,4 +77,15 @@
 }
 
 
+void erase_sectors( int last_sector )
+{
+    char    command_str[ STR_BUFF_SIZE ];
 
+    sprintf( command_str, "P 0 %d\r\n", last_sector );
+    try_and_check( command_str, "0", 0 );
+
+    *(command_str)  = 'E';
+    try_and_check( command_str, "0", 0 );
+}
+
+
--- a/command_interface.h	Fri Sep 13 03:51:14 2013 +0000
+++ b/command_interface.h	Fri Sep 13 12:56:23 2013 +0000
@@ -1,6 +1,10 @@
+
 #define     STR_BUFF_SIZE       64
+
 int     try_and_check( char *command, char *expected_return_str, int mode );
 int     try_and_check2( char *command, char *expected_return_str, int mode );
 void    print_command( char *command );
 void    print_result( int r );
 void    send_RAM_transfer_checksum( int checksum );
+void    erase_sectors( int last_sector );
+
--- a/ika.h	Fri Sep 13 03:51:14 2013 +0000
+++ b/ika.h	Fri Sep 13 12:56:23 2013 +0000
@@ -3,5 +3,5 @@
 
 void set_leds( char v );
 
+extern int     error_state;
 
-extern int     error_state;
--- a/main.cpp	Fri Sep 13 03:51:14 2013 +0000
+++ b/main.cpp	Fri Sep 13 12:56:23 2013 +0000
@@ -2,22 +2,22 @@
  *  Sample of ISP operation for NXP MCUs
  *
  *  @author  Tedd OKANO
- *  @version 0.8
+ *  @version 0.9
  *  @date    Sep-2013
- *  
- *  This program programs MCU flash memory through UART. It uses 
+ *
+ *  This program programs MCU flash memory through UART. It uses
  *  "In-System Programming (ISP)" interface in target MCU (NXP LPC micro-
  *  controllers).
- *  
- *  The ISP is done by PC and serial cable normally. The ISP protocol is 
+ *
+ *  The ISP is done by PC and serial cable normally. The ISP protocol is
  *  executed software on a PC. The software reads a data file and transfers
- *  the data with the ISP protocol. 
- *  This program does same process of that. The mbed perform the function like 
+ *  the data with the ISP protocol.
+ *  This program does same process of that. The mbed perform the function like
  *  "FlashMagic" and "lpc21isp".
- *  (This program not just copies the binary but also insert 4 byte checksum at 
+ *  (This program not just copies the binary but also insert 4 byte checksum at
  *  address 0x1C.)
- *  
- *  This program currently supports LPC1114(LPC1114FN28/102 - DIP28-ARM) and 
+ *
+ *  This program currently supports LPC1114(LPC1114FN28/102 - DIP28-ARM) and
  *  LPC810(LPC810M021FN8 - DIP8-ARM).
  */
 
@@ -32,26 +32,18 @@
 #include    "_user_settings.h"
 #include    "ika.h"
 
-
 BusOut          leds( LED4, LED3, LED2, LED1 );
 LocalFileSystem local( "local" );
 Ticker          success;
 
-
-
 int     error_state         = 0;
 
 int     post_writing_process( target_param *tpp );
-
 int     file_size( FILE *fp );
 char    read_byte( void );
-void    erase_sectors( int last_sector );
-
 void    success_indicator();
 
 
-#pragma diag_suppress 1293  //  surpressing a warning message of "assignment in condition" ;)
-
 int main()
 {
     FILE            *fp;
@@ -61,8 +53,7 @@
 
     printf( "\r\n\r\n\r\nmbed ISP program : programming LPC device from mbed\r\n" );
 
-    if ( NULL == (tpp = open_target( ISP_BAUD_RATE )) )
-    {
+    if ( NULL == (tpp = open_target( ISP_BAUD_RATE )) ) {
         error( "couldn't open the taget" );
         return ( 1 );
     }
@@ -87,7 +78,10 @@
 
     erase_sectors( last_sector );
 
+    printf( "\r\n  ==== flash writing ====\r\n" );
     write_flash( fp, tpp );
+    
+    printf( "\r\n  ==== flash reading and verifying ====\r\n" );
     verify_flash( fp, tpp );
 
     fclose( fp );
@@ -97,14 +91,13 @@
             "** The data could not be written :(" :
             "** The data has been written successflly :)"
           );
-    
+
     if ( error_state )
         error( "  ** ISP failed\r\n" );
-    
+
     post_writing_process( tpp );
 
 
-#define AUTO_PROGRAM_START
 #ifdef  AUTO_PROGRAM_START
     set_target_baud_rate( TARGET_OPERATION_BAUD_RATE );
 
@@ -123,8 +116,9 @@
 int post_writing_process( target_param *tpp )
 {
     if ( tpp->write_type == UUENCODE )
-                try_and_check( "G 0 T\r\n", "0", 0 );
-
+        return ( try_and_check( "G 0 T\r\n", "0", 0 ) );
+    else
+        return ( 0 );
 }
 
 
@@ -140,29 +134,10 @@
 }
 
 
-
-
-void erase_sectors( int last_sector )
-{
-    char    command_str[ STR_BUFF_SIZE ];
-
-    sprintf( command_str, "P 0 %d\r\n", last_sector );
-    try_and_check( command_str, "0", 0 );
-
-    *(command_str)  = 'E';
-    try_and_check( command_str, "0", 0 );
-}
-
-
-
-
-
-
-
 void success_indicator()
 {
     static int  i   = 0;
-    
+
     leds    = 0x1 << (i++ & 0x3);
 }
 
@@ -171,3 +146,5 @@
 {
     leds    = v;
 }
+
+
--- a/serial_utilities.cpp	Fri Sep 13 03:51:14 2013 +0000
+++ b/serial_utilities.cpp	Fri Sep 13 12:56:23 2013 +0000
@@ -13,6 +13,11 @@
 MODSERIAL       target( p28, p27 ); //
 #endif
 
+Timeout timeout;
+
+int timeout_flag    = 0;
+
+
 void set_target_baud_rate( int baud_rate )
 {
     target.baud( baud_rate );
@@ -53,10 +58,6 @@
 }
 
 
-Timeout timeout;
-
-int timeout_flag    = 0;
-
 void set_flag()
 {
     timeout_flag    = 1;
--- a/serial_utilities.h	Fri Sep 13 03:51:14 2013 +0000
+++ b/serial_utilities.h	Fri Sep 13 12:56:23 2013 +0000
@@ -7,3 +7,4 @@
 void    get_string( char *s );
 int     get_binary( char *b, int length );
 char    read_byte( void );
+
--- a/target_handling.cpp	Fri Sep 13 03:51:14 2013 +0000
+++ b/target_handling.cpp	Fri Sep 13 12:56:23 2013 +0000
@@ -53,3 +53,4 @@
     reset_pin   = 1;
     wait_ms( 100 );
 }
+
--- a/target_handling.h	Fri Sep 13 03:51:14 2013 +0000
+++ b/target_handling.h	Fri Sep 13 12:56:23 2013 +0000
@@ -8,3 +8,4 @@
 
 target_param    *open_target( int baud_date );
 void            reset_target( int isp_pin_state );
+
--- a/target_table.cpp	Fri Sep 13 03:51:14 2013 +0000
+++ b/target_table.cpp	Fri Sep 13 12:56:23 2013 +0000
@@ -26,3 +26,4 @@
     
     return ( target_table );
 }
+
--- a/target_table.h	Fri Sep 13 03:51:14 2013 +0000
+++ b/target_table.h	Fri Sep 13 12:56:23 2013 +0000
@@ -2,7 +2,6 @@
 #define MBED_ISP__TARGET_TABLE__
 
 
-
 #define     NOT_FOUND   0
 
 #define UUENCODE    0
@@ -25,3 +24,4 @@
 target_param *find_target_param( char *device_id_string );
 
 #endif
+
--- a/verification.cpp	Fri Sep 13 03:51:14 2013 +0000
+++ b/verification.cpp	Fri Sep 13 12:56:23 2013 +0000
@@ -17,6 +17,8 @@
         verify_binary_data( fp );
     else
         verify_uucoded_data( fp );
+
+    return ( 0 );   //  this is temporallry return code
 }
 
 
@@ -43,8 +45,6 @@
         error( "malloc error happened (in verify process, read data buffer)\r\n" );
 
 
-    printf( "\r\n  ==== flash reading and verifying ====\r\n" );
-
     while ( size    = fread( bf, sizeof( char ), flash_reading_size, fp ) ) {
 
         if ( read_size < 0x20 ) {
@@ -53,11 +53,11 @@
                 if ( checksum_count == 7 ) {
                     checksum    = 0xFFFFFFFF - checksum + 1;
                     *((unsigned int *)(bf + i)) = checksum;
-                  //printf( "\r\n\r\n  -- calculated checksum    : 0x%08X\r\n", checksum );
+                    //printf( "\r\n\r\n  -- calculated checksum    : 0x%08X\r\n", checksum );
                 } else {
                     checksum    += *((unsigned int *)(bf + i));
                 }
-                
+
                 checksum_count++;
             }
         }
@@ -80,12 +80,12 @@
 
         if ( error_flag )
             break;
-            
+
         read_size   += size;
 
 //        printf( "  total %d bytes read\r\n", read_size );
     }
-    
+
     error_state |= error_flag;
 
     printf( "  total %d bytes read\r", read_size );
@@ -143,7 +143,7 @@
 
         if ( error_flag )
             break;
-            
+
         read_size   += size;
 //        printf( "  total %d bytes read\r", read_size );
     }
--- a/verification.h	Fri Sep 13 03:51:14 2013 +0000
+++ b/verification.h	Fri Sep 13 12:56:23 2013 +0000
@@ -2,3 +2,4 @@
 
 
 int     verify_flash( FILE *fp, target_param *tpp );
+
--- a/writing.cpp	Fri Sep 13 03:51:14 2013 +0000
+++ b/writing.cpp	Fri Sep 13 12:56:23 2013 +0000
@@ -18,6 +18,8 @@
         write_binary_data( fp, tpp->ram_size, tpp->sector_size, tpp->ram_start_address );
     else // UUENCODE
         write_uuencoded_data(  fp, tpp->ram_size, tpp->sector_size, tpp->ram_start_address );
+        
+    return ( 0 );   //  this is temporallry return code 
 }
 
 
@@ -106,8 +108,6 @@
     if ( NULL == (b     = (char *)malloc( flash_writing_size * sizeof( char ) )) )
         error( "malloc error happened\r\n" );
 
-    printf( "\r\n  ==== flash writing ====\r\n" );
-
     while ( size    = fread( b, sizeof( char ), flash_writing_size, fp ) ) {
 
         if ( !total_size ) {
@@ -157,7 +157,7 @@
     *p  = 0xFFFFFFFF - cksum + 1;
     printf( "  -- calculated checksum    : 0x%08X\r\n", *p );
 
-    printf( "     new checksum will be used to program flash\r\n" );
+    printf( "     new checksum will be used programing flash\r\n" );
 }