tcl/target: add SPDX tag
[fw/openocd] / tcl / target / icepick.cfg
1 # SPDX-License-Identifier: GPL-2.0-or-later
2
3 #
4 # Copyright (C)   2011        by Karl Kurbjun
5 # Copyright (C)   2009        by David Brownell
6 #
7
8 # Utilities for TI ICEpick-C/D used in most TI SoCs
9 # Details about the ICEPick are available in the the TRM for each SoC
10 # and http://processors.wiki.ti.com/index.php/ICEPICK
11
12 # create "constants"
13 proc CONST { key } {
14
15         array set constant {
16                 # define ICEPick instructions
17                 IR_BYPASS   0x00
18                 IR_ROUTER   0x02
19                 IR_CONNECT  0x07
20                 IF_BYPASS   0x3F
21         }
22         return $constant($key)
23 }
24
25 # Instruction to connect to the icepick module
26 proc icepick_c_connect {jrc} {
27
28         # Send CONNECT instruction in IR state
29         irscan $jrc [CONST IR_CONNECT] -endstate IRPAUSE
30
31         # Send write and connect key
32         drscan $jrc 8 0x89 -endstate DRPAUSE
33 }
34
35 # Instruction to disconnect to the icepick module
36 proc icepick_c_disconnect {jrc} {
37
38         # Send CONNECT instruction in IR state
39         irscan $jrc [CONST IR_CONNECT] -endstate IRPAUSE
40
41         # Send write and connect key
42         drscan $jrc 8 0x86 -endstate DRPAUSE
43 }
44
45 #
46 # icepick_c_router:
47 #  this function is for sending router commands
48 # arguments are:
49 #  jrc:        TAP name for the ICEpick
50 #  rw:         read/write (0 for read, 1 for write)
51 #  block:      icepick or DAP
52 #  register:   which register to read/write
53 #  payload:    value to read/write
54 # this function is for sending router commands
55 #
56 proc icepick_c_router {jrc rw block register payload} {
57
58         set new_dr_value \
59                 [expr { ( ($rw & 0x1) << 31)        | ( ($block & 0x7) << 28) | \
60                                 ( ($register & 0xF) << 24)  | ( $payload & 0xFFFFFF ) } ]
61
62 #       echo "\tNew router value:\t0x[format %x $new_dr_value]"
63
64         # select router
65         irscan $jrc [CONST IR_ROUTER] -endstate IRPAUSE
66
67         # ROUTER instructions are 32 bits wide
68         set old_dr_value 0x[drscan $jrc 32 $new_dr_value -endstate DRPAUSE]
69 #       echo "\tOld router value:\t0x[format %x $old_dr_value]"
70 }
71
72 # Configure the icepick control register
73 proc icepick_c_setup {jrc} {
74
75         # send a router write, block is 0, register is 1, value is 0x2100
76         icepick_c_router $jrc 1 0x0 0x1 0x001000
77 }
78
79 # jrc   == TAP name for the ICEpick
80 # port  == a port number, 0..15 for debug tap, 16..31 for test tap
81 proc icepick_c_tapenable {jrc port} {
82
83         if { ($port >= 0) && ($port < 16) } {
84                 # Debug tap"
85                 set tap $port
86                 set block 0x2
87         } elseif { $port < 32 } {
88                 # Test tap
89                 set tap [expr {$port - 16}]
90                 set block 0x1
91         } else {
92                 echo "ERROR: Invalid ICEPick C port number: $port"
93                 return
94         }
95
96         # First CONNECT to the ICEPick
97 #       echo "Connecting to ICEPick"
98         icepick_c_connect $jrc
99
100 #       echo "Configuring the ICEpick"
101         icepick_c_setup $jrc
102
103         # NOTE: it's important not to enter RUN/IDLE state until
104         # done sending these instructions and data to the ICEpick.
105         # And never to enter RESET, which will disable the TAPs.
106
107         # first enable power and clock for TAP
108         icepick_c_router $jrc 1 $block $tap 0x110048
109
110         # TRM states that the register should be read back here, skipped for now
111
112         # enable debug "default" mode
113         icepick_c_router $jrc 1 $block $tap 0x112048
114
115         # TRM states that debug enable and debug mode should be read back and
116         # confirmed - skipped for now
117
118         # Finally select the tap
119         icepick_c_router $jrc 1 $block $tap 0x112148
120
121         # Enter the bypass state
122         irscan $jrc [CONST IR_BYPASS] -endstate RUN/IDLE
123         runtest 10
124 }
125
126 # jrc   == TAP name for the ICEpick
127 # coreid== core id number 0..15 (not same as port number!)
128 proc icepick_d_set_core_control {jrc coreid value } {
129         icepick_c_router $jrc 1 0x6 $coreid $value
130 }
131
132 # jrc   == TAP name for the ICEpick
133 # port  == a port number, 0..15
134 # Follow the sequence described in
135 # http://processors.wiki.ti.com/images/f/f6/Router_Scan_Sequence-ICEpick-D.pdf
136 proc icepick_d_tapenable {jrc port coreid { value 0x2008 } } {
137
138         # First CONNECT to the ICEPick
139         icepick_c_connect $jrc
140         icepick_c_setup $jrc
141
142         # Select the port
143         icepick_c_router $jrc 1 0x2 $port 0x2108
144
145         # Set icepick core control for $coreid
146         icepick_d_set_core_control $jrc $coreid $value
147
148         # Enter the bypass state
149         irscan $jrc [CONST IF_BYPASS] -endstate RUN/IDLE
150         runtest 10
151 }
152
153 # This function uses the ICEPick to send a warm system reset
154 proc icepick_c_wreset {jrc} {
155
156         # send a router write, block is 0, register is 1, value is 0x2100
157         icepick_c_router $jrc 1 0x0 0x1 0x002101
158 }