Playing with the AT91SAM7S64 32bit ARM processor

After all the playing with Arduino and Raspberry Pi it is time to get going with some real low level programming on microprocessors. One nice device I found is the ATMEL AT91SAM7S64 MCU.
This microprocessor is based on a ARM7TDMI® ARM® Thumb® Processor , which is a 32 bit RISC processor. So a bit more powerful compared to the 8 bit Ardunio. And much more low level compared to the Raspberry Pi. This MCU has a lot of build in periphery and offers a lot of things to discover.
Even though this MCU is probably not the most up to date one, there are a lot advanced types out there, I still decided to go for it.
One way to get started is to buy one of the Evolution Kits from ATMEL (expensive) or buy a breakout board (cheaper).
The way I took is to build a breakout board by myself. The main reason is that I wanted to see how complicated it is to build a board based on SMD “64-lead LQFP Package” in my home lab. Most modern MCUs are sold in such a surface mount package and I needed to see if I can handle them.
If one is building more advanced things it is not so nice to couple a lot of breakout boards together.
It would be much nicer to connect MCU, FPGA, ADC and other things on a single PCB. A more professional style 😛
So I started with the development of schematics, the design of the board and etching of the PCB.

The design was done in Eagle:

SamSch SamBrd

The etching was done in the same way as described in one of my older posts.

SamPCB1 SamPCB2

I decided to go for a single sided PCB even though of cause I had to solder a lot of wires on the other side. The main reason for this was that I wanted to have as much control as possible over the board and not a failure, just because a via is broken. The complexity of a home made double sided PCB should not be underestimated, even though it is fully possible. But for a start the single sided PCB is the saver choice.

The final results:

SamPCB4 SamPCB3

does not look too bad. And it is working, I was surprised!

To get started with playing with this processor there are some things to do. It is for sure not as easy as to get started with the Arduino.
The SAM microprocessors come with a boot-loader which one can save in the flash memory.
This copy process requires just that one ties the TST pin and the PA0, PA1 and PA2 pins high (3.3V) for about 10 seconds. This copies internally the boot loader from a reserved memory space into the flash memory. Since PA0-PA2 are already internally pulled up by a pull up resistor the only pin to pull high is the TST pin. After doing this one removes the connection to high for TST pin and restarts the board. That’s it! No programmer or anything needed! Now one has a boot loader on the MCU and connecting the USB connector with a PC, the boot loader should communicate with the PC. On my Linux machine it appears in the list as:


Bus 002 Device 008: ID 03eb:6124 Atmel Corp. at91sam SAMBA bootloader

when typing “lsusb” in the command line.
Also on Windows it was recognized.

Having this boot-loader one is now able to program the MCU. One way of doing this is to use the
Atmel SAM-BA In-system Programmer [1] a piece of software to do in-system programming on the SAM MCUs. This tool is a convenient way to program.
If one chooses to program directly into the SRAM one can simply reset the board without reinstalling the boot loader. When programming into flash one needs to recopy the boot loader by pulling the TST pin high as described before. Another nice tool for programming is the Sam_I_Am [2] tool.

The next step is the programming. Since one is usually not developing on a ARM architecture one does need a cross compiler.
There are several tool chains on the market for ARM based development. The one I choose is the GNU ARM tool chain. This chain comes already with a couple of Linux distributions. But can also be installed in a extra package. This is more convenient from my point of view since one has full control where headers, libraries and the compilation tools are located and one has the latest version or can have several versions in parallel. One can download the tool chain from [3]. This is in principle everything needed to get started. One other nice thing to have, specially when doing more advanced things are the ATMEL libraries at91lib [4]. With these one finds a lot of useful functions to interact with the periphery embedded in the SAM MCU.

To get going and to test that the board is really working I have tested with a program which blinks a LED connected to one of the 32 I/O pins. All pins are getting high – low-high, so it does not matter on which pin one connects the LED… This is a good test to check if all I/O pins are working.


// Definitions of the ARM chip and on-chip peripherals. 
#include "at91sam7s64.h" 

//up counting loop to waste some tome 
void delay() 
{ 
	int i = 0; 
	for (i = 0; i < 30000000; i++){ 
		asm("nop");//embeded ASM "no peration" 
	} 
} 


int main() 
{ 
	//Get a pointer to the I/O datastructure 
	volatile AT91PS_PIO pPIO = AT91C_BASE_PIOA; 
	 
	//Enable the I/O pins 
	//this is a bit mask 
	//here all 32 pins are enabled 
	pPIO->PIO_PER = 0xFFFFFFFF;//LED_MASK; 
	 
	//set all 32 pins as output 
	pPIO->PIO_OER = 0xFFFFFFFF;//LED_MASK; 

	while(1) 
	{ 
		//Set all 32 pins high 
		pPIO->PIO_SODR = 0xFFFFFFFF; 

		delay();//wait 

		//Set all 32 pins low 
		pPIO->PIO_CODR = 0xFFFFFFFF; 

		delay();//wait 
	} 

	return 0; 
}

If everything is setup correctly a simple “make” should compile the package.
It can be necessary that the path in the MAKEFILE to the compiler chain is changed,

After compilation one finds a hex “blink.hex” file which can be used to copy to the SAM7 using the tool Sam_I_Am.

This can be done by:

$ samiam.py

>open /dev/ttyACM0
>send blink.hex
0x00202000-0x002020EF: 240 bytes
Start Address: 0x202000
>go 0x202000

This should make a LED connected to GND and one of the I/O pins blink.

The code for this example and the drawings for the PCB can be found on GitHub:

git clone https://github.com/digibird1/AT91SAM7S64


[1] http://www.atmel.com/tools/atmelsam-bain-systemprogrammer.aspx
[2] http://claymore.engineer.gvsu.edu/~steriana/Software/Sam_I_Am/
[3] https://launchpad.net/gcc-arm-embedded/
[4] http://www.atmel.com/tools/at91samsoftwarepackage.aspx

Advertisements
One comment on “Playing with the AT91SAM7S64 32bit ARM processor
  1. […] Playing with the AT91SAM7S64 32bit ARM processor […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: