1 /***************************************************************************
2 * Copyright (C) 2017 by Texas Instruments, Inc. *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
16 ***************************************************************************/
19 * r0 = buffer start address (in)
20 * r1 = flash destination address (in)
21 * r2 = number of words to write (in/out)
33 * r4 = buffer word counter
34 * r10 = flash programming key
35 * r11 = base FWB address
36 * r12 = base flash regs address
40 ldr r10, =0xa4420001 /* flash programming key */
41 ldr r11, =0x400fd100 /* base of FWB */
42 ldr r12, =0x400fd000 /* base of flash regs */
43 and r3, r1, #0x7f /* is the dest address 32 word aligned? */
45 bne program_word /* if not aligned do one word at a time */
47 /* program using the write buffers */
49 mov r4, #0 /* start the buffer word counter at 0 */
50 str r1, [r12] /* store the dest addr in FMA */
52 ldr r3, [r0] /* get the word to write to FWB */
53 str r3, [r11] /* store the word in the FWB */
54 add r11, r11, #4 /* increment the FWB pointer */
55 add r0, r0, #4 /* increment the source pointer */
56 sub r2, r2, #1 /* decrement the total word counter */
57 add r4, r4, #1 /* increment the buffer word counter */
58 add r1, r1, #4 /* increment the dest pointer */
59 cmp r2, #0 /* is the total word counter now 0? */
60 beq buffer_ready /* go to end if total word counter is 0 */
61 cmp r4, #32 /* is the buffer word counter now 32? */
62 bne fill_buffer /* go to continue to fill buffer */
64 str r10, [r12, #0x20] /* store the key and write bit to FMC2 */
66 ldr r3, [r12, #0x20] /* read FMC2 */
67 tst r3, #1 /* see if the write bit is cleared */
68 bne wait_buffer_done /* go to read FMC2 if bit not cleared */
69 cmp r2, #0 /* is the total word counter now 0? */
70 bne start /* go if there is more to program */
73 /* program just one word */
75 str r1, [r12] /* store the dest addr in FMA */
76 ldr r3, [r0] /* get the word to write to FMD */
77 str r3, [r12, #0x4] /* store the word in FMD */
78 str r10, [r12, #0x8] /* store the key and write bit to FMC */
80 ldr r3, [r12, #0x8] /* read FMC */
81 tst r3, #1 /* see if the write bit is cleared */
82 bne wait_word_done /* go to read FMC if bit not cleared */
83 sub r2, r2, #1 /* decrement the total word counter */
84 add r0, r0, #4 /* increment the source pointer */
85 add r1, r1, #4 /* increment the dest pointer */
86 cmp r2, #0 /* is the total word counter now 0 */
87 bne start /* go if there is more to program */