]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_STM32F7_STM32756G-EVAL_IAR_Keil/ST_Library/stm32f7xx_hal_sram.c
Final V8.2.1 release ready for tagging:
[freertos] / FreeRTOS / Demo / CORTEX_M7_STM32F7_STM32756G-EVAL_IAR_Keil / ST_Library / stm32f7xx_hal_sram.c
1 /**\r
2   ******************************************************************************\r
3   * @file    stm32f7xx_hal_sram.c\r
4   * @author  MCD Application Team\r
5   * @version V1.0.0RC1\r
6   * @date    24-March-2015\r
7   * @brief   SRAM HAL module driver.\r
8   *          This file provides a generic firmware to drive SRAM memories  \r
9   *          mounted as external device.\r
10   *         \r
11   @verbatim\r
12   ==============================================================================\r
13                           ##### How to use this driver #####\r
14   ==============================================================================  \r
15   [..]\r
16     This driver is a generic layered driver which contains a set of APIs used to \r
17     control SRAM memories. It uses the FMC layer functions to interface \r
18     with SRAM devices.  \r
19     The following sequence should be followed to configure the FMC to interface\r
20     with SRAM/PSRAM memories: \r
21       \r
22    (#) Declare a SRAM_HandleTypeDef handle structure, for example:\r
23           SRAM_HandleTypeDef  hsram; and: \r
24           \r
25        (++) Fill the SRAM_HandleTypeDef handle "Init" field with the allowed \r
26             values of the structure member.\r
27             \r
28        (++) Fill the SRAM_HandleTypeDef handle "Instance" field with a predefined \r
29             base register instance for NOR or SRAM device \r
30                          \r
31        (++) Fill the SRAM_HandleTypeDef handle "Extended" field with a predefined\r
32             base register instance for NOR or SRAM extended mode \r
33              \r
34    (#) Declare two FMC_NORSRAM_TimingTypeDef structures, for both normal and extended \r
35        mode timings; for example:\r
36           FMC_NORSRAM_TimingTypeDef  Timing and FMC_NORSRAM_TimingTypeDef  ExTiming;\r
37       and fill its fields with the allowed values of the structure member.\r
38       \r
39    (#) Initialize the SRAM Controller by calling the function HAL_SRAM_Init(). This function\r
40        performs the following sequence:\r
41           \r
42        (##) MSP hardware layer configuration using the function HAL_SRAM_MspInit()\r
43        (##) Control register configuration using the FMC NORSRAM interface function \r
44             FMC_NORSRAM_Init()\r
45        (##) Timing register configuration using the FMC NORSRAM interface function \r
46             FMC_NORSRAM_Timing_Init()\r
47        (##) Extended mode Timing register configuration using the FMC NORSRAM interface function \r
48             FMC_NORSRAM_Extended_Timing_Init()\r
49        (##) Enable the SRAM device using the macro __FMC_NORSRAM_ENABLE()    \r
50 \r
51    (#) At this stage you can perform read/write accesses from/to the memory connected \r
52        to the NOR/SRAM Bank. You can perform either polling or DMA transfer using the\r
53        following APIs:\r
54        (++) HAL_SRAM_Read()/HAL_SRAM_Write() for polling read/write access\r
55        (++) HAL_SRAM_Read_DMA()/HAL_SRAM_Write_DMA() for DMA read/write transfer\r
56        \r
57    (#) You can also control the SRAM device by calling the control APIs HAL_SRAM_WriteOperation_Enable()/\r
58        HAL_SRAM_WriteOperation_Disable() to respectively enable/disable the SRAM write operation  \r
59        \r
60    (#) You can continuously monitor the SRAM device HAL state by calling the function\r
61        HAL_SRAM_GetState()              \r
62                              \r
63   @endverbatim\r
64   ******************************************************************************\r
65   * @attention\r
66   *\r
67   * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>\r
68   *\r
69   * Redistribution and use in source and binary forms, with or without modification,\r
70   * are permitted provided that the following conditions are met:\r
71   *   1. Redistributions of source code must retain the above copyright notice,\r
72   *      this list of conditions and the following disclaimer.\r
73   *   2. Redistributions in binary form must reproduce the above copyright notice,\r
74   *      this list of conditions and the following disclaimer in the documentation\r
75   *      and/or other materials provided with the distribution.\r
76   *   3. Neither the name of STMicroelectronics nor the names of its contributors\r
77   *      may be used to endorse or promote products derived from this software\r
78   *      without specific prior written permission.\r
79   *\r
80   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
81   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
82   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
83   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\r
84   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
85   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
86   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
87   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\r
88   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
89   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
90   *\r
91   ******************************************************************************\r
92   */ \r
93 \r
94 /* Includes ------------------------------------------------------------------*/\r
95 #include "stm32f7xx_hal.h"\r
96 \r
97 /** @addtogroup STM32F7xx_HAL_Driver\r
98   * @{\r
99   */\r
100 \r
101 /** @defgroup SRAM SRAM \r
102   * @brief SRAM driver modules\r
103   * @{\r
104   */\r
105 #ifdef HAL_SRAM_MODULE_ENABLED\r
106 /* Private typedef -----------------------------------------------------------*/\r
107 /* Private define ------------------------------------------------------------*/\r
108 /* Private macro -------------------------------------------------------------*/    \r
109 /* Private variables ---------------------------------------------------------*/\r
110 /* Private function prototypes -----------------------------------------------*/\r
111 /* Exported functions --------------------------------------------------------*/\r
112 \r
113 /** @defgroup SRAM_Exported_Functions SRAM Exported Functions\r
114   * @{\r
115   */\r
116 \r
117 /** @defgroup SRAM_Exported_Functions_Group1 Initialization and de-initialization functions\r
118   * @brief    Initialization and Configuration functions.\r
119   *\r
120   @verbatim    \r
121   ==============================================================================\r
122            ##### SRAM Initialization and de_initialization functions #####\r
123   ==============================================================================\r
124     [..]  This section provides functions allowing to initialize/de-initialize\r
125           the SRAM memory\r
126   \r
127 @endverbatim\r
128   * @{\r
129   */\r
130 \r
131 /**\r
132   * @brief  Performs the SRAM device initialization sequence\r
133   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains\r
134   *                the configuration information for SRAM module.\r
135   * @param  Timing: Pointer to SRAM control timing structure \r
136   * @param  ExtTiming: Pointer to SRAM extended mode timing structure  \r
137   * @retval HAL status\r
138   */\r
139 HAL_StatusTypeDef HAL_SRAM_Init(SRAM_HandleTypeDef *hsram, FMC_NORSRAM_TimingTypeDef *Timing, FMC_NORSRAM_TimingTypeDef *ExtTiming)\r
140\r
141   /* Check the SRAM handle parameter */\r
142   if(hsram == NULL)\r
143   {\r
144      return HAL_ERROR;\r
145   }\r
146   \r
147   if(hsram->State == HAL_SRAM_STATE_RESET)\r
148   {  \r
149     /* Initialize the low level hardware (MSP) */\r
150     HAL_SRAM_MspInit(hsram);\r
151   }\r
152   \r
153   /* Initialize SRAM control Interface */\r
154   FMC_NORSRAM_Init(hsram->Instance, &(hsram->Init));\r
155 \r
156   /* Initialize SRAM timing Interface */\r
157   FMC_NORSRAM_Timing_Init(hsram->Instance, Timing, hsram->Init.NSBank); \r
158 \r
159   /* Initialize SRAM extended mode timing Interface */\r
160   FMC_NORSRAM_Extended_Timing_Init(hsram->Extended, ExtTiming, hsram->Init.NSBank,  hsram->Init.ExtendedMode);  \r
161   \r
162   /* Enable the NORSRAM device */\r
163   __FMC_NORSRAM_ENABLE(hsram->Instance, hsram->Init.NSBank); \r
164   \r
165   return HAL_OK;\r
166 }\r
167 \r
168 /**\r
169   * @brief  Performs the SRAM device De-initialization sequence.\r
170   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains\r
171   *                the configuration information for SRAM module.\r
172   * @retval HAL status\r
173   */\r
174 HAL_StatusTypeDef  HAL_SRAM_DeInit(SRAM_HandleTypeDef *hsram)\r
175\r
176   /* De-Initialize the low level hardware (MSP) */\r
177   HAL_SRAM_MspDeInit(hsram);\r
178    \r
179   /* Configure the SRAM registers with their reset values */\r
180   FMC_NORSRAM_DeInit(hsram->Instance, hsram->Extended, hsram->Init.NSBank);\r
181 \r
182   hsram->State = HAL_SRAM_STATE_RESET;\r
183   \r
184   /* Release Lock */\r
185   __HAL_UNLOCK(hsram);\r
186 \r
187   return HAL_OK;\r
188 }\r
189 \r
190 /**\r
191   * @brief  SRAM MSP Init.\r
192   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains\r
193   *                the configuration information for SRAM module.\r
194   * @retval None\r
195   */\r
196 __weak void HAL_SRAM_MspInit(SRAM_HandleTypeDef *hsram)\r
197 {\r
198   /* NOTE : This function Should not be modified, when the callback is needed,\r
199             the HAL_SRAM_MspInit could be implemented in the user file\r
200    */ \r
201 }\r
202 \r
203 /**\r
204   * @brief  SRAM MSP DeInit.\r
205   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains\r
206   *                the configuration information for SRAM module.\r
207   * @retval None\r
208   */\r
209 __weak void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef *hsram)\r
210 {\r
211   /* NOTE : This function Should not be modified, when the callback is needed,\r
212             the HAL_SRAM_MspDeInit could be implemented in the user file\r
213    */ \r
214 }\r
215 \r
216 /**\r
217   * @brief  DMA transfer complete callback.\r
218   * @param  hdma: pointer to a SRAM_HandleTypeDef structure that contains\r
219   *                the configuration information for SRAM module.\r
220   * @retval None\r
221   */\r
222 __weak void HAL_SRAM_DMA_XferCpltCallback(DMA_HandleTypeDef *hdma)\r
223 {\r
224   /* NOTE : This function Should not be modified, when the callback is needed,\r
225             the HAL_SRAM_DMA_XferCpltCallback could be implemented in the user file\r
226    */ \r
227 }\r
228 \r
229 /**\r
230   * @brief  DMA transfer complete error callback.\r
231   * @param  hdma: pointer to a SRAM_HandleTypeDef structure that contains\r
232   *                the configuration information for SRAM module.\r
233   * @retval None\r
234   */\r
235 __weak void HAL_SRAM_DMA_XferErrorCallback(DMA_HandleTypeDef *hdma)\r
236 {\r
237   /* NOTE : This function Should not be modified, when the callback is needed,\r
238             the HAL_SRAM_DMA_XferErrorCallback could be implemented in the user file\r
239    */ \r
240 }\r
241 \r
242 /**\r
243   * @}\r
244   */\r
245 \r
246 /** @defgroup SRAM_Exported_Functions_Group2 Input Output and memory control functions \r
247   * @brief    Input Output and memory control functions \r
248   *\r
249   @verbatim    \r
250   ==============================================================================\r
251                   ##### SRAM Input and Output functions #####\r
252   ==============================================================================\r
253   [..]  \r
254     This section provides functions allowing to use and control the SRAM memory\r
255   \r
256 @endverbatim\r
257   * @{\r
258   */\r
259 \r
260 /**\r
261   * @brief  Reads 8-bit buffer from SRAM memory. \r
262   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains\r
263   *                the configuration information for SRAM module.\r
264   * @param  pAddress: Pointer to read start address\r
265   * @param  pDstBuffer: Pointer to destination buffer  \r
266   * @param  BufferSize: Size of the buffer to read from memory\r
267   * @retval HAL status\r
268   */\r
269 HAL_StatusTypeDef HAL_SRAM_Read_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pDstBuffer, uint32_t BufferSize)\r
270 {\r
271   __IO uint8_t * psramaddress = (uint8_t *)pAddress;\r
272   \r
273   /* Process Locked */\r
274   __HAL_LOCK(hsram);\r
275   \r
276   /* Update the SRAM controller state */\r
277   hsram->State = HAL_SRAM_STATE_BUSY;  \r
278   \r
279   /* Read data from memory */\r
280   for(; BufferSize != 0; BufferSize--)\r
281   {\r
282     *pDstBuffer = *(__IO uint8_t *)psramaddress;\r
283     pDstBuffer++;\r
284     psramaddress++;\r
285   }\r
286   \r
287   /* Update the SRAM controller state */\r
288   hsram->State = HAL_SRAM_STATE_READY;    \r
289 \r
290   /* Process unlocked */\r
291   __HAL_UNLOCK(hsram); \r
292     \r
293   return HAL_OK;   \r
294 }\r
295 \r
296 /**\r
297   * @brief  Writes 8-bit buffer to SRAM memory. \r
298   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains\r
299   *                the configuration information for SRAM module.\r
300   * @param  pAddress: Pointer to write start address\r
301   * @param  pSrcBuffer: Pointer to source buffer to write  \r
302   * @param  BufferSize: Size of the buffer to write to memory\r
303   * @retval HAL status\r
304   */\r
305 HAL_StatusTypeDef HAL_SRAM_Write_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pSrcBuffer, uint32_t BufferSize)\r
306 {\r
307   __IO uint8_t * psramaddress = (uint8_t *)pAddress;\r
308   \r
309   /* Check the SRAM controller state */\r
310   if(hsram->State == HAL_SRAM_STATE_PROTECTED)\r
311   {\r
312     return  HAL_ERROR; \r
313   }\r
314   \r
315   /* Process Locked */\r
316   __HAL_LOCK(hsram);\r
317   \r
318   /* Update the SRAM controller state */\r
319   hsram->State = HAL_SRAM_STATE_BUSY; \r
320 \r
321   /* Write data to memory */\r
322   for(; BufferSize != 0; BufferSize--)\r
323   {\r
324     *(__IO uint8_t *)psramaddress = *pSrcBuffer; \r
325     pSrcBuffer++;\r
326     psramaddress++;    \r
327   }    \r
328 \r
329   /* Update the SRAM controller state */\r
330   hsram->State = HAL_SRAM_STATE_READY; \r
331   \r
332   /* Process unlocked */\r
333   __HAL_UNLOCK(hsram);\r
334     \r
335   return HAL_OK;   \r
336 }\r
337 \r
338 /**\r
339   * @brief  Reads 16-bit buffer from SRAM memory. \r
340   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains\r
341   *                the configuration information for SRAM module.\r
342   * @param  pAddress: Pointer to read start address\r
343   * @param  pDstBuffer: Pointer to destination buffer  \r
344   * @param  BufferSize: Size of the buffer to read from memory\r
345   * @retval HAL status\r
346   */\r
347 HAL_StatusTypeDef HAL_SRAM_Read_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pDstBuffer, uint32_t BufferSize)\r
348 {\r
349   __IO uint16_t * psramaddress = (uint16_t *)pAddress;\r
350   \r
351   /* Process Locked */\r
352   __HAL_LOCK(hsram);\r
353   \r
354   /* Update the SRAM controller state */\r
355   hsram->State = HAL_SRAM_STATE_BUSY;  \r
356   \r
357   /* Read data from memory */\r
358   for(; BufferSize != 0; BufferSize--)\r
359   {\r
360     *pDstBuffer = *(__IO uint16_t *)psramaddress;\r
361     pDstBuffer++;\r
362     psramaddress++;\r
363   }\r
364   \r
365   /* Update the SRAM controller state */\r
366   hsram->State = HAL_SRAM_STATE_READY;    \r
367 \r
368   /* Process unlocked */\r
369   __HAL_UNLOCK(hsram); \r
370     \r
371   return HAL_OK;  \r
372 }\r
373 \r
374 /**\r
375   * @brief  Writes 16-bit buffer to SRAM memory. \r
376   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains\r
377   *                the configuration information for SRAM module.\r
378   * @param  pAddress: Pointer to write start address\r
379   * @param  pSrcBuffer: Pointer to source buffer to write  \r
380   * @param  BufferSize: Size of the buffer to write to memory\r
381   * @retval HAL status\r
382   */\r
383 HAL_StatusTypeDef HAL_SRAM_Write_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pSrcBuffer, uint32_t BufferSize)\r
384 {\r
385   __IO uint16_t * psramaddress = (uint16_t *)pAddress; \r
386   \r
387   /* Check the SRAM controller state */\r
388   if(hsram->State == HAL_SRAM_STATE_PROTECTED)\r
389   {\r
390     return  HAL_ERROR; \r
391   }\r
392   \r
393   /* Process Locked */\r
394   __HAL_LOCK(hsram);\r
395   \r
396   /* Update the SRAM controller state */\r
397   hsram->State = HAL_SRAM_STATE_BUSY; \r
398 \r
399   /* Write data to memory */\r
400   for(; BufferSize != 0; BufferSize--)\r
401   {\r
402     *(__IO uint16_t *)psramaddress = *pSrcBuffer; \r
403     pSrcBuffer++;\r
404     psramaddress++;    \r
405   }    \r
406 \r
407   /* Update the SRAM controller state */\r
408   hsram->State = HAL_SRAM_STATE_READY; \r
409   \r
410   /* Process unlocked */\r
411   __HAL_UNLOCK(hsram);\r
412     \r
413   return HAL_OK;  \r
414 }\r
415 \r
416 /**\r
417   * @brief  Reads 32-bit buffer from SRAM memory. \r
418   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains\r
419   *                the configuration information for SRAM module.\r
420   * @param  pAddress: Pointer to read start address\r
421   * @param  pDstBuffer: Pointer to destination buffer  \r
422   * @param  BufferSize: Size of the buffer to read from memory\r
423   * @retval HAL status\r
424   */\r
425 HAL_StatusTypeDef HAL_SRAM_Read_32b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pDstBuffer, uint32_t BufferSize)\r
426 {\r
427   /* Process Locked */\r
428   __HAL_LOCK(hsram);\r
429   \r
430   /* Update the SRAM controller state */\r
431   hsram->State = HAL_SRAM_STATE_BUSY;  \r
432   \r
433   /* Read data from memory */\r
434   for(; BufferSize != 0; BufferSize--)\r
435   {\r
436     *pDstBuffer = *(__IO uint32_t *)pAddress;\r
437     pDstBuffer++;\r
438     pAddress++;\r
439   }\r
440   \r
441   /* Update the SRAM controller state */\r
442   hsram->State = HAL_SRAM_STATE_READY;    \r
443 \r
444   /* Process unlocked */\r
445   __HAL_UNLOCK(hsram); \r
446     \r
447   return HAL_OK;  \r
448 }\r
449 \r
450 /**\r
451   * @brief  Writes 32-bit buffer to SRAM memory. \r
452   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains\r
453   *                the configuration information for SRAM module.\r
454   * @param  pAddress: Pointer to write start address\r
455   * @param  pSrcBuffer: Pointer to source buffer to write  \r
456   * @param  BufferSize: Size of the buffer to write to memory\r
457   * @retval HAL status\r
458   */\r
459 HAL_StatusTypeDef HAL_SRAM_Write_32b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pSrcBuffer, uint32_t BufferSize)\r
460 {\r
461   /* Check the SRAM controller state */\r
462   if(hsram->State == HAL_SRAM_STATE_PROTECTED)\r
463   {\r
464     return  HAL_ERROR; \r
465   }\r
466   \r
467   /* Process Locked */\r
468   __HAL_LOCK(hsram);\r
469   \r
470   /* Update the SRAM controller state */\r
471   hsram->State = HAL_SRAM_STATE_BUSY; \r
472 \r
473   /* Write data to memory */\r
474   for(; BufferSize != 0; BufferSize--)\r
475   {\r
476     *(__IO uint32_t *)pAddress = *pSrcBuffer; \r
477     pSrcBuffer++;\r
478     pAddress++;    \r
479   }    \r
480 \r
481   /* Update the SRAM controller state */\r
482   hsram->State = HAL_SRAM_STATE_READY; \r
483   \r
484   /* Process unlocked */\r
485   __HAL_UNLOCK(hsram);\r
486     \r
487   return HAL_OK;   \r
488 }\r
489 \r
490 /**\r
491   * @brief  Reads a Words data from the SRAM memory using DMA transfer.\r
492   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains\r
493   *                the configuration information for SRAM module.\r
494   * @param  pAddress: Pointer to read start address\r
495   * @param  pDstBuffer: Pointer to destination buffer  \r
496   * @param  BufferSize: Size of the buffer to read from memory\r
497   * @retval HAL status\r
498   */\r
499 HAL_StatusTypeDef HAL_SRAM_Read_DMA(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pDstBuffer, uint32_t BufferSize)\r
500 {\r
501   /* Process Locked */\r
502   __HAL_LOCK(hsram);  \r
503   \r
504   /* Update the SRAM controller state */\r
505   hsram->State = HAL_SRAM_STATE_BUSY;   \r
506   \r
507   /* Configure DMA user callbacks */\r
508   hsram->hdma->XferCpltCallback  = HAL_SRAM_DMA_XferCpltCallback;\r
509   hsram->hdma->XferErrorCallback = HAL_SRAM_DMA_XferErrorCallback;\r
510 \r
511   /* Enable the DMA Stream */\r
512   HAL_DMA_Start_IT(hsram->hdma, (uint32_t)pAddress, (uint32_t)pDstBuffer, (uint32_t)BufferSize);\r
513   \r
514   /* Update the SRAM controller state */\r
515   hsram->State = HAL_SRAM_STATE_READY; \r
516   \r
517   /* Process unlocked */\r
518   __HAL_UNLOCK(hsram);  \r
519   \r
520   return HAL_OK; \r
521 }\r
522 \r
523 /**\r
524   * @brief  Writes a Words data buffer to SRAM memory using DMA transfer.\r
525   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains\r
526   *                the configuration information for SRAM module.\r
527   * @param  pAddress: Pointer to write start address\r
528   * @param  pSrcBuffer: Pointer to source buffer to write  \r
529   * @param  BufferSize: Size of the buffer to write to memory\r
530   * @retval HAL status\r
531   */\r
532 HAL_StatusTypeDef HAL_SRAM_Write_DMA(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pSrcBuffer, uint32_t BufferSize)\r
533 {\r
534   /* Check the SRAM controller state */\r
535   if(hsram->State == HAL_SRAM_STATE_PROTECTED)\r
536   {\r
537     return  HAL_ERROR; \r
538   }\r
539   \r
540   /* Process Locked */\r
541   __HAL_LOCK(hsram);\r
542   \r
543   /* Update the SRAM controller state */\r
544   hsram->State = HAL_SRAM_STATE_BUSY; \r
545   \r
546   /* Configure DMA user callbacks */\r
547   hsram->hdma->XferCpltCallback  = HAL_SRAM_DMA_XferCpltCallback;\r
548   hsram->hdma->XferErrorCallback = HAL_SRAM_DMA_XferErrorCallback;\r
549 \r
550   /* Enable the DMA Stream */\r
551   HAL_DMA_Start_IT(hsram->hdma, (uint32_t)pSrcBuffer, (uint32_t)pAddress, (uint32_t)BufferSize);\r
552   \r
553   /* Update the SRAM controller state */\r
554   hsram->State = HAL_SRAM_STATE_READY;  \r
555   \r
556   /* Process unlocked */\r
557   __HAL_UNLOCK(hsram);  \r
558   \r
559   return HAL_OK;\r
560 }\r
561 \r
562 /**\r
563   * @}\r
564   */\r
565   \r
566 /** @defgroup SRAM_Exported_Functions_Group3 Control functions \r
567  *  @brief   Control functions \r
568  *\r
569 @verbatim   \r
570   ==============================================================================\r
571                         ##### SRAM Control functions #####\r
572   ==============================================================================  \r
573   [..]\r
574     This subsection provides a set of functions allowing to control dynamically\r
575     the SRAM interface.\r
576 \r
577 @endverbatim\r
578   * @{\r
579   */\r
580     \r
581 /**\r
582   * @brief  Enables dynamically SRAM write operation.\r
583   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains\r
584   *                the configuration information for SRAM module.\r
585   * @retval HAL status\r
586   */\r
587 HAL_StatusTypeDef HAL_SRAM_WriteOperation_Enable(SRAM_HandleTypeDef *hsram)\r
588 {\r
589   /* Process Locked */\r
590   __HAL_LOCK(hsram);\r
591 \r
592   /* Enable write operation */\r
593   FMC_NORSRAM_WriteOperation_Enable(hsram->Instance, hsram->Init.NSBank); \r
594   \r
595   /* Update the SRAM controller state */\r
596   hsram->State = HAL_SRAM_STATE_READY;\r
597   \r
598   /* Process unlocked */\r
599   __HAL_UNLOCK(hsram); \r
600   \r
601   return HAL_OK;  \r
602 }\r
603 \r
604 /**\r
605   * @brief  Disables dynamically SRAM write operation.\r
606   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains\r
607   *                the configuration information for SRAM module.\r
608   * @retval HAL status\r
609   */\r
610 HAL_StatusTypeDef HAL_SRAM_WriteOperation_Disable(SRAM_HandleTypeDef *hsram)\r
611 {\r
612   /* Process Locked */\r
613   __HAL_LOCK(hsram);\r
614 \r
615   /* Update the SRAM controller state */\r
616   hsram->State = HAL_SRAM_STATE_BUSY;\r
617     \r
618   /* Disable write operation */\r
619   FMC_NORSRAM_WriteOperation_Disable(hsram->Instance, hsram->Init.NSBank); \r
620   \r
621   /* Update the SRAM controller state */\r
622   hsram->State = HAL_SRAM_STATE_PROTECTED;\r
623   \r
624   /* Process unlocked */\r
625   __HAL_UNLOCK(hsram); \r
626   \r
627   return HAL_OK;  \r
628 }\r
629 \r
630 /**\r
631   * @}\r
632   */\r
633 \r
634 /** @defgroup SRAM_Exported_Functions_Group4 Peripheral State functions \r
635  *  @brief   Peripheral State functions \r
636  *\r
637 @verbatim   \r
638   ==============================================================================\r
639                       ##### SRAM State functions #####\r
640   ==============================================================================  \r
641   [..]\r
642     This subsection permits to get in run-time the status of the SRAM controller \r
643     and the data flow.\r
644 \r
645 @endverbatim\r
646   * @{\r
647   */\r
648   \r
649 /**\r
650   * @brief  Returns the SRAM controller state\r
651   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains\r
652   *                the configuration information for SRAM module.\r
653   * @retval HAL state\r
654   */\r
655 HAL_SRAM_StateTypeDef HAL_SRAM_GetState(SRAM_HandleTypeDef *hsram)\r
656 {\r
657   return hsram->State;\r
658 }\r
659 \r
660 /**\r
661   * @}\r
662   */\r
663 \r
664 /**\r
665   * @}\r
666   */\r
667 #endif /* HAL_SRAM_MODULE_ENABLED */\r
668 /**\r
669   * @}\r
670   */\r
671 \r
672 /**\r
673   * @}\r
674   */\r
675 \r
676 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/\r