From 181959f1debf3f72a4e053a1b3d688c9e1f15885 Mon Sep 17 00:00:00 2001 From: Valeriy Koval Date: Thu, 9 Apr 2015 18:50:03 +0300 Subject: [PATCH 1/3] Add support for ESP8266 // Resolve #119 --- examples/espressif/esp8266-native/README.rst | 21 ++++++ .../espressif/esp8266-native/platformio.ini | 22 +++++++ .../esp8266-native/src/user_config.h | 5 ++ .../espressif/esp8266-native/src/user_main.c | 33 ++++++++++ platformio/boards/espressif.json | 3 +- platformio/builder/scripts/espressif.py | 66 +++++++++++-------- .../builder/scripts/frameworks/arduino.py | 5 +- 7 files changed, 126 insertions(+), 29 deletions(-) create mode 100644 examples/espressif/esp8266-native/README.rst create mode 100644 examples/espressif/esp8266-native/platformio.ini create mode 100644 examples/espressif/esp8266-native/src/user_config.h create mode 100644 examples/espressif/esp8266-native/src/user_main.c diff --git a/examples/espressif/esp8266-native/README.rst b/examples/espressif/esp8266-native/README.rst new file mode 100644 index 00000000..2704e158 --- /dev/null +++ b/examples/espressif/esp8266-native/README.rst @@ -0,0 +1,21 @@ +How to build PlatformIO based project +===================================== + +1. `Install PlatformIO `_ +2. Download `source code with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platformio-develop/examples/espressif/esp8266-native + + # Process example project + > platformio run + + # Upload firmware + > platformio run --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/espressif/esp8266-native/platformio.ini b/examples/espressif/esp8266-native/platformio.ini new file mode 100644 index 00000000..304bd86f --- /dev/null +++ b/examples/espressif/esp8266-native/platformio.ini @@ -0,0 +1,22 @@ +# +# Project Configuration File +# +# A detailed documentation with the EXAMPLES is located here: +# http://docs.platformio.org/en/latest/projectconf.html +# + +# A sign `#` at the beginning of the line indicates a comment +# Comment lines are ignored. + +# Simple and base environment +# [env:mybaseenv] +# platform = %INSTALLED_PLATFORM_NAME_HERE% +# framework = +# board = +# +# Automatic targets - enable auto-uploading +# targets = upload + +[env:esp01_8266] +platform = espressif +board = esp01 diff --git a/examples/espressif/esp8266-native/src/user_config.h b/examples/espressif/esp8266-native/src/user_config.h new file mode 100644 index 00000000..35e838d5 --- /dev/null +++ b/examples/espressif/esp8266-native/src/user_config.h @@ -0,0 +1,5 @@ +#ifndef __USER_CONFIG_H__ +#define __USER_CONFIG_H__ + +#endif + diff --git a/examples/espressif/esp8266-native/src/user_main.c b/examples/espressif/esp8266-native/src/user_main.c new file mode 100644 index 00000000..b6f4d027 --- /dev/null +++ b/examples/espressif/esp8266-native/src/user_main.c @@ -0,0 +1,33 @@ +/****************************************************************************** + * 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(void *data) +{ + struct station_config *sta_conf = data; + + wifi_station_set_config(sta_conf); + wifi_station_disconnect(); + wifi_station_connect(); +} + +void user_init(void) +{ + os_printf("SDK version:%s\n", system_get_sdk_version()); + + wifi_set_opmode(STATION_MODE); + smartconfig_start(SC_TYPE_AIRKISS, smartconfig_done); +} diff --git a/platformio/boards/espressif.json b/platformio/boards/espressif.json index 2fa1d39c..6c2b226c 100644 --- a/platformio/boards/espressif.json +++ b/platformio/boards/espressif.json @@ -16,8 +16,7 @@ "maximum_size": 524288, "protocol": "arduino", "require_upload_port" : true, - "speed": 115200, - "wait_for_upload_port": true + "speed": 115200 }, "url": "https://nurdspace.nl/ESP8266", "vendor": "Espressif" diff --git a/platformio/builder/scripts/espressif.py b/platformio/builder/scripts/espressif.py index 78dfced8..310648ab 100644 --- a/platformio/builder/scripts/espressif.py +++ b/platformio/builder/scripts/espressif.py @@ -5,7 +5,9 @@ Builder for Espressif MCUs """ +import os from os.path import join +from platform import system from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Builder, Default, DefaultEnvironment) @@ -65,45 +67,59 @@ env.Replace( "-Wl,-static" ], - LIBPATH=[join("$PLATFORMFW_DIR", "sdk", "lib")], - LIBS=["hal", "phy", "net80211", "lwip", "wpa", "main", "pp", "c", "gcc"], - SIZEPRINTCMD='"$SIZETOOL" -B -d $SOURCES', - UPLOADER=join("$PIOPACKAGES_DIR", "tool-esptool", "esptool"), + UPLOADER=join("$PIOPACKAGES_DIR", "tool-esptool", "esptool.py"), UPLOADERFLAGS=[ - "-vv", - "-cd", "none", - "-cb", "$UPLOAD_SPEED", - "-cp", "$UPLOAD_PORT", - "-ca", "0x00000", - "-cf", "${SOURCES[0]}", - "-ca", "0x40000", - "-cf", "${SOURCES[1]}" + "--port", "$UPLOAD_PORT", + "--baud", "$UPLOAD_SPEED", + "write_flash", + "0x00000", join("$BUILD_DIR", "firmware.elf-0x00000.bin"), + "0x40000", join("$BUILD_DIR", "firmware.elf-0x40000.bin") ], - UPLOADCMD='$UPLOADER $UPLOADERFLAGS' + UPLOADCMD='python $UPLOADER $UPLOADERFLAGS' ) env.Append( BUILDERS=dict( ElfToBin=Builder( action=" ".join([ - "$UPLOADER", - "-eo", "$SOURCES", - "-bo", "${TARGETS[0]}", - "-bs", ".text", - "-bs", ".data", - "-bs", ".rodata", - "-bc", "-ec", - "-eo", "$SOURCES", - "-es", ".irom0.text", "${TARGETS[1]}", - "-ec", "-v" + "python", "$UPLOADER", "elf2image", "$SOURCES" ]), suffix=".bin" ) ) ) +if system() == "Windows": + paths = [] + for path in os.environ['PATH'].split(";"): + if "python" in path.lower(): + paths.append(path) + + env.AppendENVPath( + "PATH", ";".join(paths) + ) + +# +# Configure SDK +# + +if "FRAMEWORK" not in env: + env.Append( + CPPPATH=[ + join("$PIOPACKAGES_DIR", "sdk-esp8266", "include"), + "$PROJECTSRC_DIR" + ], + LIBPATH=[join("$PIOPACKAGES_DIR", "sdk-esp8266", "lib")] + ) + 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", "at", "ssl"] + ) + # # Target: Build executable and linkable firmware # @@ -117,9 +133,7 @@ target_elf = env.BuildFirmware() if "uploadlazy" in COMMAND_LINE_TARGETS: target_firm = join("$BUILD_DIR", "firmware.bin") else: - target_firm = env.ElfToBin( - [join("$BUILD_DIR", "firmware_00000"), - join("$BUILD_DIR", "firmware_40000")], target_elf) + target_firm = env.ElfToBin(target_elf) # # Target: Print binary size diff --git a/platformio/builder/scripts/frameworks/arduino.py b/platformio/builder/scripts/frameworks/arduino.py index 4b6acde2..efded5f3 100644 --- a/platformio/builder/scripts/frameworks/arduino.py +++ b/platformio/builder/scripts/frameworks/arduino.py @@ -44,7 +44,10 @@ elif env.get("PLATFORM") == "timsp430": ) elif env.get("PLATFORM") == "espressif": env.Prepend( - CPPPATH=[join("$PLATFORMFW_DIR", "sdk", "include")] + CPPPATH=[join("$PLATFORMFW_DIR", "sdk", "include")], + LIBPATH=[join("$PLATFORMFW_DIR", "sdk", "lib")], + LIBS=["hal", "phy", "net80211", "lwip", + "wpa", "main", "pp", "c", "gcc"] ) env.Replace(PLATFORMFW_DIR=PLATFORMFW_DIR) From 3fda4920383a9c0231b897b1c2c2c0803f8cd43a Mon Sep 17 00:00:00 2001 From: Valeriy Koval Date: Fri, 10 Apr 2015 18:23:21 +0300 Subject: [PATCH 2/3] Return to esptool-mk uploader. --- platformio/builder/scripts/espressif.py | 45 +++++++++++++------------ 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/platformio/builder/scripts/espressif.py b/platformio/builder/scripts/espressif.py index 310648ab..289f9955 100644 --- a/platformio/builder/scripts/espressif.py +++ b/platformio/builder/scripts/espressif.py @@ -5,9 +5,7 @@ Builder for Espressif MCUs """ -import os from os.path import join -from platform import system from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Builder, Default, DefaultEnvironment) @@ -69,38 +67,40 @@ env.Replace( SIZEPRINTCMD='"$SIZETOOL" -B -d $SOURCES', - UPLOADER=join("$PIOPACKAGES_DIR", "tool-esptool", "esptool.py"), + UPLOADER=join("$PIOPACKAGES_DIR", "tool-esptool", "esptool"), UPLOADERFLAGS=[ - "--port", "$UPLOAD_PORT", - "--baud", "$UPLOAD_SPEED", - "write_flash", - "0x00000", join("$BUILD_DIR", "firmware.elf-0x00000.bin"), - "0x40000", join("$BUILD_DIR", "firmware.elf-0x40000.bin") + "-vv", + "-cd", "none", + "-cb", "$UPLOAD_SPEED", + "-cp", "$UPLOAD_PORT", + "-ca", "0x00000", + "-cf", "${SOURCES[0]}", + "-ca", "0x40000", + "-cf", "${SOURCES[1]}" ], - UPLOADCMD='python $UPLOADER $UPLOADERFLAGS' + UPLOADCMD='$UPLOADER $UPLOADERFLAGS' ) env.Append( BUILDERS=dict( ElfToBin=Builder( action=" ".join([ - "python", "$UPLOADER", "elf2image", "$SOURCES" + "$UPLOADER", + "-eo", "$SOURCES", + "-bo", "${TARGETS[0]}", + "-bs", ".text", + "-bs", ".data", + "-bs", ".rodata", + "-bc", "-ec", + "-eo", "$SOURCES", + "-es", ".irom0.text", "${TARGETS[1]}", + "-ec", "-v" ]), suffix=".bin" ) ) ) -if system() == "Windows": - paths = [] - for path in os.environ['PATH'].split(";"): - if "python" in path.lower(): - paths.append(path) - - env.AppendENVPath( - "PATH", ";".join(paths) - ) - # # Configure SDK # @@ -133,7 +133,10 @@ target_elf = env.BuildFirmware() if "uploadlazy" in COMMAND_LINE_TARGETS: target_firm = join("$BUILD_DIR", "firmware.bin") else: - target_firm = env.ElfToBin(target_elf) + target_firm = env.ElfToBin( + [join("$BUILD_DIR", "firmware_00000"), + join("$BUILD_DIR", "firmware_40000")], target_elf) + # # Target: Print binary size From 52e5f7ac2e02fa850cfb6dbda1e131b002d6be35 Mon Sep 17 00:00:00 2001 From: Valeriy Koval Date: Fri, 10 Apr 2015 18:24:03 +0300 Subject: [PATCH 3/3] Add Quirkbot board. --- platformio/boards/misc.json | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/platformio/boards/misc.json b/platformio/boards/misc.json index 14d71cfa..b9f7dba6 100644 --- a/platformio/boards/misc.json +++ b/platformio/boards/misc.json @@ -493,5 +493,33 @@ }, "url": "http://www.bq.com/gb/products/zum.html", "vendor": "BQ" + }, + + "quirkbot": { + "build": { + "core": "arduino", + "extra_flags": "-DARDUINO_ARCH_AVR -DQUIRKBOT", + "f_cpu": "8000000L", + "mcu": "atmega32u4", + "variant" : "quirkbot", + "vid": "0xf055", + "pid": "0xf055", + "usb_product": "Quirkbot" + }, + "frameworks": ["arduino"], + "name": "Quirkbot", + "platform": "atmelavr", + "upload": { + "disable_flushing": true, + "maximum_ram_size": 2560, + "maximum_size": 28672, + "protocol": "avr109", + "require_upload_port" : true, + "speed": 57600, + "use_1200bps_touch": true, + "wait_for_upload_port": true + }, + "url": "http://quirkbot.com", + "vendor": "Quirkbot" } }