• 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
Loading...
+ 48 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.