Skip to content

Commit

Permalink
Added experimental support for SDK 2.1 (#1264)
Browse files Browse the repository at this point in the history
In order to use SDK 2.1 you should set one environment variable before compiling Sming and applications based on it.  The variable is SDK_BASE and it should point to `$SMING_HOME/third-party/ESP8266_NONOS_SDK`.

For Windows you need to do:
```
set SDK_BASE %SMING_HOME%//third-party/ESP8266_NONOS_SDK
```

For Linux(bash) you need to do:
```
export SDK_BASE="$SMING_HOME/third-party/ESP8266_NONOS_SDK"
```

Read the comments from this URL for known issues:
#1264
  • Loading branch information
slaff authored Nov 23, 2017
1 parent f1e685f commit c2cc852
Show file tree
Hide file tree
Showing 18 changed files with 188 additions and 55 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@
path = Sming/third-party/lwip2
url = https://github.com/d-a-v/esp82xx-nonos-linklayer.git
ignore = dirty
[submodule "Sming/third-party/ESP8266_NONOS_SDK"]
path = Sming/third-party/ESP8266_NONOS_SDK
url = https://github.com/espressif/ESP8266_NONOS_SDK.git
ignore = dirty
13 changes: 8 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ matrix:
env: SDK_VERSION=1.5.0
- os: linux
env: SDK_VERSION=2.0.0
- os: linux
env: SDK_VERSION=2.1.0

git:
submodules: false
Expand All @@ -29,19 +31,20 @@ addons:
- graphviz

install:
- if [ "$SDK_VERSION" != "2.0.0" ] && [ "$TRAVIS_OS_NAME" == "osx" ]; then export SDK_FILE_NAME="esp-alt-sdk-v${SDK_VERSION}.${SDK_BUILD}-macos-x86_64.zip"; fi
- if [ "$SDK_VERSION" != "2.0.0" ] && [ "$TRAVIS_OS_NAME" == "linux" ]; then export SDK_FILE_NAME="esp-alt-sdk-v${SDK_VERSION}.${SDK_BUILD}-linux-x86_64.tar.gz"; fi
- if [ "$SDK_VERSION" == "1.5.0" ] && [ "$TRAVIS_OS_NAME" == "osx" ]; then export SDK_FILE_NAME="esp-alt-sdk-v${SDK_VERSION}.${SDK_BUILD}-macos-x86_64.zip"; fi
- if [ "$SDK_VERSION" == "1.5.0" ] && [ "$TRAVIS_OS_NAME" == "linux" ]; then export SDK_FILE_NAME="esp-alt-sdk-v${SDK_VERSION}.${SDK_BUILD}-linux-x86_64.tar.gz"; fi
- mkdir -p $TRAVIS_BUILD_DIR/opt/esp-alt-sdk
- if [ "$SDK_VERSION" != "2.0.0" ]; then wget https://bintray.com/artifact/download/kireevco/generic/${SDK_FILE_NAME}; fi
- if [ "$SDK_VERSION" != "2.0.0" ]; then bsdtar -xf ${SDK_FILE_NAME} -C $TRAVIS_BUILD_DIR/opt/esp-alt-sdk; fi
- if [ "$SDK_VERSION" == "2.0.0" ] && [ "$TRAVIS_OS_NAME" == "linux" ]; then wget https://github.com/nodemcu/nodemcu-firmware/raw/master/tools/esp-open-sdk.tar.xz; tar -Jxvf esp-open-sdk.tar.xz; ln -s `pwd`/esp-open-sdk/xtensa-lx106-elf $TRAVIS_BUILD_DIR/opt/esp-alt-sdk/. ; fi
- if [ "$SDK_VERSION" == "1.5.0" ]; then wget https://bintray.com/artifact/download/kireevco/generic/${SDK_FILE_NAME}; fi
- if [ "$SDK_VERSION" == "1.5.0" ]; then bsdtar -xf ${SDK_FILE_NAME} -C $TRAVIS_BUILD_DIR/opt/esp-alt-sdk; fi
- if [[ "$SDK_VERSION" != "1.5.0" && "$TRAVIS_OS_NAME" == "linux" ]]; then wget https://github.com/nodemcu/nodemcu-firmware/raw/master/tools/esp-open-sdk.tar.xz; tar -Jxvf esp-open-sdk.tar.xz; ln -s `pwd`/esp-open-sdk/xtensa-lx106-elf $TRAVIS_BUILD_DIR/opt/esp-alt-sdk/. ; fi
- if [ "$SDK_VERSION" == "2.0.0" ] && [ "$TRAVIS_OS_NAME" == "linux" ]; then wget http://bbs.espressif.com/download/file.php?id=1690 -O sdk.zip; unzip sdk.zip; ln -s `pwd`/ESP8266_NONOS_SDK/ $TRAVIS_BUILD_DIR/opt/esp-alt-sdk/sdk; export DEPLOY='true'; fi

script:
- export CHANGED_FILES=`git diff --diff-filter=AMD HEAD HEAD^ --name-only`
- export CHANGED_PROJECTS=`for i in $CHANGED_FILES; do echo "$i" | grep '^samples/' | cut -d'/' -f2; done | uniq`
- export SMING_HOME=$TRAVIS_BUILD_DIR/Sming
- export ESP_HOME=$TRAVIS_BUILD_DIR/opt/esp-alt-sdk
- if [ "$SDK_VERSION" == "2.1.0" ]; then export SDK_BASE=$SMING_HOME/third-party/ESP8266_NONOS_SDK; fi
- export PATH=$PATH:$ESP_HOME/xtensa-lx106-elf/bin:$ESP_HOME/utils/:$SMING_HOME/../.travis/tools
- cd $SMING_HOME
- make test
Expand Down
10 changes: 8 additions & 2 deletions Sming/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,17 @@ THIRD_PARTY_DATA += third-party/http-parser/Makefile
MODULES += third-party/http-parser/
EXTRA_INCDIR += third-party/http-parser/

# => webscoket-parser
# => websocket-parser
THIRD_PARTY_DATA += third-party/ws_parser/Makefile
MODULES += third-party/ws_parser/
EXTRA_INCDIR += third-party/ws_parser/

# => SDK
ifneq (,$(findstring third-party/ESP8266_NONOS_SDK, $(SDK_BASE)))
THIRD_PARTY_DATA += third-party/ESP8266_NONOS_SDK/Makefile
CFLAGS += -DSDK_INTERNAL
endif

# => esp-gdbstub
ifeq ($(ENABLE_GDB), 1)
THIRD_PARTY_DATA += third-party/esp-gdbstub/Makefile
Expand Down Expand Up @@ -240,7 +246,7 @@ endif
MFORCE32 := $(shell $(CC) --help=target | grep mforce-l32)

# compiler flags using during compilation of source files. Add '-pg' for debugging
CFLAGS = -Wpointer-arith -Wundef -Werror -Wl,-EL -nostdlib -mlongcalls -mtext-section-literals -finline-functions -fdata-sections -ffunction-sections \
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) -DENABLE_CMD_EXECUTOR=$(ENABLE_CMD_EXECUTOR) -DESP8266=1
ifeq ($(SMING_RELEASE),1)
# See: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
Expand Down
4 changes: 4 additions & 0 deletions Sming/Makefile-project.mk
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ endif

