added experemental -xf= option to override flash size on isp

This commit is contained in:
MX682X
2024-12-16 23:41:44 +01:00
parent e09370f1fa
commit 8aa795be04
3 changed files with 291 additions and 178 deletions

View File

@@ -92,6 +92,8 @@ struct pdata {
unsigned char dW_switched_isp;
unsigned int overwrite_flash;
unsigned char devID[4]; // Last byte has the Chip Revision of the target
unsigned char app_version[3]; // Buffer for display() sent by get_fw()
unsigned char fw_info[16]; // Buffer for display() sent by get_fw()
@@ -278,6 +280,10 @@ static int pickit5_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) {
my.hvupdi_enabled = 1;
continue;
}
if(str_starts(extended_param, "f=")) {
sscanf(extended_param, "f=%d", &my.overwrite_flash);
continue;
}
if(str_eq(extended_param, "help")) {
msg_error("%s -c %s extended options:\n", progname, pgmid);
@@ -513,14 +519,21 @@ static void pickit5_enable(PROGRAMMER *pgm, const AVRPART *p) {
}
if(is_debugwire(pgm)) {
if((mem = avr_locate_flash(p))) {
mem->page_size = mem->size < 1024? mem->size : 1024; // The Flash Write function needs 1600 bytes
mem->page_size = mem->size < 1024? mem->size : 1024; // The Flash Write function on DW needs 1600 bytes
mem->readsize = mem->size < 1024? mem->size : 1024; // this reduces overhead and speeds things up
}
}
if(is_isp(pgm)){
if((mem = avr_locate_flash(p))) {
mem->page_size = mem->size < 1024? mem->size : 1024;
mem->readsize = mem->size < 1024? mem->size : 1024;
if (mem->mode != 0x04) { // Don't change default flash settings on old AVRs
mem->page_size = mem->size < 1024? mem->size : 1024;
mem->readsize = mem->size < 1024? mem->size : 1024;
}
if(my.overwrite_flash > 0) {
mem->page_size = my.overwrite_flash;
mem->readsize = my.overwrite_flash;
mem->blocksize = my.overwrite_flash;
}
}
if((mem = avr_locate_eeprom(p))) {
if (mem->mode == 0x04) { // Increasing minimal write/read length so that the old AVRs work with PK5
@@ -577,16 +590,15 @@ static void pickit5_print_parms(const PROGRAMMER *pgm, FILE *fp) {
}
static int pickit5_updi_init(const PROGRAMMER *pgm, const AVRPART *p, double v_target) {
// Get SIB so we can get the NVM Version
if(pickit5_program_enable(pgm, p) < 0)
return -1;
// Get SIB so we can get the NVM Version
if(pickit5_updi_read_sib(pgm, p, my.sib_string) < 0) {
pmsg_error("failed to obtain System Info Block\n");
return -1;
}
if(pickit5_read_dev_id(pgm, p) < 0) {
pmsg_error("failed to obtain device ID\n");
return -1;
@@ -630,6 +642,7 @@ static int pickit5_updi_init(const PROGRAMMER *pgm, const AVRPART *p, double v_t
}
}
}
if(pickit5_set_sck_period(pgm, 1.0 / baud) >= 0) {
pmsg_notice("UPDI speed set to %i kHz\n", baud / 1000);
my.actual_pgm_clk = baud;
@@ -715,10 +728,14 @@ static int pickit5_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
return -1; // Verify voltage
// Make sure the voltage is in our requested range. Due to voltage drop on
// the LDO and on USB itself, the lower voltage has a wider allowed range
if(v_target < my.target_voltage - 0.5
|| v_target > my.target_voltage + 0.15) {
pmsg_error("target voltage out of range, aborting\n");
// the LDO and on USB itself, the lower limit is capped at 4.4V
double upper_limit = my.target_voltage + 0.2;
double lower_limit = my.target_voltage - 0.3;
if (lower_limit > 4.4) {
lower_limit = 4.4;
}
if((v_target < lower_limit) || (v_target > upper_limit)) {
pmsg_error("target voltage (%1.2fV) is outside of allowed range, aborting\n", v_target);
return -1;
}
} else {
@@ -788,26 +805,22 @@ static int pickit5_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
}
}
if(my.pk_op_mode == PK_OP_READY) {
if(pickit5_send_script(pgm, SCR_CMD, enter_prog, enter_prog_len, NULL, 0, 0) < 0)
return -1;
if(pickit5_read_response(pgm) < 0)
if(pickit5_send_script_cmd(pgm, enter_prog, enter_prog_len, NULL, 0) < 0) {
return -1;
}
}
return 0;
}
static int pickit5_program_disable(const PROGRAMMER *pgm, const AVRPART *p) {
pmsg_debug("%s()\n", __func__);
const unsigned char *enter_prog = my.scripts.ExitProgMode;
unsigned int enter_prog_len = my.scripts.ExitProgMode_len;
const unsigned char *exit_prog = my.scripts.ExitProgMode;
unsigned int exit_prog_len = my.scripts.ExitProgMode_len;
if(my.pk_op_mode == PK_OP_READY) {
if(pickit5_send_script(pgm, SCR_CMD, enter_prog, enter_prog_len, NULL, 0, 0) < 0)
return -1;
if(pickit5_read_response(pgm) < 0)
if(pickit5_send_script_cmd(pgm, exit_prog, exit_prog_len, NULL, 0) < 0) {
return -1;
}
}
return 0;
}
@@ -822,14 +835,12 @@ static int pickit5_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
const unsigned char *chip_erase = my.scripts.EraseChip;
unsigned int chip_erase_len = my.scripts.EraseChip_len;
if(pickit5_send_script(pgm, SCR_CMD, chip_erase, chip_erase_len, NULL, 0, 0) >= 0) {
if(pickit5_read_response(pgm) >= 0) {
if(pickit5_array_to_uint32(&(my.rxBuf[16])) == 0x00) {
pmsg_info("target successfully erased\n");
my.pk_op_mode = PK_OP_READY;
pickit5_program_enable(pgm, p);
return 0;
}
if(pickit5_send_script_cmd(pgm, chip_erase, chip_erase_len, NULL, 0) >= 0) {
if(pickit5_array_to_uint32(&(my.rxBuf[16])) == 0x00) {
pmsg_info("target successfully erased\n");
my.pk_op_mode = PK_OP_READY;
pickit5_program_enable(pgm, p);
return 0;
}
}
@@ -856,13 +867,12 @@ static int pickit5_set_sck_period(const PROGRAMMER *pgm, double sckperiod) {
const unsigned char *set_speed = my.scripts.SetSpeed;
unsigned int set_speed_len = my.scripts.SetSpeed_len;
unsigned char buf[4];
if(set_speed == NULL) { // debugWire is fun . . .
return 0; // No script, to execute, return success
if(set_speed == NULL) { // debugWire has no set speed, return success
return 0;
}
pickit5_uint32_to_array(buf, frq);
if(pickit5_send_script(pgm, SCR_CMD, set_speed, set_speed_len, buf, 4, 0) >= 0) {
if(pickit5_read_response(pgm) >= 0)
if(pickit5_send_script_cmd(pgm, set_speed, set_speed_len, buf, 4) >= 0) {
return 0;
}

View File

@@ -270,6 +270,26 @@ const unsigned char WriteProgmem_updi_5[231] = {
0x10, 0x00, 0x00, 0x1e, 0x06, 0x02, 0x0b,
};
const unsigned char WriteProgmem_updi_6[272] = {
0x91, 0x00, 0x91, 0x01, 0x90, 0x02, 0x07, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02,
0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x11, 0x00, 0x00,
0x00, 0x00, 0x90, 0x0f, 0x00, 0x02, 0x00, 0x00, 0xfa, 0x01, 0x0f, 0x30, 0x00, 0x60, 0x0f, 0x01,
0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x08, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07,
0x90, 0x06, 0xff, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x00, 0x06, 0x90, 0x02, 0x07, 0x10, 0x00, 0x00,
0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06,
0x06, 0x07, 0x90, 0x02, 0x07, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5,
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00,
0x90, 0x07, 0x02, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x90, 0x10, 0x00, 0x01, 0x00, 0x00,
0xfa, 0x0f, 0x10, 0xa8, 0x00, 0x60, 0x10, 0x0f, 0x1e, 0x09, 0x00, 0x60, 0x04, 0x10, 0x67, 0x04,
0x01, 0x1e, 0x10, 0x04, 0x1e, 0x0b, 0x04, 0x6a, 0x0f, 0x10, 0x6e, 0x00, 0x10, 0x6a, 0x01, 0x10,
0xfc, 0x0f, 0x11, 0x9a, 0x00, 0x6c, 0x0c, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0d,
0x00, 0x01, 0x90, 0x02, 0x07, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5,
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00,
0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0xfc, 0x01, 0x11, 0x22, 0x00, 0x5a,
0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07,
};
const unsigned char ReadProgmem_updi_0[73] = {
0x91, 0x00, 0x91, 0x01, 0x95, 0x90, 0x11, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0f, 0x40, 0x00, 0x00,
0x00, 0xfa, 0x01, 0x0f, 0x19, 0x00, 0x60, 0x0f, 0x01, 0x90, 0x10, 0x00, 0x01, 0x00, 0x00, 0xfa,
@@ -370,6 +390,20 @@ const unsigned char WriteDataEEmem_updi_4[176] = {
0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07,
};
const unsigned char WriteDataEEmem_updi_5[176] = {
0x91, 0x00, 0x91, 0x01, 0x90, 0x11, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0f, 0x01, 0x00, 0x00, 0x00,
0xfa, 0x01, 0x0f, 0x18, 0x00, 0x60, 0x0f, 0x01, 0x90, 0x02, 0x07, 0x10, 0x00, 0x00, 0xa2, 0x1e,
0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00,
0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x13, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07,
0x90, 0x10, 0x00, 0x01, 0x00, 0x00, 0xfa, 0x0f, 0x10, 0x4e, 0x00, 0x60, 0x10, 0x0f, 0x1e, 0x09,
0x00, 0x1e, 0x10, 0x10, 0x1e, 0x0a, 0x10, 0x6a, 0x0f, 0x10, 0x6e, 0x00, 0x10, 0x6a, 0x01, 0x10,
0xfc, 0x0f, 0x11, 0x40, 0x00, 0x6c, 0x0c, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0d,
0xa0, 0x00, 0x90, 0x02, 0x07, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5,
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00,
0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0xfc, 0x01, 0x11, 0x0a, 0x00, 0x5a,
0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07,
};
const unsigned char ReadDataEEmem_updi_0[67] = {
0x91, 0x00, 0x91, 0x01, 0x95, 0x90, 0x11, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0f, 0x20, 0x00, 0x00,
0x00, 0xfa, 0x01, 0x0f, 0x19, 0x00, 0x60, 0x0f, 0x01, 0x90, 0x10, 0x00, 0x01, 0x00, 0x00, 0xfa,
@@ -478,6 +512,17 @@ const unsigned char WriteConfigmem_updi_3[128] = {
0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07,
};
const unsigned char WriteConfigmem_updi_4[128] = {
0x91, 0x00, 0x91, 0x01, 0xad, 0x01, 0x90, 0x02, 0x07, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02,
0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06,
0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x13, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x99, 0x03,
0x1e, 0x06, 0x00, 0x03, 0x6c, 0x0c, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0d, 0x70,
0x00, 0x90, 0x02, 0x07, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90,
0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x92, 0x00, 0x01, 0x00, 0x00, 0x00, 0xae,
0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07,
};
const unsigned char WriteConfigmemFuse_updi_0[369] = {
0x91, 0x00, 0x91, 0x01, 0x90, 0x03, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x03, 0x01, 0x00, 0x00, 0x00,
0x93, 0x00, 0xad, 0x01, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02,
@@ -554,6 +599,17 @@ const unsigned char WriteConfigmemFuse_updi_3[128] = {
0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07,
};
const unsigned char WriteConfigmemFuse_updi_4[128] = {
0x91, 0x00, 0x91, 0x01, 0xad, 0x01, 0x90, 0x02, 0x07, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02,
0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06,
0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x13, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x99, 0x03,
0x1e, 0x06, 0x00, 0x03, 0x6c, 0x0c, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0d, 0x70,
0x00, 0x90, 0x02, 0x07, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90,
0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x92, 0x00, 0x01, 0x00, 0x00, 0x00, 0xae,
0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07,
};
const unsigned char WriteConfigmemLock_updi_0[369] = {
0x91, 0x00, 0x91, 0x01, 0x90, 0x03, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x03, 0x01, 0x00, 0x00, 0x00,
0x93, 0x00, 0xad, 0x01, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02,
@@ -630,6 +686,17 @@ const unsigned char WriteConfigmemLock_updi_3[128] = {
0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07,
};
const unsigned char WriteConfigmemLock_updi_4[128] = {
0x91, 0x00, 0x91, 0x01, 0xad, 0x01, 0x90, 0x02, 0x07, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02,
0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06,
0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x13, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x99, 0x03,
0x1e, 0x06, 0x00, 0x03, 0x6c, 0x0c, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0d, 0x70,
0x00, 0x90, 0x02, 0x07, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90,
0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x92, 0x00, 0x01, 0x00, 0x00, 0x00, 0xae,
0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07,
};
const unsigned char ReadConfigmem_updi_0[19] = {
0x91, 0x00, 0x91, 0x01, 0x95, 0xad, 0x01, 0x1e, 0x03, 0x00, 0x9f, 0x92, 0x00, 0x01, 0x00, 0x00,
0x00, 0xae, 0x5a,
@@ -775,6 +842,26 @@ const unsigned char WriteIDmem_updi_4[266] = {
0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07,
};
const unsigned char WriteIDmem_updi_5[266] = {
0x91, 0x00, 0x91, 0x01, 0x90, 0x11, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0f, 0x20, 0x00, 0x00, 0x00,
0xfa, 0x01, 0x0f, 0x18, 0x00, 0x60, 0x0f, 0x01, 0x90, 0x02, 0x07, 0x10, 0x00, 0x00, 0xa2, 0x1e,
0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00,
0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x08, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07,
0x90, 0x06, 0xff, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x00, 0x06, 0x90, 0x02, 0x07, 0x10, 0x00, 0x00,
0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06,
0x06, 0x07, 0x90, 0x02, 0x07, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5,
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00,
0x90, 0x07, 0x02, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x90, 0x10, 0x00, 0x01, 0x00, 0x00,
0xfa, 0x0f, 0x10, 0xa8, 0x00, 0x60, 0x10, 0x0f, 0x1e, 0x09, 0x00, 0x1e, 0x10, 0x10, 0x1e, 0x0a,
0x10, 0x6a, 0x0f, 0x10, 0x6e, 0x00, 0x10, 0x6a, 0x01, 0x10, 0xfc, 0x0f, 0x11, 0x9a, 0x00, 0x6c,
0x0c, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0d, 0xfa, 0x00, 0x90, 0x02, 0x07, 0x10,
0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00,
0x1e, 0x06, 0x06, 0x07, 0xfc, 0x01, 0x11, 0x0a, 0x00, 0x5a, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00,
0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07,
};
const unsigned char ReadIDmem_updi_0[67] = {
0x91, 0x00, 0x91, 0x01, 0x95, 0x90, 0x11, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0f, 0x20, 0x00, 0x00,
0x00, 0xfa, 0x01, 0x0f, 0x19, 0x00, 0x60, 0x0f, 0x01, 0x90, 0x10, 0x00, 0x01, 0x00, 0x00, 0xfa,
@@ -863,20 +950,21 @@ static void pickit_updi_script_init(SCRIPT *scr) {
const char * const pickit5_updi_chip_lut[] = {
"ATtiny416auto", "ATmega1608", "ATmega1609", "ATmega3208", "ATmega3209", "ATmega4808", "ATmega4809", "ATmega808",
"ATmega809", "ATtiny1604", "ATtiny1606", "ATtiny1607", "ATtiny1614", "ATtiny1616", "ATtiny1617", "ATtiny1624",
"ATtiny1626", "ATtiny1627", "ATtiny202", "ATtiny204", "ATtiny212", "ATtiny214", "ATtiny3216", "ATtiny3217",
"ATtiny3224", "ATtiny3226", "ATtiny3227", "ATtiny402", "ATtiny404", "ATtiny406", "ATtiny412", "ATtiny414",
"ATtiny416", "ATtiny417", "ATtiny424", "ATtiny426", "ATtiny427", "ATtiny804", "ATtiny806", "ATtiny807",
"ATtiny814", "ATtiny816", "ATtiny817", "ATtiny824", "ATtiny826", "ATtiny827", "AVR128DA28", "AVR128DA32",
"AVR128DA48", "AVR128DA64", "AVR128DB28", "AVR128DB32", "AVR128DB48", "AVR128DB64", "AVR16DD14", "AVR16DD20",
"AVR16DD28", "AVR16DD32", "AVR32DA28", "AVR32DA32", "AVR32DA48", "AVR32DB28", "AVR32DB32", "AVR32DB48",
"AVR32DD14", "AVR32DD20", "AVR32DD28", "AVR32DD32", "AVR64DA28", "AVR64DA32", "AVR64DA48", "AVR64DA64",
"AVR64DB28", "AVR64DB32", "AVR64DB48", "AVR64DB64", "AVR64DD14", "AVR64DD20", "AVR64DD28", "AVR64DD32",
"AVR64EA28", "AVR64EA32", "AVR64EA48", "AVR16DU14", "AVR16DU20", "AVR16DU28", "AVR16DU32", "AVR32DU14",
"AVR32DU20", "AVR32DU28", "AVR32DU32", "AVR64DU28", "AVR64DU32", "AVR16EA28", "AVR16EA32", "AVR16EA48",
"AVR32EA28", "AVR32EA32", "AVR32EA48", "AVR8EA28", "AVR8EA32", "AVR16EB14", "AVR16EB20", "AVR16EB28",
"AVR16EB32",
"ATmega1608", "ATmega1609", "ATmega3208", "ATmega3209", "ATmega4808", "ATmega4809", "ATmega808", "ATmega809",
"ATtiny1604", "ATtiny1606", "ATtiny1607", "ATtiny1614", "ATtiny1616", "ATtiny1617", "ATtiny1624", "ATtiny1626",
"ATtiny1627", "ATtiny202", "ATtiny204", "ATtiny212", "ATtiny214", "ATtiny3216", "ATtiny3217", "ATtiny3224",
"ATtiny3226", "ATtiny3227", "ATtiny402", "ATtiny404", "ATtiny406", "ATtiny412", "ATtiny414", "ATtiny416",
"ATtiny417", "ATtiny424", "ATtiny426", "ATtiny427", "ATtiny804", "ATtiny806", "ATtiny807", "ATtiny814",
"ATtiny816", "ATtiny817", "ATtiny824", "ATtiny826", "ATtiny827", "AVR128DA28", "AVR128DA32", "AVR128DA48",
"AVR128DA64", "AVR128DB28", "AVR128DB32", "AVR128DB48", "AVR128DB64", "AVR16DD14", "AVR16DD20", "AVR16DD28",
"AVR16DD32", "AVR32DA28", "AVR32DA32", "AVR32DA48", "AVR32DB28", "AVR32DB32", "AVR32DB48", "AVR32DD14",
"AVR32DD20", "AVR32DD28", "AVR32DD32", "AVR64DA28", "AVR64DA32", "AVR64DA48", "AVR64DA64", "AVR64DB28",
"AVR64DB32", "AVR64DB48", "AVR64DB64", "AVR64DD14", "AVR64DD20", "AVR64DD28", "AVR64DD32", "AVR64EA28",
"AVR64EA32", "AVR64EA48", "AVR16DA28", "AVR16DA32", "AVR16DA48", "AVR16DB28", "AVR16DB32", "AVR16DB48",
"AVR16DU14", "AVR16DU20", "AVR16DU28", "AVR16DU32", "AVR32DU14", "AVR32DU20", "AVR32DU28", "AVR32DU32",
"AVR64DU28", "AVR64DU32", "AVR16EA28", "AVR16EA32", "AVR16EA48", "AVR32EA28", "AVR32EA32", "AVR32EA48",
"AVR8EA28", "AVR8EA32", "AVR16EB14", "AVR16EB20", "AVR16EB28", "AVR16EB32", "AVR32EB28", "AVR32EB32",
"AVR32SD32", "AVR64SD48",
};
const unsigned char * get_devid_script_by_nvm_ver(unsigned char version) {
@@ -893,7 +981,7 @@ int get_pickit_updi_script(SCRIPT *scr, const char* partdesc) {
return -1;
}
int namepos = -1;
for (int i = 0; i < 105; i++) {
for (int i = 0; i < 114; i++) {
if (strncmp(pickit5_updi_chip_lut[i], partdesc, 10) == 0) {
namepos = i;
break;
@@ -906,43 +994,42 @@ int get_pickit_updi_script(SCRIPT *scr, const char* partdesc) {
pickit_updi_script_init(scr); // load common functions
switch (namepos) {
case 0: /* ATtiny416auto */
case 1: /* ATmega1608 */
case 2: /* ATmega1609 */
case 7: /* ATmega808 */
case 8: /* ATmega809 */
case 9: /* ATtiny1604 */
case 10: /* ATtiny1606 */
case 11: /* ATtiny1607 */
case 12: /* ATtiny1614 */
case 13: /* ATtiny1616 */
case 14: /* ATtiny1617 */
case 15: /* ATtiny1624 */
case 16: /* ATtiny1626 */
case 17: /* ATtiny1627 */
case 18: /* ATtiny202 */
case 19: /* ATtiny204 */
case 20: /* ATtiny212 */
case 21: /* ATtiny214 */
case 27: /* ATtiny402 */
case 28: /* ATtiny404 */
case 29: /* ATtiny406 */
case 30: /* ATtiny412 */
case 31: /* ATtiny414 */
case 32: /* ATtiny416 */
case 33: /* ATtiny417 */
case 34: /* ATtiny424 */
case 35: /* ATtiny426 */
case 36: /* ATtiny427 */
case 37: /* ATtiny804 */
case 38: /* ATtiny806 */
case 39: /* ATtiny807 */
case 40: /* ATtiny814 */
case 41: /* ATtiny816 */
case 42: /* ATtiny817 */
case 43: /* ATtiny824 */
case 44: /* ATtiny826 */
case 45: /* ATtiny827 */
case 0: /* ATmega1608 */
case 1: /* ATmega1609 */
case 6: /* ATmega808 */
case 7: /* ATmega809 */
case 8: /* ATtiny1604 */
case 9: /* ATtiny1606 */
case 10: /* ATtiny1607 */
case 11: /* ATtiny1614 */
case 12: /* ATtiny1616 */
case 13: /* ATtiny1617 */
case 14: /* ATtiny1624 */
case 15: /* ATtiny1626 */
case 16: /* ATtiny1627 */
case 17: /* ATtiny202 */
case 18: /* ATtiny204 */
case 19: /* ATtiny212 */
case 20: /* ATtiny214 */
case 26: /* ATtiny402 */
case 27: /* ATtiny404 */
case 28: /* ATtiny406 */
case 29: /* ATtiny412 */
case 30: /* ATtiny414 */
case 31: /* ATtiny416 */
case 32: /* ATtiny417 */
case 33: /* ATtiny424 */
case 34: /* ATtiny426 */
case 35: /* ATtiny427 */
case 36: /* ATtiny804 */
case 37: /* ATtiny806 */
case 38: /* ATtiny807 */
case 39: /* ATtiny814 */
case 40: /* ATtiny816 */
case 41: /* ATtiny817 */
case 42: /* ATtiny824 */
case 43: /* ATtiny826 */
case 44: /* ATtiny827 */
scr->GetDeviceID = GetDeviceID_updi_0;
scr->GetDeviceID_len = sizeof(GetDeviceID_updi_0);
scr->WriteProgmem = WriteProgmem_updi_0;
@@ -964,12 +1051,12 @@ int get_pickit_updi_script(SCRIPT *scr, const char* partdesc) {
scr->ReadIDmem = ReadIDmem_updi_0;
scr->ReadIDmem_len = sizeof(ReadIDmem_updi_0);
break;
case 3: /* ATmega3208 */
case 4: /* ATmega3209 */
case 5: /* ATmega4808 */
case 6: /* ATmega4809 */
case 22: /* ATtiny3216 */
case 23: /* ATtiny3217 */
case 2: /* ATmega3208 */
case 3: /* ATmega3209 */
case 4: /* ATmega4808 */
case 5: /* ATmega4809 */
case 21: /* ATtiny3216 */
case 22: /* ATtiny3217 */
scr->GetDeviceID = GetDeviceID_updi_0;
scr->GetDeviceID_len = sizeof(GetDeviceID_updi_0);
scr->WriteProgmem = WriteProgmem_updi_1;
@@ -991,9 +1078,9 @@ int get_pickit_updi_script(SCRIPT *scr, const char* partdesc) {
scr->ReadIDmem = ReadIDmem_updi_1;
scr->ReadIDmem_len = sizeof(ReadIDmem_updi_1);
break;
case 24: /* ATtiny3224 */
case 25: /* ATtiny3226 */
case 26: /* ATtiny3227 */
case 23: /* ATtiny3224 */
case 24: /* ATtiny3226 */
case 25: /* ATtiny3227 */
scr->GetDeviceID = GetDeviceID_updi_0;
scr->GetDeviceID_len = sizeof(GetDeviceID_updi_0);
scr->WriteProgmem = WriteProgmem_updi_1;
@@ -1015,40 +1102,46 @@ int get_pickit_updi_script(SCRIPT *scr, const char* partdesc) {
scr->ReadIDmem = ReadIDmem_updi_0;
scr->ReadIDmem_len = sizeof(ReadIDmem_updi_0);
break;
case 46: /* AVR128DA28 */
case 47: /* AVR128DA32 */
case 48: /* AVR128DA48 */
case 49: /* AVR128DA64 */
case 50: /* AVR128DB28 */
case 51: /* AVR128DB32 */
case 52: /* AVR128DB48 */
case 53: /* AVR128DB64 */
case 54: /* AVR16DD14 */
case 55: /* AVR16DD20 */
case 56: /* AVR16DD28 */
case 57: /* AVR16DD32 */
case 58: /* AVR32DA28 */
case 59: /* AVR32DA32 */
case 60: /* AVR32DA48 */
case 61: /* AVR32DB28 */
case 62: /* AVR32DB32 */
case 63: /* AVR32DB48 */
case 64: /* AVR32DD14 */
case 65: /* AVR32DD20 */
case 66: /* AVR32DD28 */
case 67: /* AVR32DD32 */
case 68: /* AVR64DA28 */
case 69: /* AVR64DA32 */
case 70: /* AVR64DA48 */
case 71: /* AVR64DA64 */
case 72: /* AVR64DB28 */
case 73: /* AVR64DB32 */
case 74: /* AVR64DB48 */
case 75: /* AVR64DB64 */
case 76: /* AVR64DD14 */
case 77: /* AVR64DD20 */
case 78: /* AVR64DD28 */
case 79: /* AVR64DD32 */
case 45: /* AVR128DA28 */
case 46: /* AVR128DA32 */
case 47: /* AVR128DA48 */
case 48: /* AVR128DA64 */
case 49: /* AVR128DB28 */
case 50: /* AVR128DB32 */
case 51: /* AVR128DB48 */
case 52: /* AVR128DB64 */
case 53: /* AVR16DD14 */
case 54: /* AVR16DD20 */
case 55: /* AVR16DD28 */
case 56: /* AVR16DD32 */
case 57: /* AVR32DA28 */
case 58: /* AVR32DA32 */
case 59: /* AVR32DA48 */
case 60: /* AVR32DB28 */
case 61: /* AVR32DB32 */
case 62: /* AVR32DB48 */
case 63: /* AVR32DD14 */
case 64: /* AVR32DD20 */
case 65: /* AVR32DD28 */
case 66: /* AVR32DD32 */
case 67: /* AVR64DA28 */
case 68: /* AVR64DA32 */
case 69: /* AVR64DA48 */
case 70: /* AVR64DA64 */
case 71: /* AVR64DB28 */
case 72: /* AVR64DB32 */
case 73: /* AVR64DB48 */
case 74: /* AVR64DB64 */
case 75: /* AVR64DD14 */
case 76: /* AVR64DD20 */
case 77: /* AVR64DD28 */
case 78: /* AVR64DD32 */
case 82: /* AVR16DA28 */
case 83: /* AVR16DA32 */
case 84: /* AVR16DA48 */
case 85: /* AVR16DB28 */
case 86: /* AVR16DB32 */
case 87: /* AVR16DB48 */
scr->GetDeviceID = GetDeviceID_updi_0;
scr->GetDeviceID_len = sizeof(GetDeviceID_updi_0);
scr->WriteProgmem = WriteProgmem_updi_2;
@@ -1070,9 +1163,9 @@ int get_pickit_updi_script(SCRIPT *scr, const char* partdesc) {
scr->ReadIDmem = ReadIDmem_updi_0;
scr->ReadIDmem_len = sizeof(ReadIDmem_updi_0);
break;
case 80: /* AVR64EA28 */
case 81: /* AVR64EA32 */
case 82: /* AVR64EA48 */
case 79: /* AVR64EA28 */
case 80: /* AVR64EA32 */
case 81: /* AVR64EA48 */
scr->GetDeviceID = GetDeviceID_updi_0;
scr->GetDeviceID_len = sizeof(GetDeviceID_updi_0);
scr->WriteProgmem = WriteProgmem_updi_3;
@@ -1094,16 +1187,16 @@ int get_pickit_updi_script(SCRIPT *scr, const char* partdesc) {
scr->ReadIDmem = ReadIDmem_updi_1;
scr->ReadIDmem_len = sizeof(ReadIDmem_updi_1);
break;
case 83: /* AVR16DU14 */
case 84: /* AVR16DU20 */
case 85: /* AVR16DU28 */
case 86: /* AVR16DU32 */
case 87: /* AVR32DU14 */
case 88: /* AVR32DU20 */
case 89: /* AVR32DU28 */
case 90: /* AVR32DU32 */
case 91: /* AVR64DU28 */
case 92: /* AVR64DU32 */
case 88: /* AVR16DU14 */
case 89: /* AVR16DU20 */
case 90: /* AVR16DU28 */
case 91: /* AVR16DU32 */
case 92: /* AVR32DU14 */
case 93: /* AVR32DU20 */
case 94: /* AVR32DU28 */
case 95: /* AVR32DU32 */
case 96: /* AVR64DU28 */
case 97: /* AVR64DU32 */
scr->GetDeviceID = GetDeviceID_updi_1;
scr->GetDeviceID_len = sizeof(GetDeviceID_updi_1);
scr->WriteProgmem = WriteProgmem_updi_4;
@@ -1125,14 +1218,14 @@ int get_pickit_updi_script(SCRIPT *scr, const char* partdesc) {
scr->ReadIDmem = ReadIDmem_updi_2;
scr->ReadIDmem_len = sizeof(ReadIDmem_updi_2);
break;
case 93: /* AVR16EA28 */
case 94: /* AVR16EA32 */
case 95: /* AVR16EA48 */
case 96: /* AVR32EA28 */
case 97: /* AVR32EA32 */
case 98: /* AVR32EA48 */
case 99: /* AVR8EA28 */
case 100: /* AVR8EA32 */
case 98: /* AVR16EA28 */
case 99: /* AVR16EA32 */
case 100: /* AVR16EA48 */
case 101: /* AVR32EA28 */
case 102: /* AVR32EA32 */
case 103: /* AVR32EA48 */
case 104: /* AVR8EA28 */
case 105: /* AVR8EA32 */
scr->GetDeviceID = GetDeviceID_updi_0;
scr->GetDeviceID_len = sizeof(GetDeviceID_updi_0);
scr->WriteProgmem = WriteProgmem_updi_5;
@@ -1154,10 +1247,12 @@ int get_pickit_updi_script(SCRIPT *scr, const char* partdesc) {
scr->ReadIDmem = ReadIDmem_updi_1;
scr->ReadIDmem_len = sizeof(ReadIDmem_updi_1);
break;
case 101: /* AVR16EB14 */
case 102: /* AVR16EB20 */
case 103: /* AVR16EB28 */
case 104: /* AVR16EB32 */
case 106: /* AVR16EB14 */
case 107: /* AVR16EB20 */
case 108: /* AVR16EB28 */
case 109: /* AVR16EB32 */
case 110: /* AVR32EB28 */
case 111: /* AVR32EB32 */
scr->GetDeviceID = GetDeviceID_updi_1;
scr->GetDeviceID_len = sizeof(GetDeviceID_updi_1);
scr->WriteProgmem = WriteProgmem_updi_5;
@@ -1179,6 +1274,29 @@ int get_pickit_updi_script(SCRIPT *scr, const char* partdesc) {
scr->ReadIDmem = ReadIDmem_updi_1;
scr->ReadIDmem_len = sizeof(ReadIDmem_updi_1);
break;
case 112: /* AVR32SD32 */
case 113: /* AVR64SD48 */
scr->GetDeviceID = GetDeviceID_updi_1;
scr->GetDeviceID_len = sizeof(GetDeviceID_updi_1);
scr->WriteProgmem = WriteProgmem_updi_6;
scr->WriteProgmem_len = sizeof(WriteProgmem_updi_6);
scr->ReadProgmem = ReadProgmem_updi_2;
scr->ReadProgmem_len = sizeof(ReadProgmem_updi_2);
scr->WriteDataEEmem = WriteDataEEmem_updi_5;
scr->WriteDataEEmem_len = sizeof(WriteDataEEmem_updi_5);
scr->ReadDataEEmem = ReadDataEEmem_updi_2;
scr->ReadDataEEmem_len = sizeof(ReadDataEEmem_updi_2);
scr->WriteConfigmem = WriteConfigmem_updi_4;
scr->WriteConfigmem_len = sizeof(WriteConfigmem_updi_4);
scr->WriteConfigmemFuse = WriteConfigmemFuse_updi_4;
scr->WriteConfigmemFuse_len = sizeof(WriteConfigmemFuse_updi_4);
scr->WriteConfigmemLock = WriteConfigmemLock_updi_4;
scr->WriteConfigmemLock_len = sizeof(WriteConfigmemLock_updi_4);
scr->WriteIDmem = WriteIDmem_updi_5;
scr->WriteIDmem_len = sizeof(WriteIDmem_updi_5);
scr->ReadIDmem = ReadIDmem_updi_0;
scr->ReadIDmem_len = sizeof(ReadIDmem_updi_0);
break;
}
return 0;
}

View File

@@ -86,8 +86,11 @@ c_func_list = [
"ReadBootMem",
]
# List of MCUs that are supported by avrdude, extracted from the .conf file
mcu_list = []
# List of MCUs Names that are not supported by avrdude
mcu_to_exclude = [
"ATA5700M322", "ATA5702M322", "ATA5782", "ATA5787", "ATA5831", "ATA5835", "ATA8210", "ATA8510",
"ATtiny416auto", "AVR16DV14", "AVR16DV20", "AVR64EC48"
]
import platform
@@ -243,7 +246,6 @@ def convert_xml(xml_path, c_funcs):
# Prepare directories
parent_dir = os.getcwd()
src_dir = os.path.join(parent_dir, "src")
conf_path = os.path.join(src_dir, "avrdude.conf.in")
print("Opening file {0}".format(xml_path))
print("Parent Dir: {0}".format(parent_dir))
print("Src directory: {0}".format(src_dir))
@@ -252,21 +254,10 @@ def convert_xml(xml_path, c_funcs):
# create h-File (make sure to provide all function definitions)
generate_h_file(c_funcs, src_dir)
with open(conf_path, "r") as conf_file:
while True:
line = conf_file.readline()
if line == "":
print("List of MCUs created with {0} devices".format(len(mcu_list)))
break # Exit on end of file
if line.startswith("part"):
desc = conf_file.readline().split('"', 3)[1]
if desc.lower().find("common") < 0: # Skip any desc that contains the word "common"
mcu_list.append(desc)
with open(xml_path, "r") as xml_script:
print ("XML File opened")
scr_bytes_buffer = bytearray(2048) # allocate 2kB of memory in advance
scr_bytes_buffer = bytearray(2048) # allocate 2kB of memory in advance, avoids memory managment
while True:
line = xml_script.readline() # go line by line, hopefully reducing memory usage compared to readlines()
if line == "":
@@ -288,12 +279,12 @@ def convert_xml(xml_path, c_funcs):
if programming_mode not in ["UPDI", "PDI", "dW", "ISP", "TPI", "JTAG"]:
continue # Filters out "FPGA" and other edge cases
if function_name not in c_funcs:
continue # Filter out debug Functions. Do that before mcu check, as there are over 300 MCUs and less then 50 functions
if chip_name not in mcu_list:
if chip_name in mcu_to_exclude:
continue # don't handle chips avrdude doesn't know anyway
if function_name not in c_funcs:
continue # Filter out debug Functions
func_bytes = None
counter = 0
while True:
@@ -326,7 +317,7 @@ def convert_xml(xml_path, c_funcs):
if chip_name not in program_iface[programming_mode]:
program_iface[programming_mode][chip_name] = [(function_name, index)]
#print("Added to " + programming_mode + ": " + chip_name)
#print("Added to " + programming_mode + ": " + chip_name) # Debugging
else:
program_iface[programming_mode][chip_name].append((function_name, index))
#program_iface = {
@@ -383,16 +374,12 @@ def convert_xml(xml_path, c_funcs):
common_func.append(func_name)
struct_init_func += " scr->{0} = {0}_{1}_0;\n".format(func_name, lower_prog_iface)
struct_init_len += " scr->{0}_len = sizeof({0}_{1}_0);\n".format(func_name, lower_prog_iface)
#else: # is done by a memset
# struct_init_func += " scr->{0} = NULL;\n".format(func_name)
# struct_init_len += " scr->{0}_len = 0;\n".format(func_name)
# EOFL
c_file.write("\n\n\nstatic void pickit_{0}_script_init(SCRIPT *scr);\n".format(lower_prog_iface)) # declaration
c_file.write("static void pickit_{0}_script_init(SCRIPT *scr)".format(lower_prog_iface) + " {\n") # definition
c_file.write("static void pickit_{0}_script_init(SCRIPT *scr)".format(lower_prog_iface) + " {\n") # definition
c_file.write(" memset(scr, 0x00, sizeof(SCRIPT)); // Make sure everything is NULL\n\n")
c_file.write(struct_init_func)
c_file.write("\n") # improve readability
@@ -460,9 +447,7 @@ def convert_xml(xml_path, c_funcs):
# End of switch case
print("finished " + prog_iface)
print("c-File generated")
pass