pyedbglib.protocols

pyedbglib.protocols.ati

Wrapper for the Asynchronous Transport Interface (ATI)

class pyedbglib.protocols.ati.AsynchronousTransportInterface(transport)

Bases: pyedbglib.protocols.dapwrapper.DapWrapper

Generic wrapper class for the Asynchronous Transport Interface (ATI)

read_buffer(buffer_id, num_bytes=None, buffer_type=0)

Read data from a buffer. Will handle chopping of data reads to suit USB endpoint size

Parameters
  • buffer_id – ID of buffer to read from

  • num_bytes – Number of bytes to read from the buffer

  • buffer_type – ATI_CTRL_TYPE_DATA, ATI_CTRL_TYPE_METADATA, ATI_CTRL_TYPE_CMDRSP or ATI_CTRL_TYPE_SYS

Returns

bytearray of data bytes read from the buffer

read_data_buffer(buffer_id, num_bytes=None)

Read data from data buffer

Parameters
  • buffer_id – ID of data buffer to read from

  • num_bytes – Number of bytes to read from buffer

Returns

bytearray of data bytes read from buffer

read_metadata_buffer(buffer_id, num_bytes=None)

Read data from metadata buffer

Parameters
  • buffer_id – ID of metadata buffer to read from

  • num_bytes – Number of bytes to read from buffer

Returns

bytearray of databytes read from buffer

read_response_buffer(num_bytes=None)

Read data from the response buffer

Parameters

num_bytes – Number of bytes to read from buffer

Returns

bytearray of data bytes read from the buffer

receive_fragment(buffer_id, flags, bytes_to_receive)

Receive data fragment from buffer. Limited by USB endpoint size

Parameters
  • buffer_id – ID of buffer to receive from

  • flags – BIT: | 7 | 6 | 5 | 4 3 | 2 1 0 | USE: | read | EOF | SOF | buffer_type | Buffer ID |

  • bytes_to_receive – Number of bytes to read from the buffer

Returns

bytearray of data bytes read from the buffer

send_fragment(buffer_id, flags, data)

Send a fragment of data to a buffer. Limited by USB endpoint size

Parameters
  • buffer_id – ID of buffer to send data to

  • flags – BIT: | 7 | 6 | 5 | 4 3 | 2 1 0 | USE: | read | EOF | SOF | buffer_type | Buffer ID |

  • data – bytearray of data bytes to write to the buffer

write_buffer(buffer_id, data, buffer_type=0)

Write data to a buffer. Will handle chopping of data to suit USB endpoint size

Parameters
  • buffer_id – ID of buffer to write data to

  • data – bytearray of data bytes to be written

  • buffer_type – ATI_CTRL_TYPE_DATA, ATI_CTRL_TYPE_METADATA, ATI_CTRL_TYPE_CMDRSP or ATI_CTRL_TYPE_SYS

write_command_buffer(data)

Write data to command buffer

Parameters

data – bytearray of data bytes to write to the buffer

write_data_buffer(buffer_id, data)

Write data to data buffer

Parameters
  • buffer_id – ID of data buffer to write to

  • data – bytearray of data bytes to write to buffer

write_metadata_buffer(buffer_id, data)

Write data to metadata buffer

Parameters
  • buffer_id – ID of metadata buffer to write to

  • data – Data bytes to be written to the buffer (bytearray)

pyedbglib.protocols.ati.get_ati_header(handler, handler_variant=0)

Generates an ATI header for an ATI consumer

Parameters
  • handler – Which handler to invoke

  • handler_variant – Variant (flags) of that handler

Returns

ATI header frame (bytearray)

pyedbglib.protocols.avr32protocol

Implements Avr32 Protocol, a sub-protocol in the JTAGICE3 family of protocols.

class pyedbglib.protocols.avr32protocol.Avr32Protocol(transport)

Bases: pyedbglib.protocols.jtagice3protocol.Jtagice3Protocol

Implements AVR32 protocol functionality on the JTAGICE3 protocol family

AVR32_AWIRE_BASE = 16
AVR32_CONTEXT_DEVICE = 130
AVR32_CONTEXT_PHYSICAL = 128
AVR32_CONTEXT_SESSION = 4
AVR32_CONTEXT_USB = 3
AVR32_FAILURE_OK = 0
AVR32_FLASH_CTRL_BASE = 2
AVR32_FLASH_PAGEBYTES = 6
AVR32_FLASH_PAGES = 11
AVR32_MEMTYPE_BLOCK = 131
AVR32_MEMTYPE_BYTE = 132
AVR32_MEMTYPE_FUSES = 148
AVR32_MEMTYPE_HALF_WORD = 133
AVR32_MEMTYPE_INTERNAL_FLASH = 144
AVR32_MEMTYPE_MEMORY_SERVICE = 130
AVR32_MEMTYPE_NEXUS = 129
AVR32_MEMTYPE_REGFILE = 146
AVR32_MEMTYPE_SAB = 128
AVR32_MEMTYPE_SYSREG = 145
AVR32_MEMTYPE_USER_PAGE = 147
AVR32_PHYSICAL_AWIRE_BAUD = 4
AVR32_PHYSICAL_AWIRE_MAX_BAUD = 2
AVR32_PHYSICAL_AWIRE_VERSION = 5
AVR32_PHYSICAL_DAISY = 3
AVR32_PHYSICAL_EXTERNAL_RESET = 12
AVR32_PHYSICAL_JTAG_CLOCK = 1
AVR32_PHYSICAL_PHYSICAL = 0
AVR32_PHY_INTF_AWIRE = 7
AVR32_PHY_INTF_JTAG = 4
AVR32_PHY_INTF_NONE = 0
AVR32_QUERY_COMMANDS = 0
AVR32_QUERY_COMMAND_VERSIONS = 8
AVR32_QUERY_CONFIGURATION = 5
AVR32_QUERY_DEVICE = 4
AVR32_QUERY_FAMILIES = 1
AVR32_QUERY_FUNCTIONS = 2
AVR32_QUERY_INTERFACES = 3
AVR32_QUERY_READ_MEMTYPES = 6
AVR32_QUERY_WRITE_MEMTYPES = 7
AVR32_RESET_DOMAINS = 10
AVR32_SESSION_RUN_LED = 0
AVR32_TAP_DR = 1
AVR32_TAP_IR = 0
AVR32_USB_MAX_READ = 0
AVR32_USB_MAX_WRITE = 1
CMD_AVR32_ACTIVATE_PHYSICAL = 3
CMD_AVR32_DEACTIVATE_PHYSICAL = 4
CMD_AVR32_ERASE = 17
CMD_AVR32_ERASE_SECTION = 25
CMD_AVR32_GET = 2
CMD_AVR32_GET_ID = 16
CMD_AVR32_HALT = 18
CMD_AVR32_IS_PROTECTED = 24
CMD_AVR32_QUERY = 0
CMD_AVR32_READ = 21
CMD_AVR32_RESET = 19
CMD_AVR32_SET = 1
CMD_AVR32_STEP = 20
CMD_AVR32_TAP = 23
CMD_AVR32_WRITE = 22
RSP_AVR32_DATA = 132
RSP_AVR32_DATA_PROBED = 133
RSP_AVR32_FAILED = 160
RSP_AVR32_ID = 130
RSP_AVR32_LIST = 129
RSP_AVR32_OK = 128
RSP_AVR32_PC = 131
activate_physical(use_reset=False)

