Sunday, May 31, 2009

Toolchain Components

The components of your toolchain are a code editor, a compiler, a linker, an assembler, a debugger, your reference documentation, a development board, and the means to communicate and download from your coding platform to your development board. If your primary concern in learning about microcontrollers is time and energy, then the professional tools available will be the most efficient way to enter the field. But if money is a concern there are alternatives that cost more in creative effort and time, but cost nothing in cash money.

Tools such as Keil Uvision, from ARM provide an integrated and comprehensive way to develop microcontroller software. The downside is that it is an expensive solution and it is only available for Windows machines. Another non-Mac solution is AVRDude , but this tool is designed for only one manufacturer's chips, ATMEL, though these are extremely popular.

But here, I'll concentrate on a toolchain that is completely compatible with Macs, and, with the possible exception of the development board, is totally free. You'll find in the software examples that come with Xcode our loader written as an example of USB transfer code for the IOKit, EZ-Loader. And I'll provide a template for a project that integrates SDCC with the rest of the tools of Xcode. Together these tools will take you quite a way along the path exploring microcontroller knowledge.

Here's what you'll need:

  • A Mac with Leopard 10.5 and the Developers package
  • SDCC, the Small Device C Compiler
  • Familiarity with the C language. You should be familiar with the compiling, linking, and debugging processes.
  • Familiarity with the Mac Terminal program

  • Xcode

    Of course, since you're reading this, you've got a Mac, but I'd recommend an upgrade to Leopard even with a PowerPC machine( that's what I use .) Xcode is definitely worth the hassle of learning a new OS.
    Xcode icon image
    The code editor is brilliant, with multiple views, automated error labeling, and code folding, you're working with a tool that helps you organize your thoughts as well as your code. The Organizer let's you keep sample code, or libraries, or other projects, instantly available for reference. And there's a software reference assistant available to give you suggestions when you find yourself lost in the technical miasma.

    You become a member of the "Developer Connection", which provides you with access to enormous amounts sample code, a plethora of API's, as well as the definitive reference for all of Apple's available technologies, including the workings of the IPhone.

    Download The Developer's package and Xcode here.

    Once Xcode is installed and working, use this Xcode SDCC-Build template to work with SDCC within Xcode. This template will only work if you move the root folder of your SDCC installation into your Developer folder: /Developer/sdcc.

    So it makes sense to download and install SDCC BEFORE you download this template.

    SDCC
    Xcode SDCC-Build template

    Download this Xcode project template to create SDCC compiled HEX programs in Xcode.

    The opensource Small Device C Compiler, SDCC is a suite of shell programs that create microcontroller applications from c code. It compiles, assembles and links your c code into HEX files, loadable programs that will function in your microcontroller. As an opensource project the authors have assembled the header files, source files, and tools, for virtually every 8051 derivative chip that's out there. It's an amazing group effort that deserves support, and in my experience functions beautifully.
    Here are the details for downloading and installing SDCC.

    I'll show you how to setup Xcode to control SDCC and build HEX files that you can download to your development board.

    Microcontroller Development Kits

    Manufacturers need to educate potential users about the features and methods of their chips, so they provide packages of tools and software that include tutorials, reference libraries, and sample code. Most assume that the developing platform is a Windows PC, but that is changing, and once you've become familiar with the peculiarities of coding for microcontrollers, it's easy to adapt the code to a Mac environment.

    Development Boards

    So here you have many choices, controlled primarily by the manufacturer of the chip you are interested in. The cost of these boards varies wildly depending on the processing power and ancillary technologies that are provided.
    The least expensive are chips you find in existing circuits that you can communicate with. This is the solution I chose. These cost nothing, but take time and effort to locate and research, and you should be willing to take things apart and do a little soldering.

    But there are many alternatives just a bit more expensive.

  • The Arduino, an opensource hardware project is by far the easiest and least expensive to get into. There is a large community of users who clearly have a lot of fun with their gizmos. And there are many support sites.

  • The PICStamp, is another very popular hobbyist board that is available in many different configurations, and at many different price points.

  • In the future I'll discuss ways to simplify these boards use with a Mac. There are quite a few others I'm not familiar with. If you want a look at what is readily available check out Digikey, they have an enormous selection and limited quantities are welcome. But, all the alternatives do have one major disadvantage—they are not free.

    And you're off!

    There you have it. Assembling these components provides a toolchain that you can use to explore the features of microcontrollers, and create your own gizmos, or robots, or whatever. And the price can't be beat.