Skip to content

Commit 84843a7

Browse files
authored
Fix Arduino as an component of IDF compile for the C2
1 parent 92c5479 commit 84843a7

18 files changed

+123
-180
lines changed

boards/esp32-c5-devkitc-1.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"build": {
3+
"core": "esp32",
4+
"f_cpu": "240000000L",
5+
"f_flash": "80000000L",
6+
"flash_mode": "qio",
7+
"mcu": "esp32c5",
8+
"variant": "esp32c5"
9+
},
10+
"connectivity": [
11+
"bluetooth",
12+
"wifi"
13+
],
14+
"debug": {
15+
"openocd_target": "esp32c5.cfg"
16+
},
17+
"frameworks": [
18+
"arduino",
19+
"espidf"
20+
],
21+
"name": "Espressif ESP32-C5-DevKitC-1 4MB no PSRAM",
22+
"upload": {
23+
"flash_size": "4MB",
24+
"maximum_ram_size": 327680,
25+
"maximum_size": 4194304,
26+
"require_upload_port": true,
27+
"speed": 460800
28+
},
29+
"url": "https://docs.espressif.com/projects/esp-dev-kits/en/latest/esp32c5/esp32-c5-devkitc-1/user_guide.html",
30+
"vendor": "Espressif"
31+
}

builder/frameworks/_embed_files.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ def transform_to_asm(target, source, env):
110110
" ".join(
111111
[
112112
"riscv32-esp-elf-objcopy"
113-
if mcu in ("esp32c2","esp32c3","esp32c6","esp32h2","esp32p4")
113+
if mcu in ("esp32c2","esp32c3","esp32c5","esp32c6","esp32h2","esp32p4")
114114
else "xtensa-%s-elf-objcopy" % mcu,
115115
"--input-target",
116116
"binary",
117117
"--output-target",
118-
"elf32-littleriscv" if mcu in ("esp32c2","esp32c3","esp32c6","esp32h2","esp32p4") else "elf32-xtensa-le",
118+
"elf32-littleriscv" if mcu in ("esp32c2","esp32c3","esp32c5","esp32c6","esp32h2","esp32p4") else "elf32-xtensa-le",
119119
"--binary-architecture",
120-
"riscv" if mcu in ("esp32c2","esp32c3","esp32c6","esp32h2","esp32p4") else "xtensa",
120+
"riscv" if mcu in ("esp32c2","esp32c3","esp32c5","esp32c6","esp32h2","esp32p4") else "xtensa",
121121
"--rename-section",
122122
".data=.rodata.embedded",
123123
"$SOURCE",

builder/frameworks/arduino.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,20 @@ def shorthen_includes(env, node):
230230
+ shortened_includes,
231231
)
232232

233+
# Check if framework = arduino, espidf is set -> compile Arduino as an component of IDF
234+
# using platformio.ini entry since we modify the framework env var for Hybrid Compile!
235+
def get_frameworks_in_current_env():
236+
current_env_section = "env:" + env["PIOENV"]
237+
if "framework" in config.options(current_env_section):
238+
frameworks = config.get(current_env_section, "framework", "")
239+
return frameworks
240+
return []
241+
242+
current_env_frameworks = get_frameworks_in_current_env()
243+
if "arduino" in current_env_frameworks and "espidf" in current_env_frameworks:
244+
# Arduino as component is set, switch off Hybrid compile
245+
flag_custom_sdkconfig = False
246+
233247
def call_compile_libs():
234248
if mcu == "esp32c2":
235249
ARDUINO_FRMWRK_C2_LIB_DIR = join(platform.get_package_dir("framework-arduinoespressif32-libs"),mcu)

builder/frameworks/espidf.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,14 @@ def _get_installed_standard_pip_packages():
155155
):
156156
print("Warning! Debugging an IDF project requires PlatformIO Core >= 6.1.11!")
157157

