STM32F103: Use flash size from device for DFU string.

Complements #204.
STLinkV2-1 has F103CB on board! F103C8 on older Stlinks can use upper flash
with hopefully acceptable error rate.
For F103C8 devices, user has to give the force option to dfu-utils.
This commit is contained in:
Uwe Bonnes 2017-04-27 19:00:15 +02:00
parent f450b1745d
commit b09a522f37
6 changed files with 38 additions and 10 deletions

View File

@ -33,9 +33,7 @@
#define PLATFORM_HAS_TRACESWO
#define BOARD_IDENT "Black Magic Probe (F4Discovery), (Firmware " FIRMWARE_VERSION ")"
#define BOARD_IDENT_DFU "Black Magic (Upgrade) for F4Discovery, (Firmware " FIRMWARE_VERSION ")"
#define DFU_IDENT "Black Magic Firmware Upgrade (F4Discovery"
#define DFU_IFACE_STRING "@Internal Flash /0x08000000/1*016Ka,3*016Kg,1*064Kg,7*128Kg"
/* Important pin mappings for STM32 implementation:
*

View File

@ -36,7 +36,6 @@
#define BOARD_IDENT "Black Magic Probe (HydraBus), (Firmware " FIRMWARE_VERSION ")"
#define BOARD_IDENT_DFU "Black Magic (Upgrade) for HydraBus, (Firmware " FIRMWARE_VERSION ")"
#define DFU_IDENT "Black Magic Firmware Upgrade (HydraBus)"
#define DFU_IFACE_STRING "@Internal Flash /0x08000000/1*016Ka,3*016Kg,1*064Kg,7*128Kg"
/* Important pin mappings for STM32 implementation:
*

View File

@ -38,7 +38,6 @@
#define BOARD_IDENT_DFU "Black Magic Probe (Upgrade)"
#define BOARD_IDENT_UPD "Black Magic Probe (DFU Upgrade)"
#define DFU_IDENT "Black Magic Firmware Upgrade"
#define DFU_IFACE_STRING "@Internal Flash /0x08000000/8*001Ka,120*001Kg"
#define UPD_IFACE_STRING "@Internal Flash /0x08000000/8*001Kg"
/* Important pin mappings for STM32 implementation:

View File

@ -37,7 +37,6 @@
#define BOARD_IDENT_DFU "Black Magic (Upgrade) for STLink/Discovery, (Firmware " FIRMWARE_VERSION ")"
#define BOARD_IDENT_UPD "Black Magic (DFU Upgrade) for STLink/Discovery, (Firmware " FIRMWARE_VERSION ")"
#define DFU_IDENT "Black Magic Firmware Upgrade (STLINK)"
#define DFU_IFACE_STRING "@Internal Flash /0x08000000/8*001Ka,56*001Kg"
#define UPD_IFACE_STRING "@Internal Flash /0x08000000/8*001Kg"
/* Important pin mappings for STM32 implementation:

View File

@ -22,10 +22,11 @@
#include <string.h>
#if defined(STM32F1)
# include <libopencm3/stm32/f1/flash.h>
#elif defined(STM32F2)
# include <libopencm3/stm32/f2/flash.h>
# define DFU_IFACE_STRING "@Internal Flash /0x08000000/8*001Ka,000*001Kg"
# define DFU_IFACE_STRING_OFFSET 38
#elif defined(STM32F4)
# include <libopencm3/stm32/f4/flash.h>
# define DFU_IFACE_STRING "/0x08000000/1*016Ka,3*016Kg,1*064Kg,7*128Kg"
#endif
#include <libopencm3/usb/usbd.h>
#include <libopencm3/usb/dfu.h>
@ -113,13 +114,14 @@ const struct usb_config_descriptor config = {
};
static char serial_no[9];
static char if_string[] = DFU_IFACE_STRING;
static const char *usb_strings[] = {
"Black Sphere Technologies",
BOARD_IDENT_DFU,
serial_no,
/* This string is used by ST Microelectronics' DfuSe utility */
DFU_IFACE_STRING,
if_string,
};
static const char *usb_strings_upd[] = {
@ -297,6 +299,33 @@ void dfu_main(void)
usbd_poll(usbdev);
}
#if defined(DFU_IFACE_STRING_OFFSET)
static void set_dfu_iface_string(uint32_t size)
{
uint32_t res;
char *p = if_string + DFU_IFACE_STRING_OFFSET;
/* We do not want the whole printf library in the bootloader.
* Fill the size digits by hand.
*/
res = size / 100;
if (res > 9) {
*p++ = '9';
*p++ = '9';
*p++ = '9';
return;
} else {
*p++ = res + '0';
size -= res * 100;
}
res = size / 10;
*p++ = res + '0';
size -= res * 10;
*p++ = size + '0';
}
#else
# define set_dfu_iface_string()
#endif
static char *get_dev_unique_id(char *s)
{
#if defined(STM32F4) || defined(STM32F2)
@ -317,10 +346,15 @@ static char *get_dev_unique_id(char *s)
*(unique_id_p + 1) +
*(unique_id_p + 2);
int i;
uint32_t fuse_flash_size;
/* Calculated the upper flash limit from the exported data
in theparameter block*/
max_address = (*(uint32_t *) FLASH_SIZE_R) <<10;
fuse_flash_size = *(uint32_t *) FLASH_SIZE_R & 0xfff;
set_dfu_iface_string(fuse_flash_size - 8);
if (fuse_flash_size == 0x40) /* Handle F103x8 as F103xC! */
fuse_flash_size = 0x80;
max_address = FLASH_BASE + (fuse_flash_size << 10);
/* Fetch serial number from chip's unique ID */
for(i = 0; i < 8; i++) {
s[7-i] = ((unique_id >> (4*i)) & 0xF) + '0';

View File

@ -33,7 +33,6 @@
#define BOARD_IDENT_DFU "Black Magic (Upgrade), STM8S Discovery, (Firmware " FIRMWARE_VERSION ")"
#define BOARD_IDENT_UPD "Black Magic (DFU Upgrade), STM8S Discovery, (Firmware " FIRMWARE_VERSION ")"
#define DFU_IDENT "Black Magic Firmware Upgrade (SWLINK)"
#define DFU_IFACE_STRING "@Internal Flash /0x08000000/8*001Ka,56*001Kg"
#define UPD_IFACE_STRING "@Internal Flash /0x08000000/8*001Kg"
/* Pin mappings: