2323
2424static uint32_t GetSector (uint32_t Address );
2525static uint32_t GetSectorSize (uint32_t Sector );
26+ static uint32_t GetSectorBase (uint32_t SectorId );
2627
2728int32_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+
216240uint8_t flash_get_erase_value (const flash_t * obj )
217241{
218242 (void )obj ;
0 commit comments