summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--defines.mk151
-rw-r--r--include.mk159
-rw-r--r--lufa.mk45
-rw-r--r--usb-serial/Makefile14
-rw-r--r--usb-serial/usb-serial.c2
5 files changed, 238 insertions, 133 deletions
diff --git a/defines.mk b/defines.mk
new file mode 100644
index 0000000..ca29d50
--- /dev/null
+++ b/defines.mk
@@ -0,0 +1,151 @@
+##
+## spreadspace avr utils
+##
+##
+## Copyright (C) 2012 Christian Pointner <equinox@spreadspace.org>
+##
+## This file is part of spreadspace avr utils.
+##
+## spreadspace avr utils is free software: you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## any later version.
+##
+## spreadspace avr utils is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with spreadspace avr utils. If not, see <http://www.gnu.org/licenses/>.
+##
+
+ifeq ($(BOARD_TYPE),teensy1)
+ MCU := at90usb162
+ ARCH = AVR8
+ F_CPU := 16000000
+ F_USB = $(F_CPU)
+ PROG := teensy
+endif
+ifeq ($(BOARD_TYPE),teensy2)
+ MCU := atmega32u4
+ ARCH = AVR8
+ F_CPU := 16000000
+ F_USB = $(F_CPU)
+ PROG := teensy
+endif
+ifeq ($(BOARD_TYPE),teensy1pp)
+ MCU := at90usb646
+ ARCH = AVR8
+ F_CPU := 16000000
+ F_USB = $(F_CPU)
+ PROG := teensy
+endif
+ifeq ($(BOARD_TYPE),teensy2pp)
+ MCU := at90usb1286
+ ARCH = AVR8
+ F_CPU := 16000000
+ F_USB = $(F_CPU)
+ PROG := teensy
+endif
+ifeq ($(BOARD_TYPE),hhd70dongle)
+ MCU := atmega32u4
+ ARCH = AVR8
+ F_CPU := 16000000
+ F_USB = $(F_CPU)
+ PROG := DFU
+endif
+ifeq ($(BOARD_TYPE),arduinoUno)
+ MCU := atmega328p
+ ARCH = AVR8
+ F_CPU := 16000000
+ PROG := avrdude
+ UPLOAD_RATE := 57600
+ PROG_TYPE := stk500v1
+ AVRDUDE_PORT := /dev/ttyUSB0
+ RESET_FUNC := ../tools/reset_arduino
+ RESET_PARAM = $(AVRDUDE_PORT)
+endif
+ifeq ($(BOARD_TYPE),arduino2009v2)
+ MCU := atmega328p
+ ARCH = AVR8
+ F_CPU := 16000000
+ PROG := avrdude
+ UPLOAD_RATE := 57600
+ PROG_TYPE := stk500v1
+ AVRDUDE_PORT := /dev/ttyUSB0
+ RESET_FUNC := ../tools/reset_arduino
+ RESET_PARAM = $(AVRDUDE_PORT)
+endif
+ifeq ($(BOARD_TYPE),arduino2009)
+ MCU := atmega168
+ ARCH = AVR8
+ F_CPU := 16000000
+ PROG := avrdude
+ UPLOAD_RATE := 19200
+ PROG_TYPE := stk500v1
+ AVRDUDE_PORT := /dev/ttyUSB0
+ RESET_FUNC := ../tools/reset_arduino
+ RESET_PARAM = $(AVRDUDE_PORT)
+endif
+ifeq ($(BOARD_TYPE),arduino10000)
+ MCU := atmega168
+ ARCH = AVR8
+ F_CPU := 16000000
+ PROG := avrdude
+ UPLOAD_RATE := 19200
+ PROG_TYPE := stk500v1
+ AVRDUDE_PORT := /dev/ttyUSB0
+ RESET_FUNC := ../tools/reset_arduino
+ RESET_PARAM = $(AVRDUDE_PORT)
+endif
+ifeq ($(BOARD_TYPE),arduinoNG)
+ MCU := atmega8
+ ARCH = AVR8
+ F_CPU := 16000000
+ PROG := avrdude
+ UPLOAD_RATE := 19200
+ PROG_TYPE := stk500v1
+ AVRDUDE_PORT := /dev/ttyUSB0
+ RESET_FUNC := ../tools/dummy_reset
+endif
+ifeq ($(BOARD_TYPE),AvrNetIo)
+ MCU := atmega32
+ ARCH = AVR8
+ F_CPU := 16000000
+ PROG := avrdude
+ UPLOAD_RATE := 19200
+ PROG_TYPE := stk500v2
+ AVRDUDE_PORT := /dev/ttyS0
+endif
+
+CC = avr-gcc
+OBJCOPY = avr-objcopy
+AR = avr-ar rcs
+
+LIB_DIR = ../lib
+
+DFU = dfu-programmer
+teensy = teensy_loader_cli
+avrdude = avrdude
+
+## Options common to compile, link and assembly rules
+COMMON = -mmcu=$(MCU)
+
+## Compile options common for all C compilation units.
+CFLAGS = $(COMMON)
+CFLAGS += -O2
+CFLAGS += -funsigned-char
+CFLAGS += -funsigned-bitfields
+CFLAGS += -ffunction-sections
+CFLAGS += -fpack-struct
+CFLAGS += -fshort-enums
+CFLAGS += -Wall
+CFLAGS += -Wstrict-prototypes
+CFLAGS += -I$(LIB_DIR)
+CFLAGS += -DF_CPU=$(F_CPU)UL
+CFLAGS += -D__BOARD_$(BOARD_TYPE)__
+
+## Linker flags
+LDFLAGS = $(COMMON)
+LDFLAGS +=
diff --git a/include.mk b/include.mk
index 3f03342..9b02076 100644
--- a/include.mk
+++ b/include.mk
@@ -20,148 +20,48 @@
## along with spreadspace avr utils. If not, see <http://www.gnu.org/licenses/>.
##
-ifeq ($(BOARD_TYPE),teensy1)
- MCU := at90usb162
- F_CPU := 16000000
- PROG := teensy
-endif
-ifeq ($(BOARD_TYPE),teensy2)
- MCU := atmega32u4
- F_CPU := 16000000
- PROG := teensy
-endif
-ifeq ($(BOARD_TYPE),teensy1pp)
- MCU := at90usb646
- F_CPU := 16000000
- PROG := teensy
-endif
-ifeq ($(BOARD_TYPE),teensy2pp)
- MCU := at90usb1286
- F_CPU := 16000000
- PROG := teensy
-endif
-ifeq ($(BOARD_TYPE),hhd70dongle)
- MCU := atmega32u4
- F_CPU := 16000000
- PROG := DFU
-endif
-ifeq ($(BOARD_TYPE),arduinoUno)
- MCU := atmega328p
- F_CPU := 16000000
- PROG := avrdude
- UPLOAD_RATE := 57600
- PROG_TYPE := stk500v1
- AVRDUDE_PORT := /dev/ttyUSB0
- RESET_FUNC := ../tools/reset_arduino
- RESET_PARAM = $(AVRDUDE_PORT)
-endif
-ifeq ($(BOARD_TYPE),arduino2009v2)
- MCU := atmega328p
- F_CPU := 16000000
- PROG := avrdude
- UPLOAD_RATE := 57600
- PROG_TYPE := stk500v1
- AVRDUDE_PORT := /dev/ttyUSB0
- RESET_FUNC := ../tools/reset_arduino
- RESET_PARAM = $(AVRDUDE_PORT)
-endif
-ifeq ($(BOARD_TYPE),arduino2009)
- MCU := atmega168
- F_CPU := 16000000
- PROG := avrdude
- UPLOAD_RATE := 19200
- PROG_TYPE := stk500v1
- AVRDUDE_PORT := /dev/ttyUSB0
- RESET_FUNC := ../tools/reset_arduino
- RESET_PARAM = $(AVRDUDE_PORT)
-endif
-ifeq ($(BOARD_TYPE),arduino10000)
- MCU := atmega168
- F_CPU := 16000000
- PROG := avrdude
- UPLOAD_RATE := 19200
- PROG_TYPE := stk500v1
- AVRDUDE_PORT := /dev/ttyUSB0
- RESET_FUNC := ../tools/reset_arduino
- RESET_PARAM = $(AVRDUDE_PORT)
-endif
-ifeq ($(BOARD_TYPE),arduinoNG)
- MCU := atmega8
- F_CPU := 16000000
- PROG := avrdude
- UPLOAD_RATE := 19200
- PROG_TYPE := stk500v1
- AVRDUDE_PORT := /dev/ttyUSB0
- RESET_FUNC := ../tools/dummy_reset
-endif
-ifeq ($(BOARD_TYPE),AvrNetIo)
- MCU := atmega32
- F_CPU := 16000000
- PROG := avrdude
- UPLOAD_RATE := 19200
- PROG_TYPE := stk500v2
- AVRDUDE_PORT := /dev/ttyS0
-endif
-
-CC = avr-gcc
-OBJCOPY = avr-objcopy
-LIB_DIR = ../lib
+include ../defines.mk
-DFU = dfu-programmer
-teensy = teensy_loader_cli
-avrdude = avrdude
-
-## external libs
-EXTERNAL_LIBS :=
-
-LUFA_STAMP = .lufa_stamp
-ifdef LUFA_DIR
-EXTERNAL_LIBS += prepare-lufa
-endif
-
-## Options common to compile, link and assembly rules
-COMMON = -mmcu=$(MCU)
-
-## Compile options common for all C compilation units.
-CFLAGS = $(COMMON)
-CFLAGS += -O2
-CFLAGS += -funsigned-char
-CFLAGS += -funsigned-bitfields
-CFLAGS += -ffunction-sections
-CFLAGS += -fpack-struct
-CFLAGS += -fshort-enums
-CFLAGS += -Wall
-CFLAGS += -Wstrict-prototypes
-CFLAGS += -I$(LIB_DIR)
-CFLAGS += -DF_CPU=$(F_CPU)UL
-CFLAGS += -D__BOARD_$(BOARD_TYPE)__
-
-## Linker flags
-LDFLAGS = $(COMMON)
-LDFLAGS +=
+LDFLAGS += -L./
+## project-specific objects
SRC := $(OBJ:%.o=%.c)
-
+DEP := $(SRC:%.c=%.d)
OBJ_LIB := $(LIBS:%=lib-%.o)
SRC_LIB := $(LIBS:%=$(LIB_DIR)/%.c)
DEP_LIB := $(LIBS:%=lib-%.d)
-.PHONY: prepare clean program erase flash reset run
+.PHONY: prepare clean clean-external clean-lufa program erase flash reset run
ELFFILE := $(NAME).elf
HEXFILE := $(NAME).hex
all: prepare $(HEXFILE)
-prepare: $(EXTERNAL_LIBS)
-prepare-lufa: $(LUFA_STAMP)
-$(LUFA_STAMP):
- @echo "preparing external LUFA lib ($(LUFA_DIR))"
- @echo " --- TODO ---"
-## call LUFA build
- @touch $@
+
+## external Libs
+ifndef LUFA_PATH
+LUFA_PATH := ../contrib/LUFA
+endif
+
+prepare: $(EXTERNAL_LIBS:%=build-%)
+clean-external: $(EXTERNAL_LIBS:%=clean-%)
+
+export
+build-lufa: liblufa.a
+
+liblufa.a:
+ @echo "building external LUFA lib ($(LUFA_PATH))"
+ make -f ../lufa.mk liblufa.a
+ make -f ../lufa.mk clean
+
+clean-lufa:
+ @echo "cleaning external LUFA lib ($(LUFA_PATH))"
+ make -f ../lufa.mk clean
+ @rm -f liblufa.a
+## project-specific objects
lib-%.d: $(LIB_DIR)/%.c
@set -e; rm -f $@; \
$(CC) -MM $(CFLAGS) $< > $@.$$$$; \
@@ -175,7 +75,7 @@ lib-%.d: $(LIB_DIR)/%.c
rm -f $@.$$$$; echo '(re)building $@'
ifneq ($(MAKECMDGOALS),clean)
--include $(SRC:%.c=%.d)
+-include $(DEP)
-include $(DEP_LIB)
endif
@@ -186,13 +86,12 @@ lib-%.o: $(LIB_DIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@
$(ELFFILE): $(OBJ) $(OBJ_LIB)
- $(CC) $(LDFLAGS) $(OBJ) $(OBJ_LIB) -o $@
+ $(CC) $(LDFLAGS) $(OBJ) $(OBJ_LIB) $(EXTERNAL_LIBS:%=-l%) -o $@
$(HEXFILE): $(ELFFILE)
$(OBJCOPY) -O ihex -R .eeprom -R .fuse -R .lock -R .signature $< $@
clean:
- rm -f .*_stamp
rm -f *.o
rm -f *.d
rm -f *.d.*
diff --git a/lufa.mk b/lufa.mk
new file mode 100644
index 0000000..709f9be
--- /dev/null
+++ b/lufa.mk
@@ -0,0 +1,45 @@
+##
+## spreadspace avr utils
+##
+##
+## Copyright (C) 2012 Christian Pointner <equinox@spreadspace.org>
+##
+## This file is part of spreadspace avr utils.
+##
+## spreadspace avr utils is free software: you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## any later version.
+##
+## spreadspace avr utils is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with spreadspace avr utils. If not, see <http://www.gnu.org/licenses/>.
+##
+
+include ../defines.mk
+
+## TODO: change BOARD names for our tools too???
+LUFA_BOARD = TEENSY2
+
+include $(LUFA_PATH)/LUFA/makefile
+SRC = $(LUFA_SRC_USB) $(LUFA_SRC_USBCLASS)
+
+CFLAGS += -std=c99
+CFLAGS += -DF_USB=$(F_USB)UL
+CFLAGS += -DBOARD=BOARD_$(LUFA_BOARD) -DARCH=ARCH_$(ARCH)
+CFLAGS += $(LUFA_OPTS)
+
+OBJ = $(SRC:%.c=%.o)
+
+liblufa.a: $(OBJ)
+ $(AR) $@ $(OBJ)
+
+%.o: %.c
+ $(CC) -c $(CFLAGS) $< -o $@
+
+clean:
+ rm -f $(SRC:%.c=%.o)
diff --git a/usb-serial/Makefile b/usb-serial/Makefile
index b1f7687..868b51d 100644
--- a/usb-serial/Makefile
+++ b/usb-serial/Makefile
@@ -21,9 +21,19 @@
##
NAME := usb-serial
+BOARD_TYPE := teensy2
OBJ := $(NAME).o
LIBS := util led
-BOARD_TYPE := teensy2
-LUFA_DIR := ../contrib/LUFA-120219
+EXTERNAL_LIBS := lufa
+
+LUFA_PATH := ../contrib/LUFA-120219
+LUFA_OPTS = -D USB_DEVICE_ONLY
+LUFA_OPTS += -D DEVICE_STATE_AS_GPIOR=0
+LUFA_OPTS += -D ORDERED_EP_CONFIG
+LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8
+LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1
+LUFA_OPTS += -D USE_FLASH_DESCRIPTORS
+LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
+LUFA_OPTS += -D INTERRUPT_CONTROL_ENDPOINT
include ../include.mk
diff --git a/usb-serial/usb-serial.c b/usb-serial/usb-serial.c
index 851fd35..e5a67e0 100644
--- a/usb-serial/usb-serial.c
+++ b/usb-serial/usb-serial.c
@@ -32,7 +32,7 @@ int main(void)
led_init();
for(;;) {
- _delay_ms(250);
+ _delay_ms(42);
led_toggle();
}
}