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

Committer:
ChrisABailey
Date:
Sun Jul 26 14:46:23 2015 +0000
Revision:
52:afd15e54142f
Parent:
51:981107d4e84f
Use MBED to load LPC1114.  Modified to also load LPExpresso 1114 board

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okano 11:8dfc3217d1ca 1 /**
okano 11:8dfc3217d1ca 2 * Sample of ISP operation for NXP MCUs
okano 11:8dfc3217d1ca 3 *
okano 14:a7b9f74fb856 4 * @author Tedd OKANO
okano 51:981107d4e84f 5 * @version 1.2
okano 51:981107d4e84f 6 * @date Jul-2015
okano 26:a63e73885b21 7 *
okano 26:a63e73885b21 8 * This program programs MCU flash memory through UART. It uses
okano 14:a7b9f74fb856 9 * "In-System Programming (ISP)" interface in target MCU (NXP LPC micro-
okano 14:a7b9f74fb856 10 * controllers).
okano 26:a63e73885b21 11 *
okano 26:a63e73885b21 12 * The ISP is done by PC and serial cable normally. The ISP protocol is
okano 14:a7b9f74fb856 13 * executed software on a PC. The software reads a data file and transfers
okano 26:a63e73885b21 14 * the data with the ISP protocol.
okano 26:a63e73885b21 15 * This program does same process of that. The mbed perform the function like
okano 14:a7b9f74fb856 16 * "FlashMagic" and "lpc21isp".
okano 26:a63e73885b21 17 * (This program not just copies the binary but also insert 4 byte checksum at
okano 14:a7b9f74fb856 18 * address 0x1C.)
okano 26:a63e73885b21 19 *
okano 51:981107d4e84f 20 * This program supports LPC1114, LPC81x, LPC82x, LPC1768/1769 and LPC11U68/LPC11E68.
okano 51:981107d4e84f 21 *
okano 51:981107d4e84f 22 * All detailed history is available in code publishing page.
okano 51:981107d4e84f 23 * Please find it on
okano 51:981107d4e84f 24 * https://developer.mbed.org/users/okano/code/ika_shouyu_poppoyaki/shortlog
okano 51:981107d4e84f 25 * Thank you for all feedbacks and controbutes!
okano 11:8dfc3217d1ca 26 */
okano 11:8dfc3217d1ca 27
okano 5:ff30f5b58617 28 #include "mbed.h"
okano 30:e0d7524661ca 29 #include "isp.h"
okano 22:bd98a782fba6 30 #include "serial_utilities.h"
okano 25:33cb5ad8ae24 31 #include "_user_settings.h"
okano 48:99cfe3a929ea 32 #include "dir_handling.h"
okano 21:e149d0bdbf4a 33
okano 30:e0d7524661ca 34
okano 2:8d75eb0ecd20 35 LocalFileSystem local( "local" );
okano 7:815366f003ee 36
okano 19:7a7381e78025 37
okano 35:0b434ef4af49 38 #define SUMMARY_MESSAGE_FAIL "** The data could not be " WHAT_WAS_DONE " :("
okano 35:0b434ef4af49 39 #define SUMMARY_MESSAGE_SUCCESS "** The data has been " WHAT_WAS_DONE " successflly :)"
okano 35:0b434ef4af49 40
okano 7:815366f003ee 41 int main()
okano 7:815366f003ee 42 {
okano 28:689c3880e0e4 43 int err;
okano 30:e0d7524661ca 44
okano 48:99cfe3a929ea 45 printf( "\r\n\r\n\r\nmbed ISP program : programming LPC device from mbed (v1.1.2)\r\n" );
okano 30:e0d7524661ca 46
okano 48:99cfe3a929ea 47 #ifndef ENABLE_FILE_SELECTOR
okano 28:689c3880e0e4 48 err = isp_flash_write( SOURCE_FILE );
okano 48:99cfe3a929ea 49 #else
okano 48:99cfe3a929ea 50 std::string str( SOURCE_FILE );
okano 48:99cfe3a929ea 51 if ( "" == get_file_name( str, SUFFIX_FILTER_STR ) )
okano 48:99cfe3a929ea 52 goto skip_ISP;
okano 48:99cfe3a929ea 53 err = isp_flash_write( str.c_str() );
okano 48:99cfe3a929ea 54 #endif
okano 30:e0d7524661ca 55
k4zuki 42:2b40666d8177 56 printf( "\r\n %d: %s\r\n\r\n",err,
okano 28:689c3880e0e4 57 err ?
okano 35:0b434ef4af49 58 SUMMARY_MESSAGE_FAIL :
okano 35:0b434ef4af49 59 SUMMARY_MESSAGE_SUCCESS
okano 8:b220fadbb3d8 60 );
okano 26:a63e73885b21 61
okano 28:689c3880e0e4 62 if ( err )
okano 19:7a7381e78025 63 error( " ** ISP failed\r\n" );
okano 26:a63e73885b21 64
okano 48:99cfe3a929ea 65 skip_ISP:
okano 48:99cfe3a929ea 66
okano 14:a7b9f74fb856 67 #ifdef AUTO_PROGRAM_START
okano 31:1a4d59d7bd72 68
okano 30:e0d7524661ca 69 start_target_in_normal_mode( TARGET_OPERATION_BAUD_RATE );
okano 16:cac2348cfcfb 70
okano 41:74b9ff21098f 71 printf( " ** The program programmed in flash has been started!!\r\n" );
okano 35:0b434ef4af49 72
okano 14:a7b9f74fb856 73 #endif
okano 14:a7b9f74fb856 74
okano 16:cac2348cfcfb 75 printf( " (now the mbed is working in \"serial through mode\")\r\n\r\n" );
okano 35:0b434ef4af49 76
okano 30:e0d7524661ca 77 start_success_indicator();
okano 21:e149d0bdbf4a 78 usb_serial_bridge_operation(); // doesn't return. infinite loop in this function
okano 20:98d7b5878e3e 79 }
okano 16:cac2348cfcfb 80