1 /***************************************************************************
2 * Copyright (C) 2011 by Andreas Fritiofson *
3 * andreas.fritiofson@gmail.com *
5 * Copyright (C) 2013 by Paul Fertser *
6 * fercerpav@gmail.com *
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. *
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. *
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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
22 ***************************************************************************/
32 * r0 - flash base (in), status (out)
40 * r7 - current FLASH_CMD
43 #define FLASH_CMD 0x00
44 #define FLASH_ADR 0x04
47 #define FLASH_NVSTR (1 << 13)
48 #define FLASH_PROG (1 << 12)
49 #define FLASH_MAS1 (1 << 11)
50 #define FLASH_ERASE (1 << 10)
51 #define FLASH_SE (1 << 8)
52 #define FLASH_YE (1 << 7)
53 #define FLASH_XE (1 << 6)
55 ldr r7, [r0, #FLASH_CMD]
57 ldr r6, [r2, #0] /* read wp */
58 cmp r6, #0 /* abort if wp == 0 */
60 ldr r5, [r2, #4] /* read rp */
61 cmp r5, r6 /* wait until rp != wp */
64 ldr r6, [r5] /* "*target_address++ = *rp++" */
65 str r4, [r0, #FLASH_ADR]
66 str r6, [r0, #FLASH_DI]
68 ldr r6, =(FLASH_XE | FLASH_PROG)
70 str r7, [r0, #FLASH_CMD]
76 str r7, [r0, #FLASH_CMD]
82 str r7, [r0, #FLASH_CMD]
88 str r7, [r0, #FLASH_CMD]
91 str r7, [r0, #FLASH_CMD]
95 ldr r6, =#(FLASH_XE | FLASH_NVSTR)
97 str r7, [r0, #FLASH_CMD]
102 cmp r5, r3 /* wrap rp at end of buffer */
107 str r5, [r2, #4] /* store rp */
108 subs r1, r1, #1 /* decrement word count */
110 beq exit /* loop if not done */
113 mov r0, r6 /* return status in r0 */
117 * for r6 == 1 it'll take:
118 * 1 (prepare operand) + 4 (bl) + 2 (subs+cmp) + 1 (bne) + 3 (b) ->
119 * 11 tacts == 1.4us with 8MHz
120 * every extra iteration will take 5 tacts == 0.6us */