You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

858 lines
29 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_ll_fsmc.c
  4. * @author MCD Application Team
  5. * @version V1.1.0
  6. * @date 19-June-2014
  7. * @brief FSMC Low Layer HAL module driver.
  8. *
  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
  14. *
  15. @verbatim
  16. ==============================================================================
  17. ##### FSMC peripheral features #####
  18. ==============================================================================
  19. [..] The Flexible static memory controller (FSMC) includes two memory controllers:
  20. (+) The NOR/PSRAM memory controller
  21. (+) The NAND/PC Card memory controller
  22. [..] The FSMC functional block makes the interface with synchronous and asynchronous static
  23. memories, SDRAM memories, and 16-bit PC memory cards. Its main purposes are:
  24. (+) to translate AHB transactions into the appropriate external device protocol.
  25. (+) to meet the access time requirements of the external memory devices.
  26. [..] All external memories share the addresses, data and control signals with the controller.
  27. Each external device is accessed by means of a unique Chip Select. The FSMC performs
  28. only one access at a time to an external device.
  29. The main features of the FSMC controller are the following:
  30. (+) Interface with static-memory mapped devices including:
  31. (++) Static random access memory (SRAM).
  32. (++) Read-only memory (ROM).
  33. (++) NOR Flash memory/OneNAND Flash memory.
  34. (++) PSRAM (4 memory banks).
  35. (++) 16-bit PC Card compatible devices.
  36. (++) Two banks of NAND Flash memory with ECC hardware to check up to 8 Kbytes of
  37. data.
  38. (+) Independent Chip Select control for each memory bank.
  39. (+) Independent configuration for each memory bank.
  40. @endverbatim
  41. ******************************************************************************
  42. * @attention
  43. *
  44. * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
  45. *
  46. * Redistribution and use in source and binary forms, with or without modification,
  47. * are permitted provided that the following conditions are met:
  48. * 1. Redistributions of source code must retain the above copyright notice,
  49. * this list of conditions and the following disclaimer.
  50. * 2. Redistributions in binary form must reproduce the above copyright notice,
  51. * this list of conditions and the following disclaimer in the documentation
  52. * and/or other materials provided with the distribution.
  53. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  54. * may be used to endorse or promote products derived from this software
  55. * without specific prior written permission.
  56. *
  57. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  58. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  59. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  60. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  61. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  62. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  63. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  64. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  65. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  66. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  67. *
  68. ******************************************************************************
  69. */
  70. /* Includes ------------------------------------------------------------------*/
  71. #include "stm32f4xx_hal.h"
  72. /** @addtogroup STM32F4xx_HAL_Driver
  73. * @{
  74. */
  75. /** @defgroup FSMC
  76. * @brief FSMC driver modules
  77. * @{
  78. */
  79. #if defined (HAL_SRAM_MODULE_ENABLED) || defined(HAL_NOR_MODULE_ENABLED) || defined(HAL_NAND_MODULE_ENABLED) || defined(HAL_PCCARD_MODULE_ENABLED)
  80. #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx)
  81. /* Private typedef -----------------------------------------------------------*/
  82. /* Private define ------------------------------------------------------------*/
  83. /* Private macro -------------------------------------------------------------*/
  84. /* Private variables ---------------------------------------------------------*/
  85. /* Private function prototypes -----------------------------------------------*/
  86. /* Private functions ---------------------------------------------------------*/
  87. /** @defgroup FSMC_Private_Functions
  88. * @{
  89. */
  90. /** @defgroup FSMC_NORSRAM Controller functions
  91. * @brief NORSRAM Controller functions
  92. *
  93. @verbatim
  94. ==============================================================================
  95. ##### How to use NORSRAM device driver #####
  96. ==============================================================================
  97. [..]
  98. This driver contains a set of APIs to interface with the FSMC NORSRAM banks in order
  99. to run the NORSRAM external devices.
  100. (+) FSMC NORSRAM bank reset using the function FSMC_NORSRAM_DeInit()
  101. (+) FSMC NORSRAM bank control configuration using the function FSMC_NORSRAM_Init()
  102. (+) FSMC NORSRAM bank timing configuration using the function FSMC_NORSRAM_Timing_Init()
  103. (+) FSMC NORSRAM bank extended timing configuration using the function
  104. FSMC_NORSRAM_Extended_Timing_Init()
  105. (+) FSMC NORSRAM bank enable/disable write operation using the functions
  106. FSMC_NORSRAM_WriteOperation_Enable()/FSMC_NORSRAM_WriteOperation_Disable()
  107. @endverbatim
  108. * @{
  109. */
  110. /** @defgroup HAL_FSMC_NORSRAM_Group1 Initialization/de-initialization functions
  111. * @brief Initialization and Configuration functions
  112. *
  113. @verbatim
  114. ==============================================================================
  115. ##### Initialization and de_initialization functions #####
  116. ==============================================================================
  117. [..]
  118. This section provides functions allowing to:
  119. (+) Initialize and configure the FSMC NORSRAM interface
  120. (+) De-initialize the FSMC NORSRAM interface
  121. (+) Configure the FSMC clock and associated GPIOs
  122. @endverbatim
  123. * @{
  124. */
  125. /**
  126. * @brief Initialize the FSMC_NORSRAM device according to the specified
  127. * control parameters in the FSMC_NORSRAM_InitTypeDef
  128. * @param Device: Pointer to NORSRAM device instance
  129. * @param Init: Pointer to NORSRAM Initialization structure
  130. * @retval HAL status
  131. */
  132. HAL_StatusTypeDef FSMC_NORSRAM_Init(FSMC_NORSRAM_TypeDef *Device, FSMC_NORSRAM_InitTypeDef* Init)
  133. {
  134. uint32_t tmpr = 0;
  135. /* Check the parameters */
  136. assert_param(IS_FSMC_NORSRAM_BANK(Init->NSBank));
  137. assert_param(IS_FSMC_MUX(Init->DataAddressMux));
  138. assert_param(IS_FSMC_MEMORY(Init->MemoryType));
  139. assert_param(IS_FSMC_NORSRAM_MEMORY_WIDTH(Init->MemoryDataWidth));
  140. assert_param(IS_FSMC_BURSTMODE(Init->BurstAccessMode));
  141. assert_param(IS_FSMC_WAIT_POLARITY(Init->WaitSignalPolarity));
  142. assert_param(IS_FSMC_WRAP_MODE(Init->WrapMode));
  143. assert_param(IS_FSMC_WAIT_SIGNAL_ACTIVE(Init->WaitSignalActive));
  144. assert_param(IS_FSMC_WRITE_OPERATION(Init->WriteOperation));
  145. assert_param(IS_FSMC_WAITE_SIGNAL(Init->WaitSignal));
  146. assert_param(IS_FSMC_EXTENDED_MODE(Init->ExtendedMode));
  147. assert_param(IS_FSMC_ASYNWAIT(Init->AsynchronousWait));
  148. assert_param(IS_FSMC_WRITE_BURST(Init->WriteBurst));
  149. /* Set NORSRAM device control parameters */
  150. tmpr = (uint32_t)(Init->DataAddressMux |\
  151. Init->MemoryType |\
  152. Init->MemoryDataWidth |\
  153. Init->BurstAccessMode |\
  154. Init->WaitSignalPolarity |\
  155. Init->WrapMode |\
  156. Init->WaitSignalActive |\
  157. Init->WriteOperation |\
  158. Init->WaitSignal |\
  159. Init->ExtendedMode |\
  160. Init->AsynchronousWait |\
  161. Init->WriteBurst
  162. );
  163. if(Init->MemoryType == FSMC_MEMORY_TYPE_NOR)
  164. {
  165. tmpr |= (uint32_t)FSMC_NORSRAM_FLASH_ACCESS_ENABLE;
  166. }
  167. Device->BTCR[Init->NSBank] = tmpr;
  168. return HAL_OK;
  169. }
  170. /**
  171. * @brief DeInitialize the FSMC_NORSRAM peripheral
  172. * @param Device: Pointer to NORSRAM device instance
  173. * @param ExDevice: Pointer to NORSRAM extended mode device instance
  174. * @param Bank: NORSRAM bank number
  175. * @retval HAL status
  176. */
  177. HAL_StatusTypeDef FSMC_NORSRAM_DeInit(FSMC_NORSRAM_TypeDef *Device, FSMC_NORSRAM_EXTENDED_TypeDef *ExDevice, uint32_t Bank)
  178. {
  179. /* Check the parameters */
  180. assert_param(IS_FSMC_NORSRAM_DEVICE(Device));
  181. assert_param(IS_FSMC_NORSRAM_EXTENDED_DEVICE(ExDevice));
  182. /* Disable the FSMC_NORSRAM device */
  183. __FSMC_NORSRAM_DISABLE(Device, Bank);
  184. /* De-initialize the FSMC_NORSRAM device */
  185. /* FSMC_NORSRAM_BANK1 */
  186. if(Bank == FSMC_NORSRAM_BANK1)
  187. {
  188. Device->BTCR[Bank] = 0x000030DB;
  189. }
  190. /* FSMC_NORSRAM_BANK2, FSMC_NORSRAM_BANK3 or FSMC_NORSRAM_BANK4 */
  191. else
  192. {
  193. Device->BTCR[Bank] = 0x000030D2;
  194. }
  195. Device->BTCR[Bank + 1] = 0x0FFFFFFF;
  196. ExDevice->BWTR[Bank] = 0x0FFFFFFF;
  197. return HAL_OK;
  198. }
  199. /**
  200. * @brief Initialize the FSMC_NORSRAM Timing according to the specified
  201. * parameters in the FSMC_NORSRAM_TimingTypeDef
  202. * @param Device: Pointer to NORSRAM device instance
  203. * @param Timing: Pointer to NORSRAM Timing structure
  204. * @param Bank: NORSRAM bank number
  205. * @retval HAL status
  206. */
  207. HAL_StatusTypeDef FSMC_NORSRAM_Timing_Init(FSMC_NORSRAM_TypeDef *Device, FSMC_NORSRAM_TimingTypeDef *Timing, uint32_t Bank)
  208. {
  209. uint32_t tmpr = 0;
  210. /* Check the parameters */
  211. assert_param(IS_FSMC_ADDRESS_SETUP_TIME(Timing->AddressSetupTime));
  212. assert_param(IS_FSMC_ADDRESS_HOLD_TIME(Timing->AddressHoldTime));
  213. assert_param(IS_FSMC_DATASETUP_TIME(Timing->DataSetupTime));
  214. assert_param(IS_FSMC_TURNAROUND_TIME(Timing->BusTurnAroundDuration));
  215. assert_param(IS_FSMC_CLK_DIV(Timing->CLKDivision));
  216. assert_param(IS_FSMC_DATA_LATENCY(Timing->DataLatency));
  217. assert_param(IS_FSMC_ACCESS_MODE(Timing->AccessMode));
  218. /* Set FSMC_NORSRAM device timing parameters */
  219. tmpr = (uint32_t)(Timing->AddressSetupTime |\
  220. ((Timing->AddressHoldTime) << 4) |\
  221. ((Timing->DataSetupTime) << 8) |\
  222. ((Timing->BusTurnAroundDuration) << 16) |\
  223. (((Timing->CLKDivision)-1) << 20) |\
  224. (((Timing->DataLatency)-2) << 24) |\
  225. (Timing->AccessMode)
  226. );
  227. Device->BTCR[Bank + 1] = tmpr;
  228. return HAL_OK;
  229. }
  230. /**
  231. * @brief Initialize the FSMC_NORSRAM Extended mode Timing according to the specified
  232. * parameters in the FSMC_NORSRAM_TimingTypeDef
  233. * @param Device: Pointer to NORSRAM device instance
  234. * @param Timing: Pointer to NORSRAM Timing structure
  235. * @param Bank: NORSRAM bank number
  236. * @retval HAL status
  237. */
  238. HAL_StatusTypeDef FSMC_NORSRAM_Extended_Timing_Init(FSMC_NORSRAM_EXTENDED_TypeDef *Device, FSMC_NORSRAM_TimingTypeDef *Timing, uint32_t Bank, uint32_t ExtendedMode)
  239. {
  240. /* Set NORSRAM device timing register for write configuration, if extended mode is used */
  241. if(ExtendedMode == FSMC_EXTENDED_MODE_ENABLE)
  242. {
  243. /* Check the parameters */
  244. assert_param(IS_FSMC_ADDRESS_SETUP_TIME(Timing->AddressSetupTime));
  245. assert_param(IS_FSMC_ADDRESS_HOLD_TIME(Timing->AddressHoldTime));
  246. assert_param(IS_FSMC_DATASETUP_TIME(Timing->DataSetupTime));
  247. assert_param(IS_FSMC_TURNAROUND_TIME(Timing->BusTurnAroundDuration));
  248. assert_param(IS_FSMC_CLK_DIV(Timing->CLKDivision));
  249. assert_param(IS_FSMC_DATA_LATENCY(Timing->DataLatency));
  250. assert_param(IS_FSMC_ACCESS_MODE(Timing->AccessMode));
  251. Device->BWTR[Bank] = (uint32_t)(Timing->AddressSetupTime |\
  252. ((Timing->AddressHoldTime) << 4) |\
  253. ((Timing->DataSetupTime) << 8) |\
  254. ((Timing->BusTurnAroundDuration) << 16) |\
  255. (((Timing->CLKDivision)-1) << 20) |\
  256. (((Timing->DataLatency)-2) << 24) |\
  257. (Timing->AccessMode));
  258. }
  259. else
  260. {
  261. Device->BWTR[Bank] = 0x0FFFFFFF;
  262. }
  263. return HAL_OK;
  264. }
  265. /**
  266. * @}
  267. */
  268. /** @defgroup HAL_FSMC_NORSRAM_Group3 Control functions
  269. * @brief management functions
  270. *
  271. @verbatim
  272. ==============================================================================
  273. ##### FSMC_NORSRAM Control functions #####
  274. ==============================================================================
  275. [..]
  276. This subsection provides a set of functions allowing to control dynamically
  277. the FSMC NORSRAM interface.
  278. @endverbatim
  279. * @{
  280. */
  281. /**
  282. * @brief Enables dynamically FSMC_NORSRAM write operation.
  283. * @param Device: Pointer to NORSRAM device instance
  284. * @param Bank: NORSRAM bank number
  285. * @retval HAL status
  286. */
  287. HAL_StatusTypeDef FSMC_NORSRAM_WriteOperation_Enable(FSMC_NORSRAM_TypeDef *Device, uint32_t Bank)
  288. {
  289. /* Enable write operation */
  290. Device->BTCR[Bank] |= FSMC_WRITE_OPERATION_ENABLE;
  291. return HAL_OK;
  292. }
  293. /**
  294. * @brief Disables dynamically FSMC_NORSRAM write operation.
  295. * @param Device: Pointer to NORSRAM device instance
  296. * @param Bank: NORSRAM bank number
  297. * @retval HAL status
  298. */
  299. HAL_StatusTypeDef FSMC_NORSRAM_WriteOperation_Disable(FSMC_NORSRAM_TypeDef *Device, uint32_t Bank)
  300. {
  301. /* Disable write operation */
  302. Device->BTCR[Bank] &= ~FSMC_WRITE_OPERATION_ENABLE;
  303. return HAL_OK;
  304. }
  305. /**
  306. * @}
  307. */
  308. /**
  309. * @}
  310. */
  311. /** @defgroup FSMC_PCCARD Controller functions
  312. * @brief PCCARD Controller functions
  313. *
  314. @verbatim
  315. ==============================================================================
  316. ##### How to use NAND device driver #####
  317. ==============================================================================
  318. [..]
  319. This driver contains a set of APIs to interface with the FSMC NAND banks in order
  320. to run the NAND external devices.
  321. (+) FSMC NAND bank reset using the function FSMC_NAND_DeInit()
  322. (+) FSMC NAND bank control configuration using the function FSMC_NAND_Init()
  323. (+) FSMC NAND bank common space timing configuration using the function
  324. FSMC_NAND_CommonSpace_Timing_Init()
  325. (+) FSMC NAND bank attribute space timing configuration using the function
  326. FSMC_NAND_AttributeSpace_Timing_Init()
  327. (+) FSMC NAND bank enable/disable ECC correction feature using the functions
  328. FSMC_NAND_ECC_Enable()/FSMC_NAND_ECC_Disable()
  329. (+) FSMC NAND bank get ECC correction code using the function FSMC_NAND_GetECC()
  330. @endverbatim
  331. * @{
  332. */
  333. /** @defgroup HAL_FSMC_NAND_Group1 Initialization/de-initialization functions
  334. * @brief Initialization and Configuration functions
  335. *
  336. @verbatim
  337. ==============================================================================
  338. ##### Initialization and de_initialization functions #####
  339. ==============================================================================
  340. [..]
  341. This section provides functions allowing to:
  342. (+) Initialize and configure the FSMC NAND interface
  343. (+) De-initialize the FSMC NAND interface
  344. (+) Configure the FSMC clock and associated GPIOs
  345. @endverbatim
  346. * @{
  347. */
  348. /**
  349. * @brief Initializes the FSMC_NAND device according to the specified
  350. * control parameters in the FSMC_NAND_HandleTypeDef
  351. * @param Device: Pointer to NAND device instance
  352. * @param Init: Pointer to NAND Initialization structure
  353. * @retval HAL status
  354. */
  355. HAL_StatusTypeDef FSMC_NAND_Init(FSMC_NAND_TypeDef *Device, FSMC_NAND_InitTypeDef *Init)
  356. {
  357. uint32_t tmppcr = 0;
  358. /* Check the parameters */
  359. assert_param(IS_FSMC_NAND_BANK(Init->NandBank));
  360. assert_param(IS_FSMC_WAIT_FEATURE(Init->Waitfeature));
  361. assert_param(IS_FSMC_NAND_MEMORY_WIDTH(Init->MemoryDataWidth));
  362. assert_param(IS_FSMC_ECC_STATE(Init->EccComputation));
  363. assert_param(IS_FSMC_ECCPAGE_SIZE(Init->ECCPageSize));
  364. assert_param(IS_FSMC_TCLR_TIME(Init->TCLRSetupTime));
  365. assert_param(IS_FSMC_TAR_TIME(Init->TARSetupTime));
  366. /* Set NAND device control parameters */
  367. tmppcr = (uint32_t)(Init->Waitfeature |\
  368. FSMC_PCR_MEMORY_TYPE_NAND |\
  369. Init->MemoryDataWidth |\
  370. Init->EccComputation |\
  371. Init->ECCPageSize |\
  372. ((Init->TCLRSetupTime) << 9) |\
  373. ((Init->TARSetupTime) << 13)
  374. );
  375. if(Init->NandBank == FSMC_NAND_BANK2)
  376. {
  377. /* NAND bank 2 registers configuration */
  378. Device->PCR2 = tmppcr;
  379. }
  380. else
  381. {
  382. /* NAND bank 3 registers configuration */
  383. Device->PCR3 = tmppcr;
  384. }
  385. return HAL_OK;
  386. }
  387. /**
  388. * @brief Initializes the FSMC_NAND Common space Timing according to the specified
  389. * parameters in the FSMC_NAND_PCC_TimingTypeDef
  390. * @param Device: Pointer to NAND device instance
  391. * @param Timing: Pointer to NAND timing structure
  392. * @param Bank: NAND bank number
  393. * @retval HAL status
  394. */
  395. HAL_StatusTypeDef FSMC_NAND_CommonSpace_Timing_Init(FSMC_NAND_TypeDef *Device, FSMC_NAND_PCC_TimingTypeDef *Timing, uint32_t Bank)
  396. {
  397. uint32_t tmppmem = 0;
  398. /* Check the parameters */
  399. assert_param(IS_FSMC_SETUP_TIME(Timing->SetupTime));
  400. assert_param(IS_FSMC_WAIT_TIME(Timing->WaitSetupTime));
  401. assert_param(IS_FSMC_HOLD_TIME(Timing->HoldSetupTime));
  402. assert_param(IS_FSMC_HIZ_TIME(Timing->HiZSetupTime));
  403. /* Set FSMC_NAND device timing parameters */
  404. tmppmem = (uint32_t)(Timing->SetupTime |\
  405. ((Timing->WaitSetupTime) << 8) |\
  406. ((Timing->HoldSetupTime) << 16) |\
  407. ((Timing->HiZSetupTime) << 24)
  408. );
  409. if(Bank == FSMC_NAND_BANK2)
  410. {
  411. /* NAND bank 2 registers configuration */
  412. Device->PMEM2 = tmppmem;
  413. }
  414. else
  415. {
  416. /* NAND bank 3 registers configuration */
  417. Device->PMEM3 = tmppmem;
  418. }
  419. return HAL_OK;
  420. }
  421. /**
  422. * @brief Initializes the FSMC_NAND Attribute space Timing according to the specified
  423. * parameters in the FSMC_NAND_PCC_TimingTypeDef
  424. * @param Device: Pointer to NAND device instance
  425. * @param Timing: Pointer to NAND timing structure
  426. * @param Bank: NAND bank number
  427. * @retval HAL status
  428. */
  429. HAL_StatusTypeDef FSMC_NAND_AttributeSpace_Timing_Init(FSMC_NAND_TypeDef *Device, FSMC_NAND_PCC_TimingTypeDef *Timing, uint32_t Bank)
  430. {
  431. uint32_t tmppatt = 0;
  432. /* Check the parameters */
  433. assert_param(IS_FSMC_SETUP_TIME(Timing->SetupTime));
  434. assert_param(IS_FSMC_WAIT_TIME(Timing->WaitSetupTime));
  435. assert_param(IS_FSMC_HOLD_TIME(Timing->HoldSetupTime));
  436. assert_param(IS_FSMC_HIZ_TIME(Timing->HiZSetupTime));
  437. /* Set FSMC_NAND device timing parameters */
  438. tmppatt = (uint32_t)(Timing->SetupTime |\
  439. ((Timing->WaitSetupTime) << 8) |\
  440. ((Timing->HoldSetupTime) << 16) |\
  441. ((Timing->HiZSetupTime) << 24)
  442. );
  443. if(Bank == FSMC_NAND_BANK2)
  444. {
  445. /* NAND bank 2 registers configuration */
  446. Device->PATT2 = tmppatt;
  447. }
  448. else
  449. {
  450. /* NAND bank 3 registers configuration */
  451. Device->PATT3 = tmppatt;
  452. }
  453. return HAL_OK;
  454. }
  455. /**
  456. * @brief DeInitializes the FSMC_NAND device
  457. * @param Device: Pointer to NAND device instance
  458. * @param Bank: NAND bank number
  459. * @retval HAL status
  460. */
  461. HAL_StatusTypeDef FSMC_NAND_DeInit(FSMC_NAND_TypeDef *Device, uint32_t Bank)
  462. {
  463. /* Disable the NAND Bank */
  464. __FSMC_NAND_DISABLE(Device, Bank);
  465. /* De-initialize the NAND Bank */
  466. if(Bank == FSMC_NAND_BANK2)
  467. {
  468. /* Set the FSMC_NAND_BANK2 registers to their reset values */
  469. Device->PCR2 = 0x00000018;
  470. Device->SR2 = 0x00000040;
  471. Device->PMEM2 = 0xFCFCFCFC;
  472. Device->PATT2 = 0xFCFCFCFC;
  473. }
  474. /* FSMC_Bank3_NAND */
  475. else
  476. {
  477. /* Set the FSMC_NAND_BANK3 registers to their reset values */
  478. Device->PCR3 = 0x00000018;
  479. Device->SR3 = 0x00000040;
  480. Device->PMEM3 = 0xFCFCFCFC;
  481. Device->PATT3 = 0xFCFCFCFC;
  482. }
  483. return HAL_OK;
  484. }
  485. /**
  486. * @}
  487. */
  488. /** @defgroup HAL_FSMC_NAND_Group3 Control functions
  489. * @brief management functions
  490. *
  491. @verbatim
  492. ==============================================================================
  493. ##### FSMC_NAND Control functions #####
  494. ==============================================================================
  495. [..]
  496. This subsection provides a set of functions allowing to control dynamically
  497. the FSMC NAND interface.
  498. @endverbatim
  499. * @{
  500. */
  501. /**
  502. * @brief Enables dynamically FSMC_NAND ECC feature.
  503. * @param Device: Pointer to NAND device instance
  504. * @param Bank: NAND bank number
  505. * @retval HAL status
  506. */
  507. HAL_StatusTypeDef FSMC_NAND_ECC_Enable(FSMC_NAND_TypeDef *Device, uint32_t Bank)
  508. {
  509. /* Enable ECC feature */
  510. if(Bank == FSMC_NAND_BANK2)
  511. {
  512. Device->PCR2 |= FSMC_PCR2_ECCEN;
  513. }
  514. else
  515. {
  516. Device->PCR3 |= FSMC_PCR3_ECCEN;
  517. }
  518. return HAL_OK;
  519. }
  520. /**
  521. * @brief Disables dynamically FSMC_NAND ECC feature.
  522. * @param Device: Pointer to NAND device instance
  523. * @param Bank: NAND bank number
  524. * @retval HAL status
  525. */
  526. HAL_StatusTypeDef FSMC_NAND_ECC_Disable(FSMC_NAND_TypeDef *Device, uint32_t Bank)
  527. {
  528. /* Disable ECC feature */
  529. if(Bank == FSMC_NAND_BANK2)
  530. {
  531. Device->PCR2 &= ~FSMC_PCR2_ECCEN;
  532. }
  533. else
  534. {
  535. Device->PCR3 &= ~FSMC_PCR3_ECCEN;
  536. }
  537. return HAL_OK;
  538. }
  539. /**
  540. * @brief Disables dynamically FSMC_NAND ECC feature.
  541. * @param Device: Pointer to NAND device instance
  542. * @param ECCval: Pointer to ECC value
  543. * @param Bank: NAND bank number
  544. * @param Timeout: Timeout wait value
  545. * @retval HAL status
  546. */
  547. HAL_StatusTypeDef FSMC_NAND_GetECC(FSMC_NAND_TypeDef *Device, uint32_t *ECCval, uint32_t Bank, uint32_t Timeout)
  548. {
  549. uint32_t tickstart = 0;
  550. /* Check the parameters */
  551. assert_param(IS_FSMC_NAND_DEVICE(Device));
  552. assert_param(IS_FSMC_NAND_BANK(Bank));
  553. /* Get tick */
  554. tickstart = HAL_GetTick();
  555. /* Wait untill FIFO is empty */
  556. while(__FSMC_NAND_GET_FLAG(Device, Bank, FSMC_FLAG_FEMPT))
  557. {
  558. /* Check for the Timeout */
  559. if(Timeout != HAL_MAX_DELAY)
  560. {
  561. if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
  562. {
  563. return HAL_TIMEOUT;
  564. }
  565. }
  566. }
  567. if(Bank == FSMC_NAND_BANK2)
  568. {
  569. /* Get the ECCR2 register value */
  570. *ECCval = (uint32_t)Device->ECCR2;
  571. }
  572. else
  573. {
  574. /* Get the ECCR3 register value */
  575. *ECCval = (uint32_t)Device->ECCR3;
  576. }
  577. return HAL_OK;
  578. }
  579. /**
  580. * @}
  581. */
  582. /**
  583. * @}
  584. */
  585. /** @defgroup FSMC_PCCARD Controller functions
  586. * @brief PCCARD Controller functions
  587. *
  588. @verbatim
  589. ==============================================================================
  590. ##### How to use PCCARD device driver #####
  591. ==============================================================================
  592. [..]
  593. This driver contains a set of APIs to interface with the FSMC PCCARD bank in order
  594. to run the PCCARD/compact flash external devices.
  595. (+) FSMC PCCARD bank reset using the function FSMC_PCCARD_DeInit()
  596. (+) FSMC PCCARD bank control configuration using the function FSMC_PCCARD_Init()
  597. (+) FSMC PCCARD bank common space timing configuration using the function
  598. FSMC_PCCARD_CommonSpace_Timing_Init()
  599. (+) FSMC PCCARD bank attribute space timing configuration using the function
  600. FSMC_PCCARD_AttributeSpace_Timing_Init()
  601. (+) FSMC PCCARD bank IO space timing configuration using the function
  602. FSMC_PCCARD_IOSpace_Timing_Init()
  603. @endverbatim
  604. * @{
  605. */
  606. /** @defgroup HAL_FSMC_PCCARD_Group1 Initialization/de-initialization functions
  607. * @brief Initialization and Configuration functions
  608. *
  609. @verbatim
  610. ==============================================================================
  611. ##### Initialization and de_initialization functions #####
  612. ==============================================================================
  613. [..]
  614. This section provides functions allowing to:
  615. (+) Initialize and configure the FSMC PCCARD interface
  616. (+) De-initialize the FSMC PCCARD interface
  617. (+) Configure the FSMC clock and associated GPIOs
  618. @endverbatim
  619. * @{
  620. */
  621. /**
  622. * @brief Initializes the FSMC_PCCARD device according to the specified
  623. * control parameters in the FSMC_PCCARD_HandleTypeDef
  624. * @param Device: Pointer to PCCARD device instance
  625. * @param Init: Pointer to PCCARD Initialization structure
  626. * @retval HAL status
  627. */
  628. HAL_StatusTypeDef FSMC_PCCARD_Init(FSMC_PCCARD_TypeDef *Device, FSMC_PCCARD_InitTypeDef *Init)
  629. {
  630. /* Check the parameters */
  631. assert_param(IS_FSMC_WAIT_FEATURE(Init->Waitfeature));
  632. assert_param(IS_FSMC_TCLR_TIME(Init->TCLRSetupTime));
  633. assert_param(IS_FSMC_TAR_TIME(Init->TARSetupTime));
  634. /* Set FSMC_PCCARD device control parameters */
  635. Device->PCR4 = (uint32_t)(Init->Waitfeature |\
  636. FSMC_NAND_PCC_MEM_BUS_WIDTH_16 |\
  637. (Init->TCLRSetupTime << 9) |\
  638. (Init->TARSetupTime << 13));
  639. return HAL_OK;
  640. }
  641. /**
  642. * @brief Initializes the FSMC_PCCARD Common space Timing according to the specified
  643. * parameters in the FSMC_NAND_PCC_TimingTypeDef
  644. * @param Device: Pointer to PCCARD device instance
  645. * @param Timing: Pointer to PCCARD timing structure
  646. * @retval HAL status
  647. */
  648. HAL_StatusTypeDef FSMC_PCCARD_CommonSpace_Timing_Init(FSMC_PCCARD_TypeDef *Device, FSMC_NAND_PCC_TimingTypeDef *Timing)
  649. {
  650. /* Check the parameters */
  651. assert_param(IS_FSMC_SETUP_TIME(Timing->SetupTime));
  652. assert_param(IS_FSMC_WAIT_TIME(Timing->WaitSetupTime));
  653. assert_param(IS_FSMC_HOLD_TIME(Timing->HoldSetupTime));
  654. assert_param(IS_FSMC_HIZ_TIME(Timing->HiZSetupTime));
  655. /* Set PCCARD timing parameters */
  656. Device->PMEM4 = (uint32_t)((Timing->SetupTime |\
  657. ((Timing->WaitSetupTime) << 8) |\
  658. (Timing->HoldSetupTime) << 16) |\
  659. ((Timing->HiZSetupTime) << 24)
  660. );
  661. return HAL_OK;
  662. }
  663. /**
  664. * @brief Initializes the FSMC_PCCARD Attribute space Timing according to the specified
  665. * parameters in the FSMC_NAND_PCC_TimingTypeDef
  666. * @param Device: Pointer to PCCARD device instance
  667. * @param Timing: Pointer to PCCARD timing structure
  668. * @retval HAL status
  669. */
  670. HAL_StatusTypeDef FSMC_PCCARD_AttributeSpace_Timing_Init(FSMC_PCCARD_TypeDef *Device, FSMC_NAND_PCC_TimingTypeDef *Timing)
  671. {
  672. /* Check the parameters */
  673. assert_param(IS_FSMC_SETUP_TIME(Timing->SetupTime));
  674. assert_param(IS_FSMC_WAIT_TIME(Timing->WaitSetupTime));
  675. assert_param(IS_FSMC_HOLD_TIME(Timing->HoldSetupTime));
  676. assert_param(IS_FSMC_HIZ_TIME(Timing->HiZSetupTime));
  677. /* Set PCCARD timing parameters */
  678. Device->PATT4 = (uint32_t)((Timing->SetupTime |\
  679. ((Timing->WaitSetupTime) << 8) |\
  680. (Timing->HoldSetupTime) << 16) |\
  681. ((Timing->HiZSetupTime) << 24)
  682. );
  683. return HAL_OK;
  684. }
  685. /**
  686. * @brief Initializes the FSMC_PCCARD IO space Timing according to the specified
  687. * parameters in the FSMC_NAND_PCC_TimingTypeDef
  688. * @param Device: Pointer to PCCARD device instance
  689. * @param Timing: Pointer to PCCARD timing structure
  690. * @retval HAL status
  691. */
  692. HAL_StatusTypeDef FSMC_PCCARD_IOSpace_Timing_Init(FSMC_PCCARD_TypeDef *Device, FSMC_NAND_PCC_TimingTypeDef *Timing)
  693. {
  694. /* Check the parameters */
  695. assert_param(IS_FSMC_SETUP_TIME(Timing->SetupTime));
  696. assert_param(IS_FSMC_WAIT_TIME(Timing->WaitSetupTime));
  697. assert_param(IS_FSMC_HOLD_TIME(Timing->HoldSetupTime));
  698. assert_param(IS_FSMC_HIZ_TIME(Timing->HiZSetupTime));
  699. /* Set FSMC_PCCARD device timing parameters */
  700. Device->PIO4 = (uint32_t)((Timing->SetupTime |\
  701. ((Timing->WaitSetupTime) << 8) |\
  702. (Timing->HoldSetupTime) << 16) |\
  703. ((Timing->HiZSetupTime) << 24)
  704. );
  705. return HAL_OK;
  706. }
  707. /**
  708. * @brief DeInitializes the FSMC_PCCARD device
  709. * @param Device: Pointer to PCCARD device instance
  710. * @retval HAL status
  711. */
  712. HAL_StatusTypeDef FSMC_PCCARD_DeInit(FSMC_PCCARD_TypeDef *Device)
  713. {
  714. /* Disable the FSMC_PCCARD device */
  715. __FSMC_PCCARD_DISABLE(Device);
  716. /* De-initialize the FSMC_PCCARD device */
  717. Device->PCR4 = 0x00000018;
  718. Device->SR4 = 0x00000000;
  719. Device->PMEM4 = 0xFCFCFCFC;
  720. Device->PATT4 = 0xFCFCFCFC;
  721. Device->PIO4 = 0xFCFCFCFC;
  722. return HAL_OK;
  723. }
  724. /**
  725. * @}
  726. */
  727. /**
  728. * @}
  729. */
  730. #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx */
  731. #endif /* HAL_FSMC_MODULE_ENABLED */
  732. /**
  733. * @}
  734. */
  735. /**
  736. * @}
  737. */
  738. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/