summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/esp32/mphalport.c16
-rw-r--r--ports/esp32/mphalport.h8
2 files changed, 22 insertions, 2 deletions
diff --git a/ports/esp32/mphalport.c b/ports/esp32/mphalport.c
index d7003a143..538b3e405 100644
--- a/ports/esp32/mphalport.c
+++ b/ports/esp32/mphalport.c
@@ -53,7 +53,12 @@ STATIC uint8_t stdin_ringbuf_array[260];
ringbuf_t stdin_ringbuf = {stdin_ringbuf_array, sizeof(stdin_ringbuf_array), 0, 0};
// Check the ESP-IDF error code and raise an OSError if it's not ESP_OK.
-void check_esp_err(esp_err_t code) {
+#if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_NORMAL
+void check_esp_err_(esp_err_t code)
+#else
+void check_esp_err_(esp_err_t code, const char *func, const int line, const char *file)
+#endif
+{
if (code != ESP_OK) {
// map esp-idf error code to posix error code
uint32_t pcode = -code;
@@ -75,7 +80,16 @@ void check_esp_err(esp_err_t code) {
return;
}
o_str->base.type = &mp_type_str;
+ #if MICROPY_ERROR_REPORTING > MICROPY_ERROR_REPORTING_NORMAL
+ char err_msg[64];
+ esp_err_to_name_r(code, err_msg, sizeof(err_msg));
+ vstr_t vstr;
+ vstr_init(&vstr, 80);
+ vstr_printf(&vstr, "0x%04X %s in function '%s' at line %d in file '%s'", code, err_msg, func, line, file);
+ o_str->data = (const byte *)vstr_null_terminated_str(&vstr);
+ #else
o_str->data = (const byte *)esp_err_to_name(code); // esp_err_to_name ret's ptr to const str
+ #endif
o_str->len = strlen((char *)o_str->data);
o_str->hash = qstr_compute_hash(o_str->data, o_str->len);
// raise
diff --git a/ports/esp32/mphalport.h b/ports/esp32/mphalport.h
index 566d6609f..5e54c24bf 100644
--- a/ports/esp32/mphalport.h
+++ b/ports/esp32/mphalport.h
@@ -55,7 +55,13 @@ extern TaskHandle_t mp_main_task_handle;
extern ringbuf_t stdin_ringbuf;
// Check the ESP-IDF error code and raise an OSError if it's not ESP_OK.
-void check_esp_err(esp_err_t code);
+#if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_NORMAL
+#define check_esp_err(code) check_esp_err_(code)
+void check_esp_err_(esp_err_t code);
+#else
+#define check_esp_err(code) check_esp_err_(code, __FUNCTION__, __LINE__, __FILE__)
+void check_esp_err_(esp_err_t code, const char *func, const int line, const char *file);
+#endif
uint32_t mp_hal_ticks_us(void);
__attribute__((always_inline)) static inline uint32_t mp_hal_ticks_cpu(void) {