Skip to content

Bootloader LEDs / TXRX activity / USB Descriptors / Makefile #165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Sep 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bootloaders/mkr1000/samd21_sam_ba_arduino_mkr1000.bin
Binary file not shown.
775 changes: 404 additions & 371 deletions bootloaders/mkr1000/samd21_sam_ba_arduino_mkr1000.hex

Large diffs are not rendered by default.

Binary file modified bootloaders/mkr1000/samd21_sam_ba_genuino_mkr1000.bin
Binary file not shown.
775 changes: 404 additions & 371 deletions bootloaders/mkr1000/samd21_sam_ba_genuino_mkr1000.hex

Large diffs are not rendered by default.

87 changes: 39 additions & 48 deletions bootloaders/zero/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,34 @@
# -----------------------------------------------------------------------------
# Paths
ifeq ($(OS),Windows_NT)

# Are we using mingw/msys/msys2/cygwin?
ifeq ($(TERM),xterm)
T=$(shell cygpath -u $(LOCALAPPDATA))
T=$(shell cygpath -u $(LOCALAPPDATA))
MODULE_PATH?=$(T)/Arduino15/packages/arduino
ARM_GCC_PATH?=$(MODULE_PATH)/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-
RM=rm
SEP=/
else
MODULE_PATH?=$(LOCALAPPDATA)/Arduino15/packages/arduino
ARM_GCC_PATH?=$(MODULE_PATH)/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-
RM=rm
SEP=\\
endif
else
UNAME_S := $(shell uname -s)

ifeq ($(UNAME_S),Linux)
MODULE_PATH?=$(HOME)/.arduino15/packages/arduino
ARM_GCC_PATH?=$(MODULE_PATH)/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-
RM=rm
SEP=/
endif

ifeq ($(UNAME_S),Darwin)
MODULE_PATH?=$(HOME)/Library/Arduino15/packages/arduino/
ARM_GCC_PATH?=$(MODULE_PATH)/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-
RM=rm
SEP=/
endif
UNAME_S := $(shell uname -s)

ifeq ($(UNAME_S),Linux)
MODULE_PATH?=$(HOME)/.arduino15/packages/arduino
RM=rm
SEP=/
endif

ifeq ($(UNAME_S),Darwin)
MODULE_PATH?=$(HOME)/Library/Arduino15/packages/arduino/
RM=rm
SEP=/
endif
endif

ARM_GCC_PATH?=$(MODULE_PATH)/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-
BUILD_PATH=build

# -----------------------------------------------------------------------------
Expand All @@ -59,23 +55,23 @@ OBJCOPY=$(ARM_GCC_PATH)objcopy
NM=$(ARM_GCC_PATH)nm
SIZE=$(ARM_GCC_PATH)size

# -----------------------------------------------------------------------------
# Boards definitions
BOARD_ID?=arduino_zero

# -----------------------------------------------------------------------------
# Compiler options
CFLAGS_EXTRA=-D__SAMD21G18A__ -DBOARD_ID_$(BOARD_ID)
CFLAGS=-mthumb -mcpu=cortex-m0plus -Wall -c -std=gnu99 -ffunction-sections -fdata-sections -nostdlib -nostartfiles --param max-inline-insns-single=500
ifdef DEBUG
CFLAGS+=-g3 -O1 -DDEBUG=1
CFLAGS+=-g3 -O1 -DDEBUG=1
else
CFLAGS+=-Os -DDEBUG=0
CFLAGS+=-Os -DDEBUG=0
endif