158-
# Arduino framework as a component is not compatible with ESP-IDF >5.3
159158
if "arduino" in env.subst("$PIOFRAMEWORK"):
160159
ARDUINO_FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32")
161160
ARDUINO_FRMWRK_LIB_DIR = platform.get_package_dir("framework-arduinoespressif32-libs")
161+
if mcu == "esp32c2":
162+
ARDUINO_FRMWRK_C2_LIB_DIR = join(platform.get_package_dir("framework-arduinoespressif32-libs"),mcu)
163+
if not os.path.exists(ARDUINO_FRMWRK_C2_LIB_DIR):
164+
ARDUINO_C2_DIR = join(platform.get_package_dir("framework-arduino-c2-skeleton-lib"),mcu)
165+
shutil.copytree(ARDUINO_C2_DIR, ARDUINO_FRMWRK_C2_LIB_DIR, dirs_exist_ok=True)
162166
# Possible package names in 'package@version' format is not compatible with CMake
163167
if "@" in os.path.basename(ARDUINO_FRAMEWORK_DIR):
164168
new_path = os.path.join(
@@ -296,7 +300,7 @@ def HandleCOMPONENTsettings(env):
296300
if flag_custom_component_add == True or flag_custom_component_remove == True: # todo remove duplicated
297301
import yaml
298302
from yaml import SafeLoader
299-
print("*** \"custom_component\" is used to select managed idf components ***")
303+
print("*** \"custom_component\" is used to (de)select managed idf components ***")
300304
if flag_custom_component_remove == True:
301305
idf_custom_component_remove = env.GetProjectOption("custom_component_remove").splitlines()
302306
else:
@@ -365,7 +369,7 @@ def HandleCOMPONENTsettings(env):
365369
if flag_custom_component_add == True or flag_custom_component_remove == True:
366370
HandleCOMPONENTsettings(env)
367371

368-
if flag_custom_sdkonfig == True and "arduino" in env.subst("$PIOFRAMEWORK"):
372+
if flag_custom_sdkonfig == True and "arduino" in env.subst("$PIOFRAMEWORK") and "espidf" not in env.subst("$PIOFRAMEWORK"):
369373
HandleArduinoIDFsettings(env)
370374
LIB_SOURCE = os.path.join(ProjectConfig.get_instance().get("platformio", "platforms_dir"), "espressif32", "builder", "build_lib")
371375
if not bool(os.path.exists(os.path.join(PROJECT_DIR, ".dummy"))):
@@ -2056,7 +2060,7 @@ def _skip_prj_source_files(node):
20562060
# Compile Arduino IDF sources
20572061
#
20582062

2059-
if "arduino" in env.get("PIOFRAMEWORK") and "espidf" not in env.get("PIOFRAMEWORK"):
2063+
if ("arduino" in env.subst("$PIOFRAMEWORK")) and ("espidf" not in env.subst("$PIOFRAMEWORK")):
20602064
def idf_lib_copy(source, target, env):
20612065
env_build = join(env["PROJECT_BUILD_DIR"],env["PIOENV"])
20622066
sdkconfig_h_path = join(env_build,"config","sdkconfig.h")
@@ -2114,7 +2118,7 @@ def idf_lib_copy(source, target, env):
21142118
print("*** Original Arduino \"idf_component.yml\" couldnt be restored ***")
21152119
env.AddPostAction("checkprogsize", idf_lib_copy)
21162120

2117-
if "espidf" in env.get("PIOFRAMEWORK") and (flag_custom_component_add == True or flag_custom_component_remove == True):
2121+
if "espidf" in env.subst("$PIOFRAMEWORK") and (flag_custom_component_add == True or flag_custom_component_remove == True):
21182122
def idf_custom_component(source, target, env):
21192123
try:
21202124
shutil.copy(join(ARDUINO_FRAMEWORK_DIR,"idf_component.yml.orig"),join(ARDUINO_FRAMEWORK_DIR,"idf_component.yml"))

builder/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def __fetch_fs_size(target, source, env):
235235
mcu = board.get("build.mcu", "esp32")
236236
toolchain_arch = "xtensa-%s" % mcu
237237
filesystem = board.get("build.filesystem", "spiffs")
238-
if mcu in ("esp32c2", "esp32c3", "esp32c6", "esp32h2", "esp32p4"):
238+
if mcu in ("esp32c2", "esp32c3", "esp32c5", "esp32c6", "esp32h2", "esp32p4"):
239239
toolchain_arch = "riscv32-esp"
240240

241241
if "INTEGRATION_EXTRA_DATA" not in env:
@@ -256,7 +256,7 @@ def __fetch_fs_size(target, source, env):
256256
GDB=join(
257257
platform.get_package_dir(
258258
"riscv32-esp-elf-gdb"
259-
if mcu in ("esp32c2", "esp32c3", "esp32c6", "esp32h2", "esp32p4")
259+
if mcu in ("esp32c2", "esp32c3", "esp32c5", "esp32c6", "esp32h2", "esp32p4")
260260
else "xtensa-esp-elf-gdb"
261261
)
262262
or "",

examples/arduino-rmt-blink/platformio.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ board = esp32-c3-devkitm-1
1919
build_flags = -DBUILTIN_RGBLED_PIN=8
2020
-DNR_OF_LEDS=1
2121

22+
[env:esp32-c5]
23+
platform = espressif32
24+
framework = arduino
25+
board = esp32-c5-devkitc-1
26+
build_flags = -DBUILTIN_RGBLED_PIN=27
27+
-DNR_OF_LEDS=1
28+
2229
[env:esp32-c6]
2330
platform = espressif32
2431
framework = arduino

examples/espidf-hello-world/platformio.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ board = esp32-s2-kaluga-1
2020

2121
[env:esp32-c3-devkitm-1]
2222
board = esp32-c3-devkitm-1
23+
24+
[env:esp32-c5-devkitc-1]
25+
board = esp32-c5-devkitc-1

examples/espidf-ulp-lp/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
cmake_minimum_required(VERSION 3.16)
22

33
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
4-
project(lp_core_pulse_counter)
4+
project(lp_core_gpio_wake_up_example)

examples/espidf-ulp-lp/README.md

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,26 @@
1-
| Supported Targets | ESP32-C6 |
2-
| ----------------- | -------- |
1+
| Supported Targets | ESP32-C5 | ESP32-C6 | ESP32-P4 |
2+
| ----------------- | -------- | -------- | -------- |
3+
# ULP-LP-Core simple example with GPIO Interrupt:
34

4-
This example demonstrates how to program the ULP Core coprocessor to count pulses on an IO while the main CPUs are either running some other code or are in deep sleep. See the README.md file in the upper level 'examples' directory for more information about examples.
5+
This example demonstrates how to program the LP-Core coprocessor to wake up from a RTC IO interrupt, instead of waking periodically from the ULP timer.
56

6-
At runtime, the main code running on the ESP (found in lp_core_pulse_counter_example_main.c) loads ULP program into the `RTC_SLOW_MEM` memory region using `ulp_lp_core_load_binary` function. Main code configures the ULP program by setting up values of some variables and then starts it using `ulp_lp_core_run`. Once the ULP program is started, it monitors the IO pin for pulses.
7+
ULP program written in C can be found across `ulp/main.c`. The build system compiles and links this program, converts it into binary format, and embeds it into the .rodata section of the ESP-IDF application.
78

8-
When the ULP program finds an edge in the input signal, it performs debouncing and increments the variable maintaining the total edge count. Once the edge count reaches certain value, ULP triggers wake up from deep sleep. Note that the ULP program keeps running and monitoring the input signal even when the SoC is woken up.
9+
At runtime, the main code running on the ESP (found in lp_core_gpio_wake_up_example_main.c) loads ULP program into the `RTC_SLOW_MEM` memory region using `ulp_lp_core_load_binary` function. The main code then configures the ULP GPIO wakeup source and starts the coprocessor by using `ulp_lp_core_run` followed by putting the chip into deep sleep mode.
910

10-
### Hardware Required
11+
When the wakeup source pin is pulled low the LP-Core coprocessor is woken up, sends a wakeup signal to the main CPU and goes back to sleep again.
1112

12-
To run this example, you should have a development board based on any of the chips listed in the supported targets table at the top and a host machine with a serial input connection.
13+
In this example the input signal is connected to GPIO2. To change the pin number, check the Chip Pin List document and adjust `WAKEUP_PIN` variable in main.c.
1314

14-
#### Pin Assignment:
1515

16-
**Note:** The following pin assignments are used by default.
16+
## Example output
1717

18-
19-
| | Uart Tx | Pulse Count Input |
20-
| ----------------------- | ------- | ----------------- |
21-
| ESP32-C6 | GPIO5 | GPIO6 |
22-
| Host machine | Rx | N/A |
23-
24-
25-
## Example Output
26-
27-
The log output from the serial monitor connected to the main core should indicate that the LP core and the LP UART peripheral have been successfully initialized. The main CPU would then enter deep sleep mode.
28-
29-
```bash
30-
Using pin 6 as pulse counter input
31-
ULP will wake up processor after every 10 pulses
32-
Not a ULP wakeup, initializing it!
33-
Entering in deep sleep
34-
...
35-
rst:0x5 (SLEEP_WAKEUP),boot:0xc (SPI_FAST_FLASH_BOOT)
36-
...
37-
ULP woke up the main CPU!
38-
Pulse count: 11
39-
Entering in deep sleep
4018
```
19+
Not a LP-Core wakeup, initializing it!
20+
Entering deep sleep
4121
42-
The log output from the serial monitor connected to the LP core should display output as below -
22+
...
4323
44-
```bash
45-
LP Core pulse counter started
46-
Pulse count: 10, wake-up main CPU
24+
LP-Core woke up the main CPU!
25+
Entering deep sleep
4726
```
48-
49-
## Troubleshooting
50-
51-
(For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you as soon as possible.)

examples/espidf-ulp-lp/platformio.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ board = esp32-c6-devkitc-1
1616
platform = espressif32
1717
framework = espidf
1818
board = esp32-p4
19+
20+
[env:esp32-c5]
21+
platform = espressif32
22+
framework = espidf
23+
board = esp32-c5-devkitc-1

0 commit comments

Comments
 (0)