Skip to content

Commit e6f62d1

Browse files
committed
Merge branch 'bootloader_rework' of https://github.com/aethaniel/ArduinoCore-samd
Conflicts: bootloaders/zero/drivers/cdc_enumerate.c
2 parents 5d10da2 + 97cda83 commit e6f62d1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3712
-5201
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ SAMD CORE 1.6.3
22

33
* Added SPI.transfer16(..) method
44
* Bugfix: added missing Serial.begin(baud, config) method. Thanks @tuxedo0801
5+
* Bootloader: 32Khz external oscillator is now used, improves USB clock. Thanks @aethaniel
6+
* Bootloader: Clean up of makefiles and file organization. Thanks @aethaniel
57

68
SAMD CORE 1.6.2 2015.11.03
79

bootloaders/zero/Makefile

Lines changed: 166 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,174 @@
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 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+
22+
# Are we using mingw/msys/msys2/cygwin?
23+
ifeq ($(TERM),xterm)
24+
# this is the path coming with night build
25+
# T=$(shell cygpath -u $(LOCALAPPDATA))
26+
# this is the path till 1.6.5 r5
27+
T=$(shell cygpath -u $(APPDATA))
28+
MODULE_PATH?=$(T)/Arduino15/packages/arduino
29+
ARM_GCC_PATH?=$(MODULE_PATH)/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-
30+
RM=rm
31+
SEP=/
32+
else
33+
# this is the path coming with night build
34+
# MODULE_PATH?=$(LOCALAPPDATA)/Arduino15/packages/arduino
35+
# this is the path till 1.6.5 r5
36+
MODULE_PATH?=$(APPDATA)/Arduino15/packages/arduino
37+
ARM_GCC_PATH?=$(MODULE_PATH)/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-
38+
RM=rm
39+
SEP=\\
40+
endif
41+
else
42+
UNAME_S := $(shell uname -s)
43+
44+
ifeq ($(UNAME_S),Linux)
45+
MODULE_PATH?=$HOME/.arduino15/packages/arduino
46+
ARM_GCC_PATH?=$(MODULE_PATH)/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-
47+
RM=rm
48+
SEP=/
49+
endif
50+
51+
ifeq ($(UNAME_S),Darwin)
52+
MODULE_PATH?=$HOME/Library/Arduino15/packages/arduino/
53+
ARM_GCC_PATH?=$(MODULE_PATH)/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-
54+
RM=rm
55+
SEP=/
56+
endif
57+
endif
58+
759
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
60+
61+
# -----------------------------------------------------------------------------
62+
# Tools
63+
CC=$(ARM_GCC_PATH)gcc
64+
OBJCOPY=$(ARM_GCC_PATH)objcopy
65+
NM=$(ARM_GCC_PATH)nm
66+
SIZE=$(ARM_GCC_PATH)size
67+
68+
# -----------------------------------------------------------------------------
69+
# Compiler options
70+
CFLAGS=-mthumb -mcpu=cortex-m0plus -Wall -c -std=gnu99 -ffunction-sections -fdata-sections -nostdlib -nostartfiles --param max-inline-insns-single=500
71+
ifdef DEBUG
72+
CFLAGS+=-g3 -O1 -DDEBUG=1
73+
else
74+
CFLAGS+=-Os -DDEBUG=0
75+
endif
76+
CFLAGS_EXTRA?=-D__SAMD21G18A__ -DUSB_PID_LOW=0x4D -DUSB_PID_HIGH=0x00
77+
INCLUDES=-I"$(MODULE_PATH)/tools/CMSIS/4.0.0-atmel/CMSIS/Include/" -I"$(MODULE_PATH)/tools/CMSIS/4.0.0-atmel/Device/ATMEL/"
78+
79+
# -----------------------------------------------------------------------------
80+
# Linker options
81+
LDFLAGS=-mthumb -mcpu=cortex-m0plus -Wall -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all
82+
LDFLAGS+=-Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols --specs=nano.specs --specs=nosys.specs
83+
84+
# -----------------------------------------------------------------------------
85+
# Source files and objects
86+
SOURCES= \
87+
board_driver_led.c \
88+
board_driver_serial.c \
89+
board_driver_usb.c \
90+
board_init.c \
91+
board_startup.c \
92+
main.c \
93+
sam_ba_usb.c \
94+
sam_ba_cdc.c \
95+
sam_ba_monitor.c \
96+
sam_ba_serial.c
97+
1098
OBJECTS=$(addprefix $(BUILD_PATH)/, $(SOURCES:.c=.o))
99+
DEPS=$(addprefix $(BUILD_PATH)/, $(SOURCES:.c=.d))
11100

