Merge commit '5107a29699904fb4e60907d1e9b2438592f6a3ff' into sam-update
This commit is contained in:
commit
885fdcc354
12
Makefile
12
Makefile
@ -3,16 +3,28 @@ MFLAGS += --no-print-dir
|
|||||||
Q := @
|
Q := @
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
PC_HOSTED =
|
||||||
|
ifeq ($(PROBE_HOST), libftdi)
|
||||||
|
PC_HOSTED = true
|
||||||
|
endif
|
||||||
|
ifeq ($(PROBE_HOST), pc-stlinkv2)
|
||||||
|
PC_HOSTED = true
|
||||||
|
endif
|
||||||
|
|
||||||
all:
|
all:
|
||||||
|
ifndef PC_HOSTED
|
||||||
$(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 ;\
|
||||||
git submodule update ;\
|
git submodule update ;\
|
||||||
fi
|
fi
|
||||||
$(Q)$(MAKE) $(MFLAGS) -C libopencm3 lib
|
$(Q)$(MAKE) $(MFLAGS) -C libopencm3 lib
|
||||||
|
endif
|
||||||
$(Q)$(MAKE) $(MFLAGS) -C src
|
$(Q)$(MAKE) $(MFLAGS) -C src
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
ifndef PC_HOSTED
|
||||||
$(Q)$(MAKE) $(MFLAGS) -C libopencm3 $@
|
$(Q)$(MAKE) $(MFLAGS) -C libopencm3 $@
|
||||||
|
endif
|
||||||
$(Q)$(MAKE) $(MFLAGS) -C src $@
|
$(Q)$(MAKE) $(MFLAGS) -C src $@
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
#if !defined(timersub)
|
#if !defined(timersub)
|
||||||
@ -206,7 +207,7 @@ typedef struct {
|
|||||||
uint16_t vid;
|
uint16_t vid;
|
||||||
uint16_t pid;
|
uint16_t pid;
|
||||||
uint8_t transport_mode;
|
uint8_t transport_mode;
|
||||||
uint8_t serial[32];
|
char serial[32];
|
||||||
uint8_t dap_select;
|
uint8_t dap_select;
|
||||||
uint8_t ep_tx;
|
uint8_t ep_tx;
|
||||||
uint8_t ver_hw; /* 20, 21 or 31 deciphered from USB PID.*/
|
uint8_t ver_hw; /* 20, 21 or 31 deciphered from USB PID.*/
|
||||||
@ -719,16 +720,38 @@ void stlink_init(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
r = libusb_open(dev, &Stlink.handle);
|
r = libusb_open(dev, &Stlink.handle);
|
||||||
if (r == LIBUSB_SUCCESS) {
|
if (r == LIBUSB_SUCCESS) {
|
||||||
|
uint8_t data[32];
|
||||||
|
uint16_t lang;
|
||||||
|
libusb_get_string_descriptor(
|
||||||
|
Stlink.handle, 0, 0, data, sizeof(data));
|
||||||
|
lang = data[2] << 8 | data[3];
|
||||||
|
unsigned char sernum[32];
|
||||||
if (desc.iSerialNumber) {
|
if (desc.iSerialNumber) {
|
||||||
r = libusb_get_string_descriptor_ascii
|
r = libusb_get_string_descriptor
|
||||||
(Stlink.handle,desc.iSerialNumber, Stlink.serial,
|
(Stlink.handle, desc.iSerialNumber, lang,
|
||||||
sizeof(Stlink.serial));
|
sernum, sizeof(sernum));
|
||||||
} else {
|
} else {
|
||||||
DEBUG("No serial number\n");
|
DEBUG("No serial number\n");
|
||||||
}
|
}
|
||||||
if (serial && (!strncmp((char*)Stlink.serial, serial, strlen(serial))))
|
/* Older devices have hex values instead of ascii
|
||||||
|
* in the serial string. Recode eventually!*/
|
||||||
|
bool readable = true;
|
||||||
|
uint16_t *p = (uint16_t *)sernum;
|
||||||
|
for (p += 1; *p; p++) {
|
||||||
|
bool isr = isalnum(*p);
|
||||||
|
readable &= isr;
|
||||||
|
}
|
||||||
|
char *s = Stlink.serial;
|
||||||
|
p = (uint16_t *)sernum;
|
||||||
|
for (p += 1; *p; p++, s++) {
|
||||||
|
if (readable)
|
||||||
|
*s = *p;
|
||||||
|
else
|
||||||
|
snprintf(s, 3, "%02x", *p & 0xff);
|
||||||
|
}
|
||||||
|
if (serial && (!strncmp(Stlink.serial, serial, strlen(serial))))
|
||||||
DEBUG("Found ");
|
DEBUG("Found ");
|
||||||
if (!serial || (!strncmp((char*)Stlink.serial, serial, strlen(serial)))) {
|
if (!serial || (!strncmp(Stlink.serial, serial, strlen(serial)))) {
|
||||||
if (desc.idProduct == PRODUCT_ID_STLINKV2) {
|
if (desc.idProduct == PRODUCT_ID_STLINKV2) {
|
||||||
DEBUG("STLINKV20 serial %s\n", Stlink.serial);
|
DEBUG("STLINKV20 serial %s\n", Stlink.serial);
|
||||||
Stlink.ver_hw = 20;
|
Stlink.ver_hw = 20;
|
||||||
@ -753,7 +776,7 @@ void stlink_init(int argc, char **argv)
|
|||||||
DEBUG("Unknown STLINK variant, serial %s\n", Stlink.serial);
|
DEBUG("Unknown STLINK variant, serial %s\n", Stlink.serial);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (serial && (!strncmp((char*)Stlink.serial, serial, strlen(serial))))
|
if (serial && (!strncmp(Stlink.serial, serial, strlen(serial))))
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
DEBUG("Open failed %s\n", libusb_strerror(r));
|
DEBUG("Open failed %s\n", libusb_strerror(r));
|
||||||
|
@ -1,5 +1,13 @@
|
|||||||
OUTFILE = blackmagic_upgrade
|
OUTFILE = blackmagic_upgrade
|
||||||
|
|
||||||
|
PC_HOSTED =
|
||||||
|
ifeq ($(PROBE_HOST), libftdi)
|
||||||
|
PC_HOSTED = true
|
||||||
|
endif
|
||||||
|
ifeq ($(PROBE_HOST), pc-stlinkv2)
|
||||||
|
PC_HOSTED = true
|
||||||
|
endif
|
||||||
|
|
||||||
CC = $(CROSS_COMPILE)gcc
|
CC = $(CROSS_COMPILE)gcc
|
||||||
|
|
||||||
CFLAGS = -Wall -Wextra -std=gnu99 -O0 -g -MD -mno-ms-bitfields
|
CFLAGS = -Wall -Wextra -std=gnu99 -O0 -g -MD -mno-ms-bitfields
|
||||||
@ -10,7 +18,29 @@ OBJ = bindata.o \
|
|||||||
stm32mem.o \
|
stm32mem.o \
|
||||||
main.o
|
main.o
|
||||||
|
|
||||||
|
ifndef $(PROBE_HOST)
|
||||||
|
PROBE_HOST=native
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifndef PC_HOSTED
|
||||||
all: $(OUTFILE)
|
all: $(OUTFILE)
|
||||||
|
else
|
||||||
|
all:
|
||||||
|
ifeq ($(PROBE_HOST), libftdi)
|
||||||
|
@echo "Libftdi needs no firmware update"
|
||||||
|
endif
|
||||||
|
ifeq ($(PROBE_HOST), pc-stlinkv2)
|
||||||
|
@echo "Pc-stlinkv2 use ST provided tools for firmware update"
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
bindata.o: $(PROBE_HOST).d
|
||||||
|
|
||||||
|
$(PROBE_HOST).d: ../src/blackmagic.bin
|
||||||
|
-rm *.d
|
||||||
|
make -C ../src $0 clean
|
||||||
|
make -C ../src $0
|
||||||
|
touch $(PROBE_HOST).d
|
||||||
|
|
||||||
$(OUTFILE) $(OUTFILE).exe: $(OBJ)
|
$(OUTFILE) $(OUTFILE).exe: $(OBJ)
|
||||||
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
|
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
|
||||||
|
@ -157,7 +157,7 @@ retry:
|
|||||||
printf("Progress: %d%%\r", (offset*100)/bindatalen);
|
printf("Progress: %d%%\r", (offset*100)/bindatalen);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
assert(stm32_mem_erase(handle, iface, LOAD_ADDRESS + offset) == 0);
|
assert(stm32_mem_erase(handle, iface, LOAD_ADDRESS + offset) == 0);
|
||||||
stm32_mem_write(handle, iface, (void*)&bindata[offset], 1024);
|
stm32_mem_write(handle, iface, (void*)&bindata[offset], 1024, LOAD_ADDRESS + offset);
|
||||||
}
|
}
|
||||||
stm32_mem_manifest(handle, iface);
|
stm32_mem_manifest(handle, iface);
|
||||||
|
|
||||||
|
@ -69,8 +69,13 @@ int stm32_mem_erase(usb_dev_handle *dev, uint16_t iface, uint32_t addr)
|
|||||||
return stm32_download(dev, iface, 0, request, sizeof(request));
|
return stm32_download(dev, iface, 0, request, sizeof(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
int stm32_mem_write(usb_dev_handle *dev, uint16_t iface, void *data, int size)
|
int stm32_mem_write(usb_dev_handle *dev, uint16_t iface, void *data, int size, uint32_t addr)
|
||||||
{
|
{
|
||||||
|
uint8_t request[5];
|
||||||
|
|
||||||
|
request[0] = STM32_CMD_SETADDRESSPOINTER;
|
||||||
|
memcpy(request+1, &addr, sizeof(addr));
|
||||||
|
stm32_download(dev, iface, 0, request, sizeof(request));
|
||||||
return stm32_download(dev, iface, 2, data, size);
|
return stm32_download(dev, iface, 2, data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
int stm32_mem_erase(usb_dev_handle *dev, uint16_t iface, uint32_t addr);
|
int stm32_mem_erase(usb_dev_handle *dev, uint16_t iface, uint32_t addr);
|
||||||
int stm32_mem_write(usb_dev_handle *dev, uint16_t iface, void *data, int size);
|
int stm32_mem_write(usb_dev_handle *dev, uint16_t iface, void *data, int size, uint32_t addr);
|
||||||
int stm32_mem_manifest(usb_dev_handle *dev, uint16_t iface);
|
int stm32_mem_manifest(usb_dev_handle *dev, uint16_t iface);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user