23
23
24
24
static uint32_t GetSector (uint32_t Address );
25
25
static uint32_t GetSectorSize (uint32_t Sector );
26
+ static uint32_t GetSectorBase (uint32_t SectorId );
26
27
27
28
int32_t flash_init (flash_t * obj )
28
29
{
@@ -91,6 +92,9 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
91
92
}
92
93
}
93
94
95
+ SCB_CleanInvalidateDCache_by_Addr ((uint32_t * )GetSectorBase (SectorId ), GetSectorSize (SectorId ));
96
+ SCB_InvalidateICache ();
97
+
94
98
HAL_FLASH_Lock ();
95
99
#if defined(DUAL_CORE )
96
100
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,
103
107
{
104
108
uint32_t StartAddress = 0 ;
105
109
int32_t status = 0 ;
110
+ uint32_t FullSize = size ;
106
111
107
112
if ((address >= (FLASH_BASE + FLASH_SIZE )) || (address < FLASH_BASE )) {
108
113
return -1 ;
@@ -135,6 +140,9 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
135
140
}
136
141
}
137
142
143
+ SCB_CleanInvalidateDCache_by_Addr ((uint32_t * )StartAddress , FullSize );
144
+ SCB_InvalidateICache ();
145
+
138
146
HAL_FLASH_Lock ();
139
147
#if defined(DUAL_CORE )
140
148
LL_HSEM_ReleaseLock (HSEM , CFG_HW_FLASH_SEMID , HSEM_CR_COREID_CURRENT );
@@ -213,6 +221,22 @@ static uint32_t GetSectorSize(uint32_t Sector)
213
221
return (uint32_t )(128 * 1024 ); // 128 KB
214
222
}
215
223
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
+
216
240
uint8_t flash_get_erase_value (const flash_t * obj )
217
241
{
218
242
(void )obj ;
0 commit comments