Skip to content

Commit 5e6a84c

Browse files
author
MikHw
committed
Merge pull request #6 from aethaniel/bootloader_update
Bootloader update
2 parents ee5bb6f + 606906e commit 5e6a84c

26 files changed

+543
-5844
lines changed
Lines changed: 167 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,175 @@
1-
IDE_PATH="../../../../.."
2-
ARM_GCC_PATH=$(IDE_PATH)/hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/bin
3-
CC=$(ARM_GCC_PATH)/arm-none-eabi-gcc
4-
CFLAGS=-mthumb -mcpu=cortex-m0plus -Wall -c -g -Os -w -std=gnu99 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500
5-
LDFLAGS=-mthumb -mcpu=cortex-m0plus -Wall -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols
6-
BLD_EXTA_FLAGS=-D__SAMD21G18A__
1+
# Copyright (c) 2015 Thibaut VIARD. All right reserved.
2+
#
3+
# This library is free software; you can redistribute it and/or
4+
# modify it under the terms of the GNU Lesser General Public
5+
# License as published by the Free Software Foundation; either
6+
# version 2.1 of the License, or (at your option) any later version.
7+
#
8+
# This library is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11+
# See the GNU Lesser General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU Lesser General Public
14+
# License along with this library; if not, write to the Free Software
15+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16+
17+
# -----------------------------------------------------------------------------
18+
# Paths
19+
ifeq ($(OS),Windows_NT)
20+
21+
# Are we using mingw/msys/msys2/cygwin?
22+
ifeq ($(TERM),xterm)
23+
# T=$(shell cygpath -u $(LOCALAPPDATA))
24+
T=$(shell cygpath -u $(APPDATA))
25+
MODULE_PATH?=$(T)/Arduino15/packages/arduino
26+
ARM_GCC_PATH?=$(MODULE_PATH)/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-
27+
RM=rm
28+
SEP=/
29+
else
30+
# MODULE_PATH?=$(LOCALAPPDATA)/Arduino15/packages/arduino
31+
MODULE_PATH?=$(APPDATA)/Arduino15/packages/arduino
32+
ARM_GCC_PATH?=$(MODULE_PATH)/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-
33+
RM=rm
34+
SEP=\\
35+
endif
36+
else
37+
UNAME_S := $(shell uname -s)
38+
39+
ifeq ($(UNAME_S),Linux)
40+
MODULE_PATH?=$HOME/.arduino15/packages/arduino
41+
ARM_GCC_PATH?=$(MODULE_PATH)/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-
42+
RM=rm
43+
SEP=/
44+
endif
45+
46+
ifeq ($(UNAME_S),Darwin)
47+
MODULE_PATH?=$HOME/Library/Arduino15/packages/arduino/
48+
ARM_GCC_PATH?=$(MODULE_PATH)/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-
49+
RM=rm
50+
SEP=/
51+
endif
52+
endif
53+
754
BUILD_PATH=build
8-
INCLUDES=-I$(IDE_PATH)/hardware/tools/CMSIS/CMSIS/Include/ -I$(IDE_PATH)/hardware/tools/CMSIS/Device/ATMEL/ -I./drivers/ -I./utils/ -I./utils/preprocessor/ -I./utils/interrupt
9-
SOURCES=main.c sam_ba_monitor.c startup_samd21.c usart_sam_ba.c drivers/cdc_enumerate.c drivers/uart_driver.c utils/interrupt/interrupt_sam_nvic.c
55+
56+
# -----------------------------------------------------------------------------
57+
# Tools
58+
CC=$(ARM_GCC_PATH)gcc
59+
OBJCOPY=$(ARM_GCC_PATH)objcopy
60+
NM=$(ARM_GCC_PATH)nm
61+
SIZE=$(ARM_GCC_PATH)size
62+
63+
# -----------------------------------------------------------------------------
64+
# Compiler options
65+
#-w
66+
CFLAGS=-mthumb -mcpu=cortex-m0plus -Wall -c -std=gnu99 -ffunction-sections -fdata-sections -nostdlib -nostartfiles --param max-inline-insns-single=500
67+
ifdef DEBUG
68+
CFLAGS+=-g3 -O1 -DDEBUG=1
69+
else
70+
CFLAGS+=-Os -DDEBUG=0
71+
endif
72+
CFLAGS_EXTRA?=-D__SAMD21J18A__ -DUSB_PID_LOW=0x01 -DUSB_PID_HIGH=0xE0
73+
INCLUDES=-I"$(MODULE_PATH)/tools/CMSIS/4.0.0-atmel/CMSIS/Include/" -I"$(MODULE_PATH)/tools/CMSIS/4.0.0-atmel/Device/ATMEL/"
74+
75+
# -----------------------------------------------------------------------------
76+
# Linker options
77+
LDFLAGS=-mthumb -mcpu=cortex-m0plus -Wall -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all
78+
LDFLAGS+=-Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols --specs=nano.specs --specs=nosys.specs
79+
80+
# -----------------------------------------------------------------------------
81+
# Source files and objects
82+
# this path has to be updated if Arduino delivers any samd-core update!
83+
PROJECT_PATH=$(MODULE_PATH)/hardware/samd/1.6.1/bootloaders/zero
84+
SOURCES= \
85+
board_driver_led.c \
86+
board_driver_serial.c \
87+
board_driver_usb.c \
88+
board_init.c \
89+
board_startup.c \
90+
main.c \
91+
sam_ba_usb.c \
92+
sam_ba_cdc.c \
93+
sam_ba_monitor.c \
94+
sam_ba_serial.c
95+
96+
VPATH=$(PROJECT_PATH)
1097
OBJECTS=$(addprefix $(BUILD_PATH)/, $(SOURCES:.c=.o))
98+
#DEPS=$(addprefix $(BUILD_PATH)/, $(SOURCES:.c=.d))
1199

