Arduino Zero bonus bin (openocd supported)

User avatar
Rick Kimball
Posts: 1058
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Arduino Zero bonus bin (openocd supported)

Post by Rick Kimball » Wed Jun 17, 2015 3:21 pm

Seems that now that the Arduino Zero is out openocd is in : )

The Zero uses a cortex-m0+. The programming plug on the Zero board uses a CMSIS-DAP device. I guess Atmel/Arduino decided the quickest way to get support for that device was to just use openocd as it already supports CMSIS-DAP. So to upload programs to the Zero, they setup openocd in the platform.txt. Openocd is the richer cousin to the texane st utility package, getting support from various vendors. The good thing for us is that we could start using their binary instead of texane stuff and have less to code to support. All our users would have to do is install the SAMD package instead of the DUE one. That would bring in the arm-none-eabi-gcc and openocd 0.9.0. Certainly something to ponder in the future.

Looking at the way the platform is written here, I'm not sure if they are running openocd 3 times with different parameters:

https://github.com/arduino/ArduinoCore- ... m.txt#L120

The good thing about openocd 0.9.0, it supports all the stlink devices we might want to use, st-link v2, and v2.1. And there is support for all the different stm32 targets, STM32F0, F1, F2, F3, F4.

-rick
Last edited by Rick Kimball on Mon May 23, 2016 2:05 pm, edited 1 time in total.
-rick

User avatar
Rick Kimball
Posts: 1058
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Arduino Zero bonus bin (openocd supported)

Post by Rick Kimball » Wed Jun 17, 2015 3:29 pm

Rick Kimball wrote:The platform is written here, I'm not sure if they are running openocd 3 times with different parameters:

https://github.com/arduino/ArduinoCore- ... m.txt#L120
nm .. my old eyes playing tricks...

The platform.txt it is setup for upload, program, erase and bootloader with different params provided to openocd.
-rick

User avatar
sheepdoll
Posts: 236
Joined: Fri May 22, 2015 12:58 am
Location: Silicon Valley Vortex
Contact:

Re: Arduino Zero bonus bin (openocd supported)

Post by sheepdoll » Wed Jun 17, 2015 5:18 pm

Rick;
Is there a direct link to openocd? One that can be used as a standalone tool install?

User avatar
Rick Kimball
Posts: 1058
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Arduino Zero bonus bin (openocd supported)

Post by Rick Kimball » Wed Jun 17, 2015 5:46 pm

sheepdoll wrote:Rick;
Is there a direct link to openocd? One that can be used as a standalone tool install?
I haven't looked. I just installed using the board manager. I guess you could look at the library_index.json file. Although when I just took a quick peek I didn't see it. So maybe they moved it from where I thought it was.
-rick

User avatar
Rick Kimball
Posts: 1058
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Arduino Zero bonus bin (openocd supported)

Post by Rick Kimball » Wed Jun 17, 2015 5:49 pm

Actually I was looking at a cached version in my browser ...

http://downloads.arduino.cc/packages/package_index.json

Look for openocd there ..

Code: Select all

       {
          "name": "openocd",
          "version": "0.9.0-arduino",
          "systems": [
            {
              "host": "i686-mingw32",
              "url": "http://downloads.arduino.cc/tools/OpenOCD-0.9.0-arduino-i686-pc-cygwin.tar.bz2",
              "archiveFileName": "OpenOCD-0.9.0-arduino-i686-pc-cygwin.tar.bz2",
              "checksum": "SHA-256:5310bdd3730168a33b09b68558e908ca8b2fec25620c488f50a5fb35d0d1effd",
              "size": "2360705"
            },
            {
              "host": "x86_64-apple-darwin",
              "url": "http://downloads.arduino.cc/tools/OpenOCD-0.9.0-arduino-x86_64-apple-darwin14.3.0.tar.bz2",
              "archiveFileName": "OpenOCD-0.9.0-arduino-x86_64-apple-darwin14.3.0.tar.bz2",
              "checksum": "SHA-256:ef90769c07b8018cec3a5054e690ac6c196e03720e102ac5038c3f9da4e44782",
              "size": "2275101"
            },
            {
              "host": "x86_64-pc-linux-gnu",
              "url": "http://downloads.arduino.cc/tools/OpenOCD-0.9.0-arduino-x86_64-linux-gnu.tar.bz2",
              "archiveFileName": "OpenOCD-0.9.0-arduino-x86_64-linux-gnu.tar.bz2",
              "checksum": "SHA-256:c350409f7badf213dfcc516ea34289461ad92d87806e8e33945508a2c6b2c0b3",
              "size": "1210796"
            },
            {
              "host": "i686-pc-linux-gnu",
              "url": "http://downloads.arduino.cc/tools/OpenOCD-0.9.0-arduino-i486-linux-gnu.tar.bz2",
              "archiveFileName": "OpenOCD-0.9.0-arduino-i486-linux-gnu.tar.bz2",
              "checksum": "SHA-256:4c9793dfd7822b0fc959d039e5ecabfa89092ee2911abfdc7b5905deb171499a",
              "size": "1129654"
            }
          ]
        },
-rick

User avatar
martinayotte
Posts: 1229
Joined: Mon Apr 27, 2015 1:45 pm

Re: Arduino Zero bonus bin (openocd supported)

Post by martinayotte » Wed Jun 17, 2015 6:48 pm

