Merge pull request #10248 from VVESTM/issue_9934

TARGET_STM32F7: Refresh cache when erasing or programming flash
pull/10215/head
Cruz Monrreal 2019-04-01 17:04:26 -05:00 committed by GitHub
commit cdc2579b7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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;