stm32l0xx_hal_flash.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. /**
  2. ******************************************************************************
  3. * @file stm32l0xx_hal_flash.h
  4. * @author MCD Application Team
  5. * @version V1.7.0
  6. * @date 31-May-2016
  7. * @brief Header file of Flash HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2016 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 __STM32L0XX_HAL_FLASH_H
  39. #define __STM32L0XX_HAL_FLASH_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32l0xx_hal_def.h"
  45. /** @addtogroup STM32L0xx_HAL_Driver
  46. * @{
  47. */
  48. /** @defgroup FLASH FLASH
  49. * @{
  50. */
  51. /** @defgroup FLASH_Exported_Types FLASH Exported Types
  52. * @{
  53. */
  54. /**
  55. * @brief FLASH Procedure structure definition
  56. */
  57. typedef enum
  58. {
  59. FLASH_PROC_NONE = 0U,
  60. FLASH_PROC_PAGEERASE,
  61. FLASH_PROC_PROGRAM
  62. } FLASH_ProcedureTypeDef;
  63. /**
  64. * @brief FLASH Erase structure definition
  65. */
  66. typedef struct
  67. {
  68. uint32_t TypeErase; /*!< TypeErase: Page Erase only.
  69. This parameter can be a value of @ref FLASHEx_Type_Erase */
  70. uint32_t PageAddress ; /*!< PageAddress : Initial FLASH address to be erased
  71. This parameter must be a value belonging to FLASH Programm address (depending on the devices) */
  72. uint32_t NbPages; /*!< NbPages: Number of pages to be erased.
  73. This parameter must be a value between 1 and (max number of pages - value of Initial page)*/
  74. } FLASH_EraseInitTypeDef;
  75. /**
  76. * @brief FLASH handle Structure definition
  77. */
  78. typedef struct
  79. {
  80. __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /* Internal variable to indicate which procedure is ongoing or not in IT context */
  81. __IO uint32_t NbPagesToErase; /* Internal variable to save the remaining sectors to erase in IT context */
  82. __IO uint32_t Page; /* Internal variable to define the current sector which is erasing */
  83. __IO uint32_t Address; /* Internal variable to save address selected for program */
  84. HAL_LockTypeDef Lock; /* FLASH locking object */
  85. __IO uint32_t ErrorCode; /* FLASH error code */
  86. }FLASH_ProcessTypeDef;
  87. /**
  88. * @}
  89. */
  90. /** @addtogroup FLASH_Private
  91. * @{
  92. */
  93. /**
  94. * @brief Variable used for Program/Erase sectors under interruption.
  95. * Put as extern as used also in flash_ex.c.
  96. */
  97. extern FLASH_ProcessTypeDef ProcFlash;
  98. #define FLASH_TIMEOUT_VALUE ((uint32_t)50000U) /* 50 s */
  99. #define FLASH_SIZE_DATA_REGISTER ((uint32_t)0x1FF8007CU)
  100. /**
  101. * @}
  102. */
  103. /** @defgroup FLASH_Exported_Constants FLASH Public Constants
  104. * @{
  105. */
  106. /**
  107. * @brief FLASH size information
  108. */
  109. #define FLASH_SIZE (uint32_t)(*((uint16_t *)FLASH_SIZE_DATA_REGISTER) * 1024U)
  110. #define FLASH_PAGE_SIZE ((uint32_t)128U)
  111. /** @defgroup FLASH_Type_Program FLASH Type Program
  112. * @{
  113. */
  114. #define FLASH_TYPEPROGRAM_WORD ((uint32_t)0x02U) /*!<Program a word (32-bit) at a specified address.*/
  115. /**
  116. * @}
  117. */
  118. /** @defgroup FLASH_Latency FLASH Latency
  119. * @{
  120. */
  121. #define FLASH_LATENCY_0 ((uint8_t)0x00U) /*!< FLASH Zero Latency cycle */
  122. #define FLASH_LATENCY_1 ((uint8_t)0x01U) /*!< FLASH One Latency cycle */
  123. /**
  124. * @}
  125. */
  126. /** @defgroup FLASH_Interrupts FLASH Interrupts
  127. * @{
  128. */
  129. #define FLASH_IT_EOP FLASH_PECR_EOPIE /*!< End of programming interrupt source */
  130. #define FLASH_IT_ERR FLASH_PECR_ERRIE /*!< Error interrupt source */
  131. /**
  132. * @}
  133. */
  134. /** @defgroup FLASH_Flags FLASH Flags
  135. * @{
  136. */
  137. #define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */
  138. #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Programming flag */
  139. #define FLASH_FLAG_ENDHV FLASH_SR_HVOFF /*!< FLASH End of High Voltage flag */
  140. #define FLASH_FLAG_READY FLASH_SR_READY /*!< FLASH Ready flag after low power mode */
  141. #define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protected error flag */
  142. #define FLASH_FLAG_PGAERR FLASH_SR_PGAERR /*!< FLASH Programming Alignment error flag */
  143. #define FLASH_FLAG_SIZERR FLASH_SR_SIZERR /*!< FLASH Size error flag */
  144. #define FLASH_FLAG_OPTVERR FLASH_SR_OPTVERR /*!< FLASH Option Validity error flag (not valid with STM32L031xx/STM32L041xx) */
  145. #define FLASH_FLAG_RDERR FLASH_SR_RDERR /*!< FLASH Read protected error flag */
  146. #define FLASH_FLAG_FWWERR FLASH_SR_FWWERR /*!< FLASH Write or Errase operation aborted */
  147. #define FLASH_FLAG_NOTZEROERR FLASH_SR_NOTZEROERR /*!< FLASH Read protected error flag */
  148. /**
  149. * @}
  150. */
  151. /** @defgroup FLASH_Error_Code Flash Error Code
  152. * @{
  153. */
  154. #define HAL_FLASH_ERROR_NONE 0x00U
  155. #define HAL_FLASH_ERROR_RD 0x01U
  156. #define HAL_FLASH_ERROR_SIZE 0x02U
  157. #define HAL_FLASH_ERROR_PGA 0x04U
  158. #define HAL_FLASH_ERROR_WRP 0x08U
  159. #define HAL_FLASH_ERROR_OPTV 0x10U
  160. #define HAL_FLASH_ERROR_FWWERR 0x20U
  161. #define HAL_FLASH_ERROR_NOTZERO 0x40U
  162. /**
  163. * @}
  164. */
  165. /** @defgroup FLASH_Keys FLASH Keys
  166. * @{
  167. */
  168. #define FLASH_PDKEY1 ((uint32_t)0x04152637U) /*!< Flash power down key1 */
  169. #define FLASH_PDKEY2 ((uint32_t)0xFAFBFCFDU) /*!< Flash power down key2: used with FLASH_PDKEY1
  170. to unlock the RUN_PD bit in FLASH_ACR */
  171. #define FLASH_PEKEY1 ((uint32_t)0x89ABCDEFU) /*!< Flash program erase key1 */
  172. #define FLASH_PEKEY2 ((uint32_t)0x02030405U) /*!< Flash program erase key: used with FLASH_PEKEY2
  173. to unlock the write access to the FLASH_PECR register and
  174. data EEPROM */
  175. #define FLASH_PRGKEY1 ((uint32_t)0x8C9DAEBFU) /*!< Flash program memory key1 */
  176. #define FLASH_PRGKEY2 ((uint32_t)0x13141516u) /*!< Flash program memory key2: used with FLASH_PRGKEY2
  177. to unlock the program memory */
  178. #define FLASH_OPTKEY1 ((uint32_t)0xFBEAD9C8U) /*!< Flash option key1 */
  179. #define FLASH_OPTKEY2 ((uint32_t)0x24252627U) /*!< Flash option key2: used with FLASH_OPTKEY1 to
  180. unlock the write access to the option byte block */
  181. /**
  182. * @}
  183. */
  184. /* CMSIS_Legacy */
  185. #if defined ( __ICCARM__ )
  186. #define InterruptType_ACTLR_DISMCYCINT_Msk IntType_ACTLR_DISMCYCINT_Msk
  187. #endif
  188. /**
  189. * @}
  190. */
  191. /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
  192. * @{
  193. */
  194. /** @defgroup FLASH_Macro_Interrupt Macros to handle FLASH interrupts
  195. * @brief Enable and disable the specified FLASH interrupt.
  196. * @{
  197. */
  198. /**
  199. * @brief Enable the specified FLASH interrupt.
  200. * @param __INTERRUPT__ : FLASH interrupt
  201. * This parameter can be any combination of the following values:
  202. * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
  203. * @arg FLASH_IT_ERR: Error Interrupt
  204. * @retval none
  205. */
  206. #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) ((FLASH->PECR) |= (__INTERRUPT__))
  207. /**
  208. * @brief Disable the specified FLASH interrupt.
  209. * @param __INTERRUPT__ : FLASH interrupt
  210. * This parameter can be any combination of the following values:
  211. * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
  212. * @arg FLASH_IT_ERR: Error Interrupt
  213. * @retval none
  214. */
  215. #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) ((FLASH->PECR) &= ~(uint32_t)(__INTERRUPT__))
  216. /**
  217. * @brief Get the specified FLASH flag status.
  218. * @param __FLAG__: specifies the FLASH flag to check.
  219. * This parameter can be one of the following values:
  220. * @arg FLASH_FLAG_BSY : FLASH Busy flag
  221. * @arg FLASH_FLAG_EOP: FLASH End of Operation flag
  222. * @arg FLASH_FLAG_READY: FLASH Ready flag after low power mode
  223. * @arg FLASH_FLAG_ENDHV: FLASH End of high voltage flag
  224. * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
  225. * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag (not valid with STM32L031xx/STM32L041xx)
  226. * @arg FLASH_FLAG_SIZERR: FLASH Size error flag
  227. * @arg FLASH_FLAG_OPTVERR: FLASH Option validity error flag (not valid with STM32L031xx/STM32L041xx)
  228. * @arg FLASH_FLAG_RDERR: FLASH Read protected error flag
  229. * @arg FLASH_FLAG_FWWERR: FLASH Fetch While Write Error flag
  230. * @arg FLASH_FLAG_NOTZEROERR: Not Zero area error flag
  231. * @retval The new state of __FLAG__ (SET or RESET).
  232. */
  233. #define __HAL_FLASH_GET_FLAG(__FLAG__) (((FLASH->SR) & (__FLAG__)) == (__FLAG__))
  234. /**
  235. * @brief Clear the specified FLASH flag.
  236. * @param __FLAG__: specifies the FLASH flags to clear.
  237. * This parameter can be any combination of the following values:
  238. * @arg FLASH_FLAG_EOP: FLASH End of Operation flag
  239. * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
  240. * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag (not valid with STM32L031xx/STM32L041xx)
  241. * @arg FLASH_FLAG_SIZERR: FLASH size error flag
  242. * @arg FLASH_FLAG_OPTVERR: FLASH Option validity error flag (not valid with STM32L031xx/STM32L041xx)
  243. * @arg FLASH_FLAG_RDERR: FLASH Read protected error flag
  244. * @arg FLASH_FLAG_FWWERR: FLASH Fetch While Write Error flag
  245. * @arg FLASH_FLAG_NOTZEROERR: Not Zero area error flag
  246. * @retval None
  247. */
  248. #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) (FLASH->SR = (__FLAG__))
  249. /**
  250. * @}
  251. */
  252. /**
  253. * @}
  254. */
  255. /* Include FLASH HAL Extension module */
  256. #include "stm32l0xx_hal_flash_ex.h"
  257. #include "stm32l0xx_hal_flash_ramfunc.h"
  258. /* Exported functions ------------------------------------------------------- */
  259. /** @defgroup FLASH_Exported_Functions FLASH Exported functions
  260. * @{
  261. */
  262. /** @defgroup FLASH_Exported_Functions_Group1 Programming operation functions
  263. * @{
  264. */
  265. /**
  266. * @brief FLASH memory functions that can be executed from FLASH.
  267. */
  268. /* Program operation functions ***********************************************/
  269. HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint32_t Data);
  270. HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint32_t Data);
  271. /* FLASH IRQ handler function ***********************************************/
  272. void HAL_FLASH_IRQHandler(void);
  273. /* Callbacks in non blocking modes ******************************************/
  274. void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
  275. void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
  276. /**
  277. * @}
  278. */
  279. /** @defgroup FLASH_Exported_Functions_Group2 Peripheral Control functions
  280. * @{
  281. */
  282. /* FLASH Memory Programming functions *****************************************/
  283. HAL_StatusTypeDef HAL_FLASH_Unlock(void);
  284. HAL_StatusTypeDef HAL_FLASH_Lock(void);
  285. /* Option Bytes Programming functions *****************************************/
  286. HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
  287. HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
  288. HAL_StatusTypeDef HAL_FLASH_OB_Launch(void);
  289. /**
  290. * @}
  291. */
  292. /** @defgroup FLASH_Exported_Functions_Group3 Peripheral State and Errors functions
  293. * @{
  294. */
  295. /* Peripheral State methods **************************************************/
  296. uint32_t HAL_FLASH_GetError(void);
  297. /**
  298. * @}
  299. */
  300. /**
  301. * @}
  302. */
  303. /** @addtogroup FLASH_Private
  304. * @{
  305. */
  306. #define IS_FLASH_TYPEPROGRAM(VALUE) ((VALUE) == FLASH_TYPEPROGRAM_WORD)
  307. #define IS_FLASH_LATENCY(__LATENCY__) (((__LATENCY__) == FLASH_LATENCY_0) || \
  308. ((__LATENCY__) == FLASH_LATENCY_1))
  309. /**
  310. * @brief Function used internally by HAL FLASH driver.
  311. */
  312. HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout);
  313. void FLASH_ErasePage(uint32_t Page_Address);
  314. /**
  315. * @}
  316. */
  317. /* Define the private group ***********************************/
  318. /**************************************************************/
  319. /** @defgroup FLASH_Private FLASH Private
  320. * @{
  321. */
  322. /**
  323. * @}
  324. */
  325. /**************************************************************/
  326. /**
  327. * @}
  328. */
  329. /**
  330. * @}
  331. */
  332. #ifdef __cplusplus
  333. }
  334. #endif
  335. #endif /* __STM32L0XX_HAL_FLASH_H */
  336. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/