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.
 
 
 

1118 lines
39 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_ll_fmc.c
  4. * @author MCD Application Team
  5. * @version V1.2.2
  6. * @date 14-April-2017
  7. * @brief FMC Low Layer HAL module driver.
  8. *
  9. * This file provides firmware functions to manage the following
  10. * functionalities of the Flexible Memory Controller (FMC) peripheral memories:
  11. * + Initialization/de-initialization functions
  12. * + Peripheral Control functions
  13. * + Peripheral State functions
  14. *
  15. @verbatim
  16. ==============================================================================
  17. ##### FMC peripheral features #####
  18. ==============================================================================
  19. [..] The Flexible memory controller (FMC) includes three memory controllers:
  20. (+) The NOR/PSRAM memory controller
  21. (+) The NAND memory controller
  22. (+) The Synchronous DRAM (SDRAM) controller
  23. [..] The FMC functional block makes the interface with synchronous and asynchronous static
  24. memories, SDRAM memories, and 16-bit PC memory cards. Its main purposes are:
  25. (+) to translate AHB transactions into the appropriate external device protocol
  26. (+) to meet the access time requirements of the external memory devices
  27. [..] All external memories share the addresses, data and control signals with the controller.
  28. Each external device is accessed by means of a unique Chip Select. The FMC performs
  29. only one access at a time to an external device.
  30. The main features of the FMC controller are the following:
  31. (+) Interface with static-memory mapped devices including:
  32. (++) Static random access memory (SRAM)
  33. (++) Read-only memory (ROM)
  34. (++) NOR Flash memory/OneNAND Flash memory
  35. (++) PSRAM (4 memory banks)
  36. (++) 16-bit PC Card compatible devices
  37. (++) Two banks of NAND Flash memory with ECC hardware to check up to 8 Kbytes of
  38. data
  39. (+) Interface with synchronous DRAM (SDRAM) memories
  40. (+) Independent Chip Select control for each memory bank
  41. (+) Independent configuration for each memory bank
  42. @endverbatim
  43. ******************************************************************************
  44. * @attention
  45. *
  46. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  47. *
  48. * Redistribution and use in source and binary forms, with or without modification,
  49. * are permitted provided that the following conditions are met:
  50. * 1. Redistributions of source code must retain the above copyright notice,
  51. * this list of conditions and the following disclaimer.
  52. * 2. Redistributions in binary form must reproduce the above copyright notice,
  53. * this list of conditions and the following disclaimer in the documentation
  54. * and/or other materials provided with the distribution.
  55. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  56. * may be used to endorse or promote products derived from this software
  57. * without specific prior written permission.
  58. *
  59. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  60. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  61. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  62. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  63. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  64. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  65. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  66. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  67. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  68. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  69. *
  70. ******************************************************************************
  71. */
  72. /* Includes ------------------------------------------------------------------*/
  73. #include "stm32f7xx_hal.h"
  74. /** @addtogroup STM32F7xx_HAL_Driver
  75. * @{
  76. */
  77. /** @defgroup FMC_LL FMC Low Layer
  78. * @brief FMC driver modules
  79. * @{
  80. */
  81. #if defined (HAL_SRAM_MODULE_ENABLED) || defined(HAL_NOR_MODULE_ENABLED) || defined(HAL_NAND_MODULE_ENABLED) || defined(HAL_SDRAM_MODULE_ENABLED)
  82. /* Private typedef -----------------------------------------------------------*/
  83. /* Private define ------------------------------------------------------------*/
  84. /* Private macro -------------------------------------------------------------*/
  85. /* Private variables ---------------------------------------------------------*/
  86. /* Private function prototypes -----------------------------------------------*/
  87. /* Exported functions --------------------------------------------------------*/
  88. /** @defgroup FMC_LL_Exported_Functions FMC Low Layer Exported Functions
  89. * @{
  90. */
  91. /** @defgroup FMC_LL_Exported_Functions_NORSRAM FMC Low Layer NOR SRAM Exported Functions
  92. * @brief NORSRAM Controller functions
  93. *
  94. @verbatim
  95. ==============================================================================
  96. ##### How to use NORSRAM device driver #####
  97. ==============================================================================
  98. [..]
  99. This driver contains a set of APIs to interface with the FMC NORSRAM banks in order
  100. to run the NORSRAM external devices.
  101. (+) FMC NORSRAM bank reset using the function FMC_NORSRAM_DeInit()
  102. (+) FMC NORSRAM bank control configuration using the function FMC_NORSRAM_Init()
  103. (+) FMC NORSRAM bank timing configuration using the function FMC_NORSRAM_Timing_Init()
  104. (+) FMC NORSRAM bank extended timing configuration using the function
  105. FMC_NORSRAM_Extended_Timing_Init()
  106. (+) FMC NORSRAM bank enable/disable write operation using the functions
  107. FMC_NORSRAM_WriteOperation_Enable()/FMC_NORSRAM_WriteOperation_Disable()
  108. @endverbatim
  109. * @{
  110. */
  111. /** @defgroup FMC_LL_NORSRAM_Exported_Functions_Group1 Initialization and de-initialization functions
  112. * @brief Initialization and Configuration functions
  113. *
  114. @verbatim
  115. ==============================================================================
  116. ##### Initialization and de_initialization functions #####
  117. ==============================================================================
  118. [..]
  119. This section provides functions allowing to:
  120. (+) Initialize and configure the FMC NORSRAM interface
  121. (+) De-initialize the FMC NORSRAM interface
  122. (+) Configure the FMC clock and associated GPIOs
  123. @endverbatim
  124. * @{
  125. */
  126. /**
  127. * @brief Initialize the FMC_NORSRAM device according to the specified
  128. * control parameters in the FMC_NORSRAM_InitTypeDef
  129. * @param Device: Pointer to NORSRAM device instance
  130. * @param Init: Pointer to NORSRAM Initialization structure
  131. * @retval HAL status
  132. */
  133. HAL_StatusTypeDef FMC_NORSRAM_Init(FMC_NORSRAM_TypeDef *Device, FMC_NORSRAM_InitTypeDef* Init)
  134. {
  135. uint32_t tmpr = 0;
  136. /* Check the parameters */
  137. assert_param(IS_FMC_NORSRAM_DEVICE(Device));
  138. assert_param(IS_FMC_NORSRAM_BANK(Init->NSBank));
  139. assert_param(IS_FMC_MUX(Init->DataAddressMux));
  140. assert_param(IS_FMC_MEMORY(Init->MemoryType));
  141. assert_param(IS_FMC_NORSRAM_MEMORY_WIDTH(Init->MemoryDataWidth));
  142. assert_param(IS_FMC_BURSTMODE(Init->BurstAccessMode));
  143. assert_param(IS_FMC_WAIT_POLARITY(Init->WaitSignalPolarity));
  144. assert_param(IS_FMC_WAIT_SIGNAL_ACTIVE(Init->WaitSignalActive));
  145. assert_param(IS_FMC_WRITE_OPERATION(Init->WriteOperation));
  146. assert_param(IS_FMC_WAITE_SIGNAL(Init->WaitSignal));
  147. assert_param(IS_FMC_EXTENDED_MODE(Init->ExtendedMode));
  148. assert_param(IS_FMC_ASYNWAIT(Init->AsynchronousWait));
  149. assert_param(IS_FMC_WRITE_BURST(Init->WriteBurst));
  150. assert_param(IS_FMC_CONTINOUS_CLOCK(Init->ContinuousClock));
  151. assert_param(IS_FMC_WRITE_FIFO(Init->WriteFifo));
  152. assert_param(IS_FMC_PAGESIZE(Init->PageSize));
  153. /* Get the BTCR register value */
  154. tmpr = Device->BTCR[Init->NSBank];
  155. /* Clear MBKEN, MUXEN, MTYP, MWID, FACCEN, BURSTEN, WAITPOL, WAITCFG, WREN,
  156. WAITEN, EXTMOD, ASYNCWAIT, CBURSTRW and CCLKEN bits */
  157. tmpr &= ((uint32_t)~(FMC_BCR1_MBKEN | FMC_BCR1_MUXEN | FMC_BCR1_MTYP | \
  158. FMC_BCR1_MWID | FMC_BCR1_FACCEN | FMC_BCR1_BURSTEN | \
  159. FMC_BCR1_WAITPOL | FMC_BCR1_CPSIZE | FMC_BCR1_WAITCFG | \
  160. FMC_BCR1_WREN | FMC_BCR1_WAITEN | FMC_BCR1_EXTMOD | \
  161. FMC_BCR1_ASYNCWAIT | FMC_BCR1_CBURSTRW | FMC_BCR1_CCLKEN | FMC_BCR1_WFDIS));
  162. /* Set NORSRAM device control parameters */
  163. tmpr |= (uint32_t)(Init->DataAddressMux |\
  164. Init->MemoryType |\
  165. Init->MemoryDataWidth |\
  166. Init->BurstAccessMode |\
  167. Init->WaitSignalPolarity |\
  168. Init->WaitSignalActive |\
  169. Init->WriteOperation |\
  170. Init->WaitSignal |\
  171. Init->ExtendedMode |\
  172. Init->AsynchronousWait |\
  173. Init->WriteBurst |\
  174. Init->ContinuousClock |\
  175. Init->PageSize |\
  176. Init->WriteFifo);
  177. if(Init->MemoryType == FMC_MEMORY_TYPE_NOR)
  178. {
  179. tmpr |= (uint32_t)FMC_NORSRAM_FLASH_ACCESS_ENABLE;
  180. }
  181. Device->BTCR[Init->NSBank] = tmpr;
  182. /* Configure synchronous mode when Continuous clock is enabled for bank2..4 */
  183. if((Init->ContinuousClock == FMC_CONTINUOUS_CLOCK_SYNC_ASYNC) && (Init->NSBank != FMC_NORSRAM_BANK1))
  184. {
  185. Device->BTCR[FMC_NORSRAM_BANK1] |= (uint32_t)(Init->ContinuousClock);
  186. }
  187. if(Init->NSBank != FMC_NORSRAM_BANK1)
  188. {
  189. Device->BTCR[FMC_NORSRAM_BANK1] |= (uint32_t)(Init->WriteFifo);
  190. }
  191. return HAL_OK;
  192. }
  193. /**
  194. * @brief DeInitialize the FMC_NORSRAM peripheral
  195. * @param Device: Pointer to NORSRAM device instance
  196. * @param ExDevice: Pointer to NORSRAM extended mode device instance
  197. * @param Bank: NORSRAM bank number
  198. * @retval HAL status
  199. */
  200. HAL_StatusTypeDef FMC_NORSRAM_DeInit(FMC_NORSRAM_TypeDef *Device, FMC_NORSRAM_EXTENDED_TypeDef *ExDevice, uint32_t Bank)
  201. {
  202. /* Check the parameters */
  203. assert_param(IS_FMC_NORSRAM_DEVICE(Device));
  204. assert_param(IS_FMC_NORSRAM_EXTENDED_DEVICE(ExDevice));
  205. assert_param(IS_FMC_NORSRAM_BANK(Bank));
  206. /* Disable the FMC_NORSRAM device */
  207. __FMC_NORSRAM_DISABLE(Device, Bank);
  208. /* De-initialize the FMC_NORSRAM device */
  209. /* FMC_NORSRAM_BANK1 */
  210. if(Bank == FMC_NORSRAM_BANK1)
  211. {
  212. Device->BTCR[Bank] = 0x000030DB;
  213. }
  214. /* FMC_NORSRAM_BANK2, FMC_NORSRAM_BANK3 or FMC_NORSRAM_BANK4 */
  215. else
  216. {
  217. Device->BTCR[Bank] = 0x000030D2;
  218. }
  219. Device->BTCR[Bank + 1] = 0x0FFFFFFF;
  220. ExDevice->BWTR[Bank] = 0x0FFFFFFF;
  221. return HAL_OK;
  222. }
  223. /**
  224. * @brief Initialize the FMC_NORSRAM Timing according to the specified
  225. * parameters in the FMC_NORSRAM_TimingTypeDef
  226. * @param Device: Pointer to NORSRAM device instance
  227. * @param Timing: Pointer to NORSRAM Timing structure
  228. * @param Bank: NORSRAM bank number
  229. * @retval HAL status
  230. */
  231. HAL_StatusTypeDef FMC_NORSRAM_Timing_Init(FMC_NORSRAM_TypeDef *Device, FMC_NORSRAM_TimingTypeDef *Timing, uint32_t Bank)
  232. {
  233. uint32_t tmpr = 0;
  234. /* Check the parameters */
  235. assert_param(IS_FMC_NORSRAM_DEVICE(Device));
  236. assert_param(IS_FMC_ADDRESS_SETUP_TIME(Timing->AddressSetupTime));
  237. assert_param(IS_FMC_ADDRESS_HOLD_TIME(Timing->AddressHoldTime));
  238. assert_param(IS_FMC_DATASETUP_TIME(Timing->DataSetupTime));
  239. assert_param(IS_FMC_TURNAROUND_TIME(Timing->BusTurnAroundDuration));
  240. assert_param(IS_FMC_CLK_DIV(Timing->CLKDivision));
  241. assert_param(IS_FMC_DATA_LATENCY(Timing->DataLatency));
  242. assert_param(IS_FMC_ACCESS_MODE(Timing->AccessMode));
  243. assert_param(IS_FMC_NORSRAM_BANK(Bank));
  244. /* Get the BTCR register value */
  245. tmpr = Device->BTCR[Bank + 1];
  246. /* Clear ADDSET, ADDHLD, DATAST, BUSTURN, CLKDIV, DATLAT and ACCMOD bits */
  247. tmpr &= ((uint32_t)~(FMC_BTR1_ADDSET | FMC_BTR1_ADDHLD | FMC_BTR1_DATAST | \
  248. FMC_BTR1_BUSTURN | FMC_BTR1_CLKDIV | FMC_BTR1_DATLAT | \
  249. FMC_BTR1_ACCMOD));
  250. /* Set FMC_NORSRAM device timing parameters */
  251. tmpr |= (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. Device->BTCR[Bank + 1] = tmpr;
  260. /* Configure Clock division value (in NORSRAM bank 1) when continuous clock is enabled */
  261. if(HAL_IS_BIT_SET(Device->BTCR[FMC_NORSRAM_BANK1], FMC_BCR1_CCLKEN))
  262. {
  263. tmpr = (uint32_t)(Device->BTCR[FMC_NORSRAM_BANK1 + 1] & ~(((uint32_t)0x0F) << 20));
  264. tmpr |= (uint32_t)(((Timing->CLKDivision)-1) << 20);
  265. Device->BTCR[FMC_NORSRAM_BANK1 + 1] = tmpr;
  266. }
  267. return HAL_OK;
  268. }
  269. /**
  270. * @brief Initialize the FMC_NORSRAM Extended mode Timing according to the specified
  271. * parameters in the FMC_NORSRAM_TimingTypeDef
  272. * @param Device: Pointer to NORSRAM device instance
  273. * @param Timing: Pointer to NORSRAM Timing structure
  274. * @param Bank: NORSRAM bank number
  275. * @retval HAL status
  276. */
  277. HAL_StatusTypeDef FMC_NORSRAM_Extended_Timing_Init(FMC_NORSRAM_EXTENDED_TypeDef *Device, FMC_NORSRAM_TimingTypeDef *Timing, uint32_t Bank, uint32_t ExtendedMode)
  278. {
  279. uint32_t tmpr = 0;
  280. /* Check the parameters */
  281. assert_param(IS_FMC_EXTENDED_MODE(ExtendedMode));
  282. /* Set NORSRAM device timing register for write configuration, if extended mode is used */
  283. if(ExtendedMode == FMC_EXTENDED_MODE_ENABLE)
  284. {
  285. /* Check the parameters */
  286. assert_param(IS_FMC_NORSRAM_EXTENDED_DEVICE(Device));
  287. assert_param(IS_FMC_ADDRESS_SETUP_TIME(Timing->AddressSetupTime));
  288. assert_param(IS_FMC_ADDRESS_HOLD_TIME(Timing->AddressHoldTime));
  289. assert_param(IS_FMC_DATASETUP_TIME(Timing->DataSetupTime));
  290. assert_param(IS_FMC_TURNAROUND_TIME(Timing->BusTurnAroundDuration));
  291. assert_param(IS_FMC_CLK_DIV(Timing->CLKDivision));
  292. assert_param(IS_FMC_DATA_LATENCY(Timing->DataLatency));
  293. assert_param(IS_FMC_ACCESS_MODE(Timing->AccessMode));
  294. assert_param(IS_FMC_NORSRAM_BANK(Bank));
  295. /* Get the BWTR register value */
  296. tmpr = Device->BWTR[Bank];
  297. /* Clear ADDSET, ADDHLD, DATAST, BUSTURN, CLKDIV, DATLAT and ACCMOD bits */
  298. tmpr &= ((uint32_t)~(FMC_BWTR1_ADDSET | FMC_BWTR1_ADDHLD | FMC_BWTR1_DATAST | \
  299. FMC_BWTR1_BUSTURN | FMC_BWTR1_ACCMOD));
  300. tmpr |= (uint32_t)(Timing->AddressSetupTime |\
  301. ((Timing->AddressHoldTime) << 4) |\
  302. ((Timing->DataSetupTime) << 8) |\
  303. ((Timing->BusTurnAroundDuration) << 16) |\
  304. (Timing->AccessMode));
  305. Device->BWTR[Bank] = tmpr;
  306. }
  307. else
  308. {
  309. Device->BWTR[Bank] = 0x0FFFFFFF;
  310. }
  311. return HAL_OK;
  312. }
  313. /**
  314. * @}
  315. */
  316. /** @addtogroup FMC_LL_NORSRAM_Private_Functions_Group2
  317. * @brief management functions
  318. *
  319. @verbatim
  320. ==============================================================================
  321. ##### FMC_NORSRAM Control functions #####
  322. ==============================================================================
  323. [..]
  324. This subsection provides a set of functions allowing to control dynamically
  325. the FMC NORSRAM interface.
  326. @endverbatim
  327. * @{
  328. */
  329. /**
  330. * @brief Enables dynamically FMC_NORSRAM write operation.
  331. * @param Device: Pointer to NORSRAM device instance
  332. * @param Bank: NORSRAM bank number
  333. * @retval HAL status
  334. */
  335. HAL_StatusTypeDef FMC_NORSRAM_WriteOperation_Enable(FMC_NORSRAM_TypeDef *Device, uint32_t Bank)
  336. {
  337. /* Check the parameters */
  338. assert_param(IS_FMC_NORSRAM_DEVICE(Device));
  339. assert_param(IS_FMC_NORSRAM_BANK(Bank));
  340. /* Enable write operation */
  341. Device->BTCR[Bank] |= FMC_WRITE_OPERATION_ENABLE;
  342. return HAL_OK;
  343. }
  344. /**
  345. * @brief Disables dynamically FMC_NORSRAM write operation.
  346. * @param Device: Pointer to NORSRAM device instance
  347. * @param Bank: NORSRAM bank number
  348. * @retval HAL status
  349. */
  350. HAL_StatusTypeDef FMC_NORSRAM_WriteOperation_Disable(FMC_NORSRAM_TypeDef *Device, uint32_t Bank)
  351. {
  352. /* Check the parameters */
  353. assert_param(IS_FMC_NORSRAM_DEVICE(Device));
  354. assert_param(IS_FMC_NORSRAM_BANK(Bank));
  355. /* Disable write operation */
  356. Device->BTCR[Bank] &= ~FMC_WRITE_OPERATION_ENABLE;
  357. return HAL_OK;
  358. }
  359. /**
  360. * @}
  361. */
  362. /**
  363. * @}
  364. */
  365. /** @defgroup FMC_LL_Exported_Functions_NAND FMC Low Layer NAND Exported Functions
  366. * @brief NAND Controller functions
  367. *
  368. @verbatim
  369. ==============================================================================
  370. ##### How to use NAND device driver #####
  371. ==============================================================================
  372. [..]
  373. This driver contains a set of APIs to interface with the FMC NAND banks in order
  374. to run the NAND external devices.
  375. (+) FMC NAND bank reset using the function FMC_NAND_DeInit()
  376. (+) FMC NAND bank control configuration using the function FMC_NAND_Init()
  377. (+) FMC NAND bank common space timing configuration using the function
  378. FMC_NAND_CommonSpace_Timing_Init()
  379. (+) FMC NAND bank attribute space timing configuration using the function
  380. FMC_NAND_AttributeSpace_Timing_Init()
  381. (+) FMC NAND bank enable/disable ECC correction feature using the functions
  382. FMC_NAND_ECC_Enable()/FMC_NAND_ECC_Disable()
  383. (+) FMC NAND bank get ECC correction code using the function FMC_NAND_GetECC()
  384. @endverbatim
  385. * @{
  386. */
  387. /** @defgroup FMC_LL_NAND_Exported_Functions_Group1 Initialization and de-initialization functions
  388. * @brief Initialization and Configuration functions
  389. *
  390. @verbatim
  391. ==============================================================================
  392. ##### Initialization and de_initialization functions #####
  393. ==============================================================================
  394. [..]
  395. This section provides functions allowing to:
  396. (+) Initialize and configure the FMC NAND interface
  397. (+) De-initialize the FMC NAND interface
  398. (+) Configure the FMC clock and associated GPIOs
  399. @endverbatim
  400. * @{
  401. */
  402. /**
  403. * @brief Initializes the FMC_NAND device according to the specified
  404. * control parameters in the FMC_NAND_HandleTypeDef
  405. * @param Device: Pointer to NAND device instance
  406. * @param Init: Pointer to NAND Initialization structure
  407. * @retval HAL status
  408. */
  409. HAL_StatusTypeDef FMC_NAND_Init(FMC_NAND_TypeDef *Device, FMC_NAND_InitTypeDef *Init)
  410. {
  411. uint32_t tmpr = 0;
  412. /* Check the parameters */
  413. assert_param(IS_FMC_NAND_DEVICE(Device));
  414. assert_param(IS_FMC_NAND_BANK(Init->NandBank));
  415. assert_param(IS_FMC_WAIT_FEATURE(Init->Waitfeature));
  416. assert_param(IS_FMC_NAND_MEMORY_WIDTH(Init->MemoryDataWidth));
  417. assert_param(IS_FMC_ECC_STATE(Init->EccComputation));
  418. assert_param(IS_FMC_ECCPAGE_SIZE(Init->ECCPageSize));
  419. assert_param(IS_FMC_TCLR_TIME(Init->TCLRSetupTime));
  420. assert_param(IS_FMC_TAR_TIME(Init->TARSetupTime));
  421. /* Get the NAND bank 3 register value */
  422. tmpr = Device->PCR;
  423. /* Clear PWAITEN, PBKEN, PTYP, PWID, ECCEN, TCLR, TAR and ECCPS bits */
  424. tmpr &= ((uint32_t)~(FMC_PCR_PWAITEN | FMC_PCR_PBKEN | FMC_PCR_PTYP | \
  425. FMC_PCR_PWID | FMC_PCR_ECCEN | FMC_PCR_TCLR | \
  426. FMC_PCR_TAR | FMC_PCR_ECCPS));
  427. /* Set NAND device control parameters */
  428. tmpr |= (uint32_t)(Init->Waitfeature |\
  429. FMC_PCR_MEMORY_TYPE_NAND |\
  430. Init->MemoryDataWidth |\
  431. Init->EccComputation |\
  432. Init->ECCPageSize |\
  433. ((Init->TCLRSetupTime) << 9) |\
  434. ((Init->TARSetupTime) << 13));
  435. /* NAND bank 3 registers configuration */
  436. Device->PCR = tmpr;
  437. return HAL_OK;
  438. }
  439. /**
  440. * @brief Initializes the FMC_NAND Common space Timing according to the specified
  441. * parameters in the FMC_NAND_PCC_TimingTypeDef
  442. * @param Device: Pointer to NAND device instance
  443. * @param Timing: Pointer to NAND timing structure
  444. * @param Bank: NAND bank number
  445. * @retval HAL status
  446. */
  447. HAL_StatusTypeDef FMC_NAND_CommonSpace_Timing_Init(FMC_NAND_TypeDef *Device, FMC_NAND_PCC_TimingTypeDef *Timing, uint32_t Bank)
  448. {
  449. uint32_t tmpr = 0;
  450. /* Check the parameters */
  451. assert_param(IS_FMC_NAND_DEVICE(Device));
  452. assert_param(IS_FMC_SETUP_TIME(Timing->SetupTime));
  453. assert_param(IS_FMC_WAIT_TIME(Timing->WaitSetupTime));
  454. assert_param(IS_FMC_HOLD_TIME(Timing->HoldSetupTime));
  455. assert_param(IS_FMC_HIZ_TIME(Timing->HiZSetupTime));
  456. assert_param(IS_FMC_NAND_BANK(Bank));
  457. /* Get the NAND bank 3 register value */
  458. tmpr = Device->PMEM;
  459. /* Clear MEMSETx, MEMWAITx, MEMHOLDx and MEMHIZx bits */
  460. tmpr &= ((uint32_t)~(FMC_PMEM_MEMSET3 | FMC_PMEM_MEMWAIT3 | FMC_PMEM_MEMHOLD3 | \
  461. FMC_PMEM_MEMHIZ3));
  462. /* Set FMC_NAND device timing parameters */
  463. tmpr |= (uint32_t)(Timing->SetupTime |\
  464. ((Timing->WaitSetupTime) << 8) |\
  465. ((Timing->HoldSetupTime) << 16) |\
  466. ((Timing->HiZSetupTime) << 24)
  467. );
  468. /* NAND bank 3 registers configuration */
  469. Device->PMEM = tmpr;
  470. return HAL_OK;
  471. }
  472. /**
  473. * @brief Initializes the FMC_NAND Attribute space Timing according to the specified
  474. * parameters in the FMC_NAND_PCC_TimingTypeDef
  475. * @param Device: Pointer to NAND device instance
  476. * @param Timing: Pointer to NAND timing structure
  477. * @param Bank: NAND bank number
  478. * @retval HAL status
  479. */
  480. HAL_StatusTypeDef FMC_NAND_AttributeSpace_Timing_Init(FMC_NAND_TypeDef *Device, FMC_NAND_PCC_TimingTypeDef *Timing, uint32_t Bank)
  481. {
  482. uint32_t tmpr = 0;
  483. /* Check the parameters */
  484. assert_param(IS_FMC_NAND_DEVICE(Device));
  485. assert_param(IS_FMC_SETUP_TIME(Timing->SetupTime));
  486. assert_param(IS_FMC_WAIT_TIME(Timing->WaitSetupTime));
  487. assert_param(IS_FMC_HOLD_TIME(Timing->HoldSetupTime));
  488. assert_param(IS_FMC_HIZ_TIME(Timing->HiZSetupTime));
  489. assert_param(IS_FMC_NAND_BANK(Bank));
  490. /* Get the NAND bank 3 register value */
  491. tmpr = Device->PATT;
  492. /* Clear ATTSETx, ATTWAITx, ATTHOLDx and ATTHIZx bits */
  493. tmpr &= ((uint32_t)~(FMC_PATT_ATTSET3 | FMC_PATT_ATTWAIT3 | FMC_PATT_ATTHOLD3 | \
  494. FMC_PATT_ATTHIZ3));
  495. /* Set FMC_NAND device timing parameters */
  496. tmpr |= (uint32_t)(Timing->SetupTime |\
  497. ((Timing->WaitSetupTime) << 8) |\
  498. ((Timing->HoldSetupTime) << 16) |\
  499. ((Timing->HiZSetupTime) << 24));
  500. /* NAND bank 3 registers configuration */
  501. Device->PATT = tmpr;
  502. return HAL_OK;
  503. }
  504. /**
  505. * @brief DeInitializes the FMC_NAND device
  506. * @param Device: Pointer to NAND device instance
  507. * @param Bank: NAND bank number
  508. * @retval HAL status
  509. */
  510. HAL_StatusTypeDef FMC_NAND_DeInit(FMC_NAND_TypeDef *Device, uint32_t Bank)
  511. {
  512. /* Check the parameters */
  513. assert_param(IS_FMC_NAND_DEVICE(Device));
  514. assert_param(IS_FMC_NAND_BANK(Bank));
  515. /* Disable the NAND Bank */
  516. __FMC_NAND_DISABLE(Device);
  517. /* Set the FMC_NAND_BANK3 registers to their reset values */
  518. Device->PCR = 0x00000018U;
  519. Device->SR = 0x00000040U;
  520. Device->PMEM = 0xFCFCFCFCU;
  521. Device->PATT = 0xFCFCFCFCU;
  522. return HAL_OK;
  523. }
  524. /**
  525. * @}
  526. */
  527. /** @defgroup HAL_FMC_NAND_Group3 Control functions
  528. * @brief management functions
  529. *
  530. @verbatim
  531. ==============================================================================
  532. ##### FMC_NAND Control functions #####
  533. ==============================================================================
  534. [..]
  535. This subsection provides a set of functions allowing to control dynamically
  536. the FMC NAND interface.
  537. @endverbatim
  538. * @{
  539. */
  540. /**
  541. * @brief Enables dynamically FMC_NAND ECC feature.
  542. * @param Device: Pointer to NAND device instance
  543. * @param Bank: NAND bank number
  544. * @retval HAL status
  545. */
  546. HAL_StatusTypeDef FMC_NAND_ECC_Enable(FMC_NAND_TypeDef *Device, uint32_t Bank)
  547. {
  548. /* Check the parameters */
  549. assert_param(IS_FMC_NAND_DEVICE(Device));
  550. assert_param(IS_FMC_NAND_BANK(Bank));
  551. /* Enable ECC feature */
  552. Device->PCR |= FMC_PCR_ECCEN;
  553. return HAL_OK;
  554. }
  555. /**
  556. * @brief Disables dynamically FMC_NAND ECC feature.
  557. * @param Device: Pointer to NAND device instance
  558. * @param Bank: NAND bank number
  559. * @retval HAL status
  560. */
  561. HAL_StatusTypeDef FMC_NAND_ECC_Disable(FMC_NAND_TypeDef *Device, uint32_t Bank)
  562. {
  563. /* Check the parameters */
  564. assert_param(IS_FMC_NAND_DEVICE(Device));
  565. assert_param(IS_FMC_NAND_BANK(Bank));
  566. /* Disable ECC feature */
  567. Device->PCR &= ~FMC_PCR_ECCEN;
  568. return HAL_OK;
  569. }
  570. /**
  571. * @brief Disables dynamically FMC_NAND ECC feature.
  572. * @param Device: Pointer to NAND device instance
  573. * @param ECCval: Pointer to ECC value
  574. * @param Bank: NAND bank number
  575. * @param Timeout: Timeout wait value
  576. * @retval HAL status
  577. */
  578. HAL_StatusTypeDef FMC_NAND_GetECC(FMC_NAND_TypeDef *Device, uint32_t *ECCval, uint32_t Bank, uint32_t Timeout)
  579. {
  580. uint32_t tickstart = 0;
  581. /* Check the parameters */
  582. assert_param(IS_FMC_NAND_DEVICE(Device));
  583. assert_param(IS_FMC_NAND_BANK(Bank));
  584. /* Get tick */
  585. tickstart = HAL_GetTick();
  586. /* Wait until FIFO is empty */
  587. while(__FMC_NAND_GET_FLAG(Device, Bank, FMC_FLAG_FEMPT) == RESET)
  588. {
  589. /* Check for the Timeout */
  590. if(Timeout != HAL_MAX_DELAY)
  591. {
  592. if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
  593. {
  594. return HAL_TIMEOUT;
  595. }
  596. }
  597. }
  598. /* Get the ECCR register value */
  599. *ECCval = (uint32_t)Device->ECCR;
  600. return HAL_OK;
  601. }
  602. /**
  603. * @}
  604. */
  605. /**
  606. * @}
  607. */
  608. /** @defgroup FMC_LL_SDRAM
  609. * @brief SDRAM Controller functions
  610. *
  611. @verbatim
  612. ==============================================================================
  613. ##### How to use SDRAM device driver #####
  614. ==============================================================================
  615. [..]
  616. This driver contains a set of APIs to interface with the FMC SDRAM banks in order
  617. to run the SDRAM external devices.
  618. (+) FMC SDRAM bank reset using the function FMC_SDRAM_DeInit()
  619. (+) FMC SDRAM bank control configuration using the function FMC_SDRAM_Init()
  620. (+) FMC SDRAM bank timing configuration using the function FMC_SDRAM_Timing_Init()
  621. (+) FMC SDRAM bank enable/disable write operation using the functions
  622. FMC_SDRAM_WriteOperation_Enable()/FMC_SDRAM_WriteOperation_Disable()
  623. (+) FMC SDRAM bank send command using the function FMC_SDRAM_SendCommand()
  624. @endverbatim
  625. * @{
  626. */
  627. /** @addtogroup FMC_LL_SDRAM_Private_Functions_Group1
  628. * @brief Initialization and Configuration functions
  629. *
  630. @verbatim
  631. ==============================================================================
  632. ##### Initialization and de_initialization functions #####
  633. ==============================================================================
  634. [..]
  635. This section provides functions allowing to:
  636. (+) Initialize and configure the FMC SDRAM interface
  637. (+) De-initialize the FMC SDRAM interface
  638. (+) Configure the FMC clock and associated GPIOs
  639. @endverbatim
  640. * @{
  641. */
  642. /**
  643. * @brief Initializes the FMC_SDRAM device according to the specified
  644. * control parameters in the FMC_SDRAM_InitTypeDef
  645. * @param Device: Pointer to SDRAM device instance
  646. * @param Init: Pointer to SDRAM Initialization structure
  647. * @retval HAL status
  648. */
  649. HAL_StatusTypeDef FMC_SDRAM_Init(FMC_SDRAM_TypeDef *Device, FMC_SDRAM_InitTypeDef *Init)
  650. {
  651. uint32_t tmpr1 = 0;
  652. uint32_t tmpr2 = 0;
  653. /* Check the parameters */
  654. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  655. assert_param(IS_FMC_SDRAM_BANK(Init->SDBank));
  656. assert_param(IS_FMC_COLUMNBITS_NUMBER(Init->ColumnBitsNumber));
  657. assert_param(IS_FMC_ROWBITS_NUMBER(Init->RowBitsNumber));
  658. assert_param(IS_FMC_SDMEMORY_WIDTH(Init->MemoryDataWidth));
  659. assert_param(IS_FMC_INTERNALBANK_NUMBER(Init->InternalBankNumber));
  660. assert_param(IS_FMC_CAS_LATENCY(Init->CASLatency));
  661. assert_param(IS_FMC_WRITE_PROTECTION(Init->WriteProtection));
  662. assert_param(IS_FMC_SDCLOCK_PERIOD(Init->SDClockPeriod));
  663. assert_param(IS_FMC_READ_BURST(Init->ReadBurst));
  664. assert_param(IS_FMC_READPIPE_DELAY(Init->ReadPipeDelay));
  665. /* Set SDRAM bank configuration parameters */
  666. if (Init->SDBank != FMC_SDRAM_BANK2)
  667. {
  668. tmpr1 = Device->SDCR[FMC_SDRAM_BANK1];
  669. /* Clear NC, NR, MWID, NB, CAS, WP, SDCLK, RBURST, and RPIPE bits */
  670. tmpr1 &= ((uint32_t)~(FMC_SDCR1_NC | FMC_SDCR1_NR | FMC_SDCR1_MWID | \
  671. FMC_SDCR1_NB | FMC_SDCR1_CAS | FMC_SDCR1_WP | \
  672. FMC_SDCR1_SDCLK | FMC_SDCR1_RBURST | FMC_SDCR1_RPIPE));
  673. tmpr1 |= (uint32_t)(Init->ColumnBitsNumber |\
  674. Init->RowBitsNumber |\
  675. Init->MemoryDataWidth |\
  676. Init->InternalBankNumber |\
  677. Init->CASLatency |\
  678. Init->WriteProtection |\
  679. Init->SDClockPeriod |\
  680. Init->ReadBurst |\
  681. Init->ReadPipeDelay
  682. );
  683. Device->SDCR[FMC_SDRAM_BANK1] = tmpr1;
  684. }
  685. else /* FMC_Bank2_SDRAM */
  686. {
  687. tmpr1 = Device->SDCR[FMC_SDRAM_BANK1];
  688. /* Clear SDCLK, RBURST, and RPIPE bits */
  689. tmpr1 &= ((uint32_t)~(FMC_SDCR1_SDCLK | FMC_SDCR1_RBURST | FMC_SDCR1_RPIPE));
  690. tmpr1 |= (uint32_t)(Init->SDClockPeriod |\
  691. Init->ReadBurst |\
  692. Init->ReadPipeDelay);
  693. tmpr2 = Device->SDCR[FMC_SDRAM_BANK2];
  694. /* Clear NC, NR, MWID, NB, CAS, WP, SDCLK, RBURST, and RPIPE bits */
  695. tmpr2 &= ((uint32_t)~(FMC_SDCR1_NC | FMC_SDCR1_NR | FMC_SDCR1_MWID | \
  696. FMC_SDCR1_NB | FMC_SDCR1_CAS | FMC_SDCR1_WP | \
  697. FMC_SDCR1_SDCLK | FMC_SDCR1_RBURST | FMC_SDCR1_RPIPE));
  698. tmpr2 |= (uint32_t)(Init->ColumnBitsNumber |\
  699. Init->RowBitsNumber |\
  700. Init->MemoryDataWidth |\
  701. Init->InternalBankNumber |\
  702. Init->CASLatency |\
  703. Init->WriteProtection);
  704. Device->SDCR[FMC_SDRAM_BANK1] = tmpr1;
  705. Device->SDCR[FMC_SDRAM_BANK2] = tmpr2;
  706. }
  707. return HAL_OK;
  708. }
  709. /**
  710. * @brief Initializes the FMC_SDRAM device timing according to the specified
  711. * parameters in the FMC_SDRAM_TimingTypeDef
  712. * @param Device: Pointer to SDRAM device instance
  713. * @param Timing: Pointer to SDRAM Timing structure
  714. * @param Bank: SDRAM bank number
  715. * @retval HAL status
  716. */
  717. HAL_StatusTypeDef FMC_SDRAM_Timing_Init(FMC_SDRAM_TypeDef *Device, FMC_SDRAM_TimingTypeDef *Timing, uint32_t Bank)
  718. {
  719. uint32_t tmpr1 = 0;
  720. uint32_t tmpr2 = 0;
  721. /* Check the parameters */
  722. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  723. assert_param(IS_FMC_LOADTOACTIVE_DELAY(Timing->LoadToActiveDelay));
  724. assert_param(IS_FMC_EXITSELFREFRESH_DELAY(Timing->ExitSelfRefreshDelay));
  725. assert_param(IS_FMC_SELFREFRESH_TIME(Timing->SelfRefreshTime));
  726. assert_param(IS_FMC_ROWCYCLE_DELAY(Timing->RowCycleDelay));
  727. assert_param(IS_FMC_WRITE_RECOVERY_TIME(Timing->WriteRecoveryTime));
  728. assert_param(IS_FMC_RP_DELAY(Timing->RPDelay));
  729. assert_param(IS_FMC_RCD_DELAY(Timing->RCDDelay));
  730. assert_param(IS_FMC_SDRAM_BANK(Bank));
  731. /* Set SDRAM device timing parameters */
  732. if (Bank != FMC_SDRAM_BANK2)
  733. {
  734. tmpr1 = Device->SDTR[FMC_SDRAM_BANK1];
  735. /* Clear TMRD, TXSR, TRAS, TRC, TWR, TRP and TRCD bits */
  736. tmpr1 &= ((uint32_t)~(FMC_SDTR1_TMRD | FMC_SDTR1_TXSR | FMC_SDTR1_TRAS | \
  737. FMC_SDTR1_TRC | FMC_SDTR1_TWR | FMC_SDTR1_TRP | \
  738. FMC_SDTR1_TRCD));
  739. tmpr1 |= (uint32_t)(((Timing->LoadToActiveDelay)-1) |\
  740. (((Timing->ExitSelfRefreshDelay)-1) << 4) |\
  741. (((Timing->SelfRefreshTime)-1) << 8) |\
  742. (((Timing->RowCycleDelay)-1) << 12) |\
  743. (((Timing->WriteRecoveryTime)-1) <<16) |\
  744. (((Timing->RPDelay)-1) << 20) |\
  745. (((Timing->RCDDelay)-1) << 24));
  746. Device->SDTR[FMC_SDRAM_BANK1] = tmpr1;
  747. }
  748. else /* FMC_Bank2_SDRAM */
  749. {
  750. tmpr1 = Device->SDTR[FMC_SDRAM_BANK1];
  751. /* Clear TRC and TRP bits */
  752. tmpr1 &= ((uint32_t)~(FMC_SDTR1_TRC | FMC_SDTR1_TRP));
  753. tmpr1 |= (uint32_t)((((Timing->RowCycleDelay)-1) << 12) |\
  754. (((Timing->RPDelay)-1) << 20));
  755. tmpr2 = Device->SDTR[FMC_SDRAM_BANK2];
  756. /* Clear TMRD, TXSR, TRAS, TRC, TWR, TRP and TRCD bits */
  757. tmpr2 &= ((uint32_t)~(FMC_SDTR1_TMRD | FMC_SDTR1_TXSR | FMC_SDTR1_TRAS | \
  758. FMC_SDTR1_TRC | FMC_SDTR1_TWR | FMC_SDTR1_TRP | \
  759. FMC_SDTR1_TRCD));
  760. tmpr2 |= (uint32_t)(((Timing->LoadToActiveDelay)-1) |\
  761. (((Timing->ExitSelfRefreshDelay)-1) << 4) |\
  762. (((Timing->SelfRefreshTime)-1) << 8) |\
  763. (((Timing->WriteRecoveryTime)-1) <<16) |\
  764. (((Timing->RCDDelay)-1) << 24));
  765. Device->SDTR[FMC_SDRAM_BANK1] = tmpr1;
  766. Device->SDTR[FMC_SDRAM_BANK2] = tmpr2;
  767. }
  768. return HAL_OK;
  769. }
  770. /**
  771. * @brief DeInitializes the FMC_SDRAM peripheral
  772. * @param Device: Pointer to SDRAM device instance
  773. * @retval HAL status
  774. */
  775. HAL_StatusTypeDef FMC_SDRAM_DeInit(FMC_SDRAM_TypeDef *Device, uint32_t Bank)
  776. {
  777. /* Check the parameters */
  778. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  779. assert_param(IS_FMC_SDRAM_BANK(Bank));
  780. /* De-initialize the SDRAM device */
  781. Device->SDCR[Bank] = 0x000002D0;
  782. Device->SDTR[Bank] = 0x0FFFFFFF;
  783. Device->SDCMR = 0x00000000;
  784. Device->SDRTR = 0x00000000;
  785. Device->SDSR = 0x00000000;
  786. return HAL_OK;
  787. }
  788. /**
  789. * @}
  790. */
  791. /** @addtogroup FMC_LL_SDRAMPrivate_Functions_Group2
  792. * @brief management functions
  793. *
  794. @verbatim
  795. ==============================================================================
  796. ##### FMC_SDRAM Control functions #####
  797. ==============================================================================
  798. [..]
  799. This subsection provides a set of functions allowing to control dynamically
  800. the FMC SDRAM interface.
  801. @endverbatim
  802. * @{
  803. */
  804. /**
  805. * @brief Enables dynamically FMC_SDRAM write protection.
  806. * @param Device: Pointer to SDRAM device instance
  807. * @param Bank: SDRAM bank number
  808. * @retval HAL status
  809. */
  810. HAL_StatusTypeDef FMC_SDRAM_WriteProtection_Enable(FMC_SDRAM_TypeDef *Device, uint32_t Bank)
  811. {
  812. /* Check the parameters */
  813. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  814. assert_param(IS_FMC_SDRAM_BANK(Bank));
  815. /* Enable write protection */
  816. Device->SDCR[Bank] |= FMC_SDRAM_WRITE_PROTECTION_ENABLE;
  817. return HAL_OK;
  818. }
  819. /**
  820. * @brief Disables dynamically FMC_SDRAM write protection.
  821. * @param hsdram: FMC_SDRAM handle
  822. * @retval HAL status
  823. */
  824. HAL_StatusTypeDef FMC_SDRAM_WriteProtection_Disable(FMC_SDRAM_TypeDef *Device, uint32_t Bank)
  825. {
  826. /* Check the parameters */
  827. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  828. assert_param(IS_FMC_SDRAM_BANK(Bank));
  829. /* Disable write protection */
  830. Device->SDCR[Bank] &= ~FMC_SDRAM_WRITE_PROTECTION_ENABLE;
  831. return HAL_OK;
  832. }
  833. /**
  834. * @brief Send Command to the FMC SDRAM bank
  835. * @param Device: Pointer to SDRAM device instance
  836. * @param Command: Pointer to SDRAM command structure
  837. * @param Timing: Pointer to SDRAM Timing structure
  838. * @param Timeout: Timeout wait value
  839. * @retval HAL state
  840. */
  841. HAL_StatusTypeDef FMC_SDRAM_SendCommand(FMC_SDRAM_TypeDef *Device, FMC_SDRAM_CommandTypeDef *Command, uint32_t Timeout)
  842. {
  843. __IO uint32_t tmpr = 0;
  844. uint32_t tickstart = 0;
  845. /* Check the parameters */
  846. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  847. assert_param(IS_FMC_COMMAND_MODE(Command->CommandMode));
  848. assert_param(IS_FMC_COMMAND_TARGET(Command->CommandTarget));
  849. assert_param(IS_FMC_AUTOREFRESH_NUMBER(Command->AutoRefreshNumber));
  850. assert_param(IS_FMC_MODE_REGISTER(Command->ModeRegisterDefinition));
  851. /* Set command register */
  852. tmpr = (uint32_t)((Command->CommandMode) |\
  853. (Command->CommandTarget) |\
  854. (((Command->AutoRefreshNumber)-1) << 5) |\
  855. ((Command->ModeRegisterDefinition) << 9)
  856. );
  857. Device->SDCMR = tmpr;
  858. /* Get tick */
  859. tickstart = HAL_GetTick();
  860. /* wait until command is send */
  861. while(HAL_IS_BIT_SET(Device->SDSR, FMC_SDSR_BUSY))
  862. {
  863. /* Check for the Timeout */
  864. if(Timeout != HAL_MAX_DELAY)
  865. {
  866. if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
  867. {
  868. return HAL_TIMEOUT;
  869. }
  870. }
  871. }
  872. return HAL_OK;
  873. }
  874. /**
  875. * @brief Program the SDRAM Memory Refresh rate.
  876. * @param Device: Pointer to SDRAM device instance
  877. * @param RefreshRate: The SDRAM refresh rate value.
  878. * @retval HAL state
  879. */
  880. HAL_StatusTypeDef FMC_SDRAM_ProgramRefreshRate(FMC_SDRAM_TypeDef *Device, uint32_t RefreshRate)
  881. {
  882. /* Check the parameters */
  883. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  884. assert_param(IS_FMC_REFRESH_RATE(RefreshRate));
  885. /* Set the refresh rate in command register */
  886. Device->SDRTR |= (RefreshRate<<1);
  887. return HAL_OK;
  888. }
  889. /**
  890. * @brief Set the Number of consecutive SDRAM Memory auto Refresh commands.
  891. * @param Device: Pointer to SDRAM device instance
  892. * @param AutoRefreshNumber: Specifies the auto Refresh number.
  893. * @retval None
  894. */
  895. HAL_StatusTypeDef FMC_SDRAM_SetAutoRefreshNumber(FMC_SDRAM_TypeDef *Device, uint32_t AutoRefreshNumber)
  896. {
  897. /* Check the parameters */
  898. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  899. assert_param(IS_FMC_AUTOREFRESH_NUMBER(AutoRefreshNumber));
  900. /* Set the Auto-refresh number in command register */
  901. Device->SDCMR |= (AutoRefreshNumber << 5);
  902. return HAL_OK;
  903. }
  904. /**
  905. * @brief Returns the indicated FMC SDRAM bank mode status.
  906. * @param Device: Pointer to SDRAM device instance
  907. * @param Bank: Defines the FMC SDRAM bank. This parameter can be
  908. * FMC_Bank1_SDRAM or FMC_Bank2_SDRAM.
  909. * @retval The FMC SDRAM bank mode status, could be on of the following values:
  910. * FMC_SDRAM_NORMAL_MODE, FMC_SDRAM_SELF_REFRESH_MODE or
  911. * FMC_SDRAM_POWER_DOWN_MODE.
  912. */
  913. uint32_t FMC_SDRAM_GetModeStatus(FMC_SDRAM_TypeDef *Device, uint32_t Bank)
  914. {
  915. uint32_t tmpreg = 0;
  916. /* Check the parameters */
  917. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  918. assert_param(IS_FMC_SDRAM_BANK(Bank));
  919. /* Get the corresponding bank mode */
  920. if(Bank == FMC_SDRAM_BANK1)
  921. {
  922. tmpreg = (uint32_t)(Device->SDSR & FMC_SDSR_MODES1);
  923. }
  924. else
  925. {
  926. tmpreg = ((uint32_t)(Device->SDSR & FMC_SDSR_MODES2) >> 2);
  927. }
  928. /* Return the mode status */
  929. return tmpreg;
  930. }
  931. /**
  932. * @}
  933. */
  934. /**
  935. * @}
  936. */
  937. /**
  938. * @}
  939. */
  940. #endif /* HAL_SRAM_MODULE_ENABLED || HAL_NOR_MODULE_ENABLED || HAL_NAND_MODULE_ENABLED || HAL_SDRAM_MODULE_ENABLED */
  941. /**
  942. * @}
  943. */
  944. /**
  945. * @}
  946. */
  947. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/