aboutsummaryrefslogtreecommitdiff
path: root/flashstub/stm32.s
blob: 8a9cb54704c7e25913d53088b884ddc991850d0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
.global _start

_start:
	ldr r0, _flashbase
	ldr r1, _addr
	mov r2, pc
	add r2, #(_data - . - 2)
	ldr r3, _size
	mov r5, #1
_next:
	cmp r3, #0
	beq _done
	@ Write PG command to FLASH_CR
	str r5, [r0, #0x10]
	@ Write data to flash (half-word)
	ldrh r4, [r2]
	strh r4, [r1]

_wait:	@ Wait for BSY bit to clear
	ldr r4, [r0, #0x0C]
	mov r6, #1
	tst r4, r6
	bne _wait

	sub r3, #2
	add r1, #2
	add r2, #2
	b _next
_done:
	bkpt

@.align 4
.org 0x28
_flashbase:
	.word 0x40022000
_addr:
	.word 0
_size:
	.word 12
_data:
	.word 0xAAAAAAAA
	.word 0xBBBBBBBB
	.word 0xCCCCCCCC