1 /** 2 ****************************************************************************** 3 * @file stm32c0xx_hal_flash.h 4 * @author MCD Application Team 5 * @brief Header file of FLASH HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2022 STMicroelectronics. 10 * All rights reserved. 11 * 12 * This software is licensed under terms that can be found in the LICENSE file 13 * in the root directory of this software component. 14 * If no LICENSE file comes with this software, it is provided AS-IS. 15 * 16 ****************************************************************************** 17 */ 18 19 /* Define to prevent recursive inclusion -------------------------------------*/ 20 #ifndef STM32C0xx_HAL_FLASH_H 21 #define STM32C0xx_HAL_FLASH_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32c0xx_hal_def.h" 29 30 /** @addtogroup STM32C0xx_HAL_Driver 31 * @{ 32 */ 33 34 /** @addtogroup FLASH 35 * @{ 36 */ 37 38 /* Exported types ------------------------------------------------------------*/ 39 /** @defgroup FLASH_Exported_Types FLASH Exported Types 40 * @{ 41 */ 42 43 /** 44 * @brief FLASH Erase structure definition 45 */ 46 typedef struct 47 { 48 uint32_t TypeErase; /*!< Mass erase or page erase. 49 This parameter can be a value of @ref FLASH_Type_Erase */ 50 uint32_t Page; /*!< Initial Flash page to erase when page erase is enabled 51 This parameter must be a value between 0 and (FLASH_PAGE_NB - 1) */ 52 uint32_t NbPages; /*!< Number of pages to be erased. 53 This parameter must be a value between 1 and (FLASH_PAGE_NB - value of initial page)*/ 54 } FLASH_EraseInitTypeDef; 55 56 /** 57 * @brief FLASH Option Bytes Program structure definition 58 */ 59 typedef struct 60 { 61 uint32_t OptionType; /*!< Option byte to be configured. 62 This parameter can be a combination of the values of @ref FLASH_OB_Type */ 63 uint32_t WRPArea; /*!< Write protection area to be programmed (used for OPTIONBYTE_WRP). 64 Only one WRP area could be programmed at the same time. 65 This parameter can be value of @ref FLASH_OB_WRP_Area */ 66 uint32_t WRPStartOffset; /*!< Write protection start offset (used for OPTIONBYTE_WRP). 67 This parameter must be a value between 0 and [FLASH_PAGE_NB - 1]*/ 68 uint32_t WRPEndOffset; /*!< Write protection end offset (used for OPTIONBYTE_WRP). 69 This parameter must be a value between WRPStartOffset and [FLASH_PAGE_NB - 1] */ 70 uint32_t RDPLevel; /*!< Set the read protection level (used for OPTIONBYTE_RDP). 71 This parameter can be a value of @ref FLASH_OB_Read_Protection */ 72 uint32_t USERType; /*!< User option byte(s) to be configured (used for OPTIONBYTE_USER). 73 This parameter can be a combination of @ref FLASH_OB_USER_Type */ 74 uint32_t USERConfig; /*!< Value of the user option byte (used for OPTIONBYTE_USER). 75 This parameter can be a combination of 76 @ref FLASH_OB_USER_BOR_ENABLE, 77 @ref FLASH_OB_USER_BOR_LEVEL, 78 @ref FLASH_OB_USER_nRST_STOP, 79 @ref FLASH_OB_USER_nRST_STANDBY, 80 @ref FLASH_OB_USER_nRST_SHUTDOWN, 81 @ref FLASH_OB_USER_IWDG_SW, 82 @ref FLASH_OB_USER_IWDG_STOP, 83 @ref FLASH_OB_USER_IWDG_STANDBY, 84 @ref FLASH_OB_USER_WWDG_SW, 85 @ref FLASH_OB_USER_SRAM_PARITY, 86 @ref FLASH_OB_USER_nBOOT_SEL, 87 @ref FLASH_OB_USER_nBOOT1, 88 @ref FLASH_OB_USER_nBOOT0, 89 @ref FLASH_OB_USER_INPUT_RESET_HOLDER*/ 90 uint32_t PCROPConfig; /*!< Configuration of the PCROP (used for OPTIONBYTE_PCROP). 91 This parameter must be a combination of @ref FLASH_OB_PCROP_ZONE 92 and @ref FLASH_OB_PCROP_RDP. Note that once set, Pcrop erase on RDP level 1 93 regression (PCROP_RDP bit) can not be reset. It will be reset by mass erase */ 94 uint32_t PCROP1AStartAddr; /*!< PCROP Start address (used for OPTIONBYTE_PCROP). It represents first address 95 of start block to protect. Make sure this parameter is multiple of PCROP 96 granularity: 512 Bytes.*/ 97 uint32_t PCROP1AEndAddr; /*!< PCROP End address (used for OPTIONBYTE_PCROP). It represents first address 98 of end block to protect. Make sure this parameter is multiple of PCROP 99 granularity: 512 Bytes.*/ 100 uint32_t PCROP1BStartAddr; /*!< PCROP Start address (used for OPTIONBYTE_PCROP). It represents first address 101 of start block to protect. Make sure this parameter is multiple of PCROP 102 granularity: 512 Bytes.*/ 103 uint32_t PCROP1BEndAddr; /*!< PCROP End address (used for OPTIONBYTE_PCROP). It represents first address 104 of end block to protect. Make sure this parameter is multiple of PCROP 105 granularity: 512 Bytes.*/ 106 uint32_t BootEntryPoint; /*!< Allow to force a unique boot entry point to Flash or system Flash */ 107 uint32_t SecSize; /*!< This parameter defines securable memory area width in number of pages starting 108 from Flash base address. This parameter must be a value between [0] 109 and [FLASH_PAGE_NB], [0] meaning no secure area defined, [1] meaning first page 110 only protected, etc... */ 111 } FLASH_OBProgramInitTypeDef; 112 113 /** 114 * @brief FLASH handle Structure definition 115 */ 116 typedef struct 117 { 118 HAL_LockTypeDef Lock; /* FLASH locking object */ 119 uint32_t ErrorCode; /* FLASH error code */ 120 uint32_t ProcedureOnGoing; /* Internal variable to indicate which procedure is ongoing or not in IT context */ 121 uint32_t Address; /* Internal variable to save address selected for program in IT context */ 122 uint32_t Page; /* Internal variable to define the current page which is erasing in IT context */ 123 uint32_t NbPagesToErase; /* Internal variable to save the remaining pages to erase in IT context */ 124 } FLASH_ProcessTypeDef; 125 126 /** 127 * @} 128 */ 129 130 /* Exported constants --------------------------------------------------------*/ 131 /** @defgroup FLASH_Exported_Constants FLASH Exported Constants 132 * @{ 133 */ 134 /** @defgroup FLASH_Keys FLASH Keys 135 * @{ 136 */ 137 #define FLASH_KEY1 0x45670123U /*!< Flash key1 */ 138 #define FLASH_KEY2 0xCDEF89ABU /*!< Flash key2: used with FLASH_KEY1 139 to unlock the FLASH registers access */ 140 #define FLASH_OPTKEY1 0x08192A3BU /*!< Flash option byte key1 */ 141 #define FLASH_OPTKEY2 0x4C5D6E7FU /*!< Flash option byte key2: used with FLASH_OPTKEY1 142 to allow option bytes operations */ 143 /** 144 * @} 145 */ 146 147 /** @defgroup FLASH_Latency FLASH Latency 148 * @{ 149 */ 150 #define FLASH_LATENCY_0 0x00000000UL /*!< FLASH Zero wait state */ 151 #define FLASH_LATENCY_1 FLASH_ACR_LATENCY_0 /*!< FLASH One wait state */ 152 153 /** 154 * @} 155 */ 156 157 /** @defgroup FLASH_Flags FLASH Flags Definition 158 * @{ 159 */ 160 #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of operation flag */ 161 #define FLASH_FLAG_OPERR FLASH_SR_OPERR /*!< FLASH Operation error flag */ 162 #define FLASH_FLAG_PROGERR FLASH_SR_PROGERR /*!< FLASH Programming error flag */ 163 #define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protection error flag */ 164 #define FLASH_FLAG_PGAERR FLASH_SR_PGAERR /*!< FLASH Programming alignment error flag */ 165 #define FLASH_FLAG_SIZERR FLASH_SR_SIZERR /*!< FLASH Size error flag */ 166 #define FLASH_FLAG_PGSERR FLASH_SR_PGSERR /*!< FLASH Programming sequence error flag */ 167 #define FLASH_FLAG_MISERR FLASH_SR_MISERR /*!< FLASH Fast programming data miss error flag */ 168 #define FLASH_FLAG_FASTERR FLASH_SR_FASTERR /*!< FLASH Fast programming error flag */ 169 #define FLASH_FLAG_RDERR FLASH_SR_RDERR /*!< FLASH PCROP read error flag */ 170 #define FLASH_FLAG_OPTVERR FLASH_SR_OPTVERR /*!< FLASH Option validity error flag */ 171 #define FLASH_FLAG_BSY FLASH_SR_BSY1 /*!< FLASH Operation Busy flag */ 172 #define FLASH_FLAG_CFGBSY FLASH_SR_CFGBSY /*!< FLASH Configuration Busy flag */ 173 #define FLASH_FLAG_PESD FLASH_SR_PESD /*!< FLASH Programming/erase operation suspended */ 174 175 #define FLASH_FLAG_ALL_ERRORS (FLASH_FLAG_OPERR | FLASH_FLAG_PROGERR | FLASH_FLAG_WRPERR | \ 176 FLASH_FLAG_PGAERR | FLASH_FLAG_SIZERR | FLASH_FLAG_PGSERR | \ 177 FLASH_FLAG_MISERR | FLASH_FLAG_FASTERR | FLASH_FLAG_RDERR | \ 178 FLASH_FLAG_OPTVERR) 179 /** 180 * @} 181 */ 182 183 /** @defgroup FLASH_Interrupt_definition FLASH Interrupts Definition 184 * @brief FLASH Interrupt definition 185 * @{ 186 */ 187 #define FLASH_IT_EOP FLASH_CR_EOPIE /*!< End of FLASH Operation Interrupt source */ 188 #define FLASH_IT_OPERR FLASH_CR_ERRIE /*!< Error Interrupt source */ 189 #define FLASH_IT_RDERR FLASH_CR_RDERRIE /*!< PCROP Read Error Interrupt source*/ 190 /** 191 * @} 192 */ 193 194 /** @defgroup FLASH_Error FLASH Error 195 * @{ 196 */ 197 #define HAL_FLASH_ERROR_NONE 0x00000000U 198 #define HAL_FLASH_ERROR_OP FLASH_FLAG_OPERR 199 #define HAL_FLASH_ERROR_PROG FLASH_FLAG_PROGERR 200 #define HAL_FLASH_ERROR_WRP FLASH_FLAG_WRPERR 201 #define HAL_FLASH_ERROR_PGA FLASH_FLAG_PGAERR 202 #define HAL_FLASH_ERROR_SIZ FLASH_FLAG_SIZERR 203 #define HAL_FLASH_ERROR_PGS FLASH_FLAG_PGSERR 204 #define HAL_FLASH_ERROR_MIS FLASH_FLAG_MISERR 205 #define HAL_FLASH_ERROR_FAST FLASH_FLAG_FASTERR 206 #define HAL_FLASH_ERROR_RD FLASH_FLAG_RDERR 207 #define HAL_FLASH_ERROR_OPTV FLASH_FLAG_OPTVERR 208 /** 209 * @} 210 */ 211 212 /** @defgroup FLASH_Type_Erase FLASH Erase Type 213 * @{ 214 */ 215 #define FLASH_TYPEERASE_PAGES FLASH_CR_PER /*!< Pages erase only */ 216 #define FLASH_TYPEERASE_MASS FLASH_CR_MER1 /*!< Flash mass erase activation */ 217 /** 218 * @} 219 */ 220 221 /** @defgroup FLASH_Type_Program FLASH Program Type 222 * @{ 223 */ 224 #define FLASH_TYPEPROGRAM_DOUBLEWORD FLASH_CR_PG /*!< Program a double-word (64-bit) at a specified address */ 225 #define FLASH_TYPEPROGRAM_FAST FLASH_CR_FSTPG /*!< Fast program a 32 row double-word (64-bit) 226 at a specified address */ 227 /** 228 * @} 229 */ 230 231 /** @defgroup FLASH_OB_Type FLASH Option Bytes Type 232 * @{ 233 */ 234 #define OPTIONBYTE_WRP 0x00000001U /*!< WRP option byte configuration */ 235 #define OPTIONBYTE_RDP 0x00000002U /*!< RDP option byte configuration */ 236 #define OPTIONBYTE_USER 0x00000004U /*!< USER option byte configuration */ 237 #define OPTIONBYTE_PCROP 0x00000008U /*!< PCROP option byte configuration */ 238 #define OPTIONBYTE_SEC 0x00000010U /*!< SEC option byte configuration */ 239 #define OPTIONBYTE_ALL (OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER) /*!< All option byte 240 configuration */ 241 242 /** 243 * @} 244 */ 245 246 /** @defgroup FLASH_OB_WRP_Area FLASH WRP Area 247 * @{ 248 */ 249 #define OB_WRPAREA_ZONE_A 0x00000001U /*!< Flash Zone A */ 250 #define OB_WRPAREA_ZONE_B 0x00000002U /*!< Flash Zone B */ 251 /** 252 * @} 253 */ 254 255 /** @defgroup FLASH_OB_Read_Protection FLASH Option Bytes Read Protection 256 * @{ 257 */ 258 #define OB_RDP_LEVEL_0 0x000000AAU 259 #define OB_RDP_LEVEL_1 0x000000BBU 260 #define OB_RDP_LEVEL_2 0x000000CCU /*!< Warning: When enabling read protection level 2 261 it is no more possible to go back to level 1 or 0 */ 262 /** 263 * @} 264 */ 265 266 /** @defgroup FLASH_OB_USER_Type FLASH Option Bytes User Type 267 * @{ 268 */ 269 #define OB_USER_BOR_EN FLASH_OPTR_BOR_EN /*!< BOR reset enable */ 270 #define OB_USER_BOR_LEV (FLASH_OPTR_BORF_LEV | FLASH_OPTR_BORR_LEV) /*!< BOR reset Level */ 271 #define OB_USER_NRST_STOP FLASH_OPTR_nRST_STOP /*!< Reset generated when entering 272 the stop mode */ 273 #define OB_USER_NRST_STDBY FLASH_OPTR_nRST_STDBY /*!< Reset generated when entering 274 the standby mode */ 275 #define OB_USER_NRST_SHDW FLASH_OPTR_nRST_SHDW /*!< Reset generated when entering 276 the shutdown mode */ 277 #define OB_USER_IWDG_SW FLASH_OPTR_IWDG_SW /*!< Independent watchdog selection */ 278 #define OB_USER_IWDG_STOP FLASH_OPTR_IWDG_STOP /*!< Independent watchdog counter 279 freeze in stop mode */ 280 #define OB_USER_IWDG_STDBY FLASH_OPTR_IWDG_STDBY /*!< Independent watchdog counter 281 freeze in standby mode */ 282 #define OB_USER_WWDG_SW FLASH_OPTR_WWDG_SW /*!< Window watchdog selection */ 283 #if defined(FLASH_OPTR_HSE_NOT_REMAPPED) 284 #define OB_USER_HSE_NOT_REMAPPED FLASH_OPTR_HSE_NOT_REMAPPED /*!< Remap HSE source from PF to PC */ 285 #endif /* FLASH_OPTR_HSE_NOT_REMAPPED */ 286 #define OB_USER_RAM_PARITY_CHECK FLASH_OPTR_RAM_PARITY_CHECK /*!< Sram parity check control */ 287 #define OB_USER_SECURE_MUXING_EN FLASH_OPTR_SECURE_MUXING_EN /*!< Multiple-bonding security enable */ 288 #define OB_USER_NBOOT_SEL FLASH_OPTR_nBOOT_SEL /*!< Boot Selection */ 289 #define OB_USER_NBOOT1 FLASH_OPTR_nBOOT1 /*!< nBoot1 configuration */ 290 #define OB_USER_NBOOT0 FLASH_OPTR_nBOOT0 /*!< nBoot0 configuration */ 291 #define OB_USER_NRST_MODE FLASH_OPTR_NRST_MODE /*!< Reset pin configuration */ 292 #define OB_USER_INPUT_RESET_HOLDER FLASH_OPTR_IRHEN /*!< Internal reset holder enable */ 293 294 #if defined(FLASH_OPTR_HSE_NOT_REMAPPED) 295 #define OB_USER_ALL (OB_USER_BOR_EN | OB_USER_BOR_LEV | OB_USER_NRST_STOP | \ 296 OB_USER_NRST_STDBY | OB_USER_NRST_SHDW | OB_USER_IWDG_SW | \ 297 OB_USER_IWDG_STOP | OB_USER_IWDG_STDBY | OB_USER_WWDG_SW | \ 298 OB_USER_HSE_NOT_REMAPPED | OB_USER_RAM_PARITY_CHECK | \ 299 OB_USER_SECURE_MUXING_EN | OB_USER_NBOOT_SEL | OB_USER_NBOOT1 | \ 300 OB_USER_NBOOT0 | OB_USER_NRST_MODE | OB_USER_INPUT_RESET_HOLDER) /*!< all option bits */ 301 #else 302 #define OB_USER_ALL (OB_USER_BOR_EN | OB_USER_BOR_LEV | OB_USER_NRST_STOP | \ 303 OB_USER_NRST_STDBY | OB_USER_NRST_SHDW | OB_USER_IWDG_SW | \ 304 OB_USER_IWDG_STOP | OB_USER_IWDG_STDBY | OB_USER_WWDG_SW | \ 305 OB_USER_RAM_PARITY_CHECK | OB_USER_SECURE_MUXING_EN | \ 306 OB_USER_NBOOT_SEL | OB_USER_NBOOT1 | \ 307 OB_USER_NBOOT0 | OB_USER_NRST_MODE | OB_USER_INPUT_RESET_HOLDER) /*!< all option bits */ 308 #endif /* FLASH_OPTR_HSE_NOT_REMAPPED */ 309 /** 310 * @} 311 */ 312 313 /** @defgroup FLASH_OB_USER_BOR_ENABLE FLASH Option Bytes User BOR enable 314 * @{ 315 */ 316 #define OB_BOR_DISABLE 0x00000000U /*!< BOR Reset set to default */ 317 #define OB_BOR_ENABLE FLASH_OPTR_BOR_EN /*!< Use option byte to define BOR thresholds */ 318 /** 319 * @} 320 */ 321 322 /** @defgroup FLASH_OB_USER_BOR_LEVEL FLASH Option Bytes User BOR Level 323 * @{ 324 */ 325 #define OB_BOR_LEVEL_FALLING_0 0x00000000U /*!< BOR falling level 1 with 326 threshold around 2.0V */ 327 #define OB_BOR_LEVEL_FALLING_1 FLASH_OPTR_BORF_LEV_0 /*!< BOR falling level 2 with 328 threshold around 2.2V */ 329 #define OB_BOR_LEVEL_FALLING_2 FLASH_OPTR_BORF_LEV_1 /*!< BOR falling level 3 with 330 threshold around 2.5V */ 331 #define OB_BOR_LEVEL_FALLING_3 (FLASH_OPTR_BORF_LEV_0 | FLASH_OPTR_BORF_LEV_1) /*!< BOR falling level 4 with 332 threshold around 2.8V */ 333 #define OB_BOR_LEVEL_RISING_0 0x00000000U /*!< BOR rising level 1 with 334 threshold around 2.1V */ 335 #define OB_BOR_LEVEL_RISING_1 FLASH_OPTR_BORR_LEV_0 /*!< BOR rising level 2 with 336 threshold around 2.3V */ 337 #define OB_BOR_LEVEL_RISING_2 FLASH_OPTR_BORR_LEV_1 /*!< BOR rising level 3 with 338 threshold around 2.6V */ 339 #define OB_BOR_LEVEL_RISING_3 (FLASH_OPTR_BORR_LEV_0 | FLASH_OPTR_BORR_LEV_1) /*!< BOR rising level 4 with 340 threshold around 2.9V */ 341 /** 342 * @} 343 */ 344 345 /** @defgroup FLASH_OB_USER_nRST_STOP FLASH Option Bytes User Reset On Stop 346 * @{ 347 */ 348 #define OB_STOP_RST 0x00000000U /*!< Reset generated when entering the stop mode */ 349 #define OB_STOP_NORST FLASH_OPTR_nRST_STOP /*!< No reset generated when entering the stop mode */ 350 /** 351 * @} 352 */ 353 354 /** @defgroup FLASH_OB_USER_nRST_STANDBY FLASH Option Bytes User Reset On Standby 355 * @{ 356 */ 357 #define OB_STANDBY_RST 0x00000000U /*!< Reset generated when entering the standby mode */ 358 #define OB_STANDBY_NORST FLASH_OPTR_nRST_STDBY /*!< No reset generated when entering the standby mode */ 359 /** 360 * @} 361 */ 362 363 /** @defgroup FLASH_OB_USER_nRST_SHUTDOWN FLASH Option Bytes User Reset On Shutdown 364 * @{ 365 */ 366 #define OB_SHUTDOWN_RST 0x00000000U /*!< Reset generated when entering the shutdown mode */ 367 #define OB_SHUTDOWN_NORST FLASH_OPTR_nRST_SHDW /*!< No reset generated when entering the shutdown mode */ 368 /** 369 * @} 370 */ 371 372 /** @defgroup FLASH_OB_USER_IWDG_SW FLASH Option Bytes User IWDG Type 373 * @{ 374 */ 375 #define OB_IWDG_HW 0x00000000U /*!< Hardware independent watchdog */ 376 #define OB_IWDG_SW FLASH_OPTR_IWDG_SW /*!< Software independent watchdog */ 377 /** 378 * @} 379 */ 380 381 /** @defgroup FLASH_OB_USER_IWDG_STOP FLASH Option Bytes User IWDG Mode On Stop 382 * @{ 383 */ 384 #define OB_IWDG_STOP_FREEZE 0x00000000U /*!< Independent watchdog counter is frozen 385 in Stop mode */ 386 #define OB_IWDG_STOP_RUN FLASH_OPTR_IWDG_STOP /*!< Independent watchdog counter is running 387 in Stop mode */ 388 /** 389 * @} 390 */ 391 392 /** @defgroup FLASH_OB_USER_IWDG_STANDBY FLASH Option Bytes User IWDG Mode On Standby 393 * @{ 394 */ 395 #define OB_IWDG_STDBY_FREEZE 0x00000000U /*!< Independent watchdog counter is frozen 396 in Standby mode */ 397 #define OB_IWDG_STDBY_RUN FLASH_OPTR_IWDG_STDBY /*!< Independent watchdog counter is running 398 in Standby mode */ 399 /** 400 * @} 401 */ 402 403 /** @defgroup FLASH_OB_USER_WWDG_SW FLASH Option Bytes User WWDG Type 404 * @{ 405 */ 406 #define OB_WWDG_HW 0x00000000U /*!< Hardware window watchdog */ 407 #define OB_WWDG_SW FLASH_OPTR_WWDG_SW /*!< Software window watchdog */ 408 /** 409 * @} 410 */ 411 412 #if defined(FLASH_OPTR_HSE_NOT_REMAPPED) 413 /** @defgroup FLASH_OB_USER_HSE_REMAP FLASH Option Bytes User HSE REMAP 414 * @{ 415 */ 416 #define OB_HSE_NOT_REMAPPED_ENABLE 0x00000000U /*!< HSE Remap enable */ 417 #define OB_HSE_NOT_REMAPPED_DISABLE FLASH_OPTR_HSE_NOT_REMAPPED /*!< HSE Remap disable */ 418 /** 419 * @} 420 */ 421 #endif /* FLASH_OPTR_HSE_NOT_REMAPPED */ 422 423 /** @defgroup FLASH_OB_USER_SRAM_PARITY FLASH Option Bytes User SRAM parity 424 * @{ 425 */ 426 #define OB_SRAM_PARITY_ENABLE 0x00000000U /*!< Sram parity enable */ 427 #define OB_SRAM_PARITY_DISABLE FLASH_OPTR_RAM_PARITY_CHECK /*!< Sram parity disable */ 428 /** 429 * @} 430 */ 431 432 /** @defgroup FLASH_OB_USER_SECURE_MUXING_EN FLASH Option Bytes User Multiple-bonding security 433 * @{ 434 */ 435 #define OB_SECURE_MUXING_ENABLE FLASH_OPTR_SECURE_MUXING_EN /*!< Multiple-bonding security enable */ 436 #define OB_SECURE_MUXING_DISABLE 0x00000000U /*!< Multiple-bonding security disable */ 437 /** 438 * @} 439 */ 440 441 /** @defgroup FLASH_OB_USER_nBOOT_SEL FLASH Option Bytes User Boot0 Selection 442 * @{ 443 */ 444 #define OB_BOOT0_FROM_PIN 0x00000000U /*!< BOOT0 signal is defined by PA14/BOOT0 pin value */ 445 #define OB_BOOT0_FROM_OB FLASH_OPTR_nBOOT_SEL /*!< BOOT0 signal is defined by nBOOT0 option bit */ 446 /** 447 * @} 448 */ 449 450 /** @defgroup FLASH_OB_USER_nBOOT1 FLASH Option Bytes User BOOT1 Type 451 * @{ 452 */ 453 #define OB_BOOT1_SRAM 0x00000000U /*!< Embedded SRAM is selected as boot space 454 (if nBOOT0=0 or BOOT0_pin=1) */ 455 #define OB_BOOT1_SYSTEM FLASH_OPTR_nBOOT1 /*!< System memory is selected as boot space 456 (if nBOOT0=0 or BOOT0_pin=1) */ 457 /** 458 * @} 459 */ 460 461 /** @defgroup FLASH_OB_USER_nBOOT0 FLASH Option Bytes User nBOOT0 option bit 462 * @{ 463 */ 464 #define OB_NBOOT0_RESET 0x00000000U /*!< nBOOT0 = 0 */ 465 #define OB_NBOOT0_SET FLASH_OPTR_nBOOT0 /*!< nBOOT0 = 1 */ 466 /** 467 * @} 468 */ 469 470 /** @defgroup FLASH_OB_USER_RESET_CONFIG FLASH Option Bytes User reset config bit 471 * @{ 472 */ 473 #define OB_RESET_MODE_INPUT_ONLY FLASH_OPTR_NRST_MODE_0 /*!< Reset pin is in Reset input mode only */ 474 #define OB_RESET_MODE_GPIO FLASH_OPTR_NRST_MODE_1 /*!< Reset pin is in GPIO mode mode only */ 475 #define OB_RESET_MODE_INPUT_OUTPUT FLASH_OPTR_NRST_MODE /*!< Reset pin is in reset input and output mode */ 476 /** 477 * @} 478 */ 479 480 /** @defgroup FLASH_OB_USER_INPUT_RESET_HOLDER FLASH Option Bytes User input reset holder bit 481 * @{ 482 */ 483 #define OB_IRH_ENABLE 0x00000000U /*!< Internal Reset handler enable */ 484 #define OB_IRH_DISABLE FLASH_OPTR_IRHEN /*!< Internal Reset handler disable */ 485 /** 486 * @} 487 */ 488 489 /** @defgroup FLASH_OB_PCROP_ZONE FLASH Option Bytes PCROP ZONE 490 * @{ 491 */ 492 #define OB_PCROP_ZONE_A 0x00000001U /*!< PCROP Zone A */ 493 #define OB_PCROP_ZONE_B 0x00000002U /*!< PCROP Zone B */ 494 /** 495 * @} 496 */ 497 498 /** @defgroup FLASH_OB_PCROP_RDP FLASH Option Bytes PCROP On RDP Level Type 499 * @{ 500 */ 501 #define OB_PCROP_RDP_NOT_ERASE 0x00000000U /*!< PCROP area is not erased when the RDP level 502 is decreased from Level 1 to Level 0 */ 503 #define OB_PCROP_RDP_ERASE FLASH_PCROP1AER_PCROP_RDP /*!< PCROP area is erased when the RDP level is 504 decreased from Level 1 to Level 0 505 (full mass erase).Once this bit is set only, 506 it will be reset by mass erase */ 507 /** 508 * @} 509 */ 510 511 /** @defgroup FLASH_OB_SEC_BOOT_LOCK FLASH Option Bytes Secure boot lock 512 * @{ 513 */ 514 #define OB_BOOT_ENTRY_FORCED_NONE 0x00000000U /*!< Boot entry is free */ 515 #define OB_BOOT_ENTRY_FORCED_FLASH FLASH_SECR_BOOT_LOCK /*!< Boot entry is forced to Flash or System Flash */ 516 /** 517 * @} 518 */ 519 520 /** 521 * @} 522 */ 523 524 /* Exported macros -----------------------------------------------------------*/ 525 /** @defgroup FLASH_Exported_Macros FLASH Exported Macros 526 * @brief macros to control FLASH features 527 * @{ 528 */ 529 530 /** 531 * @brief Set the FLASH Latency. 532 * @param __LATENCY__ FLASH Latency 533 * This parameter can be one of the following values : 534 * @arg @ref FLASH_LATENCY_0 FLASH Zero wait state 535 * @arg @ref FLASH_LATENCY_1 FLASH One wait state 536 * @retval None 537 */ 538 #define __HAL_FLASH_SET_LATENCY(__LATENCY__) MODIFY_REG(FLASH->ACR, FLASH_ACR_LATENCY, (__LATENCY__)) 539 540 /** 541 * @brief Get the FLASH Latency. 542 * @retval FLASH Latency 543 * Returned value can be one of the following values : 544 * @arg @ref FLASH_LATENCY_0 FLASH Zero wait state 545 * @arg @ref FLASH_LATENCY_1 FLASH One wait state 546 */ 547 #define __HAL_FLASH_GET_LATENCY() READ_BIT(FLASH->ACR, FLASH_ACR_LATENCY) 548 549 /** 550 * @brief Enable the FLASH prefetch buffer. 551 * @retval None 552 */ 553 #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() SET_BIT(FLASH->ACR, FLASH_ACR_PRFTEN) 554 555 /** 556 * @brief Disable the FLASH prefetch buffer. 557 * @retval None 558 */ 559 #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() CLEAR_BIT(FLASH->ACR, FLASH_ACR_PRFTEN) 560 561 /** 562 * @brief Enable the FLASH instruction cache. 563 * @retval none 564 */ 565 #define __HAL_FLASH_INSTRUCTION_CACHE_ENABLE() SET_BIT(FLASH->ACR, FLASH_ACR_ICEN) 566 567 /** 568 * @brief Disable the FLASH instruction cache. 569 * @retval none 570 */ 571 #define __HAL_FLASH_INSTRUCTION_CACHE_DISABLE() CLEAR_BIT(FLASH->ACR, FLASH_ACR_ICEN) 572 573 /** 574 * @brief Reset the FLASH instruction Cache. 575 * @note This function must be used only when the Instruction Cache is disabled. 576 * @retval None 577 */ 578 #define __HAL_FLASH_INSTRUCTION_CACHE_RESET() do { SET_BIT(FLASH->ACR, FLASH_ACR_ICRST); \ 579 CLEAR_BIT(FLASH->ACR, FLASH_ACR_ICRST); \ 580 } while (0U) 581 /** 582 * @} 583 */ 584 585 /** @defgroup FLASH_Interrupt FLASH Interrupts Macros 586 * @brief macros to handle FLASH interrupts 587 * @{ 588 */ 589 590 /** 591 * @brief Enable the specified FLASH interrupt. 592 * @param __INTERRUPT__ FLASH interrupt 593 * This parameter can be any combination of the following values: 594 * @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt 595 * @arg @ref FLASH_IT_OPERR Error Interrupt 596 * @arg @ref FLASH_IT_RDERR PCROP Read Error Interrupt 597 * @retval none 598 */ 599 #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) SET_BIT((FLASH->CR), (__INTERRUPT__)) 600 /** 601 * @brief Disable the specified FLASH interrupt. 602 * @param __INTERRUPT__ FLASH interrupt 603 * This parameter can be any combination of the following values: 604 * @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt 605 * @arg @ref FLASH_IT_OPERR Error Interrupt 606 * @arg @ref FLASH_IT_RDERR PCROP Read Error Interrupt 607 * @retval none 608 */ 609 #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) CLEAR_BIT((FLASH->CR), (uint32_t)(__INTERRUPT__)) 610 611 /** 612 * @brief Check whether the specified FLASH flag is set or not. 613 * @param __FLAG__ specifies the FLASH flag to check. 614 * This parameter can be one of the following values: 615 * @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag 616 * @arg @ref FLASH_FLAG_OPERR FLASH Operation error flag 617 * @arg @ref FLASH_FLAG_PROGERR FLASH Programming error flag 618 * @arg @ref FLASH_FLAG_WRPERR FLASH Write protection error flag 619 * @arg @ref FLASH_FLAG_PGAERR FLASH Programming alignment error flag 620 * @arg @ref FLASH_FLAG_SIZERR FLASH Size error flag 621 * @arg @ref FLASH_FLAG_PGSERR FLASH Programming sequence error flag 622 * @arg @ref FLASH_FLAG_MISERR FLASH Fast programming data miss error flag 623 * @arg @ref FLASH_FLAG_FASTERR FLASH Fast programming error flag 624 * @arg @ref FLASH_FLAG_RDERR FLASH PCROP read error flag 625 * @arg @ref FLASH_FLAG_OPTVERR FLASH Option validity error flag 626 * @arg @ref FLASH_FLAG_BSY FLASH write/erase operations in progress flag 627 * @arg @ref FLASH_FLAG_CFGBSY FLASH configuration is busy : program or erase setting are used. 628 * @arg @ref FLASH_FLAG_PESD FLASH Programming/erase operation suspended 629 * @retval The new state of FLASH_FLAG (SET or RESET). 630 */ 631 #define __HAL_FLASH_GET_FLAG(__FLAG__) (READ_BIT(FLASH->SR, (__FLAG__)) == (__FLAG__)) 632 633 /** 634 * @brief Clear the FLASHs pending flags. 635 * @param __FLAG__ specifies the FLASH flags to clear. 636 * This parameter can be any combination of the following values: 637 * @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag 638 * @arg @ref FLASH_FLAG_OPERR FLASH Operation error flag 639 * @arg @ref FLASH_FLAG_PROGERR FLASH Programming error flag 640 * @arg @ref FLASH_FLAG_WRPERR FLASH Write protection error flag 641 * @arg @ref FLASH_FLAG_PGAERR FLASH Programming alignment error flag 642 * @arg @ref FLASH_FLAG_SIZERR FLASH Size error flag 643 * @arg @ref FLASH_FLAG_PGSERR FLASH Programming sequence error flag 644 * @arg @ref FLASH_FLAG_MISERR FLASH Fast programming data miss error flag 645 * @arg @ref FLASH_FLAG_FASTERR FLASH Fast programming error flag 646 * @arg @ref FLASH_FLAG_RDERR FLASH PCROP read error flag 647 * @arg @ref FLASH_FLAG_OPTVERR FLASH Option validity error flag 648 * @retval None 649 */ 650 #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) ((FLASH->SR) = (__FLAG__)) 651 652 /** 653 * @} 654 */ 655 656 /* Include FLASH HAL Extended module */ 657 #include "stm32c0xx_hal_flash_ex.h" 658 /* Exported variables --------------------------------------------------------*/ 659 /** @defgroup FLASH_Exported_Variables FLASH Exported Variables 660 * @{ 661 */ 662 extern FLASH_ProcessTypeDef pFlash; 663 /** 664 * @} 665 */ 666 667 /* Exported functions --------------------------------------------------------*/ 668 /** @addtogroup FLASH_Exported_Functions 669 * @{ 670 */ 671 672 /* Program operation functions ***********************************************/ 673 /** @addtogroup FLASH_Exported_Functions_Group1 674 * @{ 675 */ 676 HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data); 677 HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data); 678 /* FLASH IRQ handler method */ 679 void HAL_FLASH_IRQHandler(void); 680 /* Callbacks in non blocking modes */ 681 void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue); 682 void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue); 683 /** 684 * @} 685 */ 686 687 /* Peripheral Control functions **********************************************/ 688 /** @addtogroup FLASH_Exported_Functions_Group2 689 * @{ 690 */ 691 HAL_StatusTypeDef HAL_FLASH_Unlock(void); 692 HAL_StatusTypeDef HAL_FLASH_Lock(void); 693 /* Option bytes control */ 694 HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void); 695 HAL_StatusTypeDef HAL_FLASH_OB_Lock(void); 696 HAL_StatusTypeDef HAL_FLASH_OB_Launch(void); 697 /** 698 * @} 699 */ 700 701 /* Peripheral State functions ************************************************/ 702 /** @addtogroup FLASH_Exported_Functions_Group3 703 * @{ 704 */ 705 uint32_t HAL_FLASH_GetError(void); 706 /** 707 * @} 708 */ 709 710 /** 711 * @} 712 */ 713 714 /* Private types --------------------------------------------------------*/ 715 /** @defgroup FLASH_Private_types FLASH Private Types 716 * @{ 717 */ 718 HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout); 719 /** 720 * @} 721 */ 722 723 /* Private constants --------------------------------------------------------*/ 724 /** @defgroup FLASH_Private_Constants FLASH Private Constants 725 * @{ 726 */ 727 #define FLASH_SIZE_DATA_REGISTER FLASHSIZE_BASE 728 729 #define FLASH_BANK_SIZE (FLASH_SIZE) /*!< FLASH Bank Size */ 730 731 #define FLASH_PAGE_SIZE 0x00000800U /*!< FLASH Page Size, 2 KBytes */ 732 733 #define FLASH_PAGE_NB (FLASH_BANK_SIZE / FLASH_PAGE_SIZE) /*!< Number of pages per bank */ 734 735 #define FLASH_TIMEOUT_VALUE 1000U /*!< FLASH Execution Timeout, 1 s */ 736 737 #define FLASH_TYPENONE 0x00000000U /*!< No Programmation Procedure On Going */ 738 739 #define FLASH_FLAG_SR_ERROR (FLASH_FLAG_OPERR | FLASH_FLAG_PROGERR | FLASH_FLAG_WRPERR | \ 740 FLASH_FLAG_PGAERR | FLASH_FLAG_SIZERR | FLASH_FLAG_PGSERR | \ 741 FLASH_FLAG_MISERR | FLASH_FLAG_FASTERR | FLASH_FLAG_RDERR | \ 742 FLASH_FLAG_OPTVERR) /*!< All SR error flags */ 743 /** 744 * @} 745 */ 746 747 /* Private macros ------------------------------------------------------------*/ 748 /** @defgroup FLASH_Private_Macros FLASH Private Macros 749 * @{ 750 */ 751 #define IS_FLASH_MAIN_MEM_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= (FLASH_BASE)) && \ 752 ((__ADDRESS__) <= (FLASH_BASE + FLASH_SIZE - 1UL))) 753 754 #define IS_FLASH_PROGRAM_MAIN_MEM_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= (FLASH_BASE)) && \ 755 ((__ADDRESS__) <= (FLASH_BASE + FLASH_SIZE - 8UL))) 756 757 #define IS_FLASH_PROGRAM_OTP_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= 0x1FFF7000U) && \ 758 ((__ADDRESS__) <= (0x1FFF7400U - 8UL))) 759 760 #define IS_FLASH_PROGRAM_ADDRESS(__ADDRESS__) ((IS_FLASH_PROGRAM_MAIN_MEM_ADDRESS(__ADDRESS__)) || \ 761 (IS_FLASH_PROGRAM_OTP_ADDRESS(__ADDRESS__))) 762 763 #define IS_FLASH_FAST_PROGRAM_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= (FLASH_BASE)) && \ 764 ((__ADDRESS__) <= (FLASH_BASE + FLASH_SIZE - 256UL))) 765 766 #define IS_FLASH_PAGE(__PAGE__) ((__PAGE__) < FLASH_PAGE_NB) 767 768 #define IS_FLASH_BANK(__BANK__) ((__BANK__) == 0x00UL) 769 770 #define IS_FLASH_TYPEERASE(__VALUE__) (((__VALUE__) == FLASH_TYPEERASE_PAGES) || \ 771 ((__VALUE__) == FLASH_TYPEERASE_MASS)) 772 773 #define IS_FLASH_TYPEPROGRAM(__VALUE__) (((__VALUE__) == FLASH_TYPEPROGRAM_DOUBLEWORD) || \ 774 ((__VALUE__) == FLASH_TYPEPROGRAM_FAST)) 775 776 #define IS_OPTIONBYTE(__VALUE__) ((((__VALUE__) & OPTIONBYTE_ALL) != 0x00U) && \ 777 (((__VALUE__) & ~OPTIONBYTE_ALL) == 0x00U)) 778 779 #define IS_OB_WRPAREA(__VALUE__) (((__VALUE__) == OB_WRPAREA_ZONE_A) || \ 780 ((__VALUE__) == OB_WRPAREA_ZONE_B)) 781 782 #define IS_OB_RDP_LEVEL(__LEVEL__) (((__LEVEL__) == OB_RDP_LEVEL_0) ||\ 783 ((__LEVEL__) == OB_RDP_LEVEL_1) ||\ 784 ((__LEVEL__) == OB_RDP_LEVEL_2)) 785 786 #define IS_OB_USER_TYPE(__TYPE__) ((((__TYPE__) & OB_USER_ALL) != 0x00U) && \ 787 (((__TYPE__) & ~OB_USER_ALL) == 0x00U)) 788 789 #define IS_OB_USER_CONFIG(__TYPE__,__CONFIG__) ((~(__TYPE__) & (__CONFIG__)) == 0x00U) 790 791 #define IS_OB_PCROP_CONFIG(__CONFIG__) (((__CONFIG__) & ~(OB_PCROP_ZONE_A | OB_PCROP_ZONE_B | \ 792 OB_PCROP_RDP_ERASE)) == 0x00U) 793 794 #define IS_OB_SEC_BOOT_LOCK(__VALUE__) (((__VALUE__) == OB_BOOT_ENTRY_FORCED_NONE) || \ 795 ((__VALUE__) == OB_BOOT_ENTRY_FORCED_FLASH)) 796 797 #define IS_OB_SEC_SIZE(__VALUE__) ((__VALUE__) < (FLASH_PAGE_NB + 1U)) 798 799 #define IS_FLASH_LATENCY(__LATENCY__) (((__LATENCY__) == FLASH_LATENCY_0) || \ 800 ((__LATENCY__) == FLASH_LATENCY_1)) 801 /** 802 * @} 803 */ 804 805 /** 806 * @} 807 */ 808 809 /** 810 * @} 811 */ 812 813 #ifdef __cplusplus 814 } 815 #endif 816 817 #endif /* STM32C0xx_HAL_FLASH_H */ 818