From: Simon Wright Date: Fri, 23 Jan 2015 20:43:32 +0000 (+0000) Subject: Merge branch 'master' of https://github.com/texane/stlink X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=5a722e32100257b4ea70f23fb766cff748c21b59;hp=b2dac269232543ae595e349b1c5b64b6d0cb5af6;p=fw%2Fstlink Merge branch 'master' of https://github.com/texane/stlink --- diff --git a/README b/README index 6f0a1ad..cedbd24 100644 --- a/README +++ b/README @@ -187,5 +187,7 @@ Known Working Targets: * STM32F401xx (STM32 Nucleo-F401RE board) * STM32F030R8T6 (STM32 Nucleo-F030R8 board) * STM32F072RBT6 (STM32 Nucleo-F072RB board) +* STM32F103RB (STM32 Nucleo-F103RB board) +* STM32F334R8 (STM32 Nucleo-F334R8 board) Please report any and all known working combinations so I can update this! diff --git a/flash/main.c b/flash/main.c index 82803fe..f843232 100644 --- a/flash/main.c +++ b/flash/main.c @@ -9,6 +9,9 @@ #include #include "stlink-common.h" +#define DEBUG_LOG_LEVEL 100 +#define STND_LOG_LEVEL 50 + enum st_cmds {DO_WRITE = 0, DO_READ = 1, DO_ERASE = 2}; struct opts { @@ -18,26 +21,38 @@ struct opts stm32_addr_t addr; size_t size; int reset; + int log_level; }; static void usage(void) { - puts("stlinkv1 command line: ./flash [--reset] {read|write} /dev/sgX path addr "); - puts("stlinkv1 command line: ./flash /dev/sgX erase"); - puts("stlinkv2 command line: ./flash [--reset] {read|write} path addr "); - puts("stlinkv2 command line: ./flash erase"); + puts("stlinkv1 command line: ./st-flash [--debug] [--reset] {read|write} /dev/sgX path addr "); + puts("stlinkv1 command line: ./st-flash [--debug] /dev/sgX erase"); + puts("stlinkv2 command line: ./st-flash [--debug] [--reset] {read|write} path addr "); + puts("stlinkv2 command line: ./st-flash [--debug] erase"); puts(" use hex format for addr and "); } static int get_opts(struct opts* o, int ac, char** av) { - /* stlinkv1 command line: ./flash {read|write} /dev/sgX path addr */ - /* stlinkv2 command line: ./flash {read|write} path addr */ + /* stlinkv1 command line: ./st-flash {read|write} /dev/sgX path addr */ + /* stlinkv2 command line: ./st-flash {read|write} path addr */ unsigned int i = 0; if (ac < 1) return -1; + if (strcmp(av[0], "--debug") == 0) + { + o->log_level = DEBUG_LOG_LEVEL; + ac--; + av++; + } + else + { + o->log_level = STND_LOG_LEVEL; + } + if (strcmp(av[0], "--reset") == 0) { o->reset = 1; @@ -120,15 +135,15 @@ int main(int ac, char** av) if (o.devname != NULL) /* stlinkv1 */ { - sl = stlink_v1_open(50, 1); + sl = stlink_v1_open(o.log_level, 1); if (sl == NULL) goto on_error; - sl->verbose = 50; + sl->verbose = o.log_level; } else /* stlinkv2 */ { - sl = stlink_open_usb(50, 1); + sl = stlink_open_usb(o.log_level, 1); if (sl == NULL) goto on_error; - sl->verbose = 50; + sl->verbose = o.log_level; } if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE) diff --git a/gdbserver/gdb-server.c b/gdbserver/gdb-server.c index 2753709..daacb85 100644 --- a/gdbserver/gdb-server.c +++ b/gdbserver/gdb-server.c @@ -310,6 +310,7 @@ static const char* const memory_map_template_F4 = " 0x20000" //128kB " " " " // peripheral regs + " " // AHB3 Peripherals " " // cortex regs " " // bootrom " " // option byte area diff --git a/src/stlink-common.c b/src/stlink-common.c index 4d30287..6e327f0 100644 --- a/src/stlink-common.c +++ b/src/stlink-common.c @@ -478,6 +478,12 @@ int stlink_load_device_params(stlink_t *sl) { sl->sys_base = params->bootrom_base; sl->sys_size = params->bootrom_size; + //medium and low devices have the same chipid. ram size depends on flash size. + //STM32F100xx datasheet Doc ID 16455 Table 2 + if(sl->chip_id == STM32_CHIPID_F1_VL_MEDIUM_LOW && sl->flash_size < 64 * 1024){ + sl->sram_size = 0x1000; + } + ILOG("Device connected is: %s, id %#x\n", params->description, chip_id); // TODO make note of variable page size here..... ILOG("SRAM size: %#x bytes (%d KiB), Flash: %#x bytes (%d KiB) in pages of %zd bytes\n", @@ -1379,7 +1385,7 @@ int write_loader_to_sram(stlink_t *sl, stm32_addr_t* addr, size_t* size) { sl->chip_id == STM32_CHIPID_F4_LP || sl->chip_id == STM32_CHIPID_F4_HD || (sl->chip_id == STM32_CHIPID_F411RE)){ loader_code = loader_code_stm32f4; loader_size = sizeof(loader_code_stm32f4); - } else if (sl->chip_id == STM32_CHIPID_F0 || sl->chip_id == STM32_CHIPID_F0_CAN || sl->chip_id == STM32_CHIPID_F0_SMALL) { + } else if (sl->chip_id == STM32_CHIPID_F0 || sl->chip_id == STM32_CHIPID_F04 || sl->chip_id == STM32_CHIPID_F0_CAN || sl->chip_id == STM32_CHIPID_F0_SMALL) { loader_code = loader_code_stm32f0; loader_size = sizeof(loader_code_stm32f0); } else if (sl->chip_id == STM32_CHIPID_L0) { diff --git a/src/stlink-common.h b/src/stlink-common.h index 17e488d..aeeaa85 100644 --- a/src/stlink-common.h +++ b/src/stlink-common.h @@ -108,7 +108,7 @@ extern "C" { #define STM32_CHIPID_L0 0x417 #define STM32_CHIPID_F1_CONN 0x418 #define STM32_CHIPID_F4_HD 0x419 -#define STM32_CHIPID_F1_VL_MEDIUM 0x420 +#define STM32_CHIPID_F1_VL_MEDIUM_LOW 0x420 #define STM32_CHIPID_F3 0x422 #define STM32_CHIPID_F4_LP 0x423 @@ -132,6 +132,8 @@ extern "C" { #define STM32_CHIPID_F0_SMALL 0x444 +#define STM32_CHIPID_F04 0x445 + #define STM32_CHIPID_F0_CAN 0x448 /* @@ -296,12 +298,12 @@ extern "C" { .bootrom_base = 0x1fffb000, .bootrom_size = 0x4800 }, - { - .chip_id = STM32_CHIPID_F1_VL_MEDIUM, - .description = "F1 Medium-density Value Line device", + {//Low and Medium density VL have same chipid. RM0041 25.6.1 + .chip_id = STM32_CHIPID_F1_VL_MEDIUM_LOW, + .description = "F1 Medium/Low-density Value Line device", .flash_size_reg = 0x1ffff7e0, .flash_pagesize = 0x400, - .sram_size = 0x2000, + .sram_size = 0x2000,//0x1000 for low density devices .bootrom_base = 0x1ffff000, .bootrom_size = 0x800 }, @@ -367,6 +369,17 @@ extern "C" { .bootrom_base = 0x1fffec00, // "System memory" starting address from Table 2 .bootrom_size = 0xC00 // "System memory" byte size in hex from Table 2 }, + { + //Use this as an example for mapping future chips: + //RM0091 document was used to find these paramaters + .chip_id = STM32_CHIPID_F04, + .description = "F04x device", + .flash_size_reg = 0x1ffff7cc, // "Flash size data register" (pg735) + .flash_pagesize = 0x400, // Page sizes listed in Table 4 + .sram_size = 0x1000, // "SRAM" byte size in hex from Table 2 + .bootrom_base = 0x1fffec00, // "System memory" starting address from Table 2 + .bootrom_size = 0xC00 // "System memory" byte size in hex from Table 2 + }, { //Use this as an example for mapping future chips: //RM0091 document was used to find these paramaters diff --git a/src/stlink-usb.c b/src/stlink-usb.c index d9faaa9..d8b6c46 100644 --- a/src/stlink-usb.c +++ b/src/stlink-usb.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "stlink-common.h" #include "stlink-usb.h" @@ -788,7 +789,8 @@ stlink_t* stlink_open_usb(const int verbose, int reset) { } else { int error = libusb_open(list[cnt], &slu->usb_handle); if( error !=0 ) { - WLOG("Error %d opening ST-Link/V2 device %03d:%03d\n", error, libusb_get_bus_number(list[cnt]), libusb_get_device_address(list[cnt])); + WLOG("Error %d (%s) opening ST-Link/V2 device %03d:%03d\n", + error, strerror (errno), libusb_get_bus_number(list[cnt]), libusb_get_device_address(list[cnt])); goto on_error; } } @@ -864,10 +866,8 @@ stlink_t* stlink_open_usb(const int verbose, int reset) { if (reset) { stlink_reset(sl); } - stlink_load_device_params(sl); stlink_version(sl); - - error = 0; + error = stlink_load_device_params(sl); on_libusb_error: if (devs != NULL) { @@ -887,6 +887,6 @@ on_error: libusb_exit(slu->libusb_ctx); if (sl != NULL) free(sl); if (slu != NULL) free(slu); - return 0; + return NULL; }