Skip to content

Commit 965b3ff

Browse files
committed
Add initial support for Arduino framework as IDF component // Issue espressif#24
1 parent ba054a9 commit 965b3ff

File tree

22 files changed

+1310
-6
lines changed

22 files changed

+1310
-6
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ python:
66
env:
77
- PLATFORMIO_PROJECT_DIR=examples/arduino-blink
88
- PLATFORMIO_PROJECT_DIR=examples/arduino-wifiscan
9+
- PLATFORMIO_PROJECT_DIR=examples/espidf-arduino-blink
10+
- PLATFORMIO_PROJECT_DIR=examples/espidf-arduino-wifiscan
911
- PLATFORMIO_PROJECT_DIR=examples/espidf-aws-iot
1012
- PLATFORMIO_PROJECT_DIR=examples/espidf-ble-adv
1113
- PLATFORMIO_PROJECT_DIR=examples/espidf-coap-server

appveyor.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ environment:
44
matrix:
55
- PLATFORMIO_PROJECT_DIR: "examples/arduino-blink"
66
- PLATFORMIO_PROJECT_DIR: "examples/arduino-wifiscan"
7+
- PLATFORMIO_PROJECT_DIR: "examples/espidf-arduino-blink"
8+
- PLATFORMIO_PROJECT_DIR: "examples/espidf-arduino-wifiscan"
79
- PLATFORMIO_PROJECT_DIR: "examples/espidf-aws-iot"
810
- PLATFORMIO_PROJECT_DIR: "examples/espidf-ble-adv"
911
- PLATFORMIO_PROJECT_DIR: "examples/espidf-coap-server"

builder/frameworks/arduino.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
SConscript("_embedtxt_files.py", exports="env")
3232

33-
SConscript(
34-
join(DefaultEnvironment().PioPlatform().get_package_dir(
35-
"framework-arduinoespressif32"), "tools", "platformio-build.py"))
33+
if "espidf" not in env.subst("$PIOFRAMEWORK"):
34+
SConscript(
35+
join(DefaultEnvironment().PioPlatform().get_package_dir(
36+
"framework-arduinoespressif32"), "tools", "platformio-build.py"))

builder/frameworks/espidf.py

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@
4141
ulp_lib = env.SConscript("ulp.py", exports="env")
4242

4343
FRAMEWORK_DIR = platform.get_package_dir("framework-espidf")
44+
ARDUINO_FRAMEWORK_DIR = platform.get_package_dir(
45+
"framework-arduinoespressif32")
4446
assert FRAMEWORK_DIR and isdir(FRAMEWORK_DIR)
47+
assert ARDUINO_FRAMEWORK_DIR and isdir(ARDUINO_FRAMEWORK_DIR)
4548

4649

4750
def get_toolchain_version():
@@ -67,6 +70,11 @@ def is_ulp_enabled(sdk_params):
6770
return ulp_memory > 0 and ulp_enabled != 0
6871

6972

73+
def is_arduino_enabled(sdk_params):
74+
arduino_enabled = int(sdk_params.get("CONFIG_ENABLE_ARDUINO_DEPENDS", 0))
75+
return arduino_enabled > 0
76+
77+
7078
def parse_mk(path):
7179
result = {}
7280
variable = None
@@ -292,6 +300,15 @@ def build_wpa_supplicant_lib():
292300
join(FRAMEWORK_DIR, "components", "wpa_supplicant"), config)
293301

294302

303+
def build_heap_lib(params):
304+
src_filter = "+<*> -<test*>"
305+
if int(sdk_params.get("CONFIG_HEAP_POISONING_DISABLED", 0)) != 0:
306+
src_filter += " -<multi_heap_poisoning.c>"
307+
308+
return build_component(
309+
join(FRAMEWORK_DIR, "components", "heap"), {"src_filter": src_filter})
310+
311+
295312
def build_espidf_bootloader():
296313
envsafe = env.Clone()
297314
envsafe.Append(CPPDEFINES=[("BOOTLOADER_BUILD", 1)])
@@ -361,6 +378,46 @@ def build_espidf_bootloader():
361378
)
362379

363380

