From fddfe86a4b56af14d7b1e643bdff2391cdb6b48a Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Sun, 14 Oct 2018 13:50:38 +0200 Subject: [PATCH] cpu/esp32: fixes dependency problem for timer Xtensa newlib version requires pthread_setcancelstate as symbol. Therefore, the module pthread was always used, which in turn requires the module xtimer. The xtimer module, however, uses TIMER_DEV(0). Therefore, tests/timers failed for TIMER_DEV(0). --- cpu/esp32/Makefile.dep | 2 ++ cpu/esp32/Makefile.include | 11 +++++------ cpu/esp32/periph/flash.c | 4 ++++ cpu/esp32/startup.c | 2 ++ cpu/esp32/syscalls.c | 16 ++++++++++++++++ 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/cpu/esp32/Makefile.dep b/cpu/esp32/Makefile.dep index c121231c8a..162dfa6033 100644 --- a/cpu/esp32/Makefile.dep +++ b/cpu/esp32/Makefile.dep @@ -52,6 +52,7 @@ endif # each device has SPI flash memory, but must be explicitly enabled ifneq (,$(filter esp_spiffs,$(USEMODULE))) + USEMODULE += esp_idf_spi_flash USEMODULE += spiffs USEMODULE += vfs export SPIFFS_STD_OPTION = -std=c99 @@ -70,6 +71,7 @@ endif ifneq (,$(filter shell,$(USEMODULE))) USEMODULE += newlib_syscalls_default + USEMODULE += ps USEMODULE += xtimer endif diff --git a/cpu/esp32/Makefile.include b/cpu/esp32/Makefile.include index 3999f376c6..442a8d334f 100644 --- a/cpu/esp32/Makefile.include +++ b/cpu/esp32/Makefile.include @@ -29,6 +29,10 @@ endif # SPECIAL module dependencies # cannot be done in Makefile.dep since Makefile.dep is included too late +ifneq (,$(findstring core_thread_flags,$(USEMODULE))) + USEMODULE += pthread +endif + ifneq (,$(filter esp_gdbstub,$(USEMODULE))) USEMODULE += esp_gdb endif @@ -57,18 +61,13 @@ export CPU ?= esp32 export TARGET_ARCH ?= xtensa-esp32-elf export ESPTOOL ?= $(ESP32_SDK_DIR)/components/esptool_py/esptool/esptool.py -USEMODULE += core_thread_flags USEMODULE += esp_idf USEMODULE += esp_idf_driver USEMODULE += esp_idf_esp32 USEMODULE += esp_idf_soc -USEMODULE += esp_idf_spi_flash USEMODULE += log -USEMODULE += mtd USEMODULE += periph USEMODULE += periph_common -USEMODULE += pthread -USEMODULE += ps USEMODULE += random USEMODULE += xtensa @@ -137,7 +136,7 @@ ifneq (,$(filter pthread,$(USEMODULE))) LINKFLAGS += $(BINDIR)/pthread.a endif -LINKFLAGS += -lhal -lc -lg +LINKFLAGS += -lhal -lg -lc -lg LINKFLAGS += -Wl,--end-group LINKFLAGS += -L$(RIOTCPU)/$(CPU)/ld/ LINKFLAGS += -T$(RIOTCPU)/$(CPU)/ld/esp32.ld diff --git a/cpu/esp32/periph/flash.c b/cpu/esp32/periph/flash.c index 9beb26c29b..8298e6bc8b 100644 --- a/cpu/esp32/periph/flash.c +++ b/cpu/esp32/periph/flash.c @@ -18,6 +18,8 @@ * @} */ +#if MODULE_MTD + #define ENABLE_DEBUG (0) #include "debug.h" @@ -429,3 +431,5 @@ static int _flash_power (mtd_dev_t *dev, enum mtd_power_state power) return -ENOTSUP; } + +#endif /* MODULE_MTD */ diff --git a/cpu/esp32/startup.c b/cpu/esp32/startup.c index b006d0e020..c1a34e16d5 100644 --- a/cpu/esp32/startup.c +++ b/cpu/esp32/startup.c @@ -316,9 +316,11 @@ static NORETURN void IRAM system_init (void) _sys_time.tm_year + 1900, _sys_time.tm_mon + 1, _sys_time.tm_mday, _sys_time.tm_hour, _sys_time.tm_min, _sys_time.tm_sec); + #if MODULE_MTD /* init flash drive */ extern void spi_flash_drive_init (void); spi_flash_drive_init(); + #endif /* initialize the board */ board_init(); diff --git a/cpu/esp32/syscalls.c b/cpu/esp32/syscalls.c index c82756de27..6d3cc6da67 100644 --- a/cpu/esp32/syscalls.c +++ b/cpu/esp32/syscalls.c @@ -113,6 +113,22 @@ int IRAM printf(const char* format, ...) return ret; } +#ifndef MODULE_PTHREAD + +#define PTHREAD_CANCEL_DISABLE 1 +/* + * This is a dummy function to avoid undefined references when linking + * against newlib and module pthread is not used. + */ +int pthread_setcancelstate(int state, int *oldstate) +{ + if (oldstate) { + *oldstate = PTHREAD_CANCEL_DISABLE; + } + return 0; +} +#endif /* MODULE_PTHREAD*/ + /** * @name Locking functions *