Skip to content

Commit b0f1405

Browse files
committed
Rework the lib-builder for ESP-IDF v5.1
1 parent e18eecd commit b0f1405

13 files changed

+151
-72
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ sdkconfig
1818
sdkconfig.old
1919
version.txt
2020
dependencies.lock
21+
managed_components/

Diff for: build.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ COPY_OUT=0
1717
DEPLOY_OUT=0
1818

1919
function print_help() {
20-
echo "Usage: build.sh [-s] [-A <arduino_branch>] [-I <idf_branch>] [-i <idf_commit>] [-c <path>] [-t <target>] [-b <build|menuconfig|idf_libs|copy_bootloader|mem_variant>] [config ...]"
20+
echo "Usage: build.sh [-s] [-A <arduino_branch>] [-I <idf_branch>] [-i <idf_commit>] [-c <path>] [-t <target>] [-b <build|menuconfig|reconfigure|idf_libs|copy_bootloader|mem_variant>] [config ...]"
2121
echo " -s Skip installing/updating of ESP-IDF and all components"
2222
echo " -A Set which branch of arduino-esp32 to be used for compilation"
2323
echo " -I Set which branch of ESP-IDF to be used for compilation"
@@ -58,6 +58,7 @@ while getopts ":A:I:i:c:t:b:sd" opt; do
5858
b=$OPTARG
5959
if [ "$b" != "build" ] &&
6060
[ "$b" != "menuconfig" ] &&
61+
[ "$b" != "reconfigure" ] &&
6162
[ "$b" != "idf_libs" ] &&
6263
[ "$b" != "copy_bootloader" ] &&
6364
[ "$b" != "mem_variant" ]; then
@@ -121,6 +122,9 @@ if [ "$BUILD_TYPE" != "all" ]; then
121122
fi
122123

123124
rm -rf build sdkconfig out
125+
echo "* Reconfigure Project"
126+
idf.py reconfigure
127+
rm -rf build sdkconfig
124128

125129
# Add components version info
126130
mkdir -p "$AR_TOOLS/sdk" && rm -rf version.txt && rm -rf "$AR_TOOLS/sdk/versions.txt"

Diff for: components/arduino_tinyusb/CMakeLists.txt

+39-31
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,22 @@
1-
idf_component_register(REQUIRES esp_rom freertos soc PRIV_REQUIRES arduino main)
2-
31
if(CONFIG_TINYUSB_ENABLED)
42

53
### variables ###
64
#################
7-
# if(IDF_TARGET STREQUAL "esp32s2")
5+
6+
if(IDF_TARGET STREQUAL "esp32s2")
87
set(compile_options
98
"-DCFG_TUSB_MCU=OPT_MCU_ESP32S2"
109
"-DCFG_TUSB_DEBUG=${CONFIG_TINYUSB_DEBUG_LEVEL}"
1110
"-Wno-type-limits" # needed for the vanila tinyusb with turned off classes
1211
)
13-
# elseif(IDF_TARGET STREQUAL "esp32s3")
14-
# set(compile_options
15-
# "-DCFG_TUSB_MCU=OPT_MCU_ESP32S2"
16-
# "-DCFG_TUSB_DEBUG=${CONFIG_TINYUSB_DEBUG_LEVEL}"
17-
# "-Wno-type-limits" # needed for the vanila tinyusb with turned off classes
18-
# )
19-
# endif()
20-
idf_component_get_property(FREERTOS_ORIG_INCLUDE_PATH freertos
21-
ORIG_INCLUDE_PATH)
22-
set(includes_private
23-
# tusb:
24-
"${COMPONENT_DIR}/tinyusb/hw/bsp/"
25-
"${COMPONENT_DIR}/tinyusb/src/"
26-
"${COMPONENT_DIR}/tinyusb/src/device"
27-
)
12+
elseif(IDF_TARGET STREQUAL "esp32s3")
13+
set(compile_options
14+
"-DCFG_TUSB_MCU=OPT_MCU_ESP32S3"
15+
"-DCFG_TUSB_DEBUG=${CONFIG_TINYUSB_DEBUG_LEVEL}"
16+
"-Wno-type-limits" # needed for the vanila tinyusb with turned off classes
17+
)
18+
endif()
2819

29-
set(includes_public
30-
# tusb:
31-
"${FREERTOS_ORIG_INCLUDE_PATH}"
32-
"${COMPONENT_DIR}/tinyusb/src/"
33-
# espressif:
34-
"${COMPONENT_DIR}/include")
3520
set(srcs
3621
# espressif:
3722
"${COMPONENT_DIR}/src/dcd_esp32sx.c"
@@ -49,14 +34,37 @@ if(CONFIG_TINYUSB_ENABLED)
4934
"${COMPONENT_DIR}/tinyusb/src/device/usbd.c"
5035
"${COMPONENT_DIR}/tinyusb/src/tusb.c")
5136

37+
set(includes_private
38+
# tusb:
39+
"${COMPONENT_DIR}/tinyusb/hw/bsp/"
40+
"${COMPONENT_DIR}/tinyusb/src/"
41+
"${COMPONENT_DIR}/tinyusb/src/device"
42+
)
43+
44+
idf_component_get_property(FREERTOS_ORIG_INCLUDE_PATH freertos
45+
ORIG_INCLUDE_PATH)
46+
set(includes_public
47+
# tusb:
48+
"${FREERTOS_ORIG_INCLUDE_PATH}"
49+
"${COMPONENT_DIR}/tinyusb/src/"
50+
# espressif:
51+
"${COMPONENT_DIR}/include")
52+
53+
set(requires esp_rom freertos soc)
54+
set(priv_requires arduino main)
5255
### tinyusb lib ###
5356
###################
54-
add_library(arduino_tinyusb STATIC ${srcs})
55-
target_include_directories(
56-
arduino_tinyusb
57-
PUBLIC ${includes_public}
58-
PRIVATE ${includes_private})
59-
target_compile_options(arduino_tinyusb PRIVATE ${compile_options})
60-
target_link_libraries(${COMPONENT_TARGET} INTERFACE arduino_tinyusb)
57+
idf_component_register(INCLUDE_DIRS ${includes_public} PRIV_INCLUDE_DIRS ${includes_private} SRCS ${srcs} REQUIRES ${requires} PRIV_REQUIRES ${priv_requires})
58+
# add_library(${COMPONENT_TARGET} STATIC ${srcs})
59+
# target_include_directories(
60+
# ${COMPONENT_TARGET}
61+
# PUBLIC ${includes_public}
62+
# PRIVATE ${includes_private})
63+
target_compile_options(${COMPONENT_TARGET} PRIVATE ${compile_options})
64+
#target_link_libraries(${COMPONENT_TARGET} INTERFACE ${COMPONENT_TARGET})
65+
66+
else()
67+
68+
idf_component_register()
6169

6270
endif()

Diff for: components/arduino_tinyusb/src/dcd_esp32sx.c

+26-3
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,16 @@
2828

2929
#include "tusb_option.h"
3030

31-
#if (((CFG_TUSB_MCU == OPT_MCU_ESP32S2) || (CFG_TUSB_MCU == OPT_MCU_ESP32S3)) && TUSB_OPT_DEVICE_ENABLED)
31+
#if (((CFG_TUSB_MCU == OPT_MCU_ESP32S2) || (CFG_TUSB_MCU == OPT_MCU_ESP32S3)) && CFG_TUD_ENABLED)
3232

3333
// Espressif
34-
#include "driver/periph_ctrl.h"
3534
#include "freertos/xtensa_api.h"
3635
#include "esp_intr_alloc.h"
3736
#include "esp_log.h"
38-
#include "driver/gpio.h"
3937
#include "soc/dport_reg.h"
4038
#include "soc/gpio_sig_map.h"
4139
#include "soc/usb_periph.h"
40+
#include "soc/periph_defs.h" // for interrupt source
4241

4342
#include "device/dcd.h"
4443

@@ -60,6 +59,7 @@ typedef struct {
6059
uint16_t queued_len;
6160
uint16_t max_size;
6261
bool short_packet;
62+
uint8_t interval;
6363
} xfer_ctl_t;
6464

6565
static const char *TAG = "TUSB:DCD";
@@ -284,6 +284,14 @@ void dcd_disconnect(uint8_t rhport)
284284
USB0.dctl |= USB_SFTDISCON_M;
285285
}
286286

