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