2 ******************************************************************************
3 * @file stm32h7xx_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 "stm32h7xx_hal.h"
119 /** @addtogroup STM32H7xx_HAL_Driver
123 #ifdef HAL_SRAM_MODULE_ENABLED
125 /** @defgroup SRAM SRAM
126 * @brief SRAM driver modules
133 /* Private typedef -----------------------------------------------------------*/
134 /* Private define ------------------------------------------------------------*/
135 /* Private macro -------------------------------------------------------------*/
136 /* Private variables ---------------------------------------------------------*/
137 /* Private function prototypes -----------------------------------------------*/
138 static void SRAM_DMACplt (MDMA_HandleTypeDef
*hmdma
);
139 static void SRAM_DMACpltProt(MDMA_HandleTypeDef
*hmdma
);
140 static void SRAM_DMAError (MDMA_HandleTypeDef
*hmdma
);
145 /* Exported functions --------------------------------------------------------*/
147 /** @defgroup SRAM_Exported_Functions SRAM Exported Functions
151 /** @defgroup SRAM_Exported_Functions_Group1 Initialization and de-initialization functions
152 * @brief Initialization and Configuration functions.
155 ==============================================================================
156 ##### SRAM Initialization and de_initialization functions #####
157 ==============================================================================
158 [..] This section provides functions allowing to initialize/de-initialize
166 * @brief Performs the SRAM device initialization sequence
167 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
168 * the configuration information for SRAM module.
169 * @param Timing Pointer to SRAM control timing structure
170 * @param ExtTiming Pointer to SRAM extended mode timing structure
173 HAL_StatusTypeDef
HAL_SRAM_Init(SRAM_HandleTypeDef
*hsram
, FMC_NORSRAM_TimingTypeDef
*Timing
, FMC_NORSRAM_TimingTypeDef
*ExtTiming
)
175 /* Check the SRAM handle parameter */
181 if (hsram
->State
== HAL_SRAM_STATE_RESET
)
183 /* Allocate lock resource and initialize it */
184 hsram
->Lock
= HAL_UNLOCKED
;
186 #if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
187 if(hsram
->MspInitCallback
== NULL
)
189 hsram
->MspInitCallback
= HAL_SRAM_MspInit
;
191 hsram
->DmaXferCpltCallback
= HAL_SRAM_DMA_XferCpltCallback
;
192 hsram
->DmaXferErrorCallback
= HAL_SRAM_DMA_XferErrorCallback
;
194 /* Init the low level hardware */
195 hsram
->MspInitCallback(hsram
);
197 /* Initialize the low level hardware (MSP) */
198 HAL_SRAM_MspInit(hsram
);
202 /* Initialize SRAM control Interface */
203 (void)FMC_NORSRAM_Init(hsram
->Instance
, &(hsram
->Init
));
205 /* Initialize SRAM timing Interface */
206 (void)FMC_NORSRAM_Timing_Init(hsram
->Instance
, Timing
, hsram
->Init
.NSBank
);
208 /* Initialize SRAM extended mode timing Interface */
209 (void)FMC_NORSRAM_Extended_Timing_Init(hsram
->Extended
, ExtTiming
, hsram
->Init
.NSBank
, hsram
->Init
.ExtendedMode
);
211 /* Enable the NORSRAM device */
212 __FMC_NORSRAM_ENABLE(hsram
->Instance
, hsram
->Init
.NSBank
);
214 /* Enable FMC Peripheral */
217 /* Initialize the SRAM controller state */
218 hsram
->State
= HAL_SRAM_STATE_READY
;
224 * @brief Performs the SRAM device De-initialization sequence.
225 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
226 * the configuration information for SRAM module.
229 HAL_StatusTypeDef
HAL_SRAM_DeInit(SRAM_HandleTypeDef
*hsram
)
231 #if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
232 if(hsram
->MspDeInitCallback
== NULL
)
234 hsram
->MspDeInitCallback
= HAL_SRAM_MspDeInit
;
237 /* DeInit the low level hardware */
238 hsram
->MspDeInitCallback(hsram
);
240 /* De-Initialize the low level hardware (MSP) */
241 HAL_SRAM_MspDeInit(hsram
);
244 /* Configure the SRAM registers with their reset values */
245 (void)FMC_NORSRAM_DeInit(hsram
->Instance
, hsram
->Extended
, hsram
->Init
.NSBank
);
247 /* Reset the SRAM controller state */
248 hsram
->State
= HAL_SRAM_STATE_RESET
;
257 * @brief SRAM MSP Init.
258 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
259 * the configuration information for SRAM module.
262 __weak
void HAL_SRAM_MspInit(SRAM_HandleTypeDef
*hsram
)
264 /* Prevent unused argument(s) compilation warning */
267 /* NOTE : This function Should not be modified, when the callback is needed,
268 the HAL_SRAM_MspInit could be implemented in the user file
273 * @brief SRAM MSP DeInit.
274 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
275 * the configuration information for SRAM module.
278 __weak
void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef
*hsram
)
280 /* Prevent unused argument(s) compilation warning */
283 /* NOTE : This function Should not be modified, when the callback is needed,
284 the HAL_SRAM_MspDeInit could be implemented in the user file
289 * @brief DMA transfer complete callback.
290 * @param hmdma pointer to a SRAM_HandleTypeDef structure that contains
291 * the configuration information for SRAM module.
294 __weak
void HAL_SRAM_DMA_XferCpltCallback(MDMA_HandleTypeDef
*hmdma
)
296 /* Prevent unused argument(s) compilation warning */
299 /* NOTE : This function Should not be modified, when the callback is needed,
300 the HAL_SRAM_DMA_XferCpltCallback could be implemented in the user file
305 * @brief DMA transfer complete error callback.
306 * @param hmdma pointer to a SRAM_HandleTypeDef structure that contains
307 * the configuration information for SRAM module.
310 __weak
void HAL_SRAM_DMA_XferErrorCallback(MDMA_HandleTypeDef
*hmdma
)
312 /* Prevent unused argument(s) compilation warning */
315 /* NOTE : This function Should not be modified, when the callback is needed,
316 the HAL_SRAM_DMA_XferErrorCallback could be implemented in the user file
324 /** @defgroup SRAM_Exported_Functions_Group2 Input Output and memory control functions
325 * @brief Input Output and memory control functions
328 ==============================================================================
329 ##### SRAM Input and Output functions #####
330 ==============================================================================
332 This section provides functions allowing to use and control the SRAM memory
339 * @brief Reads 8-bit buffer from SRAM memory.
340 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
341 * the configuration information for SRAM module.
342 * @param pAddress Pointer to read start address
343 * @param pDstBuffer Pointer to destination buffer
344 * @param BufferSize Size of the buffer to read from memory
347 HAL_StatusTypeDef
HAL_SRAM_Read_8b(SRAM_HandleTypeDef
*hsram
, uint32_t *pAddress
, uint8_t *pDstBuffer
, uint32_t BufferSize
)
350 __IO
uint8_t *psramaddress
= (uint8_t *)pAddress
;
351 uint8_t * pdestbuff
= pDstBuffer
;
352 HAL_SRAM_StateTypeDef state
= hsram
->State
;
354 /* Check the SRAM controller state */
355 if ((state
== HAL_SRAM_STATE_READY
) || (state
== HAL_SRAM_STATE_PROTECTED
))
360 /* Update the SRAM controller state */
361 hsram
->State
= HAL_SRAM_STATE_BUSY
;
363 /* Read data from memory */
364 for (size
= BufferSize
; size
!= 0U; size
--)
366 *pdestbuff
= *psramaddress
;
371 /* Update the SRAM controller state */
372 hsram
->State
= state
;
374 /* Process unlocked */
386 * @brief Writes 8-bit buffer to SRAM memory.
387 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
388 * the configuration information for SRAM module.
389 * @param pAddress Pointer to write start address
390 * @param pSrcBuffer Pointer to source buffer to write
391 * @param BufferSize Size of the buffer to write to memory
394 HAL_StatusTypeDef
HAL_SRAM_Write_8b(SRAM_HandleTypeDef
*hsram
, uint32_t *pAddress
, uint8_t *pSrcBuffer
, uint32_t BufferSize
)
397 __IO
uint8_t *psramaddress
= (uint8_t *)pAddress
;
398 uint8_t * psrcbuff
= pSrcBuffer
;
400 /* Check the SRAM controller state */
401 if (hsram
->State
== HAL_SRAM_STATE_READY
)
406 /* Update the SRAM controller state */
407 hsram
->State
= HAL_SRAM_STATE_BUSY
;
409 /* Write data to memory */
410 for (size
= BufferSize
; size
!= 0U; size
--)
412 *psramaddress
= *psrcbuff
;
417 /* Update the SRAM controller state */
418 hsram
->State
= HAL_SRAM_STATE_READY
;
420 /* Process unlocked */
432 * @brief Reads 16-bit buffer from SRAM memory.
433 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
434 * the configuration information for SRAM module.
435 * @param pAddress Pointer to read start address
436 * @param pDstBuffer Pointer to destination buffer
437 * @param BufferSize Size of the buffer to read from memory
440 HAL_StatusTypeDef
HAL_SRAM_Read_16b(SRAM_HandleTypeDef
*hsram
, uint32_t *pAddress
, uint16_t *pDstBuffer
, uint32_t BufferSize
)
443 __IO
uint32_t *psramaddress
= pAddress
;
444 uint16_t *pdestbuff
= pDstBuffer
;
446 HAL_SRAM_StateTypeDef state
= hsram
->State
;
448 /* Check the SRAM controller state */
449 if ((state
== HAL_SRAM_STATE_READY
) || (state
== HAL_SRAM_STATE_PROTECTED
))
454 /* Update the SRAM controller state */
455 hsram
->State
= HAL_SRAM_STATE_BUSY
;
457 /* Check if the size is a 32-bits mulitple */
458 limit
= (((BufferSize
% 2U) != 0U) ? 1U : 0U);
460 /* Read data from memory */
461 for (size
= BufferSize
; size
!= limit
; size
-=2U)
463 *pdestbuff
= (uint16_t)((*psramaddress
) & 0x0000FFFFU
);
465 *pdestbuff
= (uint16_t)(((*psramaddress
) & 0xFFFF0000U
) >> 16U);
470 /* Read last 16-bits if size is not 32-bits multiple */
473 *pdestbuff
= (uint16_t)((*psramaddress
) & 0x0000FFFFU
);
476 /* Update the SRAM controller state */
477 hsram
->State
= state
;
479 /* Process unlocked */
491 * @brief Writes 16-bit buffer to SRAM memory.
492 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
493 * the configuration information for SRAM module.
494 * @param pAddress Pointer to write start address
495 * @param pSrcBuffer Pointer to source buffer to write
496 * @param BufferSize Size of the buffer to write to memory
499 HAL_StatusTypeDef
HAL_SRAM_Write_16b(SRAM_HandleTypeDef
*hsram
, uint32_t *pAddress
, uint16_t *pSrcBuffer
, uint32_t BufferSize
)
502 __IO
uint32_t *psramaddress
= pAddress
;
503 uint16_t * psrcbuff
= pSrcBuffer
;
506 /* Check the SRAM controller state */
507 if (hsram
->State
== HAL_SRAM_STATE_READY
)
512 /* Update the SRAM controller state */
513 hsram
->State
= HAL_SRAM_STATE_BUSY
;
515 /* Check if the size is a 32-bits mulitple */
516 limit
= (((BufferSize
% 2U) != 0U) ? 1U : 0U);
518 /* Write data to memory */
519 for (size
= BufferSize
; size
!= limit
; size
-=2U)
521 *psramaddress
= (uint32_t)(*psrcbuff
);
523 *psramaddress
|= ((uint32_t)(*psrcbuff
) << 16U);
528 /* Write last 16-bits if size is not 32-bits multiple */
531 *psramaddress
= ((uint32_t)(*psrcbuff
) & 0x0000FFFFU
) | ((*psramaddress
) & 0xFFFF0000U
);
534 /* Update the SRAM controller state */
535 hsram
->State
= HAL_SRAM_STATE_READY
;
537 /* Process unlocked */
549 * @brief Reads 32-bit buffer from SRAM memory.
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_32b(SRAM_HandleTypeDef
*hsram
, uint32_t *pAddress
, uint32_t *pDstBuffer
, uint32_t BufferSize
)
560 __IO
uint32_t * psramaddress
= pAddress
;
561 uint32_t * pdestbuff
= pDstBuffer
;
562 HAL_SRAM_StateTypeDef state
= hsram
->State
;
564 /* Check the SRAM controller state */
565 if ((state
== HAL_SRAM_STATE_READY
) || (state
== HAL_SRAM_STATE_PROTECTED
))
570 /* Update the SRAM controller state */
571 hsram
->State
= HAL_SRAM_STATE_BUSY
;
573 /* Read data from memory */
574 for (size
= BufferSize
; size
!= 0U; size
--)
576 *pdestbuff
= *psramaddress
;
581 /* Update the SRAM controller state */
582 hsram
->State
= state
;
584 /* Process unlocked */
596 * @brief Writes 32-bit buffer to SRAM memory.
597 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
598 * the configuration information for SRAM module.
599 * @param pAddress Pointer to write start address
600 * @param pSrcBuffer Pointer to source buffer to write
601 * @param BufferSize Size of the buffer to write to memory
604 HAL_StatusTypeDef
HAL_SRAM_Write_32b(SRAM_HandleTypeDef
*hsram
, uint32_t *pAddress
, uint32_t *pSrcBuffer
, uint32_t BufferSize
)
607 __IO
uint32_t * psramaddress
= pAddress
;
608 uint32_t * psrcbuff
= pSrcBuffer
;
610 /* Check the SRAM controller state */
611 if (hsram
->State
== HAL_SRAM_STATE_READY
)
616 /* Update the SRAM controller state */
617 hsram
->State
= HAL_SRAM_STATE_BUSY
;
619 /* Write data to memory */
620 for (size
= BufferSize
; size
!= 0U; size
--)
622 *psramaddress
= *psrcbuff
;
627 /* Update the SRAM controller state */
628 hsram
->State
= HAL_SRAM_STATE_READY
;
630 /* Process unlocked */
642 * @brief Reads a Words data from the SRAM memory using DMA transfer.
643 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
644 * the configuration information for SRAM module.
645 * @param pAddress Pointer to read start address
646 * @param pDstBuffer Pointer to destination buffer
647 * @param BufferSize Size of the buffer to read from memory
650 HAL_StatusTypeDef
HAL_SRAM_Read_DMA(SRAM_HandleTypeDef
*hsram
, uint32_t *pAddress
, uint32_t *pDstBuffer
, uint32_t BufferSize
)
652 HAL_StatusTypeDef status
;
653 HAL_SRAM_StateTypeDef state
= hsram
->State
;
655 /* Check the SRAM controller state */
656 if ((state
== HAL_SRAM_STATE_READY
) || (state
== HAL_SRAM_STATE_PROTECTED
))
661 /* Update the SRAM controller state */
662 hsram
->State
= HAL_SRAM_STATE_BUSY
;
664 /* Configure DMA user callbacks */
665 if (state
== HAL_SRAM_STATE_READY
)
667 hsram
->hmdma
->XferCpltCallback
= SRAM_DMACplt
;
671 hsram
->hmdma
->XferCpltCallback
= SRAM_DMACpltProt
;
673 hsram
->hmdma
->XferErrorCallback
= SRAM_DMAError
;
675 /* Enable the DMA Stream */
676 status
= HAL_MDMA_Start_IT(hsram
->hmdma
, (uint32_t)pAddress
, (uint32_t)pDstBuffer
, (uint32_t)(BufferSize
* 4U), 1);
678 /* Process unlocked */
690 * @brief Writes a Words data buffer to SRAM memory using DMA transfer.
691 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
692 * the configuration information for SRAM module.
693 * @param pAddress Pointer to write start address
694 * @param pSrcBuffer Pointer to source buffer to write
695 * @param BufferSize Size of the buffer to write to memory
698 HAL_StatusTypeDef
HAL_SRAM_Write_DMA(SRAM_HandleTypeDef
*hsram
, uint32_t *pAddress
, uint32_t *pSrcBuffer
, uint32_t BufferSize
)
700 HAL_StatusTypeDef status
;
702 /* Check the SRAM controller state */
703 if (hsram
->State
== HAL_SRAM_STATE_READY
)
708 /* Update the SRAM controller state */
709 hsram
->State
= HAL_SRAM_STATE_BUSY
;
711 /* Configure DMA user callbacks */
712 hsram
->hmdma
->XferCpltCallback
= SRAM_DMACplt
;
713 hsram
->hmdma
->XferErrorCallback
= SRAM_DMAError
;
715 /* Enable the DMA Stream */
716 status
= HAL_MDMA_Start_IT(hsram
->hmdma
, (uint32_t)pSrcBuffer
, (uint32_t)pAddress
, (uint32_t)(BufferSize
* 4U), 1);
718 /* Process unlocked */
729 #if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
731 * @brief Register a User SRAM Callback
732 * To be used instead of the weak (surcharged) predefined callback
733 * @param hsram : SRAM handle
734 * @param CallbackId : ID of the callback to be registered
735 * This parameter can be one of the following values:
736 * @arg @ref HAL_SRAM_MSP_INIT_CB_ID SRAM MspInit callback ID
737 * @arg @ref HAL_SRAM_MSP_DEINIT_CB_ID SRAM MspDeInit callback ID
738 * @param pCallback : pointer to the Callback function
741 HAL_StatusTypeDef
HAL_SRAM_RegisterCallback (SRAM_HandleTypeDef
*hsram
, HAL_SRAM_CallbackIDTypeDef CallbackId
, pSRAM_CallbackTypeDef pCallback
)
743 HAL_StatusTypeDef status
= HAL_OK
;
744 HAL_SRAM_StateTypeDef state
;
746 if(pCallback
== NULL
)
754 state
= hsram
->State
;
755 if((state
== HAL_SRAM_STATE_READY
) || (state
== HAL_SRAM_STATE_RESET
) || (state
== HAL_SRAM_STATE_PROTECTED
))
759 case HAL_SRAM_MSP_INIT_CB_ID
:
760 hsram
->MspInitCallback
= pCallback
;
762 case HAL_SRAM_MSP_DEINIT_CB_ID
:
763 hsram
->MspDeInitCallback
= pCallback
;
766 /* update return status */
773 /* update return status */
783 * @brief Unregister a User SRAM Callback
784 * SRAM Callback is redirected to the weak (surcharged) predefined callback
785 * @param hsram : SRAM handle
786 * @param CallbackId : ID of the callback to be unregistered
787 * This parameter can be one of the following values:
788 * @arg @ref HAL_SRAM_MSP_INIT_CB_ID SRAM MspInit callback ID
789 * @arg @ref HAL_SRAM_MSP_DEINIT_CB_ID SRAM MspDeInit callback ID
790 * @arg @ref HAL_SRAM_DMA_XFER_CPLT_CB_ID SRAM DMA Xfer Complete callback ID
791 * @arg @ref HAL_SRAM_DMA_XFER_ERR_CB_ID SRAM DMA Xfer Error callback ID
794 HAL_StatusTypeDef
HAL_SRAM_UnRegisterCallback (SRAM_HandleTypeDef
*hsram
, HAL_SRAM_CallbackIDTypeDef CallbackId
)
796 HAL_StatusTypeDef status
= HAL_OK
;
797 HAL_SRAM_StateTypeDef state
;
802 state
= hsram
->State
;
803 if((state
== HAL_SRAM_STATE_READY
) || (state
== HAL_SRAM_STATE_PROTECTED
))
807 case HAL_SRAM_MSP_INIT_CB_ID
:
808 hsram
->MspInitCallback
= HAL_SRAM_MspInit
;
810 case HAL_SRAM_MSP_DEINIT_CB_ID
:
811 hsram
->MspDeInitCallback
= HAL_SRAM_MspDeInit
;
813 case HAL_SRAM_DMA_XFER_CPLT_CB_ID
:
814 hsram
->DmaXferCpltCallback
= HAL_SRAM_DMA_XferCpltCallback
;
816 case HAL_SRAM_DMA_XFER_ERR_CB_ID
:
817 hsram
->DmaXferErrorCallback
= HAL_SRAM_DMA_XferErrorCallback
;
820 /* update return status */
825 else if(state
== HAL_SRAM_STATE_RESET
)
829 case HAL_SRAM_MSP_INIT_CB_ID
:
830 hsram
->MspInitCallback
= HAL_SRAM_MspInit
;
832 case HAL_SRAM_MSP_DEINIT_CB_ID
:
833 hsram
->MspDeInitCallback
= HAL_SRAM_MspDeInit
;
836 /* update return status */
843 /* update return status */
853 * @brief Register a User SRAM Callback for DMA transfers
854 * To be used instead of the weak (surcharged) predefined callback
855 * @param hsram : SRAM handle
856 * @param CallbackId : ID of the callback to be registered
857 * This parameter can be one of the following values:
858 * @arg @ref HAL_SRAM_DMA_XFER_CPLT_CB_ID SRAM DMA Xfer Complete callback ID
859 * @arg @ref HAL_SRAM_DMA_XFER_ERR_CB_ID SRAM DMA Xfer Error callback ID
860 * @param pCallback : pointer to the Callback function
863 HAL_StatusTypeDef
HAL_SRAM_RegisterDmaCallback(SRAM_HandleTypeDef
*hsram
, HAL_SRAM_CallbackIDTypeDef CallbackId
, pSRAM_DmaCallbackTypeDef pCallback
)
865 HAL_StatusTypeDef status
= HAL_OK
;
866 HAL_SRAM_StateTypeDef state
;
868 if(pCallback
== NULL
)
876 state
= hsram
->State
;
877 if((state
== HAL_SRAM_STATE_READY
) || (state
== HAL_SRAM_STATE_PROTECTED
))
881 case HAL_SRAM_DMA_XFER_CPLT_CB_ID
:
882 hsram
->DmaXferCpltCallback
= pCallback
;
884 case HAL_SRAM_DMA_XFER_ERR_CB_ID
:
885 hsram
->DmaXferErrorCallback
= pCallback
;
888 /* update return status */
895 /* update return status */
909 /** @defgroup SRAM_Exported_Functions_Group3 Control functions
910 * @brief Control functions
913 ==============================================================================
914 ##### SRAM Control functions #####
915 ==============================================================================
917 This subsection provides a set of functions allowing to control dynamically
925 * @brief Enables dynamically SRAM write operation.
926 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
927 * the configuration information for SRAM module.
930 HAL_StatusTypeDef
HAL_SRAM_WriteOperation_Enable(SRAM_HandleTypeDef
*hsram
)
932 /* Check the SRAM controller state */
933 if(hsram
->State
== HAL_SRAM_STATE_PROTECTED
)
938 /* Update the SRAM controller state */
939 hsram
->State
= HAL_SRAM_STATE_BUSY
;
941 /* Enable write operation */
942 (void)FMC_NORSRAM_WriteOperation_Enable(hsram
->Instance
, hsram
->Init
.NSBank
);
944 /* Update the SRAM controller state */
945 hsram
->State
= HAL_SRAM_STATE_READY
;
947 /* Process unlocked */
959 * @brief Disables dynamically SRAM write operation.
960 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
961 * the configuration information for SRAM module.
964 HAL_StatusTypeDef
HAL_SRAM_WriteOperation_Disable(SRAM_HandleTypeDef
*hsram
)
966 /* Check the SRAM controller state */
967 if(hsram
->State
== HAL_SRAM_STATE_READY
)
972 /* Update the SRAM controller state */
973 hsram
->State
= HAL_SRAM_STATE_BUSY
;
975 /* Disable write operation */
976 (void)FMC_NORSRAM_WriteOperation_Disable(hsram
->Instance
, hsram
->Init
.NSBank
);
978 /* Update the SRAM controller state */
979 hsram
->State
= HAL_SRAM_STATE_PROTECTED
;
981 /* Process unlocked */
996 /** @defgroup SRAM_Exported_Functions_Group4 Peripheral State functions
997 * @brief Peripheral State functions
1000 ==============================================================================
1001 ##### SRAM State functions #####
1002 ==============================================================================
1004 This subsection permits to get in run-time the status of the SRAM controller
1012 * @brief Returns the SRAM controller state
1013 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
1014 * the configuration information for SRAM module.
1017 HAL_SRAM_StateTypeDef
HAL_SRAM_GetState(SRAM_HandleTypeDef
*hsram
)
1019 return hsram
->State
;
1034 * @brief MDMA SRAM process complete callback.
1035 * @param hmdma : MDMA handle
1038 static void SRAM_DMACplt(MDMA_HandleTypeDef
*hmdma
)
1040 SRAM_HandleTypeDef
* hsram
= ( SRAM_HandleTypeDef
* )(hmdma
->Parent
);
1042 /* Disable the MDMA channel */
1043 __HAL_MDMA_DISABLE(hmdma
);
1045 /* Update the SRAM controller state */
1046 hsram
->State
= HAL_SRAM_STATE_READY
;
1048 #if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
1049 hsram
->DmaXferCpltCallback(hmdma
);
1051 HAL_SRAM_DMA_XferCpltCallback(hmdma
);
1056 * @brief MDMA SRAM process complete callback.
1057 * @param hmdma : MDMA handle
1060 static void SRAM_DMACpltProt(MDMA_HandleTypeDef
*hmdma
)
1062 SRAM_HandleTypeDef
* hsram
= ( SRAM_HandleTypeDef
* )(hmdma
->Parent
);
1064 /* Disable the MDMA channel */
1065 __HAL_MDMA_DISABLE(hmdma
);
1067 /* Update the SRAM controller state */
1068 hsram
->State
= HAL_SRAM_STATE_PROTECTED
;
1070 #if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
1071 hsram
->DmaXferCpltCallback(hmdma
);
1073 HAL_SRAM_DMA_XferCpltCallback(hmdma
);
1078 * @brief MDMA SRAM error callback.
1079 * @param hmdma : MDMA handle
1082 static void SRAM_DMAError(MDMA_HandleTypeDef
*hmdma
)
1084 SRAM_HandleTypeDef
* hsram
= ( SRAM_HandleTypeDef
* )(hmdma
->Parent
);
1086 /* Disable the MDMA channel */
1087 __HAL_MDMA_DISABLE(hmdma
);
1089 /* Update the SRAM controller state */
1090 hsram
->State
= HAL_SRAM_STATE_ERROR
;
1092 #if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
1093 hsram
->DmaXferErrorCallback(hmdma
);
1095 HAL_SRAM_DMA_XferErrorCallback(hmdma
);
1106 #endif /* HAL_SRAM_MODULE_ENABLED */
1113 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/