Microcontroller Development Environment using Open Source Tools


Here is my setup:

I think I got mine from SparkFun website fairly inexpensively.

Here's the big picture of the open source development tools that need to be setup:

  • I use Eclipse running the CDT and Zylin plugin for the integrated development environment (IDE) and it also interfaces with GDB for very nice debugging
  • OpenOCD - this package has the USB drivers for the JTAG device and runs as a daemon that GDB will talk to
  • YAGARTO (Yet Another GNU ARM Toolchain) - this has both the compiler for the ARM, GDB, and the basic tools like 'make'.  This can be done without Cygwin installed.
  • Some example code to run on the AT91SAM7
  • The example code can be loaded into RAM by GDB for development purposes or it can be loaded into flash so it boots directly whenever the device is powered on

Now here area the step by step instructions.  I'm borrowing heavily from examples that I have found.  James Lynch wrote a very nice tutorial on doing exactly what we are doing here.  However, it was written in October of 2006 and some of the tools have changed since then (OpenOCD has very different configuration parameters now).  Nevertheless, it is a great resource that goes into greater detail than I do on the specifics of the example code and how to use Eclipse.

  1. Download and install the necessary software
    1. Eclipse
      1. CDT
      2. Zylin Plugin - This is done from within Eclipse.  Help -> Install New Software...  Add a new site called zylincdt with a link http://opensource.zylin.com/zylincdt.  For detailed instructions see this page.
    2. YAGARTO - I installed both the YAGARTO Tools and the YAGARTO GNU ARM Toolchain
    3. OpenOCD - There is a nice installer that installs everything.
    4. Example code for the AT91SAM7S.  The blinker tutorial can be downloaded from here or here.
  2. Setup OpenOCD for your JTAG and development board.  It will run as a daemon that GDB (through Eclipse) will connect to. 
    1. First you need to install the USB drivers for the JTAG device.  I simply plugged in the JTAG and then pointed the install wizard to the USB driver that is included in the OpenOCD install package.  For some reason, I had to do this twice -- once for 'Channel A' and then for 'Channel B'.
    2. Then once the USB drivers are setup and happy, you need to run OpenOCD with the correct configuration files.  Conveniently, there are config files for both the ARM-USB-TINY and Olimex SAM7-P256 eval board that I'm using.  Copy 'olimex-jtag-tiny.cfg' from the interface directory and 'olimex_sam7_ex256.cfg' from the board directly into the bin directory.  Then launch the daemon by typing: "openocd -f olimex-jtag-tiny.cfg -f olimex_sam7_ex256.cfg" from a command prompt.  This is where I got a little off track trying to follow Peter Lynch's tutorial.  I was not able to use his config files -- I think because OpenOCD has gone through major changes since he wrote his tutorial.  Don't try to setup the flash stuff yet -- let's just get things running in RAM first.
  3. Create a new project in Eclipse and import the example code -- use the 'demo_at91sam7_blink_ram' version.  Peter Lynch's tutorial shows how to do this and AI Frog talks about it as well (although note that the AI Frog instructions are using don't use the Makefile approach.  I used the Makefile approach.)
  4. Compile the project.
  5. Create a debug profile in Eclipse that will connect to the OpenOCD daemon.  I deviated from the two above.  This is a good time to stop and explain what we are really doing.  OpenOCD is running as a daemon that you can connect to either by telnet or gdb.  (For example, from the command prompt type: 'telnet localhost port 4444'.  This will connect you to the OpenOCD daemon that is running.  Now type 'poll' and it will tell you want the processor is doing.  Or to do the same with gdb, run arm-elf-gdb.exe and then type: 'target remote localhost:3333'.  Now type 'monitor poll' and you will get the same thing as when you telnet in.)  We want to setup Eclipse to run gdb, setup the processor through gdb, load our code into RAM of the processor, and then finally graphically debug through Eclipse.  To do this we need to setup Zyliln as a debug profile in Eclipse. 
    1. Goto Run -> Debug Configurations..., click on 'Zylin Embedded Debug (Native)' and click the 'New' icon.  (Again, see the Peter Lynch tutorial for more detailed instructions).
    2. Under the Main tab, set the project to the project with the example code in it and set the C/C++ application to 'main.out' that is in your working directory.
    3. Under the Debugger tab, set the GDB debugger to: 'C:\Program Files\yagarto\bin\arm-elf-gdb.exe'
    4. Under the commands tab, put the following script into the 'Initialize Commands' box:
    5. #copy this to the init command box in Eclipse Gdb settings

      target remote localhost:3333
      monitor reset
      monitor sleep 500
      monitor poll
      monitor soft_reset_halt
      #monitor arm7_9 sw_bkpts enable
      #monitor gdb_breakpoint_override hard

      # select the core state
      monitor armv4_5 core_state arm

      # WDT_MR, disable watchdog
      monitor mww 0xFFFFFD44 0xa0008000

      # RSTC_MR, enable user reset
      monitor mww 0xfffffd08 0xa5000401

      # CKGR_MOR
      monitor mww 0xFFFFFC20 0x00000601
      monitor sleep 100

      # CKGR_PLLR
      monitor mww 0xFFFFFC2C 0x00480a0e
      monitor sleep 200

      # PMC_MCKR
      monitor mww 0xFFFFFC30 0x00000007
      monitor sleep 100

      # PMC_IER, set flash wait state (AT91C_MC_FMR)
      monitor mww 0xffffff60 0x00320100
      monitor sleep 100

      # remap 0x0 memory to RAM
      monitor mww 0xffffff00 0x1
      monitor sleep 100

      #Go ahead
      break main
    1. Now you are ready to debug the application from Eclipse! Launch the debug profile you created above.  You will see the commands that are sent to GDB (and subsequently to OpenOCD).  The initialization commands above setup the processor, load your program into RAM, sets a breakpoint at the beginning of main() and starts execution.  From here you can now use Eclipe's debugger to step through the program, inspect variables etc.
If you have comments, suggestions, or questions, please post a comment!  Good luck and happy embedded code developing and debugging!