stm32l1xx_hal_flash_ex.h 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984
  1. /**
  2. ******************************************************************************
  3. * @file stm32l1xx_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) 2017 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32L1xx_HAL_FLASH_EX_H
  37. #define __STM32L1xx_HAL_FLASH_EX_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32l1xx_hal_def.h"
  43. /** @addtogroup STM32L1xx_HAL_Driver
  44. * @{
  45. */
  46. /** @addtogroup FLASHEx
  47. * @{
  48. */
  49. /** @addtogroup FLASHEx_Private_Constants
  50. * @{
  51. */
  52. #if defined(FLASH_SR_RDERR) && defined(FLASH_SR_OPTVERRUSR)
  53. #define FLASH_FLAG_MASK ( FLASH_FLAG_EOP | FLASH_FLAG_ENDHV | FLASH_FLAG_WRPERR | \
  54. FLASH_FLAG_OPTVERR | FLASH_FLAG_PGAERR | FLASH_FLAG_SIZERR | \
  55. FLASH_FLAG_OPTVERRUSR | FLASH_FLAG_RDERR)
  56. #elif defined(FLASH_SR_RDERR)
  57. #define FLASH_FLAG_MASK ( FLASH_FLAG_EOP | FLASH_FLAG_ENDHV | FLASH_FLAG_WRPERR | \
  58. FLASH_FLAG_OPTVERR | FLASH_FLAG_PGAERR | FLASH_FLAG_SIZERR | \
  59. FLASH_FLAG_RDERR)
  60. #elif defined(FLASH_SR_OPTVERRUSR)
  61. #define FLASH_FLAG_MASK ( FLASH_FLAG_EOP | FLASH_FLAG_ENDHV | FLASH_FLAG_WRPERR | \
  62. FLASH_FLAG_OPTVERR | FLASH_FLAG_PGAERR | FLASH_FLAG_SIZERR | \
  63. FLASH_FLAG_OPTVERRUSR)
  64. #else
  65. #define FLASH_FLAG_MASK ( FLASH_FLAG_EOP | FLASH_FLAG_ENDHV | FLASH_FLAG_WRPERR | \
  66. FLASH_FLAG_OPTVERR | FLASH_FLAG_PGAERR | FLASH_FLAG_SIZERR)
  67. #endif /* FLASH_SR_RDERR & FLASH_SR_OPTVERRUSR */
  68. #if defined(STM32L100xB) || defined(STM32L151xB) || defined(STM32L152xB) || defined(STM32L100xBA) \
  69. || defined(STM32L151xBA) || defined(STM32L152xBA)
  70. /******* Devices with FLASH 128K *******/
  71. #define FLASH_NBPAGES_MAX 512U /* 512 pages from page 0 to page 511U */
  72. #elif defined(STM32L100xC) || defined(STM32L151xC) || defined(STM32L152xC) || defined(STM32L162xC) \
  73. || defined(STM32L151xCA) || defined(STM32L152xCA) || defined(STM32L162xCA)
  74. /******* Devices with FLASH 256K *******/
  75. #define FLASH_NBPAGES_MAX 1025U /* 1025 pages from page 0 to page 1024U */
  76. #elif defined(STM32L151xD) || defined(STM32L151xDX) || defined(STM32L152xD) || defined(STM32L152xDX) \
  77. || defined(STM32L162xD) || defined(STM32L162xDX)
  78. /******* Devices with FLASH 384K *******/
  79. #define FLASH_NBPAGES_MAX 1536U /* 1536 pages from page 0 to page 1535U */
  80. #elif defined(STM32L151xE) || defined(STM32L152xE) || defined(STM32L162xE)
  81. /******* Devices with FLASH 512K *******/
  82. #define FLASH_NBPAGES_MAX 2048U /* 2048 pages from page 0 to page 2047U */
  83. #endif /* STM32L100xB || STM32L151xB || STM32L152xB || STM32L100xBA || STM32L151xBA || STM32L152xBA */
  84. #define WRP_MASK_LOW (0x0000FFFFU)
  85. #define WRP_MASK_HIGH (0xFFFF0000U)
  86. /**
  87. * @}
  88. */
  89. /** @addtogroup FLASHEx_Private_Macros
  90. * @{
  91. */
  92. #define IS_FLASH_TYPEERASE(__VALUE__) (((__VALUE__) == FLASH_TYPEERASE_PAGES))
  93. #define IS_OPTIONBYTE(__VALUE__) (((__VALUE__) <= (OPTIONBYTE_WRP|OPTIONBYTE_RDP|OPTIONBYTE_USER|OPTIONBYTE_BOR)))
  94. #define IS_WRPSTATE(__VALUE__) (((__VALUE__) == OB_WRPSTATE_DISABLE) || \
  95. ((__VALUE__) == OB_WRPSTATE_ENABLE))
  96. #define IS_OB_WRP(__PAGE__) (((__PAGE__) != 0x0000000U))
  97. #define IS_OB_RDP(__LEVEL__) (((__LEVEL__) == OB_RDP_LEVEL_0) ||\
  98. ((__LEVEL__) == OB_RDP_LEVEL_1) ||\
  99. ((__LEVEL__) == OB_RDP_LEVEL_2))
  100. #define IS_OB_BOR_LEVEL(__LEVEL__) (((__LEVEL__) == OB_BOR_OFF) || \
  101. ((__LEVEL__) == OB_BOR_LEVEL1) || \
  102. ((__LEVEL__) == OB_BOR_LEVEL2) || \
  103. ((__LEVEL__) == OB_BOR_LEVEL3) || \
  104. ((__LEVEL__) == OB_BOR_LEVEL4) || \
  105. ((__LEVEL__) == OB_BOR_LEVEL5))
  106. #define IS_OB_IWDG_SOURCE(__SOURCE__) (((__SOURCE__) == OB_IWDG_SW) || ((__SOURCE__) == OB_IWDG_HW))
  107. #define IS_OB_STOP_SOURCE(__SOURCE__) (((__SOURCE__) == OB_STOP_NORST) || ((__SOURCE__) == OB_STOP_RST))
  108. #define IS_OB_STDBY_SOURCE(__SOURCE__) (((__SOURCE__) == OB_STDBY_NORST) || ((__SOURCE__) == OB_STDBY_RST))
  109. #if defined(FLASH_OBR_SPRMOD) && defined(FLASH_OBR_nRST_BFB2)
  110. #define IS_OBEX(__VALUE__) (((__VALUE__) == OPTIONBYTE_PCROP) || ((__VALUE__) == OPTIONBYTE_BOOTCONFIG))
  111. #elif defined(FLASH_OBR_SPRMOD) && !defined(FLASH_OBR_nRST_BFB2)
  112. #define IS_OBEX(__VALUE__) ((__VALUE__) == OPTIONBYTE_PCROP)
  113. #elif !defined(FLASH_OBR_SPRMOD) && defined(FLASH_OBR_nRST_BFB2)
  114. #define IS_OBEX(__VALUE__) ((__VALUE__) == OPTIONBYTE_BOOTCONFIG)
  115. #endif /* FLASH_OBR_SPRMOD && FLASH_OBR_nRST_BFB2 */
  116. #if defined(FLASH_OBR_SPRMOD)
  117. #define IS_PCROPSTATE(__VALUE__) (((__VALUE__) == OB_PCROP_STATE_DISABLE) || \
  118. ((__VALUE__) == OB_PCROP_STATE_ENABLE))
  119. #define IS_OB_PCROP(__PAGE__) (((__PAGE__) != 0x0000000U))
  120. #endif /* FLASH_OBR_SPRMOD */
  121. #if defined(FLASH_OBR_nRST_BFB2)
  122. #define IS_OB_BOOT_BANK(__BANK__) (((__BANK__) == OB_BOOT_BANK2) || ((__BANK__) == OB_BOOT_BANK1))
  123. #endif /* FLASH_OBR_nRST_BFB2 */
  124. #define IS_TYPEERASEDATA(__VALUE__) (((__VALUE__) == FLASH_TYPEERASEDATA_BYTE) || \
  125. ((__VALUE__) == FLASH_TYPEERASEDATA_HALFWORD) || \
  126. ((__VALUE__) == FLASH_TYPEERASEDATA_WORD))
  127. #define IS_TYPEPROGRAMDATA(__VALUE__) (((__VALUE__) == FLASH_TYPEPROGRAMDATA_BYTE) || \
  128. ((__VALUE__) == FLASH_TYPEPROGRAMDATA_HALFWORD) || \
  129. ((__VALUE__) == FLASH_TYPEPROGRAMDATA_WORD) || \
  130. ((__VALUE__) == FLASH_TYPEPROGRAMDATA_FASTBYTE) || \
  131. ((__VALUE__) == FLASH_TYPEPROGRAMDATA_FASTHALFWORD) || \
  132. ((__VALUE__) == FLASH_TYPEPROGRAMDATA_FASTWORD))
  133. /** @defgroup FLASHEx_Address FLASHEx Address
  134. * @{
  135. */
  136. #define IS_FLASH_DATA_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= FLASH_EEPROM_BASE) && ((__ADDRESS__) <= FLASH_EEPROM_END))
  137. #if defined(STM32L100xB) || defined(STM32L151xB) || defined(STM32L152xB) || defined(STM32L100xBA) \
  138. || defined(STM32L151xBA) || defined(STM32L152xBA) || defined(STM32L100xC) || defined(STM32L151xC) \
  139. || defined(STM32L152xC) || defined(STM32L162xC) || defined(STM32L151xCA) || defined(STM32L152xCA) \
  140. || defined(STM32L162xCA)
  141. #define IS_FLASH_PROGRAM_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= FLASH_BASE) && ((__ADDRESS__) <= FLASH_END))
  142. #else /*STM32L151xD || STM32L152xD || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
  143. #define IS_FLASH_PROGRAM_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= FLASH_BASE) && ((__ADDRESS__) <= FLASH_BANK2_END))
  144. #define IS_FLASH_PROGRAM_BANK1_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= FLASH_BASE) && ((__ADDRESS__) <= FLASH_BANK1_END))
  145. #define IS_FLASH_PROGRAM_BANK2_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= FLASH_BANK2_BASE) && ((__ADDRESS__) <= FLASH_BANK2_END))
  146. #endif /* STM32L100xB || STM32L151xB || STM32L152xB || (...) || STM32L151xCA || STM32L152xCA || STM32L162xCA */
  147. #define IS_NBPAGES(__PAGES__) (((__PAGES__) >= 1U) && ((__PAGES__) <= FLASH_NBPAGES_MAX))
  148. /**
  149. * @}
  150. */
  151. /**
  152. * @}
  153. */
  154. /* Exported types ------------------------------------------------------------*/
  155. /** @defgroup FLASHEx_Exported_Types FLASHEx Exported Types
  156. * @{
  157. */
  158. /**
  159. * @brief FLASH Erase structure definition
  160. */
  161. typedef struct
  162. {
  163. uint32_t TypeErase; /*!< TypeErase: Page Erase only.
  164. This parameter can be a value of @ref FLASHEx_Type_Erase */
  165. uint32_t PageAddress; /*!< PageAddress: Initial FLASH address to be erased
  166. This parameter must be a value belonging to FLASH Programm address (depending on the devices) */
  167. uint32_t NbPages; /*!< NbPages: Number of pages to be erased.
  168. This parameter must be a value between 1 and (max number of pages - value of Initial page)*/
  169. } FLASH_EraseInitTypeDef;
  170. /**
  171. * @brief FLASH Option Bytes PROGRAM structure definition
  172. */
  173. typedef struct
  174. {
  175. uint32_t OptionType; /*!< OptionType: Option byte to be configured.
  176. This parameter can be a value of @ref FLASHEx_Option_Type */
  177. uint32_t WRPState; /*!< WRPState: Write protection activation or deactivation.
  178. This parameter can be a value of @ref FLASHEx_WRP_State */
  179. uint32_t WRPSector0To31; /*!< WRPSector0To31: specifies the sector(s) which are write protected between Sector 0 to 31
  180. This parameter can be a combination of @ref FLASHEx_Option_Bytes_Write_Protection1 */
  181. #if defined(STM32L100xC) || defined(STM32L151xC) || defined(STM32L152xC) || defined(STM32L162xC) \
  182. || defined(STM32L151xCA) || defined(STM32L151xD) || defined(STM32L151xDX) || defined(STM32L152xCA) \
  183. || defined(STM32L152xD) || defined(STM32L152xDX) || defined(STM32L162xCA) || defined(STM32L162xD) \
  184. || defined(STM32L162xDX) || defined(STM32L151xE) || defined(STM32L152xE) || defined(STM32L162xE)
  185. uint32_t WRPSector32To63; /*!< WRPSector32To63: specifies the sector(s) which are write protected between Sector 32 to 63
  186. This parameter can be a combination of @ref FLASHEx_Option_Bytes_Write_Protection2 */
  187. #endif /* STM32L100xC || STM32L151xC || STM32L152xC || (...) || STM32L151xE || STM32L152xE || STM32L162xE */
  188. #if defined(STM32L151xD) || defined(STM32L151xDX) || defined(STM32L152xD) || defined(STM32L152xDX) \
  189. || defined(STM32L162xD) || defined(STM32L162xDX) || defined(STM32L151xE) || defined(STM32L152xE) \
  190. || defined(STM32L162xE)
  191. uint32_t WRPSector64To95; /*!< WRPSector64to95: specifies the sector(s) which are write protected between Sector 64 to 95
  192. This parameter can be a combination of @ref FLASHEx_Option_Bytes_Write_Protection3 */
  193. #endif /* STM32L151xD || STM32L152xD || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
  194. #if defined(STM32L151xE) || defined(STM32L152xE) || defined(STM32L162xE) || defined(STM32L151xDX) \
  195. || defined(STM32L152xDX) || defined(STM32L162xDX)
  196. uint32_t WRPSector96To127; /*!< WRPSector96To127: specifies the sector(s) which are write protected between Sector 96 to 127 or
  197. Sectors 96 to 111 for STM32L1xxxDX devices.
  198. This parameter can be a combination of @ref FLASHEx_Option_Bytes_Write_Protection4 */
  199. #endif /* STM32L151xE || STM32L152xE || STM32L162xE || STM32L151xDX || ... */
  200. uint8_t RDPLevel; /*!< RDPLevel: Set the read protection level.
  201. This parameter can be a value of @ref FLASHEx_Option_Bytes_Read_Protection */
  202. uint8_t BORLevel; /*!< BORLevel: Set the BOR Level.
  203. This parameter can be a value of @ref FLASHEx_Option_Bytes_BOR_Level */
  204. uint8_t USERConfig; /*!< USERConfig: Program the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY.
  205. This parameter can be a combination of @ref FLASHEx_Option_Bytes_IWatchdog,
  206. @ref FLASHEx_Option_Bytes_nRST_STOP and @ref FLASHEx_Option_Bytes_nRST_STDBY*/
  207. } FLASH_OBProgramInitTypeDef;
  208. #if defined(FLASH_OBR_SPRMOD) || defined(FLASH_OBR_nRST_BFB2)
  209. /**
  210. * @brief FLASH Advanced Option Bytes Program structure definition
  211. */
  212. typedef struct
  213. {
  214. uint32_t OptionType; /*!< OptionType: Option byte to be configured for extension .
  215. This parameter can be a value of @ref FLASHEx_OptionAdv_Type */
  216. #if defined(FLASH_OBR_SPRMOD)
  217. uint32_t PCROPState; /*!< PCROPState: PCROP activation or deactivation.
  218. This parameter can be a value of @ref FLASHEx_PCROP_State */
  219. uint32_t PCROPSector0To31; /*!< PCROPSector0To31: specifies the sector(s) set for PCROP
  220. This parameter can be a value of @ref FLASHEx_Option_Bytes_PC_ReadWrite_Protection1 */
  221. #if defined(STM32L151xC) || defined(STM32L152xC) || defined(STM32L162xC)
  222. uint32_t PCROPSector32To63; /*!< PCROPSector32To63: specifies the sector(s) set for PCROP
  223. This parameter can be a value of @ref FLASHEx_Option_Bytes_PC_ReadWrite_Protection2 */
  224. #endif /* STM32L151xC || STM32L152xC || STM32L162xC */
  225. #endif /* FLASH_OBR_SPRMOD */
  226. #if defined(FLASH_OBR_nRST_BFB2)
  227. uint16_t BootConfig; /*!< BootConfig: specifies Option bytes for boot config
  228. This parameter can be a value of @ref FLASHEx_Option_Bytes_BOOT */
  229. #endif /* FLASH_OBR_nRST_BFB2*/
  230. } FLASH_AdvOBProgramInitTypeDef;
  231. /**
  232. * @}
  233. */
  234. #endif /* FLASH_OBR_SPRMOD || FLASH_OBR_nRST_BFB2 */
  235. /* Exported constants --------------------------------------------------------*/
  236. /** @defgroup FLASHEx_Exported_Constants FLASHEx Exported Constants
  237. * @{
  238. */
  239. /** @defgroup FLASHEx_Type_Erase FLASHEx_Type_Erase
  240. * @{
  241. */
  242. #define FLASH_TYPEERASE_PAGES (0x00U) /*!<Page erase only*/
  243. /**
  244. * @}
  245. */
  246. /** @defgroup FLASHEx_Option_Type FLASHEx Option Type
  247. * @{
  248. */
  249. #define OPTIONBYTE_WRP (0x01U) /*!<WRP option byte configuration*/
  250. #define OPTIONBYTE_RDP (0x02U) /*!<RDP option byte configuration*/
  251. #define OPTIONBYTE_USER (0x04U) /*!<USER option byte configuration*/
  252. #define OPTIONBYTE_BOR (0x08U) /*!<BOR option byte configuration*/
  253. /**
  254. * @}
  255. */
  256. /** @defgroup FLASHEx_WRP_State FLASHEx WRP State
  257. * @{
  258. */
  259. #define OB_WRPSTATE_DISABLE (0x00U) /*!<Disable the write protection of the desired sectors*/
  260. #define OB_WRPSTATE_ENABLE (0x01U) /*!<Enable the write protection of the desired sectors*/
  261. /**
  262. * @}
  263. */
  264. /** @defgroup FLASHEx_Option_Bytes_Write_Protection1 FLASHEx Option Bytes Write Protection1
  265. * @{
  266. */
  267. /* Common pages for Cat1, Cat2, Cat3, Cat4 & Cat5 devices */
  268. #define OB_WRP1_PAGES0TO15 (0x00000001U) /* Write protection of Sector0 */
  269. #define OB_WRP1_PAGES16TO31 (0x00000002U) /* Write protection of Sector1 */
  270. #define OB_WRP1_PAGES32TO47 (0x00000004U) /* Write protection of Sector2 */
  271. #define OB_WRP1_PAGES48TO63 (0x00000008U) /* Write protection of Sector3 */
  272. #define OB_WRP1_PAGES64TO79 (0x00000010U) /* Write protection of Sector4 */
  273. #define OB_WRP1_PAGES80TO95 (0x00000020U) /* Write protection of Sector5 */
  274. #define OB_WRP1_PAGES96TO111 (0x00000040U) /* Write protection of Sector6 */
  275. #define OB_WRP1_PAGES112TO127 (0x00000080U) /* Write protection of Sector7 */
  276. #define OB_WRP1_PAGES128TO143 (0x00000100U) /* Write protection of Sector8 */
  277. #define OB_WRP1_PAGES144TO159 (0x00000200U) /* Write protection of Sector9 */
  278. #define OB_WRP1_PAGES160TO175 (0x00000400U) /* Write protection of Sector10 */
  279. #define OB_WRP1_PAGES176TO191 (0x00000800U) /* Write protection of Sector11 */
  280. #define OB_WRP1_PAGES192TO207 (0x00001000U) /* Write protection of Sector12 */
  281. #define OB_WRP1_PAGES208TO223 (0x00002000U) /* Write protection of Sector13 */
  282. #define OB_WRP1_PAGES224TO239 (0x00004000U) /* Write protection of Sector14 */
  283. #define OB_WRP1_PAGES240TO255 (0x00008000U) /* Write protection of Sector15 */
  284. #define OB_WRP1_PAGES256TO271 (0x00010000U) /* Write protection of Sector16 */
  285. #define OB_WRP1_PAGES272TO287 (0x00020000U) /* Write protection of Sector17 */
  286. #define OB_WRP1_PAGES288TO303 (0x00040000U) /* Write protection of Sector18 */
  287. #define OB_WRP1_PAGES304TO319 (0x00080000U) /* Write protection of Sector19 */
  288. #define OB_WRP1_PAGES320TO335 (0x00100000U) /* Write protection of Sector20 */
  289. #define OB_WRP1_PAGES336TO351 (0x00200000U) /* Write protection of Sector21 */
  290. #define OB_WRP1_PAGES352TO367 (0x00400000U) /* Write protection of Sector22 */
  291. #define OB_WRP1_PAGES368TO383 (0x00800000U) /* Write protection of Sector23 */
  292. #define OB_WRP1_PAGES384TO399 (0x01000000U) /* Write protection of Sector24 */
  293. #define OB_WRP1_PAGES400TO415 (0x02000000U) /* Write protection of Sector25 */
  294. #define OB_WRP1_PAGES416TO431 (0x04000000U) /* Write protection of Sector26 */
  295. #define OB_WRP1_PAGES432TO447 (0x08000000U) /* Write protection of Sector27 */
  296. #define OB_WRP1_PAGES448TO463 (0x10000000U) /* Write protection of Sector28 */
  297. #define OB_WRP1_PAGES464TO479 (0x20000000U) /* Write protection of Sector29 */
  298. #define OB_WRP1_PAGES480TO495 (0x40000000U) /* Write protection of Sector30 */
  299. #define OB_WRP1_PAGES496TO511 (0x80000000U) /* Write protection of Sector31 */
  300. #define OB_WRP1_ALLPAGES ((uint32_t)FLASH_WRPR1_WRP) /*!< Write protection of all Sectors */
  301. /**
  302. * @}
  303. */
  304. #if defined(STM32L100xC) || defined(STM32L151xC) || defined(STM32L152xC) || defined(STM32L162xC) \
  305. || defined(STM32L151xCA) || defined(STM32L151xD) || defined(STM32L151xDX) || defined(STM32L152xCA) \
  306. || defined(STM32L152xD) || defined(STM32L152xDX) || defined(STM32L162xCA) || defined(STM32L162xD) \
  307. || defined(STM32L162xDX) || defined(STM32L151xE) || defined(STM32L152xE) || defined(STM32L162xE)
  308. /** @defgroup FLASHEx_Option_Bytes_Write_Protection2 FLASHEx Option Bytes Write Protection2
  309. * @{
  310. */
  311. /* Pages for Cat3, Cat4 & Cat5 devices*/
  312. #define OB_WRP2_PAGES512TO527 (0x00000001U) /* Write protection of Sector32 */
  313. #define OB_WRP2_PAGES528TO543 (0x00000002U) /* Write protection of Sector33 */
  314. #define OB_WRP2_PAGES544TO559 (0x00000004U) /* Write protection of Sector34 */
  315. #define OB_WRP2_PAGES560TO575 (0x00000008U) /* Write protection of Sector35 */
  316. #define OB_WRP2_PAGES576TO591 (0x00000010U) /* Write protection of Sector36 */
  317. #define OB_WRP2_PAGES592TO607 (0x00000020U) /* Write protection of Sector37 */
  318. #define OB_WRP2_PAGES608TO623 (0x00000040U) /* Write protection of Sector38 */
  319. #define OB_WRP2_PAGES624TO639 (0x00000080U) /* Write protection of Sector39 */
  320. #define OB_WRP2_PAGES640TO655 (0x00000100U) /* Write protection of Sector40 */
  321. #define OB_WRP2_PAGES656TO671 (0x00000200U) /* Write protection of Sector41 */
  322. #define OB_WRP2_PAGES672TO687 (0x00000400U) /* Write protection of Sector42 */
  323. #define OB_WRP2_PAGES688TO703 (0x00000800U) /* Write protection of Sector43 */
  324. #define OB_WRP2_PAGES704TO719 (0x00001000U) /* Write protection of Sector44 */
  325. #define OB_WRP2_PAGES720TO735 (0x00002000U) /* Write protection of Sector45 */
  326. #define OB_WRP2_PAGES736TO751 (0x00004000U) /* Write protection of Sector46 */
  327. #define OB_WRP2_PAGES752TO767 (0x00008000U) /* Write protection of Sector47 */
  328. #if defined(STM32L100xC) || defined(STM32L151xC) || defined(STM32L152xC) || defined(STM32L162xC) \
  329. || defined(STM32L151xCA) || defined(STM32L151xD) || defined(STM32L152xCA) || defined(STM32L152xD) \
  330. || defined(STM32L162xCA) || defined(STM32L162xD) || defined(STM32L151xE) || defined(STM32L152xE) \
  331. || defined(STM32L162xE)
  332. #define OB_WRP2_PAGES768TO783 (0x00010000U) /* Write protection of Sector48 */
  333. #define OB_WRP2_PAGES784TO799 (0x00020000U) /* Write protection of Sector49 */
  334. #define OB_WRP2_PAGES800TO815 (0x00040000U) /* Write protection of Sector50 */
  335. #define OB_WRP2_PAGES816TO831 (0x00080000U) /* Write protection of Sector51 */
  336. #define OB_WRP2_PAGES832TO847 (0x00100000U) /* Write protection of Sector52 */
  337. #define OB_WRP2_PAGES848TO863 (0x00200000U) /* Write protection of Sector53 */
  338. #define OB_WRP2_PAGES864TO879 (0x00400000U) /* Write protection of Sector54 */
  339. #define OB_WRP2_PAGES880TO895 (0x00800000U) /* Write protection of Sector55 */
  340. #define OB_WRP2_PAGES896TO911 (0x01000000U) /* Write protection of Sector56 */
  341. #define OB_WRP2_PAGES912TO927 (0x02000000U) /* Write protection of Sector57 */
  342. #define OB_WRP2_PAGES928TO943 (0x04000000U) /* Write protection of Sector58 */
  343. #define OB_WRP2_PAGES944TO959 (0x08000000U) /* Write protection of Sector59 */
  344. #define OB_WRP2_PAGES960TO975 (0x10000000U) /* Write protection of Sector60 */
  345. #define OB_WRP2_PAGES976TO991 (0x20000000U) /* Write protection of Sector61 */
  346. #define OB_WRP2_PAGES992TO1007 (0x40000000U) /* Write protection of Sector62 */
  347. #define OB_WRP2_PAGES1008TO1023 (0x80000000U) /* Write protection of Sector63 */
  348. #endif /* STM32L100xC || STM32L151xC || STM32L152xC || (...) || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
  349. #define OB_WRP2_ALLPAGES ((uint32_t)FLASH_WRPR2_WRP) /*!< Write protection of all Sectors */
  350. /**
  351. * @}
  352. */
  353. #endif /* STM32L100xC || STM32L151xC || STM32L152xC || (...) || STM32L162xD || STM32L151xDX || STM32L152xE || STM32L162xE */
  354. #if defined(STM32L151xD) || defined(STM32L151xDX) || defined(STM32L152xD) || defined(STM32L152xDX) \
  355. || defined(STM32L162xD) || defined(STM32L162xDX) || defined(STM32L151xE) || defined(STM32L152xE) \
  356. || defined(STM32L162xE)
  357. /** @defgroup FLASHEx_Option_Bytes_Write_Protection3 FLASHEx Option Bytes Write Protection3
  358. * @{
  359. */
  360. /* Pages for devices with FLASH >= 256KB*/
  361. #define OB_WRP3_PAGES1024TO1039 (0x00000001U) /* Write protection of Sector64 */
  362. #define OB_WRP3_PAGES1040TO1055 (0x00000002U) /* Write protection of Sector65 */
  363. #define OB_WRP3_PAGES1056TO1071 (0x00000004U) /* Write protection of Sector66 */
  364. #define OB_WRP3_PAGES1072TO1087 (0x00000008U) /* Write protection of Sector67 */
  365. #define OB_WRP3_PAGES1088TO1103 (0x00000010U) /* Write protection of Sector68 */
  366. #define OB_WRP3_PAGES1104TO1119 (0x00000020U) /* Write protection of Sector69 */
  367. #define OB_WRP3_PAGES1120TO1135 (0x00000040U) /* Write protection of Sector70 */
  368. #define OB_WRP3_PAGES1136TO1151 (0x00000080U) /* Write protection of Sector71 */
  369. #define OB_WRP3_PAGES1152TO1167 (0x00000100U) /* Write protection of Sector72 */
  370. #define OB_WRP3_PAGES1168TO1183 (0x00000200U) /* Write protection of Sector73 */
  371. #define OB_WRP3_PAGES1184TO1199 (0x00000400U) /* Write protection of Sector74 */
  372. #define OB_WRP3_PAGES1200TO1215 (0x00000800U) /* Write protection of Sector75 */
  373. #define OB_WRP3_PAGES1216TO1231 (0x00001000U) /* Write protection of Sector76 */
  374. #define OB_WRP3_PAGES1232TO1247 (0x00002000U) /* Write protection of Sector77 */
  375. #define OB_WRP3_PAGES1248TO1263 (0x00004000U) /* Write protection of Sector78 */
  376. #define OB_WRP3_PAGES1264TO1279 (0x00008000U) /* Write protection of Sector79 */
  377. #define OB_WRP3_PAGES1280TO1295 (0x00010000U) /* Write protection of Sector80 */
  378. #define OB_WRP3_PAGES1296TO1311 (0x00020000U) /* Write protection of Sector81 */
  379. #define OB_WRP3_PAGES1312TO1327 (0x00040000U) /* Write protection of Sector82 */
  380. #define OB_WRP3_PAGES1328TO1343 (0x00080000U) /* Write protection of Sector83 */
  381. #define OB_WRP3_PAGES1344TO1359 (0x00100000U) /* Write protection of Sector84 */
  382. #define OB_WRP3_PAGES1360TO1375 (0x00200000U) /* Write protection of Sector85 */
  383. #define OB_WRP3_PAGES1376TO1391 (0x00400000U) /* Write protection of Sector86 */
  384. #define OB_WRP3_PAGES1392TO1407 (0x00800000U) /* Write protection of Sector87 */
  385. #define OB_WRP3_PAGES1408TO1423 (0x01000000U) /* Write protection of Sector88 */
  386. #define OB_WRP3_PAGES1424TO1439 (0x02000000U) /* Write protection of Sector89 */
  387. #define OB_WRP3_PAGES1440TO1455 (0x04000000U) /* Write protection of Sector90 */
  388. #define OB_WRP3_PAGES1456TO1471 (0x08000000U) /* Write protection of Sector91 */
  389. #define OB_WRP3_PAGES1472TO1487 (0x10000000U) /* Write protection of Sector92 */
  390. #define OB_WRP3_PAGES1488TO1503 (0x20000000U) /* Write protection of Sector93 */
  391. #define OB_WRP3_PAGES1504TO1519 (0x40000000U) /* Write protection of Sector94 */
  392. #define OB_WRP3_PAGES1520TO1535 (0x80000000U) /* Write protection of Sector95 */
  393. #define OB_WRP3_ALLPAGES ((uint32_t)FLASH_WRPR3_WRP) /*!< Write protection of all Sectors */
  394. /**
  395. * @}
  396. */
  397. #endif /* STM32L151xD || STM32L152xD || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE*/
  398. #if defined(STM32L151xE) || defined(STM32L152xE) || defined(STM32L162xE) || defined(STM32L151xDX) \
  399. || defined(STM32L152xDX) || defined(STM32L162xDX)
  400. /** @defgroup FLASHEx_Option_Bytes_Write_Protection4 FLASHEx Option Bytes Write Protection4
  401. * @{
  402. */
  403. /* Pages for Cat5 devices*/
  404. #define OB_WRP4_PAGES1536TO1551 (0x00000001U)/* Write protection of Sector96*/
  405. #define OB_WRP4_PAGES1552TO1567 (0x00000002U)/* Write protection of Sector97*/
  406. #define OB_WRP4_PAGES1568TO1583 (0x00000004U)/* Write protection of Sector98*/
  407. #define OB_WRP4_PAGES1584TO1599 (0x00000008U)/* Write protection of Sector99*/
  408. #define OB_WRP4_PAGES1600TO1615 (0x00000010U) /* Write protection of Sector100*/
  409. #define OB_WRP4_PAGES1616TO1631 (0x00000020U) /* Write protection of Sector101*/
  410. #define OB_WRP4_PAGES1632TO1647 (0x00000040U) /* Write protection of Sector102*/
  411. #define OB_WRP4_PAGES1648TO1663 (0x00000080U) /* Write protection of Sector103*/
  412. #define OB_WRP4_PAGES1664TO1679 (0x00000100U) /* Write protection of Sector104*/
  413. #define OB_WRP4_PAGES1680TO1695 (0x00000200U) /* Write protection of Sector105*/
  414. #define OB_WRP4_PAGES1696TO1711 (0x00000400U) /* Write protection of Sector106*/
  415. #define OB_WRP4_PAGES1712TO1727 (0x00000800U) /* Write protection of Sector107*/
  416. #define OB_WRP4_PAGES1728TO1743 (0x00001000U) /* Write protection of Sector108*/
  417. #define OB_WRP4_PAGES1744TO1759 (0x00002000U) /* Write protection of Sector109*/
  418. #define OB_WRP4_PAGES1760TO1775 (0x00004000U) /* Write protection of Sector110*/
  419. #define OB_WRP4_PAGES1776TO1791 (0x00008000U) /* Write protection of Sector111*/
  420. #if defined(STM32L151xE) || defined(STM32L152xE) || defined(STM32L162xE)
  421. #define OB_WRP4_PAGES1792TO1807 (0x00010000U) /* Write protection of Sector112*/
  422. #define OB_WRP4_PAGES1808TO1823 (0x00020000U) /* Write protection of Sector113*/
  423. #define OB_WRP4_PAGES1824TO1839 (0x00040000U) /* Write protection of Sector114*/
  424. #define OB_WRP4_PAGES1840TO1855 (0x00080000U) /* Write protection of Sector115*/
  425. #define OB_WRP4_PAGES1856TO1871 (0x00100000U) /* Write protection of Sector116*/
  426. #define OB_WRP4_PAGES1872TO1887 (0x00200000U) /* Write protection of Sector117*/
  427. #define OB_WRP4_PAGES1888TO1903 (0x00400000U) /* Write protection of Sector118*/
  428. #define OB_WRP4_PAGES1904TO1919 (0x00800000U) /* Write protection of Sector119*/
  429. #define OB_WRP4_PAGES1920TO1935 (0x01000000U) /* Write protection of Sector120*/
  430. #define OB_WRP4_PAGES1936TO1951 (0x02000000U) /* Write protection of Sector121*/
  431. #define OB_WRP4_PAGES1952TO1967 (0x04000000U) /* Write protection of Sector122*/
  432. #define OB_WRP4_PAGES1968TO1983 (0x08000000U) /* Write protection of Sector123*/
  433. #define OB_WRP4_PAGES1984TO1999 (0x10000000U) /* Write protection of Sector124*/
  434. #define OB_WRP4_PAGES2000TO2015 (0x20000000U) /* Write protection of Sector125*/
  435. #define OB_WRP4_PAGES2016TO2031 (0x40000000U) /* Write protection of Sector126*/
  436. #define OB_WRP4_PAGES2032TO2047 (0x80000000U) /* Write protection of Sector127*/
  437. #endif /* STM32L151xE || STM32L152xE || STM32L162xE */
  438. #define OB_WRP4_ALLPAGES ((uint32_t)FLASH_WRPR4_WRP) /*!< Write protection of all Sectors */
  439. /**
  440. * @}
  441. */
  442. #endif /* STM32L151xE || STM32L152xE || STM32L162xE || STM32L151xDX || ... */
  443. /** @defgroup FLASHEx_Option_Bytes_Read_Protection FLASHEx Option Bytes Read Protection
  444. * @{
  445. */
  446. #define OB_RDP_LEVEL_0 ((uint8_t)0xAAU)
  447. #define OB_RDP_LEVEL_1 ((uint8_t)0xBBU)
  448. #define OB_RDP_LEVEL_2 ((uint8_t)0xCCU) /* Warning: When enabling read protection level 2
  449. it is no more possible to go back to level 1 or 0 */
  450. /**
  451. * @}
  452. */
  453. /** @defgroup FLASHEx_Option_Bytes_BOR_Level FLASHEx Option Bytes BOR Level
  454. * @{
  455. */
  456. #define OB_BOR_OFF ((uint8_t)0x00U) /*!< BOR is disabled at power down, the reset is asserted when the VDD
  457. power supply reaches the PDR(Power Down Reset) threshold (1.5V) */
  458. #define OB_BOR_LEVEL1 ((uint8_t)0x08U) /*!< BOR Reset threshold levels for 1.7V - 1.8V VDD power supply */
  459. #define OB_BOR_LEVEL2 ((uint8_t)0x09U) /*!< BOR Reset threshold levels for 1.9V - 2.0V VDD power supply */
  460. #define OB_BOR_LEVEL3 ((uint8_t)0x0AU) /*!< BOR Reset threshold levels for 2.3V - 2.4V VDD power supply */
  461. #define OB_BOR_LEVEL4 ((uint8_t)0x0BU) /*!< BOR Reset threshold levels for 2.55V - 2.65V VDD power supply */
  462. #define OB_BOR_LEVEL5 ((uint8_t)0x0CU) /*!< BOR Reset threshold levels for 2.8V - 2.9V VDD power supply */
  463. /**
  464. * @}
  465. */
  466. /** @defgroup FLASHEx_Option_Bytes_IWatchdog FLASHEx Option Bytes IWatchdog
  467. * @{
  468. */
  469. #define OB_IWDG_SW ((uint8_t)0x10U) /*!< Software WDG selected */
  470. #define OB_IWDG_HW ((uint8_t)0x00U) /*!< Hardware WDG selected */
  471. /**
  472. * @}
  473. */
  474. /** @defgroup FLASHEx_Option_Bytes_nRST_STOP FLASHEx Option Bytes nRST_STOP
  475. * @{
  476. */
  477. #define OB_STOP_NORST ((uint8_t)0x20U) /*!< No reset generated when entering in STOP */
  478. #define OB_STOP_RST ((uint8_t)0x00U) /*!< Reset generated when entering in STOP */
  479. /**
  480. * @}
  481. */
  482. /** @defgroup FLASHEx_Option_Bytes_nRST_STDBY FLASHEx Option Bytes nRST_STDBY
  483. * @{
  484. */
  485. #define OB_STDBY_NORST ((uint8_t)0x40U) /*!< No reset generated when entering in STANDBY */
  486. #define OB_STDBY_RST ((uint8_t)0x00U) /*!< Reset generated when entering in STANDBY */
  487. /**
  488. * @}
  489. */
  490. #if defined(FLASH_OBR_SPRMOD)
  491. /** @defgroup FLASHEx_OptionAdv_Type FLASHEx Option Advanced Type
  492. * @{
  493. */
  494. #define OPTIONBYTE_PCROP (0x01U) /*!<PCROP option byte configuration*/
  495. /**
  496. * @}
  497. */
  498. #endif /* FLASH_OBR_SPRMOD */
  499. #if defined(FLASH_OBR_nRST_BFB2)
  500. /** @defgroup FLASHEx_OptionAdv_Type FLASHEx Option Advanced Type
  501. * @{
  502. */
  503. #define OPTIONBYTE_BOOTCONFIG (0x02U) /*!<BOOTConfig option byte configuration*/
  504. /**
  505. * @}
  506. */
  507. #endif /* FLASH_OBR_nRST_BFB2 */
  508. #if defined(FLASH_OBR_SPRMOD)
  509. /** @defgroup FLASHEx_PCROP_State FLASHEx PCROP State
  510. * @{
  511. */
  512. #define OB_PCROP_STATE_DISABLE (0x00U) /*!<Disable PCROP for selected sectors */
  513. #define OB_PCROP_STATE_ENABLE (0x01U) /*!<Enable PCROP for selected sectors */
  514. /**
  515. * @}
  516. */
  517. /** @defgroup FLASHEx_Selection_Protection_Mode FLASHEx Selection Protection Mode
  518. * @{
  519. */
  520. #define OB_PCROP_DESELECTED ((uint16_t)0x0000U) /*!< Disabled PCROP, nWPRi bits used for Write Protection on sector i */
  521. #define OB_PCROP_SELECTED ((uint16_t)FLASH_OBR_SPRMOD) /*!< Enable PCROP, nWPRi bits used for PCRoP Protection on sector i */
  522. /**
  523. * @}
  524. */
  525. #endif /* FLASH_OBR_SPRMOD */
  526. #if defined(STM32L151xBA) || defined(STM32L152xBA) || defined(STM32L151xC) || defined(STM32L152xC) \
  527. || defined(STM32L162xC)
  528. /** @defgroup FLASHEx_Option_Bytes_PC_ReadWrite_Protection1 FLASHEx Option Bytes PC ReadWrite Protection 1
  529. * @{
  530. */
  531. /* Common pages for Cat1, Cat2, Cat3, Cat4 & Cat5 devices */
  532. #define OB_PCROP1_PAGES0TO15 (0x00000001U) /* PC Read/Write protection of Sector0 */
  533. #define OB_PCROP1_PAGES16TO31 (0x00000002U) /* PC Read/Write protection of Sector1 */
  534. #define OB_PCROP1_PAGES32TO47 (0x00000004U) /* PC Read/Write protection of Sector2 */
  535. #define OB_PCROP1_PAGES48TO63 (0x00000008U) /* PC Read/Write protection of Sector3 */
  536. #define OB_PCROP1_PAGES64TO79 (0x00000010U) /* PC Read/Write protection of Sector4 */
  537. #define OB_PCROP1_PAGES80TO95 (0x00000020U) /* PC Read/Write protection of Sector5 */
  538. #define OB_PCROP1_PAGES96TO111 (0x00000040U) /* PC Read/Write protection of Sector6 */
  539. #define OB_PCROP1_PAGES112TO127 (0x00000080U) /* PC Read/Write protection of Sector7 */
  540. #define OB_PCROP1_PAGES128TO143 (0x00000100U) /* PC Read/Write protection of Sector8 */
  541. #define OB_PCROP1_PAGES144TO159 (0x00000200U) /* PC Read/Write protection of Sector9 */
  542. #define OB_PCROP1_PAGES160TO175 (0x00000400U) /* PC Read/Write protection of Sector10 */
  543. #define OB_PCROP1_PAGES176TO191 (0x00000800U) /* PC Read/Write protection of Sector11 */
  544. #define OB_PCROP1_PAGES192TO207 (0x00001000U) /* PC Read/Write protection of Sector12 */
  545. #define OB_PCROP1_PAGES208TO223 (0x00002000U) /* PC Read/Write protection of Sector13 */
  546. #define OB_PCROP1_PAGES224TO239 (0x00004000U) /* PC Read/Write protection of Sector14 */
  547. #define OB_PCROP1_PAGES240TO255 (0x00008000U) /* PC Read/Write protection of Sector15 */
  548. #define OB_PCROP1_PAGES256TO271 (0x00010000U) /* PC Read/Write protection of Sector16 */
  549. #define OB_PCROP1_PAGES272TO287 (0x00020000U) /* PC Read/Write protection of Sector17 */
  550. #define OB_PCROP1_PAGES288TO303 (0x00040000U) /* PC Read/Write protection of Sector18 */
  551. #define OB_PCROP1_PAGES304TO319 (0x00080000U) /* PC Read/Write protection of Sector19 */
  552. #define OB_PCROP1_PAGES320TO335 (0x00100000U) /* PC Read/Write protection of Sector20 */
  553. #define OB_PCROP1_PAGES336TO351 (0x00200000U) /* PC Read/Write protection of Sector21 */
  554. #define OB_PCROP1_PAGES352TO367 (0x00400000U) /* PC Read/Write protection of Sector22 */
  555. #define OB_PCROP1_PAGES368TO383 (0x00800000U) /* PC Read/Write protection of Sector23 */
  556. #define OB_PCROP1_PAGES384TO399 (0x01000000U) /* PC Read/Write protection of Sector24 */
  557. #define OB_PCROP1_PAGES400TO415 (0x02000000U) /* PC Read/Write protection of Sector25 */
  558. #define OB_PCROP1_PAGES416TO431 (0x04000000U) /* PC Read/Write protection of Sector26 */
  559. #define OB_PCROP1_PAGES432TO447 (0x08000000U) /* PC Read/Write protection of Sector27 */
  560. #define OB_PCROP1_PAGES448TO463 (0x10000000U) /* PC Read/Write protection of Sector28 */
  561. #define OB_PCROP1_PAGES464TO479 (0x20000000U) /* PC Read/Write protection of Sector29 */
  562. #define OB_PCROP1_PAGES480TO495 (0x40000000U) /* PC Read/Write protection of Sector30 */
  563. #define OB_PCROP1_PAGES496TO511 (0x80000000U) /* PC Read/Write protection of Sector31 */
  564. #define OB_PCROP1_ALLPAGES (0xFFFFFFFFU) /*!< PC Read/Write protection of all Sectors */
  565. /**
  566. * @}
  567. */
  568. #endif /* STM32L151xBA || STM32L152xBA || STM32L151xC || STM32L152xC || STM32L162xC */
  569. #if defined(STM32L151xC) || defined(STM32L152xC) || defined(STM32L162xC)
  570. /** @defgroup FLASHEx_Option_Bytes_PC_ReadWrite_Protection2 FLASHEx Option Bytes PC ReadWrite Protection 2
  571. * @{
  572. */
  573. /* Pages for Cat3, Cat4 & Cat5 devices*/
  574. #define OB_PCROP2_PAGES512TO527 (0x00000001U) /* PC Read/Write protection of Sector32 */
  575. #define OB_PCROP2_PAGES528TO543 (0x00000002U) /* PC Read/Write protection of Sector33 */
  576. #define OB_PCROP2_PAGES544TO559 (0x00000004U) /* PC Read/Write protection of Sector34 */
  577. #define OB_PCROP2_PAGES560TO575 (0x00000008U) /* PC Read/Write protection of Sector35 */
  578. #define OB_PCROP2_PAGES576TO591 (0x00000010U) /* PC Read/Write protection of Sector36 */
  579. #define OB_PCROP2_PAGES592TO607 (0x00000020U) /* PC Read/Write protection of Sector37 */
  580. #define OB_PCROP2_PAGES608TO623 (0x00000040U) /* PC Read/Write protection of Sector38 */
  581. #define OB_PCROP2_PAGES624TO639 (0x00000080U) /* PC Read/Write protection of Sector39 */
  582. #define OB_PCROP2_PAGES640TO655 (0x00000100U) /* PC Read/Write protection of Sector40 */
  583. #define OB_PCROP2_PAGES656TO671 (0x00000200U) /* PC Read/Write protection of Sector41 */
  584. #define OB_PCROP2_PAGES672TO687 (0x00000400U) /* PC Read/Write protection of Sector42 */
  585. #define OB_PCROP2_PAGES688TO703 (0x00000800U) /* PC Read/Write protection of Sector43 */
  586. #define OB_PCROP2_PAGES704TO719 (0x00001000U) /* PC Read/Write protection of Sector44 */
  587. #define OB_PCROP2_PAGES720TO735 (0x00002000U) /* PC Read/Write protection of Sector45 */
  588. #define OB_PCROP2_PAGES736TO751 (0x00004000U) /* PC Read/Write protection of Sector46 */
  589. #define OB_PCROP2_PAGES752TO767 (0x00008000U) /* PC Read/Write protection of Sector47 */
  590. #define OB_PCROP2_PAGES768TO783 (0x00010000U) /* PC Read/Write protection of Sector48 */
  591. #define OB_PCROP2_PAGES784TO799 (0x00020000U) /* PC Read/Write protection of Sector49 */
  592. #define OB_PCROP2_PAGES800TO815 (0x00040000U) /* PC Read/Write protection of Sector50 */
  593. #define OB_PCROP2_PAGES816TO831 (0x00080000U) /* PC Read/Write protection of Sector51 */
  594. #define OB_PCROP2_PAGES832TO847 (0x00100000U) /* PC Read/Write protection of Sector52 */
  595. #define OB_PCROP2_PAGES848TO863 (0x00200000U) /* PC Read/Write protection of Sector53 */
  596. #define OB_PCROP2_PAGES864TO879 (0x00400000U) /* PC Read/Write protection of Sector54 */
  597. #define OB_PCROP2_PAGES880TO895 (0x00800000U) /* PC Read/Write protection of Sector55 */
  598. #define OB_PCROP2_PAGES896TO911 (0x01000000U) /* PC Read/Write protection of Sector56 */
  599. #define OB_PCROP2_PAGES912TO927 (0x02000000U) /* PC Read/Write protection of Sector57 */
  600. #define OB_PCROP2_PAGES928TO943 (0x04000000U) /* PC Read/Write protection of Sector58 */
  601. #define OB_PCROP2_PAGES944TO959 (0x08000000U) /* PC Read/Write protection of Sector59 */
  602. #define OB_PCROP2_PAGES960TO975 (0x10000000U) /* PC Read/Write protection of Sector60 */
  603. #define OB_PCROP2_PAGES976TO991 (0x20000000U) /* PC Read/Write protection of Sector61 */
  604. #define OB_PCROP2_PAGES992TO1007 (0x40000000U) /* PC Read/Write protection of Sector62 */
  605. #define OB_PCROP2_PAGES1008TO1023 (0x80000000U) /* PC Read/Write protection of Sector63 */
  606. #define OB_PCROP2_ALLPAGES (0xFFFFFFFFU) /*!< PC Read/Write protection of all Sectors */
  607. /**
  608. * @}
  609. */
  610. #endif /* STM32L151xC || STM32L152xC || STM32L162xC */
  611. /** @defgroup FLASHEx_Type_Erase_Data FLASHEx Type Erase Data
  612. * @{
  613. */
  614. #define FLASH_TYPEERASEDATA_BYTE (0x00U) /*!<Erase byte (8-bit) at a specified address.*/
  615. #define FLASH_TYPEERASEDATA_HALFWORD (0x01U) /*!<Erase a half-word (16-bit) at a specified address.*/
  616. #define FLASH_TYPEERASEDATA_WORD (0x02U) /*!<Erase a word (32-bit) at a specified address.*/
  617. /**
  618. * @}
  619. */
  620. /** @defgroup FLASHEx_Type_Program_Data FLASHEx Type Program Data
  621. * @{
  622. */
  623. #define FLASH_TYPEPROGRAMDATA_BYTE (0x00U) /*!<Program byte (8-bit) at a specified address.*/
  624. #define FLASH_TYPEPROGRAMDATA_HALFWORD (0x01U) /*!<Program a half-word (16-bit) at a specified address.*/
  625. #define FLASH_TYPEPROGRAMDATA_WORD (0x02U) /*!<Program a word (32-bit) at a specified address.*/
  626. #define FLASH_TYPEPROGRAMDATA_FASTBYTE (0x04U) /*!<Fast Program byte (8-bit) at a specified address.*/
  627. #define FLASH_TYPEPROGRAMDATA_FASTHALFWORD (0x08U) /*!<Fast Program a half-word (16-bit) at a specified address.*/
  628. #define FLASH_TYPEPROGRAMDATA_FASTWORD (0x10U) /*!<Fast Program a word (32-bit) at a specified address.*/
  629. /**
  630. * @}
  631. */
  632. #if defined(FLASH_OBR_nRST_BFB2)
  633. /** @defgroup FLASHEx_Option_Bytes_BOOT FLASHEx Option Bytes BOOT
  634. * @{
  635. */
  636. #define OB_BOOT_BANK2 ((uint8_t)0x00U) /*!< At startup, if boot pins are set in boot from user Flash position
  637. and this parameter is selected the device will boot from Bank 2
  638. or Bank 1, depending on the activation of the bank */
  639. #define OB_BOOT_BANK1 ((uint8_t)(FLASH_OBR_nRST_BFB2 >> 16U)) /*!< At startup, if boot pins are set in boot from user Flash position
  640. and this parameter is selected the device will boot from Bank1(Default) */
  641. /**
  642. * @}
  643. */
  644. #endif /* FLASH_OBR_nRST_BFB2 */
  645. /**
  646. * @}
  647. */
  648. /* Exported macro ------------------------------------------------------------*/
  649. /** @defgroup FLASHEx_Exported_Macros FLASHEx Exported Macros
  650. * @{
  651. */
  652. /**
  653. * @brief Set the FLASH Latency.
  654. * @param __LATENCY__ FLASH Latency
  655. * This parameter can be one of the following values:
  656. * @arg @ref FLASH_LATENCY_0 FLASH Zero Latency cycle
  657. * @arg @ref FLASH_LATENCY_1 FLASH One Latency cycle
  658. * @retval none
  659. */
  660. #define __HAL_FLASH_SET_LATENCY(__LATENCY__) do { \
  661. if ((__LATENCY__) == FLASH_LATENCY_1) {__HAL_FLASH_ACC64_ENABLE();} \
  662. MODIFY_REG((FLASH->ACR), FLASH_ACR_LATENCY, (__LATENCY__)); \
  663. } while(0U)
  664. /**
  665. * @brief Get the FLASH Latency.
  666. * @retval FLASH Latency
  667. * This parameter can be one of the following values:
  668. * @arg @ref FLASH_LATENCY_0 FLASH Zero Latency cycle
  669. * @arg @ref FLASH_LATENCY_1 FLASH One Latency cycle
  670. */
  671. #define __HAL_FLASH_GET_LATENCY() (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY))
  672. /**
  673. * @brief Enable the FLASH 64-bit access.
  674. * @note Read access 64 bit is used.
  675. * @note This bit cannot be written at the same time as the LATENCY and
  676. * PRFTEN bits.
  677. * @retval none
  678. */
  679. #define __HAL_FLASH_ACC64_ENABLE() (SET_BIT((FLASH->ACR), FLASH_ACR_ACC64))
  680. /**
  681. * @brief Disable the FLASH 64-bit access.
  682. * @note Read access 32 bit is used
  683. * @note To reset this bit, the LATENCY should be zero wait state and the
  684. * prefetch off.
  685. * @retval none
  686. */
  687. #define __HAL_FLASH_ACC64_DISABLE() (CLEAR_BIT((FLASH->ACR), FLASH_ACR_ACC64))
  688. /**
  689. * @brief Enable the FLASH prefetch buffer.
  690. * @retval none
  691. */
  692. #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() do { __HAL_FLASH_ACC64_ENABLE(); \
  693. SET_BIT((FLASH->ACR), FLASH_ACR_PRFTEN); \
  694. } while(0U)
  695. /**
  696. * @brief Disable the FLASH prefetch buffer.
  697. * @retval none
  698. */
  699. #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() CLEAR_BIT((FLASH->ACR), FLASH_ACR_PRFTEN)
  700. /**
  701. * @brief Enable the FLASH power down during Sleep mode
  702. * @retval none
  703. */
  704. #define __HAL_FLASH_SLEEP_POWERDOWN_ENABLE() SET_BIT(FLASH->ACR, FLASH_ACR_SLEEP_PD)
  705. /**
  706. * @brief Disable the FLASH power down during Sleep mode
  707. * @retval none
  708. */
  709. #define __HAL_FLASH_SLEEP_POWERDOWN_DISABLE() CLEAR_BIT(FLASH->ACR, FLASH_ACR_SLEEP_PD)
  710. /**
  711. * @brief Enable the Flash Run power down mode.
  712. * @note Writing this bit to 0 this bit, automatically the keys are
  713. * loss and a new unlock sequence is necessary to re-write it to 1.
  714. */
  715. #define __HAL_FLASH_POWER_DOWN_ENABLE() do { FLASH->PDKEYR = FLASH_PDKEY1; \
  716. FLASH->PDKEYR = FLASH_PDKEY2; \
  717. SET_BIT((FLASH->ACR), FLASH_ACR_RUN_PD); \
  718. } while (0U)
  719. /**
  720. * @brief Disable the Flash Run power down mode.
  721. * @note Writing this bit to 0 this bit, automatically the keys are
  722. * loss and a new unlock sequence is necessary to re-write it to 1.
  723. */
  724. #define __HAL_FLASH_POWER_DOWN_DISABLE() do { FLASH->PDKEYR = FLASH_PDKEY1; \
  725. FLASH->PDKEYR = FLASH_PDKEY2; \
  726. CLEAR_BIT((FLASH->ACR), FLASH_ACR_RUN_PD); \
  727. } while (0U)
  728. /**
  729. * @}
  730. */
  731. /* Exported functions --------------------------------------------------------*/
  732. /** @addtogroup FLASHEx_Exported_Functions
  733. * @{
  734. */
  735. /** @addtogroup FLASHEx_Exported_Functions_Group1
  736. * @{
  737. */
  738. HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError);
  739. HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit);
  740. /**
  741. * @}
  742. */
  743. /** @addtogroup FLASHEx_Exported_Functions_Group2
  744. * @{
  745. */
  746. HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit);
  747. void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit);
  748. #if defined(FLASH_OBR_SPRMOD) || defined(FLASH_OBR_nRST_BFB2)
  749. HAL_StatusTypeDef HAL_FLASHEx_AdvOBProgram (FLASH_AdvOBProgramInitTypeDef *pAdvOBInit);
  750. void HAL_FLASHEx_AdvOBGetConfig(FLASH_AdvOBProgramInitTypeDef *pAdvOBInit);
  751. #endif /* FLASH_OBR_SPRMOD || FLASH_OBR_nRST_BFB2 */
  752. #if defined(FLASH_OBR_SPRMOD)
  753. HAL_StatusTypeDef HAL_FLASHEx_OB_SelectPCROP(void);
  754. HAL_StatusTypeDef HAL_FLASHEx_OB_DeSelectPCROP(void);
  755. #endif /* FLASH_OBR_SPRMOD */
  756. /**
  757. * @}
  758. */
  759. /** @addtogroup FLASHEx_Exported_Functions_Group3
  760. * @{
  761. */
  762. HAL_StatusTypeDef HAL_FLASHEx_DATAEEPROM_Unlock(void);
  763. HAL_StatusTypeDef HAL_FLASHEx_DATAEEPROM_Lock(void);
  764. HAL_StatusTypeDef HAL_FLASHEx_DATAEEPROM_Erase(uint32_t TypeErase, uint32_t Address);
  765. HAL_StatusTypeDef HAL_FLASHEx_DATAEEPROM_Program(uint32_t TypeProgram, uint32_t Address, uint32_t Data);
  766. void HAL_FLASHEx_DATAEEPROM_EnableFixedTimeProgram(void);
  767. void HAL_FLASHEx_DATAEEPROM_DisableFixedTimeProgram(void);
  768. /**
  769. * @}
  770. */
  771. /**
  772. * @}
  773. */
  774. /**
  775. * @}
  776. */
  777. /**
  778. * @}
  779. */
  780. #ifdef __cplusplus
  781. }
  782. #endif
  783. #endif /* __STM32L1xx_HAL_FLASH_EX_H */
  784. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/