AVR068: STK500 Communication Protocol Features • Interfaces both STK500 and AVRISP • Supports STK500 FW 2.XX 1 Introduction 8-bit Microcontrollers Application Note This document describes the 2.0 version of the communication protocol between the Atmel STK500 and the PC controlling the STK500. The firmware is distributed with AVR Studio 4.11 build 401 or later. The definition of all commands, responses, parameters and other defined values can be found in the file “command.h”.
Communication interface The communication between the STK500 and the PC is done over RS232 (PC COM port). The STK500 uses: 115.2kbps, 8 data bits, 1stop bits, no parity. The PC should be set up similarly for the communication to work. 3 Message Format All commands and responses share a common message format: Figure 3-1. Message format. MESSAGE_START SEQUENCE_NUMBER MESSAGE_SIZE TOKEN MESSAGE_BODY CHECKSUM Table 3-1.
AVR068 The table describes all states, events and conditions for the handling of incoming data. Table 4-1.
5 Commands STK500 commands are sent in the MESSAGE_BODY part of a message (see chapter 2). This section describes all commands that can be entered to the STK500, and all the possible responses that each command can give back to the host. In general, all programming modes use the same protocol commands, but various parameters are sent with the different programming modes in order to avoid unnecessary overhead in the protocol layer.
AVR068 5.1.2 CMD_SET_PARAMETER The host can set a multitude of parameters in the STK500. See 5.7 Parameters for a description of each parameter. All parameters are one-byte values. Table 5-4. Command format Field Size Values Description Command ID 1 byte CMD_SET_PARAMETER Command id Parameter ID 1 byte Which parameter to set Value 1 byte The parameter’s new value Table 5-5.
5.1.4 CMD_OSCCAL This command performs a calibration sequence as described in application note AVR053. Table 5-9. Command format Field Size Values Description Command ID 1 byte CMD_OSCCAL Command id Table 5-10. Answer format Field Size Values Description Answer ID 1 byte CMD_OSCCAL Answer id Status 1 byte STATUS_CMD_OK or STATUS_CMD_FAILED A status value indicating success or failure. 5.1.5 CMD_LOAD_ADDRESS This command will load an address into the STK500.
AVR068 5.1.6 CMD_FIRMWARE_UPGRADE When the host is trying to connect to the programmer, it checks the firmware version. A firmware upgrade is initiated if a newer version is available on the PC. The STK500 can “reboot” into upgrade mode by using this command. (If the PROGRAM button on STK500 is pressed while turning on power, upgrade mode is also entered.) Table 5-13.
Table 5-15.
AVR068 5.2.2 CMD_LEAVE_PROGMODE_ISP This command will make STK500 leave programming mode. The device will be put into normal operating mode. XML path: /AVRPART/ICE_SETTINGS/STK500_2/IspLeaveProgMode/ Table 5-17. Command format Field Size Values Description Command ID 1 byte CMD_LEAVE_PROGMODE_ISP Command id preDelay 1 byte XML: preDelay Pre-delay (in ms) postDelay 1 byte XML: postDelay Post-delay (in ms) Table 5-18.
5.2.4 CMD_PROGRAM_FLASH_ISP This command will program data into the FLASH memory of the target device if it succeeds. XML path: /AVRPART/ICE_SETTINGS/STK500_2/IspProgramFlash/ Table 5-21.
AVR068 5.2.4.1 Mode byte description The mode parameter is essential for how this command works. The bits in the mode byte have the following meanings: Table 5-23. The bits in the mode byte Bit # Description 0 Word/Page Mode (0 = word, 1 = page) 1 Timed delay 2 Value polling 3 RDY/BSY polling 4 Timed delay 5 Value polling 6 RDY/BSY polling 7 Write page Mode Word Mode Page Mode The Word/Page Mode bit selects if the device supports page programming or not.
5.2.5 CMD_READ_FLASH_ISP This command will read data from the FLASH memory of the target device if it succeeds. XML path: /AVRPART/ICE_SETTINGS/STK500_2/IspReadFlash/ Table 5-24. Command format Field Size Values Description Command ID 1 byte CMD_READ_FLASH_ISP Command id NumBytes 2 byte XML: blockSize Total number of bytes to read, MSB first cmd1 1 byte Read Program Memory command byte #1. Low/High byte selection bit (3rd bit) is handled in the FIRMWARE. Table 5-25.
AVR068 5.2.8 CMD_PROGRAM_FUSE_ISP This command programs the fuses of the target device. Table 5-27. Command format Field Size Values Description Command ID 1 byte CMD_PROGRAM_FUSE_ISP Command id cmd1 1 byte Command Byte #1 cmd2 1 byte Command Byte #2 cmd3 1 byte Command Byte #3 cmd4 1 byte Command Byte #4 Note: cmd1, cmd2, cmd3 and cmd4 are the four bytes of the low-level program fuse ISP command Table 5-28.
Table 5-30. Answer format Field Size Values Description Answer ID 1 byte CMD_READ_FUSE_ISP Answer id Status1 1 byte STATUS_CMD_OK A status value indicating the result of the operation, always OK data 1 byte Status2 1 byte The fuse byte read from the device STATUS_CMD_OK A status value indicating the result of the operation, always OK 5.2.10 CMD_PROGRAM_LOCK_ISP See CMD_PROGRAM_FUSE.
AVR068 Table 5-32. Answer format Field Size Values Description Answer ID 1 byte CMD_SPI_MULTI Answer id Status1 1 byte STATUS_CMD_OK Will always read OK data 0-255 bytes Status2 1 byte The data read from the ISP bus as indicated in the command STATUS_CMD_OK Will always read OK 5.3 Parallel Programming Mode Commands 5.3.1 CMD_ENTER_PROGMODE_PP This command will make the target device enter programming mode if it succeeds. XML PATH: /AVRPART/ICE_SETTINGS/STK500_2/PpEnterProgMode/ Table 5-33.
Table 5-34. Answer format (same for all results) Field Size Values Description Answer ID 1 byte CMD_ENTER_ PROGMODE_PP Answer id Status 1 byte See table below A Result Value indicating the result of the operation Table 5-35. Valid Result Values for the answer to this command Values Description STATUS_CMD_OK Operation succeeded STATUS_CMD_ FAILED Operation failed 5.3.2 CMD_LEAVE_PROGMODE_PP This command will make the target device leave programming mode if it succeeds.
AVR068 Table 5-39. Answer format (same for all results) Field Size Values Description Answer ID 1 byte CMD_CHIP_ ERASE_PP Answer id Status 1 byte See table below A Result Value indicating the result of the operation Table 5-40. Valid Result Values for the answer to this command Values Description STATUS_CMD_OK Operation succeeded STATUS_RDY_BSY_ TOUT No response from target device within specified timeframe 5.3.
Table 5-43. Valid Result Values for the answer to this command Values Description STATUS_CMD_OK Operation succeeded STATUS_RDY_BSY_ TOUT No response from target device within specified timeframe 5.3.4.1 Mode byte description • Bit 0: This bit indicates whether to use byte ‘0’ or page ‘1’ programming. • Bit 1-3 are the pagesize bits, pagesize are given in bytes not words, see table below: Table 5-44.
AVR068 Table 5-46. Answer format if the command is executed Field Size Values Description Answer id Answer ID 1 byte CMD_READ_FLASH_PP Status 1 byte STATUS_CMD_OK Data Nmb bytes Status 1 byte Data read from device. Will be padded with 0’s if errors occurred during read-out. STATUS_CMD_OK A Result Value indicating the result of the operation 5.3.6 CMD_PROGRAM_EEPROM_PP This command programs one page the EEPROM memory of the target device if it succeeds.
Table 5-49. Valid Result Values for the answer to this command Values Description STATUS_CMD_OK Operation succeeded STATUS_RDY_BSY_ TOUT No response from target device within specified timeframe 5.3.9 CMD_READ_FUSE_PP XML PATH: /AVRPART/ICE_SETTINGS/STK500_2/PpReadFuse/ Table 5-50. Command format Field Size Values Description Command ID 1 byte CMD_READ_FUSE_PP Command id Address 1 byte Address of fuse byte to read Table 5-51.
AVR068 5.3.14 CMD_SET_CONTROL_STACK Uploads the control stack to the STK. This is used for both PP and HVSP. Note: The Control stack must always be uploaded before performing any programming commands in high voltage mode if the STK500 has been powered down. To check if the controller PARAM_CONTROLLER_INIT has a valid control stack: Read Se chapter 5.7.14: PARAM_CONTROLLER_INIT Table 5-52.
Table 5-54.
AVR068 Table 5-57. Answer format Field Size Values Description Answer ID 1 byte CMD_LEAVE_ PROGMODE_HVSP Answer id Status 1 byte STATUS_CMD_OK A Result Value indicating the result of the operation. Will always read OK 5.4.3 CMD_CHIP_ERASE_HVSP This command will perform a chip erase on the target device if it succeeds. XML path: /AVRPART/ICE_SETTINGS/STK500_2/HvspChipErase/ Table 5-58.
Table 5-61. Answer format Field Size Values Description Answer ID 1 byte CMD_PROGRAM_FLASH_HVSP Answer id Status 1 byte STATUS_CMD_OK or A Result Value indicating the result of the operation. STATUS_RDY_BSY_TOUT 5.4.4.1 Mode byte description • Bit 0: This bit indicates whether to use byte ‘0’ or page ‘1’ programming. • Bit 1-3 are the pagesize bits, pagesize are given in bytes not words, see table below: Table 5-62.
AVR068 Table 5-64. Answer format if the command is executed Field Size Values Description Command ID 1 byte CMD_READ_FLASH_HVSP Answer id Status1 1 byte STATUS_CMD_OK Temporary status, will always read OK Data Byte*N Status2 1 byte Data read from device. Will be padded with 0’s if errors occurred during read-out. STATUS_CMD_OK A Result Value indicating the result of the operation. Will always read OK 5.4.6 CMD_PROGRAM_EEPROM_HVSP See the CMD_WRITE_FLASH_HVSP command. 5.4.
Table 5-67. Command format Field Size Values Description Command ID 1 byte CMD_ READ_FUSE_HVSP Command id Fuse Address 1 byte 0, 1 or 2 Address of byte to read (0=low, 1=high, 2=ext) Table 5-68. Answer format if command was executed Field Size Values Description Command ID 1 byte CMD_ READ_FUSE_HVSP Answer id Status 1 byte STATUS_CMD_OK A Result Value indicating the result of the operation. Will always read OK Fuse Byte 1 byte Data read from device.
AVR068 5.5 Special answers Answers that don’t correspond to a specific command. 5.5.1 ANSWER_CKSUM_ERROR This is an answer generated by the transport layer, indicating that a message with incorrect checksum has been received. Table 5-69. Answer format Field Size Values Description Command ID 1 byte ANSWER_CKSUM_ERROR Answer id Status 1 byte ANSWER_CKSUM_ERROR A status value indicating checksum error 5.6 Return values This section describes all possible return values and their meaning in detail.
5.7 Parameters The following parameters can be read and/or written by the CMD_GET_PARAM and CMD_SET_PARAM commands: Table 5-73.
AVR068 5.7.6 PARAM_VTARGET This parameter only applies to STK500, not the AVRISP. STK500 has a controllable target voltage supply, which can be set and monitored with this parameter. The parameter value is voltage in volts x10, i.e. a parameter value of 42 (decimal) corresponds to 4.2V. The VTARGET voltage is adjustable between 0 and 6V. 5.7.7 PARAM_VADJUST This parameter only applies to STK500, not the AVRISP. STK500 has an adjustable analog reference in the same way as the supply voltage.
The STK500 system clock is fsys = 7.37MHz., which gives the following relation between prescaler and compare values and the resulting frequency: f = prescaled clock / (compare value + 1) / 2 The prescale clock is the system clock divided by some factor according to this table: Table 5-74.
AVR068 The STK500 and AVRISP supports ISP frequencies from 4 kHz up to 1.8 MHz. The value for PARAM_SCK_DURATION can be found using the following algorithm: #define T_STK500 135.63e-9 #define T_AVRISP 271.27e-9 #define B 12.
5.7.11 PARAM_TOPCARD_DETECT This parameter only applies to STK500, not the AVRISP. Expansion cards can be connected to STK500. Each type of card has an id circuitry, so that the STK500 can detect which type of card that is mounted. The following IDs are in use: Table 5-75. Topcard IDs Card ID STK501 0xAA STK502 0x55 STK503 0xFA STK504 0xEE STK505 0xE4 STK520 0xDD 5.7.12 PARAM_DATA This parameter only applies to STK500, not the AVRISP.
AVR068 6 XML Parameter Values One of the major enhancements in the 2.0 version of the STK500 protocol is the ability to describe parameters for all details of the programming algorithms. A parameter set is specific for a certain AVR device, thus the parameter settings belong in the XML part description file. Below is a description where to find the STK500 parameter values in the device specific XML file.
7 Command Sequence Example This chapter contains examples of how to connect to the STK500 from the PC Frontend and how to read signature from a device. See chapter 5 Commands for the description of the commands and parameters. 7.1 Connect The sequence of commands and parameters sent from AvrStudio to the STK500 in order to connect is listed below.
AVR068 7.2.2 High Voltage Programming The sequence of commands and parameters sent from AvrStudio to the STK500 in order to read the device signature through High Voltage Programming is listed below. Note that one already have to be connected to do this. This sequence goes for both High Voltage Parallel Programming and High Voltage Serial Programming.
Figure 7-2. The “Edit String” dialog box After editing the Registry, open AvrStudio and start the STK500 Programming Dialog. All commands will now be written to the text file specified in the Registry. This file will look like this: Figure 7-3. Example log file contents Notes: 1. This is the Command ID, in this case 0x03 which is CMD_GET_PARAMETER 2.
Disclaimer Atmel Corporation 2325 Orchard Parkway San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 487-2600 Regional Headquarters Europe Atmel Sarl Route des Arsenaux 41 Case Postale 80 CH-1705 Fribourg Switzerland Tel: (41) 26-426-5555 Fax: (41) 26-426-5500 Asia Room 1219 Chinachem Golden Plaza 77 Mody Road Tsimshatsui East Kowloon Hong Kong Tel: (852) 2721-9778 Fax: (852) 2722-1369 Japan 9F, Tonetsu Shinkawa Bldg.