Skip to content

Commit 8de7ffc

Browse files
committed
esp32/mphalport: Add __FUNCTION__, __LINE__, __FILE__ info to check_esp_err().
1 parent 36ae5d3 commit 8de7ffc

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

ports/esp32/mphalport.c

100644100755
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,17 @@
4646
#include "usb_serial_jtag.h"
4747
#include "uart.h"
4848

49+
#include "py/mpprint.h"
50+
//#define DBG(...)
51+
#define DBG(...) mp_printf(MP_PYTHON_PRINTER, __VA_ARGS__); mp_printf(&mp_plat_print, "\n");
52+
4953
TaskHandle_t mp_main_task_handle;
5054

5155
STATIC uint8_t stdin_ringbuf_array[260];
5256
ringbuf_t stdin_ringbuf = {stdin_ringbuf_array, sizeof(stdin_ringbuf_array), 0, 0};
5357

5458
// Check the ESP-IDF error code and raise an OSError if it's not ESP_OK.
55-
void check_esp_err(esp_err_t code) {
59+
void check_esp_err_(esp_err_t code, const char* func, const int line, const char *file) {
5660
if (code != ESP_OK) {
5761
// map esp-idf error code to posix error code
5862
uint32_t pcode = -code;
@@ -78,8 +82,14 @@ void check_esp_err(esp_err_t code) {
7882
o_str->len = strlen((char *)o_str->data);
7983
o_str->hash = qstr_compute_hash(o_str->data, o_str->len);
8084
// raise
81-
mp_obj_t args[2] = { MP_OBJ_NEW_SMALL_INT(pcode), MP_OBJ_FROM_PTR(o_str)};
85+
#if 0
86+
mp_obj_t args[2] = { MP_OBJ_NEW_SMALL_INT(pcode), MP_OBJ_FROM_PTR(o_str) };
8287
nlr_raise(mp_obj_exception_make_new(&mp_type_OSError, 2, 0, args));
88+
#else
89+
DBG("Exception from function '%s' at line %d in file '%s'", func, line, file)
90+
mp_obj_t args[5] = { MP_OBJ_NEW_SMALL_INT(pcode), MP_OBJ_FROM_PTR(o_str), mp_obj_new_str(func, strlen(func)), mp_obj_new_int(line), mp_obj_new_str(file, strlen(file)) };
91+
nlr_raise(mp_obj_exception_make_new(&mp_type_OSError, 5, 0, args));
92+
#endif
8393
}
8494
}
8595

ports/esp32/mphalport.h

100644100755
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ extern TaskHandle_t mp_main_task_handle;
5757
extern ringbuf_t stdin_ringbuf;
5858

5959
// Check the ESP-IDF error code and raise an OSError if it's not ESP_OK.
60-
void check_esp_err(esp_err_t code);
60+
#define check_esp_err(code) check_esp_err_(code, __FUNCTION__, __LINE__, __FILE__)
61+
void check_esp_err_(esp_err_t code, const char* func, const int line, const char *file);
6162

6263
uint32_t mp_hal_ticks_us(void);
6364
__attribute__((always_inline)) static inline uint32_t mp_hal_ticks_cpu(void) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy