Skip to content

Commit 2b3a316

Browse files
committed
Moved set the PG flag from loader to code
1 parent 80c31a1 commit 2b3a316

File tree

3 files changed

+29
-42
lines changed

3 files changed

+29
-42
lines changed

flashloaders/stm32f0.s

-14
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,9 @@ copy:
3030
# add r3 to flash_base for support dual bank (see flash_loader.c)
3131
ldr r7, flash_base
3232
add r7, r7, r3
33-
ldr r6, flash_off_cr
34-
add r6, r6, r7
3533
ldr r5, flash_off_sr
3634
add r5, r5, r7
3735

38-
# FLASH_CR = 0x01 (set PG)
39-
ldr r4, =0x1
40-
str r4, [r6]
41-
4236
loop:
4337
# copy 2 bytes
4438
ldrh r4, [r0]
@@ -68,18 +62,10 @@ wait:
6862
bgt loop
6963

7064
exit:
71-
# FLASH_CR &= ~1
72-
ldr r7, =0x1
73-
ldr r4, [r6]
74-
bics r4, r4, r7
75-
str r4, [r6]
76-
7765
bkpt
7866

7967
.align 2
8068
flash_base:
8169
.word 0x40022000
82-
flash_off_cr:
83-
.word 0x10
8470
flash_off_sr:
8571
.word 0x0c

src/common.c

+15-3
Original file line numberDiff line numberDiff line change
@@ -3257,6 +3257,15 @@ int stlink_flashloader_start(stlink_t *sl, flash_loader_t *fl) {
32573257
ELOG("stlink_flash_loader_init() == -1\n");
32583258
return (-1);
32593259
}
3260+
3261+
// unlock flash
3262+
unlock_flash_if(sl);
3263+
3264+
// set programming mode
3265+
set_flash_cr_pg(sl, BANK_1);
3266+
if (sl->flash_type == STLINK_FLASH_TYPE_F1_XL) {
3267+
set_flash_cr_pg(sl, BANK_2);
3268+
}
32603269
} else if (sl->flash_type == STLINK_FLASH_TYPE_H7) {
32613270
ILOG("Starting Flash write for H7\n");
32623271

@@ -3437,7 +3446,9 @@ int stlink_flashloader_write(stlink_t *sl, flash_loader_t *fl,
34373446
int stlink_flashloader_stop(stlink_t *sl, flash_loader_t *fl) {
34383447
uint32_t dhcsr;
34393448

3440-
if ((sl->flash_type == STLINK_FLASH_TYPE_F4) ||
3449+
if ((sl->flash_type == STLINK_FLASH_TYPE_F0) ||
3450+
(sl->flash_type == STLINK_FLASH_TYPE_F1_XL) ||
3451+
(sl->flash_type == STLINK_FLASH_TYPE_F4) ||
34413452
(sl->flash_type == STLINK_FLASH_TYPE_F7) ||
34423453
(sl->flash_type == STLINK_FLASH_TYPE_L4) ||
34433454
(sl->flash_type == STLINK_FLASH_TYPE_WB) ||
@@ -3446,8 +3457,9 @@ int stlink_flashloader_stop(stlink_t *sl, flash_loader_t *fl) {
34463457
(sl->flash_type == STLINK_FLASH_TYPE_H7)) {
34473458

34483459
clear_flash_cr_pg(sl, BANK_1);
3449-
if (sl->flash_type == STLINK_FLASH_TYPE_H7 &&
3450-
sl->chip_flags & CHIP_F_HAS_DUAL_BANK) {
3460+
if ((sl->flash_type == STLINK_FLASH_TYPE_H7 &&
3461+
sl->chip_flags & CHIP_F_HAS_DUAL_BANK) ||
3462+
sl->flash_type == STLINK_FLASH_TYPE_F1_XL) {
34513463
clear_flash_cr_pg(sl, BANK_2);
34523464
}
34533465
lock_flash(sl);

src/stlink-lib/flash_loader.c

+14-25
Original file line numberDiff line numberDiff line change
@@ -19,44 +19,33 @@
1919
/* flashloaders/stm32f0.s -- compiled with thumb2 */
2020
static const uint8_t loader_code_stm32vl[] = {
2121
0x00, 0xbf, 0x00, 0xbf,
22-
0x0e, 0x4f, 0x1f, 0x44,
23-
0x0e, 0x4e, 0x3e, 0x44,
24-
0x0e, 0x4d, 0x3d, 0x44,
25-
0x4f, 0xf0, 0x01, 0x04,
26-
0x34, 0x60, 0x04, 0x88,
27-
0x0c, 0x80, 0x02, 0x30,
28-
0x02, 0x31, 0x4f, 0xf0,
29-
0x01, 0x07, 0x2c, 0x68,
30-
0x3c, 0x42, 0xfc, 0xd1,
31-
0x4f, 0xf0, 0x14, 0x07,
32-
0x3c, 0x42, 0x01, 0xd1,
33-
0x02, 0x3a, 0xf0, 0xdc,
22+
0x09, 0x4f, 0x1f, 0x44,
23+
0x09, 0x4d, 0x3d, 0x44,
24+
0x04, 0x88, 0x0c, 0x80,
25+
0x02, 0x30, 0x02, 0x31,
3426
0x4f, 0xf0, 0x01, 0x07,
35-
0x34, 0x68, 0xbc, 0x43,
36-
0x34, 0x60, 0x00, 0xbe,
27+
0x2c, 0x68, 0x3c, 0x42,
28+
0xfc, 0xd1, 0x4f, 0xf0,
29+
0x14, 0x07, 0x3c, 0x42,
30+
0x01, 0xd1, 0x02, 0x3a,
31+
0xf0, 0xdc, 0x00, 0xbe,
3732
0x00, 0x20, 0x02, 0x40,
38-
0x10, 0x00, 0x00, 0x00,
3933
0x0c, 0x00, 0x00, 0x00
4034
};
4135

4236
/* flashloaders/stm32f0.s -- thumb1 only, same sequence as for STM32VL, bank ignored */
4337
static const uint8_t loader_code_stm32f0[] = {
4438
0xc0, 0x46, 0xc0, 0x46,
45-
0x0c, 0x4f, 0x1f, 0x44,
46-
0x0c, 0x4e, 0x3e, 0x44,
47-
0x0c, 0x4d, 0x3d, 0x44,
48-
0x0c, 0x4c, 0x34, 0x60,
39+
0x08, 0x4f, 0x1f, 0x44,
40+
0x08, 0x4d, 0x3d, 0x44,
4941
0x04, 0x88, 0x0c, 0x80,
5042
0x02, 0x30, 0x02, 0x31,
51-
0x09, 0x4f, 0x2c, 0x68,
43+
0x06, 0x4f, 0x2c, 0x68,
5244
0x3c, 0x42, 0xfc, 0xd1,
53-
0x08, 0x4f, 0x3c, 0x42,
45+
0x05, 0x4f, 0x3c, 0x42,
5446
0x01, 0xd1, 0x02, 0x3a,
55-
0xf2, 0xdc, 0x05, 0x4f,
56-
0x34, 0x68, 0xbc, 0x43,
57-
0x34, 0x60, 0x00, 0xbe,
47+
0xf2, 0xdc, 0x00, 0xbe,
5848
0x00, 0x20, 0x02, 0x40,
59-
0x10, 0x00, 0x00, 0x00,
6049
0x0c, 0x00, 0x00, 0x00,
6150
0x01, 0x00, 0x00, 0x00,
6251
0x14, 0x00, 0x00, 0x00

0 commit comments

Comments
 (0)