kopia lustrzana https://github.com/stlink-org/stlink
Replace data types with fixed width typedefs (C99)
- Unified variable type: size_t --> uint32_t - Removed unnecessary explicit casts - Minor formatting fixespull/1315/head
rodzic
efc5c3713d
commit
755c20c08e
|
@ -33,7 +33,7 @@
|
|||
int32_t (*set_swdclk) (stlink_t * stl, int32_t freq_khz);
|
||||
int32_t (*trace_enable) (stlink_t * sl, uint32_t frequency);
|
||||
int32_t (*trace_disable) (stlink_t * sl);
|
||||
int32_t (*trace_read) (stlink_t * sl, uint8_t* buf, size_t size);
|
||||
int32_t (*trace_read) (stlink_t * sl, uint8_t* buf, uint32_t size);
|
||||
} stlink_backend_t;
|
||||
|
||||
#endif // BACKEND_H
|
||||
|
|
18
inc/stlink.h
18
inc/stlink.h
|
@ -210,22 +210,22 @@ struct _stlink {
|
|||
// stlink_chipid_params.flash_type, set by stlink_load_device_params(), values: STM32_FLASH_TYPE_xx
|
||||
|
||||
stm32_addr_t flash_base; // STM32_FLASH_BASE, set by stlink_load_device_params()
|
||||
size_t flash_size; // calculated by stlink_load_device_params()
|
||||
size_t flash_pgsz; // stlink_chipid_params.flash_pagesize, set by stlink_load_device_params()
|
||||
uint32_t flash_size; // calculated by stlink_load_device_params()
|
||||
uint32_t flash_pgsz; // stlink_chipid_params.flash_pagesize, set by stlink_load_device_params()
|
||||
|
||||
/* sram settings */
|
||||
stm32_addr_t sram_base; // STM32_SRAM_BASE, set by stlink_load_device_params()
|
||||
size_t sram_size; // stlink_chipid_params.sram_size, set by stlink_load_device_params()
|
||||
uint32_t sram_size; // stlink_chipid_params.sram_size, set by stlink_load_device_params()
|
||||
|
||||
/* option settings */
|
||||
stm32_addr_t option_base;
|
||||
size_t option_size;
|
||||
uint32_t option_size;
|
||||
|
||||
// bootloader
|
||||
// sys_base and sys_size are not used by the tools, but are only there to download the bootloader code
|
||||
// (see tests/sg.c)
|
||||
stm32_addr_t sys_base; // stlink_chipid_params.bootrom_base, set by stlink_load_device_params()
|
||||
size_t sys_size; // stlink_chipid_params.bootrom_size, set by stlink_load_device_params()
|
||||
uint32_t sys_size; // stlink_chipid_params.bootrom_size, set by stlink_load_device_params()
|
||||
|
||||
struct stlink_version_ version;
|
||||
|
||||
|
@ -262,8 +262,8 @@ int32_t stlink_target_voltage(stlink_t *sl);
|
|||
int32_t stlink_set_swdclk(stlink_t *sl, int32_t freq_khz);
|
||||
int32_t stlink_trace_enable(stlink_t* sl, uint32_t frequency);
|
||||
int32_t stlink_trace_disable(stlink_t* sl);
|
||||
int32_t stlink_trace_read(stlink_t* sl, uint8_t* buf, size_t size);
|
||||
int32_t stlink_parse_ihex(const char* path, uint8_t erased_pattern, uint8_t * * mem, size_t * size, uint32_t * begin);
|
||||
int32_t stlink_trace_read(stlink_t* sl, uint8_t* buf, uint32_t size);
|
||||
int32_t stlink_parse_ihex(const char* path, uint8_t erased_pattern, uint8_t * * mem, uint32_t * size, uint32_t * begin);
|
||||
uint8_t stlink_get_erased_pattern(stlink_t *sl);
|
||||
int32_t stlink_mwrite_sram(stlink_t *sl, uint8_t* data, uint32_t length, stm32_addr_t addr);
|
||||
int32_t stlink_fwrite_sram(stlink_t *sl, const char* path, stm32_addr_t addr);
|
||||
|
@ -278,9 +278,9 @@ uint32_t read_uint32(const unsigned char *c, const int32_t pt);
|
|||
void write_uint32(unsigned char* buf, uint32_t ui);
|
||||
void write_uint16(unsigned char* buf, uint16_t ui);
|
||||
bool stlink_is_core_halted(stlink_t *sl);
|
||||
int32_t write_buffer_to_sram(stlink_t *sl, flash_loader_t* fl, const uint8_t* buf, size_t size);
|
||||
int32_t write_buffer_to_sram(stlink_t *sl, flash_loader_t* fl, const uint8_t* buf, uint32_t size);
|
||||
int32_t write_loader_to_sram(stlink_t *sl, stm32_addr_t* addr, size_t* size);
|
||||
int32_t stlink_fread(stlink_t* sl, const char* path, bool is_ihex, stm32_addr_t addr, size_t size);
|
||||
int32_t stlink_fread(stlink_t* sl, const char* path, bool is_ihex, stm32_addr_t addr, uint32_t size);
|
||||
int32_t stlink_load_device_params(stlink_t *sl);
|
||||
int32_t stlink_target_connect(stlink_t *sl, enum connect_type connect);
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ int32_t main(int32_t ac, char** av) {
|
|||
|
||||
if ( o.flash_size != 0u && o.flash_size != sl->flash_size ) {
|
||||
sl->flash_size = o.flash_size;
|
||||
printf("Forcing flash size: --flash=0x%08X\n", (uint32_t)sl->flash_size);
|
||||
printf("Forcing flash size: --flash=0x%08X\n", sl->flash_size);
|
||||
}
|
||||
|
||||
sl->verbose = o.log_level;
|
||||
|
@ -106,7 +106,7 @@ int32_t main(int32_t ac, char** av) {
|
|||
}
|
||||
|
||||
if (o.cmd == FLASH_CMD_WRITE) {
|
||||
size_t size = 0;
|
||||
uint32_t size = 0;
|
||||
|
||||
// write
|
||||
if (o.format == FLASH_FORMAT_IHEX) {
|
||||
|
@ -119,7 +119,7 @@ int32_t main(int32_t ac, char** av) {
|
|||
}
|
||||
if ((o.addr >= sl->flash_base) && (o.addr < sl->flash_base + sl->flash_size)) {
|
||||
if (o.format == FLASH_FORMAT_IHEX) {
|
||||
err = stlink_mwrite_flash(sl, mem, (uint32_t)size, o.addr);
|
||||
err = stlink_mwrite_flash(sl, mem, size, o.addr);
|
||||
} else {
|
||||
err = stlink_fwrite_flash(sl, o.filename, o.addr);
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ int32_t main(int32_t ac, char** av) {
|
|||
}
|
||||
} else if ((o.addr >= sl->sram_base) && (o.addr < sl->sram_base + sl->sram_size)) {
|
||||
if (o.format == FLASH_FORMAT_IHEX) {
|
||||
err = stlink_mwrite_sram(sl, mem, (uint32_t)size, o.addr);
|
||||
err = stlink_mwrite_sram(sl, mem, size, o.addr);
|
||||
} else {
|
||||
err = stlink_fwrite_sram(sl, o.filename, o.addr);
|
||||
}
|
||||
|
@ -221,10 +221,10 @@ int32_t main(int32_t ac, char** av) {
|
|||
goto on_error;
|
||||
}
|
||||
} else if (o.area == FLASH_OPTION_BYTES) {
|
||||
size_t remaining_option_length = sl->option_size / 4;
|
||||
uint32_t remaining_option_length = sl->option_size / 4;
|
||||
DLOG("@@@@ Read %u (%#x) option bytes from %#10x\n",
|
||||
(uint32_t)remaining_option_length,
|
||||
(uint32_t)remaining_option_length,
|
||||
remaining_option_length,
|
||||
remaining_option_length,
|
||||
sl->option_base);
|
||||
|
||||
uint32_t option_byte = 0;
|
||||
|
|
|
@ -17,13 +17,13 @@ struct flash_opts {
|
|||
uint8_t serial[STLINK_SERIAL_BUFFER_SIZE];
|
||||
const char* filename;
|
||||
stm32_addr_t addr;
|
||||
size_t size;
|
||||
uint32_t size;
|
||||
int32_t reset;
|
||||
int32_t log_level;
|
||||
enum flash_format format;
|
||||
enum flash_area area;
|
||||
uint32_t val;
|
||||
size_t flash_size; // --flash=n[k, M]
|
||||
uint32_t flash_size; // --flash=n[k, M]
|
||||
int32_t opt; // enable empty tail data drop optimization
|
||||
int32_t freq; // --freq=n[k, M] frequency of JTAG/SWD
|
||||
enum connect_type connect;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include "flash.h"
|
||||
|
||||
static bool starts_with(const char * str, const char * prefix) {
|
||||
size_t n = strlen(prefix);
|
||||
uint32_t n = strlen(prefix);
|
||||
|
||||
if (strlen(str) < n) { return(false); }
|
||||
|
||||
|
@ -61,7 +61,7 @@ static int32_t get_integer_from_char_array (const char *const str, uint32_t *rea
|
|||
fprintf (stderr, "*** Error: Integer greater than UINT32_MAX, cannot convert to int32_t\n");
|
||||
return(-1);
|
||||
} else {
|
||||
*read_value = (uint32_t)value;
|
||||
*read_value = value;
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
|
@ -318,7 +318,7 @@ int32_t flash_get_opts(struct flash_opts* o, int32_t ac, char** av) {
|
|||
if (result != 0) {
|
||||
return bad_arg ("val");
|
||||
} else {
|
||||
o->val = (uint32_t) val;
|
||||
o->val = val;
|
||||
}
|
||||
} else if (o->area == FLASH_OPTION_BYTES_BOOT_ADD) { // expect option bytes boot address
|
||||
if (ac != 1) { return invalid_args("option bytes boot_add write <value>"); }
|
||||
|
@ -329,7 +329,7 @@ int32_t flash_get_opts(struct flash_opts* o, int32_t ac, char** av) {
|
|||
if (result != 0) {
|
||||
return(bad_arg ("val"));
|
||||
} else {
|
||||
o->val = (uint32_t)val;
|
||||
o->val = val;
|
||||
}
|
||||
} else if (o->area == FLASH_OPTCR) { // expect option control register value
|
||||
if (ac != 1) { return invalid_args("option control register write <value>"); }
|
||||
|
@ -340,7 +340,7 @@ int32_t flash_get_opts(struct flash_opts* o, int32_t ac, char** av) {
|
|||
if (result != 0) {
|
||||
return bad_arg ("val");
|
||||
} else {
|
||||
o->val = (uint32_t) val;
|
||||
o->val = val;
|
||||
}
|
||||
} else if (o->area == FLASH_OPTCR1) { // expect option control register 1 value
|
||||
if (ac != 1) { return invalid_args("option control register 1 write <value>"); }
|
||||
|
@ -350,7 +350,7 @@ int32_t flash_get_opts(struct flash_opts* o, int32_t ac, char** av) {
|
|||
if (result != 0) {
|
||||
return bad_arg ("val");
|
||||
} else {
|
||||
o->val = (uint32_t) val;
|
||||
o->val = val;
|
||||
}
|
||||
} else if (o->format == FLASH_FORMAT_BINARY) { // expect filename and addr
|
||||
if (ac != 2) { return invalid_args("write <path> <addr>"); }
|
||||
|
|
|
@ -35,8 +35,8 @@ static void stlink_print_info(stlink_t *sl) {
|
|||
|
||||
printf(" version: "); stlink_print_version(sl);
|
||||
printf(" serial: %s\n", sl->serial);
|
||||
printf(" flash: %u (pagesize: %u)\n", (uint32_t)sl->flash_size, (uint32_t)sl->flash_pgsz);
|
||||
printf(" sram: %u\n", (uint32_t)sl->sram_size);
|
||||
printf(" flash: %u (pagesize: %u)\n", sl->flash_size, sl->flash_pgsz);
|
||||
printf(" sram: %u\n", sl->sram_size);
|
||||
printf(" chipid: 0x%.3x\n", sl->chip_id);
|
||||
|
||||
params = stlink_chipid_get_params(sl->chip_id);
|
||||
|
@ -45,14 +45,14 @@ static void stlink_print_info(stlink_t *sl) {
|
|||
|
||||
static void stlink_probe(enum connect_type connect, int32_t freq) {
|
||||
stlink_t **stdevs;
|
||||
size_t size;
|
||||
uint32_t size;
|
||||
|
||||
size = stlink_probe_usb(&stdevs, connect, freq);
|
||||
|
||||
printf("Found %u stlink programmers\n", (uint32_t)size);
|
||||
printf("Found %u stlink programmers\n", size);
|
||||
|
||||
for (size_t n = 0; n < size; n++) {
|
||||
if (size > 1) printf("%u.\n", (uint32_t)n+1);
|
||||
for (uint32_t n = 0; n < size; n++) {
|
||||
if (size > 1) printf("%u.\n", n+1);
|
||||
stlink_print_info(stdevs[n]);
|
||||
}
|
||||
|
||||
|
@ -107,11 +107,11 @@ static int32_t print_data(int32_t ac, char **av) {
|
|||
if (strcmp(av[1], "--serial") == 0) {
|
||||
printf("%s\n", sl->serial);
|
||||
} else if (strcmp(av[1], "--flash") == 0) {
|
||||
printf("0x%x\n", (uint32_t)sl->flash_size);
|
||||
printf("0x%x\n", sl->flash_size);
|
||||
} else if (strcmp(av[1], "--pagesize") == 0) {
|
||||
printf("0x%x\n", (uint32_t)sl->flash_pgsz);
|
||||
printf("0x%x\n", sl->flash_pgsz);
|
||||
} else if (strcmp(av[1], "--sram") == 0) {
|
||||
printf("0x%x\n", (uint32_t)sl->sram_size);
|
||||
printf("0x%x\n", sl->sram_size);
|
||||
} else if (strcmp(av[1], "--chipid") == 0) {
|
||||
printf("0x%.4x\n", sl->chip_id);
|
||||
} else if (strcmp(av[1], "--descr") == 0) {
|
||||
|
|
|
@ -554,7 +554,7 @@ static const char* const memory_map_template_F4_DE =
|
|||
|
||||
char* make_memory_map(stlink_t *sl) {
|
||||
// this will be freed in serve()
|
||||
const size_t sz = 4096;
|
||||
const uint32_t sz = 4096;
|
||||
char* map = malloc(sz);
|
||||
map[0] = '\0';
|
||||
|
||||
|
@ -566,42 +566,42 @@ char* make_memory_map(stlink_t *sl) {
|
|||
strcpy(map, memory_map_template_F4_DE);
|
||||
} else if (sl->core_id == STM32_CORE_ID_M7F_SWD) {
|
||||
snprintf(map, sz, memory_map_template_F7,
|
||||
(uint32_t)sl->sram_size);
|
||||
sl->sram_size);
|
||||
} else if (sl->chip_id == STM32_CHIPID_H74xxx) {
|
||||
snprintf(map, sz, memory_map_template_H7,
|
||||
(uint32_t)sl->flash_size,
|
||||
(uint32_t)sl->flash_pgsz);
|
||||
sl->flash_size,
|
||||
sl->flash_pgsz);
|
||||
} else if (sl->chip_id == STM32_CHIPID_F4_HD) {
|
||||
strcpy(map, memory_map_template_F4_HD);
|
||||
} else if (sl->chip_id == STM32_CHIPID_F2) {
|
||||
snprintf(map, sz, memory_map_template_F2,
|
||||
(uint32_t)sl->flash_size,
|
||||
(uint32_t)sl->sram_size,
|
||||
(uint32_t)sl->flash_size - 0x20000,
|
||||
(uint32_t)sl->sys_base,
|
||||
(uint32_t)sl->sys_size);
|
||||
sl->flash_size,
|
||||
sl->sram_size,
|
||||
sl->flash_size - 0x20000,
|
||||
sl->sys_base,
|
||||
sl->sys_size);
|
||||
} else if ((sl->chip_id == STM32_CHIPID_L4) ||
|
||||
(sl->chip_id == STM32_CHIPID_L43x_L44x) ||
|
||||
(sl->chip_id == STM32_CHIPID_L45x_L46x)) {
|
||||
snprintf(map, sz, memory_map_template_L4,
|
||||
(uint32_t)sl->flash_size,
|
||||
(uint32_t)sl->flash_size);
|
||||
sl->flash_size,
|
||||
sl->flash_size);
|
||||
} else if (sl->chip_id == STM32_CHIPID_L496x_L4A6x) {
|
||||
snprintf(map, sz, memory_map_template_L496,
|
||||
(uint32_t)sl->flash_size,
|
||||
(uint32_t)sl->flash_size);
|
||||
sl->flash_size,
|
||||
sl->flash_size);
|
||||
} else if (sl->chip_id == STM32_CHIPID_H72x) {
|
||||
snprintf(map, sz, memory_map_template_H72x3x,
|
||||
(uint32_t)sl->flash_size,
|
||||
(uint32_t)sl->flash_pgsz);
|
||||
sl->flash_size,
|
||||
sl->flash_pgsz);
|
||||
} else {
|
||||
snprintf(map, sz, memory_map_template,
|
||||
(uint32_t)sl->flash_size,
|
||||
(uint32_t)sl->sram_size,
|
||||
(uint32_t)sl->flash_size,
|
||||
(uint32_t)sl->flash_pgsz,
|
||||
(uint32_t)sl->sys_base,
|
||||
(uint32_t)sl->sys_size);
|
||||
sl->flash_size,
|
||||
sl->sram_size,
|
||||
sl->flash_size,
|
||||
sl->flash_pgsz,
|
||||
sl->sys_base,
|
||||
sl->sys_size);
|
||||
}
|
||||
|
||||
return(map);
|
||||
|
@ -1074,8 +1074,8 @@ static void cache_sync(stlink_t *sl) {
|
|||
if (ccr & (STLINK_REG_CM7_CCR_IC | STLINK_REG_CM7_CCR_DC)) { cache_flush(sl, ccr); }
|
||||
}
|
||||
|
||||
static size_t unhexify(const char *in, char *out, size_t out_count) {
|
||||
size_t i;
|
||||
static uint32_t unhexify(const char *in, char *out, uint32_t out_count) {
|
||||
uint32_t i;
|
||||
uint32_t c;
|
||||
|
||||
for (i = 0; i < out_count; i++) {
|
||||
|
@ -1248,9 +1248,9 @@ int32_t serve(stlink_t *sl, st_state_t *st) {
|
|||
params = separator + 1;
|
||||
}
|
||||
|
||||
size_t hex_len = strlen(params);
|
||||
size_t alloc_size = (hex_len / 2) + 1;
|
||||
size_t cmd_len;
|
||||
uint32_t hex_len = strlen(params);
|
||||
uint32_t alloc_size = (hex_len / 2) + 1;
|
||||
uint32_t cmd_len;
|
||||
char *cmd = malloc(alloc_size);
|
||||
|
||||
if (cmd == NULL) {
|
||||
|
@ -1669,7 +1669,7 @@ int32_t serve(stlink_t *sl, st_state_t *st) {
|
|||
uint32_t adj_start = start % 4;
|
||||
uint32_t count_rnd = (count + adj_start + 4 - 1) / 4 * 4;
|
||||
|
||||
if (count_rnd > sl->flash_pgsz) { count_rnd = (uint32_t)sl->flash_pgsz; }
|
||||
if (count_rnd > sl->flash_pgsz) { count_rnd = sl->flash_pgsz; }
|
||||
|
||||
if (count_rnd > 0x1800) { count_rnd = 0x1800; }
|
||||
|
||||
|
|
|
@ -262,7 +262,7 @@ static gpointer stlink_gui_populate_filemem_view(gpointer data) {
|
|||
*/
|
||||
|
||||
uint8_t* mem = NULL;
|
||||
size_t size = 0;
|
||||
uint32_t size = 0;
|
||||
uint32_t begin = 0;
|
||||
int32_t res = stlink_parse_ihex(gui->filename, 0, &mem, &size, &begin);
|
||||
|
||||
|
|
|
@ -47,8 +47,7 @@ uint32_t calculate_F7_sectornum(uint32_t flashaddr) {
|
|||
}
|
||||
}
|
||||
|
||||
uint32_t calculate_H7_sectornum(stlink_t *sl, uint32_t flashaddr,
|
||||
uint32_t bank) {
|
||||
uint32_t calculate_H7_sectornum(stlink_t *sl, uint32_t flashaddr, uint32_t bank) {
|
||||
flashaddr &=
|
||||
~((bank == BANK_1)
|
||||
? STM32_FLASH_BASE
|
||||
|
@ -68,7 +67,7 @@ uint32_t calculate_L4_page(stlink_t *sl, uint32_t flashaddr) {
|
|||
sl->chip_id == STM32_CHIPID_L4Rx) {
|
||||
// this chip use dual banked flash
|
||||
if (flashopt & (uint32_t)(1lu << FLASH_L4_OPTR_DUALBANK)) {
|
||||
uint32_t banksize = (uint32_t)sl->flash_size / 2;
|
||||
uint32_t banksize = sl->flash_size / 2;
|
||||
|
||||
if (flashaddr >= banksize) {
|
||||
flashaddr -= banksize;
|
||||
|
@ -79,5 +78,5 @@ uint32_t calculate_L4_page(stlink_t *sl, uint32_t flashaddr) {
|
|||
|
||||
// For 1MB chips without the dual-bank option set, the page address will
|
||||
// overflow into the BKER bit, which gives us the correct bank:page value.
|
||||
return (bker | flashaddr / (uint32_t)sl->flash_pgsz);
|
||||
return (bker | flashaddr / sl->flash_pgsz);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
uint32_t calculate_F4_sectornum(uint32_t);
|
||||
uint32_t calculate_F7_sectornum(uint32_t);
|
||||
uint32_t calculate_H7_sectornum(stlink_t *, uint32_t, unsigned);
|
||||
uint32_t calculate_H7_sectornum(stlink_t *, uint32_t, uint32_t);
|
||||
uint32_t calculate_L4_page(stlink_t *, uint32_t);
|
||||
|
||||
#endif // CALCULATE_H
|
||||
|
|
|
@ -196,7 +196,7 @@ void process_chipfile(char *fname) {
|
|||
|
||||
void init_chipids(char *dir_to_scan) {
|
||||
DIR *d;
|
||||
size_t nl; // namelen
|
||||
uint32_t nl; // namelen
|
||||
struct dirent *dir;
|
||||
|
||||
if (!dir_to_scan) {
|
||||
|
|
|
@ -56,7 +56,7 @@ int32_t stlink_jtag_reset(stlink_t *, int32_t);
|
|||
int32_t stlink_soft_reset(stlink_t *, int32_t);
|
||||
void _parse_version(stlink_t *, stlink_version_t *);
|
||||
static uint8_t stlink_parse_hex(const char *);
|
||||
static int32_t stlink_read(stlink_t *, stm32_addr_t, size_t, save_block_fn, void *);
|
||||
static int32_t stlink_read(stlink_t *, stm32_addr_t, uint32_t, save_block_fn, void *);
|
||||
static bool stlink_fread_ihex_init(struct stlink_fread_ihex_worker_arg *, int32_t, stm32_addr_t);
|
||||
static bool stlink_fread_ihex_worker(void *, uint8_t *, ssize_t);
|
||||
static bool stlink_fread_ihex_finalize(struct stlink_fread_ihex_worker_arg *);
|
||||
|
@ -323,8 +323,8 @@ int32_t stlink_load_device_params(stlink_t *sl) {
|
|||
}
|
||||
|
||||
ILOG("%s: %u KiB SRAM, %u KiB flash in at least %u %s pages.\n",
|
||||
params->dev_type, (uint32_t)(sl->sram_size / 1024), (uint32_t)(sl->flash_size / 1024),
|
||||
(sl->flash_pgsz < 1024) ? (uint32_t)(sl->flash_pgsz) : (uint32_t)(sl->flash_pgsz / 1024),
|
||||
params->dev_type, (sl->sram_size / 1024), (sl->flash_size / 1024),
|
||||
(sl->flash_pgsz < 1024) ? sl->flash_pgsz : (sl->flash_pgsz / 1024),
|
||||
(sl->flash_pgsz < 1024) ? "byte" : "KiB");
|
||||
|
||||
return (0);
|
||||
|
@ -609,7 +609,7 @@ int32_t stlink_trace_disable(stlink_t *sl) {
|
|||
}
|
||||
|
||||
// 276
|
||||
int32_t stlink_trace_read(stlink_t *sl, uint8_t *buf, size_t size) {
|
||||
int32_t stlink_trace_read(stlink_t *sl, uint8_t *buf, uint32_t size) {
|
||||
return (sl->backend->trace_read(sl, buf, size));
|
||||
}
|
||||
|
||||
|
@ -645,8 +645,8 @@ int32_t stlink_mwrite_sram(stlink_t *sl, uint8_t *data, uint32_t length, stm32_a
|
|||
// write the file in sram at addr
|
||||
|
||||
int32_t error = -1;
|
||||
size_t off;
|
||||
size_t len;
|
||||
uint32_t off;
|
||||
uint32_t len;
|
||||
|
||||
// check addr range is inside the sram
|
||||
if (addr < sl->sram_base) {
|
||||
|
@ -671,7 +671,7 @@ int32_t stlink_mwrite_sram(stlink_t *sl, uint8_t *data, uint32_t length, stm32_a
|
|||
|
||||
// do the copy by 1kB blocks
|
||||
for (off = 0; off < len; off += 1024) {
|
||||
size_t size = 1024;
|
||||
uint32_t size = 1024;
|
||||
|
||||
if ((off + size) > len) {
|
||||
size = len - off;
|
||||
|
@ -683,12 +683,12 @@ int32_t stlink_mwrite_sram(stlink_t *sl, uint8_t *data, uint32_t length, stm32_a
|
|||
size += 2;
|
||||
} // round size if needed
|
||||
|
||||
stlink_write_mem32(sl, addr + (uint32_t)off, (uint16_t)size);
|
||||
stlink_write_mem32(sl, addr + off, (uint16_t)size);
|
||||
}
|
||||
|
||||
if (length > len) {
|
||||
memcpy(sl->q_buf, data + len, length - len);
|
||||
stlink_write_mem8(sl, addr + (uint32_t)len, (uint16_t)(length - len));
|
||||
stlink_write_mem8(sl, addr + len, (uint16_t)(length - len));
|
||||
}
|
||||
|
||||
error = 0; // success
|
||||
|
@ -703,8 +703,8 @@ int32_t stlink_fwrite_sram(stlink_t *sl, const char *path, stm32_addr_t addr) {
|
|||
// write the file in sram at addr
|
||||
|
||||
int32_t error = -1;
|
||||
size_t off;
|
||||
size_t len;
|
||||
uint32_t off;
|
||||
uint32_t len;
|
||||
mapped_file_t mf = MAPPED_FILE_INITIALIZER;
|
||||
|
||||
if (map_file(&mf, path) == -1) {
|
||||
|
@ -739,7 +739,7 @@ int32_t stlink_fwrite_sram(stlink_t *sl, const char *path, stm32_addr_t addr) {
|
|||
|
||||
// do the copy by 1kB blocks
|
||||
for (off = 0; off < len; off += 1024) {
|
||||
size_t size = 1024;
|
||||
uint32_t size = 1024;
|
||||
|
||||
if ((off + size) > len) {
|
||||
size = len - off;
|
||||
|
@ -751,12 +751,12 @@ int32_t stlink_fwrite_sram(stlink_t *sl, const char *path, stm32_addr_t addr) {
|
|||
size += 2;
|
||||
} // round size if needed
|
||||
|
||||
stlink_write_mem32(sl, addr + (uint32_t)off, (uint16_t)size);
|
||||
stlink_write_mem32(sl, addr + off, (uint16_t)size);
|
||||
}
|
||||
|
||||
if (mf.len > len) {
|
||||
memcpy(sl->q_buf, mf.base + len, mf.len - len);
|
||||
stlink_write_mem8(sl, addr + (uint32_t)len, (uint16_t)(mf.len - len));
|
||||
stlink_write_mem8(sl, addr + len, (uint16_t)(mf.len - len));
|
||||
}
|
||||
|
||||
// check the file has been written
|
||||
|
@ -774,9 +774,9 @@ on_error:
|
|||
}
|
||||
|
||||
// 302
|
||||
int32_t stlink_fread(stlink_t *sl, const char *path, bool is_ihex, stm32_addr_t addr, size_t size) {
|
||||
int32_t stlink_fread(stlink_t *sl, const char *path, bool is_ihex, stm32_addr_t addr, uint32_t size) {
|
||||
// read size bytes from addr to file
|
||||
ILOG("read from address %#010x size %u\n", addr, (uint32_t)size);
|
||||
ILOG("read from address %#010x size %u\n", addr, size);
|
||||
|
||||
int32_t error;
|
||||
int32_t fd = open(path, O_RDWR | O_TRUNC | O_CREAT | O_BINARY, 00700);
|
||||
|
@ -808,11 +808,11 @@ int32_t stlink_fread(stlink_t *sl, const char *path, bool is_ihex, stm32_addr_t
|
|||
}
|
||||
|
||||
// 300
|
||||
int32_t write_buffer_to_sram(stlink_t *sl, flash_loader_t *fl, const uint8_t *buf, size_t size) {
|
||||
int32_t write_buffer_to_sram(stlink_t *sl, flash_loader_t *fl, const uint8_t *buf, uint32_t size) {
|
||||
// write the buffer right after the loader
|
||||
int32_t ret = 0;
|
||||
size_t chunk = size & ~0x3;
|
||||
size_t rem = size & 0x3;
|
||||
uint32_t chunk = size & ~0x3;
|
||||
uint32_t rem = size & 0x3;
|
||||
|
||||
if (chunk) {
|
||||
memcpy(sl->q_buf, buf, chunk);
|
||||
|
@ -821,7 +821,7 @@ int32_t write_buffer_to_sram(stlink_t *sl, flash_loader_t *fl, const uint8_t *bu
|
|||
|
||||
if (rem && !ret) {
|
||||
memcpy(sl->q_buf, buf + chunk, rem);
|
||||
ret = stlink_write_mem8(sl, (fl->buf_addr) + (uint32_t)chunk, (uint16_t)rem);
|
||||
ret = stlink_write_mem8(sl, (fl->buf_addr) + chunk, (uint16_t)rem);
|
||||
}
|
||||
|
||||
return (ret);
|
||||
|
@ -865,12 +865,12 @@ uint32_t stlink_calculate_pagesize(stlink_t *sl, uint32_t flashaddr) {
|
|||
}
|
||||
}
|
||||
|
||||
return ((uint32_t)sl->flash_pgsz);
|
||||
return (sl->flash_pgsz);
|
||||
}
|
||||
|
||||
// 279
|
||||
int32_t stlink_parse_ihex(const char *path, uint8_t erased_pattern, uint8_t **mem,
|
||||
size_t *size, uint32_t *begin) {
|
||||
uint32_t *size, uint32_t *begin) {
|
||||
int32_t res = 0;
|
||||
*begin = UINT32_MAX;
|
||||
uint8_t *data = NULL;
|
||||
|
@ -896,7 +896,7 @@ int32_t stlink_parse_ihex(const char *path, uint8_t erased_pattern, uint8_t **me
|
|||
data = calloc(*size, 1); // use calloc to get NULL if out of memory
|
||||
|
||||
if (!data) {
|
||||
ELOG("Cannot allocate %u bytes\n", (uint32_t)(*size));
|
||||
ELOG("Cannot allocate %u bytes\n", (*size));
|
||||
res = -1;
|
||||
break;
|
||||
}
|
||||
|
@ -926,7 +926,7 @@ int32_t stlink_parse_ihex(const char *path, uint8_t erased_pattern, uint8_t **me
|
|||
break;
|
||||
}
|
||||
|
||||
size_t l = strlen(line);
|
||||
uint32_t l = strlen(line);
|
||||
|
||||
while (l > 0 && (line[l - 1] == '\n' || line[l - 1] == '\r')) {
|
||||
--l;
|
||||
|
@ -942,7 +942,7 @@ int32_t stlink_parse_ihex(const char *path, uint8_t erased_pattern, uint8_t **me
|
|||
|
||||
uint8_t chksum = 0; // check sum
|
||||
|
||||
for (size_t i = 1; i < l; i += 2) {
|
||||
for (uint32_t i = 1; i < l; i += 2) {
|
||||
chksum += stlink_parse_hex(line + i);
|
||||
}
|
||||
|
||||
|
@ -1215,8 +1215,7 @@ void stlink_run_at(stlink_t *sl, stm32_addr_t addr) {
|
|||
}
|
||||
}
|
||||
|
||||
static int32_t stlink_read(stlink_t *sl, stm32_addr_t addr, size_t size,
|
||||
save_block_fn fn, void *fn_arg) {
|
||||
static int32_t stlink_read(stlink_t *sl, stm32_addr_t addr, uint32_t size, save_block_fn fn, void *fn_arg) {
|
||||
|
||||
int32_t error = -1;
|
||||
|
||||
|
@ -1228,10 +1227,10 @@ static int32_t stlink_read(stlink_t *sl, stm32_addr_t addr, size_t size,
|
|||
size = sl->flash_size;
|
||||
}
|
||||
|
||||
size_t cmp_size = (sl->flash_pgsz > 0x1800) ? 0x1800 : sl->flash_pgsz;
|
||||
uint32_t cmp_size = (sl->flash_pgsz > 0x1800) ? 0x1800 : sl->flash_pgsz;
|
||||
|
||||
for (size_t off = 0; off < size; off += cmp_size) {
|
||||
size_t aligned_size;
|
||||
for (uint32_t off = 0; off < size; off += cmp_size) {
|
||||
uint32_t aligned_size;
|
||||
|
||||
// adjust last page size
|
||||
if ((off + cmp_size) > size) {
|
||||
|
@ -1244,7 +1243,7 @@ static int32_t stlink_read(stlink_t *sl, stm32_addr_t addr, size_t size,
|
|||
aligned_size = (cmp_size + 4) & ~(4 - 1);
|
||||
}
|
||||
|
||||
stlink_read_mem32(sl, addr + (uint32_t)off, (uint16_t)aligned_size);
|
||||
stlink_read_mem32(sl, addr + off, (uint16_t)aligned_size);
|
||||
|
||||
if (!fn(fn_arg, sl->q_buf, aligned_size)) {
|
||||
goto on_error;
|
||||
|
|
|
@ -1027,10 +1027,8 @@ int32_t stlink_erase_flash_page(stlink_t *sl, stm32_addr_t flashaddr) {
|
|||
}
|
||||
|
||||
// unlock program memory
|
||||
stlink_write_debug32(sl, flash_regs_base + FLASH_PRGKEYR_OFF,
|
||||
FLASH_L0_PRGKEY1);
|
||||
stlink_write_debug32(sl, flash_regs_base + FLASH_PRGKEYR_OFF,
|
||||
FLASH_L0_PRGKEY2);
|
||||
stlink_write_debug32(sl, flash_regs_base + FLASH_PRGKEYR_OFF, FLASH_L0_PRGKEY1);
|
||||
stlink_write_debug32(sl, flash_regs_base + FLASH_PRGKEYR_OFF, FLASH_L0_PRGKEY2);
|
||||
|
||||
// check pecr.prglock is cleared
|
||||
stlink_read_debug32(sl, flash_regs_base + FLASH_PECR_OFF, &val);
|
||||
|
@ -1069,16 +1067,14 @@ int32_t stlink_erase_flash_page(stlink_t *sl, stm32_addr_t flashaddr) {
|
|||
|
||||
// set the page to erase
|
||||
if (sl->flash_type == STM32_FLASH_TYPE_G0) {
|
||||
uint32_t flash_page =
|
||||
((flashaddr - STM32_FLASH_BASE) / (uint32_t)(sl->flash_pgsz));
|
||||
uint32_t flash_page = ((flashaddr - STM32_FLASH_BASE) / sl->flash_pgsz);
|
||||
stlink_read_debug32(sl, FLASH_Gx_CR, &val);
|
||||
// sec 3.7.5 - PNB[5:0] is offset by 3. PER is 0x2.
|
||||
val &= ~(0x3F << 3);
|
||||
val |= ((flash_page & 0x3F) << 3) | (1 << FLASH_CR_PER);
|
||||
stlink_write_debug32(sl, FLASH_Gx_CR, val);
|
||||
} else if (sl->flash_type == STM32_FLASH_TYPE_G4) {
|
||||
uint32_t flash_page =
|
||||
((flashaddr - STM32_FLASH_BASE) / (uint32_t)(sl->flash_pgsz));
|
||||
uint32_t flash_page = ((flashaddr - STM32_FLASH_BASE) / sl->flash_pgsz);
|
||||
stlink_read_debug32(sl, FLASH_Gx_CR, &val);
|
||||
// sec 3.7.5 - PNB[6:0] is offset by 3. PER is 0x2.
|
||||
val &= ~(0x7F << 3);
|
||||
|
@ -1088,13 +1084,11 @@ int32_t stlink_erase_flash_page(stlink_t *sl, stm32_addr_t flashaddr) {
|
|||
uint32_t flash_page;
|
||||
stlink_read_debug32(sl, FLASH_L5_NSCR, &val);
|
||||
if (sl->flash_pgsz == 0x800 && (flashaddr - STM32_FLASH_BASE) >= sl->flash_size/2) {
|
||||
flash_page = (flashaddr - STM32_FLASH_BASE - sl->flash_size/2) /
|
||||
(uint32_t)(sl->flash_pgsz);
|
||||
flash_page = (flashaddr - STM32_FLASH_BASE - sl->flash_size/2) / sl->flash_pgsz;
|
||||
// set bank 2 for erasure
|
||||
val |= (1 << FLASH_L5_NSCR_NSBKER);
|
||||
} else {
|
||||
flash_page =
|
||||
((flashaddr - STM32_FLASH_BASE) / (uint32_t)(sl->flash_pgsz));
|
||||
flash_page = ((flashaddr - STM32_FLASH_BASE) / sl->flash_pgsz);
|
||||
// set bank 1 for erasure
|
||||
val &= ~(1 << FLASH_L5_NSCR_NSBKER);
|
||||
}
|
||||
|
@ -1103,8 +1097,7 @@ int32_t stlink_erase_flash_page(stlink_t *sl, stm32_addr_t flashaddr) {
|
|||
val |= ((flash_page & 0x7F) << 3) | (1 << FLASH_CR_PER);
|
||||
stlink_write_debug32(sl, FLASH_L5_NSCR, val);
|
||||
} else if (sl->flash_type == STM32_FLASH_TYPE_WB_WL) {
|
||||
uint32_t flash_page =
|
||||
((flashaddr - STM32_FLASH_BASE) / (uint32_t)(sl->flash_pgsz));
|
||||
uint32_t flash_page = ((flashaddr - STM32_FLASH_BASE) / sl->flash_pgsz);
|
||||
stlink_read_debug32(sl, FLASH_WB_CR, &val);
|
||||
|
||||
// sec 3.10.5 - PNB[7:0] is offset by 3.
|
||||
|
@ -1133,8 +1126,7 @@ int32_t stlink_erase_flash_page(stlink_t *sl, stm32_addr_t flashaddr) {
|
|||
} else if (sl->flash_type == STM32_FLASH_TYPE_H7) {
|
||||
uint32_t bank = (flashaddr < STM32_H7_FLASH_BANK2_BASE) ? BANK_1 : BANK_2;
|
||||
unlock_flash_if(sl); // unlock if locked
|
||||
uint32_t sector = calculate_H7_sectornum(
|
||||
sl, flashaddr, bank); // calculate the actual page from the address
|
||||
uint32_t sector = calculate_H7_sectornum(sl, flashaddr, bank); // calculate the actual page from the address
|
||||
write_flash_cr_snb(sl, sector, bank); // select the page to erase
|
||||
set_flash_cr_strt(sl, bank); // start erase operation
|
||||
wait_flash_busy(sl); // wait for completion
|
||||
|
@ -1147,7 +1139,7 @@ int32_t stlink_erase_flash_page(stlink_t *sl, stm32_addr_t flashaddr) {
|
|||
return check_flash_error(sl);
|
||||
}
|
||||
|
||||
int32_t stlink_erase_flash_section(stlink_t *sl, stm32_addr_t base_addr, size_t size, bool align_size) {
|
||||
int32_t stlink_erase_flash_section(stlink_t *sl, stm32_addr_t base_addr, uint32_t size, bool align_size) {
|
||||
// Check the address and size validity
|
||||
if (stlink_check_address_range_validity(sl, base_addr, size) < 0) {
|
||||
return -1;
|
||||
|
@ -1247,7 +1239,7 @@ int32_t stlink_mwrite_flash(stlink_t *sl, uint8_t *data, uint32_t length, stm32_
|
|||
* Therfore it is turned off by default.
|
||||
*/
|
||||
if (sl->opt) {
|
||||
idx = (uint32_t)length;
|
||||
idx = length;
|
||||
|
||||
for (num_empty = 0; num_empty != length; ++num_empty)
|
||||
if (data[--idx] != erased_pattern) {
|
||||
|
@ -1270,9 +1262,8 @@ int32_t stlink_mwrite_flash(stlink_t *sl, uint8_t *data, uint32_t length, stm32_
|
|||
* still flash the whole file even if ignoring message is printed.
|
||||
*/
|
||||
err = stlink_write_flash(sl, addr, data,
|
||||
(num_empty == length) ? (uint32_t)length
|
||||
: (uint32_t)length - num_empty,
|
||||
num_empty == length);
|
||||
(num_empty == length) ? length : length - num_empty,
|
||||
num_empty == length);
|
||||
stlink_fwrite_finalize(sl, addr);
|
||||
return (err);
|
||||
}
|
||||
|
@ -1358,12 +1349,12 @@ int32_t stlink_fcheck_flash(stlink_t *sl, const char *path, stm32_addr_t addr) {
|
|||
* @return 0 for success, -ve for failure
|
||||
*/
|
||||
int32_t stlink_verify_write_flash(stlink_t *sl, stm32_addr_t address, uint8_t *data, uint32_t length) {
|
||||
size_t off;
|
||||
size_t cmp_size = (sl->flash_pgsz > 0x1800) ? 0x1800 : sl->flash_pgsz;
|
||||
uint32_t off;
|
||||
uint32_t cmp_size = (sl->flash_pgsz > 0x1800) ? 0x1800 : sl->flash_pgsz;
|
||||
ILOG("Starting verification of write complete\n");
|
||||
|
||||
for (off = 0; off < length; off += cmp_size) {
|
||||
size_t aligned_size;
|
||||
uint32_t aligned_size;
|
||||
|
||||
// adjust last page size
|
||||
if ((off + cmp_size) > length) {
|
||||
|
@ -1376,10 +1367,10 @@ int32_t stlink_verify_write_flash(stlink_t *sl, stm32_addr_t address, uint8_t *d
|
|||
aligned_size = (cmp_size + 4) & ~(4 - 1);
|
||||
}
|
||||
|
||||
stlink_read_mem32(sl, address + (uint32_t)off, (uint16_t)aligned_size);
|
||||
stlink_read_mem32(sl, address + off, (uint16_t)aligned_size);
|
||||
|
||||
if (memcmp(sl->q_buf, data + off, cmp_size)) {
|
||||
ELOG("Verification of flash failed at offset: %u\n", (uint32_t)off);
|
||||
ELOG("Verification of flash failed at offset: %u\n", off);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
@ -1389,7 +1380,7 @@ int32_t stlink_verify_write_flash(stlink_t *sl, stm32_addr_t address, uint8_t *d
|
|||
}
|
||||
|
||||
// Check if an address and size are within the flash
|
||||
int32_t stlink_check_address_range_validity(stlink_t *sl, stm32_addr_t addr, size_t size) {
|
||||
int32_t stlink_check_address_range_validity(stlink_t *sl, stm32_addr_t addr, uint32_t size) {
|
||||
uint32_t logvar;
|
||||
if (addr < sl->flash_base || addr >= (sl->flash_base + sl->flash_size)) {
|
||||
logvar = sl->flash_base + sl->flash_size - 1;
|
||||
|
@ -1436,7 +1427,7 @@ int32_t stlink_write_flash(stlink_t *sl, stm32_addr_t addr, uint8_t *base, uint3
|
|||
ELOG("addr not a multiple of current pagesize (%u bytes), not supported, "
|
||||
"check page start address and compare with flash module organisation "
|
||||
"in related ST reference manual of your device.\n",
|
||||
(uint32_t)(sl->flash_pgsz));
|
||||
sl->flash_pgsz);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
|
|
@ -37,13 +37,13 @@ void clear_flash_cr_pg(stlink_t *, uint32_t);
|
|||
// static void set_flash_cr_strt(stlink_t *sl, uint32_t bank);
|
||||
// static void set_flash_cr_mer(stlink_t *sl, bool v, uint32_t bank);
|
||||
int32_t stlink_erase_flash_page(stlink_t *sl, stm32_addr_t flashaddr);
|
||||
int32_t stlink_erase_flash_section(stlink_t *sl, stm32_addr_t base_addr, size_t size, bool align_size);
|
||||
int32_t stlink_erase_flash_section(stlink_t *sl, stm32_addr_t base_addr, uint32_t size, bool align_size);
|
||||
int32_t stlink_erase_flash_mass(stlink_t *sl);
|
||||
int32_t stlink_mwrite_flash(stlink_t *sl, uint8_t *data, uint32_t length, stm32_addr_t addr);
|
||||
int32_t stlink_fwrite_flash(stlink_t *sl, const char *path, stm32_addr_t addr);
|
||||
int32_t stlink_fcheck_flash(stlink_t *sl, const char *path, stm32_addr_t addr);
|
||||
int32_t stlink_verify_write_flash(stlink_t *sl, stm32_addr_t address, uint8_t *data, uint32_t length);
|
||||
int32_t stlink_check_address_range_validity(stlink_t *sl, stm32_addr_t addr, size_t size);
|
||||
int32_t stlink_check_address_range_validity(stlink_t *sl, stm32_addr_t addr, uint32_t size);
|
||||
int32_t stlink_check_address_alignment(stlink_t *sl, stm32_addr_t addr);
|
||||
int32_t stlink_write_flash(stlink_t *sl, stm32_addr_t addr, uint8_t *base, uint32_t len, uint8_t eraseonly);
|
||||
void stlink_fwrite_finalize(stlink_t *, stm32_addr_t);
|
||||
|
|
|
@ -162,7 +162,7 @@ static const uint8_t loader_code_stm32f7_lv[] = {
|
|||
|
||||
|
||||
int32_t stlink_flash_loader_init(stlink_t *sl, flash_loader_t *fl) {
|
||||
size_t size = 0;
|
||||
uint32_t size = 0;
|
||||
uint32_t dfsr, cfsr, hfsr;
|
||||
|
||||
/* Interrupt masking according to DDI0419C, Table C1-7 firstly force halt */
|
||||
|
@ -172,8 +172,7 @@ int32_t stlink_flash_loader_init(stlink_t *sl, flash_loader_t *fl) {
|
|||
/* and only then disable interrupts */
|
||||
stlink_write_debug32(sl, STLINK_REG_DHCSR,
|
||||
STLINK_REG_DHCSR_DBGKEY | STLINK_REG_DHCSR_C_DEBUGEN |
|
||||
STLINK_REG_DHCSR_C_HALT |
|
||||
STLINK_REG_DHCSR_C_MASKINTS);
|
||||
STLINK_REG_DHCSR_C_HALT | STLINK_REG_DHCSR_C_MASKINTS);
|
||||
|
||||
// allocate the loader in SRAM
|
||||
if (stlink_flash_loader_write_to_sram(sl, &fl->loader_addr, &size) == -1) {
|
||||
|
@ -182,7 +181,7 @@ int32_t stlink_flash_loader_init(stlink_t *sl, flash_loader_t *fl) {
|
|||
}
|
||||
|
||||
// allocate a one page buffer in SRAM right after loader
|
||||
fl->buf_addr = fl->loader_addr + (uint32_t)size;
|
||||
fl->buf_addr = fl->loader_addr + size;
|
||||
ILOG("Successfully loaded flash loader in sram\n");
|
||||
|
||||
// set address of IWDG key register for reset it
|
||||
|
@ -210,9 +209,9 @@ int32_t stlink_flash_loader_init(stlink_t *sl, flash_loader_t *fl) {
|
|||
}
|
||||
|
||||
static int32_t loader_v_dependent_assignment(stlink_t *sl,
|
||||
const uint8_t **loader_code, size_t *loader_size,
|
||||
const uint8_t *high_v_loader, size_t high_v_loader_size,
|
||||
const uint8_t *low_v_loader, size_t low_v_loader_size) {
|
||||
const uint8_t **loader_code, uint32_t *loader_size,
|
||||
const uint8_t *high_v_loader, uint32_t high_v_loader_size,
|
||||
const uint8_t *low_v_loader, uint32_t low_v_loader_size) {
|
||||
int32_t retval = 0;
|
||||
|
||||
if ( sl->version.stlink_v == 1) {
|
||||
|
@ -239,9 +238,9 @@ static int32_t loader_v_dependent_assignment(stlink_t *sl,
|
|||
return(retval);
|
||||
}
|
||||
|
||||
int32_t stlink_flash_loader_write_to_sram(stlink_t *sl, stm32_addr_t* addr, size_t* size) {
|
||||
int32_t stlink_flash_loader_write_to_sram(stlink_t *sl, stm32_addr_t* addr, uint32_t* size) {
|
||||
const uint8_t* loader_code;
|
||||
size_t loader_size;
|
||||
uint32_t loader_size;
|
||||
|
||||
if (sl->chip_id == STM32_CHIPID_L1_MD ||
|
||||
sl->chip_id == STM32_CHIPID_L1_CAT2 ||
|
||||
|
@ -330,13 +329,13 @@ int32_t stlink_flash_loader_write_to_sram(stlink_t *sl, stm32_addr_t* addr, size
|
|||
return(0); // success
|
||||
}
|
||||
|
||||
int32_t stlink_flash_loader_run(stlink_t *sl, flash_loader_t* fl, stm32_addr_t target, const uint8_t* buf, size_t size) {
|
||||
int32_t stlink_flash_loader_run(stlink_t *sl, flash_loader_t* fl, stm32_addr_t target, const uint8_t* buf, uint32_t size) {
|
||||
struct stlink_reg rr;
|
||||
uint32_t timeout;
|
||||
uint32_t flash_base = 0;
|
||||
uint32_t dhcsr, dfsr, cfsr, hfsr;
|
||||
|
||||
DLOG("Running flash loader, write address:%#x, size: %u\n", target, (uint32_t)size);
|
||||
DLOG("Running flash loader, write address:%#x, size: %u\n", target, size);
|
||||
|
||||
if (write_buffer_to_sram(sl, fl, buf, size) == -1) {
|
||||
ELOG("write_buffer_to_sram() == -1\n");
|
||||
|
@ -350,7 +349,7 @@ int32_t stlink_flash_loader_run(stlink_t *sl, flash_loader_t* fl, stm32_addr_t t
|
|||
/* Setup core */
|
||||
stlink_write_reg(sl, fl->buf_addr, 0); // source
|
||||
stlink_write_reg(sl, target, 1); // target
|
||||
stlink_write_reg(sl, (uint32_t)size, 2); // count
|
||||
stlink_write_reg(sl, size, 2); // count
|
||||
stlink_write_reg(sl, flash_base, 3); // flash register base
|
||||
// only used on VL/F1_XL, but harmless for others
|
||||
stlink_write_reg(sl, fl->loader_addr, 15); // pc register
|
||||
|
@ -417,8 +416,7 @@ int32_t stlink_flash_loader_run(stlink_t *sl, flash_loader_t* fl, stm32_addr_t t
|
|||
|
||||
WLOG("Loader state: R2 0x%X R15 0x%X\n", rr.r[2], rr.r[15]);
|
||||
if (dhcsr != 0x3000B || dfsr || cfsr || hfsr) {
|
||||
WLOG("MCU state: DHCSR 0x%X DFSR 0x%X CFSR 0x%X HFSR 0x%X\n",
|
||||
dhcsr, dfsr, cfsr, hfsr);
|
||||
WLOG("MCU state: DHCSR 0x%X DFSR 0x%X CFSR 0x%X HFSR 0x%X\n", dhcsr, dfsr, cfsr, hfsr);
|
||||
}
|
||||
|
||||
return(-1);
|
||||
|
@ -450,8 +448,7 @@ int32_t stm32l1_write_half_pages(stlink_t *sl, stm32_addr_t addr, uint8_t *base,
|
|||
|
||||
for (count = 0; count < num_half_pages; count++) {
|
||||
if (use_loader) {
|
||||
ret = stlink_flash_loader_run(sl, &fl, addr + count * pagesize,
|
||||
base + count * pagesize, pagesize);
|
||||
ret = stlink_flash_loader_run(sl, &fl, addr + count * pagesize, base + count * pagesize, pagesize);
|
||||
if (ret && count == 0) {
|
||||
/* It seems that stm32lx devices have a problem when it is blank */
|
||||
WLOG("Failed to use flash loader, fallback to soft write\n");
|
||||
|
@ -461,7 +458,7 @@ int32_t stm32l1_write_half_pages(stlink_t *sl, stm32_addr_t addr, uint8_t *base,
|
|||
if (!use_loader) {
|
||||
ret = 0;
|
||||
for (off = 0; off < pagesize && !ret; off += 64) {
|
||||
size_t chunk = (pagesize - off > 64) ? 64 : pagesize - off;
|
||||
uint32_t chunk = (pagesize - off > 64) ? 64 : pagesize - off;
|
||||
memcpy(sl->q_buf, base + count * pagesize + off, chunk);
|
||||
ret = stlink_write_mem32(sl, addr + count * pagesize + off, (uint16_t)chunk);
|
||||
}
|
||||
|
@ -632,9 +629,7 @@ int32_t stlink_flashloader_start(stlink_t *sl, flash_loader_t *fl) {
|
|||
ILOG("enabling 32-bit flash writes\n");
|
||||
write_flash_cr_psiz(sl, 2, BANK_1);
|
||||
} else {
|
||||
ILOG("Target voltage (%d mV) too low for 32-bit flash, "
|
||||
"using 8-bit flash writes\n",
|
||||
voltage);
|
||||
ILOG("Target voltage (%d mV) too low for 32-bit flash, using 8-bit flash writes\n", voltage);
|
||||
write_flash_cr_psiz(sl, 0, BANK_1);
|
||||
}
|
||||
}
|
||||
|
@ -656,10 +651,8 @@ int32_t stlink_flashloader_start(stlink_t *sl, flash_loader_t *fl) {
|
|||
uint32_t flash_regs_base = get_stm32l0_flash_base(sl);
|
||||
|
||||
// disable pecr protection
|
||||
stlink_write_debug32(sl, flash_regs_base + FLASH_PEKEYR_OFF,
|
||||
FLASH_L0_PEKEY1);
|
||||
stlink_write_debug32(sl, flash_regs_base + FLASH_PEKEYR_OFF,
|
||||
FLASH_L0_PEKEY2);
|
||||
stlink_write_debug32(sl, flash_regs_base + FLASH_PEKEYR_OFF, FLASH_L0_PEKEY1);
|
||||
stlink_write_debug32(sl, flash_regs_base + FLASH_PEKEYR_OFF, FLASH_L0_PEKEY2);
|
||||
|
||||
// check pecr.pelock is cleared
|
||||
stlink_read_debug32(sl, flash_regs_base + FLASH_PECR_OFF, &val);
|
||||
|
@ -669,10 +662,8 @@ int32_t stlink_flashloader_start(stlink_t *sl, flash_loader_t *fl) {
|
|||
}
|
||||
|
||||
// unlock program memory
|
||||
stlink_write_debug32(sl, flash_regs_base + FLASH_PRGKEYR_OFF,
|
||||
FLASH_L0_PRGKEY1);
|
||||
stlink_write_debug32(sl, flash_regs_base + FLASH_PRGKEYR_OFF,
|
||||
FLASH_L0_PRGKEY2);
|
||||
stlink_write_debug32(sl, flash_regs_base + FLASH_PRGKEYR_OFF, FLASH_L0_PRGKEY1);
|
||||
stlink_write_debug32(sl, flash_regs_base + FLASH_PRGKEYR_OFF, FLASH_L0_PRGKEY2);
|
||||
|
||||
// check pecr.prglock is cleared
|
||||
stlink_read_debug32(sl, flash_regs_base + FLASH_PECR_OFF, &val);
|
||||
|
@ -728,17 +719,15 @@ int32_t stlink_flashloader_start(stlink_t *sl, flash_loader_t *fl) {
|
|||
}
|
||||
|
||||
int32_t stlink_flashloader_write(stlink_t *sl, flash_loader_t *fl, stm32_addr_t addr, uint8_t *base, uint32_t len) {
|
||||
size_t off;
|
||||
uint32_t off;
|
||||
if ((sl->flash_type == STM32_FLASH_TYPE_F2_F4) ||
|
||||
(sl->flash_type == STM32_FLASH_TYPE_F7) ||
|
||||
(sl->flash_type == STM32_FLASH_TYPE_L4)) {
|
||||
size_t buf_size = (sl->sram_size > 0x8000) ? 0x8000 : 0x4000;
|
||||
uint32_t buf_size = (sl->sram_size > 0x8000) ? 0x8000 : 0x4000;
|
||||
for (off = 0; off < len;) {
|
||||
size_t size = len - off > buf_size ? buf_size : len - off;
|
||||
if (stlink_flash_loader_run(sl, fl, addr + (uint32_t)off, base + off,
|
||||
size) == -1) {
|
||||
ELOG("stlink_flash_loader_run(%#x) failed! == -1\n",
|
||||
(uint32_t)(addr + off));
|
||||
uint32_t size = len - off > buf_size ? buf_size : len - off;
|
||||
if (stlink_flash_loader_run(sl, fl, addr + off, base + off, size) == -1) {
|
||||
ELOG("stlink_flash_loader_run(%#x) failed! == -1\n", (addr + off));
|
||||
check_flash_error(sl);
|
||||
return (-1);
|
||||
}
|
||||
|
@ -749,38 +738,34 @@ int32_t stlink_flashloader_write(stlink_t *sl, flash_loader_t *fl, stm32_addr_t
|
|||
sl->flash_type == STM32_FLASH_TYPE_G0 ||
|
||||
sl->flash_type == STM32_FLASH_TYPE_G4 ||
|
||||
sl->flash_type == STM32_FLASH_TYPE_L5_U5) {
|
||||
DLOG("Starting %3u page write\r\n", (uint32_t)(len / sl->flash_pgsz));
|
||||
DLOG("Starting %3u page write\n", len / sl->flash_pgsz);
|
||||
for (off = 0; off < len; off += sizeof(uint32_t)) {
|
||||
uint32_t data;
|
||||
|
||||
if ((off % sl->flash_pgsz) > (sl->flash_pgsz - 5)) {
|
||||
fprintf(stdout, "\r%3u/%3u pages written",
|
||||
(uint32_t)(off / sl->flash_pgsz + 1),
|
||||
(uint32_t)(len / sl->flash_pgsz));
|
||||
fprintf(stdout, "\r%3u/%3u pages written", (off / sl->flash_pgsz + 1), (len / sl->flash_pgsz));
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
// write_uint32((unsigned char *)&data, *(uint32_t *)(base + off));
|
||||
data = 0;
|
||||
memcpy(&data, base + off, (len - off) < 4 ? (len - off) : 4);
|
||||
stlink_write_debug32(sl, addr + (uint32_t)off, data);
|
||||
stlink_write_debug32(sl, addr + off, data);
|
||||
wait_flash_busy(sl); // wait for 'busy' bit in FLASH_SR to clear
|
||||
}
|
||||
fprintf(stdout, "\n");
|
||||
|
||||
// flash writes happen as 2 words at a time
|
||||
if ((off / sizeof(uint32_t)) % 2 != 0) {
|
||||
stlink_write_debug32(sl, addr + (uint32_t)off,
|
||||
0); // write a single word of zeros
|
||||
wait_flash_busy(sl); // wait for 'busy' bit in FLASH_SR to clear
|
||||
stlink_write_debug32(sl, addr + off, 0); // write a single word of zeros
|
||||
wait_flash_busy(sl); // wait for 'busy' bit in FLASH_SR to clear
|
||||
}
|
||||
} else if (sl->flash_type == STM32_FLASH_TYPE_L0_L1) {
|
||||
uint32_t val;
|
||||
uint32_t flash_regs_base = get_stm32l0_flash_base(sl);
|
||||
uint32_t pagesize = (flash_regs_base == FLASH_L0_REGS_ADDR)?
|
||||
L0_WRITE_BLOCK_SIZE:L1_WRITE_BLOCK_SIZE;
|
||||
uint32_t pagesize = (flash_regs_base == FLASH_L0_REGS_ADDR)? L0_WRITE_BLOCK_SIZE : L1_WRITE_BLOCK_SIZE;
|
||||
|
||||
DLOG("Starting %3u page write\r\n", (uint32_t)(len / sl->flash_pgsz));
|
||||
DLOG("Starting %3u page write\r\n", len / sl->flash_pgsz);
|
||||
|
||||
off = 0;
|
||||
|
||||
|
@ -797,14 +782,12 @@ int32_t stlink_flashloader_write(stlink_t *sl, flash_loader_t *fl, stm32_addr_t
|
|||
uint32_t data;
|
||||
|
||||
if ((off % sl->flash_pgsz) > (sl->flash_pgsz - 5)) {
|
||||
fprintf(stdout, "\r%3u/%3u pages written",
|
||||
(uint32_t)(off / sl->flash_pgsz + 1),
|
||||
(uint32_t)(len / sl->flash_pgsz));
|
||||
fprintf(stdout, "\r%3u/%3u pages written", (off / sl->flash_pgsz + 1), (len / sl->flash_pgsz));
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
write_uint32((unsigned char *)&data, *(uint32_t *)(base + off));
|
||||
stlink_write_debug32(sl, addr + (uint32_t)off, data);
|
||||
stlink_write_debug32(sl, addr + off, data);
|
||||
|
||||
// wait for sr.busy to be cleared
|
||||
do {
|
||||
|
@ -814,22 +797,19 @@ int32_t stlink_flashloader_write(stlink_t *sl, flash_loader_t *fl, stm32_addr_t
|
|||
// TODO: check redo write operation
|
||||
}
|
||||
fprintf(stdout, "\n");
|
||||
} else if ((sl->flash_type == STM32_FLASH_TYPE_F0_F1_F3) ||
|
||||
(sl->flash_type == STM32_FLASH_TYPE_F1_XL)) {
|
||||
} else if ((sl->flash_type == STM32_FLASH_TYPE_F0_F1_F3) || (sl->flash_type == STM32_FLASH_TYPE_F1_XL)) {
|
||||
int32_t write_block_count = 0;
|
||||
for (off = 0; off < len; off += sl->flash_pgsz) {
|
||||
// adjust last write size
|
||||
size_t size = len - off > sl->flash_pgsz ? sl->flash_pgsz : len - off;
|
||||
uint32_t size = len - off > sl->flash_pgsz ? sl->flash_pgsz : len - off;
|
||||
|
||||
// unlock and set programming mode
|
||||
unlock_flash_if(sl);
|
||||
|
||||
DLOG("Finished unlocking flash, running loader!\n");
|
||||
|
||||
if (stlink_flash_loader_run(sl, fl, addr + (uint32_t)off, base + off,
|
||||
size) == -1) {
|
||||
ELOG("stlink_flash_loader_run(%#x) failed! == -1\n",
|
||||
(uint32_t)(addr + off));
|
||||
if (stlink_flash_loader_run(sl, fl, addr + off, base + off, size) == -1) {
|
||||
ELOG("stlink_flash_loader_run(%#x) failed! == -1\n", (addr + off));
|
||||
check_flash_error(sl);
|
||||
return (-1);
|
||||
}
|
||||
|
@ -840,7 +820,7 @@ int32_t stlink_flashloader_write(stlink_t *sl, flash_loader_t *fl, stm32_addr_t
|
|||
// show progress; writing procedure is slow and previous errors are
|
||||
// misleading
|
||||
fprintf(stdout, "\r%3u/%3u pages written", ++write_block_count,
|
||||
(uint32_t)((len + sl->flash_pgsz - 1) / sl->flash_pgsz));
|
||||
(len + sl->flash_pgsz - 1) / sl->flash_pgsz);
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
@ -850,17 +830,16 @@ int32_t stlink_flashloader_write(stlink_t *sl, flash_loader_t *fl, stm32_addr_t
|
|||
} else if (sl->flash_type == STM32_FLASH_TYPE_H7) {
|
||||
for (off = 0; off < len;) {
|
||||
// Program STM32H7x with 64-byte Flash words
|
||||
size_t chunk = (len - off > 64) ? 64 : len - off;
|
||||
uint32_t chunk = (len - off > 64) ? 64 : len - off;
|
||||
memcpy(sl->q_buf, base + off, chunk);
|
||||
stlink_write_mem32(sl, addr + (uint32_t)off, 64);
|
||||
stlink_write_mem32(sl, addr + off, 64);
|
||||
wait_flash_busy(sl);
|
||||
|
||||
off += chunk;
|
||||
|
||||
if (sl->verbose >= 1) {
|
||||
// show progress
|
||||
fprintf(stdout, "\r%u/%u bytes written", (uint32_t)off,
|
||||
(uint32_t)len);
|
||||
fprintf(stdout, "\r%u/%u bytes written", off, len);
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,11 +9,11 @@
|
|||
|
||||
int32_t stlink_flash_loader_init(stlink_t *sl, flash_loader_t* fl);
|
||||
// static int32_t loader_v_dependent_assignment(stlink_t *sl,
|
||||
// const uint8_t **loader_code, size_t *loader_size,
|
||||
// const uint8_t *high_v_loader, size_t high_v_loader_size,
|
||||
// const uint8_t *low_v_loader, size_t low_v_loader_size);
|
||||
int32_t stlink_flash_loader_write_to_sram(stlink_t *sl, stm32_addr_t* addr, size_t* size);
|
||||
int32_t stlink_flash_loader_run(stlink_t *sl, flash_loader_t* fl, stm32_addr_t target, const uint8_t* buf, size_t size);
|
||||
// const uint8_t **loader_code, uint32_t *loader_size,
|
||||
// const uint8_t *high_v_loader, uint32_t high_v_loader_size,
|
||||
// const uint8_t *low_v_loader, uint32_t low_v_loader_size);
|
||||
int32_t stlink_flash_loader_write_to_sram(stlink_t *sl, stm32_addr_t* addr, uint32_t* size);
|
||||
int32_t stlink_flash_loader_run(stlink_t *sl, flash_loader_t* fl, stm32_addr_t target, const uint8_t* buf, uint32_t size);
|
||||
|
||||
|
||||
/* === Functions from old header file flashloader.h === */
|
||||
|
|
|
@ -28,17 +28,17 @@
|
|||
* STLINK2 Maybe STLINK V1 needs smaller value!
|
||||
*/
|
||||
int32_t check_file(stlink_t *sl, mapped_file_t *mf, stm32_addr_t addr) {
|
||||
size_t off;
|
||||
size_t n_cmp = sl->flash_pgsz;
|
||||
uint32_t off;
|
||||
uint32_t n_cmp = sl->flash_pgsz;
|
||||
|
||||
if (n_cmp > 0x1800) {
|
||||
n_cmp = 0x1800;
|
||||
}
|
||||
|
||||
for (off = 0; off < mf->len; off += n_cmp) {
|
||||
size_t aligned_size;
|
||||
uint32_t aligned_size;
|
||||
|
||||
size_t cmp_size = n_cmp; // adjust last page size
|
||||
uint32_t cmp_size = n_cmp; // adjust last page size
|
||||
|
||||
if ((off + n_cmp) > mf->len) {
|
||||
cmp_size = mf->len - off;
|
||||
|
@ -50,7 +50,7 @@ int32_t check_file(stlink_t *sl, mapped_file_t *mf, stm32_addr_t addr) {
|
|||
aligned_size = (cmp_size + 4) & ~(4 - 1);
|
||||
}
|
||||
|
||||
stlink_read_mem32(sl, addr + (uint32_t)off, (uint16_t)aligned_size);
|
||||
stlink_read_mem32(sl, addr + off, (uint16_t)aligned_size);
|
||||
|
||||
if (memcmp(sl->q_buf, mf->base + off, cmp_size)) {
|
||||
return (-1);
|
||||
|
@ -80,7 +80,7 @@ int32_t map_file(mapped_file_t *mf, const char *path) {
|
|||
// on 32 bit systems, check if there is an overflow
|
||||
if (st.st_size > (off_t)MAX_FILE_SIZE /*1 GB*/ ) {
|
||||
// limit file size to 1 GB
|
||||
fprintf(stderr, "mmap() size_t overflow for file %s\n", path);
|
||||
fprintf(stderr, "mmap() uint32_t overflow for file %s\n", path);
|
||||
goto on_error;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
/* Memory mapped file */
|
||||
typedef struct mapped_file {
|
||||
uint8_t *base;
|
||||
size_t len;
|
||||
uint32_t len;
|
||||
} mapped_file_t;
|
||||
|
||||
#define MAPPED_FILE_INITIALIZER \
|
||||
|
|
|
@ -34,7 +34,7 @@ void stlink_checksum(mapped_file_t *mp) {
|
|||
uint32_t sum = 0;
|
||||
uint8_t *mp_byte = (uint8_t *)mp->base;
|
||||
|
||||
for (size_t i = 0; i < mp->len; ++i) {
|
||||
for (uint32_t i = 0; i < mp->len; ++i) {
|
||||
sum += mp_byte[i];
|
||||
}
|
||||
|
||||
|
|
|
@ -44,4 +44,4 @@ int32_t stlink_write_option_bytes32(stlink_t *sl, uint32_t option_byte);
|
|||
int32_t stlink_read_option_bytes_boot_add32(stlink_t *sl, uint32_t* option_byte);
|
||||
int32_t stlink_write_option_bytes_boot_add32(stlink_t *sl, uint32_t option_bytes_boot_add);
|
||||
|
||||
#endif // OPTION_BYTES_H
|
||||
#endif // OPTION_BYTES_H
|
||||
|
|
|
@ -36,7 +36,7 @@ int32_t stlink_read_debug32(stlink_t *sl, uint32_t addr, uint32_t *data) {
|
|||
|
||||
ret = sl->backend->read_debug32(sl, addr, data);
|
||||
if (!ret)
|
||||
DLOG("*** stlink_read_debug32 %#010x at %#010x\n", *data, addr);
|
||||
DLOG("*** stlink_read_debug32 %#010x at %#010x\n", *data, addr);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@
|
|||
#define STLINK_FALSE 0x81
|
||||
|
||||
static void clear_cdb(struct stlink_libsg *sl) {
|
||||
for (size_t i = 0; i < sizeof(sl->cdb_cmd_blk); i++) { sl->cdb_cmd_blk[i] = 0; }
|
||||
for (uint32_t i = 0; i < sizeof(sl->cdb_cmd_blk); i++) { sl->cdb_cmd_blk[i] = 0; }
|
||||
|
||||
// set default
|
||||
sl->cdb_cmd_blk[0] = STLINK_DEBUG_COMMAND;
|
||||
|
|
|
@ -90,8 +90,8 @@ void _stlink_usb_close(stlink_t* sl) {
|
|||
}
|
||||
}
|
||||
|
||||
ssize_t send_recv(struct stlink_libusb* handle, int32_t terminate, unsigned char* txbuf, size_t txsize,
|
||||
unsigned char* rxbuf, size_t rxsize, int32_t check_error, const char *cmd) {
|
||||
ssize_t send_recv(struct stlink_libusb* handle, int32_t terminate, unsigned char* txbuf, uint32_t txsize,
|
||||
unsigned char* rxbuf, uint32_t rxsize, int32_t check_error, const char *cmd) {
|
||||
// Note: txbuf and rxbuf can point to the same area
|
||||
int32_t res, t, retry = 0;
|
||||
|
||||
|
@ -168,7 +168,7 @@ ssize_t send_recv(struct stlink_libusb* handle, int32_t terminate, unsigned char
|
|||
}
|
||||
|
||||
static inline int32_t send_only(struct stlink_libusb* handle, int32_t terminate, unsigned char* txbuf,
|
||||
size_t txsize, const char *cmd) {
|
||||
uint32_t txsize, const char *cmd) {
|
||||
return((int32_t)send_recv(handle, terminate, txbuf, txsize, NULL, 0, CMD_CHECK_NO, cmd));
|
||||
}
|
||||
|
||||
|
@ -1000,7 +1000,7 @@ int32_t _stlink_usb_disable_trace(stlink_t* sl) {
|
|||
return(size<0?-1:0);
|
||||
}
|
||||
|
||||
int32_t _stlink_usb_read_trace(stlink_t* sl, uint8_t* buf, size_t size) {
|
||||
int32_t _stlink_usb_read_trace(stlink_t* sl, uint8_t* buf, uint32_t size) {
|
||||
struct stlink_libusb * const slu = sl->backend_data;
|
||||
unsigned char* const data = sl->q_buf;
|
||||
unsigned char* const cmd = sl->c_buf;
|
||||
|
@ -1160,7 +1160,7 @@ stlink_t *stlink_open_usb(enum ugly_loglevel verbose, enum connect_type connect,
|
|||
|
||||
if (ret) { continue; } // could not open device
|
||||
|
||||
size_t serial_len = stlink_serial(handle, &desc, sl->serial);
|
||||
uint32_t serial_len = stlink_serial(handle, &desc, sl->serial);
|
||||
|
||||
libusb_close(handle);
|
||||
|
||||
|
@ -1300,12 +1300,12 @@ on_malloc_error:
|
|||
return(NULL);
|
||||
}
|
||||
|
||||
static size_t stlink_probe_usb_devs(libusb_device **devs, stlink_t **sldevs[], enum connect_type connect, int32_t freq) {
|
||||
static uint32_t stlink_probe_usb_devs(libusb_device **devs, stlink_t **sldevs[], enum connect_type connect, int32_t freq) {
|
||||
stlink_t **_sldevs;
|
||||
libusb_device *dev;
|
||||
int32_t i = 0;
|
||||
size_t slcnt = 0;
|
||||
size_t slcur = 0;
|
||||
uint32_t slcnt = 0;
|
||||
uint32_t slcur = 0;
|
||||
|
||||
/* Count STLINKs */
|
||||
while ((dev = devs[i++]) != NULL) {
|
||||
|
@ -1363,7 +1363,7 @@ static size_t stlink_probe_usb_devs(libusb_device **devs, stlink_t **sldevs[], e
|
|||
break;
|
||||
}
|
||||
|
||||
size_t serial_len = stlink_serial(handle, &desc, serial);
|
||||
uint32_t serial_len = stlink_serial(handle, &desc, serial);
|
||||
|
||||
libusb_close(handle);
|
||||
|
||||
|
@ -1388,7 +1388,7 @@ size_t stlink_probe_usb(stlink_t **stdevs[], enum connect_type connect, int32_t
|
|||
libusb_device **devs;
|
||||
stlink_t **sldevs;
|
||||
|
||||
size_t slcnt = 0;
|
||||
uint32_t slcnt = 0;
|
||||
int32_t r;
|
||||
ssize_t cnt;
|
||||
|
||||
|
@ -1410,10 +1410,10 @@ size_t stlink_probe_usb(stlink_t **stdevs[], enum connect_type connect, int32_t
|
|||
return(slcnt);
|
||||
}
|
||||
|
||||
void stlink_probe_usb_free(stlink_t ***stdevs, size_t size) {
|
||||
void stlink_probe_usb_free(stlink_t ***stdevs, uint32_t size) {
|
||||
if (stdevs == NULL || *stdevs == NULL || size == 0) { return; }
|
||||
|
||||
for (size_t n = 0; n < size; n++) { stlink_close((*stdevs)[n]); }
|
||||
for (uint32_t n = 0; n < size; n++) { stlink_close((*stdevs)[n]); }
|
||||
|
||||
free(*stdevs);
|
||||
*stdevs = NULL;
|
||||
|
|
|
@ -62,10 +62,10 @@ struct stlink_libusb {
|
|||
// static inline uint32_t le_to_h_u32(const uint8_t* buf);
|
||||
// static int32_t _stlink_match_speed_map(const uint32_t *map, uint32_t map_size, uint32_t khz);
|
||||
void _stlink_usb_close(stlink_t* sl);
|
||||
ssize_t send_recv(struct stlink_libusb* handle, int32_t terminate, unsigned char* txbuf, size_t txsize,
|
||||
unsigned char* rxbuf, size_t rxsize, int32_t check_error, const char *cmd);
|
||||
ssize_t send_recv(struct stlink_libusb* handle, int32_t terminate, unsigned char* txbuf, uint32_t txsize,
|
||||
unsigned char* rxbuf, uint32_t rxsize, int32_t check_error, const char *cmd);
|
||||
// static inline int32_t send_only(struct stlink_libusb* handle, int32_t terminate, unsigned char* txbuf,
|
||||
// size_t txsize, const char *cmd);
|
||||
// uint32_t txsize, const char *cmd);
|
||||
// static int32_t fill_command(stlink_t * sl, enum SCSI_Generic_Direction dir, uint32_t len);
|
||||
int32_t _stlink_usb_version(stlink_t *sl);
|
||||
int32_t _stlink_usb_target_voltage(stlink_t *sl);
|
||||
|
@ -96,14 +96,14 @@ int32_t _stlink_usb_write_unsupported_reg(stlink_t *sl, uint32_t val, int32_t r_
|
|||
int32_t _stlink_usb_write_reg(stlink_t *sl, uint32_t reg, int32_t idx);
|
||||
int32_t _stlink_usb_enable_trace(stlink_t* sl, uint32_t frequency);
|
||||
int32_t _stlink_usb_disable_trace(stlink_t* sl);
|
||||
int32_t _stlink_usb_read_trace(stlink_t* sl, uint8_t* buf, size_t size);
|
||||
int32_t _stlink_usb_read_trace(stlink_t* sl, uint8_t* buf, uint32_t size);
|
||||
|
||||
// static stlink_backend_t _stlink_usb_backend = { };
|
||||
|
||||
size_t stlink_serial(struct libusb_device_handle *handle, struct libusb_device_descriptor *desc, char *serial);
|
||||
stlink_t *stlink_open_usb(enum ugly_loglevel verbose, enum connect_type connect, char serial[STLINK_SERIAL_BUFFER_SIZE], int32_t freq);
|
||||
// static size_t stlink_probe_usb_devs(libusb_device **devs, stlink_t **sldevs[], enum connect_type connect, int32_t freq);
|
||||
// static uint32_t stlink_probe_usb_devs(libusb_device **devs, stlink_t **sldevs[], enum connect_type connect, int32_t freq);
|
||||
size_t stlink_probe_usb(stlink_t **stdevs[], enum connect_type connect, int32_t freq);
|
||||
void stlink_probe_usb_free(stlink_t **stdevs[], size_t size);
|
||||
void stlink_probe_usb_free(stlink_t **stdevs[], uint32_t size);
|
||||
|
||||
#endif // USB_H
|
||||
|
|
|
@ -134,7 +134,7 @@ int32_t getopt_long(int32_t argc,
|
|||
const struct option* o = longopts;
|
||||
const struct option* match = NULL;
|
||||
int32_t num_matches = 0;
|
||||
size_t argument_name_length = 0;
|
||||
uint32_t argument_name_length = 0;
|
||||
const char* current_argument = NULL;
|
||||
int32_t retval = -1;
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include "mmap.h"
|
||||
|
||||
void *mmap (void *addr, size_t len, int32_t prot, int32_t flags, int32_t fd, int64_t offset) {
|
||||
void *mmap (void *addr, uint32_t len, int32_t prot, int32_t flags, int32_t fd, int64_t offset) {
|
||||
void *buf;
|
||||
ssize_t count;
|
||||
|
||||
|
@ -32,7 +32,7 @@ void *mmap (void *addr, size_t len, int32_t prot, int32_t flags, int32_t fd, int
|
|||
(void)flags;
|
||||
}
|
||||
|
||||
int32_t munmap (void *addr, size_t len) {
|
||||
int32_t munmap (void *addr, uint32_t len) {
|
||||
free (addr);
|
||||
return(0);
|
||||
(void)len;
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
#define MAP_ANONYMOUS (1 << 5)
|
||||
#define MAP_FAILED ((void *)-1)
|
||||
|
||||
void *mmap(void *addr, size_t len, int32_t prot, int32_t flags, int32_t fd, int64_t offset);
|
||||
int32_t munmap(void *addr, size_t len);
|
||||
void *mmap(void *addr, uint32_t len, int32_t prot, int32_t flags, int32_t fd, int64_t offset);
|
||||
int32_t munmap(void *addr, uint32_t len);
|
||||
|
||||
#endif // STLINK_HAVE_SYS_MMAN_H
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ static bool cmp_strings(const char * s1, const char * s2) {
|
|||
}
|
||||
}
|
||||
|
||||
static bool cmp_mem(const uint8_t * s1, const uint8_t * s2, size_t size) {
|
||||
static bool cmp_mem(const uint8_t * s1, const uint8_t * s2, uint32_t size) {
|
||||
if (s1 == NULL || s2 == NULL) {
|
||||
return (s1 == s2);
|
||||
} else {
|
||||
|
@ -231,7 +231,7 @@ static struct Test tests[] = {
|
|||
int32_t main() {
|
||||
bool allOk = true;
|
||||
|
||||
for (size_t i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
|
||||
for (uint32_t i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
|
||||
if (!execute_test(&tests[i]))
|
||||
allOk = false;
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue