aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
blob: bf6bed535f0eeebc9686b39471d93b7ab746ecd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
64
65
66
67
68
69
70
71
72
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# dumb dumb dumb makefile
# Project name
PROJECT=maple

STM_CONF = stm32conf/flash.conf

# ARM/GNU toolchain parameters
CC  := arm-none-eabi-gcc
CPP := arm-none-eabi-g++
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

# Platform detection
ARCH = $(shell uname -m)
OS = $(shell uname)

VENDOR_ID =  1EAF
PRODUCT_ID = 0003

ifeq ($(OS),Linux)
	DFU = dfu-util
else
	DFU = ../dfu-util/bin/linux/dfu-util
endif

BUILD_PATH = build
LIB_PATH = libmaple

OUTDIRS = $(BUILD_PATH)/$(LIB_PATH)\
	  $(BUILD_PATH)/wirish \
	  $(BUILD_PATH)/wirish/comm \
	  $(BUILD_PATH)/$(LIB_PATH)/usb \
	  $(BUILD_PATH)/$(LIB_PATH)/usb/usb_lib


INCLUDES = -I$(LIB_PATH) \
	   -I./ \
	   -Iwirish \
	   -Iwirish/comm \
	   -I$(LIB_PATH)/usb \
	   -I$(LIB_PATH)/usb/usb_lib 

# default is to upload to flash
#DEFFLAGS = VECT_TAB_BASE
CFLAGS  =  $(INCLUDES) -c \
           -Os\
           -g -mcpu=cortex-m3 -mthumb  -march=armv7-m -nostdlib \
           -ffunction-sections -fdata-sections -Wl,--gc-sections \
	   -D$(DEFFLAGS)

CXXFLAGS = -fno-rtti -fno-exceptions -Wall

#LINKER=lanchon-stm32.ld
LFLAGS  = -Tstm32conf/$(LINKER) -L stm32conf/lanchon-stm32 \
          -mcpu=cortex-m3 -mthumb -Xlinker \
          --gc-sections --print-gc-sections --march=armv7-m -Wall

CPFLAGS = -v -Obinary
ODFLAGS = -S

CSRC = libmaple/systick.c                \
       libmaple/timers.c                 \
       libmaple/adc.c 	                 \
       libmaple/syscalls.c 	         \
       libmaple/exc.c                    \
       libmaple/exti.c 	                 \
       libmaple/gpio.c 	                 \
       libmaple/nvic.c 	                 \
       libmaple/usart.c 	         \
       libmaple/util.c	                 \
       libmaple/rcc.c                    \
       libmaple/flash.c                  \
       libmaple/spi.c                    \
       wirish/wirish.c 	                 \
       wirish/wirish_shift.c             \
       wirish/wirish_analog.c            \
       wirish/time.c 		         \
       wirish/pwm.c 		         \
       wirish/ext_interrupts.c           \
       wirish/wirish_digital.c           \
       libmaple/usb/usb.c		 \
       libmaple/usb/usb_callbacks.c      \
       libmaple/usb/usb_hardware.c       \
       libmaple/usb/descriptors.c        \
       libmaple/usb/usb_lib/usb_core.c   \
       libmaple/usb/usb_lib/usb_init.c   \
       libmaple/usb/usb_lib/usb_int.c    \
       libmaple/usb/usb_lib/usb_mem.c    \
       libmaple/usb/usb_lib/usb_regs.c   \

CPPSRC = wirish/wirish_math.cpp          \
	 wirish/Print.cpp 		 \
	 wirish/comm/HardwareSerial.cpp  \
	 wirish/comm/HardwareUsb.cpp     \
	 wirish/comm/HardwareSPI.cpp 	 \
	 wirish/cxxabi-compat.cpp 	 \
   	 main.cpp

# i really have no idea what i'm doing
meep += $(CSRC)
moop = $(patsubst %, %, $(meep))
beep = $(CPPSRC)
boop = $(patsubst %, %, $(beep))

# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = -------- begin --------
MSG_ETAGS = Created TAGS File
MSG_END = --------  end  --------
MSG_SIZE = Program Image Size:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling C:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:
MSG_FLASH = Creating load file for Flash:


_COBJ =  $(moop:.c=.o)
_CPPOBJ =  $(boop:.cpp=.o)
COBJ = $(patsubst %, $(BUILD_PATH)/%,$(_COBJ))
CPPOBJ = $(patsubst %, $(BUILD_PATH)/%,$(_CPPOBJ))

.PHONY: run cscope clean info program_ram program_flash program_jtag

info:
	@echo ""
	@echo "libmaple Makefile help"
	@echo "----------------------"
	@echo "Compile targets:"
	@echo "  ram:    Compile sketch code for RAM to be loaded over the bootloader"
	@echo "  flash:  Compile sketch code for flash to be loaded over the bootloader"
	@echo "  jtag:   Compile sketch code for flash to be loaded over JTAG"
	@echo ""
	@echo "Programming targets:"
	@echo "  program_ram:   Upload code to RAM via bootloader"
	@echo "  program_flash: Upload code to flash via bootloader"
	@echo "  program_jtag:  Upload code to flash via jtag"

all: info

tags:
	etags `find . -name "*.c" -o -name "*.cpp" -o -name "*.h"`
	@echo "Made TAGS file for EMACS code browsing"

$(BUILD_PATH):
	mkdir -p build

$(OUTDIRS):
	@echo Making directory $@
	mkdir -p $@
	@echo

# actual build rules
$(COBJ) : $(BUILD_PATH)/%.o : %.c
	@echo $(MSG_COMPILING) $<
	$(CC) $(CFLAGS) -c $< -o $@
	@echo

$(CPPOBJ) : $(BUILD_PATH)/%.o : %.cpp
	@echo $(MSG_COMPILING) $<
	$(CPP) $(CFLAGS) $(CXXFLAGS) -c $< -o $@
	@echo

# targets
$(BUILD_PATH)/$(PROJECT).out: $(OUTDIRS) $(COBJ) $(CPPOBJ)
	@echo Linking
	@echo CPP OBJ: $(CPPOBJ)
	@echo
	@echo C OBJ: $(COBJ)
	@echo
	$(CC) $(LFLAGS) -o $(BUILD_PATH)/$(PROJECT).out $(COBJ) $(CPPOBJ)
	@echo

$(BUILD_PATH)/main.bin: $(BUILD_PATH)/$(PROJECT).out
	$(CP) $(CPFLAGS) $(BUILD_PATH)/$(PROJECT).out $(BUILD_PATH)/main.bin
	$(OD) $(ODFLAGS) $(BUILD_PATH)/$(PROJECT).out > $(BUILD_PATH)/$(PROJECT).d
	@echo
	find $(BUILD_PATH) -iname *.o | xargs arm-none-eabi-size -t
	@echo
	@echo "Final Size:"
	arm-none-eabi-size $<

ram: DEFFLAGS := VECT_TAB_RAM
ram: LINKER := lanchon-stm32-user-ram.ld
ram: $(BUILD_PATH)/main.bin
	@echo "RAM build"

flash: DEFFLAGS := VECT_TAB_ROM
flash: LINKER := lanchon-stm32-user-rom.ld
flash: $(BUILD_PATH)/main.bin
	@echo "Flash build"

jtag: DEFFLAGS := VECT_TAB_BASE
jtag: LINKER := lanchon-stm32.ld
jtag: $(BUILD_PATH)/main.bin
	@echo "JTAG build"

program_ram: ram 
	./reset.py
	sleep 1
	$(DFU) -a0 -d $(VENDOR_ID):$(PRODUCT_ID) -D build/main.bin -R

program_flash: flash
	./reset.py
	sleep 1
	$(DFU) -a1 -d $(VENDOR_ID):$(PRODUCT_ID) -D build/main.bin -R

program_jtag: jtag
	openocd -f stm32conf/flash.cfg


run: $(BUILD_PATH)/main.bin
	openocd -f stm32conf/run.cfg

cscope:
	rm -rf *.cscope
	find . -name '*.[hcs]' -o -name '*.cpp' | xargs cscope

clean:
	rm -f *.hex *.o
	rm -rf build