aboutsummaryrefslogtreecommitdiff
path: root/contrib/loaders
diff options
context:
space:
mode:
authorTomas Vanek <vanekt@fbl.cz>2016-07-22 13:19:19 +0200
committerFreddie Chopin <freddie.chopin@gmail.com>2016-11-04 21:26:46 +0000
commit22b4a0f40da200563a32e5bab86aceecf486ddd3 (patch)
treeaafbb624806e3740289f1277bd1cdd6e31c378ab /contrib/loaders
parent009943010420e49c2632769e9e21502b8166ba41 (diff)
downloadriscv-openocd-22b4a0f40da200563a32e5bab86aceecf486ddd3.zip
riscv-openocd-22b4a0f40da200563a32e5bab86aceecf486ddd3.tar.gz
riscv-openocd-22b4a0f40da200563a32e5bab86aceecf486ddd3.tar.bz2
flash Kinetis: longword programming changed to flash_async_algorithm
Change-Id: I9c40acfad37760c3dab454f2432817b2d420792d Signed-off-by: Tomas Vanek <vanekt@fbl.cz> Reviewed-on: http://openocd.zylin.com/3563 Reviewed-by: Steven Stallion <stallion@squareup.com> Tested-by: jenkins Reviewed-by: Freddie Chopin <freddie.chopin@gmail.com>
Diffstat (limited to 'contrib/loaders')
-rw-r--r--contrib/loaders/flash/kinetis/Makefile19
-rw-r--r--contrib/loaders/flash/kinetis/kinetis_flash.inc6
-rw-r--r--contrib/loaders/flash/kinetis/kinetis_flash.s101
3 files changed, 126 insertions, 0 deletions
diff --git a/contrib/loaders/flash/kinetis/Makefile b/contrib/loaders/flash/kinetis/Makefile
new file mode 100644
index 0000000..b240f53
--- /dev/null
+++ b/contrib/loaders/flash/kinetis/Makefile
@@ -0,0 +1,19 @@
+BIN2C = ../../../../src/helper/bin2char.sh
+
+CROSS_COMPILE ?= arm-none-eabi-
+AS = $(CROSS_COMPILE)as
+OBJCOPY = $(CROSS_COMPILE)objcopy
+
+all: kinetis_flash.inc
+
+%.elf: %.s
+ $(AS) $< -o $@
+
+%.bin: %.elf
+ $(OBJCOPY) -Obinary $< $@
+
+%.inc: %.bin
+ $(BIN2C) < $< > $@
+
+clean:
+ -rm -f *.elf *.bin *.inc
diff --git a/contrib/loaders/flash/kinetis/kinetis_flash.inc b/contrib/loaders/flash/kinetis/kinetis_flash.inc
new file mode 100644
index 0000000..c93797b
--- /dev/null
+++ b/contrib/loaders/flash/kinetis/kinetis_flash.inc
@@ -0,0 +1,6 @@
+/* Autogenerated with ../../../../src/helper/bin2char.sh */
+0x16,0x68,0x00,0x2e,0x1f,0xd0,0x55,0x68,0xb5,0x42,0xf9,0xd0,0x60,0x60,0x06,0x27,
+0xe7,0x71,0x2f,0x68,0xa7,0x60,0x80,0x27,0x27,0x70,0x04,0x35,0x9d,0x42,0x01,0xd3,
+0x15,0x1c,0x08,0x35,0x55,0x60,0x16,0x68,0x00,0x2e,0x0c,0xd0,0x26,0x78,0x3e,0x42,
+0xf9,0xd0,0x70,0x27,0x3e,0x42,0x04,0xd1,0x04,0x30,0x01,0x39,0x00,0x29,0xdf,0xd1,
+0x01,0xe0,0x00,0x25,0x55,0x60,0x00,0xbe,
diff --git a/contrib/loaders/flash/kinetis/kinetis_flash.s b/contrib/loaders/flash/kinetis/kinetis_flash.s
new file mode 100644
index 0000000..c8e6e05
--- /dev/null
+++ b/contrib/loaders/flash/kinetis/kinetis_flash.s
@@ -0,0 +1,101 @@
+/***************************************************************************
+ * Copyright (C) 2015 by Ivan Meleca *
+ * ivan@artekit.eu *
+ * *
+ * Copyright (C) 2016 by Tomas Vanek *
+ * vanekt@fbl.cz *
+ * *
+ * 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 2 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. *
+ ***************************************************************************/
+
+ /* Params:
+ * r0 = flash destination address in/out
+ * r1 = longword count
+ * r2 = workarea start address
+ * r3 = workarea end address
+ * r4 = FTFx base
+ */
+
+ .text
+ .cpu cortex-m0plus
+ .code 16
+ .thumb_func
+
+ .align 2
+
+ /* r5 = rp
+ * r6 = wp, tmp
+ * r7 = tmp
+ */
+
+ /* old longword algo: 6.680 KiB/s @ adapter_khz 2000
+ * this async algo: 19.808 KiB/s @ adapter_khz 2000
+ */
+
+FTFx_FSTAT = 0
+FTFx_FCCOB3 = 4
+FTFx_FCCOB0 = 7
+FTFx_FCCOB7 = 8
+
+wait_fifo:
+ ldr r6, [r2, #0] /* read wp */
+ cmp r6, #0 /* abort if wp == 0 */
+ beq exit
+
+ ldr r5, [r2, #4] /* read rp */
+ cmp r5, r6 /* wait until rp != wp */
+ beq wait_fifo
+
+ str r0, [r4, #FTFx_FCCOB3] /* set flash address */
+ mov r7, #6
+ strb r7, [r4, #FTFx_FCCOB0] /* flash command */
+
+ ldr r7, [r5] /* set longword data = *rp */
+ str r7, [r4, #FTFx_FCCOB7]
+
+ mov r7, #128
+ strb r7, [r4, #FTFx_FSTAT]
+
+ add r5, #4 /* rp += 4 */
+ cmp r5, r3 /* Wrap? */
+ bcc no_wrap
+ mov r5, r2
+ add r5, #8
+
+no_wrap:
+ str r5, [r2, #4] /* Store rp */
+
+wait_ccif:
+ ldr r6, [r2, #0] /* read wp */
+ cmp r6, #0 /* abort if wp == 0 */
+ beq exit
+
+ ldrb r6, [r4, #FTFx_FSTAT]
+ tst r6, r7
+ beq wait_ccif
+
+ mov r7, #0x70
+ tst r6, r7
+ bne error
+
+ add r0, #4 /* flash address += 4, do not increment before err check */
+
+ sub r1, #1 /* word_count-- */
+ cmp r1, #0
+ bne wait_fifo
+ b exit
+
+error:
+ mov r5, #0
+ str r5, [r2, #4] /* set rp = 0 on error */
+
+exit:
+ bkpt #0