stm32f4xx_fsmc.c 40 KB

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