Skip to content

Commit d09c8c6

Browse files
me-no-devlucasssvazSuGliderP-R-O-C-H-Ykvp1703
authored
ESP32 Arduino v3.1 libs from ESP-IDF v5.3 (#208)
* fix(build): Changes required to build against IDF v5.3 * Use unified Xtensa toolchain * add(build): Add initial ESP32-P4 skeleton Chip is not selected by default and has only one memory and bootloader configuration. This is the minimum required to issue `build.sh -t esp32p4` which will currently fail, because Arduino support is not yet ready * feat(esp32p4): Build libs for ESP32-P4 (#221) * feat(esp32p4): Build libs for ESP32-P4 * Add target to workflows * Enable in builds * Remove bluedroid patch * Add P4 to libspi * Add P4 mem variants * Update SDK in JSON even if version did not change (#223) * Do not build matter for ESP32-P4 * Update ESP-DL configuration * Add additional DL models and use extra components only when needed * Use extra DL models only on S3 and P4 * Switch to the new ESP-DL only for ESP32-P4 * Rename old DL component and revert the name of the new * Enable TinyUSB build for ESP32P4 * Add support for HighSpeed USB in arduino_tinyusb * Update tinyusb dcd_dwc2 * Add P4 configuration for PSRAM, WDT and ESP-HOSTED * Update dcd_dwc2.c * Remove conditional inclusion of builder specified components CCACHE is very fast and it also causes issues with memory variants * Do not use ESP-DL on P4 * Update P4 PSRAM Speed to 200MHz * Fixes Matter over WiFi to disable OpenThread (#232) * Fixes Matter over WiFi to disable OpenThread * fix flag value * disables Matter Stack WiFi manager * rollback Matter WiFi Manager changes * Add define to signify that prebuilt libs are used * Enable FreeRTOS Trace Facility (#234) * Enable FreeRTOS Trace Facility * Enable more statistics * fix(docker): Add docker tag to run scripts in 5.3 branch (#236) * fix(docker): Add docker tag to run scripts in 5.3 branch * Add additional info * fix(zigbee): Unlink the zigbee libs (#242) * fix(): Move mkdir to top as its already used * Update TinyUSB DCD Source * Add missing compile source from TinyUSB * Fix path to TinyUSB dwc2_common.c * Update TinyUSB DCD * Update TinyUSB DCD * Update dcd_dwc2.c * Update dcd_dwc2.c * Update copy-libs.sh * Support rev 0 for P4 (#254) * Support rev 0 for P4 * Revert C6 slave idf target * Fix the crash for esp32 and esp32c3 (#248) * fix(trademark): Remove 3rd party trademarks from scripts (#255) * Update dcd_dwc2.c * Prepare for merging release/v5.3 into master --------- Co-authored-by: Lucas Saavedra Vaz <[email protected]> Co-authored-by: Rodrigo Garcia <[email protected]> Co-authored-by: Jan Procházka <[email protected]> Co-authored-by: kvp1703 <[email protected]>
1 parent c73bc7f commit d09c8c6

30 files changed

+805
-1037
lines changed

Diff for: .github/workflows/cron.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ jobs:
3636
lib_builder_branch: "release/v5.1"
3737
targets: "esp32,esp32s2,esp32s3,esp32c3,esp32c6,esp32h2"
3838
- idf_branch: "release/v5.3"
39-
lib_builder_branch: "release/v5.3"
39+
lib_builder_branch: "master"
4040
targets: "esp32,esp32s2,esp32s3,esp32c3,esp32c6,esp32h2,esp32p4"

Diff for: .github/workflows/push.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
runs-on: ubuntu-latest
2626
strategy:
2727
matrix:
28-
target: [esp32, esp32s2, esp32s3, esp32c2, esp32c3, esp32c6, esp32h2]
28+
target: [esp32, esp32s2, esp32s3, esp32c2, esp32c3, esp32c6, esp32h2, esp32p4]
2929
fail-fast: false
3030
steps:
3131
- uses: actions/checkout@v4

Diff for: CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ add_custom_command(
3434
)
3535
add_custom_target(mem-variant DEPENDS "mem_variant")
3636

37+
idf_build_set_property(COMPILE_DEFINITIONS "-DESP32_ARDUINO_LIB_BUILDER" APPEND)
38+
3739
##################
3840
### ESP Matter ###
3941
##################

Diff for: build.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,14 @@ if [ "$BUILD_TYPE" = "all" ]; then
305305
if [ $? -ne 0 ]; then exit 1; fi
306306
fi
307307

308-
# Generate PlatformIO manifest file
308+
# Generate pioarduino manifest file
309309
if [ "$BUILD_TYPE" = "all" ]; then
310-
echo "* Generating PlatformIO manifest file..."
310+
echo "* Generating pioarduino manifest file..."
311311
pushd $IDF_PATH
312312
ibr=$(git describe --all 2>/dev/null)
313313
ic=$(git -C "$IDF_PATH" rev-parse --short HEAD)
314314
popd
315-
python3 ./tools/gen_platformio_manifest.py -o "$TOOLS_JSON_OUT/" -s "$ibr" -c "$ic"
315+
python3 ./tools/gen_pioarduino_manifest.py -o "$TOOLS_JSON_OUT/" -s "$ibr" -c "$ic"
316316
if [ $? -ne 0 ]; then exit 1; fi
317317
fi
318318

Diff for: components/arduino_tinyusb/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ if(CONFIG_TINYUSB_ENABLED)
2727
# espressif:
2828
"${COMPONENT_DIR}/src/dcd_dwc2.c"
2929
# tusb:
30-
#"{COMPONENT_DIR}/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c"
30+
#"${COMPONENT_DIR}/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c"
31+
"${COMPONENT_DIR}/tinyusb/src/portable/synopsys/dwc2/dwc2_common.c"
3132
"${COMPONENT_DIR}/tinyusb/src/class/cdc/cdc_device.c"
3233
"${COMPONENT_DIR}/tinyusb/src/class/hid/hid_device.c"
3334
"${COMPONENT_DIR}/tinyusb/src/class/midi/midi_device.c"

Diff for: components/arduino_tinyusb/Kconfig.projbuild

+18-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ menu "Arduino TinyUSB"
44
config TINYUSB_ENABLED
55
bool "Enable TinyUSB driver"
66
default y
7-
depends on IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
7+
depends on IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32P4
88
select FREERTOS_SUPPORT_STATIC_ALLOCATION
99
select FREERTOS_USE_AUTHENTIC_INCLUDE_PATHS
1010
help
@@ -28,14 +28,16 @@ menu "Arduino TinyUSB"
2828

2929
config TINYUSB_CDC_RX_BUFSIZE
3030
int "CDC FIFO size of RX"
31-
default 64
31+
default 64 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
32+
default 512 if IDF_TARGET_ESP32P4
3233
depends on TINYUSB_CDC_ENABLED
3334
help
3435
CDC FIFO size of RX
3536

3637
config TINYUSB_CDC_TX_BUFSIZE
3738
int "CDC FIFO size of TX"
38-
default 64
39+
default 64 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
40+
default 512 if IDF_TARGET_ESP32P4
3941
depends on TINYUSB_CDC_ENABLED
4042
help
4143
CDC FIFO size of TX
@@ -86,7 +88,8 @@ menu "Arduino TinyUSB"
8688

8789
config TINYUSB_HID_BUFSIZE
8890
int "HID Buffer size"
89-
default 64
91+
default 64 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
92+
default 512 if IDF_TARGET_ESP32P4
9093
depends on TINYUSB_HID_ENABLED
9194
help
9295
HID Buffer size. Should be sufficient to hold ID (if any) + Data
@@ -111,14 +114,16 @@ menu "Arduino TinyUSB"
111114

112115
config TINYUSB_MIDI_RX_BUFSIZE
113116
int "MIDI FIFO size of RX"
114-
default 64
117+
default 64 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
118+
default 512 if IDF_TARGET_ESP32P4
115119
depends on TINYUSB_MIDI_ENABLED
116120
help
117121
MIDI FIFO size of RX
118122

119123
config TINYUSB_MIDI_TX_BUFSIZE
120124
int "MIDI FIFO size of TX"
121-
default 64
125+
default 64 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
126+
default 512 if IDF_TARGET_ESP32P4
122127
depends on TINYUSB_MIDI_ENABLED
123128
help
124129
MIDI FIFO size of TX
@@ -143,8 +148,9 @@ menu "Arduino TinyUSB"
143148

144149
config TINYUSB_VIDEO_STREAMING_BUFSIZE
145150
int "VIDEO streaming endpoint size"
146-
range 0 64
147-
default 64
151+
range 0 512
152+
default 64 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
153+
default 512 if IDF_TARGET_ESP32P4
148154
depends on TINYUSB_VIDEO_ENABLED
149155
help
150156
VIDEO streaming endpoint size
@@ -219,14 +225,16 @@ menu "Arduino TinyUSB"
219225

220226
config TINYUSB_VENDOR_RX_BUFSIZE
221227
int "VENDOR FIFO size of RX"
222-
default 64
228+
default 64 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
229+
default 512 if IDF_TARGET_ESP32P4
223230
depends on TINYUSB_VENDOR_ENABLED
224231
help
225232
VENDOR FIFO size of RX
226233

227234
config TINYUSB_VENDOR_TX_BUFSIZE
228235
int "VENDOR FIFO size of TX"
229-
default 64
236+
default 64 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
237+
default 512 if IDF_TARGET_ESP32P4
230238
depends on TINYUSB_VENDOR_ENABLED
231239
help
232240
VENDOR FIFO size of TX

Diff for: components/arduino_tinyusb/include/tusb_config.h

+7
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,18 @@ extern "C" {
100100
# define CFG_TUSB_MEM_ALIGN TU_ATTR_ALIGNED(4)
101101
#endif
102102

103+
#if CONFIG_IDF_TARGET_ESP32P4
104+
#define CFG_TUD_MAX_SPEED OPT_MODE_HIGH_SPEED
105+
#else
106+
#define CFG_TUD_MAX_SPEED OPT_MODE_FULL_SPEED
107+
#endif
108+
103109
/* */
104110
/* DRIVER CONFIGURATION */
105111
/* */
106112

107113
#define CFG_TUD_MAINTASK_SIZE 4096
114+
#define CFG_TUD_ENDOINT_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
108115
#define CFG_TUD_ENDOINT0_SIZE 64
109116

110117
// Enabled Drivers

Diff for: components/arduino_tinyusb/patches/dcd_dwc2.patch

+28-27
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
--- a/components/arduino_tinyusb/src/dcd_dwc2.c 2024-10-02 12:17:40.000000000 +0300
22
+++ b/components/arduino_tinyusb/src/dcd_dwc2.c 2024-10-02 12:19:48.000000000 +0300
3-
@@ -316,6 +316,16 @@
3+
@@ -243,6 +243,17 @@
44
//--------------------------------------------------------------------
55
// Endpoint
66
//--------------------------------------------------------------------
7-
+#if defined(TUP_USBIP_DWC2_ESP32)
7+
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
88
+// Keep count of how many FIFOs are in use
99
+static uint8_t _allocated_fifos = 1; //FIFO0 is always in use
1010
+
@@ -14,68 +14,69 @@
1414
+ return 0;
1515
+}
1616
+#endif
17-
18-
static void edpt_activate(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc) {
17+
+
18+
static void edpt_activate(uint8_t rhport, const tusb_desc_endpoint_t* p_endpoint_desc) {
1919
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
20-
@@ -336,7 +346,18 @@
21-
dwc2->epout[epnum].doepctl = dxepctl;
22-
dwc2->daintmsk |= TU_BIT(DAINTMSK_OEPM_Pos + epnum);
23-
} else {
24-
- dwc2->epin[epnum].diepctl = dxepctl | (epnum << DIEPCTL_TXFNUM_Pos);
20+
const uint8_t epnum = tu_edpt_number(p_endpoint_desc->bEndpointAddress);
21+
@@ -266,7 +277,18 @@
22+
depctl.bm.set_data0_iso_even = 1;
23+
}
24+
if (dir == TUSB_DIR_IN) {
25+
- depctl.bm.tx_fifo_num = epnum;
26+
+ //depctl.bm.tx_fifo_num = epnum;
2527
+ uint8_t fifo_num = epnum;
26-
+#if defined(TUP_USBIP_DWC2_ESP32)
28+
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
2729
+ // Special Case for EP5, which is used by CDC but not actually called by the driver
2830
+ // we can give it a fake FIFO
2931
+ if (epnum == 5) {
3032
+ fifo_num = epnum;
3133
+ } else {
3234
+ fifo_num = get_free_fifo();
3335
+ }
34-
+ //TU_ASSERT(fifo_num != 0);
3536
+#endif
36-
+ dwc2->epin[epnum].diepctl = dxepctl | (fifo_num << DIEPCTL_TXFNUM_Pos);
37-
dwc2->daintmsk |= TU_BIT(DAINTMSK_IEPM_Pos + epnum);
37+
+ depctl.bm.tx_fifo_num = fifo_num;
3838
}
39-
}
40-
@@ -850,6 +871,10 @@
41-
xfer_status[n][TUSB_DIR_IN].max_size = 0;
39+
40+
dwc2_dep_t* dep = &dwc2->ep[dir == TUSB_DIR_IN ? 0 : 1][epnum];
41+
@@ -557,6 +579,10 @@
42+
}
4243
}
4344

44-
+#if defined(TUP_USBIP_DWC2_ESP32)
45+
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
4546
+ _allocated_fifos = 1;
4647
+#endif
4748
+
4849
dfifo_flush_tx(dwc2, 0x10); // all tx fifo
4950
dfifo_flush_rx(dwc2);
5051

51-
@@ -1204,6 +1229,9 @@
52-
if (int_status & GINTSTS_USBRST) {
52+
@@ -997,6 +1023,9 @@
53+
if (gintsts & GINTSTS_USBRST) {
5354
// USBRST is start of reset.
5455
dwc2->gintsts = GINTSTS_USBRST;
55-
+#if defined(TUP_USBIP_DWC2_ESP32)
56+
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
5657
+ _allocated_fifos = 1;
5758
+#endif
58-
bus_reset(rhport);
59+
handle_bus_reset(rhport);
5960
}
6061

61-
@@ -1235,7 +1263,11 @@
62+
@@ -1008,7 +1037,11 @@
6263

63-
if (int_status & GINTSTS_USBSUSP) {
64+
if (gintsts & GINTSTS_USBSUSP) {
6465
dwc2->gintsts = GINTSTS_USBSUSP;
6566
- dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
6667
+ //dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
6768
+ dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true);
68-
+#if defined(TUP_USBIP_DWC2_ESP32)
69+
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
6970
+ _allocated_fifos = 1;
7071
+#endif
7172
}
7273

73-
if (int_status & GINTSTS_WKUINT) {
74-
@@ -1252,6 +1284,9 @@
74+
if (gintsts & GINTSTS_WKUINT) {
75+
@@ -1025,6 +1058,9 @@
7576

7677
if (otg_int & GOTGINT_SEDET) {
7778
dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true);
78-
+#if defined(TUP_USBIP_DWC2_ESP32)
79+
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
7980
+ _allocated_fifos = 1;
8081
+#endif
8182
}

0 commit comments

Comments
 (0)