12100
NAME=samd21_sam_ba
13-
EXECUTABLE=$(NAME).bin
101+
ELF=$(NAME).elf
102+
BIN=$(NAME).bin
103+
HEX=$(NAME).hex
14104

15-
SLASH=/
16-
BSLASH=$(EMPTY)\$(EMPTY)
105+
ifneq "test$(AVRSTUDIO_EXE_PATH)" "test"
106+
AS_BUILD=copy_for_atmel_studio
107+
AS_CLEAN=clean_for_atmel_studio
108+
else
109+
AS_BUILD=
110+
AS_CLEAN=
111+
endif
17112

18-
all: $(SOURCES) $(EXECUTABLE)
19-
20-
$(EXECUTABLE): $(OBJECTS)
21-
$(CC) -L$(BUILD_PATH) $(LDFLAGS) -Os -Wl,--gc-sections -save-temps -Tsamd21j18a_flash.ld -Wl,-Map,$(BUILD_PATH)/$(NAME).map --specs=nano.specs --specs=nosys.specs -o $(BUILD_PATH)/$(NAME).elf $(OBJECTS) -Wl,--start-group -lm -Wl,--end-group
22-
$(ARM_GCC_PATH)/arm-none-eabi-objcopy -O binary $(BUILD_PATH)/$(NAME).elf $@
113+
all: print_info $(SOURCES) $(BIN) $(HEX) $(AS_BUILD)
114+
115+
$(ELF): Makefile $(BUILD_PATH) $(OBJECTS)
116+
@echo ----------------------------------------------------------
117+
@echo Creating ELF binary
118+
"$(CC)" -L"$(PROJECT_PATH)" $(LDFLAGS) -Os -Wl,--gc-sections -save-temps -Tbootloader_samd21x18.ld -Wl,-Map,"$(BUILD_PATH)/$(NAME).map" -o "$(BUILD_PATH)/$(ELF)" -Wl,--start-group $(OBJECTS) -lm -Wl,--end-group
119+
"$(NM)" "$(BUILD_PATH)/$(ELF)" >"$(BUILD_PATH)/$(NAME)_symbols.txt"
120+
"$(SIZE)" --format=sysv -t -x $(BUILD_PATH)/$(ELF)
121+
122+
$(BIN): $(ELF)
123+
@echo ----------------------------------------------------------
124+
@echo Creating flash binary
125+
"$(OBJCOPY)" -O binary $(BUILD_PATH)/$< $@
126+
127+
$(HEX): $(ELF)
128+
@echo ----------------------------------------------------------
129+
@echo Creating flash binary
130+
"$(OBJCOPY)" -O ihex $(BUILD_PATH)/$< $@
23131

24132
$(BUILD_PATH)/%.o: %.c
25-
-@mkdir -p $(@D)
26-
$(CC) $(CFLAGS) $(BLD_EXTA_FLAGS) $(INCLUDES) $< -o $@
27-
28-
clean:
29-
del $(EXECUTABLE) $(subst /,\,$(OBJECTS)) $(subst /,\,$(BUILD_PATH)/$(NAME).*)
133+
@echo ----------------------------------------------------------
134+
@echo Compiling $< to $@
135+
"$(CC)" $(CFLAGS) $(CFLAGS_EXTRA) $(INCLUDES) "$<" -o $@
136+
@echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
137+
138+
$(BUILD_PATH):
139+
@echo ----------------------------------------------------------
140+
@echo Creating build folder
141+
-mkdir $(BUILD_PATH)
142+
143+
print_info:
144+
@echo ----------------------------------------------------------
145+
@echo Compiling bootloader using
146+
@echo BASE PATH = $(MODULE_PATH)
147+
@echo GCC PATH = $(ARM_GCC_PATH)
148+
@echo PROJ PATH = $(PROJECT_PATH)
149+
# @echo SRC = $(SOURCES)
150+
# @echo OBJ = $(OBJECTS)
151+
# @echo OS = $(OS)
152+
# @echo SHELL = $(SHELL)
153+
# @echo TERM = $(TERM)
154+
# "$(CC)" -v
155+
# env
156+
157+
copy_for_atmel_studio: $(BIN) $(HEX)
158+
@echo ----------------------------------------------------------
159+
@echo Atmel Studio detected, copying ELF to project root for debug
160+
cp $(BUILD_PATH)/$(ELF) .
161+
162+
clean_for_atmel_studio:
163+
@echo ----------------------------------------------------------
164+
@echo Atmel Studio detected, cleaning ELF from project root
165+
-$(RM) ./$(ELF)
166+
167+
clean: $(AS_CLEAN)
168+
@echo ----------------------------------------------------------
169+
@echo Cleaning project
170+
-$(RM) $(BIN)
171+
-$(RM) $(HEX)
172+
-$(RM) $(BUILD_PATH)/*.*
173+
-rmdir $(BUILD_PATH)
174+
175+
.phony: print_info $(BUILD_PATH)

0 commit comments

Comments
 (0)