stm32f1xx_hal_nor.h 11 KB

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