1 /**
2   ******************************************************************************
3   * @file    stm32f4xx_hal_nor.h
4   * @author  MCD Application Team
5   * @brief   Header file of NOR HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
10   * All rights reserved.</center></h2>
11   *
12   * This software component is licensed by ST under BSD 3-Clause license,
13   * the "License"; You may not use this file except in compliance with the
14   * License. You may obtain a copy of the License at:
15   *                        opensource.org/licenses/BSD-3-Clause
16   *
17   ******************************************************************************
18   */
19 
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef __STM32F4xx_HAL_NOR_H
22 #define __STM32F4xx_HAL_NOR_H
23 
24 #ifdef __cplusplus
25  extern "C" {
26 #endif
27 
28 /* Includes ------------------------------------------------------------------*/
29 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F412Zx) ||\
30     defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F413xx) || defined(STM32F423xx)
31   #include "stm32f4xx_ll_fsmc.h"
32 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F413xx || STM32F423xx */
33 
34 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
35     defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
36   #include "stm32f4xx_ll_fmc.h"
37 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
38 
39 /** @addtogroup STM32F4xx_HAL_Driver
40   * @{
41   */
42 
43 /** @addtogroup NOR
44   * @{
45   */
46 
47 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\
48     defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
49     defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) ||\
50     defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F413xx) || defined(STM32F423xx)
51 
52 /* Exported typedef ----------------------------------------------------------*/
53 /** @defgroup NOR_Exported_Types NOR Exported Types
54   * @{
55   */
56 
57 /**
58   * @brief  HAL SRAM State structures definition
59   */
60 typedef enum
61 {
62   HAL_NOR_STATE_RESET             = 0x00U,  /*!< NOR not yet initialized or disabled  */
63   HAL_NOR_STATE_READY             = 0x01U,  /*!< NOR initialized and ready for use    */
64   HAL_NOR_STATE_BUSY              = 0x02U,  /*!< NOR internal processing is ongoing   */
65   HAL_NOR_STATE_ERROR             = 0x03U,  /*!< NOR error state                      */
66   HAL_NOR_STATE_PROTECTED         = 0x04U   /*!< NOR NORSRAM device write protected   */
67 }HAL_NOR_StateTypeDef;
68 
69 /**
70   * @brief  FMC NOR Status typedef
71   */
72 typedef enum
73 {
74   HAL_NOR_STATUS_SUCCESS  = 0U,
75   HAL_NOR_STATUS_ONGOING,
76   HAL_NOR_STATUS_ERROR,
77   HAL_NOR_STATUS_TIMEOUT
78 }HAL_NOR_StatusTypeDef;
79 
80 /**
81   * @brief  FMC NOR ID typedef
82   */
83 typedef struct
84 {
85   uint16_t Manufacturer_Code;  /*!< Defines the device's manufacturer code used to identify the memory       */
86 
87   uint16_t Device_Code1;
88 
89   uint16_t Device_Code2;
90 
91   uint16_t Device_Code3;       /*!< Defines the device's codes used to identify the memory.
92                                     These codes can be accessed by performing read operations with specific
93                                     control signals and addresses set.They can also be accessed by issuing
94                                     an Auto Select command                                                   */
95 }NOR_IDTypeDef;
96 
97 /**
98   * @brief  FMC NOR CFI typedef
99   */
100 typedef struct
101 {
102   /*!< Defines the information stored in the memory's Common flash interface
103        which contains a description of various electrical and timing parameters,
104        density information and functions supported by the memory                   */
105 
106   uint16_t CFI_1;
107 
108   uint16_t CFI_2;
109 
110   uint16_t CFI_3;
111 
112   uint16_t CFI_4;
113 }NOR_CFITypeDef;
114 
115 /**
116   * @brief  NOR handle Structure definition
117   */
118 #if (USE_HAL_NOR_REGISTER_CALLBACKS == 1)
119 typedef struct __NOR_HandleTypeDef
120 #else
121 typedef struct
122 #endif /* USE_HAL_NOR_REGISTER_CALLBACKS  */
123 
124 {
125   FMC_NORSRAM_TypeDef           *Instance;    /*!< Register base address                        */
126 
127   FMC_NORSRAM_EXTENDED_TypeDef  *Extended;    /*!< Extended mode register base address          */
128 
129   FMC_NORSRAM_InitTypeDef       Init;         /*!< NOR device control configuration parameters  */
130 
131   HAL_LockTypeDef               Lock;         /*!< NOR locking object                           */
132 
133   __IO HAL_NOR_StateTypeDef     State;        /*!< NOR device access state                      */
134 
135 #if (USE_HAL_NOR_REGISTER_CALLBACKS == 1)
136   void  (* MspInitCallback)        ( struct __NOR_HandleTypeDef * hnor);    /*!< NOR Msp Init callback              */
137   void  (* MspDeInitCallback)      ( struct __NOR_HandleTypeDef * hnor);    /*!< NOR Msp DeInit callback            */
138 #endif
139 } NOR_HandleTypeDef;
140 
141 #if (USE_HAL_NOR_REGISTER_CALLBACKS == 1)
142 /**
143   * @brief  HAL NOR Callback ID enumeration definition
144   */
145 typedef enum
146 {
147   HAL_NOR_MSP_INIT_CB_ID       = 0x00U,  /*!< NOR MspInit Callback ID          */
148   HAL_NOR_MSP_DEINIT_CB_ID     = 0x01U   /*!< NOR MspDeInit Callback ID        */
149 }HAL_NOR_CallbackIDTypeDef;
150 
151 /**
152   * @brief  HAL NOR Callback pointer definition
153   */
154 typedef void (*pNOR_CallbackTypeDef)(NOR_HandleTypeDef *hnor);
155 #endif
156 /**
157   * @}
158   */
159 
160 /* Exported constants --------------------------------------------------------*/
161 /* Exported macros ------------------------------------------------------------*/
162 /** @defgroup NOR_Exported_Macros NOR Exported Macros
163   * @{
164   */
165 /** @brief Reset NOR handle state
166   * @param  __HANDLE__ specifies the NOR handle.
167   * @retval None
168   */
169 #if (USE_HAL_NOR_REGISTER_CALLBACKS == 1)
170 #define __HAL_NOR_RESET_HANDLE_STATE(__HANDLE__)          do {                                             \
171                                                                (__HANDLE__)->State = HAL_NOR_STATE_RESET;  \
172                                                                (__HANDLE__)->MspInitCallback = NULL;       \
173                                                                (__HANDLE__)->MspDeInitCallback = NULL;     \
174                                                              } while(0)
175 #else
176 #define __HAL_NOR_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_NOR_STATE_RESET)
177 #endif
178 /**
179   * @}
180   */
181 
182 /* Exported functions --------------------------------------------------------*/
183 /** @addtogroup NOR_Exported_Functions
184  *  @{
185  */
186 
187 /** @addtogroup NOR_Exported_Functions_Group1
188  *  @{
189  */
190 /* Initialization/de-initialization functions  ********************************/
191 HAL_StatusTypeDef HAL_NOR_Init(NOR_HandleTypeDef *hnor, FMC_NORSRAM_TimingTypeDef *Timing, FMC_NORSRAM_TimingTypeDef *ExtTiming);
192 HAL_StatusTypeDef HAL_NOR_DeInit(NOR_HandleTypeDef *hnor);
193 void HAL_NOR_MspInit(NOR_HandleTypeDef *hnor);
194 void HAL_NOR_MspDeInit(NOR_HandleTypeDef *hnor);
195 void HAL_NOR_MspWait(NOR_HandleTypeDef *hnor, uint32_t Timeout);
196 /**
197   * @}
198   */
199 
200 /** @addtogroup NOR_Exported_Functions_Group2
201  *  @{
202  */
203 /* I/O operation functions  ***************************************************/
204 HAL_StatusTypeDef HAL_NOR_Read_ID(NOR_HandleTypeDef *hnor, NOR_IDTypeDef *pNOR_ID);
205 HAL_StatusTypeDef HAL_NOR_ReturnToReadMode(NOR_HandleTypeDef *hnor);
206 HAL_StatusTypeDef HAL_NOR_Read(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData);
207 HAL_StatusTypeDef HAL_NOR_Program(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData);
208 
209 HAL_StatusTypeDef HAL_NOR_ReadBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize);
210 HAL_StatusTypeDef HAL_NOR_ProgramBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize);
211 
212 HAL_StatusTypeDef HAL_NOR_Erase_Block(NOR_HandleTypeDef *hnor, uint32_t BlockAddress, uint32_t Address);
213 HAL_StatusTypeDef HAL_NOR_Erase_Chip(NOR_HandleTypeDef *hnor, uint32_t Address);
214 HAL_StatusTypeDef HAL_NOR_Read_CFI(NOR_HandleTypeDef *hnor, NOR_CFITypeDef *pNOR_CFI);
215 
216 #if (USE_HAL_NOR_REGISTER_CALLBACKS == 1)
217 /* NOR callback registering/unregistering */
218 HAL_StatusTypeDef HAL_NOR_RegisterCallback(NOR_HandleTypeDef *hnor, HAL_NOR_CallbackIDTypeDef CallbackId, pNOR_CallbackTypeDef pCallback);
219 HAL_StatusTypeDef HAL_NOR_UnRegisterCallback(NOR_HandleTypeDef *hnor, HAL_NOR_CallbackIDTypeDef CallbackId);
220 #endif
221 /**
222   * @}
223   */
224 
225 /** @addtogroup NOR_Exported_Functions_Group3
226  *  @{
227  */
228 /* NOR Control functions  *****************************************************/
229 HAL_StatusTypeDef HAL_NOR_WriteOperation_Enable(NOR_HandleTypeDef *hnor);
230 HAL_StatusTypeDef HAL_NOR_WriteOperation_Disable(NOR_HandleTypeDef *hnor);
231 /**
232   * @}
233   */
234 
235 /** @addtogroup NOR_Exported_Functions_Group4
236  *  @{
237  */
238 /* NOR State functions ********************************************************/
239 HAL_NOR_StateTypeDef  HAL_NOR_GetState(NOR_HandleTypeDef *hnor);
240 HAL_NOR_StatusTypeDef HAL_NOR_GetStatus(NOR_HandleTypeDef *hnor, uint32_t Address, uint32_t Timeout);
241 /**
242   * @}
243   */
244 
245 /**
246   * @}
247   */
248 
249 /* Private types -------------------------------------------------------------*/
250 /* Private variables ---------------------------------------------------------*/
251 /* Private constants ---------------------------------------------------------*/
252 /** @defgroup NOR_Private_Constants NOR Private Constants
253   * @{
254   */
255 /* NOR device IDs addresses */
256 #define MC_ADDRESS               ((uint16_t)0x0000)
257 #define DEVICE_CODE1_ADDR        ((uint16_t)0x0001)
258 #define DEVICE_CODE2_ADDR        ((uint16_t)0x000E)
259 #define DEVICE_CODE3_ADDR        ((uint16_t)0x000F)
260 
261 /* NOR CFI IDs addresses */
262 #define CFI1_ADDRESS             ((uint16_t)0x0061)
263 #define CFI2_ADDRESS             ((uint16_t)0x0062)
264 #define CFI3_ADDRESS             ((uint16_t)0x0063)
265 #define CFI4_ADDRESS             ((uint16_t)0x0064)
266 
267 /* NOR operation wait timeout */
268 #define NOR_TMEOUT               ((uint16_t)0xFFFF)
269 
270 /* NOR memory data width */
271 #define NOR_MEMORY_8B            ((uint8_t)0x00)
272 #define NOR_MEMORY_16B           ((uint8_t)0x01)
273 
274 /* NOR memory device read/write start address */
275 #define NOR_MEMORY_ADRESS1       0x60000000U
276 #define NOR_MEMORY_ADRESS2       0x64000000U
277 #define NOR_MEMORY_ADRESS3       0x68000000U
278 #define NOR_MEMORY_ADRESS4       0x6C000000U
279 /**
280   * @}
281   */
282 
283 /* Private macros ------------------------------------------------------------*/
284 /** @defgroup NOR_Private_Macros NOR Private Macros
285   * @{
286   */
287 /**
288   * @brief  NOR memory address shifting.
289   * @param  __NOR_ADDRESS__ NOR base address
290   * @param  NOR_MEMORY_WIDTH NOR memory width
291   * @param  ADDRESS NOR memory address
292   * @retval NOR shifted address value
293   */
294 #define NOR_ADDR_SHIFT(__NOR_ADDRESS__, NOR_MEMORY_WIDTH, ADDRESS)    (uint32_t)(((NOR_MEMORY_WIDTH) == NOR_MEMORY_16B)? ((uint32_t)((__NOR_ADDRESS__) + (2U * (ADDRESS)))):\
295                                                                                  ((uint32_t)((__NOR_ADDRESS__) + (ADDRESS))))
296 
297 /**
298   * @brief  NOR memory write data to specified address.
299   * @param  ADDRESS NOR memory address
300   * @param  DATA Data to write
301   * @retval None
302   */
303 #define NOR_WRITE(ADDRESS, DATA)  (*(__IO uint16_t *)((uint32_t)(ADDRESS)) = (DATA))
304 
305 /**
306   * @}
307   */
308 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx ||\
309           STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx ||\
310           STM32F446xx || STM32F469xx || STM32F479xx || STM32F412Zx ||\
311           STM32F412Vx || STM32F412Rx || STM32F413xx || STM32F423xx */
312 /**
313   * @}
314   */
315 
316 /**
317   * @}
318   */
319 
320 #ifdef __cplusplus
321 }
322 #endif
323 
324 #endif /* __STM32F4xx_HAL_NOR_H */
325 
326 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
327