3636
3737static uint32_t GetSector (uint32_t Address );
3838static uint32_t GetSectorSize (uint32_t Sector );
39+ static uint32_t GetSectorBase (uint32_t SectorId );
3940
4041int32_t flash_init (flash_t * obj )
4142{
@@ -130,6 +131,9 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
130131 status = -1 ;
131132 }
132133
134+ SCB_CleanInvalidateDCache_by_Addr ((uint32_t * )GetSectorBase (SectorId ), GetSectorSize (SectorId ));
135+ SCB_InvalidateICache ();
136+
133137 flash_lock ();
134138
135139 return status ;
@@ -139,6 +143,8 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
139143 uint32_t size )
140144{
141145 int32_t status = 0 ;
146+ uint32_t StartAddress = address ;
147+ uint32_t FullSize = size ;
142148
143149 if ((address >= (FLASH_BASE + FLASH_SIZE )) || (address < FLASH_BASE )) {
144150 return -1 ;
@@ -167,6 +173,9 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
167173 }
168174 }
169175
176+ SCB_CleanInvalidateDCache_by_Addr ((uint32_t * )StartAddress , FullSize );
177+ SCB_InvalidateICache ();
178+
170179 flash_lock ();
171180
172181 return status ;
@@ -265,6 +274,23 @@ static uint32_t GetSectorSize(uint32_t Sector)
265274 return sectorsize ;
266275}
267276
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+
268294uint8_t flash_get_erase_value (const flash_t * obj )
269295{
270296 (void )obj ;
0 commit comments