Subversion Repositories DashDisplay

Rev

Rev 61 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 61 Rev 77
Line 1... Line 1...
1
/**
1
/**
2
  ******************************************************************************
2
  ******************************************************************************
3
  * @file    stm32l1xx_hal_sram.c
3
  * @file    stm32l1xx_hal_sram.c
4
  * @author  MCD Application Team
4
  * @author  MCD Application Team
5
  * @brief   SRAM HAL module driver.
5
  * @brief   SRAM HAL module driver.
6
  *          This file provides a generic firmware to drive SRAM memories
6
  *          This file provides a generic firmware to drive SRAM memories
7
  *          mounted as external device.
7
  *          mounted as external device.
8
  *
8
  *
9
  @verbatim
9
  ******************************************************************************
10
  ==============================================================================
10
  * @attention
11
                          ##### How to use this driver #####
11
  *
12
  ==============================================================================
12
  * Copyright (c) 2016 STMicroelectronics.
13
  [..]
13
  * All rights reserved.
14
    This driver is a generic layered driver which contains a set of APIs used to
14
  *
15
    control SRAM memories. It uses the FSMC layer functions to interface
15
  * This software is licensed under terms that can be found in the LICENSE file
16
    with SRAM devices.
16
  * in the root directory of this software component.
17
    The following sequence should be followed to configure the FSMC to interface
17
  * If no LICENSE file comes with this software, it is provided AS-IS.
18
    with SRAM/PSRAM memories:
18
  *
19
 
19
  ******************************************************************************
20
   (#) Declare a SRAM_HandleTypeDef handle structure, for example:
20
  @verbatim
21
          SRAM_HandleTypeDef  hsram; and:
21
  ==============================================================================
22
 
22
                          ##### How to use this driver #####
23
       (++) Fill the SRAM_HandleTypeDef handle "Init" field with the allowed
23
  ==============================================================================
24
            values of the structure member.
24
  [..]
25
 
25
    This driver is a generic layered driver which contains a set of APIs used to
26
       (++) Fill the SRAM_HandleTypeDef handle "Instance" field with a predefined
26
    control SRAM memories. It uses the FSMC layer functions to interface
27
            base register instance for NOR or SRAM device
27
    with SRAM devices.
28
 
28
    The following sequence should be followed to configure the FSMC to interface
29
       (++) Fill the SRAM_HandleTypeDef handle "Extended" field with a predefined
29
    with SRAM/PSRAM memories:
30
            base register instance for NOR or SRAM extended mode
30
 
31
 
31
   (#) Declare a SRAM_HandleTypeDef handle structure, for example:
32
   (#) Declare two FSMC_NORSRAM_TimingTypeDef structures, for both normal and extended
32
          SRAM_HandleTypeDef  hsram; and:
33
       mode timings; for example:
33
 
34
          FSMC_NORSRAM_TimingTypeDef  Timing and FSMC_NORSRAM_TimingTypeDef  ExTiming;
34
       (++) Fill the SRAM_HandleTypeDef handle "Init" field with the allowed
35
      and fill its fields with the allowed values of the structure member.
35
            values of the structure member.
36
 
36
 
37
   (#) Initialize the SRAM Controller by calling the function HAL_SRAM_Init(). This function
37
       (++) Fill the SRAM_HandleTypeDef handle "Instance" field with a predefined
38
       performs the following sequence:
38
            base register instance for NOR or SRAM device
39
 
39
 
40
       (##) MSP hardware layer configuration using the function HAL_SRAM_MspInit()
40
       (++) Fill the SRAM_HandleTypeDef handle "Extended" field with a predefined
41
       (##) Control register configuration using the FSMC NORSRAM interface function
41
            base register instance for NOR or SRAM extended mode
42
            FSMC_NORSRAM_Init()
42
 
43
       (##) Timing register configuration using the FSMC NORSRAM interface function
43
   (#) Declare two FSMC_NORSRAM_TimingTypeDef structures, for both normal and extended
44
            FSMC_NORSRAM_Timing_Init()
44
       mode timings; for example:
45
       (##) Extended mode Timing register configuration using the FSMC NORSRAM interface function
45
          FSMC_NORSRAM_TimingTypeDef  Timing and FSMC_NORSRAM_TimingTypeDef  ExTiming;
46
            FSMC_NORSRAM_Extended_Timing_Init()
46
      and fill its fields with the allowed values of the structure member.
47
       (##) Enable the SRAM device using the macro __FSMC_NORSRAM_ENABLE()
47
 
48
 
48
   (#) Initialize the SRAM Controller by calling the function HAL_SRAM_Init(). This function
49
   (#) At this stage you can perform read/write accesses from/to the memory connected
49
       performs the following sequence:
50
       to the NOR/SRAM Bank. You can perform either polling or DMA transfer using the
50
 
51
       following APIs:
51
       (##) MSP hardware layer configuration using the function HAL_SRAM_MspInit()
52
       (++) HAL_SRAM_Read()/HAL_SRAM_Write() for polling read/write access
52
       (##) Control register configuration using the FSMC NORSRAM interface function
53
       (++) HAL_SRAM_Read_DMA()/HAL_SRAM_Write_DMA() for DMA read/write transfer
53
            FSMC_NORSRAM_Init()
54
 
54
       (##) Timing register configuration using the FSMC NORSRAM interface function
55
   (#) You can also control the SRAM device by calling the control APIs HAL_SRAM_WriteOperation_Enable()/
55
            FSMC_NORSRAM_Timing_Init()
56
       HAL_SRAM_WriteOperation_Disable() to respectively enable/disable the SRAM write operation
56
       (##) Extended mode Timing register configuration using the FSMC NORSRAM interface function
57
 
57
            FSMC_NORSRAM_Extended_Timing_Init()
58
   (#) You can continuously monitor the SRAM device HAL state by calling the function
58
       (##) Enable the SRAM device using the macro __FSMC_NORSRAM_ENABLE()
59
       HAL_SRAM_GetState()
59
 
60
 
60
   (#) At this stage you can perform read/write accesses from/to the memory connected
61
       *** Callback registration ***
61
       to the NOR/SRAM Bank. You can perform either polling or DMA transfer using the
62
    =============================================
62
       following APIs:
63
    [..]
63
       (++) HAL_SRAM_Read()/HAL_SRAM_Write() for polling read/write access
64
      The compilation define  USE_HAL_SRAM_REGISTER_CALLBACKS when set to 1
64
       (++) HAL_SRAM_Read_DMA()/HAL_SRAM_Write_DMA() for DMA read/write transfer
65
      allows the user to configure dynamically the driver callbacks.
65
 
66
 
66
   (#) You can also control the SRAM device by calling the control APIs HAL_SRAM_WriteOperation_Enable()/
67
      Use Functions @ref HAL_SRAM_RegisterCallback() to register a user callback,
67
       HAL_SRAM_WriteOperation_Disable() to respectively enable/disable the SRAM write operation
68
      it allows to register following callbacks:
68
 
69
        (+) MspInitCallback    : SRAM MspInit.
69
   (#) You can continuously monitor the SRAM device HAL state by calling the function
70
        (+) MspDeInitCallback  : SRAM MspDeInit.
70
       HAL_SRAM_GetState()
71
      This function takes as parameters the HAL peripheral handle, the Callback ID
71
 
72
      and a pointer to the user callback function.
72
       *** Callback registration ***
73
 
73
    =============================================
74
      Use function @ref HAL_SRAM_UnRegisterCallback() to reset a callback to the default
74
    [..]
75
      weak (surcharged) function. It allows to reset following callbacks:
75
      The compilation define  USE_HAL_SRAM_REGISTER_CALLBACKS when set to 1
76
        (+) MspInitCallback    : SRAM MspInit.
76
      allows the user to configure dynamically the driver callbacks.
77
        (+) MspDeInitCallback  : SRAM MspDeInit.
77
 
78
      This function) takes as parameters the HAL peripheral handle and the Callback ID.
78
      Use Functions HAL_SRAM_RegisterCallback() to register a user callback,
79
 
79
      it allows to register following callbacks:
80
      By default, after the @ref HAL_SRAM_Init and if the state is HAL_SRAM_STATE_RESET
80
        (+) MspInitCallback    : SRAM MspInit.
81
      all callbacks are reset to the corresponding legacy weak (surcharged) functions.
81
        (+) MspDeInitCallback  : SRAM MspDeInit.
82
      Exception done for MspInit and MspDeInit callbacks that are respectively
82
      This function takes as parameters the HAL peripheral handle, the Callback ID
83
      reset to the legacy weak (surcharged) functions in the @ref HAL_SRAM_Init
83
      and a pointer to the user callback function.
84
      and @ref  HAL_SRAM_DeInit only when these callbacks are null (not registered beforehand).
84
 
85
      If not, MspInit or MspDeInit are not null, the @ref HAL_SRAM_Init and @ref HAL_SRAM_DeInit
85
      Use function HAL_SRAM_UnRegisterCallback() to reset a callback to the default
86
      keep and use the user MspInit/MspDeInit callbacks (registered beforehand)
86
      weak (surcharged) function. It allows to reset following callbacks:
87
 
87
        (+) MspInitCallback    : SRAM MspInit.
88
      Callbacks can be registered/unregistered in READY state only.
88
        (+) MspDeInitCallback  : SRAM MspDeInit.
89
      Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
89
      This function) takes as parameters the HAL peripheral handle and the Callback ID.
90
      in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
90
 
91
      during the Init/DeInit.
91
      By default, after the HAL_SRAM_Init and if the state is HAL_SRAM_STATE_RESET
92
      In that case first register the MspInit/MspDeInit user callbacks
92
      all callbacks are reset to the corresponding legacy weak (surcharged) functions.
93
      using @ref HAL_SRAM_RegisterCallback before calling @ref HAL_SRAM_DeInit
93
      Exception done for MspInit and MspDeInit callbacks that are respectively
94
      or @ref HAL_SRAM_Init function.
94
      reset to the legacy weak (surcharged) functions in the HAL_SRAM_Init
95
 
95
      and  HAL_SRAM_DeInit only when these callbacks are null (not registered beforehand).
96
      When The compilation define USE_HAL_SRAM_REGISTER_CALLBACKS is set to 0 or
96
      If not, MspInit or MspDeInit are not null, the HAL_SRAM_Init and HAL_SRAM_DeInit
97
      not defined, the callback registering feature is not available
97
      keep and use the user MspInit/MspDeInit callbacks (registered beforehand)
98
      and weak (surcharged) callbacks are used.
98
 
99
 
99
      Callbacks can be registered/unregistered in READY state only.
100
  @endverbatim
100
      Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
101
  ******************************************************************************
101
      in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
102
  * @attention
102
      during the Init/DeInit.
103
  *
103
      In that case first register the MspInit/MspDeInit user callbacks
104
  * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
104
      using HAL_SRAM_RegisterCallback before calling HAL_SRAM_DeInit
105
  * All rights reserved.</center></h2>
105
      or HAL_SRAM_Init function.
106
  *
106
 
107
  * This software component is licensed by ST under BSD 3-Clause license,
107
      When The compilation define USE_HAL_SRAM_REGISTER_CALLBACKS is set to 0 or
108
  * the "License"; You may not use this file except in compliance with the
108
      not defined, the callback registering feature is not available
109
  * License. You may obtain a copy of the License at:
109
      and weak (surcharged) callbacks are used.
110
  *                       opensource.org/licenses/BSD-3-Clause
110
 
111
  *
111
  @endverbatim
112
  ******************************************************************************
112
  ******************************************************************************
113
  */
