Skip to content

Commit c3caa49

Browse files
committed
Added bootloader files, and updated USB VID/PID
1 parent a1483d0 commit c3caa49

Some content is hidden

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

43 files changed

+5643
-2
lines changed

boards.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
mysensors_gw_native.name=Sensebender Gateway
1818
mysensors_gw_native.vid.0=0x1209
1919
mysensors_gw_native.pid.0=0x6949
20+
mysensors_gw_native.vid.1=0x1209
21+
mysensors_gw_native.pid.1=0x6948
2022
mysensors_gw_native.upload.tool=bossac
2123
mysensors_gw_native.upload.protocol=sam-ba
2224
mysensors_gw_native.upload.maximum_size=262144
@@ -38,4 +40,4 @@ mysensors_gw_native.build.vid=0x1209
3840
mysensors_gw_native.build.pid=0x6949
3941
mysensors_gw_native.build.arch=samd
4042
mysensors_gw_native.bootloader.tool=openocd
41-
mysensors_gw_native.bootloader.file=zero/samd21_sam_ba.bin
43+
mysensors_gw_native.bootloader.file=mysensors_gw/samd21_sam_ba.bin

bootloaders/mysensors_gw/Makefile

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
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+
T=$(shell cygpath -u $(LOCALAPPDATA))
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+
ARM_GCC_PATH?=$(MODULE_PATH)/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-
32+
RM=rm
33+
SEP=\\
34+
endif
35+
else
36+
UNAME_S := $(shell uname -s)
37+
38+
ifeq ($(UNAME_S),Linux)
39+
MODULE_PATH?=$(HOME)/.arduino15/packages/arduino
40+
ARM_GCC_PATH?=$(MODULE_PATH)/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-
41+
RM=rm
42+
SEP=/
43+
endif
44+
45+
ifeq ($(UNAME_S),Darwin)
46+
MODULE_PATH?=$(HOME)/Library/Arduino15/packages/arduino/
47+
ARM_GCC_PATH?=$(MODULE_PATH)/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-
48+
RM=rm
49+
SEP=/
50+
endif
51+
endif
52+
53+
BUILD_PATH=build
54+
55+
# -----------------------------------------------------------------------------
56+
# Tools
57+
CC=$(ARM_GCC_PATH)gcc
58+
OBJCOPY=$(ARM_GCC_PATH)objcopy
59+
NM=$(ARM_GCC_PATH)nm
60+
SIZE=$(ARM_GCC_PATH)size
61+
62+
# -----------------------------------------------------------------------------
63+
# Compiler options
64+
CFLAGS=-mthumb -mcpu=cortex-m0plus -Wall -c -std=gnu99 -ffunction-sections -fdata-sections -nostdlib -nostartfiles --param max-inline-insns-single=500
65+
ifdef DEBUG
66+
CFLAGS+=-g3 -O1 -DDEBUG=1
67+
else
68+
CFLAGS+=-Os -DDEBUG=0
69+
endif
70+
71+
# MySensors GW (PID == 0x6498)
72+
CFLAGS_EXTRA?=-D__SAMD21G18A__ -DUSB_PID_HIGH=0x64 -DUSB_PID_LOW=0x48 -DUSB_VID_LOW=0x09 -DUSB_VID_HIGH=0x12
73+
74+
INCLUDES=-I"$(MODULE_PATH)/tools/CMSIS/4.0.0-atmel/CMSIS/Include/" -I"$(MODULE_PATH)/tools/CMSIS/4.0.0-atmel/Device/ATMEL/"
75+
76+
# -----------------------------------------------------------------------------
77+
# Linker options
78+
LDFLAGS=-mthumb -mcpu=cortex-m0plus -Wall -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all
79+
LDFLAGS+=-Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols --specs=nano.specs --specs=nosys.specs
80+
81+
# -----------------------------------------------------------------------------
82+
# Source files and objects
83+
SOURCES= \
84+
board_driver_led.c \
85+
board_driver_serial.c \
86+
board_driver_usb.c \
87+
board_init.c \
88+
board_startup.c \
89+
main.c \
90+
sam_ba_usb.c \
91+
sam_ba_cdc.c \
92+
sam_ba_monitor.c \
93+
sam_ba_serial.c
94+
95+
OBJECTS=$(addprefix $(BUILD_PATH)/, $(SOURCES:.c=.o))
96+
DEPS=$(addprefix $(BUILD_PATH)/, $(SOURCES:.c=.d))
97+
98+
NAME=samd21_sam_ba
99+
ELF=$(NAME).elf
100+
BIN=$(NAME).bin
101+
HEX=$(NAME).hex
102+
103+
ifneq "test$(AVRSTUDIO_EXE_PATH)" "test"
104+
AS_BUILD=copy_for_atmel_studio
105+
AS_CLEAN=clean_for_atmel_studio
106+
else
107+
AS_BUILD=
108+
AS_CLEAN=
109+
endif
110+
111+
112+
all: print_info $(SOURCES) $(BIN) $(HEX) $(AS_BUILD)
113+
114+
$(ELF): Makefile $(BUILD_PATH) $(OBJECTS)
115+
@echo ----------------------------------------------------------
116+
@echo Creating ELF binary
117+
"$(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
118+
"$(NM)" "$(BUILD_PATH)/$(ELF)" >"$(BUILD_PATH)/$(NAME)_symbols.txt"
119+
"$(SIZE)" --format=sysv -t -x $(BUILD_PATH)/$(ELF)
120+
121+
$(BIN): $(ELF)
122+
@echo ----------------------------------------------------------
123+
@echo Creating flash binary
124+
"$(OBJCOPY)" -O binary $(BUILD_PATH)/$< $@
125+
126+
$(HEX): $(ELF)
127+
@echo ----------------------------------------------------------
128+
@echo Creating flash binary
129+
"$(OBJCOPY)" -O ihex $(BUILD_PATH)/$< $@
130+
131+
$(BUILD_PATH)/%.o: %.c
132+
@echo ----------------------------------------------------------
133+
@echo Compiling $< to $@
134+
"$(CC)" $(CFLAGS) $(CFLAGS_EXTRA) $(INCLUDES) $< -o $@
135+
@echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
136+
137+
$(BUILD_PATH):
138+
@echo ----------------------------------------------------------
139+
@echo Creating build folder
140+
-mkdir $(BUILD_PATH)
141+
142+
print_info:
143+
@echo ----------------------------------------------------------
144+
@echo Compiling bootloader using
145+
@echo BASE PATH = $(MODULE_PATH)
146+
@echo GCC PATH = $(ARM_GCC_PATH)
147+
# @echo OS = $(OS)
148+
# @echo SHELL = $(SHELL)
149+
# @echo TERM = $(TERM)
150+
# "$(CC)" -v
151+
# env
152+
153+
copy_for_atmel_studio: $(BIN) $(HEX)
154+
@echo ----------------------------------------------------------
155+
@echo Atmel Studio detected, copying ELF to project root for debug
156+
cp $(BUILD_PATH)/$(ELF) .
157+
158+
clean_for_atmel_studio:
159+
@echo ----------------------------------------------------------
160+
@echo Atmel Studio detected, cleaning ELF from project root
161+
-$(RM) ./$(ELF)
162+
163+
clean: $(AS_CLEAN)
164+
@echo ----------------------------------------------------------
165+
@echo Cleaning project
166+
-$(RM) $(BIN)
167+
-$(RM) $(HEX)
168+
-$(RM) $(BUILD_PATH)/*.*
169+
-rmdir $(BUILD_PATH)
170+
171+
.phony: print_info $(BUILD_PATH)

bootloaders/mysensors_gw/README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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.
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_
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)