aboutsummaryrefslogtreecommitdiffstats
path: root/sw/Makefile
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2019-10-19 04:12:33 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2019-10-19 04:12:33 +0200
commit95039bc5231f3c9e4b129fd725c6683d21614620 (patch)
treecb51dec0ac0e8a1fb480bbf32209ef8f9e1ae1d3 /sw/Makefile
parent6d6eba632e4ed0f3f3bff0059f55d3f57dbb9954 (diff)
downloadglutte-batteries-95039bc5231f3c9e4b129fd725c6683d21614620.tar.gz
glutte-batteries-95039bc5231f3c9e4b129fd725c6683d21614620.tar.bz2
glutte-batteries-95039bc5231f3c9e4b129fd725c6683d21614620.zip
Add sw skeleton
Diffstat (limited to 'sw/Makefile')
-rw-r--r--sw/Makefile115
1 files changed, 115 insertions, 0 deletions
diff --git a/sw/Makefile b/sw/Makefile
new file mode 100644
index 0000000..06d8dd4
--- /dev/null
+++ b/sw/Makefile
@@ -0,0 +1,115 @@
+# Location of build tools
+CC=avr-gcc
+CXX=avr-g++
+OBJCOPY=avr-objcopy
+SIZE=avr-size
+AVRDUDE=avrdude
+
+# Modify this to the device name of the UART used for AVRDUDE
+AVRDUDE_DEV=usb
+PROG = dragon_isp
+
+# Modify this to the CPU you are using
+PART=atmega328
+AVRDUDE_PART=m328
+
+# Cpu frequency is 16MHz, divider = 2
+F_CPU="(16000000UL/2)"
+
+# Directory for built objects
+BUILD_DIR=build
+
+# Port/application object files
+APP_NAME = testapp1
+
+# Application object files
+APP_CXX_OBJECTS = main.o
+APP_OBJECTS =
+
+# Library object files to build and use
+LIB_OBJECTS =
+LIB_CXX_OBJECTS =
+LIB_ASM_OBJECTS =
+LIB_DIR = lib
+
+# Collection of built objects
+ALL_OBJECTS = $(LIB_OBJECTS) $(LIB_ASM_OBJECTS) $(APP_OBJECTS) $(APP_CXX_OBJECTS)
+BUILT_OBJECTS = $(patsubst %,$(BUILD_DIR)/%,$(ALL_OBJECTS))
+
+# Target application filenames (.elf and .hex) for each application object
+APP_ELF = $(APP_NAME).elf
+APP_HEX = $(APP_NAME).hex
+
+# Search build/output directory for dependencies
+vpath %.o ./$(BUILD_DIR)
+vpath %.elf ./$(BUILD_DIR)
+vpath %.hex ./$(BUILD_DIR)
+
+# GCC flags
+CFLAGS=-g -mmcu=$(PART) -O1 -Wall -Werror -DF_CPU=$(F_CPU)
+INCLUDES=-I. -I$(LIB_DIR)
+
+
+#################
+# Build targets #
+#################
+
+# All applications
+all: $(BUILD_DIR) $(APP_HEX) Makefile
+
+# Make build/output directory
+$(BUILD_DIR):
+ mkdir $(BUILD_DIR)
+
+# Application HEX files
+$(APP_HEX): %.hex: %.elf
+ @echo Building $@
+ $(OBJCOPY) -j .text -j .data -O ihex $(BUILD_DIR)/$< $(BUILD_DIR)/$@
+
+# Application ELF files
+$(APP_ELF): %.elf: $(LIB_OBJECTS) $(LIB_CXX_OBJECTS) $(LIB_ASM_OBJECTS) $(APP_OBJECTS) $(APP_CXX_OBJECTS)
+ $(CXX) $(CFLAGS) $(BUILT_OBJECTS) --output $(BUILD_DIR)/$@ -Wl,-Map,$(BUILD_DIR)/$(basename $@).map
+
+# Application objects builder
+$(APP_OBJECTS): %.o: %.c
+ $(CC) -c $(CFLAGS) $(INCLUDES) $< -o $(BUILD_DIR)/$(notdir $@)
+
+$(APP_CXX_OBJECTS): %.o: %.cpp
+ $(CXX) -c $(CFLAGS) $(INCLUDES) $< -o $(BUILD_DIR)/$(notdir $@)
+
+# Application objects builder
+$(LIB_OBJECTS): %.o: $(LIB_DIR)/%.c
+ $(CC) -c $(CFLAGS) $(INCLUDES) $< -o $(BUILD_DIR)/$(notdir $@)
+
+$(LIB_CXX_OBJECTS): %.o: $(LIB_DIR)/%.cpp
+ $(CXX) -c $(CFLAGS) $(INCLUDES) $< -o $(BUILD_DIR)/$(notdir $@)
+
+$(LIB_ASM_OBJECTS): %.o: $(LIB_DIR)/%.s
+ $(CC) -c $(CFLAGS) -x assembler-with-cpp $(INCLUDES) $< -o $(BUILD_DIR)/$(notdir $@)
+
+# .lst file builder
+%.lst: %.c
+ $(CC) $(CFLAGS) $(INCLUDES) -Wa,-al $< > $@
+
+%.lst: %.cpp
+ $(CXX) $(CFLAGS) $(INCLUDES) -Wa,-al $< > $@
+
+# Clean
+clean:
+ rm -f *.o *.elf *.map *.hex *.bin *.lst
+ rm -rf doxygen-avr
+ rm -rf build
+
+# Send to device
+program: $(APP_HEX)
+ $(SIZE) -C $(BUILD_DIR)/$(APP_ELF)
+ $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(AVRDUDE_DEV) -p $(AVRDUDE_PART) -U flash:w:$(BUILD_DIR)/$(APP_HEX) -v
+
+fuse:
+ $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(AVRDUDE_DEV) -p $(AVRDUDE_PART) -U lfuse:w:0x60:m -U hfuse:w:0xdc:m -U efuse:w:0xff:m -v
+
+interactive:
+ $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(AVRDUDE_DEV) -p $(AVRDUDE_PART) -t -v
+
+doxygen:
+ doxygen ./Doxyfile