Added bootloader support and some minor fixes

This commit is contained in:
Alex Taradov 2021-03-19 17:40:57 -07:00
parent f7987af284
commit b96db1578c
7 changed files with 195 additions and 7 deletions

View File

@ -48,6 +48,8 @@
#error Undefined board
#endif
HAL_GPIO_PIN(BOOT_ENTER, A, 31);
#define APP_EP_SEND 1
#define APP_EP_RECV 2
@ -166,12 +168,19 @@ void usb_configuration_callback(int config)
//-----------------------------------------------------------------------------
int main(void)
{
HAL_GPIO_BOOT_ENTER_in();
HAL_GPIO_BOOT_ENTER_pullup();
sys_init();
led_init();
dap_init();
usb_init();
while (1);
while (1)
{
if (0 == HAL_GPIO_BOOT_ENTER_read())
NVIC_SystemReset();
}
return 0;
}

View File

@ -0,0 +1,82 @@
/*
* Copyright (c) 2016-2017, Alex Taradov <alex@taradov.com>
* All rights reserved.
*
* 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 the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 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.
*/
MEMORY
{
flash (rx) : ORIGIN = 0x00001000, LENGTH = 0x3000
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x1000
}
__top_flash = ORIGIN(flash) + LENGTH(flash);
__top_ram = ORIGIN(ram) + LENGTH(ram);
ENTRY(irq_handler_reset)
SECTIONS
{
.text : ALIGN(4)
{
FILL(0xff)
KEEP(*(.vectors))
*(.text*)
*(.rodata)
*(.rodata.*)
. = ALIGN(4);
} > flash
. = ALIGN(4);
_etext = .;
.uninit_RESERVED : ALIGN(4)
{
KEEP(*(.bss.$RESERVED*))
} > ram
.data : ALIGN(4)
{
FILL(0xff)
_data = .;
*(.ramfunc .ramfunc.*);
*(vtable)
*(.data*)
. = ALIGN(4);
_edata = .;
} > ram AT > flash
.bss : ALIGN(4)
{
_bss = .;
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .;
PROVIDE(_end = .);
} > ram
PROVIDE(_stack_top = __top_ram - 0);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Alex Taradov <alex@taradov.com>
* Copyright (c) 2016-2017, Alex Taradov <alex@taradov.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -80,4 +80,3 @@ SECTIONS
PROVIDE(_stack_top = __top_ram - 0);
}

View File

@ -47,6 +47,7 @@
HAL_GPIO_PIN(VCP_STATUS, A, 2);
HAL_GPIO_PIN(DAP_STATUS, A, 4);
HAL_GPIO_PIN(BOOT_ENTER, A, 31);
/*- Variables ---------------------------------------------------------------*/
static alignas(4) uint8_t app_request_buffer[DAP_CONFIG_PACKET_SIZE];
@ -177,6 +178,7 @@ void usb_cdc_control_line_state_update(int line_state)
// TODO: actually open/close the port?
app_vcp_open = status;
app_send_buffer_ptr = 0;
}
//-----------------------------------------------------------------------------
@ -258,7 +260,7 @@ bool usb_class_handle_request(usb_request_t *request)
return true;
else if (usb_hid_handle_request(request))
return true;
else
else
return false;
}
@ -302,6 +304,9 @@ int main(void)
HAL_GPIO_DAP_STATUS_out();
HAL_GPIO_DAP_STATUS_set();
HAL_GPIO_BOOT_ENTER_in();
HAL_GPIO_BOOT_ENTER_pullup();
while (1)
{
sys_time_task();
@ -310,6 +315,9 @@ int main(void)
rx_task();
uart_timer_task();
status_timer_task();
if (0 == HAL_GPIO_BOOT_ENTER_read())
NVIC_SystemReset();
}
return 0;

View File

