Skip to content

Commit fa031c1

Browse files
author
Jim Lindblom
committed
Updating bootloader to latest Arduino Zero bootloader.
1 parent 694a886 commit fa031c1

32 files changed

+5011
-700
lines changed
Lines changed: 163 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,170 @@
1-
# SAMD21 BA Bootloader - SparkFun Edit
2-
# Relies on toolchain installed via Arduino SAMD Board Support
3-
# Point the IDE path to your Arduino package installer location
4-
# Windows e.g.: C:/Users/user.name/AppData/Local/Arduino15
5-
# Mac e.g: /Users/userName/Library/Arduino15
6-
7-
IDE_PATH=C:/Users/user.name/AppData/Local/Arduino15
8-
ARM_GCC_PATH=$(IDE_PATH)/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin
9-
CC=$(ARM_GCC_PATH)/arm-none-eabi-gcc
10-
CFLAGS=-mthumb -mcpu=cortex-m0plus -Wall -c -g -Os -w -std=gnu99 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500
11-
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
12-
BLD_EXTA_FLAGS=-D__SAMD21G18A__
1+
# Copyright (c) 2015 Atmel Corporation/Thibaut VIARD. All right reserved.
2+
# Copyright (c) 2015 Arduino LLC. All right reserved.
3+
#
4+
# This library is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU Lesser General Public
6+
# License as published by the Free Software Foundation; either
7+
# version 2.1 of the License, or (at your option) any later version.
8+
#
9+
# This library is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
# See the GNU Lesser General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU Lesser General Public
15+
# License along with this library; if not, write to the Free Software
16+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
18+
# -----------------------------------------------------------------------------
19+
# Paths
20+
ifeq ($(OS),Windows_NT)
21+
# Are we using mingw/msys/msys2/cygwin?
22+
ifeq ($(TERM),xterm)
23+
T=$(shell cygpath -u $(LOCALAPPDATA))
24+
MODULE_PATH?=$(T)/Arduino15/packages/arduino
25+
RM=rm
26+
SEP=/
27+
else
28+
MODULE_PATH?=$(LOCALAPPDATA)/Arduino15/packages/arduino
29+
RM=rm
30+
SEP=\\
31+
endif
32+
else
33+
UNAME_S := $(shell uname -s)
34+
35+
ifeq ($(UNAME_S),Linux)
36+
MODULE_PATH?=$(HOME)/.arduino15/packages/arduino
37+
RM=rm
38+
SEP=/
39+
endif
40+
41+
ifeq ($(UNAME_S),Darwin)
42+
MODULE_PATH?=$(HOME)/Library/Arduino15/packages/arduino/
43+
RM=rm
44+
SEP=/
45+
endif
46+
endif
47+
48+
ARM_GCC_PATH?=$(MODULE_PATH)/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-
1349
BUILD_PATH=build
14-
INCLUDES=-I$(IDE_PATH)/packages/arduino/tools/CMSIS/4.0.0-atmel/CMSIS/Include/ -I$(IDE_PATH)/packages/arduino/tools/CMSIS/4.0.0-atmel/Device/ATMEL/ -I./drivers/ -I./utils/ -I./utils/preprocessor/ -I./utils/interrupt
15-
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
50+
51+
# -----------------------------------------------------------------------------
52+
# Tools
53+
CC=$(ARM_GCC_PATH)gcc
54+
OBJCOPY=$(ARM_GCC_PATH)objcopy
55+
NM=$(ARM_GCC_PATH)nm
56+
SIZE=$(ARM_GCC_PATH)size
57+
58+
# -----------------------------------------------------------------------------
59+
# Boards definitions
60+
BOARD_ID?=sparkfun_9dof
61+
NAME?=SparkFun_9DoF_Razor_M0
62+
#SparkFun_9DoF_Razor
63+
64+
# -----------------------------------------------------------------------------
65+
# Compiler options
66+
CFLAGS_EXTRA=-D__SAMD21G18A__ -DBOARD_ID_$(BOARD_ID)
67+
CFLAGS=-mthumb -mcpu=cortex-m0plus -Wall -c -std=gnu99 -ffunction-sections -fdata-sections -nostdlib -nostartfiles --param max-inline-insns-single=500
68+
ifdef DEBUG
69+
CFLAGS+=-g3 -O1 -DDEBUG=1
70+
else
71+
CFLAGS+=-Os -DDEBUG=0
72+
endif
73+
74+
ELF=$(NAME).elf
75+
BIN=$(NAME).bin
76+
HEX=$(NAME).hex
77+
78+
INCLUDES=-I"$(MODULE_PATH)/tools/CMSIS/4.0.0-atmel/CMSIS/Include/" -I"$(MODULE_PATH)/tools/CMSIS/4.0.0-atmel/Device/ATMEL/"
79+
80+
# -----------------------------------------------------------------------------
81+
# Linker options
82+
LDFLAGS=-mthumb -mcpu=cortex-m0plus -Wall -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all
83+
LDFLAGS+=-Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols --specs=nano.specs --specs=nosys.specs
84+
85+
# -----------------------------------------------------------------------------
86+
# Source files and objects
87+
SOURCES= \
88+
board_driver_led.c \
89+
board_driver_serial.c \
90+
board_driver_usb.c \
91+
board_init.c \
92+
board_startup.c \
93+
main.c \
94+
sam_ba_usb.c \
95+
sam_ba_cdc.c \
96+
sam_ba_monitor.c \
97+
sam_ba_serial.c
98+
1699
OBJECTS=$(addprefix $(BUILD_PATH)/, $(SOURCES:.c=.o))
100+
DEPS=$(addprefix $(BUILD_PATH)/, $(SOURCES:.c=.d))
101+
102+
ifneq "test$(AVRSTUDIO_EXE_PATH)" "test"
103+
AS_BUILD=copy_for_atmel_studio
104+
AS_CLEAN=clean_for_atmel_studio
105+
else
106+
AS_BUILD=
107+
AS_CLEAN=
108+
endif
109+
17110