Activates the physical interface

Parameters

use_reset – reset

deactivate_physical()

Deactivates the physical interface

erase()

Chip erase

get_id()

Reads the device ID

Returns

device ID

halt(value)

Apply a Halt request to the device

is_protected()

Checks if the device is protected

Returns

boolean True if protected, False if not

jtag_dr(bits, data)

Raw JTAG DR operation

Parameters
  • bits – number of bits to shift

  • data – data to shift

Returns

data shifted out

jtag_ir(bits, data)

Raw JTAG IR operation

Parameters
  • bits – number of bits to shift

  • data – data to shift

memory_read(memtype, address, num_bytes)

Read memory form the target

Parameters
  • memtype – memory type (section)

  • address – start address

  • num_bytes – number of bytes

Returns

memory read

memory_write(memtype, address, data)

Write memory to target

Parameters
  • memtype – memory type / region to access

  • address – start address

  • data – data to write

reset(value)

Apply a Reset request to the device

step()

Single steps the device

Returns

new PC value

pyedbglib.protocols.avr32protocolerrors

Mapping AVR32protocol error codes to more human friendly strings

pyedbglib.protocols.avr8protocol

Implements Avr8Protocol, a sub-protocol in the JTAGICE3 family of protocols.

class pyedbglib.protocols.avr8protocol.Avr8Protocol(transport)

Bases: pyedbglib.protocols.jtagice3protocol.Jtagice3Protocol

Implements AVR8 protocol functionality on the JTAGICE3 protocol family.

