From 4bdf20145ba9671537061f39b4290dc0473ce2a3 Mon Sep 17 00:00:00 2001 From: David Lenfesty Date: Tue, 3 Sep 2019 09:25:53 -0600 Subject: [PATCH] Initial Commit --- Makefile | 79 +++++++++++++++++++++++ main.c | 5 ++ main.elf | Bin 0 -> 5064 bytes main.hex | 5 ++ thing.c | 3 + thing.mk | 189 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 281 insertions(+) create mode 100644 Makefile create mode 100644 main.c create mode 100755 main.elf create mode 100644 main.hex create mode 100644 thing.c create mode 100644 thing.mk diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..362cb30 --- /dev/null +++ b/Makefile @@ -0,0 +1,79 @@ +# Stolen from github +# +# Name: Makefile +# Author: +# Copyright: +# License: + +# DEVICE ....... The AVR device you compile for +# CLOCK ........ Target AVR clock rate in Hertz +# OBJECTS ...... The object files created from your source files. This list is +# usually the same as the list of source files with suffix ".o". +# PROGRAMMER ... Options to avrdude which define the hardware you use for +# uploading to the AVR and the interface where this hardware +# is connected. +# FUSES ........ Parameters for avrdude to flash the fuses appropriately. + +DEVICE = attiny2313 +CLOCK = 8000000 +PROGRAMMER = -c arduino -P /dev/tty.usb* -b 19200 +OBJECTS = main.o thing.o +FUSES = -U lfuse:w:0x64:m -U hfuse:w:0xdd:m -U efuse:w:0xff:m +BUILD_DIR = _build + + +###################################################################### +###################################################################### + +# Tune the lines below only if you know what you are doing: + +AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE) +COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE) + +# symbolic targets: +all: main.hex + +.c.o: + $(COMPILE) -c $< -o $@ + +.S.o: + $(COMPILE) -x assembler-with-cpp -c $< -o $@ +# "-x assembler-with-cpp" should not be necessary since this is the default +# file type for the .S (with capital S) extension. However, upper case +# characters are not always preserved on Windows. To ensure WinAVR +# compatibility define the file type manually. + +.c.s: + $(COMPILE) -S $< -o $@ + +flash: all + $(AVRDUDE) -U flash:w:main.hex:i + +fuse: + $(AVRDUDE) $(FUSES) + +install: flash fuse + +# if you use a bootloader, change the command below appropriately: +load: all + bootloadHID main.hex + +clean: + rm -f main.hex main.elf $(OBJECTS) + +# file targets: +main.elf: $(OBJECTS) + $(COMPILE) -o main.elf $(OBJECTS) + +main.hex: main.elf + rm -f main.hex $(OBJECTS) + avr-objcopy -j .text -j .data -O ihex main.elf main.hex +# If you have an EEPROM section, you must also create a hex file for the +# EEPROM and add it to the "flash" target. + +# Targets for code debugging and analysis: +disasm: main.elf + avr-objdump -d main.elf + +cpp: + $(COMPILE) -E main.c diff --git a/main.c b/main.c new file mode 100644 index 0000000..6dd3802 --- /dev/null +++ b/main.c @@ -0,0 +1,5 @@ +#include + +int main() { + // do nothing +} diff --git a/main.elf b/main.elf new file mode 100755 index 0000000000000000000000000000000000000000..7223aa094f7c9ece6ed6dc089fd7effab8031d8e GIT binary patch literal 5064 zcmb`LO>7%g5XZ-MzLTa-(k8T})ahr^HjW)TX})OVtliYDn;3tze3ivXmei2gk+X>a z@hNctE^q)YT;PB>zyS$_kU+2k32}iUaR4rW1VTuthjIZ4q41wwZ#{WMaN$Ysy_w(4 zn>YJxzn$dqMC!E1;~}?sDNC*v1^lIhXcy)v1;|T%)JDy=-EM(jeO} zN|FKbUy>vX(y=HB@7{U8B)of9S&})B9UGF&g6w=$l4+3cr)4of$VuzlDj}|eqE9~LH52W$#IZd-jd`P$i8 zy&p@mA7uY$lJtWd_(GCCkb_@I(hG9v8%c&h4u2;}805&0l7v9|ev#xPNdHwyZUs5| znBWzb8>u0h;-4N-WFw@$PsyH2%vTZkG}(4+!f z1zVT2sGwB^Z7SHNf_4>bSAkyz9V+NlL6-`4s9>iGx>eAlf}2#ZO9i`Cutxr)6ly-Y3EP*(4h*M_%V_qw);(wCfSjN!G--Pdi7 zei&0N#*LSaMI=~Nq6C&rx%@6z2n5S4l zWBobIay{2tuFm#1piiN5<9P35cI~|1r_g15u5zTED;lnNz383r{}uBTIya8Tb%|Wx z%!gUWR>vNIF5?}C?)vlo5ygH=(a$OR1?XI=bMqss1zWdO`#e^J&ha0EF86p$W3)fT|>f1%jFRrH_OU+hMrfJ;LsXeNkDzs_2g>`qPU30(74p z-HHDObP70t_oJ0Uu@qduWt>gxDP3m)7nUuUE310NShD4ZjY_$yn3s#CC0=4YSTuuW ztXMP4t2(aorAlE1>V~mkmMeM~Vmy|M>4=w{o7Gc^*_qrKCo&vY%ge=*v4+Kk3SI_= zX*|g91b6WeWfHp ztr{&gr=9zUT-}8Daf+p)%rR2SA$+1Hv*^6qw&b~1^H?1^-LjQFR&(Hk%x4pse~s@xBJmR0hGJ7;Q#;t literal 0 HcmV?d00001 diff --git a/main.hex b/main.hex new file mode 100644 index 0000000..1b938cc --- /dev/null +++ b/main.hex @@ -0,0 +1,5 @@ +:1000000012C017C016C015C014C013C012C011C052 +:1000100010C00FC00EC00DC00CC00BC00AC009C07C +:1000200008C007C006C011241FBECFEDCDBF03D04E +:1000300005C0E6CF089580E090E00895F894FFCFE2 +:00000001FF diff --git a/thing.c b/thing.c new file mode 100644 index 0000000..c85a152 --- /dev/null +++ b/thing.c @@ -0,0 +1,3 @@ +int thingie() { + +} diff --git a/thing.mk b/thing.mk new file mode 100644 index 0000000..f84ccc3 --- /dev/null +++ b/thing.mk @@ -0,0 +1,189 @@ +###### +# Makefile based on STM32Cube auto-generated makefile +# +# TODO: +# - clean up, maybe optimize builds more +# - add windows support +# - add *proper* retargeting (this is mostly restructuring some files and adding make variables) +# +# Mediocre stuff about how I'm doing this: +# - First build times are loooooong. make -j4 will help, but we're still compiling lots we do't need. +# This is mostly because I don't want people to have to specifiy which source files they need. + +#################### +# Common directories +# +# These variables need to be defined in your makefile: +# TARGET - the name of your project +# COMMON_DIR - the common/ folder, where everything not for a specific project is held +# PROJ_DIR - Location of the current project +# MCU_SERIES - f0, f3, etc... the series for STM32 you are using +# MCU_PARTNO - Full partno you are using, in the HAL style, e.g. STM32F303xC +# +# SOURCE_DIRS - project specific sources, can be empty +# LDSCRIPT - The locaton of your linker script. +# +# +# CPU, see example makefile +# FPU, see example makefile +# FLOAT-ABI - see example makefile +# + +TARGET = testing + +PROJ_DIR := ./ +SOURCE_DIRS := + +SOURCE_DIRS += \ + $(PROJ_DIR)/src \ + + +# Find C sources: +C_SOURCES := $(shell find $(SOURCE_DIRS) -maxdepth 1 ! -name "*template.c" -name "*.c") +# DSDL compiled sources need to be treated differently +C_SOURCES += $(shell find $(CANARD_DSDL_COMPILED_DIR) -name "*.c") + +# Find C++ sources +CPP_SOURCES := $(shell find $(SOURCE_DIRS) -maxdepth 1 -name "*.cpp") + +ASM_SOURCES := + + +############## +# Build tools +############## +PREFIX = avr- +# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx) +# either it can be added to the PATH environment variable. +ifdef GCC_PATH +CC = $(GCC_PATH)/$(PREFIX)gcc$(POSTFIX) +CXX = $(GCC_PATH)/$(PREFIX)g++$(POSTFIX) +AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp$(POSTFIX) +CP = $(GCC_PATH)/$(PREFIX)objcopy$(POSTFIX) +SZ = $(GCC_PATH)/$(PREFIX)size$(POSTFIX) +else +CC = $(PREFIX)gcc$(POSTFIX) +CXX = $(PREFIX)g++$(POSTFIX) +AS = $(PREFIX)gcc -x assembler-with-cpp$(POSTFIX) +CP = $(PREFIX)objcopy$(POSTFIX) +SZ = $(PREFIX)size$(POSTFIX) +endif +HEX = $(CP) -O ihex +BIN = $(CP) -O binary -S + + +# mcu +MCU = atmega168 + + +# Definitions to be called when compiling +AS_DEFS := + +# Common to C and C++ +C_DEFS := \ + +# Includes for compiling +AS_INCLUDES := + +# Common to C and C++ +C_INCLUDES := \ + +# compile gcc flags +ASFLAGS = -mmcu=$(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections + +CFLAGS = -mmcu=$(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -std=gnu99 +CXXFLAGS = -mmcu=$(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections + +ifeq ($(DEBUG), 1) +CFLAGS += -g +CXXFLAGS += -g +endif + + +# Generate dependency information +# As far as I understand, this makes it so you can recompile correctly when header files change +CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" +CXXFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" + + +################# +# Building! +################# +BUILD_DIR := $(PROJ_DIR)/build + +# default action: build all +all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin + + +####################################### +# build the application +####################################### +# list of objects +OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o))) +vpath %.c $(sort $(dir $(C_SOURCES))) +# C++ objects +OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(CPP_SOURCES:.cpp=.o))) +vpath %.cpp $(sort $(dir $(CPP_SOURCES))) +# list of ASM program objects +OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o))) +vpath %.s $(sort $(dir $(ASM_SOURCES))) + +$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) + $(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@ + +$(BUILD_DIR)/%.o: %.cpp Makefile | $(BUILD_DIR) + $(CXX) -c $(CXXFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.cpp=.lst)) $< -o $@ + +$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR) + $(AS) -c $(CFLAGS) $< -o $@ + +$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile + $(CXX) $(OBJECTS) $(LDFLAGS) -o $@ + $(SZ) $@ + +$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR) + $(HEX) $< $@ + +$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR) + $(BIN) $< $@ + +$(BUILD_DIR): + mkdir $@ + + +.PHONY: clean flash debug help + +####################################### +# clean up +####################################### +clean: + -rm -fR $(BUILD_DIR) + + +#################### +# Flashing/Debugging +#################### + +flash: $(BUILD_DIR)/$(TARGET).elf + openocd -f $(COMMON_DIR)/$(MCU_SERIES)_openocd.cfg \ + -c "program $(BUILD_DIR)/$(TARGET).elf verify reset exit" \ + +debug: $(BUILD_DIR)/$(TARGET).elf + openocd -f $(COMMON_DIR)/$(MCU_SERIES)_openocd.cfg + +################ +# Printing Stuff +################ +help: + @echo "Targets:" + @echo " - ${TARGET}: build project" + @echo " - clean: clean up build folder" + @echo " - flash: flash project to microcontroller with OpenOCD" + @echo " - debug: launch an OpenOCD debug session" + @echo " - help: print this message" + + +####################################### +# dependencies +####################################### +-include $(wildcard $(BUILD_DIR)/*.d)