stm32f4xx_ll_fmc.c 61 KB

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