cancel
Showing results for 
Search instead for 
Did you mean: 

[STM32F746BG] Accessing internal Flash from code

konrad2399
Associate II
Posted on April 24, 2016 at 18:54

Hi!

I'm programming STM32F746BG using IAR 7.40 and J-Link debugger. I have a problem when trying to use internal flash to store some data. To be more specific when I try to erase sector 7. Here's my code:


HAL_FLASH_Unlock();

__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_ERSERR); 

FirstSector = 7;

NbOfSectors = 1;

EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;

EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;

EraseInitStruct.Sector = 7;

EraseInitStruct.NbSectors = 1;

if
(HAL_FLASHEx_Erase(&EraseInitStruct, &SECTORError) != HAL_OK)

{

while
(1)

{

HAL_Delay(100);

}

}

Function (line 09) returns HAL_OK after short time (but noticeable, maybe few hunderd ms), but the memory is not erased. Sector 7 should start at address0x080A0000, and there are still old data there. However if I erase memory via J-Flash, it indeed contains only 0xFF and I can write new data which is stored. I'll appreciate any help. Best regards, Konrad #flash #stm32f7 #erase
2 REPLIES 2
konrad2399
Associate II
Posted on April 24, 2016 at 19:50

Little update.

Moving ROM to sector 2 (0x08010000) and data to sector 1 (0x08008000) is kinda a workaround, this works.

You should not use sector 0 to store data, because (in my case) IAR startup code sits at 0x08000000.

However trying to erase sectors 6 or 7 (memory from 0x08070000) still ends with nothing.

AndyJT
Associate III
Posted on April 25, 2016 at 19:11

Think you are looking at the wrong memory addresses.

The STM32F746 is this:

#define ADDR_FLASH_SECTOR_6     ((uint32_t)0x08080000) /* Base @ of Sector 6, 256 Kbytes */

#define ADDR_FLASH_SECTOR_7     ((uint32_t)0x080C0000) /* Base @ of Sector 7, 256 Kbytes */