Interestingly, I've started playing with openocd-0.9.0 few days ago. On Linux, I've simply untared, configured, compiled, and it was working.

User avatar
sheepdoll
Posts: 236
Joined: Fri May 22, 2015 12:58 am
Location: Silicon Valley Vortex
Contact:

Re: Arduino Zero bonus bin (openocd supported)

Post by sheepdoll » Wed Jun 17, 2015 7:23 pm

Rick Kimball wrote:Actually I was looking at a cached version in my browser ...

http://downloads.arduino.cc/packages/package_index.json

Look for openocd there ..
I did not realize it was part of the Arduino IDE. I was expecting a git or bazaar repository, along with a wiki and possibly a forum. I downloaded the darwin version and cd to the bin directory, but it must need install paths as it will not run

Code: Select all

$ ./openocd
Open On-Chip Debugger 0.9.0-gd4b7679 (2015-06-10-19:16)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Runtime Error: embedded:startup.tcl:60: Can't find openocd.cfg
in procedure 'script' 
at file "embedded:startup.tcl", line 60
Error: Debug Adapter has to be specified, see "interface" command
Runtime Error: embedded:startup.tcl:60: 
in procedure 'script' 
at file "embedded:startup.tcl", line 60


well it was worth a look. Does not seem to be ready for prime time, Unless I am overlooking something obvious.

User avatar
Rick Kimball
Posts: 1058
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Arduino Zero bonus bin (openocd supported)

Post by Rick Kimball » Wed Jun 17, 2015 7:55 pm

The secret sauce is in the scripts, on linux they are here:

/home/kimballr/.arduino15/packages/arduino/tools/openocd/0.9.0-arduino/share/openocd/scripts

for you with your discovery/nucleo boards they are in the board directory. I don't have one of your m4f boards, I do have a stm32l-discovery board though .. so i used:

Code: Select all

$ export OPENOCD_BASE=~/.arduino15/packages/arduino/tools/openocd/0.9.0-arduino
$ export OPENOCD_PATH=${OPENOCD_BASE}/share/openocd/scripts
$ export PATH=$PATH:${OPENOCD_BASE}/bin
$ type openocd
openocd is /home/kimballr/.arduino15/packages/arduino/tools/openocd/0.9.0-arduino//bin/openocd
$ openocd -s ${OPENOCD_PATH} -f board/stm32ldiscovery.cfg
Open On-Chip Debugger 0.9.0-gd4b7679 (2015-06-10-18:22)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
adapter speed: 300 kHz
adapter_nsrst_delay: 100
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
none separate
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
Info : Unable to match requested speed 300 kHz, using 240 kHz
Info : Unable to match requested speed 300 kHz, using 240 kHz
Info : clock speed 240 kHz
Info : STLINK v2 JTAG v21 API v2 SWIM v0 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 2.950209
Info : stm32l1.cpu: hardware has 6 breakpoints, 4 watchpoints
Then in another window you use either:

$ telnet localhost 4444
> help
... and interact with it

or

$ arm-none-eabi-gdb -ex 'target extended-remote :3333' -ex 'monitor reset init'
(gdb) ...

or you could use it with the eclipse debugger ..

You are probably interested in these board/configs :

$ pwd
/home/kimballr/.arduino15/packages/arduino/tools/openocd/0.9.0-arduino/share/openocd/scripts/board
$ ls st_nucleo_*
st_nucleo_f0.cfg st_nucleo_f3.cfg st_nucleo_l1.cfg
st_nucleo_f103rb.cfg st_nucleo_f4.cfg

-rick
-rick

User avatar
martinayotte
Posts: 1229
Joined: Mon Apr 27, 2015 1:45 pm

Re: Arduino Zero bonus bin (openocd supported)

Post by martinayotte » Wed Jun 17, 2015 7:58 pm

Hi Sheepdoll,

I'm newbie with openocd, but if I understood, "openocd.cfg" should be you "prefered" configs, but you can run it without it if you provide all required arguments, such as :

openocd -f interface/stlink-v2.cfg -c "transport select hla_swd" -f target/stm32f1x.cfg

User avatar
Rick Kimball
Posts: 1058
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Arduino Zero bonus bin (openocd supported)

Post by Rick Kimball » Wed Jun 17, 2015 8:02 pm

BTW: openocd doesn't know anything about the Arduino Zero so they had to provide their own configuration scripts for it:

https://github.com/arduino/ArduinoCore- ... o_zero.cfg

Code: Select all

source [find interface/cmsis-dap.cfg]
# chip name
set CHIPNAME at91samd21g18
set ENDIAN little
# choose a port here
set telnet_port 0
source [find target/at91samdXX.cfg]
But the cool thing is that you can add these files to be able to work with new chips and jtag devices without having to rewrite the code like you would with the texane stutil code base.

If you look at the platform.txt:
https://github.com/arduino/ArduinoCore- ... atform.txt
You can see how they pass arguments to openocd to upload a new binary:

Code: Select all

tools.openocd.upload.params.verbose=-d2
tools.openocd.upload.params.quiet=-d0
tools.openocd.upload.pattern="{path}/{cmd}" {upload.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{{build.path}/{build.project_name}.bin}} verify reset 0x00002000; shutdown"
They use the "program blahblah... verify reset 0x00002000 shutdown" ...

for us it would be something different like 0x8000000 ..

-rick
-rick

Post Reply