stm32l4xx_hal_nor.h 10 KB

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