stm32l1xx_hal_flash_ex.h 50 KB

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