eLua on AT91SAM CPUs

Using eLua with the AT91SAM7X CPUs from Atmel

Atmel is a company that doesn't need any kind of introduction from me :) Their huge product range include some quite nice ARM7TDMI core implementations. Among them are the AT91SAM7X256 and AT91SAM7X512 CPUs. The only difference between them is the ammount of internal memory (256k Flash+64k RAM for AT91SAM7X256 vs. 512k Flash+128k RAM for AT91SAM7X512). Loaded with peripherals, and accompanied by a good support package, they make a perfect host for eLua. For this tutorial I'm going to use the SAM7-EX256 development board from Olimex. It's quite a decent board, and also reasonably priced, although it lacks a proper documentation package in my oppinion. It is equipped with an AT91SAM7X256 CPU. As much as I'd like to get my hands on a board with a AT91SAM7X512 CPU, this didn't happen so far, so I'm going to stick with AT91SAM7X256. Of course, you can still try this tutorial if you have a different AT91SAM7X256 development board. Plus, the instructions should be quite similar for AT91SAM7X512 CPUs.

Prerequisites

Before you'll be able to use eLua on the AT91SAM7X256 CPU, make sure that:

  • you're using Windows. Well, this is debatable. Unlike the LM3S CPU, the Atmel CPU is supported by the excellent OpenOCD package, so programming it from Linux is definitely possible, as OpenOCD runs equally well on Windows and Linux. However, since I'm forced to use Windows anyway because of the restrictions of some of my other development boards, I'm going to take advantage of this and cover the Atmel programming tool instead of OpenOCD. The advantage is that you don't need a JTAG "dongle" to program your board (which would be the case if you were using OpenOCD). The disadvantage, of course, is that the Atmel tool runs only on Windows. Plus, I personally find OpenOCD tedious to use. If you still want to use it though, you might want to check the forementioned Olimex page, they have some OpenOCD related links there. That said, from now on I'm going to assume that you use Windows. I'm using XP, Vista should work too.
  • you have installed the AT91 In-system Programmer (ISP) package from Atmel.
  • you already built your eLua image for the AT91SAM7X256 CPU. Simply put, this means that you have a GCC toolchain for ARM, and that you used it to build eLua (remember to specify "prog" on the scons command line to get a .bin file that's suitable for programming). Or follow the instructions from the download page and download a precompiled binary image.

Burning eLua on the SAM7-EX256 board

This involves some jumper tricks, but it's still easy enough to do. We'll need to play with four jumpers: the "USB/EXT" jumper (located to the right of the USB connector from the bottom left part of the board in its close proximity), the "ERASE" jumper (located at the right of the "UEXT" header connector in the top-left part of the board, right ahead the quartz), and the block of two jumpers located right under the "RS232" connector on the board (the one that is adjacent to the Ethernet connector on its right side, NOT the one labeled "CAN" that is closer to the right edge of the board).

  • connect your board to your PC using a suitable USB cable.
  • if you have a terminal emulation program connected to the board, close it (or at least disconnect it from its port).
  • make sure that the the block of two jumpers mentioned before is set to positions "RXD0" and "TXD0" respectively, NOT "DRXD" and "DTXD".
  • make sure that the "USB/EXT" connector is set to "USB" (position 1-2) and that the "ERASE" jumper is disconnected.
  • connect the "ERASE" jumper and wait one second or more.
  • disconnect the "USB/EXT" jumper completely, then disconnect the "ERASE" jumper too.
  • connect the "USB/EXT" jumper back in the "USB" position (1-2).
  • fire up the Atmel programming tool. If you haven't installed your board yet, you'll be asked to do so at this point.
  • select "\usb\ARMx" as the connection (for me it's \usb\ARM0) and "AT91SAM7X256-EK" as the board.
  • select the "Flash" tab from the middle tab of the window.
  • in the "Send file name" box select your eLua bin file that you got from the compilation step and then press "Send File".
  • wait for the file to be sent and answer "No" to the "Lock region(s)" dialog.
  • in the window section below ("Scripts") select "Boot from Flash (GPNVM2)" then press "Execute".
  • exit the application.

Phew! That was no walk in the park, but at least eLua is now programmed in the CPU, so you can start your terminal emulator and enjoy it, as described in using eLua. If you have any problems with this procedure, feel free to contact me. Although, if you know how to burn the image from Linux/Windows with OpenOCD, please let me know and I'll include the instructions in this page.

Powered by Sputnik