stm32f4xx_ll_fmc.c 60 KB

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