Skip to content
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

add BOOT_LOAD_PIN, update BL from SRAM and Jeff Probe Board #203

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
26 changes: 21 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ WFLAGS = \
-Wno-deprecated-declarations -Wpacked -Wredundant-decls -Wnested-externs \
-Wlong-long -Wunreachable-code -Wcast-align \
-Wno-missing-braces -Wno-overflow -Wno-shadow -Wno-attributes -Wno-packed -Wno-pointer-sign
CFLAGS = $(COMMON_FLAGS) \
CFLAGS += $(COMMON_FLAGS) \
-x c -c -pipe -nostdlib \
--param max-inline-insns-single=500 \
-fno-strict-aliasing -fdata-sections -ffunction-sections \
Expand All @@ -29,9 +29,25 @@ $(WFLAGS)
UF2_VERSION_BASE = $(shell git describe --dirty --always --tags)

ifeq ($(CHIP_FAMILY), samd21)
LINKER_SCRIPT=scripts/samd21j18a.ld
BOOTLOADER_SIZE=8192
SELF_LINKER_SCRIPT=scripts/samd21j18a_self.ld
BOOTLOADER_SIZE = 8192
SRAM_BASE_ADDR = 0x20000000
ifeq ($(USE_SRAM_BL_FLASH),1)
CFLAGS += -DSRAM_BASE_ADDR=$(SRAM_BASE_ADDR) -DSRAM_BL_SIZE=0x2800
ifdef CONV_SRAM_BL
CFLAGS += -DUSE_STD_FLASH_BL
UPDATE_BL_OFST = $(BOOTLOADER_SIZE)
SELF_LINKER_SCRIPT = scripts/samd21j17a_self_conv_bl.ld
else
UPDATE_BL_OFST = $(SRAM_BASE_ADDR)
SELF_LINKER_SCRIPT = scripts/samd21j17a_self_sram_bl.ld
endif
LINKER_SCRIPT = scripts/samd21j17a_sram_bl.ld
else

UPDATE_BL_OFST = $(BOOTLOADER_SIZE)
LINKER_SCRIPT = scripts/samd21j18a.ld
SELF_LINKER_SCRIPT = scripts/samd21j18a_self.ld
endif
endif

ifeq ($(CHIP_FAMILY), samd51)
Expand Down Expand Up @@ -174,7 +190,7 @@ $(SELF_EXECUTABLE): $(SELF_OBJECTS)
-T$(SELF_LINKER_SCRIPT) \
-Wl,-Map,$(BUILD_PATH)/update-$(NAME).map -o $(BUILD_PATH)/update-$(NAME).elf $(SELF_OBJECTS)
arm-none-eabi-objcopy -O binary $(BUILD_PATH)/update-$(NAME).elf $(BUILD_PATH)/update-$(NAME).bin
python3 lib/uf2/utils/uf2conv.py -b $(BOOTLOADER_SIZE) -c -o $@ $(BUILD_PATH)/update-$(NAME).bin
python3 lib/uf2/utils/uf2conv.py -b $(UPDATE_BL_OFST) -c -o $@ $(BUILD_PATH)/update-$(NAME).bin

$(BUILD_PATH)/%.o: src/%.c $(wildcard inc/*.h boards/*/*.h) $(BUILD_PATH)/uf2_version.h
echo "$<"
Expand Down
6 changes: 6 additions & 0 deletions boards/jeff_probe/board.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CHIP_FAMILY = samd21
CHIP_VARIANT = SAMD21E17A

USE_SRAM_BL_FLASH = 1
#CONV_SRAM_BL = 1
CFLAGS += -DCRYSTALLESS
20 changes: 20 additions & 0 deletions boards/jeff_probe/board_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef BOARD_CONFIG_H
#define BOARD_CONFIG_H

#define VENDOR_NAME "Flirc"
#define PRODUCT_NAME "Jeff Probe"
#define VOLUME_LABEL "JEFF_BOOT"
#define INDEX_URL "https://flirc.tv/products/flirc-jeffprobe"
#define BOARD_ID "SAMD21E17A-Jeff_Probe"

#define USB_VID 0x1d50
#define USB_PID 0x6017

#define LED_PIN PIN_PA10

#define BOOT_LOAD_PIN PIN_PA27

// This is needed because SAMD21E17A only has 128kB of flash
#define FLASH_NUM_ROWS 512

