aboutsummaryrefslogtreecommitdiff
path: root/flashstub
diff options
context:
space:
mode:
authorGareth McMullin2015-03-08 13:35:07 -0700
committerGareth McMullin2015-03-19 07:48:57 -0700
commit437aedda11a112407af7b3f7884090023944faef (patch)
tree77f04bd2c8c06b12d3272cd33931cc227a46f913 /flashstub
parentc2462a6788c119edd9995fa46f1316a9c0431e0b (diff)
Rewrote stm32f1 stub in C and call with parameters in registers.
Diffstat (limited to 'flashstub')
-rw-r--r--flashstub/Makefile6
-rw-r--r--flashstub/stm32.s43
-rw-r--r--flashstub/stm32.stub1
-rw-r--r--flashstub/stm32f1.c34
-rw-r--r--flashstub/stm32f1.stub1
5 files changed, 40 insertions, 45 deletions
diff --git a/flashstub/Makefile b/flashstub/Makefile
index cb6f693..eeb1803 100644
--- a/flashstub/Makefile
+++ b/flashstub/Makefile
@@ -11,7 +11,11 @@ endif
CFLAGS=-mcpu=cortex-m3 -mthumb -I../libopencm3/include
ASFLAGS=-mcpu=cortex-m3 -mthumb
-all: lmi.stub stm32.stub stm32f4.stub nrf51.stub
+all: lmi.stub stm32f4.stub nrf51.stub stm32f1.stub
+
+stm32f1.o: stm32f1.c
+ $(Q)echo " CC $<"
+ $(Q)$(CC) $(CFLAGS) -DSTM32F1 -o $@ -c $<
%.o: %.s
$(Q)echo " AS $<"
diff --git a/flashstub/stm32.s b/flashstub/stm32.s
deleted file mode 100644
index 8a9cb54..0000000
--- a/flashstub/stm32.s
+++ /dev/null
@@ -1,43 +0,0 @@
-.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
diff --git a/flashstub/stm32.stub b/flashstub/stm32.stub
deleted file mode 100644
index 755f445..0000000
--- a/flashstub/stm32.stub
+++ /dev/null
@@ -1 +0,0 @@
-0x4809, 0x490A, 0x467A, 0x322C, 0x4B09, 0x2501, 0x2B00, 0xD00A, 0x6105, 0x8814, 0x800C, 0x68C4, 0x2601, 0x4234, 0xD1FB, 0x3B02, 0x3102, 0x3202, 0xE7F2, 0xBE00, 0x2000, 0x4002, 0x0000, 0x0000, 0x000C, 0x0000, 0xAAAA, 0xAAAA, 0xBBBB, 0xBBBB, 0xCCCC, 0xCCCC, \ No newline at end of file
diff --git a/flashstub/stm32f1.c b/flashstub/stm32f1.c
new file mode 100644
index 0000000..8370114
--- /dev/null
+++ b/flashstub/stm32f1.c
@@ -0,0 +1,34 @@
+/*
+ * This file is part of the Black Magic Debug project.
+ *
+ * Copyright (C) 2015 Black Sphere Technologies Ltd.
+ * Written by Gareth McMullin <gareth@blacksphere.co.nz>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "libopencm3/stm32/flash.h"
+
+void __attribute__((naked))
+stm32f1_flash_write_stub(uint16_t *dest, uint16_t *src, uint32_t size)
+{
+ while (size) {
+ FLASH_CR = FLASH_CR_PG;
+ *dest++ = *src++;
+ size -= 2;
+ while (FLASH_SR & FLASH_SR_BSY)
+ ;
+ }
+ asm("bkpt");
+}
+
diff --git a/flashstub/stm32f1.stub b/flashstub/stm32f1.stub
new file mode 100644
index 0000000..97d2a5e
--- /dev/null
+++ b/flashstub/stm32f1.stub
@@ -0,0 +1 @@
+0x4613, 0xE010, 0x4A09, 0x2401, 0x6014, 0x4602, 0x1C90, 0x460C, 0x1CA1, 0x8824, 0x8014, 0x3B02, 0xBF00, 0x4A05, 0x6812, 0xF002, 0x0201, 0x2A00, 0xD1F9, 0x2B00, 0xD1EC, 0xBE00, 0x2010, 0x4002, 0x200C, 0x4002, \ No newline at end of file