stm32f0xx_flash.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_flash.h
  4. * @author MCD Application Team
  5. * @version V1.0.0
  6. * @date 23-March-2012
  7. * @brief This file contains all the functions prototypes for the FLASH
  8. * firmware library.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
  13. *
  14. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  15. * You may not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at:
  17. *
  18. * http://www.st.com/software_license_agreement_liberty_v2
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS,
  22. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. *
  26. ******************************************************************************
  27. */
  28. /* Define to prevent recursive inclusion -------------------------------------*/
  29. #ifndef __STM32F0XX_FLASH_H
  30. #define __STM32F0XX_FLASH_H
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /* Includes ------------------------------------------------------------------*/
  35. #include "stm32f0xx.h"
  36. /** @addtogroup STM32F0xx_StdPeriph_Driver
  37. * @{
  38. */
  39. /** @addtogroup FLASH
  40. * @{
  41. */
  42. /* Exported types ------------------------------------------------------------*/
  43. /**
  44. * @brief FLASH Status
  45. */
  46. typedef enum
  47. {
  48. FLASH_BUSY = 1,
  49. FLASH_ERROR_WRP,
  50. FLASH_ERROR_PROGRAM,
  51. FLASH_COMPLETE,
  52. FLASH_TIMEOUT
  53. }FLASH_Status;
  54. /* Exported constants --------------------------------------------------------*/
  55. /** @defgroup FLASH_Exported_Constants
  56. * @{
  57. */
  58. /** @defgroup FLASH_Latency
  59. * @{
  60. */
  61. #define FLASH_Latency_0 ((uint32_t)0x00000000) /*!< FLASH Zero Latency cycle */
  62. #define FLASH_Latency_1 FLASH_ACR_LATENCY /*!< FLASH One Latency cycle */
  63. #define IS_FLASH_LATENCY(LATENCY) (((LATENCY) == FLASH_Latency_0) || \
  64. ((LATENCY) == FLASH_Latency_1))
  65. /**
  66. * @}
  67. */
  68. /** @defgroup FLASH_Interrupts
  69. * @{
  70. */
  71. #define FLASH_IT_EOP FLASH_CR_EOPIE /*!< End of programming interrupt source */
  72. #define FLASH_IT_ERR FLASH_CR_ERRIE /*!< Error interrupt source */
  73. #define IS_FLASH_IT(IT) ((((IT) & (uint32_t)0xFFFFEBFF) == 0x00000000) && (((IT) != 0x00000000)))
  74. /**
  75. * @}
  76. */
  77. /** @defgroup FLASH_Address
  78. * @{
  79. */
  80. #define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= 0x08000000) && ((ADDRESS) <= 0x0800FFFF))
  81. /**
  82. * @}
  83. */
  84. /** @defgroup FLASH_OB_DATA_ADDRESS
  85. * @{
  86. */
  87. #define IS_OB_DATA_ADDRESS(ADDRESS) (((ADDRESS) == 0x1FFFF804) || ((ADDRESS) == 0x1FFFF806))
  88. /**
  89. * @}
  90. */
  91. /** @defgroup FLASH_Option_Bytes_Write_Protection
  92. * @{
  93. */
  94. #define OB_WRP_Pages0to3 ((uint32_t)0x00000001) /* Write protection of page 0 to 3 */
  95. #define OB_WRP_Pages4to7 ((uint32_t)0x00000002) /* Write protection of page 4 to 7 */
  96. #define OB_WRP_Pages8to11 ((uint32_t)0x00000004) /* Write protection of page 8 to 11 */
  97. #define OB_WRP_Pages12to15 ((uint32_t)0x00000008) /* Write protection of page 12 to 15 */
  98. #define OB_WRP_Pages16to19 ((uint32_t)0x00000010) /* Write protection of page 16 to 19 */
  99. #define OB_WRP_Pages20to23 ((uint32_t)0x00000020) /* Write protection of page 20 to 23 */
  100. #define OB_WRP_Pages24to27 ((uint32_t)0x00000040) /* Write protection of page 24 to 27 */
  101. #define OB_WRP_Pages28to31 ((uint32_t)0x00000080) /* Write protection of page 28 to 31 */
  102. #define OB_WRP_Pages32to35 ((uint32_t)0x00000100) /* Write protection of page 32 to 35 */
  103. #define OB_WRP_Pages36to39 ((uint32_t)0x00000200) /* Write protection of page 36 to 39 */
  104. #define OB_WRP_Pages40to43 ((uint32_t)0x00000400) /* Write protection of page 40 to 43 */
  105. #define OB_WRP_Pages44to47 ((uint32_t)0x00000800) /* Write protection of page 44 to 47 */
  106. #define OB_WRP_Pages48to51 ((uint32_t)0x00001000) /* Write protection of page 48 to 51 */
  107. #define OB_WRP_Pages52to55 ((uint32_t)0x00002000) /* Write protection of page 52 to 55 */
  108. #define OB_WRP_Pages56to59 ((uint32_t)0x00004000) /* Write protection of page 56 to 59 */
  109. #define OB_WRP_Pages60to63 ((uint32_t)0x00008000) /* Write protection of page 60 to 63 */
  110. #define OB_WRP_AllPages ((uint32_t)0x0000FFFF) /*!< Write protection of all Sectors */
  111. #define IS_OB_WRP(PAGE) (((PAGE) != 0x0000000))
  112. /**
  113. * @}
  114. */
  115. /** @defgroup FLASH_Option_Bytes_Read_Protection
  116. * @{
  117. */
  118. /**
  119. * @brief FLASH_Read Protection Level
  120. */
  121. #define OB_RDP_Level_0 ((uint8_t)0xAA)
  122. #define OB_RDP_Level_1 ((uint8_t)0xBB)
  123. /*#define OB_RDP_Level_2 ((uint8_t)0xCC)*/ /* Warning: When enabling read protection level 2
  124. it's no more possible to go back to level 1 or 0 */
  125. #define IS_OB_RDP(LEVEL) (((LEVEL) == OB_RDP_Level_0)||\
  126. ((LEVEL) == OB_RDP_Level_1))/*||\
  127. ((LEVEL) == OB_RDP_Level_2))*/
  128. /**
  129. * @}
  130. */
  131. /** @defgroup FLASH_Option_Bytes_IWatchdog
  132. * @{
  133. */
  134. #define OB_IWDG_SW ((uint8_t)0x01) /*!< Software IWDG selected */
  135. #define OB_IWDG_HW ((uint8_t)0x00) /*!< Hardware IWDG selected */
  136. #define IS_OB_IWDG_SOURCE(SOURCE) (((SOURCE) == OB_IWDG_SW) || ((SOURCE) == OB_IWDG_HW))
  137. /**
  138. * @}
  139. */
  140. /** @defgroup FLASH_Option_Bytes_nRST_STOP
  141. * @{
  142. */
  143. #define OB_STOP_NoRST ((uint8_t)0x02) /*!< No reset generated when entering in STOP */
  144. #define OB_STOP_RST ((uint8_t)0x00) /*!< Reset generated when entering in STOP */
  145. #define IS_OB_STOP_SOURCE(SOURCE) (((SOURCE) == OB_STOP_NoRST) || ((SOURCE) == OB_STOP_RST))
  146. /**
  147. * @}
  148. */
  149. /** @defgroup FLASH_Option_Bytes_nRST_STDBY
  150. * @{
  151. */
  152. #define OB_STDBY_NoRST ((uint8_t)0x04) /*!< No reset generated when entering in STANDBY */
  153. #define OB_STDBY_RST ((uint8_t)0x00) /*!< Reset generated when entering in STANDBY */
  154. #define IS_OB_STDBY_SOURCE(SOURCE) (((SOURCE) == OB_STDBY_NoRST) || ((SOURCE) == OB_STDBY_RST))
  155. /**
  156. * @}
  157. */
  158. /** @defgroup FLASH_Option_Bytes_BOOT1
  159. * @{
  160. */
  161. #define OB_BOOT1_RESET ((uint8_t)0x00) /*!< BOOT1 Reset */
  162. #define OB_BOOT1_SET ((uint8_t)0x10) /*!< BOOT1 Set */
  163. #define IS_OB_BOOT1(BOOT1) (((BOOT1) == OB_BOOT1_RESET) || ((BOOT1) == OB_BOOT1_SET))
  164. /**
  165. * @}
  166. */
  167. /** @defgroup FLASH_Option_Bytes_VDDA_Analog_Monitoring
  168. * @{
  169. */
  170. #define OB_VDDA_ANALOG_ON ((uint8_t)0x00) /*!< Analog monitoring on VDDA Power source ON */
  171. #define OB_VDDA_ANALOG_OFF ((uint8_t)0x20) /*!< Analog monitoring on VDDA Power source OFF */
  172. #define IS_OB_VDDA_ANALOG(ANALOG) (((ANALOG) == OB_VDDA_ANALOG_ON) || ((ANALOG) == OB_VDDA_ANALOG_OFF))
  173. /**
  174. * @}
  175. */
  176. /** @defgroup FLASH_Option_Bytes_SRAM_Parity_Enable
  177. * @{
  178. */
  179. #define OB_SRAM_PARITY_SET ((uint8_t)0x00) /*!< SRAM parity enable Set */
  180. #define OB_SRAM_PARITY_RESET ((uint8_t)0x40) /*!< SRAM parity enable reset */
  181. #define IS_OB_SRAM_PARITY(PARITY) (((PARITY) == OB_SRAM_PARITY_SET) || ((PARITY) == OB_SRAM_PARITY_RESET))
  182. /**
  183. * @}
  184. */
  185. /** @defgroup FLASH_Flags
  186. * @{
  187. */
  188. #define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */
  189. #define FLASH_FLAG_PGERR FLASH_SR_PGERR /*!< FLASH Programming error flag */
  190. #define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protected error flag */
  191. #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Programming flag */
  192. #define IS_FLASH_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFFFFC3) == 0x00000000) && ((FLAG) != 0x00000000))
  193. #define IS_FLASH_GET_FLAG(FLAG) (((FLAG) == FLASH_FLAG_BSY) || ((FLAG) == FLASH_FLAG_PGERR) || \
  194. ((FLAG) == FLASH_FLAG_WRPERR) || ((FLAG) == FLASH_FLAG_EOP))
  195. /**
  196. * @}
  197. */
  198. /** @defgroup FLASH_Timeout_definition
  199. * @{
  200. */
  201. #define FLASH_ER_PRG_TIMEOUT ((uint32_t)0x000B0000)
  202. /**
  203. * @}
  204. */
  205. /**
  206. * @}
  207. */
  208. /* Exported macro ------------------------------------------------------------*/
  209. /* Exported functions ------------------------------------------------------- */
  210. /**
  211. * @brief FLASH memory functions that can be executed from FLASH.
  212. */
  213. /* FLASH Interface configuration functions ************************************/
  214. void FLASH_SetLatency(uint32_t FLASH_Latency);
  215. void FLASH_PrefetchBufferCmd(FunctionalState NewState);
  216. FlagStatus FLASH_GetPrefetchBufferStatus(void);
  217. /* FLASH Memory Programming functions *****************************************/
  218. void FLASH_Unlock(void);
  219. void FLASH_Lock(void);
  220. FLASH_Status FLASH_ErasePage(uint32_t Page_Address);
  221. FLASH_Status FLASH_EraseAllPages(void);
  222. FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data);
  223. FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data);
  224. /* FLASH Option Bytes Programming functions *****************************************/
  225. void FLASH_OB_Unlock(void);
  226. void FLASH_OB_Lock(void);
  227. void FLASH_OB_Launch(void);
  228. FLASH_Status FLASH_OB_Erase(void);
  229. FLASH_Status FLASH_OB_EnableWRP(uint32_t OB_WRP);
  230. FLASH_Status FLASH_OB_RDPConfig(uint8_t OB_RDP);
  231. FLASH_Status FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY);
  232. FLASH_Status FLASH_OB_BOOTConfig(uint8_t OB_BOOT1);
  233. FLASH_Status FLASH_OB_VDDAConfig(uint8_t OB_VDDA_ANALOG);
  234. FLASH_Status FLASH_OB_SRAMParityConfig(uint8_t OB_SRAM_Parity);
  235. FLASH_Status FLASH_OB_WriteUser(uint8_t OB_USER);
  236. FLASH_Status FLASH_ProgramOptionByteData(uint32_t Address, uint8_t Data);
  237. uint8_t FLASH_OB_GetUser(void);
  238. uint32_t FLASH_OB_GetWRP(void);
  239. FlagStatus FLASH_OB_GetRDP(void);
  240. /* FLASH Interrupts and flags management functions **********************************/
  241. void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState);
  242. FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG);
  243. void FLASH_ClearFlag(uint32_t FLASH_FLAG);
  244. FLASH_Status FLASH_GetStatus(void);
  245. FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout);
  246. #ifdef __cplusplus
  247. }
  248. #endif
  249. #endif /* __STM32F0XX_FLASH_H */
  250. /**
  251. * @}
  252. */
  253. /**
  254. * @}
  255. */
  256. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/