AVR8_CONFIG_FUNCTION = 1
AVR8_CONFIG_VARIANT = 0
AVR8_CTXT_CONFIG = 0
AVR8_CTXT_DEVICE = 2
AVR8_CTXT_OPTIONS = 3
AVR8_CTXT_PHYSICAL = 1
AVR8_CTXT_SESSION = 4
AVR8_CTXT_TEST = 128
AVR8_FAILURE_ACK_ERROR = 71
AVR8_FAILURE_BOOT_ERROR = 70
AVR8_FAILURE_CLOCK_ERROR = 33
AVR8_FAILURE_COLLISION = 26
AVR8_FAILURE_CRC_FAILURE = 67
AVR8_FAILURE_CS_ERROR = 66
AVR8_FAILURE_DAISY_CHAIN_CONFIG = 37
AVR8_FAILURE_DAISY_CHAIN_TOO_LONG = 36
AVR8_FAILURE_DMA_ERROR = 29
AVR8_FAILURE_DW_PHY_ERROR = 16
AVR8_FAILURE_EB_ERROR = 24
AVR8_FAILURE_FRAMING_ERROR = 28
AVR8_FAILURE_ILLEGAL_BREAKPOINT = 128
AVR8_FAILURE_ILLEGAL_ID = 58
AVR8_FAILURE_ILLEGAL_MEMORY_RANGE = 56
AVR8_FAILURE_ILLEGAL_OCD_STATUS = 61
AVR8_FAILURE_ILLEGAL_STATE = 50
AVR8_FAILURE_ILLEGAL_VALUE = 57
AVR8_FAILURE_INVALID_ADDRESS = 54
AVR8_FAILURE_INVALID_ALIGNMENT = 55
AVR8_FAILURE_INVALID_CLOCK_SPEED = 59
AVR8_FAILURE_INVALID_CONFIG = 51
AVR8_FAILURE_INVALID_MEMTYPE = 52
AVR8_FAILURE_INVALID_PHYSICAL_STATE = 49
AVR8_FAILURE_INVALID_SIZE = 53
AVR8_FAILURE_JTAGM_ERROR = 18
AVR8_FAILURE_JTAGM_INIT_ERROR = 17
AVR8_FAILURE_JTAGM_TIMEOUT = 21
AVR8_FAILURE_JTAGM_VERSION = 20
AVR8_FAILURE_JTAG_BIT_BANGER_TIMEOUT = 22
AVR8_FAILURE_JTAG_ERROR = 19
AVR8_FAILURE_KEY_ERROR = 69
AVR8_FAILURE_NOT_ATTACHED = 35
AVR8_FAILURE_NOT_IMPLEMENTED = 145
AVR8_FAILURE_NOT_SUPPORTED = 144
AVR8_FAILURE_NO_DEVICE_FOUND = 32
AVR8_FAILURE_NO_OCD_CONTROL = 80
AVR8_FAILURE_NO_TARGET_POWER = 34
AVR8_FAILURE_NO_VOUT_SET = 82
AVR8_FAILURE_NVM_DISABLE = 65
AVR8_FAILURE_NVM_ENABLE = 64
AVR8_FAILURE_OCD_LOCKED = 68
AVR8_FAILURE_OK = 0
AVR8_FAILURE_PARITY_ERROR = 23
AVR8_FAILURE_PC_READ_FAILED = 96
AVR8_FAILURE_PDI_ENABLE = 27
AVR8_FAILURE_PDI_TIMEOUT = 25
AVR8_FAILURE_PLEASE_TOGGLE_POWER = 81
AVR8_FAILURE_READ_ERROR = 112
AVR8_FAILURE_REGISTER_READ_FAILED = 97
AVR8_FAILURE_TIMEOUT = 60
AVR8_FAILURE_TOO_MANY_BREAKPOINTS = 129
AVR8_FAILURE_UNKNOWN = 255
AVR8_FAILURE_VOUT_ERROR = 83
AVR8_FAILURE_VTG_TOO_LOW_FOR_FEATURE = 84
AVR8_FAILURE_WRITE_ERROR = 113
AVR8_FAILURE_WRITE_TIMEOUT = 114
AVR8_FUNC_DEBUGGING = 2
AVR8_FUNC_NONE = 0
AVR8_FUNC_PROGRAMMING = 1
AVR8_MEMTYPE_APPL_FLASH = 192
AVR8_MEMTYPE_APPL_FLASH_ATOMIC = 194
AVR8_MEMTYPE_BOOT_FLASH = 193
AVR8_MEMTYPE_BOOT_FLASH_ATOMIC = 195
AVR8_MEMTYPE_CALIBRATION_SIGNATURE = 198
AVR8_MEMTYPE_CAN = 182
AVR8_MEMTYPE_CS = 208
AVR8_MEMTYPE_EEPROM = 34
AVR8_MEMTYPE_EEPROM_ATOMIC = 196
AVR8_MEMTYPE_EEPROM_PAGE = 177
AVR8_MEMTYPE_FLASH_PAGE = 176
AVR8_MEMTYPE_FUSES = 178
AVR8_MEMTYPE_IO_SHADOW = 48
AVR8_MEMTYPE_LOCKBITS = 179
AVR8_MEMTYPE_OCD = 209
AVR8_MEMTYPE_OCD_PC = 20
AVR8_MEMTYPE_OCD_SP = 24
AVR8_MEMTYPE_OCD_SREG = 28
AVR8_MEMTYPE_OSCCAL = 181
AVR8_MEMTYPE_REGFILE = 184
AVR8_MEMTYPE_SIB = 211
AVR8_MEMTYPE_SIGNATURE = 180
AVR8_MEMTYPE_SPM = 160
AVR8_MEMTYPE_SRAM = 32
AVR8_MEMTYPE_TBUS = 183
AVR8_MEMTYPE_USER_SIGNATURE = 197
AVR8_OPT_12V_UPDI_ENABLE = 6
AVR8_OPT_CHIP_ERASE_TO_ENTER = 7
AVR8_OPT_DISABLE_DBP = 1
AVR8_OPT_ENABLE_IDR = 3
AVR8_OPT_HV_UPDI_ENABLE = 6
AVR8_OPT_POLL_INT = 4
AVR8_OPT_POWER_NAP = 5
AVR8_OPT_RUN_TIMERS = 0
AVR8_PHY_DW_CLK_DIV = 16
AVR8_PHY_INTERFACE = 0
AVR8_PHY_INTF_DW = 5
AVR8_PHY_INTF_JTAG = 4
AVR8_PHY_INTF_NONE = 0
AVR8_PHY_INTF_PDI = 6
AVR8_PHY_INTF_PDI_1W = 8
AVR8_PHY_INTF_PDI_3W = 10
AVR8_PHY_JTAG_DAISY = 1
AVR8_PHY_MEGA_DBG_CLK = 33
AVR8_PHY_MEGA_PRG_CLK = 32
AVR8_PHY_XM_JTAG_CLK = 48
AVR8_PHY_XM_PDI_CLK = 49
AVR8_TEST_TGT_RUNNING = 0
AVR8_VARIANT_LOOPBACK = 0
AVR8_VARIANT_MEGAOCD = 2
AVR8_VARIANT_NONE = 255
AVR8_VARIANT_TINYOCD = 1
AVR8_VARIANT_TINYX = 5
AVR8_VARIANT_UPDI = 5
AVR8_VARIANT_XMEGA = 3
CMD_AVR8_ACTIVATE_PHYSICAL = 16
CMD_AVR8_ATTACH = 19
CMD_AVR8_CRC = 36
CMD_AVR8_DEACTIVATE_PHYSICAL = 17
CMD_AVR8_DETACH = 20
CMD_AVR8_DISABLE_DEBUGWIRE = 23
CMD_AVR8_ERASE = 32
CMD_AVR8_EXECUTE_PATCH = 112
CMD_AVR8_GET = 2
CMD_AVR8_GET_ID = 18
CMD_AVR8_HW_BREAK_CLEAR = 65
CMD_AVR8_HW_BREAK_SET = 64
CMD_AVR8_MEMORY_READ = 33
CMD_AVR8_MEMORY_READ_MASKED = 34
CMD_AVR8_MEMORY_WRITE = 35
CMD_AVR8_PAGE_ERASE = 80
CMD_AVR8_PC_READ = 53
CMD_AVR8_PC_WRITE = 54
CMD_AVR8_PROG_MODE_ENTER = 21
CMD_AVR8_PROG_MODE_LEAVE = 22
CMD_AVR8_QUERY = 0
CMD_AVR8_RESET = 48
CMD_AVR8_RUN = 50
CMD_AVR8_RUN_TO_ADDRESS = 51
CMD_AVR8_SET = 1
CMD_AVR8_STEP = 52
CMD_AVR8_STOP = 49
CMD_AVR8_SW_BREAK_CLEAR = 68
CMD_AVR8_SW_BREAK_CLEAR_ALL = 69
CMD_AVR8_SW_BREAK_SET = 67
ERASE_APP = 1
ERASE_APP_PAGE = 4
ERASE_BOOT = 2
ERASE_BOOT_PAGE = 5
ERASE_CHIP = 0
ERASE_EEPROM = 3
ERASE_EEPROM_PAGE = 6
ERASE_USERSIG = 7
EVT_AVR8_BREAK = 64
EVT_AVR8_BREAK_CAUSE = 5
EVT_AVR8_BREAK_EVT_ID = 0
EVT_AVR8_BREAK_EXT_INFO = 6
EVT_AVR8_BREAK_PC = 1
EVT_AVR8_IDR = 65
RSP_AVR8_DATA = 132
RSP_AVR8_FAILED = 160
RSP_AVR8_LIST = 129
RSP_AVR8_OK = 128
RSP_AVR8_PC = 131
UPDI_12V_NONE = 0
UPDI_HV_AUTO_POWER_TOGGLE = 2
UPDI_HV_NONE = 0
UPDI_HV_SIMPLE_PULSE = 1
UPDI_HV_USER_POWER_TOGGLE = 3
activate_physical(use_reset=False)

Activates the physical interface

Parameters

use_reset – reset

attach(do_break=False)

Attaches the debugger to the target

Parameters

do_break – break execution on attach?

configure_daisy_chain(settings)

Sets the daisy-chain fields in the physical context

Parameters

settings – array of daisy-chain info

deactivate_physical()

Deactivates the physical interface

debugwire_disable()

Disables debugWIRE interface temporarily

decode_break_event(event)
Decodes a break event in JTAGICE3 format

BRK 0x40 version PC[0] PC[1] PC[2] PC[3] cause ext-info H ext-info L

Parameters

event – event information for parsing

Returns

Program Counter value if it is a break event, None otherwise

detach()

Detaches the debugger from the target

enter_progmode()

Enters programming mode

erase(mode=0, address=0)

Erase target flash

Parameters
  • mode – flash erase mode to use

  • address – start address to erase from

error_as_string(code)

Get the response error as a string (error code translated to descriptive string)

Returns

error code as descriptive string

get_id()

Reads the device ID

Returns

device ID

leave_progmode()

Exits programming mode

memory_read(memtype, address, num_bytes)

Read memory form the target

Parameters
  • memtype – memory type (section)

  • address – start address

  • num_bytes – number of bytes

Returns

memory read

memory_write(memtype, address, data)

Write memory to target

Parameters
  • memtype – memory type / region to access

  • address – start address

  • data – data to write

program_counter_read()

Reads out the program counter

Returns

PC value

program_counter_write(program_counter)

Writes the program counter

Parameters

program_counter – new program counter value

regfile_read()

Reads out the AVR register file (R0::R31)

Returns

32 bytes of register file content as bytearray

regfile_write(data)

Writes the AVR registe file (R0::R31)

Parameters

data – 32 byte register file content as bytearray

Raises

ValueError – if 32 bytes are not given

reset()

Resets the core and holds it in reset

