Ika Shouyu Poppoyaki - LPC82x supported
Fork of ika_shouyu_poppoyaki by
Diff: main.cpp
- Revision:
- 26:a63e73885b21
- Parent:
- 25:33cb5ad8ae24
- Child:
- 27:2b5c1eb39bb5
--- 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; } + +