Skip to content

esp32/mphalport: Add _FUNCTION_, _LINE_, _FILE_ info to check_esp_err(). #10888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion ports/esp32/mphalport.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion ports/esp32/mphalport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down