Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ESP32-H2 and ESP32-C2 #1347

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions boards/esp32-c2-devkitm-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"build": {
"core": "esp32",
"f_cpu": "120000000L",
"f_flash": "60000000L",
"flash_mode": "qio",
"mcu": "esp32c2",
"variant": "esp32c2"
},
"connectivity": [
"wifi"
],
"debug": {
"openocd_target": "esp32c2.cfg"
},
"frameworks": [
"arduino",
"espidf"
],
"name": "Espressif ESP32-C2-DevKitM-1",
"upload": {
"flash_size": "4MB",
"maximum_ram_size": 278528,
"maximum_size": 4194304,
"require_upload_port": true,
"speed": 460800
},
"url": "https://docs.espressif.com/projects/espressif-esp-dev-kits/en/latest/esp8684/esp8684-devkitm-1/user_guide.html",
"vendor": "Espressif"
}
37 changes: 37 additions & 0 deletions boards/esp32-h2-devkitm-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"build": {
"core": "esp32",
"f_cpu": "96000000L",
"f_flash": "64000000L",
"f_image": "48000000L",
"flash_mode": "qio",
"mcu": "esp32h2",
"variant": "esp32h2",
"hwids": [
[
"0x303A",
"0x1001"
]
]
},
"connectivity": [
"wifi"
],
"debug": {
"openocd_target": "esp32h2.cfg"
},
"frameworks": [
"arduino",
"espidf"
],
"name": "Espressif ESP32-H2-DevKit",
"upload": {
"flash_size": "4MB",
"maximum_ram_size": 327680,
"maximum_size": 4194304,
"require_upload_port": true,
"speed": 460800
},
"url": "https://docs.espressif.com/projects/espressif-esp-dev-kits/en/latest/esp32h2/esp32-h2-devkitm-1/index.html",
"vendor": "Espressif"
}
6 changes: 3 additions & 3 deletions builder/frameworks/_embed_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ def transform_to_asm(target, source, env):
" ".join(
[
"riscv32-esp-elf-objcopy"
if mcu in ("esp32c3", "esp32c6")
if mcu in ("esp32c2", "esp32c3", "esp32c6", "esp32h2")
else "xtensa-%s-elf-objcopy" % mcu,
"--input-target",
"binary",
"--output-target",
"elf32-littleriscv" if mcu in ("esp32c3","esp32c6") else "elf32-xtensa-le",
"elf32-littleriscv" if mcu in ("esp32c2", "esp32c3", "esp32c6", "esp32h2") else "elf32-xtensa-le",
"--binary-architecture",
"riscv" if mcu in ("esp32c3","esp32c6") else "xtensa",
"riscv" if mcu in ("esp32c2", "esp32c3", "esp32c6", "esp32h2") else "xtensa",
"--rename-section",
".data=.rodata.embedded",
"$SOURCE",
Expand Down
10 changes: 5 additions & 5 deletions builder/frameworks/espidf.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
IDF_ENV_VERSION = "1.0.0"
FRAMEWORK_DIR = platform.get_package_dir("framework-espidf")
TOOLCHAIN_DIR = platform.get_package_dir(
"toolchain-%s" % ("riscv32-esp" if mcu in ("esp32c3", "esp32c6") else ("xtensa-%s" % mcu))
"toolchain-%s" % ("riscv32-esp" if mcu in ("esp32c2", "esp32c3", "esp32c6", "esp32h2") else ("xtensa-%s" % mcu))
)


Expand Down Expand Up @@ -243,7 +243,7 @@ def populate_idf_env_vars(idf_env):
os.path.dirname(get_python_exe()),
]

if mcu not in ("esp32c3", "esp32c6"):
if mcu not in ("esp32c2", "esp32c3", "esp32c6","esp32h2"):
additional_packages.append(
os.path.join(platform.get_package_dir("toolchain-esp32ulp"), "bin"),
)
Expand Down Expand Up @@ -498,7 +498,7 @@ def extract_linker_script_fragments(framework_components_dir, sdk_config):
sys.stderr.write("Error: Failed to extract paths to linker script fragments\n")
env.Exit(1)

if mcu in ("esp32c3", "esp32c6"):
if mcu in ("esp32c2", "esp32c3", "esp32c6", "esp32h2"):
result.append(os.path.join(framework_components_dir, "riscv", "linker.lf"))

# Add extra linker fragments
Expand Down Expand Up @@ -1519,7 +1519,7 @@ def _skip_prj_source_files(node):
(
board.get(
"upload.bootloader_offset",
"0x0" if mcu in ("esp32c3", "esp32c6", "esp32s3") else "0x1000",
"0x0" if mcu in ("esp32c2", "esp32c3", "esp32c6", "esp32s3", "esp32h2") else "0x1000",
),
os.path.join("$BUILD_DIR", "bootloader.bin"),
),
Expand Down Expand Up @@ -1630,7 +1630,7 @@ def _skip_prj_source_files(node):
#

ulp_dir = os.path.join(PROJECT_DIR, "ulp")
if os.path.isdir(ulp_dir) and os.listdir(ulp_dir) and mcu not in ("esp32c3", "esp32c6"):
if os.path.isdir(ulp_dir) and os.listdir(ulp_dir) and mcu not in ("esp32c2", "esp32c3", "esp32c6", "esp32h2"):
env.SConscript("ulp.py", exports="env sdk_config project_config idf_variant")

#
Expand Down
4 changes: 2 additions & 2 deletions builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def __fetch_fs_size(target, source, env):
mcu = board.get("build.mcu", "esp32")
toolchain_arch = "xtensa-%s" % mcu
filesystem = board.get("build.filesystem", "spiffs")
if mcu in ("esp32c3", "esp32c6"):
if mcu in ("esp32c2", "esp32c3", "esp32c6", "esp32h2"):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not much of a python guy, but I program(med) a lot.

Espressif has said that all new devices will have RISC-V cores. Should code like this reflect that? Could this code set a global (I know, globals are bad. But we have mcu...) for "mcu_is_riscv" using approximately this test and then use "mcu_is_riscv" (I don't care how it's spelled) in all the places that are making this exact test, such as setting the GDB name? Otherwise, when something like p4 gets added, there's going to be the same bulky hunt-and-destroy exercise to add a model name to a test that's essentially an eternally growing list of post-2020 models?

Here we set
if mcu in ("esp32c2", "esp32c3", "esp32c6", "esp32h2", "esp32p4", ...):
mcu_family_riscv = true; // whatever

Then the special cases for GDB and ULP and esp-builtin and the dozen others changed here can be
"tool-riscv32-esp-elf-gdb"
if mcu_family_riscv
else "tool-xtensa-esp-elf-gdb"
...and importantly, those dozen hunks don't have to change when p4 and p5 and esp32z3 and whatever else gets added.

Otherwise, the bulk of this CL gets repeated for every new incoming model.

Just a review fly-by...

Copy link
Contributor

@Jason2866 Jason2866 Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that easy. There are checks not only based on the MCU architecture. As example ULP check...
So the whole code needs always checked when a new MCU is added. I knew this a bit, added the P4 and LP core support ;-)

Copy link

@robertlipe robertlipe Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as you've looked at it, minimized the amount of work to do, and concluded this is as good as it gets, my work here is done. 😀. I'll take my not quite common subexpression optimization and crawl back under my rock. I was just trying to help make future revs not need the entire catalog added in a bunch of places.
Thanx for being awesome.

toolchain_arch = "riscv32-esp"

if "INTEGRATION_EXTRA_DATA" not in env:
Expand All @@ -257,7 +257,7 @@ def __fetch_fs_size(target, source, env):
GDB=join(
platform.get_package_dir(
"tool-riscv32-esp-elf-gdb"
if mcu in ("esp32c3", "esp32c6")
if mcu in ("esp32c2", "esp32c3", "esp32c6", "esp32h2")
else "tool-xtensa-esp-elf-gdb"
)
or "",
Expand Down
6 changes: 4 additions & 2 deletions platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ def configure_default_packages(self, variables, targets):
else:
self.packages.pop("toolchain-xtensa-%s" % available_mcu, None)

if mcu in ("esp32s2", "esp32s3", "esp32c3", "esp32c6"):
if mcu in ("esp32s2", "esp32s3", "esp32c2", "esp32c3", "esp32c6", "esp32h2"):
if mcu in ("esp32c2", "esp32c3", "esp32c6", "esp32h2"):
self.packages.pop("toolchain-esp32ulp", None)
# RISC-V based toolchain for ESP32C3, ESP32C6 ESP32S2, ESP32S3 ULP
self.packages["toolchain-riscv32-esp"]["optional"] = False

Expand Down Expand Up @@ -187,7 +189,7 @@ def _add_dynamic_options(self, board):
if board.id == "esp32-s2-kaluga-1":
supported_debug_tools.append("ftdi")

if board.get("build.mcu", "") in ("esp32c3", "esp32c6", "esp32s3"):
if board.get("build.mcu", "") in ("esp32c3", "esp32c6", "esp32s3", "esp32h2"):
supported_debug_tools.append("esp-builtin")

upload_protocol = board.manifest.get("upload", {}).get("protocol")
Expand Down