stm32h7xx_ll_fmc.c 39 KB

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