Makefile 4.64 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#	Generic makefile

#-------------------------------------------------------------------------------
#		User set options
#-------------------------------------------------------------------------------

CHIP	= at91sam9g20
BOARD	= at91sam9g20-ek

# Trace level used for compilation
# (can be overriden by adding TRACE_LEVEL=#number to the command-line)
# TRACE_LEVEL_DEBUG      5
# TRACE_LEVEL_INFO       4
# TRACE_LEVEL_WARNING    3
# TRACE_LEVEL_ERROR      2
# TRACE_LEVEL_FATAL      1
# TRACE_LEVEL_NO_TRACE   0
18
# TRACE_LEVEL	= 5
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

AT91LIB		= src/at91lib
FREERTOS	= src/freertos

# Output file basename
OUTPUT		= img

# Compile with specific chip features
CHIP_CORE	= arm926ej_s
CHIP_IP_MCI	= MCI_PDC
CHIP_IP_UDP	= USB_UDP
CHIP_IP_UHP	= USB_OHCI

# Compile for all available memories
MEMORIES 	= sdram

# Output directories
BIN		= bin
OBJ		= obj

#-------------------------------------------------------------------------------
#		Tools
#-------------------------------------------------------------------------------

# Tools suffix when cross-compiling
CROSS_COMPILE=arm-none-eabi-

# Compilation tools
CC 	= $(CROSS_COMPILE)gcc
SIZE	= $(CROSS_COMPILE)size
STRIP	= $(CROSS_COMPILE)strip
OBJCOPY	= $(CROSS_COMPILE)objcopy

# Flags
INCLUDES	= -I$(AT91LIB)/boards/$(BOARD)
INCLUDES	+= -I$(AT91LIB)/peripherals
INCLUDES	+= -I$(AT91LIB)/components
INCLUDES	+= -I$(AT91LIB)
INCLUDES	+= -I$(FREERTOS)/portable/GCC/ARM9_AT91SAM9G20
INCLUDES	+= -I$(FREERTOS)/portable/MemMang
INCLUDES	+= -I$(FREERTOS)/portable/
INCLUDES	+= -I$(FREERTOS)/include
INCLUDES	+= -I$(FREERTOS)
INCLUDES	+= -Isrc/

64 65
OPTIM	= -O3

66
CFLAGS	= -Wall -mlong-calls -ffunction-sections
67 68 69 70 71 72
CFLAGS	+= -fomit-frame-pointer -fno-strict-aliasing -fno-dwarf2-cfi-asm
CFLAGS  += -mthumb-interwork -D THUMB_INTERWORK
CFLAGS	+= -g $(OPTIM) $(INCLUDES) -D$(CHIP)
# -DTRACE_LEVE=$(TRACE_LEVEL)
ASFLAGS	= -Wall -g $(OPTIM) $(INCLUDES) -D$(CHIP) -D__ASSEMBLY__
LDFLAGS	= -mthumb -g $(OPTIM) -nostartfiles -Wl,--gc-sections
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162

#-------------------------------------------------------------------------------
#		FILES
#-------------------------------------------------------------------------------

# Directories where source files can be found
UTILITY	= $(AT91LIB)/utility
PERIPH	= $(AT91LIB)/peripherals
BOARDS	= $(AT91LIB)/boards

PORT	= $(FREERTOS)/portable/GCC/ARM9_AT91SAM9G20
MEM_MGT	= $(FREERTOS)/portable/MemMang	

VPATH   = src/
VPATH	+= $(UTILITY)
VPATH	+= $(PERIPH)/dbgu
VPATH	+= $(PERIPH)/irq
VPATH	+= $(PERIPH)/pio
VPATH	+= $(PERIPH)/pit
VPATH	+= $(PERIPH)/tc
VPATH	+= $(PERIPH)/pmc
VPATH	+= $(PERIPH)/cp15
VPATH	+= $(PERIPH)/systicks
VPATH	+= $(BOARDS)/$(BOARD)
VPATH	+= $(BOARDS)/$(BOARD)/$(CHIP)
VPATH	+= $(MEM_MGT)
VPATH	+= $(PORT)
VPATH	+= $(FREERTOS)


# Objects build from C source files
C_OBJECTS	= main.o
C_OBJECTS	+= led.o
C_OBJECTS	+= stdio.o
C_OBJECTS	+= dbgu.o
C_OBJECTS	+= pio.o
C_OBJECTS	+= pio_it.o
C_OBJECTS	+= tc.o
C_OBJECTS	+= pmc.o
C_OBJECTS	+= board_lowlevel.o
C_OBJECTS	+= trace.o
C_OBJECTS	+= board_memories.o
C_OBJECTS	+= aic.o
C_OBJECTS	+= cp15.o
C_OBJECTS	+= pit.o
C_OBJECTS	+= port.o
C_OBJECTS	+= tasks.o
C_OBJECTS	+= queue.o
C_OBJECTS	+= event_groups.o
C_OBJECTS	+= list.o
C_OBJECTS	+= stream_buffer.o
C_OBJECTS	+= timers.o
C_OBJECTS	+= heap_2.o

# Objects build with ARM instruction set from C source files
ARM_OBJECTS 	= portISR.o


# Objects build form assembly source files
ASM_OBJECTS	= board_cstartup.o
ASM_OBJECTS	+= cp15_asm_gcc.o

#Append OBJ and BIN directories to output filename
OUTPUT	:= $(BIN)/$(OUTPUT)

#-------------------------------------------------------------------------------
#		Rules
#-------------------------------------------------------------------------------
all: $(BIN) $(OBJ) $(MEMORIES)

phony: flash clean

$(BIN) $(OBJ):
	mkdir $@

define RULES
ARM_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(ARM_OBJECTS))
C_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(C_OBJECTS))
ASM_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(ASM_OBJECTS))

$(1): $$(ARM_OBJECTS_$(1)) $$(ASM_OBJECTS_$(1)) $$(C_OBJECTS_$(1))
	$(CC) $(LDFLAGS) -T"$(AT91LIB)/boards/$(BOARD)/$(CHIP)/$$@.lds" \
	-o $(OUTPUT)-$$@.elf $$^
	$(OBJCOPY) -O binary $(OUTPUT)-$$@.elf $(OUTPUT)-$$@.bin
	$(SIZE) $$^ $(OUTPUT)-$$@.elf

$$(ARM_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.c Makefile $(OBJ) $(BIN)
	$(CC) $(CFLAGS) -D$(1) -c -o $$@ $$<

$$(C_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.c Makefile $(OBJ) $(BIN)
163
	$(CC) $(CFLAGS) -mthumb -D$(1) -c -o $$@ $$<
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181

$$(ASM_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.S Makefile $(OBJ) $(BIN)
	$(CC) $(ASFLAGS) -D$(1) -c -o $$@ $$<

debug_$(1): $(1)
	perl ../resources/gdb/debug.pl $(OUTPUT)-$(1).elf

endef

$(foreach MEMORY, $(MEMORIES), $(eval $(call RULES,$(MEMORY))))

flash:
	./src/flashing/flash.sh

clean:
	-rm -f $(OBJ)/*.o $(BIN)/*.bin $(BIN)/*.elf flash.log