# 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) -DENABLE_CMD_EXECUTOR=$(ENABLE_CMD_EXECUTOR)
# => SDK
ifneq (,$(findstring third-party/ESP8266_NONOS_SDK, $(SDK_BASE)))
CFLAGS += -DSDK_INTERNAL
endif
ifeq ($(SMING_RELEASE),1)
# See: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
# for full list of optimization options
Expand Down
4 changes: 4 additions & 0 deletions Sming/Makefile-rboot.mk
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ USER_LIBDIR = $(SMING_HOME)/compiler/lib/

# 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) -DENABLE_CMD_EXECUTOR=$(ENABLE_CMD_EXECUTOR)
# => SDK
ifneq (,$(findstring third-party/ESP8266_NONOS_SDK, $(SDK_BASE)))
CFLAGS += -DSDK_INTERNAL
endif
ifeq ($(SMING_RELEASE),1)
# See: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
# for full list of optimization options
Expand Down
4 changes: 2 additions & 2 deletions Sming/SmingCore/HardwareTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ static void IRAM_ATTR hw_timer_isr_cb(void *arg)

Hardware_Timer::Hardware_Timer()
{
ETS_FRC_TIMER1_INTR_ATTACH((void*)hw_timer_isr_cb, (void *)this);
ETS_FRC_TIMER1_INTR_ATTACH((ets_isr_t)hw_timer_isr_cb, (void *)this);
}

Hardware_Timer::~Hardware_Timer()
{
ETS_FRC_TIMER1_INTR_ATTACH((void*)hw_timer_isr_cb, null);
ETS_FRC_TIMER1_INTR_ATTACH((ets_isr_t)hw_timer_isr_cb, null);
stop();
}

Expand Down
2 changes: 1 addition & 1 deletion Sming/SmingCore/Interrupts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void attachInterruptHandler(uint8_t pin, GPIO_INT_TYPE mode)

if (!_gpioInterruptsInitialied)
{
ETS_GPIO_INTR_ATTACH((void*)interruptHandler, NULL); // Register interrupt handler
ETS_GPIO_INTR_ATTACH((ets_isr_t)interruptHandler, NULL); // Register interrupt handler
_gpioInterruptsInitialied = true;
}

