Align loader to 32-bit boundary
[fw/stlink] / flashloaders / stm32l4.s
1 .global start
2 .syntax unified
3
4 @ Adapted from stm32f4.s
5 @ STM32L4's flash controller expects double-word writes, has the flash
6 @ controller mapped in a different location with the registers we care about
7 @ moved down from the base address, and has BSY moved to bit 16 of SR.
8 @ r0 = source
9 @ r1 = target
10 @ r2 = wordcount
11 @ r3 = flash_base
12 @ r4 = temp
13 @ r5 = temp
14
15 start:
16     ldr     r3, flash_base
17 next:
18     cbz     r2, done
19     ldr     r4, [r0]            /* copy doubleword from source to target */
20     ldr     r5, [r0, #4]
21     str     r4, [r1]
22     str     r5, [r1, #4]
23
24 wait:
25     ldrh    r4, [r3, #0x12]     /* high half of status register */
26     tst     r4, #1              /* BSY = bit 16 */
27     bne     wait
28
29     add     r0, #8
30     add     r1, #8
31     sub     r2, #1
32     b       next
33 done:
34     bkpt
35
36 .align 2
37
38 flash_base:
39     .word 0x40022000