Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/arduino.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static int arduino_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) {

if(str_eq(extended_param, "help")) {
help = true;
rv = LIBAVRDUDE_EXIT;
rv = LIBAVRDUDE_EXIT_OK;
}

if(!help) {
Expand Down
6 changes: 3 additions & 3 deletions src/avr.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ int avr_read_mem(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem, con
if(pgm->read_sig_bytes) {
int rc = pgm->read_sig_bytes(pgm, p, mem);

if(rc < 0 && rc != LIBAVRDUDE_EXIT)
if(rc < 0 && rc != LIBAVRDUDE_EXIT_OK)
led_set(pgm, LED_ERR);
led_clr(pgm, LED_PGM);
return rc;
Expand Down Expand Up @@ -1216,13 +1216,13 @@ int avr_signature(const PROGRAMMER *pgm, const AVRPART *p) {
if(verbose > 1)
report_progress(0, 1, "Reading");
rc = avr_read(pgm, p, "signature", 0);
if(rc < LIBAVRDUDE_SUCCESS && rc != LIBAVRDUDE_EXIT) {
if(rc < LIBAVRDUDE_SUCCESS && rc != LIBAVRDUDE_EXIT_OK) {
pmsg_error("unable to read signature data for part %s (rc = %d)\n", p->desc, rc);
return rc;
}
report_progress(1, 1, NULL);

return rc < LIBAVRDUDE_SUCCESS? LIBAVRDUDE_EXIT: LIBAVRDUDE_SUCCESS;
return rc < LIBAVRDUDE_SUCCESS? LIBAVRDUDE_EXIT_OK: LIBAVRDUDE_SUCCESS;
}

// Obtain bitmask for byte in memory (classic, TPI, PDI and UPDI parts)
Expand Down
2 changes: 1 addition & 1 deletion src/avr910.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ static int avr910_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) {
}
if(str_eq(extended_param, "help")) {
help = true;
rv = LIBAVRDUDE_EXIT;
rv = LIBAVRDUDE_EXIT_OK;
}

if(!help) {
Expand Down
13 changes: 8 additions & 5 deletions src/avrdude.1
Original file line number Diff line number Diff line change
Expand Up @@ -1665,15 +1665,18 @@ Show help menu and exit.
.It Ar PICkit 4
.It Ar MPLAB SNAP
.Bl -tag -offset indent -width indent
.It Ar mode=avr,pic
Switch programmer to AVR or PIC mode, then exit: the PICkit 4 and MPLAB SNAP
programmer can only be utilised by
.It Ar mode=avr
Switch programmer to AVR mode, then exit if not already in AVR mode
.It Ar mode=<mplab|pic>
Switch programmer to MPLAB aka PIC mode, then exit
.Pp
The PICkit 4 and MPLAB SNAP programmer can only be utilised by
.Nm
when in AVR mode. Use
.Ar -x mode=avr
for switching to AVR mode, or
.Ar -x mode=pic
for switching to PIC mode.
.Ar -x mode=mplab
for switching (back) to MPLAB mode.
.It Ar help
Show help menu and exit.
.El
Expand Down
2 changes: 1 addition & 1 deletion src/avrftdi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ static int avrftdi_jtag_initialize(const PROGRAMMER *pgm, const AVRPART *p) {

pmsg_error("programmer type %s is known not to work for %s\n", pgm->type, p->desc);
pmsg_error("exiting, use -F to carry on regardless\n");
return LIBAVRDUDE_EXIT;
return LIBAVRDUDE_EXIT_FAIL;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/buspirate.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ static int buspirate_parseextparms(const PROGRAMMER *pgm, const LISTID extparms)

if(str_eq(extended_param, "help")) {
help = true;
rv = LIBAVRDUDE_EXIT;
rv = LIBAVRDUDE_EXIT_OK;
}

if(!help) {
Expand Down
2 changes: 1 addition & 1 deletion src/butterfly.c
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ static int butterfly_parseextparms(const PROGRAMMER *pgm, const LISTID extparms)

if(str_eq(extended_param, "help")) {
help = true;
rv = LIBAVRDUDE_EXIT;
rv = LIBAVRDUDE_EXIT_OK;
}

if(!help) {
Expand Down
13 changes: 8 additions & 5 deletions src/doc/avrdude.texi
Original file line number Diff line number Diff line change
Expand Up @@ -1422,13 +1422,16 @@ The current set-voltage can be read by @code{-x vtarg} alone.

The PICkit 4 and MPLAB(R) SNAP programmers accept the following extended parameters:
@table @code
@item mode=avr,mplab/pic
Switch programmer to AVR or MPLAB mode, then exit: the PICkit 4 and MPLAB(R) SNAP
programmer can only be utilised by Avrdude when in AVR mode.
Use @code{-x mode=avr} for switching to AVR mode, or @code{-x mode=mplab}
for switching to MPLAB mode.
@item mode=avr
Switch programmer to AVR mode, then exit unless it was already in AVR mode
@item mode=<mplab|pic>
Switch programmer to MPLAB aka PIC mode, then exit
@end table

The PICkit 4 and MPLAB(R) SNAP programmer can only be utilised by AVRDUDE
when in AVR mode. Use @code{-x mode=avr} for switching to AVR mode, or
@code{-x mode=mplab} for switching (back) to MPLAB mode.

@cindex Option @code{-x} PICkit 5
@cindex @code{-x} PICkit 5
@cindex MPLAB(R) PICkit 4
Expand Down
2 changes: 1 addition & 1 deletion src/dryrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ static int dryrun_parseextparams(const PROGRAMMER *pgm, const LISTID extparms) {
}
if(str_eq(xpara, "help")) {
help = true;
rc = LIBAVRDUDE_EXIT;
rc = LIBAVRDUDE_EXIT_OK;
}

if(!help) {
Expand Down
2 changes: 1 addition & 1 deletion src/flip2.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ static int flip2_parseexitspecs(PROGRAMMER *pgm, const char *sp) {
}
if(str_eq(cp, "help")) {
help = true;
rv = LIBAVRDUDE_EXIT;
rv = LIBAVRDUDE_EXIT_OK;
}

if(!help) {
Expand Down
83 changes: 50 additions & 33 deletions src/jtag3.c
Original file line number Diff line number Diff line change
Expand Up @@ -1585,8 +1585,7 @@ static int jtag3_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) {
continue;
}
// Flag a switch to PIC mode
if(str_caseeq(extended_param, "mode=pic") ||
str_caseeq(extended_param, "mode=mplab")) {
if(str_caseeq(extended_param, "mode=mplab") || str_caseeq(extended_param, "mode=pic")) {
my.pk4_snap_mode = PK4_SNAP_MODE_PIC;
continue;
}
Expand All @@ -1597,7 +1596,7 @@ static int jtag3_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) {

if(str_eq(extended_param, "help")) {
help = true;
rv = LIBAVRDUDE_EXIT;
rv = LIBAVRDUDE_EXIT_OK;
}

if(!help) {
Expand All @@ -1607,25 +1606,27 @@ static int jtag3_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) {
msg_error("%s -c %s extended options:\n", progname, pgmid);
if(str_eq(pgm->type, "JTAGICE3")) {
msg_error(" -x jtagchain=UB,UA,BB,BA Setup the JTAG scan chain order\n");
msg_error(" UB/UA = units before/after, BB/BA = bits before/after\n");
msg_error(" UB/UA = units before/after, BB/BA = bits before/after\n");
}
if(lsize(pgm->hvupdi_support) > 1)
msg_error(" -x hvupdi Enable high-voltage UPDI initialization\n");
msg_error(" -x hvupdi Enable high-voltage UPDI initialization\n");
if(pgm->extra_features & HAS_SUFFER) {
msg_error(" -x suffer Read SUFFER register value\n");
msg_error(" -x suffer=<n> Set SUFFER register to <n> (0x.. hex, 0.. oct or dec)\n");
msg_error(" -x suffer Read SUFFER register value\n");
msg_error(" -x suffer=<n> Set SUFFER register to <n> (0x.. hex, 0.. oct or dec)\n");
}
if(pgm->extra_features & HAS_VTARG_SWITCH) {
msg_error(" -x vtarg_switch Read on-board target voltage switch state\n");
msg_error(" -x vtarg_switch=<0..1> Set on-board target voltage switch state\n");
msg_error(" -x vtarg_switch Read on-board target voltage switch state\n");
msg_error(" -x vtarg_switch=<0|1> Set on-board target voltage switch state\n");
}
if(pgm->extra_features & HAS_VTARG_ADJ) {
msg_error(" -x vtarg Read on-board target supply voltage\n");
msg_error(" -x vtarg=<dbl> Set on-board target supply voltage to <dbl> V\n");
msg_error(" -x vtarg Read on-board target supply voltage\n");
msg_error(" -x vtarg=<dbl> Set on-board target supply voltage to <dbl> V\n");
}
if(str_starts(pgmid, "pickit4") || str_starts(pgmid, "snap"))
msg_error(" -x mode=avr|[pic|mplab] Set programmer to AVR or MPLAB (PIC) mode, then exit\n");
msg_error(" -x help Show this help menu and exit\n");
if(str_starts(pgmid, "pickit4") || str_starts(pgmid, "snap")) {
msg_error(" -x mode=avr Set programmer to AVR mode and exit if it was not\n");
msg_error(" -x mode=<mplab|pic> Set programmer to MPLAB aka PIC mode and exit\n");
}
msg_error(" -x help Show this help menu and exit\n");
return rv;
}

Expand Down Expand Up @@ -1714,31 +1715,48 @@ int jtag3_open_common(PROGRAMMER *pgm, const char *port, int mode_switch) {
pic_mode = serial_open(port, pinfo, &pgm->fd);
}
if(pic_mode >= 0) {
msg_error("\n");
const char *partsdesc_flag = partdesc? " -p ": "";
const char *partsdesc_str = partdesc? partdesc: "";
const char *pgm_suffix = strchr(pgmid, '_')? strchr(pgmid, '_'): "";

cx->usb_access_error = 0;
pmsg_error("%s in %s mode detected\n", pgmstr, pinfo.usbinfo.pid == bl_pid? "bootloader": "mplab");
if(mode_switch == PK4_SNAP_MODE_AVR) {
imsg_error("switching to AVR mode; ");

switch(mode_switch) {
case PK4_SNAP_MODE_AVR:
msg_info("\n");
pmsg_info("%s in %s mode detected\n", pgmstr,
pinfo.usbinfo.pid == bl_pid? "bootloader": "mplab");
pmsg_info("switching to AVR mode; ");
if(pinfo.usbinfo.pid == bl_pid)
serial_send(&pgm->fd, exit_bl_cmd, sizeof(exit_bl_cmd));
else {
serial_send(&pgm->fd, enter_avr_mode_cmd, sizeof(enter_avr_mode_cmd));
usleep(250*1000);
serial_send(&pgm->fd, reset_cmd, sizeof(reset_cmd));
}
imsg_error("run %s again to continue the session\n\n", progname);
} else {

const char *partsdesc_flag = partdesc? " -p ": "";
const char *partsdesc_str = partdesc? partdesc: "";
const char *pgm_suffix = strchr(pgmid, '_')? strchr(pgmid, '_'): "";
imsg_info("run %s again to continue the session\n", progname);
serial_close(&pgm->fd);
return LIBAVRDUDE_EXIT_OK;

case PK4_SNAP_MODE_PIC:
pmsg_info("%s in %s mode detected; exiting\n", pgmstr,
pinfo.usbinfo.pid == bl_pid? "bootloader": "mplab");
serial_close(&pgm->fd);
return LIBAVRDUDE_EXIT_OK;

default:
msg_error("\n");
pmsg_error("%s in %s mode detected\n", pgmstr,
pinfo.usbinfo.pid == bl_pid? "bootloader": "mplab");
imsg_error("to switch into AVR mode try\n");
imsg_error("$ %s -c %s%s%s -P %s -x mode=avr\n\n", progname, pgmid, partsdesc_flag, partsdesc_str, port);
imsg_error("or use MPLAB mode by using the pickit4_mplab%s programmer option:\n", pgm_suffix);
imsg_error("$ %s -c pickit4_mplab%s%s%s -P %s\n", progname, pgm_suffix, partsdesc_flag, partsdesc_str, port);
imsg_error("$ %s -c %s%s%s -P %s -x mode=avr\n\n", progname,
pgmid, partsdesc_flag, partsdesc_str, port);
imsg_error("or use MPLAB mode with the pickit4_mplab%s programmer:\n", pgm_suffix);
imsg_error("$ %s -c pickit4_mplab%s%s%s -P %s\n", progname,
pgm_suffix, partsdesc_flag, partsdesc_str, port);
serial_close(&pgm->fd);
return LIBAVRDUDE_EXIT_FAIL;
}
serial_close(&pgm->fd);
return LIBAVRDUDE_EXIT;;
}
}
}
Expand Down Expand Up @@ -1779,15 +1797,14 @@ int jtag3_open_common(PROGRAMMER *pgm, const char *port, int mode_switch) {

// Switch from AVR to PIC mode
if(mode_switch == PK4_SNAP_MODE_PIC) {
imsg_error("switching to MPLAB mode: ");
unsigned char *resp, buf[] = { SCOPE_GENERAL, CMD3_FW_UPGRADE, 0x00, 0x00, 0x70, 0x6d, 0x6a };
if(jtag3_command(pgm, buf, sizeof(buf), &resp, "enter MPLAB mode") < 0) {
msg_error("entering MPLAB mode failed\n");
pmsg_error("switching to MPLAB mode failed\n");
return -1;
}
msg_error("MPLAB mode switch successful\n");
msg_info("switched successfully to MPLAB mode\n");
serial_close(&pgm->fd);
return LIBAVRDUDE_EXIT;;
return LIBAVRDUDE_EXIT_OK;
}

return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/jtagmkII.c
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ static int jtagmkII_parseextparms(const PROGRAMMER *pgm, const LISTID extparms)

if(str_eq(extended_param, "help")) {
help = true;
rv = LIBAVRDUDE_EXIT;
rv = LIBAVRDUDE_EXIT_OK;
}

if(!help) {
Expand Down Expand Up @@ -2674,7 +2674,7 @@ static int jtagmkII_reset32(const PROGRAMMER *pgm, unsigned short flags) {

status = jtagmkII_recv(pgm, &resp);
if(status != 2 || resp[0] != 0x87 || resp[1] != 01)
gotoerr;;
gotoerr;
}

if(flags & (AVR32_RESET_WRITE | AVR32_SET4RUNNING)) {
Expand Down
10 changes: 7 additions & 3 deletions src/libavrdude.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,13 @@ typedef uint32_t Pinmask;
#define LIBAVRDUDE_GENERAL_FAILURE (-1)
#define LIBAVRDUDE_NOTSUPPORTED (-2) // Operation not supported
#define LIBAVRDUDE_SOFTFAIL (-3) // Returned, eg, if caller might proceed with a plan B
#define LIBAVRDUDE_EXIT (-4) // End all operations in this session
#define LIBAVRDUDE_DEVICE_LOCKED (-5) // Returned if the programmer determined that the device is locked
#define LIBAVRDUDE_BEYOND_ERRS (-6) // This error and lower not normally used by libavrdude functions
#define LIBAVRDUDE_EXIT_OK (-4) // End all operations in this session and exit(0) in main
#define LIBAVRDUDE_EXIT_FAIL (-5) // End all operations in this session and exit(1) in main
#ifndef TO_BE_DEPRECATED_IN_2027
#define LIBAVRDUDE_EXIT (-4) // Deprecated: this is now LIBAVRDUDE_EXIT_OK
#endif
#define LIBAVRDUDE_DEVICE_LOCKED (-6) // Returned if the programmer determined that the device is locked
#define LIBAVRDUDE_BEYOND_ERRS (-7) // This error and lower not normally used by libavrdude functions

// Message system

Expand Down
2 changes: 1 addition & 1 deletion src/linuxgpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ static int linuxgpio_parseexitspecs(PROGRAMMER *pgm, const char *sp) {
}
if(str_eq(cp, "help")) {
help = true;
rv = LIBAVRDUDE_EXIT;
rv = LIBAVRDUDE_EXIT_OK;
}

if(!help) {
Expand Down
4 changes: 2 additions & 2 deletions src/linuxspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ static int linuxspi_parseexitspecs(PROGRAMMER *pgm, const char *sp) {
}
if(str_eq(cp, "help")) {
help = true;
rv = LIBAVRDUDE_EXIT;
rv = LIBAVRDUDE_EXIT_OK;
}

if(!help) {
Expand Down Expand Up @@ -438,7 +438,7 @@ static int linuxspi_parseextparams(const PROGRAMMER *pgm, const LISTID extparms)

if(str_eq(extended_param, "help")) {
help = true;
rc = LIBAVRDUDE_EXIT;
rc = LIBAVRDUDE_EXIT_OK;
}

if(!help) {
Expand Down
16 changes: 8 additions & 8 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ int main(int argc, char *argv[]) {
} else {
int rc = pgm->parseextparams(pgm, extended_params);

if(rc == LIBAVRDUDE_EXIT)
if(rc == LIBAVRDUDE_EXIT_OK)
exit(0);
if(rc < 0) {
pmsg_error("unable to parse list of -x parameters\n");
Expand Down Expand Up @@ -1495,8 +1495,8 @@ int main(int argc, char *argv[]) {

rc = pgm->open(pgm, port);
if(rc < 0) {
if(rc == LIBAVRDUDE_EXIT) {
exitrc = 0;
if(rc == LIBAVRDUDE_EXIT_FAIL || rc == LIBAVRDUDE_EXIT_OK) {
exitrc = rc == LIBAVRDUDE_EXIT_FAIL;
goto main_exit;
}

Expand Down Expand Up @@ -1536,7 +1536,7 @@ int main(int argc, char *argv[]) {
} else {
int rc = pgm->parseexitspecs(pgm, exitspecs);

if(rc == LIBAVRDUDE_EXIT)
if(rc == LIBAVRDUDE_EXIT_OK)
exit(0);
if(rc < 0) {
pmsg_error("unable to parse list of -E parameters\n");
Expand Down Expand Up @@ -1628,8 +1628,8 @@ int main(int argc, char *argv[]) {
init_again:
init_ok = (rc = pgm->initialize(pgm, p)) >= 0;
if(!init_ok) {
if(rc == LIBAVRDUDE_EXIT) {
exitrc = 0;
if(rc == LIBAVRDUDE_EXIT_FAIL || rc == LIBAVRDUDE_EXIT_OK) {
exitrc = rc == LIBAVRDUDE_EXIT_FAIL;
goto main_exit;
}
if(rc == LIBAVRDUDE_DEVICE_LOCKED) { // The pickit5 with UPDI is a bit tricky
Expand Down Expand Up @@ -1699,8 +1699,8 @@ int main(int argc, char *argv[]) {
usleep(waittime);
if(init_ok) {
rc = avr_signature(pgm, p);
if(rc == LIBAVRDUDE_EXIT) {
exitrc = 0;
if(rc == LIBAVRDUDE_EXIT_FAIL || rc == LIBAVRDUDE_EXIT_OK) {
exitrc = rc == LIBAVRDUDE_EXIT_FAIL;
goto main_exit;
}
if(rc != LIBAVRDUDE_SUCCESS) {
Expand Down
2 changes: 1 addition & 1 deletion src/micronucleus.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ static int micronucleus_parseextparams(const PROGRAMMER *pgm, const LISTID xpara

if(str_eq(extended_param, "help")) {
help = true;
rv = LIBAVRDUDE_EXIT;
rv = LIBAVRDUDE_EXIT_OK;
}

if(!help) {
Expand Down
Loading
Loading