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