1284ab0a2f67f76b8f0866abc3ad64d0ae8259d5
[fw/openocd] / contrib / loaders / watchdog / armv7m_kinetis_wdog32.s
1 /***************************************************************************
2  *   Copyright (C) 2017 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, 32-bit version for newer Kinetis
22         Parameters:
23                 r0 ... WDOG32 base (in)
24
25         Used instruction set should work on both Cortex-M4 and M0+
26 */
27
28         .text
29         .syntax unified
30         .cpu cortex-m0
31         .thumb
32
33 /* WDOG registers offsets */
34 WDOG_CS         = 0
35 WDOG_CNT        = 4
36 WDOG_TOVAL      = 8
37
38 WDOG_KEY        = 0xd928c520
39
40         .thumb_func
41 start:
42 /* test WDOG_CS bit CMD32EN */
43         ldr     r2, [r0, WDOG_CS]
44         ldr     r3, =0x2000
45         tst     r2, r3
46         ldr     r3, =WDOG_KEY
47         beq     cmd16
48
49 /* WDOG_CNT = key */
50         str     r3, [r0, WDOG_CNT]
51         b       unlocked
52
53 cmd16:
54 /* WDOG_CNT = key, halfword by halfword */
55         strh    r3, [r0, WDOG_CNT]
56         lsrs    r3, r3, #16
57         strh    r3, [r0, WDOG_CNT]
58
59 /* WDOG_CS: clear EN bit 7, set UPDATE bit 5 */
60 unlocked:
61         movs    r4, #0x80
62         bics    r2, r4
63         movs    r4, #0x20
64         orrs    r2, r4
65         str     r2, [r0, WDOG_CS]
66 /* All active WDOG registers have to be updated, set dummy timeout */
67 /* WDOG_TOVAL = 0x400 */
68         ldr     r3, =0x400
69         str     r3, [r0, WDOG_TOVAL]
70 /* OpenOCD checks exit point address. Jump to the very end. */
71         b       done
72
73         .pool
74
75 /* Avoid padding at .text segment end. Otherwise exit point check fails. */
76         .skip   ( . - start + 2) & 2, 0
77 done:
78         bkpt    #0
79
80         .end