stm32f4xx_ll_fmc.c 60 KB

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