Merge commit '443ced62d4e47d73da13746a836369d8421b4fe8' into sam-update

# Conflicts:
#	libopencm3
This commit is contained in:
Jason Kotzin 2022-08-02 01:23:28 -07:00
commit 81bb75bba6
22 changed files with 69 additions and 63 deletions

View File

@ -4,15 +4,18 @@ Q := @
endif endif
PC_HOSTED = PC_HOSTED =
NO_LIBOPENCM3 =
ifeq ($(PROBE_HOST), libftdi) ifeq ($(PROBE_HOST), libftdi)
PC_HOSTED = true PC_HOSTED = true
NO_LIBOPENCM3 = true
endif endif
ifeq ($(PROBE_HOST), pc-stlinkv2) ifeq ($(PROBE_HOST), pc-stlinkv2)
PC_HOSTED = true PC_HOSTED = true
NO_LIBOPENCM3 = true
endif endif
all: all:
ifndef PC_HOSTED ifndef NO_LIBOPENCM3
$(Q)if [ ! -f libopencm3/Makefile ]; then \ $(Q)if [ ! -f libopencm3/Makefile ]; then \
echo "Initialising git submodules..." ;\ echo "Initialising git submodules..." ;\
git submodule init ;\ git submodule init ;\
@ -23,7 +26,7 @@ endif
$(Q)$(MAKE) $(MFLAGS) -C src $(Q)$(MAKE) $(MFLAGS) -C src
clean: clean:
ifndef PC_HOSTED ifndef NO_LIBOPENCM3
$(Q)$(MAKE) $(MFLAGS) -C libopencm3 $@ $(Q)$(MAKE) $(MFLAGS) -C libopencm3 $@
endif endif
$(Q)$(MAKE) $(MFLAGS) -C src $@ $(Q)$(MAKE) $(MFLAGS) -C src $@

@ -1 +1 @@
Subproject commit 46e315bf2b3da94dbaec7671541e8ad2b2f87a75 Subproject commit f86c46467d94c0160c2f58044675e42f1a8fdb7c

View File

@ -8,12 +8,9 @@ MAKEFLAGS += --no-print-dir
Q := @ Q := @
endif endif
OPT_FLAGS ?= -O2
CFLAGS += -Wall -Wextra -Werror -Wno-char-subscripts -Wno-cast-function-type \ CFLAGS += -Wall -Wextra -Werror -Wno-char-subscripts -Wno-cast-function-type \
$(OPT_FLAGS) -std=gnu99 -g3 -MD \ -std=gnu99 -g3 -MD \
-I. -Iinclude -Iplatforms/common -I$(PLATFORM_DIR) -I. -Iinclude -Iplatforms/common -I$(PLATFORM_DIR)
LDFLAGS += $(OPT_FLAGS)
ifeq ($(ENABLE_DEBUG), 1) ifeq ($(ENABLE_DEBUG), 1)
CFLAGS += -DENABLE_DEBUG -g3 -ggdb CFLAGS += -DENABLE_DEBUG -g3 -ggdb
@ -60,6 +57,10 @@ SRC = \
include $(PLATFORM_DIR)/Makefile.inc include $(PLATFORM_DIR)/Makefile.inc
OPT_FLAGS ?= -O2
CFLAGS += $(OPT_FLAGS)
LDFLAGS += $(OPT_FLAGS)
ifndef TARGET ifndef TARGET
TARGET=blackmagic TARGET=blackmagic
endif endif
@ -72,7 +73,7 @@ ifndef OWN_HL
SRC += jtag_scan.c jtagtap.c swdptap.c SRC += jtag_scan.c jtagtap.c swdptap.c
endif endif
OBJ = $(SRC:.c=.o) OBJ = $(patsubst %.S,%.o,$(patsubst %.c,%.o,$(SRC)))
$(TARGET): include/version.h $(OBJ) $(TARGET): include/version.h $(OBJ)
@echo " LD $@" @echo " LD $@"
@ -82,6 +83,10 @@ $(TARGET): include/version.h $(OBJ)
@echo " CC $<" @echo " CC $<"
$(Q)$(CC) $(CFLAGS) -c $< -o $@ $(Q)$(CC) $(CFLAGS) -c $< -o $@
%.o: %.S
@echo " AS $<"
$(Q)$(CC) $(CFLAGS) -c $< -o $@
%.bin: % %.bin: %
@echo " OBJCOPY $@" @echo " OBJCOPY $@"
$(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) -O binary $^ $@ $(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) -O binary $^ $@

View File

@ -120,7 +120,7 @@ void gdb_putpacket(const char *packet, int size)
} }
} }
gdb_if_putchar('#', 0); gdb_if_putchar('#', 0);
sprintf(xmit_csum, "%02X", csum); snprintf(xmit_csum, sizeof(xmit_csum), "%02X", csum);
gdb_if_putchar(xmit_csum[0], 0); gdb_if_putchar(xmit_csum[0], 0);
gdb_if_putchar(xmit_csum[1], 1); gdb_if_putchar(xmit_csum[1], 1);
#ifdef DEBUG_GDBPACKET #ifdef DEBUG_GDBPACKET

View File

@ -21,7 +21,7 @@
#ifndef __GDB_IF_H #ifndef __GDB_IF_H
#define __GDB_IF_H #define __GDB_IF_H
#if !defined(PC_HOSTED) #if !defined(NO_LIBOPENCM3)
#include <libopencm3/usb/usbd.h> #include <libopencm3/usb/usbd.h>
void gdb_usb_out_cb(usbd_device *dev, uint8_t ep); void gdb_usb_out_cb(usbd_device *dev, uint8_t ep);
#endif #endif

View File

@ -423,7 +423,7 @@ static void dfu_detach_complete(usbd_device *dev, struct usb_setup_data *req)
#endif #endif
} }
static int cdcacm_control_request(usbd_device *dev, static enum usbd_request_return_codes cdcacm_control_request(usbd_device *dev,
struct usb_setup_data *req, uint8_t **buf, uint16_t *len, struct usb_setup_data *req, uint8_t **buf, uint16_t *len,
void (**complete)(usbd_device *dev, struct usb_setup_data *req)) void (**complete)(usbd_device *dev, struct usb_setup_data *req))
{ {
@ -437,23 +437,23 @@ static int cdcacm_control_request(usbd_device *dev,
cdcacm_set_modem_state(dev, req->wIndex, true, true); cdcacm_set_modem_state(dev, req->wIndex, true, true);
/* Ignore if not for GDB interface */ /* Ignore if not for GDB interface */
if(req->wIndex != 0) if(req->wIndex != 0)
return 1; return USBD_REQ_HANDLED;
cdcacm_gdb_dtr = req->wValue & 1; cdcacm_gdb_dtr = req->wValue & 1;
return 1; return USBD_REQ_HANDLED;
case USB_CDC_REQ_SET_LINE_CODING: case USB_CDC_REQ_SET_LINE_CODING:
if(*len < sizeof(struct usb_cdc_line_coding)) if(*len < sizeof(struct usb_cdc_line_coding))
return 0; return USBD_REQ_NOTSUPP;
switch(req->wIndex) { switch(req->wIndex) {
case 2: case 2:
usbuart_set_line_coding((struct usb_cdc_line_coding*)*buf); usbuart_set_line_coding((struct usb_cdc_line_coding*)*buf);
return 1; return USBD_REQ_HANDLED;
case 0: case 0:
return 1; /* Ignore on GDB Port */ return USBD_REQ_HANDLED; /* Ignore on GDB Port */
default: default:
return 0; return USBD_REQ_NOTSUPP;
} }
case DFU_GETSTATUS: case DFU_GETSTATUS:
if(req->wIndex == DFU_IF_NO) { if(req->wIndex == DFU_IF_NO) {
@ -465,17 +465,17 @@ static int cdcacm_control_request(usbd_device *dev,
(*buf)[5] = 0; /* iString not used here */ (*buf)[5] = 0; /* iString not used here */
*len = 6; *len = 6;
return 1; return USBD_REQ_HANDLED;
} }
return 0; return USBD_REQ_NOTSUPP;
case DFU_DETACH: case DFU_DETACH:
if(req->wIndex == DFU_IF_NO) { if(req->wIndex == DFU_IF_NO) {
*complete = dfu_detach_complete; *complete = dfu_detach_complete;
return 1; return USBD_REQ_HANDLED;
} }
return 0; return USBD_REQ_NOTSUPP;
} }
return 0; return USBD_REQ_NOTSUPP;
} }
int cdcacm_get_config(void) int cdcacm_get_config(void)

