Skip to content
This repository has been archived by the owner on May 16, 2019. It is now read-only.

here you go mer #2

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions PROS/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
################################################################################
######################### User configurable parameters #########################
# filename extensions
CEXTS:=c
ASMEXTS:=s S
CXXEXTS:=cpp c++ cc

# probably shouldn't modify these, but you may need them below
ROOT=.
FWDIR:=$(ROOT)/firmware
BINDIR=$(ROOT)/bin
SRCDIR=$(ROOT)/src
INCDIR=$(ROOT)/include

WARNFLAGS+=
EXTRA_CFLAGS=
EXTRA_CXXFLAGS=

# Set this to 1 to add additional rules to compile your project as a PROS library template
IS_LIBRARY:=0
# TODO: CHANGE THIS!
LIBNAME:=libbest
VERSION:=1.0.0
# EXCLUDE_SRC_FROM_LIB= $(SRCDIR)/unpublishedfile.c
# this line excludes opcontrol.c and similar files
EXCLUDE_SRC_FROM_LIB+=$(foreach file, $(SRCDIR)/opcontrol $(SRCDIR)/initialize $(SRCDIR)/autonomous,$(foreach cext,$(CEXTS),$(file).$(cext)) $(foreach cxxext,$(CXXEXTS),$(file).$(cxxext)))

# files that get distributed to every user (beyond your source archive) - add
# whatever files you want here. This line is configured to add all header files
# that are in the the include directory get exported
TEMPLATE_FILES=$(INCDIR)/**/*.h $(INCDIR)/**/*.hpp

.DEFAULT_GOAL=quick

################################################################################
################################################################################
########## Nothing below this line should be edited by typical users ###########
-include ./common.mk

INCLUDE=-isystem$(INCDIR)

ASMSRC=$(foreach asmext,$(ASMEXTS),$(call rwildcard, $(SRCDIR),*.$(asmext), $1))
ASMOBJ=$(addprefix $(BINDIR)/,$(patsubst $(SRCDIR)/%,%.o,$(call ASMSRC,$1)))
CSRC=$(foreach cext,$(CEXTS),$(call rwildcard, $(SRCDIR),*.$(cext), $1))
COBJ=$(addprefix $(BINDIR)/,$(patsubst $(SRCDIR)/%,%.o,$(call CSRC, $1)))
CXXSRC=$(foreach cxxext,$(CXXEXTS),$(call rwildcard, $(SRCDIR),*.$(cxxext), $1))
CXXOBJ=$(addprefix $(BINDIR)/,$(patsubst $(SRCDIR)/%,%.o,$(call CXXSRC,$1)))

GETALLOBJ=$(sort $(call ASMOBJ,$1) $(call COBJ,$1) $(call CXXOBJ,$1))

