25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

990 lines
40 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_fsmc.c
  4. * @author MCD Application Team
  5. * @version V1.1.0
  6. * @date 11-January-2013
  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 2013 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 and SRAM Controller functions #####
  69. ===============================================================================
  70. [..] The following sequence should be followed to configure the FSMC to interface
  71. with SRAM, PSRAM, NOR or OneNAND memory connected to the NOR/SRAM Bank:
  72. (#) 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. (#) 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. (#) 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. (#) Initialize the NOR/SRAM Controller by calling the function
  85. FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
  86. (#) Then enable the NOR/SRAM Bank, for example:
  87. FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM2, ENABLE);
  88. (#) At this stage you can read/write from/to the memory connected to the NOR/SRAM Bank.
  89. @endverbatim
  90. * @{
  91. */
  92. /**
  93. * @brief De-initializes 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
  274. with 8-bit or 16-bit NAND memory connected to the NAND Bank:
  275. (#) 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. (#) 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. (#) 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. (#) Initialize the NAND Controller by calling the function
  288. FSMC_NANDInit(&FSMC_NANDInitStructure);
  289. (#) Then enable the NAND Bank, for example:
  290. FSMC_NANDCmd(FSMC_Bank3_NAND, ENABLE);
  291. (#) At this stage you can read/write from/to the memory connected to the NAND Bank.
  292. [..]
  293. (@) To enable the Error Correction Code (ECC), you have to use the function
  294. FSMC_NANDECCCmd(FSMC_Bank3_NAND, ENABLE);
  295. [..]
  296. (@) and to get the current ECC value you have to use the function
  297. ECCval = FSMC_GetECC(FSMC_Bank3_NAND);
  298. @endverbatim
  299. * @{
  300. */
  301. /**
  302. * @brief De-initializes the FSMC NAND Banks registers to their default reset values.
  303. * @param FSMC_Bank: specifies the FSMC Bank to be used
  304. * This parameter can be one of the following values:
  305. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  306. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  307. * @retval None
  308. */
  309. void FSMC_NANDDeInit(uint32_t FSMC_Bank)
  310. {
  311. /* Check the parameter */
  312. assert_param(IS_FSMC_NAND_BANK(FSMC_Bank));
  313. if(FSMC_Bank == FSMC_Bank2_NAND)
  314. {
  315. /* Set the FSMC_Bank2 registers to their reset values */
  316. FSMC_Bank2->PCR2 = 0x00000018;
  317. FSMC_Bank2->SR2 = 0x00000040;
  318. FSMC_Bank2->PMEM2 = 0xFCFCFCFC;
  319. FSMC_Bank2->PATT2 = 0xFCFCFCFC;
  320. }
  321. /* FSMC_Bank3_NAND */
  322. else
  323. {
  324. /* Set the FSMC_Bank3 registers to their reset values */
  325. FSMC_Bank3->PCR3 = 0x00000018;
  326. FSMC_Bank3->SR3 = 0x00000040;
  327. FSMC_Bank3->PMEM3 = 0xFCFCFCFC;
  328. FSMC_Bank3->PATT3 = 0xFCFCFCFC;
  329. }
  330. }
  331. /**
  332. * @brief Initializes the FSMC NAND Banks according to the specified parameters
  333. * in the FSMC_NANDInitStruct.
  334. * @param FSMC_NANDInitStruct : pointer to a FSMC_NANDInitTypeDef structure that
  335. * contains the configuration information for the FSMC NAND specified Banks.
  336. * @retval None
  337. */
  338. void FSMC_NANDInit(FSMC_NANDInitTypeDef* FSMC_NANDInitStruct)
  339. {
  340. uint32_t tmppcr = 0x00000000, tmppmem = 0x00000000, tmppatt = 0x00000000;
  341. /* Check the parameters */
  342. assert_param( IS_FSMC_NAND_BANK(FSMC_NANDInitStruct->FSMC_Bank));
  343. assert_param( IS_FSMC_WAIT_FEATURE(FSMC_NANDInitStruct->FSMC_Waitfeature));
  344. assert_param( IS_FSMC_MEMORY_WIDTH(FSMC_NANDInitStruct->FSMC_MemoryDataWidth));
  345. assert_param( IS_FSMC_ECC_STATE(FSMC_NANDInitStruct->FSMC_ECC));
  346. assert_param( IS_FSMC_ECCPAGE_SIZE(FSMC_NANDInitStruct->FSMC_ECCPageSize));
  347. assert_param( IS_FSMC_TCLR_TIME(FSMC_NANDInitStruct->FSMC_TCLRSetupTime));
  348. assert_param( IS_FSMC_TAR_TIME(FSMC_NANDInitStruct->FSMC_TARSetupTime));
  349. assert_param(IS_FSMC_SETUP_TIME(FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime));
  350. assert_param(IS_FSMC_WAIT_TIME(FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime));
  351. assert_param(IS_FSMC_HOLD_TIME(FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime));
  352. assert_param(IS_FSMC_HIZ_TIME(FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime));
  353. assert_param(IS_FSMC_SETUP_TIME(FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime));
  354. assert_param(IS_FSMC_WAIT_TIME(FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime));
  355. assert_param(IS_FSMC_HOLD_TIME(FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime));
  356. assert_param(IS_FSMC_HIZ_TIME(FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime));
  357. /* Set the tmppcr value according to FSMC_NANDInitStruct parameters */
  358. tmppcr = (uint32_t)FSMC_NANDInitStruct->FSMC_Waitfeature |
  359. PCR_MEMORYTYPE_NAND |
  360. FSMC_NANDInitStruct->FSMC_MemoryDataWidth |
  361. FSMC_NANDInitStruct->FSMC_ECC |
  362. FSMC_NANDInitStruct->FSMC_ECCPageSize |
  363. (FSMC_NANDInitStruct->FSMC_TCLRSetupTime << 9 )|
  364. (FSMC_NANDInitStruct->FSMC_TARSetupTime << 13);
  365. /* Set tmppmem value according to FSMC_CommonSpaceTimingStructure parameters */
  366. tmppmem = (uint32_t)FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime |
  367. (FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
  368. (FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
  369. (FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime << 24);
  370. /* Set tmppatt value according to FSMC_AttributeSpaceTimingStructure parameters */
  371. tmppatt = (uint32_t)FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime |
  372. (FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
  373. (FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
  374. (FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime << 24);
  375. if(FSMC_NANDInitStruct->FSMC_Bank == FSMC_Bank2_NAND)
  376. {
  377. /* FSMC_Bank2_NAND registers configuration */
  378. FSMC_Bank2->PCR2 = tmppcr;
  379. FSMC_Bank2->PMEM2 = tmppmem;
  380. FSMC_Bank2->PATT2 = tmppatt;
  381. }
  382. else
  383. {
  384. /* FSMC_Bank3_NAND registers configuration */
  385. FSMC_Bank3->PCR3 = tmppcr;
  386. FSMC_Bank3->PMEM3 = tmppmem;
  387. FSMC_Bank3->PATT3 = tmppatt;
  388. }
  389. }
  390. /**
  391. * @brief Fills each FSMC_NANDInitStruct member with its default value.
  392. * @param FSMC_NANDInitStruct: pointer to a FSMC_NANDInitTypeDef structure which
  393. * will be initialized.
  394. * @retval None
  395. */
  396. void FSMC_NANDStructInit(FSMC_NANDInitTypeDef* FSMC_NANDInitStruct)
  397. {
  398. /* Reset NAND Init structure parameters values */
  399. FSMC_NANDInitStruct->FSMC_Bank = FSMC_Bank2_NAND;
  400. FSMC_NANDInitStruct->FSMC_Waitfeature = FSMC_Waitfeature_Disable;
  401. FSMC_NANDInitStruct->FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
  402. FSMC_NANDInitStruct->FSMC_ECC = FSMC_ECC_Disable;
  403. FSMC_NANDInitStruct->FSMC_ECCPageSize = FSMC_ECCPageSize_256Bytes;
  404. FSMC_NANDInitStruct->FSMC_TCLRSetupTime = 0x0;
  405. FSMC_NANDInitStruct->FSMC_TARSetupTime = 0x0;
  406. FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime = 0xFC;
  407. FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
  408. FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
  409. FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
  410. FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime = 0xFC;
  411. FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
  412. FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
  413. FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
  414. }
  415. /**
  416. * @brief Enables or disables the specified NAND Memory Bank.
  417. * @param FSMC_Bank: specifies the FSMC Bank to be used
  418. * This parameter can be one of the following values:
  419. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  420. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  421. * @param NewState: new state of the FSMC_Bank. This parameter can be: ENABLE or DISABLE.
  422. * @retval None
  423. */
  424. void FSMC_NANDCmd(uint32_t FSMC_Bank, FunctionalState NewState)
  425. {
  426. assert_param(IS_FSMC_NAND_BANK(FSMC_Bank));
  427. assert_param(IS_FUNCTIONAL_STATE(NewState));
  428. if (NewState != DISABLE)
  429. {
  430. /* Enable the selected NAND Bank by setting the PBKEN bit in the PCRx register */
  431. if(FSMC_Bank == FSMC_Bank2_NAND)
  432. {
  433. FSMC_Bank2->PCR2 |= PCR_PBKEN_SET;
  434. }
  435. else
  436. {
  437. FSMC_Bank3->PCR3 |= PCR_PBKEN_SET;
  438. }
  439. }
  440. else
  441. {
  442. /* Disable the selected NAND Bank by clearing the PBKEN bit in the PCRx register */
  443. if(FSMC_Bank == FSMC_Bank2_NAND)
  444. {
  445. FSMC_Bank2->PCR2 &= PCR_PBKEN_RESET;
  446. }
  447. else
  448. {
  449. FSMC_Bank3->PCR3 &= PCR_PBKEN_RESET;
  450. }
  451. }
  452. }
  453. /**
  454. * @brief Enables or disables the FSMC NAND ECC feature.
  455. * @param FSMC_Bank: specifies the FSMC Bank to be used
  456. * This parameter can be one of the following values:
  457. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  458. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  459. * @param NewState: new state of the FSMC NAND ECC feature.
  460. * This parameter can be: ENABLE or DISABLE.
  461. * @retval None
  462. */
  463. void FSMC_NANDECCCmd(uint32_t FSMC_Bank, FunctionalState NewState)
  464. {
  465. assert_param(IS_FSMC_NAND_BANK(FSMC_Bank));
  466. assert_param(IS_FUNCTIONAL_STATE(NewState));
  467. if (NewState != DISABLE)
  468. {
  469. /* Enable the selected NAND Bank ECC function by setting the ECCEN bit in the PCRx register */
  470. if(FSMC_Bank == FSMC_Bank2_NAND)
  471. {
  472. FSMC_Bank2->PCR2 |= PCR_ECCEN_SET;
  473. }
  474. else
  475. {
  476. FSMC_Bank3->PCR3 |= PCR_ECCEN_SET;
  477. }
  478. }
  479. else
  480. {
  481. /* Disable the selected NAND Bank ECC function by clearing the ECCEN bit in the PCRx register */
  482. if(FSMC_Bank == FSMC_Bank2_NAND)
  483. {
  484. FSMC_Bank2->PCR2 &= PCR_ECCEN_RESET;
  485. }
  486. else
  487. {
  488. FSMC_Bank3->PCR3 &= PCR_ECCEN_RESET;
  489. }
  490. }
  491. }
  492. /**
  493. * @brief Returns the error correction code register value.
  494. * @param FSMC_Bank: specifies the FSMC Bank to be used
  495. * This parameter can be one of the following values:
  496. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  497. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  498. * @retval The Error Correction Code (ECC) value.
  499. */
  500. uint32_t FSMC_GetECC(uint32_t FSMC_Bank)
  501. {
  502. uint32_t eccval = 0x00000000;
  503. if(FSMC_Bank == FSMC_Bank2_NAND)
  504. {
  505. /* Get the ECCR2 register value */
  506. eccval = FSMC_Bank2->ECCR2;
  507. }
  508. else
  509. {
  510. /* Get the ECCR3 register value */
  511. eccval = FSMC_Bank3->ECCR3;
  512. }
  513. /* Return the error correction code value */
  514. return(eccval);
  515. }
  516. /**
  517. * @}
  518. */
  519. /** @defgroup FSMC_Group3 PCCARD Controller functions
  520. * @brief PCCARD Controller functions
  521. *
  522. @verbatim
  523. ===============================================================================
  524. ##### PCCARD Controller functions #####
  525. ===============================================================================
  526. [..] he following sequence should be followed to configure the FSMC to interface
  527. with 16-bit PC Card compatible memory connected to the PCCARD Bank:
  528. (#) Enable the clock for the FSMC and associated GPIOs using the following functions:
  529. (++) RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE);
  530. (++) RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE);
  531. (#) FSMC pins configuration
  532. (++) Connect the involved FSMC pins to AF12 using the following function
  533. GPIO_PinAFConfig(GPIOx, GPIO_PinSourcex, GPIO_AF_FSMC);
  534. (++) Configure these FSMC pins in alternate function mode by calling the function
  535. GPIO_Init();
  536. (#) Declare a FSMC_PCCARDInitTypeDef structure, for example:
  537. FSMC_PCCARDInitTypeDef FSMC_PCCARDInitStructure;
  538. and fill the FSMC_PCCARDInitStructure variable with the allowed values of
  539. the structure member.
  540. (#) Initialize the PCCARD Controller by calling the function
  541. FSMC_PCCARDInit(&FSMC_PCCARDInitStructure);
  542. (#) Then enable the PCCARD Bank:
  543. FSMC_PCCARDCmd(ENABLE);
  544. (#) At this stage you can read/write from/to the memory connected to the PCCARD Bank.
  545. @endverbatim
  546. * @{
  547. */
  548. /**
  549. * @brief De-initializes the FSMC PCCARD Bank registers to their default reset values.
  550. * @param None
  551. * @retval None
  552. */
  553. void FSMC_PCCARDDeInit(void)
  554. {
  555. /* Set the FSMC_Bank4 registers to their reset values */
  556. FSMC_Bank4->PCR4 = 0x00000018;
  557. FSMC_Bank4->SR4 = 0x00000000;
  558. FSMC_Bank4->PMEM4 = 0xFCFCFCFC;
  559. FSMC_Bank4->PATT4 = 0xFCFCFCFC;
  560. FSMC_Bank4->PIO4 = 0xFCFCFCFC;
  561. }
  562. /**
  563. * @brief Initializes the FSMC PCCARD Bank according to the specified parameters
  564. * in the FSMC_PCCARDInitStruct.
  565. * @param FSMC_PCCARDInitStruct : pointer to a FSMC_PCCARDInitTypeDef structure
  566. * that contains the configuration information for the FSMC PCCARD Bank.
  567. * @retval None
  568. */
  569. void FSMC_PCCARDInit(FSMC_PCCARDInitTypeDef* FSMC_PCCARDInitStruct)
  570. {
  571. /* Check the parameters */
  572. assert_param(IS_FSMC_WAIT_FEATURE(FSMC_PCCARDInitStruct->FSMC_Waitfeature));
  573. assert_param(IS_FSMC_TCLR_TIME(FSMC_PCCARDInitStruct->FSMC_TCLRSetupTime));
  574. assert_param(IS_FSMC_TAR_TIME(FSMC_PCCARDInitStruct->FSMC_TARSetupTime));
  575. assert_param(IS_FSMC_SETUP_TIME(FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime));
  576. assert_param(IS_FSMC_WAIT_TIME(FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime));
  577. assert_param(IS_FSMC_HOLD_TIME(FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime));
  578. assert_param(IS_FSMC_HIZ_TIME(FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime));
  579. assert_param(IS_FSMC_SETUP_TIME(FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime));
  580. assert_param(IS_FSMC_WAIT_TIME(FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime));
  581. assert_param(IS_FSMC_HOLD_TIME(FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime));
  582. assert_param(IS_FSMC_HIZ_TIME(FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime));
  583. assert_param(IS_FSMC_SETUP_TIME(FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_SetupTime));
  584. assert_param(IS_FSMC_WAIT_TIME(FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_WaitSetupTime));
  585. assert_param(IS_FSMC_HOLD_TIME(FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HoldSetupTime));
  586. assert_param(IS_FSMC_HIZ_TIME(FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HiZSetupTime));
  587. /* Set the PCR4 register value according to FSMC_PCCARDInitStruct parameters */
  588. FSMC_Bank4->PCR4 = (uint32_t)FSMC_PCCARDInitStruct->FSMC_Waitfeature |
  589. FSMC_MemoryDataWidth_16b |
  590. (FSMC_PCCARDInitStruct->FSMC_TCLRSetupTime << 9) |
  591. (FSMC_PCCARDInitStruct->FSMC_TARSetupTime << 13);
  592. /* Set PMEM4 register value according to FSMC_CommonSpaceTimingStructure parameters */
  593. FSMC_Bank4->PMEM4 = (uint32_t)FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime |
  594. (FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
  595. (FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
  596. (FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime << 24);
  597. /* Set PATT4 register value according to FSMC_AttributeSpaceTimingStructure parameters */
  598. FSMC_Bank4->PATT4 = (uint32_t)FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime |
  599. (FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
  600. (FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
  601. (FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime << 24);
  602. /* Set PIO4 register value according to FSMC_IOSpaceTimingStructure parameters */
  603. FSMC_Bank4->PIO4 = (uint32_t)FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_SetupTime |
  604. (FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
  605. (FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
  606. (FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HiZSetupTime << 24);
  607. }
  608. /**
  609. * @brief Fills each FSMC_PCCARDInitStruct member with its default value.
  610. * @param FSMC_PCCARDInitStruct: pointer to a FSMC_PCCARDInitTypeDef structure
  611. * which will be initialized.
  612. * @retval None
  613. */
  614. void FSMC_PCCARDStructInit(FSMC_PCCARDInitTypeDef* FSMC_PCCARDInitStruct)
  615. {
  616. /* Reset PCCARD Init structure parameters values */
  617. FSMC_PCCARDInitStruct->FSMC_Waitfeature = FSMC_Waitfeature_Disable;
  618. FSMC_PCCARDInitStruct->FSMC_TCLRSetupTime = 0x0;
  619. FSMC_PCCARDInitStruct->FSMC_TARSetupTime = 0x0;
  620. FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime = 0xFC;
  621. FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
  622. FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
  623. FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
  624. FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime = 0xFC;
  625. FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
  626. FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
  627. FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
  628. FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_SetupTime = 0xFC;
  629. FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
  630. FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
  631. FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
  632. }
  633. /**
  634. * @brief Enables or disables the PCCARD Memory Bank.
  635. * @param NewState: new state of the PCCARD Memory Bank.
  636. * This parameter can be: ENABLE or DISABLE.
  637. * @retval None
  638. */
  639. void FSMC_PCCARDCmd(FunctionalState NewState)
  640. {
  641. assert_param(IS_FUNCTIONAL_STATE(NewState));
  642. if (NewState != DISABLE)
  643. {
  644. /* Enable the PCCARD Bank by setting the PBKEN bit in the PCR4 register */
  645. FSMC_Bank4->PCR4 |= PCR_PBKEN_SET;
  646. }
  647. else
  648. {
  649. /* Disable the PCCARD Bank by clearing the PBKEN bit in the PCR4 register */
  650. FSMC_Bank4->PCR4 &= PCR_PBKEN_RESET;
  651. }
  652. }
  653. /**
  654. * @}
  655. */
  656. /** @defgroup FSMC_Group4 Interrupts and flags management functions
  657. * @brief Interrupts and flags management functions
  658. *
  659. @verbatim
  660. ===============================================================================
  661. ##### Interrupts and flags management functions #####
  662. ===============================================================================
  663. @endverbatim
  664. * @{
  665. */
  666. /**
  667. * @brief Enables or disables the specified FSMC interrupts.
  668. * @param FSMC_Bank: specifies the FSMC Bank to be used
  669. * This parameter can be one of the following values:
  670. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  671. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  672. * @arg FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
  673. * @param FSMC_IT: specifies the FSMC interrupt sources to be enabled or disabled.
  674. * This parameter can be any combination of the following values:
  675. * @arg FSMC_IT_RisingEdge: Rising edge detection interrupt.
  676. * @arg FSMC_IT_Level: Level edge detection interrupt.
  677. * @arg FSMC_IT_FallingEdge: Falling edge detection interrupt.
  678. * @param NewState: new state of the specified FSMC interrupts.
  679. * This parameter can be: ENABLE or DISABLE.
  680. * @retval None
  681. */
  682. void FSMC_ITConfig(uint32_t FSMC_Bank, uint32_t FSMC_IT, FunctionalState NewState)
  683. {
  684. assert_param(IS_FSMC_IT_BANK(FSMC_Bank));
  685. assert_param(IS_FSMC_IT(FSMC_IT));
  686. assert_param(IS_FUNCTIONAL_STATE(NewState));
  687. if (NewState != DISABLE)
  688. {
  689. /* Enable the selected FSMC_Bank2 interrupts */
  690. if(FSMC_Bank == FSMC_Bank2_NAND)
  691. {
  692. FSMC_Bank2->SR2 |= FSMC_IT;
  693. }
  694. /* Enable the selected FSMC_Bank3 interrupts */
  695. else if (FSMC_Bank == FSMC_Bank3_NAND)
  696. {
  697. FSMC_Bank3->SR3 |= FSMC_IT;
  698. }
  699. /* Enable the selected FSMC_Bank4 interrupts */
  700. else
  701. {
  702. FSMC_Bank4->SR4 |= FSMC_IT;
  703. }
  704. }
  705. else
  706. {
  707. /* Disable the selected FSMC_Bank2 interrupts */
  708. if(FSMC_Bank == FSMC_Bank2_NAND)
  709. {
  710. FSMC_Bank2->SR2 &= (uint32_t)~FSMC_IT;
  711. }
  712. /* Disable the selected FSMC_Bank3 interrupts */
  713. else if (FSMC_Bank == FSMC_Bank3_NAND)
  714. {
  715. FSMC_Bank3->SR3 &= (uint32_t)~FSMC_IT;
  716. }
  717. /* Disable the selected FSMC_Bank4 interrupts */
  718. else
  719. {
  720. FSMC_Bank4->SR4 &= (uint32_t)~FSMC_IT;
  721. }
  722. }
  723. }
  724. /**
  725. * @brief Checks whether the specified FSMC flag is set or not.
  726. * @param FSMC_Bank: specifies the FSMC Bank to be used
  727. * This parameter can be one of the following values:
  728. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  729. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  730. * @arg FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
  731. * @param FSMC_FLAG: specifies the flag to check.
  732. * This parameter can be one of the following values:
  733. * @arg FSMC_FLAG_RisingEdge: Rising edge detection Flag.
  734. * @arg FSMC_FLAG_Level: Level detection Flag.
  735. * @arg FSMC_FLAG_FallingEdge: Falling edge detection Flag.
  736. * @arg FSMC_FLAG_FEMPT: Fifo empty Flag.
  737. * @retval The new state of FSMC_FLAG (SET or RESET).
  738. */
  739. FlagStatus FSMC_GetFlagStatus(uint32_t FSMC_Bank, uint32_t FSMC_FLAG)
  740. {
  741. FlagStatus bitstatus = RESET;
  742. uint32_t tmpsr = 0x00000000;
  743. /* Check the parameters */
  744. assert_param(IS_FSMC_GETFLAG_BANK(FSMC_Bank));
  745. assert_param(IS_FSMC_GET_FLAG(FSMC_FLAG));
  746. if(FSMC_Bank == FSMC_Bank2_NAND)
  747. {
  748. tmpsr = FSMC_Bank2->SR2;
  749. }
  750. else if(FSMC_Bank == FSMC_Bank3_NAND)
  751. {
  752. tmpsr = FSMC_Bank3->SR3;
  753. }
  754. /* FSMC_Bank4_PCCARD*/
  755. else
  756. {
  757. tmpsr = FSMC_Bank4->SR4;
  758. }
  759. /* Get the flag status */
  760. if ((tmpsr & FSMC_FLAG) != (uint16_t)RESET )
  761. {
  762. bitstatus = SET;
  763. }
  764. else
  765. {
  766. bitstatus = RESET;
  767. }
  768. /* Return the flag status */
  769. return bitstatus;
  770. }
  771. /**
  772. * @brief Clears the FSMC's pending flags.
  773. * @param FSMC_Bank: specifies the FSMC Bank to be used
  774. * This parameter can be one of the following values:
  775. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  776. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  777. * @arg FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
  778. * @param FSMC_FLAG: specifies the flag to clear.
  779. * This parameter can be any combination of the following values:
  780. * @arg FSMC_FLAG_RisingEdge: Rising edge detection Flag.
  781. * @arg FSMC_FLAG_Level: Level detection Flag.
  782. * @arg FSMC_FLAG_FallingEdge: Falling edge detection Flag.
  783. * @retval None
  784. */
  785. void FSMC_ClearFlag(uint32_t FSMC_Bank, uint32_t FSMC_FLAG)
  786. {
  787. /* Check the parameters */
  788. assert_param(IS_FSMC_GETFLAG_BANK(FSMC_Bank));
  789. assert_param(IS_FSMC_CLEAR_FLAG(FSMC_FLAG)) ;
  790. if(FSMC_Bank == FSMC_Bank2_NAND)
  791. {
  792. FSMC_Bank2->SR2 &= ~FSMC_FLAG;
  793. }
  794. else if(FSMC_Bank == FSMC_Bank3_NAND)
  795. {
  796. FSMC_Bank3->SR3 &= ~FSMC_FLAG;
  797. }
  798. /* FSMC_Bank4_PCCARD*/
  799. else
  800. {
  801. FSMC_Bank4->SR4 &= ~FSMC_FLAG;
  802. }
  803. }
  804. /**
  805. * @brief Checks whether the specified FSMC interrupt has occurred or not.
  806. * @param FSMC_Bank: specifies the FSMC Bank to be used
  807. * This parameter can be one of the following values:
  808. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  809. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  810. * @arg FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
  811. * @param FSMC_IT: specifies the FSMC interrupt source to check.
  812. * This parameter can be one of the following values:
  813. * @arg FSMC_IT_RisingEdge: Rising edge detection interrupt.
  814. * @arg FSMC_IT_Level: Level edge detection interrupt.
  815. * @arg FSMC_IT_FallingEdge: Falling edge detection interrupt.
  816. * @retval The new state of FSMC_IT (SET or RESET).
  817. */
  818. ITStatus FSMC_GetITStatus(uint32_t FSMC_Bank, uint32_t FSMC_IT)
  819. {
  820. ITStatus bitstatus = RESET;
  821. uint32_t tmpsr = 0x0, itstatus = 0x0, itenable = 0x0;
  822. /* Check the parameters */
  823. assert_param(IS_FSMC_IT_BANK(FSMC_Bank));
  824. assert_param(IS_FSMC_GET_IT(FSMC_IT));
  825. if(FSMC_Bank == FSMC_Bank2_NAND)
  826. {
  827. tmpsr = FSMC_Bank2->SR2;
  828. }
  829. else if(FSMC_Bank == FSMC_Bank3_NAND)
  830. {
  831. tmpsr = FSMC_Bank3->SR3;
  832. }
  833. /* FSMC_Bank4_PCCARD*/
  834. else
  835. {
  836. tmpsr = FSMC_Bank4->SR4;
  837. }
  838. itstatus = tmpsr & FSMC_IT;
  839. itenable = tmpsr & (FSMC_IT >> 3);
  840. if ((itstatus != (uint32_t)RESET) && (itenable != (uint32_t)RESET))
  841. {
  842. bitstatus = SET;
  843. }
  844. else
  845. {
  846. bitstatus = RESET;
  847. }
  848. return bitstatus;
  849. }
  850. /**
  851. * @brief Clears the FSMC's interrupt pending bits.
  852. * @param FSMC_Bank: specifies the FSMC Bank to be used
  853. * This parameter can be one of the following values:
  854. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  855. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  856. * @arg FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
  857. * @param FSMC_IT: specifies the interrupt pending bit to clear.
  858. * This parameter can be any combination of the following values:
  859. * @arg FSMC_IT_RisingEdge: Rising edge detection interrupt.
  860. * @arg FSMC_IT_Level: Level edge detection interrupt.
  861. * @arg FSMC_IT_FallingEdge: Falling edge detection interrupt.
  862. * @retval None
  863. */
  864. void FSMC_ClearITPendingBit(uint32_t FSMC_Bank, uint32_t FSMC_IT)
  865. {
  866. /* Check the parameters */
  867. assert_param(IS_FSMC_IT_BANK(FSMC_Bank));
  868. assert_param(IS_FSMC_IT(FSMC_IT));
  869. if(FSMC_Bank == FSMC_Bank2_NAND)
  870. {
  871. FSMC_Bank2->SR2 &= ~(FSMC_IT >> 3);
  872. }
  873. else if(FSMC_Bank == FSMC_Bank3_NAND)
  874. {
  875. FSMC_Bank3->SR3 &= ~(FSMC_IT >> 3);
  876. }
  877. /* FSMC_Bank4_PCCARD*/
  878. else
  879. {
  880. FSMC_Bank4->SR4 &= ~(FSMC_IT >> 3);
  881. }
  882. }
  883. /**
  884. * @}
  885. */
  886. /**
  887. * @}
  888. */
  889. /**
  890. * @}
  891. */
  892. /**
  893. * @}
  894. */
  895. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/