Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix jtag3_page_erase for targets with UPDI #1112

Merged
merged 2 commits into from
Oct 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/jtag3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -1700,8 +1700,8 @@ static int jtag3_page_erase(const PROGRAMMER *pgm, const AVRPART *p, const AVRME
cmd[1] = CMD3_ERASE_MEMORY;
cmd[2] = 0;

if (strcmp(m->desc, "flash") == 0) {
if (jtag3_memtype(pgm, p, addr) == MTYPE_FLASH)
if (avr_mem_is_flash_type(m)) {
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;
Expand All @@ -1710,14 +1710,17 @@ static int jtag3_page_erase(const PROGRAMMER *pgm, const AVRPART *p, const AVRME
} else if (strcmp(m->desc, "usersig") == 0 ||
strcmp(m->desc, "userrow") == 0) {
cmd[3] = XMEGA_ERASE_USERSIG;
} else if (strcmp(m->desc, "boot") == 0) {
cmd[3] = XMEGA_ERASE_BOOT_PAGE;
} else {
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;

Expand Down