Thursday, July 29, 2010

Using sam-ba on linux

Looks like ATMEL has a linux version of sam-ba.

And it turns out this board I have is actually an olimex sam7-h256 instead of a h64, so that is good.

to use sam-ba install the tst jumper, plug the board into a usb cable to apply power, wait for a second. unplug from the usb cable, remove the tst jumper, and plug back in. If everything worked right dmesg should show you that a device was connected and there is a serial port on ttyUSBx.

Download sam-ba from the above link.

unzip somewhere and run sam-ba. the gui will ask for a serial port, enter the ttyUSBx number from dmesg. I my case I select the sam7s-256 evaluation kit board type even though it is not an atmel eval kit, it makes sam-ba look at the chip and recognize what it is.

Taking the software and instructions from the prior post, even though I said the rom/ram based solution would be the last thing I would do that is the next thing I am going to show.

Change memmap to:

/* memmap */
rom(RX) : ORIGIN = 0x00000000, LENGTH = 0x10000
ram(WAIL) : ORIGIN = 0x00200000, LENGTH = 0x1000

.text : { *(.text*) } > rom

The RX means read and execute, the WAIL is everything else which we want in ram. We are not using variables so we dont have to get into initializing .data or .bss discussions.

I had mentioned in the prior post about the chip booting up slow then writing clock registers to make it go faster. Whatever bootloader was in this chip when I got it did the fast clock thing, so the prior example needed a long count in order to make the blink not too fast and not too slow. But this example runs from flash so we get the chip post-reset without the clock adjusted so it is in the slow mode. So the counter in the prior post was really too long for running from flash as far as a demonstration goes. So here is the new blinker1.c program:

void PUT32 ( unsigned int, unsigned int );
void ASMDELAY ( unsigned int );

#define PIOA_BASE 0xFFFFF400

#define PIO_PER 0x0000
#define PIO_OER 0x0010
#define PIO_SODR 0x0030
#define PIO_CODR 0x0034
#define PIO_PUDR 0x0060


#define LED_BIT (1<<8)

int notmain ( void )
//volatile unsigned int ra;
PUT32(PIOA_PER,LED_BIT); //enable/connect PIO control to led output
PUT32(PIOA_PUDR,LED_BIT); //disable pull up resistor
PUT32(PIOA_OER,LED_BIT); //enable/set as an output pin
PUT32(PIOA_CODR,LED_BIT); //turn on led. other side of led is 3.3v so to turn it on drive/sink 0 volts.

//for(ra=0;ra<0x10000;ra++) continue;
ASMDELAY(0x4000); //this way the compiler wont optimize out the for loop

So count to 0x4000 is actually a pretty slow blink 3 seconds plus or minus between on and off state changes.

So using the Makefile and vectors.s from the prior post build blinker1.bin.

In samba. IN the top area that says memory display, click in the box with 0x200000 and change that to 0x100000 and press the Refresh button. This is the flash data.

In the middle section press the flash tab. next to the execute button select Enable Flash access and press Execute. Then select Erase All Flash and press Execute, it may warn you that
at least one section may be locked do you want to unlock. press the button saying that you do want to unlock those sections.

In the Memory Display window press refres, now the flash memory should be all 0xFFs, which is erased.

use the open folder icon next to the Send File Name box to find blinker1.bin wherever you built

Then press the Send File button. Once complete it will ask you if you want to lock the flash areas affected. You can say yes or no, shouldnt matter.

In the memory display window if you press the Refresh button the data in flash should now match the data in the blinker1.list file.

Close/exit sam-ba

Unplug the board from the usb cable and then plug it back in. the green led should blink every few seconds which means our program is now in flash and running.

1 comment:

  1. Hi, I am following your suggestions to make my Olimex sam7p256 board running. I downloaded samba and I got the USB port as /dev/ttyUSB0 and I connected using that port and the board configuration as you have specified. But after clicking "connect" I am not getting anything. no SAM BA gui window. When I press the reset button in the board a window pops up saying "Failed to initialize FLASH accesses".
    Even if I wait for a long time no GUI window is appearing before resetting the board. Same behaviour with samba 2.8, 2.9.
    Can you give me any suggestion, should I do any changes to the tcl files.
    any suggestion will help me move from this dead lock.
    Atleast some other tool apart from SAM-BA?