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 #define OB_USER_RAM_PARITY_CHECK FLASH_OPTR_RAM_PARITY_CHECK /*!< Sram parity check control */ 284 #define OB_USER_NBOOT_SEL FLASH_OPTR_nBOOT_SEL /*!< Boot Selection */ 285 #define OB_USER_NBOOT1 FLASH_OPTR_nBOOT1 /*!< nBoot1 configuration */ 286 #define OB_USER_NBOOT0 FLASH_OPTR_nBOOT0 /*!< nBoot0 configuration */ 287 #define OB_USER_NRST_MODE FLASH_OPTR_NRST_MODE /*!< Reset pin configuration */ 288 #define OB_USER_INPUT_RESET_HOLDER FLASH_OPTR_IRHEN /*!< Internal reset holder enable */ 289 290 #define OB_USER_ALL (OB_USER_BOR_EN | OB_USER_BOR_LEV | OB_USER_NRST_STOP | \ 291 OB_USER_NRST_STDBY | OB_USER_NRST_SHDW | OB_USER_IWDG_SW | \ 292 OB_USER_IWDG_STOP | OB_USER_IWDG_STDBY | OB_USER_WWDG_SW | \ 293 OB_USER_RAM_PARITY_CHECK | OB_USER_NBOOT_SEL | OB_USER_NBOOT1 | \ 294 OB_USER_NBOOT0 | OB_USER_NRST_MODE | OB_USER_INPUT_RESET_HOLDER) /*!< all option bits */ 295 /** 296 * @} 297 */ 298 299 /** @defgroup FLASH_OB_USER_BOR_ENABLE FLASH Option Bytes User BOR enable 300 * @{ 301 */ 302 #define OB_BOR_DISABLE 0x00000000U /*!< BOR Reset set to default */ 303 #define OB_BOR_ENABLE FLASH_OPTR_BOR_EN /*!< Use option byte to define BOR thresholds */ 304 /** 305 * @} 306 */ 307 308 /** @defgroup FLASH_OB_USER_BOR_LEVEL FLASH Option Bytes User BOR Level 309 * @{ 310 */ 311 #define OB_BOR_LEVEL_FALLING_0 0x00000000U /*!< BOR falling level 1 with 312 threshold around 2.0V */ 313 #define OB_BOR_LEVEL_FALLING_1 FLASH_OPTR_BORF_LEV_0 /*!< BOR falling level 2 with 314 threshold around 2.2V */ 315 #define OB_BOR_LEVEL_FALLING_2 FLASH_OPTR_BORF_LEV_1 /*!< BOR falling level 3 with 316 threshold around 2.5V */ 317 #define OB_BOR_LEVEL_FALLING_3 (FLASH_OPTR_BORF_LEV_0 | FLASH_OPTR_BORF_LEV_1) /*!< BOR falling level 4 with 318 threshold around 2.8V */ 319 #define OB_BOR_LEVEL_RISING_0 0x00000000U /*!< BOR rising level 1 with 320 threshold around 2.1V */ 321 #define OB_BOR_LEVEL_RISING_1 FLASH_OPTR_BORR_LEV_0 /*!< BOR rising level 2 with 322 threshold around 2.3V */ 323 #define OB_BOR_LEVEL_RISING_2 FLASH_OPTR_BORR_LEV_1 /*!< BOR rising level 3 with 324 threshold around 2.6V */ 325 #define OB_BOR_LEVEL_RISING_3 (FLASH_OPTR_BORR_LEV_0 | FLASH_OPTR_BORR_LEV_1) /*!< BOR rising level 4 with 326 threshold around 2.9V */ 327 /** 328 * @} 329 */ 330 331 /** @defgroup FLASH_OB_USER_nRST_STOP FLASH Option Bytes User Reset On Stop 332 * @{ 333 */ 334 #define OB_STOP_RST 0x00000000U /*!< Reset generated when entering the stop mode */ 335 #define OB_STOP_NORST FLASH_OPTR_nRST_STOP /*!< No reset generated when entering the stop mode */ 336 /** 337 * @} 338 */ 339 340 /** @defgroup FLASH_OB_USER_nRST_STANDBY FLASH Option Bytes User Reset On Standby 341 * @{ 342 */ 343 #define OB_STANDBY_RST 0x00000000U /*!< Reset generated when entering the standby mode */ 344 #define OB_STANDBY_NORST FLASH_OPTR_nRST_STDBY /*!< No reset generated when entering the standby mode */ 345 /** 346 * @} 347 */ 348 349 /** @defgroup FLASH_OB_USER_nRST_SHUTDOWN FLASH Option Bytes User Reset On Shutdown 350 * @{ 351 */ 352 #define OB_SHUTDOWN_RST 0x00000000U /*!< Reset generated when entering the shutdown mode */ 353 #define OB_SHUTDOWN_NORST FLASH_OPTR_nRST_SHDW /*!< No reset generated when entering the shutdown mode */ 354 /** 355 * @} 356 */ 357 358 /** @defgroup FLASH_OB_USER_IWDG_SW FLASH Option Bytes User IWDG Type 359 * @{ 360 */ 361 #define OB_IWDG_HW 0x00000000U /*!< Hardware independent watchdog */ 362 #define OB_IWDG_SW FLASH_OPTR_IWDG_SW /*!< Software independent watchdog */ 363 /** 364 * @} 365 */ 366 367 /** @defgroup FLASH_OB_USER_IWDG_STOP FLASH Option Bytes User IWDG Mode On Stop 368 * @{ 369 */ 370 #define OB_IWDG_STOP_FREEZE 0x00000000U /*!< Independent watchdog counter is frozen 371 in Stop mode */ 372 #define OB_IWDG_STOP_RUN FLASH_OPTR_IWDG_STOP /*!< Independent watchdog counter is running 373 in Stop mode */ 374 /** 375 * @} 376 */ 377 378 /** @defgroup FLASH_OB_USER_IWDG_STANDBY FLASH Option Bytes User IWDG Mode On Standby 379 * @{ 380 */ 381 #define OB_IWDG_STDBY_FREEZE 0x00000000U /*!< Independent watchdog counter is frozen 382 in Standby mode */ 383 #define OB_IWDG_STDBY_RUN FLASH_OPTR_IWDG_STDBY /*!< Independent watchdog counter is running 384 in Standby mode */ 385 /** 386 * @} 387 */ 388 389 /** @defgroup FLASH_OB_USER_WWDG_SW FLASH Option Bytes User WWDG Type 390 * @{ 391 */ 392 #define OB_WWDG_HW 0x00000000U /*!< Hardware window watchdog */ 393 #define OB_WWDG_SW FLASH_OPTR_WWDG_SW /*!< Software window watchdog */ 394 /** 395 * @} 396 */ 397 398 /** @defgroup FLASH_OB_USER_SRAM_PARITY FLASH Option Bytes User SRAM parity 399 * @{ 400 */ 401 #define OB_SRAM_PARITY_ENABLE 0x00000000U /*!< Sram parity enable */ 402 #define OB_SRAM_PARITY_DISABLE FLASH_OPTR_RAM_PARITY_CHECK /*!< Sram parity disable */ 403 /** 404 * @} 405 */ 406 407 /** @defgroup FLASH_OB_USER_nBOOT_SEL FLASH Option Bytes User Boot0 Selection 408 * @{ 409 */ 410 #define OB_BOOT0_FROM_PIN 0x00000000U /*!< BOOT0 signal is defined by PA14/BOOT0 pin value */ 411 #define OB_BOOT0_FROM_OB FLASH_OPTR_nBOOT_SEL /*!< BOOT0 signal is defined by nBOOT0 option bit */ 412 /** 413 * @} 414 */ 415 416 /** @defgroup FLASH_OB_USER_nBOOT1 FLASH Option Bytes User BOOT1 Type 417 * @{ 418 */ 419 #define OB_BOOT1_SRAM 0x00000000U /*!< Embedded SRAM is selected as boot space 420 (if nBOOT0=0 or BOOT0_pin=1) */ 421 #define OB_BOOT1_SYSTEM FLASH_OPTR_nBOOT1 /*!< System memory is selected as boot space 422 (if nBOOT0=0 or BOOT0_pin=1) */ 423 /** 424 * @} 425 */ 426 427 /** @defgroup FLASH_OB_USER_nBOOT0 FLASH Option Bytes User nBOOT0 option bit 428 * @{ 429 */ 430 #define OB_NBOOT0_RESET 0x00000000U /*!< nBOOT0 = 0 */ 431 #define OB_NBOOT0_SET FLASH_OPTR_nBOOT0 /*!< nBOOT0 = 1 */ 432 /** 433 * @} 434 */ 435 436 /** @defgroup FLASH_OB_USER_RESET_CONFIG FLASH Option Bytes User reset config bit 437 * @{ 438 */ 439 #define OB_RESET_MODE_INPUT_ONLY FLASH_OPTR_NRST_MODE_0 /*!< Reset pin is in Reset input mode only */ 440 #define OB_RESET_MODE_GPIO FLASH_OPTR_NRST_MODE_1 /*!< Reset pin is in GPIO mode mode only */ 441 #define OB_RESET_MODE_INPUT_OUTPUT FLASH_OPTR_NRST_MODE /*!< Reset pin is in reset input and output mode */ 442 /** 443 * @} 444 */ 445 446 /** @defgroup FLASH_OB_USER_INPUT_RESET_HOLDER FLASH Option Bytes User input reset holder bit 447 * @{ 448 */ 449 #define OB_IRH_ENABLE 0x00000000U /*!< Internal Reset handler enable */ 450 #define OB_IRH_DISABLE FLASH_OPTR_IRHEN /*!< Internal Reset handler disable */ 451 /** 452 * @} 453 */ 454 455 /** @defgroup FLASH_OB_PCROP_ZONE FLASH Option Bytes PCROP ZONE 456 * @{ 457 */ 458 #define OB_PCROP_ZONE_A 0x00000001U /*!< PCROP Zone A */ 459 #define OB_PCROP_ZONE_B 0x00000002U /*!< PCROP Zone B */ 460 /** 461 * @} 462 */ 463 464 /** @defgroup FLASH_OB_PCROP_RDP FLASH Option Bytes PCROP On RDP Level Type 465 * @{ 466 */ 467 #define OB_PCROP_RDP_NOT_ERASE 0x00000000U /*!< PCROP area is not erased when the RDP level 468 is decreased from Level 1 to Level 0 */ 469 #define OB_PCROP_RDP_ERASE FLASH_PCROP1AER_PCROP_RDP /*!< PCROP area is erased when the RDP level is 470 decreased from Level 1 to Level 0 471 (full mass erase).Once this bit is set only, 472 it will be reset by mass erase */ 473 /** 474 * @} 475 */ 476 477 /** @defgroup FLASH_OB_SEC_BOOT_LOCK FLASH Option Bytes Secure boot lock 478 * @{ 479 */ 480 #define OB_BOOT_ENTRY_FORCED_NONE 0x00000000U /*!< Boot entry is free */ 481 #define OB_BOOT_ENTRY_FORCED_FLASH FLASH_SECR_BOOT_LOCK /*!< Boot entry is forced to Flash or System Flash */ 482 /** 483 * @} 484 */ 485 486 /** 487 * @} 488 */ 489 490 /* Exported macros -----------------------------------------------------------*/ 491 /** @defgroup FLASH_Exported_Macros FLASH Exported Macros 492 * @brief macros to control FLASH features 493 * @{ 494 */ 495 496 /** 497 * @brief Set the FLASH Latency. 498 * @param __LATENCY__ FLASH Latency 499 * This parameter can be one of the following values : 500 * @arg @ref FLASH_LATENCY_0 FLASH Zero wait state 501 * @arg @ref FLASH_LATENCY_1 FLASH One wait state 502 * @retval None 503 */ 504 #define __HAL_FLASH_SET_LATENCY(__LATENCY__) MODIFY_REG(FLASH->ACR, FLASH_ACR_LATENCY, (__LATENCY__)) 505 506 /** 507 * @brief Get the FLASH Latency. 508 * @retval FLASH Latency 509 * Returned value can be one of the following values : 510 * @arg @ref FLASH_LATENCY_0 FLASH Zero wait state 511 * @arg @ref FLASH_LATENCY_1 FLASH One wait state 512 */ 513 #define __HAL_FLASH_GET_LATENCY() READ_BIT(FLASH->ACR, FLASH_ACR_LATENCY) 514 515 /** 516 * @brief Enable the FLASH prefetch buffer. 517 * @retval None 518 */ 519 #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() SET_BIT(FLASH->ACR, FLASH_ACR_PRFTEN) 520 521 /** 522 * @brief Disable the FLASH prefetch buffer. 523 * @retval None 524 */ 525 #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() CLEAR_BIT(FLASH->ACR, FLASH_ACR_PRFTEN) 526 527 /** 528 * @brief Enable the FLASH instruction cache. 529 * @retval none 530 */ 531 #define __HAL_FLASH_INSTRUCTION_CACHE_ENABLE() SET_BIT(FLASH->ACR, FLASH_ACR_ICEN) 532 533 /** 534 * @brief Disable the FLASH instruction cache. 535 * @retval none 536 */ 537 #define __HAL_FLASH_INSTRUCTION_CACHE_DISABLE() CLEAR_BIT(FLASH->ACR, FLASH_ACR_ICEN) 538 539 /** 540 * @brief Reset the FLASH instruction Cache. 541 * @note This function must be used only when the Instruction Cache is disabled. 542 * @retval None 543 */ 544 #define __HAL_FLASH_INSTRUCTION_CACHE_RESET() do { SET_BIT(FLASH->ACR, FLASH_ACR_ICRST); \ 545 CLEAR_BIT(FLASH->ACR, FLASH_ACR_ICRST); \ 546 } while (0U) 547 /** 548 * @} 549 */ 550 551 /** @defgroup FLASH_Interrupt FLASH Interrupts Macros 552 * @brief macros to handle FLASH interrupts 553 * @{ 554 */ 555 556 /** 557 * @brief Enable the specified FLASH interrupt. 558 * @param __INTERRUPT__ FLASH interrupt 559 * This parameter can be any combination of the following values: 560 * @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt 561 * @arg @ref FLASH_IT_OPERR Error Interrupt 562 * @arg @ref FLASH_IT_RDERR PCROP Read Error Interrupt 563 * @retval none 564 */ 565 #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) SET_BIT((FLASH->CR), (__INTERRUPT__)) 566 /** 567 * @brief Disable the specified FLASH interrupt. 568 * @param __INTERRUPT__ FLASH interrupt 569 * This parameter can be any combination of the following values: 570 * @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt 571 * @arg @ref FLASH_IT_OPERR Error Interrupt 572 * @arg @ref FLASH_IT_RDERR PCROP Read Error Interrupt 573 * @retval none 574 */ 575 #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) CLEAR_BIT((FLASH->CR), (uint32_t)(__INTERRUPT__)) 576 577 /** 578 * @brief Check whether the specified FLASH flag is set or not. 579 * @param __FLAG__ specifies the FLASH flag to check. 580 * This parameter can be one of the following values: 581 * @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag 582 * @arg @ref FLASH_FLAG_OPERR FLASH Operation error flag 583 * @arg @ref FLASH_FLAG_PROGERR FLASH Programming error flag 584 * @arg @ref FLASH_FLAG_WRPERR FLASH Write protection error flag 585 * @arg @ref FLASH_FLAG_PGAERR FLASH Programming alignment error flag 586 * @arg @ref FLASH_FLAG_SIZERR FLASH Size error flag 587 * @arg @ref FLASH_FLAG_PGSERR FLASH Programming sequence error flag 588 * @arg @ref FLASH_FLAG_MISERR FLASH Fast programming data miss error flag 589 * @arg @ref FLASH_FLAG_FASTERR FLASH Fast programming error flag 590 * @arg @ref FLASH_FLAG_RDERR FLASH PCROP read error flag 591 * @arg @ref FLASH_FLAG_OPTVERR FLASH Option validity error flag 592 * @arg @ref FLASH_FLAG_BSY FLASH write/erase operations in progress flag 593 * @arg @ref FLASH_FLAG_CFGBSY FLASH configuration is busy : program or erase setting are used. 594 * @arg @ref FLASH_FLAG_PESD FLASH Programming/erase operation suspended 595 * @retval The new state of FLASH_FLAG (SET or RESET). 596 */ 597 #define __HAL_FLASH_GET_FLAG(__FLAG__) (READ_BIT(FLASH->SR, (__FLAG__)) == (__FLAG__)) 598 599 /** 600 * @brief Clear the FLASHs pending flags. 601 * @param __FLAG__ specifies the FLASH flags to clear. 602 * This parameter can be any combination of the following values: 603 * @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag 604 * @arg @ref FLASH_FLAG_OPERR FLASH Operation error flag 605 * @arg @ref FLASH_FLAG_PROGERR FLASH Programming error flag 606 * @arg @ref FLASH_FLAG_WRPERR FLASH Write protection error flag 607 * @arg @ref FLASH_FLAG_PGAERR FLASH Programming alignment error flag 608 * @arg @ref FLASH_FLAG_SIZERR FLASH Size error flag 609 * @arg @ref FLASH_FLAG_PGSERR FLASH Programming sequence error flag 610 * @arg @ref FLASH_FLAG_MISERR FLASH Fast programming data miss error flag 611 * @arg @ref FLASH_FLAG_FASTERR FLASH Fast programming error flag 612 * @arg @ref FLASH_FLAG_RDERR FLASH PCROP read error flag 613 * @arg @ref FLASH_FLAG_OPTVERR FLASH Option validity error flag 614 * @retval None 615 */ 616 #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) ((FLASH->SR) = (__FLAG__)) 617 618 /** 619 * @} 620 */ 621 622 /* Include FLASH HAL Extended module */ 623 #include "stm32c0xx_hal_flash_ex.h" 624 /* Exported variables --------------------------------------------------------*/ 625 /** @defgroup FLASH_Exported_Variables FLASH Exported Variables 626 * @{ 627 */ 628 extern FLASH_ProcessTypeDef pFlash; 629 /** 630 * @} 631 */ 632 633 /* Exported functions --------------------------------------------------------*/ 634 /** @addtogroup FLASH_Exported_Functions 635 * @{ 636 */ 637 638 /* Program operation functions ***********************************************/ 639 /** @addtogroup FLASH_Exported_Functions_Group1 640 * @{ 641 */ 642 HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data); 643 HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data); 644 /* FLASH IRQ handler method */ 645 void HAL_FLASH_IRQHandler(void); 646 /* Callbacks in non blocking modes */ 647 void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue); 648 void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue); 649 /** 650 * @} 651 */ 652 653 /* Peripheral Control functions **********************************************/ 654 /** @addtogroup FLASH_Exported_Functions_Group2 655 * @{ 656 */ 657 HAL_StatusTypeDef HAL_FLASH_Unlock(void); 658 HAL_StatusTypeDef HAL_FLASH_Lock(void); 659 /* Option bytes control */ 660 HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void); 661 HAL_StatusTypeDef HAL_FLASH_OB_Lock(void); 662 HAL_StatusTypeDef HAL_FLASH_OB_Launch(void); 663 /** 664 * @} 665 */ 666 667 /* Peripheral State functions ************************************************/ 668 /** @addtogroup FLASH_Exported_Functions_Group3 669 * @{ 670 */ 671 uint32_t HAL_FLASH_GetError(void); 672 /** 673 * @} 674 */ 675 676 /** 677 * @} 678 */ 679 680 /* Private types --------------------------------------------------------*/ 681 /** @defgroup FLASH_Private_types FLASH Private Types 682 * @{ 683 */ 684 HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout); 685 /** 686 * @} 687 */ 688 689 /* Private constants --------------------------------------------------------*/ 690 /** @defgroup FLASH_Private_Constants FLASH Private Constants 691 * @{ 692 */ 693 #define FLASH_SIZE_DATA_REGISTER FLASHSIZE_BASE 694 695 #define FLASH_SIZE ((((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0xFFFFU)) ? 0x8000U : \ 696 ((((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x0000U)) ? 0x8000U : \ 697 (((uint32_t)(*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) & (0x00FFU)) << 10U))) 698 699 #define FLASH_BANK_SIZE (FLASH_SIZE) /*!< FLASH Bank Size */ 700 701 #define FLASH_PAGE_SIZE 0x00000800U /*!< FLASH Page Size, 2 KBytes */ 702 703 704 #define FLASH_PAGE_NB 16U 705 706 707 #define FLASH_TIMEOUT_VALUE 1000U /*!< FLASH Execution Timeout, 1 s */ 708 709 #define FLASH_TYPENONE 0x00000000U /*!< No Programmation Procedure On Going */ 710 711 #define FLASH_FLAG_SR_ERROR (FLASH_FLAG_OPERR | FLASH_FLAG_PROGERR | FLASH_FLAG_WRPERR | \ 712 FLASH_FLAG_PGAERR | FLASH_FLAG_SIZERR | FLASH_FLAG_PGSERR | \ 713 FLASH_FLAG_MISERR | FLASH_FLAG_FASTERR | FLASH_FLAG_RDERR | \ 714 FLASH_FLAG_OPTVERR) /*!< All SR error flags */ 715 /** 716 * @} 717 */ 718 719 /* Private macros ------------------------------------------------------------*/ 720 /** @defgroup FLASH_Private_Macros FLASH Private Macros 721 * @{ 722 */ 723 #define IS_FLASH_MAIN_MEM_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= (FLASH_BASE)) && \ 724 ((__ADDRESS__) <= (FLASH_BASE + FLASH_SIZE - 1UL))) 725 726 #define IS_FLASH_PROGRAM_MAIN_MEM_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= (FLASH_BASE)) && \ 727 ((__ADDRESS__) <= (FLASH_BASE + FLASH_SIZE - 8UL))) 728 729 #define IS_FLASH_PROGRAM_OTP_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= 0x1FFF7000U) && \ 730 ((__ADDRESS__) <= (0x1FFF7400U - 8UL))) 731 732 #define IS_FLASH_PROGRAM_ADDRESS(__ADDRESS__) ((IS_FLASH_PROGRAM_MAIN_MEM_ADDRESS(__ADDRESS__)) || \ 733 (IS_FLASH_PROGRAM_OTP_ADDRESS(__ADDRESS__))) 734 735 #define IS_FLASH_FAST_PROGRAM_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= (FLASH_BASE)) && \ 736 ((__ADDRESS__) <= (FLASH_BASE + FLASH_SIZE - 256UL))) 737 738 #define IS_FLASH_PAGE(__PAGE__) ((__PAGE__) < FLASH_PAGE_NB) 739 740 #define IS_FLASH_BANK(__BANK__) ((__BANK__) == 0x00UL) 741 742 #define IS_FLASH_TYPEERASE(__VALUE__) (((__VALUE__) == FLASH_TYPEERASE_PAGES) || \ 743 ((__VALUE__) == FLASH_TYPEERASE_MASS)) 744 745 #define IS_FLASH_TYPEPROGRAM(__VALUE__) (((__VALUE__) == FLASH_TYPEPROGRAM_DOUBLEWORD) || \ 746 ((__VALUE__) == FLASH_TYPEPROGRAM_FAST)) 747 748 #define IS_OPTIONBYTE(__VALUE__) ((((__VALUE__) & OPTIONBYTE_ALL) != 0x00U) && \ 749 (((__VALUE__) & ~OPTIONBYTE_ALL) == 0x00U)) 750 751 #define IS_OB_WRPAREA(__VALUE__) (((__VALUE__) == OB_WRPAREA_ZONE_A) || \ 752 ((__VALUE__) == OB_WRPAREA_ZONE_B)) 753 754 #define IS_OB_RDP_LEVEL(__LEVEL__) (((__LEVEL__) == OB_RDP_LEVEL_0) ||\ 755 ((__LEVEL__) == OB_RDP_LEVEL_1) ||\ 756 ((__LEVEL__) == OB_RDP_LEVEL_2)) 757 758 #define IS_OB_USER_TYPE(__TYPE__) ((((__TYPE__) & OB_USER_ALL) != 0x00U) && \ 759 (((__TYPE__) & ~OB_USER_ALL) == 0x00U)) 760 761 #define IS_OB_USER_CONFIG(__TYPE__,__CONFIG__) ((~(__TYPE__) & (__CONFIG__)) == 0x00U) 762 763 #define IS_OB_PCROP_CONFIG(__CONFIG__) (((__CONFIG__) & ~(OB_PCROP_ZONE_A | OB_PCROP_ZONE_B | \ 764 OB_PCROP_RDP_ERASE)) == 0x00U) 765 766 #define IS_OB_SEC_BOOT_LOCK(__VALUE__) (((__VALUE__) == OB_BOOT_ENTRY_FORCED_NONE) || \ 767 ((__VALUE__) == OB_BOOT_ENTRY_FORCED_FLASH)) 768 769 #define IS_OB_SEC_SIZE(__VALUE__) ((__VALUE__) < (FLASH_PAGE_NB + 1U)) 770 771 #define IS_FLASH_LATENCY(__LATENCY__) (((__LATENCY__) == FLASH_LATENCY_0) || \ 772 ((__LATENCY__) == FLASH_LATENCY_1)) 773 /** 774 * @} 775 */ 776 777 /** 778 * @} 779 */ 780 781 /** 782 * @} 783 */ 784 785 #ifdef __cplusplus 786 } 787 #endif 788 789 #endif /* STM32C0xx_HAL_FLASH_H */ 790