Warning!! This is my first foray into the world of ARM straight on silicon (done ARM code under Linux before)
I just got a sam7x256 based board (SAM7-EX256 from olimex) together with a olimes JTAG tiny that I’m trying to learn ARM coding on.
I have used quite a bit of 8 bit avr’s before, but this turns out to be much more complicated than I though
I’m using Crossworks ide and have a project I found online (simple LED blinker) and modified it so it uses a pin available on the boards EXT connector (PA4).
I also include the at91sam7x256.h from atmel rather than the one supplied with crossworks to make it compatible with the sample but it seem to also list the crossworks ones in the project explorer from creating the project as a at91sam7x256 project.
The code runs fine if I create a RAM DEBUG target or RAM RELEASE target and start it from the IDE. LED blinks.
however if I create a FLASH DEBUG or FLASH RELEASE target, I can flash the board seemingly correctly and it verifies, but if I start debug and step through…it seem to work in the ide, but no LED blinking. If I do FLASH RELEASE target, I can’t start it from the IDE or from reset/bootup.
I read an entry on the Crossworks support site about creating a definition(STARTUP_FROM_RESET) for startup code, but I have tried to add it to what I think is the startup code(AT91SAM7_startup.s and crt0.s), though I don’t see any conditional statement looking for the definition in any file.
I also tried changing the TST jumper to no avail.
Please help me get this ball rolling so that I can start some real code
Just in case, here is the code from the main unit in case that is screwing with the startup:
// CrossWorks Tutorial
#include <cross_studio_io.h>
/*
* main.c - AT91SAM7 hello world example program.
*
* Copyright (c) 2007 by Wolfgang Wieser ] wwieser (a) gmx <*> de [
*/
#include "AT91SAM7X256.h"
typedef signed char int8;
typedef unsigned char uint8;
#define nop() __asm__ __volatile__("nop")
#define LED_A (1U<<3) /* PA0, pin 48 */
static void DefaultInterruptHandler(void)
{ /* Do nothing. */ }
static void SpuriousInterruptHandler(void)
{ /* Never do anything; just return as quickly as possible. */ }
// Endless loop of LED_A (PA0) blinks for error diagnosis.
extern void PanicBlinker(uint8 code);
void PanicBlinker(uint8 code)
{
volatile AT91PS_PIO pPIO = AT91C_BASE_PIOA;
pPIO->PIO_PER |= LED_A; // Allow PIO to control LEDs.
pPIO->PIO_OER |= LED_A; // Enable output.
pPIO->PIO_SODR = LED_A; // Start with LED off.
for(;;)
{
uint8 i;
unsigned int j;
for(i=0; i<code; i++)
{
pPIO->PIO_CODR = LED_A; // LOW = turn LED on.
for(j=300000; j; j--) nop();
pPIO->PIO_SODR = LED_A; // HIGH = turn LED off.
for(j=300000; j; j--) nop();
}
for(j=300000*3; j; j--) nop(); // Wait some time...
}
}
// Hardware initialization function.
static void Initialize(void)
{
// Set Flash Wait sate: 0 wait states.
AT91C_BASE_MC->MC_FMR = ((AT91C_MC_FMCN)&(22 <<16)) | AT91C_MC_FWS_0FWS;
// Disable watchdog.
AT91C_BASE_WDTC->WDTC_WDMR= AT91C_WDTC_WDDIS;
// Start up the main oscillator.
AT91PS_PMC pPMC = AT91C_BASE_PMC;
pPMC->PMC_MOR = (( AT91C_CKGR_OSCOUNT & (6U <<8)) | AT91C_CKGR_MOSCEN );
while(!(pPMC->PMC_SR & AT91C_PMC_MOSCS));
// Select master clock (MCK): Main oscillator.
pPMC->PMC_MCKR = AT91C_PMC_CSS_MAIN_CLK;
while(!(pPMC->PMC_SR & AT91C_PMC_MCKRDY));
pPMC->PMC_MCKR = AT91C_PMC_CSS_MAIN_CLK | AT91C_PMC_PRES_CLK;
while(!(pPMC->PMC_SR & AT91C_PMC_MCKRDY));
// Enable user reset. This aids in debugging.
AT91C_BASE_RSTC->RSTC_RMR = 0xa5000400U | AT91C_RSTC_URSTEN;
// Set up the default interrupt handlers. 0 = FIQ, 1 = SYS.
int i;
for(i=0; i<31; i++)
{ AT91C_BASE_AIC->AIC_SVR[i] = (unsigned)&DefaultInterruptHandler; }
AT91C_BASE_AIC->AIC_SPU = (unsigned)&SpuriousInterruptHandler;
// Set up the IOs.
volatile AT91PS_PIO pPIO = AT91C_BASE_PIOA;
pPIO->PIO_PER = LED_A ; // Allow PIO to control LEDs.
pPIO->PIO_OER = LED_A ; // Enable outputs for LED pins.
pPIO->PIO_SODR = LED_A ; // Set outputs HIGH to turn LEDs off.
}
uint8 delay_us(uint8 x)
{
while(x--)
{
asm volatile (" NOP");
asm volatile (" NOP");
asm volatile (" NOP");
asm volatile (" NOP");
asm volatile (" NOP");
asm volatile (" NOP");
asm volatile (" NOP");
asm volatile (" NOP");
asm volatile (" NOP");
asm volatile (" NOP");
asm volatile (" NOP");
asm volatile (" NOP");
asm volatile (" NOP");
}
return 0;
}
uint8 delay_ms(int time)
{
uint8 i;
while(time--)
{
for(i=0; i<4; i++)
{
delay_us(250);
}
}
return 0;
}
int main(void)
{
Initialize();
int j;
volatile AT91PS_PIO pPIO = AT91C_BASE_PIOA;
for(;;)
{
int i;
// Toggle...
pPIO->PIO_CODR = LED_A;
delay_ms(500);
pPIO->PIO_SODR = LED_A;
delay_ms(500);
}
return(0);
}
[/code]