From 5a2608bbbc55a63b940fe9da10aaf0c73fcd23dc Mon Sep 17 00:00:00 2001 From: Tomas Vanek Date: Mon, 26 Dec 2016 19:59:10 +0100 Subject: flash Kinetis: handle all types of watchdog, disable in reset-init MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Active watchdog forces reset during armv7m_checksum_memory() in verify_image command if run just after reset init. COP watchdog in KL series and WDOG32 in KE1 series have longer timeout however they need to be disabled too. The change extends 'kinetis disable_wdog' command to optionally probe the chip and use appropriate algorithm to disable watchdog. Setting of cache type is also split from flash_support flags. Tcl command 'kinetis disable_wdog' is called in reset-init event. Change-Id: I3191e230f38b679ed74f2a97fe323ef8fb3fe22e Signed-off-by: Tomas Vanek Reviewed-on: http://openocd.zylin.com/3901 Tested-by: jenkins Reviewed-by: Joakim NohlgÄrd Reviewed-by: Freddie Chopin --- contrib/loaders/watchdog/Makefile | 2 +- contrib/loaders/watchdog/armv7m_kinetis_wdog.inc | 5 +- contrib/loaders/watchdog/armv7m_kinetis_wdog.s | 14 ++-- contrib/loaders/watchdog/armv7m_kinetis_wdog32.inc | 5 ++ contrib/loaders/watchdog/armv7m_kinetis_wdog32.s | 81 ++++++++++++++++++++++ 5 files changed, 96 insertions(+), 11 deletions(-) create mode 100644 contrib/loaders/watchdog/armv7m_kinetis_wdog32.inc create mode 100644 contrib/loaders/watchdog/armv7m_kinetis_wdog32.s (limited to 'contrib') diff --git a/contrib/loaders/watchdog/Makefile b/contrib/loaders/watchdog/Makefile index 623e744..ed6d8f4 100644 --- a/contrib/loaders/watchdog/Makefile +++ b/contrib/loaders/watchdog/Makefile @@ -6,7 +6,7 @@ ARM_OBJCOPY ?= $(ARM_CROSS_COMPILE)objcopy ARM_AFLAGS = -EL -mthumb -arm: armv7m_kinetis_wdog.inc +arm: armv7m_kinetis_wdog.inc armv7m_kinetis_wdog32.inc armv7m_%.elf: armv7m_%.s $(ARM_AS) $(ARM_AFLAGS) $< -o $@ diff --git a/contrib/loaders/watchdog/armv7m_kinetis_wdog.inc b/contrib/loaders/watchdog/armv7m_kinetis_wdog.inc index 4b6579e..317d084 100644 --- a/contrib/loaders/watchdog/armv7m_kinetis_wdog.inc +++ b/contrib/loaders/watchdog/armv7m_kinetis_wdog.inc @@ -1,4 +1,3 @@ /* Autogenerated with ../../../src/helper/bin2char.sh */ -0x04,0x4b,0x05,0x4a,0xda,0x81,0x05,0x4a,0xda,0x81,0x01,0x24,0x1a,0x88,0xa2,0x43, -0x1a,0x80,0x06,0xe0,0x00,0x20,0x05,0x40,0x20,0xc5,0x00,0x00,0x28,0xd9,0x00,0x00, -0x00,0x00,0x00,0xbe, +0x04,0x4a,0xc2,0x81,0x04,0x4a,0xc2,0x81,0x01,0x24,0x02,0x88,0xa2,0x43,0x02,0x80, +0x05,0xe0,0x00,0x00,0x20,0xc5,0x00,0x00,0x28,0xd9,0x00,0x00,0x00,0x00,0x00,0xbe, diff --git a/contrib/loaders/watchdog/armv7m_kinetis_wdog.s b/contrib/loaders/watchdog/armv7m_kinetis_wdog.s index bac924a..d724192 100644 --- a/contrib/loaders/watchdog/armv7m_kinetis_wdog.s +++ b/contrib/loaders/watchdog/armv7m_kinetis_wdog.s @@ -19,7 +19,9 @@ /* Disable watchdog for Kinetis Kx and KVx - Parameters: none + Parameters: + r0 ... WDOG base (in) + Used instruction set should work on both Cortex-M4 and M0+ */ @@ -28,7 +30,6 @@ .cpu cortex-m0 .thumb -WDOG_ADDR = 0x40052000 /* WDOG registers offsets */ WDOG_STCTRLH = 0 WDOG_UNLOCK = 0x0e @@ -39,17 +40,16 @@ WDOG_KEY2 = 0xd928 .thumb_func start: /* WDOG_UNLOCK = 0xC520 */ - ldr r3, =WDOG_ADDR ldr r2, =WDOG_KEY1 - strh r2, [r3, WDOG_UNLOCK] + strh r2, [r0, WDOG_UNLOCK] /* WDOG_UNLOCK = 0xD928 */ ldr r2, =WDOG_KEY2 - strh r2, [r3, WDOG_UNLOCK] + strh r2, [r0, WDOG_UNLOCK] /* WDOG_STCTRLH clear bit 0 */ movs r4, #1 - ldrh r2, [r3, WDOG_STCTRLH] + ldrh r2, [r0, WDOG_STCTRLH] bics r2, r4 - strh r2, [r3, WDOG_STCTRLH] + strh r2, [r0, WDOG_STCTRLH] /* OpenOCD checks exit point address. Jump to the very end. */ b done diff --git a/contrib/loaders/watchdog/armv7m_kinetis_wdog32.inc b/contrib/loaders/watchdog/armv7m_kinetis_wdog32.inc new file mode 100644 index 0000000..4ee06ed --- /dev/null +++ b/contrib/loaders/watchdog/armv7m_kinetis_wdog32.inc @@ -0,0 +1,5 @@ +/* Autogenerated with ../../../src/helper/bin2char.sh */ +0x02,0x68,0x08,0x4b,0x1a,0x42,0x08,0x4b,0x01,0xd0,0x43,0x60,0x02,0xe0,0x83,0x80, +0x1b,0x0c,0x83,0x80,0x80,0x24,0xa2,0x43,0x20,0x24,0x22,0x43,0x02,0x60,0x03,0x4b, +0x83,0x60,0x06,0xe0,0x00,0x20,0x00,0x00,0x20,0xc5,0x28,0xd9,0x00,0x04,0x00,0x00, +0x00,0x00,0x00,0xbe, diff --git a/contrib/loaders/watchdog/armv7m_kinetis_wdog32.s b/contrib/loaders/watchdog/armv7m_kinetis_wdog32.s new file mode 100644 index 0000000..bf58327 --- /dev/null +++ b/contrib/loaders/watchdog/armv7m_kinetis_wdog32.s @@ -0,0 +1,81 @@ +/*************************************************************************** + * Copyright (C) 2017 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc. * + ***************************************************************************/ + +/* + Disable watchdog, 32-bit version for newer Kinetis + Parameters: + r0 ... WDOG32 base (in) + + Used instruction set should work on both Cortex-M4 and M0+ +*/ + + .text + .syntax unified + .cpu cortex-m0 + .thumb + +/* WDOG registers offsets */ +WDOG_CS = 0 +WDOG_CNT = 4 +WDOG_TOVAL = 8 + +WDOG_KEY = 0xd928c520 + + .thumb_func +start: +/* test WDOG_CS bit CMD32EN */ + ldr r2, [r0, WDOG_CS] + ldr r3, =0x2000 + tst r2, r3 + ldr r3, =WDOG_KEY + beq cmd16 + +/* WDOG_CNT = key */ + str r3, [r0, WDOG_CNT] + b unlocked + +cmd16: +/* WDOG_CNT = key, halfword by halfword */ + strh r3, [r0, WDOG_CNT] + lsrs r3, r3, #16 + strh r3, [r0, WDOG_CNT] + +/* WDOG_CS: clear EN bit 7, set UPDATE bit 5 */ +unlocked: + movs r4, #0x80 + bics r2, r4 + movs r4, #0x20 + orrs r2, r4 + str r2, [r0, WDOG_CS] +/* All active WDOG registers have to be updated, set dummy timeout */ +/* WDOG_TOVAL = 0x400 */ + ldr r3, =0x400 + str r3, [r0, WDOG_TOVAL] +/* OpenOCD checks exit point address. Jump to the very end. */ + b done + + .pool + +/* Avoid padding at .text segment end. Otherwise exit point check fails. */ + .skip ( . - start + 2) & 2, 0 +done: + bkpt #0 + + .end + -- cgit v1.1