本文整理汇总了C++中FLASH_EraseSector函数的典型用法代码示例。如果您正苦于以下问题:C++ FLASH_EraseSector函数的具体用法?C++ FLASH_EraseSector怎么用?C++ FLASH_EraseSector使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FLASH_EraseSector函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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 FLASH_Status EE_Format(void) {
FLASH_Status FlashStatus = FLASH_COMPLETE;
/* Erase Page0 */
FlashStatus = FLASH_EraseSector(PAGE0_ID, FLASH_VOLTAGE_RANGE );
/* If erase operation was failed, a Flash error code is returned */
if (FlashStatus != FLASH_COMPLETE) {
return FlashStatus;
}
/* Set Page0 as valid page: Write VALID_PAGE at Page0 base address */
FlashStatus = FLASH_ProgramHalfWord(PAGE0_BASE_ADDRESS, VALID_PAGE );
/* If program operation was failed, a Flash error code is returned */
if (FlashStatus != FLASH_COMPLETE) {
return FlashStatus;
}
/* Erase Page1 */
FlashStatus = FLASH_EraseSector(PAGE1_ID, FLASH_VOLTAGE_RANGE );
/* Return Page1 erase operation status */
return FlashStatus;
}
示例2: eraseHelper
FLASH_Status eraseHelper(uint32_t pageAddress)
{
#if defined(SERIES_STM32F37x) || defined(SERIES_STM32F30x)
return FLASH_ErasePage(pageAddress);
#else
if (pageAddress == PAGE0_BASE_ADDRESS)
return FLASH_EraseSector(PAGE0_ID, VOLTAGE_RANGE);
else if (pageAddress == PAGE1_BASE_ADDRESS)
return FLASH_EraseSector(PAGE1_ID, VOLTAGE_RANGE);
else
return FLASH_ERROR_PROGRAM;
#endif
}
示例3: bsp_Firmware_Erase
u8 bsp_Firmware_Erase(u8 APP_Select)
{
u8 status=0;
FLASH_Unlock(); //解锁
FLASH_DataCacheCmd(DISABLE);//FLASH擦除期间,必须禁止数据缓存
FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_OPERR|FLASH_FLAG_WRPERR| FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR);
if(APP_Select)
status=FLASH_EraseSector(FLASH_Sector_6 ,VoltageRange_3);//VCC=2.7~3.6V之间!!
else
status=FLASH_EraseSector(FLASH_Sector_5 ,VoltageRange_3);//VCC=2.7~3.6V之间!!
MCU_WriteStatus=status;
return MCU_WriteStatus;
}
示例4: Flash_EraseDataBuffer
void Flash_EraseDataBuffer()
{
FLASH_Unlock();
FLASH_ClearFlag( FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
// Erase Sectors
// 8-10 is data logger
FLASH_EraseSector(FLASH_Sector_8, VoltageRange_3);
FLASH_EraseSector(FLASH_Sector_9, VoltageRange_3);
FLASH_EraseSector(FLASH_Sector_10, VoltageRange_3);
Flash_ResetFlashAddress();
FLASH_Lock();
}
示例5: eep_erase
/**
* @brief Main program
* @param None
* @retval None
*/
ErrorStatus eep_erase( void )
{
ErrorStatus Err = SUCCESS;
/* Enable the flash control register access */
FLASH_Unlock();
/* Erase the user Flash area ************************************************/
/* area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR */
/* Clear pending flags (if any) */
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR);
/* Get the number of the start and end sectors */
uwStartSector = GetSector(FLASH_USER_START_ADDR);
/* Device voltage range supposed to be [2.7V to 3.6V], the operation will
be done by word */
if (FLASH_EraseSector(uwStartSector, VoltageRange_3) != FLASH_COMPLETE)
{
/* Error occurred while sector erase.
User can add here some code to deal with this error */
Err = ERROR;
}
FLASH_Lock();
return Err;
}
示例6: restoreCalibrateParamToFlash
static bool restoreCalibrateParamToFlash ( CalibrateParam* p )
{
int i ;
int n = sizeof(*p) / sizeof(uint32_t) ;
uint32_t Address = CALIBRATE_PARAM_ADDR ;
uint32_t *d = (uint32_t *) p ;
FLASH_Unlock();
FLASH_EraseSector(FLASH_Sector_5,VoltageRange_3);
for ( i=0;i<n;i++){
FLASH_ProgramWord( Address, *d );
d ++ ;
Address += 4;
}
FLASH_Lock();
// 检验是否正确写入
bool ret = true ;
d = (uint32_t *) p ;
uint32_t *d2 = (uint32_t*)CALIBRATE_PARAM_ADDR ;
for ( i=0; i<n; i++ )
{
if ( d[i] != d2[i] )
{
ret = false ;
break ;
}
}
return ret ;
}
示例7: write
bool write(uint32_t addr, uint16_t * data, const uint16_t data_len)
{
int sector;
/* Check bounds */
if ((addr >= (SECTOR11_START_ADDR + SECTOR_SIZE_128KB)) ||
(addr < SECTOR0_START_ADDR))
return false;
/* Need to compute sector to erase */
if (addr >= SECTOR5_START_ADDR)
sector = 5 + ((addr - SECTOR5_START_ADDR)/SECTOR_SIZE_128KB);
else if (addr >= SECTOR4_START_ADDR)
sector = 4;
else
sector = (addr - SECTOR0_START_ADDR)/SECTOR_SIZE_16KB;
/* Unlock flash */
FLASH_Unlock();
FLASH_EraseSector(sector * 0x08, VoltageRange_3);
/* Write data */
for (int i = 0; i < data_len; i += 2)
{
FLASH_ProgramHalfWord(addr, *data);
data++; addr += 2;
}
return true;
}
示例8: stm32_flash_erase
int stm32_flash_erase(uint32_t offset, uint16_t len)
{
uint32_t StartSector, EndSector;
uint32_t flash_user_start_addr, flash_user_end_addr;
uint32_t addr;
uint8_t i;
/* Get the number of the start and end sectors */
flash_user_start_addr = ADDR_FLASH_SECTOR_0 + offset;
flash_user_end_addr = flash_user_start_addr + len;
StartSector = GetSector(flash_user_start_addr);
EndSector = GetSector(flash_user_end_addr);
/* Erase sector */
for (i = StartSector; i <= EndSector; i += 8) {
/* Device voltage range supposed to be [2.7V to 3.6V], the operation will
be done by word */
if (FLASH_EraseSector(i, VoltageRange_3) != FLASH_COMPLETE) {
return -1;
}
}
return 0;
}
示例9: Flash_WriteParams
/**
* @brief ½«²ÎÊýдÈëFLASHÖÐ
*
* @param b:ÊÇ·ñÓÐLEDÌáʾ
* @retval none
*/
void Flash_WriteParams(uint8_t b)
{
FLASH_Status status;
uint32_t i;
FLASH_Unlock();
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGPERR | FLASH_FLAG_WRPERR);
// //if (FLASH_ErasePage(FLASH_WRITE_ADDR) == FLASH_COMPLETE)
if(FLASH_EraseSector(FLASH_WRITE_SECTOR, VoltageRange_3) == FLASH_COMPLETE)
{
for (i = 0; i < sizeof(config_t); i += 4)
{
status = FLASH_ProgramWord(FLASH_WRITE_ADDR + i, *(uint32_t *) ((char *) &cfg + i));
if (status != FLASH_COMPLETE)
{
System_FailureMode(1);
break; // TODO: fail
}
}
}
else
System_FailureMode(1);
FLASH_Lock();
Flash_Read();
}
示例10: FLASH_eraseSector
const DC3Error_t FLASH_eraseSector( const uint32_t sectorAddr )
{
DC3Error_t status = ERR_NONE;
/* These flags have to be cleared before any operation can be done on the
* flash memory */
// DBG_printf("Clearing flash flags. Status before clear: %x\n",FLASH->SR );
FLASH_ClearFlag(
FLASH_FLAG_PGSERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGAERR |
FLASH_FLAG_WRPERR | FLASH_FLAG_OPERR | FLASH_FLAG_EOP
);
// DBG_printf("Status after clear: %x\n",FLASH->SR );
WRN_printf("*** Erasing Flash sector addr 0x%08x ***\n", sectorAddr);
/*Look up the STM32 value of the sector given the sector address */
uint16_t sector = FLASH_sectorAddrToFlashSect( sectorAddr );
DBG_printf("Erasing sector (0x%04x) with base addr: 0x%08x...\n",
sector, sectorAddr);
/* This is a blocking operation but it's only for a single sector so should
* not take that long */
FLASH_Status flash_status = FLASH_EraseSector(sector, VoltageRange_3);
status = FLASH_statusToErrorCode( flash_status );
if (ERR_NONE != status) {
ERR_printf("Flash error %d ( error 0x%08x) while erasing sector "
"0x%04x (base addr: 0x%08x)\n",
flash_status, status, sector, sectorAddr);
DBG_printf("FLASH SR:%lx\n", FLASH->SR);
}
return( status );
}
示例11: flash_helper_erase_new_app
uint16_t flash_helper_erase_new_app(uint32_t new_app_size) {
FLASH_Unlock();
FLASH_ClearFlag(FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR |
FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
new_app_size += flash_addr[NEW_APP_BASE];
mcpwm_unlock();
mcpwm_release_motor();
utils_sys_lock_cnt();
RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, DISABLE);
for (int i = 0;i < NEW_APP_SECTORS;i++) {
if (new_app_size > flash_addr[NEW_APP_BASE + i]) {
uint16_t res = FLASH_EraseSector(flash_sector[NEW_APP_BASE + i], VoltageRange_3);
if (res != FLASH_COMPLETE) {
return res;
}
} else {
break;
}
}
RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);
utils_sys_unlock_cnt();
return FLASH_COMPLETE;
}
示例12: flash_write_word
bool flash_write_word(uint32_t add, uint32_t value)
{
/* Unlock the Flash to enable the flash control register access *************/
FLASH_Unlock();
/* Clear pending flags (if any) */
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR);
if (FLASH_EraseSector(FLASH_Sector_11, VoltageRange_4) != FLASH_COMPLETE)
{
goto fop_error;
}
//Program the user Flash area word by word
if (FLASH_ProgramWord(add, value) != FLASH_COMPLETE)
{
goto fop_error;
}
FLASH_Lock();
return true;
fop_error:
FLASH_Lock();
return false;
}
示例13: FLASH_If_Erase
/*******************************************************************************
* Function Name : FLASH_If_Erase
* Description : Erase sector
* Input : None
* Output : None
* Return : None
*******************************************************************************/
uint16_t FLASH_If_Erase(uint32_t Add)
{
/* Unlock the internal flash */
FLASH_Unlock();
FLASH_ClearFlags();
#if defined (STM32F2XX) || defined (STM32F4XX)
/* Disable sector write protection if it's already protected */
uint16_t OB_WRP_Sector = FLASH_SectorToWriteProtect(FLASH_INTERNAL, Add);
FLASH_WriteProtection_Disable(OB_WRP_Sector);
/* Check which sector has to be erased */
uint16_t FLASH_Sector = FLASH_SectorToErase(FLASH_INTERNAL, Add);
FLASH_Status status = FLASH_EraseSector(FLASH_Sector, VoltageRange_3);
#elif defined(STM32F10X_CL)
/* Call the standard Flash erase function */
FLASH_ErasePage(Add);
#endif /* STM32F2XX */
/* Lock the internal flash */
FLASH_Lock();
if (status != FLASH_COMPLETE) return MAL_FAIL;
return MAL_OK;
}
示例14: flash_helper_erase_new_app
uint16_t flash_helper_erase_new_app(uint32_t new_app_size) {
FLASH_Unlock();
FLASH_ClearFlag(FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR |
FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
new_app_size += flash_addr[NEW_APP_BASE];
mc_interface_unlock();
mc_interface_release_motor();
utils_sys_lock_cnt();
timeout_configure_IWDT_slowest();
for (int i = 0;i < NEW_APP_SECTORS;i++) {
if (new_app_size > flash_addr[NEW_APP_BASE + i]) {
uint16_t res = FLASH_EraseSector(flash_sector[NEW_APP_BASE + i], VoltageRange_3);
if (res != FLASH_COMPLETE) {
FLASH_Lock();
return res;
}
} else {
break;
}
}
FLASH_Lock();
timeout_configure_IWDT();
utils_sys_unlock_cnt();
return FLASH_COMPLETE;
}
示例15: writeFlash
void writeFlash(u8 address_num,u32 data) //address_num should start from 0 up to 255
{
const u8 data_count=255;
u32 flash_data[data_count];
for (u8 i = 0; i < data_count; ++i) {
flash_data[i] = readFlash(i);
}
flash_data[address_num] = data;
FLASH_Unlock();// you need to unlcok flash first
/* Clear All pending flags */
FLASH_ClearFlag( FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
//you need to erase entire sector before write anything
FLASH_EraseSector(FLASH_Sector_11, VoltageRange_3);
//VoltageRange_3 ((uint8_t)0x02) /*!<Device operating range: 2.7V to 3.6V */
for (u8 i = 0; i < data_count; ++i) { //write back the whole sector memory
FLASH_ProgramWord((u32)(startAddress + i * 4), flash_data[i]);
}
FLASH_Lock();//lock flash at the end
}