4444#define ESP32P4_CACHE_MAP_L2_CACHE BIT(5)
4545#define ESP32P4_CACHE_SYNC_INVALIDATE BIT(0)
4646#define ESP32P4_CACHE_SYNC_WRITEBACK BIT(2)
47+ #define ESP32P4_CACHE_SYNC_FLUSH BIT(3) /* Writeback + invalidate */
4748#define ESP32P4_CACHE_SYNC_DONE BIT(4)
4849
4950#define ESP32P4_CACHE_L1_LINE_SIZE 64
@@ -296,7 +297,8 @@ static int esp32p4_read_memory(struct target *target, target_addr_t address,
296297 }
297298
298299 if (ESP32P4_ADDRESS_IS_L2MEM (address )) {
299- int res = esp32p4_sync_l1_cache (target , address , size * count , ESP32P4_CACHE_MAP_ALL ,
300+ /* Write-back is (for dcache and l2 cache only) */
301+ int res = esp32p4_sync_l1_cache (target , address , size * count , ESP32P4_CACHE_MAP_L1_DCACHE ,
300302 ESP32P4_CACHE_SYNC_WRITEBACK );
301303 if (res != ERROR_OK )
302304 LOG_TARGET_WARNING (target , "Cache writeback failed! Read main memory anyway." );
@@ -308,22 +310,20 @@ static int esp32p4_read_memory(struct target *target, target_addr_t address,
308310static int esp32p4_write_memory (struct target * target , target_addr_t address ,
309311 uint32_t size , uint32_t count , const uint8_t * buffer )
310312{
311- bool cache_invalidate = false;
312-
313313 // TODO: check all valid/invalid memory regions
314314
315315 if (ESP32P4_ADDRESS_IS_L2MEM (address )) {
316316 /* write to main memory and invalidate cache */
317- int res = esp32p4_sync_l1_cache (target , address , size * count , ESP32P4_CACHE_MAP_ALL ,
317+ /* Write-back is (for dcache and l2 cache only) */
318+ int res = esp32p4_sync_l1_cache (target , address , size * count , ESP32P4_CACHE_MAP_L1_DCACHE ,
318319 ESP32P4_CACHE_SYNC_WRITEBACK );
319320 if (res != ERROR_OK )
320321 LOG_TARGET_WARNING (target , "Cache writeback failed! Write main memory anyway." );
321- cache_invalidate = true;
322322 }
323323
324324 int res = esp_riscv_write_memory (target , address , size , count , buffer );
325325
326- if (cache_invalidate &&
326+ if (ESP32P4_ADDRESS_IS_L2MEM ( address ) &&
327327 esp32p4_sync_l1_cache (target , address , size * count , ESP32P4_CACHE_MAP_ALL ,
328328 ESP32P4_CACHE_SYNC_INVALIDATE ) != ERROR_OK )
329329 LOG_TARGET_WARNING (target , "Cache invalidate failed!" );
0 commit comments