1 /***************************************************************************
2 * Copyright (C) 2015 by Bogdan Kolbov *
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. *
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. *
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 ***************************************************************************/
26 /* K1921VK01T has 128-bitwidth flash, so it`s able to load 4x32-bit words at the time.
27 * And only after all words loaded we can start write
30 /* Registers addresses */
31 #define FLASH_FMA 0x00 /* Address reg */
32 #define FLASH_FMD1 0x04 /* Data1 reg */
33 #define FLASH_FMC 0x08 /* Command reg */
34 #define FLASH_FCIS 0x0C /* Operation Status reg */
35 #define FLASH_FCIC 0x14 /* Operation Status Clear reg */
36 #define FLASH_FMD2 0x50 /* Data2 reg */
37 #define FLASH_FMD3 0x54 /* Data3 reg */
38 #define FLASH_FMD4 0x58 /* Data4 reg*/
41 * r0 - write cmd (in), status (out)
52 ldr r7, =#0xA001C000 /* Flash reg base*/
55 ldr r6, [r2, #0] /* read wp */
56 cmp r6, #0 /* abort if wp == 0 */
58 ldr r5, [r2, #4] /* read rp */
59 cmp r5, r6 /* wait until rp != wp */
64 ldr r6, [r5] /* read data1 */
65 str r6, [r7, #FLASH_FMD1]
68 ldr r6, [r5] /* read data2 */
69 str r6, [r7, #FLASH_FMD2]
72 ldr r6, [r5] /* read data3 */
73 str r6, [r7, #FLASH_FMD3]
76 ldr r6, [r5] /* read data4 */
77 str r6, [r7, #FLASH_FMD4]
81 str r4, [r7, #FLASH_FMA] /* set addr */
83 str r0, [r7, #FLASH_FMC] /* write cmd */
86 ldr r6, [r7, #FLASH_FCIS] /* wait until flag set */
90 cmp r6, #2 /* check the error bit */
93 movs r6, #1 /* clear flags */
94 str r6, [r7, #FLASH_FCIC]
96 cmp r5, r3 /* wrap rp at end of buffer */
101 str r5, [r2, #4] /* store rp */
102 subs r1, r1, #1 /* decrement 16-byte block count */
104 beq exit /* loop if not done */
109 str r0, [r2, #4] /* set rp = 0 on error */
111 mov r0, r6 /* return status in r0 */