@ -1,6 +1,6 @@
##############################################################################
BUILD = build
BIN = free_dap_d11_vcp
BIN = free_dap_d11_vcp_bl
##############################################################################
.PHONY: all directory clean size
@ -24,7 +24,7 @@ CFLAGS += -MD -MP -MT $(BUILD)/$(*F).o -MF $(BUILD)/$(@F).d
LDFLAGS += -mcpu=cortex-m0plus -mthumb
LDFLAGS += -Wl,--gc-sections
LDFLAGS += -Wl,--script=../linker/samd11d14.ld
LDFLAGS += -Wl,--script=../linker/samd11d14_bl.ld
INCLUDES += \
-I../include \
@ -45,7 +45,7 @@ SRCS += \
DEFINES += \
-D__SAMD11C14A__ \
-DDONT_USE_CMSIS_INIT \
-DF_CPU=48000000
-DF_CPU=48000000
CFLAGS += $(INCLUDES) $(DEFINES)

View File

@ -0,0 +1,84 @@
##############################################################################
BUILD = build
BIN = free_dap_d11_vcp_std
##############################################################################
.PHONY: all directory clean size
CC = arm-none-eabi-gcc
OBJCOPY = arm-none-eabi-objcopy
SIZE = arm-none-eabi-size
ifeq ($(OS), Windows_NT)
MKDIR = gmkdir
else
MKDIR = mkdir
endif
CFLAGS += -W -Wall --std=gnu11 -Os
CFLAGS += -fno-diagnostics-show-caret
CFLAGS += -fdata-sections -ffunction-sections
CFLAGS += -funsigned-char -funsigned-bitfields
CFLAGS += -mcpu=cortex-m0plus -mthumb
CFLAGS += -MD -MP -MT $(BUILD)/$(*F).o -MF $(BUILD)/$(@F).d
LDFLAGS += -mcpu=cortex-m0plus -mthumb
LDFLAGS += -Wl,--gc-sections
LDFLAGS += -Wl,--script=../linker/samd11d14_std.ld
INCLUDES += \
-I../include \
-I../../.. \
-I..
SRCS += \
../main.c \
../uart.c \
../usb.c \
../usb_std.c \
../usb_cdc.c \
../usb_hid.c \
../usb_descriptors.c \
../startup_samd11.c \
../../../dap.c \
DEFINES += \
-D__SAMD11C14A__ \
-DDONT_USE_CMSIS_INIT \
-DF_CPU=48000000
CFLAGS += $(INCLUDES) $(DEFINES)
OBJS = $(addprefix $(BUILD)/, $(notdir %/$(subst .c,.o, $(SRCS))))
all: directory $(BUILD)/$(BIN).elf $(BUILD)/$(BIN).hex $(BUILD)/$(BIN).bin size
$(BUILD)/$(BIN).elf: $(OBJS)
@echo LD $@
@$(CC) $(LDFLAGS) $(OBJS) $(LIBS) -o $@
$(BUILD)/$(BIN).hex: $(BUILD)/$(BIN).elf
@echo OBJCOPY $@
@$(OBJCOPY) -O ihex $^ $@
$(BUILD)/$(BIN).bin: $(BUILD)/$(BIN).elf
@echo OBJCOPY $@
@$(OBJCOPY) -O binary $^ $@
%.o:
@echo CC $@
@$(CC) $(CFLAGS) $(filter %/$(subst .o,.c,$(notdir $@)), $(SRCS)) -c -o $@
directory:
@$(MKDIR) -p $(BUILD)
size: $(BUILD)/$(BIN).elf
@echo size:
@$(SIZE) -t $^
clean:
@echo clean
@-rm -rf $(BUILD)
-include $(wildcard $(BUILD)/*.d)

View File

@ -26,6 +26,9 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
//-----------------------------------------------------------------------------
#include "samd11.h"
//-----------------------------------------------------------------------------
#define DUMMY __attribute__ ((weak, alias ("irq_handler_dummy")))
@ -125,7 +128,10 @@ void irq_handler_reset(void)
while (dst < &_ebss)
*dst++ = 0;
SCB->VTOR = (uint32_t)vectors;
main();
while (1);
}