stm32f4xx_fmc.c 59 KB

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