Menu

#280 stlink-v2 not working with bcm2835 raspberry pi

0.9.0
new
nobody
None
2021-04-06
2020-10-15
No

Hi:

I am trying to use a stlink-v2 to debug a raspberry pi (bcm2835) using jtag, but I am not succeding. I have tryied with two transports, hla and dapdirect, and each of them is giving me different problems.

Using the openocd snapshot from debian unstable (from 2020-08-19). The commands I use to connect and the debug output from openocd are the following:

  • Using hla:

$ openocd -d3 -f interface/stlink-v2.cfg -c "transport select hla_jtag" -c "adapter speed 100" -c "hla newtap raspi arm -irlen 5 -expected-id 0x07b7617F" -c "target create raspi.arm arm11 -chain-position raspi.arm"

Open On-Chip Debugger 0.10.0+dev-snapshot (2020-10-14-11:42)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
User : 13 5 options.c:63 configuration_output_handler(): debug_level: 3
User : 14 5 options.c:63 configuration_output_handler():
Debug: 15 5 options.c:187 add_default_dirs(): bindir=/usr/bin
Debug: 16 5 options.c:188 add_default_dirs(): pkgdatadir=/usr/share/openocd
Debug: 17 5 options.c:189 add_default_dirs(): exepath=/usr/bin
Debug: 18 5 options.c:190 add_default_dirs(): bin2data=../share/openocd
Debug: 19 5 configuration.c:42 add_script_search_dir(): adding /home/christian/.openocd
Debug: 20 5 configuration.c:42 add_script_search_dir(): adding /usr/bin/../share/openocd/site
Debug: 21 5 configuration.c:42 add_script_search_dir(): adding /usr/bin/../share/openocd/scripts
Debug: 22 6 configuration.c:97 find_file(): found /usr/bin/../share/openocd/scripts/interface/stlink-v2.cfg
Debug: 23 6 command.c:146 script_debug(): command - echo WARNING: interface/stlink-v2.cfg is deprecated, please switch to interface/stlink.cfg
User : 25 6 command.c:767 jim_echo(): WARNING: interface/stlink-v2.cfg is deprecated, please switch to interface/stlink.cfg
Debug: 26 6 configuration.c:97 find_file(): found /usr/bin/../share/openocd/scripts/interface/stlink.cfg
Debug: 27 6 command.c:146 script_debug(): command - adapter driver hla
Debug: 29 6 command.c:352 register_command_handler(): registering 'hla_device_desc'...
Debug: 30 6 command.c:352 register_command_handler(): registering 'hla_serial'...
Debug: 31 6 command.c:352 register_command_handler(): registering 'hla_layout'...
Debug: 32 6 command.c:352 register_command_handler(): registering 'hla_vid_pid'...
Debug: 33 6 command.c:352 register_command_handler(): registering 'hla_command'...
Debug: 34 6 command.c:146 script_debug(): command - hla_layout stlink
Debug: 36 6 hla_interface.c:242 hl_interface_handle_layout_command(): hl_interface_handle_layout_command
Debug: 37 6 command.c:146 script_debug(): command - hla_device_desc ST-LINK
Debug: 39 6 hla_interface.c:216 hl_interface_handle_device_desc_command(): hl_interface_handle_device_desc_command
Debug: 40 6 command.c:146 script_debug(): command - hla_vid_pid 0x0483 0x3744 0x0483 0x3748 0x0483 0x374b 0x0483 0x374d 0x0483 0x374e 0x0483 0x374f 0x0483 0x3752 0x0483 0x3753
Debug: 42 6 command.c:146 script_debug(): command - transport select hla_jtag
Debug: 43 6 hla_transport.c:189 hl_transport_select(): hl_transport_select
Debug: 44 6 command.c:352 register_command_handler(): registering 'hla'...
Debug: 45 6 command.c:352 register_command_handler(): registering 'jtag'...
Debug: 46 6 command.c:352 register_command_handler(): registering 'jtag'...
Debug: 47 6 command.c:352 register_command_handler(): registering 'jtag'...
Debug: 48 6 command.c:352 register_command_handler(): registering 'jtag'...
Debug: 49 6 command.c:352 register_command_handler(): registering 'jtag'...
Debug: 50 7 command.c:352 register_command_handler(): registering 'jtag'...
Debug: 51 7 command.c:352 register_command_handler(): registering 'jtag'...
Debug: 52 7 command.c:352 register_command_handler(): registering 'jtag'...
Debug: 53 7 command.c:352 register_command_handler(): registering 'jtag'...
Debug: 54 7 command.c:352 register_command_handler(): registering 'jtag_ntrst_delay'...
User : 55 7 options.c:63 configuration_output_handler(): hla_jtagUser : 56 7 options.c:63 configuration_output_handler():
Debug: 57 7 command.c:146 script_debug(): command - adapter speed 100
Debug: 59 7 core.c:1822 jtag_config_khz(): handle jtag khz
Debug: 60 7 core.c:1785 adapter_khz_to_speed(): convert khz to interface specific speed value
Debug: 61 7 core.c:1785 adapter_khz_to_speed(): convert khz to interface specific speed value
User : 62 7 options.c:63 configuration_output_handler(): adapter speed: 100 kHz
User : 63 7 options.c:63 configuration_output_handler():
Debug: 64 7 command.c:146 script_debug(): command - hla newtap raspi arm -irlen 5 -expected-id 0x07b7617F
Debug: 65 7 hla_tcl.c:111 jim_hl_newtap_cmd(): Creating New Tap, Chip: raspi, Tap: arm, Dotted: raspi.arm, 4 params
Debug: 66 7 hla_tcl.c:121 jim_hl_newtap_cmd(): Processing option: -irlen
Debug: 67 7 hla_tcl.c:121 jim_hl_newtap_cmd(): Processing option: -expected-id
Debug: 68 7 core.c:1488 jtag_tap_init(): Created Tap: raspi.arm @ abs position 0, irlen 0, capture: 0x0 mask: 0x0
Debug: 69 7 command.c:146 script_debug(): command - target create raspi.arm arm11 -chain-position raspi.arm
Error: 70 7 target.c:5458 target_create(): The selected transport doesn't support this target
User : 71 8 command.c:692 command_run_line(): invalid command name "raspi.arm"

  • Using dapdirect:

