stm32f4xx_ll_fmc.c 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_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/PC Card 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.
  45. * All rights reserved.</center></h2>
  46. *
  47. * This software component is licensed by ST under BSD 3-Clause license,
  48. * the "License"; You may not use this file except in compliance with the
  49. * License. You may obtain a copy of the License at:
  50. * opensource.org/licenses/BSD-3-Clause
  51. *
  52. ******************************************************************************
  53. */
  54. /* Includes ------------------------------------------------------------------*/
  55. #include "stm32f4xx_hal.h"
  56. /** @addtogroup STM32F4xx_HAL_Driver
  57. * @{
  58. */
  59. /** @defgroup FMC_LL FMC Low Layer
  60. * @brief FMC driver modules
  61. * @{
  62. */
  63. #if defined (HAL_SRAM_MODULE_ENABLED) || defined(HAL_NOR_MODULE_ENABLED) || defined(HAL_NAND_MODULE_ENABLED) || defined(HAL_PCCARD_MODULE_ENABLED) || defined(HAL_SDRAM_MODULE_ENABLED)
  64. #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
  65. /* Private typedef -----------------------------------------------------------*/
  66. /* Private define ------------------------------------------------------------*/
  67. /* Private macro -------------------------------------------------------------*/
  68. /* Private variables ---------------------------------------------------------*/
  69. /* Private function prototypes -----------------------------------------------*/
  70. /* Private functions ---------------------------------------------------------*/
  71. /** @addtogroup FMC_LL_Private_Functions
  72. * @{
  73. */
  74. /** @addtogroup FMC_LL_NORSRAM
  75. * @brief NORSRAM Controller functions
  76. *
  77. @verbatim
  78. ==============================================================================
  79. ##### How to use NORSRAM device driver #####
  80. ==============================================================================
  81. [..]
  82. This driver contains a set of APIs to interface with the FMC NORSRAM banks in order
  83. to run the NORSRAM external devices.
  84. (+) FMC NORSRAM bank reset using the function FMC_NORSRAM_DeInit()
  85. (+) FMC NORSRAM bank control configuration using the function FMC_NORSRAM_Init()
  86. (+) FMC NORSRAM bank timing configuration using the function FMC_NORSRAM_Timing_Init()
  87. (+) FMC NORSRAM bank extended timing configuration using the function
  88. FMC_NORSRAM_Extended_Timing_Init()
  89. (+) FMC NORSRAM bank enable/disable write operation using the functions
  90. FMC_NORSRAM_WriteOperation_Enable()/FMC_NORSRAM_WriteOperation_Disable()
  91. @endverbatim
  92. * @{
  93. */
  94. /** @addtogroup FMC_LL_NORSRAM_Private_Functions_Group1
  95. * @brief Initialization and Configuration functions
  96. *
  97. @verbatim
  98. ==============================================================================
  99. ##### Initialization and de_initialization functions #####
  100. ==============================================================================
  101. [..]
  102. This section provides functions allowing to:
  103. (+) Initialize and configure the FMC NORSRAM interface
  104. (+) De-initialize the FMC NORSRAM interface
  105. (+) Configure the FMC clock and associated GPIOs
  106. @endverbatim
  107. * @{
  108. */
  109. /**
  110. * @brief Initialize the FMC_NORSRAM device according to the specified
  111. * control parameters in the FMC_NORSRAM_InitTypeDef
  112. * @param Device Pointer to NORSRAM device instance
  113. * @param Init Pointer to NORSRAM Initialization structure
  114. * @retval HAL status
  115. */
  116. HAL_StatusTypeDef FMC_NORSRAM_Init(FMC_NORSRAM_TypeDef *Device, FMC_NORSRAM_InitTypeDef* Init)
  117. {
  118. uint32_t tmpr = 0U;
  119. /* Check the parameters */
  120. assert_param(IS_FMC_NORSRAM_DEVICE(Device));
  121. assert_param(IS_FMC_NORSRAM_BANK(Init->NSBank));
  122. assert_param(IS_FMC_MUX(Init->DataAddressMux));
  123. assert_param(IS_FMC_MEMORY(Init->MemoryType));
  124. assert_param(IS_FMC_NORSRAM_MEMORY_WIDTH(Init->MemoryDataWidth));
  125. assert_param(IS_FMC_BURSTMODE(Init->BurstAccessMode));
  126. assert_param(IS_FMC_WAIT_POLARITY(Init->WaitSignalPolarity));
  127. #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
  128. assert_param(IS_FMC_WRAP_MODE(Init->WrapMode));
  129. #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
  130. assert_param(IS_FMC_WAIT_SIGNAL_ACTIVE(Init->WaitSignalActive));
  131. assert_param(IS_FMC_WRITE_OPERATION(Init->WriteOperation));
  132. assert_param(IS_FMC_WAITE_SIGNAL(Init->WaitSignal));
  133. assert_param(IS_FMC_EXTENDED_MODE(Init->ExtendedMode));
  134. assert_param(IS_FMC_ASYNWAIT(Init->AsynchronousWait));
  135. assert_param(IS_FMC_WRITE_BURST(Init->WriteBurst));
  136. assert_param(IS_FMC_CONTINOUS_CLOCK(Init->ContinuousClock));
  137. assert_param(IS_FMC_PAGESIZE(Init->PageSize));
  138. #if defined (STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
  139. assert_param(IS_FMC_WRITE_FIFO(Init->WriteFifo));
  140. #endif /* STM32F446xx || STM32F469xx || STM32F479xx */
  141. /* Get the BTCR register value */
  142. tmpr = Device->BTCR[Init->NSBank];
  143. #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
  144. /* Clear MBKEN, MUXEN, MTYP, MWID, FACCEN, BURSTEN, WAITPOL, WRAPMOD, WAITCFG, WREN,
  145. WAITEN, EXTMOD, ASYNCWAIT, CPSIZE, CBURSTRW and CCLKEN bits */
  146. tmpr &= ((uint32_t)~(FMC_BCR1_MBKEN | FMC_BCR1_MUXEN | FMC_BCR1_MTYP | \
  147. FMC_BCR1_MWID | FMC_BCR1_FACCEN | FMC_BCR1_BURSTEN | \
  148. FMC_BCR1_WAITPOL | FMC_BCR1_WRAPMOD | FMC_BCR1_WAITCFG | \
  149. FMC_BCR1_WREN | FMC_BCR1_WAITEN | FMC_BCR1_EXTMOD | \
  150. FMC_BCR1_ASYNCWAIT | FMC_BCR1_CPSIZE | FMC_BCR1_CBURSTRW | \
  151. FMC_BCR1_CCLKEN));
  152. /* Set NORSRAM device control parameters */
  153. tmpr |= (uint32_t)(Init->DataAddressMux |\
  154. Init->MemoryType |\
  155. Init->MemoryDataWidth |\
  156. Init->BurstAccessMode |\
  157. Init->WaitSignalPolarity |\
  158. Init->WrapMode |\
  159. Init->WaitSignalActive |\
  160. Init->WriteOperation |\
  161. Init->WaitSignal |\
  162. Init->ExtendedMode |\
  163. Init->AsynchronousWait |\
  164. Init->PageSize |\
  165. Init->WriteBurst |\
  166. Init->ContinuousClock);
  167. #else /* defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) */
  168. /* Clear MBKEN, MUXEN, MTYP, MWID, FACCEN, BURSTEN, WAITPOL, CPSIZE, WAITCFG, WREN,
  169. WAITEN, EXTMOD, ASYNCWAIT, CBURSTRW, CCLKEN and WFDIS bits */
  170. tmpr &= ((uint32_t)~(FMC_BCR1_MBKEN | FMC_BCR1_MUXEN | FMC_BCR1_MTYP | \
  171. FMC_BCR1_MWID | FMC_BCR1_FACCEN | FMC_BCR1_BURSTEN | \
  172. FMC_BCR1_WAITPOL | FMC_BCR1_WAITCFG | FMC_BCR1_CPSIZE | \
  173. FMC_BCR1_WREN | FMC_BCR1_WAITEN | FMC_BCR1_EXTMOD | \
  174. FMC_BCR1_ASYNCWAIT | FMC_BCR1_CBURSTRW | FMC_BCR1_CCLKEN | \
  175. FMC_BCR1_WFDIS));
  176. /* Set NORSRAM device control parameters */
  177. tmpr |= (uint32_t)(Init->DataAddressMux |\
  178. Init->MemoryType |\
  179. Init->MemoryDataWidth |\
  180. Init->BurstAccessMode |\
  181. Init->WaitSignalPolarity |\
  182. Init->WaitSignalActive |\
  183. Init->WriteOperation |\
  184. Init->WaitSignal |\
  185. Init->ExtendedMode |\
  186. Init->AsynchronousWait |\
  187. Init->WriteBurst |\
  188. Init->ContinuousClock |\
  189. Init->PageSize |\
  190. Init->WriteFifo);
  191. #endif /* defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) */
  192. if(Init->MemoryType == FMC_MEMORY_TYPE_NOR)
  193. {
  194. tmpr |= (uint32_t)FMC_NORSRAM_FLASH_ACCESS_ENABLE;
  195. }
  196. Device->BTCR[Init->NSBank] = tmpr;
  197. /* Configure synchronous mode when Continuous clock is enabled for bank2..4 */
  198. if((Init->ContinuousClock == FMC_CONTINUOUS_CLOCK_SYNC_ASYNC) && (Init->NSBank != FMC_NORSRAM_BANK1))
  199. {
  200. Device->BTCR[FMC_NORSRAM_BANK1] |= (uint32_t)(Init->ContinuousClock);
  201. }
  202. #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
  203. if(Init->NSBank != FMC_NORSRAM_BANK1)
  204. {
  205. Device->BTCR[FMC_NORSRAM_BANK1] |= (uint32_t)(Init->WriteFifo);
  206. }
  207. #endif /* STM32F446xx || STM32F469xx || STM32F479xx */
  208. return HAL_OK;
  209. }
  210. /**
  211. * @brief DeInitialize the FMC_NORSRAM peripheral
  212. * @param Device Pointer to NORSRAM device instance
  213. * @param ExDevice Pointer to NORSRAM extended mode device instance
  214. * @param Bank NORSRAM bank number
  215. * @retval HAL status
  216. */
  217. HAL_StatusTypeDef FMC_NORSRAM_DeInit(FMC_NORSRAM_TypeDef *Device, FMC_NORSRAM_EXTENDED_TypeDef *ExDevice, uint32_t Bank)
  218. {
  219. /* Check the parameters */
  220. assert_param(IS_FMC_NORSRAM_DEVICE(Device));
  221. assert_param(IS_FMC_NORSRAM_EXTENDED_DEVICE(ExDevice));
  222. assert_param(IS_FMC_NORSRAM_BANK(Bank));
  223. /* Disable the FMC_NORSRAM device */
  224. __FMC_NORSRAM_DISABLE(Device, Bank);
  225. /* De-initialize the FMC_NORSRAM device */
  226. /* FMC_NORSRAM_BANK1 */
  227. if(Bank == FMC_NORSRAM_BANK1)
  228. {
  229. Device->BTCR[Bank] = 0x000030DBU;
  230. }
  231. /* FMC_NORSRAM_BANK2, FMC_NORSRAM_BANK3 or FMC_NORSRAM_BANK4 */
  232. else
  233. {
  234. Device->BTCR[Bank] = 0x000030D2U;
  235. }
  236. Device->BTCR[Bank + 1U] = 0x0FFFFFFFU;
  237. ExDevice->BWTR[Bank] = 0x0FFFFFFFU;
  238. return HAL_OK;
  239. }
  240. /**
  241. * @brief Initialize the FMC_NORSRAM Timing according to the specified
  242. * parameters in the FMC_NORSRAM_TimingTypeDef
  243. * @param Device Pointer to NORSRAM device instance
  244. * @param Timing Pointer to NORSRAM Timing structure
  245. * @param Bank NORSRAM bank number
  246. * @retval HAL status
  247. */
  248. HAL_StatusTypeDef FMC_NORSRAM_Timing_Init(FMC_NORSRAM_TypeDef *Device, FMC_NORSRAM_TimingTypeDef *Timing, uint32_t Bank)
  249. {
  250. uint32_t tmpr = 0U;
  251. /* Check the parameters */
  252. assert_param(IS_FMC_NORSRAM_DEVICE(Device));
  253. assert_param(IS_FMC_ADDRESS_SETUP_TIME(Timing->AddressSetupTime));
  254. assert_param(IS_FMC_ADDRESS_HOLD_TIME(Timing->AddressHoldTime));
  255. assert_param(IS_FMC_DATASETUP_TIME(Timing->DataSetupTime));
  256. assert_param(IS_FMC_TURNAROUND_TIME(Timing->BusTurnAroundDuration));
  257. assert_param(IS_FMC_CLK_DIV(Timing->CLKDivision));
  258. assert_param(IS_FMC_DATA_LATENCY(Timing->DataLatency));
  259. assert_param(IS_FMC_ACCESS_MODE(Timing->AccessMode));
  260. assert_param(IS_FMC_NORSRAM_BANK(Bank));
  261. /* Get the BTCR register value */
  262. tmpr = Device->BTCR[Bank + 1U];
  263. /* Clear ADDSET, ADDHLD, DATAST, BUSTURN, CLKDIV, DATLAT and ACCMOD bits */
  264. tmpr &= ((uint32_t)~(FMC_BTR1_ADDSET | FMC_BTR1_ADDHLD | FMC_BTR1_DATAST | \
  265. FMC_BTR1_BUSTURN | FMC_BTR1_CLKDIV | FMC_BTR1_DATLAT | \
  266. FMC_BTR1_ACCMOD));
  267. /* Set FMC_NORSRAM device timing parameters */
  268. tmpr |= (uint32_t)(Timing->AddressSetupTime |\
  269. ((Timing->AddressHoldTime) << 4U) |\
  270. ((Timing->DataSetupTime) << 8U) |\
  271. ((Timing->BusTurnAroundDuration) << 16U) |\
  272. (((Timing->CLKDivision) - 1U) << 20U) |\
  273. (((Timing->DataLatency) - 2U) << 24U) |\
  274. (Timing->AccessMode));
  275. Device->BTCR[Bank + 1U] = tmpr;
  276. /* Configure Clock division value (in NORSRAM bank 1) when continuous clock is enabled */
  277. if(HAL_IS_BIT_SET(Device->BTCR[FMC_NORSRAM_BANK1], FMC_BCR1_CCLKEN))
  278. {
  279. tmpr = (uint32_t)(Device->BTCR[FMC_NORSRAM_BANK1 + 1U] & ~(0x0FU << 20U));
  280. tmpr |= (uint32_t)(((Timing->CLKDivision) - 1U) << 20U);
  281. Device->BTCR[FMC_NORSRAM_BANK1 + 1U] = tmpr;
  282. }
  283. return HAL_OK;
  284. }
  285. /**
  286. * @brief Initialize the FMC_NORSRAM Extended mode Timing according to the specified
  287. * parameters in the FMC_NORSRAM_TimingTypeDef
  288. * @param Device Pointer to NORSRAM device instance
  289. * @param Timing Pointer to NORSRAM Timing structure
  290. * @param Bank NORSRAM bank number
  291. * @retval HAL status
  292. */
  293. HAL_StatusTypeDef FMC_NORSRAM_Extended_Timing_Init(FMC_NORSRAM_EXTENDED_TypeDef *Device, FMC_NORSRAM_TimingTypeDef *Timing, uint32_t Bank, uint32_t ExtendedMode)
  294. {
  295. uint32_t tmpr = 0U;
  296. /* Check the parameters */
  297. assert_param(IS_FMC_EXTENDED_MODE(ExtendedMode));
  298. /* Set NORSRAM device timing register for write configuration, if extended mode is used */
  299. if(ExtendedMode == FMC_EXTENDED_MODE_ENABLE)
  300. {
  301. /* Check the parameters */
  302. assert_param(IS_FMC_NORSRAM_EXTENDED_DEVICE(Device));
  303. assert_param(IS_FMC_ADDRESS_SETUP_TIME(Timing->AddressSetupTime));
  304. assert_param(IS_FMC_ADDRESS_HOLD_TIME(Timing->AddressHoldTime));
  305. assert_param(IS_FMC_DATASETUP_TIME(Timing->DataSetupTime));
  306. assert_param(IS_FMC_TURNAROUND_TIME(Timing->BusTurnAroundDuration));
  307. assert_param(IS_FMC_ACCESS_MODE(Timing->AccessMode));
  308. assert_param(IS_FMC_NORSRAM_BANK(Bank));
  309. /* Get the BWTR register value */
  310. tmpr = Device->BWTR[Bank];
  311. /* Clear ADDSET, ADDHLD, DATAST, BUSTURN and ACCMOD bits */
  312. tmpr &= ((uint32_t)~(FMC_BWTR1_ADDSET | FMC_BWTR1_ADDHLD | FMC_BWTR1_DATAST | \
  313. FMC_BWTR1_BUSTURN | FMC_BWTR1_ACCMOD));
  314. tmpr |= (uint32_t)(Timing->AddressSetupTime |\
  315. ((Timing->AddressHoldTime) << 4U) |\
  316. ((Timing->DataSetupTime) << 8U) |\
  317. ((Timing->BusTurnAroundDuration) << 16U) |\
  318. (Timing->AccessMode));
  319. Device->BWTR[Bank] = tmpr;
  320. }
  321. else
  322. {
  323. Device->BWTR[Bank] = 0x0FFFFFFFU;
  324. }
  325. return HAL_OK;
  326. }
  327. /**
  328. * @}
  329. */
  330. /** @addtogroup FMC_LL_NORSRAM_Private_Functions_Group2
  331. * @brief management functions
  332. *
  333. @verbatim
  334. ==============================================================================
  335. ##### FMC_NORSRAM Control functions #####
  336. ==============================================================================
  337. [..]
  338. This subsection provides a set of functions allowing to control dynamically
  339. the FMC NORSRAM interface.
  340. @endverbatim
  341. * @{
  342. */
  343. /**
  344. * @brief Enables dynamically FMC_NORSRAM write operation.
  345. * @param Device Pointer to NORSRAM device instance
  346. * @param Bank NORSRAM bank number
  347. * @retval HAL status
  348. */
  349. HAL_StatusTypeDef FMC_NORSRAM_WriteOperation_Enable(FMC_NORSRAM_TypeDef *Device, uint32_t Bank)
  350. {
  351. /* Check the parameters */
  352. assert_param(IS_FMC_NORSRAM_DEVICE(Device));
  353. assert_param(IS_FMC_NORSRAM_BANK(Bank));
  354. /* Enable write operation */
  355. Device->BTCR[Bank] |= FMC_WRITE_OPERATION_ENABLE;
  356. return HAL_OK;
  357. }
  358. /**
  359. * @brief Disables dynamically FMC_NORSRAM write operation.
  360. * @param Device Pointer to NORSRAM device instance
  361. * @param Bank NORSRAM bank number
  362. * @retval HAL status
  363. */
  364. HAL_StatusTypeDef FMC_NORSRAM_WriteOperation_Disable(FMC_NORSRAM_TypeDef *Device, uint32_t Bank)
  365. {
  366. /* Check the parameters */
  367. assert_param(IS_FMC_NORSRAM_DEVICE(Device));
  368. assert_param(IS_FMC_NORSRAM_BANK(Bank));
  369. /* Disable write operation */
  370. Device->BTCR[Bank] &= ~FMC_WRITE_OPERATION_ENABLE;
  371. return HAL_OK;
  372. }
  373. /**
  374. * @}
  375. */
  376. /**
  377. * @}
  378. */
  379. /** @addtogroup FMC_LL_NAND
  380. * @brief NAND Controller functions
  381. *
  382. @verbatim
  383. ==============================================================================
  384. ##### How to use NAND device driver #####
  385. ==============================================================================
  386. [..]
  387. This driver contains a set of APIs to interface with the FMC NAND banks in order
  388. to run the NAND external devices.
  389. (+) FMC NAND bank reset using the function FMC_NAND_DeInit()
  390. (+) FMC NAND bank control configuration using the function FMC_NAND_Init()
  391. (+) FMC NAND bank common space timing configuration using the function
  392. FMC_NAND_CommonSpace_Timing_Init()
  393. (+) FMC NAND bank attribute space timing configuration using the function
  394. FMC_NAND_AttributeSpace_Timing_Init()
  395. (+) FMC NAND bank enable/disable ECC correction feature using the functions
  396. FMC_NAND_ECC_Enable()/FMC_NAND_ECC_Disable()
  397. (+) FMC NAND bank get ECC correction code using the function FMC_NAND_GetECC()
  398. @endverbatim
  399. * @{
  400. */
  401. #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
  402. /** @defgroup HAL_FMC_NAND_Group1 Initialization/de-initialization functions
  403. * @brief Initialization and Configuration functions
  404. *
  405. @verbatim
  406. ==============================================================================
  407. ##### Initialization and de_initialization functions #####
  408. ==============================================================================
  409. [..]
  410. This section provides functions allowing to:
  411. (+) Initialize and configure the FMC NAND interface
  412. (+) De-initialize the FMC NAND interface
  413. (+) Configure the FMC clock and associated GPIOs
  414. @endverbatim
  415. * @{
  416. */
  417. /**
  418. * @brief Initializes the FMC_NAND device according to the specified
  419. * control parameters in the FMC_NAND_HandleTypeDef
  420. * @param Device Pointer to NAND device instance
  421. * @param Init Pointer to NAND Initialization structure
  422. * @retval HAL status
  423. */
  424. HAL_StatusTypeDef FMC_NAND_Init(FMC_NAND_TypeDef *Device, FMC_NAND_InitTypeDef *Init)
  425. {
  426. uint32_t tmpr = 0U;
  427. /* Check the parameters */
  428. assert_param(IS_FMC_NAND_DEVICE(Device));
  429. assert_param(IS_FMC_NAND_BANK(Init->NandBank));
  430. assert_param(IS_FMC_WAIT_FEATURE(Init->Waitfeature));
  431. assert_param(IS_FMC_NAND_MEMORY_WIDTH(Init->MemoryDataWidth));
  432. assert_param(IS_FMC_ECC_STATE(Init->EccComputation));
  433. assert_param(IS_FMC_ECCPAGE_SIZE(Init->ECCPageSize));
  434. assert_param(IS_FMC_TCLR_TIME(Init->TCLRSetupTime));
  435. assert_param(IS_FMC_TAR_TIME(Init->TARSetupTime));
  436. /* Get the NAND bank register value */
  437. tmpr = Device->PCR;
  438. /* Clear PWAITEN, PBKEN, PTYP, PWID, ECCEN, TCLR, TAR and ECCPS bits */
  439. tmpr &= ((uint32_t)~(FMC_PCR_PWAITEN | FMC_PCR_PBKEN | FMC_PCR_PTYP | \
  440. FMC_PCR_PWID | FMC_PCR_ECCEN | FMC_PCR_TCLR | \
  441. FMC_PCR_TAR | FMC_PCR_ECCPS));
  442. /* Set NAND device control parameters */
  443. tmpr |= (uint32_t)(Init->Waitfeature |\
  444. FMC_PCR_MEMORY_TYPE_NAND |\
  445. Init->MemoryDataWidth |\
  446. Init->EccComputation |\
  447. Init->ECCPageSize |\
  448. ((Init->TCLRSetupTime) << 9U) |\
  449. ((Init->TARSetupTime) << 13U));
  450. /* NAND bank registers configuration */
  451. Device->PCR = tmpr;
  452. return HAL_OK;
  453. }
  454. /**
  455. * @brief Initializes the FMC_NAND Common space Timing according to the specified
  456. * parameters in the FMC_NAND_PCC_TimingTypeDef
  457. * @param Device Pointer to NAND device instance
  458. * @param Timing Pointer to NAND timing structure
  459. * @param Bank NAND bank number
  460. * @retval HAL status
  461. */
  462. HAL_StatusTypeDef FMC_NAND_CommonSpace_Timing_Init(FMC_NAND_TypeDef *Device, FMC_NAND_PCC_TimingTypeDef *Timing, uint32_t Bank)
  463. {
  464. uint32_t tmpr = 0U;
  465. /* Check the parameters */
  466. assert_param(IS_FMC_NAND_DEVICE(Device));
  467. assert_param(IS_FMC_SETUP_TIME(Timing->SetupTime));
  468. assert_param(IS_FMC_WAIT_TIME(Timing->WaitSetupTime));
  469. assert_param(IS_FMC_HOLD_TIME(Timing->HoldSetupTime));
  470. assert_param(IS_FMC_HIZ_TIME(Timing->HiZSetupTime));
  471. assert_param(IS_FMC_NAND_BANK(Bank));
  472. /* Get the NAND bank 2 register value */
  473. tmpr = Device->PMEM;
  474. /* Clear MEMSETx, MEMWAITx, MEMHOLDx and MEMHIZx bits */
  475. tmpr &= ((uint32_t)~(FMC_PMEM_MEMSET2 | FMC_PMEM_MEMWAIT2 | FMC_PMEM_MEMHOLD2 | \
  476. FMC_PMEM_MEMHIZ2));
  477. /* Set FMC_NAND device timing parameters */
  478. tmpr |= (uint32_t)(Timing->SetupTime |\
  479. ((Timing->WaitSetupTime) << 8U) |\
  480. ((Timing->HoldSetupTime) << 16U) |\
  481. ((Timing->HiZSetupTime) << 24U)
  482. );
  483. /* NAND bank registers configuration */
  484. Device->PMEM = tmpr;
  485. return HAL_OK;
  486. }
  487. /**
  488. * @brief Initializes the FMC_NAND Attribute space Timing according to the specified
  489. * parameters in the FMC_NAND_PCC_TimingTypeDef
  490. * @param Device Pointer to NAND device instance
  491. * @param Timing Pointer to NAND timing structure
  492. * @param Bank NAND bank number
  493. * @retval HAL status
  494. */
  495. HAL_StatusTypeDef FMC_NAND_AttributeSpace_Timing_Init(FMC_NAND_TypeDef *Device, FMC_NAND_PCC_TimingTypeDef *Timing, uint32_t Bank)
  496. {
  497. uint32_t tmpr = 0U;
  498. /* Check the parameters */
  499. assert_param(IS_FMC_NAND_DEVICE(Device));
  500. assert_param(IS_FMC_SETUP_TIME(Timing->SetupTime));
  501. assert_param(IS_FMC_WAIT_TIME(Timing->WaitSetupTime));
  502. assert_param(IS_FMC_HOLD_TIME(Timing->HoldSetupTime));
  503. assert_param(IS_FMC_HIZ_TIME(Timing->HiZSetupTime));
  504. assert_param(IS_FMC_NAND_BANK(Bank));
  505. /* Get the NAND bank register value */
  506. tmpr = Device->PATT;
  507. /* Clear ATTSETx, ATTWAITx, ATTHOLDx and ATTHIZx bits */
  508. tmpr &= ((uint32_t)~(FMC_PATT_ATTSET2 | FMC_PATT_ATTWAIT2 | FMC_PATT_ATTHOLD2 | \
  509. FMC_PATT_ATTHIZ2));
  510. /* Set FMC_NAND device timing parameters */
  511. tmpr |= (uint32_t)(Timing->SetupTime |\
  512. ((Timing->WaitSetupTime) << 8U) |\
  513. ((Timing->HoldSetupTime) << 16U) |\
  514. ((Timing->HiZSetupTime) << 24U));
  515. /* NAND bank registers configuration */
  516. Device->PATT = tmpr;
  517. return HAL_OK;
  518. }
  519. /**
  520. * @brief DeInitializes the FMC_NAND device
  521. * @param Device Pointer to NAND device instance
  522. * @param Bank NAND bank number
  523. * @retval HAL status
  524. */
  525. HAL_StatusTypeDef FMC_NAND_DeInit(FMC_NAND_TypeDef *Device, uint32_t Bank)
  526. {
  527. /* Check the parameters */
  528. assert_param(IS_FMC_NAND_DEVICE(Device));
  529. assert_param(IS_FMC_NAND_BANK(Bank));
  530. /* Disable the NAND Bank */
  531. __FMC_NAND_DISABLE(Device, Bank);
  532. /* De-initialize the NAND Bank */
  533. /* Set the FMC_NAND_BANK registers to their reset values */
  534. Device->PCR = 0x00000018U;
  535. Device->SR = 0x00000040U;
  536. Device->PMEM = 0xFCFCFCFCU;
  537. Device->PATT = 0xFCFCFCFCU;
  538. return HAL_OK;
  539. }
  540. /**
  541. * @}
  542. */
  543. /** @defgroup HAL_FMC_NAND_Group2 Control functions
  544. * @brief management functions
  545. *
  546. @verbatim
  547. ==============================================================================
  548. ##### FMC_NAND Control functions #####
  549. ==============================================================================
  550. [..]
  551. This subsection provides a set of functions allowing to control dynamically
  552. the FMC NAND interface.
  553. @endverbatim
  554. * @{
  555. */
  556. /**
  557. * @brief Enables dynamically FMC_NAND ECC feature.
  558. * @param Device Pointer to NAND device instance
  559. * @param Bank NAND bank number
  560. * @retval HAL status
  561. */
  562. HAL_StatusTypeDef FMC_NAND_ECC_Enable(FMC_NAND_TypeDef *Device, uint32_t Bank)
  563. {
  564. /* Check the parameters */
  565. assert_param(IS_FMC_NAND_DEVICE(Device));
  566. assert_param(IS_FMC_NAND_BANK(Bank));
  567. /* Enable ECC feature */
  568. Device->PCR |= FMC_PCR_ECCEN;
  569. return HAL_OK;
  570. }
  571. /**
  572. * @brief Disables dynamically FMC_NAND ECC feature.
  573. * @param Device Pointer to NAND device instance
  574. * @param Bank NAND bank number
  575. * @retval HAL status
  576. */
  577. HAL_StatusTypeDef FMC_NAND_ECC_Disable(FMC_NAND_TypeDef *Device, uint32_t Bank)
  578. {
  579. /* Check the parameters */
  580. assert_param(IS_FMC_NAND_DEVICE(Device));
  581. assert_param(IS_FMC_NAND_BANK(Bank));
  582. /* Disable ECC feature */
  583. Device->PCR &= ~FMC_PCR_ECCEN;
  584. return HAL_OK;
  585. }
  586. /**
  587. * @brief Disables dynamically FMC_NAND ECC feature.
  588. * @param Device Pointer to NAND device instance
  589. * @param ECCval Pointer to ECC value
  590. * @param Bank NAND bank number
  591. * @param Timeout Timeout wait value
  592. * @retval HAL status
  593. */
  594. HAL_StatusTypeDef FMC_NAND_GetECC(FMC_NAND_TypeDef *Device, uint32_t *ECCval, uint32_t Bank, uint32_t Timeout)
  595. {
  596. uint32_t tickstart = 0U;
  597. /* Check the parameters */
  598. assert_param(IS_FMC_NAND_DEVICE(Device));
  599. assert_param(IS_FMC_NAND_BANK(Bank));
  600. /* Get tick */
  601. tickstart = HAL_GetTick();
  602. /* Wait until FIFO is empty */
  603. while(__FMC_NAND_GET_FLAG(Device, Bank, FMC_FLAG_FEMPT) == RESET)
  604. {
  605. /* Check for the Timeout */
  606. if(Timeout != HAL_MAX_DELAY)
  607. {
  608. if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout))
  609. {
  610. return HAL_TIMEOUT;
  611. }
  612. }
  613. }
  614. /* Get the ECCR register value */
  615. *ECCval = (uint32_t)Device->ECCR;
  616. return HAL_OK;
  617. }
  618. /**
  619. * @}
  620. */
  621. #else /* defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) */
  622. /** @defgroup HAL_FMC_NAND_Group1 Initialization/de-initialization functions
  623. * @brief Initialization and Configuration functions
  624. *
  625. @verbatim
  626. ==============================================================================
  627. ##### Initialization and de_initialization functions #####
  628. ==============================================================================
  629. [..]
  630. This section provides functions allowing to:
  631. (+) Initialize and configure the FMC NAND interface
  632. (+) De-initialize the FMC NAND interface
  633. (+) Configure the FMC clock and associated GPIOs
  634. @endverbatim
  635. * @{
  636. */
  637. /**
  638. * @brief Initializes the FMC_NAND device according to the specified
  639. * control parameters in the FMC_NAND_HandleTypeDef
  640. * @param Device Pointer to NAND device instance
  641. * @param Init Pointer to NAND Initialization structure
  642. * @retval HAL status
  643. */
  644. HAL_StatusTypeDef FMC_NAND_Init(FMC_NAND_TypeDef *Device, FMC_NAND_InitTypeDef *Init)
  645. {
  646. uint32_t tmpr = 0U;
  647. /* Check the parameters */
  648. assert_param(IS_FMC_NAND_DEVICE(Device));
  649. assert_param(IS_FMC_NAND_BANK(Init->NandBank));
  650. assert_param(IS_FMC_WAIT_FEATURE(Init->Waitfeature));
  651. assert_param(IS_FMC_NAND_MEMORY_WIDTH(Init->MemoryDataWidth));
  652. assert_param(IS_FMC_ECC_STATE(Init->EccComputation));
  653. assert_param(IS_FMC_ECCPAGE_SIZE(Init->ECCPageSize));
  654. assert_param(IS_FMC_TCLR_TIME(Init->TCLRSetupTime));
  655. assert_param(IS_FMC_TAR_TIME(Init->TARSetupTime));
  656. if(Init->NandBank == FMC_NAND_BANK2)
  657. {
  658. /* Get the NAND bank 2 register value */
  659. tmpr = Device->PCR2;
  660. }
  661. else
  662. {
  663. /* Get the NAND bank 3 register value */
  664. tmpr = Device->PCR3;
  665. }
  666. /* Clear PWAITEN, PBKEN, PTYP, PWID, ECCEN, TCLR, TAR and ECCPS bits */
  667. tmpr &= ((uint32_t)~(FMC_PCR2_PWAITEN | FMC_PCR2_PBKEN | FMC_PCR2_PTYP | \
  668. FMC_PCR2_PWID | FMC_PCR2_ECCEN | FMC_PCR2_TCLR | \
  669. FMC_PCR2_TAR | FMC_PCR2_ECCPS));
  670. /* Set NAND device control parameters */
  671. tmpr |= (uint32_t)(Init->Waitfeature |\
  672. FMC_PCR_MEMORY_TYPE_NAND |\
  673. Init->MemoryDataWidth |\
  674. Init->EccComputation |\
  675. Init->ECCPageSize |\
  676. ((Init->TCLRSetupTime) << 9U) |\
  677. ((Init->TARSetupTime) << 13U));
  678. if(Init->NandBank == FMC_NAND_BANK2)
  679. {
  680. /* NAND bank 2 registers configuration */
  681. Device->PCR2 = tmpr;
  682. }
  683. else
  684. {
  685. /* NAND bank 3 registers configuration */
  686. Device->PCR3 = tmpr;
  687. }
  688. return HAL_OK;
  689. }
  690. /**
  691. * @brief Initializes the FMC_NAND Common space Timing according to the specified
  692. * parameters in the FMC_NAND_PCC_TimingTypeDef
  693. * @param Device Pointer to NAND device instance
  694. * @param Timing Pointer to NAND timing structure
  695. * @param Bank NAND bank number
  696. * @retval HAL status
  697. */
  698. HAL_StatusTypeDef FMC_NAND_CommonSpace_Timing_Init(FMC_NAND_TypeDef *Device, FMC_NAND_PCC_TimingTypeDef *Timing, uint32_t Bank)
  699. {
  700. uint32_t tmpr = 0U;
  701. /* Check the parameters */
  702. assert_param(IS_FMC_NAND_DEVICE(Device));
  703. assert_param(IS_FMC_SETUP_TIME(Timing->SetupTime));
  704. assert_param(IS_FMC_WAIT_TIME(Timing->WaitSetupTime));
  705. assert_param(IS_FMC_HOLD_TIME(Timing->HoldSetupTime));
  706. assert_param(IS_FMC_HIZ_TIME(Timing->HiZSetupTime));
  707. assert_param(IS_FMC_NAND_BANK(Bank));
  708. if(Bank == FMC_NAND_BANK2)
  709. {
  710. /* Get the NAND bank 2 register value */
  711. tmpr = Device->PMEM2;
  712. }
  713. else
  714. {
  715. /* Get the NAND bank 3 register value */
  716. tmpr = Device->PMEM3;
  717. }
  718. /* Clear MEMSETx, MEMWAITx, MEMHOLDx and MEMHIZx bits */
  719. tmpr &= ((uint32_t)~(FMC_PMEM2_MEMSET2 | FMC_PMEM2_MEMWAIT2 | FMC_PMEM2_MEMHOLD2 | \
  720. FMC_PMEM2_MEMHIZ2));
  721. /* Set FMC_NAND device timing parameters */
  722. tmpr |= (uint32_t)(Timing->SetupTime |\
  723. ((Timing->WaitSetupTime) << 8U) |\
  724. ((Timing->HoldSetupTime) << 16U) |\
  725. ((Timing->HiZSetupTime) << 24U)
  726. );
  727. if(Bank == FMC_NAND_BANK2)
  728. {
  729. /* NAND bank 2 registers configuration */
  730. Device->PMEM2 = tmpr;
  731. }
  732. else
  733. {
  734. /* NAND bank 3 registers configuration */
  735. Device->PMEM3 = tmpr;
  736. }
  737. return HAL_OK;
  738. }
  739. /**
  740. * @brief Initializes the FMC_NAND Attribute space Timing according to the specified
  741. * parameters in the FMC_NAND_PCC_TimingTypeDef
  742. * @param Device Pointer to NAND device instance
  743. * @param Timing Pointer to NAND timing structure
  744. * @param Bank NAND bank number
  745. * @retval HAL status
  746. */
  747. HAL_StatusTypeDef FMC_NAND_AttributeSpace_Timing_Init(FMC_NAND_TypeDef *Device, FMC_NAND_PCC_TimingTypeDef *Timing, uint32_t Bank)
  748. {
  749. uint32_t tmpr = 0U;
  750. /* Check the parameters */
  751. assert_param(IS_FMC_NAND_DEVICE(Device));
  752. assert_param(IS_FMC_SETUP_TIME(Timing->SetupTime));
  753. assert_param(IS_FMC_WAIT_TIME(Timing->WaitSetupTime));
  754. assert_param(IS_FMC_HOLD_TIME(Timing->HoldSetupTime));
  755. assert_param(IS_FMC_HIZ_TIME(Timing->HiZSetupTime));
  756. assert_param(IS_FMC_NAND_BANK(Bank));
  757. if(Bank == FMC_NAND_BANK2)
  758. {
  759. /* Get the NAND bank 2 register value */
  760. tmpr = Device->PATT2;
  761. }
  762. else
  763. {
  764. /* Get the NAND bank 3 register value */
  765. tmpr = Device->PATT3;
  766. }
  767. /* Clear ATTSETx, ATTWAITx, ATTHOLDx and ATTHIZx bits */
  768. tmpr &= ((uint32_t)~(FMC_PATT2_ATTSET2 | FMC_PATT2_ATTWAIT2 | FMC_PATT2_ATTHOLD2 | \
  769. FMC_PATT2_ATTHIZ2));
  770. /* Set FMC_NAND device timing parameters */
  771. tmpr |= (uint32_t)(Timing->SetupTime |\
  772. ((Timing->WaitSetupTime) << 8U) |\
  773. ((Timing->HoldSetupTime) << 16U) |\
  774. ((Timing->HiZSetupTime) << 24U));
  775. if(Bank == FMC_NAND_BANK2)
  776. {
  777. /* NAND bank 2 registers configuration */
  778. Device->PATT2 = tmpr;
  779. }
  780. else
  781. {
  782. /* NAND bank 3 registers configuration */
  783. Device->PATT3 = tmpr;
  784. }
  785. return HAL_OK;
  786. }
  787. /**
  788. * @brief DeInitializes the FMC_NAND device
  789. * @param Device Pointer to NAND device instance
  790. * @param Bank NAND bank number
  791. * @retval HAL status
  792. */
  793. HAL_StatusTypeDef FMC_NAND_DeInit(FMC_NAND_TypeDef *Device, uint32_t Bank)
  794. {
  795. /* Check the parameters */
  796. assert_param(IS_FMC_NAND_DEVICE(Device));
  797. assert_param(IS_FMC_NAND_BANK(Bank));
  798. /* Disable the NAND Bank */
  799. __FMC_NAND_DISABLE(Device, Bank);
  800. /* De-initialize the NAND Bank */
  801. if(Bank == FMC_NAND_BANK2)
  802. {
  803. /* Set the FMC_NAND_BANK2 registers to their reset values */
  804. Device->PCR2 = 0x00000018U;
  805. Device->SR2 = 0x00000040U;
  806. Device->PMEM2 = 0xFCFCFCFCU;
  807. Device->PATT2 = 0xFCFCFCFCU;
  808. }
  809. /* FMC_Bank3_NAND */
  810. else
  811. {
  812. /* Set the FMC_NAND_BANK3 registers to their reset values */
  813. Device->PCR3 = 0x00000018U;
  814. Device->SR3 = 0x00000040U;
  815. Device->PMEM3 = 0xFCFCFCFCU;
  816. Device->PATT3 = 0xFCFCFCFCU;
  817. }
  818. return HAL_OK;
  819. }
  820. /**
  821. * @}
  822. */
  823. /** @addtogroup FMC_LL_NAND_Private_Functions_Group2
  824. * @brief management functions
  825. *
  826. @verbatim
  827. ==============================================================================
  828. ##### FMC_NAND Control functions #####
  829. ==============================================================================
  830. [..]
  831. This subsection provides a set of functions allowing to control dynamically
  832. the FMC NAND interface.
  833. @endverbatim
  834. * @{
  835. */
  836. /**
  837. * @brief Enables dynamically FMC_NAND ECC feature.
  838. * @param Device Pointer to NAND device instance
  839. * @param Bank NAND bank number
  840. * @retval HAL status
  841. */
  842. HAL_StatusTypeDef FMC_NAND_ECC_Enable(FMC_NAND_TypeDef *Device, uint32_t Bank)
  843. {
  844. /* Check the parameters */
  845. assert_param(IS_FMC_NAND_DEVICE(Device));
  846. assert_param(IS_FMC_NAND_BANK(Bank));
  847. /* Enable ECC feature */
  848. if(Bank == FMC_NAND_BANK2)
  849. {
  850. Device->PCR2 |= FMC_PCR2_ECCEN;
  851. }
  852. else
  853. {
  854. Device->PCR3 |= FMC_PCR3_ECCEN;
  855. }
  856. return HAL_OK;
  857. }
  858. /**
  859. * @brief Disables dynamically FMC_NAND ECC feature.
  860. * @param Device Pointer to NAND device instance
  861. * @param Bank NAND bank number
  862. * @retval HAL status
  863. */
  864. HAL_StatusTypeDef FMC_NAND_ECC_Disable(FMC_NAND_TypeDef *Device, uint32_t Bank)
  865. {
  866. /* Check the parameters */
  867. assert_param(IS_FMC_NAND_DEVICE(Device));
  868. assert_param(IS_FMC_NAND_BANK(Bank));
  869. /* Disable ECC feature */
  870. if(Bank == FMC_NAND_BANK2)
  871. {
  872. Device->PCR2 &= ~FMC_PCR2_ECCEN;
  873. }
  874. else
  875. {
  876. Device->PCR3 &= ~FMC_PCR3_ECCEN;
  877. }
  878. return HAL_OK;
  879. }
  880. /**
  881. * @brief Disables dynamically FMC_NAND ECC feature.
  882. * @param Device Pointer to NAND device instance
  883. * @param ECCval Pointer to ECC value
  884. * @param Bank NAND bank number
  885. * @param Timeout Timeout wait value
  886. * @retval HAL status
  887. */
  888. HAL_StatusTypeDef FMC_NAND_GetECC(FMC_NAND_TypeDef *Device, uint32_t *ECCval, uint32_t Bank, uint32_t Timeout)
  889. {
  890. uint32_t tickstart = 0U;
  891. /* Check the parameters */
  892. assert_param(IS_FMC_NAND_DEVICE(Device));
  893. assert_param(IS_FMC_NAND_BANK(Bank));
  894. /* Get tick */
  895. tickstart = HAL_GetTick();
  896. /* Wait until FIFO is empty */
  897. while(__FMC_NAND_GET_FLAG(Device, Bank, FMC_FLAG_FEMPT) == RESET)
  898. {
  899. /* Check for the Timeout */
  900. if(Timeout != HAL_MAX_DELAY)
  901. {
  902. if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout))
  903. {
  904. return HAL_TIMEOUT;
  905. }
  906. }
  907. }
  908. if(Bank == FMC_NAND_BANK2)
  909. {
  910. /* Get the ECCR2 register value */
  911. *ECCval = (uint32_t)Device->ECCR2;
  912. }
  913. else
  914. {
  915. /* Get the ECCR3 register value */
  916. *ECCval = (uint32_t)Device->ECCR3;
  917. }
  918. return HAL_OK;
  919. }
  920. /**
  921. * @}
  922. */
  923. #endif /* defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) */
  924. /**
  925. * @}
  926. */
  927. #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
  928. /** @addtogroup FMC_LL_PCCARD
  929. * @brief PCCARD Controller functions
  930. *
  931. @verbatim
  932. ==============================================================================
  933. ##### How to use PCCARD device driver #####
  934. ==============================================================================
  935. [..]
  936. This driver contains a set of APIs to interface with the FMC PCCARD bank in order
  937. to run the PCCARD/compact flash external devices.
  938. (+) FMC PCCARD bank reset using the function FMC_PCCARD_DeInit()
  939. (+) FMC PCCARD bank control configuration using the function FMC_PCCARD_Init()
  940. (+) FMC PCCARD bank common space timing configuration using the function
  941. FMC_PCCARD_CommonSpace_Timing_Init()
  942. (+) FMC PCCARD bank attribute space timing configuration using the function
  943. FMC_PCCARD_AttributeSpace_Timing_Init()
  944. (+) FMC PCCARD bank IO space timing configuration using the function
  945. FMC_PCCARD_IOSpace_Timing_Init()
  946. @endverbatim
  947. * @{
  948. */
  949. /** @addtogroup FMC_LL_PCCARD_Private_Functions_Group1
  950. * @brief Initialization and Configuration functions
  951. *
  952. @verbatim
  953. ==============================================================================
  954. ##### Initialization and de_initialization functions #####
  955. ==============================================================================
  956. [..]
  957. This section provides functions allowing to:
  958. (+) Initialize and configure the FMC PCCARD interface
  959. (+) De-initialize the FMC PCCARD interface
  960. (+) Configure the FMC clock and associated GPIOs
  961. @endverbatim
  962. * @{
  963. */
  964. /**
  965. * @brief Initializes the FMC_PCCARD device according to the specified
  966. * control parameters in the FMC_PCCARD_HandleTypeDef
  967. * @param Device Pointer to PCCARD device instance
  968. * @param Init Pointer to PCCARD Initialization structure
  969. * @retval HAL status
  970. */
  971. HAL_StatusTypeDef FMC_PCCARD_Init(FMC_PCCARD_TypeDef *Device, FMC_PCCARD_InitTypeDef *Init)
  972. {
  973. uint32_t tmpr = 0U;
  974. /* Check the parameters */
  975. assert_param(IS_FMC_PCCARD_DEVICE(Device));
  976. assert_param(IS_FMC_WAIT_FEATURE(Init->Waitfeature));
  977. assert_param(IS_FMC_TCLR_TIME(Init->TCLRSetupTime));
  978. assert_param(IS_FMC_TAR_TIME(Init->TARSetupTime));
  979. /* Get PCCARD control register value */
  980. tmpr = Device->PCR4;
  981. /* Clear TAR, TCLR, PWAITEN and PWID bits */
  982. tmpr &= ((uint32_t)~(FMC_PCR4_TAR | FMC_PCR4_TCLR | FMC_PCR4_PWAITEN | \
  983. FMC_PCR4_PWID | FMC_PCR4_PTYP));
  984. /* Set FMC_PCCARD device control parameters */
  985. tmpr |= (uint32_t)(Init->Waitfeature |\
  986. FMC_NAND_PCC_MEM_BUS_WIDTH_16 |\
  987. (Init->TCLRSetupTime << 9U) |\
  988. (Init->TARSetupTime << 13U));
  989. Device->PCR4 = tmpr;
  990. return HAL_OK;
  991. }
  992. /**
  993. * @brief Initializes the FMC_PCCARD Common space Timing according to the specified
  994. * parameters in the FMC_NAND_PCC_TimingTypeDef
  995. * @param Device Pointer to PCCARD device instance
  996. * @param Timing Pointer to PCCARD timing structure
  997. * @retval HAL status
  998. */
  999. HAL_StatusTypeDef FMC_PCCARD_CommonSpace_Timing_Init(FMC_PCCARD_TypeDef *Device, FMC_NAND_PCC_TimingTypeDef *Timing)
  1000. {
  1001. uint32_t tmpr = 0U;
  1002. /* Check the parameters */
  1003. assert_param(IS_FMC_PCCARD_DEVICE(Device));
  1004. assert_param(IS_FMC_SETUP_TIME(Timing->SetupTime));
  1005. assert_param(IS_FMC_WAIT_TIME(Timing->WaitSetupTime));
  1006. assert_param(IS_FMC_HOLD_TIME(Timing->HoldSetupTime));
  1007. assert_param(IS_FMC_HIZ_TIME(Timing->HiZSetupTime));
  1008. /* Get PCCARD common space timing register value */
  1009. tmpr = Device->PMEM4;
  1010. /* Clear MEMSETx, MEMWAITx, MEMHOLDx and MEMHIZx bits */
  1011. tmpr &= ((uint32_t)~(FMC_PMEM4_MEMSET4 | FMC_PMEM4_MEMWAIT4 | FMC_PMEM4_MEMHOLD4 | \
  1012. FMC_PMEM4_MEMHIZ4));
  1013. /* Set PCCARD timing parameters */
  1014. tmpr |= (uint32_t)(Timing->SetupTime |\
  1015. ((Timing->WaitSetupTime) << 8U) |\
  1016. ((Timing->HoldSetupTime) << 16U) |\
  1017. ((Timing->HiZSetupTime) << 24U));
  1018. Device->PMEM4 = tmpr;
  1019. return HAL_OK;
  1020. }
  1021. /**
  1022. * @brief Initializes the FMC_PCCARD Attribute space Timing according to the specified
  1023. * parameters in the FMC_NAND_PCC_TimingTypeDef
  1024. * @param Device Pointer to PCCARD device instance
  1025. * @param Timing Pointer to PCCARD timing structure
  1026. * @retval HAL status
  1027. */
  1028. HAL_StatusTypeDef FMC_PCCARD_AttributeSpace_Timing_Init(FMC_PCCARD_TypeDef *Device, FMC_NAND_PCC_TimingTypeDef *Timing)
  1029. {
  1030. uint32_t tmpr = 0U;
  1031. /* Check the parameters */
  1032. assert_param(IS_FMC_PCCARD_DEVICE(Device));
  1033. assert_param(IS_FMC_SETUP_TIME(Timing->SetupTime));
  1034. assert_param(IS_FMC_WAIT_TIME(Timing->WaitSetupTime));
  1035. assert_param(IS_FMC_HOLD_TIME(Timing->HoldSetupTime));
  1036. assert_param(IS_FMC_HIZ_TIME(Timing->HiZSetupTime));
  1037. /* Get PCCARD timing parameters */
  1038. tmpr = Device->PATT4;
  1039. /* Clear ATTSETx, ATTWAITx, ATTHOLDx and ATTHIZx bits */
  1040. tmpr &= ((uint32_t)~(FMC_PATT4_ATTSET4 | FMC_PATT4_ATTWAIT4 | FMC_PATT4_ATTHOLD4 | \
  1041. FMC_PATT4_ATTHIZ4));
  1042. /* Set PCCARD timing parameters */
  1043. tmpr |= (uint32_t)(Timing->SetupTime |\
  1044. ((Timing->WaitSetupTime) << 8U) |\
  1045. ((Timing->HoldSetupTime) << 16U) |\
  1046. ((Timing->HiZSetupTime) << 24U));
  1047. Device->PATT4 = tmpr;
  1048. return HAL_OK;
  1049. }
  1050. /**
  1051. * @brief Initializes the FMC_PCCARD IO space Timing according to the specified
  1052. * parameters in the FMC_NAND_PCC_TimingTypeDef
  1053. * @param Device Pointer to PCCARD device instance
  1054. * @param Timing Pointer to PCCARD timing structure
  1055. * @retval HAL status
  1056. */
  1057. HAL_StatusTypeDef FMC_PCCARD_IOSpace_Timing_Init(FMC_PCCARD_TypeDef *Device, FMC_NAND_PCC_TimingTypeDef *Timing)
  1058. {
  1059. uint32_t tmpr = 0;
  1060. /* Check the parameters */
  1061. assert_param(IS_FMC_PCCARD_DEVICE(Device));
  1062. assert_param(IS_FMC_SETUP_TIME(Timing->SetupTime));
  1063. assert_param(IS_FMC_WAIT_TIME(Timing->WaitSetupTime));
  1064. assert_param(IS_FMC_HOLD_TIME(Timing->HoldSetupTime));
  1065. assert_param(IS_FMC_HIZ_TIME(Timing->HiZSetupTime));
  1066. /* Get FMC_PCCARD device timing parameters */
  1067. tmpr = Device->PIO4;
  1068. /* Clear IOSET4, IOWAIT4, IOHOLD4 and IOHIZ4 bits */
  1069. tmpr &= ((uint32_t)~(FMC_PIO4_IOSET4 | FMC_PIO4_IOWAIT4 | FMC_PIO4_IOHOLD4 | \
  1070. FMC_PIO4_IOHIZ4));
  1071. /* Set FMC_PCCARD device timing parameters */
  1072. tmpr |= (uint32_t)(Timing->SetupTime |\
  1073. ((Timing->WaitSetupTime) << 8U) |\
  1074. ((Timing->HoldSetupTime) << 16U) |\
  1075. ((Timing->HiZSetupTime) << 24U));
  1076. Device->PIO4 = tmpr;
  1077. return HAL_OK;
  1078. }
  1079. /**
  1080. * @brief DeInitializes the FMC_PCCARD device
  1081. * @param Device Pointer to PCCARD device instance
  1082. * @retval HAL status
  1083. */
  1084. HAL_StatusTypeDef FMC_PCCARD_DeInit(FMC_PCCARD_TypeDef *Device)
  1085. {
  1086. /* Check the parameters */
  1087. assert_param(IS_FMC_PCCARD_DEVICE(Device));
  1088. /* Disable the FMC_PCCARD device */
  1089. __FMC_PCCARD_DISABLE(Device);
  1090. /* De-initialize the FMC_PCCARD device */
  1091. Device->PCR4 = 0x00000018U;
  1092. Device->SR4 = 0x00000000U;
  1093. Device->PMEM4 = 0xFCFCFCFCU;
  1094. Device->PATT4 = 0xFCFCFCFCU;
  1095. Device->PIO4 = 0xFCFCFCFCU;
  1096. return HAL_OK;
  1097. }
  1098. /**
  1099. * @}
  1100. */
  1101. #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
  1102. /** @addtogroup FMC_LL_SDRAM
  1103. * @brief SDRAM Controller functions
  1104. *
  1105. @verbatim
  1106. ==============================================================================
  1107. ##### How to use SDRAM device driver #####
  1108. ==============================================================================
  1109. [..]
  1110. This driver contains a set of APIs to interface with the FMC SDRAM banks in order
  1111. to run the SDRAM external devices.
  1112. (+) FMC SDRAM bank reset using the function FMC_SDRAM_DeInit()
  1113. (+) FMC SDRAM bank control configuration using the function FMC_SDRAM_Init()
  1114. (+) FMC SDRAM bank timing configuration using the function FMC_SDRAM_Timing_Init()
  1115. (+) FMC SDRAM bank enable/disable write operation using the functions
  1116. FMC_SDRAM_WriteOperation_Enable()/FMC_SDRAM_WriteOperation_Disable()
  1117. (+) FMC SDRAM bank send command using the function FMC_SDRAM_SendCommand()
  1118. @endverbatim
  1119. * @{
  1120. */
  1121. /** @addtogroup FMC_LL_SDRAM_Private_Functions_Group1
  1122. * @brief Initialization and Configuration functions
  1123. *
  1124. @verbatim
  1125. ==============================================================================
  1126. ##### Initialization and de_initialization functions #####
  1127. ==============================================================================
  1128. [..]
  1129. This section provides functions allowing to:
  1130. (+) Initialize and configure the FMC SDRAM interface
  1131. (+) De-initialize the FMC SDRAM interface
  1132. (+) Configure the FMC clock and associated GPIOs
  1133. @endverbatim
  1134. * @{
  1135. */
  1136. /**
  1137. * @brief Initializes the FMC_SDRAM device according to the specified
  1138. * control parameters in the FMC_SDRAM_InitTypeDef
  1139. * @param Device Pointer to SDRAM device instance
  1140. * @param Init Pointer to SDRAM Initialization structure
  1141. * @retval HAL status
  1142. */
  1143. HAL_StatusTypeDef FMC_SDRAM_Init(FMC_SDRAM_TypeDef *Device, FMC_SDRAM_InitTypeDef *Init)
  1144. {
  1145. uint32_t tmpr1 = 0U;
  1146. uint32_t tmpr2 = 0U;
  1147. /* Check the parameters */
  1148. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  1149. assert_param(IS_FMC_SDRAM_BANK(Init->SDBank));
  1150. assert_param(IS_FMC_COLUMNBITS_NUMBER(Init->ColumnBitsNumber));
  1151. assert_param(IS_FMC_ROWBITS_NUMBER(Init->RowBitsNumber));
  1152. assert_param(IS_FMC_SDMEMORY_WIDTH(Init->MemoryDataWidth));
  1153. assert_param(IS_FMC_INTERNALBANK_NUMBER(Init->InternalBankNumber));
  1154. assert_param(IS_FMC_CAS_LATENCY(Init->CASLatency));
  1155. assert_param(IS_FMC_WRITE_PROTECTION(Init->WriteProtection));
  1156. assert_param(IS_FMC_SDCLOCK_PERIOD(Init->SDClockPeriod));
  1157. assert_param(IS_FMC_READ_BURST(Init->ReadBurst));
  1158. assert_param(IS_FMC_READPIPE_DELAY(Init->ReadPipeDelay));
  1159. /* Set SDRAM bank configuration parameters */
  1160. if (Init->SDBank != FMC_SDRAM_BANK2)
  1161. {
  1162. tmpr1 = Device->SDCR[FMC_SDRAM_BANK1];
  1163. /* Clear NC, NR, MWID, NB, CAS, WP, SDCLK, RBURST, and RPIPE bits */
  1164. tmpr1 &= ((uint32_t)~(FMC_SDCR1_NC | FMC_SDCR1_NR | FMC_SDCR1_MWID | \
  1165. FMC_SDCR1_NB | FMC_SDCR1_CAS | FMC_SDCR1_WP | \
  1166. FMC_SDCR1_SDCLK | FMC_SDCR1_RBURST | FMC_SDCR1_RPIPE));
  1167. tmpr1 |= (uint32_t)(Init->ColumnBitsNumber |\
  1168. Init->RowBitsNumber |\
  1169. Init->MemoryDataWidth |\
  1170. Init->InternalBankNumber |\
  1171. Init->CASLatency |\
  1172. Init->WriteProtection |\
  1173. Init->SDClockPeriod |\
  1174. Init->ReadBurst |\
  1175. Init->ReadPipeDelay
  1176. );
  1177. Device->SDCR[FMC_SDRAM_BANK1] = tmpr1;
  1178. }
  1179. else /* FMC_Bank2_SDRAM */
  1180. {
  1181. tmpr1 = Device->SDCR[FMC_SDRAM_BANK1];
  1182. /* Clear NC, NR, MWID, NB, CAS, WP, SDCLK, RBURST, and RPIPE bits */
  1183. tmpr1 &= ((uint32_t)~(FMC_SDCR1_SDCLK | FMC_SDCR1_RBURST | FMC_SDCR1_RPIPE));
  1184. tmpr1 |= (uint32_t)(Init->SDClockPeriod |\
  1185. Init->ReadBurst |\
  1186. Init->ReadPipeDelay);
  1187. tmpr2 = Device->SDCR[FMC_SDRAM_BANK2];
  1188. /* Clear NC, NR, MWID, NB, CAS, WP, SDCLK, RBURST, and RPIPE bits */
  1189. tmpr2 &= ((uint32_t)~(FMC_SDCR1_NC | FMC_SDCR1_NR | FMC_SDCR1_MWID | \
  1190. FMC_SDCR1_NB | FMC_SDCR1_CAS | FMC_SDCR1_WP | \
  1191. FMC_SDCR1_SDCLK | FMC_SDCR1_RBURST | FMC_SDCR1_RPIPE));
  1192. tmpr2 |= (uint32_t)(Init->ColumnBitsNumber |\
  1193. Init->RowBitsNumber |\
  1194. Init->MemoryDataWidth |\
  1195. Init->InternalBankNumber |\
  1196. Init->CASLatency |\
  1197. Init->WriteProtection);
  1198. Device->SDCR[FMC_SDRAM_BANK1] = tmpr1;
  1199. Device->SDCR[FMC_SDRAM_BANK2] = tmpr2;
  1200. }
  1201. return HAL_OK;
  1202. }
  1203. /**
  1204. * @brief Initializes the FMC_SDRAM device timing according to the specified
  1205. * parameters in the FMC_SDRAM_TimingTypeDef
  1206. * @param Device Pointer to SDRAM device instance
  1207. * @param Timing Pointer to SDRAM Timing structure
  1208. * @param Bank SDRAM bank number
  1209. * @retval HAL status
  1210. */
  1211. HAL_StatusTypeDef FMC_SDRAM_Timing_Init(FMC_SDRAM_TypeDef *Device, FMC_SDRAM_TimingTypeDef *Timing, uint32_t Bank)
  1212. {
  1213. uint32_t tmpr1 = 0U;
  1214. uint32_t tmpr2 = 0U;
  1215. /* Check the parameters */
  1216. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  1217. assert_param(IS_FMC_LOADTOACTIVE_DELAY(Timing->LoadToActiveDelay));
  1218. assert_param(IS_FMC_EXITSELFREFRESH_DELAY(Timing->ExitSelfRefreshDelay));
  1219. assert_param(IS_FMC_SELFREFRESH_TIME(Timing->SelfRefreshTime));
  1220. assert_param(IS_FMC_ROWCYCLE_DELAY(Timing->RowCycleDelay));
  1221. assert_param(IS_FMC_WRITE_RECOVERY_TIME(Timing->WriteRecoveryTime));
  1222. assert_param(IS_FMC_RP_DELAY(Timing->RPDelay));
  1223. assert_param(IS_FMC_RCD_DELAY(Timing->RCDDelay));
  1224. assert_param(IS_FMC_SDRAM_BANK(Bank));
  1225. /* Set SDRAM device timing parameters */
  1226. if (Bank != FMC_SDRAM_BANK2)
  1227. {
  1228. tmpr1 = Device->SDTR[FMC_SDRAM_BANK1];
  1229. /* Clear TMRD, TXSR, TRAS, TRC, TWR, TRP and TRCD bits */
  1230. tmpr1 &= ((uint32_t)~(FMC_SDTR1_TMRD | FMC_SDTR1_TXSR | FMC_SDTR1_TRAS | \
  1231. FMC_SDTR1_TRC | FMC_SDTR1_TWR | FMC_SDTR1_TRP | \
  1232. FMC_SDTR1_TRCD));
  1233. tmpr1 |= (uint32_t)(((Timing->LoadToActiveDelay)-1U) |\
  1234. (((Timing->ExitSelfRefreshDelay)-1U) << 4U) |\
  1235. (((Timing->SelfRefreshTime)-1U) << 8U) |\
  1236. (((Timing->RowCycleDelay)-1U) << 12U) |\
  1237. (((Timing->WriteRecoveryTime)-1U) <<16U) |\
  1238. (((Timing->RPDelay)-1U) << 20U) |\
  1239. (((Timing->RCDDelay)-1U) << 24U));
  1240. Device->SDTR[FMC_SDRAM_BANK1] = tmpr1;
  1241. }
  1242. else /* FMC_Bank2_SDRAM */
  1243. {
  1244. tmpr1 = Device->SDTR[FMC_SDRAM_BANK1];
  1245. /* Clear TRC and TRP bits */
  1246. tmpr1 &= ((uint32_t)~(FMC_SDTR1_TRC | FMC_SDTR1_TRP));
  1247. tmpr1 |= (uint32_t)((((Timing->RowCycleDelay)-1U) << 12U) |\
  1248. (((Timing->RPDelay)-1U) << 20U));
  1249. tmpr2 = Device->SDTR[FMC_SDRAM_BANK2];
  1250. /* Clear TMRD, TXSR, TRAS, TRC, TWR, TRP and TRCD bits */
  1251. tmpr2 &= ((uint32_t)~(FMC_SDTR1_TMRD | FMC_SDTR1_TXSR | FMC_SDTR1_TRAS | \
  1252. FMC_SDTR1_TRC | FMC_SDTR1_TWR | FMC_SDTR1_TRP | \
  1253. FMC_SDTR1_TRCD));
  1254. tmpr2 |= (uint32_t)((((Timing->LoadToActiveDelay)-1U) |\
  1255. (((Timing->ExitSelfRefreshDelay)-1U) << 4U) |\
  1256. (((Timing->SelfRefreshTime)-1U) << 8U) |\
  1257. (((Timing->WriteRecoveryTime)-1U) <<16U) |\
  1258. (((Timing->RCDDelay)-1U) << 24U)));
  1259. Device->SDTR[FMC_SDRAM_BANK1] = tmpr1;
  1260. Device->SDTR[FMC_SDRAM_BANK2] = tmpr2;
  1261. }
  1262. return HAL_OK;
  1263. }
  1264. /**
  1265. * @brief DeInitializes the FMC_SDRAM peripheral
  1266. * @param Device Pointer to SDRAM device instance
  1267. * @retval HAL status
  1268. */
  1269. HAL_StatusTypeDef FMC_SDRAM_DeInit(FMC_SDRAM_TypeDef *Device, uint32_t Bank)
  1270. {
  1271. /* Check the parameters */
  1272. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  1273. assert_param(IS_FMC_SDRAM_BANK(Bank));
  1274. /* De-initialize the SDRAM device */
  1275. Device->SDCR[Bank] = 0x000002D0U;
  1276. Device->SDTR[Bank] = 0x0FFFFFFFU;
  1277. Device->SDCMR = 0x00000000U;
  1278. Device->SDRTR = 0x00000000U;
  1279. Device->SDSR = 0x00000000U;
  1280. return HAL_OK;
  1281. }
  1282. /**
  1283. * @}
  1284. */
  1285. /** @addtogroup FMC_LL_SDRAMPrivate_Functions_Group2
  1286. * @brief management functions
  1287. *
  1288. @verbatim
  1289. ==============================================================================
  1290. ##### FMC_SDRAM Control functions #####
  1291. ==============================================================================
  1292. [..]
  1293. This subsection provides a set of functions allowing to control dynamically
  1294. the FMC SDRAM interface.
  1295. @endverbatim
  1296. * @{
  1297. */
  1298. /**
  1299. * @brief Enables dynamically FMC_SDRAM write protection.
  1300. * @param Device Pointer to SDRAM device instance
  1301. * @param Bank SDRAM bank number
  1302. * @retval HAL status
  1303. */
  1304. HAL_StatusTypeDef FMC_SDRAM_WriteProtection_Enable(FMC_SDRAM_TypeDef *Device, uint32_t Bank)
  1305. {
  1306. /* Check the parameters */
  1307. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  1308. assert_param(IS_FMC_SDRAM_BANK(Bank));
  1309. /* Enable write protection */
  1310. Device->SDCR[Bank] |= FMC_SDRAM_WRITE_PROTECTION_ENABLE;
  1311. return HAL_OK;
  1312. }
  1313. /**
  1314. * @brief Disables dynamically FMC_SDRAM write protection.
  1315. * @param hsdram FMC_SDRAM handle
  1316. * @retval HAL status
  1317. */
  1318. HAL_StatusTypeDef FMC_SDRAM_WriteProtection_Disable(FMC_SDRAM_TypeDef *Device, uint32_t Bank)
  1319. {
  1320. /* Check the parameters */
  1321. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  1322. assert_param(IS_FMC_SDRAM_BANK(Bank));
  1323. /* Disable write protection */
  1324. Device->SDCR[Bank] &= ~FMC_SDRAM_WRITE_PROTECTION_ENABLE;
  1325. return HAL_OK;
  1326. }
  1327. /**
  1328. * @brief Send Command to the FMC SDRAM bank
  1329. * @param Device Pointer to SDRAM device instance
  1330. * @param Command Pointer to SDRAM command structure
  1331. * @param Timing Pointer to SDRAM Timing structure
  1332. * @param Timeout Timeout wait value
  1333. * @retval HAL state
  1334. */
  1335. HAL_StatusTypeDef FMC_SDRAM_SendCommand(FMC_SDRAM_TypeDef *Device, FMC_SDRAM_CommandTypeDef *Command, uint32_t Timeout)
  1336. {
  1337. __IO uint32_t tmpr = 0U;
  1338. uint32_t tickstart = 0U;
  1339. /* Check the parameters */
  1340. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  1341. assert_param(IS_FMC_COMMAND_MODE(Command->CommandMode));
  1342. assert_param(IS_FMC_COMMAND_TARGET(Command->CommandTarget));
  1343. assert_param(IS_FMC_AUTOREFRESH_NUMBER(Command->AutoRefreshNumber));
  1344. assert_param(IS_FMC_MODE_REGISTER(Command->ModeRegisterDefinition));
  1345. /* Set command register */
  1346. tmpr = (uint32_t)((Command->CommandMode) |\
  1347. (Command->CommandTarget) |\
  1348. (((Command->AutoRefreshNumber)-1U) << 5U) |\
  1349. ((Command->ModeRegisterDefinition) << 9U)
  1350. );
  1351. Device->SDCMR = tmpr;
  1352. /* Get tick */
  1353. tickstart = HAL_GetTick();
  1354. /* Wait until command is send */
  1355. while(HAL_IS_BIT_SET(Device->SDSR, FMC_SDSR_BUSY))
  1356. {
  1357. /* Check for the Timeout */
  1358. if(Timeout != HAL_MAX_DELAY)
  1359. {
  1360. if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout))
  1361. {
  1362. return HAL_TIMEOUT;
  1363. }
  1364. }
  1365. }
  1366. return HAL_OK;
  1367. }
  1368. /**
  1369. * @brief Program the SDRAM Memory Refresh rate.
  1370. * @param Device Pointer to SDRAM device instance
  1371. * @param RefreshRate The SDRAM refresh rate value.
  1372. * @retval HAL state
  1373. */
  1374. HAL_StatusTypeDef FMC_SDRAM_ProgramRefreshRate(FMC_SDRAM_TypeDef *Device, uint32_t RefreshRate)
  1375. {
  1376. /* Check the parameters */
  1377. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  1378. assert_param(IS_FMC_REFRESH_RATE(RefreshRate));
  1379. /* Set the refresh rate in command register */
  1380. Device->SDRTR |= (RefreshRate<<1U);
  1381. return HAL_OK;
  1382. }
  1383. /**
  1384. * @brief Set the Number of consecutive SDRAM Memory auto Refresh commands.
  1385. * @param Device Pointer to SDRAM device instance
  1386. * @param AutoRefreshNumber Specifies the auto Refresh number.
  1387. * @retval None
  1388. */
  1389. HAL_StatusTypeDef FMC_SDRAM_SetAutoRefreshNumber(FMC_SDRAM_TypeDef *Device, uint32_t AutoRefreshNumber)
  1390. {
  1391. /* Check the parameters */
  1392. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  1393. assert_param(IS_FMC_AUTOREFRESH_NUMBER(AutoRefreshNumber));
  1394. /* Set the Auto-refresh number in command register */
  1395. Device->SDCMR |= (AutoRefreshNumber << 5U);
  1396. return HAL_OK;
  1397. }
  1398. /**
  1399. * @brief Returns the indicated FMC SDRAM bank mode status.
  1400. * @param Device Pointer to SDRAM device instance
  1401. * @param Bank Defines the FMC SDRAM bank. This parameter can be
  1402. * FMC_Bank1_SDRAM or FMC_Bank2_SDRAM.
  1403. * @retval The FMC SDRAM bank mode status, could be on of the following values:
  1404. * FMC_SDRAM_NORMAL_MODE, FMC_SDRAM_SELF_REFRESH_MODE or
  1405. * FMC_SDRAM_POWER_DOWN_MODE.
  1406. */
  1407. uint32_t FMC_SDRAM_GetModeStatus(FMC_SDRAM_TypeDef *Device, uint32_t Bank)
  1408. {
  1409. uint32_t tmpreg = 0U;
  1410. /* Check the parameters */
  1411. assert_param(IS_FMC_SDRAM_DEVICE(Device));
  1412. assert_param(IS_FMC_SDRAM_BANK(Bank));
  1413. /* Get the corresponding bank mode */
  1414. if(Bank == FMC_SDRAM_BANK1)
  1415. {
  1416. tmpreg = (uint32_t)(Device->SDSR & FMC_SDSR_MODES1);
  1417. }
  1418. else
  1419. {
  1420. tmpreg = ((uint32_t)(Device->SDSR & FMC_SDSR_MODES2) >> 2U);
  1421. }
  1422. /* Return the mode status */
  1423. return tmpreg;
  1424. }
  1425. /**
  1426. * @}
  1427. */
  1428. /**
  1429. * @}
  1430. */
  1431. /**
  1432. * @}
  1433. */
  1434. #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
  1435. #endif /* HAL_SRAM_MODULE_ENABLED || HAL_NOR_MODULE_ENABLED || HAL_NAND_MODULE_ENABLED || HAL_PCCARD_MODULE_ENABLED || HAL_SDRAM_MODULE_ENABLED */
  1436. /**
  1437. * @}
  1438. */
  1439. /**
  1440. * @}
  1441. */
  1442. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/