stlink-common: Update STM32L0/1 loaders to return remaining count in r2
authorMaxime Coquelin <mcoquelin.stm32@gmail.com>
Mon, 14 Mar 2016 13:22:54 +0000 (14:22 +0100)
committerMaxime Coquelin <mcoquelin.stm32@gmail.com>
Mon, 14 Mar 2016 14:17:36 +0000 (15:17 +0100)
All the loaders returns remaining work count in r2, except stm32l0/1.
Make these loaders behaving as the others to simplify run_flash_loader() code.

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

index 6c863c64aef7a869251c872675d319b5b767210b..fcbd06e396944d5853de798b07b51fe51dbc5b34 100644 (file)
     r2 - count
 */
 
-    // Set 0 to r3
-    movs    r3, #0
     // Go to compare
-    b.n test_done
+    b test_done
 
 write_word:
     // Load one word from address in r0, increment by 4
     ldr    r4, [r0]
     // Store the word to address in r1, increment by 4
     str    r4, [r1]
-    // Increment r3
-    adds    r3, #1
+    // Decrement r2
+    subs    r2, #1
        adds    r1, #4
        // does not matter, only first addr is important
        // next 15 bytes are in sequnce RM0367 page 66
        adds    r0, #4
 
 test_done:
-    // Compare r3 and r2
-    cmp     r3, r2
+    // Test r2
+    cmp     r2, #0
     // Loop if not zero
     bcc.n    write_word
 
index 764594d9ceb9eef761ad6a9afcebefe0b6893821..bb8f7c93f6ad77b703b3aa25a59f4eb5f131e5ee 100644 (file)
     r2 - count
 */
 
-    // Set 0 to r3
-    movs    r3, #0
     // Go to compare
-    b.n test_done
+    b test_done
 
 write_word:
     // Load one word from address in r0, increment by 4
     ldr.w    ip, [r0], #4
     // Store the word to address in r1, increment by 4
     str.w    ip, [r1], #4
-    // Increment r3
-    adds    r3, #1
+    // Decrement r2
+    subs    r2, #1
 
 test_done:
-    // Compare r3 and r2
-    cmp     r3, r2
+    // Test r2
+    cmp     r2, #0
     // Loop if not zero
     bcc.n    write_word
 
index 01ce06c6fa782a8ebbdd3297c6c23c0270384473..dce100daaec73e7189d08d2cdabed792cc54b9f2 100644 (file)
@@ -1504,17 +1504,16 @@ int write_loader_to_sram(stlink_t *sl, stm32_addr_t* addr, size_t* size) {
            r0, input, source addr
            r1, input, dest addr
            r2, input, word count
-           r3, output, word count
+           r2, output, remaining word count
            */
 
-        0x00, 0x23,
         0x04, 0xe0,
 
         0x50, 0xf8, 0x04, 0xcb,
         0x41, 0xf8, 0x04, 0xcb,
-        0x01, 0x33,
+        0x01, 0x3a,
 
-        0x93, 0x42,
+        0x00, 0x2a,
         0xf8, 0xd3,
         0x00, 0xbe
     };
@@ -1525,19 +1524,18 @@ int write_loader_to_sram(stlink_t *sl, stm32_addr_t* addr, size_t* size) {
            r0, input, source addr
            r1, input, dest addr
            r2, input, word count
-           r3, output, word count
+           r2, output, remaining word count
          */
 
-        0x00, 0x23,
         0x04, 0xe0,
 
         0x04, 0x68,
         0x0c, 0x60,
-        0x01, 0x33,
+        0x01, 0x3a,
         0x04, 0x31,
         0x04, 0x30,
 
-        0x93, 0x42,
+        0x00, 0x2a,
         0xf8, 0xd3,
         0x00, 0xbe
     };
@@ -2117,19 +2115,11 @@ int run_flash_loader(stlink_t *sl, flash_loader_t* fl, stm32_addr_t target, cons
         return -1;
     }
 
-    stlink_read_all_regs(sl, &rr);
-
     /* check written byte count */
-    if (sl->flash_type == FLASH_TYPE_L0) {
-        if (rr.r[3] != count) {
-            fprintf(stderr, "write error, count == %u\n", rr.r[3]);
-            return -1;
-        }
-    } else {
-        if (rr.r[2] != 0) {
-            fprintf(stderr, "write error, count == %u\n", rr.r[2]);
-            return -1;
-        }
+    stlink_read_all_regs(sl, &rr);
+    if (rr.r[2] != 0) {
+        fprintf(stderr, "write error, count == %u\n", rr.r[2]);
+        return -1;
     }
 
     return 0;