Skip to content

Esp idf v5.1 #52

New issue

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

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

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ sdkconfig
sdkconfig.old
version.txt
dependencies.lock
managed_components/
12 changes: 11 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ COPY_OUT=0
DEPLOY_OUT=0

function print_help() {
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 ...]"
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 ...]"
echo " -s Skip installing/updating of ESP-IDF and all components"
echo " -A Set which branch of arduino-esp32 to be used for compilation"
echo " -I Set which branch of ESP-IDF to be used for compilation"
Expand Down Expand Up @@ -58,6 +58,7 @@ while getopts ":A:I:i:c:t:b:sd" opt; do
b=$OPTARG
if [ "$b" != "build" ] &&
[ "$b" != "menuconfig" ] &&
[ "$b" != "reconfigure" ] &&
[ "$b" != "idf_libs" ] &&
[ "$b" != "copy_bootloader" ] &&
[ "$b" != "mem_variant" ]; then
Expand Down Expand Up @@ -121,6 +122,9 @@ if [ "$BUILD_TYPE" != "all" ]; then
fi

rm -rf build sdkconfig out
echo "* Reconfigure Project"
idf.py reconfigure
rm -rf build sdkconfig

# Add components version info
mkdir -p "$AR_TOOLS/sdk" && rm -rf version.txt && rm -rf "$AR_TOOLS/sdk/versions.txt"
Expand Down Expand Up @@ -187,6 +191,12 @@ for target_json in `jq -c '.targets[]' configs/builds.json`; do
done
done

# update package_esp32_index.template.json
if [ "$BUILD_TYPE" = "all" ]; then
python3 ./tools/gen_tools_json.py -i "$IDF_PATH" -j "$AR_COMPS/arduino/package/package_esp32_index.template.json" -o "$AR_OUT/"
if [ $? -ne 0 ]; then exit 1; fi
fi

# archive the build
if [ "$BUILD_TYPE" = "all" ]; then
./tools/archive-build.sh
Expand Down
70 changes: 39 additions & 31 deletions components/arduino_tinyusb/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,37 +1,22 @@
idf_component_register(REQUIRES esp_rom freertos soc PRIV_REQUIRES arduino main)

if(CONFIG_TINYUSB_ENABLED)

### variables ###
#################
# if(IDF_TARGET STREQUAL "esp32s2")

if(IDF_TARGET STREQUAL "esp32s2")
set(compile_options
"-DCFG_TUSB_MCU=OPT_MCU_ESP32S2"
"-DCFG_TUSB_DEBUG=${CONFIG_TINYUSB_DEBUG_LEVEL}"
"-Wno-type-limits" # needed for the vanila tinyusb with turned off classes
)
# elseif(IDF_TARGET STREQUAL "esp32s3")
# set(compile_options
# "-DCFG_TUSB_MCU=OPT_MCU_ESP32S2"
# "-DCFG_TUSB_DEBUG=${CONFIG_TINYUSB_DEBUG_LEVEL}"
# "-Wno-type-limits" # needed for the vanila tinyusb with turned off classes
# )
# endif()
idf_component_get_property(FREERTOS_ORIG_INCLUDE_PATH freertos
ORIG_INCLUDE_PATH)
set(includes_private
# tusb:
"${COMPONENT_DIR}/tinyusb/hw/bsp/"
"${COMPONENT_DIR}/tinyusb/src/"
"${COMPONENT_DIR}/tinyusb/src/device"
)
elseif(IDF_TARGET STREQUAL "esp32s3")
set(compile_options
"-DCFG_TUSB_MCU=OPT_MCU_ESP32S3"
"-DCFG_TUSB_DEBUG=${CONFIG_TINYUSB_DEBUG_LEVEL}"
"-Wno-type-limits" # needed for the vanila tinyusb with turned off classes
)
endif()

set(includes_public
# tusb:
"${FREERTOS_ORIG_INCLUDE_PATH}"
"${COMPONENT_DIR}/tinyusb/src/"
# espressif:
"${COMPONENT_DIR}/include")
set(srcs
# espressif:
"${COMPONENT_DIR}/src/dcd_esp32sx.c"
Expand All @@ -49,14 +34,37 @@ if(CONFIG_TINYUSB_ENABLED)
"${COMPONENT_DIR}/tinyusb/src/device/usbd.c"
"${COMPONENT_DIR}/tinyusb/src/tusb.c")

set(includes_private
# tusb:
"${COMPONENT_DIR}/tinyusb/hw/bsp/"
"${COMPONENT_DIR}/tinyusb/src/"
"${COMPONENT_DIR}/tinyusb/src/device"
)

