Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
buspirate.c File Reference
#include "ac_cfg.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "avrdude.h"
#include "libavrdude.h"
#include "bitbang.h"
#include "buspirate.h"
+ Include dependency graph for buspirate.c:

Go to the source code of this file.

Classes

struct  pdata
 

Macros

#define BP_RESET_CS   0x01
 
#define BP_RESET_AUX   0x02
 
#define BP_RESET_AUX2   0x04
 
#define BP_FLAG_IN_BINMODE   (1<<0)
 
#define BP_FLAG_XPARM_FORCE_ASCII   (1<<1)
 
#define BP_FLAG_XPARM_RESET   (1<<2)
 
#define BP_FLAG_XPARM_SPIFREQ   (1<<3)
 
#define BP_FLAG_NOPAGEDWRITE   (1<<4)
 
#define BP_FLAG_XPARM_CPUFREQ   (1<<5)
 
#define BP_FLAG_XPARM_RAWFREQ   (1<<6)
 
#define BP_FLAG_NOPAGEDREAD   (1<<7)
 
#define PDATA(pgm)   ((struct pdata *)(pgm->cookie))
 

Functions

static int buspirate_uses_ascii (struct programmer_t *pgm)
 
static void dump_mem (const int msglvl, const unsigned char *buf, size_t len)
 
static int buspirate_send_bin (struct programmer_t *pgm, const unsigned char *data, size_t len)
 
static int buspirate_recv_bin (struct programmer_t *pgm, unsigned char *buf, size_t len)
 
static int buspirate_expect_bin (struct programmer_t *pgm, unsigned char *send_data, size_t send_len, unsigned char *expect_data, size_t expect_len)
 
static int buspirate_expect_bin_byte (struct programmer_t *pgm, unsigned char send_byte, unsigned char expect_byte)
 
static int buspirate_getc (struct programmer_t *pgm)
 
static char * buspirate_readline_noexit (struct programmer_t *pgm, char *buf, size_t len)
 
static char * buspirate_readline (struct programmer_t *pgm, char *buf, size_t len)
 
static int buspirate_send (struct programmer_t *pgm, const char *str)
 
static int buspirate_is_prompt (const char *str)
 
static int buspirate_expect (struct programmer_t *pgm, char *send, char *expect, int wait_for_prompt)
 
static void buspirate_dummy_6 (struct programmer_t *pgm, const char *p)
 
static int buspirate_parseextparms (struct programmer_t *pgm, LISTID extparms)
 
static int buspirate_verifyconfig (struct programmer_t *pgm)
 
static int buspirate_open (struct programmer_t *pgm, char *port)
 
static void buspirate_close (struct programmer_t *pgm)
 
static void buspirate_reset_from_binmode (struct programmer_t *pgm)
 
static int buspirate_start_mode_bin (struct programmer_t *pgm)
 
static int buspirate_start_spi_mode_ascii (struct programmer_t *pgm)
 
static void buspirate_enable (struct programmer_t *pgm)
 
static void buspirate_disable (struct programmer_t *pgm)
 
static int buspirate_initialize (struct programmer_t *pgm, AVRPART *p)
 
static void buspirate_powerup (struct programmer_t *pgm)
 
static void buspirate_powerdown (struct programmer_t *pgm)
 
static int buspirate_cmd_bin (struct programmer_t *pgm, const unsigned char *cmd, unsigned char *res)
 
static int buspirate_cmd_ascii (struct programmer_t *pgm, const unsigned char *cmd, unsigned char *res)
 
static int buspirate_cmd (struct programmer_t *pgm, const unsigned char *cmd, unsigned char *res)
 
static int buspirate_paged_load (PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int address, unsigned int n_bytes)
 
static int buspirate_paged_write (struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int base_addr, unsigned int n_data_bytes)
 
static int buspirate_program_enable (struct programmer_t *pgm, AVRPART *p)
 
static int buspirate_chip_erase (struct programmer_t *pgm, AVRPART *p)
 
static void buspirate_setup (struct programmer_t *pgm)
 
static void buspirate_teardown (struct programmer_t *pgm)
 
void buspirate_initpgm (struct programmer_t *pgm)
 
static void buspirate_bb_enable (struct programmer_t *pgm)
 
static int buspirate_bb_getpin (struct programmer_t *pgm, int pinfunc)
 
static int buspirate_bb_setpin_internal (struct programmer_t *pgm, int pin, int value)
 
static int buspirate_bb_setpin (struct programmer_t *pgm, int pinfunc, int value)
 
static int buspirate_bb_highpulsepin (struct programmer_t *pgm, int pinfunc)
 
static void buspirate_bb_powerup (struct programmer_t *pgm)
 
static void buspirate_bb_powerdown (struct programmer_t *pgm)
 
void buspirate_bb_initpgm (struct programmer_t *pgm)
 

Variables

const char buspirate_desc [] = "Using the Bus Pirate's SPI interface for programming"
 
const char buspirate_bb_desc [] = "Using the Bus Pirate's bitbang interface for programming"
 

Macro Definition Documentation

◆ BP_FLAG_IN_BINMODE

#define BP_FLAG_IN_BINMODE   (1<<0)

◆ BP_FLAG_NOPAGEDREAD

#define BP_FLAG_NOPAGEDREAD   (1<<7)

◆ BP_FLAG_NOPAGEDWRITE

#define BP_FLAG_NOPAGEDWRITE   (1<<4)

◆ BP_FLAG_XPARM_CPUFREQ

#define BP_FLAG_XPARM_CPUFREQ   (1<<5)

◆ BP_FLAG_XPARM_FORCE_ASCII

#define BP_FLAG_XPARM_FORCE_ASCII   (1<<1)

◆ BP_FLAG_XPARM_RAWFREQ

#define BP_FLAG_XPARM_RAWFREQ   (1<<6)

◆ BP_FLAG_XPARM_RESET

#define BP_FLAG_XPARM_RESET   (1<<2)

◆ BP_FLAG_XPARM_SPIFREQ

#define BP_FLAG_XPARM_SPIFREQ   (1<<3)

◆ BP_RESET_AUX

#define BP_RESET_AUX   0x02

◆ BP_RESET_AUX2

#define BP_RESET_AUX2   0x04

◆ BP_RESET_CS

#define BP_RESET_CS   0x01

◆ PDATA

#define PDATA (   pgm)    ((struct pdata *)(pgm->cookie))

Function Documentation

◆ buspirate_bb_enable()

static void buspirate_bb_enable ( struct programmer_t pgm)
static
1187{
1188 unsigned char buf[20] = { '\0' };
1189
1191 return; /* XXX should treat as error */
1192
1193 avrdude_message(MSG_INFO, "Attempting to initiate BusPirate bitbang binary mode...\n");
1194
1195 /* Send two CRs to ensure we're not in a sub-menu of the UI if we're in ASCII mode: */
1196 buspirate_send_bin(pgm, (const unsigned char*)"\n\n", 2);
1197
1198 /* Clear input buffer: */
1199 serial_drain(&pgm->fd, 0);
1200
1201 /* == Switch to binmode - send 20x '\0' == */
1202 buspirate_send_bin(pgm, buf, sizeof(buf));
1203
1204 /* Expecting 'BBIOx' reply */
1205 memset(buf, 0, sizeof(buf));
1206 buspirate_recv_bin(pgm, buf, 5);
1207 if (sscanf((char*)buf, "BBIO%1d", &PDATA(pgm)->binmode_version) != 1) {
1208 avrdude_message(MSG_INFO, "Binary mode not confirmed: '%s'\n", buf);
1210 return;
1211 }
1212 avrdude_message(MSG_INFO, "BusPirate binmode version: %d\n",
1213 PDATA(pgm)->binmode_version);
1214
1216
1217 /* Set pin directions and an initial pin status (all high) */
1218 PDATA(pgm)->pin_dir = 0x12; /* AUX, MISO input; everything else output */
1219 buf[0] = PDATA(pgm)->pin_dir | 0x40;
1220 buspirate_send_bin(pgm, buf, 1);
1221 buspirate_recv_bin(pgm, buf, 1);
1222
1223 PDATA(pgm)->pin_val = 0x3f; /* PULLUP, AUX, MOSI, CLK, MISO, CS high */
1224 buf[0] = PDATA(pgm)->pin_val | 0x80;
1225 buspirate_send_bin(pgm, buf, 1);
1226 buspirate_recv_bin(pgm, buf, 1);
1227
1228 /* Done */
1229 return;
1230}
#define MSG_INFO
Definition avrdude.h:51
int avrdude_message(const int msglvl, const char *format,...)
Definition main.c:93
int bitbang_check_prerequisites(PROGRAMMER *pgm)
Definition bitbang.c:637
static void buspirate_reset_from_binmode(struct programmer_t *pgm)
Definition buspirate.c:445
#define BP_FLAG_IN_BINMODE
Definition buspirate.c:58
static int buspirate_recv_bin(struct programmer_t *pgm, unsigned char *buf, size_t len)
Definition buspirate.c:120
#define PDATA(pgm)
Definition buspirate.c:80
static int buspirate_send_bin(struct programmer_t *pgm, const unsigned char *data, size_t len)
Definition buspirate.c:108
#define serial_drain
Definition libavrdude.h:579
static PROGRAMMER * pgm
Definition main.c:192
char flag
Definition libavrdude.h:690
union filedescriptor fd
Definition libavrdude.h:637

References avrdude_message(), bitbang_check_prerequisites(), BP_FLAG_IN_BINMODE, buspirate_recv_bin(), buspirate_reset_from_binmode(), buspirate_send_bin(), programmer_t::fd, programmer_t::flag, MSG_INFO, PDATA, pgm, and serial_drain.

Referenced by buspirate_bb_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_bb_getpin()