View File

@ -62,7 +62,7 @@ void platform_init(void)
scb_reset_core(); scb_reset_core();
} }
rcc_clock_setup_hse_3v3(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_48MHZ]); rcc_clock_setup_pll(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]);
/* Enable peripherals */ /* Enable peripherals */
rcc_periph_clock_enable(RCC_OTGFS); rcc_periph_clock_enable(RCC_OTGFS);

View File

@ -46,7 +46,7 @@ void platform_init(void)
scb_reset_core(); scb_reset_core();
} }
rcc_clock_setup_hse_3v3(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_48MHZ]); rcc_clock_setup_pll(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]);
/* Enable peripherals */ /* Enable peripherals */
rcc_peripheral_enable_clock(&RCC_AHB2ENR, RCC_AHB2ENR_OTGFSEN); rcc_peripheral_enable_clock(&RCC_AHB2ENR, RCC_AHB2ENR_OTGFSEN);

View File

@ -143,10 +143,8 @@ static const char *usb_strings[] = {
//"@Internal Flash /0x00000000/1*0016Ka,15*0016Kg", //"@Internal Flash /0x00000000/1*0016Ka,15*0016Kg",
}; };
static uint8_t usbdfu_getstatus(usbd_device *usbd_dev, uint32_t *bwPollTimeout) static uint8_t usbdfu_getstatus(uint32_t *bwPollTimeout)
{ {
(void)usbd_dev;
switch (usbdfu_state) { switch (usbdfu_state) {
case STATE_DFU_DNLOAD_SYNC: case STATE_DFU_DNLOAD_SYNC:
usbdfu_state = STATE_DFU_DNBUSY; usbdfu_state = STATE_DFU_DNBUSY;
@ -225,9 +223,12 @@ static void usbdfu_getstatus_complete(usbd_device *usbd_dev, struct usb_setup_da
} }
} }
static int usbdfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, static enum usbd_request_return_codes usbdfu_control_request(usbd_device *dev,
uint16_t *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req)) struct usb_setup_data *req, uint8_t **buf, uint16_t *len,
void (**complete)(usbd_device *dev, struct usb_setup_data *req))
{ {
(void)dev;
if ((req->bmRequestType & 0x7F) != 0x21) if ((req->bmRequestType & 0x7F) != 0x21)
return 0; /* Only accept class request. */ return 0; /* Only accept class request. */
@ -258,7 +259,7 @@ static int usbdfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *
return 0; return 0;
case DFU_GETSTATUS: { case DFU_GETSTATUS: {
uint32_t bwPollTimeout = 0; /* 24-bit integer in DFU class spec */ uint32_t bwPollTimeout = 0; /* 24-bit integer in DFU class spec */
(*buf)[0] = usbdfu_getstatus(usbd_dev, &bwPollTimeout); (*buf)[0] = usbdfu_getstatus(&bwPollTimeout);
(*buf)[1] = bwPollTimeout & 0xFF; (*buf)[1] = bwPollTimeout & 0xFF;
(*buf)[2] = (bwPollTimeout >> 8) & 0xFF; (*buf)[2] = (bwPollTimeout >> 8) & 0xFF;
(*buf)[3] = (bwPollTimeout >> 16) & 0xFF; (*buf)[3] = (bwPollTimeout >> 16) & 0xFF;

View File

@ -68,7 +68,7 @@ extern uint8_t running_status;
gpio_set_output_config(SWDIO_PORT, GPIO_OTYPE_PP, GPIO_DRIVE_2MA, SWDIO_PIN); \ gpio_set_output_config(SWDIO_PORT, GPIO_OTYPE_PP, GPIO_DRIVE_2MA, SWDIO_PIN); \
} }
extern usbd_driver lm4f_usb_driver; extern const usbd_driver lm4f_usb_driver;
#define USB_DRIVER lm4f_usb_driver #define USB_DRIVER lm4f_usb_driver
#define USB_IRQ NVIC_USB0_IRQ #define USB_IRQ NVIC_USB0_IRQ
#define USB_ISR usb0_isr #define USB_ISR usb0_isr

View File

@ -1,5 +1,5 @@
SYS = $(shell $(CC) -dumpmachine) SYS = $(shell $(CC) -dumpmachine)
CFLAGS += -DPC_HOSTED -DENABLE_DEBUG CFLAGS += -DPC_HOSTED -DNO_LIBOPENCM3 -DENABLE_DEBUG
LDFLAGS += -lftdi1 LDFLAGS += -lftdi1
ifneq (, $(findstring mingw, $(SYS))) ifneq (, $(findstring mingw, $(SYS)))
LDFLAGS += -lusb-1.0 -lws2_32 LDFLAGS += -lusb-1.0 -lws2_32

View File

@ -1,6 +1,6 @@
TARGET=blackmagic_stlinkv2 TARGET=blackmagic_stlinkv2
SYS = $(shell $(CC) -dumpmachine) SYS = $(shell $(CC) -dumpmachine)
CFLAGS += -DPC_HOSTED -DSTLINKV2 -DJTAG_HL -DENABLE_DEBUG CFLAGS += -DPC_HOSTED -DNO_LIBOPENCM3 -DSTLINKV2 -DJTAG_HL -DENABLE_DEBUG
CFLAGS +=-I ./target CFLAGS +=-I ./target
LDFLAGS += -lusb-1.0 LDFLAGS += -lusb-1.0
ifneq (, $(findstring mingw, $(SYS))) ifneq (, $(findstring mingw, $(SYS)))

View File

@ -25,5 +25,5 @@ MEMORY
} }
/* Include the common ld script from libopenstm32. */ /* Include the common ld script from libopenstm32. */
INCLUDE libopencm3_stm32f1.ld INCLUDE cortex-m-generic.ld

View File

@ -198,20 +198,20 @@ usbdfu_getstatus_complete(usbd_device *dev, struct usb_setup_data *req)
} }
} }
static int usbdfu_control_request(usbd_device *dev, static enum usbd_request_return_codes usbdfu_control_request(usbd_device *dev,
struct usb_setup_data *req, uint8_t **buf, uint16_t *len, struct usb_setup_data *req, uint8_t **buf, uint16_t *len,
void (**complete)(usbd_device *dev, struct usb_setup_data *req)) void (**complete)(usbd_device *dev, struct usb_setup_data *req))
{ {
(void)dev; (void)dev;
if((req->bmRequestType & 0x7F) != 0x21) if((req->bmRequestType & 0x7F) != 0x21)
return 0; /* Only accept class request */ return USBD_REQ_NOTSUPP; /* Only accept class request */
switch(req->bRequest) { switch(req->bRequest) {
case DFU_DNLOAD: case DFU_DNLOAD:
if((len == NULL) || (*len == 0)) { if((len == NULL) || (*len == 0)) {
usbdfu_state = STATE_DFU_MANIFEST_SYNC; usbdfu_state = STATE_DFU_MANIFEST_SYNC;
return 1; return USBD_REQ_HANDLED;
} else { } else {
/* Copy download data for use on GET_STATUS */ /* Copy download data for use on GET_STATUS */
prog.blocknum = req->wValue; prog.blocknum = req->wValue;
@ -222,22 +222,22 @@ static int usbdfu_control_request(usbd_device *dev,
if ((addr < app_address) || (addr >= max_address)) { if ((addr < app_address) || (addr >= max_address)) {
current_error = DFU_STATUS_ERR_TARGET; current_error = DFU_STATUS_ERR_TARGET;
usbdfu_state = STATE_DFU_ERROR; usbdfu_state = STATE_DFU_ERROR;
return 1; return USBD_REQ_HANDLED;
} else } else
prog.addr = addr; prog.addr = addr;
} }
usbdfu_state = STATE_DFU_DNLOAD_SYNC; usbdfu_state = STATE_DFU_DNLOAD_SYNC;
return 1; return USBD_REQ_HANDLED;
} }
case DFU_CLRSTATUS: case DFU_CLRSTATUS:
/* Clear error and return to dfuIDLE */ /* Clear error and return to dfuIDLE */
if(usbdfu_state == STATE_DFU_ERROR) if(usbdfu_state == STATE_DFU_ERROR)
usbdfu_state = STATE_DFU_IDLE; usbdfu_state = STATE_DFU_IDLE;
return 1; return USBD_REQ_HANDLED;
case DFU_ABORT: case DFU_ABORT:
/* Abort returns to dfuIDLE state */ /* Abort returns to dfuIDLE state */
usbdfu_state = STATE_DFU_IDLE; usbdfu_state = STATE_DFU_IDLE;
return 1; return USBD_REQ_HANDLED;
case DFU_UPLOAD: case DFU_UPLOAD:
if ((usbdfu_state == STATE_DFU_IDLE) || if ((usbdfu_state == STATE_DFU_IDLE) ||
(usbdfu_state == STATE_DFU_DNLOAD_IDLE) || (usbdfu_state == STATE_DFU_DNLOAD_IDLE) ||
@ -250,10 +250,10 @@ static int usbdfu_control_request(usbd_device *dev,
dfu_function.wTransferSize); dfu_function.wTransferSize);
memcpy(*buf, (void*)baseaddr, *len); memcpy(*buf, (void*)baseaddr, *len);
} }
return 1; return USBD_REQ_HANDLED;
} else { } else {
usbd_ep_stall_set(dev, 0, 1); usbd_ep_stall_set(dev, 0, 1);
return 0; return USBD_REQ_NOTSUPP;
} }
case DFU_GETSTATUS: { case DFU_GETSTATUS: {
uint32_t bwPollTimeout = 0; /* 24-bit integer in DFU class spec */ uint32_t bwPollTimeout = 0; /* 24-bit integer in DFU class spec */
@ -268,16 +268,16 @@ static int usbdfu_control_request(usbd_device *dev,
*complete = usbdfu_getstatus_complete; *complete = usbdfu_getstatus_complete;
return 1; return USBD_REQ_HANDLED;
} }
case DFU_GETSTATE: case DFU_GETSTATE:
/* Return state with no state transision */ /* Return state with no state transision */
*buf[0] = usbdfu_state; *buf[0] = usbdfu_state;
*len = 1; *len = 1;
return 1; return USBD_REQ_HANDLED;
} }
return 0; return USBD_REQ_NOTSUPP;
} }
void dfu_init(const usbd_driver *driver, dfu_mode_t mode) void dfu_init(const usbd_driver *driver, dfu_mode_t mode)

