Skip to content

Commit a485001

Browse files
author
Janne Kiiskila
committed
Fix for the H747 flash driver / cache cleaning
This copies the approach of the STM32F7 flash driver submitted via PR #10248 With this change the board finally passes all of the device key tests 10/10 times correctly.
1 parent 3ab36cb commit a485001

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

targets/TARGET_STM/TARGET_STM32H7/flash_api.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
static uint32_t GetSector(uint32_t Address);
2525
static uint32_t GetSectorSize(uint32_t Sector);
26+
static uint32_t GetSectorBase(uint32_t SectorId);
2627

2728
int32_t flash_init(flash_t *obj)
2829
{
@@ -91,6 +92,9 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
9192
}
9293
}
9394

95+
SCB_CleanInvalidateDCache_by_Addr((uint32_t *)GetSectorBase(SectorId), GetSectorSize(SectorId));
96+
SCB_InvalidateICache();
97+
9498
HAL_FLASH_Lock();
9599
#if defined(DUAL_CORE)
96100
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,
103107
{
104108
uint32_t StartAddress = 0;
105109
int32_t status = 0;
110+
uint32_t FullSize = size;
106111

107112
if ((address >= (FLASH_BASE + FLASH_SIZE)) || (address < FLASH_BASE)) {
108113
return -1;
@@ -135,6 +140,9 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
135140
}
136141
}
137142

143+
SCB_CleanInvalidateDCache_by_Addr((uint32_t *)StartAddress, FullSize);
144+
SCB_InvalidateICache();
145+
138146
HAL_FLASH_Lock();
139147
#if defined(DUAL_CORE)
140148
LL_HSEM_ReleaseLock(HSEM, CFG_HW_FLASH_SEMID, HSEM_CR_COREID_CURRENT);
@@ -213,6 +221,22 @@ static uint32_t GetSectorSize(uint32_t Sector)
213221
return (uint32_t)(128 * 1024); // 128 KB
214222
}
215223

224+
/**
225+
* @brief Gets sector base address
226+
* @param SectorId
227+
* @retval base address of a given sector
228+
*/
229+
static uint32_t GetSectorBase(uint32_t SectorId)
230+
{
231+
uint32_t i = 0;
232+
uint32_t address_sector = FLASH_BASE;
233+
234+
for (i = 0; i < SectorId; i++) {
235+
address_sector += GetSectorSize(i);
236+
}
237+
return address_sector;
238+
}
239+
216240
uint8_t flash_get_erase_value(const flash_t *obj)
217241
{
218242
(void)obj;

0 commit comments

Comments
 (0)