add support for dW, JTAG, ISP, and PDI (untested)

dW has some hiccups on flash writes
JTAG must erase chip before overwriting EEPROM
This commit is contained in:
MX682X
2024-10-14 21:28:58 +02:00
parent 0b92721af9
commit 7b077029bc
13 changed files with 12476 additions and 1135 deletions

View File

@@ -229,7 +229,12 @@ set(SOURCES
pgm_type.c
pickit2.c
pickit2.h
pickit5_updi_lut.c
pickit5_lut_dw.c
pickit5_lut_isp.c
pickit5_lut_jtag.c
pickit5_lut_pdi.c
pickit5_lut_tpi.c
pickit5_lut_updi.c
pickit5_lut.h
pickit5.c
pickit5.h

View File

@@ -156,7 +156,12 @@ libavrdude_la_SOURCES = \
pgm_type.c \
pickit2.c \
pickit2.h \
pickit5_updi_lut.c \
pickit5_lut_dw.c \
pickit5_lut_isp.c \
pickit5_lut_jtag.c \
pickit5_lut_pdi.c \
pickit5_lut_tpi.c \
pickit5_lut_updi.c \
pickit5_lut.h \
pickit5.c \
pickit5.h \

View File

@@ -3058,30 +3058,60 @@ programmer # pickit4_tpi
# Microchip PICkit 5. For details, see
# https://www.microchip.com/en-us/development-tool/PG164150
#
# Currently -c pickit5 only supports UPDI programming
# The PICkit 5 supports the following programming modes
# using different programmer names:
#
# PIN UPDI
# > 1 !RST(*)
# 2 VCC
# 3 GND
# 4 UPDI(*)
# 5
# 6
# 7
# 8
# Interface: Programmer name:
# JTAG pickit5, pickit4_jtag
# PDI pickit5_pdi
# UPDI pickit5_updi
# debugWIRE pickit5_dw (can auto-switch to ISP to write fuses)
# ISP pickit5_isp
# TPI pickit5_tpi
#
# PIN JTAG PDI UPDI ISP/dW TPI UART(°)
# > 1 RST(*)
# 2 VCC VCC VCC VCC VCC VCC
# 3 GND GND GND GND GND GND
# 4 TDO DATA UPDI(*) SDI DATA
# 5 TCK SCK SCK
# 6 RST SCK RST/dW RST
# 7 TDI SDO TX (target)
# 8 TMS RX (target)
#
# Note: pickit5_dw does not support flash erase and must switch
# to ISP, thus requires all 6 Pins when modifing the flash
#
# (*): The PICkit5 can generate a High-Voltage (12V) Pulse on this pins
# to restore the UPDI Pin functionality, if it was changed through fuses.
# AVRDUDE automatically selects the correct pin, if the HV pulse is
# enabled through the '-x hvupdi' flag.
# to restore the UPDI Pin functionality, if it was changed through fuses.
# AVRDUDE automatically selects the correct pin, if the HV pulse is
# enabled through the '-x hvupdi' flag.
# (°): The PICkit5 can also be used as a USB to UART
# interface for simple serial debugging.
#------------------------------------------------------------
# pickit5 /pickit5_updi
# pickit5 /pickit5_jtag
#------------------------------------------------------------
programmer # pickit5_jtag
id = "pickit5_jtag";
desc = "MPLAB(R) PICkit 5, PICkit 4 and SNAP (PIC) in JTAG Mode";
type = "pickit5_jtag";
prog_modes = PM_JTAG | PM_XMEGAJTAG;
extra_features = HAS_VTARG_READ;
connection_type = usb;
baudrate = 200000; # JTAG default clock
usbvid = 0x04d8;
usbpid = 0x9036, 0x9012, 0x9018; # PK5, PK4 (pic mode), snap (pic mode)
;
#------------------------------------------------------------
# pickit5_updi
#------------------------------------------------------------
programmer # pickit5_updi
id = "pickit5_updi";
desc = "MPLAB(R) PICkit 5, PICkit 4 and SNAP (PIC)";
desc = "MPLAB(R) PICkit 5, PICkit 4 and SNAP (PIC) in UPDI Mode";
type = "pickit5_updi";
prog_modes = PM_UPDI;
extra_features = HAS_VTARG_READ;
@@ -3092,6 +3122,66 @@ programmer # pickit5_updi
hvupdi_support = 0, 1, 2;
;
#------------------------------------------------------------
# pickit5_isp
#------------------------------------------------------------
programmer # pickit5_isp
id = "pickit5_isp";
desc = "MPLAB(R) PICkit 5, PICkit 4 and SNAP (PIC) in ISP Mode";
type = "pickit5_isp";
prog_modes = PM_ISP;
extra_features = HAS_VTARG_READ;
connection_type = usb;
baudrate = 125000; # ISP default clock
usbvid = 0x04d8;
usbpid = 0x9036, 0x9012, 0x9018; # PK5, PK4 (pic mode), snap (pic mode)
;
#------------------------------------------------------------
# pickit5_dw
#------------------------------------------------------------
programmer # pickit5_dw
id = "pickit5_dw";
desc = "MPLAB(R) PICkit 5, PICkit 4 and SNAP (PIC) in dW Mode";
type = "pickit5_dw";
prog_modes = PM_debugWIRE;
extra_features = HAS_VTARG_READ;
connection_type = usb;
baudrate = 200000; # dW default clock
usbvid = 0x04d8;
usbpid = 0x9036, 0x9012, 0x9018; # PK5, PK4 (pic mode), snap (pic mode)
;
#------------------------------------------------------------
# pickit5_tpi
#------------------------------------------------------------
programmer # pickit5_tpi
id = "pickit5_tpi";
desc = "MPLAB(R) PICkit 5, PICkit 4 and SNAP (PIC) in TPI Mode";
type = "pickit5_tpi";
prog_modes = PM_TPI;
extra_features = HAS_VTARG_READ;
connection_type = usb;
baudrate = 125000; # TPI default clock
usbvid = 0x04d8;
usbpid = 0x9036, 0x9012, 0x9018; # PK5, PK4 (pic mode), snap (pic mode)
;
#------------------------------------------------------------
# pickit5_pdi
#------------------------------------------------------------
programmer # pickit5_tpi
id = "pickit5_pdi";
desc = "MPLAB(R) PICkit 5, PICkit 4 and SNAP (PIC) in PDI Mode";
type = "pickit5_pdi";
prog_modes = PM_PDI;
extra_features = HAS_VTARG_READ;
connection_type = usb;
baudrate = 125000; # PDI default clock
usbvid = 0x04d8;
usbpid = 0x9036, 0x9012, 0x9018; # PK5, PK4 (pic mode), snap (pic mode)
;
#------------------------------------------------------------
# snap /snap_jtag
#------------------------------------------------------------

View File

@@ -97,6 +97,11 @@ const PROGRAMMER_TYPE programmers_types[] = { // Name(s) the programmers call
{"micronucleus", micronucleus_initpgm, micronucleus_desc}, // "micronucleus" or "Micronucleus V2.0"
{"par", par_initpgm, par_desc}, // "PPI"
{"pickit2", pickit2_initpgm, pickit2_desc}, // "pickit2"
{"pickit5_dw", pickit5_initpgm, pickit5_desc}, // "pickit5"
{"pickit5_isp", pickit5_initpgm, pickit5_desc}, // "pickit5"
{"pickit5_jtag", pickit5_initpgm, pickit5_desc}, // "pickit5"
{"pickit5_pdi", pickit5_initpgm, pickit5_desc}, // "pickit5"
{"pickit5_tpi", pickit5_initpgm, pickit5_desc}, // "pickit5"
{"pickit5_updi", pickit5_initpgm, pickit5_desc}, // "pickit5"
{"serbb", serbb_initpgm, serbb_desc}, // "SERBB"
{"serialupdi", serialupdi_initpgm, serialupdi_desc}, // "serialupdi"

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,6 @@
/* This file was auto-generated by scripts_decoder.py, any changes will be overwritten */
/* This file was auto-generated by scripts_decoder.py.
* Any changes will be overwritten on regeneration
*/
/*
* avrdude - A Downloader/Uploader for AVR device programmers
@@ -61,20 +63,45 @@ struct avr_script_lut {
unsigned int ReadMem8_len;
const unsigned char *WriteConfigmem;
unsigned int WriteConfigmem_len;
const unsigned char *WriteConfigmemFuse;
unsigned int WriteConfigmemFuse_len;
const unsigned char *WriteConfigmemLock;
unsigned int WriteConfigmemLock_len;
const unsigned char *ReadConfigmem;
unsigned int ReadConfigmem_len;
const unsigned char *ReadConfigmemFuse;
unsigned int ReadConfigmemFuse_len;
const unsigned char *ReadConfigmemLock;
unsigned int ReadConfigmemLock_len;
const unsigned char *WriteIDmem;
unsigned int WriteIDmem_len;
const unsigned char *ReadIDmem;
unsigned int ReadIDmem_len;
const unsigned char *ReadSIB;
unsigned int ReadSIB_len;
const unsigned char *switchtoISP;
unsigned int switchtoISP_len;
const unsigned char *ReadMemIO;
unsigned int ReadMemIO_len;
const unsigned char *WriteMemIO;
unsigned int WriteMemIO_len;
const unsigned char *ReadCalibrationByte;
unsigned int ReadCalibrationByte_len;
const unsigned char *WriteSRAM;
unsigned int WriteSRAM_len;
const unsigned char *ReadSRAM;
unsigned int ReadSRAM_len;
};
typedef struct avr_script_lut SCRIPT;
const unsigned char * get_devid_script_by_nvm_ver(unsigned char version);
int get_pickit_dw_script(SCRIPT *scr, const char *partdesc);
int get_pickit_isp_script(SCRIPT *scr, const char *partdesc);
int get_pickit_jtag_script(SCRIPT *scr, const char *partdesc);
int get_pickit_updi_script(SCRIPT *scr, const char *partdesc);
int get_pickit_pdi_script(SCRIPT *scr, const char *partdesc);
int get_pickit_tpi_script(SCRIPT *scr, const char *partdesc);
#ifdef __cplusplus
}

4595
src/pickit5_lut_dw.c Normal file

File diff suppressed because it is too large Load Diff

3550
src/pickit5_lut_isp.c Normal file

File diff suppressed because it is too large Load Diff

1994
src/pickit5_lut_jtag.c Normal file

File diff suppressed because it is too large Load Diff

514
src/pickit5_lut_pdi.c Normal file
View File

@@ -0,0 +1,514 @@
/* This file was auto-generated by scripts_decoder.py.
* Any changes will be overwritten on regeneration
*/
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <ac_cfg.h>
#include <stddef.h>
#include <string.h>
#include "pickit5_lut.h"
const unsigned char EnterProgMode_pdi_0[121] = {
0x9b, 0x00, 0x06, 0x9b, 0x01, 0x00, 0x1e, 0x01, 0x00, 0x01, 0x9b, 0x01, 0x00, 0x9b, 0x02, 0xfd,
0x1e, 0x0f, 0x01, 0x02, 0x9b, 0x01, 0x00, 0xa2, 0x1e, 0x0e, 0x01, 0xa5, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x9b, 0x01, 0x01, 0x9b, 0x02, 0x59, 0x1e, 0x0f, 0x01, 0x02,
0x9b, 0x01, 0x00, 0x65, 0xff, 0x88, 0xd8, 0xcd, 0x04, 0x65, 0x45, 0xab, 0x89, 0x12, 0x04, 0x1e,
0x11, 0x01, 0x9b, 0x01, 0x00, 0x1e, 0x0e, 0x01, 0x6c, 0x02, 0x66, 0x02, 0xf9, 0x00, 0x00, 0x00,
0x90, 0x03, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x02, 0x03, 0x70, 0x00, 0x9b, 0x01, 0x00, 0xa2, 0x1e,
0x0e, 0x01, 0xa5, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xe8, 0x03, 0xfb, 0x78, 0x00,
0x90, 0x01, 0x00, 0x01, 0x00, 0x00, 0x7f, 0x01, 0x5a,
};
const unsigned char ExitProgMode_pdi_0[40] = {
0x9b, 0x01, 0x01, 0x9b, 0x02, 0x00, 0x1e, 0x0f, 0x01, 0x02, 0x9b, 0x01, 0x00, 0x9b, 0x02, 0x00,
0x1e, 0x0f, 0x01, 0x02, 0x9b, 0x01, 0x00, 0xa2, 0x1e, 0x0e, 0x01, 0xa5, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x1e, 0x02,
};
const unsigned char SetSpeed_pdi_0[5] = {
0x91, 0x00, 0x1e, 0x14, 0x00,
};
const unsigned char GetDeviceID_pdi_0[104] = {
0x95, 0x90, 0x01, 0xc0, 0x01, 0x00, 0x00, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x00, 0x25, 0x00, 0x90,
0x03, 0xca, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x03, 0x6c, 0x0a, 0x90, 0x03, 0xc4, 0x01, 0x00, 0x01,
0x1e, 0x03, 0x03, 0x6c, 0x0b, 0x90, 0x00, 0x90, 0x00, 0x00, 0x01, 0x1e, 0x09, 0x00, 0x9c, 0x01,
0x03, 0x00, 0x1e, 0x10, 0x01, 0x9b, 0x02, 0x03, 0x1e, 0x0c, 0x02, 0x90, 0x02, 0x93, 0x00, 0x00,
0x01, 0x1e, 0x03, 0x02, 0x9f, 0x90, 0x01, 0xc0, 0x01, 0x00, 0x00, 0xfe, 0x01, 0x00, 0x00, 0x00,
0x00, 0x67, 0x00, 0x90, 0x03, 0xca, 0x01, 0x00, 0x01, 0x1e, 0x06, 0x03, 0x0a, 0x90, 0x03, 0xc4,
0x01, 0x00, 0x01, 0x1e, 0x06, 0x03, 0x0b, 0x5a,
};
const unsigned char EraseChip_pdi_0[99] = {
0x90, 0x01, 0xca, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x01, 0x6c, 0x05, 0x90, 0x01, 0xca, 0x01, 0x00,
0x01, 0x90, 0x02, 0x40, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x01, 0x02, 0x90, 0x01, 0xcb, 0x01, 0x00,
0x01, 0x90, 0x02, 0x01, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x01, 0x02, 0x90, 0x01, 0x00, 0x00, 0x00,
0x00, 0xa2, 0x1e, 0x0e, 0x01, 0xa5, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xd0, 0x07,
0x94, 0x0a, 0x00, 0x90, 0x01, 0xcf, 0x01, 0x00, 0x01, 0xa2, 0x1e, 0x03, 0x01, 0xa5, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x90, 0x01, 0xca, 0x01, 0x00, 0x01, 0x1e, 0x06,
0x01, 0x05, 0x5a,
};
const unsigned char WriteProgmem_pdi_0[172] = {
0x91, 0x00, 0x91, 0x01, 0x60, 0x03, 0x01, 0x93, 0x03, 0x00, 0x02, 0xad, 0x03, 0x90, 0x04, 0xc0,
0x01, 0x00, 0x00, 0xfe, 0x04, 0x00, 0x00, 0x00, 0x00, 0x41, 0x00, 0x90, 0x06, 0xca, 0x01, 0x00,
0x01, 0x1e, 0x03, 0x06, 0x6c, 0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c,
0x0b, 0x90, 0x04, 0xca, 0x01, 0x00, 0x01, 0x90, 0x05, 0x23, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x04,
0x05, 0x1e, 0x09, 0x00, 0x9c, 0x04, 0x00, 0x02, 0x1e, 0x10, 0x04, 0x1e, 0x0a, 0x04, 0x90, 0x04,
0xc0, 0x01, 0x00, 0x00, 0xfe, 0x04, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x00, 0x90, 0x04, 0xca, 0x01,
0x00, 0x01, 0x90, 0x05, 0x25, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x04, 0x05, 0x1e, 0x09, 0x00, 0x65,
0xff, 0x00, 0x00, 0x00, 0x01, 0x9b, 0x06, 0x01, 0x1e, 0x0a, 0x06, 0x90, 0x06, 0xcf, 0x01, 0x00,
0x01, 0xa2, 0x1e, 0x03, 0x06, 0xa5, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00,
0x90, 0x06, 0xca, 0x01, 0x00, 0x01, 0x1e, 0x06, 0x06, 0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01,
0x1e, 0x06, 0x06, 0x0b, 0x92, 0x00, 0x00, 0x02, 0x00, 0x00, 0xae, 0x5a,
};
const unsigned char WriteProgmem_pdi_1[172] = {
0x91, 0x00, 0x91, 0x01, 0x60, 0x03, 0x01, 0x93, 0x03, 0x00, 0x01, 0xad, 0x03, 0x90, 0x04, 0xc0,
0x01, 0x00, 0x00, 0xfe, 0x04, 0x00, 0x00, 0x00, 0x00, 0x41, 0x00, 0x90, 0x06, 0xca, 0x01, 0x00,
0x01, 0x1e, 0x03, 0x06, 0x6c, 0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c,
0x0b, 0x90, 0x04, 0xca, 0x01, 0x00, 0x01, 0x90, 0x05, 0x23, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x04,
0x05, 0x1e, 0x09, 0x00, 0x9c, 0x04, 0x00, 0x01, 0x1e, 0x10, 0x04, 0x1e, 0x0a, 0x04, 0x90, 0x04,
0xc0, 0x01, 0x00, 0x00, 0xfe, 0x04, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x00, 0x90, 0x04, 0xca, 0x01,
0x00, 0x01, 0x90, 0x05, 0x25, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x04, 0x05, 0x1e, 0x09, 0x00, 0x65,
0xff, 0x00, 0x00, 0x00, 0x01, 0x9b, 0x06, 0x01, 0x1e, 0x0a, 0x06, 0x90, 0x06, 0xcf, 0x01, 0x00,
0x01, 0xa2, 0x1e, 0x03, 0x06, 0xa5, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00,
0x90, 0x06, 0xca, 0x01, 0x00, 0x01, 0x1e, 0x06, 0x06, 0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01,
0x1e, 0x06, 0x06, 0x0b, 0x92, 0x00, 0x00, 0x01, 0x00, 0x00, 0xae, 0x5a,
};
const unsigned char WriteProgmem_pdi_2[172] = {
0x91, 0x00, 0x91, 0x01, 0x60, 0x03, 0x01, 0x93, 0x03, 0x80, 0x00, 0xad, 0x03, 0x90, 0x04, 0xc0,
0x01, 0x00, 0x00, 0xfe, 0x04, 0x00, 0x00, 0x00, 0x00, 0x41, 0x00, 0x90, 0x06, 0xca, 0x01, 0x00,
0x01, 0x1e, 0x03, 0x06, 0x6c, 0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c,
0x0b, 0x90, 0x04, 0xca, 0x01, 0x00, 0x01, 0x90, 0x05, 0x23, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x04,
0x05, 0x1e, 0x09, 0x00, 0x9c, 0x04, 0x80, 0x00, 0x1e, 0x10, 0x04, 0x1e, 0x0a, 0x04, 0x90, 0x04,
0xc0, 0x01, 0x00, 0x00, 0xfe, 0x04, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x00, 0x90, 0x04, 0xca, 0x01,
0x00, 0x01, 0x90, 0x05, 0x25, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x04, 0x05, 0x1e, 0x09, 0x00, 0x65,
0xff, 0x00, 0x00, 0x00, 0x01, 0x9b, 0x06, 0x01, 0x1e, 0x0a, 0x06, 0x90, 0x06, 0xcf, 0x01, 0x00,
0x01, 0xa2, 0x1e, 0x03, 0x06, 0xa5, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00,
0x90, 0x06, 0xca, 0x01, 0x00, 0x01, 0x1e, 0x06, 0x06, 0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01,
0x1e, 0x06, 0x06, 0x0b, 0x92, 0x00, 0x80, 0x00, 0x00, 0x00, 0xae, 0x5a,
};
const unsigned char ReadProgmem_pdi_0[126] = {
0x91, 0x00, 0x91, 0x01, 0x95, 0x90, 0x04, 0xc0, 0x01, 0x00, 0x00, 0x90, 0x05, 0x00, 0x00, 0x00,
0x00, 0xfc, 0x04, 0x05, 0x26, 0x00, 0xad, 0x01, 0x1e, 0x03, 0x00, 0x9f, 0x92, 0x00, 0x01, 0x00,
0x00, 0x00, 0xae, 0xfb, 0x7d, 0x00, 0x90, 0x06, 0xca, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c,
0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c, 0x0b, 0x60, 0x03, 0x01, 0x93,
0x03, 0x00, 0x02, 0xad, 0x03, 0x90, 0x04, 0xca, 0x01, 0x00, 0x01, 0x90, 0x05, 0x43, 0x00, 0x00,
0x00, 0x1e, 0x06, 0x04, 0x05, 0x1e, 0x09, 0x00, 0x9c, 0x04, 0x00, 0x02, 0x1e, 0x10, 0x04, 0x1e,
0x0c, 0x04, 0x92, 0x00, 0x00, 0x02, 0x00, 0x00, 0xae, 0x90, 0x06, 0xca, 0x01, 0x00, 0x01, 0x1e,
0x06, 0x06, 0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x06, 0x06, 0x0b, 0x5a,
};
const unsigned char ReadProgmem_pdi_1[126] = {
0x91, 0x00, 0x91, 0x01, 0x95, 0x90, 0x04, 0xc0, 0x01, 0x00, 0x00, 0x90, 0x05, 0x00, 0x00, 0x00,
0x00, 0xfc, 0x04, 0x05, 0x26, 0x00, 0xad, 0x01, 0x1e, 0x03, 0x00, 0x9f, 0x92, 0x00, 0x01, 0x00,
0x00, 0x00, 0xae, 0xfb, 0x7d, 0x00, 0x90, 0x06, 0xca, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c,
0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c, 0x0b, 0x60, 0x03, 0x01, 0x93,
0x03, 0x00, 0x01, 0xad, 0x03, 0x90, 0x04, 0xca, 0x01, 0x00, 0x01, 0x90, 0x05, 0x43, 0x00, 0x00,
0x00, 0x1e, 0x06, 0x04, 0x05, 0x1e, 0x09, 0x00, 0x9c, 0x04, 0x00, 0x01, 0x1e, 0x10, 0x04, 0x1e,
0x0c, 0x04, 0x92, 0x00, 0x00, 0x01, 0x00, 0x00, 0xae, 0x90, 0x06, 0xca, 0x01, 0x00, 0x01, 0x1e,
0x06, 0x06, 0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x06, 0x06, 0x0b, 0x5a,
};
const unsigned char ReadProgmem_pdi_2[126] = {
0x91, 0x00, 0x91, 0x01, 0x95, 0x90, 0x04, 0xc0, 0x01, 0x00, 0x00, 0x90, 0x05, 0x00, 0x00, 0x00,
0x00, 0xfc, 0x04, 0x05, 0x26, 0x00, 0xad, 0x01, 0x1e, 0x03, 0x00, 0x9f, 0x92, 0x00, 0x01, 0x00,
0x00, 0x00, 0xae, 0xfb, 0x7d, 0x00, 0x90, 0x06, 0xca, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c,
0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c, 0x0b, 0x60, 0x03, 0x01, 0x93,
0x03, 0x80, 0x00, 0xad, 0x03, 0x90, 0x04, 0xca, 0x01, 0x00, 0x01, 0x90, 0x05, 0x43, 0x00, 0x00,
0x00, 0x1e, 0x06, 0x04, 0x05, 0x1e, 0x09, 0x00, 0x9c, 0x04, 0x80, 0x00, 0x1e, 0x10, 0x04, 0x1e,
0x0c, 0x04, 0x92, 0x00, 0x80, 0x00, 0x00, 0x00, 0xae, 0x90, 0x06, 0xca, 0x01, 0x00, 0x01, 0x1e,
0x06, 0x06, 0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x06, 0x06, 0x0b, 0x5a,
};
const unsigned char WriteDataEEmem_pdi_0[334] = {
0x91, 0x00, 0x91, 0x01, 0x60, 0x03, 0x01, 0x93, 0x03, 0x20, 0x00, 0xad, 0x03, 0x90, 0x05, 0xc0,
0x01, 0x00, 0x00, 0xfe, 0x05, 0x00, 0x00, 0x00, 0x00, 0xf3, 0x00, 0x90, 0x09, 0xcc, 0x01, 0x00,
0x01, 0x1e, 0x03, 0x09, 0x6c, 0x05, 0x6c, 0x0a, 0x66, 0x05, 0x08, 0x00, 0x00, 0x00, 0xfe, 0x05,
0x00, 0x00, 0x00, 0x00, 0xc3, 0x00, 0x60, 0x05, 0x0a, 0x66, 0x05, 0xf7, 0xff, 0xff, 0xff, 0x1e,
0x06, 0x09, 0x05, 0xac, 0x02, 0x00, 0x90, 0x05, 0xca, 0x01, 0x00, 0x01, 0x90, 0x06, 0x36, 0x00,
0x00, 0x00, 0x1e, 0x06, 0x05, 0x06, 0x90, 0x05, 0xcb, 0x01, 0x00, 0x01, 0x90, 0x06, 0x01, 0x00,
0x00, 0x00, 0x1e, 0x06, 0x05, 0x06, 0x90, 0x05, 0xca, 0x01, 0x00, 0x01, 0x90, 0x06, 0x33, 0x00,
0x00, 0x00, 0x1e, 0x06, 0x05, 0x06, 0x90, 0x08, 0x00, 0x00, 0x8c, 0x00, 0x1e, 0x09, 0x08, 0x65,
0xff, 0x00, 0x00, 0x00, 0x01, 0x90, 0x06, 0x01, 0x00, 0x00, 0x00, 0x1e, 0x0a, 0x06, 0x90, 0x04,
0xca, 0x01, 0x00, 0x01, 0x90, 0x05, 0x35, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x04, 0x05, 0x1e, 0x09,
0x08, 0x65, 0xff, 0x00, 0x00, 0x00, 0x01, 0x9b, 0x06, 0x01, 0x1e, 0x0a, 0x06, 0x90, 0x06, 0xcf,
0x01, 0x00, 0x01, 0xa2, 0x1e, 0x03, 0x06, 0xa5, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x64, 0x00, 0xa4, 0x90, 0x05, 0xca, 0x01, 0x00, 0x01, 0x90, 0x06, 0x36, 0x00, 0x00, 0x00, 0x1e,
0x06, 0x05, 0x06, 0x90, 0x05, 0xcb, 0x01, 0x00, 0x01, 0x90, 0x06, 0x01, 0x00, 0x00, 0x00, 0x1e,
0x06, 0x05, 0x06, 0x90, 0x05, 0xca, 0x01, 0x00, 0x01, 0x90, 0x06, 0x33, 0x00, 0x00, 0x00, 0x1e,
0x06, 0x05, 0x06, 0x1e, 0x09, 0x00, 0x9c, 0x04, 0x20, 0x00, 0x1e, 0x10, 0x04, 0x1e, 0x0a, 0x04,
0x90, 0x05, 0xc0, 0x01, 0x00, 0x00, 0xfe, 0x05, 0x00, 0x00, 0x00, 0x00, 0x46, 0x01, 0x90, 0x04,
0xca, 0x01, 0x00, 0x01, 0x90, 0x05, 0x34, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x04, 0x05, 0x1e, 0x09,
0x00, 0x65, 0xff, 0x00, 0x00, 0x00, 0x01, 0x9b, 0x06, 0x01, 0x1e, 0x0a, 0x06, 0x90, 0x06, 0xcf,
0x01, 0x00, 0x01, 0xa2, 0x1e, 0x03, 0x06, 0xa5, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x64, 0x00, 0x1e, 0x06, 0x09, 0x0a, 0x92, 0x00, 0x20, 0x00, 0x00, 0x00, 0xae, 0x5a,
};
const unsigned char ReadDataEEmem_pdi_0[126] = {
0x91, 0x00, 0x91, 0x01, 0x95, 0x90, 0x04, 0xc0, 0x01, 0x00, 0x00, 0x90, 0x05, 0x00, 0x00, 0x00,
0x00, 0xfc, 0x04, 0x05, 0x26, 0x00, 0xad, 0x01, 0x1e, 0x03, 0x00, 0x9f, 0x92, 0x00, 0x01, 0x00,
0x00, 0x00, 0xae, 0xfb, 0x7d, 0x00, 0x90, 0x06, 0xca, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c,
0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c, 0x0b, 0x60, 0x03, 0x01, 0x93,
0x03, 0x20, 0x00, 0xad, 0x03, 0x90, 0x04, 0xca, 0x01, 0x00, 0x01, 0x90, 0x05, 0x06, 0x00, 0x00,
0x00, 0x1e, 0x06, 0x04, 0x05, 0x1e, 0x09, 0x00, 0x9c, 0x04, 0x20, 0x00, 0x1e, 0x10, 0x04, 0x1e,
0x0c, 0x04, 0x92, 0x00, 0x20, 0x00, 0x00, 0x00, 0xae, 0x90, 0x06, 0xca, 0x01, 0x00, 0x01, 0x1e,
0x06, 0x06, 0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x06, 0x06, 0x0b, 0x5a,
};
const unsigned char WriteConfigmem_pdi_0[89] = {
0x91, 0x00, 0x91, 0x01, 0xfe, 0x00, 0x27, 0x00, 0x8f, 0x00, 0x15, 0x00, 0x90, 0x07, 0x4c, 0x00,
0x00, 0x00, 0xfb, 0x1b, 0x00, 0x90, 0x07, 0x08, 0x00, 0x00, 0x00, 0xaf, 0xad, 0x01, 0x90, 0x02,
0xc0, 0x01, 0x00, 0x00, 0xfe, 0x02, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x90, 0x02, 0xca, 0x01,
0x00, 0x01, 0x1e, 0x06, 0x02, 0x07, 0x99, 0x04, 0x1e, 0x06, 0x00, 0x04, 0x90, 0x06, 0xcf, 0x01,
0x00, 0x01, 0xa2, 0x1e, 0x03, 0x06, 0xa5, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64,
0x00, 0x92, 0x00, 0x01, 0x00, 0x00, 0x00, 0xae, 0x5a,
};
const unsigned char WriteConfigmemFuse_pdi_0[71] = {
0x91, 0x00, 0x91, 0x01, 0xad, 0x01, 0x90, 0x02, 0xc0, 0x01, 0x00, 0x00, 0xfe, 0x02, 0x00, 0x00,
0x00, 0x00, 0x24, 0x00, 0x90, 0x02, 0xca, 0x01, 0x00, 0x01, 0x90, 0x03, 0x4c, 0x00, 0x00, 0x00,
0x1e, 0x06, 0x02, 0x03, 0x99, 0x04, 0x1e, 0x06, 0x00, 0x04, 0x90, 0x06, 0xcf, 0x01, 0x00, 0x01,
0xa2, 0x1e, 0x03, 0x06, 0xa5, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x92,
0x00, 0x01, 0x00, 0x00, 0x00, 0xae, 0x5a,
};
const unsigned char WriteConfigmemLock_pdi_0[71] = {
0x91, 0x00, 0x91, 0x01, 0xad, 0x01, 0x90, 0x02, 0xc0, 0x01, 0x00, 0x00, 0xfe, 0x02, 0x00, 0x00,
0x00, 0x00, 0x24, 0x00, 0x90, 0x02, 0xca, 0x01, 0x00, 0x01, 0x90, 0x03, 0x08, 0x00, 0x00, 0x00,
0x1e, 0x06, 0x02, 0x03, 0x99, 0x04, 0x1e, 0x06, 0x00, 0x04, 0x90, 0x06, 0xcf, 0x01, 0x00, 0x01,
0xa2, 0x1e, 0x03, 0x06, 0xa5, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x92,
0x00, 0x01, 0x00, 0x00, 0x00, 0xae, 0x5a,
};
const unsigned char ReadConfigmem_pdi_0[106] = {
0x91, 0x00, 0x91, 0x01, 0x95, 0x90, 0x04, 0xc0, 0x01, 0x00, 0x00, 0x90, 0x05, 0x00, 0x00, 0x00,
0x00, 0xfc, 0x04, 0x05, 0x26, 0x00, 0xad, 0x01, 0x1e, 0x03, 0x00, 0x9f, 0x92, 0x00, 0x01, 0x00,
0x00, 0x00, 0xae, 0xfb, 0x69, 0x00, 0x90, 0x06, 0xca, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c,
0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c, 0x0b, 0x90, 0x04, 0xca, 0x01,
0x00, 0x01, 0x90, 0x05, 0x07, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x04, 0x05, 0x1e, 0x09, 0x00, 0x1e,
0x10, 0x01, 0x1e, 0x0c, 0x01, 0x90, 0x06, 0xca, 0x01, 0x00, 0x01, 0x1e, 0x06, 0x06, 0x0a, 0x90,
0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x06, 0x06, 0x0b, 0x5a,
};
const unsigned char ReadConfigmemFuse_pdi_0[106] = {
0x91, 0x00, 0x91, 0x01, 0x95, 0x90, 0x04, 0xc0, 0x01, 0x00, 0x00, 0x90, 0x05, 0x00, 0x00, 0x00,
0x00, 0xfc, 0x04, 0x05, 0x26, 0x00, 0xad, 0x01, 0x1e, 0x03, 0x00, 0x9f, 0x92, 0x00, 0x01, 0x00,
0x00, 0x00, 0xae, 0xfb, 0x69, 0x00, 0x90, 0x06, 0xca, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c,
0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c, 0x0b, 0x90, 0x04, 0xca, 0x01,
0x00, 0x01, 0x90, 0x05, 0x07, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x04, 0x05, 0x1e, 0x09, 0x00, 0x1e,
0x10, 0x01, 0x1e, 0x0c, 0x01, 0x90, 0x06, 0xca, 0x01, 0x00, 0x01, 0x1e, 0x06, 0x06, 0x0a, 0x90,
0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x06, 0x06, 0x0b, 0x5a,
};
const unsigned char ReadConfigmemLock_pdi_0[106] = {
0x91, 0x00, 0x91, 0x01, 0x95, 0x90, 0x04, 0xc0, 0x01, 0x00, 0x00, 0x90, 0x05, 0x00, 0x00, 0x00,
0x00, 0xfc, 0x04, 0x05, 0x26, 0x00, 0xad, 0x01, 0x1e, 0x03, 0x00, 0x9f, 0x92, 0x00, 0x01, 0x00,
0x00, 0x00, 0xae, 0xfb, 0x69, 0x00, 0x90, 0x06, 0xca, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c,
0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c, 0x0b, 0x90, 0x04, 0xca, 0x01,
0x00, 0x01, 0x90, 0x05, 0x07, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x04, 0x05, 0x1e, 0x09, 0x00, 0x1e,
0x10, 0x01, 0x1e, 0x0c, 0x01, 0x90, 0x06, 0xca, 0x01, 0x00, 0x01, 0x1e, 0x06, 0x06, 0x0a, 0x90,
0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x06, 0x06, 0x0b, 0x5a,
};
const unsigned char WriteIDmem_pdi_0[198] = {
0x91, 0x00, 0x91, 0x01, 0x90, 0x04, 0xca, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x04, 0x6c, 0x0a, 0x90,
0x04, 0xca, 0x01, 0x00, 0x01, 0x90, 0x05, 0x18, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x04, 0x05, 0x90,
0x05, 0x55, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x00, 0x05, 0x90, 0x04, 0xcf, 0x01, 0x00, 0x01, 0xa2,
0x1e, 0x03, 0x04, 0xa5, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x90, 0x04,
0xca, 0x01, 0x00, 0x01, 0x1e, 0x06, 0x04, 0x0a, 0x60, 0x03, 0x01, 0x93, 0x03, 0x00, 0x02, 0xad,
0x03, 0x90, 0x04, 0xc0, 0x01, 0x00, 0x00, 0xfe, 0x04, 0x00, 0x00, 0x00, 0x00, 0x6f, 0x00, 0x90,
0x04, 0xca, 0x01, 0x00, 0x01, 0x90, 0x05, 0x23, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x04, 0x05, 0x1e,
0x09, 0x00, 0x9c, 0x04, 0x00, 0x02, 0x1e, 0x10, 0x04, 0x1e, 0x0a, 0x04, 0x90, 0x04, 0xc0, 0x01,
0x00, 0x00, 0xfe, 0x04, 0x00, 0x00, 0x00, 0x00, 0xbe, 0x00, 0x90, 0x04, 0xca, 0x01, 0x00, 0x01,
0x90, 0x05, 0x1a, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x04, 0x05, 0x1e, 0x09, 0x00, 0x65, 0xff, 0x00,
0x00, 0x00, 0x01, 0x9b, 0x06, 0x01, 0x1e, 0x0a, 0x06, 0x90, 0x06, 0xcf, 0x01, 0x00, 0x01, 0xa2,
0x1e, 0x03, 0x06, 0xa5, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x92, 0x00,
0x00, 0x02, 0x00, 0x00, 0xae, 0x5a,
};
const unsigned char WriteIDmem_pdi_1[198] = {
0x91, 0x00, 0x91, 0x01, 0x90, 0x04, 0xca, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x04, 0x6c, 0x0a, 0x90,
0x04, 0xca, 0x01, 0x00, 0x01, 0x90, 0x05, 0x18, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x04, 0x05, 0x90,
0x05, 0x55, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x00, 0x05, 0x90, 0x04, 0xcf, 0x01, 0x00, 0x01, 0xa2,
0x1e, 0x03, 0x04, 0xa5, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x90, 0x04,
0xca, 0x01, 0x00, 0x01, 0x1e, 0x06, 0x04, 0x0a, 0x60, 0x03, 0x01, 0x93, 0x03, 0x00, 0x01, 0xad,
0x03, 0x90, 0x04, 0xc0, 0x01, 0x00, 0x00, 0xfe, 0x04, 0x00, 0x00, 0x00, 0x00, 0x6f, 0x00, 0x90,
0x04, 0xca, 0x01, 0x00, 0x01, 0x90, 0x05, 0x23, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x04, 0x05, 0x1e,
0x09, 0x00, 0x9c, 0x04, 0x00, 0x01, 0x1e, 0x10, 0x04, 0x1e, 0x0a, 0x04, 0x90, 0x04, 0xc0, 0x01,
0x00, 0x00, 0xfe, 0x04, 0x00, 0x00, 0x00, 0x00, 0xbe, 0x00, 0x90, 0x04, 0xca, 0x01, 0x00, 0x01,
0x90, 0x05, 0x1a, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x04, 0x05, 0x1e, 0x09, 0x00, 0x65, 0xff, 0x00,
0x00, 0x00, 0x01, 0x9b, 0x06, 0x01, 0x1e, 0x0a, 0x06, 0x90, 0x06, 0xcf, 0x01, 0x00, 0x01, 0xa2,
0x1e, 0x03, 0x06, 0xa5, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x92, 0x00,
0x00, 0x01, 0x00, 0x00, 0xae, 0x5a,
};
const unsigned char WriteIDmem_pdi_2[198] = {
0x91, 0x00, 0x91, 0x01, 0x90, 0x04, 0xca, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x04, 0x6c, 0x0a, 0x90,
0x04, 0xca, 0x01, 0x00, 0x01, 0x90, 0x05, 0x18, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x04, 0x05, 0x90,
0x05, 0x55, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x00, 0x05, 0x90, 0x04, 0xcf, 0x01, 0x00, 0x01, 0xa2,
0x1e, 0x03, 0x04, 0xa5, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x90, 0x04,
0xca, 0x01, 0x00, 0x01, 0x1e, 0x06, 0x04, 0x0a, 0x60, 0x03, 0x01, 0x93, 0x03, 0x80, 0x00, 0xad,
0x03, 0x90, 0x04, 0xc0, 0x01, 0x00, 0x00, 0xfe, 0x04, 0x00, 0x00, 0x00, 0x00, 0x6f, 0x00, 0x90,
0x04, 0xca, 0x01, 0x00, 0x01, 0x90, 0x05, 0x23, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x04, 0x05, 0x1e,
0x09, 0x00, 0x9c, 0x04, 0x80, 0x00, 0x1e, 0x10, 0x04, 0x1e, 0x0a, 0x04, 0x90, 0x04, 0xc0, 0x01,
0x00, 0x00, 0xfe, 0x04, 0x00, 0x00, 0x00, 0x00, 0xbe, 0x00, 0x90, 0x04, 0xca, 0x01, 0x00, 0x01,
0x90, 0x05, 0x1a, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x04, 0x05, 0x1e, 0x09, 0x00, 0x65, 0xff, 0x00,
0x00, 0x00, 0x01, 0x9b, 0x06, 0x01, 0x1e, 0x0a, 0x06, 0x90, 0x06, 0xcf, 0x01, 0x00, 0x01, 0xa2,
0x1e, 0x03, 0x06, 0xa5, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x92, 0x00,
0x80, 0x00, 0x00, 0x00, 0xae, 0x5a,
};
const unsigned char ReadIDmem_pdi_0[126] = {
0x91, 0x00, 0x91, 0x01, 0x95, 0x90, 0x04, 0xc0, 0x01, 0x00, 0x00, 0x90, 0x05, 0x00, 0x00, 0x00,
0x00, 0xfc, 0x04, 0x05, 0x26, 0x00, 0xad, 0x01, 0x1e, 0x03, 0x00, 0x9f, 0x92, 0x00, 0x01, 0x00,
0x00, 0x00, 0xae, 0xfb, 0x7d, 0x00, 0x90, 0x06, 0xca, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c,
0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c, 0x0b, 0x60, 0x03, 0x01, 0x93,
0x03, 0x00, 0x02, 0xad, 0x03, 0x90, 0x04, 0xca, 0x01, 0x00, 0x01, 0x90, 0x05, 0x43, 0x00, 0x00,
0x00, 0x1e, 0x06, 0x04, 0x05, 0x1e, 0x09, 0x00, 0x9c, 0x04, 0x00, 0x02, 0x1e, 0x10, 0x04, 0x1e,
0x0c, 0x04, 0x92, 0x00, 0x00, 0x02, 0x00, 0x00, 0xae, 0x90, 0x06, 0xca, 0x01, 0x00, 0x01, 0x1e,
0x06, 0x06, 0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x06, 0x06, 0x0b, 0x5a,
};
const unsigned char ReadIDmem_pdi_1[126] = {
0x91, 0x00, 0x91, 0x01, 0x95, 0x90, 0x04, 0xc0, 0x01, 0x00, 0x00, 0x90, 0x05, 0x00, 0x00, 0x00,
0x00, 0xfc, 0x04, 0x05, 0x26, 0x00, 0xad, 0x01, 0x1e, 0x03, 0x00, 0x9f, 0x92, 0x00, 0x01, 0x00,
0x00, 0x00, 0xae, 0xfb, 0x7d, 0x00, 0x90, 0x06, 0xca, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c,
0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c, 0x0b, 0x60, 0x03, 0x01, 0x93,
0x03, 0x00, 0x01, 0xad, 0x03, 0x90, 0x04, 0xca, 0x01, 0x00, 0x01, 0x90, 0x05, 0x43, 0x00, 0x00,
0x00, 0x1e, 0x06, 0x04, 0x05, 0x1e, 0x09, 0x00, 0x9c, 0x04, 0x00, 0x01, 0x1e, 0x10, 0x04, 0x1e,
0x0c, 0x04, 0x92, 0x00, 0x00, 0x01, 0x00, 0x00, 0xae, 0x90, 0x06, 0xca, 0x01, 0x00, 0x01, 0x1e,
0x06, 0x06, 0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x06, 0x06, 0x0b, 0x5a,
};
const unsigned char ReadIDmem_pdi_2[126] = {
0x91, 0x00, 0x91, 0x01, 0x95, 0x90, 0x04, 0xc0, 0x01, 0x00, 0x00, 0x90, 0x05, 0x00, 0x00, 0x00,
0x00, 0xfc, 0x04, 0x05, 0x26, 0x00, 0xad, 0x01, 0x1e, 0x03, 0x00, 0x9f, 0x92, 0x00, 0x01, 0x00,
0x00, 0x00, 0xae, 0xfb, 0x7d, 0x00, 0x90, 0x06, 0xca, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c,
0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c, 0x0b, 0x60, 0x03, 0x01, 0x93,
0x03, 0x80, 0x00, 0xad, 0x03, 0x90, 0x04, 0xca, 0x01, 0x00, 0x01, 0x90, 0x05, 0x43, 0x00, 0x00,
0x00, 0x1e, 0x06, 0x04, 0x05, 0x1e, 0x09, 0x00, 0x9c, 0x04, 0x80, 0x00, 0x1e, 0x10, 0x04, 0x1e,
0x0c, 0x04, 0x92, 0x00, 0x80, 0x00, 0x00, 0x00, 0xae, 0x90, 0x06, 0xca, 0x01, 0x00, 0x01, 0x1e,
0x06, 0x06, 0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x06, 0x06, 0x0b, 0x5a,
};
const unsigned char WriteSRAM_pdi_0[70] = {
0x91, 0x00, 0x91, 0x01, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x90, 0x03, 0x00, 0x00, 0x01, 0x00,
0xfa, 0x01, 0x03, 0x1b, 0x00, 0x60, 0x04, 0x01, 0xfb, 0x21, 0x00, 0x90, 0x04, 0x00, 0x00, 0x01,
0x00, 0x6a, 0x01, 0x04, 0x90, 0x02, 0xca, 0x01, 0x00, 0x01, 0x90, 0x03, 0x00, 0x00, 0x00, 0x00,
0x1e, 0x06, 0x02, 0x03, 0x1e, 0x09, 0x00, 0x1e, 0x10, 0x04, 0x1e, 0x0a, 0x04, 0x6e, 0x00, 0x04,
0xfc, 0x01, 0x07, 0x0a, 0x00, 0x5a,
};
const unsigned char ReadSRAM_pdi_0[130] = {
0x91, 0x00, 0x91, 0x01, 0x95, 0x90, 0x04, 0xc0, 0x01, 0x00, 0x00, 0x90, 0x05, 0x00, 0x00, 0x00,
0x00, 0xfc, 0x04, 0x05, 0x26, 0x00, 0xad, 0x01, 0x1e, 0x03, 0x00, 0x9f, 0x92, 0x00, 0x01, 0x00,
0x00, 0x00, 0xae, 0xfb, 0x81, 0x00, 0x90, 0x06, 0xca, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c,
0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c, 0x0b, 0x90, 0x07, 0x00, 0x00,
0x00, 0x00, 0x90, 0x03, 0x00, 0x00, 0x01, 0x00, 0xfa, 0x01, 0x03, 0x53, 0x00, 0x60, 0x04, 0x01,
0xfb, 0x59, 0x00, 0x90, 0x04, 0x00, 0x00, 0x01, 0x00, 0x6a, 0x01, 0x04, 0x1e, 0x09, 0x00, 0x1e,
0x10, 0x04, 0x1e, 0x0c, 0x04, 0x6e, 0x00, 0x04, 0xfc, 0x01, 0x07, 0x42, 0x00, 0x90, 0x06, 0xca,
0x01, 0x00, 0x01, 0x1e, 0x06, 0x06, 0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x06, 0x06,
0x0b, 0x5a,
};
const unsigned char WriteCSreg_pdi_0[8] = {
0x99, 0x00, 0x99, 0x01, 0x1e, 0x0f, 0x00, 0x01,
};
const unsigned char ReadCSreg_pdi_0[6] = {
0x99, 0x00, 0x1e, 0x0e, 0x00, 0x9f,
};
const unsigned char WriteMem8_pdi_0[70] = {
0x91, 0x00, 0x91, 0x01, 0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x90, 0x03, 0x00, 0x00, 0x01, 0x00,
0xfa, 0x01, 0x03, 0x1b, 0x00, 0x60, 0x04, 0x01, 0xfb, 0x21, 0x00, 0x90, 0x04, 0x00, 0x00, 0x01,
0x00, 0x6a, 0x01, 0x04, 0x90, 0x02, 0xca, 0x01, 0x00, 0x01, 0x90, 0x03, 0x00, 0x00, 0x00, 0x00,
0x1e, 0x06, 0x02, 0x03, 0x1e, 0x09, 0x00, 0x1e, 0x10, 0x04, 0x1e, 0x0a, 0x04, 0x6e, 0x00, 0x04,
0xfc, 0x01, 0x07, 0x0a, 0x00, 0x5a,
};
const unsigned char ReadMem8_pdi_0[130] = {
0x91, 0x00, 0x91, 0x01, 0x95, 0x90, 0x04, 0xc0, 0x01, 0x00, 0x00, 0x90, 0x05, 0x00, 0x00, 0x00,
0x00, 0xfc, 0x04, 0x05, 0x26, 0x00, 0xad, 0x01, 0x1e, 0x03, 0x00, 0x9f, 0x92, 0x00, 0x01, 0x00,
0x00, 0x00, 0xae, 0xfb, 0x81, 0x00, 0x90, 0x06, 0xca, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c,
0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x03, 0x06, 0x6c, 0x0b, 0x90, 0x07, 0x00, 0x00,
0x00, 0x00, 0x90, 0x03, 0x00, 0x00, 0x01, 0x00, 0xfa, 0x01, 0x03, 0x53, 0x00, 0x60, 0x04, 0x01,
0xfb, 0x59, 0x00, 0x90, 0x04, 0x00, 0x00, 0x01, 0x00, 0x6a, 0x01, 0x04, 0x1e, 0x09, 0x00, 0x1e,
0x10, 0x04, 0x1e, 0x0c, 0x04, 0x6e, 0x00, 0x04, 0xfc, 0x01, 0x07, 0x42, 0x00, 0x90, 0x06, 0xca,
0x01, 0x00, 0x01, 0x1e, 0x06, 0x06, 0x0a, 0x90, 0x06, 0xc4, 0x01, 0x00, 0x01, 0x1e, 0x06, 0x06,
0x0b, 0x5a,
};
static void pickit_pdi_script_init(SCRIPT *scr);
static void pickit_pdi_script_init(SCRIPT *scr) {
memset(scr, 0x00, sizeof(SCRIPT)); // Make sure everything is NULL
scr->EnterProgMode = EnterProgMode_pdi_0;
scr->ExitProgMode = ExitProgMode_pdi_0;
scr->SetSpeed = SetSpeed_pdi_0;
scr->GetDeviceID = GetDeviceID_pdi_0;
scr->EraseChip = EraseChip_pdi_0;
scr->WriteDataEEmem = WriteDataEEmem_pdi_0;
scr->ReadDataEEmem = ReadDataEEmem_pdi_0;
scr->WriteConfigmem = WriteConfigmem_pdi_0;
scr->WriteConfigmemFuse = WriteConfigmemFuse_pdi_0;
scr->WriteConfigmemLock = WriteConfigmemLock_pdi_0;
scr->ReadConfigmem = ReadConfigmem_pdi_0;
scr->ReadConfigmemFuse = ReadConfigmemFuse_pdi_0;
scr->ReadConfigmemLock = ReadConfigmemLock_pdi_0;
scr->WriteSRAM = WriteSRAM_pdi_0;
scr->ReadSRAM = ReadSRAM_pdi_0;
scr->WriteCSreg = WriteCSreg_pdi_0;
scr->ReadCSreg = ReadCSreg_pdi_0;
scr->WriteMem8 = WriteMem8_pdi_0;
scr->ReadMem8 = ReadMem8_pdi_0;
scr->EnterProgMode_len = sizeof(EnterProgMode_pdi_0);
scr->ExitProgMode_len = sizeof(ExitProgMode_pdi_0);
scr->SetSpeed_len = sizeof(SetSpeed_pdi_0);
scr->GetDeviceID_len = sizeof(GetDeviceID_pdi_0);
scr->EraseChip_len = sizeof(EraseChip_pdi_0);
scr->WriteDataEEmem_len = sizeof(WriteDataEEmem_pdi_0);
scr->ReadDataEEmem_len = sizeof(ReadDataEEmem_pdi_0);
scr->WriteConfigmem_len = sizeof(WriteConfigmem_pdi_0);
scr->WriteConfigmemFuse_len = sizeof(WriteConfigmemFuse_pdi_0);
scr->WriteConfigmemLock_len = sizeof(WriteConfigmemLock_pdi_0);
scr->ReadConfigmem_len = sizeof(ReadConfigmem_pdi_0);
scr->ReadConfigmemFuse_len = sizeof(ReadConfigmemFuse_pdi_0);
scr->ReadConfigmemLock_len = sizeof(ReadConfigmemLock_pdi_0);
scr->WriteSRAM_len = sizeof(WriteSRAM_pdi_0);
scr->ReadSRAM_len = sizeof(ReadSRAM_pdi_0);
scr->WriteCSreg_len = sizeof(WriteCSreg_pdi_0);
scr->ReadCSreg_len = sizeof(ReadCSreg_pdi_0);
scr->WriteMem8_len = sizeof(WriteMem8_pdi_0);
scr->ReadMem8_len = sizeof(ReadMem8_pdi_0);
}
const char * const pickit5_pdi_chip_lut[] = {
"ATxmega128A1", "ATxmega128A1U", "ATxmega128A3", "ATxmega128A3U", "ATxmega128A4U", "ATxmega16A4", "ATxmega16A4U", "ATxmega192A3",
"ATxmega192A3U", "ATxmega256A3", "ATxmega256A3B", "ATxmega256A3BU", "ATxmega256A3U", "ATxmega32A4", "ATxmega32A4U", "ATxmega64A1",
"ATxmega64A1U", "ATxmega64A3", "ATxmega64A3U", "ATxmega64A4U", "ATxmega128B1", "ATxmega128B3", "ATxmega64B1", "ATxmega64B3",
"ATxmega128C3", "ATxmega16C4", "ATxmega192C3", "ATxmega256C3", "ATxmega32C3", "ATxmega32C4", "ATxmega384C3", "ATxmega64C3",
"ATxmega128D3", "ATxmega128D4", "ATxmega16D4", "ATxmega192D3", "ATxmega256D3", "ATxmega32D3", "ATxmega32D4", "ATxmega384D3",
"ATxmega64D3", "ATxmega64D4", "ATxmega16E5", "ATxmega32E5", "ATxmega8E5",
};
int get_pickit_pdi_script(SCRIPT *scr, const char* partdesc) {
if ((scr == NULL) || (partdesc == NULL)) {
return -1;
}
int namepos = -1;
for (int i = 0; i < 45; i++) {
if (strncmp(pickit5_pdi_chip_lut[i], partdesc, 10) == 0) {
namepos = i;
break;
}
}
if (namepos == -1) {
return -2;
}
pickit_pdi_script_init(scr); // load common functions
switch (namepos) {
case 0: /* ATxmega128A1 */
case 1: /* ATxmega128A1U */
case 2: /* ATxmega128A3 */
case 3: /* ATxmega128A3U */
case 7: /* ATxmega192A3 */
case 8: /* ATxmega192A3U */
case 9: /* ATxmega256A3 */
case 10: /* ATxmega256A3B */
case 11: /* ATxmega256A3BU */
case 12: /* ATxmega256A3U */
case 24: /* ATxmega128C3 */
case 26: /* ATxmega192C3 */
case 27: /* ATxmega256C3 */
case 30: /* ATxmega384C3 */
case 32: /* ATxmega128D3 */
case 35: /* ATxmega192D3 */
case 36: /* ATxmega256D3 */
case 39: /* ATxmega384D3 */
scr->WriteProgmem = WriteProgmem_pdi_0;
scr->WriteProgmem_len = sizeof(WriteProgmem_pdi_0);
scr->ReadProgmem = ReadProgmem_pdi_0;
scr->ReadProgmem_len = sizeof(ReadProgmem_pdi_0);
scr->WriteIDmem = WriteIDmem_pdi_0;
scr->WriteIDmem_len = sizeof(WriteIDmem_pdi_0);
scr->ReadIDmem = ReadIDmem_pdi_0;
scr->ReadIDmem_len = sizeof(ReadIDmem_pdi_0);
break;
case 4: /* ATxmega128A4U */
case 5: /* ATxmega16A4 */
case 6: /* ATxmega16A4U */
case 13: /* ATxmega32A4 */
case 14: /* ATxmega32A4U */
case 15: /* ATxmega64A1 */
case 16: /* ATxmega64A1U */
case 17: /* ATxmega64A3 */
case 18: /* ATxmega64A3U */
case 19: /* ATxmega64A4U */
case 20: /* ATxmega128B1 */
case 21: /* ATxmega128B3 */
case 22: /* ATxmega64B1 */
case 23: /* ATxmega64B3 */
case 25: /* ATxmega16C4 */
case 28: /* ATxmega32C3 */
case 29: /* ATxmega32C4 */
case 31: /* ATxmega64C3 */
case 33: /* ATxmega128D4 */
case 34: /* ATxmega16D4 */
case 37: /* ATxmega32D3 */
case 38: /* ATxmega32D4 */
case 40: /* ATxmega64D3 */
case 41: /* ATxmega64D4 */
scr->WriteProgmem = WriteProgmem_pdi_1;
scr->WriteProgmem_len = sizeof(WriteProgmem_pdi_1);
scr->ReadProgmem = ReadProgmem_pdi_1;
scr->ReadProgmem_len = sizeof(ReadProgmem_pdi_1);
scr->WriteIDmem = WriteIDmem_pdi_1;
scr->WriteIDmem_len = sizeof(WriteIDmem_pdi_1);
scr->ReadIDmem = ReadIDmem_pdi_1;
scr->ReadIDmem_len = sizeof(ReadIDmem_pdi_1);
break;
case 42: /* ATxmega16E5 */
case 43: /* ATxmega32E5 */
case 44: /* ATxmega8E5 */
scr->WriteProgmem = WriteProgmem_pdi_2;
scr->WriteProgmem_len = sizeof(WriteProgmem_pdi_2);
scr->ReadProgmem = ReadProgmem_pdi_2;
scr->ReadProgmem_len = sizeof(ReadProgmem_pdi_2);
scr->WriteIDmem = WriteIDmem_pdi_2;
scr->WriteIDmem_len = sizeof(WriteIDmem_pdi_2);
scr->ReadIDmem = ReadIDmem_pdi_2;
scr->ReadIDmem_len = sizeof(ReadIDmem_pdi_2);
break;
}
return 0;
}

186
src/pickit5_lut_tpi.c Normal file
View File

@@ -0,0 +1,186 @@
/* This file was auto-generated by scripts_decoder.py.
* Any changes will be overwritten on regeneration
*/
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <ac_cfg.h>
#include <stddef.h>
#include <string.h>
#include "pickit5_lut.h"
const unsigned char EnterProgMode_tpi_0[63] = {
0x9b, 0x00, 0x01, 0x1e, 0x20, 0x00, 0x9b, 0x00, 0x0f, 0x1e, 0x27, 0x00, 0x9b, 0x00, 0x02, 0x1e,
0x27, 0x00, 0x9b, 0x00, 0x02, 0x9b, 0x01, 0x04, 0x1e, 0x28, 0x00, 0x01, 0x6c, 0x02, 0x1e, 0x27,
0x02, 0x1e, 0x29, 0x45, 0xab, 0x89, 0x12, 0xff, 0x88, 0xd8, 0xcd, 0x9b, 0x00, 0x00, 0xa2, 0x1e,
0x27, 0x00, 0x6c, 0x02, 0xa5, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x32, 0x00,
};
const unsigned char ExitProgMode_tpi_0[18] = {
0x9b, 0x00, 0x00, 0x9b, 0x01, 0x00, 0x1e, 0x28, 0x00, 0x01, 0x9b, 0x00, 0x00, 0x1e, 0x27, 0x00,
0x1e, 0x21,
};
const unsigned char SetSpeed_tpi_0[1] = {
0x5a,
};
const unsigned char GetDeviceID_tpi_0[29] = {
0x9c, 0x00, 0x33, 0x00, 0x9b, 0x01, 0x00, 0x1e, 0x26, 0x00, 0x01, 0x9c, 0x00, 0xc0, 0x3f, 0xac,
0x03, 0x00, 0x1e, 0x22, 0x00, 0x9f, 0x92, 0x00, 0x01, 0x00, 0x00, 0x00, 0xa4,
};
const unsigned char EraseChip_tpi_0[43] = {
0x9b, 0x00, 0x33, 0x9b, 0x01, 0x10, 0x1e, 0x26, 0x00, 0x01, 0x9c, 0x00, 0x01, 0x40, 0x9b, 0x01,
0xff, 0x1e, 0x23, 0x00, 0x01, 0x90, 0x04, 0x32, 0x00, 0x00, 0x00, 0xa2, 0x1e, 0x25, 0x04, 0xa5,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0xae,
};
const unsigned char WriteProgmem_tpi_0[140] = {
0x91, 0x00, 0x91, 0x01, 0x9b, 0x02, 0x33, 0x9b, 0x03, 0x1d, 0x60, 0x05, 0x01, 0x66, 0x01, 0x01,
0x00, 0x00, 0x00, 0x60, 0x06, 0x01, 0x60, 0x01, 0x05, 0x67, 0x01, 0x01, 0x1e, 0x26, 0x02, 0x03,
0x9b, 0x07, 0x00, 0xf8, 0x01, 0x07, 0x66, 0x00, 0xfb, 0x2b, 0x00, 0xad, 0x01, 0x99, 0x02, 0x1e,
0x23, 0x00, 0x02, 0x92, 0x00, 0x01, 0x00, 0x00, 0x00, 0x99, 0x02, 0x1e, 0x23, 0x00, 0x02, 0x92,
0x00, 0x01, 0x00, 0x00, 0x00, 0x90, 0x04, 0x32, 0x00, 0x00, 0x00, 0xa2, 0x1e, 0x25, 0x04, 0xa5,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0xae, 0x9b, 0x07, 0x01, 0xf8, 0x06,
0x07, 0x66, 0x00, 0xfb, 0x8b, 0x00, 0x99, 0x02, 0x1e, 0x23, 0x00, 0x02, 0x92, 0x00, 0x01, 0x00,
0x00, 0x00, 0x1e, 0x23, 0x00, 0xff, 0x90, 0x04, 0x32, 0x00, 0x00, 0x00, 0xa2, 0x1e, 0x25, 0x04,
0xa5, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x5a,
};
const unsigned char ReadProgmem_tpi_0[27] = {
0x91, 0x00, 0x91, 0x01, 0x9b, 0x02, 0x33, 0x9b, 0x03, 0x00, 0x1e, 0x26, 0x02, 0x03, 0xad, 0x01,
0x1e, 0x22, 0x00, 0x9f, 0x92, 0x00, 0x01, 0x00, 0x00, 0x00, 0xae,
};
const unsigned char WriteConfigmemFuse_tpi_0[189] = {
0x91, 0x00, 0x91, 0x01, 0x9b, 0x0a, 0x33, 0x9b, 0x0b, 0x14, 0x1e, 0x26, 0x0a, 0x0b, 0x9c, 0x0a,
0x41, 0x3f, 0x9b, 0x0b, 0xff, 0x1e, 0x23, 0x0a, 0x0b, 0x90, 0x0e, 0x32, 0x00, 0x00, 0x00, 0xa2,
0x1e, 0x25, 0x0e, 0xa5, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0xae, 0x94,
0x32, 0x00, 0x9b, 0x02, 0x33, 0x9b, 0x03, 0x1d, 0x60, 0x05, 0x01, 0x66, 0x01, 0x01, 0x00, 0x00,
0x00, 0x60, 0x06, 0x01, 0x60, 0x01, 0x05, 0x67, 0x01, 0x01, 0x1e, 0x26, 0x02, 0x03, 0x9b, 0x07,
0x00, 0xf8, 0x01, 0x07, 0x94, 0x00, 0xfb, 0x59, 0x00, 0xad, 0x01, 0x99, 0x02, 0x1e, 0x23, 0x00,
0x02, 0x92, 0x00, 0x01, 0x00, 0x00, 0x00, 0x99, 0x02, 0x1e, 0x23, 0x00, 0x02, 0x92, 0x00, 0x01,
0x00, 0x00, 0x00, 0x90, 0x04, 0x32, 0x00, 0x00, 0x00, 0xa2, 0x1e, 0x25, 0x04, 0xa5, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0xae, 0x9b, 0x07, 0x01, 0xf8, 0x06, 0x07, 0x94,
0x00, 0xfb, 0xbc, 0x00, 0x99, 0x02, 0x1e, 0x23, 0x00, 0x02, 0x92, 0x00, 0x01, 0x00, 0x00, 0x00,
0x1e, 0x23, 0x00, 0xff, 0x90, 0x04, 0x32, 0x00, 0x00, 0x00, 0xa2, 0x1e, 0x25, 0x04, 0xa5, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x94, 0x19, 0x00, 0x5a,
};
const unsigned char WriteConfigmemLock_tpi_0[189] = {
0x91, 0x00, 0x91, 0x01, 0x9b, 0x0a, 0x33, 0x9b, 0x0b, 0x14, 0x1e, 0x26, 0x0a, 0x0b, 0x9c, 0x0a,
0x41, 0x3f, 0x9b, 0x0b, 0xff, 0x1e, 0x23, 0x0a, 0x0b, 0x90, 0x0e, 0x32, 0x00, 0x00, 0x00, 0xa2,
0x1e, 0x25, 0x0e, 0xa5, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0xae, 0x94,
0x32, 0x00, 0x9b, 0x02, 0x33, 0x9b, 0x03, 0x1d, 0x60, 0x05, 0x01, 0x66, 0x01, 0x01, 0x00, 0x00,
0x00, 0x60, 0x06, 0x01, 0x60, 0x01, 0x05, 0x67, 0x01, 0x01, 0x1e, 0x26, 0x02, 0x03, 0x9b, 0x07,
0x00, 0xf8, 0x01, 0x07, 0x94, 0x00, 0xfb, 0x59, 0x00, 0xad, 0x01, 0x99, 0x02, 0x1e, 0x23, 0x00,
0x02, 0x92, 0x00, 0x01, 0x00, 0x00, 0x00, 0x99, 0x02, 0x1e, 0x23, 0x00, 0x02, 0x92, 0x00, 0x01,
0x00, 0x00, 0x00, 0x90, 0x04, 0x32, 0x00, 0x00, 0x00, 0xa2, 0x1e, 0x25, 0x04, 0xa5, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0xae, 0x9b, 0x07, 0x01, 0xf8, 0x06, 0x07, 0x94,
0x00, 0xfb, 0xbc, 0x00, 0x99, 0x02, 0x1e, 0x23, 0x00, 0x02, 0x92, 0x00, 0x01, 0x00, 0x00, 0x00,
0x1e, 0x23, 0x00, 0xff, 0x90, 0x04, 0x32, 0x00, 0x00, 0x00, 0xa2, 0x1e, 0x25, 0x04, 0xa5, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x94, 0x19, 0x00, 0x5a,
};
const unsigned char ReadConfigmem_tpi_0[27] = {
0x91, 0x00, 0x91, 0x01, 0x9b, 0x02, 0x33, 0x9b, 0x03, 0x00, 0x1e, 0x26, 0x02, 0x03, 0xad, 0x01,
0x1e, 0x22, 0x00, 0x9f, 0x92, 0x00, 0x01, 0x00, 0x00, 0x00, 0xae,
};
const unsigned char ReadConfigmemFuse_tpi_0[27] = {
0x91, 0x00, 0x91, 0x01, 0x9b, 0x02, 0x33, 0x9b, 0x03, 0x00, 0x1e, 0x26, 0x02, 0x03, 0xad, 0x01,
0x1e, 0x22, 0x00, 0x9f, 0x92, 0x00, 0x01, 0x00, 0x00, 0x00, 0xae,
};
const unsigned char ReadConfigmemLock_tpi_0[27] = {
0x91, 0x00, 0x91, 0x01, 0x9b, 0x02, 0x33, 0x9b, 0x03, 0x00, 0x1e, 0x26, 0x02, 0x03, 0xad, 0x01,
0x1e, 0x22, 0x00, 0x9f, 0x92, 0x00, 0x01, 0x00, 0x00, 0x00, 0xae,
};
static void pickit_tpi_script_init(SCRIPT *scr);
static void pickit_tpi_script_init(SCRIPT *scr) {
memset(scr, 0x00, sizeof(SCRIPT)); // Make sure everything is NULL
scr->EnterProgMode = EnterProgMode_tpi_0;
scr->ExitProgMode = ExitProgMode_tpi_0;
scr->SetSpeed = SetSpeed_tpi_0;
scr->GetDeviceID = GetDeviceID_tpi_0;
scr->EraseChip = EraseChip_tpi_0;
scr->WriteProgmem = WriteProgmem_tpi_0;
scr->ReadProgmem = ReadProgmem_tpi_0;
scr->WriteConfigmemFuse = WriteConfigmemFuse_tpi_0;
scr->WriteConfigmemLock = WriteConfigmemLock_tpi_0;
scr->ReadConfigmem = ReadConfigmem_tpi_0;
scr->ReadConfigmemFuse = ReadConfigmemFuse_tpi_0;
scr->ReadConfigmemLock = ReadConfigmemLock_tpi_0;
scr->EnterProgMode_len = sizeof(EnterProgMode_tpi_0);
scr->ExitProgMode_len = sizeof(ExitProgMode_tpi_0);
scr->SetSpeed_len = sizeof(SetSpeed_tpi_0);
scr->GetDeviceID_len = sizeof(GetDeviceID_tpi_0);
scr->EraseChip_len = sizeof(EraseChip_tpi_0);
scr->WriteProgmem_len = sizeof(WriteProgmem_tpi_0);
scr->ReadProgmem_len = sizeof(ReadProgmem_tpi_0);
scr->WriteConfigmemFuse_len = sizeof(WriteConfigmemFuse_tpi_0);
scr->WriteConfigmemLock_len = sizeof(WriteConfigmemLock_tpi_0);
scr->ReadConfigmem_len = sizeof(ReadConfigmem_tpi_0);
scr->ReadConfigmemFuse_len = sizeof(ReadConfigmemFuse_tpi_0);
scr->ReadConfigmemLock_len = sizeof(ReadConfigmemLock_tpi_0);
}
const char * const pickit5_tpi_chip_lut[] = {
"ATtiny10", "ATtiny102", "ATtiny104", "ATtiny20", "ATtiny4", "ATtiny40", "ATtiny5", "ATtiny9",
};
int get_pickit_tpi_script(SCRIPT *scr, const char* partdesc) {
if ((scr == NULL) || (partdesc == NULL)) {
return -1;
}
int namepos = -1;
for (int i = 0; i < 8; i++) {
if (strncmp(pickit5_tpi_chip_lut[i], partdesc, 10) == 0) {
namepos = i;
break;
}
}
if (namepos == -1) {
return -2;
}
pickit_tpi_script_init(scr); // load common functions
switch (namepos) {
case 0: /* ATtiny10 */
case 1: /* ATtiny102 */
case 2: /* ATtiny104 */
case 3: /* ATtiny20 */
case 4: /* ATtiny4 */
case 5: /* ATtiny40 */
case 6: /* ATtiny5 */
case 7: /* ATtiny9 */
break;
}
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -19,117 +19,73 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# this is a small python sketch that tries to find the PICkit5_TP folder
# this is a small python skript 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 original file has a size of about 300MB, containing a lot of
# redundand information as well as sub-programs for chips avrdude doesn't
# support, like ARM MCUs.
# This python scripts iterates through all functions, removing identical ones,
# redundand information (like the XML tags) as well as sub-programs for chips
# avrdude doesn't support, like ARM MCUs.
# This python script goes through all functions, removing identical ones,
# and indexes those. The index is then used to connect the MCUs with those functions
# so that the correct array pointers can be loaded.
# Warning: If you run this python program, the previously generated files will be
# overwritten without warning.
#
# As the XML file is fairly large, a machine with at least 16GB RAM is recommended
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" : [], # High Voltage Pulse on UPDI line
"EnterProgModeHvSpRst" : [], # High Voltage Pulse on Reset Pin
"EnterProgModeHvUpt" : [],
"ExitProgMode" : [],
"SetSpeed" : [],
"GetDeviceID" : [],
"EraseChip" : [],
"WriteProgmem" : [],
"ReadProgmem" : [],
"WriteDataEEmem" : [],
"ReadDataEEmem" : [],
"WriteCSreg" : [],
"ReadCSreg" : [],
"WriteMem8" : [],
"ReadMem8" : [],
"WriteConfigmem" : [],
"ReadConfigmem" : [],
"WriteIDmem" : [],
"ReadIDmem" : [],
"ReadSIB" : [],
}
c_func_list = [
# Started with UPDI
"EnterProgMode",
"EnterProgModeHvSp", # High Voltage Pulse on UPDI line
"EnterProgModeHvSpRst", # High Voltage Pulse on Reset Pin
"EnterProgModeHvUpt", # User Power Toggle
"ExitProgMode",
"SetSpeed",
"GetDeviceID",
"EraseChip",
"WriteProgmem",
"ReadProgmem",
"WriteDataEEmem",
"ReadDataEEmem",
"WriteCSreg",
"ReadCSreg",
"WriteMem8",
"ReadMem8",
"WriteConfigmem",
"WriteConfigmemFuse",
"WriteConfigmemLock",
"ReadConfigmem",
"ReadConfigmemFuse",
"ReadConfigmemLock",
"WriteIDmem",
"ReadIDmem",
"ReadSIB",
# List of MCUs that should not end up in the lookup-table,
# preferably only those that are known not be released in the future
mcu_blacklist = [
"AVR16DV14", "AVR16DV20"
# Added from dW
"switchtoISP",
"ReadMemIO",
"WriteMemIO",
# Added from ISP
"ReadCalibrationByte",
# Added from JTAG/PDI
"WriteSRAM",
"ReadSRAM",
]
# 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
'''
# List of MCUs that are supported by avrdude, extracted from the .conf file
mcu_list = []
import platform
@@ -141,155 +97,13 @@ 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))
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
# Beginning of C and H Files
common_header = \
'''/* This file was auto-generated by scripts_decoder.py, any changes will be overwritten */
'''\
/* This file was auto-generated by scripts_decoder.py.
* Any changes will be overwritten on regeneration
*/
/*
* avrdude - A Downloader/Uploader for AVR device programmers
@@ -312,7 +126,7 @@ common_header = \
'''
# generates the h-file. generates the struct definition
def generate_h_file(c_dict, file_dir):
def generate_h_file(c_funcs, file_dir):
h_header = \
'''
#ifndef pickit5_lut_h
@@ -331,7 +145,12 @@ struct avr_script_lut {
typedef struct avr_script_lut SCRIPT;
const unsigned char * get_devid_script_by_nvm_ver(unsigned char version);
int get_pickit_dw_script(SCRIPT *scr, const char *partdesc);
int get_pickit_isp_script(SCRIPT *scr, const char *partdesc);
int get_pickit_jtag_script(SCRIPT *scr, const char *partdesc);
int get_pickit_updi_script(SCRIPT *scr, const char *partdesc);
int get_pickit_pdi_script(SCRIPT *scr, const char *partdesc);
int get_pickit_tpi_script(SCRIPT *scr, const char *partdesc);
#ifdef __cplusplus
}
@@ -346,10 +165,11 @@ int get_pickit_updi_script(SCRIPT *scr, const char *partdesc);
h_lut_path = os.path.join(file_dir, "pickit5_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(common_header)
h_file.write(h_header)
for func_name in c_dict:
for func_name in c_funcs:
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")
@@ -357,319 +177,299 @@ int get_pickit_updi_script(SCRIPT *scr, const char *partdesc);
# 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:
# 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
c_lut_path = os.path.join(file_dir, "pickit5_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 <ac_cfg.h>\n")
c_file.write("#include <stddef.h>\n")
c_file.write("#include <string.h>\n")
c_file.write("#include \"pickit5_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)
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))
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)
print("List of scripts.xml files:")
print(result)
return result[-1]
# EOF
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 = "const 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
# Example of a function declaration in the XML-File
# <script>
# <function>SetSpeedFromDevice</function>
# <processor>ATSAM4LC2A</processor>
# <ri4command>0x00001504</ri4command>
# <scrbytes>
# <byte>0x3B</byte>
# <byte>0x02</byte>
# <byte>0x00</byte>
# <byte>0x00</byte>
# <byte>0x00</byte>
# </scrbytes>
# </script>
# A sum of the previous functions, generating the c/h files
# without needing any intermediate files
def convert_xml(xml_path, c_dict):
def convert_xml(xml_path, c_funcs):
if xml_path == None:
print("No Path to XML file provided")
return
mcu_dict = dict()
program_iface = {
"UPDI": dict(),
"PDI": dict(),
"dW": dict(),
"ISP": dict(),
"TPI": dict(),
"JTAG": dict()
}
function_dict = {
"UPDI": dict(),
"PDI": dict(),
"dW": dict(),
"ISP": dict(),
"TPI": dict(),
"JTAG": dict()
}
# Prepare directories
parent_dir = os.getcwd()
src_dir = os.path.join(parent_dir, "src")
conf_path = os.path.join(src_dir, "avrdude.conf.in")
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")
# create h-File (make sure to provide all function definitions)
generate_h_file(c_funcs, src_dir)
# 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 in mcu_blacklist): # filter out chips in blacklist
continue
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 processed")
with open(conf_path, "r") as conf_file:
while True:
line = conf_file.readline()
if line == "":
print("List of MCUs created with {0} devices".format(len(mcu_list)))
break # Exit on end of file
if line.startswith("part"):
desc = conf_file.readline().split('"', 3)[1]
if desc.lower().find("common") < 0: # Skip any desc that contains the word "common"
mcu_list.append(desc)
# 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] = []
with open(xml_path, "r") as xml_script:
print ("XML File opened")
scr_bytes_buffer = bytearray(2048) # allocate 2kB of memory in advance
while True:
line = xml_script.readline() # go line by line, hopefully reducing memory usage compared to readlines()
if line == "":
break # exit when End of file
if line.startswith(" <function>"):
function = line[14:] # remove " <function>"
function = function.split("<", 2)[0] # remove trailing element
scr_header = xml_script.readlines(3) # read 3 more lines
processor = scr_header[0][15:] # remove " <processor>"
chip_name = processor.split("<", 2)[0] # remove trailing element
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)
try:
function_name, programming_mode = function.split('_')
except:
continue # If the function did not contain any '_', continue to next line
if programming_mode not in ["UPDI", "PDI", "dW", "ISP", "TPI", "JTAG"]:
continue # Filters out "FPGA" and other edge cases
if function_name not in c_funcs:
continue # Filter out debug Functions. Do that before mcu check, as there are over 300 MCUs and less then 50 functions
if chip_name not in mcu_list:
continue # don't handle chips avrdude doesn't know anyway
func_bytes = None
counter = 0
while True:
byte = xml_script.readline()
if (byte.startswith(" ")): # 6 spaces is already unique enough
scr_bytes_buffer[counter] = int(byte[14:16], 16) # only handle the value
counter += 1
elif (byte.startswith(" </scrbytes>")): # done with the list
func_bytes = bytes(scr_bytes_buffer[:counter]) # create an immutable bytes array
break
if func_bytes == None:
continue # continue with next chip if somethin went wrong
if function_name not in function_dict[programming_mode].keys():
function_dict[programming_mode][function_name] = []
if func_bytes not in function_dict[programming_mode][function_name]:
function_dict[programming_mode][function_name].append(func_bytes)
index = function_dict[programming_mode][function_name].index(func_bytes)
#function_dict = {
# "UPDI": {
# "EnterProgMode" : [bytes_0, bytes_1]},
# "SetSpeed" : [bytes_2, bytes_3]}
# }
#}
if chip_name not in program_iface[programming_mode]:
program_iface[programming_mode][chip_name] = [(function_name, index)]
#print("Added to " + programming_mode + ": " + chip_name)
else:
program_iface[programming_mode][chip_name].append((function_name, index))
#program_iface = {
# "UPDI": {
# "Attiny1614": [
# ("EnterProgMode", 0),
# ("ExitProgMode", 0),
# ("...", 1),
# ]
# }
#}
# /if starts with
# /while True
# /with open
print("XML File processed")
# create c-File
global common_header
c_lut_path = os.path.join(src_dir, "pickit5_updi_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(common_header)
c_file.write("#include <ac_cfg.h>\n")
c_file.write("#include <stddef.h>\n")
c_file.write("#include <string.h>\n")
c_file.write("#include \"pickit5_lut.h\"\n\n\n")
# Generate the arrays for the functions
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 += " = {" # begin array
for i in range (len(array)): # go through every byte
if (i % 16 == 0):
array_str += "\n " # new line after 16 bytes
array_str += "0x{0:02x}, ".format(array[i]) # and generate String
array_str += "\n};\n\n" # complete array
array_iterator += 1
c_file.write(array_str)
for prog_iface, prog_mcu_list in program_iface.items():
lower_prog_iface = prog_iface.lower()
c_lut_path = os.path.join(src_dir, "pickit5_lut_" + lower_prog_iface + ".c")
if (os.path.exists(c_lut_path)):
os.remove(c_lut_path)
with open(c_lut_path, 'w') as c_file:
c_file.write(common_header)
c_file.write("#include <ac_cfg.h>\n")
c_file.write("#include <stddef.h>\n")
c_file.write("#include <string.h>\n")
c_file.write("#include \"pickit5_lut.h\"\n\n\n")
if array_iterator == 1:
struct_init_func += " scr->{0} = {0}_0;\n".format(func_name)
struct_init_len += " scr->{0}_len = sizeof({0}_0);\n".format(func_name)
else:
struct_init_func += " scr->{0} = NULL;\n".format(func_name)
struct_init_len += " scr->{0}_len = 0;\n".format(func_name)
non_unique_func.append(func_name)
struct_init_func = ""
struct_init_len = ""
common_func = [] # List of Functions that exist once
for (func_name, func_array_bytes) in function_dict[prog_iface].items():
for (array_iter, func_bytes) in enumerate(func_array_bytes):
func_length = len(func_bytes)
c_file.write("const unsigned char {0}_{1}_{2}[{3}]".format(
func_name, lower_prog_iface, array_iter, func_length) + " = {")
num_line = " "
for (iter, byte) in enumerate(func_bytes): # go through every byte
if (iter % 16 == 0):
c_file.write(num_line) # new line after 16 bytes
num_line = "\n "
num_line += "0x{0:02x}, ".format(byte) # and generate String
c_file.write(num_line + "\n};\n\n") # complete array
if len(func_array_bytes) == 1: # look for common function
struct_init_func += " scr->{0} = {0}_{1}_0;\n".format(func_name, lower_prog_iface)
struct_init_len += " scr->{0}_len = sizeof({0}_{1}_0);\n".format(func_name, lower_prog_iface)
common_func.append(func_name)
#else: # is done by a memset
# struct_init_func += " scr->{0} = NULL;\n".format(func_name)
# struct_init_len += " scr->{0}_len = 0;\n".format(func_name)
# EOFL
c_file.write("\n\n\nstatic void pickit_{0}_script_init(SCRIPT *scr);\n".format(lower_prog_iface)) # declaration
c_file.write("static void pickit_{0}_script_init(SCRIPT *scr)".format(lower_prog_iface) + " {\n") # definition
c_file.write(" memset(scr, 0x00, sizeof(SCRIPT)); // Make sure everything is NULL\n\n")
c_file.write(struct_init_func)
c_file.write("\n") # improve readability
c_file.write(struct_init_len)
c_file.write("}\n\n\n")
c_file.write("const char * const pickit5_{0}_chip_lut[]".format(lower_prog_iface) + " = {")
chip_line = " "
for (iter, chip_name) in enumerate(prog_mcu_list.keys()): # go through every chip
if (iter % 8 == 0):
c_file.write(chip_line) # new line after 8 Chips
chip_line = "\n "
chip_line += "{0:>16}, ".format( '"' + chip_name + '"') # and generate String
c_file.write(chip_line + "\n};\n\n") # complete array
c_file.write("\n\n\nstatic void pickit_updi_script_init(SCRIPT *scr);\n") # declaration
c_file.write("static void pickit_updi_script_init(SCRIPT *scr) {\n") # definition
c_file.write(struct_init_func)
c_file.write("\n") # improve readability
c_file.write(struct_init_len)
c_file.write("}\n\n\n")
# Lookup Table for Chip Names
chip_lut_str = "const char * const pickit5_updi_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)
# Provide a way to get the DevID Script by NVM Version stored in SIB
devid_str = "const unsigned char * get_devid_script_by_nvm_ver(unsigned char version) {\n"
devid_str += " if (version >= '0') version -= '0'; // allow chars\n"
devid_str += " if (version > 9) return NULL; // Not a valid number\n"
devid_str += " if (version <= 3) // tiny, mega, DA, DB, DD, EA\n"
devid_str += " return GetDeviceID_0;\n"
devid_str += " else // DU, EB\n"
devid_str += " return GetDeviceID_1;\n}\n\n"
c_file.write(devid_str)
# Main Function to load the data into the structure
c_func_str = "int get_pickit_updi_script(SCRIPT *scr, const char* partdesc) { \n"
c_func_str += " if ((scr == NULL) || (partdesc == NULL))\n return -1;\n\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(pickit5_updi_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 -2;\n }\n\n"
c_func_str += " pickit_updi_script_init(scr); // load common functions\n\n"
c_file.write(c_func_str)
if (prog_iface == "UPDI"):
c_file.write("const unsigned char * get_devid_script_by_nvm_ver(unsigned char version) {\n")
c_file.write(" if (version >= '0') version -= '0'; // allow chars\n")
c_file.write(" if (version > 9) return NULL; // Not a valid number\n")
c_file.write(" if (version <= 3) // tiny, mega, DA, DB, DD, EA\n")
c_file.write(" return GetDeviceID_updi_0;\n")
c_file.write(" else // DU, EB\n")
c_file.write(" return GetDeviceID_updi_1;\n}\n\n")
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] += " scr->{0} = {0}_{1};\n".format(func_lut, chip_func[func_lut])
break_str_list[switch_iterator] += " scr->{0}_len = sizeof({0}_{1});\n".format(func_lut, chip_func[func_lut])
break_str_list[switch_iterator] += " break;\n"
switch_iterator += 1
c_file.write("int get_pickit_{0}_script(SCRIPT *scr, const char* partdesc)".format(lower_prog_iface) + " {\n")
c_file.write(" if ((scr == NULL) || (partdesc == NULL)) {\n return -1;\n }\n")
c_file.write(" int namepos = -1;\n")
c_file.write(" for (int i = 0; i < {0}; i++)".format(len(prog_mcu_list.keys())) + " {\n")
c_file.write(" if (strncmp(pickit5_{0}_chip_lut[i], partdesc, 10) == 0)".format(lower_prog_iface) + " {\n")
c_file.write(" namepos = i;\n break;\n }\n }\n")
c_file.write(" if (namepos == -1) {\n return -2;\n }\n\n")
c_file.write(" pickit_{0}_script_init(scr); // load common functions\n\n".format(lower_prog_iface))
case_list = []
case_func_list = []
#print(common_func)
c_file.write(" switch (namepos) {\n")
for (switch_iterator, (chip_name, functions)) in enumerate(prog_mcu_list.items()):
new_case = " case {0}: /* {1} */\n".format(switch_iterator, chip_name)
new_func_str = ""
for func_name, func_num in functions: # generate list of unique function assignments
if func_name in common_func:
continue # skip common functions, they were set in _init()
new_func_str += "{0}_{1}_{2}\n".format(func_name, lower_prog_iface, func_num)
if new_func_str not in case_func_list: # Check if there is an already existing function set
case_list.append(new_case)
case_func_list.append(new_func_str)
else: # if it exists, figure out the index at which to add the case
case_list[case_func_list.index(new_func_str)] += new_case
for (case_str, func_list) in zip(case_list, case_func_list):
c_file.write(case_str)
func_list = func_list.split("\n")[:-1] # Remove last Element that will be an empty string
for func in func_list:
func_name = func.split("_")[0]
c_file.write(" scr->{0} = {1};\n".format(func_name, func))
c_file.write(" scr->{0}_len = sizeof({1});\n".format(func_name, func))
c_file.write(" break;\n")
c_file.write(" }\n return 0;\n}")
# End of switch case
print("finished " + prog_iface)
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 0;\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)
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()
pass
convert_xml(xml_path, c_func_list)
quit()