run()

Resumes core execution

run_to(address)

Runs to the given address.

A BREAK event will be generated when/if it reaches the address.

Parameters

address – address to run to

set_function(debugger_function)

Sets the function field in the config context

Parameters

debugger_function – function of this session (prog / debug)

set_interface(interface)

Sets the function field in the physical context

Parameters

interface – physical interface setting

set_variant(variant)

Sets the variant field in the config context

Parameters

variant – type of device

software_breakpoint_clear(address)

Removes a software breakpoint from the given address

Parameters

address – breakpoint address

software_breakpoint_clear_all()

Clears all software breakpoints

software_breakpoint_set(address)

Insert a software breakpoint at the given address

Parameters

address – breakpoint address

step()

Executes a single-step on the core.

A BREAK event will be generated when it has completed. This behaviour originates from previous debuggers which could do C level stepping which took time.

stop()

Requests a core halt.

A BREAK even will be generated when it has successfully stopped.

write_device_data(data)

Write device info into the device context

Parameters

data – device data content

pyedbglib.protocols.avr8protocolerrors

Mapping AVR8protocol error codes to more human friendly strings

pyedbglib.protocols.avrcmsisdap

CMSIS-DAP wrapper for custom commands (using vendor extensions) This mechanism is used to pass JTAGICE3-style commands for AVR devices over the CMSIS-DAP interface

class pyedbglib.protocols.avrcmsisdap.AvrCommand(transport, no_timeouts=False)

Bases: pyedbglib.protocols.cmsisdap.CmsisDapUnit

Wraps AVR command and responses

AVR_CMD_COMMAND_HEADER_CMD = 0
AVR_CMD_COMMAND_HEADER_FRAGMENT_NUMBER = 1
AVR_CMD_COMMAND_HEADER_PAYLOAD_START = 4
AVR_CMD_COMMAND_HEADER_SIZE = 2
AVR_CMD_RESPONSE_FRAGMENT_CODE = 1
AVR_CMD_RESPONSE_HEADER_CMD = 0
AVR_COMMAND = 128
AVR_COMMAND_RESPONSE_MAX_PAYLOAD = 512
AVR_EVENT = 130
AVR_EVENT_COMMAND_HEADER_EVT = 0
AVR_EVENT_RESPONSE_HEADER_EVT = 0
AVR_EVENT_RESPONSE_HEADER_PAYLOAD_START = 3
AVR_EVENT_RESPONSE_HEADER_SIZE = 1
AVR_EVENT_RESPONSE_MAX_SIZE = 61
AVR_EVENT_RESPONSE_MIN_SIZE = 6
AVR_FINAL_FRAGMENT = 1
AVR_MORE_FRAGMENTS = 0
AVR_RESPONSE = 129
AVR_RETRY_DELAY_MS = 50
AVR_RSP_COMMAND_HEADER_RSP = 0
AVR_RSP_RESPONSE_HEADER_FRAGMENT_NUMBER = 1
AVR_RSP_RESPONSE_HEADER_PAYLOAD_START = 4
AVR_RSP_RESPONSE_HEADER_RSP = 0
AVR_RSP_RESPONSE_HEADER_SIZE = 2
avr_command_response(command)

Sends an AVR command and receives a response

Parameters

command – Command bytes to send

Returns

Response bytes received

poll_events()

Polling for events from AVRs

Returns

bytearray containing a received event, or None

exception pyedbglib.protocols.avrcmsisdap.AvrCommandError

Bases: Exception

Exception type for AVR command-response wrapping

pyedbglib.protocols.avrispprotocol

Simple wrapper for AVR ISP programming protocol over JTAGICE3 transport

Important note:

The AVR ISP protocol dates back to very early AVR devices. Many of the parametric information included in the protocol metadata applies only to those old devices. This is not a universal implementation, and does not draw any such information from the XML descriptions included in Atmel Studio (ATDF) and MPLABX. It does work on ATmega328P and close relatives.

TODO: use SPI CLOCK settings TODO: add more memory types

class pyedbglib.protocols.avrispprotocol.AvrIspProtocol(transport)

Bases: pyedbglib.protocols.jtagice3protocol.Jtagice3Protocol

Protocol wrapper

AVR_ERASE_COMMAND = [172, 128]
AVR_ERASE_DELAY = 45
AVR_ERASE_POLLMODE = 1
AVR_LOAD_PAGE_COMMAND = 64
AVR_POLL_VALUE = 83
AVR_POST_LEAVE_DELAY_MS = 1
AVR_PRE_LEAVE_DELAY_MS = 1
AVR_PROG_ENABLE_COMMAND = [172, 83, 0, 0]
AVR_READ_CALIBRATION_BYTE_COMMAND = [56, 0, 0, 0]
AVR_READ_EEPROM_COMMAND = 160
AVR_READ_FLASH_COMMAND = 32
AVR_READ_FUSE_COMMANDS = [[80, 0, 0, 0], [88, 8, 0, 0], [80, 8, 0, 0]]
AVR_READ_LOCK_COMMAND = [88, 0, 0, 0]
AVR_READ_SIGNATURE_COMMAND = [48, 0, 0, 0]
AVR_REPLY_OFFSET = 3
AVR_WRITE_FUSE_COMMANDS = [[172, 160, 0], [172, 168, 0], [172, 164, 0]]
AVR_WRITE_LOCK_COMMAND = [172, 224, 0]
AVR_WRITE_PAGE_COMMAND = 76
BYTE_DELAY = 0
FUNC_DELAY = 25
PIN_DELAY = 100
SPI_CMD_CHIP_ERASE = 18
SPI_CMD_ENTER_PROGMODE = 16
SPI_CMD_GET_BAUD = 30
SPI_CMD_LEAVE_PROGMODE = 17
SPI_CMD_LOAD_ADDRESS = 6
SPI_CMD_PROGRAM_EEPROM = 21
SPI_CMD_PROGRAM_FLASH = 19
SPI_CMD_PROGRAM_FUSE = 23
SPI_CMD_PROGRAM_LOCK = 25
SPI_CMD_READ_EEPROM = 22
SPI_CMD_READ_FLASH = 20
SPI_CMD_READ_FUSE = 24
SPI_CMD_READ_LOCK = 26
SPI_CMD_READ_OSCCAL = 28
SPI_CMD_READ_SIGNATURE = 27
SPI_CMD_SET_BAUD = 29
SPI_CMD_SIGN_ON = 1
SPI_STATUS_BAUD_INVALID = 205
SPI_STATUS_CLOCK_ERROR = 204
SPI_STATUS_CMD_FAILED = 192
SPI_STATUS_CMD_OK = 0
SPI_STATUS_CMD_TOUT = 128
SPI_STATUS_CMD_UNKNOWN = 201
SPI_STATUS_PHY_ERROR = 203
SPI_STATUS_RDY_BSY_TOUT = 129
SYNC_LOOPS = 32
enter_progmode()

Enter programming mode

erase()

Chip erase

get_id()

