Rev 1 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1 | Rev 196 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /******************** (C) COPYRIGHT 2006 STMicroelectronics ******************** |
1 | /******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** |
2 | * File Name : 91x_fmi.c |
2 | * File Name : 91x_fmi.c |
3 | * Author : MCD Application Team |
3 | * Author : MCD Application Team |
- | 4 | * Version : V2.1 |
|
4 | * Date First Issued : 05/18/2006 : Version 1.0 |
5 | * Date : 12/22/2008 |
5 | * Description : This file provides all the FMI software functions. |
6 | * Description : This file provides all the FMI firmware functions. |
6 | ******************************************************************************** |
- | |
7 | * History: |
- | |
8 | * 05/22/2007 : Version 1.2 |
- | |
9 | * 05/24/2006 : Version 1.1 |
- | |
10 | * 05/18/2006 : Version 1.0 |
- | |
11 | ******************************************************************************** |
7 | ******************************************************************************** |
12 | * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH |
8 | * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH |
13 | * CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS |
9 | * CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS |
14 | * A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT |
10 | * A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT |
15 | * OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT |
11 | * OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT |
Line 95... | Line 91... | ||
95 | * This parameter can be one of the following values: |
91 | * This parameter can be one of the following values: |
96 | * - FMI_FREQ_LOW: Low working frequency (up to 66MHz). |
92 | * - FMI_FREQ_LOW: Low working frequency (up to 66MHz). |
97 | * - FMI_FREQ_HIGH: High working frequency (above 66MHz) . |
93 | * - FMI_FREQ_HIGH: High working frequency (above 66MHz) . |
98 | * Output : None |
94 | * Output : None |
99 | * Return : None |
95 | * Return : None |
- | 96 | * |
|
- | 97 | *NOTE: |
|
- | 98 | *This function should be executed from SRAM when booting from bank1 |
|
- | 99 | *to avoid any conflicts(reading and writing at the same time in bank1) |
|
- | 100 | * |
|
100 | *******************************************************************************/ |
101 | *******************************************************************************/ |
101 | void FMI_Config(u16 FMI_ReadWaitState, u32 FMI_WriteWaitState, u16 FMI_PWD,\ |
102 | void FMI_Config(u16 FMI_ReadWaitState, u32 FMI_WriteWaitState, u16 FMI_PWD,\ |
102 | u16 FMI_LVDEN, u16 FMI_FreqRange) |
103 | u16 FMI_LVDEN, u16 FMI_FreqRange) |
103 | { |
104 | { |
104 | /* Configure the write wait state value */ |
105 | /* Configure the write wait state value */ |
Line 122... | Line 123... | ||
122 | * Function Name : FMI_EraseSector |
123 | * Function Name : FMI_EraseSector |
123 | * Description : Erase the needed sector. |
124 | * Description : Erase the needed sector. |
124 | * Input : FMI_Sector: specifies the sector to be erased. |
125 | * Input : FMI_Sector: specifies the sector to be erased. |
125 | * This parameter can be one of the following values: |
126 | * This parameter can be one of the following values: |
126 | * - FMI_B0S0: FMI bank 0 sector 0. |
127 | * - FMI_B0S0: FMI bank 0 sector 0. |
127 | * - FMI_B0S1: FMI bank 0 sector 1. |
- | |
128 | * - FMI_B0S2: FMI bank 0 sector 2. |
128 | * ... |
129 | * - FMI_B0S3: FMI bank 0 sector 3. |
129 | * - FMI_B0S31: FMI bank 0 sector 31. |
130 | * - FMI_B0S4: FMI bank 0 sector 4. |
- | |
131 | * - FMI_B0S5: FMI bank 0 sector 5. |
- | |
132 | * - FMI_B0S6: FMI bank 0 sector 6. |
- | |
133 | * - FMI_B0S7: FMI bank 0 sector 7. |
- | |
- | 130 | * |
|
- | 131 | * |
|
134 | * - FMI_B1S0: FMI bank 1 sector 0. |
132 | * - FMI_B1S0: FMI bank 1 sector 0. |
135 | * - FMI_B1S1: FMI bank 1 sector 1. |
133 | * ... |
136 | * - FMI_B1S2: FMI bank 1 sector 2. |
134 | * - FMI_B1S7: FMI bank 1 sector 7. |
137 | * - FMI_B1S3: FMI bank 1 sector 3. |
- | |
138 | * Output : None |
135 | * Output : None |
139 | * Return : None |
136 | * Return : None |
140 | *******************************************************************************/ |
137 | *******************************************************************************/ |
141 | void FMI_EraseSector(vu32 FMI_Sector) |
138 | void FMI_EraseSector(vu32 FMI_Sector) |
142 | { |
139 | { |
Line 234... | Line 231... | ||
234 | /******************************************************************************* |
231 | /******************************************************************************* |
235 | * Function Name : FMI_ReadOTPData |
232 | * Function Name : FMI_ReadOTPData |
236 | * Description : Read data from the OTP sector. |
233 | * Description : Read data from the OTP sector. |
237 | * Input : FMI_OTPAddress: specifies the address of the data to be read. |
234 | * Input : FMI_OTPAddress: specifies the address of the data to be read. |
238 | * This parameter can be one of the following values: |
235 | * This parameter can be one of the following values: |
239 | * - FMI_OTP_WORD_0: FMI bank 0 sector 0. |
236 | * - FMI_OTP_WORD_0: OTP word 0 . |
240 | * - FMI_OTP_WORD_1: FMI bank 0 sector 1. |
237 | * - FMI_OTP_WORD_1: OTP word 1 . |
241 | * - FMI_OTP_WORD_2: FMI bank 0 sector 2. |
238 | * - FMI_OTP_WORD_2: OTP word 2 . |
242 | * - FMI_OTP_WORD_3: FMI bank 0 sector 3. |
239 | * - FMI_OTP_WORD_3: OTP word 3 . |
243 | * - FMI_OTP_WORD_4: FMI bank 0 sector 4. |
240 | * - FMI_OTP_WORD_4: OTP word 4 . |
244 | * - FMI_OTP_WORD_5: FMI bank 0 sector 5. |
241 | * - FMI_OTP_WORD_5: OTP word 5 . |
245 | * - FMI_OTP_WORD_6: FMI bank 0 sector 6. |
242 | * - FMI_OTP_WORD_6: OTP word 6 . |
246 | * - FMI_OTP_WORD_7: FMI bank 0 sector 7. |
243 | * - FMI_OTP_WORD_7: OTP word 7 . |
247 | * Output : None |
244 | * Output : None |
248 | * Return : The needed OTP words. |
245 | * Return : The needed OTP words. |
249 | *******************************************************************************/ |
246 | *******************************************************************************/ |
250 | u32 FMI_ReadOTPData(u8 FMI_OTPAddress) |
247 | u32 FMI_ReadOTPData(u8 FMI_OTPAddress) |
251 | { |
248 | { |
Line 314... | Line 311... | ||
314 | * Return : The current read wait states value. |
311 | * Return : The current read wait states value. |
315 | *******************************************************************************/ |
312 | *******************************************************************************/ |
316 | u16 FMI_GetReadWaitStateValue(void) |
313 | u16 FMI_GetReadWaitStateValue(void) |
317 | { |
314 | { |
318 | u16 FMI_Configuration_Register = 0; |
315 | u16 FMI_Configuration_Register = 0; |
319 | /* Write a read flash configuration register command */ |
316 | /*Write a read RSIG command to any word address in Bank1*/ |
320 | *(vu16 *)FMI_BANK_1 = 0x90; |
317 | *(vu16 *)FMI_BANK_1 = 0x90; |
321 | 318 | ||
322 | /* Read the flash configuration register */ |
319 | /* Read the flash configuration register */ |
- | 320 | #ifdef Flash_512KB_256KB |
|
323 | FMI_Configuration_Register = *(vu16 *)(FMI_BANK_1 + 0x14); |
321 | FMI_Configuration_Register = *(vu16 *)(FMI_BANK_1 + 0x14); |
- | 322 | #endif |
|
324 | 323 | ||
- | 324 | #ifdef Flash_2MB_1MB |
|
- | 325 | FMI_Configuration_Register = *(vu16 *)(FMI_BANK_1 + 0x1C); |
|
- | 326 | #endif |
|
325 | /* Write a read array command */ |
327 | /* Write a read array command */ |
326 | *(vu16 *)FMI_BANK_1 = 0xFF; |
328 | *(vu16 *)FMI_BANK_1 = 0xFF; |
Line 327... | Line 329... | ||
327 | 329 | ||
328 | FMI_Configuration_Register = ((FMI_Configuration_Register>>11) + 1) & 0x3; |
330 | FMI_Configuration_Register = ((FMI_Configuration_Register >> 11) + 1) & 0x3; |
329 | 331 | ||
330 | /* Return the wait states value */ |
332 | /* Return the wait states value */ |
331 | return FMI_Configuration_Register; |
333 | return FMI_Configuration_Register; |
Line 332... | Line 334... | ||
332 | } |
334 | } |
Line 395... | Line 397... | ||
395 | * Function Name : FMI_WriteProtectionCmd |
397 | * Function Name : FMI_WriteProtectionCmd |
396 | * Description : Enable or disable the write protection for the needed sector. |
398 | * Description : Enable or disable the write protection for the needed sector. |
397 | * Input1 : FMI_Sector: specifies the sector to be protected or |
399 | * Input1 : FMI_Sector: specifies the sector to be protected or |
398 | * unprotected. |
400 | * unprotected. |
399 | * This parameter can be one of the following values: |
401 | * This parameter can be one of the following values: |
- | 402 | * |
|
400 | * - FMI_B0S0: FMI bank 0 sector 0. |
403 | * - FMI_B0S0: FMI bank 0 sector 0. |
401 | * - FMI_B0S1: FMI bank 0 sector 1. |
- | |
402 | * - FMI_B0S2: FMI bank 0 sector 2. |
404 | * ... |
403 | * - FMI_B0S3: FMI bank 0 sector 3. |
405 | * - FMI_B0S31: FMI bank 0 sector 31. |
404 | * - FMI_B0S4: FMI bank 0 sector 4. |
- | |
405 | * - FMI_B0S5: FMI bank 0 sector 5. |
- | |
406 | * - FMI_B0S6: FMI bank 0 sector 6. |
- | |
407 | * - FMI_B0S7: FMI bank 0 sector 7. |
- | |
- | 406 | * |
|
- | 407 | * |
|
408 | * - FMI_B1S0: FMI bank 1 sector 0. |
408 | * - FMI_B1S0: FMI bank 1 sector 0. |
409 | * - FMI_B1S1: FMI bank 1 sector 1. |
409 | * ... |
410 | * - FMI_B1S2: FMI bank 1 sector 2. |
410 | * - FMI_B1S7: FMI bank 1 sector 7. |
411 | * - FMI_B1S3: FMI bank 1 sector 3. |
- | |
- | 411 | * |
|
412 | * Input2 : FMI_NewState: specifies the protection status. |
412 | * Input2 : FMI_NewState: specifies the protection status. |
413 | * This parameter can be one of the following values: |
413 | * This parameter can be one of the following values: |
414 | * - ENABLE: Enable the protection. |
414 | * - ENABLE: Enable the protection. |
415 | * - DISABLE: Disable the protection. |
415 | * - DISABLE: Disable the protection. |
416 | * Output : None |
416 | * Output : None |
Line 430... | Line 430... | ||
430 | *(vu16*)FMI_Sector = 0xD0; |
430 | *(vu16*)FMI_Sector = 0xD0; |
431 | *(vu16*)FMI_Sector = 0xFF; |
431 | *(vu16*)FMI_Sector = 0xFF; |
432 | } |
432 | } |
433 | } |
433 | } |
Line 434... | Line -... | ||
434 | - | ||
435 | /******************************************************************************* |
- | |
436 | * Function Name : FMI_GetWriteProtectionStatus |
- | |
437 | * Description : Get the write protection status for the needed sector. |
- | |
438 | * Input : FMI_Sector_Mask: specifies the needed sector mask. |
- | |
439 | * This parameter can be one of the following values: |
- | |
440 | * - FMI_B0S0_MASK: FMI bank 0 sector 0. |
- | |
441 | * - FMI_B0S1_MASK: FMI bank 0 sector 1. |
- | |
442 | * - FMI_B0S2_MASK: FMI bank 0 sector 2. |
- | |
443 | * - FMI_B0S3_MASK: FMI bank 0 sector 3. |
- | |
444 | * - FMI_B0S4_MASK: FMI bank 0 sector 4. |
- | |
445 | * - FMI_B0S5_MASK: FMI bank 0 sector 5. |
- | |
446 | * - FMI_B0S6_MASK: FMI bank 0 sector 6. |
- | |
447 | * - FMI_B0S7_MASK: FMI bank 0 sector 7. |
- | |
448 | * - FMI_B1S0_MASK: FMI bank 1 sector 0. |
- | |
449 | * - FMI_B1S1_MASK: FMI bank 1 sector 1. |
- | |
450 | * - FMI_B1S2_MASK: FMI bank 1 sector 2. |
- | |
451 | * - FMI_B1S3_MASK: FMI bank 1 sector 3. |
- | |
452 | * Output : None |
- | |
453 | * Return : The Protection Status of the needed sector. |
- | |
454 | * - RESET: The needed sector is not write protected. |
- | |
455 | * - SET : The needed sector is write protected. |
- | |
456 | *******************************************************************************/ |
- | |
457 | FlagStatus FMI_GetWriteProtectionStatus(u32 FMI_Sector_Mask) |
- | |
458 | { |
- | |
459 | u16 Protection_Level_1_Register = 0; |
- | |
460 | /* Write a read flash protection level 1 register command */ |
- | |
461 | *(vu16 *)FMI_BANK_1 = 0x90; |
- | |
462 | - | ||
463 | /* Read the flash protection level 1 register */ |
- | |
464 | Protection_Level_1_Register = *(vu16 *)(FMI_BANK_1 + 0x10); |
- | |
465 | - | ||
466 | /* Write a read array command */ |
- | |
467 | *(vu16 *)FMI_BANK_1 = 0xFF; |
- | |
468 | - | ||
469 | if (Protection_Level_1_Register &= FMI_Sector_Mask) |
- | |
470 | { |
- | |
471 | return SET; |
- | |
472 | } |
- | |
473 | else |
- | |
474 | { |
- | |
475 | return RESET; |
- | |
476 | } |
- | |
Line 477... | Line 434... | ||
477 | } |
434 | |
478 | 435 | ||
479 | /******************************************************************************* |
436 | /******************************************************************************* |
480 | * Function Name : FMI_WaitForLastOperation |
437 | * Function Name : FMI_WaitForLastOperation |
Line 514... | Line 471... | ||
514 | { |
471 | { |
515 | return FMI_NO_TIME_OUT_ERROR; |
472 | return FMI_NO_TIME_OUT_ERROR; |
516 | } |
473 | } |
517 | } |
474 | } |
Line -... | Line 475... | ||
- | 475 | ||
- | 476 | /******************************************************************************* |
|
- | 477 | * Function Name : FMI_ReadRSIGData |
|
- | 478 | * Description : Read the Electronic Signature stored in the user configuration |
|
- | 479 | * sector of Bank 1. |
|
- | 480 | * Input : FMI_LSB_RSIGAddress: specifies the low byte of the address |
|
- | 481 | * to select the register. |
|
- | 482 | * This parameter can be one of the following values: |
|
- | 483 | * - FMI_ReadRSIGData_0. |
|
- | 484 | * - FMI_ReadRSIGData_1. |
|
- | 485 | * - FMI_ReadRSIGData_2. |
|
- | 486 | * - FMI_ReadRSIGData_3. |
|
- | 487 | * - FMI_ReadRSIGData_4. |
|
- | 488 | * - FMI_ReadRSIGData_5. |
|
- | 489 | * - FMI_ReadRSIGData_6. |
|
- | 490 | * - FMI_ReadRSIGData_7. |
|
- | 491 | * |
|
- | 492 | * Output : None |
|
- | 493 | * Return : The needed RSIG data. |
|
- | 494 | *******************************************************************************/ |
|
- | 495 | ||
- | 496 | u32 FMI_ReadRSIGData(u8 FMI_LSB_RSIGAddress) |
|
- | 497 | { |
|
- | 498 | u32 RSIG_Data = 0x0; |
|
- | 499 | ||
- | 500 | /*Write a read RSIG command to any word address in Bank1*/ |
|
- | 501 | *(vu16 *)(FMI_BANK_1) = 0x90; |
|
- | 502 | ||
- | 503 | /*Read any RSIG register from any address in Bank1*/ |
|
- | 504 | RSIG_Data = (*(vu32*)(FMI_BANK_1 + (FMI_LSB_RSIGAddress<<2))); |
|
- | 505 | ||
- | 506 | /*write a Read Array command (FFh) to any word address in Bank 1 to*/ |
|
- | 507 | /*return it to Read Array mode.*/ |
|
- | 508 | *(vu16 *)FMI_BANK_1 = 0xFF; |
|
- | 509 | ||
- | 510 | return RSIG_Data; |
|
Line 518... | Line 511... | ||
518 | 511 | } |