diff --git a/flashloaders/stm32l0x.s b/flashloaders/stm32l0x.s index 6c863c64a..fcbd06e39 100644 --- a/flashloaders/stm32l0x.s +++ b/flashloaders/stm32l0x.s @@ -39,26 +39,24 @@ 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 diff --git a/flashloaders/stm32lx.s b/flashloaders/stm32lx.s index 764594d9c..bb8f7c93f 100644 --- a/flashloaders/stm32lx.s +++ b/flashloaders/stm32lx.s @@ -39,22 +39,20 @@ 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 diff --git a/src/stlink-common.c b/src/stlink-common.c index 01ce06c6f..dce100daa 100644 --- a/src/stlink-common.c +++ b/src/stlink-common.c @@ -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;