Skip to content
Snippets Groups Projects
Commit 8ab16b6a authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

esp8266: Add custom _assert() function.

Enabling standard assert() (by removing -DNDEBUG) produces non-bootable
binary (because all messages go to .rodata which silently overflows).
So, for once-off debugging, have a custom _assert().
parent c70637bc
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#include "uart.h" #include "uart.h"
#include "esp_mphal.h" #include "esp_mphal.h"
#include "user_interface.h" #include "user_interface.h"
#include "py/obj.h"
#include "py/mpstate.h"
extern void ets_wdt_disable(void); extern void ets_wdt_disable(void);
extern void wdt_feed(void); extern void wdt_feed(void);
...@@ -98,3 +100,9 @@ void mp_hal_delay_ms(uint32_t delay) { ...@@ -98,3 +100,9 @@ void mp_hal_delay_ms(uint32_t delay) {
void mp_hal_set_interrupt_char(int c) { void mp_hal_set_interrupt_char(int c) {
// TODO // TODO
} }
void __assert_func(const char *file, int line, const char *func, const char *expr) {
printf("assert:%s:%d:%s: %s\n", file, line, func, expr);
nlr_raise(mp_obj_new_exception_msg(&mp_type_AssertionError,
"C-level assert"));
}
...@@ -113,3 +113,5 @@ extern const struct _mp_obj_module_t mp_module_machine; ...@@ -113,3 +113,5 @@ extern const struct _mp_obj_module_t mp_module_machine;
#define MICROPY_HW_BOARD_NAME "ESP module" #define MICROPY_HW_BOARD_NAME "ESP module"
#define MICROPY_HW_MCU_NAME "ESP8266" #define MICROPY_HW_MCU_NAME "ESP8266"
#define MICROPY_PY_SYS_PLATFORM "ESP8266" #define MICROPY_PY_SYS_PLATFORM "ESP8266"
#define _assert(expr) ((expr) ? (void)0 : __assert_func(__FILE__, __LINE__, __func__, #expr))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment