Skip to content

Commit 891779c

Browse files
committed
[bl] first pass rework, work in progress
1 parent 0f4b0d8 commit 891779c

Some content is hidden

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

41 files changed

+2869
-5123
lines changed

bootloaders/zero/Makefile

Lines changed: 149 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,159 @@
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 Arduino LLC. All right reserved.
2+
#
3+
# This library is free software; you can redistribute it and/or
4+
# modify it under the terms of the GNU Lesser General Public
5+
# License as published by the Free Software Foundation; either
6+
# version 2.1 of the License, or (at your option) any later version.
7+
#
8+
# This library is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11+
# See the GNU Lesser General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU Lesser General Public
14+
# License along with this library; if not, write to the Free Software
15+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16+
17+
# -----------------------------------------------------------------------------
18+
# Paths
19+
ifeq ($(OS),Windows_NT)
20+
21+
# Are we using mingw/msys/msys2/cygwin?
22+
ifeq ($(TERM),xterm)
23+
# T=$(shell cygpath -u $(LOCALAPPDATA))
24+
T=$(shell cygpath -u $(APPDATA))
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+
MODULE_PATH?=$(APPDATA)/Arduino15/packages/arduino
32+
ARM_GCC_PATH?=$(MODULE_PATH)/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-
33+
RM=rm
34+
SEP=\\
35+
endif
36+
else
37+
UNAME_S := $(shell uname -s)
38+
39+
ifeq ($(UNAME_S),Linux)
40+
MODULE_PATH?=$HOME/.arduino15/packages/arduino
41+
ARM_GCC_PATH?=$(MODULE_PATH)/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-
42+
RM=rm
43+
SEP=/
44+
endif
45+
46+
ifeq ($(UNAME_S),Darwin)
47+
MODULE_PATH?=$HOME/Library/Arduino15/packages/arduino/
48+
ARM_GCC_PATH?=$(MODULE_PATH)/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-
49+
RM=rm
50+
SEP=/
51+
endif
52+
endif
53+
754
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
55+
56+
# -----------------------------------------------------------------------------
57+
# Tools
58+
CC=$(ARM_GCC_PATH)gcc
59+
OBJCOPY=$(ARM_GCC_PATH)objcopy
60+
NM=$(ARM_GCC_PATH)nm
61+
SIZE=$(ARM_GCC_PATH)size
62+
63+
# -----------------------------------------------------------------------------
64+
# Compiler options
65+
#-w
66+
CFLAGS=-mthumb -mcpu=cortex-m0plus -Wall -c -std=gnu99 -ffunction-sections -fdata-sections -nostdlib -nostartfiles --param max-inline-insns-single=500
67+
ifdef DEBUG
68+
CFLAGS+=-g3 -O1
69+
else
70+
CFLAGS+=-Os
71+
endif
72+
#CFLAGS_EXTRA?=-D__SAMD21G18A__ -DUSB_PID_LOW=0x4D -DUSB_PID_HIGH=0x00
73+
CFLAGS_EXTRA?=-D__SAMD21J18A__ -DUSB_PID_LOW=0x01 -DUSB_PID_HIGH=0xE0
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+
cdc_enumerate.c \
90+
main.c \
91+
sam_ba_cdc.c \
92+
sam_ba_led.c \
93+
sam_ba_monitor.c \
94+
sam_ba_serial.c
95+
96+
1097
OBJECTS=$(addprefix $(BUILD_PATH)/, $(SOURCES:.c=.o))
98+
DEPS=$(addprefix $(BUILD_PATH)/, $(SOURCES:.c=.d))
1199

12100
NAME=samd21_sam_ba
101+
ELF=$(NAME).elf
13102
EXECUTABLE=$(NAME).bin
14103

15-
SLASH=/
16-
BSLASH=$(EMPTY)\$(EMPTY)
104+
ifneq "test$(AVRSTUDIO_EXE_PATH)" "test"
105+
AS=copy_for_atmel_studio
106+
else
107+
AS=
108+
endif
109+
110+
111+
all: print_info $(SOURCES) $(EXECUTABLE) $(AS)
17112

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 $@
113+
$(ELF): Makefile $(BUILD_PATH) $(OBJECTS)
114+
@echo ----------------------------------------------------------
115+
@echo Creating ELF binary
116+
"$(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
117+
"$(NM)" "$(BUILD_PATH)/$(ELF)" >"$(BUILD_PATH)/$(NAME)_symbols.txt"
118+
"$(SIZE)" --format=sysv -t -x $(BUILD_PATH)/$(ELF)
119+
120+
$(EXECUTABLE): $(ELF)
121+
@echo ----------------------------------------------------------
122+
@echo Creating flash binary
123+
"$(OBJCOPY)" -O binary $(BUILD_PATH)/$< $@
23124

