From 120b3134bbd9f4a5dc56e5a7e166646c3cd5078e Mon Sep 17 00:00:00 2001 From: Damien Merenne Date: Mon, 7 Sep 2020 15:46:51 +0200 Subject: [PATCH 1/7] Add SAM4SD32C/B support. --- src/target/sam3x.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/target/sam3x.c b/src/target/sam3x.c index 7e1be99c..0537c11a 100644 --- a/src/target/sam3x.c +++ b/src/target/sam3x.c @@ -108,6 +108,8 @@ const struct command_s sam3x_cmd_list[] = { #define CHIPID_CIDR_ARCH_SAM4SxA (0x88 << 20) #define CHIPID_CIDR_ARCH_SAM4SxB (0x89 << 20) #define CHIPID_CIDR_ARCH_SAM4SxC (0x8A << 20) +#define CHIPID_CIDR_ARCH_SAM4SDB (0x99 << 20) +#define CHIPID_CIDR_ARCH_SAM4SDC (0x9A << 20) #define CHIPID_CIDR_NVPTYP_MASK (0x07 << 28) #define CHIPID_CIDR_NVPTYP_FLASH (0x02 << 28) #define CHIPID_CIDR_NVPTYP_ROM_FLASH (0x03 << 28) @@ -242,6 +244,8 @@ bool sam3x_probe(target *t) case CHIPID_CIDR_ARCH_SAM4SxA | CHIPID_CIDR_EPROC_CM4: case CHIPID_CIDR_ARCH_SAM4SxB | CHIPID_CIDR_EPROC_CM4: case CHIPID_CIDR_ARCH_SAM4SxC | CHIPID_CIDR_EPROC_CM4: + case CHIPID_CIDR_ARCH_SAM4SDB | CHIPID_CIDR_EPROC_CM4: + case CHIPID_CIDR_ARCH_SAM4SDC | CHIPID_CIDR_EPROC_CM4: t->driver = "Atmel SAM4S"; target_add_ram(t, 0x20000000, 0x400000); size_t size = sam_flash_size(t->idcode); From 6d18a61b2e5b9842d9cfd5df4cade1cb75a81204 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Fri, 11 Sep 2020 12:16:45 +0200 Subject: [PATCH 2/7] hosted: Make ASAN build optional. Use ASAN=1 on the make command line to activate, --- src/platforms/hosted/Makefile.inc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/platforms/hosted/Makefile.inc b/src/platforms/hosted/Makefile.inc index d1700d01..b3c65019 100644 --- a/src/platforms/hosted/Makefile.inc +++ b/src/platforms/hosted/Makefile.inc @@ -5,8 +5,10 @@ CFLAGS +=-I ./target -I./platforms/pc ifneq (, $(findstring linux, $(SYS))) SRC += serial_unix.c +ifeq ($(ASAN), 1) CFLAGS += -fsanitize=address LDFLAGS += -lasan +endif else ifneq (, $(findstring mingw, $(SYS))) SRC += serial_win.c LDFLAGS += -lws2_32 From de01a75ca9b2561269d6382f4ca27fbd4ff678aa Mon Sep 17 00:00:00 2001 From: Raghu Date: Tue, 15 Sep 2020 22:59:01 +0530 Subject: [PATCH 3/7] Fix broken link to bluepill pinout. --- src/platforms/swlink/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/swlink/README.md b/src/platforms/swlink/README.md index 70856622..edfbb9e6 100644 --- a/src/platforms/swlink/README.md +++ b/src/platforms/swlink/README.md @@ -29,7 +29,7 @@ on STM8S-Disco on CN5/3 Use first number! [Blue Pill Schematics 2 - ](https://wiki.stm32duino.com/images/a/ae/Bluepillpinout.gif) : + ](https://stm32duinoforum.com/forum/images/a/ae/wiki_subdomain/Bluepillpinout.gif) : Use second number! Distinguish boards by checking the SWIM_IN connection PB9/PB10 seen on From 75b5e72a004c05652f7672231869950b7a4d0e2b Mon Sep 17 00:00:00 2001 From: jxltom Date: Wed, 16 Sep 2020 23:31:11 +0800 Subject: [PATCH 4/7] Fix typo --- src/platforms/native/platform.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index 0799ab4d..451d308a 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -50,7 +50,7 @@ int usbuart_debug_write(const char *buf, size_t len); * LED1 = PB10 (Yellow LED : Idle) * LED2 = PB11 (Red LED : Error) * - * TPWR = RB0 (input) -- analogue on mini design ADC1, ch8 + * TPWR = PB0 (input) -- analogue on mini design ADC1, ch8 * nTRST = PB1 (output) [blackmagic] * PWR_BR = PB1 (output) [blackmagic_mini] -- supply power to the target, active low * TMS_DIR = PA1 (output) [blackmagic_mini v2.1] -- choose direction of the TCK pin, input low, output high From a4a934f461ca0994a45b72e0ed83fa2faa10c785 Mon Sep 17 00:00:00 2001 From: jxltom Date: Thu, 17 Sep 2020 00:52:11 +0800 Subject: [PATCH 5/7] Add comments for hardware revision of v2.1 --- src/platforms/native/platform.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index 7d750572..e16632b6 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -43,6 +43,7 @@ static void setup_vbus_irq(void); * 000 - Original production build. * 001 - Mini production build. * 010 - Mini V2.0e and later. + * 011 - Mini V2.1e and later. */ int platform_hwversion(void) { From bdb351a6eaf552763556c9ffb5901c7bb8e7aa40 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Thu, 17 Sep 2020 22:02:54 +0200 Subject: [PATCH 6/7] adiv5_swdp: On ACK_FAULT, error() and try again once #731 when writing CSW. --- src/target/adiv5_swdp.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/target/adiv5_swdp.c b/src/target/adiv5_swdp.c index 5097febd..eba7cab5 100644 --- a/src/target/adiv5_swdp.c +++ b/src/target/adiv5_swdp.c @@ -146,6 +146,12 @@ uint32_t firmware_swdp_low_access(ADIv5_DP_t *dp, uint8_t RnW, do { swd_proc.swdptap_seq_out(request, 8); ack = swd_proc.swdptap_seq_in(3); + if (ack == SWDP_ACK_FAULT) { + /* On fault, abort() and repeat the command once.*/ + firmware_swdp_error(dp); + swd_proc.swdptap_seq_out(request, 8); + ack = swd_proc.swdptap_seq_in(3); + } } while (ack == SWDP_ACK_WAIT && !platform_timeout_is_expired(&timeout)); if (ack == SWDP_ACK_WAIT) From 77231e8972fa22cb233354ba5aed694dff4a9e24 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Sun, 20 Sep 2020 13:14:50 +0200 Subject: [PATCH 7/7] serial_no: Fix error with "mon trace" #732 launchpad-icdi: Allow to set a serial number with make --- src/command.c | 4 ++- src/{platforms/common => include}/serialno.h | 2 +- src/platforms/common/cdcacm.c | 6 ++-- src/platforms/launchpad-icdi/Makefile.inc | 3 +- src/platforms/launchpad-icdi/platform.c | 8 ++--- src/platforms/stm32/serialno.c | 37 +++++++++----------- 6 files changed, 29 insertions(+), 31 deletions(-) rename src/{platforms/common => include}/serialno.h (95%) diff --git a/src/command.c b/src/command.c index fd7e0b4d..2758d31b 100644 --- a/src/command.c +++ b/src/command.c @@ -29,6 +29,7 @@ #include "target.h" #include "morse.h" #include "version.h" +#include "serialno.h" #ifdef PLATFORM_HAS_TRACESWO # include "traceswo.h" @@ -367,7 +368,7 @@ static bool cmd_target_power(target *t, int argc, const char **argv) #ifdef PLATFORM_HAS_TRACESWO static bool cmd_traceswo(target *t, int argc, const char **argv) { - extern char *serial_no; + char serial_no[13]; (void)t; #if TRACESWO_PROTOCOL == 2 uint32_t baudrate = SWO_DEFAULT_BAUD; @@ -413,6 +414,7 @@ static bool cmd_traceswo(target *t, int argc, const char **argv) #else traceswo_init(swo_channelmask); #endif + serial_no_read(serial_no, sizeof(serial_no)); gdb_outf("%s:%02X:%02X\n", serial_no, 5, 0x85); return true; } diff --git a/src/platforms/common/serialno.h b/src/include/serialno.h similarity index 95% rename from src/platforms/common/serialno.h rename to src/include/serialno.h index 946dc203..69cfe025 100644 --- a/src/platforms/common/serialno.h +++ b/src/include/serialno.h @@ -20,7 +20,7 @@ #ifndef __SERIALNO_H #define __SERIALNO_H -char *serialno_read(char *s); +char *serial_no_read(char *s, int max); #endif diff --git a/src/platforms/common/cdcacm.c b/src/platforms/common/cdcacm.c index 49c9a702..7fe4dc3a 100644 --- a/src/platforms/common/cdcacm.c +++ b/src/platforms/common/cdcacm.c @@ -391,9 +391,9 @@ static const struct usb_config_descriptor config = { }; #if defined(STM32L0) || defined(STM32F3) || defined(STM32F4) -char serial_no[13]; +static char serial_no[13]; #else -char serial_no[9]; +static char serial_no[9]; #endif static const char *usb_strings[] = { @@ -547,7 +547,7 @@ void cdcacm_init(void) { void exti15_10_isr(void); - serialno_read(serial_no); + serial_no_read(serial_no, sizeof(serial_no)); usbdev = usbd_init(&USB_DRIVER, &dev, &config, usb_strings, sizeof(usb_strings)/sizeof(char *), diff --git a/src/platforms/launchpad-icdi/Makefile.inc b/src/platforms/launchpad-icdi/Makefile.inc index ac717971..80d12ca2 100644 --- a/src/platforms/launchpad-icdi/Makefile.inc +++ b/src/platforms/launchpad-icdi/Makefile.inc @@ -1,11 +1,12 @@ CROSS_COMPILE ?= arm-none-eabi- +SERIAL_NO ?= 1 CC = $(CROSS_COMPILE)gcc OBJCOPY = $(CROSS_COMPILE)objcopy INCLUDES = -I../libopencm3/include CPU_FLAGS = -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -CFLAGS += $(INCLUDES) $(CPU_FLAGS) -DTARGET_IS_BLIZZARD_RB1 -DLM4F -DPART_TM4C123GH6PM +CFLAGS += $(INCLUDES) $(CPU_FLAGS) -DSERIAL_NO=$(SERIAL_NO) -DTARGET_IS_BLIZZARD_RB1 -DLM4F -DPART_TM4C123GH6PM LINKER_SCRIPT="platforms/tm4c/tm4c.ld" LDFLAGS = -nostartfiles -lc $(CPU_FLAGS) -nodefaultlibs -T$(LINKER_SCRIPT) -Wl,--gc-sections \ diff --git a/src/platforms/launchpad-icdi/platform.c b/src/platforms/launchpad-icdi/platform.c index d794372e..5a78063c 100644 --- a/src/platforms/launchpad-icdi/platform.c +++ b/src/platforms/launchpad-icdi/platform.c @@ -118,20 +118,20 @@ const char *platform_target_voltage(void) return NULL; } -char *serialno_read(char *s) +char *serial_no_read(char *s, int max) { /* FIXME: Store a unique serial number somewhere and retreive here */ - uint32_t unique_id = 1; + uint32_t unique_id = SERIAL_NO; int i; /* Fetch serial number from chip's unique ID */ for(i = 0; i < 8; i++) { s[7-i] = ((unique_id >> (4*i)) & 0xF) + '0'; } - for(i = 0; i < 8; i++) + for(i = 0; i < max - 1; i++) if(s[i] > '9') s[i] += 'A' - '9' - 1; - s[8] = 0; + s[max] = 0; return s; } diff --git a/src/platforms/stm32/serialno.c b/src/platforms/stm32/serialno.c index ae02f8a5..69503804 100644 --- a/src/platforms/stm32/serialno.c +++ b/src/platforms/stm32/serialno.c @@ -19,32 +19,27 @@ */ #include "general.h" -char *serialno_read(char *s) +char *serial_no_read(char *s, int max) { -#if defined(STM32L0) || defined(STM32F3) || defined(STM32F4) - volatile uint16_t *uid = (volatile uint16_t *)DESIG_UNIQUE_ID_BASE; +#if defined(STM32F1) +/* Only STM32F103 has no DFU Bootloader. Generate a ID comatible + * with the BMP Bootloader since ages. + */ + uint32_t *unique_id_p = (uint32_t *)DESIG_UNIQUE_ID_BASE; + uint32_t unique_id = *unique_id_p + + *(unique_id_p + 1) + + *(unique_id_p + 2); + snprintf(s, max, "%08" PRIX32, unique_id); +#else + /* Use the same serial number as the ST DFU Bootloader.*/ + uint16_t *uid = (uint16_t *)DESIG_UNIQUE_ID_BASE; # if defined(STM32F4) int offset = 3; -# elif defined(STM32L0) || defined(STM32F4) +# elif defined(STM32L0) || defined(STM32F3) int offset = 5; -#endif - sprintf(s, "%04X%04X%04X", +# endif + snprintf(s, max, "%04X%04X%04X", uid[1] + uid[5], uid[0] + uid[4], uid[offset]); -#else - volatile uint32_t *unique_id_p = (volatile uint32_t *)0x1FFFF7E8; - uint32_t unique_id = *unique_id_p + - *(unique_id_p + 1) + - *(unique_id_p + 2); - int i; - - /* Fetch serial number from chip's unique ID */ - for(i = 0; i < 8; i++) { - s[7-i] = ((unique_id >> (4*i)) & 0xF) + '0'; - } - for(i = 0; i < 8; i++) - if(s[i] > '9') - s[i] += 'A' - '9' - 1; - s[8] = 0; #endif return s;