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.

stm32l1xx_hal_nor.h 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /**
  2. ******************************************************************************
  3. * @file stm32l1xx_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 __STM32L1xx_HAL_NOR_H
  21. #define __STM32L1xx_HAL_NOR_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32l1xx_ll_fsmc.h"
  27. /** @addtogroup STM32L1xx_HAL_Driver
  28. * @{
  29. */
  30. #if defined (STM32L151xD) || defined (STM32L152xD) || defined (STM32L162xD)
  31. /** @addtogroup NOR
  32. * @{
  33. */
  34. /** @addtogroup NOR_Private_Constants
  35. * @{
  36. */
  37. /* NOR device IDs addresses */
  38. #define MC_ADDRESS ((uint16_t)0x0000)
  39. #define DEVICE_CODE1_ADDR ((uint16_t)0x0001)
  40. #define DEVICE_CODE2_ADDR ((uint16_t)0x000E)
  41. #define DEVICE_CODE3_ADDR ((uint16_t)0x000F)
  42. /* NOR CFI IDs addresses */
  43. #define CFI1_ADDRESS ((uint16_t)0x10)
  44. #define CFI2_ADDRESS ((uint16_t)0x11)
  45. #define CFI3_ADDRESS ((uint16_t)0x12)
  46. #define CFI4_ADDRESS ((uint16_t)0x13)
  47. /* NOR operation wait timeout */
  48. #define NOR_TMEOUT ((uint16_t)0xFFFF)
  49. /* NOR memory data width */
  50. #define NOR_MEMORY_8B ((uint8_t)0x0)
  51. #define NOR_MEMORY_16B ((uint8_t)0x1)
  52. /* NOR memory device read/write start address */
  53. #define NOR_MEMORY_ADRESS1 FSMC_BANK1_1
  54. #define NOR_MEMORY_ADRESS2 FSMC_BANK1_2
  55. #define NOR_MEMORY_ADRESS3 FSMC_BANK1_3
  56. #define NOR_MEMORY_ADRESS4 FSMC_BANK1_4
  57. /**
  58. * @}
  59. */
  60. /** @addtogroup NOR_Private_Macros
  61. * @{
  62. */
  63. /**
  64. * @brief NOR memory address shifting.
  65. * @param __NOR_ADDRESS NOR base address
  66. * @param __NOR_MEMORY_WIDTH_ NOR memory width
  67. * @param __ADDRESS__ NOR memory address
  68. * @retval NOR shifted address value
  69. */
  70. #define NOR_ADDR_SHIFT(__NOR_ADDRESS, __NOR_MEMORY_WIDTH_, __ADDRESS__) \
  71. ((uint32_t)(((__NOR_MEMORY_WIDTH_) == NOR_MEMORY_16B)? \
  72. ((uint32_t)((__NOR_ADDRESS) + (2 * (__ADDRESS__)))): \
  73. ((uint32_t)((__NOR_ADDRESS) + (__ADDRESS__)))))
  74. /**
  75. * @brief NOR memory write data to specified address.
  76. * @param __ADDRESS__ NOR memory address
  77. * @param __DATA__ Data to write
  78. * @retval None
  79. */
  80. #define NOR_WRITE(__ADDRESS__, __DATA__) (*(__IO uint16_t *)((uint32_t)(__ADDRESS__)) = (__DATA__))
  81. /**
  82. * @}
  83. */
  84. /* Exported typedef ----------------------------------------------------------*/
  85. /** @defgroup NOR_Exported_Types NOR Exported Types
  86. * @{
  87. */
  88. /**
  89. * @brief HAL SRAM State structures definition
  90. */
  91. typedef enum
  92. {
  93. HAL_NOR_STATE_RESET = 0x00, /*!< NOR not yet initialized or disabled */
  94. HAL_NOR_STATE_READY = 0x01, /*!< NOR initialized and ready for use */
  95. HAL_NOR_STATE_BUSY = 0x02, /*!< NOR internal processing is ongoing */
  96. HAL_NOR_STATE_ERROR = 0x03, /*!< NOR error state */
  97. HAL_NOR_STATE_PROTECTED = 0x04 /*!< NOR NORSRAM device write protected */
  98. }HAL_NOR_StateTypeDef;
  99. /**
  100. * @brief FSMC NOR Status typedef
  101. */
  102. typedef enum
  103. {
  104. HAL_NOR_STATUS_SUCCESS = 0,
  105. HAL_NOR_STATUS_ONGOING,
  106. HAL_NOR_STATUS_ERROR,
  107. HAL_NOR_STATUS_TIMEOUT
  108. }HAL_NOR_StatusTypeDef;
  109. /**
  110. * @brief FSMC NOR ID typedef
  111. */
  112. typedef struct
  113. {
  114. uint16_t Manufacturer_Code; /*!< Defines the device's manufacturer code used to identify the memory */
  115. uint16_t Device_Code1;
  116. uint16_t Device_Code2;
  117. uint16_t Device_Code3; /*!< Defines the device's codes used to identify the memory.
  118. These codes can be accessed by performing read operations with specific
  119. control signals and addresses set.They can also be accessed by issuing
  120. an Auto Select command */
  121. }NOR_IDTypeDef;
  122. /**
  123. * @brief FSMC NOR CFI typedef
  124. */
  125. typedef struct
  126. {
  127. /*!< Defines the information stored in the memory's Common flash interface
  128. which contains a description of various electrical and timing parameters,
  129. density information and functions supported by the memory */
  130. uint16_t CFI_1;
  131. uint16_t CFI_2;
  132. uint16_t CFI_3;
  133. uint16_t CFI_4;
  134. }NOR_CFITypeDef;
  135. /**
  136. * @brief NOR handle Structure definition
  137. */
  138. typedef struct
  139. {
  140. FSMC_NORSRAM_TypeDef *Instance; /*!< Register base address */
  141. FSMC_NORSRAM_EXTENDED_TypeDef *Extended; /*!< Extended mode register base address */
  142. FSMC_NORSRAM_InitTypeDef Init; /*!< NOR device control configuration parameters */
  143. HAL_LockTypeDef Lock; /*!< NOR locking object */
  144. __IO HAL_NOR_StateTypeDef State; /*!< NOR device access state */
  145. }NOR_HandleTypeDef;
  146. /**
  147. * @}
  148. */
  149. /* Exported constants --------------------------------------------------------*/
  150. /* Exported macro ------------------------------------------------------------*/
  151. /** @defgroup NOR_Exported_macro NOR Exported Macros
  152. * @{
  153. */
  154. /** @brief Reset NOR handle state
  155. * @param __HANDLE__ NOR handle
  156. * @retval None
  157. */
  158. #define __HAL_NOR_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_NOR_STATE_RESET)
  159. /**
  160. * @}
  161. */
  162. /* Exported functions --------------------------------------------------------*/
  163. /** @addtogroup NOR_Exported_Functions NOR Exported Functions
  164. * @{
  165. */
  166. /** @addtogroup NOR_Exported_Functions_Group1
  167. * @{
  168. */
  169. /* Initialization/de-initialization functions **********************************/
  170. HAL_StatusTypeDef HAL_NOR_Init(NOR_HandleTypeDef *hnor, FSMC_NORSRAM_TimingTypeDef *Timing, FSMC_NORSRAM_TimingTypeDef *ExtTiming);
  171. HAL_StatusTypeDef HAL_NOR_DeInit(NOR_HandleTypeDef *hnor);
  172. void HAL_NOR_MspInit(NOR_HandleTypeDef *hnor);
  173. void HAL_NOR_MspDeInit(NOR_HandleTypeDef *hnor);
  174. void HAL_NOR_MspWait(NOR_HandleTypeDef *hnor, uint32_t Timeout);
  175. /**
  176. * @}
  177. */
  178. /** @addtogroup NOR_Exported_Functions_Group2
  179. * @{
  180. */
  181. /* I/O operation functions ***************************************************/
  182. HAL_StatusTypeDef HAL_NOR_Read_ID(NOR_HandleTypeDef *hnor, NOR_IDTypeDef *pNOR_ID);
  183. HAL_StatusTypeDef HAL_NOR_ReturnToReadMode(NOR_HandleTypeDef *hnor);
  184. HAL_StatusTypeDef HAL_NOR_Read(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData);
  185. HAL_StatusTypeDef HAL_NOR_Program(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData);
  186. HAL_StatusTypeDef HAL_NOR_ReadBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize);
  187. HAL_StatusTypeDef HAL_NOR_ProgramBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize);
  188. HAL_StatusTypeDef HAL_NOR_Erase_Block(NOR_HandleTypeDef *hnor, uint32_t BlockAddress, uint32_t Address);
  189. HAL_StatusTypeDef HAL_NOR_Erase_Chip(NOR_HandleTypeDef *hnor, uint32_t Address);
  190. HAL_StatusTypeDef HAL_NOR_Read_CFI(NOR_HandleTypeDef *hnor, NOR_CFITypeDef *pNOR_CFI);
  191. /**
  192. * @}
  193. */
  194. /** @addtogroup NOR_Exported_Functions_Group3
  195. * @{
  196. */
  197. /* NOR Control functions *****************************************************/
  198. HAL_StatusTypeDef HAL_NOR_WriteOperation_Enable(NOR_HandleTypeDef *hnor);
  199. HAL_StatusTypeDef HAL_NOR_WriteOperation_Disable(NOR_HandleTypeDef *hnor);
  200. /**
  201. * @}
  202. */
  203. /** @addtogroup NOR_Exported_Functions_Group4
  204. * @{
  205. */
  206. /* NOR State functions ********************************************************/
  207. HAL_NOR_StateTypeDef HAL_NOR_GetState(NOR_HandleTypeDef *hnor);
  208. HAL_NOR_StatusTypeDef HAL_NOR_GetStatus(NOR_HandleTypeDef *hnor, uint32_t Address, uint32_t Timeout);
  209. /**
  210. * @}
  211. */
  212. /**
  213. * @}
  214. */
  215. /**
  216. * @}
  217. */
  218. #endif /* STM32L151xD || STM32L152xD || STM32L162xD */
  219. /**
  220. * @}
  221. */
  222. #ifdef __cplusplus
  223. }
  224. #endif
  225. #endif /* __STM32L1xx_HAL_NOR_H */
  226. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/