esp_debug_helpers.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #ifdef __cplusplus
  3. extern "C" {
  4. #endif
  5. #ifndef __ASSEMBLER__
  6. #include <stdbool.h>
  7. #include "esp_err.h"
  8. #define ESP_WATCHPOINT_LOAD 0x40000000
  9. #define ESP_WATCHPOINT_STORE 0x80000000
  10. #define ESP_WATCHPOINT_ACCESS 0xC0000000
  11. /**
  12. * @brief If an OCD is connected over JTAG. set breakpoint 0 to the given function
  13. * address. Do nothing otherwise.
  14. * @param fn Pointer to the target breakpoint position
  15. */
  16. void esp_set_breakpoint_if_jtag(void *fn);
  17. /**
  18. * @brief Set a watchpoint to break/panic when a certain memory range is accessed.
  19. *
  20. * @param no Watchpoint number. On the ESP32, this can be 0 or 1.
  21. * @param adr Base address to watch
  22. * @param size Size of the region, starting at the base address, to watch. Must
  23. * be one of 2^n, with n in [0..6].
  24. * @param flags One of ESP_WATCHPOINT_* flags
  25. *
  26. * @return ESP_ERR_INVALID_ARG on invalid arg, ESP_OK otherwise
  27. *
  28. * @warning The ESP32 watchpoint hardware watches a region of bytes by effectively
  29. * masking away the lower n bits for a region with size 2^n. If adr does
  30. * not have zero for these lower n bits, you may not be watching the
  31. * region you intended.
  32. */
  33. esp_err_t esp_set_watchpoint(int no, void *adr, int size, int flags);
  34. /**
  35. * @brief Clear a watchpoint
  36. *
  37. * @param no Watchpoint to clear
  38. *
  39. */
  40. void esp_clear_watchpoint(int no);
  41. /**
  42. * @brief Checks stack pointer
  43. */
  44. static inline bool esp_stack_ptr_is_sane(uint32_t sp)
  45. {
  46. return !(sp < 0x3ffae010UL || sp > 0x3ffffff0UL || ((sp & 0xf) != 0));
  47. }
  48. #endif
  49. #ifdef __cplusplus
  50. }
  51. #endif