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 @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