From 77f5effeaea8aad19cc1fd044b866cca8f163754 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Wed, 8 Jan 2025 13:27:51 +0200 Subject: [PATCH 01/48] Configure build for ESP-IDF v5.4 --- tools/config.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/config.sh b/tools/config.sh index 3349e4553..1b2941e97 100755 --- a/tools/config.sh +++ b/tools/config.sh @@ -6,11 +6,11 @@ if [ -z $IDF_PATH ]; then fi if [ -z $IDF_BRANCH ]; then - IDF_BRANCH="release/v5.3" + IDF_BRANCH="release/v5.4" fi if [ -z $AR_PR_TARGET_BRANCH ]; then - AR_PR_TARGET_BRANCH="master" + AR_PR_TARGET_BRANCH="release/v3.2.x" fi if [ -z $IDF_TARGET ]; then From 731afdf3bfa2a161aec934747b1d4f606a38255c Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Wed, 8 Jan 2025 13:28:16 +0200 Subject: [PATCH 02/48] Remove support for REV0 ESP32-P4 --- configs/defconfig.esp32p4 | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/configs/defconfig.esp32p4 b/configs/defconfig.esp32p4 index 850b5fd2c..9cc5e8392 100644 --- a/configs/defconfig.esp32p4 +++ b/configs/defconfig.esp32p4 @@ -14,17 +14,6 @@ CONFIG_ESP_SDIO_PIN_D1=15 CONFIG_ESP_SDIO_PIN_D2=16 CONFIG_ESP_SDIO_PIN_D3=17 -# -# Chip revision -# -CONFIG_ESP32P4_REV_MIN_0=y -# CONFIG_ESP32P4_REV_MIN_1 is not set -CONFIG_ESP32P4_REV_MIN_FULL=0 -CONFIG_ESP_REV_MIN_FULL=0 -CONFIG_ESP32P4_REV_MAX_FULL=99 -CONFIG_ESP_REV_MAX_FULL=99 -# end of Chip revision - # RGB Display Optimizations CONFIG_LCD_RGB_ISR_IRAM_SAFE=y CONFIG_LCD_RGB_RESTART_IN_VSYNC=y From 784cd9d2626483b40047ad172e06bf897af2b642 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Wed, 15 Jan 2025 15:50:23 +0200 Subject: [PATCH 03/48] Add temporarily the option to use toolchains with `_signed` postfix This is to fix an issue with ARM Mac toolchain for IDF v5.4 --- tools/gen_tools_json.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tools/gen_tools_json.py b/tools/gen_tools_json.py index 392eed508..a795285b9 100644 --- a/tools/gen_tools_json.py +++ b/tools/gen_tools_json.py @@ -27,8 +27,8 @@ def replace_if_xz(system): if not system['url'].endswith(".tar.xz"): return system - new_url = system['url'].replace(".tar.xz", ".tar.gz") - new_name = system['archiveFileName'].replace(".tar.xz", ".tar.gz") + new_url = system['url'].replace(".tar.xz", "_signed.tar.gz") + new_name = system['archiveFileName'].replace(".tar.xz", "_signed.tar.gz") new_checksum = "" new_size = 0 @@ -40,8 +40,16 @@ def replace_if_xz(system): (owner, proj, version, filename) = urlx[0] release_manifest_url = "https://github.com/%s/%s/releases/download/%s/%s-%s-checksum.sha256" % (owner, proj, version, proj, version) else: - print("No manifest match") - return system + new_url = system['url'].replace(".tar.xz", ".tar.gz") + new_name = system['archiveFileName'].replace(".tar.xz", ".tar.gz") + # parse the download url to extract all info needed for the checksum file url + urlx = re.findall("^https://github.com/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/releases/download/([a-zA-Z0-9_\-.]+)/([a-zA-Z0-9_\-.]+)$", new_url) + if urlx and len(urlx) > 0: + (owner, proj, version, filename) = urlx[0] + release_manifest_url = "https://github.com/%s/%s/releases/download/%s/%s-%s-checksum.sha256" % (owner, proj, version, proj, version) + else: + print("No manifest match") + return system # check if we have already downloaded and parsed that manifest manifest_index = 0 From cc827d83668c660ba3fa9a2329e756e5e47bb9b2 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Thu, 16 Jan 2025 17:44:36 +0200 Subject: [PATCH 04/48] Fix tools json generation --- tools/gen_tools_json.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/gen_tools_json.py b/tools/gen_tools_json.py index a795285b9..f03b73d78 100644 --- a/tools/gen_tools_json.py +++ b/tools/gen_tools_json.py @@ -27,8 +27,10 @@ def replace_if_xz(system): if not system['url'].endswith(".tar.xz"): return system - new_url = system['url'].replace(".tar.xz", "_signed.tar.gz") - new_name = system['archiveFileName'].replace(".tar.xz", "_signed.tar.gz") + new_url = system['url'].replace(".tar.xz", ".tar.gz") + new_name = system['archiveFileName'].replace(".tar.xz", ".tar.gz") + new_signed_url = system['url'].replace(".tar.xz", "_signed.tar.gz") + new_signed_name = system['archiveFileName'].replace(".tar.xz", "_signed.tar.gz") new_checksum = "" new_size = 0 @@ -40,16 +42,8 @@ def replace_if_xz(system): (owner, proj, version, filename) = urlx[0] release_manifest_url = "https://github.com/%s/%s/releases/download/%s/%s-%s-checksum.sha256" % (owner, proj, version, proj, version) else: - new_url = system['url'].replace(".tar.xz", ".tar.gz") - new_name = system['archiveFileName'].replace(".tar.xz", ".tar.gz") - # parse the download url to extract all info needed for the checksum file url - urlx = re.findall("^https://github.com/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/releases/download/([a-zA-Z0-9_\-.]+)/([a-zA-Z0-9_\-.]+)$", new_url) - if urlx and len(urlx) > 0: - (owner, proj, version, filename) = urlx[0] - release_manifest_url = "https://github.com/%s/%s/releases/download/%s/%s-%s-checksum.sha256" % (owner, proj, version, proj, version) - else: - print("No manifest match") - return system + print("No manifest match") + return system # check if we have already downloaded and parsed that manifest manifest_index = 0 @@ -84,6 +78,12 @@ def replace_if_xz(system): release_manifests.append(manifest) # find the new file in the list and get it's size and checksum + for file in release_manifests[manifest_index]['files']: + if file['name'] == new_signed_name: + print("Found a signed version of the file") + new_url = new_signed_url + new_name = new_signed_name + break for file in release_manifests[manifest_index]['files']: if file['name'] == new_name: system['url'] = new_url From 43e5553eeff8e28c296b24c41cd0823d1e4c18cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Tue, 4 Feb 2025 22:59:32 +0100 Subject: [PATCH 05/48] fix(zigbee): Exclude correct libs for 1.6.2 version (#269) --- tools/copy-libs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/copy-libs.sh b/tools/copy-libs.sh index 21efe1a78..17014e70d 100755 --- a/tools/copy-libs.sh +++ b/tools/copy-libs.sh @@ -95,7 +95,7 @@ fi if [ -d "managed_components/espressif__esp-zboss-lib/lib/$IDF_TARGET/" ]; then cp -r "managed_components/espressif__esp-zboss-lib/lib/$IDF_TARGET"/* "$AR_SDK/lib/" - EXCLUDE_LIBS+="zboss_stack.ed;zboss_port.debug;" + EXCLUDE_LIBS+="zboss_stack.ed;zboss_port.native.debug;" fi #collect includes, defines and c-flags From ffdf58bb89214802251d334cb1f9cdafadd93f6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Wed, 5 Feb 2025 11:14:11 +0100 Subject: [PATCH 06/48] fix(zigbee): Update exclude libs in script (#274) --- tools/copy-libs.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/copy-libs.sh b/tools/copy-libs.sh index 17014e70d..53e41eee5 100755 --- a/tools/copy-libs.sh +++ b/tools/copy-libs.sh @@ -90,12 +90,12 @@ fi # copy zigbee + zboss lib if [ -d "managed_components/espressif__esp-zigbee-lib/lib/$IDF_TARGET/" ]; then cp -r "managed_components/espressif__esp-zigbee-lib/lib/$IDF_TARGET"/* "$AR_SDK/lib/" - EXCLUDE_LIBS+="esp_zb_api_ed;" + EXCLUDE_LIBS+="esp_zb_api.ed;" fi if [ -d "managed_components/espressif__esp-zboss-lib/lib/$IDF_TARGET/" ]; then cp -r "managed_components/espressif__esp-zboss-lib/lib/$IDF_TARGET"/* "$AR_SDK/lib/" - EXCLUDE_LIBS+="zboss_stack.ed;zboss_port.native.debug;" + EXCLUDE_LIBS+="zboss_stack.ed;zboss_port.native;zboss_port.native.debug;" fi #collect includes, defines and c-flags From 3225f04b8efad7d11286cd27dfef60ac361bfcba Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Tue, 18 Feb 2025 11:48:43 +0200 Subject: [PATCH 07/48] Update target branches --- .github/workflows/cron.yml | 8 ++++---- tools/config.sh | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cron.yml b/.github/workflows/cron.yml index 31c578ef7..8a8f721db 100644 --- a/.github/workflows/cron.yml +++ b/.github/workflows/cron.yml @@ -35,11 +35,11 @@ jobs: # - idf_branch: "release/v5.1" # lib_builder_branch: "release/v5.1" # targets: "esp32,esp32s2,esp32s3,esp32c3,esp32c6,esp32h2" - - idf_branch: "release/v5.3" - lib_builder_branch: "master" - targets: "esp32,esp32s2,esp32s3,esp32c3,esp32c6,esp32h2,esp32p4" + # - idf_branch: "release/v5.3" + # lib_builder_branch: "master" + # targets: "esp32,esp32s2,esp32s3,esp32c3,esp32c6,esp32h2,esp32p4" - idf_branch: "release/v5.4" - lib_builder_branch: "release/v5.4" + lib_builder_branch: "master" targets: "esp32,esp32s2,esp32s3,esp32c3,esp32c6,esp32h2,esp32p4" - idf_branch: "master" lib_builder_branch: "release/v5.5" diff --git a/tools/config.sh b/tools/config.sh index 1b2941e97..79d4feef5 100755 --- a/tools/config.sh +++ b/tools/config.sh @@ -10,7 +10,7 @@ if [ -z $IDF_BRANCH ]; then fi if [ -z $AR_PR_TARGET_BRANCH ]; then - AR_PR_TARGET_BRANCH="release/v3.2.x" + AR_PR_TARGET_BRANCH="master" fi if [ -z $IDF_TARGET ]; then From 5d86a90635cc9c695913503315284fd47b4c192a Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Tue, 18 Feb 2025 21:57:38 +0100 Subject: [PATCH 08/48] Delete removed Zigbee RCP mode / rename of libs --- configs/pioarduino_start.txt | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/configs/pioarduino_start.txt b/configs/pioarduino_start.txt index c5174173d..ec10a10dc 100644 --- a/configs/pioarduino_start.txt +++ b/configs/pioarduino_start.txt @@ -45,28 +45,17 @@ flatten_cppdefines = env.Flatten(env['CPPDEFINES']) if "ZIGBEE_MODE_ZCZR" in flatten_cppdefines: env.Append( LIBS=[ - "-lesp_zb_api_zczr", - "-lesp_zb_cli_command", + "-lesp_zb_api.zczr", "-lzboss_stack.zczr", - "-lzboss_port" + "-lzboss_port.native" ] ) if "ZIGBEE_MODE_ED" in flatten_cppdefines: env.Append( LIBS=[ - "-lesp_zb_api_ed", - "-lesp_zb_cli_command", + "-lesp_zb_api.ed", "-lzboss_stack.ed", - "-lzboss_port" - ] - ) -if "ZIGBEE_MODE_RCP" in flatten_cppdefines: - env.Append( - LIBS=[ - "-lesp_zb_api_rcp", - "-lesp_zb_cli_command", - "-lzboss_stack.rcp", - "-lzboss_port" + "-lzboss_port.native" ] ) From 252044546d2eb42a64401c71df580e4841ebcb7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Thu, 20 Feb 2025 16:31:53 +0100 Subject: [PATCH 09/48] feat(zigbee): Enable Zigbee by default on all chips --- configs/defconfig.common | 3 +++ configs/defconfig.esp32c6 | 1 - configs/defconfig.esp32h2 | 1 - 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/configs/defconfig.common b/configs/defconfig.common index bf5d1197f..2fc18a697 100644 --- a/configs/defconfig.common +++ b/configs/defconfig.common @@ -134,3 +134,6 @@ CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y #TinyUSB Config CONFIG_TINYUSB_CDC_MAX_PORTS=2 + +# Zigbee Config +CONFIG_ZB_ENABLED=y diff --git a/configs/defconfig.esp32c6 b/configs/defconfig.esp32c6 index 8a45b0eed..d0e2b7bbd 100644 --- a/configs/defconfig.esp32c6 +++ b/configs/defconfig.esp32c6 @@ -45,7 +45,6 @@ CONFIG_ENABLE_MATTER_OVER_THREAD=n # # Zigbee # -CONFIG_ZB_ENABLED=y CONFIG_ZB_ZED=y CONFIG_ZB_RADIO_NATIVE=y # end of Zigbee diff --git a/configs/defconfig.esp32h2 b/configs/defconfig.esp32h2 index 9bc304886..024120d34 100644 --- a/configs/defconfig.esp32h2 +++ b/configs/defconfig.esp32h2 @@ -38,7 +38,6 @@ CONFIG_OPENTHREAD_NETWORK_PSKC="104810e2315100afd6bc9215a6bfac53" # # Zigbee # -CONFIG_ZB_ENABLED=y CONFIG_ZB_ZED=y CONFIG_ZB_RADIO_NATIVE=y # end of Zigbee From 4ed776080713d42e786f7179b13b8557fc67707c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Thu, 20 Feb 2025 19:09:07 +0100 Subject: [PATCH 10/48] fix(libs): Add also zcrz and remote zb libs to exclude --- tools/copy-libs.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/copy-libs.sh b/tools/copy-libs.sh index 53e41eee5..5c71c72ab 100755 --- a/tools/copy-libs.sh +++ b/tools/copy-libs.sh @@ -90,12 +90,12 @@ fi # copy zigbee + zboss lib if [ -d "managed_components/espressif__esp-zigbee-lib/lib/$IDF_TARGET/" ]; then cp -r "managed_components/espressif__esp-zigbee-lib/lib/$IDF_TARGET"/* "$AR_SDK/lib/" - EXCLUDE_LIBS+="esp_zb_api.ed;" + EXCLUDE_LIBS+="esp_zb_api.ed;esp_zb_api.zczr;" fi if [ -d "managed_components/espressif__esp-zboss-lib/lib/$IDF_TARGET/" ]; then cp -r "managed_components/espressif__esp-zboss-lib/lib/$IDF_TARGET"/* "$AR_SDK/lib/" - EXCLUDE_LIBS+="zboss_stack.ed;zboss_port.native;zboss_port.native.debug;" + EXCLUDE_LIBS+="zboss_stack.ed;zboss_stack.zczr;zboss_port.native;zboss_port.native.debug;zboss_port.remote;zboss_port.remote.debug;" fi #collect includes, defines and c-flags From 5db5d9aea007f55e4983ad74de17204649829725 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Tue, 25 Feb 2025 10:30:06 +0200 Subject: [PATCH 11/48] Update PR Title and commit messages to Arduino --- tools/check-deploy-needed.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/check-deploy-needed.sh b/tools/check-deploy-needed.sh index e33cc169c..28a95ee7e 100755 --- a/tools/check-deploy-needed.sh +++ b/tools/check-deploy-needed.sh @@ -33,8 +33,8 @@ fi # format new branch name and pr title AR_NEW_BRANCH_NAME="idf-$IDF_BRANCH" -AR_NEW_COMMIT_MESSAGE="IDF $IDF_BRANCH $IDF_COMMIT" -AR_NEW_PR_TITLE="IDF $IDF_BRANCH" +AR_NEW_COMMIT_MESSAGE="ci(libs): ESP-IDF $IDF_BRANCH $IDF_COMMIT" +AR_NEW_PR_TITLE="ci(libs): ESP-IDF $IDF_BRANCH" LIBS_RELEASE_TAG="idf-"${IDF_BRANCH//\//_}"" LIBS_VERSION_PREFIX="$LIBS_RELEASE_TAG-$IDF_COMMIT-v" From 16a6e09d397baa2fb58a34dd6abf45d9307100c4 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Wed, 26 Feb 2025 16:14:00 +0200 Subject: [PATCH 12/48] Revert "Update PR Title and commit messages to Arduino" This reverts commit 5db5d9aea007f55e4983ad74de17204649829725. --- tools/check-deploy-needed.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/check-deploy-needed.sh b/tools/check-deploy-needed.sh index 28a95ee7e..e33cc169c 100755 --- a/tools/check-deploy-needed.sh +++ b/tools/check-deploy-needed.sh @@ -33,8 +33,8 @@ fi # format new branch name and pr title AR_NEW_BRANCH_NAME="idf-$IDF_BRANCH" -AR_NEW_COMMIT_MESSAGE="ci(libs): ESP-IDF $IDF_BRANCH $IDF_COMMIT" -AR_NEW_PR_TITLE="ci(libs): ESP-IDF $IDF_BRANCH" +AR_NEW_COMMIT_MESSAGE="IDF $IDF_BRANCH $IDF_COMMIT" +AR_NEW_PR_TITLE="IDF $IDF_BRANCH" LIBS_RELEASE_TAG="idf-"${IDF_BRANCH//\//_}"" LIBS_VERSION_PREFIX="$LIBS_RELEASE_TAG-$IDF_COMMIT-v" From 206744855a44ab7332147431ddc4433c93f9c5df Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Thu, 6 Mar 2025 13:11:22 -0300 Subject: [PATCH 13/48] feat(matter): updates matter version to 1.4 --- main/idf_component.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/idf_component.yml b/main/idf_component.yml index c6bb97f46..8c574bb08 100644 --- a/main/idf_component.yml +++ b/main/idf_component.yml @@ -17,7 +17,7 @@ dependencies: rules: - if: "target in [esp32s3]" espressif/esp_matter: - version: "^1.3.0" + version: "^1.4.0" require: public rules: - if: "target not in [esp32c2, esp32h2, esp32p4]" From a401c5baa24b14515d6dcc7d0c78d0c216dc5ceb Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Fri, 7 Mar 2025 11:21:26 +0200 Subject: [PATCH 14/48] Enable I2S_ISR_IRAM_SAFE to fix bug in ESP-IDF --- configs/defconfig.common | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/defconfig.common b/configs/defconfig.common index 2fc18a697..621256ba7 100644 --- a/configs/defconfig.common +++ b/configs/defconfig.common @@ -121,6 +121,7 @@ CONFIG_ESP_COREDUMP_STACK_SIZE=0 CONFIG_MBEDTLS_DYNAMIC_BUFFER=y CONFIG_MBEDTLS_DYNAMIC_FREE_PEER_CERT=y CONFIG_MBEDTLS_DYNAMIC_FREE_CONFIG_DATA=y +CONFIG_I2S_ISR_IRAM_SAFE=y # # Matter Settings # From fffa99e734a4505fd36d4caf94fbf5cb5f192c5c Mon Sep 17 00:00:00 2001 From: TANAKA Masayuki Date: Fri, 7 Mar 2025 18:26:53 +0900 Subject: [PATCH 15/48] fix(TinyUSB): USB HUB Subport Added, FIFO sizes(Bias Periodic OUT) It is used by USB HUB. And, Supports USB packets of 128 bytes or more. --- configs/defconfig.common | 3 +++ 1 file changed, 3 insertions(+) diff --git a/configs/defconfig.common b/configs/defconfig.common index 2fc18a697..ad01918a7 100644 --- a/configs/defconfig.common +++ b/configs/defconfig.common @@ -134,6 +134,9 @@ CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y #TinyUSB Config CONFIG_TINYUSB_CDC_MAX_PORTS=2 +CONFIG_USB_HOST_HUBS_SUPPORTED=y +CONFIG_USB_HOST_HUB_MULTI_LEVEL=y +CONFIG_USB_HOST_HW_BUFFER_BIAS_PERIODIC_OUT=y # Zigbee Config CONFIG_ZB_ENABLED=y From 3150a1dfabec2b9fa4b5e8be71af90b4d4c05306 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Fri, 7 Mar 2025 16:58:43 +0200 Subject: [PATCH 16/48] Disable custom IP6 LwIP hook --- configs/defconfig.common | 1 - 1 file changed, 1 deletion(-) diff --git a/configs/defconfig.common b/configs/defconfig.common index c0c91d0c4..48baf5081 100644 --- a/configs/defconfig.common +++ b/configs/defconfig.common @@ -78,7 +78,6 @@ CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y CONFIG_LWIP_HOOK_IP6_SELECT_SRC_ADDR_DEFAULT=y CONFIG_LWIP_HOOK_NETCONN_EXT_RESOLVE_DEFAULT=y -CONFIG_LWIP_HOOK_IP6_INPUT_CUSTOM=y CONFIG_LWIP_MULTICAST_PING=y CONFIG_LWIP_BROADCAST_PING=y CONFIG_LWIP_IPV6_NUM_ADDRESSES=8 From ce6f1932b49db1aed494871df72fac97592d08b4 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Sat, 8 Mar 2025 19:18:26 -0300 Subject: [PATCH 17/48] fixes Matter 1.4 Resolve Include Macro --- tools/copy-libs.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/copy-libs.sh b/tools/copy-libs.sh index 5c71c72ab..7c302ab66 100755 --- a/tools/copy-libs.sh +++ b/tools/copy-libs.sh @@ -525,9 +525,10 @@ for flag_file in "c_flags" "cpp_flags" "S_flags"; do sed 's/\\\"-DCHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER=\\\"/-DCHIP_HAVE_CONFIG_H/' $FLAGS_DIR/$flag_file > $FLAGS_DIR/$flag_file.temp mv $FLAGS_DIR/$flag_file.temp $FLAGS_DIR/$flag_file done -CHIP_RESOLVE_DIR="$AR_SDK/include/espressif__esp_matter/connectedhomeip/connectedhomeip/src/lib/address_resolve" -sed 's/CHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER//' $CHIP_RESOLVE_DIR/AddressResolve.h > $CHIP_RESOLVE_DIR/AddressResolve_temp.h -mv $CHIP_RESOLVE_DIR/AddressResolve_temp.h $CHIP_RESOLVE_DIR/AddressResolve.h +# this is not necessary for Matter 1.4, but it is for Matter 1.3 +#CHIP_RESOLVE_DIR="$AR_SDK/include/espressif__esp_matter/connectedhomeip/connectedhomeip/src/lib/address_resolve" +#sed 's/CHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER//' $CHIP_RESOLVE_DIR/AddressResolve.h > $CHIP_RESOLVE_DIR/AddressResolve_temp.h +#mv $CHIP_RESOLVE_DIR/AddressResolve_temp.h $CHIP_RESOLVE_DIR/AddressResolve.h # End of Matter Library adjustments # sdkconfig From 91af3d16ec1ecef6e589bd9ca1b48b4fbe137a46 Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Wed, 19 Mar 2025 17:37:46 +0200 Subject: [PATCH 18/48] Enable TLS 1.3 --- configs/defconfig.common | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/defconfig.common b/configs/defconfig.common index 48baf5081..096556a9f 100644 --- a/configs/defconfig.common +++ b/configs/defconfig.common @@ -90,6 +90,7 @@ CONFIG_MBEDTLS_CAMELLIA_C=y CONFIG_MBEDTLS_GCM_SUPPORT_NON_AES_CIPHER=y # CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN is not set CONFIG_MBEDTLS_SSL_PROTO_DTLS=y +CONFIG_MBEDTLS_SSL_PROTO_TLS1_3=y CONFIG_OPENSSL_ASSERT_DO_NOTHING=y CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT=2048 CONFIG_SPI_FLASH_YIELD_DURING_ERASE=y From 5c05937d6ea565806dcba24258812cb8dadbe4af Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Wed, 19 Mar 2025 18:51:21 -0300 Subject: [PATCH 19/48] ci(workflows): Lock actions to commits and improve readability --- .github/workflows/cron_build.yml | 19 +++++++++++-------- .github/workflows/docker.yml | 12 ++++++------ .github/workflows/push.yml | 13 +++++++------ .github/workflows/repository_dispatch.yml | 11 ++++++++--- 4 files changed, 32 insertions(+), 23 deletions(-) diff --git a/.github/workflows/cron_build.yml b/.github/workflows/cron_build.yml index 8d13759b7..fd9634928 100644 --- a/.github/workflows/cron_build.yml +++ b/.github/workflows/cron_build.yml @@ -41,7 +41,8 @@ jobs: deploy_needed: ${{ steps.check.outputs.deploy_needed }} targets_list: ${{ steps.check.outputs.targets_list }} steps: - - uses: actions/checkout@v4 + - name: Checkout ${{ inputs.lib_builder_branch }} + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: ref: ${{ inputs.lib_builder_branch }} @@ -65,7 +66,8 @@ jobs: matrix: target: ${{ fromJson(needs.check-if-needed.outputs.targets_list) }} steps: - - uses: actions/checkout@v4 + - name: Checkout ${{ inputs.lib_builder_branch }} + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: ref: ${{ inputs.lib_builder_branch }} @@ -88,13 +90,13 @@ jobs: - name: Upload build if: failure() - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: build-${{ env.libs_branch }}-${{ matrix.target }} path: build - name: Upload library files - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: libs-${{ env.libs_branch }}-${{ matrix.target }} path: dist @@ -105,7 +107,8 @@ jobs: needs: [check-if-needed, build-libs] if: needs.check-if-needed.outputs.deploy_needed == '1' steps: - - uses: actions/checkout@v4 + - name: Checkout ${{ inputs.lib_builder_branch }} + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: ref: ${{ inputs.lib_builder_branch }} @@ -115,7 +118,7 @@ jobs: echo "libs_branch=${branch//\//_}" >> $GITHUB_ENV - name: Download artifacts - uses: actions/download-artifact@v4 + uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1 with: path: dist pattern: libs-${{ env.libs_branch }}-* @@ -125,7 +128,7 @@ jobs: run: bash ./tools/combine-artifacts.sh - name: Upload full esp32-arduino-libs archive - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: esp32-arduino-libs-${{ env.libs_branch }} path: dist/esp32-arduino-libs.zip @@ -154,7 +157,7 @@ jobs: bash ./tools/push-to-arduino.sh - name: Upload package_esp32_index.template.json - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: package-esp32-index-json-${{ env.libs_branch }} path: out/package_esp32_index.template.json diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index d6166a365..c89352150 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -66,23 +66,23 @@ jobs: echo "URL: $URL" - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Login to Docker Hub if: ${{ github.event_name == 'push' }} - uses: docker/login-action@v3 + uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Set up QEMU for multiarch builds - uses: docker/setup-qemu-action@v3 + uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0 - name: Build and push - uses: docker/build-push-action@v5 + uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6.15.0 with: context: tools/docker push: ${{ github.event_name == 'push' }} @@ -94,7 +94,7 @@ jobs: - name: Update Docker Hub repository description (master branch) if: ${{ github.event_name == 'push' && github.ref_type == 'branch' && github.ref_name == 'master' }} - uses: peter-evans/dockerhub-description@v4 + uses: peter-evans/dockerhub-description@e98e4d1628a5f3be2be7c231e50981aee98723ae # v4.0.0 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 95610c403..756ab0991 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -28,7 +28,8 @@ jobs: target: [esp32, esp32s2, esp32s3, esp32c2, esp32c3, esp32c6, esp32h2, esp32p4] fail-fast: false steps: - - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Install dependencies run: bash ./tools/prepare-ci.sh @@ -38,13 +39,13 @@ jobs: - name: Upload build if: failure() - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: build-${{ matrix.target }} path: build - name: Upload archive - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: artifacts-${{ matrix.target }} path: dist @@ -55,7 +56,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Download artifacts - uses: actions/download-artifact@v4 + uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1 with: path: dist pattern: artifacts-* @@ -69,13 +70,13 @@ jobs: cp out/package_esp32_index.template.json dist/package_esp32_index.template.json - name: Upload full esp32-arduino-libs archive - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: esp32-arduino-libs path: dist/esp32-arduino-libs.tar.gz - name: Upload package_esp32_index.template.json - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: package-esp32-index-json path: dist/package_esp32_index.template.json diff --git a/.github/workflows/repository_dispatch.yml b/.github/workflows/repository_dispatch.yml index a18412a3d..62837976b 100644 --- a/.github/workflows/repository_dispatch.yml +++ b/.github/workflows/repository_dispatch.yml @@ -7,25 +7,30 @@ jobs: name: Dispatch Event runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: fetch-depth: 0 + - name: Install dependencies run: bash ./tools/prepare-ci.sh + - name: Handle Event env: GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN }} GIT_AUTHOR_EMAIL: ${{ secrets.PUSH_EMAIL }} GIT_COMMITTER_EMAIL: ${{ secrets.PUSH_EMAIL }} run: bash ./tools/repository_dispatch.sh + - name: Upload build if: failure() - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: build path: build + - name: Upload archive - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: artifacts path: dist From c4a6b8f289dee1ea92618dfbd91d981ea2f4d1aa Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Thu, 20 Mar 2025 02:00:16 +0200 Subject: [PATCH 20/48] Revert "Enable TLS 1.3" This reverts commit 91af3d16ec1ecef6e589bd9ca1b48b4fbe137a46. --- configs/defconfig.common | 1 - 1 file changed, 1 deletion(-) diff --git a/configs/defconfig.common b/configs/defconfig.common index 096556a9f..48baf5081 100644 --- a/configs/defconfig.common +++ b/configs/defconfig.common @@ -90,7 +90,6 @@ CONFIG_MBEDTLS_CAMELLIA_C=y CONFIG_MBEDTLS_GCM_SUPPORT_NON_AES_CIPHER=y # CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN is not set CONFIG_MBEDTLS_SSL_PROTO_DTLS=y -CONFIG_MBEDTLS_SSL_PROTO_TLS1_3=y CONFIG_OPENSSL_ASSERT_DO_NOTHING=y CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT=2048 CONFIG_SPI_FLASH_YIELD_DURING_ERASE=y From 2e3852231dfddc35cae7c9017713d8c95a1188b9 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Thu, 20 Mar 2025 23:25:22 -0300 Subject: [PATCH 21/48] Update CMakeLists.txt to use gnu++2a instead of 17 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1268b8e68..b79d85c0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,4 +39,4 @@ idf_build_set_property(COMPILE_DEFINITIONS "-DESP32_ARDUINO_LIB_BUILDER" APPEND) ################## ### ESP Matter ### ################## -idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++17;-DCHIP_HAVE_CONFIG_H" APPEND) +idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++2a;-DCHIP_HAVE_CONFIG_H" APPEND) From 33f0b46c4c79eacc5939fa3598c3563cc07828a0 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Tue, 15 Apr 2025 16:41:57 +0300 Subject: [PATCH 22/48] Update TinyUSB DWC2 DCD --- .../arduino_tinyusb/patches/dcd_dwc2.patch | 8 +- components/arduino_tinyusb/src/dcd_dwc2.c | 106 +++++++++--------- 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/components/arduino_tinyusb/patches/dcd_dwc2.patch b/components/arduino_tinyusb/patches/dcd_dwc2.patch index 11c1c05c0..14e6975f0 100644 --- a/components/arduino_tinyusb/patches/dcd_dwc2.patch +++ b/components/arduino_tinyusb/patches/dcd_dwc2.patch @@ -19,11 +19,11 @@ dwc2_regs_t* dwc2 = DWC2_REG(rhport); const uint8_t epnum = tu_edpt_number(p_endpoint_desc->bEndpointAddress); @@ -266,7 +277,18 @@ - depctl.bm.set_data0_iso_even = 1; + depctl.set_data0_iso_even = 1; } if (dir == TUSB_DIR_IN) { -- depctl.bm.tx_fifo_num = epnum; -+ //depctl.bm.tx_fifo_num = epnum; +- depctl.tx_fifo_num = epnum; ++ //depctl.tx_fifo_num = epnum; + uint8_t fifo_num = epnum; +#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) + // Special Case for EP5, which is used by CDC but not actually called by the driver @@ -34,7 +34,7 @@ + fifo_num = get_free_fifo(); + } +#endif -+ depctl.bm.tx_fifo_num = fifo_num; ++ depctl.tx_fifo_num = fifo_num; } dwc2_dep_t* dep = &dwc2->ep[dir == TUSB_DIR_IN ? 0 : 1][epnum]; diff --git a/components/arduino_tinyusb/src/dcd_dwc2.c b/components/arduino_tinyusb/src/dcd_dwc2.c index d6796641a..ea931ab90 100644 --- a/components/arduino_tinyusb/src/dcd_dwc2.c +++ b/components/arduino_tinyusb/src/dcd_dwc2.c @@ -41,12 +41,6 @@ #include "device/dcd.h" #include "dwc2_common.h" -#if TU_CHECK_MCU(OPT_MCU_GD32VF103) - #define DWC2_EP_COUNT(_dwc2) DWC2_EP_MAX -#else - #define DWC2_EP_COUNT(_dwc2) ((_dwc2)->ghwcfg2_bm.num_dev_ep + 1) -#endif - //--------------------------------------------------------------------+ // MACRO TYPEDEF CONSTANT ENUM //--------------------------------------------------------------------+ @@ -79,6 +73,16 @@ CFG_TUD_MEM_SECTION static struct { TUD_EPBUF_DEF(setup_packet, 8); } _dcd_usbbuf; +TU_ATTR_ALWAYS_INLINE static inline uint8_t dwc2_ep_count(const dwc2_regs_t* dwc2) { + #if TU_CHECK_MCU(OPT_MCU_GD32VF103) + return DWC2_EP_MAX; + #else + const dwc2_ghwcfg2_t ghwcfg2 = {.value = dwc2->ghwcfg2}; + return ghwcfg2.num_dev_ep + 1; + #endif +} + + //-------------------------------------------------------------------- // DMA //-------------------------------------------------------------------- @@ -102,7 +106,8 @@ bool dcd_dcache_clean_invalidate(const void* addr, uint32_t data_size) { TU_ATTR_ALWAYS_INLINE static inline bool dma_device_enabled(const dwc2_regs_t* dwc2) { (void) dwc2; // Internal DMA only - return CFG_TUD_DWC2_DMA_ENABLE && dwc2->ghwcfg2_bm.arch == GHWCFG2_ARCH_INTERNAL_DMA; + const dwc2_ghwcfg2_t ghwcfg2 = {.value = dwc2->ghwcfg2}; + return CFG_TUD_DWC2_DMA_ENABLE && ghwcfg2.arch == GHWCFG2_ARCH_INTERNAL_DMA; } static void dma_setup_prepare(uint8_t rhport) { @@ -261,20 +266,15 @@ static void edpt_activate(uint8_t rhport, const tusb_desc_endpoint_t* p_endpoint xfer->interval = p_endpoint_desc->bInterval; // Endpoint control - union { - uint32_t value; - dwc2_depctl_t bm; - } depctl; - depctl.value = 0; - - depctl.bm.mps = xfer->max_size; - depctl.bm.active = 1; - depctl.bm.type = p_endpoint_desc->bmAttributes.xfer; + dwc2_depctl_t depctl = {.value = 0}; + depctl.mps = xfer->max_size; + depctl.active = 1; + depctl.type = p_endpoint_desc->bmAttributes.xfer; if (p_endpoint_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS) { - depctl.bm.set_data0_iso_even = 1; + depctl.set_data0_iso_even = 1; } if (dir == TUSB_DIR_IN) { - //depctl.bm.tx_fifo_num = epnum; + //depctl.tx_fifo_num = epnum; uint8_t fifo_num = epnum; #if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) // Special Case for EP5, which is used by CDC but not actually called by the driver @@ -285,7 +285,7 @@ static void edpt_activate(uint8_t rhport, const tusb_desc_endpoint_t* p_endpoint fifo_num = get_free_fifo(); } #endif - depctl.bm.tx_fifo_num = fifo_num; + depctl.tx_fifo_num = fifo_num; } dwc2_dep_t* dep = &dwc2->ep[dir == TUSB_DIR_IN ? 0 : 1][epnum]; @@ -365,31 +365,22 @@ static void edpt_schedule_packets(uint8_t rhport, const uint8_t epnum, const uin } // transfer size: A full OUT transfer (multiple packets, possibly) triggers XFRC. - union { - uint32_t value; - dwc2_ep_tsize_t bm; - } deptsiz; - deptsiz.value = 0; - deptsiz.bm.xfer_size = total_bytes; - deptsiz.bm.packet_count = num_packets; - + dwc2_ep_tsize_t deptsiz = {.value = 0}; + deptsiz.xfer_size = total_bytes; + deptsiz.packet_count = num_packets; dep->tsiz = deptsiz.value; // control - union { - dwc2_depctl_t bm; - uint32_t value; - } depctl; - depctl.value = dep->ctl; - - depctl.bm.clear_nak = 1; - depctl.bm.enable = 1; - if (depctl.bm.type == DEPCTL_EPTYPE_ISOCHRONOUS && xfer->interval == 1) { - const uint32_t odd_now = (dwc2->dsts_bm.frame_number & 1u); + dwc2_depctl_t depctl = {.value = dep->ctl}; + depctl.clear_nak = 1; + depctl.enable = 1; + if (depctl.type == DEPCTL_EPTYPE_ISOCHRONOUS && xfer->interval == 1) { + const dwc2_dsts_t dsts = {.value = dwc2->dsts}; + const uint32_t odd_now = dsts.frame_number & 1u; if (odd_now) { - depctl.bm.set_data0_iso_even = 1; + depctl.set_data0_iso_even = 1; } else { - depctl.bm.set_data1_iso_odd = 1; + depctl.set_data1_iso_odd = 1; } } @@ -432,7 +423,8 @@ bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { // XCVRDLY: transceiver delay between xcvr_sel and txvalid during device chirp is required // when using with some PHYs such as USB334x (USB3341, USB3343, USB3346, USB3347) - if (dwc2->ghwcfg2_bm.hs_phy_type == GHWCFG2_HSPHY_ULPI) { + const dwc2_ghwcfg2_t ghwcfg2 = {.value = dwc2->ghwcfg2}; + if (ghwcfg2.hs_phy_type == GHWCFG2_HSPHY_ULPI) { dcfg |= DCFG_XCVRDLY; } } else { @@ -667,7 +659,7 @@ void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) { // 7.4.1 Initialization on USB Reset static void handle_bus_reset(uint8_t rhport) { dwc2_regs_t *dwc2 = DWC2_REG(rhport); - const uint8_t ep_count = DWC2_EP_COUNT(dwc2); + const uint8_t ep_count = dwc2_ep_count(dwc2); tu_memclr(xfer_status, sizeof(xfer_status)); @@ -697,7 +689,9 @@ static void handle_bus_reset(uint8_t rhport) { dfifo_device_init(rhport); // 5. Reset device address - dwc2->dcfg_bm.address = 0; + dwc2_dcfg_t dcfg = {.value = dwc2->dcfg}; + dcfg.address = 0; + dwc2->dcfg = dcfg.value; // Fixed both control EP0 size to 64 bytes dwc2->epin[0].ctl &= ~(0x03 << DIEPCTL_MPSIZ_Pos); @@ -717,8 +711,9 @@ static void handle_bus_reset(uint8_t rhport) { static void handle_enum_done(uint8_t rhport) { dwc2_regs_t *dwc2 = DWC2_REG(rhport); + const dwc2_dsts_t dsts = {.value = dwc2->dsts}; tusb_speed_t speed; - switch (dwc2->dsts_bm.enum_speed) { + switch (dsts.enum_speed) { case DCFG_SPEED_HIGH: speed = TUSB_SPEED_HIGH; break; @@ -763,12 +758,12 @@ static void handle_rxflvl_irq(uint8_t rhport) { const volatile uint32_t* rx_fifo = dwc2->fifo[0]; // Pop control word off FIFO - const dwc2_grxstsp_t grxstsp_bm = dwc2->grxstsp_bm; - const uint8_t epnum = grxstsp_bm.ep_ch_num; + const dwc2_grxstsp_t grxstsp = {.value = dwc2->grxstsp}; + const uint8_t epnum = grxstsp.ep_ch_num; dwc2_dep_t* epout = &dwc2->epout[epnum]; - switch (grxstsp_bm.packet_status) { + switch (grxstsp.packet_status) { case GRXSTS_PKTSTS_GLOBAL_OUT_NAK: // Global OUT NAK: do nothing break; @@ -790,7 +785,7 @@ static void handle_rxflvl_irq(uint8_t rhport) { case GRXSTS_PKTSTS_RX_DATA: { // Out packet received - const uint16_t byte_count = grxstsp_bm.byte_count; + const uint16_t byte_count = grxstsp.byte_count; xfer_ctl_t* xfer = XFER_CTL_BASE(epnum, TUSB_DIR_OUT); if (byte_count) { @@ -804,7 +799,8 @@ static void handle_rxflvl_irq(uint8_t rhport) { // short packet, minus remaining bytes (xfer_size) if (byte_count < xfer->max_size) { - xfer->total_len -= epout->tsiz_bm.xfer_size; + const dwc2_ep_tsize_t tsiz = {.value = epout->tsiz}; + xfer->total_len -= tsiz.xfer_size; if (epnum == 0) { xfer->total_len -= _dcd_data.ep0_pending[TUSB_DIR_OUT]; _dcd_data.ep0_pending[TUSB_DIR_OUT] = 0; @@ -866,11 +862,13 @@ static void handle_epin_slave(uint8_t rhport, uint8_t epnum, dwc2_diepint_t diep // - 64 bytes or // - Half/Empty of TX FIFO size (configured by GAHBCFG.TXFELVL) if (diepint_bm.txfifo_empty && (dwc2->diepempmsk & (1 << epnum))) { - const uint16_t remain_packets = epin->tsiz_bm.packet_count; + dwc2_ep_tsize_t tsiz = {.value = epin->tsiz}; + const uint16_t remain_packets = tsiz.packet_count; // Process every single packet (only whole packets can be written to fifo) for (uint16_t i = 0; i < remain_packets; i++) { - const uint16_t remain_bytes = (uint16_t) epin->tsiz_bm.xfer_size; + tsiz.value = epin->tsiz; + const uint16_t remain_bytes = (uint16_t) tsiz.xfer_size; const uint16_t xact_bytes = tu_min16(remain_bytes, xfer->max_size); // Check if dtxfsts has enough space available @@ -889,7 +887,8 @@ static void handle_epin_slave(uint8_t rhport, uint8_t epnum, dwc2_diepint_t diep } // Turn off TXFE if all bytes are written. - if (epin->tsiz_bm.xfer_size == 0) { + tsiz.value = epin->tsiz; + if (tsiz.xfer_size == 0) { dwc2->diepempmsk &= ~(1 << epnum); } } @@ -920,7 +919,8 @@ static void handle_epout_dma(uint8_t rhport, uint8_t epnum, dwc2_doepint_t doepi xfer_ctl_t* xfer = XFER_CTL_BASE(epnum, TUSB_DIR_OUT); // determine actual received bytes - const uint16_t remain = epout->tsiz_bm.xfer_size; + const dwc2_ep_tsize_t tsiz = {.value = epout->tsiz}; + const uint16_t remain = tsiz.xfer_size; xfer->total_len -= remain; // this is ZLP, so prepare EP0 for next setup @@ -956,7 +956,7 @@ static void handle_epin_dma(uint8_t rhport, uint8_t epnum, dwc2_diepint_t diepin static void handle_ep_irq(uint8_t rhport, uint8_t dir) { dwc2_regs_t* dwc2 = DWC2_REG(rhport); const bool is_dma = dma_device_enabled(dwc2); - const uint8_t ep_count = DWC2_EP_COUNT(dwc2); + const uint8_t ep_count = dwc2_ep_count(dwc2); const uint8_t daint_offset = (dir == TUSB_DIR_IN) ? DAINT_IEPINT_Pos : DAINT_OEPINT_Pos; dwc2_dep_t* ep_base = &dwc2->ep[dir == TUSB_DIR_IN ? 0 : 1][0]; From 6685e7b71234fe2852b676e1eef9bf93cdcfb29d Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Mon, 12 May 2025 06:59:53 -0300 Subject: [PATCH 23/48] feat(esp_matter): updates esp_matter component to 1.4.1 Fixes many warning messages when compiling sketches that use Arduino Matter Library. Fixes the `asset()` issue with `-DNDEBUG` --- main/idf_component.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/idf_component.yml b/main/idf_component.yml index 8c574bb08..a398fa272 100644 --- a/main/idf_component.yml +++ b/main/idf_component.yml @@ -17,7 +17,7 @@ dependencies: rules: - if: "target in [esp32s3]" espressif/esp_matter: - version: "^1.4.0" + version: "^1.4.1" require: public rules: - if: "target not in [esp32c2, esp32h2, esp32p4]" From 4304a24cb17f0429d956e9440cb966f65ff68363 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Mon, 12 May 2025 08:25:08 -0300 Subject: [PATCH 24/48] fix(esp_matter): use fixed esp_matter version --- main/idf_component.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/idf_component.yml b/main/idf_component.yml index a398fa272..a85eca541 100644 --- a/main/idf_component.yml +++ b/main/idf_component.yml @@ -17,7 +17,7 @@ dependencies: rules: - if: "target in [esp32s3]" espressif/esp_matter: - version: "^1.4.1" + version: "1.4.1" require: public rules: - if: "target not in [esp32c2, esp32h2, esp32p4]" From ff441d3fbb9e06307601ad15ff30aa5728901db0 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Tue, 13 May 2025 10:41:07 +0200 Subject: [PATCH 25/48] Disable CONFIG_LCD_RGB_ISR_IRAM_SAFE --- configs/defconfig.esp32s3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/defconfig.esp32s3 b/configs/defconfig.esp32s3 index ce53e7747..36fa6b6a5 100644 --- a/configs/defconfig.esp32s3 +++ b/configs/defconfig.esp32s3 @@ -19,5 +19,5 @@ CONFIG_ULP_COPROC_TYPE_FSM=y CONFIG_ULP_COPROC_RESERVE_MEM=512 # RGB Display Optimizations -CONFIG_LCD_RGB_ISR_IRAM_SAFE=y +# CONFIG_LCD_RGB_ISR_IRAM_SAFE is not set CONFIG_LCD_RGB_RESTART_IN_VSYNC=y From d7bdda2c445100aaa3c94cd4728df77b33af323f Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Fri, 16 May 2025 19:56:41 +0200 Subject: [PATCH 26/48] Update cron target branches --- .github/workflows/cron.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cron.yml b/.github/workflows/cron.yml index 8a8f721db..ade7e7fa5 100644 --- a/.github/workflows/cron.yml +++ b/.github/workflows/cron.yml @@ -36,11 +36,11 @@ jobs: # lib_builder_branch: "release/v5.1" # targets: "esp32,esp32s2,esp32s3,esp32c3,esp32c6,esp32h2" # - idf_branch: "release/v5.3" - # lib_builder_branch: "master" + # lib_builder_branch: "release/v5.3" # targets: "esp32,esp32s2,esp32s3,esp32c3,esp32c6,esp32h2,esp32p4" - idf_branch: "release/v5.4" lib_builder_branch: "master" targets: "esp32,esp32s2,esp32s3,esp32c3,esp32c6,esp32h2,esp32p4" - - idf_branch: "master" + - idf_branch: "release/v5.5" lib_builder_branch: "release/v5.5" targets: "esp32,esp32s2,esp32s3,esp32c3,esp32c6,esp32h2,esp32p4,esp32c5" From 1a35d2df15ec5279385fe1715af5606c49775415 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Thu, 22 May 2025 19:35:35 +0300 Subject: [PATCH 27/48] fix(deploy): Increase page limit and add pagination to releases --- tools/config.sh | 48 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/tools/config.sh b/tools/config.sh index 79d4feef5..4f17d8a12 100755 --- a/tools/config.sh +++ b/tools/config.sh @@ -108,7 +108,7 @@ function github_get_libs_idf(){ # github_get_libs_idf local version_found="" local libs_version="" - while [[ "$libs_version" == "" && "$page" -le 3 ]]; do + while [[ "$libs_version" == "" && "$page" -le 5 ]]; do # Get the latest commit message that matches the prefix and extract the hash from the last commit message version_found=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/commits?sha=$branch_name&per_page=100&page=$page" | \ jq -r --arg prefix "$message_prefix" '[ .[] | select(.commit.message | test($prefix + " [a-f0-9]{8}")) ][0] | .commit.message' | \ @@ -131,7 +131,7 @@ function github_commit_exists(){ #github_commit_exists local page=1 local commits_found=0 - while [ "$page" -le 3 ]; do + while [ "$page" -le 5 ]; do local response=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/commits?sha=$branch_name&per_page=100&page=$page"` if [[ -z "$response" || "$response" == "[]" ]]; then @@ -178,16 +178,52 @@ function github_pr_exists(){ # github_pr_exists function github_release_id(){ # github_release_id local repo_path="$1" local release_tag="$2" - local release=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/releases" | jq --arg release_tag "$release_tag" -r '.[] | select(.tag_name == $release_tag) | .id'` - if [ ! "$release" == "" ] && [ ! "$release" == "null" ]; then echo "$release"; else echo ""; fi + local page=1 + local release_id="" + + while [[ "$page" -le 3 ]]; do + local response=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/releases?per_page=100&page=$page"` + + if [[ -z "$response" || "$response" == "[]" ]]; then + break + fi + + local release=`echo "$response" | jq --arg release_tag "$release_tag" -r '.[] | select(.tag_name == $release_tag) | .id'` + if [ ! "$release" == "" ] && [ ! "$release" == "null" ]; then + release_id=$release + break + fi + + page=$((page+1)) + done + + echo "$release_id" } function github_release_asset_id(){ # github_release_asset_id local repo_path="$1" local release_id="$2" local release_file="$3" - local release_asset=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/releases/$release_id/assets" | jq --arg release_file "$release_file" -r '.[] | select(.name == $release_file) | .id'` - if [ ! "$release_asset" == "" ] && [ ! "$release_asset" == "null" ]; then echo "$release_asset"; else echo ""; fi + local page=1 + local asset_id="" + + while [[ "$page" -le 5 ]]; do + local response=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/releases/$release_id/assets?per_page=100&page=$page"` + + if [[ -z "$response" || "$response" == "[]" ]]; then + break + fi + + local release_asset=`echo "$response" | jq --arg release_file "$release_file" -r '.[] | select(.name == $release_file) | .id'` + if [ ! "$release_asset" == "" ] && [ ! "$release_asset" == "null" ]; then + asset_id=$release_asset + break + fi + + page=$((page+1)) + done + + echo "$asset_id" } function github_release_asset_upload(){ # github_release_asset_upload From fdb4a87b69a6e246a6804648af2e9d1410e8f071 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Fri, 30 May 2025 15:50:07 +0300 Subject: [PATCH 28/48] Update TinyUSB DWC2 patch and source --- .../arduino_tinyusb/patches/dcd_dwc2.patch | 4 +- components/arduino_tinyusb/src/dcd_dwc2.c | 71 +++++++++++++------ 2 files changed, 53 insertions(+), 22 deletions(-) diff --git a/components/arduino_tinyusb/patches/dcd_dwc2.patch b/components/arduino_tinyusb/patches/dcd_dwc2.patch index 14e6975f0..2521a38e5 100644 --- a/components/arduino_tinyusb/patches/dcd_dwc2.patch +++ b/components/arduino_tinyusb/patches/dcd_dwc2.patch @@ -56,9 +56,9 @@ +#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) + _allocated_fifos = 1; +#endif + + usbd_spin_lock(true); handle_bus_reset(rhport); - } - @@ -1008,7 +1037,11 @@ if (gintsts & GINTSTS_USBSUSP) { diff --git a/components/arduino_tinyusb/src/dcd_dwc2.c b/components/arduino_tinyusb/src/dcd_dwc2.c index ea931ab90..b6c3b1b22 100644 --- a/components/arduino_tinyusb/src/dcd_dwc2.c +++ b/components/arduino_tinyusb/src/dcd_dwc2.c @@ -39,6 +39,7 @@ #define DWC2_DEBUG 2 #include "device/dcd.h" +#include "device/usbd_pvt.h" #include "dwc2_common.h" //--------------------------------------------------------------------+ @@ -52,6 +53,7 @@ typedef struct { uint8_t interval; } xfer_ctl_t; +// This variable is modified from ISR context, so it must be protected by critical section static xfer_ctl_t xfer_status[DWC2_EP_MAX][2]; #define XFER_CTL_BASE(_ep, _dir) (&xfer_status[_ep][_dir]) @@ -343,6 +345,9 @@ static void edpt_disable(uint8_t rhport, uint8_t ep_addr, bool stall) { } } +// Since this function returns void, it is not possible to return a boolean success message +// We must make sure that this function is not called when the EP is disabled +// Must be called from critical section static void edpt_schedule_packets(uint8_t rhport, const uint8_t epnum, const uint8_t dir) { dwc2_regs_t* dwc2 = DWC2_REG(rhport); xfer_ctl_t* const xfer = XFER_CTL_BASE(epnum, dir); @@ -553,6 +558,8 @@ void dcd_edpt_close_all(uint8_t rhport) { dwc2_regs_t* dwc2 = DWC2_REG(rhport); uint8_t const ep_count = _dwc2_controller[rhport].ep_count; + usbd_spin_lock(false); + _dcd_data.allocated_epin_count = 0; // Disable non-control interrupt @@ -574,8 +581,9 @@ void dcd_edpt_close_all(uint8_t rhport) { dfifo_flush_tx(dwc2, 0x10); // all tx fifo dfifo_flush_rx(dwc2); - dfifo_device_init(rhport); // re-init dfifo + + usbd_spin_unlock(false); } bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) { @@ -593,21 +601,31 @@ bool dcd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * p_endpo bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t total_bytes) { uint8_t const epnum = tu_edpt_number(ep_addr); uint8_t const dir = tu_edpt_dir(ep_addr); - xfer_ctl_t* xfer = XFER_CTL_BASE(epnum, dir); - xfer->buffer = buffer; - xfer->ff = NULL; - xfer->total_len = total_bytes; + bool ret; - // EP0 can only handle one packet - if (epnum == 0) { - _dcd_data.ep0_pending[dir] = total_bytes; + usbd_spin_lock(false); + + if (xfer->max_size == 0) { + ret = false; // Endpoint is closed + } else { + xfer->buffer = buffer; + xfer->ff = NULL; + xfer->total_len = total_bytes; + + // EP0 can only handle one packet + if (epnum == 0) { + _dcd_data.ep0_pending[dir] = total_bytes; + } + + // Schedule packets to be sent within interrupt + edpt_schedule_packets(rhport, epnum, dir); + ret = true; } - // Schedule packets to be sent within interrupt - edpt_schedule_packets(rhport, epnum, dir); + usbd_spin_unlock(false); - return true; + return ret; } // The number of bytes has to be given explicitly to allow more flexible control of how many @@ -620,17 +638,27 @@ bool dcd_edpt_xfer_fifo(uint8_t rhport, uint8_t ep_addr, tu_fifo_t* ff, uint16_t uint8_t const epnum = tu_edpt_number(ep_addr); uint8_t const dir = tu_edpt_dir(ep_addr); - xfer_ctl_t* xfer = XFER_CTL_BASE(epnum, dir); - xfer->buffer = NULL; - xfer->ff = ff; - xfer->total_len = total_bytes; + bool ret; - // Schedule packets to be sent within interrupt - // TODO xfer fifo may only available for slave mode - edpt_schedule_packets(rhport, epnum, dir); + usbd_spin_lock(false); - return true; + if (xfer->max_size == 0) { + ret = false; // Endpoint is closed + } else { + xfer->buffer = NULL; + xfer->ff = ff; + xfer->total_len = total_bytes; + + // Schedule packets to be sent within interrupt + // TODO xfer fifo may only available for slave mode + edpt_schedule_packets(rhport, epnum, dir); + ret = true; + } + + usbd_spin_unlock(false); + + return ret; } void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr) { @@ -657,6 +685,7 @@ void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) { //-------------------------------------------------------------------- // 7.4.1 Initialization on USB Reset +// Must be called from critical section static void handle_bus_reset(uint8_t rhport) { dwc2_regs_t *dwc2 = DWC2_REG(rhport); const uint8_t ep_count = dwc2_ep_count(dwc2); @@ -1009,7 +1038,6 @@ static void handle_ep_irq(uint8_t rhport, uint8_t dir) { */ void dcd_int_handler(uint8_t rhport) { dwc2_regs_t* dwc2 = DWC2_REG(rhport); - const uint32_t gintmask = dwc2->gintmsk; const uint32_t gintsts = dwc2->gintsts & gintmask; @@ -1019,7 +1047,10 @@ void dcd_int_handler(uint8_t rhport) { #if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) _allocated_fifos = 1; #endif + + usbd_spin_lock(true); handle_bus_reset(rhport); + usbd_spin_unlock(true); } if (gintsts & GINTSTS_ENUMDNE) { From c93087a5f761ba2bdfebcd95755522829393cc65 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Wed, 4 Jun 2025 22:01:11 +0300 Subject: [PATCH 29/48] fix(logging): Silence stdout from IDF installation --- tools/install-esp-idf.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/install-esp-idf.sh b/tools/install-esp-idf.sh index 0519ae67a..06a67c354 100755 --- a/tools/install-esp-idf.sh +++ b/tools/install-esp-idf.sh @@ -33,7 +33,8 @@ fi if [ ! -x $idf_was_installed ] || [ ! -x $commit_predefined ]; then git -C $IDF_PATH submodule update --init --recursive - $IDF_PATH/install.sh + echo "Installing ESP-IDF..." + $IDF_PATH/install.sh > /dev/null export IDF_COMMIT=$(git -C "$IDF_PATH" rev-parse --short HEAD) export IDF_BRANCH=$(git -C "$IDF_PATH" symbolic-ref --short HEAD || git -C "$IDF_PATH" tag --points-at HEAD) From c332ce66c65fcaa6ef4fe13209f4216d38491009 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Tue, 24 Jun 2025 15:42:39 +0300 Subject: [PATCH 30/48] fix(docker): Fix docker image tagging --- .github/workflows/docker.yml | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index c89352150..616cc084a 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -26,47 +26,52 @@ jobs: name: Build docker image and push if needed runs-on: ubuntu-latest steps: + - name: Checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + # Depending on the branch/tag, set CLONE_BRANCH_OR_TAG variable (used in the Dockerfile - # as a build arg) and TAG_NAME (used when tagging the image). + # as a build arg) and DOCKER_TAGS (used when tagging the image). # # The following 3 steps cover the alternatives (tag, release branch, master branch): - name: Set variables (tags) if: ${{ github.ref_type == 'tag' }} run: | echo "CLONE_BRANCH_OR_TAG=$GITHUB_REF_NAME" >> $GITHUB_ENV - echo "TAG_NAME=$GITHUB_REF_NAME" >> $GITHUB_ENV + echo "DOCKER_TAGS=${{ env.DOCKERHUB_REPO }}:$GITHUB_REF_NAME" >> $GITHUB_ENV echo "URL=${{ github.server_url }}/${{ github.repository }}.git" >> $GITHUB_ENV - name: Set variables (release branches) if: ${{ github.ref_type == 'branch' && startsWith(github.ref_name, 'release/') }} run: | echo "CLONE_BRANCH_OR_TAG=$GITHUB_REF_NAME" >> $GITHUB_ENV - echo "TAG_NAME=release-${GITHUB_REF_NAME##release/}" >> $GITHUB_ENV + echo "DOCKER_TAGS=${{ env.DOCKERHUB_REPO }}:release-${GITHUB_REF_NAME##release/}" >> $GITHUB_ENV echo "URL=${{ github.server_url }}/${{ github.repository }}.git" >> $GITHUB_ENV - name: Set variables (main branch) if: ${{ github.ref_type == 'branch' && github.ref_name == 'master' }} run: | + source ./tools/config.sh echo "CLONE_BRANCH_OR_TAG=master" >> $GITHUB_ENV - echo "TAG_NAME=latest" >> $GITHUB_ENV + echo "DOCKER_TAGS<> $GITHUB_ENV + echo "${{ env.DOCKERHUB_REPO }}:latest" >> $GITHUB_ENV + echo "${{ env.DOCKERHUB_REPO }}:release-${IDF_BRANCH##release/}" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV echo "URL=${{ github.server_url }}/${{ github.repository }}.git" >> $GITHUB_ENV - name: Set variables (pull requests) if: ${{ github.event_name == 'pull_request' }} run: | echo "CLONE_BRANCH_OR_TAG=${{ github.event.pull_request.head.ref }}" >> $GITHUB_ENV - echo "TAG_NAME=PR_${{ github.event.number }}" >> $GITHUB_ENV + echo "DOCKER_TAGS=${{ env.DOCKERHUB_REPO }}:PR_${{ github.event.number }}" >> $GITHUB_ENV echo "URL=${{ github.server_url }}/${{ github.event.pull_request.head.repo.full_name }}.git" >> $GITHUB_ENV # Display the variables set above, just in case. - name: Check variables run: | echo "CLONE_BRANCH_OR_TAG: $CLONE_BRANCH_OR_TAG" - echo "TAG_NAME: $TAG_NAME" echo "URL: $URL" - - - name: Checkout - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + echo "DOCKER_TAGS:" + echo "$DOCKER_TAGS" - name: Login to Docker Hub if: ${{ github.event_name == 'push' }} @@ -86,7 +91,8 @@ jobs: with: context: tools/docker push: ${{ github.event_name == 'push' }} - tags: ${{ env.DOCKERHUB_REPO }}:${{ env.TAG_NAME }} + tags: | + ${{ env.DOCKER_TAGS }} platforms: ${{ env.BUILD_PLATFORMS }} build-args: | LIBBUILDER_CLONE_URL=${{ env.URL }} From f46b0d7381c3e89ef39b8b8ee0a544e0c407f7fd Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Wed, 23 Jul 2025 15:29:33 +0300 Subject: [PATCH 31/48] Support for IDF v5.5 and ESP32-C5 (#268) * Initial changes for IDF v5.5 and ESP32-C5 * Update gen_pioarduino_manifest.py * Add support for ESP32-C5 PSRAM * Disable Matter on C5 for now * fix(libs): Remove unnecessary IDF patches * Update target IDF branch for v5.5 * Enable Matter on ESP32-C5 * Update PSRAM Options * Add cleaner script * feat(nimble): Replace Bluedroid with NimBLE except for ESP32 * feat(matter): removes CHIPOBLE to manage it case by case --------- Co-authored-by: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Co-authored-by: Sugar Glider --- .github/workflows/push.yml | 2 +- clean.sh | 2 + configs/builds.json | 16 ++++- configs/defconfig.common | 7 +- configs/defconfig.esp32 | 6 ++ configs/defconfig.esp32c2 | 7 +- configs/defconfig.esp32c3 | 8 +++ configs/defconfig.esp32c5 | 66 +++++++++++++++++ configs/defconfig.esp32c6 | 17 ++++- configs/defconfig.esp32h2 | 14 +++- configs/defconfig.esp32s2 | 3 + configs/defconfig.esp32s3 | 11 +++ configs/defconfig.qio_ram | 1 + main/idf_component.yml | 2 +- patches/lwip_max_tcp_pcb.diff | 118 ------------------------------- tools/config.sh | 4 +- tools/gen_pioarduino_manifest.py | 3 + tools/install-esp-idf.sh | 7 +- 18 files changed, 161 insertions(+), 133 deletions(-) create mode 100755 clean.sh create mode 100644 configs/defconfig.esp32c5 delete mode 100644 patches/lwip_max_tcp_pcb.diff diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 756ab0991..c76e45a6b 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -25,7 +25,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - target: [esp32, esp32s2, esp32s3, esp32c2, esp32c3, esp32c6, esp32h2, esp32p4] + target: [esp32, esp32s2, esp32s3, esp32c2, esp32c3, esp32c6, esp32h2, esp32p4, esp32c5] fail-fast: false steps: - name: Checkout repository diff --git a/clean.sh b/clean.sh new file mode 100755 index 000000000..5fbe754fa --- /dev/null +++ b/clean.sh @@ -0,0 +1,2 @@ +#!/bin/bash +rm -rf out build dist managed_components sdkconfig diff --git a/configs/builds.json b/configs/builds.json index ddfb8e4f8..1e161c683 100644 --- a/configs/builds.json +++ b/configs/builds.json @@ -4,7 +4,7 @@ "file":"libspi_flash.a", "src":"build/esp-idf/spi_flash/libspi_flash.a", "out":"lib/libspi_flash.a", - "targets":["esp32","esp32c2","esp32c3","esp32s2","esp32s3","esp32c6","esp32h2","esp32p4"] + "targets":["esp32","esp32c2","esp32c3","esp32s2","esp32s3","esp32c6","esp32h2","esp32p4","esp32c5"] }, { "file":"libesp_psram.a", @@ -44,6 +44,20 @@ } ], "targets":[ + { + "target": "esp32c5", + "features":["qio_ram"], + "idf_libs":["qio","80m"], + "bootloaders":[ + ["qio","80m"], + ["dio","80m"], + ["qio","40m"], + ["dio","40m"] + ], + "mem_variants":[ + ["dio","80m"] + ] + }, { "target": "esp32p4", "features":["qio_ram"], diff --git a/configs/defconfig.common b/configs/defconfig.common index 48baf5081..abab83e0c 100644 --- a/configs/defconfig.common +++ b/configs/defconfig.common @@ -125,12 +125,17 @@ CONFIG_I2S_ISR_IRAM_SAFE=y # Matter Settings # # Disable Matter BLE -CONFIG_ENABLE_CHIPOBLE=n CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING=n # ESP Insights CONFIG_ENABLE_ESP_INSIGHTS_TRACE=n # Use compact attribute storage mode CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y +# Do not use minimal mDNS within Matter Core +CONFIG_USE_MINIMAL_MDNS=n +# Changes Matter Memory Allocation Mode to use the default malloc() that can use PSRAM is enabled +CONFIG_ESP_MATTER_MEM_ALLOC_MODE_DEFAULT=y +# Disable default mode that only allocates memory from DRAM +CONFIG_ESP_MATTER_MEM_ALLOC_MODE_INTERNAL=n #TinyUSB Config CONFIG_TINYUSB_CDC_MAX_PORTS=2 diff --git a/configs/defconfig.esp32 b/configs/defconfig.esp32 index db01aeab3..ecfa1b1bf 100644 --- a/configs/defconfig.esp32 +++ b/configs/defconfig.esp32 @@ -20,3 +20,9 @@ CONFIG_TWAI_ERRATA_FIX_RX_FRAME_INVALID=y CONFIG_TWAI_ERRATA_FIX_RX_FIFO_CORRUPT=y CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4096 + +# Matter settings: +CONFIG_ENABLE_CHIPOBLE=n +# increase the maximum number of endpoints per device +CONFIG_ESP_MATTER_MAX_DYNAMIC_ENDPOINT_COUNT=32 + diff --git a/configs/defconfig.esp32c2 b/configs/defconfig.esp32c2 index 11c0100a0..9cc76880e 100644 --- a/configs/defconfig.esp32c2 +++ b/configs/defconfig.esp32c2 @@ -1,7 +1,12 @@ CONFIG_XTAL_FREQ_26=y CONFIG_XTAL_FREQ=26 CONFIG_BT_ENABLED=y -CONFIG_BT_BLE_BLUFI_ENABLE=y +CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y +CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n +CONFIG_BTDM_CTRL_MODE_BTDM=n +CONFIG_BT_BLUEDROID_ENABLED=n +CONFIG_BT_NIMBLE_ENABLED=y +CONFIG_BT_NIMBLE_BLUFI_ENABLE=y CONFIG_RTC_CLK_CAL_CYCLES=576 # CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 is not set CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=2304 diff --git a/configs/defconfig.esp32c3 b/configs/defconfig.esp32c3 index 1baf62540..d860aed26 100644 --- a/configs/defconfig.esp32c3 +++ b/configs/defconfig.esp32c3 @@ -2,8 +2,16 @@ CONFIG_RTC_CLK_CAL_CYCLES=576 # CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 is not set CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=2304 CONFIG_BT_ENABLED=y +CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y +CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n +CONFIG_BTDM_CTRL_MODE_BTDM=n +CONFIG_BT_BLUEDROID_ENABLED=n +CONFIG_BT_NIMBLE_ENABLED=y CONFIG_ESP_WIFI_11KV_SUPPORT=y CONFIG_ESP_WIFI_SCAN_CACHE=y CONFIG_ESP_WIFI_MBO_SUPPORT=y CONFIG_ESP_WIFI_11R_SUPPORT=y CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4096 + +# Matter settings: +CONFIG_ENABLE_CHIPOBLE=y diff --git a/configs/defconfig.esp32c5 b/configs/defconfig.esp32c5 new file mode 100644 index 000000000..b6354c2e9 --- /dev/null +++ b/configs/defconfig.esp32c5 @@ -0,0 +1,66 @@ +CONFIG_XTAL_FREQ_AUTO=y +CONFIG_XTAL_FREQ=0 +CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y +CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y +CONFIG_SPIRAM=y + +CONFIG_BT_ENABLED=y +CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y +CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n +CONFIG_BTDM_CTRL_MODE_BTDM=n +CONFIG_BT_BLUEDROID_ENABLED=n +CONFIG_BT_NIMBLE_ENABLED=y +CONFIG_BT_NIMBLE_BLUFI_ENABLE=y +CONFIG_RTC_CLK_CAL_CYCLES=576 +# CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 is not set +CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=2304 +# This Enables RISCV LP for C6 - but it can't be used within Arduino at this time. +#CONFIG_ULP_COPROC_ENABLED=y +#CONFIG_ULP_COPROC_LP_CORE=y +#CONFIG_ULP_COPROC_RESERVE_MEM=4096 + +# +# OpenThread +# +CONFIG_OPENTHREAD_ENABLED=y +# Border Router disabled +# CONFIG_OPENTHREAD_BORDER_ROUTER=y +# CONFIG_OPENTHREAD_RADIO_SPINEL_UART=y + +# DNS64 and NAT64 will be disabled for a while +# OT IDF issue https://github.com/espressif/esp-idf/issues/15069 +# CONFIG_OPENTHREAD_DNS64_CLIENT=y + +# Radio for RPC +# CONFIG_OPENTHREAD_RADIO=y +# CONFIG_OPENTHREAD_RADIO_NATIVE=y +# CONFIG_OPENTHREAD_DIAG=n +CONFIG_OPENTHREAD_COMMISSIONER=y +CONFIG_OPENTHREAD_JOINER=y +CONFIG_OPENTHREAD_CLI=y +CONFIG_OPENTHREAD_SRP_CLIENT=y +CONFIG_OPENTHREAD_DNS_CLIENT=y +# Default dataset for quick start +CONFIG_OPENTHREAD_NETWORK_NAME="OpenThread-ESP" +CONFIG_OPENTHREAD_MESH_LOCAL_PREFIX="fd00:db8:a0:0::/64" +CONFIG_OPENTHREAD_NETWORK_CHANNEL=15 +CONFIG_OPENTHREAD_NETWORK_PANID=0x1234 +CONFIG_OPENTHREAD_NETWORK_EXTPANID="dead00beef00cafe" +CONFIG_OPENTHREAD_NETWORK_MASTERKEY="00112233445566778899aabbccddeeff" +CONFIG_OPENTHREAD_NETWORK_PSKC="104810e2315100afd6bc9215a6bfac53" +# end of OpenThread + +# Matter settings: OpenThread + CHIPoBLE +CONFIG_ENABLE_CHIPOBLE=y +CONFIG_ENABLE_MATTER_OVER_THREAD=y +# Disable Matter over WiFi +CONFIG_ENABLE_WIFI_AP=n +CONFIG_ENABLE_WIFI_STATION=n + +# +# Zigbee +# +CONFIG_ZB_ENABLED=y +CONFIG_ZB_ZED=y +CONFIG_ZB_RADIO_NATIVE=y +# end of Zigbee diff --git a/configs/defconfig.esp32c6 b/configs/defconfig.esp32c6 index d0e2b7bbd..a10bf3335 100644 --- a/configs/defconfig.esp32c6 +++ b/configs/defconfig.esp32c6 @@ -1,5 +1,10 @@ CONFIG_BT_ENABLED=y -CONFIG_BT_BLE_BLUFI_ENABLE=y +CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y +CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n +CONFIG_BTDM_CTRL_MODE_BTDM=n +CONFIG_BT_BLUEDROID_ENABLED=n +CONFIG_BT_NIMBLE_ENABLED=y +CONFIG_BT_NIMBLE_BLUFI_ENABLE=y CONFIG_RTC_CLK_CAL_CYCLES=576 # CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 is not set CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=2304 @@ -39,8 +44,14 @@ CONFIG_OPENTHREAD_NETWORK_MASTERKEY="00112233445566778899aabbccddeeff" CONFIG_OPENTHREAD_NETWORK_PSKC="104810e2315100afd6bc9215a6bfac53" # end of OpenThread -# Matter shall use only WiFi -CONFIG_ENABLE_MATTER_OVER_THREAD=n +# Matter settings: WiFi and OpenThread + CHIPoBLE +CONFIG_ENABLE_CHIPOBLE=y +CONFIG_ENABLE_MATTER_OVER_THREAD=y +# Set endpoint id for Thread and Wi-Fi, depending on the secondary network interface endpoint id. +CONFIG_THREAD_NETWORK_ENDPOINT_ID=2 +CONFIG_WIFI_NETWORK_ENDPOINT_ID=0 +# increase the maximum number of endpoints per device +CONFIG_ESP_MATTER_MAX_DYNAMIC_ENDPOINT_COUNT=32 # # Zigbee diff --git a/configs/defconfig.esp32h2 b/configs/defconfig.esp32h2 index 024120d34..89bec3064 100644 --- a/configs/defconfig.esp32h2 +++ b/configs/defconfig.esp32h2 @@ -1,5 +1,10 @@ CONFIG_BT_ENABLED=y -CONFIG_BT_BLE_BLUFI_ENABLE=y +CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y +CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n +CONFIG_BTDM_CTRL_MODE_BTDM=n +CONFIG_BT_BLUEDROID_ENABLED=n +CONFIG_BT_NIMBLE_ENABLED=y +CONFIG_BT_NIMBLE_BLUFI_ENABLE=y CONFIG_RTC_CLK_CAL_CYCLES=576 # CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 is not set CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=2304 @@ -35,6 +40,13 @@ CONFIG_OPENTHREAD_NETWORK_MASTERKEY="00112233445566778899aabbccddeeff" CONFIG_OPENTHREAD_NETWORK_PSKC="104810e2315100afd6bc9215a6bfac53" # end of OpenThread +# Matter settings: OpenThread + CHIPoBLE +CONFIG_ENABLE_CHIPOBLE=y +CONFIG_ENABLE_MATTER_OVER_THREAD=y +# Disable Matter over WiFi +CONFIG_ENABLE_WIFI_AP=n +CONFIG_ENABLE_WIFI_STATION=n + # # Zigbee # diff --git a/configs/defconfig.esp32s2 b/configs/defconfig.esp32s2 index 3b0af548a..f90b0fab5 100644 --- a/configs/defconfig.esp32s2 +++ b/configs/defconfig.esp32s2 @@ -15,3 +15,6 @@ CONFIG_ULP_COPROC_ENABLED=y CONFIG_ULP_COPROC_TYPE_FSM=y # CONFIG_ULP_COPROC_TYPE_RISCV=y CONFIG_ULP_COPROC_RESERVE_MEM=512 + +# Matter settings: +CONFIG_ENABLE_CHIPOBLE=n diff --git a/configs/defconfig.esp32s3 b/configs/defconfig.esp32s3 index 36fa6b6a5..c80667029 100644 --- a/configs/defconfig.esp32s3 +++ b/configs/defconfig.esp32s3 @@ -1,4 +1,9 @@ CONFIG_BT_ENABLED=y +CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y +CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n +CONFIG_BTDM_CTRL_MODE_BTDM=n +CONFIG_BT_BLUEDROID_ENABLED=n +CONFIG_BT_NIMBLE_ENABLED=y CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y CONFIG_SPIRAM=y @@ -21,3 +26,9 @@ CONFIG_ULP_COPROC_RESERVE_MEM=512 # RGB Display Optimizations # CONFIG_LCD_RGB_ISR_IRAM_SAFE is not set CONFIG_LCD_RGB_RESTART_IN_VSYNC=y + +# Matter settings: +CONFIG_ENABLE_CHIPOBLE=y +# increase the maximum number of endpoints per device +CONFIG_ESP_MATTER_MAX_DYNAMIC_ENDPOINT_COUNT=32 + diff --git a/configs/defconfig.qio_ram b/configs/defconfig.qio_ram index 902680b3a..c5c13e4dd 100644 --- a/configs/defconfig.qio_ram +++ b/configs/defconfig.qio_ram @@ -1 +1,2 @@ +# CONFIG_SPIRAM_BOOT_HW_INIT is not set # CONFIG_SPIRAM_BOOT_INIT is not set \ No newline at end of file diff --git a/main/idf_component.yml b/main/idf_component.yml index a85eca541..4ba96d85a 100644 --- a/main/idf_component.yml +++ b/main/idf_component.yml @@ -20,4 +20,4 @@ dependencies: version: "1.4.1" require: public rules: - - if: "target not in [esp32c2, esp32h2, esp32p4]" + - if: "target not in [esp32c2, esp32p4]" diff --git a/patches/lwip_max_tcp_pcb.diff b/patches/lwip_max_tcp_pcb.diff deleted file mode 100644 index 6b9e73cb6..000000000 --- a/patches/lwip_max_tcp_pcb.diff +++ /dev/null @@ -1,118 +0,0 @@ -diff --git a/components/lwip/lwip/src/core/memp.c b/components/lwip/lwip/src/core/memp.c -index 352ce5a55127a658b6b3c9d8541298c42df332ff..39433cf476b3456b046e337e9b1f016299964a84 100644 ---- a/components/lwip/lwip/src/core/memp.c -+++ b/components/lwip/lwip/src/core/memp.c -@@ -240,6 +240,10 @@ memp_init(void) - #endif /* MEMP_OVERFLOW_CHECK >= 2 */ - } - -+#if MEMP_MEM_MALLOC && ESP_LWIP && LWIP_TCP -+static u32_t num_tcp_pcb = 0; -+#endif -+ - static void * - #if !MEMP_OVERFLOW_CHECK - do_memp_malloc_pool(const struct memp_desc *desc) -@@ -251,6 +255,16 @@ do_memp_malloc_pool_fn(const struct memp_desc *desc, const char *file, const int - SYS_ARCH_DECL_PROTECT(old_level); - - #if MEMP_MEM_MALLOC -+#if ESP_LWIP -+#if LWIP_TCP -+ if(desc == memp_pools[MEMP_TCP_PCB]){ -+ if(num_tcp_pcb >= MEMP_NUM_TCP_PCB){ -+ return NULL; -+ } -+ } -+#endif -+#endif -+ - memp = (struct memp *)mem_malloc(MEMP_SIZE + MEMP_ALIGN_SIZE(desc->size)); - SYS_ARCH_PROTECT(old_level); - #else /* MEMP_MEM_MALLOC */ -@@ -260,6 +274,12 @@ do_memp_malloc_pool_fn(const struct memp_desc *desc, const char *file, const int - #endif /* MEMP_MEM_MALLOC */ - - if (memp != NULL) { -+#if MEMP_MEM_MALLOC && ESP_LWIP && LWIP_TCP -+ if (desc == memp_pools[MEMP_TCP_PCB]) { -+ num_tcp_pcb++; -+ } -+#endif -+ - #if !MEMP_MEM_MALLOC - #if MEMP_OVERFLOW_CHECK == 1 - memp_overflow_check_element(memp, desc); -@@ -369,6 +389,12 @@ do_memp_free_pool(const struct memp_desc *desc, void *mem) - - SYS_ARCH_PROTECT(old_level); - -+#if MEMP_MEM_MALLOC && ESP_LWIP && LWIP_TCP -+ if (desc == memp_pools[MEMP_TCP_PCB]) { -+ num_tcp_pcb--; -+ } -+#endif -+ - #if MEMP_OVERFLOW_CHECK == 1 - memp_overflow_check_element(memp, desc); - #endif /* MEMP_OVERFLOW_CHECK */ -diff --git a/components/lwip/lwip/src/core/tcp.c b/components/lwip/lwip/src/core/tcp.c -index 3fbdd89ae07807208ff7466abb50f90b5e7727e4..fe6baaf250927cb4b89f8d1dbd41c73def88692b 100644 ---- a/components/lwip/lwip/src/core/tcp.c -+++ b/components/lwip/lwip/src/core/tcp.c -@@ -1765,7 +1765,9 @@ tcp_kill_state(enum tcp_state state) - struct tcp_pcb *pcb, *inactive; - u32_t inactivity; - -+#if !ESP_LWIP - LWIP_ASSERT("invalid state", (state == CLOSING) || (state == LAST_ACK)); -+#endif - - inactivity = 0; - inactive = NULL; -@@ -1870,17 +1872,41 @@ tcp_alloc(u8_t prio) - tcp_kill_state(CLOSING); - /* Try to allocate a tcp_pcb again. */ - pcb = (struct tcp_pcb *)memp_malloc(MEMP_TCP_PCB); -+#if ESP_LWIP - if (pcb == NULL) { -- /* Try killing oldest active connection with lower priority than the new one. */ -- LWIP_DEBUGF(TCP_DEBUG, ("tcp_alloc: killing oldest connection with prio lower than %d\n", prio)); -- tcp_kill_prio(prio); -- /* Try to allocate a tcp_pcb again. */ -+ /* Try killing oldest connection in FIN_WAIT_2. */ -+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_alloc: killing off oldest FIN_WAIT_2 connection\n")); -+ tcp_kill_state(FIN_WAIT_2); - pcb = (struct tcp_pcb *)memp_malloc(MEMP_TCP_PCB); -+ if (pcb == NULL) { -+ /* Try killing oldest connection in FIN_WAIT_1. */ -+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_alloc: killing off oldest FIN_WAIT_1 connection\n")); -+ tcp_kill_state(FIN_WAIT_1); -+ pcb = (struct tcp_pcb *)memp_malloc(MEMP_TCP_PCB); -+#endif -+ if (pcb == NULL) { -+ /* Try killing oldest active connection with lower priority than the new one. */ -+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_alloc: killing oldest connection with prio lower than %d\n", prio)); -+ tcp_kill_prio(prio); -+ /* Try to allocate a tcp_pcb again. */ -+ pcb = (struct tcp_pcb *)memp_malloc(MEMP_TCP_PCB); -+ if (pcb != NULL) { -+ /* adjust err stats: memp_malloc failed multiple times before */ -+ MEMP_STATS_DEC(err, MEMP_TCP_PCB); -+ } -+ } -+#if ESP_LWIP -+ if (pcb != NULL) { -+ /* adjust err stats: memp_malloc failed multiple times before */ -+ MEMP_STATS_DEC(err, MEMP_TCP_PCB); -+ } -+ } - if (pcb != NULL) { - /* adjust err stats: memp_malloc failed multiple times before */ - MEMP_STATS_DEC(err, MEMP_TCP_PCB); - } - } -+#endif - if (pcb != NULL) { - /* adjust err stats: memp_malloc failed multiple times before */ - MEMP_STATS_DEC(err, MEMP_TCP_PCB); diff --git a/tools/config.sh b/tools/config.sh index 4f17d8a12..707867a90 100755 --- a/tools/config.sh +++ b/tools/config.sh @@ -6,11 +6,11 @@ if [ -z $IDF_PATH ]; then fi if [ -z $IDF_BRANCH ]; then - IDF_BRANCH="release/v5.4" + IDF_BRANCH="release/v5.5" fi if [ -z $AR_PR_TARGET_BRANCH ]; then - AR_PR_TARGET_BRANCH="master" + AR_PR_TARGET_BRANCH="release/v3.3.x" fi if [ -z $IDF_TARGET ]; then diff --git a/tools/gen_pioarduino_manifest.py b/tools/gen_pioarduino_manifest.py index 9d2b99c19..2a76d6cd8 100644 --- a/tools/gen_pioarduino_manifest.py +++ b/tools/gen_pioarduino_manifest.py @@ -23,6 +23,9 @@ def convert_version(version_string): 'v7.7.7' becomes '7.7.7' """ + if version_string == 'heads/master': + return ".".join(("5", "5", "0")) #temporary + regex_pattern = ( r"v(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)\.*(?P0|[1-9]\d*)*" ) diff --git a/tools/install-esp-idf.sh b/tools/install-esp-idf.sh index 06a67c354..45c63d200 100755 --- a/tools/install-esp-idf.sh +++ b/tools/install-esp-idf.sh @@ -39,10 +39,9 @@ if [ ! -x $idf_was_installed ] || [ ! -x $commit_predefined ]; then export IDF_BRANCH=$(git -C "$IDF_PATH" symbolic-ref --short HEAD || git -C "$IDF_PATH" tag --points-at HEAD) # Temporarily patch the ESP32-S2 I2C LL driver to keep the clock source - cd $IDF_PATH - patch -p1 -N -i $AR_PATCHES/esp32s2_i2c_ll_master_init.diff - patch -p1 -N -i $AR_PATCHES/lwip_max_tcp_pcb.diff - cd - + #cd $IDF_PATH + #patch -p1 -N -i $AR_PATCHES/esp32s2_i2c_ll_master_init.diff + #cd - fi # From c658f0f2fc135f6ba77aa7862584d78a924f0697 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Wed, 23 Jul 2025 15:32:41 +0300 Subject: [PATCH 32/48] Update configs for cron and build.sh for IDF 5.5 --- .github/workflows/cron.yml | 8 ++++---- tools/config.sh | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cron.yml b/.github/workflows/cron.yml index ade7e7fa5..48e1ff7a9 100644 --- a/.github/workflows/cron.yml +++ b/.github/workflows/cron.yml @@ -38,9 +38,9 @@ jobs: # - idf_branch: "release/v5.3" # lib_builder_branch: "release/v5.3" # targets: "esp32,esp32s2,esp32s3,esp32c3,esp32c6,esp32h2,esp32p4" - - idf_branch: "release/v5.4" - lib_builder_branch: "master" - targets: "esp32,esp32s2,esp32s3,esp32c3,esp32c6,esp32h2,esp32p4" + # - idf_branch: "release/v5.4" + # lib_builder_branch: "release/v5.4" + # targets: "esp32,esp32s2,esp32s3,esp32c3,esp32c6,esp32h2,esp32p4" - idf_branch: "release/v5.5" - lib_builder_branch: "release/v5.5" + lib_builder_branch: "master" targets: "esp32,esp32s2,esp32s3,esp32c3,esp32c6,esp32h2,esp32p4,esp32c5" diff --git a/tools/config.sh b/tools/config.sh index 707867a90..1ede4185c 100755 --- a/tools/config.sh +++ b/tools/config.sh @@ -10,7 +10,7 @@ if [ -z $IDF_BRANCH ]; then fi if [ -z $AR_PR_TARGET_BRANCH ]; then - AR_PR_TARGET_BRANCH="release/v3.3.x" + AR_PR_TARGET_BRANCH="master" fi if [ -z $IDF_TARGET ]; then From 4faed90b1711fa1d0b445e6baf133e3370466db8 Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Tue, 29 Jul 2025 13:32:39 +0300 Subject: [PATCH 33/48] Enable 200MHz PSRAM for ESP32-P4 (#310) --- configs/builds.json | 12 ++++++------ configs/defconfig.40m_200m | 2 ++ configs/defconfig.80m_200m | 2 ++ configs/defconfig.esp32p4 | 1 - 4 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 configs/defconfig.40m_200m create mode 100644 configs/defconfig.80m_200m diff --git a/configs/builds.json b/configs/builds.json index 1e161c683..036f0558c 100644 --- a/configs/builds.json +++ b/configs/builds.json @@ -61,15 +61,15 @@ { "target": "esp32p4", "features":["qio_ram"], - "idf_libs":["qio","80m"], + "idf_libs":["qio","80m_200m"], "bootloaders":[ - ["qio","80m"], - ["dio","80m"], - ["qio","40m"], - ["dio","40m"] + ["qio","80m_200m"], + ["dio","80m_200m"], + ["qio","40m_200m"], + ["dio","40m_200m"] ], "mem_variants":[ - ["dio","80m"] + ["dio","80m_200m"] ] }, { diff --git a/configs/defconfig.40m_200m b/configs/defconfig.40m_200m new file mode 100644 index 000000000..6e0c0a856 --- /dev/null +++ b/configs/defconfig.40m_200m @@ -0,0 +1,2 @@ +CONFIG_ESPTOOLPY_FLASHFREQ_40M=y +CONFIG_SPIRAM_SPEED_200M=y \ No newline at end of file diff --git a/configs/defconfig.80m_200m b/configs/defconfig.80m_200m new file mode 100644 index 000000000..aa837b24c --- /dev/null +++ b/configs/defconfig.80m_200m @@ -0,0 +1,2 @@ +CONFIG_ESPTOOLPY_FLASHFREQ_80M=y +CONFIG_SPIRAM_SPEED_200M=y \ No newline at end of file diff --git a/configs/defconfig.esp32p4 b/configs/defconfig.esp32p4 index 9cc5e8392..fcf5f28d3 100644 --- a/configs/defconfig.esp32p4 +++ b/configs/defconfig.esp32p4 @@ -1,6 +1,5 @@ CONFIG_IDF_EXPERIMENTAL_FEATURES=y CONFIG_SPIRAM=y -CONFIG_SPIRAM_SPEED_200M=y # CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 is not set CONFIG_LWIP_TCP_SACK_OUT=y From beff44533067167aee6aedf014ec918b2ff750f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Tue, 29 Jul 2025 12:32:55 +0200 Subject: [PATCH 34/48] fix(wifi): Use external log wrap (#309) --- configs/defconfig.common | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/defconfig.common b/configs/defconfig.common index abab83e0c..2f34548aa 100644 --- a/configs/defconfig.common +++ b/configs/defconfig.common @@ -111,6 +111,7 @@ CONFIG_DIAG_ENABLE_HEAP_METRICS=y CONFIG_DIAG_ENABLE_WIFI_METRICS=y CONFIG_DIAG_ENABLE_VARIABLES=y CONFIG_DIAG_ENABLE_NETWORK_VARIABLES=y +CONFIG_DIAG_USE_EXTERNAL_LOG_WRAP=y CONFIG_ESP_COREDUMP_ENABLE=y CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH=y CONFIG_ESP_COREDUMP_DATA_FORMAT_ELF=y From 3aa1668103c1a7df01c095b3858206ab38b9eef3 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Mon, 1 Sep 2025 14:14:03 +0300 Subject: [PATCH 35/48] Update clean.sh --- clean.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clean.sh b/clean.sh index 5fbe754fa..41163b44c 100755 --- a/clean.sh +++ b/clean.sh @@ -1,2 +1,2 @@ #!/bin/bash -rm -rf out build dist managed_components sdkconfig +rm -rf build dist managed_components out sdkconfig dependencies.lock From 44177d2ea784b20031e97fec1e6418ed8e63c1d5 Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Thu, 4 Sep 2025 10:29:33 +0300 Subject: [PATCH 36/48] Enable srmodel export for ESP32-P4 (#313) --- build.sh | 2 +- configs/builds.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index 50e376c2a..a1de00765 100755 --- a/build.sh +++ b/build.sh @@ -226,7 +226,7 @@ for target_json in `jq -c '.targets[]' configs/builds.json`; do idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$idf_libs_configs" idf-libs if [ $? -ne 0 ]; then exit 1; fi - if [ "$target" == "esp32s3" ]; then + if [ "$target" == "esp32s3" ] || [ "$target" == "esp32p4" ]; then idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$idf_libs_configs" srmodels_bin if [ $? -ne 0 ]; then exit 1; fi AR_SDK="$AR_TOOLS/esp32-arduino-libs/$target" diff --git a/configs/builds.json b/configs/builds.json index 036f0558c..d40c15d2f 100644 --- a/configs/builds.json +++ b/configs/builds.json @@ -60,7 +60,7 @@ }, { "target": "esp32p4", - "features":["qio_ram"], + "features":["qio_ram","esp_sr"], "idf_libs":["qio","80m_200m"], "bootloaders":[ ["qio","80m_200m"], From 0209f1fde2a1b8a97f8740a05dd588a6140c1115 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Wed, 10 Sep 2025 08:40:02 -0300 Subject: [PATCH 37/48] feat(ble): Enable BLE for P4 through esp-hosted (#318) --- configs/defconfig.esp32p4 | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/configs/defconfig.esp32p4 b/configs/defconfig.esp32p4 index fcf5f28d3..b94284eff 100644 --- a/configs/defconfig.esp32p4 +++ b/configs/defconfig.esp32p4 @@ -3,6 +3,7 @@ CONFIG_SPIRAM=y # CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 is not set CONFIG_LWIP_TCP_SACK_OUT=y +# ESP-Hosted-MCU CONFIG_SLAVE_IDF_TARGET_ESP32C6=y CONFIG_ESP_SDIO_BUS_WIDTH=4 CONFIG_ESP_SDIO_CLOCK_FREQ_KHZ=40000 @@ -13,6 +14,15 @@ CONFIG_ESP_SDIO_PIN_D1=15 CONFIG_ESP_SDIO_PIN_D2=16 CONFIG_ESP_SDIO_PIN_D3=17 +# Bluetooth through ESP-Hosted-MCU +CONFIG_BT_ENABLED=y +CONFIG_BT_CONTROLLER_DISABLED=y +CONFIG_BT_BLUEDROID_ENABLED=n +CONFIG_BT_NIMBLE_ENABLED=y +CONFIG_BT_NIMBLE_TRANSPORT_UART=n +CONFIG_ESP_HOSTED_ENABLE_BT_NIMBLE=y +CONFIG_ESP_HOSTED_NIMBLE_HCI_VHCI=y + # RGB Display Optimizations CONFIG_LCD_RGB_ISR_IRAM_SAFE=y CONFIG_LCD_RGB_RESTART_IN_VSYNC=y From 1cec1dd183a84a651e6eddfa9a411a82acef9711 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Wed, 10 Sep 2025 13:43:40 +0200 Subject: [PATCH 38/48] Update ASFLAGS for pioarduino (#317) * Update ASFLAGS for esp32p4 target and default for riscv targets * Refactor assembler flags extraction in copy-libs.sh Refactor assembler flags handling to streamline the extraction of -march, -mabi, and -mlongcalls flags from CXX and CC flags. --- tools/copy-libs.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tools/copy-libs.sh b/tools/copy-libs.sh index 7c302ab66..a49b851f0 100755 --- a/tools/copy-libs.sh +++ b/tools/copy-libs.sh @@ -318,16 +318,23 @@ done mkdir -p "$AR_SDK" +# Keep only -march, -mabi and -mlongcalls flags for Assembler +PIOARDUINO_AS_FLAGS=$( + { + echo "$PIOARDUINO_CXX_FLAGS" | grep -oE '\-march=[^[:space:]]*|\-mabi=[^[:space:]]*|\-mlongcalls' + echo "$PIOARDUINO_CC_FLAGS" | grep -oE '\-march=[^[:space:]]*|\-mabi=[^[:space:]]*|\-mlongcalls' + } | awk '!seen[$0]++' | paste -sd ' ' +) + # start generation of pioarduino-build.py AR_PIOARDUINO_PY="$AR_SDK/pioarduino-build.py" cat configs/pioarduino_start.txt > "$AR_PIOARDUINO_PY" echo " ASFLAGS=[" >> "$AR_PIOARDUINO_PY" -if [ "$IS_XTENSA" = "y" ]; then - echo " \"-mlongcalls\"" >> "$AR_PIOARDUINO_PY" -else - echo " \"-march=rv32imc\"" >> "$AR_PIOARDUINO_PY" -fi +set -- $PIOARDUINO_AS_FLAGS +for item; do + echo " \"$item\"," >> "$AR_PIOARDUINO_PY" +done echo " ]," >> "$AR_PIOARDUINO_PY" echo "" >> "$AR_PIOARDUINO_PY" From 87aa70c33c10533030a64bc9f0d476f34e478df9 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Wed, 10 Sep 2025 13:44:01 +0200 Subject: [PATCH 39/48] Enable TCP SACK option in defconfig (#316) --- configs/defconfig.common | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/defconfig.common b/configs/defconfig.common index 2f34548aa..68f1ad767 100644 --- a/configs/defconfig.common +++ b/configs/defconfig.common @@ -57,6 +57,7 @@ CONFIG_LWIP_ETHARP_TRUST_IP_MAC=y CONFIG_LWIP_TCP_SYNMAXRTX=6 CONFIG_LWIP_TCP_MSS=1436 CONFIG_LWIP_TCP_RTO_TIME=3000 +CONFIG_LWIP_TCP_SACK_OUT=y CONFIG_LWIP_TCPIP_TASK_STACK_SIZE=4096 CONFIG_LWIP_TCPIP_TASK_AFFINITY_CPU0=y CONFIG_LWIP_MAX_SOCKETS=16 From 487f7433404ca9e6837e3f2c840edb89fe3bfbe4 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Tue, 16 Sep 2025 05:22:31 -0300 Subject: [PATCH 40/48] fix(nimble): Enable NVS persist to match bluedroid behavior (#320) --- configs/defconfig.esp32c2 | 1 + configs/defconfig.esp32c3 | 1 + configs/defconfig.esp32c5 | 1 + configs/defconfig.esp32c6 | 1 + configs/defconfig.esp32h2 | 1 + configs/defconfig.esp32p4 | 1 + configs/defconfig.esp32s3 | 1 + 7 files changed, 7 insertions(+) diff --git a/configs/defconfig.esp32c2 b/configs/defconfig.esp32c2 index 9cc76880e..baaaeb7c7 100644 --- a/configs/defconfig.esp32c2 +++ b/configs/defconfig.esp32c2 @@ -7,6 +7,7 @@ CONFIG_BTDM_CTRL_MODE_BTDM=n CONFIG_BT_BLUEDROID_ENABLED=n CONFIG_BT_NIMBLE_ENABLED=y CONFIG_BT_NIMBLE_BLUFI_ENABLE=y +CONFIG_BT_NIMBLE_NVS_PERSIST=y CONFIG_RTC_CLK_CAL_CYCLES=576 # CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 is not set CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=2304 diff --git a/configs/defconfig.esp32c3 b/configs/defconfig.esp32c3 index d860aed26..4b7009786 100644 --- a/configs/defconfig.esp32c3 +++ b/configs/defconfig.esp32c3 @@ -7,6 +7,7 @@ CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n CONFIG_BTDM_CTRL_MODE_BTDM=n CONFIG_BT_BLUEDROID_ENABLED=n CONFIG_BT_NIMBLE_ENABLED=y +CONFIG_BT_NIMBLE_NVS_PERSIST=y CONFIG_ESP_WIFI_11KV_SUPPORT=y CONFIG_ESP_WIFI_SCAN_CACHE=y CONFIG_ESP_WIFI_MBO_SUPPORT=y diff --git a/configs/defconfig.esp32c5 b/configs/defconfig.esp32c5 index b6354c2e9..2ad03f3ac 100644 --- a/configs/defconfig.esp32c5 +++ b/configs/defconfig.esp32c5 @@ -11,6 +11,7 @@ CONFIG_BTDM_CTRL_MODE_BTDM=n CONFIG_BT_BLUEDROID_ENABLED=n CONFIG_BT_NIMBLE_ENABLED=y CONFIG_BT_NIMBLE_BLUFI_ENABLE=y +CONFIG_BT_NIMBLE_NVS_PERSIST=y CONFIG_RTC_CLK_CAL_CYCLES=576 # CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 is not set CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=2304 diff --git a/configs/defconfig.esp32c6 b/configs/defconfig.esp32c6 index a10bf3335..c77b4e65a 100644 --- a/configs/defconfig.esp32c6 +++ b/configs/defconfig.esp32c6 @@ -5,6 +5,7 @@ CONFIG_BTDM_CTRL_MODE_BTDM=n CONFIG_BT_BLUEDROID_ENABLED=n CONFIG_BT_NIMBLE_ENABLED=y CONFIG_BT_NIMBLE_BLUFI_ENABLE=y +CONFIG_BT_NIMBLE_NVS_PERSIST=y CONFIG_RTC_CLK_CAL_CYCLES=576 # CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 is not set CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=2304 diff --git a/configs/defconfig.esp32h2 b/configs/defconfig.esp32h2 index 89bec3064..61ff6d17a 100644 --- a/configs/defconfig.esp32h2 +++ b/configs/defconfig.esp32h2 @@ -5,6 +5,7 @@ CONFIG_BTDM_CTRL_MODE_BTDM=n CONFIG_BT_BLUEDROID_ENABLED=n CONFIG_BT_NIMBLE_ENABLED=y CONFIG_BT_NIMBLE_BLUFI_ENABLE=y +CONFIG_BT_NIMBLE_NVS_PERSIST=y CONFIG_RTC_CLK_CAL_CYCLES=576 # CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 is not set CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=2304 diff --git a/configs/defconfig.esp32p4 b/configs/defconfig.esp32p4 index b94284eff..74b8ac880 100644 --- a/configs/defconfig.esp32p4 +++ b/configs/defconfig.esp32p4 @@ -19,6 +19,7 @@ CONFIG_BT_ENABLED=y CONFIG_BT_CONTROLLER_DISABLED=y CONFIG_BT_BLUEDROID_ENABLED=n CONFIG_BT_NIMBLE_ENABLED=y +CONFIG_BT_NIMBLE_NVS_PERSIST=y CONFIG_BT_NIMBLE_TRANSPORT_UART=n CONFIG_ESP_HOSTED_ENABLE_BT_NIMBLE=y CONFIG_ESP_HOSTED_NIMBLE_HCI_VHCI=y diff --git a/configs/defconfig.esp32s3 b/configs/defconfig.esp32s3 index c80667029..12aec7c47 100644 --- a/configs/defconfig.esp32s3 +++ b/configs/defconfig.esp32s3 @@ -4,6 +4,7 @@ CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n CONFIG_BTDM_CTRL_MODE_BTDM=n CONFIG_BT_BLUEDROID_ENABLED=n CONFIG_BT_NIMBLE_ENABLED=y +CONFIG_BT_NIMBLE_NVS_PERSIST=y CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y CONFIG_SPIRAM=y From 59038b5439a6e66cc07961f68128b0bdfbba3023 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Mon, 13 Oct 2025 16:04:47 +0200 Subject: [PATCH 41/48] Update ESP32P4 defconfig with Wi-Fi and LWIP settings (#323) Added configuration options for Wi-Fi and LWIP buffers. --- configs/defconfig.esp32p4 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/configs/defconfig.esp32p4 b/configs/defconfig.esp32p4 index 74b8ac880..3a1a2b3da 100644 --- a/configs/defconfig.esp32p4 +++ b/configs/defconfig.esp32p4 @@ -14,6 +14,20 @@ CONFIG_ESP_SDIO_PIN_D1=15 CONFIG_ESP_SDIO_PIN_D2=16 CONFIG_ESP_SDIO_PIN_D3=17 +CONFIG_WIFI_RMT_STATIC_RX_BUFFER_NUM=16 +CONFIG_WIFI_RMT_DYNAMIC_RX_BUFFER_NUM=64 +CONFIG_WIFI_RMT_DYNAMIC_TX_BUFFER_NUM=64 +CONFIG_WIFI_RMT_AMPDU_TX_ENABLED=y +CONFIG_WIFI_RMT_TX_BA_WIN=32 +CONFIG_WIFI_RMT_AMPDU_RX_ENABLED=y +CONFIG_WIFI_RMT_RX_BA_WIN=32 + +CONFIG_LWIP_TCP_SND_BUF_DEFAULT=65534 +CONFIG_LWIP_TCP_WND_DEFAULT=65534 +CONFIG_LWIP_TCP_RECVMBOX_SIZE=64 +CONFIG_LWIP_UDP_RECVMBOX_SIZE=64 +CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=64 + # Bluetooth through ESP-Hosted-MCU CONFIG_BT_ENABLED=y CONFIG_BT_CONTROLLER_DISABLED=y From 24e56584b2dc26227acdfcbcd3650822417277f3 Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Fri, 17 Oct 2025 13:32:56 +0300 Subject: [PATCH 42/48] Update P4 config for C5 slaves (#324) --- configs/defconfig.esp32p4 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/configs/defconfig.esp32p4 b/configs/defconfig.esp32p4 index 3a1a2b3da..da605c0fe 100644 --- a/configs/defconfig.esp32p4 +++ b/configs/defconfig.esp32p4 @@ -14,13 +14,13 @@ CONFIG_ESP_SDIO_PIN_D1=15 CONFIG_ESP_SDIO_PIN_D2=16 CONFIG_ESP_SDIO_PIN_D3=17 -CONFIG_WIFI_RMT_STATIC_RX_BUFFER_NUM=16 -CONFIG_WIFI_RMT_DYNAMIC_RX_BUFFER_NUM=64 -CONFIG_WIFI_RMT_DYNAMIC_TX_BUFFER_NUM=64 +CONFIG_WIFI_RMT_STATIC_RX_BUFFER_NUM=10 +CONFIG_WIFI_RMT_DYNAMIC_RX_BUFFER_NUM=32 +CONFIG_WIFI_RMT_DYNAMIC_TX_BUFFER_NUM=32 CONFIG_WIFI_RMT_AMPDU_TX_ENABLED=y CONFIG_WIFI_RMT_TX_BA_WIN=32 CONFIG_WIFI_RMT_AMPDU_RX_ENABLED=y -CONFIG_WIFI_RMT_RX_BA_WIN=32 +CONFIG_WIFI_RMT_RX_BA_WIN=16 CONFIG_LWIP_TCP_SND_BUF_DEFAULT=65534 CONFIG_LWIP_TCP_WND_DEFAULT=65534 From 5236148770dd0fc5f9dce28dd43aa9338b00c60d Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Mon, 27 Oct 2025 13:53:41 +0200 Subject: [PATCH 43/48] Make TCP buffer dividable by MSS (#325) By default the buffer has 16 bytes overhead --- configs/defconfig.common | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/defconfig.common b/configs/defconfig.common index 68f1ad767..1f4a1924d 100644 --- a/configs/defconfig.common +++ b/configs/defconfig.common @@ -56,6 +56,7 @@ CONFIG_LWIP_ETHARP_TRUST_IP_MAC=y # CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set CONFIG_LWIP_TCP_SYNMAXRTX=6 CONFIG_LWIP_TCP_MSS=1436 +CONFIG_LWIP_TCP_SND_BUF_DEFAULT=5744 CONFIG_LWIP_TCP_RTO_TIME=3000 CONFIG_LWIP_TCP_SACK_OUT=y CONFIG_LWIP_TCPIP_TASK_STACK_SIZE=4096 From fc0e6bbba162d42f4b0b5035234ed2b14abfe07f Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Mon, 27 Oct 2025 15:27:21 +0200 Subject: [PATCH 44/48] Add script to build ESP-Hosted slave firmwares (#326) --- build.sh | 16 +++++++++++-- tools/build-hosted.sh | 52 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100755 tools/build-hosted.sh diff --git a/build.sh b/build.sh index a1de00765..bc6622680 100755 --- a/build.sh +++ b/build.sh @@ -31,7 +31,7 @@ if [ -z $DEPLOY_OUT ]; then fi function print_help() { - echo "Usage: build.sh [-s] [-n] [-A ] [-I ] [-D ] [-i ] [-c ] [-t ] [-b ] [config ...]" + echo "Usage: build.sh [-s] [-n] [-A ] [-I ] [-D ] [-i ] [-c ] [-t ] [-b ] [config ...]" echo " -s Skip installing/updating of ESP-IDF and all components" echo " -n Disable ccache" echo " -A Set which branch of arduino-esp32 to be used for compilation" @@ -87,7 +87,8 @@ while getopts ":A:I:i:c:t:b:D:sde" opt; do [ "$b" != "reconfigure" ] && [ "$b" != "idf-libs" ] && [ "$b" != "copy-bootloader" ] && - [ "$b" != "mem-variant" ]; then + [ "$b" != "mem-variant" ] && + [ "$b" != "hosted" ]; then print_help fi BUILD_TYPE="$b" @@ -137,6 +138,11 @@ if [ "$BUILD_TYPE" != "all" ]; then print_help fi + if [ "$BUILD_TYPE" == "hosted" ]; then + ./tools/build-hosted.sh + exit $? + fi + # Target Features Configs for target_json in `jq -c '.targets[]' configs/builds.json`; do target=$(echo "$target_json" | jq -c '.target' | tr -d '"') @@ -226,6 +232,12 @@ for target_json in `jq -c '.targets[]' configs/builds.json`; do idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$idf_libs_configs" idf-libs if [ $? -ne 0 ]; then exit 1; fi + # Build ESP-Hosted slave firmwares + if [ "$target" == "esp32p4" ]; then + ./tools/build-hosted.sh + fi + + # Build ESP-SR Models if [ "$target" == "esp32s3" ] || [ "$target" == "esp32p4" ]; then idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$idf_libs_configs" srmodels_bin if [ $? -ne 0 ]; then exit 1; fi diff --git a/tools/build-hosted.sh b/tools/build-hosted.sh new file mode 100755 index 000000000..fb168c5cf --- /dev/null +++ b/tools/build-hosted.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +CCACHE_ENABLE=1 + +export IDF_CCACHE_ENABLE=$CCACHE_ENABLE +source ./tools/config.sh + +SLAVE_DIR="$AR_MANAGED_COMPS/espressif__esp_hosted/slave" + +if [ ! -d "$SLAVE_DIR" ]; then + echo "ESP-Hosted component not found!" + exit 1 +fi + +VERSION_FILE="$SLAVE_DIR/main/esp_hosted_coprocessor_fw_ver.h" + +if [ ! -f "$VERSION_FILE" ]; then + echo "Error: File $VERSION_FILE not found!" + exit 1 +fi + +MAJOR=$(grep "PROJECT_VERSION_MAJOR_1" "$VERSION_FILE" | sed 's/.*PROJECT_VERSION_MAJOR_1 \([0-9]*\).*/\1/') +MINOR=$(grep "PROJECT_VERSION_MINOR_1" "$VERSION_FILE" | sed 's/.*PROJECT_VERSION_MINOR_1 \([0-9]*\).*/\1/') +PATCH=$(grep "PROJECT_VERSION_PATCH_1" "$VERSION_FILE" | sed 's/.*PROJECT_VERSION_PATCH_1 \([0-9]*\).*/\1/') + +if [ -z "$MAJOR" ] || [ -z "$MINOR" ] || [ -z "$PATCH" ]; then + echo "Error: Could not extract all version infos!" + echo "MAJOR: '$MAJOR', MINOR: '$MINOR', PATCH: '$PATCH'" + exit 1 +fi + +VERSION="$MAJOR.$MINOR.$PATCH" +echo "Building ESP-Hosted firmware $VERSION" + +cd "$SLAVE_DIR" + +OUTPUT_DIR="$AR_TOOLS/esp32-arduino-libs/hosted" +mkdir -p "$OUTPUT_DIR" + +TARGETS=( + "esp32c5" + "esp32c6" +) + +for target in "${TARGETS[@]}"; do + echo "Building for target: $target" + idf.py set-target "$target" + idf.py clean + idf.py build + cp "$SLAVE_DIR/build/network_adapter.bin" "$OUTPUT_DIR/$target-v$VERSION.bin" + echo "Build completed: $target-v$VERSION.bin" +done From 64767cc7a88f3f39829e448a7a91ea4d4165fb7c Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Tue, 4 Nov 2025 12:45:23 +0200 Subject: [PATCH 45/48] Compile support for TinyUSB Host (#314) --- components/arduino_tinyusb/CMakeLists.txt | 28 ++++++++++--- .../arduino_tinyusb/include/tusb_config.h | 42 ++++++++++++++++++- patches/dwc2_esp32_h.diff | 18 ++++++++ tools/update-components.sh | 3 ++ 4 files changed, 84 insertions(+), 7 deletions(-) create mode 100644 patches/dwc2_esp32_h.diff diff --git a/components/arduino_tinyusb/CMakeLists.txt b/components/arduino_tinyusb/CMakeLists.txt index fd6f5983d..242b0ef17 100755 --- a/components/arduino_tinyusb/CMakeLists.txt +++ b/components/arduino_tinyusb/CMakeLists.txt @@ -25,10 +25,17 @@ if(CONFIG_TINYUSB_ENABLED) set(srcs # espressif: - "${COMPONENT_DIR}/src/dcd_dwc2.c" + #"${COMPONENT_DIR}/src/dcd_dwc2.c" # tusb: - #"${COMPONENT_DIR}/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c" + "${COMPONENT_DIR}/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c" "${COMPONENT_DIR}/tinyusb/src/portable/synopsys/dwc2/dwc2_common.c" + "${COMPONENT_DIR}/tinyusb/src/portable/synopsys/dwc2/hcd_dwc2.c" + # common + "${COMPONENT_DIR}/tinyusb/src/tusb.c" + "${COMPONENT_DIR}/tinyusb/src/common/tusb_fifo.c" + # device + "${COMPONENT_DIR}/tinyusb/src/device/usbd_control.c" + "${COMPONENT_DIR}/tinyusb/src/device/usbd.c" "${COMPONENT_DIR}/tinyusb/src/class/cdc/cdc_device.c" "${COMPONENT_DIR}/tinyusb/src/class/hid/hid_device.c" "${COMPONENT_DIR}/tinyusb/src/class/midi/midi_device.c" @@ -38,16 +45,25 @@ if(CONFIG_TINYUSB_ENABLED) "${COMPONENT_DIR}/tinyusb/src/class/dfu/dfu_device.c" "${COMPONENT_DIR}/tinyusb/src/class/vendor/vendor_device.c" "${COMPONENT_DIR}/tinyusb/src/class/net/ncm_device.c" - "${COMPONENT_DIR}/tinyusb/src/common/tusb_fifo.c" - "${COMPONENT_DIR}/tinyusb/src/device/usbd_control.c" - "${COMPONENT_DIR}/tinyusb/src/device/usbd.c" - "${COMPONENT_DIR}/tinyusb/src/tusb.c") + "${COMPONENT_DIR}/tinyusb/src/class/net/ecm_rndis_device.c" + "${COMPONENT_DIR}/tinyusb/src/class/usbtmc/usbtmc_device.c" + # host + "${COMPONENT_DIR}/tinyusb/src/host/usbh.c" + "${COMPONENT_DIR}/tinyusb/src/host/hub.c" + "${COMPONENT_DIR}/tinyusb/src/class/cdc/cdc_host.c" + "${COMPONENT_DIR}/tinyusb/src/class/hid/hid_host.c" + "${COMPONENT_DIR}/tinyusb/src/class/midi/midi_host.c" + "${COMPONENT_DIR}/tinyusb/src/class/msc/msc_host.c" + "${COMPONENT_DIR}/tinyusb/src/class/vendor/vendor_host.c" + ) set(includes_private # tusb: + #"${COMPONENT_DIR}/tinyusb/lib/networking/" "${COMPONENT_DIR}/tinyusb/hw/bsp/" "${COMPONENT_DIR}/tinyusb/src/" "${COMPONENT_DIR}/tinyusb/src/device" + "${COMPONENT_DIR}/tinyusb/src/host" "${COMPONENT_DIR}/tinyusb/src/portable/synopsys/dwc2" ) diff --git a/components/arduino_tinyusb/include/tusb_config.h b/components/arduino_tinyusb/include/tusb_config.h index 7802bea8f..c64768391 100755 --- a/components/arduino_tinyusb/include/tusb_config.h +++ b/components/arduino_tinyusb/include/tusb_config.h @@ -76,6 +76,10 @@ extern "C" { # define CONFIG_TINYUSB_NCM_ENABLED 0 #endif +#if CONFIG_TINYUSB_ENABLED +# define CFG_TUD_ENABLED 1 +#endif + /* */ /* COMMON CONFIGURATION */ /* */ @@ -84,6 +88,7 @@ extern "C" { #endif #define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE #define CFG_TUSB_OS OPT_OS_FREERTOS +#define BOARD_TUD_RHPORT 0 /* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment. * Tinyusb use follows macros to declare transferring memory so that they can be put @@ -97,8 +102,12 @@ extern "C" { #endif #ifndef CFG_TUSB_MEM_ALIGN +#if CONFIG_IDF_TARGET_ESP32P4 +# define CFG_TUSB_MEM_ALIGN TU_ATTR_ALIGNED(64) +#else # define CFG_TUSB_MEM_ALIGN TU_ATTR_ALIGNED(4) #endif +#endif #if CONFIG_IDF_TARGET_ESP32P4 #define CFG_TUD_MAX_SPEED OPT_MODE_HIGH_SPEED @@ -106,8 +115,10 @@ extern "C" { #define CFG_TUD_MAX_SPEED OPT_MODE_FULL_SPEED #endif +#define BOARD_TUD_MAX_SPEED CFG_TUD_MAX_SPEED + /* */ -/* DRIVER CONFIGURATION */ +/* DEVICE CONFIGURATION */ /* */ #define CFG_TUD_MAINTASK_SIZE 4096 @@ -155,6 +166,35 @@ extern "C" { #define CFG_TUD_VENDOR_RX_BUFSIZE CONFIG_TINYUSB_VENDOR_RX_BUFSIZE #define CFG_TUD_VENDOR_TX_BUFSIZE CONFIG_TINYUSB_VENDOR_TX_BUFSIZE +/* */ +/* HOST CONFIGURATION */ +/* */ + +#define CFG_TUH_ENABLED CFG_TUD_ENABLED +#define CFG_TUSB_RHPORT1_MODE OPT_MODE_HOST +#define BOARD_TUH_RHPORT 1 +#define BOARD_TUH_MAX_SPEED CFG_TUD_MAX_SPEED +#define CFG_TUH_ENUMERATION_BUFSIZE 256 + +#define CFG_TUH_HUB 2 // number of supported hubs +#define CFG_TUH_CDC 1 // CDC ACM +#define CFG_TUH_CDC_FTDI 1 // FTDI Serial. FTDI is not part of CDC class, only to re-use CDC driver API +#define CFG_TUH_CDC_CP210X 1 // CP210x Serial. CP210X is not part of CDC class, only to re-use CDC driver API +#define CFG_TUH_CDC_CH34X 1 // CH340 or CH341 Serial. CH34X is not part of CDC class, only to re-use CDC driver API +#define CFG_TUH_HID 1 // typical keyboard + mouse device can have 3-4 HID interfaces +#define CFG_TUH_MSC 1 +//#define CFG_TUH_VENDOR 3 + +#define CFG_TUH_DEVICE_MAX (3*CFG_TUH_HUB + 1) + +//------------- HID -------------// +#define CFG_TUH_HID_EPIN_BUFSIZE 64 +#define CFG_TUH_HID_EPOUT_BUFSIZE 64 + +//------------- CDC -------------// +#define CFG_TUH_CDC_LINE_CONTROL_ON_ENUM 0x03 +#define CFG_TUH_CDC_LINE_CODING_ON_ENUM { 115200, CDC_LINE_CODING_STOP_BITS_1, CDC_LINE_CODING_PARITY_NONE, 8 } + #ifdef __cplusplus } #endif diff --git a/patches/dwc2_esp32_h.diff b/patches/dwc2_esp32_h.diff new file mode 100644 index 000000000..94cb86f32 --- /dev/null +++ b/patches/dwc2_esp32_h.diff @@ -0,0 +1,18 @@ +diff --git a/src/portable/synopsys/dwc2/dwc2_esp32.h b/src/portable/synopsys/dwc2/dwc2_esp32.h +index 49b8c54cb..8b5e99741 100644 +--- a/src/portable/synopsys/dwc2/dwc2_esp32.h ++++ b/src/portable/synopsys/dwc2/dwc2_esp32.h +@@ -70,11 +70,13 @@ static void dwc2_int_handler_wrap(void* arg) { + const tusb_role_t role = (tusb_role_t) tu_u16_high((uint16_t)(uintptr_t)arg); + #if CFG_TUD_ENABLED + if (role == TUSB_ROLE_DEVICE) { ++ void dcd_int_handler(uint8_t rhport); + dcd_int_handler(rhport); + } + #endif + #if CFG_TUH_ENABLED && !CFG_TUH_MAX3421 + if (role == TUSB_ROLE_HOST) { ++ void hcd_int_handler(uint8_t rhport, bool in_isr); + hcd_int_handler(rhport, true); + } + #endif diff --git a/tools/update-components.sh b/tools/update-components.sh index 298783c74..18e7b689e 100755 --- a/tools/update-components.sh +++ b/tools/update-components.sh @@ -14,4 +14,7 @@ else git -C "$TINYUSB_REPO_DIR" fetch && \ git -C "$TINYUSB_REPO_DIR" pull --ff-only fi +cd $TINYUSB_REPO_DIR +patch -p1 -N -i $AR_PATCHES/dwc2_esp32_h.diff +cd - if [ $? -ne 0 ]; then exit 1; fi From 6b0a0e6727c4f767f6ddb86f03ff94ecd6d8f1e5 Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Fri, 7 Nov 2025 00:14:27 +0200 Subject: [PATCH 46/48] Clean TinyUSB component (#327) --- components/arduino_tinyusb/CMakeLists.txt | 2 - .../arduino_tinyusb/patches/dcd_dwc2.patch | 84 -- components/arduino_tinyusb/src/dcd_dwc2.c | 1141 ----------------- patches/dwc2_esp32_h.diff | 18 - tools/patch-tinyusb.sh | 4 - tools/update-components.sh | 3 - 6 files changed, 1252 deletions(-) delete mode 100644 components/arduino_tinyusb/patches/dcd_dwc2.patch delete mode 100644 components/arduino_tinyusb/src/dcd_dwc2.c delete mode 100644 patches/dwc2_esp32_h.diff delete mode 100755 tools/patch-tinyusb.sh diff --git a/components/arduino_tinyusb/CMakeLists.txt b/components/arduino_tinyusb/CMakeLists.txt index 242b0ef17..0d1fe9fb7 100755 --- a/components/arduino_tinyusb/CMakeLists.txt +++ b/components/arduino_tinyusb/CMakeLists.txt @@ -24,8 +24,6 @@ if(CONFIG_TINYUSB_ENABLED) endif() set(srcs - # espressif: - #"${COMPONENT_DIR}/src/dcd_dwc2.c" # tusb: "${COMPONENT_DIR}/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c" "${COMPONENT_DIR}/tinyusb/src/portable/synopsys/dwc2/dwc2_common.c" diff --git a/components/arduino_tinyusb/patches/dcd_dwc2.patch b/components/arduino_tinyusb/patches/dcd_dwc2.patch deleted file mode 100644 index 2521a38e5..000000000 --- a/components/arduino_tinyusb/patches/dcd_dwc2.patch +++ /dev/null @@ -1,84 +0,0 @@ ---- a/components/arduino_tinyusb/src/dcd_dwc2.c 2024-10-02 12:17:40.000000000 +0300 -+++ b/components/arduino_tinyusb/src/dcd_dwc2.c 2024-10-02 12:19:48.000000000 +0300 -@@ -243,6 +243,17 @@ - //-------------------------------------------------------------------- - // Endpoint - //-------------------------------------------------------------------- -+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) -+// Keep count of how many FIFOs are in use -+static uint8_t _allocated_fifos = 1; //FIFO0 is always in use -+ -+// Will either return an unused FIFO number, or 0 if all are used. -+static uint8_t get_free_fifo(void) { -+ if (_allocated_fifos < 5) return _allocated_fifos++; -+ return 0; -+} -+#endif -+ - static void edpt_activate(uint8_t rhport, const tusb_desc_endpoint_t* p_endpoint_desc) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - const uint8_t epnum = tu_edpt_number(p_endpoint_desc->bEndpointAddress); -@@ -266,7 +277,18 @@ - depctl.set_data0_iso_even = 1; - } - if (dir == TUSB_DIR_IN) { -- depctl.tx_fifo_num = epnum; -+ //depctl.tx_fifo_num = epnum; -+ uint8_t fifo_num = epnum; -+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) -+ // Special Case for EP5, which is used by CDC but not actually called by the driver -+ // we can give it a fake FIFO -+ if (epnum == 5) { -+ fifo_num = epnum; -+ } else { -+ fifo_num = get_free_fifo(); -+ } -+#endif -+ depctl.tx_fifo_num = fifo_num; - } - - dwc2_dep_t* dep = &dwc2->ep[dir == TUSB_DIR_IN ? 0 : 1][epnum]; -@@ -557,6 +579,10 @@ - } - } - -+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) -+ _allocated_fifos = 1; -+#endif -+ - dfifo_flush_tx(dwc2, 0x10); // all tx fifo - dfifo_flush_rx(dwc2); - -@@ -997,6 +1023,9 @@ - if (gintsts & GINTSTS_USBRST) { - // USBRST is start of reset. - dwc2->gintsts = GINTSTS_USBRST; -+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) -+ _allocated_fifos = 1; -+#endif - - usbd_spin_lock(true); - handle_bus_reset(rhport); -@@ -1008,7 +1037,11 @@ - - if (gintsts & GINTSTS_USBSUSP) { - dwc2->gintsts = GINTSTS_USBSUSP; -- dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true); -+ //dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true); -+ dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true); -+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) -+ _allocated_fifos = 1; -+#endif - } - - if (gintsts & GINTSTS_WKUINT) { -@@ -1025,6 +1058,9 @@ - - if (otg_int & GOTGINT_SEDET) { - dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true); -+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) -+ _allocated_fifos = 1; -+#endif - } - - dwc2->gotgint = otg_int; diff --git a/components/arduino_tinyusb/src/dcd_dwc2.c b/components/arduino_tinyusb/src/dcd_dwc2.c deleted file mode 100644 index b6c3b1b22..000000000 --- a/components/arduino_tinyusb/src/dcd_dwc2.c +++ /dev/null @@ -1,1141 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2019 William D. Jones - * Copyright (c) 2019 Ha Thach (tinyusb.org) - * Copyright (c) 2020 Jan Duempelmann - * Copyright (c) 2020 Reinhard Panhuber - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * This file is part of the TinyUSB stack. - */ - -#include "tusb_option.h" - -#if CFG_TUD_ENABLED && defined(TUP_USBIP_DWC2) - -#if !(CFG_TUD_DWC2_SLAVE_ENABLE || CFG_TUD_DWC2_DMA_ENABLE) -#error DWC2 require either CFG_TUD_DWC2_SLAVE_ENABLE or CFG_TUD_DWC2_DMA_ENABLE to be enabled -#endif - -// Debug level for DWC2 -#define DWC2_DEBUG 2 - -#include "device/dcd.h" -#include "device/usbd_pvt.h" -#include "dwc2_common.h" - -//--------------------------------------------------------------------+ -// MACRO TYPEDEF CONSTANT ENUM -//--------------------------------------------------------------------+ -typedef struct { - uint8_t* buffer; - tu_fifo_t* ff; - uint16_t total_len; - uint16_t max_size; - uint8_t interval; -} xfer_ctl_t; - -// This variable is modified from ISR context, so it must be protected by critical section -static xfer_ctl_t xfer_status[DWC2_EP_MAX][2]; -#define XFER_CTL_BASE(_ep, _dir) (&xfer_status[_ep][_dir]) - -typedef struct { - // EP0 transfers are limited to 1 packet - larger sizes has to be split - uint16_t ep0_pending[2]; // Index determines direction as tusb_dir_t type - uint16_t dfifo_top; // top free location in DFIFO in words - - // Number of IN endpoints active - uint8_t allocated_epin_count; - - // SOF enabling flag - required for SOF to not get disabled in ISR when SOF was enabled by - bool sof_en; -} dcd_data_t; - -static dcd_data_t _dcd_data; - -CFG_TUD_MEM_SECTION static struct { - TUD_EPBUF_DEF(setup_packet, 8); -} _dcd_usbbuf; - -TU_ATTR_ALWAYS_INLINE static inline uint8_t dwc2_ep_count(const dwc2_regs_t* dwc2) { - #if TU_CHECK_MCU(OPT_MCU_GD32VF103) - return DWC2_EP_MAX; - #else - const dwc2_ghwcfg2_t ghwcfg2 = {.value = dwc2->ghwcfg2}; - return ghwcfg2.num_dev_ep + 1; - #endif -} - - -//-------------------------------------------------------------------- -// DMA -//-------------------------------------------------------------------- -#if CFG_TUD_MEM_DCACHE_ENABLE -bool dcd_dcache_clean(const void* addr, uint32_t data_size) { - TU_VERIFY(addr && data_size); - return dwc2_dcache_clean(addr, data_size); -} - -bool dcd_dcache_invalidate(const void* addr, uint32_t data_size) { - TU_VERIFY(addr && data_size); - return dwc2_dcache_invalidate(addr, data_size); -} - -bool dcd_dcache_clean_invalidate(const void* addr, uint32_t data_size) { - TU_VERIFY(addr && data_size); - return dwc2_dcache_clean_invalidate(addr, data_size); -} -#endif - -TU_ATTR_ALWAYS_INLINE static inline bool dma_device_enabled(const dwc2_regs_t* dwc2) { - (void) dwc2; - // Internal DMA only - const dwc2_ghwcfg2_t ghwcfg2 = {.value = dwc2->ghwcfg2}; - return CFG_TUD_DWC2_DMA_ENABLE && ghwcfg2.arch == GHWCFG2_ARCH_INTERNAL_DMA; -} - -static void dma_setup_prepare(uint8_t rhport) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - - if (dwc2->gsnpsid >= DWC2_CORE_REV_3_00a) { - if(dwc2->epout[0].doepctl & DOEPCTL_EPENA) { - return; - } - } - - // Receive only 1 packet - dwc2->epout[0].doeptsiz = (1 << DOEPTSIZ_STUPCNT_Pos) | (1 << DOEPTSIZ_PKTCNT_Pos) | (8 << DOEPTSIZ_XFRSIZ_Pos); - dwc2->epout[0].doepdma = (uintptr_t) _dcd_usbbuf.setup_packet; - dwc2->epout[0].doepctl |= DOEPCTL_EPENA | DOEPCTL_USBAEP; -} - -//--------------------------------------------------------------------+ -// Data FIFO -//--------------------------------------------------------------------+ - - -/* Device Data FIFO scheme - - The FIFO is split up into - - EPInfo: for storing DMA metadata, only required when use DMA. Maximum size is called - EP_LOC_CNT = ep_fifo_size - ghwcfg3.dfifo_depth. For value less than EP_LOC_CNT, gdfifocfg must be configured before - gahbcfg.dmaen is set - - Buffer mode: 1 word per endpoint direction - - Scatter/Gather DMA: 4 words per endpoint direction - - TX FIFO: one fifo for each IN endpoint. Size is dynamic depending on packet size, starting from top with EP0 IN. - - Shared RX FIFO: a shared fifo for all OUT endpoints. Typically, can hold up to 2 packets of the largest EP size. - - We allocated TX FIFO from top to bottom (using top pointer), this to allow the RX FIFO to grow dynamically which is - possible since the free space is located between the RX and TX FIFOs. - - ---------------- ep_fifo_size - | DxEPIDMAn | - |-------------|-- gdfifocfg.EPINFOBASE (max is ghwcfg3.dfifo_depth) - | IN FIFO 0 | control EP - |-------------| - | IN FIFO 1 | - |-------------| - | . . . . | - |-------------| - | IN FIFO n | - |-------------| - | FREE | - |-------------|-- GRXFSIZ (expandable) - | OUT FIFO | - | ( Shared ) | - --------------- 0 - - According to "FIFO RAM allocation" section in RM, FIFO RAM are allocated as follows (each word 32-bits): - - Each EP IN needs at least max packet size - - All EP OUT shared a unique OUT FIFO which uses (for Slave or Buffer DMA, Scatt/Gather DMA use different formula): - - 13 for setup packets + control words (up to 3 setup packets). - - 1 for global NAK (not required/used here). - - Largest-EPsize/4 + 1. ( FS: 64 bytes, HS: 512 bytes). Recommended is "2 x (Largest-EPsize/4 + 1)" - - 2 for each used OUT endpoint - - Therefore GRXFSIZ = 13 + 1 + 2 x (Largest-EPsize/4 + 1) + 2 x EPOUTnum -*/ - -TU_ATTR_ALWAYS_INLINE static inline uint16_t calc_device_grxfsiz(uint16_t largest_ep_size, uint8_t ep_count) { - return 13 + 1 + 2 * ((largest_ep_size / 4) + 1) + 2 * ep_count; -} - -static bool dfifo_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t packet_size) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - const dwc2_controller_t* dwc2_controller = &_dwc2_controller[rhport]; - const uint8_t ep_count = dwc2_controller->ep_count; - const uint8_t epnum = tu_edpt_number(ep_addr); - const uint8_t dir = tu_edpt_dir(ep_addr); - - TU_ASSERT(epnum < ep_count); - - uint16_t fifo_size = tu_div_ceil(packet_size, 4); - if (dir == TUSB_DIR_OUT) { - // Calculate required size of RX FIFO - const uint16_t new_sz = calc_device_grxfsiz(4 * fifo_size, ep_count); - - // If size_rx needs to be extended check if there is enough free space - if (dwc2->grxfsiz < new_sz) { - TU_ASSERT(new_sz <= _dcd_data.dfifo_top); - dwc2->grxfsiz = new_sz; // Enlarge RX FIFO - } - } else { - // Check IN endpoints concurrently active limit - if(dwc2_controller->ep_in_count) { - TU_ASSERT(_dcd_data.allocated_epin_count < dwc2_controller->ep_in_count); - _dcd_data.allocated_epin_count++; - } - - // If The TXFELVL is configured as half empty, the fifo must be twice the max_size. - if ((dwc2->gahbcfg & GAHBCFG_TX_FIFO_EPMTY_LVL) == 0) { - fifo_size *= 2; - } - - // Check if free space is available - TU_ASSERT(_dcd_data.dfifo_top >= fifo_size + dwc2->grxfsiz); - _dcd_data.dfifo_top -= fifo_size; - // TU_LOG(DWC2_DEBUG, " TX FIFO %u: allocated %u words at offset %u\r\n", epnum, fifo_size, dfifo_top); - - // Both TXFD and TXSA are in unit of 32-bit words. - if (epnum == 0) { - dwc2->dieptxf0 = (fifo_size << DIEPTXF0_TX0FD_Pos) | _dcd_data.dfifo_top; - } else { - // DIEPTXF starts at FIFO #1. - dwc2->dieptxf[epnum - 1] = (fifo_size << DIEPTXF_INEPTXFD_Pos) | _dcd_data.dfifo_top; - } - } - - return true; -} - -static void dfifo_device_init(uint8_t rhport) { - const dwc2_controller_t* dwc2_controller = &_dwc2_controller[rhport]; - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - dwc2->grxfsiz = calc_device_grxfsiz(CFG_TUD_ENDPOINT0_SIZE, dwc2_controller->ep_count); - - // Scatter/Gather DMA mode is not yet supported. Buffer DMA only need 1 words per endpoint direction - const bool is_dma = dma_device_enabled(dwc2); - _dcd_data.dfifo_top = dwc2_controller->ep_fifo_size/4; - if (is_dma) { - _dcd_data.dfifo_top -= 2 * dwc2_controller->ep_count; - } - dwc2->gdfifocfg = (_dcd_data.dfifo_top << GDFIFOCFG_EPINFOBASE_SHIFT) | _dcd_data.dfifo_top; - - // Allocate FIFO for EP0 IN - dfifo_alloc(rhport, 0x80, CFG_TUD_ENDPOINT0_SIZE); -} - - -//-------------------------------------------------------------------- -// Endpoint -//-------------------------------------------------------------------- -#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) -// Keep count of how many FIFOs are in use -static uint8_t _allocated_fifos = 1; //FIFO0 is always in use - -// Will either return an unused FIFO number, or 0 if all are used. -static uint8_t get_free_fifo(void) { - if (_allocated_fifos < 5) return _allocated_fifos++; - return 0; -} -#endif - -static void edpt_activate(uint8_t rhport, const tusb_desc_endpoint_t* p_endpoint_desc) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - const uint8_t epnum = tu_edpt_number(p_endpoint_desc->bEndpointAddress); - const uint8_t dir = tu_edpt_dir(p_endpoint_desc->bEndpointAddress); - - xfer_ctl_t* xfer = XFER_CTL_BASE(epnum, dir); - xfer->max_size = tu_edpt_packet_size(p_endpoint_desc); - xfer->interval = p_endpoint_desc->bInterval; - - // Endpoint control - dwc2_depctl_t depctl = {.value = 0}; - depctl.mps = xfer->max_size; - depctl.active = 1; - depctl.type = p_endpoint_desc->bmAttributes.xfer; - if (p_endpoint_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS) { - depctl.set_data0_iso_even = 1; - } - if (dir == TUSB_DIR_IN) { - //depctl.tx_fifo_num = epnum; - uint8_t fifo_num = epnum; -#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) - // Special Case for EP5, which is used by CDC but not actually called by the driver - // we can give it a fake FIFO - if (epnum == 5) { - fifo_num = epnum; - } else { - fifo_num = get_free_fifo(); - } -#endif - depctl.tx_fifo_num = fifo_num; - } - - dwc2_dep_t* dep = &dwc2->ep[dir == TUSB_DIR_IN ? 0 : 1][epnum]; - dep->ctl = depctl.value; - dwc2->daintmsk |= TU_BIT(epnum + DAINT_SHIFT(dir)); -} - -static void edpt_disable(uint8_t rhport, uint8_t ep_addr, bool stall) { - (void) rhport; - - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - const uint8_t epnum = tu_edpt_number(ep_addr); - const uint8_t dir = tu_edpt_dir(ep_addr); - dwc2_dep_t* dep = &dwc2->ep[dir == TUSB_DIR_IN ? 0 : 1][epnum]; - - if (dir == TUSB_DIR_IN) { - // Only disable currently enabled non-control endpoint - if ((epnum == 0) || !(dep->diepctl & DIEPCTL_EPENA)) { - dep->diepctl |= DIEPCTL_SNAK | (stall ? DIEPCTL_STALL : 0); - } else { - // Stop transmitting packets and NAK IN xfers. - dep->diepctl |= DIEPCTL_SNAK; - while ((dep->diepint & DIEPINT_INEPNE) == 0) {} - - // Disable the endpoint. - dep->diepctl |= DIEPCTL_EPDIS | (stall ? DIEPCTL_STALL : 0); - while ((dep->diepint & DIEPINT_EPDISD_Msk) == 0) {} - - dep->diepint = DIEPINT_EPDISD; - } - - // Flush the FIFO, and wait until we have confirmed it cleared. - dfifo_flush_tx(dwc2, epnum); - } else { - // Only disable currently enabled non-control endpoint - if ((epnum == 0) || !(dep->doepctl & DOEPCTL_EPENA)) { - dep->doepctl |= stall ? DOEPCTL_STALL : 0; - } else { - // Asserting GONAK is required to STALL an OUT endpoint. - // Simpler to use polling here, we don't use the "B"OUTNAKEFF interrupt - // anyway, and it can't be cleared by user code. If this while loop never - // finishes, we have bigger problems than just the stack. - dwc2->dctl |= DCTL_SGONAK; - while ((dwc2->gintsts & GINTSTS_BOUTNAKEFF_Msk) == 0) {} - - // Ditto here disable the endpoint. - dep->doepctl |= DOEPCTL_EPDIS | (stall ? DOEPCTL_STALL : 0); - while ((dep->doepint & DOEPINT_EPDISD_Msk) == 0) {} - - dep->doepint = DOEPINT_EPDISD; - - // Allow other OUT endpoints to keep receiving. - dwc2->dctl |= DCTL_CGONAK; - } - } -} - -// Since this function returns void, it is not possible to return a boolean success message -// We must make sure that this function is not called when the EP is disabled -// Must be called from critical section -static void edpt_schedule_packets(uint8_t rhport, const uint8_t epnum, const uint8_t dir) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - xfer_ctl_t* const xfer = XFER_CTL_BASE(epnum, dir); - dwc2_dep_t* dep = &dwc2->ep[dir == TUSB_DIR_IN ? 0 : 1][epnum]; - - uint16_t num_packets; - uint16_t total_bytes; - - // EP0 is limited to one packet per xfer - if (epnum == 0) { - total_bytes = tu_min16(_dcd_data.ep0_pending[dir], xfer->max_size); - _dcd_data.ep0_pending[dir] -= total_bytes; - num_packets = 1; - } else { - total_bytes = xfer->total_len; - num_packets = tu_div_ceil(total_bytes, xfer->max_size); - if (num_packets == 0) { - num_packets = 1; // zero length packet still count as 1 - } - } - - // transfer size: A full OUT transfer (multiple packets, possibly) triggers XFRC. - dwc2_ep_tsize_t deptsiz = {.value = 0}; - deptsiz.xfer_size = total_bytes; - deptsiz.packet_count = num_packets; - dep->tsiz = deptsiz.value; - - // control - dwc2_depctl_t depctl = {.value = dep->ctl}; - depctl.clear_nak = 1; - depctl.enable = 1; - if (depctl.type == DEPCTL_EPTYPE_ISOCHRONOUS && xfer->interval == 1) { - const dwc2_dsts_t dsts = {.value = dwc2->dsts}; - const uint32_t odd_now = dsts.frame_number & 1u; - if (odd_now) { - depctl.set_data0_iso_even = 1; - } else { - depctl.set_data1_iso_odd = 1; - } - } - - const bool is_dma = dma_device_enabled(dwc2); - if(is_dma) { - if (dir == TUSB_DIR_IN && total_bytes != 0) { - dcd_dcache_clean(xfer->buffer, total_bytes); - } - dep->diepdma = (uintptr_t) xfer->buffer; - dep->diepctl = depctl.value; // enable endpoint - } else { - dep->diepctl = depctl.value; // enable endpoint - - // Enable tx fifo empty interrupt only if there is data. Note must after depctl enable - if (dir == TUSB_DIR_IN && total_bytes != 0) { - dwc2->diepempmsk |= (1 << epnum); - } - } -} - -//-------------------------------------------------------------------- -// Controller API -//-------------------------------------------------------------------- -bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { - (void) rh_init; - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - - tu_memclr(&_dcd_data, sizeof(_dcd_data)); - - // Core Initialization - const bool is_highspeed = dwc2_core_is_highspeed(dwc2, TUSB_ROLE_DEVICE); - const bool is_dma = dma_device_enabled(dwc2); - TU_ASSERT(dwc2_core_init(rhport, is_highspeed, is_dma)); - - //------------- 7.1 Device Initialization -------------// - // Set device max speed - uint32_t dcfg = dwc2->dcfg & ~DCFG_DSPD_Msk; - if (is_highspeed) { - dcfg |= DCFG_DSPD_HS << DCFG_DSPD_Pos; - - // XCVRDLY: transceiver delay between xcvr_sel and txvalid during device chirp is required - // when using with some PHYs such as USB334x (USB3341, USB3343, USB3346, USB3347) - const dwc2_ghwcfg2_t ghwcfg2 = {.value = dwc2->ghwcfg2}; - if (ghwcfg2.hs_phy_type == GHWCFG2_HSPHY_ULPI) { - dcfg |= DCFG_XCVRDLY; - } - } else { - dcfg |= DCFG_DSPD_FS << DCFG_DSPD_Pos; - } - - dcfg |= DCFG_NZLSOHSK; // send STALL back and discard if host send non-zlp during control status - dwc2->dcfg = dcfg; - - dcd_disconnect(rhport); - - // Force device mode - dwc2->gusbcfg = (dwc2->gusbcfg & ~GUSBCFG_FHMOD) | GUSBCFG_FDMOD; - - // Clear A override, force B Valid - dwc2->gotgctl = (dwc2->gotgctl & ~GOTGCTL_AVALOEN) | GOTGCTL_BVALOEN | GOTGCTL_BVALOVAL; - - // Enable required interrupts - dwc2->gintmsk |= GINTMSK_OTGINT | GINTMSK_USBSUSPM | GINTMSK_USBRST | GINTMSK_ENUMDNEM | GINTMSK_WUIM; - - // TX FIFO empty level for interrupt is complete empty - uint32_t gahbcfg = dwc2->gahbcfg; - gahbcfg |= GAHBCFG_TX_FIFO_EPMTY_LVL; - gahbcfg |= GAHBCFG_GINT; // Enable global interrupt - dwc2->gahbcfg = gahbcfg; - - dcd_connect(rhport); - return true; -} - -void dcd_int_enable(uint8_t rhport) { - dwc2_dcd_int_enable(rhport); -} - -void dcd_int_disable(uint8_t rhport) { - dwc2_dcd_int_disable(rhport); -} - -void dcd_set_address(uint8_t rhport, uint8_t dev_addr) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - dwc2->dcfg = (dwc2->dcfg & ~DCFG_DAD_Msk) | (dev_addr << DCFG_DAD_Pos); - - // Response with status after changing device address - dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0); -} - -void dcd_remote_wakeup(uint8_t rhport) { - (void) rhport; - - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - - // set remote wakeup - dwc2->dctl |= DCTL_RWUSIG; - - // enable SOF to detect bus resume - dwc2->gintsts = GINTSTS_SOF; - dwc2->gintmsk |= GINTMSK_SOFM; - - // Per specs: remote wakeup signal bit must be clear within 1-15ms - dwc2_remote_wakeup_delay(); - - dwc2->dctl &= ~DCTL_RWUSIG; -} - -void dcd_connect(uint8_t rhport) { - (void) rhport; - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - -#ifdef TUP_USBIP_DWC2_ESP32 - usb_wrap_otg_conf_reg_t conf = USB_WRAP.otg_conf; - conf.pad_pull_override = 0; - conf.dp_pullup = 0; - conf.dp_pulldown = 0; - conf.dm_pullup = 0; - conf.dm_pulldown = 0; - USB_WRAP.otg_conf = conf; -#endif - - dwc2->dctl &= ~DCTL_SDIS; -} - -void dcd_disconnect(uint8_t rhport) { - (void) rhport; - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - -#ifdef TUP_USBIP_DWC2_ESP32 - usb_wrap_otg_conf_reg_t conf = USB_WRAP.otg_conf; - conf.pad_pull_override = 1; - conf.dp_pullup = 0; - conf.dp_pulldown = 1; - conf.dm_pullup = 0; - conf.dm_pulldown = 1; - USB_WRAP.otg_conf = conf; -#endif - - dwc2->dctl |= DCTL_SDIS; -} - -// Be advised: audio, video and possibly other iso-ep classes use dcd_sof_enable() to enable/disable its corresponding ISR on purpose! -void dcd_sof_enable(uint8_t rhport, bool en) { - (void) rhport; - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - - _dcd_data.sof_en = en; - - if (en) { - dwc2->gintsts = GINTSTS_SOF; - dwc2->gintmsk |= GINTMSK_SOFM; - } else { - dwc2->gintmsk &= ~GINTMSK_SOFM; - } -} - -/*------------------------------------------------------------------*/ -/* DCD Endpoint port - *------------------------------------------------------------------*/ - -bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const* desc_edpt) { - TU_ASSERT(dfifo_alloc(rhport, desc_edpt->bEndpointAddress, tu_edpt_packet_size(desc_edpt))); - edpt_activate(rhport, desc_edpt); - return true; -} - -// Close all non-control endpoints, cancel all pending transfers if any. -void dcd_edpt_close_all(uint8_t rhport) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - uint8_t const ep_count = _dwc2_controller[rhport].ep_count; - - usbd_spin_lock(false); - - _dcd_data.allocated_epin_count = 0; - - // Disable non-control interrupt - dwc2->daintmsk = (1 << DAINTMSK_OEPM_Pos) | (1 << DAINTMSK_IEPM_Pos); - - for (uint8_t n = 1; n < ep_count; n++) { - for (uint8_t d = 0; d < 2; d++) { - dwc2_dep_t* dep = &dwc2->ep[d][n]; - if (dep->ctl & EPCTL_EPENA) { - dep->ctl |= EPCTL_SNAK | EPCTL_EPDIS; - } - xfer_status[n][1-d].max_size = 0; - } - } - -#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) - _allocated_fifos = 1; -#endif - - dfifo_flush_tx(dwc2, 0x10); // all tx fifo - dfifo_flush_rx(dwc2); - dfifo_device_init(rhport); // re-init dfifo - - usbd_spin_unlock(false); -} - -bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) { - TU_ASSERT(dfifo_alloc(rhport, ep_addr, largest_packet_size)); - return true; -} - -bool dcd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc) { - // Disable EP to clear potential incomplete transfers - edpt_disable(rhport, p_endpoint_desc->bEndpointAddress, false); - edpt_activate(rhport, p_endpoint_desc); - return true; -} - -bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t total_bytes) { - uint8_t const epnum = tu_edpt_number(ep_addr); - uint8_t const dir = tu_edpt_dir(ep_addr); - xfer_ctl_t* xfer = XFER_CTL_BASE(epnum, dir); - bool ret; - - usbd_spin_lock(false); - - if (xfer->max_size == 0) { - ret = false; // Endpoint is closed - } else { - xfer->buffer = buffer; - xfer->ff = NULL; - xfer->total_len = total_bytes; - - // EP0 can only handle one packet - if (epnum == 0) { - _dcd_data.ep0_pending[dir] = total_bytes; - } - - // Schedule packets to be sent within interrupt - edpt_schedule_packets(rhport, epnum, dir); - ret = true; - } - - usbd_spin_unlock(false); - - return ret; -} - -// The number of bytes has to be given explicitly to allow more flexible control of how many -// bytes should be written and second to keep the return value free to give back a boolean -// success message. If total_bytes is too big, the FIFO will copy only what is available -// into the USB buffer! -bool dcd_edpt_xfer_fifo(uint8_t rhport, uint8_t ep_addr, tu_fifo_t* ff, uint16_t total_bytes) { - // USB buffers always work in bytes so to avoid unnecessary divisions we demand item_size = 1 - TU_ASSERT(ff->item_size == 1); - - uint8_t const epnum = tu_edpt_number(ep_addr); - uint8_t const dir = tu_edpt_dir(ep_addr); - xfer_ctl_t* xfer = XFER_CTL_BASE(epnum, dir); - bool ret; - - usbd_spin_lock(false); - - if (xfer->max_size == 0) { - ret = false; // Endpoint is closed - } else { - xfer->buffer = NULL; - xfer->ff = ff; - xfer->total_len = total_bytes; - - // Schedule packets to be sent within interrupt - // TODO xfer fifo may only available for slave mode - edpt_schedule_packets(rhport, epnum, dir); - ret = true; - } - - usbd_spin_unlock(false); - - return ret; -} - -void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - edpt_disable(rhport, ep_addr, true); - if((tu_edpt_number(ep_addr) == 0) && dma_device_enabled(dwc2)) { - dma_setup_prepare(rhport); - } -} - -void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - uint8_t const epnum = tu_edpt_number(ep_addr); - uint8_t const dir = tu_edpt_dir(ep_addr); - dwc2_dep_t* dep = &dwc2->ep[dir == TUSB_DIR_IN ? 0 : 1][epnum]; - - // Clear stall and reset data toggle - dep->ctl &= ~EPCTL_STALL;; - dep->ctl |= EPCTL_SD0PID_SEVNFRM; -} - -//-------------------------------------------------------------------- -// Interrupt Handler -//-------------------------------------------------------------------- - -// 7.4.1 Initialization on USB Reset -// Must be called from critical section -static void handle_bus_reset(uint8_t rhport) { - dwc2_regs_t *dwc2 = DWC2_REG(rhport); - const uint8_t ep_count = dwc2_ep_count(dwc2); - - tu_memclr(xfer_status, sizeof(xfer_status)); - - _dcd_data.sof_en = false; - _dcd_data.allocated_epin_count = 0; - - // 1. NAK for all OUT endpoints - for (uint8_t n = 0; n < ep_count; n++) { - dwc2->epout[n].doepctl |= DOEPCTL_SNAK; - } - - // Disable all IN endpoints - for (uint8_t n = 0; n < ep_count; n++) { - if (dwc2->epin[n].diepctl & DIEPCTL_EPENA) { - dwc2->epin[n].diepctl |= DIEPCTL_SNAK | DIEPCTL_EPDIS; - } - } - - // 2. Set up interrupt mask for EP0 - dwc2->daintmsk = TU_BIT(DAINTMSK_OEPM_Pos) | TU_BIT(DAINTMSK_IEPM_Pos); - dwc2->doepmsk = DOEPMSK_STUPM | DOEPMSK_XFRCM; - dwc2->diepmsk = DIEPMSK_TOM | DIEPMSK_XFRCM; - - // 4. Set up DFIFO - dfifo_flush_tx(dwc2, 0x10); // all tx fifo - dfifo_flush_rx(dwc2); - dfifo_device_init(rhport); - - // 5. Reset device address - dwc2_dcfg_t dcfg = {.value = dwc2->dcfg}; - dcfg.address = 0; - dwc2->dcfg = dcfg.value; - - // Fixed both control EP0 size to 64 bytes - dwc2->epin[0].ctl &= ~(0x03 << DIEPCTL_MPSIZ_Pos); - dwc2->epout[0].ctl &= ~(0x03 << DOEPCTL_MPSIZ_Pos); - - xfer_status[0][TUSB_DIR_OUT].max_size = 64; - xfer_status[0][TUSB_DIR_IN].max_size = 64; - - if(dma_device_enabled(dwc2)) { - dma_setup_prepare(rhport); - } else { - dwc2->epout[0].doeptsiz |= (3 << DOEPTSIZ_STUPCNT_Pos); - } - - dwc2->gintmsk |= GINTMSK_OEPINT | GINTMSK_IEPINT; -} - -static void handle_enum_done(uint8_t rhport) { - dwc2_regs_t *dwc2 = DWC2_REG(rhport); - const dwc2_dsts_t dsts = {.value = dwc2->dsts}; - tusb_speed_t speed; - switch (dsts.enum_speed) { - case DCFG_SPEED_HIGH: - speed = TUSB_SPEED_HIGH; - break; - - case DCFG_SPEED_LOW: - speed = TUSB_SPEED_LOW; - break; - - case DCFG_SPEED_FULL_30_60MHZ: - case DCFG_SPEED_FULL_48MHZ: - default: - speed = TUSB_SPEED_FULL; - break; - } - - // TODO must update GUSBCFG_TRDT according to link speed - dcd_event_bus_reset(rhport, speed, true); -} - -#if 0 -TU_ATTR_ALWAYS_INLINE static inline void print_doepint(uint32_t doepint) { - const char* str[] = { - "XFRC", "DIS", "AHBERR", "SETUP_DONE", - "ORXED", "STATUS_RX", "SETUP_B2B", "RSV7", - "OPERR", "BNA", "RSV10", "ISODROP", - "BBLERR", "NAK", "NYET", "SETUP_RX" - }; - - for(uint32_t i=0; ififo[0]; - - // Pop control word off FIFO - const dwc2_grxstsp_t grxstsp = {.value = dwc2->grxstsp}; - const uint8_t epnum = grxstsp.ep_ch_num; - - dwc2_dep_t* epout = &dwc2->epout[epnum]; - - switch (grxstsp.packet_status) { - case GRXSTS_PKTSTS_GLOBAL_OUT_NAK: - // Global OUT NAK: do nothing - break; - - case GRXSTS_PKTSTS_SETUP_RX: { - // Setup packet received - uint32_t* setup = (uint32_t*)(uintptr_t) _dcd_usbbuf.setup_packet; - // We can receive up to three setup packets in succession, but only the last one is valid. - setup[0] = (*rx_fifo); - setup[1] = (*rx_fifo); - break; - } - - case GRXSTS_PKTSTS_SETUP_DONE: - // Setup packet done: - // After popping this out, dwc2 asserts a DOEPINT_SETUP interrupt which is handled by handle_epout_irq() - epout->doeptsiz |= (3 << DOEPTSIZ_STUPCNT_Pos); - break; - - case GRXSTS_PKTSTS_RX_DATA: { - // Out packet received - const uint16_t byte_count = grxstsp.byte_count; - xfer_ctl_t* xfer = XFER_CTL_BASE(epnum, TUSB_DIR_OUT); - - if (byte_count) { - // Read packet off RxFIFO - if (xfer->ff) { - tu_fifo_write_n_const_addr_full_words(xfer->ff, (const void*) (uintptr_t) rx_fifo, byte_count); - } else { - dfifo_read_packet(dwc2, xfer->buffer, byte_count); - xfer->buffer += byte_count; - } - - // short packet, minus remaining bytes (xfer_size) - if (byte_count < xfer->max_size) { - const dwc2_ep_tsize_t tsiz = {.value = epout->tsiz}; - xfer->total_len -= tsiz.xfer_size; - if (epnum == 0) { - xfer->total_len -= _dcd_data.ep0_pending[TUSB_DIR_OUT]; - _dcd_data.ep0_pending[TUSB_DIR_OUT] = 0; - } - } - } - break; - } - - case GRXSTS_PKTSTS_RX_COMPLETE: - // Out packet done - // After this entry is popped from the receive FIFO, dwc2 asserts a Transfer Completed interrupt on - // the specified OUT endpoint which will be handled by handle_epout_irq() - break; - - default: break; - } -} - -static void handle_epout_slave(uint8_t rhport, uint8_t epnum, dwc2_doepint_t doepint_bm) { - if (doepint_bm.setup_phase_done) { - dcd_event_setup_received(rhport, _dcd_usbbuf.setup_packet, true); - return; - } - - // Normal OUT transfer complete - if (doepint_bm.xfer_complete) { - // only handle data skip if it is setup or status related - // Note: even though (xfer_complete + status_phase_rx) is for buffered DMA only, for STM32L47x (dwc2 v3.00a) they - // can is set when GRXSTS_PKTSTS_SETUP_RX is popped therefore they can bet set before/together with setup_phase_done - if (!doepint_bm.status_phase_rx && !doepint_bm.setup_packet_rx) { - xfer_ctl_t* xfer = XFER_CTL_BASE(epnum, TUSB_DIR_OUT); - - if ((epnum == 0) && _dcd_data.ep0_pending[TUSB_DIR_OUT]) { - // EP0 can only handle one packet, Schedule another packet to be received. - edpt_schedule_packets(rhport, epnum, TUSB_DIR_OUT); - } else { - dcd_event_xfer_complete(rhport, epnum, xfer->total_len, XFER_RESULT_SUCCESS, true); - } - } - } -} - -static void handle_epin_slave(uint8_t rhport, uint8_t epnum, dwc2_diepint_t diepint_bm) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - dwc2_dep_t* epin = &dwc2->epin[epnum]; - xfer_ctl_t* xfer = XFER_CTL_BASE(epnum, TUSB_DIR_IN); - - if (diepint_bm.xfer_complete) { - if ((epnum == 0) && _dcd_data.ep0_pending[TUSB_DIR_IN]) { - // EP0 can only handle one packet. Schedule another packet to be transmitted. - edpt_schedule_packets(rhport, epnum, TUSB_DIR_IN); - } else { - dcd_event_xfer_complete(rhport, epnum | TUSB_DIR_IN_MASK, xfer->total_len, XFER_RESULT_SUCCESS, true); - } - } - - // TX FIFO empty bit is read-only. It will only be cleared by hardware when written bytes is more than - // - 64 bytes or - // - Half/Empty of TX FIFO size (configured by GAHBCFG.TXFELVL) - if (diepint_bm.txfifo_empty && (dwc2->diepempmsk & (1 << epnum))) { - dwc2_ep_tsize_t tsiz = {.value = epin->tsiz}; - const uint16_t remain_packets = tsiz.packet_count; - - // Process every single packet (only whole packets can be written to fifo) - for (uint16_t i = 0; i < remain_packets; i++) { - tsiz.value = epin->tsiz; - const uint16_t remain_bytes = (uint16_t) tsiz.xfer_size; - const uint16_t xact_bytes = tu_min16(remain_bytes, xfer->max_size); - - // Check if dtxfsts has enough space available - if (xact_bytes > ((epin->dtxfsts & DTXFSTS_INEPTFSAV_Msk) << 2)) { - break; - } - - // Push packet to Tx-FIFO - if (xfer->ff) { - volatile uint32_t* tx_fifo = dwc2->fifo[epnum]; - tu_fifo_read_n_const_addr_full_words(xfer->ff, (void*)(uintptr_t)tx_fifo, xact_bytes); - } else { - dfifo_write_packet(dwc2, epnum, xfer->buffer, xact_bytes); - xfer->buffer += xact_bytes; - } - } - - // Turn off TXFE if all bytes are written. - tsiz.value = epin->tsiz; - if (tsiz.xfer_size == 0) { - dwc2->diepempmsk &= ~(1 << epnum); - } - } -} -#endif - -#if CFG_TUD_DWC2_DMA_ENABLE -static void handle_epout_dma(uint8_t rhport, uint8_t epnum, dwc2_doepint_t doepint_bm) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - - if (doepint_bm.setup_phase_done) { - dma_setup_prepare(rhport); - dcd_dcache_invalidate(_dcd_usbbuf.setup_packet, 8); - dcd_event_setup_received(rhport, _dcd_usbbuf.setup_packet, true); - return; - } - - // OUT XFER complete - if (doepint_bm.xfer_complete) { - // only handle data skip if it is setup or status related - // Normal OUT transfer complete - if (!doepint_bm.status_phase_rx && !doepint_bm.setup_packet_rx) { - if ((epnum == 0) && _dcd_data.ep0_pending[TUSB_DIR_OUT]) { - // EP0 can only handle one packet Schedule another packet to be received. - edpt_schedule_packets(rhport, epnum, TUSB_DIR_OUT); - } else { - dwc2_dep_t* epout = &dwc2->epout[epnum]; - xfer_ctl_t* xfer = XFER_CTL_BASE(epnum, TUSB_DIR_OUT); - - // determine actual received bytes - const dwc2_ep_tsize_t tsiz = {.value = epout->tsiz}; - const uint16_t remain = tsiz.xfer_size; - xfer->total_len -= remain; - - // this is ZLP, so prepare EP0 for next setup - // TODO use status phase rx - if(epnum == 0 && xfer->total_len == 0) { - dma_setup_prepare(rhport); - } - - dcd_dcache_invalidate(xfer->buffer, xfer->total_len); - dcd_event_xfer_complete(rhport, epnum, xfer->total_len, XFER_RESULT_SUCCESS, true); - } - } - } -} - -static void handle_epin_dma(uint8_t rhport, uint8_t epnum, dwc2_diepint_t diepint_bm) { - xfer_ctl_t* xfer = XFER_CTL_BASE(epnum, TUSB_DIR_IN); - - if (diepint_bm.xfer_complete) { - if ((epnum == 0) && _dcd_data.ep0_pending[TUSB_DIR_IN]) { - // EP0 can only handle one packet. Schedule another packet to be transmitted. - edpt_schedule_packets(rhport, epnum, TUSB_DIR_IN); - } else { - if(epnum == 0) { - dma_setup_prepare(rhport); - } - dcd_event_xfer_complete(rhport, epnum | TUSB_DIR_IN_MASK, xfer->total_len, XFER_RESULT_SUCCESS, true); - } - } -} -#endif - -static void handle_ep_irq(uint8_t rhport, uint8_t dir) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - const bool is_dma = dma_device_enabled(dwc2); - const uint8_t ep_count = dwc2_ep_count(dwc2); - const uint8_t daint_offset = (dir == TUSB_DIR_IN) ? DAINT_IEPINT_Pos : DAINT_OEPINT_Pos; - dwc2_dep_t* ep_base = &dwc2->ep[dir == TUSB_DIR_IN ? 0 : 1][0]; - - // DAINT for a given EP clears when DEPINTx is cleared. - // EPINT will be cleared when DAINT bits are cleared. - for (uint8_t epnum = 0; epnum < ep_count; epnum++) { - if (dwc2->daint & TU_BIT(daint_offset + epnum)) { - dwc2_dep_t* epout = &ep_base[epnum]; - union { - uint32_t value; - dwc2_diepint_t diepint_bm; - dwc2_doepint_t doepint_bm; - } intr; - intr.value = epout->intr; - - epout->intr = intr.value; // Clear interrupt - - if (is_dma) { - #if CFG_TUD_DWC2_DMA_ENABLE - if (dir == TUSB_DIR_IN) { - handle_epin_dma(rhport, epnum, intr.diepint_bm); - } else { - handle_epout_dma(rhport, epnum, intr.doepint_bm); - } - #endif - } else { - #if CFG_TUD_DWC2_SLAVE_ENABLE - if (dir == TUSB_DIR_IN) { - handle_epin_slave(rhport, epnum, intr.diepint_bm); - } else { - handle_epout_slave(rhport, epnum, intr.doepint_bm); - } - #endif - } - } - } -} - -/* Interrupt Hierarchy - DIEPINT DIEPINT - \ / - \ / - DAINT - / \ - / \ - GINTSTS: OEPInt IEPInt | USBReset | EnumDone | USBSusp | WkUpInt | OTGInt | SOF | RXFLVL - - Note: when OTG_MULTI_PROC_INTRPT = 1, Device Each endpoint interrupt deachint/deachmsk/diepeachmsk/doepeachmsk - are combined to generate dedicated interrupt line for each endpoint. - */ -void dcd_int_handler(uint8_t rhport) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - const uint32_t gintmask = dwc2->gintmsk; - const uint32_t gintsts = dwc2->gintsts & gintmask; - - if (gintsts & GINTSTS_USBRST) { - // USBRST is start of reset. - dwc2->gintsts = GINTSTS_USBRST; -#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) - _allocated_fifos = 1; -#endif - - usbd_spin_lock(true); - handle_bus_reset(rhport); - usbd_spin_unlock(true); - } - - if (gintsts & GINTSTS_ENUMDNE) { - // ENUMDNE is the end of reset where speed of the link is detected - dwc2->gintsts = GINTSTS_ENUMDNE; - handle_enum_done(rhport); - } - - if (gintsts & GINTSTS_USBSUSP) { - dwc2->gintsts = GINTSTS_USBSUSP; - //dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true); - dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true); -#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) - _allocated_fifos = 1; -#endif - } - - if (gintsts & GINTSTS_WKUINT) { - dwc2->gintsts = GINTSTS_WKUINT; - dcd_event_bus_signal(rhport, DCD_EVENT_RESUME, true); - } - - // TODO check GINTSTS_DISCINT for disconnect detection - // if(int_status & GINTSTS_DISCINT) - - if (gintsts & GINTSTS_OTGINT) { - // OTG INT bit is read-only - const uint32_t otg_int = dwc2->gotgint; - - if (otg_int & GOTGINT_SEDET) { - dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true); -#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) - _allocated_fifos = 1; -#endif - } - - dwc2->gotgint = otg_int; - } - - if(gintsts & GINTSTS_SOF) { - dwc2->gintsts = GINTSTS_SOF; - const uint32_t frame = (dwc2->dsts & DSTS_FNSOF) >> DSTS_FNSOF_Pos; - - // Disable SOF interrupt if SOF was not explicitly enabled since SOF was used for remote wakeup detection - if (!_dcd_data.sof_en) { - dwc2->gintmsk &= ~GINTMSK_SOFM; - } - - dcd_event_sof(rhport, frame, true); - } - -#if CFG_TUD_DWC2_SLAVE_ENABLE - // RxFIFO non-empty interrupt handling. - if (gintsts & GINTSTS_RXFLVL) { - // RXFLVL bit is read-only - dwc2->gintmsk &= ~GINTMSK_RXFLVLM; // disable RXFLVL interrupt while reading - - do { - handle_rxflvl_irq(rhport); // read all packets - } while(dwc2->gintsts & GINTSTS_RXFLVL); - - dwc2->gintmsk |= GINTMSK_RXFLVLM; - } -#endif - - // OUT endpoint interrupt handling. - if (gintsts & GINTSTS_OEPINT) { - // OEPINT is read-only, clear using DOEPINTn - handle_ep_irq(rhport, TUSB_DIR_OUT); - } - - // IN endpoint interrupt handling. - if (gintsts & GINTSTS_IEPINT) { - // IEPINT bit read-only, clear using DIEPINTn - handle_ep_irq(rhport, TUSB_DIR_IN); - } -} - -#if CFG_TUD_TEST_MODE -void dcd_enter_test_mode(uint8_t rhport, tusb_feature_test_mode_t test_selector) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - - // Enable the test mode - dwc2->dctl = (dwc2->dctl & ~DCTL_TCTL_Msk) | (((uint8_t) test_selector) << DCTL_TCTL_Pos); -} -#endif - -#endif diff --git a/patches/dwc2_esp32_h.diff b/patches/dwc2_esp32_h.diff deleted file mode 100644 index 94cb86f32..000000000 --- a/patches/dwc2_esp32_h.diff +++ /dev/null @@ -1,18 +0,0 @@ -diff --git a/src/portable/synopsys/dwc2/dwc2_esp32.h b/src/portable/synopsys/dwc2/dwc2_esp32.h -index 49b8c54cb..8b5e99741 100644 ---- a/src/portable/synopsys/dwc2/dwc2_esp32.h -+++ b/src/portable/synopsys/dwc2/dwc2_esp32.h -@@ -70,11 +70,13 @@ static void dwc2_int_handler_wrap(void* arg) { - const tusb_role_t role = (tusb_role_t) tu_u16_high((uint16_t)(uintptr_t)arg); - #if CFG_TUD_ENABLED - if (role == TUSB_ROLE_DEVICE) { -+ void dcd_int_handler(uint8_t rhport); - dcd_int_handler(rhport); - } - #endif - #if CFG_TUH_ENABLED && !CFG_TUH_MAX3421 - if (role == TUSB_ROLE_HOST) { -+ void hcd_int_handler(uint8_t rhport, bool in_isr); - hcd_int_handler(rhport, true); - } - #endif diff --git a/tools/patch-tinyusb.sh b/tools/patch-tinyusb.sh deleted file mode 100755 index eeaa4d43b..000000000 --- a/tools/patch-tinyusb.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -mv components/arduino_tinyusb/src/dcd_dwc2.c components/arduino_tinyusb/src/dcd_dwc2.c.prev -cp components/arduino_tinyusb/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c components/arduino_tinyusb/src/dcd_dwc2.c -patch -p1 -N -i components/arduino_tinyusb/patches/dcd_dwc2.patch diff --git a/tools/update-components.sh b/tools/update-components.sh index 18e7b689e..298783c74 100755 --- a/tools/update-components.sh +++ b/tools/update-components.sh @@ -14,7 +14,4 @@ else git -C "$TINYUSB_REPO_DIR" fetch && \ git -C "$TINYUSB_REPO_DIR" pull --ff-only fi -cd $TINYUSB_REPO_DIR -patch -p1 -N -i $AR_PATCHES/dwc2_esp32_h.diff -cd - if [ $? -ne 0 ]; then exit 1; fi From aabf62d9836f46e06d7fb3929998ef4003bd2e57 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Mon, 10 Nov 2025 18:01:11 -0300 Subject: [PATCH 47/48] ci(deploy): Fix deploy checks (#328) --- .github/workflows/cron.yml | 2 +- .github/workflows/cron_build.yml | 2 +- tools/check-deploy-needed.sh | 113 +++++++----- tools/config.sh | 306 +++++++++++++++---------------- 4 files changed, 215 insertions(+), 208 deletions(-) diff --git a/.github/workflows/cron.yml b/.github/workflows/cron.yml index 48e1ff7a9..58fa2757c 100644 --- a/.github/workflows/cron.yml +++ b/.github/workflows/cron.yml @@ -21,7 +21,7 @@ defaults: jobs: build-libs: name: Build with IDF ${{ matrix.idf_branch }} - if: github.repository_owner == 'espressif' + if: github.repository_owner == 'espressif' || github.event_name == 'workflow_dispatch' uses: ./.github/workflows/cron_build.yml with: idf_branch: ${{ matrix.idf_branch }} diff --git a/.github/workflows/cron_build.yml b/.github/workflows/cron_build.yml index fd9634928..e69b23187 100644 --- a/.github/workflows/cron_build.yml +++ b/.github/workflows/cron_build.yml @@ -51,7 +51,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - source ./tools/check-deploy-needed.sh + bash ./tools/check-deploy-needed.sh targets_list=$(echo "${{ inputs.targets }}" | sed 's/ *, */,/g' | sed 's/^/["/' | sed 's/$/"]/' | sed 's/,/","/g') echo "Targets list: $targets_list" echo "targets_list=$targets_list" >> $GITHUB_OUTPUT diff --git a/tools/check-deploy-needed.sh b/tools/check-deploy-needed.sh index e33cc169c..4c4d29458 100755 --- a/tools/check-deploy-needed.sh +++ b/tools/check-deploy-needed.sh @@ -1,65 +1,87 @@ -#/bin/bash +#!/bin/bash source ./tools/config.sh -IDF_COMMIT=`github_last_commit "$IDF_REPO" "$IDF_BRANCH"` +IDF_COMMIT=$(github_last_commit "$IDF_REPO" "$IDF_BRANCH") -if [ -z $IDF_COMMIT ]; then +if [ -z "$IDF_COMMIT" ]; then echo "Failed to get IDF commit for branch $IDF_BRANCH" exit 1 fi -if [ -z $GITHUB_HEAD_REF ]; then - current_branch=`git branch --show-current` +if [ -z "$GITHUB_HEAD_REF" ]; then + current_branch=$(git branch --show-current) else current_branch="$GITHUB_HEAD_REF" fi AR_BRANCH="master" -if [[ "$current_branch" != "master" && `github_branch_exists "$AR_REPO" "$current_branch"` == "1" ]]; then +if [[ "$current_branch" != "master" && $(github_branch_exists "$AR_REPO" "$current_branch") == "1" ]]; then AR_BRANCH="$current_branch" else AR_BRANCH_NAME="idf-$IDF_BRANCH" - has_ar_branch=`github_branch_exists "$AR_REPO" "$AR_BRANCH_NAME"` + has_ar_branch=$(github_branch_exists "$AR_REPO" "$AR_BRANCH_NAME") if [ "$has_ar_branch" == "1" ]; then AR_BRANCH="$AR_BRANCH_NAME" else - has_ar_branch=`github_branch_exists "$AR_REPO" "$AR_PR_TARGET_BRANCH"` + has_ar_branch=$(github_branch_exists "$AR_REPO" "$AR_PR_TARGET_BRANCH") if [ "$has_ar_branch" == "1" ]; then AR_BRANCH="$AR_PR_TARGET_BRANCH" fi fi fi +echo "AR_BRANCH: $AR_BRANCH" +echo "AR_BRANCH_NAME: $AR_BRANCH_NAME" +echo "AR_PR_TARGET_BRANCH: $AR_PR_TARGET_BRANCH" +echo "has_ar_branch: $has_ar_branch" + # format new branch name and pr title AR_NEW_BRANCH_NAME="idf-$IDF_BRANCH" AR_NEW_COMMIT_MESSAGE="IDF $IDF_BRANCH $IDF_COMMIT" AR_NEW_PR_TITLE="IDF $IDF_BRANCH" -LIBS_RELEASE_TAG="idf-"${IDF_BRANCH//\//_}"" +LIBS_RELEASE_TAG="idf-${IDF_BRANCH//\//_}" LIBS_VERSION_PREFIX="$LIBS_RELEASE_TAG-$IDF_COMMIT-v" VERSION_COUNTER=1 -AR_HAS_BRANCH=`github_branch_exists "$AR_REPO" "$AR_NEW_BRANCH_NAME"` +AR_HAS_BRANCH=$(github_branch_exists "$AR_REPO" "$AR_NEW_BRANCH_NAME") if [ "$AR_HAS_BRANCH" == "1" ]; then - LATEST_LIBS_IDF=`github_get_libs_idf "$AR_REPO" "$AR_NEW_BRANCH_NAME" "$AR_NEW_PR_TITLE"` + LATEST_LIBS_IDF=$(github_get_libs_idf "$AR_REPO" "$AR_NEW_BRANCH_NAME" "$AR_NEW_PR_TITLE") else - LATEST_LIBS_IDF=`github_get_libs_idf "$AR_REPO" "$AR_BRANCH" "$AR_NEW_PR_TITLE"` + LATEST_LIBS_IDF=$(github_get_libs_idf "$AR_REPO" "$AR_BRANCH" "$AR_NEW_PR_TITLE") fi +echo "AR_NEW_BRANCH_NAME: $AR_NEW_BRANCH_NAME" +echo "AR_NEW_COMMIT_MESSAGE: $AR_NEW_COMMIT_MESSAGE" +echo "AR_NEW_PR_TITLE: $AR_NEW_PR_TITLE" + +echo "LIBS_RELEASE_TAG: $LIBS_RELEASE_TAG" +echo "LIBS_VERSION_PREFIX: $LIBS_VERSION_PREFIX" +echo "VERSION_COUNTER: $VERSION_COUNTER" + +echo "AR_HAS_BRANCH: $AR_HAS_BRANCH" +echo "LATEST_LIBS_IDF: $LATEST_LIBS_IDF" + echo "Current IDF commit: $IDF_COMMIT" echo "Latest IDF commit in $AR_BRANCH of $AR_REPO: $LATEST_LIBS_IDF" -AR_HAS_COMMIT=`if [ "$LATEST_LIBS_IDF" == "$IDF_COMMIT" ]; then echo "1"; else echo "0"; fi` -AR_HAS_PR=`github_pr_exists "$AR_REPO" "$AR_NEW_BRANCH_NAME"` +AR_HAS_COMMIT=$(if [ "$LATEST_LIBS_IDF" == "$IDF_COMMIT" ]; then echo "1"; else echo "0"; fi) +AR_HAS_PR=$(github_pr_exists "$AR_REPO" "$AR_NEW_BRANCH_NAME") + +echo "AR_HAS_COMMIT: $AR_HAS_COMMIT" +echo "AR_HAS_PR: $AR_HAS_PR" + +LIBS_RELEASE_ID=$(github_release_id "$AR_LIBS_REPO" "$LIBS_RELEASE_TAG") +LIBS_HAS_RELEASE=$(if [ -n "$LIBS_RELEASE_ID" ]; then echo "1"; else echo "0"; fi) -LIBS_RELEASE_ID=`github_release_id "$AR_LIBS_REPO" "$LIBS_RELEASE_TAG"` -LIBS_HAS_RELEASE=`if [ -n "$LIBS_RELEASE_ID" ]; then echo "1"; else echo "0"; fi` +echo "LIBS_RELEASE_ID: $LIBS_RELEASE_ID" +echo "LIBS_HAS_RELEASE: $LIBS_HAS_RELEASE" if [ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]; then echo "Workflow dispatch event. Generating new libs." while true; do - LIBS_ASSET_ID=`github_release_asset_id "$AR_LIBS_REPO" "$LIBS_RELEASE_ID" "esp32-arduino-libs-$LIBS_VERSION_PREFIX$VERSION_COUNTER.zip"` + LIBS_ASSET_ID=$(github_release_asset_id "$AR_LIBS_REPO" "$LIBS_RELEASE_ID" "esp32-arduino-libs-$LIBS_VERSION_PREFIX$VERSION_COUNTER.zip") if [ -n "$LIBS_ASSET_ID" ]; then VERSION_COUNTER=$((VERSION_COUNTER+1)) else @@ -67,11 +89,16 @@ if [ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]; then fi done else - LIBS_ASSET_ID=`github_release_asset_id "$AR_LIBS_REPO" "$LIBS_RELEASE_ID" "esp32-arduino-libs-$LIBS_VERSION_PREFIX$VERSION_COUNTER.zip"` + LIBS_ASSET_ID=$(github_release_asset_id "$AR_LIBS_REPO" "$LIBS_RELEASE_ID" "esp32-arduino-libs-$LIBS_VERSION_PREFIX$VERSION_COUNTER.zip") fi +echo "LIBS_ASSET_ID: $LIBS_ASSET_ID" + LIBS_VERSION="$LIBS_VERSION_PREFIX$VERSION_COUNTER" -LIBS_HAS_ASSET=`if [ -n "$LIBS_ASSET_ID" ]; then echo "1"; else echo "0"; fi` +LIBS_HAS_ASSET=$(if [ -n "$LIBS_ASSET_ID" ]; then echo "1"; else echo "0"; fi) + +echo "LIBS_VERSION: $LIBS_VERSION" +echo "LIBS_HAS_ASSET: $LIBS_HAS_ASSET" export IDF_COMMIT @@ -103,37 +130,25 @@ else exit 1 fi -echo "IDF_COMMIT: $IDF_COMMIT" -echo "AR_BRANCH: $AR_BRANCH" -echo "AR_NEW_COMMIT_MESSAGE: $AR_NEW_COMMIT_MESSAGE" -echo "AR_NEW_BRANCH_NAME: $AR_NEW_BRANCH_NAME" -echo "AR_NEW_PR_TITLE: $AR_NEW_PR_TITLE" -echo "AR_HAS_COMMIT: $AR_HAS_COMMIT" -echo "AR_HAS_BRANCH: $AR_HAS_BRANCH" -echo "AR_HAS_PR: $AR_HAS_PR" -echo "LIBS_RELEASE_TAG: $LIBS_RELEASE_TAG" -echo "LIBS_VERSION: $LIBS_VERSION" -echo "LIBS_RELEASE_ID: $LIBS_RELEASE_ID" -echo "LIBS_HAS_RELEASE: $LIBS_HAS_RELEASE" -echo "LIBS_ASSET_ID: $LIBS_ASSET_ID" -echo "LIBS_HAS_ASSET: $LIBS_HAS_ASSET" echo "DEPLOY_NEEDED: $DEPLOY_NEEDED" -if [ ! -x $GITHUB_OUTPUT ]; then - echo "idf_commit=$IDF_COMMIT" >> "$GITHUB_OUTPUT" - echo "ar_branch=$AR_BRANCH" >> "$GITHUB_OUTPUT" - echo "ar_new_commit_message=$AR_NEW_COMMIT_MESSAGE" >> "$GITHUB_OUTPUT" - echo "ar_new_branch_name=$AR_NEW_BRANCH_NAME" >> "$GITHUB_OUTPUT" - echo "ar_new_pr_title=$AR_NEW_PR_TITLE" >> "$GITHUB_OUTPUT" - echo "ar_has_commit=$AR_HAS_COMMIT" >> "$GITHUB_OUTPUT" - echo "ar_has_branch=$AR_HAS_BRANCH" >> "$GITHUB_OUTPUT" - echo "ar_has_pr=$AR_HAS_PR" >> "$GITHUB_OUTPUT" - echo "libs_release_tag=$LIBS_RELEASE_TAG" >> "$GITHUB_OUTPUT" - echo "libs_version=$LIBS_VERSION" >> "$GITHUB_OUTPUT" - echo "libs_release_id=$LIBS_RELEASE_ID" >> "$GITHUB_OUTPUT" - echo "libs_has_release=$LIBS_HAS_RELEASE" >> "$GITHUB_OUTPUT" - echo "libs_asset_id=$LIBS_ASSET_ID" >> "$GITHUB_OUTPUT" - echo "libs_has_asset=$LIBS_HAS_ASSET" >> "$GITHUB_OUTPUT" - echo "deploy_needed=$DEPLOY_NEEDED" >> "$GITHUB_OUTPUT" +if [ -n "$GITHUB_OUTPUT" ]; then + { + echo "idf_commit=$IDF_COMMIT" + echo "ar_branch=$AR_BRANCH" + echo "ar_new_commit_message=$AR_NEW_COMMIT_MESSAGE" + echo "ar_new_branch_name=$AR_NEW_BRANCH_NAME" + echo "ar_new_pr_title=$AR_NEW_PR_TITLE" + echo "ar_has_commit=$AR_HAS_COMMIT" + echo "ar_has_branch=$AR_HAS_BRANCH" + echo "ar_has_pr=$AR_HAS_PR" + echo "libs_release_tag=$LIBS_RELEASE_TAG" + echo "libs_version=$LIBS_VERSION" + echo "libs_release_id=$LIBS_RELEASE_ID" + echo "libs_has_release=$LIBS_HAS_RELEASE" + echo "libs_asset_id=$LIBS_ASSET_ID" + echo "libs_has_asset=$LIBS_HAS_ASSET" + echo "deploy_needed=$DEPLOY_NEEDED" + } >> "$GITHUB_OUTPUT" fi diff --git a/tools/config.sh b/tools/config.sh index 1ede4185c..853c618af 100755 --- a/tools/config.sh +++ b/tools/config.sh @@ -1,21 +1,23 @@ #!/bin/bash +# shellcheck disable=SC2034 +DEBUG() { echo -e "DEBUG: $*\n" >&2; } -if [ -z $IDF_PATH ]; then +if [ -z "$IDF_PATH" ]; then export IDF_PATH="$PWD/esp-idf" fi -if [ -z $IDF_BRANCH ]; then +if [ -z "$IDF_BRANCH" ]; then IDF_BRANCH="release/v5.5" fi -if [ -z $AR_PR_TARGET_BRANCH ]; then +if [ -z "$AR_PR_TARGET_BRANCH" ]; then AR_PR_TARGET_BRANCH="master" fi -if [ -z $IDF_TARGET ]; then +if [ -z "$IDF_TARGET" ]; then if [ -f sdkconfig ]; then - IDF_TARGET=`cat sdkconfig | grep CONFIG_IDF_TARGET= | cut -d'"' -f2` + IDF_TARGET=$(grep CONFIG_IDF_TARGET= sdkconfig | cut -d'"' -f2) if [ "$IDF_TARGET" = "" ]; then IDF_TARGET="esp32" fi @@ -35,7 +37,7 @@ AR_LIBS_REPO="$AR_USER/esp32-arduino-lib-builder" AR_REPO_URL="https://github.com/$AR_REPO.git" IDF_REPO_URL="https://github.com/$IDF_REPO.git" AR_LIBS_REPO_URL="https://github.com/$AR_LIBS_REPO.git" -if [ -n $GITHUB_TOKEN ]; then +if [ -n "$GITHUB_TOKEN" ]; then AR_REPO_URL="https://$GITHUB_TOKEN@github.com/$AR_REPO.git" AR_LIBS_REPO_URL="https://$GITHUB_TOKEN@github.com/$AR_LIBS_REPO.git" fi @@ -53,224 +55,214 @@ PIOARDUINO_SDK="FRAMEWORK_SDK_DIR, \"$IDF_TARGET\"" TOOLS_JSON_OUT="$AR_TOOLS/esp32-arduino-libs" if [ -d "$IDF_PATH" ]; then - export IDF_COMMIT=$(git -C "$IDF_PATH" rev-parse --short HEAD) - export IDF_BRANCH=$(git -C "$IDF_PATH" symbolic-ref --short HEAD || git -C "$IDF_PATH" tag --points-at HEAD) + IDF_COMMIT=$(git -C "$IDF_PATH" rev-parse --short HEAD) + IDF_BRANCH=$(git -C "$IDF_PATH" symbolic-ref --short HEAD || git -C "$IDF_PATH" tag --points-at HEAD) + export IDF_COMMIT + export IDF_BRANCH fi -function get_os(){ - OSBITS=`uname -m` +get_os() { + DEBUG "get_os()" + OSBITS=$(uname -m) + DEBUG "OSTYPE=$OSTYPE, OSBITS=$OSBITS" if [[ "$OSTYPE" == "linux"* ]]; then - if [[ "$OSBITS" == "i686" ]]; then - echo "linux32" - elif [[ "$OSBITS" == "x86_64" ]]; then - echo "linux64" - elif [[ "$OSBITS" == "armv7l" ]]; then - echo "linux-armel" - else - echo "unknown" - return 1 - fi + case "$OSBITS" in + i686) echo "linux32" ;; + x86_64) echo "linux64" ;; + armv7l) echo "linux-armel" ;; + *) echo "unknown"; return 1 ;; + esac elif [[ "$OSTYPE" == "darwin"* ]]; then echo "macos" - elif [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then + elif [[ "$OSTYPE" == "cygwin" || "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then echo "win32" else echo "$OSTYPE" return 1 fi - return 0 } -AR_OS=`get_os` - +AR_OS=$(get_os) export SED="sed" export SSTAT="stat -c %s" if [[ "$AR_OS" == "macos" ]]; then - if ! [ -x "$(command -v gsed)" ]; then - echo "ERROR: gsed is not installed! Please install gsed first. ex. brew install gsed" + if ! command -v gsed >/dev/null; then + echo "ERROR: gsed not installed" >&2 exit 1 fi - if ! [ -x "$(command -v gawk)" ]; then - echo "ERROR: gawk is not installed! Please install gawk first. ex. brew install gawk" + if ! command -v gawk >/dev/null; then + echo "ERROR: gawk not installed" >&2 exit 1 fi export SED="gsed" export SSTAT="stat -f %z" fi -function github_get_libs_idf(){ # github_get_libs_idf +github_get_libs_idf() { + DEBUG "github_get_libs_idf($1, $2, $3)" local repo_path="$1" local branch_name="$2" local message_prefix="$3" - message_prefix=$(echo $message_prefix | sed 's/[]\/$*.^|[]/\\&/g') # Escape special characters - local page=1 - local version_found="" - local libs_version="" - - while [[ "$libs_version" == "" && "$page" -le 5 ]]; do - # Get the latest commit message that matches the prefix and extract the hash from the last commit message - version_found=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/commits?sha=$branch_name&per_page=100&page=$page" | \ - jq -r --arg prefix "$message_prefix" '[ .[] | select(.commit.message | test($prefix + " [a-f0-9]{8}")) ][0] | .commit.message' | \ - grep -Eo "$message_prefix [a-f0-9]{8}" | \ - awk 'END {print $NF}'` - if [[ "$version_found" != "" && "$version_found" != "null" ]]; then + message_prefix=$(echo "$message_prefix" | sed 's/[]\/$*.^|[]/\\&/g') + local page=1 libs_version="" + while [[ -z "$libs_version" && "$page" -le 5 ]]; do + DEBUG "Fetching commits page $page" + local response + response=$(curl -s -k -H "Authorization: token $GITHUB_TOKEN" \ + -H "Accept: application/vnd.github.v3.raw+json" \ + "https://api.github.com/repos/$repo_path/commits?sha=$branch_name&per_page=100&page=$page") + local version_found + version_found=$(echo "$response" | jq -r --arg prefix "$message_prefix" \ + '[ .[] | select(.commit.message | test($prefix + " [a-f0-9]{8}")) ][0] | .commit.message' | \ + grep -Eo "$message_prefix [a-f0-9]{8}" | awk 'END {print $NF}') + if [[ -n "$version_found" ]]; then + DEBUG "Found version: $version_found" libs_version=$version_found else - page=$((page+1)) + ((page++)) fi done - - if [ ! "$libs_version" == "" ] && [ ! "$libs_version" == "null" ]; then echo $libs_version; else echo ""; fi + echo "$libs_version" } -function github_commit_exists(){ #github_commit_exists - local repo_path="$1" - local branch_name="$2" - local commit_message="$3" - local page=1 - local commits_found=0 - +github_commit_exists() { + DEBUG "github_commit_exists($1, $2, $3)" + local repo_path="$1" branch_name="$2" commit_message="$3" + local page=1 commits_found=0 while [ "$page" -le 5 ]; do - local response=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/commits?sha=$branch_name&per_page=100&page=$page"` - - if [[ -z "$response" || "$response" == "[]" ]]; then - break - fi - - local commits=`echo "$response" | jq -r '.[].commit.message' | grep "$commit_message" | wc -l` - if [ "$commits" -gt 0 ]; then + DEBUG "Checking commits page $page" + local response + response=$(curl -s -k -H "Authorization: token $GITHUB_TOKEN" \ + -H "Accept: application/vnd.github.v3.raw+json" \ + "https://api.github.com/repos/$repo_path/commits?sha=$branch_name&per_page=100&page=$page") + [[ -z "$response" || "$response" == "[]" ]] && break + if echo "$response" | jq -r '.[].commit.message' | grep -q "$commit_message"; then commits_found=1 break fi - - page=$((page+1)) + ((page++)) done - - echo $commits_found + echo "$commits_found" } -function github_last_commit(){ # github_last_commit - local repo_path="$1" - local branch_name="$2" - local commit=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/commits/heads/$branch_name" | jq -r '.sha'` - if [ ! "$commit" == "" ] && [ ! "$commit" == "null" ]; then - echo ${commit:0:8} - else - echo "" - fi +github_last_commit() { + DEBUG "github_last_commit($1, $2)" + local repo_path="$1" branch_name="$2" + local url="https://api.github.com/repos/$repo_path/commits/heads/$branch_name" + DEBUG "GET $url" + local commit + commit=$(curl -s -k -H "Authorization: token $GITHUB_TOKEN" "$url" | jq -r '.sha') + [[ -n "$commit" && "$commit" != "null" ]] && echo "${commit:0:8}" || echo "" } -function github_branch_exists(){ # github_branch_exists - local repo_path="$1" - local branch_name="$2" - local branch=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/branches/$branch_name" | jq -r '.name'` - if [ "$branch" == "$branch_name" ]; then echo 1; else echo 0; fi +github_branch_exists() { + DEBUG "github_branch_exists($1, $2)" + local repo_path="$1" branch_name="$2" + local url="https://api.github.com/repos/$repo_path/branches/$branch_name" + local branch + branch=$(curl -s -k -H "Authorization: token $GITHUB_TOKEN" "$url" | jq -r '.name') + [[ "$branch" == "$branch_name" ]] && echo 1 || echo 0 } -function github_pr_exists(){ # github_pr_exists - local repo_path="$1" - local branch_name="$2" - local pr_num=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/pulls?head=$AR_USER:$branch_name&state=open" | jq -r '.[].number'` - if [ ! "$pr_num" == "" ] && [ ! "$pr_num" == "null" ]; then echo 1; else echo 0; fi +github_pr_exists() { + DEBUG "github_pr_exists($1, $2)" + local repo_path="$1" branch_name="$2" + local url="https://api.github.com/repos/$repo_path/pulls?head=$AR_USER:$branch_name&state=open" + local pr_num + pr_num=$(curl -s -k -H "Authorization: token $GITHUB_TOKEN" "$url" | jq -r '.[].number') + [[ -n "$pr_num" && "$pr_num" != "null" ]] && echo 1 || echo 0 } -function github_release_id(){ # github_release_id - local repo_path="$1" - local release_tag="$2" - local page=1 - local release_id="" - +github_release_id() { + DEBUG "github_release_id($1, $2)" + local repo_path="$1" release_tag="$2" page=1 release_id="" while [[ "$page" -le 3 ]]; do - local response=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/releases?per_page=100&page=$page"` - - if [[ -z "$response" || "$response" == "[]" ]]; then - break - fi - - local release=`echo "$response" | jq --arg release_tag "$release_tag" -r '.[] | select(.tag_name == $release_tag) | .id'` - if [ ! "$release" == "" ] && [ ! "$release" == "null" ]; then - release_id=$release - break + local url="https://api.github.com/repos/$repo_path/releases?per_page=100&page=$page" + DEBUG "Fetching $url" + local response + response=$(curl -s -k -H "Authorization: token $GITHUB_TOKEN" "$url") + [[ -z "$response" || "$response" == "[]" ]] && break + release_id=$(echo "$response" | jq --arg tag "$release_tag" -r '.[] | select(.tag_name == $tag) | .id') + if [[ -n "$release_id" && "$release_id" != "null" ]]; then + DEBUG "Found release_id=$release_id" + echo "$release_id" + return 0 fi - - page=$((page+1)) + ((page++)) done - - echo "$release_id" + echo "Release '$release_tag' not found in $repo_path" >&2 + exit 1 } -function github_release_asset_id(){ # github_release_asset_id - local repo_path="$1" - local release_id="$2" - local release_file="$3" - local page=1 - local asset_id="" - +github_release_asset_id() { + DEBUG "github_release_asset_id($1, $2, $3)" + local repo_path="$1" release_id="$2" release_file="$3" page=1 while [[ "$page" -le 5 ]]; do - local response=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/releases/$release_id/assets?per_page=100&page=$page"` - - if [[ -z "$response" || "$response" == "[]" ]]; then - break + local url="https://api.github.com/repos/$repo_path/releases/$release_id/assets?per_page=100&page=$page" + DEBUG "GET $url" + local response + response=$(curl -s -k -H "Authorization: token $GITHUB_TOKEN" "$url") + [[ -z "$response" || "$response" == "[]" ]] && break + local asset_id + asset_id=$(echo "$response" | jq --arg f "$release_file" -r '.[] | select(.name == $f) | .id') + if [[ -n "$asset_id" && "$asset_id" != "null" ]]; then + DEBUG "Found asset_id=$asset_id" + echo "$asset_id" + return 0 fi - - local release_asset=`echo "$response" | jq --arg release_file "$release_file" -r '.[] | select(.name == $release_file) | .id'` - if [ ! "$release_asset" == "" ] && [ ! "$release_asset" == "null" ]; then - asset_id=$release_asset - break - fi - - page=$((page+1)) + ((page++)) done - - echo "$asset_id" + echo "No asset found for $release_file" >&2 + exit 1 } -function github_release_asset_upload(){ # github_release_asset_upload - local repo_path="$1" - local release_id="$2" - local release_file_name="$3" - local release_file_path="$4" +github_release_asset_upload() { + DEBUG "github_release_asset_upload($1, $2, $3, $4)" + local repo_path="$1" release_id="$2" release_file_name="$3" release_file_path="$4" local file_extension="${release_file_name##*.}" - local release_asset=`curl -s -k -X POST -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" -H "Content-Type: application/$file_extension" --data-binary "@$release_file_path" "https://uploads.github.com/repos/$repo_path/releases/$release_id/assets?name=$release_file_name" | jq -r '.id'` - if [ ! "$release_asset" == "" ] && [ ! "$release_asset" == "null" ]; then echo "$release_asset"; else echo ""; fi + local url="https://uploads.github.com/repos/$repo_path/releases/$release_id/assets?name=$release_file_name" + DEBUG "Uploading $release_file_name to $url" + local release_asset + release_asset=$(curl -s -k -X POST -H "Authorization: token $GITHUB_TOKEN" \ + -H "Content-Type: application/$file_extension" --data-binary "@$release_file_path" "$url" | jq -r '.id') + [[ -n "$release_asset" && "$release_asset" != "null" ]] && echo "$release_asset" || echo "" } -function github_release_asset_delete(){ # github_release_asset_delete - local repo_path="$1" - local release_asset_id="$2" +github_release_asset_delete() { + DEBUG "github_release_asset_delete($1, $2)" + local repo_path="$1" release_asset_id="$2" + local url="https://api.github.com/repos/$repo_path/releases/assets/$release_asset_id" + DEBUG "DELETE $url" local res - local return_code - res=$(curl -s -k -o /dev/null -w "%{http_code}" -X DELETE -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/releases/assets/$release_asset_id") - return_code=$? - if [ "$res" -eq 204 ] && [ "$return_code" -eq 0 ] ; then echo 1; else echo 0; fi + res=$(curl -s -k -o /dev/null -w "%{http_code}" -X DELETE -H "Authorization: token $GITHUB_TOKEN" "$url") + [[ "$res" -eq 204 ]] && echo 1 || echo 0 } - -function git_branch_exists(){ # git_branch_exists - local repo_path="$1" - local branch_name="$2" - local branch_found=`git -C "$repo_path" ls-remote --heads origin "$branch_name"` - if [ -n "$branch_found" ]; then echo 1; else echo 0; fi +git_branch_exists() { + DEBUG "git_branch_exists($1, $2)" + local repo_path="$1" branch_name="$2" + git -C "$repo_path" ls-remote --heads origin "$branch_name" | grep -q . && echo 1 || echo 0 } -function git_commit_exists(){ #git_commit_exists - local repo_path="$1" - local commit_message="$2" - local commits_found=`git -C "$repo_path" log --all --grep="$commit_message" | grep commit` - if [ -n "$commits_found" ]; then echo 1; else echo 0; fi +git_commit_exists() { + DEBUG "git_commit_exists($1, $2)" + local repo_path="$1" commit_message="$2" + git -C "$repo_path" log --all --grep="$commit_message" | grep -q commit && echo 1 || echo 0 } -function git_create_pr(){ # git_create_pr - local pr_branch="$1" - local pr_title="$2" - local pr_target="$3" +git_create_pr() { + DEBUG "git_create_pr($1, $2, $3)" + local pr_branch="$1" pr_title="$2" pr_target="$3" local pr_body="\`\`\`\r\n" - while read -r line; do pr_body+=$line"\r\n"; done < "$AR_TOOLS/esp32-arduino-libs/versions.txt" + while IFS= read -r line; do pr_body+="$line\r\n"; done < "$AR_TOOLS/esp32-arduino-libs/versions.txt" pr_body+="\`\`\`\r\n" local pr_data="{\"title\": \"$pr_title\", \"body\": \"$pr_body\", \"head\": \"$AR_USER:$pr_branch\", \"base\": \"$pr_target\"}" - git_create_pr_res=`echo "$pr_data" | curl -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" --data @- "https://api.github.com/repos/$AR_REPO/pulls"` - local done_pr=`echo "$git_create_pr_res" | jq -r '.title'` - if [ ! "$done_pr" == "" ] && [ ! "$done_pr" == "null" ]; then echo 1; else echo 0; fi + local url="https://api.github.com/repos/$AR_REPO/pulls" + DEBUG "Creating PR via $url" + local response + response=$(echo "$pr_data" | curl -s -k -H "Authorization: token $GITHUB_TOKEN" --data @- "$url") + local result + result=$(echo "$response" | jq -r '.title') + [[ -n "$result" && "$result" != "null" ]] && echo 1 || echo 0 } - From 45c1b25b0a43ba35f629598ff8a3b8933200c821 Mon Sep 17 00:00:00 2001 From: Linar Yusupov <linar.r.yusupov@gmail.com> Date: Wed, 12 Nov 2025 12:20:11 +0300 Subject: [PATCH 48/48] USB Host Library settings relocated from common to S2, S3 and P5 specific defconfig files (#330) --- configs/defconfig.common | 3 --- configs/defconfig.esp32p4 | 4 ++++ configs/defconfig.esp32s2 | 4 ++++ configs/defconfig.esp32s3 | 3 +++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/configs/defconfig.common b/configs/defconfig.common index 1f4a1924d..a28c46bb1 100644 --- a/configs/defconfig.common +++ b/configs/defconfig.common @@ -142,9 +142,6 @@ CONFIG_ESP_MATTER_MEM_ALLOC_MODE_INTERNAL=n #TinyUSB Config CONFIG_TINYUSB_CDC_MAX_PORTS=2 -CONFIG_USB_HOST_HUBS_SUPPORTED=y -CONFIG_USB_HOST_HUB_MULTI_LEVEL=y -CONFIG_USB_HOST_HW_BUFFER_BIAS_PERIODIC_OUT=y # Zigbee Config CONFIG_ZB_ENABLED=y diff --git a/configs/defconfig.esp32p4 b/configs/defconfig.esp32p4 index da605c0fe..1d1f4c525 100644 --- a/configs/defconfig.esp32p4 +++ b/configs/defconfig.esp32p4 @@ -41,3 +41,7 @@ CONFIG_ESP_HOSTED_NIMBLE_HCI_VHCI=y # RGB Display Optimizations CONFIG_LCD_RGB_ISR_IRAM_SAFE=y CONFIG_LCD_RGB_RESTART_IN_VSYNC=y + +CONFIG_USB_HOST_HUBS_SUPPORTED=y +CONFIG_USB_HOST_HUB_MULTI_LEVEL=y +CONFIG_USB_HOST_HW_BUFFER_BIAS_BALANCED=y diff --git a/configs/defconfig.esp32s2 b/configs/defconfig.esp32s2 index f90b0fab5..82bcde5d3 100644 --- a/configs/defconfig.esp32s2 +++ b/configs/defconfig.esp32s2 @@ -18,3 +18,7 @@ CONFIG_ULP_COPROC_RESERVE_MEM=512 # Matter settings: CONFIG_ENABLE_CHIPOBLE=n + +CONFIG_USB_HOST_HUBS_SUPPORTED=y +CONFIG_USB_HOST_HUB_MULTI_LEVEL=y +CONFIG_USB_HOST_HW_BUFFER_BIAS_PERIODIC_OUT=y diff --git a/configs/defconfig.esp32s3 b/configs/defconfig.esp32s3 index 12aec7c47..312491c3d 100644 --- a/configs/defconfig.esp32s3 +++ b/configs/defconfig.esp32s3 @@ -33,3 +33,6 @@ CONFIG_ENABLE_CHIPOBLE=y # increase the maximum number of endpoints per device CONFIG_ESP_MATTER_MAX_DYNAMIC_ENDPOINT_COUNT=32 +CONFIG_USB_HOST_HUBS_SUPPORTED=y +CONFIG_USB_HOST_HUB_MULTI_LEVEL=y +CONFIG_USB_HOST_HW_BUFFER_BIAS_PERIODIC_OUT=y