diff --git a/platform/samd11/main.c b/platform/samd11/main.c index 263c0ac..c9ddcab 100644 --- a/platform/samd11/main.c +++ b/platform/samd11/main.c @@ -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; } diff --git a/platform/samd11_vcp/linker/samd11d14_bl.ld b/platform/samd11_vcp/linker/samd11d14_bl.ld new file mode 100644 index 0000000..a653082 --- /dev/null +++ b/platform/samd11_vcp/linker/samd11d14_bl.ld @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2016-2017, Alex Taradov + * 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); +} diff --git a/platform/samd11_vcp/linker/samd11d14.ld b/platform/samd11_vcp/linker/samd11d14_std.ld similarity index 97% rename from platform/samd11_vcp/linker/samd11d14.ld rename to platform/samd11_vcp/linker/samd11d14_std.ld index 8e2f7fd..d6d8217 100644 --- a/platform/samd11_vcp/linker/samd11d14.ld +++ b/platform/samd11_vcp/linker/samd11d14_std.ld @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Alex Taradov + * Copyright (c) 2016-2017, Alex Taradov * 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); } - diff --git a/platform/samd11_vcp/main.c b/platform/samd11_vcp/main.c index d9c4383..c2dae0a 100644 --- a/platform/samd11_vcp/main.c +++ b/platform/samd11_vcp/main.c @@ -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; diff --git a/platform/samd11_vcp/make/Makefile b/platform/samd11_vcp/make/Makefile_bl similarity index 90% rename from platform/samd11_vcp/make/Makefile rename to platform/samd11_vcp/make/Makefile_bl index d70b3e2..7b82124 100644 --- a/platform/samd11_vcp/make/Makefile +++ b/platform/samd11_vcp/make/Makefile_bl @@ -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) diff --git a/platform/samd11_vcp/make/Makefile_std b/platform/samd11_vcp/make/Makefile_std new file mode 100644 index 0000000..957cc22 --- /dev/null +++ b/platform/samd11_vcp/make/Makefile_std @@ -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) + diff --git a/platform/samd11_vcp/startup_samd11.c b/platform/samd11_vcp/startup_samd11.c index 2d53e83..df2c994 100644 --- a/platform/samd11_vcp/startup_samd11.c +++ b/platform/samd11_vcp/startup_samd11.c @@ -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); }