static int buspirate_bb_getpin ( struct programmer_t pgm,
int  pinfunc 
)
static
1247{
1248 unsigned char buf[10];
1249 int value = 0;
1250 int pin = pgm->pinno[pinfunc];
1251
1252 if (pin & PIN_INVERSE) {
1253 pin &= PIN_MASK;
1254 value = 1;
1255 }
1256
1257 if (pin < 1 || pin > 5)
1258 return -1;
1259
1260 buf[0] = PDATA(pgm)->pin_dir | 0x40;
1261 if (buspirate_send_bin(pgm, buf, 1) < 0)
1262 return -1;
1263 /* Read all of the previously-expected-but-unread bytes */
1264 while (PDATA(pgm)->unread_bytes > 0) {
1265 if (buspirate_recv_bin(pgm, buf, 1) < 0)
1266 return -1;
1267 PDATA(pgm)->unread_bytes--;
1268 }
1269
1270 /* Now read the actual response */
1271 if (buspirate_recv_bin(pgm, buf, 1) < 0)
1272 return -1;
1273
1274 if (buf[0] & (1 << (pin - 1)))
1275 value ^= 1;
1276
1277 avrdude_message(MSG_DEBUG, "get pin %d = %d\n", pin, value);
1278
1279 return value;
1280}
#define MSG_DEBUG
Definition avrdude.h:54
#define PIN_MASK
Definition libavrdude.h:366
#define PIN_INVERSE
Definition libavrdude.h:367
unsigned int pinno[N_PINS]
Definition libavrdude.h:622

References avrdude_message(), buspirate_recv_bin(), buspirate_send_bin(), MSG_DEBUG, PDATA, pgm, PIN_INVERSE, PIN_MASK, and programmer_t::pinno.

Referenced by buspirate_bb_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_bb_highpulsepin()

static int buspirate_bb_highpulsepin ( struct programmer_t pgm,
int  pinfunc 
)
static
1319{
1320 int ret;
1321 ret = buspirate_bb_setpin(pgm, pinfunc, 1);
1322 if (ret < 0)
1323 return ret;
1324 return buspirate_bb_setpin(pgm, pinfunc, 0);
1325}
static int buspirate_bb_setpin(struct programmer_t *pgm, int pinfunc, int value)
Definition buspirate.c:1312

References buspirate_bb_setpin(), and pgm.

Referenced by buspirate_bb_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_bb_initpgm()

void buspirate_bb_initpgm ( struct programmer_t pgm)
1340{
1341 strcpy(pgm->type, "BusPirate_BB");
1342
1343 pgm_fill_old_pins(pgm); // TODO to be removed if old pin data no longer needed
1344
1346
1347 /* BusPirate itself related methods */
1354
1355 /* Chip related methods */
1363 pgm->cmd = bitbang_cmd;
1372}
int avr_write_byte_default(PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char data)
Definition avr.c:530
int avr_read_byte_default(PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char *value)
Definition avr.c:183
int bitbang_initialize(PROGRAMMER *pgm, AVRPART *p)
Definition bitbang.c:523
int bitbang_pgm_led(PROGRAMMER *pgm, int value)
Definition bitbang.c:308
int bitbang_program_enable(PROGRAMMER *pgm, AVRPART *p)
Definition bitbang.c:486
int bitbang_chip_erase(PROGRAMMER *pgm, AVRPART *p)
Definition bitbang.c:425
int bitbang_err_led(PROGRAMMER *pgm, int value)
Definition bitbang.c:302
int bitbang_cmd_tpi(PROGRAMMER *pgm, const unsigned char *cmd, int cmd_len, unsigned char *res, int res_len)
Definition bitbang.c:350
int bitbang_rdy_led(PROGRAMMER *pgm, int value)
Definition bitbang.c:296
int bitbang_vfy_led(PROGRAMMER *pgm, int value)
Definition bitbang.c:314
int bitbang_cmd(PROGRAMMER *pgm, const unsigned char *cmd, unsigned char *res)
Definition bitbang.c:325
static int buspirate_open(struct programmer_t *pgm, char *port)
Definition buspirate.c:420
static void buspirate_bb_enable(struct programmer_t *pgm)
Definition buspirate.c:1186
static void buspirate_setup(struct programmer_t *pgm)
Definition buspirate.c:1134
static void buspirate_disable(struct programmer_t *pgm)
Definition buspirate.c:773
static void buspirate_dummy_6(struct programmer_t *pgm, const char *p)
Definition buspirate.c:287
static void buspirate_bb_powerdown(struct programmer_t *pgm)
Definition buspirate.c:1332
static void buspirate_bb_powerup(struct programmer_t *pgm)
Definition buspirate.c:1327
static int buspirate_bb_highpulsepin(struct programmer_t *pgm, int pinfunc)
Definition buspirate.c:1318
static void buspirate_close(struct programmer_t *pgm)
Definition buspirate.c:439
static int buspirate_bb_getpin(struct programmer_t *pgm, int pinfunc)
Definition buspirate.c:1246
static void buspirate_teardown(struct programmer_t *pgm)
Definition buspirate.c:1146
int pgm_fill_old_pins(struct programmer_t *const pgm)
Definition pindefs.c:120
void(* display)(struct programmer_t *pgm, const char *p)
Definition libavrdude.h:644
int(* open)(struct programmer_t *pgm, char *port)
Definition libavrdude.h:657
int(* read_byte)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned long addr, unsigned char *value)
Definition libavrdude.h:670
void(* powerup)(struct programmer_t *pgm)
Definition libavrdude.h:647
int(* getpin)(struct programmer_t *pgm, int pinfunc)
Definition libavrdude.h:679
void(* teardown)(struct programmer_t *pgm)
Definition libavrdude.h:685
int(* vfy_led)(struct programmer_t *pgm, int value)
Definition libavrdude.h:642
int(* setpin)(struct programmer_t *pgm, int pinfunc, int value)
Definition libavrdude.h:678
int(* cmd_tpi)(struct programmer_t *pgm, const unsigned char *cmd, int cmd_len, unsigned char res[], int res_len)
Definition libavrdude.h:653
int(* cmd)(struct programmer_t *pgm, const unsigned char *cmd, unsigned char *res)
Definition libavrdude.h:651
int(* pgm_led)(struct programmer_t *pgm, int value)
Definition libavrdude.h:641
void(* enable)(struct programmer_t *pgm)
Definition libavrdude.h:645
int(* rdy_led)(struct programmer_t *pgm, int value)
Definition libavrdude.h:639
int(* err_led)(struct programmer_t *pgm, int value)
Definition libavrdude.h:640
int(* highpulsepin)(struct programmer_t *pgm, int pinfunc)
Definition libavrdude.h:680
int(* program_enable)(struct programmer_t *pgm, AVRPART *p)
Definition libavrdude.h:649
int(* write_byte)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned long addr, unsigned char value)
Definition libavrdude.h:668
void(* setup)(struct programmer_t *pgm)
Definition libavrdude.h:684
char type[PGM_TYPELEN]
Definition libavrdude.h:619
int(* initialize)(struct programmer_t *pgm, AVRPART *p)
Definition libavrdude.h:643
void(* close)(struct programmer_t *pgm)
Definition libavrdude.h:658
int(* chip_erase)(struct programmer_t *pgm, AVRPART *p)
Definition libavrdude.h:650
void(* disable)(struct programmer_t *pgm)
Definition libavrdude.h:646
void(* powerdown)(struct programmer_t *pgm)
Definition libavrdude.h:648

References avr_read_byte_default(), avr_write_byte_default(), bitbang_chip_erase(), bitbang_cmd(), bitbang_cmd_tpi(), bitbang_err_led(), bitbang_initialize(), bitbang_pgm_led(), bitbang_program_enable(), bitbang_rdy_led(), bitbang_vfy_led(), buspirate_bb_enable(), buspirate_bb_getpin(), buspirate_bb_highpulsepin(), buspirate_bb_powerdown(), buspirate_bb_powerup(), buspirate_bb_setpin(), buspirate_close(), buspirate_disable(), buspirate_dummy_6(), buspirate_open(), buspirate_setup(), buspirate_teardown(), programmer_t::chip_erase, programmer_t::close, programmer_t::cmd, programmer_t::cmd_tpi, programmer_t::disable, programmer_t::display, programmer_t::enable, programmer_t::err_led, programmer_t::getpin, programmer_t::highpulsepin, programmer_t::initialize, programmer_t::open, pgm, pgm_fill_old_pins(), programmer_t::pgm_led, programmer_t::powerdown, programmer_t::powerup, programmer_t::program_enable, programmer_t::rdy_led, programmer_t::read_byte, programmer_t::setpin, programmer_t::setup, programmer_t::teardown, programmer_t::type, programmer_t::vfy_led, and programmer_t::write_byte.

+ Here is the call graph for this function:

◆ buspirate_bb_powerdown()

static void buspirate_bb_powerdown ( struct programmer_t pgm)
static
1333{
1335}
static int buspirate_bb_setpin_internal(struct programmer_t *pgm, int pin, int value)
Definition buspirate.c:1282

References buspirate_bb_setpin_internal(), and pgm.

Referenced by buspirate_bb_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_bb_powerup()

static void buspirate_bb_powerup ( struct programmer_t pgm)
static
1328{
1330}

References buspirate_bb_setpin_internal(), and pgm.

Referenced by buspirate_bb_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_bb_setpin()

static int buspirate_bb_setpin ( struct programmer_t pgm,
int  pinfunc,
int  value 
)
static
1313{
1314 return buspirate_bb_setpin_internal(pgm, pgm->pinno[pinfunc], value);
1315}

References buspirate_bb_setpin_internal(), pgm, and programmer_t::pinno.

Referenced by buspirate_bb_highpulsepin(), and buspirate_bb_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_bb_setpin_internal()

