From 9e47872a59d16406107951e6da99678839bc33df Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Tue, 6 Aug 2019 07:58:10 +0200 Subject: [PATCH] cpu/esp32: fix multiple definition of putchar When standard C libraries are added to BASELIBS to group them together with all other modules, there are multiple definitions for the putchar function. The one that is defined writing to the UART as standard output and the one that is provided by the standard C libraries. To solve this symbol conflict, putchar and getchar functions that use the UART as standard output/input are renamed to __wrap_putchar and __wrap_getchar and the linker options are extended by -Wl,-wrap option. --- cpu/esp32/Makefile.include | 6 +++++- cpu/esp32/syscalls.c | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cpu/esp32/Makefile.include b/cpu/esp32/Makefile.include index 9def844fb0..850a724022 100644 --- a/cpu/esp32/Makefile.include +++ b/cpu/esp32/Makefile.include @@ -140,8 +140,12 @@ LINKFLAGS += -T$(RIOTCPU)/$(CPU)/ld/esp32.common.ld LINKFLAGS += -T$(RIOTCPU)/$(CPU)/ld/esp32.peripherals.ld LINKFLAGS += -T$(RIOTCPU)/$(CPU)/ld/esp32.rom.ld LINKFLAGS += -T$(RIOTCPU)/$(CPU)/ld/esp32.rom.nanofmt.ld -LINKFLAGS += -nostdlib -lgcc -u putchar -Wl,-gc-sections +LINKFLAGS += -nostdlib -lgcc -Wl,-gc-sections +ifneq (,$(filter stdio_uart,$(USEMODULE))) + LINKFLAGS += -Wl,-wrap,putchar + LINKFLAGS += -Wl,-wrap,getchar +endif # The ELFFILE is the base one used for flashing FLASHFILE ?= $(ELFFILE) diff --git a/cpu/esp32/syscalls.c b/cpu/esp32/syscalls.c index 674441e6d8..6c1e6269e3 100644 --- a/cpu/esp32/syscalls.c +++ b/cpu/esp32/syscalls.c @@ -67,7 +67,7 @@ #ifdef MODULE_STDIO_UART #include "stdio_uart.h" -int IRAM putchar(int c) +int IRAM __wrap_putchar(int c) { char tmp = c; if (stdio_write(&tmp, 1) > 0) { @@ -76,7 +76,7 @@ int IRAM putchar(int c) return -EOF; } -int IRAM getchar(void) +int IRAM __wrap_getchar(void) { char tmp; if (stdio_read(&tmp, 1) > 0) {