2 ******************************************************************************
3 * @file stm32g4xx_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 "stm32g4xx_hal.h"
118 #if defined(FMC_BANK1)
120 /** @addtogroup STM32G4xx_HAL_Driver
124 #ifdef HAL_SRAM_MODULE_ENABLED
126 /** @defgroup SRAM SRAM
127 * @brief SRAM driver modules
134 /* Private typedef -----------------------------------------------------------*/
135 /* Private define ------------------------------------------------------------*/
136 /* Private macro -------------------------------------------------------------*/
137 /* Private variables ---------------------------------------------------------*/
138 /* Private function prototypes -----------------------------------------------*/
139 static void SRAM_DMACplt (DMA_HandleTypeDef
*hdma
);
140 static void SRAM_DMACpltProt(DMA_HandleTypeDef
*hdma
);
141 static void SRAM_DMAError (DMA_HandleTypeDef
*hdma
);
146 /* Exported functions --------------------------------------------------------*/
148 /** @defgroup SRAM_Exported_Functions SRAM Exported Functions
152 /** @defgroup SRAM_Exported_Functions_Group1 Initialization and de-initialization functions
153 * @brief Initialization and Configuration functions.
156 ==============================================================================
157 ##### SRAM Initialization and de_initialization functions #####
158 ==============================================================================
159 [..] This section provides functions allowing to initialize/de-initialize
167 * @brief Performs the SRAM device initialization sequence
168 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
169 * the configuration information for SRAM module.
170 * @param Timing Pointer to SRAM control timing structure
171 * @param ExtTiming Pointer to SRAM extended mode timing structure
174 HAL_StatusTypeDef
HAL_SRAM_Init(SRAM_HandleTypeDef
*hsram
, FMC_NORSRAM_TimingTypeDef
*Timing
, FMC_NORSRAM_TimingTypeDef
*ExtTiming
)
176 /* Check the SRAM handle parameter */
182 if (hsram
->State
== HAL_SRAM_STATE_RESET
)
184 /* Allocate lock resource and initialize it */
185 hsram
->Lock
= HAL_UNLOCKED
;
187 #if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
188 if(hsram
->MspInitCallback
== NULL
)
190 hsram
->MspInitCallback
= HAL_SRAM_MspInit
;
192 hsram
->DmaXferCpltCallback
= HAL_SRAM_DMA_XferCpltCallback
;
193 hsram
->DmaXferErrorCallback
= HAL_SRAM_DMA_XferErrorCallback
;
195 /* Init the low level hardware */
196 hsram
->MspInitCallback(hsram
);
198 /* Initialize the low level hardware (MSP) */
199 HAL_SRAM_MspInit(hsram
);
203 /* Initialize SRAM control Interface */
204 (void)FMC_NORSRAM_Init(hsram
->Instance
, &(hsram
->Init
));
206 /* Initialize SRAM timing Interface */
207 (void)FMC_NORSRAM_Timing_Init(hsram
->Instance
, Timing
, hsram
->Init
.NSBank
);
209 /* Initialize SRAM extended mode timing Interface */
210 (void)FMC_NORSRAM_Extended_Timing_Init(hsram
->Extended
, ExtTiming
, hsram
->Init
.NSBank
, hsram
->Init
.ExtendedMode
);
212 /* Enable the NORSRAM device */
213 __FMC_NORSRAM_ENABLE(hsram
->Instance
, hsram
->Init
.NSBank
);
215 /* Initialize the SRAM controller state */
216 hsram
->State
= HAL_SRAM_STATE_READY
;
222 * @brief Performs the SRAM device De-initialization sequence.
223 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
224 * the configuration information for SRAM module.
227 HAL_StatusTypeDef
HAL_SRAM_DeInit(SRAM_HandleTypeDef
*hsram
)
229 #if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
230 if(hsram
->MspDeInitCallback
== NULL
)
232 hsram
->MspDeInitCallback
= HAL_SRAM_MspDeInit
;
235 /* DeInit the low level hardware */
236 hsram
->MspDeInitCallback(hsram
);
238 /* De-Initialize the low level hardware (MSP) */
239 HAL_SRAM_MspDeInit(hsram
);
242 /* Configure the SRAM registers with their reset values */
243 (void)FMC_NORSRAM_DeInit(hsram
->Instance
, hsram
->Extended
, hsram
->Init
.NSBank
);
245 /* Reset the SRAM controller state */
246 hsram
->State
= HAL_SRAM_STATE_RESET
;
255 * @brief SRAM MSP Init.
256 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
257 * the configuration information for SRAM module.
260 __weak
void HAL_SRAM_MspInit(SRAM_HandleTypeDef
*hsram
)
262 /* Prevent unused argument(s) compilation warning */
265 /* NOTE : This function Should not be modified, when the callback is needed,
266 the HAL_SRAM_MspInit could be implemented in the user file
271 * @brief SRAM MSP DeInit.
272 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
273 * the configuration information for SRAM module.
276 __weak
void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef
*hsram
)
278 /* Prevent unused argument(s) compilation warning */
281 /* NOTE : This function Should not be modified, when the callback is needed,
282 the HAL_SRAM_MspDeInit could be implemented in the user file
287 * @brief DMA transfer complete callback.
288 * @param hdma pointer to a SRAM_HandleTypeDef structure that contains
289 * the configuration information for SRAM module.
292 __weak
void HAL_SRAM_DMA_XferCpltCallback(DMA_HandleTypeDef
*hdma
)
294 /* Prevent unused argument(s) compilation warning */
297 /* NOTE : This function Should not be modified, when the callback is needed,
298 the HAL_SRAM_DMA_XferCpltCallback could be implemented in the user file
303 * @brief DMA transfer complete error callback.
304 * @param hdma pointer to a SRAM_HandleTypeDef structure that contains
305 * the configuration information for SRAM module.
308 __weak
void HAL_SRAM_DMA_XferErrorCallback(DMA_HandleTypeDef
*hdma
)
310 /* Prevent unused argument(s) compilation warning */
313 /* NOTE : This function Should not be modified, when the callback is needed,
314 the HAL_SRAM_DMA_XferErrorCallback could be implemented in the user file
322 /** @defgroup SRAM_Exported_Functions_Group2 Input Output and memory control functions
323 * @brief Input Output and memory control functions
326 ==============================================================================
327 ##### SRAM Input and Output functions #####
328 ==============================================================================
330 This section provides functions allowing to use and control the SRAM memory
337 * @brief Reads 8-bit buffer from SRAM memory.
338 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
339 * the configuration information for SRAM module.
340 * @param pAddress Pointer to read start address
341 * @param pDstBuffer Pointer to destination buffer
342 * @param BufferSize Size of the buffer to read from memory
345 HAL_StatusTypeDef
HAL_SRAM_Read_8b(SRAM_HandleTypeDef
*hsram
, uint32_t *pAddress
, uint8_t *pDstBuffer
, uint32_t BufferSize
)
348 __IO
uint8_t *psramaddress
= (uint8_t *)pAddress
;
349 uint8_t * pdestbuff
= pDstBuffer
;
350 HAL_SRAM_StateTypeDef state
= hsram
->State
;
352 /* Check the SRAM controller state */
353 if ((state
== HAL_SRAM_STATE_READY
) || (state
== HAL_SRAM_STATE_PROTECTED
))
358 /* Update the SRAM controller state */
359 hsram
->State
= HAL_SRAM_STATE_BUSY
;
361 /* Read data from memory */
362 for (size
= BufferSize
; size
!= 0U; size
--)
364 *pdestbuff
= *psramaddress
;
369 /* Update the SRAM controller state */
370 hsram
->State
= state
;
372 /* Process unlocked */
384 * @brief Writes 8-bit buffer to SRAM memory.
385 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
386 * the configuration information for SRAM module.
387 * @param pAddress Pointer to write start address
388 * @param pSrcBuffer Pointer to source buffer to write
389 * @param BufferSize Size of the buffer to write to memory
392 HAL_StatusTypeDef
HAL_SRAM_Write_8b(SRAM_HandleTypeDef
*hsram
, uint32_t *pAddress
, uint8_t *pSrcBuffer
, uint32_t BufferSize
)
395 __IO
uint8_t *psramaddress
= (uint8_t *)pAddress
;
396 uint8_t * psrcbuff
= pSrcBuffer
;
398 /* Check the SRAM controller state */
399 if (hsram
->State
== HAL_SRAM_STATE_READY
)
404 /* Update the SRAM controller state */
405 hsram
->State
= HAL_SRAM_STATE_BUSY
;
407 /* Write data to memory */
408 for (size
= BufferSize
; size
!= 0U; size
--)
410 *psramaddress
= *psrcbuff
;
415 /* Update the SRAM controller state */
416 hsram
->State
= HAL_SRAM_STATE_READY
;
418 /* Process unlocked */
430 * @brief Reads 16-bit buffer from SRAM memory.
431 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
432 * the configuration information for SRAM module.
433 * @param pAddress Pointer to read start address
434 * @param pDstBuffer Pointer to destination buffer
435 * @param BufferSize Size of the buffer to read from memory
438 HAL_StatusTypeDef
HAL_SRAM_Read_16b(SRAM_HandleTypeDef
*hsram
, uint32_t *pAddress
, uint16_t *pDstBuffer
, uint32_t BufferSize
)
441 __IO
uint32_t *psramaddress
= pAddress
;
442 uint16_t *pdestbuff
= pDstBuffer
;
444 HAL_SRAM_StateTypeDef state
= hsram
->State
;
446 /* Check the SRAM controller state */
447 if ((state
== HAL_SRAM_STATE_READY
) || (state
== HAL_SRAM_STATE_PROTECTED
))
452 /* Update the SRAM controller state */
453 hsram
->State
= HAL_SRAM_STATE_BUSY
;
455 /* Check if the size is a 32-bits mulitple */
456 limit
= (((BufferSize
% 2U) != 0U) ? 1U : 0U);
458 /* Read data from memory */
459 for (size
= BufferSize
; size
!= limit
; size
-=2U)
461 *pdestbuff
= (uint16_t)((*psramaddress
) & 0x0000FFFFU
);
463 *pdestbuff
= (uint16_t)(((*psramaddress
) & 0xFFFF0000U
) >> 16U);
468 /* Read last 16-bits if size is not 32-bits multiple */
471 *pdestbuff
= (uint16_t)((*psramaddress
) & 0x0000FFFFU
);
474 /* Update the SRAM controller state */
475 hsram
->State
= state
;
477 /* Process unlocked */
489 * @brief Writes 16-bit buffer to SRAM memory.
490 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
491 * the configuration information for SRAM module.
492 * @param pAddress Pointer to write start address
493 * @param pSrcBuffer Pointer to source buffer to write
494 * @param BufferSize Size of the buffer to write to memory
497 HAL_StatusTypeDef
HAL_SRAM_Write_16b(SRAM_HandleTypeDef
*hsram
, uint32_t *pAddress
, uint16_t *pSrcBuffer
, uint32_t BufferSize
)
500 __IO
uint32_t *psramaddress
= pAddress
;
501 uint16_t * psrcbuff
= pSrcBuffer
;
504 /* Check the SRAM controller state */
505 if (hsram
->State
== HAL_SRAM_STATE_READY
)
510 /* Update the SRAM controller state */
511 hsram
->State
= HAL_SRAM_STATE_BUSY
;
513 /* Check if the size is a 32-bits mulitple */
514 limit
= (((BufferSize
% 2U) != 0U) ? 1U : 0U);
516 /* Write data to memory */
517 for (size
= BufferSize
; size
!= limit
; size
-=2U)
519 *psramaddress
= (uint32_t)(*psrcbuff
);
521 *psramaddress
|= ((uint32_t)(*psrcbuff
) << 16U);
526 /* Write last 16-bits if size is not 32-bits multiple */
529 *psramaddress
= ((uint32_t)(*psrcbuff
) & 0x0000FFFFU
) | ((*psramaddress
) & 0xFFFF0000U
);
532 /* Update the SRAM controller state */
533 hsram
->State
= HAL_SRAM_STATE_READY
;
535 /* Process unlocked */
547 * @brief Reads 32-bit buffer from SRAM memory.
548 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
549 * the configuration information for SRAM module.
550 * @param pAddress Pointer to read start address
551 * @param pDstBuffer Pointer to destination buffer
552 * @param BufferSize Size of the buffer to read from memory
555 HAL_StatusTypeDef
HAL_SRAM_Read_32b(SRAM_HandleTypeDef
*hsram
, uint32_t *pAddress
, uint32_t *pDstBuffer
, uint32_t BufferSize
)
558 __IO
uint32_t * psramaddress
= pAddress
;
559 uint32_t * pdestbuff
= pDstBuffer
;
560 HAL_SRAM_StateTypeDef state
= hsram
->State
;
562 /* Check the SRAM controller state */
563 if ((state
== HAL_SRAM_STATE_READY
) || (state
== HAL_SRAM_STATE_PROTECTED
))
568 /* Update the SRAM controller state */
569 hsram
->State
= HAL_SRAM_STATE_BUSY
;
571 /* Read data from memory */
572 for (size
= BufferSize
; size
!= 0U; size
--)
574 *pdestbuff
= *psramaddress
;
579 /* Update the SRAM controller state */
580 hsram
->State
= state
;
582 /* Process unlocked */
594 * @brief Writes 32-bit buffer to SRAM memory.
595 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
596 * the configuration information for SRAM module.
597 * @param pAddress Pointer to write start address
598 * @param pSrcBuffer Pointer to source buffer to write
599 * @param BufferSize Size of the buffer to write to memory
602 HAL_StatusTypeDef
HAL_SRAM_Write_32b(SRAM_HandleTypeDef
*hsram
, uint32_t *pAddress
, uint32_t *pSrcBuffer
, uint32_t BufferSize
)
605 __IO
uint32_t * psramaddress
= pAddress
;
606 uint32_t * psrcbuff
= pSrcBuffer
;
608 /* Check the SRAM controller state */
609 if (hsram
->State
== HAL_SRAM_STATE_READY
)
614 /* Update the SRAM controller state */
615 hsram
->State
= HAL_SRAM_STATE_BUSY
;
617 /* Write data to memory */
618 for (size
= BufferSize
; size
!= 0U; size
--)
620 *psramaddress
= *psrcbuff
;
625 /* Update the SRAM controller state */
626 hsram
->State
= HAL_SRAM_STATE_READY
;
628 /* Process unlocked */
640 * @brief Reads a Words data from the SRAM memory using DMA transfer.
641 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
642 * the configuration information for SRAM module.
643 * @param pAddress Pointer to read start address
644 * @param pDstBuffer Pointer to destination buffer
645 * @param BufferSize Size of the buffer to read from memory
648 HAL_StatusTypeDef
HAL_SRAM_Read_DMA(SRAM_HandleTypeDef
*hsram
, uint32_t *pAddress
, uint32_t *pDstBuffer
, uint32_t BufferSize
)
650 HAL_StatusTypeDef status
;
651 HAL_SRAM_StateTypeDef state
= hsram
->State
;
653 /* Check the SRAM controller state */
654 if ((state
== HAL_SRAM_STATE_READY
) || (state
== HAL_SRAM_STATE_PROTECTED
))
659 /* Update the SRAM controller state */
660 hsram
->State
= HAL_SRAM_STATE_BUSY
;
662 /* Configure DMA user callbacks */
663 if (state
== HAL_SRAM_STATE_READY
)
665 hsram
->hdma
->XferCpltCallback
= SRAM_DMACplt
;
669 hsram
->hdma
->XferCpltCallback
= SRAM_DMACpltProt
;
671 hsram
->hdma
->XferErrorCallback
= SRAM_DMAError
;
673 /* Enable the DMA Stream */
674 status
= HAL_DMA_Start_IT(hsram
->hdma
, (uint32_t)pAddress
, (uint32_t)pDstBuffer
, (uint32_t)BufferSize
);
676 /* Process unlocked */
688 * @brief Writes a Words data buffer to SRAM memory using DMA transfer.
689 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
690 * the configuration information for SRAM module.
691 * @param pAddress Pointer to write start address
692 * @param pSrcBuffer Pointer to source buffer to write
693 * @param BufferSize Size of the buffer to write to memory
696 HAL_StatusTypeDef
HAL_SRAM_Write_DMA(SRAM_HandleTypeDef
*hsram
, uint32_t *pAddress
, uint32_t *pSrcBuffer
, uint32_t BufferSize
)
698 HAL_StatusTypeDef status
;
700 /* Check the SRAM controller state */
701 if (hsram
->State
== HAL_SRAM_STATE_READY
)
706 /* Update the SRAM controller state */
707 hsram
->State
= HAL_SRAM_STATE_BUSY
;
709 /* Configure DMA user callbacks */
710 hsram
->hdma
->XferCpltCallback
= SRAM_DMACplt
;
711 hsram
->hdma
->XferErrorCallback
= SRAM_DMAError
;
713 /* Enable the DMA Stream */
714 status
= HAL_DMA_Start_IT(hsram
->hdma
, (uint32_t)pSrcBuffer
, (uint32_t)pAddress
, (uint32_t)BufferSize
);
716 /* Process unlocked */
727 #if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
729 * @brief Register a User SRAM Callback
730 * To be used instead of the weak (surcharged) predefined callback
731 * @param hsram : SRAM handle
732 * @param CallbackId : ID of the callback to be registered
733 * This parameter can be one of the following values:
734 * @arg @ref HAL_SRAM_MSP_INIT_CB_ID SRAM MspInit callback ID
735 * @arg @ref HAL_SRAM_MSP_DEINIT_CB_ID SRAM MspDeInit callback ID
736 * @param pCallback : pointer to the Callback function
739 HAL_StatusTypeDef
HAL_SRAM_RegisterCallback (SRAM_HandleTypeDef
*hsram
, HAL_SRAM_CallbackIDTypeDef CallbackId
, pSRAM_CallbackTypeDef pCallback
)
741 HAL_StatusTypeDef status
= HAL_OK
;
742 HAL_SRAM_StateTypeDef state
;
744 if(pCallback
== NULL
)
752 state
= hsram
->State
;
753 if((state
== HAL_SRAM_STATE_READY
) || (state
== HAL_SRAM_STATE_RESET
) || (state
== HAL_SRAM_STATE_PROTECTED
))
757 case HAL_SRAM_MSP_INIT_CB_ID
:
758 hsram
->MspInitCallback
= pCallback
;
760 case HAL_SRAM_MSP_DEINIT_CB_ID
:
761 hsram
->MspDeInitCallback
= pCallback
;
764 /* update return status */
771 /* update return status */
781 * @brief Unregister a User SRAM Callback
782 * SRAM Callback is redirected to the weak (surcharged) predefined callback
783 * @param hsram : SRAM handle
784 * @param CallbackId : ID of the callback to be unregistered
785 * This parameter can be one of the following values:
786 * @arg @ref HAL_SRAM_MSP_INIT_CB_ID SRAM MspInit callback ID
787 * @arg @ref HAL_SRAM_MSP_DEINIT_CB_ID SRAM MspDeInit callback ID
788 * @arg @ref HAL_SRAM_DMA_XFER_CPLT_CB_ID SRAM DMA Xfer Complete callback ID
789 * @arg @ref HAL_SRAM_DMA_XFER_ERR_CB_ID SRAM DMA Xfer Error callback ID
792 HAL_StatusTypeDef
HAL_SRAM_UnRegisterCallback (SRAM_HandleTypeDef
*hsram
, HAL_SRAM_CallbackIDTypeDef CallbackId
)
794 HAL_StatusTypeDef status
= HAL_OK
;
795 HAL_SRAM_StateTypeDef state
;
800 state
= hsram
->State
;
801 if((state
== HAL_SRAM_STATE_READY
) || (state
== HAL_SRAM_STATE_PROTECTED
))
805 case HAL_SRAM_MSP_INIT_CB_ID
:
806 hsram
->MspInitCallback
= HAL_SRAM_MspInit
;
808 case HAL_SRAM_MSP_DEINIT_CB_ID
:
809 hsram
->MspDeInitCallback
= HAL_SRAM_MspDeInit
;
811 case HAL_SRAM_DMA_XFER_CPLT_CB_ID
:
812 hsram
->DmaXferCpltCallback
= HAL_SRAM_DMA_XferCpltCallback
;
814 case HAL_SRAM_DMA_XFER_ERR_CB_ID
:
815 hsram
->DmaXferErrorCallback
= HAL_SRAM_DMA_XferErrorCallback
;
818 /* update return status */
823 else if(state
== HAL_SRAM_STATE_RESET
)
827 case HAL_SRAM_MSP_INIT_CB_ID
:
828 hsram
->MspInitCallback
= HAL_SRAM_MspInit
;
830 case HAL_SRAM_MSP_DEINIT_CB_ID
:
831 hsram
->MspDeInitCallback
= HAL_SRAM_MspDeInit
;
834 /* update return status */
841 /* update return status */
851 * @brief Register a User SRAM Callback for DMA transfers
852 * To be used instead of the weak (surcharged) predefined callback
853 * @param hsram : SRAM handle
854 * @param CallbackId : ID of the callback to be registered
855 * This parameter can be one of the following values:
856 * @arg @ref HAL_SRAM_DMA_XFER_CPLT_CB_ID SRAM DMA Xfer Complete callback ID
857 * @arg @ref HAL_SRAM_DMA_XFER_ERR_CB_ID SRAM DMA Xfer Error callback ID
858 * @param pCallback : pointer to the Callback function
861 HAL_StatusTypeDef
HAL_SRAM_RegisterDmaCallback(SRAM_HandleTypeDef
*hsram
, HAL_SRAM_CallbackIDTypeDef CallbackId
, pSRAM_DmaCallbackTypeDef pCallback
)
863 HAL_StatusTypeDef status
= HAL_OK
;
864 HAL_SRAM_StateTypeDef state
;
866 if(pCallback
== NULL
)
874 state
= hsram
->State
;
875 if((state
== HAL_SRAM_STATE_READY
) || (state
== HAL_SRAM_STATE_PROTECTED
))
879 case HAL_SRAM_DMA_XFER_CPLT_CB_ID
:
880 hsram
->DmaXferCpltCallback
= pCallback
;
882 case HAL_SRAM_DMA_XFER_ERR_CB_ID
:
883 hsram
->DmaXferErrorCallback
= pCallback
;
886 /* update return status */
893 /* update return status */
907 /** @defgroup SRAM_Exported_Functions_Group3 Control functions
908 * @brief Control functions
911 ==============================================================================
912 ##### SRAM Control functions #####
913 ==============================================================================
915 This subsection provides a set of functions allowing to control dynamically
923 * @brief Enables dynamically SRAM write operation.
924 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
925 * the configuration information for SRAM module.
928 HAL_StatusTypeDef
HAL_SRAM_WriteOperation_Enable(SRAM_HandleTypeDef
*hsram
)
930 /* Check the SRAM controller state */
931 if(hsram
->State
== HAL_SRAM_STATE_PROTECTED
)
936 /* Update the SRAM controller state */
937 hsram
->State
= HAL_SRAM_STATE_BUSY
;
939 /* Enable write operation */
940 (void)FMC_NORSRAM_WriteOperation_Enable(hsram
->Instance
, hsram
->Init
.NSBank
);
942 /* Update the SRAM controller state */
943 hsram
->State
= HAL_SRAM_STATE_READY
;
945 /* Process unlocked */
957 * @brief Disables dynamically SRAM write operation.
958 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
959 * the configuration information for SRAM module.
962 HAL_StatusTypeDef
HAL_SRAM_WriteOperation_Disable(SRAM_HandleTypeDef
*hsram
)
964 /* Check the SRAM controller state */
965 if(hsram
->State
== HAL_SRAM_STATE_READY
)
970 /* Update the SRAM controller state */
971 hsram
->State
= HAL_SRAM_STATE_BUSY
;
973 /* Disable write operation */
974 (void)FMC_NORSRAM_WriteOperation_Disable(hsram
->Instance
, hsram
->Init
.NSBank
);
976 /* Update the SRAM controller state */
977 hsram
->State
= HAL_SRAM_STATE_PROTECTED
;
979 /* Process unlocked */
994 /** @defgroup SRAM_Exported_Functions_Group4 Peripheral State functions
995 * @brief Peripheral State functions
998 ==============================================================================
999 ##### SRAM State functions #####
1000 ==============================================================================
1002 This subsection permits to get in run-time the status of the SRAM controller
1010 * @brief Returns the SRAM controller state
1011 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
1012 * the configuration information for SRAM module.
1015 HAL_SRAM_StateTypeDef
HAL_SRAM_GetState(SRAM_HandleTypeDef
*hsram
)
1017 return hsram
->State
;
1032 * @brief DMA SRAM process complete callback.
1033 * @param hdma : DMA handle
1036 static void SRAM_DMACplt(DMA_HandleTypeDef
*hdma
)
1038 SRAM_HandleTypeDef
* hsram
= ( SRAM_HandleTypeDef
* )(hdma
->Parent
);
1040 /* Disable the DMA channel */
1041 __HAL_DMA_DISABLE(hdma
);
1043 /* Update the SRAM controller state */
1044 hsram
->State
= HAL_SRAM_STATE_READY
;
1046 #if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
1047 hsram
->DmaXferCpltCallback(hdma
);
1049 HAL_SRAM_DMA_XferCpltCallback(hdma
);
1054 * @brief DMA SRAM process complete callback.
1055 * @param hdma : DMA handle
1058 static void SRAM_DMACpltProt(DMA_HandleTypeDef
*hdma
)
1060 SRAM_HandleTypeDef
* hsram
= ( SRAM_HandleTypeDef
* )(hdma
->Parent
);
1062 /* Disable the DMA channel */
1063 __HAL_DMA_DISABLE(hdma
);
1065 /* Update the SRAM controller state */
1066 hsram
->State
= HAL_SRAM_STATE_PROTECTED
;
1068 #if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
1069 hsram
->DmaXferCpltCallback(hdma
);
1071 HAL_SRAM_DMA_XferCpltCallback(hdma
);
1076 * @brief DMA SRAM error callback.
1077 * @param hdma : DMA handle
1080 static void SRAM_DMAError(DMA_HandleTypeDef
*hdma
)
1082 SRAM_HandleTypeDef
* hsram
= ( SRAM_HandleTypeDef
* )(hdma
->Parent
);
1084 /* Disable the DMA channel */
1085 __HAL_DMA_DISABLE(hdma
);
1087 /* Update the SRAM controller state */
1088 hsram
->State
= HAL_SRAM_STATE_ERROR
;
1090 #if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
1091 hsram
->DmaXferErrorCallback(hdma
);
1093 HAL_SRAM_DMA_XferErrorCallback(hdma
);
1104 #endif /* HAL_SRAM_MODULE_ENABLED */
1110 #endif /* FMC_BANK1 */
1112 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/