static int buspirate_bb_setpin_internal ( struct programmer_t pgm,
int  pin,
int  value 
)
static
1283{
1284 unsigned char buf[10];
1285
1286 if (pin & PIN_INVERSE) {
1287 value = !value;
1288 pin &= PIN_MASK;
1289 }
1290
1291 if ((pin < 1 || pin > 5) && (pin != 7)) // 7 is POWER
1292 return -1;
1293
1294 avrdude_message(MSG_DEBUG, "set pin %d = %d\n", pin, value);
1295
1296 if (value)
1297 PDATA(pgm)->pin_val |= (1 << (pin - 1));
1298 else
1299 PDATA(pgm)->pin_val &= ~(1 << (pin - 1));
1300
1301 buf[0] = PDATA(pgm)->pin_val | 0x80;
1302 if (buspirate_send_bin(pgm, buf, 1) < 0)
1303 return -1;
1304 /* We'll get a byte back, but we don't need to read it now.
1305 This is just a quick optimization that saves some USB
1306 round trips, improving read times by a factor of 3. */
1307 PDATA(pgm)->unread_bytes++;
1308
1309 return 0;
1310}

References avrdude_message(), buspirate_send_bin(), MSG_DEBUG, PDATA, pgm, PIN_INVERSE, and PIN_MASK.

Referenced by buspirate_bb_powerdown(), buspirate_bb_powerup(), and buspirate_bb_setpin().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_chip_erase()

static int buspirate_chip_erase ( struct programmer_t pgm,
AVRPART p 
)
static
1109{
1110 unsigned char cmd[4];
1111 unsigned char res[4];
1112
1113 if (p->op[AVR_OP_CHIP_ERASE] == NULL) {
1114 avrdude_message(MSG_INFO, "chip erase instruction not defined for part \"%s\"\n",
1115 p->desc);
1116 return -1;
1117 }
1118
1119 pgm->pgm_led(pgm, ON);
1120
1121 memset(cmd, 0, sizeof(cmd));
1122
1124 pgm->cmd(pgm, cmd, res);
1126 pgm->initialize(pgm, p);
1127
1128 pgm->pgm_led(pgm, OFF);
1129
1130 return 0;
1131}
int avr_set_bits(OPCODE *op, unsigned char *cmd)
Definition avrpart.c:80
#define OFF
Definition libavrdude.h:585
@ AVR_OP_CHIP_ERASE
Definition libavrdude.h:156
int chip_erase_delay
Definition libavrdude.h:222
char desc[AVR_DESCLEN]
Definition libavrdude.h:218
OPCODE * op[AVR_OP_MAX]
Definition libavrdude.h:275
#define ON
Definition libavrdude.h:584
struct command cmd[]
Definition term.c:94
int usleep(unsigned usec)
Definition unistd.cpp:13

References AVR_OP_CHIP_ERASE, avr_set_bits(), avrdude_message(), avrpart::chip_erase_delay, programmer_t::cmd, cmd, avrpart::desc, programmer_t::initialize, MSG_INFO, OFF, ON, avrpart::op, pgm, programmer_t::pgm_led, and usleep().

Referenced by buspirate_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_close()

static void buspirate_close ( struct programmer_t pgm)
static
440{
442 pgm->fd.ifd = -1;
443}
#define serial_close
Definition libavrdude.h:576
int ifd
Definition libavrdude.h:522

References programmer_t::fd, filedescriptor::ifd, pgm, and serial_close.

Referenced by buspirate_bb_initpgm(), and buspirate_initpgm().

+ Here is the caller graph for this function:

◆ buspirate_cmd()

static int buspirate_cmd ( struct programmer_t pgm,
const unsigned char *  cmd,
unsigned char *  res 
)
static
895{
897 return buspirate_cmd_bin(pgm, cmd, res);
898 else
899 return buspirate_cmd_ascii(pgm, cmd, res);
900}
static int buspirate_cmd_bin(struct programmer_t *pgm, const unsigned char *cmd, unsigned char *res)
Definition buspirate.c:838
static int buspirate_cmd_ascii(struct programmer_t *pgm, const unsigned char *cmd, unsigned char *res)
Definition buspirate.c:856

References BP_FLAG_IN_BINMODE, buspirate_cmd_ascii(), buspirate_cmd_bin(), cmd, programmer_t::flag, and pgm.

Referenced by buspirate_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_cmd_ascii()

static int buspirate_cmd_ascii ( struct programmer_t pgm,
const unsigned char *  cmd,
unsigned char *  res 
)
static
859{
860 char buf[25];
861 char *rcvd;
862 int spi_write, spi_read, i = 0;
863
864 snprintf(buf, sizeof(buf), "0x%02x 0x%02x 0x%02x 0x%02x\n",
865 cmd[0], cmd[1], cmd[2], cmd[3]);
866 buspirate_send(pgm, buf);
867 while (i < 4) {
868 rcvd = buspirate_readline(pgm, NULL, 0);
869 if (rcvd == NULL) {
870 return -1;
871 }
872 /* WRITE: 0xAC READ: 0x04 */
873 if (sscanf(rcvd, "WRITE: 0x%2x READ: 0x%2x", &spi_write, &spi_read) == 2) {
874 res[i++] = spi_read;
875 }
876 if (buspirate_is_prompt(rcvd))
877 break;
878 }
879
880 if (i != 4) {
881 avrdude_message(MSG_INFO, "%s: error: SPI has not read 4 bytes back\n", progname);
882 return -1;
883 }
884
885 /* wait for prompt */
886 while (buspirate_getc(pgm) != '>')
887 /* do nothing */;
888
889 return 0;
890}
char * progname
Definition main.c:61
static int buspirate_getc(struct programmer_t *pgm)
Definition buspirate.c:159
static int buspirate_is_prompt(const char *str)
Definition buspirate.c:250
static char * buspirate_readline(struct programmer_t *pgm, char *buf, size_t len)
Definition buspirate.c:212
static int buspirate_send(struct programmer_t *pgm, const char *str)
Definition buspirate.c:224
#define snprintf
Definition unistd.h:49

References avrdude_message(), buspirate_getc(), buspirate_is_prompt(), buspirate_readline(), buspirate_send(), cmd, MSG_INFO, pgm, progname, and snprintf.

Referenced by buspirate_cmd().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_cmd_bin()

static int buspirate_cmd_bin ( struct programmer_t pgm,
const unsigned char *  cmd,
unsigned char *  res 
)
static
841{
842 /* 0001xxxx - Bulk transfer, send/read 1-16 bytes (0=1byte!)
843 * we are sending 4 bytes -> 0x13 */
844 int rv = buspirate_expect_bin_byte(pgm, 0x13, 0x01);
845 if (rv < 0)
846 return -1;
847 if (rv == 0)
848 return -1;
849
851 buspirate_recv_bin(pgm, res, 4);
852
853 return 0;
854}
static int buspirate_expect_bin_byte(struct programmer_t *pgm, unsigned char send_byte, unsigned char expect_byte)
Definition buspirate.c:151

References buspirate_expect_bin_byte(), buspirate_recv_bin(), buspirate_send_bin(), cmd, and pgm.

Referenced by buspirate_cmd().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_disable()

static void buspirate_disable ( struct programmer_t pgm)
static
774{
775 if (pgm->flag & BP_FLAG_IN_BINMODE) {
778 } else {
779 buspirate_expect(pgm, "#\n", "RESET", 1);
780 }
781}
static int buspirate_expect(struct programmer_t *pgm, char *send, char *expect, int wait_for_prompt)
Definition buspirate.c:258
long serial_recv_timeout
Definition ser_posix.c:47

References BP_FLAG_IN_BINMODE, buspirate_expect(), buspirate_reset_from_binmode(), programmer_t::flag, pgm, and serial_recv_timeout.

Referenced by buspirate_bb_initpgm(), and buspirate_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_dummy_6()

static void buspirate_dummy_6 ( struct programmer_t pgm,
const char *  p 
)
static
288{
289}

Referenced by buspirate_bb_initpgm(), and buspirate_initpgm().

+ Here is the caller graph for this function:

◆ buspirate_enable()

static void buspirate_enable ( struct programmer_t pgm)
static
706{
707 static const char *reset_str = "#\n";
708 static const char *accept_str = "y\n";
709 char *rcvd;
710 int rc, print_banner = 0;
711
712 /* Ensure configuration is self-consistant: */
714 return; /* XXX should handle error */
715
716 /* Attempt to start binary SPI mode unless explicitly told otherwise: */
718 avrdude_message(MSG_INFO, "Attempting to initiate BusPirate binary mode...\n");
719
720 /* Send two CRs to ensure we're not in a sub-menu of the UI if we're in ASCII mode: */
721 buspirate_send_bin(pgm, (const unsigned char*)"\n\n", 2);
722
723 /* Clear input buffer: */
724 serial_drain(&pgm->fd, 0);
725
726 /* Attempt to enter binary mode: */
728 return;
729 else
730 avrdude_message(MSG_INFO, "%s: Failed to start binary mode, falling back to ASCII...\n", progname);
731 }
732
733 avrdude_message(MSG_INFO, "Attempting to initiate BusPirate ASCII mode...\n");
734
735 /* Call buspirate_send_bin() instead of buspirate_send()
736 * because we don't know if BP is in text or bin mode */
737 rc = buspirate_send_bin(pgm, (const unsigned char*)reset_str, strlen(reset_str));
738 if (rc) {
739 avrdude_message(MSG_INFO, "BusPirate is not responding. Serial port error: %d\n", rc);
740 return;
741 }
742
743 while(1) {
744 rcvd = buspirate_readline_noexit(pgm, NULL, 0);
745 if (! rcvd) {
746 avrdude_message(MSG_INFO, "%s: Fatal: Programmer is not responding.\n", progname);
747 return;
748 }
749 if (strncmp(rcvd, "Are you sure?", 13) == 0) {
750 buspirate_send_bin(pgm, (const unsigned char*)accept_str, strlen(accept_str));
751 }
752 if (strncmp(rcvd, "RESET", 5) == 0) {
753 print_banner = 1;
754 continue;
755 }
756 if (buspirate_is_prompt(rcvd)) {
757 avrdude_message(MSG_DEBUG, "**\n");
758 break;
759 }
760 if (print_banner)
761 avrdude_message(MSG_DEBUG, "** %s", rcvd);
762 }
763
764 if (!(pgm->flag & BP_FLAG_IN_BINMODE)) {
765 avrdude_message(MSG_INFO, "BusPirate: using ASCII mode\n");
767 avrdude_message(MSG_INFO, "%s: Failed to start ascii SPI mode\n", progname);
768 return;
769 }
770 }
771}
static int buspirate_start_mode_bin(struct programmer_t *pgm)
Definition buspirate.c:491
static int buspirate_uses_ascii(struct programmer_t *pgm)
Definition buspirate.c:84
static int buspirate_start_spi_mode_ascii(struct programmer_t *pgm)
Definition buspirate.c:646
static int buspirate_verifyconfig(struct programmer_t *pgm)
Definition buspirate.c:399
static char * buspirate_readline_noexit(struct programmer_t *pgm, char *buf, size_t len)
Definition buspirate.c:175

