fix samd21 race condition with setup packet

reproduced with Adafruit_TinyUSB_ArduinoCore port commit 11d669b4d2a40eb2fc5e51b2a9707a6de9d42363 and SAMD BSP 1.6.1
This commit is contained in:
hathach 2020-07-23 01:39:15 +07:00
parent 7d2fc12445
commit 0407cfe16c
8 changed files with 76 additions and 40 deletions

View File

@ -46,31 +46,32 @@ SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/hw/bsp/$(BOARD)/*.c))
# Compiler Flags
CFLAGS += \
-fdata-sections \
-ffunction-sections \
-fsingle-precision-constant \
-fno-strict-aliasing \
-Wdouble-promotion \
-Wstrict-prototypes \
-Wall \
-Wextra \
-Werror \
-Wfatal-errors \
-Werror-implicit-function-declaration \
-Wfloat-equal \
-Wundef \
-Wshadow \
-Wwrite-strings \
-Wsign-compare \
-Wmissing-format-attribute \
-Wunreachable-code \
-Wcast-align
-ggdb \
-fdata-sections \
-ffunction-sections \
-fsingle-precision-constant \
-fno-strict-aliasing \
-Wdouble-promotion \
-Wstrict-prototypes \
-Wall \
-Wextra \
-Werror \
-Wfatal-errors \
-Werror-implicit-function-declaration \
-Wfloat-equal \
-Wundef \
-Wshadow \
-Wwrite-strings \
-Wsign-compare \
-Wmissing-format-attribute \
-Wunreachable-code \
-Wcast-align
# Debugging/Optimization
ifeq ($(DEBUG), 1)
CFLAGS += -Og -ggdb
CFLAGS += -Og
else
CFLAGS += -Os
CFLAGS += -Os
endif
# Log level is mapped to TUSB DEBUG option
@ -80,14 +81,11 @@ endif
# Logger: default is uart, can be set to rtt or swo
ifeq ($(LOGGER),rtt)
RTT_SRC = lib/SEGGER_RTT
CFLAGS += -DLOGGER_RTT -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
RTT_SRC = lib/SEGGER_RTT
CFLAGS += -DLOGGER_RTT -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
INC += $(TOP)/$(RTT_SRC)/RTT
SRC_C += $(RTT_SRC)/RTT/SEGGER_RTT_printf.c
SRC_C += $(RTT_SRC)/RTT/SEGGER_RTT.c
else ifeq ($(LOGGER),swo)
CFLAGS += -DLOGGER_SWO
CFLAGS += -DLOGGER_SWO
endif

View File

@ -41,5 +41,11 @@ FREERTOS_PORT = ARM_CM0
JLINK_DEVICE = ATSAMD21G18
JLINK_IF = swd
# flash using jlink
flash: flash-jlink
# flash using bossac at least version 1.8
# can be found in arduino15/packages/arduino/tools/bossac/
# Add it to your PATH or change BOSSAC variable to match your installation
BOSSAC = bossac
flash: $(BUILD)/$(BOARD)-firmware.bin
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0)
$(BOSSAC) --port=$(SERIAL) -U -i --offset=0x2000 -e -w $^ -R

View File

@ -44,5 +44,11 @@ FREERTOS_PORT = ARM_CM4F
JLINK_DEVICE = ATSAMD51J19
JLINK_IF = swd
# flash using jlink
flash: flash-jlink
# flash using bossac at least version 1.8
# can be found in arduino15/packages/arduino/tools/bossac/
# Add it to your PATH or change BOSSAC variable to match your installation
BOSSAC = bossac
flash: $(BUILD)/$(BOARD)-firmware.bin
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0)
$(BOSSAC) --port=$(SERIAL) -U -i --offset=0x4000 -e -w $^ -R

View File

@ -41,5 +41,11 @@ FREERTOS_PORT = ARM_CM0
JLINK_DEVICE = ATSAMD21G18
JLINK_IF = swd
# flash using jlink
flash: flash-jlink
# flash using bossac at least version 1.8
# can be found in arduino15/packages/arduino/tools/bossac/
# Add it to your PATH or change BOSSAC variable to match your installation
BOSSAC = bossac
flash: $(BUILD)/$(BOARD)-firmware.bin
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0)
$(BOSSAC) --port=$(SERIAL) -U -i --offset=0x2000 -e -w $^ -R

View File

@ -44,5 +44,11 @@ FREERTOS_PORT = ARM_CM4F
JLINK_DEVICE = ATSAMD51J19
JLINK_IF = swd
# flash using jlink
flash: flash-jlink
# flash using bossac at least version 1.8
# can be found in arduino15/packages/arduino/tools/bossac/
# Add it to your PATH or change BOSSAC variable to match your installation
BOSSAC = bossac
flash: $(BUILD)/$(BOARD)-firmware.bin
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0)
$(BOSSAC) --port=$(SERIAL) -U -i --offset=0x4000 -e -w $^ -R

View File

@ -41,5 +41,11 @@ FREERTOS_PORT = ARM_CM0
JLINK_DEVICE = ATSAMD21G18
JLINK_IF = swd
# flash using jlink
flash: flash-jlink
# flash using bossac at least version 1.8
# can be found in arduino15/packages/arduino/tools/bossac/
# Add it to your PATH or change BOSSAC variable to match your installation
BOSSAC = bossac
flash: $(BUILD)/$(BOARD)-firmware.bin
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0)
$(BOSSAC) --port=$(SERIAL) -U -i --offset=0x2000 -e -w $^ -R

View File

@ -44,5 +44,11 @@ FREERTOS_PORT = ARM_CM4F
JLINK_DEVICE = ATSAMD51J19
JLINK_IF = swd
# flash using jlink
flash: flash-jlink
# flash using bossac at least version 1.8
# can be found in arduino15/packages/arduino/tools/bossac/
# Add it to your PATH or change BOSSAC variable to match your installation
BOSSAC = bossac
flash: $(BUILD)/$(BOARD)-firmware.bin
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0)
$(BOSSAC) --port=$(SERIAL) -U -i --offset=0x4000 -e -w $^ -R

View File

@ -43,6 +43,8 @@ static inline void prepare_setup(void)
{
// Only make sure the EP0 OUT buffer is ready
sram_registers[0][0].ADDR.reg = (uint32_t) _setup_packet;
sram_registers[0][0].PCKSIZE.bit.MULTI_PACKET_SIZE = sizeof(_setup_packet);
sram_registers[0][0].PCKSIZE.bit.BYTE_COUNT = 0;
}
// Setup the control endpoint 0.