Merge branch 'master' of https://github.com/texane/stlink
authorSimon Wright <simon@pushface.org>
Fri, 23 Jan 2015 20:43:32 +0000 (20:43 +0000)
committerSimon Wright <simon@pushface.org>
Fri, 23 Jan 2015 20:43:32 +0000 (20:43 +0000)
README
flash/main.c
gdbserver/gdb-server.c
src/stlink-common.c
src/stlink-common.h
src/stlink-usb.c

diff --git a/README b/README
index 6f0a1ade23991026b0d9dadfddd00d2f4202d17b..cedbd2474e7fac908c1c4efb5f027100cada6446 100644 (file)
--- 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!
index 82803fe61e6b45bd4db01fe0cdd8bd62dc0bc20f..f84323217674b88a45eefe8bf520cd3833353cfa 100644 (file)
@@ -9,6 +9,9 @@
 #include <sys/types.h>
 #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 <size>");
-    puts("stlinkv1 command line: ./flash /dev/sgX erase");
-    puts("stlinkv2 command line: ./flash [--reset] {read|write} path addr <size>");
-    puts("stlinkv2 command line: ./flash erase");
+    puts("stlinkv1 command line: ./st-flash [--debug] [--reset] {read|write} /dev/sgX path addr <size>");
+    puts("stlinkv1 command line: ./st-flash [--debug] /dev/sgX erase");
+    puts("stlinkv2 command line: ./st-flash [--debug] [--reset] {read|write} path addr <size>");
+    puts("stlinkv2 command line: ./st-flash [--debug] erase");
     puts("                       use hex format for addr and <size>");
 }
 
 static int get_opts(struct opts* o, int ac, char** av)
 {
-    /* stlinkv1 command line: ./flash {read|write} /dev/sgX path addr <size> */
-    /* stlinkv2 command line: ./flash {read|write} path addr <size> */
+    /* stlinkv1 command line: ./st-flash {read|write} /dev/sgX path addr <size> */
+    /* stlinkv2 command line: ./st-flash {read|write} path addr <size> */
 
     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)
index 275370991125bcbe0ae9fc059f6973f82e915ca7..daacb85cb6a6eb4d85146e115849d5e80d808a6a 100644 (file)
@@ -310,6 +310,7 @@ static const char* const memory_map_template_F4 =
     "    <property name=\"blocksize\">0x20000</property>"                   //128kB
     "  </memory>"
     "  <memory type=\"ram\" start=\"0x40000000\" length=\"0x1fffffff\"/>"   // peripheral regs
+    "  <memory type=\"ram\" start=\"0x60000000\" length=\"0x7fffffff\"/>"   // AHB3 Peripherals
     "  <memory type=\"ram\" start=\"0xe0000000\" length=\"0x1fffffff\"/>"   // cortex regs
     "  <memory type=\"rom\" start=\"0x1fff0000\" length=\"0x7800\"/>"       // bootrom
     "  <memory type=\"rom\" start=\"0x1fffc000\" length=\"0x10\"/>"         // option byte area
index 4d30287add9b39dfbddc8259bf67077566f69c9f..6e327f02877a854ed2cac3aed54923e7cdac21ba 100644 (file)
@@ -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) {
index 17e488dcff645b45d1657c39a89b8fac6fff5695..aeeaa85a4778e3eb7cc57e15a0a00bfbc6793b2f 100644 (file)
@@ -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
index d9faaa9f8d1fc6fc3a68775345e21d9ba7ff3b12..d8b6c4673318a889147e6c8d76fcdac5de701f98 100644 (file)
@@ -5,6 +5,7 @@
 #include <sys/time.h>
 #include <sys/types.h>
 #include <libusb.h>
+#include <errno.h>
 
 #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;
 }