73#ifdef HAL_FLASH_MODULE_ENABLED
80#define FLASH_TIMEOUT_VALUE 50000U
111#if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F411xE) ||\
112 defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) ||\
119#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx) || defined(STM32F469xx) || defined(STM32F479xx)
177 *SectorError = 0xFFFFFFFFU;
188 FLASH->CR &= (~FLASH_MER_BIT);
204 CLEAR_BIT(FLASH->CR, (FLASH_CR_SER | FLASH_CR_SNB));
209 *SectorError = index;
357#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
358 defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F410Tx) || defined(STM32F410Cx) ||\
359 defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F469xx) ||\
360 defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) ||\
361 defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
384#if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) ||\
385 defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) ||\
386 defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
389 status =
FLASH_OB_EnablePCROP(pAdvOBInit->SectorsBank1, pAdvOBInit->SectorsBank2, pAdvOBInit->Banks);
396#if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) ||\
397 defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) ||\
398 defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
401 status =
FLASH_OB_DisablePCROP(pAdvOBInit->SectorsBank1, pAdvOBInit->SectorsBank2, pAdvOBInit->Banks);
407#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || defined(STM32F469xx) || defined(STM32F479xx)
409 if (((pAdvOBInit->
OptionType) & OPTIONBYTE_BOOTCONFIG) == OPTIONBYTE_BOOTCONFIG)
411 status = FLASH_OB_BootConfig(pAdvOBInit->BootConfig);
427#if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) ||\
428 defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) ||\
429 defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
437 pAdvOBInit->SectorsBank2 = (*(__IO uint16_t *)(OPTCR1_BYTE2_ADDRESS));
459 uint8_t optiontmp = 0xFF;
484 uint8_t optiontmp = 0xFF;
498#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx) || defined(STM32F469xx) || defined(STM32F479xx)
504uint16_t HAL_FLASHEx_OB_GetBank2WRP(
void)
507 return (*(__IO uint16_t *)(OPTCR1_BYTE2_ADDRESS));
515#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || defined(STM32F469xx) || defined(STM32F479xx)
544 CLEAR_BIT(FLASH->CR, FLASH_CR_PSIZE);
546 if (Banks == FLASH_BANK_BOTH)
554 FLASH->CR |= FLASH_CR_MER1;
559 FLASH->CR |= FLASH_CR_MER2;
561 FLASH->CR |= FLASH_CR_STRT | ((uint32_t)VoltageRange << 8U);
583 uint32_t tmp_psize = 0U;
607 if (Sector > FLASH_SECTOR_11)
612 CLEAR_BIT(FLASH->CR, FLASH_CR_PSIZE);
613 FLASH->CR |= tmp_psize;
614 CLEAR_BIT(FLASH->CR, FLASH_CR_SNB);
615 FLASH->CR |= FLASH_CR_SER | (Sector << FLASH_CR_SNB_Pos);
616 FLASH->CR |= FLASH_CR_STRT;
655 (WRPSector < OB_WRP_SECTOR_12))
671 *(__IO uint16_t *)OPTCR1_BYTE2_ADDRESS &= (~(WRPSector >> 12));
682 *(__IO uint16_t *)OPTCR1_BYTE2_ADDRESS &= (~(WRPSector >> 12));
726 (WRPSector < OB_WRP_SECTOR_12))
742 *(__IO uint16_t *)OPTCR1_BYTE2_ADDRESS |= (uint16_t)(WRPSector >> 12);
753 *(__IO uint16_t *)OPTCR1_BYTE2_ADDRESS |= (uint16_t)(WRPSector >> 12);
824 if ((Banks ==
FLASH_BANK_1) || (Banks == FLASH_BANK_BOTH))
834 *(__IO uint16_t *)OPTCR1_BYTE2_ADDRESS |= (uint16_t)SectorBank2;
838 if (Banks == FLASH_BANK_BOTH)
847 *(__IO uint16_t *)OPTCR1_BYTE2_ADDRESS |= (uint16_t)SectorBank2;
889 if ((Banks ==
FLASH_BANK_1) || (Banks == FLASH_BANK_BOTH))
899 *(__IO uint16_t *)OPTCR1_BYTE2_ADDRESS &= (~SectorBank2);
903 if (Banks == FLASH_BANK_BOTH)
912 *(__IO uint16_t *)OPTCR1_BYTE2_ADDRESS &= (~SectorBank2);
924#if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\
925 defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F410Tx) || defined(STM32F410Cx) ||\
926 defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) ||\
927 defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) ||\
955 CLEAR_BIT(FLASH->CR, FLASH_CR_PSIZE);
956 FLASH->CR |= FLASH_CR_MER;
957 FLASH->CR |= FLASH_CR_STRT | ((uint32_t)VoltageRange << 8U);
979 uint32_t tmp_psize = 0U;
1003 CLEAR_BIT(FLASH->CR, FLASH_CR_PSIZE);
1004 FLASH->CR |= tmp_psize;
1005 CLEAR_BIT(FLASH->CR, FLASH_CR_SNB);
1006 FLASH->CR |= FLASH_CR_SER | (Sector << FLASH_CR_SNB_Pos);
1007 FLASH->CR |= FLASH_CR_STRT;
1084#if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) ||\
1085 defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) ||\
1086 defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
1193 uint8_t optiontmp = 0xFF;
1210 *(__IO uint8_t *)
OPTCR_BYTE0_ADDRESS = Iwdg | (uint8_t)(Stdby | (uint8_t)(Stop | ((uint8_t)optiontmp)));
1247 return ((uint8_t)(FLASH->OPTCR & 0xE0));
1309 if (READ_BIT(FLASH->ACR, FLASH_ACR_ICEN) != RESET)
1320 if (READ_BIT(FLASH->ACR, FLASH_ACR_DCEN) != RESET)
HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit)
Program option bytes.
HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *SectorError)
Perform a mass erase or erase the specified FLASH memory sectors.
void HAL_FLASHEx_AdvOBGetConfig(FLASH_AdvOBProgramInitTypeDef *pAdvOBInit)
Get the OBEX byte configuration.
void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit)
Get the Option byte configuration.
HAL_StatusTypeDef HAL_FLASHEx_OB_SelectPCROP(void)
Select the Protection Mode.
HAL_StatusTypeDef HAL_FLASHEx_OB_DeSelectPCROP(void)
Deselect the Protection Mode.
HAL_StatusTypeDef HAL_FLASHEx_AdvOBProgram(FLASH_AdvOBProgramInitTypeDef *pAdvOBInit)
Program option bytes.
HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit)
Perform a mass erase or erase the specified FLASH memory sectors with interrupt enabled.
void FLASH_FlushCaches(void)
Flush the instruction and data caches.
void FLASH_Erase_Sector(uint32_t Sector, uint8_t VoltageRange)
Erase the specified FLASH memory sector.
#define IS_OB_STOP_SOURCE(SOURCE)
#define IS_FLASH_BANK(BANK)
#define IS_OB_PCROP(SECTOR)
#define IS_FLASH_NBSECTORS(NBSECTORS)
#define IS_WRPSTATE(VALUE)
#define IS_OPTIONBYTE(VALUE)
#define IS_OB_STDBY_SOURCE(SOURCE)
#define IS_OB_RDP_LEVEL(LEVEL)
#define IS_FLASH_SECTOR(SECTOR)
#define IS_VOLTAGERANGE(RANGE)
#define IS_PCROPSTATE(VALUE)
#define IS_OB_BOR_LEVEL(LEVEL)
#define IS_OB_WRP_SECTOR(SECTOR)
#define IS_FLASH_TYPEERASE(VALUE)
#define IS_OB_IWDG_SOURCE(SOURCE)
#define OB_WRP_SECTOR_All
#define OB_PCROP_STATE_ENABLE
#define FLASH_TIMEOUT_VALUE
static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WRPSector, uint32_t Banks)
Disable the write protection of the desired bank 1 sectors.
static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t Level)
Set the read protection level.
static HAL_StatusTypeDef FLASH_OB_BOR_LevelConfig(uint8_t Level)
Set the BOR Level.
static uint8_t FLASH_OB_GetBOR(void)
Returns the FLASH BOR level.
static uint16_t FLASH_OB_GetWRP(void)
Return the FLASH Write Protection Option Bytes value.
static uint8_t FLASH_OB_GetRDP(void)
Returns the FLASH Read Protection level.
static void FLASH_MassErase(uint8_t VoltageRange, uint32_t Banks)
Mass erase of FLASH memory.
static uint8_t FLASH_OB_GetUser(void)
Return the FLASH User Option Byte value.
static HAL_StatusTypeDef FLASH_OB_EnablePCROP(uint32_t Sector)
Enable the read/write protection (PCROP) of the desired sectors.
static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WRPSector, uint32_t Banks)
Enable the write protection of the desired bank 1 sectors.
static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t Iwdg, uint8_t Stop, uint8_t Stdby)
Program the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY.
static HAL_StatusTypeDef FLASH_OB_DisablePCROP(uint32_t Sector)
Disable the read/write protection (PCROP) of the desired sectors.
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
Wait for a FLASH operation to complete.
FLASH_ProcessTypeDef pFlash
#define OB_PCROP_SELECTED
#define OB_PCROP_DESELECTED
#define FLASH_TYPEERASE_MASSERASE
#define FLASH_VOLTAGE_RANGE_3
#define FLASH_VOLTAGE_RANGE_1
#define FLASH_VOLTAGE_RANGE_2
#define OB_WRPSTATE_ENABLE
#define __HAL_FLASH_INSTRUCTION_CACHE_DISABLE()
Disable the FLASH instruction cache.
#define __HAL_FLASH_ENABLE_IT(__INTERRUPT__)
Enable the specified FLASH interrupt.
#define __HAL_FLASH_DATA_CACHE_DISABLE()
Disable the FLASH data cache.
#define __HAL_FLASH_DATA_CACHE_RESET()
Resets the FLASH data Cache.
#define __HAL_FLASH_CLEAR_FLAG(__FLAG__)
Clear the specified FLASH flags.
#define __HAL_FLASH_INSTRUCTION_CACHE_RESET()
Resets the FLASH instruction Cache.
#define __HAL_FLASH_DATA_CACHE_ENABLE()
Enable the FLASH data cache.
#define __HAL_FLASH_INSTRUCTION_CACHE_ENABLE()
Enable the FLASH instruction cache.
#define FLASH_FLAG_PGSERR
#define FLASH_FLAG_PGAERR
#define FLASH_FLAG_WRPERR
#define FLASH_FLAG_PGPERR
#define OPTCR_BYTE1_ADDRESS
OPTCR register byte 1 (Bits[15:8]) base address.
#define OPTCR_BYTE2_ADDRESS
OPTCR register byte 2 (Bits[23:16]) base address.
#define OPTCR_BYTE0_ADDRESS
OPTCR register byte 0 (Bits[7:0]) base address.
#define OPTCR_BYTE3_ADDRESS
OPTCR register byte 3 (Bits[31:24]) base address.
#define FLASH_PSIZE_DOUBLE_WORD
#define FLASH_PSIZE_HALF_WORD
#define assert_param(expr)
This file contains all the functions prototypes for the HAL module driver.
HAL_StatusTypeDef
HAL Status structures definition
#define __HAL_UNLOCK(__HANDLE__)
#define __HAL_LOCK(__HANDLE__)
FLASH Advanced Option Bytes Program structure definition.
FLASH Erase structure definition.
FLASH Option Bytes Program structure definition.
FLASH handle Structure definition.
__IO uint32_t NbSectorsToErase
__IO uint8_t VoltageForErase
__IO FLASH_ProcedureTypeDef ProcedureOnGoing