diff --git a/codes/Makefile b/codes/Makefile new file mode 100644 index 0000000..a94ffdb --- /dev/null +++ b/codes/Makefile @@ -0,0 +1,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 + -- libgit2 0.21.2