Skip to content

Commit

Permalink
stlink-common: Update STM32L0/1 loaders to return remaining count in r2
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mcoquelin-stm32 committed Mar 14, 2016
1 parent 907383d commit e43a737
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 34 deletions.
12 changes: 5 additions & 7 deletions flashloaders/stm32l0x.s
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 5 additions & 7 deletions flashloaders/stm32lx.s
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 10 additions & 20 deletions src/stlink-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand All @@ -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
};
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e43a737

Please sign in to comment.