stm32f4xx_fsmc.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_fsmc.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 FSMC 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. * + Interrupts and flags management
  13. *
  14. ******************************************************************************
  15. * @attention
  16. *
  17. * Copyright (c) 2016 STMicroelectronics.
  18. * All rights reserved.
  19. *
  20. * This software is licensed under terms that can be found in the LICENSE file
  21. * in the root directory of this software component.
  22. * If no LICENSE file comes with this software, it is provided AS-IS.
  23. *
  24. ******************************************************************************
  25. */
  26. /* Includes ------------------------------------------------------------------*/
  27. #include "stm32f4xx_fsmc.h"
  28. #include "stm32f4xx_rcc.h"
  29. /** @addtogroup STM32F4xx_StdPeriph_Driver
  30. * @{
  31. */
  32. /** @defgroup FSMC
  33. * @brief FSMC driver modules
  34. * @{
  35. */
  36. /* Private typedef -----------------------------------------------------------*/
  37. const FSMC_NORSRAMTimingInitTypeDef FSMC_DefaultTimingStruct = {0x0F, /* FSMC_AddressSetupTime */
  38. 0x0F, /* FSMC_AddressHoldTime */
  39. 0xFF, /* FSMC_DataSetupTime */
  40. 0x0F, /* FSMC_BusTurnAroundDuration */
  41. 0x0F, /* FSMC_CLKDivision */
  42. 0x0F, /* FSMC_DataLatency */
  43. FSMC_AccessMode_A /* FSMC_AccessMode */
  44. };
  45. /* Private define ------------------------------------------------------------*/
  46. /* --------------------- FSMC registers bit mask ---------------------------- */
  47. /* FSMC 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. /* FSMC 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. /* Private macro -------------------------------------------------------------*/
  58. /* Private variables ---------------------------------------------------------*/
  59. /* Private function prototypes -----------------------------------------------*/
  60. /* Private functions ---------------------------------------------------------*/
  61. /** @defgroup FSMC_Private_Functions
  62. * @{
  63. */
  64. /** @defgroup FSMC_Group1 NOR/SRAM Controller functions
  65. * @brief NOR/SRAM Controller functions
  66. *
  67. @verbatim
  68. ===============================================================================
  69. ##### NOR and SRAM Controller functions #####
  70. ===============================================================================
  71. [..] The following sequence should be followed to configure the FSMC to interface
  72. with SRAM, PSRAM, NOR or OneNAND memory connected to the NOR/SRAM Bank:
  73. (#) Enable the clock for the FSMC and associated GPIOs using the following functions:
  74. RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE);
  75. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE);
  76. (#) FSMC pins configuration
  77. (++) Connect the involved FSMC pins to AF12 using the following function
  78. GPIO_PinAFConfig(GPIOx, GPIO_PinSourcex, GPIO_AF_FSMC);
  79. (++) Configure these FSMC pins in alternate function mode by calling the function
  80. GPIO_Init();
  81. (#) Declare a FSMC_NORSRAMInitTypeDef structure, for example:
  82. FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
  83. and fill the FSMC_NORSRAMInitStructure variable with the allowed values of
  84. the structure member.
  85. (#) Initialize the NOR/SRAM Controller by calling the function
  86. FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
  87. (#) Then enable the NOR/SRAM Bank, for example:
  88. FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM2, ENABLE);
  89. (#) At this stage you can read/write from/to the memory connected to the NOR/SRAM Bank.
  90. @endverbatim
  91. * @{
  92. */
  93. /**
  94. * @brief De-initializes the FSMC NOR/SRAM Banks registers to their default
  95. * reset values.
  96. * @param FSMC_Bank: specifies the FSMC Bank to be used
  97. * This parameter can be one of the following values:
  98. * @arg FSMC_Bank1_NORSRAM1: FSMC Bank1 NOR/SRAM1
  99. * @arg FSMC_Bank1_NORSRAM2: FSMC Bank1 NOR/SRAM2
  100. * @arg FSMC_Bank1_NORSRAM3: FSMC Bank1 NOR/SRAM3
  101. * @arg FSMC_Bank1_NORSRAM4: FSMC Bank1 NOR/SRAM4
  102. * @retval None
  103. */
  104. void FSMC_NORSRAMDeInit(uint32_t FSMC_Bank)
  105. {
  106. /* Check the parameter */
  107. assert_param(IS_FSMC_NORSRAM_BANK(FSMC_Bank));
  108. /* FSMC_Bank1_NORSRAM1 */
  109. if(FSMC_Bank == FSMC_Bank1_NORSRAM1)
  110. {
  111. FSMC_Bank1->BTCR[FSMC_Bank] = 0x000030DB;
  112. }
  113. /* FSMC_Bank1_NORSRAM2, FSMC_Bank1_NORSRAM3 or FSMC_Bank1_NORSRAM4 */
  114. else
  115. {
  116. FSMC_Bank1->BTCR[FSMC_Bank] = 0x000030D2;
  117. }
  118. FSMC_Bank1->BTCR[FSMC_Bank + 1] = 0x0FFFFFFF;
  119. FSMC_Bank1E->BWTR[FSMC_Bank] = 0x0FFFFFFF;
  120. }
  121. /**
  122. * @brief Initializes the FSMC NOR/SRAM Banks according to the specified
  123. * parameters in the FSMC_NORSRAMInitStruct.
  124. * @param FSMC_NORSRAMInitStruct : pointer to a FSMC_NORSRAMInitTypeDef structure
  125. * that contains the configuration information for the FSMC NOR/SRAM
  126. * specified Banks.
  127. * @retval None
  128. */
  129. void FSMC_NORSRAMInit(FSMC_NORSRAMInitTypeDef* FSMC_NORSRAMInitStruct)
  130. {
  131. uint32_t tmpbcr = 0, tmpbtr = 0, tmpbwr = 0;
  132. /* Check the parameters */
  133. assert_param(IS_FSMC_NORSRAM_BANK(FSMC_NORSRAMInitStruct->FSMC_Bank));
  134. assert_param(IS_FSMC_MUX(FSMC_NORSRAMInitStruct->FSMC_DataAddressMux));
  135. assert_param(IS_FSMC_MEMORY(FSMC_NORSRAMInitStruct->FSMC_MemoryType));
  136. assert_param(IS_FSMC_MEMORY_WIDTH(FSMC_NORSRAMInitStruct->FSMC_MemoryDataWidth));
  137. assert_param(IS_FSMC_BURSTMODE(FSMC_NORSRAMInitStruct->FSMC_BurstAccessMode));
  138. assert_param(IS_FSMC_ASYNWAIT(FSMC_NORSRAMInitStruct->FSMC_AsynchronousWait));
  139. assert_param(IS_FSMC_WAIT_POLARITY(FSMC_NORSRAMInitStruct->FSMC_WaitSignalPolarity));
  140. assert_param(IS_FSMC_WRAP_MODE(FSMC_NORSRAMInitStruct->FSMC_WrapMode));
  141. assert_param(IS_FSMC_WAIT_SIGNAL_ACTIVE(FSMC_NORSRAMInitStruct->FSMC_WaitSignalActive));
  142. assert_param(IS_FSMC_WRITE_OPERATION(FSMC_NORSRAMInitStruct->FSMC_WriteOperation));
  143. assert_param(IS_FSMC_WAITE_SIGNAL(FSMC_NORSRAMInitStruct->FSMC_WaitSignal));
  144. assert_param(IS_FSMC_EXTENDED_MODE(FSMC_NORSRAMInitStruct->FSMC_ExtendedMode));
  145. assert_param(IS_FSMC_WRITE_BURST(FSMC_NORSRAMInitStruct->FSMC_WriteBurst));
  146. assert_param(IS_FSMC_ADDRESS_SETUP_TIME(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressSetupTime));
  147. assert_param(IS_FSMC_ADDRESS_HOLD_TIME(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressHoldTime));
  148. assert_param(IS_FSMC_DATASETUP_TIME(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataSetupTime));
  149. assert_param(IS_FSMC_TURNAROUND_TIME(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_BusTurnAroundDuration));
  150. assert_param(IS_FSMC_CLK_DIV(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_CLKDivision));
  151. assert_param(IS_FSMC_DATA_LATENCY(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataLatency));
  152. assert_param(IS_FSMC_ACCESS_MODE(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AccessMode));
  153. /* Get the BTCR register value */
  154. tmpbcr = FSMC_Bank1->BTCR[FSMC_NORSRAMInitStruct->FSMC_Bank];
  155. /* Clear MBKEN, MUXEN, MTYP, MWID, FACCEN, BURSTEN, WAITPOL, WRAPMOD, WAITCFG, WREN,
  156. WAITEN, EXTMOD, ASYNCWAIT, CBURSTRW and CCLKEN bits */
  157. tmpbcr &= ((uint32_t)~(FSMC_BCR1_MBKEN | FSMC_BCR1_MUXEN | FSMC_BCR1_MTYP | \
  158. FSMC_BCR1_MWID | FSMC_BCR1_FACCEN | FSMC_BCR1_BURSTEN | \
  159. FSMC_BCR1_WAITPOL | FSMC_BCR1_WRAPMOD | FSMC_BCR1_WAITCFG | \
  160. FSMC_BCR1_WREN | FSMC_BCR1_WAITEN | FSMC_BCR1_EXTMOD | \
  161. FSMC_BCR1_ASYNCWAIT | FSMC_BCR1_CBURSTRW));
  162. /* Bank1 NOR/SRAM control register configuration */
  163. tmpbcr |= (uint32_t)FSMC_NORSRAMInitStruct->FSMC_DataAddressMux |
  164. FSMC_NORSRAMInitStruct->FSMC_MemoryType |
  165. FSMC_NORSRAMInitStruct->FSMC_MemoryDataWidth |
  166. FSMC_NORSRAMInitStruct->FSMC_BurstAccessMode |
  167. FSMC_NORSRAMInitStruct->FSMC_AsynchronousWait |
  168. FSMC_NORSRAMInitStruct->FSMC_WaitSignalPolarity |
  169. FSMC_NORSRAMInitStruct->FSMC_WrapMode |
  170. FSMC_NORSRAMInitStruct->FSMC_WaitSignalActive |
  171. FSMC_NORSRAMInitStruct->FSMC_WriteOperation |
  172. FSMC_NORSRAMInitStruct->FSMC_WaitSignal |
  173. FSMC_NORSRAMInitStruct->FSMC_ExtendedMode |
  174. FSMC_NORSRAMInitStruct->FSMC_WriteBurst;
  175. FSMC_Bank1->BTCR[FSMC_NORSRAMInitStruct->FSMC_Bank] = tmpbcr;
  176. if(FSMC_NORSRAMInitStruct->FSMC_MemoryType == FSMC_MemoryType_NOR)
  177. {
  178. FSMC_Bank1->BTCR[FSMC_NORSRAMInitStruct->FSMC_Bank] |= (uint32_t)BCR_FACCEN_SET;
  179. }
  180. /* Get the BTCR register value */
  181. tmpbtr = FSMC_Bank1->BTCR[FSMC_NORSRAMInitStruct->FSMC_Bank+1];
  182. /* Clear ADDSET, ADDHLD, DATAST, BUSTURN, CLKDIV, DATLAT and ACCMOD bits */
  183. tmpbtr &= ((uint32_t)~(FSMC_BTR1_ADDSET | FSMC_BTR1_ADDHLD | FSMC_BTR1_DATAST | \
  184. FSMC_BTR1_BUSTURN | FSMC_BTR1_CLKDIV | FSMC_BTR1_DATLAT | \
  185. FSMC_BTR1_ACCMOD));
  186. /* Bank1 NOR/SRAM timing register configuration */
  187. tmpbtr |= (uint32_t)FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressSetupTime |
  188. (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressHoldTime << 4) |
  189. (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataSetupTime << 8) |
  190. (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_BusTurnAroundDuration << 16) |
  191. (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_CLKDivision << 20) |
  192. (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataLatency << 24) |
  193. FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AccessMode;
  194. FSMC_Bank1->BTCR[FSMC_NORSRAMInitStruct->FSMC_Bank+1] = tmpbtr;
  195. /* Bank1 NOR/SRAM timing register for write configuration, if extended mode is used */
  196. if(FSMC_NORSRAMInitStruct->FSMC_ExtendedMode == FSMC_ExtendedMode_Enable)
  197. {
  198. assert_param(IS_FSMC_ADDRESS_SETUP_TIME(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressSetupTime));
  199. assert_param(IS_FSMC_ADDRESS_HOLD_TIME(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressHoldTime));
  200. assert_param(IS_FSMC_DATASETUP_TIME(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataSetupTime));
  201. assert_param(IS_FSMC_TURNAROUND_TIME(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_BusTurnAroundDuration));
  202. assert_param(IS_FSMC_ACCESS_MODE(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AccessMode));
  203. /* Get the BWTR register value */
  204. tmpbwr = FSMC_Bank1E->BWTR[FSMC_NORSRAMInitStruct->FSMC_Bank];
  205. /* Clear ADDSET, ADDHLD, DATAST, BUSTURN, and ACCMOD bits */
  206. tmpbwr &= ((uint32_t)~(FSMC_BWTR1_ADDSET | FSMC_BWTR1_ADDHLD | FSMC_BWTR1_DATAST | \
  207. FSMC_BWTR1_BUSTURN | FSMC_BWTR1_ACCMOD));
  208. tmpbwr |= (uint32_t)FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressSetupTime |
  209. (FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressHoldTime << 4 )|
  210. (FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataSetupTime << 8) |
  211. (FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_BusTurnAroundDuration << 16) |
  212. FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AccessMode;
  213. FSMC_Bank1E->BWTR[FSMC_NORSRAMInitStruct->FSMC_Bank] = tmpbwr;
  214. }
  215. else
  216. {
  217. FSMC_Bank1E->BWTR[FSMC_NORSRAMInitStruct->FSMC_Bank] = 0x0FFFFFFF;
  218. }
  219. }
  220. /**
  221. * @brief Fills each FSMC_NORSRAMInitStruct member with its default value.
  222. * @param FSMC_NORSRAMInitStruct: pointer to a FSMC_NORSRAMInitTypeDef structure
  223. * which will be initialized.
  224. * @retval None
  225. */
  226. void FSMC_NORSRAMStructInit(FSMC_NORSRAMInitTypeDef* FSMC_NORSRAMInitStruct)
  227. {
  228. /* Reset NOR/SRAM Init structure parameters values */
  229. FSMC_NORSRAMInitStruct->FSMC_Bank = FSMC_Bank1_NORSRAM1;
  230. FSMC_NORSRAMInitStruct->FSMC_DataAddressMux = FSMC_DataAddressMux_Enable;
  231. FSMC_NORSRAMInitStruct->FSMC_MemoryType = FSMC_MemoryType_SRAM;
  232. FSMC_NORSRAMInitStruct->FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
  233. FSMC_NORSRAMInitStruct->FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
  234. FSMC_NORSRAMInitStruct->FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
  235. FSMC_NORSRAMInitStruct->FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
  236. FSMC_NORSRAMInitStruct->FSMC_WrapMode = FSMC_WrapMode_Disable;
  237. FSMC_NORSRAMInitStruct->FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
  238. FSMC_NORSRAMInitStruct->FSMC_WriteOperation = FSMC_WriteOperation_Enable;
  239. FSMC_NORSRAMInitStruct->FSMC_WaitSignal = FSMC_WaitSignal_Enable;
  240. FSMC_NORSRAMInitStruct->FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
  241. FSMC_NORSRAMInitStruct->FSMC_WriteBurst = FSMC_WriteBurst_Disable;
  242. FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct = (FSMC_NORSRAMTimingInitTypeDef*)((uint32_t)&FSMC_DefaultTimingStruct);
  243. FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct = (FSMC_NORSRAMTimingInitTypeDef*)((uint32_t)&FSMC_DefaultTimingStruct);
  244. }
  245. /**
  246. * @brief Enables or disables the specified NOR/SRAM Memory Bank.
  247. * @param FSMC_Bank: specifies the FSMC Bank to be used
  248. * This parameter can be one of the following values:
  249. * @arg FSMC_Bank1_NORSRAM1: FSMC Bank1 NOR/SRAM1
  250. * @arg FSMC_Bank1_NORSRAM2: FSMC Bank1 NOR/SRAM2
  251. * @arg FSMC_Bank1_NORSRAM3: FSMC Bank1 NOR/SRAM3
  252. * @arg FSMC_Bank1_NORSRAM4: FSMC Bank1 NOR/SRAM4
  253. * @param NewState: new state of the FSMC_Bank. This parameter can be: ENABLE or DISABLE.
  254. * @retval None
  255. */
  256. void FSMC_NORSRAMCmd(uint32_t FSMC_Bank, FunctionalState NewState)
  257. {
  258. assert_param(IS_FSMC_NORSRAM_BANK(FSMC_Bank));
  259. assert_param(IS_FUNCTIONAL_STATE(NewState));
  260. if (NewState != DISABLE)
  261. {
  262. /* Enable the selected NOR/SRAM Bank by setting the PBKEN bit in the BCRx register */
  263. FSMC_Bank1->BTCR[FSMC_Bank] |= BCR_MBKEN_SET;
  264. }
  265. else
  266. {
  267. /* Disable the selected NOR/SRAM Bank by clearing the PBKEN bit in the BCRx register */
  268. FSMC_Bank1->BTCR[FSMC_Bank] &= BCR_MBKEN_RESET;
  269. }
  270. }
  271. /**
  272. * @}
  273. */
  274. /** @defgroup FSMC_Group2 NAND Controller functions
  275. * @brief NAND Controller functions
  276. *
  277. @verbatim
  278. ===============================================================================
  279. ##### NAND Controller functions #####
  280. ===============================================================================
  281. [..] The following sequence should be followed to configure the FSMC to interface
  282. with 8-bit or 16-bit NAND memory connected to the NAND Bank:
  283. (#) Enable the clock for the FSMC and associated GPIOs using the following functions:
  284. (++) RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE);
  285. (++) RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE);
  286. (#) FSMC pins configuration
  287. (++) Connect the involved FSMC pins to AF12 using the following function
  288. GPIO_PinAFConfig(GPIOx, GPIO_PinSourcex, GPIO_AF_FSMC);
  289. (++) Configure these FSMC pins in alternate function mode by calling the function
  290. GPIO_Init();
  291. (#) Declare a FSMC_NANDInitTypeDef structure, for example:
  292. FSMC_NANDInitTypeDef FSMC_NANDInitStructure;
  293. and fill the FSMC_NANDInitStructure variable with the allowed values of
  294. the structure member.
  295. (#) Initialize the NAND Controller by calling the function
  296. FSMC_NANDInit(&FSMC_NANDInitStructure);
  297. (#) Then enable the NAND Bank, for example:
  298. FSMC_NANDCmd(FSMC_Bank3_NAND, ENABLE);
  299. (#) At this stage you can read/write from/to the memory connected to the NAND Bank.
  300. [..]
  301. (@) To enable the Error Correction Code (ECC), you have to use the function
  302. FSMC_NANDECCCmd(FSMC_Bank3_NAND, ENABLE);
  303. [..]
  304. (@) and to get the current ECC value you have to use the function
  305. ECCval = FSMC_GetECC(FSMC_Bank3_NAND);
  306. @endverbatim
  307. * @{
  308. */
  309. /**
  310. * @brief De-initializes the FSMC NAND Banks registers to their default reset values.
  311. * @param FSMC_Bank: specifies the FSMC Bank to be used
  312. * This parameter can be one of the following values:
  313. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  314. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  315. * @retval None
  316. */
  317. void FSMC_NANDDeInit(uint32_t FSMC_Bank)
  318. {
  319. /* Check the parameter */
  320. assert_param(IS_FSMC_NAND_BANK(FSMC_Bank));
  321. if(FSMC_Bank == FSMC_Bank2_NAND)
  322. {
  323. /* Set the FSMC_Bank2 registers to their reset values */
  324. FSMC_Bank2->PCR2 = 0x00000018;
  325. FSMC_Bank2->SR2 = 0x00000040;
  326. FSMC_Bank2->PMEM2 = 0xFCFCFCFC;
  327. FSMC_Bank2->PATT2 = 0xFCFCFCFC;
  328. }
  329. /* FSMC_Bank3_NAND */
  330. else
  331. {
  332. /* Set the FSMC_Bank3 registers to their reset values */
  333. FSMC_Bank3->PCR3 = 0x00000018;
  334. FSMC_Bank3->SR3 = 0x00000040;
  335. FSMC_Bank3->PMEM3 = 0xFCFCFCFC;
  336. FSMC_Bank3->PATT3 = 0xFCFCFCFC;
  337. }
  338. }
  339. /**
  340. * @brief Initializes the FSMC NAND Banks according to the specified parameters
  341. * in the FSMC_NANDInitStruct.
  342. * @param FSMC_NANDInitStruct : pointer to a FSMC_NANDInitTypeDef structure that
  343. * contains the configuration information for the FSMC NAND specified Banks.
  344. * @retval None
  345. */
  346. void FSMC_NANDInit(FSMC_NANDInitTypeDef* FSMC_NANDInitStruct)
  347. {
  348. uint32_t tmppcr = 0x00000000, tmppmem = 0x00000000, tmppatt = 0x00000000;
  349. /* Check the parameters */
  350. assert_param( IS_FSMC_NAND_BANK(FSMC_NANDInitStruct->FSMC_Bank));
  351. assert_param( IS_FSMC_WAIT_FEATURE(FSMC_NANDInitStruct->FSMC_Waitfeature));
  352. assert_param( IS_FSMC_MEMORY_WIDTH(FSMC_NANDInitStruct->FSMC_MemoryDataWidth));
  353. assert_param( IS_FSMC_ECC_STATE(FSMC_NANDInitStruct->FSMC_ECC));
  354. assert_param( IS_FSMC_ECCPAGE_SIZE(FSMC_NANDInitStruct->FSMC_ECCPageSize));
  355. assert_param( IS_FSMC_TCLR_TIME(FSMC_NANDInitStruct->FSMC_TCLRSetupTime));
  356. assert_param( IS_FSMC_TAR_TIME(FSMC_NANDInitStruct->FSMC_TARSetupTime));
  357. assert_param(IS_FSMC_SETUP_TIME(FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime));
  358. assert_param(IS_FSMC_WAIT_TIME(FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime));
  359. assert_param(IS_FSMC_HOLD_TIME(FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime));
  360. assert_param(IS_FSMC_HIZ_TIME(FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime));
  361. assert_param(IS_FSMC_SETUP_TIME(FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime));
  362. assert_param(IS_FSMC_WAIT_TIME(FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime));
  363. assert_param(IS_FSMC_HOLD_TIME(FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime));
  364. assert_param(IS_FSMC_HIZ_TIME(FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime));
  365. if(FSMC_NANDInitStruct->FSMC_Bank == FSMC_Bank2_NAND)
  366. {
  367. /* Get the NAND bank 2 register value */
  368. tmppcr = FSMC_Bank2->PCR2;
  369. }
  370. else
  371. {
  372. /* Get the NAND bank 3 register value */
  373. tmppcr = FSMC_Bank3->PCR3;
  374. }
  375. /* Clear PWAITEN, PBKEN, PTYP, PWID, ECCEN, TCLR, TAR and ECCPS bits */
  376. tmppcr &= ((uint32_t)~(FSMC_PCR2_PWAITEN | FSMC_PCR2_PBKEN | FSMC_PCR2_PTYP | \
  377. FSMC_PCR2_PWID | FSMC_PCR2_ECCEN | FSMC_PCR2_TCLR | \
  378. FSMC_PCR2_TAR | FSMC_PCR2_ECCPS));
  379. /* Set the tmppcr value according to FSMC_NANDInitStruct parameters */
  380. tmppcr |= (uint32_t)FSMC_NANDInitStruct->FSMC_Waitfeature |
  381. PCR_MEMORYTYPE_NAND |
  382. FSMC_NANDInitStruct->FSMC_MemoryDataWidth |
  383. FSMC_NANDInitStruct->FSMC_ECC |
  384. FSMC_NANDInitStruct->FSMC_ECCPageSize |
  385. (FSMC_NANDInitStruct->FSMC_TCLRSetupTime << 9 )|
  386. (FSMC_NANDInitStruct->FSMC_TARSetupTime << 13);
  387. if(FSMC_NANDInitStruct->FSMC_Bank == FSMC_Bank2_NAND)
  388. {
  389. /* Get the NAND bank 2 register value */
  390. tmppmem = FSMC_Bank2->PMEM2;
  391. }
  392. else
  393. {
  394. /* Get the NAND bank 3 register value */
  395. tmppmem = FSMC_Bank3->PMEM3;
  396. }
  397. /* Clear MEMSETx, MEMWAITx, MEMHOLDx and MEMHIZx bits */
  398. tmppmem &= ((uint32_t)~(FSMC_PMEM2_MEMSET2 | FSMC_PMEM2_MEMWAIT2 | FSMC_PMEM2_MEMHOLD2 | \
  399. FSMC_PMEM2_MEMHIZ2));
  400. /* Set tmppmem value according to FSMC_CommonSpaceTimingStructure parameters */
  401. tmppmem |= (uint32_t)FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime |
  402. (FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
  403. (FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
  404. (FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime << 24);
  405. if(FSMC_NANDInitStruct->FSMC_Bank == FSMC_Bank2_NAND)
  406. {
  407. /* Get the NAND bank 2 register value */
  408. tmppatt = FSMC_Bank2->PATT2;
  409. }
  410. else
  411. {
  412. /* Get the NAND bank 3 register value */
  413. tmppatt = FSMC_Bank3->PATT3;
  414. }
  415. /* Clear ATTSETx, ATTWAITx, ATTHOLDx and ATTHIZx bits */
  416. tmppatt &= ((uint32_t)~(FSMC_PATT2_ATTSET2 | FSMC_PATT2_ATTWAIT2 | FSMC_PATT2_ATTHOLD2 | \
  417. FSMC_PATT2_ATTHIZ2));
  418. /* Set tmppatt value according to FSMC_AttributeSpaceTimingStructure parameters */
  419. tmppatt |= (uint32_t)FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime |
  420. (FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
  421. (FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
  422. (FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime << 24);
  423. if(FSMC_NANDInitStruct->FSMC_Bank == FSMC_Bank2_NAND)
  424. {
  425. /* FSMC_Bank2_NAND registers configuration */
  426. FSMC_Bank2->PCR2 = tmppcr;
  427. FSMC_Bank2->PMEM2 = tmppmem;
  428. FSMC_Bank2->PATT2 = tmppatt;
  429. }
  430. else
  431. {
  432. /* FSMC_Bank3_NAND registers configuration */
  433. FSMC_Bank3->PCR3 = tmppcr;
  434. FSMC_Bank3->PMEM3 = tmppmem;
  435. FSMC_Bank3->PATT3 = tmppatt;
  436. }
  437. }
  438. /**
  439. * @brief Fills each FSMC_NANDInitStruct member with its default value.
  440. * @param FSMC_NANDInitStruct: pointer to a FSMC_NANDInitTypeDef structure which
  441. * will be initialized.
  442. * @retval None
  443. */
  444. void FSMC_NANDStructInit(FSMC_NANDInitTypeDef* FSMC_NANDInitStruct)
  445. {
  446. /* Reset NAND Init structure parameters values */
  447. FSMC_NANDInitStruct->FSMC_Bank = FSMC_Bank2_NAND;
  448. FSMC_NANDInitStruct->FSMC_Waitfeature = FSMC_Waitfeature_Disable;
  449. FSMC_NANDInitStruct->FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
  450. FSMC_NANDInitStruct->FSMC_ECC = FSMC_ECC_Disable;
  451. FSMC_NANDInitStruct->FSMC_ECCPageSize = FSMC_ECCPageSize_256Bytes;
  452. FSMC_NANDInitStruct->FSMC_TCLRSetupTime = 0x0;
  453. FSMC_NANDInitStruct->FSMC_TARSetupTime = 0x0;
  454. FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime = 0xFC;
  455. FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
  456. FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
  457. FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
  458. FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime = 0xFC;
  459. FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
  460. FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
  461. FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
  462. }
  463. /**
  464. * @brief Enables or disables the specified NAND Memory Bank.
  465. * @param FSMC_Bank: specifies the FSMC Bank to be used
  466. * This parameter can be one of the following values:
  467. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  468. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  469. * @param NewState: new state of the FSMC_Bank. This parameter can be: ENABLE or DISABLE.
  470. * @retval None
  471. */
  472. void FSMC_NANDCmd(uint32_t FSMC_Bank, FunctionalState NewState)
  473. {
  474. assert_param(IS_FSMC_NAND_BANK(FSMC_Bank));
  475. assert_param(IS_FUNCTIONAL_STATE(NewState));
  476. if (NewState != DISABLE)
  477. {
  478. /* Enable the selected NAND Bank by setting the PBKEN bit in the PCRx register */
  479. if(FSMC_Bank == FSMC_Bank2_NAND)
  480. {
  481. FSMC_Bank2->PCR2 |= PCR_PBKEN_SET;
  482. }
  483. else
  484. {
  485. FSMC_Bank3->PCR3 |= PCR_PBKEN_SET;
  486. }
  487. }
  488. else
  489. {
  490. /* Disable the selected NAND Bank by clearing the PBKEN bit in the PCRx register */
  491. if(FSMC_Bank == FSMC_Bank2_NAND)
  492. {
  493. FSMC_Bank2->PCR2 &= PCR_PBKEN_RESET;
  494. }
  495. else
  496. {
  497. FSMC_Bank3->PCR3 &= PCR_PBKEN_RESET;
  498. }
  499. }
  500. }
  501. /**
  502. * @brief Enables or disables the FSMC NAND ECC feature.
  503. * @param FSMC_Bank: specifies the FSMC Bank to be used
  504. * This parameter can be one of the following values:
  505. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  506. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  507. * @param NewState: new state of the FSMC NAND ECC feature.
  508. * This parameter can be: ENABLE or DISABLE.
  509. * @retval None
  510. */
  511. void FSMC_NANDECCCmd(uint32_t FSMC_Bank, FunctionalState NewState)
  512. {
  513. assert_param(IS_FSMC_NAND_BANK(FSMC_Bank));
  514. assert_param(IS_FUNCTIONAL_STATE(NewState));
  515. if (NewState != DISABLE)
  516. {
  517. /* Enable the selected NAND Bank ECC function by setting the ECCEN bit in the PCRx register */
  518. if(FSMC_Bank == FSMC_Bank2_NAND)
  519. {
  520. FSMC_Bank2->PCR2 |= PCR_ECCEN_SET;
  521. }
  522. else
  523. {
  524. FSMC_Bank3->PCR3 |= PCR_ECCEN_SET;
  525. }
  526. }
  527. else
  528. {
  529. /* Disable the selected NAND Bank ECC function by clearing the ECCEN bit in the PCRx register */
  530. if(FSMC_Bank == FSMC_Bank2_NAND)
  531. {
  532. FSMC_Bank2->PCR2 &= PCR_ECCEN_RESET;
  533. }
  534. else
  535. {
  536. FSMC_Bank3->PCR3 &= PCR_ECCEN_RESET;
  537. }
  538. }
  539. }
  540. /**
  541. * @brief Returns the error correction code register value.
  542. * @param FSMC_Bank: specifies the FSMC Bank to be used
  543. * This parameter can be one of the following values:
  544. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  545. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  546. * @retval The Error Correction Code (ECC) value.
  547. */
  548. uint32_t FSMC_GetECC(uint32_t FSMC_Bank)
  549. {
  550. uint32_t eccval = 0x00000000;
  551. if(FSMC_Bank == FSMC_Bank2_NAND)
  552. {
  553. /* Get the ECCR2 register value */
  554. eccval = FSMC_Bank2->ECCR2;
  555. }
  556. else
  557. {
  558. /* Get the ECCR3 register value */
  559. eccval = FSMC_Bank3->ECCR3;
  560. }
  561. /* Return the error correction code value */
  562. return(eccval);
  563. }
  564. /**
  565. * @}
  566. */
  567. /** @defgroup FSMC_Group3 PCCARD Controller functions
  568. * @brief PCCARD Controller functions
  569. *
  570. @verbatim
  571. ===============================================================================
  572. ##### PCCARD Controller functions #####
  573. ===============================================================================
  574. [..] he following sequence should be followed to configure the FSMC to interface
  575. with 16-bit PC Card compatible memory connected to the PCCARD Bank:
  576. (#) Enable the clock for the FSMC and associated GPIOs using the following functions:
  577. (++) RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE);
  578. (++) RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE);
  579. (#) FSMC pins configuration
  580. (++) Connect the involved FSMC pins to AF12 using the following function
  581. GPIO_PinAFConfig(GPIOx, GPIO_PinSourcex, GPIO_AF_FSMC);
  582. (++) Configure these FSMC pins in alternate function mode by calling the function
  583. GPIO_Init();
  584. (#) Declare a FSMC_PCCARDInitTypeDef structure, for example:
  585. FSMC_PCCARDInitTypeDef FSMC_PCCARDInitStructure;
  586. and fill the FSMC_PCCARDInitStructure variable with the allowed values of
  587. the structure member.
  588. (#) Initialize the PCCARD Controller by calling the function
  589. FSMC_PCCARDInit(&FSMC_PCCARDInitStructure);
  590. (#) Then enable the PCCARD Bank:
  591. FSMC_PCCARDCmd(ENABLE);
  592. (#) At this stage you can read/write from/to the memory connected to the PCCARD Bank.
  593. @endverbatim
  594. * @{
  595. */
  596. /**
  597. * @brief De-initializes the FSMC PCCARD Bank registers to their default reset values.
  598. * @param None
  599. * @retval None
  600. */
  601. void FSMC_PCCARDDeInit(void)
  602. {
  603. /* Set the FSMC_Bank4 registers to their reset values */
  604. FSMC_Bank4->PCR4 = 0x00000018;
  605. FSMC_Bank4->SR4 = 0x00000000;
  606. FSMC_Bank4->PMEM4 = 0xFCFCFCFC;
  607. FSMC_Bank4->PATT4 = 0xFCFCFCFC;
  608. FSMC_Bank4->PIO4 = 0xFCFCFCFC;
  609. }
  610. /**
  611. * @brief Initializes the FSMC PCCARD Bank according to the specified parameters
  612. * in the FSMC_PCCARDInitStruct.
  613. * @param FSMC_PCCARDInitStruct : pointer to a FSMC_PCCARDInitTypeDef structure
  614. * that contains the configuration information for the FSMC PCCARD Bank.
  615. * @retval None
  616. */
  617. void FSMC_PCCARDInit(FSMC_PCCARDInitTypeDef* FSMC_PCCARDInitStruct)
  618. {
  619. uint32_t tmppcr4 = 0, tmppmem4 = 0, tmppatt4 = 0, tmppio4 = 0;
  620. /* Check the parameters */
  621. assert_param(IS_FSMC_WAIT_FEATURE(FSMC_PCCARDInitStruct->FSMC_Waitfeature));
  622. assert_param(IS_FSMC_TCLR_TIME(FSMC_PCCARDInitStruct->FSMC_TCLRSetupTime));
  623. assert_param(IS_FSMC_TAR_TIME(FSMC_PCCARDInitStruct->FSMC_TARSetupTime));
  624. assert_param(IS_FSMC_SETUP_TIME(FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime));
  625. assert_param(IS_FSMC_WAIT_TIME(FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime));
  626. assert_param(IS_FSMC_HOLD_TIME(FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime));
  627. assert_param(IS_FSMC_HIZ_TIME(FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime));
  628. assert_param(IS_FSMC_SETUP_TIME(FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime));
  629. assert_param(IS_FSMC_WAIT_TIME(FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime));
  630. assert_param(IS_FSMC_HOLD_TIME(FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime));
  631. assert_param(IS_FSMC_HIZ_TIME(FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime));
  632. assert_param(IS_FSMC_SETUP_TIME(FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_SetupTime));
  633. assert_param(IS_FSMC_WAIT_TIME(FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_WaitSetupTime));
  634. assert_param(IS_FSMC_HOLD_TIME(FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HoldSetupTime));
  635. assert_param(IS_FSMC_HIZ_TIME(FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HiZSetupTime));
  636. /* Get PCCARD control register value */
  637. tmppcr4 = FSMC_Bank4->PCR4;
  638. /* Clear TAR, TCLR, PWAITEN and PWID bits */
  639. tmppcr4 &= ((uint32_t)~(FSMC_PCR4_TAR | FSMC_PCR4_TCLR | FSMC_PCR4_PWAITEN | \
  640. FSMC_PCR4_PWID));
  641. /* Set the PCR4 register value according to FSMC_PCCARDInitStruct parameters */
  642. tmppcr4 |= (uint32_t)FSMC_PCCARDInitStruct->FSMC_Waitfeature |
  643. FSMC_MemoryDataWidth_16b |
  644. (FSMC_PCCARDInitStruct->FSMC_TCLRSetupTime << 9) |
  645. (FSMC_PCCARDInitStruct->FSMC_TARSetupTime << 13);
  646. FSMC_Bank4->PCR4 = tmppcr4;
  647. /* Get PCCARD common space timing register value */
  648. tmppmem4 = FSMC_Bank4->PMEM4;
  649. /* Clear MEMSETx, MEMWAITx, MEMHOLDx and MEMHIZx bits */
  650. tmppmem4 &= ((uint32_t)~(FSMC_PMEM4_MEMSET4 | FSMC_PMEM4_MEMWAIT4 | FSMC_PMEM4_MEMHOLD4 | \
  651. FSMC_PMEM4_MEMHIZ4));
  652. /* Set PMEM4 register value according to FSMC_CommonSpaceTimingStructure parameters */
  653. tmppmem4 |= (uint32_t)FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime |
  654. (FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
  655. (FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
  656. (FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime << 24);
  657. FSMC_Bank4->PMEM4 = tmppmem4;
  658. /* Get PCCARD timing parameters */
  659. tmppatt4 = FSMC_Bank4->PATT4;
  660. /* Clear ATTSETx, ATTWAITx, ATTHOLDx and ATTHIZx bits */
  661. tmppatt4 &= ((uint32_t)~(FSMC_PATT4_ATTSET4 | FSMC_PATT4_ATTWAIT4 | FSMC_PATT4_ATTHOLD4 | \
  662. FSMC_PATT4_ATTHIZ4));
  663. /* Set PATT4 register value according to FSMC_AttributeSpaceTimingStructure parameters */
  664. tmppatt4 |= (uint32_t)FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime |
  665. (FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
  666. (FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
  667. (FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime << 24);
  668. FSMC_Bank4->PATT4 = tmppatt4;
  669. /* Get FSMC_PCCARD device timing parameters */
  670. tmppio4 = FSMC_Bank4->PIO4;
  671. /* Clear IOSET4, IOWAIT4, IOHOLD4 and IOHIZ4 bits */
  672. tmppio4 &= ((uint32_t)~(FSMC_PIO4_IOSET4 | FSMC_PIO4_IOWAIT4 | FSMC_PIO4_IOHOLD4 | \
  673. FSMC_PIO4_IOHIZ4));
  674. /* Set PIO4 register value according to FSMC_IOSpaceTimingStructure parameters */
  675. tmppio4 |= (uint32_t)FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_SetupTime |
  676. (FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
  677. (FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
  678. (FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HiZSetupTime << 24);
  679. FSMC_Bank4->PIO4 = tmppio4;
  680. }
  681. /**
  682. * @brief Fills each FSMC_PCCARDInitStruct member with its default value.
  683. * @param FSMC_PCCARDInitStruct: pointer to a FSMC_PCCARDInitTypeDef structure
  684. * which will be initialized.
  685. * @retval None
  686. */
  687. void FSMC_PCCARDStructInit(FSMC_PCCARDInitTypeDef* FSMC_PCCARDInitStruct)
  688. {
  689. /* Reset PCCARD Init structure parameters values */
  690. FSMC_PCCARDInitStruct->FSMC_Waitfeature = FSMC_Waitfeature_Disable;
  691. FSMC_PCCARDInitStruct->FSMC_TCLRSetupTime = 0x0;
  692. FSMC_PCCARDInitStruct->FSMC_TARSetupTime = 0x0;
  693. FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime = 0xFC;
  694. FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
  695. FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
  696. FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
  697. FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime = 0xFC;
  698. FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
  699. FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
  700. FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
  701. FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_SetupTime = 0xFC;
  702. FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
  703. FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
  704. FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
  705. }
  706. /**
  707. * @brief Enables or disables the PCCARD Memory Bank.
  708. * @param NewState: new state of the PCCARD Memory Bank.
  709. * This parameter can be: ENABLE or DISABLE.
  710. * @retval None
  711. */
  712. void FSMC_PCCARDCmd(FunctionalState NewState)
  713. {
  714. assert_param(IS_FUNCTIONAL_STATE(NewState));
  715. if (NewState != DISABLE)
  716. {
  717. /* Enable the PCCARD Bank by setting the PBKEN bit in the PCR4 register */
  718. FSMC_Bank4->PCR4 |= PCR_PBKEN_SET;
  719. }
  720. else
  721. {
  722. /* Disable the PCCARD Bank by clearing the PBKEN bit in the PCR4 register */
  723. FSMC_Bank4->PCR4 &= PCR_PBKEN_RESET;
  724. }
  725. }
  726. /**
  727. * @}
  728. */
  729. /** @defgroup FSMC_Group4 Interrupts and flags management functions
  730. * @brief Interrupts and flags management functions
  731. *
  732. @verbatim
  733. ===============================================================================
  734. ##### Interrupts and flags management functions #####
  735. ===============================================================================
  736. @endverbatim
  737. * @{
  738. */
  739. /**
  740. * @brief Enables or disables the specified FSMC interrupts.
  741. * @param FSMC_Bank: specifies the FSMC Bank to be used
  742. * This parameter can be one of the following values:
  743. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  744. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  745. * @arg FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
  746. * @param FSMC_IT: specifies the FSMC interrupt sources to be enabled or disabled.
  747. * This parameter can be any combination of the following values:
  748. * @arg FSMC_IT_RisingEdge: Rising edge detection interrupt.
  749. * @arg FSMC_IT_Level: Level edge detection interrupt.
  750. * @arg FSMC_IT_FallingEdge: Falling edge detection interrupt.
  751. * @param NewState: new state of the specified FSMC interrupts.
  752. * This parameter can be: ENABLE or DISABLE.
  753. * @retval None
  754. */
  755. void FSMC_ITConfig(uint32_t FSMC_Bank, uint32_t FSMC_IT, FunctionalState NewState)
  756. {
  757. assert_param(IS_FSMC_IT_BANK(FSMC_Bank));
  758. assert_param(IS_FSMC_IT(FSMC_IT));
  759. assert_param(IS_FUNCTIONAL_STATE(NewState));
  760. if (NewState != DISABLE)
  761. {
  762. /* Enable the selected FSMC_Bank2 interrupts */
  763. if(FSMC_Bank == FSMC_Bank2_NAND)
  764. {
  765. FSMC_Bank2->SR2 |= FSMC_IT;
  766. }
  767. /* Enable the selected FSMC_Bank3 interrupts */
  768. else if (FSMC_Bank == FSMC_Bank3_NAND)
  769. {
  770. FSMC_Bank3->SR3 |= FSMC_IT;
  771. }
  772. /* Enable the selected FSMC_Bank4 interrupts */
  773. else
  774. {
  775. FSMC_Bank4->SR4 |= FSMC_IT;
  776. }
  777. }
  778. else
  779. {
  780. /* Disable the selected FSMC_Bank2 interrupts */
  781. if(FSMC_Bank == FSMC_Bank2_NAND)
  782. {
  783. FSMC_Bank2->SR2 &= (uint32_t)~FSMC_IT;
  784. }
  785. /* Disable the selected FSMC_Bank3 interrupts */
  786. else if (FSMC_Bank == FSMC_Bank3_NAND)
  787. {
  788. FSMC_Bank3->SR3 &= (uint32_t)~FSMC_IT;
  789. }
  790. /* Disable the selected FSMC_Bank4 interrupts */
  791. else
  792. {
  793. FSMC_Bank4->SR4 &= (uint32_t)~FSMC_IT;
  794. }
  795. }
  796. }
  797. /**
  798. * @brief Checks whether the specified FSMC flag is set or not.
  799. * @param FSMC_Bank: specifies the FSMC Bank to be used
  800. * This parameter can be one of the following values:
  801. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  802. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  803. * @arg FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
  804. * @param FSMC_FLAG: specifies the flag to check.
  805. * This parameter can be one of the following values:
  806. * @arg FSMC_FLAG_RisingEdge: Rising edge detection Flag.
  807. * @arg FSMC_FLAG_Level: Level detection Flag.
  808. * @arg FSMC_FLAG_FallingEdge: Falling edge detection Flag.
  809. * @arg FSMC_FLAG_FEMPT: Fifo empty Flag.
  810. * @retval The new state of FSMC_FLAG (SET or RESET).
  811. */
  812. FlagStatus FSMC_GetFlagStatus(uint32_t FSMC_Bank, uint32_t FSMC_FLAG)
  813. {
  814. FlagStatus bitstatus = RESET;
  815. uint32_t tmpsr = 0x00000000;
  816. /* Check the parameters */
  817. assert_param(IS_FSMC_GETFLAG_BANK(FSMC_Bank));
  818. assert_param(IS_FSMC_GET_FLAG(FSMC_FLAG));
  819. if(FSMC_Bank == FSMC_Bank2_NAND)
  820. {
  821. tmpsr = FSMC_Bank2->SR2;
  822. }
  823. else if(FSMC_Bank == FSMC_Bank3_NAND)
  824. {
  825. tmpsr = FSMC_Bank3->SR3;
  826. }
  827. /* FSMC_Bank4_PCCARD*/
  828. else
  829. {
  830. tmpsr = FSMC_Bank4->SR4;
  831. }
  832. /* Get the flag status */
  833. if ((tmpsr & FSMC_FLAG) != (uint16_t)RESET )
  834. {
  835. bitstatus = SET;
  836. }
  837. else
  838. {
  839. bitstatus = RESET;
  840. }
  841. /* Return the flag status */
  842. return bitstatus;
  843. }
  844. /**
  845. * @brief Clears the FSMC's pending flags.
  846. * @param FSMC_Bank: specifies the FSMC Bank to be used
  847. * This parameter can be one of the following values:
  848. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  849. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  850. * @arg FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
  851. * @param FSMC_FLAG: specifies the flag to clear.
  852. * This parameter can be any combination of the following values:
  853. * @arg FSMC_FLAG_RisingEdge: Rising edge detection Flag.
  854. * @arg FSMC_FLAG_Level: Level detection Flag.
  855. * @arg FSMC_FLAG_FallingEdge: Falling edge detection Flag.
  856. * @retval None
  857. */
  858. void FSMC_ClearFlag(uint32_t FSMC_Bank, uint32_t FSMC_FLAG)
  859. {
  860. /* Check the parameters */
  861. assert_param(IS_FSMC_GETFLAG_BANK(FSMC_Bank));
  862. assert_param(IS_FSMC_CLEAR_FLAG(FSMC_FLAG)) ;
  863. if(FSMC_Bank == FSMC_Bank2_NAND)
  864. {
  865. FSMC_Bank2->SR2 &= ~FSMC_FLAG;
  866. }
  867. else if(FSMC_Bank == FSMC_Bank3_NAND)
  868. {
  869. FSMC_Bank3->SR3 &= ~FSMC_FLAG;
  870. }
  871. /* FSMC_Bank4_PCCARD*/
  872. else
  873. {
  874. FSMC_Bank4->SR4 &= ~FSMC_FLAG;
  875. }
  876. }
  877. /**
  878. * @brief Checks whether the specified FSMC interrupt has occurred or not.
  879. * @param FSMC_Bank: specifies the FSMC Bank to be used
  880. * This parameter can be one of the following values:
  881. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  882. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  883. * @arg FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
  884. * @param FSMC_IT: specifies the FSMC interrupt source to check.
  885. * This parameter can be one of the following values:
  886. * @arg FSMC_IT_RisingEdge: Rising edge detection interrupt.
  887. * @arg FSMC_IT_Level: Level edge detection interrupt.
  888. * @arg FSMC_IT_FallingEdge: Falling edge detection interrupt.
  889. * @retval The new state of FSMC_IT (SET or RESET).
  890. */
  891. ITStatus FSMC_GetITStatus(uint32_t FSMC_Bank, uint32_t FSMC_IT)
  892. {
  893. ITStatus bitstatus = RESET;
  894. uint32_t tmpsr = 0x0, itstatus = 0x0, itenable = 0x0;
  895. /* Check the parameters */
  896. assert_param(IS_FSMC_IT_BANK(FSMC_Bank));
  897. assert_param(IS_FSMC_GET_IT(FSMC_IT));
  898. if(FSMC_Bank == FSMC_Bank2_NAND)
  899. {
  900. tmpsr = FSMC_Bank2->SR2;
  901. }
  902. else if(FSMC_Bank == FSMC_Bank3_NAND)
  903. {
  904. tmpsr = FSMC_Bank3->SR3;
  905. }
  906. /* FSMC_Bank4_PCCARD*/
  907. else
  908. {
  909. tmpsr = FSMC_Bank4->SR4;
  910. }
  911. itstatus = tmpsr & FSMC_IT;
  912. itenable = tmpsr & (FSMC_IT >> 3);
  913. if ((itstatus != (uint32_t)RESET) && (itenable != (uint32_t)RESET))
  914. {
  915. bitstatus = SET;
  916. }
  917. else
  918. {
  919. bitstatus = RESET;
  920. }
  921. return bitstatus;
  922. }
  923. /**
  924. * @brief Clears the FSMC's interrupt pending bits.
  925. * @param FSMC_Bank: specifies the FSMC Bank to be used
  926. * This parameter can be one of the following values:
  927. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  928. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  929. * @arg FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
  930. * @param FSMC_IT: specifies the interrupt pending bit to clear.
  931. * This parameter can be any combination of the following values:
  932. * @arg FSMC_IT_RisingEdge: Rising edge detection interrupt.
  933. * @arg FSMC_IT_Level: Level edge detection interrupt.
  934. * @arg FSMC_IT_FallingEdge: Falling edge detection interrupt.
  935. * @retval None
  936. */
  937. void FSMC_ClearITPendingBit(uint32_t FSMC_Bank, uint32_t FSMC_IT)
  938. {
  939. /* Check the parameters */
  940. assert_param(IS_FSMC_IT_BANK(FSMC_Bank));
  941. assert_param(IS_FSMC_IT(FSMC_IT));
  942. if(FSMC_Bank == FSMC_Bank2_NAND)
  943. {
  944. FSMC_Bank2->SR2 &= ~(FSMC_IT >> 3);
  945. }
  946. else if(FSMC_Bank == FSMC_Bank3_NAND)
  947. {
  948. FSMC_Bank3->SR3 &= ~(FSMC_IT >> 3);
  949. }
  950. /* FSMC_Bank4_PCCARD*/
  951. else
  952. {
  953. FSMC_Bank4->SR4 &= ~(FSMC_IT >> 3);
  954. }
  955. }
  956. /**
  957. * @}
  958. */
  959. /**
  960. * @}
  961. */
  962. /**
  963. * @}
  964. */
  965. /**
  966. * @}
  967. */