flash: New Spansion FM4 flash driver
[openocd.git] / tcl / target / icepick.cfg
blobabd7b6a084db6c5468edc49db3acffcaf97241c1
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
10 # create "constants"
11 proc CONST { key } {
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)
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
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
54 proc icepick_c_router {jrc rw block register payload} {
56         set new_dr_value \
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]"
62         # select router
63         irscan $jrc [CONST IR_ROUTER] -endstate IRPAUSE
65         # ROUTER instructions are 32 bits wide
66         set old_dr_value [drscan $jrc 32 $new_dr_value -endstate DRPAUSE]
69 # Configure the icepick control register
70 proc icepick_c_setup {jrc} {
72         # send a router write, block is 0, register is 1, value is 0x2100
73         icepick_c_router $jrc 1 0x0 0x1 0x001000
76 # jrc   == TAP name for the ICEpick
77 # port  == a port number, 0..15
78 proc icepick_c_tapenable {jrc port} {
80         # First CONNECT to the ICEPick
81 #       echo "Connecting to ICEPick"
82         icepick_c_connect $jrc
84 #       echo "Configuring the ICEpick"
85         icepick_c_setup $jrc
87         # NOTE: it's important not to enter RUN/IDLE state until
88         # done sending these instructions and data to the ICEpick.
89         # And never to enter RESET, which will disable the TAPs.
91         # first enable power and clock for TAP
92         icepick_c_router $jrc 1 0x2 $port 0x100048
94         # TRM states that the register should be read back here, skipped for now
96         # enable debug "default" mode
97         icepick_c_router $jrc 1 0x2 $port 0x102048
99         # TRM states that debug enable and debug mode should be read back and
100         # confirmed - skipped for now
102         # Finally select the tap
103         icepick_c_router $jrc 1 0x2 $port 0x102148
105         # Enter the bypass state
106         irscan $jrc [CONST IR_BYPASS] -endstate RUN/IDLE
107         runtest 10
110 # jrc   == TAP name for the ICEpick
111 # coreid== core id number 0..15 (not same as port number!)
112 proc icepick_d_set_coreid {jrc coreid } {
113         icepick_c_router $jrc 1 0x6 $coreid 0x2008
116 # jrc   == TAP name for the ICEpick
117 # port  == a port number, 0..15
118 # Follow the sequence described in
119 # http://processors.wiki.ti.com/images/f/f6/Router_Scan_Sequence-ICEpick-D.pdf
120 proc icepick_d_tapenable {jrc port coreid} {
121         # First CONNECT to the ICEPick
122         icepick_c_connect $jrc
123         icepick_c_setup $jrc
125         # Select the port
126         icepick_c_router $jrc 1 0x2 $port 0x2108
128         # Set 4 bit core ID to the Cortex-A
129         icepick_d_set_coreid $jrc $coreid
131         # Enter the bypass state
132         irscan $jrc [CONST IF_BYPASS] -endstate RUN/IDLE
133         runtest 10
136 # This function uses the ICEPick to send a warm system reset
137 proc icepick_c_wreset {jrc} {
139         # send a router write, block is 0, register is 1, value is 0x2100
140         icepick_c_router $jrc 1 0x0 0x1 0x002101