stm32f4xx_ll_fmc.c 59 KB

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