diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 796008681..9bcf116a8 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -220,8 +220,12 @@ add_library(libavrdude
pgm_type.c
pickit2.c
pickit2.h
+ pickit5.c
+ pickit5.h
pindefs.c
ppi.c
+ scripts_lut.c
+ scripts_lut.h
ppi.h
ppiwin.c
serbb.h
diff --git a/src/Makefile.am b/src/Makefile.am
index fc9782714..a9cbde5cc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -154,6 +154,8 @@ libavrdude_a_SOURCES = \
pgm_type.c \
pickit2.c \
pickit2.h \
+ pickit5.c \
+ pickit5.h \
pindefs.c \
ppi.c \
ppi.h \
@@ -165,6 +167,8 @@ libavrdude_a_SOURCES = \
ser_posix.c \
ser_win32.c \
serialadapter.c \
+ scripts_lut.c \
+ scripts_lut.h \
solaris_ecpp.h \
stk500.c \
stk500.h \
diff --git a/src/avr.c b/src/avr.c
index ee228f47c..1d8e3ce42 100644
--- a/src/avr.c
+++ b/src/avr.c
@@ -499,6 +499,15 @@ int avr_read_mem(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem, con
}
}
+ if (pgm->read_array != NULL) { // if possible, try to read all bytes at once
+ rc = pgm->read_array(pgm, p, mem, 0, mem->size, mem->buf);
+ if (rc < 0)
+ report_progress(1, -1, NULL);
+ else
+ report_progress(mem->size, mem->size, NULL);
+ return rc;
+ }
+
for (i=0; i < (unsigned long) mem->size; i++) {
if (vmem == NULL || (vmem->tags[i] & TAG_ALLOCATED) != 0) {
rc = pgm->read_byte(pgm, p, mem, i, mem->buf + i);
diff --git a/src/avrdude.conf.in b/src/avrdude.conf.in
index 4c5cc4fc0..036c84aec 100644
--- a/src/avrdude.conf.in
+++ b/src/avrdude.conf.in
@@ -2993,6 +2993,46 @@ programmer # pickit4_tpi
usbpid = 0x2177, 0x2178, 0x2179;
;
+
+# Microchip PICkit 5. See
+# https://www.microchip.com/en-us/development-tool/PG164150
+# for details.
+#
+# Currently, avrdude only supports UPDI Programming
+# with the PICkit 5
+#
+# Interface: Programmer name:
+# UPDI pickit5
+#
+#
+# PIN UPDI
+# > 1 HVRST
+# 2 VCC
+# 3 GND
+# 4 UPDI
+# 5
+# 6
+# 7
+# 8
+#
+
+#------------------------------------------------------------
+# pickit5
+#------------------------------------------------------------
+
+programmer # pickit5
+ id = "pickit5";
+ desc = "MPLAB(R) PICkit 5";
+ type = "pickit5";
+ prog_modes = PM_UPDI;
+ extra_features = HAS_VTARG_READ;
+ connection_type = usb;
+ usbpid = 0x9035, 0x9036;
+ baudrate = 200000; # UPDI default clock
+;
+
+
+
#------------------------------------------------------------
# snap /snap_jtag
#------------------------------------------------------------
diff --git a/src/libavrdude.h b/src/libavrdude.h
index 3713a902e..c84212ff6 100644
--- a/src/libavrdude.h
+++ b/src/libavrdude.h
@@ -1004,6 +1004,8 @@ typedef struct programmer {
int (*read_sig_bytes) (const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m);
int (*read_sib) (const PROGRAMMER *pgm, const AVRPART *p, char *sib);
int (*read_chip_rev) (const PROGRAMMER *pgm, const AVRPART *p, unsigned char *chip_rev);
+ int (*write_array) (const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m, unsigned long addr, int len, unsigned char *value);
+ int (*read_array) (const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m, unsigned long addr, int len, unsigned char *value);
int (*term_keep_alive)(const PROGRAMMER *pgm, const AVRPART *p);
int (*end_programming)(const PROGRAMMER *pgm, const AVRPART *p);
diff --git a/src/pgm.c b/src/pgm.c
index 3c3de18e0..bab3197fc 100644
--- a/src/pgm.c
+++ b/src/pgm.c
@@ -131,6 +131,8 @@ void pgm_init_functions(PROGRAMMER *pgm) {
pgm->teardown = NULL;
pgm->readonly = NULL;
pgm->flash_readhook = NULL;
+ pgm->write_array = NULL;
+ pgm->read_array = NULL;
}
diff --git a/src/pgm_type.c b/src/pgm_type.c
index e439e8568..b162eccaa 100644
--- a/src/pgm_type.c
+++ b/src/pgm_type.c
@@ -46,6 +46,7 @@
#include "micronucleus.h"
#include "par.h"
#include "pickit2.h"
+#include "pickit5.h"
#include "ppi.h"
#include "serbb.h"
#include "serialupdi.h"
@@ -99,6 +100,7 @@ const PROGRAMMER_TYPE programmers_types[] = { // Name(s) the programmers call th
{"micronucleus", micronucleus_initpgm, micronucleus_desc}, // "micronucleus" or "Micronucleus V2.0"
{"par", par_initpgm, par_desc}, // "PPI"
{"pickit2", pickit2_initpgm, pickit2_desc}, // "pickit2"
+ {"pickit5", pickit5_initpgm, pickit5_desc}, // "pickit5"
{"serbb", serbb_initpgm, serbb_desc}, // "SERBB"
{"serialupdi", serialupdi_initpgm, serialupdi_desc}, // "serialupdi"
{"serprog", serprog_initpgm, serprog_desc}, // "serprog"
diff --git a/src/pickit5.c b/src/pickit5.c
new file mode 100644
index 000000000..fab8c3c68
--- /dev/null
+++ b/src/pickit5.c
@@ -0,0 +1,1129 @@
+/*
+ * avrdude - A Downloader/Uploader for AVR device programmers
+ * Copyright (C) 2024 MX682X
+ *
+ * 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
+ * along with this program. If not, see .
+ *
+ * This code is not affiliated in any way with Microchip®
+ */
+
+
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#if defined(HAVE_USB_H)
+# include
+#elif defined(HAVE_LUSB0_USB_H)
+# include
+#else
+# error "libusb needs either or "
+#endif
+
+#include "avrdude.h"
+#include "libavrdude.h"
+
+#include "pickit5.h"
+#include "scripts_lut.h"
+#include "updi_constants.h"
+#include "usbdevs.h"
+
+
+
+#if defined(HAVE_LIBUSB) || defined(HAVE_LIBUSB_1_0)
+
+#ifdef HAVE_LIBUSB_1_0
+# define USE_LIBUSB_1_0
+#endif
+
+#if defined(USE_LIBUSB_1_0)
+# if defined(HAVE_LIBUSB_1_0_LIBUSB_H)
+# include
+# else
+# include
+# endif
+#else
+# if defined(HAVE_USB_H)
+# include
+# elif defined(HAVE_LUSB0_USB_H)
+# include
+# else
+# error "libusb needs either or "
+# endif
+#endif
+
+
+#define USB_PK5_CMD_READ_EP 0x81
+#define USB_PK5_CMD_WRITE_EP 0x02
+#define USB_PK5_DATA_READ_EP 0x83
+#define USB_PK5_DATA_WRITE_EP 0x04
+
+#define USB_PK5_MAX_XFER 512
+
+#define CHECK_ERROR 0x01
+#define BIST_TEST 0x02
+#define BIST_RESULT 0x03
+
+
+// Private data for this programmer
+struct pdata {
+#ifdef USE_LIBUSB_1_0
+ libusb_device_handle *usbhandle;
+#else
+ usb_dev_handle *usbhandle;
+#endif
+ unsigned char pk_op_mode; // 0 - init, 1: pk found, 2: pk operating, 3: pk programming
+ unsigned char power_source; // external / from PICkit / ignore check
+ unsigned int target_voltage; // voltage to supply to target
+ unsigned char target_revision; // we get this together with the device ID, so just buffer it
+ unsigned char txBuf[1024];
+ unsigned char rxBuf[1024];
+ struct avr_script_lut *scripts;
+};
+
+#define PDATA(pgm) ((struct pdata *)(pgm->cookie))
+
+
+/* Prototypes */
+// interface - management
+static void pickit5_setup(PROGRAMMER *pgm);
+static void pickit5_teardown(PROGRAMMER *pgm);
+static int pickit5_parseextparms(const PROGRAMMER *pgm, const LISTID extparms);
+
+// interface - prog.
+static int pickit5_open(PROGRAMMER *pgm, const char *port);
+static void pickit5_close(PROGRAMMER *pgm);
+// dummy functions
+static void pickit5_disable(const PROGRAMMER *pgm);
+static void pickit5_enable(PROGRAMMER *pgm, const AVRPART *p);
+static void pickit5_display(const PROGRAMMER *pgm, const char *p);
+// universal functions
+static int pickit5_initialize(const PROGRAMMER *pgm, const AVRPART *p);
+// UPDI specific functions
+static int pickit5_cmd(const PROGRAMMER *pgm, const unsigned char *cmd, unsigned char *res);
+static int pickit5_program_enable(const PROGRAMMER *pgm, const AVRPART *p);
+static int pickit5_program_disable(const PROGRAMMER *pgm, const AVRPART *p);
+
+static int pickit5_chip_erase(const PROGRAMMER *pgm, const AVRPART *p);
+static int pickit5_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem,
+ unsigned int page_size, unsigned int addr, unsigned int n_bytes);
+static int pickit5_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem,
+ unsigned int page_size, unsigned int addr, unsigned int n_bytes);
+static int pickit5_write_byte (const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem,
+ unsigned long addr, unsigned char value);
+static int pickit5_read_byte (const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem,
+ unsigned long addr, unsigned char *value);
+static int pickit5_read_sig_bytes (const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem);
+static int pickit5_read_sib (const PROGRAMMER *pgm, const AVRPART *p, char *sib);
+static int pickit5_read_chip_rev (const PROGRAMMER *pgm, const AVRPART *p, unsigned char *chip_rev);
+static int pickit5_read_array (const PROGRAMMER *pgm, const AVRPART *p,
+ const AVRMEM *mem, unsigned long addr, int len, unsigned char *value);
+static int pickit5_write_array(const PROGRAMMER *pgm, const AVRPART *p,
+ const AVRMEM *mem, unsigned long addr, int len, unsigned char *value);
+// Extra Functions
+static int pickit5_get_fw_info(const PROGRAMMER *pgm);
+static int pickit5_set_vtarget (const PROGRAMMER *pgm, double v);
+static int pickit5_get_vtarget (const PROGRAMMER *pgm, double *v);
+static int pickit5_set_ptg_mode(const PROGRAMMER *pgm);
+static int pickit5_set_sck_period(const PROGRAMMER *pgm, double sckperiod);
+static int pickit5_write_cs_reg(const PROGRAMMER *pgm, unsigned int addr, unsigned char value);
+static int pickit5_read_cs_reg(const PROGRAMMER *pgm, unsigned int addr, unsigned char* value);
+
+
+// Internal Functions
+inline static void pickit5_uint32_to_array(unsigned char *buf, uint32_t num);
+inline static unsigned int pickit5_array_to_uint32(unsigned char *buf);
+inline static void pickit5_create_payload_header(unsigned char *buf, unsigned int type,
+ unsigned int msg_len, unsigned int trans_len);
+inline static void pickit5_create_script_header(unsigned char *buf, unsigned int arg_len,
+ unsigned int script_len);
+inline static int pickit5_check_ret_status(const PROGRAMMER *pgm);
+static int pickit5_get_Status(const PROGRAMMER *pgm, unsigned char status);
+
+static int pickit5_send_script(const PROGRAMMER *pgm, unsigned int script_type,
+ const unsigned char *script, unsigned int script_len,
+ const unsigned char *param, unsigned int param_len, unsigned int payload_len);
+static int pickit5_send_script_done(const PROGRAMMER *pgm, char *func);
+static int pickit5_read_response(const PROGRAMMER *pgm, char *fn_name);
+
+
+// Extra USB related Functions, because we need more then 2 Endpoints
+static int usbdev_data_recv(const union filedescriptor *fd, unsigned char *buf, size_t nbytes);
+static int usbdev_data_send(const union filedescriptor *fd, const unsigned char *bp, size_t mlen);
+
+
+inline static void pickit5_uint32_to_array(unsigned char *buf, uint32_t num) {
+ *(buf++) = (uint8_t) num;
+ *(buf++) = (uint8_t) (num >> 8);
+ *(buf++) = (uint8_t) (num >> 16);
+ *(buf) = (uint8_t) (num >> 24);
+}
+
+inline static unsigned int pickit5_array_to_uint32(unsigned char *buf) {
+ unsigned int retval = 0;
+ retval |= *(buf++);
+ retval |= *(buf++) << 8;
+ retval |= *(buf++) << 16;
+ retval |= *(buf++) << 24;
+ return retval;
+}
+
+inline static void pickit5_create_payload_header(unsigned char *buf, unsigned int type,
+ unsigned int msg_len, unsigned int trans_len) {
+ pickit5_uint32_to_array(&buf[0], type);
+ pickit5_uint32_to_array(&buf[4], 0);
+ pickit5_uint32_to_array(&buf[8], msg_len);
+ pickit5_uint32_to_array(&buf[12], trans_len);
+}
+
+inline static void pickit5_create_script_header(unsigned char *buf, unsigned int arg_len,
+ unsigned int script_len) {
+ pickit5_uint32_to_array(&buf[0], arg_len);
+ pickit5_uint32_to_array(&buf[4], script_len);
+ }
+
+/* Interface - management */
+static void pickit5_setup(PROGRAMMER *pgm) {
+ pgm->cookie = mmt_malloc(sizeof(struct pdata));
+}
+
+static void pickit5_teardown(PROGRAMMER *pgm) {
+ mmt_free(pgm->cookie);
+ pgm->cookie = NULL;
+}
+
+static int pickit5_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) {
+ LNODEID ln;
+ const char *extended_param;
+ int rv = 0;
+
+ for (ln = lfirst(extparms); ln; ln = lnext(ln)) {
+ extended_param = ldata(ln);
+
+ if (str_starts(extended_param, "voltage=")) {
+ int voltage = -1;
+ if (sscanf(extended_param, "voltage=%i", &voltage) != 1) {
+
+ pmsg_error("invalid voltage paramter '%s'\n", extended_param);
+ rv = -1;
+ continue;
+ }
+ if (voltage == 0) {
+ PDATA(pgm)->power_source = 2; // Voltage check disabled
+ } else if (voltage < 1800 || voltage > 5500) {
+ pmsg_error("Voltage %imV outside of valid range [1800~5500]\n", voltage);
+ rv = -1;
+ continue;
+ }
+ PDATA(pgm)->power_source = 1; // PK supplies power
+ PDATA(pgm)->target_voltage = voltage;
+ continue;
+ }
+
+ if (str_eq(extended_param, "help")) {
+ msg_error("%s -c %s extended options:\n", progname, pgmid);
+ msg_error(" -xvoltage= Enables power output. must be in range 1800~5500[mV]\n");
+ msg_error(" -xhelp Show this help menu and exit\n");
+ return LIBAVRDUDE_EXIT;
+ }
+
+ pmsg_error("invalid extended parameter '%s'\n", extended_param);
+ rv = -1;
+ }
+ return rv;
+}
+
+
+/* Internal functions */
+
+// type can be CMD, UPLOAD or DOWNLOAD. Might enum be better?
+#define SCR_CMD 0x0100
+#define SCR_UPLOAD 0x80000102
+#define SCR_DOWNLAOD 0x0C0000101
+
+
+static int pickit5_send_script(const PROGRAMMER *pgm, unsigned int script_type,
+ const unsigned char *script, unsigned int script_len,
+ const unsigned char *param, unsigned int param_len,
+ unsigned int payload_len) {
+ if (script == NULL) // a valid pointer to a script is needed
+ return -1;
+
+ unsigned int header_len = 16 + 8; // header info + script header
+ unsigned int preamble_len = header_len + param_len;
+ unsigned int message_len = preamble_len + script_len;
+
+ if (message_len > 1023) // required memory will exceed buffer size, abort
+ return -1; // 1kB should be enough for everything
+
+ unsigned char *buf = PDATA(pgm)->txBuf;
+
+ pickit5_create_payload_header(&buf[0], script_type, message_len, payload_len);
+ pickit5_create_script_header(&buf[16], param_len, script_len);
+
+ if (param != NULL) // param can be NULL, make sure not to touch it then
+ memcpy(&buf[24], param, param_len);
+
+ memcpy(&buf[preamble_len], script, script_len);
+
+ return serial_send(&pgm->fd, buf, message_len);
+}
+
+static int pickit5_read_response(const PROGRAMMER *pgm, char *fn_name) {
+ unsigned char *buf = PDATA(pgm)->rxBuf;
+ if (serial_recv(&pgm->fd, buf, 1024) < 0) {
+ pmsg_error("Reading from PICkit failed");
+ return -1;
+ }
+ unsigned int status = pickit5_array_to_uint32(&buf[0]);
+ if (status != 0x0D) {
+ pmsg_error("Error on response in function \"%s\"", fn_name);
+ return -1;
+ }
+ return 0;
+}
+
+static int pickit5_send_script_done(const PROGRAMMER *pgm, char *func) {
+ unsigned char script_done [16];
+ unsigned int script_done_type = 0x0103;
+ pickit5_create_payload_header(script_done, script_done_type, 16, 0);
+ if (serial_send(&pgm->fd, script_done, 16) >= 0)
+ return pickit5_read_response(pgm, func);
+ pmsg_error("Failed to send \"script done\"");
+ return -1;
+}
+
+
+/* Interface - prog. */
+static int pickit5_open(PROGRAMMER *pgm, const char *port) {
+ if (PDATA(pgm) == NULL) // Make sure we do have a pointer to our data structure
+ return -1;
+ pmsg_debug("pickit5_open(\"%s\")\n", port);
+ union pinfo pinfo;
+ LNODEID usbpid;
+ int rv = -1;
+
+#if !defined(HAVE_LIBUSB) && !defined(HAVE_LIBHIDAPI)
+ pmsg_error("was compiled without USB or HIDAPI support\n");
+ return -1;
+#endif
+
+ // If the config entry did not specify a USB PID, insert the default one.
+ if (lfirst(pgm->usbpid) == NULL)
+ ladd(pgm->usbpid, (void *)USB_DEVICE_PICKIT5);
+
+ pinfo.usbinfo.vid = pgm->usbvid? pgm->usbvid: USB_VENDOR_MICROCHIP;
+
+#if defined(HAVE_LIBHIDAPI)
+ // Try HIDAPI first. LibUSB is more generic, but might
+ // cause trouble for HID-class devices in some OSes
+ serdev = &usbhid_serdev;
+ for (usbpid = lfirst(pgm->usbpid); rv < 0 && usbpid != NULL; usbpid = lnext(usbpid)) {
+ pinfo.usbinfo.flags = PINFO_FL_SILENT;
+ pinfo.usbinfo.pid = *(int *)(ldata(usbpid));
+ pgm->fd.usb.max_xfer = USB_PK5_MAX_XFER;
+ pgm->fd.usb.rep = 0x81; // command read
+ pgm->fd.usb.wep = 0x02; // command write
+ pgm->fd.usb.eep = 0x00;
+
+ pgm->port = port;
+ rv = serial_open(port, pinfo, &pgm->fd);
+ }
+ if (rv < 0) {
+#endif /* HAVE_LIBHIDAPI */
+#if defined(HAVE_LIBUSB)
+ serdev = &usb_serdev_frame;
+ for (usbpid = lfirst(pgm->usbpid); rv < 0 && usbpid != NULL; usbpid = lnext(usbpid)) {
+ pinfo.usbinfo.flags = PINFO_FL_SILENT;
+ pinfo.usbinfo.pid = *(int *)(ldata(usbpid));
+ pgm->fd.usb.max_xfer = USB_PK5_MAX_XFER;
+ pgm->fd.usb.rep = 0x81; // command read
+ pgm->fd.usb.wep = 0x02; // command write
+ pgm->fd.usb.eep = 0x00;
+
+ pgm->port = port;
+ rv = serial_open(port, pinfo, &pgm->fd);
+ }
+#endif /* HAVE_LIBUSB */
+#if defined(HAVE_LIBHIDAPI)
+ }
+#endif
+
+ // Make USB serial number available to programmer
+ if (serdev && serdev->usbsn) {
+ pgm->usbsn = serdev->usbsn;
+ PDATA(pgm)->pk_op_mode = 0x01;
+ }
+
+ return rv;
+}
+
+static void pickit5_close(PROGRAMMER *pgm) {
+ pmsg_debug("pickit5_close()\n");
+ if (PDATA(pgm)->pk_op_mode == 3)
+ pickit5_program_disable(pgm, NULL); // Disable Programming mode if still enabled
+
+ pickit5_set_vtarget(pgm, 0.0); // Switches off PICkit Voltage regulator, if enabled
+
+ if (PDATA(pgm)->usbhandle!=NULL) {
+ unsigned char temp[4];
+ memset(temp, 0, sizeof(temp));
+ serial_close(&pgm->fd);
+ }
+}
+
+static void pickit5_disable(const PROGRAMMER *pgm) {
+ return;
+}
+
+static void pickit5_enable(PROGRAMMER *pgm, const AVRPART *p) {
+ return;
+}
+
+static void pickit5_display(const PROGRAMMER *pgm, const char *p) {
+ return;
+}
+
+static int pickit5_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
+ pmsg_debug("pickit5_initialize()");
+ if (PDATA(pgm) == NULL)
+ return -1;
+
+ PDATA(pgm)->scripts = get_pickit_script(p->desc);
+ if (PDATA(pgm)->scripts == NULL) {
+ pmsg_error("Failed to match scripts to %s\n", p->desc);
+ return -1;
+ }
+ pmsg_info("Scripts for %s found and loaded\n", p->desc);
+
+ if (pickit5_get_fw_info(pgm) < 0) // PK responds, we can try to enable voltage
+ return -1;
+
+ pickit5_set_ptg_mode(pgm);
+ double v_target;
+ pickit5_get_vtarget(pgm, &v_target); // see if we have to supply power, or we get it externally
+ if (v_target < 1800.0) {
+ if (PDATA(pgm)->power_source == 2) {
+ pmsg_warning("No external Voltage detected, but continuing anyway\n");
+ } else if (PDATA(pgm)->power_source == 1) {
+ pmsg_info("No extenal Voltage detected, will try to supply from PICkit\n");
+ if (pickit5_set_vtarget(pgm, (double)PDATA(pgm)->target_voltage) < 0) return -1;
+ if (pickit5_get_vtarget(pgm, &v_target) < 0) return -1; // Verify Voltage
+ if (v_target < PDATA(pgm)->target_voltage - 250.0 // Voltage supply is not accurate, allow some room
+ || v_target > PDATA(pgm)->target_voltage + 150.0) {
+ pmsg_error("Target Voltage out of range, Aborting.\n");
+ return -1;
+ }
+
+ pickit5_program_enable(pgm, p);
+ unsigned int baud = pgm->baudrate;
+ if (baud < 300) { // Better be safe than sorry
+ pmsg_warning("UPDI needs a higher clock for operation, limiting UPDI to 300Hz\n");
+ baud = 300;
+ }
+ if (baud > 225000) {
+ if (v_target < 2900.0) {
+ pmsg_warning("UPDI needs a higher Voltage for a faster Baudrate, limiting UPDI to 225kHz\n");
+ baud = 225000;
+ } else {
+ // ToDo: Datasheet recommends setting BOD to highest level, but the BODs address is either 0x00A0 or 0x0080
+ // So best would be to figure out a way to deduct the correct address
+
+ if (baud > 900000) {
+ pmsg_warning("Requested clock too high. Limiting UPDI to 900kHz\n");
+ baud = 900000;
+ }
+ pickit5_set_sck_period(pgm, 1.0/100000); // Start with 200kHz
+ pickit5_write_cs_reg(pgm, UPDI_ASI_CTRLA, 0x01); // Change UPDI Clock
+ unsigned char ret_val = 0;
+ pickit5_read_cs_reg(pgm, UPDI_ASI_CTRLA, &ret_val);
+ if (ret_val != 0x01) {
+ pmsg_warning("Failed to change UPDI Clock, falling back to 225kHz");
+ baud = 225000;
+ }
+ }
+ }
+ if (pickit5_set_sck_period(pgm, 1.0/baud) >= 0) {
+ pmsg_info("UPDI Speed set to %ikHz\n", baud / 1000);
+ } else {
+ pmsg_warning("Failed to set UPDI speed, continuing...\n");
+ }
+ pickit5_program_enable(pgm, p);
+ } else {
+ pmsg_error("No external Voltage detected, aborting. Overwrite this check with -xvoltage=0\n");
+ return -1;
+ }
+ } else {
+ PDATA(pgm)->power_source = 0;
+ pmsg_info("External Voltage detected, won't supply power\n");
+ }
+ return 0;
+}
+
+
+static int pickit5_cmd(const PROGRAMMER *pgm, const unsigned char *cmd,
+ unsigned char *res) {
+ return -2;
+}
+
+static int pickit5_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
+ pmsg_debug("pickit5_enter_prog_mode()\n");
+ const unsigned char *enter_prog = PDATA(pgm)->scripts->EnterProgMode;
+ unsigned int enter_prog_len = PDATA(pgm)->scripts->EnterProgMode_len;
+ if (PDATA(pgm)->pk_op_mode != 3) {
+ if (pickit5_send_script(pgm, SCR_CMD, enter_prog, enter_prog_len, NULL, 0, 0) < 0)
+ return -1;
+
+ if (pickit5_read_response(pgm, "Enter Programming Mode") < 0)
+ return -1;
+ PDATA(pgm)->pk_op_mode = 3;
+ }
+ return 0;
+}
+
+static int pickit5_program_disable(const PROGRAMMER *pgm, const AVRPART *p) {
+ pmsg_debug("pickit5_exit_prog_mode()\n");
+ const unsigned char *enter_prog = PDATA(pgm)->scripts->ExitProgMode;
+ unsigned int enter_prog_len = PDATA(pgm)->scripts->ExitProgMode_len;
+ if (PDATA(pgm)->pk_op_mode == 3) {
+ if (pickit5_send_script(pgm, SCR_CMD, enter_prog, enter_prog_len, NULL, 0, 0) < 0)
+ return -1;
+
+ if (pickit5_read_response(pgm, "Exit Programming Mode") < 0)
+ return -1;
+ PDATA(pgm)->pk_op_mode = 2;
+ }
+ return 0;
+}
+
+static int pickit5_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
+ pmsg_debug("pickit5_chip_erase()\n");
+ if (PDATA(pgm)->pk_op_mode == 3) { // we have to be in Prog-Mode
+ const unsigned char *chip_erase = PDATA(pgm)->scripts->EraseChip;
+ unsigned int chip_erase_len = PDATA(pgm)->scripts->EraseChip_len;
+
+ if (pickit5_send_script(pgm, SCR_CMD, chip_erase, chip_erase_len, NULL, 0, 0) >= 0){
+ if (pickit5_read_response(pgm, "Erase Chip") >= 0) {
+ if (pickit5_array_to_uint32(&(PDATA(pgm)->rxBuf[16])) == 0x00) {
+ pmsg_info("Target successfully erased");
+ PDATA(pgm)->pk_op_mode = 2;
+ return 0;
+ }
+ }
+ }
+ }
+ pmsg_error("Chip Erase failed\n");
+ return -1;
+}
+
+static int pickit5_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem,
+ unsigned int page_size, unsigned int address, unsigned int n_bytes) {
+
+ pickit5_program_enable(pgm, p);
+ return pickit5_read_array(pgm, p, mem, address, n_bytes, &mem->buf[address]);
+}
+
+static int pickit5_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem,
+ unsigned int page_size, unsigned int address, unsigned int n_bytes) {
+
+ pickit5_program_enable(pgm, p);
+ return pickit5_write_array(pgm, p, mem, address, n_bytes, &mem->buf[address]);
+}
+
+
+// Sets UPDI Frequency in kHz
+static int pickit5_set_sck_period(const PROGRAMMER *pgm, double sckperiod) {
+ pmsg_debug("pickit5_set_sck_period()\n");
+ double frq = (0.001 / sckperiod) + 0.5; // 1ms/period = kHz; round up
+ const unsigned char *set_speed = PDATA(pgm)->scripts->SetSpeed;
+ int set_speed_len = PDATA(pgm)->scripts->SetSpeed_len;
+ unsigned char buf[4];
+ pickit5_uint32_to_array(buf, frq);
+ if(pickit5_send_script(pgm, SCR_CMD, set_speed, set_speed_len, buf, 4, 0) < 0)
+ return -1;
+ if (pickit5_read_response(pgm, "Set UPDI Speed") < 0)
+ return -1;
+ return 0;
+}
+
+static int pickit5_write_byte (const PROGRAMMER *pgm, const AVRPART *p,
+ const AVRMEM *mem, unsigned long addr, unsigned char value) {
+ return pickit5_write_array(pgm, p, mem, addr, 1, &value);
+}
+
+static int pickit5_read_byte (const PROGRAMMER *pgm, const AVRPART *p,
+ const AVRMEM *mem, unsigned long addr, unsigned char *value) {
+ return pickit5_read_array(pgm, p, mem, addr, 1, value);
+}
+
+
+static int pickit5_write_array(const PROGRAMMER *pgm, const AVRPART *p,
+ const AVRMEM *mem, unsigned long addr, int len, unsigned char *value) {
+ pmsg_debug("pickit5_write_array(%s, 0x%04x, %i)", mem->desc, (unsigned int)addr, len);
+
+ if (len > mem->size || mem->size < 1) {
+ pmsg_error("cannot write byte to %s %s owing to its size %d\n", p->desc, mem->desc, mem->size);
+ return -1;
+ }
+ if (addr >= (unsigned long) mem->size) {
+ pmsg_error("cannot write byte to %s %s as address 0x%04lx outside range [0, 0x%04x]\n",
+ p->desc, mem->desc, addr, mem->size-1);
+ return -1;
+ }
+
+ const unsigned char *write_bytes = NULL;
+ unsigned int write_bytes_len = 0;
+ if (mem_is_flash(mem) && (len == mem->page_size)) {
+ write_bytes = PDATA(pgm)->scripts->WriteProgmem;
+ write_bytes_len = PDATA(pgm)->scripts->WriteProgmem_len;
+ } else if (mem_is_eeprom(mem)) {
+ write_bytes = PDATA(pgm)->scripts->WriteDataEEmem;
+ write_bytes_len = PDATA(pgm)->scripts->WriteDataEEmem_len;
+ } else if (mem_is_in_fuses(mem)) {
+ write_bytes = PDATA(pgm)->scripts->WriteConfigmem;
+ write_bytes_len = PDATA(pgm)->scripts->WriteConfigmem_len;
+ } else if (mem_is_io(mem) || mem_is_sram(mem)) {
+ write_bytes = PDATA(pgm)->scripts->WriteMem8;
+ write_bytes_len = PDATA(pgm)->scripts->WriteMem8_len;
+ } else {
+ pmsg_error("Unsupported memory type: %s\n", mem->desc);
+ return -2;
+ }
+ addr += mem->offset;
+
+ unsigned char buf [8];
+ pickit5_uint32_to_array(&buf[0], addr);
+ pickit5_uint32_to_array(&buf[4], len);
+
+ if (pickit5_send_script(pgm, SCR_DOWNLAOD, write_bytes, write_bytes_len, buf, 8, len) < 0) {
+ pmsg_error("Sending Script failed\n");
+ return -1;
+ }
+
+ if (pickit5_read_response(pgm, "Write Bytes") < 0) {
+ pmsg_error("Reading Script Response\n");
+ return -1;
+ }
+ if (usbdev_data_send(&pgm->fd, value, len) < 0) {
+ pmsg_error("Failed to send data\n");
+ return -1;
+ }
+ if (pickit5_get_Status(pgm, CHECK_ERROR) < 0) {
+ pmsg_error("Error Check failed\n");
+ return -1;
+ }
+ if (pickit5_send_script_done(pgm, "Write Bytes") < 0) {
+ pmsg_error("Sending Script Done failed\n");
+ return -1;
+ }
+ return len;
+}
+
+/*
+ * return numbers of byte read
+*/
+static int pickit5_read_array (const PROGRAMMER *pgm, const AVRPART *p,
+ const AVRMEM *mem, unsigned long addr, int len, unsigned char *value) {
+ pmsg_debug("pickit5_read_array(%i)\n", len);
+
+ if (len > mem->size || mem->size < 1) {
+ pmsg_error("cannot read byte from %s %s owing to its size %d\n", p->desc, mem->desc, mem->size);
+ return -1;
+ }
+ if (addr >= (unsigned long) mem->size) {
+ pmsg_error("cannot read byte from %s %s as address 0x%04lx outside range [0, 0x%04x]\n",
+ p->desc, mem->desc, addr, mem->size-1);
+ return -1;
+ }
+
+ const unsigned char *read_bytes = NULL;
+ unsigned int read_bytes_len = 0;
+ if (mem_is_flash(mem)) {
+ read_bytes = PDATA(pgm)->scripts->ReadProgmem;
+ read_bytes_len = PDATA(pgm)->scripts->ReadProgmem_len;
+ } else if (mem_is_eeprom(mem)) {
+ read_bytes = PDATA(pgm)->scripts->ReadDataEEmem;
+ read_bytes_len = PDATA(pgm)->scripts->ReadDataEEmem_len;
+ } else if (mem_is_in_fuses(mem) || mem_is_prodsig(mem) || mem_is_sigrow(mem)
+ || mem_is_sernum(mem) || mem_is_tempsense(mem)) {
+ read_bytes = PDATA(pgm)->scripts->ReadConfigmem;
+ read_bytes_len = PDATA(pgm)->scripts->ReadConfigmem_len;
+ } else if (mem_is_io(mem) || mem_is_sram(mem) || mem_is_lock(mem)) {
+ read_bytes = PDATA(pgm)->scripts->ReadMem8;
+ read_bytes_len = PDATA(pgm)->scripts->ReadMem8_len;
+ } else if (mem_is_sib(mem)) {
+ return pickit5_read_sib(pgm, p, (char *)value); // silence pointer sign warning
+ } else {
+ pmsg_error("Unsupported memory type: %s\n", mem->desc);
+ return -2;
+ }
+ addr += mem->offset;
+
+ unsigned char buf [8];
+ pickit5_uint32_to_array(&buf[0], addr);
+ pickit5_uint32_to_array(&buf[4], len);
+
+ if (pickit5_send_script(pgm, SCR_UPLOAD, read_bytes, read_bytes_len, buf, 8, len) < 0) {
+ pmsg_error("Sending Script failed\n");
+ return -1;
+ }
+ if (pickit5_read_response(pgm, "Read Bytes") < 0) {
+ pmsg_error("Read Response Failed\n");
+ return -1;
+ }
+ if (usbdev_data_recv(&pgm->fd, value, len) < 0) {
+ pmsg_error("Reading Data Memory failed\n");
+ return -1;
+ }
+ if (pickit5_send_script_done(pgm, "Read Bytes") < 0) {
+ pmsg_error("Sending Script Done failed\n");
+ return -1;
+ }
+ return len;
+}
+
+static int pickit5_read_sig_bytes (const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m) {
+ pmsg_debug("pickit5_read_sig_bytes()\n");
+ const unsigned char *read_id = PDATA(pgm)->scripts->GetDeviceID;
+ unsigned int read_id_len = PDATA(pgm)->scripts->GetDeviceID_len;
+ if(pickit5_send_script(pgm, SCR_CMD, read_id, read_id_len, NULL, 0, 0) < 0)
+ return -1;
+ if (pickit5_read_response(pgm, "Read Device ID") < 0)
+ return -1;
+ m->buf[0] = PDATA(pgm)->rxBuf[24];
+ m->buf[1] = PDATA(pgm)->rxBuf[25];
+ m->buf[2] = PDATA(pgm)->rxBuf[26];
+ PDATA(pgm)->target_revision = PDATA(pgm)->rxBuf[27]; // Chip revision
+ return 3;
+}
+
+static int pickit5_read_sib (const PROGRAMMER *pgm, const AVRPART *p, char *sib) {
+ pmsg_debug("pickit5_read_sib()\n");
+ const unsigned char *read_sib = PDATA(pgm)->scripts->ReadSIB;
+ unsigned int read_sib_len = PDATA(pgm)->scripts->ReadSIB_len;
+
+ if (pickit5_send_script(pgm, SCR_CMD, read_sib, read_sib_len, NULL, 0, 0) < 0)
+ return -1;
+ if (pickit5_read_response(pgm, "Read SIB") < 0)
+ return -1;
+ unsigned int ret_len = pickit5_array_to_uint32(&(PDATA(pgm)->rxBuf[20]));
+ if (ret_len == 0x20) { // 0x20 bytes == 32 bytes
+ memcpy(sib, &PDATA(pgm)->rxBuf[24], 32);
+ } else {
+ return -1;
+ }
+ return 0;
+}
+
+static int pickit5_read_chip_rev (const PROGRAMMER *pgm, const AVRPART *p, unsigned char *chip_rev) {
+ pmsg_debug("pickit5_read_chip_rev()\n");
+ *chip_rev = PDATA(pgm)->target_revision;
+ return 0;
+}
+
+static int pickit5_write_cs_reg(const PROGRAMMER *pgm, unsigned int addr, unsigned char value) {
+ pmsg_debug("pickit5_write_cs_reg(*%i = %i)", addr, value);
+ const unsigned char *write_cs = PDATA(pgm)->scripts->WriteCSreg;
+ unsigned int write_cs_len = PDATA(pgm)->scripts->WriteCSreg_len;
+
+ if (addr > 0x0C) {
+ pmsg_error("CS reg %i out of range [0x00, 0x0C], addr\n", addr);
+ return -1;
+ }
+
+ unsigned char buf [2];
+ buf[0] = addr;
+ buf[1] = value;
+
+ if (pickit5_send_script(pgm, SCR_CMD, write_cs, write_cs_len, buf, 2, 0) < 0) {
+ pmsg_error("Sending Script failed\n");
+ return -1;
+ }
+
+ if (pickit5_read_response(pgm, "Write CS reg") < 0) {
+ pmsg_error("Reading Script Response\n");
+ return -1;
+ }
+ return 1;
+}
+
+static int pickit5_read_cs_reg(const PROGRAMMER *pgm, unsigned int addr, unsigned char* value) {
+ pmsg_debug("pickit5_read_cs_reg(%i)\n", addr);
+ const unsigned char *read_cs = PDATA(pgm)->scripts->ReadCSreg;
+ unsigned int read_cs_len = PDATA(pgm)->scripts->ReadCSreg_len;
+
+ if (addr > 0x0C) {
+ pmsg_error("CS reg %i out of range [0x00, 0x0C], addr\n", addr);
+ return -1;
+ }
+
+ unsigned char buf [1];
+ buf[0] = addr;
+
+ if (pickit5_send_script(pgm, SCR_UPLOAD, read_cs, read_cs_len, buf, 1, 1) < 0) {
+ pmsg_error("Sending Script failed\n");
+ return -1;
+ }
+ if (pickit5_read_response(pgm, "Read CS") < 0) {
+ pmsg_error("Read Response Failed\n");
+ return -1;
+ }
+ if (usbdev_data_recv(&pgm->fd, value, 1) < 0) {
+ pmsg_error("Reading CS Memory failed\n");
+ return -1;
+ }
+ if (pickit5_send_script_done(pgm, "Read CS") < 0) {
+ pmsg_error("Sending Script Done failed\n");
+ return -1;
+ }
+ return 0;
+}
+
+
+static int pickit5_get_fw_info(const PROGRAMMER *pgm) {
+ pmsg_debug("pickit5_get_fw_info()");
+ unsigned char *buf = PDATA(pgm)->rxBuf;
+ const unsigned char get_fw [] = {0xE1};
+
+ if (serial_send(&pgm->fd, get_fw, 1) < 0) {
+ pmsg_error("Failed to send command\n");
+ return -1;
+ }
+
+ // PICkit didn't like receive transfers smaller 1024
+ if (serial_recv(&pgm->fd, buf, 1024) < 0) {
+ pmsg_error("Failed to receive FW response\n");
+ return -1;
+ }
+
+ if (buf[0] != 0xE1) {
+ pmsg_error("Unexpected Device Response on \"Get Firmware Info\"\n");
+ return -1;
+ }
+
+ unsigned char str_num [32];
+ memcpy(str_num, &buf[32], 18);
+ str_num[18] = 0; // Known Zero terminator
+ pmsg_info("PICkit5, FW Ver: %02x.%02x.%02x, SerialNumber: %s\n", buf[3], buf[4], buf[5], str_num);
+ return 0;
+}
+
+
+static int pickit5_set_vtarget (const PROGRAMMER *pgm, double v) {
+ unsigned char set_vtarget [] = {
+ 0x40,
+ 0x00, 0x00, 0x00, 0x00, // Vdd
+ 0x00, 0x00, 0x00, 0x00, // Vpp
+ 0x00, 0x00, 0x00, 0x00, // Vpp_op
+ 0x42, 0x43,
+ };
+ unsigned char power_source [] = {
+ 0x46, 0x00, 0x00, 0x00, 0x00,
+ };
+ unsigned char disable_power [] = {
+ 0x44
+ };
+
+ pmsg_debug("pickit5_set_vtarget(%4.1fmV)\n", v);
+
+ if (v < 1.0) { // make sure not to trip on float's "inaccuracy"
+ if (pickit5_send_script(pgm, SCR_CMD, power_source, 5, NULL, 0, 0) < 0)
+ return -1;
+ if (pickit5_read_response(pgm, "Select external power source") < 0)
+ return -1;
+
+ if (pickit5_send_script(pgm, SCR_CMD, disable_power, 1, NULL, 0, 0) < 0)
+ return -1;
+ if (pickit5_read_response(pgm, "Disabling Power") < 0)
+ return -1;
+ } else {
+ power_source[1] = 0x01;
+ if (pickit5_send_script(pgm, SCR_CMD, power_source, 5, NULL, 0, 0) < 0)
+ return -1;
+ if (pickit5_read_response(pgm, "Select internal power source") < 0)
+ return -1;
+
+ pickit5_uint32_to_array(&set_vtarget[1], PDATA(pgm)->target_voltage);
+ pickit5_uint32_to_array(&set_vtarget[5], PDATA(pgm)->target_voltage);
+ pickit5_uint32_to_array(&set_vtarget[9], PDATA(pgm)->target_voltage);
+
+ if (pickit5_send_script(pgm, SCR_CMD, set_vtarget, 15, NULL, 0, 0) < 0)
+ return -1;
+
+ if (pickit5_read_response(pgm, "set_vtarget") < 0)
+ return -1;
+ }
+ return 0;
+}
+
+static int pickit5_get_vtarget (const PROGRAMMER *pgm, double *v) {
+ const unsigned char get_vtarget [] = {0x47, };
+ unsigned char *buf = PDATA(pgm)->rxBuf;
+ pmsg_debug("pickit5_get_vtarget()\n");
+
+ if (pickit5_send_script(pgm, SCR_CMD, get_vtarget, 1, NULL, 0, 0) < 0)
+ return -1;
+
+ if (pickit5_read_response(pgm, "get_vtarget") < 0)
+ return -1;
+
+ // 24 - internal Vdd [mV]
+ // 28 - target Vdd [mV]
+ // 32 - Target Vpp [mV]
+ // 36 - Internal Vpp [mV]
+ // 48 - Vdd Current Sense [mA]
+ int vtarget = pickit5_array_to_uint32(&buf[28]);
+ int itarget = pickit5_array_to_uint32(&buf[48]);
+ pmsg_info("Target Vdd: %umV, Target current: %umA\n", vtarget, itarget);
+ *v = (double)vtarget;
+ return 0;
+}
+
+
+static int pickit5_set_ptg_mode(const PROGRAMMER *pgm) {
+ unsigned char ptg_mode [] = {
+ 0x5E, 0x00, 0x00, 0x00, 0x00,
+ };
+ unsigned char buf[8];
+ pmsg_debug("pickit5_set_ptg_mode()\n");
+
+ if (pickit5_send_script(pgm, SCR_UPLOAD, ptg_mode, 5, NULL, 0, 4) < 0)
+ return -1;
+ if (pickit5_read_response(pgm, "Set PTG mode") < 0)
+ return -1;
+
+ if (usbdev_data_recv(&pgm->fd, buf, 4) < 0)
+ return -1;
+ if (pickit5_send_script_done(pgm, "Set PTG Mode") < 0)
+ return -1;
+ return 0;
+}
+
+static int pickit5_get_Status(const PROGRAMMER *pgm, unsigned char status) {
+ unsigned char* buf = PDATA(pgm)->txBuf;
+ const unsigned int type = 0x0105;
+ unsigned int key_len = 0;
+
+ if (CHECK_ERROR == status) {
+ key_len = strlen("ERROR_STATUS_KEY") + 1;
+ memcpy (&buf[16], "ERROR_STATUS_KEY", key_len);
+ } else if (BIST_TEST == status) {
+ key_len = strlen("BIST Tested") + 1;
+ memcpy (&buf[16], "BIST Tested", key_len);
+ } else if (BIST_RESULT == status) {
+ key_len = strlen("BIST Results") + 1;
+ memcpy (&buf[16], "BIST Results", key_len);
+ }
+ if (0 == key_len) {
+ pmsg_error("Uknown key typed passed");
+ return -1;
+ }
+ unsigned int msg_len = 16 + key_len;
+ pickit5_create_payload_header(&buf[0], type, msg_len, 0);
+ serial_send(&pgm->fd, buf, msg_len);
+ serial_recv(&pgm->fd, PDATA(pgm)->rxBuf, 1024);
+ if (pickit5_check_ret_status(pgm) < 0) {
+ return -1;
+ }
+ unsigned int status_len = pickit5_array_to_uint32(&(PDATA(pgm)->rxBuf[8]));
+ if (status_len > 64)
+ status_len = 64;
+ PDATA(pgm)->rxBuf[16+status_len] = 0x00; // Known Zero Terminator
+ if (str_starts((const char*)&(PDATA(pgm)->rxBuf[16]), "NONE") == 0) { // cast to remove warning
+ pmsg_error("PICkit Error Status report: %s", buf);
+ return -1;
+ }
+ return 0;
+}
+
+inline static int pickit5_check_ret_status(const PROGRAMMER *pgm) {
+ unsigned char ret = PDATA(pgm)->rxBuf[0];
+ if (0x0D != ret) {
+ pmsg_error("PICkit5 Bad Response: %i", ret);
+ return -1;
+ }
+ return 0;
+}
+
+
+
+
+void pickit5_initpgm(PROGRAMMER *pgm) {
+ strcpy(pgm->type, "pickit5");
+
+ /*
+ * mandatory functions
+ */
+
+ pgm->initialize = pickit5_initialize;
+ pgm->parseextparams = pickit5_parseextparms;
+ pgm->display = pickit5_display;
+ pgm->enable = pickit5_enable;
+ pgm->disable = pickit5_disable;
+ pgm->program_enable = pickit5_program_enable;
+ pgm->chip_erase = pickit5_chip_erase;
+ pgm->cmd = pickit5_cmd;
+ pgm->open = pickit5_open;
+ pgm->close = pickit5_close;
+ pgm->write_byte = pickit5_write_byte;
+ pgm->read_byte = pickit5_read_byte;
+
+
+ /*
+ * optional functions
+ */
+ pgm->write_array = pickit5_write_array;
+ pgm->read_array = pickit5_read_array;
+ pgm->paged_write = pickit5_paged_write;
+ pgm->paged_load = pickit5_paged_load;
+ pgm->setup = pickit5_setup;
+ pgm->teardown = pickit5_teardown;
+ pgm->set_sck_period = pickit5_set_sck_period;
+ pgm->end_programming = pickit5_program_disable;
+ pgm->read_sig_bytes = pickit5_read_sig_bytes;
+ pgm->read_sib = pickit5_read_sib;
+ pgm->read_chip_rev = pickit5_read_chip_rev;
+ pgm->set_vtarget = pickit5_set_vtarget;
+ pgm->get_vtarget = pickit5_get_vtarget;
+
+}
+
+
+#if defined(USE_LIBUSB_1_0)
+static int usb_fill_buf(usb_dev_handle *udev, int maxsize, int ep, int use_interrupt_xfer);
+static int usb_fill_buf(usb_dev_handle *udev, int maxsize, int ep, int use_interrupt_xfer) {
+ int rv;
+
+ if (use_interrupt_xfer)
+ rv = usb_interrupt_read(udev, ep, cx->usb_buf, maxsize, 10000);
+ else
+ rv = usb_bulk_read(udev, ep, cx->usb_buf, maxsize, 10000);
+ if (rv < 0)
+ {
+ pmsg_notice2("usb_fill_buf(): usb_%s_read() error: %s\n",
+ use_interrupt_xfer? "interrupt": "bulk", usb_strerror());
+ return -1;
+ }
+
+ cx->usb_buflen = rv;
+ cx->usb_bufptr = 0;
+
+ return 0;
+}
+
+static int usbdev_data_recv(const union filedescriptor *fd, unsigned char *buf, size_t nbytes) {
+ usb_dev_handle *udev = (usb_dev_handle *)fd->usb.handle;
+ int i, amnt;
+ unsigned char *p = buf;
+
+ if (udev == NULL)
+ return -1;
+
+ for (i = 0; nbytes > 0;)
+ {
+ if (cx->usb_buflen <= cx->usb_bufptr)
+ {
+ if (usb_fill_buf(udev, fd->usb.max_xfer, USB_PK5_DATA_READ_EP, fd->usb.use_interrupt_xfer) < 0)
+ return -1;
+ }
+ amnt = cx->usb_buflen - cx->usb_bufptr > (int) nbytes? (int) nbytes: cx->usb_buflen - cx->usb_bufptr;
+ memcpy(buf + i, cx->usb_buf + cx->usb_bufptr, amnt);
+ cx->usb_bufptr += amnt;
+ nbytes -= amnt;
+ i += amnt;
+ }
+
+ if(verbose > 4)
+ trace_buffer(__func__, p, i);
+
+ return 0;
+}
+
+static int usbdev_data_send(const union filedescriptor *fd, const unsigned char *bp, size_t mlen) {
+ usb_dev_handle *udev = (usb_dev_handle *)fd->usb.handle;
+ int rv;
+ int i = mlen;
+ const unsigned char *p = bp;
+ int tx_size;
+
+ if (udev == NULL)
+ return -1;
+
+ /*
+ * Split the frame into multiple packets. It's important to make
+ * sure we finish with a short packet, or else the device won't know
+ * the frame is finished. For example, if we need to send 64 bytes,
+ * we must send a packet of length 64 followed by a packet of length
+ * 0.
+ */
+ do {
+ tx_size = ((int) mlen < fd->usb.max_xfer)? (int) mlen: fd->usb.max_xfer;
+ if (fd->usb.use_interrupt_xfer)
+ rv = usb_interrupt_write(udev, USB_PK5_DATA_WRITE_EP, (char *)bp, tx_size, 10000);
+ else
+ rv = usb_bulk_write(udev, USB_PK5_DATA_WRITE_EP, (char *)bp, tx_size, 10000);
+ if (rv != tx_size)
+ {
+ pmsg_error("wrote %d out of %d bytes, err = %s\n", rv, tx_size, usb_strerror());
+ return -1;
+ }
+ bp += tx_size;
+ mlen -= tx_size;
+ } while (mlen > 0);
+
+ if(verbose > 3)
+ trace_buffer(__func__, p, i);
+ return 0;
+}
+#else
+
+// Allow compiling without throwing dozen errors
+// We need libusb so we can access specific Endpoints.
+// This does not seem to be possible with usbhid
+
+static int usbdev_data_recv(const union filedescriptor *fd, unsigned char *buf, size_t nbytes) {
+ return -1;
+}
+
+static int usbdev_data_send(const union filedescriptor *fd, const unsigned char *bp, size_t mlen) {
+ return -1;
+}
+
+#endif
+
+
+#else /* HAVE_LIBUSB */
+static int pickit5_nousb_open(PROGRAMMER *pgm, const char *name);
+
+static int pickit5_nousb_open(PROGRAMMER *pgm, const char *name) {
+ pmsg_error("no usb support; please compile again with libusb installed\n");
+
+ return -1;
+}
+
+void pickit5_initpgm(PROGRAMMER *pgm) {
+ strcpy(pgm->type, "pickit5");
+
+ pgm->open = pickit5_nousb_open;
+}
+
+#endif /* HAVE_LIBUSB */
+
+const char pickit5_desc[] = "Microchip's PICkit 5 Programmer/Debugger";
diff --git a/src/pickit5.h b/src/pickit5.h
new file mode 100644
index 000000000..c84a0bc3c
--- /dev/null
+++ b/src/pickit5.h
@@ -0,0 +1,35 @@
+/*
+ * avrdude - A Downloader/Uploader for AVR device programmers
+ * Copyright (C) 2024 MX682X
+ *
+ * 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
+ * along with this program. If not, see .
+ */
+
+
+
+#ifndef pickit5_h
+#define pickit5_h
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern const char pickit5_desc[];
+void pickit5_initpgm(PROGRAMMER *pgm);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // pickit5_h
diff --git a/src/scripts_lut.c b/src/scripts_lut.c
new file mode 100644
index 000000000..f6593b5b7
--- /dev/null
+++ b/src/scripts_lut.c
@@ -0,0 +1,441 @@
+/* this file was auto-generated by scripts_deocder.py*/
+#include
+#include
+#include
+#include "scripts_lut.h"
+
+
+const unsigned char EnterProgMode_0[294] = {
+ 0x9b, 0x00, 0x08, 0x9b, 0x01, 0x00, 0x1e, 0x01, 0x00, 0x01, 0xfd, 0x19, 0x00, 0x00, 0x00, 0x08, 0x01, 0x94, 0x32, 0x00, 0x94, 0x40, 0x00, 0x9b, 0x00, 0x0b, 0x1e, 0x0e, 0x00, 0x6c, 0x01, 0x66, 0x01, 0x08, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x08, 0x00, 0x00, 0x00, 0x26, 0x01, 0x9b, 0x00, 0x08, 0x9b, 0x01, 0x59, 0x1e, 0x0f, 0x00, 0x01, 0x9b, 0x01, 0x00, 0x65, 0x20, 0x67, 0x6f, 0x72, 0x04, 0x65, 0x50, 0x4d, 0x56, 0x4e, 0x04, 0x1e, 0x11, 0x01, 0x9b, 0x02, 0x07, 0x1e, 0x0e, 0x02, 0x6c, 0x03, 0x66, 0x03, 0x10, 0x00, 0x00, 0x00, 0x9b, 0x04, 0x10, 0xfc, 0x03, 0x04, 0x1e, 0x01, 0x9b, 0x00, 0x08, 0x9b, 0x01, 0x59, 0x1e, 0x0f, 0x00, 0x01, 0x9b, 0x01, 0x0b, 0xa2, 0x1e, 0x0e, 0x01, 0xa5, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x9b, 0x00, 0x08, 0x9b, 0x01, 0x00, 0x1e, 0x0f, 0x00, 0x01, 0x9b, 0x01, 0x0b, 0xa2, 0x1e, 0x0e, 0x01, 0xa5, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x94, 0x48, 0x00, 0x9b, 0x00, 0x0b, 0x1e, 0x0e, 0x00, 0x6c, 0x01, 0x66, 0x01, 0x08, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x08, 0x00, 0x00, 0x00, 0x26, 0x01, 0x9b, 0x00, 0x0b, 0x1e, 0x0e, 0x00, 0x6c, 0x01, 0x66, 0x01, 0x01, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x01, 0x00, 0x00, 0x00, 0x13, 0x01, 0x6c, 0x01, 0x66, 0x01, 0x02, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x02, 0x00, 0x00, 0x00, 0x13, 0x01, 0x9b, 0x01, 0x0c, 0x1e, 0x0e, 0x01, 0x6c, 0x02, 0x66, 0x02, 0x04, 0x00, 0x00, 0x00, 0xfe, 0x02, 0x04, 0x00, 0x00, 0x00, 0x13, 0x01, 0x94, 0xf4, 0x01, 0x9b, 0x01, 0x0c, 0x1e, 0x0e, 0x01, 0x6c, 0x02, 0x66, 0x02, 0x04, 0x00, 0x00, 0x00, 0xfe, 0x02, 0x04, 0x00, 0x00, 0x00, 0x13, 0x01, 0xfb, 0x1e, 0x01, 0x90, 0x01, 0x51, 0x00, 0x00, 0x00, 0x7f, 0x01, 0xfb, 0x26, 0x01, 0x90, 0x01, 0x44, 0x00, 0x00, 0x00, 0x7f, 0x01, 0xfb, 0x26, 0x01, 0x90, 0x01, 0x00, 0x01, 0x00, 0x00, 0x7f, 0x01,
+};
+const unsigned char EnterProgModeHvSp_0[339] = {
+ 0x9b, 0x00, 0x08, 0x9b, 0x01, 0x01, 0x1e, 0x01, 0x00, 0x01, 0xfd, 0x54, 0x00, 0x00, 0x00, 0x3a, 0x01, 0xfd, 0x08, 0x03, 0x00, 0x00, 0x45, 0x01, 0xfd, 0x09, 0x03, 0x00, 0x00, 0x48, 0x01, 0xfd, 0x19, 0x00, 0x00, 0x00, 0x24, 0x01, 0xfd, 0x1b, 0x00, 0x00, 0x00, 0x24, 0x01, 0x94, 0x32, 0x00, 0x94, 0x40, 0x00, 0x9b, 0x00, 0x0b, 0x1e, 0x0e, 0x00, 0x6c, 0x01, 0x66, 0x01, 0x08, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x08, 0x00, 0x00, 0x00, 0x53, 0x01, 0x9b, 0x00, 0x08, 0x9b, 0x01, 0x59, 0x1e, 0x0f, 0x00, 0x01, 0x9b, 0x01, 0x00, 0x65, 0x20, 0x67, 0x6f, 0x72, 0x04, 0x65, 0x50, 0x4d, 0x56, 0x4e, 0x04, 0x1e, 0x11, 0x01, 0x9b, 0x02, 0x07, 0x1e, 0x0e, 0x02, 0x6c, 0x03, 0x66, 0x03, 0x10, 0x00, 0x00, 0x00, 0x9b, 0x04, 0x10, 0xfc, 0x03, 0x04, 0x4b, 0x01, 0x9b, 0x00, 0x08, 0x9b, 0x01, 0x59, 0x1e, 0x0f, 0x00, 0x01, 0x9b, 0x01, 0x0b, 0xa2, 0x1e, 0x0e, 0x01, 0xa5, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x9b, 0x00, 0x08, 0x9b, 0x01, 0x00, 0x1e, 0x0f, 0x00, 0x01, 0x9b, 0x01, 0x0b, 0xa2, 0x1e, 0x0e, 0x01, 0xa5, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x94, 0x48, 0x00, 0x9b, 0x00, 0x0b, 0x1e, 0x0e, 0x00, 0x6c, 0x01, 0x66, 0x01, 0x08, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x08, 0x00, 0x00, 0x00, 0x53, 0x01, 0x9b, 0x00, 0x0b, 0x1e, 0x0e, 0x00, 0x6c, 0x01, 0x66, 0x01, 0x01, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x01, 0x00, 0x00, 0x00, 0x2f, 0x01, 0x6c, 0x01, 0x66, 0x01, 0x02, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x02, 0x00, 0x00, 0x00, 0x2f, 0x01, 0x9b, 0x01, 0x0c, 0x1e, 0x0e, 0x01, 0x6c, 0x02, 0x66, 0x02, 0x04, 0x00, 0x00, 0x00, 0xfe, 0x02, 0x04, 0x00, 0x00, 0x00, 0x2f, 0x01, 0x94, 0xf4, 0x01, 0x9b, 0x01, 0x0c, 0x1e, 0x0e, 0x01, 0x6c, 0x02, 0x66, 0x02, 0x04, 0x00, 0x00, 0x00, 0xfe, 0x02, 0x04, 0x00, 0x00, 0x00, 0x2f, 0x01, 0xfb, 0x4b, 0x01, 0x90, 0x01, 0x51, 0x00, 0x00, 0x00, 0x7f, 0x01, 0xfb, 0x53, 0x01, 0x90, 0x01, 0x44, 0x00, 0x00, 0x00, 0x7f, 0x01, 0xfb, 0x53, 0x01, 0x90, 0x01, 0x54, 0x00, 0x00, 0x00, 0x7f, 0x01, 0xfb, 0x53, 0x01, 0xfb, 0x53, 0x01, 0xfb, 0x53, 0x01, 0x90, 0x01, 0x00, 0x01, 0x00, 0x00, 0x7f, 0x01,
+};
+const unsigned char EnterProgModeHvSpRst_0[325] = {
+ 0x9b, 0x00, 0x08, 0x9b, 0x01, 0x05, 0x1e, 0x01, 0x00, 0x01, 0xfd, 0x54, 0x00, 0x00, 0x00, 0x2c, 0x01, 0xfd, 0x08, 0x03, 0x00, 0x00, 0x37, 0x01, 0xfd, 0x09, 0x03, 0x00, 0x00, 0x3a, 0x01, 0x94, 0x32, 0x00, 0x94, 0x40, 0x00, 0x9b, 0x00, 0x0b, 0x1e, 0x0e, 0x00, 0x6c, 0x01, 0x66, 0x01, 0x08, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x08, 0x00, 0x00, 0x00, 0x45, 0x01, 0x9b, 0x00, 0x08, 0x9b, 0x01, 0x59, 0x1e, 0x0f, 0x00, 0x01, 0x9b, 0x01, 0x00, 0x65, 0x20, 0x67, 0x6f, 0x72, 0x04, 0x65, 0x50, 0x4d, 0x56, 0x4e, 0x04, 0x1e, 0x11, 0x01, 0x9b, 0x02, 0x07, 0x1e, 0x0e, 0x02, 0x6c, 0x03, 0x66, 0x03, 0x10, 0x00, 0x00, 0x00, 0x9b, 0x04, 0x10, 0xfc, 0x03, 0x04, 0x3d, 0x01, 0x9b, 0x00, 0x08, 0x9b, 0x01, 0x59, 0x1e, 0x0f, 0x00, 0x01, 0x9b, 0x01, 0x0b, 0xa2, 0x1e, 0x0e, 0x01, 0xa5, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x9b, 0x00, 0x08, 0x9b, 0x01, 0x00, 0x1e, 0x0f, 0x00, 0x01, 0x9b, 0x01, 0x0b, 0xa2, 0x1e, 0x0e, 0x01, 0xa5, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x94, 0x48, 0x00, 0x9b, 0x00, 0x0b, 0x1e, 0x0e, 0x00, 0x6c, 0x01, 0x66, 0x01, 0x08, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x08, 0x00, 0x00, 0x00, 0x45, 0x01, 0x9b, 0x00, 0x0b, 0x1e, 0x0e, 0x00, 0x6c, 0x01, 0x66, 0x01, 0x01, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x01, 0x00, 0x00, 0x00, 0x21, 0x01, 0x6c, 0x01, 0x66, 0x01, 0x02, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x02, 0x00, 0x00, 0x00, 0x21, 0x01, 0x9b, 0x01, 0x0c, 0x1e, 0x0e, 0x01, 0x6c, 0x02, 0x66, 0x02, 0x04, 0x00, 0x00, 0x00, 0xfe, 0x02, 0x04, 0x00, 0x00, 0x00, 0x21, 0x01, 0x94, 0xf4, 0x01, 0x9b, 0x01, 0x0c, 0x1e, 0x0e, 0x01, 0x6c, 0x02, 0x66, 0x02, 0x04, 0x00, 0x00, 0x00, 0xfe, 0x02, 0x04, 0x00, 0x00, 0x00, 0x21, 0x01, 0xfb, 0x3d, 0x01, 0x90, 0x01, 0x51, 0x00, 0x00, 0x00, 0x7f, 0x01, 0xfb, 0x45, 0x01, 0x90, 0x01, 0x44, 0x00, 0x00, 0x00, 0x7f, 0x01, 0xfb, 0x45, 0x01, 0x90, 0x01, 0x54, 0x00, 0x00, 0x00, 0x7f, 0x01, 0xfb, 0x45, 0x01, 0xfb, 0x45, 0x01, 0xfb, 0x45, 0x01, 0x90, 0x01, 0x00, 0x01, 0x00, 0x00, 0x7f, 0x01,
+};
+const unsigned char EnterProgModeHvUpt_0[339] = {
+ 0x9b, 0x00, 0x08, 0x9b, 0x01, 0x03, 0x1e, 0x01, 0x00, 0x01, 0xfd, 0x54, 0x00, 0x00, 0x00, 0x3a, 0x01, 0xfd, 0x08, 0x03, 0x00, 0x00, 0x45, 0x01, 0xfd, 0x09, 0x03, 0x00, 0x00, 0x48, 0x01, 0xfd, 0x19, 0x00, 0x00, 0x00, 0x24, 0x01, 0xfd, 0x1b, 0x00, 0x00, 0x00, 0x24, 0x01, 0x94, 0x32, 0x00, 0x94, 0x40, 0x00, 0x9b, 0x00, 0x0b, 0x1e, 0x0e, 0x00, 0x6c, 0x01, 0x66, 0x01, 0x08, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x08, 0x00, 0x00, 0x00, 0x53, 0x01, 0x9b, 0x00, 0x08, 0x9b, 0x01, 0x59, 0x1e, 0x0f, 0x00, 0x01, 0x9b, 0x01, 0x00, 0x65, 0x20, 0x67, 0x6f, 0x72, 0x04, 0x65, 0x50, 0x4d, 0x56, 0x4e, 0x04, 0x1e, 0x11, 0x01, 0x9b, 0x02, 0x07, 0x1e, 0x0e, 0x02, 0x6c, 0x03, 0x66, 0x03, 0x10, 0x00, 0x00, 0x00, 0x9b, 0x04, 0x10, 0xfc, 0x03, 0x04, 0x4b, 0x01, 0x9b, 0x00, 0x08, 0x9b, 0x01, 0x59, 0x1e, 0x0f, 0x00, 0x01, 0x9b, 0x01, 0x0b, 0xa2, 0x1e, 0x0e, 0x01, 0xa5, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x9b, 0x00, 0x08, 0x9b, 0x01, 0x00, 0x1e, 0x0f, 0x00, 0x01, 0x9b, 0x01, 0x0b, 0xa2, 0x1e, 0x0e, 0x01, 0xa5, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x94, 0x48, 0x00, 0x9b, 0x00, 0x0b, 0x1e, 0x0e, 0x00, 0x6c, 0x01, 0x66, 0x01, 0x08, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x08, 0x00, 0x00, 0x00, 0x53, 0x01, 0x9b, 0x00, 0x0b, 0x1e, 0x0e, 0x00, 0x6c, 0x01, 0x66, 0x01, 0x01, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x01, 0x00, 0x00, 0x00, 0x2f, 0x01, 0x6c, 0x01, 0x66, 0x01, 0x02, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x02, 0x00, 0x00, 0x00, 0x2f, 0x01, 0x9b, 0x01, 0x0c, 0x1e, 0x0e, 0x01, 0x6c, 0x02, 0x66, 0x02, 0x04, 0x00, 0x00, 0x00, 0xfe, 0x02, 0x04, 0x00, 0x00, 0x00, 0x2f, 0x01, 0x94, 0xf4, 0x01, 0x9b, 0x01, 0x0c, 0x1e, 0x0e, 0x01, 0x6c, 0x02, 0x66, 0x02, 0x04, 0x00, 0x00, 0x00, 0xfe, 0x02, 0x04, 0x00, 0x00, 0x00, 0x2f, 0x01, 0xfb, 0x4b, 0x01, 0x90, 0x01, 0x51, 0x00, 0x00, 0x00, 0x7f, 0x01, 0xfb, 0x53, 0x01, 0x90, 0x01, 0x44, 0x00, 0x00, 0x00, 0x7f, 0x01, 0xfb, 0x53, 0x01, 0x90, 0x01, 0x54, 0x00, 0x00, 0x00, 0x7f, 0x01, 0xfb, 0x53, 0x01, 0xfb, 0x53, 0x01, 0xfb, 0x53, 0x01, 0x90, 0x01, 0x00, 0x01, 0x00, 0x00, 0x7f, 0x01,
+};
+const unsigned char ExitProgMode_0[22] = {
+ 0x9b, 0x00, 0x08, 0x9b, 0x01, 0x59, 0x1e, 0x0f, 0x00, 0x01, 0x9b, 0x00, 0x08, 0x9b, 0x01, 0x00, 0x1e, 0x0f, 0x00, 0x01, 0x1e, 0x02,
+};
+const unsigned char SetSpeed_0[5] = {
+ 0x91, 0x00, 0x1e, 0x14, 0x00,
+};
+const unsigned char GetDeviceID_0[33] = {
+ 0x95, 0x90, 0x00, 0x00, 0x11, 0x00, 0x00, 0x1e, 0x09, 0x00, 0x9c, 0x01, 0x03, 0x00, 0x1e, 0x10, 0x01, 0x9b, 0x02, 0x03, 0x1e, 0x0c, 0x02, 0x90, 0x02, 0x01, 0x0f, 0x00, 0x00, 0x1e, 0x03, 0x02, 0x9f,
+};
+const unsigned char GetDeviceID_1[33] = {
+ 0x95, 0x90, 0x00, 0x80, 0x10, 0x00, 0x00, 0x1e, 0x09, 0x00, 0x9c, 0x01, 0x03, 0x00, 0x1e, 0x10, 0x01, 0x9b, 0x02, 0x03, 0x1e, 0x0c, 0x02, 0x90, 0x02, 0x01, 0x0f, 0x00, 0x00, 0x1e, 0x03, 0x02, 0x9f,
+};
+const unsigned char EraseChip_0[184] = {
+ 0x94, 0x32, 0x00, 0x94, 0x40, 0x00, 0x90, 0x01, 0x00, 0x00, 0x00, 0x00, 0x65, 0x65, 0x73, 0x61, 0x72, 0x04, 0x65, 0x45, 0x4d, 0x56, 0x4e, 0x04, 0x1e, 0x11, 0x01, 0x90, 0x02, 0x07, 0x00, 0x00, 0x00, 0x1e, 0x0e, 0x02, 0x6c, 0x03, 0x66, 0x03, 0x08, 0x00, 0x00, 0x00, 0x90, 0x04, 0x08, 0x00, 0x00, 0x00, 0xfc, 0x03, 0x04, 0xaf, 0x00, 0x90, 0x00, 0x08, 0x00, 0x00, 0x00, 0x90, 0x01, 0x59, 0x00, 0x00, 0x00, 0x1e, 0x0f, 0x00, 0x01, 0x90, 0x01, 0x0b, 0x00, 0x00, 0x00, 0xa2, 0x1e, 0x0e, 0x01, 0xa5, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x90, 0x00, 0x08, 0x00, 0x00, 0x00, 0x90, 0x01, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x0f, 0x00, 0x01, 0x90, 0x01, 0x0b, 0x00, 0x00, 0x00, 0xa2, 0x1e, 0x0e, 0x01, 0xa5, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x90, 0x01, 0x0b, 0x00, 0x00, 0x00, 0xa2, 0x94, 0x02, 0x00, 0x1e, 0x0e, 0x01, 0xa5, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x1e, 0x0e, 0x01, 0x6c, 0x03, 0x66, 0x03, 0x40, 0x00, 0x00, 0x00, 0xfe, 0x03, 0x40, 0x00, 0x00, 0x00, 0xaf, 0x00, 0xfb, 0xb7, 0x00, 0x90, 0x01, 0x00, 0x01, 0x00, 0x00, 0x7f, 0x01, 0x5a,
+};
+const unsigned char WriteProgmem_0[231] = {
+ 0x91, 0x00, 0x91, 0x01, 0x90, 0x02, 0x08, 0x10, 0x00, 0x00, 0x1e, 0x03, 0x02, 0x6c, 0x0a, 0x90, 0x02, 0x09, 0x10, 0x00, 0x00, 0x1e, 0x03, 0x02, 0x6c, 0x0b, 0x90, 0x11, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0f, 0x40, 0x00, 0x00, 0x00, 0xfa, 0x01, 0x0f, 0x2e, 0x00, 0x60, 0x0f, 0x01, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x02, 0x00, 0x10, 0x00, 0x00, 0x90, 0x03, 0x04, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x02, 0x03, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x10, 0x00, 0x01, 0x00, 0x00, 0xfa, 0x0f, 0x10, 0x7c, 0x00, 0x60, 0x10, 0x0f, 0x1e, 0x09, 0x00, 0x60, 0x04, 0x10, 0x67, 0x04, 0x01, 0x1e, 0x10, 0x04, 0x1e, 0x0b, 0x04, 0x6a, 0x0f, 0x10, 0x6e, 0x00, 0x10, 0x6a, 0x01, 0x10, 0xfc, 0x0f, 0x11, 0x6e, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x03, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x6c, 0x0c, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0d, 0xd3, 0x00, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0xfc, 0x01, 0x11, 0x20, 0x00, 0x90, 0x02, 0x08, 0x10, 0x00, 0x00, 0x1e, 0x06, 0x02, 0x0a, 0x90, 0x02, 0x09, 0x10, 0x00, 0x00, 0x1e, 0x06, 0x02, 0x0b,
+};
+const unsigned char WriteProgmem_1[231] = {
+ 0x91, 0x00, 0x91, 0x01, 0x90, 0x02, 0x08, 0x10, 0x00, 0x00, 0x1e, 0x03, 0x02, 0x6c, 0x0a, 0x90, 0x02, 0x09, 0x10, 0x00, 0x00, 0x1e, 0x03, 0x02, 0x6c, 0x0b, 0x90, 0x11, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0f, 0x80, 0x00, 0x00, 0x00, 0xfa, 0x01, 0x0f, 0x2e, 0x00, 0x60, 0x0f, 0x01, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x02, 0x00, 0x10, 0x00, 0x00, 0x90, 0x03, 0x04, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x02, 0x03, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x10, 0x00, 0x01, 0x00, 0x00, 0xfa, 0x0f, 0x10, 0x7c, 0x00, 0x60, 0x10, 0x0f, 0x1e, 0x09, 0x00, 0x60, 0x04, 0x10, 0x67, 0x04, 0x01, 0x1e, 0x10, 0x04, 0x1e, 0x0b, 0x04, 0x6a, 0x0f, 0x10, 0x6e, 0x00, 0x10, 0x6a, 0x01, 0x10, 0xfc, 0x0f, 0x11, 0x6e, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x03, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x6c, 0x0c, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0d, 0xd3, 0x00, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0xfc, 0x01, 0x11, 0x20, 0x00, 0x90, 0x02, 0x08, 0x10, 0x00, 0x00, 0x1e, 0x06, 0x02, 0x0a, 0x90, 0x02, 0x09, 0x10, 0x00, 0x00, 0x1e, 0x06, 0x02, 0x0b,
+};
+const unsigned char WriteProgmem_2[272] = {
+ 0x91, 0x00, 0x91, 0x01, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x11, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0f, 0x00, 0x02, 0x00, 0x00, 0xfa, 0x01, 0x0f, 0x30, 0x00, 0x60, 0x0f, 0x01, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x08, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x90, 0x06, 0xff, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x00, 0x06, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x02, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x90, 0x10, 0x00, 0x01, 0x00, 0x00, 0xfa, 0x0f, 0x10, 0xa8, 0x00, 0x60, 0x10, 0x0f, 0x1e, 0x09, 0x00, 0x60, 0x04, 0x10, 0x67, 0x04, 0x01, 0x1e, 0x10, 0x04, 0x1e, 0x0b, 0x04, 0x6a, 0x0f, 0x10, 0x6e, 0x00, 0x10, 0x6a, 0x01, 0x10, 0xfc, 0x0f, 0x11, 0x9a, 0x00, 0x6c, 0x0c, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0d, 0x00, 0x01, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0xfc, 0x01, 0x11, 0x22, 0x00, 0x5a, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07,
+};
+const unsigned char WriteProgmem_3[231] = {
+ 0x91, 0x00, 0x91, 0x01, 0x90, 0x02, 0x0c, 0x10, 0x00, 0x00, 0x1e, 0x03, 0x02, 0x6c, 0x0a, 0x90, 0x02, 0x0d, 0x10, 0x00, 0x00, 0x1e, 0x03, 0x02, 0x6c, 0x0b, 0x90, 0x11, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0f, 0x80, 0x00, 0x00, 0x00, 0xfa, 0x01, 0x0f, 0x2e, 0x00, 0x60, 0x0f, 0x01, 0x90, 0x02, 0x06, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x02, 0x00, 0x10, 0x00, 0x00, 0x90, 0x03, 0x0f, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x02, 0x03, 0x90, 0x02, 0x06, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x10, 0x00, 0x01, 0x00, 0x00, 0xfa, 0x0f, 0x10, 0x7c, 0x00, 0x60, 0x10, 0x0f, 0x1e, 0x09, 0x00, 0x60, 0x04, 0x10, 0x67, 0x04, 0x01, 0x1e, 0x10, 0x04, 0x1e, 0x0b, 0x04, 0x6a, 0x0f, 0x10, 0x6e, 0x00, 0x10, 0x6a, 0x01, 0x10, 0xfc, 0x0f, 0x11, 0x6e, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x05, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x6c, 0x0c, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0d, 0xd3, 0x00, 0x90, 0x02, 0x06, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0xfc, 0x01, 0x11, 0x20, 0x00, 0x90, 0x02, 0x0c, 0x10, 0x00, 0x00, 0x1e, 0x06, 0x02, 0x0a, 0x90, 0x02, 0x0d, 0x10, 0x00, 0x00, 0x1e, 0x06, 0x02, 0x0b,
+};
+const unsigned char WriteProgmem_4[272] = {
+ 0x91, 0x00, 0x91, 0x01, 0x90, 0x02, 0x06, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x11, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0f, 0x00, 0x02, 0x00, 0x00, 0xfa, 0x01, 0x0f, 0x30, 0x00, 0x60, 0x0f, 0x01, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x08, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x90, 0x06, 0xff, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x00, 0x06, 0x90, 0x02, 0x06, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x90, 0x02, 0x06, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x02, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x90, 0x10, 0x00, 0x01, 0x00, 0x00, 0xfa, 0x0f, 0x10, 0xa8, 0x00, 0x60, 0x10, 0x0f, 0x1e, 0x09, 0x00, 0x60, 0x04, 0x10, 0x67, 0x04, 0x01, 0x1e, 0x10, 0x04, 0x1e, 0x0b, 0x04, 0x6a, 0x0f, 0x10, 0x6e, 0x00, 0x10, 0x6a, 0x01, 0x10, 0xfc, 0x0f, 0x11, 0x9a, 0x00, 0x6c, 0x0c, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0d, 0x00, 0x01, 0x90, 0x02, 0x06, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0xfc, 0x01, 0x11, 0x22, 0x00, 0x5a, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07,
+};
+const unsigned char WriteProgmem_5[231] = {
+ 0x91, 0x00, 0x91, 0x01, 0x90, 0x02, 0x0c, 0x10, 0x00, 0x00, 0x1e, 0x03, 0x02, 0x6c, 0x0a, 0x90, 0x02, 0x0d, 0x10, 0x00, 0x00, 0x1e, 0x03, 0x02, 0x6c, 0x0b, 0x90, 0x11, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0f, 0x40, 0x00, 0x00, 0x00, 0xfa, 0x01, 0x0f, 0x2e, 0x00, 0x60, 0x0f, 0x01, 0x90, 0x02, 0x06, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x02, 0x00, 0x10, 0x00, 0x00, 0x90, 0x03, 0x0f, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x02, 0x03, 0x90, 0x02, 0x06, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x10, 0x00, 0x01, 0x00, 0x00, 0xfa, 0x0f, 0x10, 0x7c, 0x00, 0x60, 0x10, 0x0f, 0x1e, 0x09, 0x00, 0x60, 0x04, 0x10, 0x67, 0x04, 0x01, 0x1e, 0x10, 0x04, 0x1e, 0x0b, 0x04, 0x6a, 0x0f, 0x10, 0x6e, 0x00, 0x10, 0x6a, 0x01, 0x10, 0xfc, 0x0f, 0x11, 0x6e, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x05, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x6c, 0x0c, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0d, 0xd3, 0x00, 0x90, 0x02, 0x06, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0xfc, 0x01, 0x11, 0x20, 0x00, 0x90, 0x02, 0x0c, 0x10, 0x00, 0x00, 0x1e, 0x06, 0x02, 0x0a, 0x90, 0x02, 0x0d, 0x10, 0x00, 0x00, 0x1e, 0x06, 0x02, 0x0b,
+};
+const unsigned char WriteProgmem_6[272] = {
+ 0x91, 0x00, 0x91, 0x01, 0x90, 0x02, 0x07, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x11, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0f, 0x00, 0x02, 0x00, 0x00, 0xfa, 0x01, 0x0f, 0x30, 0x00, 0x60, 0x0f, 0x01, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x08, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x90, 0x06, 0xff, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x00, 0x06, 0x90, 0x02, 0x07, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x90, 0x02, 0x07, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x02, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x90, 0x10, 0x00, 0x01, 0x00, 0x00, 0xfa, 0x0f, 0x10, 0xa8, 0x00, 0x60, 0x10, 0x0f, 0x1e, 0x09, 0x00, 0x60, 0x04, 0x10, 0x67, 0x04, 0x01, 0x1e, 0x10, 0x04, 0x1e, 0x0b, 0x04, 0x6a, 0x0f, 0x10, 0x6e, 0x00, 0x10, 0x6a, 0x01, 0x10, 0xfc, 0x0f, 0x11, 0x9a, 0x00, 0x6c, 0x0c, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0d, 0x00, 0x01, 0x90, 0x02, 0x07, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0xfc, 0x01, 0x11, 0x22, 0x00, 0x5a, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07,
+};
+const unsigned char ReadProgmem_0[73] = {
+ 0x91, 0x00, 0x91, 0x01, 0x95, 0x90, 0x11, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0f, 0x40, 0x00, 0x00, 0x00, 0xfa, 0x01, 0x0f, 0x19, 0x00, 0x60, 0x0f, 0x01, 0x90, 0x10, 0x00, 0x01, 0x00, 0x00, 0xfa, 0x0f, 0x10, 0x27, 0x00, 0x60, 0x10, 0x0f, 0x1e, 0x09, 0x00, 0x60, 0x04, 0x10, 0x67, 0x04, 0x01, 0x1e, 0x10, 0x04, 0x1e, 0x0d, 0x04, 0x6a, 0x0f, 0x10, 0x6e, 0x00, 0x10, 0x6a, 0x01, 0x10, 0xfc, 0x0f, 0x11, 0x19, 0x00, 0xfc, 0x01, 0x11, 0x0b, 0x00,
+};
+const unsigned char ReadProgmem_1[73] = {
+ 0x91, 0x00, 0x91, 0x01, 0x95, 0x90, 0x11, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0f, 0x80, 0x00, 0x00, 0x00, 0xfa, 0x01, 0x0f, 0x19, 0x00, 0x60, 0x0f, 0x01, 0x90, 0x10, 0x00, 0x01, 0x00, 0x00, 0xfa, 0x0f, 0x10, 0x27, 0x00, 0x60, 0x10, 0x0f, 0x1e, 0x09, 0x00, 0x60, 0x04, 0x10, 0x67, 0x04, 0x01, 0x1e, 0x10, 0x04, 0x1e, 0x0d, 0x04, 0x6a, 0x0f, 0x10, 0x6e, 0x00, 0x10, 0x6a, 0x01, 0x10, 0xfc, 0x0f, 0x11, 0x19, 0x00, 0xfc, 0x01, 0x11, 0x0b, 0x00,
+};
+const unsigned char ReadProgmem_2[73] = {
+ 0x91, 0x00, 0x91, 0x01, 0x95, 0x90, 0x11, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0f, 0x00, 0x02, 0x00, 0x00, 0xfa, 0x01, 0x0f, 0x19, 0x00, 0x60, 0x0f, 0x01, 0x90, 0x10, 0x00, 0x01, 0x00, 0x00, 0xfa, 0x0f, 0x10, 0x27, 0x00, 0x60, 0x10, 0x0f, 0x1e, 0x09, 0x00, 0x60, 0x04, 0x10, 0x67, 0x04, 0x01, 0x1e, 0x10, 0x04, 0x1e, 0x0d, 0x04, 0x6a, 0x0f, 0x10, 0x6e, 0x00, 0x10, 0x6a, 0x01, 0x10, 0xfc, 0x0f, 0x11, 0x19, 0x00, 0xfc, 0x01, 0x11, 0x0b, 0x00,
+};
+const unsigned char WriteDataEEmem_0[208] = {
+ 0x91, 0x00, 0x91, 0x01, 0x90, 0x11, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0f, 0x20, 0x00, 0x00, 0x00, 0xfa, 0x01, 0x0f, 0x18, 0x00, 0x60, 0x0f, 0x01, 0x90, 0x03, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x03, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x90, 0x02, 0x00, 0x10, 0x00, 0x00, 0x1e, 0x06, 0x02, 0x03, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x02, 0x00, 0x10, 0x00, 0x00, 0x90, 0x03, 0x04, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x02, 0x03, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x10, 0x00, 0x01, 0x00, 0x00, 0xfa, 0x0f, 0x10, 0x7e, 0x00, 0x60, 0x10, 0x0f, 0x1e, 0x09, 0x00, 0x1e, 0x10, 0x10, 0x1e, 0x0a, 0x10, 0x6a, 0x0f, 0x10, 0x6e, 0x00, 0x10, 0x6a, 0x01, 0x10, 0xfc, 0x0f, 0x11, 0x70, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x03, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x6c, 0x0c, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0d, 0xcf, 0x00, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0xfc, 0x01, 0x11, 0x0a, 0x00, 0xaf,
+};
+const unsigned char WriteDataEEmem_1[208] = {
+ 0x91, 0x00, 0x91, 0x01, 0x90, 0x11, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0f, 0x40, 0x00, 0x00, 0x00, 0xfa, 0x01, 0x0f, 0x18, 0x00, 0x60, 0x0f, 0x01, 0x90, 0x03, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x03, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x90, 0x02, 0x00, 0x10, 0x00, 0x00, 0x1e, 0x06, 0x02, 0x03, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x02, 0x00, 0x10, 0x00, 0x00, 0x90, 0x03, 0x04, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x02, 0x03, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x10, 0x00, 0x01, 0x00, 0x00, 0xfa, 0x0f, 0x10, 0x7e, 0x00, 0x60, 0x10, 0x0f, 0x1e, 0x09, 0x00, 0x1e, 0x10, 0x10, 0x1e, 0x0a, 0x10, 0x6a, 0x0f, 0x10, 0x6e, 0x00, 0x10, 0x6a, 0x01, 0x10, 0xfc, 0x0f, 0x11, 0x70, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x03, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x6c, 0x0c, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0d, 0xcf, 0x00, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0xfc, 0x01, 0x11, 0x0a, 0x00, 0xaf,
+};
+const unsigned char WriteDataEEmem_2[176] = {
+ 0x91, 0x00, 0x91, 0x01, 0x90, 0x11, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0f, 0x01, 0x00, 0x00, 0x00, 0xfa, 0x01, 0x0f, 0x18, 0x00, 0x60, 0x0f, 0x01, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x13, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x90, 0x10, 0x00, 0x01, 0x00, 0x00, 0xfa, 0x0f, 0x10, 0x4e, 0x00, 0x60, 0x10, 0x0f, 0x1e, 0x09, 0x00, 0x1e, 0x10, 0x10, 0x1e, 0x0a, 0x10, 0x6a, 0x0f, 0x10, 0x6e, 0x00, 0x10, 0x6a, 0x01, 0x10, 0xfc, 0x0f, 0x11, 0x40, 0x00, 0x6c, 0x0c, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0d, 0xa0, 0x00, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0xfc, 0x01, 0x11, 0x0a, 0x00, 0x5a, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07,
+};
+const unsigned char WriteDataEEmem_3[208] = {
+ 0x91, 0x00, 0x91, 0x01, 0x90, 0x11, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0f, 0x08, 0x00, 0x00, 0x00, 0xfa, 0x01, 0x0f, 0x18, 0x00, 0x60, 0x0f, 0x01, 0x90, 0x03, 0x1f, 0x00, 0x00, 0x00, 0xfe, 0x03, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x90, 0x02, 0x00, 0x10, 0x00, 0x00, 0x1e, 0x06, 0x02, 0x03, 0x90, 0x02, 0x06, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x02, 0x00, 0x10, 0x00, 0x00, 0x90, 0x03, 0x0f, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x02, 0x03, 0x90, 0x02, 0x06, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x10, 0x00, 0x01, 0x00, 0x00, 0xfa, 0x0f, 0x10, 0x7e, 0x00, 0x60, 0x10, 0x0f, 0x1e, 0x09, 0x00, 0x1e, 0x10, 0x10, 0x1e, 0x0a, 0x10, 0x6a, 0x0f, 0x10, 0x6e, 0x00, 0x10, 0x6a, 0x01, 0x10, 0xfc, 0x0f, 0x11, 0x70, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x15, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x6c, 0x0c, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0d, 0xcf, 0x00, 0x90, 0x02, 0x06, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0xfc, 0x01, 0x11, 0x0a, 0x00, 0xaf,
+};
+const unsigned char WriteDataEEmem_4[176] = {
+ 0x91, 0x00, 0x91, 0x01, 0x90, 0x11, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0f, 0x01, 0x00, 0x00, 0x00, 0xfa, 0x01, 0x0f, 0x18, 0x00, 0x60, 0x0f, 0x01, 0x90, 0x02, 0x06, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x13, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x90, 0x10, 0x00, 0x01, 0x00, 0x00, 0xfa, 0x0f, 0x10, 0x4e, 0x00, 0x60, 0x10, 0x0f, 0x1e, 0x09, 0x00, 0x1e, 0x10, 0x10, 0x1e, 0x0a, 0x10, 0x6a, 0x0f, 0x10, 0x6e, 0x00, 0x10, 0x6a, 0x01, 0x10, 0xfc, 0x0f, 0x11, 0x40, 0x00, 0x6c, 0x0c, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0d, 0xa0, 0x00, 0x90, 0x02, 0x06, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0xfc, 0x01, 0x11, 0x0a, 0x00, 0x5a, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07,
+};
+const unsigned char WriteDataEEmem_5[176] = {
+ 0x91, 0x00, 0x91, 0x01, 0x90, 0x11, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0f, 0x01, 0x00, 0x00, 0x00, 0xfa, 0x01, 0x0f, 0x18, 0x00, 0x60, 0x0f, 0x01, 0x90, 0x02, 0x07, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x13, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x90, 0x10, 0x00, 0x01, 0x00, 0x00, 0xfa, 0x0f, 0x10, 0x4e, 0x00, 0x60, 0x10, 0x0f, 0x1e, 0x09, 0x00, 0x1e, 0x10, 0x10, 0x1e, 0x0a, 0x10, 0x6a, 0x0f, 0x10, 0x6e, 0x00, 0x10, 0x6a, 0x01, 0x10, 0xfc, 0x0f, 0x11, 0x40, 0x00, 0x6c, 0x0c, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0d, 0xa0, 0x00, 0x90, 0x02, 0x07, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0xfc, 0x01, 0x11, 0x0a, 0x00, 0x5a, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07,
+};
+const unsigned char ReadDataEEmem_0[67] = {
+ 0x91, 0x00, 0x91, 0x01, 0x95, 0x90, 0x11, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0f, 0x20, 0x00, 0x00, 0x00, 0xfa, 0x01, 0x0f, 0x19, 0x00, 0x60, 0x0f, 0x01, 0x90, 0x10, 0x00, 0x01, 0x00, 0x00, 0xfa, 0x0f, 0x10, 0x27, 0x00, 0x60, 0x10, 0x0f, 0x1e, 0x09, 0x00, 0x1e, 0x10, 0x10, 0x1e, 0x0c, 0x10, 0x6a, 0x0f, 0x10, 0x6e, 0x00, 0x10, 0x6a, 0x01, 0x10, 0xfc, 0x0f, 0x11, 0x19, 0x00, 0xfc, 0x01, 0x11, 0x0b, 0x00,
+};
+const unsigned char ReadDataEEmem_1[67] = {
+ 0x91, 0x00, 0x91, 0x01, 0x95, 0x90, 0x11, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0f, 0x40, 0x00, 0x00, 0x00, 0xfa, 0x01, 0x0f, 0x19, 0x00, 0x60, 0x0f, 0x01, 0x90, 0x10, 0x00, 0x01, 0x00, 0x00, 0xfa, 0x0f, 0x10, 0x27, 0x00, 0x60, 0x10, 0x0f, 0x1e, 0x09, 0x00, 0x1e, 0x10, 0x10, 0x1e, 0x0c, 0x10, 0x6a, 0x0f, 0x10, 0x6e, 0x00, 0x10, 0x6a, 0x01, 0x10, 0xfc, 0x0f, 0x11, 0x19, 0x00, 0xfc, 0x01, 0x11, 0x0b, 0x00,
+};
+const unsigned char ReadDataEEmem_2[67] = {
+ 0x91, 0x00, 0x91, 0x01, 0x95, 0x90, 0x11, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0f, 0x01, 0x00, 0x00, 0x00, 0xfa, 0x01, 0x0f, 0x19, 0x00, 0x60, 0x0f, 0x01, 0x90, 0x10, 0x00, 0x01, 0x00, 0x00, 0xfa, 0x0f, 0x10, 0x27, 0x00, 0x60, 0x10, 0x0f, 0x1e, 0x09, 0x00, 0x1e, 0x10, 0x10, 0x1e, 0x0c, 0x10, 0x6a, 0x0f, 0x10, 0x6e, 0x00, 0x10, 0x6a, 0x01, 0x10, 0xfc, 0x0f, 0x11, 0x19, 0x00, 0xfc, 0x01, 0x11, 0x0b, 0x00,
+};
+const unsigned char ReadDataEEmem_3[67] = {
+ 0x91, 0x00, 0x91, 0x01, 0x95, 0x90, 0x11, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0f, 0x08, 0x00, 0x00, 0x00, 0xfa, 0x01, 0x0f, 0x19, 0x00, 0x60, 0x0f, 0x01, 0x90, 0x10, 0x00, 0x01, 0x00, 0x00, 0xfa, 0x0f, 0x10, 0x27, 0x00, 0x60, 0x10, 0x0f, 0x1e, 0x09, 0x00, 0x1e, 0x10, 0x10, 0x1e, 0x0c, 0x10, 0x6a, 0x0f, 0x10, 0x6e, 0x00, 0x10, 0x6a, 0x01, 0x10, 0xfc, 0x0f, 0x11, 0x19, 0x00, 0xfc, 0x01, 0x11, 0x0b, 0x00,
+};
+const unsigned char WriteConfigmem_0[369] = {
+ 0x91, 0x00, 0x91, 0x01, 0x90, 0x03, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x03, 0x01, 0x00, 0x00, 0x00, 0x93, 0x00, 0xad, 0x01, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x60, 0x03, 0x00, 0x60, 0x04, 0x00, 0x66, 0x03, 0xff, 0x00, 0x00, 0x00, 0x67, 0x04, 0x08, 0x66, 0x04, 0xff, 0x00, 0x00, 0x00, 0x90, 0x06, 0x08, 0x10, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x03, 0x90, 0x06, 0x09, 0x10, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x04, 0x90, 0x06, 0x06, 0x10, 0x00, 0x00, 0x99, 0x07, 0x1e, 0x06, 0x06, 0x07, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x07, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x92, 0x00, 0x01, 0x00, 0x00, 0x00, 0xae, 0xfb, 0x70, 0x01, 0xad, 0x01, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x60, 0x03, 0x00, 0x60, 0x04, 0x00, 0x66, 0x03, 0xff, 0x00, 0x00, 0x00, 0x67, 0x04, 0x08, 0x66, 0x04, 0xff, 0x00, 0x00, 0x00, 0x90, 0x06, 0x08, 0x10, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x03, 0x90, 0x06, 0x09, 0x10, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x04, 0x90, 0x03, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x03, 0x00, 0x00, 0x00, 0x00, 0xee, 0x00, 0x90, 0x02, 0x00, 0x10, 0x00, 0x00, 0x1e, 0x06, 0x02, 0x03, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x02, 0x00, 0x10, 0x00, 0x00, 0x90, 0x03, 0x04, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x02, 0x03, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x99, 0x07, 0x1e, 0x06, 0x00, 0x07, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x03, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x6c, 0x0c, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0d, 0x70, 0x01, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x92, 0x00, 0x01, 0x00, 0x00, 0x00, 0xae, 0xaf,
+};
+const unsigned char WriteConfigmem_1[128] = {
+ 0x91, 0x00, 0x91, 0x01, 0xad, 0x01, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x13, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x99, 0x03, 0x1e, 0x06, 0x00, 0x03, 0x6c, 0x0c, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0d, 0x70, 0x00, 0x90, 0x02, 0x02, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x92, 0x00, 0x01, 0x00, 0x00, 0x00, 0xae, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07,
+};
+const unsigned char WriteConfigmem_2[369] = {
+ 0x91, 0x00, 0x91, 0x01, 0x90, 0x03, 0x01, 0x00, 0x00, 0x00, 0xfe, 0x03, 0x01, 0x00, 0x00, 0x00, 0x93, 0x00, 0xad, 0x01, 0x90, 0x02, 0x06, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x60, 0x03, 0x00, 0x60, 0x04, 0x00, 0x66, 0x03, 0xff, 0x00, 0x00, 0x00, 0x67, 0x04, 0x08, 0x66, 0x04, 0xff, 0x00, 0x00, 0x00, 0x90, 0x06, 0x0c, 0x10, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x03, 0x90, 0x06, 0x0d, 0x10, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x04, 0x90, 0x06, 0x08, 0x10, 0x00, 0x00, 0x99, 0x07, 0x1e, 0x06, 0x06, 0x07, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x90, 0x02, 0x06, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x92, 0x00, 0x01, 0x00, 0x00, 0x00, 0xae, 0xfb, 0x70, 0x01, 0xad, 0x01, 0x90, 0x02, 0x06, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x60, 0x03, 0x00, 0x60, 0x04, 0x00, 0x66, 0x03, 0xff, 0x00, 0x00, 0x00, 0x67, 0x04, 0x08, 0x66, 0x04, 0xff, 0x00, 0x00, 0x00, 0x90, 0x06, 0x0c, 0x10, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x03, 0x90, 0x06, 0x0d, 0x10, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x04, 0x90, 0x03, 0x1f, 0x00, 0x00, 0x00, 0xfe, 0x03, 0x00, 0x00, 0x00, 0x00, 0xee, 0x00, 0x90, 0x02, 0x00, 0x10, 0x00, 0x00, 0x1e, 0x06, 0x02, 0x03, 0x90, 0x02, 0x06, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x02, 0x00, 0x10, 0x00, 0x00, 0x90, 0x03, 0x0f, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x02, 0x03, 0x90, 0x02, 0x06, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x99, 0x07, 0x1e, 0x06, 0x00, 0x07, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x15, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x6c, 0x0c, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0d, 0x70, 0x01, 0x90, 0x02, 0x06, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x92, 0x00, 0x01, 0x00, 0x00, 0x00, 0xae, 0xaf,
+};
+const unsigned char WriteConfigmem_3[128] = {
+ 0x91, 0x00, 0x91, 0x01, 0xad, 0x01, 0x90, 0x02, 0x06, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x13, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x99, 0x03, 0x1e, 0x06, 0x00, 0x03, 0x6c, 0x0c, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0d, 0x70, 0x00, 0x90, 0x02, 0x06, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x92, 0x00, 0x01, 0x00, 0x00, 0x00, 0xae, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07,
+};
+const unsigned char WriteConfigmem_4[128] = {
+ 0x91, 0x00, 0x91, 0x01, 0xad, 0x01, 0x90, 0x02, 0x07, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x13, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x99, 0x03, 0x1e, 0x06, 0x00, 0x03, 0x6c, 0x0c, 0x90, 0x0d, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0d, 0x70, 0x00, 0x90, 0x02, 0x07, 0x10, 0x00, 0x00, 0xa2, 0x1e, 0x03, 0x02, 0x94, 0x02, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07, 0x92, 0x00, 0x01, 0x00, 0x00, 0x00, 0xae, 0x90, 0x06, 0x00, 0x10, 0x00, 0x00, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x06, 0x07,
+};
+const unsigned char ReadConfigmem_0[19] = {
+ 0x91, 0x00, 0x91, 0x01, 0x95, 0xad, 0x01, 0x1e, 0x03, 0x00, 0x9f, 0x92, 0x00, 0x01, 0x00, 0x00, 0x00, 0xae, 0x5a,
+};
+const unsigned char WriteCSreg_0[8] = {
+ 0x99, 0x00, 0x99, 0x01, 0x1e, 0x0f, 0x00, 0x01,
+};
+const unsigned char ReadCSreg_0[6] = {
+ 0x99, 0x00, 0x1e, 0x0e, 0x00, 0x9f,
+};
+const unsigned char WriteMem8_0[20] = {
+ 0x91, 0x00, 0x91, 0x01, 0xad, 0x01, 0x99, 0x03, 0x1e, 0x06, 0x00, 0x03, 0x92, 0x00, 0x01, 0x00, 0x00, 0x00, 0xae, 0x5a,
+};
+const unsigned char ReadMem8_0[19] = {
+ 0x91, 0x00, 0x91, 0x01, 0x95, 0xad, 0x01, 0x1e, 0x03, 0x00, 0x9f, 0x92, 0x00, 0x01, 0x00, 0x00, 0x00, 0xae, 0x5a,
+};
+const unsigned char ReadSIB_0[7] = {
+ 0x95, 0x9b, 0x00, 0x02, 0x1e, 0x12, 0x00,
+};
+
+
+
+struct avr_script_lut avr_scripts = {
+ .EnterProgMode = EnterProgMode_0,
+ .EnterProgModeHvSp = EnterProgModeHvSp_0,
+ .EnterProgModeHvSpRst = EnterProgModeHvSpRst_0,
+ .EnterProgModeHvUpt = EnterProgModeHvUpt_0,
+ .ExitProgMode = ExitProgMode_0,
+ .SetSpeed = SetSpeed_0,
+ .GetDeviceID = NULL,
+ .EraseChip = EraseChip_0,
+ .WriteProgmem = NULL,
+ .ReadProgmem = NULL,
+ .WriteDataEEmem = NULL,
+ .ReadDataEEmem = NULL,
+ .WriteConfigmem = NULL,
+ .ReadConfigmem = ReadConfigmem_0,
+ .WriteCSreg = WriteCSreg_0,
+ .ReadCSreg = ReadCSreg_0,
+ .WriteMem8 = WriteMem8_0,
+ .ReadMem8 = ReadMem8_0,
+ .ReadSIB = ReadSIB_0,
+ .EnterProgMode_len = sizeof(EnterProgMode_0),
+ .EnterProgModeHvSp_len = sizeof(EnterProgModeHvSp_0),
+ .EnterProgModeHvSpRst_len = sizeof(EnterProgModeHvSpRst_0),
+ .EnterProgModeHvUpt_len = sizeof(EnterProgModeHvUpt_0),
+ .ExitProgMode_len = sizeof(ExitProgMode_0),
+ .SetSpeed_len = sizeof(SetSpeed_0),
+ .GetDeviceID_len = 0,
+ .EraseChip_len = sizeof(EraseChip_0),
+ .WriteProgmem_len = 0,
+ .ReadProgmem_len = 0,
+ .WriteDataEEmem_len = 0,
+ .ReadDataEEmem_len = 0,
+ .WriteConfigmem_len = 0,
+ .ReadConfigmem_len = sizeof(ReadConfigmem_0),
+ .WriteCSreg_len = sizeof(WriteCSreg_0),
+ .ReadCSreg_len = sizeof(ReadCSreg_0),
+ .WriteMem8_len = sizeof(WriteMem8_0),
+ .ReadMem8_len = sizeof(ReadMem8_0),
+ .ReadSIB_len = sizeof(ReadSIB_0),
+};
+
+
+char *chip_lut[] = {
+ "ATtiny416auto", "ATmega1608", "ATmega1609", "ATmega3208", "ATmega3209", "ATmega4808", "ATmega4809", "ATmega808",
+ "ATmega809", "ATtiny1604", "ATtiny1606", "ATtiny1607", "ATtiny1614", "ATtiny1616", "ATtiny1617", "ATtiny1624",
+ "ATtiny1626", "ATtiny1627", "ATtiny202", "ATtiny204", "ATtiny212", "ATtiny214", "ATtiny3216", "ATtiny3217",
+ "ATtiny3224", "ATtiny3226", "ATtiny3227", "ATtiny402", "ATtiny404", "ATtiny406", "ATtiny412", "ATtiny414",
+ "ATtiny416", "ATtiny417", "ATtiny424", "ATtiny426", "ATtiny427", "ATtiny804", "ATtiny806", "ATtiny807",
+ "ATtiny814", "ATtiny816", "ATtiny817", "ATtiny824", "ATtiny826", "ATtiny827", "AVR128DA28", "AVR128DA32",
+ "AVR128DA48", "AVR128DA64", "AVR128DB28", "AVR128DB32", "AVR128DB48", "AVR128DB64", "AVR16DD14", "AVR16DD20",
+ "AVR16DD28", "AVR16DD32", "AVR32DA28", "AVR32DA32", "AVR32DA48", "AVR32DB28", "AVR32DB32", "AVR32DB48",
+ "AVR32DD14", "AVR32DD20", "AVR32DD28", "AVR32DD32", "AVR64DA28", "AVR64DA32", "AVR64DA48", "AVR64DA64",
+ "AVR64DB28", "AVR64DB32", "AVR64DB48", "AVR64DB64", "AVR64DD14", "AVR64DD20", "AVR64DD28", "AVR64DD32",
+ "AVR64EA28", "AVR64EA32", "AVR64EA48", "AVR16DA28", "AVR16DA32", "AVR16DA48", "AVR16DB28", "AVR16DB32",
+ "AVR16DB48", "AVR16DU14", "AVR16DU20", "AVR16DU28", "AVR16DU32", "AVR16DV14", "AVR16DV20", "AVR32DU14",
+ "AVR32DU20", "AVR32DU28", "AVR32DU32", "AVR64DU28", "AVR64DU32", "AVR16EA28", "AVR16EA32", "AVR16EA48",
+ "AVR32EA28", "AVR32EA32", "AVR32EA48", "AVR8EA28", "AVR8EA32", "AVR16EB14", "AVR16EB20", "AVR16EB28",
+ "AVR16EB32", "AVR32EB28", "AVR32EB32", "AVR64EC48", "AVR32SD32", "AVR64SD48",
+};
+
+
+struct avr_script_lut* get_pickit_script(const char* partdesc) {
+ int namepos = -1;
+ for (int i = 0; i < 118; i++) {
+ if (strncmp(chip_lut[i], partdesc, 10) == 0) {
+ namepos = i;
+ break;
+ }
+ }
+ if (namepos == -1) {
+ return NULL;
+ }
+ switch (namepos) {
+ case 0: /* ATtiny416auto */
+ case 1: /* ATmega1608 */
+ case 2: /* ATmega1609 */
+ case 7: /* ATmega808 */
+ case 8: /* ATmega809 */
+ case 9: /* ATtiny1604 */
+ case 10: /* ATtiny1606 */
+ case 11: /* ATtiny1607 */
+ case 12: /* ATtiny1614 */
+ case 13: /* ATtiny1616 */
+ case 14: /* ATtiny1617 */
+ case 15: /* ATtiny1624 */
+ case 16: /* ATtiny1626 */
+ case 17: /* ATtiny1627 */
+ case 18: /* ATtiny202 */
+ case 19: /* ATtiny204 */
+ case 20: /* ATtiny212 */
+ case 21: /* ATtiny214 */
+ case 27: /* ATtiny402 */
+ case 28: /* ATtiny404 */
+ case 29: /* ATtiny406 */
+ case 30: /* ATtiny412 */
+ case 31: /* ATtiny414 */
+ case 32: /* ATtiny416 */
+ case 33: /* ATtiny417 */
+ case 34: /* ATtiny424 */
+ case 35: /* ATtiny426 */
+ case 36: /* ATtiny427 */
+ case 37: /* ATtiny804 */
+ case 38: /* ATtiny806 */
+ case 39: /* ATtiny807 */
+ case 40: /* ATtiny814 */
+ case 41: /* ATtiny816 */
+ case 42: /* ATtiny817 */
+ case 43: /* ATtiny824 */
+ case 44: /* ATtiny826 */
+ case 45: /* ATtiny827 */
+ avr_scripts.GetDeviceID = GetDeviceID_0;
+ avr_scripts.GetDeviceID_len = sizeof(GetDeviceID_0);
+ avr_scripts.WriteProgmem = WriteProgmem_0;
+ avr_scripts.WriteProgmem_len = sizeof(WriteProgmem_0);
+ avr_scripts.ReadProgmem = ReadProgmem_0;
+ avr_scripts.ReadProgmem_len = sizeof(ReadProgmem_0);
+ avr_scripts.WriteDataEEmem = WriteDataEEmem_0;
+ avr_scripts.WriteDataEEmem_len = sizeof(WriteDataEEmem_0);
+ avr_scripts.ReadDataEEmem = ReadDataEEmem_0;
+ avr_scripts.ReadDataEEmem_len = sizeof(ReadDataEEmem_0);
+ avr_scripts.WriteConfigmem = WriteConfigmem_0;
+ avr_scripts.WriteConfigmem_len = sizeof(WriteConfigmem_0);
+ break;
+ case 3: /* ATmega3208 */
+ case 4: /* ATmega3209 */
+ case 5: /* ATmega4808 */
+ case 6: /* ATmega4809 */
+ case 22: /* ATtiny3216 */
+ case 23: /* ATtiny3217 */
+ case 24: /* ATtiny3224 */
+ case 25: /* ATtiny3226 */
+ case 26: /* ATtiny3227 */
+ avr_scripts.GetDeviceID = GetDeviceID_0;
+ avr_scripts.GetDeviceID_len = sizeof(GetDeviceID_0);
+ avr_scripts.WriteProgmem = WriteProgmem_1;
+ avr_scripts.WriteProgmem_len = sizeof(WriteProgmem_1);
+ avr_scripts.ReadProgmem = ReadProgmem_1;
+ avr_scripts.ReadProgmem_len = sizeof(ReadProgmem_1);
+ avr_scripts.WriteDataEEmem = WriteDataEEmem_1;
+ avr_scripts.WriteDataEEmem_len = sizeof(WriteDataEEmem_1);
+ avr_scripts.ReadDataEEmem = ReadDataEEmem_1;
+ avr_scripts.ReadDataEEmem_len = sizeof(ReadDataEEmem_1);
+ avr_scripts.WriteConfigmem = WriteConfigmem_0;
+ avr_scripts.WriteConfigmem_len = sizeof(WriteConfigmem_0);
+ break;
+ case 46: /* AVR128DA28 */
+ case 47: /* AVR128DA32 */
+ case 48: /* AVR128DA48 */
+ case 49: /* AVR128DA64 */
+ case 50: /* AVR128DB28 */
+ case 51: /* AVR128DB32 */
+ case 52: /* AVR128DB48 */
+ case 53: /* AVR128DB64 */
+ case 54: /* AVR16DD14 */
+ case 55: /* AVR16DD20 */
+ case 56: /* AVR16DD28 */
+ case 57: /* AVR16DD32 */
+ case 58: /* AVR32DA28 */
+ case 59: /* AVR32DA32 */
+ case 60: /* AVR32DA48 */
+ case 61: /* AVR32DB28 */
+ case 62: /* AVR32DB32 */
+ case 63: /* AVR32DB48 */
+ case 64: /* AVR32DD14 */
+ case 65: /* AVR32DD20 */
+ case 66: /* AVR32DD28 */
+ case 67: /* AVR32DD32 */
+ case 68: /* AVR64DA28 */
+ case 69: /* AVR64DA32 */
+ case 70: /* AVR64DA48 */
+ case 71: /* AVR64DA64 */
+ case 72: /* AVR64DB28 */
+ case 73: /* AVR64DB32 */
+ case 74: /* AVR64DB48 */
+ case 75: /* AVR64DB64 */
+ case 76: /* AVR64DD14 */
+ case 77: /* AVR64DD20 */
+ case 78: /* AVR64DD28 */
+ case 79: /* AVR64DD32 */
+ case 83: /* AVR16DA28 */
+ case 84: /* AVR16DA32 */
+ case 85: /* AVR16DA48 */
+ case 86: /* AVR16DB28 */
+ case 87: /* AVR16DB32 */
+ case 88: /* AVR16DB48 */
+ avr_scripts.GetDeviceID = GetDeviceID_0;
+ avr_scripts.GetDeviceID_len = sizeof(GetDeviceID_0);
+ avr_scripts.WriteProgmem = WriteProgmem_2;
+ avr_scripts.WriteProgmem_len = sizeof(WriteProgmem_2);
+ avr_scripts.ReadProgmem = ReadProgmem_2;
+ avr_scripts.ReadProgmem_len = sizeof(ReadProgmem_2);
+ avr_scripts.WriteDataEEmem = WriteDataEEmem_2;
+ avr_scripts.WriteDataEEmem_len = sizeof(WriteDataEEmem_2);
+ avr_scripts.ReadDataEEmem = ReadDataEEmem_2;
+ avr_scripts.ReadDataEEmem_len = sizeof(ReadDataEEmem_2);
+ avr_scripts.WriteConfigmem = WriteConfigmem_1;
+ avr_scripts.WriteConfigmem_len = sizeof(WriteConfigmem_1);
+ break;
+ case 80: /* AVR64EA28 */
+ case 81: /* AVR64EA32 */
+ case 82: /* AVR64EA48 */
+ avr_scripts.GetDeviceID = GetDeviceID_0;
+ avr_scripts.GetDeviceID_len = sizeof(GetDeviceID_0);
+ avr_scripts.WriteProgmem = WriteProgmem_3;
+ avr_scripts.WriteProgmem_len = sizeof(WriteProgmem_3);
+ avr_scripts.ReadProgmem = ReadProgmem_1;
+ avr_scripts.ReadProgmem_len = sizeof(ReadProgmem_1);
+ avr_scripts.WriteDataEEmem = WriteDataEEmem_3;
+ avr_scripts.WriteDataEEmem_len = sizeof(WriteDataEEmem_3);
+ avr_scripts.ReadDataEEmem = ReadDataEEmem_3;
+ avr_scripts.ReadDataEEmem_len = sizeof(ReadDataEEmem_3);
+ avr_scripts.WriteConfigmem = WriteConfigmem_2;
+ avr_scripts.WriteConfigmem_len = sizeof(WriteConfigmem_2);
+ break;
+ case 89: /* AVR16DU14 */
+ case 90: /* AVR16DU20 */
+ case 91: /* AVR16DU28 */
+ case 92: /* AVR16DU32 */
+ case 93: /* AVR16DV14 */
+ case 94: /* AVR16DV20 */
+ case 95: /* AVR32DU14 */
+ case 96: /* AVR32DU20 */
+ case 97: /* AVR32DU28 */
+ case 98: /* AVR32DU32 */
+ case 99: /* AVR64DU28 */
+ case 100: /* AVR64DU32 */
+ avr_scripts.GetDeviceID = GetDeviceID_1;
+ avr_scripts.GetDeviceID_len = sizeof(GetDeviceID_1);
+ avr_scripts.WriteProgmem = WriteProgmem_4;
+ avr_scripts.WriteProgmem_len = sizeof(WriteProgmem_4);
+ avr_scripts.ReadProgmem = ReadProgmem_2;
+ avr_scripts.ReadProgmem_len = sizeof(ReadProgmem_2);
+ avr_scripts.WriteDataEEmem = WriteDataEEmem_4;
+ avr_scripts.WriteDataEEmem_len = sizeof(WriteDataEEmem_4);
+ avr_scripts.ReadDataEEmem = ReadDataEEmem_2;
+ avr_scripts.ReadDataEEmem_len = sizeof(ReadDataEEmem_2);
+ avr_scripts.WriteConfigmem = WriteConfigmem_3;
+ avr_scripts.WriteConfigmem_len = sizeof(WriteConfigmem_3);
+ break;
+ case 101: /* AVR16EA28 */
+ case 102: /* AVR16EA32 */
+ case 103: /* AVR16EA48 */
+ case 104: /* AVR32EA28 */
+ case 105: /* AVR32EA32 */
+ case 106: /* AVR32EA48 */
+ case 107: /* AVR8EA28 */
+ case 108: /* AVR8EA32 */
+ avr_scripts.GetDeviceID = GetDeviceID_0;
+ avr_scripts.GetDeviceID_len = sizeof(GetDeviceID_0);
+ avr_scripts.WriteProgmem = WriteProgmem_5;
+ avr_scripts.WriteProgmem_len = sizeof(WriteProgmem_5);
+ avr_scripts.ReadProgmem = ReadProgmem_0;
+ avr_scripts.ReadProgmem_len = sizeof(ReadProgmem_0);
+ avr_scripts.WriteDataEEmem = WriteDataEEmem_3;
+ avr_scripts.WriteDataEEmem_len = sizeof(WriteDataEEmem_3);
+ avr_scripts.ReadDataEEmem = ReadDataEEmem_3;
+ avr_scripts.ReadDataEEmem_len = sizeof(ReadDataEEmem_3);
+ avr_scripts.WriteConfigmem = WriteConfigmem_2;
+ avr_scripts.WriteConfigmem_len = sizeof(WriteConfigmem_2);
+ break;
+ case 109: /* AVR16EB14 */
+ case 110: /* AVR16EB20 */
+ case 111: /* AVR16EB28 */
+ case 112: /* AVR16EB32 */
+ case 113: /* AVR32EB28 */
+ case 114: /* AVR32EB32 */
+ avr_scripts.GetDeviceID = GetDeviceID_1;
+ avr_scripts.GetDeviceID_len = sizeof(GetDeviceID_1);
+ avr_scripts.WriteProgmem = WriteProgmem_5;
+ avr_scripts.WriteProgmem_len = sizeof(WriteProgmem_5);
+ avr_scripts.ReadProgmem = ReadProgmem_0;
+ avr_scripts.ReadProgmem_len = sizeof(ReadProgmem_0);
+ avr_scripts.WriteDataEEmem = WriteDataEEmem_3;
+ avr_scripts.WriteDataEEmem_len = sizeof(WriteDataEEmem_3);
+ avr_scripts.ReadDataEEmem = ReadDataEEmem_3;
+ avr_scripts.ReadDataEEmem_len = sizeof(ReadDataEEmem_3);
+ avr_scripts.WriteConfigmem = WriteConfigmem_2;
+ avr_scripts.WriteConfigmem_len = sizeof(WriteConfigmem_2);
+ break;
+ case 115: /* AVR64EC48 */
+ avr_scripts.GetDeviceID = GetDeviceID_1;
+ avr_scripts.GetDeviceID_len = sizeof(GetDeviceID_1);
+ avr_scripts.WriteProgmem = WriteProgmem_3;
+ avr_scripts.WriteProgmem_len = sizeof(WriteProgmem_3);
+ avr_scripts.ReadProgmem = ReadProgmem_1;
+ avr_scripts.ReadProgmem_len = sizeof(ReadProgmem_1);
+ avr_scripts.WriteDataEEmem = WriteDataEEmem_3;
+ avr_scripts.WriteDataEEmem_len = sizeof(WriteDataEEmem_3);
+ avr_scripts.ReadDataEEmem = ReadDataEEmem_3;
+ avr_scripts.ReadDataEEmem_len = sizeof(ReadDataEEmem_3);
+ avr_scripts.WriteConfigmem = WriteConfigmem_2;
+ avr_scripts.WriteConfigmem_len = sizeof(WriteConfigmem_2);
+ break;
+ case 116: /* AVR32SD32 */
+ case 117: /* AVR64SD48 */
+ avr_scripts.GetDeviceID = GetDeviceID_1;
+ avr_scripts.GetDeviceID_len = sizeof(GetDeviceID_1);
+ avr_scripts.WriteProgmem = WriteProgmem_6;
+ avr_scripts.WriteProgmem_len = sizeof(WriteProgmem_6);
+ avr_scripts.ReadProgmem = ReadProgmem_2;
+ avr_scripts.ReadProgmem_len = sizeof(ReadProgmem_2);
+ avr_scripts.WriteDataEEmem = WriteDataEEmem_5;
+ avr_scripts.WriteDataEEmem_len = sizeof(WriteDataEEmem_5);
+ avr_scripts.ReadDataEEmem = ReadDataEEmem_2;
+ avr_scripts.ReadDataEEmem_len = sizeof(ReadDataEEmem_2);
+ avr_scripts.WriteConfigmem = WriteConfigmem_4;
+ avr_scripts.WriteConfigmem_len = sizeof(WriteConfigmem_4);
+ break;
+ }
+ return &avr_scripts;
+ }
\ No newline at end of file
diff --git a/src/scripts_lut.h b/src/scripts_lut.h
new file mode 100644
index 000000000..76791b74a
--- /dev/null
+++ b/src/scripts_lut.h
@@ -0,0 +1,58 @@
+
+/* This file was auto-generated by scripts_decoder.py, changes may be overwritten */
+#ifndef scripts_lut_h
+#define scripts_lut_h
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+struct avr_script_lut {
+ const unsigned char *EnterProgMode;
+ unsigned int EnterProgMode_len;
+ const unsigned char *EnterProgModeHvSp;
+ unsigned int EnterProgModeHvSp_len;
+ const unsigned char *EnterProgModeHvSpRst;
+ unsigned int EnterProgModeHvSpRst_len;
+ const unsigned char *EnterProgModeHvUpt;
+ unsigned int EnterProgModeHvUpt_len;
+ const unsigned char *ExitProgMode;
+ unsigned int ExitProgMode_len;
+ const unsigned char *SetSpeed;
+ unsigned int SetSpeed_len;
+ const unsigned char *GetDeviceID;
+ unsigned int GetDeviceID_len;
+ const unsigned char *EraseChip;
+ unsigned int EraseChip_len;
+ const unsigned char *WriteProgmem;
+ unsigned int WriteProgmem_len;
+ const unsigned char *ReadProgmem;
+ unsigned int ReadProgmem_len;
+ const unsigned char *WriteDataEEmem;
+ unsigned int WriteDataEEmem_len;
+ const unsigned char *ReadDataEEmem;
+ unsigned int ReadDataEEmem_len;
+ const unsigned char *WriteCSreg;
+ unsigned int WriteCSreg_len;
+ const unsigned char *ReadCSreg;
+ unsigned int ReadCSreg_len;
+ const unsigned char *WriteMem8;
+ unsigned int WriteMem8_len;
+ const unsigned char *ReadMem8;
+ unsigned int ReadMem8_len;
+ const unsigned char *WriteConfigmem;
+ unsigned int WriteConfigmem_len;
+ const unsigned char *ReadConfigmem;
+ unsigned int ReadConfigmem_len;
+ const unsigned char *ReadSIB;
+ unsigned int ReadSIB_len;
+
+};
+
+struct avr_script_lut* get_pickit_script(const char *partdesc);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // scripts_lut_h
diff --git a/src/term.c b/src/term.c
index bab6732fc..d96634c78 100644
--- a/src/term.c
+++ b/src/term.c
@@ -415,17 +415,28 @@ static unsigned char *readbuf(const PROGRAMMER *pgm, const AVRPART *p, int argc,
}
report_progress(0, 1, "Reading");
- for(int j = 0; j < toread; j++) {
- int addr = (whence + j) % maxsize;
- int rc = pgm->read_byte_cached(pgm, p, mem, addr, &buf[j]);
- if (rc != 0) {
+ if (pgm->read_array != NULL) { // if the programmer can read multiple bytes
+ int rc = pgm->read_array(pgm, p, mem, whence, toread, buf);
+ if (rc < 0) {
report_progress(1, -1, NULL);
pmsg_error("(%s) error reading %s address 0x%05lx of part %s\n", cmd, mem->desc,
- (long) whence + j, p->desc);
+ (long) whence + rc, p->desc);
mmt_free(buf);
return NULL;
}
- report_progress(j, toread, NULL);
+ } else {
+ for(int j = 0; j < toread; j++) { // otherwise do byte-by-byte
+ int addr = (whence + j) % maxsize;
+ int rc = pgm->read_byte_cached(pgm, p, mem, addr, &buf[j]);
+ if (rc < 0) {
+ report_progress(1, -1, NULL);
+ pmsg_error("(%s) error reading %s address 0x%05lx of part %s\n", cmd, mem->desc,
+ (long) whence + j, p->desc);
+ mmt_free(buf);
+ return NULL;
+ }
+ report_progress(j, toread, NULL);
+ }
}
report_progress(1, 1, NULL);
@@ -845,7 +856,7 @@ static int cmd_write(const PROGRAMMER *pgm, const AVRPART *p, int argc, const ch
int rc = pgm->write_byte_cached(pgm, p, mem, addr+i, buf[i]);
if (rc == LIBAVRDUDE_SOFTFAIL) {
pmsg_warning("(write) programmer write protects %s address 0x%04x\n", mem->desc, addr+i);
- } else if(rc) {
+ } else if(rc < 0) {
pmsg_error("(write) error writing 0x%02x at 0x%05x, rc=%d\n", buf[i], addr+i, (int) rc);
if (rc == -1)
imsg_error("%*swrite operation not supported on memory %s\n", 8, "", mem->desc);
diff --git a/src/usbdevs.h b/src/usbdevs.h
index 6fc6b773d..7213badd0 100644
--- a/src/usbdevs.h
+++ b/src/usbdevs.h
@@ -40,6 +40,7 @@
#define USB_DEVICE_PICKIT4_AVR_MODE 0x2177
#define USB_DEVICE_PICKIT4_PIC_MODE 0x9012
#define USB_DEVICE_PICKIT4_PIC_MODE_BL 0x9017 // PICkit4 in bootloader mode
+#define USB_DEVICE_PICKIT5 0x9036
#define USB_DEVICE_SNAP_AVR_MODE 0x2180
#define USB_DEVICE_SNAP_PIC_MODE 0x9018
#define USB_DEVICE_SNAP_PIC_MODE_BL 0x9019 // SNAP in bootloader mode
diff --git a/tools/scripts_decoder.py b/tools/scripts_decoder.py
new file mode 100644
index 000000000..365dde8d3
--- /dev/null
+++ b/tools/scripts_decoder.py
@@ -0,0 +1,613 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+
+# this is a small python sketch that tries to find the PICkit5_TP folder
+# created by MPLAB X that contains the scripts.xml file.
+# Works on Windows and Linux (MacOS untested), as long as the default installation
+# folder was not changed. If it was changed, and the program is unable to locate
+# the scripts.xml file, you should be promted to enter a path. You can
+# either provide the path to the file, or to the directory providing the file.
+#
+# This file contains some functions that were used in initial develeopment
+# but are not needed anymore. However, they might provide useful, thus they
+# can be enabled by setting "user_input" to 1.
+#
+# The idea behind this program is to extract the sub-programs defined in the
+# script.xml. The file has a size of about 300MB, containing a lot of
+# redundand information as well as sub-programs for chips avr-dude doesn't
+# support, like ARM MCUs. This extracts the sub-programs, compares them
+# with already known and links them to the MCUs by creating a look-up
+# table. This Table is generated as a c/h file combo, making the integration
+# to the rest of avr-dude relatively easy, or at least I hope so.
+#
+# As the XML file is fairly large, a machine with at least 16GB RAM is recommended
+# Also, upon execution of the script, the old script_lut.c/h files will be overridden
+
+import os, fnmatch, mmap
+from pathlib import Path
+from xml.etree import ElementTree as ET
+
+user_input = 0
+
+# The list of functions, as a Python Dictionary, that will be used by avr-dude
+# The complete list of available functions can be found below
+c_dict = {
+ "EnterProgMode" : [],
+ "EnterProgModeHvSp" : [],
+ "EnterProgModeHvSpRst" : [],
+ "EnterProgModeHvUpt" : [],
+ "ExitProgMode" : [],
+ "SetSpeed" : [],
+ "GetDeviceID" : [],
+ "EraseChip" : [],
+ "WriteProgmem" : [],
+ "ReadProgmem" : [],
+ "WriteDataEEmem" : [],
+ "ReadDataEEmem" : [],
+ "WriteCSreg" : [],
+ "ReadCSreg" : [],
+ "WriteMem8" : [],
+ "ReadMem8" : [],
+ "WriteConfigmem" : [],
+ "ReadConfigmem" : [],
+ "ReadSIB" : [],
+}
+
+# A complete list of Functions defined in the scripts.xml
+# This string was used to generate an intermediate python file
+dict_header = \
+'''
+func_dict = {
+ "EnterProgMode" : [],
+ "EnterProgModeHvSp" : [],
+ "EnterProgModeHvSpRst" : [],
+ "EnterProgModeHvUpt" : [],
+ "ExitProgMode" : [],
+ "SetSpeed" : [],
+ "GetDeviceID" : [],
+ "EraseChip" : [],
+ "WriteProgmem" : [],
+ "ReadProgmem" : [],
+ "WriteDataEEmem" : [],
+ "ReadDataEEmem" : [],
+ "WriteConfigmem" : [],
+ "WriteConfigmemFuse" : [],
+ "WriteConfigmemLock" : [],
+ "ReadConfigmem" : [],
+ "ReadConfigmemFuse" : [],
+ "ReadConfigmemLock" : [],
+ "WriteIDmem" : [],
+ "ReadIDmem" : [],
+ "WriteCSreg" : [],
+ "ReadCSreg" : [],
+ "WriteMem8" : [],
+ "WriteMem16" : [],
+ "ReadMem8" : [],
+ "ReadMem16" : [],
+ "ReadSIB" : [],
+ "HoldInReset" : [],
+ "ReleaseFromReset" : [],
+ "EnterDebugMode" : [],
+ "EnterDebugModeHvSp" : [],
+ "EnterDebugModeHvSpRst" : [],
+ "EnterDebugModeHvUpt" : [],
+ "ExitDebugMode" : [],
+ "SetPC" : [],
+ "GetPC" : [],
+ "Run" : [],
+ "Halt" : [],
+ "DebugReset" : [],
+ "GetHaltStatus" : [],
+ "SingleStep" : [],
+ "SetHWBP" : [],
+ "ClearHWBP" : [],
+}\n
+'''
+
+
+import platform
+
+work_dir = os.path.abspath(os.getcwd())
+cache_dir = os.path.join(work_dir, "scripts_cache")
+
+print(work_dir)
+print(cache_dir)
+
+
+# Tries to locate the xml file in a known location
+def find_xml():
+ home_dir = str(Path.home())
+ print("Home Path: {0}".format(home_dir))
+ if home_dir == None:
+ return
+ home_dir = os.path.join(home_dir, ".mchp_packs", "Microchip")
+ home_dir_A = os.path.join(home_dir, "PICkit5_TP")
+ result = []
+ for root, dirs, files in os.walk(home_dir_A):
+ for name in files:
+ if fnmatch.fnmatch(name, "scripts.xml"):
+ result.append(os.path.join(root, name))
+
+ # home_dir_A = os.path.join(home_dir, "PICkit4_TP") # maybe in the future, if needed
+ print("List of scripts.xml files:")
+ print(result)
+ return result[-1]
+ # EOF
+
+# extracts only the functions from the scripts.xml that end with "UPDI"
+def cache_xml(file):
+ if file == None:
+ return
+ print("Opening file {0}".format(file))
+ global cache_dir
+ origin_tree = ET.parse(file)
+ origin_root = origin_tree.getroot()
+ work_root = ET.Element("scripts")
+ old_chip_name = ""
+ print("List of UPDI MCUs:")
+ for script in origin_root.findall('script'):
+ function_name = script[0].text # the function name is always on the first place
+ if (function_name.endswith("UPDI")):
+ chip_name = script[1].text
+ if (old_chip_name != chip_name):
+ print(chip_name)
+ old_chip_name = chip_name
+ work_root.append(script) # copy UPDI entries to our working element
+
+
+ work_tree = ET.ElementTree(work_root)
+ work_tree.write(os.path.join(cache_dir, "scripts_updi.xml"))
+ # EOF
+
+
+# generates a python file out of the reduced scripts.xml file
+def decode_xml_cache(xml_path):
+ global cache_dir
+ dict_path = os.path.join(cache_dir, "scripts_dict.py")
+
+ xml_tree = ET.parse(xml_path)
+ xml_root = xml_tree.getroot()
+
+ if (os.path.exists(dict_path)):
+ os.remove(dict_path)
+
+ with open(dict_path, 'w') as dict_file:
+ dict_list = []
+ dict_iterator = -1
+ old_chip_name = ""
+ old_function_name = ""
+ for script in xml_root:
+ function_string = ""
+ function_name = script[0].text
+ chip_name = script[1].text
+ if (old_chip_name != chip_name):
+ if (dict_iterator >= 0):
+ dict_list[dict_iterator] += " },\n" # trailing bracket
+ print("{0} generated".format(old_chip_name))
+
+ dict_iterator += 1
+ dict_list.append("")
+ dict_list[dict_iterator] = " \"{0}\" : ".format(chip_name) # thisdict : {
+ dict_list[dict_iterator] += "{\n"
+ old_chip_name = chip_name
+
+ if (old_function_name != function_name):
+ dict_list[dict_iterator] += " \"{0}\" : ".format(function_name[0:-5]) # "function_name" :
+ old_function_name = function_name
+
+ scrbytes = script[3]
+ for bytes in scrbytes:
+ function_string += bytes.text
+ function_string += ", "
+
+ dict_list[dict_iterator] += "[{0}],\n".format(function_string[0:-2]) # "function string",
+
+ dict_file.write(dict_header)
+ dict_file.write("scripts = {\n")
+ for x in range (dict_iterator):
+ dict_file.write(dict_list[x]) # store decoded dictionary
+ dict_file.write("}")
+
+
+
+
+# tries to reduce file size, reuires the previous function to be executed
+# in order to provide the python file
+def optimize_dict():
+ import scripts_cache.scripts_dict as dict
+ global cache_dir
+ for chip_name in dict.scripts: # Go through every chip
+ for func_name in dict.scripts[chip_name]: # Go through every function for each chip
+ if func_name in dict.func_dict: # Only handle the function if we care
+ func_array = dict.func_dict[func_name] # Use the array
+ position = -1
+ for x in range (len(func_array)): # go through
+ if func_array[x] == dict.scripts[chip_name][func_name]:
+ position = x
+ break
+ if position >= 0:
+ dict.scripts[chip_name][func_name] = position
+ else:
+ func_array.append(dict.scripts[chip_name][func_name])
+ dict.scripts[chip_name][func_name] = position + 1
+
+ lut_path = os.path.join(cache_dir, "scripts_lut.py")
+ if (os.path.exists(lut_path)):
+ os.remove(lut_path)
+
+ with open(lut_path, 'w') as lut_file: # Create file
+ lut_file.write("func_dict = {\n") # start with function look-up Table
+ for func in dict.func_dict:
+ lut_file.write(" \"{0}\" : [\n".format(func)) # function start
+ func_array = dict.func_dict[func]
+
+ for array_elem in func_array: # function list start
+ func_string = " ["
+ for i in array_elem: # iterate through the sub-function elements
+ func_string += "0x{0:02X}, ".format(i) # format for readability
+ func_string += "],\n" # end of sub-function
+ lut_file.write(func_string) # write to file
+ lut_file.write(" ],\n") # end of function
+ lut_file.write("}\n\n\n") # end of lut
+
+ lut_file.write("scripts = {\n")
+ for chip_name in dict.scripts: # Go through every chip
+ lut_file.write(" \""+ chip_name + "\" : {\n")
+ for func_name in dict.scripts[chip_name]: # Go through every function for each chip
+ lut_file.write(" \"{0}\" : {1},\n".format(func_name, dict.scripts[chip_name][func_name]))
+ lut_file.write(" },\n")
+ lut_file.write("}") # close dict
+ print("done")
+ #EOF
+
+
+
+# generates the h-file. generates the struct definition
+def generate_h_file(c_dict, file_dir):
+ h_header = \
+'''
+/* This file was auto-generated by scripts_decoder.py, changes may be overwritten */
+#ifndef scripts_lut_h
+#define scripts_lut_h
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+struct avr_script_lut {
+'''
+
+ h_trailer = \
+'''
+};
+
+struct avr_script_lut* get_pickit_script(const char *partdesc);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // scripts_lut_h
+'''
+
+ if file_dir is None:
+ return
+
+ h_lut_path = os.path.join(file_dir, "scripts_lut.h") # first - handle defining the structure
+ if (os.path.exists(h_lut_path)):
+ os.remove(h_lut_path)
+ with open(h_lut_path, 'w') as h_file:
+ h_file.write(h_header)
+ for func_name in c_dict:
+ h_file.write(" const unsigned char *{0};\n unsigned int {0}_len;\n".format(func_name))
+ h_file.write(h_trailer)
+ print("h-File generated")
+ #EOF
+
+
+
+# generates the c-file out of a previously generated python file
+def generate_c_file(c_dict, file_dir):
+ import scripts_cache.scripts_lut as lut
+
+ if file_dir is None:
+ return
+
+ c_lut_path = os.path.join(file_dir, "scripts_lut.c")
+ if (os.path.exists(c_lut_path)):
+ os.remove(c_lut_path)
+ with open(c_lut_path, 'w') as c_file:
+ non_unique_func = []
+ c_file.write("/* this file was auto-generated */\n")
+ c_file.write("#include \n")
+ c_file.write("#include \n")
+ c_file.write("#include \n")
+ c_file.write("#include \"scripts_lut.h\"\n\n\n")
+ struct_init_func = ""
+ struct_init_len = ""
+ for func_name in lut.func_dict: # for each function in our database
+ if func_name in c_dict: # if the function exists in our c-list
+ function = lut.func_dict[func_name] # load data associated with the function
+ array_iterator = 0
+ for array in function: # for each array in function
+ array_str = "const unsigned char {0}_{1}[{2}]".format(func_name, array_iterator, len(array))
+ array_str += " = {\n " # begin array
+ for i in range (len(array)): # go through every byte
+ array_str += "0x{0:02x}, ".format(array[i]) # and generate String
+ array_str += "\n};\n" # complete array
+ array_iterator += 1
+ c_file.write(array_str)
+
+ if array_iterator == 1:
+ struct_init_func += " .{0} = {0}_0,\n".format(func_name)
+ struct_init_len += " .{0}_len = sizeof({0}_0),\n".format(func_name)
+ else:
+ struct_init_func += " .{0} = NULL,\n".format(func_name)
+ struct_init_len += " .{0}_len = 0,\n".format(func_name)
+ non_unique_func.append(func_name)
+
+
+ c_file.write("\n\n\nstruct avr_script_lut avr_scripts = {\n")
+ c_file.write(struct_init_func)
+ c_file.write(struct_init_len)
+ c_file.write("};\n\n\n")
+
+ chip_lut_str = "char *chip_lut[] = {\n "
+ chip_name_iterator = 0
+ for chip_name in lut.scripts:
+ chip_lut_str += "\""
+ chip_lut_str += chip_name
+ chip_lut_str += "\", "
+ chip_name_iterator += 1
+ if chip_name_iterator % 8 == 0:
+ chip_lut_str += "\n "
+ chip_lut_str += "\n};\n\n\n"
+ c_file.write(chip_lut_str)
+
+ c_func_str = "struct avr_script_lut* get_pickit_script(const char* partdesc) { \n"
+ c_func_str += " int namepos = -1;\n"
+ c_func_str += " for (int i = 0; i < {0}; i++)".format(chip_name_iterator)
+ c_func_str += " {\n"
+ c_func_str += " if (strncmp(chip_lut[i], partdesc, 10) == 0) {\n"
+ c_func_str += " namepos = i;\n break;\n }\n }\n"
+ c_func_str += " if (namepos == -1) {\n return NULL;\n }\n"
+ c_file.write(c_func_str)
+
+ switch_iterator = 0
+ c_file.write(" switch (namepos) {\n")
+ for chip_name in lut.scripts:
+ case_str = " case {0}:\n".format(switch_iterator)
+ chip_func = lut.scripts[chip_name]
+ for func_lut in chip_func:
+ if func_lut in non_unique_func:
+ case_str += " avr_scripts.{0} = {0}_{1};\n".format(func_lut, chip_func[func_lut])
+ case_str += " avr_scripts.{0}_len = sizeof({0}_{1});\n".format(func_lut, chip_func[func_lut])
+ case_str += " break;\n"
+ switch_iterator += 1
+ c_file.write(case_str)
+ c_file.write(" }\n return &avr_scripts;\n }")
+ print("c-File generated")
+ #EOF
+
+
+def convert_to_c(c_dict, file_dir):
+
+ generate_h_file(c_dict, file_dir)
+ generate_c_file(c_dict, file_dir)
+ #EOF
+
+
+
+# A sum of the previous functions, generating the c/h files
+# without needing any intermediate files
+def convert_xml(xml_path, c_dict):
+ if xml_path == None:
+ print("No Path to XML file provided")
+ return
+
+ mcu_dict = dict()
+
+ # Prepare directories
+ # own_dir = os.path.abspath(os.getcwd())
+ parent_dir = os.getcwd()
+ src_dir = os.path.join(parent_dir, "src")
+ print("Opening file {0}".format(xml_path))
+ print("Parent Dir: {0}".format(parent_dir))
+ print("Src directory: {0}".format(src_dir))
+
+ # open XML file
+ origin_tree = ET.parse(xml_path)
+ origin_root = origin_tree.getroot()
+ work_root = ET.Element("scripts")
+ print ("XML File loaded")
+
+ # scan scripts file
+ for script in origin_root.findall('script'):
+ function_name = script[0].text # the function name is always on the first place
+ if (function_name.endswith("UPDI")): # We're only intrested in UPDI functions
+ function_name = function_name[0:-5] # remove "_UPDI" from function name
+ if (function_name in c_dict): # filter out unneded functions
+ chip_name = script[1].text # get chip name
+ if (chip_name not in mcu_dict):
+ mcu_dict[chip_name] = dict()
+ if (function_name not in mcu_dict[chip_name]):
+ mcu_dict[chip_name][function_name] = []
+ scrbytes = script[3]
+ for bytes in scrbytes:
+ mcu_dict[chip_name][function_name].append(int(bytes.text, 16))
+ # the mcu dict has following layout "mcu_name" : "function1" : [], "function2" : []
+ print("XML File proceesed")
+
+ # reorder mcu_dict to a func_dict
+ func_dict = dict()
+ for mcu_name in mcu_dict: # Go through every MCU
+ for function_name in mcu_dict[mcu_name]: # Go through every Function for every CPU
+ if (function_name not in func_dict):
+ func_dict[function_name] = []
+
+ funct_bytes = mcu_dict[mcu_name][function_name] # get Function bytes
+ entries = len(func_dict[function_name])
+ for x in range (entries + 1): # try to find an existing entry
+ if x == entries: # if we reached the end
+ func_dict[function_name].append(funct_bytes) # add an entry to our dict
+ mcu_dict[mcu_name][function_name] = x # remember the postion in dict
+ break
+ if func_dict[function_name][x] == funct_bytes: # if match found
+ mcu_dict[mcu_name][function_name] = x # remember the postion
+ break
+ # the funct dict has following layout: "function1" : [[], []], "function2" : [[], []],
+ # the mcu dict has following layout "mcu_name" : "function1" : 1, "function2" : 0
+
+ # create h-File
+ generate_h_file(c_dict, src_dir)
+
+ # create c-File
+ c_lut_path = os.path.join(src_dir, "scripts_lut.c")
+ if (os.path.exists(c_lut_path)):
+ os.remove(c_lut_path)
+ with open(c_lut_path, 'w') as c_file:
+ non_unique_func = []
+ c_file.write("/* this file was auto-generated by scripts_deocder.py*/\n")
+ c_file.write("#include \n")
+ c_file.write("#include \n")
+ c_file.write("#include \n")
+ c_file.write("#include \"scripts_lut.h\"\n\n\n")
+ struct_init_func = ""
+ struct_init_len = ""
+ for func_name in func_dict: # for each function in our database
+ function = func_dict[func_name] # load data associated with the function
+ array_iterator = 0
+ for array in function: # for each array in function
+ array_str = "const unsigned char {0}_{1}[{2}]".format(func_name, array_iterator, len(array))
+ array_str += " = {\n " # begin array
+ for i in range (len(array)): # go through every byte
+ array_str += "0x{0:02x}, ".format(array[i]) # and generate String
+ array_str += "\n};\n" # complete array
+ array_iterator += 1
+ c_file.write(array_str)
+
+ if array_iterator == 1:
+ struct_init_func += " .{0} = {0}_0,\n".format(func_name)
+ struct_init_len += " .{0}_len = sizeof({0}_0),\n".format(func_name)
+ else:
+ struct_init_func += " .{0} = NULL,\n".format(func_name)
+ struct_init_len += " .{0}_len = 0,\n".format(func_name)
+ non_unique_func.append(func_name)
+
+
+ c_file.write("\n\n\nstruct avr_script_lut avr_scripts = {\n")
+ c_file.write(struct_init_func)
+ c_file.write(struct_init_len)
+ c_file.write("};\n\n\n")
+
+ chip_lut_str = "char *chip_lut[] = {\n "
+ chip_name_iterator = 0
+ for chip_name in mcu_dict:
+ chip_lut_str += "\""
+ chip_lut_str += chip_name
+ chip_lut_str += "\", "
+ chip_name_iterator += 1
+ if chip_name_iterator % 8 == 0:
+ chip_lut_str += "\n "
+ chip_lut_str += "\n};\n\n\n"
+ c_file.write(chip_lut_str)
+
+ c_func_str = "struct avr_script_lut* get_pickit_script(const char* partdesc) { \n"
+ c_func_str += " int namepos = -1;\n"
+ c_func_str += " for (int i = 0; i < {0}; i++)".format(chip_name_iterator)
+ c_func_str += " {\n"
+ c_func_str += " if (strncmp(chip_lut[i], partdesc, 10) == 0) {\n"
+ c_func_str += " namepos = i;\n break;\n }\n }\n"
+ c_func_str += " if (namepos == -1) {\n return NULL;\n }\n"
+ c_file.write(c_func_str)
+
+
+ switch_iterator = 0
+ c_file.write(" switch (namepos) {\n")
+ case_str_list = []
+ break_str_list = []
+ for chip_name in mcu_dict:
+ case_str_list.append("")
+ break_str_list.append("")
+ case_str_list[switch_iterator] = " case {0}: /* {1} */\n".format(switch_iterator, chip_name)
+ chip_func = mcu_dict[chip_name]
+ for func_lut in chip_func:
+ if func_lut in non_unique_func:
+ break_str_list[switch_iterator] += " avr_scripts.{0} = {0}_{1};\n".format(func_lut, chip_func[func_lut])
+ break_str_list[switch_iterator] += " avr_scripts.{0}_len = sizeof({0}_{1});\n".format(func_lut, chip_func[func_lut])
+ break_str_list[switch_iterator] += " break;\n"
+ switch_iterator += 1
+
+
+ for x in range (0, switch_iterator):
+ if (case_str_list[x] != ""): # ignore already "filtered" out cases
+ file_str = case_str_list[x] # start with a case
+ temp_str = break_str_list[x] # buffer the content of the case
+ for y in range(x + 1, switch_iterator): # go through all future entries
+ if temp_str == break_str_list[y]: # if we find one that is identical
+ file_str += case_str_list[y] # add it to the case at the beginning
+ case_str_list[y] = "" # clear case entry
+ break_str_list[y] = "" # clear content entry to speed up filtering
+ file_str += temp_str # add the content of the case
+ c_file.write(file_str)
+
+
+ c_file.write(" }\n return &avr_scripts;\n }")
+ print("c-File generated")
+ pass
+
+
+
+if not user_input:
+ xml_path = find_xml()
+ if xml_path == None:
+ print("Unable to find scripts.xml in the default location.")
+ print("Please Enter a Path to the File or Directory:")
+ xml_path = input(">")
+ if (os.path.isdir(xml_path)):
+ os.path.join(xml_path, "scripts.xml")
+ if (os.path.exists(xml_path) == False):
+ print("File not found, exiting")
+ quit()
+ convert_xml(xml_path, c_dict)
+ quit()
+
+
+while user_input:
+ user_in = input(">")
+
+ if (user_in == "cache"):
+ xml_path = find_xml()
+ cache_xml(xml_path)
+ elif (user_in == "decode"):
+ xml_path = os.path.join(cache_dir, "scripts_updi.xml")
+ decode_xml_cache(xml_path)
+ elif (user_in == "optimize"):
+ optimize_dict()
+ elif (user_in == "cfy"):
+ convert_to_c(c_dict, cache_dir)
+ elif (user_in == "dude"):
+ xml_path = find_xml()
+ if xml_path == None:
+ print("Unable to find scripts.xml in the default location.")
+ print("Please Enter a Path to the File or Directory:")
+ xml_path = input(">")
+ if (os.path.isdir(xml_path)):
+ os.path.join(xml_path, "scripts.xml")
+ if (os.path.exists(xml_path) == False):
+ print("File not found, exiting")
+ quit()
+ convert_xml(xml_path, c_dict)
+ quit()
+ pass
+
+
+
+
+
+
+
+
+
+