flash Kinetis: new KVx family added
[openocd.git] / contrib / loaders / watchdog / armv7m_kinetis_wdog.s
1 /***************************************************************************
2  *   Copyright (C) 2015 Tomas Vanek                                        *
3  *   vanekt@fbl.cz                                                         *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.                                        *
18  ***************************************************************************/
19
20 /*
21         Disable watchdog for Kinetis Kx and KVx
22         Parameters: none
23         Used instruction set should work on both Cortex-M4 and M0+
24 */
25
26         .text
27         .syntax unified
28         .cpu cortex-m0
29         .thumb
30
31 WDOG_ADDR       = 0x40052000
32 /* WDOG registers offsets */
33 WDOG_STCTRLH    = 0
34 WDOG_UNLOCK     = 0x0e
35
36 WDOG_KEY1       = 0xc520
37 WDOG_KEY2       = 0xd928
38
39         .thumb_func
40 start:
41 /* WDOG_UNLOCK = 0xC520 */
42         ldr     r3, =WDOG_ADDR
43         ldr     r2, =WDOG_KEY1
44         strh    r2, [r3, WDOG_UNLOCK]
45 /* WDOG_UNLOCK = 0xD928 */
46         ldr     r2, =WDOG_KEY2
47         strh    r2, [r3, WDOG_UNLOCK]
48 /* WDOG_STCTRLH clear bit 0 */
49         movs    r4, #1
50         ldrh    r2, [r3, WDOG_STCTRLH]
51         bics    r2, r4
52         strh    r2, [r3, WDOG_STCTRLH]
53 /* OpenOCD checks exit point address. Jump to the very end. */
54         b       done
55
56         .pool
57
58 /* Avoid padding at .text segment end. Otherwise exit point check fails. */
59         .skip   ( . - start + 2) & 2, 0
60 done:
61         bkpt    #0
62
63         .end
64