Read device ID

leave_progmode()

Leave programming mode

load_address(address)

Loads the address pointer (stored in FW)

read_calibration_bytes(offset, numbytes)

Read device calibration bytes

Parameters
  • offset – offset to read from

  • numbytes – number of bytes to read

read_eeprom_chunk(byte_address, numbytes)

Reads a chunk of eeprom memory

Parameters
  • byte_address – start address

  • numbytes – number of bytes

Returns

data read

read_flash_chunk(byte_address, numbytes)

Reads a chunk of flash memory

Parameters
  • byte_address – start address

  • numbytes – number of bytes

Returns

data read

read_fuse_byte(offset)

Read fuse bytes

Parameters

offset – offset to read from

read_lockbits()

Read lockbits

read_signature_bytes(offset, numbytes)

Read device signature bytes

Parameters
  • offset – offset to read from

  • numbytes – number of bytes to read

write_eeprom_page(byte_address, data)

Writes a page of eeprom

Parameters
  • byte_address – start address

  • data – data to write

write_flash_page(byte_address, data)

Writes a page of flash

Parameters
  • byte_address – start address

  • data – data to write

write_fuse_byte(offset, data)

Write fuse byte

Parameters
  • offset – offset to write to

  • data – data value to write

write_lockbits(data)

Write lockbits

Parameters

data – data value to write

exception pyedbglib.protocols.avrispprotocol.AvrIspProtocolError

Bases: Exception

Exception type for AVRISP command-response wrapping

pyedbglib.protocols.cmsisdap

CMSIS DAP access protocol

Interfaces with CMSIS-DAP standard debuggers over HID

class pyedbglib.protocols.cmsisdap.CmsisDapDebugger(transport)

Bases: pyedbglib.protocols.cmsisdap.CmsisDapUnit

ARM-specific cmsis-dap implementation

CDBGPWRUPACK = 536870912
CDBGPWRUPREQ = 268435456
CDBGRSTACK = 134217728
CDBGRSTREQ = 67108864
CM0P_DAPID = 197203063
CSW_16BIT = 1
CSW_32BIT = 2
CSW_8BIT = 0
CSW_ADDRINC_OFF = 0
CSW_ADDRINC_ON = 16
CSYSPWRUPACK = 2147483648
CSYSPWRUPREQ = 1073741824
DAP_SWJ_SWCLK_TCK = 1
DAP_SWJ_SWDIO_TMS = 2
DAP_SWJ_TDI = 4
DAP_SWJ_TDO = 8
DAP_SWJ_nRESET = 128
DAP_SWJ_nTRST = 32
DAP_TRANSFER_A2 = 4
DAP_TRANSFER_A3 = 8
DAP_TRANSFER_APnDP = 1
DAP_TRANSFER_ERROR = 8
DAP_TRANSFER_FAULT = 4
DAP_TRANSFER_INVALID = 0
DAP_TRANSFER_MATCH_MASK = 32
DAP_TRANSFER_MATCH_VALUE = 16
DAP_TRANSFER_MISMATCH = 16
DAP_TRANSFER_OK = 1
DAP_TRANSFER_RnW = 2
DAP_TRANSFER_WAIT = 2
DP_ABORT = 0
DP_CTRL_STAT = 4
DP_IDCODE = 0
DP_RDBUFF = 12
DP_RESEND = 8
DP_SELECT = 8
DP_WCR = 4
JTAG_ABORT = 8
JTAG_APACC = 11
JTAG_BYPASS = 15
JTAG_DPACC = 10
JTAG_IDCODE = 14
ORUNDETECT = 1
READOK = 64
STICKYCMP = 16
STICKYERR = 32
STICKYORUN = 2
SWD_AP_CSW = 0
SWD_AP_DRW = 12
SWD_AP_TAR = 4
TAR_MAX = 1024
TRNMODE = 4
WDATAERR = 128
dap_read_idcode()

Reads the IDCODE from the SWD DP

dap_read_reg(reg)

Reads a DAP AP/DP register

Parameters

reg – register to read

Raises

PyedbglibError – if the read fails

dap_reset_target()

Reset the target using the DAP

Raises

PyedbglibError – if the reset fails

dap_swd_configure(cfg)

Configures the SWD interface

Parameters

cfg – turnaround and data phase config parameters

Raises

PyedbglibError – if the configuration fails

dap_swj_clock(clock)

Sets up the SWD clock timing

Parameters

clock – clock value in Hz

Raises

PyedbglibError – if the configuration fails

dap_target_init()

Configures the DAP for use

dap_transfer_configure(idle, count, retry)

Configures SWD transfers

Parameters
  • idle – idle cycles

  • count – retry count

  • retry – match retry value

Raises

PyedbglibError – if the configuration fails

dap_write_reg(reg, value)

Writes a DAP AP/DP register

Parameters
  • reg – register to write

  • value – value to write

Raises

PyedbglibError – if the write fails

init_swj()

Magic sequence to execute on pins to enable SWD in case of JTAG-default parts

Raises

PyedbglibError – if the sequence execution fails

static multiple_of_four(x)

4 byte boundary

read_block(address, numbytes)

Reads a block from the device memory bus

Parameters
  • address – byte address

  • numbytes – number of bytes

Raises

PyedbglibError – if the transfer fails

read_word(address)

Reads a word from the device memory bus

Parameters

address – address to read

write_block(address, data)

Writes a block to the device memory bus

Parameters
  • address – byte address

  • data – data

write_word(address, data)

Writes a word to the device memory bus

Parameters
  • address – address to write

  • data – data to write

class pyedbglib.protocols.cmsisdap.CmsisDapSamDebugger(transport)

Bases: pyedbglib.protocols.cmsisdap.CmsisDapDebugger

SAM specific CMSIS-DAP debugger

dap_reset_ext(extend=False)

Reset the target using the hardware

Some SAM devices (for example SAMDx and SAMLx) have an additional ‘reset extension’ capability which is not part of the CMSIS-DAP standard. It is used to prevent the device from running after reset and then overriding its SWD IO. The procedure is simply to hold SW_CLK low while releasing /RESET. This is done here using SWJ pins function IF the extend argument is set.

Parameters

extend – boolean flag to extend reset

class pyedbglib.protocols.cmsisdap.CmsisDapUnit(transport)

Bases: pyedbglib.protocols.dapwrapper.DapWrapper

Communicates with a DAP via standard CMSIS-DAP firmware stack over HID transport

