Fix for the H747 flash driver / cache cleaning

This copies the approach of the STM32F7 flash driver submitted via
PR https://github.com/ARMmbed/mbed-os/pull/10248

With this change the board finally passes all of the device key
tests 10/10 times correctly.
pull/11619/head
Janne Kiiskila 2019-10-30 14:56:29 +02:00
parent 3ab36cb934
commit a48500183e
1 changed files with 24 additions and 0 deletions

View File

@ -23,6 +23,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)
{ {
@ -91,6 +92,9 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
} }
} }
SCB_CleanInvalidateDCache_by_Addr((uint32_t *)GetSectorBase(SectorId), GetSectorSize(SectorId));
SCB_InvalidateICache();
HAL_FLASH_Lock(); HAL_FLASH_Lock();
#if defined(DUAL_CORE) #if defined(DUAL_CORE)
LL_HSEM_ReleaseLock(HSEM, CFG_HW_FLASH_SEMID, HSEM_CR_COREID_CURRENT); LL_HSEM_ReleaseLock(HSEM, CFG_HW_FLASH_SEMID, HSEM_CR_COREID_CURRENT);
@ -103,6 +107,7 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
{ {
uint32_t StartAddress = 0; uint32_t StartAddress = 0;
int32_t status = 0; int32_t status = 0;
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;
@ -135,6 +140,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();
HAL_FLASH_Lock(); HAL_FLASH_Lock();
#if defined(DUAL_CORE) #if defined(DUAL_CORE)
LL_HSEM_ReleaseLock(HSEM, CFG_HW_FLASH_SEMID, HSEM_CR_COREID_CURRENT); LL_HSEM_ReleaseLock(HSEM, CFG_HW_FLASH_SEMID, HSEM_CR_COREID_CURRENT);
@ -213,6 +221,22 @@ static uint32_t GetSectorSize(uint32_t Sector)
return (uint32_t)(128 * 1024); // 128 KB return (uint32_t)(128 * 1024); // 128 KB
} }
/**
* @brief Gets sector base address
* @param SectorId
* @retval base address of a given sector
*/
static uint32_t GetSectorBase(uint32_t SectorId)
{
uint32_t 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;