idf_component_get_property(FREERTOS_ORIG_INCLUDE_PATH freertos
ORIG_INCLUDE_PATH)
set(includes_public
# tusb:
"${FREERTOS_ORIG_INCLUDE_PATH}"
"${COMPONENT_DIR}/tinyusb/src/"
# espressif:
"${COMPONENT_DIR}/include")

set(requires esp_rom freertos soc)
set(priv_requires arduino main)
### tinyusb lib ###
###################
add_library(arduino_tinyusb STATIC ${srcs})
target_include_directories(
arduino_tinyusb
PUBLIC ${includes_public}
PRIVATE ${includes_private})
target_compile_options(arduino_tinyusb PRIVATE ${compile_options})
target_link_libraries(${COMPONENT_TARGET} INTERFACE arduino_tinyusb)
idf_component_register(INCLUDE_DIRS ${includes_public} PRIV_INCLUDE_DIRS ${includes_private} SRCS ${srcs} REQUIRES ${requires} PRIV_REQUIRES ${priv_requires})
# add_library(${COMPONENT_TARGET} STATIC ${srcs})
# target_include_directories(
# ${COMPONENT_TARGET}
# PUBLIC ${includes_public}
# PRIVATE ${includes_private})
target_compile_options(${COMPONENT_TARGET} PRIVATE ${compile_options})
#target_link_libraries(${COMPONENT_TARGET} INTERFACE ${COMPONENT_TARGET})

else()

idf_component_register()

endif()
29 changes: 26 additions & 3 deletions components/arduino_tinyusb/src/dcd_esp32sx.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,16 @@

#include "tusb_option.h"

#if (((CFG_TUSB_MCU == OPT_MCU_ESP32S2) || (CFG_TUSB_MCU == OPT_MCU_ESP32S3)) && TUSB_OPT_DEVICE_ENABLED)
#if (((CFG_TUSB_MCU == OPT_MCU_ESP32S2) || (CFG_TUSB_MCU == OPT_MCU_ESP32S3)) && CFG_TUD_ENABLED)

// Espressif
#include "driver/periph_ctrl.h"
#include "freertos/xtensa_api.h"
#include "esp_intr_alloc.h"
#include "esp_log.h"
#include "driver/gpio.h"
#include "soc/dport_reg.h"
#include "soc/gpio_sig_map.h"
#include "soc/usb_periph.h"
#include "soc/periph_defs.h" // for interrupt source

#include "device/dcd.h"

Expand All @@ -60,6 +59,7 @@ typedef struct {
uint16_t queued_len;
uint16_t max_size;
bool short_packet;
uint8_t interval;
} xfer_ctl_t;

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

void dcd_sof_enable(uint8_t rhport, bool en)
{
(void) rhport;
(void) en;

// TODO implement later
}

/*------------------------------------------------------------------*/
/* DCD Endpoint port
*------------------------------------------------------------------*/
Expand All @@ -303,6 +311,7 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const *desc_edpt)

xfer_ctl_t *xfer = XFER_CTL_BASE(epnum, dir);
xfer->max_size = tu_edpt_packet_size(desc_edpt);
xfer->interval = desc_edpt->bInterval;

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

// For ISO endpoint with interval=1 set correct DATA0/DATA1 bit for next frame
if ((USB0.in_ep_reg[epnum].diepctl & USB_D_EPTYPE0_M) == (1 << USB_D_EPTYPE1_S) && xfer->interval == 1) {
// Take odd/even bit from frame counter.
uint32_t const odd_frame_now = (USB0.dsts & (1u << USB_SOFFN_S));
USB0.in_ep_reg[epnum].diepctl |= (odd_frame_now ? USB_DI_SETD0PID1 : USB_DI_SETD1PID1);
}

