diff --git a/src/jtag3.c b/src/jtag3.c index 0c04426a..1681a001 100644 --- a/src/jtag3.c +++ b/src/jtag3.c @@ -2305,6 +2305,31 @@ int jtag3_read_sib(PROGRAMMER * pgm, AVRPART * p, char * sib) return 0; } +static int jtag3_set_vtarget(PROGRAMMER * pgm, double v) +{ + unsigned uaref, utarg; + unsigned char buf[2]; + + utarg = (unsigned)(v * 1000); + + if (jtag3_getparm(pgm, SCOPE_GENERAL, 1, PARM3_VTARGET, buf, 2) < 0) { + avrdude_message(MSG_INFO, "%s: jtag3_set_vtarget(): cannot obtain V[aref]\n", + progname); + return -1; + } + + uaref = b2_to_u16(buf); + u16_to_b2(buf, utarg); + + avrdude_message(MSG_INFO, "%s: jtag3_set_vtarget(): changing V[target] from %.1f to %.1f\n", + progname, uaref / 1000.0, v); + + if (jtag3_setparm(pgm, SCOPE_GENERAL, 1, PARM3_VADJUST, buf, sizeof(buf)) < 0) + return -1; + + return 0; +} + static void jtag3_display(PROGRAMMER * pgm, const char * p) { unsigned char parms[5]; @@ -2564,5 +2589,12 @@ void jtag3_updi_initpgm(PROGRAMMER * pgm) pgm->flag = PGM_FL_IS_UPDI; pgm->unlock = jtag3_unlock_erase_key; pgm->read_sib = jtag3_read_sib; + + /* + * enable target voltage adjustment for PKOB/nEDBG boards + */ + if (matches(ldata(lfirst(pgm->id)), "pkobn_updi")) { + pgm->set_vtarget = jtag3_set_vtarget; + } } diff --git a/src/jtag3_private.h b/src/jtag3_private.h index 5ce634f9..a3e7fb08 100644 --- a/src/jtag3_private.h +++ b/src/jtag3_private.h @@ -189,8 +189,11 @@ #define PARM3_FW_RELEASE 0x03 /* section 0, generic scope, 1 byte; * always asked for by Atmel Studio, * but never displayed there */ -#define PARM3_VTARGET 0x00 /* section 1, generic scope, 2 bytes, - * in millivolts */ +#define PARM3_VTARGET 0x00 /* section 1, generic scope, 2 bytes, in millivolts */ +#define PARM3_VBUF 0x01 /* section 1, generic scope, 2 bytes, bufferred target voltage reference */ +#define PARM3_VUSB 0x02 /* section 1, generic scope, 2 bytes, USB voltage */ +#define PARM3_VADJUST 0x20 /* section 1, generic scope, 2 bytes, set voltage */ + #define PARM3_DEVICEDESC 0x00 /* section 2, memory etc. configuration, * 31 bytes for tiny/mega AVR, 47 bytes * for Xmega; is also used in command