2006-09-10 20:41:00 +00:00
|
|
|
/*
|
|
|
|
* avrdude - A Downloader/Uploader for AVR device programmers
|
|
|
|
* Copyright (C) 2006 Thomas Fischl
|
main.c, pgm.c, pgm.h: Add setup and teardown hooks to the programmer
definition. If present, call the setup hook immediately after finding
the respective programmer object, and schedule the teardown hook to be
called upon exit. This allows the programmer implementation to
dynamically allocate private programmer data.
avr910.c, butterfly.c, jtagmkI.c, jtagmkII.c, stk500v2.c, usbasp.c,
usbtiny.c: Convert static programmer data into dynamically allocated
data.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@764 81a1dc3b-b13d-400b-aceb-764788c761c2
2007-11-07 20:36:12 +00:00
|
|
|
* Copyright 2007 Joerg Wunsch <j@uriah.heep.sax.de>
|
2006-09-10 20:41:00 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
2006-09-10 20:41:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* $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>
|
2011-08-12 15:56:21 +00:00
|
|
|
#include <stdint.h>
|
2006-09-10 20:41:00 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2007-01-24 21:07:54 +00:00
|
|
|
#include "avrdude.h"
|
2014-05-19 10:01:59 +00:00
|
|
|
#include "libavrdude.h"
|
|
|
|
|
2006-09-10 20:41:00 +00:00
|
|
|
#include "usbasp.h"
|
2014-02-27 13:06:03 +00:00
|
|
|
#include "usbdevs.h"
|
2006-09-10 20:41:00 +00:00
|
|
|
|
2010-03-12 18:27:56 +00:00
|
|
|
#if defined(HAVE_LIBUSB) || defined(HAVE_LIBUSB_1_0)
|
|
|
|
|
|
|
|
#ifdef HAVE_LIBUSB_1_0
|
|
|
|
# define USE_LIBUSB_1_0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(USE_LIBUSB_1_0)
|
|
|
|
# if defined(HAVE_LIBUSB_1_0_LIBUSB_H)
|
|
|
|
# include <libusb-1.0/libusb.h>
|
|
|
|
# else
|
|
|
|
# include <libusb.h>
|
|
|
|
# endif
|
|
|
|
#else
|
2012-01-20 09:39:56 +00:00
|
|
|
# if defined(HAVE_USB_H)
|
|
|
|
# include <usb.h>
|
|
|
|
# elif defined(HAVE_LUSB0_USB_H)
|
|
|
|
# include <lusb0_usb.h>
|
|
|
|
# else
|
|
|
|
# error "libusb needs either <usb.h> or <lusb0_usb.h>"
|
|
|
|
# endif
|
2010-03-12 18:27:56 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_LIBUSB_1_0
|
|
|
|
|
|
|
|
static libusb_context *ctx = NULL;
|
|
|
|
|
2022-01-21 22:13:56 +00:00
|
|
|
static const char *errstr(int result)
|
2010-03-12 18:27:56 +00:00
|
|
|
{
|
2022-01-29 22:32:39 +00:00
|
|
|
static char msg[30];
|
2022-01-21 22:13:56 +00:00
|
|
|
int n = 0;
|
|
|
|
|
2010-03-12 18:27:56 +00:00
|
|
|
switch (result) {
|
|
|
|
case LIBUSB_SUCCESS:
|
2022-01-21 22:13:56 +00:00
|
|
|
return "No error";
|
2010-03-12 18:27:56 +00:00
|
|
|
case LIBUSB_ERROR_IO:
|
2022-01-21 22:13:56 +00:00
|
|
|
n = EIO;
|
|
|
|
break;
|
2010-03-12 18:27:56 +00:00
|
|
|
case LIBUSB_ERROR_INVALID_PARAM:
|
2022-01-21 22:13:56 +00:00
|
|
|
n = EINVAL;
|
|
|
|
break;
|
2010-03-12 18:27:56 +00:00
|
|
|
case LIBUSB_ERROR_ACCESS:
|
2022-01-21 22:13:56 +00:00
|
|
|
n = EACCES;
|
|
|
|
break;
|
2010-03-12 18:27:56 +00:00
|
|
|
case LIBUSB_ERROR_NO_DEVICE:
|
2022-01-21 22:13:56 +00:00
|
|
|
n = ENXIO;
|
|
|
|
break;
|
2010-03-12 18:27:56 +00:00
|
|
|
case LIBUSB_ERROR_NOT_FOUND:
|
2022-01-21 22:13:56 +00:00
|
|
|
n = ENOENT;
|
|
|
|
break;
|
2010-03-12 18:27:56 +00:00
|
|
|
case LIBUSB_ERROR_BUSY:
|
2022-01-21 22:13:56 +00:00
|
|
|
n = EBUSY;
|
|
|
|
break;
|
2010-03-12 18:27:56 +00:00
|
|
|
case LIBUSB_ERROR_TIMEOUT:
|
2022-01-21 22:13:56 +00:00
|
|
|
#ifdef ETIMEDOUT
|
|
|
|
n = ETIMEDOUT;
|
|
|
|
break;
|
|
|
|
#else
|
|
|
|
return "Operation timed out"
|
2011-08-26 05:46:50 +00:00
|
|
|
#endif
|
2010-03-12 18:27:56 +00:00
|
|
|
case LIBUSB_ERROR_OVERFLOW:
|
2022-01-21 22:13:56 +00:00
|
|
|
#ifdef EOVERFLOW
|
|
|
|
n = EOVERFLOW;
|
|
|
|
break;
|
|
|
|
#else
|
|
|
|
return "Value too large to be stored in data type"
|
2011-08-26 05:46:50 +00:00
|
|
|
#endif
|
2010-03-12 18:27:56 +00:00
|
|
|
case LIBUSB_ERROR_PIPE:
|
2022-01-21 22:13:56 +00:00
|
|
|
n = EPIPE;
|
|
|
|
break;
|
2010-03-12 18:27:56 +00:00
|
|
|
case LIBUSB_ERROR_INTERRUPTED:
|
2022-01-21 22:13:56 +00:00
|
|
|
n = EINTR;
|
|
|
|
break;
|
2010-03-12 18:27:56 +00:00
|
|
|
case LIBUSB_ERROR_NO_MEM:
|
2022-01-21 22:13:56 +00:00
|
|
|
n = ENOMEM;
|
|
|
|
break;
|
2010-03-12 18:27:56 +00:00
|
|
|
case LIBUSB_ERROR_NOT_SUPPORTED:
|
2022-01-21 22:13:56 +00:00
|
|
|
n = ENOSYS;
|
|
|
|
break;
|
2010-03-12 18:27:56 +00:00
|
|
|
default:
|
2022-10-17 14:44:55 +00:00
|
|
|
snprintf(msg, sizeof msg, "Unknown libusb error code %d", result);
|
2022-01-21 22:13:56 +00:00
|
|
|
return msg;
|
2010-03-12 18:27:56 +00:00
|
|
|
}
|
2022-01-21 22:13:56 +00:00
|
|
|
return strerror(n);
|
2010-03-12 18:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2006-09-10 20:41:00 +00:00
|
|
|
|
main.c, pgm.c, pgm.h: Add setup and teardown hooks to the programmer
definition. If present, call the setup hook immediately after finding
the respective programmer object, and schedule the teardown hook to be
called upon exit. This allows the programmer implementation to
dynamically allocate private programmer data.
avr910.c, butterfly.c, jtagmkI.c, jtagmkII.c, stk500v2.c, usbasp.c,
usbtiny.c: Convert static programmer data into dynamically allocated
data.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@764 81a1dc3b-b13d-400b-aceb-764788c761c2
2007-11-07 20:36:12 +00:00
|
|
|
/*
|
|
|
|
* Private data for this programmer.
|
|
|
|
*/
|
|
|
|
struct pdata
|
|
|
|
{
|
2010-03-12 18:27:56 +00:00
|
|
|
#ifdef USE_LIBUSB_1_0
|
|
|
|
libusb_device_handle *usbhandle;
|
|
|
|
#else
|
main.c, pgm.c, pgm.h: Add setup and teardown hooks to the programmer
definition. If present, call the setup hook immediately after finding
the respective programmer object, and schedule the teardown hook to be
called upon exit. This allows the programmer implementation to
dynamically allocate private programmer data.
avr910.c, butterfly.c, jtagmkI.c, jtagmkII.c, stk500v2.c, usbasp.c,
usbtiny.c: Convert static programmer data into dynamically allocated
data.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@764 81a1dc3b-b13d-400b-aceb-764788c761c2
2007-11-07 20:36:12 +00:00
|
|
|
usb_dev_handle *usbhandle;
|
2010-03-12 18:27:56 +00:00
|
|
|
#endif
|
2011-05-28 07:35:40 +00:00
|
|
|
int sckfreq_hz;
|
|
|
|
unsigned int capabilities;
|
|
|
|
int use_tpi;
|
2018-01-16 22:40:28 +00:00
|
|
|
int section_e;
|
2020-09-18 21:52:12 +00:00
|
|
|
int sck_3mhz;
|
main.c, pgm.c, pgm.h: Add setup and teardown hooks to the programmer
definition. If present, call the setup hook immediately after finding
the respective programmer object, and schedule the teardown hook to be
called upon exit. This allows the programmer implementation to
dynamically allocate private programmer data.
avr910.c, butterfly.c, jtagmkI.c, jtagmkII.c, stk500v2.c, usbasp.c,
usbtiny.c: Convert static programmer data into dynamically allocated
data.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@764 81a1dc3b-b13d-400b-aceb-764788c761c2
2007-11-07 20:36:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define PDATA(pgm) ((struct pdata *)(pgm->cookie))
|
2011-05-28 07:35:40 +00:00
|
|
|
#define IMPORT_PDATA(pgm) struct pdata *pdata = PDATA(pgm)
|
main.c, pgm.c, pgm.h: Add setup and teardown hooks to the programmer
definition. If present, call the setup hook immediately after finding
the respective programmer object, and schedule the teardown hook to be
called upon exit. This allows the programmer implementation to
dynamically allocate private programmer data.
avr910.c, butterfly.c, jtagmkI.c, jtagmkII.c, stk500v2.c, usbasp.c,
usbtiny.c: Convert static programmer data into dynamically allocated
data.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@764 81a1dc3b-b13d-400b-aceb-764788c761c2
2007-11-07 20:36:12 +00:00
|
|
|
|
2011-05-28 07:35:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Prototypes */
|
|
|
|
// interface - management
|
|
|
|
static void usbasp_setup(PROGRAMMER * pgm);
|
|
|
|
static void usbasp_teardown(PROGRAMMER * 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 usbasp_parseextparms(const PROGRAMMER *pgm, const LISTID extparms);
|
2011-05-28 07:35:40 +00:00
|
|
|
// internal functions
|
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 usbasp_transmit(const PROGRAMMER *pgm, unsigned char receive,
|
2013-09-02 20:22:53 +00:00
|
|
|
unsigned char functionid, const unsigned char *send,
|
|
|
|
unsigned char *buffer, int buffersize);
|
2011-05-28 07:35:40 +00:00
|
|
|
#ifdef USE_LIBUSB_1_0
|
2022-08-07 13:05:54 +00:00
|
|
|
static int usbOpenDevice(libusb_device_handle **device, int vendor, const char *vendorName, int product, const char *productName);
|
2011-05-28 07:35:40 +00:00
|
|
|
#else
|
2022-08-07 13:05:54 +00:00
|
|
|
static int usbOpenDevice(usb_dev_handle **device, int vendor, const char *vendorName, int product, const char *productName);
|
2011-05-28 07:35:40 +00:00
|
|
|
#endif
|
|
|
|
// interface - prog.
|
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 usbasp_open(PROGRAMMER *pgm, const char *port);
|
|
|
|
static void usbasp_close(PROGRAMMER *pgm);
|
2011-05-28 07:35:40 +00:00
|
|
|
// dummy functions
|
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 void usbasp_disable(const PROGRAMMER *pgm);
|
|
|
|
static void usbasp_enable(PROGRAMMER *pgm, const AVRPART *p);
|
|
|
|
static void usbasp_display(const PROGRAMMER *pgm, const char *p);
|
2011-05-28 07:35:40 +00:00
|
|
|
// universal functions
|
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 usbasp_initialize(const PROGRAMMER *pgm, const AVRPART *p);
|
2011-05-28 07:35:40 +00:00
|
|
|
// SPI specific functions
|
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 usbasp_spi_cmd(const PROGRAMMER *pgm, const unsigned char *cmd, unsigned char *res);
|
|
|
|
static int usbasp_spi_program_enable(const PROGRAMMER *pgm, const AVRPART *p);
|
|
|
|
static int usbasp_spi_chip_erase(const PROGRAMMER *pgm, const AVRPART *p);
|
|
|
|
static int usbasp_spi_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
2011-09-14 21:49:42 +00:00
|
|
|
unsigned int page_size,
|
|
|
|
unsigned int addr, unsigned int n_bytes);
|
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 usbasp_spi_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
2011-09-14 21:49:42 +00:00
|
|
|
unsigned int page_size,
|
|
|
|
unsigned int addr, unsigned int n_bytes);
|
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 usbasp_spi_set_sck_period(const PROGRAMMER *pgm, double sckperiod);
|
2011-05-28 07:35:40 +00:00
|
|
|
// TPI specific functions
|
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 void usbasp_tpi_send_byte(const PROGRAMMER *pgm, uint8_t b);
|
|
|
|
static int usbasp_tpi_cmd(const PROGRAMMER *pgm, const unsigned char *cmd, unsigned char *res);
|
|
|
|
static int usbasp_tpi_program_enable(const PROGRAMMER *pgm, const AVRPART *p);
|
|
|
|
static int usbasp_tpi_chip_erase(const PROGRAMMER *pgm, const AVRPART *p);
|
|
|
|
static int usbasp_tpi_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
2011-09-14 21:49:42 +00:00
|
|
|
unsigned int page_size,
|
|
|
|
unsigned int addr, unsigned int n_bytes);
|
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 usbasp_tpi_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
2011-09-14 21:49:42 +00:00
|
|
|
unsigned int page_size,
|
|
|
|
unsigned int addr, unsigned int n_bytes);
|
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 usbasp_tpi_set_sck_period(const PROGRAMMER *pgm, double sckperiod);
|
|
|
|
static int usbasp_tpi_read_byte(const PROGRAMMER * pgm, const AVRPART *p, const AVRMEM *m, unsigned long addr, unsigned char *value);
|
|
|
|
static int usbasp_tpi_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m, unsigned long addr, unsigned char data);
|
|
|
|
|
|
|
|
|
|
|
|
// Dispatching wrappers
|
|
|
|
|
|
|
|
static int usbasp_cmd(const PROGRAMMER *pgm, const unsigned char *cmd, unsigned char *res) {
|
|
|
|
return PDATA(pgm)->use_tpi?
|
|
|
|
usbasp_tpi_cmd(pgm, cmd, res):
|
|
|
|
usbasp_spi_cmd(pgm, cmd, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int usbasp_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
|
|
|
|
return PDATA(pgm)->use_tpi?
|
|
|
|
usbasp_tpi_program_enable(pgm, p):
|
|
|
|
usbasp_spi_program_enable(pgm, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int usbasp_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
|
|
|
|
return PDATA(pgm)->use_tpi?
|
|
|
|
usbasp_tpi_chip_erase(pgm, p):
|
|
|
|
usbasp_spi_chip_erase(pgm, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int usbasp_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
|
|
|
unsigned int page_size, unsigned int addr, unsigned int n_bytes) {
|
|
|
|
|
|
|
|
return PDATA(pgm)->use_tpi?
|
|
|
|
usbasp_tpi_paged_load(pgm, p, m, page_size, addr, n_bytes):
|
|
|
|
usbasp_spi_paged_load(pgm, p, m, page_size, addr, n_bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int usbasp_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
|
|
|
unsigned int page_size, unsigned int addr, unsigned int n_bytes) {
|
|
|
|
|
|
|
|
return PDATA(pgm)->use_tpi?
|
|
|
|
usbasp_tpi_paged_write(pgm, p, m, page_size, addr, n_bytes):
|
|
|
|
usbasp_spi_paged_write(pgm, p, m, page_size, addr, n_bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int usbasp_set_sck_period(const PROGRAMMER *pgm, double sckperiod) {
|
|
|
|
return PDATA(pgm)->use_tpi?
|
|
|
|
usbasp_tpi_set_sck_period(pgm, sckperiod):
|
|
|
|
usbasp_spi_set_sck_period(pgm, sckperiod);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int usbasp_read_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
|
|
|
unsigned long addr, unsigned char * value) {
|
|
|
|
|
|
|
|
return PDATA(pgm)->use_tpi?
|
|
|
|
usbasp_tpi_read_byte(pgm, p, m, addr, value):
|
|
|
|
avr_read_byte_default(pgm, p, m, addr, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int usbasp_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
|
|
|
unsigned long addr, unsigned char data) {
|
|
|
|
|
|
|
|
return PDATA(pgm)->use_tpi?
|
|
|
|
usbasp_tpi_write_byte(pgm, p, m, addr, data):
|
|
|
|
avr_write_byte_default(pgm, p, m, addr, data);
|
|
|
|
}
|
2011-05-28 07:35:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Interface - management */
|
main.c, pgm.c, pgm.h: Add setup and teardown hooks to the programmer
definition. If present, call the setup hook immediately after finding
the respective programmer object, and schedule the teardown hook to be
called upon exit. This allows the programmer implementation to
dynamically allocate private programmer data.
avr910.c, butterfly.c, jtagmkI.c, jtagmkII.c, stk500v2.c, usbasp.c,
usbtiny.c: Convert static programmer data into dynamically allocated
data.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@764 81a1dc3b-b13d-400b-aceb-764788c761c2
2007-11-07 20:36:12 +00:00
|
|
|
static void usbasp_setup(PROGRAMMER * pgm)
|
|
|
|
{
|
|
|
|
if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error(" out of memory allocating private data\n");
|
main.c, pgm.c, pgm.h: Add setup and teardown hooks to the programmer
definition. If present, call the setup hook immediately after finding
the respective programmer object, and schedule the teardown hook to be
called upon exit. This allows the programmer implementation to
dynamically allocate private programmer data.
avr910.c, butterfly.c, jtagmkI.c, jtagmkII.c, stk500v2.c, usbasp.c,
usbtiny.c: Convert static programmer data into dynamically allocated
data.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@764 81a1dc3b-b13d-400b-aceb-764788c761c2
2007-11-07 20:36:12 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
memset(pgm->cookie, 0, sizeof(struct pdata));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void usbasp_teardown(PROGRAMMER * pgm)
|
|
|
|
{
|
|
|
|
free(pgm->cookie);
|
|
|
|
}
|
|
|
|
|
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 usbasp_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) {
|
2018-01-16 22:40:28 +00:00
|
|
|
LNODEID ln;
|
|
|
|
const char *extended_param;
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
for (ln = lfirst(extparms); ln; ln = lnext(ln)) {
|
|
|
|
extended_param = ldata(ln);
|
|
|
|
|
|
|
|
if (strncmp(extended_param, "section_config", strlen("section_config")) == 0) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_notice2("usbasp_parseextparms(): set section_e to 1 (config section)\n");
|
2018-01-16 22:40:28 +00:00
|
|
|
PDATA(pgm)->section_e = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("invalid extended parameter '%s'\n", extended_param);
|
2018-01-16 22:40:28 +00:00
|
|
|
rv = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-28 07:35:40 +00:00
|
|
|
/* Internal functions */
|
2013-08-31 07:32:18 +00:00
|
|
|
|
|
|
|
static const char *usbasp_get_funcname(unsigned char functionid)
|
|
|
|
{
|
|
|
|
switch (functionid) {
|
|
|
|
case USBASP_FUNC_CONNECT: return "USBASP_FUNC_CONNECT"; break;
|
|
|
|
case USBASP_FUNC_DISCONNECT: return "USBASP_FUNC_DISCONNECT"; break;
|
|
|
|
case USBASP_FUNC_TRANSMIT: return "USBASP_FUNC_TRANSMIT"; break;
|
|
|
|
case USBASP_FUNC_READFLASH: return "USBASP_FUNC_READFLASH"; break;
|
|
|
|
case USBASP_FUNC_ENABLEPROG: return "USBASP_FUNC_ENABLEPROG"; break;
|
|
|
|
case USBASP_FUNC_WRITEFLASH: return "USBASP_FUNC_WRITEFLASH"; break;
|
|
|
|
case USBASP_FUNC_READEEPROM: return "USBASP_FUNC_READEEPROM"; break;
|
|
|
|
case USBASP_FUNC_WRITEEEPROM: return "USBASP_FUNC_WRITEEEPROM"; break;
|
|
|
|
case USBASP_FUNC_SETLONGADDRESS: return "USBASP_FUNC_SETLONGADDRESS"; break;
|
|
|
|
case USBASP_FUNC_SETISPSCK: return "USBASP_FUNC_SETISPSCK"; break;
|
|
|
|
case USBASP_FUNC_TPI_CONNECT: return "USBASP_FUNC_TPI_CONNECT"; break;
|
|
|
|
case USBASP_FUNC_TPI_DISCONNECT: return "USBASP_FUNC_TPI_DISCONNECT"; break;
|
|
|
|
case USBASP_FUNC_TPI_RAWREAD: return "USBASP_FUNC_TPI_RAWREAD"; break;
|
|
|
|
case USBASP_FUNC_TPI_RAWWRITE: return "USBASP_FUNC_TPI_RAWWRITE"; break;
|
|
|
|
case USBASP_FUNC_TPI_READBLOCK: return "USBASP_FUNC_TPI_READBLOCK"; break;
|
|
|
|
case USBASP_FUNC_TPI_WRITEBLOCK: return "USBASP_FUNC_TPI_WRITEBLOCK"; break;
|
|
|
|
case USBASP_FUNC_GETCAPABILITIES: return "USBASP_FUNC_GETCAPABILITIES"; break;
|
|
|
|
default: return "Unknown USBASP function"; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-10 20:41:00 +00:00
|
|
|
/*
|
|
|
|
* wrapper for usb_control_msg call
|
|
|
|
*/
|
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 usbasp_transmit(const PROGRAMMER *pgm,
|
main.c, pgm.c, pgm.h: Add setup and teardown hooks to the programmer
definition. If present, call the setup hook immediately after finding
the respective programmer object, and schedule the teardown hook to be
called upon exit. This allows the programmer implementation to
dynamically allocate private programmer data.
avr910.c, butterfly.c, jtagmkI.c, jtagmkII.c, stk500v2.c, usbasp.c,
usbtiny.c: Convert static programmer data into dynamically allocated
data.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@764 81a1dc3b-b13d-400b-aceb-764788c761c2
2007-11-07 20:36:12 +00:00
|
|
|
unsigned char receive, unsigned char functionid,
|
2013-09-02 20:22:53 +00:00
|
|
|
const unsigned char *send,
|
|
|
|
unsigned char *buffer, int buffersize)
|
2006-09-10 20:41:00 +00:00
|
|
|
{
|
|
|
|
int nbytes;
|
2013-08-31 07:32:18 +00:00
|
|
|
|
|
|
|
if (verbose > 3) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_trace("usbasp_transmit(\"%s\", 0x%02x, 0x%02x, 0x%02x, 0x%02x)\n",
|
|
|
|
usbasp_get_funcname(functionid), send[0], send[1], send[2], send[3]);
|
2013-08-31 07:32:18 +00:00
|
|
|
if (!receive && buffersize > 0) {
|
|
|
|
int i;
|
2022-10-17 14:44:55 +00:00
|
|
|
imsg_trace(" => ");
|
2013-08-31 07:32:18 +00:00
|
|
|
for (i = 0; i < buffersize; i++)
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_trace("[%02x] ", buffer[i]);
|
|
|
|
msg_trace("\n");
|
2013-08-31 07:32:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-12 18:27:56 +00:00
|
|
|
#ifdef USE_LIBUSB_1_0
|
|
|
|
nbytes = libusb_control_transfer(PDATA(pgm)->usbhandle,
|
|
|
|
(LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | (receive << 7)) & 0xff,
|
|
|
|
functionid & 0xff,
|
2010-04-25 12:36:36 +00:00
|
|
|
((send[1] << 8) | send[0]) & 0xffff,
|
2010-03-12 18:27:56 +00:00
|
|
|
((send[3] << 8) | send[2]) & 0xffff,
|
2014-07-16 20:02:01 +00:00
|
|
|
buffer,
|
2010-03-12 18:27:56 +00:00
|
|
|
buffersize & 0xffff,
|
|
|
|
5000);
|
|
|
|
if(nbytes < 0){
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_ext_error("%s\n", errstr(nbytes));
|
2010-04-25 12:36:36 +00:00
|
|
|
return -1;
|
2010-03-12 18:27:56 +00:00
|
|
|
}
|
|
|
|
#else
|
main.c, pgm.c, pgm.h: Add setup and teardown hooks to the programmer
definition. If present, call the setup hook immediately after finding
the respective programmer object, and schedule the teardown hook to be
called upon exit. This allows the programmer implementation to
dynamically allocate private programmer data.
avr910.c, butterfly.c, jtagmkI.c, jtagmkII.c, stk500v2.c, usbasp.c,
usbtiny.c: Convert static programmer data into dynamically allocated
data.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@764 81a1dc3b-b13d-400b-aceb-764788c761c2
2007-11-07 20:36:12 +00:00
|
|
|
nbytes = usb_control_msg(PDATA(pgm)->usbhandle,
|
2006-09-10 20:41:00 +00:00
|
|
|
USB_TYPE_VENDOR | USB_RECIP_DEVICE | (receive << 7),
|
|
|
|
functionid,
|
|
|
|
(send[1] << 8) | send[0],
|
|
|
|
(send[3] << 8) | send[2],
|
2008-07-25 21:14:43 +00:00
|
|
|
(char *)buffer, buffersize,
|
2006-09-10 20:41:00 +00:00
|
|
|
5000);
|
|
|
|
if(nbytes < 0){
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("%s\n", usb_strerror());
|
2010-04-25 12:36:36 +00:00
|
|
|
return -1;
|
2006-09-10 20:41:00 +00:00
|
|
|
}
|
2010-03-12 18:27:56 +00:00
|
|
|
#endif
|
2013-08-31 07:32:18 +00:00
|
|
|
|
|
|
|
if (verbose > 3 && receive && nbytes > 0) {
|
|
|
|
int i;
|
2022-10-17 14:44:55 +00:00
|
|
|
imsg_trace("<= ");
|
2013-08-31 07:32:18 +00:00
|
|
|
for (i = 0; i < nbytes; i++)
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_trace("[%02x] ", buffer[i]);
|
|
|
|
msg_trace("\n");
|
2013-08-31 07:32:18 +00:00
|
|
|
}
|
|
|
|
|
2006-09-10 20:41:00 +00:00
|
|
|
return nbytes;
|
|
|
|
}
|
|
|
|
|
2006-09-17 20:35:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to open USB device with given VID, PID, vendor and product name
|
|
|
|
* Parts of this function were taken from an example code by OBJECTIVE
|
|
|
|
* DEVELOPMENT Software GmbH (www.obdev.at) to meet conditions for
|
|
|
|
* shared VID/PID
|
|
|
|
*/
|
2010-03-12 18:27:56 +00:00
|
|
|
#ifdef USE_LIBUSB_1_0
|
|
|
|
static int usbOpenDevice(libusb_device_handle **device, int vendor,
|
2022-08-07 13:05:54 +00:00
|
|
|
const char *vendorName, int product, const char *productName)
|
2010-03-12 18:27:56 +00:00
|
|
|
{
|
|
|
|
libusb_device_handle *handle = NULL;
|
|
|
|
int errorCode = USB_ERROR_NOTFOUND;
|
|
|
|
static int didUsbInit = 0;
|
|
|
|
int j;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
if(!didUsbInit){
|
|
|
|
didUsbInit = 1;
|
|
|
|
libusb_init(&ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
libusb_device **dev_list;
|
|
|
|
int dev_list_len = libusb_get_device_list(ctx, &dev_list);
|
|
|
|
|
|
|
|
for (j=0; j<dev_list_len; ++j) {
|
|
|
|
libusb_device *dev = dev_list[j];
|
|
|
|
struct libusb_device_descriptor descriptor;
|
|
|
|
libusb_get_device_descriptor(dev, &descriptor);
|
|
|
|
if (descriptor.idVendor == vendor && descriptor.idProduct == product) {
|
|
|
|
char string[256];
|
|
|
|
/* we need to open the device in order to query strings */
|
|
|
|
r = libusb_open(dev, &handle);
|
|
|
|
if (!handle) {
|
|
|
|
errorCode = USB_ERROR_ACCESS;
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_warning("cannot open USB device: %s\n", errstr(r));
|
|
|
|
continue;
|
2012-01-17 17:37:23 +00:00
|
|
|
}
|
|
|
|
errorCode = 0;
|
|
|
|
/* now check whether the names match: */
|
|
|
|
/* if vendorName not given ignore it (any vendor matches) */
|
2014-07-16 20:02:01 +00:00
|
|
|
r = libusb_get_string_descriptor_ascii(handle, descriptor.iManufacturer & 0xff, (unsigned char*)string, sizeof(string));
|
2012-01-17 17:37:23 +00:00
|
|
|
if (r < 0) {
|
|
|
|
if ((vendorName != NULL) && (vendorName[0] != 0)) {
|
2010-03-12 18:27:56 +00:00
|
|
|
errorCode = USB_ERROR_IO;
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_warning("cannot query manufacturer for device: %s\n", errstr(r));
|
2012-01-17 17:37:23 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_notice2("seen device from vendor >%s<\n", string);
|
2012-01-17 17:37:23 +00:00
|
|
|
if ((vendorName != NULL) && (vendorName[0] != 0) && (strcmp(string, vendorName) != 0))
|
2010-03-12 18:27:56 +00:00
|
|
|
errorCode = USB_ERROR_NOTFOUND;
|
|
|
|
}
|
2012-01-17 17:37:23 +00:00
|
|
|
/* if productName not given ignore it (any product matches) */
|
2014-07-16 20:02:01 +00:00
|
|
|
r = libusb_get_string_descriptor_ascii(handle, descriptor.iProduct & 0xff, (unsigned char*)string, sizeof(string));
|
2012-01-17 17:37:23 +00:00
|
|
|
if (r < 0) {
|
|
|
|
if ((productName != NULL) && (productName[0] != 0)) {
|
|
|
|
errorCode = USB_ERROR_IO;
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_warning("cannot query product for device: %s\n", errstr(r));
|
2012-01-17 17:37:23 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_notice2("seen product >%s<\n", string);
|
2012-01-17 17:37:23 +00:00
|
|
|
if((productName != NULL) && (productName[0] != 0) && (strcmp(string, productName) != 0))
|
|
|
|
errorCode = USB_ERROR_NOTFOUND;
|
|
|
|
}
|
|
|
|
if (errorCode == 0)
|
|
|
|
break;
|
|
|
|
libusb_close(handle);
|
|
|
|
handle = NULL;
|
|
|
|
}
|
2010-03-12 18:27:56 +00:00
|
|
|
}
|
2012-01-17 20:56:37 +00:00
|
|
|
libusb_free_device_list(dev_list,1);
|
2010-03-12 18:27:56 +00:00
|
|
|
if (handle != NULL){
|
|
|
|
errorCode = 0;
|
|
|
|
*device = handle;
|
|
|
|
}
|
|
|
|
return errorCode;
|
|
|
|
}
|
|
|
|
#else
|
2006-09-17 20:35:36 +00:00
|
|
|
static int usbOpenDevice(usb_dev_handle **device, int vendor,
|
2022-08-07 13:05:54 +00:00
|
|
|
const char *vendorName, int product, const char *productName)
|
2006-09-10 20:41:00 +00:00
|
|
|
{
|
2010-03-12 18:27:56 +00:00
|
|
|
struct usb_bus *bus;
|
|
|
|
struct usb_device *dev;
|
|
|
|
usb_dev_handle *handle = NULL;
|
|
|
|
int errorCode = USB_ERROR_NOTFOUND;
|
|
|
|
static int didUsbInit = 0;
|
2006-09-10 20:41:00 +00:00
|
|
|
|
2006-09-17 20:35:36 +00:00
|
|
|
if(!didUsbInit){
|
|
|
|
didUsbInit = 1;
|
|
|
|
usb_init();
|
2006-09-10 20:41:00 +00:00
|
|
|
}
|
2006-09-17 20:35:36 +00:00
|
|
|
usb_find_busses();
|
|
|
|
usb_find_devices();
|
|
|
|
for(bus=usb_get_busses(); bus; bus=bus->next){
|
|
|
|
for(dev=bus->devices; dev; dev=dev->next){
|
|
|
|
if(dev->descriptor.idVendor == vendor &&
|
|
|
|
dev->descriptor.idProduct == product){
|
|
|
|
char string[256];
|
|
|
|
int len;
|
|
|
|
/* we need to open the device in order to query strings */
|
|
|
|
handle = usb_open(dev);
|
|
|
|
if(!handle){
|
|
|
|
errorCode = USB_ERROR_ACCESS;
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_warning("cannot open USB device: %s\n", usb_strerror());
|
2006-09-17 20:35:36 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-01-17 17:37:23 +00:00
|
|
|
errorCode = 0;
|
2006-09-17 20:35:36 +00:00
|
|
|
/* now check whether the names match: */
|
2012-01-17 17:37:23 +00:00
|
|
|
/* if vendorName not given ignore it (any vendor matches) */
|
2006-09-17 20:35:36 +00:00
|
|
|
len = usb_get_string_simple(handle, dev->descriptor.iManufacturer,
|
|
|
|
string, sizeof(string));
|
|
|
|
if(len < 0){
|
2012-01-17 17:37:23 +00:00
|
|
|
if ((vendorName != NULL) && (vendorName[0] != 0)) {
|
2006-09-17 20:35:36 +00:00
|
|
|
errorCode = USB_ERROR_IO;
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_warning("cannot query manufacturer for device: %s\n", usb_strerror());
|
2012-01-17 17:37:23 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_notice2("seen device from vendor >%s<\n", string);
|
2012-01-17 17:37:23 +00:00
|
|
|
if((vendorName != NULL) && (vendorName[0] != 0) && (strcmp(string, vendorName) != 0))
|
|
|
|
errorCode = USB_ERROR_NOTFOUND;
|
|
|
|
}
|
|
|
|
/* if productName not given ignore it (any product matches) */
|
|
|
|
len = usb_get_string_simple(handle, dev->descriptor.iProduct,
|
|
|
|
string, sizeof(string));
|
|
|
|
if(len < 0){
|
|
|
|
if ((productName != NULL) && (productName[0] != 0)) {
|
|
|
|
errorCode = USB_ERROR_IO;
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_warning("cannot query product for device: %s\n", usb_strerror());
|
2012-01-17 17:37:23 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_notice2("seen product >%s<\n", string);
|
2012-01-17 17:37:23 +00:00
|
|
|
if((productName != NULL) && (productName[0] != 0) && (strcmp(string, productName) != 0))
|
|
|
|
errorCode = USB_ERROR_NOTFOUND;
|
2006-09-17 20:35:36 +00:00
|
|
|
}
|
2012-01-17 17:37:23 +00:00
|
|
|
if (errorCode == 0)
|
|
|
|
break;
|
2006-09-17 20:35:36 +00:00
|
|
|
usb_close(handle);
|
|
|
|
handle = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(handle)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(handle != NULL){
|
|
|
|
errorCode = 0;
|
|
|
|
*device = handle;
|
|
|
|
}
|
|
|
|
return errorCode;
|
|
|
|
}
|
2010-03-12 18:27:56 +00:00
|
|
|
#endif
|
2006-09-17 20:35:36 +00:00
|
|
|
|
2011-05-28 07:35:40 +00:00
|
|
|
|
|
|
|
/* Interface - prog. */
|
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 usbasp_open(PROGRAMMER *pgm, const char *port) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_debug("usbasp_open(\"%s\")\n", port);
|
2013-09-02 06:43:06 +00:00
|
|
|
|
2012-01-17 20:56:37 +00:00
|
|
|
/* usb_init will be done in usbOpenDevice */
|
2014-02-27 13:06:03 +00:00
|
|
|
LNODEID usbpid = lfirst(pgm->usbpid);
|
|
|
|
int pid, vid;
|
|
|
|
if (usbpid) {
|
|
|
|
pid = *(int *)(ldata(usbpid));
|
|
|
|
if (lnext(usbpid))
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_warning("using PID 0x%04x, ignoring remaining PIDs in list\n", pid);
|
2014-02-27 13:06:03 +00:00
|
|
|
} else {
|
|
|
|
pid = USBASP_SHARED_PID;
|
|
|
|
}
|
|
|
|
vid = pgm->usbvid? pgm->usbvid: USBASP_SHARED_VID;
|
|
|
|
if (usbOpenDevice(&PDATA(pgm)->usbhandle, vid, pgm->usbvendor, pid, pgm->usbproduct) != 0) {
|
2012-01-17 17:37:23 +00:00
|
|
|
/* try alternatives */
|
|
|
|
if(strcasecmp(ldata(lfirst(pgm->id)), "usbasp") == 0) {
|
|
|
|
/* for id usbasp autodetect some variants */
|
|
|
|
if(strcasecmp(port, "nibobee") == 0) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("using -C usbasp -P nibobee is deprecated, use -C nibobee instead\n");
|
2012-01-17 17:37:23 +00:00
|
|
|
if (usbOpenDevice(&PDATA(pgm)->usbhandle, USBASP_NIBOBEE_VID, "www.nicai-systems.com",
|
|
|
|
USBASP_NIBOBEE_PID, "NIBObee") != 0) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("cannot find USB device NIBObee with vid=0x%x pid=0x%x\n",
|
|
|
|
USBASP_NIBOBEE_VID, USBASP_NIBOBEE_PID);
|
2012-01-17 17:37:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* check if device with old VID/PID is available */
|
|
|
|
if (usbOpenDevice(&PDATA(pgm)->usbhandle, USBASP_OLD_VID, "www.fischl.de",
|
|
|
|
USBASP_OLD_PID, "USBasp") == 0) {
|
|
|
|
/* found USBasp with old IDs */
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("found USB device USBasp with old VID/PID; please update firmware of USBasp\n");
|
2012-01-17 17:37:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* original USBasp is specified in config file, so no need to check it again here */
|
|
|
|
/* no alternative found => fall through to generic error message */
|
2010-03-12 18:27:56 +00:00
|
|
|
}
|
2006-09-17 20:35:36 +00:00
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("cannot find USB device with vid=0x%x pid=0x%x", vid, pid);
|
2012-01-17 17:37:23 +00:00
|
|
|
if (pgm->usbvendor[0] != 0) {
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_error(" vendor='%s'", pgm->usbvendor);
|
2006-09-17 20:35:36 +00:00
|
|
|
}
|
2012-01-17 17:37:23 +00:00
|
|
|
if (pgm->usbproduct[0] != 0) {
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_error(" product='%s'", pgm->usbproduct);
|
2012-01-17 17:37:23 +00:00
|
|
|
}
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_error("\n");
|
2012-01-17 17:37:23 +00:00
|
|
|
return -1;
|
2006-09-10 20:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void usbasp_close(PROGRAMMER * pgm)
|
|
|
|
{
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_debug("usbasp_close()\n");
|
2013-09-02 06:43:06 +00:00
|
|
|
|
2010-04-25 12:36:36 +00:00
|
|
|
if (PDATA(pgm)->usbhandle!=NULL) {
|
|
|
|
unsigned char temp[4];
|
|
|
|
memset(temp, 0, sizeof(temp));
|
2011-05-28 07:35:40 +00:00
|
|
|
|
|
|
|
if (PDATA(pgm)->use_tpi) {
|
|
|
|
usbasp_transmit(pgm, 1, USBASP_FUNC_TPI_DISCONNECT, temp, temp, sizeof(temp));
|
|
|
|
} else {
|
|
|
|
usbasp_transmit(pgm, 1, USBASP_FUNC_DISCONNECT, temp, temp, sizeof(temp));
|
|
|
|
}
|
|
|
|
|
2010-03-12 18:27:56 +00:00
|
|
|
#ifdef USE_LIBUSB_1_0
|
2010-04-25 12:36:36 +00:00
|
|
|
libusb_close(PDATA(pgm)->usbhandle);
|
2010-03-12 18:27:56 +00:00
|
|
|
#else
|
2010-04-25 12:36:36 +00:00
|
|
|
usb_close(PDATA(pgm)->usbhandle);
|
2010-03-12 18:27:56 +00:00
|
|
|
#endif
|
2010-04-25 12:36:36 +00:00
|
|
|
}
|
2012-01-17 20:56:37 +00:00
|
|
|
#ifdef USE_LIBUSB_1_0
|
|
|
|
libusb_exit(ctx);
|
|
|
|
#else
|
|
|
|
/* nothing for usb 0.1 ? */
|
|
|
|
#endif
|
2006-09-10 20:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-28 07:35:40 +00:00
|
|
|
/* Dummy functions */
|
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 void usbasp_disable(const PROGRAMMER *pgm) {
|
2006-09-10 20:41:00 +00:00
|
|
|
/* Do nothing. */
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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 void usbasp_enable(PROGRAMMER *pgm, const AVRPART *p) {
|
2006-09-10 20:41:00 +00:00
|
|
|
/* Do nothing. */
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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 void usbasp_display(const PROGRAMMER *pgm, const char *p) {
|
2006-09-10 20:41:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
// @@@
|
|
|
|
|
2011-05-28 07:35:40 +00:00
|
|
|
/* Universal functions: for both SPI and TPI */
|
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 usbasp_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
|
2011-05-28 07:35:40 +00:00
|
|
|
unsigned char temp[4];
|
|
|
|
unsigned char res[4];
|
|
|
|
IMPORT_PDATA(pgm);
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_debug("usbasp_initialize()\n");
|
2011-05-28 07:35:40 +00:00
|
|
|
|
|
|
|
/* get capabilities */
|
|
|
|
memset(temp, 0, sizeof(temp));
|
|
|
|
if(usbasp_transmit(pgm, 1, USBASP_FUNC_GETCAPABILITIES, temp, res, sizeof(res)) == 4)
|
|
|
|
pdata->capabilities = res[0] | ((unsigned int)res[1] << 8) | ((unsigned int)res[2] << 16) | ((unsigned int)res[3] << 24);
|
|
|
|
else
|
|
|
|
pdata->capabilities = 0;
|
|
|
|
|
2022-08-30 15:33:42 +00:00
|
|
|
pdata->use_tpi = (pdata->capabilities & USBASP_CAP_TPI) && (p->prog_modes & PM_TPI);
|
2020-09-18 21:52:12 +00:00
|
|
|
// query support for 3 MHz SCK in UsbAsp-flash firmware
|
|
|
|
// https://github.com/nofeletru/UsbAsp-flash
|
|
|
|
pdata->sck_3mhz = ((pdata->capabilities & USBASP_CAP_3MHZ) != 0) ? 1 :0;
|
2011-05-28 07:35:40 +00:00
|
|
|
|
|
|
|
if(pdata->use_tpi)
|
|
|
|
{
|
|
|
|
/* calc tpiclk delay */
|
2012-01-08 17:09:40 +00:00
|
|
|
int dly = 1500000.0 * pgm->bitclock;
|
2011-05-28 07:35:40 +00:00
|
|
|
if(dly < 1)
|
|
|
|
dly = 1;
|
|
|
|
else if(dly > 2047)
|
|
|
|
dly = 2047;
|
|
|
|
temp[0] = dly;
|
|
|
|
temp[1] = dly >> 8;
|
|
|
|
|
|
|
|
/* connect */
|
|
|
|
usbasp_transmit(pgm, 1, USBASP_FUNC_TPI_CONNECT, temp, res, sizeof(res));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* set sck period */
|
|
|
|
pgm->set_sck_period(pgm, pgm->bitclock);
|
|
|
|
|
|
|
|
/* connect to target device */
|
|
|
|
usbasp_transmit(pgm, 1, USBASP_FUNC_CONNECT, temp, res, sizeof(res));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wait, so device is ready to receive commands */
|
|
|
|
usleep(100000);
|
|
|
|
|
|
|
|
return pgm->program_enable(pgm, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SPI specific functions */
|
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 usbasp_spi_cmd(const PROGRAMMER *pgm, const unsigned char *cmd,
|
2013-09-02 20:22:53 +00:00
|
|
|
unsigned char *res)
|
2006-09-10 20:41:00 +00:00
|
|
|
{
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_debug("usbasp_spi_cmd(0x%02x, 0x%02x, 0x%02x, 0x%02x)%s",
|
|
|
|
cmd[0], cmd[1], cmd[2], cmd[3], verbose > 3? " ...\n": "");
|
2013-09-02 06:43:06 +00:00
|
|
|
|
2006-09-10 20:41:00 +00:00
|
|
|
int nbytes =
|
2012-01-08 17:09:40 +00:00
|
|
|
usbasp_transmit(pgm, 1, USBASP_FUNC_TRANSMIT, cmd, res, 4);
|
2006-09-10 20:41:00 +00:00
|
|
|
|
|
|
|
if(nbytes != 4){
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_debug("\n");
|
2013-09-02 06:43:06 +00:00
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("wrong response size\n");
|
2006-09-10 20:41:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_trace("usbasp_spi_cmd()");
|
|
|
|
msg_debug(" => 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
|
2014-06-13 20:07:40 +00:00
|
|
|
res[0], res[1], res[2], res[3]);
|
2006-09-10 20:41:00 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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 usbasp_spi_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
|
2006-09-10 20:41:00 +00:00
|
|
|
unsigned char res[4];
|
|
|
|
unsigned char cmd[4];
|
|
|
|
memset(cmd, 0, sizeof(cmd));
|
|
|
|
memset(res, 0, sizeof(res));
|
|
|
|
|
|
|
|
cmd[0] = 0;
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_debug("usbasp_program_enable()\n");
|
2013-09-02 06:43:06 +00:00
|
|
|
|
2006-09-10 20:41:00 +00:00
|
|
|
int nbytes =
|
main.c, pgm.c, pgm.h: Add setup and teardown hooks to the programmer
definition. If present, call the setup hook immediately after finding
the respective programmer object, and schedule the teardown hook to be
called upon exit. This allows the programmer implementation to
dynamically allocate private programmer data.
avr910.c, butterfly.c, jtagmkI.c, jtagmkII.c, stk500v2.c, usbasp.c,
usbtiny.c: Convert static programmer data into dynamically allocated
data.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@764 81a1dc3b-b13d-400b-aceb-764788c761c2
2007-11-07 20:36:12 +00:00
|
|
|
usbasp_transmit(pgm, 1, USBASP_FUNC_ENABLEPROG, cmd, res, sizeof(res));
|
2006-09-10 20:41:00 +00:00
|
|
|
|
|
|
|
if ((nbytes != 1) | (res[0] != 0)) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("program enable: target does not answer (0x%02x)\n", res[0]);
|
2006-09-10 20:41:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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 usbasp_spi_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
|
2006-09-10 20:41:00 +00:00
|
|
|
unsigned char cmd[4];
|
|
|
|
unsigned char res[4];
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_debug("usbasp_chip_erase()\n");
|
2013-09-02 06:43:06 +00:00
|
|
|
|
2006-09-10 20:41:00 +00:00
|
|
|
if (p->op[AVR_OP_CHIP_ERASE] == NULL) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("chip erase instruction not defined for part %s\n", p->desc);
|
2006-09-10 20:41:00 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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 usbasp_spi_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
|
|
|
unsigned int page_size, unsigned int address, unsigned int n_bytes) {
|
|
|
|
|
2006-09-10 20:41:00 +00:00
|
|
|
int n;
|
|
|
|
unsigned char cmd[4];
|
|
|
|
int wbytes = n_bytes;
|
|
|
|
int blocksize;
|
2012-01-03 22:38:59 +00:00
|
|
|
unsigned char *buffer = m->buf + address;
|
2006-09-10 20:41:00 +00:00
|
|
|
int function;
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_debug("usbasp_program_paged_load(\"%s\", 0x%x, %d)\n", m->desc, address, n_bytes);
|
2013-09-02 06:43:06 +00:00
|
|
|
|
2006-09-10 20:41:00 +00:00
|
|
|
if (strcmp(m->desc, "flash") == 0) {
|
|
|
|
function = USBASP_FUNC_READFLASH;
|
|
|
|
} else if (strcmp(m->desc, "eeprom") == 0) {
|
|
|
|
function = USBASP_FUNC_READEEPROM;
|
|
|
|
} else {
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
2010-01-08 18:33:23 +00:00
|
|
|
/* set blocksize depending on sck frequency */
|
|
|
|
if ((PDATA(pgm)->sckfreq_hz > 0) && (PDATA(pgm)->sckfreq_hz < 10000)) {
|
|
|
|
blocksize = USBASP_READBLOCKSIZE / 10;
|
|
|
|
} else {
|
|
|
|
blocksize = USBASP_READBLOCKSIZE;
|
|
|
|
}
|
|
|
|
|
2006-09-10 20:41:00 +00:00
|
|
|
while (wbytes) {
|
2010-01-08 18:33:23 +00:00
|
|
|
if (wbytes <= blocksize) {
|
2006-09-10 20:41:00 +00:00
|
|
|
blocksize = wbytes;
|
|
|
|
}
|
2010-01-08 18:33:23 +00:00
|
|
|
wbytes -= blocksize;
|
2006-09-10 20:41:00 +00:00
|
|
|
|
2007-07-24 16:43:25 +00:00
|
|
|
/* set address (new mode) - if firmware on usbasp support newmode, then they use address from this command */
|
|
|
|
unsigned char temp[4];
|
|
|
|
memset(temp, 0, sizeof(temp));
|
2006-09-10 20:41:00 +00:00
|
|
|
cmd[0] = address & 0xFF;
|
|
|
|
cmd[1] = address >> 8;
|
2007-07-24 16:43:25 +00:00
|
|
|
cmd[2] = address >> 16;
|
|
|
|
cmd[3] = address >> 24;
|
2009-02-28 13:10:47 +00:00
|
|
|
usbasp_transmit(pgm, 1, USBASP_FUNC_SETLONGADDRESS, cmd, temp, sizeof(temp));
|
|
|
|
|
2007-07-24 16:43:25 +00:00
|
|
|
/* send command with address (compatibility mode) - if firmware on
|
|
|
|
usbasp doesn't support newmode, then they use address from this */
|
|
|
|
cmd[0] = address & 0xFF;
|
|
|
|
cmd[1] = address >> 8;
|
|
|
|
// for compatibility - previous version of usbasp.c doesn't initialize this fields (firmware ignore it)
|
|
|
|
cmd[2] = 0;
|
|
|
|
cmd[3] = 0;
|
2006-09-10 20:41:00 +00:00
|
|
|
|
main.c, pgm.c, pgm.h: Add setup and teardown hooks to the programmer
definition. If present, call the setup hook immediately after finding
the respective programmer object, and schedule the teardown hook to be
called upon exit. This allows the programmer implementation to
dynamically allocate private programmer data.
avr910.c, butterfly.c, jtagmkI.c, jtagmkII.c, stk500v2.c, usbasp.c,
usbtiny.c: Convert static programmer data into dynamically allocated
data.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@764 81a1dc3b-b13d-400b-aceb-764788c761c2
2007-11-07 20:36:12 +00:00
|
|
|
n = usbasp_transmit(pgm, 1, function, cmd, buffer, blocksize);
|
2006-09-10 20:41:00 +00:00
|
|
|
|
|
|
|
if (n != blocksize) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("wrong reading bytes %x\n", n);
|
2010-04-25 12:36:36 +00:00
|
|
|
return -3;
|
2006-09-10 20:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
buffer += blocksize;
|
|
|
|
address += blocksize;
|
|
|
|
}
|
|
|
|
|
|
|
|
return n_bytes;
|
|
|
|
}
|
|
|
|
|
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 usbasp_spi_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
|
|
|
unsigned int page_size, unsigned int address, unsigned int n_bytes) {
|
|
|
|
|
2006-09-10 20:41:00 +00:00
|
|
|
int n;
|
|
|
|
unsigned char cmd[4];
|
|
|
|
int wbytes = n_bytes;
|
|
|
|
int blocksize;
|
2012-01-03 22:38:59 +00:00
|
|
|
unsigned char *buffer = m->buf + address;
|
2006-09-10 20:41:00 +00:00
|
|
|
unsigned char blockflags = USBASP_BLOCKFLAG_FIRST;
|
|
|
|
int function;
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_debug("usbasp_program_paged_write(\"%s\", 0x%x, %d)\n", m->desc, address, n_bytes);
|
2013-09-02 06:43:06 +00:00
|
|
|
|
2006-09-10 20:41:00 +00:00
|
|
|
if (strcmp(m->desc, "flash") == 0) {
|
|
|
|
function = USBASP_FUNC_WRITEFLASH;
|
|
|
|
} else if (strcmp(m->desc, "eeprom") == 0) {
|
|
|
|
function = USBASP_FUNC_WRITEEEPROM;
|
|
|
|
} else {
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
2010-01-08 18:33:23 +00:00
|
|
|
/* set blocksize depending on sck frequency */
|
|
|
|
if ((PDATA(pgm)->sckfreq_hz > 0) && (PDATA(pgm)->sckfreq_hz < 10000)) {
|
|
|
|
blocksize = USBASP_WRITEBLOCKSIZE / 10;
|
|
|
|
} else {
|
|
|
|
blocksize = USBASP_WRITEBLOCKSIZE;
|
|
|
|
}
|
|
|
|
|
2006-09-10 20:41:00 +00:00
|
|
|
while (wbytes) {
|
2010-01-08 18:33:23 +00:00
|
|
|
|
|
|
|
if (wbytes <= blocksize) {
|
2006-09-10 20:41:00 +00:00
|
|
|
blocksize = wbytes;
|
|
|
|
}
|
2010-01-08 18:33:23 +00:00
|
|
|
wbytes -= blocksize;
|
|
|
|
|
2006-09-10 20:41:00 +00:00
|
|
|
|
2007-07-24 16:43:25 +00:00
|
|
|
/* set address (new mode) - if firmware on usbasp support newmode, then
|
|
|
|
they use address from this command */
|
|
|
|
unsigned char temp[4];
|
|
|
|
memset(temp, 0, sizeof(temp));
|
|
|
|
cmd[0] = address & 0xFF;
|
|
|
|
cmd[1] = address >> 8;
|
|
|
|
cmd[2] = address >> 16;
|
|
|
|
cmd[3] = address >> 24;
|
main.c, pgm.c, pgm.h: Add setup and teardown hooks to the programmer
definition. If present, call the setup hook immediately after finding
the respective programmer object, and schedule the teardown hook to be
called upon exit. This allows the programmer implementation to
dynamically allocate private programmer data.
avr910.c, butterfly.c, jtagmkI.c, jtagmkII.c, stk500v2.c, usbasp.c,
usbtiny.c: Convert static programmer data into dynamically allocated
data.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@764 81a1dc3b-b13d-400b-aceb-764788c761c2
2007-11-07 20:36:12 +00:00
|
|
|
usbasp_transmit(pgm, 1, USBASP_FUNC_SETLONGADDRESS, cmd, temp, sizeof(temp));
|
2009-02-28 13:10:47 +00:00
|
|
|
|
2007-07-24 16:43:25 +00:00
|
|
|
/* normal command - firmware what support newmode - use address from previous command,
|
|
|
|
firmware what doesn't support newmode - ignore previous command and use address from this command */
|
2009-02-28 13:10:47 +00:00
|
|
|
|
2006-09-10 20:41:00 +00:00
|
|
|
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;
|
|
|
|
|
main.c, pgm.c, pgm.h: Add setup and teardown hooks to the programmer
definition. If present, call the setup hook immediately after finding
the respective programmer object, and schedule the teardown hook to be
called upon exit. This allows the programmer implementation to
dynamically allocate private programmer data.
avr910.c, butterfly.c, jtagmkI.c, jtagmkII.c, stk500v2.c, usbasp.c,
usbtiny.c: Convert static programmer data into dynamically allocated
data.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@764 81a1dc3b-b13d-400b-aceb-764788c761c2
2007-11-07 20:36:12 +00:00
|
|
|
n = usbasp_transmit(pgm, 0, function, cmd, buffer, blocksize);
|
2006-09-10 20:41:00 +00:00
|
|
|
|
|
|
|
if (n != blocksize) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("wrong count at writing %x\n", n);
|
2010-04-25 12:36:36 +00:00
|
|
|
return -3;
|
2006-09-10 20:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
buffer += blocksize;
|
|
|
|
address += blocksize;
|
|
|
|
}
|
|
|
|
|
|
|
|
return n_bytes;
|
|
|
|
}
|
|
|
|
|
2010-01-08 18:33:23 +00:00
|
|
|
/* The list of SCK frequencies in Hz supported by USBasp */
|
2009-02-28 13:10:47 +00:00
|
|
|
static struct sckoptions_t usbaspSCKoptions[] = {
|
2020-09-18 21:52:12 +00:00
|
|
|
{ USBASP_ISP_SCK_3000, 3000000 },
|
2010-01-08 18:33:23 +00:00
|
|
|
{ USBASP_ISP_SCK_1500, 1500000 },
|
|
|
|
{ USBASP_ISP_SCK_750, 750000 },
|
|
|
|
{ USBASP_ISP_SCK_375, 375000 },
|
|
|
|
{ USBASP_ISP_SCK_187_5, 187500 },
|
|
|
|
{ USBASP_ISP_SCK_93_75, 93750 },
|
|
|
|
{ USBASP_ISP_SCK_32, 32000 },
|
|
|
|
{ USBASP_ISP_SCK_16, 16000 },
|
|
|
|
{ USBASP_ISP_SCK_8, 8000 },
|
|
|
|
{ USBASP_ISP_SCK_4, 4000 },
|
|
|
|
{ USBASP_ISP_SCK_2, 2000 },
|
|
|
|
{ USBASP_ISP_SCK_1, 1000 },
|
|
|
|
{ USBASP_ISP_SCK_0_5, 500 }
|
2009-02-28 13:10:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set sck period (in seconds)
|
|
|
|
* Find next possible sck period and write it to the programmer.
|
|
|
|
*/
|
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 usbasp_spi_set_sck_period(const PROGRAMMER *pgm, double sckperiod) {
|
2009-02-28 13:10:47 +00:00
|
|
|
char clockoption = USBASP_ISP_SCK_AUTO;
|
|
|
|
unsigned char res[4];
|
|
|
|
unsigned char cmd[4];
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_debug("usbasp_spi_set_sck_period(%g)\n", sckperiod);
|
2013-09-02 06:43:06 +00:00
|
|
|
|
2009-02-28 13:10:47 +00:00
|
|
|
memset(cmd, 0, sizeof(cmd));
|
|
|
|
memset(res, 0, sizeof(res));
|
|
|
|
|
2010-01-08 18:33:23 +00:00
|
|
|
/* reset global sck frequency to auto */
|
|
|
|
PDATA(pgm)->sckfreq_hz = 0;
|
|
|
|
|
2009-02-28 13:10:47 +00:00
|
|
|
if (sckperiod == 0) {
|
|
|
|
/* auto sck set */
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_notice("auto set sck period (because given equals null)\n");
|
2009-02-28 13:10:47 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2010-01-08 18:33:23 +00:00
|
|
|
int sckfreq = 1 / sckperiod; /* sck in Hz */
|
|
|
|
int usefreq = 0;
|
2009-02-28 13:10:47 +00:00
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_notice2("try to set SCK period to %g s (= %i Hz)\n", sckperiod, sckfreq);
|
2009-02-28 13:10:47 +00:00
|
|
|
|
2020-09-18 21:52:12 +00:00
|
|
|
/* Check if programmer is capable of 3 MHz SCK, if not then ommit 3 MHz setting */
|
|
|
|
int i;
|
|
|
|
if (PDATA(pgm)->sck_3mhz) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_notice2("connected USBasp is capable of 3 MHz SCK\n");
|
2020-09-18 21:52:12 +00:00
|
|
|
i = 0;
|
|
|
|
} else {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_notice2("connected USBasp is not cabable of 3 MHz SCK\n");
|
2020-09-18 21:52:12 +00:00
|
|
|
i = 1;
|
|
|
|
}
|
|
|
|
if (sckfreq >= usbaspSCKoptions[i].frequency) {
|
|
|
|
clockoption = usbaspSCKoptions[i].id;
|
|
|
|
usefreq = usbaspSCKoptions[i].frequency;
|
2009-02-28 13:10:47 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
/* find clock option next to given clock */
|
2020-09-18 21:52:12 +00:00
|
|
|
|
|
|
|
for (; i < sizeof(usbaspSCKoptions) / sizeof(usbaspSCKoptions[0]); i++) {
|
2010-01-08 18:33:23 +00:00
|
|
|
if (sckfreq >= usbaspSCKoptions[i].frequency - 1) { /* subtract 1 to compensate round errors */
|
2009-02-28 13:10:47 +00:00
|
|
|
clockoption = usbaspSCKoptions[i].id;
|
|
|
|
usefreq = usbaspSCKoptions[i].frequency;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-08 18:33:23 +00:00
|
|
|
/* save used sck frequency */
|
|
|
|
PDATA(pgm)->sckfreq_hz = usefreq;
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_info("set SCK frequency to %i Hz\n", usefreq);
|
2009-02-28 13:10:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd[0] = clockoption;
|
|
|
|
|
|
|
|
int nbytes =
|
|
|
|
usbasp_transmit(pgm, 1, USBASP_FUNC_SETISPSCK, cmd, res, sizeof(res));
|
|
|
|
|
|
|
|
if ((nbytes != 1) | (res[0] != 0)) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("cannot set sck period; please check for usbasp firmware update\n");
|
2009-02-28 13:10:47 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-28 07:35:40 +00:00
|
|
|
/* TPI specific functions */
|
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 void usbasp_tpi_send_byte(const PROGRAMMER *pgm, uint8_t b) {
|
2011-05-28 07:35:40 +00:00
|
|
|
unsigned char temp[4];
|
|
|
|
memset(temp, 0, sizeof(temp));
|
|
|
|
|
|
|
|
temp[0] = b;
|
|
|
|
|
|
|
|
usbasp_transmit(pgm, 1, USBASP_FUNC_TPI_RAWWRITE, temp, temp, sizeof(temp));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 usbasp_tpi_recv_byte(const PROGRAMMER *pgm) {
|
2011-05-28 07:35:40 +00:00
|
|
|
unsigned char temp[4];
|
|
|
|
memset(temp, 0, sizeof(temp));
|
|
|
|
|
|
|
|
if(usbasp_transmit(pgm, 1, USBASP_FUNC_TPI_RAWREAD, temp, temp, sizeof(temp)) != 1)
|
|
|
|
{
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("wrong response size\n");
|
2011-05-28 07:35:40 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return temp[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 usbasp_tpi_nvm_waitbusy(const PROGRAMMER *pgm) {
|
2011-05-28 07:35:40 +00:00
|
|
|
int retry;
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_debug("usbasp_tpi_nvm_waitbusy() ...");
|
2011-05-28 07:35:40 +00:00
|
|
|
|
|
|
|
for(retry=50; retry>0; retry--)
|
|
|
|
{
|
|
|
|
usbasp_tpi_send_byte(pgm, TPI_OP_SIN(NVMCSR));
|
|
|
|
if(usbasp_tpi_recv_byte(pgm) & NVMCSR_BSY)
|
|
|
|
continue;
|
2013-09-01 20:48:17 +00:00
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_debug(" ready\n");
|
2013-09-01 20:48:17 +00:00
|
|
|
|
2011-05-28 07:35:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2013-09-01 20:48:17 +00:00
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_debug(" failure\n");
|
2013-09-01 20:48:17 +00:00
|
|
|
|
2011-05-28 07:35:40 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
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 usbasp_tpi_cmd(const PROGRAMMER *pgm, const unsigned char *cmd, unsigned char *res) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("spi_cmd used in TPI mode: not allowed\n");
|
2011-05-28 07:35:40 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
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 usbasp_tpi_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
|
2011-05-28 07:35:40 +00:00
|
|
|
int retry;
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_debug("usbasp_tpi_program_enable()\n");
|
2013-09-01 20:48:17 +00:00
|
|
|
|
2011-05-28 07:35:40 +00:00
|
|
|
/* change guard time */
|
|
|
|
usbasp_tpi_send_byte(pgm, TPI_OP_SSTCS(TPIPCR));
|
|
|
|
usbasp_tpi_send_byte(pgm, TPIPCR_GT_2b);
|
|
|
|
|
|
|
|
/* send SKEY */
|
|
|
|
usbasp_tpi_send_byte(pgm, 0xE0);
|
|
|
|
usbasp_tpi_send_byte(pgm, 0xFF);
|
|
|
|
usbasp_tpi_send_byte(pgm, 0x88);
|
|
|
|
usbasp_tpi_send_byte(pgm, 0xD8);
|
|
|
|
usbasp_tpi_send_byte(pgm, 0xCD);
|
|
|
|
usbasp_tpi_send_byte(pgm, 0x45);
|
|
|
|
usbasp_tpi_send_byte(pgm, 0xAB);
|
|
|
|
usbasp_tpi_send_byte(pgm, 0x89);
|
|
|
|
usbasp_tpi_send_byte(pgm, 0x12);
|
|
|
|
|
|
|
|
/* check if device is ready */
|
|
|
|
for(retry=0; retry<10; retry++)
|
|
|
|
{
|
|
|
|
usbasp_tpi_send_byte(pgm, TPI_OP_SLDCS(TPIIR));
|
|
|
|
if(usbasp_tpi_recv_byte(pgm) != 0x80)
|
|
|
|
continue;
|
|
|
|
usbasp_tpi_send_byte(pgm, TPI_OP_SLDCS(TPISR));
|
|
|
|
if((usbasp_tpi_recv_byte(pgm) & TPISR_NVMEN) == 0)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(retry >= 10)
|
|
|
|
{
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("program enable, target does not answer\n");
|
2011-05-28 07:35:40 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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 usbasp_tpi_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
|
2018-01-16 22:40:28 +00:00
|
|
|
int pr_0;
|
|
|
|
int pr_1;
|
|
|
|
int nvm_cmd;
|
|
|
|
|
|
|
|
switch (PDATA(pgm)->section_e) {
|
|
|
|
/* Config bits section erase */
|
|
|
|
case 1:
|
|
|
|
pr_0 = 0x41;
|
|
|
|
pr_1 = 0x3F;
|
|
|
|
nvm_cmd = NVMCMD_SECTION_ERASE;
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_debug("usbasp_tpi_chip_erase() - section erase\n");
|
2018-01-16 22:40:28 +00:00
|
|
|
break;
|
|
|
|
/* Chip erase (flash only) */
|
|
|
|
default:
|
|
|
|
pr_0 = 0x01;
|
|
|
|
pr_1 = 0x40;
|
|
|
|
nvm_cmd = NVMCMD_CHIP_ERASE;
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_debug("usbasp_tpi_chip_erase() - chip erase\n");
|
2018-01-16 22:40:28 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-09-01 20:48:17 +00:00
|
|
|
|
2018-01-16 22:40:28 +00:00
|
|
|
/* Set PR */
|
2011-05-28 07:35:40 +00:00
|
|
|
usbasp_tpi_send_byte(pgm, TPI_OP_SSTPR(0));
|
2018-01-16 22:40:28 +00:00
|
|
|
usbasp_tpi_send_byte(pgm, pr_0);
|
2011-05-28 07:35:40 +00:00
|
|
|
usbasp_tpi_send_byte(pgm, TPI_OP_SSTPR(1));
|
2018-01-16 22:40:28 +00:00
|
|
|
usbasp_tpi_send_byte(pgm, pr_1);
|
|
|
|
/* select what been erase */
|
2011-05-28 07:35:40 +00:00
|
|
|
usbasp_tpi_send_byte(pgm, TPI_OP_SOUT(NVMCMD));
|
2018-01-16 22:40:28 +00:00
|
|
|
usbasp_tpi_send_byte(pgm, nvm_cmd);
|
2011-05-28 07:35:40 +00:00
|
|
|
/* dummy write */
|
|
|
|
usbasp_tpi_send_byte(pgm, TPI_OP_SST_INC);
|
|
|
|
usbasp_tpi_send_byte(pgm, 0x00);
|
|
|
|
usbasp_tpi_nvm_waitbusy(pgm);
|
2018-01-16 22:40:28 +00:00
|
|
|
|
2011-05-28 07:35:40 +00:00
|
|
|
usleep(p->chip_erase_delay);
|
|
|
|
pgm->initialize(pgm, p);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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 usbasp_tpi_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
|
|
|
unsigned int page_size, unsigned int addr, unsigned int n_bytes) {
|
|
|
|
|
2011-05-28 07:35:40 +00:00
|
|
|
unsigned char cmd[4];
|
|
|
|
unsigned char* dptr;
|
|
|
|
int readed, clen, n;
|
|
|
|
uint16_t pr;
|
|
|
|
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_debug("usbasp_tpi_paged_load(\"%s\", 0x%0x, %d)\n", m->desc, addr, n_bytes);
|
2013-09-01 20:48:17 +00:00
|
|
|
|
2013-09-01 20:54:56 +00:00
|
|
|
dptr = addr + m->buf;
|
2011-09-14 21:49:42 +00:00
|
|
|
pr = addr + m->offset;
|
2011-05-28 07:35:40 +00:00
|
|
|
readed = 0;
|
|
|
|
|
|
|
|
while(readed < n_bytes)
|
|
|
|
{
|
|
|
|
clen = n_bytes - readed;
|
|
|
|
if(clen > 32)
|
|
|
|
clen = 32;
|
|
|
|
|
|
|
|
/* prepare READBLOCK cmd */
|
|
|
|
cmd[0] = pr & 0xFF;
|
|
|
|
cmd[1] = pr >> 8;
|
|
|
|
cmd[2] = 0;
|
|
|
|
cmd[3] = 0;
|
|
|
|
n = usbasp_transmit(pgm, 1, USBASP_FUNC_TPI_READBLOCK, cmd, dptr, clen);
|
|
|
|
if(n != clen)
|
|
|
|
{
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("wrong reading bytes %x\n", n);
|
2011-05-28 07:35:40 +00:00
|
|
|
return -3;
|
|
|
|
}
|
|
|
|
|
|
|
|
readed += clen;
|
|
|
|
pr += clen;
|
|
|
|
dptr += clen;
|
|
|
|
}
|
|
|
|
|
|
|
|
return n_bytes;
|
|
|
|
}
|
|
|
|
|
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 usbasp_tpi_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
|
|
|
unsigned int page_size, unsigned int addr, unsigned int n_bytes) {
|
|
|
|
|
2011-05-28 07:35:40 +00:00
|
|
|
unsigned char cmd[4];
|
|
|
|
unsigned char* sptr;
|
|
|
|
int writed, clen, n;
|
|
|
|
uint16_t pr;
|
|
|
|
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_debug("usbasp_tpi_paged_write(\"%s\", 0x%0x, %d)\n", m->desc, addr, n_bytes);
|
2013-09-01 20:48:17 +00:00
|
|
|
|
2013-09-01 20:54:56 +00:00
|
|
|
sptr = addr + m->buf;
|
2011-09-14 21:49:42 +00:00
|
|
|
pr = addr + m->offset;
|
2011-05-28 07:35:40 +00:00
|
|
|
writed = 0;
|
|
|
|
|
2021-11-07 20:10:24 +00:00
|
|
|
/* must erase fuse first */
|
|
|
|
if(strcmp(m->desc, "fuse") == 0)
|
|
|
|
{
|
|
|
|
/* Set PR */
|
|
|
|
usbasp_tpi_send_byte(pgm, TPI_OP_SSTPR(0));
|
|
|
|
usbasp_tpi_send_byte(pgm, (pr & 0xFF) | 1 );
|
|
|
|
usbasp_tpi_send_byte(pgm, TPI_OP_SSTPR(1));
|
|
|
|
usbasp_tpi_send_byte(pgm, (pr >> 8) );
|
|
|
|
/* select SECTION_ERASE */
|
|
|
|
usbasp_tpi_send_byte(pgm, TPI_OP_SOUT(NVMCMD));
|
|
|
|
usbasp_tpi_send_byte(pgm, NVMCMD_SECTION_ERASE);
|
|
|
|
/* dummy write */
|
|
|
|
usbasp_tpi_send_byte(pgm, TPI_OP_SST_INC);
|
|
|
|
usbasp_tpi_send_byte(pgm, 0x00);
|
|
|
|
|
|
|
|
usbasp_tpi_nvm_waitbusy(pgm);
|
|
|
|
}
|
|
|
|
|
2011-05-28 07:35:40 +00:00
|
|
|
/* Set PR to flash */
|
|
|
|
usbasp_tpi_send_byte(pgm, TPI_OP_SSTPR(0));
|
|
|
|
usbasp_tpi_send_byte(pgm, (pr & 0xFF) | 1 );
|
|
|
|
usbasp_tpi_send_byte(pgm, TPI_OP_SSTPR(1));
|
|
|
|
usbasp_tpi_send_byte(pgm, (pr >> 8) );
|
|
|
|
|
|
|
|
while(writed < n_bytes)
|
|
|
|
{
|
|
|
|
clen = n_bytes - writed;
|
|
|
|
if(clen > 32)
|
|
|
|
clen = 32;
|
|
|
|
|
|
|
|
/* prepare WRITEBLOCK cmd */
|
|
|
|
cmd[0] = pr & 0xFF;
|
|
|
|
cmd[1] = pr >> 8;
|
|
|
|
cmd[2] = 0;
|
|
|
|
cmd[3] = 0;
|
|
|
|
n = usbasp_transmit(pgm, 0, USBASP_FUNC_TPI_WRITEBLOCK, cmd, sptr, clen);
|
|
|
|
if(n != clen)
|
|
|
|
{
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("wrong count at writing %x\n", n);
|
2011-05-28 07:35:40 +00:00
|
|
|
return -3;
|
|
|
|
}
|
|
|
|
|
|
|
|
writed += clen;
|
|
|
|
pr += clen;
|
|
|
|
sptr += clen;
|
|
|
|
}
|
|
|
|
|
|
|
|
return n_bytes;
|
|
|
|
}
|
|
|
|
|
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 usbasp_tpi_set_sck_period(const PROGRAMMER *pgm, double sckperiod) {
|
2011-05-28 07:35:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
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 usbasp_tpi_read_byte(const PROGRAMMER * pgm, const AVRPART *p, const AVRMEM *m, unsigned long addr, unsigned char *value) {
|
2011-05-28 07:35:40 +00:00
|
|
|
unsigned char cmd[4];
|
|
|
|
int n;
|
|
|
|
uint16_t pr;
|
|
|
|
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_debug("usbasp_tpi_read_byte(\"%s\", 0x%0lx)\n", m->desc, addr);
|
2013-09-01 20:48:17 +00:00
|
|
|
|
2011-05-28 07:35:40 +00:00
|
|
|
pr = m->offset + addr;
|
|
|
|
|
|
|
|
/* READBLOCK */
|
|
|
|
cmd[0] = pr & 0xFF;
|
|
|
|
cmd[1] = pr >> 8;
|
|
|
|
cmd[2] = 0;
|
|
|
|
cmd[3] = 0;
|
|
|
|
n = usbasp_transmit(pgm, 1, USBASP_FUNC_TPI_READBLOCK, cmd, value, 1);
|
|
|
|
if(n != 1)
|
|
|
|
{
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("wrong reading bytes %x\n", n);
|
2011-05-28 07:35:40 +00:00
|
|
|
return -3;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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 usbasp_tpi_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
|
|
|
unsigned long addr, unsigned char data) { // FIXME: use avr_write_byte_cache() when implemented
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("usbasp_write_byte in TPI mode; all writes have to be done at page level\n");
|
2011-05-28 07:35:40 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-02-28 13:10:47 +00:00
|
|
|
|
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 usbasp_initpgm(PROGRAMMER *pgm) {
|
2006-09-10 20:41:00 +00:00
|
|
|
strcpy(pgm->type, "usbasp");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* mandatory functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
pgm->initialize = usbasp_initialize;
|
|
|
|
pgm->display = usbasp_display;
|
|
|
|
pgm->enable = usbasp_enable;
|
|
|
|
pgm->disable = usbasp_disable;
|
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
|
|
|
pgm->program_enable = usbasp_program_enable;
|
|
|
|
pgm->chip_erase = usbasp_chip_erase;
|
|
|
|
pgm->cmd = usbasp_cmd;
|
2006-09-10 20:41:00 +00:00
|
|
|
pgm->open = usbasp_open;
|
|
|
|
pgm->close = usbasp_close;
|
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
|
|
|
pgm->read_byte = usbasp_read_byte;
|
|
|
|
pgm->write_byte = usbasp_write_byte;
|
2006-09-10 20:41:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* optional functions
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
pgm->paged_write = usbasp_paged_write;
|
|
|
|
pgm->paged_load = usbasp_paged_load;
|
main.c, pgm.c, pgm.h: Add setup and teardown hooks to the programmer
definition. If present, call the setup hook immediately after finding
the respective programmer object, and schedule the teardown hook to be
called upon exit. This allows the programmer implementation to
dynamically allocate private programmer data.
avr910.c, butterfly.c, jtagmkI.c, jtagmkII.c, stk500v2.c, usbasp.c,
usbtiny.c: Convert static programmer data into dynamically allocated
data.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@764 81a1dc3b-b13d-400b-aceb-764788c761c2
2007-11-07 20:36:12 +00:00
|
|
|
pgm->setup = usbasp_setup;
|
|
|
|
pgm->teardown = usbasp_teardown;
|
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
|
|
|
pgm->set_sck_period = usbasp_set_sck_period;
|
2018-01-16 22:40:28 +00:00
|
|
|
pgm->parseextparams = usbasp_parseextparms;
|
2006-09-10 20:41:00 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#else /* HAVE_LIBUSB */
|
|
|
|
|
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 usbasp_nousb_open(PROGRAMMER *pgm, const char *name) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("no usb support; please compile again with libusb installed\n");
|
2006-09-10 20:41:00 +00:00
|
|
|
|
2010-04-25 12:36:36 +00:00
|
|
|
return -1;
|
2006-09-10 20:41:00 +00:00
|
|
|
}
|
|
|
|
|
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 usbasp_initpgm(PROGRAMMER *pgm) {
|
2006-09-10 20:41:00 +00:00
|
|
|
strcpy(pgm->type, "usbasp");
|
|
|
|
|
|
|
|
pgm->open = usbasp_nousb_open;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_LIBUSB */
|
2012-01-31 17:03:43 +00:00
|
|
|
|
|
|
|
const char usbasp_desc[] = "USBasp programmer, see http://www.fischl.de/usbasp/";
|
|
|
|
|