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
Revision 41:74b9ff21098f, committed 2013-11-19
- Comitter:
- okano
- Date:
- Tue Nov 19 23:53:20 2013 +0000
- Parent:
- 40:615dc8275648
- Child:
- 42:2b40666d8177
- Commit message:
- enabled to handle <0x300 (768) bytes data file
Changed in this revision
--- a/_user_settings.h Sun Sep 29 03:57:02 2013 +0000 +++ b/_user_settings.h Tue Nov 19 23:53:20 2013 +0000 @@ -1,18 +1,15 @@ #ifndef MBED_ISP___USER_SETTINGS__ #define MBED_ISP___USER_SETTINGS__ +// file name for the binary data +// edit here if you need to use different file name or storage media +#define SOURCE_FILE "/local/bin" -#define SOURCE_FILE "/local/bin" // "ISP_BAUD_RATE" is baud rate for ISP operation #define ISP_BAUD_RATE 115200 -// suppress "command and result" monitoring output to terminal -// the "command and result" monitoring feature is made for debugging. -#define SUPPRESS_COMMAND_RESULT_MESSAGE - - // "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, @@ -20,6 +17,11 @@ #define TARGET_OPERATION_BAUD_RATE 9600 +// suppress "command and result" monitoring output to terminal +// the "command and result" monitoring feature is made for debugging. +#define SUPPRESS_COMMAND_RESULT_MESSAGE + + // enable "AUTO_PROGRAM_START" to let target starts the program after flash writing complete #define AUTO_PROGRAM_START
--- a/isp.cpp Sun Sep 29 03:57:02 2013 +0000 +++ b/isp.cpp Tue Nov 19 23:53:20 2013 +0000 @@ -10,6 +10,8 @@ #include "isp.h" #include "_user_settings.h" +#define CRP_WORD_OFFSET 0x2FC + BusOut leds( LED4, LED3, LED2, LED1 ); Ticker success; @@ -46,22 +48,26 @@ } data_size = file_size( fp ); - + if ( !data_size ) return ( ERROR_DATA_SIZE_ZERO ); - + last_sector = (data_size - 1) / tpp->sector_size; - if ( crp_check( fp ) ) { - printf( " the CRP is enabled in the data source file\r\n" ); + if ( data_size < (CRP_WORD_OFFSET + sizeof( unsigned int )) ) { + printf( " CRP check is not performed because data size is less than 0x300(768) bytes\r\n" ); + } else { + 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" ); + printf( " aborting execution by CRP warning\r\n" ); - return ( WARNING_CRP_CODE_DETECTED ); + return ( WARNING_CRP_CODE_DETECTED ); #else - printf( " this program continues to write the CRP enabled binary into the target flash\r\n" ); + 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 ); @@ -110,7 +116,7 @@ int size; fseek( fp, 0, SEEK_END ); // seek to end of file - size = ftell( fp ); // get current file pointer + size = ftell( fp ); // get current file pointer fseek( fp, 0, SEEK_SET ); // seek back to beginning of file return size; @@ -138,7 +144,7 @@ crp = 0x0; // no CRP code detected break; } - + return ( crp ); } @@ -147,7 +153,7 @@ { unsigned int crp; - fseek( fp, 0x2FC, SEEK_SET ); // seek back to beginning of file + fseek( fp, CRP_WORD_OFFSET, SEEK_SET ); // seek to 0x2FC (764th byte) if ( 1 != fread( &crp, sizeof( crp ), 1, fp ) ) return ( CRP_CHECK_ERROR );
--- a/main.cpp Sun Sep 29 03:57:02 2013 +0000 +++ b/main.cpp Tue Nov 19 23:53:20 2013 +0000 @@ -2,8 +2,8 @@ * Sample of ISP operation for NXP MCUs * * @author Tedd OKANO - * @version 0.98 - * @date Sep-2013 + * @version 0.999 + * @date Nov-2013 * * This program programs MCU flash memory through UART. It uses * "In-System Programming (ISP)" interface in target MCU (NXP LPC micro- @@ -37,7 +37,7 @@ { int err; - printf( "\r\n\r\n\r\nmbed ISP program : programming LPC device from mbed (v0.98)\r\n" ); + printf( "\r\n\r\n\r\nmbed ISP program : programming LPC device from mbed (v0.999)\r\n" ); err = isp_flash_write( SOURCE_FILE ); @@ -54,7 +54,7 @@ start_target_in_normal_mode( TARGET_OPERATION_BAUD_RATE ); - printf( " ** The program in flash has been started!!\r\n" ); + printf( " ** The program programmed in flash has been started!!\r\n" ); #endif
--- a/writing.cpp Sun Sep 29 03:57:02 2013 +0000 +++ b/writing.cpp Tue Nov 19 23:53:20 2013 +0000 @@ -110,7 +110,6 @@ int flash_writing_size; char *b; - flash_writing_size = 256; if ( NULL == (b = (char *)malloc( flash_writing_size * sizeof( char ) )) )