2 ******************************************************************************
3 * @file stm32f1xx_ll_fsmc.c
4 * @author MCD Application Team
7 * @brief FSMC Low Layer HAL module driver.
9 * This file provides firmware functions to manage the following
10 * functionalities of the Flexible Static Memory Controller (FSMC) peripheral memories:
11 * + Initialization/de-initialization functions
12 * + Peripheral Control functions
13 * + Peripheral State functions
16 =============================================================================
17 ##### FSMC peripheral features #####
18 =============================================================================
19 [..] The Flexible static memory controller (FSMC) includes following memory controllers:
20 (+) The NOR/PSRAM memory controller
21 (+) The PC Card memory controller
22 (+) The NAND memory controller
23 (PC Card and NAND controllers available only on STM32F101xE, STM32F103xE, STM32F101xG and STM32F103xG)
25 [..] The FSMC functional block makes the interface with synchronous and asynchronous static
26 memories and 16-bit PC memory cards. Its main purposes are:
27 (+) to translate AHB transactions into the appropriate external device protocol.
28 (+) to meet the access time requirements of the external memory devices.
30 [..] All external memories share the addresses, data and control signals with the controller.
31 Each external device is accessed by means of a unique Chip Select. The FSMC performs
32 only one access at a time to an external device.
33 The main features of the FSMC controller are the following:
34 (+) Interface with static-memory mapped devices including:
35 (++) Static random access memory (SRAM).
36 (++) NOR Flash memory.
37 (++) PSRAM (4 memory banks).
38 (++) 16-bit PC Card compatible devices.
39 (++) Two banks of NAND Flash memory with ECC hardware to check up to 8 Kbytes of
41 (+) Independent Chip Select control for each memory bank.
42 (+) Independent configuration for each memory bank.
45 ******************************************************************************
48 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
50 * Redistribution and use in source and binary forms, with or without modification,
51 * are permitted provided that the following conditions are met:
52 * 1. Redistributions of source code must retain the above copyright notice,
53 * this list of conditions and the following disclaimer.
54 * 2. Redistributions in binary form must reproduce the above copyright notice,
55 * this list of conditions and the following disclaimer in the documentation
56 * and/or other materials provided with the distribution.
57 * 3. Neither the name of STMicroelectronics nor the names of its contributors
58 * may be used to endorse or promote products derived from this software
59 * without specific prior written permission.
61 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
62 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
63 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
64 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
65 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
66 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
67 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
68 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
69 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
70 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
72 ******************************************************************************
75 /* Includes ------------------------------------------------------------------*/
76 #include "stm32f1xx_hal.h"
78 /** @addtogroup STM32F1xx_HAL_Driver
82 #if defined(FSMC_BANK1)
84 #if defined(HAL_SRAM_MODULE_ENABLED) || defined(HAL_NOR_MODULE_ENABLED) || defined(HAL_PCCARD_MODULE_ENABLED) || defined(HAL_NAND_MODULE_ENABLED)
86 /** @defgroup FSMC_LL FSMC Low Layer
87 * @brief FSMC driver modules
91 /* Private typedef -----------------------------------------------------------*/
92 /* Private define ------------------------------------------------------------*/
93 /* Private macro -------------------------------------------------------------*/
94 /* Private variables ---------------------------------------------------------*/
95 /* Private function prototypes -----------------------------------------------*/
96 /* Exported functions --------------------------------------------------------*/
98 /** @defgroup FSMC_LL_Exported_Functions FSMC Low Layer Exported Functions
102 /** @defgroup FSMC_NORSRAM FSMC NORSRAM Controller functions
103 * @brief NORSRAM Controller functions
106 ==============================================================================
107 ##### How to use NORSRAM device driver #####
108 ==============================================================================
111 This driver contains a set of APIs to interface with the FSMC NORSRAM banks in order
112 to run the NORSRAM external devices.
114 (+) FSMC NORSRAM bank reset using the function FSMC_NORSRAM_DeInit()
115 (+) FSMC NORSRAM bank control configuration using the function FSMC_NORSRAM_Init()
116 (+) FSMC NORSRAM bank timing configuration using the function FSMC_NORSRAM_Timing_Init()
117 (+) FSMC NORSRAM bank extended timing configuration using the function
118 FSMC_NORSRAM_Extended_Timing_Init()
119 (+) FSMC NORSRAM bank enable/disable write operation using the functions
120 FSMC_NORSRAM_WriteOperation_Enable()/FSMC_NORSRAM_WriteOperation_Disable()
126 /** @addtogroup FSMC_LL_NORSRAM_Private_Functions_Group1
127 * @brief Initialization and Configuration functions
130 ==============================================================================
131 ##### Initialization and de_initialization functions #####
132 ==============================================================================
134 This section provides functions allowing to:
135 (+) Initialize and configure the FSMC NORSRAM interface
136 (+) De-initialize the FSMC NORSRAM interface
137 (+) Configure the FSMC clock and associated GPIOs
144 * @brief Initialize the FSMC_NORSRAM device according to the specified
145 * control parameters in the FSMC_NORSRAM_InitTypeDef
146 * @param Device: Pointer to NORSRAM device instance
147 * @param Init: Pointer to NORSRAM Initialization structure
150 HAL_StatusTypeDef
FSMC_NORSRAM_Init(FSMC_NORSRAM_TypeDef
*Device
, FSMC_NORSRAM_InitTypeDef
*Init
)
152 /* Check the parameters */
153 assert_param(IS_FSMC_NORSRAM_DEVICE(Device
));
154 assert_param(IS_FSMC_NORSRAM_BANK(Init
->NSBank
));
155 assert_param(IS_FSMC_MUX(Init
->DataAddressMux
));
156 assert_param(IS_FSMC_MEMORY(Init
->MemoryType
));
157 assert_param(IS_FSMC_NORSRAM_MEMORY_WIDTH(Init
->MemoryDataWidth
));
158 assert_param(IS_FSMC_BURSTMODE(Init
->BurstAccessMode
));
159 assert_param(IS_FSMC_WAIT_POLARITY(Init
->WaitSignalPolarity
));
160 assert_param(IS_FSMC_WRAP_MODE(Init
->WrapMode
));
161 assert_param(IS_FSMC_WAIT_SIGNAL_ACTIVE(Init
->WaitSignalActive
));
162 assert_param(IS_FSMC_WRITE_OPERATION(Init
->WriteOperation
));
163 assert_param(IS_FSMC_WAITE_SIGNAL(Init
->WaitSignal
));
164 assert_param(IS_FSMC_EXTENDED_MODE(Init
->ExtendedMode
));
165 assert_param(IS_FSMC_ASYNWAIT(Init
->AsynchronousWait
));
166 assert_param(IS_FSMC_WRITE_BURST(Init
->WriteBurst
));
168 /* Disable NORSRAM Device */
169 __FSMC_NORSRAM_DISABLE(Device
, Init
->NSBank
);
171 /* Set NORSRAM device control parameters */
172 if (Init
->MemoryType
== FSMC_MEMORY_TYPE_NOR
)
174 MODIFY_REG(Device
->BTCR
[Init
->NSBank
], BCR_CLEAR_MASK
, (uint32_t)(FSMC_NORSRAM_FLASH_ACCESS_ENABLE
175 | Init
->DataAddressMux
177 | Init
->MemoryDataWidth
178 | Init
->BurstAccessMode
179 | Init
->WaitSignalPolarity
181 | Init
->WaitSignalActive
182 | Init
->WriteOperation
185 | Init
->AsynchronousWait
192 MODIFY_REG(Device
->BTCR
[Init
->NSBank
], BCR_CLEAR_MASK
, (uint32_t)(FSMC_NORSRAM_FLASH_ACCESS_DISABLE
193 | Init
->DataAddressMux
195 | Init
->MemoryDataWidth
196 | Init
->BurstAccessMode
197 | Init
->WaitSignalPolarity
199 | Init
->WaitSignalActive
200 | Init
->WriteOperation
203 | Init
->AsynchronousWait
213 * @brief DeInitialize the FSMC_NORSRAM peripheral
214 * @param Device: Pointer to NORSRAM device instance
215 * @param ExDevice: Pointer to NORSRAM extended mode device instance
216 * @param Bank: NORSRAM bank number
219 HAL_StatusTypeDef
FSMC_NORSRAM_DeInit(FSMC_NORSRAM_TypeDef
*Device
, FSMC_NORSRAM_EXTENDED_TypeDef
*ExDevice
, uint32_t Bank
)
221 /* Check the parameters */
222 assert_param(IS_FSMC_NORSRAM_DEVICE(Device
));
223 assert_param(IS_FSMC_NORSRAM_EXTENDED_DEVICE(ExDevice
));
224 assert_param(IS_FSMC_NORSRAM_BANK(Bank
));
226 /* Disable the FSMC_NORSRAM device */
227 __FSMC_NORSRAM_DISABLE(Device
, Bank
);
229 /* De-initialize the FSMC_NORSRAM device */
230 /* FSMC_NORSRAM_BANK1 */
231 if(Bank
== FSMC_NORSRAM_BANK1
)
233 Device
->BTCR
[Bank
] = 0x000030DBU
;
235 /* FSMC_NORSRAM_BANK2, FSMC_NORSRAM_BANK3 or FSMC_NORSRAM_BANK4 */
238 Device
->BTCR
[Bank
] = 0x000030D2U
;
241 Device
->BTCR
[Bank
+ 1U] = 0x0FFFFFFFU
;
242 ExDevice
->BWTR
[Bank
] = 0x0FFFFFFFU
;
249 * @brief Initialize the FSMC_NORSRAM Timing according to the specified
250 * parameters in the FSMC_NORSRAM_TimingTypeDef
251 * @param Device: Pointer to NORSRAM device instance
252 * @param Timing: Pointer to NORSRAM Timing structure
253 * @param Bank: NORSRAM bank number
256 HAL_StatusTypeDef
FSMC_NORSRAM_Timing_Init(FSMC_NORSRAM_TypeDef
*Device
, FSMC_NORSRAM_TimingTypeDef
*Timing
, uint32_t Bank
)
258 /* Check the parameters */
259 assert_param(IS_FSMC_NORSRAM_DEVICE(Device
));
260 assert_param(IS_FSMC_ADDRESS_SETUP_TIME(Timing
->AddressSetupTime
));
261 assert_param(IS_FSMC_ADDRESS_HOLD_TIME(Timing
->AddressHoldTime
));
262 assert_param(IS_FSMC_DATASETUP_TIME(Timing
->DataSetupTime
));
263 assert_param(IS_FSMC_TURNAROUND_TIME(Timing
->BusTurnAroundDuration
));
264 assert_param(IS_FSMC_CLK_DIV(Timing
->CLKDivision
));
265 assert_param(IS_FSMC_DATA_LATENCY(Timing
->DataLatency
));
266 assert_param(IS_FSMC_ACCESS_MODE(Timing
->AccessMode
));
267 assert_param(IS_FSMC_NORSRAM_BANK(Bank
));
269 /* Set FSMC_NORSRAM device timing parameters */
270 MODIFY_REG(Device
->BTCR
[Bank
+ 1U], \
272 (uint32_t)(Timing
->AddressSetupTime
| \
273 ((Timing
->AddressHoldTime
) << FSMC_BTRx_ADDHLD_Pos
) | \
274 ((Timing
->DataSetupTime
) << FSMC_BTRx_DATAST_Pos
) | \
275 ((Timing
->BusTurnAroundDuration
) << FSMC_BTRx_BUSTURN_Pos
) | \
276 (((Timing
->CLKDivision
) - 1U) << FSMC_BTRx_CLKDIV_Pos
) | \
277 (((Timing
->DataLatency
) - 2U) << FSMC_BTRx_DATLAT_Pos
) | \
278 (Timing
->AccessMode
)));
284 * @brief Initialize the FSMC_NORSRAM Extended mode Timing according to the specified
285 * parameters in the FSMC_NORSRAM_TimingTypeDef
286 * @param Device: Pointer to NORSRAM device instance
287 * @param Timing: Pointer to NORSRAM Timing structure
288 * @param Bank: NORSRAM bank number
289 * @param ExtendedMode FSMC Extended Mode
290 * This parameter can be one of the following values:
291 * @arg FSMC_EXTENDED_MODE_DISABLE
292 * @arg FSMC_EXTENDED_MODE_ENABLE
295 HAL_StatusTypeDef
FSMC_NORSRAM_Extended_Timing_Init(FSMC_NORSRAM_EXTENDED_TypeDef
*Device
, FSMC_NORSRAM_TimingTypeDef
*Timing
, uint32_t Bank
, uint32_t ExtendedMode
)
297 /* Check the parameters */
298 assert_param(IS_FSMC_EXTENDED_MODE(ExtendedMode
));
300 /* Set NORSRAM device timing register for write configuration, if extended mode is used */
301 if(ExtendedMode
== FSMC_EXTENDED_MODE_ENABLE
)
303 /* Check the parameters */
304 assert_param(IS_FSMC_NORSRAM_EXTENDED_DEVICE(Device
));
305 assert_param(IS_FSMC_ADDRESS_SETUP_TIME(Timing
->AddressSetupTime
));
306 assert_param(IS_FSMC_ADDRESS_HOLD_TIME(Timing
->AddressHoldTime
));
307 assert_param(IS_FSMC_DATASETUP_TIME(Timing
->DataSetupTime
));
308 #if defined(STM32F101xE) || defined(STM32F103xE) || defined(STM32F101xG) || defined(STM32F103xG)
309 assert_param(IS_FSMC_TURNAROUND_TIME(Timing
->BusTurnAroundDuration
));
311 assert_param(IS_FSMC_CLK_DIV(Timing
->CLKDivision
));
312 assert_param(IS_FSMC_DATA_LATENCY(Timing
->DataLatency
));
313 #endif /* STM32F101xE || STM32F103xE || STM32F101xG || STM32F103xG */
314 assert_param(IS_FSMC_ACCESS_MODE(Timing
->AccessMode
));
315 assert_param(IS_FSMC_NORSRAM_BANK(Bank
));
317 /* Set NORSRAM device timing register for write configuration, if extended mode is used */
318 #if defined(STM32F101xE) || defined(STM32F103xE) || defined(STM32F101xG) || defined(STM32F103xG)
319 MODIFY_REG(Device
->BWTR
[Bank
], \
321 (uint32_t)(Timing
->AddressSetupTime
| \
322 ((Timing
->AddressHoldTime
) << FSMC_BWTRx_ADDHLD_Pos
) | \
323 ((Timing
->DataSetupTime
) << FSMC_BWTRx_DATAST_Pos
) | \
324 Timing
->AccessMode
| \
325 ((Timing
->BusTurnAroundDuration
) << FSMC_BWTRx_BUSTURN_Pos
)));
327 MODIFY_REG(Device
->BWTR
[Bank
], \
329 (uint32_t)(Timing
->AddressSetupTime
| \
330 ((Timing
->AddressHoldTime
) << FSMC_BWTRx_ADDHLD_Pos
) | \
331 ((Timing
->DataSetupTime
) << FSMC_BWTRx_DATAST_Pos
) | \
332 Timing
->AccessMode
| \
333 (((Timing
->CLKDivision
) - 1U) << FSMC_BTRx_CLKDIV_Pos
) | \
334 (((Timing
->DataLatency
) - 2U) << FSMC_BWTRx_DATLAT_Pos
)));
335 #endif /* STM32F101xE || STM32F103xE || STM32F101xG || STM32F103xG */
339 Device
->BWTR
[Bank
] = 0x0FFFFFFFU
;
348 /** @defgroup FSMC_NORSRAM_Group2 Control functions
349 * @brief management functions
352 ==============================================================================
353 ##### FSMC_NORSRAM Control functions #####
354 ==============================================================================
356 This subsection provides a set of functions allowing to control dynamically
357 the FSMC NORSRAM interface.
364 * @brief Enables dynamically FSMC_NORSRAM write operation.
365 * @param Device: Pointer to NORSRAM device instance
366 * @param Bank: NORSRAM bank number
369 HAL_StatusTypeDef
FSMC_NORSRAM_WriteOperation_Enable(FSMC_NORSRAM_TypeDef
*Device
, uint32_t Bank
)
371 /* Check the parameters */
372 assert_param(IS_FSMC_NORSRAM_DEVICE(Device
));
373 assert_param(IS_FSMC_NORSRAM_BANK(Bank
));
375 /* Enable write operation */
376 SET_BIT(Device
->BTCR
[Bank
], FSMC_WRITE_OPERATION_ENABLE
);
382 * @brief Disables dynamically FSMC_NORSRAM write operation.
383 * @param Device: Pointer to NORSRAM device instance
384 * @param Bank: NORSRAM bank number
387 HAL_StatusTypeDef
FSMC_NORSRAM_WriteOperation_Disable(FSMC_NORSRAM_TypeDef
*Device
, uint32_t Bank
)
389 /* Check the parameters */
390 assert_param(IS_FSMC_NORSRAM_DEVICE(Device
));
391 assert_param(IS_FSMC_NORSRAM_BANK(Bank
));
393 /* Disable write operation */
394 CLEAR_BIT(Device
->BTCR
[Bank
], FSMC_WRITE_OPERATION_ENABLE
);
406 #if (defined (STM32F101xE) || defined(STM32F103xE) || defined(STM32F101xG) || defined(STM32F103xG))
407 /** @defgroup FSMC_NAND FSMC NAND Controller functions
408 * @brief NAND Controller functions
411 ==============================================================================
412 ##### How to use NAND device driver #####
413 ==============================================================================
415 This driver contains a set of APIs to interface with the FSMC NAND banks in order
416 to run the NAND external devices.
418 (+) FSMC NAND bank reset using the function FSMC_NAND_DeInit()
419 (+) FSMC NAND bank control configuration using the function FSMC_NAND_Init()
420 (+) FSMC NAND bank common space timing configuration using the function
421 FSMC_NAND_CommonSpace_Timing_Init()
422 (+) FSMC NAND bank attribute space timing configuration using the function
423 FSMC_NAND_AttributeSpace_Timing_Init()
424 (+) FSMC NAND bank enable/disable ECC correction feature using the functions
425 FSMC_NAND_ECC_Enable()/FSMC_NAND_ECC_Disable()
426 (+) FSMC NAND bank get ECC correction code using the function FSMC_NAND_GetECC()
432 /** @defgroup FSMC_NAND_Exported_Functions_Group1 Initialization and de-initialization functions
433 * @brief Initialization and Configuration functions
436 ==============================================================================
437 ##### Initialization and de_initialization functions #####
438 ==============================================================================
440 This section provides functions allowing to:
441 (+) Initialize and configure the FSMC NAND interface
442 (+) De-initialize the FSMC NAND interface
443 (+) Configure the FSMC clock and associated GPIOs
450 * @brief Initializes the FSMC_NAND device according to the specified
451 * control parameters in the FSMC_NAND_HandleTypeDef
452 * @param Device: Pointer to NAND device instance
453 * @param Init: Pointer to NAND Initialization structure
456 HAL_StatusTypeDef
FSMC_NAND_Init(FSMC_NAND_TypeDef
*Device
, FSMC_NAND_InitTypeDef
*Init
)
458 /* Check the parameters */
459 assert_param(IS_FSMC_NAND_DEVICE(Device
));
460 assert_param(IS_FSMC_NAND_BANK(Init
->NandBank
));
461 assert_param(IS_FSMC_WAIT_FEATURE(Init
->Waitfeature
));
462 assert_param(IS_FSMC_NAND_MEMORY_WIDTH(Init
->MemoryDataWidth
));
463 assert_param(IS_FSMC_ECC_STATE(Init
->EccComputation
));
464 assert_param(IS_FSMC_ECCPAGE_SIZE(Init
->ECCPageSize
));
465 assert_param(IS_FSMC_TCLR_TIME(Init
->TCLRSetupTime
));
466 assert_param(IS_FSMC_TAR_TIME(Init
->TARSetupTime
));
468 /* Set NAND device control parameters */
469 if (Init
->NandBank
== FSMC_NAND_BANK2
)
471 /* NAND bank 2 registers configuration */
472 MODIFY_REG(Device
->PCR2
, PCR_CLEAR_MASK
, (Init
->Waitfeature
|
473 FSMC_PCR_MEMORY_TYPE_NAND
|
474 Init
->MemoryDataWidth
|
475 Init
->EccComputation
|
477 ((Init
->TCLRSetupTime
) << FSMC_PCRx_TCLR_Pos
) |
478 ((Init
->TARSetupTime
) << FSMC_PCRx_TAR_Pos
)));
482 /* NAND bank 3 registers configuration */
483 MODIFY_REG(Device
->PCR3
, PCR_CLEAR_MASK
, (Init
->Waitfeature
|
484 FSMC_PCR_MEMORY_TYPE_NAND
|
485 Init
->MemoryDataWidth
|
486 Init
->EccComputation
|
488 ((Init
->TCLRSetupTime
) << FSMC_PCRx_TCLR_Pos
) |
489 ((Init
->TARSetupTime
) << FSMC_PCRx_TAR_Pos
)));
496 * @brief Initializes the FSMC_NAND Common space Timing according to the specified
497 * parameters in the FSMC_NAND_PCC_TimingTypeDef
498 * @param Device: Pointer to NAND device instance
499 * @param Timing: Pointer to NAND timing structure
500 * @param Bank: NAND bank number
503 HAL_StatusTypeDef
FSMC_NAND_CommonSpace_Timing_Init(FSMC_NAND_TypeDef
*Device
, FSMC_NAND_PCC_TimingTypeDef
*Timing
, uint32_t Bank
)
505 /* Check the parameters */
506 assert_param(IS_FSMC_NAND_DEVICE(Device
));
507 assert_param(IS_FSMC_SETUP_TIME(Timing
->SetupTime
));
508 assert_param(IS_FSMC_WAIT_TIME(Timing
->WaitSetupTime
));
509 assert_param(IS_FSMC_HOLD_TIME(Timing
->HoldSetupTime
));
510 assert_param(IS_FSMC_HIZ_TIME(Timing
->HiZSetupTime
));
511 assert_param(IS_FSMC_NAND_BANK(Bank
));
513 /* Set FMC_NAND device timing parameters */
514 if(Bank
== FSMC_NAND_BANK2
)
516 /* NAND bank 2 registers configuration */
517 MODIFY_REG(Device
->PMEM2
, PMEM_CLEAR_MASK
, (Timing
->SetupTime
| \
518 ((Timing
->WaitSetupTime
) << FSMC_PMEMx_MEMWAITx_Pos
) | \
519 ((Timing
->HoldSetupTime
) << FSMC_PMEMx_MEMHOLDx_Pos
) | \
520 ((Timing
->HiZSetupTime
) << FSMC_PMEMx_MEMHIZx_Pos
)));
524 /* NAND bank 3 registers configuration */
525 MODIFY_REG(Device
->PMEM3
, PMEM_CLEAR_MASK
, (Timing
->SetupTime
| \
526 ((Timing
->WaitSetupTime
) << FSMC_PMEMx_MEMWAITx_Pos
) | \
527 ((Timing
->HoldSetupTime
) << FSMC_PMEMx_MEMHOLDx_Pos
) | \
528 ((Timing
->HiZSetupTime
) << FSMC_PMEMx_MEMHIZx_Pos
)));
535 * @brief Initializes the FSMC_NAND Attribute space Timing according to the specified
536 * parameters in the FSMC_NAND_PCC_TimingTypeDef
537 * @param Device: Pointer to NAND device instance
538 * @param Timing: Pointer to NAND timing structure
539 * @param Bank: NAND bank number
542 HAL_StatusTypeDef
FSMC_NAND_AttributeSpace_Timing_Init(FSMC_NAND_TypeDef
*Device
, FSMC_NAND_PCC_TimingTypeDef
*Timing
, uint32_t Bank
)
544 /* Check the parameters */
545 assert_param(IS_FSMC_NAND_DEVICE(Device
));
546 assert_param(IS_FSMC_SETUP_TIME(Timing
->SetupTime
));
547 assert_param(IS_FSMC_WAIT_TIME(Timing
->WaitSetupTime
));
548 assert_param(IS_FSMC_HOLD_TIME(Timing
->HoldSetupTime
));
549 assert_param(IS_FSMC_HIZ_TIME(Timing
->HiZSetupTime
));
550 assert_param(IS_FSMC_NAND_BANK(Bank
));
552 /* Set FMC_NAND device timing parameters */
553 if(Bank
== FSMC_NAND_BANK2
)
555 /* NAND bank 2 registers configuration */
556 MODIFY_REG(Device
->PATT2
, PATT_CLEAR_MASK
, (Timing
->SetupTime
| \
557 ((Timing
->WaitSetupTime
) << FSMC_PATTx_ATTWAITx_Pos
) | \
558 ((Timing
->HoldSetupTime
) << FSMC_PATTx_ATTHOLDx_Pos
) | \
559 ((Timing
->HiZSetupTime
) << FSMC_PATTx_ATTHIZx_Pos
)));
563 /* NAND bank 3 registers configuration */
564 MODIFY_REG(Device
->PATT3
, PATT_CLEAR_MASK
, (Timing
->SetupTime
| \
565 ((Timing
->WaitSetupTime
) << FSMC_PATTx_ATTWAITx_Pos
) | \
566 ((Timing
->HoldSetupTime
) << FSMC_PATTx_ATTHOLDx_Pos
) | \
567 ((Timing
->HiZSetupTime
) << FSMC_PATTx_ATTHIZx_Pos
)));
575 * @brief DeInitializes the FSMC_NAND device
576 * @param Device: Pointer to NAND device instance
577 * @param Bank: NAND bank number
580 HAL_StatusTypeDef
FSMC_NAND_DeInit(FSMC_NAND_TypeDef
*Device
, uint32_t Bank
)
582 /* Check the parameters */
583 assert_param(IS_FSMC_NAND_DEVICE(Device
));
584 assert_param(IS_FSMC_NAND_BANK(Bank
));
586 /* Disable the NAND Bank */
587 __FSMC_NAND_DISABLE(Device
, Bank
);
589 /* De-initialize the NAND Bank */
590 if(Bank
== FSMC_NAND_BANK2
)
592 /* Set the FSMC_NAND_BANK2 registers to their reset values */
593 WRITE_REG(Device
->PCR2
, 0x00000018U
);
594 WRITE_REG(Device
->SR2
, 0x00000040U
);
595 WRITE_REG(Device
->PMEM2
, 0xFCFCFCFCU
);
596 WRITE_REG(Device
->PATT2
, 0xFCFCFCFCU
);
598 /* FSMC_Bank3_NAND */
601 /* Set the FSMC_NAND_BANK3 registers to their reset values */
602 WRITE_REG(Device
->PCR3
, 0x00000018U
);
603 WRITE_REG(Device
->SR3
, 0x00000040U
);
604 WRITE_REG(Device
->PMEM3
, 0xFCFCFCFCU
);
605 WRITE_REG(Device
->PATT3
, 0xFCFCFCFCU
);
616 /** @defgroup FSMC_NAND_Exported_Functions_Group2 Peripheral Control functions
617 * @brief management functions
620 ==============================================================================
621 ##### FSMC_NAND Control functions #####
622 ==============================================================================
624 This subsection provides a set of functions allowing to control dynamically
625 the FSMC NAND interface.
632 * @brief Enables dynamically FSMC_NAND ECC feature.
633 * @param Device: Pointer to NAND device instance
634 * @param Bank: NAND bank number
637 HAL_StatusTypeDef
FSMC_NAND_ECC_Enable(FSMC_NAND_TypeDef
*Device
, uint32_t Bank
)
639 /* Check the parameters */
640 assert_param(IS_FSMC_NAND_DEVICE(Device
));
641 assert_param(IS_FSMC_NAND_BANK(Bank
));
643 /* Enable ECC feature */
644 if(Bank
== FSMC_NAND_BANK2
)
646 SET_BIT(Device
->PCR2
, FSMC_PCRx_ECCEN
);
650 SET_BIT(Device
->PCR3
, FSMC_PCRx_ECCEN
);
657 * @brief Disables dynamically FSMC_NAND ECC feature.
658 * @param Device: Pointer to NAND device instance
659 * @param Bank: NAND bank number
662 HAL_StatusTypeDef
FSMC_NAND_ECC_Disable(FSMC_NAND_TypeDef
*Device
, uint32_t Bank
)
664 /* Check the parameters */
665 assert_param(IS_FSMC_NAND_DEVICE(Device
));
666 assert_param(IS_FSMC_NAND_BANK(Bank
));
668 /* Disable ECC feature */
669 if(Bank
== FSMC_NAND_BANK2
)
671 CLEAR_BIT(Device
->PCR2
, FSMC_PCRx_ECCEN
);
675 CLEAR_BIT(Device
->PCR3
, FSMC_PCRx_ECCEN
);
682 * @brief Disables dynamically FSMC_NAND ECC feature.
683 * @param Device: Pointer to NAND device instance
684 * @param ECCval: Pointer to ECC value
685 * @param Bank: NAND bank number
686 * @param Timeout: Timeout wait value
689 HAL_StatusTypeDef
FSMC_NAND_GetECC(FSMC_NAND_TypeDef
*Device
, uint32_t *ECCval
, uint32_t Bank
, uint32_t Timeout
)
691 uint32_t tickstart
= 0U;
693 /* Check the parameters */
694 assert_param(IS_FSMC_NAND_DEVICE(Device
));
695 assert_param(IS_FSMC_NAND_BANK(Bank
));
698 tickstart
= HAL_GetTick();
700 /* Wait until FIFO is empty */
701 while(__FSMC_NAND_GET_FLAG(Device
, Bank
, FSMC_FLAG_FEMPT
) == RESET
)
703 /* Check for the Timeout */
704 if(Timeout
!= HAL_MAX_DELAY
)
706 if((Timeout
== 0U)||((HAL_GetTick() - tickstart
) > Timeout
))
713 if(Bank
== FSMC_NAND_BANK2
)
715 /* Get the ECCR2 register value */
716 *ECCval
= (uint32_t)Device
->ECCR2
;
720 /* Get the ECCR3 register value */
721 *ECCval
= (uint32_t)Device
->ECCR3
;
735 /** @defgroup FSMC_PCCARD FSMC PCCARD Controller functions
736 * @brief PCCARD Controller functions
739 ==============================================================================
740 ##### How to use PCCARD device driver #####
741 ==============================================================================
743 This driver contains a set of APIs to interface with the FSMC PCCARD bank in order
744 to run the PCCARD/compact flash external devices.
746 (+) FSMC PCCARD bank reset using the function FSMC_PCCARD_DeInit()
747 (+) FSMC PCCARD bank control configuration using the function FSMC_PCCARD_Init()
748 (+) FSMC PCCARD bank common space timing configuration using the function
749 FSMC_PCCARD_CommonSpace_Timing_Init()
750 (+) FSMC PCCARD bank attribute space timing configuration using the function
751 FSMC_PCCARD_AttributeSpace_Timing_Init()
752 (+) FSMC PCCARD bank IO space timing configuration using the function
753 FSMC_PCCARD_IOSpace_Timing_Init()
759 /** @defgroup FSMC_PCCARD_Exported_Functions_Group1 Initialization and de-initialization functions
760 * @brief Initialization and Configuration functions
763 ==============================================================================
764 ##### Initialization and de_initialization functions #####
765 ==============================================================================
767 This section provides functions allowing to:
768 (+) Initialize and configure the FSMC PCCARD interface
769 (+) De-initialize the FSMC PCCARD interface
770 (+) Configure the FSMC clock and associated GPIOs
777 * @brief Initializes the FSMC_PCCARD device according to the specified
778 * control parameters in the FSMC_PCCARD_HandleTypeDef
779 * @param Device: Pointer to PCCARD device instance
780 * @param Init: Pointer to PCCARD Initialization structure
783 HAL_StatusTypeDef
FSMC_PCCARD_Init(FSMC_PCCARD_TypeDef
*Device
, FSMC_PCCARD_InitTypeDef
*Init
)
785 /* Check the parameters */
786 assert_param(IS_FSMC_PCCARD_DEVICE(Device
));
787 assert_param(IS_FSMC_WAIT_FEATURE(Init
->Waitfeature
));
788 assert_param(IS_FSMC_TCLR_TIME(Init
->TCLRSetupTime
));
789 assert_param(IS_FSMC_TAR_TIME(Init
->TARSetupTime
));
791 /* Set FSMC_PCCARD device control parameters */
792 MODIFY_REG(Device
->PCR4
,
793 (FSMC_PCRx_PTYP
| FSMC_PCRx_PWAITEN
| FSMC_PCRx_PWID
|
794 FSMC_PCRx_TCLR
| FSMC_PCRx_TAR
),
795 (FSMC_PCR_MEMORY_TYPE_PCCARD
|
797 FSMC_NAND_PCC_MEM_BUS_WIDTH_16
|
798 (Init
->TCLRSetupTime
<< FSMC_PCRx_TCLR_Pos
) |
799 (Init
->TARSetupTime
<< FSMC_PCRx_TAR_Pos
)));
806 * @brief Initializes the FSMC_PCCARD Common space Timing according to the specified
807 * parameters in the FSMC_NAND_PCC_TimingTypeDef
808 * @param Device: Pointer to PCCARD device instance
809 * @param Timing: Pointer to PCCARD timing structure
812 HAL_StatusTypeDef
FSMC_PCCARD_CommonSpace_Timing_Init(FSMC_PCCARD_TypeDef
*Device
, FSMC_NAND_PCC_TimingTypeDef
*Timing
)
814 /* Check the parameters */
815 assert_param(IS_FSMC_PCCARD_DEVICE(Device
));
816 assert_param(IS_FSMC_SETUP_TIME(Timing
->SetupTime
));
817 assert_param(IS_FSMC_WAIT_TIME(Timing
->WaitSetupTime
));
818 assert_param(IS_FSMC_HOLD_TIME(Timing
->HoldSetupTime
));
819 assert_param(IS_FSMC_HIZ_TIME(Timing
->HiZSetupTime
));
821 /* Set PCCARD timing parameters */
822 MODIFY_REG(Device
->PMEM4
, PMEM_CLEAR_MASK
,
824 ((Timing
->WaitSetupTime
) << FSMC_PMEMx_MEMWAITx_Pos
) |
825 ((Timing
->HoldSetupTime
) << FSMC_PMEMx_MEMHOLDx_Pos
) |
826 ((Timing
->HiZSetupTime
) << FSMC_PMEMx_MEMHIZx_Pos
)));
832 * @brief Initializes the FSMC_PCCARD Attribute space Timing according to the specified
833 * parameters in the FSMC_NAND_PCC_TimingTypeDef
834 * @param Device: Pointer to PCCARD device instance
835 * @param Timing: Pointer to PCCARD timing structure
838 HAL_StatusTypeDef
FSMC_PCCARD_AttributeSpace_Timing_Init(FSMC_PCCARD_TypeDef
*Device
, FSMC_NAND_PCC_TimingTypeDef
*Timing
)
840 /* Check the parameters */
841 assert_param(IS_FSMC_PCCARD_DEVICE(Device
));
842 assert_param(IS_FSMC_SETUP_TIME(Timing
->SetupTime
));
843 assert_param(IS_FSMC_WAIT_TIME(Timing
->WaitSetupTime
));
844 assert_param(IS_FSMC_HOLD_TIME(Timing
->HoldSetupTime
));
845 assert_param(IS_FSMC_HIZ_TIME(Timing
->HiZSetupTime
));
847 /* Set PCCARD timing parameters */
848 MODIFY_REG(Device
->PATT4
, PATT_CLEAR_MASK
, \
849 (Timing
->SetupTime
| \
850 ((Timing
->WaitSetupTime
) << FSMC_PATTx_ATTWAITx_Pos
) | \
851 ((Timing
->HoldSetupTime
) << FSMC_PATTx_ATTHOLDx_Pos
) | \
852 ((Timing
->HiZSetupTime
) << FSMC_PATTx_ATTHIZx_Pos
)));
858 * @brief Initializes the FSMC_PCCARD IO space Timing according to the specified
859 * parameters in the FSMC_NAND_PCC_TimingTypeDef
860 * @param Device: Pointer to PCCARD device instance
861 * @param Timing: Pointer to PCCARD timing structure
864 HAL_StatusTypeDef
FSMC_PCCARD_IOSpace_Timing_Init(FSMC_PCCARD_TypeDef
*Device
, FSMC_NAND_PCC_TimingTypeDef
*Timing
)
866 /* Check the parameters */
867 assert_param(IS_FSMC_PCCARD_DEVICE(Device
));
868 assert_param(IS_FSMC_SETUP_TIME(Timing
->SetupTime
));
869 assert_param(IS_FSMC_WAIT_TIME(Timing
->WaitSetupTime
));
870 assert_param(IS_FSMC_HOLD_TIME(Timing
->HoldSetupTime
));
871 assert_param(IS_FSMC_HIZ_TIME(Timing
->HiZSetupTime
));
873 /* Set FSMC_PCCARD device timing parameters */
874 MODIFY_REG(Device
->PIO4
, PIO4_CLEAR_MASK
, \
875 (Timing
->SetupTime
| \
876 (Timing
->WaitSetupTime
<< FSMC_PIO4_IOWAIT4_Pos
) | \
877 (Timing
->HoldSetupTime
<< FSMC_PIO4_IOHOLD4_Pos
) | \
878 (Timing
->HiZSetupTime
<< FSMC_PIO4_IOHIZ4_Pos
)));
884 * @brief DeInitializes the FSMC_PCCARD device
885 * @param Device: Pointer to PCCARD device instance
888 HAL_StatusTypeDef
FSMC_PCCARD_DeInit(FSMC_PCCARD_TypeDef
*Device
)
890 /* Check the parameters */
891 assert_param(IS_FSMC_PCCARD_DEVICE(Device
));
893 /* Disable the FSMC_PCCARD device */
894 __FSMC_PCCARD_DISABLE(Device
);
896 /* De-initialize the FSMC_PCCARD device */
897 WRITE_REG(Device
->PCR4
, 0x00000018U
);
898 WRITE_REG(Device
->SR4
, 0x00000040U
);
899 WRITE_REG(Device
->PMEM4
, 0xFCFCFCFCU
);
900 WRITE_REG(Device
->PATT4
, 0xFCFCFCFCU
);
901 WRITE_REG(Device
->PIO4
, 0xFCFCFCFCU
);
913 #endif /* STM32F101xE || STM32F103xE || STM32F101xG || STM32F103xG */
923 #endif /* HAL_SRAM_MODULE_ENABLED || HAL_NOR_MODULE_ENABLED || HAL_NAND_MODULE_ENABLED || HAL_PCCARD_MODULE_ENABLED */
925 #endif /* FSMC_BANK1 */
931 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/