$ openocd -d3 -f interface/stlink-dap.cfg -c "transport select dapdirect_jtag" -c "adapter speed 100" -c "jtag newtap raspi arm -irlen 5 -expected-id 0x07b7617F" -c "target create raspi.arm arm11 -chain-position raspi.arm"

Open On-Chip Debugger 0.10.0+dev-snapshot (2020-10-14-11:42)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
User : 13 6 options.c:63 configuration_output_handler(): debug_level: 3
User : 14 6 options.c:63 configuration_output_handler():
Debug: 15 6 options.c:187 add_default_dirs(): bindir=/usr/bin
Debug: 16 6 options.c:188 add_default_dirs(): pkgdatadir=/usr/share/openocd
Debug: 17 6 options.c:189 add_default_dirs(): exepath=/usr/bin
Debug: 18 6 options.c:190 add_default_dirs(): bin2data=../share/openocd
Debug: 19 6 configuration.c:42 add_script_search_dir(): adding /home/christian/.openocd
Debug: 20 6 configuration.c:42 add_script_search_dir(): adding /usr/bin/../share/openocd/site
Debug: 21 7 configuration.c:42 add_script_search_dir(): adding /usr/bin/../share/openocd/scripts
Debug: 22 7 configuration.c:97 find_file(): found /usr/bin/../share/openocd/scripts/interface/stlink-dap.cfg
Debug: 23 7 command.c:146 script_debug(): command - adapter driver st-link
Debug: 25 7 command.c:352 register_command_handler(): registering 'st-link'...
Debug: 26 7 command.c:352 register_command_handler(): registering 'st-link'...
Debug: 27 7 command.c:146 script_debug(): command - st-link vid_pid 0x0483 0x3744 0x0483 0x3748 0x0483 0x374b 0x0483 0x374d 0x0483 0x374e 0x0483 0x374f 0x0483 0x3752 0x0483 0x3753
Debug: 29 7 command.c:146 script_debug(): command - transport select dapdirect_jtag
Debug: 30 7 adi_v5_dapdirect.c:168 dapdirect_jtag_select(): dapdirect_jtag_select()
Debug: 31 7 command.c:352 register_command_handler(): registering 'jtag'...
Debug: 32 7 command.c:352 register_command_handler(): registering 'jtag'...
Debug: 33 7 command.c:352 register_command_handler(): registering 'jtag'...
Debug: 34 7 command.c:352 register_command_handler(): registering 'jtag'...
Debug: 35 7 command.c:352 register_command_handler(): registering 'jtag'...
Debug: 36 7 command.c:352 register_command_handler(): registering 'jtag'...
Debug: 37 7 command.c:352 register_command_handler(): registering 'jtag'...
Debug: 38 7 command.c:352 register_command_handler(): registering 'jtag'...
Debug: 39 7 command.c:352 register_command_handler(): registering 'jtag'...
Debug: 40 7 command.c:352 register_command_handler(): registering 'jtag'...
Debug: 41 7 command.c:352 register_command_handler(): registering 'jtag_ntrst_delay'...
User : 42 7 options.c:63 configuration_output_handler(): dapdirect_jtagUser : 43 7 options.c:63 configuration_output_handler():
Debug: 44 7 command.c:146 script_debug(): command - adapter speed 100
Debug: 46 7 core.c:1822 jtag_config_khz(): handle jtag khz
Debug: 47 7 core.c:1785 adapter_khz_to_speed(): convert khz to interface specific speed value
Debug: 48 7 core.c:1785 adapter_khz_to_speed(): convert khz to interface specific speed value
User : 49 7 options.c:63 configuration_output_handler(): adapter speed: 100 kHz
User : 50 8 options.c:63 configuration_output_handler():
Debug: 51 8 command.c:146 script_debug(): command - jtag newtap raspi arm -irlen 5 -expected-id 0x07b7617F
Debug: 52 8 tcl.c:567 jim_newtap_cmd(): Creating New Tap, Chip: raspi, Tap: arm, Dotted: raspi.arm, 4 params
Debug: 53 8 core.c:1488 jtag_tap_init(): Created Tap: raspi.arm @ abs position 0, irlen 0, capture: 0x0 mask: 0x0
Debug: 54 8 command.c:146 script_debug(): command - target create raspi.arm arm11 -chain-position raspi.arm
Debug: 55 8 target.c:1996 target_free_all_working_areas_restore(): freeing all working areas
Error: 56 8 arm11.c:1104 arm11_target_create(): 'target arm11' expects IR LENGTH = 5

