stlink-common: Fix STM32L4 loader write count to reflect 64bits granularity
authorMaxime Coquelin <mcoquelin.stm32@gmail.com>
Mon, 14 Mar 2016 13:53:32 +0000 (14:53 +0100)
committerMaxime Coquelin <mcoquelin.stm32@gmail.com>
Mon, 14 Mar 2016 14:17:44 +0000 (15:17 +0100)
The stm32l4 loader expects a count of 32 bits words while its granularity is
really 64 bits.

This patch fixes this to simplify count calculation in run_flash_loader().

Signed-off-by: Maxime Coquelin <mcoquelin.stm32@gmail.com>
flashloaders/stm32l4.s
src/stlink-common.c

index 4b908633d9d409cd54ebc5664ac19c2ef44a60f2..6aa2be050061219492e0a1fe5b7d8c2cb87ecf54 100644 (file)
@@ -28,7 +28,7 @@ wait:
 
     add     r0, #8
     add     r1, #8
-    sub     r2, #2
+    sub     r2, #1
     b       next
 done:
     bkpt
index dce100daaec73e7189d08d2cdabed792cc54b9f2..76413b4fdca7009df03b7dd8b9ed5b6c18db38b5 100644 (file)
@@ -1598,7 +1598,7 @@ int write_loader_to_sram(stlink_t *sl, stm32_addr_t* addr, size_t* size) {
         0xfb, 0xd1,             //        bne.n <wait>
         0x00, 0xf1, 0x08, 0x00, //        add.w r0, r0, #8
         0x01, 0xf1, 0x08, 0x01, //        add.w r1, r1, #8
-        0xa2, 0xf1, 0x02, 0x02, //        add.w r2, r2, #2
+        0xa2, 0xf1, 0x01, 0x02, //        sub.w r2, r2, #1
         0xef, 0xe7,             //        b.n   <next>
         0x00, 0xbe,             // done:  bkpt  0x0000
         0x00, 0x20, 0x02, 0x40  // flash_base:  .word 0x40022000
@@ -2077,16 +2077,14 @@ int run_flash_loader(stlink_t *sl, flash_loader_t* fl, stm32_addr_t target, cons
         count = size / sizeof(uint16_t);
         if (size % sizeof(uint16_t))
             ++count;
-    } else if (sl->flash_type == FLASH_TYPE_F4 ||
-            sl->flash_type == FLASH_TYPE_L4 ||
-            sl->flash_type == FLASH_TYPE_L0) {
+    } else if (sl->flash_type == FLASH_TYPE_F4 || sl->flash_type == FLASH_TYPE_L0) {
         count = size / sizeof(uint32_t);
         if (size % sizeof(uint32_t))
             ++count;
-        if (sl->chip_id == STM32_CHIPID_L4) {
-            if (count % 2)
-                ++count;
-        }
+    } else if (sl->flash_type == FLASH_TYPE_L4) {
+        count = size / sizeof(uint64_t);
+        if (size % sizeof(uint64_t))
+            ++count;
     } else {
         fprintf(stderr, "unknown coreid 0x%x, don't know what flash loader to use\n", sl->core_id);
         return -1;
@@ -2116,7 +2114,7 @@ int run_flash_loader(stlink_t *sl, flash_loader_t* fl, stm32_addr_t target, cons
     }
 
     /* check written byte count */
-    stlink_read_all_regs(sl, &rr);
+    stlink_read_reg(sl, 2, &rr);
     if (rr.r[2] != 0) {
         fprintf(stderr, "write error, count == %u\n", rr.r[2]);
         return -1;