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_flash.h 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. /**
  2. ******************************************************************************
  3. * @file stm32l1xx_hal_flash.h
  4. * @author MCD Application Team
  5. * @brief Header file of Flash 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_FLASH_H
  21. #define __STM32L1xx_HAL_FLASH_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32l1xx_hal_def.h"
  27. /** @addtogroup STM32L1xx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup FLASH
  31. * @{
  32. */
  33. /** @addtogroup FLASH_Private_Constants
  34. * @{
  35. */
  36. #define FLASH_TIMEOUT_VALUE (50000U) /* 50 s */
  37. /**
  38. * @}
  39. */
  40. /** @addtogroup FLASH_Private_Macros
  41. * @{
  42. */
  43. #define IS_FLASH_TYPEPROGRAM(_VALUE_) ((_VALUE_) == FLASH_TYPEPROGRAM_WORD)
  44. #define IS_FLASH_LATENCY(__LATENCY__) (((__LATENCY__) == FLASH_LATENCY_0) || \
  45. ((__LATENCY__) == FLASH_LATENCY_1))
  46. /**
  47. * @}
  48. */
  49. /* Exported types ------------------------------------------------------------*/
  50. /** @defgroup FLASH_Exported_Types FLASH Exported Types
  51. * @{
  52. */
  53. /**
  54. * @brief FLASH Procedure structure definition
  55. */
  56. typedef enum
  57. {
  58. FLASH_PROC_NONE = 0U,
  59. FLASH_PROC_PAGEERASE = 1U,
  60. FLASH_PROC_PROGRAM = 2U,
  61. } FLASH_ProcedureTypeDef;
  62. /**
  63. * @brief FLASH handle Structure definition
  64. */
  65. typedef struct
  66. {
  67. __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*!< Internal variable to indicate which procedure is ongoing or not in IT context */
  68. __IO uint32_t NbPagesToErase; /*!< Internal variable to save the remaining sectors to erase in IT context*/
  69. __IO uint32_t Address; /*!< Internal variable to save address selected for program or erase */
  70. __IO uint32_t Page; /*!< Internal variable to define the current page which is erasing */
  71. HAL_LockTypeDef Lock; /*!< FLASH locking object */
  72. __IO uint32_t ErrorCode; /*!< FLASH error code
  73. This parameter can be a value of @ref FLASH_Error_Codes */
  74. } FLASH_ProcessTypeDef;
  75. /**
  76. * @}
  77. */
  78. /* Exported constants --------------------------------------------------------*/
  79. /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
  80. * @{
  81. */
  82. /** @defgroup FLASH_Error_Codes FLASH Error Codes
  83. * @{
  84. */
  85. #define HAL_FLASH_ERROR_NONE 0x00U /*!< No error */
  86. #define HAL_FLASH_ERROR_PGA 0x01U /*!< Programming alignment error */
  87. #define HAL_FLASH_ERROR_WRP 0x02U /*!< Write protection error */
  88. #define HAL_FLASH_ERROR_OPTV 0x04U /*!< Option validity error */
  89. #define HAL_FLASH_ERROR_SIZE 0x08U /*!< */
  90. #define HAL_FLASH_ERROR_RD 0x10U /*!< Read protected error */
  91. #define HAL_FLASH_ERROR_OPTVUSR 0x20U /*!< Option UserValidity Error. */
  92. #define HAL_FLASH_ERROR_OPERATION 0x40U /*!< Not used */
  93. /**
  94. * @}
  95. */
  96. /** @defgroup FLASH_Page_Size FLASH size information
  97. * @{
  98. */
  99. #define FLASH_SIZE (uint32_t)((*((uint32_t *)FLASHSIZE_BASE)&0xFFFFU) * 1024U)
  100. #define FLASH_PAGE_SIZE (256U) /*!< FLASH Page Size in bytes */
  101. /**
  102. * @}
  103. */
  104. /** @defgroup FLASH_Type_Program FLASH Type Program
  105. * @{
  106. */
  107. #define FLASH_TYPEPROGRAM_WORD (0x02U) /*!<Program a word (32-bit) at a specified address.*/
  108. /**
  109. * @}
  110. */
  111. /** @defgroup FLASH_Latency FLASH Latency
  112. * @{
  113. */
  114. #define FLASH_LATENCY_0 (0x00000000U) /*!< FLASH Zero Latency cycle */
  115. #define FLASH_LATENCY_1 FLASH_ACR_LATENCY /*!< FLASH One Latency cycle */
  116. /**
  117. * @}
  118. */
  119. /** @defgroup FLASH_Interrupts FLASH Interrupts
  120. * @{
  121. */
  122. #define FLASH_IT_EOP FLASH_PECR_EOPIE /*!< End of programming interrupt source */
  123. #define FLASH_IT_ERR FLASH_PECR_ERRIE /*!< Error interrupt source */
  124. /**
  125. * @}
  126. */
  127. /** @defgroup FLASH_Flags FLASH Flags
  128. * @{
  129. */
  130. #define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */
  131. #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Programming flag */
  132. #define FLASH_FLAG_ENDHV FLASH_SR_ENDHV /*!< FLASH End of High Voltage flag */
  133. #define FLASH_FLAG_READY FLASH_SR_READY /*!< FLASH Ready flag after low power mode */
  134. #define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protected error flag */
  135. #define FLASH_FLAG_PGAERR FLASH_SR_PGAERR /*!< FLASH Programming Alignment error flag */
  136. #define FLASH_FLAG_SIZERR FLASH_SR_SIZERR /*!< FLASH Size error flag */
  137. #define FLASH_FLAG_OPTVERR FLASH_SR_OPTVERR /*!< FLASH Option Validity error flag */
  138. /* Cat2 & Cat3*/
  139. #if defined(FLASH_SR_RDERR)
  140. #define FLASH_FLAG_RDERR FLASH_SR_RDERR /*!< Read protected error flag */
  141. #endif /* FLASH_SR_RDERR */
  142. /* Cat3, Cat4 & Cat5*/
  143. #if defined(FLASH_SR_OPTVERRUSR)
  144. #define FLASH_FLAG_OPTVERRUSR FLASH_SR_OPTVERRUSR /*!< FLASH Option User Validity error flag */
  145. #endif /* FLASH_SR_OPTVERRUSR */
  146. /**
  147. * @}
  148. */
  149. /** @defgroup FLASH_Keys FLASH Keys
  150. * @{
  151. */
  152. #define FLASH_PDKEY1 (0x04152637U) /*!< Flash power down key1 */
  153. #define FLASH_PDKEY2 (0xFAFBFCFDU) /*!< Flash power down key2: used with FLASH_PDKEY1
  154. to unlock the RUN_PD bit in FLASH_ACR */
  155. #define FLASH_PEKEY1 (0x89ABCDEFU) /*!< Flash program erase key1 */
  156. #define FLASH_PEKEY2 (0x02030405U) /*!< Flash program erase key: used with FLASH_PEKEY2
  157. to unlock the write access to the FLASH_PECR register and
  158. data EEPROM */
  159. #define FLASH_PRGKEY1 (0x8C9DAEBFU) /*!< Flash program memory key1 */
  160. #define FLASH_PRGKEY2 (0x13141516U) /*!< Flash program memory key2: used with FLASH_PRGKEY2
  161. to unlock the program memory */
  162. #define FLASH_OPTKEY1 (0xFBEAD9C8U) /*!< Flash option key1 */
  163. #define FLASH_OPTKEY2 (0x24252627U) /*!< Flash option key2: used with FLASH_OPTKEY1 to
  164. unlock the write access to the option byte block */
  165. /**
  166. * @}
  167. */
  168. /**
  169. * @}
  170. */
  171. /* Exported macro ------------------------------------------------------------*/
  172. /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
  173. * @brief macros to control FLASH features
  174. * @{
  175. */
  176. /** @defgroup FLASH_Interrupt FLASH Interrupts
  177. * @brief macros to handle FLASH interrupts
  178. * @{
  179. */
  180. /**
  181. * @brief Enable the specified FLASH interrupt.
  182. * @param __INTERRUPT__ FLASH interrupt
  183. * This parameter can be any combination of the following values:
  184. * @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt
  185. * @arg @ref FLASH_IT_ERR Error Interrupt
  186. * @retval none
  187. */
  188. #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) SET_BIT((FLASH->PECR), (__INTERRUPT__))
  189. /**
  190. * @brief Disable the specified FLASH interrupt.
  191. * @param __INTERRUPT__ FLASH interrupt
  192. * This parameter can be any combination of the following values:
  193. * @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt
  194. * @arg @ref FLASH_IT_ERR Error Interrupt
  195. * @retval none
  196. */
  197. #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) CLEAR_BIT((FLASH->PECR), (uint32_t)(__INTERRUPT__))
  198. /**
  199. * @brief Get the specified FLASH flag status.
  200. * @param __FLAG__ specifies the FLASH flag to check.
  201. * This parameter can be one of the following values:
  202. * @arg @ref FLASH_FLAG_BSY FLASH Busy flag
  203. * @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag
  204. * @arg @ref FLASH_FLAG_ENDHV FLASH End of High Voltage flag
  205. * @arg @ref FLASH_FLAG_READY FLASH Ready flag after low power mode
  206. * @arg @ref FLASH_FLAG_PGAERR FLASH Programming Alignment error flag
  207. * @arg @ref FLASH_FLAG_SIZERR FLASH Size error flag
  208. * @arg @ref FLASH_FLAG_OPTVERR FLASH Option validity error error flag
  209. @if STM32L100xB
  210. @elif STM32L100xBA
  211. * @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP)
  212. @elif STM32L151xB
  213. @elif STM32L151xBA
  214. * @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP)
  215. @elif STM32L152xB
  216. @elif STM32L152xBA
  217. * @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP)
  218. @elif STM32L100xC
  219. * @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP)
  220. * @arg @ref FLASH_FLAG_OPTVERRUSR FLASH Option User validity error
  221. @elif STM32L151xC
  222. * @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP)
  223. * @arg @ref FLASH_FLAG_OPTVERRUSR FLASH Option User validity error
  224. @elif STM32L152xC
  225. * @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP)
  226. * @arg @ref FLASH_FLAG_OPTVERRUSR FLASH Option User validity error
  227. @elif STM32L162xC
  228. * @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP)
  229. * @arg @ref FLASH_FLAG_OPTVERRUSR FLASH Option User validity error
  230. @else
  231. * @arg @ref FLASH_FLAG_OPTVERRUSR FLASH Option User validity error
  232. @endif
  233. * @arg @ref FLASH_FLAG_WRPERR FLASH Write protected error flag
  234. * @retval The new state of __FLAG__ (SET or RESET).
  235. */
  236. #define __HAL_FLASH_GET_FLAG(__FLAG__) (((FLASH->SR) & (__FLAG__)) == (__FLAG__))
  237. /**
  238. * @brief Clear the specified FLASH flag.
  239. * @param __FLAG__ specifies the FLASH flags to clear.
  240. * This parameter can be any combination of the following values:
  241. * @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag
  242. * @arg @ref FLASH_FLAG_PGAERR FLASH Programming Alignment error flag
  243. * @arg @ref FLASH_FLAG_SIZERR FLASH Size error flag
  244. * @arg @ref FLASH_FLAG_OPTVERR FLASH Option validity error error flag
  245. @if STM32L100xB
  246. @elif STM32L100xBA
  247. * @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP)
  248. @elif STM32L151xB
  249. @elif STM32L151xBA
  250. * @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP)
  251. @elif STM32L152xB
  252. @elif STM32L152xBA
  253. * @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP)
  254. @elif STM32L100xC
  255. * @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP)
  256. * @arg @ref FLASH_FLAG_OPTVERRUSR FLASH Option User validity error
  257. @elif STM32L151xC
  258. * @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP)
  259. * @arg @ref FLASH_FLAG_OPTVERRUSR FLASH Option User validity error
  260. @elif STM32L152xC
  261. * @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP)
  262. * @arg @ref FLASH_FLAG_OPTVERRUSR FLASH Option User validity error
  263. @elif STM32L162xC
  264. * @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP)
  265. * @arg @ref FLASH_FLAG_OPTVERRUSR FLASH Option User validity error
  266. @else
  267. * @arg @ref FLASH_FLAG_OPTVERRUSR FLASH Option User validity error
  268. @endif
  269. * @arg @ref FLASH_FLAG_WRPERR FLASH Write protected error flag
  270. * @retval none
  271. */
  272. #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) ((FLASH->SR) = (__FLAG__))
  273. /**
  274. * @}
  275. */
  276. /**
  277. * @}
  278. */
  279. /* Include FLASH HAL Extended module */
  280. #include "stm32l1xx_hal_flash_ex.h"
  281. #include "stm32l1xx_hal_flash_ramfunc.h"
  282. /* Exported functions --------------------------------------------------------*/
  283. /** @addtogroup FLASH_Exported_Functions
  284. * @{
  285. */
  286. /** @addtogroup FLASH_Exported_Functions_Group1
  287. * @{
  288. */
  289. /* IO operation functions *****************************************************/
  290. HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint32_t Data);
  291. HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint32_t Data);
  292. /* FLASH IRQ handler function */
  293. void HAL_FLASH_IRQHandler(void);
  294. /* Callbacks in non blocking modes */
  295. void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
  296. void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
  297. /**
  298. * @}
  299. */
  300. /** @addtogroup FLASH_Exported_Functions_Group2
  301. * @{
  302. */
  303. /* Peripheral Control functions ***********************************************/
  304. HAL_StatusTypeDef HAL_FLASH_Unlock(void);
  305. HAL_StatusTypeDef HAL_FLASH_Lock(void);
  306. HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
  307. HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
  308. HAL_StatusTypeDef HAL_FLASH_OB_Launch(void);
  309. /**
  310. * @}
  311. */
  312. /** @addtogroup FLASH_Exported_Functions_Group3
  313. * @{
  314. */
  315. /* Peripheral State and Error functions ***************************************/
  316. uint32_t HAL_FLASH_GetError(void);
  317. /**
  318. * @}
  319. */
  320. /**
  321. * @}
  322. */
  323. /* Private function -------------------------------------------------*/
  324. /** @addtogroup FLASH_Private_Functions
  325. * @{
  326. */
  327. HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout);
  328. /**
  329. * @}
  330. */
  331. /**
  332. * @}
  333. */
  334. /**
  335. * @}
  336. */
  337. #ifdef __cplusplus
  338. }
  339. #endif
  340. #endif /* __STM32L1xx_HAL_FLASH_H */
  341. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/