Commit 29232b6e1699f9e86fdf212864485a89ed3cf837
1 parent
ccb29150
Makefile générique qui upload le code selon le num de capteur et le moyen d'upload (USB, SPI)
J'ai volontairement omis de gérer la NUCLEO pour l'instant
Showing
1 changed file
with
81 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,81 @@ | @@ -0,0 +1,81 @@ | ||
1 | +export CC = avr-gcc | ||
2 | + | ||
3 | +export MCU = atmega328p | ||
4 | +export TARGET_ARCH = -mmcu=$(MCU) | ||
5 | + | ||
6 | +export CFLAGS = -Wall -I. -DF_CPU=16000000 -Os #-pedantic -std=c99#-g | ||
7 | +export LDFLAGS = -g $(TARGET_ARCH) -lm -Wl,--gc-sections # -Os | ||
8 | + | ||
9 | +TARGET = libretour | ||
10 | +TERM0 = /dev/ttyACM0 | ||
11 | +TERM1 = /dev/ttyACM1 | ||
12 | +CPPFLAGS = -mmcu=$(MCU) | ||
13 | +#PGMER = -c stk500v1 -b 57600 -P $(TERM) | ||
14 | +PGMERISP0 = -c stk500v1 -b 115200 -P $(TERM0) | ||
15 | +PGMERISP1 = -c stk500v1 -b 115200 -P $(TERM1) | ||
16 | +ARVDUDECONF= -C /usr/local/arduino/arduino-0021/hardware/tools/avrdude.conf | ||
17 | +export DUDE = /usr/bin/avrdude -F -v -p $(MCU) $(AVRDUDECONF) | ||
18 | +CLIB=ar cq | ||
19 | + | ||
20 | +C_SRC = $(wildcard *.c) | ||
21 | +OBJS = $(C_SRC:.c=.o) | ||
22 | + | ||
23 | +all: $(TARGET).a | ||
24 | + | ||
25 | + | ||
26 | +clean: | ||
27 | + rm -f *.o *.hex *.elf *.a | ||
28 | + | ||
29 | +$(TARGET).o: $(TARGET).c $(TARGET).h | ||
30 | + $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ | ||
31 | + | ||
32 | + | ||
33 | +$(TARGET).elf: $(OBJS) | ||
34 | + $(CC) $(LDFLAGS) -o $@ $(OBJS) | ||
35 | + | ||
36 | +$(TARGET).hex: $(TARGET).elf | ||
37 | + avr-objcopy -j .text -j .data -O ihex $(TARGET).elf $(TARGET).hex | ||
38 | + avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex $(TARGET).elf eeprom.hex | ||
39 | + | ||
40 | +$(TARGET).a: $(TARGET).o | ||
41 | + rm -rf $@ | ||
42 | + $(CLIB) $@ $+ | ||
43 | + | ||
44 | + | ||
45 | +#UPLOAD CONDITIONNEL | ||
46 | +FOLDER = $(notdir $(CURDIR)) | ||
47 | + | ||
48 | +upload: $(TARGET).hex | ||
49 | +#CAPTEUR 1 | ||
50 | +ifeq ($(FOLDER), capteur1-0) | ||
51 | + | ||
52 | + stty -F $(TERM0) hupcl # reset | ||
53 | + # $(DUDE) $(PGMER) -U flash:w:$(TARGET).hex | ||
54 | + $(DUDE) $(PGMERISP0) -U flash:w:$(TARGET).hex | ||
55 | +endif | ||
56 | + | ||
57 | +ifeq ($(FOLDER), capteur1-1) | ||
58 | + | ||
59 | + stty -F $(TERM0) hupcl # reset | ||
60 | + # $(DUDE) $(PGMER) -U flash:w:$(TARGET).hex | ||
61 | + $(DUDE) $(PGMERISP0) -U flash:w:$(TARGET).hex | ||
62 | +endif | ||
63 | + | ||
64 | +#CAPTEUR 2 | ||
65 | +ifeq ($(FOLDER), capteur2-0) | ||
66 | + | ||
67 | + stty -F $(TERM1) hupcl # reset | ||
68 | + # $(DUDE) $(PGMER) -U flash:w:$(TARGET).hex | ||
69 | + $(DUDE) $(PGMERISP1) -U flash:w:$(TARGET).hex | ||
70 | +endif | ||
71 | + | ||
72 | +ifeq ($(FOLDER), capteur2-1) | ||
73 | + | ||
74 | + stty -F $(TERM1) hupcl # reset | ||
75 | + # $(DUDE) $(PGMER) -U flash:w:$(TARGET).hex | ||
76 | + $(DUDE) $(PGMERISP1) -U flash:w:$(TARGET).hex | ||
77 | +endif | ||
78 | + | ||
79 | +size: $(TARGET).elf | ||
80 | + avr-size --format=avr --mcu=$(MCU) $(TARGET).elf | ||
81 | + |