381+
def build_arduino_framework():
382+
core = env.BoardConfig().get("build.core")
383+
variant = env.BoardConfig().get("build.variant")
384+
385+
env.Append(
386+
CPPPATH=[
387+
join(ARDUINO_FRAMEWORK_DIR, "cores", core),
388+
join(ARDUINO_FRAMEWORK_DIR, "variants", variant)
389+
]
390+
)
391+
392+
envsafe = env.Clone()
393+
envsafe.Append(
394+
CPPDEFINES=[("ARDUINO", 10805), ("ARDUINO_ARCH_ESP32", 1)]
395+
)
396+
397+
arduino_libs = []
398+
if "build.variant" in env.BoardConfig():
399+
envsafe.Append(
400+
CPPPATH=[join(ARDUINO_FRAMEWORK_DIR, "variants", variant)]
401+
)
402+
arduino_libs.append(envsafe.BuildLibrary(
403+
join("$BUILD_DIR", "FrameworkArduinoVariant"),
404+
join(ARDUINO_FRAMEWORK_DIR, "variants", variant)
405+
))
406+
407+
arduino_libs.append(envsafe.BuildLibrary(
408+
join("$BUILD_DIR", "FrameworkArduino"),
409+
join(ARDUINO_FRAMEWORK_DIR, "cores", core)
410+
))
411+
412+
env.Append(
413+
LIBSOURCE_DIRS=[
414+
join(ARDUINO_FRAMEWORK_DIR, "libraries")
415+
],
416+
417+
LIBS=arduino_libs
418+
)
419+
420+
364421
env.Prepend(
365422
CPPPATH=[
366423
join(FRAMEWORK_DIR, "components", "app_trace", "include"),
@@ -622,8 +679,8 @@ def build_espidf_bootloader():
622679

623680
if ulp_lib:
624681
if not is_ulp_enabled(sdk_params):
625-
print("Warning! ULP is not properly configured."
626-
"Add next configuration lines to your sdkconfig.h:")
682+
print("Warning! ULP is not properly configured. "
683+
"Add the next configuration lines to your sdkconfig.h:")
627684
print (" #define CONFIG_ULP_COPROC_ENABLED 1")
628685
print (" #define CONFIG_ULP_COPROC_RESERVE_MEM 1024")
629686

@@ -647,13 +704,13 @@ def build_espidf_bootloader():
647704
"aws_iot": "-<*> +<port> +<aws-iot-device-sdk-embedded-C/src>",
648705
"esp32": "-<*> +<*.[sSc]*> +<hwcrypto>",
649706
"bootloader_support": "+<*> -<test> -<src/bootloader_init.c>",
650-
"heap": "+<*> -<test*> -<multi_heap_poisoning.c>",
651707
"soc": "+<*> -<test> -<esp32/test>",
652708
"spi_flash": "+<*> -<test*> -<sim>"
653709
}
654710

655711
special_env = (
656712
"freertos",
713+
"heap",
657714
"lwip",
658715
"protocomm",
659716
"libsodium",
@@ -679,9 +736,28 @@ def build_espidf_bootloader():
679736
libs.extend((
680737
build_lwip_lib(sdk_params),
681738
build_protocomm_lib(sdk_params),
739+
build_heap_lib(sdk_params),
682740
build_rtos_lib(),
683741
build_libsodium_lib(),
684742
build_wpa_supplicant_lib()
685743
))
686744

745+
#
746+
# Process Arduino core
747+
#
748+
749+
if "arduino" in env.subst("$PIOFRAMEWORK"):
750+
if is_arduino_enabled(sdk_params):
751+
build_arduino_framework()
752+
else:
753+
print("Warning! Arduino support is not properly configured. "
754+
"Add the next configuration lines to your sdkconfig.h:")
755+
print (" #define CONFIG_ENABLE_ARDUINO_DEPENDS 1")
756+
print (" #define CONFIG_AUTOSTART_ARDUINO 1")
757+
print (" #define CONFIG_ARDUINO_RUNNING_CORE 1")
758+
print (" #define CONFIG_ARDUINO_UDP_RUN_CORE1 1")
759+
print (" #define CONFIG_ARDUINO_EVENT_RUN_CORE1 1")
760+
print (" #define CONFIG_ARDUINO_EVENT_RUNNING_CORE 1")
761+
print (" #define CONFIG_ARDUINO_UDP_RUNNING_CORE 1")
762+
687763
env.Prepend(LIBS=libs)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.pioenvs
2+
.piolibdeps
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Continuous Integration (CI) is the practice, in software
2+
# engineering, of merging all developer working copies with a shared mainline
3+
# several times a day < https://docs.platformio.org/page/ci/index.html >
4+
#
5+
# Documentation:
6+
#
7+
# * Travis CI Embedded Builds with PlatformIO
8+
# < https://docs.travis-ci.com/user/integration/platformio/ >
9+
#
10+
# * PlatformIO integration with Travis CI
11+
# < https://docs.platformio.org/page/ci/travis.html >
12+
#
13+
# * User Guide for `platformio ci` command
14+
# < https://docs.platformio.org/page/userguide/cmd_ci.html >
15+
#
16+
#
17+
# Please choose one of the following templates (proposed below) and uncomment
18+
# it (remove "# " before each line) or use own configuration according to the
19+
# Travis CI documentation (see above).
20+
#
21+
22+
23+
#
24+
# Template #1: General project. Test it using existing `platformio.ini`.
25+
#
26+
27+
# language: python
28+
# python:
29+
# - "2.7"
30+
#
31+
# sudo: false
32+
# cache:
33+
# directories:
34+
# - "~/.platformio"
35+
#
36+
# install:
37+
# - pip install -U platformio
38+
# - platformio update
39+
#
40+
# script:
41+
# - platformio run
42+
43+
44+
#
45+
# Template #2: The project is intended to be used as a library with examples.
46+
#
47+
48+
# language: python
49+
# python:
50+
# - "2.7"
51+
#
52+
# sudo: false
53+
# cache:
54+
# directories:
55+
# - "~/.platformio"
56+
#
57+
# env:
58+
# - PLATFORMIO_CI_SRC=path/to/test/file.c
59+
# - PLATFORMIO_CI_SRC=examples/file.ino
60+
# - PLATFORMIO_CI_SRC=path/to/test/directory
61+
#
62+
# install:
63+
# - pip install -U platformio
64+
# - platformio update
65+
#
66+
# script:
67+
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.. Copyright 2014-present PlatformIO <[email protected]>
2+
Licensed under the Apache License, Version 2.0 (the "License");
3+
you may not use this file except in compliance with the License.
4+
You may obtain a copy of the License at
5+
http://www.apache.org/licenses/LICENSE-2.0
6+
Unless required by applicable law or agreed to in writing, software
7+
distributed under the License is distributed on an "AS IS" BASIS,
8+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
See the License for the specific language governing permissions and
10+
limitations under the License.
11+
12+
How to build PlatformIO based project
13+
=====================================
14+
15+
1. `Install PlatformIO Core <http://docs.platformio.org/page/core.html>`_
16+
2. Download `development platform with examples <https://github.com/platformio/platform-espressif32/archive/develop.zip>`_
17+
3. Extract ZIP archive
18+
4. Run these commands:
19+
20+
.. code-block:: bash
21+
22+
# Change directory to example
23+
> cd platform-espressif32/examples/espidf-arduino-blink
24+
25+
# Build project
26+
> platformio run
27+
28+
# Upload firmware
29+
> platformio run --target upload
30+
31+
# Build specific environment
32+
> platformio run -e esp32dev
33+
34+
# Upload firmware for the specific environment
35+
> platformio run -e esp32dev --target upload
36+
37+
# Clean build files
38+
> platformio run --target clean
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
This directory is intended for project header files.
3+
4+
A header file is a file containing C declarations and macro definitions
5+
to be shared between several project source files. You request the use of a
6+
header file in your project source file (C, C++, etc) located in `src` folder
7+
by including it, with the C preprocessing directive `#include'.
8+
9+
```src/main.c
10+
11+
#include "header.h"
12+
13+
int main (void)
14+
{
15+
...
16+
}
17+
```
18+
19+
Including a header file produces the same results as copying the header file
20+
into each source file that needs it. Such copying would be time-consuming
21+
and error-prone. With a header file, the related declarations appear
22+
in only one place. If they need to be changed, they can be changed in one
23+
place, and programs that include the header file will automatically use the
24+
new version when next recompiled. The header file eliminates the labor of
25+
finding and changing all the copies as well as the risk that a failure to
26+
find one copy will result in inconsistencies within a program.
27+
28+
In C, the usual convention is to give header files names that end with `.h'.
29+
It is most portable to use only letters, digits, dashes, and underscores in
30+
header file names, and at most one dot.
31+
32+
Read more about using header files in official GCC documentation:
33+
34+
* Include Syntax
35+
* Include Operation
36+
* Once-Only Headers
37+
* Computed Includes
38+
39+
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
This directory is intended for project specific (private) libraries.
3+
PlatformIO will compile them to static libraries and link into executable file.
4+
5+
The source code of each library should be placed in a an own separate directory
6+
("lib/your_library_name/[here are source files]").
7+
8+
For example, see a structure of the following two libraries `Foo` and `Bar`:
9+
10+
|--lib
11+
| |
12+
| |--Bar
13+
| | |--docs
14+
| | |--examples
15+
| | |--src
16+
| | |- Bar.c
17+
| | |- Bar.h
18+
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
19+
| |
20+
| |--Foo
21+
| | |- Foo.c
22+
| | |- Foo.h
23+
| |
24+
| |- README --> THIS FILE
25+
|
26+
|- platformio.ini
27+
|--src
28+
|- main.c
29+
30+
and a contents of `src/main.c`:
31+
```
32+
#include <Foo.h>
33+
#include <Bar.h>
34+
35+
int main (void)
36+
{
37+
...
38+
}
39+
40+
```
41+
42+
PlatformIO Library Dependency Finder will find automatically dependent
43+
libraries scanning project source files.
44+
45+
More information about PlatformIO Library Dependency Finder
46+
- https://docs.platformio.org/page/librarymanager/ldf.html
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; PlatformIO Project Configuration File
2+
;
3+
; Build options: build flags, source filter, extra scripting
4+
; Upload options: custom port, speed and extra flags
5+
; Library options: dependencies, extra library storages
6+
;
7+
; Please visit documentation for the other options and examples
8+
; http://docs.platformio.org/page/projectconf.html
9+
10+
[env:esp32dev]
11+
platform = espressif32
12+
framework = arduino, espidf
13+
board = esp32dev
14+
monitor_speed = 115200
15+
16+
[env:esp wrover kit]
17+
platform = espressif32
18+
framework = arduino, espidf
19+
board = esp-wrover-kit
20+
monitor_speed = 115200

0 commit comments

Comments
 (0)