Makefile
2.19 KB
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
export CC = avr-gcc
export MCU = atmega328p
export TARGET_ARCH = -mmcu=$(MCU)
export CFLAGS = -Wall -I. -DF_CPU=16000000 -Os #-pedantic -std=c99#-g
export LDFLAGS = -g $(TARGET_ARCH) -lm -Wl,--gc-sections # -Os
TARGET = libretour
TERM0 = /dev/ttyACM0
TERM1 = /dev/ttyACM1
CPPFLAGS = -mmcu=$(MCU)
#PGMER = -c stk500v1 -b 57600 -P $(TERM)
#Dans le cas de l'upload par USB (selon le port)
PGMERISP0 = -c stk500v1 -b 115200 -P $(TERM0)
PGMERISP1 = -c stk500v1 -b 115200 -P $(TERM1)
ARVDUDECONF= -C /usr/local/arduino/arduino-0021/hardware/tools/avrdude.conf
export DUDE = /usr/bin/avrdude -F -v -p $(MCU) $(AVRDUDECONF)
#Dans le cas de l'upload par SPI depuis la raspberry
PGMERISP_RPI = -c pi_3
ARVDUDECONF_RPI = -C ~/avrdude_gpio.conf
export DUDE_RPI = avrdude -v -p $(MCU) $(AVRDUDECONF_RPI)
CLIB=ar cq
C_SRC = $(wildcard *.c)
OBJS = $(C_SRC:.c=.o)
all: $(TARGET).a
clean:
rm -f *.o *.hex *.elf *.a build-uno
$(TARGET).o: $(TARGET).c $(TARGET).h
$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
$(TARGET).elf: $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS)
$(TARGET).hex: $(TARGET).elf
avr-objcopy -j .text -j .data -O ihex $(TARGET).elf $(TARGET).hex
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex $(TARGET).elf eeprom.hex
$(TARGET).a: $(TARGET).o
rm -rf $@
$(CLIB) $@ $+
#UPLOAD CONDITIONNEL
FOLDER = $(notdir $(CURDIR))
upload: $(TARGET).hex
#CAPTEUR 1 connecté en USB
ifeq ($(FOLDER), capteur1-0)
stty -F $(TERM0) hupcl # reset
# $(DUDE) $(PGMER) -U flash:w:$(TARGET).hex
$(DUDE) $(PGMERISP0) -U flash:w:$(TARGET).hex
endif
#CAPTEUR 1 connecté en SPI
ifeq ($(FOLDER), capteur1-1)
stty -F $(TERM0) hupcl # reset
# $(DUDE) $(PGMER) -U flash:w:$(TARGET).hex
$(DUDE_RPI) $(PGMERISP_RPI) -U flash:w:$(TARGET).hex
endif
#CAPTEUR 2 connecté en USB
ifeq ($(FOLDER), capteur2-0)
stty -F $(TERM1) hupcl # reset
# $(DUDE) $(PGMER) -U flash:w:$(TARGET).hex
$(DUDE) $(PGMERISP1) -U flash:w:$(TARGET).hex
endif
#CAPTEUR 2 connecté en SPI
ifeq ($(FOLDER), capteur2-1)
stty -F $(TERM1) hupcl # reset
# $(DUDE) $(PGMER) -U flash:w:$(TARGET).hex
$(DUDE_RPI) $(PGMERISP_RPI) -U flash:w:$(TARGET).hex
endif
size: $(TARGET).elf
avr-size --format=avr --mcu=$(MCU) $(TARGET).elf