本文整理汇总了C++中HAL_FLASHEx_Erase函数的典型用法代码示例。如果您正苦于以下问题:C++ HAL_FLASHEx_Erase函数的具体用法?C++ HAL_FLASHEx_Erase怎么用?C++ HAL_FLASHEx_Erase使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HAL_FLASHEx_Erase函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(void)
{
HAL_StatusTypeDef status;
FLASH_EraseInitTypeDef eraseInit;
uint32_t sectorError;
uint32_t *ptr=ADDRESS_SECTOR_18;
uint32_t checkCR;
int guard=0;
while(1){
status=HAL_FLASH_Unlock();
//this guard function is to program the Flash
if(guard){
while(status==HAL_BUSY);
status=HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, ADDRESS_SECTOR_18, DATA_PROGRAM);
while(status==HAL_BUSY);
guard=0;
}
//this guard function is to sector erase the Flash
if(guard){
flashEraseInit(&eraseInit,
FLASH_TYPEERASE_SECTORS,
0,
FLASH_SECTOR_18,
1,
FLASH_VOLTAGE_RANGE_3);
while(status==HAL_BUSY);
HAL_FLASHEx_Erase(&eraseInit,§orError);
while(status==HAL_BUSY);
guard=0;
}
//this guard function is to Mass erase the Flash
if(guard){
flashEraseInit(&eraseInit,
FLASH_TYPEERASE_MASSERASE,
0,
0,
1,
FLASH_VOLTAGE_RANGE_3);
while(status==HAL_BUSY);
HAL_FLASHEx_Erase(&eraseInit,§orError);
while(status==HAL_BUSY);
guard=0;
}
status=HAL_FLASH_Lock();
}
}
示例2: ErasePage
void ErasePage(uint32_t pageAddress)
{
FLASH_EraseInitTypeDef EraseInitStruct;
uint32_t FirstPage = 0, NbOfPages = 0, BankNumber = 0, PAGEError = 0;
/* Unlock the Flash to enable the flash control register access */
HAL_FLASH_Unlock();
/* Clear OPTVERR bit set on virgin samples */
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
/* Get the 1st page to erase */
FirstPage = GetPage(pageAddress);
/* Get the number of pages to erase from 1st page */
NbOfPages = 1;
/* Get the bank */
BankNumber = GetBank(pageAddress);
/* Fill EraseInit structure*/
EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
EraseInitStruct.Banks = BankNumber;
EraseInitStruct.Page = FirstPage;
EraseInitStruct.NbPages = NbOfPages;
HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError);
HAL_FLASH_Lock();
}
示例3: flash_erase
void flash_erase(uint32_t sector)
{
uint32_t SectorError = 0;
// unlock
HAL_FLASH_Unlock();
// Clear pending flags (if any)
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
// erase the sector(s)
FLASH_EraseInitTypeDef EraseInitStruct;
EraseInitStruct.TypeErase = TYPEERASE_SECTORS;
EraseInitStruct.VoltageRange = VOLTAGE_RANGE_3; // voltage range needs to be 2.7V to 3.6V
EraseInitStruct.Sector = sector;
EraseInitStruct.NbSectors = 1;
if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) {
// error occurred during sector erase
HAL_FLASH_Lock(); // lock the flash
__fatal_error();
}
HAL_FLASH_Lock(); // lock the flash
}
示例4: ResetSSIDPasswordInMemory
/**
* @brief Erase Access Point parameters from FLASH
* @param None
* @retval System_Status_t (MODULE_SUCCESS/MODULE_ERROR)
*/
System_Status_t ResetSSIDPasswordInMemory(void)
{
/* Reset Calibration Values in FLASH */
System_Status_t status = MODULE_ERROR;
/* Erase First Flash sector */
FLASH_EraseInitTypeDef EraseInitStruct;
uint32_t SectorError = 0;
EraseInitStruct.TypeErase = TYPEERASE_SECTORS;
EraseInitStruct.VoltageRange = VOLTAGE_RANGE_3;
EraseInitStruct.Sector = BLUEMSYS_FLASH_SECTOR;
EraseInitStruct.NbSectors = 1;
/* Unlock the Flash to enable the flash control register access *************/
HAL_FLASH_Unlock();
if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK){
/* Error occurred while sector erase.
User can add here some code to deal with this error.
SectorError will contain the faulty sector and then to know the code error on this sector,
user can call function 'HAL_FLASH_GetError()'
FLASH_ErrorTypeDef errorcode = HAL_FLASH_GetError(); */
printf("\n\rError while erasing FLASH memory");
} else {
status = MODULE_SUCCESS;
}
/* Lock the Flash to disable the flash control register access (recommended
to protect the FLASH memory against possible unwanted operation) *********/
HAL_FLASH_Lock();
return status;
}
示例5: FLASH_If_Erase
/**
* @brief This function does an erase of all user flash area
* @param StartSector: start of user flash area
* @retval 0: user flash area successfully erased
* 1: error occurred
*/
int8_t FLASH_If_Erase(uint32_t StartSector)
{
uint32_t FlashAddress;
FlashAddress = StartSector;
/* Device voltage range supposed to be [2.7V to 3.6V], the operation will
be done by word */
if (FlashAddress <= (uint32_t) USER_FLASH_LAST_PAGE_ADDRESS)
{
FLASH_EraseInitTypeDef FLASH_EraseInitStruct;
uint32_t sectornb = 0;
FLASH_EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
FLASH_EraseInitStruct.Sector = FLASH_SECTOR_5;
FLASH_EraseInitStruct.NbSectors = 7;
FLASH_EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;
if (HAL_FLASHEx_Erase(&FLASH_EraseInitStruct, §ornb) != HAL_OK)
return (1);
}
else
{
return (1);
}
return (0);
}
示例6: FLASH_If_Erase
/**
* @brief This function does an erase of all user flash area
* @param start: start of user flash area
* @retval FLASHIF_OK : user flash area successfully erased
* FLASHIF_ERASEKO : error occurred
*/
uint32_t FLASH_If_Erase(uint32_t start)
{
uint32_t NbrOfPages = 0;
uint32_t PageError = 0;
FLASH_EraseInitTypeDef pEraseInit;
HAL_StatusTypeDef status = HAL_OK;
/* Unlock the Flash to enable the flash control register access *************/
HAL_FLASH_Unlock();
/* Get the sector where start the user flash area */
NbrOfPages = (USER_FLASH_END_ADDRESS - start)/FLASH_PAGE_SIZE;
pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES;
pEraseInit.PageAddress = start;
pEraseInit.NbPages = NbrOfPages;
status = HAL_FLASHEx_Erase(&pEraseInit, &PageError);
/* Lock the Flash to disable the flash control register access (recommended
to protect the FLASH memory against possible unwanted operation) *********/
HAL_FLASH_Lock();
if (status != HAL_OK)
{
/* Error occurred while page erase */
return FLASHIF_ERASEKO;
}
return FLASHIF_OK;
}
示例7: Flash_If_Erase
/**
* @brief Erases sector.
* @param Add: Address of sector to be erased.
* @retval 0 if operation is successful, MAL_FAIL else.
*/
uint16_t Flash_If_Erase(uint32_t Add)
{
uint32_t startsector = 0, sectorerror = 0, nbofsectors = 0;
/* Variable contains Flash operation status */
HAL_StatusTypeDef status;
FLASH_EraseInitTypeDef eraseinitstruct;
/* Get the number of sector */
startsector = GetSector(Add);
/* Get the number of sector to erase from the start sector: max number of sectors - value of Initial sector */
nbofsectors = (USBD_DFU_MAX_NB_OF_SECTORS - startsector);
eraseinitstruct.TypeErase = FLASH_TYPEERASE_SECTORS;
eraseinitstruct.Banks = 0;
eraseinitstruct.Sector = startsector;
eraseinitstruct.NbSectors = nbofsectors;
eraseinitstruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;
status = HAL_FLASHEx_Erase(&eraseinitstruct, §orerror);
if (status != HAL_OK)
{
return 1;
}
return 0;
}
示例8: flash_erase
void flash_erase(uint32_t flash_dest, const uint32_t *src, uint32_t num_word32) {
// check there is something to write
if (num_word32 == 0) {
return;
}
// unlock
HAL_FLASH_Unlock();
// Clear pending flags (if any)
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
// erase the sector(s)
FLASH_EraseInitTypeDef EraseInitStruct;
EraseInitStruct.TypeErase = TYPEERASE_SECTORS;
EraseInitStruct.VoltageRange = VOLTAGE_RANGE_3; // voltage range needs to be 2.7V to 3.6V
EraseInitStruct.Sector = flash_get_sector_info(flash_dest, NULL, NULL);
EraseInitStruct.NbSectors = flash_get_sector_info(flash_dest + 4 * num_word32 - 1, NULL, NULL) - EraseInitStruct.Sector + 1;
uint32_t SectorError = 0;
if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) {
// error occurred during sector erase
HAL_FLASH_Lock(); // lock the flash
return;
}
}
示例9: FLASH_If_Erase
/**
* @brief This function does an erase of all user flash area
* @param StartSector: start of user flash area
* @retval 0: user flash area successfully erased
* 1: error occurred
*/
uint32_t FLASH_If_Erase(uint32_t StartSector)
{
uint32_t UserStartSector;
uint32_t SectorError;
FLASH_EraseInitTypeDef pEraseInit;
/* Unlock the Flash to enable the flash control register access *************/
FLASH_If_Init();
/* Get the sector where start the user flash area */
UserStartSector = GetSector(APPLICATION_ADDRESS);
pEraseInit.TypeErase = TYPEERASE_SECTORS;
pEraseInit.Sector = UserStartSector;
pEraseInit.NbSectors = 6;
pEraseInit.VoltageRange = VOLTAGE_RANGE_3;
if (HAL_FLASHEx_Erase(&pEraseInit, &SectorError) != HAL_OK)
{
/* Error occurred while page erase */
return (1);
}
return (0);
}
示例10: FLASH_If_EraseSectors
/**
* @brief Erases the required FLASH Sectors.
* @param Address: Start address for erasing data
* @retval 0: Erase sectors done with success
* 1: Erase error
*/
uint32_t FLASH_If_EraseSectors(uint32_t Address)
{
/* Erase the user Flash area
(area defined by APPLICATION_ADDRESS and USER_FLASH_LAST_PAGE_ADDRESS) ****/
if(Address <= (uint32_t) USER_FLASH_LAST_PAGE_ADDRESS)
{
/* Get the 1st sector to erase */
FirstSector = FLASH_If_GetSectorNumber(Address);
/* Get the number of sector to erase from 1st sector */
NbOfSectors = FLASH_If_GetSectorNumber(USER_FLASH_LAST_PAGE_ADDRESS) - FirstSector + 1;
FLASH_EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
FLASH_EraseInitStruct.Sector = FirstSector;
FLASH_EraseInitStruct.NbSectors = NbOfSectors;
FLASH_EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;
if(HAL_FLASHEx_Erase(&FLASH_EraseInitStruct, &SectorError) != HAL_OK)
return (1);
}
else
{
return (1);
}
return (0);
}
示例11: writeEEPROM
// FIXME: HAL for now this will only work for F4/F7 as flash layout is different
void writeEEPROM(void)
{
// Generate compile time error if the config does not fit in the reserved area of flash.
BUILD_BUG_ON(sizeof(master_t) > FLASH_TO_RESERVE_FOR_CONFIG);
HAL_StatusTypeDef status;
uint32_t wordOffset;
int8_t attemptsRemaining = 3;
suspendRxSignal();
// prepare checksum/version constants
masterConfig.version = EEPROM_CONF_VERSION;
masterConfig.size = sizeof(master_t);
masterConfig.magic_be = 0xBE;
masterConfig.magic_ef = 0xEF;
masterConfig.chk = 0; // erase checksum before recalculating
masterConfig.chk = calculateChecksum((const uint8_t *) &masterConfig, sizeof(master_t));
// write it
/* Unlock the Flash to enable the flash control register access *************/
HAL_FLASH_Unlock();
while (attemptsRemaining--)
{
/* Fill EraseInit structure*/
FLASH_EraseInitTypeDef EraseInitStruct = {0};
EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3; // 2.7-3.6V
EraseInitStruct.Sector = (FLASH_SECTOR_TOTAL-1);
EraseInitStruct.NbSectors = 1;
uint32_t SECTORError;
status = HAL_FLASHEx_Erase(&EraseInitStruct, &SECTORError);
if (status != HAL_OK)
{
continue;
}
else
{
for (wordOffset = 0; wordOffset < sizeof(master_t); wordOffset += 4)
{
status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, CONFIG_START_FLASH_ADDRESS + wordOffset, *(uint32_t *) ((char *) &masterConfig + wordOffset));
if(status != HAL_OK)
{
break;
}
}
}
if (status == HAL_OK) {
break;
}
}
HAL_FLASH_Lock();
// Flash write failed - just die now
if (status != HAL_OK || !isEEPROMContentValid()) {
failureMode(FAILURE_FLASH_WRITE_FAILED);
}
resumeRxSignal();
}
示例12: stm32f3_flash_erase_block
/**
* @brief Erase flash block
* @note Block is the same thing as page in terms of stm32 lib:
* it's minimal erasable chunk of flash memory
*
* @param dev
* @param block
*
* @return Error code
*/
static int stm32f3_flash_erase_block(struct flash_dev *dev, uint32_t block) {
int err;
uint32_t page_err;
FLASH_EraseInitTypeDef erase_struct;
if (!stm32f3_flash_check_block(dev, block)) {
return -EINVAL;
}
HAL_FLASH_Unlock();
erase_struct = (FLASH_EraseInitTypeDef) {
.TypeErase = TYPEERASE_PAGES,
.PageAddress = dev->start + block * STM32F3_FLASH_PAGE_SIZE,
.NbPages = 1,
};
err = HAL_FLASHEx_Erase(&erase_struct, &page_err);
/* TODO check errcode */
/* Lock to prevent unwanted operations with flash memory */
HAL_FLASH_Lock();
return err;
}
static int stm32f3_flash_read(struct flash_dev *dev, uint32_t base, void* data, size_t len) {
size_t rlen = min(len, dev->end - dev->start + base);
/* read can be unaligned */
memcpy(data, (void *) dev->start + base, rlen);
return rlen;
}
示例13: stm32_flash_bdev_erase
static ssize_t stm32_flash_bdev_erase(struct bdev *bdev, off_t offset, size_t len)
{
LTRACEF("dev %p, offset 0x%llx, len 0x%zx\n", bdev, offset, len);
ssize_t total_erased = 0;
HAL_FLASH_Unlock();
while (len > 0) {
uint32_t sector = 0;
off_t sector_offset = 0;
off_t next_offset = 0;
if (offset_to_sector(offset, §or, §or_offset, &next_offset) < 0)
return ERR_INVALID_ARGS;
FLASH_EraseInitTypeDef erase;
erase.TypeErase = FLASH_TYPEERASE_SECTORS;
erase.Sector = sector;
erase.NbSectors = 1;
erase.VoltageRange = FLASH_VOLTAGE_RANGE_3; // XXX
LTRACEF("erase params: sector %u, num_sectors %u, next_offset 0x%llx\n", erase.Sector, erase.NbSectors, next_offset);
if (1) {
uint32_t sector_error;
HAL_StatusTypeDef err = HAL_FLASHEx_Erase(&erase, §or_error);
if (err != HAL_OK) {
TRACEF("error starting erase operation, sector error %u\n", sector_error);
total_erased = ERR_IO;
break;
}
err = FLASH_WaitForLastOperation(HAL_MAX_DELAY);
if (err != HAL_OK) {
TRACEF("error waiting for erase operation to end, hal error %u\n", HAL_FLASH_GetError());
total_erased = ERR_IO;
break;
}
// invalidate the cache on this region
arch_invalidate_cache_range(FLASHAXI_BASE + sector_offset, next_offset - sector_offset);
}
// move to the next erase boundary
total_erased += next_offset - sector_offset;
off_t erased_bytes = next_offset - offset;
if (erased_bytes >= len)
break;
len -= erased_bytes;
offset = next_offset;
}
HAL_FLASH_Lock();
return total_erased;
}
示例14: EE_Format
/**
* @brief Erases PAGE and PAGE1 and writes VALID_PAGE header to PAGE
* @param None
* @retval Status of the last operation (Flash write or erase) done during
* EEPROM formating
*/
static HAL_StatusTypeDef EE_Format(void)
{
HAL_StatusTypeDef FlashStatus = HAL_OK;
uint32_t SectorError = 0;
FLASH_EraseInitTypeDef pEraseInit;
pEraseInit.TypeErase = FLASH_TYPEERASE_SECTORS;
pEraseInit.Sector = PAGE0_ID;
pEraseInit.NbSectors = 1;
pEraseInit.VoltageRange = VOLTAGE_RANGE;
/* Erase Page0 */
if(!EE_VerifyPageFullyErased(PAGE0_BASE_ADDRESS))
{
FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
/* If erase operation was failed, a Flash error code is returned */
if (FlashStatus != HAL_OK)
{
return FlashStatus;
}
}
/* Set Page0 as valid page: Write VALID_PAGE at Page0 base address */
FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, PAGE0_BASE_ADDRESS, VALID_PAGE);
/* If program operation was failed, a Flash error code is returned */
if (FlashStatus != HAL_OK)
{
return FlashStatus;
}
pEraseInit.Sector = PAGE1_ID;
/* Erase Page1 */
if(!EE_VerifyPageFullyErased(PAGE1_BASE_ADDRESS))
{
FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
/* If erase operation was failed, a Flash error code is returned */
if (FlashStatus != HAL_OK)
{
return FlashStatus;
}
}
return HAL_OK;
}
示例15: EE_Format
/**
* @brief Erases PAGE and PAGE1 and writes VALID_PAGE header to PAGE
* @param None
* @retval Status of the last operation (Flash write or erase) done during
* EEPROM formating
*/
static HAL_StatusTypeDef EE_Format(void)
{
HAL_StatusTypeDef flashstatus = HAL_OK;
uint32_t page_error = 0;
FLASH_EraseInitTypeDef s_eraseinit;
s_eraseinit.TypeErase = FLASH_TYPEERASE_PAGES;
s_eraseinit.PageAddress = PAGE0_ID;
s_eraseinit.NbPages = 1;
/* Erase Page0 */
if(!EE_VerifyPageFullyErased(PAGE0_BASE_ADDRESS))
{
flashstatus = HAL_FLASHEx_Erase(&s_eraseinit, &page_error);
/* If erase operation was failed, a Flash error code is returned */
if (flashstatus != HAL_OK)
{
return flashstatus;
}
}
/* Set Page0 as valid page: Write VALID_PAGE at Page0 base address */
flashstatus = HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, PAGE0_BASE_ADDRESS, VALID_PAGE);
/* If program operation was failed, a Flash error code is returned */
if (flashstatus != HAL_OK)
{
return flashstatus;
}
s_eraseinit.PageAddress = PAGE1_ID;
/* Erase Page1 */
if(!EE_VerifyPageFullyErased(PAGE1_BASE_ADDRESS))
{
flashstatus = HAL_FLASHEx_Erase(&s_eraseinit, &page_error);
/* If erase operation was failed, a Flash error code is returned */
if (flashstatus != HAL_OK)
{
return flashstatus;
}
}
return HAL_OK;
}