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.

Tuesday, August 30, 2011

Part 1: 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.

My motivation: I am an electrical engineer that uses a Mac. It's a long story, but now that I'm here I'd rather not switch operating systems via Boot Camp multiple times per day. I admit that it's not THAT hard to reboot in Windows, nor does it take THAT long, and I'm sure I've spent more time on this research project than I'll ever save. However, I wanted to know more about open source embedded dev tools and this was a great way to find out if its worth it. Is it worth it? I don't know yet. I'll try to get comfortable debugging the STM32 in Eclipse and report back. If it works out well then I'll try the STM8 with its SWIM interface and get all of my development under one IDE umbrella.

Where I came from: IAR Embedded Workbench for ARM + IAR J-Link. This is great software and hardware, no doubt. Very easy to use, supports every processor I've ever heard of, and my chip vendor of choice (ST Micro) supplies great sample projects in IAR format. But it doesn't run on Mac, and its not cheap (even if you use the free 16K version of EWARM the J-Link will cost you a lot). For some the cost is irrelevant, but if you switch chips a lot, if you're a student, or if you have multiple developers who just want to experiment then maybe this article is for you.

Bill of Materials
I am going to show you how to establish an embedded processor programming and debugging ecosystem using as much free and open source stuff as I reasonably can, and do it all on a Mac. Here are the pieces:
  1. STM32 development board with JTAG interface. I am using an STM32F103 on my own PCB design, you can use your own platform or buy any of the many development kits out there.
  2. Olimex ARM-USB-TINY-H JTAG device (buy it from Mouser.com for about $50).
  3. Mac OS X Lion 10.7.1
  4. Eclipse IDE with C/C++ Developer Tooling (CDT). These are separate downloads and you need them both. I am using Helios SR2 with CDT 7.0.2. I haven't upgraded to Indigo yet, but I'm sure the process is very similar. You will need a few helper pieces as well, described below.
  5. YAGARTO means Yet Another GNU ARM Toolchain. I used the 29 Apr 2011 version with GCC-4.6.0 and GDB-7.2. 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.
  6. Zylin Embedded CDT is an open source plug-in for GDB that magically fills the gap between Eclipse and OpenOCD. It gets installed into Eclipse.
  7. OpenOCD the Open On-Chip Debugger v0.4.0. This lets GDB talk to the JTAG hardware over USB. Hadn't been updated in over a year until I start using it then they release v0.5.0 : ) No hard feelings, but you should be aware that many of the OpenOCD server commands changed with the new version, so to use what I've done you should get the old one, or wait (potentially for eternity) for me to update to the latest.
  8. I used the MacPorts method to install OpenOCD, and I suggest you do the same if you are fairly new to the command line of Mac OS X or Linux. Heck, even if you're not new to the nitty gritty you should use it, I think MacPorts is great, and it's the method I'll show.
If it wasn't for the great open source community out there I never would have accomplished my goal. It took the aggregation of multiple how-to guides and forums for me to put together my specific solution, so I will reference those resources but also publish sufficient relavent information here.

First Things First
First thing to do is get the hardware interface installed, so go on to Part 2: Lay the Foundation.

Saturday, August 6, 2011

Get Mac OS X Lion to Work with NTFS [UPDATED]

From a comment in a neighboring blog I successfully got my NTFS drives to mount again after upgrading to Lion. There are paid solutions to NTFS on Lion, but I use Windows-formatted drives so rarely that I can't justify $39.

[UPDATE Aug 31, 2011]
MacFUSE 2.2 has been released with Lion compatibility: There is a 2.2.1 out in the wild, but many have reported that it makes your CPU run like crazy. 2.2.x is expected to be the last MacFUSE release with the new Fuse4X project taking over, but not yet useful for NTFS, as far as I can tell.



Its working great for me and not throwing that weird 15.00000 second timeout error that MacFUSE 2.0.3 was doing. and is simpler than the original method I posted.
[/UPDATE]

Old way...
How to do it:
1. Install the latest version of MacFUSE: http://macfuse.googlecode.com/files/MacFUSE-2.0.3%2C2.dmg


2. Install the lastest MacFUSE core of Tuxera (aka NTFS-3G): Install http://www.tuxera.com/mac/macfuse-core-10.5-2.1.9.dmg


Restart as necessary to make it all happy and stuff.