cc824ad0e951d45e5fe3f4135aeb78e5dbb2e230
[fw/openocd] / tcl / target / icepick.cfg
1 #
2 # Copyright (C)   2011        by Karl Kurbjun
3 # Copyright (C)   2009        by David Brownell
4 #
5
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
9
10 # create "constants"
11 proc CONST { key } {
12
13         array set constant {
14                 # define ICEPick instructions
15                 IR_BYPASS   0x00
16                 IR_ROUTER   0x02
17                 IR_CONNECT  0x07
18                 IF_BYPASS   0x3F
19         }
20         return $constant($key)
21 }
22
23 # Instruction to connect to the icepick module
24 proc icepick_c_connect {jrc} {
25
26         # Send CONNECT instruction in IR state
27         irscan $jrc [CONST IR_CONNECT] -endstate IRPAUSE
28
29         # Send write and connect key
30         drscan $jrc 8 0x89 -endstate DRPAUSE
31 }
32
33 # Instruction to disconnect to the icepick module
34 proc icepick_c_disconnect {jrc} {
35
36         # Send CONNECT instruction in IR state
37         irscan $jrc [CONST IR_CONNECT] -endstate IRPAUSE
38
39         # Send write and connect key
40         drscan $jrc 8 0x86 -endstate DRPAUSE
41 }
42
43 #
44 # icepick_c_router:
45 #  this function is for sending router commands
46 # arguments are:
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
53 #
54 proc icepick_c_router {jrc rw block register payload} {
55
56         set new_dr_value \
57                 [expr { ( ($rw & 0x1) << 31)        | ( ($block & 0x7) << 28) | \
58                                 ( ($register & 0xF) << 24)  | ( $payload & 0xFFFFFF ) } ]
59
60 #       echo "\tNew router value:\t0x[format %x $new_dr_value]"
61
62         # select router
63         irscan $jrc [CONST IR_ROUTER] -endstate IRPAUSE
64
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]"
68 }
69
70 # Configure the icepick control register
71 proc icepick_c_setup {jrc} {
72
73         # send a router write, block is 0, register is 1, value is 0x2100
74         icepick_c_router $jrc 1 0x0 0x1 0x001000
75 }
76
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} {
80
81         if { ($port >= 0) && ($port < 16) } {
82                 # Debug tap"
83                 set tap $port
84                 set block 0x2
85         } elseif { $port < 32 } {
86                 # Test tap
87                 set tap [expr {$port - 16}]
88                 set block 0x1
89         } else {
90                 echo "ERROR: Invalid ICEPick C port number: $port"
91                 return
92         }
93
94         # First CONNECT to the ICEPick
95 #       echo "Connecting to ICEPick"
96         icepick_c_connect $jrc
97
98 #       echo "Configuring the ICEpick"
99         icepick_c_setup $jrc
100
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.
104
105         # first enable power and clock for TAP
106         icepick_c_router $jrc 1 $block $tap 0x110048
107
108         # TRM states that the register should be read back here, skipped for now
109
110         # enable debug "default" mode
111         icepick_c_router $jrc 1 $block $tap 0x112048
112
113         # TRM states that debug enable and debug mode should be read back and
114         # confirmed - skipped for now
115
116         # Finally select the tap
117         icepick_c_router $jrc 1 $block $tap 0x112148
118
119         # Enter the bypass state
120         irscan $jrc [CONST IR_BYPASS] -endstate RUN/IDLE
121         runtest 10
122 }
123
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
128 }
129
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 } } {
135
136         # First CONNECT to the ICEPick
137         icepick_c_connect $jrc
138         icepick_c_setup $jrc
139
140         # Select the port
141         icepick_c_router $jrc 1 0x2 $port 0x2108
142
143         # Set icepick core control for $coreid
144         icepick_d_set_core_control $jrc $coreid $value
145
146         # Enter the bypass state
147         irscan $jrc [CONST IF_BYPASS] -endstate RUN/IDLE
148         runtest 10
149 }
150
151 # This function uses the ICEPick to send a warm system reset
152 proc icepick_c_wreset {jrc} {
153
154         # send a router write, block is 0, register is 1, value is 0x2100
155         icepick_c_router $jrc 1 0x0 0x1 0x002101
156 }