File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -115,12 +115,20 @@ void ihx_write(char line[]) {
115115
116116 switch (record_type ) {
117117 case IHX_RECORD_DATA :
118+ buff [0 ] = 0xFF ; // Padding in case the flash start address is not even.
118119 for (i = 0 ; i < byte_count ; i ++ )
119- buff [i ] = hex8 (& line [9 + i * 2 ]);
120- buff [byte_count ] = 0xFF ; // If there are not an even no. of bytes, pad with 0xFF to preserve flash.
120+ buff [i + 1 ] = hex8 (& line [9 + i * 2 ]);
121+ buff [byte_count + 1 ] = 0xFF ; // If there are not an even no. of bytes, pad with 0xFF to preserve flash.
121122
122- // (byte_count+1)/2 == number of 16-bit words to transfer, rounded up
123- flash_check_erase_and_write ((uint16_t * )buff , (byte_count + 1 )/2 , address );
123+ if (address & 1 ) {
124+ // Odd start address
125+ // (byte_count+1)/2 == number of 16-bit words to transfer, rounded up
126+ flash_check_erase_and_write ((uint16_t * )buff , (byte_count + 2 )/2 , address - 1 );
127+ } else {
128+ // Even start address
129+ // (byte_count+1)/2 == number of 16-bit words to transfer, rounded up
130+ flash_check_erase_and_write ((uint16_t * )(buff + 1 ), (byte_count + 1 )/2 , address );
131+ }
124132
125133 break ;
126134 case IHX_RECORD_EOF :
You can’t perform that action at this time.
0 commit comments