Files
esp-idf/components/esp_system
Guillaume Souchere 0ce211539a fix(esp_system): PSRAM stack crash in esp_restart_noos on RISC-V chips
On RISC-V chips with SPIRAM support (esp32c5, esp32c61, esp32h4, esp32p4,
esp32s31), esp_restart_noos() was disabling the cache while the current
stack pointer could still be in external RAM. Any stack access after cache
disable (function call, local variable spill) would then fault with
"Cache disabled but cached memory region accessed".

Xtensa chips (esp32, esp32s2, esp32s3) already had this guard via the
SET_STACK macro. Add the equivalent for RISC-V:

- Add rv_utils_set_sp() to riscv/rv_utils.h (plain "mv sp, %0" with a
  memory clobber; no window register management needed on RISC-V)
- In each affected system_internal.c, under
  CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM, check whether the current
  SP is in PSRAM and if so switch it to the top of internal BSS before
  any cache disable or writeback operation
- Fix xTaskCreateStaticPinnedToCore() stack size argument in the
  spiram_stack test (was passing bytes instead of word count)
- Mark the null-pointer write in func_do_exception() as volatile to
  prevent the compiler from optimizing it away
- Extend the [spiram_stack] tests to RISC-V by sharing fibonacci() and
  the task/finish helpers across architectures, guarding only the
  Xtensa-specific WINDOWBASE/WINDOWSTART prints
2026-04-28 11:08:55 +02:00
..

System Notes

Timekeeping

The following are the timekeeping mechanisms available and their differences:

  1. System time (esp_system_get_time)

Time with the origin at g_startup_time. The implementation is not handled by esp_system, but it does provide a default implementation using RTC timer. Currently, esp_timer provides system time, since the hardware timers are under the control of that component. However, no matter the underlying timer, the system time provider should maintain the definition of having the origin point at g_startup_time.

  1. esp_timer time (esp_timer_get_time)

This is the time read from an underlying hardware timer, controlled through config. Origin is at the point where the underlying timer starts counting.

  1. esp_libc time (gettimeofday)

Timekeeping function in standard library. Can be set (settimeofday) or moved forward/backward (adjtime); with the possibility of the changes being made persistent through config. Currently implemented in terms of system time, as the point of origin is fixed. If persistence is enabled, RTC time is also used in conjunction with system time.

  1. RTC time (esp_rtc_get_time_us)

Time read from RTC timer.

Brownout

on some boards, we name BOD1 as ana_bod, to unify the usage, using BOD1 in following passage.

BOD1 will be a little faster then BOD0, but BOD0 can be widely used(can reset rf, flash, or using interrupt, etc.) So, in IDF code, we use BOD1 in bootloader and BOD0 in the app.