12101
NAME=samd21_sam_ba
13-
EXECUTABLE=$(NAME).bin
102+
ELF=$(NAME).elf
103+
BIN=$(NAME).bin
104+
HEX=$(NAME).hex
14105

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

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 $@
114+
115+
all: print_info $(SOURCES) $(BIN) $(HEX) $(AS_BUILD)
116+
117+
$(ELF): Makefile $(BUILD_PATH) $(OBJECTS)
118+
@echo ----------------------------------------------------------
119+
@echo Creating ELF binary
120+
"$(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
121+
"$(NM)" "$(BUILD_PATH)/$(ELF)" >"$(BUILD_PATH)/$(NAME)_symbols.txt"
122+
"$(SIZE)" --format=sysv -t -x $(BUILD_PATH)/$(ELF)
123+
124+
$(BIN): $(ELF)
125+
@echo ----------------------------------------------------------
126+
@echo Creating flash binary
127+
"$(OBJCOPY)" -O binary $(BUILD_PATH)/$< $@
128+
129+
$(HEX): $(ELF)
130+
@echo ----------------------------------------------------------
131+
@echo Creating flash binary
132+
"$(OBJCOPY)" -O ihex $(BUILD_PATH)/$< $@
23133

24134
$(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).*)
135+
@echo ----------------------------------------------------------
136+
@echo Compiling $< to $@
137+
"$(CC)" $(CFLAGS) $(CFLAGS_EXTRA) $(INCLUDES) $< -o $@
138+
@echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
139+
140+
$(BUILD_PATH):
141+
@echo ----------------------------------------------------------
142+
@echo Creating build folder
143+
-mkdir $(BUILD_PATH)
144+
145+
print_info:
146+
@echo ----------------------------------------------------------
147+
@echo Compiling bootloader using
148+
@echo BASE PATH = $(MODULE_PATH)
149+
@echo GCC PATH = $(ARM_GCC_PATH)
150+
# @echo OS = $(OS)
151+
# @echo SHELL = $(SHELL)
152+
# @echo TERM = $(TERM)
153+
# "$(CC)" -v
154+
# env
155+
156+
copy_for_atmel_studio: $(BIN) $(HEX)
157+
@echo ----------------------------------------------------------
158+
@echo Atmel Studio detected, copying ELF to project root for debug
159+
cp $(BUILD_PATH)/$(ELF) .
160+
161+
clean_for_atmel_studio:
162+
@echo ----------------------------------------------------------
163+
@echo Atmel Studio detected, cleaning ELF from project root
164+
-$(RM) ./$(ELF)
165+
166+
clean: $(AS_CLEAN)
167+
@echo ----------------------------------------------------------
168+
@echo Cleaning project
169+
-$(RM) $(BIN)
170+
-$(RM) $(HEX)
171+
-$(RM) $(BUILD_PATH)/*.*
172+
-rmdir $(BUILD_PATH)
173+
174+
.phony: print_info $(BUILD_PATH)

bootloaders/zero/README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
### Windows
13+
14+
* Native command line
15+
Make binary can be obtained here: http://gnuwin32.sourceforge.net/packages/make.htm
16+
17+
* Cygwin/MSys/MSys2/Babun/etc...
18+
It is available natively in all distributions.
19+
20+
* Atmel Studio
21+
An Atmel Studio **7** Makefile-based project is present at project root, just open samd21_sam_ba.atsln file in AS7.
22+
23+
### Linux
24+
25+
Make is usually available by default.
26+
27+
### OS X
28+
29+
Make is available through XCode package.
30+
31+
32+
## 2- Selecting available SAM-BA interfaces
33+
34+
By default both USB and UART are made available, but this parameter can be modified in sam_ba_monitor.h, line 31:
35+
36+
Set the define SAM_BA_INTERFACE to
37+
* SAM_BA_UART_ONLY for only UART interface
38+
* SAM_BA_USBCDC_ONLY for only USB CDC interface
39+
* SAM_BA_BOTH_INTERFACES for enabling both the interfaces
40+
41+
## 3- Behaviour
42+
43+
This bootloader implements the double-tap on Reset button.
44+
By quickly pressing this button two times, the board will reset and stay in bootloader, waiting for communication on either USB or USART.
45+
46+
The USB port in use is the USB Native port, close to the Reset button.
47+
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).
48+
49+
## 4- Description
50+
51+
**Pinmap**
52+
53+
The following pins are used by the program :
54+
PA25 : input/output (USB DP)
55+
PA24 : input/output (USB DM)
56+
PA11 : input (USART RX)
57+
PA10 : output (USART TX)
58+
59+
The application board shall avoid driving the PA25, PA24, PB23 and PB22 signals while the boot program is running (after a POR for example).
60+
61+
**Clock system**
62+
63+
CPU runs at 48MHz from Generic Clock Generator 0 on DFLL48M.
64+
65+
Generic Clock Generator 1 is using external 32kHz oscillator and is the source of DFLL48M.
66+
67+
USB and USART are using Generic Clock Generator 0 also.
68+
69+
**Memory Mapping**
70+
71+
Bootloader code will be located at 0x0 and executed before any applicative code.
72+
73+
Applications compiled to be executed along with the bootloader will start at 0x2000 (see linker script bootloader_samd21x18.ld).
74+
75+
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.

bootloaders/zero/board_definitions.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
* If BOOT_DOUBLE_TAP_ADDRESS is defined the bootloader is started by
25+
* quickly tapping two times on the reset button.
26+
* BOOT_DOUBLE_TAP_ADDRESS must point to a free SRAM cell that must not
27+
* be touched from the loaded application.
28+
*/
29+
#define BOOT_DOUBLE_TAP_ADDRESS (0x20007FFCul)
30+
#define BOOT_DOUBLE_TAP_DATA (*((volatile uint32_t *) BOOT_DOUBLE_TAP_ADDRESS))
31+
32+
/*
33+
* If BOOT_LOAD_PIN is defined the bootloader is started if the selected
34+
* pin is tied LOW.
35+
*/
36+
//#define BOOT_LOAD_PIN PIN_PA21 // Pin 7
37+
//#define BOOT_LOAD_PIN PIN_PA15 // Pin 5
38+
#define BOOT_PIN_MASK (1U << (BOOT_LOAD_PIN & 0x1f))
39+
40+
#define CPU_FREQUENCY (48000000ul)
41+
42+
#define BOOT_USART_MODULE SERCOM0
43+
#define BOOT_USART_BUS_CLOCK_INDEX PM_APBCMASK_SERCOM0
44+
#define BOOT_USART_PER_CLOCK_INDEX GCLK_ID_SERCOM0_CORE
45+
#define BOOT_USART_PAD_SETTINGS UART_RX_PAD3_TX_PAD2
46+
#define BOOT_USART_PAD3 PINMUX_PA11C_SERCOM0_PAD3
47+
#define BOOT_USART_PAD2 PINMUX_PA10C_SERCOM0_PAD2
48+
#define BOOT_USART_PAD1 PINMUX_UNUSED
49+
#define BOOT_USART_PAD0 PINMUX_UNUSED
50+
51+
/* Frequency of the board main oscillator */
52+
#define VARIANT_MAINOSC (32768ul)
53+
54+
/* Master clock frequency */
55+
#define VARIANT_MCK CPU_FREQUENCY
56+
57+
#define NVM_SW_CALIB_DFLL48M_COARSE_VAL (58)
58+
#define NVM_SW_CALIB_DFLL48M_FINE_VAL (64)
59+
60+
/*
61+
* LEDs definitions
62+
*/
63+
#define BOARD_LED_PORT (0)
64+
#define BOARD_LED_PIN (17)
65+
66+
#define BOARD_LEDRX_PORT (1)
67+
#define BOARD_LEDRX_PIN (3)
68+
69+
#define BOARD_LEDTX_PORT (0)
70+
#define BOARD_LEDTX_PIN (27)
71+
72+
#endif // _BOARD_DEFINITIONS_H_

bootloaders/zero/board_driver_led.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
#include "board_driver_led.h"
21+
22+

0 commit comments

Comments
 (0)