From fac7ca27226894fd0f221d92be9ec003d4ce9fb5 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Wed, 25 Feb 2009 09:39:04 +0000 Subject: [PATCH] Submitted by Lars Immisch: patch #6750: Arduino support - new programmer-id * arduino.c: New file, inherits stk500.c. * arduino.h: New file. * Makefile.am: Add arduino.c and arduino.h. * config_gram.y: Add arduino keyword. * lexer.l: (Ditto.) * avrdude.conf.in: (Ditto.) * avrdude.1: Document the new programmer type. * doc/avrdude.texi: (Ditto.) git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@808 81a1dc3b-b13d-400b-aceb-764788c761c2 --- ChangeLog | 13 +++++++ Makefile.am | 2 ++ NEWS | 1 + arduino.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++ arduino.h | 29 +++++++++++++++ avrdude.1 | 4 +++ avrdude.conf.in | 8 ++++- config_gram.y | 8 +++++ doc/avrdude.texi | 6 ++++ lexer.l | 1 + 10 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 arduino.c create mode 100644 arduino.h diff --git a/ChangeLog b/ChangeLog index d6fcb76b..38e1d6d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2009-02-25 Joerg Wunsch + + Submitted by Lars Immisch: + patch #6750: Arduino support - new programmer-id + * arduino.c: New file, inherits stk500.c. + * arduino.h: New file. + * Makefile.am: Add arduino.c and arduino.h. + * config_gram.y: Add arduino keyword. + * lexer.l: (Ditto.) + * avrdude.conf.in: (Ditto.) + * avrdude.1: Document the new programmer type. + * doc/avrdude.texi: (Ditto.) + 2009-02-25 Joerg Wunsch * stk500v2.c: Turn all non-const static data into instance data. diff --git a/Makefile.am b/Makefile.am index 19b1d718..a7d07111 100644 --- a/Makefile.am +++ b/Makefile.am @@ -77,6 +77,8 @@ dist-hook: libavrdude_a_SOURCES = \ config_gram.y \ lexer.l \ + arduino.h \ + arduino.c \ avr.c \ avr.h \ avr910.c \ diff --git a/NEWS b/NEWS index fddf08bb..e7a53f26 100644 --- a/NEWS +++ b/NEWS @@ -21,6 +21,7 @@ Current: * New programmers supported: - AT89ISP cable (patch #6069) + - Arduino * Add support for the -x option to pass extended parameters to the programmer backend. diff --git a/arduino.c b/arduino.c new file mode 100644 index 00000000..2f37c108 --- /dev/null +++ b/arduino.c @@ -0,0 +1,94 @@ +/* + * avrdude - A Downloader/Uploader for AVR device programmers + * Copyright (C) 2009 Lars Immisch + * + * 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$ */ + +/* + * avrdude interface for Arduino programmer + * + * The Arduino programmer is mostly a STK500v1, just the signature bytes + * are read differently. + */ + +#include "ac_cfg.h" + +#include +#include + +#include "avrdude.h" +#include "pgm.h" +#include "stk500_private.h" +#include "stk500.h" +#include "serial.h" + +/* read signature bytes - arduino version */ +static int arduino_read_sig_bytes(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m) +{ + unsigned char buf[32]; + + /* Signature byte reads are always 3 bytes. */ + + if (m->size < 3) { + fprintf(stderr, "%s: memsize too small for sig byte read", progname); + return -1; + } + + buf[0] = Cmnd_STK_READ_SIGN; + buf[1] = Sync_CRC_EOP; + + serial_send(&pgm->fd, buf, 2); + + if (serial_recv(&pgm->fd, buf, 5) < 0) + return -1; + if (buf[0] == Resp_STK_NOSYNC) { + fprintf(stderr, "%s: stk500_cmd(): programmer is out of sync\n", + progname); + return -1; + } else if (buf[0] != Resp_STK_INSYNC) { + fprintf(stderr, + "\n%s: arduino_read_sig_bytes(): (a) protocol error, " + "expect=0x%02x, resp=0x%02x\n", + progname, Resp_STK_INSYNC, buf[0]); + return -2; + } + if (buf[4] != Resp_STK_OK) { + fprintf(stderr, + "\n%s: arduino_read_sig_bytes(): (a) protocol error, " + "expect=0x%02x, resp=0x%02x\n", + progname, Resp_STK_OK, buf[4]); + return -3; + } + + m->buf[0] = buf[1]; + m->buf[1] = buf[2]; + m->buf[2] = buf[3]; + + return 3; +} + +void arduino_initpgm(PROGRAMMER * pgm) +{ + /* This is mostly a STK500; just the signature is read + differently than on real STK500v1 */ + stk500_initpgm(pgm); + + strcpy(pgm->type, "Arduino"); + pgm->read_sig_bytes = arduino_read_sig_bytes; + +} diff --git a/arduino.h b/arduino.h new file mode 100644 index 00000000..a5819ee1 --- /dev/null +++ b/arduino.h @@ -0,0 +1,29 @@ +/* + * avrdude - A Downloader/Uploader for AVR device programmers + * Copyright (C) 2009 Lars Immisch + * + * 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 arduino_h__ +#define arduino_h__ + +void arduino_initpgm (PROGRAMMER * pgm); + +#endif + + diff --git a/avrdude.1 b/avrdude.1 index a44814cc..843114c4 100644 --- a/avrdude.1 +++ b/avrdude.1 @@ -107,6 +107,9 @@ Using firmware version 2, high-voltage programming is also supported, both parallel and serial (programmer types stk500pp and stk500hvsp). .Pp +The Arduino (which is very similar to the STK500 1.x) is supported via +its own programmer type specification ``arduino''. +.Pp Atmel's STK600 programmer is supported in ISP and high-voltage programming modes, and connects through the USB. For ATxmega devices, the STK600 is supported in PDI mode. @@ -203,6 +206,7 @@ m103 ATmega103 m128 ATmega128 m1280 ATmega1280 m1281 ATmega1281 +m1284p ATmega1284P m128rfa1 ATmega128RFA1 m16 ATmega16 m161 ATmega161 diff --git a/avrdude.conf.in b/avrdude.conf.in index af4d3177..64a465d2 100644 --- a/avrdude.conf.in +++ b/avrdude.conf.in @@ -20,7 +20,7 @@ # avr910 | butterfly | usbasp | # jtagmki | jtagmkii | jtagmkii_isp | jtagmkii_dw | # dragon_dw | dragon_jtag | dragon_isp | dragon_pp | -# dragon_hvsp; # programmer type +# dragon_hvsp | arduino; # programmer type # baudrate = ; # baudrate for avr910-programmer # vcc = [, ... ] ; # pin number(s) # reset = ; # pin number @@ -310,6 +310,12 @@ default_serial = "@DEFAULT_SER_PORT@"; # PROGRAMMER DEFINITIONS # +programmer + id = "arduino"; + desc = "Arduino"; + type = arduino; +; + programmer id = "avrisp"; desc = "Atmel AVR ISP"; diff --git a/config_gram.y b/config_gram.y index 7bbe0242..2351009f 100644 --- a/config_gram.y +++ b/config_gram.y @@ -37,6 +37,7 @@ #include "ppi.h" #include "pgm.h" #include "stk500.h" +#include "arduino.h" #include "stk500v2.h" #include "stk500generic.h" #include "avr910.h" @@ -79,6 +80,7 @@ static int parse_cmdbits(OPCODE * op); %token K_PAGE_SIZE %token K_PAGED +%token K_ARDUINO %token K_BAUDRATE %token K_BS2 %token K_BUFF @@ -417,6 +419,12 @@ prog_parm : } } | + K_TYPE TKN_EQUAL K_ARDUINO { + { + arduino_initpgm(current_prog); + } + } | + K_TYPE TKN_EQUAL K_STK600 { { stk600_initpgm(current_prog); diff --git a/doc/avrdude.texi b/doc/avrdude.texi index dd232634..71647631 100644 --- a/doc/avrdude.texi +++ b/doc/avrdude.texi @@ -190,6 +190,9 @@ by AVRDUDE. For the JTAG ICE mkII, JTAG, debugWire and ISP mode are supported. See below for the limitations of debugWire. +The Arduino (which is very similar to the STK500 1.x) is supported via +its own programmer type specification ``arduino''. + The AVR Dragon is supported in all modes (ISP, JTAG, HVSP, PP, debugWire). When used in JTAG and debugWire mode, the AVR Dragon behaves similar to a JTAG ICE mkII, so all device-specific comments for that device @@ -297,6 +300,7 @@ Currently, the following MCU types are understood: @item @code{m128} @tab ATmega128 @item @code{m1280} @tab ATmega1280 @item @code{m1281} @tab ATmega1281 +@item @code{m1284p} @tab ATmega1284P @item @code{m128rfa1} @tab ATmega128RFA1 @item @code{m16} @tab ATmega16 @item @code{m161} @tab ATmega161 @@ -371,6 +375,8 @@ ABCmini Board, aka Dick Smith HOTCHIP @item @code{alf} @tab Nightshade ALF-PgmAVR,@* @url{http://nightshade.homeip.net/} +@item @code{arduino} +Arduino board, protocol similar to STK500 1.x @item @code{atisp} @tab AT-ISP V1.1 programming cable for AVR-SDK1 from,@* @url{http://micro-research.co.th/} diff --git a/lexer.l b/lexer.l index 268d7b90..d7c1dcd3 100644 --- a/lexer.l +++ b/lexer.l @@ -117,6 +117,7 @@ SIGN [+-] exit(1); } allowfullpagebitstream { yylval=NULL; return K_ALLOWFULLPAGEBITSTREAM; } +arduino { yylval=NULL; return K_ARDUINO; } avr910 { yylval=NULL; return K_AVR910; } avr910_devcode { yylval=NULL; return K_AVR910_DEVCODE; } usbasp { yylval=NULL; return K_USBASP; }