# Compiler options here.
ifeq ($(USE_OPT),)
- USE_OPT = -O0 -ggdb -fomit-frame-pointer -falign-functions=16 -std=gnu99 -DPROTOCOL_CHIBIOS
+ USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16 -std=gnu99 -DPROTOCOL_CHIBIOS
endif
# C specific options here (added to USE_OPT).
# Enable this if you want link time optimizations (LTO)
ifeq ($(USE_LTO),)
- USE_LTO = yes
+ USE_LTO = no
endif
# If enabled, this option allows to compile the application in THUMB mode.
#
# Imported source files and paths
-CHIBIOS = $(TMK_DIR)/tool/chibios/chibios
-# Startup files.
-include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/startup_$(shell echo $(MCU_SERIES) | tr '[:upper:]' '[:lower:]').mk
+CHIBIOS ?= $(TMK_DIR)/tool/chibios/ChibiOS
+CHIBIOS_CONTRIB ?= $(TMK_DIR)/tool/chibios/ChibiOS-Contrib
+# Startup files. Try a few different locations, for compability with old versions and
+# for things hardware in the contrib repository
+STARTUP_MK = $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/startup_$(MCU_STARTUP).mk
+ifeq ("$(wildcard $(STARTUP_MK))","")
+ STARTUP_MK = $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_$(MCU_STARTUP).mk
+ ifeq ("$(wildcard $(STARTUP_MK))","")
+ STARTUP_MK = $(CHIBIOS_CONTRIB)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_$(MCU_STARTUP).mk
+ endif
+endif
+include $(STARTUP_MK)
# HAL-OSAL files (optional).
include $(CHIBIOS)/os/hal/hal.mk
-include $(CHIBIOS)/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)/platform.mk
-ifneq ("$(wildcard $(TARGET_DIR)/boards/$(BOARD))","")
- include $(TARGET_DIR)/boards/$(BOARD)/board.mk
-else
- include $(CHIBIOS)/os/hal/boards/$(BOARD)/board.mk
+
+PLATFORM_MK = $(CHIBIOS)/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)/platform.mk
+ifeq ("$(wildcard $(PLATFORM_MK))","")
+PLATFORM_MK = $(CHIBIOS_CONTRIB)/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)/platform.mk
+endif
+include $(PLATFORM_MK)
+
+
+BOARD_MK = $(TARGET_DIR)/boards/$(BOARD)/board.mk
+ifeq ("$(wildcard $(BOARD_MK))","")
+ BOARD_MK = $(CHIBIOS)/os/hal/boards/$(BOARD)/board.mk
+ ifeq ("$(wildcard $(BOARD_MK))","")
+ BOARD_MK = $(CHIBIOS_CONTRIB)/os/hal/boards/$(BOARD)/board.mk
+ endif
endif
+include $(BOARD_MK)
include $(CHIBIOS)/os/hal/osal/rt/osal.mk
# RTOS files (optional).
include $(CHIBIOS)/os/rt/rt.mk
-include $(CHIBIOS)/os/rt/ports/ARMCMx/compilers/GCC/mk/port_v$(ARMV)m.mk
+# Compability with old version
+PORT_V = $(CHIBIOS)/os/rt/ports/ARMCMx/compilers/GCC/mk/port_v$(ARMV)m.mk
+ifeq ("$(wildcard $(PORT_V))","")
+PORT_V = $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v$(ARMV)m.mk
+endif
+include $(PORT_V)
# Other files (optional).
+include $(CHIBIOS)/os/hal/lib/streams/streams.mk
# Define linker script file here
-ifneq ("$(wildcard $(TARGET_DIR)/ld/$(MCU_MODEL_FAMILY).ld)","")
-LDSCRIPT = $(TARGET_DIR)/ld/$(MCU_MODEL_FAMILY).ld
+ifneq ("$(wildcard $(TARGET_DIR)/ld/$(MCU_LDSCRIPT).ld)","")
+LDSCRIPT = $(TARGET_DIR)/ld/$(MCU_LDSCRIPT).ld
else
-LDSCRIPT = $(STARTUPLD)/$(MCU_MODEL_FAMILY).ld
+LDSCRIPT = $(STARTUPLD)/$(MCU_LDSCRIPT).ld
endif
# C sources that can be compiled in ARM or THUMB mode depending on the global
$(HALSRC) \
$(PLATFORMSRC) \
$(BOARDSRC) \
- $(CHIBIOS)/os/hal/lib/streams/chprintf.c \
+ $(STREAMSSRC) \
$(TMK_DIR)/protocol/chibios/usb_main.c \
$(TMK_DIR)/protocol/chibios/main.c \
$(SRC)
TCPPSRC =
# List ASM source files here
-ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
+ASMSRC =
+ASMXSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
-INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
+INCDIR = $(CHIBIOS)/os/license \
+ $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
$(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
- $(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various \
+ $(STREAMSINC) $(CHIBIOS)/os/various \
$(TMK_DIR) $(COMMON_DIR) $(TMK_DIR)/protocol/chibios \
- $(TARGET_DIR)
+ $(TMK_DIR)/protocol $(TARGET_DIR)
#
# Project, sources and paths
# Compiler settings
#
-MCU = cortex-m0
-
#TRGT = arm-elf-
TRGT = arm-none-eabi-
CC = $(TRGT)gcc
AS = $(TRGT)gcc -x assembler-with-cpp
AR = $(TRGT)ar
OD = $(TRGT)objdump
-SZ = $(TRGT)size
+SZ = $(TRGT)size -A
HEX = $(CP) -O ihex
BIN = $(CP) -O binary
# List all user C define here, like -D_DEBUG=1
## Select which interfaces to include here!
-UDEFS = $(OPT_DEFS)
+UDEFS += $(OPT_DEFS)
# Define ASM defines here
-UADEFS = $(OPT_DEFS)
+UADEFS += $(OPT_DEFS)
+# bootloader definitions may be used in the startup .s file
+ifneq ("$(wildcard $(TARGET_DIR)/bootloader_defs.h)","")
+ UADEFS += -include $(TARGET_DIR)/bootloader_defs.h
+ UDEFS += -include $(TARGET_DIR)/bootloader_defs.h
+else ifneq ("$(wildcard $(TARGET_DIR)/boards/$(BOARD)/bootloader_defs.h)","")
+ UADEFS += -include $(TARGET_DIR)/boards/$(BOARD)/bootloader_defs.h
+ UDEFS += -include $(TARGET_DIR)/boards/$(BOARD)/bootloader_defs.h
+endif
# List all user directories here
-UINCDIR =
+#UINCDIR =
# List the user directory to look for the libraries here
-ULIBDIR =
+#ULIBDIR =
# List all user libraries here
-ULIBS =
+#ULIBS =
#
# End of user defines
##############################################################################
RULESPATH = $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC
+ifeq ("$(wildcard $(RULESPATH)/rules.mk)","")
+RULESPATH = $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC
+endif
include $(RULESPATH)/rules.mk