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.
 
 
 

379 lines
13 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32l0xx_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) 2016 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 __STM32L0xx_HAL_FLASH_H
  21. #define __STM32L0xx_HAL_FLASH_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32l0xx_hal_def.h"
  27. /** @addtogroup STM32L0xx_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. #define FLASH_SIZE_DATA_REGISTER FLASHSIZE_BASE
  38. /**
  39. * @}
  40. */
  41. /** @addtogroup FLASH_Private_Macros
  42. * @{
  43. */
  44. #define IS_FLASH_TYPEPROGRAM(_VALUE_) ((_VALUE_) == FLASH_TYPEPROGRAM_WORD)
  45. #define IS_FLASH_LATENCY(__LATENCY__) (((__LATENCY__) == FLASH_LATENCY_0) || \
  46. ((__LATENCY__) == FLASH_LATENCY_1))
  47. /**
  48. * @}
  49. */
  50. /* Exported types ------------------------------------------------------------*/
  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 = 0,
  60. FLASH_PROC_PAGEERASE = 1,
  61. FLASH_PROC_PROGRAM = 2,
  62. } FLASH_ProcedureTypeDef;
  63. /**
  64. * @brief FLASH handle Structure definition
  65. */
  66. typedef struct
  67. {
  68. __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*!< Internal variable to indicate which procedure is ongoing or not in IT context */
  69. __IO uint32_t NbPagesToErase; /*!< Internal variable to save the remaining sectors to erase in IT context*/
  70. __IO uint32_t Address; /*!< Internal variable to save address selected for program or erase */
  71. __IO uint32_t Page; /*!< Internal variable to define the current page which is erasing */
  72. HAL_LockTypeDef Lock; /*!< FLASH locking object */
  73. __IO uint32_t ErrorCode; /*!< FLASH error code
  74. This parameter can be a value of @ref FLASH_Error_Codes */
  75. } FLASH_ProcessTypeDef;
  76. /**
  77. * @}
  78. */
  79. /* Exported constants --------------------------------------------------------*/
  80. /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
  81. * @{
  82. */
  83. /** @defgroup FLASH_Error_Codes FLASH Error Codes
  84. * @{
  85. */
  86. #define HAL_FLASH_ERROR_NONE 0x00U /*!< No error */
  87. #define HAL_FLASH_ERROR_PGA 0x01U /*!< Programming alignment error */
  88. #define HAL_FLASH_ERROR_WRP 0x02U /*!< Write protection error */
  89. #define HAL_FLASH_ERROR_OPTV 0x04U /*!< Option validity error */
  90. #define HAL_FLASH_ERROR_SIZE 0x08U /*!< */
  91. #define HAL_FLASH_ERROR_RD 0x10U /*!< Read protected error */
  92. #define HAL_FLASH_ERROR_FWWERR 0x20U /*!< FLASH Write or Erase operation aborted */
  93. #define HAL_FLASH_ERROR_NOTZERO 0x40U /*!< FLASH Write operation is done in a not-erased region */
  94. /**
  95. * @}
  96. */
  97. /** @defgroup FLASH_Page_Size FLASH size information
  98. * @{
  99. */
  100. #define FLASH_SIZE (uint32_t)((*((uint32_t *)FLASHSIZE_BASE)&0xFFFF) * 1024U)
  101. #define FLASH_PAGE_SIZE ((uint32_t)128U) /*!< FLASH Page Size in bytes */
  102. #define FLASH_END (FLASH_BASE + FLASH_SIZE - 1) /*!< FLASH end address in the alias region */
  103. #if defined (STM32L071xx) || defined (STM32L072xx) || defined (STM32L073xx) || defined (STM32L081xx) || defined (STM32L082xx) || defined (STM32L083xx)
  104. #define FLASH_BANK2_BASE (FLASH_BASE + (FLASH_SIZE >> 1)) /*!< FLASH BANK2 base address in the alias region */
  105. #define FLASH_BANK1_END (FLASH_BANK2_BASE - 1) /*!< Program end FLASH BANK1 address */
  106. #define FLASH_BANK2_END (FLASH_END) /*!< Program end FLASH BANK2 address */
  107. #endif
  108. /**
  109. * @}
  110. */
  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 ((uint32_t)0x00000000U) /*!< FLASH Zero Latency cycle */
  122. #define FLASH_LATENCY_1 FLASH_ACR_LATENCY /*!< 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 */
  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_Keys FLASH Keys
  152. * @{
  153. */
  154. #define FLASH_PDKEY1 ((uint32_t)0x04152637U) /*!< Flash power down key1 */
  155. #define FLASH_PDKEY2 ((uint32_t)0xFAFBFCFDU) /*!< Flash power down key2: used with FLASH_PDKEY1
  156. to unlock the RUN_PD bit in FLASH_ACR */
  157. #define FLASH_PEKEY1 ((uint32_t)0x89ABCDEFU) /*!< Flash program erase key1 */
  158. #define FLASH_PEKEY2 ((uint32_t)0x02030405U) /*!< Flash program erase key: used with FLASH_PEKEY2
  159. to unlock the write access to the FLASH_PECR register and
  160. data EEPROM */
  161. #define FLASH_PRGKEY1 ((uint32_t)0x8C9DAEBFU) /*!< Flash program memory key1 */
  162. #define FLASH_PRGKEY2 ((uint32_t)0x13141516U) /*!< Flash program memory key2: used with FLASH_PRGKEY2
  163. to unlock the program memory */
  164. #define FLASH_OPTKEY1 ((uint32_t)0xFBEAD9C8U) /*!< Flash option key1 */
  165. #define FLASH_OPTKEY2 ((uint32_t)0x24252627U) /*!< Flash option key2: used with FLASH_OPTKEY1 to
  166. unlock the write access to the option byte block */
  167. /**
  168. * @}
  169. */
  170. /* CMSIS_Legacy */
  171. #if defined ( __ICCARM__ )
  172. #define InterruptType_ACTLR_DISMCYCINT_Msk IntType_ACTLR_DISMCYCINT_Msk
  173. #endif
  174. /**
  175. * @}
  176. */
  177. /* Exported macro ------------------------------------------------------------*/
  178. /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
  179. * @brief macros to control FLASH features
  180. * @{
  181. */
  182. /** @defgroup FLASH_Interrupt FLASH Interrupts
  183. * @brief macros to handle FLASH interrupts
  184. * @{
  185. */
  186. /**
  187. * @brief Enable the specified FLASH interrupt.
  188. * @param __INTERRUPT__ FLASH interrupt
  189. * This parameter can be any combination of the following values:
  190. * @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt
  191. * @arg @ref FLASH_IT_ERR Error Interrupt
  192. * @retval none
  193. */
  194. #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) SET_BIT((FLASH->PECR), (__INTERRUPT__))
  195. /**
  196. * @brief Disable the specified FLASH interrupt.
  197. * @param __INTERRUPT__ FLASH interrupt
  198. * This parameter can be any combination of the following values:
  199. * @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt
  200. * @arg @ref FLASH_IT_ERR Error Interrupt
  201. * @retval none
  202. */
  203. #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) CLEAR_BIT((FLASH->PECR), (uint32_t)(__INTERRUPT__))
  204. /**
  205. * @brief Get the specified FLASH flag status.
  206. * @param __FLAG__ specifies the FLASH flag to check.
  207. * This parameter can be one of the following values:
  208. * @arg @ref FLASH_FLAG_BSY FLASH Busy flag
  209. * @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag
  210. * @arg @ref FLASH_FLAG_ENDHV FLASH End of High Voltage flag
  211. * @arg @ref FLASH_FLAG_READY FLASH Ready flag after low power mode
  212. * @arg @ref FLASH_FLAG_PGAERR FLASH Programming Alignment error flag
  213. * @arg @ref FLASH_FLAG_SIZERR FLASH Size error flag
  214. * @arg @ref FLASH_FLAG_OPTVERR FLASH Option validity error flag (not valid with STM32L031xx/STM32L041xx)
  215. * @arg @ref FLASH_FLAG_RDERR FLASH Read protected error flag
  216. * @arg @ref FLASH_FLAG_WRPERR FLASH Write protected error flag
  217. * @arg @ref FLASH_FLAG_FWWERR FLASH Fetch While Write Error flag
  218. * @arg @ref FLASH_FLAG_NOTZEROERR Not Zero area error flag
  219. * @retval The new state of __FLAG__ (SET or RESET).
  220. */
  221. #define __HAL_FLASH_GET_FLAG(__FLAG__) (((FLASH->SR) & (__FLAG__)) == (__FLAG__))
  222. /**
  223. * @brief Clear the specified FLASH flag.
  224. * @param __FLAG__ specifies the FLASH flags to clear.
  225. * This parameter can be any combination of the following values:
  226. * @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag
  227. * @arg @ref FLASH_FLAG_PGAERR FLASH Programming Alignment error flag
  228. * @arg @ref FLASH_FLAG_SIZERR FLASH Size error flag
  229. * @arg @ref FLASH_FLAG_OPTVERR FLASH Option validity error flag (not valid with STM32L031xx/STM32L041xx)
  230. * @arg @ref FLASH_FLAG_RDERR FLASH Read protected error flag
  231. * @arg @ref FLASH_FLAG_WRPERR FLASH Write protected error flag
  232. * @arg @ref FLASH_FLAG_FWWERR FLASH Fetch While Write Error flag
  233. * @arg @ref FLASH_FLAG_NOTZEROERR Not Zero area error flag
  234. * @retval none
  235. */
  236. #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) ((FLASH->SR) = (__FLAG__))
  237. /**
  238. * @}
  239. */
  240. /**
  241. * @}
  242. */
  243. /* Include FLASH HAL Extended module */
  244. #include "stm32l0xx_hal_flash_ex.h"
  245. #include "stm32l0xx_hal_flash_ramfunc.h"
  246. /* Exported functions --------------------------------------------------------*/
  247. /** @addtogroup FLASH_Exported_Functions
  248. * @{
  249. */
  250. /** @addtogroup FLASH_Exported_Functions_Group1
  251. * @{
  252. */
  253. /* IO operation functions *****************************************************/
  254. HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint32_t Data);
  255. HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint32_t Data);
  256. /* FLASH IRQ handler function */
  257. void HAL_FLASH_IRQHandler(void);
  258. /* Callbacks in non blocking modes */
  259. void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
  260. void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
  261. /**
  262. * @}
  263. */
  264. /** @addtogroup FLASH_Exported_Functions_Group2
  265. * @{
  266. */
  267. /* Peripheral Control functions ***********************************************/
  268. HAL_StatusTypeDef HAL_FLASH_Unlock(void);
  269. HAL_StatusTypeDef HAL_FLASH_Lock(void);
  270. HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
  271. HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
  272. HAL_StatusTypeDef HAL_FLASH_OB_Launch(void);
  273. /**
  274. * @}
  275. */
  276. /** @addtogroup FLASH_Exported_Functions_Group3
  277. * @{
  278. */
  279. /* Peripheral State and Error functions ***************************************/
  280. uint32_t HAL_FLASH_GetError(void);
  281. /**
  282. * @}
  283. */
  284. /**
  285. * @}
  286. */
  287. /* Private function -------------------------------------------------*/
  288. /** @addtogroup FLASH_Private_Functions
  289. * @{
  290. */
  291. HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout);
  292. /**
  293. * @}
  294. */
  295. /**
  296. * @}
  297. */
  298. /**
  299. * @}
  300. */
  301. #ifdef __cplusplus
  302. }
  303. #endif
  304. #endif /* __STM32L0xx_HAL_FLASH_H */
  305. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/