From 7332e21f665ddb8711cd44fafe6a854fcb0dde3e Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 22 Oct 2016 02:20:57 +0300 Subject: [PATCH 01/10] Initial commit --- .gitignore | 1 + .travis.yml | 22 +++++ LICENSE | 174 ++++++++++++++++++++++++++++++++++ README.md | 22 ++++- appveyor.yml | 22 +++++ builder/frameworks/arduino.py | 25 +++++ builder/frameworks/espidf.py | 23 +++++ builder/main.py | 15 +++ platform.json | 49 ++++++++++ 9 files changed, 351 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 LICENSE create mode 100644 appveyor.yml create mode 100644 builder/frameworks/arduino.py create mode 100644 builder/frameworks/espidf.py create mode 100644 builder/main.py create mode 100644 platform.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..0d20b6487 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..a583d6ba8 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,22 @@ +language: python +python: + - "2.7" + +env: + - PLATFORMIO_PROJECT_DIR=examples/arduino-blink + +install: + - pip install -U https://github.com/platformio/platformio/archive/develop.zip + - platformio platform install file://. + +script: + - platformio run -d $PLATFORMIO_PROJECT_DIR + +notifications: + email: false + + slack: + rooms: + secure: zKv2HzE18J8f+mHUeoNylXSvh6IBlfaaf2H96cicwGB3p53jOXBXO/99N7MVe6UnkJludmVeTGim4timqZdCOLglUPxIo8lSFSp5+4dO+WCpZB7z9P+vw4oy+qV+5Kp1EhDQnOybg/7DdYiJiCVz1psDZH+oYRqnW/+lU6s48svItrUpy6s36OeZJsYP9jjoWnSyzAemvO3kurC3Gib475tJfKIMVd5l9Lmj3yuALonDj6z6DXHyM8lExxRbaAe22CvHzuTXs3N0S/d34Gdi7+f/+NOcKrdBgNbzMnchtwLgnX8uqGAp+3D96JmTNFxdBc1uY82WdDY/ij2X/f6GFzIWgXRI7medHxvWqUFdRC1Z6bK1t36QsPgot2A3nT4oJnlJ/NqpwsjnSN60emDmkbDUf0p1JzErhHHQTVrasTWOX7yXVteXXIIP1HYR1A+5VMjO+6r20J9AM+QYm/b+9Rmy6t2uMdmimiRTy2fQxH/eExWSmJqrzdvgWHPc8gPxj9Ib8mryVegFlkajswv/rh2L8I5FZwNTot0+qwYFyst+hNm0PBVBmcyLhSW4v2/sVBwq38ir4NyXtnps46S7VNKh7b8kdO2o4f8oRkv+PWSnnK6N6tej20CAZeBjTh2puIl2HVL47/rCQA7DZMiJP+iGet6HG6pWKktilvfhSLs= + on_failure: always + on_success: change diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..2f79a3b32 --- /dev/null +++ b/LICENSE @@ -0,0 +1,174 @@ +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, +and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by +the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all +other entities that control, are controlled by, or are under common +control with that entity. For the purposes of this definition, +"control" means (i) the power, direct or indirect, to cause the +direction or management of such entity, whether by contract or +otherwise, or (ii) ownership of fifty percent (50%) or more of the +outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity +exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, +including but not limited to software source code, documentation +source, and configuration files. + +"Object" form shall mean any form resulting from mechanical +transformation or translation of a Source form, including but +not limited to compiled object code, generated documentation, +and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or +Object form, made available under the License, as indicated by a +copyright notice that is included in or attached to the work +(an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object +form, that is based on (or derived from) the Work and for which the +editorial revisions, annotations, elaborations, or other modifications +represent, as a whole, an original work of authorship. For the purposes +of this License, Derivative Works shall not include works that remain +separable from, or merely link (or bind by name) to the interfaces of, +the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including +the original version of the Work and any modifications or additions +to that Work or Derivative Works thereof, that is intentionally +submitted to Licensor for inclusion in the Work by the copyright owner +or by an individual or Legal Entity authorized to submit on behalf of +the copyright owner. For the purposes of this definition, "submitted" +means any form of electronic, verbal, or written communication sent +to the Licensor or its representatives, including but not limited to +communication on electronic mailing lists, source code control systems, +and issue tracking systems that are managed by, or on behalf of, the +Licensor for the purpose of discussing and improving the Work, but +excluding communication that is conspicuously marked or otherwise +designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity +on behalf of whom a Contribution has been received by Licensor and +subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +copyright license to reproduce, prepare Derivative Works of, +publicly display, publicly perform, sublicense, and distribute the +Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +(except as stated in this section) patent license to make, have made, +use, offer to sell, sell, import, and otherwise transfer the Work, +where such license applies only to those patent claims licensable +by such Contributor that are necessarily infringed by their +Contribution(s) alone or by combination of their Contribution(s) +with the Work to which such Contribution(s) was submitted. If You +institute patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the Work +or a Contribution incorporated within the Work constitutes direct +or contributory patent infringement, then any patent licenses +granted to You under this License for that Work shall terminate +as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the +Work or Derivative Works thereof in any medium, with or without +modifications, and in Source or Object form, provided that You +meet the following conditions: + +(a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + +(b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + +(c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + +(d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + +You may add Your own copyright statement to Your modifications and +may provide additional or different license terms and conditions +for use, reproduction, or distribution of Your modifications, or +for any such Derivative Works as a whole, provided Your use, +reproduction, and distribution of the Work otherwise complies with +the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, +any Contribution intentionally submitted for inclusion in the Work +by You to the Licensor shall be under the terms and conditions of +this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify +the terms of any separate license agreement you may have executed +with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade +names, trademarks, service marks, or product names of the Licensor, +except as required for reasonable and customary use in describing the +origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or +agreed to in writing, Licensor provides the Work (and each +Contributor provides its Contributions) on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +implied, including, without limitation, any warranties or conditions +of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A +PARTICULAR PURPOSE. You are solely responsible for determining the +appropriateness of using or redistributing the Work and assume any +risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, +whether in tort (including negligence), contract, or otherwise, +unless required by applicable law (such as deliberate and grossly +negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, +incidental, or consequential damages of any character arising as a +result of this License or out of the use or inability to use the +Work (including but not limited to damages for loss of goodwill, +work stoppage, computer failure or malfunction, or any and all +other commercial damages or losses), even if such Contributor +has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing +the Work or Derivative Works thereof, You may choose to offer, +and charge a fee for, acceptance of support, warranty, indemnity, +or other liability obligations and/or rights consistent with this +License. However, in accepting such obligations, You may act only +on Your own behalf and on Your sole responsibility, not on behalf +of any other Contributor, and only if You agree to indemnify, +defend, and hold each Contributor harmless for any liability +incurred by, or claims asserted against, such Contributor by reason +of your accepting any such warranty or additional liability. diff --git a/README.md b/README.md index ef2483572..9266572ee 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,20 @@ -# platform-espressif32 -Espressif 32: development platform for PlatformIO +# Espressif 32: development platform for [PlatformIO](http://platformio.org) +[![Build Status](https://travis-ci.org/platformio/platform-espressif32.svg?branch=develop)](https://travis-ci.org/platformio/platform-espressif32) +[![Build status](https://ci.appveyor.com/api/projects/status/aob49qatio84iygj/branch/develop?svg=true)](https://ci.appveyor.com/project/ivankravets/platform-espressif32/branch/develop) + +Espressif Systems is a privately held fabless semiconductor company. They provide wireless communications and Wi-Fi chips which are widely used in mobile devices and the Internet of Things applications. + +* [Home](http://platformio.org/platforms/espressif32) (home page in PlatformIO Platform Registry) +* [Documentation](http://docs.platformio.org/en/stable/platforms/espressif32.html) (advanced usage, packages, boards, frameworks, etc.) + +# Usage + +1. [Install PlatformIO CLI](http://docs.platformio.org/en/stable/installation.html) +2. Install Espressif 32 development platform: +```bash +# install the latest stable version +> platformio platform install espressif32 + +# install development version +> platformio platform install https://github.com/platformio/platform-espressif32.git +``` diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 000000000..aa189aace --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,22 @@ +build: off +environment: + + matrix: + - PLATFORMIO_PROJECT_DIR: "examples/arduino-blink" + +install: +- cmd: git submodule update --init --recursive +- cmd: SET PATH=%PATH%;C:\Python27\Scripts +- cmd: pip install -U https://github.com/platformio/platformio/archive/develop.zip +- cmd: platformio platform install file://. + +test_script: +- cmd: platformio run -d %PLATFORMIO_PROJECT_DIR% + +notifications: + - provider: Slack + incoming_webhook: + secure: E9H0SU0Ju7WLDvgxsV8cs3J62T3nTTX7QkEjsczN0Sto/c9hWkVfhc5gGWUkxhlD975cokHByKGJIdwYwCewqOI+7BrcT8U+nlga4Uau7J8= + on_build_success: false + on_build_failure: true + on_build_status_changed: true diff --git a/builder/frameworks/arduino.py b/builder/frameworks/arduino.py new file mode 100644 index 000000000..aec4b3980 --- /dev/null +++ b/builder/frameworks/arduino.py @@ -0,0 +1,25 @@ +# Copyright 2014-present PlatformIO +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Arduino + +Arduino Wiring-based Framework allows writing cross-platform software to +control devices attached to a wide range of Arduino boards to create all +kinds of creative coding, interactive objects, spaces or physical experiences. + +http://arduino.cc/en/Reference/HomePage +""" + +# TODO \ No newline at end of file diff --git a/builder/frameworks/espidf.py b/builder/frameworks/espidf.py new file mode 100644 index 000000000..9a6473b48 --- /dev/null +++ b/builder/frameworks/espidf.py @@ -0,0 +1,23 @@ +# Copyright 2014-present PlatformIO +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +ESP IDF + +Espressif IoT Development Framework. Official development framework for ESP32. + +https://github.com/espressif/esp-idf +""" + +# TODO \ No newline at end of file diff --git a/builder/main.py b/builder/main.py new file mode 100644 index 000000000..edbcab18a --- /dev/null +++ b/builder/main.py @@ -0,0 +1,15 @@ +# Copyright 2014-present PlatformIO +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# @TODO diff --git a/platform.json b/platform.json new file mode 100644 index 000000000..8e3b8ede8 --- /dev/null +++ b/platform.json @@ -0,0 +1,49 @@ +{ + "name": "espressif32", + "title": "Espressif 32", + "description": "Espressif Systems is a privately held fabless semiconductor company. They provide wireless communications and Wi-Fi chips which are widely used in mobile devices and the Internet of Things applications.", + "url": "https://espressif.com/", + "homepage": "http://platformio.org/platforms/espressif32", + "license": "Apache-2.0", + "engines": { + "platformio": "^3.0.0", + "scons": ">=2.3.0,<2.6.0" + }, + "repository": { + "type": "git", + "url": "https://github.com/platformio/platform-espressif32.git" + }, + "version": "0.0.0", + "packageRepositories": [ + "https://dl.bintray.com/platformio/dl-packages/manifest.json", + "https://sourceforge.net/projects/platformio-storage/files/packages/manifest.json/download", + "http://dl.platformio.org/packages/manifest.json", + "https://raw.githubusercontent.com/eerimoq/simba/master/make/platformio/manifest.json" + ], + "frameworks": { + "arduino": { + "package": "framework-arduinoespressif32", + "script": "builder/frameworks/arduino.py" + }, + "espidf": { + "package": "framework-espidf", + "script": "builder/frameworks/espidf.py" + } + }, + "packages": { + "toolchain-xtensa32": { + "type": "toolchain", + "version": "~1.40802.0" + }, + "framework-arduinoespressif32": { + "type": "framework", + "optional": true, + "version": "~0.0.0" + }, + "framework-espidf": { + "type": "framework", + "optional": true, + "version": "~1.90.0" + } + } +} From c37ff5c0dc6fd0656e8fef9854d073eb218c2500 Mon Sep 17 00:00:00 2001 From: Valeriy Koval Date: Mon, 24 Oct 2016 20:23:25 +0300 Subject: [PATCH 02/10] Initial support for ESP32 --- .travis.yml | 2 + appveyor.yml | 2 + boards/esp32.json | 27 +++ builder/frameworks/arduino.py | 87 ++++++- builder/frameworks/espidf.py | 88 ++++++- builder/main.py | 251 +++++++++++++++++++- examples/arduino-blink/.gitignore | 3 + examples/arduino-blink/.travis.yml | 65 +++++ examples/arduino-blink/README.rst | 38 +++ examples/arduino-blink/lib/readme.txt | 38 +++ examples/arduino-blink/platformio.ini | 13 + examples/arduino-blink/src/Blink.cpp | 27 +++ examples/arduino-wifiscan/.gitignore | 3 + examples/arduino-wifiscan/.travis.yml | 65 +++++ examples/arduino-wifiscan/README.rst | 38 +++ examples/arduino-wifiscan/lib/readme.txt | 38 +++ examples/arduino-wifiscan/platformio.ini | 13 + examples/arduino-wifiscan/src/WiFiScan.ino | 48 ++++ examples/espidf-http-request/.gitignore | 3 + examples/espidf-http-request/.travis.yml | 65 +++++ examples/espidf-http-request/README.rst | 29 +++ examples/espidf-http-request/lib/readme.txt | 38 +++ examples/espidf-http-request/platformio.ini | 14 ++ examples/espidf-http-request/src/main.c | 181 ++++++++++++++ platform.json | 6 +- 25 files changed, 1176 insertions(+), 6 deletions(-) create mode 100644 boards/esp32.json create mode 100644 examples/arduino-blink/.gitignore create mode 100644 examples/arduino-blink/.travis.yml create mode 100644 examples/arduino-blink/README.rst create mode 100644 examples/arduino-blink/lib/readme.txt create mode 100644 examples/arduino-blink/platformio.ini create mode 100644 examples/arduino-blink/src/Blink.cpp create mode 100644 examples/arduino-wifiscan/.gitignore create mode 100644 examples/arduino-wifiscan/.travis.yml create mode 100644 examples/arduino-wifiscan/README.rst create mode 100644 examples/arduino-wifiscan/lib/readme.txt create mode 100644 examples/arduino-wifiscan/platformio.ini create mode 100644 examples/arduino-wifiscan/src/WiFiScan.ino create mode 100644 examples/espidf-http-request/.gitignore create mode 100644 examples/espidf-http-request/.travis.yml create mode 100644 examples/espidf-http-request/README.rst create mode 100644 examples/espidf-http-request/lib/readme.txt create mode 100644 examples/espidf-http-request/platformio.ini create mode 100644 examples/espidf-http-request/src/main.c diff --git a/.travis.yml b/.travis.yml index a583d6ba8..a39fb22b3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,8 @@ python: env: - PLATFORMIO_PROJECT_DIR=examples/arduino-blink + - PLATFORMIO_PROJECT_DIR=examples/arduino-wifiscan + - PLATFORMIO_PROJECT_DIR=examples/espidf-http-request install: - pip install -U https://github.com/platformio/platformio/archive/develop.zip diff --git a/appveyor.yml b/appveyor.yml index aa189aace..63bc3e001 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,6 +3,8 @@ environment: matrix: - PLATFORMIO_PROJECT_DIR: "examples/arduino-blink" + - PLATFORMIO_PROJECT_DIR: "examples/arduino-wifiscan" + - PLATFORMIO_PROJECT_DIR: "examples/espidf-http-request" install: - cmd: git submodule update --init --recursive diff --git a/boards/esp32.json b/boards/esp32.json new file mode 100644 index 000000000..2f3d137dc --- /dev/null +++ b/boards/esp32.json @@ -0,0 +1,27 @@ +{ + "build": { + "core": "esp32", + "extra_flags": "-DESP32_DEV -DARDUINO_ESP32_DEV", + "f_cpu": "160000000L", + "f_flash": "80000000L", + "flash_mode": "dio", + "ldscript": "esp32.out.ld", + "mcu": "esp32", + "variant": "esp32" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Espressif ESP32 Dev Module", + "upload": { + "maximum_ram_size": 114688, + "maximum_size": 1044464, + "require_upload_port": true, + "resetmethod": "nodemcu", + "speed": 115200, + "wait_for_upload_port": true + }, + "url": "https://en.wikipedia.org/wiki/ESP32", + "vendor": "Espressif" +} diff --git a/builder/frameworks/arduino.py b/builder/frameworks/arduino.py index aec4b3980..a0aa1ae56 100644 --- a/builder/frameworks/arduino.py +++ b/builder/frameworks/arduino.py @@ -22,4 +22,89 @@ http://arduino.cc/en/Reference/HomePage """ -# TODO \ No newline at end of file +from os.path import isdir, join + +from SCons.Script import DefaultEnvironment + +env = DefaultEnvironment() +platform = env.PioPlatform() + +FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32") +FRAMEWORK_VERSION = platform.get_package_version( + "framework-arduinoespressif32") +assert isdir(FRAMEWORK_DIR) + +env.Prepend( + CPPDEFINES=[ + "ARDUINO=%s" % FRAMEWORK_VERSION.split(".")[1], + "ARDUINO_ARCH_ESP32" + ], + + CPPPATH=[ + join(FRAMEWORK_DIR, "tools", "sdk", "include", "config"), + join(FRAMEWORK_DIR, "tools", "sdk", "include", "bt"), + join(FRAMEWORK_DIR, "tools", "sdk", "include", "driver"), + join(FRAMEWORK_DIR, "tools", "sdk", "include", "esp32"), + join(FRAMEWORK_DIR, "tools", "sdk", "include", "freertos"), + join(FRAMEWORK_DIR, "tools", "sdk", "include", "log"), + join(FRAMEWORK_DIR, "tools", "sdk", "include", "lwip"), + join(FRAMEWORK_DIR, "tools", "sdk", "include", "newlib"), + join(FRAMEWORK_DIR, "tools", "sdk", "include", "nvs_flash"), + join(FRAMEWORK_DIR, "tools", "sdk", "include", "spi_flash"), + join(FRAMEWORK_DIR, "tools", "sdk", "include", "tcpip_adapter"), + join(FRAMEWORK_DIR, "tools", "sdk", "include", "expat"), + join(FRAMEWORK_DIR, "tools", "sdk", "include", "json"), + join(FRAMEWORK_DIR, "tools", "sdk", "include", "mbedtls"), + join(FRAMEWORK_DIR, "tools", "sdk", "include", "nghttp"), + join(FRAMEWORK_DIR, "cores", env.BoardConfig().get("build.core")) + ], + LIBPATH=[ + join(FRAMEWORK_DIR, "tools", "sdk", "lib"), + join(FRAMEWORK_DIR, "tools", "sdk", "ld"), + ], + LIBS=[ + "hal", "core", "net80211", "phy", "rtc", "pp", "wpa", + "smartconfig", "btdm_app", "bt", "driver", "esp32", "crypto", "expat", + "freertos", "json", "log", "lwip", "mbedtls", "nghttp", "nvs_flash", + "spi_flash", "tcpip_adapter", "gcc", "m", "c" + ] +) + +env.Append( + LIBSOURCE_DIRS=[ + join(FRAMEWORK_DIR, "libraries") + ], + + LINKFLAGS=[ + "-T", "esp32.common.ld", + "-T", "esp32.rom.ld", + "-T", "esp32.peripherals.ld" + ] +) + +# +# Target: Build Core Library +# + +libs = [] + +if "build.variant" in env.BoardConfig(): + env.Append( + CPPPATH=[ + join(FRAMEWORK_DIR, "variants", + env.BoardConfig().get("build.variant")) + ] + ) + libs.append(env.BuildLibrary( + join("$BUILD_DIR", "FrameworkArduinoVariant"), + join(FRAMEWORK_DIR, "variants", env.BoardConfig().get("build.variant")) + )) + +envsafe = env.Clone() + +libs.append(envsafe.BuildLibrary( + join("$BUILD_DIR", "FrameworkArduino"), + join(FRAMEWORK_DIR, "cores", env.BoardConfig().get("build.core")) +)) + +env.Prepend(LIBS=libs) diff --git a/builder/frameworks/espidf.py b/builder/frameworks/espidf.py index 9a6473b48..3afdd8791 100644 --- a/builder/frameworks/espidf.py +++ b/builder/frameworks/espidf.py @@ -13,11 +13,93 @@ # limitations under the License. """ -ESP IDF +Espressif IDF -Espressif IoT Development Framework. Official development framework for ESP32. +Espressif IoT Development Framework for ESP32 MCU https://github.com/espressif/esp-idf """ -# TODO \ No newline at end of file +from os import listdir +from os.path import isdir, join + +from SCons.Script import DefaultEnvironment + +env = DefaultEnvironment() +platform = env.PioPlatform() + +FRAMEWORK_DIR = platform.get_package_dir("framework-espidf") +FRAMEWORK_VERSION = platform.get_package_version( + "framework-espidf") +assert isdir(FRAMEWORK_DIR) + + +env.Prepend( + CPPPATH=[ + join(FRAMEWORK_DIR, "config"), + join(FRAMEWORK_DIR, "components", "nghttp", "include"), + join(FRAMEWORK_DIR, "components", "nghttp", "port", "include"), + join(FRAMEWORK_DIR, "components", "bt", "include"), + join(FRAMEWORK_DIR, "components", "driver", "include"), + join(FRAMEWORK_DIR, "components", "esp32", "include"), + join(FRAMEWORK_DIR, "components", "freertos", "include"), + join(FRAMEWORK_DIR, "components", "freertos", "include", "freertos"), + join(FRAMEWORK_DIR, "components", "log", "include"), + join(FRAMEWORK_DIR, "components", "newlib", "include"), + join(FRAMEWORK_DIR, "components", "nvs_flash", "include"), + join(FRAMEWORK_DIR, "components", "spi_flash", "include"), + join(FRAMEWORK_DIR, "components", "tcpip_adapter", "include"), + join(FRAMEWORK_DIR, "components", "lwip", "include", "lwip"), + join(FRAMEWORK_DIR, "components", "lwip", "include", "lwip", "port"), + join(FRAMEWORK_DIR, "components", "lwip", "include", "lwip", "posix"), + join(FRAMEWORK_DIR, "components", "expat", "include", "expat"), + join(FRAMEWORK_DIR, "components", "expat", "port", "include"), + join(FRAMEWORK_DIR, "components", "json", "include"), + join(FRAMEWORK_DIR, "components", "json", "port", "include"), + join(FRAMEWORK_DIR, "components", "mbedtls", "include"), + join(FRAMEWORK_DIR, "components", "mbedtls", "port", "include") + ], + + LIBPATH=[ + join(FRAMEWORK_DIR, "components", "esp32"), + join(FRAMEWORK_DIR, "components", "esp32", "lib"), + join(FRAMEWORK_DIR, "components", "bt", "lib"), + join(FRAMEWORK_DIR, "components", "newlib", "lib"), + join(FRAMEWORK_DIR, "components", "esp32", "ld") + ], + + LIBS=[ + "hal", "crypto", "core", "net80211", "phy", "rtc", "pp", "wpa", + "smartconfig", "btdm_app", "m", "c", "gcc" + ] +) + +env.Append( + LIBSOURCE_DIRS=[ + join(FRAMEWORK_DIR, "libraries") + ], + + LINKFLAGS=[ + "-T", "esp32.common.ld", + "-T", "esp32.rom.ld", + "-T", "esp32.peripherals.ld" + ], +) + +# +# Target: Build Core Library +# + +libs = [] + +for d in listdir(join(FRAMEWORK_DIR, "components")): + if d == "bootloader": + continue + if isdir(join(FRAMEWORK_DIR, "components", d)): + libs.append(env.BuildLibrary( + join("$BUILD_DIR", "IDFComponents_%s" % d), + join(FRAMEWORK_DIR, "components", d), + src_filter="+<*> -" + )) + +env.Prepend(LIBS=libs) diff --git a/builder/main.py b/builder/main.py index edbcab18a..388fd80b5 100644 --- a/builder/main.py +++ b/builder/main.py @@ -12,4 +12,253 @@ # See the License for the specific language governing permissions and # limitations under the License. -# @TODO + +import re +from os.path import join + +from SCons.Script import (AlwaysBuild, Builder, Default, DefaultEnvironment) + + +def _get_board_f_flash(env): + frequency = env.subst("$BOARD_F_FLASH") + frequency = str(frequency).replace("L", "") + return str(int(int(frequency) / 1000000)) + "m" + + +def build_espidf_bootloader(): + envsafe = env.Clone() + framework_dir = env.subst("$ESPIDF_DIR") + envsafe.Replace( + CPPDEFINES=["ESP_PLATFORM", "BOOTLOADER_BUILD=1"], + + LIBPATH=[ + join(framework_dir, "components", "esp32", "ld"), + join(framework_dir, "components", "bootloader", "src", "main") + ], + + LINKFLAGS=[ + "-Os", + "-nostdlib", + "-Wl,-static", + "-u", "call_user_start_cpu0", + "-Wl,-static", + "-Wl,--gc-sections", + "-T", "esp32.bootloader.ld", + "-T", "esp32.rom.ld" + ] + ), + + envsafe.Append(CCFLAGS=["-fstrict-volatile-bitfields"]) + + envsafe.Replace( + LIBS=[ + envsafe.BuildLibrary( + join("$BUILD_DIR", "bootloaderLog"), + join(framework_dir, "components", "log") + ), "gcc" + ] + ) + + return envsafe.Program( + join("$BUILD_DIR", "bootloader.elf"), + envsafe.CollectBuildFiles( + join("$BUILD_DIR", "bootloader"), + join(framework_dir, "components", "bootloader", "src", "main") + ) + ) + + +env = DefaultEnvironment() +platform = env.PioPlatform() + +env.Replace( + __get_board_f_flash=_get_board_f_flash, + + AR="xtensa-esp32-elf-ar", + AS="xtensa-esp32-elf-as", + CC="xtensa-esp32-elf-gcc", + CXX="xtensa-esp32-elf-g++", + OBJCOPY=join(platform.get_package_dir("tool-esptool"), "esptool.py"), + RANLIB="xtensa-esp32-elf-ranlib", + SIZETOOL="xtensa-esp32-elf-size", + + ARFLAGS=["rcs"], + + ASFLAGS=["-x", "assembler-with-cpp"], + + CFLAGS=["-std=gnu99"], + + CCFLAGS=[ + "-Os", # optimize for size + "-nostdlib", + "-Wpointer-arith", + "-Wno-error=unused-function", + "-Wno-error=unused-but-set-variable", + "-Wno-error=unused-variable", + "-mlongcalls", + "-ffunction-sections", + "-fdata-sections" + ], + + CXXFLAGS=[ + "-fno-rtti", + "-fno-exceptions", + "-std=gnu++11" + ], + + CPPDEFINES=[ + "ESP32", + "ESP_PLATFORM", + "F_CPU=$BOARD_F_CPU", + "HAVE_CONFIG_H", + "MBEDTLS_CONFIG_FILE=\\\"mbedtls/esp_config.h\\\"" + ], + + LINKFLAGS=[ + "-Os", + "-nostdlib", + "-Wl,-static", + "-u", "call_user_start_cpu0", + "-Wl,-static", + "-Wl,--undefined=uxTopUsedPriority", + "-Wl,--gc-sections" + ], + + # + # Packages + # + + FRAMEWORK_ARDUINOESP32_DIR=platform.get_package_dir( + "framework-arduinoespressif32"), + ESPIDF_DIR=platform.get_package_dir("framework-espidf"), + + # + # Upload + # + + UPLOADER=join(platform.get_package_dir("tool-esptool"), "esptool.py"), + + UPLOADERFLAGS=[ + "--chip", "esp32", + "--port", '"$UPLOAD_PORT"', + "--baud", "$UPLOAD_SPEED", + "write_flash", "-z", + "--flash_mode", "$BOARD_FLASH_MODE", + "--flash_freq", "${__get_board_f_flash(__env__)}" + ], + + UPLOADCMD='"$PYTHONEXE" "$UPLOADER" $UPLOADERFLAGS $SOURCE', + + PROGNAME="firmware", + PROGSUFFIX=".elf" +) + +if env.subst("$PIOFRAMEWORK") == "arduino": + framework_dir = platform.get_package_dir("framework-arduinoespressif32") + env.Append( + UPLOADERFLAGS=[ + "0x1000", join("$FRAMEWORK_ARDUINOESP32_DIR", "tools", + "sdk", "bin", "bootloader.bin"), + "0x4000", join("$FRAMEWORK_ARDUINOESP32_DIR", "tools", + "sdk", "bin", "partitions_singleapp.bin"), + "0x10000" + ] + ) +if env.subst("$PIOFRAMEWORK") == "espidf": + framework_dir = platform.get_package_dir("framework-espidf") + env.Append( + UPLOADERFLAGS=[ + "0x1000", join("$BUILD_DIR", "bootloader.bin"), + "0x4000", join("$BUILD_DIR", "partitions_singleapp.bin"), + "0x10000" + ], + + PTABLE_SCRIPT=join("$ESPIDF_DIR", "components", + "partition_table", "gen_esp32part.py"), + + PTABLE_FLAGS=[ + "-q", join("$ESPIDF_DIR", "components", + "partition_table", "partitions_singleapp.csv"), + join(env.subst("$BUILD_DIR"), "partitions_singleapp.bin") + + ], + + PTABLE_CMD='"$PYTHONEXE" "$PTABLE_SCRIPT" $PTABLE_FLAGS' + ) + + +env.Append( + ASFLAGS=env.get("CCFLAGS", [])[:] +) + +# +# Framework and SDK specific configuration +# + +env.Append( + BUILDERS=dict( + ElfToBin=Builder( + action=env.VerboseAction(" ".join([ + '"$PYTHONEXE" "$OBJCOPY"', + "--chip", "esp32", + "elf2image", + "--flash_mode", "$BOARD_FLASH_MODE", + "--flash_freq", "${__get_board_f_flash(__env__)}", + "-o", "$TARGET", "$SOURCES" + ]), "Building $TARGET"), + suffix=".bin" + ) + ) +) + +# +# Target: Build executable and linkable firmware or SPIFFS image +# + + +def __tmp_hook_before_pio_3_2(): + env.ProcessFlags(env.get("BUILD_FLAGS")) + # append specified LD_SCRIPT + if ("LDSCRIPT_PATH" in env and + not any(["-Wl,-T" in f for f in env['LINKFLAGS']])): + env.Append(LINKFLAGS=['-Wl,-T"$LDSCRIPT_PATH"']) + + +target_elf = env.BuildProgram() +if "PIOFRAMEWORK" in env: + target_firm = env.ElfToBin(join("$BUILD_DIR", "firmware"), target_elf) + +if env.subst("$PIOFRAMEWORK") == "espidf": + bootloader_bin = env.ElfToBin( + join("$BUILD_DIR", "bootloader"), build_espidf_bootloader()) + target_buildprog = env.Alias( + "buildprog", [target_firm, bootloader_bin], "$PTABLE_CMD") +else: + target_buildprog = env.Alias("buildprog", target_firm) + + +# +# Target: Print binary size +# + +target_size = env.Alias( + "size", target_elf, + env.VerboseAction("$SIZEPRINTCMD", "Calculating size $SOURCE")) +AlwaysBuild(target_size) + +# +# Target: Upload firmware or SPIFFS image +# + +target_upload = env.Alias( + "upload", target_firm, + [env.VerboseAction(env.AutodetectUploadPort, "Looking for upload port..."), + env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")]) +env.AlwaysBuild(target_upload) + + +# +# Default targets +# + +Default([target_buildprog, target_size]) diff --git a/examples/arduino-blink/.gitignore b/examples/arduino-blink/.gitignore new file mode 100644 index 000000000..5402c188e --- /dev/null +++ b/examples/arduino-blink/.gitignore @@ -0,0 +1,3 @@ +.pioenvs +.clang_complete +.gcc-flags.json diff --git a/examples/arduino-blink/.travis.yml b/examples/arduino-blink/.travis.yml new file mode 100644 index 000000000..ac0a029dc --- /dev/null +++ b/examples/arduino-blink/.travis.yml @@ -0,0 +1,65 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < http://docs.platformio.org/en/stable/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < http://docs.platformio.org/en/stable/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < http://docs.platformio.org/en/stable/userguide/cmd_ci.html > +# +# +# Please choose one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to by used as a library with examples +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/arduino-blink/README.rst b/examples/arduino-blink/README.rst new file mode 100644 index 000000000..2bb346aec --- /dev/null +++ b/examples/arduino-blink/README.rst @@ -0,0 +1,38 @@ +.. Copyright 2014-present PlatformIO + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +How to build PlatformIO based project +===================================== + +1. `Install PlatformIO `_ +2. Download `development platform with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platform-espressif32/examples/arduino-blink + + # Build project + > platformio run + + # Upload firmware + > platformio run --target upload + + # Build specific environment + > platformio run -e nodemcuv2 + + # Upload firmware for the specific environment + > platformio run -e nodemcuv2 --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/arduino-blink/lib/readme.txt b/examples/arduino-blink/lib/readme.txt new file mode 100644 index 000000000..0d0e7be40 --- /dev/null +++ b/examples/arduino-blink/lib/readme.txt @@ -0,0 +1,38 @@ + +This directory is intended for the project specific (private) libraries. +PlatformIO will compile them to static libraries and link to executable file. + +The source code of each library should be placed in separate directory, like +"lib/private_lib/[here are source files]". + +For example, see how can be organized `Foo` and `Bar` libraries: + +|--lib +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| |--Foo +| | |- Foo.c +| | |- Foo.h +| |- readme.txt --> THIS FILE +|- platformio.ini +|--src + |- main.c + +Then in `src/main.c` you should use: + +#include +#include + +// rest H/C/CPP code + +PlatformIO will find your libraries automatically, configure preprocessor's +include paths and build them. + +See additional options for PlatformIO Library Dependency Finder `lib_*`: + +http://docs.platformio.org/en/stable/projectconf.html#lib-install + diff --git a/examples/arduino-blink/platformio.ini b/examples/arduino-blink/platformio.ini new file mode 100644 index 000000000..830b59189 --- /dev/null +++ b/examples/arduino-blink/platformio.ini @@ -0,0 +1,13 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter, extra scripting +; Upload options: custom port, speed and extra flags +; Library options: dependencies, extra library storages +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/en/stable/projectconf.html + +[env:esp32] +platform = espressif32 +framework = arduino +board = esp32 diff --git a/examples/arduino-blink/src/Blink.cpp b/examples/arduino-blink/src/Blink.cpp new file mode 100644 index 000000000..f4059a0cf --- /dev/null +++ b/examples/arduino-blink/src/Blink.cpp @@ -0,0 +1,27 @@ +/* + * Blink + * Turns on an LED on for one second, + * then off for one second, repeatedly. + */ + +#include + +#define LED_BUILTIN 13 + +void setup() +{ + // initialize LED digital pin as an output. + pinMode(LED_BUILTIN, OUTPUT); +} + +void loop() +{ + // turn the LED on (HIGH is the voltage level) + digitalWrite(LED_BUILTIN, HIGH); + // wait for a second + delay(1000); + // turn the LED off by making the voltage LOW + digitalWrite(LED_BUILTIN, LOW); + // wait for a second + delay(1000); +} diff --git a/examples/arduino-wifiscan/.gitignore b/examples/arduino-wifiscan/.gitignore new file mode 100644 index 000000000..5402c188e --- /dev/null +++ b/examples/arduino-wifiscan/.gitignore @@ -0,0 +1,3 @@ +.pioenvs +.clang_complete +.gcc-flags.json diff --git a/examples/arduino-wifiscan/.travis.yml b/examples/arduino-wifiscan/.travis.yml new file mode 100644 index 000000000..ac0a029dc --- /dev/null +++ b/examples/arduino-wifiscan/.travis.yml @@ -0,0 +1,65 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < http://docs.platformio.org/en/stable/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < http://docs.platformio.org/en/stable/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < http://docs.platformio.org/en/stable/userguide/cmd_ci.html > +# +# +# Please choose one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to by used as a library with examples +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/arduino-wifiscan/README.rst b/examples/arduino-wifiscan/README.rst new file mode 100644 index 000000000..eb2609bee --- /dev/null +++ b/examples/arduino-wifiscan/README.rst @@ -0,0 +1,38 @@ +.. Copyright 2014-present PlatformIO + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +How to build PlatformIO based project +===================================== + +1. `Install PlatformIO `_ +2. Download `development platform with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platform-espressif32/examples/arduino-wifiscan + + # Build project + > platformio run + + # Upload firmware + > platformio run --target upload + + # Build specific environment + > platformio run -e nodemcuv2 + + # Upload firmware for the specific environment + > platformio run -e nodemcuv2 --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/arduino-wifiscan/lib/readme.txt b/examples/arduino-wifiscan/lib/readme.txt new file mode 100644 index 000000000..0d0e7be40 --- /dev/null +++ b/examples/arduino-wifiscan/lib/readme.txt @@ -0,0 +1,38 @@ + +This directory is intended for the project specific (private) libraries. +PlatformIO will compile them to static libraries and link to executable file. + +The source code of each library should be placed in separate directory, like +"lib/private_lib/[here are source files]". + +For example, see how can be organized `Foo` and `Bar` libraries: + +|--lib +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| |--Foo +| | |- Foo.c +| | |- Foo.h +| |- readme.txt --> THIS FILE +|- platformio.ini +|--src + |- main.c + +Then in `src/main.c` you should use: + +#include +#include + +// rest H/C/CPP code + +PlatformIO will find your libraries automatically, configure preprocessor's +include paths and build them. + +See additional options for PlatformIO Library Dependency Finder `lib_*`: + +http://docs.platformio.org/en/stable/projectconf.html#lib-install + diff --git a/examples/arduino-wifiscan/platformio.ini b/examples/arduino-wifiscan/platformio.ini new file mode 100644 index 000000000..830b59189 --- /dev/null +++ b/examples/arduino-wifiscan/platformio.ini @@ -0,0 +1,13 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter, extra scripting +; Upload options: custom port, speed and extra flags +; Library options: dependencies, extra library storages +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/en/stable/projectconf.html + +[env:esp32] +platform = espressif32 +framework = arduino +board = esp32 diff --git a/examples/arduino-wifiscan/src/WiFiScan.ino b/examples/arduino-wifiscan/src/WiFiScan.ino new file mode 100644 index 000000000..5d11fbb69 --- /dev/null +++ b/examples/arduino-wifiscan/src/WiFiScan.ino @@ -0,0 +1,48 @@ +/* + * This sketch demonstrates how to scan WiFi networks. + * The API is almost the same as with the WiFi Shield library, + * the most obvious difference being the different file you need to include: + */ +#include "WiFi.h" + +void setup() +{ + Serial.begin(115200); + + // Set WiFi to station mode and disconnect from an AP if it was previously connected + WiFi.mode(WIFI_STA); + WiFi.disconnect(); + delay(100); + + Serial.println("Setup done"); +} + +void loop() +{ + Serial.println("scan start"); + + // WiFi.scanNetworks will return the number of networks found + int n = WiFi.scanNetworks(); + Serial.println("scan done"); + if (n == 0) { + Serial.println("no networks found"); + } else { + Serial.print(n); + Serial.println(" networks found"); + for (int i = 0; i < n; ++i) { + // Print SSID and RSSI for each network found + Serial.print(i + 1); + Serial.print(": "); + Serial.print(WiFi.SSID(i)); + Serial.print(" ("); + Serial.print(WiFi.RSSI(i)); + Serial.print(")"); + Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*"); + delay(10); + } + } + Serial.println(""); + + // Wait a bit before scanning again + delay(5000); +} diff --git a/examples/espidf-http-request/.gitignore b/examples/espidf-http-request/.gitignore new file mode 100644 index 000000000..5402c188e --- /dev/null +++ b/examples/espidf-http-request/.gitignore @@ -0,0 +1,3 @@ +.pioenvs +.clang_complete +.gcc-flags.json diff --git a/examples/espidf-http-request/.travis.yml b/examples/espidf-http-request/.travis.yml new file mode 100644 index 000000000..72c6e43ff --- /dev/null +++ b/examples/espidf-http-request/.travis.yml @@ -0,0 +1,65 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < http://docs.platformio.org/en/stable/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < http://docs.platformio.org/en/stable/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < http://docs.platformio.org/en/stable/userguide/cmd_ci.html > +# +# +# Please choice one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to by used as a library with examples +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/espidf-http-request/README.rst b/examples/espidf-http-request/README.rst new file mode 100644 index 000000000..939467a2d --- /dev/null +++ b/examples/espidf-http-request/README.rst @@ -0,0 +1,29 @@ +.. Copyright 2014-present PlatformIO + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +How to build PlatformIO based project +===================================== + +1. `Install PlatformIO `_ +2. Download `development platform with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platform-espressif8266/examples/espidf-http-request + + # Process example project + > platformio run + + # Upload firmware + > platformio run --target upload diff --git a/examples/espidf-http-request/lib/readme.txt b/examples/espidf-http-request/lib/readme.txt new file mode 100644 index 000000000..a3271c795 --- /dev/null +++ b/examples/espidf-http-request/lib/readme.txt @@ -0,0 +1,38 @@ + +This directory is intended for the project specific (private) libraries. +PlatformIO will compile them to static libraries and link to executable file. + +The source code of each library should be placed in separate directory, like +"lib/private_lib/[here are source files]". + +For example, see how can be organised `Foo` and `Bar` libraries: + +|--lib +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| |--Foo +| | |- Foo.c +| | |- Foo.h +| |- readme.txt --> THIS FILE +|- platformio.ini +|--src + |- main.c + +Then in `src/main.c` you should use: + +#include +#include + +// rest H/C/CPP code + +PlatformIO will find your libraries automatically, configure preprocessor's +include paths and build them. + +See additional options for PlatformIO Library Dependency Finder `lib_*`: + +http://docs.platformio.org/en/stable/projectconf.html#lib-install + diff --git a/examples/espidf-http-request/platformio.ini b/examples/espidf-http-request/platformio.ini new file mode 100644 index 000000000..55eafde9d --- /dev/null +++ b/examples/espidf-http-request/platformio.ini @@ -0,0 +1,14 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter, extra scripting +; Upload options: custom port, speed and extra flags +; Library options: dependencies, extra library storages +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/en/stable/projectconf.html + +[env:esp32] +platform = espressif32 +framework = espidf +board = esp32 +build_flags = -DCONFIG_WIFI_SSID=\"ESP_AP\" -DCONFIG_WIFI_PASSWORD=\"MYPASS\" \ No newline at end of file diff --git a/examples/espidf-http-request/src/main.c b/examples/espidf-http-request/src/main.c new file mode 100644 index 000000000..1f8d988cf --- /dev/null +++ b/examples/espidf-http-request/src/main.c @@ -0,0 +1,181 @@ +/* HTTP GET Example using plain POSIX sockets + + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/event_groups.h" +#include "esp_system.h" +#include "esp_wifi.h" +#include "esp_event_loop.h" +#include "esp_log.h" +#include "nvs_flash.h" + +#include "lwip/err.h" +#include "lwip/sockets.h" +#include "lwip/sys.h" +#include "lwip/netdb.h" +#include "lwip/dns.h" + +/* The examples use simple WiFi configuration that you can set via + 'make menuconfig'. + + If you'd rather not, just change the below entries to strings with + the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid" +*/ +#define EXAMPLE_WIFI_SSID CONFIG_WIFI_SSID +#define EXAMPLE_WIFI_PASS CONFIG_WIFI_PASSWORD + +/* FreeRTOS event group to signal when we are connected & ready to make a request */ +static EventGroupHandle_t wifi_event_group; + +/* The event group allows multiple bits for each event, + but we only care about one event - are we connected + to the AP with an IP? */ +const int CONNECTED_BIT = BIT0; + +/* Constants that aren't configurable in menuconfig */ +#define WEB_SERVER "example.com" +#define WEB_PORT 80 +#define WEB_URL "http://example.com/" + +static const char *TAG = "example"; + +static const char *REQUEST = "GET " WEB_URL " HTTP/1.1\n" + "Host: "WEB_SERVER"\n" + "User-Agent: esp-idf/1.0 esp32\n" + "\n"; + +static esp_err_t event_handler(void *ctx, system_event_t *event) +{ + switch(event->event_id) { + case SYSTEM_EVENT_STA_START: + esp_wifi_connect(); + break; + case SYSTEM_EVENT_STA_GOT_IP: + xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); + break; + case SYSTEM_EVENT_STA_DISCONNECTED: + /* This is a workaround as ESP32 WiFi libs don't currently + auto-reassociate. */ + esp_wifi_connect(); + xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); + break; + default: + break; + } + return ESP_OK; +} + +static void initialise_wifi(void) +{ + tcpip_adapter_init(); + wifi_event_group = xEventGroupCreate(); + ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) ); + wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); + ESP_ERROR_CHECK( esp_wifi_init(&cfg) ); + ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) ); + wifi_config_t wifi_config = { + .sta = { + .ssid = EXAMPLE_WIFI_SSID, + .password = EXAMPLE_WIFI_PASS, + }, + }; + ESP_LOGI(TAG, "Setting WiFi configuration SSID %s...", wifi_config.sta.ssid); + ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) ); + ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &wifi_config) ); + ESP_ERROR_CHECK( esp_wifi_start() ); +} + +static void http_get_task(void *pvParameters) +{ + const struct addrinfo hints = { + .ai_family = AF_INET, + .ai_socktype = SOCK_STREAM, + }; + struct addrinfo *res; + struct in_addr *addr; + int s, r; + char recv_buf[64]; + + while(1) { + /* Wait for the callback to set the CONNECTED_BIT in the + event group. + */ + xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, + false, true, portMAX_DELAY); + ESP_LOGI(TAG, "Connected to AP"); + + int err = getaddrinfo(WEB_SERVER, "80", &hints, &res); + + if(err != 0 || res == NULL) { + ESP_LOGE(TAG, "DNS lookup failed err=%d res=%p", err, res); + vTaskDelay(1000 / portTICK_RATE_MS); + continue; + } + + /* Code to print the resolved IP. + + Note: inet_ntoa is non-reentrant, look at ipaddr_ntoa_r for "real" code */ + addr = &((struct sockaddr_in *)res->ai_addr)->sin_addr; + ESP_LOGI(TAG, "DNS lookup succeeded. IP=%s", inet_ntoa(*addr)); + + s = socket(res->ai_family, res->ai_socktype, 0); + if(s < 0) { + ESP_LOGE(TAG, "... Failed to allocate socket."); + freeaddrinfo(res); + vTaskDelay(1000 / portTICK_RATE_MS); + continue; + } + ESP_LOGI(TAG, "... allocated socket\r\n"); + + if(connect(s, res->ai_addr, res->ai_addrlen) != 0) { + ESP_LOGE(TAG, "... socket connect failed errno=%d", errno); + close(s); + freeaddrinfo(res); + vTaskDelay(4000 / portTICK_RATE_MS); + continue; + } + + ESP_LOGI(TAG, "... connected"); + freeaddrinfo(res); + + if (write(s, REQUEST, strlen(REQUEST)) < 0) { + ESP_LOGE(TAG, "... socket send failed"); + close(s); + vTaskDelay(4000 / portTICK_RATE_MS); + continue; + } + ESP_LOGI(TAG, "... socket send success"); + + /* Read HTTP response */ + do { + bzero(recv_buf, sizeof(recv_buf)); + r = read(s, recv_buf, sizeof(recv_buf)-1); + for(int i = 0; i < r; i++) { + putchar(recv_buf[i]); + } + } while(r > 0); + + ESP_LOGI(TAG, "... done reading from socket. Last read return=%d errno=%d\r\n", r, errno); + close(s); + for(int countdown = 10; countdown >= 0; countdown--) { + ESP_LOGI(TAG, "%d... ", countdown); + vTaskDelay(1000 / portTICK_RATE_MS); + } + ESP_LOGI(TAG, "Starting again!"); + } +} + +void app_main() +{ + nvs_flash_init(); + system_init(); + initialise_wifi(); + xTaskCreate(&http_get_task, "http_get_task", 2048, NULL, 5, NULL); +} \ No newline at end of file diff --git a/platform.json b/platform.json index 8e3b8ede8..a3122efe5 100644 --- a/platform.json +++ b/platform.json @@ -33,7 +33,7 @@ "packages": { "toolchain-xtensa32": { "type": "toolchain", - "version": "~1.40802.0" + "version": "~1.40805.0" }, "framework-arduinoespressif32": { "type": "framework", @@ -44,6 +44,10 @@ "type": "framework", "optional": true, "version": "~1.90.0" + }, + "tool-esptool": { + "type": "uploader", + "version": "~1.409.0" } } } From 271f61fb27f76b36f58ca64cd4b7f77e5d58e6ec Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 27 Oct 2016 23:19:43 +0300 Subject: [PATCH 03/10] Fix `buildprog` target --- builder/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builder/main.py b/builder/main.py index 388fd80b5..1edf30d47 100644 --- a/builder/main.py +++ b/builder/main.py @@ -228,13 +228,13 @@ def __tmp_hook_before_pio_3_2(): if "PIOFRAMEWORK" in env: target_firm = env.ElfToBin(join("$BUILD_DIR", "firmware"), target_elf) -if env.subst("$PIOFRAMEWORK") == "espidf": +if "espidf" in env.subst("$PIOFRAMEWORK"): bootloader_bin = env.ElfToBin( join("$BUILD_DIR", "bootloader"), build_espidf_bootloader()) target_buildprog = env.Alias( "buildprog", [target_firm, bootloader_bin], "$PTABLE_CMD") else: - target_buildprog = env.Alias("buildprog", target_firm) + target_buildprog = env.Alias("buildprog", target_firm, target_firm) # From 8c2e29da2459de038abc9c097d52fb1bf785b5a2 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 29 Oct 2016 19:31:23 +0300 Subject: [PATCH 04/10] Added packages, updated Arduino for ESP32 --- .travis.yml | 2 +- README.md | 2 +- boards/esp32.json | 27 --------------------- boards/esp32dev.json | 27 +++++++++++++++++++++ builder/main.py | 8 +++--- examples/arduino-blink/platformio.ini | 4 +-- examples/arduino-wifiscan/platformio.ini | 4 +-- examples/espidf-http-request/platformio.ini | 4 +-- platform.json | 6 ++--- 9 files changed, 42 insertions(+), 42 deletions(-) delete mode 100644 boards/esp32.json create mode 100644 boards/esp32dev.json diff --git a/.travis.yml b/.travis.yml index a39fb22b3..77fc687cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,6 +19,6 @@ notifications: slack: rooms: - secure: zKv2HzE18J8f+mHUeoNylXSvh6IBlfaaf2H96cicwGB3p53jOXBXO/99N7MVe6UnkJludmVeTGim4timqZdCOLglUPxIo8lSFSp5+4dO+WCpZB7z9P+vw4oy+qV+5Kp1EhDQnOybg/7DdYiJiCVz1psDZH+oYRqnW/+lU6s48svItrUpy6s36OeZJsYP9jjoWnSyzAemvO3kurC3Gib475tJfKIMVd5l9Lmj3yuALonDj6z6DXHyM8lExxRbaAe22CvHzuTXs3N0S/d34Gdi7+f/+NOcKrdBgNbzMnchtwLgnX8uqGAp+3D96JmTNFxdBc1uY82WdDY/ij2X/f6GFzIWgXRI7medHxvWqUFdRC1Z6bK1t36QsPgot2A3nT4oJnlJ/NqpwsjnSN60emDmkbDUf0p1JzErhHHQTVrasTWOX7yXVteXXIIP1HYR1A+5VMjO+6r20J9AM+QYm/b+9Rmy6t2uMdmimiRTy2fQxH/eExWSmJqrzdvgWHPc8gPxj9Ib8mryVegFlkajswv/rh2L8I5FZwNTot0+qwYFyst+hNm0PBVBmcyLhSW4v2/sVBwq38ir4NyXtnps46S7VNKh7b8kdO2o4f8oRkv+PWSnnK6N6tej20CAZeBjTh2puIl2HVL47/rCQA7DZMiJP+iGet6HG6pWKktilvfhSLs= + secure: EkXAtWoUQtgtFeiOobnNZmaUgPw7evpo60Tam5jQiKbVK02bCbBODELTSFsGfIj05oAzNm4s1xBTRD3x9bsvPqvfThHwIHZ2M2BlrT06iINsfFXoXM5yCuBAIi8FF61UKmiZn+Pm+IK6OeUFmzXoP5BcpS2LRB0eSoCj0nsF5cj/H+oA6BnCn/5AXhbSQSiHxOPfq/0khQb5dalmf3B9NHq08MEiOLJR5J9zPglKMfE2HR8PS98irN0x1t9+aReMfUJSZrxfqwvWKz/Sb38/2H37A4GOXpsnRDagZXkfw/MSckSxRFtW8p/0LUBQqeaxdC5Z9qIuyDCAeHPm8d0AIArR7Ylz6BjlNVJVdCTAZaNTp7PUV4n1cN7gZPq8NhWnuGG3wdWiYlJEyHmmRjr9adDYTshCl3gf2GOjB5YJIjoNrixkoJwHM2gJLvwuOw7mgo0hLbqW84XSgV6KeSU12AYk9d2nz3AhWVsb4DiKrN+EqnhBVnCygAxYGlNxfZOPG0FIYai2DUsl6PXd3OBmxeNEWG+x7BivG+maaQEyC4SeFaNFIBR1L4F+C0fHW1VxiCvJCb6vB7fOk7fU5UDhpYnrRmSuyAVYR86aZ+3VnZjbjpGac6hfN7Qxg5WeC5Yd6eR2lrNag9lG5zASylZ1nsdlOZloPs8ilGe43mDpAkg= on_failure: always on_success: change diff --git a/README.md b/README.md index 9266572ee..a3c22118b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Espressif 32: development platform for [PlatformIO](http://platformio.org) [![Build Status](https://travis-ci.org/platformio/platform-espressif32.svg?branch=develop)](https://travis-ci.org/platformio/platform-espressif32) -[![Build status](https://ci.appveyor.com/api/projects/status/aob49qatio84iygj/branch/develop?svg=true)](https://ci.appveyor.com/project/ivankravets/platform-espressif32/branch/develop) +[![Build status](https://ci.appveyor.com/api/projects/status/nl087sumhneumse3/branch/develop?svg=true)](https://ci.appveyor.com/project/ivankravets/platform-espressif32/branch/develop) Espressif Systems is a privately held fabless semiconductor company. They provide wireless communications and Wi-Fi chips which are widely used in mobile devices and the Internet of Things applications. diff --git a/boards/esp32.json b/boards/esp32.json deleted file mode 100644 index 2f3d137dc..000000000 --- a/boards/esp32.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "build": { - "core": "esp32", - "extra_flags": "-DESP32_DEV -DARDUINO_ESP32_DEV", - "f_cpu": "160000000L", - "f_flash": "80000000L", - "flash_mode": "dio", - "ldscript": "esp32.out.ld", - "mcu": "esp32", - "variant": "esp32" - }, - "frameworks": [ - "arduino", - "espidf" - ], - "name": "Espressif ESP32 Dev Module", - "upload": { - "maximum_ram_size": 114688, - "maximum_size": 1044464, - "require_upload_port": true, - "resetmethod": "nodemcu", - "speed": 115200, - "wait_for_upload_port": true - }, - "url": "https://en.wikipedia.org/wiki/ESP32", - "vendor": "Espressif" -} diff --git a/boards/esp32dev.json b/boards/esp32dev.json new file mode 100644 index 000000000..8898a484f --- /dev/null +++ b/boards/esp32dev.json @@ -0,0 +1,27 @@ +{ + "build": { + "core": "esp32", + "extra_flags": "-DESP32_DEV -DARDUINO_ESP32_DEV", + "f_cpu": "160000000L", + "f_flash": "80000000L", + "flash_mode": "dio", + "ldscript": "esp32_out.ld", + "mcu": "esp32", + "variant": "esp32" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Espressif ESP32 Dev Module", + "upload": { + "maximum_ram_size": 114688, + "maximum_size": 1044464, + "require_upload_port": true, + "resetmethod": "nodemcu", + "speed": 115200, + "wait_for_upload_port": true + }, + "url": "https://en.wikipedia.org/wiki/ESP32", + "vendor": "Espressif" +} diff --git a/builder/main.py b/builder/main.py index 1edf30d47..53813bbca 100644 --- a/builder/main.py +++ b/builder/main.py @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. - -import re from os.path import join from SCons.Script import (AlwaysBuild, Builder, Default, DefaultEnvironment) @@ -78,7 +76,8 @@ def build_espidf_bootloader(): AS="xtensa-esp32-elf-as", CC="xtensa-esp32-elf-gcc", CXX="xtensa-esp32-elf-g++", - OBJCOPY=join(platform.get_package_dir("tool-esptool"), "esptool.py"), + OBJCOPY=join( + platform.get_package_dir("tool-esptoolpy") or "", "esptool.py"), RANLIB="xtensa-esp32-elf-ranlib", SIZETOOL="xtensa-esp32-elf-size", @@ -136,7 +135,8 @@ def build_espidf_bootloader(): # Upload # - UPLOADER=join(platform.get_package_dir("tool-esptool"), "esptool.py"), + UPLOADER=join( + platform.get_package_dir("tool-esptoolpy") or "", "esptool.py"), UPLOADERFLAGS=[ "--chip", "esp32", diff --git a/examples/arduino-blink/platformio.ini b/examples/arduino-blink/platformio.ini index 830b59189..42a8c81e8 100644 --- a/examples/arduino-blink/platformio.ini +++ b/examples/arduino-blink/platformio.ini @@ -7,7 +7,7 @@ ; Please visit documentation for the other options and examples ; http://docs.platformio.org/en/stable/projectconf.html -[env:esp32] +[env:esp32dev] platform = espressif32 framework = arduino -board = esp32 +board = esp32dev diff --git a/examples/arduino-wifiscan/platformio.ini b/examples/arduino-wifiscan/platformio.ini index 830b59189..42a8c81e8 100644 --- a/examples/arduino-wifiscan/platformio.ini +++ b/examples/arduino-wifiscan/platformio.ini @@ -7,7 +7,7 @@ ; Please visit documentation for the other options and examples ; http://docs.platformio.org/en/stable/projectconf.html -[env:esp32] +[env:esp32dev] platform = espressif32 framework = arduino -board = esp32 +board = esp32dev diff --git a/examples/espidf-http-request/platformio.ini b/examples/espidf-http-request/platformio.ini index 55eafde9d..2f9f3b234 100644 --- a/examples/espidf-http-request/platformio.ini +++ b/examples/espidf-http-request/platformio.ini @@ -7,8 +7,8 @@ ; Please visit documentation for the other options and examples ; http://docs.platformio.org/en/stable/projectconf.html -[env:esp32] +[env:esp32dev] platform = espressif32 framework = espidf -board = esp32 +board = esp32dev build_flags = -DCONFIG_WIFI_SSID=\"ESP_AP\" -DCONFIG_WIFI_PASSWORD=\"MYPASS\" \ No newline at end of file diff --git a/platform.json b/platform.json index a3122efe5..a0cdd6e3f 100644 --- a/platform.json +++ b/platform.json @@ -38,16 +38,16 @@ "framework-arduinoespressif32": { "type": "framework", "optional": true, - "version": "~0.0.0" + "version": "~1.0.0" }, "framework-espidf": { "type": "framework", "optional": true, "version": "~1.90.0" }, - "tool-esptool": { + "tool-esptoolpy": { "type": "uploader", - "version": "~1.409.0" + "version": "~1.0.0" } } } From 06e193e8fa5c6f2249664d9c5cf350e484a8756b Mon Sep 17 00:00:00 2001 From: Valeriy Koval Date: Sun, 6 Nov 2016 16:46:33 +0200 Subject: [PATCH 05/10] Autogenerate linker script for esp-idf --- builder/frameworks/espidf.py | 20 ++++++++++++++++++++ builder/main.py | 6 ++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/builder/frameworks/espidf.py b/builder/frameworks/espidf.py index 3afdd8791..4c5f1b4fb 100644 --- a/builder/frameworks/espidf.py +++ b/builder/frameworks/espidf.py @@ -25,6 +25,8 @@ from SCons.Script import DefaultEnvironment +from platformio.util import exec_command + env = DefaultEnvironment() platform = env.PioPlatform() @@ -34,6 +36,18 @@ assert isdir(FRAMEWORK_DIR) +def generate_ld_script(): + exec_command([ + join(platform.get_package_dir("toolchain-xtensa32") + or "", "bin", env.subst("$CC")), + "-I", join(env.subst("$ESPIDF_DIR"), "config"), + "-C", "-P", "-x", "c", "-E", + join(env.subst("$ESPIDF_DIR"), "components", + "esp32", "ld", "esp32.ld"), + "-o", join(env.subst("$ESPIDF_DIR"), "components", + "esp32", "ld", "esp32_out.ld") + ]) + env.Prepend( CPPPATH=[ join(FRAMEWORK_DIR, "config"), @@ -86,6 +100,12 @@ ], ) +# +# Generate a specific linker script +# + +generate_ld_script() + # # Target: Build Core Library # diff --git a/builder/main.py b/builder/main.py index 53813bbca..d469bc008 100644 --- a/builder/main.py +++ b/builder/main.py @@ -154,7 +154,6 @@ def build_espidf_bootloader(): ) if env.subst("$PIOFRAMEWORK") == "arduino": - framework_dir = platform.get_package_dir("framework-arduinoespressif32") env.Append( UPLOADERFLAGS=[ "0x1000", join("$FRAMEWORK_ARDUINOESP32_DIR", "tools", @@ -165,7 +164,6 @@ def build_espidf_bootloader(): ] ) if env.subst("$PIOFRAMEWORK") == "espidf": - framework_dir = platform.get_package_dir("framework-espidf") env.Append( UPLOADERFLAGS=[ "0x1000", join("$BUILD_DIR", "bootloader.bin"), @@ -229,10 +227,10 @@ def __tmp_hook_before_pio_3_2(): target_firm = env.ElfToBin(join("$BUILD_DIR", "firmware"), target_elf) if "espidf" in env.subst("$PIOFRAMEWORK"): - bootloader_bin = env.ElfToBin( + target_buildboot = env.ElfToBin( join("$BUILD_DIR", "bootloader"), build_espidf_bootloader()) target_buildprog = env.Alias( - "buildprog", [target_firm, bootloader_bin], "$PTABLE_CMD") + "buildprog", [target_firm, target_buildboot], "$PTABLE_CMD") else: target_buildprog = env.Alias("buildprog", target_firm, target_firm) From 22c680eeb65dd3c609a69c0b80aaae26861ba997 Mon Sep 17 00:00:00 2001 From: Valeriy Koval Date: Sun, 6 Nov 2016 16:48:35 +0200 Subject: [PATCH 06/10] Add some new libs to build process for Arduino framework --- builder/frameworks/arduino.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/builder/frameworks/arduino.py b/builder/frameworks/arduino.py index a0aa1ae56..67bb3fd4a 100644 --- a/builder/frameworks/arduino.py +++ b/builder/frameworks/arduino.py @@ -52,6 +52,7 @@ join(FRAMEWORK_DIR, "tools", "sdk", "include", "nvs_flash"), join(FRAMEWORK_DIR, "tools", "sdk", "include", "spi_flash"), join(FRAMEWORK_DIR, "tools", "sdk", "include", "tcpip_adapter"), + join(FRAMEWORK_DIR, "tools", "sdk", "include", "vfs"), join(FRAMEWORK_DIR, "tools", "sdk", "include", "expat"), join(FRAMEWORK_DIR, "tools", "sdk", "include", "json"), join(FRAMEWORK_DIR, "tools", "sdk", "include", "mbedtls"), @@ -66,7 +67,7 @@ "hal", "core", "net80211", "phy", "rtc", "pp", "wpa", "smartconfig", "btdm_app", "bt", "driver", "esp32", "crypto", "expat", "freertos", "json", "log", "lwip", "mbedtls", "nghttp", "nvs_flash", - "spi_flash", "tcpip_adapter", "gcc", "m", "c" + "spi_flash", "tcpip_adapter", "newlib", "vfs", "gcc", "m", "c" ] ) From 5151fa5d0a018eaabc0378e0994bd05839bedec8 Mon Sep 17 00:00:00 2001 From: Valeriy Koval Date: Sun, 13 Nov 2016 21:36:25 +0200 Subject: [PATCH 07/10] Add several new boards --- boards/esp320.json | 27 +++++++++++++++++++++++++++ boards/espea32.json | 27 +++++++++++++++++++++++++++ boards/lolin32.json | 27 +++++++++++++++++++++++++++ boards/nano32.json | 27 +++++++++++++++++++++++++++ boards/quantum.json | 27 +++++++++++++++++++++++++++ 5 files changed, 135 insertions(+) create mode 100644 boards/esp320.json create mode 100644 boards/espea32.json create mode 100644 boards/lolin32.json create mode 100644 boards/nano32.json create mode 100644 boards/quantum.json diff --git a/boards/esp320.json b/boards/esp320.json new file mode 100644 index 000000000..71e38fc68 --- /dev/null +++ b/boards/esp320.json @@ -0,0 +1,27 @@ +{ + "build": { + "core": "esp32", + "extra_flags": "-DESP32_DEV -DARDUINO_ESP320", + "f_cpu": "160000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "ldscript": "esp32_out.ld", + "mcu": "esp32", + "variant": "esp320" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Electronic SweetPeas ESP320", + "upload": { + "maximum_ram_size": 294912, + "maximum_size": 1044464, + "require_upload_port": true, + "resetmethod": "nodemcu", + "speed": 115200, + "wait_for_upload_port": true + }, + "url": "http://www.sweetpeas.se/controller-modules/10-esp210.html", + "vendor": "Electronic SweetPeas" +} diff --git a/boards/espea32.json b/boards/espea32.json new file mode 100644 index 000000000..245fef5f2 --- /dev/null +++ b/boards/espea32.json @@ -0,0 +1,27 @@ +{ + "build": { + "core": "esp32", + "extra_flags": "-DESP32_DEV -DARDUINO_ESPea32", + "f_cpu": "160000000L", + "f_flash": "80000000L", + "flash_mode": "dio", + "ldscript": "esp32_out.ld", + "mcu": "esp32", + "variant": "espea32" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "April Brother ESPea32", + "upload": { + "maximum_ram_size": 294912, + "maximum_size": 1044464, + "require_upload_port": true, + "resetmethod": "nodemcu", + "speed": 115200, + "wait_for_upload_port": true + }, + "url": "https://blog.aprbrother.com/product/espea", + "vendor": "April Brother" +} diff --git a/boards/lolin32.json b/boards/lolin32.json new file mode 100644 index 000000000..822d3a078 --- /dev/null +++ b/boards/lolin32.json @@ -0,0 +1,27 @@ +{ + "build": { + "core": "esp32", + "extra_flags": "-DESP32_DEV -DARDUINO_LoLin32", + "f_cpu": "160000000L", + "f_flash": "80000000L", + "flash_mode": "dio", + "ldscript": "esp32_out.ld", + "mcu": "esp32", + "variant": "lolin32" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "WEMOS LoLin32", + "upload": { + "maximum_ram_size": 294912, + "maximum_size": 1044464, + "require_upload_port": true, + "resetmethod": "nodemcu", + "speed": 115200, + "wait_for_upload_port": true + }, + "url": "https://wemos.cc", + "vendor": "WEMOS" +} diff --git a/boards/nano32.json b/boards/nano32.json new file mode 100644 index 000000000..2988726c2 --- /dev/null +++ b/boards/nano32.json @@ -0,0 +1,27 @@ +{ + "build": { + "core": "esp32", + "extra_flags": "-DESP32_DEV -DARDUINO_NANO32", + "f_cpu": "160000000L", + "f_flash": "80000000L", + "flash_mode": "dio", + "ldscript": "esp32_out.ld", + "mcu": "esp32", + "variant": "nano32" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "MakerAsia Nano32", + "upload": { + "maximum_ram_size": 294912, + "maximum_size": 1044464, + "require_upload_port": true, + "resetmethod": "nodemcu", + "speed": 115200, + "wait_for_upload_port": true + }, + "url": "http://iot-bits.com/nano32-esp32-development-board", + "vendor": "MakerAsia" +} diff --git a/boards/quantum.json b/boards/quantum.json new file mode 100644 index 000000000..e1099aba4 --- /dev/null +++ b/boards/quantum.json @@ -0,0 +1,27 @@ +{ + "build": { + "core": "esp32", + "extra_flags": "-DESP32_DEV -DARDUINO_QUANTUM", + "f_cpu": "160000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "ldscript": "esp32_out.ld", + "mcu": "esp32", + "variant": "quantum" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Noduino Quantum", + "upload": { + "maximum_ram_size": 294912, + "maximum_size": 1044464, + "require_upload_port": true, + "resetmethod": "nodemcu", + "speed": 115200, + "wait_for_upload_port": true + }, + "url": "http://wiki.jackslab.org/Noduino", + "vendor": "Noduino" +} From 6e7196429ed3d5e5c8ac58d20cc75140a78a2aa0 Mon Sep 17 00:00:00 2001 From: Valeriy Koval Date: Sun, 13 Nov 2016 21:42:12 +0200 Subject: [PATCH 08/10] Update build script for espidf framework --- builder/frameworks/espidf.py | 49 +++++++++++++++++++++++++++++------- builder/main.py | 33 ++++++++---------------- 2 files changed, 50 insertions(+), 32 deletions(-) diff --git a/builder/frameworks/espidf.py b/builder/frameworks/espidf.py index 4c5f1b4fb..39c49b588 100644 --- a/builder/frameworks/espidf.py +++ b/builder/frameworks/espidf.py @@ -20,7 +20,8 @@ https://github.com/espressif/esp-idf """ -from os import listdir +import sys +from os import listdir, makedirs from os.path import isdir, join from SCons.Script import DefaultEnvironment @@ -37,20 +38,45 @@ def generate_ld_script(): - exec_command([ + if not isdir(env.subst("$BUILD_DIR")): + makedirs(env.subst("$BUILD_DIR")) + result = exec_command([ join(platform.get_package_dir("toolchain-xtensa32") or "", "bin", env.subst("$CC")), - "-I", join(env.subst("$ESPIDF_DIR"), "config"), + "-I", env.subst("$PROJECTSRC_DIR"), "-C", "-P", "-x", "c", "-E", join(env.subst("$ESPIDF_DIR"), "components", "esp32", "ld", "esp32.ld"), - "-o", join(env.subst("$ESPIDF_DIR"), "components", - "esp32", "ld", "esp32_out.ld") + "-o", join(env.subst("$BUILD_DIR"), "esp32_out.ld") ]) + if result['returncode'] != 0: + sys.stderr.write( + "Cannot create linker script! %s" % result['err']) + env.Exit(1) + + +def generate_ptable(): + if not isdir(env.subst("$BUILD_DIR")): + makedirs(env.subst("$BUILD_DIR")) + + result = exec_command([ + env.subst("$PYTHONEXE"), + join(env.subst("$ESPIDF_DIR"), "components", + "partition_table", "gen_esp32part.py"), + "-q", join(env.subst("$ESPIDF_DIR"), "components", + "partition_table", "partitions_singleapp.csv"), + join(env.subst("$BUILD_DIR"), "partitions_table.bin"), + ]) + + if result['returncode'] != 0: + sys.stderr.write( + "Cannot create partition table! %s" % result['err']) + env.Exit(1) + env.Prepend( CPPPATH=[ - join(FRAMEWORK_DIR, "config"), + join("$PROJECTSRC_DIR"), join(FRAMEWORK_DIR, "components", "nghttp", "include"), join(FRAMEWORK_DIR, "components", "nghttp", "port", "include"), join(FRAMEWORK_DIR, "components", "bt", "include"), @@ -76,10 +102,11 @@ def generate_ld_script(): LIBPATH=[ join(FRAMEWORK_DIR, "components", "esp32"), + join(FRAMEWORK_DIR, "components", "esp32", "ld"), join(FRAMEWORK_DIR, "components", "esp32", "lib"), join(FRAMEWORK_DIR, "components", "bt", "lib"), join(FRAMEWORK_DIR, "components", "newlib", "lib"), - join(FRAMEWORK_DIR, "components", "esp32", "ld") + "$BUILD_DIR" ], LIBS=[ @@ -105,6 +132,7 @@ def generate_ld_script(): # generate_ld_script() +generate_ptable() # # Target: Build Core Library @@ -112,12 +140,15 @@ def generate_ld_script(): libs = [] +ignore_dirs = ( + "bootloader", "esptool_py", "idf_test", "newlib", "partition_table") + for d in listdir(join(FRAMEWORK_DIR, "components")): - if d == "bootloader": + if d in ignore_dirs: continue if isdir(join(FRAMEWORK_DIR, "components", d)): libs.append(env.BuildLibrary( - join("$BUILD_DIR", "IDFComponents_%s" % d), + join("$BUILD_DIR", "%s" % d), join(FRAMEWORK_DIR, "components", d), src_filter="+<*> -" )) diff --git a/builder/main.py b/builder/main.py index d469bc008..d81318bbf 100644 --- a/builder/main.py +++ b/builder/main.py @@ -88,7 +88,8 @@ def build_espidf_bootloader(): CFLAGS=["-std=gnu99"], CCFLAGS=[ - "-Os", # optimize for size + "-Og", + "-g3", "-nostdlib", "-Wpointer-arith", "-Wno-error=unused-function", @@ -102,7 +103,8 @@ def build_espidf_bootloader(): CXXFLAGS=[ "-fno-rtti", "-fno-exceptions", - "-std=gnu++11" + "-std=gnu++11", + "-fstrict-volatile-bitfields" ], CPPDEFINES=[ @@ -114,11 +116,9 @@ def build_espidf_bootloader(): ], LINKFLAGS=[ - "-Os", "-nostdlib", "-Wl,-static", "-u", "call_user_start_cpu0", - "-Wl,-static", "-Wl,--undefined=uxTopUsedPriority", "-Wl,--gc-sections" ], @@ -167,21 +167,9 @@ def build_espidf_bootloader(): env.Append( UPLOADERFLAGS=[ "0x1000", join("$BUILD_DIR", "bootloader.bin"), - "0x4000", join("$BUILD_DIR", "partitions_singleapp.bin"), + "0x4000", join("$BUILD_DIR", "partitions_table.bin"), "0x10000" - ], - - PTABLE_SCRIPT=join("$ESPIDF_DIR", "components", - "partition_table", "gen_esp32part.py"), - - PTABLE_FLAGS=[ - "-q", join("$ESPIDF_DIR", "components", - "partition_table", "partitions_singleapp.csv"), - join(env.subst("$BUILD_DIR"), "partitions_singleapp.bin") - - ], - - PTABLE_CMD='"$PYTHONEXE" "$PTABLE_SCRIPT" $PTABLE_FLAGS' + ] ) @@ -227,12 +215,11 @@ def __tmp_hook_before_pio_3_2(): target_firm = env.ElfToBin(join("$BUILD_DIR", "firmware"), target_elf) if "espidf" in env.subst("$PIOFRAMEWORK"): - target_buildboot = env.ElfToBin( + target_boot = env.ElfToBin( join("$BUILD_DIR", "bootloader"), build_espidf_bootloader()) - target_buildprog = env.Alias( - "buildprog", [target_firm, target_buildboot], "$PTABLE_CMD") -else: - target_buildprog = env.Alias("buildprog", target_firm, target_firm) + env.Depends(target_firm, target_boot) + +target_buildprog = env.Alias("buildprog", target_firm, target_firm) # From f2454c07dde912248b1d6eaaab4b24e5143b9313 Mon Sep 17 00:00:00 2001 From: Valeriy Koval Date: Sun, 13 Nov 2016 21:51:15 +0200 Subject: [PATCH 09/10] Supplement examples with new boards --- examples/arduino-blink/README.rst | 4 +- examples/arduino-blink/platformio.ini | 10 +++ examples/arduino-wifiscan/README.rst | 4 +- examples/arduino-wifiscan/platformio.ini | 14 ++++- examples/arduino-wifiscan/src/WiFiScan.ino | 2 +- examples/espidf-hello-world/.gitignore | 3 + examples/espidf-hello-world/.travis.yml | 65 ++++++++++++++++++++ examples/espidf-hello-world/README.rst | 38 ++++++++++++ examples/espidf-hello-world/lib/readme.txt | 38 ++++++++++++ examples/espidf-hello-world/platformio.ini | 23 +++++++ examples/espidf-hello-world/src/main.c | 32 ++++++++++ examples/espidf-hello-world/src/sdkconfig.h | 53 ++++++++++++++++ examples/espidf-http-request/README.rst | 13 +++- examples/espidf-http-request/platformio.ini | 18 +++++- examples/espidf-http-request/src/sdkconfig.h | 51 +++++++++++++++ 15 files changed, 356 insertions(+), 12 deletions(-) create mode 100644 examples/espidf-hello-world/.gitignore create mode 100644 examples/espidf-hello-world/.travis.yml create mode 100644 examples/espidf-hello-world/README.rst create mode 100644 examples/espidf-hello-world/lib/readme.txt create mode 100644 examples/espidf-hello-world/platformio.ini create mode 100644 examples/espidf-hello-world/src/main.c create mode 100644 examples/espidf-hello-world/src/sdkconfig.h create mode 100644 examples/espidf-http-request/src/sdkconfig.h diff --git a/examples/arduino-blink/README.rst b/examples/arduino-blink/README.rst index 2bb346aec..c455a2da5 100644 --- a/examples/arduino-blink/README.rst +++ b/examples/arduino-blink/README.rst @@ -29,10 +29,10 @@ How to build PlatformIO based project > platformio run --target upload # Build specific environment - > platformio run -e nodemcuv2 + > platformio run -e esp32dev # Upload firmware for the specific environment - > platformio run -e nodemcuv2 --target upload + > platformio run -e esp32dev --target upload # Clean build files > platformio run --target clean diff --git a/examples/arduino-blink/platformio.ini b/examples/arduino-blink/platformio.ini index 42a8c81e8..97486710a 100644 --- a/examples/arduino-blink/platformio.ini +++ b/examples/arduino-blink/platformio.ini @@ -11,3 +11,13 @@ platform = espressif32 framework = arduino board = esp32dev + +[env:quantum] +platform = espressif32 +framework = arduino +board = quantum + +[env:lolin32] +platform = espressif32 +framework = arduino +board = lolin32 diff --git a/examples/arduino-wifiscan/README.rst b/examples/arduino-wifiscan/README.rst index eb2609bee..49dfa1a7c 100644 --- a/examples/arduino-wifiscan/README.rst +++ b/examples/arduino-wifiscan/README.rst @@ -29,10 +29,10 @@ How to build PlatformIO based project > platformio run --target upload # Build specific environment - > platformio run -e nodemcuv2 + > platformio run -e quantum # Upload firmware for the specific environment - > platformio run -e nodemcuv2 --target upload + > platformio run -e quantum --target upload # Clean build files > platformio run --target clean diff --git a/examples/arduino-wifiscan/platformio.ini b/examples/arduino-wifiscan/platformio.ini index 42a8c81e8..c359dfd80 100644 --- a/examples/arduino-wifiscan/platformio.ini +++ b/examples/arduino-wifiscan/platformio.ini @@ -7,7 +7,17 @@ ; Please visit documentation for the other options and examples ; http://docs.platformio.org/en/stable/projectconf.html -[env:esp32dev] +[env:nano32] platform = espressif32 framework = arduino -board = esp32dev +board = nano32 + +[env:espea32] +platform = espressif32 +framework = arduino +board = espea32 + +[env:esp320] +platform = espressif32 +framework = arduino +board = esp320 diff --git a/examples/arduino-wifiscan/src/WiFiScan.ino b/examples/arduino-wifiscan/src/WiFiScan.ino index 5d11fbb69..67ac308ca 100644 --- a/examples/arduino-wifiscan/src/WiFiScan.ino +++ b/examples/arduino-wifiscan/src/WiFiScan.ino @@ -45,4 +45,4 @@ void loop() // Wait a bit before scanning again delay(5000); -} +} \ No newline at end of file diff --git a/examples/espidf-hello-world/.gitignore b/examples/espidf-hello-world/.gitignore new file mode 100644 index 000000000..5402c188e --- /dev/null +++ b/examples/espidf-hello-world/.gitignore @@ -0,0 +1,3 @@ +.pioenvs +.clang_complete +.gcc-flags.json diff --git a/examples/espidf-hello-world/.travis.yml b/examples/espidf-hello-world/.travis.yml new file mode 100644 index 000000000..72c6e43ff --- /dev/null +++ b/examples/espidf-hello-world/.travis.yml @@ -0,0 +1,65 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < http://docs.platformio.org/en/stable/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < http://docs.platformio.org/en/stable/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < http://docs.platformio.org/en/stable/userguide/cmd_ci.html > +# +# +# Please choice one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to by used as a library with examples +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/espidf-hello-world/README.rst b/examples/espidf-hello-world/README.rst new file mode 100644 index 000000000..a30e25cd4 --- /dev/null +++ b/examples/espidf-hello-world/README.rst @@ -0,0 +1,38 @@ +.. Copyright 2014-present PlatformIO + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +How to build PlatformIO based project +===================================== + +1. `Install PlatformIO `_ +2. Download `development platform with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platform-espressif32/examples/espidf-hello-world + + # Build project + > platformio run + + # Upload firmware + > platformio run --target upload + + # Build specific environment + > platformio run -e esp32dev + + # Upload firmware for the specific environment + > platformio run -e esp32dev --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/espidf-hello-world/lib/readme.txt b/examples/espidf-hello-world/lib/readme.txt new file mode 100644 index 000000000..a3271c795 --- /dev/null +++ b/examples/espidf-hello-world/lib/readme.txt @@ -0,0 +1,38 @@ + +This directory is intended for the project specific (private) libraries. +PlatformIO will compile them to static libraries and link to executable file. + +The source code of each library should be placed in separate directory, like +"lib/private_lib/[here are source files]". + +For example, see how can be organised `Foo` and `Bar` libraries: + +|--lib +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| |--Foo +| | |- Foo.c +| | |- Foo.h +| |- readme.txt --> THIS FILE +|- platformio.ini +|--src + |- main.c + +Then in `src/main.c` you should use: + +#include +#include + +// rest H/C/CPP code + +PlatformIO will find your libraries automatically, configure preprocessor's +include paths and build them. + +See additional options for PlatformIO Library Dependency Finder `lib_*`: + +http://docs.platformio.org/en/stable/projectconf.html#lib-install + diff --git a/examples/espidf-hello-world/platformio.ini b/examples/espidf-hello-world/platformio.ini new file mode 100644 index 000000000..b3b366a0c --- /dev/null +++ b/examples/espidf-hello-world/platformio.ini @@ -0,0 +1,23 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter, extra scripting +; Upload options: custom port, speed and extra flags +; Library options: dependencies, extra library storages +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/en/stable/projectconf.html + +[env:esp32dev] +platform = espressif32 +framework = espidf +board = esp32dev + +[env:quantum] +platform = espressif32 +framework = espidf +board = quantum + +[env:lolin32] +platform = espressif32 +framework = espidf +board = lolin32 diff --git a/examples/espidf-hello-world/src/main.c b/examples/espidf-hello-world/src/main.c new file mode 100644 index 000000000..0b37e55a3 --- /dev/null +++ b/examples/espidf-hello-world/src/main.c @@ -0,0 +1,32 @@ +/* Hello World Example + + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "esp_system.h" +#include "nvs_flash.h" + +void hello_task(void *pvParameter) +{ + printf("Hello world!\n"); + for (int i = 10; i >= 0; i--) { + printf("Restarting in %d seconds...\n", i); + vTaskDelay(1000 / portTICK_RATE_MS); + } + printf("Restarting now.\n"); + fflush(stdout); + system_restart(); +} + +void app_main() +{ + nvs_flash_init(); + system_init(); + xTaskCreate(&hello_task, "hello_task", 2048, NULL, 5, NULL); +} \ No newline at end of file diff --git a/examples/espidf-hello-world/src/sdkconfig.h b/examples/espidf-hello-world/src/sdkconfig.h new file mode 100644 index 000000000..1fd4b81b5 --- /dev/null +++ b/examples/espidf-hello-world/src/sdkconfig.h @@ -0,0 +1,53 @@ +/* + * + * Automatically generated file; DO NOT EDIT. + * Espressif IoT Development Framework Configuration + * + */ +#define CONFIG_TRACEMEM_RESERVE_DRAM 0x0 +#define CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE 1 +#define CONFIG_ESPTOOLPY_FLASHFREQ "80m" +#define CONFIG_NEWLIB_STDOUT_ADDCR 1 +#define CONFIG_FREERTOS_PANIC_PRINT_REBOOT 1 +#define CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS 1 +#define CONFIG_LOG_DEFAULT_LEVEL_INFO 1 +#define CONFIG_BT_RESERVE_DRAM 0x0 +#define CONFIG_LWIP_MAX_SOCKETS 4 +#define CONFIG_ULP_COPROC_RESERVE_MEM 0 +#define CONFIG_ESPTOOLPY_BAUD 921600 +#define CONFIG_TOOLPREFIX "xtensa-esp32-elf-" +#define CONFIG_LWIP_THREAD_LOCAL_STORAGE_INDEX 0 +#define CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN 16384 +#define CONFIG_ESP32_ENABLE_STACK_WIFI 1 +#define CONFIG_LOG_BOOTLOADER_LEVEL_WARN 1 +#define CONFIG_MAIN_TASK_STACK_SIZE 4096 +#define CONFIG_ESPTOOLPY_FLASHMODE "dio" +#define CONFIG_LOG_DEFAULT_LEVEL 3 +#define CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION 1 +#define CONFIG_ESPTOOLPY_FLASHMODE_DIO 1 +#define CONFIG_PYTHON "python" +#define CONFIG_ESPTOOLPY_COMPRESSED 1 +#define CONFIG_PARTITION_TABLE_FILENAME "partitions_singleapp.csv" +#define CONFIG_WIFI_SSID "myssid" +#define CONFIG_PARTITION_TABLE_SINGLE_APP 1 +#define CONFIG_WIFI_ENABLED 1 +#define CONFIG_ESPTOOLPY_FLASHFREQ_80M 1 +#define CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE 2048 +#define CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET 0x10000 +#define CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ 240 +#define CONFIG_FREERTOS_HZ 100 +#define CONFIG_LOG_COLORS 1 +#define CONFIG_FREERTOS_ASSERT_FAIL_ABORT 1 +#define CONFIG_LOG_BOOTLOADER_LEVEL 2 +#define CONFIG_ESPTOOLPY_BAUD_OTHER_VAL 115200 +#define CONFIG_ESP32_DEFAULT_CPU_FREQ_240 1 +#define CONFIG_FREERTOS_BREAK_ON_SCHEDULER_START_JTAG 1 +#define CONFIG_FREERTOS_CORETIMER_0 1 +#define CONFIG_PARTITION_TABLE_CUSTOM_FILENAME "partitions.csv" +#define CONFIG_FREERTOS_DEBUG_OCDAWARE 1 +#define CONFIG_WIFI_PASSWORD "myssid" +#define CONFIG_SYSTEM_EVENT_QUEUE_SIZE 32 +#define CONFIG_ESPTOOLPY_BAUD_921600B 1 +#define CONFIG_APP_OFFSET 0x10000 +#define CONFIG_MEMMAP_SMP 1 +#define CONFIG_ESPTOOLPY_PORT "/dev/ttyUSB0" diff --git a/examples/espidf-http-request/README.rst b/examples/espidf-http-request/README.rst index 939467a2d..c21cd895b 100644 --- a/examples/espidf-http-request/README.rst +++ b/examples/espidf-http-request/README.rst @@ -20,10 +20,19 @@ How to build PlatformIO based project .. code-block:: bash # Change directory to example - > cd platform-espressif8266/examples/espidf-http-request + > cd platform-espressif32/examples/espidf-http-request - # Process example project + # Build project > platformio run # Upload firmware > platformio run --target upload + + # Build specific environment + > platformio run -e quantum + + # Upload firmware for the specific environment + > platformio run -e quantum --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/espidf-http-request/platformio.ini b/examples/espidf-http-request/platformio.ini index 2f9f3b234..ced207ae0 100644 --- a/examples/espidf-http-request/platformio.ini +++ b/examples/espidf-http-request/platformio.ini @@ -7,8 +7,20 @@ ; Please visit documentation for the other options and examples ; http://docs.platformio.org/en/stable/projectconf.html -[env:esp32dev] +[env:nano32] platform = espressif32 framework = espidf -board = esp32dev -build_flags = -DCONFIG_WIFI_SSID=\"ESP_AP\" -DCONFIG_WIFI_PASSWORD=\"MYPASS\" \ No newline at end of file +board = nano32 +build_flags = -DCONFIG_WIFI_SSID=\"ESP_AP\" -DCONFIG_WIFI_PASSWORD=\"MYPASS\" + +[env:espea32] +platform = espressif32 +framework = espidf +board = espea32 +build_flags = -DCONFIG_WIFI_SSID=\"ESP_AP\" -DCONFIG_WIFI_PASSWORD=\"MYPASS\" + +[env:esp320] +platform = espressif32 +framework = espidf +board = esp320 +build_flags = -DCONFIG_WIFI_SSID=\"ESP_AP\" -DCONFIG_WIFI_PASSWORD=\"MYPASS\" diff --git a/examples/espidf-http-request/src/sdkconfig.h b/examples/espidf-http-request/src/sdkconfig.h new file mode 100644 index 000000000..77f2a4622 --- /dev/null +++ b/examples/espidf-http-request/src/sdkconfig.h @@ -0,0 +1,51 @@ +/* + * + * Automatically generated file; DO NOT EDIT. + * Espressif IoT Development Framework Configuration + * + */ +#define CONFIG_TRACEMEM_RESERVE_DRAM 0x0 +#define CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE 1 +#define CONFIG_ESPTOOLPY_FLASHFREQ "80m" +#define CONFIG_NEWLIB_STDOUT_ADDCR 1 +#define CONFIG_FREERTOS_PANIC_PRINT_REBOOT 1 +#define CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS 1 +#define CONFIG_LOG_DEFAULT_LEVEL_INFO 1 +#define CONFIG_BT_RESERVE_DRAM 0x0 +#define CONFIG_LWIP_MAX_SOCKETS 4 +#define CONFIG_ULP_COPROC_RESERVE_MEM 0 +#define CONFIG_ESPTOOLPY_BAUD 921600 +#define CONFIG_TOOLPREFIX "xtensa-esp32-elf-" +#define CONFIG_LWIP_THREAD_LOCAL_STORAGE_INDEX 0 +#define CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN 16384 +#define CONFIG_ESP32_ENABLE_STACK_WIFI 1 +#define CONFIG_LOG_BOOTLOADER_LEVEL_WARN 1 +#define CONFIG_MAIN_TASK_STACK_SIZE 4096 +#define CONFIG_ESPTOOLPY_FLASHMODE "dio" +#define CONFIG_LOG_DEFAULT_LEVEL 3 +#define CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION 1 +#define CONFIG_ESPTOOLPY_FLASHMODE_DIO 1 +#define CONFIG_PYTHON "python" +#define CONFIG_ESPTOOLPY_COMPRESSED 1 +#define CONFIG_PARTITION_TABLE_FILENAME "partitions_singleapp.csv" +#define CONFIG_PARTITION_TABLE_SINGLE_APP 1 +#define CONFIG_WIFI_ENABLED 1 +#define CONFIG_ESPTOOLPY_FLASHFREQ_80M 1 +#define CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE 2048 +#define CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET 0x10000 +#define CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ 240 +#define CONFIG_FREERTOS_HZ 100 +#define CONFIG_LOG_COLORS 1 +#define CONFIG_FREERTOS_ASSERT_FAIL_ABORT 1 +#define CONFIG_LOG_BOOTLOADER_LEVEL 2 +#define CONFIG_ESPTOOLPY_BAUD_OTHER_VAL 115200 +#define CONFIG_ESP32_DEFAULT_CPU_FREQ_240 1 +#define CONFIG_FREERTOS_BREAK_ON_SCHEDULER_START_JTAG 1 +#define CONFIG_FREERTOS_CORETIMER_0 1 +#define CONFIG_PARTITION_TABLE_CUSTOM_FILENAME "partitions.csv" +#define CONFIG_FREERTOS_DEBUG_OCDAWARE 1 +#define CONFIG_SYSTEM_EVENT_QUEUE_SIZE 32 +#define CONFIG_ESPTOOLPY_BAUD_921600B 1 +#define CONFIG_APP_OFFSET 0x10000 +#define CONFIG_MEMMAP_SMP 1 +#define CONFIG_ESPTOOLPY_PORT "/dev/ttyUSB0" From 5829295dfbe77d59100613165b6bad0aab02cfd0 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 18 Nov 2016 17:11:15 +0200 Subject: [PATCH 10/10] Bump version to 0.1.0 --- platform.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform.json b/platform.json index a0cdd6e3f..e5d803ef4 100644 --- a/platform.json +++ b/platform.json @@ -13,7 +13,7 @@ "type": "git", "url": "https://github.com/platformio/platform-espressif32.git" }, - "version": "0.0.0", + "version": "0.1.0", "packageRepositories": [ "https://dl.bintray.com/platformio/dl-packages/manifest.json", "https://sourceforge.net/projects/platformio-storage/files/packages/manifest.json/download",