stm32f7xx_ll_fmc.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098
  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_ll_fmc.c
  4. * @author MCD Application Team
  5. * @brief FMC Low Layer HAL module driver.
  6. *
  7. * This file provides firmware functions to manage the following
  8. * functionalities of the Flexible Memory Controller (FMC) peripheral memories:
  9. * + Initialization/de-initialization functions
  10. * + Peripheral Control functions
  11. * + Peripheral State functions
  12. *
  13. @verbatim
  14. ==============================================================================
  15. ##### FMC peripheral features #####
  16. ==============================================================================
  17. [..] The Flexible memory controller (FMC) includes three memory controllers:
  18. (+) The NOR/PSRAM memory controller
  19. (+) The NAND memory controller
  20. (+) The Synchronous DRAM (SDRAM) controller
  21. [..] The FMC functional block makes the interface with synchronous and asynchronous static
  22. memories, SDRAM memories, and 16-bit PC memory cards. Its main purposes are:
  23. (+) to translate AHB transactions into the appropriate external device protocol
  24. (+) to meet the access time requirements of the external memory devices
  25. [..] All external memories share the addresses, data and control signals with the controller.
  26. Each external device is accessed by means of a unique Chip Select. The FMC performs
  27. only one access at a time to an external device.
  28. The main features of the FMC controller are the following:
  29. (+) Interface with static-memory mapped devices including:
  30. (++) Static random access memory (SRAM)
  31. (++) Read-only memory (ROM)
  32. (++) NOR Flash memory/OneNAND Flash memory
  33. (++) PSRAM (4 memory banks)
  34. (++) 16-bit PC Card compatible devices
  35. (++) Two banks of NAND Flash memory with ECC hardware to check up to 8 Kbytes of
  36. 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 "stm32f7xx_hal.h"
  72. /** @addtogroup STM32F7xx_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 | FMC_PCR_PTYP | \
  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. FMC_PCR_MEMORY_TYPE_NAND |\
  428. Init->MemoryDataWidth |\
  429. Init->EccComputation |\
  430. Init->ECCPageSize |\
  431. ((Init->TCLRSetupTime) << 9) |\
  432. ((Init->TARSetupTime) << 13));
  433. /* NAND bank 3 registers configuration */
  434. Device->PCR = tmpr;
  435. return HAL_OK;
  436. }
  437. /**
  438. * @brief Initializes the FMC_NAND Common space Timing according to the specified
  439. * parameters in the FMC_NAND_PCC_TimingTypeDef
  440. * @param Device Pointer to NAND device instance
  441. * @param Timing Pointer to NAND timing structure
  442. * @param Bank NAND bank number
  443. * @retval HAL status
  444. */
  445. HAL_StatusTypeDef FMC_NAND_CommonSpace_Timing_Init(FMC_NAND_TypeDef *Device, FMC_NAND_PCC_TimingTypeDef *Timing, uint32_t Bank)
  446. {
  447. uint32_t tmpr = 0;
  448. /* Check the parameters */
  449. assert_param(IS_FMC_NAND_DEVICE(Device));
  450. assert_param(IS_FMC_SETUP_TIME(Timing->SetupTime));
  451. assert_param(IS_FMC_WAIT_TIME(Timing->WaitSetupTime));
  452. assert_param(IS_FMC_HOLD_TIME(Timing->HoldSetupTime));
  453. assert_param(IS_FMC_HIZ_TIME(Timing->HiZSetupTime));
  454. assert_param(IS_FMC_NAND_BANK(Bank));
  455. /* Get the NAND bank 3 register value */
  456. tmpr = Device->PMEM;
  457. /* Clear MEMSETx, MEMWAITx, MEMHOLDx and MEMHIZx bits */
  458. tmpr &= ((uint32_t)~(FMC_PMEM_MEMSET3 | FMC_PMEM_MEMWAIT3 | FMC_PMEM_MEMHOLD3 | \
  459. FMC_PMEM_MEMHIZ3));
  460. /* Set FMC_NAND device timing parameters */
  461. tmpr |= (uint32_t)(Timing->SetupTime |\
  462. ((Timing->WaitSetupTime) << 8) |\
  463. ((Timing->HoldSetupTime) << 16) |\
  464. ((Timing->HiZSetupTime) << 24)
  465. );
  466. /* NAND bank 3 registers configuration */
  467. Device->PMEM = tmpr;
  468. return HAL_OK;
  469. }
  470. /**
  471. * @brief Initializes the FMC_NAND Attribute space Timing according to the specified
  472. * parameters in the FMC_NAND_PCC_TimingTypeDef
  473. * @param Device Pointer to NAND device instance
  474. * @param Timing Pointer to NAND timing structure
  475. * @param Bank NAND bank number
  476. * @retval HAL status
  477. */
  478. HAL_StatusTypeDef FMC_NAND_AttributeSpace_Timing_Init(FMC_NAND_TypeDef *Device, FMC_NAND_PCC_TimingTypeDef *Timing, uint32_t Bank)
  479. {
  480. uint32_t tmpr = 0;
  481. /* Check the parameters */
  482. assert_param(IS_FMC_NAND_DEVICE(Device));
  483. assert_param(IS_FMC_SETUP_TIME(Timing->SetupTime));
  484. assert_param(IS_FMC_WAIT_TIME(Timing->WaitSetupTime));
  485. assert_param(IS_FMC_HOLD_TIME(Timing->HoldSetupTime));
  486. assert_param(IS_FMC_HIZ_TIME(Timing->HiZSetupTime));
  487. assert_param(IS_FMC_NAND_BANK(Bank));
  488. /* Get the NAND bank 3 register value */
  489. tmpr = Device->PATT;
  490. /* Clear ATTSETx, ATTWAITx, ATTHOLDx and ATTHIZx bits */
  491. tmpr &= ((uint32_t)~(FMC_PATT_ATTSET3 | FMC_PATT_ATTWAIT3 | FMC_PATT_ATTHOLD3 | \
  492. FMC_PATT_ATTHIZ3));
  493. /* Set FMC_NAND device timing parameters */
  494. tmpr |= (uint32_t)(Timing->SetupTime |\
  495. ((Timing->WaitSetupTime) << 8) |\
  496. ((Timing->HoldSetupTime) << 16) |\
  497. ((Timing->HiZSetupTime) << 24));
  498. /* NAND bank 3 registers configuration */
  499. Device->PATT = tmpr;
  500. return HAL_OK;
  501. }
  502. /**
  503. * @brief DeInitializes the FMC_NAND device
  504. * @param Device Pointer to NAND device instance
  505. * @param Bank NAND bank number
  506. * @retval HAL status
  507. */
  508. HAL_StatusTypeDef FMC_NAND_DeInit(FMC_NAND_TypeDef *Device, uint32_t Bank)
  509. {
  510. /* Check the parameters */
  511. assert_param(IS_FMC_NAND_DEVICE(Device));
  512. assert_param(IS_FMC_NAND_BANK(Bank));
  513. /* Disable the NAND Bank */
  514. __FMC_NAND_DISABLE(Device);
  515. /* Set the FMC_NAND_BANK3 registers to their reset values */
  516. Device->PCR = 0x00000018U;
  517. Device->SR = 0x00000040U;
  518. Device->PMEM = 0xFCFCFCFCU;
  519. Device->PATT = 0xFCFCFCFCU;
  520. return HAL_OK;
  521. }
  522. /**
  523. * @}
  524. */
  525. /** @defgroup HAL_FMC_NAND_Group3 Control functions
  526. * @brief management functions
  527. *
  528. @verbatim
  529. ==============================================================================
  530. ##### FMC_NAND Control functions #####
  531. ==============================================================================
  532. [..]
  533. This subsection provides a set of functions allowing to control dynamically
  534. the FMC NAND interface.
  535. @endverbatim
  536. * @{
  537. */
  538. /**
  539. * @brief Enables dynamically FMC_NAND ECC feature.
  540. * @param Device Pointer to NAND device instance
  541. * @param Bank NAND bank number
  542. * @retval HAL status
  543. */
  544. HAL_StatusTypeDef FMC_NAND_ECC_Enable(FMC_NAND_TypeDef *Device, uint32_t Bank)
  545. {
  546. /* Check the parameters */
  547. assert_param(IS_FMC_NAND_DEVICE(Device));
  548. assert_param(IS_FMC_NAND_BANK(Bank));
  549. /* Enable ECC feature */
  550. Device->PCR |= FMC_PCR_ECCEN;
  551. return HAL_OK;
  552. }
  553. /**
  554. * @brief Disables dynamically FMC_NAND ECC feature.
  555. * @param Device Pointer to NAND device instance
  556. * @param Bank NAND bank number
  557. * @retval HAL status
  558. */
  559. HAL_StatusTypeDef FMC_NAND_ECC_Disable(FMC_NAND_TypeDef *Device, uint32_t Bank)
  560. {
  561. /* Check the parameters */
  562. assert_param(IS_FMC_NAND_DEVICE(Device));
  563. assert_param(IS_FMC_NAND_BANK(Bank));
  564. /* Disable ECC feature */
  565. Device->PCR &= ~FMC_PCR_ECCEN;
  566. return HAL_OK;
  567. }
  568. /**
  569. * @brief Disables dynamically FMC_NAND ECC feature.
  570. * @param Device Pointer to NAND device instance
  571. * @param ECCval Pointer to ECC value
  572. * @param Bank NAND bank number
  573. * @param Timeout Timeout wait value
  574. * @retval HAL status
  575. */
  576. HAL_StatusTypeDef FMC_NAND_GetECC(FMC_NAND_TypeDef *Device, uint32_t *ECCval, uint32_t Bank, uint32_t Timeout)
  577. {
  578. uint32_t tickstart = 0;
  579. /* Check the parameters */
  580. assert_param(IS_FMC_NAND_DEVICE(Device));
  581. assert_param(IS_FMC_NAND_BANK(Bank));
  582. /* Get tick */
  583. tickstart = HAL_GetTick();
  584. /* Wait until FIFO is empty */
  585. while(__FMC_NAND_GET_FLAG(Device, Bank, FMC_FLAG_FEMPT) == RESET)
  586. {
  587. /* Check for the Timeout */
  588. if(Timeout != HAL_MAX_DELAY)
  589. {
  590. if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
  591. {
  592. return HAL_TIMEOUT;
  593. }
  594. }
  595. }
  596. /* Get the ECCR register value */
  597. *ECCval = (uint32_t)Device->ECCR;
  598. return HAL_OK;
  599. }
  600. /**
  601. * @}
  602. */
  603. /**
  604. * @}
  605. */
  606. /** @defgroup FMC_LL_SDRAM
  607. * @brief SDRAM Controller functions
  608. *
  609. @verbatim
  610. ==============================================================================
  611. ##### How to use SDRAM device driver #####
  612. ==============================================================================
  613. [..]
  614. This driver contains a set of APIs to interface with the FMC SDRAM banks in order
  615. to run the SDRAM external devices.
  616. (+) FMC SDRAM bank reset using the function FMC_SDRAM_DeInit()
  617. (+) FMC SDRAM bank control configuration using the function FMC_SDRAM_Init()
  618. (+) FMC SDRAM bank timing configuration using the function FMC_SDRAM_Timing_Init()
  619. (+) FMC SDRAM bank enable/disable write operation using the functions
  620. FMC_SDRAM_WriteOperation_Enable()/FMC_SDRAM_WriteOperation_Disable()
  621. (+) FMC SDRAM bank send command using the function FMC_SDRAM_SendCommand()
  622. @endverbatim
  623. * @{
  624. */
  625. /** @addtogroup FMC_LL_SDRAM_Private_Functions_Group1
  626. * @brief Initialization and Configuration functions
  627. *
  628. @verbatim
  629. ==============================================================================
  630. ##### Initialization and de_initialization functions #####
  631. ==============================================================================
  632. [..]
  633. This section provides functions allowing to:
  634. (+) Initialize and configure the FMC SDRAM interface
  635. (+) De-initialize the FMC SDRAM interface
  636. (+) Configure the FMC clock and associated GPIOs
  637. @endverbatim
  638. * @{
  639. */
  640. /**
  641. * @brief Initializes the FMC_SDRAM device according to the specified
  642. * control parameters in the FMC_SDRAM_InitTypeDef
  643. * @param Device Pointer to SDRAM device instance
  644. * @param Init Pointer to SDRAM Initialization structure
  645. * @retval HAL status
  646. */
  647. HAL_StatusTypeDef FMC_SDRAM_Init(FMC_SDRAM_TypeDef *Device, FMC_SDRAM_InitTypeDef *Init)
  648. {
  649. uint32_t tmpr1 = 0;
  650. uint32_t tmpr2 = 0;
  651. /* Check the parameters */
  652. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  653. assert_param(IS_FMC_SDRAM_BANK(Init->SDBank));
  654. assert_param(IS_FMC_COLUMNBITS_NUMBER(Init->ColumnBitsNumber));
  655. assert_param(IS_FMC_ROWBITS_NUMBER(Init->RowBitsNumber));
  656. assert_param(IS_FMC_SDMEMORY_WIDTH(Init->MemoryDataWidth));
  657. assert_param(IS_FMC_INTERNALBANK_NUMBER(Init->InternalBankNumber));
  658. assert_param(IS_FMC_CAS_LATENCY(Init->CASLatency));
  659. assert_param(IS_FMC_WRITE_PROTECTION(Init->WriteProtection));
  660. assert_param(IS_FMC_SDCLOCK_PERIOD(Init->SDClockPeriod));
  661. assert_param(IS_FMC_READ_BURST(Init->ReadBurst));
  662. assert_param(IS_FMC_READPIPE_DELAY(Init->ReadPipeDelay));
  663. /* Set SDRAM bank configuration parameters */
  664. if (Init->SDBank != FMC_SDRAM_BANK2)
  665. {
  666. tmpr1 = Device->SDCR[FMC_SDRAM_BANK1];
  667. /* Clear NC, NR, MWID, NB, CAS, WP, SDCLK, RBURST, and RPIPE bits */
  668. tmpr1 &= ((uint32_t)~(FMC_SDCR1_NC | FMC_SDCR1_NR | FMC_SDCR1_MWID | \
  669. FMC_SDCR1_NB | FMC_SDCR1_CAS | FMC_SDCR1_WP | \
  670. FMC_SDCR1_SDCLK | FMC_SDCR1_RBURST | FMC_SDCR1_RPIPE));
  671. tmpr1 |= (uint32_t)(Init->ColumnBitsNumber |\
  672. Init->RowBitsNumber |\
  673. Init->MemoryDataWidth |\
  674. Init->InternalBankNumber |\
  675. Init->CASLatency |\
  676. Init->WriteProtection |\
  677. Init->SDClockPeriod |\
  678. Init->ReadBurst |\
  679. Init->ReadPipeDelay
  680. );
  681. Device->SDCR[FMC_SDRAM_BANK1] = tmpr1;
  682. }
  683. else /* FMC_Bank2_SDRAM */
  684. {
  685. tmpr1 = Device->SDCR[FMC_SDRAM_BANK1];
  686. /* Clear SDCLK, RBURST, and RPIPE bits */
  687. tmpr1 &= ((uint32_t)~(FMC_SDCR1_SDCLK | FMC_SDCR1_RBURST | FMC_SDCR1_RPIPE));
  688. tmpr1 |= (uint32_t)(Init->SDClockPeriod |\
  689. Init->ReadBurst |\
  690. Init->ReadPipeDelay);
  691. tmpr2 = Device->SDCR[FMC_SDRAM_BANK2];
  692. /* Clear NC, NR, MWID, NB, CAS, WP, SDCLK, RBURST, and RPIPE bits */
  693. tmpr2 &= ((uint32_t)~(FMC_SDCR1_NC | FMC_SDCR1_NR | FMC_SDCR1_MWID | \
  694. FMC_SDCR1_NB | FMC_SDCR1_CAS | FMC_SDCR1_WP | \
  695. FMC_SDCR1_SDCLK | FMC_SDCR1_RBURST | FMC_SDCR1_RPIPE));
  696. tmpr2 |= (uint32_t)(Init->ColumnBitsNumber |\
  697. Init->RowBitsNumber |\
  698. Init->MemoryDataWidth |\
  699. Init->InternalBankNumber |\
  700. Init->CASLatency |\
  701. Init->WriteProtection);
  702. Device->SDCR[FMC_SDRAM_BANK1] = tmpr1;
  703. Device->SDCR[FMC_SDRAM_BANK2] = tmpr2;
  704. }
  705. return HAL_OK;
  706. }
  707. /**
  708. * @brief Initializes the FMC_SDRAM device timing according to the specified
  709. * parameters in the FMC_SDRAM_TimingTypeDef
  710. * @param Device Pointer to SDRAM device instance
  711. * @param Timing Pointer to SDRAM Timing structure
  712. * @param Bank SDRAM bank number
  713. * @retval HAL status
  714. */
  715. HAL_StatusTypeDef FMC_SDRAM_Timing_Init(FMC_SDRAM_TypeDef *Device, FMC_SDRAM_TimingTypeDef *Timing, uint32_t Bank)
  716. {
  717. uint32_t tmpr1 = 0;
  718. uint32_t tmpr2 = 0;
  719. /* Check the parameters */
  720. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  721. assert_param(IS_FMC_LOADTOACTIVE_DELAY(Timing->LoadToActiveDelay));
  722. assert_param(IS_FMC_EXITSELFREFRESH_DELAY(Timing->ExitSelfRefreshDelay));
  723. assert_param(IS_FMC_SELFREFRESH_TIME(Timing->SelfRefreshTime));
  724. assert_param(IS_FMC_ROWCYCLE_DELAY(Timing->RowCycleDelay));
  725. assert_param(IS_FMC_WRITE_RECOVERY_TIME(Timing->WriteRecoveryTime));
  726. assert_param(IS_FMC_RP_DELAY(Timing->RPDelay));
  727. assert_param(IS_FMC_RCD_DELAY(Timing->RCDDelay));
  728. assert_param(IS_FMC_SDRAM_BANK(Bank));
  729. /* Set SDRAM device timing parameters */
  730. if (Bank != FMC_SDRAM_BANK2)
  731. {
  732. tmpr1 = Device->SDTR[FMC_SDRAM_BANK1];
  733. /* Clear TMRD, TXSR, TRAS, TRC, TWR, TRP and TRCD bits */
  734. tmpr1 &= ((uint32_t)~(FMC_SDTR1_TMRD | FMC_SDTR1_TXSR | FMC_SDTR1_TRAS | \
  735. FMC_SDTR1_TRC | FMC_SDTR1_TWR | FMC_SDTR1_TRP | \
  736. FMC_SDTR1_TRCD));
  737. tmpr1 |= (uint32_t)(((Timing->LoadToActiveDelay)-1) |\
  738. (((Timing->ExitSelfRefreshDelay)-1) << 4) |\
  739. (((Timing->SelfRefreshTime)-1) << 8) |\
  740. (((Timing->RowCycleDelay)-1) << 12) |\
  741. (((Timing->WriteRecoveryTime)-1) <<16) |\
  742. (((Timing->RPDelay)-1) << 20) |\
  743. (((Timing->RCDDelay)-1) << 24));
  744. Device->SDTR[FMC_SDRAM_BANK1] = tmpr1;
  745. }
  746. else /* FMC_Bank2_SDRAM */
  747. {
  748. tmpr1 = Device->SDTR[FMC_SDRAM_BANK1];
  749. /* Clear TRC and TRP bits */
  750. tmpr1 &= ((uint32_t)~(FMC_SDTR1_TRC | FMC_SDTR1_TRP));
  751. tmpr1 |= (uint32_t)((((Timing->RowCycleDelay)-1) << 12) |\
  752. (((Timing->RPDelay)-1) << 20));
  753. tmpr2 = Device->SDTR[FMC_SDRAM_BANK2];
  754. /* Clear TMRD, TXSR, TRAS, TRC, TWR, TRP and TRCD bits */
  755. tmpr2 &= ((uint32_t)~(FMC_SDTR1_TMRD | FMC_SDTR1_TXSR | FMC_SDTR1_TRAS | \
  756. FMC_SDTR1_TRC | FMC_SDTR1_TWR | FMC_SDTR1_TRP | \
  757. FMC_SDTR1_TRCD));
  758. tmpr2 |= (uint32_t)(((Timing->LoadToActiveDelay)-1) |\
  759. (((Timing->ExitSelfRefreshDelay)-1) << 4) |\
  760. (((Timing->SelfRefreshTime)-1) << 8) |\
  761. (((Timing->WriteRecoveryTime)-1) <<16) |\
  762. (((Timing->RCDDelay)-1) << 24));
  763. Device->SDTR[FMC_SDRAM_BANK1] = tmpr1;
  764. Device->SDTR[FMC_SDRAM_BANK2] = tmpr2;
  765. }
  766. return HAL_OK;
  767. }
  768. /**
  769. * @brief DeInitializes the FMC_SDRAM peripheral
  770. * @param Device Pointer to SDRAM device instance
  771. * @retval HAL status
  772. */
  773. HAL_StatusTypeDef FMC_SDRAM_DeInit(FMC_SDRAM_TypeDef *Device, uint32_t Bank)
  774. {
  775. /* Check the parameters */
  776. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  777. assert_param(IS_FMC_SDRAM_BANK(Bank));
  778. /* De-initialize the SDRAM device */
  779. Device->SDCR[Bank] = 0x000002D0;
  780. Device->SDTR[Bank] = 0x0FFFFFFF;
  781. Device->SDCMR = 0x00000000;
  782. Device->SDRTR = 0x00000000;
  783. Device->SDSR = 0x00000000;
  784. return HAL_OK;
  785. }
  786. /**
  787. * @}
  788. */
  789. /** @addtogroup FMC_LL_SDRAMPrivate_Functions_Group2
  790. * @brief management functions
  791. *
  792. @verbatim
  793. ==============================================================================
  794. ##### FMC_SDRAM Control functions #####
  795. ==============================================================================
  796. [..]
  797. This subsection provides a set of functions allowing to control dynamically
  798. the FMC SDRAM interface.
  799. @endverbatim
  800. * @{
  801. */
  802. /**
  803. * @brief Enables dynamically FMC_SDRAM write protection.
  804. * @param Device Pointer to SDRAM device instance
  805. * @param Bank SDRAM bank number
  806. * @retval HAL status
  807. */
  808. HAL_StatusTypeDef FMC_SDRAM_WriteProtection_Enable(FMC_SDRAM_TypeDef *Device, uint32_t Bank)
  809. {
  810. /* Check the parameters */
  811. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  812. assert_param(IS_FMC_SDRAM_BANK(Bank));
  813. /* Enable write protection */
  814. Device->SDCR[Bank] |= FMC_SDRAM_WRITE_PROTECTION_ENABLE;
  815. return HAL_OK;
  816. }
  817. /**
  818. * @brief Disables dynamically FMC_SDRAM write protection.
  819. * @param hsdram FMC_SDRAM handle
  820. * @retval HAL status
  821. */
  822. HAL_StatusTypeDef FMC_SDRAM_WriteProtection_Disable(FMC_SDRAM_TypeDef *Device, uint32_t Bank)
  823. {
  824. /* Check the parameters */
  825. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  826. assert_param(IS_FMC_SDRAM_BANK(Bank));
  827. /* Disable write protection */
  828. Device->SDCR[Bank] &= ~FMC_SDRAM_WRITE_PROTECTION_ENABLE;
  829. return HAL_OK;
  830. }
  831. /**
  832. * @brief Send Command to the FMC SDRAM bank
  833. * @param Device Pointer to SDRAM device instance
  834. * @param Command Pointer to SDRAM command structure
  835. * @param Timing Pointer to SDRAM Timing structure
  836. * @param Timeout Timeout wait value
  837. * @retval HAL state
  838. */
  839. HAL_StatusTypeDef FMC_SDRAM_SendCommand(FMC_SDRAM_TypeDef *Device, FMC_SDRAM_CommandTypeDef *Command, uint32_t Timeout)
  840. {
  841. __IO uint32_t tmpr = 0;
  842. /* Check the parameters */
  843. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  844. assert_param(IS_FMC_COMMAND_MODE(Command->CommandMode));
  845. assert_param(IS_FMC_COMMAND_TARGET(Command->CommandTarget));
  846. assert_param(IS_FMC_AUTOREFRESH_NUMBER(Command->AutoRefreshNumber));
  847. assert_param(IS_FMC_MODE_REGISTER(Command->ModeRegisterDefinition));
  848. /* Set command register */
  849. tmpr = (uint32_t)((Command->CommandMode) |\
  850. (Command->CommandTarget) |\
  851. (((Command->AutoRefreshNumber)-1) << 5) |\
  852. ((Command->ModeRegisterDefinition) << 9)
  853. );
  854. Device->SDCMR = tmpr;
  855. return HAL_OK;
  856. }
  857. /**
  858. * @brief Program the SDRAM Memory Refresh rate.
  859. * @param Device Pointer to SDRAM device instance
  860. * @param RefreshRate The SDRAM refresh rate value.
  861. * @retval HAL state
  862. */
  863. HAL_StatusTypeDef FMC_SDRAM_ProgramRefreshRate(FMC_SDRAM_TypeDef *Device, uint32_t RefreshRate)
  864. {
  865. /* Check the parameters */
  866. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  867. assert_param(IS_FMC_REFRESH_RATE(RefreshRate));
  868. /* Set the refresh rate in command register */
  869. Device->SDRTR |= (RefreshRate<<1);
  870. return HAL_OK;
  871. }
  872. /**
  873. * @brief Set the Number of consecutive SDRAM Memory auto Refresh commands.
  874. * @param Device Pointer to SDRAM device instance
  875. * @param AutoRefreshNumber Specifies the auto Refresh number.
  876. * @retval None
  877. */
  878. HAL_StatusTypeDef FMC_SDRAM_SetAutoRefreshNumber(FMC_SDRAM_TypeDef *Device, uint32_t AutoRefreshNumber)
  879. {
  880. /* Check the parameters */
  881. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  882. assert_param(IS_FMC_AUTOREFRESH_NUMBER(AutoRefreshNumber));
  883. /* Set the Auto-refresh number in command register */
  884. Device->SDCMR |= (AutoRefreshNumber << 5);
  885. return HAL_OK;
  886. }
  887. /**
  888. * @brief Returns the indicated FMC SDRAM bank mode status.
  889. * @param Device Pointer to SDRAM device instance
  890. * @param Bank Defines the FMC SDRAM bank. This parameter can be
  891. * FMC_Bank1_SDRAM or FMC_Bank2_SDRAM.
  892. * @retval The FMC SDRAM bank mode status, could be on of the following values:
  893. * FMC_SDRAM_NORMAL_MODE, FMC_SDRAM_SELF_REFRESH_MODE or
  894. * FMC_SDRAM_POWER_DOWN_MODE.
  895. */
  896. uint32_t FMC_SDRAM_GetModeStatus(FMC_SDRAM_TypeDef *Device, uint32_t Bank)
  897. {
  898. uint32_t tmpreg = 0;
  899. /* Check the parameters */
  900. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  901. assert_param(IS_FMC_SDRAM_BANK(Bank));
  902. /* Get the corresponding bank mode */
  903. if(Bank == FMC_SDRAM_BANK1)
  904. {
  905. tmpreg = (uint32_t)(Device->SDSR & FMC_SDSR_MODES1);
  906. }
  907. else
  908. {
  909. tmpreg = ((uint32_t)(Device->SDSR & FMC_SDSR_MODES2) >> 2);
  910. }
  911. /* Return the mode status */
  912. return tmpreg;
  913. }
  914. /**
  915. * @}
  916. */
  917. /**
  918. * @}
  919. */
  920. /**
  921. * @}
  922. */
  923. #endif /* HAL_SRAM_MODULE_ENABLED || HAL_NOR_MODULE_ENABLED || HAL_NAND_MODULE_ENABLED || HAL_SDRAM_MODULE_ENABLED */
  924. /**
  925. * @}
  926. */
  927. /**
  928. * @}
  929. */
  930. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/