Updated folder structure

This commit is contained in:
David Lenfesty 2019-09-03 09:55:35 -06:00
parent fb4bb5e81b
commit ccdf3604bc
15 changed files with 411 additions and 199 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.hex
*.elf

79
final_project/Makefile Normal file
View File

@ -0,0 +1,79 @@
# Stolen from github
#
# Name: Makefile
# Author: <insert your name here>
# Copyright: <insert your copyright message here>
# License: <insert your license reference here>
# 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

16
final_project/main.c Normal file
View File

@ -0,0 +1,16 @@
#include <avr/io.h>
// Set up GPIO here
void pin_setup() {
}
int main() {
pin_setup()
while (1) {
}
}

79
lab_1/Makefile Normal file
View File

@ -0,0 +1,79 @@
# Stolen from github
#
# Name: Makefile
# Author: <insert your name here>
# Copyright: <insert your copyright message here>
# License: <insert your license reference here>
# 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

16
lab_1/main.c Normal file
View File

@ -0,0 +1,16 @@
#include <avr/io.h>
// Set up GPIO here
void pin_setup() {
}
int main() {
pin_setup()
while (1) {
}
}

16
lab_2/main.c Normal file
View File

@ -0,0 +1,16 @@
#include <avr/io.h>
// Set up GPIO here
void pin_setup() {
}
int main() {
pin_setup()
while (1) {
}
}

79
lab_3/Makefile Normal file
View File

@ -0,0 +1,79 @@
# Stolen from github
#
# Name: Makefile
# Author: <insert your name here>
# Copyright: <insert your copyright message here>
# License: <insert your license reference here>
# 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

16
lab_3/main.c Normal file
View File

@ -0,0 +1,16 @@
#include <avr/io.h>
// Set up GPIO here
void pin_setup() {
}
int main() {
pin_setup()
while (1) {
}
}

79
lab_4/Makefile Normal file
View File

@ -0,0 +1,79 @@
# Stolen from github
#
# Name: Makefile
# Author: <insert your name here>
# Copyright: <insert your copyright message here>
# License: <insert your license reference here>
# 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

16
lab_4/main.c Normal file
View File

@ -0,0 +1,16 @@
#include <avr/io.h>
// Set up GPIO here
void pin_setup() {
}
int main() {
pin_setup()
while (1) {
}
}

15
main.c
View File

@ -1,5 +1,16 @@
#include <avr/io.h> #include <avr/io.h>
int main() { // Set up GPIO here
// do nothing void pin_setup() {
}
int main() {
pin_setup()
while (1) {
}
} }

BIN
main.elf

Binary file not shown.

View File

@ -1,5 +0,0 @@
:1000000012C017C016C015C014C013C012C011C052
:1000100010C00FC00EC00DC00CC00BC00AC009C07C
:1000200008C007C006C011241FBECFEDCDBF03D04E
:1000300005C0E6CF089580E090E00895F894FFCFE2
:00000001FF

View File

@ -1,3 +0,0 @@
int thingie() {
}

189
thing.mk
View File

@ -1,189 +0,0 @@
######
# 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)