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.
This commit is contained in:
Gunar Schorcht 2019-08-06 07:58:10 +02:00
parent 4972d5bd67
commit 9e47872a59
2 changed files with 7 additions and 3 deletions

View File

@ -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)

View File

@ -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) {