Trying to add source files to the OlimexODS LPC2378 blink flash example makefile

Started by BruceC, October 26, 2013, 11:11:40 AM

Previous topic - Next topic

BruceC

It appears the makefile for the LPC2378 blink flash example is not set up to easily expand beyond main.c + crt.s.  I'm expecting to see a line where I can add a new source file (like SRC += newsource.c), but instead the makefile spells out main.c and crt.s throughout the process.

I want to add in about 10 source files and I'm not sure how I would even do one.  What would be the best approach?

On an unrelated note, I notice that the PLLCFG register is defined as an unsigned char in lpc2378.h, which seems like it could be a problem for choosing the PLL "N" value via bits 16:24

Thanks for your help!

BruceC

Update:  I've actually made some progress.  I can now create all the object files via a SRC = file1.c file2.c etc, but I'm having some trouble in the linking stage, wherein I get a bunch of "undefined reference to `__aeabi_uidiv'" and similar errors.  These occur anytime there is a division operator, but only in some files, oddly enough.  For instance if I add a statement with division in main.c it does not create a problem.

I came up with my modifications by studying the SAM7-MT256_lcddemo_FLASH example Makefile.  Here's what I changed:

I inserted:

# List C source files here.
# use file-extension c for "c-only"-files
SRC  = $(TARGET).c
SRC += menu.c
SRC += BilgePumpMonitor.c
SRC += init.c LCDApi.c LCDSetUp.c print.c meter.c ADC.c

# Define all object files.
COBJ      = $(SRC:.c=.o)


Modified the Linker invocation to:

$(TARGET).out:crt.o $(COBJ) 2378_demo.cmd
   @echo
   @echo "--- Linking"
   $(LD) $(LFLAGS) -o main.out  crt.o $(COBJ)


And replaced the original c compiler invocation with:

# Compile: create object files from C source files. ARM
$(COBJ) : %.o : %.c
   @ echo
   @ echo "- compiling"
   $(CC) -c $(CFLAGS) $< -o $@

BruceC

Here's the whole makefile as it currently stands:

NAME   = lpc_p2378
PROJNAME = LPC-2378(-STK)
TARGET = main
OLIMEX_MSG = "OLIMEX OpenOCD projects (Eclipse Helios)"
MSG_BEGIN = "------ begin (proj:$(PROJNAME))------"
MSG_END   = ------  end  ------

# List C source files here. (C dependencies are automatically generated.)
# use file-extension c for "c-only"-files
SRC  = $(TARGET).c
SRC += menu.c
SRC += BilgePumpMonitor.c
SRC += init.c LCDApi.c LCDSetUp.c print.c meter.c ADC.c
#SRC += lpc177x8xRTC.c uart.c 
#SRC += $(TARGET).c cdc_enumerate.c interrupt_Usart.c

# List C source files here which must be compiled in ARM-Mode.
# use file-extension c for "c-only"-files
SRCARM  =

# List Assembler source files here.
# Make them always end in a capital .S.  Files ending in a lowercase .s
# will not be considered source files but generated files (assembler
# output from the compiler), and will be deleted upon "make clean"!
# Even though the DOS/Win* filesystem matches both .s and .S the same,
# it will preserve the spelling of the filenames, and gcc itself does
# care about how the name is spelled on its command-line.
ASRC =

# List Assembler source files here which must be assembled in ARM-Mode..
ASRCARM  = crt.S
ASRCARM += critical.S

# Define all object files.
COBJ      = $(SRC:.c=.o)
AOBJ      = $(ASRC:.S=.o)
COBJARM   = $(SRCARM:.c=.o)
AOBJARM   = $(ASRCARM:.S=.o)

# Define all listing files.
LST = $(ASRC:.S=.lst) $(ASRCARM:.S=.lst) $(SRC:.c=.lst) $(SRCARM:.c=.lst)
#LST += $(CPPSRC:.cpp=.lst) $(CPPSRCARM:.cpp=.lst)

CC      = arm-none-eabi-gcc
LD      = arm-none-eabi-ld -v
AR      = arm-none-eabi-ar
AS      = arm-none-eabi-as
CP      = arm-none-eabi-objcopy
OD = arm-none-eabi-objdump

#  -g*:          generate debugging information
#  -O*:          optimization level
CFLAGS  = -I./ -c -fno-common -O0 -g
AFLAGS  = -ahls -mapcs-32 -o crt.o
LFLAGS  =  -Map main.map -T2378_demo.cmd
CPFLAGS = -O binary
HEXFLAGS = -O ihex
ODFLAGS = -x --all-headers
REMOVE  = -rm -f
#SHELL = sh

all: begin build end

clean: begin clean_list end

clean_list:
@ echo
@ echo "Cleaning project..."
@ echo
$(REMOVE) $(TARGET).o $(TARGET).map $(TARGET).bin $(TARGET).elf $(TARGET).hex $(TARGET).out crt.o $(COBJ)

build:$(TARGET).out
@ echo
@ echo "--- Copying to .bin"
$(CP) $(CPFLAGS) main.out main.bin
@ echo
@ echo "--- Building hex"
$(CP) $(HEXFLAGS) main.out main.hex


$(TARGET).out:crt.o critical.o $(COBJ) 2378_demo.cmd
# $(TARGET).out:crt.o main.o menu.o BilgePumpMonitor.o 2378_demo.cmd
@echo
@echo "--- Linking"
$(LD) $(LFLAGS) -o main.out  crt.o critical.o $(COBJ)
# $(LD) $(LFLAGS) -o main.out  crt.o main.o menu.o BilgePumpMonitor.o

crt.o: crt.s
@ echo
@ echo "--- Building"
@ echo "- assembling"
$(AS) $(AFLAGS) crt.s

critical.o: critical.s
@ echo
@ echo "--- Building"
@ echo "- assembling"
$(AS) $(AFLAGS) critical.s

# Compile: create object files from C source files. ARM
$(COBJ) : %.o : %.c
@ echo
@ echo "- compiling"
$(CC) -c $(CFLAGS) $< -o $@

#menu.o: menu.c
# @ echo
# @ echo "- compiling"
# $(CC) $(CFLAGS) menu.c

#main.o: main.c
# @ echo
# @ echo "- compiling"
# $(CC) $(CFLAGS) main.c



begin:
@echo
@echo $(OLIMEX_MSG)
@echo $(MSG_BEGIN)

end:
@echo
@echo $(MSG_END)