Submitted by Jan Egil Ruud <janegil.ruud@microchip.com>

patch #9507: Fix UPDI chip erase
* jtag3.c (jtag3_chip_erase_updi): New function
* jtag3_private.h: More constants




git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1403 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
Joerg Wunsch 2017-12-30 00:05:54 +00:00
parent ecaaa1e1d5
commit 559c20f207
4 changed files with 64 additions and 4 deletions

View File

@ -1,3 +1,10 @@
2017-12-30 Joerg Wunsch <j.gnu@uriah.heep.sax.de>
Submitted by Jan Egil Ruud <janegil.ruud@microchip.com>
patch #9507: Fix UPDI chip erase
* jtag3.c (jtag3_chip_erase_updi): New function
* jtag3_private.h: More constants
2017-12-30 Joerg Wunsch <j.gnu@uriah.heep.sax.de> 2017-12-30 Joerg Wunsch <j.gnu@uriah.heep.sax.de>
Submitted by Jan Egil Ruud <janegil.ruud@microchip.com> Submitted by Jan Egil Ruud <janegil.ruud@microchip.com>

2
NEWS
View File

@ -33,6 +33,8 @@ Current:
* Patches: * Patches:
patch #9482: Add support for UPDI and AVR8X patch #9482: Add support for UPDI and AVR8X
patch #9508: Add PowerDebugger and XPlained Mini in UPDI mode
patch #9507: Fix UPDI chip erase
* Internals: * Internals:

40
jtag3.c
View File

@ -840,8 +840,14 @@ int jtag3_recv(PROGRAMMER * pgm, unsigned char **msg) {
c = (*resp)[1]; c = (*resp)[1];
if ((c & RSP3_STATUS_MASK) != RSP3_OK) { if ((c & RSP3_STATUS_MASK) != RSP3_OK) {
avrdude_message(MSG_INFO, "%s: bad response to %s command: 0x%02x\n", if ((c == RSP3_FAILED) && ((*resp)[3] == RSP3_FAIL_OCD_LOCKED)) {
progname, descr, c); avrdude_message(MSG_INFO,
"%s: Device is locked! Chip erase required to unlock.\n",
progname);
} else {
avrdude_message(MSG_INFO, "%s: bad response to %s command: 0x%02x\n",
progname, descr, c);
}
free(*resp); free(*resp);
resp = 0; resp = 0;
return -1; return -1;
@ -895,6 +901,34 @@ static int jtag3_chip_erase(PROGRAMMER * pgm, AVRPART * p)
return 0; return 0;
} }
/*
* UPDI 'chip erase' -> 'enter progmode' with chip erase key
*/
static int jtag3_chip_erase_updi(PROGRAMMER * pgm, AVRPART * p)
{
unsigned char buf[8], *resp;
buf[0] = 1; /* Enable */
if (jtag3_setparm(pgm, SCOPE_AVR, SET_GET_CTXT_OPTIONS, PARM3_OPT_CHIP_ERASE_TO_ENTER, buf, 1) < 0)
return -1;
buf[0] = SCOPE_AVR;
buf[1] = CMD3_ENTER_PROGMODE;
buf[2] = 0;
if (jtag3_command(pgm, buf, 3, &resp, "enter progmode") < 0)
return -1;
PDATA(pgm)->prog_enabled = 1;
buf[0] = 0; /* Disable */
if (jtag3_setparm(pgm, SCOPE_AVR, SET_GET_CTXT_OPTIONS, PARM3_OPT_CHIP_ERASE_TO_ENTER, buf, 1) < 0)
return -1;
free(resp);
return 0;
}
/* /*
* There is no chip erase functionality in debugWire mode. * There is no chip erase functionality in debugWire mode.
*/ */
@ -2378,7 +2412,7 @@ void jtag3_updi_initpgm(PROGRAMMER * pgm)
pgm->enable = jtag3_enable; pgm->enable = jtag3_enable;
pgm->disable = jtag3_disable; pgm->disable = jtag3_disable;
pgm->program_enable = jtag3_program_enable_dummy; pgm->program_enable = jtag3_program_enable_dummy;
pgm->chip_erase = jtag3_chip_erase; pgm->chip_erase = jtag3_chip_erase_updi;
pgm->open = jtag3_open_updi; pgm->open = jtag3_open_updi;
pgm->close = jtag3_close; pgm->close = jtag3_close;
pgm->read_byte = jtag3_read_byte; pgm->read_byte = jtag3_read_byte;

View File

@ -144,6 +144,7 @@
# define RSP3_FAIL_WRONG_MODE 0x32 /* progmode vs. non-prog */ # define RSP3_FAIL_WRONG_MODE 0x32 /* progmode vs. non-prog */
# define RSP3_FAIL_UNSUPP_MEMORY 0x34 /* unsupported memory type */ # define RSP3_FAIL_UNSUPP_MEMORY 0x34 /* unsupported memory type */
# define RSP3_FAIL_WRONG_LENGTH 0x35 /* wrong lenth for mem access */ # define RSP3_FAIL_WRONG_LENGTH 0x35 /* wrong lenth for mem access */
# define RSP3_FAIL_OCD_LOCKED 0x44 /* device is locked */
# define RSP3_FAIL_NOT_UNDERSTOOD 0x91 # define RSP3_FAIL_NOT_UNDERSTOOD 0x91
/* ICE events */ /* ICE events */
@ -168,6 +169,15 @@
#define MTYPE_PRODSIG 0xc6 /* xmega production signature - undocumented in AVR067 */ #define MTYPE_PRODSIG 0xc6 /* xmega production signature - undocumented in AVR067 */
#define MTYPE_SIB 0xD3 /* AVR8X System Information Block */ #define MTYPE_SIB 0xD3 /* AVR8X System Information Block */
/*
* SET and GET context definitions
*/
#define SET_GET_CTXT_CONFIG 0x00 /* Configuration */
#define SET_GET_CTXT_PHYSICAL 0x01 /* Physical interface related */
#define SET_GET_CTXT_DEVICE 0x02 /* Device specific settings */
#define SET_GET_CTXT_OPTIONS 0x03 /* Option-related settings */
#define SET_GET_CTXT_SESSION 0x04 /* Session-related settings */
/* /*
* Parameters are divided into sections, where the section number * Parameters are divided into sections, where the section number
* precedes each parameter address. There are distinct parameter * precedes each parameter address. There are distinct parameter
@ -209,12 +219,19 @@
* before/after, bits before/after), 4 * before/after, bits before/after), 4
* bytes */ * bytes */
/*
* Physical context parameters
*/
#define PARM3_CLK_MEGA_PROG 0x20 /* section 1, AVR scope, 2 bytes (kHz) */ #define PARM3_CLK_MEGA_PROG 0x20 /* section 1, AVR scope, 2 bytes (kHz) */
#define PARM3_CLK_MEGA_DEBUG 0x21 /* section 1, AVR scope, 2 bytes (kHz) */ #define PARM3_CLK_MEGA_DEBUG 0x21 /* section 1, AVR scope, 2 bytes (kHz) */
#define PARM3_CLK_XMEGA_JTAG 0x30 /* section 1, AVR scope, 2 bytes (kHz) */ #define PARM3_CLK_XMEGA_JTAG 0x30 /* section 1, AVR scope, 2 bytes (kHz) */
#define PARM3_CLK_XMEGA_PDI 0x31 /* section 1, AVR scope, 2 bytes (kHz) */ #define PARM3_CLK_XMEGA_PDI 0x31 /* section 1, AVR scope, 2 bytes (kHz) */
/*
* Options context parameters
*/
#define PARM3_OPT_12V_UPDI_ENABLE 0x06
#define PARM3_OPT_CHIP_ERASE_TO_ENTER 0x07
/* Xmega erase memory types, for CMND_XMEGA_ERASE */ /* Xmega erase memory types, for CMND_XMEGA_ERASE */
#define XMEGA_ERASE_CHIP 0x00 #define XMEGA_ERASE_CHIP 0x00