max32xxx: Support for MAX32XXX devices.
[openocd.git] / contrib / loaders / flash / max32xxx / max32xxx.s
blobf5306d6c5d6c8eeec11d7e9a7e9567791c6255b1
1 /***************************************************************************
2 * Copyright (C) 2016 by Maxim Integrated *
3 * Kevin Gillespie <kevin.gillespie@maximintegrated.com *
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, see <http://www.gnu.org/licenses/>. *
17 ***************************************************************************/
19 .text
20 .syntax unified
21 .cpu cortex-m3
22 .thumb
23 .thumb_func
26 * Params :
27 * r0 = workarea start
28 * r1 = workarea end
29 * r2 = target address
30 * r3 = count (32bit words)
31 * r4 = pFLASH_CTRL_BASE
33 * Clobbered:
34 * r5 = FLASHWRITECMD
35 * r7 - rp
36 * r8 - wp, tmp
39 write:
41 wait_fifo:
42 ldr r8, [r0, #0] /* read wp */
43 cmp r8, #0 /* abort if wp == 0 */
44 beq exit
45 ldr r7, [r0, #4] /* read rp */
46 cmp r7, r8 /* wait until rp != wp */
47 beq wait_fifo
49 mainloop:
50 str r2, [r4, #0x00] /* FLSH_ADDR - write address */
51 add r2, r2, #4 /* increment target address */
52 ldr r8, [r7], #4
53 str r8, [r4, #0x30] /* FLSH_DATA0 - write data */
54 ldr r5, [r4, #0x08] /* FLSH_CN */
55 orr r5, r5, #1
56 str r5, [r4, #0x08] /* FLSH_CN - enable write */
57 busy:
58 ldr r8, [r4, #0x08] /* FLSH_CN */
59 tst r8, #1
60 bne busy
62 cmp r7, r1 /* wrap rp at end of buffer */
63 it cs
64 addcs r7, r0, #8 /* skip loader args */
65 str r7, [r0, #4] /* store rp */
66 subs r3, r3, #1 /* decrement word count */
67 cbz r3, exit /* loop if not done */
68 b wait_fifo
69 exit:
70 bkpt