Debug: 57 8 target.c:5609 target_create(): target_create failed
User : 58 8 command.c:692 command_run_line(): raspi.arm

As you can see, the hla transport seems to not support arm11 as target. On the other hand, the dapdirect transport seems to ignore the -irlen flag passed to the jtag newtap command, and then the openocd complains when the tap is initialized.

Can anyone help me to solve this problem or at least throw some light on it? Have anyone succed in using stlink-v2 to debug a raspberry pi using the jtag protocol?

Thank you all.

Christian.

Discussion

  • Antonio Borneo

    Antonio Borneo - 2020-10-15

    I don't know bcm2835, but I see you use the command 'target create raspi.arm arm11'!
    ST-Link can only work on DAP based Cortex-M/Cortex-A devices.
    I expect it to not be able to work with arm11.

     
  • Christian Tenllado

    Thank you very much Antonio. I assume that could indeed be the problem with the hla transport. I was hopping that the new dapdirect would provide support for other processors appart from cortex m and cortex a, but I don't know whether that is the intention or not.

     
  • Paul Fertser

    Paul Fertser - 2020-10-15

    Hello,

    On Thu, Oct 15, 2020 at 02:42:26PM -0000, Christian Tenllado wrote:

    I am trying to use a stlink-v2 to debug a raspberry pi (bcm2835) using jtag, but

    This is not possible, stlink-v2 is not a generic JTAG adapter, it only
    supports Cortex-M targets.

     
    • Christian Tenllado

      Thank you very much for your input Paul. Is that still true with the new dapdirect transport? Do you know if it is a limitation of the stlink hardware itself or an openocd support limmitation? Thank you in advance.

       
      • Antonio Borneo

        Antonio Borneo - 2020-10-15

        It's a limitation of ST-Link. It uses the ARM DAP (arm adi v5) that is today used only for Cortex-A and Cortex-M.
        In theory would be possible to have an old arm7, 9 or 11 behind a ARM DAP, but I never found such devices and there is no support in OpenOCD yet for such setup. Anyway I don't expect bcm2835 to have such architecture

         
        • Christian Tenllado

          Thank you a lot Antonio for the information, I have to find an alternative debugger then.

           
          • Paul Fertser

            Paul Fertser - 2020-10-15

            On Thu, Oct 15, 2020 at 04:25:48PM -0000, Christian Tenllado wrote:

            Thank you a lot Antonio for the information, I have to find an alternative
            debugger then.

            Another raspberry pi would work as an alternative debugger by jtag
            bitbanging.

            --
            Be free, use free (http://www.gnu.org/philosophy/free-sw.html) software!
            mailto:fercerpav@gmail.com

             
    • Luke Kenneth Casson Leighton

      with the attached patch it has been possible to disable the hard requirement that a target exist, in order to successfully get the STLinkv2 to send JTAG commands out to a general (non-cortex_m) device.

      that also involved adding in basic settings of ir_capture_mask, ir_length and ir_capture_value to support jtag newtap options in hla_tcl.c that were not being reported as completely ignored, thus leading to a huge amount of confusion for several weeks in our case, and misleading others online (including Christian). a better patch would involve duplicating the error-checking used in src/jtag/tcl.c. an even better patch would use the same code rather than duplicate it.

      Christian: the above paragraph may explain why you were unable to get success, because the parameters you gave on the "jtag newtap" line were being completely and silently ignored. the clue was this line:

      Debug: 53 8 core.c:1488 jtag_tap_init(): Created Tap: raspi.arm @ abs position 0, irlen 0, capture: 0x0 mask: 0x0
      

      you will need to properly investigate the patch to ensure that you can still specify a target (our application specifically does not need one). you can see the difference here. with the patch, we get this:

      Debug: 38 1 core.c:1476 jtag_tap_init(): Created Tap: ls180.tap @ abs position 0, irlen 4, capture: 0x1 mask: 0xf
      

      the stage we are at so far is that the device being communicated with may be unable to cope with a 140 khz clock rate, therefore we have yet to confirm success: however we got to the point where at least it looks like the STLinkv2 actually made an effort:

      Debug: 83 5 stlink_usb.c:1019 stlink_usb_error_check(): unknown/unexpected STLINK status code 0x5
      Error: 84 5 stlink_usb.c:3493 stlink_open(): init mode failed (unable to connect to the target)
      

      also unfortunately there is no access to a logic analyzer at this location in order to debug further.

      in looking for more information as to whether HLA can actually do JTAG or not, i came across this:
      https://ftp.mak.com/out/classdocs/vrlink5.2.1/hla1516/vrl_hla_dis_and_protocol_independence.html

      The HLA 1.3 and IEEE 1516 specifications are copyrighted by their owners and MAK cannot distribute them to customers. You can get documentation for the RTI 1.3 and 1516 interface specifications at:

      http://shop.ieee.org/store/ (IEEE 1516 specifications)
      http://www.sisostds.org (SISO DLC HLA API 1516).
      

      however a quick google search shows this may be a red herring as HLA does not specify the actual wire format. it therefore remains to be confirmed as to whether it is in fact completely impossible to do plain JTAG over an STLinkv2.

      this is our best effort so far to investigate this matter: unfortunately the only remaining option to progress our project further, which is under time pressure, is to abandon the use of an STLinkV2 and to use bitbanging, USB Blaster, or FT2232.

      at least however the above insights may prove useful to someone else wishing to take this further.

       

      Last edit: Luke Kenneth Casson Leighton 2021-04-06

Log in to post a comment.