openocd jtag pin toggle
[x300-pci] / openocd-jtag / README
1 http://marc.info/?l=openocd-development&m=137182292914653
2
3 [prev in list] [next in list] [prev in thread] [next in thread] 
4
5 List:       openocd-development
6 Subject:    [OpenOCD-devel] Instructions on doing (semi-)manual JTAG boundary scan with OpenOCD
7 From:       Paul Fertser <fercerpav () gmail ! com>
8 Date:       2013-06-21 13:51:24
9 Message-ID: 20130621135124.GC2326 () home ! lan
10 [Download message RAW]
11
12 Hi,
13
14 It wasn't the first time I tried and failed to find any guides on
15 using JTAG for its original purpose, so I felt like trying it on my
16 own. It's still unclear how to communicate with several different
17 devices on a chain at the same time as OpenOCD seems to require to
18 have only one TAP in non-bypass mode at a time.
19
20 Here go draft instructions:
21
22 1. You need a BSDL file for the components you're using. For STM32s
23 it's readily available from the vendor's website.
24
25 2. From the BSDL file you need to figure out the Boundary Scan
26 Register Length, e.g. for STM32F100 it's shown in this line:
27 attribute BOUNDARY_LENGTH of STM32F1_Low_Med_density_value_LQFP64 : entity is 232;
28
29 3. It's followed by
30 attribute BOUNDARY_REGISTER of STM32F1_Low_Med_density_value_LQFP64 : entity is
31
32 which describes which bits of BSR correspond to which device's ports.
33
34 4. Read the description of the port you're interested in. E.g. PC8
35 is described by
36       "75       (BC_1,  *,              CONTROL,        1),                             " &
37       "74       (BC_1,  PC8,            OUTPUT3,        X,      75,     1,      Z),     " &
38       "73       (BC_4,  PC8,            INPUT,          X),                             " &          
39
40 which means that bit 73 reflects port's input (when it's configured as
41 input), bit 74 defines port's output (when it's configured as output),
42 bit 75 sets PC8 to Z-state when set to 1 and to output when set to 0.  
43
44 5. Decide on what mode you need: in SAMPLE/PRELOAD mode the buffers
45 are disconnected from the boundary scan logic and are controlled by
46 the cpu as usual but you can still sample their values. In EXTEST mode
47 the buffers are fully controlled by the boundary scan logic. Some SoCs
48 (including STM32) allow to do boundary scan while SRST is held low,
49 that makes it impossible for CPU to interfere with the test. You can
50 control SRST state with "jtag_reset" command.
51
52 6. Source manual_bs.tcl (attached) and call "init_bs <bstap>
53 <bsrlength>". This should be done after "init" call.
54
55 7. Proceed with your tests by calling "sample_get_bit_bsr <bitn>" and
56 other functions from manual_bs.tcl
57
58 An example of a semi-automated boundary scan test for an
59 STM32VLDiscovery board is attached, here follows the log:
60
61 $ sudo openocd -f interface/raspberrypi-native.cfg -f target/stm32f1x.cfg -f stm32vldiscovery_bs.tcl 
62 Open On-Chip Debugger 0.8.0-dev-00011-g7b21292-dirty (2013-05-09-23:11)
63 Licensed under GNU GPL v2
64 For bug reports, read
65         http://openocd.sourceforge.net/doc/doxygen/bugs.html
66 Info : only one transport option; autoselect 'jtag'
67 BCM2835 GPIO config: tck = 11, tms = 25, tdi = 10, tdi = 9
68 adapter speed: 1000 kHz
69 adapter_nsrst_delay: 100
70 jtag_ntrst_delay: 100
71 cortex_m3 reset_config sysresetreq
72 Info : clock speed 1006 kHz
73 Info : JTAG tap: stm32f1x.cpu tap/device found: 0x3ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x3)
74 Info : JTAG tap: stm32f1x.bs tap/device found: 0x06420041 (mfg: 0x020, part: 0x6420, ver: 0x0)
75 Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
76
77
78 Starting basic STM32VLDiscovery JTAG boundary scan test
79
80 All LEDs should be OFF, press Enter
81
82 Green LED should be ON, blue LED OFF, press Enter
83
84 Green and blue LEDs should be ON, press Enter
85
86 Blue LED should be ON, green LED OFF, press Enter
87
88 Green and blue LEDs should be ON, do NOT press the USER button, press Enter
89
90 Green and blue LEDs should be ON, DO press the USER button, press Enter
91
92 Green and blue LEDs should be ON, do NOT press the USER button, press Enter
93
94 Green and blue LEDs should be ON, DO press the USER button, press Enter
95
96 All tests passed SUCCESSFULLY, exiting
97 shutdown command invoked
98
99 -- 
100 Be free, use free (http://www.gnu.org/philosophy/free-sw.html) software!
101 mailto:fercerpav@gmail.com
102
103 ["manual_bs.tcl" (application/x-tcl)]
104
105 # Init global variables to work with the boundary scan register
106 # the first argument is tap name, the second is BSR length
107 proc init_bs {tap len} {
108     global bsrtap bsrlen
109     set bsrtap $tap
110     set bsrlen $len
111     init_bsrstate
112     # disable polling for the cpu TAP as it should be kept in BYPASS 
113     poll off
114     sample_mode
115 }
116
117 # In this mode BSR doesn't control the outputs but can read the current
118 # pins' states, the CPU can continue to function normally 
119 proc sample_mode {} {
120     global bsrtap
121     # SAMPLE/PRELOAD
122     irscan $bsrtap 2
123 }
124
125 # Connect BSR to the boundary scan logic
126 proc extest_mode {} {
127     global bsrtap
128     # EXTEST
129     irscan $bsrtap 0
130 }
131
132 # Write bsrstateout to target and store the result in bsrstate
133 proc exchange_bsr {} {
134     global bsrtap bsrstate bsrstateout
135     update_bsrstate [eval drscan [concat $bsrtap $bsrstateout]]
136     return $bsrstate
137 }
138
139 # Check if particular bit is set in bsrstate
140 proc get_bit_bsr {bit} {
141     global bsrstate
142     set idx [expr $bit / 32]
143     set bit [expr $bit % 32]
144     expr ([lindex $bsrstate [expr $idx*2 + 1]] & [expr 2**$bit]) != 0
145 }
146
147 # Resample and get bit
148 proc sample_get_bit_bsr {bit} {
149     exchange_bsr
150     get_bit_bsr $bit
151 }
152
153 # Set particular bit to "value" in bsrstateout
154 proc set_bit_bsr {bit value} {
155     global bsrstateout
156     set idx [expr ($bit / 32) * 2 + 1]
157     set bit [expr $bit % 32]
158     set bitval [expr 2**$bit]
159     set word [lindex $bsrstateout $idx]
160     if {$value == 0} {
161         set word [format %X [expr $word & ~$bitval]]
162     } else {
163         set word [format %X [expr $word | $bitval]]
164     }
165     set bsrstateout [lreplace $bsrstateout $idx $idx 0x$word]
166     return
167 }
168
169 # Set the bit and update BSR on target 
170 proc set_bit_bsr_do {bit value} {
171     set_bit_bsr $bit $value
172     exchange_bsr
173 }
174
175 proc init_bsrstate {} {
176     global bsrtap bsrlen bsrstate bsrstateout
177     set bsrstate ""
178     for {set i $bsrlen} {$i > 32} {incr i -32} {
179         append bsrstate 32 " " 0xFFFFFFFF " "
180     }
181     if {$i > 0} {
182         append bsrstate $i " " 0xFFFFFFFF
183     }
184     set bsrstateout $bsrstate
185     return
186 }
187
188 proc update_bsrstate {state} {
189     global bsrstate
190     set i 1
191     foreach word $state {
192         set bsrstate [lreplace $bsrstate $i $i 0x$word]
193         incr i 2
194     }
195 }
196
197 ["stm32vldiscovery_bs.tcl" (application/x-tcl)]
198
199 # Example script to test STM32VLDiscovery with boundary scan
200
201 init
202
203 echo "\n\nStarting basic STM32VLDiscovery JTAG boundary scan test\n"
204
205 source manual_bs.tcl
206
207 init_bs stm32f1x.bs 232
208 extest_mode
209 exchange_bsr
210 echo "All LEDs should be OFF, press Enter"
211 read stdin 1
212
213 # Set PC9 to output 1
214 set_bit_bsr 72 0
215 set_bit_bsr_do 71 1
216 echo "Green LED should be ON, blue LED OFF, press Enter"
217 read stdin 1
218
219 # Set PC8 to output 1
220 set_bit_bsr 75 0
221 set_bit_bsr_do 74 1
222 echo "Green and blue LEDs should be ON, press Enter"
223 read stdin 1
224
225 # Set PC9 to output 0
226 set_bit_bsr_do 71 0
227 echo "Blue LED should be ON, green LED OFF, press Enter"
228 read stdin 1
229
230 # Set PC9 to output 1
231 set_bit_bsr_do 71 1
232 foreach i {0 1} {
233     echo "Green and blue LEDs should be ON, do NOT press the USER button, press Enter"
234     read stdin 1
235     # Read PA0 state, there's a pulldown on board
236     if {[sample_get_bit_bsr 187] == 1} {
237         echo "Button is stuck at 1: ERROR, aborting"
238         shutdown
239         return
240     }
241
242     echo "Green and blue LEDs should be ON, DO press the USER button, press Enter"
243     read stdin 1
244     if {[sample_get_bit_bsr 187] == 0} {
245         echo "Button is stuck at 0: ERROR, aborting"
246         shutdown
247         return
248     }
249 }
250
251 echo "All tests passed SUCCESSFULLY, exiting"
252 shutdown
253
254
255 ------------------------------------------------------------------------------
256 This SF.net email is sponsored by Windows:
257
258 Build for Windows Store.
259
260 http://p.sf.net/sfu/windows-dev2dev
261
262 _______________________________________________
263 OpenOCD-devel mailing list
264 OpenOCD-devel@lists.sourceforge.net
265 https://lists.sourceforge.net/lists/listinfo/openocd-devel
266
267
268 [prev in list] [next in list] [prev in thread] [next in thread] 
269
270 Configure | About | News | Add a list | Sponsored by KoreLogic