Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
Includes latest Eltangas update (3/20/2022)
  • Loading branch information
Dlloydev committed Mar 22, 2022
1 parent 126220a commit 0b219a7
Show file tree
Hide file tree
Showing 15 changed files with 724 additions and 668 deletions.
34 changes: 33 additions & 1 deletion JICE_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,39 @@
namespace {
// *** Baud rate lookup table for UBRR0 register ***
// Indexed by valid values for PARAM_BAUD_RATE_VAL (defined in JTAG2.h)
FLASH<uint16_t> baud_tbl[8] = {baud_reg_val(2400), baud_reg_val(4800), baud_reg_val(9600), baud_reg_val(19200), baud_reg_val(38400), baud_reg_val(57600), baud_reg_val(115200), baud_reg_val(14400)};
FLASH<uint16_t> baud_tbl[28] = {
baud_reg_val(2400),
baud_reg_val(4800),
baud_reg_val(9600),
baud_reg_val(19200),
baud_reg_val(38400),
baud_reg_val(57600),
baud_reg_val(115200),
baud_reg_val(14400),
// Extension to jtagmkII protocol: extra baud rates, standard series.
baud_reg_val(153600),
baud_reg_val(230400),
baud_reg_val(460800),
baud_reg_val(921600),
// Extension to jtagmkII protocol: extra baud rates, binary series.
baud_reg_val(128000),
baud_reg_val(256000),
baud_reg_val(512000),
baud_reg_val(1024000),
// Extension to jtagmkII protocol: extra baud rates, decimal series.
baud_reg_val(150000),
baud_reg_val(200000),
baud_reg_val(250000),
baud_reg_val(300000),
baud_reg_val(400000),
baud_reg_val(500000),
baud_reg_val(600000),
baud_reg_val(666666),
baud_reg_val(1000000),
baud_reg_val(1500000),
baud_reg_val(2000000),
baud_reg_val(3000000)
};
}

// Functions
Expand Down
2 changes: 1 addition & 1 deletion JICE_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Created: 18-11-2017 14:55:53
* Author: JMR_2
*/
*/


