2020-07-06 06:55 PM
Hi All.
I work with stm32f767igt for using flash.
The code below is erasing and writing flash.
I succeed writing the flash.
But when i try to delete the flash with
HAL_FLASHEx_Erase(&EraseInitStruct, &SECTORError) ;
and
FLASH_Erase_Sector(FLASH_SECTOR_10 ,FLASH_VOLTAGE_RANGE_3);
it didn't work properly.
So i can't update data in flash because flash doesn't deleted.
What am i doing wrong?
------------------------------------code ---------------------------------------------------------------------------------------
#define FLASH_BASE_ADDR ADDR_FLASH_SECTOR_10 /* Start @ of user Flash area */
#define FLASH_END_ADDR (ADDR_FLASH_SECTOR_11-1) /* End @ of user Flash area */
void flash_erase_write(void)
{
HAL_FLASH_Unlock();
// HAL_FLASH_OB_Unlock();
// HAL_FLASHEx_OBGetConfig(&OBInit);
// #if defined(DUAL_BANK)
// /* Turn on LED3 if FLASH is configured in Dual Bank mode */
// if((OBInit.USERConfig & OB_NDBANK_SINGLE_BANK) == OB_NDBANK_SINGLE_BANK)
// #else
// /* Turn on LED3 if FLASH is configured in Single Bank mode */
// if((OBInit.USERConfig & OB_NDBANK_SINGLE_BANK) == OB_NDBANK_DUAL_BANK)
// #endif
// {
// while(1);
// }
/* Get the 1st sector to erase */
FirstSector = GetSector(FLASH_BASE_ADDR);
/* Get the number of sector to erase from 1st sector*/
NbOfSectors = GetSector(FLASH_END_ADDR) - FirstSector + 1;
/* Fill EraseInit structure*/
EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;
EraseInitStruct.Sector = FirstSector;
EraseInitStruct.NbSectors = NbOfSectors;//NbOfSectors;
//FLASH_Erase_Sector(FLASH_SECTOR_10 ,FLASH_VOLTAGE_RANGE_3);
if (HAL_FLASHEx_Erase(&EraseInitStruct, &SECTORError) != HAL_OK)
{
printf("flash erase Error!!!\r\n");
while (1)
{
}
}
Address = FLASH_BASE_ADDR;
#define DATA_32 ((uint32_t)0x12345678)
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, Address, DATA_32) == HAL_OK)
{
Address = Address + 4;
}
}
2020-07-06 07:50 PM
Does HAL_FLASHEx_Erase return HAL_OK or some other value?
Double check your arguments in EraseInitStruct. You haven't included enough code to check them here.
Ensure your DUAL_BANK define matches up with what you have configured in the option bytes.
2020-07-06 09:02 PM
thank you for your quick reply.
Yes. the HAL_FLASHEx_Erase returns HAL_OK otherwise it stuck in while(1).
i didn't set any option realted with DUAL_BANK.
how do i check the option bytes?
2020-07-06 11:38 PM
Say hello to high-performance Cortex-M7 with cache and idiot made HAL (non-)high-level library. By default FLASH region is configured as write-through. Because of that after write operations no cache management is necessary, but after erase cache invalidation must be executed on the respective region. Typically you need to use SCB_InvalidateDCache_by_Addr().
2020-07-07 12:53 AM
SCB_InvalidateDCache_by_Addr((uint32_t*)0x080C0000, 131072);
/* flash delete */
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()'
*/
/* Infinite loop */
printf("flash erase Error!!!\r\n");
while (1)
{
}
}
I program like this, but it didn't work.
How do i use this function correctly?
2020-07-07 01:32 AM
What do you think the word "after" means?
2020-07-07 01:37 AM
Yes. . . I added after erase flash() ,,too
But , not working
Also i have tested on nucleo-144 stm32f767ZIboard, it works.
2020-07-07 02:04 AM
"Not working" is not a description of the problem and with that noone can help. Have you looked at flash contents after power cycle? Have you debugged HAL bloatware?
Oh, that bloatware even has multiple copies of the same function... Because of sector number 12, this could also be your problem.
The first one seems to be the latest one with additional code for sector numbers. @Imen DAHMEN, how can such a crap get through all ST's year long "tests"?
2020-07-07 02:37 AM
i'm not familiar with english
anyway, thank you for the link.
very helpful!
regard
2020-07-07 02:44 AM
That's not related to the language but the fact that you have not done your homework of debugging and describing the situation.