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_nor.c |
3 | * @file stm32f1xx_hal_nor.c |
| 4 | * @author MCD Application Team |
4 | * @author MCD Application Team |
| 5 | * @brief NOR HAL module driver. |
5 | * @brief NOR HAL module driver. |
| 6 | * This file provides a generic firmware to drive NOR memories mounted |
6 | * This file provides a generic firmware to drive NOR memories mounted |
| 7 | * as external device. |
7 | * 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 NOR flash memories. It uses the FSMC layer functions to interface |
15 | control NOR flash memories. It uses the FSMC layer functions to interface |
| 16 | with NOR devices. This driver is used as follows: |
16 | with NOR devices. This driver is used as follows: |
| 17 | |
17 | |
| 18 | (+) NOR flash memory configuration sequence using the function HAL_NOR_Init() |
18 | (+) NOR flash memory configuration sequence using the function HAL_NOR_Init() |
| 19 | with control and timing parameters for both normal and extended mode. |
19 | with control and timing parameters for both normal and extended mode. |
| 20 | |
20 | |
| 21 | (+) Read NOR flash memory manufacturer code and device IDs using the function |
21 | (+) Read NOR flash memory manufacturer code and device IDs using the function |
| 22 | HAL_NOR_Read_ID(). The read information is stored in the NOR_ID_TypeDef |
22 | HAL_NOR_Read_ID(). The read information is stored in the NOR_ID_TypeDef |
| 23 | structure declared by the function caller. |
23 | structure declared by the function caller. |
| 24 | |
24 | |
| 25 | (+) Access NOR flash memory by read/write data unit operations using the functions |
25 | (+) Access NOR flash memory by read/write data unit operations using the functions |
| 26 | HAL_NOR_Read(), HAL_NOR_Program(). |
26 | HAL_NOR_Read(), HAL_NOR_Program(). |
| 27 | |
27 | |
| 28 | (+) Perform NOR flash erase block/chip operations using the functions |
28 | (+) Perform NOR flash erase block/chip operations using the functions |
| 29 | HAL_NOR_Erase_Block() and HAL_NOR_Erase_Chip(). |
29 | HAL_NOR_Erase_Block() and HAL_NOR_Erase_Chip(). |
| 30 | |
30 | |
| 31 | (+) Read the NOR flash CFI (common flash interface) IDs using the function |
31 | (+) Read the NOR flash CFI (common flash interface) IDs using the function |
| 32 | HAL_NOR_Read_CFI(). The read information is stored in the NOR_CFI_TypeDef |
32 | HAL_NOR_Read_CFI(). The read information is stored in the NOR_CFI_TypeDef |
| 33 | structure declared by the function caller. |
33 | structure declared by the function caller. |
| 34 | |
34 | |
| 35 | (+) You can also control the NOR device by calling the control APIs HAL_NOR_WriteOperation_Enable()/ |
35 | (+) You can also control the NOR device by calling the control APIs HAL_NOR_WriteOperation_Enable()/ |
| 36 | HAL_NOR_WriteOperation_Disable() to respectively enable/disable the NOR write operation |
36 | HAL_NOR_WriteOperation_Disable() to respectively enable/disable the NOR write operation |
| 37 | |
37 | |
| 38 | (+) You can monitor the NOR device HAL state by calling the function |
38 | (+) You can monitor the NOR device HAL state by calling the function |
| 39 | HAL_NOR_GetState() |
39 | HAL_NOR_GetState() |
| 40 | [..] |
40 | [..] |
| 41 | (@) This driver is a set of generic APIs which handle standard NOR flash operations. |
41 | (@) This driver is a set of generic APIs which handle standard NOR flash operations. |
| 42 | If a NOR flash device contains different operations and/or implementations, |
42 | If a NOR flash device contains different operations and/or implementations, |
| 43 | it should be implemented separately. |
43 | it should be implemented separately. |
| 44 | 44 | ||
| 45 | *** NOR HAL driver macros list *** |
45 | *** NOR HAL driver macros list *** |
| 46 | ============================================= |
46 | ============================================= |
| 47 | [..] |
47 | [..] |
| 48 | Below the list of most used macros in NOR HAL driver. |
48 | Below the list of most used macros in NOR HAL driver. |
| 49 | |
49 | |
| 50 | (+) NOR_WRITE : NOR memory write data to specified address |
50 | (+) NOR_WRITE : NOR memory write data to specified address |
| 51 | 51 | ||
| - | 52 | *** Callback registration *** |
|
| - | 53 | ============================================= |
|
| - | 54 | [..] |
|
| - | 55 | The compilation define USE_HAL_NOR_REGISTER_CALLBACKS when set to 1 |
|
| - | 56 | allows the user to configure dynamically the driver callbacks. |
|
| - | 57 | ||
| - | 58 | Use Functions @ref HAL_NOR_RegisterCallback() to register a user callback, |
|
| - | 59 | it allows to register following callbacks: |
|
| - | 60 | (+) MspInitCallback : NOR MspInit. |
|
| - | 61 | (+) MspDeInitCallback : NOR MspDeInit. |
|
| - | 62 | This function takes as parameters the HAL peripheral handle, the Callback ID |
|
| - | 63 | and a pointer to the user callback function. |
|
| - | 64 | ||
| - | 65 | Use function @ref HAL_NOR_UnRegisterCallback() to reset a callback to the default |
|
| - | 66 | weak (surcharged) function. It allows to reset following callbacks: |
|
| - | 67 | (+) MspInitCallback : NOR MspInit. |
|
| - | 68 | (+) MspDeInitCallback : NOR MspDeInit. |
|
| - | 69 | This function) takes as parameters the HAL peripheral handle and the Callback ID. |
|
| - | 70 | ||
| - | 71 | By default, after the @ref HAL_NOR_Init and if the state is HAL_NOR_STATE_RESET |
|
| - | 72 | all callbacks are reset to the corresponding legacy weak (surcharged) functions. |
|
| - | 73 | Exception done for MspInit and MspDeInit callbacks that are respectively |
|
| - | 74 | reset to the legacy weak (surcharged) functions in the @ref HAL_NOR_Init |
|
| - | 75 | and @ref HAL_NOR_DeInit only when these callbacks are null (not registered beforehand). |
|
| - | 76 | If not, MspInit or MspDeInit are not null, the @ref HAL_NOR_Init and @ref HAL_NOR_DeInit |
|
| - | 77 | keep and use the user MspInit/MspDeInit callbacks (registered beforehand) |
|
| - | 78 | ||
| - | 79 | Callbacks can be registered/unregistered in READY state only. |
|
| - | 80 | Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered |
|
| - | 81 | in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used |
|
| - | 82 | during the Init/DeInit. |
|
| - | 83 | In that case first register the MspInit/MspDeInit user callbacks |
|
| - | 84 | using @ref HAL_NOR_RegisterCallback before calling @ref HAL_NOR_DeInit |
|
| - | 85 | or @ref HAL_NOR_Init function. |
|
| - | 86 | ||
| - | 87 | When The compilation define USE_HAL_NOR_REGISTER_CALLBACKS is set to 0 or |
|
| - | 88 | not defined, the callback registering feature is not available |
|
| - | 89 | and weak (surcharged) callbacks are used. |
|
| - | 90 | ||
| 52 | @endverbatim |
91 | @endverbatim |
| 53 | ****************************************************************************** |
92 | ****************************************************************************** |
| 54 | * @attention |
93 | * @attention |
| 55 | * |
94 | * |
| 56 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
95 | * <h2><center>© Copyright (c) 2016 STMicroelectronics. |
| 57 | * |
- | |
| 58 | * Redistribution and use in source and binary forms, with or without modification, |
- | |
| 59 | * are permitted provided that the following conditions are met: |
- | |
| 60 | * 1. Redistributions of source code must retain the above copyright notice, |
- | |
| 61 | * this list of conditions and the following disclaimer. |
- | |
| 62 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
- | |
| 63 | * this list of conditions and the following disclaimer in the documentation |
- | |
| 64 | * and/or other materials provided with the distribution. |
- | |
| 65 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
- | |
| 66 | * may be used to endorse or promote products derived from this software |
- | |
| 67 | * without specific prior written permission. |
96 | * All rights reserved.</center></h2> |
| 68 | * |
97 | * |
| 69 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
98 | * This software component is licensed by ST under BSD 3-Clause license, |
| 70 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
- | |
| 71 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
- | |
| 72 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
- | |
| 73 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
- | |
| 74 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
99 | * the "License"; You may not use this file except in compliance with the |
| 75 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
100 | * License. You may obtain a copy of the License at: |
| 76 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
- | |
| 77 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
- | |
| 78 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
101 | * opensource.org/licenses/BSD-3-Clause |
| 79 | * |
102 | * |
| 80 | ****************************************************************************** |
103 | ****************************************************************************** |
| 81 | */ |
104 | */ |
| 82 | 105 | ||
| 83 | /* Includes ------------------------------------------------------------------*/ |
106 | /* Includes ------------------------------------------------------------------*/ |
| 84 | #include "stm32f1xx_hal.h" |
107 | #include "stm32f1xx_hal.h" |
| 85 | 108 | ||
| - | 109 | #if defined FSMC_BANK1 |
|
| - | 110 | ||
| 86 | /** @addtogroup STM32F1xx_HAL_Driver |
111 | /** @addtogroup STM32F1xx_HAL_Driver |
| 87 | * @{ |
112 | * @{ |
| 88 | */ |
113 | */ |
| 89 | 114 | ||
| 90 | #ifdef HAL_NOR_MODULE_ENABLED |
115 | #ifdef HAL_NOR_MODULE_ENABLED |
| 91 | #if defined (STM32F101xE) || defined(STM32F103xE) || defined(STM32F101xG) || defined(STM32F103xG) || defined(STM32F100xE) |
- | |
| 92 | 116 | ||
| 93 | /** @defgroup NOR NOR |
117 | /** @defgroup NOR NOR |
| 94 | * @brief NOR driver modules |
118 | * @brief NOR driver modules |
| 95 | * @{ |
119 | * @{ |
| 96 | */ |
120 | */ |
| - | 121 | ||
| 97 | /* Private typedef -----------------------------------------------------------*/ |
122 | /* Private typedef -----------------------------------------------------------*/ |
| 98 | /* Private define ------------------------------------------------------------*/ |
123 | /* Private define ------------------------------------------------------------*/ |
| - | 124 | ||
| 99 | /** @defgroup NOR_Private_Constants NOR Private Constants |
125 | /** @defgroup NOR_Private_Defines NOR Private Defines |
| 100 | * @{ |
126 | * @{ |
| 101 | */ |
127 | */ |
| 102 | 128 | ||
| 103 | /* Constants to define address to set to write a command */ |
129 | /* Constants to define address to set to write a command */ |
| 104 | #define NOR_CMD_ADDRESS_FIRST (uint16_t)0x0555 |
130 | #define NOR_CMD_ADDRESS_FIRST (uint16_t)0x0555 |
| Line 123... | Line 149... | ||
| 123 | 149 | ||
| 124 | #define NOR_CMD_DATA_BUFFER_AND_PROG (uint8_t)0x25 |
150 | #define NOR_CMD_DATA_BUFFER_AND_PROG (uint8_t)0x25 |
| 125 | #define NOR_CMD_DATA_BUFFER_AND_PROG_CONFIRM (uint8_t)0x29 |
151 | #define NOR_CMD_DATA_BUFFER_AND_PROG_CONFIRM (uint8_t)0x29 |
| 126 | #define NOR_CMD_DATA_BLOCK_ERASE (uint8_t)0x30 |
152 | #define NOR_CMD_DATA_BLOCK_ERASE (uint8_t)0x30 |
| 127 | 153 | ||
| - | 154 | #define NOR_CMD_READ_ARRAY (uint16_t)0x00FF |
|
| - | 155 | #define NOR_CMD_WORD_PROGRAM (uint16_t)0x0040 |
|
| - | 156 | #define NOR_CMD_BUFFERED_PROGRAM (uint16_t)0x00E8 |
|
| - | 157 | #define NOR_CMD_CONFIRM (uint16_t)0x00D0 |
|
| - | 158 | #define NOR_CMD_BLOCK_ERASE (uint16_t)0x0020 |
|
| - | 159 | #define NOR_CMD_BLOCK_UNLOCK (uint16_t)0x0060 |
|
| - | 160 | #define NOR_CMD_READ_STATUS_REG (uint16_t)0x0070 |
|
| - | 161 | #define NOR_CMD_CLEAR_STATUS_REG (uint16_t)0x0050 |
|
| - | 162 | ||
| 128 | /* Mask on NOR STATUS REGISTER */ |
163 | /* Mask on NOR STATUS REGISTER */ |
| - | 164 | #define NOR_MASK_STATUS_DQ4 (uint16_t)0x0010 |
|
| 129 | #define NOR_MASK_STATUS_DQ5 (uint16_t)0x0020 |
165 | #define NOR_MASK_STATUS_DQ5 (uint16_t)0x0020 |
| 130 | #define NOR_MASK_STATUS_DQ6 (uint16_t)0x0040 |
166 | #define NOR_MASK_STATUS_DQ6 (uint16_t)0x0040 |
| - | 167 | #define NOR_MASK_STATUS_DQ7 (uint16_t)0x0080 |
|
| 131 | 168 | ||
| 132 | /** |
- | |
| 133 | * @} |
169 | /* Address of the primary command set */ |
| 134 | */ |
- | |
| - | 170 | #define NOR_ADDRESS_COMMAND_SET (uint16_t)0x0013 |
|
| 135 | 171 | ||
| 136 | /* Private macro -------------------------------------------------------------*/ |
172 | /* Command set code assignment (defined in JEDEC JEP137B version may 2004) */ |
| - | 173 | #define NOR_INTEL_SHARP_EXT_COMMAND_SET (uint16_t)0x0001 /* Supported in this driver */ |
|
| - | 174 | #define NOR_AMD_FUJITSU_COMMAND_SET (uint16_t)0x0002 /* Supported in this driver */ |
|
| - | 175 | #define NOR_INTEL_STANDARD_COMMAND_SET (uint16_t)0x0003 /* Not Supported in this driver */ |
|
| - | 176 | #define NOR_AMD_FUJITSU_EXT_COMMAND_SET (uint16_t)0x0004 /* Not Supported in this driver */ |
|
| 137 | /** @defgroup NOR_Private_Macros NOR Private Macros |
177 | #define NOR_WINDBOND_STANDARD_COMMAND_SET (uint16_t)0x0006 /* Not Supported in this driver */ |
| 138 | * @{ |
- | |
| 139 | */ |
- | |
| - | 178 | #define NOR_MITSUBISHI_STANDARD_COMMAND_SET (uint16_t)0x0100 /* Not Supported in this driver */ |
|
| - | 179 | #define NOR_MITSUBISHI_EXT_COMMAND_SET (uint16_t)0x0101 /* Not Supported in this driver */ |
|
| - | 180 | #define NOR_PAGE_WRITE_COMMAND_SET (uint16_t)0x0102 /* Not Supported in this driver */ |
|
| - | 181 | #define NOR_INTEL_PERFORMANCE_COMMAND_SET (uint16_t)0x0200 /* Not Supported in this driver */ |
|
| - | 182 | #define NOR_INTEL_DATA_COMMAND_SET (uint16_t)0x0210 /* Not Supported in this driver */ |
|
| 140 | 183 | ||
| 141 | /** |
184 | /** |
| 142 | * @} |
185 | * @} |
| 143 | */ |
186 | */ |
| 144 | 187 | ||
| - | 188 | /* Private macro -------------------------------------------------------------*/ |
|
| 145 | /* Private variables ---------------------------------------------------------*/ |
189 | /* Private variables ---------------------------------------------------------*/ |
| 146 | - | ||
| 147 | /** @defgroup NOR_Private_Variables NOR Private Variables |
190 | /** @defgroup NOR_Private_Variables NOR Private Variables |
| 148 | * @{ |
191 | * @{ |
| 149 | */ |
192 | */ |
| 150 | 193 | ||
| 151 | static uint32_t uwNORMemoryDataWidth = NOR_MEMORY_8B; |
194 | static uint32_t uwNORMemoryDataWidth = NOR_MEMORY_8B; |
| 152 | 195 | ||
| 153 | /** |
196 | /** |
| 154 | * @} |
197 | * @} |
| 155 | */ |
198 | */ |
| 156 | 199 | ||
| 157 | /* Private function prototypes -----------------------------------------------*/ |
- | |
| 158 | /* Private functions ---------------------------------------------------------*/ |
200 | /* Private functions ---------------------------------------------------------*/ |
| 159 | - | ||
| - | 201 | /* Exported functions --------------------------------------------------------*/ |
|
| 160 | /** @defgroup NOR_Exported_Functions NOR Exported Functions |
202 | /** @defgroup NOR_Exported_Functions NOR Exported Functions |
| 161 | * @{ |
203 | * @{ |
| 162 | */ |
204 | */ |
| 163 | 205 | ||
| 164 | /** @defgroup NOR_Exported_Functions_Group1 Initialization and de-initialization functions |
206 | /** @defgroup NOR_Exported_Functions_Group1 Initialization and de-initialization functions |
| 165 | * @brief Initialization and Configuration functions |
207 | * @brief Initialization and Configuration functions |
| 166 | * |
208 | * |
| 167 | @verbatim |
209 | @verbatim |
| 168 | ============================================================================== |
210 | ============================================================================== |
| 169 | ##### NOR Initialization and de_initialization functions ##### |
211 | ##### NOR Initialization and de_initialization functions ##### |
| 170 | ============================================================================== |
212 | ============================================================================== |
| 171 | [..] |
213 | [..] |
| 172 | This section provides functions allowing to initialize/de-initialize |
214 | This section provides functions allowing to initialize/de-initialize |
| 173 | the NOR memory |
215 | the NOR memory |
| 174 | |
216 | |
| 175 | @endverbatim |
217 | @endverbatim |
| 176 | * @{ |
218 | * @{ |
| 177 | */ |
219 | */ |
| 178 | 220 | ||
| 179 | /** |
221 | /** |
| 180 | * @brief Perform the NOR memory Initialization sequence |
222 | * @brief Perform the NOR memory Initialization sequence |
| 181 | * @param hnor: pointer to a NOR_HandleTypeDef structure that contains |
223 | * @param hnor pointer to a NOR_HandleTypeDef structure that contains |
| 182 | * the configuration information for NOR module. |
224 | * the configuration information for NOR module. |
| 183 | * @param Timing: pointer to NOR control timing structure |
225 | * @param Timing pointer to NOR control timing structure |
| 184 | * @param ExtTiming: pointer to NOR extended mode timing structure |
226 | * @param ExtTiming pointer to NOR extended mode timing structure |
| 185 | * @retval HAL status |
227 | * @retval HAL status |
| 186 | */ |
228 | */ |
| 187 | HAL_StatusTypeDef HAL_NOR_Init(NOR_HandleTypeDef *hnor, FSMC_NORSRAM_TimingTypeDef *Timing, FSMC_NORSRAM_TimingTypeDef *ExtTiming) |
229 | HAL_StatusTypeDef HAL_NOR_Init(NOR_HandleTypeDef *hnor, FSMC_NORSRAM_TimingTypeDef *Timing, |
| - | 230 | FSMC_NORSRAM_TimingTypeDef *ExtTiming) |
|
| 188 | { |
231 | { |
| - | 232 | uint32_t deviceaddress; |
|
| - | 233 | ||
| 189 | /* Check the NOR handle parameter */ |
234 | /* Check the NOR handle parameter */ |
| 190 | if(hnor == NULL) |
235 | if (hnor == NULL) |
| 191 | { |
236 | { |
| 192 | return HAL_ERROR; |
237 | return HAL_ERROR; |
| 193 | } |
238 | } |
| 194 | 239 | ||
| 195 | if(hnor->State == HAL_NOR_STATE_RESET) |
240 | if (hnor->State == HAL_NOR_STATE_RESET) |
| 196 | { |
241 | { |
| 197 | /* Allocate lock resource and initialize it */ |
242 | /* Allocate lock resource and initialize it */ |
| 198 | hnor->Lock = HAL_UNLOCKED; |
243 | hnor->Lock = HAL_UNLOCKED; |
| - | 244 | ||
| - | 245 | #if (USE_HAL_NOR_REGISTER_CALLBACKS == 1) |
|
| - | 246 | if (hnor->MspInitCallback == NULL) |
|
| 199 | 247 | { |
|
| - | 248 | hnor->MspInitCallback = HAL_NOR_MspInit; |
|
| - | 249 | } |
|
| - | 250 | ||
| - | 251 | /* Init the low level hardware */ |
|
| - | 252 | hnor->MspInitCallback(hnor); |
|
| - | 253 | #else |
|
| 200 | /* Initialize the low level hardware (MSP) */ |
254 | /* Initialize the low level hardware (MSP) */ |
| 201 | HAL_NOR_MspInit(hnor); |
255 | HAL_NOR_MspInit(hnor); |
| - | 256 | #endif /* (USE_HAL_NOR_REGISTER_CALLBACKS) */ |
|
| 202 | } |
257 | } |
| 203 | 258 | ||
| 204 | /* Initialize NOR control Interface */ |
259 | /* Initialize NOR control Interface */ |
| 205 | FSMC_NORSRAM_Init(hnor->Instance, &(hnor->Init)); |
260 | (void)FSMC_NORSRAM_Init(hnor->Instance, &(hnor->Init)); |
| 206 | 261 | ||
| 207 | /* Initialize NOR timing Interface */ |
262 | /* Initialize NOR timing Interface */ |
| 208 | FSMC_NORSRAM_Timing_Init(hnor->Instance, Timing, hnor->Init.NSBank); |
263 | (void)FSMC_NORSRAM_Timing_Init(hnor->Instance, Timing, hnor->Init.NSBank); |
| 209 | 264 | ||
| 210 | /* Initialize NOR extended mode timing Interface */ |
265 | /* Initialize NOR extended mode timing Interface */ |
| 211 | FSMC_NORSRAM_Extended_Timing_Init(hnor->Extended, ExtTiming, hnor->Init.NSBank, hnor->Init.ExtendedMode); |
266 | (void)FSMC_NORSRAM_Extended_Timing_Init(hnor->Extended, ExtTiming, hnor->Init.NSBank, hnor->Init.ExtendedMode); |
| 212 | 267 | ||
| 213 | /* Enable the NORSRAM device */ |
268 | /* Enable the NORSRAM device */ |
| 214 | __FSMC_NORSRAM_ENABLE(hnor->Instance, hnor->Init.NSBank); |
269 | __FSMC_NORSRAM_ENABLE(hnor->Instance, hnor->Init.NSBank); |
| 215 | 270 | ||
| 216 | /* Initialize NOR Memory Data Width*/ |
271 | /* Initialize NOR Memory Data Width*/ |
| 217 | if (hnor->Init.MemoryDataWidth == FSMC_NORSRAM_MEM_BUS_WIDTH_8) |
272 | if (hnor->Init.MemoryDataWidth == FSMC_NORSRAM_MEM_BUS_WIDTH_8) |
| 218 | { |
273 | { |
| 219 | uwNORMemoryDataWidth = NOR_MEMORY_8B; |
274 | uwNORMemoryDataWidth = NOR_MEMORY_8B; |
| Line 221... | Line 276... | ||
| 221 | else |
276 | else |
| 222 | { |
277 | { |
| 223 | uwNORMemoryDataWidth = NOR_MEMORY_16B; |
278 | uwNORMemoryDataWidth = NOR_MEMORY_16B; |
| 224 | } |
279 | } |
| 225 | 280 | ||
| 226 | /* Check the NOR controller state */ |
281 | /* Initialize the NOR controller state */ |
| 227 | hnor->State = HAL_NOR_STATE_READY; |
282 | hnor->State = HAL_NOR_STATE_READY; |
| - | 283 | ||
| - | 284 | /* Select the NOR device address */ |
|
| - | 285 | if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1) |
|
| - | 286 | { |
|
| - | 287 | deviceaddress = NOR_MEMORY_ADRESS1; |
|
| - | 288 | } |
|
| - | 289 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2) |
|
| - | 290 | { |
|
| - | 291 | deviceaddress = NOR_MEMORY_ADRESS2; |
|
| - | 292 | } |
|
| - | 293 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3) |
|
| - | 294 | { |
|
| - | 295 | deviceaddress = NOR_MEMORY_ADRESS3; |
|
| - | 296 | } |
|
| - | 297 | else /* FSMC_NORSRAM_BANK4 */ |
|
| - | 298 | { |
|
| - | 299 | deviceaddress = NOR_MEMORY_ADRESS4; |
|
| 228 | 300 | } |
|
| - | 301 | ||
| - | 302 | /* Get the value of the command set */ |
|
| - | 303 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_CFI), NOR_CMD_DATA_CFI); |
|
| - | 304 | hnor->CommandSet = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_ADDRESS_COMMAND_SET); |
|
| - | 305 | ||
| 229 | return HAL_OK; |
306 | return HAL_NOR_ReturnToReadMode(hnor); |
| 230 | } |
307 | } |
| 231 | 308 | ||
| 232 | /** |
309 | /** |
| 233 | * @brief Perform NOR memory De-Initialization sequence |
310 | * @brief Perform NOR memory De-Initialization sequence |
| 234 | * @param hnor: pointer to a NOR_HandleTypeDef structure that contains |
311 | * @param hnor pointer to a NOR_HandleTypeDef structure that contains |
| 235 | * the configuration information for NOR module. |
312 | * the configuration information for NOR module. |
| 236 | * @retval HAL status |
313 | * @retval HAL status |
| 237 | */ |
314 | */ |
| 238 | HAL_StatusTypeDef HAL_NOR_DeInit(NOR_HandleTypeDef *hnor) |
315 | HAL_StatusTypeDef HAL_NOR_DeInit(NOR_HandleTypeDef *hnor) |
| 239 | { |
316 | { |
| - | 317 | #if (USE_HAL_NOR_REGISTER_CALLBACKS == 1) |
|
| - | 318 | if (hnor->MspDeInitCallback == NULL) |
|
| - | 319 | { |
|
| - | 320 | hnor->MspDeInitCallback = HAL_NOR_MspDeInit; |
|
| - | 321 | } |
|
| - | 322 | ||
| - | 323 | /* DeInit the low level hardware */ |
|
| - | 324 | hnor->MspDeInitCallback(hnor); |
|
| - | 325 | #else |
|
| 240 | /* De-Initialize the low level hardware (MSP) */ |
326 | /* De-Initialize the low level hardware (MSP) */ |
| 241 | HAL_NOR_MspDeInit(hnor); |
327 | HAL_NOR_MspDeInit(hnor); |
| - | 328 | #endif /* (USE_HAL_NOR_REGISTER_CALLBACKS) */ |
|
| 242 | 329 | ||
| 243 | /* Configure the NOR registers with their reset values */ |
330 | /* Configure the NOR registers with their reset values */ |
| 244 | FSMC_NORSRAM_DeInit(hnor->Instance, hnor->Extended, hnor->Init.NSBank); |
331 | (void)FSMC_NORSRAM_DeInit(hnor->Instance, hnor->Extended, hnor->Init.NSBank); |
| 245 | 332 | ||
| 246 | /* Update the NOR controller state */ |
333 | /* Reset the NOR controller state */ |
| 247 | hnor->State = HAL_NOR_STATE_RESET; |
334 | hnor->State = HAL_NOR_STATE_RESET; |
| 248 | 335 | ||
| 249 | /* Release Lock */ |
336 | /* Release Lock */ |
| 250 | __HAL_UNLOCK(hnor); |
337 | __HAL_UNLOCK(hnor); |
| 251 | 338 | ||
| 252 | return HAL_OK; |
339 | return HAL_OK; |
| 253 | } |
340 | } |
| 254 | 341 | ||
| 255 | /** |
342 | /** |
| 256 | * @brief NOR MSP Init |
343 | * @brief NOR MSP Init |
| 257 | * @param hnor: pointer to a NOR_HandleTypeDef structure that contains |
344 | * @param hnor pointer to a NOR_HandleTypeDef structure that contains |
| 258 | * the configuration information for NOR module. |
345 | * the configuration information for NOR module. |
| 259 | * @retval None |
346 | * @retval None |
| 260 | */ |
347 | */ |
| 261 | __weak void HAL_NOR_MspInit(NOR_HandleTypeDef *hnor) |
348 | __weak void HAL_NOR_MspInit(NOR_HandleTypeDef *hnor) |
| 262 | { |
349 | { |
| 263 | /* Prevent unused argument(s) compilation warning */ |
350 | /* Prevent unused argument(s) compilation warning */ |
| 264 | UNUSED(hnor); |
351 | UNUSED(hnor); |
| - | 352 | ||
| 265 | /* NOTE : This function Should not be modified, when the callback is needed, |
353 | /* NOTE : This function Should not be modified, when the callback is needed, |
| 266 | the HAL_NOR_MspInit could be implemented in the user file |
354 | the HAL_NOR_MspInit could be implemented in the user file |
| 267 | */ |
355 | */ |
| 268 | } |
356 | } |
| 269 | 357 | ||
| 270 | /** |
358 | /** |
| 271 | * @brief NOR MSP DeInit |
359 | * @brief NOR MSP DeInit |
| 272 | * @param hnor: pointer to a NOR_HandleTypeDef structure that contains |
360 | * @param hnor pointer to a NOR_HandleTypeDef structure that contains |
| 273 | * the configuration information for NOR module. |
361 | * the configuration information for NOR module. |
| 274 | * @retval None |
362 | * @retval None |
| 275 | */ |
363 | */ |
| 276 | __weak void HAL_NOR_MspDeInit(NOR_HandleTypeDef *hnor) |
364 | __weak void HAL_NOR_MspDeInit(NOR_HandleTypeDef *hnor) |
| 277 | { |
365 | { |
| 278 | /* Prevent unused argument(s) compilation warning */ |
366 | /* Prevent unused argument(s) compilation warning */ |
| 279 | UNUSED(hnor); |
367 | UNUSED(hnor); |
| - | 368 | ||
| 280 | /* NOTE : This function Should not be modified, when the callback is needed, |
369 | /* NOTE : This function Should not be modified, when the callback is needed, |
| 281 | the HAL_NOR_MspDeInit could be implemented in the user file |
370 | the HAL_NOR_MspDeInit could be implemented in the user file |
| 282 | */ |
371 | */ |
| 283 | } |
372 | } |
| 284 | 373 | ||
| 285 | /** |
374 | /** |
| 286 | * @brief NOR MSP Wait fro Ready/Busy signal |
375 | * @brief NOR MSP Wait for Ready/Busy signal |
| 287 | * @param hnor: pointer to a NOR_HandleTypeDef structure that contains |
376 | * @param hnor pointer to a NOR_HandleTypeDef structure that contains |
| 288 | * the configuration information for NOR module. |
377 | * the configuration information for NOR module. |
| 289 | * @param Timeout: Maximum timeout value |
378 | * @param Timeout Maximum timeout value |
| 290 | * @retval None |
379 | * @retval None |
| 291 | */ |
380 | */ |
| 292 | __weak void HAL_NOR_MspWait(NOR_HandleTypeDef *hnor, uint32_t Timeout) |
381 | __weak void HAL_NOR_MspWait(NOR_HandleTypeDef *hnor, uint32_t Timeout) |
| 293 | { |
382 | { |
| 294 | /* Prevent unused argument(s) compilation warning */ |
383 | /* Prevent unused argument(s) compilation warning */ |
| 295 | UNUSED(hnor); |
384 | UNUSED(hnor); |
| 296 | UNUSED(Timeout); |
385 | UNUSED(Timeout); |
| - | 386 | ||
| 297 | /* NOTE : This function Should not be modified, when the callback is needed, |
387 | /* NOTE : This function Should not be modified, when the callback is needed, |
| 298 | the HAL_NOR_MspWait could be implemented in the user file |
388 | the HAL_NOR_MspWait could be implemented in the user file |
| 299 | */ |
389 | */ |
| 300 | } |
390 | } |
| 301 | 391 | ||
| 302 | /** |
392 | /** |
| 303 | * @} |
393 | * @} |
| 304 | */ |
394 | */ |
| 305 | 395 | ||
| 306 | /** @defgroup NOR_Exported_Functions_Group2 Input and Output functions |
396 | /** @defgroup NOR_Exported_Functions_Group2 Input and Output functions |
| 307 | * @brief Input Output and memory control functions |
397 | * @brief Input Output and memory control functions |
| 308 | * |
398 | * |
| 309 | @verbatim |
399 | @verbatim |
| 310 | ============================================================================== |
400 | ============================================================================== |
| 311 | ##### NOR Input and Output functions ##### |
401 | ##### NOR Input and Output functions ##### |
| 312 | ============================================================================== |
402 | ============================================================================== |
| 313 | [..] |
403 | [..] |
| 314 | This section provides functions allowing to use and control the NOR memory |
404 | This section provides functions allowing to use and control the NOR memory |
| 315 | |
405 | |
| 316 | @endverbatim |
406 | @endverbatim |
| 317 | * @{ |
407 | * @{ |
| 318 | */ |
408 | */ |
| 319 | 409 | ||
| 320 | /** |
410 | /** |
| 321 | * @brief Read NOR flash IDs |
411 | * @brief Read NOR flash IDs |
| 322 | * @param hnor: pointer to a NOR_HandleTypeDef structure that contains |
412 | * @param hnor pointer to a NOR_HandleTypeDef structure that contains |
| 323 | * the configuration information for NOR module. |
413 | * the configuration information for NOR module. |
| 324 | * @param pNOR_ID : pointer to NOR ID structure |
414 | * @param pNOR_ID pointer to NOR ID structure |
| 325 | * @retval HAL status |
415 | * @retval HAL status |
| 326 | */ |
416 | */ |
| 327 | HAL_StatusTypeDef HAL_NOR_Read_ID(NOR_HandleTypeDef *hnor, NOR_IDTypeDef *pNOR_ID) |
417 | HAL_StatusTypeDef HAL_NOR_Read_ID(NOR_HandleTypeDef *hnor, NOR_IDTypeDef *pNOR_ID) |
| 328 | { |
418 | { |
| 329 | uint32_t deviceaddress = 0U; |
419 | uint32_t deviceaddress; |
| 330 | - | ||
| 331 | /* Process Locked */ |
420 | HAL_NOR_StateTypeDef state; |
| 332 | __HAL_LOCK(hnor); |
421 | HAL_StatusTypeDef status = HAL_OK; |
| 333 | 422 | ||
| 334 | /* Check the NOR controller state */ |
423 | /* Check the NOR controller state */ |
| 335 | if(hnor->State == HAL_NOR_STATE_BUSY) |
- | |
| 336 | { |
- | |
| 337 | return HAL_BUSY; |
424 | state = hnor->State; |
| 338 | } |
- | |
| 339 | - | ||
| 340 | /* Select the NOR device address */ |
- | |
| 341 | if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1) |
425 | if (state == HAL_NOR_STATE_BUSY) |
| 342 | { |
426 | { |
| 343 | deviceaddress = NOR_MEMORY_ADRESS1; |
427 | return HAL_BUSY; |
| 344 | } |
428 | } |
| 345 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2) |
429 | else if ((state == HAL_NOR_STATE_READY) || (state == HAL_NOR_STATE_PROTECTED)) |
| 346 | { |
430 | { |
| - | 431 | /* Process Locked */ |
|
| - | 432 | __HAL_LOCK(hnor); |
|
| - | 433 | ||
| - | 434 | /* Update the NOR controller state */ |
|
| - | 435 | hnor->State = HAL_NOR_STATE_BUSY; |
|
| - | 436 | ||
| - | 437 | /* Select the NOR device address */ |
|
| - | 438 | if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1) |
|
| - | 439 | { |
|
| - | 440 | deviceaddress = NOR_MEMORY_ADRESS1; |
|
| - | 441 | } |
|
| - | 442 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2) |
|
| - | 443 | { |
|
| 347 | deviceaddress = NOR_MEMORY_ADRESS2; |
444 | deviceaddress = NOR_MEMORY_ADRESS2; |
| - | 445 | } |
|
| - | 446 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3) |
|
| - | 447 | { |
|
| - | 448 | deviceaddress = NOR_MEMORY_ADRESS3; |
|
| - | 449 | } |
|
| - | 450 | else /* FSMC_NORSRAM_BANK4 */ |
|
| - | 451 | { |
|
| - | 452 | deviceaddress = NOR_MEMORY_ADRESS4; |
|
| - | 453 | } |
|
| - | 454 | ||
| - | 455 | /* Send read ID command */ |
|
| - | 456 | if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET) |
|
| - | 457 | { |
|
| - | 458 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST); |
|
| - | 459 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND); |
|
| - | 460 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_AUTO_SELECT); |
|
| - | 461 | } |
|
| - | 462 | else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET) |
|
| - | 463 | { |
|
| - | 464 | NOR_WRITE(deviceaddress, NOR_CMD_DATA_AUTO_SELECT); |
|
| - | 465 | } |
|
| - | 466 | else |
|
| - | 467 | { |
|
| - | 468 | /* Primary command set not supported by the driver */ |
|
| - | 469 | status = HAL_ERROR; |
|
| - | 470 | } |
|
| - | 471 | ||
| - | 472 | if (status != HAL_ERROR) |
|
| - | 473 | { |
|
| - | 474 | /* Read the NOR IDs */ |
|
| - | 475 | pNOR_ID->Manufacturer_Code = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, MC_ADDRESS); |
|
| - | 476 | pNOR_ID->Device_Code1 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, DEVICE_CODE1_ADDR); |
|
| - | 477 | pNOR_ID->Device_Code2 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, DEVICE_CODE2_ADDR); |
|
| - | 478 | pNOR_ID->Device_Code3 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, DEVICE_CODE3_ADDR); |
|
| - | 479 | } |
|
| - | 480 | ||
| - | 481 | /* Check the NOR controller state */ |
|
| - | 482 | hnor->State = state; |
|
| - | 483 | ||
| - | 484 | /* Process unlocked */ |
|
| - | 485 | __HAL_UNLOCK(hnor); |
|
| 348 | } |
486 | } |
| 349 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3) |
487 | else |
| 350 | { |
488 | { |
| 351 | deviceaddress = NOR_MEMORY_ADRESS3; |
489 | return HAL_ERROR; |
| 352 | } |
490 | } |
| 353 | else /* FSMC_NORSRAM_BANK4 */ |
- | |
| 354 | { |
- | |
| 355 | deviceaddress = NOR_MEMORY_ADRESS4; |
- | |
| 356 | } |
- | |
| 357 | - | ||
| 358 | /* Update the NOR controller state */ |
- | |
| 359 | hnor->State = HAL_NOR_STATE_BUSY; |
- | |
| 360 | - | ||
| 361 | /* Send read ID command */ |
- | |
| 362 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST); |
- | |
| 363 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND); |
- | |
| 364 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_AUTO_SELECT); |
- | |
| 365 | 491 | ||
| 366 | /* Read the NOR IDs */ |
- | |
| 367 | pNOR_ID->Manufacturer_Code = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, MC_ADDRESS); |
- | |
| 368 | pNOR_ID->Device_Code1 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, DEVICE_CODE1_ADDR); |
- | |
| 369 | pNOR_ID->Device_Code2 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, DEVICE_CODE2_ADDR); |
- | |
| 370 | pNOR_ID->Device_Code3 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, DEVICE_CODE3_ADDR); |
- | |
| 371 | - | ||
| 372 | /* Check the NOR controller state */ |
- | |
| 373 | hnor->State = HAL_NOR_STATE_READY; |
- | |
| 374 | - | ||
| 375 | /* Process unlocked */ |
- | |
| 376 | __HAL_UNLOCK(hnor); |
- | |
| 377 | - | ||
| 378 | return HAL_OK; |
492 | return status; |
| 379 | } |
493 | } |
| 380 | 494 | ||
| 381 | /** |
495 | /** |
| 382 | * @brief Returns the NOR memory to Read mode. |
496 | * @brief Returns the NOR memory to Read mode. |
| 383 | * @param hnor: pointer to a NOR_HandleTypeDef structure that contains |
497 | * @param hnor pointer to a NOR_HandleTypeDef structure that contains |
| 384 | * the configuration information for NOR module. |
498 | * the configuration information for NOR module. |
| 385 | * @retval HAL status |
499 | * @retval HAL status |
| 386 | */ |
500 | */ |
| 387 | HAL_StatusTypeDef HAL_NOR_ReturnToReadMode(NOR_HandleTypeDef *hnor) |
501 | HAL_StatusTypeDef HAL_NOR_ReturnToReadMode(NOR_HandleTypeDef *hnor) |
| 388 | { |
502 | { |
| 389 | uint32_t deviceaddress = 0U; |
503 | uint32_t deviceaddress; |
| 390 | - | ||
| 391 | /* Process Locked */ |
504 | HAL_NOR_StateTypeDef state; |
| 392 | __HAL_LOCK(hnor); |
505 | HAL_StatusTypeDef status = HAL_OK; |
| 393 | 506 | ||
| 394 | /* Check the NOR controller state */ |
507 | /* Check the NOR controller state */ |
| 395 | if(hnor->State == HAL_NOR_STATE_BUSY) |
- | |
| 396 | { |
- | |
| 397 | return HAL_BUSY; |
508 | state = hnor->State; |
| 398 | } |
- | |
| 399 | - | ||
| 400 | /* Select the NOR device address */ |
- | |
| 401 | if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1) |
509 | if (state == HAL_NOR_STATE_BUSY) |
| 402 | { |
510 | { |
| 403 | deviceaddress = NOR_MEMORY_ADRESS1; |
511 | return HAL_BUSY; |
| 404 | } |
512 | } |
| 405 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2) |
513 | else if ((state == HAL_NOR_STATE_READY) || (state == HAL_NOR_STATE_PROTECTED)) |
| 406 | { |
514 | { |
| - | 515 | /* Process Locked */ |
|
| - | 516 | __HAL_LOCK(hnor); |
|
| - | 517 | ||
| - | 518 | /* Update the NOR controller state */ |
|
| - | 519 | hnor->State = HAL_NOR_STATE_BUSY; |
|
| - | 520 | ||
| - | 521 | /* Select the NOR device address */ |
|
| - | 522 | if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1) |
|
| - | 523 | { |
|
| - | 524 | deviceaddress = NOR_MEMORY_ADRESS1; |
|
| - | 525 | } |
|
| - | 526 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2) |
|
| - | 527 | { |
|
| 407 | deviceaddress = NOR_MEMORY_ADRESS2; |
528 | deviceaddress = NOR_MEMORY_ADRESS2; |
| - | 529 | } |
|
| - | 530 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3) |
|
| - | 531 | { |
|
| - | 532 | deviceaddress = NOR_MEMORY_ADRESS3; |
|
| - | 533 | } |
|
| - | 534 | else /* FSMC_NORSRAM_BANK4 */ |
|
| - | 535 | { |
|
| - | 536 | deviceaddress = NOR_MEMORY_ADRESS4; |
|
| - | 537 | } |
|
| - | 538 | ||
| - | 539 | if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET) |
|
| - | 540 | { |
|
| - | 541 | NOR_WRITE(deviceaddress, NOR_CMD_DATA_READ_RESET); |
|
| - | 542 | } |
|
| - | 543 | else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET) |
|
| - | 544 | { |
|
| - | 545 | NOR_WRITE(deviceaddress, NOR_CMD_READ_ARRAY); |
|
| - | 546 | } |
|
| - | 547 | else |
|
| - | 548 | { |
|
| - | 549 | /* Primary command set not supported by the driver */ |
|
| - | 550 | status = HAL_ERROR; |
|
| - | 551 | } |
|
| - | 552 | ||
| - | 553 | /* Check the NOR controller state */ |
|
| - | 554 | hnor->State = state; |
|
| - | 555 | ||
| - | 556 | /* Process unlocked */ |
|
| - | 557 | __HAL_UNLOCK(hnor); |
|
| 408 | } |
558 | } |
| 409 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3) |
559 | else |
| 410 | { |
560 | { |
| 411 | deviceaddress = NOR_MEMORY_ADRESS3; |
561 | return HAL_ERROR; |
| 412 | } |
562 | } |
| 413 | else /* FSMC_NORSRAM_BANK4 */ |
- | |
| 414 | { |
- | |
| 415 | deviceaddress = NOR_MEMORY_ADRESS4; |
- | |
| 416 | } |
- | |
| 417 | - | ||
| 418 | NOR_WRITE(deviceaddress, NOR_CMD_DATA_READ_RESET); |
- | |
| 419 | 563 | ||
| 420 | /* Check the NOR controller state */ |
- | |
| 421 | hnor->State = HAL_NOR_STATE_READY; |
- | |
| 422 | - | ||
| 423 | /* Process unlocked */ |
- | |
| 424 | __HAL_UNLOCK(hnor); |
- | |
| 425 | - | ||
| 426 | return HAL_OK; |
564 | return status; |
| 427 | } |
565 | } |
| 428 | 566 | ||
| 429 | /** |
567 | /** |
| 430 | * @brief Read data from NOR memory |
568 | * @brief Read data from NOR memory |
| 431 | * @param hnor: pointer to a NOR_HandleTypeDef structure that contains |
569 | * @param hnor pointer to a NOR_HandleTypeDef structure that contains |
| 432 | * the configuration information for NOR module. |
570 | * the configuration information for NOR module. |
| 433 | * @param pAddress: pointer to Device address |
571 | * @param pAddress pointer to Device address |
| 434 | * @param pData : pointer to read data |
572 | * @param pData pointer to read data |
| 435 | * @retval HAL status |
573 | * @retval HAL status |
| 436 | */ |
574 | */ |
| 437 | HAL_StatusTypeDef HAL_NOR_Read(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData) |
575 | HAL_StatusTypeDef HAL_NOR_Read(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData) |
| 438 | { |
576 | { |
| 439 | uint32_t deviceaddress = 0U; |
577 | uint32_t deviceaddress; |
| 440 | - | ||
| 441 | /* Process Locked */ |
578 | HAL_NOR_StateTypeDef state; |
| 442 | __HAL_LOCK(hnor); |
579 | HAL_StatusTypeDef status = HAL_OK; |
| 443 | 580 | ||
| 444 | /* Check the NOR controller state */ |
581 | /* Check the NOR controller state */ |
| - | 582 | state = hnor->State; |
|
| 445 | if(hnor->State == HAL_NOR_STATE_BUSY) |
583 | if (state == HAL_NOR_STATE_BUSY) |
| 446 | { |
584 | { |
| 447 | return HAL_BUSY; |
585 | return HAL_BUSY; |
| 448 | } |
586 | } |
| 449 | - | ||
| 450 | /* Select the NOR device address */ |
- | |
| 451 | if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1) |
587 | else if ((state == HAL_NOR_STATE_READY) || (state == HAL_NOR_STATE_PROTECTED)) |
| 452 | { |
588 | { |
| - | 589 | /* Process Locked */ |
|
| - | 590 | __HAL_LOCK(hnor); |
|
| - | 591 | ||
| - | 592 | /* Update the NOR controller state */ |
|
| - | 593 | hnor->State = HAL_NOR_STATE_BUSY; |
|
| - | 594 | ||
| - | 595 | /* Select the NOR device address */ |
|
| - | 596 | if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1) |
|
| - | 597 | { |
|
| 453 | deviceaddress = NOR_MEMORY_ADRESS1; |
598 | deviceaddress = NOR_MEMORY_ADRESS1; |
| 454 | } |
599 | } |
| 455 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2) |
600 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2) |
| 456 | { |
601 | { |
| 457 | deviceaddress = NOR_MEMORY_ADRESS2; |
602 | deviceaddress = NOR_MEMORY_ADRESS2; |
| - | 603 | } |
|
| - | 604 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3) |
|
| - | 605 | { |
|
| - | 606 | deviceaddress = NOR_MEMORY_ADRESS3; |
|
| - | 607 | } |
|
| - | 608 | else /* FSMC_NORSRAM_BANK4 */ |
|
| - | 609 | { |
|
| - | 610 | deviceaddress = NOR_MEMORY_ADRESS4; |
|
| - | 611 | } |
|
| - | 612 | ||
| - | 613 | /* Send read data command */ |
|
| - | 614 | if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET) |
|
| - | 615 | { |
|
| - | 616 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST); |
|
| - | 617 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND); |
|
| - | 618 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_READ_RESET); |
|
| - | 619 | } |
|
| - | 620 | else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET) |
|
| - | 621 | { |
|
| - | 622 | NOR_WRITE(pAddress, NOR_CMD_READ_ARRAY); |
|
| - | 623 | } |
|
| - | 624 | else |
|
| - | 625 | { |
|
| - | 626 | /* Primary command set not supported by the driver */ |
|
| - | 627 | status = HAL_ERROR; |
|
| - | 628 | } |
|
| - | 629 | ||
| - | 630 | if (status != HAL_ERROR) |
|
| - | 631 | { |
|
| - | 632 | /* Read the data */ |
|
| - | 633 | *pData = (uint16_t)(*(__IO uint32_t *)pAddress); |
|
| - | 634 | } |
|
| - | 635 | ||
| - | 636 | /* Check the NOR controller state */ |
|
| - | 637 | hnor->State = state; |
|
| - | 638 | ||
| - | 639 | /* Process unlocked */ |
|
| - | 640 | __HAL_UNLOCK(hnor); |
|
| 458 | } |
641 | } |
| 459 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3) |
642 | else |
| 460 | { |
643 | { |
| 461 | deviceaddress = NOR_MEMORY_ADRESS3; |
644 | return HAL_ERROR; |
| 462 | } |
645 | } |
| 463 | else /* FSMC_NORSRAM_BANK4 */ |
- | |
| 464 | { |
- | |
| 465 | deviceaddress = NOR_MEMORY_ADRESS4; |
- | |
| 466 | } |
- | |
| 467 | - | ||
| 468 | /* Update the NOR controller state */ |
- | |
| 469 | hnor->State = HAL_NOR_STATE_BUSY; |
- | |
| 470 | - | ||
| 471 | /* Send read data command */ |
- | |
| 472 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST); |
- | |
| 473 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND); |
- | |
| 474 | NOR_WRITE((uint32_t)pAddress, NOR_CMD_DATA_READ_RESET); |
- | |
| 475 | 646 | ||
| 476 | /* Read the data */ |
- | |
| 477 | *pData = *(__IO uint32_t *)(uint32_t)pAddress; |
- | |
| 478 | - | ||
| 479 | /* Check the NOR controller state */ |
- | |
| 480 | hnor->State = HAL_NOR_STATE_READY; |
- | |
| 481 | - | ||
| 482 | /* Process unlocked */ |
- | |
| 483 | __HAL_UNLOCK(hnor); |
- | |
| 484 | - | ||
| 485 | return HAL_OK; |
647 | return status; |
| 486 | } |
648 | } |
| 487 | 649 | ||
| 488 | /** |
650 | /** |
| 489 | * @brief Program data to NOR memory |
651 | * @brief Program data to NOR memory |
| 490 | * @param hnor: pointer to a NOR_HandleTypeDef structure that contains |
652 | * @param hnor pointer to a NOR_HandleTypeDef structure that contains |
| 491 | * the configuration information for NOR module. |
653 | * the configuration information for NOR module. |
| 492 | * @param pAddress: Device address |
654 | * @param pAddress Device address |
| 493 | * @param pData : pointer to the data to write |
655 | * @param pData pointer to the data to write |
| 494 | * @retval HAL status |
656 | * @retval HAL status |
| 495 | */ |
657 | */ |
| 496 | HAL_StatusTypeDef HAL_NOR_Program(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData) |
658 | HAL_StatusTypeDef HAL_NOR_Program(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData) |
| 497 | { |
659 | { |
| 498 | uint32_t deviceaddress = 0U; |
660 | uint32_t deviceaddress; |
| 499 | - | ||
| 500 | /* Process Locked */ |
661 | HAL_StatusTypeDef status = HAL_OK; |
| 501 | __HAL_LOCK(hnor); |
- | |
| 502 | 662 | ||
| 503 | /* Check the NOR controller state */ |
663 | /* Check the NOR controller state */ |
| 504 | if(hnor->State == HAL_NOR_STATE_BUSY) |
664 | if (hnor->State == HAL_NOR_STATE_BUSY) |
| 505 | { |
665 | { |
| 506 | return HAL_BUSY; |
666 | return HAL_BUSY; |
| 507 | } |
667 | } |
| 508 | - | ||
| 509 | /* Select the NOR device address */ |
- | |
| 510 | if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1) |
- | |
| 511 | { |
- | |
| 512 | deviceaddress = NOR_MEMORY_ADRESS1; |
- | |
| 513 | } |
- | |
| 514 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2) |
668 | else if (hnor->State == HAL_NOR_STATE_READY) |
| 515 | { |
669 | { |
| - | 670 | /* Process Locked */ |
|
| - | 671 | __HAL_LOCK(hnor); |
|
| - | 672 | ||
| - | 673 | /* Update the NOR controller state */ |
|
| - | 674 | hnor->State = HAL_NOR_STATE_BUSY; |
|
| - | 675 | ||
| - | 676 | /* Select the NOR device address */ |
|
| - | 677 | if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1) |
|
| - | 678 | { |
|
| - | 679 | deviceaddress = NOR_MEMORY_ADRESS1; |
|
| - | 680 | } |
|
| - | 681 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2) |
|
| - | 682 | { |
|
| 516 | deviceaddress = NOR_MEMORY_ADRESS2; |
683 | deviceaddress = NOR_MEMORY_ADRESS2; |
| - | 684 | } |
|
| - | 685 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3) |
|
| - | 686 | { |
|
| - | 687 | deviceaddress = NOR_MEMORY_ADRESS3; |
|
| - | 688 | } |
|
| - | 689 | else /* FSMC_NORSRAM_BANK4 */ |
|
| - | 690 | { |
|
| - | 691 | deviceaddress = NOR_MEMORY_ADRESS4; |
|
| - | 692 | } |
|
| - | 693 | ||
| - | 694 | /* Send program data command */ |
|
| - | 695 | if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET) |
|
| - | 696 | { |
|
| - | 697 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST); |
|
| - | 698 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND); |
|
| - | 699 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_PROGRAM); |
|
| - | 700 | } |
|
| - | 701 | else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET) |
|
| - | 702 | { |
|
| - | 703 | NOR_WRITE(pAddress, NOR_CMD_WORD_PROGRAM); |
|
| - | 704 | } |
|
| - | 705 | else |
|
| - | 706 | { |
|
| - | 707 | /* Primary command set not supported by the driver */ |
|
| - | 708 | status = HAL_ERROR; |
|
| - | 709 | } |
|
| - | 710 | ||
| - | 711 | if (status != HAL_ERROR) |
|
| - | 712 | { |
|
| - | 713 | /* Write the data */ |
|
| - | 714 | NOR_WRITE(pAddress, *pData); |
|
| - | 715 | } |
|
| - | 716 | ||
| - | 717 | /* Check the NOR controller state */ |
|
| - | 718 | hnor->State = HAL_NOR_STATE_READY; |
|
| - | 719 | ||
| - | 720 | /* Process unlocked */ |
|
| - | 721 | __HAL_UNLOCK(hnor); |
|
| 517 | } |
722 | } |
| 518 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3) |
723 | else |
| 519 | { |
724 | { |
| 520 | deviceaddress = NOR_MEMORY_ADRESS3; |
725 | return HAL_ERROR; |
| 521 | } |
726 | } |
| 522 | else /* FSMC_NORSRAM_BANK4 */ |
- | |
| 523 | { |
- | |
| 524 | deviceaddress = NOR_MEMORY_ADRESS4; |
- | |
| 525 | } |
- | |
| 526 | - | ||
| 527 | /* Update the NOR controller state */ |
- | |
| 528 | hnor->State = HAL_NOR_STATE_BUSY; |
- | |
| 529 | - | ||
| 530 | /* Send program data command */ |
- | |
| 531 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST); |
- | |
| 532 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND); |
- | |
| 533 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_PROGRAM); |
- | |
| 534 | 727 | ||
| 535 | /* Write the data */ |
- | |
| 536 | NOR_WRITE(pAddress, *pData); |
- | |
| 537 | - | ||
| 538 | /* Check the NOR controller state */ |
- | |
| 539 | hnor->State = HAL_NOR_STATE_READY; |
- | |
| 540 | - | ||
| 541 | /* Process unlocked */ |
- | |
| 542 | __HAL_UNLOCK(hnor); |
- | |
| 543 | - | ||
| 544 | return HAL_OK; |
728 | return status; |
| 545 | } |
729 | } |
| 546 | 730 | ||
| 547 | /** |
731 | /** |
| 548 | * @brief Reads a block of data from the FSMC NOR memory. |
732 | * @brief Reads a half-word buffer from the NOR memory. |
| 549 | * @param hnor: pointer to a NOR_HandleTypeDef structure that contains |
733 | * @param hnor pointer to the NOR handle |
| 550 | * the configuration information for NOR module. |
- | |
| 551 | * @param uwAddress: NOR memory internal address to read from. |
734 | * @param uwAddress NOR memory internal address to read from. |
| 552 | * @param pData: pointer to the buffer that receives the data read from the |
735 | * @param pData pointer to the buffer that receives the data read from the |
| 553 | * NOR memory. |
736 | * NOR memory. |
| 554 | * @param uwBufferSize : number of Half word to read. |
737 | * @param uwBufferSize number of Half word to read. |
| 555 | * @retval HAL status |
738 | * @retval HAL status |
| 556 | */ |
739 | */ |
| 557 | HAL_StatusTypeDef HAL_NOR_ReadBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize) |
740 | HAL_StatusTypeDef HAL_NOR_ReadBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, |
| - | 741 | uint32_t uwBufferSize) |
|
| 558 | { |
742 | { |
| 559 | uint32_t deviceaddress = 0U; |
743 | uint32_t deviceaddress; |
| 560 | 744 | uint32_t size = uwBufferSize; |
|
| 561 | /* Process Locked */ |
745 | uint32_t address = uwAddress; |
| 562 | __HAL_LOCK(hnor); |
746 | uint16_t *data = pData; |
| - | 747 | HAL_NOR_StateTypeDef state; |
|
| - | 748 | HAL_StatusTypeDef status = HAL_OK; |
|
| 563 | 749 | ||
| 564 | /* Check the NOR controller state */ |
750 | /* Check the NOR controller state */ |
| - | 751 | state = hnor->State; |
|
| 565 | if(hnor->State == HAL_NOR_STATE_BUSY) |
752 | if (state == HAL_NOR_STATE_BUSY) |
| 566 | { |
753 | { |
| 567 | return HAL_BUSY; |
754 | return HAL_BUSY; |
| 568 | } |
755 | } |
| 569 | - | ||
| 570 | /* Select the NOR device address */ |
- | |
| 571 | if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1) |
- | |
| 572 | { |
- | |
| 573 | deviceaddress = NOR_MEMORY_ADRESS1; |
- | |
| 574 | } |
- | |
| 575 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2) |
756 | else if ((state == HAL_NOR_STATE_READY) || (state == HAL_NOR_STATE_PROTECTED)) |
| 576 | { |
757 | { |
| - | 758 | /* Process Locked */ |
|
| - | 759 | __HAL_LOCK(hnor); |
|
| - | 760 | ||
| - | 761 | /* Update the NOR controller state */ |
|
| - | 762 | hnor->State = HAL_NOR_STATE_BUSY; |
|
| - | 763 | ||
| - | 764 | /* Select the NOR device address */ |
|
| - | 765 | if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1) |
|
| - | 766 | { |
|
| - | 767 | deviceaddress = NOR_MEMORY_ADRESS1; |
|
| - | 768 | } |
|
| - | 769 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2) |
|
| - | 770 | { |
|
| 577 | deviceaddress = NOR_MEMORY_ADRESS2; |
771 | deviceaddress = NOR_MEMORY_ADRESS2; |
| - | 772 | } |
|
| - | 773 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3) |
|
| - | 774 | { |
|
| - | 775 | deviceaddress = NOR_MEMORY_ADRESS3; |
|
| - | 776 | } |
|
| - | 777 | else /* FSMC_NORSRAM_BANK4 */ |
|
| - | 778 | { |
|
| - | 779 | deviceaddress = NOR_MEMORY_ADRESS4; |
|
| - | 780 | } |
|
| - | 781 | ||
| - | 782 | /* Send read data command */ |
|
| - | 783 | if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET) |
|
| - | 784 | { |
|
| - | 785 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST); |
|
| - | 786 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND); |
|
| - | 787 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_READ_RESET); |
|
| - | 788 | } |
|
| - | 789 | else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET) |
|
| - | 790 | { |
|
| - | 791 | NOR_WRITE(deviceaddress, NOR_CMD_READ_ARRAY); |
|
| - | 792 | } |
|
| - | 793 | else |
|
| - | 794 | { |
|
| - | 795 | /* Primary command set not supported by the driver */ |
|
| - | 796 | status = HAL_ERROR; |
|
| - | 797 | } |
|
| - | 798 | ||
| - | 799 | if (status != HAL_ERROR) |
|
| - | 800 | { |
|
| - | 801 | /* Read buffer */ |
|
| - | 802 | while (size > 0U) |
|
| - | 803 | { |
|
| - | 804 | *data = *(__IO uint16_t *)address; |
|
| - | 805 | data++; |
|
| - | 806 | address += 2U; |
|
| - | 807 | size--; |
|
| - | 808 | } |
|
| - | 809 | } |
|
| - | 810 | ||
| - | 811 | /* Check the NOR controller state */ |
|
| - | 812 | hnor->State = state; |
|
| - | 813 | ||
| - | 814 | /* Process unlocked */ |
|
| - | 815 | __HAL_UNLOCK(hnor); |
|
| 578 | } |
816 | } |
| 579 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3) |
817 | else |
| 580 | { |
818 | { |
| 581 | deviceaddress = NOR_MEMORY_ADRESS3; |
819 | return HAL_ERROR; |
| 582 | } |
820 | } |
| 583 | else /* FSMC_NORSRAM_BANK4 */ |
- | |
| 584 | { |
- | |
| 585 | deviceaddress = NOR_MEMORY_ADRESS4; |
- | |
| 586 | } |
- | |
| 587 | - | ||
| 588 | /* Update the NOR controller state */ |
- | |
| 589 | hnor->State = HAL_NOR_STATE_BUSY; |
- | |
| 590 | 821 | ||
| 591 | /* Send read data command */ |
- | |
| 592 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST); |
- | |
| 593 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND); |
- | |
| 594 | NOR_WRITE(uwAddress, NOR_CMD_DATA_READ_RESET); |
- | |
| 595 | - | ||
| 596 | /* Read buffer */ |
- | |
| 597 | while( uwBufferSize > 0U) |
- | |
| 598 | { |
- | |
| 599 | *pData++ = *(__IO uint16_t *)uwAddress; |
- | |
| 600 | uwAddress += 2U; |
- | |
| 601 | uwBufferSize--; |
- | |
| 602 | } |
- | |
| 603 | - | ||
| 604 | /* Check the NOR controller state */ |
- | |
| 605 | hnor->State = HAL_NOR_STATE_READY; |
- | |
| 606 | - | ||
| 607 | /* Process unlocked */ |
- | |
| 608 | __HAL_UNLOCK(hnor); |
- | |
| 609 | - | ||
| 610 | return HAL_OK; |
822 | return status; |
| 611 | } |
823 | } |
| 612 | 824 | ||
| 613 | /** |
825 | /** |
| 614 | * @brief Writes a half-word buffer to the FSMC NOR memory. This function |
826 | * @brief Writes a half-word buffer to the NOR memory. This function must be used |
| 615 | * must be used only with S29GL128P NOR memory. |
827 | only with S29GL128P NOR memory. |
| 616 | * @param hnor: pointer to a NOR_HandleTypeDef structure that contains |
828 | * @param hnor pointer to the NOR handle |
| 617 | * the configuration information for NOR module. |
- | |
| 618 | * @param uwAddress: NOR memory internal address from which the data |
829 | * @param uwAddress NOR memory internal start write address |
| 619 | * @note Some NOR memory need Address aligned to xx bytes (can be aligned to |
- | |
| 620 | * 64 bytes boundary for example). |
- | |
| 621 | * @param pData: pointer to source data buffer. |
830 | * @param pData pointer to source data buffer. |
| 622 | * @param uwBufferSize: number of Half words to write. |
831 | * @param uwBufferSize Size of the buffer to write |
| 623 | * @note The maximum buffer size allowed is NOR memory dependent |
- | |
| 624 | * (can be 64 Bytes max for example). |
- | |
| 625 | * @retval HAL status |
832 | * @retval HAL status |
| 626 | */ |
833 | */ |
| 627 | HAL_StatusTypeDef HAL_NOR_ProgramBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize) |
834 | HAL_StatusTypeDef HAL_NOR_ProgramBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, |
| - | 835 | uint32_t uwBufferSize) |
|
| 628 | { |
836 | { |
| 629 | uint16_t * p_currentaddress = (uint16_t *)NULL; |
837 | uint16_t *p_currentaddress; |
| 630 | uint16_t * p_endaddress = (uint16_t *)NULL; |
838 | const uint16_t *p_endaddress; |
| 631 | uint32_t lastloadedaddress = 0U, deviceaddress = 0U; |
839 | uint16_t *data = pData; |
| 632 | - | ||
| 633 | /* Process Locked */ |
840 | uint32_t deviceaddress; |
| 634 | __HAL_LOCK(hnor); |
841 | HAL_StatusTypeDef status = HAL_OK; |
| 635 | 842 | ||
| 636 | /* Check the NOR controller state */ |
843 | /* Check the NOR controller state */ |
| 637 | if(hnor->State == HAL_NOR_STATE_BUSY) |
844 | if (hnor->State == HAL_NOR_STATE_BUSY) |
| 638 | { |
845 | { |
| 639 | return HAL_BUSY; |
846 | return HAL_BUSY; |
| 640 | } |
847 | } |
| 641 | - | ||
| 642 | /* Select the NOR device address */ |
- | |
| 643 | if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1) |
848 | else if (hnor->State == HAL_NOR_STATE_READY) |
| 644 | { |
849 | { |
| - | 850 | /* Process Locked */ |
|
| - | 851 | __HAL_LOCK(hnor); |
|
| - | 852 | ||
| - | 853 | /* Update the NOR controller state */ |
|
| - | 854 | hnor->State = HAL_NOR_STATE_BUSY; |
|
| - | 855 | ||
| - | 856 | /* Select the NOR device address */ |
|
| - | 857 | if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1) |
|
| - | 858 | { |
|
| 645 | deviceaddress = NOR_MEMORY_ADRESS1; |
859 | deviceaddress = NOR_MEMORY_ADRESS1; |
| 646 | } |
860 | } |
| 647 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2) |
861 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2) |
| 648 | { |
862 | { |
| 649 | deviceaddress = NOR_MEMORY_ADRESS2; |
863 | deviceaddress = NOR_MEMORY_ADRESS2; |
| 650 | } |
864 | } |
| 651 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3) |
865 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3) |
| 652 | { |
866 | { |
| 653 | deviceaddress = NOR_MEMORY_ADRESS3; |
867 | deviceaddress = NOR_MEMORY_ADRESS3; |
| - | 868 | } |
|
| - | 869 | else /* FSMC_NORSRAM_BANK4 */ |
|
| - | 870 | { |
|
| - | 871 | deviceaddress = NOR_MEMORY_ADRESS4; |
|
| - | 872 | } |
|
| - | 873 | ||
| - | 874 | /* Initialize variables */ |
|
| - | 875 | p_currentaddress = (uint16_t *)(deviceaddress + uwAddress); |
|
| - | 876 | p_endaddress = (uint16_t *)(deviceaddress + uwAddress + (2U * (uwBufferSize - 1U))); |
|
| - | 877 | ||
| - | 878 | if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET) |
|
| - | 879 | { |
|
| - | 880 | /* Issue unlock command sequence */ |
|
| - | 881 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST); |
|
| - | 882 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND); |
|
| - | 883 | ||
| - | 884 | /* Write Buffer Load Command */ |
|
| - | 885 | NOR_WRITE((deviceaddress + uwAddress), NOR_CMD_DATA_BUFFER_AND_PROG); |
|
| - | 886 | NOR_WRITE((deviceaddress + uwAddress), (uint16_t)(uwBufferSize - 1U)); |
|
| - | 887 | } |
|
| - | 888 | else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET) |
|
| - | 889 | { |
|
| - | 890 | /* Write Buffer Load Command */ |
|
| - | 891 | NOR_WRITE((deviceaddress + uwAddress), NOR_CMD_BUFFERED_PROGRAM); |
|
| - | 892 | NOR_WRITE((deviceaddress + uwAddress), (uint16_t)(uwBufferSize - 1U)); |
|
| - | 893 | } |
|
| - | 894 | else |
|
| - | 895 | { |
|
| - | 896 | /* Primary command set not supported by the driver */ |
|
| - | 897 | status = HAL_ERROR; |
|
| - | 898 | } |
|
| - | 899 | ||
| - | 900 | if (status != HAL_ERROR) |
|
| - | 901 | { |
|
| - | 902 | /* Load Data into NOR Buffer */ |
|
| - | 903 | while (p_currentaddress <= p_endaddress) |
|
| - | 904 | { |
|
| - | 905 | NOR_WRITE(p_currentaddress, *data); |
|
| - | 906 | ||
| - | 907 | data++; |
|
| - | 908 | p_currentaddress ++; |
|
| - | 909 | } |
|
| - | 910 | ||
| - | 911 | if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET) |
|
| - | 912 | { |
|
| - | 913 | NOR_WRITE((deviceaddress + uwAddress), NOR_CMD_DATA_BUFFER_AND_PROG_CONFIRM); |
|
| - | 914 | } |
|
| - | 915 | else /* => hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET */ |
|
| - | 916 | { |
|
| - | 917 | NOR_WRITE((deviceaddress + uwAddress), NOR_CMD_CONFIRM); |
|
| - | 918 | } |
|
| - | 919 | } |
|
| - | 920 | ||
| - | 921 | /* Check the NOR controller state */ |
|
| - | 922 | hnor->State = HAL_NOR_STATE_READY; |
|
| - | 923 | ||
| - | 924 | /* Process unlocked */ |
|
| - | 925 | __HAL_UNLOCK(hnor); |
|
| 654 | } |
926 | } |
| 655 | else /* FSMC_NORSRAM_BANK4 */ |
927 | else |
| 656 | { |
928 | { |
| 657 | deviceaddress = NOR_MEMORY_ADRESS4; |
- | |
| 658 | } |
- | |
| 659 | - | ||
| 660 | /* Update the NOR controller state */ |
- | |
| 661 | hnor->State = HAL_NOR_STATE_BUSY; |
- | |
| 662 | - | ||
| 663 | /* Initialize variables */ |
- | |
| 664 | p_currentaddress = (uint16_t*)((uint32_t)(uwAddress)); |
- | |
| 665 | p_endaddress = p_currentaddress + (uwBufferSize-1U); |
- | |
| 666 | lastloadedaddress = (uint32_t)(uwAddress); |
- | |
| 667 | - | ||
| 668 | /* Issue unlock command sequence */ |
- | |
| 669 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST); |
- | |
| 670 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND); |
- | |
| 671 | - | ||
| 672 | /* Write Buffer Load Command */ |
- | |
| 673 | NOR_WRITE((uint32_t)(p_currentaddress), NOR_CMD_DATA_BUFFER_AND_PROG); |
- | |
| 674 | NOR_WRITE((uint32_t)(p_currentaddress), (uwBufferSize-1U)); |
- | |
| 675 | - | ||
| 676 | /* Load Data into NOR Buffer */ |
- | |
| 677 | while(p_currentaddress <= p_endaddress) |
- | |
| 678 | { |
- | |
| 679 | /* Store last loaded address & data value (for polling) */ |
- | |
| 680 | lastloadedaddress = (uint32_t)p_currentaddress; |
- | |
| 681 | - | ||
| 682 | NOR_WRITE(p_currentaddress, *pData++); |
- | |
| 683 | - | ||
| 684 | p_currentaddress++; |
929 | return HAL_ERROR; |
| 685 | } |
930 | } |
| 686 | 931 | ||
| 687 | NOR_WRITE((uint32_t)(lastloadedaddress), NOR_CMD_DATA_BUFFER_AND_PROG_CONFIRM); |
- | |
| 688 | - | ||
| 689 | /* Check the NOR controller state */ |
- | |
| 690 | hnor->State = HAL_NOR_STATE_READY; |
- | |
| 691 | - | ||
| 692 | /* Process unlocked */ |
- | |
| 693 | __HAL_UNLOCK(hnor); |
- | |
| 694 | - | ||
| 695 | return HAL_OK; |
932 | return status; |
| 696 | 933 | ||
| 697 | } |
934 | } |
| 698 | 935 | ||
| 699 | /** |
936 | /** |
| 700 | * @brief Erase the specified block of the NOR memory |
937 | * @brief Erase the specified block of the NOR memory |
| 701 | * @param hnor: pointer to a NOR_HandleTypeDef structure that contains |
938 | * @param hnor pointer to a NOR_HandleTypeDef structure that contains |
| 702 | * the configuration information for NOR module. |
939 | * the configuration information for NOR module. |
| 703 | * @param BlockAddress : Block to erase address |
940 | * @param BlockAddress Block to erase address |
| 704 | * @param Address: Device address |
941 | * @param Address Device address |
| 705 | * @retval HAL status |
942 | * @retval HAL status |
| 706 | */ |
943 | */ |
| 707 | HAL_StatusTypeDef HAL_NOR_Erase_Block(NOR_HandleTypeDef *hnor, uint32_t BlockAddress, uint32_t Address) |
944 | HAL_StatusTypeDef HAL_NOR_Erase_Block(NOR_HandleTypeDef *hnor, uint32_t BlockAddress, uint32_t Address) |
| 708 | { |
945 | { |
| 709 | uint32_t deviceaddress = 0U; |
946 | uint32_t deviceaddress; |
| - | 947 | HAL_StatusTypeDef status = HAL_OK; |
|
| 710 | 948 | ||
| 711 | /* Process Locked */ |
- | |
| 712 | __HAL_LOCK(hnor); |
- | |
| 713 | - | ||
| 714 | /* Check the NOR controller state */ |
949 | /* Check the NOR controller state */ |
| 715 | if(hnor->State == HAL_NOR_STATE_BUSY) |
950 | if (hnor->State == HAL_NOR_STATE_BUSY) |
| 716 | { |
951 | { |
| 717 | return HAL_BUSY; |
952 | return HAL_BUSY; |
| 718 | } |
953 | } |
| 719 | - | ||
| 720 | /* Select the NOR device address */ |
- | |
| 721 | if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1) |
954 | else if (hnor->State == HAL_NOR_STATE_READY) |
| 722 | { |
955 | { |
| - | 956 | /* Process Locked */ |
|
| - | 957 | __HAL_LOCK(hnor); |
|
| - | 958 | ||
| - | 959 | /* Update the NOR controller state */ |
|
| - | 960 | hnor->State = HAL_NOR_STATE_BUSY; |
|
| - | 961 | ||
| - | 962 | /* Select the NOR device address */ |
|
| - | 963 | if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1) |
|
| - | 964 | { |
|
| 723 | deviceaddress = NOR_MEMORY_ADRESS1; |
965 | deviceaddress = NOR_MEMORY_ADRESS1; |
| 724 | } |
966 | } |
| 725 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2) |
967 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2) |
| 726 | { |
968 | { |
| 727 | deviceaddress = NOR_MEMORY_ADRESS2; |
969 | deviceaddress = NOR_MEMORY_ADRESS2; |
| - | 970 | } |
|
| - | 971 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3) |
|
| - | 972 | { |
|
| - | 973 | deviceaddress = NOR_MEMORY_ADRESS3; |
|
| - | 974 | } |
|
| - | 975 | else /* FSMC_NORSRAM_BANK4 */ |
|
| - | 976 | { |
|
| - | 977 | deviceaddress = NOR_MEMORY_ADRESS4; |
|
| - | 978 | } |
|
| - | 979 | ||
| - | 980 | /* Send block erase command sequence */ |
|
| - | 981 | if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET) |
|
| - | 982 | { |
|
| - | 983 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST); |
|
| - | 984 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND); |
|
| - | 985 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), |
|
| - | 986 | NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD); |
|
| - | 987 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FOURTH), |
|
| - | 988 | NOR_CMD_DATA_CHIP_BLOCK_ERASE_FOURTH); |
|
| - | 989 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIFTH), |
|
| - | 990 | NOR_CMD_DATA_CHIP_BLOCK_ERASE_FIFTH); |
|
| - | 991 | NOR_WRITE((uint32_t)(BlockAddress + Address), NOR_CMD_DATA_BLOCK_ERASE); |
|
| - | 992 | } |
|
| - | 993 | else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET) |
|
| - | 994 | { |
|
| - | 995 | NOR_WRITE((BlockAddress + Address), NOR_CMD_BLOCK_UNLOCK); |
|
| - | 996 | NOR_WRITE((BlockAddress + Address), NOR_CMD_CONFIRM); |
|
| - | 997 | NOR_WRITE((BlockAddress + Address), NOR_CMD_BLOCK_ERASE); |
|
| - | 998 | NOR_WRITE((BlockAddress + Address), NOR_CMD_CONFIRM); |
|
| - | 999 | } |
|
| - | 1000 | else |
|
| - | 1001 | { |
|
| - | 1002 | /* Primary command set not supported by the driver */ |
|
| - | 1003 | status = HAL_ERROR; |
|
| - | 1004 | } |
|
| - | 1005 | ||
| - | 1006 | /* Check the NOR memory status and update the controller state */ |
|
| - | 1007 | hnor->State = HAL_NOR_STATE_READY; |
|
| - | 1008 | ||
| - | 1009 | /* Process unlocked */ |
|
| - | 1010 | __HAL_UNLOCK(hnor); |
|
| 728 | } |
1011 | } |
| 729 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3) |
1012 | else |
| 730 | { |
1013 | { |
| 731 | deviceaddress = NOR_MEMORY_ADRESS3; |
1014 | return HAL_ERROR; |
| 732 | } |
1015 | } |
| 733 | else /* FSMC_NORSRAM_BANK4 */ |
- | |
| 734 | { |
- | |
| 735 | deviceaddress = NOR_MEMORY_ADRESS4; |
- | |
| 736 | } |
- | |
| 737 | - | ||
| 738 | /* Update the NOR controller state */ |
- | |
| 739 | hnor->State = HAL_NOR_STATE_BUSY; |
- | |
| 740 | - | ||
| 741 | /* Send block erase command sequence */ |
- | |
| 742 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST); |
- | |
| 743 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND); |
- | |
| 744 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD); |
- | |
| 745 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FOURTH), NOR_CMD_DATA_CHIP_BLOCK_ERASE_FOURTH); |
- | |
| 746 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIFTH), NOR_CMD_DATA_CHIP_BLOCK_ERASE_FIFTH); |
- | |
| 747 | NOR_WRITE((uint32_t)(BlockAddress + Address), NOR_CMD_DATA_BLOCK_ERASE); |
- | |
| 748 | 1016 | ||
| 749 | /* Check the NOR memory status and update the controller state */ |
- | |
| 750 | hnor->State = HAL_NOR_STATE_READY; |
- | |
| 751 | - | ||
| 752 | /* Process unlocked */ |
- | |
| 753 | __HAL_UNLOCK(hnor); |
- | |
| 754 | - | ||
| 755 | return HAL_OK; |
1017 | return status; |
| 756 | 1018 | ||
| 757 | } |
1019 | } |
| 758 | 1020 | ||
| 759 | /** |
1021 | /** |
| 760 | * @brief Erase the entire NOR chip. |
1022 | * @brief Erase the entire NOR chip. |
| 761 | * @param hnor: pointer to a NOR_HandleTypeDef structure that contains |
1023 | * @param hnor pointer to a NOR_HandleTypeDef structure that contains |
| 762 | * the configuration information for NOR module. |
1024 | * the configuration information for NOR module. |
| 763 | * @param Address : Device address |
1025 | * @param Address Device address |
| 764 | * @retval HAL status |
1026 | * @retval HAL status |
| 765 | */ |
1027 | */ |
| 766 | HAL_StatusTypeDef HAL_NOR_Erase_Chip(NOR_HandleTypeDef *hnor, uint32_t Address) |
1028 | HAL_StatusTypeDef HAL_NOR_Erase_Chip(NOR_HandleTypeDef *hnor, uint32_t Address) |
| 767 | { |
1029 | { |
| - | 1030 | uint32_t deviceaddress; |
|
| 768 | /* Prevent unused argument(s) compilation warning */ |
1031 | HAL_StatusTypeDef status = HAL_OK; |
| 769 | UNUSED(Address); |
1032 | UNUSED(Address); |
| 770 | 1033 | ||
| 771 | uint32_t deviceaddress = 0U; |
- | |
| 772 | - | ||
| 773 | /* Process Locked */ |
- | |
| 774 | __HAL_LOCK(hnor); |
- | |
| 775 | - | ||
| 776 | /* Check the NOR controller state */ |
1034 | /* Check the NOR controller state */ |
| 777 | if(hnor->State == HAL_NOR_STATE_BUSY) |
1035 | if (hnor->State == HAL_NOR_STATE_BUSY) |
| 778 | { |
1036 | { |
| 779 | return HAL_BUSY; |
1037 | return HAL_BUSY; |
| 780 | } |
1038 | } |
| 781 | - | ||
| 782 | /* Select the NOR device address */ |
- | |
| 783 | if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1) |
- | |
| 784 | { |
- | |
| 785 | deviceaddress = NOR_MEMORY_ADRESS1; |
- | |
| 786 | } |
- | |
| 787 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2) |
1039 | else if (hnor->State == HAL_NOR_STATE_READY) |
| 788 | { |
1040 | { |
| - | 1041 | /* Process Locked */ |
|
| - | 1042 | __HAL_LOCK(hnor); |
|
| - | 1043 | ||
| - | 1044 | /* Update the NOR controller state */ |
|
| - | 1045 | hnor->State = HAL_NOR_STATE_BUSY; |
|
| - | 1046 | ||
| - | 1047 | /* Select the NOR device address */ |
|
| - | 1048 | if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1) |
|
| - | 1049 | { |
|
| - | 1050 | deviceaddress = NOR_MEMORY_ADRESS1; |
|
| - | 1051 | } |
|
| - | 1052 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2) |
|
| - | 1053 | { |
|
| 789 | deviceaddress = NOR_MEMORY_ADRESS2; |
1054 | deviceaddress = NOR_MEMORY_ADRESS2; |
| 790 | } |
1055 | } |
| 791 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3) |
1056 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3) |
| 792 | { |
1057 | { |
| 793 | deviceaddress = NOR_MEMORY_ADRESS3; |
1058 | deviceaddress = NOR_MEMORY_ADRESS3; |
| - | 1059 | } |
|
| - | 1060 | else /* FSMC_NORSRAM_BANK4 */ |
|
| - | 1061 | { |
|
| - | 1062 | deviceaddress = NOR_MEMORY_ADRESS4; |
|
| - | 1063 | } |
|
| - | 1064 | ||
| - | 1065 | /* Send NOR chip erase command sequence */ |
|
| - | 1066 | if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET) |
|
| - | 1067 | { |
|
| - | 1068 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST); |
|
| - | 1069 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND); |
|
| - | 1070 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), |
|
| - | 1071 | NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD); |
|
| - | 1072 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FOURTH), |
|
| - | 1073 | NOR_CMD_DATA_CHIP_BLOCK_ERASE_FOURTH); |
|
| - | 1074 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIFTH), |
|
| - | 1075 | NOR_CMD_DATA_CHIP_BLOCK_ERASE_FIFTH); |
|
| - | 1076 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SIXTH), NOR_CMD_DATA_CHIP_ERASE); |
|
| - | 1077 | } |
|
| - | 1078 | else |
|
| - | 1079 | { |
|
| - | 1080 | /* Primary command set not supported by the driver */ |
|
| - | 1081 | status = HAL_ERROR; |
|
| - | 1082 | } |
|
| - | 1083 | ||
| - | 1084 | /* Check the NOR memory status and update the controller state */ |
|
| - | 1085 | hnor->State = HAL_NOR_STATE_READY; |
|
| - | 1086 | ||
| - | 1087 | /* Process unlocked */ |
|
| - | 1088 | __HAL_UNLOCK(hnor); |
|
| 794 | } |
1089 | } |
| 795 | else /* FSMC_NORSRAM_BANK4 */ |
1090 | else |
| 796 | { |
1091 | { |
| 797 | deviceaddress = NOR_MEMORY_ADRESS4; |
1092 | return HAL_ERROR; |
| 798 | } |
1093 | } |
| 799 | - | ||
| 800 | /* Update the NOR controller state */ |
- | |
| 801 | hnor->State = HAL_NOR_STATE_BUSY; |
- | |
| 802 | - | ||
| 803 | /* Send NOR chip erase command sequence */ |
- | |
| 804 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST); |
- | |
| 805 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND); |
- | |
| 806 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD); |
- | |
| 807 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FOURTH), NOR_CMD_DATA_CHIP_BLOCK_ERASE_FOURTH); |
- | |
| 808 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIFTH), NOR_CMD_DATA_CHIP_BLOCK_ERASE_FIFTH); |
- | |
| 809 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SIXTH), NOR_CMD_DATA_CHIP_ERASE); |
- | |
| 810 | - | ||
| 811 | /* Check the NOR memory status and update the controller state */ |
- | |
| 812 | hnor->State = HAL_NOR_STATE_READY; |
- | |
| 813 | - | ||
| 814 | /* Process unlocked */ |
- | |
| 815 | __HAL_UNLOCK(hnor); |
- | |
| 816 | 1094 | ||
| 817 | return HAL_OK; |
1095 | return status; |
| 818 | } |
1096 | } |
| 819 | 1097 | ||
| 820 | /** |
1098 | /** |
| 821 | * @brief Read NOR flash CFI IDs |
1099 | * @brief Read NOR flash CFI IDs |
| 822 | * @param hnor: pointer to a NOR_HandleTypeDef structure that contains |
1100 | * @param hnor pointer to a NOR_HandleTypeDef structure that contains |
| 823 | * the configuration information for NOR module. |
1101 | * the configuration information for NOR module. |
| 824 | * @param pNOR_CFI : pointer to NOR CFI IDs structure |
1102 | * @param pNOR_CFI pointer to NOR CFI IDs structure |
| 825 | * @retval HAL status |
1103 | * @retval HAL status |
| 826 | */ |
1104 | */ |
| 827 | HAL_StatusTypeDef HAL_NOR_Read_CFI(NOR_HandleTypeDef *hnor, NOR_CFITypeDef *pNOR_CFI) |
1105 | HAL_StatusTypeDef HAL_NOR_Read_CFI(NOR_HandleTypeDef *hnor, NOR_CFITypeDef *pNOR_CFI) |
| 828 | { |
1106 | { |
| 829 | uint32_t deviceaddress = 0U; |
1107 | uint32_t deviceaddress; |
| 830 | - | ||
| 831 | /* Process Locked */ |
- | |
| 832 | __HAL_LOCK(hnor); |
1108 | HAL_NOR_StateTypeDef state; |
| 833 | 1109 | ||
| 834 | /* Check the NOR controller state */ |
1110 | /* Check the NOR controller state */ |
| - | 1111 | state = hnor->State; |
|
| 835 | if(hnor->State == HAL_NOR_STATE_BUSY) |
1112 | if (state == HAL_NOR_STATE_BUSY) |
| 836 | { |
1113 | { |
| 837 | return HAL_BUSY; |
1114 | return HAL_BUSY; |
| 838 | } |
1115 | } |
| 839 | - | ||
| 840 | /* Select the NOR device address */ |
- | |
| 841 | if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1) |
1116 | else if ((state == HAL_NOR_STATE_READY) || (state == HAL_NOR_STATE_PROTECTED)) |
| 842 | { |
1117 | { |
| - | 1118 | /* Process Locked */ |
|
| - | 1119 | __HAL_LOCK(hnor); |
|
| - | 1120 | ||
| - | 1121 | /* Update the NOR controller state */ |
|
| - | 1122 | hnor->State = HAL_NOR_STATE_BUSY; |
|
| - | 1123 | ||
| - | 1124 | /* Select the NOR device address */ |
|
| - | 1125 | if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1) |
|
| - | 1126 | { |
|
| 843 | deviceaddress = NOR_MEMORY_ADRESS1; |
1127 | deviceaddress = NOR_MEMORY_ADRESS1; |
| - | 1128 | } |
|
| - | 1129 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2) |
|
| - | 1130 | { |
|
| - | 1131 | deviceaddress = NOR_MEMORY_ADRESS2; |
|
| - | 1132 | } |
|
| - | 1133 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3) |
|
| - | 1134 | { |
|
| - | 1135 | deviceaddress = NOR_MEMORY_ADRESS3; |
|
| - | 1136 | } |
|
| - | 1137 | else /* FSMC_NORSRAM_BANK4 */ |
|
| - | 1138 | { |
|
| - | 1139 | deviceaddress = NOR_MEMORY_ADRESS4; |
|
| - | 1140 | } |
|
| - | 1141 | ||
| - | 1142 | /* Send read CFI query command */ |
|
| - | 1143 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_CFI), NOR_CMD_DATA_CFI); |
|
| - | 1144 | ||
| - | 1145 | /* read the NOR CFI information */ |
|
| - | 1146 | pNOR_CFI->CFI_1 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI1_ADDRESS); |
|
| - | 1147 | pNOR_CFI->CFI_2 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI2_ADDRESS); |
|
| - | 1148 | pNOR_CFI->CFI_3 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI3_ADDRESS); |
|
| - | 1149 | pNOR_CFI->CFI_4 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI4_ADDRESS); |
|
| - | 1150 | ||
| - | 1151 | /* Check the NOR controller state */ |
|
| - | 1152 | hnor->State = state; |
|
| - | 1153 | ||
| - | 1154 | /* Process unlocked */ |
|
| - | 1155 | __HAL_UNLOCK(hnor); |
|
| 844 | } |
1156 | } |
| 845 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2) |
1157 | else |
| 846 | { |
1158 | { |
| 847 | deviceaddress = NOR_MEMORY_ADRESS2; |
1159 | return HAL_ERROR; |
| 848 | } |
1160 | } |
| - | 1161 | ||
| - | 1162 | return HAL_OK; |
|
| - | 1163 | } |
|
| - | 1164 | ||
| - | 1165 | #if (USE_HAL_NOR_REGISTER_CALLBACKS == 1) |
|
| - | 1166 | /** |
|
| 849 | else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3) |
1167 | * @brief Register a User NOR Callback |
| - | 1168 | * To be used instead of the weak (surcharged) predefined callback |
|
| - | 1169 | * @param hnor : NOR handle |
|
| - | 1170 | * @param CallbackId : ID of the callback to be registered |
|
| - | 1171 | * This parameter can be one of the following values: |
|
| - | 1172 | * @arg @ref HAL_NOR_MSP_INIT_CB_ID NOR MspInit callback ID |
|
| - | 1173 | * @arg @ref HAL_NOR_MSP_DEINIT_CB_ID NOR MspDeInit callback ID |
|
| - | 1174 | * @param pCallback : pointer to the Callback function |
|
| - | 1175 | * @retval status |
|
| - | 1176 | */ |
|
| - | 1177 | HAL_StatusTypeDef HAL_NOR_RegisterCallback(NOR_HandleTypeDef *hnor, HAL_NOR_CallbackIDTypeDef CallbackId, |
|
| - | 1178 | pNOR_CallbackTypeDef pCallback) |
|
| - | 1179 | { |
|
| - | 1180 | HAL_StatusTypeDef status = HAL_OK; |
|
| - | 1181 | HAL_NOR_StateTypeDef state; |
|
| - | 1182 | ||
| - | 1183 | if (pCallback == NULL) |
|
| 850 | { |
1184 | { |
| 851 | deviceaddress = NOR_MEMORY_ADRESS3; |
1185 | return HAL_ERROR; |
| 852 | } |
1186 | } |
| - | 1187 | ||
| 853 | else /* FSMC_NORSRAM_BANK4 */ |
1188 | /* Process locked */ |
| - | 1189 | __HAL_LOCK(hnor); |
|
| - | 1190 | ||
| - | 1191 | state = hnor->State; |
|
| - | 1192 | if ((state == HAL_NOR_STATE_READY) || (state == HAL_NOR_STATE_RESET) || (state == HAL_NOR_STATE_PROTECTED)) |
|
| 854 | { |
1193 | { |
| 855 | deviceaddress = NOR_MEMORY_ADRESS4; |
1194 | switch (CallbackId) |
| 856 | } |
1195 | { |
| - | 1196 | case HAL_NOR_MSP_INIT_CB_ID : |
|
| - | 1197 | hnor->MspInitCallback = pCallback; |
|
| - | 1198 | break; |
|
| - | 1199 | case HAL_NOR_MSP_DEINIT_CB_ID : |
|
| - | 1200 | hnor->MspDeInitCallback = pCallback; |
|
| 857 | 1201 | break; |
|
| - | 1202 | default : |
|
| 858 | /* Update the NOR controller state */ |
1203 | /* update return status */ |
| 859 | hnor->State = HAL_NOR_STATE_BUSY; |
1204 | status = HAL_ERROR; |
| - | 1205 | break; |
|
| - | 1206 | } |
|
| - | 1207 | } |
|
| - | 1208 | else |
|
| 860 | 1209 | { |
|
| 861 | /* Send read CFI query command */ |
1210 | /* update return status */ |
| 862 | NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_CFI), NOR_CMD_DATA_CFI); |
1211 | status = HAL_ERROR; |
| - | 1212 | } |
|
| 863 | 1213 | ||
| 864 | /* read the NOR CFI information */ |
1214 | /* Release Lock */ |
| 865 | pNOR_CFI->CFI_1 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI1_ADDRESS); |
1215 | __HAL_UNLOCK(hnor); |
| 866 | pNOR_CFI->CFI_2 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI2_ADDRESS); |
1216 | return status; |
| 867 | pNOR_CFI->CFI_3 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI3_ADDRESS); |
- | |
| 868 | pNOR_CFI->CFI_4 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI4_ADDRESS); |
- | |
| - | 1217 | } |
|
| 869 | 1218 | ||
| - | 1219 | /** |
|
| - | 1220 | * @brief Unregister a User NOR Callback |
|
| - | 1221 | * NOR Callback is redirected to the weak (surcharged) predefined callback |
|
| - | 1222 | * @param hnor : NOR handle |
|
| - | 1223 | * @param CallbackId : ID of the callback to be unregistered |
|
| - | 1224 | * This parameter can be one of the following values: |
|
| - | 1225 | * @arg @ref HAL_NOR_MSP_INIT_CB_ID NOR MspInit callback ID |
|
| - | 1226 | * @arg @ref HAL_NOR_MSP_DEINIT_CB_ID NOR MspDeInit callback ID |
|
| - | 1227 | * @retval status |
|
| - | 1228 | */ |
|
| - | 1229 | HAL_StatusTypeDef HAL_NOR_UnRegisterCallback(NOR_HandleTypeDef *hnor, HAL_NOR_CallbackIDTypeDef CallbackId) |
|
| - | 1230 | { |
|
| - | 1231 | HAL_StatusTypeDef status = HAL_OK; |
|
| - | 1232 | HAL_NOR_StateTypeDef state; |
|
| - | 1233 | ||
| - | 1234 | /* Process locked */ |
|
| - | 1235 | __HAL_LOCK(hnor); |
|
| - | 1236 | ||
| - | 1237 | state = hnor->State; |
|
| - | 1238 | if ((state == HAL_NOR_STATE_READY) || (state == HAL_NOR_STATE_RESET) || (state == HAL_NOR_STATE_PROTECTED)) |
|
| - | 1239 | { |
|
| - | 1240 | switch (CallbackId) |
|
| - | 1241 | { |
|
| - | 1242 | case HAL_NOR_MSP_INIT_CB_ID : |
|
| - | 1243 | hnor->MspInitCallback = HAL_NOR_MspInit; |
|
| - | 1244 | break; |
|
| - | 1245 | case HAL_NOR_MSP_DEINIT_CB_ID : |
|
| - | 1246 | hnor->MspDeInitCallback = HAL_NOR_MspDeInit; |
|
| - | 1247 | break; |
|
| - | 1248 | default : |
|
| 870 | /* Check the NOR controller state */ |
1249 | /* update return status */ |
| 871 | hnor->State = HAL_NOR_STATE_READY; |
1250 | status = HAL_ERROR; |
| - | 1251 | break; |
|
| - | 1252 | } |
|
| - | 1253 | } |
|
| - | 1254 | else |
|
| - | 1255 | { |
|
| - | 1256 | /* update return status */ |
|
| - | 1257 | status = HAL_ERROR; |
|
| 872 | 1258 | } |
|
| - | 1259 | ||
| 873 | /* Process unlocked */ |
1260 | /* Release Lock */ |
| 874 | __HAL_UNLOCK(hnor); |
1261 | __HAL_UNLOCK(hnor); |
| 875 | - | ||
| 876 | return HAL_OK; |
1262 | return status; |
| 877 | } |
1263 | } |
| - | 1264 | #endif /* (USE_HAL_NOR_REGISTER_CALLBACKS) */ |
|
| 878 | 1265 | ||
| 879 | /** |
1266 | /** |
| 880 | * @} |
1267 | * @} |
| 881 | */ |
1268 | */ |
| 882 | 1269 | ||
| 883 | /** @defgroup NOR_Exported_Functions_Group3 Control functions |
1270 | /** @defgroup NOR_Exported_Functions_Group3 NOR Control functions |
| 884 | * @brief management functions |
1271 | * @brief management functions |
| 885 | * |
1272 | * |
| 886 | @verbatim |
1273 | @verbatim |
| 887 | ============================================================================== |
1274 | ============================================================================== |
| 888 | ##### NOR Control functions ##### |
1275 | ##### NOR Control functions ##### |
| 889 | ============================================================================== |
1276 | ============================================================================== |
| 890 | [..] |
1277 | [..] |
| 891 | This subsection provides a set of functions allowing to control dynamically |
1278 | This subsection provides a set of functions allowing to control dynamically |
| 892 | the NOR interface. |
1279 | the NOR interface. |
| 893 | 1280 | ||
| 894 | @endverbatim |
1281 | @endverbatim |
| 895 | * @{ |
1282 | * @{ |
| 896 | */ |
1283 | */ |
| 897 | 1284 | ||
| 898 | /** |
1285 | /** |
| 899 | * @brief Enables dynamically NOR write operation. |
1286 | * @brief Enables dynamically NOR write operation. |
| 900 | * @param hnor: pointer to a NOR_HandleTypeDef structure that contains |
1287 | * @param hnor pointer to a NOR_HandleTypeDef structure that contains |
| 901 | * the configuration information for NOR module. |
1288 | * the configuration information for NOR module. |
| 902 | * @retval HAL status |
1289 | * @retval HAL status |
| 903 | */ |
1290 | */ |
| 904 | HAL_StatusTypeDef HAL_NOR_WriteOperation_Enable(NOR_HandleTypeDef *hnor) |
1291 | HAL_StatusTypeDef HAL_NOR_WriteOperation_Enable(NOR_HandleTypeDef *hnor) |
| 905 | { |
1292 | { |
| - | 1293 | /* Check the NOR controller state */ |
|
| - | 1294 | if (hnor->State == HAL_NOR_STATE_PROTECTED) |
|
| - | 1295 | { |
|
| 906 | /* Process Locked */ |
1296 | /* Process Locked */ |
| 907 | __HAL_LOCK(hnor); |
1297 | __HAL_LOCK(hnor); |
| 908 | 1298 | ||
| - | 1299 | /* Update the NOR controller state */ |
|
| - | 1300 | hnor->State = HAL_NOR_STATE_BUSY; |
|
| - | 1301 | ||
| 909 | /* Enable write operation */ |
1302 | /* Enable write operation */ |
| 910 | FSMC_NORSRAM_WriteOperation_Enable(hnor->Instance, hnor->Init.NSBank); |
1303 | (void)FSMC_NORSRAM_WriteOperation_Enable(hnor->Instance, hnor->Init.NSBank); |
| 911 | 1304 | ||
| 912 | /* Update the NOR controller state */ |
1305 | /* Update the NOR controller state */ |
| 913 | hnor->State = HAL_NOR_STATE_READY; |
1306 | hnor->State = HAL_NOR_STATE_READY; |
| 914 | 1307 | ||
| 915 | /* Process unlocked */ |
1308 | /* Process unlocked */ |
| 916 | __HAL_UNLOCK(hnor); |
1309 | __HAL_UNLOCK(hnor); |
| - | 1310 | } |
|
| - | 1311 | else |
|
| - | 1312 | { |
|
| - | 1313 | return HAL_ERROR; |
|
| 917 | 1314 | } |
|
| - | 1315 | ||
| 918 | return HAL_OK; |
1316 | return HAL_OK; |
| 919 | } |
1317 | } |
| 920 | 1318 | ||
| 921 | /** |
1319 | /** |
| 922 | * @brief Disables dynamically NOR write operation. |
1320 | * @brief Disables dynamically NOR write operation. |
| 923 | * @param hnor: pointer to a NOR_HandleTypeDef structure that contains |
1321 | * @param hnor pointer to a NOR_HandleTypeDef structure that contains |
| 924 | * the configuration information for NOR module. |
1322 | * the configuration information for NOR module. |
| 925 | * @retval HAL status |
1323 | * @retval HAL status |
| 926 | */ |
1324 | */ |
| 927 | HAL_StatusTypeDef HAL_NOR_WriteOperation_Disable(NOR_HandleTypeDef *hnor) |
1325 | HAL_StatusTypeDef HAL_NOR_WriteOperation_Disable(NOR_HandleTypeDef *hnor) |
| 928 | { |
1326 | { |
| - | 1327 | /* Check the NOR controller state */ |
|
| - | 1328 | if (hnor->State == HAL_NOR_STATE_READY) |
|
| - | 1329 | { |
|
| 929 | /* Process Locked */ |
1330 | /* Process Locked */ |
| 930 | __HAL_LOCK(hnor); |
1331 | __HAL_LOCK(hnor); |
| - | 1332 | ||
| - | 1333 | /* Update the NOR controller state */ |
|
| - | 1334 | hnor->State = HAL_NOR_STATE_BUSY; |
|
| - | 1335 | ||
| - | 1336 | /* Disable write operation */ |
|
| - | 1337 | (void)FSMC_NORSRAM_WriteOperation_Disable(hnor->Instance, hnor->Init.NSBank); |
|
| - | 1338 | ||
| - | 1339 | /* Update the NOR controller state */ |
|
| - | 1340 | hnor->State = HAL_NOR_STATE_PROTECTED; |
|
| - | 1341 | ||
| - | 1342 | /* Process unlocked */ |
|
| - | 1343 | __HAL_UNLOCK(hnor); |
|
| - | 1344 | } |
|
| - | 1345 | else |
|
| - | 1346 | { |
|
| - | 1347 | return HAL_ERROR; |
|
| - | 1348 | } |
|
| 931 | 1349 | ||
| 932 | /* Update the SRAM controller state */ |
- | |
| 933 | hnor->State = HAL_NOR_STATE_BUSY; |
- | |
| 934 | - | ||
| 935 | /* Disable write operation */ |
- | |
| 936 | FSMC_NORSRAM_WriteOperation_Disable(hnor->Instance, hnor->Init.NSBank); |
- | |
| 937 | - | ||
| 938 | /* Update the NOR controller state */ |
- | |
| 939 | hnor->State = HAL_NOR_STATE_PROTECTED; |
- | |
| 940 | - | ||
| 941 | /* Process unlocked */ |
- | |
| 942 | __HAL_UNLOCK(hnor); |
- | |
| 943 | - | ||
| 944 | return HAL_OK; |
1350 | return HAL_OK; |
| 945 | } |
1351 | } |
| 946 | 1352 | ||
| 947 | /** |
1353 | /** |
| 948 | * @} |
1354 | * @} |
| 949 | */ |
1355 | */ |
| 950 | 1356 | ||
| 951 | /** @defgroup NOR_Exported_Functions_Group4 State functions |
1357 | /** @defgroup NOR_Exported_Functions_Group4 NOR State functions |
| 952 | * @brief Peripheral State functions |
1358 | * @brief Peripheral State functions |
| 953 | * |
1359 | * |
| 954 | @verbatim |
1360 | @verbatim |
| 955 | ============================================================================== |
1361 | ============================================================================== |
| 956 | ##### NOR State functions ##### |
1362 | ##### NOR State functions ##### |
| 957 | ============================================================================== |
1363 | ============================================================================== |
| 958 | [..] |
1364 | [..] |
| 959 | This subsection permits to get in run-time the status of the NOR controller |
1365 | This subsection permits to get in run-time the status of the NOR controller |
| 960 | and the data flow. |
1366 | and the data flow. |
| 961 | 1367 | ||
| 962 | @endverbatim |
1368 | @endverbatim |
| 963 | * @{ |
1369 | * @{ |
| 964 | */ |
1370 | */ |
| 965 | 1371 | ||
| 966 | /** |
1372 | /** |
| 967 | * @brief return the NOR controller state |
1373 | * @brief return the NOR controller state |
| 968 | * @param hnor: pointer to a NOR_HandleTypeDef structure that contains |
1374 | * @param hnor pointer to a NOR_HandleTypeDef structure that contains |
| 969 | * the configuration information for NOR module. |
1375 | * the configuration information for NOR module. |
| 970 | * @retval NOR controller state |
1376 | * @retval NOR controller state |
| 971 | */ |
1377 | */ |
| 972 | HAL_NOR_StateTypeDef HAL_NOR_GetState(NOR_HandleTypeDef *hnor) |
1378 | HAL_NOR_StateTypeDef HAL_NOR_GetState(NOR_HandleTypeDef *hnor) |
| 973 | { |
1379 | { |
| 974 | return hnor->State; |
1380 | return hnor->State; |
| 975 | } |
1381 | } |
| 976 | 1382 | ||
| 977 | /** |
1383 | /** |
| 978 | * @brief Returns the NOR operation status. |
1384 | * @brief Returns the NOR operation status. |
| 979 | * @param hnor: pointer to a NOR_HandleTypeDef structure that contains |
1385 | * @param hnor pointer to a NOR_HandleTypeDef structure that contains |
| 980 | * the configuration information for NOR module. |
1386 | * the configuration information for NOR module. |
| 981 | * @param Address: Device address |
1387 | * @param Address Device address |
| 982 | * @param Timeout: NOR progamming Timeout |
1388 | * @param Timeout NOR programming Timeout |
| 983 | * @retval NOR_Status: The returned value can be: HAL_NOR_STATUS_SUCCESS, HAL_NOR_STATUS_ERROR |
1389 | * @retval NOR_Status The returned value can be: HAL_NOR_STATUS_SUCCESS, HAL_NOR_STATUS_ERROR |
| 984 | * or HAL_NOR_STATUS_TIMEOUT |
1390 | * or HAL_NOR_STATUS_TIMEOUT |
| 985 | */ |
1391 | */ |
| 986 | HAL_NOR_StatusTypeDef HAL_NOR_GetStatus(NOR_HandleTypeDef *hnor, uint32_t Address, uint32_t Timeout) |
1392 | HAL_NOR_StatusTypeDef HAL_NOR_GetStatus(NOR_HandleTypeDef *hnor, uint32_t Address, uint32_t Timeout) |
| 987 | { |
1393 | { |
| 988 | HAL_NOR_StatusTypeDef status = HAL_NOR_STATUS_ONGOING; |
1394 | HAL_NOR_StatusTypeDef status = HAL_NOR_STATUS_ONGOING; |
| - | 1395 | uint16_t tmpsr1; |
|
| 989 | uint16_t tmp_sr1 = 0, tmp_sr2 = 0; |
1396 | uint16_t tmpsr2; |
| 990 | uint32_t tickstart = 0U; |
1397 | uint32_t tickstart; |
| 991 | 1398 | ||
| 992 | /* Poll on NOR memory Ready/Busy signal ------------------------------------*/ |
1399 | /* Poll on NOR memory Ready/Busy signal ------------------------------------*/ |
| 993 | HAL_NOR_MspWait(hnor, Timeout); |
1400 | HAL_NOR_MspWait(hnor, Timeout); |
| - | 1401 | ||
| - | 1402 | /* Get the NOR memory operation status -------------------------------------*/ |
|
| 994 | 1403 | ||
| 995 | /* Get tick */ |
1404 | /* Get tick */ |
| 996 | tickstart = HAL_GetTick(); |
1405 | tickstart = HAL_GetTick(); |
| - | 1406 | ||
| 997 | while((status != HAL_NOR_STATUS_SUCCESS) && (status != HAL_NOR_STATUS_TIMEOUT)) |
1407 | if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET) |
| 998 | { |
1408 | { |
| 999 | /* Check for the Timeout */ |
- | |
| 1000 | if(Timeout != HAL_MAX_DELAY) |
1409 | while ((status != HAL_NOR_STATUS_SUCCESS) && (status != HAL_NOR_STATUS_TIMEOUT)) |
| 1001 | { |
1410 | { |
| - | 1411 | /* Check for the Timeout */ |
|
| 1002 | if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout)) |
1412 | if (Timeout != HAL_MAX_DELAY) |
| 1003 | { |
1413 | { |
| - | 1414 | if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) |
|
| - | 1415 | { |
|
| 1004 | status = HAL_NOR_STATUS_TIMEOUT; |
1416 | status = HAL_NOR_STATUS_TIMEOUT; |
| 1005 | } |
1417 | } |
| 1006 | } |
1418 | } |
| - | 1419 | ||
| - | 1420 | /* Read NOR status register (DQ6 and DQ5) */ |
|
| - | 1421 | tmpsr1 = *(__IO uint16_t *)Address; |
|
| - | 1422 | tmpsr2 = *(__IO uint16_t *)Address; |
|
| 1007 | 1423 | ||
| 1008 | /* Read NOR status register (DQ6 and DQ5) */ |
1424 | /* If DQ6 did not toggle between the two reads then return HAL_NOR_STATUS_SUCCESS */ |
| 1009 | tmp_sr1 = *(__IO uint16_t *)Address; |
1425 | if ((tmpsr1 & NOR_MASK_STATUS_DQ6) == (tmpsr2 & NOR_MASK_STATUS_DQ6)) |
| - | 1426 | { |
|
| 1010 | tmp_sr2 = *(__IO uint16_t *)Address; |
1427 | return HAL_NOR_STATUS_SUCCESS ; |
| - | 1428 | } |
|
| 1011 | 1429 | ||
| - | 1430 | if ((tmpsr1 & NOR_MASK_STATUS_DQ5) == NOR_MASK_STATUS_DQ5) |
|
| - | 1431 | { |
|
| - | 1432 | status = HAL_NOR_STATUS_ONGOING; |
|
| - | 1433 | } |
|
| - | 1434 | ||
| - | 1435 | tmpsr1 = *(__IO uint16_t *)Address; |
|
| - | 1436 | tmpsr2 = *(__IO uint16_t *)Address; |
|
| - | 1437 | ||
| 1012 | /* If DQ6 did not toggle between the two reads then return NOR_Success */ |
1438 | /* If DQ6 did not toggle between the two reads then return HAL_NOR_STATUS_SUCCESS */ |
| 1013 | if((tmp_sr1 & NOR_MASK_STATUS_DQ6) == (tmp_sr2 & NOR_MASK_STATUS_DQ6)) |
1439 | if ((tmpsr1 & NOR_MASK_STATUS_DQ6) == (tmpsr2 & NOR_MASK_STATUS_DQ6)) |
| 1014 | { |
1440 | { |
| 1015 | return HAL_NOR_STATUS_SUCCESS; |
1441 | return HAL_NOR_STATUS_SUCCESS; |
| - | 1442 | } |
|
| - | 1443 | if ((tmpsr1 & NOR_MASK_STATUS_DQ5) == NOR_MASK_STATUS_DQ5) |
|
| - | 1444 | { |
|
| - | 1445 | return HAL_NOR_STATUS_ERROR; |
|
| - | 1446 | } |
|
| 1016 | } |
1447 | } |
| 1017 | 1448 | } |
|
| 1018 | if((tmp_sr1 & NOR_MASK_STATUS_DQ5) != NOR_MASK_STATUS_DQ5) |
1449 | else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET) |
| - | 1450 | { |
|
| - | 1451 | do |
|
| 1019 | { |
1452 | { |
| 1020 | status = HAL_NOR_STATUS_ONGOING; |
1453 | NOR_WRITE(Address, NOR_CMD_READ_STATUS_REG); |
| 1021 | } |
- | |
| 1022 | - | ||
| 1023 | tmp_sr1 = *(__IO uint16_t *)Address; |
- | |
| 1024 | tmp_sr2 = *(__IO uint16_t *)Address; |
1454 | tmpsr2 = *(__IO uint16_t *)(Address); |
| 1025 | 1455 | ||
| - | 1456 | /* Check for the Timeout */ |
|
| - | 1457 | if (Timeout != HAL_MAX_DELAY) |
|
| - | 1458 | { |
|
| 1026 | /* If DQ6 did not toggle between the two reads then return NOR_Success */ |
1459 | if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) |
| - | 1460 | { |
|
| - | 1461 | return HAL_NOR_STATUS_TIMEOUT; |
|
| - | 1462 | } |
|
| - | 1463 | } |
|
| - | 1464 | } while ((tmpsr2 & NOR_MASK_STATUS_DQ7) == 0U); |
|
| - | 1465 | ||
| - | 1466 | NOR_WRITE(Address, NOR_CMD_READ_STATUS_REG); |
|
| - | 1467 | tmpsr1 = *(__IO uint16_t *)(Address); |
|
| 1027 | if((tmp_sr1 & NOR_MASK_STATUS_DQ6) == (tmp_sr2 & NOR_MASK_STATUS_DQ6)) |
1468 | if ((tmpsr1 & (NOR_MASK_STATUS_DQ5 | NOR_MASK_STATUS_DQ4)) != 0U) |
| 1028 | { |
1469 | { |
| - | 1470 | /* Clear the Status Register */ |
|
| - | 1471 | NOR_WRITE(Address, NOR_CMD_READ_STATUS_REG); |
|
| 1029 | return HAL_NOR_STATUS_SUCCESS; |
1472 | status = HAL_NOR_STATUS_ERROR; |
| 1030 | } |
1473 | } |
| 1031 | else if((tmp_sr1 & NOR_MASK_STATUS_DQ5) == NOR_MASK_STATUS_DQ5) |
1474 | else |
| 1032 | { |
1475 | { |
| 1033 | return HAL_NOR_STATUS_ERROR; |
1476 | status = HAL_NOR_STATUS_SUCCESS; |
| 1034 | } |
1477 | } |
| - | 1478 | } |
|
| - | 1479 | else |
|
| - | 1480 | { |
|
| - | 1481 | /* Primary command set not supported by the driver */ |
|
| - | 1482 | status = HAL_NOR_STATUS_ERROR; |
|
| 1035 | } |
1483 | } |
| 1036 | 1484 | ||
| 1037 | /* Return the operation status */ |
1485 | /* Return the operation status */ |
| 1038 | return status; |
1486 | return status; |
| 1039 | } |
1487 | } |
| Line 1043... | Line 1491... | ||
| 1043 | */ |
1491 | */ |
| 1044 | 1492 | ||
| 1045 | /** |
1493 | /** |
| 1046 | * @} |
1494 | * @} |
| 1047 | */ |
1495 | */ |
| - | 1496 | ||
| 1048 | /** |
1497 | /** |
| 1049 | * @} |
1498 | * @} |
| 1050 | */ |
1499 | */ |
| 1051 | #endif /* STM32F101xE || STM32F103xE || STM32F101xG || STM32F103xG || STM32F100xE */ |
- | |
| - | 1500 | ||
| 1052 | #endif /* HAL_NOR_MODULE_ENABLED */ |
1501 | #endif /* HAL_NOR_MODULE_ENABLED */ |
| 1053 | 1502 | ||
| 1054 | /** |
1503 | /** |
| 1055 | * @} |
1504 | * @} |
| 1056 | */ |
1505 | */ |
| 1057 | 1506 | ||
| - | 1507 | #endif /* FSMC_BANK1 */ |
|
| - | 1508 | ||
| 1058 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
1509 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |