1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
|
/*
* avrjtag - The "avrjtag" program.
* Copyright (C) 2001 Scott Finneran & Peter Jansen
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
*
* This file contains the AVR JTAG ICE protocol documentation.
*/
AVR JTAG-ICE serial protocol commands
Background: This document outlines the results of a reverse engineering
effort of the protocol which exists between AVRStudio and the AVR
JTAG-Ice.
Something to note is that the protocol supports dynamic bitrate
changes. AVRStudio does indeed change the bitrate "mid-stream".
Specifically, it seems to speed it up to 115200bps just prior to
downloading (and possibly uploading) blocks of date to the
JTAG-Ice. After the download, the bitrate is restored to 19200bps.
This can make Analysing the protocol somewhat painful using a serial line
sniffer.
Something that the document does lack is detail on the "state" or
procedural aspect of the protocol. ie "This command must be proceeded
by blah blah...."
Most commands are of the format <letter> [operands....]. An assumption
was made that the letters actually mean something (ie W for write, R for
read).
***************************************************************
Hints for those wishing to help with understanding the protocol:
The thing that made understanding the protocol difficult, is that it
switches bitrates when writing to memory. As such, a traditional
protocol analyser or line monitor (which connects to the serial line
itself) will lose sync when this happens!.
One work-around for this is to use a program like HHD Serial Monitor
(http://www.hhdsoftware.com). Rather than involve serial hardware, this
program captures the MS-Windows serial driver requests. As such, you can
see the data sent and received, without worrying about bitrate changes
(although you can see driver config requests also, so you know when it
happens).
***************************************************************
Formatting:
All commands from the Host end in a Space, Space (shown below as '__')
All commands from the JTAG box start with a 'A' and end in a 'A', except
when writing to memory, a 'A''A' is sent only after the data is
written.
Things in [] are hex characters. eg [42] [FA]
Underscores '_' indicate a space. Actual spaces in the text below are
for the purposes of formatting only.
Serial port works at 19200, N 8 1
(until the bitrate change command is issued)
****************************************************************
This command is either sync (ie serial line sync) or status or
something. The first command also appears to have a few spaces sent down
first. Haven't quite worked it out yet.
S__ : Sync
A AVRNOCD A - the reply
****************************************************************
Query:
These commands start with a ASCII 'q' (ie [71])
qz__ : query HW version
A [c0] A - the reply
q [7B] __ : query SW version
A [66] A
q [84] __ : query supply voltage
A [xx] A - the reply voltage = xx/41
q [A7] __ : ????
A [3f] A
q [A8] __ : ????
A [20] A
q [A9] __ : ????
A [70] A
q [AA] __ : ????
A [29] A
****************************************************************
Appears to somehow configure the JTAG box. The data probably changes for
different processors.
[A0] [.(123 bytes).....] __ : ????
A A
****************************************************************
[A3] __ : Enable program mode.
A A
****************************************************************
[A4] __ : Disable program mode.
A A
****************************************************************
[A5] __ : Erase program memory. Program mode must be enabled.
A A
****************************************************************
R [cc] [x][x][y][y] __ : Read memory
where cc is command
[B2] - Fuse Bits
[B3] - Lock Bits
[B4] - Signature Bits
[A0] - Program memory if Prog Mode enabled (read words)
[B0] - Program memory if Prog Mode disabled (read words)
[20] - Data Memory
[22] - EEPROM
x x is the number of locations - 1 (little endian) *1 *2
y y is the start address (big endian)
A [....(data)....] [00] A *1
For data memory, the data returned is a series of bytes (endian-ness
does not apply).
For prog memory, the data returned is a 16-bit big endian.
*1 note: For program memory each location is 16 bits. As such, it will
return N words, rather than bytes. These words are little endian. For
data space, locations are 8 bits wide, so N bytes are returned.
*2 AVRStudio only requests 0xff bytes at a time. The reliability of the
system to respond to larger numbers is unknown.
****************************************************************
W [cc] [x][x][y][y] __ : Write memory
where cc is command
[A0] - Program memory if Prog Mode enabled (write words)
[B0] - Program memory if Prog Mode disabled (write words)
[B2] - Fuse Bits
[B3] - Lock Bits
[B4] - Signature Bits
[20] - Data memory (write bytes)
[22] - EEPROM
[60] - first program break point at location y y
this needs the data [01] for the following h command
x x is the numer of locations - 1 (little endian)
y y is the start address (big endian)
The reply to this command is a single A
Then the Host sends h [....(data)....] __ which is the data
The reply is A A (success) or E E (failure).
ONLY IN THE CASE OF PROG SPACE WRITE:
The data is written into the flash when the flash programming buffer
(2048 bits/256 bytes/128 words) is filled. As such, in the event of a
prog space page being smaller than an entire page (ie < 0x7F words),
AVRStudio sends down a single write to the last location in the page.
notes:
- For program memory each location is 16 bits. As such, N words (rather
than bytes) need to be sent. These words are little endian.
- The object files output from both AVRStudio & GCC are already
word-wise little endian.
****************************************************************
3 [x][x][x] __ : set PC
A A : where xxx is the new value for the PC.
****************************************************************
2 __ : get next PC
A [x][x][x] A : where xxx is the next location to execute (?)
NOTE: APPEARS TO BE INVALID WHEN THE LAST INSTRUCTION
WAS A BRANCH.
****************************************************************
1 __ : single step command
A A
****************************************************************
G __ : go command
The JTAG box replies immediately with a single
A
If breakpoints have been configured, and a breakpoint "hits", the JTAG
box will send
B [00] [BP]
[BP] - which breakpoint was "hit" (refer breakpoint below).
[04] - Breakpoint X
[08] - Breakpoint Y
[10] - Breakpoint Z
****************************************************************
F __ : finish (halt)
A [00][PCL][PCH] A
[PCL] - PC Low byte
[PCH] - PC High byte
****************************************************************
x __ : ???
A A
****************************************************************
"Box Config" commands
These appear to be set actions performed on various configuration
registers withing the box itself. The generic command appears to be:
B [rn] [val] __ : Box Config
where rn is the register number, val is the value written.
[FD] - ???
[FF] - ???
[FA] - ???
[00] - ???
[62] set bit rate.
val = (FA: 19200, FF: 115200)
[86] set JTAG port bitrate (AVRStudio calls this the debug freq.)
val = (FA: 100kHz, F3: 50kHz, FD: 200kHz)
[81] [00] Written after modifying the PC.
[A1] set break on branch/skip (will run until the next
branch/skip instruction)
[A2] val = Breakpoint X Address -High
[A3] val = Breakpoint X Address -Low
[A4] val = Breakpoint Y Address -High
[A5] val = Breakpoint Y Address -Low
[A6] val = BP mode (see Breakpoints below)
[88] val = ?? (related to config bits. refer below).
[89] val = ?? (related to config bits. refer below).
[8A] val = ?? (related to config bits. refer below).
Programming Mode.
The following sequence (according to AVRStudio), prepares the chip for
JTAG programming. It appears to only happen once per session (when
programming mode is enabled).
Send: [42] [88] [00] [20] [20]
Reply: [41] [41]
Send: [42] [89] [01] [20] [20]
Reply: [41] [41]
Send: [42] [8A] [08] [20] [20]
Reply: [41] [41]
Chip Config (Fuse, Signature and Lock) Bits:
These are access using the normal read & write commands using
"special" address space identifiers.Fuse Bits:
Fuse bits are written/read by accessing address zero of the [B2]
address space.
Signature Bits:
Signature bits are written/read by accessing address zero of the [B4]
address space.
Lock Bits:
Lock bits are written/read by accessing address zero of the [B3]
address space.
Breakpoints:
note: AVRStudio's first breakpoint is set by writing a 1 to the
desired break address using address space 60 (refer Write
command). I believe a corresponding write of zero will clear this
breakpoint.This is a code space breakpoint only.
Where BP mode is a bitmask formatted thusly (don't you think the word
thusly doesn't get used enough in doco?):
-------------------------------------------------
| | | | | | |
| 0 | Mask| BP Active | BP Mode | BP Mode |
| | Mode| | | (BP X) | (BP Y) |
-------------------------------------------------
Mask Mode:
[0] = X & Y are seperate Breakpoints (non-masked mode).
[1] = X is masked with Y to create a single range of
breakpoint addresses.
BP Active:
[00] = No breakpoints enabled
[01] = Masked Mode (must be set to this value if Mask Mode = 1).
[10] = 1 Breakpoint (Breakpoint X active only)
[11] = 2 Breakpoints (Breakpoints X & Y active)
BP Mode:
[00] = Data Space Read
[01] = Data Space Write
[10] = Data Space Read/Write (ie Data Access)
[11] = Program Space Read
Examples:
[2C] - Single program BP at [x][x]
[3F] - two break points at [x][x] and [y][y]
[28] - single data R/W BP at [x][x]
[20] - single data R BP at [x][x]
[24] - single data W BP at [x][x]
[34] - two data BP's one R at [x][x] and one W at [y][y]
[35] - two data BP's one R at [x][x] and one R at [y][y]
[53] - Masked program read BP at [x][x] mask [y][y]
[50] - Masked data read BP at [x][x] mask [y][y]
[51] - masked data write BP at [x][x] mask [y][y]
[52] - masked data RW BP at [x][x] mask [y][y]
The reply is A A
|