Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    Raspberry Pi 4 to Toolboard 1LC with OpenOCD

    Scheduled Pinned Locked Moved Solved
    Firmware developers
    3
    14
    1.5k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Wulfstaundefined
      Wulfsta
      last edited by Wulfsta

      I'm trying to flash the 1LC using a Pi 4 and OpenOCD 0.11.0, but am seeing the following error:

      Open On-Chip Debugger 0.11.0
      Licensed under GNU GPL v2
      For bug reports, read
              http://openocd.org/doc/doxygen/bugs.html
      adapter srst pulse_width: 100
      
      Info : Listening on port 6666 for tcl connections
      Info : Listening on port 4444 for telnet connections
      Info : BCM2835 GPIO JTAG/SWD bitbang driver
      Info : clock speed 400 kHz
      Error: Error connecting DP: cannot read IDR
      

      When running with -d, I see

      ...
      Debug: 3824 504 bitbang.c:426 bitbang_swd_switch_seq(): bitbang_swd_switch_seq
      Debug: 3825 504 bitbang.c:434 bitbang_swd_switch_seq(): JTAG-to-SWD
      Debug: 3826 504 bitbang.c:394 bitbang_swd_exchange(): bitbang_swd_exchange
      Debug: 3827 504 bitbang.c:457 bitbang_swd_read_reg(): bitbang_swd_read_reg
      Debug: 3828 504 bitbang.c:394 bitbang_swd_exchange(): bitbang_swd_exchange
      Debug: 3829 504 bitbang.c:394 bitbang_swd_exchange(): bitbang_swd_exchange
      Debug: 3830 505 bitbang.c:479 bitbang_swd_read_reg(): JUNK DP read reg 0 = ffffffff
      Debug: 3831 505 bitbang.c:507 bitbang_swd_read_reg(): No valid acknowledge: ack=7
      Debug: 3832 505 bitbang.c:568 bitbang_swd_run_queue(): bitbang_swd_run_queue
      Debug: 3833 505 bitbang.c:394 bitbang_swd_exchange(): bitbang_swd_exchange
      Debug: 3834 505 bitbang.c:575 bitbang_swd_run_queue(): SWD queue return value: 07
      ...
      

      My configuration is as follows:

      adapter driver bcm2835gpio
      bcm2835gpio_peripheral_base 0xFE000000
      bcm2835gpio_speed_coeffs 236181 60
      bcm2835gpio_swd_nums 25 24
      bcm2835gpio_srst_num 18
      
      transport select swd
       
      set CHIPNAME at91samc21g18
      source [find target/at91samdXX.cfg]
      
      reset_config srst_nogate
       
      adapter srst delay 100
      adapter srst pulse_width 100
      
      adapter speed 400
      

      Tried this on two toolboards with different connections, same result. Can anyone help?

      dc42undefined 1 Reply Last reply Reply Quote 0
      • Phaedruxundefined Phaedrux marked this topic as a question
      • Wulfstaundefined
        Wulfsta
        last edited by Wulfsta

        I have it working with the following bash script:

        SWCLK=25
        SWDIO=24
        SRST=18
        
        echo "Exporting SWCLK and SRST pins."
        echo $SWCLK > /sys/class/gpio/export
        echo $SRST > /sys/class/gpio/export
        echo "out" > /sys/class/gpio/gpio$SWCLK/direction
        echo "out" > /sys/class/gpio/gpio$SRST/direction
        
        echo "Setting SWCLK low and pulsing SRST."
        echo "0" > /sys/class/gpio/gpio$SWCLK/value
        echo "0" > /sys/class/gpio/gpio$SRST/value
        echo "1" > /sys/class/gpio/gpio$SRST/value
        
        echo "Unexporting SWCLK and SRST pins."
        echo $SWCLK > /sys/class/gpio/unexport
        echo $SRST > /sys/class/gpio/unexport
        
        echo "Ready for OpenOCD."
        
        openocd -c "adapter driver bcm2835gpio; \\
        bcm2835gpio peripheral_base 0xFE000000; \\
        bcm2835gpio speed_coeffs 236181 60; \\
        adapter gpio swclk $SWCLK; \\
        adapter gpio swdio $SWDIO; \\
        adapter gpio srst $SRST; \\
        transport select swd; \\
        set CHIPNAME samc21; \\
        source [find target/at91samdXX.cfg]; \\
        reset_config srst_only; \\
        adapter speed 276; \\
        init; \\
        reset; \\
        reset; \\
        at91samd chip-erase; \\
        at91samd bootloader 0; \\
        program Duet3Bootloader-SAMC21.elf verify; \\
        reset; \\
        shutdown"
        
        echo "Done."
        

        This is adapted from here.

        1 Reply Last reply Reply Quote 2
        • dc42undefined
          dc42 administrators @Wulfsta
          last edited by

          @wulfsta you may find this thread useful https://www.avrfreaks.net/forum/samd51-and-openocd. You may also want to search the web for "Error connecting DP: cannot read IDR" which has a number of hits.

          Duet WiFi hardware designer and firmware engineer
          Please do not ask me for Duet support via PM or email, use the forum
          http://www.escher3d.com, https://miscsolutions.wordpress.com

          Wulfstaundefined 2 Replies Last reply Reply Quote 0
          • Wulfstaundefined
            Wulfsta @dc42
            last edited by

            @dc42 I've had no luck - I built OpenOCD at the latest commit, and am still seeing the same issue. My only lead is that if I disconnect the swclk line I see the same error - perhaps a pull-up issue or similar hardware configuration I'm missing? Config for the latest version is as follows:

            adapter driver bcm2835gpio
            bcm2835gpio peripheral_base 0xFE000000
            bcm2835gpio speed_coeffs 236181 60
            adapter gpio swdio 24
            adapter gpio swclk 25
            adapter gpio srst 18
            
            transport select swd
             
            set CHIPNAME at91samc21g18
            source [find target/at91samdXX.cfg]
            
            reset_config srst_nogate
             
            adapter srst delay 100
            adapter srst pulse_width 100
            
            adapter speed 400
            

            I'd greatly appreciate it if someone with the same hardware could attempt to replicate what I'm seeing.

            1 Reply Last reply Reply Quote 0
            • Wulfstaundefined
              Wulfsta @dc42
              last edited by

              @dc42 Aha! I pulled out an old v1.0 of the 1LC, and had no problem connecting to it with the Pi. Is this related to the swdclk pin being used to blink the STATUS LED? I would like to be able to flash any version of the 1LC from a Pi.

              dc42undefined gloomyandyundefined 2 Replies Last reply Reply Quote 0
              • dc42undefined
                dc42 administrators @Wulfsta
                last edited by

                @wulfsta said in Raspberry Pi 4 to Toolboard 1LC with OpenOCD:

                @dc42 Aha! I pulled out an old v1.0 of the 1LC, and had no problem connecting to it with the Pi. Is this related to the swdclk pin being used to blink the STATUS LED? I would like to be able to flash any version of the 1LC from a Pi.

                Yes, probably. On the rare occasions that I use a debugger with Duet boards that connect LEDs to SWCLK and/or SWDIO, I use a Debug build of the firmware, which doesn't drive those LEDs.

                Duet WiFi hardware designer and firmware engineer
                Please do not ask me for Duet support via PM or email, use the forum
                http://www.escher3d.com, https://miscsolutions.wordpress.com

                dc42undefined Wulfstaundefined 2 Replies Last reply Reply Quote 1
                • dc42undefined
                  dc42 administrators @dc42
                  last edited by dc42

                  PS - I see that it is possible to detect whether a debugger is present by reading a register. So in the next firmware version, I will change it not to drive the LEDs when a debugger is detected.

                  Duet WiFi hardware designer and firmware engineer
                  Please do not ask me for Duet support via PM or email, use the forum
                  http://www.escher3d.com, https://miscsolutions.wordpress.com

                  1 Reply Last reply Reply Quote 0
                  • gloomyandyundefined
                    gloomyandy @Wulfsta
                    last edited by

                    @wulfsta I see this a lot with STM32 based control boards that often attach LEDs to the SWD pins. As David mentioned the firmware can detect the debugger and not use the pin (that's what the STM port of RRF does). However there is still the problem of how to get the debug probe actually talking with the board in the first place. If the pins are not being used for other purposes the probe can attach while the mcu is running, it can then use the SWD protocol to reset the board. But if the pin is already being used this may not work and you may need to attach the probe while the board is in reset. On the boards I use there is usually a reset button and if you press this and start the debugger at the same time it is usually able to attach. However I don't think the 1LC has a reset button. You may be able to adjust the openOCD settings to get it to use hardware reset (and connect the reset line on the SWD connector), but as it says in the openOCD documentation, this can be tricky to get it working!

                    Wulfstaundefined 1 Reply Last reply Reply Quote 0
                    • Wulfstaundefined
                      Wulfsta @gloomyandy
                      last edited by

                      @gloomyandy I actually have no idea how to do this, and a cursory look at the docs didn't seem to suggest it's well-known; do you happen to have a reference that I could look at, or example of someone doing this? Or at least, a link to where this is located in the OpenOCD docs?

                      gloomyandyundefined 1 Reply Last reply Reply Quote 0
                      • gloomyandyundefined
                        gloomyandy @Wulfsta
                        last edited by

                        @Wulfsta As I said it can be rather complex and the openocd documentation is perhaps not the best. You will probably need to dig through the configuration files used to setup your Pi4 as an openocd swd probe (I've never used the rPi in this mode, so can't help there sorry). Take a look at https://openocd.org/doc/html/Reset-Configuration.html

                        Wulfstaundefined 1 Reply Last reply Reply Quote 0
                        • Wulfstaundefined
                          Wulfsta @gloomyandy
                          last edited by

                          @gloomyandy Ah yeah, I saw this page, but didn't have a close enough look at it. Thanks for the help though!

                          1 Reply Last reply Reply Quote 0
                          • Wulfstaundefined
                            Wulfsta @dc42
                            last edited by

                            @dc42 Could you provide a debug build I can use for this purpose? I don't want to set up all the tooling to build RRF...

                            dc42undefined 1 Reply Last reply Reply Quote 0
                            • dc42undefined
                              dc42 administrators @Wulfsta
                              last edited by

                              @Wulfsta the debug build configuration I have for the Tool1LC is for running without the bootloader. To use it, you would need to remove the bootloader protection, then write it to flash memory via SWD. Then to use the tool board normally again, you would need to reinstall the bootloader, again via SWD. The only tool I have ever done this with is an Atmel ICE. So unless you already have one, I can't recommend this route.

                              Duet WiFi hardware designer and firmware engineer
                              Please do not ask me for Duet support via PM or email, use the forum
                              http://www.escher3d.com, https://miscsolutions.wordpress.com

                              Wulfstaundefined 1 Reply Last reply Reply Quote 0
                              • Wulfstaundefined
                                Wulfsta @dc42
                                last edited by Wulfsta

                                @dc42 said in Raspberry Pi 4 to Toolboard 1LC with OpenOCD:

                                @Wulfsta the debug build configuration I have for the Tool1LC is for running without the bootloader. To use it, you would need to remove the bootloader protection, then write it to flash memory via SWD. Then to use the tool board normally again, you would need to reinstall the bootloader, again via SWD. The only tool I have ever done this with is an Atmel ICE. So unless you already have one, I can't recommend this route.

                                Yeah, if I had one I’d just erase the chip using that… I do wonder why I can’t get OpenOCD working - maybe it’s the frequency or pulse width?

                                Edit: I should mention that I’m trying to connect under reset as the OpenOCD docs suggest, and still no luck.

                                1 Reply Last reply Reply Quote 0
                                • Wulfstaundefined
                                  Wulfsta
                                  last edited by Wulfsta

                                  I have it working with the following bash script:

                                  SWCLK=25
                                  SWDIO=24
                                  SRST=18
                                  
                                  echo "Exporting SWCLK and SRST pins."
                                  echo $SWCLK > /sys/class/gpio/export
                                  echo $SRST > /sys/class/gpio/export
                                  echo "out" > /sys/class/gpio/gpio$SWCLK/direction
                                  echo "out" > /sys/class/gpio/gpio$SRST/direction
                                  
                                  echo "Setting SWCLK low and pulsing SRST."
                                  echo "0" > /sys/class/gpio/gpio$SWCLK/value
                                  echo "0" > /sys/class/gpio/gpio$SRST/value
                                  echo "1" > /sys/class/gpio/gpio$SRST/value
                                  
                                  echo "Unexporting SWCLK and SRST pins."
                                  echo $SWCLK > /sys/class/gpio/unexport
                                  echo $SRST > /sys/class/gpio/unexport
                                  
                                  echo "Ready for OpenOCD."
                                  
                                  openocd -c "adapter driver bcm2835gpio; \\
                                  bcm2835gpio peripheral_base 0xFE000000; \\
                                  bcm2835gpio speed_coeffs 236181 60; \\
                                  adapter gpio swclk $SWCLK; \\
                                  adapter gpio swdio $SWDIO; \\
                                  adapter gpio srst $SRST; \\
                                  transport select swd; \\
                                  set CHIPNAME samc21; \\
                                  source [find target/at91samdXX.cfg]; \\
                                  reset_config srst_only; \\
                                  adapter speed 276; \\
                                  init; \\
                                  reset; \\
                                  reset; \\
                                  at91samd chip-erase; \\
                                  at91samd bootloader 0; \\
                                  program Duet3Bootloader-SAMC21.elf verify; \\
                                  reset; \\
                                  shutdown"
                                  
                                  echo "Done."
                                  

                                  This is adapted from here.

                                  1 Reply Last reply Reply Quote 2
                                  • Wulfstaundefined Wulfsta has marked this topic as solved
                                  • oliofundefined oliof referenced this topic
                                  • First post
                                    Last post
                                  Unless otherwise noted, all forum content is licensed under CC-BY-SA