Skip to content

Commit 8ab16b6

Browse files
committed
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().
1 parent c70637b commit 8ab16b6

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

esp8266/esp_mphal.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include "uart.h"
3131
#include "esp_mphal.h"
3232
#include "user_interface.h"
33+
#include "py/obj.h"
34+
#include "py/mpstate.h"
3335

3436
extern void ets_wdt_disable(void);
3537
extern void wdt_feed(void);
@@ -98,3 +100,9 @@ void mp_hal_delay_ms(uint32_t delay) {
98100
void mp_hal_set_interrupt_char(int c) {
99101
// TODO
100102
}
103+
104+
void __assert_func(const char *file, int line, const char *func, const char *expr) {
105+
printf("assert:%s:%d:%s: %s\n", file, line, func, expr);
106+
nlr_raise(mp_obj_new_exception_msg(&mp_type_AssertionError,
107+
"C-level assert"));
108+
}

esp8266/mpconfigport.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,5 @@ extern const struct _mp_obj_module_t mp_module_machine;
113113
#define MICROPY_HW_BOARD_NAME "ESP module"
114114
#define MICROPY_HW_MCU_NAME "ESP8266"
115115
#define MICROPY_PY_SYS_PLATFORM "ESP8266"
116+
117+
#define _assert(expr) ((expr) ? (void)0 : __assert_func(__FILE__, __LINE__, __func__, #expr))

0 commit comments

Comments
 (0)