# Arduino Zero (PID == 0x004D)
CFLAGS_EXTRA?=-D__SAMD21G18A__ -DUSB_PID_HIGH=0x00 -DUSB_PID_LOW=0x4D -DUSB_VID_LOW=0x41 -DUSB_VID_HIGH=0x23
# Genuino Zero (PID == 0x024D)
# CFLAGS_EXTRA?=-D__SAMD21G18A__ -DUSB_PID_HIGH=0x02 -DUSB_PID_LOW=0x4D -DUSB_VID_LOW=0x41 -DUSB_VID_HIGH=0x23
# Arduino MKR1000 (PID == 0x004E)
# CFLAGS_EXTRA?=-D__SAMD21G18A__ -DUSB_PID_HIGH=0x00 -DUSB_PID_LOW=0x4E -DUSB_VID_LOW=0x41 -DUSB_VID_HIGH=0x23
# Genuino MKR1000 (PID == 0x024E)
# CFLAGS_EXTRA?=-D__SAMD21G18A__ -DUSB_PID_HIGH=0x02 -DUSB_PID_LOW=0x4E -DUSB_VID_LOW=0x41 -DUSB_VID_HIGH=0x23
ELF=$(NAME).elf
BIN=$(NAME).bin
HEX=$(NAME).hex

INCLUDES=-I"$(MODULE_PATH)/tools/CMSIS/4.0.0-atmel/CMSIS/Include/" -I"$(MODULE_PATH)/tools/CMSIS/4.0.0-atmel/Device/ATMEL/"

Expand All @@ -87,31 +83,26 @@ LDFLAGS+=-Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbol
# -----------------------------------------------------------------------------
# Source files and objects
SOURCES= \
board_driver_led.c \
board_driver_serial.c \
board_driver_usb.c \
board_init.c \
board_startup.c \
main.c \
sam_ba_usb.c \
sam_ba_cdc.c \
sam_ba_monitor.c \
sam_ba_serial.c
board_driver_led.c \
board_driver_serial.c \
board_driver_usb.c \
board_init.c \
board_startup.c \
main.c \
sam_ba_usb.c \
sam_ba_cdc.c \
sam_ba_monitor.c \
sam_ba_serial.c

OBJECTS=$(addprefix $(BUILD_PATH)/, $(SOURCES:.c=.o))
DEPS=$(addprefix $(BUILD_PATH)/, $(SOURCES:.c=.d))

NAME=samd21_sam_ba
ELF=$(NAME).elf
BIN=$(NAME).bin
HEX=$(NAME).hex

ifneq "test$(AVRSTUDIO_EXE_PATH)" "test"
AS_BUILD=copy_for_atmel_studio
AS_CLEAN=clean_for_atmel_studio
AS_BUILD=copy_for_atmel_studio
AS_CLEAN=clean_for_atmel_studio
else
AS_BUILD=
AS_CLEAN=
AS_BUILD=
AS_CLEAN=
endif


Expand Down
16 changes: 16 additions & 0 deletions bootloaders/zero/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,19 @@ Bootloader code will be located at 0x0 and executed before any applicative code.
Applications compiled to be executed along with the bootloader will start at 0x2000 (see linker script bootloader_samd21x18.ld).

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.

## 5- How to build

If not specified the makefile builds for **Arduino Zero**:

```
make
```

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`.
For example for the **Arduino MKR1000** we use `board_definitions_arduino_mkr1000.h` and it is build with the following command:

```
BOARD_ID=arduino_mkr1000 NAME=samd21_sam_ba_arduino_mkr1000 make clean all
```

68 changes: 16 additions & 52 deletions bootloaders/zero/board_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,20 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef _BOARD_DEFINITIONS_H_
#define _BOARD_DEFINITIONS_H_
#if defined(BOARD_ID_arduino_zero)
#include "board_definitions_arduino_zero.h"
#elif defined(BOARD_ID_genuino_zero)
#include "board_definitions_genuino_zero.h"
#elif defined(BOARD_ID_arduino_mkr1000)
#include "board_definitions_arduino_mkr1000.h"
#elif defined(BOARD_ID_genuino_mkr1000)
#include "board_definitions_genuino_mkr1000.h"
#else
#error You must define a BOARD_ID and add the corresponding definitions in board_definitions.h
#endif

// Common definitions
// ------------------

#define BOOT_PIN_MASK (1U << (BOOT_LOAD_PIN & 0x1f))

/*
* If BOOT_DOUBLE_TAP_ADDRESS is defined the bootloader is started by
* quickly tapping two times on the reset button.
* BOOT_DOUBLE_TAP_ADDRESS must point to a free SRAM cell that must not
* be touched from the loaded application.
*/
#define BOOT_DOUBLE_TAP_ADDRESS (0x20007FFCul)
#define BOOT_DOUBLE_TAP_DATA (*((volatile uint32_t *) BOOT_DOUBLE_TAP_ADDRESS))

/*
* If BOOT_LOAD_PIN is defined the bootloader is started if the selected
* pin is tied LOW.
*/
//#define BOOT_LOAD_PIN PIN_PA21 // Pin 7
//#define BOOT_LOAD_PIN PIN_PA15 // Pin 5
#define BOOT_PIN_MASK (1U << (BOOT_LOAD_PIN & 0x1f))

#define CPU_FREQUENCY (48000000ul)

#define BOOT_USART_MODULE SERCOM0
#define BOOT_USART_BUS_CLOCK_INDEX PM_APBCMASK_SERCOM0
#define BOOT_USART_PER_CLOCK_INDEX GCLK_ID_SERCOM0_CORE
#define BOOT_USART_PAD_SETTINGS UART_RX_PAD3_TX_PAD2
#define BOOT_USART_PAD3 PINMUX_PA11C_SERCOM0_PAD3
#define BOOT_USART_PAD2 PINMUX_PA10C_SERCOM0_PAD2
#define BOOT_USART_PAD1 PINMUX_UNUSED
#define BOOT_USART_PAD0 PINMUX_UNUSED

/* Frequency of the board main oscillator */
#define VARIANT_MAINOSC (32768ul)

/* Master clock frequency */
#define VARIANT_MCK CPU_FREQUENCY

#define NVM_SW_CALIB_DFLL48M_COARSE_VAL (58)
#define NVM_SW_CALIB_DFLL48M_FINE_VAL (64)

/*
* LEDs definitions
*/
#define BOARD_LED_PORT (0)
#define BOARD_LED_PIN (17)

#define BOARD_LEDRX_PORT (1)
#define BOARD_LEDRX_PIN (3)

#define BOARD_LEDTX_PORT (0)
#define BOARD_LEDTX_PIN (27)

#endif // _BOARD_DEFINITIONS_H_
82 changes: 82 additions & 0 deletions bootloaders/zero/board_definitions_arduino_mkr1000.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
Copyright (c) 2015 Arduino LLC. All right reserved.
Copyright (c) 2015 Atmel Corporation/Thibaut VIARD. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef _BOARD_DEFINITIONS_H_
#define _BOARD_DEFINITIONS_H_

/*
* USB device definitions
*/
#define STRING_PRODUCT "Arduino MKR1000"
#define USB_VID_HIGH 0x23
#define USB_VID_LOW 0x41
#define USB_PID_HIGH 0x00
#define USB_PID_LOW 0x4E

/*
* If BOOT_DOUBLE_TAP_ADDRESS is defined the bootloader is started by
* quickly tapping two times on the reset button.
* BOOT_DOUBLE_TAP_ADDRESS must point to a free SRAM cell that must not
* be touched from the loaded application.
*/
#define BOOT_DOUBLE_TAP_ADDRESS (0x20007FFCul)
#define BOOT_DOUBLE_TAP_DATA (*((volatile uint32_t *) BOOT_DOUBLE_TAP_ADDRESS))

/*
* If BOOT_LOAD_PIN is defined the bootloader is started if the selected
* pin is tied LOW.
*/
//#define BOOT_LOAD_PIN PIN_PA21 // Pin 7
//#define BOOT_LOAD_PIN PIN_PA15 // Pin 5

#define BOOT_USART_MODULE SERCOM0
#define BOOT_USART_BUS_CLOCK_INDEX PM_APBCMASK_SERCOM0
#define BOOT_USART_PER_CLOCK_INDEX GCLK_ID_SERCOM0_CORE
#define BOOT_USART_PAD_SETTINGS UART_RX_PAD3_TX_PAD2
#define BOOT_USART_PAD3 PINMUX_PA11C_SERCOM0_PAD3
#define BOOT_USART_PAD2 PINMUX_PA10C_SERCOM0_PAD2
#define BOOT_USART_PAD1 PINMUX_UNUSED
#define BOOT_USART_PAD0 PINMUX_UNUSED

/* Master clock frequency */
#define CPU_FREQUENCY (48000000ul)
#define VARIANT_MCK CPU_FREQUENCY

/* Frequency of the board main oscillator */
#define VARIANT_MAINOSC (32768ul)

/* Calibration values for DFLL48 pll */
#define NVM_SW_CALIB_DFLL48M_COARSE_VAL (58)
#define NVM_SW_CALIB_DFLL48M_FINE_VAL (64)

/*
* LEDs definitions
*/
// PA20 (digital pin 6)
#define BOARD_LED_PORT (0)
#define BOARD_LED_PIN (20)

// No RX/TX led
//#define BOARD_LEDRX_PORT
//#define BOARD_LEDRX_PIN

//#define BOARD_LEDTX_PORT
//#define BOARD_LEDTX_PIN

#endif // _BOARD_DEFINITIONS_H_
81 changes: 81 additions & 0 deletions bootloaders/zero/board_definitions_arduino_zero.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
Copyright (c) 2015 Arduino LLC. All right reserved.
Copyright (c) 2015 Atmel Corporation/Thibaut VIARD. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef _BOARD_DEFINITIONS_H_
#define _BOARD_DEFINITIONS_H_

/*
* USB device definitions
*/
#define STRING_PRODUCT "Arduino Zero"
#define USB_VID_HIGH 0x23
#define USB_VID_LOW 0x41
#define USB_PID_HIGH 0x00
#define USB_PID_LOW 0x4D

/*
* If BOOT_DOUBLE_TAP_ADDRESS is defined the bootloader is started by
* quickly tapping two times on the reset button.
* BOOT_DOUBLE_TAP_ADDRESS must point to a free SRAM cell that must not
* be touched from the loaded application.
*/
#define BOOT_DOUBLE_TAP_ADDRESS (0x20007FFCul)
#define BOOT_DOUBLE_TAP_DATA (*((volatile uint32_t *) BOOT_DOUBLE_TAP_ADDRESS))

/*
* If BOOT_LOAD_PIN is defined the bootloader is started if the selected
* pin is tied LOW.
*/
//#define BOOT_LOAD_PIN PIN_PA21 // Pin 7
//#define BOOT_LOAD_PIN PIN_PA15 // Pin 5

#define BOOT_USART_MODULE SERCOM0
#define BOOT_USART_BUS_CLOCK_INDEX PM_APBCMASK_SERCOM0
#define BOOT_USART_PER_CLOCK_INDEX GCLK_ID_SERCOM0_CORE
#define BOOT_USART_PAD_SETTINGS UART_RX_PAD3_TX_PAD2
#define BOOT_USART_PAD3 PINMUX_PA11C_SERCOM0_PAD3
#define BOOT_USART_PAD2 PINMUX_PA10C_SERCOM0_PAD2
#define BOOT_USART_PAD1 PINMUX_UNUSED
#define BOOT_USART_PAD0 PINMUX_UNUSED


/* Master clock frequency */
#define CPU_FREQUENCY (48000000ul)
#define VARIANT_MCK CPU_FREQUENCY

/* Frequency of the board main oscillator */
#define VARIANT_MAINOSC (32768ul)

/* Calibration values for DFLL48 pll */
#define NVM_SW_CALIB_DFLL48M_COARSE_VAL (58)
#define NVM_SW_CALIB_DFLL48M_FINE_VAL (64)

/*
* LEDs definitions
*/
#define BOARD_LED_PORT (0)
#define BOARD_LED_PIN (17)

#define BOARD_LEDRX_PORT (1)
#define BOARD_LEDRX_PIN (3)

#define BOARD_LEDTX_PORT (0)
#define BOARD_LEDTX_PIN (27)

#endif // _BOARD_DEFINITIONS_H_
Loading