Skip to content

Commit

Permalink
Moved set the PG flag from loader to code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ant-ON committed Apr 25, 2021
1 parent 80c31a1 commit 2b3a316
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 42 deletions.
14 changes: 0 additions & 14 deletions flashloaders/stm32f0.s
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,9 @@ copy:
# add r3 to flash_base for support dual bank (see flash_loader.c)
ldr r7, flash_base
add r7, r7, r3
ldr r6, flash_off_cr
add r6, r6, r7
ldr r5, flash_off_sr
add r5, r5, r7

# FLASH_CR = 0x01 (set PG)
ldr r4, =0x1
str r4, [r6]

loop:
# copy 2 bytes
ldrh r4, [r0]
Expand Down Expand Up @@ -68,18 +62,10 @@ wait:
bgt loop

exit:
# FLASH_CR &= ~1
ldr r7, =0x1
ldr r4, [r6]
bics r4, r4, r7
str r4, [r6]

bkpt

.align 2
flash_base:
.word 0x40022000
flash_off_cr:
.word 0x10
flash_off_sr:
.word 0x0c
18 changes: 15 additions & 3 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -3257,6 +3257,15 @@ int stlink_flashloader_start(stlink_t *sl, flash_loader_t *fl) {
ELOG("stlink_flash_loader_init() == -1\n");
return (-1);
}

// unlock flash
unlock_flash_if(sl);

// set programming mode
set_flash_cr_pg(sl, BANK_1);
if (sl->flash_type == STLINK_FLASH_TYPE_F1_XL) {
set_flash_cr_pg(sl, BANK_2);
}
} else if (sl->flash_type == STLINK_FLASH_TYPE_H7) {
ILOG("Starting Flash write for H7\n");

Expand Down Expand Up @@ -3437,7 +3446,9 @@ int stlink_flashloader_write(stlink_t *sl, flash_loader_t *fl,
int stlink_flashloader_stop(stlink_t *sl, flash_loader_t *fl) {
uint32_t dhcsr;

if ((sl->flash_type == STLINK_FLASH_TYPE_F4) ||
if ((sl->flash_type == STLINK_FLASH_TYPE_F0) ||
(sl->flash_type == STLINK_FLASH_TYPE_F1_XL) ||
(sl->flash_type == STLINK_FLASH_TYPE_F4) ||
(sl->flash_type == STLINK_FLASH_TYPE_F7) ||
(sl->flash_type == STLINK_FLASH_TYPE_L4) ||
(sl->flash_type == STLINK_FLASH_TYPE_WB) ||
Expand All @@ -3446,8 +3457,9 @@ int stlink_flashloader_stop(stlink_t *sl, flash_loader_t *fl) {
(sl->flash_type == STLINK_FLASH_TYPE_H7)) {

clear_flash_cr_pg(sl, BANK_1);
if (sl->flash_type == STLINK_FLASH_TYPE_H7 &&
sl->chip_flags & CHIP_F_HAS_DUAL_BANK) {
if ((sl->flash_type == STLINK_FLASH_TYPE_H7 &&
sl->chip_flags & CHIP_F_HAS_DUAL_BANK) ||
sl->flash_type == STLINK_FLASH_TYPE_F1_XL) {
clear_flash_cr_pg(sl, BANK_2);
}
lock_flash(sl);
Expand Down
39 changes: 14 additions & 25 deletions src/stlink-lib/flash_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,33 @@
/* flashloaders/stm32f0.s -- compiled with thumb2 */
static const uint8_t loader_code_stm32vl[] = {
0x00, 0xbf, 0x00, 0xbf,
0x0e, 0x4f, 0x1f, 0x44,
0x0e, 0x4e, 0x3e, 0x44,
0x0e, 0x4d, 0x3d, 0x44,
0x4f, 0xf0, 0x01, 0x04,
0x34, 0x60, 0x04, 0x88,
0x0c, 0x80, 0x02, 0x30,
0x02, 0x31, 0x4f, 0xf0,
0x01, 0x07, 0x2c, 0x68,
0x3c, 0x42, 0xfc, 0xd1,
0x4f, 0xf0, 0x14, 0x07,
0x3c, 0x42, 0x01, 0xd1,
0x02, 0x3a, 0xf0, 0xdc,
0x09, 0x4f, 0x1f, 0x44,
0x09, 0x4d, 0x3d, 0x44,
0x04, 0x88, 0x0c, 0x80,
0x02, 0x30, 0x02, 0x31,
0x4f, 0xf0, 0x01, 0x07,
0x34, 0x68, 0xbc, 0x43,
0x34, 0x60, 0x00, 0xbe,
0x2c, 0x68, 0x3c, 0x42,
0xfc, 0xd1, 0x4f, 0xf0,
0x14, 0x07, 0x3c, 0x42,
0x01, 0xd1, 0x02, 0x3a,
0xf0, 0xdc, 0x00, 0xbe,
0x00, 0x20, 0x02, 0x40,
0x10, 0x00, 0x00, 0x00,
0x0c, 0x00, 0x00, 0x00
};

/* flashloaders/stm32f0.s -- thumb1 only, same sequence as for STM32VL, bank ignored */
static const uint8_t loader_code_stm32f0[] = {
0xc0, 0x46, 0xc0, 0x46,
0x0c, 0x4f, 0x1f, 0x44,
0x0c, 0x4e, 0x3e, 0x44,
0x0c, 0x4d, 0x3d, 0x44,
0x0c, 0x4c, 0x34, 0x60,
0x08, 0x4f, 0x1f, 0x44,
0x08, 0x4d, 0x3d, 0x44,
0x04, 0x88, 0x0c, 0x80,
0x02, 0x30, 0x02, 0x31,
0x09, 0x4f, 0x2c, 0x68,
0x06, 0x4f, 0x2c, 0x68,
0x3c, 0x42, 0xfc, 0xd1,
0x08, 0x4f, 0x3c, 0x42,
0x05, 0x4f, 0x3c, 0x42,
0x01, 0xd1, 0x02, 0x3a,
0xf2, 0xdc, 0x05, 0x4f,
0x34, 0x68, 0xbc, 0x43,
0x34, 0x60, 0x00, 0xbe,
0xf2, 0xdc, 0x00, 0xbe,
0x00, 0x20, 0x02, 0x40,
0x10, 0x00, 0x00, 0x00,
0x0c, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x14, 0x00, 0x00, 0x00
Expand Down

0 comments on commit 2b3a316

Please sign in to comment.