From a34d5637572ee320e654daec1d7c6b82262f26ea Mon Sep 17 00:00:00 2001 From: Fabien Le Mentec Date: Tue, 18 Oct 2011 16:35:24 -0500 Subject: [PATCH] [merge] karl/uwe_usb branch --- gdbserver/gdb-server.c | 19 ++++++++++++++++--- src/stlink-usb.c | 6 +++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/gdbserver/gdb-server.c b/gdbserver/gdb-server.c index d20d66a..9728801 100644 --- a/gdbserver/gdb-server.c +++ b/gdbserver/gdb-server.c @@ -32,6 +32,11 @@ static const char* current_memory_map = NULL; * Chip IDs are explained in the appropriate programming manual for the * DBGMCU_IDCODE register (0xE0042000) */ + +#define CORE_M3_R1 0x1BA00477 +#define CORE_M3_R2 0x4BA00477 +#define CORE_M4_R0 0x2BA01477 + struct chip_params { uint32_t chip_id; char* description; @@ -43,11 +48,11 @@ struct chip_params { { 0x410, "F1 Medium-density device", 0x1ffff7e0, 0x20000, 0x400, 0x5000, 0x1ffff000, 0x800 }, // table 2, pm0063 { 0x411, "F2 device", 0, /* No flash size register found in the docs*/ - 0x100000, 0x20000, 0x20000, 0x1ff00000, 0x7800 }, // table 1, pm0059 + 0x100000, 0x20000, 0x20000, 0x1fff0000, 0x7800 }, // table 1, pm0059 { 0x412, "F1 Low-density device", 0x1ffff7e0, 0x8000, 0x400, 0x2800, 0x1ffff000, 0x800 }, // table 1, pm0063 { 0x413, "F4 device", 0x1FFF7A10, - 0x100000, 0x20000, 0x20000, 0x1ff00000, 0x7800 }, // table 1, pm0081 + 0x100000, 0x20000, 0x20000, 0x1fff0000, 0x7800 }, // table 1, pm0081 { 0x414, "F1 High-density device", 0x1ffff7e0, 0x80000, 0x800, 0x10000, 0x1ffff000, 0x800 }, // table 3 pm0063 // This ignores the EEPROM! (and uses the page erase size, @@ -147,7 +152,15 @@ int main(int argc, char** argv) { } uint32_t chip_id = stlink_chip_id(sl); - printf("Chip ID is %08x.\n", chip_id); + uint32_t core_id = stlink_core_id(sl); + + /* Fix chip_id for F4 */ + if (((chip_id & 0xFFF) == 0x411) && (core_id == CORE_M4_R0)) { + printf("Fixing wrong chip_id for STM32F4 Rev A errata\n"); + chip_id = 0x413; + } + + printf("Chip ID is %08x, Core ID is %08x.\n", chip_id, core_id); const struct chip_params* params = NULL; diff --git a/src/stlink-usb.c b/src/stlink-usb.c index f36c60f..bf2f5b4 100644 --- a/src/stlink-usb.c +++ b/src/stlink-usb.c @@ -124,6 +124,7 @@ ssize_t send_recv(struct stlink_libusb* handle, int terminate, (handle->rep_trans, handle->usb_handle, handle->ep_rep, sg_buf, 13, NULL, NULL, 0); res = submit_wait(handle, handle->rep_trans); + /* The STLink doesn't seem to evaluate the sequence number */ handle->sg_transfer_idx++; if (res ) return -1; } @@ -715,7 +716,10 @@ stlink_t* stlink_open_usb(const int verbose) { slu->cmd_len = (slu->protocoll == 1)? STLINK_SG_SIZE: STLINK_CMD_SIZE; /* success */ - stlink_exit_dfu_mode(sl); + if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE) { + printf("-- exit_dfu_mode\n"); + stlink_exit_dfu_mode(sl); + } stlink_version(sl); error = 0; -- 2.30.2