Create release.yml
[betaflight.git] / lib / main / STM32F4 / Drivers / STM32F4xx_StdPeriph_Driver / src / stm32f4xx_fmc.c
blob3a346ba9e97df6481dd856d00c089c157c5bef19
1 /**
2 ******************************************************************************
3 * @file stm32f4xx_fmc.c
4 * @author MCD Application Team
5 * @version V1.7.1
6 * @date 20-May-2016
7 * @brief This file provides firmware functions to manage the following
8 * functionalities of the FMC peripheral:
9 * + Interface with SRAM, PSRAM, NOR and OneNAND memories
10 * + Interface with NAND memories
11 * + Interface with 16-bit PC Card compatible memories
12 * + Interface with SDRAM memories
13 * + Interrupts and flags management
15 ******************************************************************************
16 * @attention
18 * <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
20 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
21 * You may not use this file except in compliance with the License.
22 * You may obtain a copy of the License at:
24 * http://www.st.com/software_license_agreement_liberty_v2
26 * Unless required by applicable law or agreed to in writing, software
27 * distributed under the License is distributed on an "AS IS" BASIS,
28 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 * See the License for the specific language governing permissions and
30 * limitations under the License.
32 ******************************************************************************
35 /* Includes ------------------------------------------------------------------*/
36 #include "stm32f4xx_fmc.h"
37 #include "stm32f4xx_rcc.h"
39 /** @addtogroup STM32F4xx_StdPeriph_Driver
40 * @{
43 /** @defgroup FMC
44 * @brief FMC driver modules
45 * @{
46 */
48 /* Private typedef -----------------------------------------------------------*/
49 const FMC_NORSRAMTimingInitTypeDef FMC_DefaultTimingStruct = {0x0F, /* FMC_AddressSetupTime */
50 0x0F, /* FMC_AddressHoldTime */
51 0xFF, /* FMC_DataSetupTime */
52 0x0F, /* FMC_BusTurnAroundDuration */
53 0x0F, /* FMC_CLKDivision */
54 0x0F, /* FMC_DataLatency */
55 FMC_AccessMode_A /* FMC_AccessMode */
57 /* --------------------- FMC registers bit mask ---------------------------- */
58 /* FMC BCRx Mask */
59 #define BCR_MBKEN_SET ((uint32_t)0x00000001)
60 #define BCR_MBKEN_RESET ((uint32_t)0x000FFFFE)
61 #define BCR_FACCEN_SET ((uint32_t)0x00000040)
63 /* FMC PCRx Mask */
64 #define PCR_PBKEN_SET ((uint32_t)0x00000004)
65 #define PCR_PBKEN_RESET ((uint32_t)0x000FFFFB)
66 #define PCR_ECCEN_SET ((uint32_t)0x00000040)
67 #define PCR_ECCEN_RESET ((uint32_t)0x000FFFBF)
68 #define PCR_MEMORYTYPE_NAND ((uint32_t)0x00000008)
70 /* FMC SDCRx write protection Mask*/
71 #define SDCR_WriteProtection_RESET ((uint32_t)0x00007DFF)
73 /* FMC SDCMR Mask*/
74 #define SDCMR_CTB1_RESET ((uint32_t)0x003FFFEF)
75 #define SDCMR_CTB2_RESET ((uint32_t)0x003FFFF7)
76 #define SDCMR_CTB1_2_RESET ((uint32_t)0x003FFFE7)
78 /* Private macro -------------------------------------------------------------*/
79 /* Private variables ---------------------------------------------------------*/
80 /* Private function prototypes -----------------------------------------------*/
81 /* Private functions ---------------------------------------------------------*/
83 /** @defgroup FMC_Private_Functions
84 * @{
87 /** @defgroup FMC_Group1 NOR/SRAM Controller functions
88 * @brief NOR/SRAM Controller functions
90 @verbatim
91 ===============================================================================
92 ##### NOR and SRAM Controller functions #####
93 ===============================================================================
95 [..] The following sequence should be followed to configure the FMC to interface
96 with SRAM, PSRAM, NOR or OneNAND memory connected to the NOR/SRAM Bank:
98 (#) Enable the clock for the FMC and associated GPIOs using the following functions:
99 RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FMC, ENABLE);
100 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE);
102 (#) FMC pins configuration
103 (++) Connect the involved FMC pins to AF12 using the following function
104 GPIO_PinAFConfig(GPIOx, GPIO_PinSourcex, GPIO_AF_FMC);
105 (++) Configure these FMC pins in alternate function mode by calling the function
106 GPIO_Init();
108 (#) Declare a FMC_NORSRAMInitTypeDef structure, for example:
109 FMC_NORSRAMInitTypeDef FMC_NORSRAMInitStructure;
110 and fill the FMC_NORSRAMInitStructure variable with the allowed values of
111 the structure member.
113 (#) Initialize the NOR/SRAM Controller by calling the function
114 FMC_NORSRAMInit(&FMC_NORSRAMInitStructure);
116 (#) Then enable the NOR/SRAM Bank, for example:
117 FMC_NORSRAMCmd(FMC_Bank1_NORSRAM2, ENABLE);
119 (#) At this stage you can read/write from/to the memory connected to the NOR/SRAM Bank.
121 @endverbatim
122 * @{
126 * @brief De-initializes the FMC NOR/SRAM Banks registers to their default
127 * reset values.
128 * @param FMC_Bank: specifies the FMC Bank to be used
129 * This parameter can be one of the following values:
130 * @arg FMC_Bank1_NORSRAM1: FMC Bank1 NOR/SRAM1
131 * @arg FMC_Bank1_NORSRAM2: FMC Bank1 NOR/SRAM2
132 * @arg FMC_Bank1_NORSRAM3: FMC Bank1 NOR/SRAM3
133 * @arg FMC_Bank1_NORSRAM4: FMC Bank1 NOR/SRAM4
134 * @retval None
136 void FMC_NORSRAMDeInit(uint32_t FMC_Bank)
138 /* Check the parameter */
139 assert_param(IS_FMC_NORSRAM_BANK(FMC_Bank));
141 /* FMC_Bank1_NORSRAM1 */
142 if(FMC_Bank == FMC_Bank1_NORSRAM1)
144 FMC_Bank1->BTCR[FMC_Bank] = 0x000030DB;
146 /* FMC_Bank1_NORSRAM2, FMC_Bank1_NORSRAM3 or FMC_Bank1_NORSRAM4 */
147 else
149 FMC_Bank1->BTCR[FMC_Bank] = 0x000030D2;
151 FMC_Bank1->BTCR[FMC_Bank + 1] = 0x0FFFFFFF;
152 FMC_Bank1E->BWTR[FMC_Bank] = 0x0FFFFFFF;
156 * @brief Initializes the FMC NOR/SRAM Banks according to the specified
157 * parameters in the FMC_NORSRAMInitStruct.
158 * @param FMC_NORSRAMInitStruct : pointer to a FMC_NORSRAMInitTypeDef structure
159 * that contains the configuration information for the FMC NOR/SRAM
160 * specified Banks.
161 * @retval None
163 void FMC_NORSRAMInit(FMC_NORSRAMInitTypeDef* FMC_NORSRAMInitStruct)
165 uint32_t tmpr = 0, tmpbcr = 0, tmpbwr = 0;
167 /* Check the parameters */
168 assert_param(IS_FMC_NORSRAM_BANK(FMC_NORSRAMInitStruct->FMC_Bank));
169 assert_param(IS_FMC_MUX(FMC_NORSRAMInitStruct->FMC_DataAddressMux));
170 assert_param(IS_FMC_MEMORY(FMC_NORSRAMInitStruct->FMC_MemoryType));
171 assert_param(IS_FMC_NORSRAM_MEMORY_WIDTH(FMC_NORSRAMInitStruct->FMC_MemoryDataWidth));
172 assert_param(IS_FMC_BURSTMODE(FMC_NORSRAMInitStruct->FMC_BurstAccessMode));
173 assert_param(IS_FMC_WAIT_POLARITY(FMC_NORSRAMInitStruct->FMC_WaitSignalPolarity));
174 assert_param(IS_FMC_WRAP_MODE(FMC_NORSRAMInitStruct->FMC_WrapMode));
175 assert_param(IS_FMC_WAIT_SIGNAL_ACTIVE(FMC_NORSRAMInitStruct->FMC_WaitSignalActive));
176 assert_param(IS_FMC_WRITE_OPERATION(FMC_NORSRAMInitStruct->FMC_WriteOperation));
177 assert_param(IS_FMC_WAITE_SIGNAL(FMC_NORSRAMInitStruct->FMC_WaitSignal));
178 assert_param(IS_FMC_EXTENDED_MODE(FMC_NORSRAMInitStruct->FMC_ExtendedMode));
179 assert_param(IS_FMC_ASYNWAIT(FMC_NORSRAMInitStruct->FMC_AsynchronousWait));
180 assert_param(IS_FMC_WRITE_BURST(FMC_NORSRAMInitStruct->FMC_WriteBurst));
181 assert_param(IS_FMC_CONTINOUS_CLOCK(FMC_NORSRAMInitStruct->FMC_ContinousClock));
182 assert_param(IS_FMC_ADDRESS_SETUP_TIME(FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_AddressSetupTime));
183 assert_param(IS_FMC_ADDRESS_HOLD_TIME(FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_AddressHoldTime));
184 assert_param(IS_FMC_DATASETUP_TIME(FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_DataSetupTime));
185 assert_param(IS_FMC_TURNAROUND_TIME(FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_BusTurnAroundDuration));
186 assert_param(IS_FMC_CLK_DIV(FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_CLKDivision));
187 assert_param(IS_FMC_DATA_LATENCY(FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_DataLatency));
188 assert_param(IS_FMC_ACCESS_MODE(FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_AccessMode));
190 /* Get the BTCR register value */
191 tmpbcr = FMC_Bank1->BTCR[FMC_NORSRAMInitStruct->FMC_Bank];
193 /* Clear MBKEN, MUXEN, MTYP, MWID, FACCEN, BURSTEN, WAITPOL, WRAPMOD, WAITCFG, WREN,
194 WAITEN, EXTMOD, ASYNCWAIT, CBURSTRW and CCLKEN bits */
195 tmpbcr &= ((uint32_t)~(FMC_BCR1_MBKEN | FMC_BCR1_MUXEN | FMC_BCR1_MTYP | \
196 FMC_BCR1_MWID | FMC_BCR1_FACCEN | FMC_BCR1_BURSTEN | \
197 FMC_BCR1_WAITPOL | FMC_BCR1_WRAPMOD | FMC_BCR1_WAITCFG | \
198 FMC_BCR1_WREN | FMC_BCR1_WAITEN | FMC_BCR1_EXTMOD | \
199 FMC_BCR1_ASYNCWAIT| FMC_BCR1_CBURSTRW | FMC_BCR1_CCLKEN));
201 /* NOR/SRAM Bank control register configuration */
202 tmpbcr |= (uint32_t)FMC_NORSRAMInitStruct->FMC_DataAddressMux |
203 FMC_NORSRAMInitStruct->FMC_MemoryType |
204 FMC_NORSRAMInitStruct->FMC_MemoryDataWidth |
205 FMC_NORSRAMInitStruct->FMC_BurstAccessMode |
206 FMC_NORSRAMInitStruct->FMC_WaitSignalPolarity |
207 FMC_NORSRAMInitStruct->FMC_WrapMode |
208 FMC_NORSRAMInitStruct->FMC_WaitSignalActive |
209 FMC_NORSRAMInitStruct->FMC_WriteOperation |
210 FMC_NORSRAMInitStruct->FMC_WaitSignal |
211 FMC_NORSRAMInitStruct->FMC_ExtendedMode |
212 FMC_NORSRAMInitStruct->FMC_AsynchronousWait |
213 FMC_NORSRAMInitStruct->FMC_WriteBurst |
214 FMC_NORSRAMInitStruct->FMC_ContinousClock;
216 FMC_Bank1->BTCR[FMC_NORSRAMInitStruct->FMC_Bank] = tmpbcr;
218 if(FMC_NORSRAMInitStruct->FMC_MemoryType == FMC_MemoryType_NOR)
220 FMC_Bank1->BTCR[FMC_NORSRAMInitStruct->FMC_Bank] |= (uint32_t)BCR_FACCEN_SET;
223 /* Configure Continuous clock feature when bank2..4 is used */
224 if((FMC_NORSRAMInitStruct->FMC_ContinousClock == FMC_CClock_SyncAsync) && (FMC_NORSRAMInitStruct->FMC_Bank != FMC_Bank1_NORSRAM1))
226 tmpr = (uint32_t)((FMC_Bank1->BTCR[FMC_Bank1_NORSRAM1+1]) & ~(((uint32_t)0x0F) << 20));
228 FMC_Bank1->BTCR[FMC_Bank1_NORSRAM1] |= FMC_NORSRAMInitStruct->FMC_ContinousClock;
229 FMC_Bank1->BTCR[FMC_Bank1_NORSRAM1] |= FMC_BurstAccessMode_Enable;
230 FMC_Bank1->BTCR[FMC_Bank1_NORSRAM1+1] = (uint32_t)(tmpr | (((FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_CLKDivision)-1) << 20));
233 /* NOR/SRAM Bank timing register configuration */
234 FMC_Bank1->BTCR[FMC_NORSRAMInitStruct->FMC_Bank+1] =
235 (uint32_t)FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_AddressSetupTime |
236 (FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_AddressHoldTime << 4) |
237 (FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_DataSetupTime << 8) |
238 (FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_BusTurnAroundDuration << 16) |
239 (FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_CLKDivision << 20) |
240 (FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_DataLatency << 24) |
241 FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_AccessMode;
243 /* NOR/SRAM Bank timing register for write configuration, if extended mode is used */
244 if(FMC_NORSRAMInitStruct->FMC_ExtendedMode == FMC_ExtendedMode_Enable)
246 assert_param(IS_FMC_ADDRESS_SETUP_TIME(FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_AddressSetupTime));
247 assert_param(IS_FMC_ADDRESS_HOLD_TIME(FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_AddressHoldTime));
248 assert_param(IS_FMC_DATASETUP_TIME(FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_DataSetupTime));
249 assert_param(IS_FMC_TURNAROUND_TIME(FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_BusTurnAroundDuration));
250 assert_param(IS_FMC_ACCESS_MODE(FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_AccessMode));
252 /* Get the BWTR register value */
253 tmpbwr = FMC_Bank1E->BWTR[FMC_NORSRAMInitStruct->FMC_Bank];
255 /* Clear ADDSET, ADDHLD, DATAST, BUSTURN and ACCMOD bits */
256 tmpbwr &= ((uint32_t)~(FMC_BWTR1_ADDSET | FMC_BWTR1_ADDHLD | FMC_BWTR1_DATAST | \
257 FMC_BWTR1_BUSTURN | FMC_BWTR1_ACCMOD));
259 tmpbwr |= (uint32_t)(FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_AddressSetupTime |
260 (FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_AddressHoldTime << 4)|
261 (FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_DataSetupTime << 8) |
262 (FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_BusTurnAroundDuration << 16) |
263 FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_AccessMode);
265 FMC_Bank1E->BWTR[FMC_NORSRAMInitStruct->FMC_Bank] = tmpbwr;
267 else
269 FMC_Bank1E->BWTR[FMC_NORSRAMInitStruct->FMC_Bank] = 0x0FFFFFFF;
275 * @brief Fills each FMC_NORSRAMInitStruct member with its default value.
276 * @param FMC_NORSRAMInitStruct: pointer to a FMC_NORSRAMInitTypeDef structure
277 * which will be initialized.
278 * @retval None
280 void FMC_NORSRAMStructInit(FMC_NORSRAMInitTypeDef* FMC_NORSRAMInitStruct)
282 /* Reset NOR/SRAM Init structure parameters values */
283 FMC_NORSRAMInitStruct->FMC_Bank = FMC_Bank1_NORSRAM1;
284 FMC_NORSRAMInitStruct->FMC_DataAddressMux = FMC_DataAddressMux_Enable;
285 FMC_NORSRAMInitStruct->FMC_MemoryType = FMC_MemoryType_SRAM;
286 FMC_NORSRAMInitStruct->FMC_MemoryDataWidth = FMC_NORSRAM_MemoryDataWidth_16b;
287 FMC_NORSRAMInitStruct->FMC_BurstAccessMode = FMC_BurstAccessMode_Disable;
288 FMC_NORSRAMInitStruct->FMC_AsynchronousWait = FMC_AsynchronousWait_Disable;
289 FMC_NORSRAMInitStruct->FMC_WaitSignalPolarity = FMC_WaitSignalPolarity_Low;
290 FMC_NORSRAMInitStruct->FMC_WrapMode = FMC_WrapMode_Disable;
291 FMC_NORSRAMInitStruct->FMC_WaitSignalActive = FMC_WaitSignalActive_BeforeWaitState;
292 FMC_NORSRAMInitStruct->FMC_WriteOperation = FMC_WriteOperation_Enable;
293 FMC_NORSRAMInitStruct->FMC_WaitSignal = FMC_WaitSignal_Enable;
294 FMC_NORSRAMInitStruct->FMC_ExtendedMode = FMC_ExtendedMode_Disable;
295 FMC_NORSRAMInitStruct->FMC_WriteBurst = FMC_WriteBurst_Disable;
296 FMC_NORSRAMInitStruct->FMC_ContinousClock = FMC_CClock_SyncOnly;
298 FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct = (FMC_NORSRAMTimingInitTypeDef*)&FMC_DefaultTimingStruct;
299 FMC_NORSRAMInitStruct->FMC_WriteTimingStruct = (FMC_NORSRAMTimingInitTypeDef*)&FMC_DefaultTimingStruct;
303 * @brief Enables or disables the specified NOR/SRAM Memory Bank.
304 * @param FMC_Bank: specifies the FMC Bank to be used
305 * This parameter can be one of the following values:
306 * @arg FMC_Bank1_NORSRAM1: FMC Bank1 NOR/SRAM1
307 * @arg FMC_Bank1_NORSRAM2: FMC Bank1 NOR/SRAM2
308 * @arg FMC_Bank1_NORSRAM3: FMC Bank1 NOR/SRAM3
309 * @arg FMC_Bank1_NORSRAM4: FMC Bank1 NOR/SRAM4
310 * @param NewState: new state of the FMC_Bank. This parameter can be: ENABLE or DISABLE.
311 * @retval None
313 void FMC_NORSRAMCmd(uint32_t FMC_Bank, FunctionalState NewState)
315 assert_param(IS_FMC_NORSRAM_BANK(FMC_Bank));
316 assert_param(IS_FUNCTIONAL_STATE(NewState));
318 if (NewState != DISABLE)
320 /* Enable the selected NOR/SRAM Bank by setting the PBKEN bit in the BCRx register */
321 FMC_Bank1->BTCR[FMC_Bank] |= BCR_MBKEN_SET;
323 else
325 /* Disable the selected NOR/SRAM Bank by clearing the PBKEN bit in the BCRx register */
326 FMC_Bank1->BTCR[FMC_Bank] &= BCR_MBKEN_RESET;
330 * @}
333 /** @defgroup FMC_Group2 NAND Controller functions
334 * @brief NAND Controller functions
336 @verbatim
337 ===============================================================================
338 ##### NAND Controller functions #####
339 ===============================================================================
341 [..] The following sequence should be followed to configure the FMC to interface
342 with 8-bit or 16-bit NAND memory connected to the NAND Bank:
344 (#) Enable the clock for the FMC and associated GPIOs using the following functions:
345 (++) RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FMC, ENABLE);
346 (++) RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE);
348 (#) FMC pins configuration
349 (++) Connect the involved FMC pins to AF12 using the following function
350 GPIO_PinAFConfig(GPIOx, GPIO_PinSourcex, GPIO_AF_FMC);
351 (++) Configure these FMC pins in alternate function mode by calling the function
352 GPIO_Init();
354 (#) Declare a FMC_NANDInitTypeDef structure, for example:
355 FMC_NANDInitTypeDef FMC_NANDInitStructure;
356 and fill the FMC_NANDInitStructure variable with the allowed values of
357 the structure member.
359 (#) Initialize the NAND Controller by calling the function
360 FMC_NANDInit(&FMC_NANDInitStructure);
362 (#) Then enable the NAND Bank, for example:
363 FMC_NANDCmd(FMC_Bank3_NAND, ENABLE);
365 (#) At this stage you can read/write from/to the memory connected to the NAND Bank.
367 [..]
368 (@) To enable the Error Correction Code (ECC), you have to use the function
369 FMC_NANDECCCmd(FMC_Bank3_NAND, ENABLE);
370 [..]
371 (@) and to get the current ECC value you have to use the function
372 ECCval = FMC_GetECC(FMC_Bank3_NAND);
374 @endverbatim
375 * @{
379 * @brief De-initializes the FMC NAND Banks registers to their default reset values.
380 * @param FMC_Bank: specifies the FMC Bank to be used
381 * This parameter can be one of the following values:
382 * @arg FMC_Bank2_NAND: FMC Bank2 NAND
383 * @arg FMC_Bank3_NAND: FMC Bank3 NAND
384 * @retval None
386 void FMC_NANDDeInit(uint32_t FMC_Bank)
388 /* Check the parameter */
389 assert_param(IS_FMC_NAND_BANK(FMC_Bank));
391 if(FMC_Bank == FMC_Bank2_NAND)
393 /* Set the FMC_Bank2 registers to their reset values */
394 FMC_Bank2->PCR2 = 0x00000018;
395 FMC_Bank2->SR2 = 0x00000040;
396 FMC_Bank2->PMEM2 = 0xFCFCFCFC;
397 FMC_Bank2->PATT2 = 0xFCFCFCFC;
399 /* FMC_Bank3_NAND */
400 else
402 /* Set the FMC_Bank3 registers to their reset values */
403 FMC_Bank3->PCR3 = 0x00000018;
404 FMC_Bank3->SR3 = 0x00000040;
405 FMC_Bank3->PMEM3 = 0xFCFCFCFC;
406 FMC_Bank3->PATT3 = 0xFCFCFCFC;
411 * @brief Initializes the FMC NAND Banks according to the specified parameters
412 * in the FMC_NANDInitStruct.
413 * @param FMC_NANDInitStruct : pointer to a FMC_NANDInitTypeDef structure that
414 * contains the configuration information for the FMC NAND specified Banks.
415 * @retval None
417 void FMC_NANDInit(FMC_NANDInitTypeDef* FMC_NANDInitStruct)
419 uint32_t tmppcr = 0x00000000, tmppmem = 0x00000000, tmppatt = 0x00000000;
421 /* Check the parameters */
422 assert_param(IS_FMC_NAND_BANK(FMC_NANDInitStruct->FMC_Bank));
423 assert_param(IS_FMC_WAIT_FEATURE(FMC_NANDInitStruct->FMC_Waitfeature));
424 assert_param(IS_FMC_NAND_MEMORY_WIDTH(FMC_NANDInitStruct->FMC_MemoryDataWidth));
425 assert_param(IS_FMC_ECC_STATE(FMC_NANDInitStruct->FMC_ECC));
426 assert_param(IS_FMC_ECCPAGE_SIZE(FMC_NANDInitStruct->FMC_ECCPageSize));
427 assert_param(IS_FMC_TCLR_TIME(FMC_NANDInitStruct->FMC_TCLRSetupTime));
428 assert_param(IS_FMC_TAR_TIME(FMC_NANDInitStruct->FMC_TARSetupTime));
429 assert_param(IS_FMC_SETUP_TIME(FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_SetupTime));
430 assert_param(IS_FMC_WAIT_TIME(FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_WaitSetupTime));
431 assert_param(IS_FMC_HOLD_TIME(FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HoldSetupTime));
432 assert_param(IS_FMC_HIZ_TIME(FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HiZSetupTime));
433 assert_param(IS_FMC_SETUP_TIME(FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_SetupTime));
434 assert_param(IS_FMC_WAIT_TIME(FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_WaitSetupTime));
435 assert_param(IS_FMC_HOLD_TIME(FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HoldSetupTime));
436 assert_param(IS_FMC_HIZ_TIME(FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HiZSetupTime));
438 if(FMC_NANDInitStruct->FMC_Bank == FMC_Bank2_NAND)
440 /* Get the NAND bank 2 register value */
441 tmppcr = FMC_Bank2->PCR2;
443 else
445 /* Get the NAND bank 3 register value */
446 tmppcr = FMC_Bank3->PCR3;
449 /* Clear PWAITEN, PBKEN, PTYP, PWID, ECCEN, TCLR, TAR and ECCPS bits */
450 tmppcr &= ((uint32_t)~(FMC_PCR2_PWAITEN | FMC_PCR2_PBKEN | FMC_PCR2_PTYP | \
451 FMC_PCR2_PWID | FMC_PCR2_ECCEN | FMC_PCR2_TCLR | \
452 FMC_PCR2_TAR | FMC_PCR2_ECCPS));
454 /* Set the tmppcr value according to FMC_NANDInitStruct parameters */
455 tmppcr |= (uint32_t)FMC_NANDInitStruct->FMC_Waitfeature |
456 PCR_MEMORYTYPE_NAND |
457 FMC_NANDInitStruct->FMC_MemoryDataWidth |
458 FMC_NANDInitStruct->FMC_ECC |
459 FMC_NANDInitStruct->FMC_ECCPageSize |
460 (FMC_NANDInitStruct->FMC_TCLRSetupTime << 9 )|
461 (FMC_NANDInitStruct->FMC_TARSetupTime << 13);
463 if(FMC_NANDInitStruct->FMC_Bank == FMC_Bank2_NAND)
465 /* Get the NAND bank 2 register value */
466 tmppmem = FMC_Bank2->PMEM2;
468 else
470 /* Get the NAND bank 3 register value */
471 tmppmem = FMC_Bank3->PMEM3;
474 /* Clear MEMSETx, MEMWAITx, MEMHOLDx and MEMHIZx bits */
475 tmppmem &= ((uint32_t)~(FMC_PMEM2_MEMSET2 | FMC_PMEM2_MEMWAIT2 | FMC_PMEM2_MEMHOLD2 | \
476 FMC_PMEM2_MEMHIZ2));
478 /* Set tmppmem value according to FMC_CommonSpaceTimingStructure parameters */
479 tmppmem |= (uint32_t)FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_SetupTime |
480 (FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_WaitSetupTime << 8) |
481 (FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HoldSetupTime << 16)|
482 (FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HiZSetupTime << 24);
484 if(FMC_NANDInitStruct->FMC_Bank == FMC_Bank2_NAND)
486 /* Get the NAND bank 2 register value */
487 tmppatt = FMC_Bank2->PATT2;
489 else
491 /* Get the NAND bank 3 register value */
492 tmppatt = FMC_Bank3->PATT3;
495 /* Clear ATTSETx, ATTWAITx, ATTHOLDx and ATTHIZx bits */
496 tmppatt &= ((uint32_t)~(FMC_PATT2_ATTSET2 | FMC_PATT2_ATTWAIT2 | FMC_PATT2_ATTHOLD2 | \
497 FMC_PATT2_ATTHIZ2));
499 /* Set tmppatt value according to FMC_AttributeSpaceTimingStructure parameters */
500 tmppatt |= (uint32_t)FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_SetupTime |
501 (FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_WaitSetupTime << 8) |
502 (FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HoldSetupTime << 16)|
503 (FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HiZSetupTime << 24);
505 if(FMC_NANDInitStruct->FMC_Bank == FMC_Bank2_NAND)
507 /* FMC_Bank2_NAND registers configuration */
508 FMC_Bank2->PCR2 = tmppcr;
509 FMC_Bank2->PMEM2 = tmppmem;
510 FMC_Bank2->PATT2 = tmppatt;
512 else
514 /* FMC_Bank3_NAND registers configuration */
515 FMC_Bank3->PCR3 = tmppcr;
516 FMC_Bank3->PMEM3 = tmppmem;
517 FMC_Bank3->PATT3 = tmppatt;
523 * @brief Fills each FMC_NANDInitStruct member with its default value.
524 * @param FMC_NANDInitStruct: pointer to a FMC_NANDInitTypeDef structure which
525 * will be initialized.
526 * @retval None
528 void FMC_NANDStructInit(FMC_NANDInitTypeDef* FMC_NANDInitStruct)
530 /* Reset NAND Init structure parameters values */
531 FMC_NANDInitStruct->FMC_Bank = FMC_Bank2_NAND;
532 FMC_NANDInitStruct->FMC_Waitfeature = FMC_Waitfeature_Disable;
533 FMC_NANDInitStruct->FMC_MemoryDataWidth = FMC_NAND_MemoryDataWidth_16b;
534 FMC_NANDInitStruct->FMC_ECC = FMC_ECC_Disable;
535 FMC_NANDInitStruct->FMC_ECCPageSize = FMC_ECCPageSize_256Bytes;
536 FMC_NANDInitStruct->FMC_TCLRSetupTime = 0x0;
537 FMC_NANDInitStruct->FMC_TARSetupTime = 0x0;
538 FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_SetupTime = 252;
539 FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_WaitSetupTime = 252;
540 FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HoldSetupTime = 252;
541 FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HiZSetupTime = 252;
542 FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_SetupTime = 252;
543 FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_WaitSetupTime = 252;
544 FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HoldSetupTime = 252;
545 FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HiZSetupTime = 252;
549 * @brief Enables or disables the specified NAND Memory Bank.
550 * @param FMC_Bank: specifies the FMC Bank to be used
551 * This parameter can be one of the following values:
552 * @arg FMC_Bank2_NAND: FMC Bank2 NAND
553 * @arg FMC_Bank3_NAND: FMC Bank3 NAND
554 * @param NewState: new state of the FMC_Bank. This parameter can be: ENABLE or DISABLE.
555 * @retval None
557 void FMC_NANDCmd(uint32_t FMC_Bank, FunctionalState NewState)
559 assert_param(IS_FMC_NAND_BANK(FMC_Bank));
560 assert_param(IS_FUNCTIONAL_STATE(NewState));
562 if (NewState != DISABLE)
564 /* Enable the selected NAND Bank by setting the PBKEN bit in the PCRx register */
565 if(FMC_Bank == FMC_Bank2_NAND)
567 FMC_Bank2->PCR2 |= PCR_PBKEN_SET;
569 else
571 FMC_Bank3->PCR3 |= PCR_PBKEN_SET;
574 else
576 /* Disable the selected NAND Bank by clearing the PBKEN bit in the PCRx register */
577 if(FMC_Bank == FMC_Bank2_NAND)
579 FMC_Bank2->PCR2 &= PCR_PBKEN_RESET;
581 else
583 FMC_Bank3->PCR3 &= PCR_PBKEN_RESET;
588 * @brief Enables or disables the FMC NAND ECC feature.
589 * @param FMC_Bank: specifies the FMC Bank to be used
590 * This parameter can be one of the following values:
591 * @arg FMC_Bank2_NAND: FMC Bank2 NAND
592 * @arg FMC_Bank3_NAND: FMC Bank3 NAND
593 * @param NewState: new state of the FMC NAND ECC feature.
594 * This parameter can be: ENABLE or DISABLE.
595 * @retval None
597 void FMC_NANDECCCmd(uint32_t FMC_Bank, FunctionalState NewState)
599 assert_param(IS_FMC_NAND_BANK(FMC_Bank));
600 assert_param(IS_FUNCTIONAL_STATE(NewState));
602 if (NewState != DISABLE)
604 /* Enable the selected NAND Bank ECC function by setting the ECCEN bit in the PCRx register */
605 if(FMC_Bank == FMC_Bank2_NAND)
607 FMC_Bank2->PCR2 |= PCR_ECCEN_SET;
609 else
611 FMC_Bank3->PCR3 |= PCR_ECCEN_SET;
614 else
616 /* Disable the selected NAND Bank ECC function by clearing the ECCEN bit in the PCRx register */
617 if(FMC_Bank == FMC_Bank2_NAND)
619 FMC_Bank2->PCR2 &= PCR_ECCEN_RESET;
621 else
623 FMC_Bank3->PCR3 &= PCR_ECCEN_RESET;
629 * @brief Returns the error correction code register value.
630 * @param FMC_Bank: specifies the FMC Bank to be used
631 * This parameter can be one of the following values:
632 * @arg FMC_Bank2_NAND: FMC Bank2 NAND
633 * @arg FMC_Bank3_NAND: FMC Bank3 NAND
634 * @retval The Error Correction Code (ECC) value.
636 uint32_t FMC_GetECC(uint32_t FMC_Bank)
638 uint32_t eccval = 0x00000000;
640 if(FMC_Bank == FMC_Bank2_NAND)
642 /* Get the ECCR2 register value */
643 eccval = FMC_Bank2->ECCR2;
645 else
647 /* Get the ECCR3 register value */
648 eccval = FMC_Bank3->ECCR3;
650 /* Return the error correction code value */
651 return(eccval);
654 * @}
657 /** @defgroup FMC_Group3 PCCARD Controller functions
658 * @brief PCCARD Controller functions
660 @verbatim
661 ===============================================================================
662 ##### PCCARD Controller functions #####
663 ===============================================================================
665 [..] he following sequence should be followed to configure the FMC to interface
666 with 16-bit PC Card compatible memory connected to the PCCARD Bank:
668 (#) Enable the clock for the FMC and associated GPIOs using the following functions:
669 (++) RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FMC, ENABLE);
670 (++) RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE);
672 (#) FMC pins configuration
673 (++) Connect the involved FMC pins to AF12 using the following function
674 GPIO_PinAFConfig(GPIOx, GPIO_PinSourcex, GPIO_AF_FMC);
675 (++) Configure these FMC pins in alternate function mode by calling the function
676 GPIO_Init();
678 (#) Declare a FMC_PCCARDInitTypeDef structure, for example:
679 FMC_PCCARDInitTypeDef FMC_PCCARDInitStructure;
680 and fill the FMC_PCCARDInitStructure variable with the allowed values of
681 the structure member.
683 (#) Initialize the PCCARD Controller by calling the function
684 FMC_PCCARDInit(&FMC_PCCARDInitStructure);
686 (#) Then enable the PCCARD Bank:
687 FMC_PCCARDCmd(ENABLE);
689 (#) At this stage you can read/write from/to the memory connected to the PCCARD Bank.
691 @endverbatim
692 * @{
696 * @brief De-initializes the FMC PCCARD Bank registers to their default reset values.
697 * @param None
698 * @retval None
700 void FMC_PCCARDDeInit(void)
702 /* Set the FMC_Bank4 registers to their reset values */
703 FMC_Bank4->PCR4 = 0x00000018;
704 FMC_Bank4->SR4 = 0x00000000;
705 FMC_Bank4->PMEM4 = 0xFCFCFCFC;
706 FMC_Bank4->PATT4 = 0xFCFCFCFC;
707 FMC_Bank4->PIO4 = 0xFCFCFCFC;
711 * @brief Initializes the FMC PCCARD Bank according to the specified parameters
712 * in the FMC_PCCARDInitStruct.
713 * @param FMC_PCCARDInitStruct : pointer to a FMC_PCCARDInitTypeDef structure
714 * that contains the configuration information for the FMC PCCARD Bank.
715 * @retval None
717 void FMC_PCCARDInit(FMC_PCCARDInitTypeDef* FMC_PCCARDInitStruct)
719 /* temporary registers */
720 uint32_t tmppcr = 0, tmpmem = 0, tmppatt = 0, tmppio = 0;
722 /* Check the parameters */
723 assert_param(IS_FMC_WAIT_FEATURE(FMC_PCCARDInitStruct->FMC_Waitfeature));
724 assert_param(IS_FMC_TCLR_TIME(FMC_PCCARDInitStruct->FMC_TCLRSetupTime));
725 assert_param(IS_FMC_TAR_TIME(FMC_PCCARDInitStruct->FMC_TARSetupTime));
727 assert_param(IS_FMC_SETUP_TIME(FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_SetupTime));
728 assert_param(IS_FMC_WAIT_TIME(FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_WaitSetupTime));
729 assert_param(IS_FMC_HOLD_TIME(FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HoldSetupTime));
730 assert_param(IS_FMC_HIZ_TIME(FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HiZSetupTime));
732 assert_param(IS_FMC_SETUP_TIME(FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_SetupTime));
733 assert_param(IS_FMC_WAIT_TIME(FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_WaitSetupTime));
734 assert_param(IS_FMC_HOLD_TIME(FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HoldSetupTime));
735 assert_param(IS_FMC_HIZ_TIME(FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HiZSetupTime));
736 assert_param(IS_FMC_SETUP_TIME(FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_SetupTime));
737 assert_param(IS_FMC_WAIT_TIME(FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_WaitSetupTime));
738 assert_param(IS_FMC_HOLD_TIME(FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_HoldSetupTime));
739 assert_param(IS_FMC_HIZ_TIME(FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_HiZSetupTime));
741 /* Get PCCARD control register value */
742 tmppcr = FMC_Bank4->PCR4;
744 /* Clear TAR, TCLR, PWAITEN and PWID bits */
745 tmppcr &= ((uint32_t)~(FMC_PCR4_TAR | FMC_PCR4_TCLR | FMC_PCR4_PWAITEN | \
746 FMC_PCR4_PWID));
748 /* Set the PCR4 register value according to FMC_PCCARDInitStruct parameters */
749 tmppcr |= (uint32_t)FMC_PCCARDInitStruct->FMC_Waitfeature |
750 FMC_NAND_MemoryDataWidth_16b |
751 (FMC_PCCARDInitStruct->FMC_TCLRSetupTime << 9) |
752 (FMC_PCCARDInitStruct->FMC_TARSetupTime << 13);
754 FMC_Bank4->PCR4 = tmppcr;
756 /* Get PCCARD common space timing register value */
757 tmpmem = FMC_Bank4->PMEM4;
759 /* Clear MEMSETx, MEMWAITx, MEMHOLDx and MEMHIZx bits */
760 tmpmem &= ((uint32_t)~(FMC_PMEM4_MEMSET4 | FMC_PMEM4_MEMWAIT4 | FMC_PMEM4_MEMHOLD4 | \
761 FMC_PMEM4_MEMHIZ4));
763 /* Set PMEM4 register value according to FMC_CommonSpaceTimingStructure parameters */
764 tmpmem |= (uint32_t)FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_SetupTime |
765 (FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_WaitSetupTime << 8) |
766 (FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HoldSetupTime << 16)|
767 (FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HiZSetupTime << 24);
769 FMC_Bank4->PMEM4 = tmpmem;
771 /* Get PCCARD timing parameters */
772 tmppatt = FMC_Bank4->PATT4;
774 /* Clear ATTSETx, ATTWAITx, ATTHOLDx and ATTHIZx bits */
775 tmppatt &= ((uint32_t)~(FMC_PATT4_ATTSET4 | FMC_PATT4_ATTWAIT4 | FMC_PATT4_ATTHOLD4 | \
776 FMC_PATT4_ATTHIZ4));
778 /* Set PATT4 register value according to FMC_AttributeSpaceTimingStructure parameters */
779 tmppatt |= (uint32_t)FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_SetupTime |
780 (FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_WaitSetupTime << 8) |
781 (FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HoldSetupTime << 16)|
782 (FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HiZSetupTime << 24);
784 FMC_Bank4->PATT4 = tmppatt;
786 /* Get FMC_PCCARD device timing parameters */
787 tmppio = FMC_Bank4->PIO4;
789 /* Clear IOSET4, IOWAIT4, IOHOLD4 and IOHIZ4 bits */
790 tmppio &= ((uint32_t)~(FMC_PIO4_IOSET4 | FMC_PIO4_IOWAIT4 | FMC_PIO4_IOHOLD4 | \
791 FMC_PIO4_IOHIZ4));
793 /* Set PIO4 register value according to FMC_IOSpaceTimingStructure parameters */
794 tmppio |= (uint32_t)FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_SetupTime |
795 (FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_WaitSetupTime << 8) |
796 (FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_HoldSetupTime << 16)|
797 (FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_HiZSetupTime << 24);
799 FMC_Bank4->PIO4 = tmppio;
803 * @brief Fills each FMC_PCCARDInitStruct member with its default value.
804 * @param FMC_PCCARDInitStruct: pointer to a FMC_PCCARDInitTypeDef structure
805 * which will be initialized.
806 * @retval None
808 void FMC_PCCARDStructInit(FMC_PCCARDInitTypeDef* FMC_PCCARDInitStruct)
810 /* Reset PCCARD Init structure parameters values */
811 FMC_PCCARDInitStruct->FMC_Waitfeature = FMC_Waitfeature_Disable;
812 FMC_PCCARDInitStruct->FMC_TCLRSetupTime = 0;
813 FMC_PCCARDInitStruct->FMC_TARSetupTime = 0;
814 FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_SetupTime = 252;
815 FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_WaitSetupTime = 252;
816 FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HoldSetupTime = 252;
817 FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HiZSetupTime = 252;
818 FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_SetupTime = 252;
819 FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_WaitSetupTime = 252;
820 FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HoldSetupTime = 252;
821 FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HiZSetupTime = 252;
822 FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_SetupTime = 252;
823 FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_WaitSetupTime = 252;
824 FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_HoldSetupTime = 252;
825 FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_HiZSetupTime = 252;
829 * @brief Enables or disables the PCCARD Memory Bank.
830 * @param NewState: new state of the PCCARD Memory Bank.
831 * This parameter can be: ENABLE or DISABLE.
832 * @retval None
834 void FMC_PCCARDCmd(FunctionalState NewState)
836 assert_param(IS_FUNCTIONAL_STATE(NewState));
838 if (NewState != DISABLE)
840 /* Enable the PCCARD Bank by setting the PBKEN bit in the PCR4 register */
841 FMC_Bank4->PCR4 |= PCR_PBKEN_SET;
843 else
845 /* Disable the PCCARD Bank by clearing the PBKEN bit in the PCR4 register */
846 FMC_Bank4->PCR4 &= PCR_PBKEN_RESET;
851 * @}
854 /** @defgroup FMC_Group4 SDRAM Controller functions
855 * @brief SDRAM Controller functions
857 @verbatim
858 ===============================================================================
859 ##### SDRAM Controller functions #####
860 ===============================================================================
862 [..] The following sequence should be followed to configure the FMC to interface
863 with SDRAM memory connected to the SDRAM Bank 1 or SDRAM bank 2:
865 (#) Enable the clock for the FMC and associated GPIOs using the following functions:
866 (++) RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FMC, ENABLE);
867 (++) RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE);
869 (#) FMC pins configuration
870 (++) Connect the involved FMC pins to AF12 using the following function
871 GPIO_PinAFConfig(GPIOx, GPIO_PinSourcex, GPIO_AF_FMC);
872 (++) Configure these FMC pins in alternate function mode by calling the function
873 GPIO_Init();
875 (#) Declare a FMC_SDRAMInitTypeDef structure, for example:
876 FMC_SDRAMInitTypeDef FMC_SDRAMInitStructure;
877 and fill the FMC_SDRAMInitStructure variable with the allowed values of
878 the structure member.
880 (#) Initialize the SDRAM Controller by calling the function
881 FMC_SDRAMInit(&FMC_SDRAMInitStructure);
883 (#) Declare a FMC_SDRAMCommandTypeDef structure, for example:
884 FMC_SDRAMCommandTypeDef FMC_SDRAMCommandStructure;
885 and fill the FMC_SDRAMCommandStructure variable with the allowed values of
886 the structure member.
888 (#) Configure the SDCMR register with the desired command parameters by calling
889 the function FMC_SDRAMCmdConfig(&FMC_SDRAMCommandStructure);
891 (#) At this stage, the SDRAM memory is ready for any valid command.
893 @endverbatim
894 * @{
898 * @brief De-initializes the FMC SDRAM Banks registers to their default
899 * reset values.
900 * @param FMC_Bank: specifies the FMC Bank to be used
901 * This parameter can be one of the following values:
902 * @arg FMC_Bank1_SDRAM: FMC Bank1 SDRAM
903 * @arg FMC_Bank2_SDRAM: FMC Bank2 SDRAM
904 * @retval None
906 void FMC_SDRAMDeInit(uint32_t FMC_Bank)
908 /* Check the parameter */
909 assert_param(IS_FMC_SDRAM_BANK(FMC_Bank));
911 FMC_Bank5_6->SDCR[FMC_Bank] = 0x000002D0;
912 FMC_Bank5_6->SDTR[FMC_Bank] = 0x0FFFFFFF;
913 FMC_Bank5_6->SDCMR = 0x00000000;
914 FMC_Bank5_6->SDRTR = 0x00000000;
915 FMC_Bank5_6->SDSR = 0x00000000;
919 * @brief Initializes the FMC SDRAM Banks according to the specified
920 * parameters in the FMC_SDRAMInitStruct.
921 * @param FMC_SDRAMInitStruct : pointer to a FMC_SDRAMInitTypeDef structure
922 * that contains the configuration information for the FMC SDRAM
923 * specified Banks.
924 * @retval None
926 void FMC_SDRAMInit(FMC_SDRAMInitTypeDef* FMC_SDRAMInitStruct)
928 /* temporary registers */
929 uint32_t tmpr1 = 0, tmpr2 = 0, tmpr3 = 0, tmpr4 = 0;
931 /* Check the parameters */
933 /* Control parameters */
934 assert_param(IS_FMC_SDRAM_BANK(FMC_SDRAMInitStruct->FMC_Bank));
935 assert_param(IS_FMC_COLUMNBITS_NUMBER(FMC_SDRAMInitStruct->FMC_ColumnBitsNumber));
936 assert_param(IS_FMC_ROWBITS_NUMBER(FMC_SDRAMInitStruct->FMC_RowBitsNumber));
937 assert_param(IS_FMC_SDMEMORY_WIDTH(FMC_SDRAMInitStruct->FMC_SDMemoryDataWidth));
938 assert_param(IS_FMC_INTERNALBANK_NUMBER(FMC_SDRAMInitStruct->FMC_InternalBankNumber));
939 assert_param(IS_FMC_CAS_LATENCY(FMC_SDRAMInitStruct->FMC_CASLatency));
940 assert_param(IS_FMC_WRITE_PROTECTION(FMC_SDRAMInitStruct->FMC_WriteProtection));
941 assert_param(IS_FMC_SDCLOCK_PERIOD(FMC_SDRAMInitStruct->FMC_SDClockPeriod));
942 assert_param(IS_FMC_READ_BURST(FMC_SDRAMInitStruct->FMC_ReadBurst));
943 assert_param(IS_FMC_READPIPE_DELAY(FMC_SDRAMInitStruct->FMC_ReadPipeDelay));
945 /* Timing parameters */
946 assert_param(IS_FMC_LOADTOACTIVE_DELAY(FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_LoadToActiveDelay));
947 assert_param(IS_FMC_EXITSELFREFRESH_DELAY(FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_ExitSelfRefreshDelay));
948 assert_param(IS_FMC_SELFREFRESH_TIME(FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_SelfRefreshTime));
949 assert_param(IS_FMC_ROWCYCLE_DELAY(FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RowCycleDelay));
950 assert_param(IS_FMC_WRITE_RECOVERY_TIME(FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_WriteRecoveryTime));
951 assert_param(IS_FMC_RP_DELAY(FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RPDelay));
952 assert_param(IS_FMC_RCD_DELAY(FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RCDDelay));
954 /* Get SDRAM register value */
955 tmpr1 = FMC_Bank5_6->SDCR[FMC_SDRAMInitStruct->FMC_Bank];
957 /* Clear NC, NR, MWID, NB, CAS, WP, SDCLK, RBURST, and RPIPE bits */
958 tmpr1 &= ((uint32_t)~(FMC_SDCR1_NC | FMC_SDCR1_NR | FMC_SDCR1_MWID | \
959 FMC_SDCR1_NB | FMC_SDCR1_CAS | FMC_SDCR1_WP | \
960 FMC_SDCR1_SDCLK | FMC_SDCR1_RBURST | FMC_SDCR1_RPIPE));
962 /* SDRAM bank control register configuration */
963 tmpr1 |= (uint32_t)FMC_SDRAMInitStruct->FMC_ColumnBitsNumber |
964 FMC_SDRAMInitStruct->FMC_RowBitsNumber |
965 FMC_SDRAMInitStruct->FMC_SDMemoryDataWidth |
966 FMC_SDRAMInitStruct->FMC_InternalBankNumber |
967 FMC_SDRAMInitStruct->FMC_CASLatency |
968 FMC_SDRAMInitStruct->FMC_WriteProtection |
969 FMC_SDRAMInitStruct->FMC_SDClockPeriod |
970 FMC_SDRAMInitStruct->FMC_ReadBurst |
971 FMC_SDRAMInitStruct->FMC_ReadPipeDelay;
973 if(FMC_SDRAMInitStruct->FMC_Bank == FMC_Bank1_SDRAM )
975 FMC_Bank5_6->SDCR[FMC_SDRAMInitStruct->FMC_Bank] = tmpr1;
977 else /* SDCR2 "don't care" bits configuration */
979 /* Get SDCR register value */
980 tmpr3 = FMC_Bank5_6->SDCR[FMC_Bank1_SDRAM];
982 /* Clear NC, NR, MWID, NB, CAS, WP, SDCLK, RBURST, and RPIPE bits */
983 tmpr3 &= ((uint32_t)~(FMC_SDCR1_NC | FMC_SDCR1_NR | FMC_SDCR1_MWID | \
984 FMC_SDCR1_NB | FMC_SDCR1_CAS | FMC_SDCR1_WP | \
985 FMC_SDCR1_SDCLK | FMC_SDCR1_RBURST | FMC_SDCR1_RPIPE));
987 tmpr3 |= (uint32_t)FMC_SDRAMInitStruct->FMC_SDClockPeriod |
988 FMC_SDRAMInitStruct->FMC_ReadBurst |
989 FMC_SDRAMInitStruct->FMC_ReadPipeDelay;
991 FMC_Bank5_6->SDCR[FMC_Bank1_SDRAM] = tmpr3;
992 FMC_Bank5_6->SDCR[FMC_SDRAMInitStruct->FMC_Bank] = tmpr1;
994 /* SDRAM bank timing register configuration */
995 if(FMC_SDRAMInitStruct->FMC_Bank == FMC_Bank1_SDRAM )
997 /* Get SDTR register value */
998 tmpr2 = FMC_Bank5_6->SDTR[FMC_SDRAMInitStruct->FMC_Bank];
1000 /* Clear TMRD, TXSR, TRAS, TRC, TWR, TRP and TRCD bits */
1001 tmpr2 &= ((uint32_t)~(FMC_SDTR1_TMRD | FMC_SDTR1_TXSR | FMC_SDTR1_TRAS | \
1002 FMC_SDTR1_TRC | FMC_SDTR1_TWR | FMC_SDTR1_TRP | \
1003 FMC_SDTR1_TRCD));
1005 tmpr2 |= (uint32_t)((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_LoadToActiveDelay)-1) |
1006 (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_ExitSelfRefreshDelay)-1) << 4) |
1007 (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_SelfRefreshTime)-1) << 8) |
1008 (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RowCycleDelay)-1) << 12) |
1009 (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_WriteRecoveryTime)-1) << 16) |
1010 (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RPDelay)-1) << 20) |
1011 (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RCDDelay)-1) << 24);
1013 FMC_Bank5_6->SDTR[FMC_SDRAMInitStruct->FMC_Bank] = tmpr2;
1015 else /* SDTR "don't care bits configuration */
1017 /* Get SDTR register value */
1018 tmpr2 = FMC_Bank5_6->SDTR[FMC_SDRAMInitStruct->FMC_Bank];
1020 /* Clear TMRD, TXSR, TRAS, TRC, TWR, TRP and TRCD bits */
1021 tmpr2 &= ((uint32_t)~(FMC_SDTR1_TMRD | FMC_SDTR1_TXSR | FMC_SDTR1_TRAS | \
1022 FMC_SDTR1_TRC | FMC_SDTR1_TWR | FMC_SDTR1_TRP | \
1023 FMC_SDTR1_TRCD));
1025 tmpr2 |= (uint32_t)((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_LoadToActiveDelay)-1) |
1026 (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_ExitSelfRefreshDelay)-1) << 4) |
1027 (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_SelfRefreshTime)-1) << 8) |
1028 (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_WriteRecoveryTime)-1) << 16);
1030 /* Get SDTR register value */
1031 tmpr4 = FMC_Bank5_6->SDTR[FMC_Bank1_SDRAM];
1033 /* Clear TMRD, TXSR, TRAS, TRC, TWR, TRP and TRCD bits */
1034 tmpr4 &= ((uint32_t)~(FMC_SDTR1_TMRD | FMC_SDTR1_TXSR | FMC_SDTR1_TRAS | \
1035 FMC_SDTR1_TRC | FMC_SDTR1_TWR | FMC_SDTR1_TRP | \
1036 FMC_SDTR1_TRCD));
1038 tmpr4 |= (uint32_t)(((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RowCycleDelay)-1) << 12) |
1039 (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RPDelay)-1) << 20);
1041 FMC_Bank5_6->SDTR[FMC_Bank1_SDRAM] = tmpr4;
1042 FMC_Bank5_6->SDTR[FMC_SDRAMInitStruct->FMC_Bank] = tmpr2;
1048 * @brief Fills each FMC_SDRAMInitStruct member with its default value.
1049 * @param FMC_SDRAMInitStruct: pointer to a FMC_SDRAMInitTypeDef structure
1050 * which will be initialized.
1051 * @retval None
1053 void FMC_SDRAMStructInit(FMC_SDRAMInitTypeDef* FMC_SDRAMInitStruct)
1055 /* Reset SDRAM Init structure parameters values */
1056 FMC_SDRAMInitStruct->FMC_Bank = FMC_Bank1_SDRAM;
1057 FMC_SDRAMInitStruct->FMC_ColumnBitsNumber = FMC_ColumnBits_Number_8b;
1058 FMC_SDRAMInitStruct->FMC_RowBitsNumber = FMC_RowBits_Number_11b;
1059 FMC_SDRAMInitStruct->FMC_SDMemoryDataWidth = FMC_SDMemory_Width_16b;
1060 FMC_SDRAMInitStruct->FMC_InternalBankNumber = FMC_InternalBank_Number_4;
1061 FMC_SDRAMInitStruct->FMC_CASLatency = FMC_CAS_Latency_1;
1062 FMC_SDRAMInitStruct->FMC_WriteProtection = FMC_Write_Protection_Enable;
1063 FMC_SDRAMInitStruct->FMC_SDClockPeriod = FMC_SDClock_Disable;
1064 FMC_SDRAMInitStruct->FMC_ReadBurst = FMC_Read_Burst_Disable;
1065 FMC_SDRAMInitStruct->FMC_ReadPipeDelay = FMC_ReadPipe_Delay_0;
1067 FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_LoadToActiveDelay = 16;
1068 FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_ExitSelfRefreshDelay = 16;
1069 FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_SelfRefreshTime = 16;
1070 FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RowCycleDelay = 16;
1071 FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_WriteRecoveryTime = 16;
1072 FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RPDelay = 16;
1073 FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RCDDelay = 16;
1078 * @brief Configures the SDRAM memory command issued when the device is accessed.
1079 * @param FMC_SDRAMCommandStruct: pointer to a FMC_SDRAMCommandTypeDef structure
1080 * which will be configured.
1081 * @retval None
1083 void FMC_SDRAMCmdConfig(FMC_SDRAMCommandTypeDef* FMC_SDRAMCommandStruct)
1085 uint32_t tmpr = 0x0;
1087 /* check parameters */
1088 assert_param(IS_FMC_COMMAND_MODE(FMC_SDRAMCommandStruct->FMC_CommandMode));
1089 assert_param(IS_FMC_COMMAND_TARGET(FMC_SDRAMCommandStruct->FMC_CommandTarget));
1090 assert_param(IS_FMC_AUTOREFRESH_NUMBER(FMC_SDRAMCommandStruct->FMC_AutoRefreshNumber));
1091 assert_param(IS_FMC_MODE_REGISTER(FMC_SDRAMCommandStruct->FMC_ModeRegisterDefinition));
1093 tmpr = (uint32_t)(FMC_SDRAMCommandStruct->FMC_CommandMode |
1094 FMC_SDRAMCommandStruct->FMC_CommandTarget |
1095 (((FMC_SDRAMCommandStruct->FMC_AutoRefreshNumber)-1)<<5) |
1096 ((FMC_SDRAMCommandStruct->FMC_ModeRegisterDefinition)<<9));
1098 FMC_Bank5_6->SDCMR = tmpr;
1104 * @brief Returns the indicated FMC SDRAM bank mode status.
1105 * @param SDRAM_Bank: Defines the FMC SDRAM bank. This parameter can be
1106 * FMC_Bank1_SDRAM or FMC_Bank2_SDRAM.
1107 * @retval The FMC SDRAM bank mode status
1109 uint32_t FMC_GetModeStatus(uint32_t SDRAM_Bank)
1111 uint32_t tmpreg = 0;
1113 /* Check the parameter */
1114 assert_param(IS_FMC_SDRAM_BANK(SDRAM_Bank));
1116 /* Get the busy flag status */
1117 if(SDRAM_Bank == FMC_Bank1_SDRAM)
1119 tmpreg = (uint32_t)(FMC_Bank5_6->SDSR & FMC_SDSR_MODES1);
1121 else
1123 tmpreg = ((uint32_t)(FMC_Bank5_6->SDSR & FMC_SDSR_MODES2) >> 2);
1126 /* Return the mode status */
1127 return tmpreg;
1131 * @brief defines the SDRAM Memory Refresh rate.
1132 * @param FMC_Count: specifies the Refresh timer count.
1133 * @retval None
1135 void FMC_SetRefreshCount(uint32_t FMC_Count)
1137 /* check the parameters */
1138 assert_param(IS_FMC_REFRESH_COUNT(FMC_Count));
1140 FMC_Bank5_6->SDRTR |= (FMC_Count<<1);
1145 * @brief Sets the Number of consecutive SDRAM Memory auto Refresh commands.
1146 * @param FMC_Number: specifies the auto Refresh number.
1147 * @retval None
1149 void FMC_SetAutoRefresh_Number(uint32_t FMC_Number)
1151 /* check the parameters */
1152 assert_param(IS_FMC_AUTOREFRESH_NUMBER(FMC_Number));
1154 FMC_Bank5_6->SDCMR |= (FMC_Number << 5);
1158 * @brief Enables or disables write protection to the specified FMC SDRAM Bank.
1159 * @param SDRAM_Bank: Defines the FMC SDRAM bank. This parameter can be
1160 * FMC_Bank1_SDRAM or FMC_Bank2_SDRAM.
1161 * @param NewState: new state of the write protection flag.
1162 * This parameter can be: ENABLE or DISABLE.
1163 * @retval None
1165 void FMC_SDRAMWriteProtectionConfig(uint32_t SDRAM_Bank, FunctionalState NewState)
1167 /* Check the parameter */
1168 assert_param(IS_FUNCTIONAL_STATE(NewState));
1169 assert_param(IS_FMC_SDRAM_BANK(SDRAM_Bank));
1171 if (NewState != DISABLE)
1173 FMC_Bank5_6->SDCR[SDRAM_Bank] |= FMC_Write_Protection_Enable;
1175 else
1177 FMC_Bank5_6->SDCR[SDRAM_Bank] &= SDCR_WriteProtection_RESET;
1183 * @}
1186 /** @defgroup FMC_Group5 Interrupts and flags management functions
1187 * @brief Interrupts and flags management functions
1189 @verbatim
1190 ===============================================================================
1191 ##### Interrupts and flags management functions #####
1192 ===============================================================================
1194 @endverbatim
1195 * @{
1199 * @brief Enables or disables the specified FMC interrupts.
1200 * @param FMC_Bank: specifies the FMC Bank to be used
1201 * This parameter can be one of the following values:
1202 * @arg FMC_Bank2_NAND: FMC Bank2 NAND
1203 * @arg FMC_Bank3_NAND: FMC Bank3 NAND
1204 * @arg FMC_Bank4_PCCARD: FMC Bank4 PCCARD
1205 * @arg FMC_Bank1_SDRAM: FMC Bank1 SDRAM
1206 * @arg FMC_Bank2_SDRAM: FMC Bank2 SDRAM
1207 * @param FMC_IT: specifies the FMC interrupt sources to be enabled or disabled.
1208 * This parameter can be any combination of the following values:
1209 * @arg FMC_IT_RisingEdge: Rising edge detection interrupt.
1210 * @arg FMC_IT_Level: Level edge detection interrupt.
1211 * @arg FMC_IT_FallingEdge: Falling edge detection interrupt.
1212 * @arg FMC_IT_Refresh: Refresh error detection interrupt.
1213 * @param NewState: new state of the specified FMC interrupts.
1214 * This parameter can be: ENABLE or DISABLE.
1215 * @retval None
1217 void FMC_ITConfig(uint32_t FMC_Bank, uint32_t FMC_IT, FunctionalState NewState)
1219 assert_param(IS_FMC_IT_BANK(FMC_Bank));
1220 assert_param(IS_FMC_IT(FMC_IT));
1221 assert_param(IS_FUNCTIONAL_STATE(NewState));
1223 if (NewState != DISABLE)
1225 /* Enable the selected FMC_Bank2 interrupts */
1226 if(FMC_Bank == FMC_Bank2_NAND)
1228 FMC_Bank2->SR2 |= FMC_IT;
1230 /* Enable the selected FMC_Bank3 interrupts */
1231 else if (FMC_Bank == FMC_Bank3_NAND)
1233 FMC_Bank3->SR3 |= FMC_IT;
1235 /* Enable the selected FMC_Bank4 interrupts */
1236 else if (FMC_Bank == FMC_Bank4_PCCARD)
1238 FMC_Bank4->SR4 |= FMC_IT;
1240 /* Enable the selected FMC_Bank5_6 interrupt */
1241 else
1243 /* Enables the interrupt if the refresh error flag is set */
1244 FMC_Bank5_6->SDRTR |= FMC_IT;
1247 else
1249 /* Disable the selected FMC_Bank2 interrupts */
1250 if(FMC_Bank == FMC_Bank2_NAND)
1253 FMC_Bank2->SR2 &= (uint32_t)~FMC_IT;
1255 /* Disable the selected FMC_Bank3 interrupts */
1256 else if (FMC_Bank == FMC_Bank3_NAND)
1258 FMC_Bank3->SR3 &= (uint32_t)~FMC_IT;
1260 /* Disable the selected FMC_Bank4 interrupts */
1261 else if(FMC_Bank == FMC_Bank4_PCCARD)
1263 FMC_Bank4->SR4 &= (uint32_t)~FMC_IT;
1265 /* Disable the selected FMC_Bank5_6 interrupt */
1266 else
1268 /* Disables the interrupt if the refresh error flag is not set */
1269 FMC_Bank5_6->SDRTR &= (uint32_t)~FMC_IT;
1275 * @brief Checks whether the specified FMC flag is set or not.
1276 * @param FMC_Bank: specifies the FMC Bank to be used
1277 * This parameter can be one of the following values:
1278 * @arg FMC_Bank2_NAND: FMC Bank2 NAND
1279 * @arg FMC_Bank3_NAND: FMC Bank3 NAND
1280 * @arg FMC_Bank4_PCCARD: FMC Bank4 PCCARD
1281 * @arg FMC_Bank1_SDRAM: FMC Bank1 SDRAM
1282 * @arg FMC_Bank2_SDRAM: FMC Bank2 SDRAM
1283 * @arg FMC_Bank1_SDRAM | FMC_Bank2_SDRAM: FMC Bank1 or Bank2 SDRAM
1284 * @param FMC_FLAG: specifies the flag to check.
1285 * This parameter can be one of the following values:
1286 * @arg FMC_FLAG_RisingEdge: Rising edge detection Flag.
1287 * @arg FMC_FLAG_Level: Level detection Flag.
1288 * @arg FMC_FLAG_FallingEdge: Falling edge detection Flag.
1289 * @arg FMC_FLAG_FEMPT: Fifo empty Flag.
1290 * @arg FMC_FLAG_Refresh: Refresh error Flag.
1291 * @arg FMC_FLAG_Busy: Busy status Flag.
1292 * @retval The new state of FMC_FLAG (SET or RESET).
1294 FlagStatus FMC_GetFlagStatus(uint32_t FMC_Bank, uint32_t FMC_FLAG)
1296 FlagStatus bitstatus = RESET;
1297 uint32_t tmpsr = 0x00000000;
1299 /* Check the parameters */
1300 assert_param(IS_FMC_GETFLAG_BANK(FMC_Bank));
1301 assert_param(IS_FMC_GET_FLAG(FMC_FLAG));
1303 if(FMC_Bank == FMC_Bank2_NAND)
1305 tmpsr = FMC_Bank2->SR2;
1307 else if(FMC_Bank == FMC_Bank3_NAND)
1309 tmpsr = FMC_Bank3->SR3;
1311 else if(FMC_Bank == FMC_Bank4_PCCARD)
1313 tmpsr = FMC_Bank4->SR4;
1315 else
1317 tmpsr = FMC_Bank5_6->SDSR;
1320 /* Get the flag status */
1321 if ((tmpsr & FMC_FLAG) != FMC_FLAG )
1323 bitstatus = RESET;
1325 else
1327 bitstatus = SET;
1329 /* Return the flag status */
1330 return bitstatus;
1334 * @brief Clears the FMC's pending flags.
1335 * @param FMC_Bank: specifies the FMC Bank to be used
1336 * This parameter can be one of the following values:
1337 * @arg FMC_Bank2_NAND: FMC Bank2 NAND
1338 * @arg FMC_Bank3_NAND: FMC Bank3 NAND
1339 * @arg FMC_Bank4_PCCARD: FMC Bank4 PCCARD
1340 * @arg FMC_Bank1_SDRAM: FMC Bank1 SDRAM
1341 * @arg FMC_Bank2_SDRAM: FMC Bank2 SDRAM
1342 * @param FMC_FLAG: specifies the flag to clear.
1343 * This parameter can be any combination of the following values:
1344 * @arg FMC_FLAG_RisingEdge: Rising edge detection Flag.
1345 * @arg FMC_FLAG_Level: Level detection Flag.
1346 * @arg FMC_FLAG_FallingEdge: Falling edge detection Flag.
1347 * @arg FMC_FLAG_Refresh: Refresh error Flag.
1348 * @retval None
1350 void FMC_ClearFlag(uint32_t FMC_Bank, uint32_t FMC_FLAG)
1352 /* Check the parameters */
1353 assert_param(IS_FMC_GETFLAG_BANK(FMC_Bank));
1354 assert_param(IS_FMC_CLEAR_FLAG(FMC_FLAG)) ;
1356 if(FMC_Bank == FMC_Bank2_NAND)
1358 FMC_Bank2->SR2 &= (~FMC_FLAG);
1360 else if(FMC_Bank == FMC_Bank3_NAND)
1362 FMC_Bank3->SR3 &= (~FMC_FLAG);
1364 else if(FMC_Bank == FMC_Bank4_PCCARD)
1366 FMC_Bank4->SR4 &= (~FMC_FLAG);
1368 /* FMC_Bank5_6 SDRAM*/
1369 else
1371 FMC_Bank5_6->SDRTR &= (~FMC_FLAG);
1377 * @brief Checks whether the specified FMC interrupt has occurred or not.
1378 * @param FMC_Bank: specifies the FMC Bank to be used
1379 * This parameter can be one of the following values:
1380 * @arg FMC_Bank2_NAND: FMC Bank2 NAND
1381 * @arg FMC_Bank3_NAND: FMC Bank3 NAND
1382 * @arg FMC_Bank4_PCCARD: FMC Bank4 PCCARD
1383 * @arg FMC_Bank1_SDRAM: FMC Bank1 SDRAM
1384 * @arg FMC_Bank2_SDRAM: FMC Bank2 SDRAM
1385 * @param FMC_IT: specifies the FMC interrupt source to check.
1386 * This parameter can be one of the following values:
1387 * @arg FMC_IT_RisingEdge: Rising edge detection interrupt.
1388 * @arg FMC_IT_Level: Level edge detection interrupt.
1389 * @arg FMC_IT_FallingEdge: Falling edge detection interrupt.
1390 * @arg FMC_IT_Refresh: Refresh error detection interrupt.
1391 * @retval The new state of FMC_IT (SET or RESET).
1393 ITStatus FMC_GetITStatus(uint32_t FMC_Bank, uint32_t FMC_IT)
1395 ITStatus bitstatus = RESET;
1396 uint32_t tmpsr = 0x0;
1397 uint32_t tmpsr2 = 0x0;
1398 uint32_t itstatus = 0x0;
1399 uint32_t itenable = 0x0;
1401 /* Check the parameters */
1402 assert_param(IS_FMC_IT_BANK(FMC_Bank));
1403 assert_param(IS_FMC_GET_IT(FMC_IT));
1405 if(FMC_Bank == FMC_Bank2_NAND)
1407 tmpsr = FMC_Bank2->SR2;
1409 else if(FMC_Bank == FMC_Bank3_NAND)
1411 tmpsr = FMC_Bank3->SR3;
1413 else if(FMC_Bank == FMC_Bank4_PCCARD)
1415 tmpsr = FMC_Bank4->SR4;
1417 /* FMC_Bank5_6 SDRAM*/
1418 else
1420 tmpsr = FMC_Bank5_6->SDRTR;
1421 tmpsr2 = FMC_Bank5_6->SDSR;
1424 /* get the IT enable bit status*/
1425 itenable = tmpsr & FMC_IT;
1427 /* get the corresponding IT Flag status*/
1428 if((FMC_Bank == FMC_Bank1_SDRAM) || (FMC_Bank == FMC_Bank2_SDRAM))
1430 itstatus = tmpsr2 & FMC_SDSR_RE;
1432 else
1434 itstatus = tmpsr & (FMC_IT >> 3);
1437 if ((itstatus != (uint32_t)RESET) && (itenable != (uint32_t)RESET))
1439 bitstatus = SET;
1441 else
1443 bitstatus = RESET;
1445 return bitstatus;
1449 * @brief Clears the FMC's interrupt pending bits.
1450 * @param FMC_Bank: specifies the FMC Bank to be used
1451 * This parameter can be one of the following values:
1452 * @arg FMC_Bank2_NAND: FMC Bank2 NAND
1453 * @arg FMC_Bank3_NAND: FMC Bank3 NAND
1454 * @arg FMC_Bank4_PCCARD: FMC Bank4 PCCARD
1455 * @arg FMC_Bank1_SDRAM: FMC Bank1 SDRAM
1456 * @arg FMC_Bank2_SDRAM: FMC Bank2 SDRAM
1457 * @param FMC_IT: specifies the interrupt pending bit to clear.
1458 * This parameter can be any combination of the following values:
1459 * @arg FMC_IT_RisingEdge: Rising edge detection interrupt.
1460 * @arg FMC_IT_Level: Level edge detection interrupt.
1461 * @arg FMC_IT_FallingEdge: Falling edge detection interrupt.
1462 * @arg FMC_IT_Refresh: Refresh error detection interrupt.
1463 * @retval None
1465 void FMC_ClearITPendingBit(uint32_t FMC_Bank, uint32_t FMC_IT)
1467 /* Check the parameters */
1468 assert_param(IS_FMC_IT_BANK(FMC_Bank));
1469 assert_param(IS_FMC_IT(FMC_IT));
1471 if(FMC_Bank == FMC_Bank2_NAND)
1473 FMC_Bank2->SR2 &= ~(FMC_IT >> 3);
1475 else if(FMC_Bank == FMC_Bank3_NAND)
1477 FMC_Bank3->SR3 &= ~(FMC_IT >> 3);
1479 else if(FMC_Bank == FMC_Bank4_PCCARD)
1481 FMC_Bank4->SR4 &= ~(FMC_IT >> 3);
1483 /* FMC_Bank5_6 SDRAM*/
1484 else
1486 FMC_Bank5_6->SDRTR |= FMC_SDRTR_CRE;
1491 * @}
1495 * @}
1499 * @}
1503 * @}
1506 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/