Merge commit '1330288271bea7b6224bac5bc8e1438305eec44a' into sam-update

This commit is contained in:
Jason Kotzin 2022-08-10 20:09:58 -07:00
commit cb1ef7d616
12 changed files with 60 additions and 56 deletions

View File

@ -426,7 +426,7 @@ static bool cmd_target_power(target *t, int argc, const char **argv)
#ifdef PLATFORM_HAS_TRACESWO #ifdef PLATFORM_HAS_TRACESWO
static bool cmd_traceswo(target *t, int argc, const char **argv) static bool cmd_traceswo(target *t, int argc, const char **argv)
{ {
char serial_no[13]; char serial_no[DFU_SERIAL_LENGTH];
(void)t; (void)t;
#if TRACESWO_PROTOCOL == 2 #if TRACESWO_PROTOCOL == 2
uint32_t baudrate = SWO_DEFAULT_BAUD; uint32_t baudrate = SWO_DEFAULT_BAUD;
@ -472,7 +472,7 @@ static bool cmd_traceswo(target *t, int argc, const char **argv)
#else #else
traceswo_init(swo_channelmask); traceswo_init(swo_channelmask);
#endif #endif
serial_no_read(serial_no, sizeof(serial_no)); serial_no_read(serial_no);
gdb_outf("%s:%02X:%02X\n", serial_no, 5, 0x85); gdb_outf("%s:%02X:%02X\n", serial_no, 5, 0x85);
return true; return true;
} }

View File

@ -20,7 +20,7 @@
#ifndef __SERIALNO_H #ifndef __SERIALNO_H
#define __SERIALNO_H #define __SERIALNO_H
char *serial_no_read(char *s, int max); char *serial_no_read(char *s);
#endif #endif

View File

@ -394,12 +394,7 @@ static const struct usb_config_descriptor config = {
.interface = ifaces, .interface = ifaces,
}; };
static char serial_no[DFU_SERIAL_LENGTH];
#if defined(DUSE_ST_SERIAL)
char serial_no[13];
#else
static char serial_no[9];
#endif
#define BOARD_IDENT "Black Magic Probe " PLATFORM_IDENT FIRMWARE_VERSION #define BOARD_IDENT "Black Magic Probe " PLATFORM_IDENT FIRMWARE_VERSION
#define DFU_IDENT "Black Magic Firmware Upgrade " PLATFORM_IDENT FIRMWARE_VERSION #define DFU_IDENT "Black Magic Firmware Upgrade " PLATFORM_IDENT FIRMWARE_VERSION
@ -559,7 +554,7 @@ void cdcacm_init(void)
{ {
void exti15_10_isr(void); void exti15_10_isr(void);
serial_no_read(serial_no, sizeof(serial_no)); serial_no_read(serial_no);
usbdev = usbd_init(&USB_DRIVER, &dev, &config, usb_strings, usbdev = usbd_init(&USB_DRIVER, &dev, &config, usb_strings,
sizeof(usb_strings)/sizeof(char *), sizeof(usb_strings)/sizeof(char *),

View File

@ -5,7 +5,7 @@ OBJCOPY = $(CROSS_COMPILE)objcopy
CFLAGS += -Istm32/include -mcpu=cortex-m4 -mthumb \ CFLAGS += -Istm32/include -mcpu=cortex-m4 -mthumb \
-mfloat-abi=hard -mfpu=fpv4-sp-d16 \ -mfloat-abi=hard -mfpu=fpv4-sp-d16 \
-DSTM32F4 -DF4DISCOVERY -I../libopencm3/include \ -DSTM32F4 -I../libopencm3/include \
-Iplatforms/stm32 -Iplatforms/stm32
LDFLAGS_BOOT = -lopencm3_stm32f4 \ LDFLAGS_BOOT = -lopencm3_stm32f4 \
@ -17,9 +17,10 @@ LDFLAGS_BOOT = -lopencm3_stm32f4 \
ifeq ($(BMP_BOOTLOADER), 1) ifeq ($(BMP_BOOTLOADER), 1)
$(info Load address 0x08004000 for BMPBootloader) $(info Load address 0x08004000 for BMPBootloader)
LDFLAGS = $(LDFLAGS_BOOT) -Wl,-Ttext=0x8004000 LDFLAGS = $(LDFLAGS_BOOT) -Wl,-Ttext=0x8004000
CFLAGS += -DDFU_SERIAL_LENGTH=9
else else
LDFLAGS += $(LDFLAGS_BOOT) LDFLAGS += $(LDFLAGS_BOOT)
CFLAGS += -DUSE_ST_SERIAL CFLAGS += -DDFU_SERIAL_LENGTH=13
endif endif
VPATH += platforms/stm32 VPATH += platforms/stm32
@ -36,7 +37,7 @@ ifneq ($(BMP_BOOTLOADER), 1)
all: blackmagic.bin all: blackmagic.bin
else else
all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex
blackmagic_dfu: usbdfu.o dfucore.o dfu_f4.o blackmagic_dfu: usbdfu.o dfucore.o dfu_f4.o serialno.o
$(CC) $^ -o $@ $(LDFLAGS_BOOT) $(CC) $^ -o $@ $(LDFLAGS_BOOT)
blackmagic_dfu.bin: blackmagic_dfu blackmagic_dfu.bin: blackmagic_dfu

View File

@ -4,8 +4,8 @@ OBJCOPY = $(CROSS_COMPILE)objcopy
CFLAGS += -Istm32/include -mcpu=cortex-m4 -mthumb \ CFLAGS += -Istm32/include -mcpu=cortex-m4 -mthumb \
-mfloat-abi=hard -mfpu=fpv4-sp-d16 \ -mfloat-abi=hard -mfpu=fpv4-sp-d16 \
-DSTM32F4 -DHYDRABUS -I../libopencm3/include \ -DSTM32F4 -I../libopencm3/include \
-Iplatforms/stm32 -DUSE_ST_BOOTLOADER -Iplatforms/stm32 -DDFU_SERIAL_LENGTH=9
LDFLAGS = -lopencm3_stm32f4 \ LDFLAGS = -lopencm3_stm32f4 \
-Wl,-T,platforms/stm32/f4discovery.ld -nostartfiles -lc -lnosys \ -Wl,-T,platforms/stm32/f4discovery.ld -nostartfiles -lc -lnosys \

View File

@ -7,6 +7,7 @@ INCLUDES = -I../libopencm3/include
CPU_FLAGS = -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard CPU_FLAGS = -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard
CFLAGS += $(INCLUDES) $(CPU_FLAGS) -DSERIAL_NO=$(SERIAL_NO) -DTARGET_IS_BLIZZARD_RB1 -DLM4F -DPART_TM4C123GH6PM CFLAGS += $(INCLUDES) $(CPU_FLAGS) -DSERIAL_NO=$(SERIAL_NO) -DTARGET_IS_BLIZZARD_RB1 -DLM4F -DPART_TM4C123GH6PM
CFLAGS += -DDFU_SERIAL_LENGTH=9
LINKER_SCRIPT="platforms/tm4c/tm4c.ld" LINKER_SCRIPT="platforms/tm4c/tm4c.ld"
LDFLAGS = -nostartfiles -lc $(CPU_FLAGS) -nodefaultlibs -T$(LINKER_SCRIPT) -Wl,--gc-sections \ LDFLAGS = -nostartfiles -lc $(CPU_FLAGS) -nodefaultlibs -T$(LINKER_SCRIPT) -Wl,--gc-sections \

View File

@ -120,7 +120,7 @@ const char *platform_target_voltage(void)
return NULL; return NULL;
} }
char *serial_no_read(char *s, int max) char *serial_no_read(char *s)
{ {
/* FIXME: Store a unique serial number somewhere and retreive here */ /* FIXME: Store a unique serial number somewhere and retreive here */
uint32_t unique_id = SERIAL_NO; uint32_t unique_id = SERIAL_NO;
@ -130,10 +130,10 @@ char *serial_no_read(char *s, int max)
for(i = 0; i < 8; i++) { for(i = 0; i < 8; i++) {
s[7-i] = ((unique_id >> (4*i)) & 0xF) + '0'; s[7-i] = ((unique_id >> (4*i)) & 0xF) + '0';
} }
for(i = 0; i < max - 1; i++) for(i = 0; i < DFU_SERIAL_LENGTH - 1; i++)
if(s[i] > '9') if(s[i] > '9')
s[i] += 'A' - '9' - 1; s[i] += 'A' - '9' - 1;
s[max] = 0; s[DFU_SERIAL_LENGTH - 1] = 0;
return s; return s;
} }

View File

@ -4,7 +4,7 @@ OBJCOPY = $(CROSS_COMPILE)objcopy
CFLAGS += -Istm32/include -mcpu=cortex-m3 -mthumb \ CFLAGS += -Istm32/include -mcpu=cortex-m3 -mthumb \
-DSTM32F1 -DBLACKMAGIC -I../libopencm3/include \ -DSTM32F1 -DBLACKMAGIC -I../libopencm3/include \
-Iplatforms/stm32 -Iplatforms/stm32 -DDFU_SERIAL_LENGTH=9
LDFLAGS_BOOT := $(LDFLAGS) --specs=nano.specs -lopencm3_stm32f1 \ LDFLAGS_BOOT := $(LDFLAGS) --specs=nano.specs -lopencm3_stm32f1 \
-Wl,-T,platforms/stm32/blackmagic.ld -nostartfiles -lc \ -Wl,-T,platforms/stm32/blackmagic.ld -nostartfiles -lc \
@ -30,7 +30,7 @@ SRC += cdcacm.c \
all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex
blackmagic_dfu.elf: usbdfu.o dfucore.o dfu_f1.o blackmagic_dfu.elf: usbdfu.o dfucore.o dfu_f1.o serialno.o
@echo " LD $@" @echo " LD $@"
$(Q)$(CC) $^ -o $@ $(LDFLAGS_BOOT) $(Q)$(CC) $^ -o $@ $(LDFLAGS_BOOT)

View File

@ -3,8 +3,8 @@ ST_BOOTLOADER ?=
CC = $(CROSS_COMPILE)gcc CC = $(CROSS_COMPILE)gcc
OBJCOPY = $(CROSS_COMPILE)objcopy OBJCOPY = $(CROSS_COMPILE)objcopy
CFLAGS += -mcpu=cortex-m3 -mthumb \ OPT_FLAGS = -Os
-DSTM32F1 -DDISCOVERY_STLINK -I../libopencm3/include \ CFLAGS += -mcpu=cortex-m3 -mthumb -DSTM32F1 -I../libopencm3/include \
-I platforms/stm32 -I platforms/stm32
LDFLAGS_BOOT := $(LDFLAGS) --specs=nano.specs -lopencm3_stm32f1 \ LDFLAGS_BOOT := $(LDFLAGS) --specs=nano.specs -lopencm3_stm32f1 \
-Wl,-T,platforms/stm32/stlink.ld -nostartfiles -lc \ -Wl,-T,platforms/stm32/stlink.ld -nostartfiles -lc \
@ -12,9 +12,10 @@ LDFLAGS_BOOT := $(LDFLAGS) --specs=nano.specs -lopencm3_stm32f1 \
-L../libopencm3/lib -L../libopencm3/lib
ifeq ($(ST_BOOTLOADER), 1) ifeq ($(ST_BOOTLOADER), 1)
$(info Load address 0x08004000 for original ST-LinkV2 Bootloader) $(info Load address 0x08004000 for original ST-LinkV2 Bootloader)
CFLAGS += -DST_BOOTLOADER CFLAGS += -DST_BOOTLOADER -DDFU_SERIAL_LENGTH=25
LDFLAGS = $(LDFLAGS_BOOT) -Wl,-Ttext=0x8004000 LDFLAGS = $(LDFLAGS_BOOT) -Wl,-Ttext=0x8004000
else else
CFLAGS += -DDFU_SERIAL_LENGTH=9
LDFLAGS = $(LDFLAGS_BOOT) -Wl,-Ttext=0x8002000 LDFLAGS = $(LDFLAGS_BOOT) -Wl,-Ttext=0x8002000
endif endif
@ -40,7 +41,7 @@ all: blackmagic.bin
else else
all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex
endif endif
blackmagic_dfu.elf: usbdfu.o dfucore.o dfu_f1.o stlink_common.o blackmagic_dfu.elf: usbdfu.o dfucore.o dfu_f1.o stlink_common.o serialno.o
@echo " LD $@" @echo " LD $@"
$(Q)$(CC) $^ -o $@ $(LDFLAGS_BOOT) $(Q)$(CC) $^ -o $@ $(LDFLAGS_BOOT)

View File

@ -19,10 +19,11 @@
#include "general.h" #include "general.h"
#include "version.h" #include "version.h"
#include "serialno.h"
#include <string.h>
#include <libopencm3/stm32/desig.h> #include <libopencm3/stm32/desig.h>
#include <string.h>
#if defined(STM32F1HD) #if defined(STM32F1HD)
# define DFU_IFACE_STRING "@Internal Flash /0x08000000/4*002Ka,000*002Kg" # define DFU_IFACE_STRING "@Internal Flash /0x08000000/4*002Ka,000*002Kg"
# define DFU_IFACE_STRING_OFFSET 38 # define DFU_IFACE_STRING_OFFSET 38
@ -124,7 +125,7 @@ const struct usb_config_descriptor config = {
.interface = ifaces, .interface = ifaces,
}; };
static char serial_no[9]; static char serial_no[DFU_SERIAL_LENGTH];
static char if_string[] = DFU_IFACE_STRING; static char if_string[] = DFU_IFACE_STRING;
#define BOARD_IDENT_DFU(BOARD_TYPE) "Black Magic Probe DFU " PLATFORM_IDENT "" FIRMWARE_VERSION #define BOARD_IDENT_DFU(BOARD_TYPE) "Black Magic Probe DFU " PLATFORM_IDENT "" FIRMWARE_VERSION
@ -338,11 +339,6 @@ static void set_dfu_iface_string(uint32_t size)
static char *get_dev_unique_id(char *s) static char *get_dev_unique_id(char *s)
{ {
volatile uint32_t *unique_id_p = (volatile uint32_t *)DESIG_UNIQUE_ID_BASE;
uint32_t unique_id = *unique_id_p +
*(unique_id_p + 1) +
*(unique_id_p + 2);
int i;
uint32_t fuse_flash_size; uint32_t fuse_flash_size;
/* Calculated the upper flash limit from the exported data /* Calculated the upper flash limit from the exported data
@ -352,14 +348,5 @@ static char *get_dev_unique_id(char *s)
fuse_flash_size = 0x80; fuse_flash_size = 0x80;
set_dfu_iface_string(fuse_flash_size - 8); set_dfu_iface_string(fuse_flash_size - 8);
max_address = FLASH_BASE + (fuse_flash_size << 10); max_address = FLASH_BASE + (fuse_flash_size << 10);
/* Fetch serial number from chip's unique ID */ return serial_no_read(s);
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;
return s;
} }

View File

@ -18,30 +18,49 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "general.h" #include "general.h"
#include <libopencm3/stm32/desig.h>
char *serial_no_read(char *s, int max) char *serial_no_read(char *s)
{ {
#if defined(STM32F1) || defined(USE_BMP_SERIAL) #if DFU_SERIAL_LENGTH == 9
/* Only STM32F103 has no DFU Bootloader. Generate a ID comatible int i;
* with the BMP Bootloader since ages. volatile uint32_t *unique_id_p = (volatile uint32_t *)DESIG_UNIQUE_ID_BASE;
*/
uint32_t *unique_id_p = (uint32_t *)DESIG_UNIQUE_ID_BASE;
uint32_t unique_id = *unique_id_p + uint32_t unique_id = *unique_id_p +
*(unique_id_p + 1) + *(unique_id_p + 1) +
*(unique_id_p + 2); *(unique_id_p + 2);
snprintf(s, max, "%08" PRIX32, unique_id); /* Fetch serial number from chip's unique ID */
#else 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;
#elif DFU_SERIAL_LENGTH == 13
/* Use the same serial number as the ST DFU Bootloader.*/ /* Use the same serial number as the ST DFU Bootloader.*/
uint16_t *uid = (uint16_t *)DESIG_UNIQUE_ID_BASE; uint16_t *uid = (uint16_t *)DESIG_UNIQUE_ID_BASE;
# if defined(STM32F4) # if defined(STM32F4) || defined(STM32F7)
int offset = 3; int offset = 3;
# elif defined(STM32L0) || defined(STM32F3) # elif defined(STM32L0) || defined(STM32F3)
int offset = 5; int offset = 5;
# endif # endif
snprintf(s, max, "%04X%04X%04X", sprintf(s, "%04X%04X%04X",
uid[1] + uid[5], uid[0] + uid[4], uid[offset]); uid[1] + uid[5], uid[0] + uid[4], uid[offset]);
#elif DFU_SERIAL_LENGTH == 25
int i;
uint32_t unique_id[3];
memcpy(unique_id, (uint32_t *)DESIG_UNIQUE_ID_BASE, 12);
for(i = 0; i < 8; i++) {
s[ 7-i] = ((unique_id[0] >> (4*i)) & 0xF) + '0';
s[15-i] = ((unique_id[1] >> (4*i)) & 0xF) + '0';
s[23-i] = ((unique_id[2] >> (4*i)) & 0xF) + '0';
}
for (i = 0; i < 24; i++)
if(s[i] > '9')
s[i] += 'A' - '9' - 1;
#else
# WARNING "Unhandled DFU_SERIAL_LENGTH"
#endif #endif
s[DFU_SERIAL_LENGTH - 1] = 0;
return s; return s;
} }

View File

@ -3,7 +3,7 @@ CC = $(CROSS_COMPILE)gcc
OBJCOPY = $(CROSS_COMPILE)objcopy OBJCOPY = $(CROSS_COMPILE)objcopy
CFLAGS += -mcpu=cortex-m3 -mthumb \ CFLAGS += -mcpu=cortex-m3 -mthumb \
-DSTM32F1 -DDISCOVERY_SWLINK -I../libopencm3/include \ -DSTM32F1 -DDFU_SERIAL_LENGTH=9 -I../libopencm3/include \
-I platforms/stm32 -I platforms/stm32
LDFLAGS_BOOT := $(LDFLAGS) --specs=nano.specs -lopencm3_stm32f1 \ LDFLAGS_BOOT := $(LDFLAGS) --specs=nano.specs -lopencm3_stm32f1 \
-Wl,-T,platforms/stm32/stlink.ld -nostartfiles -lc\ -Wl,-T,platforms/stm32/stlink.ld -nostartfiles -lc\
@ -30,7 +30,7 @@ SRC += cdcacm.c \
all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex
blackmagic_dfu.elf: usbdfu.o dfucore.o dfu_f1.o platform_common.o blackmagic_dfu.elf: usbdfu.o dfucore.o dfu_f1.o platform_common.o serialno.o
@echo " LD $@" @echo " LD $@"
$(Q)$(CC) $^ -o $@ $(LDFLAGS_BOOT) $(Q)$(CC) $^ -o $@ $(LDFLAGS_BOOT)