OpenOCD: Difference between revisions

No edit summary
No edit summary
 
Line 35: Line 35:
</pre>
</pre>
This prints out the device attributes that we need to use in our rules file.
This prints out the device attributes that we need to use in our rules file.
<br />
<br />
=== Using OpenOCD in a GNU-MCU-Eclipse Project ===
Users of the [https://gnu-mcu-eclipse.github.io/ GNU-MCU Eclipse] development environment need to specify the OpenOCD '''configuration options''' in the Debug launch settings window. Assuming that your system is Ubuntu Linux and that OpenOCD was installed from the standard repository via ''apt'', you can find a number of configuration files (with extension .cfg) in the various folders under the ''/usr/share/openocd/scripts/'' folder. In the launch settings window, enter the path to the appropriate configuration file into the "Config options" field in the "Debugger" tab, including the "-f" option selector, as shown in this example for Nucleo-64 boards with STM32F4xx processor:
<pre class=code>
-f /usr/share/openocd/scripts/board/st_nucleo_f4.cfg
</pre>
<br />
<br />
=== Using st-flash instead of OpenOCD ===
=== Using st-flash instead of OpenOCD ===
For STM32 processors on Nucleo or Discovery boards, the '''st-flash''' tool from [https://github.com/texane/stlink the open-source stlink project] can be used as an alternative to OpenOCD. On Ubuntu, the source files need to be built and the udev rules file installed, as explained on the project main page.
For STM32 processors on Nucleo or Discovery boards, the '''st-flash''' tool from [https://github.com/texane/stlink the open-source stlink project] can be used as an alternative to OpenOCD. On Ubuntu, the source files need to be built and the udev rules file installed, as explained on the project main page.

Latest revision as of 2019-07-20T12:29:30


Introduction

OpenOCD (http://openocd.org) is open-source software used for transferring ("flashing") binary images (executables) to a micro-controller, and therefore an important piece in the open-source toolchain for micro-controller software development. OpenOCD supports industry-standard protocols that are used to inspect or manipulate the state of a micro-controller. For example, the J-Link interface developed by Segger, and the STLink interface developed by STMicroelectronics.

Access To USB Devices For Non-Privileged Users

On Linux, in order to allow non-privileged users to access predefined micro-controller devices over USB, a rules file needs to be placed in the folder /etc/udev/rules.d/. Micro-controller software development tools usually include such a rules file that you simply copy into the aforementioned folder. For example, the GNU ARM Eclipse project (https://github.com/gnu-mcu-eclipse/openocd/releases) provides an OpenOCD distribution that includes a rules file (located in the contrib folder).

$ sudo cp /opt/gnuarmeclipse/openocd/0.10.0-201510281129-dev/contrib/99-openocd.rules /etc/udev/rules.d/
$ sudo udevadm control --reload-rules



The contents of a custom rules file may look like this:

SUBSYSTEM=="usb", ATTRS{idVendor}=="10c4", MODE="0666"
SUBSYSTEM=="usb_device", ATTRS{idVendor}=="10c4", MODE="0666"
BUS!="usb", ACTION!="add", SUBSYSTEM!=="usb_device", GOTO="my_rules_end"
ATTR{idProduct}=="1010", ATTR{idVendor}=="1366", MODE="666"
LABEL="my_rules_end"

where the attribute idVendor is used to only allow access to USB devices with the specified vendor ID. MODE is used to specify the access permissions for all devices that match the conditions preceding the MODE statement on the same line.

How do we determine the vendor ID and the product ID of a specific micro-controller? On Linux we can use udevadm to query the attributes of connected USB devices. In order to use udevadm, however, we need to find out the path of the corresponding device file. There is a neat trick for that: when the USB cable from your micro-controller is inserted into the USB port of your work computer system, several log entries that contain the device file path will be generated. Type

cat /var/log/syslog

to view the system log and examine the recent entries. For example, look for a line that ends like this:

mtp-probe: checking bus 1, device 11: "/sys/devices/pci0000:00/0000:00:14.0/usb1/1-1"

The part in quotes (/sys/devices/pci0000:00/0000:00:14.0/usb1/1-1) is the device path. Copy the device path and use it to query the device attributes like so:

sudo udevadm info --query=all --attribute-walk --path=/sys/devices/pci0000:00/0000:00:14.0/usb1/1-1

This prints out the device attributes that we need to use in our rules file.

Using OpenOCD in a GNU-MCU-Eclipse Project

Users of the GNU-MCU Eclipse development environment need to specify the OpenOCD configuration options in the Debug launch settings window. Assuming that your system is Ubuntu Linux and that OpenOCD was installed from the standard repository via apt, you can find a number of configuration files (with extension .cfg) in the various folders under the /usr/share/openocd/scripts/ folder. In the launch settings window, enter the path to the appropriate configuration file into the "Config options" field in the "Debugger" tab, including the "-f" option selector, as shown in this example for Nucleo-64 boards with STM32F4xx processor:

-f /usr/share/openocd/scripts/board/st_nucleo_f4.cfg


Using st-flash instead of OpenOCD

For STM32 processors on Nucleo or Discovery boards, the st-flash tool from the open-source stlink project can be used as an alternative to OpenOCD. On Ubuntu, the source files need to be built and the udev rules file installed, as explained on the project main page.