113
  */
114
 
114
 
115
/* Includes ------------------------------------------------------------------*/
115
/* Includes ------------------------------------------------------------------*/
116
#include "stm32l1xx_hal.h"
116
#include "stm32l1xx_hal.h"
117
 
117
 
118
#if defined(FSMC_BANK1)
118
#if defined(FSMC_BANK1)
119
 
119
 
120
/** @addtogroup STM32L1xx_HAL_Driver
120
/** @addtogroup STM32L1xx_HAL_Driver
121
  * @{
121
  * @{
122
  */
122
  */
123
 
123
 
124
#ifdef HAL_SRAM_MODULE_ENABLED
124
#ifdef HAL_SRAM_MODULE_ENABLED
125
 
125
 
126
/** @defgroup SRAM SRAM
126
/** @defgroup SRAM SRAM
127
  * @brief SRAM driver modules
127
  * @brief SRAM driver modules
128
  * @{
128
  * @{
129
  */
129
  */
130
 
130
 
131
/* Private typedef -----------------------------------------------------------*/
131
/* Private typedef -----------------------------------------------------------*/
132
/* Private define ------------------------------------------------------------*/
132
/* Private define ------------------------------------------------------------*/
133
/* Private macro -------------------------------------------------------------*/
133
/* Private macro -------------------------------------------------------------*/
134
/* Private variables ---------------------------------------------------------*/
134
/* Private variables ---------------------------------------------------------*/
135
/* Private function prototypes -----------------------------------------------*/
135
/* Private function prototypes -----------------------------------------------*/
136
static void SRAM_DMACplt(DMA_HandleTypeDef *hdma);
136
static void SRAM_DMACplt(DMA_HandleTypeDef *hdma);
137
static void SRAM_DMACpltProt(DMA_HandleTypeDef *hdma);
137
static void SRAM_DMACpltProt(DMA_HandleTypeDef *hdma);
138
static void SRAM_DMAError(DMA_HandleTypeDef *hdma);
138
static void SRAM_DMAError(DMA_HandleTypeDef *hdma);
139
 
139
 
140
/* Exported functions --------------------------------------------------------*/
140
/* Exported functions --------------------------------------------------------*/
141
 
141
 
142
/** @defgroup SRAM_Exported_Functions SRAM Exported Functions
142
/** @defgroup SRAM_Exported_Functions SRAM Exported Functions
143
  * @{
143
  * @{
144
  */
144
  */
145
 
145
 
146
/** @defgroup SRAM_Exported_Functions_Group1 Initialization and de-initialization functions
146
/** @defgroup SRAM_Exported_Functions_Group1 Initialization and de-initialization functions
147
  * @brief    Initialization and Configuration functions.
147
  * @brief    Initialization and Configuration functions.
148
  *
148
  *
149
  @verbatim
149
  @verbatim
150
  ==============================================================================
150
  ==============================================================================
151
           ##### SRAM Initialization and de_initialization functions #####
151
           ##### SRAM Initialization and de_initialization functions #####
152
  ==============================================================================
152
  ==============================================================================
153
    [..]  This section provides functions allowing to initialize/de-initialize
153
    [..]  This section provides functions allowing to initialize/de-initialize
154
          the SRAM memory
154
          the SRAM memory
155
 
155
 
156
@endverbatim
156
@endverbatim
157
  * @{
157
  * @{
158
  */
158
  */
159
 
159
 
160
/**
160
/**
161
  * @brief  Performs the SRAM device initialization sequence
161
  * @brief  Performs the SRAM device initialization sequence
162
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
162
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
163
  *                the configuration information for SRAM module.
163
  *                the configuration information for SRAM module.
164
  * @param  Timing Pointer to SRAM control timing structure
164
  * @param  Timing Pointer to SRAM control timing structure
165
  * @param  ExtTiming Pointer to SRAM extended mode timing structure
165
  * @param  ExtTiming Pointer to SRAM extended mode timing structure
166
  * @retval HAL status
166
  * @retval HAL status
167
  */
167
  */
168
HAL_StatusTypeDef HAL_SRAM_Init(SRAM_HandleTypeDef *hsram, FSMC_NORSRAM_TimingTypeDef *Timing,
168
HAL_StatusTypeDef HAL_SRAM_Init(SRAM_HandleTypeDef *hsram, FSMC_NORSRAM_TimingTypeDef *Timing,
169
                                FSMC_NORSRAM_TimingTypeDef *ExtTiming)
169
                                FSMC_NORSRAM_TimingTypeDef *ExtTiming)
170
{
170
{
171
  /* Check the SRAM handle parameter */
171
  /* Check the SRAM handle parameter */
172
  if (hsram == NULL)
172
  if (hsram == NULL)
173
  {
173
  {
174
    return HAL_ERROR;
174
    return HAL_ERROR;
175
  }
175
  }
176
 
176
 
177
  if (hsram->State == HAL_SRAM_STATE_RESET)
177
  if (hsram->State == HAL_SRAM_STATE_RESET)
178
  {
178
  {
179
    /* Allocate lock resource and initialize it */
179
    /* Allocate lock resource and initialize it */
180
    hsram->Lock = HAL_UNLOCKED;
180
    hsram->Lock = HAL_UNLOCKED;
181
 
181
 
182
#if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
182
#if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
183
    if (hsram->MspInitCallback == NULL)
183
    if (hsram->MspInitCallback == NULL)
184
    {
184
    {
185
      hsram->MspInitCallback = HAL_SRAM_MspInit;
185
      hsram->MspInitCallback = HAL_SRAM_MspInit;
186
    }
186
    }
187
    hsram->DmaXferCpltCallback = HAL_SRAM_DMA_XferCpltCallback;
187
    hsram->DmaXferCpltCallback = HAL_SRAM_DMA_XferCpltCallback;
188
    hsram->DmaXferErrorCallback = HAL_SRAM_DMA_XferErrorCallback;
188
    hsram->DmaXferErrorCallback = HAL_SRAM_DMA_XferErrorCallback;
189
 
189
 
190
    /* Init the low level hardware */
190
    /* Init the low level hardware */
191
    hsram->MspInitCallback(hsram);
191
    hsram->MspInitCallback(hsram);
192
#else
192
#else
193
    /* Initialize the low level hardware (MSP) */
193
    /* Initialize the low level hardware (MSP) */
194
    HAL_SRAM_MspInit(hsram);
194
    HAL_SRAM_MspInit(hsram);
195
#endif /* USE_HAL_SRAM_REGISTER_CALLBACKS */
195
#endif /* USE_HAL_SRAM_REGISTER_CALLBACKS */
196
  }
196
  }
197
 
197
 
198
  /* Initialize SRAM control Interface */
198
  /* Initialize SRAM control Interface */
199
  (void)FSMC_NORSRAM_Init(hsram->Instance, &(hsram->Init));
199
  (void)FSMC_NORSRAM_Init(hsram->Instance, &(hsram->Init));
200
 
200
 
201
  /* Initialize SRAM timing Interface */
201
  /* Initialize SRAM timing Interface */
202
  (void)FSMC_NORSRAM_Timing_Init(hsram->Instance, Timing, hsram->Init.NSBank);
202
  (void)FSMC_NORSRAM_Timing_Init(hsram->Instance, Timing, hsram->Init.NSBank);
203
 
203
 
204
  /* Initialize SRAM extended mode timing Interface */
204
  /* Initialize SRAM extended mode timing Interface */
205
  (void)FSMC_NORSRAM_Extended_Timing_Init(hsram->Extended, ExtTiming, hsram->Init.NSBank,
205
  (void)FSMC_NORSRAM_Extended_Timing_Init(hsram->Extended, ExtTiming, hsram->Init.NSBank,
206
                                         hsram->Init.ExtendedMode);
206
                                         hsram->Init.ExtendedMode);
207
 
207
 
208
  /* Enable the NORSRAM device */
208
  /* Enable the NORSRAM device */
209
  __FSMC_NORSRAM_ENABLE(hsram->Instance, hsram->Init.NSBank);
209
  __FSMC_NORSRAM_ENABLE(hsram->Instance, hsram->Init.NSBank);
210
 
210
 
211
  /* Initialize the SRAM controller state */
211
  /* Initialize the SRAM controller state */
212
  hsram->State = HAL_SRAM_STATE_READY;
212
  hsram->State = HAL_SRAM_STATE_READY;
213
 
213
 
214
  return HAL_OK;
214
  return HAL_OK;
215
}
215
}
216
 
216
 
217
/**
217
/**
218
  * @brief  Performs the SRAM device De-initialization sequence.
218
  * @brief  Performs the SRAM device De-initialization sequence.
219
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
219
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
220
  *                the configuration information for SRAM module.
220
  *                the configuration information for SRAM module.
221
  * @retval HAL status
221
  * @retval HAL status
222
  */
222
  */
