aboutsummaryrefslogtreecommitdiff
path: root/flashstub
diff options
context:
space:
mode:
authorGareth McMullin2011-02-12 22:09:38 +1300
committerGareth McMullin2011-02-12 22:09:38 +1300
commit7de78bbd6c05a1b9ba432ba5e1a73206a72ac238 (patch)
treee644b2948e25d892168130474ca658f799deb41a /flashstub
parentdf5c3d06d591c8408e31d7068c9e7c600f3c7e9e (diff)
Added Flash programming stubs.
Diffstat (limited to 'flashstub')
-rw-r--r--flashstub/README5
-rw-r--r--flashstub/lmi.s42
-rw-r--r--flashstub/stm32.s42
3 files changed, 89 insertions, 0 deletions
diff --git a/flashstub/README b/flashstub/README
new file mode 100644
index 0000000..05172a4
--- /dev/null
+++ b/flashstub/README
@@ -0,0 +1,5 @@
+These are the assembler routines for executing a flash write
+on the supported targets. They are kept here for reference, but
+are not used, as the compiled binary code is included in the
+target drivers.
+
diff --git a/flashstub/lmi.s b/flashstub/lmi.s
new file mode 100644
index 0000000..b3b206e
--- /dev/null
+++ b/flashstub/lmi.s
@@ -0,0 +1,42 @@
+
+_start:
+ ldr r0, _flashbase
+ ldr r1, _addr
+ mov r2, pc
+ add r2, #(_data - . - 2)
+ ldr r3, _size
+ ldr r5, _flash_write_cmd
+_next:
+ cbz r3, _done
+ @ Write address to FMA
+ str r1, [r0]
+ @ Write data to FMD
+ ldr r4, [r2]
+ str r4, [r0, #4]
+ @ Write WRITE bit to FMC
+ str r5, [r0, #8]
+_wait: @ Wait for WRITE bit to clear
+ ldr r4, [r0, #8]
+ mov r6, #1
+ tst r4, r6
+ bne _wait
+
+ sub r3, #1
+ add r1, #4
+ add r2, #4
+ b _next
+_done:
+ bkpt
+
+@.align 4
+.org 0x28
+_flashbase:
+ .word 0x400FD000
+_flash_write_cmd:
+ .word 0xA4420001
+_addr:
+ .word 0
+_size:
+ .word 4
+_data:
+ .string "Hello World!\n\0\0\0"
diff --git a/flashstub/stm32.s b/flashstub/stm32.s
new file mode 100644
index 0000000..b27d8b2
--- /dev/null
+++ b/flashstub/stm32.s
@@ -0,0 +1,42 @@
+.global _start
+
+_start:
+ ldr r0, _flashbase
+ ldr r1, _addr
+ mov r2, pc
+ add r2, #(_data - . - 2)
+ ldr r3, _size
+ mov r5, #1
+_next:
+ cbz r3, _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