• Special Characters and Packet Formats for Packet Synchronization and
Error Control
• Break Point Handling in JTAGICE mkII (tinyAVR / megaAVR devices only)
1 Introduction
This document describes the communication protocol used between AVR Studio
and JTAGICE mkII. The purpose of this document is to enable third party vendors
to design their own front-end to the JTAGICE mkII.
8-bit
Microcontrollers
Application Note
Rev. 2587D-AVR-11/09
http://www.BDTIC.com/ATMEL
2 Theory of operation
The communication protocol operates in a master – slave environment, AVR Studio
being the master and JTAGICE mkII being the slave.
The JTAGICE mkII slave is always operating in one of three states (with
enumeration):
1. STOPPED
2. RUNNING
3. PROGRAMMING
Some commands can only be executed while the slave is in STOPPED mode, others
may be allowed in all modes. The details are described for each different command.
Events are messages sent from the slave with no prior commands given from the
master.
Serial communication is asynchronous by nature, so is the JTAGICE mkII protocol. All
commands and responses have tokens and CRC checks included enabling the
receiver to verify the validity of the received message.
This transport protocol guarantees that every packet that is received is verified
correctly, but it does not guarantee that every packet is received. Retransmission and
lost packets are to be handled by the application layer, not the transmission layer.
When USB is used, the hardware layer handles retransmission automatically. This is
not the case with RS232.
The protocol is “Little Endean”, LSB is always transferred first in memory addresses.
2.1 USB and RS-232 Connection
The JTAGICE mkII has both a USB and an RS-232 interface for connecting to a host
computer. They share the same message format (see section 3).
USB is preferred due to speed.
2.1.1 RS-232 Connection
The RS-232 connection’s power-on settings are 19,200 bps, 8N1, no handshake.
However, using the Set Parameter command and the Baud rate parameter, the baud
rate can be changed.
2.1.2 USB Connection
The JTAGICE mkII has a USB port capable of USB full-speed connection (12Mbps).
In addition to data transfer, the USB cable can also supply power to the emulator, so
no external power is required. After enumeration, the emulator can draw up to 500mA
from the USB hub.
2.1.3 USB Configuration
The JTAGICE mkII has one configuration with one interface containing two bulk
transfer endpoints. The USB descriptors can be found in section 7.
The JTAGICE mkII messages are transferred through the bulk endpoints. Maximum
packet size is shown in the endpoint descriptors.
2
AVR067
2587D-AVR-11/09
3 Message Format
http://www.BDTIC.com/ATMEL
In addition to the framing mechanisms supplied by the JTAGICE mkII frame format,
the emulator uses short packets (both IN and OUT endpoints) to indicate which USB
packet is the last one in a JTAGEICE mkII frame. The host driver must also support
short packets.
All commands, responses and events share a common message format:
<MESSAGE_START, SEQUENCE_NUMBER, MESSAGE_SIZE, TOKEN,
MESSAGE_SIZE Size of the message body in bytes [BYTE]*4, LSB first
TOKEN
MESSAGE_BODY Message body [BYTE]*MESSAGE_SIZE
CRC
First byte of the message body is always the MESSAGE_ID. The size of the
MESSAGE_BODY is at least 1 byte.
Incremented by one for each
message sent. Wraps to zero after
0xFFFE. 0xFFFF is reserved for
(asynchronous) EVENTS.
ASCII 14, making the protocol more
robust.
Uses all characters in message
including MESSAGE_START and
MESSAGE_BODY.
[BYTE]*2, LSB first.
[BYTE]
[BYTE]*2
AVR067
4 Message parsing
4.1 Introduction
2587D-AVR-11/09
• Messages use MESSAGE_ID in the range from 0x01 to 0x3F
• Success responses use MESSAGE_ID in the range from 0x80 to 0x9F
• Failure responses use MESSAGE_ID in the range from 0xA0 to 0xBF
• Events use MESSAGE_ID in the range from 0xE0 to 0xFF
• Message start is ASCII 27 (0x1B), not to be changed.
• Token is ASCII 14 (0x0E), not to be changed.
Messages either way should be read as a byte stream by a state machine. Every time
a MESSAGE_START character occurs, the state machine starts to decode the
message, either completing the message or falling out of the byte stream if a
message rule is violated.
Messages can come in any order and there is no specific timing regarding required
timeframes between commands. The emulator implements a message queue, when
the state machine has parsed and verified a complete message it is serialized and put
on a message queue. The emulator executes the messages in the sequence found
3
http://www.BDTIC.com/ATMEL
on the queue. Responses to the messages are given when they are processed by the
emulator.
The same state machine is used for both RS232 and USB transmission. An interrupt
routine on the communication control processor in the JTAGICE mkII reads the
appropriate UART and puts the incoming data in a FIFO implemented in SRAM. The
state machine reads and parses the data from the FIFO.
The emulator hosts a number of set-up parameters. This command is used to write all
parameters. The parameter ID identifies the parameter written.
Slave state: Depending on the parameter.
Table 5-7. Message Format.
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Incremented for each packet sent.
MESSAGE_SIZE The size of the MESSAGE_BODY in bytes.
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
The message body consists of:
<MESSAGE_ID, PARAMETER_ID, PARAMETER_VALUE>
Table 5-8. Parameters.
Parameter Name Usage Format
MESSAGE_ID 0x02 (CMND_SET_PARAMETER) [BYTE]
PARAMETER_ID Parameter ID [BYTE]
PARAMETER_VALUE Parameter value, can be of any size
[BYTE] * N,
LSB first if
applicable.
Table 5-9. Response.
Parameter Name Description
RSP_OK The parameter is written OK.
RSP_FAILED
RSP_ILLEGAL_PARAMETER
RSP_ILLEGAL_VALUE The given value was invalid or out or range
RSP_ILLEGAL_EMULATOR_MODE
Timeout No response from the slave within the timeout time.
The command was not understood by the JTAGICE
mkII
The JTAGICE mkII does not support the selected
parameter (AVR Studio 4 – JTAGICE mkII FW
incompatibility).
The operation cannot be performed in this emulator
mode. (JTAG / debugWire).
The parameter description is found in a later section in this document.
0x02: HIGH LEVEL
(stops at next high level statement)
Table 5-33. Response.
Parameter Name Description
RSP_OK The command is executed.
RSP_FAILED
RSP_ILLEGAL_EMULATOR_MODE
Timeout No response from the slave within the timeout time.
The command was not understood by the JTAGICE
mkII
The operation cannot be performed in this emulator
mode. (JTAG / debugWire).
[BYTE]
5.1.12 Reset User Program (CMND_RESET: 0x0B)
Emulator performs all actions to restart program execution
Slave state: Any. If the slave is in RUNNING mode prior to this operation, the slave
will change to STOPPED state prior to the execution of this command
Table 5-34. Message Format.
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Incremented for each packet sent.
MESSAGE_SIZE Size of message body
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
High level or low level flag. High level typically
returns to main. Give a procedure. Give low level
reset with “run afterwards”.
16
AVR067
2587D-AVR-11/09
http://www.BDTIC.com/ATMEL
AVR067
The MESSAGE_BODY consists of:
<MESSAGE_ID, FLAG>
Table 5-35. Parameters.
Parameter Name Usage Format
MESSAGE_ID 0x0B (CMND_RESET) [BYTE]
FLAG 0x01: Low level
0x02: High level (reset, then run to
main)
0x04: Reset with debugWire
disable.
[BYTE]
Table 5-36. Response.
Parameter Name Description
RSP_OK The command is executed.
RSP_FAILED
RSP_ILLEGAL_EMULATOR_MODE
Timeout No response from the slave within the timeout time.
The command was not understood by the JTAGICE
mkII
The operation cannot be performed in this emulator
mode. (JTAG / debugWire).
5.1.13 Set Device Descriptor (CMND_SET_DEVICE_DESCRIPTOR: 0x0C)
Transmits all parameters relevant for a specific device set-up
Slave state: STOPPED.
Table 5-37. Message Format.
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Incremented for each packet sent.
MESSAGE_SIZE Size of message body
TOKEN ASCII 14
MESSAGE_BODY All parameters for a specific device set-up.
CRC 2-byte CRC.
The MESSAGE_BODY consists of:
<MESSAGE_ID, PARAMETERS>
Table 5-38. Parameters.
Parameter Name Usage Format
MESSAGE_ID
0x0C
(CMND_SET_DEVICE_DESCRIPTOR)
[BYTE]
2587D-AVR-11/09
17
http://www.BDTIC.com/ATMEL
Parameter Name Usage Format
PARAMETERS
Table 5-39. Response.
Parameter Name Description
RSP_OK The command is executed.
RSP_FAILED
RSP_ILLEGAL_EMULATOR_MODE
RSP_ILLEGAL_MCU_STATE
Timeout No response from the slave within the timeout time.
5.1.14 Erase Page SPM (CMND_ERASEPAGE_SPM: 0x0D)
Erases a whole page in Flash memory
All parameters required to set up a
device in raw binary form, identical to the
JTAGICE descriptor.
The command was not understood by the JTAGICE
mkII
The operation cannot be performed in this emulator
mode. (JTAG / debugWire).
The operation cannot be performed with the target
MCU in its current state.
[BYTE] *
298
Slave state: STOPPED
Table 5-40. Message Format.
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
MESSAGE_ID 0x0D (CMND_ERASEPAGE_SPM)
SEQUENCE_NUMBER Incremented for each packet sent.
MESSAGE_SIZE 5
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
The MESSAGE_BODY consists of:
<MESSAGE_ID, PAGE_ADDRESS>
Table 5-41. Parameters.
Parameter Name Usage Format
MESSAGE_ID
PAGE_ADDRESS Address to the page to be erased
0x0D
(CMND_ERASEPAGE_SPM)
[BYTE]
[BYTE]*4, LSB
first
Table 5-42. Response.
Parameter Name Description
18
AVR067
2587D-AVR-11/09
Parameter Name Description
http://www.BDTIC.com/ATMEL
RSP_OK The command is executed.
RSP_FAILED
RSP_ILLEGAL_EMULATOR_MODE
RSP_ILLEGAL_MCU_STATE
Timeout No response from the slave within the timeout time.
5.1.15 Get Sync (CMND_GET_SYNC 0x0F)
Sent from AVR Studio in order to regain synchronization with JTAGICE mkII, if lost
Table 5-43. Message Format.
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Incremented for each packet sent.
MESSAGE_SIZE 1
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
The command was not understood by the JTAGICE
mkII
The operation cannot be performed in this emulator
mode. (JTAG / debugWire).
The operation cannot be performed with the target
MCU in its current state.
AVR067
The MESSAGE_BODY consists of:
<MESSAGE_ID>
Table 5-44. Parameters.
Parameter Name Usage Format
MESSAGE_ID 0x0F (CMND_GET_SYNC) [BYTE]
Table 5-45. Response.
Parameter Name Description
RSP_OK The command is executed.
RSP_FAILED
Timeout No response from the slave within the timeout time.
5.1.16 Self test (CMND_SELFTEST: 0x10)
Makes the JTAGICE mkII perform self test and report back to the master.
Slave state: STOPPED
Table 5-46. Message Format.
Parameter Name Description
The command was not understood by the JTAGICE
mkII.
2587D-AVR-11/09
19
http://www.BDTIC.com/ATMEL
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character).
SEQUENCE_NUMBER Incremented for each packet sent.
MESSAGE_SIZE Size of message body.
TOKEN ASCII 14
MESSAGE_BODY Parameters for self test (choose what to test).
CRC 2-byte CRC.
The MESSAGE_BODY consists of:
<MESSAGE_ID, FLAGS>
Table 5-47. Parameters.
Parameter Name Usage Format
MESSAGE_ID 0x10 (CMND_SELFTEST) [BYTE]
FLAGS
FLAGS identifying which tests to be
performed.
bit 7: internal tests (SRAM, FIFO…)
bit 6: <not used>
bit 5: <not used>
bit 4: <not used>
bit 3: STK500 RESET JUMPER
detector
bit 2: JTAG PUSH PULL
bit 1: debugWire Capacitance
bit 0: debugWire PUSH PULL
[BYTE]
Table 5-48. Response.
Parameter Name Description
RSP_SELFTEST The command is executed.
RSP_FAILED
RSP_ILLEGAL_EMULATOR_MODE
RSP_ILLEGAL_MCU_STATE
Timeout No response from the slave within the timeout time.
5.1.17 Set Breakpoint (CMND_SET_BREAK: 0x11)
Set a breakpoint. (For hardware breakpoints on megaAVR devices with JTAG
interface only, and software breakpoints)
Slave state: STOPPED
20
AVR067
Selftest (RSP_SELFTEST : 0x85)
The command was not understood by the JTAGICE
mkII.
The operation cannot be performed in this emulator
mode. (JTAG / debugWire).
The operation cannot be performed with the target
MCU in its current state.
2587D-AVR-11/09
http://www.BDTIC.com/ATMEL
AVR067
Table 5-49. Message Format.
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Incremented for each packet sent.
MESSAGE_SIZE Size of message body
TOKEN ASCII 14
MESSAGE_BODY Breakpoint setting (see format below).
CRC 2-byte CRC.
The MESSAGE_BODY consists of:
<MESSAGE_ID, TYPE, NUMBER, ADDRESS, MODE>
Table 5-50. Parameters.
Parameter Name Usage Format
MESSAGE_ID 0x11 (CMND_SET_BREAK) [BYTE]
TYPE 0x01: program memory breakpoint
0x02: data breakpoint
0x03:mask for data breakpoint
NUMBER
ADDRESS Break address of mask value
MODE 0x00: Break on memory read
Breakpoint number, 0x01 to 0x04
(up to 4 breakpoints are supported
0x00 for SW BP
0x01: Break on memory write
0x02: Break on memory read or
write.
0x03: Program breakpoint
[BYTE]
[BYTE]
[BYTE] * 4,
LSB first
[BYTE]
2587D-AVR-11/09
21
http://www.BDTIC.com/ATMEL
Table 5-51. Response.
Parameter Name Description
RSP_OK The command is executed.
RSP_FAILED
RSP_ILLEGAL_BREAKPOINT The breakpoint number does not exist.
RSP_ILLEGAL_EMULATOR_MODE
RSP_ILLEGAL_MCU_STATE
RSP_ILLEGAL_BREAKPOINT
Timeout No response from the slave within the timeout time.
5.1.18 Get Breakpoint (CMND_GET_BREAK: 0x12)
Used by the host to read back the current breakpoint setting in the JTAGICE mkII.
(For hardware breakpoints on megaAVR devices with JTAG interface only, and
software breakpoints)
The command was not understood by the JTAGICE
mkII.
Illegal breakpoint (RSP_ILLEGAL_BREAKPOINT:
0xA8)
The operation cannot be performed in this emulator
mode. (JTAG / debugWire).
The operation cannot be performed with the target
MCU in its current state.
The breakpoint number is not supported (in this
mode)
Slave state: STOPPED
Table 5-52. Message Format.
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Incremented for each packet sent.
MESSAGE_SIZE 2
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
The MESSAGE_BODY consists of:
<MESSAGE_ID, NUMBER>
Table 5-53. Parameters.
Parameter Name Usage Format
MESSAGE_ID 0x12 (CMND_GET_BREAK) [BYTE]
NUMBER
Breakpoint number, 0x01 to 0x04
(up to 4 breakpoints are supported
[BYTE]
Table 5-54. Response.
Parameter Name Description
22
AVR067
2587D-AVR-11/09
Parameter Name Description
http://www.BDTIC.com/ATMEL
RSP_GET_BREAK The command is executed, breakpoint returned.
RSP_FAILED
RSP_ILLEGAL_EMULATOR_MODE
RSP_ILLEGAL_MCU_STATE
RSP_ILLEGAL_BREAKPOINT
Timeout No response from the slave within the timeout time.
5.1.19 Chip erase (CMD_CHIP_ERASE: 0x13)
Used in order to do a complete chip erase. (megaAVR devices with JTAG interface
only. Devices with debugWire interface automatically erase flash pages before
programming. XMEGA devices use dedicated XMEGA Erase function, detailed later
in this document. )
Breakpoint read (RSP_GET_BREAK: 0x83)
The command was not understood by the JTAGICE
mkII
The operation cannot be performed in this emulator
mode. (JTAG / debugWire).
The operation cannot be performed with the target
MCU in its current state.
The breakpoint number is not supported (in this
mode)
AVR067
Table 5-55. Message Format.
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Incremented for each packet sent.
MESSAGE_SIZE 1
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
The MESSAGE_BODY consists of:
<MESSAGE_ID>
Table 5-56. Parameters.
Parameter Name Usage Format
MESSAGE_ID 0x13 (CMD_CHIP_ERASE) [BYTE]
Table 5-57. Response.
Parameter Name Description
RSP_OK The command is executed.
RSP_FAILED
RSP_ILLEGAL_EMULATOR_MODE
The command was not understood by the JTAGICE
mkII
The operation cannot be performed in this emulator
mode. (JTAG / debugWire).
2587D-AVR-11/09
23
http://www.BDTIC.com/ATMEL
Parameter Name Description
RSP_ILLEGAL_MCU_STATE
Timeout No response from the slave within the timeout time.
5.1.20 Enter programming mode (CMND_ENTER_PROGMODE: 0x14)
Enter programming mode.
Table 5-58. Message Format.
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Incremented for each packet sent.
MESSAGE_SIZE 1
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
The MESSAGE_BODY consists of:
The operation cannot be performed with the target
MCU in its current state.
<MESSAGE_ID>
Table 5-59. Parameters.
Parameter Name Usage Format
MESSAGE_ID
0x14
(CMND_ENTER_PROGMODE)
[BYTE]
Table 5-60. Response.
Parameter Name Description
RSP_OK The command is executed.
RSP_FAILED
RSP_ILLEGAL_JTAG_ID
RSP_ILLEGAL_EMULATOR_MODE
RSP_ILLEGAL_MCU_STATE
Timeout No response from the slave within the timeout time.
The command was not understood by the JTAGICE
mkII
The JTAG ID does not match the target device’s.
Illegal JTAG ID (RSP_ILLEGAL_JTAG_ID : 0xA9)
The operation cannot be performed in this emulator
mode. (JTAG / debugWire).
The operation cannot be performed with the target
MCU in its current state.
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Incremented for each packet sent.
MESSAGE_SIZE 1
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
The MESSAGE_BODY consists of:
<MESSAGE_ID>
Table 5-62. Parameters.
Parameter Name Usage Format
MESSAGE_ID
0x15
(CMND_LEAVE_PROGMODE)
[BYTE]
Table 5-63. Response.
Parameter Name Description
RSP_OK The command is executed.
RSP_FAILED
RSP_ILLEGAL_EMULATOR_MODE
RSP_ILLEGAL_MCU_STATE
Timeout No response from the slave within the timeout time.
5.1.22 Clear Breakpoint (CMND_CLR_BREAK: 0x1A)
Clear a breakpoint. (For hardware breakpoints on megaAVR devices with JTAG
interface only, and software breakpoints)
Slave state: STOPPED
Table 5-64. Message Format.
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Incremented for each packet sent.
MESSAGE_SIZE Size of message body
TOKEN ASCII 14
MESSAGE_BODY Breakpoint setting (see format below).
The command was not understood by the JTAGICE
mkII
The operation cannot be performed in this emulator
mode. (JTAG / debugWire).
The operation cannot be performed with the target
MCU in its current state.
2587D-AVR-11/09
25
http://www.BDTIC.com/ATMEL
Parameter Name Description
CRC 2-byte CRC.
The MESSAGE_BODY consists of:
<MESSAGE_ID, NUMBER, ADDRESS >
Table 5-65. Parameters.
Parameter Name Usage Format
MESSAGE_ID 0x1A (CMND_CLR_BREAK) [BYTE]
NUMBER
ADDRESS Break address (for SW BP)
Table 5-66. Response.
Parameter Name Description
RSP_OK The command is executed.
RSP_FAILED
RSP_ILLEGAL_BREAKPOINT The breakpoint number does not exist.
RSP_ILLEGAL_EMULATOR_MODE
RSP_ILLEGAL_MCU_STATE
RSP_ILLEGAL_BREAKPOINT
Timeout No response from the slave within the timeout time.
Breakpoint number, 0x01 to 0x04
(up to 4 breakpoints are supported
The command was not understood by the JTAGICE
mkII
Instructs the JTAGICE mkII to clear its event memory (for SW breakpoints). Must be
called AFTER setting the device descriptor to ensure that only the required amount of
event memory is cleared.
Table 5-73. Message Format.
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Incremented for each packet sent.
MESSAGE_SIZE 1
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
The command was not understood by the JTAGICE
mkII
The operation cannot be performed in this emulator
mode. (Must be in SPI mode).
28
AVR067
The MESSAGE_BODY consists of:
<MESSAGE_ID >
Table 5-74. Parameters.
Parameter Name Usage Format
MESSAGE_ID 0x22 (CMND_CLEAR_EVENTS) [BYTE]
Table 5-75. Response.
Parameter Name Description
RSP_OK The command is executed.
RSP_FAILED
RSP_ILLEGAL_MCU_STATE
Timeout No response from the slave within the timeout time.
The command was not understood by the JTAGICE
mkII
The operation cannot be performed with the target
MCU in its current state.
2587D-AVR-11/09
5.1.26 Restore target (CMND_RESTORE_TARGET: 0x23)
http://www.BDTIC.com/ATMEL
Instructs the JTAGICE mkII to restore the target device into a state where it can run
freely. This is to be done upon terminating a debug session, before signing off and
before disabling the OCD fuse (for JTAG). The command does the following:
• Stop target
• Replaces SW breakpoints with original instructions
• Reset target
• Run target
Table 5-76. Message Format.
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Incremented for each packet sent.
MESSAGE_SIZE 1
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
AVR067
The MESSAGE_BODY consists of:
<MESSAGE_ID >
Table 5-77. Parameters.
Parameter Name Usage Format
MESSAGE_ID
Table 5-78. Response.
Parameter Name Description
RSP_OK The command is executed.
RSP_FAILED
RSP_ILLEGAL_MCU_STATE
Timeout No response from the slave within the timeout time.
Used to send any ISP programming commands to the JTAGICE mkII. An ISP packet
compatible with the AVRISP mkII is encapsulated in a JTAGICE mkII packet. The
JTAGICE mkII then operates on the ISP packet in the same way as the AVRISP mkII.
Table 5-170 shows the ISP commands, which are supported on the JTAGICE mkII
0x23
(CMND_RESTORE_TARGET)
The command was not understood by the JTAGICE
mkII
The operation cannot be performed with the target
MCU in its current state.
[BYTE]
For further information regarding the ISP commands, consult document AVR069:
AVRISP mkII Communication Protocol.
2587D-AVR-11/09
29
http://www.BDTIC.com/ATMEL
Table 5-79. Message Format.
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Incremented for each packet sent.
MESSAGE_SIZE Size of message body
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
The MESSAGE_BODY consists of:
<MESSAGE_ID, ISP_PACKET>
Table 5-80. Parameters.
Parameter Name Usage Format
MESSAGE_ID 0x2F (CMND_ISP_PACKET) [BYTE]
ISP_PACKET Encapsulated AVRISP data [BYTE] * n
Table 5-81. Response.
Parameter Name Description
RSP_OK The command is executed.
RSP_FAILED
RSP_ILLEGAL_MCU_STATE
Timeout No response from the slave within the timeout time.
The command was not understood by the JTAGICE
mkII
The operation cannot be performed with the target
MCU in its current state.
Table 5-170. Supported AVRISP mkII commands on the JTAGICE mkII
Command Usage
CMD_SET_PARAMETER Sets a parameter
CMD_GET_PARAMETER Reads back a parameter value
CMD_OSCCAL Performs OSCCAL calibration sequence
CMD_LOAD_ADDRESS Loads an address for programming functions
CMD_ENTER_PROGMODE_ISP Puts the target device into programming mode
CMD_LEAVE_PROGMODE_ISP Target device leaves programming mode
CMD_CHIP_ERASE_ISP Perform a chip erase on the target device
CMD_PROGRAM_FLASH_ISP Programs the flash memory on the target device
CMD_READ_FLASH_ISP Reads the flash memory on the target device
CMD_PROGRAM_EEPROM_ISP Programs the EEPROM on the target device
CMD_READ_EEPROM_ISP Reads the EEPROM on the target device
CMD_PROGRAM_FUSE_ISP Programs fuses on the target device
CMD_READ_FUSE_ISP Reads fuses on the target device
30
AVR067
2587D-AVR-11/09
Command Usage
http://www.BDTIC.com/ATMEL
CMD_PROGRAM_LOCK_ISP Programs lock bits on the target device
CMD_READ_LOCK_ISP Reads lock bits on the target device
CMD_READ_SIGNATURE_ISP Reads the signature bytes on the target device
CMD_READ_OSCCAL_ISP Reads the OSCCAL byte on the target device
CMD_SPI_MULTI Generic command used to execute ISP commands
Timeout No response from the slave within the timeout time.
The command was not understood by the JTAGICE
mkII
The operation cannot be performed in this emulator
mode. (JTAG / debugWire).
The operation cannot be performed with the target
MCU in its current state.
Acknowledge: The slave understood the command and everything is OK.
Table 5-103. Message Format.
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Identical to the associated request
MESSAGE_SIZE 1
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
36
AVR067
2587D-AVR-11/09
The MESSAGE_BODY consists of:
http://www.BDTIC.com/ATMEL
<MESSAGE_ID>
Table 5-104. Parameters.
5.2.2 Failed (RSP_FAILED: 0xA0)
The slave did not understand the command and did nothing. The message body can
be extended to encompass detailed information on WHAT actually failed, this
specification may be updated at this point.
Table 5-105. Message Format.
Parameter Name Usage Format
MESSAGE_ID 0x80 (RSP_OK) [BYTE]
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Identical to the associated request
MESSAGE_SIZE 1
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
The master has tried to write or read an unsupported memory size.
Table 5-113. Message Format.
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Identical to the associated request
MESSAGE_SIZE 1
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
AVR067
[BYTE]
The MESSAGE_BODY consists of:
<MESSAGE_ID>
Table 5-114. Parameters.
Parameter Name Usage Format
MESSAGE_ID
5.2.7 Memory read (RSP_MEMORY: 0x82)
The emulator returns the requested memory block
Table 5-115. Message Format.
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Identical to the associated request
MESSAGE_SIZE The size of MESSAGE_BODY in bytes.
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
0xA3
(RSP_ILLEGAL_MEMORY_RANGE)
[BYTE]
The MESSAGE_BODY consists of:
2587D-AVR-11/09
39
http://www.BDTIC.com/ATMEL
<MESSAGE_ID, DATA>
Table 5-116. Parameters.
Parameter Name Usage Format
MESSAGE_ID 0x82 (RSP_MEMORY) [BYTE]
DATA Memory read! [BYTE] * N
5.2.8 Breakpoint read (RSP_GET_BREAK: 0x83)
The emulator returns only the requested breakpoint:
Table 5-117. Message Format.
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Identical to the associated request
MESSAGE_SIZE The size of MESSAGE_BODY in bytes.
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
The MESSAGE_BODY consists of:
<MESSAGE_ID, TYPE, ADDRESS, MODE>
Table 5-118. Parameters.
Parameter Name Usage Format
MESSAGE_ID 0x83 (RSP_GET_BREAK) [BYTE]
TYPE 0x01: program breakpoint
0x02: data breakpoint
ADDRESS Address
MODE
0x00: (Program breakpoint – not
used)
0x01: Break on memory read
0x02: Break on memory write
0x03: Break on memory read or
write.
5.2.9 Operation cannot be performed (RSP_ILLEGAL_EMULATOR_MODE: 0xA4)
The master has requested an operation that cannot be performed in the current
emulator mode:
[BYTE]
[BYTE] * 4,
LSB first
[BYTE]
Table 5-119. Message Format.
Parameter Name Description
40
AVR067
2587D-AVR-11/09
http://www.BDTIC.com/ATMEL
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Identical to the associated request
MESSAGE_SIZE 2
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
AVR067
The MESSAGE_BODY consists of:
<MESSAGE_ID, CURRENT_MODE>
5.2.10 Operation cannot be performed (RSP_ILLEGAL_MCU_STATE: 0xA5)
The master has requested an operation that cannot be performed in the current
operating state of the target MCU:
Table 5-121. Message Format
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Identical to the associated request
MESSAGE_SIZE 2
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
The MESSAGE_BODY consists of:
<MESSAGE_ID, CURRENT_MODE>
Table 5-122. Parameters.
Parameter Name Usage Format
MESSAGE_ID
0xA5
(RSP_ILLEGAL_MCU_STATE)
[BYTE]
2587D-AVR-11/09
41
http://www.BDTIC.com/ATMEL
Parameter Name Usage Format
CURRENT_MODE 0x00: STOPPED
5.2.11 Program Counter Read (RSP_PC: 0x84)
Returns the current program counter to the master
Table 5-123. Message Format.
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Identical to the associated request
MESSAGE_SIZE 5
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
The MESSAGE_BODY consists of:
[BYTE]
0x01: RUNNING
0x02: PROGRAMMING
<MESSAGE_ID, PROGRAM_COUNTER>
Table 5-124. Parameters.
Parameter Name Usage Format
MESSAGE_ID 0x84 (RSP_PC) [BYTE]
MESSAGE_BODY Program counter
5.2.12 Selftest (RSP_SELFTEST: 0x85)
Returns the result of a self-test. Content of self-test is described later. The self-test
serves two purposes:
1. Verifying the integrity of the unit itself.
2. Verifying that the actual debug set-up is working (device interface is ok, no stuck
lines etc)
Table 5-125. Message Format.
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Identical to the associated request
MESSAGE_SIZE The size of MESSAGE_BODY in bytes.
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
[BYTE] * 4,
LSB first
42
AVR067
2587D-AVR-11/09
http://www.BDTIC.com/ATMEL
AVR067
The MESSAGE_BODY consists of 9 parts:
< MESSAGE_ID, SELFTEST_0, …, SELFTEST_7>
Up to 8 individual self-test functions can be selected by the CMND_SELFTEST
command. Each test returns one byte to the response, regardless of whether it is
executed or not. The individual results are SELFTEST values, which can be
customized further for each specific test.
Table 5-127. Response.
Self-test response Value Meaning
SELFTEST_SKIPPED 0x00 This self-test was not executed
SELFTEST_OK 0x01 Self-test passed
SELFTEST_FAILED 0x80 Self-test failed
ST_USART_FAILURE 0x81 Internal USART test failed
ST_FIFO_M_FAILURE 0x82 Master side F I FO reading failed
ST_FIFO_S_FAILURE 0x83 Slave side FIFO reading failed
ST_FIFO_M_EMPTY_FAILURE 0x84 Master side EMPTY bit reading failed
ST_FIFO_S_EMPTY_FAILURE 0x85 Slave side EMPTY bit reading failed
ST_FIFO_M_FULL_FAILURE 0x86 Master side FULL bit readi ng failed
ST_FIFO_S_FULL_FAILURE 0x87 Slave side FULL bit reading failed
ST_FIFO_M_NINE_FAILURE 0x88 Master side NINTH bit reading failed
ST_FIFO_S_NINE_FAILURE 0x89 Slave side NINTH bit reading failed
ST_SRAM_FAILURE 0x8A Internal SRAM read-write test failed
ST_JTAG_TMS_STUCK_HIGH 0x8B JTAG TMS line cannot be driven low!
ST_JTAG_TCK_STUCK_HIGH 0x8C JTAG TCK line cannot be driven low!
ST_JTAG_TDI_STUCK_HIGH 0x8D JTAG TDI line cannot be driven low!
ST_JTAG_TMS_STUCK_LOW 0x8E JTAG TMS line cannot be driven high!
ST_JTAG_TCK_STUCK_TMS 0x8F
ST_JTAG_TDI_STUCK_TMS 0x90
ST_JTAG_TCK_STUCK_LOW 0x91 JTAG TCK line cannot be driven high!
ST_JTAG_TMS_STUCK_TCK 0x92
JTAG lines TCK and TMS are possibly tied
together.
JTAG lines TDI and TMS are possibly tied
together.
JTAG lines TMS and TCK are possibly tied
together.
2587D-AVR-11/09
43
http://www.BDTIC.com/ATMEL
Self-test response Value Meaning
ST_JTAG_TDI_STUCK_TCK 0x93
ST_JTAG_TDI_STUCK_LOW 0x94 JTAG TDI line cannot be driven high!
ST_JTAG_TMS_STUCK_TDI 0x95
ST_JTAG_TCK_STUCK_TDI 0x96
• JTAG self-test messages should be in the form:
“JTAG connection failed: %message. Please check the physical connection between
the ICE and the target.”
• If the debugWire Capacitance test fails, the message should read:
“The JTAGICE mkII has detected a high capacitance on the RESET line, which may
be affecting the debugWire communication. Please remove any capacitors from the
reset line in your target circuit.”
JTAG lines TDI and TCK are possibly tied
together.
JTAG lines TMS and TDI are possibly tied
together.
JTAG lines TCK and TDI are possibly tied
together.
• If the debugWire PUSH PULL test fails, the message should read:
“The JTAGICE mkII is unable to pull the reset line low in your target application.
Using a too strong pull-up resistor (to low resistance) can cause this. The
recommended value is in the order of 10k.”
5.2.13 SPI data returned (RSP_SPI_DATA: 0x88)
Returns the data clocked out from an SPI command.
Table 5-128. Message Format.
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Identical to the associated request
MESSAGE_SIZE Size of message body in bytes
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
The master has tried to access an illegal emulator command.
Table 5-130. Message Format.
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Identical to the associated request
MESSAGE_SIZE 1
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
The MESSAGE_BODY consists of:
<MESSAGE_ID>
Table 5-131. Parameters.
Parameter Name Usage Format
MESSAGE_ID
0xAA
(RSP_ILLEGAL_COMMAND)
AVR067
[BYTE]
5.2.15 Illegal Value (RSP_ILLEGAL_VALUE: 0xA6)
The master has tried to write an illegal value to an emulator parameter.
Table 5-132. Message Format.
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Identical to the associated request
MESSAGE_SIZE 1
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
The MESSAGE_BODY consists of:
<MESSAGE_ID>
Table 5-133. Parameters.
Parameter Name Usage Format
MESSAGE_ID 0xA6 (RSP_ILLEGAL_VALUE) [BYTE]
2587D-AVR-11/09
45
http://www.BDTIC.com/ATMEL
5.2.16 Sign on (RSP_SIGN_ON: 0x86)
Response to the Master sign on command. The purpose of the response is to tell
AVR Studio which device is attached and which HW and FW versions are in use.
Table 5-134. Message Format
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Identical to the associated request
MESSAGE_SIZE Size of message body in bytes
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
The MESSAGE_BODY consists of:
<MESSAGE_ID, COMM_ID, M_MCU_BLDR, M_MCU_FW_MIN, M_MCU_FW_MAJ,
The master has attempted to enter debugWire mode, but the target did not respond to
a reset pulse. DebugWire synchronization was not achieved.
Can only be returned by a set_parameter emulator mode to debugWire, or possibly
other debugWire mode commands.
48
AVR067
2587D-AVR-11/09
http://www.BDTIC.com/ATMEL
Table 5-144. Message Format.
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Identical to the associated request
MESSAGE_SIZE 1
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
The MESSAGE_BODY consists of:
<MESSAGE_ID>
Table 5-145. Parameters.
Parameter Name Usage Format
MESSAGE_ID
5.2.22 JTAGICE mkII has not enough power to run (RSP_ILLEGAL_POWER_STATE: 0xAD)
0xAC
(RSP_DEBUGWIRE_SYNC_FAILED)
AVR067
[BYTE]
This response is sent to any command when the JTAGICE mkII is running off USB
power but has only enumerated for 100mA operation. The JTAGICE mkII is in power
save mode and will not respond normally to any commands.
Table 5-146. Message Format.
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Identical to the associated request
MESSAGE_SIZE 1
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
Returns data from successful direct reading of the JTAG scan chain
Table 5-148. Message Format.
Parameter Name Description
2587D-AVR-11/09
49
http://www.BDTIC.com/ATMEL
Parameter Name Description
MESSAGE_START ASCII 27 (ESC character)
SEQUENCE_NUMBER Identical to the associated request
MESSAGE_SIZE N+1
TOKEN ASCII 14
MESSAGE_BODY See below
CRC 2-byte CRC.
The MESSAGE_BODY consists of:
<MESSAGE_ID, DATA>
Table 5-149. Parameters.
Parameter Name Usage Format
MESSAGE_ID 0x87 (RSP_SCAN_CHAIN_READ) [BYTE]
DATA
DATA read from the JTAG scan
chain
[BYTE] * N,
LSB first
6 Events
6.1 Introduction
Events are messages sent from the slave (JTAGICE mkII) to the master (AVR Studio)
with no prior command going the other way. A typical example of an event is a
BREAK, the emulator can go on running forever, but suddenly a break condition is
true, and the emulator breaks. The emulator issues a BREAK event to the master,
who takes the appropriate actions. This section lists all events.
6.2 Events
6.2.1 Event Break (EVT_BREAK: 0xE0)
A break condition is met; the emulator goes from RUNNING to STOPPED state.
This section list the descriptors used in relation to the JTAGICE mkII USB
communication.
7.1 DEVICE Descriptor
Table 7-1. Device descriptors.
Offset Field Value Description
0 bLength 0x12 The size of this descriptor is 18 bytes
1 bDescriptorType 0x01 DEVICE Descriptor Type
2 bcdUSB 0x0110 Device compliant to the USB specification version 1.10
4 bDeviceClass 0xFF The device class is vendor-specific
5 bDeviceSubClass 0x00 Each interface specifies its own subclass information
6 bDeviceProtocol 0x00 No protocols on the device basis
7 bMaxPacketSize0 0x10 Maximum packet size for endpoint zero is 16
8 idVendor 0x03EB Vendor ID is 1003: Atmel Corporation
10 idProduct 0x2103 The Product ID is 0x2103
12 bcdDevice 0x0200 The device release numb er is 2.00
14 iManufacturer 0x01 The index of the string descriptor describing the manufacturer is 1
15 iProduct 0x02 The index of the string descriptor describing the product is 2
16 iSerialNumber 0x03 The index of the string descriptor describing the serial number is 3
17 bNumConfigurations 0x01 The device has 1 possible configurations
56
AVR067
2587D-AVR-11/09
http://www.BDTIC.com/ATMEL
AVR067
7.2 CONFIGURATION Descriptor
Table 7-2. Configuration descriptors.
Offset Field Value Description
0 bLength 0x09 The size of this descriptor is 9 bytes
1 bDescriptorType 0x02 CONFIGURATION Descriptor Type
2 wTotalLength 0x0020
4 bNumInterfaces 0x01 This configuration supports 1 interfaces
5 bConfigurationV alue 0x01 The value 1 should be used to select this configuration
6 iConfiguration 0x00 The device doesn't have the string descriptor describing this configur ation
7 bmAttributes 0x80 Configuration characteristics:Bit 7: Reserved
8 MaxPower 0xFA Maximum power consumption of the device in this configuration is 500 mA
The total length of data for this configuration is 32. This includes the combined
length of all the descriptors returned
7.3 INTERFACE Descriptor
Table 7-3. Interface descriptors.
Offset Field Value Description
0 bLength 0x09 The size of this descriptor is 9 b ytes
1 bDescriptorType 0x04 INTERFACE Descriptor Type
2 bInterfaceNumber 0x00 The number of this interface is 0
3 bAlternateSetting 0x00 The value used to select alternate setting for this interface is 0
4 bNumEndpoints 0x02 The number of endpoints used by this interface is 2(excluding endpoint zero)
5 bInterfaceClass 0xFF The interface class is vendor-specific
6 bInterfaceSubClass 0x00 The subclass code is 0x00
7 bInterfaceProtocol 0x00 The interface doesn't use any class-specific protocols
8 iInterface 0x00 The device doesn't have the string descriptor describing this interface
7.4 IN ENDPOINT Descriptor
Table 7-4. In end-point descriptors
Offset Field Value Description
0 bLength 0x07 The size of this descriptor is 7 b ytes
1 bDescriptorType 0x05 ENDPOINT Descriptor Type
2 bEndpointAddress 0x82 This is an IN endpoint with address (endpoint number) 2
3 bmAttributes 0x02 Types –Transfer:BULKSync:No SyncUsage:Data EP
4 wMaxPacketSize 0x0040
6 bInterval 0x0A bInterval:10. The polling interval value is bInterval or 2**(bInterval- 1)
2587D-AVR-11/09
Maximum packet size value for this endpoint is 0x40(Bits 12-11: Addtl.
Transactions/frame)
57
http://www.BDTIC.com/ATMEL
7.5 OUT ENDPOINT Descriptor
Table 7-5. Out end-point descriptors.
Offset Field Value Description
0 bLength 0x07 The size of this descriptor is 7 b ytes
1 bDescriptorType 0x05 ENDPOINT Descriptor Type
2 bEndpointAddress 0x02 This is an OUT endpoint with address (endpoint number) 2
3 bmAttributes 0x02 Types –Transfer:BULKSync:No SyncUsage:Data EP
4 wMaxPacketSize 0x0040
6 bInterval 0x0A bInterval:10. The polling interval value is bInterval or 2**(bInterval- 1)
8 Parameters
The following table describes all JTAGICE mkII parameters maintained through the
Set and Get Parameter commands.
Table 8-1. Parameter Description
ID Description Format Access Value
0x01 Hard ware Version [BYTE] M_MCU ver
0x02 FW version [BYTE] M_MCU_min
0x03 Emulator MODE
(debugWire or JTAG)
0x04 (not used) (not used)
0x05 Baud rate (the default value is 4 : 19200)
The RS232 setup is:
Baud rate, No Parity, 8 data bit, 1 stop bit.
0x06 OCD Vtarget [BYTE] * 2, LSB first R Read from target
0x07 OCD JT AG Clock [BYTE] R/W
0x08 OCD Break Cause [BYTE] R Read from target upon break
Maximum packet size value for this endpoint is 0x40(Bits 12-11: Addtl.
Transactions/frame)
R Hardvare version string
[BYTE] S_MCU ver
R Firmware version string
[BYTE] M_MCU_maj
[BYTE] S_MCU_min
[BYTE] S_MCU_maj
[BYTE] R/W 0x00: debugWire
0x01: JTAG for megaAVR
0x02: unknown / none (default)
0x03: SPI
0x04: JTAG for AVR32
0x05: JTAG for XMEGA
0x06: PDI for XMEGA
Delay between setting and clearing
the JTAG clock.
0x00 for no delay (target at 4MHz+)
58
AVR067
2587D-AVR-11/09
http://www.BDTIC.com/ATMEL
AVR067
ID Description Format Access Value
0x09
0x0A Break on Change of Flo w [BYTE] R/W 0x00
0x0B Break Addr1 [BYTE] * 2, LSB first R/W (not used)
0x0C Break Addr2 [BYTE] * 2, LSB first R/W (not used)
0x0D CombBreakCtrl [BYTE] R/W (not used)
0x0E JTAGID string [BYTE] * 4 R Device specific
0x0F (not used) (not used)
0x10 (not used) (not used)
0x11 (not used) (not used)
0x12 (not used) (not used)
0x13 External Reset [BYTE] R/W 0x00 : No
0x14 Flash Page Size [BYTE] * 2, LSB first R/W Device specific
0x15 EEPROM Page Size [BYTE] R/W Device s pecific
0x16 (not used) (not used)
0x17 PSB0 [BYTE] * 2, LSB first R/W (not used)
0x18 PSB1 [BYTE] * 2, LSB first R/W (not used)
0x19 (not used) (not used)
0x1A Target MCU STATE [BYTE] R 0x00 : STOPPED
0x1B Daisy chain info [BYTE] units before
0x1C Boot address [BYTE] * 4, LSB first R/W
0x1D Target Signature [BYTE] * 2, LSB first R Read from target
0x1E (not used) (not used)
0x1F Program entry point [BYTE] * 4, LSB first W
0x22 Read CAN mai lbo x [BYTE] R/W 0x00: Don’t read CAN-mailbox
0x23 Enable IDR events [BYTE] W 0x00: Access OSCCAL
0x24 Allo w page programming in a scan chain [BYTE] W 0x00: Not allowed
0x2D Soft reset (after signing off) [BYTE] W 0x00: Hard reset
0x31 PDI offset of NVM controller [BYTE] * 4, LSB first W Device specific
0x32 PDI offset of flash applicatio n section [BYTE] * 4, LSB first W Device specific
0x33 PDI offset of flash boot section [BYTE] * 4, LSB first W Device specific
Timers Running when target device is in
stopped mode
[BYTE] R/W 0x00 : Timers stopped (default)
0x01 : Timers Running
0x01 : Yes (default)
0x01 : RUNNING
0x02 : PROGRAMMING
R/W
[BYTE] units after
[BYTE] bits before
[BYTE] bits after
0x01: Read CAN-mailbox
0x01: Access IDR
0x01: Allowed
0x03: No reset
2587D-AVR-11/09
59
http://www.BDTIC.com/ATMEL
ID Description Format Access Value
0x37 AVR32 JT AG enable sequence [BYTE] W 0x00: No JTAG enable
0x01: Use JTAG enable sequence
0x38 Run after progr amming [BYTE] W 0x00: Hold target stopped
0x01: Allow target to run
0x40 Packet parsing errors [BYTE] * 4, LSB first R
0x41 Valid packets received [BYTE] * 4, LSB first R
0x42 Intercommunication TX failures [BYTE] * 4, LSB first R
0x43 Intercommunic ation RX failures [BYTE] * 4, LSB first R
0x44 CRC errors [BYTE] * 4, LSB first R
0x45 Po wer source [BYTE] R 0x00 : External
0x01 : USB
9 Device Descriptor fields
Figure 9-1. Defined parameters used by the “Set Device Descriptor” command.
unsigned char ucAllowFullPageBitstream; // FALSE on ALL new
60
AVR067
2587D-AVR-11/09
10 Memory Types
http://www.BDTIC.com/ATMEL
//parts
unsigned int uiStartSmallestBootLoaderSection //
unsigned char EnablePageProgramming; // For JTAG parts only,
// default TRUE
unsigned char ucCacheType; // CacheType_Normal 0x00,
// CacheType_CAN 0x01,
unsigned int uiSramStartAddr // Start of SRAM
unsigned char ucResetType; // Selects reset type. 0x00
unsigned char ucPCMaskExtended; // For parts with extended PC
unsigned char ucPCMaskHigh; // PC high mask
unsigned char ucEindAddress; // EIND IO address
unsigned int EECRAddress; // EECR IO address
When reading SRAM three different actions can be taken depending on the address
range. If the address is in the range 0x0000 to 0x001F JTAGICE mkII will fetch the
data from the general purpose working register file. If the address is in the range
0x0020 to 0x005F data will be fetched from the IO register file. If the AVR supports
Extended IO registers and the address is in the range less than 0x00FF data will be
fetched from the External IO register file.
If the address is beyond 0x005F data is fetched from internal/external SRAM when no
external IO register file is used. If external IO register file is used the address must be
beyond 0x0FF to fetch data from internal/external SRAM.
2587D-AVR-11/09
61
http://www.BDTIC.com/ATMEL
Read memory type SPM reads a single program word while FLASH_PAGE reads a
whole page. Write memory uses FLASH_PAGE to program the whole flash. SPM is
used only for programming a single page.
Memory type EEPROM_PAGE uses page write and byte read. Memtypes
FUSE_BITS, LOCK_BITS and OSCCAL_BYTE use byte read and (write).
The address sent to JTAGICE mkII is byte address for all memory types. Only the
start address needs to be supplied.
The Emulator program reports Read Memory errors as Resp_FAILED. Unknown
Read Memory types are ignored. Write Memory unknown types are also ignored.
Memory Type CAN is handled by reading 300 bytes each time the memory type is
accessed. The access of the CAN memory type is controlled by parameter Read CAN
mailbox. If parameter Read CAN mailbox = TRUE then read all the 300 bytes if not
(FALSE) don’t read.
Writing to the CAN-mailbox is also done by using MemType_CAN. For each byte
edited/written there should be a Cmnd_Write_Memory call for this memory type along
with the address for the byte.
11 Breakpoints (megaAVR devices with JTAG interface)
The OCD system uses Break Point Comparators to set Break Points. The Break Point
control unit contains two single Program Memory Break Points, and two combined
Break Points. Together, the four Break Points can be configured as either: (One
Break Point is always used for single step.)
• 4 single Program Memory Break Points.
• 3 Single Program Memory Break Point + 1 single Data Memory Break Point
• 2 Single Program Memory Break Point + 2 single Data Memory Break Point
• 2 Single Program Memory Break Point + 1 Program Memory Break Point with
mask (“range Break Point”)
• 2 Single Program Memory Break Point + 1 Data Memory Break Point with mask
(“range Break Point”)
The Data Memory Break Point can be set to one out of three modes; Data Memory
Read, Data Memory Write, or Data Memory Read or Write. A Data Memory break
sets the AVR CPU in the Stopped mode after finishing the instruction causing the
break condition.
Break on data content is not supported.
The OCD system contains different registers in the Break Point control unit.
PSBO and PSB1 – Program Break on single address – are 16-bit compare registers
for the Program Counter from the CPU.
PDMSB – Program/Data Mask or Single Break – is the register used for setting a
single program Break Point on either a Program Memory or a Data Memory address.
Alternatively, PDMSB can act as a mask on the address to the PDSB comparator,
thereby implementing a “range-break”.
PDSB – Program/Data Single Break – is used for setting a single Break Point on
either a Program Memory or a Data Memory address. Alternatively, PDMSB can
mask the address to the PDSB Comparator, thereby implementing a "range-break".
62
AVR067
2587D-AVR-11/09
12 CRC16 Calculations
http://www.BDTIC.com/ATMEL
BCR – Break Control Register – is among other things used to control the settings of
the four different Break Registers mentioned above.
To set Break Points in the JTAGICE mkII, AVR Studio uses
CMND_SET_PARAMETER to set the PSB0 or PSB1 Registers. In this case, the
address of the Set Parameter command is the address where the Break Points will be
located, and the value indicates if the PSB0 or PSB1 Break Points should be set to
this location (0 = PSB0, 1 = PSB1). Necessary modification of BCR is done
automatically.
CmndSetParameter and Parameter BreakAddr set the PDMSB and PDSB Registers.
BCR is not automatically modified in this case. To activate the PDMSB and PDSB
Break Points the command CmndSetParameter and parameter CombBreakCtrl
should be used to set BCR to the proper value. When the JTAGICE mkII breaks, all
Break Points are cleared therefore, Break Points must be set prior to each run. There
is no need for Clear Break Points commands.
The following source code performs CRC16 calculation and verification for the
JTAGICE mkII Communication Protocol. Use the VerifyChecksum function to verify
the integrity of a received command. Returns TRUE if the message integrity is
maintained, returns FALSE otherwise.
AVR067
Use the AppendChecksum function to append the 2 CRC16 bytes to a message prior
to sending the message.
Figure 12-1. File: crc16.h.
#ifndef CRC16_H
#define CRC16_H
class Crc16
{
public:
// Calculate the checksum of a message.
static unsigned short Checksum( const unsigned char* message,
unsigned long length,
unsigned short crc = 0xffff);
// Verify that the last two bytes is a (LSB first)
// valid CRC of the message.
static bool VerifyChecksum( const unsigned char* message,
unsigned long length);
// Append a two byte CRC (LSB first) to message.
// length is size of message excluding crc.
// Space for the CRC bytes must be allocated in advance!
static void AppendChecksum( unsigned char* message,
unsigned short crc)
{ for(unsigned long i = 0; i < length; i++)
{ CRC(crc, message[i]);
}
return crc;
}
bool Crc16::VerifyChecksum(const unsigned char* message, unsigned
long length)
{ // Returns true if the last two bytes in a message is the crc
// of the preceding bytes.
unsigned short expected = Checksum(message, length - 2);
return (expected & 0xff) == message[length - 2] &&
((expected >> 8) & 0xff) == message[length - 1];
}
void Crc16::AppendChecksum(unsigned char* message, unsigned long
13 Table of Contents......................................................................... 66
68
AVR067
2587D-AVR-11/09
http://www.BDTIC.com/ATMEL
Headquarters International
Atmel Corporation
2325 Orchard Parkway
San Jose, CA 95131
USA
Tel: 1(408) 441-0311
Fax: 1(408) 487-2600
Atmel Asia
Unit 1-5 & 16, 19/F
BEA Tower, Millennium City 5
418 Kwun Tong Road
Kwun Tong, Kowloon
Hong Kong
Tel: (852) 2245-6100
Fax: (852) 2722-1369
Atmel Europe
Le Krebs
8, Rue Jean-Pierre Timbaud
BP 309
78054 Saint-Quentin-enYvelines Cedex
France
Tel: (33) 1-30-60-70-00
Fax: (33) 1-30-60-71-11
Atmel Japan
9F, Tonetsu Shinkawa Bldg.
1-24-8 Shinkawa
Chuo-ku, Tokyo 104-0033
Japan
Tel: (81) 3-3523-3551
Fax: (81) 3-3523-7581
Product Contact
Web Site
http://www.atmel.com/
Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any
intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN ATMEL’S TERMS AND
CONDITIONS OF SALE LOCATED ON ATMEL’S WEB SITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED
OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS,
BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS
BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the
contents of this document and reserves the right to make changes to specifications and product descriptions at any time without notice. Atmel does not make any
commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in,
automotive applications. Atmel’s products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life.