aboutsummaryrefslogtreecommitdiff
path: root/flashstub
diff options
context:
space:
mode:
Diffstat (limited to 'flashstub')
-rw-r--r--flashstub/Makefile41
-rw-r--r--flashstub/README22
-rwxr-xr-xflashstub/dump-to-array.sh11
-rw-r--r--flashstub/lmi.stub1
-rw-r--r--flashstub/nrf51.s (renamed from flashstub/stm32f4.s)28
-rw-r--r--flashstub/nrf51.stub1
-rw-r--r--flashstub/stm32.s43
-rw-r--r--flashstub/stm32f1.c40
-rw-r--r--flashstub/stm32f1.stub1
-rw-r--r--flashstub/stm32f4.c40
-rw-r--r--flashstub/stm32f4.stub1
-rw-r--r--flashstub/stm32l05x-nvm-prog-erase.cc93
-rw-r--r--flashstub/stm32l05x-nvm-prog-erase.stub67
-rw-r--r--flashstub/stm32l05x-nvm-prog-write.cc113
-rw-r--r--flashstub/stm32l05x-nvm-prog-write.stub99
-rw-r--r--flashstub/stub.h30
16 files changed, 568 insertions, 63 deletions
diff --git a/flashstub/Makefile b/flashstub/Makefile
new file mode 100644
index 0000000..c955ca8
--- /dev/null
+++ b/flashstub/Makefile
@@ -0,0 +1,41 @@
+CROSS_COMPILE ?= arm-none-eabi-
+AS = $(CROSS_COMPILE)as
+CC = $(CROSS_COMPILE)gcc
+OBJCOPY = $(CROSS_COMPILE)objcopy
+HEXDUMP = hexdump
+
+ifneq ($(V), 1)
+Q = @
+endif
+
+CFLAGS=-Os -std=gnu99 -mcpu=cortex-m3 -mthumb -I../libopencm3/include
+ASFLAGS=-mcpu=cortex-m3 -mthumb
+
+all: lmi.stub stm32f4.stub nrf51.stub stm32f1.stub
+
+stm32f1.o: stm32f1.c
+ $(Q)echo " CC $<"
+ $(Q)$(CC) $(CFLAGS) -DSTM32F1 -o $@ -c $<
+
+stm32f4.o: stm32f4.c
+ $(Q)echo " CC $<"
+ $(Q)$(CC) $(CFLAGS) -DSTM32F4 -o $@ -c $<
+
+%.o: %.s
+ $(Q)echo " AS $<"
+ $(Q)$(AS) $(ASFLAGS) -o $@ $<
+
+%.bin: %.o
+ $(Q)echo " OBJCOPY $@"
+ $(Q)$(OBJCOPY) -O binary $< $@
+
+%.stub: %.bin
+ $(Q)echo " HEXDUMP $@"
+ $(Q)$(HEXDUMP) -v -e '/2 "0x%04X, "' $< > $@
+
+.PHONY: clean
+
+clean:
+ $(Q)echo " CLEAN"
+ -$(Q)rm -f *.o *.bin *.stub
+
diff --git a/flashstub/README b/flashstub/README
index 05172a4..90d164c 100644
--- a/flashstub/README
+++ b/flashstub/README
@@ -1,5 +1,19 @@
-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.
+Flash Stubs
+===========
+For most of the targets, these are 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.
+
+For the STM32l0x, the stubs are written in C++ and emitted as arrays
+of half-words for inclusion in the target driver. The use of a higher
+level language allows more detailed code and for easy revisions.
+These stubs communicate with the driver through a structure defined in
+the src/include/stm32l0-nvm.h header.
+
+The dump-to-array.sh helper script uses sed to transform the output of
+'objdump -d' into a half-word array of the instructions that may be
+included in C code to declare the stub. FWIW, objcopy doesn't produce
+the same output as objdump. It omits some of the instructions,
+probably because the object file isn't linked.
diff --git a/flashstub/dump-to-array.sh b/flashstub/dump-to-array.sh
new file mode 100755
index 0000000..78584d0
--- /dev/null
+++ b/flashstub/dump-to-array.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+#
+# Convert the output of objdump to an array of half-words that can be
+# included into C code to represent the stub.
+#
+# Invoke with something like this:
+#
+# objdump -z -d FILE.o | dump-to-array.sh > FILE.stub
+#
+
+sed -E "/^[ ][ ]*[0-9a-fA-F]+:/!d; s/([0-9a-fA-F]+):[ \t]+([0-9a-fA-F]+).*/[0x\1\/2] = 0x\2,/ ; s/0x(....)(....),/0x\2, 0x\1,/"
diff --git a/flashstub/lmi.stub b/flashstub/lmi.stub
new file mode 100644
index 0000000..afaf939
--- /dev/null
+++ b/flashstub/lmi.stub
@@ -0,0 +1 @@
+0x4809, 0x490B, 0x467A, 0x3230, 0x4B0A, 0x4D08, 0xB15B, 0x6001, 0x6814, 0x6044, 0x6085, 0x6884, 0x2601, 0x4234, 0xD1FB, 0x3B01, 0x3104, 0x3204, 0xE7F2, 0xBE00, 0xD000, 0x400F, 0x0001, 0xA442, 0x0000, 0x0000, 0x0004, 0x0000, 0x6548, 0x6C6C, 0x206F, 0x6F57, 0x6C72, 0x2164, 0x000A, 0x0000, 0x0000,
diff --git a/flashstub/stm32f4.s b/flashstub/nrf51.s
index fa3fda0..e23b613 100644
--- a/flashstub/stm32f4.s
+++ b/flashstub/nrf51.s
@@ -1,25 +1,23 @@
.global _start
_start:
- ldr r0, _flashbase
+ ldr r0, _ready
ldr r1, _addr
mov r2, pc
add r2, #(_data - . - 2)
ldr r3, _size
- ldr r5, _cr
_next:
- cbz r3, _done
- @ Write PG command to FLASH_CR
- str r5, [r0, #0x10]
- @ Write data to flash (word)
+ cmp r3, #0
+ beq _done
+ @ Write data to flash
ldr r4, [r2]
str r4, [r1]
-_wait: @ Wait for BSY bit to clear
- ldrh r4, [r0, #0x0E]
+_wait: @ Wait for READY bit
+ ldr r4, [r0]
mov r6, #1
tst r4, r6
- bne _wait
+ beq _wait
sub r3, #4
add r1, #4
@@ -29,15 +27,13 @@ _done:
bkpt
@.align 4
-.org 0x28
-_cr:
- .word 0x00000201
-_flashbase:
- .word 0x40023C00
+.org 0x24
+_ready:
+ .word 0x4001E400
_addr:
- .word 0x0800bf78
+ .word 0
_size:
- .word 8
+ .word 12
_data:
.word 0xAAAAAAAA
.word 0xBBBBBBBB
diff --git a/flashstub/nrf51.stub b/flashstub/nrf51.stub
new file mode 100644
index 0000000..6c12fa4
--- /dev/null
+++ b/flashstub/nrf51.stub
@@ -0,0 +1 @@
+0x4808, 0x4909, 0x467A, 0x3228, 0x4B08, 0x2B00, 0xD009, 0x6814, 0x600C, 0x6804, 0x2601, 0x4234, 0xD0FB, 0x3B04, 0x3104, 0x3204, 0xE7F3, 0xBE00, 0xE400, 0x4001, 0x0000, 0x0000, 0x000C, 0x0000, 0xAAAA, 0xAAAA, 0xBBBB, 0xBBBB, 0xCCCC, 0xCCCC,
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/stm32f1.c b/flashstub/stm32f1.c
new file mode 100644
index 0000000..f9ba0a1
--- /dev/null
+++ b/flashstub/stm32f1.c
@@ -0,0 +1,40 @@
+/*
+ * 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"
+#include "stub.h"
+
+#define SR_ERROR_MASK 0x14
+
+void __attribute__((naked))
+stm32f1_flash_write_stub(uint16_t *dest, uint16_t *src, uint32_t size)
+{
+ for (int i; i < size; i += 2) {
+ FLASH_CR = FLASH_CR_PG;
+ *dest++ = *src++;
+ while (FLASH_SR & FLASH_SR_BSY)
+ ;
+ }
+
+ if (FLASH_SR & SR_ERROR_MASK)
+ stub_exit(1);
+
+ stub_exit(0);
+}
+
diff --git a/flashstub/stm32f1.stub b/flashstub/stm32f1.stub
new file mode 100644
index 0000000..7f2914c
--- /dev/null
+++ b/flashstub/stm32f1.stub
@@ -0,0 +1 @@
+0x2300, 0x4293, 0x4C09, 0xD20A, 0x4D09, 0x2601, 0x602E, 0x5ACD, 0x52C5, 0x6825, 0xF015, 0x0F01, 0xD1FB, 0x3302, 0xE7F1, 0x6823, 0xF013, 0x0F14, 0xD000, 0xBE01, 0xBE00, 0xBF00, 0x200C, 0x4002, 0x2010, 0x4002, \ No newline at end of file
diff --git a/flashstub/stm32f4.c b/flashstub/stm32f4.c
new file mode 100644
index 0000000..6732897
--- /dev/null
+++ b/flashstub/stm32f4.c
@@ -0,0 +1,40 @@
+/*
+ * 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"
+#include "stub.h"
+
+#define SR_ERROR_MASK 0xF2
+
+void __attribute__((naked))
+stm32f4_flash_write_stub(uint32_t *dest, uint32_t *src, uint32_t size)
+{
+ for (int i = 0; i < size; i += 4) {
+ FLASH_CR = FLASH_CR_PROGRAM_X32 | FLASH_CR_PG;
+ *dest++ = *src++;
+ while (FLASH_SR & FLASH_SR_BSY)
+ ;
+ }
+
+ if (FLASH_SR & SR_ERROR_MASK)
+ stub_exit(1);
+
+ stub_exit(0);
+}
+
diff --git a/flashstub/stm32f4.stub b/flashstub/stm32f4.stub
new file mode 100644
index 0000000..25b5d9a
--- /dev/null
+++ b/flashstub/stm32f4.stub
@@ -0,0 +1 @@
+0x2300, 0x4293, 0x4C09, 0xD20B, 0x4D09, 0xF240, 0x2601, 0x602E, 0x58CD, 0x50C5, 0x6825, 0xF415, 0x3F80, 0xD1FB, 0x3304, 0xE7F0, 0x6823, 0xF013, 0x0FF2, 0xD000, 0xBE01, 0xBE00, 0x3C0C, 0x4002, 0x3C10, 0x4002, \ No newline at end of file
diff --git a/flashstub/stm32l05x-nvm-prog-erase.cc b/flashstub/stm32l05x-nvm-prog-erase.cc
new file mode 100644
index 0000000..58030e3
--- /dev/null
+++ b/flashstub/stm32l05x-nvm-prog-erase.cc
@@ -0,0 +1,93 @@
+/* @file stm32l05x-nvm-prog-erase.cc
+ *
+ * This file is part of the Black Magic Debug project.
+ *
+ * Copyright (C) 2014 Woollysoft
+ * Written by Marc Singer <elf@woollysoft.com>
+ *
+ * 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/>.
+ */
+
+/* -----------
+ DESCRIPTION
+ -----------
+
+ NVM program flash erase stub for STM32L05x, a Cortex-M0+ core. The
+ stub uses SRAM to host the code fragment to perform the erase.
+
+ This stub works with the STM32L1xx given a few options.
+
+ If you plan to modify this routine and emit a new stub, make sure
+ to audit the code. We don't have a stack so we cannot make calls
+ that save the link pointer. IOW, the inline functions should be be
+ inlined.
+
+*/
+
+#include <stdint.h>
+#include <string.h>
+#include "../src/include/stm32lx-nvm.h"
+
+/* Erase a region of flash. In the event that the erase is misaligned
+ with respect to pages, it will erase the pages that contain the
+ requested range of bytes. */
+extern "C" void __attribute((naked)) stm32l05x_nvm_prog_erase() {
+ // Leave room for INFO at second word of routine
+ __asm volatile ("b 0f\n\t"
+ ".align 2\n\t"
+ ".word 0\n\t"
+ ".word 0\n\t"
+ ".word 0\n\t"
+ ".word 0\n\t"
+ ".word 0\n\t"
+ "0:");
+
+ auto& nvm = Nvm (Info.nvm);
+
+ // Align to the start of the first page so that we make sure to erase
+ // all of the target pages.
+ auto remainder = reinterpret_cast<uint32_t> (Info.destination)
+ & (Info.page_size - 1);
+ Info.size += remainder;
+ Info.destination -= remainder/sizeof (*Info.destination);
+
+ if (!unlock(nvm))
+ goto quit;
+
+ nvm.sr = STM32Lx_NVM_SR_ERR_M; // Clear errors
+
+ // Enable erasing
+ nvm.pecr = STM32Lx_NVM_PECR_PROG | STM32Lx_NVM_PECR_ERASE;
+ if ((nvm.pecr & (STM32Lx_NVM_PECR_PROG | STM32Lx_NVM_PECR_ERASE))
+ != (STM32Lx_NVM_PECR_PROG | STM32Lx_NVM_PECR_ERASE))
+ goto quit;
+
+ while (Info.size > 0) {
+ *Info.destination = 0; // Initiate erase
+
+ Info.destination += Info.page_size/sizeof (*Info.destination);
+ Info.size -= Info.page_size;
+ }
+
+quit:
+ lock(nvm);
+ __asm volatile ("bkpt");
+}
+
+/*
+ Local Variables:
+ compile-command: "/opt/arm/arm-none-eabi-g++ -mcpu=cortex-m0plus -g -c -std=c++11 -mthumb -o stm32l05x-nvm-prog-erase.o -Os -Wa,-ahndl=stm32l05x-nvm-prog-erase.lst stm32l05x-nvm-prog-erase.cc ; /opt/arm/arm-none-eabi-objdump -d -z stm32l05x-nvm-prog-erase.o | ./dump-to-array.sh > stm32l05x-nvm-prog-erase.stub"
+ End:
+
+*/
diff --git a/flashstub/stm32l05x-nvm-prog-erase.stub b/flashstub/stm32l05x-nvm-prog-erase.stub
new file mode 100644
index 0000000..e0fea34
--- /dev/null
+++ b/flashstub/stm32l05x-nvm-prog-erase.stub
@@ -0,0 +1,67 @@
+ [0x0/2] = 0xe00a,
+ [0x2/2] = 0x46c0,
+ [0x4/2] = 0x0000, 0x0000,
+ [0x8/2] = 0x0000, 0x0000,
+ [0xc/2] = 0x0000, 0x0000,
+ [0x10/2] = 0x0000, 0x0000,
+ [0x14/2] = 0x0000, 0x0000,
+ [0x18/2] = 0x491a,
+ [0x1a/2] = 0x8a08,
+ [0x1c/2] = 0x680c,
+ [0x1e/2] = 0x684d,
+ [0x20/2] = 0x1e42,
+ [0x22/2] = 0x4022,
+ [0x24/2] = 0x1955,
+ [0x26/2] = 0x0892,
+ [0x28/2] = 0x0092,
+ [0x2a/2] = 0x1aa2,
+ [0x2c/2] = 0x600a,
+ [0x2e/2] = 0x2201,
+ [0x30/2] = 0x68cb,
+ [0x32/2] = 0x604d,
+ [0x34/2] = 0x605a,
+ [0x36/2] = 0x4a14,
+ [0x38/2] = 0x60da,
+ [0x3a/2] = 0x4a14,
+ [0x3c/2] = 0x60da,
+ [0x3e/2] = 0x4a14,
+ [0x40/2] = 0x611a,
+ [0x42/2] = 0x4a14,
+ [0x44/2] = 0x611a,
+ [0x46/2] = 0x685a,
+ [0x48/2] = 0x0792,
+ [0x4a/2] = 0xd502,
+ [0x4c/2] = 0x2201,
+ [0x4e/2] = 0x605a,
+ [0x50/2] = 0xbe00,
+ [0x52/2] = 0x4a11,
+ [0x54/2] = 0x619a,
+ [0x56/2] = 0x2282,
+ [0x58/2] = 0x0092,
+ [0x5a/2] = 0x605a,
+ [0x5c/2] = 0x685c,
+ [0x5e/2] = 0x4014,
+ [0x60/2] = 0x4294,
+ [0x62/2] = 0xd1f3,
+ [0x64/2] = 0x0884,
+ [0x66/2] = 0x00a4,
+ [0x68/2] = 0x684d,
+ [0x6a/2] = 0x4a06,
+ [0x6c/2] = 0x2d00,
+ [0x6e/2] = 0xdded,
+ [0x70/2] = 0x2600,
+ [0x72/2] = 0x6815,
+ [0x74/2] = 0x602e,
+ [0x76/2] = 0x6815,
+ [0x78/2] = 0x192d,
+ [0x7a/2] = 0x6015,
+ [0x7c/2] = 0x6855,
+ [0x7e/2] = 0x1a2d,
+ [0x80/2] = 0x6055,
+ [0x82/2] = 0xe7f1,
+ [0x84/2] = 0x0004, 0x2000,
+ [0x88/2] = 0xcdef, 0x89ab,
+ [0x8c/2] = 0x0405, 0x0203,
+ [0x90/2] = 0xaebf, 0x8c9d,
+ [0x94/2] = 0x1516, 0x1314,
+ [0x98/2] = 0x0700, 0x0001,
diff --git a/flashstub/stm32l05x-nvm-prog-write.cc b/flashstub/stm32l05x-nvm-prog-write.cc
new file mode 100644
index 0000000..e90401e
--- /dev/null
+++ b/flashstub/stm32l05x-nvm-prog-write.cc
@@ -0,0 +1,113 @@
+/* @file stm32l05x-nvm-prog-write.cc
+ *
+ * This file is part of the Black Magic Debug project.
+ *
+ * Copyright (C) 2014 Woollysoft
+ * Written by Marc Singer <elf@woollysoft.com>
+ *
+ * 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/>.
+ */
+
+/* -----------
+ DESCRIPTION
+ -----------
+
+ NVM program flash writing stub for STM32L05x, a Cortex-M0+ core.
+ The stub uses SRAM to host the code fragment and source data to
+ perform a write to flash.
+
+ This stub works with the STM32L1xx given a few options.
+
+ If you plan to modify this routine and emit a new stub, make sure
+ to audit the code. We don't have a stack so we cannot make calls
+ that save the link pointer. IOW, the inline functions should be be
+ inlined.
+
+*/
+
+#include <stdint.h>
+#include <string.h>
+#include "../src/include/stm32lx-nvm.h"
+
+/* Write a block of bytes to flash. The called is responsible for
+ making sure that the address are aligned and that the count is an
+ even multiple of words. */
+extern "C" void __attribute((naked)) stm32l05x_nvm_prog_write() {
+ // Leave room for INFO at second word of routine
+ __asm volatile ("b 0f\n\t"
+ ".align 2\n\t"
+ ".word 0\n\t"
+ ".word 0\n\t"
+ ".word 0\n\t"
+ ".word 0\n\t"
+ ".word 0\n\t"
+ "0:");
+
+ auto& nvm = Nvm (Info.nvm);
+
+ if (!unlock(nvm))
+ goto quit;
+
+ nvm.sr = STM32Lx_NVM_SR_ERR_M; // Clear errors
+
+ while (Info.size > 0) {
+
+ // Either we're not half-page aligned or we have less
+ // than a half page to write
+ if (Info.size < Info.page_size/2
+ || (reinterpret_cast<uint32_t> (Info.destination)
+ & (Info.page_size/2 - 1))) {
+ nvm.pecr = (Info.options & OPT_STM32L1) ? 0
+ : STM32Lx_NVM_PECR_PROG; // Word programming
+ size_t c = Info.page_size/2
+ - (reinterpret_cast<uint32_t> (Info.destination)
+ & (Info.page_size/2 - 1));
+ if (c > Info.size)
+ c = Info.size;
+ Info.size -= c;
+ c /= 4;
+ while (c--) {
+ uint32_t v = *Info.source++;
+ *Info.destination++ = v;
+ if (nvm.sr & STM32Lx_NVM_SR_ERR_M)
+ goto quit;
+ }
+ }
+ // Or we are writing a half-page(s)
+ else {
+ nvm.pecr = STM32Lx_NVM_PECR_PROG
+ | STM32Lx_NVM_PECR_FPRG; // Half-page prg
+ size_t c = Info.size & ~(Info.page_size/2 - 1);
+ Info.size -= c;
+ c /= 4;
+ while (c--) {
+ uint32_t v = *Info.source++;
+ *Info.destination++ = v;
+ }
+ if (nvm.sr & STM32Lx_NVM_SR_ERR_M)
+ goto quit;
+ }
+ }
+
+quit:
+ lock(nvm);
+ __asm volatile ("bkpt");
+}
+
+/*
+ Local Variables:
+ compile-command: "/opt/arm/arm-none-eabi-g++ -mcpu=cortex-m0plus -g -c -std=c++11 -mthumb -o stm32l05x-nvm-prog-write.o -Os -Wa,-ahndl=stm32l05x-nvm-prog-write.lst stm32l05x-nvm-prog-write.cc ; /opt/arm/arm-none-eabi-objdump -d -z stm32l05x-nvm-prog-write.o | ./dump-to-array.sh > stm32l05x-nvm-prog-write.stub"
+ End:
+
+*/
diff --git a/flashstub/stm32l05x-nvm-prog-write.stub b/flashstub/stm32l05x-nvm-prog-write.stub
new file mode 100644
index 0000000..7ddbc81
--- /dev/null
+++ b/flashstub/stm32l05x-nvm-prog-write.stub
@@ -0,0 +1,99 @@
+ [0x0/2] = 0xe00a,
+ [0x2/2] = 0x46c0,
+ [0x4/2] = 0x0000, 0x0000,
+ [0x8/2] = 0x0000, 0x0000,
+ [0xc/2] = 0x0000, 0x0000,
+ [0x10/2] = 0x0000, 0x0000,
+ [0x14/2] = 0x0000, 0x0000,
+ [0x18/2] = 0x2201,
+ [0x1a/2] = 0x4b2a,
+ [0x1c/2] = 0x68d9,
+ [0x1e/2] = 0x604a,
+ [0x20/2] = 0x4a29,
+ [0x22/2] = 0x60ca,
+ [0x24/2] = 0x4a29,
+ [0x26/2] = 0x60ca,
+ [0x28/2] = 0x4a29,
+ [0x2a/2] = 0x610a,
+ [0x2c/2] = 0x4a29,
+ [0x2e/2] = 0x610a,
+ [0x30/2] = 0x684a,
+ [0x32/2] = 0x0792,
+ [0x34/2] = 0xd502,
+ [0x36/2] = 0x2301,
+ [0x38/2] = 0x604b,
+ [0x3a/2] = 0xbe00,
+ [0x3c/2] = 0x4826,
+ [0x3e/2] = 0x6188,
+ [0x40/2] = 0x685d,
+ [0x42/2] = 0x4e20,
+ [0x44/2] = 0x2d00,
+ [0x46/2] = 0xddf6,
+ [0x48/2] = 0x8a32,
+ [0x4a/2] = 0x0852,
+ [0x4c/2] = 0x1e54,
+ [0x4e/2] = 0x4295,
+ [0x50/2] = 0xdb02,
+ [0x52/2] = 0x6837,
+ [0x54/2] = 0x4227,
+ [0x56/2] = 0xd01d,
+ [0x58/2] = 0x2602,
+ [0x5a/2] = 0x8a5f,
+ [0x5c/2] = 0x4037,
+ [0x5e/2] = 0x427e,
+ [0x60/2] = 0x417e,
+ [0x62/2] = 0x00f6,
+ [0x64/2] = 0x604e,
+ [0x66/2] = 0x681e,
+ [0x68/2] = 0x4034,
+ [0x6a/2] = 0x1b12,
+ [0x6c/2] = 0x42aa,
+ [0x6e/2] = 0xd900,
+ [0x70/2] = 0x1c2a,
+ [0x72/2] = 0x1aad,
+ [0x74/2] = 0x605d,
+ [0x76/2] = 0x0892,
+ [0x78/2] = 0x3a01,
+ [0x7a/2] = 0xd3e1,
+ [0x7c/2] = 0x689c,
+ [0x7e/2] = 0x1d25,
+ [0x80/2] = 0x609d,
+ [0x82/2] = 0x6825,
+ [0x84/2] = 0x681c,
+ [0x86/2] = 0x1d26,
+ [0x88/2] = 0x601e,
+ [0x8a/2] = 0x6025,
+ [0x8c/2] = 0x698c,
+ [0x8e/2] = 0x4204,
+ [0x90/2] = 0xd0f2,
+ [0x92/2] = 0xe7d0,
+ [0x94/2] = 0x2481,
+ [0x96/2] = 0x4252,
+ [0x98/2] = 0x402a,
+ [0x9a/2] = 0x1aad,
+ [0x9c/2] = 0x00e4,
+ [0x9e/2] = 0x604c,
+ [0xa0/2] = 0x0892,
+ [0xa2/2] = 0x6075,
+ [0xa4/2] = 0x3a01,
+ [0xa6/2] = 0xd308,
+ [0xa8/2] = 0x689c,
+ [0xaa/2] = 0x1d25,
+ [0xac/2] = 0x609d,
+ [0xae/2] = 0x6825,
+ [0xb0/2] = 0x681c,
+ [0xb2/2] = 0x1d26,
+ [0xb4/2] = 0x601e,
+ [0xb6/2] = 0x6025,
+ [0xb8/2] = 0xe7f4,
+ [0xba/2] = 0x698a,
+ [0xbc/2] = 0x4202,
+ [0xbe/2] = 0xd0bf,
+ [0xc0/2] = 0xe7b9,
+ [0xc2/2] = 0x46c0,
+ [0xc4/2] = 0x0004, 0x2000,
+ [0xc8/2] = 0xcdef, 0x89ab,
+ [0xcc/2] = 0x0405, 0x0203,
+ [0xd0/2] = 0xaebf, 0x8c9d,
+ [0xd4/2] = 0x1516, 0x1314,
+ [0xd8/2] = 0x0700, 0x0001,
diff --git a/flashstub/stub.h b/flashstub/stub.h
new file mode 100644
index 0000000..b837bae
--- /dev/null
+++ b/flashstub/stub.h
@@ -0,0 +1,30 @@
+/*
+ * 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/>.
+ */
+#ifndef __STUB_H
+#define __STUB_H
+
+static inline void __attribute__((always_inline))
+stub_exit(const int code)
+{
+ asm("bkpt %0"::"i"(code));
+}
+
+#endif
+