From 6d617b3b8cee06487813740ab1909208e9af139d Mon Sep 17 00:00:00 2001 From: zarya Date: Sat, 15 Nov 2014 17:51:04 +0100 Subject: [PATCH 1/9] changed blinky to realy blink --- blinky/user/user_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/blinky/user/user_main.c b/blinky/user/user_main.c index 80ba305..a21c035 100644 --- a/blinky/user/user_main.c +++ b/blinky/user/user_main.c @@ -2,6 +2,7 @@ #include "osapi.h" #include "gpio.h" #include "os_type.h" +#include "user_config.h" #define user_procTaskPrio 0 #define user_procTaskQueueLen 1 @@ -56,7 +57,7 @@ user_init() //&some_timer is the pointer //1000 is the fire time in ms //0 for once and 1 for repeating - os_timer_arm(&some_timer, 1000, 0); + os_timer_arm(&some_timer, 1000, 1); //Start os task system_os_task(user_procTask, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen); From 118aef2e4ef261e124e05e39c8eb6d415078da6e Mon Sep 17 00:00:00 2001 From: Tommie Gannert Date: Sat, 22 Nov 2014 16:19:52 +0000 Subject: [PATCH 2/9] Flash both images in one go. The esptool will start executing the image after it finishes. Also unify all Makefiles and ensure we do not use headers from the wrong architecture. --- basic_example/Makefile | 10 ++++------ blinky/Makefile | 10 ++++------ example.Makefile | 6 ++---- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/basic_example/Makefile b/basic_example/Makefile index 57e79c5..f3275bf 100644 --- a/basic_example/Makefile +++ b/basic_example/Makefile @@ -26,10 +26,10 @@ TARGET = app # which modules (subdirectories) of the project to include in compiling MODULES = driver user -EXTRA_INCDIR = include /usr/include /usr/include/i386-linux-gnu +EXTRA_INCDIR = include /opt/Espressif/include # libraries used in this project, mainly provided by the SDK -LIBS = c gcc hal phy net80211 lwip wpa main +LIBS = c gcc hal phy net80211 lwip wpa upgrade upgrade_ssl main # compiler flags using during compilation of source files CFLAGS = -Os -g -O2 -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH @@ -101,7 +101,7 @@ $1/%.o: %.c $(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@ endef -.PHONY: all checkdirs clean +.PHONY: all checkdirs flash clean all: checkdirs $(TARGET_OUT) $(FW_FILE_1) $(FW_FILE_2) @@ -130,9 +130,7 @@ firmware: $(Q) mkdir -p $@ flash: firmware/0x00000.bin firmware/0x40000.bin - -$(ESPTOOL) --port $(ESPPORT) write_flash 0x00000 firmware/0x00000.bin - sleep 3 - -$(ESPTOOL) --port $(ESPPORT) write_flash 0x40000 firmware/0x40000.bin + -$(ESPTOOL) --port $(ESPPORT) write_flash 0x00000 firmware/0x00000.bin 0x40000 firmware/0x40000.bin clean: $(Q) rm -f $(APP_AR) diff --git a/blinky/Makefile b/blinky/Makefile index 57e79c5..f3275bf 100644 --- a/blinky/Makefile +++ b/blinky/Makefile @@ -26,10 +26,10 @@ TARGET = app # which modules (subdirectories) of the project to include in compiling MODULES = driver user -EXTRA_INCDIR = include /usr/include /usr/include/i386-linux-gnu +EXTRA_INCDIR = include /opt/Espressif/include # libraries used in this project, mainly provided by the SDK -LIBS = c gcc hal phy net80211 lwip wpa main +LIBS = c gcc hal phy net80211 lwip wpa upgrade upgrade_ssl main # compiler flags using during compilation of source files CFLAGS = -Os -g -O2 -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH @@ -101,7 +101,7 @@ $1/%.o: %.c $(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@ endef -.PHONY: all checkdirs clean +.PHONY: all checkdirs flash clean all: checkdirs $(TARGET_OUT) $(FW_FILE_1) $(FW_FILE_2) @@ -130,9 +130,7 @@ firmware: $(Q) mkdir -p $@ flash: firmware/0x00000.bin firmware/0x40000.bin - -$(ESPTOOL) --port $(ESPPORT) write_flash 0x00000 firmware/0x00000.bin - sleep 3 - -$(ESPTOOL) --port $(ESPPORT) write_flash 0x40000 firmware/0x40000.bin + -$(ESPTOOL) --port $(ESPPORT) write_flash 0x00000 firmware/0x00000.bin 0x40000 firmware/0x40000.bin clean: $(Q) rm -f $(APP_AR) diff --git a/example.Makefile b/example.Makefile index f8eacd4..8e444c3 100644 --- a/example.Makefile +++ b/example.Makefile @@ -27,7 +27,7 @@ TARGET = app # which modules (subdirectories) of the project to include in compiling MODULES = driver user -EXTRA_INCDIR = include /opt/Espressif/include/ +EXTRA_INCDIR = include /opt/Espressif/include # libraries used in this project, mainly provided by the SDK LIBS = c gcc hal phy net80211 lwip wpa upgrade upgrade_ssl main @@ -131,9 +131,7 @@ firmware: $(Q) mkdir -p $@ flash: firmware/0x00000.bin firmware/0x40000.bin - -$(ESPTOOL) --port $(ESPPORT) write_flash 0x00000 firmware/0x00000.bin - sleep 3 - -$(ESPTOOL) --port $(ESPPORT) write_flash 0x40000 firmware/0x40000.bin + -$(ESPTOOL) --port $(ESPPORT) write_flash 0x00000 firmware/0x00000.bin 0x40000 firmware/0x40000.bin clean: $(Q) rm -f $(APP_AR) From 461e812417092146d1774144e998f8e9837c90d2 Mon Sep 17 00:00:00 2001 From: Tommie Gannert Date: Sat, 22 Nov 2014 16:21:27 +0000 Subject: [PATCH 3/9] Run gpio_init() and ensure GPIO2 is toggled in Blinky. Previously the if-statement was inverted so never actually changed anything. --- blinky/user/user_main.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/blinky/user/user_main.c b/blinky/user/user_main.c index a21c035..e0ca1d5 100644 --- a/blinky/user/user_main.c +++ b/blinky/user/user_main.c @@ -9,24 +9,21 @@ os_event_t user_procTaskQueue[user_procTaskQueueLen]; static void user_procTask(os_event_t *events); -extern uint32_t PIN_OUT; -#define CHECK_BIT(var,pos) ((var) & (1<<(pos))) - static volatile os_timer_t some_timer; void some_timerfunc(void *arg) { //Do blinky stuff - if (CHECK_BIT(PIN_OUT,2)) + if (GPIO_REG_READ(GPIO_OUT_ADDRESS) & BIT2) { - //Set GPIO2 to HIGH - gpio_output_set(BIT2, 0, BIT2, 0); + //Set GPIO2 to LOW + gpio_output_set(0, BIT2, BIT2, 0); } else { - //Set GPIO2 to LOW - gpio_output_set(0, BIT2, BIT2, 0); + //Set GPIO2 to HIGH + gpio_output_set(BIT2, 0, BIT2, 0); } } @@ -41,6 +38,9 @@ user_procTask(os_event_t *events) void ICACHE_FLASH_ATTR user_init() { + // Initialize the GPIO subsystem. + gpio_init(); + //Set GPIO2 to output mode PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2); From 3ddfa2df473b0a47b1067e7a86e910ddb76338fc Mon Sep 17 00:00:00 2001 From: zarya Date: Sun, 23 Nov 2014 12:32:39 +0100 Subject: [PATCH 4/9] Updated to SDK 0.9.3 (removed upgrade lib this is not needed --- basic_example/Makefile | 2 +- blinky/Makefile | 2 +- example.Makefile | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/basic_example/Makefile b/basic_example/Makefile index f3275bf..3340b12 100644 --- a/basic_example/Makefile +++ b/basic_example/Makefile @@ -29,7 +29,7 @@ MODULES = driver user EXTRA_INCDIR = include /opt/Espressif/include # libraries used in this project, mainly provided by the SDK -LIBS = c gcc hal phy net80211 lwip wpa upgrade upgrade_ssl main +LIBS = c gcc hal pp phy net80211 lwip wpa main # compiler flags using during compilation of source files CFLAGS = -Os -g -O2 -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH diff --git a/blinky/Makefile b/blinky/Makefile index f3275bf..3340b12 100644 --- a/blinky/Makefile +++ b/blinky/Makefile @@ -29,7 +29,7 @@ MODULES = driver user EXTRA_INCDIR = include /opt/Espressif/include # libraries used in this project, mainly provided by the SDK -LIBS = c gcc hal phy net80211 lwip wpa upgrade upgrade_ssl main +LIBS = c gcc hal pp phy net80211 lwip wpa main # compiler flags using during compilation of source files CFLAGS = -Os -g -O2 -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH diff --git a/example.Makefile b/example.Makefile index 8e444c3..e4c1f77 100644 --- a/example.Makefile +++ b/example.Makefile @@ -5,7 +5,7 @@ # # This make file still needs some work. # -# Updated for SDK 0.9.2 +# Updated for SDK 0.9.3 # # Output directors to store intermediate compiled files # relative to the project directory @@ -30,7 +30,7 @@ MODULES = driver user EXTRA_INCDIR = include /opt/Espressif/include # libraries used in this project, mainly provided by the SDK -LIBS = c gcc hal phy net80211 lwip wpa upgrade upgrade_ssl main +LIBS = c gcc hal pp phy net80211 lwip wpa main # compiler flags using during compilation of source files CFLAGS = -Os -g -O2 -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH From 132421c4933c0418632cdc465922d1b3beaee5d1 Mon Sep 17 00:00:00 2001 From: zarya Date: Thu, 4 Dec 2014 11:59:54 +0100 Subject: [PATCH 5/9] Fixed password lenght --- basic_example/user/user_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basic_example/user/user_main.c b/basic_example/user/user_main.c index f75f925..45e9132 100644 --- a/basic_example/user/user_main.c +++ b/basic_example/user/user_main.c @@ -32,7 +32,7 @@ user_init() //Set ap settings os_memcpy(&stationConf.ssid, ssid, 32); - os_memcpy(&stationConf.password, password, 32); + os_memcpy(&stationConf.password, password, 64); wifi_station_set_config(&stationConf); //Start os task From 43eaa85383e59bcc5f352025aae62c48f50adb86 Mon Sep 17 00:00:00 2001 From: George Hopkins Date: Thu, 25 Dec 2014 12:33:23 +0100 Subject: [PATCH 6/9] Replace esptool by esptool.py --- basic_example/Makefile | 63 +++++++++++++++++----------------------- blinky/Makefile | 63 +++++++++++++++++----------------------- example.Makefile | 66 ++++++++++++++++++------------------------ 3 files changed, 82 insertions(+), 110 deletions(-) diff --git a/basic_example/Makefile b/basic_example/Makefile index 3340b12..2eb212b 100644 --- a/basic_example/Makefile +++ b/basic_example/Makefile @@ -1,23 +1,29 @@ -# tnx to mamalala -# Changelog -# Changed the variables to include the header file directory -# Added global var for the XTENSA tool root -# -# This make file still needs some work. +# Makefile for ESP8266 projects # +# Thanks to: +# - zarya +# - Jeroen Domburg (Sprite_tm) +# - Christian Klippel (mamalala) +# - Tommie Gannert (tommie) # +# Changelog: +# - 2014-10-06: Changed the variables to include the header file directory +# - 2014-10-06: Added global var for the Xtensa tool root +# - 2014-11-23: Updated for SDK 0.9.3 +# - 2014-12-25: Replaced esptool by esptool.py + # Output directors to store intermediate compiled files # relative to the project directory BUILD_BASE = build FW_BASE = firmware -# Base directory for the compiler +# base directory for the compiler XTENSA_TOOLS_ROOT ?= /opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin # base directory of the ESP8266 SDK package, absolute SDK_BASE ?= /opt/Espressif/ESP8266_SDK -#Esptool.py path and port +# esptool.py path and port ESPTOOL ?= esptool.py ESPPORT ?= /dev/ttyUSB0 @@ -26,7 +32,7 @@ TARGET = app # which modules (subdirectories) of the project to include in compiling MODULES = driver user -EXTRA_INCDIR = include /opt/Espressif/include +EXTRA_INCDIR = include # libraries used in this project, mainly provided by the SDK LIBS = c gcc hal pp phy net80211 lwip wpa main @@ -47,10 +53,8 @@ SDK_INCDIR = include include/json # we create two different files for uploading into the flash # these are the names and options to generate them -FW_FILE_1 = 0x00000 -FW_FILE_1_ARGS = -bo $@ -bs .text -bs .data -bs .rodata -bc -ec -FW_FILE_2 = 0x40000 -FW_FILE_2_ARGS = -es .irom0.text $@ -ec +FW_FILE_1_ADDR = 0x00000 +FW_FILE_2_ADDR = 0x40000 # select which tools to use as compiler, librarian and linker CC := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc @@ -62,7 +66,6 @@ LD := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc #### #### no user configurable options below here #### -FW_TOOL ?= /usr/bin/esptool SRC_DIR := $(MODULES) BUILD_DIR := $(addprefix $(BUILD_BASE)/,$(MODULES)) @@ -81,8 +84,8 @@ INCDIR := $(addprefix -I,$(SRC_DIR)) EXTRA_INCDIR := $(addprefix -I,$(EXTRA_INCDIR)) MODULE_INCDIR := $(addsuffix /include,$(INCDIR)) -FW_FILE_1 := $(addprefix $(FW_BASE)/,$(FW_FILE_1).bin) -FW_FILE_2 := $(addprefix $(FW_BASE)/,$(FW_FILE_2).bin) +FW_FILE_1 := $(addprefix $(FW_BASE)/,$(FW_FILE_1_ADDR).bin) +FW_FILE_2 := $(addprefix $(FW_BASE)/,$(FW_FILE_2_ADDR).bin) V ?= $(VERBOSE) ifeq ("$(V)","1") @@ -98,20 +101,16 @@ vpath %.c $(SRC_DIR) define compile-objects $1/%.o: %.c $(vecho) "CC $$<" - $(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@ + $(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@ endef .PHONY: all checkdirs flash clean all: checkdirs $(TARGET_OUT) $(FW_FILE_1) $(FW_FILE_2) -$(FW_FILE_1): $(TARGET_OUT) - $(vecho) "FW $@" - $(Q) $(FW_TOOL) -eo $(TARGET_OUT) $(FW_FILE_1_ARGS) - -$(FW_FILE_2): $(TARGET_OUT) - $(vecho) "FW $@" - $(Q) $(FW_TOOL) -eo $(TARGET_OUT) $(FW_FILE_2_ARGS) +$(FW_BASE)/%.bin: $(TARGET_OUT) | $(FW_BASE) + $(vecho) "FW $(FW_BASE)/" + $(Q) $(ESPTOOL) elf2image -o $(FW_BASE)/ $(TARGET_OUT) $(TARGET_OUT): $(APP_AR) $(vecho) "LD $@" @@ -126,21 +125,13 @@ checkdirs: $(BUILD_DIR) $(FW_BASE) $(BUILD_DIR): $(Q) mkdir -p $@ -firmware: +$(FW_BASE): $(Q) mkdir -p $@ -flash: firmware/0x00000.bin firmware/0x40000.bin - -$(ESPTOOL) --port $(ESPPORT) write_flash 0x00000 firmware/0x00000.bin 0x40000 firmware/0x40000.bin +flash: $(FW_FILE_1) $(FW_FILE_2) + $(ESPTOOL) --port $(ESPPORT) write_flash $(FW_FILE_1_ADDR) $(FW_FILE_1) $(FW_FILE_2_ADDR) $(FW_FILE_2) clean: - $(Q) rm -f $(APP_AR) - $(Q) rm -f $(TARGET_OUT) - $(Q) rm -rf $(BUILD_DIR) - $(Q) rm -rf $(BUILD_BASE) - - - $(Q) rm -f $(FW_FILE_1) - $(Q) rm -f $(FW_FILE_2) - $(Q) rm -rf $(FW_BASE) + $(Q) rm -rf $(FW_BASE) $(BUILD_BASE) $(foreach bdir,$(BUILD_DIR),$(eval $(call compile-objects,$(bdir)))) diff --git a/blinky/Makefile b/blinky/Makefile index 3340b12..2eb212b 100644 --- a/blinky/Makefile +++ b/blinky/Makefile @@ -1,23 +1,29 @@ -# tnx to mamalala -# Changelog -# Changed the variables to include the header file directory -# Added global var for the XTENSA tool root -# -# This make file still needs some work. +# Makefile for ESP8266 projects # +# Thanks to: +# - zarya +# - Jeroen Domburg (Sprite_tm) +# - Christian Klippel (mamalala) +# - Tommie Gannert (tommie) # +# Changelog: +# - 2014-10-06: Changed the variables to include the header file directory +# - 2014-10-06: Added global var for the Xtensa tool root +# - 2014-11-23: Updated for SDK 0.9.3 +# - 2014-12-25: Replaced esptool by esptool.py + # Output directors to store intermediate compiled files # relative to the project directory BUILD_BASE = build FW_BASE = firmware -# Base directory for the compiler +# base directory for the compiler XTENSA_TOOLS_ROOT ?= /opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin # base directory of the ESP8266 SDK package, absolute SDK_BASE ?= /opt/Espressif/ESP8266_SDK -#Esptool.py path and port +# esptool.py path and port ESPTOOL ?= esptool.py ESPPORT ?= /dev/ttyUSB0 @@ -26,7 +32,7 @@ TARGET = app # which modules (subdirectories) of the project to include in compiling MODULES = driver user -EXTRA_INCDIR = include /opt/Espressif/include +EXTRA_INCDIR = include # libraries used in this project, mainly provided by the SDK LIBS = c gcc hal pp phy net80211 lwip wpa main @@ -47,10 +53,8 @@ SDK_INCDIR = include include/json # we create two different files for uploading into the flash # these are the names and options to generate them -FW_FILE_1 = 0x00000 -FW_FILE_1_ARGS = -bo $@ -bs .text -bs .data -bs .rodata -bc -ec -FW_FILE_2 = 0x40000 -FW_FILE_2_ARGS = -es .irom0.text $@ -ec +FW_FILE_1_ADDR = 0x00000 +FW_FILE_2_ADDR = 0x40000 # select which tools to use as compiler, librarian and linker CC := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc @@ -62,7 +66,6 @@ LD := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc #### #### no user configurable options below here #### -FW_TOOL ?= /usr/bin/esptool SRC_DIR := $(MODULES) BUILD_DIR := $(addprefix $(BUILD_BASE)/,$(MODULES)) @@ -81,8 +84,8 @@ INCDIR := $(addprefix -I,$(SRC_DIR)) EXTRA_INCDIR := $(addprefix -I,$(EXTRA_INCDIR)) MODULE_INCDIR := $(addsuffix /include,$(INCDIR)) -FW_FILE_1 := $(addprefix $(FW_BASE)/,$(FW_FILE_1).bin) -FW_FILE_2 := $(addprefix $(FW_BASE)/,$(FW_FILE_2).bin) +FW_FILE_1 := $(addprefix $(FW_BASE)/,$(FW_FILE_1_ADDR).bin) +FW_FILE_2 := $(addprefix $(FW_BASE)/,$(FW_FILE_2_ADDR).bin) V ?= $(VERBOSE) ifeq ("$(V)","1") @@ -98,20 +101,16 @@ vpath %.c $(SRC_DIR) define compile-objects $1/%.o: %.c $(vecho) "CC $$<" - $(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@ + $(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@ endef .PHONY: all checkdirs flash clean all: checkdirs $(TARGET_OUT) $(FW_FILE_1) $(FW_FILE_2) -$(FW_FILE_1): $(TARGET_OUT) - $(vecho) "FW $@" - $(Q) $(FW_TOOL) -eo $(TARGET_OUT) $(FW_FILE_1_ARGS) - -$(FW_FILE_2): $(TARGET_OUT) - $(vecho) "FW $@" - $(Q) $(FW_TOOL) -eo $(TARGET_OUT) $(FW_FILE_2_ARGS) +$(FW_BASE)/%.bin: $(TARGET_OUT) | $(FW_BASE) + $(vecho) "FW $(FW_BASE)/" + $(Q) $(ESPTOOL) elf2image -o $(FW_BASE)/ $(TARGET_OUT) $(TARGET_OUT): $(APP_AR) $(vecho) "LD $@" @@ -126,21 +125,13 @@ checkdirs: $(BUILD_DIR) $(FW_BASE) $(BUILD_DIR): $(Q) mkdir -p $@ -firmware: +$(FW_BASE): $(Q) mkdir -p $@ -flash: firmware/0x00000.bin firmware/0x40000.bin - -$(ESPTOOL) --port $(ESPPORT) write_flash 0x00000 firmware/0x00000.bin 0x40000 firmware/0x40000.bin +flash: $(FW_FILE_1) $(FW_FILE_2) + $(ESPTOOL) --port $(ESPPORT) write_flash $(FW_FILE_1_ADDR) $(FW_FILE_1) $(FW_FILE_2_ADDR) $(FW_FILE_2) clean: - $(Q) rm -f $(APP_AR) - $(Q) rm -f $(TARGET_OUT) - $(Q) rm -rf $(BUILD_DIR) - $(Q) rm -rf $(BUILD_BASE) - - - $(Q) rm -f $(FW_FILE_1) - $(Q) rm -f $(FW_FILE_2) - $(Q) rm -rf $(FW_BASE) + $(Q) rm -rf $(FW_BASE) $(BUILD_BASE) $(foreach bdir,$(BUILD_DIR),$(eval $(call compile-objects,$(bdir)))) diff --git a/example.Makefile b/example.Makefile index e4c1f77..2eb212b 100644 --- a/example.Makefile +++ b/example.Makefile @@ -1,24 +1,29 @@ -# tnx to mamalala -# Changelog -# Changed the variables to include the header file directory -# Added global var for the XTENSA tool root +# Makefile for ESP8266 projects # -# This make file still needs some work. -# -# Updated for SDK 0.9.3 +# Thanks to: +# - zarya +# - Jeroen Domburg (Sprite_tm) +# - Christian Klippel (mamalala) +# - Tommie Gannert (tommie) # +# Changelog: +# - 2014-10-06: Changed the variables to include the header file directory +# - 2014-10-06: Added global var for the Xtensa tool root +# - 2014-11-23: Updated for SDK 0.9.3 +# - 2014-12-25: Replaced esptool by esptool.py + # Output directors to store intermediate compiled files # relative to the project directory BUILD_BASE = build FW_BASE = firmware -# Base directory for the compiler +# base directory for the compiler XTENSA_TOOLS_ROOT ?= /opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin # base directory of the ESP8266 SDK package, absolute SDK_BASE ?= /opt/Espressif/ESP8266_SDK -#Esptool.py path and port +# esptool.py path and port ESPTOOL ?= esptool.py ESPPORT ?= /dev/ttyUSB0 @@ -27,7 +32,7 @@ TARGET = app # which modules (subdirectories) of the project to include in compiling MODULES = driver user -EXTRA_INCDIR = include /opt/Espressif/include +EXTRA_INCDIR = include # libraries used in this project, mainly provided by the SDK LIBS = c gcc hal pp phy net80211 lwip wpa main @@ -48,10 +53,8 @@ SDK_INCDIR = include include/json # we create two different files for uploading into the flash # these are the names and options to generate them -FW_FILE_1 = 0x00000 -FW_FILE_1_ARGS = -bo $@ -bs .text -bs .data -bs .rodata -bc -ec -FW_FILE_2 = 0x40000 -FW_FILE_2_ARGS = -es .irom0.text $@ -ec +FW_FILE_1_ADDR = 0x00000 +FW_FILE_2_ADDR = 0x40000 # select which tools to use as compiler, librarian and linker CC := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc @@ -63,7 +66,6 @@ LD := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc #### #### no user configurable options below here #### -FW_TOOL ?= /usr/bin/esptool SRC_DIR := $(MODULES) BUILD_DIR := $(addprefix $(BUILD_BASE)/,$(MODULES)) @@ -82,8 +84,8 @@ INCDIR := $(addprefix -I,$(SRC_DIR)) EXTRA_INCDIR := $(addprefix -I,$(EXTRA_INCDIR)) MODULE_INCDIR := $(addsuffix /include,$(INCDIR)) -FW_FILE_1 := $(addprefix $(FW_BASE)/,$(FW_FILE_1).bin) -FW_FILE_2 := $(addprefix $(FW_BASE)/,$(FW_FILE_2).bin) +FW_FILE_1 := $(addprefix $(FW_BASE)/,$(FW_FILE_1_ADDR).bin) +FW_FILE_2 := $(addprefix $(FW_BASE)/,$(FW_FILE_2_ADDR).bin) V ?= $(VERBOSE) ifeq ("$(V)","1") @@ -99,20 +101,16 @@ vpath %.c $(SRC_DIR) define compile-objects $1/%.o: %.c $(vecho) "CC $$<" - $(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@ + $(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@ endef -.PHONY: all checkdirs clean +.PHONY: all checkdirs flash clean all: checkdirs $(TARGET_OUT) $(FW_FILE_1) $(FW_FILE_2) -$(FW_FILE_1): $(TARGET_OUT) - $(vecho) "FW $@" - $(Q) $(FW_TOOL) -eo $(TARGET_OUT) $(FW_FILE_1_ARGS) - -$(FW_FILE_2): $(TARGET_OUT) - $(vecho) "FW $@" - $(Q) $(FW_TOOL) -eo $(TARGET_OUT) $(FW_FILE_2_ARGS) +$(FW_BASE)/%.bin: $(TARGET_OUT) | $(FW_BASE) + $(vecho) "FW $(FW_BASE)/" + $(Q) $(ESPTOOL) elf2image -o $(FW_BASE)/ $(TARGET_OUT) $(TARGET_OUT): $(APP_AR) $(vecho) "LD $@" @@ -127,21 +125,13 @@ checkdirs: $(BUILD_DIR) $(FW_BASE) $(BUILD_DIR): $(Q) mkdir -p $@ -firmware: +$(FW_BASE): $(Q) mkdir -p $@ -flash: firmware/0x00000.bin firmware/0x40000.bin - -$(ESPTOOL) --port $(ESPPORT) write_flash 0x00000 firmware/0x00000.bin 0x40000 firmware/0x40000.bin +flash: $(FW_FILE_1) $(FW_FILE_2) + $(ESPTOOL) --port $(ESPPORT) write_flash $(FW_FILE_1_ADDR) $(FW_FILE_1) $(FW_FILE_2_ADDR) $(FW_FILE_2) clean: - $(Q) rm -f $(APP_AR) - $(Q) rm -f $(TARGET_OUT) - $(Q) rm -rf $(BUILD_DIR) - $(Q) rm -rf $(BUILD_BASE) - - - $(Q) rm -f $(FW_FILE_1) - $(Q) rm -f $(FW_FILE_2) - $(Q) rm -rf $(FW_BASE) + $(Q) rm -rf $(FW_BASE) $(BUILD_BASE) $(foreach bdir,$(BUILD_DIR),$(eval $(call compile-objects,$(bdir)))) From a1ef21cd613b59e9f75c3e1d669f0d397f434a63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Zabalza?= Date: Fri, 27 Feb 2015 04:41:44 +0100 Subject: [PATCH 7/9] Interrupt example Basic example to set a interrupt input --- interrupt_example/.gitignore | 3 + interrupt_example/Makefile | 149 ++++++++++++++++++++++++ interrupt_example/user/user_config.h | 0 interrupt_example/user/user_main.c | 165 +++++++++++++++++++++++++++ 4 files changed, 317 insertions(+) create mode 100644 interrupt_example/.gitignore create mode 100644 interrupt_example/Makefile create mode 100644 interrupt_example/user/user_config.h create mode 100644 interrupt_example/user/user_main.c diff --git a/interrupt_example/.gitignore b/interrupt_example/.gitignore new file mode 100644 index 0000000..9623423 --- /dev/null +++ b/interrupt_example/.gitignore @@ -0,0 +1,3 @@ +build +firmware +testinterrupt.* diff --git a/interrupt_example/Makefile b/interrupt_example/Makefile new file mode 100644 index 0000000..728e812 --- /dev/null +++ b/interrupt_example/Makefile @@ -0,0 +1,149 @@ +# tnx to mamalala +# Changelog +# Changed the variables to include the header file directory +# Added global var for the XTENSA tool root +# Added variable for esptool bauds. Some modules don't work with default speed. +# +# This make file still needs some work. +# +# Updated for SDK 0.9.3 +# +# Output directors to store intermediate compiled files +# relative to the project directory +BUILD_BASE = build +FW_BASE = firmware + +# Base directory for the compiler +XTENSA_TOOLS_ROOT ?= /opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin + +# base directory of the ESP8266 SDK package, absolute +SDK_BASE ?= /opt/Espressif/ESP8266_SDK + +#Esptool.py path and port +ESPTOOL ?= esptool.py +ESPPORT ?= /dev/ttyUSB0 +ESPBAUD ?= 115200 + +# name for the target project +TARGET = app + +# which modules (subdirectories) of the project to include in compiling +MODULES = driver user +EXTRA_INCDIR = include /opt/Espressif/include + +# libraries used in this project, mainly provided by the SDK +LIBS = c gcc hal pp phy net80211 lwip wpa main + +# compiler flags using during compilation of source files +CFLAGS = -Os -g -O2 -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH + +# linker flags used to generate the main object file +LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static + +# linker script used for the above linkier step +LD_SCRIPT = eagle.app.v6.ld + +# various paths from the SDK used in this project +SDK_LIBDIR = lib +SDK_LDDIR = ld +SDK_INCDIR = include include/json + +# we create two different files for uploading into the flash +# these are the names and options to generate them +FW_FILE_1 = 0x00000 +FW_FILE_1_ARGS = -bo $@ -bs .text -bs .data -bs .rodata -bc -ec +FW_FILE_2 = 0x40000 +FW_FILE_2_ARGS = -es .irom0.text $@ -ec + +# select which tools to use as compiler, librarian and linker +CC := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc +AR := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-ar +LD := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc + + + +#### +#### no user configurable options below here +#### +FW_TOOL ?= /usr/bin/esptool +SRC_DIR := $(MODULES) +BUILD_DIR := $(addprefix $(BUILD_BASE)/,$(MODULES)) + +SDK_LIBDIR := $(addprefix $(SDK_BASE)/,$(SDK_LIBDIR)) +SDK_INCDIR := $(addprefix -I$(SDK_BASE)/,$(SDK_INCDIR)) + +SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c)) +OBJ := $(patsubst %.c,$(BUILD_BASE)/%.o,$(SRC)) +LIBS := $(addprefix -l,$(LIBS)) +APP_AR := $(addprefix $(BUILD_BASE)/,$(TARGET)_app.a) +TARGET_OUT := $(addprefix $(BUILD_BASE)/,$(TARGET).out) + +LD_SCRIPT := $(addprefix -T$(SDK_BASE)/$(SDK_LDDIR)/,$(LD_SCRIPT)) + +INCDIR := $(addprefix -I,$(SRC_DIR)) +EXTRA_INCDIR := $(addprefix -I,$(EXTRA_INCDIR)) +MODULE_INCDIR := $(addsuffix /include,$(INCDIR)) + +FW_FILE_1 := $(addprefix $(FW_BASE)/,$(FW_FILE_1).bin) +FW_FILE_2 := $(addprefix $(FW_BASE)/,$(FW_FILE_2).bin) + +V ?= $(VERBOSE) +ifeq ("$(V)","1") +Q := +vecho := @true +else +Q := @ +vecho := @echo +endif + +vpath %.c $(SRC_DIR) + +define compile-objects +$1/%.o: %.c + $(vecho) "CC $$<" + $(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@ +endef + +.PHONY: all checkdirs flash clean + +all: checkdirs $(TARGET_OUT) $(FW_FILE_1) $(FW_FILE_2) + +$(FW_FILE_1): $(TARGET_OUT) + $(vecho) "FW $@" + $(Q) $(FW_TOOL) -eo $(TARGET_OUT) $(FW_FILE_1_ARGS) + +$(FW_FILE_2): $(TARGET_OUT) + $(vecho) "FW $@" + $(Q) $(FW_TOOL) -eo $(TARGET_OUT) $(FW_FILE_2_ARGS) + +$(TARGET_OUT): $(APP_AR) + $(vecho) "LD $@" + $(Q) $(LD) -L$(SDK_LIBDIR) $(LD_SCRIPT) $(LDFLAGS) -Wl,--start-group $(LIBS) $(APP_AR) -Wl,--end-group -o $@ + +$(APP_AR): $(OBJ) + $(vecho) "AR $@" + $(Q) $(AR) cru $@ $^ + +checkdirs: $(BUILD_DIR) $(FW_BASE) + +$(BUILD_DIR): + $(Q) mkdir -p $@ + +firmware: + $(Q) mkdir -p $@ + +flash: firmware/0x00000.bin firmware/0x40000.bin + -$(ESPTOOL) --baud $(ESPBAUD) --port $(ESPPORT) write_flash 0x00000 firmware/0x00000.bin 0x40000 firmware/0x40000.bin + +clean: + $(Q) rm -f $(APP_AR) + $(Q) rm -f $(TARGET_OUT) + $(Q) rm -rf $(BUILD_DIR) + $(Q) rm -rf $(BUILD_BASE) + + + $(Q) rm -f $(FW_FILE_1) + $(Q) rm -f $(FW_FILE_2) + $(Q) rm -rf $(FW_BASE) + +$(foreach bdir,$(BUILD_DIR),$(eval $(call compile-objects,$(bdir)))) diff --git a/interrupt_example/user/user_config.h b/interrupt_example/user/user_config.h new file mode 100644 index 0000000..e69de29 diff --git a/interrupt_example/user/user_main.c b/interrupt_example/user/user_main.c new file mode 100644 index 0000000..a9f4ef8 --- /dev/null +++ b/interrupt_example/user/user_main.c @@ -0,0 +1,165 @@ +#include "ets_sys.h" +#include "osapi.h" +#include "gpio.h" +#include "os_type.h" +#include "user_interface.h" + +#define user_procTaskPrio 0 +#define user_procTaskQueueLen 1 +os_event_t user_procTaskQueue[user_procTaskQueueLen]; +static void loop(os_event_t *events); + + +// variable modified indirectly by interrupt handler +volatile int whatyouwant; + +// gpio interrupt handler. See below +LOCAL void gpio_intr_handler(int * dummy); + +//------------------------------------------------------------------------------------------------- +// loop function will be execute by "os" periodically +static void ICACHE_FLASH_ATTR loop(os_event_t *events) +{ + static int level; + + os_printf("What you want %d \r\n",whatyouwant); +// change GPIO 2 level + level = !level; + GPIO_OUTPUT_SET(GPIO_ID_PIN(2), ((level) ? 1 : 0)); +// Delay + os_delay_us(100000); +// turn again + system_os_post(user_procTaskPrio, 0, 0 ); +} + +//------------------------------------------------------------------------------------------------- +//Init function +void ICACHE_FLASH_ATTR user_init() +{ + +// Initialize UART0 to use as debug + uart_div_modify(0, UART_CLK_FREQ / 9600); + + os_printf( + "GPIO Interrupt ESP8266 test\r\n" + "---------------------------\r\n" + " This program out a square wave on gpio2 and count edges for gpio0\r\n" + " The program report count edges gpio0 periodically.\r\n" + " You Can\r\n" + " 1.- Connect GPIO0 to GPIO2 so you can see increment count edge periodically\r\n" + " 2.- Unconnect GPIO0 from GPIO2 so you can see stop count edge\r\n" + " 3.- Connect GPIO0 to ground to increment count edge\r\n" +); + +// ================================================= +// Initialize GPIO2 and GPIO0 as GPIO +// ================================================= +// +// +// PIN_FUNC_SELECT() defined in eagle_soc.h +// PERIPHS_IO_MUX_... for each pin defined in eagle_soc.h +// FUNC_... for each PERIPHS macros defined in eagle_soc.h +// +// From eagle_soc.h: +// GPIO0 only can be GPIO +// GPIO2 can be GPIO, TXD from uart0, or TXD from uart1 +// +// #define PERIPHS_IO_MUX_GPIO0_U (PERIPHS_IO_MUX + 0x34) +// #define FUNC_GPIO0 0 +// #define PERIPHS_IO_MUX_GPIO2_U (PERIPHS_IO_MUX + 0x38) +// #define FUNC_GPIO2 0 +// #define FUNC_U1TXD_BK 2 +// #define FUNC_U0TXD_BK 4 +// + + PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0); + PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2); + +// You can select enable/disable internal pullup/pulldown for each pin +// +// PIN_PULLUP_DIS(PIN_NAME) +// PIN_PULLUP_EN(PIN_NAME) +// PIN_PULLDWN_DIS(PIN_NAME) +// PIN_PULLDWN_EN(PIN_NAME) + + PIN_PULLUP_DIS(PERIPHS_IO_MUX_GPIO0_U); + PIN_PULLDWN_DIS(PERIPHS_IO_MUX_GPIO0_U); + PIN_PULLUP_EN(PERIPHS_IO_MUX_GPIO2_U); + +// +// void gpio_output_set(uint32 set_mask, uint32 clear_mask, uint32 enable_mask, uint32 disable_mask) +// +// set status and direction pin by mask gpio id pin. + + gpio_output_set(0, GPIO_ID_PIN(2), GPIO_ID_PIN(2), GPIO_ID_PIN(0)); // set gpio 2 as output and low. set gpio 0 as input + +// ================================================= +// Activate gpio interrupt for gpio2 +// ================================================= + + // Disable interrupts by GPIO + ETS_GPIO_INTR_DISABLE(); + +// Attach interrupt handle to gpio interrupts. +// You can set a void pointer that will be passed to interrupt handler each interrupt + + ETS_GPIO_INTR_ATTACH(gpio_intr_handler, &whatyouwant); + +// void gpio_register_set(uint32 reg_id, uint32 value); +// +// From include file +// Set the specified GPIO register to the specified value. +// This is a very general and powerful interface that is not +// expected to be used during normal operation. It is intended +// mainly for debug, or for unusual requirements. +// +// All people repeat this mantra but I don't know what it means +// + gpio_register_set(GPIO_PIN_ADDR(0), + GPIO_PIN_INT_TYPE_SET(GPIO_PIN_INTR_DISABLE) | + GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_DISABLE) | + GPIO_PIN_SOURCE_SET(GPIO_AS_PIN_SOURCE)); + +// clear gpio status. Say ESP8266EX SDK Programming Guide in 5.1.6. GPIO interrupt handler + + GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(0)); + +// enable interrupt for his GPIO +// GPIO_PIN_INTR_... defined in gpio.h + + gpio_pin_intr_state_set(GPIO_ID_PIN(0), GPIO_PIN_INTR_ANYEGDE); + + ETS_GPIO_INTR_ENABLE(); + + //Start os task + system_os_task(loop, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen); + + system_os_post(user_procTaskPrio, 0, 0 ); +} + +//------------------------------------------------------------------------------------------------- +// interrupt handler +// this function will be executed on any edge of GPIO0 +LOCAL void gpio_intr_handler(int * dummy) +{ +// clear gpio status. Say ESP8266EX SDK Programming Guide in 5.1.6. GPIO interrupt handler + + uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS); + +// if the interrupt was by GPIO0 + if (gpio_status & BIT(0)) + { +// disable interrupt for GPIO0 + gpio_pin_intr_state_set(GPIO_ID_PIN(0), GPIO_PIN_INTR_DISABLE); + +// Do something, for example, increment whatyouwant indirectly + (*dummy)++; + +//clear interrupt status for GPIO0 + GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status & BIT(0)); + +// Reactivate interrupts for GPIO0 + gpio_pin_intr_state_set(GPIO_ID_PIN(0), GPIO_PIN_INTR_ANYEGDE); + } +} + From 17e65300ebc95377ad7de6a4b997543fe77f9800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Zabalza?= Date: Thu, 5 Mar 2015 06:19:40 +0100 Subject: [PATCH 8/9] Add gpio initialization --- interrupt_example/user/user_main.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/interrupt_example/user/user_main.c b/interrupt_example/user/user_main.c index a9f4ef8..f591bee 100644 --- a/interrupt_example/user/user_main.c +++ b/interrupt_example/user/user_main.c @@ -51,6 +51,9 @@ void ICACHE_FLASH_ATTR user_init() " 3.- Connect GPIO0 to ground to increment count edge\r\n" ); +// Initialize the GPIO subsystem. + gpio_init(); + // ================================================= // Initialize GPIO2 and GPIO0 as GPIO // ================================================= From 6cc718d3f2fb5203237897b05f4a2ac05769219b Mon Sep 17 00:00:00 2001 From: Ron Battles Date: Sun, 26 Jul 2015 23:12:07 -0500 Subject: [PATCH 9/9] Adding example for connecting to dweet.io and sending some JSON "thing data". --- dweet/Makefile | 137 ++++++++++++++++++++++++++++++++++ dweet/user/user_config.h | 0 dweet/user/user_main.c | 156 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 293 insertions(+) create mode 100644 dweet/Makefile create mode 100644 dweet/user/user_config.h create mode 100644 dweet/user/user_main.c diff --git a/dweet/Makefile b/dweet/Makefile new file mode 100644 index 0000000..de908bc --- /dev/null +++ b/dweet/Makefile @@ -0,0 +1,137 @@ +# Makefile for ESP8266 projects +# +# Thanks to: +# - zarya +# - Jeroen Domburg (Sprite_tm) +# - Christian Klippel (mamalala) +# - Tommie Gannert (tommie) +# +# Changelog: +# - 2014-10-06: Changed the variables to include the header file directory +# - 2014-10-06: Added global var for the Xtensa tool root +# - 2014-11-23: Updated for SDK 0.9.3 +# - 2014-12-25: Replaced esptool by esptool.py + +# Output directors to store intermediate compiled files +# relative to the project directory +BUILD_BASE = build +FW_BASE = firmware + +# base directory for the compiler +XTENSA_TOOLS_ROOT ?= /home/rbattles/nas/work/esp-open-sdk/xtensa-lx106-elf/bin + +# base directory of the ESP8266 SDK package, absolute +SDK_BASE ?= /home/rbattles/nas/work/esp-open-sdk/esp_iot_sdk_v1.2.0 + +# esptool.py path and port +ESPTOOL ?= esptool.py +ESPPORT ?= /dev/ttyUSB0 + +# name for the target project +TARGET = dweet + +# which modules (subdirectories) of the project to include in compiling +MODULES = driver user +EXTRA_INCDIR = include + +# libraries used in this project, mainly provided by the SDK +LIBS = c gcc hal pp phy net80211 lwip wpa main + +# compiler flags using during compilation of source files +CFLAGS = -Os -g -O2 -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH + +# linker flags used to generate the main object file +LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static + +# linker script used for the above linkier step +LD_SCRIPT = eagle.app.v6.ld + +# various paths from the SDK used in this project +SDK_LIBDIR = lib +SDK_LDDIR = ld +SDK_INCDIR = include include/json + +# we create two different files for uploading into the flash +# these are the names and options to generate them +FW_FILE_1_ADDR = 0x00000 +FW_FILE_2_ADDR = 0x40000 + +# select which tools to use as compiler, librarian and linker +CC := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc +AR := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-ar +LD := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc + + + +#### +#### no user configurable options below here +#### +SRC_DIR := $(MODULES) +BUILD_DIR := $(addprefix $(BUILD_BASE)/,$(MODULES)) + +SDK_LIBDIR := $(addprefix $(SDK_BASE)/,$(SDK_LIBDIR)) +SDK_INCDIR := $(addprefix -I$(SDK_BASE)/,$(SDK_INCDIR)) + +SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c)) +OBJ := $(patsubst %.c,$(BUILD_BASE)/%.o,$(SRC)) +LIBS := $(addprefix -l,$(LIBS)) +APP_AR := $(addprefix $(BUILD_BASE)/,$(TARGET)_app.a) +TARGET_OUT := $(addprefix $(BUILD_BASE)/,$(TARGET).out) + +LD_SCRIPT := $(addprefix -T$(SDK_BASE)/$(SDK_LDDIR)/,$(LD_SCRIPT)) + +INCDIR := $(addprefix -I,$(SRC_DIR)) +EXTRA_INCDIR := $(addprefix -I,$(EXTRA_INCDIR)) +MODULE_INCDIR := $(addsuffix /include,$(INCDIR)) + +FW_FILE_1 := $(addprefix $(FW_BASE)/,$(FW_FILE_1_ADDR).bin) +FW_FILE_2 := $(addprefix $(FW_BASE)/,$(FW_FILE_2_ADDR).bin) + +V ?= $(VERBOSE) +ifeq ("$(V)","1") +Q := +vecho := @true +else +Q := @ +vecho := @echo +endif + +vpath %.c $(SRC_DIR) + +define compile-objects +$1/%.o: %.c + $(vecho) "CC $$<" + $(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@ +endef + +.PHONY: all checkdirs flash clean + +all: checkdirs $(TARGET_OUT) $(FW_FILE_1) $(FW_FILE_2) + +$(FW_BASE)/%.bin: $(TARGET_OUT) | $(FW_BASE) + $(vecho) "FW $(FW_BASE)/" + $(Q) $(ESPTOOL) elf2image -o $(FW_BASE)/ $(TARGET_OUT) + +$(TARGET_OUT): $(APP_AR) + $(vecho) "LD $@" + $(Q) $(LD) -L$(SDK_LIBDIR) $(LD_SCRIPT) $(LDFLAGS) -Wl,--start-group $(LIBS) $(APP_AR) -Wl,--end-group -o $@ + +$(APP_AR): $(OBJ) + $(vecho) "AR $@" + $(Q) $(AR) cru $@ $^ + +checkdirs: $(BUILD_DIR) $(FW_BASE) + +$(BUILD_DIR): + $(Q) mkdir -p $@ + +$(FW_BASE): + $(Q) mkdir -p $@ + +flash: $(FW_FILE_1) $(FW_FILE_2) + $(ESPTOOL) --port $(ESPPORT) write_flash $(FW_FILE_1_ADDR) $(FW_FILE_1) $(FW_FILE_2_ADDR) $(FW_FILE_2) + +clean: + $(Q) rm -rf $(FW_BASE) $(BUILD_BASE) + +$(foreach bdir,$(BUILD_DIR),$(eval $(call compile-objects,$(bdir)))) diff --git a/dweet/user/user_config.h b/dweet/user/user_config.h new file mode 100644 index 0000000..e69de29 diff --git a/dweet/user/user_main.c b/dweet/user/user_main.c new file mode 100644 index 0000000..4422dcb --- /dev/null +++ b/dweet/user/user_main.c @@ -0,0 +1,156 @@ +#include "ets_sys.h" +#include "osapi.h" +#include "gpio.h" +#include "os_type.h" +#include "ip_addr.h" +#include "espconn.h" +#include "user_interface.h" +#include "user_config.h" + + +struct espconn dweet_conn; +ip_addr_t dweet_ip; +esp_tcp dweet_tcp; + +char dweet_host[] = "dweet.io"; +char dweet_path[] = "/dweet/for/eccd882c-33d0-11e5-96b7-10bf4884d1f9"; +char json_data[ 256 ]; +char buffer[ 2048 ]; + + +void user_rf_pre_init( void ) +{ +} + + +void data_received( void *arg, char *pdata, unsigned short len ) +{ + struct espconn *conn = arg; + + os_printf( "%s: %s\n", __FUNCTION__, pdata ); + + espconn_disconnect( conn ); +} + + +void tcp_connected( void *arg ) +{ + int temperature = 55; // test data + struct espconn *conn = arg; + + os_printf( "%s\n", __FUNCTION__ ); + espconn_regist_recvcb( conn, data_received ); + + os_sprintf( json_data, "{\"temperature\": \"%d\" }", temperature ); + os_sprintf( buffer, "POST %s HTTP/1.1\r\nHost: %s\r\nConnection: close\r\nContent-Type: application/json\r\nContent-Length: %d\r\n\r\n%s", + dweet_path, dweet_host, os_strlen( json_data ), json_data ); + + os_printf( "Sending: %s\n", buffer ); + espconn_sent( conn, buffer, os_strlen( buffer ) ); +} + + +void tcp_disconnected( void *arg ) +{ + struct espconn *conn = arg; + + os_printf( "%s\n", __FUNCTION__ ); + wifi_station_disconnect(); +} + + +void dns_done( const char *name, ip_addr_t *ipaddr, void *arg ) +{ + struct espconn *conn = arg; + + os_printf( "%s\n", __FUNCTION__ ); + + if ( ipaddr == NULL) + { + os_printf("DNS lookup failed\n"); + wifi_station_disconnect(); + } + else + { + os_printf("Connecting...\n" ); + + conn->type = ESPCONN_TCP; + conn->state = ESPCONN_NONE; + conn->proto.tcp=&dweet_tcp; + conn->proto.tcp->local_port = espconn_port(); + conn->proto.tcp->remote_port = 80; + os_memcpy( conn->proto.tcp->remote_ip, &ipaddr->addr, 4 ); + + espconn_regist_connectcb( conn, tcp_connected ); + espconn_regist_disconcb( conn, tcp_disconnected ); + + espconn_connect( conn ); + } +} + + +void wifi_callback( System_Event_t *evt ) +{ + os_printf( "%s: %d\n", __FUNCTION__, evt->event ); + + switch ( evt->event ) + { + case EVENT_STAMODE_CONNECTED: + { + os_printf("connect to ssid %s, channel %d\n", + evt->event_info.connected.ssid, + evt->event_info.connected.channel); + break; + } + + case EVENT_STAMODE_DISCONNECTED: + { + os_printf("disconnect from ssid %s, reason %d\n", + evt->event_info.disconnected.ssid, + evt->event_info.disconnected.reason); + + deep_sleep_set_option( 0 ); + system_deep_sleep( 60 * 1000 * 1000 ); // 60 seconds + break; + } + + case EVENT_STAMODE_GOT_IP: + { + os_printf("ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR, + IP2STR(&evt->event_info.got_ip.ip), + IP2STR(&evt->event_info.got_ip.mask), + IP2STR(&evt->event_info.got_ip.gw)); + os_printf("\n"); + + espconn_gethostbyname( &dweet_conn, dweet_host, &dweet_ip, dns_done ); + break; + } + + default: + { + break; + } + } +} + + +void user_init( void ) +{ + static struct station_config config; + + uart_div_modify( 0, UART_CLK_FREQ / ( 115200 ) ); + os_printf( "%s\n", __FUNCTION__ ); + + wifi_station_set_hostname( "dweet" ); + wifi_set_opmode_current( STATION_MODE ); + + gpio_init(); + + config.bssid_set = 0; + os_memcpy( &config.ssid, "AndiceLabs", 32 ); + os_memcpy( &config.password, "password", 64 ); + wifi_station_set_config( &config ); + + wifi_set_event_handler_cb( wifi_callback ); +} +