Wall's Corners Wall's Corners Author
Title: Programming Microcontrollers using OpenOCD on a Raspberry Pi
Author: Wall's Corners
Rating 5 of 5 Des:
Yay you have finally moved on from 8-bit chips and are ready to try out some 32-bit hotness! Those ARM Cortex chips look fun, some have buil...

Yay you have finally moved on from 8-bit chips and are ready to try out some 32-bit hotness! Those ARM Cortex chips look fun, some have built in bluetooth, or 2.4ghz radios, or usb…all you have to do is learn how to program them.

OpenOCD

On your way to learning how to use your favorite new ARM Cortex you may have heard of OpenOCD. OpenOCD is the software that we will use to do the actual programming of chips. Unlike the AVR ISP programming protocol, every ARM chip is significantly different to program, with platform-unique commands, flash locations, fuse bits, settings, etc. Teasing out those details is a struggle and if you change chips you have to start all over even if both chips are, say, Cortex-M3 based! 

Each chip fab tends to supply its own programming software – Atmel has Atmel Studio, Nordic has NRFGo, ST has ST Link – but often times that software is Windows only.

OpenOCD is great because its cross platform, open source, and has support for a vast number of chips & programmers.

You can use OpenOCD with dongle-programmers such as J-Link and ST-Link or even an FTDI chip. But, if you have a spare Pi (and who doesn’t these days?) you can use it as a native OpenOCD programmer with just a few wires.

It’s also really fast to program chips natively, and if you have to program a mess of chips, it can make things speedy – an extra 30 seconds adds up when you’re doing 1000!

 

Compiling OpenOCD

Compiling OpenOCD takes about 15 minutes but is worth the effort to get the latest code. You’ll  need to have command line access and a Pi on the Internet so you can download packages and software.

Thanks to http://ift.tt/1TgkGAF for the great tutorial, we’re just adapting it for Pi usage!

Compiling OpenOCD

Start by doing a fresh sudo apt-get update this will make sure you have the latest packages and repository set up.

Next, run

sudo apt-get install git autoconf libtool make pkg-config libusb-1.0-0 libusb-1.0-0-dev

to install all the tools you’ll need to compile OpenOCD. OpenOCD changes a lot and is under constant development so we do suggest compiling your own!

raspberry_pi_1aptget.png
raspberry_pi_2aptget.png

Download the latest source code for OpenOCD with

git clone git://git.code.sf.net/p/openocd/code openocd-code

raspberry_pi_3gitclone.png

Change into the code directory and run the bootstrapper with:

cd openocd-code
./bootstrap

raspberry_pi_4bootstrap.png

Next, we will compile OpenOCD with the Raspberry Pi native GPIO twiddling support – this will work on various Raspberry Pi’s despite being called ‘bcm2835gpio’

./configure –enable-sysfsgpio –enable-bcm2835gpio

If you’re following this guide on a non-Pi embedded linux board, you can skip the –enable-bcm2835gpio part and try to just use sysfsgpio. Sysfsgpio is much slower than native GPIO twiddling but it may not matter too much in your application.

raspberry_pi_8configing.png
raspberry_pi_9configed.png

Note that when done, it wont mention GPIO support in the configuration summary, thats OK!

Run make

raspberry_pi_10making.png
raspberry_pi_11compiled.png

Assuming compilation completes successfully as above, you can install with

sudo make install

raspberry_pi_12installed.png

That’s pretty much it!

You can see the list of interfaces available in/usr/local/share/openocd/scripts/interface

There’s a lot of options, in particular check out raspberrypi2-native.cfg and raspberrypi-native.cfg if you are interested in using OpenOCD with a non-Pi, loot at sysfsgpio-raspberrypi.cfgwhich can help you port to a different linux computer

raspberry_pi_13interfaces.png
raspberry_pi_SWDPinoutPi2.png

Share This:

View more at: http://yoursmart.mobi

About Author

Advertisement

Post a Comment

 
Top