You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
165 lines
4.4 KiB
165 lines
4.4 KiB
3 years ago
|
# https://github.com/jkent/caterina-promicro
|
||
|
|
||
|
## === CPU settings ===
|
||
|
MCU = atmega32u4
|
||
|
F_CPU = 16000000
|
||
|
ARCH = AVR8
|
||
|
TARGET = Target
|
||
|
|
||
|
# Input clock frequency.
|
||
|
# This will define a symbol, F_USB, in all source code files equal to the
|
||
|
# input clock frequency (before any prescaling is performed) in Hz. This value may
|
||
|
# differ from F_CPU if prescaling is used on the latter, and is required as the
|
||
|
# raw input clock is fed directly to the PLL sections of the AVR for high speed
|
||
|
# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
|
||
|
# at the end, this will be done automatically to create a 32-bit value in your
|
||
|
# source code.
|
||
|
#
|
||
|
# If no clock division is performed on the input clock inside the AVR (via the
|
||
|
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
|
||
|
F_USB = $(F_CPU)
|
||
|
|
||
|
|
||
|
|
||
|
## === Source files ===
|
||
|
# Main C file
|
||
|
|
||
|
APP = app
|
||
|
SRC_DIR=src
|
||
|
INC_DIR=src
|
||
|
OBJ_DIR=obj
|
||
|
BIN_DIR=bin
|
||
|
|
||
|
|
||
|
|
||
|
# LUFA library compile-time options and predefined tokens
|
||
|
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_RAM_DESCRIPTORS
|
||
|
LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
|
||
|
LUFA_OPTS += -D NO_INTERNAL_SERIAL
|
||
|
LUFA_OPTS += -D NO_DEVICE_SELF_POWER
|
||
|
LUFA_OPTS += -D NO_DEVICE_REMOTE_WAKEUP
|
||
|
LUFA_OPTS += -D NO_SOF_EVENTS
|
||
|
LUFA_OPTS += -D F_USB=$(F_USB)UL
|
||
|
|
||
|
#LUFA_OPTS += -D NO_BLOCK_SUPPORT
|
||
|
#LUFA_OPTS += -D NO_EEPROM_BYTE_SUPPORT
|
||
|
#LUFA_OPTS += -D NO_FLASH_BYTE_SUPPORT
|
||
|
LUFA_OPTS += -D NO_LOCK_BYTE_WRITE_SUPPORT
|
||
|
|
||
|
LUFA_PATH = src/lufa-LUFA-210130/LUFA
|
||
|
|
||
|
include $(LUFA_PATH)/Build/lufa_core.mk
|
||
|
include $(LUFA_PATH)/Build/lufa_sources.mk
|
||
|
include $(LUFA_PATH)/Build/lufa_build.mk
|
||
|
#include $(LUFA_PATH)/Build/lufa_cppcheck.mk
|
||
|
#include $(LUFA_PATH)/Build/lufa_doxygen.mk
|
||
|
#include $(LUFA_PATH)/Build/lufa_dfu.mk
|
||
|
#include $(LUFA_PATH)/Build/lufa_hid.mk
|
||
|
#include $(LUFA_PATH)/Build/lufa_avrdude.mk
|
||
|
#include $(LUFA_PATH)/Build/lufa_atprogram.mk
|
||
|
|
||
|
## === Programmer ===
|
||
|
#PROGRAMMER_TYPE = arduino
|
||
|
PROGRAMMER_TYPE = avr109
|
||
|
PROGRAMMER_ARGS = -P /dev/ttyACM0
|
||
|
|
||
|
# USB vendor ID (VID)
|
||
|
# SparkFun
|
||
|
VID = 0xbeef
|
||
|
# USB product ID (PID)
|
||
|
PID = 0x0001
|
||
|
|
||
|
CDEFS = -DDEVICE_VID=$(VID)UL
|
||
|
CDEFS += -DDEVICE_PID=$(PID)UL
|
||
|
|
||
|
## === C flags ===
|
||
|
|
||
|
INCFLAGS += -I$(INC_DIR) -I$(LUFA_PATH)/
|
||
|
|
||
|
CFLAGS = -std=gnu99 -mmcu=$(MCU) -DF_CPU=$(F_CPU)UL $(CDEFS)
|
||
|
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
|
||
|
CFLAGS += -Wall -Wno-main -Wno-strict-prototypes -Wno-comment
|
||
|
CFLAGS += -g2 -Wextra -Wfatal-errors -Wno-unused-but-set-variable
|
||
|
CFLAGS += -ffunction-sections -fdata-sections -Os $(LUFA_OPTS)
|
||
|
|
||
|
LFLAGS = -Wl,--gc-sections -Wl,--relax
|
||
|
|
||
|
# CFLAGS += -lm ## Math
|
||
|
# CFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf
|
||
|
# CFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf
|
||
|
|
||
|
|
||
|
# ---------------------------------------------------------------------------
|
||
|
|
||
|
## Defined programs / locations
|
||
|
CC = avr-gcc
|
||
|
LD = avr-gcc
|
||
|
OBJCOPY = avr-objcopy
|
||
|
OBJDUMP = avr-objdump
|
||
|
AVRSIZE = avr-size
|
||
|
AVRDUDE = avrdude
|
||
|
|
||
|
#$(wildcard $(SRC_DIR)/*.c)
|
||
|
SOURCES=src/main.c src/Descriptors.c $(LUFA_SRC_ALL_FILES)
|
||
|
OBJECTS=$(SOURCES:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
|
||
|
DEPENDS=$(OBJ_DIR)/.depends
|
||
|
|
||
|
TARGET=$(BIN_DIR)/$(APP)
|
||
|
|
||
|
|
||
|
.PHONY: all clean eeprom size
|
||
|
|
||
|
|
||
|
all: $(TARGET).hex size
|
||
|
|
||
|
debug:
|
||
|
@echo "SOURCES $(SOURCES)"
|
||
|
@echo "OBJECTS $(OBJECTS)"
|
||
|
@echo "TARGET $(TARGET)"
|
||
|
|
||
|
eeprom: $(TARGET).eeprom
|
||
|
|
||
|
size: $(TARGET).elf
|
||
|
$(AVRSIZE) -C --mcu=$(MCU) $<
|
||
|
|
||
|
$(TARGET).elf: $(OBJECTS) | $(BIN_DIR)
|
||
|
$(LD) $(CFLAGS) $(LFLGAS) -o $@ $^
|
||
|
|
||
|
%.hex: %.elf
|
||
|
$(OBJCOPY) -R .eeprom -O ihex $< $@
|
||
|
|
||
|
%.eeprom: %.elf
|
||
|
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
|
||
|
|
||
|
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
|
||
|
$(CC) -c $(CFLAGS) $(INCFLAGS) -o $@ $<
|
||
|
|
||
|
$(DEPENDS): $(SOURCES) | $(OBJ_DIR)
|
||
|
$(CC) $(INCFLAGS) -MM $(SOURCES) | sed -e 's!^!$(OBJ_DIR)/!' >$@
|
||
|
|
||
|
$(BIN_DIR):
|
||
|
mkdir -p $@
|
||
|
$(OBJ_DIR):
|
||
|
mkdir -p $@
|
||
|
|
||
|
clean:
|
||
|
rm -rf $(BIN_DIR) $(OBJ_DIR)
|
||
|
|
||
|
## === avrdude ===
|
||
|
|
||
|
flash: $(TARGET).hex
|
||
|
stty -F /dev/ttyACM0 speed 1200
|
||
|
stty -F /dev/ttyACM0 speed 115200
|
||
|
$(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$<
|
||
|
|
||
|
flashe: $(TARGET).eeprom
|
||
|
$(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$<
|
||
|
|
||
|
shell:
|
||
|
$(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt
|