DAP_ERROR = 255
DAP_ID_CAPABILITIES = 240
DAP_ID_DEVICE_NAME = 6
DAP_ID_DEVICE_VENDOR = 5
DAP_ID_FW_VER = 4
DAP_ID_PACKET_COUNT = 254
DAP_ID_PACKET_SIZE = 255
DAP_ID_PRODUCT = 2
DAP_ID_SER_NUM = 3
DAP_ID_VENDOR = 1
DAP_OK = 0
DAP_PORT_AUTODETECT = 0
DAP_PORT_DISABLED = 0
DAP_PORT_JTAG = 2
DAP_PORT_SWD = 1
ID_DAP_Connect = 2
ID_DAP_Delay = 9
ID_DAP_Disconnect = 3
ID_DAP_HostStatus = 1
ID_DAP_Info = 0
ID_DAP_JTAG_Configure = 21
ID_DAP_JTAG_IDCODE = 22
ID_DAP_JTAG_Sequence = 20
ID_DAP_ResetTarget = 10
ID_DAP_SWD_Configure = 19
ID_DAP_SWJ_Clock = 17
ID_DAP_SWJ_Pins = 16
ID_DAP_SWJ_Sequence = 18
ID_DAP_Transfer = 5
ID_DAP_TransferAbort = 7
ID_DAP_TransferBlock = 6
ID_DAP_TransferConfigure = 4
ID_DAP_WriteABORT = 8
dap_connect()

Connects to the DAP

dap_disconnect()

Disconnects from the DAP

dap_info()

Collects the dap info

dap_led(index, state)

Operates the LED

Parameters
  • index – which led

  • state – what to do with it

pyedbglib.protocols.configprotocol

Kit configuration programming protocol layer This protocol is used in manufacturing to provision Curiosity Nano kits. It is not intended for end-user usage - for kit customisation use the pydebuggerconfig package.

class pyedbglib.protocols.configprotocol.ConfigProtocol(transport)

Bases: pyedbglib.protocols.dapwrapper.DapWrapper

Transport layer for programming and reading device config

GET_CONFIG = 131
RSP_OK = 0
SET_CONFIG = 132
fix(fix_data)

Checks if the incoming data is OK to send

Parameters

fix_data – Input data

Returns

list of valid data to send

get_config(offset, byte_count)

Low level function to read configuration data from target.

Parameters
  • offset – Offset to read from

  • byte_count – Number of bytes to read

Returns

Response byte + data

read_config_block(factory=False)

Read the configuration block

Parameters

factory – Default false, use true for factory programming

Returns

Configuration from the target

read_device_data_block()

Read the device data block

Returns

Device data block

set_config(offset, data)

Block programming of configuration data

Parameters
  • offset – Offset to start programming

  • data – Configuration data to program

set_transport(transport)

Set the transport for the protocol if not set at init

Parameters

transport – Transport to use

tool_check()

Check if transport has been initialised

Raises

IOError – if not initialised

write_config_block(config, factory=False)

Read the configuration block

Parameters
  • config – Configuration data to be written to target

  • factory – Use true to program the factory section

write_device_data_block(device_data)

Write the device data block

Parameters

device_data – Device data to write

exception pyedbglib.protocols.configprotocol.ConfigProtocolResponseError(msg, code)

Bases: Exception

Exception type for Config protocol responses

pyedbglib.protocols.configprotocol.create_blank_config_block()

Create a blank config block

Returns

Blank config block

pyedbglib.protocols.configprotocol.create_blank_device_data_block()

Create a blank device data block

Returns

Blank device data block

pyedbglib.protocols.dapcommand

DAP information wrapper for any CMSIS-DAP tool

class pyedbglib.protocols.dapcommand.DapCommand(transport)

Bases: pyedbglib.protocols.dapwrapper.DapWrapper

DAP information wrapper for any CMSIS-DAP tool

get_all_info()

Fetches a set of useful information from the DAP

Returns

dictionary of parameters

info(dap_id)

Fetch specific DAP information given by dap_id

Parameters

dap_id – code for different DAP_ID_* fields

Returns

bytearray with dap information

pyedbglib.protocols.dapwrapper

Wrapper for any protocol over CMSIS-DAP

class pyedbglib.protocols.dapwrapper.DapWrapper(transport)

Bases: object

Base class for any CMSIS-DAP protocol wrapper

dap_command_read()

Receive data

Returns

data received

dap_command_response(packet)

Send a command, receive a response

Parameters

packet – bytes to send

Returns

response received

dap_command_write(packet)

Send a packet

Parameters

packet – packed data to sent

Returns

bytes sent

pyedbglib.protocols.edbgprotocol

Implements EDBG Protocol, a sub-protocol in the JTAGICE3 family of protocols.

class pyedbglib.protocols.edbgprotocol.EdbgProtocol(transport)

Bases: pyedbglib.protocols.jtagice3protocol.Jtagice3Protocol

Implements EDBG protocol functionality on the JTAGICE3 protocol family

AVR_GET_CONFIG = 131
CMD_EDBG_GET = 2
CMD_EDBG_PROGRAM_ID_CHIP = 80
CMD_EDBG_QUERY = 0
CMD_EDBG_READ_ID_CHIP = 126
CMD_EDBG_REFRESH_ID_CHIP = 81
CMD_EDBG_SET = 1
EDBG_CONFIG_KIT_DATA = 32

Mapping EDBG error codes to more human friendly strings

EDBG_CONTROL_EXT_PROG = 1
EDBG_CONTROL_LED_USAGE = 0
EDBG_CONTROL_TARGET_POWER = 16
EDBG_CTXT_CONTROL = 0
EDBG_ERRORS = {0: 'SUCCESS'}

Mapping SHA204 response codes to more human friendly strings

EDBG_QUERY_COMMANDS = 0
RESPONSE_CODE = {0: 'SHA204_SUCCESS', 210: 'SHA204_PARSE_ERROR', 211: 'SHA204_CMD_FAIL', 212: 'SHA204_STATUS_CRC', 224: 'SHA204_FUNC_FAIL', 226: 'SHA204_BAD_PARAM', 228: 'SHA204_INVALID_SIZE', 229: 'SHA204_BAD_CRC', 230: 'SHA204_RX_FAIL', 231: 'SHA204_RX_NO_RESPONSE', 232: 'SHA204_RESYNC_WITH_WAKEUP', 240: 'SHA204_COMM_FAIL', 241: 'SHA204_TIMEOUT', 250: 'ID_DATA_LOCKED', 251: 'ID_CONFIG_LOCKED', 252: 'ID_INVALID_SLOT', 253: 'ID_DATA_PARSING_ERROR', 254: 'ID_DATA_NOT_EQUAL'}
RSP_EDBG_DATA = 132
RSP_EDBG_FAILED = 160
RSP_EDBG_LIST = 129
RSP_EDBG_OK = 128
check_command_exists(command)

Check if command is supported

Runs a query to the tool to get a list of supported commands, then looks for the input command in the list. If not supported, it raises NotImplementedError.

Parameters

command – The command to test.

error_as_string(code)

Get the response error as a string (error code translated to descriptive string)

Parameters

code – error code

Returns

error code as descriptive string

program_id_chip(id_number, data)

Program the connected ID device located at the id_number with data.

Parameters
  • id_number – Extension header ID number (Range 1 - 16)

  • data – A 64-byte data array to be programmed

Returns

Response status from the programming

read_edbg_extra_info()

Reads the kit info flash page, containing board specific data

Returns

