36
36
37
37
static uint32_t GetSector (uint32_t Address );
38
38
static uint32_t GetSectorSize (uint32_t Sector );
39
+ static uint32_t GetSectorBase (uint32_t SectorId );
39
40
40
41
int32_t flash_init (flash_t * obj )
41
42
{
@@ -130,6 +131,9 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
130
131
status = -1 ;
131
132
}
132
133
134
+ SCB_CleanInvalidateDCache_by_Addr ((uint32_t * )GetSectorBase (SectorId ), GetSectorSize (SectorId ));
135
+ SCB_InvalidateICache ();
136
+
133
137
flash_lock ();
134
138
135
139
return status ;
@@ -139,6 +143,8 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
139
143
uint32_t size )
140
144
{
141
145
int32_t status = 0 ;
146
+ uint32_t StartAddress = address ;
147
+ uint32_t FullSize = size ;
142
148
143
149
if ((address >= (FLASH_BASE + FLASH_SIZE )) || (address < FLASH_BASE )) {
144
150
return -1 ;
@@ -167,6 +173,9 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
167
173
}
168
174
}
169
175
176
+ SCB_CleanInvalidateDCache_by_Addr ((uint32_t * )StartAddress , FullSize );
177
+ SCB_InvalidateICache ();
178
+
170
179
flash_lock ();
171
180
172
181
return status ;
@@ -265,6 +274,23 @@ static uint32_t GetSectorSize(uint32_t Sector)
265
274
return sectorsize ;
266
275
}
267
276
277
+ /**
278
+ * @brief Gets sector base address
279
+ * @param SectorId
280
+ * @retval base address of a given sector
281
+ */
282
+ static uint32_t GetSectorBase (uint32_t SectorId )
283
+ {
284
+ int i = 0 ;
285
+ uint32_t address_sector = FLASH_BASE ;
286
+
287
+ for (i = 0 ;i < SectorId ;i ++ ){
288
+ address_sector += GetSectorSize (i );
289
+ }
290
+ return address_sector ;
291
+ }
292
+
293
+
268
294
uint8_t flash_get_erase_value (const flash_t * obj )
269
295
{
270
296
(void )obj ;
0 commit comments