Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 

327 rindas
12 KiB

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