A data array containing the kit info

read_id_chip(id_number)

Reads the ID information from the ID chip connected at id_number

Parameters

id_number – Extension header ID number (Range 1 - 16)

Returns

A 64-byte data array

refresh_id_chip()

Forces a refresh of the list of connected ID devices.

Raises

IOError – if an invalid response is received

response_as_string(code)

Get the response code as a string (response code translated to descriptive string)

Parameters

code – response code

Returns

error code as descriptive string

pyedbglib.protocols.housekeepingprotocol

Implements Housekeeping Protocol, a sub-protocol in the JTAGICE3 family of protocols.

class pyedbglib.protocols.housekeepingprotocol.Jtagice3HousekeepingProtocol(transport)

Bases: pyedbglib.protocols.jtagice3protocol.Jtagice3Protocol

Implements housekeeping functionality on the JTAGICE3 protocol family

CMD_HOUSEKEEPING_END_SESSION = 17
CMD_HOUSEKEEPING_FW_UPGRADE = 80
CMD_HOUSEKEEPING_START_SESSION = 16
HOUSEKEEPING_ABILITY_HV_UPDI_ENABLE = 16
HOUSEKEEPING_ABILITY_RESET_EXTENSION = 0
HOUSEKEEPING_ANALOG_VTG_BUF = 1
HOUSEKEEPING_ANALOG_VTREF = 0
HOUSEKEEPING_ANALOG_VUSB = 2
HOUSEKEEPING_CONFIG_AUX_MCU_FW_MAJ = 32
HOUSEKEEPING_CONFIG_AUX_MCU_FW_MIN = 33
HOUSEKEEPING_CONFIG_AUX_MCU_FW_REV = 34
HOUSEKEEPING_CONFIG_BLDR_MAJ = 6
HOUSEKEEPING_CONFIG_BLDR_MIN = 7
HOUSEKEEPING_CONFIG_BUILD = 3
HOUSEKEEPING_CONFIG_CHIP = 5
HOUSEKEEPING_CONFIG_DEBUG_BUILD = 8
HOUSEKEEPING_CONFIG_FIRMWARE_IMAGE = 9
HOUSEKEEPING_CONFIG_FPGA_FW_MAJ = 16
HOUSEKEEPING_CONFIG_FPGA_FW_MIN = 17
HOUSEKEEPING_CONFIG_FPGA_FW_REV = 18
HOUSEKEEPING_CONFIG_FWREV_MAJ = 1
HOUSEKEEPING_CONFIG_FWREV_MIN = 2
HOUSEKEEPING_CONFIG_HWREV = 0
HOUSEKEEPING_CONTEXT_ANALOG = 1
HOUSEKEEPING_CONTEXT_CONFIG = 0
HOUSEKEEPING_CONTEXT_DIAGNOSTICS = 129
HOUSEKEEPING_CONTEXT_STATEMENT = 2
HOUSEKEEPING_CONTEXT_STATISTICS = 128
HOUSEKEEPING_CONTEXT_USB = 3
HOUSEKEEPING_DIAGNOSTICS_BOD_CTRL = 1
HOUSEKEEPING_DIAGNOSTICS_CPU_CLK = 6
HOUSEKEEPING_DIAGNOSTICS_RESET_CAUSE = 0
HOUSEKEEPING_HOST_ID = 2
HOUSEKEEPING_HOST_REV = 3
HOUSEKEEPING_MODULE_VER_AW = 5
HOUSEKEEPING_MODULE_VER_JTAG = 4
HOUSEKEEPING_QUERY_ANALOG_CHANNELS = 1
HOUSEKEEPING_QUERY_COMMANDS = 0
HOUSEKEEPING_QUERY_SPECIAL_ABILITIES = 2
HOUSEKEEPING_TSUP_VOLTAGE = 32
HOUSEKEEPING_USB_EP_SIZE_CDC = 17
HOUSEKEEPING_USB_EP_SIZE_HID = 16
HOUSEKEEPING_USB_MAX_READ = 0
HOUSEKEEPING_USB_MAX_WRITE = 1
end_session(reset_tool=False)

Ends a session with the debugger (sign-off)

Parameters

reset_tool – resets the hardware

enter_upgrade_mode(key=829586448)

Puts the debugger into firmware upgrade mode

Parameters

key – upgrade key

list_supported_commands()

Uses the query interface to list all supported commands

read_version_info()

Reads version info from the debugger

start_session()

Starts a session with the debugger (sign-on)

pyedbglib.protocols.jtagice3protocol

JTAGICE3 protocol mappings

class pyedbglib.protocols.jtagice3protocol.Jtagice3Command(transport, handler)

Bases: pyedbglib.protocols.avrcmsisdap.AvrCommand

Sends a “JTAGICE3” command frame, and received a response

JTAGICE3 protocol header is formatted:

JTAGICE3_TOKEN 0x0E PROTOCOL_VERSION 0 SEQUENCE_NUMBER_L SEQUENCE_NUMBER_H HANDLER_ID PAYLOAD

Response format is:

JTAGICE3_TOKEN 0x0E SEQUENCE_NUMBER_L echo SEQUENCE_NUMBER_H echo HANDLER_ID PAYLOAD

EVENT_HANDLER_IDS = [1, 18]
HANDLER_AVR32_GENERIC = 19
HANDLER_AVR8_GENERIC = 18
HANDLER_COPROCESSOR = 33
HANDLER_DISCOVERY = 0
HANDLER_EDBG = 32
HANDLER_HOUSEKEEPING = 1
HANDLER_POWER = 34
HANDLER_SELFTEST = 129
HANDLER_SPI = 17
HANDLER_TPI = 20
JTAGICE3_HEADER_COMMAND_HANDLER_ID = 4
JTAGICE3_HEADER_COMMAND_PAYLOAD_START = 5
JTAGICE3_HEADER_COMMAND_PROTOCOL_VERSION = 1
JTAGICE3_HEADER_COMMAND_SEQUENCE = 2
JTAGICE3_HEADER_COMMAND_SOF_TOKEN = 0
JTAGICE3_HEADER_EVENT_HANDLER_ID = 4
JTAGICE3_HEADER_EVENT_PAYLOAD_START = 5
JTAGICE3_HEADER_EVENT_PROTOCOL_VERSION = 1
JTAGICE3_HEADER_EVENT_SEQUENCE = 2
JTAGICE3_HEADER_EVENT_SOF_TOKEN = 0
JTAGICE3_HEADER_RESPONSE_HANDLER_ID = 3
JTAGICE3_HEADER_RESPONSE_PAYLOAD_START = 4
JTAGICE3_HEADER_RESPONSE_SEQUENCE = 1
JTAGICE3_HEADER_RESPONSE_SOF_TOKEN = 0
JTAGICE3_PROTOCOL_VERSION = 0
JTAGICE3_TOKEN = 14
jtagice3_command_response(command)

Sends a JTAGICE3 command and receives the corresponding response, and validates it

Parameters

command – bytearray command to send

jtagice3_command_response_raw(command)

Sends a JTAGICE3 command and receives the corresponding response

Parameters

command – bytearray command to send

validate_response(response)

Validates the response form the debugger

Parameters

response – raw response bytes

Raises

PyedbglibError – if validation fails

class pyedbglib.protocols.jtagice3protocol.Jtagice3Protocol(transport, handler, supports_trailing_status=True)

Bases: pyedbglib.protocols.jtagice3protocol.Jtagice3Command

Base class for all protocols in the JTAGICE3 family.

All sub-protocols support query, get and set commands.

CMD_GET = 2
CMD_QUERY = 0
CMD_SET = 1
CMD_VERSION0 = 0
CMD_VERSION1 = 1
FAILURE_OK = 0
JTAGICE3_ERRORS = {0: 'SUCCESS'}
PROTOCOL_DATA = 132
PROTOCOL_FAILED = 160
PROTOCOL_HEADER_RESPONSE_ID = 0
PROTOCOL_HEADER_RESPONSE_PAYLOAD = 2
PROTOCOL_HEADER_RESPONSE_VERSION = 1
PROTOCOL_LIST = 129
PROTOCOL_OK = 128
SETGET_FAILURE_HANDLER_ERROR = 48

Mapping JTAGICE3 error codes to more human friendly strings

SETGET_FAILURE_ILLEGAL_STATE = 33
SETGET_FAILURE_INVALID_CLOCK_SPEED = 32
SETGET_FAILURE_INVALID_VALUE = 35
SETGET_FAILURE_JTAGM_INIT_ERROR = 34
SETGET_FAILURE_NOT_IMPLEMENTED = 16
SETGET_FAILURE_NOT_SUPPORTED = 17
SETGET_FAILURE_OK = 0
check_response(response, expected=None)

Checks the response for known errors

Parameters
  • response – response bytes

  • expected – expected response

Returns

data from response

error_as_string(code)

Get the response error as a string (error code translated to descriptive string)

Parameters

code – error code

Returns

error code as descriptive string

get_byte(context, offset)

Get a single-byte parameter

Parameters
  • context – context (address) to set

  • offset – offset address to set

Returns

value read

get_le16(context, offset)

Get a little-endian 16-bit parameter

Parameters
  • context – context (address) to set

  • offset – offset address to set

Returns

value read

get_le32(context, offset)

Get a little-endian 32-bit parameter

Parameters
  • context – context (address) to set

  • offset – offset address to set

Returns

value read

peel_response(response, expected=None)

Process the response, extracting error codes and data

Parameters
  • response – raw response bytes

  • expected – expected response

Returns

status, data

poll_events()

Polls for JTAGICE3 protocol events

Events are framed as:

SOF 0x0E version sequence H sequence L HANDLER ID [n] * PAYLOAD

Returns

bytearray containing a received event, or None

query(context)

Queries functionality using the QUERY API

Parameters

context – Query context

Returns

List of supported entries

Raises

PyedbglibError – if the query fails

set_byte(context, offset, value)

Sets a single byte parameter

Parameters
  • context – context (address) to set

  • offset – offset address to set

  • value – value to set

set_le16(context, offset, value)

Sets a little-endian 16-bit parameter

Parameters
  • context – context (address) to set

  • offset – offset address to set

  • value – value to set

set_le32(context, offset, value)

Sets a little-endian 32-bit parameter

Parameters
  • context – context (address) to set

  • offset – offset address to set

  • value – value to set

exception pyedbglib.protocols.jtagice3protocol.Jtagice3ResponseError(msg, code)

Bases: Exception

Exception type for JTAGICE3 responses

pyedbglib.protocols.selftestprotocol

Implements SelftestProtocol, a sub-protocol in the JTAGICE3 family of protocols.

class pyedbglib.protocols.selftestprotocol.SelftestProtocol(transport)

Bases: pyedbglib.protocols.jtagice3protocol.Jtagice3Protocol

Implementation of the tool selftest protocol. This protocol is used for kit production and firmware testing purposes. Not all tools support all commands.

CMD_SELFTEST_DELAY_MS = 17
CMD_SELFTEST_DELAY_S = 16
CMD_SELFTEST_DELAY_US = 18
CMD_SELFTEST_DGI_PIN_RAW_READ = 32
CMD_SELFTEST_PLATFORM = 240
CMD_SELFTEST_SHORT_DELAY = 19
CMD_SELFTEST_TIMEOUT_MS = 0
CMD_SELFTEST_TIMER_EXPIRED = 2
CMD_SELFTEST_TIMER_START = 1
HANDLER_SELFTEST = 129
RSP_SELFTEST_DATA = 132
RSP_SELFTEST_FAILED = 160
RSP_SELFTEST_FAILED_WITH_DATA = 161
RSP_SELFTEST_LIST = 129
RSP_SELFTEST_OK = 128
SELFTEST_DGI_PINS = {0: 'DGI_SPI_MOSI', 1: 'DGI_SPI_MISO', 2: 'DGI_SPI_SCK', 3: 'DGI_SPI_SS', 4: 'DGI_USART_TX', 5: 'DGI_USART_RX', 6: 'DGI_USART_CLK', 7: 'DGI_I2C_DATA', 8: 'DGI_I2C_CLK', 9: 'CDC_TX', 10: 'CDC_RX', 11: 'DGI_GPIO0', 12: 'DGI_GPIO1', 13: 'DGI_GPIO2', 14: 'DGI_GPIO3'}
SELFTEST_FAILED_INVALID_PARAMETER_VALUE = 19
SELFTEST_FAILED_NOT_SUPPORTED = 16
SELFTEST_FAILED_OK = 0
VERSION0 = 0
selftest_delay_ms(delay_ms)

Issue a delay of delay_ms milliseconds

Parameters

delay_ms – Delay value in milliseconds. Max is 2^16 - 1 (65535)

selftest_delay_s(delay_s)

Issue a delay of delay_s seconds

Parameters

delay_s – Delay value in seconds. Max is (2^16 - 1) / 1000 (65)

selftest_delay_us(delay_us)

Issue a delay of delay_us microseconds

Parameters

delay_us – Delay value in microseconds. Max is 2^32 - 1 (4294967295)

selftest_short_delay()

Issue a delay of 2s generated using loads of the shortest delay function available in the tool

selftest_timeout_ms(timeout_ms, counter_value=0)

Test timer timeout

This function starts a timer with the given timeout value and returns when the timer has expired. Alternatively the timer counter value can be overridden by providing a counter_value value >0

Parameters
  • timeout_ms – Timeout value in milliseconds

  • counter_value – Value to be written to timer counter register before timer is started. A value of 0 means skip writing any value. The counter_value can be used to test overflow situations

selftest_timer_expired(timer_id)

Check if a timer has expired

Parameters

timer_id – ID of timer to check

Returns

True if timer has expired, False if not

selftest_timer_start(timer_id, timeout_ms)

Start a timer with the given ID and timeout value