diff --git a/.gitmodules b/.gitmodules index fde876f64f..f0eae41c30 100644 --- a/.gitmodules +++ b/.gitmodules @@ -24,3 +24,6 @@ path = Sming/third-party/umm_malloc url = https://github.com/rhempel/umm_malloc.git ignore = dirty +[submodule "Sming/third-party/esp-open-lwip"] + path = Sming/third-party/esp-open-lwip + url = https://github.com/pfalcon/esp-open-lwip.git diff --git a/.travis.yml b/.travis.yml index 58f263750b..2bec8efc1f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,12 +30,17 @@ script: - export ESP_HOME=$TRAVIS_BUILD_DIR/opt/esp-alt-sdk - export PATH=$PATH:$TRAVIS_BUILD_DIR/opt/esp-alt-sdk/utils/ - cd $SMING_HOME - - make test + - make test - cd $SMING_HOME/../ - export SMING_HAS_CHANGED=`for i in $CHANGED_FILES; do if [[ $i == Sming/* ]]; then echo 1; break; fi; done` - if [ ! -z "$SMING_HAS_CHANGED" ]; then CHANGED_PROJECTS=`cd $SMING_HOME/../samples; ls -d *`; fi - for i in $CHANGED_PROJECTS; do echo "Compiling $i"; make -C "samples/$i"; if [ $? -ne 0 ]; then exit 1; fi; done - cd $SMING_HOME - - make clean + - make clean samples-clean - make ENABLE_GDB=1 - make Basic_Debug + - make clean samples-clean + - make ENABLE_CUSTOM_HEAP=1 + - make Basic_Blink ENABLE_CUSTOM_HEAP=1 + - make clean samples-clean + - if [ "$SDK_VERSION" == "1.5.0" ]; then make ENABLE_CUSTOM_LWIP=1; make samples ENABLE_CUSTOM_LWIP=1; fi diff --git a/Readme.md b/Readme.md index bdb712cbbf..87a85d79c3 100644 --- a/Readme.md +++ b/Readme.md @@ -31,7 +31,7 @@ Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native develo * Based on Espressif NONOS SDK. Tested with versions 1.4 and 1.5. ## Latest Release -- [Sming V3.0.0](https://github.com/SmingHub/Sming/releases/tag/3.0.0) +- [Sming V3.0.1](https://github.com/SmingHub/Sming/releases/tag/3.0.1) ## Getting started - [Windows](https://github.com/SmingHub/Sming/wiki/Windows-Quickstart) diff --git a/Sming/Makefile b/Sming/Makefile index 703dc73880..172dfa4877 100644 --- a/Sming/Makefile +++ b/Sming/Makefile @@ -150,10 +150,19 @@ ifeq ($(ENABLE_CUSTOM_HEAP), 1) CUSTOM_TARGETS += $(USER_LIBDIR)/libmainmm.a endif +# => Open Source LWIP +LIBLWIP = lwip +ENABLE_ESPCONN ?= 1 +ifeq ($(ENABLE_CUSTOM_LWIP), 1) + THIRD_PARTY_DATA += third-party/esp-open-lwip/Makefile.open + EXTRA_INCDIR += third-party/esp-open-lwip/include + CUSTOM_TARGETS += $(USER_LIBDIR)/liblwip_open.a + LIBLWIP = lwip_open +endif + # libraries used in this project, mainly provided by the SDK USER_LIBDIR = compiler/lib -LIBS = microc microgcc hal phy pp net80211 lwip wpa main - +LIBS = microc microgcc hal phy pp net80211 $(LIBLWIP) wpa main ifeq ($(ENABLE_CUSTOM_PWM), 1) THIRD_PARTY_DATA += third-party/pwm/pwm.c LIBS += pwm @@ -296,6 +305,12 @@ $(USER_LIBDIR)/libmainmm.a: $(addprefix $(SDK_LIBDIR)/,libmain.a) $(Q) $(AR) -d $@ mem_manager.o endif +ifeq ($(ENABLE_CUSTOM_LWIP), 1) +$(USER_LIBDIR)/liblwip_open.a: third-party/esp-open-lwip/Makefile.open + $(Q) $(MAKE) -C third-party/esp-open-lwip/ -f Makefile.open ENABLE_ESPCONN=$(ENABLE_ESPCONN) USER_LIBDIR=$(SMING_HOME)/$(USER_LIBDIR)/ +endif + + spiffy: spiffy/spiffy spiffy/spiffy: @@ -338,7 +353,7 @@ else $(Q) $(MAKE) --no-print-directory -C spiffy clean V=$(V) endif -test: all spiffy samples +test: Basic_Blink Basic_rBoot Basic_Ssl Basic_HwPWM docs/wiki/Home.md: $(vecho) "No Wiki submodule found. Using git to fetch it..." diff --git a/Sming/Makefile-project.mk b/Sming/Makefile-project.mk index dd22a06ce4..3ee1bbc59d 100644 --- a/Sming/Makefile-project.mk +++ b/Sming/Makefile-project.mk @@ -137,16 +137,23 @@ TARGET = app THIRD_PARTY_DIR = $(SMING_HOME)/third-party +SMING_FEATURES = none LIBSMING = sming ifeq ($(ENABLE_SSL),1) LIBSMING = smingssl + SMING_FEATURES = SSL endif # which modules (subdirectories) of the project to include in compiling # define your custom directories in the project's own Makefile before including this one MODULES ?= app # default to app if not set by user EXTRA_INCDIR ?= include # default to include if not set by user -EXTRA_INCDIR += $(SMING_HOME)/include $(SMING_HOME)/ $(SMING_HOME)/system/include $(SMING_HOME)/Wiring $(SMING_HOME)/Libraries $(SMING_HOME)/SmingCore $(SMING_HOME)/Services/SpifFS $(SDK_BASE)/../include $(THIRD_PARTY_DIR)/rboot $(THIRD_PARTY_DIR)/rboot/appcode $(THIRD_PARTY_DIR)/spiffs/src + +ifeq ($(ENABLE_CUSTOM_LWIP), 1) + LWIP_INCDIR = $(SMING_HOME)/third-party/esp-open-lwip +endif + +EXTRA_INCDIR += $(SMING_HOME)/include $(SMING_HOME)/ $(LWIP_INCDIR) $(SMING_HOME)/system/include $(SMING_HOME)/Wiring $(SMING_HOME)/Libraries $(SMING_HOME)/SmingCore $(SMING_HOME)/Services/SpifFS $(SDK_BASE)/../include $(THIRD_PARTY_DIR)/rboot $(THIRD_PARTY_DIR)/rboot/appcode $(THIRD_PARTY_DIR)/spiffs/src ENABLE_CUSTOM_HEAP ?= 0 @@ -155,9 +162,14 @@ ifeq ($(ENABLE_CUSTOM_HEAP),1) LIBMAIN = mainmm endif +LIBLWIP = lwip +ifeq ($(ENABLE_CUSTOM_LWIP), 1) + LIBLWIP = lwip_open +endif + # libraries used in this project, mainly provided by the SDK USER_LIBDIR = $(SMING_HOME)/compiler/lib/ -LIBS = microc microgcc hal phy pp net80211 lwip wpa $(LIBMAIN) $(LIBSMING) crypto pwm smartconfig $(EXTRA_LIBS) +LIBS = microc microgcc hal phy pp net80211 $(LIBLWIP) wpa $(LIBMAIN) $(LIBSMING) crypto pwm smartconfig $(EXTRA_LIBS) # compiler flags using during compilation of source files CFLAGS = -Wpointer-arith -Wundef -Werror -Wl,-EL -nostdlib -mlongcalls -mtext-section-literals -finline-functions -fdata-sections -ffunction-sections -D__ets__ -DICACHE_FLASH -DARDUINO=106 -DCOM_SPEED_SERIAL=$(COM_SPEED_SERIAL) $(USER_CFLAGS) @@ -185,11 +197,16 @@ ifeq ($(ENABLE_SSL),1) AXTLS_FLAGS += -DSSL_DEBUG=1 -DDEBUG_TLS_MEM=1 endif - CUSTOM_TARGETS += $(USER_LIBDIR)/lib$(LIBSMING).a include/ssl/private_key.h + CUSTOM_TARGETS += include/ssl/private_key.h CFLAGS += $(AXTLS_FLAGS) CXXFLAGS += $(AXTLS_FLAGS) endif +ifeq ($(ENABLE_CUSTOM_LWIP), 1) + CUSTOM_TARGETS += $(USER_LIBDIR)/liblwip_open.a +# EXTRA_INCDIR += third-party/esp-open-lwip/include +endif + # we will use global WiFi settings from Eclipse Environment Variables, if possible WIFI_SSID ?= "" WIFI_PWD ?= "" @@ -313,7 +330,7 @@ endef .PHONY: all checkdirs spiff_update spiff_clean clean -all: checkdirs $(TARGET_OUT) $(SPIFF_BIN_OUT) $(FW_FILE_1) $(FW_FILE_2) +all: $(USER_LIBDIR)/lib$(LIBSMING).a checkdirs $(TARGET_OUT) $(SPIFF_BIN_OUT) $(FW_FILE_1) $(FW_FILE_2) spiff_update: spiff_clean $(SPIFF_BIN_OUT) @@ -352,7 +369,7 @@ $(APP_AR): $(OBJ) $(Q) $(AR) cru $@ $^ $(USER_LIBDIR)/lib$(LIBSMING).a: - $(vecho) "Recompiling Sming with SSL support. This may take some time" + $(vecho) "(Re)compiling Sming. Enabled features: $(SMING_FEATURES). This may take some time" $(Q) $(MAKE) -C $(SMING_HOME) clean V=$(V) ENABLE_SSL=$(ENABLE_SSL) SMING_HOME=$(SMING_HOME) $(Q) $(MAKE) -C $(SMING_HOME) V=$(V) ENABLE_SSL=$(ENABLE_SSL) SMING_HOME=$(SMING_HOME) @@ -366,6 +383,11 @@ $(USER_LIBDIR)/libpwm.a: $(Q) $(MAKE) -C $(SMING_HOME) compiler/lib/libpwm.a ENABLE_CUSTOM_PWM=1 endif +ifeq ($(ENABLE_CUSTOM_LWIP), 1) +$(USER_LIBDIR)/liblwip_open.a: + $(Q) $(MAKE) -C $(SMING_HOME) compiler/lib/liblwip_open.a ENABLE_CUSTOM_LWIP=1 +endif + checkdirs: $(BUILD_DIR) $(FW_BASE) $(CUSTOM_TARGETS) $(BUILD_DIR): diff --git a/Sming/Makefile-rboot.mk b/Sming/Makefile-rboot.mk index c520ff71e3..f18c9e3c7d 100644 --- a/Sming/Makefile-rboot.mk +++ b/Sming/Makefile-rboot.mk @@ -139,8 +139,10 @@ TARGET = app THIRD_PARTY_DIR = $(SMING_HOME)/third-party LIBSMING = sming +SMING_FEATURES = none ifeq ($(ENABLE_SSL),1) LIBSMING = smingssl + SMING_FEATURES = SSL endif # which modules (subdirectories) of the project to include in compiling @@ -148,7 +150,12 @@ endif MODULES ?= app # default to app if not set by user MODULES += $(THIRD_PARTY_DIR)/rboot/appcode EXTRA_INCDIR ?= include # default to include if not set by user -EXTRA_INCDIR += $(SMING_HOME)/include $(SMING_HOME)/ $(SMING_HOME)/system/include $(SMING_HOME)/Wiring $(SMING_HOME)/Libraries $(SMING_HOME)/SmingCore $(SMING_HOME)/Services/SpifFS $(SDK_BASE)/../include $(THIRD_PARTY_DIR)/rboot $(THIRD_PARTY_DIR)/rboot/appcode $(THIRD_PARTY_DIR)/spiffs/src + +ifeq ($(ENABLE_CUSTOM_LWIP), 1) + LWIP_INCDIR = $(SMING_HOME)/third-party/esp-open-lwip +endif + +EXTRA_INCDIR += $(SMING_HOME)/include $(SMING_HOME)/ $(LWIP_INCDIR) $(SMING_HOME)/system/include $(SMING_HOME)/Wiring $(SMING_HOME)/Libraries $(SMING_HOME)/SmingCore $(SMING_HOME)/Services/SpifFS $(SDK_BASE)/../include $(THIRD_PARTY_DIR)/rboot $(THIRD_PARTY_DIR)/rboot/appcode $(THIRD_PARTY_DIR)/spiffs/src USER_LIBDIR = $(SMING_HOME)/compiler/lib/ @@ -194,7 +201,12 @@ else endif # libraries used in this project, mainly provided by the SDK -LIBS = microc microgcc hal phy pp net80211 lwip wpa $(LIBMAIN) $(LIBSMING) crypto pwm smartconfig $(EXTRA_LIBS) +LIBLWIP = lwip +ifeq ($(ENABLE_CUSTOM_LWIP), 1) + LIBLWIP = lwip_open +endif + +LIBS = microc microgcc hal phy pp net80211 $(LIBLWIP) wpa $(LIBMAIN) $(LIBSMING) crypto pwm smartconfig $(EXTRA_LIBS) # SSL support using axTLS ifeq ($(ENABLE_SSL),1) @@ -205,11 +217,16 @@ ifeq ($(ENABLE_SSL),1) AXTLS_FLAGS += -DSSL_DEBUG=1 -DDEBUG_TLS_MEM=1 endif - CUSTOM_TARGETS += $(USER_LIBDIR)/lib$(LIBSMING).a include/ssl/private_key.h + CUSTOM_TARGETS += include/ssl/private_key.h CFLAGS += $(AXTLS_FLAGS) CXXFLAGS += $(AXTLS_FLAGS) endif +ifeq ($(ENABLE_CUSTOM_LWIP), 1) + EXTRA_INCDIR += third-party/esp-open-lwip/include +endif + + # we will use global WiFi settings from Eclipse Environment Variables, if possible WIFI_SSID ?= "" WIFI_PWD ?= "" @@ -357,7 +374,7 @@ endef .PHONY: all checkdirs spiff_update spiff_clean clean -all: checkdirs $(LIBMAIN_DST) $(RBOOT_BIN) $(RBOOT_ROM_0) $(RBOOT_ROM_1) $(SPIFF_BIN_OUT) $(FW_FILE_1) $(FW_FILE_2) +all: $(USER_LIBDIR)/lib$(LIBSMING).a checkdirs $(LIBMAIN_DST) $(RBOOT_BIN) $(RBOOT_ROM_0) $(RBOOT_ROM_1) $(SPIFF_BIN_OUT) $(FW_FILE_1) $(FW_FILE_2) $(RBOOT_BIN): $(MAKE) -C $(THIRD_PARTY_DIR)/rboot @@ -392,7 +409,7 @@ $(APP_AR): $(OBJ) $(Q) $(AR) cru $@ $^ $(USER_LIBDIR)/lib$(LIBSMING).a: - $(vecho) "Recompiling Sming with SSL support. This may take some time" + $(vecho) "(Re)compiling Sming. Enabled features: $(SMING_FEATURES). This may take some time" $(Q) $(MAKE) -C $(SMING_HOME) clean V=$(V) ENABLE_SSL=$(ENABLE_SSL) SMING_HOME=$(SMING_HOME) $(Q) $(MAKE) -C $(SMING_HOME) V=$(V) ENABLE_SSL=$(ENABLE_SSL) SMING_HOME=$(SMING_HOME) diff --git a/Sming/SmingCore/Network/WebsocketClient.cpp b/Sming/SmingCore/Network/WebsocketClient.cpp index b35ef4f377..51e5da233e 100644 --- a/Sming/SmingCore/Network/WebsocketClient.cpp +++ b/Sming/SmingCore/Network/WebsocketClient.cpp @@ -47,7 +47,7 @@ bool WebsocketClient::connect(String url, uint32_t sslOptions /* = 0 */) char b64Key[25]; _mode = wsMode::Connecting; // Server Connected / WS Upgrade request sent - randomSeed(analogRead(0)); + randomSeed(os_random()); for (int i = 0; i < 16; ++i) { @@ -56,10 +56,8 @@ bool WebsocketClient::connect(String url, uint32_t sslOptions /* = 0 */) base64_encode(16, (const unsigned char*) keyStart, 24, (char*) b64Key); - for (int i = 0; i < 24; ++i) - { - _key[i] = b64Key[i]; - } + _key.setString(b64Key, 24); + String protocol = "chat"; sendString("GET "); if (_uri.Path != "") diff --git a/Sming/SmingCore/SmingCore.h b/Sming/SmingCore/SmingCore.h index 6c667d1f0d..633e2fa8b0 100644 --- a/Sming/SmingCore/SmingCore.h +++ b/Sming/SmingCore/SmingCore.h @@ -8,7 +8,7 @@ #ifndef _NET_WIRING_ #define _NET_WIRING_ -#define SMING_VERSION "3.0.0" // Major Minor Sub +#define SMING_VERSION "3.0.1" // Major Minor Sub #include "../Wiring/WiringFrameworkIncludes.h" diff --git a/Sming/custom_heap/heap.c b/Sming/custom_heap/heap.c new file mode 100644 index 0000000000..9fc0a97d21 --- /dev/null +++ b/Sming/custom_heap/heap.c @@ -0,0 +1,51 @@ +/* heap.c - overrides of SDK heap handling functions + * Copyright (c) 2016 Ivan Grokhotkov. All rights reserved. + * This file is distributed under MIT license. + */ + +#include +#include +#include "umm_malloc_cfg.h" +#include "umm_malloc.h" + +#define IRAM_ATTR __attribute__((section(".iram.text"))) + +void* IRAM_ATTR pvPortMalloc(size_t size, const char* file, int line) +{ + return malloc(size); +} + +void IRAM_ATTR vPortFree(void *ptr, const char* file, int line) +{ + free(ptr); +} + +void* IRAM_ATTR pvPortCalloc(size_t count, size_t size, const char* file, int line) +{ + return calloc(count, size); +} + +void* IRAM_ATTR pvPortRealloc(void *ptr, size_t size, const char* file, int line) +{ + return realloc(ptr, size); +} + +void* IRAM_ATTR pvPortZalloc(size_t size, const char* file, int line) +{ + return calloc(1, size); +} + +size_t xPortGetFreeHeapSize(void) +{ + return umm_free_heap_size(); +} + +size_t IRAM_ATTR xPortWantedSizeAlign(size_t size) +{ + return (size + 3) & ~((size_t) 3); +} + +void system_show_malloc(void) +{ + umm_info(NULL, 1); +} diff --git a/Sming/third-party/.patches/esp-open-lwip.patch b/Sming/third-party/.patches/esp-open-lwip.patch new file mode 100644 index 0000000000..b549ad696a --- /dev/null +++ b/Sming/third-party/.patches/esp-open-lwip.patch @@ -0,0 +1,69 @@ +diff --git a/include/user_config.h b/include/user_config.h +index e69de29..1db5073 100644 +--- a/include/user_config.h ++++ b/include/user_config.h +@@ -0,0 +1,34 @@ ++#ifdef __cplusplus ++extern "C" { ++#endif ++ ++typedef signed short sint16_t; ++ ++void *ets_bzero(void *block, size_t size); ++bool ets_post(uint32_t prio, ETSSignal sig, ETSParam par); ++void ets_task(ETSTask task, uint32_t prio, ETSEvent * queue, uint8 qlen); ++ ++void system_pp_recycle_rx_pkt(void *eb); ++ ++#ifndef MEMLEAK_DEBUG ++ extern void *pvPortMalloc( size_t xWantedSize ); ++ extern void vPortFree( void *pv ); ++ extern void *pvPortZalloc(size_t size); ++#else ++ extern void *pvPortMalloc(size_t xWantedSize, const char *file, uint32 line); ++ extern void *pvPortZalloc(size_t xWantedSize, const char *file, uint32 line); ++ extern void vPortFree(void *ptr, const char *file, uint32 line); ++ ++ extern void pvPortFree(void *ptr); ++ extern void *vPortMalloc(size_t xWantedSize); ++#endif /*MEMLEAK_DEBUG*/ ++ ++ ++ extern void *pvPortCalloc(unsigned int n, unsigned int count); ++ extern void *pvPortRealloc(void * p, size_t size); ++ extern size_t xPortGetFreeHeapSize(void); ++// extern void prvHeapInit(void) ICACHE_FLASH_ATTR ; ++ ++#ifdef __cplusplus ++} ++#endif +diff --git a/Makefile.open b/Makefile.open +index 1bc584f..493275b 100644 +--- a/Makefile.open ++++ b/Makefile.open +@@ -36,11 +36,21 @@ lwip/core/ipv4/ip.o \ + lwip/core/ipv4/ip_frag.o \ + lwip/netif/etharp.o \ + \ +-lwip/app/dhcpserver.o \ +-\ +-espconn_dummy.o \ ++lwip/app/dhcpserver.o ++ ++ ++ifneq ($(ENABLE_ESPCONN),1) ++ OBJS += espconn_dummy.o ++else ++ OBJS += lwip/app/espconn.o \ ++lwip/app/espconn_tcp.o \ ++lwip/app/espconn_udp.o \ ++lwip/app/espconn_mdns.o \ ++lwip/core/mdns.o ++ ++endif + +-LIB = liblwip_open.a ++LIB = $(USER_LIBDIR)liblwip_open.a + + all: $(LIB) + diff --git a/Sming/third-party/esp-open-lwip b/Sming/third-party/esp-open-lwip new file mode 160000 index 0000000000..b9a23a6e9e --- /dev/null +++ b/Sming/third-party/esp-open-lwip @@ -0,0 +1 @@ +Subproject commit b9a23a6e9ef88d995ae74014e71a6a4227f61d62 diff --git a/samples/ScreenTFT_ILI9340-ILI9341/app/application.cpp b/samples/ScreenTFT_ILI9340-ILI9341/app/application.cpp index 98520cb3a1..789058e6bd 100644 --- a/samples/ScreenTFT_ILI9340-ILI9341/app/application.cpp +++ b/samples/ScreenTFT_ILI9340-ILI9341/app/application.cpp @@ -85,6 +85,10 @@ void init() //WifiStation.config(WIFI_SSID, WIFI_PWD); WifiStation.enable(false); WifiAccessPoint.enable(false); + + spiffs_mount(); + Serial.println("FileSystem mounted."); + // delay(2000); Serial.println("Display start");