Expand Down
3 changes: 1 addition & 2 deletions Sming/SmingCore/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
#include <stdlib.h>
#include "eagle_soc.h"
#include "espinc/spi_register.h"
#include "espinc/c_types_compatible.h"

#include "c_types.h"
// define the static singleton
SPIClass SPI;

Expand Down
27 changes: 26 additions & 1 deletion Sming/compiler/ld/common.ld
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,36 @@ SECTIONS
.irom0.text : ALIGN(4)
{
_irom0_text_start = ABSOLUTE(.);

*libsmartconfig.a:(.literal .text .literal.* .text.*)
*libstdc++.a:(.literal .text .literal.* .text.*)
*liblwip_open.a:(.literal .text .literal.* .text.*)
*liblwip_full.a:(.literal .text .literal.* .text.*)
*liblwip2.a:(.literal .text .literal.* .text.*)
*libaxtls.a:(.literal .text .literal.* .text.*)
*libat.a:(.literal.* .text.*)
*libcrypto.a:(.literal.* .text.*)
*libespnow.a:(.literal.* .text.*)
*libjson.a:(.literal.* .text.*)
*liblwip.a:(.literal.* .text.*)
*libmesh.a:(.literal.* .text.*)
*libnet80211.a:(.literal.* .text.*)
*libsmartconfig.a:(.literal.* .text.*)
*libssl.a:(.literal.* .text.*)
*libupgrade.a:(.literal.* .text.*)
*libwpa.a:(.literal.* .text.*)
*libwpa2.a:(.literal.* .text.*)
*libwps.a:(.literal.* .text.*)

*libmbedtls.a:(.literal.* .text.*)

*libm.a:(.literal .text .literal.* .text.*)

*(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text .irom.debug.*)
out/build/app_app.a:*(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.* .irom.debug.*)
*libsming.a:*(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.* .irom.debug.*)
*libsmingssl.a:*(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.* .irom.debug.*)
*liblwip2.a:(.literal .text .literal.* .text.*)

_irom0_text_end = ABSOLUTE(.);
_flash_code_end = ABSOLUTE(.);
} >irom0_0_seg :irom0_0_phdr
Expand Down
12 changes: 8 additions & 4 deletions Sming/include/user_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ extern "C" {
#include <limits.h>
#include <stdint.h>

// Override c_types.h include and remove buggy espconn
#define _C_TYPES_H_
// Remove buggy espconn
#define _NO_ESPCON_

// Updated, compatible version of c_types.h
// Just removed types declared in <stdint.h>
#ifdef SDK_INTERNAL
// ESP SDK 2.1 or later provide proper c_types.h
#include "c_types.h"
#else
// Older SDKs, have wrong or incompatible c_types type definitions
#define _C_TYPES_H_
#include <espinc/c_types_compatible.h>
#endif /* SDK_INTERNAL */

// System API declarations
#include <esp_systemapi.h>
Expand Down
22 changes: 17 additions & 5 deletions Sming/system/include/esp_systemapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#define assert(condition) if (!(condition)) SYSTEM_ERROR("ASSERT: %s %d", __FUNCTION__, __LINE__)
#define SYSTEM_ERROR(fmt, ...) m_printf("ERROR: " fmt "\r\n", ##__VA_ARGS__)

#ifndef SDK_INTERNAL
extern void ets_timer_arm_new(ETSTimer *ptimer, uint32_t milliseconds, bool repeat_flag, int isMstimer);
extern void ets_timer_disarm(ETSTimer *a);
extern void ets_timer_setfn(ETSTimer *t, ETSTimerFunc *pfunction, void *parg);
Expand All @@ -57,22 +58,27 @@ extern void ets_delay_us(uint32_t us);

extern void ets_isr_mask(unsigned intr);
extern void ets_isr_unmask(unsigned intr);
extern void ets_isr_attach(int intr, void *handler, void *arg);

typedef void (* ets_isr_t)(void *);

//extern void ets_isr_attach(int intr, void *handler, void *arg);
extern void ets_isr_attach(int i, ets_isr_t func, void *arg);

extern int ets_memcmp(const void *s1, const void *s2, size_t n);
extern void *ets_memcpy(void *dest, const void *src, size_t n);
extern void *ets_memset(void *s, int c, size_t n);

extern void ets_install_putc1(void *routine);
//extern void ets_install_putc1(void *routine);
extern void ets_install_putc1(void (*p)(char c));
extern int ets_sprintf(char *str, const char *format, ...) __attribute__ ((format (printf, 2, 3)));
extern int ets_str2macaddr(void *, void *);
extern int ets_strcmp(const char *s1, const char *s2);
extern char *ets_strcpy(char *dest, const char *src);
//extern int os_random();
//extern char *ets_strdup(const char *str); // :(
const char * ets_strrchr(const char *str, int character);
extern size_t ets_strlen(const char *s);
extern int ets_strncmp(const char *s1, const char *s2, int len);
extern int ets_strlen(const char *s);
extern int ets_strncmp(const char *s1, const char *s2, unsigned int len);
extern char *ets_strncpy(char *dest, const char *src, size_t n);
extern char *ets_strstr(const char *haystack, const char *needle);
extern int os_printf_plus(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
Expand All @@ -85,20 +91,26 @@ extern void pvPortFree(void *ptr);
extern void vPortFree(void *ptr, const char *file, uint32 line);
extern void *vPortMalloc(size_t xWantedSize);

extern void uart_div_modify(int no, unsigned int freq);
extern void uart_div_modify(uint8 uart_no, uint32 DivLatchValue);
extern int ets_uart_printf(const char *fmt, ...);
extern void uart_tx_one_char(char ch);

extern void ets_intr_lock();
extern void ets_intr_unlock();

#endif /* SDK_INTERNAL */

// CPU Frequency
extern void ets_update_cpu_frequency(uint32_t frq);
extern uint32_t ets_get_cpu_frequency();

extern void xt_disable_interrupts();
extern void xt_enable_interrupts();

extern void uart_tx_one_char(char ch);
extern void ets_isr_mask(unsigned intr);
extern void ets_isr_unmask(unsigned intr);

typedef signed short file_t;

#endif
9 changes: 4 additions & 5 deletions Sming/system/uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ void uart_start_isr(uart_t* uart)
USC1(uart->uart_nr) = (127 << UCFFT) | (0x02 << UCTOT) | (1 <<UCTOE );
USIC(uart->uart_nr) = 0xffff;
USIE(uart->uart_nr) = (1 << UIFF) | (1 << UIFR) | (1 << UITO);
// ETS_UART_INTR_ATTACH(uart_isr, (void *)uart);
ETS_UART_INTR_ATTACH((void *)uart_isr, (void *)uart);
ETS_UART_INTR_ATTACH(uart_isr, (void *)uart);
ETS_UART_INTR_ENABLE();
}

Expand Down Expand Up @@ -492,16 +491,16 @@ void uart_set_debug(int uart_nr)
switch(s_uart_debug_nr) {
case UART0:
system_set_os_print(1);
ets_install_putc1((void *) &uart0_write_char);
ets_install_putc1(uart0_write_char);
break;
case UART1:
system_set_os_print(1);
ets_install_putc1((void *) &uart1_write_char);
ets_install_putc1(uart1_write_char);
break;
case UART_NO:
default:
system_set_os_print(0);
ets_install_putc1((void *) &uart_ignore_char);
ets_install_putc1(uart_ignore_char);
break;
}
}
Expand Down
13 changes: 13 additions & 0 deletions Sming/third-party/.patches/ESP8266_NONOS_SDK.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/include/osapi.h b/include/osapi.h
index 0462a9c..52ad21f 100644
--- a/include/osapi.h
+++ b/include/osapi.h
@@ -30,7 +30,7 @@
#include "user_config.h"

