diff --git a/components/soc/src/esp32/include/hal/mpu_ll.h b/components/soc/src/esp32/include/hal/mpu_ll.h index b11e11a7d8..bb849f66a9 100644 --- a/components/soc/src/esp32/include/hal/mpu_ll.h +++ b/components/soc/src/esp32/include/hal/mpu_ll.h @@ -22,7 +22,7 @@ extern "C" { #endif -static inline uint32_t cpu_ll_id_to_addr(int id) +static inline uint32_t mpu_ll_id_to_addr(int id) { // vpn - id // 0x00000000 = 0 diff --git a/components/soc/src/esp32s2/include/hal/mpu_ll.h b/components/soc/src/esp32s2/include/hal/mpu_ll.h index b11e11a7d8..bb849f66a9 100644 --- a/components/soc/src/esp32s2/include/hal/mpu_ll.h +++ b/components/soc/src/esp32s2/include/hal/mpu_ll.h @@ -22,7 +22,7 @@ extern "C" { #endif -static inline uint32_t cpu_ll_id_to_addr(int id) +static inline uint32_t mpu_ll_id_to_addr(int id) { // vpn - id // 0x00000000 = 0 diff --git a/components/soc/src/hal/mpu_hal.c b/components/soc/src/hal/mpu_hal.c index b2cae6b76c..8b89f5d597 100644 --- a/components/soc/src/hal/mpu_hal.c +++ b/components/soc/src/hal/mpu_hal.c @@ -25,7 +25,7 @@ void mpu_hal_set_region_access(int id, mpu_access_t access) { - uint32_t addr = cpu_ll_id_to_addr(id); + uint32_t addr = mpu_ll_id_to_addr(id); switch (access) { @@ -48,6 +48,9 @@ void mpu_hal_set_region_access(int id, mpu_access_t access) case MPU_REGION_RWX: mpu_ll_set_region_rwx(addr); break; + case MPU_REGION_ILLEGAL: + mpu_ll_set_region_illegal(addr); + break; default: break; } diff --git a/components/soc/test/test_mpu.c b/components/soc/test/test_mpu.c new file mode 100644 index 0000000000..579cd0c703 --- /dev/null +++ b/components/soc/test/test_mpu.c @@ -0,0 +1,36 @@ +#include +#include +#include "unity.h" + +#include "esp_attr.h" + +#include "hal/mpu_hal.h" + +volatile static int RTC_NOINIT_ATTR access = 0; + +static void trigger_illegal_access(void) +{ + access = 0; + intptr_t addr = 0x60000000; + volatile int __attribute__((unused)) val = 0; + + val = *((int*) addr); + ++access; + TEST_ASSERT_EQUAL(1, access); + printf("Sucessfully accessed location %p\r\n", (void*)addr); + + mpu_hal_set_region_access(3, MPU_REGION_ILLEGAL); // 0x60000000 + ++access; + + val = *((int*) addr); + ++access; +} + +void check_access(void) +{ + TEST_ASSERT_EQUAL(2, access); +} + +TEST_CASE_MULTIPLE_STAGES("Can set illegal access regions", "[soc][mpu]", + trigger_illegal_access, + check_access); \ No newline at end of file