Page 1 of 1

ESP32-C3 Cache "preload", "invalidate", "lock"?

Posted: Mon Oct 17, 2022 8:00 pm
by MicroController
Hello!

Section 3.3.3.3 Cache Operations of the ESP32-C3 tech. ref. states the "ESP32-C3 cache support the following operations: Invalidate [...} Preload [...] Lock/Unlock". However, I can find no information anywhere on how the cache can be controlled in this way.

gcc 8.4 doesn't seem to know how, either: at least

Code: Select all

__builtin_prefetch(...)
just compiles to nothing.

I would like to know how I can trigger a prefetch into cache on the C3 - it might be quite beneficial to, e.g., prefetch a lookup table from flash into cache before actually accessing it.

Is there any information/documentation available about those cache operations? Are they available via RISC-V "hint" instructions or via some other means/peripheral/register?

Kind regards,
MicroController

Re: ESP32-C3 Cache "preload", "invalidate", "lock"?

Posted: Wed Oct 19, 2022 3:36 am
by ESP_Sprite
There's no 'nice' way to do this as of now (possibly we should hook up that builtin function you mention) but the ROM has the Cache_Start_DCache_Preload function you could use for this. (Ignore the note that it can't be used in the SDK application, someone plastered that all over the cache function; this particular function seems safe.) There's invalidate/lock functions as well, but I do not know if they can be used in ESP-IDF or not.

Re: ESP32-C3 Cache "preload", "invalidate", "lock"?

Posted: Wed Oct 19, 2022 6:16 pm
by MicroController
Hello.

Thank you for your response. You have pointed me in the right direction now. (The C3's ROM doesn't seem to have a dedicated DCache_Preload function, but there's the ICache_Preload, which I assume should be equivalent for the C3's "unified cache".)

Diving deep into that rabbit hole, I finally found soc/extmem_reg.h which seems to be just what I need. (I'm a bit reluctant to call the ROM function, which in turn seems to call a couple of other functions to validate its arguments &c. - at least for very small prefetches of only one or a few cache lines.)

I also found an example use of the ROM function in components/esp_lcd.

Thank you again for getting back about this.

Regards,
Micro Controller