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

MicroController
Posts: 1377
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

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

Postby MicroController » Mon Oct 17, 2022 8:00 pm

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

ESP_Sprite
Posts: 9293
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_Sprite » Wed Oct 19, 2022 3:36 am

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.

MicroController
Posts: 1377
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

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

Postby MicroController » Wed Oct 19, 2022 6:16 pm

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

Who is online

Users browsing this forum: No registered users and 8 guests