Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
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.
 
 
 
 
 
 

787 lines
35 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_hal_flash_ex.h
  4. * @author MCD Application Team
  5. * @brief Header file of Flash HAL Extended 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 __STM32F1xx_HAL_FLASH_EX_H
  21. #define __STM32F1xx_HAL_FLASH_EX_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32f1xx_hal_def.h"
  27. /** @addtogroup STM32F1xx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup FLASHEx
  31. * @{
  32. */
  33. /** @addtogroup FLASHEx_Private_Constants
  34. * @{
  35. */
  36. #define FLASH_SIZE_DATA_REGISTER 0x1FFFF7E0U
  37. #define OBR_REG_INDEX 1U
  38. #define SR_FLAG_MASK ((uint32_t)(FLASH_SR_BSY | FLASH_SR_PGERR | FLASH_SR_WRPRTERR | FLASH_SR_EOP))
  39. /**
  40. * @}
  41. */
  42. /** @addtogroup FLASHEx_Private_Macros
  43. * @{
  44. */
  45. #define IS_FLASH_TYPEERASE(VALUE) (((VALUE) == FLASH_TYPEERASE_PAGES) || ((VALUE) == FLASH_TYPEERASE_MASSERASE))
  46. #define IS_OPTIONBYTE(VALUE) (((VALUE) <= (OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER | OPTIONBYTE_DATA)))
  47. #define IS_WRPSTATE(VALUE) (((VALUE) == OB_WRPSTATE_DISABLE) || ((VALUE) == OB_WRPSTATE_ENABLE))
  48. #define IS_OB_RDP_LEVEL(LEVEL) (((LEVEL) == OB_RDP_LEVEL_0) || ((LEVEL) == OB_RDP_LEVEL_1))
  49. #define IS_OB_DATA_ADDRESS(ADDRESS) (((ADDRESS) == OB_DATA_ADDRESS_DATA0) || ((ADDRESS) == OB_DATA_ADDRESS_DATA1))
  50. #define IS_OB_IWDG_SOURCE(SOURCE) (((SOURCE) == OB_IWDG_SW) || ((SOURCE) == OB_IWDG_HW))
  51. #define IS_OB_STOP_SOURCE(SOURCE) (((SOURCE) == OB_STOP_NO_RST) || ((SOURCE) == OB_STOP_RST))
  52. #define IS_OB_STDBY_SOURCE(SOURCE) (((SOURCE) == OB_STDBY_NO_RST) || ((SOURCE) == OB_STDBY_RST))
  53. #if defined(FLASH_BANK2_END)
  54. #define IS_OB_BOOT1(BOOT1) (((BOOT1) == OB_BOOT1_RESET) || ((BOOT1) == OB_BOOT1_SET))
  55. #endif /* FLASH_BANK2_END */
  56. /* Low Density */
  57. #if (defined(STM32F101x6) || defined(STM32F102x6) || defined(STM32F103x6))
  58. #define IS_FLASH_NB_PAGES(ADDRESS,NBPAGES) (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x20U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)- 1 <= 0x08007FFFU) : \
  59. ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)- 1 <= 0x08003FFFU))
  60. #endif /* STM32F101x6 || STM32F102x6 || STM32F103x6 */
  61. /* Medium Density */
  62. #if (defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB))
  63. #define IS_FLASH_NB_PAGES(ADDRESS,NBPAGES) (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x80U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0801FFFFU) : \
  64. (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x40U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0800FFFFU) : \
  65. (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x20U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x08007FFFU) : \
  66. ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x08003FFFU))))
  67. #endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB*/
  68. /* High Density */
  69. #if (defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE))
  70. #define IS_FLASH_NB_PAGES(ADDRESS,NBPAGES) (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x200U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0807FFFFU) : \
  71. (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x180U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0805FFFFU) : \
  72. ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0803FFFFU)))
  73. #endif /* STM32F100xE || STM32F101xE || STM32F103xE */
  74. /* XL Density */
  75. #if defined(FLASH_BANK2_END)
  76. #define IS_FLASH_NB_PAGES(ADDRESS,NBPAGES) (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x400U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x080FFFFFU) : \
  77. ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x080BFFFFU))
  78. #endif /* FLASH_BANK2_END */
  79. /* Connectivity Line */
  80. #if (defined(STM32F105xC) || defined(STM32F107xC))
  81. #define IS_FLASH_NB_PAGES(ADDRESS,NBPAGES) (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x100U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0803FFFFU) : \
  82. (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x80U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0801FFFFU) : \
  83. ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0800FFFFU)))
  84. #endif /* STM32F105xC || STM32F107xC */
  85. #define IS_OB_WRP(PAGE) (((PAGE) != 0x0000000U))
  86. #if defined(FLASH_BANK2_END)
  87. #define IS_FLASH_BANK(BANK) (((BANK) == FLASH_BANK_1) || \
  88. ((BANK) == FLASH_BANK_2) || \
  89. ((BANK) == FLASH_BANK_BOTH))
  90. #else
  91. #define IS_FLASH_BANK(BANK) (((BANK) == FLASH_BANK_1))
  92. #endif /* FLASH_BANK2_END */
  93. /* Low Density */
  94. #if (defined(STM32F101x6) || defined(STM32F102x6) || defined(STM32F103x6))
  95. #define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x20U) ? \
  96. ((ADDRESS) <= FLASH_BANK1_END) : ((ADDRESS) <= 0x08003FFFU)))
  97. #endif /* STM32F101x6 || STM32F102x6 || STM32F103x6 */
  98. /* Medium Density */
  99. #if (defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB))
  100. #define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x80U) ? \
  101. ((ADDRESS) <= FLASH_BANK1_END) : (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x40U) ? \
  102. ((ADDRESS) <= 0x0800FFFF) : (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x20U) ? \
  103. ((ADDRESS) <= 0x08007FFF) : ((ADDRESS) <= 0x08003FFFU)))))
  104. #endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB*/
  105. /* High Density */
  106. #if (defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE))
  107. #define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x200U) ? \
  108. ((ADDRESS) <= FLASH_BANK1_END) : (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x180U) ? \
  109. ((ADDRESS) <= 0x0805FFFFU) : ((ADDRESS) <= 0x0803FFFFU))))
  110. #endif /* STM32F100xE || STM32F101xE || STM32F103xE */
  111. /* XL Density */
  112. #if defined(FLASH_BANK2_END)
  113. #define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x400U) ? \
  114. ((ADDRESS) <= FLASH_BANK2_END) : ((ADDRESS) <= 0x080BFFFFU)))
  115. #endif /* FLASH_BANK2_END */
  116. /* Connectivity Line */
  117. #if (defined(STM32F105xC) || defined(STM32F107xC))
  118. #define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x100U) ? \
  119. ((ADDRESS) <= FLASH_BANK1_END) : (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x80U) ? \
  120. ((ADDRESS) <= 0x0801FFFFU) : ((ADDRESS) <= 0x0800FFFFU))))
  121. #endif /* STM32F105xC || STM32F107xC */
  122. /**
  123. * @}
  124. */
  125. /* Exported types ------------------------------------------------------------*/
  126. /** @defgroup FLASHEx_Exported_Types FLASHEx Exported Types
  127. * @{
  128. */
  129. /**
  130. * @brief FLASH Erase structure definition
  131. */
  132. typedef struct
  133. {
  134. uint32_t TypeErase; /*!< TypeErase: Mass erase or page erase.
  135. This parameter can be a value of @ref FLASHEx_Type_Erase */
  136. uint32_t Banks; /*!< Select banks to erase when Mass erase is enabled.
  137. This parameter must be a value of @ref FLASHEx_Banks */
  138. uint32_t PageAddress; /*!< PageAdress: Initial FLASH page address to erase when mass erase is disabled
  139. This parameter must be a number between Min_Data = 0x08000000 and Max_Data = FLASH_BANKx_END
  140. (x = 1 or 2 depending on devices)*/
  141. uint32_t NbPages; /*!< NbPages: Number of pagess to be erased.
  142. This parameter must be a value between Min_Data = 1 and Max_Data = (max number of pages - value of initial page)*/
  143. } FLASH_EraseInitTypeDef;
  144. /**
  145. * @brief FLASH Options bytes program structure definition
  146. */
  147. typedef struct
  148. {
  149. uint32_t OptionType; /*!< OptionType: Option byte to be configured.
  150. This parameter can be a value of @ref FLASHEx_OB_Type */
  151. uint32_t WRPState; /*!< WRPState: Write protection activation or deactivation.
  152. This parameter can be a value of @ref FLASHEx_OB_WRP_State */
  153. uint32_t WRPPage; /*!< WRPPage: specifies the page(s) to be write protected
  154. This parameter can be a value of @ref FLASHEx_OB_Write_Protection */
  155. uint32_t Banks; /*!< Select banks for WRP activation/deactivation of all sectors.
  156. This parameter must be a value of @ref FLASHEx_Banks */
  157. uint8_t RDPLevel; /*!< RDPLevel: Set the read protection level..
  158. This parameter can be a value of @ref FLASHEx_OB_Read_Protection */
  159. #if defined(FLASH_BANK2_END)
  160. uint8_t USERConfig; /*!< USERConfig: Program the FLASH User Option Byte:
  161. IWDG / STOP / STDBY / BOOT1
  162. This parameter can be a combination of @ref FLASHEx_OB_IWatchdog, @ref FLASHEx_OB_nRST_STOP,
  163. @ref FLASHEx_OB_nRST_STDBY, @ref FLASHEx_OB_BOOT1 */
  164. #else
  165. uint8_t USERConfig; /*!< USERConfig: Program the FLASH User Option Byte:
  166. IWDG / STOP / STDBY
  167. This parameter can be a combination of @ref FLASHEx_OB_IWatchdog, @ref FLASHEx_OB_nRST_STOP,
  168. @ref FLASHEx_OB_nRST_STDBY */
  169. #endif /* FLASH_BANK2_END */
  170. uint32_t DATAAddress; /*!< DATAAddress: Address of the option byte DATA to be programmed
  171. This parameter can be a value of @ref FLASHEx_OB_Data_Address */
  172. uint8_t DATAData; /*!< DATAData: Data to be stored in the option byte DATA
  173. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF */
  174. } FLASH_OBProgramInitTypeDef;
  175. /**
  176. * @}
  177. */
  178. /* Exported constants --------------------------------------------------------*/
  179. /** @defgroup FLASHEx_Exported_Constants FLASHEx Exported Constants
  180. * @{
  181. */
  182. /** @defgroup FLASHEx_Constants FLASH Constants
  183. * @{
  184. */
  185. /** @defgroup FLASHEx_Page_Size Page Size
  186. * @{
  187. */
  188. #if (defined(STM32F101x6) || defined(STM32F102x6) || defined(STM32F103x6) || defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB))
  189. #define FLASH_PAGE_SIZE 0x400U
  190. #endif /* STM32F101x6 || STM32F102x6 || STM32F103x6 */
  191. /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */
  192. #if (defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE) || defined(STM32F101xG) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC))
  193. #define FLASH_PAGE_SIZE 0x800U
  194. #endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */
  195. /* STM32F101xG || STM32F103xG */
  196. /* STM32F105xC || STM32F107xC */
  197. /**
  198. * @}
  199. */
  200. /** @defgroup FLASHEx_Type_Erase Type Erase
  201. * @{
  202. */
  203. #define FLASH_TYPEERASE_PAGES 0x00U /*!<Pages erase only*/
  204. #define FLASH_TYPEERASE_MASSERASE 0x02U /*!<Flash mass erase activation*/
  205. /**
  206. * @}
  207. */
  208. /** @defgroup FLASHEx_Banks Banks
  209. * @{
  210. */
  211. #if defined(FLASH_BANK2_END)
  212. #define FLASH_BANK_1 1U /*!< Bank 1 */
  213. #define FLASH_BANK_2 2U /*!< Bank 2 */
  214. #define FLASH_BANK_BOTH ((uint32_t)FLASH_BANK_1 | FLASH_BANK_2) /*!< Bank1 and Bank2 */
  215. #else
  216. #define FLASH_BANK_1 1U /*!< Bank 1 */
  217. #endif
  218. /**
  219. * @}
  220. */
  221. /**
  222. * @}
  223. */
  224. /** @defgroup FLASHEx_OptionByte_Constants Option Byte Constants
  225. * @{
  226. */
  227. /** @defgroup FLASHEx_OB_Type Option Bytes Type
  228. * @{
  229. */
  230. #define OPTIONBYTE_WRP 0x01U /*!<WRP option byte configuration*/
  231. #define OPTIONBYTE_RDP 0x02U /*!<RDP option byte configuration*/
  232. #define OPTIONBYTE_USER 0x04U /*!<USER option byte configuration*/
  233. #define OPTIONBYTE_DATA 0x08U /*!<DATA option byte configuration*/
  234. /**
  235. * @}
  236. */
  237. /** @defgroup FLASHEx_OB_WRP_State Option Byte WRP State
  238. * @{
  239. */
  240. #define OB_WRPSTATE_DISABLE 0x00U /*!<Disable the write protection of the desired pages*/
  241. #define OB_WRPSTATE_ENABLE 0x01U /*!<Enable the write protection of the desired pagess*/
  242. /**
  243. * @}
  244. */
  245. /** @defgroup FLASHEx_OB_Write_Protection Option Bytes Write Protection
  246. * @{
  247. */
  248. /* STM32 Low and Medium density devices */
  249. #if defined(STM32F101x6) || defined(STM32F102x6) || defined(STM32F103x6) \
  250. || defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) \
  251. || defined(STM32F103xB)
  252. #define OB_WRP_PAGES0TO3 0x00000001U /*!< Write protection of page 0 to 3 */
  253. #define OB_WRP_PAGES4TO7 0x00000002U /*!< Write protection of page 4 to 7 */
  254. #define OB_WRP_PAGES8TO11 0x00000004U /*!< Write protection of page 8 to 11 */
  255. #define OB_WRP_PAGES12TO15 0x00000008U /*!< Write protection of page 12 to 15 */
  256. #define OB_WRP_PAGES16TO19 0x00000010U /*!< Write protection of page 16 to 19 */
  257. #define OB_WRP_PAGES20TO23 0x00000020U /*!< Write protection of page 20 to 23 */
  258. #define OB_WRP_PAGES24TO27 0x00000040U /*!< Write protection of page 24 to 27 */
  259. #define OB_WRP_PAGES28TO31 0x00000080U /*!< Write protection of page 28 to 31 */
  260. #endif /* STM32F101x6 || STM32F102x6 || STM32F103x6 */
  261. /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */
  262. /* STM32 Medium-density devices */
  263. #if defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB)
  264. #define OB_WRP_PAGES32TO35 0x00000100U /*!< Write protection of page 32 to 35 */
  265. #define OB_WRP_PAGES36TO39 0x00000200U /*!< Write protection of page 36 to 39 */
  266. #define OB_WRP_PAGES40TO43 0x00000400U /*!< Write protection of page 40 to 43 */
  267. #define OB_WRP_PAGES44TO47 0x00000800U /*!< Write protection of page 44 to 47 */
  268. #define OB_WRP_PAGES48TO51 0x00001000U /*!< Write protection of page 48 to 51 */
  269. #define OB_WRP_PAGES52TO55 0x00002000U /*!< Write protection of page 52 to 55 */
  270. #define OB_WRP_PAGES56TO59 0x00004000U /*!< Write protection of page 56 to 59 */
  271. #define OB_WRP_PAGES60TO63 0x00008000U /*!< Write protection of page 60 to 63 */
  272. #define OB_WRP_PAGES64TO67 0x00010000U /*!< Write protection of page 64 to 67 */
  273. #define OB_WRP_PAGES68TO71 0x00020000U /*!< Write protection of page 68 to 71 */
  274. #define OB_WRP_PAGES72TO75 0x00040000U /*!< Write protection of page 72 to 75 */
  275. #define OB_WRP_PAGES76TO79 0x00080000U /*!< Write protection of page 76 to 79 */
  276. #define OB_WRP_PAGES80TO83 0x00100000U /*!< Write protection of page 80 to 83 */
  277. #define OB_WRP_PAGES84TO87 0x00200000U /*!< Write protection of page 84 to 87 */
  278. #define OB_WRP_PAGES88TO91 0x00400000U /*!< Write protection of page 88 to 91 */
  279. #define OB_WRP_PAGES92TO95 0x00800000U /*!< Write protection of page 92 to 95 */
  280. #define OB_WRP_PAGES96TO99 0x01000000U /*!< Write protection of page 96 to 99 */
  281. #define OB_WRP_PAGES100TO103 0x02000000U /*!< Write protection of page 100 to 103 */
  282. #define OB_WRP_PAGES104TO107 0x04000000U /*!< Write protection of page 104 to 107 */
  283. #define OB_WRP_PAGES108TO111 0x08000000U /*!< Write protection of page 108 to 111 */
  284. #define OB_WRP_PAGES112TO115 0x10000000U /*!< Write protection of page 112 to 115 */
  285. #define OB_WRP_PAGES116TO119 0x20000000U /*!< Write protection of page 115 to 119 */
  286. #define OB_WRP_PAGES120TO123 0x40000000U /*!< Write protection of page 120 to 123 */
  287. #define OB_WRP_PAGES124TO127 0x80000000U /*!< Write protection of page 124 to 127 */
  288. #endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */
  289. /* STM32 High-density, XL-density and Connectivity line devices */
  290. #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE) \
  291. || defined(STM32F101xG) || defined(STM32F103xG) \
  292. || defined(STM32F105xC) || defined(STM32F107xC)
  293. #define OB_WRP_PAGES0TO1 0x00000001U /*!< Write protection of page 0 TO 1 */
  294. #define OB_WRP_PAGES2TO3 0x00000002U /*!< Write protection of page 2 TO 3 */
  295. #define OB_WRP_PAGES4TO5 0x00000004U /*!< Write protection of page 4 TO 5 */
  296. #define OB_WRP_PAGES6TO7 0x00000008U /*!< Write protection of page 6 TO 7 */
  297. #define OB_WRP_PAGES8TO9 0x00000010U /*!< Write protection of page 8 TO 9 */
  298. #define OB_WRP_PAGES10TO11 0x00000020U /*!< Write protection of page 10 TO 11 */
  299. #define OB_WRP_PAGES12TO13 0x00000040U /*!< Write protection of page 12 TO 13 */
  300. #define OB_WRP_PAGES14TO15 0x00000080U /*!< Write protection of page 14 TO 15 */
  301. #define OB_WRP_PAGES16TO17 0x00000100U /*!< Write protection of page 16 TO 17 */
  302. #define OB_WRP_PAGES18TO19 0x00000200U /*!< Write protection of page 18 TO 19 */
  303. #define OB_WRP_PAGES20TO21 0x00000400U /*!< Write protection of page 20 TO 21 */
  304. #define OB_WRP_PAGES22TO23 0x00000800U /*!< Write protection of page 22 TO 23 */
  305. #define OB_WRP_PAGES24TO25 0x00001000U /*!< Write protection of page 24 TO 25 */
  306. #define OB_WRP_PAGES26TO27 0x00002000U /*!< Write protection of page 26 TO 27 */
  307. #define OB_WRP_PAGES28TO29 0x00004000U /*!< Write protection of page 28 TO 29 */
  308. #define OB_WRP_PAGES30TO31 0x00008000U /*!< Write protection of page 30 TO 31 */
  309. #define OB_WRP_PAGES32TO33 0x00010000U /*!< Write protection of page 32 TO 33 */
  310. #define OB_WRP_PAGES34TO35 0x00020000U /*!< Write protection of page 34 TO 35 */
  311. #define OB_WRP_PAGES36TO37 0x00040000U /*!< Write protection of page 36 TO 37 */
  312. #define OB_WRP_PAGES38TO39 0x00080000U /*!< Write protection of page 38 TO 39 */
  313. #define OB_WRP_PAGES40TO41 0x00100000U /*!< Write protection of page 40 TO 41 */
  314. #define OB_WRP_PAGES42TO43 0x00200000U /*!< Write protection of page 42 TO 43 */
  315. #define OB_WRP_PAGES44TO45 0x00400000U /*!< Write protection of page 44 TO 45 */
  316. #define OB_WRP_PAGES46TO47 0x00800000U /*!< Write protection of page 46 TO 47 */
  317. #define OB_WRP_PAGES48TO49 0x01000000U /*!< Write protection of page 48 TO 49 */
  318. #define OB_WRP_PAGES50TO51 0x02000000U /*!< Write protection of page 50 TO 51 */
  319. #define OB_WRP_PAGES52TO53 0x04000000U /*!< Write protection of page 52 TO 53 */
  320. #define OB_WRP_PAGES54TO55 0x08000000U /*!< Write protection of page 54 TO 55 */
  321. #define OB_WRP_PAGES56TO57 0x10000000U /*!< Write protection of page 56 TO 57 */
  322. #define OB_WRP_PAGES58TO59 0x20000000U /*!< Write protection of page 58 TO 59 */
  323. #define OB_WRP_PAGES60TO61 0x40000000U /*!< Write protection of page 60 TO 61 */
  324. #define OB_WRP_PAGES62TO127 0x80000000U /*!< Write protection of page 62 TO 127 */
  325. #define OB_WRP_PAGES62TO255 0x80000000U /*!< Write protection of page 62 TO 255 */
  326. #define OB_WRP_PAGES62TO511 0x80000000U /*!< Write protection of page 62 TO 511 */
  327. #endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */
  328. /* STM32F101xG || STM32F103xG */
  329. /* STM32F105xC || STM32F107xC */
  330. #define OB_WRP_ALLPAGES 0xFFFFFFFFU /*!< Write protection of all Pages */
  331. /* Low Density */
  332. #if defined(STM32F101x6) || defined(STM32F102x6) || defined(STM32F103x6)
  333. #define OB_WRP_PAGES0TO31MASK 0x000000FFU
  334. #endif /* STM32F101x6 || STM32F102x6 || STM32F103x6 */
  335. /* Medium Density */
  336. #if defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB)
  337. #define OB_WRP_PAGES0TO31MASK 0x000000FFU
  338. #define OB_WRP_PAGES32TO63MASK 0x0000FF00U
  339. #define OB_WRP_PAGES64TO95MASK 0x00FF0000U
  340. #define OB_WRP_PAGES96TO127MASK 0xFF000000U
  341. #endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB*/
  342. /* High Density */
  343. #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE)
  344. #define OB_WRP_PAGES0TO15MASK 0x000000FFU
  345. #define OB_WRP_PAGES16TO31MASK 0x0000FF00U
  346. #define OB_WRP_PAGES32TO47MASK 0x00FF0000U
  347. #define OB_WRP_PAGES48TO255MASK 0xFF000000U
  348. #endif /* STM32F100xE || STM32F101xE || STM32F103xE */
  349. /* XL Density */
  350. #if defined(STM32F101xG) || defined(STM32F103xG)
  351. #define OB_WRP_PAGES0TO15MASK 0x000000FFU
  352. #define OB_WRP_PAGES16TO31MASK 0x0000FF00U
  353. #define OB_WRP_PAGES32TO47MASK 0x00FF0000U
  354. #define OB_WRP_PAGES48TO511MASK 0xFF000000U
  355. #endif /* STM32F101xG || STM32F103xG */
  356. /* Connectivity line devices */
  357. #if defined(STM32F105xC) || defined(STM32F107xC)
  358. #define OB_WRP_PAGES0TO15MASK 0x000000FFU
  359. #define OB_WRP_PAGES16TO31MASK 0x0000FF00U
  360. #define OB_WRP_PAGES32TO47MASK 0x00FF0000U
  361. #define OB_WRP_PAGES48TO127MASK 0xFF000000U
  362. #endif /* STM32F105xC || STM32F107xC */
  363. /**
  364. * @}
  365. */
  366. /** @defgroup FLASHEx_OB_Read_Protection Option Byte Read Protection
  367. * @{
  368. */
  369. #define OB_RDP_LEVEL_0 ((uint8_t)0xA5)
  370. #define OB_RDP_LEVEL_1 ((uint8_t)0x00)
  371. /**
  372. * @}
  373. */
  374. /** @defgroup FLASHEx_OB_IWatchdog Option Byte IWatchdog
  375. * @{
  376. */
  377. #define OB_IWDG_SW ((uint16_t)0x0001) /*!< Software IWDG selected */
  378. #define OB_IWDG_HW ((uint16_t)0x0000) /*!< Hardware IWDG selected */
  379. /**
  380. * @}
  381. */
  382. /** @defgroup FLASHEx_OB_nRST_STOP Option Byte nRST STOP
  383. * @{
  384. */
  385. #define OB_STOP_NO_RST ((uint16_t)0x0002) /*!< No reset generated when entering in STOP */
  386. #define OB_STOP_RST ((uint16_t)0x0000) /*!< Reset generated when entering in STOP */
  387. /**
  388. * @}
  389. */
  390. /** @defgroup FLASHEx_OB_nRST_STDBY Option Byte nRST STDBY
  391. * @{
  392. */
  393. #define OB_STDBY_NO_RST ((uint16_t)0x0004) /*!< No reset generated when entering in STANDBY */
  394. #define OB_STDBY_RST ((uint16_t)0x0000) /*!< Reset generated when entering in STANDBY */
  395. /**
  396. * @}
  397. */
  398. #if defined(FLASH_BANK2_END)
  399. /** @defgroup FLASHEx_OB_BOOT1 Option Byte BOOT1
  400. * @{
  401. */
  402. #define OB_BOOT1_RESET ((uint16_t)0x0000) /*!< BOOT1 Reset */
  403. #define OB_BOOT1_SET ((uint16_t)0x0008) /*!< BOOT1 Set */
  404. /**
  405. * @}
  406. */
  407. #endif /* FLASH_BANK2_END */
  408. /** @defgroup FLASHEx_OB_Data_Address Option Byte Data Address
  409. * @{
  410. */
  411. #define OB_DATA_ADDRESS_DATA0 0x1FFFF804U
  412. #define OB_DATA_ADDRESS_DATA1 0x1FFFF806U
  413. /**
  414. * @}
  415. */
  416. /**
  417. * @}
  418. */
  419. /** @addtogroup FLASHEx_Constants
  420. * @{
  421. */
  422. /** @defgroup FLASH_Flag_definition Flag definition
  423. * @brief Flag definition
  424. * @{
  425. */
  426. #if defined(FLASH_BANK2_END)
  427. #define FLASH_FLAG_BSY FLASH_FLAG_BSY_BANK1 /*!< FLASH Bank1 Busy flag */
  428. #define FLASH_FLAG_PGERR FLASH_FLAG_PGERR_BANK1 /*!< FLASH Bank1 Programming error flag */
  429. #define FLASH_FLAG_WRPERR FLASH_FLAG_WRPERR_BANK1 /*!< FLASH Bank1 Write protected error flag */
  430. #define FLASH_FLAG_EOP FLASH_FLAG_EOP_BANK1 /*!< FLASH Bank1 End of Operation flag */
  431. #define FLASH_FLAG_BSY_BANK1 FLASH_SR_BSY /*!< FLASH Bank1 Busy flag */
  432. #define FLASH_FLAG_PGERR_BANK1 FLASH_SR_PGERR /*!< FLASH Bank1 Programming error flag */
  433. #define FLASH_FLAG_WRPERR_BANK1 FLASH_SR_WRPRTERR /*!< FLASH Bank1 Write protected error flag */
  434. #define FLASH_FLAG_EOP_BANK1 FLASH_SR_EOP /*!< FLASH Bank1 End of Operation flag */
  435. #define FLASH_FLAG_BSY_BANK2 (FLASH_SR2_BSY << 16U) /*!< FLASH Bank2 Busy flag */
  436. #define FLASH_FLAG_PGERR_BANK2 (FLASH_SR2_PGERR << 16U) /*!< FLASH Bank2 Programming error flag */
  437. #define FLASH_FLAG_WRPERR_BANK2 (FLASH_SR2_WRPRTERR << 16U) /*!< FLASH Bank2 Write protected error flag */
  438. #define FLASH_FLAG_EOP_BANK2 (FLASH_SR2_EOP << 16U) /*!< FLASH Bank2 End of Operation flag */
  439. #else
  440. #define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */
  441. #define FLASH_FLAG_PGERR FLASH_SR_PGERR /*!< FLASH Programming error flag */
  442. #define FLASH_FLAG_WRPERR FLASH_SR_WRPRTERR /*!< FLASH Write protected error flag */
  443. #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Operation flag */
  444. #endif
  445. #define FLASH_FLAG_OPTVERR ((OBR_REG_INDEX << 8U | FLASH_OBR_OPTERR)) /*!< Option Byte Error */
  446. /**
  447. * @}
  448. */
  449. /** @defgroup FLASH_Interrupt_definition Interrupt definition
  450. * @brief FLASH Interrupt definition
  451. * @{
  452. */
  453. #if defined(FLASH_BANK2_END)
  454. #define FLASH_IT_EOP FLASH_IT_EOP_BANK1 /*!< End of FLASH Operation Interrupt source Bank1 */
  455. #define FLASH_IT_ERR FLASH_IT_ERR_BANK1 /*!< Error Interrupt source Bank1 */
  456. #define FLASH_IT_EOP_BANK1 FLASH_CR_EOPIE /*!< End of FLASH Operation Interrupt source Bank1 */
  457. #define FLASH_IT_ERR_BANK1 FLASH_CR_ERRIE /*!< Error Interrupt source Bank1 */
  458. #define FLASH_IT_EOP_BANK2 (FLASH_CR2_EOPIE << 16U) /*!< End of FLASH Operation Interrupt source Bank2 */
  459. #define FLASH_IT_ERR_BANK2 (FLASH_CR2_ERRIE << 16U) /*!< Error Interrupt source Bank2 */
  460. #else
  461. #define FLASH_IT_EOP FLASH_CR_EOPIE /*!< End of FLASH Operation Interrupt source */
  462. #define FLASH_IT_ERR FLASH_CR_ERRIE /*!< Error Interrupt source */
  463. #endif
  464. /**
  465. * @}
  466. */
  467. /**
  468. * @}
  469. */
  470. /**
  471. * @}
  472. */
  473. /* Exported macro ------------------------------------------------------------*/
  474. /** @defgroup FLASHEx_Exported_Macros FLASHEx Exported Macros
  475. * @{
  476. */
  477. /** @defgroup FLASH_Interrupt Interrupt
  478. * @brief macros to handle FLASH interrupts
  479. * @{
  480. */
  481. #if defined(FLASH_BANK2_END)
  482. /**
  483. * @brief Enable the specified FLASH interrupt.
  484. * @param __INTERRUPT__ FLASH interrupt
  485. * This parameter can be any combination of the following values:
  486. * @arg @ref FLASH_IT_EOP_BANK1 End of FLASH Operation Interrupt on bank1
  487. * @arg @ref FLASH_IT_ERR_BANK1 Error Interrupt on bank1
  488. * @arg @ref FLASH_IT_EOP_BANK2 End of FLASH Operation Interrupt on bank2
  489. * @arg @ref FLASH_IT_ERR_BANK2 Error Interrupt on bank2
  490. * @retval none
  491. */
  492. #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) do { \
  493. /* Enable Bank1 IT */ \
  494. SET_BIT(FLASH->CR, ((__INTERRUPT__) & 0x0000FFFFU)); \
  495. /* Enable Bank2 IT */ \
  496. SET_BIT(FLASH->CR2, ((__INTERRUPT__) >> 16U)); \
  497. } while(0U)
  498. /**
  499. * @brief Disable the specified FLASH interrupt.
  500. * @param __INTERRUPT__ FLASH interrupt
  501. * This parameter can be any combination of the following values:
  502. * @arg @ref FLASH_IT_EOP_BANK1 End of FLASH Operation Interrupt on bank1
  503. * @arg @ref FLASH_IT_ERR_BANK1 Error Interrupt on bank1
  504. * @arg @ref FLASH_IT_EOP_BANK2 End of FLASH Operation Interrupt on bank2
  505. * @arg @ref FLASH_IT_ERR_BANK2 Error Interrupt on bank2
  506. * @retval none
  507. */
  508. #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) do { \
  509. /* Disable Bank1 IT */ \
  510. CLEAR_BIT(FLASH->CR, ((__INTERRUPT__) & 0x0000FFFFU)); \
  511. /* Disable Bank2 IT */ \
  512. CLEAR_BIT(FLASH->CR2, ((__INTERRUPT__) >> 16U)); \
  513. } while(0U)
  514. /**
  515. * @brief Get the specified FLASH flag status.
  516. * @param __FLAG__ specifies the FLASH flag to check.
  517. * This parameter can be one of the following values:
  518. * @arg @ref FLASH_FLAG_EOP_BANK1 FLASH End of Operation flag on bank1
  519. * @arg @ref FLASH_FLAG_WRPERR_BANK1 FLASH Write protected error flag on bank1
  520. * @arg @ref FLASH_FLAG_PGERR_BANK1 FLASH Programming error flag on bank1
  521. * @arg @ref FLASH_FLAG_BSY_BANK1 FLASH Busy flag on bank1
  522. * @arg @ref FLASH_FLAG_EOP_BANK2 FLASH End of Operation flag on bank2
  523. * @arg @ref FLASH_FLAG_WRPERR_BANK2 FLASH Write protected error flag on bank2
  524. * @arg @ref FLASH_FLAG_PGERR_BANK2 FLASH Programming error flag on bank2
  525. * @arg @ref FLASH_FLAG_BSY_BANK2 FLASH Busy flag on bank2
  526. * @arg @ref FLASH_FLAG_OPTVERR Loaded OB and its complement do not match
  527. * @retval The new state of __FLAG__ (SET or RESET).
  528. */
  529. #define __HAL_FLASH_GET_FLAG(__FLAG__) (((__FLAG__) == FLASH_FLAG_OPTVERR) ? \
  530. (FLASH->OBR & FLASH_OBR_OPTERR) : \
  531. ((((__FLAG__) & SR_FLAG_MASK) != RESET)? \
  532. (FLASH->SR & ((__FLAG__) & SR_FLAG_MASK)) : \
  533. (FLASH->SR2 & ((__FLAG__) >> 16U))))
  534. /**
  535. * @brief Clear the specified FLASH flag.
  536. * @param __FLAG__ specifies the FLASH flags to clear.
  537. * This parameter can be any combination of the following values:
  538. * @arg @ref FLASH_FLAG_EOP_BANK1 FLASH End of Operation flag on bank1
  539. * @arg @ref FLASH_FLAG_WRPERR_BANK1 FLASH Write protected error flag on bank1
  540. * @arg @ref FLASH_FLAG_PGERR_BANK1 FLASH Programming error flag on bank1
  541. * @arg @ref FLASH_FLAG_BSY_BANK1 FLASH Busy flag on bank1
  542. * @arg @ref FLASH_FLAG_EOP_BANK2 FLASH End of Operation flag on bank2
  543. * @arg @ref FLASH_FLAG_WRPERR_BANK2 FLASH Write protected error flag on bank2
  544. * @arg @ref FLASH_FLAG_PGERR_BANK2 FLASH Programming error flag on bank2
  545. * @arg @ref FLASH_FLAG_BSY_BANK2 FLASH Busy flag on bank2
  546. * @arg @ref FLASH_FLAG_OPTVERR Loaded OB and its complement do not match
  547. * @retval none
  548. */
  549. #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) do { \
  550. /* Clear FLASH_FLAG_OPTVERR flag */ \
  551. if ((__FLAG__) == FLASH_FLAG_OPTVERR) \
  552. { \
  553. CLEAR_BIT(FLASH->OBR, FLASH_OBR_OPTERR); \
  554. } \
  555. else { \
  556. /* Clear Flag in Bank1 */ \
  557. if (((__FLAG__) & SR_FLAG_MASK) != RESET) \
  558. { \
  559. FLASH->SR = ((__FLAG__) & SR_FLAG_MASK); \
  560. } \
  561. /* Clear Flag in Bank2 */ \
  562. if (((__FLAG__) >> 16U) != RESET) \
  563. { \
  564. FLASH->SR2 = ((__FLAG__) >> 16U); \
  565. } \
  566. } \
  567. } while(0U)
  568. #else
  569. /**
  570. * @brief Enable the specified FLASH interrupt.
  571. * @param __INTERRUPT__ FLASH interrupt
  572. * This parameter can be any combination of the following values:
  573. * @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt
  574. * @arg @ref FLASH_IT_ERR Error Interrupt
  575. * @retval none
  576. */
  577. #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) (FLASH->CR |= (__INTERRUPT__))
  578. /**
  579. * @brief Disable the specified FLASH interrupt.
  580. * @param __INTERRUPT__ FLASH interrupt
  581. * This parameter can be any combination of the following values:
  582. * @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt
  583. * @arg @ref FLASH_IT_ERR Error Interrupt
  584. * @retval none
  585. */
  586. #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) (FLASH->CR &= ~(__INTERRUPT__))
  587. /**
  588. * @brief Get the specified FLASH flag status.
  589. * @param __FLAG__ specifies the FLASH flag to check.
  590. * This parameter can be one of the following values:
  591. * @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag
  592. * @arg @ref FLASH_FLAG_WRPERR FLASH Write protected error flag
  593. * @arg @ref FLASH_FLAG_PGERR FLASH Programming error flag
  594. * @arg @ref FLASH_FLAG_BSY FLASH Busy flag
  595. * @arg @ref FLASH_FLAG_OPTVERR Loaded OB and its complement do not match
  596. * @retval The new state of __FLAG__ (SET or RESET).
  597. */
  598. #define __HAL_FLASH_GET_FLAG(__FLAG__) (((__FLAG__) == FLASH_FLAG_OPTVERR) ? \
  599. (FLASH->OBR & FLASH_OBR_OPTERR) : \
  600. (FLASH->SR & (__FLAG__)))
  601. /**
  602. * @brief Clear the specified FLASH flag.
  603. * @param __FLAG__ specifies the FLASH flags to clear.
  604. * This parameter can be any combination of the following values:
  605. * @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag
  606. * @arg @ref FLASH_FLAG_WRPERR FLASH Write protected error flag
  607. * @arg @ref FLASH_FLAG_PGERR FLASH Programming error flag
  608. * @arg @ref FLASH_FLAG_OPTVERR Loaded OB and its complement do not match
  609. * @retval none
  610. */
  611. #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) do { \
  612. /* Clear FLASH_FLAG_OPTVERR flag */ \
  613. if ((__FLAG__) == FLASH_FLAG_OPTVERR) \
  614. { \
  615. CLEAR_BIT(FLASH->OBR, FLASH_OBR_OPTERR); \
  616. } \
  617. else { \
  618. /* Clear Flag in Bank1 */ \
  619. FLASH->SR = (__FLAG__); \
  620. } \
  621. } while(0U)
  622. #endif
  623. /**
  624. * @}
  625. */
  626. /**
  627. * @}
  628. */
  629. /* Exported functions --------------------------------------------------------*/
  630. /** @addtogroup FLASHEx_Exported_Functions
  631. * @{
  632. */
  633. /** @addtogroup FLASHEx_Exported_Functions_Group1
  634. * @{
  635. */
  636. /* IO operation functions *****************************************************/
  637. HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError);
  638. HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit);
  639. /**
  640. * @}
  641. */
  642. /** @addtogroup FLASHEx_Exported_Functions_Group2
  643. * @{
  644. */
  645. /* Peripheral Control functions ***********************************************/
  646. HAL_StatusTypeDef HAL_FLASHEx_OBErase(void);
  647. HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit);
  648. void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit);
  649. uint32_t HAL_FLASHEx_OBGetUserData(uint32_t DATAAdress);
  650. /**
  651. * @}
  652. */
  653. /**
  654. * @}
  655. */
  656. /**
  657. * @}
  658. */
  659. /**
  660. * @}
  661. */
  662. #ifdef __cplusplus
  663. }
  664. #endif
  665. #endif /* __STM32F1xx_HAL_FLASH_EX_H */
  666. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/