223
HAL_StatusTypeDef HAL_SRAM_DeInit(SRAM_HandleTypeDef *hsram)
223
HAL_StatusTypeDef HAL_SRAM_DeInit(SRAM_HandleTypeDef *hsram)
224
{
224
{
225
#if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
225
#if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
226
  if (hsram->MspDeInitCallback == NULL)
226
  if (hsram->MspDeInitCallback == NULL)
227
  {
227
  {
228
    hsram->MspDeInitCallback = HAL_SRAM_MspDeInit;
228
    hsram->MspDeInitCallback = HAL_SRAM_MspDeInit;
229
  }
229
  }
230
 
230
 
231
  /* DeInit the low level hardware */
231
  /* DeInit the low level hardware */
232
  hsram->MspDeInitCallback(hsram);
232
  hsram->MspDeInitCallback(hsram);
233
#else
233
#else
234
  /* De-Initialize the low level hardware (MSP) */
234
  /* De-Initialize the low level hardware (MSP) */
235
  HAL_SRAM_MspDeInit(hsram);
235
  HAL_SRAM_MspDeInit(hsram);
236
#endif /* USE_HAL_SRAM_REGISTER_CALLBACKS */
236
#endif /* USE_HAL_SRAM_REGISTER_CALLBACKS */
237
 
237
 
238
  /* Configure the SRAM registers with their reset values */
238
  /* Configure the SRAM registers with their reset values */
239
  (void)FSMC_NORSRAM_DeInit(hsram->Instance, hsram->Extended, hsram->Init.NSBank);
239
  (void)FSMC_NORSRAM_DeInit(hsram->Instance, hsram->Extended, hsram->Init.NSBank);
240
 
240
 
241
  /* Reset the SRAM controller state */
241
  /* Reset the SRAM controller state */
242
  hsram->State = HAL_SRAM_STATE_RESET;
242
  hsram->State = HAL_SRAM_STATE_RESET;
243
 
243
 
244
  /* Release Lock */
244
  /* Release Lock */
245
  __HAL_UNLOCK(hsram);
245
  __HAL_UNLOCK(hsram);
246
 
246
 
247
  return HAL_OK;
247
  return HAL_OK;
248
}
248
}
249
 
249
 
250
/**
250
/**
251
  * @brief  SRAM MSP Init.
251
  * @brief  SRAM MSP Init.
252
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
252
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
253
  *                the configuration information for SRAM module.
253
  *                the configuration information for SRAM module.
254
  * @retval None
254
  * @retval None
255
  */
255
  */
256
__weak void HAL_SRAM_MspInit(SRAM_HandleTypeDef *hsram)
256
__weak void HAL_SRAM_MspInit(SRAM_HandleTypeDef *hsram)
257
{
257
{
258
  /* Prevent unused argument(s) compilation warning */
258
  /* Prevent unused argument(s) compilation warning */
259
  UNUSED(hsram);
259
  UNUSED(hsram);
260
 
260
 
261
  /* NOTE : This function Should not be modified, when the callback is needed,
261
  /* NOTE : This function Should not be modified, when the callback is needed,
262
            the HAL_SRAM_MspInit could be implemented in the user file
262
            the HAL_SRAM_MspInit could be implemented in the user file
263
   */
263
   */
264
}
264
}
265
 
265
 
266
/**
266
/**
267
  * @brief  SRAM MSP DeInit.
267
  * @brief  SRAM MSP DeInit.
268
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
268
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
269
  *                the configuration information for SRAM module.
269
  *                the configuration information for SRAM module.
270
  * @retval None
270
  * @retval None
271
  */
271
  */
272
__weak void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef *hsram)
272
__weak void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef *hsram)
273
{
273
{
274
  /* Prevent unused argument(s) compilation warning */
274
  /* Prevent unused argument(s) compilation warning */
275
  UNUSED(hsram);
275
  UNUSED(hsram);
276
 
276
 
277
  /* NOTE : This function Should not be modified, when the callback is needed,
277
  /* NOTE : This function Should not be modified, when the callback is needed,
278
            the HAL_SRAM_MspDeInit could be implemented in the user file
278
            the HAL_SRAM_MspDeInit could be implemented in the user file
279
   */
279
   */
280
}
280
}
281
 
281
 
282
/**
282
/**
283
  * @brief  DMA transfer complete callback.
283
  * @brief  DMA transfer complete callback.
284
  * @param  hdma pointer to a SRAM_HandleTypeDef structure that contains
284
  * @param  hdma pointer to a SRAM_HandleTypeDef structure that contains
285
  *                the configuration information for SRAM module.
285
  *                the configuration information for SRAM module.
286
  * @retval None
286
  * @retval None
287
  */
287
  */
288
__weak void HAL_SRAM_DMA_XferCpltCallback(DMA_HandleTypeDef *hdma)
288
__weak void HAL_SRAM_DMA_XferCpltCallback(DMA_HandleTypeDef *hdma)
289
{
289
{
290
  /* Prevent unused argument(s) compilation warning */
290
  /* Prevent unused argument(s) compilation warning */
291
  UNUSED(hdma);
291
  UNUSED(hdma);
292
 
292
 
293
  /* NOTE : This function Should not be modified, when the callback is needed,
293
  /* NOTE : This function Should not be modified, when the callback is needed,
294
            the HAL_SRAM_DMA_XferCpltCallback could be implemented in the user file
294
            the HAL_SRAM_DMA_XferCpltCallback could be implemented in the user file
295
   */
295
   */
296
}
296
}
297
 
297
 
298
/**
298
/**
299
  * @brief  DMA transfer complete error callback.
299
  * @brief  DMA transfer complete error callback.
300
  * @param  hdma pointer to a SRAM_HandleTypeDef structure that contains
300
  * @param  hdma pointer to a SRAM_HandleTypeDef structure that contains
301
  *                the configuration information for SRAM module.
301
  *                the configuration information for SRAM module.
302
  * @retval None
302
  * @retval None
303
  */
303
  */
304
__weak void HAL_SRAM_DMA_XferErrorCallback(DMA_HandleTypeDef *hdma)
304
__weak void HAL_SRAM_DMA_XferErrorCallback(DMA_HandleTypeDef *hdma)
305
{
305
{
306
  /* Prevent unused argument(s) compilation warning */
306
  /* Prevent unused argument(s) compilation warning */
307
  UNUSED(hdma);
307
  UNUSED(hdma);
308
 
308
 
309
  /* NOTE : This function Should not be modified, when the callback is needed,
309
  /* NOTE : This function Should not be modified, when the callback is needed,
310
            the HAL_SRAM_DMA_XferErrorCallback could be implemented in the user file
310
            the HAL_SRAM_DMA_XferErrorCallback could be implemented in the user file
311
   */
311
   */
312
}
312
}
313
 
313
 
314
/**
314
/**
315
  * @}
315
  * @}
316
  */
316
  */
317
 
317
 
318
/** @defgroup SRAM_Exported_Functions_Group2 Input Output and memory control functions
318
/** @defgroup SRAM_Exported_Functions_Group2 Input Output and memory control functions
319
  * @brief    Input Output and memory control functions
319
  * @brief    Input Output and memory control functions
320
  *
320
  *
321
  @verbatim
321
  @verbatim
322
  ==============================================================================
322
  ==============================================================================
323
                  ##### SRAM Input and Output functions #####
323
                  ##### SRAM Input and Output functions #####
324
  ==============================================================================
324
  ==============================================================================
325
  [..]
325
  [..]
326
    This section provides functions allowing to use and control the SRAM memory
326
    This section provides functions allowing to use and control the SRAM memory
327
 
327
 
328
@endverbatim
328
@endverbatim
329
  * @{
329
  * @{
330
  */
330
  */
331
 
331
 
332
/**
332
/**
333
  * @brief  Reads 8-bit buffer from SRAM memory.
333
  * @brief  Reads 8-bit buffer from SRAM memory.
334
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
334
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
335
  *                the configuration information for SRAM module.
335
  *                the configuration information for SRAM module.
336
  * @param  pAddress Pointer to read start address
336
  * @param  pAddress Pointer to read start address
337
  * @param  pDstBuffer Pointer to destination buffer
337
  * @param  pDstBuffer Pointer to destination buffer
338
  * @param  BufferSize Size of the buffer to read from memory
338
  * @param  BufferSize Size of the buffer to read from memory
339
  * @retval HAL status
339
  * @retval HAL status
340
  */
340
  */
341
HAL_StatusTypeDef HAL_SRAM_Read_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pDstBuffer,
341
HAL_StatusTypeDef HAL_SRAM_Read_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pDstBuffer,
342
                                   uint32_t BufferSize)
342
                                   uint32_t BufferSize)
343
{
343
{
344
  uint32_t size;
344
  uint32_t size;
345
  __IO uint8_t *psramaddress = (uint8_t *)pAddress;
345
  __IO uint8_t *psramaddress = (uint8_t *)pAddress;
346
  uint8_t *pdestbuff = pDstBuffer;
346
  uint8_t *pdestbuff = pDstBuffer;
347
  HAL_SRAM_StateTypeDef state = hsram->State;
347
  HAL_SRAM_StateTypeDef state = hsram->State;
348
 
348
 
349
  /* Check the SRAM controller state */
349
  /* Check the SRAM controller state */
350
  if ((state == HAL_SRAM_STATE_READY) || (state == HAL_SRAM_STATE_PROTECTED))
350
  if ((state == HAL_SRAM_STATE_READY) || (state == HAL_SRAM_STATE_PROTECTED))
351
  {
351
  {
352
    /* Process Locked */
352
    /* Process Locked */
353
    __HAL_LOCK(hsram);
353
    __HAL_LOCK(hsram);
354
 
354
 
355
    /* Update the SRAM controller state */
355
    /* Update the SRAM controller state */
356
    hsram->State = HAL_SRAM_STATE_BUSY;
356
    hsram->State = HAL_SRAM_STATE_BUSY;
357
 
357
 
358
    /* Read data from memory */
358
    /* Read data from memory */
359
    for (size = BufferSize; size != 0U; size--)
359
    for (size = BufferSize; size != 0U; size--)
360
    {
360
    {
361
      *pdestbuff = *psramaddress;
361
      *pdestbuff = *psramaddress;
362
      pdestbuff++;
362
      pdestbuff++;
363
      psramaddress++;
363
      psramaddress++;
364
    }
364
    }
365
 
365
 
366
    /* Update the SRAM controller state */
366
    /* Update the SRAM controller state */
367
    hsram->State = state;
367
    hsram->State = state;
368
 
368
 
369
    /* Process unlocked */
369
    /* Process unlocked */
370
    __HAL_UNLOCK(hsram);
370
    __HAL_UNLOCK(hsram);
371
  }
371
  }
372
  else
372
  else
373
  {
373
  {
374
    return HAL_ERROR;
374
    return HAL_ERROR;
375
  }
375
  }
376
 
376
 
377
  return HAL_OK;
377
  return HAL_OK;
378
}
378
}
379
 
379
 
380
/**
380
/**
381
  * @brief  Writes 8-bit buffer to SRAM memory.
381
  * @brief  Writes 8-bit buffer to SRAM memory.
382
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
382
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
383
  *                the configuration information for SRAM module.
383
  *                the configuration information for SRAM module.
384
  * @param  pAddress Pointer to write start address
384
  * @param  pAddress Pointer to write start address
385
  * @param  pSrcBuffer Pointer to source buffer to write
385
  * @param  pSrcBuffer Pointer to source buffer to write
386
  * @param  BufferSize Size of the buffer to write to memory
386
  * @param  BufferSize Size of the buffer to write to memory
387
  * @retval HAL status
387
  * @retval HAL status
388
  */