void ets_bzero(void *s, size_t n);
-void ets_delay_us(uint16_t us);
+void ets_delay_us(uint32_t us);
void ets_install_putc1(void (*p)(char c));

#define os_bzero ets_bzero
11 changes: 10 additions & 1 deletion Sming/third-party/.patches/esp-gdbstub.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/gdbstub.c b/gdbstub.c
index 5fc6633..03f6d49 100644
index 5fc6633..fe655b8 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -8,6 +8,7 @@
Expand Down Expand Up @@ -42,3 +42,12 @@ index 5fc6633..03f6d49 100644
while(gdbReadCommand()!=ST_CONT);
ets_wdt_enable();
//Copy any changed registers back to the frame the Xtensa HAL uses.
@@ -714,7 +719,7 @@ static void ATTR_GDBFN uart_hdlr(void *arg, void *frame) {
}

static void ATTR_GDBINIT install_uart_hdlr() {
- ets_isr_attach(ETS_UART_INUM, uart_hdlr, NULL);
+ ets_isr_attach(ETS_UART_INUM, (ets_isr_t)uart_hdlr, NULL);
SET_PERI_REG_MASK(UART_INT_ENA(0), UART_RXFIFO_FULL_INT_ENA|UART_RXFIFO_TOUT_INT_ENA);
ets_isr_unmask((1<<ETS_UART_INUM)); //enable uart interrupt
}
Loading

0 comments on commit c2cc852

Please sign in to comment.