- if ((retval = target_write_buffer(target,
- pic32mx_info->write_algorithm->address,
- sizeof(pic32mx_flash_write_code),
- (uint8_t*)pic32mx_flash_write_code)) != ERROR_OK)
+ /* Change values for counters and row size, depending on variant */
+ if (pic32mx_info->dev_type == MX_1_2) {
+ /* 128 byte row */
+ pic32mx_flash_write_code[8] = 0x2CD30020;
+ pic32mx_flash_write_code[14] = 0x24840080;
+ pic32mx_flash_write_code[15] = 0x24A50080;
+ pic32mx_flash_write_code[17] = 0x24C6FFE0;
+ row_size = 128;
+ } else {
+ /* 512 byte row */
+ pic32mx_flash_write_code[8] = 0x2CD30080;
+ pic32mx_flash_write_code[14] = 0x24840200;
+ pic32mx_flash_write_code[15] = 0x24A50200;
+ pic32mx_flash_write_code[17] = 0x24C6FF80;
+ row_size = 512;
+ }
+
+ uint8_t code[sizeof(pic32mx_flash_write_code)];
+ target_buffer_set_u32_array(target, code, ARRAY_SIZE(pic32mx_flash_write_code),
+ pic32mx_flash_write_code);
+ retval = target_write_buffer(target, write_algorithm->address, sizeof(code), code);
+ if (retval != ERROR_OK)