test_mpu.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include "unity.h"
  4. #include "esp_attr.h"
  5. #include "hal/mpu_hal.h"
  6. // TODO ESP32-C3 IDF-2375
  7. // LL still not implemented
  8. #if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C3)
  9. volatile static int RTC_NOINIT_ATTR access = 0;
  10. static void trigger_illegal_access(void)
  11. {
  12. access = 0;
  13. intptr_t addr = 0x80000000; // MPU region 4
  14. volatile int __attribute__((unused)) val = 0;
  15. // Marked as an illegal access region at startup in ESP32, ESP32S2.
  16. // Make accessible temporarily.
  17. mpu_hal_set_region_access(4, MPU_REGION_RW);
  18. val = *((int*) addr);
  19. ++access;
  20. TEST_ASSERT_EQUAL(1, access);
  21. printf("Sucessfully accessed location %p\r\n", (void*)addr);
  22. // Make access to region illegal again.
  23. mpu_hal_set_region_access(4, MPU_REGION_ILLEGAL);
  24. ++access;
  25. // Since access to region is illegal, this should fail (causing a reset), and the increment
  26. // to access count is not performed.
  27. val = *((int*) addr);
  28. ++access;
  29. }
  30. void check_access(void)
  31. {
  32. TEST_ASSERT_EQUAL(2, access);
  33. }
  34. TEST_CASE_MULTIPLE_STAGES("Can set illegal access regions", "[soc][mpu]",
  35. trigger_illegal_access,
  36. check_access);
  37. #endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C3)