287+
void dcd_sof_enable(uint8_t rhport, bool en)
288+
{
289+
(void) rhport;
290+
(void) en;
291+
292+
// TODO implement later
293+
}
294+
287295
/*------------------------------------------------------------------*/
288296
/* DCD Endpoint port
289297
*------------------------------------------------------------------*/
@@ -303,6 +311,7 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const *desc_edpt)
303311

304312
xfer_ctl_t *xfer = XFER_CTL_BASE(epnum, dir);
305313
xfer->max_size = tu_edpt_packet_size(desc_edpt);
314+
xfer->interval = desc_edpt->bInterval;
306315

307316
if (dir == TUSB_DIR_OUT) {
308317
out_ep[epnum].doepctl &= ~(USB_D_EPTYPE0_M | USB_D_MPS0_M);
@@ -423,6 +432,13 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t to
423432
USB0.in_ep_reg[epnum].dieptsiz = (num_packets << USB_D_PKTCNT0_S) | total_bytes;
424433
USB0.in_ep_reg[epnum].diepctl |= USB_D_EPENA1_M | USB_D_CNAK1_M; // Enable | CNAK
425434

435+
// For ISO endpoint with interval=1 set correct DATA0/DATA1 bit for next frame
436+
if ((USB0.in_ep_reg[epnum].diepctl & USB_D_EPTYPE0_M) == (1 << USB_D_EPTYPE1_S) && xfer->interval == 1) {
437+
// Take odd/even bit from frame counter.
438+
uint32_t const odd_frame_now = (USB0.dsts & (1u << USB_SOFFN_S));
439+
USB0.in_ep_reg[epnum].diepctl |= (odd_frame_now ? USB_DI_SETD0PID1 : USB_DI_SETD1PID1);
440+
}
441+
426442
// Enable fifo empty interrupt only if there are something to put in the fifo.
427443
if(total_bytes != 0) {
428444
USB0.dtknqr4_fifoemptymsk |= (1 << epnum);
@@ -431,6 +447,13 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t to
431447
// Each complete packet for OUT xfers triggers XFRC.
432448
USB0.out_ep_reg[epnum].doeptsiz |= USB_PKTCNT0_M | ((xfer->max_size & USB_XFERSIZE0_V) << USB_XFERSIZE0_S);
433449
USB0.out_ep_reg[epnum].doepctl |= USB_EPENA0_M | USB_CNAK0_M;
450+
451+
// For ISO endpoint with interval=1 set correct DATA0/DATA1 bit for next frame
452+
if ((USB0.out_ep_reg[epnum].doepctl & USB_D_EPTYPE0_M) == (1 << USB_D_EPTYPE1_S) && xfer->interval == 1) {
453+
// Take odd/even bit from frame counter.
454+
uint32_t const odd_frame_now = (USB0.dsts & (1u << USB_SOFFN_S));
455+
USB0.out_ep_reg[epnum].doepctl |= (odd_frame_now ? USB_DO_SETD0PID1 : USB_DO_SETD1PID1);
456+
}
434457
}
435458
return true;
436459
}

Diff for: configs/defconfig.common

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ CONFIG_FATFS_API_ENCODING_UTF_8=y
3737
# CONFIG_FMB_CONTROLLER_SLAVE_ID_SUPPORT is not set
3838
CONFIG_FMB_TIMER_PORT_ENABLED=y
3939
CONFIG_FREERTOS_HZ=1000
40+
CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY=y
4041
# CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION is not set
4142
CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=1024
4243
CONFIG_HEAP_POISONING_LIGHT=y

Diff for: configs/defconfig.esp32

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ CONFIG_BT_SPP_ENABLED=y
88
CONFIG_BT_HFP_ENABLE=y
99
CONFIG_BT_STACK_NO_LOG=y
1010
CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY=y
11-
CONFIG_ESP32_SPIRAM_SUPPORT=y
11+
CONFIG_SPIRAM=y
1212
CONFIG_SPIRAM_OCCUPY_HSPI_HOST=y
13-
CONFIG_ESP32_ULP_COPROC_ENABLED=y
14-
CONFIG_ESP32_XTAL_FREQ_AUTO=y
13+
CONFIG_ULP_COPROC_ENABLED=y
14+
CONFIG_XTAL_FREQ_AUTO=y
1515
# CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 is not set
1616
CONFIG_FREERTOS_FPU_IN_ISR=y
1717
# CONFIG_USE_WAKENET is not set

Diff for: configs/defconfig.esp32c3

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
CONFIG_BT_BLE_BLUFI_ENABLE=y
2-
CONFIG_ESP32C3_RTC_CLK_CAL_CYCLES=576
2+
CONFIG_RTC_CLK_CAL_CYCLES=576
33
# CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 is not set
44
CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=2304

Diff for: configs/defconfig.esp32s2

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y
2-
CONFIG_ESP32S2_DEFAULT_CPU_FREQ_240=y
3-
CONFIG_ESP32S2_SPIRAM_SUPPORT=y
2+
CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y
3+
CONFIG_SPIRAM=y
44
CONFIG_ESP32S2_KEEP_USB_ALIVE=y
55
# CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 is not set
66
# CONFIG_USE_WAKENET is not set

Diff for: configs/defconfig.esp32s3

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y
2-
CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y
3-
CONFIG_ESP32S3_SPIRAM_SUPPORT=y
4-
CONFIG_ESP32S3_RTC_CLK_CAL_CYCLES=576
2+
CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y
3+
CONFIG_SPIRAM=y
4+
CONFIG_RTC_CLK_CAL_CYCLES=576
55
CONFIG_ESP32S3_UNIVERSAL_MAC_ADDRESSES_TWO=y
66
# CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND is not set
77
# CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 is not set

Diff for: main/idf_component.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
dependencies:
2+
# Required IDF version
3+
idf: ">=5.1"
4+
5+
mdns: "^1.0.7"
6+
# nghttp: "^1.50.0"
7+
# esp_jpeg: "^1.0.4"
8+
# esp-dsp: "^1.2.0"
9+
# esp-sr: "^1.0.3"
10+
# esp32-camera: "^2.0.3"
11+
# esp-dl:
12+
# git: https://github.com/espressif/esp-dl.git
13+
# arduino:
14+
# path: components/arduino
15+
16+
# # Defining a dependency from the registry:
17+
# # https://components.espressif.com/component/example/cmp
18+
# example/cmp: "^3.3.3" # Automatically update minor releases
19+
#
20+
# # Other ways to define dependencies
21+
#
22+
# # For components maintained by Espressif only name can be used.
23+
# # Same as `espressif/cmp`
24+
# component: "~1.0.0" # Automatically update bugfix releases
25+
#
26+
# # Or in a longer form with extra parameters
27+
# component2:
28+
# version: ">=2.0.0"
29+
#
30+
# # For transient dependencies `public` flag can be set.
31+
# # `public` flag doesn't have an effect for the `main` component.
32+
# # All dependencies of `main` are public by default.
33+
# public: true
34+
#
35+
# # For components hosted on non-default registry:
36+
# service_url: "https://componentregistry.company.com"
37+
#
38+
# # For components in git repository:
39+
# test_component:
40+
# path: test_component
41+
# git: ssh://[email protected]/user/components.git
42+
#
43+
# # For test projects during component development
44+
# # components can be used from a local directory
45+
# # with relative or absolute path
46+
# some_local_component:
47+
# path: ../../projects/component

Diff for: tools/config.sh

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if [ -z $IDF_PATH ]; then
66
fi
77

88
if [ -z $IDF_BRANCH ]; then
9-
IDF_BRANCH="release/v4.4"
9+
IDF_BRANCH="master"
1010
fi
1111

1212
if [ -z $AR_PR_TARGET_BRANCH ]; then
@@ -24,9 +24,6 @@ if [ -z $IDF_TARGET ]; then
2424
fi
2525
fi
2626

27-
IDF_COMPS="$IDF_PATH/components"
28-
IDF_TOOLCHAIN="xtensa-$IDF_TARGET-elf"
29-
3027
# Owner of the target ESP32 Arduino repository
3128
AR_USER="espressif"
3229

Diff for: tools/copy-libs.sh

