Skip to content

Commit 7864cd5

Browse files
committed
esp32/mphalport: Add FUNC info to check_esp_err().
esp32/mphalport: Add __FUNCTION__, __LINE__, __FILE__ info to check_esp_err(). Signed-off-by: Ihor Nehrutsa <IhorNehrutsa@gmail.com>
1 parent 3637252 commit 7864cd5

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

ports/esp32/mphalport.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "freertos/task.h"
3535
#include "esp_timer.h"
3636

37+
#include "py/mpprint.h"
3738
#include "py/obj.h"
3839
#include "py/objstr.h"
3940
#include "py/stream.h"
@@ -53,7 +54,11 @@ STATIC uint8_t stdin_ringbuf_array[260];
5354
ringbuf_t stdin_ringbuf = {stdin_ringbuf_array, sizeof(stdin_ringbuf_array), 0, 0};
5455

5556
// Check the ESP-IDF error code and raise an OSError if it's not ESP_OK.
56-
void check_esp_err(esp_err_t code) {
57+
#if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_NORMAL
58+
void check_esp_err_(esp_err_t code) {
59+
#else
60+
void check_esp_err_(esp_err_t code, const char *func, const int line, const char *file) {
61+
#endif
5762
if (code != ESP_OK) {
5863
// map esp-idf error code to posix error code
5964
uint32_t pcode = -code;
@@ -78,6 +83,9 @@ void check_esp_err(esp_err_t code) {
7883
o_str->data = (const byte *)esp_err_to_name(code); // esp_err_to_name ret's ptr to const str
7984
o_str->len = strlen((char *)o_str->data);
8085
o_str->hash = qstr_compute_hash(o_str->data, o_str->len);
86+
#if MICROPY_ERROR_REPORTING > MICROPY_ERROR_REPORTING_NORMAL
87+
mp_printf(MP_PYTHON_PRINTER, "Exception in function '%s' at line %d in file '%s'\n", func, line, file);
88+
#endif
8189
// raise
8290
mp_obj_t args[2] = { MP_OBJ_NEW_SMALL_INT(pcode), MP_OBJ_FROM_PTR(o_str)};
8391
nlr_raise(mp_obj_exception_make_new(&mp_type_OSError, 2, 0, args));

ports/esp32/mphalport.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ extern TaskHandle_t mp_main_task_handle;
5555
extern ringbuf_t stdin_ringbuf;
5656

5757
// Check the ESP-IDF error code and raise an OSError if it's not ESP_OK.
58-
void check_esp_err(esp_err_t code);
58+
#if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_NORMAL
59+
#define check_esp_err(code) check_esp_err_(code)
60+
void check_esp_err_(esp_err_t code);
61+
#else
62+
#define check_esp_err(code) check_esp_err_(code, __FUNCTION__, __LINE__, __FILE__)
63+
void check_esp_err_(esp_err_t code, const char *func, const int line, const char *file);
64+
#endif
5965

6066
uint32_t mp_hal_ticks_us(void);
6167
__attribute__((always_inline)) static inline uint32_t mp_hal_ticks_cpu(void) {

0 commit comments

Comments
 (0)