Skip to content

Commit 894cacc

Browse files
authored
add Hybrid Compile (#73)
1 parent 5621a0e commit 894cacc

18 files changed

+791
-41
lines changed

.github/workflows/examples.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
- "examples/arduino-wifiscan"
2121
- "examples/arduino-zigbee-light"
2222
- "examples/arduino-zigbee-switch"
23+
- "examples/tasmota"
2324
- "examples/espidf-arduino-h2zero-BLE_scan"
2425
- "examples/espidf-arduino-matter-light"
2526
- "examples/espidf-arduino-blink"
@@ -49,15 +50,15 @@ jobs:
4950
python -m pip install --upgrade pip
5051
pip install wheel
5152
pip install -U https://github.com/platformio/platformio/archive/develop.zip
52-
pio pkg install --global --platform symlink://.
53+
pio pkg install --global --platform file://.
5354
if: "matrix.os == 'windows-2022'"
5455
env:
5556
PLATFORMIO_CORE_DIR: C:\plat
5657
PLATFORMIO_PACKAGES_DIR: C:\plat\pack
5758
PLATFORMIO_PLATFORMS_DIR: C:\plat\plat
5859
- name: Build Windows examples
5960
run: pio run -d ${{ matrix.example }}
60-
if: "matrix.os == 'windows-2022'"
61+
if: "matrix.example != 'examples/tasmota' && matrix.os == 'windows-2022'"
6162
env:
6263
PLATFORMIO_CORE_DIR: C:\plat
6364
PLATFORMIO_PACKAGES_DIR: C:\plat\pack
@@ -67,8 +68,13 @@ jobs:
6768
python -m pip install --upgrade pip
6869
pip install wheel
6970
pip install -U https://github.com/platformio/platformio/archive/develop.zip
70-
pio pkg install --global --platform symlink://.
71+
pio pkg install --global --platform file://.
7172
if: "matrix.os != 'windows-2022'"
73+
- name: git clone Tasmota and add to examples
74+
run: |
75+
git clone -b development --depth 1 https://github.com/arendst/Tasmota.git examples/tasmota
76+
cp examples/tasmota_platformio_override.ini examples/tasmota/platformio_override.ini
77+
if: "matrix.example == 'examples/tasmota' && matrix.os != 'windows-2022'"
7278
- name: Build Ubuntu Mac examples
7379
run: pio run -d ${{ matrix.example }}
7480
if: "matrix.os != 'windows-2022'"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ based on devel branch Arduino 3.1.0 and IDF 5.3.1+
5050

5151
```ini
5252
[env:development]
53-
platform = https://github.com/pioarduino/platform-espressif32.git#Arduino/IDF53
53+
platform = https://github.com/pioarduino/platform-espressif32.git#Arduino/IDF53_work_hybrid
5454
board = ...
5555
...
5656
```

boards/esp32-solo1.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
{
22
"build": {
3-
"arduino":{
4-
"ldscript": "esp32_out.ld"
5-
},
63
"core": "esp32",
74
"extra_flags": "-DARDUINO_ESP32_DEV -DARDUINO_USB_CDC_ON_BOOT=0 -DCORE32SOLO1",
8-
"f_cpu": "80000000L",
5+
"f_cpu": "160000000L",
96
"f_flash": "40000000L",
107
"flash_mode": "dio",
118
"mcu": "esp32",
@@ -32,6 +29,11 @@
3229
"require_upload_port": true,
3330
"speed": 460800
3431
},
32+
"espidf": {
33+
"custom_sdkconfig": [
34+
"CONFIG_FREERTOS_UNICORE=y"
35+
]
36+
},
3537
"url": "https://en.wikipedia.org/wiki/ESP32",
3638
"vendor": "Espressif"
3739
}

boards/esp32s3_120_16_8-qio_opi.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"build": {
3+
"arduino": {
4+
"memory_type": "qio_opi",
5+
"partitions": "default_16MB.csv"
6+
},
7+
"core": "esp32",
8+
"f_cpu": "240000000L",
9+
"f_flash": "80000000L",
10+
"f_boot": "120000000L",
11+
"boot": "qio",
12+
"flash_mode": "qio",
13+
"extra_flags": [
14+
"-DBOARD_HAS_PSRAM",
15+
"-DARDUINO_USB_MODE=1",
16+
"-DARDUINO_USB_CDC_ON_BOOT=1",
17+
"-DARDUINO_RUNNING_CORE=1",
18+
"-DARDUINO_EVENT_RUNNING_CORE=1"
19+
],
20+
"hwids": [
21+
[
22+
"0x303A",
23+
"0x1001"
24+
]
25+
],
26+
"mcu": "esp32s3",
27+
"variant": "esp32s3"
28+
},
29+
"connectivity": [
30+
"bluetooth",
31+
"wifi"
32+
],
33+
"debug": {
34+
"openocd_target": "esp32s3.cfg"
35+
},
36+
"frameworks": [
37+
"arduino",
38+
"espidf"
39+
],
40+
"name": "ESP32-S3 16MB QIO, 8MB OPI PSRAM",
41+
"upload": {
42+
"flash_size": "16MB",
43+
"maximum_ram_size": 327680,
44+
"maximum_size": 16777216,
45+
"require_upload_port": true,
46+
"speed": 460800
47+
},
48+
"url": "https://www.espressif.com/sites/default/files/documentation/esp32-s3-wroom-1_wroom-1u_datasheet_en.pdf",
49+
"vendor": "espressif"
50+
}

builder/build_lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
idf_component_register(SRCS "sketch.cpp" "arduino-lib-builder-gcc.c" "arduino-lib-builder-cpp.cpp" "arduino-lib-builder-as.S" INCLUDE_DIRS ".")

builder/build_lib/arduino-lib-builder-as.S

Whitespace-only changes.

builder/build_lib/arduino-lib-builder-cpp.cpp

Whitespace-only changes.

builder/build_lib/arduino-lib-builder-gcc.c

Whitespace-only changes.

builder/build_lib/idf_component.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
dependencies:
2+
# Required IDF version
3+
idf: ">=5.1"
4+
espressif/cmake_utilities:
5+
version: "0.*"
6+
espressif/fb_gfx:
7+
version: "master"
8+
path: components/fb_gfx
9+
git: https://github.com/espressif/esp32-arduino-lib-builder.git
10+
require: public
11+
rules:
12+
- if: "target in [esp32, esp32s2, esp32s3, esp32p4]"

builder/build_lib/sketch.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "Arduino.h"
2+
3+
void setup() {
4+
Serial.begin(115200);
5+
}
6+
7+
void loop() {
8+
Serial.println("Hello World!");
9+
delay(1000);
10+
}

builder/frameworks/arduino.py

Lines changed: 163 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,179 @@
2222
http://arduino.cc/en/Reference/HomePage
2323
"""
2424

25+
import subprocess
26+
import json
27+
import semantic_version
2528
import os
29+
import shutil
2630
from os.path import join
2731

28-
from SCons.Script import DefaultEnvironment, SConscript
32+
from SCons.Script import COMMAND_LINE_TARGETS, DefaultEnvironment, SConscript
33+
from platformio.package.version import pepver_to_semver
34+
from platformio.project.config import ProjectConfig
35+
from platformio.package.manager.tool import ToolPackageManager
2936

3037
env = DefaultEnvironment()
38+
pm = ToolPackageManager()
39+
platform = env.PioPlatform()
40+
config = env.GetProjectConfig()
3141
board = env.BoardConfig()
32-
build_core = board.get("build.core", "").lower()
42+
mcu = board.get("build.mcu", "esp32")
43+
board_sdkconfig = board.get("espidf.custom_sdkconfig", "")
44+
entry_custom_sdkconfig = "\n"
45+
flag_custom_sdkconfig = False
46+
47+
if config.has_option("env:"+env["PIOENV"], "custom_sdkconfig"):
48+
entry_custom_sdkconfig = env.GetProjectOption("custom_sdkconfig")
49+
flag_custom_sdkconfig = True
50+
51+
if len(str(board_sdkconfig)) > 2:
52+
flag_custom_sdkconfig = True
53+
54+
extra_flags = (''.join([element for element in board.get("build.extra_flags", "")])).replace("-D", " ")
55+
framework_reinstall = False
56+
flag_any_custom_sdkconfig = False
3357

3458
SConscript("_embed_files.py", exports="env")
3559

36-
if "espidf" not in env.subst("$PIOFRAMEWORK"):
37-
if os.path.exists(join(DefaultEnvironment().PioPlatform().get_package_dir(
60+
flag_any_custom_sdkconfig = os.path.exists(join(platform.get_package_dir("framework-arduinoespressif32-libs"),"sdkconfig"))
61+
62+
# Esp32-solo1 libs needs adopted settings
63+
if flag_custom_sdkconfig == True and ("CORE32SOLO1" in extra_flags or "CONFIG_FREERTOS_UNICORE=y" in entry_custom_sdkconfig or "CONFIG_FREERTOS_UNICORE=y" in board_sdkconfig):
64+
if len(str(env.GetProjectOption("build_unflags"))) == 2: # No valid env, needs init
65+
env['BUILD_UNFLAGS'] = {}
66+
build_unflags = " ".join(env['BUILD_UNFLAGS'])
67+
build_unflags = build_unflags + " -mdisable-hardware-atomics -ustart_app_other_cores"
68+
new_build_unflags = build_unflags.split()
69+
env.Replace(
70+
BUILD_UNFLAGS=new_build_unflags
71+
)
72+
73+
def install_python_deps():
74+
def _get_installed_pip_packages():
75+
result = {}
76+
packages = {}
77+
pip_output = subprocess.check_output(
78+
[
79+
env.subst("$PYTHONEXE"),
80+
"-m",
81+
"pip",
82+
"list",
83+
"--format=json",
84+
"--disable-pip-version-check",
85+
]
86+
)
87+
try:
88+
packages = json.loads(pip_output)
89+
except:
90+
print("Warning! Couldn't extract the list of installed Python packages.")
91+
return {}
92+
for p in packages:
93+
result[p["name"]] = pepver_to_semver(p["version"])
94+
95+
return result
96+
97+
deps = {
98+
"wheel": ">=0.35.1",
99+
"PyYAML": ">=6.0.2",
100+
"intelhex": ">=2.3.0"
101+
}
102+
103+
installed_packages = _get_installed_pip_packages()
104+
packages_to_install = []
105+
for package, spec in deps.items():
106+
if package not in installed_packages:
107+
packages_to_install.append(package)
108+
else:
109+
version_spec = semantic_version.Spec(spec)
110+
if not version_spec.match(installed_packages[package]):
111+
packages_to_install.append(package)
112+
113+
if packages_to_install:
114+
env.Execute(
115+
env.VerboseAction(
116+
(
117+
'"$PYTHONEXE" -m pip install -U '
118+
+ " ".join(
119+
[
120+
'"%s%s"' % (p, deps[p])
121+
for p in packages_to_install
122+
]
123+
)
124+
),
125+
"Installing Arduino Python dependencies",
126+
)
127+
)
128+
return
129+
130+
install_python_deps()
131+
132+
def get_MD5_hash(phrase):
133+
import hashlib
134+
return hashlib.md5((phrase).encode('utf-8')).hexdigest()[:16]
135+
136+
137+
def matching_custom_sdkconfig():
138+
# check if current env is matching to existing sdkconfig
139+
cust_sdk_is_present = False
140+
matching_sdkconfig = False
141+
last_sdkconfig_path = join(env.subst("$PROJECT_DIR"),"sdkconfig.defaults")
142+
if flag_any_custom_sdkconfig == False:
143+
matching_sdkconfig = True
144+
return matching_sdkconfig, cust_sdk_is_present
145+
if os.path.exists(last_sdkconfig_path) == False:
146+
return matching_sdkconfig, cust_sdk_is_present
147+
if flag_custom_sdkconfig == False:
148+
matching_sdkconfig = False
149+
return matching_sdkconfig, cust_sdk_is_present
150+
with open(last_sdkconfig_path) as src:
151+
line = src.readline()
152+
if line.startswith("# TASMOTA__"):
153+
cust_sdk_is_present = True;
154+
costum_options = entry_custom_sdkconfig
155+
if (line.split("__")[1]).strip() == get_MD5_hash((costum_options).strip() + mcu):
156+
matching_sdkconfig = True
157+
158+
return matching_sdkconfig, cust_sdk_is_present
159+
160+
def check_reinstall_frwrk():
161+
framework_reinstall = False
162+
cust_sdk_is_present = False
163+
matching_sdkconfig = False
164+
if flag_custom_sdkconfig == True:
165+
matching_sdkconfig, cust_sdk_is_present = matching_custom_sdkconfig()
166+
if flag_custom_sdkconfig == False and flag_any_custom_sdkconfig == True:
167+
# case custom sdkconfig exists and a env without "custom_sdkconfig"
168+
framework_reinstall = True
169+
if flag_custom_sdkconfig == True and matching_sdkconfig == False:
170+
# check if current custom sdkconfig is different from existing
171+
framework_reinstall = True
172+
return framework_reinstall
173+
174+
def call_compile_libs():
175+
if mcu == "esp32c2":
176+
ARDUINO_FRMWRK_C2_LIB_DIR = join(platform.get_package_dir("framework-arduinoespressif32-libs"),mcu)
177+
ARDUINO_C2_DIR = join(platform.get_package_dir("framework-arduino-c2-skeleton-lib"),mcu)
178+
shutil.copytree(ARDUINO_C2_DIR, ARDUINO_FRMWRK_C2_LIB_DIR, dirs_exist_ok=True)
179+
print("*** Compile Arduino IDF libs for %s ***" % env["PIOENV"])
180+
SConscript("espidf.py")
181+
182+
if check_reinstall_frwrk() == True:
183+
print("*** Reinstall Arduino framework libs ***")
184+
shutil.rmtree(platform.get_package_dir("framework-arduinoespressif32-libs"))
185+
ARDUINO_FRMWRK_LIB_URL = str(platform.get_package_spec("framework-arduinoespressif32-libs")).split("uri=",1)[1][:-1]
186+
pm.install(ARDUINO_FRMWRK_LIB_URL)
187+
if flag_custom_sdkconfig == True:
188+
call_compile_libs()
189+
flag_custom_sdkconfig = False
190+
191+
if flag_custom_sdkconfig == True and flag_any_custom_sdkconfig == False:
192+
call_compile_libs()
193+
194+
if "arduino" in env.subst("$PIOFRAMEWORK") and "espidf" not in env.subst("$PIOFRAMEWORK") and env.subst("$ARDUINO_LIB_COMPILE_FLAG") in ("Inactive", "True"):
195+
if os.path.exists(join(platform.get_package_dir(
38196
"framework-arduinoespressif32"), "tools", "platformio-build.py")):
39197
PIO_BUILD = "platformio-build.py"
40198
else:
41199
PIO_BUILD = "pioarduino-build.py"
42-
SConscript(
43-
join(DefaultEnvironment().PioPlatform().get_package_dir(
44-
"framework-arduinoespressif32"), "tools", PIO_BUILD))
200+
SConscript(join(platform.get_package_dir("framework-arduinoespressif32"), "tools", PIO_BUILD))

0 commit comments

Comments
 (0)