View File

@ -25,5 +25,5 @@ MEMORY
} }
/* Include the common ld script from libopenstm32. */ /* Include the common ld script from libopenstm32. */
INCLUDE libopencm3_stm32f4.ld INCLUDE cortex-m-generic.ld

View File

@ -25,4 +25,4 @@ MEMORY
} }
/* Include the common ld script from libopenstm32. */ /* Include the common ld script from libopenstm32. */
INCLUDE libopencm3_stm32f1.ld INCLUDE cortex-m-generic.ld

View File

@ -25,4 +25,4 @@ MEMORY
} }
/* Include the common ld script from libopenstm32. */ /* Include the common ld script from libopenstm32. */
INCLUDE libopencm3_stm32f1.ld INCLUDE cortex-m-generic.ld

View File

@ -42,8 +42,6 @@ void traceswo_init(void)
{ {
TRACE_TIM_CLK_EN(); TRACE_TIM_CLK_EN();
timer_reset(TRACE_TIM);
/* Refer to ST doc RM0008 - STM32F10xx Reference Manual. /* Refer to ST doc RM0008 - STM32F10xx Reference Manual.
* Section 14.3.4 - 14.3.6 (General Purpose Timer - Input Capture) * Section 14.3.4 - 14.3.6 (General Purpose Timer - Input Capture)
* *

View File

@ -68,7 +68,6 @@ void usbuart_init(void)
/* Setup timer for running deferred FIFO processing */ /* Setup timer for running deferred FIFO processing */
USBUSART_TIM_CLK_EN(); USBUSART_TIM_CLK_EN();
timer_reset(USBUSART_TIM);
timer_set_mode(USBUSART_TIM, TIM_CR1_CKD_CK_INT, timer_set_mode(USBUSART_TIM, TIM_CR1_CKD_CK_INT,
TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP); TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP);
timer_set_prescaler(USBUSART_TIM, timer_set_prescaler(USBUSART_TIM,

View File

@ -25,5 +25,5 @@ MEMORY
} }
/* Include the common ld script from libopenstm32. */ /* Include the common ld script from libopenstm32. */
INCLUDE libopencm3_lm4f.ld INCLUDE cortex-m-generic.ld

View File

@ -611,7 +611,7 @@ bool efm32_probe(target *t)
uint32_t ram_size = ram_kib * 0x400; uint32_t ram_size = ram_kib * 0x400;
uint32_t flash_page_size = device->flash_page_size; uint32_t flash_page_size = device->flash_page_size;
sprintf(variant_string, "%c\b%c\b%s %d F%d %s", snprintf(variant_string, sizeof(variant_string), "%c\b%c\b%s %d F%d %s",
di_version + 48, (uint8_t)device_index + 32, di_version + 48, (uint8_t)device_index + 32,
device->name, part_number, flash_kib, device->description); device->name, part_number, flash_kib, device->description);

View File

@ -364,7 +364,7 @@ static void samd_add_flash(target *t, uint32_t addr, size_t length)
target_add_flash(t, f); target_add_flash(t, f);
} }
char variant_string[40]; char variant_string[60];
bool samd_probe(target *t) bool samd_probe(target *t)
{ {
uint32_t cid = samd_read_cid(t); uint32_t cid = samd_read_cid(t);
@ -390,12 +390,12 @@ bool samd_probe(target *t)
/* Part String */ /* Part String */
if (protected) { if (protected) {
sprintf(variant_string, snprintf(variant_string, sizeof(variant_string),
"Atmel SAMD%d%c%dA%s (rev %c) (PROT=1)", "Atmel SAMD%d%c%dA%s (rev %c) (PROT=1)",
samd.series, samd.pin, samd.mem, samd.series, samd.pin, samd.mem,
samd.package, samd.revision); samd.package, samd.revision);
} else { } else {
sprintf(variant_string, snprintf(variant_string, sizeof(variant_string),
"Atmel SAMD%d%c%dA%s (rev %c)", "Atmel SAMD%d%c%dA%s (rev %c)",
samd.series, samd.pin, samd.mem, samd.series, samd.pin, samd.mem,
samd.package, samd.revision); samd.package, samd.revision);