• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ HAL_FLASHEx_Erase函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中HAL_FLASHEx_Erase函数的典型用法代码示例。如果您正苦于以下问题:C++ HAL_FLASHEx_Erase函数的具体用法?C++ HAL_FLASHEx_Erase怎么用?C++ HAL_FLASHEx_Erase使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了HAL_FLASHEx_Erase函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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,&sectorError);
			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,&sectorError);
			while(status==HAL_BUSY);
			guard=0;
		}



		status=HAL_FLASH_Lock();

	}




}
开发者ID:JangSing,项目名称:stm32f429_Flash_Hal,代码行数:56,代码来源:main.c


示例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();
}
开发者ID:meisteg,项目名称:muc-loader,代码行数:27,代码来源:stm32l4xx_flash.c


示例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
}
开发者ID:michaelchi08,项目名称:openmv,代码行数:26,代码来源:flash.c


示例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;
}
开发者ID:nguyendinhthi,项目名称:nguyendinh,代码行数:38,代码来源:wifi_support.c


示例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, &sectornb) != HAL_OK)
      return (1);
  }
  else
  {
    return (1);
  }

  return (0);
}
开发者ID:451506709,项目名称:automated_machine,代码行数:35,代码来源:flash_if.c


示例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;
}
开发者ID:NjordCZ,项目名称:stm32cubef0,代码行数:36,代码来源:flash_if.c


示例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, &sectorerror);
  
  if (status != HAL_OK)
  {
    return 1;
  }
  return 0;
}
开发者ID:z80,项目名称:stm32f429,代码行数:31,代码来源:usbd_dfu_flash.c


示例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;
    }
}
开发者ID:ashtons,项目名称:micropython,代码行数:26,代码来源:flash.c


示例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);
}
开发者ID:MrZANE42,项目名称:verisure1512,代码行数:31,代码来源:flash_if.c


示例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);
}
开发者ID:Joe-Merten,项目名称:Stm32-Tools-Evaluation,代码行数:33,代码来源:flash_if.c


示例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();
}
开发者ID:tianbin4279,项目名称:betaflight,代码行数:61,代码来源:config_eeprom.c


示例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;
}
开发者ID:AleksandraButrova,项目名称:embox,代码行数:45,代码来源:stm32f3_flash.c


示例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, &sector, &sector_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, &sector_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;
}
开发者ID:ajithat,项目名称:lk,代码行数:57,代码来源:flash.c


示例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;
}
开发者ID:z80,项目名称:stm32f429,代码行数:48,代码来源:eeprom.c


示例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;
}
开发者ID:Lembed,项目名称:STM32CubeF1-mirrors,代码行数:47,代码来源:eeprom.c


示例16: stm32f4_flash_erase_sector_id

static void
stm32f4_flash_erase_sector_id(int sector_id)
{
    FLASH_EraseInitTypeDef eraseinit;
    uint32_t SectorError;

    eraseinit.TypeErase = FLASH_TYPEERASE_SECTORS;
    eraseinit.Banks = 0;
    eraseinit.Sector = sector_id;
    eraseinit.NbSectors = 1;
    eraseinit.VoltageRange = FLASH_VOLTAGE_RANGE_1;

    HAL_FLASHEx_Erase(&eraseinit, &SectorError);
}
开发者ID:ccollins476ad,项目名称:incubator-mynewt-core,代码行数:14,代码来源:hal_flash.c


示例17: flash_erase

int flash_erase(uint32_t start_addr, uint32_t size)
{
  FLASH_EraseInitTypeDef EraseInitStruct;
  uint32_t FirstPage = 0, NbOfPages = 0, BankNumber = 0, PAGEError = 0;
  uint32_t end_addr = start_addr + size;

  /* Unlock the Flash to enable the flash control register access *************/
  HAL_FLASH_Unlock();

  /* Erase the user Flash area */

  /* Clear OPTVERR bit set on virgin samples */
  __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
  /* Get the 1st page to erase */
  FirstPage = GetPage(start_addr);
  /* Get the number of pages to erase from 1st page */
  NbOfPages = GetPage(end_addr) - FirstPage + 1;
  /* Get the bank */
  BankNumber = GetBank(start_addr);
  /* Fill EraseInit structure*/
  EraseInitStruct.TypeErase   = FLASH_TYPEERASE_PAGES;
  EraseInitStruct.Banks       = BankNumber;
  EraseInitStruct.Page        = FirstPage;
  EraseInitStruct.NbPages     = NbOfPages;

  /* Note: If an erase operation in Flash memory also concerns data in the data or instruction cache,
     you have to make sure that these data are rewritten before they are accessed during code
     execution. If this cannot be done safely, it is recommended to flush the caches by setting the
     DCRST and ICRST bits in the FLASH_CR register. */
  if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK)
  {
    /*
      Error occurred while page erase.
      User can add here some code to deal with this error.
      PAGEError will contain the faulty page and then to know the code error on this page,
      user can call function 'HAL_FLASH_GetError()'
    */
    /* Infinite loop */
    while (1) {
    }
  }
  return 0;
}
开发者ID:meisteg,项目名称:muc-loader,代码行数:43,代码来源:stm32l4xx_flash.c


