STM32F10x Standard Peripherals Library  3.5.0
/opt/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_fsmc.c
Go to the documentation of this file.
00001 
00022 /* Includes ------------------------------------------------------------------*/
00023 #include "stm32f10x_fsmc.h"
00024 #include "stm32f10x_rcc.h"
00025 
00046 /* --------------------- FSMC registers bit mask ---------------------------- */
00047 
00048 /* FSMC BCRx Mask */
00049 #define BCR_MBKEN_Set                       ((uint32_t)0x00000001)
00050 #define BCR_MBKEN_Reset                     ((uint32_t)0x000FFFFE)
00051 #define BCR_FACCEN_Set                      ((uint32_t)0x00000040)
00052 
00053 /* FSMC PCRx Mask */
00054 #define PCR_PBKEN_Set                       ((uint32_t)0x00000004)
00055 #define PCR_PBKEN_Reset                     ((uint32_t)0x000FFFFB)
00056 #define PCR_ECCEN_Set                       ((uint32_t)0x00000040)
00057 #define PCR_ECCEN_Reset                     ((uint32_t)0x000FFFBF)
00058 #define PCR_MemoryType_NAND                 ((uint32_t)0x00000008)
00059 
00102 void FSMC_NORSRAMDeInit(uint32_t FSMC_Bank)
00103 {
00104   /* Check the parameter */
00105   assert_param(IS_FSMC_NORSRAM_BANK(FSMC_Bank));
00106   
00107   /* FSMC_Bank1_NORSRAM1 */
00108   if(FSMC_Bank == FSMC_Bank1_NORSRAM1)
00109   {
00110     FSMC_Bank1->BTCR[FSMC_Bank] = 0x000030DB;    
00111   }
00112   /* FSMC_Bank1_NORSRAM2,  FSMC_Bank1_NORSRAM3 or FSMC_Bank1_NORSRAM4 */
00113   else
00114   {   
00115     FSMC_Bank1->BTCR[FSMC_Bank] = 0x000030D2; 
00116   }
00117   FSMC_Bank1->BTCR[FSMC_Bank + 1] = 0x0FFFFFFF;
00118   FSMC_Bank1E->BWTR[FSMC_Bank] = 0x0FFFFFFF;  
00119 }
00120 
00129 void FSMC_NANDDeInit(uint32_t FSMC_Bank)
00130 {
00131   /* Check the parameter */
00132   assert_param(IS_FSMC_NAND_BANK(FSMC_Bank));
00133   
00134   if(FSMC_Bank == FSMC_Bank2_NAND)
00135   {
00136     /* Set the FSMC_Bank2 registers to their reset values */
00137     FSMC_Bank2->PCR2 = 0x00000018;
00138     FSMC_Bank2->SR2 = 0x00000040;
00139     FSMC_Bank2->PMEM2 = 0xFCFCFCFC;
00140     FSMC_Bank2->PATT2 = 0xFCFCFCFC;  
00141   }
00142   /* FSMC_Bank3_NAND */  
00143   else
00144   {
00145     /* Set the FSMC_Bank3 registers to their reset values */
00146     FSMC_Bank3->PCR3 = 0x00000018;
00147     FSMC_Bank3->SR3 = 0x00000040;
00148     FSMC_Bank3->PMEM3 = 0xFCFCFCFC;
00149     FSMC_Bank3->PATT3 = 0xFCFCFCFC; 
00150   }  
00151 }
00152 
00158 void FSMC_PCCARDDeInit(void)
00159 {
00160   /* Set the FSMC_Bank4 registers to their reset values */
00161   FSMC_Bank4->PCR4 = 0x00000018; 
00162   FSMC_Bank4->SR4 = 0x00000000; 
00163   FSMC_Bank4->PMEM4 = 0xFCFCFCFC;
00164   FSMC_Bank4->PATT4 = 0xFCFCFCFC;
00165   FSMC_Bank4->PIO4 = 0xFCFCFCFC;
00166 }
00167 
00176 void FSMC_NORSRAMInit(FSMC_NORSRAMInitTypeDef* FSMC_NORSRAMInitStruct)
00177 { 
00178   /* Check the parameters */
00179   assert_param(IS_FSMC_NORSRAM_BANK(FSMC_NORSRAMInitStruct->FSMC_Bank));
00180   assert_param(IS_FSMC_MUX(FSMC_NORSRAMInitStruct->FSMC_DataAddressMux));
00181   assert_param(IS_FSMC_MEMORY(FSMC_NORSRAMInitStruct->FSMC_MemoryType));
00182   assert_param(IS_FSMC_MEMORY_WIDTH(FSMC_NORSRAMInitStruct->FSMC_MemoryDataWidth));
00183   assert_param(IS_FSMC_BURSTMODE(FSMC_NORSRAMInitStruct->FSMC_BurstAccessMode));
00184   assert_param(IS_FSMC_ASYNWAIT(FSMC_NORSRAMInitStruct->FSMC_AsynchronousWait));
00185   assert_param(IS_FSMC_WAIT_POLARITY(FSMC_NORSRAMInitStruct->FSMC_WaitSignalPolarity));
00186   assert_param(IS_FSMC_WRAP_MODE(FSMC_NORSRAMInitStruct->FSMC_WrapMode));
00187   assert_param(IS_FSMC_WAIT_SIGNAL_ACTIVE(FSMC_NORSRAMInitStruct->FSMC_WaitSignalActive));
00188   assert_param(IS_FSMC_WRITE_OPERATION(FSMC_NORSRAMInitStruct->FSMC_WriteOperation));
00189   assert_param(IS_FSMC_WAITE_SIGNAL(FSMC_NORSRAMInitStruct->FSMC_WaitSignal));
00190   assert_param(IS_FSMC_EXTENDED_MODE(FSMC_NORSRAMInitStruct->FSMC_ExtendedMode));
00191   assert_param(IS_FSMC_WRITE_BURST(FSMC_NORSRAMInitStruct->FSMC_WriteBurst));  
00192   assert_param(IS_FSMC_ADDRESS_SETUP_TIME(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressSetupTime));
00193   assert_param(IS_FSMC_ADDRESS_HOLD_TIME(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressHoldTime));
00194   assert_param(IS_FSMC_DATASETUP_TIME(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataSetupTime));
00195   assert_param(IS_FSMC_TURNAROUND_TIME(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_BusTurnAroundDuration));
00196   assert_param(IS_FSMC_CLK_DIV(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_CLKDivision));
00197   assert_param(IS_FSMC_DATA_LATENCY(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataLatency));
00198   assert_param(IS_FSMC_ACCESS_MODE(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AccessMode)); 
00199   
00200   /* Bank1 NOR/SRAM control register configuration */ 
00201   FSMC_Bank1->BTCR[FSMC_NORSRAMInitStruct->FSMC_Bank] = 
00202             (uint32_t)FSMC_NORSRAMInitStruct->FSMC_DataAddressMux |
00203             FSMC_NORSRAMInitStruct->FSMC_MemoryType |
00204             FSMC_NORSRAMInitStruct->FSMC_MemoryDataWidth |
00205             FSMC_NORSRAMInitStruct->FSMC_BurstAccessMode |
00206             FSMC_NORSRAMInitStruct->FSMC_AsynchronousWait |
00207             FSMC_NORSRAMInitStruct->FSMC_WaitSignalPolarity |
00208             FSMC_NORSRAMInitStruct->FSMC_WrapMode |
00209             FSMC_NORSRAMInitStruct->FSMC_WaitSignalActive |
00210             FSMC_NORSRAMInitStruct->FSMC_WriteOperation |
00211             FSMC_NORSRAMInitStruct->FSMC_WaitSignal |
00212             FSMC_NORSRAMInitStruct->FSMC_ExtendedMode |
00213             FSMC_NORSRAMInitStruct->FSMC_WriteBurst;
00214 
00215   if(FSMC_NORSRAMInitStruct->FSMC_MemoryType == FSMC_MemoryType_NOR)
00216   {
00217     FSMC_Bank1->BTCR[FSMC_NORSRAMInitStruct->FSMC_Bank] |= (uint32_t)BCR_FACCEN_Set;
00218   }
00219   
00220   /* Bank1 NOR/SRAM timing register configuration */
00221   FSMC_Bank1->BTCR[FSMC_NORSRAMInitStruct->FSMC_Bank+1] = 
00222             (uint32_t)FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressSetupTime |
00223             (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressHoldTime << 4) |
00224             (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataSetupTime << 8) |
00225             (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_BusTurnAroundDuration << 16) |
00226             (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_CLKDivision << 20) |
00227             (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataLatency << 24) |
00228              FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AccessMode;
00229             
00230     
00231   /* Bank1 NOR/SRAM timing register for write configuration, if extended mode is used */
00232   if(FSMC_NORSRAMInitStruct->FSMC_ExtendedMode == FSMC_ExtendedMode_Enable)
00233   {
00234     assert_param(IS_FSMC_ADDRESS_SETUP_TIME(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressSetupTime));
00235     assert_param(IS_FSMC_ADDRESS_HOLD_TIME(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressHoldTime));
00236     assert_param(IS_FSMC_DATASETUP_TIME(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataSetupTime));
00237     assert_param(IS_FSMC_CLK_DIV(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_CLKDivision));
00238     assert_param(IS_FSMC_DATA_LATENCY(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataLatency));
00239     assert_param(IS_FSMC_ACCESS_MODE(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AccessMode));
00240     FSMC_Bank1E->BWTR[FSMC_NORSRAMInitStruct->FSMC_Bank] = 
00241               (uint32_t)FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressSetupTime |
00242               (FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressHoldTime << 4 )|
00243               (FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataSetupTime << 8) |
00244               (FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_CLKDivision << 20) |
00245               (FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataLatency << 24) |
00246                FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AccessMode;
00247   }
00248   else
00249   {
00250     FSMC_Bank1E->BWTR[FSMC_NORSRAMInitStruct->FSMC_Bank] = 0x0FFFFFFF;
00251   }
00252 }
00253 
00262 void FSMC_NANDInit(FSMC_NANDInitTypeDef* FSMC_NANDInitStruct)
00263 {
00264   uint32_t tmppcr = 0x00000000, tmppmem = 0x00000000, tmppatt = 0x00000000; 
00265     
00266   /* Check the parameters */
00267   assert_param( IS_FSMC_NAND_BANK(FSMC_NANDInitStruct->FSMC_Bank));
00268   assert_param( IS_FSMC_WAIT_FEATURE(FSMC_NANDInitStruct->FSMC_Waitfeature));
00269   assert_param( IS_FSMC_MEMORY_WIDTH(FSMC_NANDInitStruct->FSMC_MemoryDataWidth));
00270   assert_param( IS_FSMC_ECC_STATE(FSMC_NANDInitStruct->FSMC_ECC));
00271   assert_param( IS_FSMC_ECCPAGE_SIZE(FSMC_NANDInitStruct->FSMC_ECCPageSize));
00272   assert_param( IS_FSMC_TCLR_TIME(FSMC_NANDInitStruct->FSMC_TCLRSetupTime));
00273   assert_param( IS_FSMC_TAR_TIME(FSMC_NANDInitStruct->FSMC_TARSetupTime));
00274   assert_param(IS_FSMC_SETUP_TIME(FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime));
00275   assert_param(IS_FSMC_WAIT_TIME(FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime));
00276   assert_param(IS_FSMC_HOLD_TIME(FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime));
00277   assert_param(IS_FSMC_HIZ_TIME(FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime));
00278   assert_param(IS_FSMC_SETUP_TIME(FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime));
00279   assert_param(IS_FSMC_WAIT_TIME(FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime));
00280   assert_param(IS_FSMC_HOLD_TIME(FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime));
00281   assert_param(IS_FSMC_HIZ_TIME(FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime));
00282   
00283   /* Set the tmppcr value according to FSMC_NANDInitStruct parameters */
00284   tmppcr = (uint32_t)FSMC_NANDInitStruct->FSMC_Waitfeature |
00285             PCR_MemoryType_NAND |
00286             FSMC_NANDInitStruct->FSMC_MemoryDataWidth |
00287             FSMC_NANDInitStruct->FSMC_ECC |
00288             FSMC_NANDInitStruct->FSMC_ECCPageSize |
00289             (FSMC_NANDInitStruct->FSMC_TCLRSetupTime << 9 )|
00290             (FSMC_NANDInitStruct->FSMC_TARSetupTime << 13);
00291             
00292   /* Set tmppmem value according to FSMC_CommonSpaceTimingStructure parameters */
00293   tmppmem = (uint32_t)FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime |
00294             (FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
00295             (FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
00296             (FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime << 24); 
00297             
00298   /* Set tmppatt value according to FSMC_AttributeSpaceTimingStructure parameters */
00299   tmppatt = (uint32_t)FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime |
00300             (FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
00301             (FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
00302             (FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime << 24);
00303   
00304   if(FSMC_NANDInitStruct->FSMC_Bank == FSMC_Bank2_NAND)
00305   {
00306     /* FSMC_Bank2_NAND registers configuration */
00307     FSMC_Bank2->PCR2 = tmppcr;
00308     FSMC_Bank2->PMEM2 = tmppmem;
00309     FSMC_Bank2->PATT2 = tmppatt;
00310   }
00311   else
00312   {
00313     /* FSMC_Bank3_NAND registers configuration */
00314     FSMC_Bank3->PCR3 = tmppcr;
00315     FSMC_Bank3->PMEM3 = tmppmem;
00316     FSMC_Bank3->PATT3 = tmppatt;
00317   }
00318 }
00319 
00328 void FSMC_PCCARDInit(FSMC_PCCARDInitTypeDef* FSMC_PCCARDInitStruct)
00329 {
00330   /* Check the parameters */
00331   assert_param(IS_FSMC_WAIT_FEATURE(FSMC_PCCARDInitStruct->FSMC_Waitfeature));
00332   assert_param(IS_FSMC_TCLR_TIME(FSMC_PCCARDInitStruct->FSMC_TCLRSetupTime));
00333   assert_param(IS_FSMC_TAR_TIME(FSMC_PCCARDInitStruct->FSMC_TARSetupTime));
00334  
00335   assert_param(IS_FSMC_SETUP_TIME(FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime));
00336   assert_param(IS_FSMC_WAIT_TIME(FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime));
00337   assert_param(IS_FSMC_HOLD_TIME(FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime));
00338   assert_param(IS_FSMC_HIZ_TIME(FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime));
00339   
00340   assert_param(IS_FSMC_SETUP_TIME(FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime));
00341   assert_param(IS_FSMC_WAIT_TIME(FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime));
00342   assert_param(IS_FSMC_HOLD_TIME(FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime));
00343   assert_param(IS_FSMC_HIZ_TIME(FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime));
00344   assert_param(IS_FSMC_SETUP_TIME(FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_SetupTime));
00345   assert_param(IS_FSMC_WAIT_TIME(FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_WaitSetupTime));
00346   assert_param(IS_FSMC_HOLD_TIME(FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HoldSetupTime));
00347   assert_param(IS_FSMC_HIZ_TIME(FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HiZSetupTime));
00348   
00349   /* Set the PCR4 register value according to FSMC_PCCARDInitStruct parameters */
00350   FSMC_Bank4->PCR4 = (uint32_t)FSMC_PCCARDInitStruct->FSMC_Waitfeature |
00351                      FSMC_MemoryDataWidth_16b |  
00352                      (FSMC_PCCARDInitStruct->FSMC_TCLRSetupTime << 9) |
00353                      (FSMC_PCCARDInitStruct->FSMC_TARSetupTime << 13);
00354             
00355   /* Set PMEM4 register value according to FSMC_CommonSpaceTimingStructure parameters */
00356   FSMC_Bank4->PMEM4 = (uint32_t)FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime |
00357                       (FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
00358                       (FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
00359                       (FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime << 24); 
00360             
00361   /* Set PATT4 register value according to FSMC_AttributeSpaceTimingStructure parameters */
00362   FSMC_Bank4->PATT4 = (uint32_t)FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime |
00363                       (FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
00364                       (FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
00365                       (FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime << 24);        
00366             
00367   /* Set PIO4 register value according to FSMC_IOSpaceTimingStructure parameters */
00368   FSMC_Bank4->PIO4 = (uint32_t)FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_SetupTime |
00369                      (FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
00370                      (FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
00371                      (FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HiZSetupTime << 24);             
00372 }
00373 
00380 void FSMC_NORSRAMStructInit(FSMC_NORSRAMInitTypeDef* FSMC_NORSRAMInitStruct)
00381 {  
00382   /* Reset NOR/SRAM Init structure parameters values */
00383   FSMC_NORSRAMInitStruct->FSMC_Bank = FSMC_Bank1_NORSRAM1;
00384   FSMC_NORSRAMInitStruct->FSMC_DataAddressMux = FSMC_DataAddressMux_Enable;
00385   FSMC_NORSRAMInitStruct->FSMC_MemoryType = FSMC_MemoryType_SRAM;
00386   FSMC_NORSRAMInitStruct->FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
00387   FSMC_NORSRAMInitStruct->FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
00388   FSMC_NORSRAMInitStruct->FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
00389   FSMC_NORSRAMInitStruct->FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
00390   FSMC_NORSRAMInitStruct->FSMC_WrapMode = FSMC_WrapMode_Disable;
00391   FSMC_NORSRAMInitStruct->FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
00392   FSMC_NORSRAMInitStruct->FSMC_WriteOperation = FSMC_WriteOperation_Enable;
00393   FSMC_NORSRAMInitStruct->FSMC_WaitSignal = FSMC_WaitSignal_Enable;
00394   FSMC_NORSRAMInitStruct->FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
00395   FSMC_NORSRAMInitStruct->FSMC_WriteBurst = FSMC_WriteBurst_Disable;
00396   FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressSetupTime = 0xF;
00397   FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressHoldTime = 0xF;
00398   FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataSetupTime = 0xFF;
00399   FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_BusTurnAroundDuration = 0xF;
00400   FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_CLKDivision = 0xF;
00401   FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataLatency = 0xF;
00402   FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AccessMode = FSMC_AccessMode_A; 
00403   FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressSetupTime = 0xF;
00404   FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressHoldTime = 0xF;
00405   FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataSetupTime = 0xFF;
00406   FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_BusTurnAroundDuration = 0xF;
00407   FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_CLKDivision = 0xF;
00408   FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataLatency = 0xF;
00409   FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AccessMode = FSMC_AccessMode_A;
00410 }
00411 
00418 void FSMC_NANDStructInit(FSMC_NANDInitTypeDef* FSMC_NANDInitStruct)
00419 { 
00420   /* Reset NAND Init structure parameters values */
00421   FSMC_NANDInitStruct->FSMC_Bank = FSMC_Bank2_NAND;
00422   FSMC_NANDInitStruct->FSMC_Waitfeature = FSMC_Waitfeature_Disable;
00423   FSMC_NANDInitStruct->FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
00424   FSMC_NANDInitStruct->FSMC_ECC = FSMC_ECC_Disable;
00425   FSMC_NANDInitStruct->FSMC_ECCPageSize = FSMC_ECCPageSize_256Bytes;
00426   FSMC_NANDInitStruct->FSMC_TCLRSetupTime = 0x0;
00427   FSMC_NANDInitStruct->FSMC_TARSetupTime = 0x0;
00428   FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime = 0xFC;
00429   FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
00430   FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
00431   FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
00432   FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime = 0xFC;
00433   FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
00434   FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
00435   FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;         
00436 }
00437 
00444 void FSMC_PCCARDStructInit(FSMC_PCCARDInitTypeDef* FSMC_PCCARDInitStruct)
00445 {
00446   /* Reset PCCARD Init structure parameters values */
00447   FSMC_PCCARDInitStruct->FSMC_Waitfeature = FSMC_Waitfeature_Disable;
00448   FSMC_PCCARDInitStruct->FSMC_TCLRSetupTime = 0x0;
00449   FSMC_PCCARDInitStruct->FSMC_TARSetupTime = 0x0;
00450   FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime = 0xFC;
00451   FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
00452   FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
00453   FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
00454   FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime = 0xFC;
00455   FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
00456   FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
00457   FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;     
00458   FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_SetupTime = 0xFC;
00459   FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
00460   FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
00461   FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
00462 }
00463 
00475 void FSMC_NORSRAMCmd(uint32_t FSMC_Bank, FunctionalState NewState)
00476 {
00477   assert_param(IS_FSMC_NORSRAM_BANK(FSMC_Bank));
00478   assert_param(IS_FUNCTIONAL_STATE(NewState));
00479   
00480   if (NewState != DISABLE)
00481   {
00482     /* Enable the selected NOR/SRAM Bank by setting the PBKEN bit in the BCRx register */
00483     FSMC_Bank1->BTCR[FSMC_Bank] |= BCR_MBKEN_Set;
00484   }
00485   else
00486   {
00487     /* Disable the selected NOR/SRAM Bank by clearing the PBKEN bit in the BCRx register */
00488     FSMC_Bank1->BTCR[FSMC_Bank] &= BCR_MBKEN_Reset;
00489   }
00490 }
00491 
00501 void FSMC_NANDCmd(uint32_t FSMC_Bank, FunctionalState NewState)
00502 {
00503   assert_param(IS_FSMC_NAND_BANK(FSMC_Bank));
00504   assert_param(IS_FUNCTIONAL_STATE(NewState));
00505   
00506   if (NewState != DISABLE)
00507   {
00508     /* Enable the selected NAND Bank by setting the PBKEN bit in the PCRx register */
00509     if(FSMC_Bank == FSMC_Bank2_NAND)
00510     {
00511       FSMC_Bank2->PCR2 |= PCR_PBKEN_Set;
00512     }
00513     else
00514     {
00515       FSMC_Bank3->PCR3 |= PCR_PBKEN_Set;
00516     }
00517   }
00518   else
00519   {
00520     /* Disable the selected NAND Bank by clearing the PBKEN bit in the PCRx register */
00521     if(FSMC_Bank == FSMC_Bank2_NAND)
00522     {
00523       FSMC_Bank2->PCR2 &= PCR_PBKEN_Reset;
00524     }
00525     else
00526     {
00527       FSMC_Bank3->PCR3 &= PCR_PBKEN_Reset;
00528     }
00529   }
00530 }
00531 
00538 void FSMC_PCCARDCmd(FunctionalState NewState)
00539 {
00540   assert_param(IS_FUNCTIONAL_STATE(NewState));
00541   
00542   if (NewState != DISABLE)
00543   {
00544     /* Enable the PCCARD Bank by setting the PBKEN bit in the PCR4 register */
00545     FSMC_Bank4->PCR4 |= PCR_PBKEN_Set;
00546   }
00547   else
00548   {
00549     /* Disable the PCCARD Bank by clearing the PBKEN bit in the PCR4 register */
00550     FSMC_Bank4->PCR4 &= PCR_PBKEN_Reset;
00551   }
00552 }
00553 
00564 void FSMC_NANDECCCmd(uint32_t FSMC_Bank, FunctionalState NewState)
00565 {
00566   assert_param(IS_FSMC_NAND_BANK(FSMC_Bank));
00567   assert_param(IS_FUNCTIONAL_STATE(NewState));
00568   
00569   if (NewState != DISABLE)
00570   {
00571     /* Enable the selected NAND Bank ECC function by setting the ECCEN bit in the PCRx register */
00572     if(FSMC_Bank == FSMC_Bank2_NAND)
00573     {
00574       FSMC_Bank2->PCR2 |= PCR_ECCEN_Set;
00575     }
00576     else
00577     {
00578       FSMC_Bank3->PCR3 |= PCR_ECCEN_Set;
00579     }
00580   }
00581   else
00582   {
00583     /* Disable the selected NAND Bank ECC function by clearing the ECCEN bit in the PCRx register */
00584     if(FSMC_Bank == FSMC_Bank2_NAND)
00585     {
00586       FSMC_Bank2->PCR2 &= PCR_ECCEN_Reset;
00587     }
00588     else
00589     {
00590       FSMC_Bank3->PCR3 &= PCR_ECCEN_Reset;
00591     }
00592   }
00593 }
00594 
00603 uint32_t FSMC_GetECC(uint32_t FSMC_Bank)
00604 {
00605   uint32_t eccval = 0x00000000;
00606   
00607   if(FSMC_Bank == FSMC_Bank2_NAND)
00608   {
00609     /* Get the ECCR2 register value */
00610     eccval = FSMC_Bank2->ECCR2;
00611   }
00612   else
00613   {
00614     /* Get the ECCR3 register value */
00615     eccval = FSMC_Bank3->ECCR3;
00616   }
00617   /* Return the error correction code value */
00618   return(eccval);
00619 }
00620 
00637 void FSMC_ITConfig(uint32_t FSMC_Bank, uint32_t FSMC_IT, FunctionalState NewState)
00638 {
00639   assert_param(IS_FSMC_IT_BANK(FSMC_Bank));
00640   assert_param(IS_FSMC_IT(FSMC_IT));    
00641   assert_param(IS_FUNCTIONAL_STATE(NewState));
00642   
00643   if (NewState != DISABLE)
00644   {
00645     /* Enable the selected FSMC_Bank2 interrupts */
00646     if(FSMC_Bank == FSMC_Bank2_NAND)
00647     {
00648       FSMC_Bank2->SR2 |= FSMC_IT;
00649     }
00650     /* Enable the selected FSMC_Bank3 interrupts */
00651     else if (FSMC_Bank == FSMC_Bank3_NAND)
00652     {
00653       FSMC_Bank3->SR3 |= FSMC_IT;
00654     }
00655     /* Enable the selected FSMC_Bank4 interrupts */
00656     else
00657     {
00658       FSMC_Bank4->SR4 |= FSMC_IT;    
00659     }
00660   }
00661   else
00662   {
00663     /* Disable the selected FSMC_Bank2 interrupts */
00664     if(FSMC_Bank == FSMC_Bank2_NAND)
00665     {
00666       
00667       FSMC_Bank2->SR2 &= (uint32_t)~FSMC_IT;
00668     }
00669     /* Disable the selected FSMC_Bank3 interrupts */
00670     else if (FSMC_Bank == FSMC_Bank3_NAND)
00671     {
00672       FSMC_Bank3->SR3 &= (uint32_t)~FSMC_IT;
00673     }
00674     /* Disable the selected FSMC_Bank4 interrupts */
00675     else
00676     {
00677       FSMC_Bank4->SR4 &= (uint32_t)~FSMC_IT;    
00678     }
00679   }
00680 }
00681 
00697 FlagStatus FSMC_GetFlagStatus(uint32_t FSMC_Bank, uint32_t FSMC_FLAG)
00698 {
00699   FlagStatus bitstatus = RESET;
00700   uint32_t tmpsr = 0x00000000;
00701   
00702   /* Check the parameters */
00703   assert_param(IS_FSMC_GETFLAG_BANK(FSMC_Bank));
00704   assert_param(IS_FSMC_GET_FLAG(FSMC_FLAG));
00705   
00706   if(FSMC_Bank == FSMC_Bank2_NAND)
00707   {
00708     tmpsr = FSMC_Bank2->SR2;
00709   }  
00710   else if(FSMC_Bank == FSMC_Bank3_NAND)
00711   {
00712     tmpsr = FSMC_Bank3->SR3;
00713   }
00714   /* FSMC_Bank4_PCCARD*/
00715   else
00716   {
00717     tmpsr = FSMC_Bank4->SR4;
00718   } 
00719   
00720   /* Get the flag status */
00721   if ((tmpsr & FSMC_FLAG) != (uint16_t)RESET )
00722   {
00723     bitstatus = SET;
00724   }
00725   else
00726   {
00727     bitstatus = RESET;
00728   }
00729   /* Return the flag status */
00730   return bitstatus;
00731 }
00732 
00747 void FSMC_ClearFlag(uint32_t FSMC_Bank, uint32_t FSMC_FLAG)
00748 {
00749  /* Check the parameters */
00750   assert_param(IS_FSMC_GETFLAG_BANK(FSMC_Bank));
00751   assert_param(IS_FSMC_CLEAR_FLAG(FSMC_FLAG)) ;
00752     
00753   if(FSMC_Bank == FSMC_Bank2_NAND)
00754   {
00755     FSMC_Bank2->SR2 &= ~FSMC_FLAG; 
00756   }  
00757   else if(FSMC_Bank == FSMC_Bank3_NAND)
00758   {
00759     FSMC_Bank3->SR3 &= ~FSMC_FLAG;
00760   }
00761   /* FSMC_Bank4_PCCARD*/
00762   else
00763   {
00764     FSMC_Bank4->SR4 &= ~FSMC_FLAG;
00765   }
00766 }
00767 
00782 ITStatus FSMC_GetITStatus(uint32_t FSMC_Bank, uint32_t FSMC_IT)
00783 {
00784   ITStatus bitstatus = RESET;
00785   uint32_t tmpsr = 0x0, itstatus = 0x0, itenable = 0x0; 
00786   
00787   /* Check the parameters */
00788   assert_param(IS_FSMC_IT_BANK(FSMC_Bank));
00789   assert_param(IS_FSMC_GET_IT(FSMC_IT));
00790   
00791   if(FSMC_Bank == FSMC_Bank2_NAND)
00792   {
00793     tmpsr = FSMC_Bank2->SR2;
00794   }  
00795   else if(FSMC_Bank == FSMC_Bank3_NAND)
00796   {
00797     tmpsr = FSMC_Bank3->SR3;
00798   }
00799   /* FSMC_Bank4_PCCARD*/
00800   else
00801   {
00802     tmpsr = FSMC_Bank4->SR4;
00803   } 
00804   
00805   itstatus = tmpsr & FSMC_IT;
00806   
00807   itenable = tmpsr & (FSMC_IT >> 3);
00808   if ((itstatus != (uint32_t)RESET)  && (itenable != (uint32_t)RESET))
00809   {
00810     bitstatus = SET;
00811   }
00812   else
00813   {
00814     bitstatus = RESET;
00815   }
00816   return bitstatus; 
00817 }
00818 
00833 void FSMC_ClearITPendingBit(uint32_t FSMC_Bank, uint32_t FSMC_IT)
00834 {
00835   /* Check the parameters */
00836   assert_param(IS_FSMC_IT_BANK(FSMC_Bank));
00837   assert_param(IS_FSMC_IT(FSMC_IT));
00838     
00839   if(FSMC_Bank == FSMC_Bank2_NAND)
00840   {
00841     FSMC_Bank2->SR2 &= ~(FSMC_IT >> 3); 
00842   }  
00843   else if(FSMC_Bank == FSMC_Bank3_NAND)
00844   {
00845     FSMC_Bank3->SR3 &= ~(FSMC_IT >> 3);
00846   }
00847   /* FSMC_Bank4_PCCARD*/
00848   else
00849   {
00850     FSMC_Bank4->SR4 &= ~(FSMC_IT >> 3);
00851   }
00852 }
00853 
00866 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/