2 ******************************************************************************
3 * @file stm32f4xx_fsmc.c
4 * @author MCD Application Team
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
14 ******************************************************************************
17 * <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2>
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:
23 * http://www.st.com/software_license_agreement_liberty_v2
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.
31 ******************************************************************************
34 /* Includes ------------------------------------------------------------------*/
35 #include "stm32f4xx_fsmc.h"
36 #include "stm32f4xx_rcc.h"
38 /** @addtogroup STM32F4xx_StdPeriph_Driver
43 * @brief FSMC driver modules
47 /* Private typedef -----------------------------------------------------------*/
48 const FSMC_NORSRAMTimingInitTypeDef FSMC_DefaultTimingStruct
= {0x0F, /* FSMC_AddressSetupTime */
49 0x0F, /* FSMC_AddressHoldTime */
50 0xFF, /* FSMC_DataSetupTime */
51 0x0F, /* FSMC_BusTurnAroundDuration */
52 0x0F, /* FSMC_CLKDivision */
53 0x0F, /* FSMC_DataLatency */
54 FSMC_AccessMode_A
/* FSMC_AccessMode */
56 /* Private define ------------------------------------------------------------*/
58 /* --------------------- FSMC registers bit mask ---------------------------- */
60 #define BCR_MBKEN_SET ((uint32_t)0x00000001)
61 #define BCR_MBKEN_RESET ((uint32_t)0x000FFFFE)
62 #define BCR_FACCEN_SET ((uint32_t)0x00000040)
65 #define PCR_PBKEN_SET ((uint32_t)0x00000004)
66 #define PCR_PBKEN_RESET ((uint32_t)0x000FFFFB)
67 #define PCR_ECCEN_SET ((uint32_t)0x00000040)
68 #define PCR_ECCEN_RESET ((uint32_t)0x000FFFBF)
69 #define PCR_MEMORYTYPE_NAND ((uint32_t)0x00000008)
71 /* Private macro -------------------------------------------------------------*/
72 /* Private variables ---------------------------------------------------------*/
73 /* Private function prototypes -----------------------------------------------*/
74 /* Private functions ---------------------------------------------------------*/
76 /** @defgroup FSMC_Private_Functions
80 /** @defgroup FSMC_Group1 NOR/SRAM Controller functions
81 * @brief NOR/SRAM Controller functions
84 ===============================================================================
85 ##### NOR and SRAM Controller functions #####
86 ===============================================================================
88 [..] The following sequence should be followed to configure the FSMC to interface
89 with SRAM, PSRAM, NOR or OneNAND memory connected to the NOR/SRAM Bank:
91 (#) Enable the clock for the FSMC and associated GPIOs using the following functions:
92 RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE);
93 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE);
95 (#) FSMC pins configuration
96 (++) Connect the involved FSMC pins to AF12 using the following function
97 GPIO_PinAFConfig(GPIOx, GPIO_PinSourcex, GPIO_AF_FSMC);
98 (++) Configure these FSMC pins in alternate function mode by calling the function
101 (#) Declare a FSMC_NORSRAMInitTypeDef structure, for example:
102 FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
103 and fill the FSMC_NORSRAMInitStructure variable with the allowed values of
104 the structure member.
106 (#) Initialize the NOR/SRAM Controller by calling the function
107 FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
109 (#) Then enable the NOR/SRAM Bank, for example:
110 FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM2, ENABLE);
112 (#) At this stage you can read/write from/to the memory connected to the NOR/SRAM Bank.
119 * @brief De-initializes the FSMC NOR/SRAM Banks registers to their default
121 * @param FSMC_Bank: specifies the FSMC Bank to be used
122 * This parameter can be one of the following values:
123 * @arg FSMC_Bank1_NORSRAM1: FSMC Bank1 NOR/SRAM1
124 * @arg FSMC_Bank1_NORSRAM2: FSMC Bank1 NOR/SRAM2
125 * @arg FSMC_Bank1_NORSRAM3: FSMC Bank1 NOR/SRAM3
126 * @arg FSMC_Bank1_NORSRAM4: FSMC Bank1 NOR/SRAM4
129 void FSMC_NORSRAMDeInit(uint32_t FSMC_Bank
)
131 /* Check the parameter */
132 assert_param(IS_FSMC_NORSRAM_BANK(FSMC_Bank
));
134 /* FSMC_Bank1_NORSRAM1 */
135 if(FSMC_Bank
== FSMC_Bank1_NORSRAM1
)
137 FSMC_Bank1
->BTCR
[FSMC_Bank
] = 0x000030DB;
139 /* FSMC_Bank1_NORSRAM2, FSMC_Bank1_NORSRAM3 or FSMC_Bank1_NORSRAM4 */
142 FSMC_Bank1
->BTCR
[FSMC_Bank
] = 0x000030D2;
144 FSMC_Bank1
->BTCR
[FSMC_Bank
+ 1] = 0x0FFFFFFF;
145 FSMC_Bank1E
->BWTR
[FSMC_Bank
] = 0x0FFFFFFF;
149 * @brief Initializes the FSMC NOR/SRAM Banks according to the specified
150 * parameters in the FSMC_NORSRAMInitStruct.
151 * @param FSMC_NORSRAMInitStruct : pointer to a FSMC_NORSRAMInitTypeDef structure
152 * that contains the configuration information for the FSMC NOR/SRAM
156 void FSMC_NORSRAMInit(FSMC_NORSRAMInitTypeDef
* FSMC_NORSRAMInitStruct
)
158 uint32_t tmpbcr
= 0, tmpbtr
= 0, tmpbwr
= 0;
160 /* Check the parameters */
161 assert_param(IS_FSMC_NORSRAM_BANK(FSMC_NORSRAMInitStruct
->FSMC_Bank
));
162 assert_param(IS_FSMC_MUX(FSMC_NORSRAMInitStruct
->FSMC_DataAddressMux
));
163 assert_param(IS_FSMC_MEMORY(FSMC_NORSRAMInitStruct
->FSMC_MemoryType
));
164 assert_param(IS_FSMC_MEMORY_WIDTH(FSMC_NORSRAMInitStruct
->FSMC_MemoryDataWidth
));
165 assert_param(IS_FSMC_BURSTMODE(FSMC_NORSRAMInitStruct
->FSMC_BurstAccessMode
));
166 assert_param(IS_FSMC_ASYNWAIT(FSMC_NORSRAMInitStruct
->FSMC_AsynchronousWait
));
167 assert_param(IS_FSMC_WAIT_POLARITY(FSMC_NORSRAMInitStruct
->FSMC_WaitSignalPolarity
));
168 assert_param(IS_FSMC_WRAP_MODE(FSMC_NORSRAMInitStruct
->FSMC_WrapMode
));
169 assert_param(IS_FSMC_WAIT_SIGNAL_ACTIVE(FSMC_NORSRAMInitStruct
->FSMC_WaitSignalActive
));
170 assert_param(IS_FSMC_WRITE_OPERATION(FSMC_NORSRAMInitStruct
->FSMC_WriteOperation
));
171 assert_param(IS_FSMC_WAITE_SIGNAL(FSMC_NORSRAMInitStruct
->FSMC_WaitSignal
));
172 assert_param(IS_FSMC_EXTENDED_MODE(FSMC_NORSRAMInitStruct
->FSMC_ExtendedMode
));
173 assert_param(IS_FSMC_WRITE_BURST(FSMC_NORSRAMInitStruct
->FSMC_WriteBurst
));
174 assert_param(IS_FSMC_ADDRESS_SETUP_TIME(FSMC_NORSRAMInitStruct
->FSMC_ReadWriteTimingStruct
->FSMC_AddressSetupTime
));
175 assert_param(IS_FSMC_ADDRESS_HOLD_TIME(FSMC_NORSRAMInitStruct
->FSMC_ReadWriteTimingStruct
->FSMC_AddressHoldTime
));
176 assert_param(IS_FSMC_DATASETUP_TIME(FSMC_NORSRAMInitStruct
->FSMC_ReadWriteTimingStruct
->FSMC_DataSetupTime
));
177 assert_param(IS_FSMC_TURNAROUND_TIME(FSMC_NORSRAMInitStruct
->FSMC_ReadWriteTimingStruct
->FSMC_BusTurnAroundDuration
));
178 assert_param(IS_FSMC_CLK_DIV(FSMC_NORSRAMInitStruct
->FSMC_ReadWriteTimingStruct
->FSMC_CLKDivision
));
179 assert_param(IS_FSMC_DATA_LATENCY(FSMC_NORSRAMInitStruct
->FSMC_ReadWriteTimingStruct
->FSMC_DataLatency
));
180 assert_param(IS_FSMC_ACCESS_MODE(FSMC_NORSRAMInitStruct
->FSMC_ReadWriteTimingStruct
->FSMC_AccessMode
));
182 /* Get the BTCR register value */
183 tmpbcr
= FSMC_Bank1
->BTCR
[FSMC_NORSRAMInitStruct
->FSMC_Bank
];
185 /* Clear MBKEN, MUXEN, MTYP, MWID, FACCEN, BURSTEN, WAITPOL, WRAPMOD, WAITCFG, WREN,
186 WAITEN, EXTMOD, ASYNCWAIT, CBURSTRW and CCLKEN bits */
187 tmpbcr
&= ((uint32_t)~(FSMC_BCR1_MBKEN
| FSMC_BCR1_MUXEN
| FSMC_BCR1_MTYP
| \
188 FSMC_BCR1_MWID
| FSMC_BCR1_FACCEN
| FSMC_BCR1_BURSTEN
| \
189 FSMC_BCR1_WAITPOL
| FSMC_BCR1_WRAPMOD
| FSMC_BCR1_WAITCFG
| \
190 FSMC_BCR1_WREN
| FSMC_BCR1_WAITEN
| FSMC_BCR1_EXTMOD
| \
191 FSMC_BCR1_ASYNCWAIT
| FSMC_BCR1_CBURSTRW
));
193 /* Bank1 NOR/SRAM control register configuration */
194 tmpbcr
|= (uint32_t)FSMC_NORSRAMInitStruct
->FSMC_DataAddressMux
|
195 FSMC_NORSRAMInitStruct
->FSMC_MemoryType
|
196 FSMC_NORSRAMInitStruct
->FSMC_MemoryDataWidth
|
197 FSMC_NORSRAMInitStruct
->FSMC_BurstAccessMode
|
198 FSMC_NORSRAMInitStruct
->FSMC_AsynchronousWait
|
199 FSMC_NORSRAMInitStruct
->FSMC_WaitSignalPolarity
|
200 FSMC_NORSRAMInitStruct
->FSMC_WrapMode
|
201 FSMC_NORSRAMInitStruct
->FSMC_WaitSignalActive
|
202 FSMC_NORSRAMInitStruct
->FSMC_WriteOperation
|
203 FSMC_NORSRAMInitStruct
->FSMC_WaitSignal
|
204 FSMC_NORSRAMInitStruct
->FSMC_ExtendedMode
|
205 FSMC_NORSRAMInitStruct
->FSMC_WriteBurst
;
207 FSMC_Bank1
->BTCR
[FSMC_NORSRAMInitStruct
->FSMC_Bank
] = tmpbcr
;
209 if(FSMC_NORSRAMInitStruct
->FSMC_MemoryType
== FSMC_MemoryType_NOR
)
211 FSMC_Bank1
->BTCR
[FSMC_NORSRAMInitStruct
->FSMC_Bank
] |= (uint32_t)BCR_FACCEN_SET
;
214 /* Get the BTCR register value */
215 tmpbtr
= FSMC_Bank1
->BTCR
[FSMC_NORSRAMInitStruct
->FSMC_Bank
+1];
217 /* Clear ADDSET, ADDHLD, DATAST, BUSTURN, CLKDIV, DATLAT and ACCMOD bits */
218 tmpbtr
&= ((uint32_t)~(FSMC_BTR1_ADDSET
| FSMC_BTR1_ADDHLD
| FSMC_BTR1_DATAST
| \
219 FSMC_BTR1_BUSTURN
| FSMC_BTR1_CLKDIV
| FSMC_BTR1_DATLAT
| \
222 /* Bank1 NOR/SRAM timing register configuration */
223 tmpbtr
|= (uint32_t)FSMC_NORSRAMInitStruct
->FSMC_ReadWriteTimingStruct
->FSMC_AddressSetupTime
|
224 (FSMC_NORSRAMInitStruct
->FSMC_ReadWriteTimingStruct
->FSMC_AddressHoldTime
<< 4) |
225 (FSMC_NORSRAMInitStruct
->FSMC_ReadWriteTimingStruct
->FSMC_DataSetupTime
<< 8) |
226 (FSMC_NORSRAMInitStruct
->FSMC_ReadWriteTimingStruct
->FSMC_BusTurnAroundDuration
<< 16) |
227 (FSMC_NORSRAMInitStruct
->FSMC_ReadWriteTimingStruct
->FSMC_CLKDivision
<< 20) |
228 (FSMC_NORSRAMInitStruct
->FSMC_ReadWriteTimingStruct
->FSMC_DataLatency
<< 24) |
229 FSMC_NORSRAMInitStruct
->FSMC_ReadWriteTimingStruct
->FSMC_AccessMode
;
231 FSMC_Bank1
->BTCR
[FSMC_NORSRAMInitStruct
->FSMC_Bank
+1] = tmpbtr
;
233 /* Bank1 NOR/SRAM timing register for write configuration, if extended mode is used */
234 if(FSMC_NORSRAMInitStruct
->FSMC_ExtendedMode
== FSMC_ExtendedMode_Enable
)
236 assert_param(IS_FSMC_ADDRESS_SETUP_TIME(FSMC_NORSRAMInitStruct
->FSMC_WriteTimingStruct
->FSMC_AddressSetupTime
));
237 assert_param(IS_FSMC_ADDRESS_HOLD_TIME(FSMC_NORSRAMInitStruct
->FSMC_WriteTimingStruct
->FSMC_AddressHoldTime
));
238 assert_param(IS_FSMC_DATASETUP_TIME(FSMC_NORSRAMInitStruct
->FSMC_WriteTimingStruct
->FSMC_DataSetupTime
));
239 assert_param(IS_FSMC_TURNAROUND_TIME(FSMC_NORSRAMInitStruct
->FSMC_WriteTimingStruct
->FSMC_BusTurnAroundDuration
));
240 assert_param(IS_FSMC_ACCESS_MODE(FSMC_NORSRAMInitStruct
->FSMC_WriteTimingStruct
->FSMC_AccessMode
));
242 /* Get the BWTR register value */
243 tmpbwr
= FSMC_Bank1E
->BWTR
[FSMC_NORSRAMInitStruct
->FSMC_Bank
];
245 /* Clear ADDSET, ADDHLD, DATAST, BUSTURN, and ACCMOD bits */
246 tmpbwr
&= ((uint32_t)~(FSMC_BWTR1_ADDSET
| FSMC_BWTR1_ADDHLD
| FSMC_BWTR1_DATAST
| \
247 FSMC_BWTR1_BUSTURN
| FSMC_BWTR1_ACCMOD
));
249 tmpbwr
|= (uint32_t)FSMC_NORSRAMInitStruct
->FSMC_WriteTimingStruct
->FSMC_AddressSetupTime
|
250 (FSMC_NORSRAMInitStruct
->FSMC_WriteTimingStruct
->FSMC_AddressHoldTime
<< 4 )|
251 (FSMC_NORSRAMInitStruct
->FSMC_WriteTimingStruct
->FSMC_DataSetupTime
<< 8) |
252 (FSMC_NORSRAMInitStruct
->FSMC_WriteTimingStruct
->FSMC_BusTurnAroundDuration
<< 16) |
253 FSMC_NORSRAMInitStruct
->FSMC_WriteTimingStruct
->FSMC_AccessMode
;
255 FSMC_Bank1E
->BWTR
[FSMC_NORSRAMInitStruct
->FSMC_Bank
] = tmpbwr
;
259 FSMC_Bank1E
->BWTR
[FSMC_NORSRAMInitStruct
->FSMC_Bank
] = 0x0FFFFFFF;
264 * @brief Fills each FSMC_NORSRAMInitStruct member with its default value.
265 * @param FSMC_NORSRAMInitStruct: pointer to a FSMC_NORSRAMInitTypeDef structure
266 * which will be initialized.
269 void FSMC_NORSRAMStructInit(FSMC_NORSRAMInitTypeDef
* FSMC_NORSRAMInitStruct
)
271 /* Reset NOR/SRAM Init structure parameters values */
272 FSMC_NORSRAMInitStruct
->FSMC_Bank
= FSMC_Bank1_NORSRAM1
;
273 FSMC_NORSRAMInitStruct
->FSMC_DataAddressMux
= FSMC_DataAddressMux_Enable
;
274 FSMC_NORSRAMInitStruct
->FSMC_MemoryType
= FSMC_MemoryType_SRAM
;
275 FSMC_NORSRAMInitStruct
->FSMC_MemoryDataWidth
= FSMC_MemoryDataWidth_8b
;
276 FSMC_NORSRAMInitStruct
->FSMC_BurstAccessMode
= FSMC_BurstAccessMode_Disable
;
277 FSMC_NORSRAMInitStruct
->FSMC_AsynchronousWait
= FSMC_AsynchronousWait_Disable
;
278 FSMC_NORSRAMInitStruct
->FSMC_WaitSignalPolarity
= FSMC_WaitSignalPolarity_Low
;
279 FSMC_NORSRAMInitStruct
->FSMC_WrapMode
= FSMC_WrapMode_Disable
;
280 FSMC_NORSRAMInitStruct
->FSMC_WaitSignalActive
= FSMC_WaitSignalActive_BeforeWaitState
;
281 FSMC_NORSRAMInitStruct
->FSMC_WriteOperation
= FSMC_WriteOperation_Enable
;
282 FSMC_NORSRAMInitStruct
->FSMC_WaitSignal
= FSMC_WaitSignal_Enable
;
283 FSMC_NORSRAMInitStruct
->FSMC_ExtendedMode
= FSMC_ExtendedMode_Disable
;
284 FSMC_NORSRAMInitStruct
->FSMC_WriteBurst
= FSMC_WriteBurst_Disable
;
285 FSMC_NORSRAMInitStruct
->FSMC_ReadWriteTimingStruct
= (FSMC_NORSRAMTimingInitTypeDef
*)&FSMC_DefaultTimingStruct
;
286 FSMC_NORSRAMInitStruct
->FSMC_WriteTimingStruct
= (FSMC_NORSRAMTimingInitTypeDef
*)&FSMC_DefaultTimingStruct
;
290 * @brief Enables or disables the specified NOR/SRAM Memory Bank.
291 * @param FSMC_Bank: specifies the FSMC Bank to be used
292 * This parameter can be one of the following values:
293 * @arg FSMC_Bank1_NORSRAM1: FSMC Bank1 NOR/SRAM1
294 * @arg FSMC_Bank1_NORSRAM2: FSMC Bank1 NOR/SRAM2
295 * @arg FSMC_Bank1_NORSRAM3: FSMC Bank1 NOR/SRAM3
296 * @arg FSMC_Bank1_NORSRAM4: FSMC Bank1 NOR/SRAM4
297 * @param NewState: new state of the FSMC_Bank. This parameter can be: ENABLE or DISABLE.
300 void FSMC_NORSRAMCmd(uint32_t FSMC_Bank
, FunctionalState NewState
)
302 assert_param(IS_FSMC_NORSRAM_BANK(FSMC_Bank
));
303 assert_param(IS_FUNCTIONAL_STATE(NewState
));
305 if (NewState
!= DISABLE
)
307 /* Enable the selected NOR/SRAM Bank by setting the PBKEN bit in the BCRx register */
308 FSMC_Bank1
->BTCR
[FSMC_Bank
] |= BCR_MBKEN_SET
;
312 /* Disable the selected NOR/SRAM Bank by clearing the PBKEN bit in the BCRx register */
313 FSMC_Bank1
->BTCR
[FSMC_Bank
] &= BCR_MBKEN_RESET
;
320 /** @defgroup FSMC_Group2 NAND Controller functions
321 * @brief NAND Controller functions
324 ===============================================================================
325 ##### NAND Controller functions #####
326 ===============================================================================
328 [..] The following sequence should be followed to configure the FSMC to interface
329 with 8-bit or 16-bit NAND memory connected to the NAND Bank:
331 (#) Enable the clock for the FSMC and associated GPIOs using the following functions:
332 (++) RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE);
333 (++) RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE);
335 (#) FSMC pins configuration
336 (++) Connect the involved FSMC pins to AF12 using the following function
337 GPIO_PinAFConfig(GPIOx, GPIO_PinSourcex, GPIO_AF_FSMC);
338 (++) Configure these FSMC pins in alternate function mode by calling the function
341 (#) Declare a FSMC_NANDInitTypeDef structure, for example:
342 FSMC_NANDInitTypeDef FSMC_NANDInitStructure;
343 and fill the FSMC_NANDInitStructure variable with the allowed values of
344 the structure member.
346 (#) Initialize the NAND Controller by calling the function
347 FSMC_NANDInit(&FSMC_NANDInitStructure);
349 (#) Then enable the NAND Bank, for example:
350 FSMC_NANDCmd(FSMC_Bank3_NAND, ENABLE);
352 (#) At this stage you can read/write from/to the memory connected to the NAND Bank.
355 (@) To enable the Error Correction Code (ECC), you have to use the function
356 FSMC_NANDECCCmd(FSMC_Bank3_NAND, ENABLE);
358 (@) and to get the current ECC value you have to use the function
359 ECCval = FSMC_GetECC(FSMC_Bank3_NAND);
366 * @brief De-initializes the FSMC NAND Banks registers to their default reset values.
367 * @param FSMC_Bank: specifies the FSMC Bank to be used
368 * This parameter can be one of the following values:
369 * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
370 * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
373 void FSMC_NANDDeInit(uint32_t FSMC_Bank
)
375 /* Check the parameter */
376 assert_param(IS_FSMC_NAND_BANK(FSMC_Bank
));
378 if(FSMC_Bank
== FSMC_Bank2_NAND
)
380 /* Set the FSMC_Bank2 registers to their reset values */
381 FSMC_Bank2
->PCR2
= 0x00000018;
382 FSMC_Bank2
->SR2
= 0x00000040;
383 FSMC_Bank2
->PMEM2
= 0xFCFCFCFC;
384 FSMC_Bank2
->PATT2
= 0xFCFCFCFC;
386 /* FSMC_Bank3_NAND */
389 /* Set the FSMC_Bank3 registers to their reset values */
390 FSMC_Bank3
->PCR3
= 0x00000018;
391 FSMC_Bank3
->SR3
= 0x00000040;
392 FSMC_Bank3
->PMEM3
= 0xFCFCFCFC;
393 FSMC_Bank3
->PATT3
= 0xFCFCFCFC;
398 * @brief Initializes the FSMC NAND Banks according to the specified parameters
399 * in the FSMC_NANDInitStruct.
400 * @param FSMC_NANDInitStruct : pointer to a FSMC_NANDInitTypeDef structure that
401 * contains the configuration information for the FSMC NAND specified Banks.
404 void FSMC_NANDInit(FSMC_NANDInitTypeDef
* FSMC_NANDInitStruct
)
406 uint32_t tmppcr
= 0x00000000, tmppmem
= 0x00000000, tmppatt
= 0x00000000;
408 /* Check the parameters */
409 assert_param( IS_FSMC_NAND_BANK(FSMC_NANDInitStruct
->FSMC_Bank
));
410 assert_param( IS_FSMC_WAIT_FEATURE(FSMC_NANDInitStruct
->FSMC_Waitfeature
));
411 assert_param( IS_FSMC_MEMORY_WIDTH(FSMC_NANDInitStruct
->FSMC_MemoryDataWidth
));
412 assert_param( IS_FSMC_ECC_STATE(FSMC_NANDInitStruct
->FSMC_ECC
));
413 assert_param( IS_FSMC_ECCPAGE_SIZE(FSMC_NANDInitStruct
->FSMC_ECCPageSize
));
414 assert_param( IS_FSMC_TCLR_TIME(FSMC_NANDInitStruct
->FSMC_TCLRSetupTime
));
415 assert_param( IS_FSMC_TAR_TIME(FSMC_NANDInitStruct
->FSMC_TARSetupTime
));
416 assert_param(IS_FSMC_SETUP_TIME(FSMC_NANDInitStruct
->FSMC_CommonSpaceTimingStruct
->FSMC_SetupTime
));
417 assert_param(IS_FSMC_WAIT_TIME(FSMC_NANDInitStruct
->FSMC_CommonSpaceTimingStruct
->FSMC_WaitSetupTime
));
418 assert_param(IS_FSMC_HOLD_TIME(FSMC_NANDInitStruct
->FSMC_CommonSpaceTimingStruct
->FSMC_HoldSetupTime
));
419 assert_param(IS_FSMC_HIZ_TIME(FSMC_NANDInitStruct
->FSMC_CommonSpaceTimingStruct
->FSMC_HiZSetupTime
));
420 assert_param(IS_FSMC_SETUP_TIME(FSMC_NANDInitStruct
->FSMC_AttributeSpaceTimingStruct
->FSMC_SetupTime
));
421 assert_param(IS_FSMC_WAIT_TIME(FSMC_NANDInitStruct
->FSMC_AttributeSpaceTimingStruct
->FSMC_WaitSetupTime
));
422 assert_param(IS_FSMC_HOLD_TIME(FSMC_NANDInitStruct
->FSMC_AttributeSpaceTimingStruct
->FSMC_HoldSetupTime
));
423 assert_param(IS_FSMC_HIZ_TIME(FSMC_NANDInitStruct
->FSMC_AttributeSpaceTimingStruct
->FSMC_HiZSetupTime
));
425 if(FSMC_NANDInitStruct
->FSMC_Bank
== FSMC_Bank2_NAND
)
427 /* Get the NAND bank 2 register value */
428 tmppcr
= FSMC_Bank2
->PCR2
;
432 /* Get the NAND bank 3 register value */
433 tmppcr
= FSMC_Bank3
->PCR3
;
436 /* Clear PWAITEN, PBKEN, PTYP, PWID, ECCEN, TCLR, TAR and ECCPS bits */
437 tmppcr
&= ((uint32_t)~(FSMC_PCR2_PWAITEN
| FSMC_PCR2_PBKEN
| FSMC_PCR2_PTYP
| \
438 FSMC_PCR2_PWID
| FSMC_PCR2_ECCEN
| FSMC_PCR2_TCLR
| \
439 FSMC_PCR2_TAR
| FSMC_PCR2_ECCPS
));
441 /* Set the tmppcr value according to FSMC_NANDInitStruct parameters */
442 tmppcr
|= (uint32_t)FSMC_NANDInitStruct
->FSMC_Waitfeature
|
443 PCR_MEMORYTYPE_NAND
|
444 FSMC_NANDInitStruct
->FSMC_MemoryDataWidth
|
445 FSMC_NANDInitStruct
->FSMC_ECC
|
446 FSMC_NANDInitStruct
->FSMC_ECCPageSize
|
447 (FSMC_NANDInitStruct
->FSMC_TCLRSetupTime
<< 9 )|
448 (FSMC_NANDInitStruct
->FSMC_TARSetupTime
<< 13);
450 if(FSMC_NANDInitStruct
->FSMC_Bank
== FSMC_Bank2_NAND
)
452 /* Get the NAND bank 2 register value */
453 tmppmem
= FSMC_Bank2
->PMEM2
;
457 /* Get the NAND bank 3 register value */
458 tmppmem
= FSMC_Bank3
->PMEM3
;
461 /* Clear MEMSETx, MEMWAITx, MEMHOLDx and MEMHIZx bits */
462 tmppmem
&= ((uint32_t)~(FSMC_PMEM2_MEMSET2
| FSMC_PMEM2_MEMWAIT2
| FSMC_PMEM2_MEMHOLD2
| \
463 FSMC_PMEM2_MEMHIZ2
));
465 /* Set tmppmem value according to FSMC_CommonSpaceTimingStructure parameters */
466 tmppmem
|= (uint32_t)FSMC_NANDInitStruct
->FSMC_CommonSpaceTimingStruct
->FSMC_SetupTime
|
467 (FSMC_NANDInitStruct
->FSMC_CommonSpaceTimingStruct
->FSMC_WaitSetupTime
<< 8) |
468 (FSMC_NANDInitStruct
->FSMC_CommonSpaceTimingStruct
->FSMC_HoldSetupTime
<< 16)|
469 (FSMC_NANDInitStruct
->FSMC_CommonSpaceTimingStruct
->FSMC_HiZSetupTime
<< 24);
471 if(FSMC_NANDInitStruct
->FSMC_Bank
== FSMC_Bank2_NAND
)
473 /* Get the NAND bank 2 register value */
474 tmppatt
= FSMC_Bank2
->PATT2
;
478 /* Get the NAND bank 3 register value */
479 tmppatt
= FSMC_Bank2
->PATT2
;
482 /* Clear ATTSETx, ATTWAITx, ATTHOLDx and ATTHIZx bits */
483 tmppatt
&= ((uint32_t)~(FSMC_PATT2_ATTSET2
| FSMC_PATT2_ATTWAIT2
| FSMC_PATT2_ATTHOLD2
| \
484 FSMC_PATT2_ATTHIZ2
));
486 /* Set tmppatt value according to FSMC_AttributeSpaceTimingStructure parameters */
487 tmppatt
|= (uint32_t)FSMC_NANDInitStruct
->FSMC_AttributeSpaceTimingStruct
->FSMC_SetupTime
|
488 (FSMC_NANDInitStruct
->FSMC_AttributeSpaceTimingStruct
->FSMC_WaitSetupTime
<< 8) |
489 (FSMC_NANDInitStruct
->FSMC_AttributeSpaceTimingStruct
->FSMC_HoldSetupTime
<< 16)|
490 (FSMC_NANDInitStruct
->FSMC_AttributeSpaceTimingStruct
->FSMC_HiZSetupTime
<< 24);
492 if(FSMC_NANDInitStruct
->FSMC_Bank
== FSMC_Bank2_NAND
)
494 /* FSMC_Bank2_NAND registers configuration */
495 FSMC_Bank2
->PCR2
= tmppcr
;
496 FSMC_Bank2
->PMEM2
= tmppmem
;
497 FSMC_Bank2
->PATT2
= tmppatt
;
501 /* FSMC_Bank3_NAND registers configuration */
502 FSMC_Bank3
->PCR3
= tmppcr
;
503 FSMC_Bank3
->PMEM3
= tmppmem
;
504 FSMC_Bank3
->PATT3
= tmppatt
;
510 * @brief Fills each FSMC_NANDInitStruct member with its default value.
511 * @param FSMC_NANDInitStruct: pointer to a FSMC_NANDInitTypeDef structure which
512 * will be initialized.
515 void FSMC_NANDStructInit(FSMC_NANDInitTypeDef
* FSMC_NANDInitStruct
)
517 /* Reset NAND Init structure parameters values */
518 FSMC_NANDInitStruct
->FSMC_Bank
= FSMC_Bank2_NAND
;
519 FSMC_NANDInitStruct
->FSMC_Waitfeature
= FSMC_Waitfeature_Disable
;
520 FSMC_NANDInitStruct
->FSMC_MemoryDataWidth
= FSMC_MemoryDataWidth_8b
;
521 FSMC_NANDInitStruct
->FSMC_ECC
= FSMC_ECC_Disable
;
522 FSMC_NANDInitStruct
->FSMC_ECCPageSize
= FSMC_ECCPageSize_256Bytes
;
523 FSMC_NANDInitStruct
->FSMC_TCLRSetupTime
= 0x0;
524 FSMC_NANDInitStruct
->FSMC_TARSetupTime
= 0x0;
525 FSMC_NANDInitStruct
->FSMC_CommonSpaceTimingStruct
->FSMC_SetupTime
= 0xFC;
526 FSMC_NANDInitStruct
->FSMC_CommonSpaceTimingStruct
->FSMC_WaitSetupTime
= 0xFC;
527 FSMC_NANDInitStruct
->FSMC_CommonSpaceTimingStruct
->FSMC_HoldSetupTime
= 0xFC;
528 FSMC_NANDInitStruct
->FSMC_CommonSpaceTimingStruct
->FSMC_HiZSetupTime
= 0xFC;
529 FSMC_NANDInitStruct
->FSMC_AttributeSpaceTimingStruct
->FSMC_SetupTime
= 0xFC;
530 FSMC_NANDInitStruct
->FSMC_AttributeSpaceTimingStruct
->FSMC_WaitSetupTime
= 0xFC;
531 FSMC_NANDInitStruct
->FSMC_AttributeSpaceTimingStruct
->FSMC_HoldSetupTime
= 0xFC;
532 FSMC_NANDInitStruct
->FSMC_AttributeSpaceTimingStruct
->FSMC_HiZSetupTime
= 0xFC;
536 * @brief Enables or disables the specified NAND Memory Bank.
537 * @param FSMC_Bank: specifies the FSMC Bank to be used
538 * This parameter can be one of the following values:
539 * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
540 * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
541 * @param NewState: new state of the FSMC_Bank. This parameter can be: ENABLE or DISABLE.
544 void FSMC_NANDCmd(uint32_t FSMC_Bank
, FunctionalState NewState
)
546 assert_param(IS_FSMC_NAND_BANK(FSMC_Bank
));
547 assert_param(IS_FUNCTIONAL_STATE(NewState
));
549 if (NewState
!= DISABLE
)
551 /* Enable the selected NAND Bank by setting the PBKEN bit in the PCRx register */
552 if(FSMC_Bank
== FSMC_Bank2_NAND
)
554 FSMC_Bank2
->PCR2
|= PCR_PBKEN_SET
;
558 FSMC_Bank3
->PCR3
|= PCR_PBKEN_SET
;
563 /* Disable the selected NAND Bank by clearing the PBKEN bit in the PCRx register */
564 if(FSMC_Bank
== FSMC_Bank2_NAND
)
566 FSMC_Bank2
->PCR2
&= PCR_PBKEN_RESET
;
570 FSMC_Bank3
->PCR3
&= PCR_PBKEN_RESET
;
575 * @brief Enables or disables the FSMC NAND ECC feature.
576 * @param FSMC_Bank: specifies the FSMC Bank to be used
577 * This parameter can be one of the following values:
578 * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
579 * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
580 * @param NewState: new state of the FSMC NAND ECC feature.
581 * This parameter can be: ENABLE or DISABLE.
584 void FSMC_NANDECCCmd(uint32_t FSMC_Bank
, FunctionalState NewState
)
586 assert_param(IS_FSMC_NAND_BANK(FSMC_Bank
));
587 assert_param(IS_FUNCTIONAL_STATE(NewState
));
589 if (NewState
!= DISABLE
)
591 /* Enable the selected NAND Bank ECC function by setting the ECCEN bit in the PCRx register */
592 if(FSMC_Bank
== FSMC_Bank2_NAND
)
594 FSMC_Bank2
->PCR2
|= PCR_ECCEN_SET
;
598 FSMC_Bank3
->PCR3
|= PCR_ECCEN_SET
;
603 /* Disable the selected NAND Bank ECC function by clearing the ECCEN bit in the PCRx register */
604 if(FSMC_Bank
== FSMC_Bank2_NAND
)
606 FSMC_Bank2
->PCR2
&= PCR_ECCEN_RESET
;
610 FSMC_Bank3
->PCR3
&= PCR_ECCEN_RESET
;
616 * @brief Returns the error correction code register value.
617 * @param FSMC_Bank: specifies the FSMC Bank to be used
618 * This parameter can be one of the following values:
619 * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
620 * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
621 * @retval The Error Correction Code (ECC) value.
623 uint32_t FSMC_GetECC(uint32_t FSMC_Bank
)
625 uint32_t eccval
= 0x00000000;
627 if(FSMC_Bank
== FSMC_Bank2_NAND
)
629 /* Get the ECCR2 register value */
630 eccval
= FSMC_Bank2
->ECCR2
;
634 /* Get the ECCR3 register value */
635 eccval
= FSMC_Bank3
->ECCR3
;
637 /* Return the error correction code value */
644 /** @defgroup FSMC_Group3 PCCARD Controller functions
645 * @brief PCCARD Controller functions
648 ===============================================================================
649 ##### PCCARD Controller functions #####
650 ===============================================================================
652 [..] he following sequence should be followed to configure the FSMC to interface
653 with 16-bit PC Card compatible memory connected to the PCCARD Bank:
655 (#) Enable the clock for the FSMC and associated GPIOs using the following functions:
656 (++) RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE);
657 (++) RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE);
659 (#) FSMC pins configuration
660 (++) Connect the involved FSMC pins to AF12 using the following function
661 GPIO_PinAFConfig(GPIOx, GPIO_PinSourcex, GPIO_AF_FSMC);
662 (++) Configure these FSMC pins in alternate function mode by calling the function
665 (#) Declare a FSMC_PCCARDInitTypeDef structure, for example:
666 FSMC_PCCARDInitTypeDef FSMC_PCCARDInitStructure;
667 and fill the FSMC_PCCARDInitStructure variable with the allowed values of
668 the structure member.
670 (#) Initialize the PCCARD Controller by calling the function
671 FSMC_PCCARDInit(&FSMC_PCCARDInitStructure);
673 (#) Then enable the PCCARD Bank:
674 FSMC_PCCARDCmd(ENABLE);
676 (#) At this stage you can read/write from/to the memory connected to the PCCARD Bank.
683 * @brief De-initializes the FSMC PCCARD Bank registers to their default reset values.
687 void FSMC_PCCARDDeInit(void)
689 /* Set the FSMC_Bank4 registers to their reset values */
690 FSMC_Bank4
->PCR4
= 0x00000018;
691 FSMC_Bank4
->SR4
= 0x00000000;
692 FSMC_Bank4
->PMEM4
= 0xFCFCFCFC;
693 FSMC_Bank4
->PATT4
= 0xFCFCFCFC;
694 FSMC_Bank4
->PIO4
= 0xFCFCFCFC;
698 * @brief Initializes the FSMC PCCARD Bank according to the specified parameters
699 * in the FSMC_PCCARDInitStruct.
700 * @param FSMC_PCCARDInitStruct : pointer to a FSMC_PCCARDInitTypeDef structure
701 * that contains the configuration information for the FSMC PCCARD Bank.
704 void FSMC_PCCARDInit(FSMC_PCCARDInitTypeDef
* FSMC_PCCARDInitStruct
)
706 uint32_t tmppcr4
= 0, tmppmem4
= 0, tmppatt4
= 0, tmppio4
= 0;
708 /* Check the parameters */
709 assert_param(IS_FSMC_WAIT_FEATURE(FSMC_PCCARDInitStruct
->FSMC_Waitfeature
));
710 assert_param(IS_FSMC_TCLR_TIME(FSMC_PCCARDInitStruct
->FSMC_TCLRSetupTime
));
711 assert_param(IS_FSMC_TAR_TIME(FSMC_PCCARDInitStruct
->FSMC_TARSetupTime
));
713 assert_param(IS_FSMC_SETUP_TIME(FSMC_PCCARDInitStruct
->FSMC_CommonSpaceTimingStruct
->FSMC_SetupTime
));
714 assert_param(IS_FSMC_WAIT_TIME(FSMC_PCCARDInitStruct
->FSMC_CommonSpaceTimingStruct
->FSMC_WaitSetupTime
));
715 assert_param(IS_FSMC_HOLD_TIME(FSMC_PCCARDInitStruct
->FSMC_CommonSpaceTimingStruct
->FSMC_HoldSetupTime
));
716 assert_param(IS_FSMC_HIZ_TIME(FSMC_PCCARDInitStruct
->FSMC_CommonSpaceTimingStruct
->FSMC_HiZSetupTime
));
718 assert_param(IS_FSMC_SETUP_TIME(FSMC_PCCARDInitStruct
->FSMC_AttributeSpaceTimingStruct
->FSMC_SetupTime
));
719 assert_param(IS_FSMC_WAIT_TIME(FSMC_PCCARDInitStruct
->FSMC_AttributeSpaceTimingStruct
->FSMC_WaitSetupTime
));
720 assert_param(IS_FSMC_HOLD_TIME(FSMC_PCCARDInitStruct
->FSMC_AttributeSpaceTimingStruct
->FSMC_HoldSetupTime
));
721 assert_param(IS_FSMC_HIZ_TIME(FSMC_PCCARDInitStruct
->FSMC_AttributeSpaceTimingStruct
->FSMC_HiZSetupTime
));
722 assert_param(IS_FSMC_SETUP_TIME(FSMC_PCCARDInitStruct
->FSMC_IOSpaceTimingStruct
->FSMC_SetupTime
));
723 assert_param(IS_FSMC_WAIT_TIME(FSMC_PCCARDInitStruct
->FSMC_IOSpaceTimingStruct
->FSMC_WaitSetupTime
));
724 assert_param(IS_FSMC_HOLD_TIME(FSMC_PCCARDInitStruct
->FSMC_IOSpaceTimingStruct
->FSMC_HoldSetupTime
));
725 assert_param(IS_FSMC_HIZ_TIME(FSMC_PCCARDInitStruct
->FSMC_IOSpaceTimingStruct
->FSMC_HiZSetupTime
));
727 /* Get PCCARD control register value */
728 tmppcr4
= FSMC_Bank4
->PCR4
;
730 /* Clear TAR, TCLR, PWAITEN and PWID bits */
731 tmppcr4
&= ((uint32_t)~(FSMC_PCR4_TAR
| FSMC_PCR4_TCLR
| FSMC_PCR4_PWAITEN
| \
734 /* Set the PCR4 register value according to FSMC_PCCARDInitStruct parameters */
735 tmppcr4
|= (uint32_t)FSMC_PCCARDInitStruct
->FSMC_Waitfeature
|
736 FSMC_MemoryDataWidth_16b
|
737 (FSMC_PCCARDInitStruct
->FSMC_TCLRSetupTime
<< 9) |
738 (FSMC_PCCARDInitStruct
->FSMC_TARSetupTime
<< 13);
740 FSMC_Bank4
->PCR4
= tmppcr4
;
742 /* Get PCCARD common space timing register value */
743 tmppmem4
= FSMC_Bank4
->PMEM4
;
745 /* Clear MEMSETx, MEMWAITx, MEMHOLDx and MEMHIZx bits */
746 tmppmem4
&= ((uint32_t)~(FSMC_PMEM4_MEMSET4
| FSMC_PMEM4_MEMWAIT4
| FSMC_PMEM4_MEMHOLD4
| \
747 FSMC_PMEM4_MEMHIZ4
));
749 /* Set PMEM4 register value according to FSMC_CommonSpaceTimingStructure parameters */
750 tmppmem4
|= (uint32_t)FSMC_PCCARDInitStruct
->FSMC_CommonSpaceTimingStruct
->FSMC_SetupTime
|
751 (FSMC_PCCARDInitStruct
->FSMC_CommonSpaceTimingStruct
->FSMC_WaitSetupTime
<< 8) |
752 (FSMC_PCCARDInitStruct
->FSMC_CommonSpaceTimingStruct
->FSMC_HoldSetupTime
<< 16)|
753 (FSMC_PCCARDInitStruct
->FSMC_CommonSpaceTimingStruct
->FSMC_HiZSetupTime
<< 24);
755 FSMC_Bank4
->PMEM4
= tmppmem4
;
757 /* Get PCCARD timing parameters */
758 tmppatt4
= FSMC_Bank4
->PATT4
;
760 /* Clear ATTSETx, ATTWAITx, ATTHOLDx and ATTHIZx bits */
761 tmppatt4
&= ((uint32_t)~(FSMC_PATT4_ATTSET4
| FSMC_PATT4_ATTWAIT4
| FSMC_PATT4_ATTHOLD4
| \
762 FSMC_PATT4_ATTHIZ4
));
764 /* Set PATT4 register value according to FSMC_AttributeSpaceTimingStructure parameters */
765 tmppatt4
|= (uint32_t)FSMC_PCCARDInitStruct
->FSMC_AttributeSpaceTimingStruct
->FSMC_SetupTime
|
766 (FSMC_PCCARDInitStruct
->FSMC_AttributeSpaceTimingStruct
->FSMC_WaitSetupTime
<< 8) |
767 (FSMC_PCCARDInitStruct
->FSMC_AttributeSpaceTimingStruct
->FSMC_HoldSetupTime
<< 16)|
768 (FSMC_PCCARDInitStruct
->FSMC_AttributeSpaceTimingStruct
->FSMC_HiZSetupTime
<< 24);
770 FSMC_Bank4
->PATT4
= tmppatt4
;
772 /* Get FSMC_PCCARD device timing parameters */
773 tmppio4
= FSMC_Bank4
->PIO4
;
775 /* Clear IOSET4, IOWAIT4, IOHOLD4 and IOHIZ4 bits */
776 tmppio4
&= ((uint32_t)~(FSMC_PIO4_IOSET4
| FSMC_PIO4_IOWAIT4
| FSMC_PIO4_IOHOLD4
| \
779 /* Set PIO4 register value according to FSMC_IOSpaceTimingStructure parameters */
780 tmppio4
|= (uint32_t)FSMC_PCCARDInitStruct
->FSMC_IOSpaceTimingStruct
->FSMC_SetupTime
|
781 (FSMC_PCCARDInitStruct
->FSMC_IOSpaceTimingStruct
->FSMC_WaitSetupTime
<< 8) |
782 (FSMC_PCCARDInitStruct
->FSMC_IOSpaceTimingStruct
->FSMC_HoldSetupTime
<< 16)|
783 (FSMC_PCCARDInitStruct
->FSMC_IOSpaceTimingStruct
->FSMC_HiZSetupTime
<< 24);
785 FSMC_Bank4
->PIO4
= tmppio4
;
789 * @brief Fills each FSMC_PCCARDInitStruct member with its default value.
790 * @param FSMC_PCCARDInitStruct: pointer to a FSMC_PCCARDInitTypeDef structure
791 * which will be initialized.
794 void FSMC_PCCARDStructInit(FSMC_PCCARDInitTypeDef
* FSMC_PCCARDInitStruct
)
796 /* Reset PCCARD Init structure parameters values */
797 FSMC_PCCARDInitStruct
->FSMC_Waitfeature
= FSMC_Waitfeature_Disable
;
798 FSMC_PCCARDInitStruct
->FSMC_TCLRSetupTime
= 0x0;
799 FSMC_PCCARDInitStruct
->FSMC_TARSetupTime
= 0x0;
800 FSMC_PCCARDInitStruct
->FSMC_CommonSpaceTimingStruct
->FSMC_SetupTime
= 0xFC;
801 FSMC_PCCARDInitStruct
->FSMC_CommonSpaceTimingStruct
->FSMC_WaitSetupTime
= 0xFC;
802 FSMC_PCCARDInitStruct
->FSMC_CommonSpaceTimingStruct
->FSMC_HoldSetupTime
= 0xFC;
803 FSMC_PCCARDInitStruct
->FSMC_CommonSpaceTimingStruct
->FSMC_HiZSetupTime
= 0xFC;
804 FSMC_PCCARDInitStruct
->FSMC_AttributeSpaceTimingStruct
->FSMC_SetupTime
= 0xFC;
805 FSMC_PCCARDInitStruct
->FSMC_AttributeSpaceTimingStruct
->FSMC_WaitSetupTime
= 0xFC;
806 FSMC_PCCARDInitStruct
->FSMC_AttributeSpaceTimingStruct
->FSMC_HoldSetupTime
= 0xFC;
807 FSMC_PCCARDInitStruct
->FSMC_AttributeSpaceTimingStruct
->FSMC_HiZSetupTime
= 0xFC;
808 FSMC_PCCARDInitStruct
->FSMC_IOSpaceTimingStruct
->FSMC_SetupTime
= 0xFC;
809 FSMC_PCCARDInitStruct
->FSMC_IOSpaceTimingStruct
->FSMC_WaitSetupTime
= 0xFC;
810 FSMC_PCCARDInitStruct
->FSMC_IOSpaceTimingStruct
->FSMC_HoldSetupTime
= 0xFC;
811 FSMC_PCCARDInitStruct
->FSMC_IOSpaceTimingStruct
->FSMC_HiZSetupTime
= 0xFC;
815 * @brief Enables or disables the PCCARD Memory Bank.
816 * @param NewState: new state of the PCCARD Memory Bank.
817 * This parameter can be: ENABLE or DISABLE.
820 void FSMC_PCCARDCmd(FunctionalState NewState
)
822 assert_param(IS_FUNCTIONAL_STATE(NewState
));
824 if (NewState
!= DISABLE
)
826 /* Enable the PCCARD Bank by setting the PBKEN bit in the PCR4 register */
827 FSMC_Bank4
->PCR4
|= PCR_PBKEN_SET
;
831 /* Disable the PCCARD Bank by clearing the PBKEN bit in the PCR4 register */
832 FSMC_Bank4
->PCR4
&= PCR_PBKEN_RESET
;
839 /** @defgroup FSMC_Group4 Interrupts and flags management functions
840 * @brief Interrupts and flags management functions
843 ===============================================================================
844 ##### Interrupts and flags management functions #####
845 ===============================================================================
852 * @brief Enables or disables the specified FSMC interrupts.
853 * @param FSMC_Bank: specifies the FSMC Bank to be used
854 * This parameter can be one of the following values:
855 * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
856 * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
857 * @arg FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
858 * @param FSMC_IT: specifies the FSMC interrupt sources to be enabled or disabled.
859 * This parameter can be any combination of the following values:
860 * @arg FSMC_IT_RisingEdge: Rising edge detection interrupt.
861 * @arg FSMC_IT_Level: Level edge detection interrupt.
862 * @arg FSMC_IT_FallingEdge: Falling edge detection interrupt.
863 * @param NewState: new state of the specified FSMC interrupts.
864 * This parameter can be: ENABLE or DISABLE.
867 void FSMC_ITConfig(uint32_t FSMC_Bank
, uint32_t FSMC_IT
, FunctionalState NewState
)
869 assert_param(IS_FSMC_IT_BANK(FSMC_Bank
));
870 assert_param(IS_FSMC_IT(FSMC_IT
));
871 assert_param(IS_FUNCTIONAL_STATE(NewState
));
873 if (NewState
!= DISABLE
)
875 /* Enable the selected FSMC_Bank2 interrupts */
876 if(FSMC_Bank
== FSMC_Bank2_NAND
)
878 FSMC_Bank2
->SR2
|= FSMC_IT
;
880 /* Enable the selected FSMC_Bank3 interrupts */
881 else if (FSMC_Bank
== FSMC_Bank3_NAND
)
883 FSMC_Bank3
->SR3
|= FSMC_IT
;
885 /* Enable the selected FSMC_Bank4 interrupts */
888 FSMC_Bank4
->SR4
|= FSMC_IT
;
893 /* Disable the selected FSMC_Bank2 interrupts */
894 if(FSMC_Bank
== FSMC_Bank2_NAND
)
897 FSMC_Bank2
->SR2
&= (uint32_t)~FSMC_IT
;
899 /* Disable the selected FSMC_Bank3 interrupts */
900 else if (FSMC_Bank
== FSMC_Bank3_NAND
)
902 FSMC_Bank3
->SR3
&= (uint32_t)~FSMC_IT
;
904 /* Disable the selected FSMC_Bank4 interrupts */
907 FSMC_Bank4
->SR4
&= (uint32_t)~FSMC_IT
;
913 * @brief Checks whether the specified FSMC flag is set or not.
914 * @param FSMC_Bank: specifies the FSMC Bank to be used
915 * This parameter can be one of the following values:
916 * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
917 * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
918 * @arg FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
919 * @param FSMC_FLAG: specifies the flag to check.
920 * This parameter can be one of the following values:
921 * @arg FSMC_FLAG_RisingEdge: Rising edge detection Flag.
922 * @arg FSMC_FLAG_Level: Level detection Flag.
923 * @arg FSMC_FLAG_FallingEdge: Falling edge detection Flag.
924 * @arg FSMC_FLAG_FEMPT: Fifo empty Flag.
925 * @retval The new state of FSMC_FLAG (SET or RESET).
927 FlagStatus
FSMC_GetFlagStatus(uint32_t FSMC_Bank
, uint32_t FSMC_FLAG
)
929 FlagStatus bitstatus
= RESET
;
930 uint32_t tmpsr
= 0x00000000;
932 /* Check the parameters */
933 assert_param(IS_FSMC_GETFLAG_BANK(FSMC_Bank
));
934 assert_param(IS_FSMC_GET_FLAG(FSMC_FLAG
));
936 if(FSMC_Bank
== FSMC_Bank2_NAND
)
938 tmpsr
= FSMC_Bank2
->SR2
;
940 else if(FSMC_Bank
== FSMC_Bank3_NAND
)
942 tmpsr
= FSMC_Bank3
->SR3
;
944 /* FSMC_Bank4_PCCARD*/
947 tmpsr
= FSMC_Bank4
->SR4
;
950 /* Get the flag status */
951 if ((tmpsr
& FSMC_FLAG
) != (uint16_t)RESET
)
959 /* Return the flag status */
964 * @brief Clears the FSMC's pending flags.
965 * @param FSMC_Bank: specifies the FSMC Bank to be used
966 * This parameter can be one of the following values:
967 * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
968 * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
969 * @arg FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
970 * @param FSMC_FLAG: specifies the flag to clear.
971 * This parameter can be any combination of the following values:
972 * @arg FSMC_FLAG_RisingEdge: Rising edge detection Flag.
973 * @arg FSMC_FLAG_Level: Level detection Flag.
974 * @arg FSMC_FLAG_FallingEdge: Falling edge detection Flag.
977 void FSMC_ClearFlag(uint32_t FSMC_Bank
, uint32_t FSMC_FLAG
)
979 /* Check the parameters */
980 assert_param(IS_FSMC_GETFLAG_BANK(FSMC_Bank
));
981 assert_param(IS_FSMC_CLEAR_FLAG(FSMC_FLAG
)) ;
983 if(FSMC_Bank
== FSMC_Bank2_NAND
)
985 FSMC_Bank2
->SR2
&= ~FSMC_FLAG
;
987 else if(FSMC_Bank
== FSMC_Bank3_NAND
)
989 FSMC_Bank3
->SR3
&= ~FSMC_FLAG
;
991 /* FSMC_Bank4_PCCARD*/
994 FSMC_Bank4
->SR4
&= ~FSMC_FLAG
;
999 * @brief Checks whether the specified FSMC interrupt has occurred or not.
1000 * @param FSMC_Bank: specifies the FSMC Bank to be used
1001 * This parameter can be one of the following values:
1002 * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
1003 * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
1004 * @arg FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
1005 * @param FSMC_IT: specifies the FSMC interrupt source to check.
1006 * This parameter can be one of the following values:
1007 * @arg FSMC_IT_RisingEdge: Rising edge detection interrupt.
1008 * @arg FSMC_IT_Level: Level edge detection interrupt.
1009 * @arg FSMC_IT_FallingEdge: Falling edge detection interrupt.
1010 * @retval The new state of FSMC_IT (SET or RESET).
1012 ITStatus
FSMC_GetITStatus(uint32_t FSMC_Bank
, uint32_t FSMC_IT
)
1014 ITStatus bitstatus
= RESET
;
1015 uint32_t tmpsr
= 0x0, itstatus
= 0x0, itenable
= 0x0;
1017 /* Check the parameters */
1018 assert_param(IS_FSMC_IT_BANK(FSMC_Bank
));
1019 assert_param(IS_FSMC_GET_IT(FSMC_IT
));
1021 if(FSMC_Bank
== FSMC_Bank2_NAND
)
1023 tmpsr
= FSMC_Bank2
->SR2
;
1025 else if(FSMC_Bank
== FSMC_Bank3_NAND
)
1027 tmpsr
= FSMC_Bank3
->SR3
;
1029 /* FSMC_Bank4_PCCARD*/
1032 tmpsr
= FSMC_Bank4
->SR4
;
1035 itstatus
= tmpsr
& FSMC_IT
;
1037 itenable
= tmpsr
& (FSMC_IT
>> 3);
1038 if ((itstatus
!= (uint32_t)RESET
) && (itenable
!= (uint32_t)RESET
))
1050 * @brief Clears the FSMC's interrupt pending bits.
1051 * @param FSMC_Bank: specifies the FSMC Bank to be used
1052 * This parameter can be one of the following values:
1053 * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
1054 * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
1055 * @arg FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
1056 * @param FSMC_IT: specifies the interrupt pending bit to clear.
1057 * This parameter can be any combination of the following values:
1058 * @arg FSMC_IT_RisingEdge: Rising edge detection interrupt.
1059 * @arg FSMC_IT_Level: Level edge detection interrupt.
1060 * @arg FSMC_IT_FallingEdge: Falling edge detection interrupt.
1063 void FSMC_ClearITPendingBit(uint32_t FSMC_Bank
, uint32_t FSMC_IT
)
1065 /* Check the parameters */
1066 assert_param(IS_FSMC_IT_BANK(FSMC_Bank
));
1067 assert_param(IS_FSMC_IT(FSMC_IT
));
1069 if(FSMC_Bank
== FSMC_Bank2_NAND
)
1071 FSMC_Bank2
->SR2
&= ~(FSMC_IT
>> 3);
1073 else if(FSMC_Bank
== FSMC_Bank3_NAND
)
1075 FSMC_Bank3
->SR3
&= ~(FSMC_IT
>> 3);
1077 /* FSMC_Bank4_PCCARD*/
1080 FSMC_Bank4
->SR4
&= ~(FSMC_IT
>> 3);
1100 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/