flash/nor/at91samd: Use 32-bit register writes for ST-Link compat
[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 ... used in DaVinci, OMAP3, and more.
7 # Details about the ICEPickC are available in the AM/DM37x document SPRUGN4M
8
9 # create "constants"
10 proc CONST { key } {
11
12         array set constant {
13                 # define ICEPick instructions
14                 IR_BYPASS   0x00
15                 IR_ROUTER   0x02
16                 IR_CONNECT  0x07
17                 IF_BYPASS   0x3F
18         }
19         return $constant($key)
20 }
21
22 # Instruction to connect to the icepick module
23 proc icepick_c_connect {jrc} {
24
25         # Send CONNECT instruction in IR state
26         irscan $jrc [CONST IR_CONNECT] -endstate IRPAUSE
27
28         # Send write and connect key
29         drscan $jrc 8 0x89 -endstate DRPAUSE
30 }
31
32 # Instruction to disconnect to the icepick module
33 proc icepick_c_disconnect {jrc} {
34
35         # Send CONNECT instruction in IR state
36         irscan $jrc [CONST IR_CONNECT] -endstate IRPAUSE
37
38         # Send write and connect key
39         drscan $jrc 8 0x86 -endstate DRPAUSE
40 }
41
42 #
43 # icepick_c_router:
44 #  this function is for sending router commands
45 # arguments are:
46 #  jrc:        TAP name for the ICEpick
47 #  rw:         read/write (0 for read, 1 for write)
48 #  block:      icepick or DAP
49 #  register:   which register to read/write
50 #  payload:    value to read/write
51 # this function is for sending router commands
52 #
53 proc icepick_c_router {jrc rw block register payload} {
54
55         set new_dr_value \
56                 [expr ( ($rw & 0x1) << 31)        | ( ($block & 0x7) << 28) | \
57                         ( ($register & 0xF) << 24)  | ( $payload & 0xFFFFFF ) ]
58
59 #       echo "\tNew router value:\t0x[format %x $new_dr_value]"
60
61         # select router
62         irscan $jrc [CONST IR_ROUTER] -endstate IRPAUSE
63
64         # ROUTER instructions are 32 bits wide
65         set old_dr_value [drscan $jrc 32 $new_dr_value -endstate DRPAUSE]
66 }
67
68 # Configure the icepick control register
69 proc icepick_c_setup {jrc} {
70
71         # send a router write, block is 0, register is 1, value is 0x2100
72         icepick_c_router $jrc 1 0x0 0x1 0x001000
73 }
74
75 # jrc   == TAP name for the ICEpick
76 # port  == a port number, 0..15
77 proc icepick_c_tapenable {jrc port} {
78
79         # First CONNECT to the ICEPick
80 #       echo "Connecting to ICEPick"
81         icepick_c_connect $jrc
82
83 #       echo "Configuring the ICEpick"
84         icepick_c_setup $jrc
85
86         # NOTE: it's important not to enter RUN/IDLE state until
87         # done sending these instructions and data to the ICEpick.
88         # And never to enter RESET, which will disable the TAPs.
89
90         # first enable power and clock for TAP
91         icepick_c_router $jrc 1 0x2 $port 0x100048
92
93         # TRM states that the register should be read back here, skipped for now
94
95         # enable debug "default" mode
96         icepick_c_router $jrc 1 0x2 $port 0x102048
97
98         # TRM states that debug enable and debug mode should be read back and
99         # confirmed - skipped for now
100
101         # Finally select the tap
102         icepick_c_router $jrc 1 0x2 $port 0x102148
103
104         # Enter the bypass state
105         irscan $jrc [CONST IR_BYPASS] -endstate RUN/IDLE
106         runtest 10
107 }
108
109 # This function uses the ICEPick to send a warm system reset
110 proc icepick_c_wreset {jrc} {
111
112         # send a router write, block is 0, register is 1, value is 0x2100
113         icepick_c_router $jrc 1 0x0 0x1 0x002101
114 }
115