References avrdude_message(), BP_FLAG_IN_BINMODE, buspirate_is_prompt(), buspirate_readline_noexit(), buspirate_send_bin(), buspirate_start_mode_bin(), buspirate_start_spi_mode_ascii(), buspirate_uses_ascii(), buspirate_verifyconfig(), programmer_t::fd, programmer_t::flag, MSG_DEBUG, MSG_INFO, pgm, progname, and serial_drain.

Referenced by buspirate_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_expect()

static int buspirate_expect ( struct programmer_t pgm,
char *  send,
char *  expect,
int  wait_for_prompt 
)
static
260{
261 int got_it = 0;
262 size_t expect_len = strlen(expect);
263 char *rcvd;
264
265 buspirate_send(pgm, send);
266 while (1) {
267 rcvd = buspirate_readline(pgm, NULL, 0);
268 if (rcvd == NULL) {
269 return -1;
270 }
271 if (strncmp(rcvd, expect, expect_len) == 0) {
272 if (! wait_for_prompt) {
273 serial_drain(&pgm->fd, 0);
274 return 1;
275 } else {
276 got_it = 1;
277 }
278 }
279
280 if (buspirate_is_prompt(rcvd))
281 break;
282 }
283 return got_it;
284}

References buspirate_is_prompt(), buspirate_readline(), buspirate_send(), programmer_t::fd, pgm, and serial_drain.

Referenced by buspirate_disable(), buspirate_powerdown(), buspirate_powerup(), and buspirate_program_enable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_expect_bin()

static int buspirate_expect_bin ( struct programmer_t pgm,
unsigned char *  send_data,
size_t  send_len,
unsigned char *  expect_data,
size_t  expect_len 
)
static
137{
138 unsigned char *recv_buf = alloca(expect_len);
139 if ((pgm->flag & BP_FLAG_IN_BINMODE) == 0) {
140 avrdude_message(MSG_INFO, "BusPirate: Internal error: buspirate_send_bin() called from ascii mode\n");
141 return -1;
142 }
143
144 buspirate_send_bin(pgm, send_data, send_len);
145 buspirate_recv_bin(pgm, recv_buf, expect_len);
146 if (memcmp(expect_data, recv_buf, expect_len) != 0)
147 return 0;
148 return 1;
149}

References avrdude_message(), BP_FLAG_IN_BINMODE, buspirate_recv_bin(), buspirate_send_bin(), programmer_t::flag, MSG_INFO, and pgm.

Referenced by buspirate_expect_bin_byte().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_expect_bin_byte()

static int buspirate_expect_bin_byte ( struct programmer_t pgm,
unsigned char  send_byte,
unsigned char  expect_byte 
)
static
153{
154 return buspirate_expect_bin(pgm, &send_byte, 1, &expect_byte, 1);
155}
static int buspirate_expect_bin(struct programmer_t *pgm, unsigned char *send_data, size_t send_len, unsigned char *expect_data, size_t expect_len)
Definition buspirate.c:134

References buspirate_expect_bin(), and pgm.

Referenced by buspirate_cmd_bin(), buspirate_program_enable(), buspirate_reset_from_binmode(), and buspirate_start_mode_bin().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_getc()

static int buspirate_getc ( struct programmer_t pgm)
static
160{
161 int rc;
162 unsigned char ch = 0;
163
164 if (pgm->flag & BP_FLAG_IN_BINMODE) {
165 avrdude_message(MSG_INFO, "BusPirate: Internal error: buspirate_getc() called from binmode\n");
166 return EOF;
167 }
168
169 rc = serial_recv(&pgm->fd, &ch, 1);
170 if (rc < 0)
171 return EOF;
172 return ch;
173}
#define serial_recv
Definition libavrdude.h:578

References avrdude_message(), BP_FLAG_IN_BINMODE, programmer_t::fd, programmer_t::flag, MSG_INFO, pgm, and serial_recv.

Referenced by buspirate_cmd_ascii(), and buspirate_readline_noexit().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_initialize()

static int buspirate_initialize ( struct programmer_t pgm,
AVRPART p 
)
static
784{
785 pgm->powerup(pgm);
786
787 return pgm->program_enable(pgm, p);
788}

References pgm, programmer_t::powerup, and programmer_t::program_enable.

Referenced by buspirate_initpgm().

+ Here is the caller graph for this function:

◆ buspirate_initpgm()

void buspirate_initpgm ( struct programmer_t pgm)
1153{
1154 strcpy(pgm->type, "BusPirate");
1155
1157
1158 /* BusPirate itself related methods */
1164
1165 /* Chip related methods */
1173
1176
1177 /* Support functions */
1179
1182}
static void buspirate_powerdown(struct programmer_t *pgm)
Definition buspirate.c:820
static int buspirate_paged_write(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int base_addr, unsigned int n_data_bytes)
Definition buspirate.c:960
static int buspirate_paged_load(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int address, unsigned int n_bytes)
Definition buspirate.c:903
static void buspirate_powerup(struct programmer_t *pgm)
Definition buspirate.c:790
static int buspirate_chip_erase(struct programmer_t *pgm, AVRPART *p)
Definition buspirate.c:1108
static int buspirate_parseextparms(struct programmer_t *pgm, LISTID extparms)
Definition buspirate.c:293
static void buspirate_enable(struct programmer_t *pgm)
Definition buspirate.c:705
static int buspirate_program_enable(struct programmer_t *pgm, AVRPART *p)
Definition buspirate.c:1078
static int buspirate_cmd(struct programmer_t *pgm, const unsigned char *cmd, unsigned char *res)
Definition buspirate.c:892
static int buspirate_initialize(struct programmer_t *pgm, AVRPART *p)
Definition buspirate.c:783
int(* paged_write)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int baseaddr, unsigned int n_bytes)
Definition libavrdude.h:659
int(* paged_load)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int baseaddr, unsigned int n_bytes)
Definition libavrdude.h:662
int(* parseextparams)(struct programmer_t *pgm, LISTID xparams)
Definition libavrdude.h:683

References avr_read_byte_default(), avr_write_byte_default(), buspirate_chip_erase(), buspirate_close(), buspirate_cmd(), buspirate_disable(), buspirate_dummy_6(), buspirate_enable(), buspirate_initialize(), buspirate_open(), buspirate_paged_load(), buspirate_paged_write(), buspirate_parseextparms(), buspirate_powerdown(), buspirate_powerup(), buspirate_program_enable(), buspirate_setup(), buspirate_teardown(), programmer_t::chip_erase, programmer_t::close, programmer_t::cmd, programmer_t::disable, programmer_t::display, programmer_t::enable, programmer_t::initialize, programmer_t::open, programmer_t::paged_load, programmer_t::paged_write, programmer_t::parseextparams, pgm, programmer_t::powerdown, programmer_t::powerup, programmer_t::program_enable, programmer_t::read_byte, programmer_t::setup, programmer_t::teardown, programmer_t::type, and programmer_t::write_byte.

+ Here is the call graph for this function:

◆ buspirate_is_prompt()

static int buspirate_is_prompt ( const char *  str)
static
251{
252 int strlen_str = (int)strlen(str);
253 /* Prompt ends with '>' or '> '
254 * all other input probably ends with '\n' */
255 return (str[strlen_str - 1] == '>' || str[strlen_str - 2] == '>');
256}

Referenced by buspirate_cmd_ascii(), buspirate_enable(), buspirate_expect(), buspirate_reset_from_binmode(), and buspirate_start_spi_mode_ascii().

+ Here is the caller graph for this function:

◆ buspirate_open()

static int buspirate_open ( struct programmer_t pgm,
char *  port 
)
static
421{
422 union pinfo pinfo;
423 /* BusPirate runs at 115200 by default */
424 if(pgm->baudrate == 0)
425 pgm->baudrate = 115200;
426
428 strcpy(pgm->port, port);
429 if (serial_open(port, pinfo, &pgm->fd)==-1) {
430 return -1;
431 }
432
433 /* drain any extraneous input */
434 serial_drain(&pgm->fd, 0);
435
436 return 0;
437}
#define serial_open
Definition libavrdude.h:574
long baud
Definition libavrdude.h:537
Definition libavrdude.h:536
char port[PGM_PORTLEN]
Definition libavrdude.h:620
int baudrate
Definition libavrdude.h:630

References pinfo::baud, programmer_t::baudrate, programmer_t::fd, pgm, programmer_t::port, serial_drain, and serial_open.

Referenced by buspirate_bb_initpgm(), and buspirate_initpgm().

+ Here is the caller graph for this function:

◆ buspirate_paged_load()

static int buspirate_paged_load ( PROGRAMMER pgm,
AVRPART p,
AVRMEM m,
unsigned int  page_size,
unsigned int  address,
unsigned int  n_bytes 
)
static
910{
911 unsigned char commandbuf[10];
912 unsigned char buf[275];
913 unsigned int addr = 0;
914
915 avrdude_message(MSG_NOTICE, "BusPirate: buspirate_paged_load(..,%s,%d,%d,%d)\n",m->desc,m->page_size,address,n_bytes);
916
917 // This should never happen, but still...
919 avrdude_message(MSG_INFO, "BusPirate: buspirate_paged_load() called while in nopagedread mode!\n");
920 return -1;
921 }
922
923 // determine what type of memory to read, only flash is supported
924 if (strcmp(m->desc, "flash") != 0) {
925 return -1;
926 }
927
928 // send command to read data
929 commandbuf[0] = 6;
930 commandbuf[1] = 2;
931
932 // send start address (in WORDS, not bytes!)
933 commandbuf[2] = (address >> 1 >> 24) & 0xff;
934 commandbuf[3] = (address >> 1>> 16) & 0xff;
935 commandbuf[4] = (address >> 1 >> 8) & 0xff;
936 commandbuf[5] = (address >> 1) & 0xff;
937
938 // send number of bytes to fetch (in BYTES)
939 commandbuf[6] = (n_bytes >> 24) & 0xff;
940 commandbuf[7] = (n_bytes >> 16) & 0xff;
941 commandbuf[8] = (n_bytes >> 8) & 0xff;
942 commandbuf[9] = (n_bytes) & 0xff;
943
944 buspirate_send_bin(pgm, commandbuf, 10);
945 buspirate_recv_bin(pgm, buf, 1);
946 buspirate_recv_bin(pgm, buf, 1);
947
948 if (buf[0] != 0x01) {
949 avrdude_message(MSG_INFO, "BusPirate: Paged Read command returned zero.\n");
950 return -1;
951 }
952
953 for (addr = 0; addr < n_bytes; addr++) {
954 buspirate_recv_bin(pgm, &m->buf[addr+address], 1);
955 }
956
957 return n_bytes;
958}
#define MSG_NOTICE
Definition avrdude.h:52
#define BP_FLAG_NOPAGEDREAD
Definition buspirate.c:65
unsigned char * buf
Definition libavrdude.h:304
int page_size
Definition libavrdude.h:287
char desc[AVR_MEMDESCLEN]
Definition libavrdude.h:284

References avrdude_message(), BP_FLAG_NOPAGEDREAD, avrmem::buf, buspirate_recv_bin(), buspirate_send_bin(), avrmem::desc, programmer_t::flag, MSG_INFO, MSG_NOTICE, avrmem::page_size, and pgm.

Referenced by buspirate_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_paged_write()

static int buspirate_paged_write ( struct programmer_t pgm,
AVRPART p,
AVRMEM m,
unsigned int  page_size,
unsigned int  base_addr,
unsigned int  n_data_bytes 
)
static
966{
967 int page, i;
968 int addr = base_addr;
969 int n_page_writes;
970 int this_page_size;
971 unsigned char cmd_buf[4096] = {'\0'};
972 unsigned char send_byte, recv_byte;
973
974 if (!(pgm->flag & BP_FLAG_IN_BINMODE)) {
975 /* Return if we are not in binary mode. */
976 return -1;
977 }
978
980 /* Return if we've nominated not to use paged writes. */
981 return -1;
982 }
983
984 if (page_size>1024) {
985 /* Page sizes greater than 1kB not yet supported. */
986 return -1;
987 }
988
989 if (strcmp(m->desc,"flash") != 0) {
990 /* Only flash memory currently supported. */
991 return -1;
992 }
993
994 /* pre-check opcodes */
995 if (m->op[AVR_OP_LOADPAGE_LO] == NULL) {
996 avrdude_message(MSG_INFO, "%s failure: %s command not defined for %s\n",
997 progname, "AVR_OP_LOADPAGE_LO", p->desc);
998 return -1;
999 }
1000 if (m->op[AVR_OP_LOADPAGE_HI] == NULL) {
1001 avrdude_message(MSG_INFO, "%s failure: %s command not defined for %s\n",
1002 progname, "AVR_OP_LOADPAGE_HI", p->desc);
1003 return -1;
1004 }
1005
1006 /* Calculate total number of page writes needed: */
1007 n_page_writes = n_data_bytes/page_size;
1008 if (n_data_bytes%page_size >0)
1009 n_page_writes++;
1010
1011 /* Ensure error LED is off: */
1012 pgm->err_led(pgm, OFF);
1013
1014 /* Loop over pages: */
1015 for (page=0; page<n_page_writes; page++) {
1016
1017 /* Determine bytes to write in this page: */
1018 this_page_size = page_size;
1019 if (page == n_page_writes-1)
1020 this_page_size = n_data_bytes - page_size*page;
1021
1022 /* Set up command buffer: */
1023 memset(cmd_buf, 0, 4*this_page_size);
1024 for (i=0; i<this_page_size; i++) {
1025
1026 addr = base_addr + page*page_size + i;
1027
1028 if (i%2 == 0) {
1029 avr_set_bits(m->op[AVR_OP_LOADPAGE_LO], &(cmd_buf[4*i]));
1030 avr_set_addr(m->op[AVR_OP_LOADPAGE_LO], &(cmd_buf[4*i]), addr/2);
1031 avr_set_input(m->op[AVR_OP_LOADPAGE_LO], &(cmd_buf[4*i]), m->buf[addr]);
1032 } else {
1033 avr_set_bits(m->op[AVR_OP_LOADPAGE_HI], &(cmd_buf[4*i]));
1034 avr_set_addr(m->op[AVR_OP_LOADPAGE_HI], &(cmd_buf[4*i]), addr/2);
1035 avr_set_input(m->op[AVR_OP_LOADPAGE_HI], &(cmd_buf[4*i]), m->buf[addr]);
1036 }
1037 }
1038
1039 /* 00000100 - Write then read */
1040 send_byte = 0x05;
1041 buspirate_send_bin(pgm, &send_byte, 1);
1042
1043 /* Number of bytes to write: */
1044 send_byte = (4*this_page_size)/0x100;
1045 buspirate_send_bin(pgm, &send_byte, 1); /* High byte */
1046 send_byte = (4*this_page_size)%0x100;
1047 buspirate_send_bin(pgm, &send_byte, 1); /* Low byte */
1048
1049 /* Number of bytes to read: */
1050 send_byte = 0x0;
1051 buspirate_send_bin(pgm, &send_byte, 1); /* High byte */
1052 buspirate_send_bin(pgm, &send_byte, 1); /* Low byte */
1053
1054 /* Set programming LED: */
1055 pgm->pgm_led(pgm, ON);
1056
1057 /* Send command buffer: */
1058 buspirate_send_bin(pgm, cmd_buf, 4*this_page_size);
1059
1060 /* Check for write failure: */
1061 if ((buspirate_recv_bin(pgm, &recv_byte, 1) == EOF) || (recv_byte != 0x01)) {
1062 avrdude_message(MSG_INFO, "BusPirate: Fatal error: Write Then Read did not succeed.\n");
1063 pgm->pgm_led(pgm, OFF);
1064 pgm->err_led(pgm, ON);
1065 return -1;
1066 }
1067
1068 /* Unset programming LED: */
1069 pgm->pgm_led(pgm, OFF);
1070
1071 /* Write loaded page to flash: */
1072 avr_write_page(pgm, p, m, addr);
1073 }
1074
1075 return n_data_bytes;
1076}
int avr_write_page(PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr)
Definition avr.c:470
int avr_set_input(OPCODE *op, unsigned char *cmd, unsigned char data)
Definition avrpart.c:136
int avr_set_addr(OPCODE *op, unsigned char *cmd, unsigned long addr)
Definition avrpart.c:107
#define BP_FLAG_NOPAGEDWRITE
Definition buspirate.c:62
@ AVR_OP_LOADPAGE_LO
Definition libavrdude.h:152
@ AVR_OP_LOADPAGE_HI
Definition libavrdude.h:153
OPCODE * op[AVR_OP_MAX]
Definition libavrdude.h:306

References AVR_OP_LOADPAGE_HI, AVR_OP_LOADPAGE_LO, avr_set_addr(), avr_set_bits(), avr_set_input(), avr_write_page(), avrdude_message(), BP_FLAG_IN_BINMODE, BP_FLAG_NOPAGEDWRITE, avrmem::buf, buspirate_recv_bin(), buspirate_send_bin(), avrpart::desc, avrmem::desc, programmer_t::err_led, programmer_t::flag, MSG_INFO, OFF, ON, avrmem::op, pgm, programmer_t::pgm_led, and progname.

Referenced by buspirate_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_parseextparms()

static int buspirate_parseextparms ( struct programmer_t pgm,
LISTID  extparms 
)
static
294{
295 LNODEID ln;
296 const char *extended_param;
297 char reset[10];
298 char *preset = reset; /* for strtok() */
299 unsigned int spifreq;
300 unsigned int rawfreq;
301 unsigned int cpufreq;
303
304 for (ln = lfirst(extparms); ln; ln = lnext(ln)) {
305 extended_param = ldata(ln);
306 if (strcmp(extended_param, "ascii") == 0) {
308 continue;
309 }
310
311 if (sscanf(extended_param, "spifreq=%u", &spifreq) == 1) {
312 if (spifreq & (~0x07)) {
313 avrdude_message(MSG_INFO, "BusPirate: spifreq must be between 0 and 7.\n");
314 avrdude_message(MSG_INFO, "BusPirate: see BusPirate manual for details.\n");
315 return -1;
316 }
318 avrdude_message(MSG_INFO, "BusPirate: set either spifreq or rawfreq\n");
319 return -1;
320 }
322 PDATA(pgm)->spifreq = spifreq;
323 continue;
324 }
325
326 if (sscanf(extended_param, "rawfreq=%u", &rawfreq) == 1) {
327 if (rawfreq >= 4) {
328 avrdude_message(MSG_INFO, "BusPirate: rawfreq must be "
329 "between 0 and 3.\n");
330 return -1;
331 }
333 avrdude_message(MSG_INFO, "BusPirate: set either spifreq or rawfreq\n");
334 return -1;
335 }
337 PDATA(pgm)->spifreq = rawfreq;
338 continue;
339 }
340
341 if (sscanf(extended_param, "cpufreq=%u", &cpufreq) == 1) {
342 /* lower limit comes from 'cpufreq > 4 * spifreq', spifreq in ascii mode is 30kHz. */
343 if (cpufreq < 125 || cpufreq > 4000) {
344 avrdude_message(MSG_INFO, "BusPirate: cpufreq must be between 125 and 4000 kHz.\n");
345 avrdude_message(MSG_INFO, "BusPirate: see BusPirate manual for details.\n");
346 return -1;
347 }
348 PDATA(pgm)->cpufreq = cpufreq;
350 continue;
351 }
352
353 if (sscanf(extended_param, "reset=%9s", reset) == 1) {
354 char *resetpin;
355 while ((resetpin = strtok(preset, ","))) {
356 preset = NULL; /* for subsequent strtok() calls */
357 if (strcasecmp(resetpin, "cs") == 0)
358 PDATA(pgm)->reset |= BP_RESET_CS;
359 else if (strcasecmp(resetpin, "aux") == 0 || strcasecmp(reset, "aux1") == 0)
360 PDATA(pgm)->reset |= BP_RESET_AUX;
361 else if (strcasecmp(resetpin, "aux2") == 0)
362 PDATA(pgm)->reset |= BP_RESET_AUX2;
363 else {
364 avrdude_message(MSG_INFO, "BusPirate: reset must be either CS or AUX.\n");
365 return -1;
366 }
367 }
369 continue;
370 }
371
372 if (strcmp(extended_param, "nopagedwrite") == 0) {
374 continue;
375 }
376
377 if (strcmp(extended_param, "nopagedread") == 0) {
379 continue;
380 }
381
382 if (sscanf(extended_param, "serial_recv_timeout=%d", &serial_recv_timeout) == 1) {
383 if (serial_recv_timeout < 1) {
384 avrdude_message(MSG_INFO, "BusPirate: serial_recv_timeout must be greater 0.\n");
385 return -1;
386 }
387 PDATA(pgm)->serial_recv_timeout = serial_recv_timeout;
388 continue;
389 }
390
391 avrdude_message(MSG_INFO, "BusPirate: do not understand extended param '%s'.\n", extended_param);
392 return -1;
393 }
394
395 return 0;
396}
#define BP_FLAG_XPARM_RESET
Definition buspirate.c:60
#define BP_FLAG_XPARM_RAWFREQ
Definition buspirate.c:64
#define BP_RESET_CS
Definition buspirate.c:54
#define BP_RESET_AUX
Definition buspirate.c:55
#define BP_RESET_AUX2
Definition buspirate.c:56
#define BP_FLAG_XPARM_SPIFREQ
Definition buspirate.c:61
#define BP_FLAG_XPARM_CPUFREQ
Definition buspirate.c:63
#define BP_FLAG_XPARM_FORCE_ASCII
Definition buspirate.c:59
void * ldata(LNODEID)
Definition lists.c:720
void * LNODEID
Definition libavrdude.h:64
LNODEID lnext(LNODEID)
Definition lists.c:704
LNODEID lfirst(LISTID)
Definition lists.c:688
#define strcasecmp
Definition unistd.h:52

References avrdude_message(), BP_FLAG_NOPAGEDREAD, BP_FLAG_NOPAGEDWRITE, BP_FLAG_XPARM_CPUFREQ, BP_FLAG_XPARM_FORCE_ASCII, BP_FLAG_XPARM_RAWFREQ, BP_FLAG_XPARM_RESET, BP_FLAG_XPARM_SPIFREQ, BP_RESET_AUX, BP_RESET_AUX2, BP_RESET_CS, programmer_t::flag, ldata(), lfirst(), lnext(), MSG_INFO, PDATA, pgm, serial_recv_timeout, and strcasecmp.

Referenced by buspirate_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_powerdown()

static void buspirate_powerdown ( struct programmer_t pgm)
static
821{
822 if (pgm->flag & BP_FLAG_IN_BINMODE) {
823 /* Powerdown in BinMode is handled in binary mode init */
824 return;
825 } else {
827 if (!buspirate_expect(pgm, "g\n", "PWM disabled", 1)) {
828 avrdude_message(MSG_INFO, "%s: warning: did not get a response to stop PWM command.\n", progname);
829 }
830 }
831 if (buspirate_expect(pgm, "w\n", "POWER SUPPLIES OFF", 1))
832 return;
833 }
834
835 avrdude_message(MSG_INFO, "%s: warning: did not get a response to PowerDown command.\n", progname);
836}

References avrdude_message(), BP_FLAG_IN_BINMODE, BP_FLAG_XPARM_CPUFREQ, buspirate_expect(), programmer_t::flag, MSG_INFO, pgm, and progname.

Referenced by buspirate_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_powerup()

static void buspirate_powerup ( struct programmer_t pgm)
static
791{
792 if (pgm->flag & BP_FLAG_IN_BINMODE) {
793 /* Powerup in BinMode is handled in binary mode init */
794 return;
795 } else {
796 if (buspirate_expect(pgm, "W\n", "POWER SUPPLIES ON", 1)) {
798 char buf[25];
799 int ok = 0;
800 snprintf(buf, sizeof(buf), "%d\n", PDATA(pgm)->cpufreq);
801 if (buspirate_expect(pgm, "g\n", "Frequency in KHz", 1)) {
802 if (buspirate_expect(pgm, buf, "Duty cycle in %", 1)) {
803 if (buspirate_expect(pgm, "50\n", "PWM active", 1)) {
804 ok = 1;
805 }
806 }
807 }
808 if(!ok) {
809 avrdude_message(MSG_INFO, "%s: warning: did not get a response to start PWM command.\n", progname);
810 }
811 }
812 return;
813 }
814 }
815
816 avrdude_message(MSG_INFO, "%s: warning: did not get a response to PowerUp command.\n", progname);
817 avrdude_message(MSG_INFO, "%s: warning: Trying to continue anyway...\n", progname);
818}

References avrdude_message(), BP_FLAG_IN_BINMODE, BP_FLAG_XPARM_CPUFREQ, buspirate_expect(), programmer_t::flag, MSG_INFO, PDATA, pgm, progname, and snprintf.

Referenced by buspirate_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_program_enable()

static int buspirate_program_enable ( struct programmer_t pgm,
AVRPART p 
)
static
1079{
1080 unsigned char cmd[4];
1081 unsigned char res[4];
1082
1083 if (pgm->flag & BP_FLAG_IN_BINMODE) {
1084 /* Clear configured reset pin(s): CS and/or AUX and/or AUX2 */
1085 PDATA(pgm)->current_peripherals_config &= ~PDATA(pgm)->reset;
1086 if (buspirate_expect_bin_byte(pgm, PDATA(pgm)->current_peripherals_config, 0x01) < 0)
1087 return -1;
1088 }
1089 else
1090 buspirate_expect(pgm, "{\n", "CS ENABLED", 1);
1091
1092 if (p->op[AVR_OP_PGM_ENABLE] == NULL) {
1093 avrdude_message(MSG_INFO, "program enable instruction not defined for part \"%s\"\n",
1094 p->desc);
1095 return -1;
1096 }
1097
1098 memset(cmd, 0, sizeof(cmd));
1100 pgm->cmd(pgm, cmd, res);
1101
1102 if (res[2] != cmd[1])
1103 return -2;
1104
1105 return 0;
1106}
@ AVR_OP_PGM_ENABLE
Definition libavrdude.h:157

References AVR_OP_PGM_ENABLE, avr_set_bits(), avrdude_message(), BP_FLAG_IN_BINMODE, buspirate_expect(), buspirate_expect_bin_byte(), programmer_t::cmd, cmd, avrpart::desc, programmer_t::flag, MSG_INFO, avrpart::op, PDATA, and pgm.

Referenced by buspirate_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_readline()

static char * buspirate_readline ( struct programmer_t pgm,
char *  buf,
size_t  len 
)
static
213{
214 char *ret;
215
216 ret = buspirate_readline_noexit(pgm, buf, len);
217 if (! ret) {
218 avrdude_message(MSG_INFO, "%s: buspirate_readline(): programmer is not responding\n",
219 progname);
220 return NULL;
221 }
222 return ret;
223}

References avrdude_message(), buspirate_readline_noexit(), MSG_INFO, pgm, and progname.

Referenced by buspirate_cmd_ascii(), buspirate_expect(), buspirate_send(), and buspirate_start_spi_mode_ascii().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_readline_noexit()

