44
44
#define ESP32P4_CACHE_MAP_L2_CACHE BIT(5)
45
45
#define ESP32P4_CACHE_SYNC_INVALIDATE BIT(0)
46
46
#define ESP32P4_CACHE_SYNC_WRITEBACK BIT(2)
47
+ #define ESP32P4_CACHE_SYNC_FLUSH BIT(3) /* Writeback + invalidate */
47
48
#define ESP32P4_CACHE_SYNC_DONE BIT(4)
48
49
49
50
#define ESP32P4_CACHE_L1_LINE_SIZE 64
@@ -296,7 +297,8 @@ static int esp32p4_read_memory(struct target *target, target_addr_t address,
296
297
}
297
298
298
299
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 ,
300
302
ESP32P4_CACHE_SYNC_WRITEBACK );
301
303
if (res != ERROR_OK )
302
304
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,
308
310
static int esp32p4_write_memory (struct target * target , target_addr_t address ,
309
311
uint32_t size , uint32_t count , const uint8_t * buffer )
310
312
{
311
- bool cache_invalidate = false;
312
-
313
313
// TODO: check all valid/invalid memory regions
314
314
315
315
if (ESP32P4_ADDRESS_IS_L2MEM (address )) {
316
316
/* 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 ,
318
319
ESP32P4_CACHE_SYNC_WRITEBACK );
319
320
if (res != ERROR_OK )
320
321
LOG_TARGET_WARNING (target , "Cache writeback failed! Write main memory anyway." );
321
- cache_invalidate = true;
322
322
}
323
323
324
324
int res = esp_riscv_write_memory (target , address , size , count , buffer );
325
325
326
- if (cache_invalidate &&
326
+ if (ESP32P4_ADDRESS_IS_L2MEM ( address ) &&
327
327
esp32p4_sync_l1_cache (target , address , size * count , ESP32P4_CACHE_MAP_ALL ,
328
328
ESP32P4_CACHE_SYNC_INVALIDATE ) != ERROR_OK )
329
329
LOG_TARGET_WARNING (target , "Cache invalidate failed!" );
0 commit comments