app_flash_program.h
5.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#ifndef _APP_FLASH_PROGRAM_H_
#define _APP_FLASH_PROGRAM_H_
#if (defined USB_HOST_ENABLE || defined SD_ENABLE)
#ifdef PC_FS
#include <stdio.h>
extern FILE *upgrade_fp;
#else
#include "ide_file.h"
extern MYFILE *upgrade_fp;
#endif
#endif
//#define SFLASH_1M_BYTE
#define SFLASH_2M_BYTE
//#define SFLASH_4M_BYTE
//#define SFLASH_8M_BYTE
#define SFLASH_8M_BIT (1*8)
#define SFLASH_16M_BIT (2*8)
#define SFLASH_32M_BIT (4*8)
#define SFLASH_64M_BIT (8*8)
#if defined SFLASH_1M_BYTE
#define SFLASH_BIT_SIZE (1*8)
#elif defined SFLASH_2M_BYTE
#define SFLASH_BIT_SIZE (2*8)
#elif defined SFLASH_4M_BYTE
#define SFLASH_BIT_SIZE (4*8)
#else
#define SFLASH_BIT_SIZE (8*8)
#endif
#define BOOT_TAG_BYTE_SIZE 16
#define CHECK_SUM_BYTE_SIZE 4
#if 0
//#define FLASH_BLOCK_OFFSET 2
#define FLASH_BLOCK_ECO_BIN_OFFSET 2
#define FLASH_BLOCK_APP_BIN_OFFSET 3
#else
//#define FLASH_BLOCK_OFFSET 6
#define FLASH_BLOCK_ECO_BIN_OFFSET 7
#define FLASH_BLOCK_APP_BIN_OFFSET 8
#endif
//256 Bytes
#define FLASH_PAGE_SIZE 256
//4 kBytes
#define FLASH_SECTOR_SIZE (1024*4) //min erasing sector is 4k.
//32 kBytes
//#define FLASH_BLOCK_SIZE (1024*32)
//64 kBytes
#define FLASH_BLOCK_SIZE (1024*64)
#define FLASH_BLOCK_SECTORS_MAX (FLASH_BLOCK_SIZE/FLASH_SECTOR_SIZE)
#define FLASH_BLOCK_PAGE_MAX (FLASH_BLOCK_SIZE/FLASH_PAGE_SIZE)
#define FLASH_SECTOR_PAGE_MAX (FLASH_SECTOR_SIZE/FLASH_PAGE_SIZE)
#define FLASH_BASE_ADDR 0x58000000
#define FIRMWARE_ADDR_OFFSET 0x30000
#define BOOT_FLASH_TAG_START 0xFF000
#define BOOT_FLASH_TAG_END 0xFF010
//1MByte sFlash
#if defined(SFLASH_1M_BYTE)
#define FLASH_BLOCKS_MAX 16
#define FLASH_PAGE_MAX 4096
#define FLASH_BOOT_TAG_ADDR 0xFF000
#elif defined(SFLASH_2M_BYTE)
#define FLASH_BLOCKS_MAX 32
#define FLASH_PAGE_MAX (4096*2)
#define FLASH_BOOT_TAG_ADDR 0x1FF000
#elif defined(SFLASH_4M_BYTE)
#define FLASH_BLOCKS_MAX 64
#define FLASH_PAGE_MAX (4096*4)
#define FLASH_BOOT_TAG_ADDR 0x3FF000
#elif defined(SFLASH_8M_BYTE)
#define FLASH_BLOCKS_MAX 128
#define FLASH_PAGE_MAX (4096*8)
#define FLASH_BOOT_TAG_ADDR 0x7FF000
#else
#error "Must Define sFlash Size"
#endif
#if defined(SFLASH_1M_BYTE)
//#define FLASH_ERASE_ALL_TIMEOUT (1000*1)//no ok:1M Byte sFlash
//#define FLASH_ERASE_ALL_TIMEOUT (1000*2)//
#define FLASH_ERASE_ALL_TIMEOUT (1000*30)//
#elif defined(SFLASH_2M_BYTE)
//#define FLASH_ERASE_ALL_TIMEOUT (1000*4)//
#define FLASH_ERASE_ALL_TIMEOUT (1000*30)//
#elif defined(SFLASH_4M_BYTE)
//#define FLASH_ERASE_ALL_TIMEOUT (1000*8)//
#define FLASH_ERASE_ALL_TIMEOUT (1000*30)//
#elif defined(SFLASH_8M_BYTE)
//#define FLASH_ERASE_ALL_TIMEOUT (1000*16)//
#define FLASH_ERASE_ALL_TIMEOUT (1000*30)//
#else
#error "Must Define sFlash Size"
#endif
//#define FLASH_ERASE_ALL_TIMEOUT (1000*15)//
#if 0
#define FLASH_ERASE_PARTIAL_TIMEOUT 1000//
#define FLASH_ERASE_4K_SECTOR_TIMEOUT 1000//
#define FLASH_ERASE_64K_SECTOR_TIMEOUT 1000//
#define FLASH_PROGRAM_ALL_TIMEOUT 1000//
#define FLASH_PROGRAM_PARTIAL_TIMEOUT 1000//
#define FLASH_PROGRAM_4K_SECTOR_TIMEOUT 1000//
#define FLASH_PROGRAM_64K_SECTOR_TIMEOUT 1000//
//#define FLASH_PROGRAM_DATA_WAIT_TIMEOUT (1000*1)//
//#define FLASH_PROGRAM_DATA_WAIT_TIMEOUT (1000*5)//
#define FLASH_PROGRAM_DATA_WAIT_TIMEOUT (1000)//
#define FLASH_ERASE_VERIFY_TIMEOUT 1000//
#define FLASH_ERASE_4K_SECTOR_VERIFY_TIMEOUT 1000//
#define FLASH_ERASE_64K_SECTOR_VERIFY_TIMEOUT 1000//
#define FLASH_VERIFY_TIMEOUT 1000//
#define FLASH_VERIFY_4K_SECTOR_TIMEOUT 1000//
#define FLASH_VERIFY_64K_SECTOR_TIMEOUT 1000//
#define FLASH_PROGRAM_TAG_TIMEOUT 1000//
#define FLASH_VERIFY_TAG_TIMEOUT 1000
#else
#define FLASH_ERASE_PARTIAL_TIMEOUT 1000//
#define FLASH_ERASE_4K_SECTOR_TIMEOUT 1000//
#define FLASH_ERASE_64K_SECTOR_TIMEOUT 1000//
#define FLASH_PROGRAM_ALL_TIMEOUT 1000//
#define FLASH_PROGRAM_PARTIAL_TIMEOUT 1000//
#if 1
#define FLASH_PROGRAM_4K_SECTOR_TIMEOUT 10000//10s
#define FLASH_PROGRAM_64K_SECTOR_TIMEOUT 10000//10s
#else
//for BLE upgrade
#define FLASH_PROGRAM_4K_SECTOR_TIMEOUT 50000//50s
#define FLASH_PROGRAM_64K_SECTOR_TIMEOUT 50000//50s
#endif
//#define FLASH_PROGRAM_DATA_WAIT_TIMEOUT (1000*1)//
//#define FLASH_PROGRAM_DATA_WAIT_TIMEOUT (1000*5)//
#define FLASH_PROGRAM_DATA_WAIT_TIMEOUT (30000)//
#define FLASH_ERASE_VERIFY_TIMEOUT 10000//
#define FLASH_ERASE_4K_SECTOR_VERIFY_TIMEOUT 10000//
#define FLASH_ERASE_64K_SECTOR_VERIFY_TIMEOUT 10000//
#define FLASH_VERIFY_TIMEOUT 1000//
#define FLASH_VERIFY_4K_SECTOR_TIMEOUT 10000//
#define FLASH_VERIFY_64K_SECTOR_TIMEOUT 10000//
#define FLASH_PROGRAM_TAG_TIMEOUT 10000//
#define FLASH_VERIFY_TAG_TIMEOUT 10000//
#endif
enum {
FLASH_ERASE_ALL,
FLASH_ERASE_PARTIAL
};
U8 app_flash_program_init(void);
U8 app_flash_program_file_checksum_get(void);
U8 app_flash_erase(U8 mode);
U8 app_flash_program(U8 mode);
#endif //_APP_FLASH_PROGRAM_H_