Skip to content

Commit 006870e

Browse files
toddtreecedeanm1278
authored andcommitted
reverts bootloaders/zero changes
1 parent d6af8a9 commit 006870e

19 files changed

+1137
-1434
lines changed

bootloaders/zero/Makefile

Lines changed: 164 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,179 @@
1-
IDE_PATH=../../../../..
2-
ARM_GCC_PATH=$(IDE_PATH)/tools/arm-none-eabi-gcc/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)/tools/CMSIS/CMSIS/Include/ -I$(IDE_PATH)/tools/CMSIS/4.0.0-atmel/Device/ATMEL/ -I$(IDE_PATH)/tools/CMSIS/4.0.0-atmel/CMSIS/Include/ -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+
77+
# Arduino Zero (PID == 0x004D)
78+
CFLAGS_EXTRA?=-D__SAMD21G18A__ -DUSB_PID_HIGH=0x00 -DUSB_PID_LOW=0x4D
79+
# Genuino Zero (PID == 0x024D)
80+
# CFLAGS_EXTRA?=-D__SAMD21G18A__ -DUSB_PID_HIGH=0x02 -DUSB_PID_LOW=0x4D
81+
82+
INCLUDES=-I"$(MODULE_PATH)/tools/CMSIS/4.0.0-atmel/CMSIS/Include/" -I"$(MODULE_PATH)/tools/CMSIS/4.0.0-atmel/Device/ATMEL/"
83+
84+
# -----------------------------------------------------------------------------
85+
# Linker options
86+
LDFLAGS=-mthumb -mcpu=cortex-m0plus -Wall -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all
87+
LDFLAGS+=-Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols --specs=nano.specs --specs=nosys.specs
88+
89+
# -----------------------------------------------------------------------------
90+
# Source files and objects
91+
SOURCES= \
92+
board_driver_led.c \
93+
board_driver_serial.c \
94+
board_driver_usb.c \
95+
board_init.c \
96+
board_startup.c \
97+
main.c \
98+
sam_ba_usb.c \
99+
sam_ba_cdc.c \
100+
sam_ba_monitor.c \
101+
sam_ba_serial.c
102+
10103
OBJECTS=$(addprefix $(BUILD_PATH)/, $(SOURCES:.c=.o))
11104
DEPS=$(addprefix $(BUILD_PATH)/, $(SOURCES:.c=.d))
12105

106+
NAME=samd21_sam_ba
107+
ELF=$(NAME).elf
108+
BIN=$(NAME).bin
109+
HEX=$(NAME).hex
110+
13111
ifneq "test$(AVRSTUDIO_EXE_PATH)" "test"
14-
AS_BUILD=copy_for_atmel_studio
15-
AS_CLEAN=clean_for_atmel_studio
112+
AS_BUILD=copy_for_atmel_studio
113+
AS_CLEAN=clean_for_atmel_studio
16114
else
17-
AS_BUILD=
18-
AS_CLEAN=
115+
AS_BUILD=
116+
AS_CLEAN=
19117
endif
20118

21-
NAME=samd21_sam_ba
22-
EXECUTABLE=$(NAME).bin
23119

24120
all: print_info $(SOURCES) $(BIN) $(HEX) $(AS_BUILD)
25121

26-
all: $(SOURCES) $(EXECUTABLE)
122+
$(ELF): Makefile $(BUILD_PATH) $(OBJECTS)
123+
@echo ----------------------------------------------------------
124+
@echo Creating ELF binary
125+
"$(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
126+
"$(NM)" "$(BUILD_PATH)/$(ELF)" >"$(BUILD_PATH)/$(NAME)_symbols.txt"
127+
"$(SIZE)" --format=sysv -t -x $(BUILD_PATH)/$(ELF)
27128

28-
$(EXECUTABLE): $(OBJECTS)
29-
$(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
30-
$(ARM_GCC_PATH)/arm-none-eabi-objcopy -O binary $(BUILD_PATH)/$(NAME).elf $@
129+
$(BIN): $(ELF)
130+
@echo ----------------------------------------------------------
131+
@echo Creating flash binary
132+
"$(OBJCOPY)" -O binary $(BUILD_PATH)/$< $@
133+
134+
$(HEX): $(ELF)
135+
@echo ----------------------------------------------------------
136+
@echo Creating flash binary
137+
"$(OBJCOPY)" -O ihex $(BUILD_PATH)/$< $@
31138

32139
$(BUILD_PATH)/%.o: %.c
33-
-@mkdir -p $(@D)
34-
$(CC) $(CFLAGS) $(BLD_EXTA_FLAGS) $(INCLUDES) $< -o $@
140+
@echo ----------------------------------------------------------
141+
@echo Compiling $< to $@
142+
"$(CC)" $(CFLAGS) $(CFLAGS_EXTRA) $(INCLUDES) $< -o $@
143+
@echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
144+
145+
$(BUILD_PATH):
146+
@echo ----------------------------------------------------------
147+
@echo Creating build folder
148+
-mkdir $(BUILD_PATH)
149+
150+
print_info:
151+
@echo ----------------------------------------------------------
152+
@echo Compiling bootloader using
153+
@echo BASE PATH = $(MODULE_PATH)
154+
@echo GCC PATH = $(ARM_GCC_PATH)
155+
# @echo OS = $(OS)
156+
# @echo SHELL = $(SHELL)
157+
# @echo TERM = $(TERM)
158+
# "$(CC)" -v
159+
# env
160+
161+
copy_for_atmel_studio: $(BIN) $(HEX)
162+
@echo ----------------------------------------------------------
163+
@echo Atmel Studio detected, copying ELF to project root for debug
164+
cp $(BUILD_PATH)/$(ELF) .
165+
166+
clean_for_atmel_studio:
167+
@echo ----------------------------------------------------------
168+
@echo Atmel Studio detected, cleaning ELF from project root
169+
-$(RM) ./$(ELF)
170+
171+
clean: $(AS_CLEAN)
172+
@echo ----------------------------------------------------------
173+
@echo Cleaning project
174+
-$(RM) $(BIN)
175+
-$(RM) $(HEX)
176+
-$(RM) $(BUILD_PATH)/*.*
177+
-rmdir $(BUILD_PATH)
35178

36-
clean:
37-
del $(EXECUTABLE) $(subst /,\,$(OBJECTS)) $(subst /,\,$(BUILD_PATH)/$(NAME).*)
179+
.phony: print_info $(BUILD_PATH)

bootloaders/zero/README.md

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ Multi-plaform GCC is provided by ARM here: https://launchpad.net/gcc-arm-embedde
99

1010
Atmel Studio contains both make and ARM GCC toolchain. You don't need to install them in this specific use case.
1111

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-
1612
### Windows
1713

1814
* Native command line
@@ -77,19 +73,3 @@ Bootloader code will be located at 0x0 and executed before any applicative code.
7773
Applications compiled to be executed along with the bootloader will start at 0x2000 (see linker script bootloader_samd21x18.ld).
7874

7975
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-

bootloaders/zero/board_definitions.h

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,56 @@
1717
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1818
*/
1919

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_arduino_mkrfox1200)
31-
#include "board_definitions_arduino_mkrfox1200.h"
32-
#elif defined(BOARD_ID_arduino_mkrgsm1400)
33-
#include "board_definitions_arduino_mkrgsm1400.h"
34-
#elif defined(BOARD_ID_arduino_mkrwan1300)
35-
#include "board_definitions_arduino_mkrwan1300.h"
36-
#elif defined(BOARD_ID_arduino_mkrwifi1010)
37-
#include "board_definitions_arduino_mkrwifi1010.h"
38-
#else
39-
#error You must define a BOARD_ID and add the corresponding definitions in board_definitions.h
40-
#endif
41-
42-
// Common definitions
43-
// ------------------
44-
45-
#define BOOT_PIN_MASK (1U << (BOOT_LOAD_PIN & 0x1f))
20+
#ifndef _BOARD_DEFINITIONS_H_
21+
#define _BOARD_DEFINITIONS_H_
4622

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: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,4 @@
1919

2020
#include "board_driver_led.h"
2121

22-
volatile uint8_t ledKeepValue = 0;
23-
volatile uint8_t ledTargetValue = 20;
24-
volatile int8_t ledDirection = 1;
2522

26-
inline void LED_pulse()
27-
{
28-
if (ledKeepValue == 0) {
29-
ledTargetValue += ledDirection;
30-
LED_toggle();
31-
}
32-
ledKeepValue ++;
33-
34-
if (ledTargetValue > 240 || ledTargetValue < 10) {
35-
ledDirection = -ledDirection;
36-
ledTargetValue += ledDirection;
37-
}
38-
39-
if (ledKeepValue == ledTargetValue) {
40-
LED_toggle();
41-
}
42-
}