24125
$(BUILD_PATH)/%.o: %.c
25-
-@mkdir -p $(@D)
26-
$(CC) $(CFLAGS) $(BLD_EXTA_FLAGS) $(INCLUDES) $< -o $@
27-
126+
@echo ----------------------------------------------------------
127+
@echo Compiling $< to $@
128+
"$(CC)" $(CFLAGS) $(CFLAGS_EXTRA) $(INCLUDES) $< -o $@
129+
@echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
130+
131+
$(BUILD_PATH):
132+
@echo ----------------------------------------------------------
133+
@echo Creating build folder
134+
-mkdir $(BUILD_PATH)
135+
136+
print_info:
137+
@echo ----------------------------------------------------------
138+
@echo Compiling bootloader using
139+
@echo BASE PATH = $(MODULE_PATH)
140+
@echo GCC PATH = $(ARM_GCC_PATH)
141+
@echo OS = $(OS)
142+
@echo SHELL = $(SHELL)
143+
@echo TERM = $(TERM)
144+
# "$(CC)" -v
145+
# env
146+
147+
copy_for_atmel_studio: $(EXECUTABLE)
148+
@echo ----------------------------------------------------------
149+
@echo Atmel Studio detected, copying ELF to project root for debug
150+
cp $(BUILD_PATH)/$(ELF) .
151+
28152
clean:
29-
del $(EXECUTABLE) $(subst /,\,$(OBJECTS)) $(subst /,\,$(BUILD_PATH)/$(NAME).*)
153+
@echo ----------------------------------------------------------
154+
@echo Cleaning project
155+
-$(RM) $(EXECUTABLE)
156+
-$(RM) $(BUILD_PATH)/*.*
157+
-rmdir $(BUILD_PATH)
158+
159+
.phony: clean print_info $(BUILD_PATH)
File renamed without changes.

bootloaders/zero/board_definitions.h

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

bootloaders/zero/board_driver_led.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "board_driver_led.h"
2+
3+

bootloaders/zero/board_driver_led.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef _BOARD_DRIVER_LED_
2+
#define _BOARD_DRIVER_LED_
3+
4+
#include <sam.h>
5+
#include "board_definitions.h"
6+
7+
inline void LED_init(void) { PORT->Group[BOARD_LED_PORT].DIRSET.reg = (1<<BOARD_LED_PIN); }
8+
inline void LED_on(void) { PORT->Group[BOARD_LED_PORT].OUTSET.reg = (1<<BOARD_LED_PIN); }
9+
inline void LED_off(void) { PORT->Group[BOARD_LED_PORT].OUTCLR.reg = (1<<BOARD_LED_PIN); }
10+
inline void LED_toggle(void) { PORT->Group[BOARD_LED_PORT].OUTTGL.reg = (1<<BOARD_LED_PIN); }
11+
12+
inline void LEDRX_init(void) { PORT->Group[BOARD_LEDRX_PORT].DIRSET.reg = (1<<BOARD_LEDRX_PIN); }
13+
inline void LEDRX_on(void) { PORT->Group[BOARD_LEDRX_PORT].OUTSET.reg = (1<<BOARD_LEDRX_PIN); }
14+
inline void LEDRX_off(void) { PORT->Group[BOARD_LEDRX_PORT].OUTCLR.reg = (1<<BOARD_LEDRX_PIN); }
15+
inline void LEDRX_toggle(void) { PORT->Group[BOARD_LEDRX_PORT].OUTTGL.reg = (1<<BOARD_LEDRX_PIN); }
16+
17+
inline void LEDTX_init(void) { PORT->Group[BOARD_LEDTX_PORT].DIRSET.reg = (1<<BOARD_LEDTX_PIN); }
18+
inline void LEDTX_on(void) { PORT->Group[BOARD_LEDTX_PORT].OUTSET.reg = (1<<BOARD_LEDTX_PIN); }
19+
inline void LEDTX_off(void) { PORT->Group[BOARD_LEDTX_PORT].OUTCLR.reg = (1<<BOARD_LEDTX_PIN); }
20+
inline void LEDTX_toggle(void) { PORT->Group[BOARD_LEDTX_PORT].OUTTGL.reg = (1<<BOARD_LEDTX_PIN); }
21+
22+
#endif // _BOARD_DRIVER_LED_

bootloaders/zero/drivers/uart_driver.c renamed to bootloaders/zero/board_driver_serial.c

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,24 @@
1-
/* ----------------------------------------------------------------------------
2-
* SAM Software Package License
3-
* ----------------------------------------------------------------------------
4-
* Copyright (c) 2011-2012, Atmel Corporation
5-
*
6-
* All rights reserved.
7-
*
8-
* Redistribution and use in source and binary forms, with or without
9-
* modification, are permitted provided that the following condition is met:
10-
*
11-
* Redistributions of source code must retain the above copyright notice,
12-
* this list of conditions and the disclaimer below.
13-
*
14-
* Atmel's name may not be used to endorse or promote products derived from
15-
* this software without specific prior written permission.
16-
*
17-
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18-
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19-
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20-
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21-
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22-
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23-
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24-
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25-
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26-
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27-
* ----------------------------------------------------------------------------
28-
*/
1+
/*
2+
Copyright (c) 2015 Arduino LLC. All right reserved.
293
30-
#include "uart_driver.h"
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.
318
32-
bool uart_drv_error_flag = false;
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.
3313
34-
uint32_t uart_get_sercom_index(Sercom *sercom_instance)
35-
{
36-
/* Save all available SERCOM instances for compare. */
37-
Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS;
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+
*/
3818

39-
/* Find index for sercom instance. */
40-
for (uint32_t i = 0; i < SERCOM_INST_NUM; i++) {
41-
if ((uintptr_t)sercom_instance == (uintptr_t)sercom_instances[i]) {
42-
return i;
43-
}
44-
}
19+
#include "board_driver_serial.h"
4520

46-
return 0;
47-
}
21+
bool uart_drv_error_flag = false;
4822

4923
void uart_basic_init(Sercom *sercom, uint16_t baud_val, enum uart_pad_settings pad_conf)
5024
{
@@ -126,4 +100,4 @@ void uart_read_buffer_polled(Sercom *sercom, uint8_t *ptr, uint16_t length)
126100
/* Store the read data to the buffer */
127101
*ptr++ = (uint8_t)sercom->USART.DATA.reg;
128102
} while (length--);
129-
}
103+
}

0 commit comments

Comments
 (0)