You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

322 lines
11 KiB

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