[merge] karl/uwe_usb branch
authorFabien Le Mentec <texane@gmail.com>
Tue, 18 Oct 2011 21:35:24 +0000 (16:35 -0500)
committerFabien Le Mentec <texane@gmail.com>
Tue, 18 Oct 2011 21:35:24 +0000 (16:35 -0500)
gdbserver/gdb-server.c
src/stlink-usb.c

index d20d66af6354bd1d29bd35a0e804fcc57e371a8c..97288014965768b3a1e5169f819d08e69459e3ee 100644 (file)
@@ -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;
 
index f36c60fbeb184c6ebde6f7a45771abd042c71b0b..bf2f5b4c348384e491565ffd17c50cd0d068389f 100644 (file)
@@ -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;