From 8e66081ae3f71c413c3aa1f080290224e21207f4 Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Tue, 24 Mar 2026 17:34:26 +0800 Subject: [PATCH] fix(esp_hw_support): guard CSR_PRV_MODE usage in esp_cpu_get_curr_privilege_level CSR_PRV_MODE is only defined for a subset of RISC-V targets. Targets that lack it (e.g. esp32h21, esp32h4, esp32s31) caused an assembler error. Fall back to returning -1 (unsupported) when the CSR is not defined. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- components/esp_hw_support/include/esp_cpu.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/esp_hw_support/include/esp_cpu.h b/components/esp_hw_support/include/esp_cpu.h index 96614c045b..de346b589a 100644 --- a/components/esp_hw_support/include/esp_cpu.h +++ b/components/esp_hw_support/include/esp_cpu.h @@ -154,8 +154,10 @@ FORCE_INLINE_ATTR __attribute__((always_inline)) int esp_cpu_get_curr_privilege_ #else #if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C2 return PRV_M; -#else +#elif defined(CSR_PRV_MODE) return RV_READ_CSR(CSR_PRV_MODE); +#else + return -1; #endif #endif }