@@ -572,7 +572,6 @@ void (*app_start)(void) = 0x0000;
572
572
int main (void )
573
573
{
574
574
address_t address = 0 ;
575
- address_t eraseAddress = 0 ;
576
575
unsigned char msgParseState ;
577
576
unsigned int ii = 0 ;
578
577
unsigned char checksum = 0 ;
@@ -1096,7 +1095,6 @@ int main(void)
1096
1095
break ;
1097
1096
#endif
1098
1097
case CMD_CHIP_ERASE_ISP :
1099
- eraseAddress = 0 ; // dthiele: should be removed, address is always given in actual message
1100
1098
msgLength = 2 ;
1101
1099
// msgBuffer[1] = STATUS_CMD_OK;
1102
1100
msgBuffer [1 ] = STATUS_CMD_FAILED ; //* isue 543, return FAILED instead of OK
@@ -1119,49 +1117,59 @@ int main(void)
1119
1117
unsigned char * p = msgBuffer + 10 ;
1120
1118
unsigned int data ;
1121
1119
unsigned char highByte , lowByte ;
1122
- address_t tempaddress = address ;
1123
-
1124
-
1120
+ address_t tempAddress ;
1121
+
1125
1122
if ( msgBuffer [0 ] == CMD_PROGRAM_FLASH_ISP )
1126
1123
{
1127
1124
// erase only main section (bootloader protection)
1128
- if (eraseAddress < APP_END )
1125
+ if (address + size <= APP_END )
1129
1126
{
1130
- boot_page_erase (eraseAddress ); // Perform page erase
1131
- boot_spm_busy_wait (); // Wait until the memory is erased.
1132
- eraseAddress += SPM_PAGESIZE ; // point to next page to be erase
1127
+ if (address % SPM_PAGESIZE == 0 )
1128
+ {
1129
+ boot_page_erase (address ); // Perform page erase
1130
+ boot_spm_busy_wait (); // Wait until the memory is erased.
1131
+ }
1132
+
1133
+ /* Write FLASH */
1134
+ tempAddress = address ;
1135
+ do {
1136
+ lowByte = * p ++ ;
1137
+ highByte = * p ++ ;
1138
+
1139
+ data = (highByte << 8 ) | lowByte ;
1140
+ boot_page_fill (tempAddress ,data );
1141
+
1142
+ tempAddress = tempAddress + 2 ; // Select next word in memory
1143
+ size -= 2 ; // Reduce number of bytes to write by two
1144
+ } while (size ); // Loop until all bytes written
1145
+
1146
+ boot_page_write (address );
1147
+ boot_spm_busy_wait ();
1148
+ boot_rww_enable (); // Re-enable the RWW section
1149
+
1150
+ msgLength = 2 ;
1151
+ msgBuffer [1 ] = STATUS_CMD_OK ;
1133
1152
}
1134
-
1135
- /* Write FLASH */
1136
- do {
1137
- lowByte = * p ++ ;
1138
- highByte = * p ++ ;
1139
-
1140
- data = (highByte << 8 ) | lowByte ;
1141
- boot_page_fill (address ,data );
1142
-
1143
- address = address + 2 ; // Select next word in memory
1144
- size -= 2 ; // Reduce number of bytes to write by two
1145
- } while (size ); // Loop until all bytes written
1146
-
1147
- boot_page_write (tempaddress );
1148
- boot_spm_busy_wait ();
1149
- boot_rww_enable (); // Re-enable the RWW section
1153
+ else
1154
+ {
1155
+ msgLength = 2 ;
1156
+ msgBuffer [1 ] = STATUS_CMD_FAILED ;
1157
+ }
1150
1158
}
1151
1159
else
1152
1160
{
1153
- //* issue 543, this should work, It has not been tested.
1154
- uint16_t ii = address >> 1 ;
1155
- /* write EEPROM */
1156
- while (size ) {
1157
- eeprom_write_byte ((uint8_t * )ii , * p ++ );
1158
- address += 2 ; // Select next EEPROM byte
1159
- ii ++ ;
1160
- size -- ;
1161
- }
1161
+ //* issue 543, this should work, It has not been tested.
1162
+ uint16_t ii = address >> 1 ;
1163
+ /* write EEPROM */
1164
+ while (size ) {
1165
+ eeprom_write_byte ((uint8_t * )ii , * p ++ );
1166
+ address += 2 ; // Select next EEPROM byte
1167
+ ii ++ ;
1168
+ size -- ;
1169
+ }
1170
+ msgLength = 2 ;
1171
+ msgBuffer [1 ] = STATUS_CMD_OK ;
1162
1172
}
1163
- msgLength = 2 ;
1164
- msgBuffer [1 ] = STATUS_CMD_OK ;
1165
1173
}
1166
1174
break ;
1167
1175
0 commit comments