2 ******************************************************************************
3 * @file stm32f7xx_hal_sram.c
4 * @author MCD Application Team
5 * @brief SRAM HAL module driver.
6 * This file provides a generic firmware to drive SRAM memories
7 * mounted as external device.
10 ==============================================================================
11 ##### How to use this driver #####
12 ==============================================================================
14 This driver is a generic layered driver which contains a set of APIs used to
15 control SRAM memories. It uses the FMC layer functions to interface
17 The following sequence should be followed to configure the FMC to interface
18 with SRAM/PSRAM memories:
20 (#) Declare a SRAM_HandleTypeDef handle structure, for example:
21 SRAM_HandleTypeDef hsram; and:
23 (++) Fill the SRAM_HandleTypeDef handle "Init" field with the allowed
24 values of the structure member.
26 (++) Fill the SRAM_HandleTypeDef handle "Instance" field with a predefined
27 base register instance for NOR or SRAM device
29 (++) Fill the SRAM_HandleTypeDef handle "Extended" field with a predefined
30 base register instance for NOR or SRAM extended mode
32 (#) Declare two FMC_NORSRAM_TimingTypeDef structures, for both normal and extended
33 mode timings; for example:
34 FMC_NORSRAM_TimingTypeDef Timing and FMC_NORSRAM_TimingTypeDef ExTiming;
35 and fill its fields with the allowed values of the structure member.
37 (#) Initialize the SRAM Controller by calling the function HAL_SRAM_Init(). This function
38 performs the following sequence:
40 (##) MSP hardware layer configuration using the function HAL_SRAM_MspInit()
41 (##) Control register configuration using the FMC NORSRAM interface function
43 (##) Timing register configuration using the FMC NORSRAM interface function
44 FMC_NORSRAM_Timing_Init()
45 (##) Extended mode Timing register configuration using the FMC NORSRAM interface function
46 FMC_NORSRAM_Extended_Timing_Init()
47 (##) Enable the SRAM device using the macro __FMC_NORSRAM_ENABLE()
49 (#) At this stage you can perform read/write accesses from/to the memory connected
50 to the NOR/SRAM Bank. You can perform either polling or DMA transfer using the
52 (++) HAL_SRAM_Read()/HAL_SRAM_Write() for polling read/write access
53 (++) HAL_SRAM_Read_DMA()/HAL_SRAM_Write_DMA() for DMA read/write transfer
55 (#) You can also control the SRAM device by calling the control APIs HAL_SRAM_WriteOperation_Enable()/
56 HAL_SRAM_WriteOperation_Disable() to respectively enable/disable the SRAM write operation
58 (#) You can continuously monitor the SRAM device HAL state by calling the function
61 *** Callback registration ***
62 =============================================
64 The compilation define USE_HAL_SRAM_REGISTER_CALLBACKS when set to 1
65 allows the user to configure dynamically the driver callbacks.
67 Use Functions @ref HAL_SRAM_RegisterCallback() to register a user callback,
68 it allows to register following callbacks:
69 (+) MspInitCallback : SRAM MspInit.
70 (+) MspDeInitCallback : SRAM MspDeInit.
71 This function takes as parameters the HAL peripheral handle, the Callback ID
72 and a pointer to the user callback function.
74 Use function @ref HAL_SRAM_UnRegisterCallback() to reset a callback to the default
75 weak (surcharged) function. It allows to reset following callbacks:
76 (+) MspInitCallback : SRAM MspInit.
77 (+) MspDeInitCallback : SRAM MspDeInit.
78 This function) takes as parameters the HAL peripheral handle and the Callback ID.
80 By default, after the @ref HAL_SRAM_Init and if the state is HAL_SRAM_STATE_RESET
81 all callbacks are reset to the corresponding legacy weak (surcharged) functions.
82 Exception done for MspInit and MspDeInit callbacks that are respectively
83 reset to the legacy weak (surcharged) functions in the @ref HAL_SRAM_Init
84 and @ref HAL_SRAM_DeInit only when these callbacks are null (not registered beforehand).
85 If not, MspInit or MspDeInit are not null, the @ref HAL_SRAM_Init and @ref HAL_SRAM_DeInit
86 keep and use the user MspInit/MspDeInit callbacks (registered beforehand)
88 Callbacks can be registered/unregistered in READY state only.
89 Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
90 in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
91 during the Init/DeInit.
92 In that case first register the MspInit/MspDeInit user callbacks
93 using @ref HAL_SRAM_RegisterCallback before calling @ref HAL_SRAM_DeInit
94 or @ref HAL_SRAM_Init function.
96 When The compilation define USE_HAL_SRAM_REGISTER_CALLBACKS is set to 0 or
97 not defined, the callback registering feature is not available
98 and weak (surcharged) callbacks are used.
101 ******************************************************************************
104 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
105 * All rights reserved.</center></h2>
107 * This software component is licensed by ST under BSD 3-Clause license,
108 * the "License"; You may not use this file except in compliance with the
109 * License. You may obtain a copy of the License at:
110 * opensource.org/licenses/BSD-3-Clause
112 ******************************************************************************
115 /* Includes ------------------------------------------------------------------*/
116 #include "stm32f7xx_hal.h"
118 /** @addtogroup STM32F7xx_HAL_Driver
122 /** @defgroup SRAM SRAM
123 * @brief SRAM driver modules
126 #ifdef HAL_SRAM_MODULE_ENABLED
127 /* Private typedef -----------------------------------------------------------*/
128 /* Private define ------------------------------------------------------------*/
129 /* Private macro -------------------------------------------------------------*/
130 /* Private variables ---------------------------------------------------------*/
131 /* Private function prototypes -----------------------------------------------*/
132 /* Exported functions --------------------------------------------------------*/
134 /** @defgroup SRAM_Exported_Functions SRAM Exported Functions
138 /** @defgroup SRAM_Exported_Functions_Group1 Initialization and de-initialization functions
139 * @brief Initialization and Configuration functions.
142 ==============================================================================
143 ##### SRAM Initialization and de_initialization functions #####
144 ==============================================================================
145 [..] This section provides functions allowing to initialize/de-initialize
153 * @brief Performs the SRAM device initialization sequence
154 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
155 * the configuration information for SRAM module.
156 * @param Timing Pointer to SRAM control timing structure
157 * @param ExtTiming Pointer to SRAM extended mode timing structure
160 HAL_StatusTypeDef
HAL_SRAM_Init(SRAM_HandleTypeDef
*hsram
, FMC_NORSRAM_TimingTypeDef
*Timing
, FMC_NORSRAM_TimingTypeDef
*ExtTiming
)
162 /* Check the SRAM handle parameter */
168 if(hsram
->State
== HAL_SRAM_STATE_RESET
)
170 /* Allocate lock resource and initialize it */
171 hsram
->Lock
= HAL_UNLOCKED
;
173 #if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
174 if(hsram
->MspInitCallback
== NULL
)
176 hsram
->MspInitCallback
= HAL_SRAM_MspInit
;
178 hsram
->DmaXferCpltCallback
= HAL_SRAM_DMA_XferCpltCallback
;
179 hsram
->DmaXferErrorCallback
= HAL_SRAM_DMA_XferErrorCallback
;
181 /* Init the low level hardware */
182 hsram
->MspInitCallback(hsram
);
184 /* Initialize the low level hardware (MSP) */
185 HAL_SRAM_MspInit(hsram
);
189 /* Initialize SRAM control Interface */
190 FMC_NORSRAM_Init(hsram
->Instance
, &(hsram
->Init
));
192 /* Initialize SRAM timing Interface */
193 FMC_NORSRAM_Timing_Init(hsram
->Instance
, Timing
, hsram
->Init
.NSBank
);
195 /* Initialize SRAM extended mode timing Interface */
196 FMC_NORSRAM_Extended_Timing_Init(hsram
->Extended
, ExtTiming
, hsram
->Init
.NSBank
, hsram
->Init
.ExtendedMode
);
198 /* Enable the NORSRAM device */
199 __FMC_NORSRAM_ENABLE(hsram
->Instance
, hsram
->Init
.NSBank
);
205 * @brief Performs the SRAM device De-initialization sequence.
206 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
207 * the configuration information for SRAM module.
210 HAL_StatusTypeDef
HAL_SRAM_DeInit(SRAM_HandleTypeDef
*hsram
)
212 #if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
213 if(hsram
->MspDeInitCallback
== NULL
)
215 hsram
->MspDeInitCallback
= HAL_SRAM_MspDeInit
;
218 /* DeInit the low level hardware */
219 hsram
->MspDeInitCallback(hsram
);
221 /* De-Initialize the low level hardware (MSP) */
222 HAL_SRAM_MspDeInit(hsram
);
225 /* Configure the SRAM registers with their reset values */
226 FMC_NORSRAM_DeInit(hsram
->Instance
, hsram
->Extended
, hsram
->Init
.NSBank
);
228 hsram
->State
= HAL_SRAM_STATE_RESET
;
237 * @brief SRAM MSP Init.
238 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
239 * the configuration information for SRAM module.
242 __weak
void HAL_SRAM_MspInit(SRAM_HandleTypeDef
*hsram
)
244 /* Prevent unused argument(s) compilation warning */
247 /* NOTE : This function Should not be modified, when the callback is needed,
248 the HAL_SRAM_MspInit could be implemented in the user file
253 * @brief SRAM MSP DeInit.
254 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
255 * the configuration information for SRAM module.
258 __weak
void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef
*hsram
)
260 /* Prevent unused argument(s) compilation warning */
263 /* NOTE : This function Should not be modified, when the callback is needed,
264 the HAL_SRAM_MspDeInit could be implemented in the user file
269 * @brief DMA transfer complete callback.
270 * @param hdma pointer to a SRAM_HandleTypeDef structure that contains
271 * the configuration information for SRAM module.
274 __weak
void HAL_SRAM_DMA_XferCpltCallback(DMA_HandleTypeDef
*hdma
)
276 /* Prevent unused argument(s) compilation warning */
279 /* NOTE : This function Should not be modified, when the callback is needed,
280 the HAL_SRAM_DMA_XferCpltCallback could be implemented in the user file
285 * @brief DMA transfer complete error callback.
286 * @param hdma pointer to a SRAM_HandleTypeDef structure that contains
287 * the configuration information for SRAM module.
290 __weak
void HAL_SRAM_DMA_XferErrorCallback(DMA_HandleTypeDef
*hdma
)
292 /* Prevent unused argument(s) compilation warning */
295 /* NOTE : This function Should not be modified, when the callback is needed,
296 the HAL_SRAM_DMA_XferErrorCallback could be implemented in the user file
304 /** @defgroup SRAM_Exported_Functions_Group2 Input Output and memory control functions
305 * @brief Input Output and memory control functions
308 ==============================================================================
309 ##### SRAM Input and Output functions #####
310 ==============================================================================
312 This section provides functions allowing to use and control the SRAM memory
319 * @brief Reads 8-bit buffer from SRAM memory.
320 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
321 * the configuration information for SRAM module.
322 * @param pAddress Pointer to read start address
323 * @param pDstBuffer Pointer to destination buffer
324 * @param BufferSize Size of the buffer to read from memory
327 HAL_StatusTypeDef
HAL_SRAM_Read_8b(SRAM_HandleTypeDef
*hsram
, uint32_t *pAddress
, uint8_t *pDstBuffer
, uint32_t BufferSize
)
329 __IO
uint8_t * psramaddress
= (uint8_t *)pAddress
;
334 /* Update the SRAM controller state */
335 hsram
->State
= HAL_SRAM_STATE_BUSY
;
337 /* Read data from memory */
338 for(; BufferSize
!= 0; BufferSize
--)
340 *pDstBuffer
= *(__IO
uint8_t *)psramaddress
;
345 /* Update the SRAM controller state */
346 hsram
->State
= HAL_SRAM_STATE_READY
;
348 /* Process unlocked */
355 * @brief Writes 8-bit buffer to SRAM memory.
356 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
357 * the configuration information for SRAM module.
358 * @param pAddress Pointer to write start address
359 * @param pSrcBuffer Pointer to source buffer to write
360 * @param BufferSize Size of the buffer to write to memory
363 HAL_StatusTypeDef
HAL_SRAM_Write_8b(SRAM_HandleTypeDef
*hsram
, uint32_t *pAddress
, uint8_t *pSrcBuffer
, uint32_t BufferSize
)
365 __IO
uint8_t * psramaddress
= (uint8_t *)pAddress
;
367 /* Check the SRAM controller state */
368 if(hsram
->State
== HAL_SRAM_STATE_PROTECTED
)
376 /* Update the SRAM controller state */
377 hsram
->State
= HAL_SRAM_STATE_BUSY
;
379 /* Write data to memory */
380 for(; BufferSize
!= 0; BufferSize
--)
382 *(__IO
uint8_t *)psramaddress
= *pSrcBuffer
;
387 /* Update the SRAM controller state */
388 hsram
->State
= HAL_SRAM_STATE_READY
;
390 /* Process unlocked */
397 * @brief Reads 16-bit buffer from SRAM memory.
398 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
399 * the configuration information for SRAM module.
400 * @param pAddress Pointer to read start address
401 * @param pDstBuffer Pointer to destination buffer
402 * @param BufferSize Size of the buffer to read from memory
405 HAL_StatusTypeDef
HAL_SRAM_Read_16b(SRAM_HandleTypeDef
*hsram
, uint32_t *pAddress
, uint16_t *pDstBuffer
, uint32_t BufferSize
)
407 __IO
uint16_t * psramaddress
= (uint16_t *)pAddress
;
412 /* Update the SRAM controller state */
413 hsram
->State
= HAL_SRAM_STATE_BUSY
;
415 /* Read data from memory */
416 for(; BufferSize
!= 0; BufferSize
--)
418 *pDstBuffer
= *(__IO
uint16_t *)psramaddress
;
423 /* Update the SRAM controller state */
424 hsram
->State
= HAL_SRAM_STATE_READY
;
426 /* Process unlocked */
433 * @brief Writes 16-bit buffer to SRAM memory.
434 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
435 * the configuration information for SRAM module.
436 * @param pAddress Pointer to write start address
437 * @param pSrcBuffer Pointer to source buffer to write
438 * @param BufferSize Size of the buffer to write to memory
441 HAL_StatusTypeDef
HAL_SRAM_Write_16b(SRAM_HandleTypeDef
*hsram
, uint32_t *pAddress
, uint16_t *pSrcBuffer
, uint32_t BufferSize
)
443 __IO
uint16_t * psramaddress
= (uint16_t *)pAddress
;
445 /* Check the SRAM controller state */
446 if(hsram
->State
== HAL_SRAM_STATE_PROTECTED
)
454 /* Update the SRAM controller state */
455 hsram
->State
= HAL_SRAM_STATE_BUSY
;
457 /* Write data to memory */
458 for(; BufferSize
!= 0; BufferSize
--)
460 *(__IO
uint16_t *)psramaddress
= *pSrcBuffer
;
465 /* Update the SRAM controller state */
466 hsram
->State
= HAL_SRAM_STATE_READY
;
468 /* Process unlocked */
475 * @brief Reads 32-bit buffer from SRAM memory.
476 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
477 * the configuration information for SRAM module.
478 * @param pAddress Pointer to read start address
479 * @param pDstBuffer Pointer to destination buffer
480 * @param BufferSize Size of the buffer to read from memory
483 HAL_StatusTypeDef
HAL_SRAM_Read_32b(SRAM_HandleTypeDef
*hsram
, uint32_t *pAddress
, uint32_t *pDstBuffer
, uint32_t BufferSize
)
488 /* Update the SRAM controller state */
489 hsram
->State
= HAL_SRAM_STATE_BUSY
;
491 /* Read data from memory */
492 for(; BufferSize
!= 0; BufferSize
--)
494 *pDstBuffer
= *(__IO
uint32_t *)pAddress
;
499 /* Update the SRAM controller state */
500 hsram
->State
= HAL_SRAM_STATE_READY
;
502 /* Process unlocked */
509 * @brief Writes 32-bit buffer to SRAM memory.
510 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
511 * the configuration information for SRAM module.
512 * @param pAddress Pointer to write start address
513 * @param pSrcBuffer Pointer to source buffer to write
514 * @param BufferSize Size of the buffer to write to memory
517 HAL_StatusTypeDef
HAL_SRAM_Write_32b(SRAM_HandleTypeDef
*hsram
, uint32_t *pAddress
, uint32_t *pSrcBuffer
, uint32_t BufferSize
)
519 /* Check the SRAM controller state */
520 if(hsram
->State
== HAL_SRAM_STATE_PROTECTED
)
528 /* Update the SRAM controller state */
529 hsram
->State
= HAL_SRAM_STATE_BUSY
;
531 /* Write data to memory */
532 for(; BufferSize
!= 0; BufferSize
--)
534 *(__IO
uint32_t *)pAddress
= *pSrcBuffer
;
539 /* Update the SRAM controller state */
540 hsram
->State
= HAL_SRAM_STATE_READY
;
542 /* Process unlocked */
549 * @brief Reads a Words data from the SRAM memory using DMA transfer.
550 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
551 * the configuration information for SRAM module.
552 * @param pAddress Pointer to read start address
553 * @param pDstBuffer Pointer to destination buffer
554 * @param BufferSize Size of the buffer to read from memory
557 HAL_StatusTypeDef
HAL_SRAM_Read_DMA(SRAM_HandleTypeDef
*hsram
, uint32_t *pAddress
, uint32_t *pDstBuffer
, uint32_t BufferSize
)
562 /* Update the SRAM controller state */
563 hsram
->State
= HAL_SRAM_STATE_BUSY
;
565 /* Configure DMA user callbacks */
566 hsram
->hdma
->XferCpltCallback
= HAL_SRAM_DMA_XferCpltCallback
;
567 hsram
->hdma
->XferErrorCallback
= HAL_SRAM_DMA_XferErrorCallback
;
569 /* Enable the DMA Stream */
570 HAL_DMA_Start_IT(hsram
->hdma
, (uint32_t)pAddress
, (uint32_t)pDstBuffer
, (uint32_t)BufferSize
);
572 /* Update the SRAM controller state */
573 hsram
->State
= HAL_SRAM_STATE_READY
;
575 /* Process unlocked */
582 * @brief Writes a Words data buffer to SRAM memory using DMA transfer.
583 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
584 * the configuration information for SRAM module.
585 * @param pAddress Pointer to write start address
586 * @param pSrcBuffer Pointer to source buffer to write
587 * @param BufferSize Size of the buffer to write to memory
590 HAL_StatusTypeDef
HAL_SRAM_Write_DMA(SRAM_HandleTypeDef
*hsram
, uint32_t *pAddress
, uint32_t *pSrcBuffer
, uint32_t BufferSize
)
592 /* Check the SRAM controller state */
593 if(hsram
->State
== HAL_SRAM_STATE_PROTECTED
)
601 /* Update the SRAM controller state */
602 hsram
->State
= HAL_SRAM_STATE_BUSY
;
604 /* Configure DMA user callbacks */
605 hsram
->hdma
->XferCpltCallback
= HAL_SRAM_DMA_XferCpltCallback
;
606 hsram
->hdma
->XferErrorCallback
= HAL_SRAM_DMA_XferErrorCallback
;
608 /* Enable the DMA Stream */
609 HAL_DMA_Start_IT(hsram
->hdma
, (uint32_t)pSrcBuffer
, (uint32_t)pAddress
, (uint32_t)BufferSize
);
611 /* Update the SRAM controller state */
612 hsram
->State
= HAL_SRAM_STATE_READY
;
614 /* Process unlocked */
620 #if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
622 * @brief Register a User SRAM Callback
623 * To be used instead of the weak (surcharged) predefined callback
624 * @param hsram : SRAM handle
625 * @param CallbackId : ID of the callback to be registered
626 * This parameter can be one of the following values:
627 * @arg @ref HAL_SRAM_MSP_INIT_CB_ID SRAM MspInit callback ID
628 * @arg @ref HAL_SRAM_MSP_DEINIT_CB_ID SRAM MspDeInit callback ID
629 * @param pCallback : pointer to the Callback function
632 HAL_StatusTypeDef
HAL_SRAM_RegisterCallback (SRAM_HandleTypeDef
*hsram
, HAL_SRAM_CallbackIDTypeDef CallbackId
, pSRAM_CallbackTypeDef pCallback
)
634 HAL_StatusTypeDef status
= HAL_OK
;
635 HAL_SRAM_StateTypeDef state
;
637 if(pCallback
== NULL
)
645 state
= hsram
->State
;
646 if((state
== HAL_SRAM_STATE_READY
) || (state
== HAL_SRAM_STATE_RESET
) || (state
== HAL_SRAM_STATE_PROTECTED
))
650 case HAL_SRAM_MSP_INIT_CB_ID
:
651 hsram
->MspInitCallback
= pCallback
;
653 case HAL_SRAM_MSP_DEINIT_CB_ID
:
654 hsram
->MspDeInitCallback
= pCallback
;
657 /* update return status */
664 /* update return status */
674 * @brief Unregister a User SRAM Callback
675 * SRAM Callback is redirected to the weak (surcharged) predefined callback
676 * @param hsram : SRAM handle
677 * @param CallbackId : ID of the callback to be unregistered
678 * This parameter can be one of the following values:
679 * @arg @ref HAL_SRAM_MSP_INIT_CB_ID SRAM MspInit callback ID
680 * @arg @ref HAL_SRAM_MSP_DEINIT_CB_ID SRAM MspDeInit callback ID
681 * @arg @ref HAL_SRAM_DMA_XFER_CPLT_CB_ID SRAM DMA Xfer Complete callback ID
682 * @arg @ref HAL_SRAM_DMA_XFER_ERR_CB_ID SRAM DMA Xfer Error callback ID
685 HAL_StatusTypeDef
HAL_SRAM_UnRegisterCallback (SRAM_HandleTypeDef
*hsram
, HAL_SRAM_CallbackIDTypeDef CallbackId
)
687 HAL_StatusTypeDef status
= HAL_OK
;
688 HAL_SRAM_StateTypeDef state
;
693 state
= hsram
->State
;
694 if((state
== HAL_SRAM_STATE_READY
) || (state
== HAL_SRAM_STATE_PROTECTED
))
698 case HAL_SRAM_MSP_INIT_CB_ID
:
699 hsram
->MspInitCallback
= HAL_SRAM_MspInit
;
701 case HAL_SRAM_MSP_DEINIT_CB_ID
:
702 hsram
->MspDeInitCallback
= HAL_SRAM_MspDeInit
;
704 case HAL_SRAM_DMA_XFER_CPLT_CB_ID
:
705 hsram
->DmaXferCpltCallback
= HAL_SRAM_DMA_XferCpltCallback
;
707 case HAL_SRAM_DMA_XFER_ERR_CB_ID
:
708 hsram
->DmaXferErrorCallback
= HAL_SRAM_DMA_XferErrorCallback
;
711 /* update return status */
716 else if(state
== HAL_SRAM_STATE_RESET
)
720 case HAL_SRAM_MSP_INIT_CB_ID
:
721 hsram
->MspInitCallback
= HAL_SRAM_MspInit
;
723 case HAL_SRAM_MSP_DEINIT_CB_ID
:
724 hsram
->MspDeInitCallback
= HAL_SRAM_MspDeInit
;
727 /* update return status */
734 /* update return status */
744 * @brief Register a User SRAM Callback for DMA transfers
745 * To be used instead of the weak (surcharged) predefined callback
746 * @param hsram : SRAM handle
747 * @param CallbackId : ID of the callback to be registered
748 * This parameter can be one of the following values:
749 * @arg @ref HAL_SRAM_DMA_XFER_CPLT_CB_ID SRAM DMA Xfer Complete callback ID
750 * @arg @ref HAL_SRAM_DMA_XFER_ERR_CB_ID SRAM DMA Xfer Error callback ID
751 * @param pCallback : pointer to the Callback function
754 HAL_StatusTypeDef
HAL_SRAM_RegisterDmaCallback(SRAM_HandleTypeDef
*hsram
, HAL_SRAM_CallbackIDTypeDef CallbackId
, pSRAM_DmaCallbackTypeDef pCallback
)
756 HAL_StatusTypeDef status
= HAL_OK
;
757 HAL_SRAM_StateTypeDef state
;
759 if(pCallback
== NULL
)
767 state
= hsram
->State
;
768 if((state
== HAL_SRAM_STATE_READY
) || (state
== HAL_SRAM_STATE_PROTECTED
))
772 case HAL_SRAM_DMA_XFER_CPLT_CB_ID
:
773 hsram
->DmaXferCpltCallback
= pCallback
;
775 case HAL_SRAM_DMA_XFER_ERR_CB_ID
:
776 hsram
->DmaXferErrorCallback
= pCallback
;
779 /* update return status */
786 /* update return status */
799 /** @defgroup SRAM_Exported_Functions_Group3 Control functions
800 * @brief Control functions
803 ==============================================================================
804 ##### SRAM Control functions #####
805 ==============================================================================
807 This subsection provides a set of functions allowing to control dynamically
815 * @brief Enables dynamically SRAM write operation.
816 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
817 * the configuration information for SRAM module.
820 HAL_StatusTypeDef
HAL_SRAM_WriteOperation_Enable(SRAM_HandleTypeDef
*hsram
)
825 /* Enable write operation */
826 FMC_NORSRAM_WriteOperation_Enable(hsram
->Instance
, hsram
->Init
.NSBank
);
828 /* Update the SRAM controller state */
829 hsram
->State
= HAL_SRAM_STATE_READY
;
831 /* Process unlocked */
838 * @brief Disables dynamically SRAM write operation.
839 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
840 * the configuration information for SRAM module.
843 HAL_StatusTypeDef
HAL_SRAM_WriteOperation_Disable(SRAM_HandleTypeDef
*hsram
)
848 /* Update the SRAM controller state */
849 hsram
->State
= HAL_SRAM_STATE_BUSY
;
851 /* Disable write operation */
852 FMC_NORSRAM_WriteOperation_Disable(hsram
->Instance
, hsram
->Init
.NSBank
);
854 /* Update the SRAM controller state */
855 hsram
->State
= HAL_SRAM_STATE_PROTECTED
;
857 /* Process unlocked */
867 /** @defgroup SRAM_Exported_Functions_Group4 Peripheral State functions
868 * @brief Peripheral State functions
871 ==============================================================================
872 ##### SRAM State functions #####
873 ==============================================================================
875 This subsection permits to get in run-time the status of the SRAM controller
883 * @brief Returns the SRAM controller state
884 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
885 * the configuration information for SRAM module.
888 HAL_SRAM_StateTypeDef
HAL_SRAM_GetState(SRAM_HandleTypeDef
*hsram
)
900 #endif /* HAL_SRAM_MODULE_ENABLED */
909 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/