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.
 
 
 

300 lines
10 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_nor.h
  4. * @author MCD Application Team
  5. * @version V1.2.2
  6. * @date 14-April-2017
  7. * @brief Header file of NOR HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32F7xx_HAL_NOR_H
  39. #define __STM32F7xx_HAL_NOR_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f7xx_ll_fmc.h"
  45. /** @addtogroup STM32F7xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup NOR
  49. * @{
  50. */
  51. /* Exported typedef ----------------------------------------------------------*/
  52. /** @defgroup NOR_Exported_Types NOR Exported Types
  53. * @{
  54. */
  55. /**
  56. * @brief HAL SRAM State structures definition
  57. */
  58. typedef enum
  59. {
  60. HAL_NOR_STATE_RESET = 0x00U, /*!< NOR not yet initialized or disabled */
  61. HAL_NOR_STATE_READY = 0x01U, /*!< NOR initialized and ready for use */
  62. HAL_NOR_STATE_BUSY = 0x02U, /*!< NOR internal processing is ongoing */
  63. HAL_NOR_STATE_ERROR = 0x03U, /*!< NOR error state */
  64. HAL_NOR_STATE_PROTECTED = 0x04U /*!< NOR NORSRAM device write protected */
  65. }HAL_NOR_StateTypeDef;
  66. /**
  67. * @brief FMC NOR Status typedef
  68. */
  69. typedef enum
  70. {
  71. HAL_NOR_STATUS_SUCCESS = 0U,
  72. HAL_NOR_STATUS_ONGOING,
  73. HAL_NOR_STATUS_ERROR,
  74. HAL_NOR_STATUS_TIMEOUT
  75. }HAL_NOR_StatusTypeDef;
  76. /**
  77. * @brief FMC NOR ID typedef
  78. */
  79. typedef struct
  80. {
  81. uint16_t Manufacturer_Code; /*!< Defines the device's manufacturer code used to identify the memory */
  82. uint16_t Device_Code1;
  83. uint16_t Device_Code2;
  84. uint16_t Device_Code3; /*!< Defines the device's codes used to identify the memory.
  85. These codes can be accessed by performing read operations with specific
  86. control signals and addresses set.They can also be accessed by issuing
  87. an Auto Select command */
  88. }NOR_IDTypeDef;
  89. /**
  90. * @brief FMC NOR CFI typedef
  91. */
  92. typedef struct
  93. {
  94. /*!< Defines the information stored in the memory's Common flash interface
  95. which contains a description of various electrical and timing parameters,
  96. density information and functions supported by the memory */
  97. uint16_t CFI_1;
  98. uint16_t CFI_2;
  99. uint16_t CFI_3;
  100. uint16_t CFI_4;
  101. }NOR_CFITypeDef;
  102. /**
  103. * @brief NOR handle Structure definition
  104. */
  105. typedef struct
  106. {
  107. FMC_NORSRAM_TypeDef *Instance; /*!< Register base address */
  108. FMC_NORSRAM_EXTENDED_TypeDef *Extended; /*!< Extended mode register base address */
  109. FMC_NORSRAM_InitTypeDef Init; /*!< NOR device control configuration parameters */
  110. HAL_LockTypeDef Lock; /*!< NOR locking object */
  111. __IO HAL_NOR_StateTypeDef State; /*!< NOR device access state */
  112. }NOR_HandleTypeDef;
  113. /**
  114. * @}
  115. */
  116. /* Exported constants --------------------------------------------------------*/
  117. /* Exported macro ------------------------------------------------------------*/
  118. /** @defgroup NOR_Exported_Macros NOR Exported Macros
  119. * @{
  120. */
  121. /** @brief Reset NOR handle state
  122. * @param __HANDLE__: specifies the NOR handle.
  123. * @retval None
  124. */
  125. #define __HAL_NOR_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_NOR_STATE_RESET)
  126. /**
  127. * @}
  128. */
  129. /* Exported functions --------------------------------------------------------*/
  130. /** @addtogroup NOR_Exported_Functions NOR Exported Functions
  131. * @{
  132. */
  133. /** @addtogroup NOR_Exported_Functions_Group1 Initialization and de-initialization functions
  134. * @{
  135. */
  136. /* Initialization/de-initialization functions ********************************/
  137. HAL_StatusTypeDef HAL_NOR_Init(NOR_HandleTypeDef *hnor, FMC_NORSRAM_TimingTypeDef *Timing, FMC_NORSRAM_TimingTypeDef *ExtTiming);
  138. HAL_StatusTypeDef HAL_NOR_DeInit(NOR_HandleTypeDef *hnor);
  139. void HAL_NOR_MspInit(NOR_HandleTypeDef *hnor);
  140. void HAL_NOR_MspDeInit(NOR_HandleTypeDef *hnor);
  141. void HAL_NOR_MspWait(NOR_HandleTypeDef *hnor, uint32_t Timeout);
  142. /**
  143. * @}
  144. */
  145. /** @addtogroup NOR_Exported_Functions_Group2 Input and Output functions
  146. * @{
  147. */
  148. /* I/O operation functions ***************************************************/
  149. HAL_StatusTypeDef HAL_NOR_Read_ID(NOR_HandleTypeDef *hnor, NOR_IDTypeDef *pNOR_ID);
  150. HAL_StatusTypeDef HAL_NOR_ReturnToReadMode(NOR_HandleTypeDef *hnor);
  151. HAL_StatusTypeDef HAL_NOR_Read(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData);
  152. HAL_StatusTypeDef HAL_NOR_Program(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData);
  153. HAL_StatusTypeDef HAL_NOR_ReadBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize);
  154. HAL_StatusTypeDef HAL_NOR_ProgramBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize);
  155. HAL_StatusTypeDef HAL_NOR_Erase_Block(NOR_HandleTypeDef *hnor, uint32_t BlockAddress, uint32_t Address);
  156. HAL_StatusTypeDef HAL_NOR_Erase_Chip(NOR_HandleTypeDef *hnor, uint32_t Address);
  157. HAL_StatusTypeDef HAL_NOR_Read_CFI(NOR_HandleTypeDef *hnor, NOR_CFITypeDef *pNOR_CFI);
  158. /**
  159. * @}
  160. */
  161. /** @addtogroup NOR_Exported_Functions_Group3 NOR Control functions
  162. * @{
  163. */
  164. /* NOR Control functions *****************************************************/
  165. HAL_StatusTypeDef HAL_NOR_WriteOperation_Enable(NOR_HandleTypeDef *hnor);
  166. HAL_StatusTypeDef HAL_NOR_WriteOperation_Disable(NOR_HandleTypeDef *hnor);
  167. /**
  168. * @}
  169. */
  170. /** @addtogroup NOR_Exported_Functions_Group4 NOR State functions
  171. * @{
  172. */
  173. /* NOR State functions ********************************************************/
  174. HAL_NOR_StateTypeDef HAL_NOR_GetState(NOR_HandleTypeDef *hnor);
  175. HAL_NOR_StatusTypeDef HAL_NOR_GetStatus(NOR_HandleTypeDef *hnor, uint32_t Address, uint32_t Timeout);
  176. /**
  177. * @}
  178. */
  179. /**
  180. * @}
  181. */
  182. /* Private types -------------------------------------------------------------*/
  183. /* Private variables ---------------------------------------------------------*/
  184. /* Private constants ---------------------------------------------------------*/
  185. /** @defgroup NOR_Private_Constants NOR Private Constants
  186. * @{
  187. */
  188. /* NOR device IDs addresses */
  189. #define MC_ADDRESS ((uint16_t)0x0000U)
  190. #define DEVICE_CODE1_ADDR ((uint16_t)0x0001U)
  191. #define DEVICE_CODE2_ADDR ((uint16_t)0x000EU)
  192. #define DEVICE_CODE3_ADDR ((uint16_t)0x000FU)
  193. /* NOR CFI IDs addresses */
  194. #define CFI1_ADDRESS ((uint16_t)0x61U)
  195. #define CFI2_ADDRESS ((uint16_t)0x62U)
  196. #define CFI3_ADDRESS ((uint16_t)0x63U)
  197. #define CFI4_ADDRESS ((uint16_t)0x64U)
  198. /* NOR operation wait timeout */
  199. #define NOR_TMEOUT ((uint16_t)0xFFFFU)
  200. /* NOR memory data width */
  201. #define NOR_MEMORY_8B ((uint8_t)0x0U)
  202. #define NOR_MEMORY_16B ((uint8_t)0x1U)
  203. /* NOR memory device read/write start address */
  204. #define NOR_MEMORY_ADRESS1 ((uint32_t)0x60000000U)
  205. #define NOR_MEMORY_ADRESS2 ((uint32_t)0x64000000U)
  206. #define NOR_MEMORY_ADRESS3 ((uint32_t)0x68000000U)
  207. #define NOR_MEMORY_ADRESS4 ((uint32_t)0x6C000000U)
  208. /**
  209. * @}
  210. */
  211. /* Private macros ------------------------------------------------------------*/
  212. /** @defgroup NOR_Private_Macros NOR Private Macros
  213. * @{
  214. */
  215. /**
  216. * @brief NOR memory address shifting.
  217. * @param __NOR_ADDRESS: NOR base address
  218. * @param __NOR_MEMORY_WIDTH_: NOR memory width
  219. * @param __ADDRESS__: NOR memory address
  220. * @retval NOR shifted address value
  221. */
  222. #define NOR_ADDR_SHIFT(__NOR_ADDRESS, __NOR_MEMORY_WIDTH_, __ADDRESS__) \
  223. ((uint32_t)(((__NOR_MEMORY_WIDTH_) == NOR_MEMORY_16B)? \
  224. ((uint32_t)((__NOR_ADDRESS) + (2 * (__ADDRESS__)))): \
  225. ((uint32_t)((__NOR_ADDRESS) + (__ADDRESS__)))))
  226. /**
  227. * @brief NOR memory write data to specified address.
  228. * @param __ADDRESS__: NOR memory address
  229. * @param __DATA__: Data to write
  230. * @retval None
  231. */
  232. #define NOR_WRITE(__ADDRESS__, __DATA__) do{ \
  233. (*(__IO uint16_t *)((uint32_t)(__ADDRESS__)) = (__DATA__)); \
  234. __DSB(); \
  235. } while(0)
  236. /**
  237. * @}
  238. */
  239. /**
  240. * @}
  241. */
  242. /**
  243. * @}
  244. */
  245. #ifdef __cplusplus
  246. }
  247. #endif
  248. #endif /* __STM32F7xx_HAL_NOR_H */
  249. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/