LIBRARIES=-Wl,--start-group $(wildcard $(FWDIR)/*.a) -lm -lgcc -Wl,--end-group
ARCHIVE_TEXT_LIST:=$(subst $(SPACE),$(COMMA),$(notdir $(basename $(wildcard $(FWDIR)/*.a))))

ifndef OUTBIN
OUTNAME:=output
endif
OUTBIN:=$(BINDIR)/$(OUTNAME).bin
OUTELF:=$(BINDIR)/$(OUTNAME).elf

.PHONY: all clean quick

quick: $(OUTBIN)

all: clean $(OUTBIN)

clean:
@echo Cleaning project
-$Drm -rf $(BINDIR)

upload-legacy:
@java -jar firmware/uniflash.jar vex $(BINDIR)/$(OUTBIN)

upload:
pros flash -f $(BINDIR)/$(OUTBIN)


$(OUTBIN): $(OUTELF) $(BINDIR)
@echo -n "Creating $@ for $(DEVICE) "
$(call test_output,$D$(OBJCOPY) $< -O binary $@,$(DONE_STRING))

$(OUTELF): $(call GETALLOBJ,$(EXCLUDE_SRCDIRS))
@echo -n "Linking project with $(ARCHIVE_TEXT_LIST) "
$(call test_output,$D$(LD) $(LDFLAGS) $^ $(LIBRARIES) -o $@,$(OK_STRING))
@echo Section sizes:
-$(VV)$(SIZETOOL) $(SIZEFLAGS) $@ $(SIZES_SED) $(SIZES_NUMFMT)

define asm_rule
$(BINDIR)/%.$1.o: $(SRCDIR)/%.$1
$(VV)mkdir -p $$(dir $$@)
@echo -n "Compiling $$< "
$$(call test_output,$D$(AS) -c $(ASMFLAGS) -o $$@ $$<,$(OK_STRING))
endef
$(foreach asmext,$(ASMEXTS),$(eval $(call asm_rule,$(asmext))))

define c_rule
$(BINDIR)/%.$1.o: $(SRCDIR)/%.$1
$(VV)mkdir -p $$(dir $$@)
@echo -n "Compiling $$< "
$$(call test_output,$D$(CC) -c $(INCLUDE) -iquote$(INCDIR)/$$(dir $$*) $(CFLAGS) $(EXTRA_CFLAGS) -o $$@ $$<,$(OK_STRING))
endef
$(foreach cext,$(CEXTS),$(eval $(call c_rule,$(cext))))

define cxx_rule
$(BINDIR)/%.$1.o: $(SRCDIR)/%.$1
$(VV)mkdir -p $$(dir $$@)
@echo -n "Compiling $$< "
$$(call test_output,$D$(CXX) -c $(INCLUDE) -iquote$(INCDIR)/$$(dir $$*) $(CXXFLAGS) $(EXTRA_CXXFLAGS) -o $$@ $$<,$(OK_STRING))
endef
$(foreach cxxext,$(CXXEXTS),$(eval $(call cxx_rule,$(cxxext))))


ifeq ($(IS_LIBRARY),1)
ifeq ($(LIBNAME),libbest)
$(errror "You should rename your library! libbest is the default library name and should be changed")
endif

LIBAR=$(BINDIR)/$(LIBNAME).a
TEMPLATE_DIR=$(ROOT)/template

clean-template:
@echo Cleaning $(TEMPLATE_DIR)
-$Drm -rf $(TEMPLATE_DIR)

$(LIBAR): $(call GETALLOBJ,$(EXCLUDE_SRC_FROM_LIB))
@echo -n "Creating $@ "
$(call test_output,$D$(AR) rcs $@ $^, $(DONE_STRING))

.PHONY: library
library: $(LIBAR)

.PHONY: template
template: clean-template $(LIBAR)
$Dprosv5 c create-template . $(LIBNAME) $(VERSION) $(foreach file,$(TEMPLATE_FILES) $(LIBAR),--system "$(file)") --target v5
endif
109 changes: 109 additions & 0 deletions PROS/common.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
ARCHTUPLE=arm-none-eabi-
DEVICE=VexCortex

MFLAGS=-mthumb -mcpu=cortex-m3 -mlittle-endian
CPPFLAGS=-Os
GCCFLAGS=-ffunction-sections -fsigned-char -fomit-frame-pointer -fsingle-precision-constant -fdiagnostics-color

WARNFLAGS+=

SPACE :=
SPACE +=
COMMA := ,
LNK_FLAGS = --gc-sections

ASMFLAGS=$(MFLAGS) $(WARNFLAGS)
CFLAGS=$(MFLAGS) $(CPPFLAGS) $(WARNFLAGS) $(GCCFLAGS) -std=gnu99
CXXFLAGS=$(MFLAGS) $(CPPFLAGS) $(WARNFLAGS) -fno-exceptions -fno-rtti -felide-constructors $(GCCFLAGS) --std=gnu++11
LDFLAGS=$(MFLAGS) $(WARNFLAGS) -nostartfiles -Wl,-static -Bfirmware -Wl,-u,VectorTable -Wl,-T -Xlinker firmware/cortex.ld $(subst ?%,$(SPACE),$(addprefix -Wl$(COMMA), $(LNK_FLAGS)))
SIZEFLAGS=-d --common
NUMFMTFLAGS=--to=iec --format %.2f --suffix=B

AR:=$(ARCHTUPLE)ar
# using arm-none-eabi-as generates a listing by default. This produces a super verbose output.
# Using gcc accomplishes the same thing without the extra output
AS:=$(ARCHTUPLE)gcc
CC:=$(ARCHTUPLE)gcc
CXX:=$(ARCHTUPLE)g++
LD:=$(ARCHTUPLE)gcc
OBJCOPY:=$(ARCHTUPLE)objcopy
SIZETOOL:=$(ARCHTUPLE)size
READELF:=$(ARCHTUPLE)readelf
STRIP:=$(ARCHTUPLE)strip

ifneq (, $(shell command -v gnumfmt 2> /dev/null))
SIZES_NUMFMT:=| gnumfmt --field=-4 --header $(NUMFMTFLAGS)
else
ifneq (, $(shell command -v numfmt 2> /dev/null))
SIZES_NUMFMT:=| numfmt --field=-4 --header $(NUMFMTFLAGS)
else
SIZES_NUMFMT:=
endif
endif

ifneq (, $(shell command -v sed 2> /dev/null))
SIZES_SED:=| sed -e 's/ dec/total/'
else
SIZES_SED:=
endif

rwildcard=$(foreach d,$(filter-out $3,$(wildcard $1*)),$(call rwildcard,$d/,$2,$3)$(filter $(subst *,%,$2),$d))

# Colors
NO_COLOR=\x1b[0m
OK_COLOR=\x1b[32;01m
ERROR_COLOR=\x1b[31;01m
WARN_COLOR=\x1b[33;01m
STEP_COLOR=\x1b[37;01m
OK_STRING=$(OK_COLOR)[OK]$(NO_COLOR)
DONE_STRING=$(OK_COLOR)[DONE]$(NO_COLOR)
ERROR_STRING=$(ERROR_COLOR)[ERRORS]$(NO_COLOR)
WARN_STRING=$(WARN_COLOR)[WARNINGS]$(NO_COLOR)
ECHO=/bin/echo -e
echo=@$(ECHO) "$2$1$(NO_COLOR)"
echon=@$(ECHO) -n "$2$1$(NO_COLOR)"

define test_output
@rm -f temp.log temp.errors
$1 2> temp.log || touch temp.errors
@if test -e temp.errors; then $(ECHO) "$(ERROR_STRING)" && cat temp.log; elif test -s temp.log; then $(ECHO) "$(WARN_STRING)" && cat temp.log; else $(ECHO) "$2"; fi;
@if test -e temp.errors; then rm -f temp.log temp.errors && false; fi;
@rm -f temp.log temp.errors
endef

# Makefile Verbosity
ifeq ("$(origin VERBOSE)", "command line")
BUILD_VERBOSE = $(VERBOSE)
endif
ifeq ("$(origin V)", "command line")
BUILD_VERBOSE = $(V)
endif

ifndef BUILD_VERBOSE
BUILD_VERBOSE = 0
endif

# R is reduced (default messages) - build verbose = 0
# V is verbose messages - verbosity = 1
# VV is super verbose - verbosity = 2
ifeq ($(BUILD_VERBOSE), 0)
R = @echo
D = @
VV = @
endif
ifeq ($(BUILD_VERBOSE), 1)
R = @echo
D =
VV = @
endif
ifeq ($(BUILD_VERBOSE), 2)
R =
D =
VV =
endif

# these rules are for build-compile-commands, which just print out sysroot information
cc-sysroot:
@echo | $(CC) -c -x c $(CFLAGS) $(EXTRA_CFLAGS) --verbose -o /dev/null -
cxx-sysroot:
@echo | $(CXX) -c -x c++ $(CXXFLAGS) $(EXTRA_CXXFLAGS) --verbose -o /dev/null -
100 changes: 100 additions & 0 deletions PROS/firmware/STM32F10x.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/* Memory space definitions */
MEMORY {
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 384K
}

/* Higher address of the user mode stack */
EXTERN ( _estack );
PROVIDE ( _estack = ORIGIN(RAM) + LENGTH(RAM) );

/* This sends all unreferenced IRQHandlers to reset. */
PROVIDE ( ISR_SWI = 0 );
PROVIDE ( ISR_IRQ = 0 );
PROVIDE ( ISR_Prefetch = 0 );
PROVIDE ( ISR_Abort = 0 );
PROVIDE ( ISR_FIQ = 0 );

PROVIDE ( ISR_NMI = 0 );
PROVIDE ( ISR_HardFault = 0 );
PROVIDE ( ISR_MemManage = 0 );
PROVIDE ( ISR_BusFault = 0 );
PROVIDE ( ISR_UsageFault = 0 );

PROVIDE ( ISR_SVC = 0 );
PROVIDE ( ISR_DebugMon = 0 );
PROVIDE ( ISR_PendSV = 0 );
PROVIDE ( ISR_SysTick = 0 );

PROVIDE ( ISR_WWDG = 0 );
PROVIDE ( ISR_PVD = 0 );
PROVIDE ( ISR_TAMPER = 0 );
PROVIDE ( ISR_RTC = 0 );
PROVIDE ( ISR_FLASH = 0 );
PROVIDE ( ISR_RCC = 0 );
PROVIDE ( ISR_EXTI0 = 0 );
PROVIDE ( ISR_EXTI1 = 0 );
PROVIDE ( ISR_EXTI2 = 0 );
PROVIDE ( ISR_EXTI3 = 0 );
PROVIDE ( ISR_EXTI4 = 0 );
PROVIDE ( ISR_DMAChannel1 = 0 );
PROVIDE ( ISR_DMAChannel2 = 0 );
PROVIDE ( ISR_DMAChannel3 = 0 );
PROVIDE ( ISR_DMAChannel4 = 0 );
PROVIDE ( ISR_DMAChannel5 = 0 );
PROVIDE ( ISR_DMAChannel6 = 0 );
PROVIDE ( ISR_DMAChannel7 = 0 );
PROVIDE ( ISR_DMA1_Channel1 = 0 );
PROVIDE ( ISR_DMA1_Channel2 = 0 );
PROVIDE ( ISR_DMA1_Channel3 = 0 );
PROVIDE ( ISR_DMA1_Channel4 = 0 );
PROVIDE ( ISR_DMA1_Channel5 = 0 );
PROVIDE ( ISR_DMA1_Channel6 = 0 );
PROVIDE ( ISR_DMA1_Channel7 = 0 );
PROVIDE ( ISR_ADC = 0 );
PROVIDE ( ISR_ADC1_2 = 0 );
PROVIDE ( ISR_USB_HP_CAN_TX = 0 );
PROVIDE ( ISR_USB_HP_CAN1_TX = 0 );
PROVIDE ( ISR_USB_LP_CAN_RX0 = 0 );
PROVIDE ( ISR_USB_LP_CAN1_RX0 = 0 );
PROVIDE ( ISR_CAN_RX1 = 0 );
PROVIDE ( ISR_CAN1_RX1 = 0 );
PROVIDE ( ISR_CAN_SCE = 0 );
PROVIDE ( ISR_CAN1_SCE = 0 );
PROVIDE ( ISR_EXTI9_5 = 0 );
PROVIDE ( ISR_TIM1_BRK = 0 );
PROVIDE ( ISR_TIM1_UP = 0 );
PROVIDE ( ISR_TIM1_TRG_COM = 0 );
PROVIDE ( ISR_TIM1_CC = 0 );
PROVIDE ( ISR_TIM2 = 0 );
PROVIDE ( ISR_TIM3 = 0 );
PROVIDE ( ISR_TIM4 = 0 );
PROVIDE ( ISR_I2C1_EV = 0 );
PROVIDE ( ISR_I2C1_ER = 0 );
PROVIDE ( ISR_I2C2_EV = 0 );
PROVIDE ( ISR_I2C2_ER = 0 );
PROVIDE ( ISR_SPI1 = 0 );
PROVIDE ( ISR_SPI2 = 0 );
PROVIDE ( ISR_USART1 = 0 );
PROVIDE ( ISR_USART2 = 0 );
PROVIDE ( ISR_USART3 = 0 );
PROVIDE ( ISR_EXTI15_10 = 0 );
PROVIDE ( ISR_RTCAlarm = 0 );
PROVIDE ( ISR_USBWakeUp = 0 );
PROVIDE ( ISR_TIM8_BRK = 0 );
PROVIDE ( ISR_TIM8_UP = 0 );
PROVIDE ( ISR_TIM8_TRG_COM = 0 );
PROVIDE ( ISR_TIM8_CC = 0 );
PROVIDE ( ISR_ADC3 = 0 );
PROVIDE ( ISR_FSMC = 0 );
PROVIDE ( ISR_SDIO = 0 );
PROVIDE ( ISR_TIM5 = 0 );
PROVIDE ( ISR_SPI3 = 0 );
PROVIDE ( ISR_UART4 = 0 );
PROVIDE ( ISR_UART5 = 0 );
PROVIDE ( ISR_TIM6 = 0 );
PROVIDE ( ISR_TIM7 = 0 );
PROVIDE ( ISR_DMA2_Channel1 = 0 );
PROVIDE ( ISR_DMA2_Channel2 = 0 );
PROVIDE ( ISR_DMA2_Channel3 = 0 );
PROVIDE ( ISR_DMA2_Channel4_5 = 0 );
Loading