#endif
8 changes: 7 additions & 1 deletion inc/uf2.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
#define COLOR_START 0x000040
#define COLOR_USB 0x004000
#define COLOR_UART 0x404000
#define COLOR_LEAVE 0x400040
#define COLOR_LEAVE 0x000000
#endif

/*
Expand Down Expand Up @@ -248,6 +248,7 @@ void padded_memcpy(char *dst, const char *src, int len);
#endif
#define DBL_TAP_MAGIC 0xf01669ef // Randomly selected, adjusted to have first and last bit set
#define DBL_TAP_MAGIC_QUICK_BOOT 0xf02669ef
#define DBL_TAP_MAGIC_SRAM_BL 0xf03669ef

#if USE_SINGLE_RESET
#ifdef SAMD21
Expand Down Expand Up @@ -321,6 +322,11 @@ void RGBLED_set_color(uint32_t color);
#define LED_RX_TGL()
#endif

// For BOOT_LOAD_PIN
#if defined(BOOT_LOAD_PIN)
#define BOOT_PIN_MASK (1U << (BOOT_LOAD_PIN & 0x1f))
#endif

extern uint32_t timerHigh, resetHorizon;
void timerTick(void);
void delay(uint32_t ms);
Expand Down
160 changes: 160 additions & 0 deletions scripts/samd21j17a_self_conv_bl.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/**
* \file
*
* \brief Linker script for running in internal FLASH on the SAMD21J18A
*
* Copyright (c) 2014-2015 Atmel Corporation. All rights reserved.
*
* \asf_license_start
*
* \page License
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name of Atmel may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 4. This software may only be redistributed and used in connection with an
* Atmel microcontroller product.
*
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* \asf_license_stop
*
*/


OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
SEARCH_DIR(.)

/* Memory Spaces Definitions */
MEMORY
{
rom (rx) : ORIGIN = 0x00002000, LENGTH = 128k -8k
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 16k
}

/* The stack size used by the application. NOTE: you need to adjust according to your application. */
STACK_SIZE = DEFINED(STACK_SIZE) ? STACK_SIZE : DEFINED(__stack_size__) ? __stack_size__ : 0x1000;

/* Section Definitions */
SECTIONS
{
.text :
{
. = ALIGN(4);
_sfixed = .;
KEEP(*(.vectors .vectors.*))
*(.text .text.* .gnu.linkonce.t.*)
*(.glue_7t) *(.glue_7)
*(.rodata .rodata* .gnu.linkonce.r.*)
*(.ARM.extab* .gnu.linkonce.armextab.*)

/* Support C constructors, and C destructors in both user code
and the C library. This also provides support for C++ code. */
. = ALIGN(4);
KEEP(*(.init))
. = ALIGN(4);
__preinit_array_start = .;
KEEP (*(.preinit_array))
__preinit_array_end = .;

. = ALIGN(4);
__init_array_start = .;
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array))
__init_array_end = .;

. = ALIGN(4);
KEEP (*crtbegin.o(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*crtend.o(.ctors))

/*

. = ALIGN(4);
KEEP(*(.fini))

. = ALIGN(4);
__fini_array_start = .;
KEEP (*(.fini_array))
KEEP (*(SORT(.fini_array.*)))
__fini_array_end = .;

KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*crtend.o(.dtors))
*/

. = ALIGN(4);
_efixed = .; /* End of text section */
} > rom

/* .ARM.exidx is sorted, so has to go in its own output section. */
PROVIDE_HIDDEN (__exidx_start = .);
.ARM.exidx :
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > rom
PROVIDE_HIDDEN (__exidx_end = .);

. = ALIGN(4);
_etext = .;

.relocate : AT (_etext)
{
. = ALIGN(4);
_srelocate = .;
*(.ramfunc .ramfunc.*);
*(.data .data.*);
. = ALIGN(4);
_erelocate = .;
} > ram

/* .bss section which is used for uninitialized data */
.bss (NOLOAD) :
{
. = ALIGN(4);
_sbss = . ;
_szero = .;
*(.bss .bss.*)
*(COMMON)
. = ALIGN(4);
_ebss = . ;
_ezero = .;
} > ram

/* stack section */
.stack (NOLOAD):
{
. = ALIGN(8);
_sstack = .;
. = . + STACK_SIZE;
. = ALIGN(8);
_estack = .;
} > ram

. = ALIGN(4);
_end = . ;
}
Loading