]> git.sur5r.net Git - openocd/blob - contrib/loaders/flash/stellaris.s
flash: add stellaris async flash loader
[openocd] / contrib / loaders / flash / stellaris.s
1 /***************************************************************************
2  *   Copyright (C) 2006 by Magnus Lundin                                   *
3  *   lundin@mlu.mine.nu                                                    *
4  *                                                                         *
5  *   Copyright (C) 2008 by Spencer Oliver                                  *
6  *   spen@spen-soft.co.uk                                                  *
7  *                                                                         *
8  *   This program is free software; you can redistribute it and/or modify  *
9  *   it under the terms of the GNU General Public License as published by  *
10  *   the Free Software Foundation; either version 2 of the License, or     *
11  *   (at your option) any later version.                                   *
12  *                                                                         *
13  *   This program is distributed in the hope that it will be useful,       *
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
16  *   GNU General Public License for more details.                          *
17  *                                                                         *
18  *   You should have received a copy of the GNU General Public License     *
19  *   along with this program; if not, write to the                         *
20  *   Free Software Foundation, Inc.,                                       *
21  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
22  ***************************************************************************/
23
24         .text
25         .syntax unified
26         .cpu cortex-m3
27         .thumb
28         .thumb_func
29
30 /*
31  * Params :
32  * r0 = workarea start
33  * r1 = workarea end
34  * r2 = target address
35  * r3 = count (32bit words)
36  *
37  * Clobbered:
38  * r4 = pFLASH_CTRL_BASE
39  * r5 = FLASHWRITECMD
40  * r7 - rp
41  * r8 - wp, tmp
42  */
43
44 write:
45         ldr     r4, pFLASH_CTRL_BASE
46         ldr     r5, FLASHWRITECMD
47
48 wait_fifo:
49         ldr     r8, [r0, #0]    /* read wp */
50         cmp     r8, #0                  /* abort if wp == 0 */
51         beq     exit
52         ldr     r7, [r0, #4]    /* read rp */
53         cmp     r7, r8                  /* wait until rp != wp */
54         beq     wait_fifo
55
56 mainloop:
57         str             r2, [r4, #0]    /* FMA - write address */
58         add             r2, r2, #4              /* increment target address */
59         ldr             r8, [r7], #4
60         str             r8, [r4, #4]    /* FMD - write data */
61         str             r5, [r4, #8]    /* FMC - enable write */
62 busy:
63         ldr             r8, [r4, #8]
64         tst             r8, #1
65         bne             busy
66
67         cmp     r7, r1                  /* wrap rp at end of buffer */
68         it      cs
69         addcs   r7, r0, #8              /* skip loader args */
70         str     r7, [r0, #4]    /* store rp */
71         subs    r3, r3, #1              /* decrement word count */
72         cbz     r3, exit                /* loop if not done */
73         b               wait_fifo
74 exit:
75         bkpt    #0
76
77 pFLASH_CTRL_BASE: .word 0x400FD000
78 FLASHWRITECMD: .word 0xA4420001