#ifndef JICE_IO_H_
Expand Down
4 changes: 2 additions & 2 deletions JTAG2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void JTAG2::set_status(uint8_t status_code) {
void JTAG2::sign_on() {
// Initialize JTAGICE2 variables
JTAG2::PARAM_EMU_MODE_VAL = 0x02;
JTAG2::PARAM_BAUD_RATE_VAL = JTAG2::baud_19200;
JTAG2::PARAM_BAUD_RATE_VAL = JTAG2::BAUD_19200;
// Send sign on message
packet.size_word[0] = sizeof(sgn_resp);
for (uint8_t i = 0; i < sizeof(sgn_resp); i++) {
Expand Down Expand Up @@ -151,7 +151,7 @@ void JTAG2::set_parameter() {
break;
case PARAM_BAUD_RATE:
// check if baud rate parameter is valid
if ((param_val >= baud_2400) && (param_val <= baud_14400)) {
if ((param_val >= BAUD_LOWER) && (param_val <= BAUD_UPPER)) {
PARAM_BAUD_RATE_VAL = (baud_rate)param_val;
break;
}
Expand Down
164 changes: 95 additions & 69 deletions JTAG2.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,94 +15,120 @@ namespace JTAG2 {

// *** Parameter IDs ***
enum parameter {
PARAM_HW_VER = 0x01,
PARAM_FW_VER = 0x02,
PARAM_EMU_MODE = 0x03,
PARAM_BAUD_RATE = 0x05,
PARAM_VTARGET = 0x06
PARAM_HW_VER = 0x01,
PARAM_FW_VER = 0x02,
PARAM_EMU_MODE = 0x03,
PARAM_BAUD_RATE = 0x05,
PARAM_VTARGET = 0x06
};

// *** valid values for PARAM_BAUD_RATE_VAL
enum baud_rate {
baud_2400 = 0x01,
baud_4800,
baud_9600,
baud_19200, // default
baud_38400,
baud_57600,
baud_115200,
baud_14400
BAUD_2400 = 0x01,
BAUD_4800,
BAUD_9600,
BAUD_19200, // default
BAUD_38400,
BAUD_57600,
BAUD_115200,
BAUD_14400,
// Extension to jtagmkII protocol: extra baud rates, standard series.
BAUD_153600,
BAUD_230400,
BAUD_460800,
BAUD_921600,
// Extension to jtagmkII protocol: extra baud rates, binary series.
BAUD_128000,
BAUD_256000,
BAUD_512000,
BAUD_1024000,
// Extension to jtagmkII protocol: extra baud rates, decimal series.
BAUD_150000,
BAUD_200000,
BAUD_250000,
BAUD_300000,
BAUD_400000,
BAUD_500000,
BAUD_600000,
BAUD_666666,
BAUD_1000000,
BAUD_1500000,
BAUD_2000000,
BAUD_3000000,

BAUD_LOWER = BAUD_2400,
BAUD_UPPER = BAUD_3000000
};

// *** Parameter Values ***
constexpr uint8_t PARAM_HW_VER_M_VAL = 0x01;
constexpr uint8_t PARAM_HW_VER_S_VAL = 0x01;
constexpr uint8_t PARAM_FW_VER_M_MIN_VAL = 0x00;
constexpr uint8_t PARAM_FW_VER_M_MAJ_VAL = 0x06;
constexpr uint8_t PARAM_FW_VER_S_MIN_VAL = 0x00;
constexpr uint8_t PARAM_FW_VER_S_MAJ_VAL = 0x06;
constexpr uint8_t PARAM_HW_VER_M_VAL = 0x01;
constexpr uint8_t PARAM_HW_VER_S_VAL = 0x01;
constexpr uint8_t PARAM_FW_VER_M_MIN_VAL = 0x00;
constexpr uint8_t PARAM_FW_VER_M_MAJ_VAL = 0x06;
constexpr uint8_t PARAM_FW_VER_S_MIN_VAL = 0x00;
constexpr uint8_t PARAM_FW_VER_S_MAJ_VAL = 0x06;
extern uint8_t PARAM_EMU_MODE_VAL;
extern uint8_t ConnectedTo;
extern baud_rate PARAM_BAUD_RATE_VAL;
constexpr uint16_t PARAM_VTARGET_VAL = 5000;
constexpr uint16_t PARAM_VTARGET_VAL = 5000;

// *** General command constants ***
enum cmnd {
CMND_SIGN_OFF = 0x00,
CMND_GET_SIGN_ON = 0x01,
CMND_SET_PARAMETER = 0x02,
CMND_GET_PARAMETER = 0x03,
CMND_WRITE_MEMORY = 0x04,
CMND_READ_MEMORY = 0x05,
CMND_GO = 0x08,
CMND_RESET = 0x0b,
CMND_SET_DEVICE_DESCRIPTOR = 0x0c,
CMND_GET_SYNC = 0x0f,
CMND_ENTER_PROGMODE = 0x14,
CMND_LEAVE_PROGMODE = 0x15,
CMND_XMEGA_ERASE = 0x34
CMND_SIGN_OFF = 0x00,
CMND_GET_SIGN_ON = 0x01,
CMND_SET_PARAMETER = 0x02,
CMND_GET_PARAMETER = 0x03,
CMND_WRITE_MEMORY = 0x04,
CMND_READ_MEMORY = 0x05,
CMND_GO = 0x08,
CMND_RESET = 0x0b,
CMND_SET_DEVICE_DESCRIPTOR = 0x0c,
CMND_GET_SYNC = 0x0f,
CMND_ENTER_PROGMODE = 0x14,
CMND_LEAVE_PROGMODE = 0x15,
CMND_XMEGA_ERASE = 0x34
};
// *** JTAG Mk2 Single byte status responses ***
enum response {
// Success
RSP_OK = 0x80,
RSP_PARAMETER = 0x81,
RSP_MEMORY = 0x82,
RSP_SIGN_ON = 0x86,
RSP_OK = 0x80,
RSP_PARAMETER = 0x81,
RSP_MEMORY = 0x82,
RSP_SIGN_ON = 0x86,
// Error
RSP_FAILED = 0xA0,
RSP_ILLEGAL_PARAMETER = 0xA1,
RSP_ILLEGAL_MEMORY_TYPE = 0xA2,
RSP_ILLEGAL_MEMORY_RANGE = 0xA3,
RSP_ILLEGAL_MCU_STATE = 0xA5,
RSP_ILLEGAL_VALUE = 0xA6,
RSP_ILLEGAL_BREAKPOINT = 0xA8,
RSP_ILLEGAL_JTAG_ID = 0xA9,
RSP_ILLEGAL_COMMAND = 0xAA,
RSP_NO_TARGET_POWER = 0xAB,
RSP_DEBUGWIRE_SYNC_FAILED = 0xAC,
RSP_ILLEGAL_POWER_STATE = 0xAD
RSP_FAILED = 0xA0,
RSP_ILLEGAL_PARAMETER = 0xA1,
RSP_ILLEGAL_MEMORY_TYPE = 0xA2,
RSP_ILLEGAL_MEMORY_RANGE = 0xA3,
RSP_ILLEGAL_MCU_STATE = 0xA5,
RSP_ILLEGAL_VALUE = 0xA6,
RSP_ILLEGAL_BREAKPOINT = 0xA8,
RSP_ILLEGAL_JTAG_ID = 0xA9,
RSP_ILLEGAL_COMMAND = 0xAA,
RSP_NO_TARGET_POWER = 0xAB,
RSP_DEBUGWIRE_SYNC_FAILED = 0xAC,
RSP_ILLEGAL_POWER_STATE = 0xAD
};

// *** memory types for CMND_{READ,WRITE}_MEMORY ***
enum mem_type {
MTYPE_IO_SHADOW = 0x30, // cached IO registers?
MTYPE_SRAM = 0x20, // target's SRAM or [ext.] IO registers
MTYPE_EEPROM = 0x22, // EEPROM, what way?
MTYPE_EVENT = 0x60, // ICE event memory
MTYPE_SPM = 0xA0, // flash through LPM/SPM
MTYPE_FLASH_PAGE = 0xB0, // flash in programming mode
MTYPE_EEPROM_PAGE = 0xB1, // EEPROM in programming mode
MTYPE_FUSE_BITS = 0xB2, // fuse bits in programming mode
MTYPE_LOCK_BITS = 0xB3, // lock bits in programming mode
MTYPE_SIGN_JTAG = 0xB4, // signature in programming mode
MTYPE_OSCCAL_BYTE = 0xB5, // osccal cells in programming mode
MTYPE_CAN = 0xB6, // CAN mailbox
MTYPE_FLASH = 0xc0, // xmega (app.) flash
MTYPE_BOOT_FLASH = 0xc1, // xmega boot flash
MTYPE_EEPROM_XMEGA = 0xc4, // xmega EEPROM in debug mode
MTYPE_USERSIG = 0xc5, // xmega user signature
MTYPE_PRODSIG = 0xc6 // xmega production signature
MTYPE_IO_SHADOW = 0x30, // cached IO registers?
MTYPE_SRAM = 0x20, // target's SRAM or [ext.] IO registers
MTYPE_EEPROM = 0x22, // EEPROM, what way?
MTYPE_EVENT = 0x60, // ICE event memory
MTYPE_SPM = 0xA0, // flash through LPM/SPM
MTYPE_FLASH_PAGE = 0xB0, // flash in programming mode
MTYPE_EEPROM_PAGE = 0xB1, // EEPROM in programming mode
MTYPE_FUSE_BITS = 0xB2, // fuse bits in programming mode
MTYPE_LOCK_BITS = 0xB3, // lock bits in programming mode
MTYPE_SIGN_JTAG = 0xB4, // signature in programming mode
MTYPE_OSCCAL_BYTE = 0xB5, // osccal cells in programming mode
MTYPE_CAN = 0xB6, // CAN mailbox
MTYPE_FLASH = 0xc0, // xmega (app.) flash
MTYPE_BOOT_FLASH = 0xc1, // xmega boot flash
MTYPE_EEPROM_XMEGA = 0xc4, // xmega EEPROM in debug mode
MTYPE_USERSIG = 0xc5, // xmega user signature
MTYPE_PRODSIG = 0xc6 // xmega production signature
};

// *** erase modes for CMND_XMEGA_ERASE ***
Expand All @@ -115,11 +141,11 @@ namespace JTAG2 {
XMEGA_ERASE_BOOT_PAGE,
XMEGA_ERASE_EEPROM_PAGE,
XMEGA_ERASE_USERSIG
};
};

// *** STK500 packet ***
constexpr uint8_t MESSAGE_START = 0x1B;
constexpr int MAX_BODY_SIZE = 700; // Note: should not be reduced to less than 300 bytes.
constexpr int MAX_BODY_SIZE = 700; // Note: should not be reduced to less than 300 bytes.
union packet_t {
uint8_t raw[6 + MAX_BODY_SIZE];
struct {
Expand Down Expand Up @@ -166,4 +192,4 @@ namespace JTAG2 {



#endif /* STK_H_ */
#endif /* STK_H_ */
32 changes: 16 additions & 16 deletions NVM.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Created: 15-12-2017 10:59:53
* Author: JMR_2
*/
*/


#ifndef NVM_H_
Expand All @@ -15,13 +15,13 @@
namespace NVM {
// *** Base Addresses ***
enum base {
NVM_base = 0x1000, /* Base address of the NVM controller */
Sig_base = 0x1100, /* Base address of the signature */
Fuse_base = 0x1280, /* Base address of the fuses */
User_base = 0x1300, /* Base address of the User Row EEPROM */
EEPROM_base = 0x1400 /* Base address of the main EEPROM */
NVM_base = 0x1000, /* Base address of the NVM controller */
Sig_base = 0x1100, /* Base address of the signature */
Fuse_base = 0x1280, /* Base address of the fuses */
User_base = 0x1300, /* Base address of the User Row EEPROM */
EEPROM_base = 0x1400 /* Base address of the main EEPROM */
};

// *** NVM Registers (offsets from NVN_base are enum default values) ***
enum reg {
CTRLA,
Expand All @@ -35,17 +35,17 @@ namespace NVM {
ADDR_lo,
ADDR_hi
};

// *** NVM Commands (write to CTRLA to execute) ***
enum cmnd {
NOP, /* Does nothing */
WP, /* Write page buffer to memory */
ER, /* Erase page */
ERWP, /* Erase and write page */
PBC, /* Page buffer clear */
CHER, /* Chip erase: erase Flash and EEPROM */
EEER, /* EEPROM Erase */
WFU /* Write fuse */
NOP, /* Does nothing */
WP, /* Write page buffer to memory */
ER, /* Erase page */
ERWP, /* Erase and write page */
PBC, /* Page buffer clear */
CHER, /* Chip erase: erase Flash and EEPROM */
EEER, /* EEPROM Erase */
WFU /* Write fuse */
};

// *** NVM Functions ***
Expand Down
2 changes: 1 addition & 1 deletion crc16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Created: 16-01-2018 23:06:40
* Author: JMR_2
*/
*/

#include "crc16.h"
#include "sys.h"
Expand Down
8 changes: 4 additions & 4 deletions crc16.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Created: 16-01-2018 23:07:05
* Author: JMR_2
*/
*/


#ifndef CRC16_H_
Expand All @@ -12,15 +12,15 @@
#include <stdint.h>

namespace CRC {
uint16_t next (uint8_t newchar, uint16_t previous = 0xFFFF); // 'previous' defaults to CRC seed value, 0xFFFF
uint16_t next (uint8_t newchar, uint16_t previous = 0xFFFF); // 'previous' defaults to CRC seed value, 0xFFFF

typedef union {
uint16_t word;
struct {
uint8_t low;
uint8_t low;
uint8_t high;
} byte;
} split_word;
} split_word;
}

#endif /* CRC16_H_ */
Loading

0 comments on commit 0b219a7

Please sign in to comment.