388
  */
389
HAL_StatusTypeDef HAL_SRAM_Write_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pSrcBuffer,
389
HAL_StatusTypeDef HAL_SRAM_Write_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pSrcBuffer,
390
                                    uint32_t BufferSize)
390
                                    uint32_t BufferSize)
391
{
391
{
392
  uint32_t size;
392
  uint32_t size;
393
  __IO uint8_t *psramaddress = (uint8_t *)pAddress;
393
  __IO uint8_t *psramaddress = (uint8_t *)pAddress;
394
  uint8_t *psrcbuff = pSrcBuffer;
394
  uint8_t *psrcbuff = pSrcBuffer;
395
 
395
 
396
  /* Check the SRAM controller state */
396
  /* Check the SRAM controller state */
397
  if (hsram->State == HAL_SRAM_STATE_READY)
397
  if (hsram->State == HAL_SRAM_STATE_READY)
398
  {
398
  {
399
    /* Process Locked */
399
    /* Process Locked */
400
    __HAL_LOCK(hsram);
400
    __HAL_LOCK(hsram);
401
 
401
 
402
    /* Update the SRAM controller state */
402
    /* Update the SRAM controller state */
403
    hsram->State = HAL_SRAM_STATE_BUSY;
403
    hsram->State = HAL_SRAM_STATE_BUSY;
404
 
404
 
405
    /* Write data to memory */
405
    /* Write data to memory */
406
    for (size = BufferSize; size != 0U; size--)
406
    for (size = BufferSize; size != 0U; size--)
407
    {
407
    {
408
      *psramaddress = *psrcbuff;
408
      *psramaddress = *psrcbuff;
409
      psrcbuff++;
409
      psrcbuff++;
410
      psramaddress++;
410
      psramaddress++;
411
    }
411
    }
412
 
412
 
413
    /* Update the SRAM controller state */
413
    /* Update the SRAM controller state */
414
    hsram->State = HAL_SRAM_STATE_READY;
414
    hsram->State = HAL_SRAM_STATE_READY;
415
 
415
 
416
    /* Process unlocked */
416
    /* Process unlocked */
417
    __HAL_UNLOCK(hsram);
417
    __HAL_UNLOCK(hsram);
418
  }
418
  }
419
  else
419
  else
420
  {
420
  {
421
    return HAL_ERROR;
421
    return HAL_ERROR;
422
  }
422
  }
423
 
423
 
424
  return HAL_OK;
424
  return HAL_OK;
425
}
425
}
426
 
426
 
427
/**
427
/**
428
  * @brief  Reads 16-bit buffer from SRAM memory.
428
  * @brief  Reads 16-bit buffer from SRAM memory.
429
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
429
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
430
  *                the configuration information for SRAM module.
430
  *                the configuration information for SRAM module.
431
  * @param  pAddress Pointer to read start address
431
  * @param  pAddress Pointer to read start address
432
  * @param  pDstBuffer Pointer to destination buffer
432
  * @param  pDstBuffer Pointer to destination buffer
433
  * @param  BufferSize Size of the buffer to read from memory
433
  * @param  BufferSize Size of the buffer to read from memory
434
  * @retval HAL status
434
  * @retval HAL status
435
  */
435
  */
436
HAL_StatusTypeDef HAL_SRAM_Read_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pDstBuffer,
436
HAL_StatusTypeDef HAL_SRAM_Read_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pDstBuffer,
437
                                    uint32_t BufferSize)
437
                                    uint32_t BufferSize)
438
{
438
{
439
  uint32_t size;
439
  uint32_t size;
440
  __IO uint32_t *psramaddress = pAddress;
440
  __IO uint32_t *psramaddress = pAddress;
441
  uint16_t *pdestbuff = pDstBuffer;
441
  uint16_t *pdestbuff = pDstBuffer;
442
  uint8_t limit;
442
  uint8_t limit;
443
  HAL_SRAM_StateTypeDef state = hsram->State;
443
  HAL_SRAM_StateTypeDef state = hsram->State;
444
 
444
 
445
  /* Check the SRAM controller state */
445
  /* Check the SRAM controller state */
446
  if ((state == HAL_SRAM_STATE_READY) || (state == HAL_SRAM_STATE_PROTECTED))
446
  if ((state == HAL_SRAM_STATE_READY) || (state == HAL_SRAM_STATE_PROTECTED))
447
  {
447
  {
448
    /* Process Locked */
448
    /* Process Locked */
449
    __HAL_LOCK(hsram);
449
    __HAL_LOCK(hsram);
450
 
450
 
451
    /* Update the SRAM controller state */
451
    /* Update the SRAM controller state */
452
    hsram->State = HAL_SRAM_STATE_BUSY;
452
    hsram->State = HAL_SRAM_STATE_BUSY;
453
 
453
 
454
    /* Check if the size is a 32-bits multiple */
454
    /* Check if the size is a 32-bits multiple */
455
    limit = (((BufferSize % 2U) != 0U) ? 1U : 0U);
455
    limit = (((BufferSize % 2U) != 0U) ? 1U : 0U);
456
 
456
 
457
    /* Read data from memory */
457
    /* Read data from memory */
458
    for (size = BufferSize; size != limit; size -= 2U)
458
    for (size = BufferSize; size != limit; size -= 2U)
459
    {
459
    {
460
      *pdestbuff = (uint16_t)((*psramaddress) & 0x0000FFFFU);
460
      *pdestbuff = (uint16_t)((*psramaddress) & 0x0000FFFFU);
461
      pdestbuff++;
461
      pdestbuff++;
462
      *pdestbuff = (uint16_t)(((*psramaddress) & 0xFFFF0000U) >> 16U);
462
      *pdestbuff = (uint16_t)(((*psramaddress) & 0xFFFF0000U) >> 16U);
463
      pdestbuff++;
463
      pdestbuff++;
464
      psramaddress++;
464
      psramaddress++;
465
    }
465
    }
466
 
466
 
467
    /* Read last 16-bits if size is not 32-bits multiple */
467
    /* Read last 16-bits if size is not 32-bits multiple */
468
    if (limit != 0U)
468
    if (limit != 0U)
469
    {
469
    {
470
      *pdestbuff = (uint16_t)((*psramaddress) & 0x0000FFFFU);
470
      *pdestbuff = (uint16_t)((*psramaddress) & 0x0000FFFFU);
471
    }
471
    }
472
 
472
 
473
    /* Update the SRAM controller state */
473
    /* Update the SRAM controller state */
474
    hsram->State = state;
474
    hsram->State = state;
475
 
475
 
476
    /* Process unlocked */
476
    /* Process unlocked */
477
    __HAL_UNLOCK(hsram);
477
    __HAL_UNLOCK(hsram);
478
  }
478
  }
479
  else
479
  else
480
  {
480
  {
481
    return HAL_ERROR;
481
    return HAL_ERROR;
482
  }
482
  }
483
 
483
 
484
  return HAL_OK;
484
  return HAL_OK;
485
}
485
}
486
 
486
 
487
/**
487
/**
488
  * @brief  Writes 16-bit buffer to SRAM memory.
488
  * @brief  Writes 16-bit buffer to SRAM memory.
489
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
489
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
490
  *                the configuration information for SRAM module.
490
  *                the configuration information for SRAM module.
491
  * @param  pAddress Pointer to write start address
491
  * @param  pAddress Pointer to write start address
492
  * @param  pSrcBuffer Pointer to source buffer to write
492
  * @param  pSrcBuffer Pointer to source buffer to write
493
  * @param  BufferSize Size of the buffer to write to memory
493
  * @param  BufferSize Size of the buffer to write to memory
494
  * @retval HAL status
494
  * @retval HAL status
495
  */
495
  */
496
HAL_StatusTypeDef HAL_SRAM_Write_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pSrcBuffer,
496
HAL_StatusTypeDef HAL_SRAM_Write_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pSrcBuffer,
497
                                     uint32_t BufferSize)
497
                                     uint32_t BufferSize)
498
{
498
{
499
  uint32_t size;
499
  uint32_t size;
500
  __IO uint32_t *psramaddress = pAddress;
500
  __IO uint32_t *psramaddress = pAddress;
501
  uint16_t *psrcbuff = pSrcBuffer;
501
  uint16_t *psrcbuff = pSrcBuffer;
502
  uint8_t limit;
502
  uint8_t limit;
503
 
503
 
504
  /* Check the SRAM controller state */
504
  /* Check the SRAM controller state */
505
  if (hsram->State == HAL_SRAM_STATE_READY)
505
  if (hsram->State == HAL_SRAM_STATE_READY)
506
  {
506
  {
507
    /* Process Locked */
507
    /* Process Locked */
508
    __HAL_LOCK(hsram);
508
    __HAL_LOCK(hsram);
509
 
509
 
510
    /* Update the SRAM controller state */
510
    /* Update the SRAM controller state */
511
    hsram->State = HAL_SRAM_STATE_BUSY;
511
    hsram->State = HAL_SRAM_STATE_BUSY;
512
 
512
 
513
    /* Check if the size is a 32-bits multiple */
513
    /* Check if the size is a 32-bits multiple */
514
    limit = (((BufferSize % 2U) != 0U) ? 1U : 0U);
514
    limit = (((BufferSize % 2U) != 0U) ? 1U : 0U);
515
 
515
 
516
    /* Write data to memory */
516
    /* Write data to memory */
517
    for (size = BufferSize; size != limit; size -= 2U)
517
    for (size = BufferSize; size != limit; size -= 2U)
518
    {
518
    {
519
      *psramaddress = (uint32_t)(*psrcbuff);
519
      *psramaddress = (uint32_t)(*psrcbuff);
520
      psrcbuff++;
520
      psrcbuff++;
521
      *psramaddress |= ((uint32_t)(*psrcbuff) << 16U);
521
      *psramaddress |= ((uint32_t)(*psrcbuff) << 16U);
522
      psrcbuff++;
522
      psrcbuff++;
523
      psramaddress++;
523
      psramaddress++;
524
    }
524
    }
525
 
525
 
526
    /* Write last 16-bits if size is not 32-bits multiple */
526
    /* Write last 16-bits if size is not 32-bits multiple */
527
    if (limit != 0U)
527
    if (limit != 0U)
528
    {
528
    {
529
      *psramaddress = ((uint32_t)(*psrcbuff) & 0x0000FFFFU) | ((*psramaddress) & 0xFFFF0000U);
529
      *psramaddress = ((uint32_t)(*psrcbuff) & 0x0000FFFFU) | ((*psramaddress) & 0xFFFF0000U);
530
    }
530
    }
531
 
531
 
532
    /* Update the SRAM controller state */
532
    /* Update the SRAM controller state */
533
    hsram->State = HAL_SRAM_STATE_READY;
533
    hsram->State = HAL_SRAM_STATE_READY;
534
 
534
 
535
    /* Process unlocked */
535
    /* Process unlocked */
536
    __HAL_UNLOCK(hsram);
536
    __HAL_UNLOCK(hsram);
537
  }
537
  }
538
  else
538
  else
539
  {
539
  {
540
    return HAL_ERROR;
540
    return HAL_ERROR;
541
  }
541
  }
542
 
542
 
543
  return HAL_OK;
543
  return HAL_OK;
544
}
544
}
545
 
545
 
546
/**
546
/**
547
  * @brief  Reads 32-bit buffer from SRAM memory.
547
  * @brief  Reads 32-bit buffer from SRAM memory.
548
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
548
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
549
  *                the configuration information for SRAM module.
549
  *                the configuration information for SRAM module.
550
  * @param  pAddress Pointer to read start address
550
  * @param  pAddress Pointer to read start address
551
  * @param  pDstBuffer Pointer to destination buffer
551
  * @param  pDstBuffer Pointer to destination buffer
552
  * @param  BufferSize Size of the buffer to read from memory
552
  * @param  BufferSize Size of the buffer to read from memory
553
  * @retval HAL status
553
  * @retval HAL status
554
  */
554
  */
555
HAL_StatusTypeDef HAL_SRAM_Read_32b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pDstBuffer,
555
HAL_StatusTypeDef HAL_SRAM_Read_32b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pDstBuffer,
556
                                    uint32_t BufferSize)
556
                                    uint32_t BufferSize)
557
{
557
{
558
  uint32_t size;
558
  uint32_t size;
559
  __IO uint32_t *psramaddress = pAddress;
559
  __IO uint32_t *psramaddress = pAddress;
560
  uint32_t *pdestbuff = pDstBuffer;
560
  uint32_t *pdestbuff = pDstBuffer;
561
  HAL_SRAM_StateTypeDef state = hsram->State;
561
  HAL_SRAM_StateTypeDef state = hsram->State;
562
 
562
 
563
  /* Check the SRAM controller state */
563
  /* Check the SRAM controller state */
564
  if ((state == HAL_SRAM_STATE_READY) || (state == HAL_SRAM_STATE_PROTECTED))
564
  if ((state == HAL_SRAM_STATE_READY) || (state == HAL_SRAM_STATE_PROTECTED))
565
  {
565
  {
566
    /* Process Locked */
566
    /* Process Locked */
567
    __HAL_LOCK(hsram);
567
    __HAL_LOCK(hsram);
568
 
568
 
569
    /* Update the SRAM controller state */
569
    /* Update the SRAM controller state */
570
    hsram->State = HAL_SRAM_STATE_BUSY;
570
    hsram->State = HAL_SRAM_STATE_BUSY;
571
 
571
 
572
    /* Read data from memory */
572
    /* Read data from memory */
573
    for (size = BufferSize; size != 0U; size--)
573
    for (size = BufferSize; size != 0U; size--)
574
    {
574
    {
575
      *pdestbuff = *psramaddress;
575
      *pdestbuff = *psramaddress;
576
      pdestbuff++;
576
      pdestbuff++;
577
      psramaddress++;
577
      psramaddress++;
578
    }
578
    }
579
 
579
 
580
    /* Update the SRAM controller state */
580
    /* Update the SRAM controller state */
581
    hsram->State = state;
581
    hsram->State = state;
582
 
582
 
583
    /* Process unlocked */
583
    /* Process unlocked */
584
    __HAL_UNLOCK(hsram);
584
    __HAL_UNLOCK(hsram);
585
  }
585
  }
586
  else
586
  else
587
  {
587
  {
588
    return HAL_ERROR;
588
    return HAL_ERROR;
589
  }
589
  }
590
 
590
 
591
  return HAL_OK;
591
  return HAL_OK;
592
}
592
}
593
 
593
 
594
/**
594
/**
595
  * @brief  Writes 32-bit buffer to SRAM memory.
595
  * @brief  Writes 32-bit buffer to SRAM memory.
596
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
596
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
597
  *                the configuration information for SRAM module.
597
  *                the configuration information for SRAM module.
598
  * @param  pAddress Pointer to write start address
598
  * @param  pAddress Pointer to write start address
599
  * @param  pSrcBuffer Pointer to source buffer to write
599
  * @param  pSrcBuffer Pointer to source buffer to write
600
  * @param  BufferSize Size of the buffer to write to memory
600
  * @param  BufferSize Size of the buffer to write to memory
601
  * @retval HAL status
601
  * @retval HAL status
602
  */
602
  */
603
HAL_StatusTypeDef HAL_SRAM_Write_32b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pSrcBuffer,
603
HAL_StatusTypeDef HAL_SRAM_Write_32b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pSrcBuffer,
604
                                     uint32_t BufferSize)
604
                                     uint32_t BufferSize)
605
{
605
{
606
  uint32_t size;
606
  uint32_t size;
607
  __IO uint32_t *psramaddress = pAddress;
607
  __IO uint32_t *psramaddress = pAddress;
608
  uint32_t *psrcbuff = pSrcBuffer;
608
  uint32_t *psrcbuff = pSrcBuffer;
609
 
609
 
610
  /* Check the SRAM controller state */
610
  /* Check the SRAM controller state */
611
  if (hsram->State == HAL_SRAM_STATE_READY)
611
  if (hsram->State == HAL_SRAM_STATE_READY)
612
  {
612
  {
613
    /* Process Locked */
613
    /* Process Locked */
614
    __HAL_LOCK(hsram);
614
    __HAL_LOCK(hsram);
615
 
615
 
616
    /* Update the SRAM controller state */
616
    /* Update the SRAM controller state */
617
    hsram->State = HAL_SRAM_STATE_BUSY;
617
    hsram->State = HAL_SRAM_STATE_BUSY;
618
 
618
 
619
    /* Write data to memory */
619
    /* Write data to memory */
620
    for (size = BufferSize; size != 0U; size--)
620
    for (size = BufferSize; size != 0U; size--)
621
    {
621
    {
622
      *psramaddress = *psrcbuff;
622
      *psramaddress = *psrcbuff;
623
      psrcbuff++;
623
      psrcbuff++;
624
      psramaddress++;
624
      psramaddress++;
625
    }
625
    }
626
 
626
 
627
    /* Update the SRAM controller state */
627
    /* Update the SRAM controller state */
628
    hsram->State = HAL_SRAM_STATE_READY;
628
    hsram->State = HAL_SRAM_STATE_READY;
629
 
629
 
630
    /* Process unlocked */
630
    /* Process unlocked */
631
    __HAL_UNLOCK(hsram);
631
    __HAL_UNLOCK(hsram);
632
  }
632
  }
633
  else
633
  else
634
  {
634
  {
635
    return HAL_ERROR;
635
    return HAL_ERROR;
636
  }
636
  }
637
 
637
 
638
  return HAL_OK;
638
  return HAL_OK;
639
}
639
}
640
 
640
 
641
/**
641
/**
642
  * @brief  Reads a Words data from the SRAM memory using DMA transfer.
642
  * @brief  Reads a Words data from the SRAM memory using DMA transfer.
643
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
643
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
644
  *                the configuration information for SRAM module.
644
  *                the configuration information for SRAM module.
645
  * @param  pAddress Pointer to read start address
645
  * @param  pAddress Pointer to read start address
646
  * @param  pDstBuffer Pointer to destination buffer
646
  * @param  pDstBuffer Pointer to destination buffer
647
  * @param  BufferSize Size of the buffer to read from memory
647
  * @param  BufferSize Size of the buffer to read from memory
648
  * @retval HAL status
648
  * @retval HAL status
649
  */
649
  */
650
HAL_StatusTypeDef HAL_SRAM_Read_DMA(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pDstBuffer,
650
HAL_StatusTypeDef HAL_SRAM_Read_DMA(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pDstBuffer,
651
                                    uint32_t BufferSize)
651
                                    uint32_t BufferSize)
652
{
652
{
653
  HAL_StatusTypeDef status;
653
  HAL_StatusTypeDef status;
654
  HAL_SRAM_StateTypeDef state = hsram->State;
654
  HAL_SRAM_StateTypeDef state = hsram->State;
655
 
655
 
656
  /* Check the SRAM controller state */
656
  /* Check the SRAM controller state */
657
  if ((state == HAL_SRAM_STATE_READY) || (state == HAL_SRAM_STATE_PROTECTED))
657
  if ((state == HAL_SRAM_STATE_READY) || (state == HAL_SRAM_STATE_PROTECTED))
658
  {
658
  {
659
    /* Process Locked */
659
    /* Process Locked */
660
    __HAL_LOCK(hsram);
660
    __HAL_LOCK(hsram);
661
 
661
 
662
    /* Update the SRAM controller state */
662
    /* Update the SRAM controller state */
663
    hsram->State = HAL_SRAM_STATE_BUSY;
663
    hsram->State = HAL_SRAM_STATE_BUSY;
664
 
664
 
665
    /* Configure DMA user callbacks */
665
    /* Configure DMA user callbacks */
666
    if (state == HAL_SRAM_STATE_READY)
666
    if (state == HAL_SRAM_STATE_READY)
667
    {
667
    {
668
      hsram->hdma->XferCpltCallback = SRAM_DMACplt;
668
      hsram->hdma->XferCpltCallback = SRAM_DMACplt;
669
    }
669
    }
670
    else
670
    else
671
    {
671
    {
672
      hsram->hdma->XferCpltCallback = SRAM_DMACpltProt;
672
      hsram->hdma->XferCpltCallback = SRAM_DMACpltProt;
673
    }
673
    }
674
    hsram->hdma->XferErrorCallback = SRAM_DMAError;
674
    hsram->hdma->XferErrorCallback = SRAM_DMAError;
675
 
675
 
676
    /* Enable the DMA Stream */
676
    /* Enable the DMA Stream */
677
    status = HAL_DMA_Start_IT(hsram->hdma, (uint32_t)pAddress, (uint32_t)pDstBuffer, (uint32_t)BufferSize);
677
    status = HAL_DMA_Start_IT(hsram->hdma, (uint32_t)pAddress, (uint32_t)pDstBuffer, (uint32_t)BufferSize);
678
 
678
 
679
    /* Process unlocked */
679
    /* Process unlocked */
680
    __HAL_UNLOCK(hsram);
680
    __HAL_UNLOCK(hsram);
681
  }
681
  }
682
  else
682
  else
683
  {
683
  {
684
    status = HAL_ERROR;
684
    status = HAL_ERROR;
685
  }
685
  }
686
 
686
 
687
  return status;
687
  return status;
688
}
688
}
689
 
689
 
690
/**
690
/**
691
  * @brief  Writes a Words data buffer to SRAM memory using DMA transfer.
691
  * @brief  Writes a Words data buffer to SRAM memory using DMA transfer.
692
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
692
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
693
  *                the configuration information for SRAM module.
693
  *                the configuration information for SRAM module.
694
  * @param  pAddress Pointer to write start address
694
  * @param  pAddress Pointer to write start address
695
  * @param  pSrcBuffer Pointer to source buffer to write
695
  * @param  pSrcBuffer Pointer to source buffer to write
696
  * @param  BufferSize Size of the buffer to write to memory
696
  * @param  BufferSize Size of the buffer to write to memory
697
  * @retval HAL status
697
  * @retval HAL status
698
  */
698
  */
699
HAL_StatusTypeDef HAL_SRAM_Write_DMA(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pSrcBuffer,
699
HAL_StatusTypeDef HAL_SRAM_Write_DMA(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pSrcBuffer,
700
                                     uint32_t BufferSize)
700
                                     uint32_t BufferSize)
701
{
701
{
702
  HAL_StatusTypeDef status;
702
  HAL_StatusTypeDef status;
703
 
703
 
704
  /* Check the SRAM controller state */
704
  /* Check the SRAM controller state */
705
  if (hsram->State == HAL_SRAM_STATE_READY)
705
  if (hsram->State == HAL_SRAM_STATE_READY)
706
  {
706
  {
707
    /* Process Locked */
707
    /* Process Locked */
708
    __HAL_LOCK(hsram);
708
    __HAL_LOCK(hsram);
709
 
709
 
710
    /* Update the SRAM controller state */
710
    /* Update the SRAM controller state */
711
    hsram->State = HAL_SRAM_STATE_BUSY;
711
    hsram->State = HAL_SRAM_STATE_BUSY;
712
 
712
 
713
    /* Configure DMA user callbacks */
713
    /* Configure DMA user callbacks */
714
    hsram->hdma->XferCpltCallback = SRAM_DMACplt;
714
    hsram->hdma->XferCpltCallback = SRAM_DMACplt;
715
    hsram->hdma->XferErrorCallback = SRAM_DMAError;
715
    hsram->hdma->XferErrorCallback = SRAM_DMAError;
716
 
716
 
717
    /* Enable the DMA Stream */
717
    /* Enable the DMA Stream */
718
    status = HAL_DMA_Start_IT(hsram->hdma, (uint32_t)pSrcBuffer, (uint32_t)pAddress, (uint32_t)BufferSize);
718
    status = HAL_DMA_Start_IT(hsram->hdma, (uint32_t)pSrcBuffer, (uint32_t)pAddress, (uint32_t)BufferSize);
719
 
719
 
720
    /* Process unlocked */
720
    /* Process unlocked */
721
    __HAL_UNLOCK(hsram);
721
    __HAL_UNLOCK(hsram);
722
  }
722
  }
723
  else
723
  else
724
  {
724
  {
725
    status = HAL_ERROR;
725
    status = HAL_ERROR;
726
  }
726
  }
727
 
727
 
728
  return status;
728
  return status;
729
}
729
}
730
 
730
 
731
#if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
731
#if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
732
/**
732
/**
733
  * @brief  Register a User SRAM Callback
733
  * @brief  Register a User SRAM Callback
734
  *         To be used instead of the weak (surcharged) predefined callback
734
  *         To be used instead of the weak (surcharged) predefined callback
735
  * @param hsram : SRAM handle
735
  * @param hsram : SRAM handle
736
  * @param CallbackId : ID of the callback to be registered
736
  * @param CallbackId : ID of the callback to be registered
737
  *        This parameter can be one of the following values:
737
  *        This parameter can be one of the following values:
738
  *          @arg @ref HAL_SRAM_MSP_INIT_CB_ID       SRAM MspInit callback ID
738
  *          @arg @ref HAL_SRAM_MSP_INIT_CB_ID       SRAM MspInit callback ID
739
  *          @arg @ref HAL_SRAM_MSP_DEINIT_CB_ID     SRAM MspDeInit callback ID
739
  *          @arg @ref HAL_SRAM_MSP_DEINIT_CB_ID     SRAM MspDeInit callback ID
740
  * @param pCallback : pointer to the Callback function
740
  * @param pCallback : pointer to the Callback function
741
  * @retval status
741
  * @retval status
742
  */
742
  */
743
HAL_StatusTypeDef HAL_SRAM_RegisterCallback(SRAM_HandleTypeDef *hsram, HAL_SRAM_CallbackIDTypeDef CallbackId,
743
HAL_StatusTypeDef HAL_SRAM_RegisterCallback(SRAM_HandleTypeDef *hsram, HAL_SRAM_CallbackIDTypeDef CallbackId,
744
                                            pSRAM_CallbackTypeDef pCallback)
744
                                            pSRAM_CallbackTypeDef pCallback)
745
{
745
{
746
  HAL_StatusTypeDef status = HAL_OK;
746
  HAL_StatusTypeDef status = HAL_OK;
747
  HAL_SRAM_StateTypeDef state;
747
  HAL_SRAM_StateTypeDef state;
748
 
748
 
749
  if (pCallback == NULL)
749
  if (pCallback == NULL)
750
  {
750
  {
751
    return HAL_ERROR;
751
    return HAL_ERROR;
752
  }
752
  }
753
 
753
 
754
  /* Process locked */
754
  /* Process locked */
755
  __HAL_LOCK(hsram);
755
  __HAL_LOCK(hsram);
756
 
756
 
757
  state = hsram->State;
757
  state = hsram->State;
758
  if ((state == HAL_SRAM_STATE_READY) || (state == HAL_SRAM_STATE_RESET) || (state == HAL_SRAM_STATE_PROTECTED))
758
  if ((state == HAL_SRAM_STATE_READY) || (state == HAL_SRAM_STATE_RESET) || (state == HAL_SRAM_STATE_PROTECTED))
759
  {
759
  {
760
    switch (CallbackId)
760
    switch (CallbackId)
761
    {
761
    {
762
      case HAL_SRAM_MSP_INIT_CB_ID :
762
      case HAL_SRAM_MSP_INIT_CB_ID :
763
        hsram->MspInitCallback = pCallback;
763
        hsram->MspInitCallback = pCallback;
764
        break;
764
        break;
765
      case HAL_SRAM_MSP_DEINIT_CB_ID :
765
      case HAL_SRAM_MSP_DEINIT_CB_ID :
766
        hsram->MspDeInitCallback = pCallback;
766
        hsram->MspDeInitCallback = pCallback;
767
        break;
767
        break;
768
      default :
768
      default :
769
        /* update return status */
769
        /* update return status */
770
        status =  HAL_ERROR;
770
        status =  HAL_ERROR;
771
        break;
771
        break;
772
    }
772
    }
773
  }
773
  }
774
  else
774
  else
775
  {
775
  {
776
    /* update return status */
776
    /* update return status */
777
    status =  HAL_ERROR;
777
    status =  HAL_ERROR;
778
  }
778
  }
779
 
779
 
780
  /* Release Lock */
780
  /* Release Lock */
781
  __HAL_UNLOCK(hsram);
781
  __HAL_UNLOCK(hsram);
782
  return status;
782
  return status;
783
}
783
}
784
 
784
 
785
/**
785
/**
786
  * @brief  Unregister a User SRAM Callback
786
  * @brief  Unregister a User SRAM Callback
787
  *         SRAM Callback is redirected to the weak (surcharged) predefined callback
787
  *         SRAM Callback is redirected to the weak (surcharged) predefined callback
788
  * @param hsram : SRAM handle
788
  * @param hsram : SRAM handle
789
  * @param CallbackId : ID of the callback to be unregistered
789
  * @param CallbackId : ID of the callback to be unregistered
790
  *        This parameter can be one of the following values:
790
  *        This parameter can be one of the following values:
791
  *          @arg @ref HAL_SRAM_MSP_INIT_CB_ID       SRAM MspInit callback ID
791
  *          @arg @ref HAL_SRAM_MSP_INIT_CB_ID       SRAM MspInit callback ID
792
  *          @arg @ref HAL_SRAM_MSP_DEINIT_CB_ID     SRAM MspDeInit callback ID
792
  *          @arg @ref HAL_SRAM_MSP_DEINIT_CB_ID     SRAM MspDeInit callback ID
793
  *          @arg @ref HAL_SRAM_DMA_XFER_CPLT_CB_ID  SRAM DMA Xfer Complete callback ID
793
  *          @arg @ref HAL_SRAM_DMA_XFER_CPLT_CB_ID  SRAM DMA Xfer Complete callback ID
794
  *          @arg @ref HAL_SRAM_DMA_XFER_ERR_CB_ID   SRAM DMA Xfer Error callback ID
794
  *          @arg @ref HAL_SRAM_DMA_XFER_ERR_CB_ID   SRAM DMA Xfer Error callback ID
795
  * @retval status
795
  * @retval status
796
  */
796
  */
797
HAL_StatusTypeDef HAL_SRAM_UnRegisterCallback(SRAM_HandleTypeDef *hsram, HAL_SRAM_CallbackIDTypeDef CallbackId)
797
HAL_StatusTypeDef HAL_SRAM_UnRegisterCallback(SRAM_HandleTypeDef *hsram, HAL_SRAM_CallbackIDTypeDef CallbackId)
798
{
798
{
799
  HAL_StatusTypeDef status = HAL_OK;
799
  HAL_StatusTypeDef status = HAL_OK;
800
  HAL_SRAM_StateTypeDef state;
800
  HAL_SRAM_StateTypeDef state;
801
 
801
 
802
  /* Process locked */
802
  /* Process locked */
803
  __HAL_LOCK(hsram);
803
  __HAL_LOCK(hsram);
804
 
804
 
805
  state = hsram->State;
805
  state = hsram->State;
806
  if ((state == HAL_SRAM_STATE_READY) || (state == HAL_SRAM_STATE_PROTECTED))
806
  if ((state == HAL_SRAM_STATE_READY) || (state == HAL_SRAM_STATE_PROTECTED))
807
  {
807
  {
808
    switch (CallbackId)
808
    switch (CallbackId)
809
    {
809
    {
810
      case HAL_SRAM_MSP_INIT_CB_ID :
810
      case HAL_SRAM_MSP_INIT_CB_ID :
811
        hsram->MspInitCallback = HAL_SRAM_MspInit;
811
        hsram->MspInitCallback = HAL_SRAM_MspInit;
812
        break;
812
        break;
813
      case HAL_SRAM_MSP_DEINIT_CB_ID :
813
      case HAL_SRAM_MSP_DEINIT_CB_ID :
814
        hsram->MspDeInitCallback = HAL_SRAM_MspDeInit;
814
        hsram->MspDeInitCallback = HAL_SRAM_MspDeInit;
815
        break;
815
        break;
816
      case HAL_SRAM_DMA_XFER_CPLT_CB_ID :
816
      case HAL_SRAM_DMA_XFER_CPLT_CB_ID :
817
        hsram->DmaXferCpltCallback = HAL_SRAM_DMA_XferCpltCallback;
817
        hsram->DmaXferCpltCallback = HAL_SRAM_DMA_XferCpltCallback;
818
        break;
818
        break;
819
      case HAL_SRAM_DMA_XFER_ERR_CB_ID :
819
      case HAL_SRAM_DMA_XFER_ERR_CB_ID :
820
        hsram->DmaXferErrorCallback = HAL_SRAM_DMA_XferErrorCallback;
820
        hsram->DmaXferErrorCallback = HAL_SRAM_DMA_XferErrorCallback;
821
        break;
821
        break;
822
      default :
822
      default :
823
        /* update return status */
823
        /* update return status */
824
        status =  HAL_ERROR;
824
        status =  HAL_ERROR;
825
        break;
825
        break;
826
    }
826
    }
827
  }
827
  }
828
  else if (state == HAL_SRAM_STATE_RESET)
828
  else if (state == HAL_SRAM_STATE_RESET)
829
  {
829
  {
830
    switch (CallbackId)
830
    switch (CallbackId)
831
    {
831
    {
832
      case HAL_SRAM_MSP_INIT_CB_ID :
832
      case HAL_SRAM_MSP_INIT_CB_ID :
833
        hsram->MspInitCallback = HAL_SRAM_MspInit;
833
        hsram->MspInitCallback = HAL_SRAM_MspInit;
834
        break;
834
        break;
835
      case HAL_SRAM_MSP_DEINIT_CB_ID :
835
      case HAL_SRAM_MSP_DEINIT_CB_ID :
836
        hsram->MspDeInitCallback = HAL_SRAM_MspDeInit;
836
        hsram->MspDeInitCallback = HAL_SRAM_MspDeInit;
837
        break;
837
        break;
838
      default :
838
      default :
839
        /* update return status */
839
        /* update return status */
840
        status =  HAL_ERROR;
840
        status =  HAL_ERROR;
841
        break;
841
        break;
842
    }
842
    }
843
  }
843
  }
844
  else
844
  else
845
  {
845
  {
846
    /* update return status */
846
    /* update return status */
847
    status =  HAL_ERROR;
847
    status =  HAL_ERROR;
848
  }
848
  }
849
 
849
 
850
  /* Release Lock */
850
  /* Release Lock */
851
  __HAL_UNLOCK(hsram);
851
  __HAL_UNLOCK(hsram);
852
  return status;
852
  return status;
853
}
853
}
854
 
854
 
855
/**
855
/**
856
  * @brief  Register a User SRAM Callback for DMA transfers
856
  * @brief  Register a User SRAM Callback for DMA transfers
857
  *         To be used instead of the weak (surcharged) predefined callback
857
  *         To be used instead of the weak (surcharged) predefined callback
858
  * @param hsram : SRAM handle
858
  * @param hsram : SRAM handle
859
  * @param CallbackId : ID of the callback to be registered
859
  * @param CallbackId : ID of the callback to be registered
860
  *        This parameter can be one of the following values:
860
  *        This parameter can be one of the following values:
861
  *          @arg @ref HAL_SRAM_DMA_XFER_CPLT_CB_ID  SRAM DMA Xfer Complete callback ID
861
  *          @arg @ref HAL_SRAM_DMA_XFER_CPLT_CB_ID  SRAM DMA Xfer Complete callback ID
862
  *          @arg @ref HAL_SRAM_DMA_XFER_ERR_CB_ID   SRAM DMA Xfer Error callback ID
862
  *          @arg @ref HAL_SRAM_DMA_XFER_ERR_CB_ID   SRAM DMA Xfer Error callback ID
863
  * @param pCallback : pointer to the Callback function
863
  * @param pCallback : pointer to the Callback function
864
  * @retval status
864
  * @retval status
865
  */
865
  */
866
HAL_StatusTypeDef HAL_SRAM_RegisterDmaCallback(SRAM_HandleTypeDef *hsram, HAL_SRAM_CallbackIDTypeDef CallbackId,
866
HAL_StatusTypeDef HAL_SRAM_RegisterDmaCallback(SRAM_HandleTypeDef *hsram, HAL_SRAM_CallbackIDTypeDef CallbackId,
867
                                               pSRAM_DmaCallbackTypeDef pCallback)
867
                                               pSRAM_DmaCallbackTypeDef pCallback)
868
{
868
{
869
  HAL_StatusTypeDef status = HAL_OK;
869
  HAL_StatusTypeDef status = HAL_OK;
870
  HAL_SRAM_StateTypeDef state;
870
  HAL_SRAM_StateTypeDef state;
871
 
871
 
872
  if (pCallback == NULL)
872
  if (pCallback == NULL)
873
  {
873
  {
874
    return HAL_ERROR;
874
    return HAL_ERROR;
875
  }
875
  }
876
 
876
 
877
  /* Process locked */
877
  /* Process locked */
878
  __HAL_LOCK(hsram);
878
  __HAL_LOCK(hsram);
879
 
879
 
880
  state = hsram->State;
880
  state = hsram->State;
881
  if ((state == HAL_SRAM_STATE_READY) || (state == HAL_SRAM_STATE_PROTECTED))
881
  if ((state == HAL_SRAM_STATE_READY) || (state == HAL_SRAM_STATE_PROTECTED))
882
  {
882
  {
883
    switch (CallbackId)
883
    switch (CallbackId)
884
    {
884
    {
885
      case HAL_SRAM_DMA_XFER_CPLT_CB_ID :
885
      case HAL_SRAM_DMA_XFER_CPLT_CB_ID :
886
        hsram->DmaXferCpltCallback = pCallback;
886
        hsram->DmaXferCpltCallback = pCallback;
887
        break;
887
        break;
888
      case HAL_SRAM_DMA_XFER_ERR_CB_ID :
888
      case HAL_SRAM_DMA_XFER_ERR_CB_ID :
889
        hsram->DmaXferErrorCallback = pCallback;
889
        hsram->DmaXferErrorCallback = pCallback;
890
        break;
890
        break;
891
      default :
891
      default :
892
        /* update return status */
892
        /* update return status */
893
        status =  HAL_ERROR;
893
        status =  HAL_ERROR;
894
        break;
894
        break;
895
    }
895
    }
896
  }
896
  }
897
  else
897
  else
898
  {
898
  {
899
    /* update return status */
899
    /* update return status */
900
    status =  HAL_ERROR;
900
    status =  HAL_ERROR;
901
  }
901
  }
902
 
902
 
903
  /* Release Lock */
903
  /* Release Lock */
904
  __HAL_UNLOCK(hsram);
904
  __HAL_UNLOCK(hsram);
905
  return status;
905
  return status;
906
}
906
}
907
#endif /* USE_HAL_SRAM_REGISTER_CALLBACKS */
907
#endif /* USE_HAL_SRAM_REGISTER_CALLBACKS */
908
 
908
 
909
/**
909
/**
910
  * @}
910
  * @}
911
  */
911
  */
912
 
912
 
913
/** @defgroup SRAM_Exported_Functions_Group3 Control functions
913
/** @defgroup SRAM_Exported_Functions_Group3 Control functions
914
  *  @brief   Control functions
914
  *  @brief   Control functions
915
  *
915
  *
916
@verbatim
916
@verbatim
917
  ==============================================================================
917
  ==============================================================================
918
                        ##### SRAM Control functions #####
918
                        ##### SRAM Control functions #####
919
  ==============================================================================
919
  ==============================================================================
920
  [..]
920
  [..]
921
    This subsection provides a set of functions allowing to control dynamically
921
    This subsection provides a set of functions allowing to control dynamically
922
    the SRAM interface.
922
    the SRAM interface.
923
 
923
 
924
@endverbatim
924
@endverbatim
925
  * @{
925
  * @{
926
  */
926
  */
927
 
927
 
928
/**
928
/**
929
  * @brief  Enables dynamically SRAM write operation.
929
  * @brief  Enables dynamically SRAM write operation.
930
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
930
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
931
  *                the configuration information for SRAM module.
931
  *                the configuration information for SRAM module.
932
  * @retval HAL status
932
  * @retval HAL status
933
  */
933
  */
934
HAL_StatusTypeDef HAL_SRAM_WriteOperation_Enable(SRAM_HandleTypeDef *hsram)
934
HAL_StatusTypeDef HAL_SRAM_WriteOperation_Enable(SRAM_HandleTypeDef *hsram)
935
{
935
{
936
  /* Check the SRAM controller state */
936
  /* Check the SRAM controller state */
937
  if (hsram->State == HAL_SRAM_STATE_PROTECTED)
937
  if (hsram->State == HAL_SRAM_STATE_PROTECTED)
938
  {
938
  {
939
    /* Process Locked */
939
    /* Process Locked */
940
    __HAL_LOCK(hsram);
940
    __HAL_LOCK(hsram);
941
 
941
 
942
    /* Update the SRAM controller state */
942
    /* Update the SRAM controller state */
943
    hsram->State = HAL_SRAM_STATE_BUSY;
943
    hsram->State = HAL_SRAM_STATE_BUSY;
944
 
944
 
945
    /* Enable write operation */
945
    /* Enable write operation */
946
    (void)FSMC_NORSRAM_WriteOperation_Enable(hsram->Instance, hsram->Init.NSBank);
946
    (void)FSMC_NORSRAM_WriteOperation_Enable(hsram->Instance, hsram->Init.NSBank);
947
 
947
 
948
    /* Update the SRAM controller state */
948
    /* Update the SRAM controller state */
949
    hsram->State = HAL_SRAM_STATE_READY;
949
    hsram->State = HAL_SRAM_STATE_READY;
950
 
950
 
951
    /* Process unlocked */
951
    /* Process unlocked */
952
    __HAL_UNLOCK(hsram);
952
    __HAL_UNLOCK(hsram);
953
  }
953
  }
954
  else
954
  else
955
  {
955
  {
956
    return HAL_ERROR;
956
    return HAL_ERROR;
957
  }
957
  }
958
 
958
 
959
  return HAL_OK;
959
  return HAL_OK;
960
}
960
}
961
 
961
 
962
/**
962
/**
963
  * @brief  Disables dynamically SRAM write operation.
963
  * @brief  Disables dynamically SRAM write operation.
964
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
964
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
965
  *                the configuration information for SRAM module.
965
  *                the configuration information for SRAM module.
966
  * @retval HAL status
966
  * @retval HAL status
967
  */
967
  */
968
HAL_StatusTypeDef HAL_SRAM_WriteOperation_Disable(SRAM_HandleTypeDef *hsram)
968
HAL_StatusTypeDef HAL_SRAM_WriteOperation_Disable(SRAM_HandleTypeDef *hsram)
969
{
969
{
970
  /* Check the SRAM controller state */
970
  /* Check the SRAM controller state */
971
  if (hsram->State == HAL_SRAM_STATE_READY)
971
  if (hsram->State == HAL_SRAM_STATE_READY)
972
  {
972
  {
973
    /* Process Locked */
973
    /* Process Locked */
974
    __HAL_LOCK(hsram);
974
    __HAL_LOCK(hsram);
975
 
975
 
976
    /* Update the SRAM controller state */
976
    /* Update the SRAM controller state */
977
    hsram->State = HAL_SRAM_STATE_BUSY;
977
    hsram->State = HAL_SRAM_STATE_BUSY;
978
 
978
 
979
    /* Disable write operation */
979
    /* Disable write operation */
980
    (void)FSMC_NORSRAM_WriteOperation_Disable(hsram->Instance, hsram->Init.NSBank);
980
    (void)FSMC_NORSRAM_WriteOperation_Disable(hsram->Instance, hsram->Init.NSBank);
981
 
981
 
982
    /* Update the SRAM controller state */
982
    /* Update the SRAM controller state */
983
    hsram->State = HAL_SRAM_STATE_PROTECTED;
983
    hsram->State = HAL_SRAM_STATE_PROTECTED;
984
 
984
 
985
    /* Process unlocked */
985
    /* Process unlocked */
986
    __HAL_UNLOCK(hsram);
986
    __HAL_UNLOCK(hsram);
987
  }
987
  }
988
  else
988
  else
989
  {
989
  {
990
    return HAL_ERROR;
990
    return HAL_ERROR;
991
  }
991
  }
992
 
992
 
993
  return HAL_OK;
993
  return HAL_OK;
994
}
994
}
995
 
995
 
996
/**
996
/**
997
  * @}
997
  * @}
998
  */
998
  */
999
 
999
 
1000
/** @defgroup SRAM_Exported_Functions_Group4 Peripheral State functions
1000
/** @defgroup SRAM_Exported_Functions_Group4 Peripheral State functions
1001
  *  @brief   Peripheral State functions
1001
  *  @brief   Peripheral State functions
1002
  *
1002
  *
1003
@verbatim
1003
@verbatim
1004
  ==============================================================================
1004
  ==============================================================================
1005
                      ##### SRAM State functions #####
1005
                      ##### SRAM State functions #####
1006
  ==============================================================================
1006
  ==============================================================================
1007
  [..]
1007
  [..]
1008
    This subsection permits to get in run-time the status of the SRAM controller
1008
    This subsection permits to get in run-time the status of the SRAM controller
1009
    and the data flow.
1009
    and the data flow.
1010
 
1010
 
1011
@endverbatim
1011
@endverbatim
1012
  * @{
1012
  * @{
1013
  */
1013
  */
1014
 
1014
 
1015
/**
1015
/**
1016
  * @brief  Returns the SRAM controller state
1016
  * @brief  Returns the SRAM controller state
1017
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
1017
  * @param  hsram pointer to a SRAM_HandleTypeDef structure that contains
1018
  *                the configuration information for SRAM module.
1018
  *                the configuration information for SRAM module.
1019
  * @retval HAL state
1019
  * @retval HAL state
1020
  */
1020
  */
1021
HAL_SRAM_StateTypeDef HAL_SRAM_GetState(SRAM_HandleTypeDef *hsram)
1021
HAL_SRAM_StateTypeDef HAL_SRAM_GetState(SRAM_HandleTypeDef *hsram)
1022
{
1022
{
1023
  return hsram->State;
1023
  return hsram->State;
1024
}
1024
}
1025
 
1025
 
1026
/**
1026
/**
1027
  * @}
1027
  * @}
1028
  */
1028
  */
1029
 
1029
 
1030
/**
1030
/**
1031
  * @}
1031
  * @}
1032
  */
1032
  */
1033
 
1033
 
1034
/**
1034
/**
1035
  * @brief  DMA SRAM process complete callback.
1035
  * @brief  DMA SRAM process complete callback.
1036
  * @param  hdma : DMA handle
1036
  * @param  hdma : DMA handle
1037
  * @retval None
1037
  * @retval None
1038
  */
1038
  */
1039
static void SRAM_DMACplt(DMA_HandleTypeDef *hdma)
1039
static void SRAM_DMACplt(DMA_HandleTypeDef *hdma)
1040
{
1040
{
1041
  SRAM_HandleTypeDef *hsram = (SRAM_HandleTypeDef *)(hdma->Parent);
1041
  SRAM_HandleTypeDef *hsram = (SRAM_HandleTypeDef *)(hdma->Parent);
1042
 
1042
 
1043
  /* Disable the DMA channel */
1043
  /* Disable the DMA channel */
1044
  __HAL_DMA_DISABLE(hdma);
1044
  __HAL_DMA_DISABLE(hdma);
1045
 
1045
 
1046
  /* Update the SRAM controller state */
1046
  /* Update the SRAM controller state */
1047
  hsram->State = HAL_SRAM_STATE_READY;
1047
  hsram->State = HAL_SRAM_STATE_READY;
1048
 
1048
 
1049
#if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
1049
#if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
1050
  hsram->DmaXferCpltCallback(hdma);
1050
  hsram->DmaXferCpltCallback(hdma);
1051
#else
1051
#else
1052
  HAL_SRAM_DMA_XferCpltCallback(hdma);
1052
  HAL_SRAM_DMA_XferCpltCallback(hdma);
1053
#endif /* USE_HAL_SRAM_REGISTER_CALLBACKS */
1053
#endif /* USE_HAL_SRAM_REGISTER_CALLBACKS */
1054
}
1054
}
1055
 
1055
 
1056
/**
1056
/**
1057
  * @brief  DMA SRAM process complete callback.
1057
  * @brief  DMA SRAM process complete callback.
1058
  * @param  hdma : DMA handle
1058
  * @param  hdma : DMA handle
1059
  * @retval None
1059
  * @retval None
1060
  */
1060
  */
1061
static void SRAM_DMACpltProt(DMA_HandleTypeDef *hdma)
1061
static void SRAM_DMACpltProt(DMA_HandleTypeDef *hdma)
1062
{
1062
{
1063
  SRAM_HandleTypeDef *hsram = (SRAM_HandleTypeDef *)(hdma->Parent);
1063
  SRAM_HandleTypeDef *hsram = (SRAM_HandleTypeDef *)(hdma->Parent);
1064
 
1064
 
1065
  /* Disable the DMA channel */
1065
  /* Disable the DMA channel */
1066
  __HAL_DMA_DISABLE(hdma);
1066
  __HAL_DMA_DISABLE(hdma);
1067
 
1067
 
1068
  /* Update the SRAM controller state */
1068
  /* Update the SRAM controller state */
1069
  hsram->State = HAL_SRAM_STATE_PROTECTED;
1069
  hsram->State = HAL_SRAM_STATE_PROTECTED;
1070
 
1070
 
1071
#if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
1071
#if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
1072
  hsram->DmaXferCpltCallback(hdma);
1072
  hsram->DmaXferCpltCallback(hdma);
1073
#else
1073
#else
1074
  HAL_SRAM_DMA_XferCpltCallback(hdma);
1074
  HAL_SRAM_DMA_XferCpltCallback(hdma);
1075
#endif /* USE_HAL_SRAM_REGISTER_CALLBACKS */
1075
#endif /* USE_HAL_SRAM_REGISTER_CALLBACKS */
1076
}
1076
}
1077
 
1077
 
1078
/**
1078
/**
1079
  * @brief  DMA SRAM error callback.
1079
  * @brief  DMA SRAM error callback.
1080
  * @param  hdma : DMA handle
1080
  * @param  hdma : DMA handle
1081
  * @retval None
1081
  * @retval None
1082
  */
1082
  */
1083
static void SRAM_DMAError(DMA_HandleTypeDef *hdma)
1083
static void SRAM_DMAError(DMA_HandleTypeDef *hdma)
1084
{
1084
{
1085
  SRAM_HandleTypeDef *hsram = (SRAM_HandleTypeDef *)(hdma->Parent);
1085
  SRAM_HandleTypeDef *hsram = (SRAM_HandleTypeDef *)(hdma->Parent);
1086
 
1086
 
1087
  /* Disable the DMA channel */
1087
  /* Disable the DMA channel */
1088
  __HAL_DMA_DISABLE(hdma);
1088
  __HAL_DMA_DISABLE(hdma);
1089
 
1089
 
1090
  /* Update the SRAM controller state */
1090
  /* Update the SRAM controller state */
1091
  hsram->State = HAL_SRAM_STATE_ERROR;
1091
  hsram->State = HAL_SRAM_STATE_ERROR;
1092
 
1092
 
1093
#if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
1093
#if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1)
1094
  hsram->DmaXferErrorCallback(hdma);
1094
  hsram->DmaXferErrorCallback(hdma);
1095
#else
1095
#else
1096
  HAL_SRAM_DMA_XferErrorCallback(hdma);
1096
  HAL_SRAM_DMA_XferErrorCallback(hdma);
1097
#endif /* USE_HAL_SRAM_REGISTER_CALLBACKS */
1097
#endif /* USE_HAL_SRAM_REGISTER_CALLBACKS */
1098
}
1098
}
1099
 
1099
 
1100
/**
1100
/**
1101
  * @}
1101
  * @}
1102
  */
1102
  */
1103
 
1103
 
1104
#endif /* HAL_SRAM_MODULE_ENABLED */
1104
#endif /* HAL_SRAM_MODULE_ENABLED */
1105
 
1105
 
1106
/**
1106
/**
1107
  * @}
1107
  * @}
1108
  */
1108
  */
1109
 
1109
 
1110
#endif /* FSMC_BANK1 */
1110
#endif /* FSMC_BANK1 */
1111
 
-
 
1112
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-