73#ifdef HAL_FLASH_MODULE_ENABLED
80#define FLASH_TIMEOUT_VALUE 50000U
100static void FLASH_MassErase(uint8_t VoltageRange, uint32_t Banks);
104static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t Iwdg, uint8_t Stop, uint8_t Stdby);
106static uint8_t FLASH_OB_GetUser(
void);
107static uint16_t FLASH_OB_GetWRP(
void);
108static uint8_t FLASH_OB_GetRDP(
void);
109static uint8_t FLASH_OB_GetBOR(
void);
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)
120static HAL_StatusTypeDef FLASH_OB_EnablePCROP(uint32_t SectorBank1, uint32_t SectorBank2, uint32_t Banks);
121static HAL_StatusTypeDef FLASH_OB_DisablePCROP(uint32_t SectorBank1, uint32_t SectorBank2, uint32_t Banks);
177 *SectorError = 0xFFFFFFFFU;
188 FLASH->CR &= (~FLASH_MER_BIT);
204 CLEAR_BIT(FLASH->CR, (FLASH_CR_SER | FLASH_CR_SNB));
209 *SectorError = index;
310 status = FLASH_OB_RDP_LevelConfig(pOBInit->
RDPLevel);
324 status = FLASH_OB_BOR_LevelConfig(pOBInit->
BORLevel);
345 pOBInit->
WRPSector = (uint32_t)FLASH_OB_GetWRP();
348 pOBInit->
RDPLevel = (uint32_t)FLASH_OB_GetRDP();
351 pOBInit->
USERConfig = (uint8_t)FLASH_OB_GetUser();
354 pOBInit->
BORLevel = (uint32_t)FLASH_OB_GetBOR();
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)
369HAL_StatusTypeDef HAL_FLASHEx_AdvOBProgram(FLASH_AdvOBProgramInitTypeDef *pAdvOBInit)
377 if (((pAdvOBInit->OptionType) & OPTIONBYTE_PCROP) == OPTIONBYTE_PCROP)
381 if ((pAdvOBInit->PCROPState) == OB_PCROP_STATE_ENABLE)
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)
387 status = FLASH_OB_EnablePCROP(pAdvOBInit->Sectors);
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)
399 status = FLASH_OB_DisablePCROP(pAdvOBInit->Sectors);
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);
425void HAL_FLASHEx_AdvOBGetConfig(FLASH_AdvOBProgramInitTypeDef *pAdvOBInit)
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));
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)
537static void FLASH_MassErase(uint8_t VoltageRange, uint32_t Banks)
544 CLEAR_BIT(FLASH->CR, FLASH_CR_PSIZE);
546 if (Banks == FLASH_BANK_BOTH)
549 FLASH->CR |= FLASH_MER_BIT;
551 else if (Banks == FLASH_BANK_1)
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;
654 if (((WRPSector == OB_WRP_SECTOR_All) && ((Banks == FLASH_BANK_1) || (Banks == FLASH_BANK_BOTH))) ||
655 (WRPSector < OB_WRP_SECTOR_12))
657 if (WRPSector == OB_WRP_SECTOR_All)
671 *(__IO uint16_t *)OPTCR1_BYTE2_ADDRESS &= (~(WRPSector >> 12));
675 if ((WRPSector == OB_WRP_SECTOR_All) && (Banks == FLASH_BANK_BOTH))
682 *(__IO uint16_t *)OPTCR1_BYTE2_ADDRESS &= (~(WRPSector >> 12));
725 if (((WRPSector == OB_WRP_SECTOR_All) && ((Banks == FLASH_BANK_1) || (Banks == FLASH_BANK_BOTH))) ||
726 (WRPSector < OB_WRP_SECTOR_12))
728 if (WRPSector == OB_WRP_SECTOR_All)
742 *(__IO uint16_t *)OPTCR1_BYTE2_ADDRESS |= (uint16_t)(WRPSector >> 12);
746 if ((WRPSector == OB_WRP_SECTOR_All) && (Banks == FLASH_BANK_BOTH))
753 *(__IO uint16_t *)OPTCR1_BYTE2_ADDRESS |= (uint16_t)(WRPSector >> 12);
813static HAL_StatusTypeDef FLASH_OB_EnablePCROP(uint32_t SectorBank1, uint32_t SectorBank2, uint32_t Banks)
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;
877static HAL_StatusTypeDef FLASH_OB_DisablePCROP(uint32_t SectorBank1, uint32_t SectorBank2, uint32_t Banks)
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) ||\
948static void FLASH_MassErase(uint8_t VoltageRange, uint32_t Banks)
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)
1191static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t Iwdg, uint8_t Stop, uint8_t Stdby)
1210 *(__IO uint8_t *)
OPTCR_BYTE0_ADDRESS = Iwdg | (uint8_t)(Stdby | (uint8_t)(Stop | ((uint8_t)optiontmp)));
1244static uint8_t FLASH_OB_GetUser(
void)
1247 return ((uint8_t)(FLASH->OPTCR & 0xE0));
1254static uint16_t FLASH_OB_GetWRP(
void)
1268static uint8_t FLASH_OB_GetRDP(
void)
1296static uint8_t FLASH_OB_GetBOR(
void)
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)
HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *SectorError)
void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit)
HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit)
#define IS_OB_STOP_SOURCE(SOURCE)
#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_VOLTAGERANGE(RANGE)
#define IS_OB_BOR_LEVEL(LEVEL)
#define IS_FLASH_TYPEERASE(VALUE)
#define IS_OB_IWDG_SOURCE(SOURCE)
void FLASH_FlushCaches(void)
void FLASH_Erase_Sector(uint32_t Sector, uint8_t VoltageRange)
#define FLASH_TYPEERASE_MASSERASE
#define FLASH_VOLTAGE_RANGE_3
#define FLASH_VOLTAGE_RANGE_1
#define FLASH_VOLTAGE_RANGE_2
#define OB_WRPSTATE_ENABLE
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
#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 Erase structure definition.
FLASH Option Bytes Program structure definition.
FLASH handle Structure definition.
volatile uint32_t NbSectorsToErase
volatile FLASH_ProcedureTypeDef ProcedureOnGoing
volatile uint8_t VoltageForErase