Merge branch 'develop' into f2023_1

pull/1300/head
nightwalker-87 2023-02-14 21:16:21 +01:00 zatwierdzone przez GitHub
commit f875a7f0c9
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
7 zmienionych plików z 225 dodań i 217 usunięć

Wyświetl plik

@ -166,35 +166,41 @@ add_subdirectory(inc)
set(STLINK_HEADERS
inc/backend.h
inc/stlink.h
src/stlink-lib/common_flash.h
inc/stm32.h
inc/stm32flash.h
src/stlink-lib/calculate.h
src/stlink-lib/commands.h
src/stlink-lib/libusb_settings.h
src/stlink-lib/reg.h
src/stlink-lib/chipid.h
src/stlink-lib/commands.h
src/stlink-lib/common_flash.h
src/stlink-lib/common.h
src/stlink-lib/flash_loader.h
src/stlink-lib/flashloader.h
src/stlink-lib/helper.h
src/stlink-lib/libusb_settings.h
src/stlink-lib/logging.h
src/stlink-lib/map_file.h
src/stlink-lib/md5.h
src/stlink-lib/option_bytes.h
src/stlink-lib/reg.h
src/stlink-lib/sg.h
src/stlink-lib/usb.h
src/stlink-lib/helper.h
)
set(STLINK_SOURCE
src/stlink-lib/read_write.c
src/stlink-lib/common.c
src/stlink-lib/option_bytes.c
src/stlink-lib/common_flash.c
src/stlink-lib/map_file.c
src/stlink-lib/flashloader.c
src/stlink-lib/calculate.c
src/stlink-lib/chipid.c
src/stlink-lib/common_flash.c
src/stlink-lib/common.c
src/stlink-lib/flash_loader.c
src/stlink-lib/flashloader.c
src/stlink-lib/helper.c
src/stlink-lib/logging.c
src/stlink-lib/map_file.c
src/stlink-lib/md5.c
src/stlink-lib/option_bytes.c
src/stlink-lib/read_write.c
src/stlink-lib/sg.c
src/stlink-lib/usb.c
src/stlink-lib/helper.c
)
if (WIN32)

Wyświetl plik

@ -79,6 +79,7 @@ We recommend to install `stlink-tools` from the package repository of the used d
- Alpine Linux: [(Link)](https://pkgs.alpinelinux.org/packages?name=stlink)
- Fedora: [(Link)](https://src.fedoraproject.org/rpms/stlink)
- FreeBSD: Users can install from [freshports](https://www.freshports.org/devel/stlink)
- MacOS: **Support for macOS will end with v1.7.1.** Please use v1.7.0 (current ***master*** branch) and the related documentation instead.
## Installation from source (advanced users)

Wyświetl plik

@ -72,7 +72,7 @@ elseif (WIN32 OR (EXISTS "/etc/debian_version" AND MINGW)) # Windows or MinGW-to
message(STATUS "downloading libusb ${LIBUSB_WIN_VERSION}")
file(DOWNLOAD
https://sourceforge.net/projects/libusb/files/libusb-1.0/libusb-${LIBUSB_WIN_VERSION}/libusb-${LIBUSB_WIN_VERSION}.7z/download
${LIBUSB_WIN_ARCHIVE_PATH} EXPECTED_MD5 cf3d38d2ff053ef343d10c0b8b0950c2
${LIBUSB_WIN_ARCHIVE_PATH} EXPECTED_MD5 aabe177bde869bfad34278335eaf8955
)
endif ()

Wyświetl plik

@ -2,7 +2,7 @@ Source: stlink
Priority: optional
Maintainer: Nightwalker-87 <stlink-org>
Build-Depends: cmake (>= 3.10.2), dh-cmake, debhelper (>= 9), libusb-1.0-0-dev (>= 1.0.21), libgtk-3-dev (>= 3.22.30)
Standards-Version: 4.5.0
Standards-Version: 4.6.2
Rules-Requires-Root: no
Section: electronics
Homepage: https://github.com/stlink-org/stlink

Wyświetl plik

@ -88,8 +88,9 @@ Tested non-official ST boards [incl. STLINK programmers]:
| Product-Code | Chip-ID | STLINK<br />Programmer | Boards |
| ------------ | ------- | ---------------------- | ---------------------------------- |
| GD32F303VGT6 | 0x430 | [v2] | STM32F303 clone from GigaDevice GD |
| GD32F303CGT6 | 0x430 | [v2] | STM32F303 clone from GigaDevice GD |
| GD32F303VET6 | 0x414 | [v2] | STM32F303 clone from GigaDevice GD |
| GD32F303VGT6 | 0x430 | [v2] | STM32F303 clone from GigaDevice GD |
## STM32F4 / ARM Cortex M4F

Wyświetl plik

@ -88,7 +88,7 @@ static void abort_trace() { g_abort_trace = true; }
BOOL WINAPI CtrlHandler(DWORD fdwCtrlType) {
(void)fdwCtrlType;
abort_trace();
return FALSE;
return TRUE;
}
#endif

Wyświetl plik

@ -1,248 +1,248 @@
#include <stm32.h>
#include <stlink.h>
#include "chipid.h"
#include <stlink.h>
#include <stm32.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
static struct stlink_chipid_params *devicelist;
void dump_a_chip (struct stlink_chipid_params *dev) {
DLOG("# Device Type: %s\n", dev->dev_type);
DLOG("# Reference Manual: RM%s\n", dev->ref_manual_id);
DLOG("#\n");
DLOG("chip_id 0x%x\n", dev->chip_id);
DLOG("flash_type %d\n", dev->flash_type);
DLOG("flash_size_reg 0x%x\n", dev->flash_size_reg);
DLOG("flash_pagesize 0x%x\n", dev->flash_pagesize);
DLOG("sram_size 0x%x\n", dev->sram_size);
DLOG("bootrom_base 0x%x\n", dev->bootrom_base);
DLOG("bootrom_size 0x%x\n", dev->bootrom_size);
DLOG("option_base 0x%x\n", dev->option_base);
DLOG("option_size 0x%x\n", dev->option_size);
DLOG("flags %d\n\n", dev->flags);
void dump_a_chip(struct stlink_chipid_params *dev) {
DLOG("# Device Type: %s\n", dev->dev_type);
DLOG("# Reference Manual: RM%s\n", dev->ref_manual_id);
DLOG("#\n");
DLOG("chip_id 0x%x\n", dev->chip_id);
DLOG("flash_type %d\n", dev->flash_type);
DLOG("flash_size_reg 0x%x\n", dev->flash_size_reg);
DLOG("flash_pagesize 0x%x\n", dev->flash_pagesize);
DLOG("sram_size 0x%x\n", dev->sram_size);
DLOG("bootrom_base 0x%x\n", dev->bootrom_base);
DLOG("bootrom_size 0x%x\n", dev->bootrom_size);
DLOG("option_base 0x%x\n", dev->option_base);
DLOG("option_size 0x%x\n", dev->option_size);
DLOG("flags %d\n\n", dev->flags);
}
struct stlink_chipid_params *stlink_chipid_get_params(uint32_t chip_id) {
struct stlink_chipid_params *params = NULL;
for (params = devicelist; params != NULL; params = params->next)
if (params->chip_id == chip_id) {
DLOG("detected chip_id parameters\n\n");
dump_a_chip(params);
break;
}
struct stlink_chipid_params *params = NULL;
for (params = devicelist; params != NULL; params = params->next)
if (params->chip_id == chip_id) {
DLOG("detected chip_id parameters\n\n");
dump_a_chip(params);
break;
}
return(params);
return (params);
}
void process_chipfile(char *fname) {
FILE *fp;
char *p, buf[256];
char word[64], value[64];
struct stlink_chipid_params *ts;
int nc;
FILE *fp;
char *p, buf[256];
char word[64], value[64];
struct stlink_chipid_params *ts;
int nc;
// fprintf (stderr, "processing chip-id file %s.\n", fname);
fp = fopen(fname, "r");
// fprintf (stderr, "processing chip-id file %s.\n", fname);
fp = fopen(fname, "r");
if (!fp) {
perror(fname);
return;
}
if (!fp) {
perror(fname);
return;
}
ts = calloc(sizeof(struct stlink_chipid_params), 1);
ts = calloc(sizeof(struct stlink_chipid_params), 1);
while (fgets(buf, sizeof(buf), fp) != NULL) {
while (fgets(buf, sizeof(buf), fp) != NULL) {
if (strncmp(buf, "#", strlen("#")) == 0)
continue; // ignore comments
if (strncmp(buf, "#", strlen("#")) == 0)
continue; // ignore comments
if ((strncmp(buf, "\n", strlen("\n")) == 0) ||
(strncmp(buf, " ", strlen(" ")) == 0))
continue; // ignore empty lines
if ((strncmp(buf, "\n", strlen("\n")) == 0) ||
(strncmp(buf, " ", strlen(" ")) == 0))
continue; // ignore empty lines
sscanf(buf, "%s %s", word, value);
sscanf(buf, "%s %s", word, value);
if (strcmp (word, "dev_type") == 0) {
buf[strlen(buf) - 1] = 0; // chomp newline
sscanf(buf, "%*s %n", &nc);
ts->dev_type = strdup(buf + nc);
} else if (strcmp(word, "ref_manual_id") == 0) {
buf[strlen(buf) - 1] = 0; // chomp newline
sscanf(buf, "%*s %n", &nc);
ts->ref_manual_id = strdup(buf + nc);
} else if (strcmp(word, "chip_id") == 0) {
buf[strlen(buf) - 1] = 0; // chomp newline
sscanf(buf, "%*s %n", &nc);
if (sscanf(value, "%i", &ts->chip_id) < 1) {
fprintf(stderr, "Failed to parse chip-id\n");
}
} else if (strcmp(word, "flash_type") == 0) {
buf[strlen(buf) - 1] = 0; // chomp newline
sscanf(buf, "%*s %n", &nc);
if (strcmp(value, "F0_F1_F3") == 0) {
ts->flash_type = STM32_FLASH_TYPE_F0_F1_F3;
} else if (strcmp(value, "F1_XL") == 0) {
ts->flash_type = STM32_FLASH_TYPE_F1_XL;
} else if (strcmp(value, "F2_F4") == 0) {
ts->flash_type = STM32_FLASH_TYPE_F2_F4;
} else if (strcmp(value, "F7") == 0) {
ts->flash_type = STM32_FLASH_TYPE_F7;
} else if (strcmp(value, "G0") == 0) {
ts->flash_type = STM32_FLASH_TYPE_G0;
} else if (strcmp(value, "G4") == 0) {
ts->flash_type = STM32_FLASH_TYPE_G4;
} else if (strcmp(value, "H7") == 0) {
ts->flash_type = STM32_FLASH_TYPE_H7;
} else if (strcmp(value, "L0_L1") == 0) {
ts->flash_type = STM32_FLASH_TYPE_L0_L1;
} else if (strcmp(value, "L4_L4P") == 0) {
ts->flash_type = STM32_FLASH_TYPE_L4;
} else if (strcmp(value, "L5_U5") == 0) {
ts->flash_type = STM32_FLASH_TYPE_L5_U5;
} else if (strcmp(value, "WB_WL") == 0) {
ts->flash_type = STM32_FLASH_TYPE_WB_WL;
} else {
ts->flash_type = STM32_FLASH_TYPE_UNKNOWN;
}
} else if (strcmp(word, "flash_size_reg") == 0) {
buf[strlen(buf) - 1] = 0; // chomp newline
sscanf(buf, "%*s %n", &nc);
if (sscanf(value, "%i", &ts->flash_size_reg) < 1) {
fprintf(stderr, "Failed to parse flash size reg\n");
}
} else if (strcmp(word, "flash_pagesize") == 0) {
buf[strlen(buf) - 1] = 0; // chomp newline
sscanf(buf, "%*s %n", &nc);
if (sscanf(value, "%i", &ts->flash_pagesize) < 1) {
fprintf(stderr, "Failed to parse flash page size\n");
}
} else if (strcmp(word, "sram_size") == 0) {
buf[strlen(buf) - 1] = 0; // chomp newline
sscanf(buf, "%*s %n", &nc);
if (sscanf(value, "%i", &ts->sram_size) < 1) {
fprintf(stderr, "Failed to parse SRAM size\n");
}
} else if (strcmp(word, "bootrom_base") == 0) {
buf[strlen(buf) - 1] = 0; // chomp newline
sscanf(buf, "%*s %n", &nc);
if (sscanf(value, "%i", &ts->bootrom_base) < 1) {
fprintf(stderr, "Failed to parse BootROM base\n");
}
} else if (strcmp(word, "bootrom_size") == 0) {
buf[strlen(buf) - 1] = 0; // chomp newline
sscanf(buf, "%*s %n", &nc);
if (sscanf(value, "%i", &ts->bootrom_size) < 1) {
fprintf(stderr, "Failed to parse BootROM size\n");
}
} else if (strcmp(word, "option_base") == 0) {
buf[strlen(buf) - 1] = 0; // chomp newline
sscanf(buf, "%*s %n", &nc);
if (sscanf(value, "%i", &ts->option_base) < 1) {
fprintf(stderr, "Failed to parse option base\n");
}
} else if (strcmp(word, "option_size") == 0) {
buf[strlen(buf) - 1] = 0; // chomp newline
sscanf(buf, "%*s %n", &nc);
if (sscanf(value, "%i", &ts->option_size) < 1) {
fprintf(stderr, "Failed to parse option size\n");
}
} else if (strcmp(word, "flags") == 0) {
buf[strlen(buf) - 1] = 0; // chomp newline
sscanf(buf, "%*s %n", &nc);
p = strtok (buf, " \t\n");
if (strcmp(word, "dev_type") == 0) {
buf[strlen(buf) - 1] = 0; // chomp newline
sscanf(buf, "%*s %n", &nc);
ts->dev_type = strdup(buf + nc);
} else if (strcmp(word, "ref_manual_id") == 0) {
buf[strlen(buf) - 1] = 0; // chomp newline
sscanf(buf, "%*s %n", &nc);
ts->ref_manual_id = strdup(buf + nc);
} else if (strcmp(word, "chip_id") == 0) {
buf[strlen(buf) - 1] = 0; // chomp newline
sscanf(buf, "%*s %n", &nc);
if (sscanf(value, "%i", &ts->chip_id) < 1) {
fprintf(stderr, "Failed to parse chip-id\n");
}
} else if (strcmp(word, "flash_type") == 0) {
buf[strlen(buf) - 1] = 0; // chomp newline
sscanf(buf, "%*s %n", &nc);
if (strcmp(value, "F0_F1_F3") == 0) {
ts->flash_type = STM32_FLASH_TYPE_F0_F1_F3;
} else if (strcmp(value, "F1_XL") == 0) {
ts->flash_type = STM32_FLASH_TYPE_F1_XL;
} else if (strcmp(value, "F2_F4") == 0) {
ts->flash_type = STM32_FLASH_TYPE_F2_F4;
} else if (strcmp(value, "F7") == 0) {
ts->flash_type = STM32_FLASH_TYPE_F7;
} else if (strcmp(value, "G0") == 0) {
ts->flash_type = STM32_FLASH_TYPE_G0;
} else if (strcmp(value, "G4") == 0) {
ts->flash_type = STM32_FLASH_TYPE_G4;
} else if (strcmp(value, "H7") == 0) {
ts->flash_type = STM32_FLASH_TYPE_H7;
} else if (strcmp(value, "L0_L1") == 0) {
ts->flash_type = STM32_FLASH_TYPE_L0_L1;
} else if (strcmp(value, "L4") == 0) {
ts->flash_type = STM32_FLASH_TYPE_L4;
} else if (strcmp(value, "L5_U5") == 0) {
ts->flash_type = STM32_FLASH_TYPE_L5_U5;
} else if (strcmp(value, "WB_WL") == 0) {
ts->flash_type = STM32_FLASH_TYPE_WB_WL;
} else {
ts->flash_type = STM32_FLASH_TYPE_UNKNOWN;
}
} else if (strcmp(word, "flash_size_reg") == 0) {
buf[strlen(buf) - 1] = 0; // chomp newline
sscanf(buf, "%*s %n", &nc);
if (sscanf(value, "%i", &ts->flash_size_reg) < 1) {
fprintf(stderr, "Failed to parse flash size reg\n");
}
} else if (strcmp(word, "flash_pagesize") == 0) {
buf[strlen(buf) - 1] = 0; // chomp newline
sscanf(buf, "%*s %n", &nc);
if (sscanf(value, "%i", &ts->flash_pagesize) < 1) {
fprintf(stderr, "Failed to parse flash page size\n");
}
} else if (strcmp(word, "sram_size") == 0) {
buf[strlen(buf) - 1] = 0; // chomp newline
sscanf(buf, "%*s %n", &nc);
if (sscanf(value, "%i", &ts->sram_size) < 1) {
fprintf(stderr, "Failed to parse SRAM size\n");
}
} else if (strcmp(word, "bootrom_base") == 0) {
buf[strlen(buf) - 1] = 0; // chomp newline
sscanf(buf, "%*s %n", &nc);
if (sscanf(value, "%i", &ts->bootrom_base) < 1) {
fprintf(stderr, "Failed to parse BootROM base\n");
}
} else if (strcmp(word, "bootrom_size") == 0) {
buf[strlen(buf) - 1] = 0; // chomp newline
sscanf(buf, "%*s %n", &nc);
if (sscanf(value, "%i", &ts->bootrom_size) < 1) {
fprintf(stderr, "Failed to parse BootROM size\n");
}
} else if (strcmp(word, "option_base") == 0) {
buf[strlen(buf) - 1] = 0; // chomp newline
sscanf(buf, "%*s %n", &nc);
if (sscanf(value, "%i", &ts->option_base) < 1) {
fprintf(stderr, "Failed to parse option base\n");
}
} else if (strcmp(word, "option_size") == 0) {
buf[strlen(buf) - 1] = 0; // chomp newline
sscanf(buf, "%*s %n", &nc);
if (sscanf(value, "%i", &ts->option_size) < 1) {
fprintf(stderr, "Failed to parse option size\n");
}
} else if (strcmp(word, "flags") == 0) {
buf[strlen(buf) - 1] = 0; // chomp newline
sscanf(buf, "%*s %n", &nc);
p = strtok(buf, " \t\n");
while ((p = strtok (NULL, " \t\n"))) {
if (strcmp(p, "none") == 0) {
// NOP
} else if (strcmp(p, "dualbank") == 0) {
ts->flags |= CHIP_F_HAS_DUAL_BANK;
} else if (strcmp(p, "swo") == 0) {
ts->flags |= CHIP_F_HAS_SWO_TRACING;
} else {
fprintf(stderr, "Unknown flags word in %s: '%s'\n",
fname, p);
}
}
sscanf(value, "%x", &ts->flags);
while ((p = strtok(NULL, " \t\n"))) {
if (strcmp(p, "none") == 0) {
// NOP
} else if (strcmp(p, "dualbank") == 0) {
ts->flags |= CHIP_F_HAS_DUAL_BANK;
} else if (strcmp(p, "swo") == 0) {
ts->flags |= CHIP_F_HAS_SWO_TRACING;
} else {
fprintf(stderr, "Unknown keyword in %s: %s\n", fname, word);
fprintf(stderr, "Unknown flags word in %s: '%s'\n", fname, p);
}
}
sscanf(value, "%x", &ts->flags);
} else {
fprintf(stderr, "Unknown keyword in %s: %s\n", fname, word);
}
fclose(fp);
ts->next = devicelist;
devicelist = ts;
}
fclose(fp);
ts->next = devicelist;
devicelist = ts;
}
#if defined(STLINK_HAVE_DIRENT_H)
#include <dirent.h>
void init_chipids(char *dir_to_scan) {
DIR *d;
size_t nl; // namelen
struct dirent *dir;
DIR *d;
size_t nl; // namelen
struct dirent *dir;
if (!dir_to_scan) {
dir_to_scan = "./";
if (!dir_to_scan) {
dir_to_scan = "./";
}
devicelist = NULL;
d = opendir(dir_to_scan);
if (d) {
while ((dir = readdir(d)) != NULL) {
nl = strlen(dir->d_name);
if (strcmp(dir->d_name + nl - 5, ".chip") == 0) {
char buf[1024];
sprintf(buf, "%s/%s", dir_to_scan, dir->d_name);
process_chipfile(buf);
}
}
devicelist = NULL;
d = opendir(dir_to_scan);
if (d) {
while ((dir = readdir(d)) != NULL) {
nl = strlen(dir->d_name);
if (strcmp(dir->d_name + nl - 5, ".chip") == 0) {
char buf[1024];
sprintf(buf, "%s/%s", dir_to_scan, dir->d_name);
process_chipfile(buf);
}
}
closedir(d);
} else {
perror (dir_to_scan);
return;
}
closedir(d);
} else {
perror(dir_to_scan);
return;
}
}
#endif //STLINK_HAVE_DIRENT_H
#endif // STLINK_HAVE_DIRENT_H
#if defined(_WIN32) && !defined(STLINK_HAVE_DIRENT_H)
#include <fileapi.h>
#include <strsafe.h>
void init_chipids(char *dir_to_scan) {
HANDLE hFind = INVALID_HANDLE_VALUE;
WIN32_FIND_DATAA ffd;
char filepath[MAX_PATH] = {0};
HANDLE hFind = INVALID_HANDLE_VALUE;
WIN32_FIND_DATAA ffd;
char filepath[MAX_PATH] = {0};
StringCchCopyA(filepath, STLINK_ARRAY_SIZE(filepath), dir_to_scan);
if (FAILED(
StringCchCatA(filepath, STLINK_ARRAY_SIZE(filepath), "\\*.chip"))) {
ELOG("Path to chips's dir too long.\n");
return;
}
hFind = FindFirstFileA(filepath, &ffd);
if (INVALID_HANDLE_VALUE == hFind) {
ELOG("Can't find any chip description file in %s.\n", filepath);
return;
}
do {
memset(filepath, 0, STLINK_ARRAY_SIZE(filepath));
StringCchCopyA(filepath, STLINK_ARRAY_SIZE(filepath), dir_to_scan);
StringCchCatA(filepath, STLINK_ARRAY_SIZE(filepath), "\\");
StringCchCatA(filepath, STLINK_ARRAY_SIZE(filepath), ffd.cFileName);
process_chipfile(filepath);
} while (FindNextFileA(hFind, &ffd) != 0);
if (FAILED(StringCchCatA(filepath, STLINK_ARRAY_SIZE(filepath), "\\*.chip"))) {
ELOG("Path to chips's dir too long.\n");
return;
}
hFind = FindFirstFileA(filepath, &ffd);
if (INVALID_HANDLE_VALUE == hFind) {
ELOG("Can't find any chip description file in %s.\n", filepath);
return;
}
do {
memset(filepath, 0, STLINK_ARRAY_SIZE(filepath));
StringCchCopyA(filepath, STLINK_ARRAY_SIZE(filepath), dir_to_scan);
StringCchCatA(filepath, STLINK_ARRAY_SIZE(filepath), "\\");
StringCchCatA(filepath, STLINK_ARRAY_SIZE(filepath), ffd.cFileName);
process_chipfile(filepath);
} while (FindNextFileA(hFind, &ffd) != 0);
FindClose(hFind);
FindClose(hFind);
}
#endif //defined(_WIN32) && !defined(STLINK_HAVE_DIRENT_H)
#endif // defined(_WIN32) && !defined(STLINK_HAVE_DIRENT_H)