Skip to content

Commit 8d3260d

Browse files
committed
Bootloader makefile has been refactored for easier customization
1 parent 36d1c72 commit 8d3260d

9 files changed

+370
-82
lines changed

Diff for: bootloaders/zero/Makefile

+8-20
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,23 @@ OBJCOPY=$(ARM_GCC_PATH)objcopy
5555
NM=$(ARM_GCC_PATH)nm
5656
SIZE=$(ARM_GCC_PATH)size
5757

58+
# -----------------------------------------------------------------------------
59+
# Boards definitions
60+
BOARD_ID?=arduino_zero
61+
5862
# -----------------------------------------------------------------------------
5963
# Compiler options
64+
CFLAGS_EXTRA=-D__SAMD21G18A__ -DBOARD_ID_$(BOARD_ID)
6065
CFLAGS=-mthumb -mcpu=cortex-m0plus -Wall -c -std=gnu99 -ffunction-sections -fdata-sections -nostdlib -nostartfiles --param max-inline-insns-single=500
6166
ifdef DEBUG
6267
CFLAGS+=-g3 -O1 -DDEBUG=1
6368
else
6469
CFLAGS+=-Os -DDEBUG=0
6570
endif
6671

67-
ifeq ($(GENUINO),)
68-
# Arduino Zero (PID == 0x004D)
69-
CFLAGS_EXTRA?=-D__SAMD21G18A__ -DUSB_PID_HIGH=0x00 -DUSB_PID_LOW=0x4D -DUSB_VID_LOW=0x41 -DUSB_VID_HIGH=0x23
70-
# Arduino MKR1000 (PID == 0x004E)
71-
# CFLAGS_EXTRA?=-D__SAMD21G18A__ -DUSB_PID_HIGH=0x00 -DUSB_PID_LOW=0x4E -DUSB_VID_LOW=0x41 -DUSB_VID_HIGH=0x23 -DSTRING_PRODUCT="\"Arduino MKR1000\""
72-
else
73-
# Genuino Zero (PID == 0x024D)
74-
CFLAGS_EXTRA?=-D__SAMD21G18A__ -DUSB_PID_HIGH=0x02 -DUSB_PID_LOW=0x4D -DUSB_VID_LOW=0x41 -DUSB_VID_HIGH=0x23 -DSTRING_PRODUCT="\"Genuino Zero\""
75-
# Genuino MKR1000 (PID == 0x024E)
76-
# CFLAGS_EXTRA?=-D__SAMD21G18A__ -DUSB_PID_HIGH=0x02 -DUSB_PID_LOW=0x4E -DUSB_VID_LOW=0x41 -DUSB_VID_HIGH=0x23 -DSTRING_PRODUCT="\"Genuino MKR1000\""
77-
endif
72+
ELF=$(NAME).elf
73+
BIN=$(NAME).bin
74+
HEX=$(NAME).hex
7875

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

@@ -100,15 +97,6 @@ SOURCES= \
10097
OBJECTS=$(addprefix $(BUILD_PATH)/, $(SOURCES:.c=.o))
10198
DEPS=$(addprefix $(BUILD_PATH)/, $(SOURCES:.c=.d))
10299

103-
ifeq ($(GENUINO),)
104-
NAME=samd21_sam_ba
105-
else
106-
NAME=samd21_sam_ba_genuino
107-
endif
108-
ELF=$(NAME).elf
109-
BIN=$(NAME).bin
110-
HEX=$(NAME).hex
111-
112100
ifneq "test$(AVRSTUDIO_EXE_PATH)" "test"
113101
AS_BUILD=copy_for_atmel_studio
114102
AS_CLEAN=clean_for_atmel_studio

Diff for: bootloaders/zero/README.md

+4-10
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,16 @@ Before jumping to the application, the bootloader changes the VTOR register to u
8080

8181
## 5- How to build
8282

83-
**Arduino Zero**
83+
If not specified the makefile builds for **Arduino Zero**:
8484

8585
```
8686
make
8787
```
8888

89-
**Genuino Zero**
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:
9091

9192
```
92-
make GENUINO=1
93+
BOARD_ID=arduino_mkr1000 NAME=samd21_sam_ba_arduino_mkr1000 make clean all
9394
```
9495

95-
**Others (derivatives)**
96-
97-
```
98-
make CFLAGS_EXTRA="-D__SAMD21G18A__ -DUSB_PID_HIGH=<your USB PID> -DUSB_PID_LOW=<your USB PID> -DUSB_VID_LOW=<your USB VID> -DUSB_VID_HIGH=<your USB VID>"
99-
```
100-
101-
You can also check https://github.com/ameltech/sme-arduino-core/blob/master/hardware/AMEL/samd/bootloaders/sme/Makefile for reference.

Diff for: bootloaders/zero/board_definitions.h

+16-52
Original file line numberDiff line numberDiff line change
@@ -17,56 +17,20 @@
1717
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1818
*/
1919

20-
#ifndef _BOARD_DEFINITIONS_H_
21-
#define _BOARD_DEFINITIONS_H_
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+
#else
29+
#error You must define a BOARD_ID and add the corresponding definitions in board_definitions.h
30+
#endif
31+
32+
// Common definitions
33+
// ------------------
34+
35+
#define BOOT_PIN_MASK (1U << (BOOT_LOAD_PIN & 0x1f))
2236

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_

Diff for: bootloaders/zero/board_definitions_arduino_mkr1000.h

+82
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_ID_SERCOM0_CORE
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_

Diff for: bootloaders/zero/board_definitions_arduino_zero.h

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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 Zero"
27+
#define USB_VID_HIGH 0x23
28+
#define USB_VID_LOW 0x41
29+
#define USB_PID_HIGH 0x00
30+
#define USB_PID_LOW 0x4D
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_ID_SERCOM0_CORE
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+
58+
/* Master clock frequency */
59+
#define CPU_FREQUENCY (48000000ul)
60+
#define VARIANT_MCK CPU_FREQUENCY
61+
62+
/* Frequency of the board main oscillator */
63+
#define VARIANT_MAINOSC (32768ul)
64+
65+
/* Calibration values for DFLL48 pll */
66+
#define NVM_SW_CALIB_DFLL48M_COARSE_VAL (58)
67+
#define NVM_SW_CALIB_DFLL48M_FINE_VAL (64)
68+
69+
/*
70+
* LEDs definitions
71+
*/
72+
#define BOARD_LED_PORT (0)
73+
#define BOARD_LED_PIN (17)
74+
75+
#define BOARD_LEDRX_PORT (1)
76+
#define BOARD_LEDRX_PIN (3)
77+
78+
#define BOARD_LEDTX_PORT (0)
79+
#define BOARD_LEDTX_PIN (27)
80+
81+
#endif // _BOARD_DEFINITIONS_H_

Diff for: bootloaders/zero/board_definitions_genuino_mkr1000.h

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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 "Genuino MKR1000"
27+
#define USB_VID_HIGH 0x23
28+
#define USB_VID_LOW 0x41
29+
#define USB_PID_HIGH 0x02
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_ID_SERCOM0_CORE
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+
58+
/* Master clock frequency */
59+
#define CPU_FREQUENCY (48000000ul)
60+
#define VARIANT_MCK CPU_FREQUENCY
61+
62+
/* Frequency of the board main oscillator */
63+
#define VARIANT_MAINOSC (32768ul)
64+
65+
/* Calibration values for DFLL48 pll */
66+
#define NVM_SW_CALIB_DFLL48M_COARSE_VAL (58)
67+
#define NVM_SW_CALIB_DFLL48M_FINE_VAL (64)
68+
69+
/*
70+
* LEDs definitions
71+
*/
72+
// PA20 (digital pin 6)
73+
#define BOARD_LED_PORT (0)
74+
#define BOARD_LED_PIN (20)
75+
76+
// No RX/TX led
77+
//#define BOARD_LEDRX_PORT
78+
//#define BOARD_LEDRX_PIN
79+
80+
//#define BOARD_LEDTX_PORT
81+
//#define BOARD_LEDTX_PIN
82+
83+
#endif // _BOARD_DEFINITIONS_H_

0 commit comments

Comments
 (0)