2012-02-01 22:26:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* avrdude - A Downloader/Uploader for AVR device programmers
|
|
|
|
* Copyright (C) 2003-2004 Theodore A. Roth <troth@openavr.org>
|
|
|
|
* some code:
|
|
|
|
* Copyright (C) 2011-2012 Roger E. Wolff <R.E.Wolff@BitWizard.nl>
|
|
|
|
*
|
|
|
|
* 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/>.
|
2012-02-01 22:26:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/* ft245r -- FT245R/FT232R Synchronous BitBangMode Programmer
|
|
|
|
default pin assign
|
|
|
|
FT232R / FT245R
|
2022-11-22 17:04:05 +00:00
|
|
|
sdi = 1; # RxD / D1
|
2013-05-03 22:35:00 +00:00
|
|
|
sck = 0; # RTS / D0
|
2022-11-22 17:04:05 +00:00
|
|
|
sdo = 2; # TxD / D2
|
2013-05-03 22:35:00 +00:00
|
|
|
reset = 4; # DTR / D4
|
2012-02-01 22:26:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
The ft232r is very similar, or even "identical" in the synchronous
|
|
|
|
bitbang mode that we use here.
|
|
|
|
|
|
|
|
This allows boards that have an ft232r for communication and an avr
|
|
|
|
as the processor to function as their own "ICSP". Boards that fit
|
|
|
|
this description include the Arduino Duemilanove, Arduino Diecimila,
|
|
|
|
Arduino NG (http://arduino.cc/it/main/boards) and the BitWizard
|
|
|
|
ftdi_atmega board (http://www.bitwizard.nl/wiki/index.php/FTDI_ATmega)
|
|
|
|
|
|
|
|
The Arduinos have to be patched to bring some of the control lines
|
|
|
|
to the ICSP header. The BitWizard board already has the neccessary
|
|
|
|
wiring on the PCB.
|
|
|
|
|
|
|
|
How to add the wires to an arduino is documented here:
|
|
|
|
http://www.geocities.jp/arduino_diecimila/bootloader/index_en.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "ac_cfg.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <unistd.h>
|
2012-02-03 21:49:45 +00:00
|
|
|
#include <stdint.h>
|
2021-11-25 09:17:11 +00:00
|
|
|
#include <math.h>
|
2012-02-01 22:26:58 +00:00
|
|
|
|
|
|
|
#include "avrdude.h"
|
2014-05-19 10:01:59 +00:00
|
|
|
#include "libavrdude.h"
|
|
|
|
|
2012-02-01 22:26:58 +00:00
|
|
|
#include "bitbang.h"
|
|
|
|
#include "ft245r.h"
|
2014-02-27 13:06:03 +00:00
|
|
|
#include "usbdevs.h"
|
2012-02-01 22:26:58 +00:00
|
|
|
|
2021-11-24 21:25:45 +00:00
|
|
|
#include "tpi.h"
|
|
|
|
|
|
|
|
#define TPIPCR_GT_0b 0x07
|
|
|
|
#define TPI_STOP_BITS 0x03
|
|
|
|
|
2013-05-16 17:11:35 +00:00
|
|
|
#if defined(HAVE_LIBFTDI1) && defined(HAVE_LIBUSB_1_0)
|
|
|
|
# if defined(HAVE_LIBUSB_1_0_LIBUSB_H)
|
|
|
|
# include <libusb-1.0/libusb.h>
|
|
|
|
# else
|
|
|
|
# include <libusb.h>
|
|
|
|
# endif
|
|
|
|
# include <libftdi1/ftdi.h>
|
2021-12-28 10:26:09 +00:00
|
|
|
#elif defined(HAVE_LIBFTDI)
|
2013-05-16 17:11:35 +00:00
|
|
|
#include <ftdi.h>
|
|
|
|
#else
|
2021-12-28 10:26:09 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma message("No libftdi or libusb support. Install libftdi1/libusb-1.0 or libftdi/libusb and run configure/make again.")
|
|
|
|
#else
|
2013-05-16 17:11:35 +00:00
|
|
|
#warning No libftdi or libusb support. Install libftdi1/libusb-1.0 or libftdi/libusb and run configure/make again.
|
2021-12-28 10:26:09 +00:00
|
|
|
#endif
|
2013-05-16 17:11:35 +00:00
|
|
|
#define DO_NOT_BUILD_FT245R
|
|
|
|
#endif
|
|
|
|
|
2021-11-25 09:10:30 +00:00
|
|
|
#if defined(DO_NOT_BUILD_FT245R)
|
2013-05-16 17:11:35 +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 ft245r_noftdi_open(PROGRAMMER *pgm, const char *name) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("no libftdi or libusb support; install libftdi1/libusb-1.0 or libftdi/libusb and run configure/make\n");
|
2013-05-16 17:11:35 +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
|
|
|
void ft245r_initpgm(PROGRAMMER *pgm) {
|
2013-05-16 17:11:35 +00:00
|
|
|
strcpy(pgm->type, "ftdi_syncbb");
|
|
|
|
pgm->open = ft245r_noftdi_open;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
2012-06-13 20:45:22 +00:00
|
|
|
|
2022-07-04 22:04:36 +00:00
|
|
|
#define FT245R_CYCLES 2
|
|
|
|
#define FT245R_CMD_SIZE (4 * 8*FT245R_CYCLES)
|
|
|
|
#define FT245R_FRAGMENT_SIZE (8 * FT245R_CMD_SIZE)
|
|
|
|
#define REQ_OUTSTANDINGS 10
|
2012-02-01 22:26:58 +00:00
|
|
|
|
2013-05-15 19:03:58 +00:00
|
|
|
#define FT245R_DEBUG 0
|
2021-11-25 09:17:11 +00:00
|
|
|
/*
|
|
|
|
Some revisions of the FTDI chips mess up the timing in bitbang mode
|
|
|
|
unless the bitclock is set to the max (3MHz). For example, see:
|
|
|
|
|
|
|
|
http://www.ftdichip.com/Support/Documents/TechnicalNotes/TN_120_FT232R%20Errata%20Technical%20Note.pdf
|
|
|
|
|
|
|
|
To work around this problem, set the macro below to 1 to always set
|
|
|
|
the bitclock to 3MHz and then issue the same byte repeatedly to get
|
|
|
|
the desired timing.
|
|
|
|
|
|
|
|
*/
|
2021-12-01 22:17:50 +00:00
|
|
|
#define FT245R_BITBANG_VARIABLE_PULSE_WIDTH_WORKAROUND 0
|
2012-02-01 22:26:58 +00:00
|
|
|
|
|
|
|
static struct ftdi_context *handle;
|
|
|
|
|
2021-11-25 09:17:11 +00:00
|
|
|
#if FT245R_BITBANG_VARIABLE_PULSE_WIDTH_WORKAROUND
|
|
|
|
static unsigned int baud_multiplier;
|
|
|
|
#else
|
|
|
|
# define baud_multiplier 1 // this let's C compiler optimize
|
|
|
|
#endif
|
2012-02-01 22:26:58 +00:00
|
|
|
static unsigned char ft245r_ddr;
|
2013-05-03 22:35:00 +00:00
|
|
|
static unsigned char ft245r_out;
|
2012-02-01 22:26:58 +00:00
|
|
|
|
2021-11-25 09:10:30 +00:00
|
|
|
#define FT245R_BUFSIZE 0x2000 // receive buffer size
|
|
|
|
#define FT245R_MIN_FIFO_SIZE 128 // min of FTDI RX/TX FIFO size
|
2012-02-01 22:26:58 +00:00
|
|
|
|
2021-11-25 09:10:30 +00:00
|
|
|
static struct {
|
|
|
|
int len; // # of bytes in transmit buffer
|
|
|
|
uint8_t buf[FT245R_MIN_FIFO_SIZE]; // transmit buffer
|
|
|
|
} tx;
|
2012-02-01 22:26:58 +00:00
|
|
|
|
2021-11-24 22:06:31 +00:00
|
|
|
static struct {
|
|
|
|
int discard; // # of bytes to discard during read
|
2021-11-25 09:10:30 +00:00
|
|
|
int pending; // # of bytes that have been written since last read
|
2022-01-17 21:47:57 +00:00
|
|
|
int len; // # of bytes in receive buffer
|
2021-11-25 09:10:30 +00:00
|
|
|
int wr; // write pointer
|
|
|
|
int rd; // read pointer
|
|
|
|
uint8_t buf[FT245R_BUFSIZE]; // receive ring buffer
|
2021-11-24 22:06:31 +00:00
|
|
|
} rx;
|
2012-02-01 22:26:58 +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 ft245r_cmd(const PROGRAMMER *pgm, const unsigned char *cmd,
|
2021-11-30 06:32:27 +00:00
|
|
|
unsigned char *res);
|
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 ft245r_tpi_tx(const PROGRAMMER *pgm, uint8_t byte);
|
|
|
|
static int ft245r_tpi_rx(const PROGRAMMER *pgm, uint8_t *bytep);
|
2021-11-30 06:32:27 +00:00
|
|
|
|
2021-11-25 09:10:30 +00:00
|
|
|
// Discard all data from the receive buffer.
|
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 ft245r_rx_buf_purge(const PROGRAMMER *pgm) {
|
2022-01-17 21:47:57 +00:00
|
|
|
rx.len = 0;
|
2021-11-25 09:10:30 +00:00
|
|
|
rx.rd = rx.wr = 0;
|
|
|
|
}
|
2012-02-01 22:26:58 +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 ft245r_rx_buf_put(const PROGRAMMER *pgm, uint8_t byte) {
|
2022-01-17 21:47:57 +00:00
|
|
|
rx.len++;
|
2021-11-25 09:10:30 +00:00
|
|
|
rx.buf[rx.wr++] = byte;
|
|
|
|
if (rx.wr >= sizeof(rx.buf))
|
|
|
|
rx.wr = 0;
|
|
|
|
}
|
2012-02-01 22:26:58 +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 uint8_t ft245r_rx_buf_get(const PROGRAMMER *pgm) {
|
2022-01-17 21:47:57 +00:00
|
|
|
rx.len--;
|
2021-11-25 09:10:30 +00:00
|
|
|
uint8_t byte = rx.buf[rx.rd++];
|
|
|
|
if (rx.rd >= sizeof(rx.buf))
|
|
|
|
rx.rd = 0;
|
|
|
|
return byte;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill receive buffer with data from the FTDI receive FIFO. */
|
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 ft245r_fill(const PROGRAMMER *pgm) {
|
2021-11-25 09:10:30 +00:00
|
|
|
uint8_t raw[FT245R_MIN_FIFO_SIZE];
|
|
|
|
int i, nread;
|
|
|
|
|
|
|
|
nread = ftdi_read_data(handle, raw, rx.pending);
|
|
|
|
if (nread < 0)
|
|
|
|
return -1;
|
|
|
|
rx.pending -= nread;
|
|
|
|
#if FT245R_DEBUG
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_info("%s: read %d bytes (pending=%d)\n", __func__, nread, rx.pending);
|
2021-11-25 09:10:30 +00:00
|
|
|
#endif
|
|
|
|
for (i = 0; i < nread; ++i)
|
|
|
|
ft245r_rx_buf_put(pgm, raw[i]);
|
|
|
|
return nread;
|
2012-02-01 22:26:58 +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 ft245r_rx_buf_fill_and_get(const PROGRAMMER *pgm) {
|
2022-01-17 21:47:57 +00:00
|
|
|
while (rx.len == 0)
|
|
|
|
{
|
|
|
|
int result = ft245r_fill(pgm);
|
|
|
|
if (result < 0)
|
|
|
|
{
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ft245r_rx_buf_get(pgm);
|
|
|
|
}
|
|
|
|
|
2021-11-25 09:10:30 +00:00
|
|
|
/* Flush pending TX data to the FTDI send FIFO. */
|
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 ft245r_flush(const PROGRAMMER *pgm) {
|
2021-11-25 09:10:30 +00:00
|
|
|
int rv, len = tx.len, avail;
|
|
|
|
uint8_t *src = tx.buf;
|
|
|
|
|
|
|
|
if (!len)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
while (len > 0) {
|
|
|
|
avail = FT245R_MIN_FIFO_SIZE - rx.pending;
|
|
|
|
if (avail <= 0) {
|
|
|
|
avail = ft245r_fill(pgm);
|
|
|
|
if (avail < 0) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("fill returned %d: %s\n", avail, ftdi_get_error_string(handle));
|
2021-11-25 09:10:30 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (avail > len)
|
|
|
|
avail = len;
|
|
|
|
|
|
|
|
#if FT245R_DEBUG
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_info("%s: writing %d bytes\n", __func__, avail);
|
2021-11-25 09:10:30 +00:00
|
|
|
#endif
|
|
|
|
rv = ftdi_write_data(handle, src, avail);
|
|
|
|
if (rv != avail) {
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_error("write returned %d (expected %d): %s\n", rv, avail, ftdi_get_error_string(handle));
|
2021-11-25 09:10:30 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
src += avail;
|
|
|
|
len -= avail;
|
|
|
|
rx.pending += avail;
|
2012-02-01 22:26:58 +00:00
|
|
|
}
|
2021-11-25 09:10:30 +00:00
|
|
|
tx.len = 0;
|
|
|
|
return 0;
|
2012-02-01 22:26:58 +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 ft245r_send2(const PROGRAMMER *pgm, unsigned char *buf, size_t len,
|
2021-11-25 09:10:30 +00:00
|
|
|
bool discard_rx_data) {
|
2021-11-25 09:17:11 +00:00
|
|
|
int i, j;
|
2012-02-01 22:26:58 +00:00
|
|
|
|
2021-11-25 09:10:30 +00:00
|
|
|
for (i = 0; i < len; ++i) {
|
2021-11-25 09:17:11 +00:00
|
|
|
for (j = 0; j < baud_multiplier; ++j) {
|
|
|
|
if (discard_rx_data)
|
|
|
|
++rx.discard;
|
|
|
|
tx.buf[tx.len++] = buf[i];
|
|
|
|
if (tx.len >= FT245R_MIN_FIFO_SIZE)
|
|
|
|
ft245r_flush(pgm);
|
|
|
|
}
|
2021-11-25 09:10:30 +00:00
|
|
|
}
|
2012-02-01 22:26:58 +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 ft245r_send(const PROGRAMMER *pgm, unsigned char *buf, size_t len) {
|
2021-11-25 09:10:30 +00:00
|
|
|
return ft245r_send2(pgm, buf, len, false);
|
|
|
|
}
|
|
|
|
|
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 ft245r_send_and_discard(const PROGRAMMER *pgm, unsigned char *buf,
|
2021-11-24 22:06:31 +00:00
|
|
|
size_t len) {
|
2021-11-25 09:10:30 +00:00
|
|
|
return ft245r_send2(pgm, buf, len, true);
|
2021-11-24 22:06:31 +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 ft245r_recv(const PROGRAMMER *pgm, unsigned char *buf, size_t len) {
|
2021-11-25 09:17:11 +00:00
|
|
|
int i, j;
|
2021-11-25 09:10:30 +00:00
|
|
|
|
|
|
|
ft245r_flush(pgm);
|
|
|
|
ft245r_fill(pgm);
|
|
|
|
|
|
|
|
#if FT245R_DEBUG
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_info("%s: discarding %d, consuming %zu bytes\n", __func__, rx.discard, len);
|
2021-11-25 09:10:30 +00:00
|
|
|
#endif
|
|
|
|
while (rx.discard > 0) {
|
2022-01-17 21:47:57 +00:00
|
|
|
int result = ft245r_rx_buf_fill_and_get(pgm);
|
|
|
|
if (result < 0)
|
|
|
|
{
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
--rx.discard;
|
2012-02-01 22:26:58 +00:00
|
|
|
}
|
|
|
|
|
2022-01-17 21:47:57 +00:00
|
|
|
for (i = 0; i < len; ++i)
|
|
|
|
{
|
|
|
|
int result = ft245r_rx_buf_fill_and_get(pgm);
|
|
|
|
if (result < 0)
|
|
|
|
{
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf[i] = (uint8_t)result;
|
|
|
|
for (j = 1; j < baud_multiplier; ++j)
|
|
|
|
{
|
|
|
|
result = ft245r_rx_buf_fill_and_get(pgm);
|
|
|
|
if (result < 0)
|
|
|
|
{
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
2021-11-25 09:17:11 +00:00
|
|
|
}
|
2012-02-01 22:26:58 +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 ft245r_drain(const PROGRAMMER *pgm, int display) {
|
2012-02-01 22:26:58 +00:00
|
|
|
int r;
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
// flush the buffer in the chip by changing the mode ...
|
2012-02-01 22:26:58 +00:00
|
|
|
r = ftdi_set_bitmode(handle, 0, BITMODE_RESET); // reset
|
|
|
|
if (r) return -1;
|
|
|
|
r = ftdi_set_bitmode(handle, ft245r_ddr, BITMODE_SYNCBB); // set Synchronuse BitBang
|
|
|
|
if (r) return -1;
|
|
|
|
|
|
|
|
// drain our buffer.
|
2021-11-25 09:10:30 +00:00
|
|
|
ft245r_rx_buf_purge(pgm);
|
2012-02-01 22:26:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-25 09:10:30 +00:00
|
|
|
/* Ensure any pending writes are sent to the FTDI chip before sleeping. */
|
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 ft245r_usleep(const PROGRAMMER *pgm, useconds_t usec) {
|
2021-11-25 09:10:30 +00:00
|
|
|
ft245r_flush(pgm);
|
|
|
|
usleep(usec);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 ft245r_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
|
2013-05-15 18:55:19 +00:00
|
|
|
unsigned char cmd[4] = {0,0,0,0};
|
2012-02-01 22:26:58 +00:00
|
|
|
unsigned char res[4];
|
|
|
|
|
2022-08-30 15:33:42 +00:00
|
|
|
if (p->prog_modes & PM_TPI)
|
2021-11-24 21:25:45 +00:00
|
|
|
return avr_tpi_chip_erase(pgm, p);
|
|
|
|
|
2012-02-01 22:26:58 +00:00
|
|
|
if (p->op[AVR_OP_CHIP_ERASE] == NULL) {
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_error("chip erase instruction not defined for part %s\n", p->desc);
|
2012-02-01 22:26:58 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
avr_set_bits(p->op[AVR_OP_CHIP_ERASE], cmd);
|
|
|
|
pgm->cmd(pgm, cmd, res);
|
2021-11-25 09:10:30 +00:00
|
|
|
ft245r_usleep(pgm, p->chip_erase_delay);
|
2013-05-15 18:55:19 +00:00
|
|
|
return pgm->initialize(pgm, p);
|
2012-02-01 22:26:58 +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 ft245r_set_bitclock(const PROGRAMMER *pgm) {
|
2021-11-25 09:17:11 +00:00
|
|
|
// libftdi1 multiplies bitbang baudrate by 4:
|
|
|
|
int r, rate = 0, ftdi_rate = 3000000 / 4;
|
2012-02-01 22:26:58 +00:00
|
|
|
|
|
|
|
/* bitclock is second. 1us = 0.000001. Max rate for ft232r 750000 */
|
|
|
|
if(pgm->bitclock) {
|
2021-11-25 09:17:11 +00:00
|
|
|
rate = (uint32_t)(1.0/pgm->bitclock);
|
2012-02-01 22:26:58 +00:00
|
|
|
} else if (pgm->baudrate) {
|
2021-11-25 09:17:11 +00:00
|
|
|
rate = pgm->baudrate;
|
2012-02-01 22:26:58 +00:00
|
|
|
} else {
|
|
|
|
rate = 150000; /* should work for all ftdi chips and the avr default internal clock of 1MHz */
|
|
|
|
}
|
|
|
|
|
2021-11-25 09:17:11 +00:00
|
|
|
#if FT245R_BITBANG_VARIABLE_PULSE_WIDTH_WORKAROUND
|
|
|
|
if (rate > 0 && rate < ftdi_rate)
|
|
|
|
baud_multiplier = round((ftdi_rate + rate - 1) / rate);
|
|
|
|
else
|
|
|
|
baud_multiplier = 1;
|
|
|
|
#else
|
|
|
|
ftdi_rate = rate;
|
|
|
|
#endif
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_notice2("%s: bitclk %d -> FTDI rate %d, baud multiplier %d\n",
|
|
|
|
__func__, rate, ftdi_rate, baud_multiplier);
|
2021-11-25 09:17:11 +00:00
|
|
|
|
|
|
|
r = ftdi_set_baudrate(handle, ftdi_rate);
|
2012-02-01 22:26:58 +00:00
|
|
|
if (r) {
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_error("set baudrate %d failed with error '%s'\n", rate, ftdi_get_error_string (handle));
|
2013-05-15 18:55:19 +00:00
|
|
|
return -1;
|
2012-02-01 22:26:58 +00:00
|
|
|
}
|
2013-05-15 18:55:19 +00:00
|
|
|
return 0;
|
2012-02-01 22:26:58 +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 get_pin(const PROGRAMMER *pgm, int pinname) {
|
2021-11-24 21:25:45 +00:00
|
|
|
uint8_t byte;
|
|
|
|
|
2021-11-25 09:10:30 +00:00
|
|
|
ft245r_flush(pgm);
|
|
|
|
|
2021-11-24 21:25:45 +00:00
|
|
|
if (ftdi_read_pins(handle, &byte) != 0)
|
|
|
|
return -1;
|
|
|
|
if (FT245R_DEBUG)
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_info("%s: in 0x%02x\n", __func__, byte);
|
2021-11-24 21:25:45 +00:00
|
|
|
return GET_BITS_0(byte, pgm, pinname) != 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 set_pin(const PROGRAMMER *pgm, int pinname, int val) {
|
2012-02-01 22:26:58 +00:00
|
|
|
unsigned char buf[1];
|
|
|
|
|
2013-05-06 19:21:38 +00:00
|
|
|
if (pgm->pin[pinname].mask[0] == 0) {
|
|
|
|
// ignore not defined pins (might be the led or vcc or buff if not needed)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ft245r_out = SET_BITS_0(ft245r_out,pgm,pinname,val);
|
2013-05-03 22:35:00 +00:00
|
|
|
buf[0] = ft245r_out;
|
|
|
|
|
2021-11-24 22:27:59 +00:00
|
|
|
ft245r_send_and_discard(pgm, buf, 1);
|
2013-05-03 22:35:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
static int set_sck(const PROGRAMMER *pgm, int value) {
|
2014-08-18 21:08:05 +00:00
|
|
|
return set_pin(pgm, PIN_AVR_SCK, 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 set_reset(const PROGRAMMER *pgm, int value) {
|
2013-05-06 19:21:38 +00:00
|
|
|
return set_pin(pgm, PIN_AVR_RESET, value);
|
|
|
|
}
|
2013-05-03 22:35: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
|
|
|
static int set_buff(const PROGRAMMER *pgm, int value) {
|
2013-05-06 19:21:38 +00:00
|
|
|
return set_pin(pgm, PPI_AVR_BUFF, value);
|
|
|
|
}
|
2012-02-01 22:26:58 +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 set_vcc(const PROGRAMMER *pgm, int value) {
|
2013-05-06 19:21:38 +00:00
|
|
|
return set_pin(pgm, PPI_AVR_VCC, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* these functions are callbacks, which go into the
|
|
|
|
* PROGRAMMER data structure ("optional functions")
|
|
|
|
*/
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
static int set_led_pgm(const PROGRAMMER *pgm, int value) {
|
2013-05-06 19:21:38 +00:00
|
|
|
return set_pin(pgm, PIN_LED_PGM, 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 set_led_rdy(const PROGRAMMER *pgm, int value) {
|
2013-05-06 19:21:38 +00:00
|
|
|
return set_pin(pgm, PIN_LED_RDY, 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 set_led_err(const PROGRAMMER *pgm, int value) {
|
2013-05-06 19:21:38 +00:00
|
|
|
return set_pin(pgm, PIN_LED_ERR, 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 set_led_vfy(const PROGRAMMER *pgm, int value) {
|
2013-05-06 19:21:38 +00:00
|
|
|
return set_pin(pgm, PIN_LED_VFY, value);
|
2012-02-01 22:26:58 +00:00
|
|
|
}
|
|
|
|
|
2013-05-06 19:21:38 +00:00
|
|
|
/*
|
|
|
|
* apply power to the AVR processor
|
|
|
|
*/
|
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 ft245r_powerup(const PROGRAMMER *pgm) {
|
2013-05-15 18:55:19 +00:00
|
|
|
set_vcc(pgm, ON); /* power up */
|
2021-11-25 09:10:30 +00:00
|
|
|
ft245r_usleep(pgm, 100);
|
2013-05-06 19:21:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* remove power from the AVR processor
|
|
|
|
*/
|
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 ft245r_powerdown(const PROGRAMMER *pgm) {
|
2013-05-15 18:55:19 +00:00
|
|
|
set_vcc(pgm, OFF); /* power down */
|
2013-05-06 19:21:38 +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 ft245r_disable(const PROGRAMMER *pgm) {
|
2013-05-15 18:55:19 +00:00
|
|
|
set_buff(pgm, OFF);
|
2012-02-01 22:26:58 +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 ft245r_enable(PROGRAMMER *pgm, const AVRPART *p) {
|
2013-05-06 19:21:38 +00:00
|
|
|
/*
|
|
|
|
* Prepare to start talking to the connected device - pull reset low
|
|
|
|
* first, delay a few milliseconds, then enable the buffer. This
|
|
|
|
* sequence allows the AVR to be reset before the buffer is enabled
|
|
|
|
* to avoid a short period of time where the AVR may be driving the
|
|
|
|
* programming lines at the same time the programmer tries to. Of
|
|
|
|
* course, if a buffer is being used, then the /RESET line from the
|
|
|
|
* programmer needs to be directly connected to the AVR /RESET line
|
|
|
|
* and not via the buffer chip.
|
|
|
|
*/
|
2013-05-15 18:55:19 +00:00
|
|
|
set_reset(pgm, OFF);
|
2021-11-25 09:10:30 +00:00
|
|
|
ft245r_usleep(pgm, 1);
|
2013-05-15 18:55:19 +00:00
|
|
|
set_buff(pgm, ON);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* issue the 'program enable' command to the AVR device
|
|
|
|
*/
|
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 ft245r_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
|
2013-05-15 18:55:19 +00:00
|
|
|
unsigned char cmd[4] = {0,0,0,0};
|
|
|
|
unsigned char res[4];
|
|
|
|
int i;
|
|
|
|
|
2022-08-30 15:33:42 +00:00
|
|
|
if (p->prog_modes & PM_TPI)
|
2021-11-24 21:25:45 +00:00
|
|
|
return avr_tpi_program_enable(pgm, p, TPIPCR_GT_0b);
|
|
|
|
|
2013-05-15 18:55:19 +00:00
|
|
|
if (p->op[AVR_OP_PGM_ENABLE] == NULL) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("AVR_OP_PGM_ENABLE command not defined for %s\n", p->desc);
|
2013-05-15 18:55:19 +00:00
|
|
|
fflush(stderr);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
avr_set_bits(p->op[AVR_OP_PGM_ENABLE], cmd);
|
|
|
|
|
|
|
|
for(i = 0; i < 4; i++) {
|
|
|
|
ft245r_cmd(pgm, cmd, res);
|
|
|
|
|
|
|
|
if (res[p->pollindex-1] == p->pollvalue) return 0;
|
|
|
|
|
2014-06-13 20:07:40 +00:00
|
|
|
if (FT245R_DEBUG) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_notice("program enable command not successful, retrying\n");
|
2013-05-15 18:55:19 +00:00
|
|
|
fflush(stderr);
|
|
|
|
}
|
|
|
|
set_pin(pgm, PIN_AVR_RESET, ON);
|
2021-11-25 09:10:30 +00:00
|
|
|
ft245r_usleep(pgm, 20);
|
2013-05-15 18:55:19 +00:00
|
|
|
set_pin(pgm, PIN_AVR_RESET, OFF);
|
|
|
|
|
|
|
|
if (i == 3) {
|
|
|
|
ft245r_drain(pgm, 0);
|
2021-11-25 09:10:30 +00:00
|
|
|
ft245r_rx_buf_purge(pgm);
|
2013-05-15 18:55:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("device is not responding to program enable; check connection\n");
|
2013-05-15 18:55:19 +00:00
|
|
|
fflush(stderr);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* initialize the AVR device and prepare it to accept commands
|
|
|
|
*/
|
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 ft245r_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
|
2013-05-15 18:55:19 +00:00
|
|
|
|
2014-08-18 21:08:05 +00:00
|
|
|
/* Apply power between VCC and GND while RESET and SCK are set to “0”. In some systems,
|
|
|
|
* the programmer can not guarantee that SCK is held low during power-up. In this
|
|
|
|
* case, RESET must be given a positive pulse of at least two CPU clock cycles duration
|
|
|
|
* after SCK has been set to “0”.
|
|
|
|
*/
|
|
|
|
set_sck(pgm, OFF);
|
2013-05-15 18:55:19 +00:00
|
|
|
ft245r_powerup(pgm);
|
|
|
|
|
|
|
|
set_reset(pgm, OFF);
|
2021-11-25 09:10:30 +00:00
|
|
|
ft245r_usleep(pgm, 5000); // 5ms
|
2013-05-15 18:55:19 +00:00
|
|
|
set_reset(pgm, ON);
|
2021-11-25 09:10:30 +00:00
|
|
|
ft245r_usleep(pgm, 5000); // 5ms
|
2013-05-15 18:55:19 +00:00
|
|
|
set_reset(pgm, OFF);
|
2014-08-18 21:08:05 +00:00
|
|
|
|
|
|
|
/* Wait for at least 20 ms and enable serial programming by sending the Programming
|
2022-11-22 17:04:05 +00:00
|
|
|
* Enable serial instruction to pin SDO.
|
2014-08-18 21:08:05 +00:00
|
|
|
*/
|
2021-11-25 09:10:30 +00:00
|
|
|
ft245r_usleep(pgm, 20000); // 20ms
|
2013-05-15 18:55:19 +00:00
|
|
|
|
2022-08-30 15:33:42 +00:00
|
|
|
if (p->prog_modes & PM_TPI) {
|
2021-11-24 21:25:45 +00:00
|
|
|
bool io_link_ok = true;
|
|
|
|
uint8_t byte;
|
|
|
|
int i;
|
|
|
|
|
2022-11-22 17:04:05 +00:00
|
|
|
/* Since there is a single TPIDATA line, SDO and SDI must be
|
2021-11-24 21:25:45 +00:00
|
|
|
linked together through a 1kOhm resistor. Verify that
|
2022-11-22 17:04:05 +00:00
|
|
|
everything we send on SDO gets mirrored back on SDI. */
|
|
|
|
set_pin(pgm, PIN_AVR_SDO, 0);
|
|
|
|
if (get_pin(pgm, PIN_AVR_SDI) != 0) {
|
2021-11-24 21:25:45 +00:00
|
|
|
io_link_ok = false;
|
2022-10-17 14:44:55 +00:00
|
|
|
if(ovsigck) {
|
2022-11-22 17:04:05 +00:00
|
|
|
pmsg_warning("SDO->SDI 0 failed\n");
|
2022-10-17 14:44:55 +00:00
|
|
|
} else {
|
2022-11-22 17:04:05 +00:00
|
|
|
pmsg_error("SDO->SDI 0 failed\n");
|
2021-11-24 21:25:45 +00:00
|
|
|
return -1;
|
2022-10-17 14:44:55 +00:00
|
|
|
}
|
2021-11-24 21:25:45 +00:00
|
|
|
}
|
2022-11-22 17:04:05 +00:00
|
|
|
set_pin(pgm, PIN_AVR_SDO, 1);
|
|
|
|
if (get_pin(pgm, PIN_AVR_SDI) != 1) {
|
2021-11-24 21:25:45 +00:00
|
|
|
io_link_ok = false;
|
2022-10-17 14:44:55 +00:00
|
|
|
if(ovsigck) {
|
2022-11-22 17:04:05 +00:00
|
|
|
pmsg_warning("SDO->SDI 1 failed\n");
|
2022-10-17 14:44:55 +00:00
|
|
|
} else {
|
2022-11-22 17:04:05 +00:00
|
|
|
pmsg_error("SDO->SDI 1 failed\n");
|
2021-11-24 21:25:45 +00:00
|
|
|
return -1;
|
2022-10-17 14:44:55 +00:00
|
|
|
}
|
2021-11-24 21:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (io_link_ok)
|
2022-11-22 17:04:05 +00:00
|
|
|
msg_notice2("SDO-SDI link present\n");
|
2021-11-24 21:25:45 +00:00
|
|
|
|
|
|
|
/* keep TPIDATA high for 16 clock cycles */
|
2022-11-22 17:04:05 +00:00
|
|
|
set_pin(pgm, PIN_AVR_SDO, 1);
|
2021-11-24 21:25:45 +00:00
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
set_sck(pgm, 1);
|
|
|
|
set_sck(pgm, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove extra guard timing bits */
|
|
|
|
ft245r_tpi_tx(pgm, TPI_CMD_SSTCS | TPI_REG_TPIPCR);
|
|
|
|
ft245r_tpi_tx(pgm, 0x7);
|
|
|
|
|
|
|
|
/* read TPI ident reg */
|
|
|
|
ft245r_tpi_tx(pgm, TPI_CMD_SLDCS | TPI_REG_TPIIR);
|
|
|
|
ft245r_tpi_rx(pgm, &byte);
|
|
|
|
if (byte != 0x80) {
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_error("TPIIR 0x%02x not correct\n", byte);
|
2021-11-24 21:25:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2013-05-15 18:55:19 +00:00
|
|
|
return ft245r_program_enable(pgm, p);
|
2012-02-01 22:26:58 +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 inline void add_bit(const PROGRAMMER *pgm, unsigned char *buf, int *buf_pos,
|
2021-11-24 21:25:45 +00:00
|
|
|
uint8_t bit) {
|
2022-11-22 17:04:05 +00:00
|
|
|
ft245r_out = SET_BITS_0(ft245r_out,pgm,PIN_AVR_SDO, bit);
|
2021-11-24 21:25:45 +00:00
|
|
|
ft245r_out = SET_BITS_0(ft245r_out,pgm,PIN_AVR_SCK,0);
|
|
|
|
buf[*buf_pos] = ft245r_out;
|
|
|
|
(*buf_pos)++;
|
|
|
|
|
|
|
|
ft245r_out = SET_BITS_0(ft245r_out,pgm,PIN_AVR_SCK,1);
|
|
|
|
buf[*buf_pos] = ft245r_out;
|
|
|
|
(*buf_pos)++;
|
|
|
|
}
|
|
|
|
|
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 inline int set_data(const PROGRAMMER *pgm, unsigned char *buf, unsigned char data) {
|
2012-02-01 22:26:58 +00:00
|
|
|
int j;
|
|
|
|
int buf_pos = 0;
|
|
|
|
unsigned char bit = 0x80;
|
|
|
|
|
|
|
|
for (j=0; j<8; j++) {
|
2021-11-24 21:25:45 +00:00
|
|
|
add_bit(pgm, buf, &buf_pos, (data & bit) != 0);
|
2012-02-01 22:26:58 +00:00
|
|
|
bit >>= 1;
|
|
|
|
}
|
|
|
|
return buf_pos;
|
|
|
|
}
|
|
|
|
|
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 inline unsigned char extract_data(const PROGRAMMER *pgm, unsigned char *buf, int offset) {
|
2012-02-01 22:26:58 +00:00
|
|
|
int j;
|
2022-11-22 17:04:05 +00:00
|
|
|
int buf_pos = FT245R_CYCLES; /* SDI data is valid AFTER rising SCK edge,
|
2021-11-14 15:44:54 +00:00
|
|
|
i.e. in next clock cycle */
|
2012-02-01 22:26:58 +00:00
|
|
|
unsigned char bit = 0x80;
|
|
|
|
unsigned char r = 0;
|
|
|
|
|
|
|
|
buf += offset * (8 * FT245R_CYCLES);
|
|
|
|
for (j=0; j<8; j++) {
|
2022-11-22 17:04:05 +00:00
|
|
|
if (GET_BITS_0(buf[buf_pos],pgm,PIN_AVR_SDI)) {
|
2012-02-01 22:26:58 +00:00
|
|
|
r |= bit;
|
|
|
|
}
|
|
|
|
buf_pos += FT245R_CYCLES;
|
|
|
|
bit >>= 1;
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* to check data */
|
2018-01-15 22:44:22 +00:00
|
|
|
#if 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 inline unsigned char extract_data_out(const PROGRAMMER *pgm, unsigned char *buf, int offset) {
|
2012-02-01 22:26:58 +00:00
|
|
|
int j;
|
|
|
|
int buf_pos = 1;
|
|
|
|
unsigned char bit = 0x80;
|
|
|
|
unsigned char r = 0;
|
|
|
|
|
|
|
|
buf += offset * (8 * FT245R_CYCLES);
|
|
|
|
for (j=0; j<8; j++) {
|
2022-11-22 17:04:05 +00:00
|
|
|
if (GET_BITS_0(buf[buf_pos],pgm,PIN_AVR_SDO)) {
|
2012-02-01 22:26:58 +00:00
|
|
|
r |= bit;
|
|
|
|
}
|
|
|
|
buf_pos += FT245R_CYCLES;
|
|
|
|
bit >>= 1;
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
2018-01-15 22:44:22 +00:00
|
|
|
#endif
|
2012-02-01 22:26:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* transmit an AVR device command and return the results; 'cmd' and
|
|
|
|
* 'res' must point to at least a 4 byte data buffer
|
|
|
|
*/
|
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 ft245r_cmd(const PROGRAMMER *pgm, const unsigned char *cmd,
|
2013-09-02 20:22:53 +00:00
|
|
|
unsigned char *res) {
|
2012-02-01 22:26:58 +00:00
|
|
|
int i,buf_pos;
|
|
|
|
unsigned char buf[128];
|
|
|
|
|
|
|
|
buf_pos = 0;
|
|
|
|
for (i=0; i<4; i++) {
|
2013-05-03 22:35:00 +00:00
|
|
|
buf_pos += set_data(pgm, buf+buf_pos, cmd[i]);
|
2012-02-01 22:26:58 +00:00
|
|
|
}
|
|
|
|
buf[buf_pos] = 0;
|
|
|
|
buf_pos++;
|
|
|
|
|
|
|
|
ft245r_send (pgm, buf, buf_pos);
|
|
|
|
ft245r_recv (pgm, buf, buf_pos);
|
2013-05-03 22:35:00 +00:00
|
|
|
res[0] = extract_data(pgm, buf, 0);
|
|
|
|
res[1] = extract_data(pgm, buf, 1);
|
|
|
|
res[2] = extract_data(pgm, buf, 2);
|
|
|
|
res[3] = extract_data(pgm, buf, 3);
|
2012-02-01 22:26:58 +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 inline uint8_t extract_tpi_data(const PROGRAMMER *pgm, unsigned char *buf,
|
2021-11-24 21:25:45 +00:00
|
|
|
int *buf_pos) {
|
|
|
|
uint8_t bit = 0x1, byte = 0;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = 0; j < 8; j++) {
|
|
|
|
(*buf_pos)++; // skip over falling clock edge
|
2022-11-22 17:04:05 +00:00
|
|
|
if (GET_BITS_0(buf[(*buf_pos)++], pgm, PIN_AVR_SDI))
|
2021-11-24 21:25:45 +00:00
|
|
|
byte |= bit;
|
|
|
|
bit <<= 1;
|
|
|
|
}
|
|
|
|
return byte;
|
|
|
|
}
|
|
|
|
|
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 inline int set_tpi_data(const PROGRAMMER *pgm, unsigned char *buf,
|
2021-11-24 21:25:45 +00:00
|
|
|
uint8_t byte) {
|
|
|
|
uint8_t bit = 0x1, parity = 0;
|
|
|
|
int j, buf_pos = 0;
|
|
|
|
|
|
|
|
// start bit:
|
|
|
|
add_bit(pgm, buf, &buf_pos, 0);
|
|
|
|
|
|
|
|
// 8 data bits:
|
|
|
|
for (j = 0; j < 8; j++) {
|
|
|
|
add_bit(pgm, buf, &buf_pos, (byte & bit) != 0);
|
|
|
|
parity ^= (byte & bit) != 0;
|
|
|
|
bit <<= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// parity bit:
|
|
|
|
add_bit(pgm, buf, &buf_pos, parity);
|
|
|
|
// stop bits:
|
|
|
|
add_bit(pgm, buf, &buf_pos, 1);
|
|
|
|
add_bit(pgm, buf, &buf_pos, 1);
|
|
|
|
return buf_pos;
|
|
|
|
}
|
|
|
|
|
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 ft245r_tpi_tx(const PROGRAMMER *pgm, uint8_t byte) {
|
2021-11-24 21:25:45 +00:00
|
|
|
uint8_t buf[128];
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = set_tpi_data(pgm, buf, byte);
|
2021-11-24 22:06:31 +00:00
|
|
|
ft245r_send_and_discard(pgm, buf, len);
|
2021-11-24 21:25:45 +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 ft245r_tpi_rx(const PROGRAMMER *pgm, uint8_t *bytep) {
|
2021-11-24 21:25:45 +00:00
|
|
|
uint8_t buf[128], bit, parity;
|
|
|
|
int i, buf_pos = 0, len = 0;
|
|
|
|
uint32_t res, m, byte;
|
|
|
|
|
|
|
|
/* Allow for up to 4 bits before we must see start bit; during
|
2022-11-22 17:04:05 +00:00
|
|
|
that time, we must keep the SDO line high. */
|
2021-11-24 21:25:45 +00:00
|
|
|
for (i = 0; i < 2; ++i)
|
|
|
|
len += set_data(pgm, &buf[len], 0xff);
|
|
|
|
|
|
|
|
ft245r_send(pgm, buf, len);
|
|
|
|
ft245r_recv(pgm, buf, len);
|
|
|
|
|
|
|
|
res = (extract_tpi_data(pgm, buf, &buf_pos)
|
|
|
|
| ((uint32_t) extract_tpi_data(pgm, buf, &buf_pos) << 8));
|
|
|
|
|
|
|
|
/* Look for start bit: */
|
|
|
|
m = 0x1;
|
|
|
|
while (m & res)
|
|
|
|
m <<= 1;
|
|
|
|
if (m >= 0x10) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("start bit missing (res=0x%04x)\n", res);
|
2021-11-24 21:25:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
byte = parity = 0;
|
|
|
|
for (i = 0; i < 8; ++i) {
|
|
|
|
m <<= 1;
|
|
|
|
bit = (res & m) != 0;
|
|
|
|
parity ^= bit;
|
|
|
|
byte |= bit << i;
|
|
|
|
}
|
|
|
|
m <<= 1;
|
|
|
|
if (((res & m) != 0) != parity) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("parity bit wrong\n");
|
2021-11-24 21:25:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (((res & (m << 1)) == 0) || ((res & (m << 2))) == 0) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("stop bits wrong\n");
|
2021-11-24 21:25:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
*bytep = (uint8_t) byte;
|
|
|
|
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 ft245r_cmd_tpi(const PROGRAMMER *pgm, const unsigned char *cmd,
|
2021-11-24 21:25:45 +00:00
|
|
|
int cmd_len, unsigned char *res, int res_len) {
|
|
|
|
int i, ret = 0;
|
|
|
|
|
|
|
|
pgm->pgm_led(pgm, ON);
|
|
|
|
|
|
|
|
for (i = 0; i < cmd_len; ++i)
|
|
|
|
ft245r_tpi_tx(pgm, cmd[i]);
|
|
|
|
for (i = 0; i < res_len; ++i)
|
|
|
|
if ((ret = ft245r_tpi_rx(pgm, &res[i])) < 0)
|
|
|
|
break;
|
|
|
|
if (verbose >= 2) {
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_notice2("%s: [ ", __func__);
|
2021-11-24 21:25:45 +00:00
|
|
|
for (i = 0; i < cmd_len; i++)
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_notice2("%02X ", cmd[i]);
|
|
|
|
msg_notice2("] [ ");
|
2021-11-24 21:25:45 +00:00
|
|
|
for(i = 0; i < res_len; i++)
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_notice2("%02X ", res[i]);
|
|
|
|
msg_notice2("]\n");
|
2021-11-24 21:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pgm->pgm_led(pgm, OFF);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-05-05 13:35:35 +00:00
|
|
|
/* lower 8 pins are accepted, they might be also inverted */
|
|
|
|
static const struct pindef_t valid_pins = {{0xff},{0xff}} ;
|
|
|
|
|
|
|
|
static const struct pin_checklist_t pin_checklist[] = {
|
|
|
|
{ PIN_AVR_SCK, 1, &valid_pins},
|
2022-11-22 17:04:05 +00:00
|
|
|
{ PIN_AVR_SDO, 1, &valid_pins},
|
|
|
|
{ PIN_AVR_SDI, 1, &valid_pins},
|
2013-05-05 13:35:35 +00:00
|
|
|
{ PIN_AVR_RESET,1, &valid_pins},
|
|
|
|
{ PPI_AVR_BUFF, 0, &valid_pins},
|
|
|
|
};
|
2012-02-01 22:26:58 +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 ft245r_open(PROGRAMMER *pgm, const char *port) {
|
2012-02-01 22:26:58 +00:00
|
|
|
int rv;
|
|
|
|
int devnum = -1;
|
2018-01-15 22:44:22 +00:00
|
|
|
char device[9] = "";
|
2013-05-03 22:35:00 +00:00
|
|
|
|
2013-06-19 17:40:32 +00:00
|
|
|
rv = pins_check(pgm,pin_checklist,sizeof(pin_checklist)/sizeof(pin_checklist[0]), true);
|
2018-01-15 22:44:22 +00:00
|
|
|
|
2013-05-05 13:35:35 +00:00
|
|
|
if(rv) {
|
|
|
|
pgm->display(pgm, progbuf);
|
|
|
|
return rv;
|
|
|
|
}
|
2013-05-03 22:35:00 +00:00
|
|
|
|
2012-02-01 22:26:58 +00:00
|
|
|
strcpy(pgm->port, port);
|
|
|
|
|
2018-01-15 22:44:22 +00:00
|
|
|
// read device string cut after 8 chars (max. length of serial number)
|
|
|
|
if ((sscanf(port, "usb:%8s", device) != 1)) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_notice("ft245r_open(): no device identifier in portname, using default\n");
|
2022-08-07 13:05:54 +00:00
|
|
|
pgm->usbsn = cache_string("");
|
2021-11-24 21:09:33 +00:00
|
|
|
devnum = 0;
|
2012-02-01 22:26:58 +00:00
|
|
|
} else {
|
2018-01-15 22:44:22 +00:00
|
|
|
if (strlen(device) == 8 ){ // serial number
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_notice2("ft245r_open(): serial number parsed as: %s\n", device);
|
2018-01-15 22:44:22 +00:00
|
|
|
// copy serial number to pgm struct
|
2022-08-07 13:05:54 +00:00
|
|
|
pgm->usbsn = cache_string(device);
|
2018-01-15 22:44:22 +00:00
|
|
|
// and use first device with matching serial (should be unique)
|
2012-02-01 22:26:58 +00:00
|
|
|
devnum = 0;
|
2018-01-15 22:44:22 +00:00
|
|
|
}
|
|
|
|
else if (strncmp("ft", device, 2) || strlen(device) <= 8) { // classic device number
|
|
|
|
char *startptr = device + 2;
|
|
|
|
char *endptr = NULL;
|
|
|
|
devnum = strtol(startptr,&endptr,10);
|
|
|
|
if ((startptr==endptr) || (*endptr != '\0')) {
|
|
|
|
devnum = -1;
|
|
|
|
}
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_notice2("ft245r_open(): device number parsed as: %d\n", devnum);
|
2018-01-15 22:44:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if something went wrong before abort with helpful message
|
|
|
|
if (devnum < 0) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("invalid portname '%s': use^ 'ft[0-9]+' or serial number\n", port);
|
2018-01-15 22:44:22 +00:00
|
|
|
return -1;
|
2012-02-01 22:26:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handle = malloc (sizeof (struct ftdi_context));
|
|
|
|
ftdi_init(handle);
|
2014-02-27 13:06:03 +00:00
|
|
|
LNODEID usbpid = lfirst(pgm->usbpid);
|
|
|
|
int pid;
|
|
|
|
if (usbpid) {
|
|
|
|
pid = *(int *)(ldata(usbpid));
|
|
|
|
if (lnext(usbpid))
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_warning("using PID 0x%04x, ignoring remaining PIDs in list\n", pid);
|
2014-02-27 13:06:03 +00:00
|
|
|
} else {
|
|
|
|
pid = USB_DEVICE_FT245;
|
|
|
|
}
|
2012-02-01 22:26:58 +00:00
|
|
|
rv = ftdi_usb_open_desc_index(handle,
|
2014-02-27 13:06:03 +00:00
|
|
|
pgm->usbvid?pgm->usbvid:USB_VENDOR_FTDI,
|
|
|
|
pid,
|
2012-02-01 22:26:58 +00:00
|
|
|
pgm->usbproduct[0]?pgm->usbproduct:NULL,
|
|
|
|
pgm->usbsn[0]?pgm->usbsn:NULL,
|
|
|
|
devnum);
|
|
|
|
if (rv) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("cannot open ftdi device: %s\n", ftdi_get_error_string(handle));
|
2013-05-15 18:55:19 +00:00
|
|
|
goto cleanup_no_usb;
|
2012-02-01 22:26:58 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 22:35:00 +00:00
|
|
|
ft245r_ddr =
|
|
|
|
pgm->pin[PIN_AVR_SCK].mask[0]
|
2022-11-22 17:04:05 +00:00
|
|
|
| pgm->pin[PIN_AVR_SDO].mask[0]
|
2013-05-03 22:35:00 +00:00
|
|
|
| pgm->pin[PIN_AVR_RESET].mask[0]
|
|
|
|
| pgm->pin[PPI_AVR_BUFF].mask[0]
|
|
|
|
| pgm->pin[PPI_AVR_VCC].mask[0]
|
|
|
|
| pgm->pin[PIN_LED_ERR].mask[0]
|
|
|
|
| pgm->pin[PIN_LED_RDY].mask[0]
|
|
|
|
| pgm->pin[PIN_LED_PGM].mask[0]
|
|
|
|
| pgm->pin[PIN_LED_VFY].mask[0];
|
|
|
|
|
|
|
|
/* set initial values for outputs, no reset everything else is off */
|
|
|
|
ft245r_out = 0;
|
|
|
|
ft245r_out = SET_BITS_0(ft245r_out,pgm,PIN_AVR_RESET,1);
|
|
|
|
ft245r_out = SET_BITS_0(ft245r_out,pgm,PIN_AVR_SCK,0);
|
2022-11-22 17:04:05 +00:00
|
|
|
ft245r_out = SET_BITS_0(ft245r_out,pgm,PIN_AVR_SDO,0);
|
2013-05-03 22:35:00 +00:00
|
|
|
ft245r_out = SET_BITS_0(ft245r_out,pgm,PPI_AVR_BUFF,0);
|
|
|
|
ft245r_out = SET_BITS_0(ft245r_out,pgm,PPI_AVR_VCC,0);
|
|
|
|
ft245r_out = SET_BITS_0(ft245r_out,pgm,PIN_LED_ERR,0);
|
|
|
|
ft245r_out = SET_BITS_0(ft245r_out,pgm,PIN_LED_RDY,0);
|
|
|
|
ft245r_out = SET_BITS_0(ft245r_out,pgm,PIN_LED_PGM,0);
|
|
|
|
ft245r_out = SET_BITS_0(ft245r_out,pgm,PIN_LED_VFY,0);
|
2012-02-01 22:26:58 +00:00
|
|
|
|
|
|
|
|
2021-11-24 22:00:45 +00:00
|
|
|
rv = ftdi_set_latency_timer(handle, 1);
|
|
|
|
if (rv) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("unable to set latency timer to 1 (%s)\n", ftdi_get_error_string(handle));
|
2021-11-24 22:00:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-02-01 22:26:58 +00:00
|
|
|
rv = ftdi_set_bitmode(handle, ft245r_ddr, BITMODE_SYNCBB); // set Synchronous BitBang
|
|
|
|
if (rv) {
|
2022-10-17 14:44:55 +00:00
|
|
|
pmsg_error("synchronous BitBangMode is not supported (%s)\n", ftdi_get_error_string(handle));
|
2013-05-15 18:55:19 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = ft245r_set_bitclock(pgm);
|
|
|
|
if (rv) {
|
|
|
|
goto cleanup;
|
2012-02-01 22:26:58 +00:00
|
|
|
}
|
2013-05-15 18:55:19 +00:00
|
|
|
|
2012-02-01 22:26:58 +00:00
|
|
|
/*
|
|
|
|
* drain any extraneous input
|
|
|
|
*/
|
|
|
|
ft245r_drain (pgm, 0);
|
|
|
|
|
2021-11-24 22:27:59 +00:00
|
|
|
ft245r_send_and_discard(pgm, &ft245r_out, 1);
|
2013-05-03 22:35:00 +00:00
|
|
|
|
2012-02-01 22:26:58 +00:00
|
|
|
return 0;
|
2013-05-15 18:55:19 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
ftdi_usb_close(handle);
|
|
|
|
cleanup_no_usb:
|
|
|
|
ftdi_deinit (handle);
|
|
|
|
free(handle);
|
2013-05-16 17:11:35 +00:00
|
|
|
handle = NULL;
|
2013-05-15 18:55:19 +00:00
|
|
|
return -1;
|
2012-02-01 22:26:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void ft245r_close(PROGRAMMER * pgm) {
|
2013-05-05 13:35:35 +00:00
|
|
|
if (handle) {
|
|
|
|
// I think the switch to BB mode and back flushes the buffer.
|
|
|
|
ftdi_set_bitmode(handle, 0, BITMODE_SYNCBB); // set Synchronous BitBang, all in puts
|
|
|
|
ftdi_set_bitmode(handle, 0, BITMODE_RESET); // disable Synchronous BitBang
|
2014-06-21 21:29:18 +00:00
|
|
|
ftdi_usb_close(handle);
|
2020-03-11 12:39:57 +00:00
|
|
|
ftdi_deinit (handle);
|
2013-05-05 13:35:35 +00:00
|
|
|
free(handle);
|
|
|
|
handle = NULL;
|
|
|
|
}
|
2012-02-01 22:26:58 +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 ft245r_display(const PROGRAMMER *pgm, const char *p) {
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_info("%sPin assignment : 0..7 = DBUS0..7\n", p); // , 8..11 = GPIO0..3\n",p);
|
2013-05-06 19:21:38 +00:00
|
|
|
pgm_display_generic_mask(pgm, p, SHOW_ALL_PINS);
|
2012-02-01 22:26:58 +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 ft245r_paged_write_gen(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
2022-07-04 22:04:36 +00:00
|
|
|
unsigned int page_size, unsigned int addr, unsigned int n_bytes) {
|
2012-02-01 22:26:58 +00:00
|
|
|
|
2022-07-04 22:04:36 +00:00
|
|
|
for(int i=0; i < (int) n_bytes; i++, addr++)
|
|
|
|
if(avr_write_byte_default(pgm, p, m, addr, m->buf[addr]) != 0)
|
|
|
|
return -2;
|
2012-02-01 22:26:58 +00:00
|
|
|
|
2022-07-04 22:04:36 +00:00
|
|
|
return n_bytes;
|
2012-02-01 22:26:58 +00:00
|
|
|
}
|
|
|
|
|
2022-07-04 22:04:36 +00:00
|
|
|
|
2012-02-01 22:26:58 +00:00
|
|
|
static struct ft245r_request {
|
|
|
|
int addr;
|
|
|
|
int bytes;
|
|
|
|
int n;
|
|
|
|
struct ft245r_request *next;
|
|
|
|
} *req_head,*req_tail,*req_pool;
|
|
|
|
|
|
|
|
static void put_request(int addr, int bytes, int n) {
|
|
|
|
struct ft245r_request *p;
|
|
|
|
if (req_pool) {
|
|
|
|
p = req_pool;
|
|
|
|
req_pool = p->next;
|
|
|
|
} else {
|
|
|
|
p = malloc(sizeof(struct ft245r_request));
|
|
|
|
if (!p) {
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_error("cannot alloc memory\n");
|
2012-02-01 22:26:58 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
memset(p, 0, sizeof(struct ft245r_request));
|
|
|
|
p->addr = addr;
|
|
|
|
p->bytes = bytes;
|
|
|
|
p->n = n;
|
|
|
|
if (req_tail) {
|
|
|
|
req_tail->next = p;
|
|
|
|
req_tail = p;
|
|
|
|
} else {
|
|
|
|
req_head = req_tail = 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 int do_request(const PROGRAMMER *pgm, const AVRMEM *m) {
|
2012-02-01 22:26:58 +00:00
|
|
|
struct ft245r_request *p;
|
|
|
|
int addr, bytes, j, n;
|
|
|
|
unsigned char buf[FT245R_FRAGMENT_SIZE+1+128];
|
|
|
|
|
|
|
|
if (!req_head) return 0;
|
|
|
|
p = req_head;
|
|
|
|
req_head = p->next;
|
|
|
|
if (!req_head) req_tail = req_head;
|
|
|
|
|
|
|
|
addr = p->addr;
|
|
|
|
bytes = p->bytes;
|
|
|
|
n = p->n;
|
|
|
|
memset(p, 0, sizeof(struct ft245r_request));
|
|
|
|
p->next = req_pool;
|
|
|
|
req_pool = p;
|
|
|
|
|
|
|
|
ft245r_recv(pgm, buf, bytes);
|
|
|
|
for (j=0; j<n; j++) {
|
2013-05-03 22:35:00 +00:00
|
|
|
m->buf[addr++] = extract_data(pgm, buf , (j * 4 + 3));
|
2012-02-01 22:26:58 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
static int ft245r_paged_write_flash(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
2022-07-04 22:04:36 +00:00
|
|
|
unsigned int page_size, unsigned int addr, unsigned int n_bytes) {
|
|
|
|
|
|
|
|
int i, j, addr_save, buf_pos, req_count, do_page_write;
|
|
|
|
unsigned char buf[FT245R_FRAGMENT_SIZE+1];
|
|
|
|
unsigned char cmd[4];
|
|
|
|
|
|
|
|
if(m->op[AVR_OP_LOADPAGE_LO] == NULL || m->op[AVR_OP_LOADPAGE_HI] == NULL) {
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_error("AVR_OP_LOADPAGE_HI/LO command not defined for %s\n", p->desc);
|
2022-07-04 22:04:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
do_page_write = req_count = i = j = buf_pos = 0;
|
|
|
|
addr_save = addr;
|
|
|
|
while(i < (int) n_bytes) {
|
|
|
|
int spi = addr&1? AVR_OP_LOADPAGE_HI: AVR_OP_LOADPAGE_LO;
|
|
|
|
|
|
|
|
// put the SPI loadpage command as FT245R_CMD_SIZE bytes into buffer
|
|
|
|
memset(cmd, 0, sizeof cmd);
|
|
|
|
avr_set_bits(m->op[spi], cmd);
|
|
|
|
avr_set_addr(m->op[spi], cmd, addr/2);
|
|
|
|
avr_set_input(m->op[spi], cmd, m->buf[addr]);
|
|
|
|
for(int k=0; k<sizeof cmd; k++)
|
|
|
|
buf_pos += set_data(pgm, buf+buf_pos, cmd[k]);
|
|
|
|
|
|
|
|
i++; j++; addr++;
|
|
|
|
|
|
|
|
if(m->paged && (i%m->page_size == 0 || i >= (int) n_bytes))
|
|
|
|
do_page_write = 1;
|
|
|
|
|
|
|
|
// page boundary, finished or buffer exhausted? queue up requests
|
|
|
|
if(do_page_write || i >= (int) n_bytes || j >= FT245R_FRAGMENT_SIZE/FT245R_CMD_SIZE) {
|
|
|
|
if(i >= n_bytes) {
|
|
|
|
ft245r_out = SET_BITS_0(ft245r_out, pgm, PIN_AVR_SCK, 0); // SCK down
|
|
|
|
buf[buf_pos++] = ft245r_out;
|
|
|
|
} else {
|
|
|
|
// stretch sequence to allow correct readout, see extract_data()
|
|
|
|
buf[buf_pos] = buf[buf_pos - 1];
|
|
|
|
buf_pos++;
|
2012-02-01 22:26:58 +00:00
|
|
|
}
|
2022-07-04 22:04:36 +00:00
|
|
|
ft245r_send(pgm, buf, buf_pos);
|
|
|
|
put_request(addr_save, buf_pos, 0);
|
|
|
|
|
|
|
|
if(++req_count > REQ_OUTSTANDINGS)
|
|
|
|
do_request(pgm, m);
|
|
|
|
|
|
|
|
if(do_page_write) {
|
|
|
|
while(do_request(pgm, m))
|
|
|
|
continue;
|
|
|
|
if(avr_write_page(pgm, p, m, addr_save - (addr_save % m->page_size)) != 0)
|
|
|
|
return -2;
|
|
|
|
do_page_write = req_count = 0;
|
2012-02-01 22:26:58 +00:00
|
|
|
}
|
2022-07-04 22:04:36 +00:00
|
|
|
|
|
|
|
// reset buffer variables
|
|
|
|
j = buf_pos = 0;
|
|
|
|
addr_save = addr;
|
2012-02-01 22:26:58 +00:00
|
|
|
}
|
|
|
|
}
|
2022-07-04 22:04:36 +00:00
|
|
|
|
|
|
|
while(do_request(pgm, m))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return n_bytes;
|
2012-02-01 22:26:58 +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 ft245r_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
2022-07-04 22:04:36 +00:00
|
|
|
unsigned int page_size, unsigned int addr, unsigned int n_bytes) {
|
|
|
|
|
|
|
|
if(!n_bytes)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(strcmp(m->desc, "flash") == 0)
|
2012-02-01 22:26:58 +00:00
|
|
|
return ft245r_paged_write_flash(pgm, p, m, page_size, addr, n_bytes);
|
2022-07-04 22:04:36 +00:00
|
|
|
|
|
|
|
if(strcmp(m->desc, "eeprom") == 0)
|
2012-02-01 22:26:58 +00:00
|
|
|
return ft245r_paged_write_gen(pgm, p, m, page_size, addr, n_bytes);
|
2022-07-04 22:04:36 +00:00
|
|
|
|
|
|
|
return -2;
|
2012-02-01 22:26:58 +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 ft245r_paged_load_gen(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
2022-07-04 22:04:36 +00:00
|
|
|
unsigned int page_size, unsigned int addr, unsigned int n_bytes) {
|
|
|
|
|
|
|
|
for(int i=0; i < (int) n_bytes; i++) {
|
|
|
|
unsigned char rbyte;
|
2012-02-01 22:26:58 +00:00
|
|
|
|
2022-07-04 22:04:36 +00:00
|
|
|
if(avr_read_byte_default(pgm, p, m, addr+i, &rbyte) != 0)
|
2012-02-01 22:26:58 +00:00
|
|
|
return -2;
|
2022-07-04 22:04:36 +00:00
|
|
|
|
|
|
|
m->buf[addr+i] = rbyte;
|
2012-02-01 22:26:58 +00:00
|
|
|
}
|
2022-07-04 22:04:36 +00:00
|
|
|
|
2012-02-01 22:26:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-07-04 22:04:36 +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 ft245r_paged_load_flash(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
2022-07-04 22:04:36 +00:00
|
|
|
unsigned int page_size, unsigned int addr, unsigned int n_bytes) {
|
|
|
|
|
|
|
|
int i, j, addr_save, buf_pos, req_count;
|
2012-02-01 22:26:58 +00:00
|
|
|
unsigned char buf[FT245R_FRAGMENT_SIZE+1];
|
2022-07-04 22:04:36 +00:00
|
|
|
unsigned char cmd[4];
|
2012-02-01 22:26:58 +00:00
|
|
|
|
2022-07-04 22:04:36 +00:00
|
|
|
if(m->op[AVR_OP_READ_LO] == NULL || m->op[AVR_OP_READ_HI] == NULL) {
|
2022-10-17 14:44:55 +00:00
|
|
|
msg_error("AVR_OP_READ_HI/LO command not defined for %s\n", p->desc);
|
2022-07-04 22:04:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-07-04 22:11:32 +00:00
|
|
|
// always called with addr at page boundary, and n_bytes == m->page_size;
|
|
|
|
// hence, OK to prepend load extended address command (at most) once
|
|
|
|
if(m->op[AVR_OP_LOAD_EXT_ADDR]) {
|
|
|
|
memset(cmd, 0, sizeof cmd);
|
|
|
|
avr_set_bits(m->op[AVR_OP_LOAD_EXT_ADDR], cmd);
|
|
|
|
avr_set_addr(m->op[AVR_OP_LOAD_EXT_ADDR], cmd, addr/2);
|
|
|
|
|
|
|
|
buf_pos = 0;
|
|
|
|
for(int k=0; k<sizeof cmd; k++)
|
|
|
|
buf_pos += set_data(pgm, buf+buf_pos, cmd[k]);
|
|
|
|
ft245r_send_and_discard(pgm, buf, buf_pos);
|
|
|
|
}
|
|
|
|
|
2022-07-04 22:04:36 +00:00
|
|
|
req_count = i = j = buf_pos = 0;
|
|
|
|
addr_save = addr;
|
|
|
|
while(i < (int) n_bytes) {
|
|
|
|
int spi = addr&1? AVR_OP_READ_HI: AVR_OP_READ_LO;
|
|
|
|
|
|
|
|
// put the SPI read command as FT245R_CMD_SIZE bytes into buffer
|
|
|
|
memset(cmd, 0, sizeof cmd);
|
|
|
|
avr_set_bits(m->op[spi], cmd);
|
|
|
|
avr_set_addr(m->op[spi], cmd, addr/2);
|
|
|
|
for(int k=0; k<sizeof cmd; k++)
|
|
|
|
buf_pos += set_data(pgm, buf+buf_pos, cmd[k]);
|
|
|
|
|
|
|
|
i++; j++; addr++;
|
|
|
|
|
|
|
|
// finished or buffer exhausted? queue up requests
|
|
|
|
if(i >= (int) n_bytes || j >= FT245R_FRAGMENT_SIZE/FT245R_CMD_SIZE) {
|
|
|
|
if(i >= (int) n_bytes) {
|
|
|
|
ft245r_out = SET_BITS_0(ft245r_out, pgm, PIN_AVR_SCK, 0); // SCK down
|
|
|
|
buf[buf_pos++] = ft245r_out;
|
|
|
|
} else {
|
|
|
|
// stretch sequence to allow correct readout, see extract_data()
|
|
|
|
buf[buf_pos] = buf[buf_pos - 1];
|
|
|
|
buf_pos++;
|
|
|
|
}
|
|
|
|
ft245r_send(pgm, buf, buf_pos);
|
|
|
|
put_request(addr_save, buf_pos, j);
|
2012-02-01 22:26:58 +00:00
|
|
|
|
2022-07-04 22:04:36 +00:00
|
|
|
if(++req_count > REQ_OUTSTANDINGS)
|
|
|
|
do_request(pgm, m);
|
|
|
|
|
|
|
|
// reset buffer variables
|
|
|
|
j = buf_pos = 0;
|
|
|
|
addr_save = addr;
|
|
|
|
}
|
2012-02-01 22:26:58 +00:00
|
|
|
}
|
2022-07-04 22:04:36 +00:00
|
|
|
|
|
|
|
while(do_request(pgm, m))
|
|
|
|
continue;
|
|
|
|
|
2012-02-01 22:26:58 +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 ft245r_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
2022-07-04 22:04:36 +00:00
|
|
|
unsigned int page_size, unsigned int addr, unsigned int n_bytes) {
|
|
|
|
|
|
|
|
if(!n_bytes)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(strcmp(m->desc, "flash") == 0)
|
2012-02-01 22:26:58 +00:00
|
|
|
return ft245r_paged_load_flash(pgm, p, m, page_size, addr, n_bytes);
|
2022-07-04 22:04:36 +00:00
|
|
|
|
|
|
|
if(strcmp(m->desc, "eeprom") == 0)
|
2012-02-01 22:26:58 +00:00
|
|
|
return ft245r_paged_load_gen(pgm, p, m, page_size, addr, n_bytes);
|
2022-07-04 22:04:36 +00:00
|
|
|
|
|
|
|
return -2;
|
2012-02-01 22:26:58 +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 ft245r_initpgm(PROGRAMMER *pgm) {
|
2012-02-01 22:26:58 +00:00
|
|
|
strcpy(pgm->type, "ftdi_syncbb");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* mandatory functions
|
|
|
|
*/
|
|
|
|
pgm->initialize = ft245r_initialize;
|
|
|
|
pgm->display = ft245r_display;
|
|
|
|
pgm->enable = ft245r_enable;
|
|
|
|
pgm->disable = ft245r_disable;
|
|
|
|
pgm->program_enable = ft245r_program_enable;
|
|
|
|
pgm->chip_erase = ft245r_chip_erase;
|
|
|
|
pgm->cmd = ft245r_cmd;
|
2021-11-24 21:25:45 +00:00
|
|
|
pgm->cmd_tpi = ft245r_cmd_tpi;
|
2012-02-01 22:26:58 +00:00
|
|
|
pgm->open = ft245r_open;
|
|
|
|
pgm->close = ft245r_close;
|
|
|
|
pgm->read_byte = avr_read_byte_default;
|
|
|
|
pgm->write_byte = avr_write_byte_default;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* optional functions
|
|
|
|
*/
|
|
|
|
pgm->paged_write = ft245r_paged_write;
|
|
|
|
pgm->paged_load = ft245r_paged_load;
|
|
|
|
|
2013-05-06 19:21:38 +00:00
|
|
|
pgm->rdy_led = set_led_rdy;
|
|
|
|
pgm->err_led = set_led_err;
|
|
|
|
pgm->pgm_led = set_led_pgm;
|
|
|
|
pgm->vfy_led = set_led_vfy;
|
|
|
|
pgm->powerup = ft245r_powerup;
|
|
|
|
pgm->powerdown = ft245r_powerdown;
|
|
|
|
|
2013-05-05 13:35:35 +00:00
|
|
|
handle = NULL;
|
2012-02-01 22:26:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const char ft245r_desc[] = "FT245R/FT232R Synchronous BitBangMode Programmer";
|