crt.S and LPC-p2148

Started by marcoscabcba June 4, 2010
Hello! First of all, my name is Marcos and i'm new in this group. My
first language is Spanish so sorry if i don't write very well in

i'm having the following problem: i'm using lpc-p2148 and
eclipse/yagarto/openocd (the one that comes in de olimex cd with de

I'm using the example that comes in de cd (proyect-->lpc-p2148) that
turns on/off the led's and works okey.

The problem came when I started to introduce some interrupt routines.

To be able to use interrupts I add the file "VIClowlevel.c".

My mian.c is very simple, the led's starts blinking and when a press
the button (B2 off the lpc board) an interrupt occurs and jump into a
routine which starts adc conversions. Up to here all works fine.

After this, I tried to introduce a routine to manage SD cards. So I just
added the file in the makefile (too see if compiles ok) without making
any change in the main.c. Now when I run the program and push the button
that produces the interrupt, the program jumps to another interrupt
direction. ( UNDEF_Routine instead of EINT0_interrupt ). In the bottom
off the message I added the main.c and the Makefiel.

The only modification I introduce was the sd_spi_lpc2000.c in the
makefile, just to compile it. If I don't compile this file, the
program runs okey again.

I believe that the problem maybe in my crt.S or the linker script

I hope you can understand my English,

Thanks in advance.

Here is the mani.c

// Simple blinking led program for the LPC-P2148 board

/* *********************************************************

Declaracion de funciones (Prototipos)

********************************************************* */

void Initialize(void);

void feed(void);

void Configuracion(void);

void IRQ_Routine (void) __attribute__ ((interrupt("IRQ")));

void FIQ_Routine (void) __attribute__ ((interrupt("FIQ")));

void SWI_Routine (void) __attribute__ ((interrupt("SWI")));

void UNDEF_Routine (void) __attribute__ ((interrupt("UNDEF")));

void EINT0_interrupt (void) __attribute__ ((interrupt("IRQ")));

void ADC0_interrupt (void) __attribute__ ((interrupt("IRQ")));

void nonvectoredIRQ(void);


Encabezados de Funcion.


#include "LPC214x.h"

#include "math.h"

#include "VIClowlevel.h"

#include "stdio.h"

#include "float.h"

#include "newlib.h"





Variables para Tarjeta SD






Variables Globales Varias


int m;

unsigned int val;

float Res,ref=3.3;




int main (void)


int j; //Contador para el loop infinito

// Inicializar el Sistema



IOSET0 = 0x00000c00;//APAGO LOS DOS LEDS



enableIRQ(); //habilito las interrupciones

// Loop sin fin que prende y apaga los LED's.

while (1)


for (j = 0; j < 1000000; j++ ); // wait 500 msec

IOSET0 = 0x00000800;

IOCLR0 = 0x00000400;

for (j = 0; j < 1000000; j++ ); // wait 500 msec

IOSET0 = 0x00000400;

IOCLR0 = 0x00000800;






#define PLOCK 0x400

void Initialize(void)


// Setting Multiplier and Divider values



// Enabling the PLL */



// Wait for the PLL to lock to set frequency

while(!(PLL0STAT & PLOCK)) ;

// Connect the PLL as the clock source



// Enabling MAM and setting number of clocks used for Flash memory
fetch (4 cclks in this case)



// Setting peripheral Clock (pclk) to System Clock (cclk)



void feed(void)





void Configuracion(void)


// ------------- CONFIGURACION PINES DE SALIDA----------------

PINSEL0= 0x00000000;// TODOS COMO GPIO

PINSEL1 |= 0x00000001; //P0.30 como AD0.3 Y P0.16 EINT0

PINSEL1 |= 0x10000000;

IODIR0 |= 0x00000c00; // P0.10 & P0.11 output

//------------------CONFIGURACION ADC0-----------------------

AD0CR &=0x0; // borro todos los bits de control

AD0CR |=0x00201F08; //Selecciono para testear AD0.3

//NOSE por cuanto divide el VPB clock
(lo puse igual q anun)

//11 clks por conversion (10 bits de

//PDN =1 lo pongo operacional

//AD0INTEN|= 0x00000008;//el ad0.3 genera interrupcion

//"Done" deAD03 genera laint.

AD0INTEN &= 0x00000000;

//--------------- CONFIGURACION INTERRUPCIONES----------------

VICIntSelect=0x00000000; //selecciono si son FIQ o VIC

VICVectCntl0 =0x00000032; //a este vector asigno el

VICVectCntl1 =0x0000002E; //a este vector asigno el boton q
inicia la conv

//Configuracion EINT0

EXTMODE = 0x00000000; //Enit0 es level sensitive

EXTPOLAR =0x00000000; //EINT0 es activa por bajo

EXTINT =0x00000001; //Borro la bandera de EINT0

//Definos las direc de las int

//VICVectAddr0=(unsigned) ADC0_interrupt;

VICVectAddr1=(unsigned) EINT0_interrupt;

//VICVectAddr1=(unsigned) ADC0_interrupt;

VICDefVectAddr=(unsigned) nonvectoredIRQ;

VICIntEnable=0x00044000; //para habilitar int ADC0 y EINT0



Rutina para escribir tarjeta SD




Rutinas para Interrupciones


void IRQ_Routine (void) {

while (1) ;


void FIQ_Routine (void) {

while (1) ;


void SWI_Routine (void) {

while (1) ;


void UNDEF_Routine (void)




void EINT0_interrupt (void)


int j;

while ((IO0PIN & 0x00010000) != 0x00010000);//espero q el
pulsador salga de 1

for (j = 0; j < 100000; j++ ); //espero un segundo y entro

//inicia la conversion

//aca voy a convertir el dato

AD0CR |= 0x01000000; // comienza a convertir

do // loop para esperar q termine de convertir


val = AD0DR3; // leeo el A/D Data Register


while ((val & 0x80000000) == 0); // Espero que la conversion
este finalizada

val = (val >> 6) & 0x03FF; // borro los otros bits del resultado q
no me importan y roto los bits

Res= val * ref ;

Res= Res/1023;




void ADC0_interrupt (void)




void nonvectoredIRQ()

{ while (1) ;


# ****************************************************************

# * Makefile Para LPC-P2148 - flash execution *

# * *

# * *

# * James P Lynch September 3, 2006 *

# sligthly changed by NSn 200700308 *


# ****************************************************************

NAME = LPC2148

# variables para el Makefile

CC = arm-elf-gcc #Define el compilador de C a utilizar

LD = arm-elf-ld -v

AR = arm-elf-ar

AS = arm-elf-as

CP = arm-elf-objcopy

OD = arm-elf-objdump

#Especificar las librerias 'extra'que se van a utilizar

EXTRA_LIBDIRS = C:\gccfd\projects\lpc-p2148\Librerias_.a -lc -lm -lgcc
#agrego libc.a,libm.a,libgcc.a

#Especificar la Direccion donde se localizan los .c adicionales Y los .h


CFLAGS = -Ic:/gccfd/yagarto/arm-elf/include -c -fno-common -O0 -g

AFLAGS = -ahls -mapcs-32 -o crt.o

LFLAGS = -Map -nostartfiles -T 2138_demo.cmd

CPFLAGS = -O binary

HEXFLAGS = -O ihex

ODFLAGS = -x --syms

#Definir aca los objetos de cada .c

OBJECTS = crt.o main.o VIClowlevel.o sd_spi_lpc2000.o

# make target called by Eclipse (Project -> Clean ...)


-rm -f $(OBJECTS)crt.lst main.out main.bin main.hex

@ echo ">>>TODO LIMPIO<<<"

#make target called by Eclipse (Project -> Build Project)

#all: begin gccversion sizebefore build sizeafter finished end

all: main.out

@ echo "...Copiando"

$(CP) $(CPFLAGS) main.out main.bin

$(OD) $(ODFLAGS) main.out > main.dmp

@echo "...building hex"

$(CP) $(HEXFLAGS) main.out main.hex

@echo ">>>>>>>La Compilaci se ha Completado

main.out: $(OBJECTS) 2138_demo.cmd

@ echo "..linking"

$(LD) $(LFLAGS) -o main.out $(OBJECTS) -L $(EXTRA_LIBDIRS)

crt.o: crt.s

@ echo ".Ensamblando crt.s"

$(AS) $(AFLAGS) crt.s > crt.lst

VIClowlevel.o: VIClowlevel.c

@ echo "--->compilando VIClowlevel"

$(CC) $(CFLAGS) VIClowlevel.c

main.o: main.c LPC214x.h VIClowlevel.h

@ echo "--->Compilando main.c"

$(CC) $(CFLAGS) main.c

sd_spi_lpc2000.o: $(EXTRA_DIR)/sd_spi_lpc2000.c $(EXTRA_DIR)/diskio.h

@ echo "--->compilando sd_spi_lpc2000"

$(CC) $(CFLAGS) $(EXTRA_DIR)/sd_spi_lpc2000.c

An Engineer's Guide to the LPC2100 Series