18-
NAME=samd21_sam_ba_sparkfun
19-
EXECUTABLE=$(NAME).bin
111+
all: print_info $(SOURCES) $(BIN) $(HEX) $(AS_BUILD)
20112

21-
SLASH=/
22-
BSLASH=$(EMPTY)\$(EMPTY)
113+
$(ELF): Makefile $(BUILD_PATH) $(OBJECTS)
114+
@echo ----------------------------------------------------------
115+
@echo Creating ELF binary
116+
"$(CC)" -L. -L$(BUILD_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
117+
"$(NM)" "$(BUILD_PATH)/$(ELF)" >"$(BUILD_PATH)/$(NAME)_symbols.txt"
118+
"$(SIZE)" --format=sysv -t -x $(BUILD_PATH)/$(ELF)
23119

24-
all: $(SOURCES) $(EXECUTABLE)
25-
26-
$(EXECUTABLE): $(OBJECTS)
27-
$(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
28-
$(ARM_GCC_PATH)/arm-none-eabi-objcopy -O binary $(BUILD_PATH)/$(NAME).elf $@
120+
$(BIN): $(ELF)
121+
@echo ----------------------------------------------------------
122+
@echo Creating flash binary
123+
"$(OBJCOPY)" -O binary $(BUILD_PATH)/$< $@
124+
125+
$(HEX): $(ELF)
126+
@echo ----------------------------------------------------------
127+
@echo Creating flash binary
128+
"$(OBJCOPY)" -O ihex $(BUILD_PATH)/$< $@
29129

30130
$(BUILD_PATH)/%.o: %.c
31-
-@mkdir -p $(@D)
32-
$(CC) $(CFLAGS) $(BLD_EXTA_FLAGS) $(INCLUDES) $< -o $@
33-
34-
clean:
35-
del $(EXECUTABLE) $(subst /,\,$(OBJECTS)) $(subst /,\,$(BUILD_PATH)\//$(NAME).*)
131+
@echo ----------------------------------------------------------
132+
@echo Compiling $< to $@
133+
"$(CC)" $(CFLAGS) $(CFLAGS_EXTRA) $(INCLUDES) $< -o $@
134+
@echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
135+
136+
$(BUILD_PATH):
137+
@echo ----------------------------------------------------------
138+
@echo Creating build folder
139+
-mkdir $(BUILD_PATH)
140+
141+
print_info:
142+
@echo ----------------------------------------------------------
143+
@echo Compiling bootloader using
144+
@echo BASE PATH = $(MODULE_PATH)
145+
@echo GCC PATH = $(ARM_GCC_PATH)
146+
# @echo OS = $(OS)
147+
# @echo SHELL = $(SHELL)
148+
# @echo TERM = $(TERM)
149+
# "$(CC)" -v
150+
# env
151+
152+
copy_for_atmel_studio: $(BIN) $(HEX)
153+
@echo ----------------------------------------------------------
154+
@echo Atmel Studio detected, copying ELF to project root for debug
155+
cp $(BUILD_PATH)/$(ELF) .
156+
157+
clean_for_atmel_studio:
158+
@echo ----------------------------------------------------------
159+
@echo Atmel Studio detected, cleaning ELF from project root
160+
-$(RM) ./$(ELF)
161+
162+
clean: $(AS_CLEAN)
163+
@echo ----------------------------------------------------------
164+
@echo Cleaning project
165+
-$(RM) $(BIN)
166+
-$(RM) $(HEX)
167+
-$(RM) $(BUILD_PATH)/*.*
168+
-rmdir $(BUILD_PATH)
169+
170+
.phony: print_info $(BUILD_PATH)
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Arduino Zero Bootloader
2+
3+
## 1- Prerequisites
4+
5+
The project build is based on Makefile system.
6+
Makefile is present at project root and try to handle multi-platform cases.
7+
8+
Multi-plaform GCC is provided by ARM here: https://launchpad.net/gcc-arm-embedded/+download
9+
10+
Atmel Studio contains both make and ARM GCC toolchain. You don't need to install them in this specific use case.
11+
12+
For all builds and platforms you will need to have the Arduino IDE installed and the board support
13+
package for "Arduino SAMD Boards (32-bits ARM Cortex-M0+)". You can install the latter
14+
from the former's "Boards Manager" UI.
15+
16+
### Windows
17+
18+
* Native command line
19+
Make binary can be obtained here: http://gnuwin32.sourceforge.net/packages/make.htm
20+
21+
* Cygwin/MSys/MSys2/Babun/etc...
22+
It is available natively in all distributions.
23+
24+
* Atmel Studio
25+
An Atmel Studio **7** Makefile-based project is present at project root, just open samd21_sam_ba.atsln file in AS7.
26+
27+
### Linux
28+
29+
Make is usually available by default.
30+
31+
### OS X
32+
33+
Make is available through XCode package.
34+
35+
36+
## 2- Selecting available SAM-BA interfaces
37+
38+
By default both USB and UART are made available, but this parameter can be modified in sam_ba_monitor.h, line 31:
39+
40+
Set the define SAM_BA_INTERFACE to
41+
* SAM_BA_UART_ONLY for only UART interface
42+
* SAM_BA_USBCDC_ONLY for only USB CDC interface
43+
* SAM_BA_BOTH_INTERFACES for enabling both the interfaces
44+
45+
## 3- Behaviour
46+
47+
This bootloader implements the double-tap on Reset button.
48+
By quickly pressing this button two times, the board will reset and stay in bootloader, waiting for communication on either USB or USART.
49+
50+
The USB port in use is the USB Native port, close to the Reset button.
51+
The USART in use is the one available on pins D0/D1, labelled respectively RX/TX. Communication parameters are a baudrate at 115200, 8bits of data, no parity and 1 stop bit (8N1).
52+
53+
## 4- Description
54+
55+
**Pinmap**
56+
57+
The following pins are used by the program :
58+
PA25 : input/output (USB DP)
59+
PA24 : input/output (USB DM)
60+
PA11 : input (USART RX)
61+
PA10 : output (USART TX)
62+
63+
The application board shall avoid driving the PA25, PA24, PB23 and PB22 signals while the boot program is running (after a POR for example).
64+
65+
**Clock system**
66+
67+
CPU runs at 48MHz from Generic Clock Generator 0 on DFLL48M.
68+
69+
Generic Clock Generator 1 is using external 32kHz oscillator and is the source of DFLL48M.
70+
71+
USB and USART are using Generic Clock Generator 0 also.
72+
73+
**Memory Mapping**
74+
75+
Bootloader code will be located at 0x0 and executed before any applicative code.
76+
77+
Applications compiled to be executed along with the bootloader will start at 0x2000 (see linker script bootloader_samd21x18.ld).
78+
79+
Before jumping to the application, the bootloader changes the VTOR register to use the interrupt vectors of the application @0x2000.<- not required as application code is taking care of this.
80+
81+
## 5- How to build
82+
83+
If not specified the makefile builds for **Arduino Zero**:
84+
85+
```
86+
make
87+
```
88+
89+
if you want to make a custom bootloader for a derivative board you must supply all the necessary information in a `board_definitions_xxx.h` file, and add the corresponding case in `board_definitions.h`.
90+
For example for the **Arduino MKR1000** we use `board_definitions_arduino_mkr1000.h` and it is build with the following command:
91+
92+
```
93+
BOARD_ID=arduino_mkr1000 NAME=samd21_sam_ba_arduino_mkr1000 make clean all
94+
```
95+
Binary file not shown.

0 commit comments

Comments
 (0)