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
target_handling.cpp@52:afd15e54142f, 2015-07-26 (annotated)
- Committer:
- ChrisABailey
- Date:
- Sun Jul 26 14:46:23 2015 +0000
- Revision:
- 52:afd15e54142f
- Parent:
- 39:f68f9fa1e88e
Use MBED to load LPC1114. Modified to also load LPExpresso 1114 board
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okano | 23:017f306cf3ca | 1 | #include "mbed.h" |
okano | 23:017f306cf3ca | 2 | #include "target_handling.h" |
okano | 23:017f306cf3ca | 3 | #include "target_table.h" |
okano | 23:017f306cf3ca | 4 | #include "command_interface.h" |
okano | 23:017f306cf3ca | 5 | #include "serial_utilities.h" |
okano | 39:f68f9fa1e88e | 6 | #include "_user_settings.h" |
okano | 39:f68f9fa1e88e | 7 | |
okano | 23:017f306cf3ca | 8 | |
okano | 23:017f306cf3ca | 9 | DigitalOut reset_pin( p26 ); |
okano | 23:017f306cf3ca | 10 | DigitalOut isp_pin( p25 ); |
okano | 23:017f306cf3ca | 11 | |
okano | 39:f68f9fa1e88e | 12 | |
okano | 23:017f306cf3ca | 13 | target_param *open_target( int baud_date ) |
okano | 23:017f306cf3ca | 14 | { |
okano | 23:017f306cf3ca | 15 | target_param *tpp; |
okano | 23:017f306cf3ca | 16 | char str_buf0[ STR_BUFF_SIZE ]; |
okano | 23:017f306cf3ca | 17 | char str_buf1[ STR_BUFF_SIZE ]; |
okano | 28:689c3880e0e4 | 18 | int retry_count = 3; |
okano | 23:017f306cf3ca | 19 | |
ChrisABailey | 52:afd15e54142f | 20 | printf ("Setting baude rate to %d \r\n",baud_date); |
okano | 23:017f306cf3ca | 21 | set_target_baud_rate( baud_date ); |
okano | 28:689c3880e0e4 | 22 | |
okano | 28:689c3880e0e4 | 23 | while ( retry_count-- ) { |
okano | 28:689c3880e0e4 | 24 | reset_target( ENTER_TO_ISP_MODE ); |
okano | 28:689c3880e0e4 | 25 | |
okano | 35:0b434ef4af49 | 26 | if ( !try_and_check( "?", "Synchronized" ) ) |
okano | 28:689c3880e0e4 | 27 | break; |
okano | 28:689c3880e0e4 | 28 | } |
okano | 28:689c3880e0e4 | 29 | |
okano | 28:689c3880e0e4 | 30 | if ( !retry_count ) |
okano | 28:689c3880e0e4 | 31 | return ( NULL ); |
okano | 28:689c3880e0e4 | 32 | |
okano | 35:0b434ef4af49 | 33 | try_and_check2( "Synchronized\r\n", "OK" ); |
okano | 35:0b434ef4af49 | 34 | try_and_check2( "12000\r\n", "OK" ); |
okano | 35:0b434ef4af49 | 35 | try_and_check2( "U 23130\r\n", "0" ); |
okano | 35:0b434ef4af49 | 36 | try_and_check2( "A 0\r\n", "0" ); |
okano | 28:689c3880e0e4 | 37 | |
okano | 35:0b434ef4af49 | 38 | try_and_check( "K\r\n", "0" ); |
okano | 23:017f306cf3ca | 39 | get_string( str_buf0 ); |
okano | 23:017f306cf3ca | 40 | get_string( str_buf1 ); |
okano | 28:689c3880e0e4 | 41 | |
okano | 39:f68f9fa1e88e | 42 | #ifndef SUPPRESS_COMMAND_RESULT_MESSAGE |
okano | 23:017f306cf3ca | 43 | printf( " result of \"K\" = %s %s\r\n", str_buf0, str_buf1 ); |
okano | 39:f68f9fa1e88e | 44 | #endif |
okano | 28:689c3880e0e4 | 45 | |
okano | 35:0b434ef4af49 | 46 | try_and_check( "J\r\n", "0" ); |
okano | 23:017f306cf3ca | 47 | get_string( str_buf0 ); |
okano | 28:689c3880e0e4 | 48 | |
okano | 39:f68f9fa1e88e | 49 | #ifndef SUPPRESS_COMMAND_RESULT_MESSAGE |
okano | 23:017f306cf3ca | 50 | printf( " result of \"J\" = %s\r\n", str_buf0 ); |
okano | 39:f68f9fa1e88e | 51 | #endif |
okano | 28:689c3880e0e4 | 52 | |
okano | 23:017f306cf3ca | 53 | tpp = find_target_param( str_buf0 ); |
okano | 28:689c3880e0e4 | 54 | |
okano | 23:017f306cf3ca | 55 | return ( tpp ); |
okano | 23:017f306cf3ca | 56 | } |
okano | 23:017f306cf3ca | 57 | |
okano | 23:017f306cf3ca | 58 | |
okano | 23:017f306cf3ca | 59 | void reset_target( int isp_pin_state ) |
okano | 23:017f306cf3ca | 60 | { |
okano | 23:017f306cf3ca | 61 | reset_pin = 1; |
okano | 23:017f306cf3ca | 62 | isp_pin = isp_pin_state; |
okano | 23:017f306cf3ca | 63 | wait_ms( 100 ); |
okano | 28:689c3880e0e4 | 64 | |
okano | 23:017f306cf3ca | 65 | reset_pin = 0; |
okano | 23:017f306cf3ca | 66 | wait_ms( 100 ); |
okano | 28:689c3880e0e4 | 67 | |
okano | 23:017f306cf3ca | 68 | reset_pin = 1; |
okano | 23:017f306cf3ca | 69 | wait_ms( 100 ); |
okano | 23:017f306cf3ca | 70 | } |
okano | 26:a63e73885b21 | 71 |