stm32f4xx_fsmc.c 41 KB

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