From 4c587e28bc188efc852039606cac641768323ee3 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Sun, 17 Apr 2016 02:12:01 +0300 Subject: [PATCH] Fix Exception 2 when using printf or vprintf ets_vprintf signature is not the same as vprintf, it takes an output function as a first argument. --- cores/esp8266/libc_replacements.c | 5 ++--- tools/sdk/include/ets_sys.h | 5 +++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cores/esp8266/libc_replacements.c b/cores/esp8266/libc_replacements.c index 57fbed9c9..23180261d 100644 --- a/cores/esp8266/libc_replacements.c +++ b/cores/esp8266/libc_replacements.c @@ -52,10 +52,9 @@ int ICACHE_RAM_ATTR putchar(int c) { } int ICACHE_RAM_ATTR printf(const char* format, ...) { - int ret; va_list arglist; va_start(arglist, format); - ret = ets_vprintf(format, arglist); + int ret = ets_vprintf(ets_putc, format, arglist); va_end(arglist); return ret; } @@ -79,7 +78,7 @@ int ICACHE_RAM_ATTR snprintf(char* buffer, size_t size, const char* format, ...) } int ICACHE_RAM_ATTR vprintf(const char * format, va_list arg) { - return ets_vprintf(format, arg); + return ets_vprintf(ets_putc, format, arg); } int ICACHE_RAM_ATTR vsnprintf(char * buffer, size_t size, const char * format, va_list arg) { diff --git a/tools/sdk/include/ets_sys.h b/tools/sdk/include/ets_sys.h index 813061ab7..8eb64b343 100644 --- a/tools/sdk/include/ets_sys.h +++ b/tools/sdk/include/ets_sys.h @@ -155,7 +155,7 @@ inline uint32_t ETS_INTR_PENDING(void) #define ETS_SDIO_INTR_DISABLE() \ ETS_INTR_DISABLE(ETS_SDIO_INUM) - + void *pvPortMalloc(size_t xWantedSize, const char* file, int line) __attribute__((malloc, alloc_size(1))); void *pvPortRealloc(void* ptr, size_t xWantedSize, const char* file, int line) __attribute__((alloc_size(2))); @@ -183,7 +183,8 @@ void ets_isr_attach(int intr, int_handler_t handler, void *arg); void ets_intr_lock(); void ets_intr_unlock(); int ets_vsnprintf(char * s, size_t n, const char * format, va_list arg) __attribute__ ((format (printf, 3, 0))); -int ets_vprintf(const char * format, va_list arg) __attribute__ ((format (printf, 1, 0))); +int ets_vprintf(int (*print_function)(int), const char * format, va_list arg) __attribute__ ((format (printf, 2, 0))); +int ets_putc(int); bool ets_task(ETSTask task, uint8 prio, ETSEvent *queue, uint8 qlen); bool ets_post(uint8 prio, ETSSignal sig, ETSParam par);