2011-08-26 20:22:09 +00:00
|
|
|
/*
|
|
|
|
* avrdude - A Downloader/Uploader for AVR device programmers
|
|
|
|
* Copyright (C) 2011 Brett Hagman
|
|
|
|
*
|
|
|
|
* 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
|
2012-11-20 14:03:50 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-08-26 20:22:09 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* avrdude interface for Wiring bootloaders
|
|
|
|
*
|
|
|
|
* http://wiring.org.co/
|
|
|
|
*
|
|
|
|
* The Wiring bootloader uses a near-complete STK500v2 protocol.
|
|
|
|
* (Only ISP specific programming commands are not implemented
|
|
|
|
* e.g. chip erase).
|
|
|
|
* DTR and RTS signals are diddled to set the board into programming mode.
|
|
|
|
*
|
|
|
|
* Also includes an extended parameter to introduce a delay after opening
|
|
|
|
* to accommodate multi-layered programmers/bootloaders. If the extended
|
|
|
|
* parameter 'snooze' > 0, then no DTR/RTS toggle takes place, and
|
|
|
|
* AVRDUDE will wait that amount of time in milliseconds before syncing.
|
|
|
|
*
|
|
|
|
* Unfortunately, there is no way to easily chain private programmer data
|
|
|
|
* when we "inherit" programmer types as we have (stk500v2). Sooooo, a
|
|
|
|
* *cringe* global variable is used to store the snooze time.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ac_cfg.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2011-08-26 20:35:40 +00:00
|
|
|
#include <stdlib.h>
|
2011-08-26 20:22:09 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "avrdude.h"
|
2014-05-19 10:01:59 +00:00
|
|
|
#include "libavrdude.h"
|
|
|
|
|
2011-08-26 20:22:09 +00:00
|
|
|
#include "stk500v2_private.h"
|
|
|
|
#include "stk500v2.h"
|
2012-01-31 17:03:43 +00:00
|
|
|
#include "wiring.h"
|
2011-08-26 20:22:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Private data for this programmer.
|
|
|
|
*/
|
|
|
|
struct wiringpdata
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We just have the single snooze integer to carry around for now.
|
|
|
|
*/
|
|
|
|
int snoozetime;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* wiringpdata is our private data */
|
|
|
|
/* pdata is stk500v2's private data (inherited) */
|
|
|
|
|
|
|
|
#define WIRINGPDATA(x) ((struct wiringpdata *)(x))
|
|
|
|
|
|
|
|
#define STK500V2PDATA(pgm) ((struct pdata *)(pgm->cookie))
|
|
|
|
|
|
|
|
|
|
|
|
static void wiring_setup(PROGRAMMER * pgm)
|
|
|
|
{
|
|
|
|
void *mycookie;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First, have STK500v2 backend allocate its own private data.
|
|
|
|
*/
|
|
|
|
stk500v2_setup(pgm);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now prepare our data
|
|
|
|
*/
|
|
|
|
if ((mycookie = malloc(sizeof(struct wiringpdata))) == 0) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: wiring_setup(): Out of memory allocating private data\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
progname);
|
2011-08-26 20:22:09 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
memset(mycookie, 0, sizeof(struct wiringpdata));
|
|
|
|
WIRINGPDATA(mycookie)->snoozetime = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Store our own cookie in a safe place for the time being.
|
|
|
|
*/
|
|
|
|
STK500V2PDATA(pgm)->chained_pdata = mycookie;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wiring_teardown(PROGRAMMER * pgm)
|
|
|
|
{
|
|
|
|
void *mycookie;
|
|
|
|
|
|
|
|
mycookie = STK500V2PDATA(pgm)->chained_pdata;
|
|
|
|
|
|
|
|
free(mycookie);
|
|
|
|
|
|
|
|
stk500v2_teardown(pgm);
|
|
|
|
}
|
|
|
|
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
static int wiring_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) {
|
2011-08-26 20:22:09 +00:00
|
|
|
LNODEID ln;
|
|
|
|
const char *extended_param;
|
|
|
|
int rv = 0;
|
|
|
|
void *mycookie = STK500V2PDATA(pgm)->chained_pdata;
|
|
|
|
|
|
|
|
for (ln = lfirst(extparms); ln; ln = lnext(ln)) {
|
|
|
|
extended_param = ldata(ln);
|
|
|
|
|
|
|
|
if (strncmp(extended_param, "snooze=", strlen("snooze=")) == 0) {
|
|
|
|
int newsnooze;
|
|
|
|
if (sscanf(extended_param, "snooze=%i", &newsnooze) != 1 ||
|
|
|
|
newsnooze < 0) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: wiring_parseextparms(): invalid snooze time '%s'\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
progname, extended_param);
|
2011-08-26 20:22:09 +00:00
|
|
|
rv = -1;
|
|
|
|
continue;
|
|
|
|
}
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_NOTICE2, "%s: wiring_parseextparms(): snooze time set to %d ms\n",
|
|
|
|
progname, newsnooze);
|
2011-08-26 20:22:09 +00:00
|
|
|
WIRINGPDATA(mycookie)->snoozetime = newsnooze;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: wiring_parseextparms(): invalid extended parameter '%s'\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
progname, extended_param);
|
2011-08-26 20:22:09 +00:00
|
|
|
rv = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
static int wiring_open(PROGRAMMER *pgm, const char *port) {
|
2011-08-26 20:22:09 +00:00
|
|
|
int timetosnooze;
|
|
|
|
void *mycookie = STK500V2PDATA(pgm)->chained_pdata;
|
2014-02-21 13:44:11 +00:00
|
|
|
union pinfo pinfo;
|
2011-08-26 20:22:09 +00:00
|
|
|
|
|
|
|
strcpy(pgm->port, port);
|
2021-12-08 10:09:52 +00:00
|
|
|
pinfo.serialinfo.baud = pgm->baudrate ? pgm->baudrate: 115200;
|
|
|
|
pinfo.serialinfo.cflags = SERIAL_8N1;
|
2014-02-21 13:44:11 +00:00
|
|
|
serial_open(port, pinfo, &pgm->fd);
|
2011-08-26 20:22:09 +00:00
|
|
|
|
|
|
|
/* If we have a snoozetime, then we wait and do NOT toggle DTR/RTS */
|
|
|
|
|
|
|
|
if (WIRINGPDATA(mycookie)->snoozetime > 0) {
|
|
|
|
timetosnooze = WIRINGPDATA(mycookie)->snoozetime;
|
|
|
|
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_NOTICE2, "%s: wiring_open(): snoozing for %d ms\n",
|
|
|
|
progname, timetosnooze);
|
2011-08-26 20:22:09 +00:00
|
|
|
while (timetosnooze--)
|
|
|
|
usleep(1000);
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_NOTICE2, "%s: wiring_open(): done snoozing\n",
|
|
|
|
progname);
|
2011-08-26 20:22:09 +00:00
|
|
|
} else {
|
|
|
|
/* Perform Wiring programming mode RESET. */
|
|
|
|
/* This effectively *releases* both DTR and RTS. */
|
|
|
|
/* i.e. both DTR and RTS rise to a HIGH logic level */
|
|
|
|
/* since they are active LOW signals. */
|
|
|
|
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_NOTICE2, "%s: wiring_open(): releasing DTR/RTS\n",
|
|
|
|
progname);
|
2011-08-26 20:22:09 +00:00
|
|
|
|
|
|
|
serial_set_dtr_rts(&pgm->fd, 0);
|
|
|
|
usleep(50*1000);
|
|
|
|
|
|
|
|
/* After releasing for 50 milliseconds, DTR and RTS */
|
|
|
|
/* are asserted (i.e. logic LOW) again. */
|
|
|
|
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_NOTICE2, "%s: wiring_open(): asserting DTR/RTS\n",
|
|
|
|
progname);
|
2011-08-26 20:22:09 +00:00
|
|
|
|
|
|
|
serial_set_dtr_rts(&pgm->fd, 1);
|
|
|
|
usleep(50*1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* drain any extraneous input */
|
|
|
|
stk500v2_drain(pgm, 0);
|
|
|
|
|
|
|
|
if (stk500v2_getsync(pgm) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wiring_close(PROGRAMMER * pgm)
|
|
|
|
{
|
|
|
|
serial_set_dtr_rts(&pgm->fd, 0);
|
|
|
|
serial_close(&pgm->fd);
|
|
|
|
pgm->fd.ifd = -1;
|
|
|
|
}
|
|
|
|
|
2012-01-31 17:03:43 +00:00
|
|
|
const char wiring_desc[] = "http://wiring.org.co/, Basically STK500v2 protocol, with some glue to trigger the bootloader.";
|
|
|
|
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
void wiring_initpgm(PROGRAMMER *pgm) {
|
2011-08-26 20:22:09 +00:00
|
|
|
/* The Wiring bootloader uses a near-complete STK500v2 protocol. */
|
|
|
|
|
|
|
|
stk500v2_initpgm(pgm);
|
|
|
|
|
|
|
|
strcpy(pgm->type, "Wiring");
|
|
|
|
pgm->open = wiring_open;
|
|
|
|
pgm->close = wiring_close;
|
|
|
|
|
|
|
|
pgm->setup = wiring_setup;
|
|
|
|
pgm->teardown = wiring_teardown;
|
|
|
|
pgm->parseextparams = wiring_parseextparms;
|
|
|
|
}
|
|
|
|
|