From dpavlin@nuc.tv Sat Jan 23 13:37:33 2016 To: root@nuc.tv Auto-Submitted: auto-generated Subject: *** SECURITY information for nuc.tv *** Status: RO Content-Length: 8647 Lines: 180 --n8g4imXOkfNTN/H1 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, It wasn't the first time I tried and failed to find any guides on using JTAG for its original purpose, so I felt like trying it on my own. It's still unclear how to communicate with several different devices on a chain at the same time as OpenOCD seems to require to have only one TAP in non-bypass mode at a time. Here go draft instructions: 1. You need a BSDL file for the components you're using. For STM32s it's readily available from the vendor's website. 2. From the BSDL file you need to figure out the Boundary Scan Register Length, e.g. for STM32F100 it's shown in this line: attribute BOUNDARY_LENGTH of STM32F1_Low_Med_density_value_LQFP64 : entity is 232; 3. It's followed by attribute BOUNDARY_REGISTER of STM32F1_Low_Med_density_value_LQFP64 : entity is which describes which bits of BSR correspond to which device's ports. 4. Read the description of the port you're interested in. E.g. PC8 is described by "75 (BC_1, *, CONTROL, 1), " & "74 (BC_1, PC8, OUTPUT3, X, 75, 1, Z), " & "73 (BC_4, PC8, INPUT, X), " & which means that bit 73 reflects port's input (when it's configured as input), bit 74 defines port's output (when it's configured as output), bit 75 sets PC8 to Z-state when set to 1 and to output when set to 0. 5. Decide on what mode you need: in SAMPLE/PRELOAD mode the buffers are disconnected from the boundary scan logic and are controlled by the cpu as usual but you can still sample their values. In EXTEST mode the buffers are fully controlled by the boundary scan logic. Some SoCs (including STM32) allow to do boundary scan while SRST is held low, that makes it impossible for CPU to interfere with the test. You can control SRST state with "jtag_reset" command. 6. Source manual_bs.tcl (attached) and call "init_bs ". This should be done after "init" call. 7. Proceed with your tests by calling "sample_get_bit_bsr " and other functions from manual_bs.tcl An example of a semi-automated boundary scan test for an STM32VLDiscovery board is attached, here follows the log: $ sudo openocd -f interface/raspberrypi-native.cfg -f target/stm32f1x.cfg -f stm32vldiscovery_bs.tcl Open On-Chip Debugger 0.8.0-dev-00011-g7b21292-dirty (2013-05-09-23:11) Licensed under GNU GPL v2 For bug reports, read http://openocd.sourceforge.net/doc/doxygen/bugs.html Info : only one transport option; autoselect 'jtag' BCM2835 GPIO config: tck = 11, tms = 25, tdi = 10, tdi = 9 adapter speed: 1000 kHz adapter_nsrst_delay: 100 jtag_ntrst_delay: 100 cortex_m3 reset_config sysresetreq Info : clock speed 1006 kHz Info : JTAG tap: stm32f1x.cpu tap/device found: 0x3ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x3) Info : JTAG tap: stm32f1x.bs tap/device found: 0x06420041 (mfg: 0x020, part: 0x6420, ver: 0x0) Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints Starting basic STM32VLDiscovery JTAG boundary scan test All LEDs should be OFF, press Enter Green LED should be ON, blue LED OFF, press Enter Green and blue LEDs should be ON, press Enter Blue LED should be ON, green LED OFF, press Enter Green and blue LEDs should be ON, do NOT press the USER button, press Enter Green and blue LEDs should be ON, DO press the USER button, press Enter Green and blue LEDs should be ON, do NOT press the USER button, press Enter Green and blue LEDs should be ON, DO press the USER button, press Enter All tests passed SUCCESSFULLY, exiting shutdown command invoked -- Be free, use free (http://www.gnu.org/philosophy/free-sw.html) software! mailto:fercerpav@gmail.com --n8g4imXOkfNTN/H1 Content-Type: application/x-tcl Content-Disposition: attachment; filename="manual_bs.tcl" Content-Transfer-Encoding: quoted-printable # Init global variables to work with the boundary scan register=0A# the fir= st argument is tap name, the second is BSR length=0Aproc init_bs {tap len} = {=0A global bsrtap bsrlen=0A set bsrtap $tap=0A set bsrlen $len=0A= init_bsrstate=0A # disable polling for the cpu TAP as it should be k= ept in BYPASS =0A poll off=0A sample_mode=0A}=0A=0A# In this mode BSR= doesn't control the outputs but can read the current=0A# pins' states, the= CPU can continue to function normally =0Aproc sample_mode {} {=0A globa= l bsrtap=0A # SAMPLE/PRELOAD=0A irscan $bsrtap 2=0A}=0A=0A# Connect B= SR to the boundary scan logic=0Aproc extest_mode {} {=0A global bsrtap= =0A # EXTEST=0A irscan $bsrtap 0=0A}=0A=0A# Write bsrstateout to targ= et and store the result in bsrstate=0Aproc exchange_bsr {} {=0A global b= srtap bsrstate bsrstateout=0A update_bsrstate [eval drscan [concat $bsrt= ap $bsrstateout]]=0A return $bsrstate=0A}=0A=0A# Check if particular bit= is set in bsrstate=0Aproc get_bit_bsr {bit} {=0A global bsrstate=0A = set idx [expr $bit / 32]=0A set bit [expr $bit % 32]=0A expr ([lindex= $bsrstate [expr $idx*2 + 1]] & [expr 2**$bit]) !=3D 0=0A}=0A=0A# Resample = and get bit=0Aproc sample_get_bit_bsr {bit} {=0A exchange_bsr=0A get_= bit_bsr $bit=0A}=0A=0A# Set particular bit to "value" in bsrstateout=0Aproc= set_bit_bsr {bit value} {=0A global bsrstateout=0A set idx [expr ($b= it / 32) * 2 + 1]=0A set bit [expr $bit % 32]=0A set bitval [expr 2**= $bit]=0A set word [lindex $bsrstateout $idx]=0A if {$value =3D=3D 0} = {=0A set word [format %X [expr $word & ~$bitval]]=0A } else {=0A set wor= d [format %X [expr $word | $bitval]]=0A }=0A set bsrstateout [lreplac= e $bsrstateout $idx $idx 0x$word]=0A return=0A}=0A=0A# Set the bit and u= pdate BSR on target =0Aproc set_bit_bsr_do {bit value} {=0A set_bit_bsr = $bit $value=0A exchange_bsr=0A}=0A=0Aproc init_bsrstate {} {=0A globa= l bsrtap bsrlen bsrstate bsrstateout=0A set bsrstate ""=0A for {set i= $bsrlen} {$i > 32} {incr i -32} {=0A append bsrstate 32 " " 0xFFFFFFFF " "= =0A }=0A if {$i > 0} {=0A append bsrstate $i " " 0xFFFFFFFF=0A }= =0A set bsrstateout $bsrstate=0A return=0A}=0A=0Aproc update_bsrstate= {state} {=0A global bsrstate=0A set i 1=0A foreach word $state {= =0A set bsrstate [lreplace $bsrstate $i $i 0x$word]=0A incr i 2=0A }=0A}= =0A --n8g4imXOkfNTN/H1 Content-Type: application/x-tcl Content-Disposition: attachment; filename="stm32vldiscovery_bs.tcl" Content-Transfer-Encoding: quoted-printable # Example script to test STM32VLDiscovery with boundary scan=0A=0Ainit=0A= =0Aecho "\n\nStarting basic STM32VLDiscovery JTAG boundary scan test\n"=0A= =0Asource manual_bs.tcl=0A=0Ainit_bs stm32f1x.bs 232=0Aextest_mode=0Aexchan= ge_bsr=0Aecho "All LEDs should be OFF, press Enter"=0Aread stdin 1=0A=0A# S= et PC9 to output 1=0Aset_bit_bsr 72 0=0Aset_bit_bsr_do 71 1=0Aecho "Green L= ED should be ON, blue LED OFF, press Enter"=0Aread stdin 1=0A=0A# Set PC8 t= o output 1=0Aset_bit_bsr 75 0=0Aset_bit_bsr_do 74 1=0Aecho "Green and blue = LEDs should be ON, press Enter"=0Aread stdin 1=0A=0A# Set PC9 to output 0= =0Aset_bit_bsr_do 71 0=0Aecho "Blue LED should be ON, green LED OFF, press = Enter"=0Aread stdin 1=0A=0A# Set PC9 to output 1=0Aset_bit_bsr_do 71 1=0Afo= reach i {0 1} {=0A echo "Green and blue LEDs should be ON, do NOT press = the USER button, press Enter"=0A read stdin 1=0A # Read PA0 state, th= ere's a pulldown on board=0A if {[sample_get_bit_bsr 187] =3D=3D 1} {=0A= echo "Button is stuck at 1: ERROR, aborting"=0A shutdown=0A return=0A }= =0A=0A echo "Green and blue LEDs should be ON, DO press the USER button,= press Enter"=0A read stdin 1=0A if {[sample_get_bit_bsr 187] =3D=3D = 0} {=0A echo "Button is stuck at 0: ERROR, aborting"=0A shutdown=0A return= =0A }=0A}=0A=0Aecho "All tests passed SUCCESSFULLY, exiting"=0Ashutdown= =0A --n8g4imXOkfNTN/H1 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------------ This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev --n8g4imXOkfNTN/H1 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ OpenOCD-devel mailing list OpenOCD-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openocd-devel --n8g4imXOkfNTN/H1--