// Enable fifo empty interrupt only if there are something to put in the fifo.
if(total_bytes != 0) {
USB0.dtknqr4_fifoemptymsk |= (1 << epnum);
Expand All @@ -431,6 +447,13 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t to
// Each complete packet for OUT xfers triggers XFRC.
USB0.out_ep_reg[epnum].doeptsiz |= USB_PKTCNT0_M | ((xfer->max_size & USB_XFERSIZE0_V) << USB_XFERSIZE0_S);
USB0.out_ep_reg[epnum].doepctl |= USB_EPENA0_M | USB_CNAK0_M;

// For ISO endpoint with interval=1 set correct DATA0/DATA1 bit for next frame
if ((USB0.out_ep_reg[epnum].doepctl & USB_D_EPTYPE0_M) == (1 << USB_D_EPTYPE1_S) && xfer->interval == 1) {
// Take odd/even bit from frame counter.
uint32_t const odd_frame_now = (USB0.dsts & (1u << USB_SOFFN_S));
USB0.out_ep_reg[epnum].doepctl |= (odd_frame_now ? USB_DO_SETD0PID1 : USB_DO_SETD1PID1);
}
}
return true;
}
Expand Down
1 change: 1 addition & 0 deletions configs/defconfig.common
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ CONFIG_FATFS_API_ENCODING_UTF_8=y
# CONFIG_FMB_CONTROLLER_SLAVE_ID_SUPPORT is not set
CONFIG_FMB_TIMER_PORT_ENABLED=y
CONFIG_FREERTOS_HZ=1000
CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY=y
# CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION is not set
CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=1024
CONFIG_HEAP_POISONING_LIGHT=y
Expand Down
6 changes: 3 additions & 3 deletions configs/defconfig.esp32
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ CONFIG_BT_SPP_ENABLED=y
CONFIG_BT_HFP_ENABLE=y
CONFIG_BT_STACK_NO_LOG=y
CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY=y
CONFIG_ESP32_SPIRAM_SUPPORT=y
CONFIG_SPIRAM=y
CONFIG_SPIRAM_OCCUPY_HSPI_HOST=y
CONFIG_ESP32_ULP_COPROC_ENABLED=y
CONFIG_ESP32_XTAL_FREQ_AUTO=y
CONFIG_ULP_COPROC_ENABLED=y
CONFIG_XTAL_FREQ_AUTO=y
# CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 is not set
CONFIG_FREERTOS_FPU_IN_ISR=y
# CONFIG_USE_WAKENET is not set
Expand Down
2 changes: 1 addition & 1 deletion configs/defconfig.esp32c3
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CONFIG_BT_BLE_BLUFI_ENABLE=y
CONFIG_ESP32C3_RTC_CLK_CAL_CYCLES=576
CONFIG_RTC_CLK_CAL_CYCLES=576
# CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 is not set
CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=2304
4 changes: 2 additions & 2 deletions configs/defconfig.esp32s2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y
CONFIG_ESP32S2_DEFAULT_CPU_FREQ_240=y
CONFIG_ESP32S2_SPIRAM_SUPPORT=y
CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y
CONFIG_SPIRAM=y
CONFIG_ESP32S2_KEEP_USB_ALIVE=y
# CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 is not set
# CONFIG_USE_WAKENET is not set
Expand Down
6 changes: 3 additions & 3 deletions configs/defconfig.esp32s3
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y
CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y
CONFIG_ESP32S3_SPIRAM_SUPPORT=y
CONFIG_ESP32S3_RTC_CLK_CAL_CYCLES=576
CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y
CONFIG_SPIRAM=y
CONFIG_RTC_CLK_CAL_CYCLES=576
CONFIG_ESP32S3_UNIVERSAL_MAC_ADDRESSES_TWO=y
# CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND is not set
# CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 is not set
Expand Down
47 changes: 47 additions & 0 deletions main/idf_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
dependencies:
# Required IDF version
idf: ">=5.1"

mdns: "^1.0.7"
# nghttp: "^1.50.0"
# esp_jpeg: "^1.0.4"
# esp-dsp: "^1.2.0"
# esp-sr: "^1.0.3"
# esp32-camera: "^2.0.3"
# esp-dl:
# git: https://github.com/espressif/esp-dl.git
# arduino:
# path: components/arduino

# # Defining a dependency from the registry:
# # https://components.espressif.com/component/example/cmp
# example/cmp: "^3.3.3" # Automatically update minor releases
#
# # Other ways to define dependencies
#
# # For components maintained by Espressif only name can be used.
# # Same as `espressif/cmp`
# component: "~1.0.0" # Automatically update bugfix releases
#
# # Or in a longer form with extra parameters
# component2:
# version: ">=2.0.0"
#
# # For transient dependencies `public` flag can be set.
# # `public` flag doesn't have an effect for the `main` component.
# # All dependencies of `main` are public by default.
# public: true
#
# # For components hosted on non-default registry:
# service_url: "https://componentregistry.company.com"
#
# # For components in git repository:
# test_component:
# path: test_component
# git: ssh://[email protected]/user/components.git
#
# # For test projects during component development
# # components can be used from a local directory
# # with relative or absolute path
# some_local_component:
# path: ../../projects/component
5 changes: 1 addition & 4 deletions tools/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if [ -z $IDF_PATH ]; then
fi

if [ -z $IDF_BRANCH ]; then
IDF_BRANCH="release/v4.4"
IDF_BRANCH="master"
fi

if [ -z $AR_PR_TARGET_BRANCH ]; then
Expand All @@ -24,9 +24,6 @@ if [ -z $IDF_TARGET ]; then
fi
fi

IDF_COMPS="$IDF_PATH/components"
IDF_TOOLCHAIN="xtensa-$IDF_TARGET-elf"

# Owner of the target ESP32 Arduino repository
AR_USER="espressif"

Expand Down
14 changes: 8 additions & 6 deletions tools/copy-libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ for item in "${@:2:${#@}-5}"; do
elif [ "$prefix" = "-O" ]; then
PIO_CC_FLAGS+="$item "
elif [[ "$item" != "-Wall" && "$item" != "-Werror=all" && "$item" != "-Wextra" ]]; then
if [[ "${item:0:23}" != "-mfix-esp32-psram-cache" && "${item:0:18}" != "-fmacro-prefix-map" ]]; then
if [[ "${item:0:23}" != "-mfix-esp32-psram-cache" && "${item:0:18}" != "-fmacro-prefix-map" && "${item:0:20}" != "-fdiagnostics-color=" ]]; then
C_FLAGS+="$item "
fi
fi
Expand All @@ -109,7 +109,7 @@ set -- $str
for item in "${@:2:${#@}-5}"; do
prefix="${item:0:2}"
if [[ "$prefix" != "-I" && "$prefix" != "-D" && "$item" != "-Wall" && "$item" != "-Werror=all" && "$item" != "-Wextra" && "$prefix" != "-O" ]]; then
if [[ "${item:0:23}" != "-mfix-esp32-psram-cache" && "${item:0:18}" != "-fmacro-prefix-map" ]]; then
if [[ "${item:0:23}" != "-mfix-esp32-psram-cache" && "${item:0:18}" != "-fmacro-prefix-map" && "${item:0:20}" != "-fdiagnostics-color=" ]]; then
AS_FLAGS+="$item "
if [[ $C_FLAGS == *"$item"* ]]; then
PIO_CC_FLAGS+="$item "
Expand All @@ -128,7 +128,7 @@ set -- $str
for item in "${@:2:${#@}-5}"; do
prefix="${item:0:2}"
if [[ "$prefix" != "-I" && "$prefix" != "-D" && "$item" != "-Wall" && "$item" != "-Werror=all" && "$item" != "-Wextra" && "$prefix" != "-O" ]]; then
if [[ "${item:0:23}" != "-mfix-esp32-psram-cache" && "${item:0:18}" != "-fmacro-prefix-map" ]]; then
if [[ "${item:0:23}" != "-mfix-esp32-psram-cache" && "${item:0:18}" != "-fmacro-prefix-map" && "${item:0:20}" != "-fdiagnostics-color=" ]]; then
CPP_FLAGS+="$item "
if [[ $PIO_CC_FLAGS != *"$item"* ]]; then
PIO_CXX_FLAGS+="$item "
Expand All @@ -155,13 +155,15 @@ else
libs="${libs:19:${#libs}-1}"
flags=`cat build/build.ninja | grep LINK_FLAGS`
flags="${flags:15:${#flags}-1}"
paths=`cat build/build.ninja | grep LINK_PATH`
paths="${paths:14:${#paths}-1}"
if [ "$IDF_TARGET" = "esp32" ]; then
flags="-Wno-frame-address $flags"
fi
if [ "$IDF_TARGET" != "esp32c3" ]; then
flags="-mlongcalls $flags"
fi
str="$flags $libs"
str="$flags $libs $paths"
fi
if [ "$IDF_TARGET" = "esp32" ]; then
LD_SCRIPTS+="-T esp32.rom.redefined.ld "
Expand Down Expand Up @@ -362,7 +364,7 @@ for item; do
if [[ "$fname" == "main" && "$dname" == "esp32-arduino-lib-builder" ]]; then
continue
fi
while [[ "$dname" != "components" && "$dname" != "build" ]]; do
while [[ "$dname" != "components" && "$dname" != "managed_components" && "$dname" != "build" ]]; do
ipath=`dirname "$ipath"`
fname=`basename "$ipath"`
dname=`basename $(dirname "$ipath")`
Expand Down Expand Up @@ -482,7 +484,7 @@ rm -rf platform_start.txt platform_mid.txt 1platform_mid.txt
cp -f "sdkconfig" "$AR_SDK/sdkconfig"

# gen_esp32part.py
cp "$IDF_COMPS/partition_table/gen_esp32part.py" "$AR_GEN_PART_PY"
cp "$IDF_PATH/components/partition_table/gen_esp32part.py" "$AR_GEN_PART_PY"

# copy precompiled libs (if we need them)
function copy_precompiled_lib(){
Expand Down
Loading