Add support for high density STM32L series (chip id 0x436)
authorKeith Packard <keithp@keithp.com>
Fri, 28 Dec 2012 23:23:29 +0000 (15:23 -0800)
committerKeith Packard <keithp@keithp.com>
Fri, 28 Dec 2012 23:23:29 +0000 (15:23 -0800)
Signed-off-by: Keith Packard <keithp@keithp.com>
src/stlink-common.c
src/stlink-common.h

index 26b36cd24121cf8c8b77ecff059a3893f75c52f7..a73801b169a036f428bee9792d4e94a6c4e24010 100644 (file)
@@ -841,13 +841,15 @@ on_error:
     return error;
 }
 
+#define IS_STM32L(sl)  ((sl)->chip_id == STM32_CHIPID_L1_MEDIUM || (sl)->chip_id == STM32_CHIPID_L1_HIGH)
+
 int stlink_fread(stlink_t* sl, const char* path, stm32_addr_t addr, size_t size) {
     /* read size bytes from addr to file */
 
     int error = -1;
     size_t off;
     int num_empty = 0;
-    unsigned char erased_pattern =(sl->chip_id == STM32_CHIPID_L1_MEDIUM)?0:0xff;
+    unsigned char erased_pattern =(IS_STM32L(sl))?0:0xff;
 
     const int fd = open(path, O_RDWR | O_TRUNC | O_CREAT, 00700);
     if (fd == -1) {
@@ -972,7 +974,7 @@ int stlink_erase_flash_page(stlink_t *sl, stm32_addr_t flashaddr)
        fprintf(stdout, "Erase Final CR:0x%x\n", read_flash_cr(sl));
 #endif
   }
-  else if (sl->chip_id == STM32_CHIPID_L1_MEDIUM)
+  else if (IS_STM32L(sl))
   {
 
     uint32_t val;
@@ -1084,7 +1086,7 @@ int stlink_erase_flash_page(stlink_t *sl, stm32_addr_t flashaddr)
 }
 
 int stlink_erase_flash_mass(stlink_t *sl) {
-     if (sl->chip_id == STM32_CHIPID_L1_MEDIUM) {
+     if (IS_STM32L(sl)) {
         /* erase each page */
         int i = 0, num_pages = sl->flash_size/sl->flash_pgsz;
         for (i = 0; i < num_pages; i++) {
@@ -1185,7 +1187,7 @@ int write_loader_to_sram(stlink_t *sl, stm32_addr_t* addr, size_t* size) {
     const uint8_t* loader_code;
     size_t loader_size;
 
-    if (sl->chip_id == STM32_CHIPID_L1_MEDIUM) /* stm32l */
+    if (IS_STM32L(sl)) /* stm32l */
     {
       loader_code = loader_code_stm32l;
       loader_size = sizeof(loader_code_stm32l);
@@ -1400,7 +1402,7 @@ int stlink_write_flash(stlink_t *sl, stm32_addr_t addr, uint8_t* base, unsigned
 
     }  //STM32F4END
 
-    else if (sl->chip_id == STM32_CHIPID_L1_MEDIUM)    {
+    else if (IS_STM32L(sl)) {
        /* use fast word write. todo: half page. */
        uint32_t val;
 
@@ -1557,7 +1559,7 @@ int stlink_fwrite_flash(stlink_t *sl, const char* path, stm32_addr_t addr) {
     /* write the file in flash at addr */
     int err;
     unsigned int num_empty = 0, index;
-    unsigned char erased_pattern =(sl->chip_id == STM32_CHIPID_L1_MEDIUM)?0:0xff;
+    unsigned char erased_pattern = (IS_STM32L(sl))?0:0xff;
     mapped_file_t mf = MAPPED_FILE_INITIALIZER;
     if (map_file(&mf, path) == -1) {
         WLOG("map_file() == -1\n");
@@ -1595,7 +1597,7 @@ int run_flash_loader(stlink_t *sl, flash_loader_t* fl, stm32_addr_t target, cons
         return -1;
     }
 
-    if (sl->chip_id == STM32_CHIPID_L1_MEDIUM) {
+    if (IS_STM32L(sl)) {
 
       size_t count = size / sizeof(uint32_t);
       if (size % sizeof(uint32_t)) ++count;
@@ -1638,7 +1640,7 @@ int run_flash_loader(stlink_t *sl, flash_loader_t* fl, stm32_addr_t target, cons
     }
         
     /* check written byte count */
-    if (sl->chip_id == STM32_CHIPID_L1_MEDIUM) {
+    if (IS_STM32L(sl)) {
 
       size_t count = size / sizeof(uint32_t);
       if (size % sizeof(uint32_t)) ++count;
index 6fcb2194e10cc35fc9b63fcf1718983376ed4260..2d699359e7bc8b2eb23beb74f68575290db6b976 100644 (file)
@@ -100,6 +100,7 @@ extern "C" {
 #define STM32_CHIPID_F4 0x413
 #define STM32_CHIPID_F1_HIGH 0x414
 #define STM32_CHIPID_L1_MEDIUM 0x416
+#define STM32_CHIPID_L1_HIGH 0x436
 #define STM32_CHIPID_F1_CONN 0x418
 #define STM32_CHIPID_F1_VL_MEDIUM 0x420
 #define STM32_CHIPID_F1_VL_HIGH 0x428
@@ -221,7 +222,18 @@ extern "C" {
                     .sram_size = 0x18000,
                     .bootrom_base = 0x1fffe000,
                     .bootrom_size = 0x1800
-        }
+        },
+        {
+          // This ignores the EEPROM! (and uses the page erase size,
+          // not the sector write protection...)
+            .chip_id = 0x436,
+                    .description = "L1 High-density device",
+                    .flash_size_reg = 0x1ff8004c,
+                    .flash_pagesize = 0x100,
+                    .sram_size = 0xc000,
+                    .bootrom_base = 0x1ff00000,
+                    .bootrom_size = 0x1000
+        },
  };