diff --git a/.github/workflows/cron.yml b/.github/workflows/cron.yml index 8a8f721d..ade7e7fa 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" diff --git a/components/arduino_tinyusb/patches/dcd_dwc2.patch b/components/arduino_tinyusb/patches/dcd_dwc2.patch index 14e6975f..2521a38e 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 ea931ab9..b6c3b1b2 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) { diff --git a/configs/defconfig.esp32s3 b/configs/defconfig.esp32s3 index ce53e774..36fa6b6a 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 diff --git a/main/idf_component.yml b/main/idf_component.yml index 8c574bb0..a85eca54 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]" diff --git a/tools/config.sh b/tools/config.sh index 79d4feef..4f17d8a1 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 diff --git a/tools/install-esp-idf.sh b/tools/install-esp-idf.sh index 0519ae67..06a67c35 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)