static char * buspirate_readline_noexit ( struct programmer_t pgm,
char *  buf,
size_t  len 
)
static
176{
177 char *buf_p;
178 long orig_serial_recv_timeout = serial_recv_timeout;
179
180 /* Static local buffer - this may come handy at times */
181 static char buf_local[100];
182
183 if (buf == NULL) {
184 buf = buf_local;
185 len = sizeof(buf_local);
186 }
187 buf_p = buf;
188 memset(buf, 0, len);
189 while (buf_p < (buf + len - 1)) { /* keep the very last byte == 0 */
190 *buf_p = buspirate_getc(pgm);
191 if (*buf_p == '\r')
192 continue;
193 if (*buf_p == '\n')
194 break;
195 if (*buf_p == EOF) {
196 *buf_p = '\0';
197 break;
198 }
199 buf_p++;
200 serial_recv_timeout = PDATA(pgm)->serial_recv_timeout;
201 }
202 serial_recv_timeout = orig_serial_recv_timeout;
203 avrdude_message(MSG_DEBUG, "%s: buspirate_readline(): %s%s",
204 progname, buf,
205 buf[strlen(buf) - 1] == '\n' ? "" : "\n");
206 if (! buf[0])
207 return NULL;
208
209 return buf;
210}

References avrdude_message(), buspirate_getc(), MSG_DEBUG, PDATA, pgm, progname, and serial_recv_timeout.

Referenced by buspirate_enable(), and buspirate_readline().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_recv_bin()

static int buspirate_recv_bin ( struct programmer_t pgm,
unsigned char *  buf,
size_t  len 
)
static
121{
122 int rc;
123
124 rc = serial_recv(&pgm->fd, buf, len);
125 if (rc < 0)
126 return EOF;
127
128 avrdude_message(MSG_DEBUG, "%s: buspirate_recv_bin():\n", progname);
129 dump_mem(MSG_DEBUG, buf, len);
130
131 return (int)len;
132}
static void dump_mem(const int msglvl, const unsigned char *buf, size_t len)
Definition buspirate.c:91

References avrdude_message(), dump_mem(), programmer_t::fd, MSG_DEBUG, pgm, progname, and serial_recv.

Referenced by buspirate_bb_enable(), buspirate_bb_getpin(), buspirate_cmd_bin(), buspirate_expect_bin(), buspirate_paged_load(), buspirate_paged_write(), buspirate_reset_from_binmode(), and buspirate_start_mode_bin().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_reset_from_binmode()

static void buspirate_reset_from_binmode ( struct programmer_t pgm)
static
446{
447 unsigned char buf[10];
448
449 buf[0] = 0x00; /* BinMode: revert to raw bitbang mode */
450 buspirate_send_bin(pgm, buf, 1);
451 buspirate_recv_bin(pgm, buf, 5);
452
454 /* disable pwm */
455 if (buspirate_expect_bin_byte(pgm, 0x13, 0x01) != 1) {
456 avrdude_message(MSG_INFO, "%s: warning: did not get a response to stop PWM command.\n", progname);
457 }
458 }
459 /* 0b0100wxyz - Configure peripherals w=power, x=pull-ups, y=AUX, z=CS
460 * we want everything off -- 0b01000000 = 0x40 */
461 if (buspirate_expect_bin_byte(pgm, 0x40, 0x00) == 1) {
462 avrdude_message(MSG_INFO, "%s: warning: did not get a response to power off command.\n", progname);
463 }
464
465 buf[0] = 0x0F; /* BinMode: reset */
466 buspirate_send_bin(pgm, buf, 1);
467
468 /* read back all output */
469 memset(buf, '\0', sizeof(buf));
470 for (;;) {
471 int rc;
472 rc = buspirate_recv_bin(pgm, buf, sizeof(buf) - 1);
473
474 if (buspirate_is_prompt((const char*)buf)) {
475 pgm->flag &= ~BP_FLAG_IN_BINMODE;
476 break;
477 }
478 if (rc == EOF)
479 break;
480 memset(buf, '\0', sizeof(buf));
481 }
482
483 if (pgm->flag & BP_FLAG_IN_BINMODE) {
484 avrdude_message(MSG_INFO, "BusPirate reset failed. You may need to powercycle it.\n");
485 return;
486 }
487
488 avrdude_message(MSG_NOTICE, "BusPirate is back in the text mode\n");
489}

References avrdude_message(), BP_FLAG_IN_BINMODE, BP_FLAG_XPARM_CPUFREQ, buspirate_expect_bin_byte(), buspirate_is_prompt(), buspirate_recv_bin(), buspirate_send_bin(), programmer_t::flag, MSG_INFO, MSG_NOTICE, pgm, and progname.

Referenced by buspirate_bb_enable(), buspirate_disable(), and buspirate_start_mode_bin().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_send()

static int buspirate_send ( struct programmer_t pgm,
const char *  str 
)
static
225{
226 int rc;
227 const char * readline;
228
229 avrdude_message(MSG_DEBUG, "%s: buspirate_send(): %s", progname, str);
230
231 if (pgm->flag & BP_FLAG_IN_BINMODE) {
232 avrdude_message(MSG_INFO, "BusPirate: Internal error: buspirate_send() called from binmode\n");
233 return -1;
234 }
235
236 rc = serial_send(&pgm->fd, (const unsigned char*)str, strlen(str));
237 if (rc)
238 return rc;
239 do {
240 readline = buspirate_readline(pgm, NULL, 0);
241 if (readline == NULL)
242 return -1;
243 /* keep reading until we get what we sent there */
244 } while (strcmp(readline, str) != 0);
245
246 /* by now we should be in sync */
247 return 0;
248}
#define serial_send
Definition libavrdude.h:577

References avrdude_message(), BP_FLAG_IN_BINMODE, buspirate_readline(), programmer_t::fd, programmer_t::flag, MSG_DEBUG, MSG_INFO, pgm, progname, and serial_send.

Referenced by buspirate_cmd_ascii(), buspirate_expect(), and buspirate_start_spi_mode_ascii().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_send_bin()

static int buspirate_send_bin ( struct programmer_t pgm,
const unsigned char *  data,
size_t  len 
)
static
109{
110 int rc;
111
112 avrdude_message(MSG_DEBUG, "%s: buspirate_send_bin():\n", progname);
113 dump_mem(MSG_DEBUG, data, len);
114
115 rc = serial_send(&pgm->fd, data, len);
116
117 return rc;
118}

References avrdude_message(), dump_mem(), programmer_t::fd, MSG_DEBUG, pgm, progname, and serial_send.

Referenced by buspirate_bb_enable(), buspirate_bb_getpin(), buspirate_bb_setpin_internal(), buspirate_cmd_bin(), buspirate_enable(), buspirate_expect_bin(), buspirate_paged_load(), buspirate_paged_write(), buspirate_reset_from_binmode(), and buspirate_start_mode_bin().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_setup()

static void buspirate_setup ( struct programmer_t pgm)
static
1135{
1136 /* Allocate private data */
1137 if ((pgm->cookie = calloc(1, sizeof(struct pdata))) == 0) {
1138 // avrdude_message(MSG_INFO, "%s: buspirate_initpgm(): Out of memory allocating private data\n",
1139 // progname);
1140 // exit(1);
1141 avrdude_oom("buspirate_initpgm(): Out of memory allocating private data\n");
1142 }
1143 PDATA(pgm)->serial_recv_timeout = 100;
1144}
void avrdude_oom(const char *context)
Definition main.c:169
Definition avr910.c:50
void * cookie
Definition libavrdude.h:689

References avrdude_oom(), programmer_t::cookie, PDATA, and pgm.

Referenced by buspirate_bb_initpgm(), and buspirate_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_start_mode_bin()

