1 /**
2   ******************************************************************************
3   * @file    stm32h7xx_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   ******************************************************************************
14   * @attention
15   *
16   * Copyright (c) 2017 STMicroelectronics.
17   * All rights reserved.
18   *
19   * This software is licensed under terms that can be found in the LICENSE file
20   * in the root directory of this software component.
21   * If no LICENSE file comes with this software, it is provided AS-IS.
22   *
23   ******************************************************************************
24   @verbatim
25   ==============================================================================
26                         ##### FMC peripheral features #####
27   ==============================================================================
28   [..] The Flexible memory controller (FMC) includes following memory controllers:
29        (+) The NOR/PSRAM memory controller
30      (+) The NAND memory controller
31        (+) The Synchronous DRAM (SDRAM) controller
32 
33   [..] The FMC functional block makes the interface with synchronous and asynchronous static
34        memories and SDRAM memories. Its main purposes are:
35        (+) to translate AHB transactions into the appropriate external device protocol
36        (+) to meet the access time requirements of the external memory devices
37 
38   [..] All external memories share the addresses, data and control signals with the controller.
39        Each external device is accessed by means of a unique Chip Select. The FMC performs
40        only one access at a time to an external device.
41        The main features of the FMC controller are the following:
42         (+) Interface with static-memory mapped devices including:
43            (++) Static random access memory (SRAM)
44            (++) Read-only memory (ROM)
45            (++) NOR Flash memory/OneNAND Flash memory
46            (++) PSRAM (4 memory banks)
47            (++) Two banks of NAND Flash memory with ECC hardware to check up to 8 Kbytes of
48                 data
49         (+) Interface with synchronous DRAM (SDRAM) memories
50         (+) Independent Chip Select control for each memory bank
51         (+) Independent configuration for each memory bank
52 
53   @endverbatim
54   ******************************************************************************
55   */
56 
57 /* Includes ------------------------------------------------------------------*/
58 #include "stm32h7xx_hal.h"
59 
60 /** @addtogroup STM32H7xx_HAL_Driver
61   * @{
62   */
63 #if defined(HAL_NOR_MODULE_ENABLED) || defined(HAL_NAND_MODULE_ENABLED) || defined(HAL_SDRAM_MODULE_ENABLED)\
64     || defined(HAL_SRAM_MODULE_ENABLED)
65 
66 /** @defgroup FMC_LL  FMC Low Layer
67   * @brief FMC driver modules
68   * @{
69   */
70 
71 /* Private typedef -----------------------------------------------------------*/
72 /* Private define ------------------------------------------------------------*/
73 
74 /** @defgroup FMC_LL_Private_Constants FMC Low Layer Private Constants
75   * @{
76   */
77 
78 /* ----------------------- FMC registers bit mask --------------------------- */
79 
80 /* --- BCR Register ---*/
81 /* BCR register clear mask */
82 
83 /* --- BTR Register ---*/
84 /* BTR register clear mask */
85 #define BTR_CLEAR_MASK    ((uint32_t)(FMC_BTRx_ADDSET | FMC_BTRx_ADDHLD  |\
86                                       FMC_BTRx_DATAST | FMC_BTRx_BUSTURN |\
87                                       FMC_BTRx_CLKDIV | FMC_BTRx_DATLAT  |\
88                                       FMC_BTRx_ACCMOD))
89 
90 /* --- BWTR Register ---*/
91 /* BWTR register clear mask */
92 #define BWTR_CLEAR_MASK   ((uint32_t)(FMC_BWTRx_ADDSET | FMC_BWTRx_ADDHLD  |\
93                                       FMC_BWTRx_DATAST | FMC_BWTRx_BUSTURN |\
94                                       FMC_BWTRx_ACCMOD))
95 
96 /* --- PCR Register ---*/
97 /* PCR register clear mask */
98 #define PCR_CLEAR_MASK    ((uint32_t)(FMC_PCR_PWAITEN | FMC_PCR_PBKEN  | \
99                                       FMC_PCR_PWID    | FMC_PCR_ECCEN  | \
100                                       FMC_PCR_TCLR    | FMC_PCR_TAR    | \
101                                       FMC_PCR_ECCPS))
102 /* --- PMEM Register ---*/
103 /* PMEM register clear mask */
104 #define PMEM_CLEAR_MASK   ((uint32_t)(FMC_PMEM_MEMSET  | FMC_PMEM_MEMWAIT |\
105                                       FMC_PMEM_MEMHOLD | FMC_PMEM_MEMHIZ))
106 
107 /* --- PATT Register ---*/
108 /* PATT register clear mask */
109 #define PATT_CLEAR_MASK   ((uint32_t)(FMC_PATT_ATTSET  | FMC_PATT_ATTWAIT |\
110                                       FMC_PATT_ATTHOLD | FMC_PATT_ATTHIZ))
111 
112 
113 /* --- SDCR Register ---*/
114 /* SDCR register clear mask */
115 #define SDCR_CLEAR_MASK   ((uint32_t)(FMC_SDCRx_NC    | FMC_SDCRx_NR     | \
116                                       FMC_SDCRx_MWID  | FMC_SDCRx_NB     | \
117                                       FMC_SDCRx_CAS   | FMC_SDCRx_WP     | \
118                                       FMC_SDCRx_SDCLK | FMC_SDCRx_RBURST | \
119                                       FMC_SDCRx_RPIPE))
120 
121 /* --- SDTR Register ---*/
122 /* SDTR register clear mask */
123 #define SDTR_CLEAR_MASK   ((uint32_t)(FMC_SDTRx_TMRD  | FMC_SDTRx_TXSR   | \
124                                       FMC_SDTRx_TRAS  | FMC_SDTRx_TRC    | \
125                                       FMC_SDTRx_TWR   | FMC_SDTRx_TRP    | \
126                                       FMC_SDTRx_TRCD))
127 
128 /**
129   * @}
130   */
131 
132 /* Private macro -------------------------------------------------------------*/
133 /* Private variables ---------------------------------------------------------*/
134 /* Private function prototypes -----------------------------------------------*/
135 /* Exported functions --------------------------------------------------------*/
136 
137 /** @defgroup FMC_LL_Exported_Functions FMC Low Layer Exported Functions
138   * @{
139   */
140 
141 
142 /** @defgroup FMC_LL_Exported_Functions_NORSRAM FMC Low Layer NOR SRAM Exported Functions
143   * @brief  NORSRAM Controller functions
144   *
145   @verbatim
146   ==============================================================================
147                    ##### How to use NORSRAM device driver #####
148   ==============================================================================
149 
150   [..]
151     This driver contains a set of APIs to interface with the FMC NORSRAM banks in order
152     to run the NORSRAM external devices.
153 
154     (+) FMC NORSRAM bank reset using the function FMC_NORSRAM_DeInit()
155     (+) FMC NORSRAM bank control configuration using the function FMC_NORSRAM_Init()
156     (+) FMC NORSRAM bank timing configuration using the function FMC_NORSRAM_Timing_Init()
157     (+) FMC NORSRAM bank extended timing configuration using the function
158         FMC_NORSRAM_Extended_Timing_Init()
159     (+) FMC NORSRAM bank enable/disable write operation using the functions
160         FMC_NORSRAM_WriteOperation_Enable()/FMC_NORSRAM_WriteOperation_Disable()
161 
162 @endverbatim
163   * @{
164   */
165 
166 /** @defgroup FMC_LL_NORSRAM_Exported_Functions_Group1 Initialization and de-initialization functions
167   * @brief    Initialization and Configuration functions
168   *
169   @verbatim
170   ==============================================================================
171               ##### Initialization and de_initialization functions #####
172   ==============================================================================
173   [..]
174     This section provides functions allowing to:
175     (+) Initialize and configure the FMC NORSRAM interface
176     (+) De-initialize the FMC NORSRAM interface
177     (+) Configure the FMC clock and associated GPIOs
178 
179 @endverbatim
180   * @{
181   */
182 
183 /**
184   * @brief  Initialize the FMC_NORSRAM device according to the specified
185   *         control parameters in the FMC_NORSRAM_InitTypeDef
186   * @param  Device Pointer to NORSRAM device instance
187   * @param  Init Pointer to NORSRAM Initialization structure
188   * @retval HAL status
189   */
FMC_NORSRAM_Init(FMC_NORSRAM_TypeDef * Device,const FMC_NORSRAM_InitTypeDef * Init)190 HAL_StatusTypeDef  FMC_NORSRAM_Init(FMC_NORSRAM_TypeDef *Device,
191                                     const FMC_NORSRAM_InitTypeDef *Init)
192 {
193   uint32_t flashaccess;
194   uint32_t btcr_reg;
195   uint32_t mask;
196 
197   /* Check the parameters */
198   assert_param(IS_FMC_NORSRAM_DEVICE(Device));
199   assert_param(IS_FMC_NORSRAM_BANK(Init->NSBank));
200   assert_param(IS_FMC_MUX(Init->DataAddressMux));
201   assert_param(IS_FMC_MEMORY(Init->MemoryType));
202   assert_param(IS_FMC_NORSRAM_MEMORY_WIDTH(Init->MemoryDataWidth));
203   assert_param(IS_FMC_BURSTMODE(Init->BurstAccessMode));
204   assert_param(IS_FMC_WAIT_POLARITY(Init->WaitSignalPolarity));
205   assert_param(IS_FMC_WAIT_SIGNAL_ACTIVE(Init->WaitSignalActive));
206   assert_param(IS_FMC_WRITE_OPERATION(Init->WriteOperation));
207   assert_param(IS_FMC_WAITE_SIGNAL(Init->WaitSignal));
208   assert_param(IS_FMC_EXTENDED_MODE(Init->ExtendedMode));
209   assert_param(IS_FMC_ASYNWAIT(Init->AsynchronousWait));
210   assert_param(IS_FMC_WRITE_BURST(Init->WriteBurst));
211   assert_param(IS_FMC_CONTINOUS_CLOCK(Init->ContinuousClock));
212   assert_param(IS_FMC_WRITE_FIFO(Init->WriteFifo));
213   assert_param(IS_FMC_PAGESIZE(Init->PageSize));
214 
215   /* Disable NORSRAM Device */
216   __FMC_NORSRAM_DISABLE(Device, Init->NSBank);
217 
218   /* Set NORSRAM device control parameters */
219   if (Init->MemoryType == FMC_MEMORY_TYPE_NOR)
220   {
221     flashaccess = FMC_NORSRAM_FLASH_ACCESS_ENABLE;
222   }
223   else
224   {
225     flashaccess = FMC_NORSRAM_FLASH_ACCESS_DISABLE;
226   }
227 
228   btcr_reg = (flashaccess                   | \
229               Init->DataAddressMux          | \
230               Init->MemoryType              | \
231               Init->MemoryDataWidth         | \
232               Init->BurstAccessMode         | \
233               Init->WaitSignalPolarity      | \
234               Init->WaitSignalActive        | \
235               Init->WriteOperation          | \
236               Init->WaitSignal              | \
237               Init->ExtendedMode            | \
238               Init->AsynchronousWait        | \
239               Init->WriteBurst);
240 
241   btcr_reg |= Init->ContinuousClock;
242   btcr_reg |= Init->WriteFifo;
243   btcr_reg |= Init->PageSize;
244 
245   mask = (FMC_BCRx_MBKEN                |
246           FMC_BCRx_MUXEN                |
247           FMC_BCRx_MTYP                 |
248           FMC_BCRx_MWID                 |
249           FMC_BCRx_FACCEN               |
250           FMC_BCRx_BURSTEN              |
251           FMC_BCRx_WAITPOL              |
252           FMC_BCRx_WAITCFG              |
253           FMC_BCRx_WREN                 |
254           FMC_BCRx_WAITEN               |
255           FMC_BCRx_EXTMOD               |
256           FMC_BCRx_ASYNCWAIT            |
257           FMC_BCRx_CBURSTRW);
258 
259   mask |= FMC_BCR1_CCLKEN;
260   mask |= FMC_BCR1_WFDIS;
261   mask |= FMC_BCRx_CPSIZE;
262 
263   MODIFY_REG(Device->BTCR[Init->NSBank], mask, btcr_reg);
264 
265   /* Configure synchronous mode when Continuous clock is enabled for bank2..4 */
266   if ((Init->ContinuousClock == FMC_CONTINUOUS_CLOCK_SYNC_ASYNC) && (Init->NSBank != FMC_NORSRAM_BANK1))
267   {
268     MODIFY_REG(Device->BTCR[FMC_NORSRAM_BANK1], FMC_BCR1_CCLKEN, Init->ContinuousClock);
269   }
270 
271   if (Init->NSBank != FMC_NORSRAM_BANK1)
272   {
273     /* Configure Write FIFO mode when Write Fifo is enabled for bank2..4 */
274     SET_BIT(Device->BTCR[FMC_NORSRAM_BANK1], (uint32_t)(Init->WriteFifo));
275   }
276 
277   return HAL_OK;
278 }
279 
280 /**
281   * @brief  DeInitialize the FMC_NORSRAM peripheral
282   * @param  Device Pointer to NORSRAM device instance
283   * @param  ExDevice Pointer to NORSRAM extended mode device instance
284   * @param  Bank NORSRAM bank number
285   * @retval HAL status
286   */
FMC_NORSRAM_DeInit(FMC_NORSRAM_TypeDef * Device,FMC_NORSRAM_EXTENDED_TypeDef * ExDevice,uint32_t Bank)287 HAL_StatusTypeDef FMC_NORSRAM_DeInit(FMC_NORSRAM_TypeDef *Device,
288                                      FMC_NORSRAM_EXTENDED_TypeDef *ExDevice, uint32_t Bank)
289 {
290   /* Check the parameters */
291   assert_param(IS_FMC_NORSRAM_DEVICE(Device));
292   assert_param(IS_FMC_NORSRAM_EXTENDED_DEVICE(ExDevice));
293   assert_param(IS_FMC_NORSRAM_BANK(Bank));
294 
295   /* Disable the FMC_NORSRAM device */
296   __FMC_NORSRAM_DISABLE(Device, Bank);
297 
298   /* De-initialize the FMC_NORSRAM device */
299   /* FMC_NORSRAM_BANK1 */
300   if (Bank == FMC_NORSRAM_BANK1)
301   {
302     Device->BTCR[Bank] = 0x000030DBU;
303   }
304   /* FMC_NORSRAM_BANK2, FMC_NORSRAM_BANK3 or FMC_NORSRAM_BANK4 */
305   else
306   {
307     Device->BTCR[Bank] = 0x000030D2U;
308   }
309 
310   Device->BTCR[Bank + 1U] = 0x0FFFFFFFU;
311   ExDevice->BWTR[Bank]   = 0x0FFFFFFFU;
312 
313   return HAL_OK;
314 }
315 
316 /**
317   * @brief  Initialize the FMC_NORSRAM Timing according to the specified
318   *         parameters in the FMC_NORSRAM_TimingTypeDef
319   * @param  Device Pointer to NORSRAM device instance
320   * @param  Timing Pointer to NORSRAM Timing structure
321   * @param  Bank NORSRAM bank number
322   * @retval HAL status
323   */
FMC_NORSRAM_Timing_Init(FMC_NORSRAM_TypeDef * Device,const FMC_NORSRAM_TimingTypeDef * Timing,uint32_t Bank)324 HAL_StatusTypeDef FMC_NORSRAM_Timing_Init(FMC_NORSRAM_TypeDef *Device,
325                                           const FMC_NORSRAM_TimingTypeDef *Timing, uint32_t Bank)
326 {
327   uint32_t tmpr;
328 
329   /* Check the parameters */
330   assert_param(IS_FMC_NORSRAM_DEVICE(Device));
331   assert_param(IS_FMC_ADDRESS_SETUP_TIME(Timing->AddressSetupTime));
332   assert_param(IS_FMC_ADDRESS_HOLD_TIME(Timing->AddressHoldTime));
333   assert_param(IS_FMC_DATASETUP_TIME(Timing->DataSetupTime));
334   assert_param(IS_FMC_TURNAROUND_TIME(Timing->BusTurnAroundDuration));
335   assert_param(IS_FMC_CLK_DIV(Timing->CLKDivision));
336   assert_param(IS_FMC_DATA_LATENCY(Timing->DataLatency));
337   assert_param(IS_FMC_ACCESS_MODE(Timing->AccessMode));
338   assert_param(IS_FMC_NORSRAM_BANK(Bank));
339 
340   /* Set FMC_NORSRAM device timing parameters */
341   Device->BTCR[Bank + 1U] =
342     (Timing->AddressSetupTime << FMC_BTRx_ADDSET_Pos) |
343     (Timing->AddressHoldTime << FMC_BTRx_ADDHLD_Pos) |
344     (Timing->DataSetupTime << FMC_BTRx_DATAST_Pos) |
345     (Timing->BusTurnAroundDuration << FMC_BTRx_BUSTURN_Pos) |
346     ((Timing->CLKDivision - 1U) << FMC_BTRx_CLKDIV_Pos) |
347     ((Timing->DataLatency - 2U) << FMC_BTRx_DATLAT_Pos) |
348     Timing->AccessMode;
349 
350   /* Configure Clock division value (in NORSRAM bank 1) when continuous clock is enabled */
351   if (HAL_IS_BIT_SET(Device->BTCR[FMC_NORSRAM_BANK1], FMC_BCR1_CCLKEN))
352   {
353     tmpr = (uint32_t)(Device->BTCR[FMC_NORSRAM_BANK1 + 1U] & ~((0x0FU) << FMC_BTRx_CLKDIV_Pos));
354     tmpr |= (uint32_t)(((Timing->CLKDivision) - 1U) << FMC_BTRx_CLKDIV_Pos);
355     MODIFY_REG(Device->BTCR[FMC_NORSRAM_BANK1 + 1U], FMC_BTRx_CLKDIV, tmpr);
356   }
357 
358   return HAL_OK;
359 }
360 
361 /**
362   * @brief  Initialize the FMC_NORSRAM Extended mode Timing according to the specified
363   *         parameters in the FMC_NORSRAM_TimingTypeDef
364   * @param  Device Pointer to NORSRAM device instance
365   * @param  Timing Pointer to NORSRAM Timing structure
366   * @param  Bank NORSRAM bank number
367   * @param  ExtendedMode FMC Extended Mode
368   *          This parameter can be one of the following values:
369   *            @arg FMC_EXTENDED_MODE_DISABLE
370   *            @arg FMC_EXTENDED_MODE_ENABLE
371   * @retval HAL status
372   */
FMC_NORSRAM_Extended_Timing_Init(FMC_NORSRAM_EXTENDED_TypeDef * Device,const FMC_NORSRAM_TimingTypeDef * Timing,uint32_t Bank,uint32_t ExtendedMode)373 HAL_StatusTypeDef FMC_NORSRAM_Extended_Timing_Init(FMC_NORSRAM_EXTENDED_TypeDef *Device,
374                                                    const FMC_NORSRAM_TimingTypeDef *Timing, uint32_t Bank,
375                                                    uint32_t ExtendedMode)
376 {
377   /* Check the parameters */
378   assert_param(IS_FMC_EXTENDED_MODE(ExtendedMode));
379 
380   /* Set NORSRAM device timing register for write configuration, if extended mode is used */
381   if (ExtendedMode == FMC_EXTENDED_MODE_ENABLE)
382   {
383     /* Check the parameters */
384     assert_param(IS_FMC_NORSRAM_EXTENDED_DEVICE(Device));
385     assert_param(IS_FMC_ADDRESS_SETUP_TIME(Timing->AddressSetupTime));
386     assert_param(IS_FMC_ADDRESS_HOLD_TIME(Timing->AddressHoldTime));
387     assert_param(IS_FMC_DATASETUP_TIME(Timing->DataSetupTime));
388     assert_param(IS_FMC_TURNAROUND_TIME(Timing->BusTurnAroundDuration));
389     assert_param(IS_FMC_ACCESS_MODE(Timing->AccessMode));
390     assert_param(IS_FMC_NORSRAM_BANK(Bank));
391 
392     /* Set NORSRAM device timing register for write configuration, if extended mode is used */
393     MODIFY_REG(Device->BWTR[Bank], BWTR_CLEAR_MASK, (Timing->AddressSetupTime                                    |
394                                                      ((Timing->AddressHoldTime)        << FMC_BWTRx_ADDHLD_Pos)  |
395                                                      ((Timing->DataSetupTime)          << FMC_BWTRx_DATAST_Pos)  |
396                                                      Timing->AccessMode                                          |
397                                                      ((Timing->BusTurnAroundDuration)  << FMC_BWTRx_BUSTURN_Pos)));
398   }
399   else
400   {
401     Device->BWTR[Bank] = 0x0FFFFFFFU;
402   }
403 
404   return HAL_OK;
405 }
406 /**
407   * @}
408   */
409 
410 /** @addtogroup FMC_LL_NORSRAM_Private_Functions_Group2
411   *  @brief   management functions
412   *
413 @verbatim
414   ==============================================================================
415                       ##### FMC_NORSRAM Control functions #####
416   ==============================================================================
417   [..]
418     This subsection provides a set of functions allowing to control dynamically
419     the FMC NORSRAM interface.
420 
421 @endverbatim
422   * @{
423   */
424 
425 /**
426   * @brief  Enables dynamically FMC_NORSRAM write operation.
427   * @param  Device Pointer to NORSRAM device instance
428   * @param  Bank NORSRAM bank number
429   * @retval HAL status
430   */
FMC_NORSRAM_WriteOperation_Enable(FMC_NORSRAM_TypeDef * Device,uint32_t Bank)431 HAL_StatusTypeDef FMC_NORSRAM_WriteOperation_Enable(FMC_NORSRAM_TypeDef *Device, uint32_t Bank)
432 {
433   /* Check the parameters */
434   assert_param(IS_FMC_NORSRAM_DEVICE(Device));
435   assert_param(IS_FMC_NORSRAM_BANK(Bank));
436 
437   /* Enable write operation */
438   SET_BIT(Device->BTCR[Bank], FMC_WRITE_OPERATION_ENABLE);
439 
440   return HAL_OK;
441 }
442 
443 /**
444   * @brief  Disables dynamically FMC_NORSRAM write operation.
445   * @param  Device Pointer to NORSRAM device instance
446   * @param  Bank NORSRAM bank number
447   * @retval HAL status
448   */
FMC_NORSRAM_WriteOperation_Disable(FMC_NORSRAM_TypeDef * Device,uint32_t Bank)449 HAL_StatusTypeDef FMC_NORSRAM_WriteOperation_Disable(FMC_NORSRAM_TypeDef *Device, uint32_t Bank)
450 {
451   /* Check the parameters */
452   assert_param(IS_FMC_NORSRAM_DEVICE(Device));
453   assert_param(IS_FMC_NORSRAM_BANK(Bank));
454 
455   /* Disable write operation */
456   CLEAR_BIT(Device->BTCR[Bank], FMC_WRITE_OPERATION_ENABLE);
457 
458   return HAL_OK;
459 }
460 
461 /**
462   * @}
463   */
464 
465 /**
466   * @}
467   */
468 
469 
470 /** @defgroup FMC_LL_Exported_Functions_NAND FMC Low Layer NAND Exported Functions
471   * @brief    NAND Controller functions
472   *
473   @verbatim
474   ==============================================================================
475                     ##### How to use NAND device driver #####
476   ==============================================================================
477   [..]
478     This driver contains a set of APIs to interface with the FMC NAND banks in order
479     to run the NAND external devices.
480 
481     (+) FMC NAND bank reset using the function FMC_NAND_DeInit()
482     (+) FMC NAND bank control configuration using the function FMC_NAND_Init()
483     (+) FMC NAND bank common space timing configuration using the function
484         FMC_NAND_CommonSpace_Timing_Init()
485     (+) FMC NAND bank attribute space timing configuration using the function
486         FMC_NAND_AttributeSpace_Timing_Init()
487     (+) FMC NAND bank enable/disable ECC correction feature using the functions
488         FMC_NAND_ECC_Enable()/FMC_NAND_ECC_Disable()
489     (+) FMC NAND bank get ECC correction code using the function FMC_NAND_GetECC()
490 
491 @endverbatim
492   * @{
493   */
494 
495 /** @defgroup FMC_LL_NAND_Exported_Functions_Group1 Initialization and de-initialization functions
496   *  @brief    Initialization and Configuration functions
497   *
498 @verbatim
499   ==============================================================================
500               ##### Initialization and de_initialization functions #####
501   ==============================================================================
502   [..]
503     This section provides functions allowing to:
504     (+) Initialize and configure the FMC NAND interface
505     (+) De-initialize the FMC NAND interface
506     (+) Configure the FMC clock and associated GPIOs
507 
508 @endverbatim
509   * @{
510   */
511 
512 /**
513   * @brief  Initializes the FMC_NAND device according to the specified
514   *         control parameters in the FMC_NAND_HandleTypeDef
515   * @param  Device Pointer to NAND device instance
516   * @param  Init Pointer to NAND Initialization structure
517   * @retval HAL status
518   */
FMC_NAND_Init(FMC_NAND_TypeDef * Device,const FMC_NAND_InitTypeDef * Init)519 HAL_StatusTypeDef FMC_NAND_Init(FMC_NAND_TypeDef *Device, const FMC_NAND_InitTypeDef *Init)
520 {
521   /* Check the parameters */
522   assert_param(IS_FMC_NAND_DEVICE(Device));
523   assert_param(IS_FMC_NAND_BANK(Init->NandBank));
524   assert_param(IS_FMC_WAIT_FEATURE(Init->Waitfeature));
525   assert_param(IS_FMC_NAND_MEMORY_WIDTH(Init->MemoryDataWidth));
526   assert_param(IS_FMC_ECC_STATE(Init->EccComputation));
527   assert_param(IS_FMC_ECCPAGE_SIZE(Init->ECCPageSize));
528   assert_param(IS_FMC_TCLR_TIME(Init->TCLRSetupTime));
529   assert_param(IS_FMC_TAR_TIME(Init->TARSetupTime));
530 
531   /* NAND bank 3 registers configuration */
532   MODIFY_REG(Device->PCR, PCR_CLEAR_MASK, (Init->Waitfeature                            |
533                                            FMC_PCR_MEMORY_TYPE_NAND                     |
534                                            Init->MemoryDataWidth                        |
535                                            Init->EccComputation                         |
536                                            Init->ECCPageSize                            |
537                                            ((Init->TCLRSetupTime) << FMC_PCR_TCLR_Pos)  |
538                                            ((Init->TARSetupTime)  << FMC_PCR_TAR_Pos)));
539 
540   return HAL_OK;
541 }
542 
543 /**
544   * @brief  Initializes the FMC_NAND Common space Timing according to the specified
545   *         parameters in the FMC_NAND_PCC_TimingTypeDef
546   * @param  Device Pointer to NAND device instance
547   * @param  Timing Pointer to NAND timing structure
548   * @param  Bank NAND bank number
549   * @retval HAL status
550   */
FMC_NAND_CommonSpace_Timing_Init(FMC_NAND_TypeDef * Device,const FMC_NAND_PCC_TimingTypeDef * Timing,uint32_t Bank)551 HAL_StatusTypeDef FMC_NAND_CommonSpace_Timing_Init(FMC_NAND_TypeDef *Device,
552                                                    const FMC_NAND_PCC_TimingTypeDef *Timing, uint32_t Bank)
553 {
554   /* Check the parameters */
555   assert_param(IS_FMC_NAND_DEVICE(Device));
556   assert_param(IS_FMC_SETUP_TIME(Timing->SetupTime));
557   assert_param(IS_FMC_WAIT_TIME(Timing->WaitSetupTime));
558   assert_param(IS_FMC_HOLD_TIME(Timing->HoldSetupTime));
559   assert_param(IS_FMC_HIZ_TIME(Timing->HiZSetupTime));
560   assert_param(IS_FMC_NAND_BANK(Bank));
561 
562   /* Prevent unused argument(s) compilation warning if no assert_param check */
563   UNUSED(Bank);
564 
565   /* NAND bank 3 registers configuration */
566   Device->PMEM = (Timing->SetupTime |
567                   ((Timing->WaitSetupTime) << FMC_PMEM_MEMWAIT_Pos) |
568                   ((Timing->HoldSetupTime) << FMC_PMEM_MEMHOLD_Pos) |
569                   ((Timing->HiZSetupTime) << FMC_PMEM_MEMHIZ_Pos));
570 
571   return HAL_OK;
572 }
573 
574 /**
575   * @brief  Initializes the FMC_NAND Attribute space Timing according to the specified
576   *         parameters in the FMC_NAND_PCC_TimingTypeDef
577   * @param  Device Pointer to NAND device instance
578   * @param  Timing Pointer to NAND timing structure
579   * @param  Bank NAND bank number
580   * @retval HAL status
581   */
FMC_NAND_AttributeSpace_Timing_Init(FMC_NAND_TypeDef * Device,const FMC_NAND_PCC_TimingTypeDef * Timing,uint32_t Bank)582 HAL_StatusTypeDef FMC_NAND_AttributeSpace_Timing_Init(FMC_NAND_TypeDef *Device,
583                                                       const FMC_NAND_PCC_TimingTypeDef *Timing, uint32_t Bank)
584 {
585   /* Check the parameters */
586   assert_param(IS_FMC_NAND_DEVICE(Device));
587   assert_param(IS_FMC_SETUP_TIME(Timing->SetupTime));
588   assert_param(IS_FMC_WAIT_TIME(Timing->WaitSetupTime));
589   assert_param(IS_FMC_HOLD_TIME(Timing->HoldSetupTime));
590   assert_param(IS_FMC_HIZ_TIME(Timing->HiZSetupTime));
591   assert_param(IS_FMC_NAND_BANK(Bank));
592 
593   /* Prevent unused argument(s) compilation warning if no assert_param check */
594   UNUSED(Bank);
595 
596   /* NAND bank 3 registers configuration */
597   Device->PATT = (Timing->SetupTime |
598                   ((Timing->WaitSetupTime) << FMC_PATT_ATTWAIT_Pos) |
599                   ((Timing->HoldSetupTime) << FMC_PATT_ATTHOLD_Pos) |
600                   ((Timing->HiZSetupTime)  << FMC_PATT_ATTHIZ_Pos));
601 
602   return HAL_OK;
603 }
604 
605 /**
606   * @brief  DeInitializes the FMC_NAND device
607   * @param  Device Pointer to NAND device instance
608   * @param  Bank NAND bank number
609   * @retval HAL status
610   */
FMC_NAND_DeInit(FMC_NAND_TypeDef * Device,uint32_t Bank)611 HAL_StatusTypeDef FMC_NAND_DeInit(FMC_NAND_TypeDef *Device, uint32_t Bank)
612 {
613   /* Check the parameters */
614   assert_param(IS_FMC_NAND_DEVICE(Device));
615   assert_param(IS_FMC_NAND_BANK(Bank));
616 
617   /* Disable the NAND Bank */
618   __FMC_NAND_DISABLE(Device, Bank);
619 
620   /* De-initialize the NAND Bank */
621   /* Prevent unused argument(s) compilation warning if no assert_param check */
622   UNUSED(Bank);
623 
624   /* Set the FMC_NAND_BANK3 registers to their reset values */
625   WRITE_REG(Device->PCR,  0x00000018U);
626   WRITE_REG(Device->SR,   0x00000040U);
627   WRITE_REG(Device->PMEM, 0xFCFCFCFCU);
628   WRITE_REG(Device->PATT, 0xFCFCFCFCU);
629 
630   return HAL_OK;
631 }
632 
633 /**
634   * @}
635   */
636 
637 /** @defgroup HAL_FMC_NAND_Group2 Peripheral Control functions
638   *  @brief   management functions
639   *
640 @verbatim
641   ==============================================================================
642                        ##### FMC_NAND Control functions #####
643   ==============================================================================
644   [..]
645     This subsection provides a set of functions allowing to control dynamically
646     the FMC NAND interface.
647 
648 @endverbatim
649   * @{
650   */
651 
652 
653 /**
654   * @brief  Enables dynamically FMC_NAND ECC feature.
655   * @param  Device Pointer to NAND device instance
656   * @param  Bank NAND bank number
657   * @retval HAL status
658   */
FMC_NAND_ECC_Enable(FMC_NAND_TypeDef * Device,uint32_t Bank)659 HAL_StatusTypeDef FMC_NAND_ECC_Enable(FMC_NAND_TypeDef *Device, uint32_t Bank)
660 {
661   /* Check the parameters */
662   assert_param(IS_FMC_NAND_DEVICE(Device));
663   assert_param(IS_FMC_NAND_BANK(Bank));
664 
665   /* Enable ECC feature */
666   /* Prevent unused argument(s) compilation warning if no assert_param check */
667   UNUSED(Bank);
668 
669   SET_BIT(Device->PCR, FMC_PCR_ECCEN);
670 
671   return HAL_OK;
672 }
673 
674 
675 /**
676   * @brief  Disables dynamically FMC_NAND ECC feature.
677   * @param  Device Pointer to NAND device instance
678   * @param  Bank NAND bank number
679   * @retval HAL status
680   */
FMC_NAND_ECC_Disable(FMC_NAND_TypeDef * Device,uint32_t Bank)681 HAL_StatusTypeDef FMC_NAND_ECC_Disable(FMC_NAND_TypeDef *Device, uint32_t Bank)
682 {
683   /* Check the parameters */
684   assert_param(IS_FMC_NAND_DEVICE(Device));
685   assert_param(IS_FMC_NAND_BANK(Bank));
686 
687   /* Disable ECC feature */
688   /* Prevent unused argument(s) compilation warning if no assert_param check */
689   UNUSED(Bank);
690 
691   CLEAR_BIT(Device->PCR, FMC_PCR_ECCEN);
692 
693   return HAL_OK;
694 }
695 
696 /**
697   * @brief  Disables dynamically FMC_NAND ECC feature.
698   * @param  Device Pointer to NAND device instance
699   * @param  ECCval Pointer to ECC value
700   * @param  Bank NAND bank number
701   * @param  Timeout Timeout wait value
702   * @retval HAL status
703   */
FMC_NAND_GetECC(const FMC_NAND_TypeDef * Device,uint32_t * ECCval,uint32_t Bank,uint32_t Timeout)704 HAL_StatusTypeDef FMC_NAND_GetECC(const FMC_NAND_TypeDef *Device, uint32_t *ECCval, uint32_t Bank,
705                                   uint32_t Timeout)
706 {
707   uint32_t tickstart;
708 
709   /* Check the parameters */
710   assert_param(IS_FMC_NAND_DEVICE(Device));
711   assert_param(IS_FMC_NAND_BANK(Bank));
712 
713   /* Get tick */
714   tickstart = HAL_GetTick();
715 
716   /* Wait until FIFO is empty */
717   while (__FMC_NAND_GET_FLAG(Device, Bank, FMC_FLAG_FEMPT) == RESET)
718   {
719     /* Check for the Timeout */
720     if (Timeout != HAL_MAX_DELAY)
721     {
722       if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
723       {
724         return HAL_TIMEOUT;
725       }
726     }
727   }
728 
729   /* Prevent unused argument(s) compilation warning if no assert_param check */
730   UNUSED(Bank);
731 
732   /* Get the ECCR register value */
733   *ECCval = (uint32_t)Device->ECCR;
734 
735   return HAL_OK;
736 }
737 
738 /**
739   * @}
740   */
741 
742 
743 /** @defgroup FMC_LL_SDRAM
744   * @brief    SDRAM Controller functions
745   *
746   @verbatim
747   ==============================================================================
748                      ##### How to use SDRAM device driver #####
749   ==============================================================================
750   [..]
751     This driver contains a set of APIs to interface with the FMC SDRAM banks in order
752     to run the SDRAM external devices.
753 
754     (+) FMC SDRAM bank reset using the function FMC_SDRAM_DeInit()
755     (+) FMC SDRAM bank control configuration using the function FMC_SDRAM_Init()
756     (+) FMC SDRAM bank timing configuration using the function FMC_SDRAM_Timing_Init()
757     (+) FMC SDRAM bank enable/disable write operation using the functions
758         FMC_SDRAM_WriteOperation_Enable()/FMC_SDRAM_WriteOperation_Disable()
759     (+) FMC SDRAM bank send command using the function FMC_SDRAM_SendCommand()
760 
761 @endverbatim
762   * @{
763   */
764 
765 /** @addtogroup FMC_LL_SDRAM_Private_Functions_Group1
766   *  @brief    Initialization and Configuration functions
767   *
768 @verbatim
769   ==============================================================================
770               ##### Initialization and de_initialization functions #####
771   ==============================================================================
772   [..]
773     This section provides functions allowing to:
774     (+) Initialize and configure the FMC SDRAM interface
775     (+) De-initialize the FMC SDRAM interface
776     (+) Configure the FMC clock and associated GPIOs
777 
778 @endverbatim
779   * @{
780   */
781 
782 /**
783   * @brief  Initializes the FMC_SDRAM device according to the specified
784   *         control parameters in the FMC_SDRAM_InitTypeDef
785   * @param  Device Pointer to SDRAM device instance
786   * @param  Init Pointer to SDRAM Initialization structure
787   * @retval HAL status
788   */
FMC_SDRAM_Init(FMC_SDRAM_TypeDef * Device,const FMC_SDRAM_InitTypeDef * Init)789 HAL_StatusTypeDef FMC_SDRAM_Init(FMC_SDRAM_TypeDef *Device, const FMC_SDRAM_InitTypeDef *Init)
790 {
791   /* Check the parameters */
792   assert_param(IS_FMC_SDRAM_DEVICE(Device));
793   assert_param(IS_FMC_SDRAM_BANK(Init->SDBank));
794   assert_param(IS_FMC_COLUMNBITS_NUMBER(Init->ColumnBitsNumber));
795   assert_param(IS_FMC_ROWBITS_NUMBER(Init->RowBitsNumber));
796   assert_param(IS_FMC_SDMEMORY_WIDTH(Init->MemoryDataWidth));
797   assert_param(IS_FMC_INTERNALBANK_NUMBER(Init->InternalBankNumber));
798   assert_param(IS_FMC_CAS_LATENCY(Init->CASLatency));
799   assert_param(IS_FMC_WRITE_PROTECTION(Init->WriteProtection));
800   assert_param(IS_FMC_SDCLOCK_PERIOD(Init->SDClockPeriod));
801   assert_param(IS_FMC_READ_BURST(Init->ReadBurst));
802   assert_param(IS_FMC_READPIPE_DELAY(Init->ReadPipeDelay));
803 
804   /* Set SDRAM bank configuration parameters */
805   if (Init->SDBank == FMC_SDRAM_BANK1)
806   {
807     MODIFY_REG(Device->SDCR[FMC_SDRAM_BANK1],
808                SDCR_CLEAR_MASK,
809                (Init->ColumnBitsNumber   |
810                 Init->RowBitsNumber      |
811                 Init->MemoryDataWidth    |
812                 Init->InternalBankNumber |
813                 Init->CASLatency         |
814                 Init->WriteProtection    |
815                 Init->SDClockPeriod      |
816                 Init->ReadBurst          |
817                 Init->ReadPipeDelay));
818   }
819   else /* FMC_Bank2_SDRAM */
820   {
821     MODIFY_REG(Device->SDCR[FMC_SDRAM_BANK1],
822                FMC_SDCRx_SDCLK           |
823                FMC_SDCRx_RBURST          |
824                FMC_SDCRx_RPIPE,
825                (Init->SDClockPeriod      |
826                 Init->ReadBurst          |
827                 Init->ReadPipeDelay));
828 
829     MODIFY_REG(Device->SDCR[FMC_SDRAM_BANK2],
830                SDCR_CLEAR_MASK,
831                (Init->ColumnBitsNumber   |
832                 Init->RowBitsNumber      |
833                 Init->MemoryDataWidth    |
834                 Init->InternalBankNumber |
835                 Init->CASLatency         |
836                 Init->WriteProtection));
837   }
838 
839   return HAL_OK;
840 }
841 
842 
843 /**
844   * @brief  Initializes the FMC_SDRAM device timing according to the specified
845   *         parameters in the FMC_SDRAM_TimingTypeDef
846   * @param  Device Pointer to SDRAM device instance
847   * @param  Timing Pointer to SDRAM Timing structure
848   * @param  Bank SDRAM bank number
849   * @retval HAL status
850   */
FMC_SDRAM_Timing_Init(FMC_SDRAM_TypeDef * Device,const FMC_SDRAM_TimingTypeDef * Timing,uint32_t Bank)851 HAL_StatusTypeDef FMC_SDRAM_Timing_Init(FMC_SDRAM_TypeDef *Device,
852                                         const FMC_SDRAM_TimingTypeDef *Timing, uint32_t Bank)
853 {
854   /* Check the parameters */
855   assert_param(IS_FMC_SDRAM_DEVICE(Device));
856   assert_param(IS_FMC_LOADTOACTIVE_DELAY(Timing->LoadToActiveDelay));
857   assert_param(IS_FMC_EXITSELFREFRESH_DELAY(Timing->ExitSelfRefreshDelay));
858   assert_param(IS_FMC_SELFREFRESH_TIME(Timing->SelfRefreshTime));
859   assert_param(IS_FMC_ROWCYCLE_DELAY(Timing->RowCycleDelay));
860   assert_param(IS_FMC_WRITE_RECOVERY_TIME(Timing->WriteRecoveryTime));
861   assert_param(IS_FMC_RP_DELAY(Timing->RPDelay));
862   assert_param(IS_FMC_RCD_DELAY(Timing->RCDDelay));
863   assert_param(IS_FMC_SDRAM_BANK(Bank));
864 
865   /* Set SDRAM device timing parameters */
866   if (Bank == FMC_SDRAM_BANK1)
867   {
868     MODIFY_REG(Device->SDTR[FMC_SDRAM_BANK1],
869                SDTR_CLEAR_MASK,
870                (((Timing->LoadToActiveDelay) - 1U)                                      |
871                 (((Timing->ExitSelfRefreshDelay) - 1U) << FMC_SDTRx_TXSR_Pos) |
872                 (((Timing->SelfRefreshTime) - 1U)      << FMC_SDTRx_TRAS_Pos) |
873                 (((Timing->RowCycleDelay) - 1U)        << FMC_SDTRx_TRC_Pos)  |
874                 (((Timing->WriteRecoveryTime) - 1U)    << FMC_SDTRx_TWR_Pos)  |
875                 (((Timing->RPDelay) - 1U)              << FMC_SDTRx_TRP_Pos)  |
876                 (((Timing->RCDDelay) - 1U)             << FMC_SDTRx_TRCD_Pos)));
877   }
878   else /* FMC_Bank2_SDRAM */
879   {
880     MODIFY_REG(Device->SDTR[FMC_SDRAM_BANK1],
881                FMC_SDTRx_TRC |
882                FMC_SDTRx_TRP,
883                (((Timing->RowCycleDelay) - 1U)         << FMC_SDTRx_TRC_Pos)  |
884                (((Timing->RPDelay) - 1U)               << FMC_SDTRx_TRP_Pos));
885 
886     MODIFY_REG(Device->SDTR[FMC_SDRAM_BANK2],
887                SDTR_CLEAR_MASK,
888                (((Timing->LoadToActiveDelay) - 1U)                                      |
889                 (((Timing->ExitSelfRefreshDelay) - 1U) << FMC_SDTRx_TXSR_Pos) |
890                 (((Timing->SelfRefreshTime) - 1U)      << FMC_SDTRx_TRAS_Pos) |
891                 (((Timing->WriteRecoveryTime) - 1U)    << FMC_SDTRx_TWR_Pos)  |
892                 (((Timing->RCDDelay) - 1U)             << FMC_SDTRx_TRCD_Pos)));
893   }
894 
895   return HAL_OK;
896 }
897 
898 /**
899   * @brief  DeInitializes the FMC_SDRAM peripheral
900   * @param  Device Pointer to SDRAM device instance
901   * @retval HAL status
902   */
FMC_SDRAM_DeInit(FMC_SDRAM_TypeDef * Device,uint32_t Bank)903 HAL_StatusTypeDef FMC_SDRAM_DeInit(FMC_SDRAM_TypeDef *Device, uint32_t Bank)
904 {
905   /* Check the parameters */
906   assert_param(IS_FMC_SDRAM_DEVICE(Device));
907   assert_param(IS_FMC_SDRAM_BANK(Bank));
908 
909   /* De-initialize the SDRAM device */
910   Device->SDCR[Bank] = 0x000002D0U;
911   Device->SDTR[Bank] = 0x0FFFFFFFU;
912   Device->SDCMR      = 0x00000000U;
913   Device->SDRTR      = 0x00000000U;
914   Device->SDSR       = 0x00000000U;
915 
916   return HAL_OK;
917 }
918 
919 /**
920   * @}
921   */
922 
923 /** @addtogroup FMC_LL_SDRAMPrivate_Functions_Group2
924   *  @brief   management functions
925   *
926 @verbatim
927   ==============================================================================
928                       ##### FMC_SDRAM Control functions #####
929   ==============================================================================
930   [..]
931     This subsection provides a set of functions allowing to control dynamically
932     the FMC SDRAM interface.
933 
934 @endverbatim
935   * @{
936   */
937 
938 /**
939   * @brief  Enables dynamically FMC_SDRAM write protection.
940   * @param  Device Pointer to SDRAM device instance
941   * @param  Bank SDRAM bank number
942   * @retval HAL status
943   */
FMC_SDRAM_WriteProtection_Enable(FMC_SDRAM_TypeDef * Device,uint32_t Bank)944 HAL_StatusTypeDef FMC_SDRAM_WriteProtection_Enable(FMC_SDRAM_TypeDef *Device, uint32_t Bank)
945 {
946   /* Check the parameters */
947   assert_param(IS_FMC_SDRAM_DEVICE(Device));
948   assert_param(IS_FMC_SDRAM_BANK(Bank));
949 
950   /* Enable write protection */
951   SET_BIT(Device->SDCR[Bank], FMC_SDRAM_WRITE_PROTECTION_ENABLE);
952 
953   return HAL_OK;
954 }
955 
956 /**
957   * @brief  Disables dynamically FMC_SDRAM write protection.
958   * @param  hsdram FMC_SDRAM handle
959   * @retval HAL status
960   */
FMC_SDRAM_WriteProtection_Disable(FMC_SDRAM_TypeDef * Device,uint32_t Bank)961 HAL_StatusTypeDef FMC_SDRAM_WriteProtection_Disable(FMC_SDRAM_TypeDef *Device, uint32_t Bank)
962 {
963   /* Check the parameters */
964   assert_param(IS_FMC_SDRAM_DEVICE(Device));
965   assert_param(IS_FMC_SDRAM_BANK(Bank));
966 
967   /* Disable write protection */
968   CLEAR_BIT(Device->SDCR[Bank], FMC_SDRAM_WRITE_PROTECTION_ENABLE);
969 
970   return HAL_OK;
971 }
972 
973 /**
974   * @brief  Send Command to the FMC SDRAM bank
975   * @param  Device Pointer to SDRAM device instance
976   * @param  Command Pointer to SDRAM command structure
977   * @param  Timing Pointer to SDRAM Timing structure
978   * @param  Timeout Timeout wait value
979   * @retval HAL state
980   */
FMC_SDRAM_SendCommand(FMC_SDRAM_TypeDef * Device,const FMC_SDRAM_CommandTypeDef * Command,uint32_t Timeout)981 HAL_StatusTypeDef FMC_SDRAM_SendCommand(FMC_SDRAM_TypeDef *Device,
982                                         const FMC_SDRAM_CommandTypeDef *Command, uint32_t Timeout)
983 {
984   /* Check the parameters */
985   assert_param(IS_FMC_SDRAM_DEVICE(Device));
986   assert_param(IS_FMC_COMMAND_MODE(Command->CommandMode));
987   assert_param(IS_FMC_COMMAND_TARGET(Command->CommandTarget));
988   assert_param(IS_FMC_AUTOREFRESH_NUMBER(Command->AutoRefreshNumber));
989   assert_param(IS_FMC_MODE_REGISTER(Command->ModeRegisterDefinition));
990 
991   /* Set command register */
992   MODIFY_REG(Device->SDCMR, (FMC_SDCMR_MODE | FMC_SDCMR_CTB2 | FMC_SDCMR_CTB1 | FMC_SDCMR_NRFS | FMC_SDCMR_MRD),
993              ((Command->CommandMode) | (Command->CommandTarget) |
994               (((Command->AutoRefreshNumber) - 1U) << FMC_SDCMR_NRFS_Pos) |
995               ((Command->ModeRegisterDefinition) << FMC_SDCMR_MRD_Pos)));
996   /* Prevent unused argument(s) compilation warning */
997   UNUSED(Timeout);
998   return HAL_OK;
999 }
1000 
1001 /**
1002   * @brief  Program the SDRAM Memory Refresh rate.
1003   * @param  Device Pointer to SDRAM device instance
1004   * @param  RefreshRate The SDRAM refresh rate value.
1005   * @retval HAL state
1006   */
FMC_SDRAM_ProgramRefreshRate(FMC_SDRAM_TypeDef * Device,uint32_t RefreshRate)1007 HAL_StatusTypeDef FMC_SDRAM_ProgramRefreshRate(FMC_SDRAM_TypeDef *Device, uint32_t RefreshRate)
1008 {
1009   /* Check the parameters */
1010   assert_param(IS_FMC_SDRAM_DEVICE(Device));
1011   assert_param(IS_FMC_REFRESH_RATE(RefreshRate));
1012 
1013   /* Set the refresh rate in command register */
1014   MODIFY_REG(Device->SDRTR, FMC_SDRTR_COUNT, (RefreshRate << FMC_SDRTR_COUNT_Pos));
1015 
1016   return HAL_OK;
1017 }
1018 
1019 /**
1020   * @brief  Set the Number of consecutive SDRAM Memory auto Refresh commands.
1021   * @param  Device Pointer to SDRAM device instance
1022   * @param  AutoRefreshNumber Specifies the auto Refresh number.
1023   * @retval None
1024   */
FMC_SDRAM_SetAutoRefreshNumber(FMC_SDRAM_TypeDef * Device,uint32_t AutoRefreshNumber)1025 HAL_StatusTypeDef FMC_SDRAM_SetAutoRefreshNumber(FMC_SDRAM_TypeDef *Device,
1026                                                  uint32_t AutoRefreshNumber)
1027 {
1028   /* Check the parameters */
1029   assert_param(IS_FMC_SDRAM_DEVICE(Device));
1030   assert_param(IS_FMC_AUTOREFRESH_NUMBER(AutoRefreshNumber));
1031 
1032   /* Set the Auto-refresh number in command register */
1033   MODIFY_REG(Device->SDCMR, FMC_SDCMR_NRFS, ((AutoRefreshNumber - 1U) << FMC_SDCMR_NRFS_Pos));
1034 
1035   return HAL_OK;
1036 }
1037 
1038 /**
1039   * @brief  Returns the indicated FMC SDRAM bank mode status.
1040   * @param  Device Pointer to SDRAM device instance
1041   * @param  Bank Defines the FMC SDRAM bank. This parameter can be
1042   *                     FMC_Bank1_SDRAM or FMC_Bank2_SDRAM.
1043   * @retval The FMC SDRAM bank mode status, could be on of the following values:
1044   *         FMC_SDRAM_NORMAL_MODE, FMC_SDRAM_SELF_REFRESH_MODE or
1045   *         FMC_SDRAM_POWER_DOWN_MODE.
1046   */
FMC_SDRAM_GetModeStatus(const FMC_SDRAM_TypeDef * Device,uint32_t Bank)1047 uint32_t FMC_SDRAM_GetModeStatus(const FMC_SDRAM_TypeDef *Device, uint32_t Bank)
1048 {
1049   uint32_t tmpreg;
1050 
1051   /* Check the parameters */
1052   assert_param(IS_FMC_SDRAM_DEVICE(Device));
1053   assert_param(IS_FMC_SDRAM_BANK(Bank));
1054 
1055   /* Get the corresponding bank mode */
1056   if (Bank == FMC_SDRAM_BANK1)
1057   {
1058     tmpreg = (uint32_t)(Device->SDSR & FMC_SDSR_MODES1);
1059   }
1060   else
1061   {
1062     tmpreg = ((uint32_t)(Device->SDSR & FMC_SDSR_MODES2) >> 2U);
1063   }
1064 
1065   /* Return the mode status */
1066   return tmpreg;
1067 }
1068 
1069 /**
1070   * @}
1071   */
1072 
1073 /**
1074   * @}
1075   */
1076 
1077 
1078 /**
1079   * @}
1080   */
1081 
1082 /**
1083   * @}
1084   */
1085 
1086 #endif /* HAL_NOR_MODULE_ENABLED */
1087 /**
1088   * @}
1089   */
1090 /**
1091   * @}
1092   */
1093