From 530868a1fee9baeee876086f4a1f2601f2b0de1a Mon Sep 17 00:00:00 2001 From: Valeriy Koval Date: Thu, 7 Apr 2016 19:19:32 +0300 Subject: [PATCH] Update native SDK support for espressif platform // Issue #366, #546, #593 --- .../espressif/esp8266-native/platformio.ini | 1 + .../espressif/esp8266-native/src/blinky.c | 36 ++++++++++ .../espressif/esp8266-native/src/user_main.c | 68 ------------------- platformio/builder/scripts/espressif.py | 29 +++++--- 4 files changed, 56 insertions(+), 78 deletions(-) create mode 100644 examples/espressif/esp8266-native/src/blinky.c delete mode 100644 examples/espressif/esp8266-native/src/user_main.c diff --git a/examples/espressif/esp8266-native/platformio.ini b/examples/espressif/esp8266-native/platformio.ini index 304bd86f..f2d2683f 100644 --- a/examples/espressif/esp8266-native/platformio.ini +++ b/examples/espressif/esp8266-native/platformio.ini @@ -20,3 +20,4 @@ [env:esp01_8266] platform = espressif board = esp01 +build_flags = -Wl,-T"eagle.app.v6.ld" diff --git a/examples/espressif/esp8266-native/src/blinky.c b/examples/espressif/esp8266-native/src/blinky.c new file mode 100644 index 00000000..34c9380f --- /dev/null +++ b/examples/espressif/esp8266-native/src/blinky.c @@ -0,0 +1,36 @@ +#include "ets_sys.h" +#include "osapi.h" +#include "gpio.h" +#include "os_type.h" + +static const int pin = 1; +static volatile os_timer_t some_timer; + +void some_timerfunc(void *arg) +{ + //Do blinky stuff + if (GPIO_REG_READ(GPIO_OUT_ADDRESS) & (1 << pin)) + { + // set gpio low + gpio_output_set(0, (1 << pin), 0, 0); + } + else + { + // set gpio high + gpio_output_set((1 << pin), 0, 0, 0); + } +} + +void ICACHE_FLASH_ATTR user_init() +{ + // init gpio sussytem + gpio_init(); + + // configure UART TXD to be GPIO1, set as output + PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_GPIO1); + gpio_output_set(0, 0, (1 << pin), 0); + + // setup timer (500ms, repeating) + os_timer_setfn(&some_timer, (os_timer_func_t *)some_timerfunc, NULL); + os_timer_arm(&some_timer, 1000, 1); +} diff --git a/examples/espressif/esp8266-native/src/user_main.c b/examples/espressif/esp8266-native/src/user_main.c deleted file mode 100644 index 14e0d077..00000000 --- a/examples/espressif/esp8266-native/src/user_main.c +++ /dev/null @@ -1,68 +0,0 @@ -/****************************************************************************** - * Copyright 2013-2014 Espressif Systems (Wuxi) - * - * FileName: user_main.c - * - * Description: entry file of user application - * - * Modification history: - * 2014/1/1, v1.0 create this file. -*******************************************************************************/ -#include "ets_sys.h" -#include "osapi.h" - -#include "user_interface.h" -#include "smartconfig.h" - -void ICACHE_FLASH_ATTR -smartconfig_done(sc_status status, void *pdata) -{ - switch(status) { - case SC_STATUS_WAIT: - os_printf("SC_STATUS_WAIT\n"); - break; - case SC_STATUS_FIND_CHANNEL: - os_printf("SC_STATUS_FIND_CHANNEL\n"); - break; - case SC_STATUS_GETTING_SSID_PSWD: - os_printf("SC_STATUS_GETTING_SSID_PSWD\n"); - sc_type *type = pdata; - if (*type == SC_TYPE_ESPTOUCH) { - os_printf("SC_TYPE:SC_TYPE_ESPTOUCH\n"); - } else { - os_printf("SC_TYPE:SC_TYPE_AIRKISS\n"); - } - break; - case SC_STATUS_LINK: - os_printf("SC_STATUS_LINK\n"); - struct station_config *sta_conf = pdata; - - wifi_station_set_config(sta_conf); - wifi_station_disconnect(); - wifi_station_connect(); - break; - case SC_STATUS_LINK_OVER: - os_printf("SC_STATUS_LINK_OVER\n"); - if (pdata != NULL) { - uint8 phone_ip[4] = {0}; - - os_memcpy(phone_ip, (uint8*)pdata, 4); - os_printf("Phone ip: %d.%d.%d.%d\n",phone_ip[0],phone_ip[1],phone_ip[2],phone_ip[3]); - } - smartconfig_stop(); - break; - } - -} - -void user_rf_pre_init(void) -{ -} - -void user_init(void) -{ - os_printf("SDK version:%s\n", system_get_sdk_version()); - - wifi_set_opmode(STATION_MODE); - smartconfig_start(smartconfig_done); -} diff --git a/platformio/builder/scripts/espressif.py b/platformio/builder/scripts/espressif.py index 45c9bdad..ca6d8e99 100644 --- a/platformio/builder/scripts/espressif.py +++ b/platformio/builder/scripts/espressif.py @@ -254,16 +254,21 @@ else: join("$PIOPACKAGES_DIR", "sdk-esp8266", "include"), "$PROJECTSRC_DIR" ], - LIBPATH=[join("$PIOPACKAGES_DIR", "sdk-esp8266", "lib")], + + LIBPATH=[ + join("$PIOPACKAGES_DIR", "sdk-esp8266", "lib"), + join("$PIOPACKAGES_DIR", "sdk-esp8266", "ld") + ], + BUILDERS=dict( ElfToBin=Builder( action=" ".join([ '"$OBJCOPY"', "-eo", "$SOURCES", "-bo", "${TARGETS[0]}", - "-bm", "qio", - "-bf", "40", - "-bz", "512K", + "-bm", "$BOARD_FLASH_MODE", + "-bf", "${__get_board_f_flash(__env__)}", + "-bz", "${__get_flash_size(__env__)}", "-bs", ".text", "-bs", ".data", "-bs", ".rodata", @@ -277,20 +282,24 @@ else: ) ) env.Replace( - LDSCRIPT_PATH=join( - "$PIOPACKAGES_DIR", "sdk-esp8266", "ld", "eagle.app.v6.ld"), - LIBS=["c", "gcc", "phy", "pp", "net80211", "lwip", "wpa", "main", - "json", "upgrade", "smartconfig", "pwm", "at", "ssl"], + LIBS=[ + "c", "gcc", "phy", "pp", "net80211", "lwip", "wpa", "wpa2", + "main", "wps", "crypto", "json", "ssl", "pwm", "upgrade", + "smartconfig", "airkiss", "at" + ], + UPLOADERFLAGS=[ "-vv", - "-cd", "ck", + "-cd", "$UPLOAD_RESETMETHOD", "-cb", "$UPLOAD_SPEED", "-cp", "$UPLOAD_PORT", "-ca", "0x00000", "-cf", "${SOURCES[0]}", "-ca", "0x40000", "-cf", "${SOURCES[1]}" - ] + ], + + UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS', ) #