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/10326/head
Vincent Veron 2019-03-14 15:40:20 +01:00 committed by Martin Kojtal
parent ff6c6b9523
commit 9a481bdca8
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 GetSector(uint32_t Address);
static uint32_t GetSectorSize(uint32_t Sector); static uint32_t GetSectorSize(uint32_t Sector);
static uint32_t GetSectorBase(uint32_t SectorId);
int32_t flash_init(flash_t *obj) int32_t flash_init(flash_t *obj)
{ {
@ -130,6 +131,9 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
status = -1; status = -1;
} }
SCB_CleanInvalidateDCache_by_Addr((uint32_t *)GetSectorBase(SectorId), GetSectorSize(SectorId));
SCB_InvalidateICache();
flash_lock(); flash_lock();
return status; return status;
@ -139,6 +143,8 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
uint32_t size) uint32_t size)
{ {
int32_t status = 0; int32_t status = 0;
uint32_t StartAddress = address;
uint32_t FullSize = size;
if ((address >= (FLASH_BASE + FLASH_SIZE)) || (address < FLASH_BASE)) { if ((address >= (FLASH_BASE + FLASH_SIZE)) || (address < FLASH_BASE)) {
return -1; 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(); flash_lock();
return status; return status;
@ -265,6 +274,23 @@ static uint32_t GetSectorSize(uint32_t Sector)
return sectorsize; 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) uint8_t flash_get_erase_value(const flash_t *obj)
{ {
(void)obj; (void)obj;