OpenOCD: Difference between revisions

Created page with "===<br/>Introduction === OpenOCD (http://openocd.org) is open-source software used for transferring ("flashing") binary images (executables) to a micro-controller, and therefo..."
 
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 />
=== 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.

Revision as of 2019-07-18T21:14:00


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