stm32f4xx_fmc.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_fmc.c
  4. * @author MCD Application Team
  5. * @version V1.8.0
  6. * @date 04-November-2016
  7. * @brief This file provides firmware functions to manage the following
  8. * functionalities of the FMC peripheral:
  9. * + Interface with SRAM, PSRAM, NOR and OneNAND memories
  10. * + Interface with NAND memories
  11. * + Interface with 16-bit PC Card compatible memories
  12. * + Interface with SDRAM memories
  13. * + Interrupts and flags management
  14. *
  15. ******************************************************************************
  16. * @attention
  17. *
  18. * <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
  19. *
  20. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  21. * You may not use this file except in compliance with the License.
  22. * You may obtain a copy of the License at:
  23. *
  24. * http://www.st.com/software_license_agreement_liberty_v2
  25. *
  26. * Unless required by applicable law or agreed to in writing, software
  27. * distributed under the License is distributed on an "AS IS" BASIS,
  28. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  29. * See the License for the specific language governing permissions and
  30. * limitations under the License.
  31. *
  32. ******************************************************************************
  33. */
  34. /* Includes ------------------------------------------------------------------*/
  35. #include "stm32f4xx_fmc.h"
  36. #include "stm32f4xx_rcc.h"
  37. /** @addtogroup STM32F4xx_StdPeriph_Driver
  38. * @{
  39. */
  40. /** @defgroup FMC
  41. * @brief FMC driver modules
  42. * @{
  43. */
  44. /* Private typedef -----------------------------------------------------------*/
  45. const FMC_NORSRAMTimingInitTypeDef FMC_DefaultTimingStruct = {0x0F, /* FMC_AddressSetupTime */
  46. 0x0F, /* FMC_AddressHoldTime */
  47. 0xFF, /* FMC_DataSetupTime */
  48. 0x0F, /* FMC_BusTurnAroundDuration */
  49. 0x0F, /* FMC_CLKDivision */
  50. 0x0F, /* FMC_DataLatency */
  51. FMC_AccessMode_A /* FMC_AccessMode */
  52. };
  53. /* --------------------- FMC registers bit mask ---------------------------- */
  54. /* FMC BCRx Mask */
  55. #define BCR_MBKEN_SET ((uint32_t)0x00000001)
  56. #define BCR_MBKEN_RESET ((uint32_t)0x000FFFFE)
  57. #define BCR_FACCEN_SET ((uint32_t)0x00000040)
  58. /* FMC PCRx Mask */
  59. #define PCR_PBKEN_SET ((uint32_t)0x00000004)
  60. #define PCR_PBKEN_RESET ((uint32_t)0x000FFFFB)
  61. #define PCR_ECCEN_SET ((uint32_t)0x00000040)
  62. #define PCR_ECCEN_RESET ((uint32_t)0x000FFFBF)
  63. #define PCR_MEMORYTYPE_NAND ((uint32_t)0x00000008)
  64. /* FMC SDCRx write protection Mask*/
  65. #define SDCR_WriteProtection_RESET ((uint32_t)0x00007DFF)
  66. /* FMC SDCMR Mask*/
  67. #define SDCMR_CTB1_RESET ((uint32_t)0x003FFFEF)
  68. #define SDCMR_CTB2_RESET ((uint32_t)0x003FFFF7)
  69. #define SDCMR_CTB1_2_RESET ((uint32_t)0x003FFFE7)
  70. /* Private macro -------------------------------------------------------------*/
  71. /* Private variables ---------------------------------------------------------*/
  72. /* Private function prototypes -----------------------------------------------*/
  73. /* Private functions ---------------------------------------------------------*/
  74. /** @defgroup FMC_Private_Functions
  75. * @{
  76. */
  77. /** @defgroup FMC_Group1 NOR/SRAM Controller functions
  78. * @brief NOR/SRAM Controller functions
  79. *
  80. @verbatim
  81. ===============================================================================
  82. ##### NOR and SRAM Controller functions #####
  83. ===============================================================================
  84. [..] The following sequence should be followed to configure the FMC to interface
  85. with SRAM, PSRAM, NOR or OneNAND memory connected to the NOR/SRAM Bank:
  86. (#) Enable the clock for the FMC and associated GPIOs using the following functions:
  87. RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FMC, ENABLE);
  88. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE);
  89. (#) FMC pins configuration
  90. (++) Connect the involved FMC pins to AF12 using the following function
  91. GPIO_PinAFConfig(GPIOx, GPIO_PinSourcex, GPIO_AF_FMC);
  92. (++) Configure these FMC pins in alternate function mode by calling the function
  93. GPIO_Init();
  94. (#) Declare a FMC_NORSRAMInitTypeDef structure, for example:
  95. FMC_NORSRAMInitTypeDef FMC_NORSRAMInitStructure;
  96. and fill the FMC_NORSRAMInitStructure variable with the allowed values of
  97. the structure member.
  98. (#) Initialize the NOR/SRAM Controller by calling the function
  99. FMC_NORSRAMInit(&FMC_NORSRAMInitStructure);
  100. (#) Then enable the NOR/SRAM Bank, for example:
  101. FMC_NORSRAMCmd(FMC_Bank1_NORSRAM2, ENABLE);
  102. (#) At this stage you can read/write from/to the memory connected to the NOR/SRAM Bank.
  103. @endverbatim
  104. * @{
  105. */
  106. /**
  107. * @brief De-initializes the FMC NOR/SRAM Banks registers to their default
  108. * reset values.
  109. * @param FMC_Bank: specifies the FMC Bank to be used
  110. * This parameter can be one of the following values:
  111. * @arg FMC_Bank1_NORSRAM1: FMC Bank1 NOR/SRAM1
  112. * @arg FMC_Bank1_NORSRAM2: FMC Bank1 NOR/SRAM2
  113. * @arg FMC_Bank1_NORSRAM3: FMC Bank1 NOR/SRAM3
  114. * @arg FMC_Bank1_NORSRAM4: FMC Bank1 NOR/SRAM4
  115. * @retval None
  116. */
  117. void FMC_NORSRAMDeInit(uint32_t FMC_Bank)
  118. {
  119. /* Check the parameter */
  120. assert_param(IS_FMC_NORSRAM_BANK(FMC_Bank));
  121. /* FMC_Bank1_NORSRAM1 */
  122. if(FMC_Bank == FMC_Bank1_NORSRAM1)
  123. {
  124. FMC_Bank1->BTCR[FMC_Bank] = 0x000030DB;
  125. }
  126. /* FMC_Bank1_NORSRAM2, FMC_Bank1_NORSRAM3 or FMC_Bank1_NORSRAM4 */
  127. else
  128. {
  129. FMC_Bank1->BTCR[FMC_Bank] = 0x000030D2;
  130. }
  131. FMC_Bank1->BTCR[FMC_Bank + 1] = 0x0FFFFFFF;
  132. FMC_Bank1E->BWTR[FMC_Bank] = 0x0FFFFFFF;
  133. }
  134. /**
  135. * @brief Initializes the FMC NOR/SRAM Banks according to the specified
  136. * parameters in the FMC_NORSRAMInitStruct.
  137. * @param FMC_NORSRAMInitStruct : pointer to a FMC_NORSRAMInitTypeDef structure
  138. * that contains the configuration information for the FMC NOR/SRAM
  139. * specified Banks.
  140. * @retval None
  141. */
  142. void FMC_NORSRAMInit(FMC_NORSRAMInitTypeDef* FMC_NORSRAMInitStruct)
  143. {
  144. uint32_t tmpr = 0, tmpbcr = 0, tmpbwr = 0;
  145. /* Check the parameters */
  146. assert_param(IS_FMC_NORSRAM_BANK(FMC_NORSRAMInitStruct->FMC_Bank));
  147. assert_param(IS_FMC_MUX(FMC_NORSRAMInitStruct->FMC_DataAddressMux));
  148. assert_param(IS_FMC_MEMORY(FMC_NORSRAMInitStruct->FMC_MemoryType));
  149. assert_param(IS_FMC_NORSRAM_MEMORY_WIDTH(FMC_NORSRAMInitStruct->FMC_MemoryDataWidth));
  150. assert_param(IS_FMC_BURSTMODE(FMC_NORSRAMInitStruct->FMC_BurstAccessMode));
  151. assert_param(IS_FMC_WAIT_POLARITY(FMC_NORSRAMInitStruct->FMC_WaitSignalPolarity));
  152. assert_param(IS_FMC_WRAP_MODE(FMC_NORSRAMInitStruct->FMC_WrapMode));
  153. assert_param(IS_FMC_WAIT_SIGNAL_ACTIVE(FMC_NORSRAMInitStruct->FMC_WaitSignalActive));
  154. assert_param(IS_FMC_WRITE_OPERATION(FMC_NORSRAMInitStruct->FMC_WriteOperation));
  155. assert_param(IS_FMC_WAITE_SIGNAL(FMC_NORSRAMInitStruct->FMC_WaitSignal));
  156. assert_param(IS_FMC_EXTENDED_MODE(FMC_NORSRAMInitStruct->FMC_ExtendedMode));
  157. assert_param(IS_FMC_ASYNWAIT(FMC_NORSRAMInitStruct->FMC_AsynchronousWait));
  158. assert_param(IS_FMC_WRITE_BURST(FMC_NORSRAMInitStruct->FMC_WriteBurst));
  159. assert_param(IS_FMC_CONTINOUS_CLOCK(FMC_NORSRAMInitStruct->FMC_ContinousClock));
  160. assert_param(IS_FMC_ADDRESS_SETUP_TIME(FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_AddressSetupTime));
  161. assert_param(IS_FMC_ADDRESS_HOLD_TIME(FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_AddressHoldTime));
  162. assert_param(IS_FMC_DATASETUP_TIME(FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_DataSetupTime));
  163. assert_param(IS_FMC_TURNAROUND_TIME(FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_BusTurnAroundDuration));
  164. assert_param(IS_FMC_CLK_DIV(FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_CLKDivision));
  165. assert_param(IS_FMC_DATA_LATENCY(FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_DataLatency));
  166. assert_param(IS_FMC_ACCESS_MODE(FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_AccessMode));
  167. /* Get the BTCR register value */
  168. tmpbcr = FMC_Bank1->BTCR[FMC_NORSRAMInitStruct->FMC_Bank];
  169. /* Clear MBKEN, MUXEN, MTYP, MWID, FACCEN, BURSTEN, WAITPOL, WRAPMOD, WAITCFG, WREN,
  170. WAITEN, EXTMOD, ASYNCWAIT, CBURSTRW and CCLKEN bits */
  171. tmpbcr &= ((uint32_t)~(FMC_BCR1_MBKEN | FMC_BCR1_MUXEN | FMC_BCR1_MTYP | \
  172. FMC_BCR1_MWID | FMC_BCR1_FACCEN | FMC_BCR1_BURSTEN | \
  173. FMC_BCR1_WAITPOL | FMC_BCR1_WRAPMOD | FMC_BCR1_WAITCFG | \
  174. FMC_BCR1_WREN | FMC_BCR1_WAITEN | FMC_BCR1_EXTMOD | \
  175. FMC_BCR1_ASYNCWAIT| FMC_BCR1_CBURSTRW | FMC_BCR1_CCLKEN));
  176. /* NOR/SRAM Bank control register configuration */
  177. tmpbcr |= (uint32_t)FMC_NORSRAMInitStruct->FMC_DataAddressMux |
  178. FMC_NORSRAMInitStruct->FMC_MemoryType |
  179. FMC_NORSRAMInitStruct->FMC_MemoryDataWidth |
  180. FMC_NORSRAMInitStruct->FMC_BurstAccessMode |
  181. FMC_NORSRAMInitStruct->FMC_WaitSignalPolarity |
  182. FMC_NORSRAMInitStruct->FMC_WrapMode |
  183. FMC_NORSRAMInitStruct->FMC_WaitSignalActive |
  184. FMC_NORSRAMInitStruct->FMC_WriteOperation |
  185. FMC_NORSRAMInitStruct->FMC_WaitSignal |
  186. FMC_NORSRAMInitStruct->FMC_ExtendedMode |
  187. FMC_NORSRAMInitStruct->FMC_AsynchronousWait |
  188. FMC_NORSRAMInitStruct->FMC_WriteBurst |
  189. FMC_NORSRAMInitStruct->FMC_ContinousClock;
  190. FMC_Bank1->BTCR[FMC_NORSRAMInitStruct->FMC_Bank] = tmpbcr;
  191. if(FMC_NORSRAMInitStruct->FMC_MemoryType == FMC_MemoryType_NOR)
  192. {
  193. FMC_Bank1->BTCR[FMC_NORSRAMInitStruct->FMC_Bank] |= (uint32_t)BCR_FACCEN_SET;
  194. }
  195. /* Configure Continuous clock feature when bank2..4 is used */
  196. if((FMC_NORSRAMInitStruct->FMC_ContinousClock == FMC_CClock_SyncAsync) && (FMC_NORSRAMInitStruct->FMC_Bank != FMC_Bank1_NORSRAM1))
  197. {
  198. tmpr = (uint32_t)((FMC_Bank1->BTCR[FMC_Bank1_NORSRAM1+1]) & ~(((uint32_t)0x0F) << 20));
  199. FMC_Bank1->BTCR[FMC_Bank1_NORSRAM1] |= FMC_NORSRAMInitStruct->FMC_ContinousClock;
  200. FMC_Bank1->BTCR[FMC_Bank1_NORSRAM1] |= FMC_BurstAccessMode_Enable;
  201. FMC_Bank1->BTCR[FMC_Bank1_NORSRAM1+1] = (uint32_t)(tmpr | (((FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_CLKDivision)-1) << 20));
  202. }
  203. /* NOR/SRAM Bank timing register configuration */
  204. FMC_Bank1->BTCR[FMC_NORSRAMInitStruct->FMC_Bank+1] =
  205. (uint32_t)FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_AddressSetupTime |
  206. (FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_AddressHoldTime << 4) |
  207. (FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_DataSetupTime << 8) |
  208. (FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_BusTurnAroundDuration << 16) |
  209. (FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_CLKDivision << 20) |
  210. (FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_DataLatency << 24) |
  211. FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_AccessMode;
  212. /* NOR/SRAM Bank timing register for write configuration, if extended mode is used */
  213. if(FMC_NORSRAMInitStruct->FMC_ExtendedMode == FMC_ExtendedMode_Enable)
  214. {
  215. assert_param(IS_FMC_ADDRESS_SETUP_TIME(FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_AddressSetupTime));
  216. assert_param(IS_FMC_ADDRESS_HOLD_TIME(FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_AddressHoldTime));
  217. assert_param(IS_FMC_DATASETUP_TIME(FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_DataSetupTime));
  218. assert_param(IS_FMC_TURNAROUND_TIME(FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_BusTurnAroundDuration));
  219. assert_param(IS_FMC_ACCESS_MODE(FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_AccessMode));
  220. /* Get the BWTR register value */
  221. tmpbwr = FMC_Bank1E->BWTR[FMC_NORSRAMInitStruct->FMC_Bank];
  222. /* Clear ADDSET, ADDHLD, DATAST, BUSTURN and ACCMOD bits */
  223. tmpbwr &= ((uint32_t)~(FMC_BWTR1_ADDSET | FMC_BWTR1_ADDHLD | FMC_BWTR1_DATAST | \
  224. FMC_BWTR1_BUSTURN | FMC_BWTR1_ACCMOD));
  225. tmpbwr |= (uint32_t)(FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_AddressSetupTime |
  226. (FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_AddressHoldTime << 4)|
  227. (FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_DataSetupTime << 8) |
  228. (FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_BusTurnAroundDuration << 16) |
  229. FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_AccessMode);
  230. FMC_Bank1E->BWTR[FMC_NORSRAMInitStruct->FMC_Bank] = tmpbwr;
  231. }
  232. else
  233. {
  234. FMC_Bank1E->BWTR[FMC_NORSRAMInitStruct->FMC_Bank] = 0x0FFFFFFF;
  235. }
  236. }
  237. /**
  238. * @brief Fills each FMC_NORSRAMInitStruct member with its default value.
  239. * @param FMC_NORSRAMInitStruct: pointer to a FMC_NORSRAMInitTypeDef structure
  240. * which will be initialized.
  241. * @retval None
  242. */
  243. void FMC_NORSRAMStructInit(FMC_NORSRAMInitTypeDef* FMC_NORSRAMInitStruct)
  244. {
  245. /* Reset NOR/SRAM Init structure parameters values */
  246. FMC_NORSRAMInitStruct->FMC_Bank = FMC_Bank1_NORSRAM1;
  247. FMC_NORSRAMInitStruct->FMC_DataAddressMux = FMC_DataAddressMux_Enable;
  248. FMC_NORSRAMInitStruct->FMC_MemoryType = FMC_MemoryType_SRAM;
  249. FMC_NORSRAMInitStruct->FMC_MemoryDataWidth = FMC_NORSRAM_MemoryDataWidth_16b;
  250. FMC_NORSRAMInitStruct->FMC_BurstAccessMode = FMC_BurstAccessMode_Disable;
  251. FMC_NORSRAMInitStruct->FMC_AsynchronousWait = FMC_AsynchronousWait_Disable;
  252. FMC_NORSRAMInitStruct->FMC_WaitSignalPolarity = FMC_WaitSignalPolarity_Low;
  253. FMC_NORSRAMInitStruct->FMC_WrapMode = FMC_WrapMode_Disable;
  254. FMC_NORSRAMInitStruct->FMC_WaitSignalActive = FMC_WaitSignalActive_BeforeWaitState;
  255. FMC_NORSRAMInitStruct->FMC_WriteOperation = FMC_WriteOperation_Enable;
  256. FMC_NORSRAMInitStruct->FMC_WaitSignal = FMC_WaitSignal_Enable;
  257. FMC_NORSRAMInitStruct->FMC_ExtendedMode = FMC_ExtendedMode_Disable;
  258. FMC_NORSRAMInitStruct->FMC_WriteBurst = FMC_WriteBurst_Disable;
  259. FMC_NORSRAMInitStruct->FMC_ContinousClock = FMC_CClock_SyncOnly;
  260. FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct = (FMC_NORSRAMTimingInitTypeDef*)((uint32_t)&FMC_DefaultTimingStruct);
  261. FMC_NORSRAMInitStruct->FMC_WriteTimingStruct = (FMC_NORSRAMTimingInitTypeDef*)((uint32_t)&FMC_DefaultTimingStruct);
  262. }
  263. /**
  264. * @brief Enables or disables the specified NOR/SRAM Memory Bank.
  265. * @param FMC_Bank: specifies the FMC Bank to be used
  266. * This parameter can be one of the following values:
  267. * @arg FMC_Bank1_NORSRAM1: FMC Bank1 NOR/SRAM1
  268. * @arg FMC_Bank1_NORSRAM2: FMC Bank1 NOR/SRAM2
  269. * @arg FMC_Bank1_NORSRAM3: FMC Bank1 NOR/SRAM3
  270. * @arg FMC_Bank1_NORSRAM4: FMC Bank1 NOR/SRAM4
  271. * @param NewState: new state of the FMC_Bank. This parameter can be: ENABLE or DISABLE.
  272. * @retval None
  273. */
  274. void FMC_NORSRAMCmd(uint32_t FMC_Bank, FunctionalState NewState)
  275. {
  276. assert_param(IS_FMC_NORSRAM_BANK(FMC_Bank));
  277. assert_param(IS_FUNCTIONAL_STATE(NewState));
  278. if (NewState != DISABLE)
  279. {
  280. /* Enable the selected NOR/SRAM Bank by setting the PBKEN bit in the BCRx register */
  281. FMC_Bank1->BTCR[FMC_Bank] |= BCR_MBKEN_SET;
  282. }
  283. else
  284. {
  285. /* Disable the selected NOR/SRAM Bank by clearing the PBKEN bit in the BCRx register */
  286. FMC_Bank1->BTCR[FMC_Bank] &= BCR_MBKEN_RESET;
  287. }
  288. }
  289. /**
  290. * @}
  291. */
  292. /** @defgroup FMC_Group2 NAND Controller functions
  293. * @brief NAND Controller functions
  294. *
  295. @verbatim
  296. ===============================================================================
  297. ##### NAND Controller functions #####
  298. ===============================================================================
  299. [..] The following sequence should be followed to configure the FMC to interface
  300. with 8-bit or 16-bit NAND memory connected to the NAND Bank:
  301. (#) Enable the clock for the FMC and associated GPIOs using the following functions:
  302. (++) RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FMC, ENABLE);
  303. (++) RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE);
  304. (#) FMC pins configuration
  305. (++) Connect the involved FMC pins to AF12 using the following function
  306. GPIO_PinAFConfig(GPIOx, GPIO_PinSourcex, GPIO_AF_FMC);
  307. (++) Configure these FMC pins in alternate function mode by calling the function
  308. GPIO_Init();
  309. (#) Declare a FMC_NANDInitTypeDef structure, for example:
  310. FMC_NANDInitTypeDef FMC_NANDInitStructure;
  311. and fill the FMC_NANDInitStructure variable with the allowed values of
  312. the structure member.
  313. (#) Initialize the NAND Controller by calling the function
  314. FMC_NANDInit(&FMC_NANDInitStructure);
  315. (#) Then enable the NAND Bank, for example:
  316. FMC_NANDCmd(FMC_Bank3_NAND, ENABLE);
  317. (#) At this stage you can read/write from/to the memory connected to the NAND Bank.
  318. [..]
  319. (@) To enable the Error Correction Code (ECC), you have to use the function
  320. FMC_NANDECCCmd(FMC_Bank3_NAND, ENABLE);
  321. [..]
  322. (@) and to get the current ECC value you have to use the function
  323. ECCval = FMC_GetECC(FMC_Bank3_NAND);
  324. @endverbatim
  325. * @{
  326. */
  327. /**
  328. * @brief De-initializes the FMC NAND Banks registers to their default reset values.
  329. * @param FMC_Bank: specifies the FMC Bank to be used
  330. * This parameter can be one of the following values:
  331. * @arg FMC_Bank2_NAND: FMC Bank2 NAND
  332. * @arg FMC_Bank3_NAND: FMC Bank3 NAND
  333. * @retval None
  334. */
  335. void FMC_NANDDeInit(uint32_t FMC_Bank)
  336. {
  337. /* Check the parameter */
  338. assert_param(IS_FMC_NAND_BANK(FMC_Bank));
  339. if(FMC_Bank == FMC_Bank2_NAND)
  340. {
  341. /* Set the FMC_Bank2 registers to their reset values */
  342. FMC_Bank2->PCR2 = 0x00000018;
  343. FMC_Bank2->SR2 = 0x00000040;
  344. FMC_Bank2->PMEM2 = 0xFCFCFCFC;
  345. FMC_Bank2->PATT2 = 0xFCFCFCFC;
  346. }
  347. /* FMC_Bank3_NAND */
  348. else
  349. {
  350. /* Set the FMC_Bank3 registers to their reset values */
  351. FMC_Bank3->PCR3 = 0x00000018;
  352. FMC_Bank3->SR3 = 0x00000040;
  353. FMC_Bank3->PMEM3 = 0xFCFCFCFC;
  354. FMC_Bank3->PATT3 = 0xFCFCFCFC;
  355. }
  356. }
  357. /**
  358. * @brief Initializes the FMC NAND Banks according to the specified parameters
  359. * in the FMC_NANDInitStruct.
  360. * @param FMC_NANDInitStruct : pointer to a FMC_NANDInitTypeDef structure that
  361. * contains the configuration information for the FMC NAND specified Banks.
  362. * @retval None
  363. */
  364. void FMC_NANDInit(FMC_NANDInitTypeDef* FMC_NANDInitStruct)
  365. {
  366. uint32_t tmppcr = 0x00000000, tmppmem = 0x00000000, tmppatt = 0x00000000;
  367. /* Check the parameters */
  368. assert_param(IS_FMC_NAND_BANK(FMC_NANDInitStruct->FMC_Bank));
  369. assert_param(IS_FMC_WAIT_FEATURE(FMC_NANDInitStruct->FMC_Waitfeature));
  370. assert_param(IS_FMC_NAND_MEMORY_WIDTH(FMC_NANDInitStruct->FMC_MemoryDataWidth));
  371. assert_param(IS_FMC_ECC_STATE(FMC_NANDInitStruct->FMC_ECC));
  372. assert_param(IS_FMC_ECCPAGE_SIZE(FMC_NANDInitStruct->FMC_ECCPageSize));
  373. assert_param(IS_FMC_TCLR_TIME(FMC_NANDInitStruct->FMC_TCLRSetupTime));
  374. assert_param(IS_FMC_TAR_TIME(FMC_NANDInitStruct->FMC_TARSetupTime));
  375. assert_param(IS_FMC_SETUP_TIME(FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_SetupTime));
  376. assert_param(IS_FMC_WAIT_TIME(FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_WaitSetupTime));
  377. assert_param(IS_FMC_HOLD_TIME(FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HoldSetupTime));
  378. assert_param(IS_FMC_HIZ_TIME(FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HiZSetupTime));
  379. assert_param(IS_FMC_SETUP_TIME(FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_SetupTime));
  380. assert_param(IS_FMC_WAIT_TIME(FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_WaitSetupTime));
  381. assert_param(IS_FMC_HOLD_TIME(FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HoldSetupTime));
  382. assert_param(IS_FMC_HIZ_TIME(FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HiZSetupTime));
  383. if(FMC_NANDInitStruct->FMC_Bank == FMC_Bank2_NAND)
  384. {
  385. /* Get the NAND bank 2 register value */
  386. tmppcr = FMC_Bank2->PCR2;
  387. }
  388. else
  389. {
  390. /* Get the NAND bank 3 register value */
  391. tmppcr = FMC_Bank3->PCR3;
  392. }
  393. /* Clear PWAITEN, PBKEN, PTYP, PWID, ECCEN, TCLR, TAR and ECCPS bits */
  394. tmppcr &= ((uint32_t)~(FMC_PCR2_PWAITEN | FMC_PCR2_PBKEN | FMC_PCR2_PTYP | \
  395. FMC_PCR2_PWID | FMC_PCR2_ECCEN | FMC_PCR2_TCLR | \
  396. FMC_PCR2_TAR | FMC_PCR2_ECCPS));
  397. /* Set the tmppcr value according to FMC_NANDInitStruct parameters */
  398. tmppcr |= (uint32_t)FMC_NANDInitStruct->FMC_Waitfeature |
  399. PCR_MEMORYTYPE_NAND |
  400. FMC_NANDInitStruct->FMC_MemoryDataWidth |
  401. FMC_NANDInitStruct->FMC_ECC |
  402. FMC_NANDInitStruct->FMC_ECCPageSize |
  403. (FMC_NANDInitStruct->FMC_TCLRSetupTime << 9 )|
  404. (FMC_NANDInitStruct->FMC_TARSetupTime << 13);
  405. if(FMC_NANDInitStruct->FMC_Bank == FMC_Bank2_NAND)
  406. {
  407. /* Get the NAND bank 2 register value */
  408. tmppmem = FMC_Bank2->PMEM2;
  409. }
  410. else
  411. {
  412. /* Get the NAND bank 3 register value */
  413. tmppmem = FMC_Bank3->PMEM3;
  414. }
  415. /* Clear MEMSETx, MEMWAITx, MEMHOLDx and MEMHIZx bits */
  416. tmppmem &= ((uint32_t)~(FMC_PMEM2_MEMSET2 | FMC_PMEM2_MEMWAIT2 | FMC_PMEM2_MEMHOLD2 | \
  417. FMC_PMEM2_MEMHIZ2));
  418. /* Set tmppmem value according to FMC_CommonSpaceTimingStructure parameters */
  419. tmppmem |= (uint32_t)FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_SetupTime |
  420. (FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_WaitSetupTime << 8) |
  421. (FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HoldSetupTime << 16)|
  422. (FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HiZSetupTime << 24);
  423. if(FMC_NANDInitStruct->FMC_Bank == FMC_Bank2_NAND)
  424. {
  425. /* Get the NAND bank 2 register value */
  426. tmppatt = FMC_Bank2->PATT2;
  427. }
  428. else
  429. {
  430. /* Get the NAND bank 3 register value */
  431. tmppatt = FMC_Bank3->PATT3;
  432. }
  433. /* Clear ATTSETx, ATTWAITx, ATTHOLDx and ATTHIZx bits */
  434. tmppatt &= ((uint32_t)~(FMC_PATT2_ATTSET2 | FMC_PATT2_ATTWAIT2 | FMC_PATT2_ATTHOLD2 | \
  435. FMC_PATT2_ATTHIZ2));
  436. /* Set tmppatt value according to FMC_AttributeSpaceTimingStructure parameters */
  437. tmppatt |= (uint32_t)FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_SetupTime |
  438. (FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_WaitSetupTime << 8) |
  439. (FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HoldSetupTime << 16)|
  440. (FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HiZSetupTime << 24);
  441. if(FMC_NANDInitStruct->FMC_Bank == FMC_Bank2_NAND)
  442. {
  443. /* FMC_Bank2_NAND registers configuration */
  444. FMC_Bank2->PCR2 = tmppcr;
  445. FMC_Bank2->PMEM2 = tmppmem;
  446. FMC_Bank2->PATT2 = tmppatt;
  447. }
  448. else
  449. {
  450. /* FMC_Bank3_NAND registers configuration */
  451. FMC_Bank3->PCR3 = tmppcr;
  452. FMC_Bank3->PMEM3 = tmppmem;
  453. FMC_Bank3->PATT3 = tmppatt;
  454. }
  455. }
  456. /**
  457. * @brief Fills each FMC_NANDInitStruct member with its default value.
  458. * @param FMC_NANDInitStruct: pointer to a FMC_NANDInitTypeDef structure which
  459. * will be initialized.
  460. * @retval None
  461. */
  462. void FMC_NANDStructInit(FMC_NANDInitTypeDef* FMC_NANDInitStruct)
  463. {
  464. /* Reset NAND Init structure parameters values */
  465. FMC_NANDInitStruct->FMC_Bank = FMC_Bank2_NAND;
  466. FMC_NANDInitStruct->FMC_Waitfeature = FMC_Waitfeature_Disable;
  467. FMC_NANDInitStruct->FMC_MemoryDataWidth = FMC_NAND_MemoryDataWidth_16b;
  468. FMC_NANDInitStruct->FMC_ECC = FMC_ECC_Disable;
  469. FMC_NANDInitStruct->FMC_ECCPageSize = FMC_ECCPageSize_256Bytes;
  470. FMC_NANDInitStruct->FMC_TCLRSetupTime = 0x0;
  471. FMC_NANDInitStruct->FMC_TARSetupTime = 0x0;
  472. FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_SetupTime = 252;
  473. FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_WaitSetupTime = 252;
  474. FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HoldSetupTime = 252;
  475. FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HiZSetupTime = 252;
  476. FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_SetupTime = 252;
  477. FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_WaitSetupTime = 252;
  478. FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HoldSetupTime = 252;
  479. FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HiZSetupTime = 252;
  480. }
  481. /**
  482. * @brief Enables or disables the specified NAND Memory Bank.
  483. * @param FMC_Bank: specifies the FMC Bank to be used
  484. * This parameter can be one of the following values:
  485. * @arg FMC_Bank2_NAND: FMC Bank2 NAND
  486. * @arg FMC_Bank3_NAND: FMC Bank3 NAND
  487. * @param NewState: new state of the FMC_Bank. This parameter can be: ENABLE or DISABLE.
  488. * @retval None
  489. */
  490. void FMC_NANDCmd(uint32_t FMC_Bank, FunctionalState NewState)
  491. {
  492. assert_param(IS_FMC_NAND_BANK(FMC_Bank));
  493. assert_param(IS_FUNCTIONAL_STATE(NewState));
  494. if (NewState != DISABLE)
  495. {
  496. /* Enable the selected NAND Bank by setting the PBKEN bit in the PCRx register */
  497. if(FMC_Bank == FMC_Bank2_NAND)
  498. {
  499. FMC_Bank2->PCR2 |= PCR_PBKEN_SET;
  500. }
  501. else
  502. {
  503. FMC_Bank3->PCR3 |= PCR_PBKEN_SET;
  504. }
  505. }
  506. else
  507. {
  508. /* Disable the selected NAND Bank by clearing the PBKEN bit in the PCRx register */
  509. if(FMC_Bank == FMC_Bank2_NAND)
  510. {
  511. FMC_Bank2->PCR2 &= PCR_PBKEN_RESET;
  512. }
  513. else
  514. {
  515. FMC_Bank3->PCR3 &= PCR_PBKEN_RESET;
  516. }
  517. }
  518. }
  519. /**
  520. * @brief Enables or disables the FMC NAND ECC feature.
  521. * @param FMC_Bank: specifies the FMC Bank to be used
  522. * This parameter can be one of the following values:
  523. * @arg FMC_Bank2_NAND: FMC Bank2 NAND
  524. * @arg FMC_Bank3_NAND: FMC Bank3 NAND
  525. * @param NewState: new state of the FMC NAND ECC feature.
  526. * This parameter can be: ENABLE or DISABLE.
  527. * @retval None
  528. */
  529. void FMC_NANDECCCmd(uint32_t FMC_Bank, FunctionalState NewState)
  530. {
  531. assert_param(IS_FMC_NAND_BANK(FMC_Bank));
  532. assert_param(IS_FUNCTIONAL_STATE(NewState));
  533. if (NewState != DISABLE)
  534. {
  535. /* Enable the selected NAND Bank ECC function by setting the ECCEN bit in the PCRx register */
  536. if(FMC_Bank == FMC_Bank2_NAND)
  537. {
  538. FMC_Bank2->PCR2 |= PCR_ECCEN_SET;
  539. }
  540. else
  541. {
  542. FMC_Bank3->PCR3 |= PCR_ECCEN_SET;
  543. }
  544. }
  545. else
  546. {
  547. /* Disable the selected NAND Bank ECC function by clearing the ECCEN bit in the PCRx register */
  548. if(FMC_Bank == FMC_Bank2_NAND)
  549. {
  550. FMC_Bank2->PCR2 &= PCR_ECCEN_RESET;
  551. }
  552. else
  553. {
  554. FMC_Bank3->PCR3 &= PCR_ECCEN_RESET;
  555. }
  556. }
  557. }
  558. /**
  559. * @brief Returns the error correction code register value.
  560. * @param FMC_Bank: specifies the FMC Bank to be used
  561. * This parameter can be one of the following values:
  562. * @arg FMC_Bank2_NAND: FMC Bank2 NAND
  563. * @arg FMC_Bank3_NAND: FMC Bank3 NAND
  564. * @retval The Error Correction Code (ECC) value.
  565. */
  566. uint32_t FMC_GetECC(uint32_t FMC_Bank)
  567. {
  568. uint32_t eccval = 0x00000000;
  569. if(FMC_Bank == FMC_Bank2_NAND)
  570. {
  571. /* Get the ECCR2 register value */
  572. eccval = FMC_Bank2->ECCR2;
  573. }
  574. else
  575. {
  576. /* Get the ECCR3 register value */
  577. eccval = FMC_Bank3->ECCR3;
  578. }
  579. /* Return the error correction code value */
  580. return(eccval);
  581. }
  582. /**
  583. * @}
  584. */
  585. /** @defgroup FMC_Group3 PCCARD Controller functions
  586. * @brief PCCARD Controller functions
  587. *
  588. @verbatim
  589. ===============================================================================
  590. ##### PCCARD Controller functions #####
  591. ===============================================================================
  592. [..] he following sequence should be followed to configure the FMC to interface
  593. with 16-bit PC Card compatible memory connected to the PCCARD Bank:
  594. (#) Enable the clock for the FMC and associated GPIOs using the following functions:
  595. (++) RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FMC, ENABLE);
  596. (++) RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE);
  597. (#) FMC pins configuration
  598. (++) Connect the involved FMC pins to AF12 using the following function
  599. GPIO_PinAFConfig(GPIOx, GPIO_PinSourcex, GPIO_AF_FMC);
  600. (++) Configure these FMC pins in alternate function mode by calling the function
  601. GPIO_Init();
  602. (#) Declare a FMC_PCCARDInitTypeDef structure, for example:
  603. FMC_PCCARDInitTypeDef FMC_PCCARDInitStructure;
  604. and fill the FMC_PCCARDInitStructure variable with the allowed values of
  605. the structure member.
  606. (#) Initialize the PCCARD Controller by calling the function
  607. FMC_PCCARDInit(&FMC_PCCARDInitStructure);
  608. (#) Then enable the PCCARD Bank:
  609. FMC_PCCARDCmd(ENABLE);
  610. (#) At this stage you can read/write from/to the memory connected to the PCCARD Bank.
  611. @endverbatim
  612. * @{
  613. */
  614. /**
  615. * @brief De-initializes the FMC PCCARD Bank registers to their default reset values.
  616. * @param None
  617. * @retval None
  618. */
  619. void FMC_PCCARDDeInit(void)
  620. {
  621. /* Set the FMC_Bank4 registers to their reset values */
  622. FMC_Bank4->PCR4 = 0x00000018;
  623. FMC_Bank4->SR4 = 0x00000000;
  624. FMC_Bank4->PMEM4 = 0xFCFCFCFC;
  625. FMC_Bank4->PATT4 = 0xFCFCFCFC;
  626. FMC_Bank4->PIO4 = 0xFCFCFCFC;
  627. }
  628. /**
  629. * @brief Initializes the FMC PCCARD Bank according to the specified parameters
  630. * in the FMC_PCCARDInitStruct.
  631. * @param FMC_PCCARDInitStruct : pointer to a FMC_PCCARDInitTypeDef structure
  632. * that contains the configuration information for the FMC PCCARD Bank.
  633. * @retval None
  634. */
  635. void FMC_PCCARDInit(FMC_PCCARDInitTypeDef* FMC_PCCARDInitStruct)
  636. {
  637. /* temporary registers */
  638. uint32_t tmppcr = 0, tmpmem = 0, tmppatt = 0, tmppio = 0;
  639. /* Check the parameters */
  640. assert_param(IS_FMC_WAIT_FEATURE(FMC_PCCARDInitStruct->FMC_Waitfeature));
  641. assert_param(IS_FMC_TCLR_TIME(FMC_PCCARDInitStruct->FMC_TCLRSetupTime));
  642. assert_param(IS_FMC_TAR_TIME(FMC_PCCARDInitStruct->FMC_TARSetupTime));
  643. assert_param(IS_FMC_SETUP_TIME(FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_SetupTime));
  644. assert_param(IS_FMC_WAIT_TIME(FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_WaitSetupTime));
  645. assert_param(IS_FMC_HOLD_TIME(FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HoldSetupTime));
  646. assert_param(IS_FMC_HIZ_TIME(FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HiZSetupTime));
  647. assert_param(IS_FMC_SETUP_TIME(FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_SetupTime));
  648. assert_param(IS_FMC_WAIT_TIME(FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_WaitSetupTime));
  649. assert_param(IS_FMC_HOLD_TIME(FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HoldSetupTime));
  650. assert_param(IS_FMC_HIZ_TIME(FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HiZSetupTime));
  651. assert_param(IS_FMC_SETUP_TIME(FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_SetupTime));
  652. assert_param(IS_FMC_WAIT_TIME(FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_WaitSetupTime));
  653. assert_param(IS_FMC_HOLD_TIME(FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_HoldSetupTime));
  654. assert_param(IS_FMC_HIZ_TIME(FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_HiZSetupTime));
  655. /* Get PCCARD control register value */
  656. tmppcr = FMC_Bank4->PCR4;
  657. /* Clear TAR, TCLR, PWAITEN and PWID bits */
  658. tmppcr &= ((uint32_t)~(FMC_PCR4_TAR | FMC_PCR4_TCLR | FMC_PCR4_PWAITEN | \
  659. FMC_PCR4_PWID));
  660. /* Set the PCR4 register value according to FMC_PCCARDInitStruct parameters */
  661. tmppcr |= (uint32_t)FMC_PCCARDInitStruct->FMC_Waitfeature |
  662. FMC_NAND_MemoryDataWidth_16b |
  663. (FMC_PCCARDInitStruct->FMC_TCLRSetupTime << 9) |
  664. (FMC_PCCARDInitStruct->FMC_TARSetupTime << 13);
  665. FMC_Bank4->PCR4 = tmppcr;
  666. /* Get PCCARD common space timing register value */
  667. tmpmem = FMC_Bank4->PMEM4;
  668. /* Clear MEMSETx, MEMWAITx, MEMHOLDx and MEMHIZx bits */
  669. tmpmem &= ((uint32_t)~(FMC_PMEM4_MEMSET4 | FMC_PMEM4_MEMWAIT4 | FMC_PMEM4_MEMHOLD4 | \
  670. FMC_PMEM4_MEMHIZ4));
  671. /* Set PMEM4 register value according to FMC_CommonSpaceTimingStructure parameters */
  672. tmpmem |= (uint32_t)FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_SetupTime |
  673. (FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_WaitSetupTime << 8) |
  674. (FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HoldSetupTime << 16)|
  675. (FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HiZSetupTime << 24);
  676. FMC_Bank4->PMEM4 = tmpmem;
  677. /* Get PCCARD timing parameters */
  678. tmppatt = FMC_Bank4->PATT4;
  679. /* Clear ATTSETx, ATTWAITx, ATTHOLDx and ATTHIZx bits */
  680. tmppatt &= ((uint32_t)~(FMC_PATT4_ATTSET4 | FMC_PATT4_ATTWAIT4 | FMC_PATT4_ATTHOLD4 | \
  681. FMC_PATT4_ATTHIZ4));
  682. /* Set PATT4 register value according to FMC_AttributeSpaceTimingStructure parameters */
  683. tmppatt |= (uint32_t)FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_SetupTime |
  684. (FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_WaitSetupTime << 8) |
  685. (FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HoldSetupTime << 16)|
  686. (FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HiZSetupTime << 24);
  687. FMC_Bank4->PATT4 = tmppatt;
  688. /* Get FMC_PCCARD device timing parameters */
  689. tmppio = FMC_Bank4->PIO4;
  690. /* Clear IOSET4, IOWAIT4, IOHOLD4 and IOHIZ4 bits */
  691. tmppio &= ((uint32_t)~(FMC_PIO4_IOSET4 | FMC_PIO4_IOWAIT4 | FMC_PIO4_IOHOLD4 | \
  692. FMC_PIO4_IOHIZ4));
  693. /* Set PIO4 register value according to FMC_IOSpaceTimingStructure parameters */
  694. tmppio |= (uint32_t)FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_SetupTime |
  695. (FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_WaitSetupTime << 8) |
  696. (FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_HoldSetupTime << 16)|
  697. (FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_HiZSetupTime << 24);
  698. FMC_Bank4->PIO4 = tmppio;
  699. }
  700. /**
  701. * @brief Fills each FMC_PCCARDInitStruct member with its default value.
  702. * @param FMC_PCCARDInitStruct: pointer to a FMC_PCCARDInitTypeDef structure
  703. * which will be initialized.
  704. * @retval None
  705. */
  706. void FMC_PCCARDStructInit(FMC_PCCARDInitTypeDef* FMC_PCCARDInitStruct)
  707. {
  708. /* Reset PCCARD Init structure parameters values */
  709. FMC_PCCARDInitStruct->FMC_Waitfeature = FMC_Waitfeature_Disable;
  710. FMC_PCCARDInitStruct->FMC_TCLRSetupTime = 0;
  711. FMC_PCCARDInitStruct->FMC_TARSetupTime = 0;
  712. FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_SetupTime = 252;
  713. FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_WaitSetupTime = 252;
  714. FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HoldSetupTime = 252;
  715. FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HiZSetupTime = 252;
  716. FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_SetupTime = 252;
  717. FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_WaitSetupTime = 252;
  718. FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HoldSetupTime = 252;
  719. FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HiZSetupTime = 252;
  720. FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_SetupTime = 252;
  721. FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_WaitSetupTime = 252;
  722. FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_HoldSetupTime = 252;
  723. FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_HiZSetupTime = 252;
  724. }
  725. /**
  726. * @brief Enables or disables the PCCARD Memory Bank.
  727. * @param NewState: new state of the PCCARD Memory Bank.
  728. * This parameter can be: ENABLE or DISABLE.
  729. * @retval None
  730. */
  731. void FMC_PCCARDCmd(FunctionalState NewState)
  732. {
  733. assert_param(IS_FUNCTIONAL_STATE(NewState));
  734. if (NewState != DISABLE)
  735. {
  736. /* Enable the PCCARD Bank by setting the PBKEN bit in the PCR4 register */
  737. FMC_Bank4->PCR4 |= PCR_PBKEN_SET;
  738. }
  739. else
  740. {
  741. /* Disable the PCCARD Bank by clearing the PBKEN bit in the PCR4 register */
  742. FMC_Bank4->PCR4 &= PCR_PBKEN_RESET;
  743. }
  744. }
  745. /**
  746. * @}
  747. */
  748. /** @defgroup FMC_Group4 SDRAM Controller functions
  749. * @brief SDRAM Controller functions
  750. *
  751. @verbatim
  752. ===============================================================================
  753. ##### SDRAM Controller functions #####
  754. ===============================================================================
  755. [..] The following sequence should be followed to configure the FMC to interface
  756. with SDRAM memory connected to the SDRAM Bank 1 or SDRAM bank 2:
  757. (#) Enable the clock for the FMC and associated GPIOs using the following functions:
  758. (++) RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FMC, ENABLE);
  759. (++) RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE);
  760. (#) FMC pins configuration
  761. (++) Connect the involved FMC pins to AF12 using the following function
  762. GPIO_PinAFConfig(GPIOx, GPIO_PinSourcex, GPIO_AF_FMC);
  763. (++) Configure these FMC pins in alternate function mode by calling the function
  764. GPIO_Init();
  765. (#) Declare a FMC_SDRAMInitTypeDef structure, for example:
  766. FMC_SDRAMInitTypeDef FMC_SDRAMInitStructure;
  767. and fill the FMC_SDRAMInitStructure variable with the allowed values of
  768. the structure member.
  769. (#) Initialize the SDRAM Controller by calling the function
  770. FMC_SDRAMInit(&FMC_SDRAMInitStructure);
  771. (#) Declare a FMC_SDRAMCommandTypeDef structure, for example:
  772. FMC_SDRAMCommandTypeDef FMC_SDRAMCommandStructure;
  773. and fill the FMC_SDRAMCommandStructure variable with the allowed values of
  774. the structure member.
  775. (#) Configure the SDCMR register with the desired command parameters by calling
  776. the function FMC_SDRAMCmdConfig(&FMC_SDRAMCommandStructure);
  777. (#) At this stage, the SDRAM memory is ready for any valid command.
  778. @endverbatim
  779. * @{
  780. */
  781. /**
  782. * @brief De-initializes the FMC SDRAM Banks registers to their default
  783. * reset values.
  784. * @param FMC_Bank: specifies the FMC Bank to be used
  785. * This parameter can be one of the following values:
  786. * @arg FMC_Bank1_SDRAM: FMC Bank1 SDRAM
  787. * @arg FMC_Bank2_SDRAM: FMC Bank2 SDRAM
  788. * @retval None
  789. */
  790. void FMC_SDRAMDeInit(uint32_t FMC_Bank)
  791. {
  792. /* Check the parameter */
  793. assert_param(IS_FMC_SDRAM_BANK(FMC_Bank));
  794. FMC_Bank5_6->SDCR[FMC_Bank] = 0x000002D0;
  795. FMC_Bank5_6->SDTR[FMC_Bank] = 0x0FFFFFFF;
  796. FMC_Bank5_6->SDCMR = 0x00000000;
  797. FMC_Bank5_6->SDRTR = 0x00000000;
  798. FMC_Bank5_6->SDSR = 0x00000000;
  799. }
  800. /**
  801. * @brief Initializes the FMC SDRAM Banks according to the specified
  802. * parameters in the FMC_SDRAMInitStruct.
  803. * @param FMC_SDRAMInitStruct : pointer to a FMC_SDRAMInitTypeDef structure
  804. * that contains the configuration information for the FMC SDRAM
  805. * specified Banks.
  806. * @retval None
  807. */
  808. void FMC_SDRAMInit(FMC_SDRAMInitTypeDef* FMC_SDRAMInitStruct)
  809. {
  810. /* temporary registers */
  811. uint32_t tmpr1 = 0, tmpr2 = 0, tmpr3 = 0, tmpr4 = 0;
  812. /* Check the parameters */
  813. /* Control parameters */
  814. assert_param(IS_FMC_SDRAM_BANK(FMC_SDRAMInitStruct->FMC_Bank));
  815. assert_param(IS_FMC_COLUMNBITS_NUMBER(FMC_SDRAMInitStruct->FMC_ColumnBitsNumber));
  816. assert_param(IS_FMC_ROWBITS_NUMBER(FMC_SDRAMInitStruct->FMC_RowBitsNumber));
  817. assert_param(IS_FMC_SDMEMORY_WIDTH(FMC_SDRAMInitStruct->FMC_SDMemoryDataWidth));
  818. assert_param(IS_FMC_INTERNALBANK_NUMBER(FMC_SDRAMInitStruct->FMC_InternalBankNumber));
  819. assert_param(IS_FMC_CAS_LATENCY(FMC_SDRAMInitStruct->FMC_CASLatency));
  820. assert_param(IS_FMC_WRITE_PROTECTION(FMC_SDRAMInitStruct->FMC_WriteProtection));
  821. assert_param(IS_FMC_SDCLOCK_PERIOD(FMC_SDRAMInitStruct->FMC_SDClockPeriod));
  822. assert_param(IS_FMC_READ_BURST(FMC_SDRAMInitStruct->FMC_ReadBurst));
  823. assert_param(IS_FMC_READPIPE_DELAY(FMC_SDRAMInitStruct->FMC_ReadPipeDelay));
  824. /* Timing parameters */
  825. assert_param(IS_FMC_LOADTOACTIVE_DELAY(FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_LoadToActiveDelay));
  826. assert_param(IS_FMC_EXITSELFREFRESH_DELAY(FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_ExitSelfRefreshDelay));
  827. assert_param(IS_FMC_SELFREFRESH_TIME(FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_SelfRefreshTime));
  828. assert_param(IS_FMC_ROWCYCLE_DELAY(FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RowCycleDelay));
  829. assert_param(IS_FMC_WRITE_RECOVERY_TIME(FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_WriteRecoveryTime));
  830. assert_param(IS_FMC_RP_DELAY(FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RPDelay));
  831. assert_param(IS_FMC_RCD_DELAY(FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RCDDelay));
  832. /* Get SDRAM register value */
  833. tmpr1 = FMC_Bank5_6->SDCR[FMC_SDRAMInitStruct->FMC_Bank];
  834. /* Clear NC, NR, MWID, NB, CAS, WP, SDCLK, RBURST, and RPIPE bits */
  835. tmpr1 &= ((uint32_t)~(FMC_SDCR1_NC | FMC_SDCR1_NR | FMC_SDCR1_MWID | \
  836. FMC_SDCR1_NB | FMC_SDCR1_CAS | FMC_SDCR1_WP | \
  837. FMC_SDCR1_SDCLK | FMC_SDCR1_RBURST | FMC_SDCR1_RPIPE));
  838. /* SDRAM bank control register configuration */
  839. tmpr1 |= (uint32_t)FMC_SDRAMInitStruct->FMC_ColumnBitsNumber |
  840. FMC_SDRAMInitStruct->FMC_RowBitsNumber |
  841. FMC_SDRAMInitStruct->FMC_SDMemoryDataWidth |
  842. FMC_SDRAMInitStruct->FMC_InternalBankNumber |
  843. FMC_SDRAMInitStruct->FMC_CASLatency |
  844. FMC_SDRAMInitStruct->FMC_WriteProtection |
  845. FMC_SDRAMInitStruct->FMC_SDClockPeriod |
  846. FMC_SDRAMInitStruct->FMC_ReadBurst |
  847. FMC_SDRAMInitStruct->FMC_ReadPipeDelay;
  848. if(FMC_SDRAMInitStruct->FMC_Bank == FMC_Bank1_SDRAM )
  849. {
  850. FMC_Bank5_6->SDCR[FMC_SDRAMInitStruct->FMC_Bank] = tmpr1;
  851. }
  852. else /* SDCR2 "don't care" bits configuration */
  853. {
  854. /* Get SDCR register value */
  855. tmpr3 = FMC_Bank5_6->SDCR[FMC_Bank1_SDRAM];
  856. /* Clear NC, NR, MWID, NB, CAS, WP, SDCLK, RBURST, and RPIPE bits */
  857. tmpr3 &= ((uint32_t)~(FMC_SDCR1_NC | FMC_SDCR1_NR | FMC_SDCR1_MWID | \
  858. FMC_SDCR1_NB | FMC_SDCR1_CAS | FMC_SDCR1_WP | \
  859. FMC_SDCR1_SDCLK | FMC_SDCR1_RBURST | FMC_SDCR1_RPIPE));
  860. tmpr3 |= (uint32_t)FMC_SDRAMInitStruct->FMC_SDClockPeriod |
  861. FMC_SDRAMInitStruct->FMC_ReadBurst |
  862. FMC_SDRAMInitStruct->FMC_ReadPipeDelay;
  863. FMC_Bank5_6->SDCR[FMC_Bank1_SDRAM] = tmpr3;
  864. FMC_Bank5_6->SDCR[FMC_SDRAMInitStruct->FMC_Bank] = tmpr1;
  865. }
  866. /* SDRAM bank timing register configuration */
  867. if(FMC_SDRAMInitStruct->FMC_Bank == FMC_Bank1_SDRAM )
  868. {
  869. /* Get SDTR register value */
  870. tmpr2 = FMC_Bank5_6->SDTR[FMC_SDRAMInitStruct->FMC_Bank];
  871. /* Clear TMRD, TXSR, TRAS, TRC, TWR, TRP and TRCD bits */
  872. tmpr2 &= ((uint32_t)~(FMC_SDTR1_TMRD | FMC_SDTR1_TXSR | FMC_SDTR1_TRAS | \
  873. FMC_SDTR1_TRC | FMC_SDTR1_TWR | FMC_SDTR1_TRP | \
  874. FMC_SDTR1_TRCD));
  875. tmpr2 |= (uint32_t)((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_LoadToActiveDelay)-1) |
  876. (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_ExitSelfRefreshDelay)-1) << 4) |
  877. (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_SelfRefreshTime)-1) << 8) |
  878. (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RowCycleDelay)-1) << 12) |
  879. (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_WriteRecoveryTime)-1) << 16) |
  880. (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RPDelay)-1) << 20) |
  881. (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RCDDelay)-1) << 24);
  882. FMC_Bank5_6->SDTR[FMC_SDRAMInitStruct->FMC_Bank] = tmpr2;
  883. }
  884. else /* SDTR "don't care bits configuration */
  885. {
  886. /* Get SDTR register value */
  887. tmpr2 = FMC_Bank5_6->SDTR[FMC_SDRAMInitStruct->FMC_Bank];
  888. /* Clear TMRD, TXSR, TRAS, TRC, TWR, TRP and TRCD bits */
  889. tmpr2 &= ((uint32_t)~(FMC_SDTR1_TMRD | FMC_SDTR1_TXSR | FMC_SDTR1_TRAS | \
  890. FMC_SDTR1_TRC | FMC_SDTR1_TWR | FMC_SDTR1_TRP | \
  891. FMC_SDTR1_TRCD));
  892. tmpr2 |= (uint32_t)((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_LoadToActiveDelay)-1) |
  893. (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_ExitSelfRefreshDelay)-1) << 4) |
  894. (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_SelfRefreshTime)-1) << 8) |
  895. (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_WriteRecoveryTime)-1) << 16);
  896. /* Get SDTR register value */
  897. tmpr4 = FMC_Bank5_6->SDTR[FMC_Bank1_SDRAM];
  898. /* Clear TMRD, TXSR, TRAS, TRC, TWR, TRP and TRCD bits */
  899. tmpr4 &= ((uint32_t)~(FMC_SDTR1_TMRD | FMC_SDTR1_TXSR | FMC_SDTR1_TRAS | \
  900. FMC_SDTR1_TRC | FMC_SDTR1_TWR | FMC_SDTR1_TRP | \
  901. FMC_SDTR1_TRCD));
  902. tmpr4 |= (uint32_t)(((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RowCycleDelay)-1) << 12) |
  903. (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RPDelay)-1) << 20);
  904. FMC_Bank5_6->SDTR[FMC_Bank1_SDRAM] = tmpr4;
  905. FMC_Bank5_6->SDTR[FMC_SDRAMInitStruct->FMC_Bank] = tmpr2;
  906. }
  907. }
  908. /**
  909. * @brief Fills each FMC_SDRAMInitStruct member with its default value.
  910. * @param FMC_SDRAMInitStruct: pointer to a FMC_SDRAMInitTypeDef structure
  911. * which will be initialized.
  912. * @retval None
  913. */
  914. void FMC_SDRAMStructInit(FMC_SDRAMInitTypeDef* FMC_SDRAMInitStruct)
  915. {
  916. /* Reset SDRAM Init structure parameters values */
  917. FMC_SDRAMInitStruct->FMC_Bank = FMC_Bank1_SDRAM;
  918. FMC_SDRAMInitStruct->FMC_ColumnBitsNumber = FMC_ColumnBits_Number_8b;
  919. FMC_SDRAMInitStruct->FMC_RowBitsNumber = FMC_RowBits_Number_11b;
  920. FMC_SDRAMInitStruct->FMC_SDMemoryDataWidth = FMC_SDMemory_Width_16b;
  921. FMC_SDRAMInitStruct->FMC_InternalBankNumber = FMC_InternalBank_Number_4;
  922. FMC_SDRAMInitStruct->FMC_CASLatency = FMC_CAS_Latency_1;
  923. FMC_SDRAMInitStruct->FMC_WriteProtection = FMC_Write_Protection_Enable;
  924. FMC_SDRAMInitStruct->FMC_SDClockPeriod = FMC_SDClock_Disable;
  925. FMC_SDRAMInitStruct->FMC_ReadBurst = FMC_Read_Burst_Disable;
  926. FMC_SDRAMInitStruct->FMC_ReadPipeDelay = FMC_ReadPipe_Delay_0;
  927. FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_LoadToActiveDelay = 16;
  928. FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_ExitSelfRefreshDelay = 16;
  929. FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_SelfRefreshTime = 16;
  930. FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RowCycleDelay = 16;
  931. FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_WriteRecoveryTime = 16;
  932. FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RPDelay = 16;
  933. FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RCDDelay = 16;
  934. }
  935. /**
  936. * @brief Configures the SDRAM memory command issued when the device is accessed.
  937. * @param FMC_SDRAMCommandStruct: pointer to a FMC_SDRAMCommandTypeDef structure
  938. * which will be configured.
  939. * @retval None
  940. */
  941. void FMC_SDRAMCmdConfig(FMC_SDRAMCommandTypeDef* FMC_SDRAMCommandStruct)
  942. {
  943. uint32_t tmpr = 0x0;
  944. /* check parameters */
  945. assert_param(IS_FMC_COMMAND_MODE(FMC_SDRAMCommandStruct->FMC_CommandMode));
  946. assert_param(IS_FMC_COMMAND_TARGET(FMC_SDRAMCommandStruct->FMC_CommandTarget));
  947. assert_param(IS_FMC_AUTOREFRESH_NUMBER(FMC_SDRAMCommandStruct->FMC_AutoRefreshNumber));
  948. assert_param(IS_FMC_MODE_REGISTER(FMC_SDRAMCommandStruct->FMC_ModeRegisterDefinition));
  949. tmpr = (uint32_t)(FMC_SDRAMCommandStruct->FMC_CommandMode |
  950. FMC_SDRAMCommandStruct->FMC_CommandTarget |
  951. (((FMC_SDRAMCommandStruct->FMC_AutoRefreshNumber)-1)<<5) |
  952. ((FMC_SDRAMCommandStruct->FMC_ModeRegisterDefinition)<<9));
  953. FMC_Bank5_6->SDCMR = tmpr;
  954. }
  955. /**
  956. * @brief Returns the indicated FMC SDRAM bank mode status.
  957. * @param SDRAM_Bank: Defines the FMC SDRAM bank. This parameter can be
  958. * FMC_Bank1_SDRAM or FMC_Bank2_SDRAM.
  959. * @retval The FMC SDRAM bank mode status
  960. */
  961. uint32_t FMC_GetModeStatus(uint32_t SDRAM_Bank)
  962. {
  963. uint32_t tmpreg = 0;
  964. /* Check the parameter */
  965. assert_param(IS_FMC_SDRAM_BANK(SDRAM_Bank));
  966. /* Get the busy flag status */
  967. if(SDRAM_Bank == FMC_Bank1_SDRAM)
  968. {
  969. tmpreg = (uint32_t)(FMC_Bank5_6->SDSR & FMC_SDSR_MODES1);
  970. }
  971. else
  972. {
  973. tmpreg = ((uint32_t)(FMC_Bank5_6->SDSR & FMC_SDSR_MODES2) >> 2);
  974. }
  975. /* Return the mode status */
  976. return tmpreg;
  977. }
  978. /**
  979. * @brief defines the SDRAM Memory Refresh rate.
  980. * @param FMC_Count: specifies the Refresh timer count.
  981. * @retval None
  982. */
  983. void FMC_SetRefreshCount(uint32_t FMC_Count)
  984. {
  985. /* check the parameters */
  986. assert_param(IS_FMC_REFRESH_COUNT(FMC_Count));
  987. FMC_Bank5_6->SDRTR |= (FMC_Count<<1);
  988. }
  989. /**
  990. * @brief Sets the Number of consecutive SDRAM Memory auto Refresh commands.
  991. * @param FMC_Number: specifies the auto Refresh number.
  992. * @retval None
  993. */
  994. void FMC_SetAutoRefresh_Number(uint32_t FMC_Number)
  995. {
  996. /* check the parameters */
  997. assert_param(IS_FMC_AUTOREFRESH_NUMBER(FMC_Number));
  998. FMC_Bank5_6->SDCMR |= (FMC_Number << 5);
  999. }
  1000. /**
  1001. * @brief Enables or disables write protection to the specified FMC SDRAM Bank.
  1002. * @param SDRAM_Bank: Defines the FMC SDRAM bank. This parameter can be
  1003. * FMC_Bank1_SDRAM or FMC_Bank2_SDRAM.
  1004. * @param NewState: new state of the write protection flag.
  1005. * This parameter can be: ENABLE or DISABLE.
  1006. * @retval None
  1007. */
  1008. void FMC_SDRAMWriteProtectionConfig(uint32_t SDRAM_Bank, FunctionalState NewState)
  1009. {
  1010. /* Check the parameter */
  1011. assert_param(IS_FUNCTIONAL_STATE(NewState));
  1012. assert_param(IS_FMC_SDRAM_BANK(SDRAM_Bank));
  1013. if (NewState != DISABLE)
  1014. {
  1015. FMC_Bank5_6->SDCR[SDRAM_Bank] |= FMC_Write_Protection_Enable;
  1016. }
  1017. else
  1018. {
  1019. FMC_Bank5_6->SDCR[SDRAM_Bank] &= SDCR_WriteProtection_RESET;
  1020. }
  1021. }
  1022. /**
  1023. * @}
  1024. */
  1025. /** @defgroup FMC_Group5 Interrupts and flags management functions
  1026. * @brief Interrupts and flags management functions
  1027. *
  1028. @verbatim
  1029. ===============================================================================
  1030. ##### Interrupts and flags management functions #####
  1031. ===============================================================================
  1032. @endverbatim
  1033. * @{
  1034. */
  1035. /**
  1036. * @brief Enables or disables the specified FMC interrupts.
  1037. * @param FMC_Bank: specifies the FMC Bank to be used
  1038. * This parameter can be one of the following values:
  1039. * @arg FMC_Bank2_NAND: FMC Bank2 NAND
  1040. * @arg FMC_Bank3_NAND: FMC Bank3 NAND
  1041. * @arg FMC_Bank4_PCCARD: FMC Bank4 PCCARD
  1042. * @arg FMC_Bank1_SDRAM: FMC Bank1 SDRAM
  1043. * @arg FMC_Bank2_SDRAM: FMC Bank2 SDRAM
  1044. * @param FMC_IT: specifies the FMC interrupt sources to be enabled or disabled.
  1045. * This parameter can be any combination of the following values:
  1046. * @arg FMC_IT_RisingEdge: Rising edge detection interrupt.
  1047. * @arg FMC_IT_Level: Level edge detection interrupt.
  1048. * @arg FMC_IT_FallingEdge: Falling edge detection interrupt.
  1049. * @arg FMC_IT_Refresh: Refresh error detection interrupt.
  1050. * @param NewState: new state of the specified FMC interrupts.
  1051. * This parameter can be: ENABLE or DISABLE.
  1052. * @retval None
  1053. */
  1054. void FMC_ITConfig(uint32_t FMC_Bank, uint32_t FMC_IT, FunctionalState NewState)
  1055. {
  1056. assert_param(IS_FMC_IT_BANK(FMC_Bank));
  1057. assert_param(IS_FMC_IT(FMC_IT));
  1058. assert_param(IS_FUNCTIONAL_STATE(NewState));
  1059. if (NewState != DISABLE)
  1060. {
  1061. /* Enable the selected FMC_Bank2 interrupts */
  1062. if(FMC_Bank == FMC_Bank2_NAND)
  1063. {
  1064. FMC_Bank2->SR2 |= FMC_IT;
  1065. }
  1066. /* Enable the selected FMC_Bank3 interrupts */
  1067. else if (FMC_Bank == FMC_Bank3_NAND)
  1068. {
  1069. FMC_Bank3->SR3 |= FMC_IT;
  1070. }
  1071. /* Enable the selected FMC_Bank4 interrupts */
  1072. else if (FMC_Bank == FMC_Bank4_PCCARD)
  1073. {
  1074. FMC_Bank4->SR4 |= FMC_IT;
  1075. }
  1076. /* Enable the selected FMC_Bank5_6 interrupt */
  1077. else
  1078. {
  1079. /* Enables the interrupt if the refresh error flag is set */
  1080. FMC_Bank5_6->SDRTR |= FMC_IT;
  1081. }
  1082. }
  1083. else
  1084. {
  1085. /* Disable the selected FMC_Bank2 interrupts */
  1086. if(FMC_Bank == FMC_Bank2_NAND)
  1087. {
  1088. FMC_Bank2->SR2 &= (uint32_t)~FMC_IT;
  1089. }
  1090. /* Disable the selected FMC_Bank3 interrupts */
  1091. else if (FMC_Bank == FMC_Bank3_NAND)
  1092. {
  1093. FMC_Bank3->SR3 &= (uint32_t)~FMC_IT;
  1094. }
  1095. /* Disable the selected FMC_Bank4 interrupts */
  1096. else if(FMC_Bank == FMC_Bank4_PCCARD)
  1097. {
  1098. FMC_Bank4->SR4 &= (uint32_t)~FMC_IT;
  1099. }
  1100. /* Disable the selected FMC_Bank5_6 interrupt */
  1101. else
  1102. {
  1103. /* Disables the interrupt if the refresh error flag is not set */
  1104. FMC_Bank5_6->SDRTR &= (uint32_t)~FMC_IT;
  1105. }
  1106. }
  1107. }
  1108. /**
  1109. * @brief Checks whether the specified FMC flag is set or not.
  1110. * @param FMC_Bank: specifies the FMC Bank to be used
  1111. * This parameter can be one of the following values:
  1112. * @arg FMC_Bank2_NAND: FMC Bank2 NAND
  1113. * @arg FMC_Bank3_NAND: FMC Bank3 NAND
  1114. * @arg FMC_Bank4_PCCARD: FMC Bank4 PCCARD
  1115. * @arg FMC_Bank1_SDRAM: FMC Bank1 SDRAM
  1116. * @arg FMC_Bank2_SDRAM: FMC Bank2 SDRAM
  1117. * @arg FMC_Bank1_SDRAM | FMC_Bank2_SDRAM: FMC Bank1 or Bank2 SDRAM
  1118. * @param FMC_FLAG: specifies the flag to check.
  1119. * This parameter can be one of the following values:
  1120. * @arg FMC_FLAG_RisingEdge: Rising edge detection Flag.
  1121. * @arg FMC_FLAG_Level: Level detection Flag.
  1122. * @arg FMC_FLAG_FallingEdge: Falling edge detection Flag.
  1123. * @arg FMC_FLAG_FEMPT: Fifo empty Flag.
  1124. * @arg FMC_FLAG_Refresh: Refresh error Flag.
  1125. * @arg FMC_FLAG_Busy: Busy status Flag.
  1126. * @retval The new state of FMC_FLAG (SET or RESET).
  1127. */
  1128. FlagStatus FMC_GetFlagStatus(uint32_t FMC_Bank, uint32_t FMC_FLAG)
  1129. {
  1130. FlagStatus bitstatus = RESET;
  1131. uint32_t tmpsr = 0x00000000;
  1132. /* Check the parameters */
  1133. assert_param(IS_FMC_GETFLAG_BANK(FMC_Bank));
  1134. assert_param(IS_FMC_GET_FLAG(FMC_FLAG));
  1135. if(FMC_Bank == FMC_Bank2_NAND)
  1136. {
  1137. tmpsr = FMC_Bank2->SR2;
  1138. }
  1139. else if(FMC_Bank == FMC_Bank3_NAND)
  1140. {
  1141. tmpsr = FMC_Bank3->SR3;
  1142. }
  1143. else if(FMC_Bank == FMC_Bank4_PCCARD)
  1144. {
  1145. tmpsr = FMC_Bank4->SR4;
  1146. }
  1147. else
  1148. {
  1149. tmpsr = FMC_Bank5_6->SDSR;
  1150. }
  1151. /* Get the flag status */
  1152. if ((tmpsr & FMC_FLAG) != FMC_FLAG )
  1153. {
  1154. bitstatus = RESET;
  1155. }
  1156. else
  1157. {
  1158. bitstatus = SET;
  1159. }
  1160. /* Return the flag status */
  1161. return bitstatus;
  1162. }
  1163. /**
  1164. * @brief Clears the FMC's pending flags.
  1165. * @param FMC_Bank: specifies the FMC Bank to be used
  1166. * This parameter can be one of the following values:
  1167. * @arg FMC_Bank2_NAND: FMC Bank2 NAND
  1168. * @arg FMC_Bank3_NAND: FMC Bank3 NAND
  1169. * @arg FMC_Bank4_PCCARD: FMC Bank4 PCCARD
  1170. * @arg FMC_Bank1_SDRAM: FMC Bank1 SDRAM
  1171. * @arg FMC_Bank2_SDRAM: FMC Bank2 SDRAM
  1172. * @param FMC_FLAG: specifies the flag to clear.
  1173. * This parameter can be any combination of the following values:
  1174. * @arg FMC_FLAG_RisingEdge: Rising edge detection Flag.
  1175. * @arg FMC_FLAG_Level: Level detection Flag.
  1176. * @arg FMC_FLAG_FallingEdge: Falling edge detection Flag.
  1177. * @arg FMC_FLAG_Refresh: Refresh error Flag.
  1178. * @retval None
  1179. */
  1180. void FMC_ClearFlag(uint32_t FMC_Bank, uint32_t FMC_FLAG)
  1181. {
  1182. /* Check the parameters */
  1183. assert_param(IS_FMC_GETFLAG_BANK(FMC_Bank));
  1184. assert_param(IS_FMC_CLEAR_FLAG(FMC_FLAG)) ;
  1185. if(FMC_Bank == FMC_Bank2_NAND)
  1186. {
  1187. FMC_Bank2->SR2 &= (~FMC_FLAG);
  1188. }
  1189. else if(FMC_Bank == FMC_Bank3_NAND)
  1190. {
  1191. FMC_Bank3->SR3 &= (~FMC_FLAG);
  1192. }
  1193. else if(FMC_Bank == FMC_Bank4_PCCARD)
  1194. {
  1195. FMC_Bank4->SR4 &= (~FMC_FLAG);
  1196. }
  1197. /* FMC_Bank5_6 SDRAM*/
  1198. else
  1199. {
  1200. FMC_Bank5_6->SDRTR &= (~FMC_FLAG);
  1201. }
  1202. }
  1203. /**
  1204. * @brief Checks whether the specified FMC interrupt has occurred or not.
  1205. * @param FMC_Bank: specifies the FMC Bank to be used
  1206. * This parameter can be one of the following values:
  1207. * @arg FMC_Bank2_NAND: FMC Bank2 NAND
  1208. * @arg FMC_Bank3_NAND: FMC Bank3 NAND
  1209. * @arg FMC_Bank4_PCCARD: FMC Bank4 PCCARD
  1210. * @arg FMC_Bank1_SDRAM: FMC Bank1 SDRAM
  1211. * @arg FMC_Bank2_SDRAM: FMC Bank2 SDRAM
  1212. * @param FMC_IT: specifies the FMC interrupt source to check.
  1213. * This parameter can be one of the following values:
  1214. * @arg FMC_IT_RisingEdge: Rising edge detection interrupt.
  1215. * @arg FMC_IT_Level: Level edge detection interrupt.
  1216. * @arg FMC_IT_FallingEdge: Falling edge detection interrupt.
  1217. * @arg FMC_IT_Refresh: Refresh error detection interrupt.
  1218. * @retval The new state of FMC_IT (SET or RESET).
  1219. */
  1220. ITStatus FMC_GetITStatus(uint32_t FMC_Bank, uint32_t FMC_IT)
  1221. {
  1222. ITStatus bitstatus = RESET;
  1223. uint32_t tmpsr = 0x0;
  1224. uint32_t tmpsr2 = 0x0;
  1225. uint32_t itstatus = 0x0;
  1226. uint32_t itenable = 0x0;
  1227. /* Check the parameters */
  1228. assert_param(IS_FMC_IT_BANK(FMC_Bank));
  1229. assert_param(IS_FMC_GET_IT(FMC_IT));
  1230. if(FMC_Bank == FMC_Bank2_NAND)
  1231. {
  1232. tmpsr = FMC_Bank2->SR2;
  1233. }
  1234. else if(FMC_Bank == FMC_Bank3_NAND)
  1235. {
  1236. tmpsr = FMC_Bank3->SR3;
  1237. }
  1238. else if(FMC_Bank == FMC_Bank4_PCCARD)
  1239. {
  1240. tmpsr = FMC_Bank4->SR4;
  1241. }
  1242. /* FMC_Bank5_6 SDRAM*/
  1243. else
  1244. {
  1245. tmpsr = FMC_Bank5_6->SDRTR;
  1246. tmpsr2 = FMC_Bank5_6->SDSR;
  1247. }
  1248. /* get the IT enable bit status*/
  1249. itenable = tmpsr & FMC_IT;
  1250. /* get the corresponding IT Flag status*/
  1251. if((FMC_Bank == FMC_Bank1_SDRAM) || (FMC_Bank == FMC_Bank2_SDRAM))
  1252. {
  1253. itstatus = tmpsr2 & FMC_SDSR_RE;
  1254. }
  1255. else
  1256. {
  1257. itstatus = tmpsr & (FMC_IT >> 3);
  1258. }
  1259. if ((itstatus != (uint32_t)RESET) && (itenable != (uint32_t)RESET))
  1260. {
  1261. bitstatus = SET;
  1262. }
  1263. else
  1264. {
  1265. bitstatus = RESET;
  1266. }
  1267. return bitstatus;
  1268. }
  1269. /**
  1270. * @brief Clears the FMC's interrupt pending bits.
  1271. * @param FMC_Bank: specifies the FMC Bank to be used
  1272. * This parameter can be one of the following values:
  1273. * @arg FMC_Bank2_NAND: FMC Bank2 NAND
  1274. * @arg FMC_Bank3_NAND: FMC Bank3 NAND
  1275. * @arg FMC_Bank4_PCCARD: FMC Bank4 PCCARD
  1276. * @arg FMC_Bank1_SDRAM: FMC Bank1 SDRAM
  1277. * @arg FMC_Bank2_SDRAM: FMC Bank2 SDRAM
  1278. * @param FMC_IT: specifies the interrupt pending bit to clear.
  1279. * This parameter can be any combination of the following values:
  1280. * @arg FMC_IT_RisingEdge: Rising edge detection interrupt.
  1281. * @arg FMC_IT_Level: Level edge detection interrupt.
  1282. * @arg FMC_IT_FallingEdge: Falling edge detection interrupt.
  1283. * @arg FMC_IT_Refresh: Refresh error detection interrupt.
  1284. * @retval None
  1285. */
  1286. void FMC_ClearITPendingBit(uint32_t FMC_Bank, uint32_t FMC_IT)
  1287. {
  1288. /* Check the parameters */
  1289. assert_param(IS_FMC_IT_BANK(FMC_Bank));
  1290. assert_param(IS_FMC_IT(FMC_IT));
  1291. if(FMC_Bank == FMC_Bank2_NAND)
  1292. {
  1293. FMC_Bank2->SR2 &= ~(FMC_IT >> 3);
  1294. }
  1295. else if(FMC_Bank == FMC_Bank3_NAND)
  1296. {
  1297. FMC_Bank3->SR3 &= ~(FMC_IT >> 3);
  1298. }
  1299. else if(FMC_Bank == FMC_Bank4_PCCARD)
  1300. {
  1301. FMC_Bank4->SR4 &= ~(FMC_IT >> 3);
  1302. }
  1303. /* FMC_Bank5_6 SDRAM*/
  1304. else
  1305. {
  1306. FMC_Bank5_6->SDRTR |= FMC_SDRTR_CRE;
  1307. }
  1308. }
  1309. /**
  1310. * @}
  1311. */
  1312. /**
  1313. * @}
  1314. */
  1315. /**
  1316. * @}
  1317. */
  1318. /**
  1319. * @}
  1320. */
  1321. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/