2009-10-08 02:05:03 +00:00
|
|
|
/*
|
|
|
|
* avrdude - A Downloader/Uploader for AVR device programmers
|
|
|
|
*
|
|
|
|
* avrdude support for The Bus Pirate - universal serial interface
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Michal Ludvig <mludvig@logix.net.nz>
|
|
|
|
*
|
|
|
|
* 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/>.
|
2009-10-08 02:05:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* BusPirate AVR Chip
|
|
|
|
* --------- --------
|
|
|
|
* GND <-> GND
|
|
|
|
* +5V <-> Vcc
|
|
|
|
* CS <-> RESET
|
|
|
|
* MOSI <-> MOSI
|
|
|
|
* MISO <-> MISO
|
|
|
|
* SCL/CLK <-> SCK
|
2012-01-31 19:01:00 +00:00
|
|
|
* ( AUX <-> XTAL1 )
|
2009-10-08 02:05:03 +00:00
|
|
|
*
|
|
|
|
* Tested with BusPirate PTH, firmware version 2.1 programming ATmega328P
|
|
|
|
*/
|
|
|
|
|
2010-01-07 13:16:38 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-10-08 02:05:03 +00:00
|
|
|
#include "ac_cfg.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "avrdude.h"
|
2014-05-19 10:01:59 +00:00
|
|
|
#include "libavrdude.h"
|
|
|
|
|
2013-01-30 21:15:39 +00:00
|
|
|
#include "bitbang.h"
|
2012-11-04 17:18:59 +00:00
|
|
|
#include "buspirate.h"
|
2009-10-08 02:05:03 +00:00
|
|
|
|
2009-11-04 03:14:17 +00:00
|
|
|
/* ====== Private data structure ====== */
|
2010-01-07 13:30:44 +00:00
|
|
|
/* CS and AUX pin bitmasks in
|
|
|
|
* 0100wxyz - Configure peripherals command */
|
2009-11-09 02:18:40 +00:00
|
|
|
#define BP_RESET_CS 0x01
|
|
|
|
#define BP_RESET_AUX 0x02
|
|
|
|
#define BP_RESET_AUX2 0x04
|
|
|
|
|
|
|
|
#define BP_FLAG_IN_BINMODE (1<<0)
|
|
|
|
#define BP_FLAG_XPARM_FORCE_ASCII (1<<1)
|
|
|
|
#define BP_FLAG_XPARM_RESET (1<<2)
|
|
|
|
#define BP_FLAG_XPARM_SPIFREQ (1<<3)
|
2012-01-31 19:01:00 +00:00
|
|
|
#define BP_FLAG_NOPAGEDWRITE (1<<4)
|
|
|
|
#define BP_FLAG_XPARM_CPUFREQ (1<<5)
|
2013-01-30 17:58:48 +00:00
|
|
|
#define BP_FLAG_XPARM_RAWFREQ (1<<6)
|
2013-01-30 18:56:31 +00:00
|
|
|
#define BP_FLAG_NOPAGEDREAD (1<<7)
|
2009-11-09 02:18:40 +00:00
|
|
|
|
2009-11-04 03:14:17 +00:00
|
|
|
struct pdata
|
|
|
|
{
|
2010-01-07 13:30:44 +00:00
|
|
|
int binmode_version;
|
2013-01-30 17:58:48 +00:00
|
|
|
int submode_version;
|
2010-01-07 13:30:44 +00:00
|
|
|
int current_peripherals_config;
|
2013-01-30 17:58:48 +00:00
|
|
|
int spifreq; /* For "set speed" commands */
|
2012-01-31 19:01:00 +00:00
|
|
|
int cpufreq; /* (125)..4000 kHz - see buspirate manual */
|
2014-11-13 13:53:47 +00:00
|
|
|
int serial_recv_timeout; /* timeout in ms, default 100 */
|
2010-01-07 13:30:44 +00:00
|
|
|
int reset; /* See BP_RESET_* above */
|
2013-01-30 21:15:39 +00:00
|
|
|
unsigned char pin_dir; /* Last written pin direction for bitbang mode */
|
|
|
|
unsigned char pin_val; /* Last written pin values for bitbang mode */
|
|
|
|
int unread_bytes; /* How many bytes we expected, but ignored */
|
2022-08-21 23:00:39 +00:00
|
|
|
int flag;
|
2009-11-04 03:14:17 +00:00
|
|
|
};
|
|
|
|
#define PDATA(pgm) ((struct pdata *)(pgm->cookie))
|
|
|
|
|
2009-11-09 02:18:40 +00:00
|
|
|
/* ====== Feature checks ====== */
|
|
|
|
static inline int
|
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
|
|
|
buspirate_uses_ascii(const PROGRAMMER *pgm) {
|
|
|
|
return (PDATA(pgm)->flag & BP_FLAG_XPARM_FORCE_ASCII);
|
2009-11-09 02:18:40 +00:00
|
|
|
}
|
|
|
|
|
2009-11-04 03:14:17 +00:00
|
|
|
/* ====== Serial talker functions - binmode ====== */
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
static void dump_mem(const unsigned char *buf, size_t len)
|
2009-11-04 03:14:17 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i<len; i++) {
|
|
|
|
if (i % 8 == 0)
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_debug("\t");
|
|
|
|
msg_debug("0x%02x ", buf[i]);
|
2009-11-04 03:14:17 +00:00
|
|
|
if (i % 8 == 3)
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_debug(" ");
|
2009-11-04 03:14:17 +00:00
|
|
|
else if (i % 8 == 7)
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_debug("\n");
|
2009-11-04 03:14:17 +00:00
|
|
|
}
|
|
|
|
if (i % 8 != 7)
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_debug("\n");
|
2009-11-04 03:14:17 +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
|
|
|
static int buspirate_send_bin(const PROGRAMMER *pgm, const unsigned char *data, size_t len) {
|
2009-11-04 03:14:17 +00:00
|
|
|
int rc;
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_debug("buspirate_send_bin():\n");
|
|
|
|
dump_mem(data, len);
|
2009-11-04 03:14:17 +00:00
|
|
|
|
2014-07-16 20:02:01 +00:00
|
|
|
rc = serial_send(&pgm->fd, data, len);
|
2009-11-04 03:14:17 +00:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
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 buspirate_recv_bin(const PROGRAMMER *pgm, unsigned char *buf, size_t len) {
|
2009-11-04 03:14:17 +00:00
|
|
|
int rc;
|
|
|
|
|
2014-07-16 20:02:01 +00:00
|
|
|
rc = serial_recv(&pgm->fd, buf, len);
|
2009-11-04 03:14:17 +00:00
|
|
|
if (rc < 0)
|
|
|
|
return EOF;
|
2014-07-16 20:02:01 +00:00
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_debug("buspirate_recv_bin():\n");
|
|
|
|
dump_mem(buf, len);
|
2009-11-04 03:14:17 +00:00
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
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 buspirate_expect_bin(const PROGRAMMER *pgm,
|
2014-07-16 20:02:01 +00:00
|
|
|
unsigned char *send_data, size_t send_len,
|
|
|
|
unsigned char *expect_data, size_t expect_len)
|
2009-11-04 03:14:17 +00:00
|
|
|
{
|
2014-07-16 20:02:01 +00:00
|
|
|
unsigned char *recv_buf = alloca(expect_len);
|
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
|
|
|
if ((PDATA(pgm)->flag & BP_FLAG_IN_BINMODE) == 0) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("called from ascii mode\n");
|
2014-05-16 15:52:25 +00:00
|
|
|
return -1;
|
2009-11-04 03:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
buspirate_send_bin(pgm, send_data, send_len);
|
|
|
|
buspirate_recv_bin(pgm, recv_buf, expect_len);
|
|
|
|
if (memcmp(expect_data, recv_buf, expect_len) != 0)
|
|
|
|
return 0;
|
|
|
|
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 buspirate_expect_bin_byte(const PROGRAMMER *pgm,
|
2014-07-16 20:02:01 +00:00
|
|
|
unsigned char send_byte, unsigned char expect_byte)
|
2009-11-04 03:14:17 +00:00
|
|
|
{
|
|
|
|
return buspirate_expect_bin(pgm, &send_byte, 1, &expect_byte, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ====== Serial talker functions - ascii mode ====== */
|
2009-10-08 02:05:03 +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
|
|
|
static int buspirate_getc(const PROGRAMMER *pgm) {
|
2009-10-08 02:05:03 +00:00
|
|
|
int rc;
|
|
|
|
unsigned char ch = 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
|
|
|
if (PDATA(pgm)->flag & BP_FLAG_IN_BINMODE) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("called from binmode\n");
|
2014-05-16 15:52:25 +00:00
|
|
|
return EOF;
|
2009-11-04 03:14:17 +00:00
|
|
|
}
|
|
|
|
|
2009-10-08 02:05:03 +00:00
|
|
|
rc = serial_recv(&pgm->fd, &ch, 1);
|
|
|
|
if (rc < 0)
|
|
|
|
return EOF;
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
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 char *buspirate_readline_noexit(const PROGRAMMER *pgm, char *buf, size_t len) {
|
2009-10-08 02:05:03 +00:00
|
|
|
char *buf_p;
|
2022-01-04 12:48:11 +00:00
|
|
|
int c;
|
2009-10-08 02:05:03 +00:00
|
|
|
long orig_serial_recv_timeout = serial_recv_timeout;
|
|
|
|
|
|
|
|
/* Static local buffer - this may come handy at times */
|
|
|
|
static char buf_local[100];
|
|
|
|
|
|
|
|
if (buf == NULL) {
|
|
|
|
buf = buf_local;
|
|
|
|
len = sizeof(buf_local);
|
|
|
|
}
|
|
|
|
buf_p = buf;
|
|
|
|
memset(buf, 0, len);
|
|
|
|
while (buf_p < (buf + len - 1)) { /* keep the very last byte == 0 */
|
2022-01-04 12:48:11 +00:00
|
|
|
*buf_p = c = buspirate_getc(pgm);
|
|
|
|
if (c == '\r')
|
2009-10-08 02:05:03 +00:00
|
|
|
continue;
|
2022-01-04 12:48:11 +00:00
|
|
|
if (c == '\n')
|
2009-10-08 02:05:03 +00:00
|
|
|
break;
|
2022-01-04 12:48:11 +00:00
|
|
|
if (c == EOF) {
|
2009-10-08 02:05:03 +00:00
|
|
|
*buf_p = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
buf_p++;
|
2012-01-31 19:01:00 +00:00
|
|
|
serial_recv_timeout = PDATA(pgm)->serial_recv_timeout;
|
2009-10-08 02:05:03 +00:00
|
|
|
}
|
|
|
|
serial_recv_timeout = orig_serial_recv_timeout;
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_debug("buspirate_readline(): %s%s", buf, *buf && buf[strlen(buf)-1] == '\n'? "": "\n");
|
2010-01-11 12:19:15 +00:00
|
|
|
if (! buf[0])
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
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 char *buspirate_readline(const PROGRAMMER *pgm, char *buf, size_t len) {
|
2010-01-11 12:19:15 +00:00
|
|
|
char *ret;
|
2014-05-16 15:52:25 +00:00
|
|
|
|
2010-01-11 12:19:15 +00:00
|
|
|
ret = buspirate_readline_noexit(pgm, buf, len);
|
|
|
|
if (! ret) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("programmer is not responding\n");
|
2014-05-16 15:52:25 +00:00
|
|
|
return NULL;
|
2009-10-08 02:05:03 +00:00
|
|
|
}
|
2010-01-11 12:19:15 +00:00
|
|
|
return ret;
|
2009-10-08 02:05:03 +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
|
|
|
static int buspirate_send(const PROGRAMMER *pgm, const char *str) {
|
2009-10-08 02:05:03 +00:00
|
|
|
int rc;
|
2014-11-13 13:53:47 +00:00
|
|
|
const char * readline;
|
2009-10-08 02:05:03 +00:00
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_debug("buspirate_send(): %s", str);
|
2009-10-08 02:05:03 +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
|
|
|
if (PDATA(pgm)->flag & BP_FLAG_IN_BINMODE) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("called from binmode\n");
|
2014-05-16 15:52:25 +00:00
|
|
|
return -1;
|
2009-11-04 03:14:17 +00:00
|
|
|
}
|
|
|
|
|
2014-07-16 20:02:01 +00:00
|
|
|
rc = serial_send(&pgm->fd, (const unsigned char*)str, strlen(str));
|
2009-10-08 02:05:03 +00:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
2014-11-13 13:53:47 +00:00
|
|
|
do {
|
|
|
|
readline = buspirate_readline(pgm, NULL, 0);
|
|
|
|
if (readline == NULL)
|
|
|
|
return -1;
|
|
|
|
/* keep reading until we get what we sent there */
|
|
|
|
} while (strcmp(readline, str) != 0);
|
|
|
|
|
2009-10-08 02:05:03 +00:00
|
|
|
/* by now we should be in sync */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-16 20:02:01 +00:00
|
|
|
static int buspirate_is_prompt(const char *str)
|
2009-10-08 02:05:03 +00:00
|
|
|
{
|
2014-07-16 20:02:01 +00:00
|
|
|
int strlen_str = strlen(str);
|
2010-07-18 13:15:07 +00:00
|
|
|
/* Prompt ends with '>' or '> '
|
|
|
|
* all other input probably ends with '\n' */
|
2014-07-16 20:02:01 +00:00
|
|
|
return (str[strlen_str - 1] == '>' || str[strlen_str - 2] == '>');
|
2009-10-08 02:05:03 +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
|
|
|
static int buspirate_expect(const PROGRAMMER *pgm, char *send,
|
2010-01-07 13:30:44 +00:00
|
|
|
char *expect, int wait_for_prompt)
|
2009-10-08 02:05:03 +00:00
|
|
|
{
|
|
|
|
int got_it = 0;
|
|
|
|
size_t expect_len = strlen(expect);
|
|
|
|
char *rcvd;
|
|
|
|
|
|
|
|
buspirate_send(pgm, send);
|
|
|
|
while (1) {
|
|
|
|
rcvd = buspirate_readline(pgm, NULL, 0);
|
2014-11-13 13:53:47 +00:00
|
|
|
if (rcvd == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
2013-01-30 18:56:31 +00:00
|
|
|
if (strncmp(rcvd, expect, expect_len) == 0) {
|
|
|
|
if (! wait_for_prompt) {
|
|
|
|
serial_drain(&pgm->fd, 0);
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
got_it = 1;
|
|
|
|
}
|
|
|
|
}
|
2009-10-08 02:05:03 +00:00
|
|
|
|
|
|
|
if (buspirate_is_prompt(rcvd))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return got_it;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ====== Do-nothing 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 buspirate_dummy_6(const PROGRAMMER *pgm, const char *p) {
|
2009-10-08 02:05:03 +00:00
|
|
|
}
|
|
|
|
|
2009-11-09 02:18:40 +00:00
|
|
|
/* ====== Config / parameters handling functions ====== */
|
|
|
|
static int
|
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
|
|
|
buspirate_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) {
|
2009-11-09 02:18:40 +00:00
|
|
|
LNODEID ln;
|
|
|
|
const char *extended_param;
|
|
|
|
char reset[10];
|
2014-11-13 13:53:47 +00:00
|
|
|
char *preset = reset; /* for strtok() */
|
|
|
|
unsigned int spifreq;
|
|
|
|
unsigned int rawfreq;
|
|
|
|
unsigned int cpufreq;
|
2012-01-31 19:01:00 +00:00
|
|
|
int serial_recv_timeout;
|
2009-11-09 02:18:40 +00:00
|
|
|
|
|
|
|
for (ln = lfirst(extparms); ln; ln = lnext(ln)) {
|
2014-07-16 20:02:01 +00:00
|
|
|
extended_param = ldata(ln);
|
2009-11-09 02:18:40 +00:00
|
|
|
if (strcmp(extended_param, "ascii") == 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
|
|
|
PDATA(pgm)->flag |= BP_FLAG_XPARM_FORCE_ASCII;
|
2009-11-09 02:18:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
2014-11-13 13:53:47 +00:00
|
|
|
|
|
|
|
if (sscanf(extended_param, "spifreq=%u", &spifreq) == 1) {
|
2009-11-09 02:18:40 +00:00
|
|
|
if (spifreq & (~0x07)) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("spifreq must be between 0 and 7\n");
|
|
|
|
imsg_error("see BusPirate manual for details\n");
|
2009-11-09 02:18: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
|
|
|
if (PDATA(pgm)->flag & BP_FLAG_XPARM_RAWFREQ) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("set either spifreq or rawfreq\n");
|
2014-11-13 13:53:47 +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
|
|
|
PDATA(pgm)->flag |= BP_FLAG_XPARM_SPIFREQ;
|
2009-11-09 02:18:40 +00:00
|
|
|
PDATA(pgm)->spifreq = spifreq;
|
2013-01-30 17:58:48 +00:00
|
|
|
continue;
|
|
|
|
}
|
2014-11-13 13:53:47 +00:00
|
|
|
|
2013-01-30 17:58:48 +00:00
|
|
|
if (sscanf(extended_param, "rawfreq=%u", &rawfreq) == 1) {
|
|
|
|
if (rawfreq >= 4) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("rawfreq must be between 0 and 3\n");
|
2013-01-30 17:58:48 +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
|
|
|
if (PDATA(pgm)->flag & BP_FLAG_XPARM_SPIFREQ) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("set either spifreq or rawfreq\n");
|
2014-11-13 13:53:47 +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
|
|
|
PDATA(pgm)->flag |= BP_FLAG_XPARM_RAWFREQ;
|
2013-01-30 17:58:48 +00:00
|
|
|
PDATA(pgm)->spifreq = rawfreq;
|
2009-11-09 02:18:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-11-13 13:53:47 +00:00
|
|
|
if (sscanf(extended_param, "cpufreq=%u", &cpufreq) == 1) {
|
2012-01-31 19:01:00 +00:00
|
|
|
/* lower limit comes from 'cpufreq > 4 * spifreq', spifreq in ascii mode is 30kHz. */
|
|
|
|
if (cpufreq < 125 || cpufreq > 4000) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("cpufreq must be between 125 and 4000 kHz\n");
|
|
|
|
imsg_error("see BusPirate manual for details\n");
|
2012-01-31 19:01:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
PDATA(pgm)->cpufreq = cpufreq;
|
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
|
|
|
PDATA(pgm)->flag |= BP_FLAG_XPARM_CPUFREQ;
|
2012-01-31 19:01:00 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-07-16 20:02:01 +00:00
|
|
|
if (sscanf(extended_param, "reset=%9s", reset) == 1) {
|
2009-11-09 02:18:40 +00:00
|
|
|
char *resetpin;
|
|
|
|
while ((resetpin = strtok(preset, ","))) {
|
2014-11-13 13:53:47 +00:00
|
|
|
preset = NULL; /* for subsequent strtok() calls */
|
2009-11-09 02:18:40 +00:00
|
|
|
if (strcasecmp(resetpin, "cs") == 0)
|
|
|
|
PDATA(pgm)->reset |= BP_RESET_CS;
|
|
|
|
else if (strcasecmp(resetpin, "aux") == 0 || strcasecmp(reset, "aux1") == 0)
|
|
|
|
PDATA(pgm)->reset |= BP_RESET_AUX;
|
|
|
|
else if (strcasecmp(resetpin, "aux2") == 0)
|
|
|
|
PDATA(pgm)->reset |= BP_RESET_AUX2;
|
|
|
|
else {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("reset must be either CS or AUX\n");
|
2009-11-09 02:18: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
|
|
|
PDATA(pgm)->flag |= BP_FLAG_XPARM_RESET;
|
2009-11-09 02:18:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-01-31 19:01:00 +00:00
|
|
|
|
|
|
|
if (strcmp(extended_param, "nopagedwrite") == 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
|
|
|
PDATA(pgm)->flag |= BP_FLAG_NOPAGEDWRITE;
|
2012-01-31 19:01:00 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-01-30 18:56:31 +00:00
|
|
|
if (strcmp(extended_param, "nopagedread") == 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
|
|
|
PDATA(pgm)->flag |= BP_FLAG_NOPAGEDREAD;
|
2013-01-30 18:56:31 +00:00
|
|
|
continue;
|
|
|
|
}
|
2014-11-13 13:53:47 +00:00
|
|
|
|
2012-01-31 19:01:00 +00:00
|
|
|
if (sscanf(extended_param, "serial_recv_timeout=%d", &serial_recv_timeout) == 1) {
|
|
|
|
if (serial_recv_timeout < 1) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("serial_recv_timeout must be greater 0\n");
|
2012-01-31 19:01:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
PDATA(pgm)->serial_recv_timeout = serial_recv_timeout;
|
|
|
|
continue;
|
|
|
|
}
|
2014-11-13 13:53:47 +00:00
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("do not understand extended param '%s'\n", extended_param);
|
2014-11-13 13:53:47 +00:00
|
|
|
return -1;
|
2009-11-09 02:18:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
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
|
|
|
buspirate_verifyconfig(const PROGRAMMER *pgm) {
|
2009-11-09 02:18:40 +00:00
|
|
|
/* Default reset pin is CS */
|
|
|
|
if (PDATA(pgm)->reset == 0x00)
|
|
|
|
PDATA(pgm)->reset |= BP_RESET_CS;
|
|
|
|
|
|
|
|
if ((PDATA(pgm)->reset != BP_RESET_CS) && buspirate_uses_ascii(pgm)) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("RESET pin other than CS is not supported in ASCII mode\n");
|
2009-11-09 02:18: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
|
|
|
if ( ((PDATA(pgm)->flag & BP_FLAG_XPARM_SPIFREQ) || (PDATA(pgm)->flag & BP_FLAG_XPARM_RAWFREQ))
|
2014-11-13 13:53:47 +00:00
|
|
|
&& buspirate_uses_ascii(pgm)) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("SPI speed selection is not supported in ASCII mode\n");
|
2009-11-09 02:18:40 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-08 02:05:03 +00:00
|
|
|
/* ====== Programmer methods ======= */
|
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 buspirate_open(PROGRAMMER *pgm, const char *port) {
|
2014-02-21 13:44:11 +00:00
|
|
|
union pinfo pinfo;
|
2009-10-08 02:05:03 +00:00
|
|
|
/* BusPirate runs at 115200 by default */
|
|
|
|
if(pgm->baudrate == 0)
|
|
|
|
pgm->baudrate = 115200;
|
|
|
|
|
2021-12-08 10:09:52 +00:00
|
|
|
pinfo.serialinfo.baud = pgm->baudrate;
|
|
|
|
pinfo.serialinfo.cflags = SERIAL_8N1;
|
2009-10-08 02:05:03 +00:00
|
|
|
strcpy(pgm->port, port);
|
2014-02-21 13:44:11 +00:00
|
|
|
if (serial_open(port, pinfo, &pgm->fd)==-1) {
|
2014-11-13 13:53:47 +00:00
|
|
|
return -1;
|
2010-10-22 14:29:56 +00:00
|
|
|
}
|
2009-10-08 02:05:03 +00:00
|
|
|
|
|
|
|
/* drain any extraneous input */
|
|
|
|
serial_drain(&pgm->fd, 0);
|
|
|
|
|
|
|
|
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 void buspirate_close(PROGRAMMER *pgm)
|
2009-10-08 02:05:03 +00:00
|
|
|
{
|
|
|
|
serial_close(&pgm->fd);
|
|
|
|
pgm->fd.ifd = -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 void buspirate_reset_from_binmode(const PROGRAMMER *pgm) {
|
2014-07-16 20:02:01 +00:00
|
|
|
unsigned char buf[10];
|
2010-01-07 13:30:44 +00:00
|
|
|
|
2014-11-13 13:53:47 +00:00
|
|
|
buf[0] = 0x00; /* BinMode: revert to raw bitbang mode */
|
2009-11-04 03:14:17 +00:00
|
|
|
buspirate_send_bin(pgm, buf, 1);
|
2014-11-13 13:53:47 +00:00
|
|
|
buspirate_recv_bin(pgm, buf, 5);
|
|
|
|
|
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
|
|
|
if (PDATA(pgm)->flag & BP_FLAG_XPARM_CPUFREQ) {
|
2014-11-13 13:53:47 +00:00
|
|
|
/* disable pwm */
|
|
|
|
if (buspirate_expect_bin_byte(pgm, 0x13, 0x01) != 1) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("did not get a response to stop PWM command\n");
|
2014-11-13 13:53:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* 0b0100wxyz - Configure peripherals w=power, x=pull-ups, y=AUX, z=CS
|
|
|
|
* we want everything off -- 0b01000000 = 0x40 */
|
|
|
|
if (buspirate_expect_bin_byte(pgm, 0x40, 0x00) == 1) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("did not get a response to power off command\n");
|
2014-11-13 13:53:47 +00:00
|
|
|
}
|
2009-11-04 03:14:17 +00:00
|
|
|
|
|
|
|
buf[0] = 0x0F; /* BinMode: reset */
|
|
|
|
buspirate_send_bin(pgm, buf, 1);
|
|
|
|
|
2010-01-11 12:19:15 +00:00
|
|
|
/* read back all output */
|
|
|
|
memset(buf, '\0', sizeof(buf));
|
|
|
|
for (;;) {
|
|
|
|
int rc;
|
|
|
|
rc = buspirate_recv_bin(pgm, buf, sizeof(buf) - 1);
|
|
|
|
|
2014-07-16 20:02:01 +00:00
|
|
|
if (buspirate_is_prompt((const char*)buf)) {
|
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
|
|
|
PDATA(pgm)->flag &= ~BP_FLAG_IN_BINMODE;
|
2009-11-04 03:14:17 +00:00
|
|
|
break;
|
2010-01-11 12:19:15 +00:00
|
|
|
}
|
|
|
|
if (rc == EOF)
|
|
|
|
break;
|
|
|
|
memset(buf, '\0', sizeof(buf));
|
2009-11-04 03:14:17 +00:00
|
|
|
}
|
2010-01-11 12:19:15 +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
|
|
|
if (PDATA(pgm)->flag & BP_FLAG_IN_BINMODE) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("reset failed; you may need to powercycle it\n");
|
2014-05-16 15:52:25 +00:00
|
|
|
return;
|
2010-01-11 12:19:15 +00:00
|
|
|
}
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_notice("BusPirate is back in text mode\n");
|
2009-11-04 03:14:17 +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
|
|
|
static int buspirate_start_mode_bin(PROGRAMMER *pgm)
|
2009-11-04 03:14:17 +00:00
|
|
|
{
|
2021-11-06 22:34:29 +00:00
|
|
|
struct submode {
|
2013-01-30 17:58:48 +00:00
|
|
|
const char *name; /* Name of mode for user messages */
|
|
|
|
char enter; /* Command to enter from base binary mode */
|
|
|
|
const char *entered_format; /* Response, for "scanf" */
|
|
|
|
char config; /* Command to setup submode parameters */
|
2021-11-06 22:34:29 +00:00
|
|
|
} submode;
|
2014-11-13 13:53: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
|
|
|
if (PDATA(pgm)->flag & BP_FLAG_XPARM_RAWFREQ) {
|
2021-11-06 22:34:29 +00:00
|
|
|
submode.name = "Raw-wire";
|
|
|
|
submode.enter = 0x05;
|
|
|
|
submode.entered_format = "RAW%1d";
|
|
|
|
submode.config = 0x8C;
|
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
|
|
|
PDATA(pgm)->flag |= BP_FLAG_NOPAGEDWRITE;
|
|
|
|
PDATA(pgm)->flag |= BP_FLAG_NOPAGEDREAD;
|
2013-01-30 17:58:48 +00:00
|
|
|
} else {
|
2021-11-06 22:34:29 +00:00
|
|
|
submode.name = "SPI";
|
|
|
|
submode.enter = 0x01;
|
|
|
|
submode.entered_format = "SPI%1d";
|
|
|
|
|
|
|
|
/* 1000wxyz - SPI config, w=HiZ(0)/3.3v(1), x=CLK idle, y=CLK edge, z=SMP sample
|
|
|
|
* we want: 3.3V(1), idle low(0), data change on
|
|
|
|
* trailing edge (1), sample in the middle
|
|
|
|
* of the pulse (0)
|
|
|
|
* => 0b10001010 = 0x8a */
|
|
|
|
submode.config = 0x8A;
|
2013-01-30 17:58:48 +00:00
|
|
|
}
|
2014-07-16 20:02:01 +00:00
|
|
|
|
|
|
|
unsigned char buf[20] = { '\0' };
|
2009-11-04 03:14:17 +00:00
|
|
|
|
|
|
|
/* == Switch to binmode - send 20x '\0' == */
|
|
|
|
buspirate_send_bin(pgm, buf, sizeof(buf));
|
|
|
|
|
|
|
|
/* Expecting 'BBIOx' reply */
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
buspirate_recv_bin(pgm, buf, 5);
|
2014-07-16 20:02:01 +00:00
|
|
|
if (sscanf((const char*)buf, "BBIO%1d", &PDATA(pgm)->binmode_version) != 1) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("binary mode not confirmed: '%s'\n", buf);
|
2009-11-04 03:14:17 +00:00
|
|
|
buspirate_reset_from_binmode(pgm);
|
|
|
|
return -1;
|
|
|
|
}
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_notice("BusPirate binmode version: %d\n",
|
2014-06-13 20:07:40 +00:00
|
|
|
PDATA(pgm)->binmode_version);
|
2009-11-04 03:14:17 +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
|
|
|
PDATA(pgm)->flag |= BP_FLAG_IN_BINMODE;
|
2009-11-04 03:14:17 +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
|
|
|
if (PDATA(pgm)->flag & BP_FLAG_XPARM_CPUFREQ) {
|
2014-11-13 13:53:47 +00:00
|
|
|
unsigned short pwm_duty;
|
|
|
|
unsigned short pwm_period;
|
|
|
|
|
|
|
|
pwm_period = 16000/(PDATA(pgm)->cpufreq) - 1; // oscillator runs at 32MHz, we don't use a prescaler
|
|
|
|
pwm_duty = pwm_period/2; // 50% duty cycle
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_notice("setting up PWM for cpufreq\n");
|
|
|
|
msg_debug("PWM settings: Prescaler=1, Duty Cycle=%hd, Period=%hd\n", pwm_duty, pwm_period);
|
2014-11-13 13:53:47 +00:00
|
|
|
|
|
|
|
buf[0] = 0x12; // pwm setup
|
|
|
|
buf[1] = 0; // prescaler 1
|
|
|
|
buf[2] = (char) ((pwm_duty >> 8) & 0xff); // duty cycle register, high byte
|
|
|
|
buf[3] = (char) pwm_duty & 0xff; // duty cycle register, low byte
|
|
|
|
buf[4] = (char) ((pwm_period >> 8) & 0xff); // period register, high byte
|
|
|
|
buf[5] = (char) pwm_period & 0xff; // period register, low byte
|
|
|
|
buspirate_send_bin(pgm, buf, 6);
|
|
|
|
|
|
|
|
buspirate_recv_bin(pgm, buf, 1);
|
|
|
|
if (buf[0] != 0x01)
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("cpufreq (PWM) setup failed\n");
|
2014-11-13 13:53:47 +00:00
|
|
|
}
|
|
|
|
|
2013-01-30 17:58:48 +00:00
|
|
|
/* == Set protocol sub-mode of binary mode == */
|
2021-11-06 22:34:29 +00:00
|
|
|
buf[0] = submode.enter;
|
2009-11-04 03:14:17 +00:00
|
|
|
buspirate_send_bin(pgm, buf, 1);
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
buspirate_recv_bin(pgm, buf, 4);
|
2021-11-06 22:34:29 +00:00
|
|
|
if (sscanf((const char*)buf, submode.entered_format, &PDATA(pgm)->submode_version) != 1) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("%s mode not confirmed: '%s'\n", submode.name, buf);
|
2009-11-04 03:14:17 +00:00
|
|
|
buspirate_reset_from_binmode(pgm);
|
|
|
|
return -1;
|
|
|
|
}
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_notice("BusPirate %s version: %d\n",
|
|
|
|
submode.name, PDATA(pgm)->submode_version);
|
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
|
|
|
if (PDATA(pgm)->flag & BP_FLAG_NOPAGEDWRITE) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_notice("paged flash write disabled\n");
|
2013-01-30 18:56:31 +00:00
|
|
|
pgm->paged_write = NULL;
|
2012-01-31 19:01:00 +00:00
|
|
|
} else {
|
|
|
|
/* Check for write-then-read without !CS/CS and disable paged_write if absent: */
|
2014-07-16 20:02:01 +00:00
|
|
|
static const unsigned char buf2[] = {5,0,0,0,0};
|
|
|
|
buspirate_send_bin(pgm, buf2, sizeof(buf2));
|
2012-01-31 19:01:00 +00:00
|
|
|
buspirate_recv_bin(pgm, buf, 1);
|
|
|
|
if (buf[0] != 0x01) {
|
|
|
|
/* Disable paged write: */
|
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
|
|
|
PDATA(pgm)->flag |= BP_FLAG_NOPAGEDWRITE;
|
2013-01-30 18:56:31 +00:00
|
|
|
pgm->paged_write = NULL;
|
2012-01-31 19:01:00 +00:00
|
|
|
|
|
|
|
/* Return to SPI mode (0x00s have landed us back in binary bitbang mode): */
|
|
|
|
buf[0] = 0x1;
|
|
|
|
buspirate_send_bin(pgm, buf, 1);
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_notice("disabling paged flash write (need BusPirate firmware >= v5.10)\n");
|
2012-01-31 19:01:00 +00:00
|
|
|
|
|
|
|
/* Flush serial buffer: */
|
|
|
|
serial_drain(&pgm->fd, 0);
|
|
|
|
} else {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_info("paged flash write enabled\n");
|
2012-01-31 19:01:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-07 13:30:44 +00:00
|
|
|
/* 0b0100wxyz - Configure peripherals w=power, x=pull-ups/aux2, y=AUX, z=CS
|
2009-11-09 02:18:40 +00:00
|
|
|
* we want power (0x48) and all reset pins high. */
|
2012-01-31 19:01:00 +00:00
|
|
|
PDATA(pgm)->current_peripherals_config = 0x48 | PDATA(pgm)->reset;
|
2014-05-16 15:52:25 +00:00
|
|
|
if (buspirate_expect_bin_byte(pgm, PDATA(pgm)->current_peripherals_config, 0x01) < 0)
|
|
|
|
return -1;
|
2014-11-13 13:53:47 +00:00
|
|
|
usleep(50000); // sleep for 50ms after power up
|
2009-11-04 03:14:17 +00:00
|
|
|
|
2013-01-30 17:58:48 +00:00
|
|
|
/* 01100xxx - Set speed */
|
2014-05-16 15:52:25 +00:00
|
|
|
if (buspirate_expect_bin_byte(pgm, 0x60 | PDATA(pgm)->spifreq, 0x01) < 0)
|
|
|
|
return -1;
|
2009-11-04 03:14:17 +00:00
|
|
|
|
2013-01-30 17:58:48 +00:00
|
|
|
/* Submode config */
|
2021-11-06 22:34:29 +00:00
|
|
|
if (buspirate_expect_bin_byte(pgm, submode.config, 0x01) < 0)
|
2014-05-16 15:52:25 +00:00
|
|
|
return -1;
|
2009-11-04 03:14:17 +00:00
|
|
|
|
2013-01-30 18:56:31 +00:00
|
|
|
/* AVR Extended Commands - test for existence */
|
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
|
|
|
if (PDATA(pgm)->flag & BP_FLAG_NOPAGEDREAD) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_notice("paged flash read disabled\n");
|
2013-01-30 18:56:31 +00:00
|
|
|
pgm->paged_load = NULL;
|
|
|
|
} else {
|
2014-05-16 15:52:25 +00:00
|
|
|
int rv = buspirate_expect_bin_byte(pgm, 0x06, 0x01);
|
|
|
|
if (rv < 0)
|
|
|
|
return -1;
|
|
|
|
if (rv) {
|
2014-07-16 20:02:01 +00:00
|
|
|
unsigned int ver = 0;
|
|
|
|
static const unsigned char buf2[] = {1};
|
|
|
|
buspirate_send_bin(pgm, buf2, sizeof(buf2));
|
2013-01-30 18:56:31 +00:00
|
|
|
buspirate_recv_bin(pgm, buf, 3);
|
|
|
|
ver = buf[1] << 8 | buf[2];
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_notice("AVR Extended Commands version %d\n", ver);
|
2013-01-30 18:56:31 +00:00
|
|
|
} else {
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_notice("AVR Extended Commands not found\n");
|
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
|
|
|
PDATA(pgm)->flag |= BP_FLAG_NOPAGEDREAD;
|
2013-01-30 18:56:31 +00:00
|
|
|
pgm->paged_load = NULL;
|
2014-05-18 08:41:46 +00:00
|
|
|
}
|
2013-01-30 18:56:31 +00:00
|
|
|
}
|
|
|
|
|
2009-11-04 03:14:17 +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 buspirate_start_spi_mode_ascii(const PROGRAMMER *pgm) {
|
2009-10-08 02:05:03 +00:00
|
|
|
int spi_cmd = -1;
|
|
|
|
int cmd;
|
2014-07-16 20:02:01 +00:00
|
|
|
char *rcvd;
|
|
|
|
char buf[5];
|
|
|
|
char mode[11];
|
2009-10-08 02:05:03 +00:00
|
|
|
|
2012-01-31 19:01:00 +00:00
|
|
|
buspirate_send(pgm, "m\n");
|
2009-10-08 02:05:03 +00:00
|
|
|
while(1) {
|
|
|
|
rcvd = buspirate_readline(pgm, NULL, 0);
|
2014-11-13 13:53:47 +00:00
|
|
|
if (rcvd == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
2014-07-16 20:02:01 +00:00
|
|
|
if (spi_cmd == -1 && sscanf(rcvd, "%2d. %10s", &cmd, mode)) {
|
2009-10-08 02:05:03 +00:00
|
|
|
if (strcmp(mode, "SPI") == 0)
|
|
|
|
spi_cmd = cmd;
|
|
|
|
}
|
|
|
|
if (buspirate_is_prompt(rcvd))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (spi_cmd == -1) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("SPI mode number not found; does your BusPirate support SPI?\n");
|
|
|
|
imsg_error("try powercycling your BusPirate and try again\n");
|
2009-10-08 02:05:03 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
snprintf(buf, sizeof(buf), "%d\n", spi_cmd);
|
|
|
|
buspirate_send(pgm, buf);
|
|
|
|
buf[0] = '\0';
|
|
|
|
while (1) {
|
|
|
|
rcvd = buspirate_readline(pgm, NULL, 0);
|
2014-11-13 13:53:47 +00:00
|
|
|
if (rcvd == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
2009-10-08 02:05:03 +00:00
|
|
|
if (strstr(rcvd, "Normal (H=3.3V, L=GND)")) {
|
|
|
|
/* BP firmware 2.1 defaults to Open-drain output.
|
|
|
|
* That doesn't work on my board, even with pull-up
|
|
|
|
* resistors. Select 3.3V output mode instead. */
|
2014-07-16 20:02:01 +00:00
|
|
|
sscanf(rcvd, " %2d.", &cmd);
|
2009-10-08 02:05:03 +00:00
|
|
|
snprintf(buf, sizeof(buf), "%d\n", cmd);
|
|
|
|
}
|
|
|
|
if (buspirate_is_prompt(rcvd)) {
|
|
|
|
if (strncmp(rcvd, "SPI>", 4) == 0) {
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_info("BusPirate is now configured for SPI\n");
|
2009-10-08 02:05:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Not yet 'SPI>' prompt */
|
|
|
|
if (buf[0]) {
|
|
|
|
buspirate_send(pgm, buf);
|
|
|
|
buf[0] = '\0';
|
|
|
|
} else
|
|
|
|
buspirate_send(pgm, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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 void buspirate_enable(PROGRAMMER *pgm, const AVRPART *p) {
|
2014-07-16 20:02:01 +00:00
|
|
|
static const char *reset_str = "#\n";
|
|
|
|
static const char *accept_str = "y\n";
|
2009-10-08 02:05:03 +00:00
|
|
|
char *rcvd;
|
2010-01-11 12:19:15 +00:00
|
|
|
int rc, print_banner = 0;
|
2009-10-08 02:05:03 +00:00
|
|
|
|
2012-01-31 19:01:00 +00:00
|
|
|
/* Ensure configuration is self-consistant: */
|
|
|
|
if (buspirate_verifyconfig(pgm)<0)
|
2014-05-16 15:52:25 +00:00
|
|
|
return; /* XXX should handle error */
|
2012-01-31 19:01:00 +00:00
|
|
|
|
|
|
|
/* Attempt to start binary SPI mode unless explicitly told otherwise: */
|
|
|
|
if (!buspirate_uses_ascii(pgm)) {
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_info("attempting to initiate BusPirate binary mode ...\n");
|
2012-01-31 19:01:00 +00:00
|
|
|
|
|
|
|
/* Send two CRs to ensure we're not in a sub-menu of the UI if we're in ASCII mode: */
|
2014-07-16 20:02:01 +00:00
|
|
|
buspirate_send_bin(pgm, (const unsigned char*)"\n\n", 2);
|
2012-01-31 19:01:00 +00:00
|
|
|
|
|
|
|
/* Clear input buffer: */
|
|
|
|
serial_drain(&pgm->fd, 0);
|
|
|
|
|
|
|
|
/* Attempt to enter binary mode: */
|
2013-01-30 17:58:48 +00:00
|
|
|
if (buspirate_start_mode_bin(pgm) >= 0)
|
2012-01-31 19:01:00 +00:00
|
|
|
return;
|
|
|
|
else
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_info("unable to start binary mode, falling back to ASCII ...\n");
|
2012-01-31 19:01:00 +00:00
|
|
|
}
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_info("attempting to initiate BusPirate ASCII mode ...\n");
|
2010-01-11 12:19:15 +00:00
|
|
|
|
|
|
|
/* Call buspirate_send_bin() instead of buspirate_send()
|
|
|
|
* because we don't know if BP is in text or bin mode */
|
2014-07-16 20:02:01 +00:00
|
|
|
rc = buspirate_send_bin(pgm, (const unsigned char*)reset_str, strlen(reset_str));
|
2010-01-11 12:19:15 +00:00
|
|
|
if (rc) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("BusPirate is not responding; serial port error code %d\n", rc);
|
2014-05-16 15:52:25 +00:00
|
|
|
return;
|
2010-01-11 12:19:15 +00:00
|
|
|
}
|
|
|
|
|
2009-10-08 02:05:03 +00:00
|
|
|
while(1) {
|
2010-01-11 12:19:15 +00:00
|
|
|
rcvd = buspirate_readline_noexit(pgm, NULL, 0);
|
|
|
|
if (! rcvd) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("programmer is not responding\n");
|
2014-05-16 15:52:25 +00:00
|
|
|
return;
|
2010-01-11 12:19:15 +00:00
|
|
|
}
|
2010-07-18 13:15:07 +00:00
|
|
|
if (strncmp(rcvd, "Are you sure?", 13) == 0) {
|
2014-07-16 20:02:01 +00:00
|
|
|
buspirate_send_bin(pgm, (const unsigned char*)accept_str, strlen(accept_str));
|
2010-07-18 13:15:07 +00:00
|
|
|
}
|
2010-01-11 12:19:15 +00:00
|
|
|
if (strncmp(rcvd, "RESET", 5) == 0) {
|
|
|
|
print_banner = 1;
|
2009-10-08 02:05:03 +00:00
|
|
|
continue;
|
2010-01-11 12:19:15 +00:00
|
|
|
}
|
2009-10-08 02:05:03 +00:00
|
|
|
if (buspirate_is_prompt(rcvd)) {
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_debug("**\n");
|
2009-10-08 02:05:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-01-11 12:19:15 +00:00
|
|
|
if (print_banner)
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_debug("** %s", rcvd);
|
2009-10-08 02:05:03 +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
|
|
|
if (!(PDATA(pgm)->flag & BP_FLAG_IN_BINMODE)) {
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_info("using ASCII mode\n");
|
2009-11-04 03:14:17 +00:00
|
|
|
if (buspirate_start_spi_mode_ascii(pgm) < 0) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("unable to start ascii SPI mode\n");
|
2014-05-16 15:52:25 +00:00
|
|
|
return;
|
2009-11-04 03:14:17 +00:00
|
|
|
}
|
|
|
|
}
|
2009-10-08 02:05:03 +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
|
|
|
static void buspirate_disable(const PROGRAMMER *pgm) {
|
|
|
|
if (PDATA(pgm)->flag & BP_FLAG_IN_BINMODE) {
|
2010-01-11 12:19:15 +00:00
|
|
|
serial_recv_timeout = 100;
|
2009-11-04 03:14:17 +00:00
|
|
|
buspirate_reset_from_binmode(pgm);
|
2014-11-13 13:53:47 +00:00
|
|
|
} else {
|
2009-11-04 03:14:17 +00:00
|
|
|
buspirate_expect(pgm, "#\n", "RESET", 1);
|
2014-11-13 13:53:47 +00:00
|
|
|
}
|
2009-10-08 02:05:03 +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
|
|
|
static int buspirate_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
|
2009-10-08 02:05:03 +00:00
|
|
|
pgm->powerup(pgm);
|
|
|
|
|
|
|
|
return pgm->program_enable(pgm, p);
|
|
|
|
}
|
|
|
|
|
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 buspirate_powerup(const PROGRAMMER *pgm) {
|
|
|
|
if (PDATA(pgm)->flag & BP_FLAG_IN_BINMODE) {
|
2013-01-30 17:58:48 +00:00
|
|
|
/* Powerup in BinMode is handled in binary mode init */
|
2009-11-04 03:14:17 +00:00
|
|
|
return;
|
2012-01-31 19:01:00 +00:00
|
|
|
} else {
|
2014-11-13 13:53:47 +00:00
|
|
|
if (buspirate_expect(pgm, "W\n", "POWER SUPPLIES ON", 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
|
|
|
if (PDATA(pgm)->flag & BP_FLAG_XPARM_CPUFREQ) {
|
2012-01-31 19:01:00 +00:00
|
|
|
char buf[25];
|
|
|
|
int ok = 0;
|
|
|
|
snprintf(buf, sizeof(buf), "%d\n", PDATA(pgm)->cpufreq);
|
2020-09-16 21:31:19 +00:00
|
|
|
if (buspirate_expect(pgm, "g\n", "Frequency in kHz", 1)) {
|
2012-01-31 19:01:00 +00:00
|
|
|
if (buspirate_expect(pgm, buf, "Duty cycle in %", 1)) {
|
|
|
|
if (buspirate_expect(pgm, "50\n", "PWM active", 1)) {
|
|
|
|
ok = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!ok) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("did not get a response to start PWM command\n");
|
2012-01-31 19:01:00 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-04 03:14:17 +00:00
|
|
|
return;
|
2012-01-31 19:01:00 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-04 03:14:17 +00:00
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_warning("did not get a response to PowerUp command\n");
|
|
|
|
imsg_warning("trying to continue anyway ...\n");
|
2009-10-08 02:05:03 +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
|
|
|
static void buspirate_powerdown(const PROGRAMMER *pgm) {
|
|
|
|
if (PDATA(pgm)->flag & BP_FLAG_IN_BINMODE) {
|
2014-11-13 13:53:47 +00:00
|
|
|
/* Powerdown in BinMode is handled in binary mode init */
|
|
|
|
return;
|
2012-01-31 19:01:00 +00:00
|
|
|
} else {
|
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
|
|
|
if (PDATA(pgm)->flag & BP_FLAG_XPARM_CPUFREQ) {
|
2012-01-31 19:01:00 +00:00
|
|
|
if (!buspirate_expect(pgm, "g\n", "PWM disabled", 1)) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("did not get a response to stop PWM command\n");
|
2012-01-31 19:01:00 +00:00
|
|
|
}
|
|
|
|
}
|
2014-11-13 13:53:47 +00:00
|
|
|
if (buspirate_expect(pgm, "w\n", "POWER SUPPLIES OFF", 1))
|
2009-11-04 03:14:17 +00:00
|
|
|
return;
|
2012-01-31 19:01:00 +00:00
|
|
|
}
|
2009-11-04 03:14:17 +00:00
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("did not get a response to PowerDown command\n");
|
2009-10-08 02:05:03 +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
|
|
|
static int buspirate_cmd_bin(const PROGRAMMER *pgm,
|
2013-09-02 20:22:53 +00:00
|
|
|
const unsigned char *cmd,
|
|
|
|
unsigned char *res)
|
2009-11-04 03:14:17 +00:00
|
|
|
{
|
2013-01-30 17:58:48 +00:00
|
|
|
/* 0001xxxx - Bulk transfer, send/read 1-16 bytes (0=1byte!)
|
2009-11-04 03:14:17 +00:00
|
|
|
* we are sending 4 bytes -> 0x13 */
|
2014-05-16 15:52:25 +00:00
|
|
|
int rv = buspirate_expect_bin_byte(pgm, 0x13, 0x01);
|
|
|
|
if (rv < 0)
|
|
|
|
return -1;
|
|
|
|
if (rv == 0)
|
2009-11-04 03:14:17 +00:00
|
|
|
return -1;
|
|
|
|
|
2014-07-16 20:02:01 +00:00
|
|
|
buspirate_send_bin(pgm, cmd, 4);
|
|
|
|
buspirate_recv_bin(pgm, res, 4);
|
2009-11-04 03:14:17 +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 buspirate_cmd_ascii(const PROGRAMMER *pgm,
|
2013-09-02 20:22:53 +00:00
|
|
|
const unsigned char *cmd,
|
|
|
|
unsigned char *res)
|
2009-10-08 02:05:03 +00:00
|
|
|
{
|
|
|
|
char buf[25];
|
|
|
|
char *rcvd;
|
2022-01-07 18:16:37 +00:00
|
|
|
int i = 0;
|
|
|
|
unsigned int spi_write, spi_read;
|
2009-10-08 02:05:03 +00:00
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "0x%02x 0x%02x 0x%02x 0x%02x\n",
|
2010-01-07 13:30:44 +00:00
|
|
|
cmd[0], cmd[1], cmd[2], cmd[3]);
|
2009-10-08 02:05:03 +00:00
|
|
|
buspirate_send(pgm, buf);
|
2009-10-08 05:00:41 +00:00
|
|
|
while (i < 4) {
|
2009-10-08 02:05:03 +00:00
|
|
|
rcvd = buspirate_readline(pgm, NULL, 0);
|
2014-11-13 13:53:47 +00:00
|
|
|
if (rcvd == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
2009-10-08 02:05:03 +00:00
|
|
|
/* WRITE: 0xAC READ: 0x04 */
|
2014-07-16 20:02:01 +00:00
|
|
|
if (sscanf(rcvd, "WRITE: 0x%2x READ: 0x%2x", &spi_write, &spi_read) == 2) {
|
2009-10-08 02:05:03 +00:00
|
|
|
res[i++] = spi_read;
|
|
|
|
}
|
|
|
|
if (buspirate_is_prompt(rcvd))
|
|
|
|
break;
|
|
|
|
}
|
2009-10-08 05:00:41 +00:00
|
|
|
|
2009-10-08 02:05:03 +00:00
|
|
|
if (i != 4) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("SPI has not read 4 bytes back\n");
|
2009-10-08 02:05:03 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-08 05:00:41 +00:00
|
|
|
|
|
|
|
/* wait for prompt */
|
|
|
|
while (buspirate_getc(pgm) != '>')
|
|
|
|
/* do nothing */;
|
|
|
|
|
2009-10-08 02:05:03 +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 buspirate_cmd(const PROGRAMMER *pgm,
|
2013-09-02 20:22:53 +00:00
|
|
|
const unsigned char *cmd,
|
|
|
|
unsigned char *res)
|
2009-11-04 03:14:17 +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
|
|
|
if (PDATA(pgm)->flag & BP_FLAG_IN_BINMODE)
|
2009-11-04 03:14:17 +00:00
|
|
|
return buspirate_cmd_bin(pgm, cmd, res);
|
|
|
|
else
|
|
|
|
return buspirate_cmd_ascii(pgm, cmd, res);
|
|
|
|
}
|
|
|
|
|
2013-01-30 18:56:31 +00:00
|
|
|
/* Paged load function which utilizes the AVR Extended Commands set */
|
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 buspirate_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
|
|
|
unsigned int page_size, unsigned int address, unsigned int n_bytes) {
|
|
|
|
|
2013-01-30 18:56:31 +00:00
|
|
|
unsigned char commandbuf[10];
|
|
|
|
unsigned char buf[275];
|
|
|
|
unsigned int addr = 0;
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_notice("buspirate_paged_load(..,%s,%d,%d,%d)\n",m->desc,m->page_size,address,n_bytes);
|
2013-01-30 18:56:31 +00:00
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
// This should never happen, but still ...
|
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
|
|
|
if (PDATA(pgm)->flag & BP_FLAG_NOPAGEDREAD) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("called while in nopagedread mode\n");
|
2013-01-30 18:56:31 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// determine what type of memory to read, only flash is supported
|
|
|
|
if (strcmp(m->desc, "flash") != 0) {
|
2014-11-13 13:53:47 +00:00
|
|
|
return -1;
|
2013-01-30 18:56:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// send command to read data
|
2014-07-16 20:02:01 +00:00
|
|
|
commandbuf[0] = 6;
|
|
|
|
commandbuf[1] = 2;
|
2013-01-30 18:56:31 +00:00
|
|
|
|
|
|
|
// send start address (in WORDS, not bytes!)
|
|
|
|
commandbuf[2] = (address >> 1 >> 24) & 0xff;
|
|
|
|
commandbuf[3] = (address >> 1>> 16) & 0xff;
|
|
|
|
commandbuf[4] = (address >> 1 >> 8) & 0xff;
|
|
|
|
commandbuf[5] = (address >> 1) & 0xff;
|
|
|
|
|
|
|
|
// send number of bytes to fetch (in BYTES)
|
|
|
|
commandbuf[6] = (n_bytes >> 24) & 0xff;
|
|
|
|
commandbuf[7] = (n_bytes >> 16) & 0xff;
|
|
|
|
commandbuf[8] = (n_bytes >> 8) & 0xff;
|
|
|
|
commandbuf[9] = (n_bytes) & 0xff;
|
|
|
|
|
|
|
|
buspirate_send_bin(pgm, commandbuf, 10);
|
|
|
|
buspirate_recv_bin(pgm, buf, 1);
|
|
|
|
buspirate_recv_bin(pgm, buf, 1);
|
|
|
|
|
|
|
|
if (buf[0] != 0x01) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("Paged Read command returned zero\n");
|
2013-01-30 18:56:31 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-07-16 20:02:01 +00:00
|
|
|
for (addr = 0; addr < n_bytes; addr++) {
|
2013-01-30 18:56:31 +00:00
|
|
|
buspirate_recv_bin(pgm, &m->buf[addr+address], 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return n_bytes;
|
|
|
|
}
|
2012-01-31 19:01:00 +00:00
|
|
|
/* Paged write function which utilizes the Bus Pirate's "Write then Read" binary SPI instruction */
|
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 buspirate_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
|
|
|
unsigned int page_size, unsigned int base_addr, unsigned int n_data_bytes) {
|
|
|
|
|
2012-01-31 19:01:00 +00:00
|
|
|
int page, i;
|
|
|
|
int addr = base_addr;
|
|
|
|
int n_page_writes;
|
|
|
|
int this_page_size;
|
2014-07-16 20:02:01 +00:00
|
|
|
unsigned char cmd_buf[4096] = {'\0'};
|
|
|
|
unsigned char send_byte, recv_byte;
|
2012-01-31 19:01: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
|
|
|
if (!(PDATA(pgm)->flag & BP_FLAG_IN_BINMODE)) {
|
2012-01-31 19:01:00 +00:00
|
|
|
/* Return if we are not in binary mode. */
|
|
|
|
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
|
|
|
if (PDATA(pgm)->flag & BP_FLAG_NOPAGEDWRITE) {
|
2012-01-31 19:01:00 +00:00
|
|
|
/* Return if we've nominated not to use paged writes. */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (page_size>1024) {
|
|
|
|
/* Page sizes greater than 1kB not yet supported. */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(m->desc,"flash") != 0) {
|
|
|
|
/* Only flash memory currently supported. */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pre-check opcodes */
|
|
|
|
if (m->op[AVR_OP_LOADPAGE_LO] == NULL) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("AVR_OP_LOADPAGE_LO command not defined for %s\n", p->desc);
|
2012-01-31 19:01:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (m->op[AVR_OP_LOADPAGE_HI] == NULL) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("AVR_OP_LOADPAGE_HI command not defined for %s\n", p->desc);
|
2012-01-31 19:01:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate total number of page writes needed: */
|
|
|
|
n_page_writes = n_data_bytes/page_size;
|
|
|
|
if (n_data_bytes%page_size >0)
|
|
|
|
n_page_writes++;
|
|
|
|
|
|
|
|
/* Ensure error LED is off: */
|
|
|
|
pgm->err_led(pgm, OFF);
|
|
|
|
|
|
|
|
/* Loop over pages: */
|
|
|
|
for (page=0; page<n_page_writes; page++) {
|
|
|
|
|
|
|
|
/* Determine bytes to write in this page: */
|
|
|
|
this_page_size = page_size;
|
|
|
|
if (page == n_page_writes-1)
|
|
|
|
this_page_size = n_data_bytes - page_size*page;
|
|
|
|
|
|
|
|
/* Set up command buffer: */
|
|
|
|
memset(cmd_buf, 0, 4*this_page_size);
|
|
|
|
for (i=0; i<this_page_size; i++) {
|
|
|
|
|
|
|
|
addr = base_addr + page*page_size + i;
|
|
|
|
|
|
|
|
if (i%2 == 0) {
|
|
|
|
avr_set_bits(m->op[AVR_OP_LOADPAGE_LO], &(cmd_buf[4*i]));
|
|
|
|
avr_set_addr(m->op[AVR_OP_LOADPAGE_LO], &(cmd_buf[4*i]), addr/2);
|
|
|
|
avr_set_input(m->op[AVR_OP_LOADPAGE_LO], &(cmd_buf[4*i]), m->buf[addr]);
|
|
|
|
} else {
|
|
|
|
avr_set_bits(m->op[AVR_OP_LOADPAGE_HI], &(cmd_buf[4*i]));
|
|
|
|
avr_set_addr(m->op[AVR_OP_LOADPAGE_HI], &(cmd_buf[4*i]), addr/2);
|
|
|
|
avr_set_input(m->op[AVR_OP_LOADPAGE_HI], &(cmd_buf[4*i]), m->buf[addr]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 00000100 - Write then read */
|
|
|
|
send_byte = 0x05;
|
|
|
|
buspirate_send_bin(pgm, &send_byte, 1);
|
|
|
|
|
|
|
|
/* Number of bytes to write: */
|
|
|
|
send_byte = (4*this_page_size)/0x100;
|
|
|
|
buspirate_send_bin(pgm, &send_byte, 1); /* High byte */
|
|
|
|
send_byte = (4*this_page_size)%0x100;
|
|
|
|
buspirate_send_bin(pgm, &send_byte, 1); /* Low byte */
|
|
|
|
|
|
|
|
/* Number of bytes to read: */
|
|
|
|
send_byte = 0x0;
|
|
|
|
buspirate_send_bin(pgm, &send_byte, 1); /* High byte */
|
|
|
|
buspirate_send_bin(pgm, &send_byte, 1); /* Low byte */
|
|
|
|
|
|
|
|
/* Set programming LED: */
|
|
|
|
pgm->pgm_led(pgm, ON);
|
|
|
|
|
|
|
|
/* Send command buffer: */
|
|
|
|
buspirate_send_bin(pgm, cmd_buf, 4*this_page_size);
|
|
|
|
|
|
|
|
/* Check for write failure: */
|
|
|
|
if ((buspirate_recv_bin(pgm, &recv_byte, 1) == EOF) || (recv_byte != 0x01)) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("write then read did not succeed\n");
|
2012-01-31 19:01:00 +00:00
|
|
|
pgm->pgm_led(pgm, OFF);
|
|
|
|
pgm->err_led(pgm, ON);
|
2014-05-16 15:52:25 +00:00
|
|
|
return -1;
|
2012-01-31 19:01:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Unset programming LED: */
|
|
|
|
pgm->pgm_led(pgm, OFF);
|
|
|
|
|
|
|
|
/* Write loaded page to flash: */
|
|
|
|
avr_write_page(pgm, p, m, addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return n_data_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 buspirate_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
|
2009-10-08 02:05:03 +00:00
|
|
|
unsigned char cmd[4];
|
|
|
|
unsigned char res[4];
|
|
|
|
|
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
|
|
|
if (PDATA(pgm)->flag & BP_FLAG_IN_BINMODE) {
|
2009-11-09 02:18:40 +00:00
|
|
|
/* Clear configured reset pin(s): CS and/or AUX and/or AUX2 */
|
|
|
|
PDATA(pgm)->current_peripherals_config &= ~PDATA(pgm)->reset;
|
2014-05-16 15:52:25 +00:00
|
|
|
if (buspirate_expect_bin_byte(pgm, PDATA(pgm)->current_peripherals_config, 0x01) < 0)
|
|
|
|
return -1;
|
2009-11-09 02:18:40 +00:00
|
|
|
}
|
2009-11-04 03:14:17 +00:00
|
|
|
else
|
|
|
|
buspirate_expect(pgm, "{\n", "CS ENABLED", 1);
|
2009-10-08 02:05:03 +00:00
|
|
|
|
|
|
|
if (p->op[AVR_OP_PGM_ENABLE] == NULL) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("program enable instruction not defined for part %s\n", p->desc);
|
2009-10-08 02:05:03 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(cmd, 0, sizeof(cmd));
|
|
|
|
avr_set_bits(p->op[AVR_OP_PGM_ENABLE], cmd);
|
|
|
|
pgm->cmd(pgm, cmd, res);
|
|
|
|
|
|
|
|
if (res[2] != cmd[1])
|
|
|
|
return -2;
|
|
|
|
|
|
|
|
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 buspirate_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
|
2009-10-08 02:05:03 +00:00
|
|
|
unsigned char cmd[4];
|
|
|
|
unsigned char res[4];
|
|
|
|
|
|
|
|
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);
|
2009-10-08 02:05:03 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pgm->pgm_led(pgm, ON);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
pgm->pgm_led(pgm, OFF);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-17 20:56:37 +00:00
|
|
|
/* Interface - management */
|
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 buspirate_setup(PROGRAMMER *pgm)
|
2012-01-17 20:56:37 +00:00
|
|
|
{
|
|
|
|
/* Allocate private data */
|
|
|
|
if ((pgm->cookie = calloc(1, sizeof(struct pdata))) == 0) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("out of memory allocating private data\n");
|
2012-01-17 20:56:37 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2012-01-31 19:01:00 +00:00
|
|
|
PDATA(pgm)->serial_recv_timeout = 100;
|
2012-01-17 20:56:37 +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
|
|
|
static void buspirate_teardown(PROGRAMMER *pgm)
|
2012-01-17 20:56:37 +00:00
|
|
|
{
|
|
|
|
free(pgm->cookie);
|
|
|
|
}
|
2012-01-31 17:03:43 +00:00
|
|
|
const char buspirate_desc[] = "Using the Bus Pirate's SPI interface for programming";
|
2012-01-17 20:56:37 +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 buspirate_initpgm(PROGRAMMER *pgm) {
|
2009-10-08 02:05:03 +00:00
|
|
|
strcpy(pgm->type, "BusPirate");
|
|
|
|
|
|
|
|
pgm->display = buspirate_dummy_6;
|
|
|
|
|
|
|
|
/* BusPirate itself related methods */
|
|
|
|
pgm->open = buspirate_open;
|
|
|
|
pgm->close = buspirate_close;
|
|
|
|
pgm->enable = buspirate_enable;
|
|
|
|
pgm->disable = buspirate_disable;
|
|
|
|
pgm->initialize = buspirate_initialize;
|
|
|
|
|
|
|
|
/* Chip related methods */
|
|
|
|
pgm->powerup = buspirate_powerup;
|
|
|
|
pgm->powerdown = buspirate_powerdown;
|
|
|
|
pgm->program_enable = buspirate_program_enable;
|
|
|
|
pgm->chip_erase = buspirate_chip_erase;
|
|
|
|
pgm->cmd = buspirate_cmd;
|
|
|
|
pgm->read_byte = avr_read_byte_default;
|
|
|
|
pgm->write_byte = avr_write_byte_default;
|
2009-11-04 03:14:17 +00:00
|
|
|
|
2012-01-31 19:01:00 +00:00
|
|
|
pgm->paged_write = buspirate_paged_write;
|
2013-01-30 18:56:31 +00:00
|
|
|
pgm->paged_load = buspirate_paged_load;
|
2012-01-31 19:01:00 +00:00
|
|
|
|
2009-11-04 03:14:17 +00:00
|
|
|
/* Support functions */
|
|
|
|
pgm->parseextparams = buspirate_parseextparms;
|
|
|
|
|
2012-01-17 20:56:37 +00:00
|
|
|
pgm->setup = buspirate_setup;
|
|
|
|
pgm->teardown = buspirate_teardown;
|
2009-10-08 02:05:03 +00:00
|
|
|
}
|
2013-01-30 21:15:39 +00:00
|
|
|
|
|
|
|
/* Bitbang support */
|
|
|
|
|
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 buspirate_bb_enable(PROGRAMMER *pgm, const AVRPART *p) {
|
2014-07-16 20:02:01 +00:00
|
|
|
unsigned char buf[20] = { '\0' };
|
2013-01-30 21:15:39 +00:00
|
|
|
|
2014-05-16 15:52:25 +00:00
|
|
|
if (bitbang_check_prerequisites(pgm) < 0)
|
2014-11-13 13:53:47 +00:00
|
|
|
return; /* XXX should treat as error */
|
2013-01-30 21:15:39 +00:00
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("attempting to initiate BusPirate bitbang binary mode ...\n");
|
2013-01-30 21:15:39 +00:00
|
|
|
|
|
|
|
/* Send two CRs to ensure we're not in a sub-menu of the UI if we're in ASCII mode: */
|
2014-07-16 20:02:01 +00:00
|
|
|
buspirate_send_bin(pgm, (const unsigned char*)"\n\n", 2);
|
2013-01-30 21:15:39 +00:00
|
|
|
|
|
|
|
/* Clear input buffer: */
|
|
|
|
serial_drain(&pgm->fd, 0);
|
|
|
|
|
|
|
|
/* == Switch to binmode - send 20x '\0' == */
|
|
|
|
buspirate_send_bin(pgm, buf, sizeof(buf));
|
|
|
|
|
|
|
|
/* Expecting 'BBIOx' reply */
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
buspirate_recv_bin(pgm, buf, 5);
|
2014-07-16 20:02:01 +00:00
|
|
|
if (sscanf((char*)buf, "BBIO%1d", &PDATA(pgm)->binmode_version) != 1) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("binary mode not confirmed: '%s'\n", buf);
|
2013-01-30 21:15:39 +00:00
|
|
|
buspirate_reset_from_binmode(pgm);
|
2014-05-16 15:52:25 +00:00
|
|
|
return;
|
2013-01-30 21:15:39 +00:00
|
|
|
}
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_info("BusPirate binmode version: %d\n", PDATA(pgm)->binmode_version);
|
2013-01-30 21:15:39 +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
|
|
|
PDATA(pgm)->flag |= BP_FLAG_IN_BINMODE;
|
2013-01-30 21:15:39 +00:00
|
|
|
|
|
|
|
/* Set pin directions and an initial pin status (all high) */
|
|
|
|
PDATA(pgm)->pin_dir = 0x12; /* AUX, MISO input; everything else output */
|
|
|
|
buf[0] = PDATA(pgm)->pin_dir | 0x40;
|
|
|
|
buspirate_send_bin(pgm, buf, 1);
|
|
|
|
buspirate_recv_bin(pgm, buf, 1);
|
|
|
|
|
|
|
|
PDATA(pgm)->pin_val = 0x3f; /* PULLUP, AUX, MOSI, CLK, MISO, CS high */
|
|
|
|
buf[0] = PDATA(pgm)->pin_val | 0x80;
|
|
|
|
buspirate_send_bin(pgm, buf, 1);
|
|
|
|
buspirate_recv_bin(pgm, buf, 1);
|
|
|
|
|
|
|
|
/* Done */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Direction:
|
|
|
|
010xxxxx
|
|
|
|
Input (1) or output (0):
|
|
|
|
AUX|MOSI|CLK|MISO|CS
|
|
|
|
|
|
|
|
Output value:
|
2014-11-13 13:53:47 +00:00
|
|
|
1xxxxxxx
|
|
|
|
High (1) or low(0):
|
2013-01-30 21:15:39 +00:00
|
|
|
1|POWER|PULLUP|AUX|MOSI|CLK|MISO|CS
|
2014-11-13 13:53:47 +00:00
|
|
|
|
2013-01-30 21:15:39 +00:00
|
|
|
Both respond with a byte with current status:
|
|
|
|
0|POWER|PULLUP|AUX|MOSI|CLK|MISO|CS
|
|
|
|
*/
|
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 buspirate_bb_getpin(const PROGRAMMER *pgm, int pinfunc) {
|
2013-01-30 21:15:39 +00:00
|
|
|
unsigned char buf[10];
|
|
|
|
int value = 0;
|
Rework of bitbanging functions setpin, getpin, highpulsepin to make simplier use of new pindefs data in pgm structure
* linuxgpio.c, bitbang.c, buspirate.c, par.c, pgm.h, term.c, serbb_*.c: changed
interface of setpin, getpin, highpulsepin to take pin function as parameter
(not the real number, which can be found by pgm->pinno[function])
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1252 81a1dc3b-b13d-400b-aceb-764788c761c2
2013-12-04 19:02:55 +00:00
|
|
|
int pin = pgm->pinno[pinfunc];
|
2013-01-30 21:15:39 +00:00
|
|
|
|
|
|
|
if (pin & PIN_INVERSE) {
|
|
|
|
pin &= PIN_MASK;
|
|
|
|
value = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pin < 1 || pin > 5)
|
|
|
|
return -1;
|
2014-11-13 13:53:47 +00:00
|
|
|
|
2013-01-30 21:15:39 +00:00
|
|
|
buf[0] = PDATA(pgm)->pin_dir | 0x40;
|
|
|
|
if (buspirate_send_bin(pgm, buf, 1) < 0)
|
|
|
|
return -1;
|
|
|
|
/* Read all of the previously-expected-but-unread bytes */
|
|
|
|
while (PDATA(pgm)->unread_bytes > 0) {
|
|
|
|
if (buspirate_recv_bin(pgm, buf, 1) < 0)
|
|
|
|
return -1;
|
|
|
|
PDATA(pgm)->unread_bytes--;
|
|
|
|
}
|
2014-11-13 13:53:47 +00:00
|
|
|
|
2013-01-30 21:15:39 +00:00
|
|
|
/* Now read the actual response */
|
|
|
|
if (buspirate_recv_bin(pgm, buf, 1) < 0)
|
2014-11-13 13:53:47 +00:00
|
|
|
return -1;
|
2013-01-30 21:15:39 +00:00
|
|
|
|
|
|
|
if (buf[0] & (1 << (pin - 1)))
|
|
|
|
value ^= 1;
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_debug("get pin %d = %d\n", pin, value);
|
2013-01-30 21:15:39 +00:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
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 buspirate_bb_setpin_internal(const PROGRAMMER *pgm, int pin, int value) {
|
2013-01-30 21:15:39 +00:00
|
|
|
unsigned char buf[10];
|
|
|
|
|
|
|
|
if (pin & PIN_INVERSE) {
|
|
|
|
value = !value;
|
|
|
|
pin &= PIN_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((pin < 1 || pin > 5) && (pin != 7)) // 7 is POWER
|
|
|
|
return -1;
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_debug("set pin %d = %d\n", pin, value);
|
2013-01-30 21:15:39 +00:00
|
|
|
|
|
|
|
if (value)
|
|
|
|
PDATA(pgm)->pin_val |= (1 << (pin - 1));
|
|
|
|
else
|
|
|
|
PDATA(pgm)->pin_val &= ~(1 << (pin - 1));
|
2014-11-13 13:53:47 +00:00
|
|
|
|
2013-01-30 21:15:39 +00:00
|
|
|
buf[0] = PDATA(pgm)->pin_val | 0x80;
|
|
|
|
if (buspirate_send_bin(pgm, buf, 1) < 0)
|
|
|
|
return -1;
|
|
|
|
/* We'll get a byte back, but we don't need to read it now.
|
|
|
|
This is just a quick optimization that saves some USB
|
|
|
|
round trips, improving read times by a factor of 3. */
|
|
|
|
PDATA(pgm)->unread_bytes++;
|
|
|
|
|
|
|
|
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 buspirate_bb_setpin(const PROGRAMMER *pgm, int pinfunc, int value) {
|
Rework of bitbanging functions setpin, getpin, highpulsepin to make simplier use of new pindefs data in pgm structure
* linuxgpio.c, bitbang.c, buspirate.c, par.c, pgm.h, term.c, serbb_*.c: changed
interface of setpin, getpin, highpulsepin to take pin function as parameter
(not the real number, which can be found by pgm->pinno[function])
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1252 81a1dc3b-b13d-400b-aceb-764788c761c2
2013-12-04 19:02:55 +00:00
|
|
|
return buspirate_bb_setpin_internal(pgm, pgm->pinno[pinfunc], value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 buspirate_bb_highpulsepin(const PROGRAMMER *pgm, int pinfunc) {
|
2013-01-30 21:15:39 +00:00
|
|
|
int ret;
|
Rework of bitbanging functions setpin, getpin, highpulsepin to make simplier use of new pindefs data in pgm structure
* linuxgpio.c, bitbang.c, buspirate.c, par.c, pgm.h, term.c, serbb_*.c: changed
interface of setpin, getpin, highpulsepin to take pin function as parameter
(not the real number, which can be found by pgm->pinno[function])
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1252 81a1dc3b-b13d-400b-aceb-764788c761c2
2013-12-04 19:02:55 +00:00
|
|
|
ret = buspirate_bb_setpin(pgm, pinfunc, 1);
|
2013-01-30 21:15:39 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
Rework of bitbanging functions setpin, getpin, highpulsepin to make simplier use of new pindefs data in pgm structure
* linuxgpio.c, bitbang.c, buspirate.c, par.c, pgm.h, term.c, serbb_*.c: changed
interface of setpin, getpin, highpulsepin to take pin function as parameter
(not the real number, which can be found by pgm->pinno[function])
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1252 81a1dc3b-b13d-400b-aceb-764788c761c2
2013-12-04 19:02:55 +00:00
|
|
|
return buspirate_bb_setpin(pgm, pinfunc, 0);
|
2013-01-30 21:15:39 +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
|
|
|
static void buspirate_bb_powerup(const PROGRAMMER *pgm) {
|
Rework of bitbanging functions setpin, getpin, highpulsepin to make simplier use of new pindefs data in pgm structure
* linuxgpio.c, bitbang.c, buspirate.c, par.c, pgm.h, term.c, serbb_*.c: changed
interface of setpin, getpin, highpulsepin to take pin function as parameter
(not the real number, which can be found by pgm->pinno[function])
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1252 81a1dc3b-b13d-400b-aceb-764788c761c2
2013-12-04 19:02:55 +00:00
|
|
|
buspirate_bb_setpin_internal(pgm, 7, 1);
|
2013-01-30 21:15:39 +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
|
|
|
static void buspirate_bb_powerdown(const PROGRAMMER *pgm) {
|
Rework of bitbanging functions setpin, getpin, highpulsepin to make simplier use of new pindefs data in pgm structure
* linuxgpio.c, bitbang.c, buspirate.c, par.c, pgm.h, term.c, serbb_*.c: changed
interface of setpin, getpin, highpulsepin to take pin function as parameter
(not the real number, which can be found by pgm->pinno[function])
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1252 81a1dc3b-b13d-400b-aceb-764788c761c2
2013-12-04 19:02:55 +00:00
|
|
|
buspirate_bb_setpin_internal(pgm, 7, 0);
|
2013-01-30 21:15:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char buspirate_bb_desc[] = "Using the Bus Pirate's bitbang interface for programming";
|
|
|
|
|
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 buspirate_bb_initpgm(PROGRAMMER *pgm) {
|
2013-01-30 21:15:39 +00:00
|
|
|
strcpy(pgm->type, "BusPirate_BB");
|
|
|
|
|
2013-05-03 22:35:00 +00:00
|
|
|
pgm_fill_old_pins(pgm); // TODO to be removed if old pin data no longer needed
|
|
|
|
|
2013-01-30 21:15:39 +00:00
|
|
|
pgm->display = buspirate_dummy_6;
|
|
|
|
|
|
|
|
/* BusPirate itself related methods */
|
|
|
|
pgm->setup = buspirate_setup;
|
|
|
|
pgm->teardown = buspirate_teardown;
|
|
|
|
pgm->open = buspirate_open;
|
|
|
|
pgm->close = buspirate_close;
|
|
|
|
pgm->enable = buspirate_bb_enable;
|
|
|
|
pgm->disable = buspirate_disable;
|
|
|
|
|
|
|
|
/* Chip related methods */
|
|
|
|
pgm->initialize = bitbang_initialize;
|
|
|
|
pgm->rdy_led = bitbang_rdy_led;
|
|
|
|
pgm->err_led = bitbang_err_led;
|
|
|
|
pgm->pgm_led = bitbang_pgm_led;
|
|
|
|
pgm->vfy_led = bitbang_vfy_led;
|
|
|
|
pgm->program_enable = bitbang_program_enable;
|
|
|
|
pgm->chip_erase = bitbang_chip_erase;
|
|
|
|
pgm->cmd = bitbang_cmd;
|
|
|
|
pgm->cmd_tpi = bitbang_cmd_tpi;
|
|
|
|
pgm->powerup = buspirate_bb_powerup;
|
|
|
|
pgm->powerdown = buspirate_bb_powerdown;
|
|
|
|
pgm->setpin = buspirate_bb_setpin;
|
|
|
|
pgm->getpin = buspirate_bb_getpin;
|
|
|
|
pgm->highpulsepin = buspirate_bb_highpulsepin;
|
|
|
|
pgm->read_byte = avr_read_byte_default;
|
|
|
|
pgm->write_byte = avr_write_byte_default;
|
|
|
|
}
|