stm32f7xx_ll_fmc.c 40 KB

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