Wednesday, August 31, 2011

Part 2: Mac OS + Eclipse + OpenOCD + STM32 (ARM Cortex M3)

Intro
I really wanted to program and debug ARM processors from my Mac. This series of entries is a work in progress as I fine tune my setup for regular use.  Be sure to read the full story:
Part 1: Getting Started, what we are going to do and what parts we are going to use.
Part 2: Laying the Foundation, getting all the parts installed.
Part 3: Connecting the Plumbing, hook up all the pieces and run it.
Part 4
: Finishing Touches, troubleshooting and final thoughts.

Laying the Foundation
We are going to work (more or less) from the bottom to the top of the list of pieces shown in Part 1.

OpenOCD Installation
First thing to do is get the hardware interface installed, that is OpenOCD, for which you will need to install MacPorts, if you want to do it my way.
  1. Install MacPorts. The MacPorts site has very good instructions on how to do that. I am running XCode 3.2.5 on OS X Lion with no problems, although the MacPorts page says to use 4.x. For those of you unfamiliar with MacPorts it is a very powerful tool similar to apt-get on Linux. MacPorts removes you from the task of compiling source code and finding all of the required dependencies for your open source software of choice. Don't be scared, embrace Terminal and realize how much more your Mac can do. Use the search feature on MacPorts' site and see how much stuff is available. I don't want to sound like a command-line freak, I'm not, I'd much rather download a sweet DMG image containing an installer and prebuilt binaries, but alas.
  2. Use MacPorts to install OpenOCD. The Terminal command is "sudo port install openocd" where sudo gives admin rights to the port command (MacPorts), and install tells MacPorts to install openocd, as opposed to uninstalling. The openocd name comes from the MacPorts description for OpenOCD. If you pay attention to the dependencies you'll see that libftdi gets installed, this is the driver for the FTDI USB-UART chip inside the Olimex JTAG (and many other budget JTAGs). You might end up waiting a while for this step to complete, depending on what is already installed on your machine, internet speed, etc. I'm talking like 5's or 10's of minutes. When it's done there won't be any new icon in your Applications folder or anything, but there will be bunch of stuff in your /opt/local/ directory. /opt/local/bin/openocd is the executable and /opt/local/share/openocd/ contains a number of different scripts to configure OpenOCD for various JTAGs and various targets (processors).
YAGARTO Installation

Next, we install YAGARTO which is a plug-in to the GDB debugger which allows the GDB to work with ARM processors.

  1. Go get the goods, and make sure you download from the Mac OS X section and not the Windows section. I used the 29 Apr 2011 version with GCC-4.6.0 and GDB-7.2. YAGARTO means Yet Another GNU ARM Toolchain. Eclipse uses this piece to cross-compile your code for the ARM on your Mac, generate the binary file used program your chip, and generate debugger data. It also uses this piece, via the Zylin add-in, to run the debugger.
  2. Install as per the ReadMe file included in the DMG: To install the toolchain copy the YAGARTO installer (yagarto-4.6.0, the blue box icon) to the folder where you want to install it. Start the installer by double clicking on it. I chose to place the installer at /Developer/YAGARTO/ so you can copy if you want to use my examples directly.
  3. The installer will simply create a directory structure under the path where you put the installer. Again, no fancy icons in your Applications folder, just some crazy sounding filenames waiting patiently for Eclipse to exercise them. The business end is at /Developer/YAGARTO/yagarto-4.6.0/bin and this is a path that will be useful to know in the near future.
Eclipse Installation

If you haven't heard of Eclipse then I'm surprised you made it this far. Eclipse is the ultimate GUI/IDE for just about every purpose. Personally I've used it for Java, Actionscript, Python, and now C for the ARM. Anyway,

  1. Download the Eclipse IDE and the C/C++ Developer Tooling (CDT). These are separate downloads and you need them both, unless you want to install Eclipse then add in the CDT via the "Help->Install New Software..." feature. I am using Helios SR2 with CDT 7.0.2. I haven't upgraded to Indigo yet, but I'm sure this process is very similar for both versions.
Zylin Installation

Zylin fills the gap between Eclipse and OpenOCD for the debugging side of things.

  1. The Zylin CDT is open source and there website is here, although there is nothing you need to download from there.
  2. What you need to do is fire up Eclipse, and use the Help->Install New Software... feature.
  3. To the right of the "Work with:" text box click the "Add..." button to bring up the "Add Repository" window. Name it something like "Zylin CDT" and put in "http://opensource.zylin.com/zylincdt" for the location. This location information came from the Zylin website.
  4. After some thinking "Zylin Embedded CDT" should show up in the big window. Check the box next to it then hit "Next" a couple times, accept the license terms, and hit "Finish." It might take a few minutes to do its thing, but wait for it, approve any unsigned software installation, then restart Eclipse when prompted.
Next Step

We have the foundation laid, so now its on to Part 3: Connect the Plumbing.

3 comments: