From d5e4ed9f8933b78c8f18776a212409bc8119aa00 Mon Sep 17 00:00:00 2001 From: MCUdude Date: Wed, 5 Oct 2022 23:52:05 +0200 Subject: [PATCH] Fix jtag3_page_erase for targets with UPDI Very handy to have now that #1106 is merged --- src/jtag3.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/jtag3.c b/src/jtag3.c index 902f8735..ce9fbe36 100644 --- a/src/jtag3.c +++ b/src/jtag3.c @@ -1687,8 +1687,8 @@ static int jtag3_page_erase(const PROGRAMMER *pgm, const AVRPART *p, const AVRME avrdude_message(MSG_NOTICE2, "%s: jtag3_page_erase(.., %s, 0x%x)\n", progname, m->desc, addr); - if (!(p->prog_modes & PM_PDI)) { - avrdude_message(MSG_INFO, "%s: jtag3_page_erase: not an Xmega device\n", + if (!(p->prog_modes & (PM_PDI | PM_UPDI))) { + avrdude_message(MSG_INFO, "%s: jtag3_page_erase: not supported\n", progname); return -1; } @@ -1701,7 +1701,7 @@ static int jtag3_page_erase(const PROGRAMMER *pgm, const AVRPART *p, const AVRME cmd[2] = 0; if (strcmp(m->desc, "flash") == 0) { - if (jtag3_memtype(pgm, p, addr) == MTYPE_FLASH) + if (p->prog_modes & PM_UPDI || jtag3_memtype(pgm, p, addr) == MTYPE_FLASH) cmd[3] = XMEGA_ERASE_APP_PAGE; else cmd[3] = XMEGA_ERASE_BOOT_PAGE; @@ -1716,8 +1716,13 @@ static int jtag3_page_erase(const PROGRAMMER *pgm, const AVRPART *p, const AVRME cmd[3] = XMEGA_ERASE_APP_PAGE; } - u32_to_b4(cmd + 4, addr + m->offset); + unsigned int addr_adj = addr; + if(p->prog_modes & PM_PDI) + addr_adj += m->offset; + else // PM_UPDI + addr_adj = jtag3_memaddr(pgm, p, m, addr); + u32_to_b4(cmd + 4, addr_adj); if (jtag3_command(pgm, cmd, 8, &resp, "page erase") < 0) return -1;