static int buspirate_start_mode_bin ( struct programmer_t pgm)
static
492{
493 const struct submode {
494 const char *name; /* Name of mode for user messages */
495 char enter; /* Command to enter from base binary mode */
496 const char *entered_format; /* Response, for "scanf" */
497 char config; /* Command to setup submode parameters */
498 } *submode;
499
501 submode = &(const struct submode){
502 .name = "Raw-wire",
503 .enter = 0x05,
504 .entered_format = "RAW%1d",
505 .config = 0x8C,
506 };
509 } else {
510 submode = &(const struct submode){
511 .name = "SPI",
512 .enter = 0x01,
513 .entered_format = "SPI%1d",
514
515 /* 1000wxyz - SPI config, w=HiZ(0)/3.3v(1), x=CLK idle, y=CLK edge, z=SMP sample
516 * we want: 3.3V(1), idle low(0), data change on
517 * trailing edge (1), sample in the middle
518 * of the pulse (0)
519 * => 0b10001010 = 0x8a */
520 .config = 0x8A,
521 };
522 }
523
524 unsigned char buf[20] = { '\0' };
525
526 /* == Switch to binmode - send 20x '\0' == */
527 buspirate_send_bin(pgm, buf, sizeof(buf));
528
529 /* Expecting 'BBIOx' reply */
530 memset(buf, 0, sizeof(buf));
531 buspirate_recv_bin(pgm, buf, 5);
532 if (sscanf((const char*)buf, "BBIO%1d", &PDATA(pgm)->binmode_version) != 1) {
533 avrdude_message(MSG_INFO, "Binary mode not confirmed: '%s'\n", buf);
535 return -1;
536 }
537 avrdude_message(MSG_NOTICE, "BusPirate binmode version: %d\n",
538 PDATA(pgm)->binmode_version);
539
541
543 unsigned short pwm_duty;
544 unsigned short pwm_period;
545
546 pwm_period = 16000/(PDATA(pgm)->cpufreq) - 1; // oscillator runs at 32MHz, we don't use a prescaler
547 pwm_duty = pwm_period/2; // 50% duty cycle
548
549 avrdude_message(MSG_NOTICE, "Setting up PWM for cpufreq\n");
550 avrdude_message(MSG_DEBUG, "PWM settings: Prescaler=1, Duty Cycle=%hd, Period=%hd\n", pwm_duty, pwm_period);
551
552 buf[0] = 0x12; // pwm setup
553 buf[1] = 0; // prescaler 1
554 buf[2] = (char) ((pwm_duty >> 8) & 0xff); // duty cycle register, high byte
555 buf[3] = (char) pwm_duty & 0xff; // duty cycle register, low byte
556 buf[4] = (char) ((pwm_period >> 8) & 0xff); // period register, high byte
557 buf[5] = (char) pwm_period & 0xff; // period register, low byte
558 buspirate_send_bin(pgm, buf, 6);
559
560 buspirate_recv_bin(pgm, buf, 1);
561 if (buf[0] != 0x01)
562 avrdude_message(MSG_INFO, "cpufreq (PWM) setup failed\n");
563 }
564
565 /* == Set protocol sub-mode of binary mode == */
566 buf[0] = submode->enter;
567 buspirate_send_bin(pgm, buf, 1);
568 memset(buf, 0, sizeof(buf));
569 buspirate_recv_bin(pgm, buf, 4);
570 if (sscanf((const char*)buf, submode->entered_format, &PDATA(pgm)->submode_version) != 1) {
571 avrdude_message(MSG_INFO, "%s mode not confirmed: '%s'\n",
572 submode->name, buf);
574 return -1;
575 }
576 avrdude_message(MSG_NOTICE, "BusPirate %s version: %d\n",
577 submode->name, PDATA(pgm)->submode_version);
578
580 avrdude_message(MSG_NOTICE, "%s: Paged flash write disabled.\n", progname);
581 pgm->paged_write = NULL;
582 } else {
583 /* Check for write-then-read without !CS/CS and disable paged_write if absent: */
584 static const unsigned char buf2[] = {5,0,0,0,0};
585 buspirate_send_bin(pgm, buf2, sizeof(buf2));
586 buspirate_recv_bin(pgm, buf, 1);
587 if (buf[0] != 0x01) {
588
589 /* Disable paged write: */
591 pgm->paged_write = NULL;
592
593 /* Return to SPI mode (0x00s have landed us back in binary bitbang mode): */
594 buf[0] = 0x1;
595 buspirate_send_bin(pgm, buf, 1);
596
597 avrdude_message(MSG_NOTICE, "%s: Disabling paged flash write. (Need BusPirate firmware >=v5.10.)\n", progname);
598
599 /* Flush serial buffer: */
600 serial_drain(&pgm->fd, 0);
601 } else {
602 avrdude_message(MSG_INFO, "%s: Paged flash write enabled.\n", progname);
603 }
604 }
605
606 /* 0b0100wxyz - Configure peripherals w=power, x=pull-ups/aux2, y=AUX, z=CS
607 * we want power (0x48) and all reset pins high. */
608 PDATA(pgm)->current_peripherals_config = 0x48 | PDATA(pgm)->reset;
609 if (buspirate_expect_bin_byte(pgm, PDATA(pgm)->current_peripherals_config, 0x01) < 0)
610 return -1;
611 usleep(50000); // sleep for 50ms after power up
612
613 /* 01100xxx - Set speed */
614 if (buspirate_expect_bin_byte(pgm, 0x60 | PDATA(pgm)->spifreq, 0x01) < 0)
615 return -1;
616
617 /* Submode config */
618 if (buspirate_expect_bin_byte(pgm, submode->config, 0x01) < 0)
619 return -1;
620
621 /* AVR Extended Commands - test for existence */
623 avrdude_message(MSG_NOTICE, "%s: Paged flash read disabled.\n", progname);
624 pgm->paged_load = NULL;
625 } else {
626 int rv = buspirate_expect_bin_byte(pgm, 0x06, 0x01);
627 if (rv < 0)
628 return -1;
629 if (rv) {
630 unsigned int ver = 0;
631 static const unsigned char buf2[] = {1};
632 buspirate_send_bin(pgm, buf2, sizeof(buf2));
633 buspirate_recv_bin(pgm, buf, 3);
634 ver = buf[1] << 8 | buf[2];
635 avrdude_message(MSG_NOTICE, "AVR Extended Commands version %d\n", ver);
636 } else {
637 avrdude_message(MSG_NOTICE, "AVR Extended Commands not found.\n");
639 pgm->paged_load = NULL;
640 }
641 }
642
643 return 0;
644}

References avrdude_message(), BP_FLAG_IN_BINMODE, BP_FLAG_NOPAGEDREAD, BP_FLAG_NOPAGEDWRITE, BP_FLAG_XPARM_CPUFREQ, BP_FLAG_XPARM_RAWFREQ, buspirate_expect_bin_byte(), buspirate_recv_bin(), buspirate_reset_from_binmode(), buspirate_send_bin(), programmer_t::fd, programmer_t::flag, MSG_DEBUG, MSG_INFO, MSG_NOTICE, programmer_t::paged_load, programmer_t::paged_write, PDATA, pgm, progname, serial_drain, and usleep().

Referenced by buspirate_enable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_start_spi_mode_ascii()

static int buspirate_start_spi_mode_ascii ( struct programmer_t pgm)
static
647{
648 int spi_cmd = -1;
649 int cmd;
650 char *rcvd;
651 char buf[5];
652 char mode[11];
653
654 buspirate_send(pgm, "m\n");
655 while(1) {
656 rcvd = buspirate_readline(pgm, NULL, 0);
657 if (rcvd == NULL) {
658 return -1;
659 }
660 if (spi_cmd == -1 && sscanf(rcvd, "%2d. %10s", &cmd, mode)) {
661 if (strcmp(mode, "SPI") == 0)
662 spi_cmd = cmd;
663 }
664 if (buspirate_is_prompt(rcvd))
665 break;
666 }
667 if (spi_cmd == -1) {
668 avrdude_message(MSG_INFO, "%s: SPI mode number not found. Does your BusPirate support SPI?\n",
669 progname);
670 avrdude_message(MSG_INFO, "%s: Try powercycling your BusPirate and try again.\n",
671 progname);
672 return -1;
673 }
674 snprintf(buf, sizeof(buf), "%d\n", spi_cmd);
675 buspirate_send(pgm, buf);
676 buf[0] = '\0';
677 while (1) {
678 rcvd = buspirate_readline(pgm, NULL, 0);
679 if (rcvd == NULL) {
680 return -1;
681 }
682 if (strstr(rcvd, "Normal (H=3.3V, L=GND)")) {
683 /* BP firmware 2.1 defaults to Open-drain output.
684 * That doesn't work on my board, even with pull-up
685 * resistors. Select 3.3V output mode instead. */
686 sscanf(rcvd, " %2d.", &cmd);
687 snprintf(buf, sizeof(buf), "%d\n", cmd);
688 }
689 if (buspirate_is_prompt(rcvd)) {
690 if (strncmp(rcvd, "SPI>", 4) == 0) {
691 avrdude_message(MSG_INFO, "BusPirate is now configured for SPI\n");
692 break;
693 }
694 /* Not yet 'SPI>' prompt */
695 if (buf[0]) {
696 buspirate_send(pgm, buf);
697 buf[0] = '\0';
698 } else
699 buspirate_send(pgm, "\n");
700 }
701 }
702 return 0;
703}
IGL_INLINE void mode(const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &X, const int d, Eigen::Matrix< T, Eigen::Dynamic, 1 > &M)
Definition mode.cpp:14

References avrdude_message(), buspirate_is_prompt(), buspirate_readline(), buspirate_send(), cmd, MSG_INFO, pgm, progname, and snprintf.

Referenced by buspirate_enable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_teardown()

static void buspirate_teardown ( struct programmer_t pgm)
static
1147{
1148 free(pgm->cookie);
1149}
void free(void *)

References programmer_t::cookie, free(), and pgm.

Referenced by buspirate_bb_initpgm(), and buspirate_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buspirate_uses_ascii()

static int buspirate_uses_ascii ( struct programmer_t pgm)
inlinestatic
85{
87}

References BP_FLAG_XPARM_FORCE_ASCII, programmer_t::flag, and pgm.

Referenced by buspirate_enable(), and buspirate_verifyconfig().

+ Here is the caller graph for this function:

◆ buspirate_verifyconfig()

static int buspirate_verifyconfig ( struct programmer_t pgm)
static
400{
401 /* Default reset pin is CS */
402 if (PDATA(pgm)->reset == 0x00)
403 PDATA(pgm)->reset |= BP_RESET_CS;
404
405 if ((PDATA(pgm)->reset != BP_RESET_CS) && buspirate_uses_ascii(pgm)) {
406 avrdude_message(MSG_INFO, "BusPirate: RESET pin other than CS is not supported in ASCII mode\n");
407 return -1;
408 }
409
412 avrdude_message(MSG_INFO, "BusPirate: SPI speed selection is not supported in ASCII mode\n");
413 return -1;
414 }
415
416 return 0;
417}

References avrdude_message(), BP_FLAG_XPARM_RAWFREQ, BP_FLAG_XPARM_SPIFREQ, BP_RESET_CS, buspirate_uses_ascii(), programmer_t::flag, MSG_INFO, PDATA, and pgm.

Referenced by buspirate_enable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dump_mem()

static void dump_mem ( const int  msglvl,
const unsigned char *  buf,
size_t  len 
)
static
92{
93 size_t i;
94
95 for (i = 0; i<len; i++) {
96 if (i % 8 == 0)
97 avrdude_message(msglvl, "\t");
98 avrdude_message(msglvl, "0x%02x ", buf[i]);
99 if (i % 8 == 3)
100 avrdude_message(msglvl, " ");
101 else if (i % 8 == 7)
102 avrdude_message(msglvl, "\n");
103 }
104 if (i % 8 != 7)
105 avrdude_message(msglvl, "\n");
106}

References avrdude_message().

Referenced by buspirate_recv_bin(), and buspirate_send_bin().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ buspirate_bb_desc

const char buspirate_bb_desc[] = "Using the Bus Pirate's bitbang interface for programming"

◆ buspirate_desc

const char buspirate_desc[] = "Using the Bus Pirate's SPI interface for programming"