+8-6
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ for item in "${@:2:${#@}-5}"; do
9595
elif [ "$prefix" = "-O" ]; then
9696
PIO_CC_FLAGS+="$item "
9797
elif [[ "$item" != "-Wall" && "$item" != "-Werror=all" && "$item" != "-Wextra" ]]; then
98-
if [[ "${item:0:23}" != "-mfix-esp32-psram-cache" && "${item:0:18}" != "-fmacro-prefix-map" ]]; then
98+
if [[ "${item:0:23}" != "-mfix-esp32-psram-cache" && "${item:0:18}" != "-fmacro-prefix-map" && "${item:0:20}" != "-fdiagnostics-color=" ]]; then
9999
C_FLAGS+="$item "
100100
fi
101101
fi
@@ -109,7 +109,7 @@ set -- $str
109109
for item in "${@:2:${#@}-5}"; do
110110
prefix="${item:0:2}"
111111
if [[ "$prefix" != "-I" && "$prefix" != "-D" && "$item" != "-Wall" && "$item" != "-Werror=all" && "$item" != "-Wextra" && "$prefix" != "-O" ]]; then
112-
if [[ "${item:0:23}" != "-mfix-esp32-psram-cache" && "${item:0:18}" != "-fmacro-prefix-map" ]]; then
112+
if [[ "${item:0:23}" != "-mfix-esp32-psram-cache" && "${item:0:18}" != "-fmacro-prefix-map" && "${item:0:20}" != "-fdiagnostics-color=" ]]; then
113113
AS_FLAGS+="$item "
114114
if [[ $C_FLAGS == *"$item"* ]]; then
115115
PIO_CC_FLAGS+="$item "
@@ -128,7 +128,7 @@ set -- $str
128128
for item in "${@:2:${#@}-5}"; do
129129
prefix="${item:0:2}"
130130
if [[ "$prefix" != "-I" && "$prefix" != "-D" && "$item" != "-Wall" && "$item" != "-Werror=all" && "$item" != "-Wextra" && "$prefix" != "-O" ]]; then
131-
if [[ "${item:0:23}" != "-mfix-esp32-psram-cache" && "${item:0:18}" != "-fmacro-prefix-map" ]]; then
131+
if [[ "${item:0:23}" != "-mfix-esp32-psram-cache" && "${item:0:18}" != "-fmacro-prefix-map" && "${item:0:20}" != "-fdiagnostics-color=" ]]; then
132132
CPP_FLAGS+="$item "
133133
if [[ $PIO_CC_FLAGS != *"$item"* ]]; then
134134
PIO_CXX_FLAGS+="$item "
@@ -155,13 +155,15 @@ else
155155
libs="${libs:19:${#libs}-1}"
156156
flags=`cat build/build.ninja | grep LINK_FLAGS`
157157
flags="${flags:15:${#flags}-1}"
158+
paths=`cat build/build.ninja | grep LINK_PATH`
159+
paths="${paths:14:${#paths}-1}"
158160
if [ "$IDF_TARGET" = "esp32" ]; then
159161
flags="-Wno-frame-address $flags"
160162
fi
161163
if [ "$IDF_TARGET" != "esp32c3" ]; then
162164
flags="-mlongcalls $flags"
163165
fi
164-
str="$flags $libs"
166+
str="$flags $libs $paths"
165167
fi
166168
if [ "$IDF_TARGET" = "esp32" ]; then
167169
LD_SCRIPTS+="-T esp32.rom.redefined.ld "
@@ -362,7 +364,7 @@ for item; do
362364
if [[ "$fname" == "main" && "$dname" == "esp32-arduino-lib-builder" ]]; then
363365
continue
364366
fi
365-
while [[ "$dname" != "components" && "$dname" != "build" ]]; do
367+
while [[ "$dname" != "components" && "$dname" != "managed_components" && "$dname" != "build" ]]; do
366368
ipath=`dirname "$ipath"`
367369
fname=`basename "$ipath"`
368370
dname=`basename $(dirname "$ipath")`
@@ -482,7 +484,7 @@ rm -rf platform_start.txt platform_mid.txt 1platform_mid.txt
482484
cp -f "sdkconfig" "$AR_SDK/sdkconfig"
483485

484486
# gen_esp32part.py
485-
cp "$IDF_COMPS/partition_table/gen_esp32part.py" "$AR_GEN_PART_PY"
487+
cp "$IDF_PATH/components/partition_table/gen_esp32part.py" "$AR_GEN_PART_PY"
486488

487489
# copy precompiled libs (if we need them)
488490
function copy_precompiled_lib(){

0 commit comments

Comments
 (0)