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@34:eaca33d3e632, 2013-09-26 (annotated)
- Committer:
- okano
- Date:
- Thu Sep 26 11:51:03 2013 +0000
- Revision:
- 34:eaca33d3e632
- Parent:
- 28:689c3880e0e4
- Child:
- 35:0b434ef4af49
[1]; fix: verification function was having a bug. 3/4 of the code was having chance of verification fail.; ; [2]; "ENABLE_WRITING" option added (see "_user_setting.h"). Verifying-only operation can be done with disabling this word
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 | 23:017f306cf3ca | 6 | |
okano | 23:017f306cf3ca | 7 | DigitalOut reset_pin( p26 ); |
okano | 23:017f306cf3ca | 8 | DigitalOut isp_pin( p25 ); |
okano | 23:017f306cf3ca | 9 | |
okano | 23:017f306cf3ca | 10 | target_param *open_target( int baud_date ) |
okano | 23:017f306cf3ca | 11 | { |
okano | 23:017f306cf3ca | 12 | target_param *tpp; |
okano | 23:017f306cf3ca | 13 | char str_buf0[ STR_BUFF_SIZE ]; |
okano | 23:017f306cf3ca | 14 | char str_buf1[ STR_BUFF_SIZE ]; |
okano | 28:689c3880e0e4 | 15 | int retry_count = 3; |
okano | 23:017f306cf3ca | 16 | |
okano | 23:017f306cf3ca | 17 | set_target_baud_rate( baud_date ); |
okano | 28:689c3880e0e4 | 18 | |
okano | 28:689c3880e0e4 | 19 | while ( retry_count-- ) { |
okano | 28:689c3880e0e4 | 20 | reset_target( ENTER_TO_ISP_MODE ); |
okano | 28:689c3880e0e4 | 21 | |
okano | 28:689c3880e0e4 | 22 | if ( !try_and_check( "?", "Synchronized", 0 ) ) |
okano | 28:689c3880e0e4 | 23 | break; |
okano | 28:689c3880e0e4 | 24 | } |
okano | 28:689c3880e0e4 | 25 | |
okano | 28:689c3880e0e4 | 26 | if ( !retry_count ) |
okano | 28:689c3880e0e4 | 27 | return ( NULL ); |
okano | 28:689c3880e0e4 | 28 | |
okano | 23:017f306cf3ca | 29 | try_and_check2( "Synchronized\r\n", "OK", 0 ); |
okano | 23:017f306cf3ca | 30 | try_and_check2( "12000\r\n", "OK", 0 ); |
okano | 23:017f306cf3ca | 31 | try_and_check2( "U 23130\r\n", "0", 0 ); |
okano | 23:017f306cf3ca | 32 | try_and_check2( "A 0\r\n", "0", 0 ); |
okano | 28:689c3880e0e4 | 33 | |
okano | 23:017f306cf3ca | 34 | try_and_check( "K\r\n", "0", 0 ); |
okano | 23:017f306cf3ca | 35 | get_string( str_buf0 ); |
okano | 23:017f306cf3ca | 36 | get_string( str_buf1 ); |
okano | 28:689c3880e0e4 | 37 | |
okano | 23:017f306cf3ca | 38 | printf( " result of \"K\" = %s %s\r\n", str_buf0, str_buf1 ); |
okano | 28:689c3880e0e4 | 39 | |
okano | 23:017f306cf3ca | 40 | try_and_check( "J\r\n", "0", 0 ); |
okano | 23:017f306cf3ca | 41 | get_string( str_buf0 ); |
okano | 28:689c3880e0e4 | 42 | |
okano | 23:017f306cf3ca | 43 | printf( " result of \"J\" = %s\r\n", str_buf0 ); |
okano | 28:689c3880e0e4 | 44 | |
okano | 23:017f306cf3ca | 45 | tpp = find_target_param( str_buf0 ); |
okano | 28:689c3880e0e4 | 46 | |
okano | 23:017f306cf3ca | 47 | return ( tpp ); |
okano | 23:017f306cf3ca | 48 | } |
okano | 23:017f306cf3ca | 49 | |
okano | 23:017f306cf3ca | 50 | |
okano | 23:017f306cf3ca | 51 | void reset_target( int isp_pin_state ) |
okano | 23:017f306cf3ca | 52 | { |
okano | 23:017f306cf3ca | 53 | reset_pin = 1; |
okano | 23:017f306cf3ca | 54 | isp_pin = isp_pin_state; |
okano | 23:017f306cf3ca | 55 | wait_ms( 100 ); |
okano | 28:689c3880e0e4 | 56 | |
okano | 23:017f306cf3ca | 57 | reset_pin = 0; |
okano | 23:017f306cf3ca | 58 | wait_ms( 100 ); |
okano | 28:689c3880e0e4 | 59 | |
okano | 23:017f306cf3ca | 60 | reset_pin = 1; |
okano | 23:017f306cf3ca | 61 | wait_ms( 100 ); |
okano | 23:017f306cf3ca | 62 | } |
okano | 26:a63e73885b21 | 63 |