bootloaders/zero/board_driver_led.h

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,19 @@
2323
#include <sam.h>
2424
#include "board_definitions.h"
2525

26-
#if defined(BOARD_LED_PORT)
2726
inline void LED_init(void) { PORT->Group[BOARD_LED_PORT].DIRSET.reg = (1<<BOARD_LED_PIN); }
2827
inline void LED_on(void) { PORT->Group[BOARD_LED_PORT].OUTSET.reg = (1<<BOARD_LED_PIN); }
2928
inline void LED_off(void) { PORT->Group[BOARD_LED_PORT].OUTCLR.reg = (1<<BOARD_LED_PIN); }
3029
inline void LED_toggle(void) { PORT->Group[BOARD_LED_PORT].OUTTGL.reg = (1<<BOARD_LED_PIN); }
31-
#else
32-
inline void LED_init(void) { }
33-
inline void LED_on(void) { }
34-
inline void LED_off(void) { }
35-
inline void LED_toggle(void) { }
36-
#endif
37-
void LED_pulse();
38-
39-
#if defined(BOARD_LEDRX_PORT)
30+
4031
inline void LEDRX_init(void) { PORT->Group[BOARD_LEDRX_PORT].DIRSET.reg = (1<<BOARD_LEDRX_PIN); }
41-
inline void LEDRX_on(void) { PORT->Group[BOARD_LEDRX_PORT].OUTCLR.reg = (1<<BOARD_LEDRX_PIN); }
42-
inline void LEDRX_off(void) { PORT->Group[BOARD_LEDRX_PORT].OUTSET.reg = (1<<BOARD_LEDRX_PIN); }
32+
inline void LEDRX_on(void) { PORT->Group[BOARD_LEDRX_PORT].OUTSET.reg = (1<<BOARD_LEDRX_PIN); }
33+
inline void LEDRX_off(void) { PORT->Group[BOARD_LEDRX_PORT].OUTCLR.reg = (1<<BOARD_LEDRX_PIN); }
4334
inline void LEDRX_toggle(void) { PORT->Group[BOARD_LEDRX_PORT].OUTTGL.reg = (1<<BOARD_LEDRX_PIN); }
44-
#else
45-
inline void LEDRX_init(void) { }
46-
inline void LEDRX_on(void) { }
47-
inline void LEDRX_off(void) { }
48-
inline void LEDRX_toggle(void) { }
49-
#endif
50-
51-
#if defined(BOARD_LEDTX_PORT)
35+
5236
inline void LEDTX_init(void) { PORT->Group[BOARD_LEDTX_PORT].DIRSET.reg = (1<<BOARD_LEDTX_PIN); }
53-
inline void LEDTX_on(void) { PORT->Group[BOARD_LEDTX_PORT].OUTCLR.reg = (1<<BOARD_LEDTX_PIN); }
54-
inline void LEDTX_off(void) { PORT->Group[BOARD_LEDTX_PORT].OUTSET.reg = (1<<BOARD_LEDTX_PIN); }
37+
inline void LEDTX_on(void) { PORT->Group[BOARD_LEDTX_PORT].OUTSET.reg = (1<<BOARD_LEDTX_PIN); }
38+
inline void LEDTX_off(void) { PORT->Group[BOARD_LEDTX_PORT].OUTCLR.reg = (1<<BOARD_LEDTX_PIN); }
5539
inline void LEDTX_toggle(void) { PORT->Group[BOARD_LEDTX_PORT].OUTTGL.reg = (1<<BOARD_LEDTX_PIN); }
56-
#else
57-
inline void LEDTX_init(void) { }
58-
inline void LEDTX_on(void) { }
59-
inline void LEDTX_off(void) { }
60-
inline void LEDTX_toggle(void) { }
61-
#endif
6240

6341
#endif // _BOARD_DRIVER_LED_

bootloaders/zero/board_driver_serial.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <sam.h>
2626

2727
#define PINMUX_UNUSED 0xFFFFFFFF
28+
#define GCLK_ID_SERCOM0_CORE 0x14
2829

2930
/* SERCOM UART available pad settings */
3031
enum uart_pad_settings {

0 commit comments

Comments
 (0)