Contributed by Thomas Fischl: add support for USBasp.
patch #4686: Add support for USBasp, a simple USB programmer * usbasp.c: New file, implement the USBasp driver. * usbasp.h: New file, interface declarations for USBasp. * Makefile.am: Wire the new files into the build. * avrdude.conf.in: Add the usbasp programmer entry. * config_gram.y: Add the usbasp token. * lexer.l: (Ditto.) * avrdude.1: Document the USBasp programmer. * doc/avrdude.texi: (Ditto.) git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@656 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
parent
501a1606b4
commit
637e389ef3
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
|||
2006-09-10 Joerg Wunsch <j@uriah.heep.sax.de>
|
||||
|
||||
Contributed by Thomas Fischl: add support for USBasp.
|
||||
patch #4686: Add support for USBasp, a simple USB programmer
|
||||
* usbasp.c: New file, implement the USBasp driver.
|
||||
* usbasp.h: New file, interface declarations for USBasp.
|
||||
* Makefile.am: Wire the new files into the build.
|
||||
* avrdude.conf.in: Add the usbasp programmer entry.
|
||||
* config_gram.y: Add the usbasp token.
|
||||
* lexer.l: (Ditto.)
|
||||
* avrdude.1: Document the USBasp programmer.
|
||||
* doc/avrdude.texi: (Ditto.)
|
||||
|
||||
2006-09-08 Joerg Wunsch <j@uriah.heep.sax.de>
|
||||
|
||||
* main.c: Implement -U filename as a shorthand for
|
||||
|
|
|
@ -123,6 +123,8 @@ avrdude_SOURCES = \
|
|||
stk500v2_private.h \
|
||||
term.c \
|
||||
term.h \
|
||||
usbasp.c \
|
||||
usbasp.h \
|
||||
usbdevs.h \
|
||||
usb_libusb.c
|
||||
|
||||
|
|
12
avrdude.1
12
avrdude.1
|
@ -19,7 +19,7 @@
|
|||
.\"
|
||||
.\" $Id$
|
||||
.\"
|
||||
.Dd DATE September 6, 2006
|
||||
.Dd DATE September 10, 2006
|
||||
.Os
|
||||
.Dt AVRDUDE 1
|
||||
.Sh NAME
|
||||
|
@ -113,6 +113,12 @@ Atmel's JTAG ICE (both mkI and mkII) is supported as well to up- or download mem
|
|||
areas from/to an AVR target (no support for on-chip debugging).
|
||||
For the JTAG ICE mkII, both JTAG and ISP mode are supported.
|
||||
.Pp
|
||||
The USBasp ISP adapter is also supported, provided
|
||||
.Nm avrdude
|
||||
has been compiled with libusb support.
|
||||
It features a simple firwmare-only USB implementation, running on
|
||||
an ATmega8 (or ATmega88).
|
||||
.Pp
|
||||
Input files can be provided, and output files can be written in
|
||||
different file formats, such as raw binary files containing the data
|
||||
to download to the chip, Intel hex format, or Motorola S-record
|
||||
|
@ -757,3 +763,7 @@ Page-mode programming the EEPROM through JTAG (i.e. through an
|
|||
option) requires a prior chip erase.
|
||||
This is an inherent feature of the way JTAG EEPROM programming works.
|
||||
This also applies to the STK500 in parallel programming mode.
|
||||
.Pp
|
||||
The USBasp driver does not offer any option to distinguish multiple
|
||||
devices connected simultaneously, so effectively only a single device
|
||||
is supported.
|
||||
|
|
|
@ -16,7 +16,8 @@
|
|||
# id = <id1> [, <id2> [, <id3>] ...] ; # <idN> are quoted strings
|
||||
# desc = <description> ; # quoted string
|
||||
# type = par | stk500 | stk500v2 | stk500pp | stk500hvsp |
|
||||
# avr910 | jtagmki | jtagmkii | jtagmkii_isp; # programmer type
|
||||
# avr910 | butterfly | usbasp |
|
||||
# jtagmki | jtagmkii | jtagmkii_isp; # programmer type
|
||||
# baudrate = <num> ; # baudrate for avr910-programmer
|
||||
# vcc = <num1> [, <num2> ... ] ; # pin number(s)
|
||||
# reset = <num> ; # pin number
|
||||
|
@ -353,6 +354,12 @@ programmer
|
|||
type = avr910;
|
||||
;
|
||||
|
||||
programmer
|
||||
id = "usbasp";
|
||||
desc = "USBasp, http://www.fischl.de/usbasp/";
|
||||
type = usbasp;
|
||||
;
|
||||
|
||||
programmer
|
||||
id = "butterfly";
|
||||
desc = "Atmel Butterfly Development Board";
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "stk500v2.h"
|
||||
#include "avr910.h"
|
||||
#include "butterfly.h"
|
||||
#include "usbasp.h"
|
||||
#include "avr.h"
|
||||
#include "jtagmkI.h"
|
||||
#include "jtagmkII.h"
|
||||
|
@ -126,6 +127,7 @@ static int parse_cmdbits(OPCODE * op);
|
|||
%token K_STK500PP
|
||||
%token K_STK500V2
|
||||
%token K_AVR910
|
||||
%token K_USBASP
|
||||
%token K_BUTTERFLY
|
||||
%token K_TYPE
|
||||
%token K_VCC
|
||||
|
@ -397,6 +399,12 @@ prog_parm :
|
|||
}
|
||||
} |
|
||||
|
||||
K_TYPE TKN_EQUAL K_USBASP {
|
||||
{
|
||||
usbasp_initpgm(current_prog);
|
||||
}
|
||||
} |
|
||||
|
||||
K_TYPE TKN_EQUAL K_BUTTERFLY {
|
||||
{
|
||||
butterfly_initpgm(current_prog);
|
||||
|
|
|
@ -184,6 +184,11 @@ Only the memory programming functionality of the JTAG ICE is supported
|
|||
by AVRDUDE.
|
||||
For the JTAG ICE mkII, both JTAG and ISP mode are supported.
|
||||
|
||||
The USBasp ISP adapter is also supported, provided AVRDUDE
|
||||
has been compiled with libusb support.
|
||||
It features a simple firwmare-only USB implementation, running on
|
||||
an ATmega8 (or ATmega88).
|
||||
|
||||
|
||||
@menu
|
||||
* History::
|
||||
|
@ -2010,6 +2015,13 @@ ISP pin
|
|||
@code{4}
|
||||
@end table
|
||||
|
||||
@item
|
||||
Problem: Multiple USBasp programmers connected simultaneously are not
|
||||
found.
|
||||
|
||||
Solution: none at this time. The simplicity of the USBasp programmer
|
||||
doesn't offer a method to distinguish multiple programmers that are
|
||||
connected simultaneously, so effectively only one USBasp is supported.
|
||||
|
||||
@end itemize
|
||||
|
||||
|
|
1
lexer.l
1
lexer.l
|
@ -122,6 +122,7 @@ SIGN [+-]
|
|||
allowfullpagebitstream { yylval=NULL; return K_ALLOWFULLPAGEBITSTREAM; }
|
||||
avr910 { yylval=NULL; return K_AVR910; }
|
||||
avr910_devcode { yylval=NULL; return K_AVR910_DEVCODE; }
|
||||
usbasp { yylval=NULL; return K_USBASP; }
|
||||
bank_size { yylval=NULL; return K_PAGE_SIZE; }
|
||||
banked { yylval=NULL; return K_PAGED; }
|
||||
baudrate { yylval=NULL; return K_BAUDRATE; }
|
||||
|
|
|
@ -0,0 +1,355 @@
|
|||
/*
|
||||
* avrdude - A Downloader/Uploader for AVR device programmers
|
||||
* Copyright (C) 2006 Thomas Fischl
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* Interface to the USBasp programmer.
|
||||
*
|
||||
* See http://www.fischl.de/usbasp/
|
||||
*/
|
||||
#include "ac_cfg.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "avr.h"
|
||||
#include "pgm.h"
|
||||
#include "usbasp.h"
|
||||
|
||||
#ifdef HAVE_LIBUSB
|
||||
#include <usb.h>
|
||||
|
||||
extern char * progname;
|
||||
extern int do_cycles;
|
||||
|
||||
static usb_dev_handle *usbhandle;
|
||||
|
||||
/*
|
||||
* wrapper for usb_control_msg call
|
||||
*/
|
||||
static int usbasp_transmit(unsigned char receive, unsigned char functionid,
|
||||
unsigned char send[4], unsigned char * buffer, int buffersize)
|
||||
{
|
||||
int nbytes;
|
||||
nbytes = usb_control_msg(usbhandle,
|
||||
USB_TYPE_VENDOR | USB_RECIP_DEVICE | (receive << 7),
|
||||
functionid,
|
||||
(send[1] << 8) | send[0],
|
||||
(send[3] << 8) | send[2],
|
||||
buffer, buffersize,
|
||||
5000);
|
||||
if(nbytes < 0){
|
||||
fprintf(stderr, "%s: error: usbasp_transmit: %s\n", progname, usb_strerror());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
static int usbasp_open(PROGRAMMER * pgm, char * port)
|
||||
{
|
||||
struct usb_bus *bus;
|
||||
struct usb_device *dev = 0;
|
||||
|
||||
usb_init();
|
||||
usb_find_busses();
|
||||
usb_find_devices();
|
||||
for(bus=usb_busses; bus; bus=bus->next){
|
||||
for(dev=bus->devices; dev; dev=dev->next){
|
||||
if(dev->descriptor.idVendor == USBDEV_VENDOR && dev->descriptor.idProduct == USBDEV_PRODUCT)
|
||||
break;
|
||||
}
|
||||
if(dev)
|
||||
break;
|
||||
}
|
||||
if(!dev){
|
||||
fprintf(stderr, "%s: error: could not find USB device vendor=0x%x product=0x%x\n",
|
||||
progname, USBDEV_VENDOR, USBDEV_PRODUCT);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
usbhandle = usb_open(dev);
|
||||
if(!usbhandle){
|
||||
fprintf(stderr, "%s: error: opening usb device: %s\n",
|
||||
progname, usb_strerror());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void usbasp_close(PROGRAMMER * pgm)
|
||||
{
|
||||
unsigned char temp[4];
|
||||
memset(temp, 0, sizeof(temp));
|
||||
usbasp_transmit(1, USBASP_FUNC_DISCONNECT, temp, temp, sizeof(temp));
|
||||
|
||||
usb_close(usbhandle);
|
||||
}
|
||||
|
||||
|
||||
static int usbasp_initialize(PROGRAMMER * pgm, AVRPART * p)
|
||||
{
|
||||
|
||||
unsigned char temp[4];
|
||||
memset(temp, 0, sizeof(temp));
|
||||
usbasp_transmit(1, USBASP_FUNC_CONNECT, temp, temp, sizeof(temp));
|
||||
|
||||
usleep(100000);
|
||||
|
||||
pgm->program_enable(pgm, p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void usbasp_disable(PROGRAMMER * pgm)
|
||||
{
|
||||
/* Do nothing. */
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void usbasp_enable(PROGRAMMER * pgm)
|
||||
{
|
||||
/* Do nothing. */
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void usbasp_display(PROGRAMMER * pgm, char * p)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static int usbasp_cmd(PROGRAMMER * pgm, unsigned char cmd[4],
|
||||
unsigned char res[4])
|
||||
{
|
||||
int nbytes =
|
||||
usbasp_transmit(1, USBASP_FUNC_TRANSMIT, cmd, res, sizeof(res));
|
||||
|
||||
if(nbytes != 4){
|
||||
fprintf(stderr, "%s: error: wrong responds size\n",
|
||||
progname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int usbasp_program_enable(PROGRAMMER * pgm, AVRPART * p)
|
||||
{
|
||||
unsigned char res[4];
|
||||
unsigned char cmd[4];
|
||||
memset(cmd, 0, sizeof(cmd));
|
||||
memset(res, 0, sizeof(res));
|
||||
|
||||
cmd[0] = 0;
|
||||
|
||||
int nbytes =
|
||||
usbasp_transmit(1, USBASP_FUNC_ENABLEPROG, cmd, res, sizeof(res));
|
||||
|
||||
if ((nbytes != 1) | (res[0] != 0)) {
|
||||
fprintf(stderr, "%s: error: programm enable: target doesn't answer. %x \n",
|
||||
progname, res[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int usbasp_chip_erase(PROGRAMMER * pgm, AVRPART * p)
|
||||
{
|
||||
unsigned char cmd[4];
|
||||
unsigned char res[4];
|
||||
|
||||
if (p->op[AVR_OP_CHIP_ERASE] == NULL) {
|
||||
fprintf(stderr, "chip erase instruction not defined for part \"%s\"\n",
|
||||
p->desc);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(cmd, 0, sizeof(cmd));
|
||||
|
||||
avr_set_bits(p->op[AVR_OP_CHIP_ERASE], cmd);
|
||||
pgm->cmd(pgm, cmd, res);
|
||||
usleep(p->chip_erase_delay);
|
||||
pgm->initialize(pgm, p);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int usbasp_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
|
||||
int page_size, int n_bytes)
|
||||
{
|
||||
int n;
|
||||
unsigned char cmd[4];
|
||||
int address = 0;
|
||||
int wbytes = n_bytes;
|
||||
int blocksize;
|
||||
unsigned char * buffer = m->buf;
|
||||
int function;
|
||||
|
||||
if (strcmp(m->desc, "flash") == 0) {
|
||||
function = USBASP_FUNC_READFLASH;
|
||||
} else if (strcmp(m->desc, "eeprom") == 0) {
|
||||
function = USBASP_FUNC_READEEPROM;
|
||||
} else {
|
||||
return -2;
|
||||
}
|
||||
|
||||
while (wbytes) {
|
||||
if (wbytes > USBASP_READBLOCKSIZE) {
|
||||
blocksize = USBASP_READBLOCKSIZE;
|
||||
wbytes -= USBASP_READBLOCKSIZE;
|
||||
} else {
|
||||
blocksize = wbytes;
|
||||
wbytes = 0;
|
||||
}
|
||||
|
||||
cmd[0] = address & 0xFF;
|
||||
cmd[1] = address >> 8;
|
||||
|
||||
n = usbasp_transmit(1, function, cmd, buffer, blocksize);
|
||||
|
||||
if (n != blocksize) {
|
||||
fprintf(stderr, "%s: error: wrong reading bytes %x\n",
|
||||
progname, n);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
buffer += blocksize;
|
||||
address += blocksize;
|
||||
|
||||
report_progress (address, n_bytes, NULL);
|
||||
}
|
||||
|
||||
return n_bytes;
|
||||
}
|
||||
|
||||
static int usbasp_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
|
||||
int page_size, int n_bytes)
|
||||
{
|
||||
int n;
|
||||
unsigned char cmd[4];
|
||||
int address = 0;
|
||||
int wbytes = n_bytes;
|
||||
int blocksize;
|
||||
unsigned char * buffer = m->buf;
|
||||
unsigned char blockflags = USBASP_BLOCKFLAG_FIRST;
|
||||
int function;
|
||||
|
||||
if (strcmp(m->desc, "flash") == 0) {
|
||||
function = USBASP_FUNC_WRITEFLASH;
|
||||
} else if (strcmp(m->desc, "eeprom") == 0) {
|
||||
function = USBASP_FUNC_WRITEEEPROM;
|
||||
} else {
|
||||
return -2;
|
||||
}
|
||||
|
||||
while (wbytes) {
|
||||
if (wbytes > USBASP_WRITEBLOCKSIZE) {
|
||||
blocksize = USBASP_WRITEBLOCKSIZE;
|
||||
wbytes -= USBASP_WRITEBLOCKSIZE;
|
||||
} else {
|
||||
blocksize = wbytes;
|
||||
wbytes = 0;
|
||||
blockflags |= USBASP_BLOCKFLAG_LAST;
|
||||
}
|
||||
|
||||
cmd[0] = address & 0xFF;
|
||||
cmd[1] = address >> 8;
|
||||
cmd[2] = page_size & 0xFF;
|
||||
cmd[3] = (blockflags & 0x0F) + ((page_size & 0xF00) >> 4); //TP: Mega128 fix
|
||||
blockflags = 0;
|
||||
|
||||
n = usbasp_transmit(0, function, cmd, buffer, blocksize);
|
||||
|
||||
if (n != blocksize) {
|
||||
fprintf(stderr, "%s: error: wrong count at writing %x\n",
|
||||
progname, n);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
buffer += blocksize;
|
||||
address += blocksize;
|
||||
|
||||
report_progress (address, n_bytes, NULL);
|
||||
}
|
||||
|
||||
return n_bytes;
|
||||
}
|
||||
|
||||
void usbasp_initpgm(PROGRAMMER * pgm)
|
||||
{
|
||||
strcpy(pgm->type, "usbasp");
|
||||
|
||||
/*
|
||||
* mandatory functions
|
||||
*/
|
||||
|
||||
pgm->initialize = usbasp_initialize;
|
||||
pgm->display = usbasp_display;
|
||||
pgm->enable = usbasp_enable;
|
||||
pgm->disable = usbasp_disable;
|
||||
pgm->program_enable = usbasp_program_enable;
|
||||
pgm->chip_erase = usbasp_chip_erase;
|
||||
pgm->cmd = usbasp_cmd;
|
||||
pgm->open = usbasp_open;
|
||||
pgm->close = usbasp_close;
|
||||
|
||||
/*
|
||||
* optional functions
|
||||
*/
|
||||
|
||||
pgm->paged_write = usbasp_paged_write;
|
||||
pgm->paged_load = usbasp_paged_load;
|
||||
|
||||
}
|
||||
|
||||
|
||||
#else /* HAVE_LIBUSB */
|
||||
|
||||
extern char * progname;
|
||||
|
||||
static int usbasp_nousb_open (struct programmer_t *pgm, char * name)
|
||||
{
|
||||
fprintf(stderr, "%s: error: no usb support. please compile again with libusb installed.\n",
|
||||
progname);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void usbasp_initpgm(PROGRAMMER * pgm)
|
||||
{
|
||||
strcpy(pgm->type, "usbasp");
|
||||
|
||||
pgm->open = usbasp_nousb_open;
|
||||
}
|
||||
|
||||
#endif /* HAVE_LIBUSB */
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* avrdude - A Downloader/Uploader for AVR device programmers
|
||||
* Copyright (C) 2006 Thomas Fischl
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef usbasp_h
|
||||
#define usbasp_h
|
||||
|
||||
#include "avrpart.h"
|
||||
|
||||
|
||||
#define USBDEV_VENDOR 0x03eb /* ATMEL */
|
||||
#define USBDEV_PRODUCT 0xc7B4 /* USBasp */
|
||||
|
||||
#define USBASP_FUNC_CONNECT 1
|
||||
#define USBASP_FUNC_DISCONNECT 2
|
||||
#define USBASP_FUNC_TRANSMIT 3
|
||||
#define USBASP_FUNC_READFLASH 4
|
||||
#define USBASP_FUNC_ENABLEPROG 5
|
||||
#define USBASP_FUNC_WRITEFLASH 6
|
||||
#define USBASP_FUNC_READEEPROM 7
|
||||
#define USBASP_FUNC_WRITEEEPROM 8
|
||||
|
||||
#define USBASP_BLOCKFLAG_FIRST 1
|
||||
#define USBASP_BLOCKFLAG_LAST 2
|
||||
|
||||
#define USBASP_READBLOCKSIZE 200
|
||||
#define USBASP_WRITEBLOCKSIZE 200
|
||||
|
||||
|
||||
void usbasp_initpgm (PROGRAMMER * pgm);
|
||||
|
||||
#endif /* usbasp_h */
|
Loading…
Reference in New Issue