From 112b6edd1c812e131763c7e61d7fafc7faed6992 Mon Sep 17 00:00:00 2001 From: David Fries Date: Thu, 1 Jan 2015 19:08:14 -0600 Subject: [PATCH 1/3] Set back to programming mode on quit Otherwise it can't read the fuses and the safe fuse code complains. --- src/term.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/term.c b/src/term.c index 96bf2bce..5c91931c 100644 --- a/src/term.c +++ b/src/term.c @@ -541,6 +541,10 @@ static int cmd_sig(PROGRAMMER * pgm, struct avrpart * p, static int cmd_quit(PROGRAMMER * pgm, struct avrpart * p, int argc, char * argv[]) { + /* FUSE bit verify will fail if left in SPI mode */ + if (spi_mode) { + cmd_pgm(pgm, p, 0, NULL); + } return 1; } From cffa6c7ca001d36861830fdcddb8ac02e843c7f0 Mon Sep 17 00:00:00 2001 From: David Fries Date: Thu, 1 Jan 2015 19:16:47 -0600 Subject: [PATCH 2/3] Add direct SPI mode to USBtiny It is limited to exactly sending (and receiving) multiples of 4 bytes, and unlike programming mode where slave select isn't required, SS must be held low for SPI to work. USBtiny programmers don't usually have a wire for SS. --- src/usbtiny.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/usbtiny.c b/src/usbtiny.c index 4c6fefcf..4bbaca7c 100644 --- a/src/usbtiny.c +++ b/src/usbtiny.c @@ -511,6 +511,20 @@ static int usbtiny_initialize (PROGRAMMER *pgm, AVRPART *p ) return 0; } +static int usbtiny_setpin(struct programmer_t * pgm, int pinfunc, int value) +{ + /* USBtiny is not a bit bang device, but it can set RESET */ + if(pinfunc == PIN_AVR_RESET) { + if (usb_control(pgm, USBTINY_POWERUP, + PDATA(pgm)->sck_period, value ? RESET_HIGH : RESET_LOW) < 0) { + return -1; + } + usleep(50000); + return 0; + } + return -1; +} + /* Tell the USBtiny to release the output pins, etc */ static void usbtiny_powerdown(PROGRAMMER * pgm) { @@ -580,6 +594,27 @@ int usbtiny_cmd_tpi(PROGRAMMER * pgm, const unsigned char *cmd, return 0; } +static int usbtiny_spi(struct programmer_t * pgm, const unsigned char *cmd, unsigned char *res, int count) +{ + int i; + + // Clear the receive buffer so we don't read old data in case of failure + memset(res, 0, count); + + if (count % 4) { + avrdude_message(MSG_INFO, "Direct SPI write must be a multiple of 4 bytes for %s\n", + pgm->type); + return -1; + } + + for (i = 0; i < count; i += 4) { + if (usbtiny_cmd(pgm, cmd + i, res + i) < 0) { + return -1; + } + } + return 0; +} + /* Send the chip-erase command */ static int usbtiny_chip_erase(PROGRAMMER * pgm, AVRPART * p) { @@ -759,6 +794,8 @@ void usbtiny_initpgm ( PROGRAMMER* pgm ) pgm->set_sck_period = usbtiny_set_sck_period; pgm->setup = usbtiny_setup; pgm->teardown = usbtiny_teardown; + pgm->setpin = usbtiny_setpin; + pgm->spi = usbtiny_spi; } #else /* !HAVE_LIBUSB */ From 40f0fae5a4a96b57331509ca9ad8801e2420ba61 Mon Sep 17 00:00:00 2001 From: David Fries Date: Thu, 1 Jan 2015 19:58:23 -0600 Subject: [PATCH 3/3] Update manpage for USBtiny and direct SPI --- src/avrdude.1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/avrdude.1 b/src/avrdude.1 index 0cadf9ab..1e6b2cc5 100644 --- a/src/avrdude.1 +++ b/src/avrdude.1 @@ -838,7 +838,7 @@ Display the device signature bytes. Enter direct SPI mode. The .Em pgmled pin acts as slave select. -.Em Only supported on parallel bitbang programmers. +.Em Only supported on parallel bitbang programmers, and partially by USBtiny. .It Ar part Display the current part settings and parameters. Includes chip specific information including all memory types supported by the @@ -1271,7 +1271,8 @@ This also applies to the STK500 and STK600 in parallel programming mode. .Pp The USBasp and USBtinyISP drivers do not offer any option to distinguish multiple devices connected simultaneously, so effectively only a single device -is supported. +is supported. Slave Select must be externally held low for direct SPI when +using USBtinyISP, and send must be a multiple of four bytes. .Pp The avrftdi driver allows one to select specific devices using any combination of vid,pid serial number (usbsn) vendor description (usbvendoror part description (usbproduct)