示例18: stm32f3_flash_erase_sector

static int
stm32f3_flash_erase_sector(const struct hal_flash *dev, uint32_t sector_address)
{
    FLASH_EraseInitTypeDef erase;
    int rc = -1;
    uint32_t errorPage = -1;

    erase.TypeErase = FLASH_TYPEERASE_PAGES;
    erase.PageAddress = sector_address;
    erase.NbPages = 1;

    HAL_FLASH_Unlock();
    if (HAL_OK == HAL_FLASHEx_Erase(&erase, &errorPage)) {
      rc = 0;
    }
    HAL_FLASH_Lock();

    return rc;
}
开发者ID:ccollins476ad,项目名称:incubator-mynewt-core,代码行数:19,代码来源:hal_flash.c


示例19: flash_erase_sector

/** Erase one sector starting at defined address
 *
 * The address should be at sector boundary. This function does not do any check for address alignments
 * @param obj The flash object
 * @param address The sector starting address
 * @return 0 for success, -1 for error
 */
int32_t flash_erase_sector(flash_t *obj, uint32_t address)
{
    uint32_t FirstPage = 0, BankNumber = 0;
    uint32_t PAGEError = 0;
    FLASH_EraseInitTypeDef EraseInitStruct;
    int32_t status = 0;

    if ((address >= (FLASH_BASE + FLASH_SIZE)) || (address < FLASH_BASE)) {

        return -1;
    }

    if (flash_unlock() != HAL_OK) {
        return -1;
    }

      /* Clear OPTVERR bit set on virgin samples */
    __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
    /* Get the 1st page to erase */
    FirstPage = GetPage(address);
    /* MBED HAL erases 1 page  / sector at a time */
    /* Get the bank */
    BankNumber = GetBank(address);
    /* Fill EraseInit structure*/
    EraseInitStruct.TypeErase   = FLASH_TYPEERASE_PAGES;
    EraseInitStruct.Banks       = BankNumber;
    EraseInitStruct.Page        = FirstPage;
    EraseInitStruct.NbPages     = 1;

    /* Note: If an erase operation in Flash memory also concerns data in the data or instruction cache,
     you have to make sure that these data are rewritten before they are accessed during code
     execution. If this cannot be done safely, it is recommended to flush the caches by setting the
     DCRST and ICRST bits in the FLASH_CR register. */

    if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK) {
        status = -1;
    }

    flash_lock();

    return status;
}
开发者ID:Archcady,项目名称:mbed-os,代码行数:49,代码来源:flash_api.c


示例20: EE_WriteVariable

void EE_WriteVariable(EepromAddress32 virtAddress, uint32_t data)
{
	uint16_t length=EE_LastUnusedVariable;
	uint32_t address = FLASH_USER_START_ADDR;
	for (uint16_t varIndex = 0;varIndex < length;varIndex++)
	{
		uint32_t data32 = *(__IO uint32_t *)address;
		EE_storage[varIndex] = data32;
		address = address + 4;
	}
	EE_storage[virtAddress] = data; //write the new data

	HAL_FLASH_Unlock();
	/* Get the 1st page to erase */
	uint32_t FirstPage = GetPage(FLASH_USER_START_ADDR);
	/* Get the number of pages to erase from 1st page */
	uint32_t NbOfPages = GetPage(FLASH_USER_END_ADDR) - FirstPage + 1;
	/* Get the bank */
	uint32_t BankNumber = GetBank(FLASH_USER_START_ADDR);
	uint32_t PAGEError;
	/* Fill EraseInit structure*/
	FLASH_EraseInitTypeDef EraseInitStruct;
	EraseInitStruct.TypeErase   = FLASH_TYPEERASE_PAGES;
	EraseInitStruct.Banks       = BankNumber;
	EraseInitStruct.Page        = FirstPage;
	EraseInitStruct.NbPages     = NbOfPages;
	HAL_Error_Handler(HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError));
	address = FLASH_USER_START_ADDR;
	for (uint16_t varIndex = 0;varIndex < length;varIndex+=2)
	{
		uint64_t toWrite=EE_storage[varIndex];
		if (varIndex+1<length)
		{
			toWrite|= ((uint64_t)EE_storage[varIndex+1])<<32;
		}
		HAL_Error_Handler(HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, address, toWrite));
		address = address + 8;
	}
	HAL_FLASH_Lock();

}
开发者ID:molnard,项目名称:STM32L476_FT811,代码行数:41,代码来源:eeprom.c



注:本文中的HAL_FLASHEx_Erase函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ HAL_FLASH_Program函数代码示例发布时间:2022-05-30
下一篇:
C++ HAL_EXIT_CRITICAL_SECTION函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap