TARGET_STM32F7: Refresh cache when erasing or programming flash

The cache must be refreshed when we erase or program flash memory.
It fix 2 issues :
    Fix #9934
    Fix #6380

This solution was initially proposed in #6380.

Signed-off-by: Vincent Veron <vincent.veron@st.com>
pull/10248/head
Vincent Veron 2019-03-14 15:40:20 +01:00
parent 1549c5c425
commit 5765c4d0e0
1 changed files with 26 additions and 0 deletions

View File

@ -36,6 +36,7 @@
static uint32_t GetSector(uint32_t Address);
static uint32_t GetSectorSize(uint32_t Sector);
static uint32_t GetSectorBase(uint32_t SectorId);
int32_t flash_init(flash_t *obj)
{
@ -130,6 +131,9 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
status = -1;
}
SCB_CleanInvalidateDCache_by_Addr((uint32_t *)GetSectorBase(SectorId), GetSectorSize(SectorId));
SCB_InvalidateICache();
flash_lock();
return status;
@ -139,6 +143,8 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
uint32_t size)
{
int32_t status = 0;
uint32_t StartAddress = address;
uint32_t FullSize = size;
if ((address >= (FLASH_BASE + FLASH_SIZE)) || (address < FLASH_BASE)) {
return -1;
@ -167,6 +173,9 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
}
}
SCB_CleanInvalidateDCache_by_Addr((uint32_t *)StartAddress, FullSize);
SCB_InvalidateICache();
flash_lock();
return status;
@ -265,6 +274,23 @@ static uint32_t GetSectorSize(uint32_t Sector)
return sectorsize;
}
/**
* @brief Gets sector base address
* @param SectorId
* @retval base address of a given sector
*/
static uint32_t GetSectorBase(uint32_t SectorId)
{
int i = 0;
uint32_t address_sector = FLASH_BASE;
for(i=0;i<SectorId;i++){
address_sector += GetSectorSize(i);
}
return address_sector;
}
uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;