Add to 11U68 11E68

Dependencies:   DirectoryList MODSERIAL mbed

Fork of ika_shouyu_poppoyaki by Tedd OKANO

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /**
00002  *  Sample of ISP operation for NXP MCUs
00003  *
00004  *  @author  Tedd OKANO
00005  *  @version 1.1.2
00006  *  @date    Jan-2015
00007  *
00008  *  This program programs MCU flash memory through UART. It uses
00009  *  "In-System Programming (ISP)" interface in target MCU (NXP LPC micro-
00010  *  controllers).
00011  *
00012  *  The ISP is done by PC and serial cable normally. The ISP protocol is
00013  *  executed software on a PC. The software reads a data file and transfers
00014  *  the data with the ISP protocol.
00015  *  This program does same process of that. The mbed perform the function like
00016  *  "FlashMagic" and "lpc21isp".
00017  *  (This program not just copies the binary but also insert 4 byte checksum at
00018  *  address 0x1C.)
00019  *
00020  *  This program supports LPC1114, LPC81x, LPC82x and LPC1768/1769.
00021  */
00022 
00023 #include    "mbed.h"
00024 #include    "isp.h"
00025 #include    "serial_utilities.h"
00026 #include    "_user_settings.h"
00027 #include    "dir_handling.h"
00028 
00029 
00030 LocalFileSystem local( "local" );
00031 
00032 
00033 #define     SUMMARY_MESSAGE_FAIL        "** The data could not be " WHAT_WAS_DONE " :("
00034 #define     SUMMARY_MESSAGE_SUCCESS     "** The data has been " WHAT_WAS_DONE " successflly :)"
00035 
00036 int main()
00037 {
00038     int     err;
00039 
00040     printf( "\r\n\r\n\r\nmbed ISP program : programming LPC device from mbed (v1.1.2)\r\n" );
00041 
00042 #ifndef ENABLE_FILE_SELECTOR
00043     err     = isp_flash_write( SOURCE_FILE );
00044 #else
00045     std::string str( SOURCE_FILE );
00046     if ( "" == get_file_name( str, SUFFIX_FILTER_STR ) )
00047         goto skip_ISP;
00048     err     = isp_flash_write( str.c_str() );
00049 #endif
00050 
00051     printf( "\r\n  %d: %s\r\n\r\n",err,
00052             err ?
00053             SUMMARY_MESSAGE_FAIL :
00054             SUMMARY_MESSAGE_SUCCESS
00055           );
00056 
00057     if ( err )
00058         error( "  ** ISP failed\r\n" );
00059 
00060 skip_ISP:
00061 
00062 #ifdef  AUTO_PROGRAM_START
00063 
00064     start_target_in_normal_mode( TARGET_OPERATION_BAUD_RATE );
00065 
00066     printf( "  ** The program programmed in flash has been started!!\r\n" );
00067 
00068 #endif
00069 
00070     printf( "     (now the mbed is working in \"serial through mode\")\r\n\r\n" );
00071 
00072     start_success_indicator();
00073     usb_serial_bridge_operation();  //  doesn't return. infinite loop in this function
00074 }
00075