Skip to content

Commit 594424a

Browse files
author
Jim Lindblom
committed
Adding Spectacle Director bootloader
1 parent 9fc5699 commit 594424a

33 files changed

+5002
-0
lines changed
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
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-
49+
BUILD_PATH=build
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+
NAME?=sparkfun_spectacle
61+
BOARD_ID?=sparkfun_spectacle
62+
63+
# -----------------------------------------------------------------------------
64+
# Compiler options
65+
CFLAGS_EXTRA=-D__SAMD21G18A__ -DBOARD_ID_$(BOARD_ID)
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+
73+
ELF=$(NAME).elf
74+
BIN=$(NAME).bin
75+
HEX=$(NAME).hex
76+
77+
78+
INCLUDES=-I"$(MODULE_PATH)/tools/CMSIS/4.5.0/CMSIS/Include/" -I"$(MODULE_PATH)/tools/CMSIS-Atmel/1.0.0/CMSIS/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+
99+
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+
110+
111+
all: print_info $(SOURCES) $(BIN) $(HEX) $(AS_BUILD)
112+
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)
119+
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)/$< $@
129+
130+
$(BUILD_PATH)/%.o: %.c
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+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Copyright (c) 2015 Arduino LLC. All right reserved.
3+
Copyright (c) 2015 Atmel Corporation/Thibaut VIARD. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13+
See the GNU Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#if defined(BOARD_ID_arduino_zero)
21+
#include "board_definitions_arduino_zero.h"
22+
#elif defined(BOARD_ID_genuino_zero)
23+
#include "board_definitions_genuino_zero.h"
24+
#elif defined(BOARD_ID_arduino_mkr1000)
25+
#include "board_definitions_arduino_mkr1000.h"
26+
#elif defined(BOARD_ID_genuino_mkr1000)
27+
#include "board_definitions_genuino_mkr1000.h"
28+
#elif defined(BOARD_ID_arduino_mkrzero)
29+
#include "board_definitions_arduino_mkrzero.h"
30+
#elif defined(BOARD_ID_sparkfun_spectacle)
31+
#include "board_definitions_sparkfun_spectacle.h"
32+
#else
33+
#error You must define a BOARD_ID and add the corresponding definitions in board_definitions.h
34+
#endif
35+
36+
// Common definitions
37+
// ------------------
38+
39+
#define BOOT_PIN_MASK (1U << (BOOT_LOAD_PIN & 0x1f))
40+
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
Copyright (c) 2015 Arduino LLC. All right reserved.
3+
Copyright (c) 2015 Atmel Corporation/Thibaut VIARD. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13+
See the GNU Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#ifndef _BOARD_DEFINITIONS_H_
21+
#define _BOARD_DEFINITIONS_H_
22+
23+
/*
24+
* USB device definitions
25+
*/
26+
#define STRING_PRODUCT "Arduino MKR1000"
27+
#define USB_VID_HIGH 0x23
28+
#define USB_VID_LOW 0x41
29+
#define USB_PID_HIGH 0x00
30+
#define USB_PID_LOW 0x4E
31+
32+
/*
33+
* If BOOT_DOUBLE_TAP_ADDRESS is defined the bootloader is started by
34+
* quickly tapping two times on the reset button.
35+
* BOOT_DOUBLE_TAP_ADDRESS must point to a free SRAM cell that must not
36+
* be touched from the loaded application.
37+
*/
38+
#define BOOT_DOUBLE_TAP_ADDRESS (0x20007FFCul)
39+
#define BOOT_DOUBLE_TAP_DATA (*((volatile uint32_t *) BOOT_DOUBLE_TAP_ADDRESS))
40+
41+
/*
42+
* If BOOT_LOAD_PIN is defined the bootloader is started if the selected
43+
* pin is tied LOW.
44+
*/
45+
//#define BOOT_LOAD_PIN PIN_PA21 // Pin 7
46+
//#define BOOT_LOAD_PIN PIN_PA15 // Pin 5
47+
48+
#define BOOT_USART_MODULE SERCOM0
49+
#define BOOT_USART_BUS_CLOCK_INDEX PM_APBCMASK_SERCOM0
50+
#define BOOT_USART_PER_CLOCK_INDEX GCLK_CLKCTRL_ID_SERCOM0_CORE_Val
51+
#define BOOT_USART_PAD_SETTINGS UART_RX_PAD3_TX_PAD2
52+
#define BOOT_USART_PAD3 PINMUX_PA11C_SERCOM0_PAD3
53+
#define BOOT_USART_PAD2 PINMUX_PA10C_SERCOM0_PAD2
54+
#define BOOT_USART_PAD1 PINMUX_UNUSED
55+
#define BOOT_USART_PAD0 PINMUX_UNUSED
56+
57+
/* Master clock frequency */
58+
#define CPU_FREQUENCY (48000000ul)
59+
#define VARIANT_MCK CPU_FREQUENCY
60+
61+
/* Frequency of the board main oscillator */
62+
#define VARIANT_MAINOSC (32768ul)
63+
64+
/* Calibration values for DFLL48 pll */
65+
#define NVM_SW_CALIB_DFLL48M_COARSE_VAL (58)
66+
#define NVM_SW_CALIB_DFLL48M_FINE_VAL (64)
67+
68+
/*
69+
* LEDs definitions
70+
*/
71+
// PA20 (digital pin 6)
72+
#define BOARD_LED_PORT (0)
73+
#define BOARD_LED_PIN (20)
74+
75+
// No RX/TX led
76+
//#define BOARD_LEDRX_PORT
77+
//#define BOARD_LEDRX_PIN
78+
79+
//#define BOARD_LEDTX_PORT
80+
//#define BOARD_LEDTX_PIN
81+
82+
#endif // _BOARD_DEFINITIONS_H_

0 commit comments

Comments
 (0)