Subversion Repositories DashDisplay

Rev

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

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