2 # Copyright (C) 2011 by Karl Kurbjun
3 # Copyright (C) 2009 by David Brownell
6 # Utilities for TI ICEpick-C/D used in most TI SoCs
7 # Details about the ICEPick are available in the the TRM for each SoC
8 # and http://processors.wiki.ti.com/index.php/ICEPICK
14 # define ICEPick instructions
20 return $constant($key)
23 # Instruction to connect to the icepick module
24 proc icepick_c_connect {jrc} {
26 # Send CONNECT instruction in IR state
27 irscan $jrc [CONST IR_CONNECT] -endstate IRPAUSE
29 # Send write and connect key
30 drscan $jrc 8 0x89 -endstate DRPAUSE
33 # Instruction to disconnect to the icepick module
34 proc icepick_c_disconnect {jrc} {
36 # Send CONNECT instruction in IR state
37 irscan $jrc [CONST IR_CONNECT] -endstate IRPAUSE
39 # Send write and connect key
40 drscan $jrc 8 0x86 -endstate DRPAUSE
45 # this function is for sending router commands
47 # jrc: TAP name for the ICEpick
48 # rw: read/write (0 for read, 1 for write)
49 # block: icepick or DAP
50 # register: which register to read/write
51 # payload: value to read/write
52 # this function is for sending router commands
54 proc icepick_c_router {jrc rw block register payload} {
57 [expr { ( ($rw & 0x1) << 31) | ( ($block & 0x7) << 28) | \
58 ( ($register & 0xF) << 24) | ( $payload & 0xFFFFFF ) } ]
60 # echo "\tNew router value:\t0x[format %x $new_dr_value]"
63 irscan $jrc [CONST IR_ROUTER] -endstate IRPAUSE
65 # ROUTER instructions are 32 bits wide
66 set old_dr_value 0x[drscan $jrc 32 $new_dr_value -endstate DRPAUSE]
67 # echo "\tOld router value:\t0x[format %x $old_dr_value]"
70 # Configure the icepick control register
71 proc icepick_c_setup {jrc} {
73 # send a router write, block is 0, register is 1, value is 0x2100
74 icepick_c_router $jrc 1 0x0 0x1 0x001000
77 # jrc == TAP name for the ICEpick
78 # port == a port number, 0..15 for debug tap, 16..31 for test tap
79 proc icepick_c_tapenable {jrc port} {
81 if { ($port >= 0) && ($port < 16) } {
85 } elseif { $port < 32 } {
87 set tap [expr {$port - 16}]
90 echo "ERROR: Invalid ICEPick C port number: $port"
94 # First CONNECT to the ICEPick
95 # echo "Connecting to ICEPick"
96 icepick_c_connect $jrc
98 # echo "Configuring the ICEpick"
101 # NOTE: it's important not to enter RUN/IDLE state until
102 # done sending these instructions and data to the ICEpick.
103 # And never to enter RESET, which will disable the TAPs.
105 # first enable power and clock for TAP
106 icepick_c_router $jrc 1 $block $tap 0x110048
108 # TRM states that the register should be read back here, skipped for now
110 # enable debug "default" mode
111 icepick_c_router $jrc 1 $block $tap 0x112048
113 # TRM states that debug enable and debug mode should be read back and
114 # confirmed - skipped for now
116 # Finally select the tap
117 icepick_c_router $jrc 1 $block $tap 0x112148
119 # Enter the bypass state
120 irscan $jrc [CONST IR_BYPASS] -endstate RUN/IDLE
124 # jrc == TAP name for the ICEpick
125 # coreid== core id number 0..15 (not same as port number!)
126 proc icepick_d_set_core_control {jrc coreid value } {
127 icepick_c_router $jrc 1 0x6 $coreid $value
130 # jrc == TAP name for the ICEpick
131 # port == a port number, 0..15
132 # Follow the sequence described in
133 # http://processors.wiki.ti.com/images/f/f6/Router_Scan_Sequence-ICEpick-D.pdf
134 proc icepick_d_tapenable {jrc port coreid { value 0x2008 } } {
136 # First CONNECT to the ICEPick
137 icepick_c_connect $jrc
141 icepick_c_router $jrc 1 0x2 $port 0x2108
143 # Set icepick core control for $coreid
144 icepick_d_set_core_control $jrc $coreid $value
146 # Enter the bypass state
147 irscan $jrc [CONST IF_BYPASS] -endstate RUN/IDLE
151 # This function uses the ICEPick to send a warm system reset
152 proc icepick_c_wreset {jrc} {
154 # send a router write, block is 0, register is 1, value is 0x2100
155 icepick_c_router $jrc 1 0x0 0x1 0x002101