aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Mussared2019-09-13 23:04:13 +1000
committerDamien George2019-09-17 12:25:36 +1000
commit96008ff59a8af9883af17d01b951029d9d02eec9 (patch)
treeb219c2d1b55a316702c15cdfda9c625d7ce8d5f4
parentb45f9de8096f37a5f588f833e6b6a00b59e67e3f (diff)
esp32: Support building with ESP IDF 4.0-beta1.
This commit adds support for a second supported hash (currently set to the 4.0-beta1 tag). When this hash is detected, the relevant changes are applied. This allows to start using v4 features (e.g. BLE with Nimble), and also start doing testing, while still supporting the original, stable, v3.3 IDF. Note: this feature is experimental, not well tested, and network.LAN and network.PPP are currently unsupported.
-rw-r--r--ports/esp32/Makefile198
-rw-r--r--ports/esp32/boards/TINYPICO/sdkconfig.board1
-rw-r--r--ports/esp32/boards/sdkconfig.base11
-rw-r--r--ports/esp32/boards/sdkconfig.spiram6
-rw-r--r--ports/esp32/esp32_ulp.c4
-rw-r--r--ports/esp32/main.c12
-rw-r--r--ports/esp32/modesp.c2
-rw-r--r--ports/esp32/modmachine.c6
-rw-r--r--ports/esp32/modnetwork.c18
-rw-r--r--ports/esp32/modsocket.c48
-rw-r--r--ports/esp32/mpconfigport.h3
-rw-r--r--ports/esp32/mphalport.c5
-rw-r--r--ports/esp32/mpthreadport.c3
-rw-r--r--ports/esp32/network_lan.c3
-rw-r--r--ports/esp32/network_ppp.c3
15 files changed, 266 insertions, 57 deletions
diff --git a/ports/esp32/Makefile b/ports/esp32/Makefile
index 3e48febf0..25001643e 100644
--- a/ports/esp32/Makefile
+++ b/ports/esp32/Makefile
@@ -50,7 +50,13 @@ SDKCONFIG_COMBINED = $(BUILD)/sdkconfig.combined
SDKCONFIG_H = $(BUILD)/sdkconfig.h
# the git hash of the currently supported ESP IDF version
-ESPIDF_SUPHASH := 6ccb4cf5b7d1fdddb8c2492f9cbc926abaf230df
+ESPIDF_SUPHASH_V3 := 6ccb4cf5b7d1fdddb8c2492f9cbc926abaf230df
+ESPIDF_SUPHASH_V4 := 310beae373446ceb9a4ad9b36b5428d7fdf2705f
+
+define print_supported_git_hash
+$(info Supported git hash (v3.3): $(ESPIDF_SUPHASH_V3))
+$(info Supported git hash (v4.0-beta1) (experimental): $(ESPIDF_SUPHASH_V4))
+endef
# paths to ESP IDF and its components
ifeq ($(ESPIDF),)
@@ -59,10 +65,11 @@ ESPIDF = $(IDF_PATH)
else
$(info The ESPIDF variable has not been set, please set it to the root of the esp-idf repository.)
$(info See README.md for installation instructions.)
-$(info Supported git hash: $(ESPIDF_SUPHASH))
$(error ESPIDF not set)
+print_supported_git_hash
endif
endif
+
ESPCOMP = $(ESPIDF)/components
ESPTOOL ?= $(ESPCOMP)/esptool_py/esptool/esptool.py
ESPCOMP_KCONFIGS = $(shell find $(ESPCOMP) -name Kconfig)
@@ -70,13 +77,18 @@ ESPCOMP_KCONFIGS_PROJBUILD = $(shell find $(ESPCOMP) -name Kconfig.projbuild)
# verify the ESP IDF version
ESPIDF_CURHASH := $(shell git -C $(ESPIDF) show -s --pretty=format:'%H')
-ifneq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH))
+
+ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V3))
+$(info Building with ESP IDF v3)
+else ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
+$(info Building with ESP IDF v4)
+else
$(info ** WARNING **)
$(info The git hash of ESP IDF does not match the supported version)
$(info The build may complete and the firmware may work but it is not guaranteed)
$(info ESP IDF path: $(ESPIDF))
$(info Current git hash: $(ESPIDF_CURHASH))
-$(info Supported git hash: $(ESPIDF_SUPHASH))
+print_supported_git_hash
endif
# pretty format of ESP IDF version, used internally by the IDF
@@ -100,20 +112,13 @@ INC_ESPCOMP += -I$(ESPCOMP)/bootloader_support/include_bootloader
INC_ESPCOMP += -I$(ESPCOMP)/console
INC_ESPCOMP += -I$(ESPCOMP)/driver/include
INC_ESPCOMP += -I$(ESPCOMP)/driver/include/driver
-INC_ESPCOMP += -I$(ESPCOMP)/nghttp/port/include
-INC_ESPCOMP += -I$(ESPCOMP)/nghttp/nghttp2/lib/includes
INC_ESPCOMP += -I$(ESPCOMP)/efuse/include
INC_ESPCOMP += -I$(ESPCOMP)/efuse/esp32/include
INC_ESPCOMP += -I$(ESPCOMP)/esp32/include
INC_ESPCOMP += -I$(ESPCOMP)/espcoredump/include
INC_ESPCOMP += -I$(ESPCOMP)/soc/include
INC_ESPCOMP += -I$(ESPCOMP)/soc/esp32/include
-INC_ESPCOMP += -I$(ESPCOMP)/ethernet/include
-INC_ESPCOMP += -I$(ESPCOMP)/expat/expat/expat/lib
-INC_ESPCOMP += -I$(ESPCOMP)/expat/port/include
INC_ESPCOMP += -I$(ESPCOMP)/heap/include
-INC_ESPCOMP += -I$(ESPCOMP)/json/include
-INC_ESPCOMP += -I$(ESPCOMP)/json/port/include
INC_ESPCOMP += -I$(ESPCOMP)/log/include
INC_ESPCOMP += -I$(ESPCOMP)/newlib/platform_include
INC_ESPCOMP += -I$(ESPCOMP)/newlib/include
@@ -129,20 +134,41 @@ INC_ESPCOMP += -I$(ESPCOMP)/mbedtls/mbedtls/include
INC_ESPCOMP += -I$(ESPCOMP)/mbedtls/port/include
INC_ESPCOMP += -I$(ESPCOMP)/mdns/include
INC_ESPCOMP += -I$(ESPCOMP)/mdns/private_include
-INC_ESPCOMP += -I$(ESPCOMP)/micro-ecc/micro-ecc
INC_ESPCOMP += -I$(ESPCOMP)/spi_flash/include
INC_ESPCOMP += -I$(ESPCOMP)/ulp/include
INC_ESPCOMP += -I$(ESPCOMP)/vfs/include
INC_ESPCOMP += -I$(ESPCOMP)/xtensa-debug-module/include
INC_ESPCOMP += -I$(ESPCOMP)/wpa_supplicant/include
INC_ESPCOMP += -I$(ESPCOMP)/wpa_supplicant/port/include
-INC_ESPCOMP += -I$(ESPCOMP)/ethernet/include
INC_ESPCOMP += -I$(ESPCOMP)/app_trace/include
INC_ESPCOMP += -I$(ESPCOMP)/app_update/include
INC_ESPCOMP += -I$(ESPCOMP)/pthread/include
INC_ESPCOMP += -I$(ESPCOMP)/smartconfig_ack/include
INC_ESPCOMP += -I$(ESPCOMP)/sdmmc/include
+ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
+INC_ESPCOMP += -I$(ESPCOMP)/esp_common/include
+INC_ESPCOMP += -I$(ESPCOMP)/esp_eth/include
+INC_ESPCOMP += -I$(ESPCOMP)/esp_event/private_include
+INC_ESPCOMP += -I$(ESPCOMP)/esp_rom/include
+INC_ESPCOMP += -I$(ESPCOMP)/esp_wifi/include
+INC_ESPCOMP += -I$(ESPCOMP)/esp_wifi/esp32/include
+INC_ESPCOMP += -I$(ESPCOMP)/lwip/include/apps/sntp
+INC_ESPCOMP += -I$(ESPCOMP)/spi_flash/private_include
+INC_ESPCOMP += -I$(ESPCOMP)/wpa_supplicant/include/esp_supplicant
+INC_ESPCOMP += -I$(ESPCOMP)/xtensa/include
+INC_ESPCOMP += -I$(ESPCOMP)/xtensa/esp32/include
+else
+INC_ESPCOMP += -I$(ESPCOMP)/ethernet/include
+INC_ESPCOMP += -I$(ESPCOMP)/expat/expat/expat/lib
+INC_ESPCOMP += -I$(ESPCOMP)/expat/port/include
+INC_ESPCOMP += -I$(ESPCOMP)/json/include
+INC_ESPCOMP += -I$(ESPCOMP)/json/port/include
+INC_ESPCOMP += -I$(ESPCOMP)/micro-ecc/micro-ecc
+INC_ESPCOMP += -I$(ESPCOMP)/nghttp/port/include
+INC_ESPCOMP += -I$(ESPCOMP)/nghttp/nghttp2/lib/includes
+endif
+
# these flags are common to C and C++ compilation
CFLAGS_COMMON = -Os -ffunction-sections -fdata-sections -fstrict-volatile-bitfields \
-mlongcalls -nostdlib \
@@ -156,6 +182,10 @@ CFLAGS += -DIDF_VER=\"$(IDF_VER)\"
CFLAGS += $(CFLAGS_MOD) $(CFLAGS_EXTRA)
CFLAGS += -I$(BOARD_DIR)
+ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
+CFLAGS += -DMICROPY_ESP_IDF_4=1
+endif
+
# this is what ESPIDF uses for c++ compilation
CXXFLAGS = -std=gnu++11 $(CFLAGS_COMMON) $(INC) $(INC_ESPCOMP)
@@ -164,6 +194,7 @@ LDFLAGS += --gc-sections -static -EL
LDFLAGS += -u call_user_start_cpu0 -u uxTopUsedPriority -u ld_include_panic_highint_hdl
LDFLAGS += -u __cxa_guard_dummy # so that implementation of static guards is taken from cxx_guards.o instead of libstdc++.a
LDFLAGS += -L$(ESPCOMP)/esp32/ld
+LDFLAGS += -L$(ESPCOMP)/esp_rom/esp32/ld
LDFLAGS += -T $(BUILD)/esp32_out.ld
LDFLAGS += -T $(BUILD)/esp32.project.ld
LDFLAGS += -T esp32.rom.ld
@@ -183,12 +214,19 @@ COPT += -Os -DNDEBUG
#LDFLAGS += --gc-sections
endif
-# Enable SPIRAM support if CONFIG_SPIRAM_SUPPORT=y in sdkconfig
-ifeq ($(CONFIG_SPIRAM_SUPPORT),y)
+# Enable SPIRAM support if CONFIG_ESP32_SPIRAM_SUPPORT=y in sdkconfig
+ifeq ($(CONFIG_ESP32_SPIRAM_SUPPORT),y)
CFLAGS_COMMON += -mfix-esp32-psram-cache-issue
LIBC_LIBM = $(ESPCOMP)/newlib/lib/libc-psram-workaround.a $(ESPCOMP)/newlib/lib/libm-psram-workaround.a
else
+# Additional newlib symbols that can only be used with spiram disabled.
+ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
+LDFLAGS += -T esp32.rom.newlib-funcs.ld
+LDFLAGS += -T esp32.rom.newlib-locale.ld
+LDFLAGS += -T esp32.rom.newlib-data.ld
+else
LDFLAGS += -T esp32.rom.spiram_incompatible_fns.ld
+endif
LIBC_LIBM = $(ESPCOMP)/newlib/lib/libc.a $(ESPCOMP)/newlib/lib/libm.a
endif
@@ -283,7 +321,8 @@ $(SDKCONFIG_H): $(SDKCONFIG_COMBINED)
--env "IDF_TARGET=esp32" \
--env "IDF_CMAKE=n" \
--env "COMPONENT_KCONFIGS=$(ESPCOMP_KCONFIGS)" \
- --env "COMPONENT_KCONFIGS_PROJBUILD=$(ESPCOMP_KCONFIGS_PROJBUILD)"
+ --env "COMPONENT_KCONFIGS_PROJBUILD=$(ESPCOMP_KCONFIGS_PROJBUILD)" \
+ --env "IDF_PATH=$(ESPIDF)"
$(Q)touch $@
$(HEADER_BUILD)/qstrdefs.generated.h: $(SDKCONFIG_H) $(BOARD_DIR)/mpconfigboard.h
@@ -293,7 +332,9 @@ $(HEADER_BUILD)/qstrdefs.generated.h: $(SDKCONFIG_H) $(BOARD_DIR)/mpconfigboard.
ESPIDF_BOOTLOADER_SUPPORT_O = $(patsubst %.c,%.o,\
$(filter-out $(ESPCOMP)/bootloader_support/src/bootloader_init.c,\
- $(wildcard $(ESPCOMP)/bootloader_support/src/*.c)))
+ $(wildcard $(ESPCOMP)/bootloader_support/src/*.c) \
+ $(wildcard $(ESPCOMP)/bootloader_support/src/idf/*.c) \
+ ))
ESPIDF_DRIVER_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/driver/*.c))
@@ -315,22 +356,22 @@ ESPIDF_HEAP_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/heap/*.c))
ESPIDF_SOC_O = $(patsubst %.c,%.o,\
$(wildcard $(ESPCOMP)/soc/esp32/*.c) \
$(wildcard $(ESPCOMP)/soc/src/*.c) \
+ $(wildcard $(ESPCOMP)/soc/src/hal/*.c) \
)
ESPIDF_CXX_O = $(patsubst %.cpp,%.o,$(wildcard $(ESPCOMP)/cxx/*.cpp))
-ESPIDF_ETHERNET_O = $(patsubst %.c,%.o,\
- $(wildcard $(ESPCOMP)/ethernet/*.c) \
- $(wildcard $(ESPCOMP)/ethernet/eth_phy/*.c) \
- )
-
ESPIDF_PTHREAD_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/pthread/*.c))
# Assembler .S files need only basic flags, and in particular should not have
# -Os because that generates subtly different code.
# We also need custom CFLAGS for .c files because FreeRTOS has headers with
# generic names (eg queue.h) which can clash with other files in the port.
+ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
+CFLAGS_ASM = -I$(BUILD) -I$(ESPCOMP)/esp32/include -I$(ESPCOMP)/soc/esp32/include -I$(ESPCOMP)/freertos/include/freertos -I. -I$(ESPCOMP)/xtensa/include -I$(ESPCOMP)/xtensa/esp32/include -I$(ESPCOMP)/esp_common/include
+else
CFLAGS_ASM = -I$(BUILD) -I$(ESPCOMP)/esp32/include -I$(ESPCOMP)/soc/esp32/include -I$(ESPCOMP)/freertos/include/freertos -I.
+endif
$(BUILD)/$(ESPCOMP)/freertos/portasm.o: CFLAGS = $(CFLAGS_ASM)
$(BUILD)/$(ESPCOMP)/freertos/xtensa_context.o: CFLAGS = $(CFLAGS_ASM)
$(BUILD)/$(ESPCOMP)/freertos/xtensa_intr_asm.o: CFLAGS = $(CFLAGS_ASM)
@@ -343,8 +384,6 @@ ESPIDF_FREERTOS_O = \
ESPIDF_VFS_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/vfs/*.c))
-ESPIDF_JSON_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/json/cJSON/cJSON*.c))
-
ESPIDF_LOG_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/log/*.c))
ESPIDF_XTENSA_DEBUG_MODULE_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/xtensa-debug-module/*.c))
@@ -382,11 +421,16 @@ ESPIDF_LWIP_O = $(patsubst %.c,%.o,\
ESPIDF_MBEDTLS_O = $(patsubst %.c,%.o,\
$(wildcard $(ESPCOMP)/mbedtls/mbedtls/library/*.c) \
$(wildcard $(ESPCOMP)/mbedtls/port/*.c) \
+ $(wildcard $(ESPCOMP)/mbedtls/port/esp32/*.c) \
)
ESPIDF_MDNS_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/mdns/*.c))
+ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
+$(BUILD)/$(ESPCOMP)/wpa_supplicant/%.o: CFLAGS += -DESP_SUPPLICANT -DIEEE8021X_EAPOL -DEAP_PEER_METHOD -DEAP_TLS -DEAP_TTLS -DEAP_PEAP -DEAP_MSCHAPv2 -DUSE_WPA2_TASK -DCONFIG_WPS2 -DCONFIG_WPS_PIN -DUSE_WPS_TASK -DESPRESSIF_USE -DESP32_WORKAROUND -DCONFIG_ECC -D__ets__ -Wno-strict-aliasing -I$(ESPCOMP)/wpa_supplicant/src -Wno-implicit-function-declaration
+else
$(BUILD)/$(ESPCOMP)/wpa_supplicant/%.o: CFLAGS += -DEMBEDDED_SUPP -DIEEE8021X_EAPOL -DEAP_PEER_METHOD -DEAP_MSCHAPv2 -DEAP_TTLS -DEAP_TLS -DEAP_PEAP -DUSE_WPA2_TASK -DCONFIG_WPS2 -DCONFIG_WPS_PIN -DUSE_WPS_TASK -DESPRESSIF_USE -DESP32_WORKAROUND -DALLOW_EVEN_MOD -D__ets__ -Wno-strict-aliasing
+endif
ESPIDF_WPA_SUPPLICANT_O = $(patsubst %.c,%.o,\
$(wildcard $(ESPCOMP)/wpa_supplicant/port/*.c) \
$(wildcard $(ESPCOMP)/wpa_supplicant/src/*/*.c) \
@@ -394,6 +438,29 @@ ESPIDF_WPA_SUPPLICANT_O = $(patsubst %.c,%.o,\
ESPIDF_SDMMC_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/sdmmc/*.c))
+ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
+ESPIDF_ESP_COMMON_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/esp_common/src/*.c))
+
+ESPIDF_ESP_EVENT_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/esp_event/*.c))
+
+ESPIDF_ESP_WIFI_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/esp_wifi/src/*.c))
+
+$(BUILD)/$(ESPCOMP)/esp_eth/src/esp_eth_mac_dm9051.o: CFLAGS += -fno-strict-aliasing
+ESPIDF_ESP_ETH_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/esp_eth/src/*.c))
+
+ESPIDF_XTENSA_O = $(patsubst %.c,%.o,\
+ $(wildcard $(ESPCOMP)/xtensa/*.c) \
+ $(wildcard $(ESPCOMP)/xtensa/esp32/*.c) \
+ )
+else
+ESPIDF_JSON_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/json/cJSON/cJSON*.c))
+
+ESPIDF_ETHERNET_O = $(patsubst %.c,%.o,\
+ $(wildcard $(ESPCOMP)/ethernet/*.c) \
+ $(wildcard $(ESPCOMP)/ethernet/eth_phy/*.c) \
+ )
+endif
+
OBJ_ESPIDF =
LIB_ESPIDF =
BUILD_ESPIDF_LIB = $(BUILD)/esp-idf
@@ -414,7 +481,6 @@ $(eval $(call gen_espidf_lib_rule,esp_ringbuf,$(ESPIDF_ESP_RINGBUF_O)))
$(eval $(call gen_espidf_lib_rule,heap,$(ESPIDF_HEAP_O)))
$(eval $(call gen_espidf_lib_rule,soc,$(ESPIDF_SOC_O)))
$(eval $(call gen_espidf_lib_rule,cxx,$(ESPIDF_CXX_O)))
-$(eval $(call gen_espidf_lib_rule,ethernet,$(ESPIDF_ETHERNET_O)))
$(eval $(call gen_espidf_lib_rule,pthread,$(ESPIDF_PTHREAD_O)))
$(eval $(call gen_espidf_lib_rule,freertos,$(ESPIDF_FREERTOS_O)))
$(eval $(call gen_espidf_lib_rule,vfs,$(ESPIDF_VFS_O)))
@@ -435,6 +501,16 @@ $(eval $(call gen_espidf_lib_rule,mdns,$(ESPIDF_MDNS_O)))
$(eval $(call gen_espidf_lib_rule,wpa_supplicant,$(ESPIDF_WPA_SUPPLICANT_O)))
$(eval $(call gen_espidf_lib_rule,sdmmc,$(ESPIDF_SDMMC_O)))
+ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
+$(eval $(call gen_espidf_lib_rule,esp_common,$(ESPIDF_ESP_COMMON_O)))
+$(eval $(call gen_espidf_lib_rule,esp_event,$(ESPIDF_ESP_EVENT_O)))
+$(eval $(call gen_espidf_lib_rule,esp_wifi,$(ESPIDF_ESP_WIFI_O)))
+$(eval $(call gen_espidf_lib_rule,esp_eth,$(ESPIDF_ESP_ETH_O)))
+$(eval $(call gen_espidf_lib_rule,xtensa,$(ESPIDF_XTENSA_O)))
+else
+$(eval $(call gen_espidf_lib_rule,ethernet,$(ESPIDF_ETHERNET_O)))
+endif
+
# Create all destination build dirs before compiling IDF source
OBJ_ESPIDF_DIRS = $(sort $(dir $(OBJ_ESPIDF))) $(BUILD_ESPIDF_LIB) $(addprefix $(BUILD_ESPIDF_LIB)/,$(LIB_ESPIDF))
$(OBJ_ESPIDF): | $(OBJ_ESPIDF_DIRS)
@@ -451,6 +527,32 @@ LIB = $(foreach lib,$(LIB_ESPIDF),$(BUILD_ESPIDF_LIB)/$(lib)/lib$(lib).a)
# ESP IDF ldgen
LDGEN_FRAGMENTS = $(shell find $(ESPCOMP) -name "*.lf")
+
+ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
+
+LDGEN_LIBRARIES=$(foreach lib,$(LIB_ESPIDF),$(BUILD_ESPIDF_LIB)/$(lib)/lib$(lib).a)
+
+$(BUILD_ESPIDF_LIB)/ldgen_libraries: $(LDGEN_LIBRARIES) $(ESPIDF)/make/ldgen.mk
+ printf "$(foreach library,$(LDGEN_LIBRARIES),$(library)\n)" > $(BUILD_ESPIDF_LIB)/ldgen_libraries
+
+$(BUILD)/esp32.project.ld: $(ESPCOMP)/esp32/ld/esp32.project.ld.in $(LDGEN_FRAGMENTS) $(SDKCONFIG_COMBINED) $(BUILD_ESPIDF_LIB)/ldgen_libraries
+ $(ECHO) "GEN $@"
+ $(Q)$(PYTHON) $(ESPIDF)/tools/ldgen/ldgen.py \
+ --input $< \
+ --output $@ \
+ --config $(SDKCONFIG_COMBINED) \
+ --kconfig $(ESPIDF)/Kconfig \
+ --fragments $(LDGEN_FRAGMENTS) \
+ --libraries-file $(BUILD_ESPIDF_LIB)/ldgen_libraries \
+ --env "IDF_TARGET=esp32" \
+ --env "IDF_CMAKE=n" \
+ --env "COMPONENT_KCONFIGS=$(ESPCOMP_KCONFIGS)" \
+ --env "COMPONENT_KCONFIGS_PROJBUILD=$(ESPCOMP_KCONFIGS_PROJBUILD)" \
+ --env "IDF_PATH=$(ESPIDF)" \
+ --objdump $(OBJDUMP)
+
+else
+
LDGEN_SECTIONS_INFO = $(foreach lib,$(LIB_ESPIDF),$(BUILD_ESPIDF_LIB)/$(lib)/lib$(lib).a.sections_info)
LDGEN_SECTION_INFOS = $(BUILD_ESPIDF_LIB)/ldgen.section_infos
@@ -477,7 +579,10 @@ $(BUILD)/esp32.project.ld: $(ESPCOMP)/esp32/ld/esp32.project.ld.in $(LDGEN_FRAGM
--env "IDF_TARGET=esp32" \
--env "IDF_CMAKE=n" \
--env "COMPONENT_KCONFIGS=$(ESPCOMP_KCONFIGS)" \
- --env "COMPONENT_KCONFIGS_PROJBUILD=$(ESPCOMP_KCONFIGS_PROJBUILD)"
+ --env "COMPONENT_KCONFIGS_PROJBUILD=$(ESPCOMP_KCONFIGS_PROJBUILD)" \
+ --env "IDF_PATH=$(ESPIDF)"
+
+endif
################################################################################
# Main targets
@@ -513,8 +618,13 @@ APP_LD_ARGS += --start-group
APP_LD_ARGS += -L$(dir $(LIBGCC_FILE_NAME)) -lgcc
APP_LD_ARGS += -L$(dir $(LIBSTDCXX_FILE_NAME)) -lstdc++
APP_LD_ARGS += $(LIBC_LIBM)
+ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
+APP_LD_ARGS += -L$(ESPCOMP)/xtensa/esp32 -lhal
+APP_LD_ARGS += -L$(ESPCOMP)/esp_wifi/lib_esp32 -lcore -lmesh -lnet80211 -lphy -lrtc -lpp -lsmartconfig -lcoexist
+else
APP_LD_ARGS += $(ESPCOMP)/esp32/libhal.a
APP_LD_ARGS += -L$(ESPCOMP)/esp32/lib -lcore -lmesh -lnet80211 -lphy -lrtc -lpp -lwpa -lsmartconfig -lcoexist -lwps -lwpa2
+endif
APP_LD_ARGS += $(OBJ)
APP_LD_ARGS += $(LIB)
APP_LD_ARGS += --end-group
@@ -553,7 +663,14 @@ $(BUILD)/%.o: %.cpp
BOOTLOADER_LIB_DIR = $(BUILD)/bootloader
BOOTLOADER_LIB_ALL =
+ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
+$(BUILD)/bootloader/$(ESPCOMP)/%.o: CFLAGS += -DBOOTLOADER_BUILD=1 -I$(ESPCOMP)/bootloader_support/include_priv -I$(ESPCOMP)/bootloader_support/include -I$(ESPCOMP)/efuse/include -I$(ESPCOMP)/esp_rom/include -Wno-error=format \
+ -I$(ESPCOMP)/esp_common/include \
+ -I$(ESPCOMP)/xtensa/include \
+ -I$(ESPCOMP)/xtensa/esp32/include
+else
$(BUILD)/bootloader/$(ESPCOMP)/%.o: CFLAGS += -DBOOTLOADER_BUILD=1 -I$(ESPCOMP)/bootloader_support/include_priv -I$(ESPCOMP)/bootloader_support/include -I$(ESPCOMP)/micro-ecc/micro-ecc -I$(ESPCOMP)/efuse/include -I$(ESPCOMP)/esp32 -Wno-error=format
+endif
# libbootloader_support.a
BOOTLOADER_LIB_ALL += bootloader_support
@@ -563,15 +680,27 @@ BOOTLOADER_LIB_BOOTLOADER_SUPPORT_OBJ = $(addprefix $(BUILD)/bootloader/$(ESPCOM
bootloader_support/src/bootloader_flash.o \
bootloader_support/src/bootloader_init.o \
bootloader_support/src/bootloader_random.o \
- bootloader_support/src/bootloader_sha.o \
bootloader_support/src/bootloader_utility.o \
bootloader_support/src/flash_qio_mode.o \
- bootloader_support/src/secure_boot_signatures.o \
- bootloader_support/src/secure_boot.o \
bootloader_support/src/esp_image_format.o \
bootloader_support/src/flash_encrypt.o \
bootloader_support/src/flash_partitions.o \
)
+
+ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
+BOOTLOADER_LIB_BOOTLOADER_SUPPORT_OBJ += $(addprefix $(BUILD)/bootloader/$(ESPCOMP)/,\
+ bootloader_support/src/esp32/bootloader_sha.o \
+ bootloader_support/src/bootloader_flash_config.o \
+ bootloader_support/src/esp32/secure_boot.o \
+ )
+else
+BOOTLOADER_LIB_BOOTLOADER_SUPPORT_OBJ += $(addprefix $(BUILD)/bootloader/$(ESPCOMP)/,\
+ bootloader_support/src/bootloader_sha.o \
+ bootloader_support/src/secure_boot_signatures.o \
+ bootloader_support/src/secure_boot.o \
+ )
+endif
+
$(BOOTLOADER_LIB_DIR)/libbootloader_support.a: $(BOOTLOADER_LIB_BOOTLOADER_SUPPORT_OBJ)
$(ECHO) "AR $@"
$(Q)$(AR) cr $@ $^
@@ -594,6 +723,7 @@ $(BOOTLOADER_LIB_DIR)/libspi_flash.a: $(BOOTLOADER_LIB_SPI_FLASH_OBJ)
$(ECHO) "AR $@"
$(Q)$(AR) cr $@ $^
+ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V3))
# libmicro-ecc.a
BOOTLOADER_LIB_ALL += micro-ecc
BOOTLOADER_LIB_MICRO_ECC_OBJ = $(addprefix $(BUILD)/bootloader/$(ESPCOMP)/,\
@@ -602,6 +732,7 @@ BOOTLOADER_LIB_MICRO_ECC_OBJ = $(addprefix $(BUILD)/bootloader/$(ESPCOMP)/,\
$(BOOTLOADER_LIB_DIR)/libmicro-ecc.a: $(BOOTLOADER_LIB_MICRO_ECC_OBJ)
$(ECHO) "AR $@"
$(Q)$(AR) cr $@ $^
+endif
# libsoc.a
$(BUILD)/bootloader/$(ESPCOMP)/soc/esp32/rtc_clk.o: CFLAGS += -fno-jump-tables -fno-tree-switch-conversion
@@ -651,7 +782,11 @@ BOOTLOADER_LIBS =
BOOTLOADER_LIBS += -Wl,--start-group
BOOTLOADER_LIBS += $(BOOTLOADER_OBJ)
BOOTLOADER_LIBS += -L$(BUILD)/bootloader $(addprefix -l,$(BOOTLOADER_LIB_ALL))
+ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
+BOOTLOADER_LIBS += -L$(ESPCOMP)/esp_wifi/lib_esp32 -lrtc
+else
BOOTLOADER_LIBS += -L$(ESPCOMP)/esp32/lib -lrtc
+endif
BOOTLOADER_LIBS += -L$(dir $(LIBGCC_FILE_NAME)) -lgcc
BOOTLOADER_LIBS += -Wl,--end-group
@@ -666,8 +801,13 @@ BOOTLOADER_LDFLAGS += -Wl,-EL
BOOTLOADER_LDFLAGS += -Wl,-Map=$(@:.elf=.map) -Wl,--cref
BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/bootloader/subproject/main/esp32.bootloader.ld
BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/bootloader/subproject/main/esp32.bootloader.rom.ld
+ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
+BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/esp_rom/esp32/ld/esp32.rom.ld
+BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/esp_rom/esp32/ld/esp32.rom.newlib-funcs.ld
+else
BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/esp32/ld/esp32.rom.ld
BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/esp32/ld/esp32.rom.spiram_incompatible_fns.ld
+endif
BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/esp32/ld/esp32.peripherals.ld
BOOTLOADER_OBJ_DIRS = $(sort $(dir $(BOOTLOADER_OBJ_ALL)))
diff --git a/ports/esp32/boards/TINYPICO/sdkconfig.board b/ports/esp32/boards/TINYPICO/sdkconfig.board
index ea4fc9b5c..dc2c23f67 100644
--- a/ports/esp32/boards/TINYPICO/sdkconfig.board
+++ b/ports/esp32/boards/TINYPICO/sdkconfig.board
@@ -1,3 +1,4 @@
CONFIG_FLASHMODE_QIO=y
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
CONFIG_SPIRAM_SPEED_80M=y
+CONFIG_ESP32_REV_MIN_1=y
diff --git a/ports/esp32/boards/sdkconfig.base b/ports/esp32/boards/sdkconfig.base
index 7bd731a66..d44a97e13 100644
--- a/ports/esp32/boards/sdkconfig.base
+++ b/ports/esp32/boards/sdkconfig.base
@@ -8,7 +8,7 @@ CONFIG_APP_EXCLUDE_PROJECT_VER_VAR=y
CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR=y
# Bootloader config
-CONFIG_LOG_BOOTLOADER_LEVEL_WARN=y
+CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y
# ESP32-specific
CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y
@@ -21,10 +21,15 @@ CONFIG_PM_ENABLE=y
# FreeRTOS
CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=2
-CONFIG_SUPPORT_STATIC_ALLOCATION=y
-CONFIG_ENABLE_STATIC_TASK_CLEAN_UP_HOOK=y
+CONFIG_FREERTOS_SUPPORT_STATIC_ALLOCATION=y
+CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP=y
# UDP
CONFIG_PPP_SUPPORT=y
CONFIG_PPP_PAP_SUPPORT=y
CONFIG_PPP_CHAP_SUPPORT=y
+
+# v3.3-only (renamed in 4.0)
+CONFIG_LOG_BOOTLOADER_LEVEL_WARN=y
+CONFIG_SUPPORT_STATIC_ALLOCATION=y
+CONFIG_ENABLE_STATIC_TASK_CLEAN_UP_HOOK=y
diff --git a/ports/esp32/boards/sdkconfig.spiram b/ports/esp32/boards/sdkconfig.spiram
index 53950e587..db1a83af8 100644
--- a/ports/esp32/boards/sdkconfig.spiram
+++ b/ports/esp32/boards/sdkconfig.spiram
@@ -1,5 +1,9 @@
# MicroPython on ESP32, ESP IDF configuration with SPIRAM support
-CONFIG_SPIRAM_SUPPORT=y
+CONFIG_ESP32_SPIRAM_SUPPORT=y
+CONFIG_SPIRAM_CACHE_WORKAROUND=y
CONFIG_SPIRAM_IGNORE_NOTFOUND=y
CONFIG_SPIRAM_USE_MEMMAP=y
+
+# v3.3-only (renamed in 4.0)
+CONFIG_SPIRAM_SUPPORT=y
diff --git a/ports/esp32/esp32_ulp.c b/ports/esp32/esp32_ulp.c
index 3772639f4..bf11de330 100644
--- a/ports/esp32/esp32_ulp.c
+++ b/ports/esp32/esp32_ulp.c
@@ -85,7 +85,11 @@ STATIC const mp_rom_map_elem_t esp32_ulp_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_set_wakeup_period), MP_ROM_PTR(&esp32_ulp_set_wakeup_period_obj) },
{ MP_ROM_QSTR(MP_QSTR_load_binary), MP_ROM_PTR(&esp32_ulp_load_binary_obj) },
{ MP_ROM_QSTR(MP_QSTR_run), MP_ROM_PTR(&esp32_ulp_run_obj) },
+ #if !MICROPY_ESP_IDF_4
{ MP_ROM_QSTR(MP_QSTR_RESERVE_MEM), MP_ROM_INT(CONFIG_ULP_COPROC_RESERVE_MEM) },
+ #else
+ { MP_ROM_QSTR(MP_QSTR_RESERVE_MEM), MP_ROM_INT(CONFIG_ESP32_ULP_COPROC_RESERVE_MEM) },
+ #endif
};
STATIC MP_DEFINE_CONST_DICT(esp32_ulp_locals_dict, esp32_ulp_locals_dict_table);
diff --git a/ports/esp32/main.c b/ports/esp32/main.c
index c8dde337c..4d25cf0b3 100644
--- a/ports/esp32/main.c
+++ b/ports/esp32/main.c
@@ -37,7 +37,11 @@
#include "esp_task.h"
#include "soc/cpu.h"
#include "esp_log.h"
+#if MICROPY_ESP_IDF_4
+#include "esp32/spiram.h"
+#else
#include "esp_spiram.h"
+#endif
#include "py/stackctrl.h"
#include "py/nlr.h"
@@ -70,7 +74,7 @@ void mp_task(void *pvParameter) {
#endif
uart_init();
- #if CONFIG_SPIRAM_SUPPORT
+ #if CONFIG_ESP32_SPIRAM_SUPPORT
// Try to use the entire external SPIRAM directly for the heap
size_t mp_task_heap_size;
void *mp_task_heap = (void*)0x3f800000;
@@ -150,7 +154,11 @@ soft_reset:
}
void app_main(void) {
- nvs_flash_init();
+ esp_err_t ret = nvs_flash_init();
+ if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
+ nvs_flash_erase();
+ nvs_flash_init();
+ }
xTaskCreatePinnedToCore(mp_task, "mp_task", MP_TASK_STACK_LEN, NULL, MP_TASK_PRIORITY, &mp_main_task_handle, MP_TASK_COREID);
}
diff --git a/ports/esp32/modesp.c b/ports/esp32/modesp.c
index e614f77a6..9584b789d 100644
--- a/ports/esp32/modesp.c
+++ b/ports/esp32/modesp.c
@@ -29,7 +29,9 @@
#include <stdio.h>
+#if !MICROPY_ESP_IDF_4
#include "rom/gpio.h"
+#endif
#include "esp_log.h"
#include "esp_spi_flash.h"
diff --git a/ports/esp32/modmachine.c b/ports/esp32/modmachine.c
index fb864947d..0c803d096 100644
--- a/ports/esp32/modmachine.c
+++ b/ports/esp32/modmachine.c
@@ -32,9 +32,15 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
+#if MICROPY_ESP_IDF_4
+#include "esp32/rom/rtc.h"
+#include "esp32/clk.h"
+#include "esp_sleep.h"
+#else
#include "rom/ets_sys.h"
#include "rom/rtc.h"
#include "esp_clk.h"
+#endif
#include "esp_pm.h"
#include "driver/touch_pad.h"
diff --git a/ports/esp32/modnetwork.c b/ports/esp32/modnetwork.c
index 45ea5139c..012dc5bce 100644
--- a/ports/esp32/modnetwork.c
+++ b/ports/esp32/modnetwork.c
@@ -43,20 +43,23 @@
#include "netutils.h"
#include "esp_eth.h"
#include "esp_wifi.h"
-#include "esp_wifi_types.h"
#include "esp_log.h"
-#include "esp_event_loop.h"
#include "lwip/dns.h"
#include "tcpip_adapter.h"
#include "mdns.h"
+#if !MICROPY_ESP_IDF_4
+#include "esp_wifi_types.h"
+#include "esp_event_loop.h"
+#endif
+
#include "modnetwork.h"
#define MODNETWORK_INCLUDE_CONSTANTS (1)
NORETURN void _esp_exceptions(esp_err_t e) {
switch (e) {
- case ESP_ERR_WIFI_NOT_INIT:
+ case ESP_ERR_WIFI_NOT_INIT:
mp_raise_msg(&mp_type_OSError, "Wifi Not Initialized");
case ESP_ERR_WIFI_NOT_STARTED:
mp_raise_msg(&mp_type_OSError, "Wifi Not Started");
@@ -93,7 +96,7 @@ NORETURN void _esp_exceptions(esp_err_t e) {
case ESP_ERR_TCPIP_ADAPTER_DHCPC_START_FAILED:
mp_raise_msg(&mp_type_OSError, "TCP/IP DHCP Client Start Failed");
case ESP_ERR_TCPIP_ADAPTER_NO_MEM:
- mp_raise_OSError(MP_ENOMEM);
+ mp_raise_OSError(MP_ENOMEM);
default:
nlr_raise(mp_obj_new_exception_msg_varg(
&mp_type_RuntimeError, "Wifi Unknown Error 0x%04x", e
@@ -650,9 +653,12 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
ESP_EXCEPTIONS(esp_wifi_get_mac(self->if_id, mac));
return mp_obj_new_bytes(mac, sizeof(mac));
+ #if !MICROPY_ESP_IDF_4
case ESP_IF_ETH:
esp_eth_get_mac(mac);
return mp_obj_new_bytes(mac, sizeof(mac));
+ #endif
+
default:
goto unknown;
}
@@ -734,8 +740,10 @@ STATIC const mp_rom_map_elem_t mp_module_network_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_network) },
{ MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&esp_initialize_obj) },
{ MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&get_wlan_obj) },
+ #if !MICROPY_ESP_IDF_4
{ MP_ROM_QSTR(MP_QSTR_LAN), MP_ROM_PTR(&get_lan_obj) },
{ MP_ROM_QSTR(MP_QSTR_PPP), MP_ROM_PTR(&ppp_make_new_obj) },
+ #endif
{ MP_ROM_QSTR(MP_QSTR_phy_mode), MP_ROM_PTR(&esp_phy_mode_obj) },
#if MODNETWORK_INCLUDE_CONSTANTS
@@ -757,12 +765,14 @@ STATIC const mp_rom_map_elem_t mp_module_network_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_PHY_TLK110), MP_ROM_INT(PHY_TLK110) },
// ETH Clock modes from ESP-IDF
+ #if !MICROPY_ESP_IDF_4
{ MP_ROM_QSTR(MP_QSTR_ETH_CLOCK_GPIO0_IN), MP_ROM_INT(ETH_CLOCK_GPIO0_IN) },
// Disabled at Aug 22nd 2018, reenabled Jan 28th 2019 in ESP-IDF
// Because we use older SDK, it's currently disabled
//{ MP_ROM_QSTR(MP_QSTR_ETH_CLOCK_GPIO0_OUT), MP_ROM_INT(ETH_CLOCK_GPIO0_OUT) },
{ MP_ROM_QSTR(MP_QSTR_ETH_CLOCK_GPIO16_OUT), MP_ROM_INT(ETH_CLOCK_GPIO16_OUT) },
{ MP_ROM_QSTR(MP_QSTR_ETH_CLOCK_GPIO17_OUT), MP_ROM_INT(ETH_CLOCK_GPIO17_OUT) },
+ #endif
{ MP_ROM_QSTR(MP_QSTR_STAT_IDLE), MP_ROM_INT(STAT_IDLE)},
{ MP_ROM_QSTR(MP_QSTR_STAT_CONNECTING), MP_ROM_INT(STAT_CONNECTING)},
diff --git a/ports/esp32/modsocket.c b/ports/esp32/modsocket.c
index a6f29718d..e11af60e2 100644
--- a/ports/esp32/modsocket.c
+++ b/ports/esp32/modsocket.c
@@ -56,6 +56,18 @@
#include "lwip/igmp.h"
#include "esp_log.h"
+#if !MICROPY_ESP_IDF_4
+#define lwip_bind lwip_bind_r
+#define lwip_listen lwip_listen_r
+#define lwip_accept lwip_accept_r
+#define lwip_setsockopt lwip_setsockopt_r
+#define lwip_fnctl lwip_fnctl_r
+#define lwip_recvfrom lwip_recvfrom_r
+#define lwip_write lwip_write_r
+#define lwip_sendto lwip_sendto_r
+#define lwip_close lwip_close_r
+#endif
+
#define SOCKET_POLL_US (100000)
#define MDNS_QUERY_TIMEOUT_MS (5000)
#define MDNS_LOCAL_SUFFIX ".local"
@@ -277,17 +289,17 @@ STATIC mp_obj_t socket_bind(const mp_obj_t arg0, const mp_obj_t arg1) {
socket_obj_t *self = MP_OBJ_TO_PTR(arg0);
struct addrinfo *res;
_socket_getaddrinfo(arg1, &res);
- int r = lwip_bind_r(self->fd, res->ai_addr, res->ai_addrlen);
+ int r = lwip_bind(self->fd, res->ai_addr, res->ai_addrlen);
lwip_freeaddrinfo(res);
if (r < 0) exception_from_errno(errno);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind);
-
+
STATIC mp_obj_t socket_listen(const mp_obj_t arg0, const mp_obj_t arg1) {
socket_obj_t *self = MP_OBJ_TO_PTR(arg0);
int backlog = mp_obj_get_int(arg1);
- int r = lwip_listen_r(self->fd, backlog);
+ int r = lwip_listen(self->fd, backlog);
if (r < 0) exception_from_errno(errno);
return mp_const_none;
}
@@ -302,7 +314,7 @@ STATIC mp_obj_t socket_accept(const mp_obj_t arg0) {
int new_fd = -1;
for (int i=0; i<=self->retries; i++) {
MP_THREAD_GIL_EXIT();
- new_fd = lwip_accept_r(self->fd, &addr, &addr_len);
+ new_fd = lwip_accept(self->fd, &addr, &addr_len);
MP_THREAD_GIL_ENTER();
if (new_fd >= 0) break;
if (errno != EAGAIN) exception_from_errno(errno);
@@ -342,7 +354,7 @@ STATIC mp_obj_t socket_connect(const mp_obj_t arg0, const mp_obj_t arg1) {
struct addrinfo *res;
_socket_getaddrinfo(arg1, &res);
MP_THREAD_GIL_EXIT();
- int r = lwip_connect_r(self->fd, res->ai_addr, res->ai_addrlen);
+ int r = lwip_connect(self->fd, res->ai_addr, res->ai_addrlen);
MP_THREAD_GIL_ENTER();
lwip_freeaddrinfo(res);
if (r != 0) {
@@ -363,7 +375,7 @@ STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) {
// level: SOL_SOCKET
case SO_REUSEADDR: {
int val = mp_obj_get_int(args[3]);
- int ret = lwip_setsockopt_r(self->fd, SOL_SOCKET, opt, &val, sizeof(int));
+ int ret = lwip_setsockopt(self->fd, SOL_SOCKET, opt, &val, sizeof(int));
if (ret != 0) {
exception_from_errno(errno);
}
@@ -424,9 +436,9 @@ void _socket_settimeout(socket_obj_t *sock, uint64_t timeout_ms) {
.tv_sec = 0,
.tv_usec = timeout_ms ? SOCKET_POLL_US : 0
};
- lwip_setsockopt_r(sock->fd, SOL_SOCKET, SO_SNDTIMEO, (const void *)&timeout, sizeof(timeout));
- lwip_setsockopt_r(sock->fd, SOL_SOCKET, SO_RCVTIMEO, (const void *)&timeout, sizeof(timeout));
- lwip_fcntl_r(sock->fd, F_SETFL, timeout_ms ? 0 : O_NONBLOCK);
+ lwip_setsockopt(sock->fd, SOL_SOCKET, SO_SNDTIMEO, (const void *)&timeout, sizeof(timeout));
+ lwip_setsockopt(sock->fd, SOL_SOCKET, SO_RCVTIMEO, (const void *)&timeout, sizeof(timeout));
+ lwip_fcntl(sock->fd, F_SETFL, timeout_ms ? 0 : O_NONBLOCK);
}
STATIC mp_obj_t socket_settimeout(const mp_obj_t arg0, const mp_obj_t arg1) {
@@ -459,7 +471,7 @@ STATIC mp_uint_t _socket_read_data(mp_obj_t self_in, void *buf, size_t size,
socket_obj_t *sock = MP_OBJ_TO_PTR(self_in);
// If the peer closed the connection then the lwIP socket API will only return "0" once
- // from lwip_recvfrom_r and then block on subsequent calls. To emulate POSIX behaviour,
+ // from lwip_recvfrom and then block on subsequent calls. To emulate POSIX behaviour,
// which continues to return "0" for each call on a closed socket, we set a flag when
// the peer closed the socket.
if (sock->peer_closed) {
@@ -482,7 +494,7 @@ STATIC mp_uint_t _socket_read_data(mp_obj_t self_in, void *buf, size_t size,
if (release_gil) {
MP_THREAD_GIL_EXIT();
}
- int r = lwip_recvfrom_r(sock->fd, buf, size, 0, from, from_len);
+ int r = lwip_recvfrom(sock->fd, buf, size, 0, from, from_len);
if (release_gil) {
MP_THREAD_GIL_ENTER();
}
@@ -543,13 +555,13 @@ int _socket_send(socket_obj_t *sock, const char *data, size_t datalen) {
int sentlen = 0;
for (int i=0; i<=sock->retries && sentlen < datalen; i++) {
MP_THREAD_GIL_EXIT();
- int r = lwip_write_r(sock->fd, data+sentlen, datalen-sentlen);
+ int r = lwip_write(sock->fd, data+sentlen, datalen-sentlen);
MP_THREAD_GIL_ENTER();
if (r < 0 && errno != EWOULDBLOCK) exception_from_errno(errno);
if (r > 0) sentlen += r;
check_for_exceptions();
}
- if (sentlen == 0) mp_raise_OSError(MP_ETIMEDOUT);
+ if (sentlen == 0) mp_raise_OSError(MP_ETIMEDOUT);
return sentlen;
}
@@ -590,7 +602,7 @@ STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_
// send the data
for (int i=0; i<=self->retries; i++) {
MP_THREAD_GIL_EXIT();
- int ret = lwip_sendto_r(self->fd, bufinfo.buf, bufinfo.len, 0, (struct sockaddr*)&to, sizeof(to));
+ int ret = lwip_sendto(self->fd, bufinfo.buf, bufinfo.len, 0, (struct sockaddr*)&to, sizeof(to));
MP_THREAD_GIL_ENTER();
if (ret > 0) return mp_obj_new_int_from_uint(ret);
if (ret == -1 && errno != EWOULDBLOCK) {
@@ -598,7 +610,7 @@ STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_
}
check_for_exceptions();
}
- mp_raise_OSError(MP_ETIMEDOUT);
+ mp_raise_OSError(MP_ETIMEDOUT);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(socket_sendto_obj, socket_sendto);
@@ -622,7 +634,7 @@ STATIC mp_uint_t socket_stream_write(mp_obj_t self_in, const void *buf, mp_uint_
socket_obj_t *sock = self_in;
for (int i=0; i<=sock->retries; i++) {
MP_THREAD_GIL_EXIT();
- int r = lwip_write_r(sock->fd, buf, size);
+ int r = lwip_write(sock->fd, buf, size);
MP_THREAD_GIL_ENTER();
if (r > 0) return r;
if (r < 0 && errno != EWOULDBLOCK) { *errcode = errno; return MP_STREAM_ERROR; }
@@ -663,7 +675,7 @@ STATIC mp_uint_t socket_stream_ioctl(mp_obj_t self_in, mp_uint_t request, uintpt
socket->events_callback = MP_OBJ_NULL;
}
#endif
- int ret = lwip_close_r(socket->fd);
+ int ret = lwip_close(socket->fd);
if (ret != 0) {
*errcode = errno;
return MP_STREAM_ERROR;
@@ -731,7 +743,7 @@ STATIC mp_obj_t esp_socket_getaddrinfo(size_t n_args, const mp_obj_t *args) {
mp_obj_new_str(resi->ai_canonname, strlen(resi->ai_canonname)),
mp_const_none
};
-
+
if (resi->ai_family == AF_INET) {
struct sockaddr_in *addr = (struct sockaddr_in *)resi->ai_addr;
// This looks odd, but it's really just a u32_t
diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h
index cba319245..1c0d8700f 100644
--- a/ports/esp32/mpconfigport.h
+++ b/ports/esp32/mpconfigport.h
@@ -6,7 +6,10 @@
#include <stdint.h>
#include <alloca.h>
+
+#if !MICROPY_ESP_IDF_4
#include "rom/ets_sys.h"
+#endif
// object representation and NLR handling
#define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_A)
diff --git a/ports/esp32/mphalport.c b/ports/esp32/mphalport.c
index 0d1ea74d6..305e87593 100644
--- a/ports/esp32/mphalport.c
+++ b/ports/esp32/mphalport.c
@@ -31,7 +31,12 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
+
+#if MICROPY_ESP_IDF_4
+#include "esp32/rom/uart.h"
+#else
#include "rom/uart.h"
+#endif
#include "py/obj.h"
#include "py/stream.h"
diff --git a/ports/esp32/mpthreadport.c b/ports/esp32/mpthreadport.c
index 9557d4071..1c0d889e9 100644
--- a/ports/esp32/mpthreadport.c
+++ b/ports/esp32/mpthreadport.c
@@ -33,6 +33,9 @@
#include "mpthreadport.h"
#include "esp_task.h"
+#if !MICROPY_ESP_IDF_4
+#include "freertos/semphr.h"
+#endif
#if MICROPY_PY_THREAD
diff --git a/ports/esp32/network_lan.c b/ports/esp32/network_lan.c
index 100894b2e..291040797 100644
--- a/ports/esp32/network_lan.c
+++ b/ports/esp32/network_lan.c
@@ -26,6 +26,7 @@
* THE SOFTWARE.
*/
+#if !MICROPY_ESP_IDF_4
#include "py/runtime.h"
#include "py/mphal.h"
@@ -216,3 +217,5 @@ const mp_obj_type_t lan_if_type = {
.name = MP_QSTR_LAN,
.locals_dict = (mp_obj_dict_t*)&lan_if_locals_dict,
};
+
+#endif // !MICROPY_ESP_IDF_4
diff --git a/ports/esp32/network_ppp.c b/ports/esp32/network_ppp.c
index 1a14c09bf..d868450fd 100644
--- a/ports/esp32/network_ppp.c
+++ b/ports/esp32/network_ppp.c
@@ -26,6 +26,7 @@
* THE SOFTWARE.
*/
+#if !MICROPY_ESP_IDF_4
#include "py/runtime.h"
#include "py/mphal.h"
#include "py/objtype.h"
@@ -282,3 +283,5 @@ const mp_obj_type_t ppp_if_type = {
.name = MP_QSTR_PPP,
.locals_dict = (mp_obj_dict_t*)&ppp_if_locals_dict,
};
+
+#endif // !MICROPY_ESP_IDF_4