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