1 |
577 |
jeremybenn |
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
|
2 |
|
|
* File Name : 91x_fmi.c
|
3 |
|
|
* Author : MCD Application Team
|
4 |
|
|
* Date First Issued : 05/18/2006 : Version 1.0
|
5 |
|
|
* Description : This file provides all the FMI software functions.
|
6 |
|
|
********************************************************************************
|
7 |
|
|
* History:
|
8 |
|
|
* 05/24/2006 : Version 1.1
|
9 |
|
|
* 05/18/2006 : Version 1.0
|
10 |
|
|
********************************************************************************
|
11 |
|
|
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
|
12 |
|
|
* CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS
|
13 |
|
|
* A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
|
14 |
|
|
* OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
|
15 |
|
|
* OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
|
16 |
|
|
* CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
17 |
|
|
*******************************************************************************/
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
/* Standard include ----------------------------------------------------------*/
|
21 |
|
|
#include "91x_fmi.h"
|
22 |
|
|
|
23 |
|
|
/* Include of other module interface headers ---------------------------------*/
|
24 |
|
|
/* Local includes ------------------------------------------------------------*/
|
25 |
|
|
/* Private typedef -----------------------------------------------------------*/
|
26 |
|
|
/* Private define ------------------------------------------------------------*/
|
27 |
|
|
|
28 |
|
|
#define TIMEOUT 0xFFFFFF /* Timeout value */
|
29 |
|
|
|
30 |
|
|
/* Private macro -------------------------------------------------------------*/
|
31 |
|
|
/* Private variables ---------------------------------------------------------*/
|
32 |
|
|
/* Private function prototypes -----------------------------------------------*/
|
33 |
|
|
/* Interface functions -------------------------------------------------------*/
|
34 |
|
|
/* Private functions ---------------------------------------------------------*/
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
/*******************************************************************************
|
38 |
|
|
* Function Name : FMI_BankRemapConfig
|
39 |
|
|
* Description : Configure the addresses and sizes of bank 0 and bank 1.
|
40 |
|
|
* Input1 : FMI_BootBankSize: specifies the boot bank size.
|
41 |
|
|
* This parameter can be one of the following values:
|
42 |
|
|
* - 0x0: 32KBytes.
|
43 |
|
|
* - 0x1: 64KBytes.
|
44 |
|
|
* - 0x2: 128KBytes.
|
45 |
|
|
* - 0x3: 256KBytes.
|
46 |
|
|
* - 0x4: 512KBytes.
|
47 |
|
|
* ....
|
48 |
|
|
* - 0xB: 64MBytes.
|
49 |
|
|
* Input2 : FMI_NonBootBankSize: specifies the non boot bank size.
|
50 |
|
|
* This parameter can be one of the following values:
|
51 |
|
|
* - 0x0: 8KBytes.
|
52 |
|
|
* - 0x1: 16KBytes.
|
53 |
|
|
* - 0x2: 32KBytes.
|
54 |
|
|
* - 0x3: 64KBytes.
|
55 |
|
|
* ....
|
56 |
|
|
* - 0xD: 64MBytes.
|
57 |
|
|
* Input3 : FMI_BootBankAddress: specifies the address of the boot bank.
|
58 |
|
|
* Input4 : FMI_NonBootBankAddress: specifies the address of the non
|
59 |
|
|
* boot bank.
|
60 |
|
|
* Output : None
|
61 |
|
|
* Return : None
|
62 |
|
|
*******************************************************************************/
|
63 |
|
|
void FMI_BankRemapConfig(u8 FMI_BootBankSize, u8 FMI_NonBootBankSize, \
|
64 |
|
|
u32 FMI_BootBankAddress, u32 FMI_NonBootBankAddress)
|
65 |
|
|
{
|
66 |
|
|
FMI->BBSR = FMI_BootBankSize;
|
67 |
|
|
FMI->NBBSR = FMI_NonBootBankSize;
|
68 |
|
|
FMI->BBADR = (FMI_BootBankAddress >> 2);
|
69 |
|
|
FMI->NBBADR = (FMI_NonBootBankAddress >> 2);
|
70 |
|
|
FMI->CR |= 0x18; /* Enable bank 1 */
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
/*******************************************************************************
|
74 |
|
|
* Function Name : FMI_Config
|
75 |
|
|
* Description : Configure the FMI.
|
76 |
|
|
* Input1 : FMI_ReadWaitState: specifies the needed read wait states.
|
77 |
|
|
* This parameter can be one of the following values:
|
78 |
|
|
* - FMI_READ_WAIT_STATE_1: One read wait state.
|
79 |
|
|
* - FMI_READ_WAIT_STATE_2: Two read wait states.
|
80 |
|
|
* - FMI_READ_WAIT_STATE_3: Three read wait states.
|
81 |
|
|
* Input2 : FMI_WriteWaitState: specifies the needed write wait states.
|
82 |
|
|
* This parameter can be one of the following values:
|
83 |
|
|
* - FMI_WRITE_WAIT_STATE_1: One write wait state.
|
84 |
|
|
* - FMI_WRITE_WAIT_STATE_2: Two write wait states.
|
85 |
|
|
* Input3 : FMI_PWD: specifies the power down mode status.
|
86 |
|
|
* This parameter can be one of the following values:
|
87 |
|
|
* - FMI_PWD_ENABLE: Enable the PWD.
|
88 |
|
|
* - FMI_PWD_DISABLE: Disable the PWD.
|
89 |
|
|
* Input4 : FMI_LVDEN: specifies the low voltage detector status.
|
90 |
|
|
* This parameter can be one of the following values:
|
91 |
|
|
* - FMI_LVD_ENABLE: Enable the LVD.
|
92 |
|
|
* - FMI_LVD_DISABLE: Disable the LVD.
|
93 |
|
|
* Input5 : FMI_FreqRange: specifies the working frequency range.
|
94 |
|
|
* This parameter can be one of the following values:
|
95 |
|
|
* - FMI_FREQ_LOW: Low working frequency (up to 66MHz).
|
96 |
|
|
* - FMI_FREQ_HIGH: High working frequency (above 66MHz) .
|
97 |
|
|
* Output : None
|
98 |
|
|
* Return : None
|
99 |
|
|
*******************************************************************************/
|
100 |
|
|
void FMI_Config(u16 FMI_ReadWaitState, u32 FMI_WriteWaitState, u16 FMI_PWD,\
|
101 |
|
|
u16 FMI_LVDEN, u16 FMI_FreqRange)
|
102 |
|
|
{
|
103 |
|
|
/* Configure the write wait state value */
|
104 |
|
|
if (FMI_WriteWaitState == FMI_WRITE_WAIT_STATE_1)
|
105 |
|
|
{
|
106 |
|
|
FMI->CR |= FMI_WRITE_WAIT_STATE_1;
|
107 |
|
|
}
|
108 |
|
|
else
|
109 |
|
|
{
|
110 |
|
|
FMI->CR &= FMI_WRITE_WAIT_STATE_0;
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
/* Write a write flash configuration register command */
|
114 |
|
|
*(vu16 *)FMI_BANK_1 = 0x60;
|
115 |
|
|
|
116 |
|
|
/* Configure the flash configuration register */
|
117 |
|
|
*(vu16 *)(FMI_BANK_1|FMI_ReadWaitState|FMI_PWD|FMI_LVDEN|FMI_FreqRange) = 0x03;
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
/*******************************************************************************
|
121 |
|
|
* Function Name : FMI_EraseSector
|
122 |
|
|
* Description : Erase the needed sector.
|
123 |
|
|
* Input : FMI_Sector: specifies the sector to be erased.
|
124 |
|
|
* This parameter can be one of the following values:
|
125 |
|
|
* - FMI_B0S0: FMI bank 0 sector 0.
|
126 |
|
|
* - FMI_B0S1: FMI bank 0 sector 1.
|
127 |
|
|
* - FMI_B0S2: FMI bank 0 sector 2.
|
128 |
|
|
* - FMI_B0S3: FMI bank 0 sector 3.
|
129 |
|
|
* - FMI_B0S4: FMI bank 0 sector 4.
|
130 |
|
|
* - FMI_B0S5: FMI bank 0 sector 5.
|
131 |
|
|
* - FMI_B0S6: FMI bank 0 sector 6.
|
132 |
|
|
* - FMI_B0S7: FMI bank 0 sector 7.
|
133 |
|
|
* - FMI_B1S0: FMI bank 1 sector 0.
|
134 |
|
|
* - FMI_B1S1: FMI bank 1 sector 1.
|
135 |
|
|
* - FMI_B1S2: FMI bank 1 sector 2.
|
136 |
|
|
* - FMI_B1S3: FMI bank 1 sector 3.
|
137 |
|
|
* Output : None
|
138 |
|
|
* Return : None
|
139 |
|
|
*******************************************************************************/
|
140 |
|
|
void FMI_EraseSector(vu32 FMI_Sector)
|
141 |
|
|
{
|
142 |
|
|
/* Write an erase set-up command to the sector */
|
143 |
|
|
*(vu16 *)FMI_Sector = 0x20;
|
144 |
|
|
|
145 |
|
|
/* Write an erase confirm command to the sector */
|
146 |
|
|
*(vu16 *)FMI_Sector = 0xD0;
|
147 |
|
|
}
|
148 |
|
|
|
149 |
|
|
/*******************************************************************************
|
150 |
|
|
* Function Name : FMI_EraseBank
|
151 |
|
|
* Description : Erase the needed bank.
|
152 |
|
|
* Input : FMI_Bank: specifies the bank to be erased.
|
153 |
|
|
* This parameter can be one of the following values:
|
154 |
|
|
* - FMI_BANK_0: FMI bank 0.
|
155 |
|
|
* - FMI_BANK_1: FMI bank 1.
|
156 |
|
|
* Output : None
|
157 |
|
|
* Return : None
|
158 |
|
|
*******************************************************************************/
|
159 |
|
|
void FMI_EraseBank(vu32 FMI_Bank)
|
160 |
|
|
{
|
161 |
|
|
/* Write a bank erase set-up command to the bank */
|
162 |
|
|
*(vu16 *)FMI_Bank = 0x80;
|
163 |
|
|
|
164 |
|
|
/* Write an erase confirm command to the sector */
|
165 |
|
|
*(vu16 *)FMI_Bank = 0xD0;
|
166 |
|
|
}
|
167 |
|
|
|
168 |
|
|
/*******************************************************************************
|
169 |
|
|
* Function Name : FMI_WriteHalfWord
|
170 |
|
|
* Description : Write a halfword to the needed Flash memory address.
|
171 |
|
|
* Input 1 : FMI_Address: specifies the address offset where the data will
|
172 |
|
|
* be written.
|
173 |
|
|
* Input 2 : FMI_Data: the needed data.
|
174 |
|
|
* Output : None
|
175 |
|
|
* Return : None
|
176 |
|
|
*******************************************************************************/
|
177 |
|
|
void FMI_WriteHalfWord(u32 FMI_Address, u16 FMI_Data)
|
178 |
|
|
{
|
179 |
|
|
/* Write a program command to the sector to be written */
|
180 |
|
|
*(vu16 *)(FMI_Address & 0xFFFFFFFC) = 0x40;
|
181 |
|
|
|
182 |
|
|
/* Write the halfword to the destination address */
|
183 |
|
|
*(vu16 *)FMI_Address = FMI_Data;
|
184 |
|
|
}
|
185 |
|
|
|
186 |
|
|
/*******************************************************************************
|
187 |
|
|
* Function Name : FMI_WriteOTPHalfWord
|
188 |
|
|
* Description : Write a halfword to the needed OTP sector address.
|
189 |
|
|
* Input 1 : FMI_OTPHWAddress: specifies the halfword address offset
|
190 |
|
|
* where the data will be written.
|
191 |
|
|
* This parameter can be one of the following values:
|
192 |
|
|
* - FMI_OTP_LOW_HALFWORD_0: OTP Low halfword 0.
|
193 |
|
|
* - FMI_OTP_HIGH_HALFWORD_0: OTP High halfword 0.
|
194 |
|
|
* - FMI_OTP_LOW_HALFWORD_1: OTP Low halfword 1.
|
195 |
|
|
* - FMI_OTP_HIGH_HALFWORD_1: OTP High halfword 1.
|
196 |
|
|
* - FMI_OTP_LOW_HALFWORD_2: OTP Low halfword 2.
|
197 |
|
|
* - FMI_OTP_HIGH_HALFWORD_2: OTP High halfword 2.
|
198 |
|
|
* - FMI_OTP_LOW_HALFWORD_3: OTP Low halfword 3.
|
199 |
|
|
* - FMI_OTP_HIGH_HALFWORD_3: OTP High halfword 3.
|
200 |
|
|
* - FMI_OTP_LOW_HALFWORD_4: OTP Low halfword 4.
|
201 |
|
|
* - FMI_OTP_HIGH_HALFWORD_4: OTP High halfword 4.
|
202 |
|
|
* - FMI_OTP_LOW_HALFWORD_5: OTP Low halfword 5.
|
203 |
|
|
* - FMI_OTP_HIGH_HALFWORD_5: OTP High halfword 5.
|
204 |
|
|
* - FMI_OTP_LOW_HALFWORD_6: OTP Low halfword 6.
|
205 |
|
|
* - FMI_OTP_HIGH_HALFWORD_6: OTP High halfword 6.
|
206 |
|
|
* - FMI_OTP_LOW_HALFWORD_7: OTP Low halfword 7.
|
207 |
|
|
* - FMI_OTP_HIGH_HALFWORD_7: OTP High halfword 7.
|
208 |
|
|
* Input 2 : FMI_OTPData: The needed OTP data.
|
209 |
|
|
* Output : None
|
210 |
|
|
* Return : None
|
211 |
|
|
*******************************************************************************/
|
212 |
|
|
void FMI_WriteOTPHalfWord(u8 FMI_OTPHWAddress, u16 FMI_OTPData)
|
213 |
|
|
{
|
214 |
|
|
/* Write a write OTP command to the needed address */
|
215 |
|
|
*(vu16 *)(FMI_BANK_1) = 0xC0;
|
216 |
|
|
|
217 |
|
|
/* Write the halfword to the destination address */
|
218 |
|
|
*(vu16 *)(FMI_BANK_1 + FMI_OTPHWAddress) = FMI_OTPData;
|
219 |
|
|
}
|
220 |
|
|
|
221 |
|
|
/*******************************************************************************
|
222 |
|
|
* Function Name : FMI_ReadWord
|
223 |
|
|
* Description : Read the correspondent data.
|
224 |
|
|
* Input : FMI_Address: specifies the needed address.
|
225 |
|
|
* Output : None
|
226 |
|
|
* Return : The data contained in the specified address.
|
227 |
|
|
*******************************************************************************/
|
228 |
|
|
u32 FMI_ReadWord(u32 FMI_Address)
|
229 |
|
|
{
|
230 |
|
|
return(*(u32*)FMI_Address);
|
231 |
|
|
}
|
232 |
|
|
|
233 |
|
|
/*******************************************************************************
|
234 |
|
|
* Function Name : FMI_ReadOTPData
|
235 |
|
|
* Description : Read data from the OTP sector.
|
236 |
|
|
* Input : FMI_OTPAddress: specifies the address of the data to be read.
|
237 |
|
|
* This parameter can be one of the following values:
|
238 |
|
|
* - FMI_OTP_WORD_0: FMI bank 0 sector 0.
|
239 |
|
|
* - FMI_OTP_WORD_1: FMI bank 0 sector 1.
|
240 |
|
|
* - FMI_OTP_WORD_2: FMI bank 0 sector 2.
|
241 |
|
|
* - FMI_OTP_WORD_3: FMI bank 0 sector 3.
|
242 |
|
|
* - FMI_OTP_WORD_4: FMI bank 0 sector 4.
|
243 |
|
|
* - FMI_OTP_WORD_5: FMI bank 0 sector 5.
|
244 |
|
|
* - FMI_OTP_WORD_6: FMI bank 0 sector 6.
|
245 |
|
|
* - FMI_OTP_WORD_7: FMI bank 0 sector 7.
|
246 |
|
|
* Output : None
|
247 |
|
|
* Return : The needed OTP words.
|
248 |
|
|
*******************************************************************************/
|
249 |
|
|
u32 FMI_ReadOTPData(u8 FMI_OTPAddress)
|
250 |
|
|
{
|
251 |
|
|
u32 OTP_Data = 0x0;
|
252 |
|
|
/* write a read OTP sector command */
|
253 |
|
|
*(vu16 *)(FMI_BANK_1) = 0x98;
|
254 |
|
|
|
255 |
|
|
/* Read the correspondent data */
|
256 |
|
|
OTP_Data = (*(vu32*)(FMI_BANK_1 + FMI_OTPAddress));
|
257 |
|
|
|
258 |
|
|
/* Write a read array command */
|
259 |
|
|
*(vu16 *)(FMI_BANK_1) = 0xFF;
|
260 |
|
|
|
261 |
|
|
return OTP_Data;
|
262 |
|
|
}
|
263 |
|
|
|
264 |
|
|
/*******************************************************************************
|
265 |
|
|
* Function Name : FMI_GetFlagStatus
|
266 |
|
|
* Description : Check whether the specified FMI flag is set or not.
|
267 |
|
|
* Input1 : FMI_Flag: flag to check.
|
268 |
|
|
* This parameter can be one of the following values:
|
269 |
|
|
* - FMI_FLAG_SPS: Sector Protection Status Flag.
|
270 |
|
|
* - FMI_FLAG_PSS: Program Suspend Status Flag.
|
271 |
|
|
* - FMI_FLAG_PS: Program Status Flag.
|
272 |
|
|
* - FMI_FLAG_ES: Erase Status Flag.
|
273 |
|
|
* - FMI_FLAG_ESS: Erase Suspend Status Flag.
|
274 |
|
|
* - FMI_FLAG_PECS: FPEC Status Flag.
|
275 |
|
|
* Input2 : FMI_Bank: specifies the needed bank.
|
276 |
|
|
* This parameter can be one of the following values:
|
277 |
|
|
* - FMI_BANK_0: FMI bank 0.
|
278 |
|
|
* - FMI_BANK_1: FMI bank 1.
|
279 |
|
|
* Output : None
|
280 |
|
|
* Return : None
|
281 |
|
|
*******************************************************************************/
|
282 |
|
|
FlagStatus FMI_GetFlagStatus(u8 FMI_Flag, vu32 FMI_Bank)
|
283 |
|
|
{
|
284 |
|
|
u16 FMI_Status_Register = 0;
|
285 |
|
|
|
286 |
|
|
/* Write a read status register command */
|
287 |
|
|
*(vu16 *)FMI_Bank = 0x70;
|
288 |
|
|
|
289 |
|
|
/* Wait until operation completion */
|
290 |
|
|
while(!((*(vu16 *)FMI_Bank) & 0x80));
|
291 |
|
|
|
292 |
|
|
/* Read the status register */
|
293 |
|
|
FMI_Status_Register = *(vu16 *)FMI_Bank;
|
294 |
|
|
|
295 |
|
|
/* Write a read array command */
|
296 |
|
|
*(vu16 *)FMI_Bank = 0xFF;
|
297 |
|
|
|
298 |
|
|
if((FMI_Status_Register & FMI_Flag) != RESET)
|
299 |
|
|
{
|
300 |
|
|
return SET;
|
301 |
|
|
}
|
302 |
|
|
else
|
303 |
|
|
{
|
304 |
|
|
return RESET;
|
305 |
|
|
}
|
306 |
|
|
}
|
307 |
|
|
|
308 |
|
|
/*******************************************************************************
|
309 |
|
|
* Function Name : FMI_GetReadWaitStateValue
|
310 |
|
|
* Description : Get the current Read wait state value.
|
311 |
|
|
* Input : None
|
312 |
|
|
* Output : None
|
313 |
|
|
* Return : The current read wait states value.
|
314 |
|
|
*******************************************************************************/
|
315 |
|
|
u16 FMI_GetReadWaitStateValue(void)
|
316 |
|
|
{
|
317 |
|
|
u16 FMI_Configuration_Register = 0;
|
318 |
|
|
/* Write a read flash configuration register command */
|
319 |
|
|
*(vu16 *)FMI_BANK_1 = 0x90;
|
320 |
|
|
|
321 |
|
|
/* Read the flash configuration register */
|
322 |
|
|
FMI_Configuration_Register = *(vu16 *)(FMI_BANK_1 + 0x14);
|
323 |
|
|
|
324 |
|
|
/* Write a read array command */
|
325 |
|
|
*(vu16 *)FMI_BANK_1 = 0xFF;
|
326 |
|
|
|
327 |
|
|
FMI_Configuration_Register = ((FMI_Configuration_Register>>11) + 1) & 0x3;
|
328 |
|
|
|
329 |
|
|
/* Return the wait states value */
|
330 |
|
|
return FMI_Configuration_Register;
|
331 |
|
|
}
|
332 |
|
|
|
333 |
|
|
/*******************************************************************************
|
334 |
|
|
* Function Name : FMI_GetWriteWaitStateValue
|
335 |
|
|
* Description : Get the current write wait state value.
|
336 |
|
|
* Input : None
|
337 |
|
|
* Output : None
|
338 |
|
|
* Return : The current write wait states value.
|
339 |
|
|
*******************************************************************************/
|
340 |
|
|
u16 FMI_GetWriteWaitStateValue(void)
|
341 |
|
|
{
|
342 |
|
|
return ((u16)((FMI->CR & 0x100) >> 8));
|
343 |
|
|
}
|
344 |
|
|
|
345 |
|
|
/*******************************************************************************
|
346 |
|
|
* Function Name : FMI_SuspendEnable
|
347 |
|
|
* Description : Suspend command enable.
|
348 |
|
|
* Input : FMI_Bank: specifies the bank to be suspended.
|
349 |
|
|
* This parameter can be one of the following values:
|
350 |
|
|
* - FMI_BANK_0: FMI bank 0.
|
351 |
|
|
* - FMI_BANK_1: FMI bank 1.
|
352 |
|
|
* Output : None
|
353 |
|
|
* Return : None
|
354 |
|
|
*******************************************************************************/
|
355 |
|
|
void FMI_SuspendEnable(vu32 FMI_Bank)
|
356 |
|
|
{
|
357 |
|
|
/* Write a suspend command to the bank */
|
358 |
|
|
*(vu16 *)FMI_Bank = 0xB0;
|
359 |
|
|
}
|
360 |
|
|
|
361 |
|
|
/*******************************************************************************
|
362 |
|
|
* Function Name : FMI_ResumeEnable
|
363 |
|
|
* Description : Resume the suspended command.
|
364 |
|
|
* Input : FMI_Bank: specifies the suspended bank.
|
365 |
|
|
* This parameter can be one of the following values:
|
366 |
|
|
* - FMI_BANK_0: FMI bank 0.
|
367 |
|
|
* - FMI_BANK_1: FMI bank 1.
|
368 |
|
|
* Output : None
|
369 |
|
|
* Return : None
|
370 |
|
|
*******************************************************************************/
|
371 |
|
|
void FMI_ResumeEnable(vu32 FMI_Bank)
|
372 |
|
|
{
|
373 |
|
|
/* Write a resume command to the bank */
|
374 |
|
|
*(vu16 *)FMI_Bank = 0xD0;
|
375 |
|
|
}
|
376 |
|
|
|
377 |
|
|
/*******************************************************************************
|
378 |
|
|
* Function Name : FMI_ClearFlag
|
379 |
|
|
* Description : Clear the FMI Flags on the correspondent bank.
|
380 |
|
|
* Input : FMI_Bank: specifies the needed bank.
|
381 |
|
|
* This parameter can be one of the following values:
|
382 |
|
|
* - FMI_BANK_0: FMI bank 0.
|
383 |
|
|
* - FMI_BANK_1: FMI bank 1.
|
384 |
|
|
* Output : None
|
385 |
|
|
* Return : None
|
386 |
|
|
*******************************************************************************/
|
387 |
|
|
void FMI_ClearFlag(vu32 FMI_Bank)
|
388 |
|
|
{
|
389 |
|
|
/* Write a clear status register command */
|
390 |
|
|
*(vu16 *)FMI_Bank = 0x50;
|
391 |
|
|
}
|
392 |
|
|
|
393 |
|
|
/*******************************************************************************
|
394 |
|
|
* Function Name : FMI_WriteProtectionCmd
|
395 |
|
|
* Description : Enable or disable the write protection for the needed sector.
|
396 |
|
|
* Input1 : FMI_Sector: specifies the sector to be protected or
|
397 |
|
|
* unprotected.
|
398 |
|
|
* This parameter can be one of the following values:
|
399 |
|
|
* - FMI_B0S0: FMI bank 0 sector 0.
|
400 |
|
|
* - FMI_B0S1: FMI bank 0 sector 1.
|
401 |
|
|
* - FMI_B0S2: FMI bank 0 sector 2.
|
402 |
|
|
* - FMI_B0S3: FMI bank 0 sector 3.
|
403 |
|
|
* - FMI_B0S4: FMI bank 0 sector 4.
|
404 |
|
|
* - FMI_B0S5: FMI bank 0 sector 5.
|
405 |
|
|
* - FMI_B0S6: FMI bank 0 sector 6.
|
406 |
|
|
* - FMI_B0S7: FMI bank 0 sector 7.
|
407 |
|
|
* - FMI_B1S0: FMI bank 1 sector 0.
|
408 |
|
|
* - FMI_B1S1: FMI bank 1 sector 1.
|
409 |
|
|
* - FMI_B1S2: FMI bank 1 sector 2.
|
410 |
|
|
* - FMI_B1S3: FMI bank 1 sector 3.
|
411 |
|
|
* Input2 : FMI_NewState: specifies the protection status.
|
412 |
|
|
* This parameter can be one of the following values:
|
413 |
|
|
* - ENABLE: Enable the protection.
|
414 |
|
|
* - DISABLE: Disable the protection.
|
415 |
|
|
* Output : None
|
416 |
|
|
* Return : None
|
417 |
|
|
*******************************************************************************/
|
418 |
|
|
void FMI_WriteProtectionCmd(vu32 FMI_Sector, FunctionalState FMI_NewState)
|
419 |
|
|
{
|
420 |
|
|
if (FMI_NewState == ENABLE)
|
421 |
|
|
{
|
422 |
|
|
*(vu16*)FMI_Sector = 0x60;
|
423 |
|
|
*(vu16*)FMI_Sector = 0x01;
|
424 |
|
|
*(vu16*)FMI_Sector = 0xFF;
|
425 |
|
|
}
|
426 |
|
|
else /* DISABLE */
|
427 |
|
|
{
|
428 |
|
|
*(vu16*)FMI_Sector = 0x60;
|
429 |
|
|
*(vu16*)FMI_Sector = 0xD0;
|
430 |
|
|
*(vu16*)FMI_Sector = 0xFF;
|
431 |
|
|
}
|
432 |
|
|
}
|
433 |
|
|
|
434 |
|
|
/*******************************************************************************
|
435 |
|
|
* Function Name : FMI_GetWriteProtectionStatus
|
436 |
|
|
* Description : Get the write protection status for the needed sector.
|
437 |
|
|
* Input : FMI_Sector_Mask: specifies the needed sector mask.
|
438 |
|
|
* This parameter can be one of the following values:
|
439 |
|
|
* - FMI_B0S0_MASK: FMI bank 0 sector 0.
|
440 |
|
|
* - FMI_B0S1_MASK: FMI bank 0 sector 1.
|
441 |
|
|
* - FMI_B0S2_MASK: FMI bank 0 sector 2.
|
442 |
|
|
* - FMI_B0S3_MASK: FMI bank 0 sector 3.
|
443 |
|
|
* - FMI_B0S4_MASK: FMI bank 0 sector 4.
|
444 |
|
|
* - FMI_B0S5_MASK: FMI bank 0 sector 5.
|
445 |
|
|
* - FMI_B0S6_MASK: FMI bank 0 sector 6.
|
446 |
|
|
* - FMI_B0S7_MASK: FMI bank 0 sector 7.
|
447 |
|
|
* - FMI_B1S0_MASK: FMI bank 1 sector 0.
|
448 |
|
|
* - FMI_B1S1_MASK: FMI bank 1 sector 1.
|
449 |
|
|
* - FMI_B1S2_MASK: FMI bank 1 sector 2.
|
450 |
|
|
* - FMI_B1S3_MASK: FMI bank 1 sector 3.
|
451 |
|
|
* Output : None
|
452 |
|
|
* Return : The Protection Status of the needed sector.
|
453 |
|
|
* - RESET: The needed sector is not write protected.
|
454 |
|
|
* - SET : The needed sector is write protected.
|
455 |
|
|
*******************************************************************************/
|
456 |
|
|
FlagStatus FMI_GetWriteProtectionStatus(u32 FMI_Sector_Mask)
|
457 |
|
|
{
|
458 |
|
|
u16 Protection_Level_1_Register = 0;
|
459 |
|
|
/* Write a read flash protection level 1 register command */
|
460 |
|
|
*(vu16 *)FMI_BANK_1 = 0x90;
|
461 |
|
|
|
462 |
|
|
/* Read the flash protection level 1 register */
|
463 |
|
|
Protection_Level_1_Register = *(vu16 *)(FMI_BANK_1 + 0x10);
|
464 |
|
|
|
465 |
|
|
/* Write a read array command */
|
466 |
|
|
*(vu16 *)FMI_BANK_1 = 0xFF;
|
467 |
|
|
|
468 |
|
|
if (Protection_Level_1_Register &= FMI_Sector_Mask)
|
469 |
|
|
{
|
470 |
|
|
return SET;
|
471 |
|
|
}
|
472 |
|
|
else
|
473 |
|
|
{
|
474 |
|
|
return RESET;
|
475 |
|
|
}
|
476 |
|
|
}
|
477 |
|
|
|
478 |
|
|
/*******************************************************************************
|
479 |
|
|
* Function Name : FMI_WaitForLastOperation
|
480 |
|
|
* Description : Wait until the last operation (Write halfword, Write OTP
|
481 |
|
|
* halfword, Erase sector and Erase bank) completion.
|
482 |
|
|
* Input : FMI_Bank: specifies the bank where the operation is on going.
|
483 |
|
|
* This parameter can be one of the following values:
|
484 |
|
|
* - FMI_BANK_0: FMI bank 0.
|
485 |
|
|
* - FMI_BANK_1: FMI bank 1.
|
486 |
|
|
* Output : None
|
487 |
|
|
* Return : The timeout status.
|
488 |
|
|
* This parameter can be one of the following values:
|
489 |
|
|
* - FMI_TIME_OUT_ERROR: Timeout error occurred.
|
490 |
|
|
* - FMI_NO_TIME_OUT_ERROR: No timeout error.
|
491 |
|
|
*******************************************************************************/
|
492 |
|
|
u8 FMI_WaitForLastOperation(vu32 FMI_Bank)
|
493 |
|
|
{
|
494 |
|
|
u32 Time_Out = 0;
|
495 |
|
|
|
496 |
|
|
/* Write a read status register command */
|
497 |
|
|
*(vu16 *)(FMI_Bank) = 0x70;
|
498 |
|
|
|
499 |
|
|
/* Wait until operation compeletion */
|
500 |
|
|
while((!((*(vu16 *)FMI_Bank) & 0x80))&&(Time_Out < TIMEOUT ))
|
501 |
|
|
{
|
502 |
|
|
Time_Out ++; /* Time Out */
|
503 |
|
|
}
|
504 |
|
|
|
505 |
|
|
/* Write a read array command */
|
506 |
|
|
*(vu16 *)FMI_Bank = 0xFF;
|
507 |
|
|
|
508 |
|
|
if (Time_Out == TIMEOUT)
|
509 |
|
|
{
|
510 |
|
|
return FMI_TIME_OUT_ERROR;
|
511 |
|
|
}
|
512 |
|
|
else
|
513 |
|
|
{
|
514 |
|
|
return FMI_NO_TIME_OUT_ERROR;
|
515 |
|
|
}
|
516 |
|
|
}
|
517 |
|
|
|
518 |
|
|
|
519 |
|
|
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/
|