Guide to MJB's AT91SAM7 Example Firmware
with Build Notes for GNU-ARM GCC tools


SAM7 Debug Monitor overview

The SAM7 Debug Monitor is a stand-alone firmware application comprising target-resident debugging facilities. It runs on Atmel's AT91SAM7S-EK evaluation board and compatible hardware platforms. The firmware is intended to provide a basic framework upon which to develop user applications. It incorporates a primitive task scheduler, but a more versatile real-time kernel (e.g. BERT) can be easily imported.

The firmware is based on various examples from Atmel's website, with MJB's 32-bit command-line user interface (CLI) added. The program is a mix of source code ported from both IAR and GNU-GCC examples obtained from Atmel's website. Code from other examples may be imported to provide additional on-chip peripheral functionality.

The code supplied in the SAM7 Debug Monitor package is meant to be built using the free GNU-GCC tools. However, it should be possible to build the firmware with the commercial IAR EWARM system, but this has not been verified. (There may be some changes required in the assembler startup module, cstartup.s, to suit the IAR assembler syntax.)

The SAM7 Debug Monitor supports the following on-chip peripherals:

PIT Generates a 1ms periodic "tick" interrupt for the kernel "task scheduler";
also provides a general-purpose milli-second timer.
DBGU Debug Port for command-line user interface (CLI) and/or "trace" output.
The DBGU is interrupt-driven for RX data.
PWM Demonstration of PWM channel usage for digital-to-analog conversion.
(PWM0 output on pin PA23 -- 4kHz with duty cycle sweep from .1% to 99.9%.)
TC0, TC1 Demonstration of Timer/Counter usage (LED flashing).
PIO General-purpose I/O (switches & LEDs), external IRQ modes (optional).
USART Serial comm's support, with DMA buffering (optional).
UDP USB CDC "Virtual UART" function library for USB-to-Serial applications;
The USB port can be used to access the CLI using HyperTerminal.

If using the PIO in interrupt mode, the module "ext_irq.c" can be included in the project. If using the USART(s), the module "usart.c" can be included in the project. The supplied "Makefile" must be modified accordingly.

The binary object file "sam7_test_flash.bin" can be loaded into the target board via the USB port, by means of the "SAM-BA" firmware download utility. (The SAM-BA Windows GUI application is available from Atmel's website.)

Version 2.2 changes and additions

This particular release (V2.2.108 object code) is built with the USB option for CLI access. 
The DBGU port is used for "trace" output. It shows the USB enumeration transactions and other traffic on the Control endpoint.

The USB CDC library was developed by MJB. It is well structured, richly annotated, and much simpler than Atmel's example USB "framework" code. A Windows host driver file is included. The driver information file may be modified to suit the developer's application. Students of electronics technology and I.T. will find this firmware helpful to implement a USB CDC project.


Installing the Windows driver.

The Windows USB driver is "usbser.sys", normally included with Windows XP, and normally found in local directory C: \Windows\system32\drivers. The custom driver information file required for this firmware is "cdc6166.inf". This should be copied to local directory C: \Windows.

When the board is first powered up with the SAM7 Debug firmware installed, Windows "Found New Hardware Wizard" should appear and prompt for these files. It's better not to let the wizard search automatically for a suitable driver. Browse to the location of each file when prompted (cdc6166.inf comes first). If the Wizard asks for a hardware device type or category, select "Ports".

If the driver installed properly, the Windows "Device Manager" will show a new device "SAM7-EK board" under "Ports (COM & LPT)". It will also show the port number of the virtual COM port assigned to the device. Use this port number when configuring HyperTerminal.


Using the command line interface (CLI) when configured for USB comm's.

Connect the SAM7-EK board to the host PC before starting HyperTerminal.

A second terminal emulator, e.g. TeraTerm, can be used to access the debug port, with DBGU serial port settings: 38400Bd, n, 8, 1.

When the board is powered up and running, start Hyperterminal.

The SAM7-EK board USB port appears to the host as a "virtual COM port". From the File menu, select "Properties".  In the dialog box, in the field "Connect Using:", select the COM port assigned to the device. (This is usually the highest numbered virtual COM port, which will be COM5 or above on PCs having physical ports on COM1 thru COM4.) Other serial port settings (Baud rate, etc) are irrelevant for USB comm's, except for devices implementing a USB-to-Serial converter, or such like.

Click "OK" to close the "Properties" dialog box.

Next, click the "Call Connect" button (or select "Call/Connect" from the menu). With the HyperTerminal window active, hit [Enter] once or twice on your keyboard. The SAM7 Debug Monitor prompt should appear (:-->).

Click the "Disconnect" button in HyperTerminal before resetting or unplugging the board. Click the "Call Connect" button to resume communications. If HyperTerminal fails to respond, close it, reset the board, then open it again. In some cases, it might be necessary to reconfigure the COM port (as above).


CLI User Guide

To list available commands, enter "help" at the prompt. Commands and their arguments are separated by spaces. All commands, when entered with the switch '-h' or '?', will show command usage details (and do nothing else). Otherwise, a command which expects at least one argument, when entered without any, will also show command usage. In usage info, [ ] brackets mean optional, e.g. [<arg>]; braces enclose alternative options, e.g. { -x | -y }. The Backspace key can be used for simple line editing. Ctrl+X cancels a line. To recall a previously entered command, use Ctrl+R.


Building AT91SAM7 firmware using GNU-ARM GCC Tools

Download the GNU ARM Toolchain, GCC-4.1 (or later version), from: http://www.gnuarm.com/
from the 'FILES' page, under the heading "Binaries - GCC-4.x toolchain".
This package includes the 'CygWin' DLL, which is necessary to run GNU software under Windows.

Download the GNU 'MAKE' utility from: http://gnuwin32.sourceforge.net/packages.html
Locate the 'Make' package and click on 'Setup' to download the package.
(The documentation included in the 'make' installation is excellent.)

Download Atmel App Note #6293A "Getting Started with AT91SAM7S Microcontrollers" from
http://www.atmel.com/dyn/products/app_notes.asp?family_id=605
This App Note explains how to install and use the GNU ARM tools.

The GCC-4.1 installation does not provide a utility to read the included documentation files!
Online HTML manuals (and downloadable PDF's) can be found at:
http://gcc.gnu.org/onlinedocs/

Various IDE "front end" software packages are available for the GNU/GCC tools, e.g. Yagarto, but the basic command-line development environment does the job adequately. If you want to use the Yagarto IDE, be sure to get Atmel App Note #6310 "GNU-Based Software Development on AT91SAM Microcontrollers" as well.

Before building your entire firmware application using 'make', note that C source files may be compiled individually using the command:

arm-elf-gcc -c -mcpu=arm7tdmi -Os -Wall -I./include %1.c -o %1.o

... where %1 is the C source filename. For convenience, this command line can be put into a batch file, e.g. "cc.bat". The C source file "hello.c" can then be compiled using the simple command:

cc hello

Similarly, individual assembly-language files, e.g. cstartup.s, may be assembled using the command:

arm-elf-gcc -D__ASSEMBLY__ -x assembler-with-cpp -g -mcpu=arm7tdmi -c -Os -Wall -I./include %1.s -o %1.o

The reason for defining the symbol __ASSEMBLY__ is to allow selective assembly of directives and definitions from header files designed for inclusion in either C or assembler source files; e.g. see "AT91SAM7S256.h" (from the Atmel "Getting Started" package, also included in my SAM7 Debug Monitor pkg).


SAM7_Firmware_Guide.htm -- MJB 2008-08-02
Copyright 2008 M.J.Bauer --
www.mjbauer.biz