diff --git a/.github/ISSUE_TEMPLATE/Feature-request.yml b/.github/ISSUE_TEMPLATE/Feature-request.yml index d50524433da..0788288036c 100644 --- a/.github/ISSUE_TEMPLATE/Feature-request.yml +++ b/.github/ISSUE_TEMPLATE/Feature-request.yml @@ -52,3 +52,11 @@ body: label: Additional context description: Please add any other context or screenshots about the feature request here. placeholder: ex. This would work only when ... + - type: checkboxes + id: confirmation + attributes: + label: I have checked existing list of Feature requests and the Contribution Guide + description: You agree to check all the resources above before opening a new Feature request. + options: + - label: I confirm I have checked existing list of Feature requests and Contribution Guide. + required: true diff --git a/.github/ISSUE_TEMPLATE/Issue-report.yml b/.github/ISSUE_TEMPLATE/Issue-report.yml index f355f26628a..ad68d2cba32 100644 --- a/.github/ISSUE_TEMPLATE/Issue-report.yml +++ b/.github/ISSUE_TEMPLATE/Issue-report.yml @@ -39,7 +39,9 @@ body: label: Version description: What version of Arduino ESP32 are you running? If possible, consider updating to the latest version. options: - - latest master + - latest master (checkout manually) + - latest development Release Candidate (RC-X) + - v2.0.2 - v2.0.1 - v2.0.0 - v1.0.6 @@ -51,7 +53,7 @@ body: attributes: label: IDE Name description: What IDE are you using? - placeholder: eg. Arduino IDE, PlatformIO, IDF component... + placeholder: eg. Arduino IDE, PlatformIO, Sloeber... validations: required: true - type: input @@ -100,8 +102,8 @@ body: id: sketch attributes: label: Sketch - description: Please provide your sketch/code which was run - placeholder: ex. related part of the code + description: Please provide full minimal sketch/code which can be run to reproduce your issue + placeholder: ex. Related part of the code to replicate the issue render: cpp validations: required: true diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 737f55dcc61..d68a0cea8a2 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,18 +1,23 @@ -*By completing this PR sufficiently, you help us to improve the quality of Release Notes* +*By completing this PR sufficiently, you help us to review this Pull Request quicker and also help improve the quality of Release Notes* ### Checklist -1. [ ] Please provide specific title of the PR describing the change, including the component name (eg. *„Update of Documentation link on Readme.md“*) -2. [ ] Please provide related links (eg. Issue, other Project, submodule PR..) -3. [ ] Please check [Contributing guide](https://docs.espressif.com/projects/arduino-esp32/en/latest/contributing.html) +1. [ ] Please provide specific title of the PR describing the change, including the component name (*eg. „Update of Documentation link on Readme.md“*) +2. [ ] Please provide related links (*eg. Issue which will be closed by this Pull Request*) +3. [ ] Please **update relevant Documentation** if applicable +4. [ ] Please check [Contributing guide](https://docs.espressif.com/projects/arduino-esp32/en/latest/contributing.html) *This entire section above can be deleted if all items are checked.* ----------- -## Summary -Please describe your proposed PR and what it contains. +## Description of Change +Please describe your proposed Pull Request and it's impact. -## Impact -Please describe impact of your PR and it's function. +## Tests scenarios +Please describe on what Hardware and Software combinations you have tested this Pull Request and how. + +(*eg. I have tested my Pull Request on Arduino-esp32 core v2.0.2 with ESP32 and ESP32-S2 Board with this scenario*) ## Related links Please provide links to related issue, PRs etc. + +(*eg. Closes #number of issue*) diff --git a/.github/scripts/install-arduino-core-esp32.sh b/.github/scripts/install-arduino-core-esp32.sh index 374d0401547..8584da5b6e2 100755 --- a/.github/scripts/install-arduino-core-esp32.sh +++ b/.github/scripts/install-arduino-core-esp32.sh @@ -2,35 +2,35 @@ export ARDUINO_ESP32_PATH="$ARDUINO_USR_PATH/hardware/espressif/esp32" if [ ! -d "$ARDUINO_ESP32_PATH" ]; then - echo "Installing ESP32 Arduino Core ..." - script_init_path="$PWD" - mkdir -p "$ARDUINO_USR_PATH/hardware/espressif" - cd "$ARDUINO_USR_PATH/hardware/espressif" + echo "Installing ESP32 Arduino Core ..." + script_init_path="$PWD" + mkdir -p "$ARDUINO_USR_PATH/hardware/espressif" + cd "$ARDUINO_USR_PATH/hardware/espressif" - echo "Installing Python Serial ..." - pip install pyserial > /dev/null + echo "Installing Python Serial ..." + pip install pyserial > /dev/null - if [ "$OS_IS_WINDOWS" == "1" ]; then - echo "Installing Python Requests ..." - pip install requests > /dev/null - fi + if [ "$OS_IS_WINDOWS" == "1" ]; then + echo "Installing Python Requests ..." + pip install requests > /dev/null + fi - if [ "$GITHUB_REPOSITORY" == "espressif/arduino-esp32" ]; then - echo "Linking Core..." - ln -s $GITHUB_WORKSPACE esp32 - else - echo "Cloning Core Repository..." - git clone https://github.com/espressif/arduino-esp32.git esp32 > /dev/null 2>&1 - fi + if [ ! -z "$GITHUB_REPOSITORY" ]; then + echo "Linking Core..." + ln -s $GITHUB_WORKSPACE esp32 + else + echo "Cloning Core Repository..." + git clone https://github.com/espressif/arduino-esp32.git esp32 > /dev/null 2>&1 + fi - #echo "Updating Submodules ..." - cd esp32 - #git submodule update --init --recursive > /dev/null 2>&1 + #echo "Updating Submodules ..." + cd esp32 + #git submodule update --init --recursive > /dev/null 2>&1 - echo "Installing Platform Tools ..." - cd tools && python get.py - cd $script_init_path + echo "Installing Platform Tools ..." + cd tools && python get.py + cd $script_init_path - echo "ESP32 Arduino has been installed in '$ARDUINO_ESP32_PATH'" - echo "" + echo "ESP32 Arduino has been installed in '$ARDUINO_ESP32_PATH'" + echo "" fi diff --git a/.github/scripts/install-arduino-ide.sh b/.github/scripts/install-arduino-ide.sh index 902c95b9e95..0f36120b3a9 100755 --- a/.github/scripts/install-arduino-ide.sh +++ b/.github/scripts/install-arduino-ide.sh @@ -6,46 +6,43 @@ OSBITS=`arch` if [[ "$OSTYPE" == "linux"* ]]; then - export OS_IS_LINUX="1" - ARCHIVE_FORMAT="tar.xz" - if [[ "$OSBITS" == "i686" ]]; then - OS_NAME="linux32" - elif [[ "$OSBITS" == "x86_64" ]]; then - OS_NAME="linux64" - elif [[ "$OSBITS" == "armv7l" || "$OSBITS" == "aarch64" ]]; then - OS_NAME="linuxarm" - else - OS_NAME="$OSTYPE-$OSBITS" - echo "Unknown OS '$OS_NAME'" - exit 1 - fi + export OS_IS_LINUX="1" + ARCHIVE_FORMAT="tar.xz" + if [[ "$OSBITS" == "i686" ]]; then + OS_NAME="linux32" + elif [[ "$OSBITS" == "x86_64" ]]; then + OS_NAME="linux64" + elif [[ "$OSBITS" == "armv7l" || "$OSBITS" == "aarch64" ]]; then + OS_NAME="linuxarm" + else + OS_NAME="$OSTYPE-$OSBITS" + echo "Unknown OS '$OS_NAME'" + exit 1 + fi elif [[ "$OSTYPE" == "darwin"* ]]; then - export OS_IS_MACOS="1" - ARCHIVE_FORMAT="zip" - OS_NAME="macosx" + export OS_IS_MACOS="1" + ARCHIVE_FORMAT="zip" + OS_NAME="macosx" elif [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then - export OS_IS_WINDOWS="1" - ARCHIVE_FORMAT="zip" - OS_NAME="windows" + export OS_IS_WINDOWS="1" + ARCHIVE_FORMAT="zip" + OS_NAME="windows" else - OS_NAME="$OSTYPE-$OSBITS" - echo "Unknown OS '$OS_NAME'" - exit 1 + OS_NAME="$OSTYPE-$OSBITS" + echo "Unknown OS '$OS_NAME'" + exit 1 fi export OS_NAME -ARDUINO_BUILD_DIR="$HOME/.arduino/build.tmp" -ARDUINO_CACHE_DIR="$HOME/.arduino/cache.tmp" - if [ "$OS_IS_MACOS" == "1" ]; then - export ARDUINO_IDE_PATH="/Applications/Arduino.app/Contents/Java" - export ARDUINO_USR_PATH="$HOME/Documents/Arduino" + export ARDUINO_IDE_PATH="/Applications/Arduino.app/Contents/Java" + export ARDUINO_USR_PATH="$HOME/Documents/Arduino" elif [ "$OS_IS_WINDOWS" == "1" ]; then - export ARDUINO_IDE_PATH="$HOME/arduino_ide" - export ARDUINO_USR_PATH="$HOME/Documents/Arduino" + export ARDUINO_IDE_PATH="$HOME/arduino_ide" + export ARDUINO_USR_PATH="$HOME/Documents/Arduino" else - export ARDUINO_IDE_PATH="$HOME/arduino_ide" - export ARDUINO_USR_PATH="$HOME/Arduino" + export ARDUINO_IDE_PATH="$HOME/arduino_ide" + export ARDUINO_USR_PATH="$HOME/Arduino" fi # Updated as of Nov 3rd 2020 @@ -55,184 +52,29 @@ ARDUINO_IDE_URL="https://github.com/espressif/arduino-esp32/releases/download/1. #ARDUINO_IDE_URL="https://www.arduino.cc/download.php?f=/arduino-nightly-" if [ ! -d "$ARDUINO_IDE_PATH" ]; then - echo "Installing Arduino IDE on $OS_NAME ..." - echo "Downloading '$ARDUINO_IDE_URL$OS_NAME.$ARCHIVE_FORMAT' to 'arduino.$ARCHIVE_FORMAT' ..." - if [ "$OS_IS_LINUX" == "1" ]; then - wget -O "arduino.$ARCHIVE_FORMAT" "$ARDUINO_IDE_URL$OS_NAME.$ARCHIVE_FORMAT" > /dev/null 2>&1 - echo "Extracting 'arduino.$ARCHIVE_FORMAT' ..." - tar xf "arduino.$ARCHIVE_FORMAT" > /dev/null - mv arduino-nightly "$ARDUINO_IDE_PATH" - else - curl -o "arduino.$ARCHIVE_FORMAT" -L "$ARDUINO_IDE_URL$OS_NAME.$ARCHIVE_FORMAT" > /dev/null 2>&1 - echo "Extracting 'arduino.$ARCHIVE_FORMAT' ..." - unzip "arduino.$ARCHIVE_FORMAT" > /dev/null - if [ "$OS_IS_MACOS" == "1" ]; then - mv "Arduino.app" "/Applications/Arduino.app" - else - mv arduino-nightly "$ARDUINO_IDE_PATH" - fi - fi - rm -rf "arduino.$ARCHIVE_FORMAT" - - mkdir -p "$ARDUINO_USR_PATH/libraries" - mkdir -p "$ARDUINO_USR_PATH/hardware" - - echo "Arduino IDE Installed in '$ARDUINO_IDE_PATH'" - echo "" -fi - -function build_sketch(){ # build_sketch [extra-options] - if [ "$#" -lt 2 ]; then - echo "ERROR: Illegal number of parameters" - echo "USAGE: build_sketch [extra-options]" - return 1 - fi - - local fqbn="$1" - local sketch="$2" - local xtra_opts="$3" - local win_opts="" - if [ "$OS_IS_WINDOWS" == "1" ]; then - local ctags_version=`ls "$ARDUINO_IDE_PATH/tools-builder/ctags/"` - local preprocessor_version=`ls "$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/"` - win_opts="-prefs=runtime.tools.ctags.path=$ARDUINO_IDE_PATH/tools-builder/ctags/$ctags_version -prefs=runtime.tools.arduino-preprocessor.path=$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/$preprocessor_version" - fi - - #echo "" - #echo "Compiling '"$(basename "$sketch")"' ..." - mkdir -p "$ARDUINO_BUILD_DIR" - mkdir -p "$ARDUINO_CACHE_DIR" - $ARDUINO_IDE_PATH/arduino-builder -compile -logger=human -core-api-version=10810 \ - -fqbn=$fqbn \ - -warnings="all" \ - -tools "$ARDUINO_IDE_PATH/tools-builder" \ - -tools "$ARDUINO_IDE_PATH/tools" \ - -built-in-libraries "$ARDUINO_IDE_PATH/libraries" \ - -hardware "$ARDUINO_IDE_PATH/hardware" \ - -hardware "$ARDUINO_USR_PATH/hardware" \ - -libraries "$ARDUINO_USR_PATH/libraries" \ - -build-cache "$ARDUINO_CACHE_DIR" \ - -build-path "$ARDUINO_BUILD_DIR" \ - $win_opts $xtra_opts "$sketch" -} - -function count_sketches() # count_sketches -{ - local examples="$1" - local target="$2" - rm -rf sketches.txt - if [ ! -d "$examples" ]; then - touch sketches.txt - return 0 - fi - local sketches=$(find $examples -name *.ino) - local sketchnum=0 - for sketch in $sketches; do - local sketchdir=$(dirname $sketch) - local sketchdirname=$(basename $sketchdir) - local sketchname=$(basename $sketch) - if [[ "$sketchdirname.ino" != "$sketchname" ]]; then - continue - elif [[ -f "$sketchdir/.skip.$target" ]]; then - continue + echo "Installing Arduino IDE on $OS_NAME ..." + echo "Downloading '$ARDUINO_IDE_URL$OS_NAME.$ARCHIVE_FORMAT' to 'arduino.$ARCHIVE_FORMAT' ..." + if [ "$OS_IS_LINUX" == "1" ]; then + wget -O "arduino.$ARCHIVE_FORMAT" "$ARDUINO_IDE_URL$OS_NAME.$ARCHIVE_FORMAT" > /dev/null 2>&1 + echo "Extracting 'arduino.$ARCHIVE_FORMAT' ..." + tar xf "arduino.$ARCHIVE_FORMAT" > /dev/null + mv arduino-nightly "$ARDUINO_IDE_PATH" + else + curl -o "arduino.$ARCHIVE_FORMAT" -L "$ARDUINO_IDE_URL$OS_NAME.$ARCHIVE_FORMAT" > /dev/null 2>&1 + echo "Extracting 'arduino.$ARCHIVE_FORMAT' ..." + unzip "arduino.$ARCHIVE_FORMAT" > /dev/null + if [ "$OS_IS_MACOS" == "1" ]; then + mv "Arduino.app" "/Applications/Arduino.app" else - echo $sketch >> sketches.txt - sketchnum=$(($sketchnum + 1)) + mv arduino-nightly "$ARDUINO_IDE_PATH" fi - done - return $sketchnum -} - -function build_sketches() # build_sketches [extra-options] -{ - local fqbn=$1 - local target="$2" - local examples=$3 - local chunk_idex=$4 - local chunks_num=$5 - local xtra_opts=$6 - - if [ "$#" -lt 3 ]; then - echo "ERROR: Illegal number of parameters" - echo "USAGE: build_sketches [ ] [extra-options]" - return 1 - fi - - if [ "$#" -lt 5 ]; then - chunk_idex="0" - chunks_num="1" - xtra_opts=$4 - fi - - if [ "$chunks_num" -le 0 ]; then - echo "ERROR: Chunks count must be positive number" - return 1 - fi - if [ "$chunk_idex" -ge "$chunks_num" ] && [ "$chunks_num" -ge 2 ]; then - echo "ERROR: Chunk index must be less than chunks count" - return 1 - fi - - set +e - count_sketches "$examples" "$target" - local sketchcount=$? - set -e - local sketches=$(cat sketches.txt) - rm -rf sketches.txt - - local chunk_size=$(( $sketchcount / $chunks_num )) - local all_chunks=$(( $chunks_num * $chunk_size )) - if [ "$all_chunks" -lt "$sketchcount" ]; then - chunk_size=$(( $chunk_size + 1 )) fi + rm -rf "arduino.$ARCHIVE_FORMAT" - local start_index=0 - local end_index=0 - if [ "$chunk_idex" -ge "$chunks_num" ]; then - start_index=$chunk_idex - end_index=$sketchcount - else - start_index=$(( $chunk_idex * $chunk_size )) - if [ "$sketchcount" -le "$start_index" ]; then - echo "Skipping job" - return 0 - fi + mkdir -p "$ARDUINO_USR_PATH/libraries" + mkdir -p "$ARDUINO_USR_PATH/hardware" - end_index=$(( $(( $chunk_idex + 1 )) * $chunk_size )) - if [ "$end_index" -gt "$sketchcount" ]; then - end_index=$sketchcount - fi - fi - - local start_num=$(( $start_index + 1 )) - echo "Found $sketchcount Sketches for target '$target'"; - echo "Chunk Index : $chunk_idex" - echo "Chunk Count : $chunks_num" - echo "Chunk Size : $chunk_size" - echo "Start Sketch: $start_num" - echo "End Sketch : $end_index" + echo "Arduino IDE Installed in '$ARDUINO_IDE_PATH'" + echo "" +fi - local sketchnum=0 - for sketch in $sketches; do - local sketchdir=$(dirname $sketch) - local sketchdirname=$(basename $sketchdir) - local sketchname=$(basename $sketch) - if [ "${sketchdirname}.ino" != "$sketchname" ] \ - || [ -f "$sketchdir/.skip.$target" ]; then - continue - fi - sketchnum=$(($sketchnum + 1)) - if [ "$sketchnum" -le "$start_index" ] \ - || [ "$sketchnum" -gt "$end_index" ]; then - continue - fi - echo "" - echo "Building Sketch Index $(($sketchnum - 1)) - $sketchdirname" - build_sketch "$fqbn" "$sketch" "$xtra_opts" - local result=$? - if [ $result -ne 0 ]; then - return $result - fi - done - return 0 -} diff --git a/.github/scripts/install-platformio-esp32.sh b/.github/scripts/install-platformio-esp32.sh index 71e3251bff2..71c1a55b297 100755 --- a/.github/scripts/install-platformio-esp32.sh +++ b/.github/scripts/install-platformio-esp32.sh @@ -1,11 +1,9 @@ #!/bin/bash export PLATFORMIO_ESP32_PATH="$HOME/.platformio/packages/framework-arduinoespressif32" -PLATFORMIO_ESP32_URL="https://github.com/platformio/platform-espressif32.git#feature/arduino-idf-master" +PLATFORMIO_ESP32_URL="https://github.com/platformio/platform-espressif32.git" -XTENSA32_TOOLCHAIN_VERSION="8.4.0+2021r1" -XTENSA32S2_TOOLCHAIN_VERSION="8.4.0+2021r1" -RISCV_TOOLCHAIN_VERSION="8.4.0+2021r1" +TOOLCHAIN_VERSION="8.4.0+2021r2-patch3" ESPTOOLPY_VERSION="~1.30100.0" ESPRESSIF_ORGANIZATION_NAME="espressif" @@ -30,9 +28,12 @@ replace_script+="data['packages']['toolchain-xtensa-esp32']['owner']='$ESPRESSIF replace_script+="data['packages']['toolchain-xtensa-esp32s2']['owner']='$ESPRESSIF_ORGANIZATION_NAME';" replace_script+="data['packages']['toolchain-riscv32-esp']['owner']='$ESPRESSIF_ORGANIZATION_NAME';" # Update versions to use the upstream -replace_script+="data['packages']['toolchain-xtensa-esp32']['version']='$XTENSA32_TOOLCHAIN_VERSION';" -replace_script+="data['packages']['toolchain-xtensa-esp32s2']['version']='$XTENSA32S2_TOOLCHAIN_VERSION';" -replace_script+="data['packages']['toolchain-riscv32-esp']['version']='$RISCV_TOOLCHAIN_VERSION';" +replace_script+="data['packages']['toolchain-xtensa-esp32']['version']='$TOOLCHAIN_VERSION';" +replace_script+="data['packages']['toolchain-xtensa-esp32s2']['version']='$TOOLCHAIN_VERSION';" +replace_script+="data['packages']['toolchain-riscv32-esp']['version']='$TOOLCHAIN_VERSION';" +# Add ESP32-S3 Toolchain +replace_script+="data['packages'].update({'toolchain-xtensa-esp32s3':{'type':'toolchain','optional':True,'owner':'$ESPRESSIF_ORGANIZATION_NAME','version':'$TOOLCHAIN_VERSION'}});" +replace_script+="data['packages']['toolchain-xtensa-esp32'].update({'optional':False});" # esptool.py may require an upstream version (for now platformio is the owner) replace_script+="data['packages']['tool-esptoolpy']['version']='$ESPTOOLPY_VERSION';" # Save results @@ -40,11 +41,11 @@ replace_script+="fp.seek(0);fp.truncate();json.dump(data, fp, indent=2);fp.close python -c "$replace_script" if [ "$GITHUB_REPOSITORY" == "espressif/arduino-esp32" ]; then - echo "Linking Core..." - ln -s $GITHUB_WORKSPACE "$PLATFORMIO_ESP32_PATH" + echo "Linking Core..." + ln -s $GITHUB_WORKSPACE "$PLATFORMIO_ESP32_PATH" else - echo "Cloning Core Repository ..." - git clone --recursive https://github.com/espressif/arduino-esp32.git "$PLATFORMIO_ESP32_PATH" > /dev/null 2>&1 + echo "Cloning Core Repository ..." + git clone --recursive https://github.com/espressif/arduino-esp32.git "$PLATFORMIO_ESP32_PATH" > /dev/null 2>&1 fi echo "PlatformIO for ESP32 has been installed" @@ -66,8 +67,7 @@ function build_pio_sketch(){ # build_pio_sketch python -m platformio ci --board "$board" "$sketch_dir" --project-option="$options" } -function count_sketches() # count_sketches -{ +function count_sketches(){ # count_sketches local examples="$1" rm -rf sketches.txt if [ ! -d "$examples" ]; then @@ -82,7 +82,7 @@ function count_sketches() # count_sketches local sketchname=$(basename $sketch) if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then continue - fi; + fi if [[ -f "$sketchdir/.test.skip" ]]; then continue fi @@ -92,8 +92,7 @@ function count_sketches() # count_sketches return $sketchnum } -function build_pio_sketches() # build_pio_sketches -{ +function build_pio_sketches(){ # build_pio_sketches if [ "$#" -lt 3 ]; then echo "ERROR: Illegal number of parameters" echo "USAGE: build_pio_sketches [ ]" diff --git a/.github/scripts/on-pages.sh b/.github/scripts/on-pages.sh index 8b88209db2f..124518469d2 100755 --- a/.github/scripts/on-pages.sh +++ b/.github/scripts/on-pages.sh @@ -71,7 +71,7 @@ function git_safe_upload_to_pages(){ local name=$(basename "$file") local size=`get_file_size "$file"` local upload_res=`git_upload_to_pages "$path" "$file"` - if [ $? -ne 0 ]; then + if [ $? -ne 0 ]; then >&2 echo "ERROR: Failed to upload '$name' ($?)" return 1 fi diff --git a/.github/scripts/on-push.sh b/.github/scripts/on-push.sh index aa30fe746d5..53dbb2250bb 100755 --- a/.github/scripts/on-push.sh +++ b/.github/scripts/on-push.sh @@ -2,92 +2,118 @@ set -e +export ARDUINO_BUILD_DIR="$HOME/.arduino/build.tmp" + +function build(){ + local target=$1 + local fqbn=$2 + local chunk_index=$3 + local chunks_cnt=$4 + local sketches=$5 + + local BUILD_SKETCH="${SCRIPTS_DIR}/sketch_utils.sh build" + local BUILD_SKETCHES="${SCRIPTS_DIR}/sketch_utils.sh chunk_build" + + local args="$ARDUINO_IDE_PATH $ARDUINO_USR_PATH" + + args+=" \"$fqbn\"" + + if [ "$OS_IS_LINUX" == "1" ]; then + args+=" $target" + args+=" $ARDUINO_ESP32_PATH/libraries" + args+=" $chunk_index $chunks_cnt" + ${BUILD_SKETCHES} ${args} + else + if [ "$OS_IS_WINDOWS" == "1" ]; then + local ctags_version=`ls "$ARDUINO_IDE_PATH/tools-builder/ctags/"` + local preprocessor_version=`ls "$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/"` + win_opts="-prefs=runtime.tools.ctags.path=$ARDUINO_IDE_PATH/tools-builder/ctags/$ctags_version + -prefs=runtime.tools.arduino-preprocessor.path=$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/$preprocessor_version" + args+=" ${win_opts}" + fi + + for sketch in ${sketches}; do + ${BUILD_SKETCH} ${args} ${sketch} + done + fi +} + if [ -z "$GITHUB_WORKSPACE" ]; then - export GITHUB_WORKSPACE="$PWD" - export GITHUB_REPOSITORY="espressif/arduino-esp32" + export GITHUB_WORKSPACE="$PWD" + export GITHUB_REPOSITORY="espressif/arduino-esp32" fi CHUNK_INDEX=$1 CHUNKS_CNT=$2 BUILD_PIO=0 if [ "$#" -lt 2 ] || [ "$CHUNKS_CNT" -le 0 ]; then - CHUNK_INDEX=0 - CHUNKS_CNT=1 + CHUNK_INDEX=0 + CHUNKS_CNT=1 elif [ "$CHUNK_INDEX" -gt "$CHUNKS_CNT" ] && [ "$CHUNKS_CNT" -ge 2 ]; then - CHUNK_INDEX=$CHUNKS_CNT + CHUNK_INDEX=$CHUNKS_CNT elif [ "$CHUNK_INDEX" -eq "$CHUNKS_CNT" ]; then - BUILD_PIO=1 + BUILD_PIO=1 fi #echo "Updating submodules ..." #git -C "$GITHUB_WORKSPACE" submodule update --init --recursive > /dev/null 2>&1 +SCRIPTS_DIR="./.github/scripts" if [ "$BUILD_PIO" -eq 0 ]; then - # ArduinoIDE ESP32 Test - TARGET="esp32" - FQBN="espressif:esp32:esp32:PSRAM=enabled,PartitionScheme=huge_app" - source ./.github/scripts/install-arduino-ide.sh - source ./.github/scripts/install-arduino-core-esp32.sh - if [ "$OS_IS_WINDOWS" == "1" ]; then - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" && \ - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/BLE/examples/BLE_server/BLE_server.ino" && \ - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino" - elif [ "$OS_IS_MACOS" == "1" ]; then - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino" && \ - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" && \ - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/BluetoothSerial/examples/SerialToSerialBT/SerialToSerialBT.ino" && \ - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/BLE/examples/BLE_server/BLE_server.ino" && \ - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino" - else - # CMake Test - if [ "$CHUNK_INDEX" -eq 0 ]; then - bash "$ARDUINO_ESP32_PATH/.github/scripts/check-cmakelists.sh" - fi - build_sketches "$FQBN" "$TARGET" "$ARDUINO_ESP32_PATH/libraries" "$CHUNK_INDEX" "$CHUNKS_CNT" - fi - - # ArduinoIDE ESP32S2 Test - TARGET="esp32s2" - FQBN="espressif:esp32:esp32s2:PSRAM=enabled,PartitionScheme=huge_app" - if [ "$OS_IS_WINDOWS" == "1" ]; then - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino" && \ - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" - elif [ "$OS_IS_MACOS" == "1" ]; then - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino" && \ - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" - else - build_sketches "$FQBN" "$TARGET" "$ARDUINO_ESP32_PATH/libraries" "$CHUNK_INDEX" "$CHUNKS_CNT" - fi + source ${SCRIPTS_DIR}/install-arduino-ide.sh + source ${SCRIPTS_DIR}/install-arduino-core-esp32.sh - # ArduinoIDE ESP32C3 Test - TARGET="esp32c3" - FQBN="espressif:esp32:esp32c3:PartitionScheme=huge_app" - if [ "$OS_IS_WINDOWS" == "1" ]; then - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino" && \ - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" - elif [ "$OS_IS_MACOS" == "1" ]; then - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino" && \ - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" - else - build_sketches "$FQBN" "$TARGET" "$ARDUINO_ESP32_PATH/libraries" "$CHUNK_INDEX" "$CHUNKS_CNT" - fi + FQBN_ESP32="espressif:esp32:esp32:PSRAM=enabled,PartitionScheme=huge_app" + FQBN_ESP32S2="espressif:esp32:esp32s2:PSRAM=enabled,PartitionScheme=huge_app" + FQBN_ESP32S3="espressif:esp32:esp32s3:PSRAM=opi,USBMode=default,PartitionScheme=huge_app" + FQBN_ESP32C3="espressif:esp32:esp32c3:PartitionScheme=huge_app" + + SKETCHES_ESP32="\ + $ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino\ + $ARDUINO_ESP32_PATH/libraries/BLE/examples/BLE_server/BLE_server.ino\ + $ARDUINO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino\ + " + + SKETCHES_ESP32XX="\ + $ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino\ + $ARDUINO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino\ + " + + build "esp32s3" $FQBN_ESP32S3 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32 + build "esp32s2" $FQBN_ESP32S2 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32XX + build "esp32c3" $FQBN_ESP32C3 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32XX + build "esp32" $FQBN_ESP32 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32 else - source ./.github/scripts/install-platformio-esp32.sh - # PlatformIO ESP32 Test - BOARD="esp32dev" + source ${SCRIPTS_DIR}/install-platformio-esp32.sh + # PlatformIO ESP32 Test + BOARD="esp32dev" OPTIONS="board_build.partitions = huge_app.csv" - build_pio_sketch "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino" && \ - build_pio_sketch "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" && \ - build_pio_sketch "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries/BluetoothSerial/examples/SerialToSerialBT/SerialToSerialBT.ino" && \ - build_pio_sketch "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries/BLE/examples/BLE_server/BLE_server.ino" && \ - build_pio_sketch "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino" - - # PlatformIO ESP32 Test + build_pio_sketch "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino" && \ + build_pio_sketch "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" && \ + build_pio_sketch "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries/BluetoothSerial/examples/SerialToSerialBT/SerialToSerialBT.ino" && \ + build_pio_sketch "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries/BLE/examples/BLE_server/BLE_server.ino" && \ + build_pio_sketch "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino" + + # PlatformIO ESP32 Test # OPTIONS="board_build.mcu = esp32s2" # build_pio_sketch "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino" && \ # build_pio_sketch "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" python -m platformio ci --board "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/WiFi/examples/WiFiClient" --project-option="board_build.mcu = esp32s2" --project-option="board_build.partitions = huge_app.csv" - - #build_pio_sketches "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries" + python -m platformio ci --board "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/WiFi/examples/WiFiClient" --project-option="board_build.mcu = esp32c3" --project-option="board_build.partitions = huge_app.csv" + + echo "Hacking in S3 support ..." + replace_script="import json; import os;" + replace_script+="fp=open(os.path.expanduser('~/.platformio/platforms/espressif32/platform.json'), 'r+');" + replace_script+="data=json.load(fp);" + replace_script+="data['packages']['toolchain-xtensa-esp32']['optional']=True;" + replace_script+="data['packages']['toolchain-xtensa-esp32s3']['optional']=False;" + replace_script+="data['packages']['tool-esptoolpy']['owner']='tasmota';" + replace_script+="data['packages']['tool-esptoolpy']['version']='https://github.com/tasmota/esptool/releases/download/v3.3/esptool-3.3.zip';" + replace_script+="fp.seek(0);fp.truncate();json.dump(data, fp, indent=2);fp.close()" + python -c "$replace_script" + + python -m platformio ci --board "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/WiFi/examples/WiFiClient" --project-option="board_build.mcu = esp32s3" --project-option="board_build.partitions = huge_app.csv" + + #build_pio_sketches "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries" fi diff --git a/.github/scripts/on-release.sh b/.github/scripts/on-release.sh index 9e1c51ff48d..7222baba128 100755 --- a/.github/scripts/on-release.sh +++ b/.github/scripts/on-release.sh @@ -33,7 +33,7 @@ PACKAGE_JSON_DEV="package_esp32_dev_index.json" PACKAGE_JSON_REL="package_esp32_index.json" echo "Event: $GITHUB_EVENT_NAME, Repo: $GITHUB_REPOSITORY, Path: $GITHUB_WORKSPACE, Ref: $GITHUB_REF" -echo "Action: $action, Branch: $RELEASE_BRANCH, ID: $RELEASE_ID" +echo "Action: $action, Branch: $RELEASE_BRANCH, ID: $RELEASE_ID" echo "Tag: $RELEASE_TAG, Draft: $draft, Pre-Release: $RELEASE_PRE" function get_file_size(){ @@ -60,7 +60,7 @@ function git_safe_upload_asset(){ local name=$(basename "$file") local size=`get_file_size "$file"` local upload_res=`git_upload_asset "$file"` - if [ $? -ne 0 ]; then + if [ $? -ne 0 ]; then >&2 echo "ERROR: Failed to upload '$name' ($?)" return 1 fi @@ -112,7 +112,7 @@ function git_safe_upload_to_pages(){ local name=$(basename "$file") local size=`get_file_size "$file"` local upload_res=`git_upload_to_pages "$path" "$file"` - if [ $? -ne 0 ]; then + if [ $? -ne 0 ]; then >&2 echo "ERROR: Failed to upload '$name' ($?)" return 1 fi @@ -131,7 +131,7 @@ function merge_package_json(){ local jsonOut=$2 local old_json=$OUTPUT_DIR/oldJson.json local merged_json=$OUTPUT_DIR/mergedJson.json - + echo "Downloading previous JSON $jsonLink ..." curl -L -o "$old_json" "https://github.com/$GITHUB_REPOSITORY/releases/download/$jsonLink?access_token=$GITHUB_TOKEN" 2>/dev/null if [ $? -ne 0 ]; then echo "ERROR: Download Failed! $?"; exit 1; fi @@ -140,7 +140,7 @@ function merge_package_json(){ set +e stdbuf -oL python "$PACKAGE_JSON_MERGE" "$jsonOut" "$old_json" > "$merged_json" set -e - + set -v if [ ! -s $merged_json ]; then rm -f "$merged_json" @@ -172,6 +172,7 @@ mkdir -p "$PKG_DIR/tools" # Copy all core files to the package folder echo "Copying files for packaging ..." cp -f "$GITHUB_WORKSPACE/boards.txt" "$PKG_DIR/" +cp -f "$GITHUB_WORKSPACE/package.json" "$PKG_DIR/" cp -f "$GITHUB_WORKSPACE/programmers.txt" "$PKG_DIR/" cp -Rf "$GITHUB_WORKSPACE/cores" "$PKG_DIR/" cp -Rf "$GITHUB_WORKSPACE/libraries" "$PKG_DIR/" @@ -317,7 +318,7 @@ releaseNotes="" relNotesRaw=`git -C "$GITHUB_WORKSPACE" show -s --format=%b $RELEASE_TAG` readarray -t msgArray <<<"$relNotesRaw" arrLen=${#msgArray[@]} -if [ $arrLen > 3 ] && [ "${msgArray[0]:0:3}" == "tag" ]; then +if [ $arrLen > 3 ] && [ "${msgArray[0]:0:3}" == "tag" ]; then ind=3 while [ $ind -lt $arrLen ]; do if [ $ind -eq 3 ]; then @@ -327,7 +328,7 @@ if [ $arrLen > 3 ] && [ "${msgArray[0]:0:3}" == "tag" ]; then oneLine="$(echo -e "${msgArray[ind]}" | sed -e 's/^[[:space:]]*//')" if [ ${#oneLine} -gt 0 ]; then if [ "${oneLine:0:2}" == "* " ]; then oneLine=$(echo ${oneLine/\*/-}); fi - if [ "${oneLine:0:2}" != "- " ]; then releaseNotes+="- "; fi + if [ "${oneLine:0:2}" != "- " ]; then releaseNotes+="- "; fi releaseNotes+="$oneLine" releaseNotes+=$'\r\n' fi @@ -368,9 +369,9 @@ done rm -f $commitFile # Prepend the original release body -if [ "${RELEASE_BODY: -1}" == $'\r' ]; then +if [ "${RELEASE_BODY: -1}" == $'\r' ]; then RELEASE_BODY="${RELEASE_BODY:0:-1}" -else +else RELEASE_BODY="$RELEASE_BODY" fi RELEASE_BODY+=$'\r\n' diff --git a/.github/scripts/sketch_utils.sh b/.github/scripts/sketch_utils.sh new file mode 100755 index 00000000000..abe3db2b977 --- /dev/null +++ b/.github/scripts/sketch_utils.sh @@ -0,0 +1,192 @@ +#!/bin/bash + +function build_sketch(){ # build_sketch [extra-options] + if [ "$#" -lt 4 ]; then + echo "ERROR: Illegal number of parameters" + echo "USAGE: ${0} build [extra-options]" + return 1 + fi + + local ide_path=$1 + local usr_path=$2 + local fqbn=$3 + local sketch=$4 + local xtra_opts=$5 + local win_opts=$6 + + ARDUINO_CACHE_DIR="$HOME/.arduino/cache.tmp" + if [ -z "$ARDUINO_BUILD_DIR" ]; then + build_dir="$(dirname $sketch)/build" + else + build_dir="$ARDUINO_BUILD_DIR" + fi + + echo $sketch + + rm -rf "$build_dir" + mkdir -p "$build_dir" + mkdir -p "$ARDUINO_CACHE_DIR" + $ide_path/arduino-builder -compile -logger=human -core-api-version=10810 \ + -fqbn=$fqbn \ + -warnings="all" \ + -tools "$ide_path/tools-builder" \ + -tools "$ide_path/tools" \ + -built-in-libraries "$ide_path/libraries" \ + -hardware "$ide_path/hardware" \ + -hardware "$usr_path/hardware" \ + -libraries "$usr_path/libraries" \ + -build-cache "$ARDUINO_CACHE_DIR" \ + -build-path "$build_dir" \ + $win_opts $xtra_opts "$sketch" +} + +function count_sketches(){ # count_sketches [target] + local path=$1 + local target=$2 + + if [ $# -lt 1 ]; then + echo "ERROR: Illegal number of parameters" + echo "USAGE: ${0} count [target]" + fi + + rm -rf sketches.txt + if [ ! -d "$path" ]; then + touch sketches.txt + return 0 + fi + + local sketches=$(find $path -name *.ino | sort) + local sketchnum=0 + for sketch in $sketches; do + local sketchdir=$(dirname $sketch) + local sketchdirname=$(basename $sketchdir) + local sketchname=$(basename $sketch) + if [[ "$sketchdirname.ino" != "$sketchname" ]]; then + continue + elif [[ -n $target ]] && [[ -f "$sketchdir/.skip.$target" ]]; then + continue + else + echo $sketch >> sketches.txt + sketchnum=$(($sketchnum + 1)) + fi + done + return $sketchnum +} + +function build_sketches(){ # build_sketches [extra-options] + local ide_path=$1 + local usr_path=$2 + local fqbn=$3 + local target=$4 + local path=$5 + local chunk_idex=$6 + local chunks_num=$7 + local xtra_opts=$8 + + if [ "$#" -lt 7 ]; then + echo "ERROR: Illegal number of parameters" + echo "USAGE: ${0} chunk_build [ ] [extra-options]" + return 1 + fi + + if [ "$chunks_num" -le 0 ]; then + echo "ERROR: Chunks count must be positive number" + return 1 + fi + if [ "$chunk_idex" -ge "$chunks_num" ] && [ "$chunks_num" -ge 2 ]; then + echo "ERROR: Chunk index must be less than chunks count" + return 1 + fi + + set +e + count_sketches "$path" "$target" + local sketchcount=$? + set -e + local sketches=$(cat sketches.txt) + rm -rf sketches.txt + + local chunk_size=$(( $sketchcount / $chunks_num )) + local all_chunks=$(( $chunks_num * $chunk_size )) + if [ "$all_chunks" -lt "$sketchcount" ]; then + chunk_size=$(( $chunk_size + 1 )) + fi + + local start_index=0 + local end_index=0 + if [ "$chunk_idex" -ge "$chunks_num" ]; then + start_index=$chunk_idex + end_index=$sketchcount + else + start_index=$(( $chunk_idex * $chunk_size )) + if [ "$sketchcount" -le "$start_index" ]; then + echo "Skipping job" + return 0 + fi + + end_index=$(( $(( $chunk_idex + 1 )) * $chunk_size )) + if [ "$end_index" -gt "$sketchcount" ]; then + end_index=$sketchcount + fi + fi + + local start_num=$(( $start_index + 1 )) + echo "Found $sketchcount Sketches for target '$target'"; + echo "Chunk Index : $chunk_idex" + echo "Chunk Count : $chunks_num" + echo "Chunk Size : $chunk_size" + echo "Start Sketch: $start_num" + echo "End Sketch : $end_index" + + local sketchnum=0 + for sketch in $sketches; do + local sketchdir=$(dirname $sketch) + local sketchdirname=$(basename $sketchdir) + local sketchname=$(basename $sketch) + sketchnum=$(($sketchnum + 1)) + if [ "$sketchnum" -le "$start_index" ] \ + || [ "$sketchnum" -gt "$end_index" ]; then + continue + fi + echo "" + echo "Building Sketch Index $(($sketchnum - 1)) - $sketchdirname" + build_sketch "$ide_path" "$usr_path" "$fqbn" "$sketch" "$xtra_opts" + local result=$? + if [ $result -ne 0 ]; then + return $result + fi + done + return 0 +} + +USAGE=" +USAGE: ${0} [command] [options] +Available commands: + count: Count sketches. + build: Build a sketch. + chunk_build: Build a chunk of sketches. +" + +cmd=$1 +shift +if [ -z $cmd ]; then + echo "ERROR: No command supplied" + echo "$USAGE" + exit 2 +fi + +case "$cmd" in + "count") + count_sketches $* + ;; + "build") + build_sketch $* + ;; + "chunk_build") + build_sketches $* + ;; + *) + echo "ERROR: Unrecognized command" + echo "$USAGE" + exit 2 +esac + diff --git a/.github/scripts/tests_build.sh b/.github/scripts/tests_build.sh new file mode 100755 index 00000000000..fd0d2db2d2f --- /dev/null +++ b/.github/scripts/tests_build.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +SCRIPTS_DIR="./.github/scripts" +BUILD_CMD="" + +if [ $# -eq 3 ]; then + chunk_build=1 +elif [ $# -eq 2 ]; then + chunk_build=0 +else + echo "ERROR: Illegal number of parameters" + echo "USAGE: + ${0} + ${0} + " + exit 0 +fi + +target=$1 + +case "$target" in + "esp32") fqbn="espressif:esp32:esp32:PSRAM=enabled,PartitionScheme=huge_app" + ;; + "esp32s2") fqbn="espressif:esp32:esp32s2:PSRAM=enabled,PartitionScheme=huge_app" + ;; + "esp32c3") fqbn="espressif:esp32:esp32c3:PartitionScheme=huge_app" + ;; + "esp32s3") fqbn="espressif:esp32:esp32s3:PSRAM=opi,USBMode=default,PartitionScheme=huge_app" + ;; +esac + +if [ -z $fqbn ]; then + echo "Unvalid chip $1" + exit 0 +fi + +source ${SCRIPTS_DIR}/install-arduino-ide.sh +source ${SCRIPTS_DIR}/install-arduino-core-esp32.sh + +args="$ARDUINO_IDE_PATH $ARDUINO_USR_PATH \"$fqbn\"" + +if [ $chunk_build -eq 1 ]; then + chunk_index=$2 + chunk_max=$3 + + if [ "$chunk_index" -gt "$chunk_max" ] && [ "$chunk_max" -ge 2 ]; then + chunk_index=$chunk_max + fi + BUILD_CMD="${SCRIPTS_DIR}/sketch_utils.sh chunk_build" + args+=" $target $PWD/tests $chunk_index $chunk_max" +else + sketchdir=$2 + BUILD_CMD="${SCRIPTS_DIR}/sketch_utils.sh build" + args+=" $PWD/tests/$sketchdir/$sketchdir.ino" +fi + +${BUILD_CMD} ${args} + diff --git a/.github/scripts/tests_run.sh b/.github/scripts/tests_run.sh new file mode 100755 index 00000000000..a13f3c00c1d --- /dev/null +++ b/.github/scripts/tests_run.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +target=$1 +chunk_idex=$2 +chunks_num=$3 + +SCRIPTS_DIR="./.github/scripts" +COUNT_SKETCHES="${SCRIPTS_DIR}/sketch_utils.sh count" + +source ${SCRIPTS_DIR}/install-arduino-ide.sh + +if [ "$chunks_num" -le 0 ]; then + echo "ERROR: Chunks count must be positive number" + return 1 +fi +if [ "$chunk_idex" -ge "$chunks_num" ] && [ "$chunks_num" -ge 2 ]; then + echo "ERROR: Chunk index must be less than chunks count" + return 1 +fi + +set +e +${COUNT_SKETCHES} $PWD/tests $target +sketchcount=$? +set -e +sketches=$(cat sketches.txt) +rm -rf sketches.txt + +chunk_size=$(( $sketchcount / $chunks_num )) +all_chunks=$(( $chunks_num * $chunk_size )) +if [ "$all_chunks" -lt "$sketchcount" ]; then + chunk_size=$(( $chunk_size + 1 )) +fi + +start_index=0 +end_index=0 +if [ "$chunk_idex" -ge "$chunks_num" ]; then + start_index=$chunk_idex + end_index=$sketchcount +else + start_index=$(( $chunk_idex * $chunk_size )) + if [ "$sketchcount" -le "$start_index" ]; then + echo "Skipping job" + return 0 + fi + + end_index=$(( $(( $chunk_idex + 1 )) * $chunk_size )) + if [ "$end_index" -gt "$sketchcount" ]; then + end_index=$sketchcount + fi +fi + +start_num=$(( $start_index + 1 )) +sketchnum=0 + +for sketch in $sketches; do + sketchdir=$(dirname $sketch) + sketchdirname=$(basename $sketchdir) + sketchname=$(basename $sketch) + sketchnum=$(($sketchnum + 1)) + if [ "$sketchnum" -le "$start_index" ] \ + || [ "$sketchnum" -gt "$end_index" ]; then + continue + fi + echo "" + echo "Test for Sketch Index $(($sketchnum - 1)) - $sketchdirname" + pytest tests -k test_$sketchdirname --junit-xml=tests/$sketchdirname/$sketchdirname.xml + result=$? + if [ $result -ne 0 ]; then + return $result + fi +done diff --git a/.github/scripts/update-version.sh b/.github/scripts/update-version.sh new file mode 100755 index 00000000000..aac4f527c0f --- /dev/null +++ b/.github/scripts/update-version.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# For reference: add tools for all boards by replacing one line in each board +# "[board].upload.tool=esptool_py" to "[board].upload.tool=esptool_py\n[board].upload.tool.default=esptool_py\n[board].upload.tool.network=esp_ota" +#cat boards.txt | sed "s/\([a-zA-Z0-9_\-]*\)\.upload\.tool\=esptool_py/\1\.upload\.tool\=esptool_py\\n\1\.upload\.tool\.default\=esptool_py\\n\1\.upload\.tool\.network\=esp_ota/" + +if [ ! $# -eq 3 ]; then + echo "Bad number of arguments: $#" >&2 + echo "usage: $0 " >&2 + exit 1 +fi + +re='^[0-9]+$' +if [[ ! $1 =~ $re ]] || [[ ! $2 =~ $re ]] || [[ ! $3 =~ $re ]] ; then + echo "error: Not a valid version: $1.$2.$3" >&2 + echo "usage: $0 " >&2 + exit 1 +fi + +ESP_ARDUINO_VERSION_MAJOR="$1" +ESP_ARDUINO_VERSION_MINOR="$2" +ESP_ARDUINO_VERSION_PATCH="$3" +ESP_ARDUINO_VERSION="$ESP_ARDUINO_VERSION_MAJOR.$ESP_ARDUINO_VERSION_MINOR.$ESP_ARDUINO_VERSION_PATCH" + +echo "New Arduino Version: $ESP_ARDUINO_VERSION" + +echo "Updating platform.txt..." +cat platform.txt | sed "s/version=.*/version=$ESP_ARDUINO_VERSION/g" > __platform.txt && mv __platform.txt platform.txt + +echo "Updating package.json..." +cat package.json | sed "s/.*\"version\":.*/ \"version\": \"$ESP_ARDUINO_VERSION\",/g" > __package.json && mv __package.json package.json + +echo "Updating cores/esp32/esp_arduino_version.h..." +cat cores/esp32/esp_arduino_version.h | \ +sed "s/#define ESP_ARDUINO_VERSION_MAJOR.*/#define ESP_ARDUINO_VERSION_MAJOR $ESP_ARDUINO_VERSION_MAJOR/g" | \ +sed "s/#define ESP_ARDUINO_VERSION_MINOR.*/#define ESP_ARDUINO_VERSION_MINOR $ESP_ARDUINO_VERSION_MINOR/g" | \ +sed "s/#define ESP_ARDUINO_VERSION_PATCH.*/#define ESP_ARDUINO_VERSION_PATCH $ESP_ARDUINO_VERSION_PATCH/g" > __esp_arduino_version.h && mv __esp_arduino_version.h cores/esp32/esp_arduino_version.h + +exit 0 diff --git a/.github/stale.yml b/.github/stale.yml deleted file mode 100644 index 8b7ca846187..00000000000 --- a/.github/stale.yml +++ /dev/null @@ -1,26 +0,0 @@ -# This workflow firstly warns and then closes issues that have had no activity for a specified amount of time. -# -# You can adjust the behavior by modifying this file. -# For more information can be found here: https://github.com/actions/stale - -name: Mark stale issues -on: - schedule: - - cron: '30 9 * * *' - -jobs: - stale: - - runs-on: ubuntu-latest - permissions: - issues: write - - steps: - - uses: actions/stale@v3 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - stale-issue-message: 'This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.' - days-before-stale: 60 - days-before-close: 14 - exempt-issue-labels: 'Type: For reference,Type: To be implemented,Type: Feature request' - stale-issue-label: 'Status: Stale' \ No newline at end of file diff --git a/.github/workflows/hil.yml b/.github/workflows/hil.yml new file mode 100644 index 00000000000..037a7432c6e --- /dev/null +++ b/.github/workflows/hil.yml @@ -0,0 +1,121 @@ +name: Run tests in hardware + +on: + pull_request: + types: [opened, reopened, synchronize, labeled] + + schedule: + - cron: '0 2 * * *' + +env: + MAX_CHUNKS: 15 + +concurrency: + group: hil-${{github.event.pull_request.number || github.ref}} + cancel-in-progress: true + +jobs: + gen_chunks: + if: | + contains(github.event.pull_request.labels.*.name, 'hil_test') || + github.event_name == 'schedule' + name: Generate Chunks matrix + runs-on: ubuntu-latest + outputs: + chunks: ${{ steps.gen-chunks.outputs.chunks }} + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Generate Chunks matrix + id: gen-chunks + run: | + set +e + bash .github/scripts/sketch_utils.sh count tests + sketches=$((? - 1)) + if [[ $sketches -gt ${{env.MAX_CHUNKS}} ]]; then + $sketches=${{env.MAX_CHUNKS}} + fi + set -e + rm sketches.txt + CHUNKS=$(jq -c -n '$ARGS.positional' --args `seq 0 1 $sketches`) + echo "::set-output name=chunks::${CHUNKS}" + + Build: + needs: gen_chunks + name: ${{matrix.chip}}-Build#${{matrix.chunks}} + runs-on: ubuntu-latest + strategy: + matrix: + chip: ['esp32', 'esp32s2', 'esp32s3', 'esp32c3'] + chunks: ${{fromJson(needs.gen_chunks.outputs.chunks)}} + + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Build sketches + run: | + bash .github/scripts/tests_build.sh ${{matrix.chip}} ${{matrix.chunks}} ${{env.MAX_CHUNKS}} + - name: Upload ${{matrix.chip}}-${{matrix.chunks}} artifacts + uses: actions/upload-artifact@v2 + with: + name: ${{matrix.chip}}-${{matrix.chunks}}.artifacts + path: | + tests/*/build/*.bin + tests/*/build/*.json + Test: + needs: [gen_chunks, Build] + name: ${{matrix.chip}}-Test#${{matrix.chunks}} + runs-on: + - ESP32 + - ESP32-S2 + - ESP32-S3 + - ESP32-C3 + + strategy: + fail-fast: false + matrix: + chip: ['esp32', 'esp32s2', 'esp32s3', 'esp32c3'] + chunks: ${{fromJson(needs.gen_chunks.outputs.chunks)}} + container: + image: python:3.10.1-bullseye + options: --privileged + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Download ${{matrix.chip}}-${{matrix.chunks}} artifacts + uses: actions/download-artifact@v2 + with: + name: ${{matrix.chip}}-${{matrix.chunks}}.artifacts + path: tests/ + + - name: Install dependencies + run: | + pip install -U pip + pip install -r tests/requirements.txt + + - name: Run Tests + run: | + bash .github/scripts/tests_run.sh ${{matrix.chip}} ${{matrix.chunks}} ${{env.MAX_CHUNKS}} + + - name: Upload test result artifacts + uses: actions/upload-artifact@v2 + if: always() + with: + name: test_results-${{matrix.chip}}-${{matrix.chunks}} + path: tests/*/*.xml + + event_file: + name: "Event File" + if: ${{ always() }} + needs: Test + runs-on: ubuntu-latest + steps: + - name: Upload + uses: actions/upload-artifact@v2 + with: + name: Event File + path: ${{github.event_path}} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000000..34d3564c4a8 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,38 @@ +name: Unit Test Results + +on: + workflow_run: + workflows: [Run tests in hardware] + branches-ignore: [master] + + types: + - completed + +jobs: + unit-test-results: + name: Unit Test Results + runs-on: ubuntu-latest + if: | + github.event.workflow_run.event == 'pull_request' && + (github.event.workflow_run.conclusion == 'success' || + github.event.workflow_run.conclusion == 'failure') + steps: + - name: Download and Extract Artifacts + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + run: | + mkdir -p artifacts && cd artifacts + artifacts_url=${{ github.event.workflow_run.artifacts_url }} + gh api "$artifacts_url" -q '.artifacts[] | [.name, .archive_download_url] | @tsv' | while read artifact + do + IFS=$'\t' read name url <<< "$artifact" + gh api $url > "$name.zip" + unzip -d "$name" "$name.zip" + done + - name: Publish Unit Test Results + uses: EnricoMi/publish-unit-test-result-action@v1 + with: + commit: ${{ github.event.workflow_run.head_sha }} + event_file: artifacts/Event File/event.json + event_name: ${{ github.event.workflow_run.event }} + files: "artifacts/**/*.xml" diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index b73b4d34c67..f2f75d7b1ac 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -1,14 +1,26 @@ name: ESP32 Arduino CI on: + workflow_dispatch: push: branches: - master - release/* pull_request: +concurrency: + group: build-${{github.event.pull_request.number || github.ref}} + cancel-in-progress: true + jobs: - + + cmake-check: + name: Check cmake file + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: bash ./.github/scripts/check-cmakelists.sh + # Ubuntu build-arduino-linux: name: Arduino ${{ matrix.chunk }} on ubuntu-latest @@ -16,12 +28,22 @@ jobs: strategy: matrix: chunk: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] - + steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: python-version: '3.x' + - name: Cache tools + id: cache-linux + uses: actions/cache@v2 + with: + path: | + ./tools/dist + ~/arduino_ide + key: ${{ runner.os }}-${{ hashFiles('package/package_esp32_index.template.json', + 'tools/get.py', + '.github/scripts/install-arduino-ide.sh') }} - name: Build Sketches run: bash ./.github/scripts/on-push.sh ${{ matrix.chunk }} 15 @@ -32,7 +54,7 @@ jobs: strategy: matrix: os: [windows-latest, macOS-latest] - + steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 @@ -48,7 +70,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macOS-latest] - + steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 @@ -56,3 +78,30 @@ jobs: python-version: '3.x' - name: Build Sketches run: bash ./.github/scripts/on-push.sh 1 1 #equal and non-zero to trigger PIO + + build-esp-idf-component: + name: Build with ESP-IDF ${{ matrix.idf_ver }} for ${{ matrix.idf_target }} + runs-on: ubuntu-20.04 + strategy: + matrix: + # The version names here correspond to the versions of espressif/idf Docker image. + # See https://hub.docker.com/r/espressif/idf/tags and + # https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-docker-image.html + # for details. + idf_ver: ["release-v4.4"] + idf_target: ["esp32", "esp32s2", "esp32s3", "esp32c3"] + container: espressif/idf:${{ matrix.idf_ver }} + steps: + - name: Check out arduino-esp32 as a component + uses: actions/checkout@v2 + with: + submodules: recursive + path: components/arduino-esp32 + - name: Build + env: + IDF_TARGET: ${{ matrix.idf_target }} + shell: bash + run: | + . ${IDF_PATH}/export.sh + idf.py create-project test + idf.py -C test -DEXTRA_COMPONENT_DIRS=$PWD/components build diff --git a/.github/workflows/test_selfhosted_runner.yml b/.github/workflows/test_selfhosted_runner.yml deleted file mode 100644 index ddac78abbc3..00000000000 --- a/.github/workflows/test_selfhosted_runner.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Test Github action on self hosted RPI runnes - -on: - push: - branches: - - master - pull_request: - -jobs: - build: - name: Dummy test - self hosted GHR - runs-on: self-hosted - if: github.repository == 'espressif/arduino-esp32' - steps: - - name: Check out repo - uses: actions/checkout@v2 - - name: Test message 1 - run: echo "This is test message" - - name: Test message 2 - run: echo "This is test message2" - - name: List directory - run: ls - - name: Create copy of README - run: cp README.md README2.md - - name: Read README2 - run: cat README2.md - - name: Delete README2 - run: rm README2.md diff --git a/.github/workflows/upload-idf-component.yml b/.github/workflows/upload-idf-component.yml new file mode 100644 index 00000000000..d9e4032df08 --- /dev/null +++ b/.github/workflows/upload-idf-component.yml @@ -0,0 +1,19 @@ +name: Push components to https://components.espressif.com +on: + push: + tags: + - v* +jobs: + upload_components: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + submodules: "recursive" + + - name: Upload components to the component registry + uses: espressif/github-actions/upload_components@master + with: + name: arduino-esp32 + namespace: espressif + api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }} diff --git a/.gitignore b/.gitignore index 5114d19da5c..90f3ff87709 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ tools/xtensa-esp32-elf tools/xtensa-esp32s2-elf +tools/xtensa-esp32s3-elf tools/riscv32-esp-elf tools/dist tools/esptool @@ -22,3 +23,6 @@ boards.sloeber.txt # Ignore docs build (Sphinx) docs/build docs/source/_build + +# Test log files +*.log diff --git a/CMakeLists.txt b/CMakeLists.txt index 59d1ded8e80..1b0300fc743 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,7 @@ set(CORE_SRCS cores/esp32/stdlib_noniso.c cores/esp32/Stream.cpp cores/esp32/StreamString.cpp + cores/esp32/Tone.cpp cores/esp32/HWCDC.cpp cores/esp32/USB.cpp cores/esp32/USBCDC.cpp @@ -86,6 +87,7 @@ set(LIBRARY_SRCS libraries/HTTPClient/src/HTTPClient.cpp libraries/HTTPUpdate/src/HTTPUpdate.cpp libraries/LittleFS/src/LittleFS.cpp + libraries/I2S/src/I2S.cpp libraries/NetBIOS/src/NetBIOS.cpp libraries/Preferences/src/Preferences.cpp libraries/RainMaker/src/RMaker.cpp @@ -115,6 +117,7 @@ set(LIBRARY_SRCS libraries/WebServer/src/Parsing.cpp libraries/WebServer/src/detail/mimetable.cpp libraries/WiFiClientSecure/src/ssl_client.cpp + libraries/WiFiClientSecure/src/esp_crt_bundle.c libraries/WiFiClientSecure/src/WiFiClientSecure.cpp libraries/WiFi/src/WiFiAP.cpp libraries/WiFi/src/WiFiClient.cpp @@ -161,7 +164,6 @@ set(BLE_SRCS libraries/BLE/src/GeneralUtils.cpp ) - set(includedirs variants/${IDF_TARGET}/ cores/esp32/ @@ -173,11 +175,13 @@ set(includedirs libraries/EEPROM/src libraries/ESP32/src libraries/ESPmDNS/src + libraries/Ethernet/src libraries/FFat/src libraries/FS/src libraries/HTTPClient/src libraries/HTTPUpdate/src libraries/LittleFS/src + libraries/I2S/src libraries/NetBIOS/src libraries/Preferences/src libraries/RainMaker/src @@ -198,7 +202,7 @@ set(includedirs set(srcs ${CORE_SRCS} ${LIBRARY_SRCS} ${BLE_SRCS}) set(priv_includes cores/esp32/libb64) -set(requires spi_flash mbedtls mdns esp_adc_cal wifi_provisioning nghttp) +set(requires spi_flash mbedtls mdns esp_adc_cal wifi_provisioning nghttp wpa_supplicant) set(priv_requires fatfs nvs_flash app_update spiffs bootloader_support openssl bt esp_ipc esp_hid) idf_component_register(INCLUDE_DIRS ${includedirs} PRIV_INCLUDE_DIRS ${priv_includes} SRCS ${srcs} REQUIRES ${requires} PRIV_REQUIRES ${priv_requires}) @@ -233,7 +237,9 @@ function(maybe_add_component component_name) endif() endfunction() -if(IDF_TARGET MATCHES "esp32" AND CONFIG_ESP_RMAKER_TASK_STACK) +maybe_add_component(esp-dsp) + +if(CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK) maybe_add_component(esp_rainmaker) maybe_add_component(qrcode) endif() diff --git a/Makefile.projbuild b/Makefile.projbuild deleted file mode 100644 index 26b43787a6f..00000000000 --- a/Makefile.projbuild +++ /dev/null @@ -1,7 +0,0 @@ -BOOT_APP_BIN_ROOT := $(call dequote,$(COMPONENT_PATH)) - -ifndef CONFIG_PARTITION_TABLE_CUSTOM -PARTITION_TABLE_CSV_PATH = $(call dequote,$(abspath $(BOOT_APP_BIN_ROOT)/$(subst $(quote),,tools/partitions/$(CONFIG_ARDUHAL_PARTITION_SCHEME).csv))) -endif - -CPPFLAGS += -DARDUINO=10800 -DESP32=1 -DARDUINO_ARCH_ESP32=1 -DBOARD_HAS_PSRAM diff --git a/README.md b/README.md index 969a8f6fb11..0fb4c3a244b 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,18 @@ -# Arduino core for the ESP32, ESP32-S2 and ESP32-C3 +# Arduino core for the ESP32, ESP32-S2, ESP32-S3 and ESP32-C3 ![Build Status](https://github.com/espressif/arduino-esp32/workflows/ESP32%20Arduino%20CI/badge.svg) [![Documentation Status](https://readthedocs.com/projects/espressif-arduino-esp32/badge/?version=latest)](https://docs.espressif.com/projects/arduino-esp32/en/latest/?badge=latest) -### Need help or have a question? Join the chat at [![https://gitter.im/espressif/arduino-esp32](https://badges.gitter.im/espressif/arduino-esp32.svg)](https://gitter.im/espressif/arduino-esp32?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +### Need help or have a question? Join the chat at [![https://gitter.im/espressif/arduino-esp32](https://badges.gitter.im/espressif/arduino-esp32.svg)](https://gitter.im/espressif/arduino-esp32?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) or [open a new Discussion](https://github.com/espressif/arduino-esp32/discussions) ## Contents -- [Development Status](#development-status) -- [Decoding Exceptions](#decoding-exceptions) -- [Issue/Bug report template](#issuebug-report-template) + - [Development Status](#development-status) + - [Development Planning](#development-planning) + - [Documentation](#documentation) + - [Supported Chips](#supported-chips) + - [Decoding exceptions](#decoding-exceptions) + - [Issue/Bug report template](#issuebug-report-template) + - [Contributing](#contributing) ### Development Status @@ -16,9 +20,15 @@ Latest Stable Release [![Release Version](https://img.shields.io/github/release Latest Development Release [![Release Version](https://img.shields.io/github/release/espressif/arduino-esp32/all.svg?style=plastic)](https://github.com/espressif/arduino-esp32/releases/) [![Release Date](https://img.shields.io/github/release-date-pre/espressif/arduino-esp32.svg?style=plastic)](https://github.com/espressif/arduino-esp32/releases/) [![Downloads](https://img.shields.io/github/downloads-pre/espressif/arduino-esp32/latest/total.svg?style=plastic)](https://github.com/espressif/arduino-esp32/releases/) +### Development Planning + +Our Development is fully tracked on this public **[Roadmap 🎉](https://github.com/orgs/espressif/projects/3)** + +For even more information you can take a look at [Sprint Meeting notes](https://github.com/espressif/arduino-esp32/discussions/categories/sprints-meeting-notes) or join [Monthly Community Meetings 🔔](https://github.com/espressif/arduino-esp32/discussions/categories/monthly-community-meetings) + ### Documentation -You can use [Arduino-ESP32 Online Documentation](https://docs.espressif.com/projects/arduino-esp32/en/latest/) to get all information about this project. +You can use the [Arduino-ESP32 Online Documentation](https://docs.espressif.com/projects/arduino-esp32/en/latest/) to get all information about this project. * [Getting Started](https://docs.espressif.com/projects/arduino-esp32/en/latest/getting_started.html) * [Installing (Windows, Linux and macOS)](https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html) @@ -36,6 +46,7 @@ Visit the [supported chips](https://docs.espressif.com/projects/arduino-esp32/en You can use [EspExceptionDecoder](https://github.com/me-no-dev/EspExceptionDecoder) to get meaningful call trace. ### Issue/Bug report template + Before reporting an issue, make sure you've searched for similar one that was already created. Also make sure to go through all the issues labelled as [Type: For reference](https://github.com/espressif/arduino-esp32/issues?q=is%3Aissue+label%3A%22Type%3A+For+reference%22+). Finally, if you are sure no one else had the issue, follow the **Issue template** or **Feature request template** while reporting any [new Issue](https://github.com/espressif/arduino-esp32/issues/new/choose). diff --git a/boards.txt b/boards.txt index 2a74cdf751c..388dc6175a4 100644 --- a/boards.txt +++ b/boards.txt @@ -1,4 +1,5 @@ menu.UploadSpeed=Upload Speed +menu.USBMode=USB Mode menu.CDCOnBoot=USB CDC On Boot menu.MSCOnBoot=USB Firmware MSC On Boot menu.DFUOnBoot=USB DFU On Boot @@ -15,16 +16,232 @@ menu.LORAWAN_REGION=LoRaWan Region menu.LoRaWanDebugLevel=LoRaWan Debug Level menu.LoopCore=Arduino Runs On menu.EventsCore=Events Run On +menu.MemoryType=Memory Type ############################################################## ### DO NOT PUT BOARDS ABOVE THE OFFICIAL ESPRESSIF BOARDS! ### ############################################################## +esp32s3.name=ESP32S3 Dev Module +esp32s3.vid.0=0x303a +esp32s3.pid.0=0x1001 + +esp32s3.bootloader.tool=esptool_py +esp32s3.bootloader.tool.default=esptool_py + +esp32s3.upload.tool=esptool_py +esp32s3.upload.tool.default=esptool_py +esp32s3.upload.tool.network=esp_ota + +esp32s3.upload.maximum_size=1310720 +esp32s3.upload.maximum_data_size=327680 +esp32s3.upload.flags= +esp32s3.upload.extra_flags= +esp32s3.upload.use_1200bps_touch=false +esp32s3.upload.wait_for_upload_port=false + +esp32s3.serial.disableDTR=false +esp32s3.serial.disableRTS=false + +esp32s3.build.tarch=xtensa +esp32s3.build.bootloader_addr=0x0 +esp32s3.build.target=esp32s3 +esp32s3.build.mcu=esp32s3 +esp32s3.build.core=esp32 +esp32s3.build.variant=esp32s3 +esp32s3.build.board=ESP32S3_DEV + +esp32s3.build.usb_mode=1 +esp32s3.build.cdc_on_boot=0 +esp32s3.build.msc_on_boot=0 +esp32s3.build.dfu_on_boot=0 +esp32s3.build.f_cpu=240000000L +esp32s3.build.flash_size=4MB +esp32s3.build.flash_freq=80m +esp32s3.build.flash_mode=dio +esp32s3.build.boot=qio +esp32s3.build.boot_freq=80m +esp32s3.build.partitions=default +esp32s3.build.defines= +esp32s3.build.loop_core= +esp32s3.build.event_core= +esp32s3.build.flash_type=qspi +esp32s3.build.psram_type=qspi +esp32s3.build.memory_type={build.flash_type}_{build.psram_type} + +esp32s3.menu.PSRAM.disabled=Disabled +esp32s3.menu.PSRAM.disabled.build.defines= +esp32s3.menu.PSRAM.disabled.build.psram_type=qspi +esp32s3.menu.PSRAM.enabled=QSPI PSRAM +esp32s3.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM +esp32s3.menu.PSRAM.enabled.build.psram_type=qspi +esp32s3.menu.PSRAM.opi=OPI PSRAM +esp32s3.menu.PSRAM.opi.build.defines=-DBOARD_HAS_PSRAM +esp32s3.menu.PSRAM.opi.build.psram_type=opi + +esp32s3.menu.FlashMode.qio=QIO 80MHz +esp32s3.menu.FlashMode.qio.build.flash_mode=dio +esp32s3.menu.FlashMode.qio.build.boot=qio +esp32s3.menu.FlashMode.qio.build.boot_freq=80m +esp32s3.menu.FlashMode.qio.build.flash_freq=80m +esp32s3.menu.FlashMode.qio.build.flash_type=qspi +esp32s3.menu.FlashMode.qio120=QIO 120MHz +esp32s3.menu.FlashMode.qio120.build.flash_mode=dio +esp32s3.menu.FlashMode.qio120.build.boot=qio +esp32s3.menu.FlashMode.qio120.build.boot_freq=120m +esp32s3.menu.FlashMode.qio120.build.flash_freq=80m +esp32s3.menu.FlashMode.qio120.build.flash_type=qspi +esp32s3.menu.FlashMode.dio=DIO 80MHz +esp32s3.menu.FlashMode.dio.build.flash_mode=dio +esp32s3.menu.FlashMode.dio.build.boot=dio +esp32s3.menu.FlashMode.dio.build.boot_freq=80m +esp32s3.menu.FlashMode.dio.build.flash_freq=80m +esp32s3.menu.FlashMode.dio.build.flash_type=qspi +esp32s3.menu.FlashMode.opi=OPI 80MHz +esp32s3.menu.FlashMode.opi.build.flash_mode=dout +esp32s3.menu.FlashMode.opi.build.boot=opi +esp32s3.menu.FlashMode.opi.build.boot_freq=80m +esp32s3.menu.FlashMode.opi.build.flash_freq=80m +esp32s3.menu.FlashMode.opi.build.flash_type=opi + +esp32s3.menu.FlashSize.4M=4MB (32Mb) +esp32s3.menu.FlashSize.4M.build.flash_size=4MB +esp32s3.menu.FlashSize.8M=8MB (64Mb) +esp32s3.menu.FlashSize.8M.build.flash_size=8MB +esp32s3.menu.FlashSize.8M.build.partitions=default_8MB +esp32s3.menu.FlashSize.16M=16MB (128Mb) +esp32s3.menu.FlashSize.16M.build.flash_size=16MB +#esp32s3.menu.FlashSize.32M=32MB (256Mb) +#esp32s3.menu.FlashSize.32M.build.flash_size=32MB + +esp32s3.menu.LoopCore.1=Core 1 +esp32s3.menu.LoopCore.1.build.loop_core=-DARDUINO_RUNNING_CORE=1 +esp32s3.menu.LoopCore.0=Core 0 +esp32s3.menu.LoopCore.0.build.loop_core=-DARDUINO_RUNNING_CORE=0 + +esp32s3.menu.EventsCore.1=Core 1 +esp32s3.menu.EventsCore.1.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1 +esp32s3.menu.EventsCore.0=Core 0 +esp32s3.menu.EventsCore.0.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=0 + +esp32s3.menu.USBMode.hwcdc=Hardware CDC and JTAG +esp32s3.menu.USBMode.hwcdc.build.usb_mode=1 +esp32s3.menu.USBMode.default=USB-OTG (TinyUSB) +esp32s3.menu.USBMode.default.build.usb_mode=0 + +esp32s3.menu.CDCOnBoot.default=Disabled +esp32s3.menu.CDCOnBoot.default.build.cdc_on_boot=0 +esp32s3.menu.CDCOnBoot.cdc=Enabled +esp32s3.menu.CDCOnBoot.cdc.build.cdc_on_boot=1 + +esp32s3.menu.MSCOnBoot.default=Disabled +esp32s3.menu.MSCOnBoot.default.build.msc_on_boot=0 +esp32s3.menu.MSCOnBoot.msc=Enabled (Requires USB-OTG Mode) +esp32s3.menu.MSCOnBoot.msc.build.msc_on_boot=1 + +esp32s3.menu.DFUOnBoot.default=Disabled +esp32s3.menu.DFUOnBoot.default.build.dfu_on_boot=0 +esp32s3.menu.DFUOnBoot.dfu=Enabled (Requires USB-OTG Mode) +esp32s3.menu.DFUOnBoot.dfu.build.dfu_on_boot=1 + +esp32s3.menu.UploadMode.default=UART0 / Hardware CDC +esp32s3.menu.UploadMode.default.upload.use_1200bps_touch=false +esp32s3.menu.UploadMode.default.upload.wait_for_upload_port=false +esp32s3.menu.UploadMode.cdc=USB-OTG CDC (TinyUSB) +esp32s3.menu.UploadMode.cdc.upload.use_1200bps_touch=true +esp32s3.menu.UploadMode.cdc.upload.wait_for_upload_port=true + +esp32s3.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +esp32s3.menu.PartitionScheme.default.build.partitions=default +esp32s3.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +esp32s3.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +esp32s3.menu.PartitionScheme.default_8MB=8M Flash (3MB APP/1.5MB FAT) +esp32s3.menu.PartitionScheme.default_8MB.build.partitions=default_8MB +esp32s3.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 +esp32s3.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS) +esp32s3.menu.PartitionScheme.minimal.build.partitions=minimal +esp32s3.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +esp32s3.menu.PartitionScheme.no_ota.build.partitions=no_ota +esp32s3.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +esp32s3.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +esp32s3.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +esp32s3.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +esp32s3.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +esp32s3.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +esp32s3.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +esp32s3.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +esp32s3.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +esp32s3.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +esp32s3.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +esp32s3.menu.PartitionScheme.huge_app.build.partitions=huge_app +esp32s3.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 +esp32s3.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS) +esp32s3.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +esp32s3.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 +esp32s3.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FAT) +esp32s3.menu.PartitionScheme.fatflash.build.partitions=ffat +esp32s3.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 +esp32s3.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9MB FATFS) +esp32s3.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB +esp32s3.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 +esp32s3.menu.PartitionScheme.rainmaker=RainMaker +esp32s3.menu.PartitionScheme.rainmaker.build.partitions=rainmaker +esp32s3.menu.PartitionScheme.rainmaker.upload.maximum_size=3145728 + +esp32s3.menu.CPUFreq.240=240MHz (WiFi) +esp32s3.menu.CPUFreq.240.build.f_cpu=240000000L +esp32s3.menu.CPUFreq.160=160MHz (WiFi) +esp32s3.menu.CPUFreq.160.build.f_cpu=160000000L +esp32s3.menu.CPUFreq.80=80MHz (WiFi) +esp32s3.menu.CPUFreq.80.build.f_cpu=80000000L +esp32s3.menu.CPUFreq.40=40MHz +esp32s3.menu.CPUFreq.40.build.f_cpu=40000000L +esp32s3.menu.CPUFreq.20=20MHz +esp32s3.menu.CPUFreq.20.build.f_cpu=20000000L +esp32s3.menu.CPUFreq.10=10MHz +esp32s3.menu.CPUFreq.10.build.f_cpu=10000000L + +esp32s3.menu.UploadSpeed.921600=921600 +esp32s3.menu.UploadSpeed.921600.upload.speed=921600 +esp32s3.menu.UploadSpeed.115200=115200 +esp32s3.menu.UploadSpeed.115200.upload.speed=115200 +esp32s3.menu.UploadSpeed.256000.windows=256000 +esp32s3.menu.UploadSpeed.256000.upload.speed=256000 +esp32s3.menu.UploadSpeed.230400.windows.upload.speed=256000 +esp32s3.menu.UploadSpeed.230400=230400 +esp32s3.menu.UploadSpeed.230400.upload.speed=230400 +esp32s3.menu.UploadSpeed.460800.linux=460800 +esp32s3.menu.UploadSpeed.460800.macosx=460800 +esp32s3.menu.UploadSpeed.460800.upload.speed=460800 +esp32s3.menu.UploadSpeed.512000.windows=512000 +esp32s3.menu.UploadSpeed.512000.upload.speed=512000 + +esp32s3.menu.DebugLevel.none=None +esp32s3.menu.DebugLevel.none.build.code_debug=0 +esp32s3.menu.DebugLevel.error=Error +esp32s3.menu.DebugLevel.error.build.code_debug=1 +esp32s3.menu.DebugLevel.warn=Warn +esp32s3.menu.DebugLevel.warn.build.code_debug=2 +esp32s3.menu.DebugLevel.info=Info +esp32s3.menu.DebugLevel.info.build.code_debug=3 +esp32s3.menu.DebugLevel.debug=Debug +esp32s3.menu.DebugLevel.debug.build.code_debug=4 +esp32s3.menu.DebugLevel.verbose=Verbose +esp32s3.menu.DebugLevel.verbose.build.code_debug=5 + +############################################################## + esp32c3.name=ESP32C3 Dev Module esp32c3.vid.0=0x303a esp32c3.pid.0=0x1001 +esp32c3.bootloader.tool=esptool_py +esp32c3.bootloader.tool.default=esptool_py + esp32c3.upload.tool=esptool_py +esp32c3.upload.tool.default=esptool_py +esp32c3.upload.tool.network=esp_ota + esp32c3.upload.maximum_size=1310720 esp32c3.upload.maximum_data_size=327680 esp32c3.upload.flags= @@ -90,6 +307,9 @@ esp32c3.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 esp32c3.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9MB FATFS) esp32c3.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB esp32c3.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 +esp32c3.menu.PartitionScheme.rainmaker=RainMaker +esp32c3.menu.PartitionScheme.rainmaker.build.partitions=rainmaker +esp32c3.menu.PartitionScheme.rainmaker.upload.maximum_size=3145728 esp32c3.menu.CPUFreq.160=160MHz (WiFi) esp32c3.menu.CPUFreq.160.build.f_cpu=160000000L @@ -165,7 +385,13 @@ esp32s2.name=ESP32S2 Dev Module esp32s2.vid.0=0x303a esp32s2.pid.0=0x0002 +esp32s2.bootloader.tool=esptool_py +esp32s2.bootloader.tool.default=esptool_py + esp32s2.upload.tool=esptool_py +esp32s2.upload.tool.default=esptool_py +esp32s2.upload.tool.network=esp_ota + esp32s2.upload.maximum_size=1310720 esp32s2.upload.maximum_data_size=327680 esp32s2.upload.flags= @@ -255,6 +481,9 @@ esp32s2.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 esp32s2.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9MB FATFS) esp32s2.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB esp32s2.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 +esp32s2.menu.PartitionScheme.rainmaker=RainMaker +esp32s2.menu.PartitionScheme.rainmaker.build.partitions=rainmaker +esp32s2.menu.PartitionScheme.rainmaker.upload.maximum_size=3145728 esp32s2.menu.CPUFreq.240=240MHz (WiFi) esp32s2.menu.CPUFreq.240.build.f_cpu=240000000L @@ -330,7 +559,13 @@ esp32s2.menu.DebugLevel.verbose.build.code_debug=5 esp32.name=ESP32 Dev Module +esp32.bootloader.tool=esptool_py +esp32.bootloader.tool.default=esptool_py + esp32.upload.tool=esptool_py +esp32.upload.tool.default=esptool_py +esp32.upload.tool.network=esp_ota + esp32.upload.maximum_size=1310720 esp32.upload.maximum_data_size=327680 esp32.upload.flags= @@ -487,9 +722,170 @@ esp32.menu.DebugLevel.verbose.build.code_debug=5 ############################################################## +esp32da.name=ESP32-WROOM-DA Module + +esp32da.bootloader.tool=esptool_py +esp32da.bootloader.tool.default=esptool_py + +esp32da.upload.tool=esptool_py +esp32da.upload.tool.default=esptool_py +esp32da.upload.tool.network=esp_ota + +esp32da.upload.maximum_size=1310720 +esp32da.upload.maximum_data_size=327680 +esp32da.upload.flags= +esp32da.upload.extra_flags= + +esp32da.serial.disableDTR=true +esp32da.serial.disableRTS=true + +esp32da.build.tarch=xtensa +esp32da.build.bootloader_addr=0x1000 +esp32da.build.target=esp32 +esp32da.build.mcu=esp32 +esp32da.build.core=esp32 +esp32da.build.variant=esp32da +esp32da.build.board=ESP32_WROOM_DA + +esp32da.build.f_cpu=240000000L +esp32da.build.flash_size=4MB +esp32da.build.flash_freq=40m +esp32da.build.flash_mode=dio +esp32da.build.boot=dio +esp32da.build.partitions=default +esp32da.build.defines= +esp32da.build.loop_core= +esp32da.build.event_core= + +esp32da.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +esp32da.menu.PartitionScheme.default.build.partitions=default +esp32da.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +esp32da.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +esp32da.menu.PartitionScheme.default_8MB=8M Flash (3MB APP/1.5MB FAT) +esp32da.menu.PartitionScheme.default_8MB.build.partitions=default_8MB +esp32da.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 +esp32da.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS) +esp32da.menu.PartitionScheme.minimal.build.partitions=minimal +esp32da.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +esp32da.menu.PartitionScheme.no_ota.build.partitions=no_ota +esp32da.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +esp32da.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +esp32da.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +esp32da.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +esp32da.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +esp32da.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +esp32da.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +esp32da.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +esp32da.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +esp32da.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +esp32da.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +esp32da.menu.PartitionScheme.huge_app.build.partitions=huge_app +esp32da.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 +esp32da.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS) +esp32da.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +esp32da.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 +esp32da.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FAT) +esp32da.menu.PartitionScheme.fatflash.build.partitions=ffat +esp32da.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 +esp32da.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9MB FATFS) +esp32da.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB +esp32da.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 +esp32da.menu.PartitionScheme.rainmaker=RainMaker +esp32da.menu.PartitionScheme.rainmaker.build.partitions=rainmaker +esp32da.menu.PartitionScheme.rainmaker.upload.maximum_size=3145728 + +esp32da.menu.CPUFreq.240=240MHz (WiFi/BT) +esp32da.menu.CPUFreq.240.build.f_cpu=240000000L +esp32da.menu.CPUFreq.160=160MHz (WiFi/BT) +esp32da.menu.CPUFreq.160.build.f_cpu=160000000L +esp32da.menu.CPUFreq.80=80MHz (WiFi/BT) +esp32da.menu.CPUFreq.80.build.f_cpu=80000000L +esp32da.menu.CPUFreq.40=40MHz (40MHz XTAL) +esp32da.menu.CPUFreq.40.build.f_cpu=40000000L +esp32da.menu.CPUFreq.26=26MHz (26MHz XTAL) +esp32da.menu.CPUFreq.26.build.f_cpu=26000000L +esp32da.menu.CPUFreq.20=20MHz (40MHz XTAL) +esp32da.menu.CPUFreq.20.build.f_cpu=20000000L +esp32da.menu.CPUFreq.13=13MHz (26MHz XTAL) +esp32da.menu.CPUFreq.13.build.f_cpu=13000000L +esp32da.menu.CPUFreq.10=10MHz (40MHz XTAL) +esp32da.menu.CPUFreq.10.build.f_cpu=10000000L + +esp32da.menu.FlashMode.qio=QIO +esp32da.menu.FlashMode.qio.build.flash_mode=dio +esp32da.menu.FlashMode.qio.build.boot=qio +esp32da.menu.FlashMode.dio=DIO +esp32da.menu.FlashMode.dio.build.flash_mode=dio +esp32da.menu.FlashMode.dio.build.boot=dio +esp32da.menu.FlashMode.qout=QOUT +esp32da.menu.FlashMode.qout.build.flash_mode=dout +esp32da.menu.FlashMode.qout.build.boot=qout +esp32da.menu.FlashMode.dout=DOUT +esp32da.menu.FlashMode.dout.build.flash_mode=dout +esp32da.menu.FlashMode.dout.build.boot=dout + +esp32da.menu.FlashFreq.80=80MHz +esp32da.menu.FlashFreq.80.build.flash_freq=80m +esp32da.menu.FlashFreq.40=40MHz +esp32da.menu.FlashFreq.40.build.flash_freq=40m + +esp32da.menu.FlashSize.4M=4MB (32Mb) +esp32da.menu.FlashSize.4M.build.flash_size=4MB +esp32da.menu.FlashSize.8M=8MB (64Mb) +esp32da.menu.FlashSize.8M.build.flash_size=8MB +esp32da.menu.FlashSize.8M.build.partitions=default_8MB +esp32da.menu.FlashSize.16M=16MB (128Mb) +esp32da.menu.FlashSize.16M.build.flash_size=16MB + +esp32da.menu.UploadSpeed.921600=921600 +esp32da.menu.UploadSpeed.921600.upload.speed=921600 +esp32da.menu.UploadSpeed.115200=115200 +esp32da.menu.UploadSpeed.115200.upload.speed=115200 +esp32da.menu.UploadSpeed.256000.windows=256000 +esp32da.menu.UploadSpeed.256000.upload.speed=256000 +esp32da.menu.UploadSpeed.230400.windows.upload.speed=256000 +esp32da.menu.UploadSpeed.230400=230400 +esp32da.menu.UploadSpeed.230400.upload.speed=230400 +esp32da.menu.UploadSpeed.460800.linux=460800 +esp32da.menu.UploadSpeed.460800.macosx=460800 +esp32da.menu.UploadSpeed.460800.upload.speed=460800 +esp32da.menu.UploadSpeed.512000.windows=512000 +esp32da.menu.UploadSpeed.512000.upload.speed=512000 + +esp32da.menu.LoopCore.1=Core 1 +esp32da.menu.LoopCore.1.build.loop_core=-DARDUINO_RUNNING_CORE=1 +esp32da.menu.LoopCore.0=Core 0 +esp32da.menu.LoopCore.0.build.loop_core=-DARDUINO_RUNNING_CORE=0 + +esp32da.menu.EventsCore.1=Core 1 +esp32da.menu.EventsCore.1.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1 +esp32da.menu.EventsCore.0=Core 0 +esp32da.menu.EventsCore.0.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=0 + +esp32da.menu.DebugLevel.none=None +esp32da.menu.DebugLevel.none.build.code_debug=0 +esp32da.menu.DebugLevel.error=Error +esp32da.menu.DebugLevel.error.build.code_debug=1 +esp32da.menu.DebugLevel.warn=Warn +esp32da.menu.DebugLevel.warn.build.code_debug=2 +esp32da.menu.DebugLevel.info=Info +esp32da.menu.DebugLevel.info.build.code_debug=3 +esp32da.menu.DebugLevel.debug=Debug +esp32da.menu.DebugLevel.debug.build.code_debug=4 +esp32da.menu.DebugLevel.verbose=Verbose +esp32da.menu.DebugLevel.verbose.build.code_debug=5 + +############################################################## + esp32wrover.name=ESP32 Wrover Module +esp32wrover.bootloader.tool=esptool_py +esp32wrover.bootloader.tool.default=esptool_py + esp32wrover.upload.tool=esptool_py +esp32wrover.upload.tool.default=esptool_py +esp32wrover.upload.tool.network=esp_ota + esp32wrover.upload.maximum_size=1310720 esp32wrover.upload.maximum_data_size=327680 esp32wrover.upload.flags= @@ -594,7 +990,13 @@ esp32wrover.menu.DebugLevel.verbose.build.code_debug=5 pico32.name=ESP32 PICO-D4 +pico32.bootloader.tool=esptool_py +pico32.bootloader.tool.default=esptool_py + pico32.upload.tool=esptool_py +pico32.upload.tool.default=esptool_py +pico32.upload.tool.network=esp_ota + pico32.upload.maximum_size=1310720 pico32.upload.maximum_data_size=327680 pico32.upload.flags= @@ -658,11 +1060,352 @@ pico32.menu.DebugLevel.verbose.build.code_debug=5 ############################################################## +esp32s3box.name=ESP32-S3-Box +esp32s3box.vid.0=0x303a +esp32s3box.pid.0=0x1001 + +esp32s3box.bootloader.tool=esptool_py +esp32s3box.bootloader.tool.default=esptool_py + +esp32s3box.upload.tool=esptool_py +esp32s3box.upload.tool.default=esptool_py +esp32s3box.upload.tool.network=esp_ota + +esp32s3box.upload.maximum_size=1310720 +esp32s3box.upload.maximum_data_size=327680 +esp32s3box.upload.speed=921600 +esp32s3box.upload.flags= +esp32s3box.upload.extra_flags= +esp32s3box.upload.use_1200bps_touch=false +esp32s3box.upload.wait_for_upload_port=false + +esp32s3box.serial.disableDTR=false +esp32s3box.serial.disableRTS=false + +esp32s3box.build.tarch=xtensa +esp32s3box.build.bootloader_addr=0x0 +esp32s3box.build.target=esp32s3 +esp32s3box.build.mcu=esp32s3 +esp32s3box.build.core=esp32 +esp32s3box.build.variant=esp32s3box +esp32s3box.build.board=ESP32_S3_BOX + +esp32s3box.build.usb_mode=1 +esp32s3box.build.cdc_on_boot=1 +esp32s3box.build.msc_on_boot=0 +esp32s3box.build.dfu_on_boot=0 +esp32s3box.build.f_cpu=240000000L +esp32s3box.build.flash_size=16MB +esp32s3box.build.flash_freq=80m +esp32s3box.build.flash_mode=dio +esp32s3box.build.boot=qio +esp32s3box.build.partitions=default +esp32s3box.build.defines=-DBOARD_HAS_PSRAM +esp32s3box.build.memory_type=qspi_opi +esp32s3box.build.loop_core=-DARDUINO_RUNNING_CORE=1 +esp32s3box.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1 + +esp32s3box.menu.USBMode.hwcdc=Hardware CDC and JTAG +esp32s3box.menu.USBMode.hwcdc.build.usb_mode=1 +esp32s3box.menu.USBMode.hwcdc.upload.use_1200bps_touch=false +esp32s3box.menu.USBMode.hwcdc.upload.wait_for_upload_port=false +esp32s3box.menu.USBMode.default=USB-OTG +esp32s3box.menu.USBMode.default.build.usb_mode=0 +esp32s3box.menu.USBMode.default.upload.use_1200bps_touch=true +esp32s3box.menu.USBMode.default.upload.wait_for_upload_port=true + +esp32s3box.menu.MSCOnBoot.default=Disabled +esp32s3box.menu.MSCOnBoot.default.build.msc_on_boot=0 +esp32s3box.menu.MSCOnBoot.msc=Enabled (Requires USB-OTG Mode) +esp32s3box.menu.MSCOnBoot.msc.build.msc_on_boot=1 + +esp32s3box.menu.DFUOnBoot.default=Disabled +esp32s3box.menu.DFUOnBoot.default.build.dfu_on_boot=0 +esp32s3box.menu.DFUOnBoot.dfu=Enabled (Requires USB-OTG Mode) +esp32s3box.menu.DFUOnBoot.dfu.build.dfu_on_boot=1 + +esp32s3box.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +esp32s3box.menu.PartitionScheme.default.build.partitions=default +esp32s3box.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +esp32s3box.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +esp32s3box.menu.PartitionScheme.default_8MB=8M Flash (3MB APP/1.5MB FAT) +esp32s3box.menu.PartitionScheme.default_8MB.build.partitions=default_8MB +esp32s3box.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 +esp32s3box.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +esp32s3box.menu.PartitionScheme.no_ota.build.partitions=no_ota +esp32s3box.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +esp32s3box.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +esp32s3box.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +esp32s3box.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +esp32s3box.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +esp32s3box.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +esp32s3box.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +esp32s3box.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +esp32s3box.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +esp32s3box.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +esp32s3box.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +esp32s3box.menu.PartitionScheme.huge_app.build.partitions=huge_app +esp32s3box.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 +esp32s3box.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS) +esp32s3box.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +esp32s3box.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 +esp32s3box.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FAT) +esp32s3box.menu.PartitionScheme.fatflash.build.partitions=ffat +esp32s3box.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 +esp32s3box.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9MB FATFS) +esp32s3box.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB +esp32s3box.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 + +esp32s3box.menu.DebugLevel.none=None +esp32s3box.menu.DebugLevel.none.build.code_debug=0 +esp32s3box.menu.DebugLevel.error=Error +esp32s3box.menu.DebugLevel.error.build.code_debug=1 +esp32s3box.menu.DebugLevel.warn=Warn +esp32s3box.menu.DebugLevel.warn.build.code_debug=2 +esp32s3box.menu.DebugLevel.info=Info +esp32s3box.menu.DebugLevel.info.build.code_debug=3 +esp32s3box.menu.DebugLevel.debug=Debug +esp32s3box.menu.DebugLevel.debug.build.code_debug=4 +esp32s3box.menu.DebugLevel.verbose=Verbose +esp32s3box.menu.DebugLevel.verbose.build.code_debug=5 + +############################################################## + +esp32s3usbotg.name=ESP32-S3-USB-OTG +esp32s3usbotg.vid.0=0x303a +esp32s3usbotg.pid.0=0x1001 + +esp32s3usbotg.bootloader.tool=esptool_py +esp32s3usbotg.bootloader.tool.default=esptool_py + +esp32s3usbotg.upload.tool=esptool_py +esp32s3usbotg.upload.tool.default=esptool_py +esp32s3usbotg.upload.tool.network=esp_ota + +esp32s3usbotg.upload.maximum_size=1310720 +esp32s3usbotg.upload.maximum_data_size=327680 +esp32s3usbotg.upload.speed=921600 +esp32s3usbotg.upload.flags= +esp32s3usbotg.upload.extra_flags= +esp32s3usbotg.upload.use_1200bps_touch=false +esp32s3usbotg.upload.wait_for_upload_port=false + +esp32s3usbotg.serial.disableDTR=false +esp32s3usbotg.serial.disableRTS=false + +esp32s3usbotg.build.tarch=xtensa +esp32s3usbotg.build.bootloader_addr=0x0 +esp32s3usbotg.build.target=esp32s3 +esp32s3usbotg.build.mcu=esp32s3 +esp32s3usbotg.build.core=esp32 +esp32s3usbotg.build.variant=esp32s3usbotg +esp32s3usbotg.build.board=ESP32_S3_USB_OTG + +esp32s3usbotg.build.usb_mode=0 +esp32s3usbotg.build.cdc_on_boot=0 +esp32s3usbotg.build.msc_on_boot=0 +esp32s3usbotg.build.dfu_on_boot=0 +esp32s3usbotg.build.f_cpu=240000000L +esp32s3usbotg.build.flash_size=8MB +esp32s3usbotg.build.flash_freq=80m +esp32s3usbotg.build.flash_mode=dio +esp32s3usbotg.build.boot=qio +esp32s3usbotg.build.partitions=default +esp32s3usbotg.build.defines= +esp32s3usbotg.build.memory_type=qspi_qspi +esp32s3usbotg.build.loop_core=-DARDUINO_RUNNING_CORE=1 +esp32s3usbotg.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1 + +esp32s3usbotg.menu.USBMode.default=USB-OTG +esp32s3usbotg.menu.USBMode.default.build.usb_mode=0 +esp32s3usbotg.menu.USBMode.default.build.cdc_on_boot=0 +esp32s3usbotg.menu.USBMode.hwcdc=Hardware CDC and JTAG +esp32s3usbotg.menu.USBMode.hwcdc.build.usb_mode=1 +esp32s3usbotg.menu.USBMode.hwcdc.build.cdc_on_boot=1 + +esp32s3usbotg.menu.UploadMode.default=UART0 / Hardware CDC +esp32s3usbotg.menu.UploadMode.default.upload.use_1200bps_touch=false +esp32s3usbotg.menu.UploadMode.default.upload.wait_for_upload_port=false +esp32s3usbotg.menu.UploadMode.cdc=USB-OTG CDC (TinyUSB) +esp32s3usbotg.menu.UploadMode.cdc.upload.use_1200bps_touch=true +esp32s3usbotg.menu.UploadMode.cdc.upload.wait_for_upload_port=true + +esp32s3usbotg.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +esp32s3usbotg.menu.PartitionScheme.default.build.partitions=default +esp32s3usbotg.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +esp32s3usbotg.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +esp32s3usbotg.menu.PartitionScheme.default_8MB=8M Flash (3MB APP/1.5MB FAT) +esp32s3usbotg.menu.PartitionScheme.default_8MB.build.partitions=default_8MB +esp32s3usbotg.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 +esp32s3usbotg.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +esp32s3usbotg.menu.PartitionScheme.no_ota.build.partitions=no_ota +esp32s3usbotg.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +esp32s3usbotg.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +esp32s3usbotg.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +esp32s3usbotg.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +esp32s3usbotg.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +esp32s3usbotg.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +esp32s3usbotg.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +esp32s3usbotg.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +esp32s3usbotg.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +esp32s3usbotg.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +esp32s3usbotg.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +esp32s3usbotg.menu.PartitionScheme.huge_app.build.partitions=huge_app +esp32s3usbotg.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 +esp32s3usbotg.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS) +esp32s3usbotg.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +esp32s3usbotg.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 +esp32s3usbotg.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FAT) +esp32s3usbotg.menu.PartitionScheme.fatflash.build.partitions=ffat +esp32s3usbotg.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 +esp32s3usbotg.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9MB FATFS) +esp32s3usbotg.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB +esp32s3usbotg.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 + +esp32s3usbotg.menu.DebugLevel.none=None +esp32s3usbotg.menu.DebugLevel.none.build.code_debug=0 +esp32s3usbotg.menu.DebugLevel.error=Error +esp32s3usbotg.menu.DebugLevel.error.build.code_debug=1 +esp32s3usbotg.menu.DebugLevel.warn=Warn +esp32s3usbotg.menu.DebugLevel.warn.build.code_debug=2 +esp32s3usbotg.menu.DebugLevel.info=Info +esp32s3usbotg.menu.DebugLevel.info.build.code_debug=3 +esp32s3usbotg.menu.DebugLevel.debug=Debug +esp32s3usbotg.menu.DebugLevel.debug.build.code_debug=4 +esp32s3usbotg.menu.DebugLevel.verbose=Verbose +esp32s3usbotg.menu.DebugLevel.verbose.build.code_debug=5 + +############################################################## + +esp32s3camlcd.name=ESP32S3 CAM LCD +esp32s3camlcd.vid.0=0x303a +esp32s3camlcd.pid.0=0x1001 + +esp32s3camlcd.bootloader.tool=esptool_py +esp32s3camlcd.bootloader.tool.default=esptool_py + +esp32s3camlcd.upload.tool=esptool_py +esp32s3camlcd.upload.tool.default=esptool_py +esp32s3camlcd.upload.tool.network=esp_ota + +esp32s3camlcd.upload.maximum_size=1310720 +esp32s3camlcd.upload.maximum_data_size=327680 +esp32s3camlcd.upload.flags= +esp32s3camlcd.upload.extra_flags= +esp32s3camlcd.upload.use_1200bps_touch=false +esp32s3camlcd.upload.wait_for_upload_port=false + +esp32s3camlcd.serial.disableDTR=false +esp32s3camlcd.serial.disableRTS=false + +esp32s3camlcd.build.tarch=xtensa +esp32s3camlcd.build.bootloader_addr=0x0 +esp32s3camlcd.build.target=esp32s3 +esp32s3camlcd.build.mcu=esp32s3 +esp32s3camlcd.build.core=esp32 +esp32s3camlcd.build.variant=esp32s3camlcd +esp32s3camlcd.build.board=ESP32S3_CAM_LCD + +esp32s3camlcd.build.usb_mode=1 +esp32s3camlcd.build.cdc_on_boot=0 +esp32s3camlcd.build.msc_on_boot=0 +esp32s3camlcd.build.dfu_on_boot=0 +esp32s3camlcd.build.f_cpu=240000000L +esp32s3camlcd.build.flash_size=4MB +esp32s3camlcd.build.flash_freq=80m +esp32s3camlcd.build.flash_mode=dout +esp32s3camlcd.build.boot=opi +esp32s3camlcd.build.partitions=default +esp32s3camlcd.build.defines=-DBOARD_HAS_PSRAM +esp32s3camlcd.build.memory_type=opi_opi +esp32s3camlcd.build.loop_core= +esp32s3camlcd.build.event_core= + +esp32s3camlcd.menu.LoopCore.1=Core 1 +esp32s3camlcd.menu.LoopCore.1.build.loop_core=-DARDUINO_RUNNING_CORE=1 +esp32s3camlcd.menu.LoopCore.0=Core 0 +esp32s3camlcd.menu.LoopCore.0.build.loop_core=-DARDUINO_RUNNING_CORE=0 + +esp32s3camlcd.menu.EventsCore.1=Core 1 +esp32s3camlcd.menu.EventsCore.1.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1 +esp32s3camlcd.menu.EventsCore.0=Core 0 +esp32s3camlcd.menu.EventsCore.0.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=0 + +esp32s3camlcd.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +esp32s3camlcd.menu.PartitionScheme.default.build.partitions=default +esp32s3camlcd.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +esp32s3camlcd.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +esp32s3camlcd.menu.PartitionScheme.default_8MB=8M Flash (3MB APP/1.5MB FAT) +esp32s3camlcd.menu.PartitionScheme.default_8MB.build.partitions=default_8MB +esp32s3camlcd.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 +esp32s3camlcd.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS) +esp32s3camlcd.menu.PartitionScheme.minimal.build.partitions=minimal +esp32s3camlcd.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +esp32s3camlcd.menu.PartitionScheme.no_ota.build.partitions=no_ota +esp32s3camlcd.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +esp32s3camlcd.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +esp32s3camlcd.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +esp32s3camlcd.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +esp32s3camlcd.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +esp32s3camlcd.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +esp32s3camlcd.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +esp32s3camlcd.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +esp32s3camlcd.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +esp32s3camlcd.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +esp32s3camlcd.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +esp32s3camlcd.menu.PartitionScheme.huge_app.build.partitions=huge_app +esp32s3camlcd.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 +esp32s3camlcd.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS) +esp32s3camlcd.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +esp32s3camlcd.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 +esp32s3camlcd.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FAT) +esp32s3camlcd.menu.PartitionScheme.fatflash.build.partitions=ffat +esp32s3camlcd.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 +esp32s3camlcd.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9MB FATFS) +esp32s3camlcd.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB +esp32s3camlcd.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 + +esp32s3camlcd.menu.UploadSpeed.921600=921600 +esp32s3camlcd.menu.UploadSpeed.921600.upload.speed=921600 +esp32s3camlcd.menu.UploadSpeed.115200=115200 +esp32s3camlcd.menu.UploadSpeed.115200.upload.speed=115200 +esp32s3camlcd.menu.UploadSpeed.256000.windows=256000 +esp32s3camlcd.menu.UploadSpeed.256000.upload.speed=256000 +esp32s3camlcd.menu.UploadSpeed.230400.windows.upload.speed=256000 +esp32s3camlcd.menu.UploadSpeed.230400=230400 +esp32s3camlcd.menu.UploadSpeed.230400.upload.speed=230400 +esp32s3camlcd.menu.UploadSpeed.460800.linux=460800 +esp32s3camlcd.menu.UploadSpeed.460800.macosx=460800 +esp32s3camlcd.menu.UploadSpeed.460800.upload.speed=460800 +esp32s3camlcd.menu.UploadSpeed.512000.windows=512000 +esp32s3camlcd.menu.UploadSpeed.512000.upload.speed=512000 + +esp32s3camlcd.menu.DebugLevel.none=None +esp32s3camlcd.menu.DebugLevel.none.build.code_debug=0 +esp32s3camlcd.menu.DebugLevel.error=Error +esp32s3camlcd.menu.DebugLevel.error.build.code_debug=1 +esp32s3camlcd.menu.DebugLevel.warn=Warn +esp32s3camlcd.menu.DebugLevel.warn.build.code_debug=2 +esp32s3camlcd.menu.DebugLevel.info=Info +esp32s3camlcd.menu.DebugLevel.info.build.code_debug=3 +esp32s3camlcd.menu.DebugLevel.debug=Debug +esp32s3camlcd.menu.DebugLevel.debug.build.code_debug=4 +esp32s3camlcd.menu.DebugLevel.verbose=Verbose +esp32s3camlcd.menu.DebugLevel.verbose.build.code_debug=5 + +############################################################## + esp32s2usb.name=ESP32S2 Native USB esp32s2usb.vid.0=0x303a esp32s2usb.pid.0=0x0003 +esp32s2usb.bootloader.tool=esptool_py +esp32s2usb.bootloader.tool.default=esptool_py + esp32s2usb.upload.tool=esptool_py +esp32s2usb.upload.tool.default=esptool_py +esp32s2usb.upload.tool.network=esp_ota + esp32s2usb.upload.maximum_size=1310720 esp32s2usb.upload.maximum_data_size=327680 esp32s2usb.upload.flags= @@ -756,7 +1499,13 @@ esp32s2usb.menu.DebugLevel.verbose.build.code_debug=5 ############################################################## esp32wroverkit.name=ESP32 Wrover Kit (all versions) +esp32wroverkit.bootloader.tool=esptool_py +esp32wroverkit.bootloader.tool.default=esptool_py + esp32wroverkit.upload.tool=esptool_py +esp32wroverkit.upload.tool.default=esptool_py +esp32wroverkit.upload.tool.network=esp_ota + esp32wroverkit.upload.maximum_size=1310720 esp32wroverkit.upload.maximum_data_size=327680 esp32wroverkit.upload.flags= @@ -878,9 +1627,16 @@ esp32wroverkit.menu.DebugLevel.verbose=Verbose esp32wroverkit.menu.DebugLevel.verbose.build.code_debug=5 ############################################################## + tinypico.name=UM TinyPICO +tinypico.bootloader.tool=esptool_py +tinypico.bootloader.tool.default=esptool_py + tinypico.upload.tool=esptool_py +tinypico.upload.tool.default=esptool_py +tinypico.upload.tool.network=esp_ota + tinypico.upload.maximum_size=1310720 tinypico.upload.maximum_data_size=327680 tinypico.upload.flags= @@ -962,11 +1718,18 @@ tinypico.menu.DebugLevel.verbose=Verbose tinypico.menu.DebugLevel.verbose.build.code_debug=5 ############################################################## + feathers2.name=UM FeatherS2 feathers2.vid.0=0x239A feathers2.pid.0=0x80AB +feathers2.bootloader.tool=esptool_py +feathers2.bootloader.tool.default=esptool_py + feathers2.upload.tool=esptool_py +feathers2.upload.tool.default=esptool_py +feathers2.upload.tool.network=esp_ota + feathers2.upload.maximum_size=1310720 feathers2.upload.maximum_data_size=327680 feathers2.upload.flags= @@ -1101,11 +1864,18 @@ feathers2.menu.DebugLevel.verbose=Verbose feathers2.menu.DebugLevel.verbose.build.code_debug=5 ############################################################## + feathers2neo.name=UM FeatherS2 Neo feathers2neo.vid.0=0x303a feathers2neo.pid.0=0x80B4 +feathers2neo.bootloader.tool=esptool_py +feathers2neo.bootloader.tool.default=esptool_py + feathers2neo.upload.tool=esptool_py +feathers2neo.upload.tool.default=esptool_py +feathers2neo.upload.tool.network=esp_ota + feathers2neo.upload.maximum_size=1310720 feathers2neo.upload.maximum_data_size=327680 feathers2neo.upload.flags= @@ -1226,11 +1996,18 @@ feathers2neo.menu.DebugLevel.verbose=Verbose feathers2neo.menu.DebugLevel.verbose.build.code_debug=5 ############################################################## + tinys2.name=UM TinyS2 tinys2.vid.0=0x303a tinys2.pid.0=0x8001 +tinys2.bootloader.tool=esptool_py +tinys2.bootloader.tool.default=esptool_py + tinys2.upload.tool=esptool_py +tinys2.upload.tool.default=esptool_py +tinys2.upload.tool.network=esp_ota + tinys2.upload.maximum_size=1310720 tinys2.upload.maximum_data_size=327680 tinys2.upload.flags= @@ -1351,9 +2128,599 @@ tinys2.menu.DebugLevel.verbose=Verbose tinys2.menu.DebugLevel.verbose.build.code_debug=5 ############################################################## +rmp.name=UM RMP +rmp.vid.0=0x303a +rmp.pid.0=0x80F6 + +rmp.upload.tool=esptool_py +rmp.upload.maximum_size=1310720 +rmp.upload.maximum_data_size=327680 +rmp.upload.flags= +rmp.upload.extra_flags= +rmp.upload.use_1200bps_touch=true +rmp.upload.wait_for_upload_port=true + +rmp.serial.disableDTR=false +rmp.serial.disableRTS=false + +rmp.build.tarch=xtensa +rmp.build.bootloader_addr=0x1000 +rmp.build.target=esp32s2 +rmp.build.mcu=esp32s2 +rmp.build.core=esp32 +rmp.build.variant=um_rmp +rmp.build.board=RMP + +rmp.build.cdc_on_boot=1 +rmp.build.msc_on_boot=0 +rmp.build.dfu_on_boot=0 +rmp.build.f_cpu=240000000L +rmp.build.flash_size=4MB +rmp.build.flash_freq=80m +rmp.build.flash_mode=dio +rmp.build.boot=qio +rmp.build.partitions=default +rmp.build.defines= + +rmp.menu.CDCOnBoot.cdc=Enabled +rmp.menu.CDCOnBoot.cdc.build.cdc_on_boot=1 +rmp.menu.CDCOnBoot.default=Disabled +rmp.menu.CDCOnBoot.default.build.cdc_on_boot=0 + +rmp.menu.MSCOnBoot.default=Disabled +rmp.menu.MSCOnBoot.default.build.msc_on_boot=0 +rmp.menu.MSCOnBoot.msc=Enabled +rmp.menu.MSCOnBoot.msc.build.msc_on_boot=1 + +rmp.menu.DFUOnBoot.default=Disabled +rmp.menu.DFUOnBoot.default.build.dfu_on_boot=0 +rmp.menu.DFUOnBoot.dfu=Enabled +rmp.menu.DFUOnBoot.dfu.build.dfu_on_boot=1 + +rmp.menu.PSRAM.enabled=Enabled +rmp.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM +rmp.menu.PSRAM.disabled=Disabled +rmp.menu.PSRAM.disabled.build.defines= + +rmp.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +rmp.menu.PartitionScheme.default.build.partitions=default +rmp.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +rmp.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +rmp.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS) +rmp.menu.PartitionScheme.minimal.build.partitions=minimal +rmp.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +rmp.menu.PartitionScheme.no_ota.build.partitions=no_ota +rmp.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +rmp.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +rmp.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +rmp.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +rmp.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +rmp.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +rmp.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +rmp.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +rmp.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +rmp.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +rmp.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +rmp.menu.PartitionScheme.huge_app.build.partitions=huge_app +rmp.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 +rmp.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS) +rmp.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +rmp.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 + +rmp.menu.CPUFreq.240=240MHz (WiFi) +rmp.menu.CPUFreq.240.build.f_cpu=240000000L +rmp.menu.CPUFreq.160=160MHz (WiFi) +rmp.menu.CPUFreq.160.build.f_cpu=160000000L +rmp.menu.CPUFreq.80=80MHz (WiFi) +rmp.menu.CPUFreq.80.build.f_cpu=80000000L +rmp.menu.CPUFreq.40=40MHz +rmp.menu.CPUFreq.40.build.f_cpu=40000000L +rmp.menu.CPUFreq.20=20MHz +rmp.menu.CPUFreq.20.build.f_cpu=20000000L +rmp.menu.CPUFreq.10=10MHz +rmp.menu.CPUFreq.10.build.f_cpu=10000000L + +rmp.menu.FlashSize.4M=4MB (32Mb) +rmp.menu.FlashSize.4M.build.flash_size=4MB +rmp.menu.FlashSize.2M=2MB (16Mb) +rmp.menu.FlashSize.2M.build.flash_size=2MB +rmp.menu.FlashSize.2M.build.partitions=minimal + +rmp.menu.UploadSpeed.921600=921600 +rmp.menu.UploadSpeed.921600.upload.speed=921600 +rmp.menu.UploadSpeed.115200=115200 +rmp.menu.UploadSpeed.115200.upload.speed=115200 +rmp.menu.UploadSpeed.256000.windows=256000 +rmp.menu.UploadSpeed.256000.upload.speed=256000 +rmp.menu.UploadSpeed.230400.windows.upload.speed=256000 +rmp.menu.UploadSpeed.230400=230400 +rmp.menu.UploadSpeed.230400.upload.speed=230400 +rmp.menu.UploadSpeed.460800.linux=460800 +rmp.menu.UploadSpeed.460800.macosx=460800 +rmp.menu.UploadSpeed.460800.upload.speed=460800 + +rmp.menu.DebugLevel.none=None +rmp.menu.DebugLevel.none.build.code_debug=0 +rmp.menu.DebugLevel.error=Error +rmp.menu.DebugLevel.error.build.code_debug=1 +rmp.menu.DebugLevel.warn=Warn +rmp.menu.DebugLevel.warn.build.code_debug=2 +rmp.menu.DebugLevel.info=Info +rmp.menu.DebugLevel.info.build.code_debug=3 +rmp.menu.DebugLevel.debug=Debug +rmp.menu.DebugLevel.debug.build.code_debug=4 +rmp.menu.DebugLevel.verbose=Verbose +rmp.menu.DebugLevel.verbose.build.code_debug=5 + +############################################################## +tinys3.name=UM TinyS3 +tinys3.vid.0=0x303a +tinys3.pid.0=0x80D0 + +tinys3.bootloader.tool=esptool_py +tinys3.bootloader.tool.default=esptool_py + +tinys3.upload.tool=esptool_py +tinys3.upload.tool.default=esptool_py +tinys3.upload.tool.network=esp_ota + +tinys3.upload.maximum_size=1310720 +tinys3.upload.maximum_data_size=327680 +tinys3.upload.flags= +tinys3.upload.extra_flags= +tinys3.upload.use_1200bps_touch=false +tinys3.upload.wait_for_upload_port=false + +tinys3.serial.disableDTR=false +tinys3.serial.disableRTS=false + +tinys3.build.tarch=xtensa +tinys3.build.bootloader_addr=0x0 +tinys3.build.target=esp32s3 +tinys3.build.mcu=esp32s3 +tinys3.build.core=esp32 +tinys3.build.variant=um_tinys3 +tinys3.build.board=TINYS3 + +tinys3.build.usb_mode=1 +tinys3.build.cdc_on_boot=0 +tinys3.build.msc_on_boot=0 +tinys3.build.dfu_on_boot=0 +tinys3.build.f_cpu=240000000L +tinys3.build.flash_size=8MB +tinys3.build.flash_freq=80m +tinys3.build.flash_mode=dio +tinys3.build.boot=qio +tinys3.build.partitions=default +tinys3.build.defines= +tinys3.build.loop_core= +tinys3.build.event_core= +tinys3.build.flash_type=qspi +tinys3.build.psram_type=qspi +tinys3.build.memory_type=qspi_qspi + +tinys3.menu.LoopCore.1=Core 1 +tinys3.menu.LoopCore.1.build.loop_core=-DARDUINO_RUNNING_CORE=1 +tinys3.menu.LoopCore.0=Core 0 +tinys3.menu.LoopCore.0.build.loop_core=-DARDUINO_RUNNING_CORE=0 + +tinys3.menu.EventsCore.1=Core 1 +tinys3.menu.EventsCore.1.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1 +tinys3.menu.EventsCore.0=Core 0 +tinys3.menu.EventsCore.0.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=0 + +tinys3.menu.USBMode.default=USB-OTG (TinyUSB) +tinys3.menu.USBMode.default.build.usb_mode=0 +tinys3.menu.USBMode.hwcdc=Hardware CDC and JTAG +tinys3.menu.USBMode.hwcdc.build.usb_mode=1 + +tinys3.menu.CDCOnBoot.cdc=Enabled +tinys3.menu.CDCOnBoot.cdc.build.cdc_on_boot=1 +tinys3.menu.CDCOnBoot.default=Disabled +tinys3.menu.CDCOnBoot.default.build.cdc_on_boot=0 + +tinys3.menu.MSCOnBoot.default=Disabled +tinys3.menu.MSCOnBoot.default.build.msc_on_boot=0 +tinys3.menu.MSCOnBoot.msc=Enabled (Requires USB-OTG Mode) +tinys3.menu.MSCOnBoot.msc.build.msc_on_boot=1 + +tinys3.menu.DFUOnBoot.default=Disabled +tinys3.menu.DFUOnBoot.default.build.dfu_on_boot=0 +tinys3.menu.DFUOnBoot.dfu=Enabled (Requires USB-OTG Mode) +tinys3.menu.DFUOnBoot.dfu.build.dfu_on_boot=1 + +tinys3.menu.UploadMode.cdc=USB-OTG CDC (TinyUSB) +tinys3.menu.UploadMode.cdc.upload.use_1200bps_touch=true +tinys3.menu.UploadMode.cdc.upload.wait_for_upload_port=true +tinys3.menu.UploadMode.default=UART0 / Hardware CDC +tinys3.menu.UploadMode.default.upload.use_1200bps_touch=false +tinys3.menu.UploadMode.default.upload.wait_for_upload_port=false + +tinys3.menu.PSRAM.enabled=Enabled +tinys3.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM +tinys3.menu.PSRAM.disabled=Disabled +tinys3.menu.PSRAM.disabled.build.defines= + +tinys3.menu.PartitionScheme.default_8MB=Default (3MB APP/1.5MB SPIFFS) +tinys3.menu.PartitionScheme.default_8MB.build.partitions=default_8MB +tinys3.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 +tinys3.menu.PartitionScheme.tinyuf2=TinyUF2 Compatibility (2MB APP/3.7MB FFAT) +tinys3.menu.PartitionScheme.tinyuf2.build.custom_bootloader=bootloader_tinyuf2 +tinys3.menu.PartitionScheme.tinyuf2.build.custom_partitions=partitions_tinyuf2 +tinys3.menu.PartitionScheme.tinyuf2.upload.extra_flags=0x410000 "{runtime.platform.path}/variants/{build.variant}/tinyuf2.bin" +tinys3.menu.PartitionScheme.tinyuf2.upload.maximum_size=2097152 + +tinys3.menu.CPUFreq.240=240MHz (WiFi) +tinys3.menu.CPUFreq.240.build.f_cpu=240000000L +tinys3.menu.CPUFreq.160=160MHz (WiFi) +tinys3.menu.CPUFreq.160.build.f_cpu=160000000L +tinys3.menu.CPUFreq.80=80MHz (WiFi) +tinys3.menu.CPUFreq.80.build.f_cpu=80000000L +tinys3.menu.CPUFreq.40=40MHz +tinys3.menu.CPUFreq.40.build.f_cpu=40000000L +tinys3.menu.CPUFreq.20=20MHz +tinys3.menu.CPUFreq.20.build.f_cpu=20000000L +tinys3.menu.CPUFreq.10=10MHz +tinys3.menu.CPUFreq.10.build.f_cpu=10000000L + +tinys3.menu.FlashMode.qio=QIO +tinys3.menu.FlashMode.qio.build.flash_mode=dio +tinys3.menu.FlashMode.qio.build.boot=qio +tinys3.menu.FlashMode.dio=DIO +tinys3.menu.FlashMode.dio.build.flash_mode=dio +tinys3.menu.FlashMode.dio.build.boot=dio + +tinys3.menu.UploadSpeed.921600=921600 +tinys3.menu.UploadSpeed.921600.upload.speed=921600 +tinys3.menu.UploadSpeed.115200=115200 +tinys3.menu.UploadSpeed.115200.upload.speed=115200 +tinys3.menu.UploadSpeed.256000.windows=256000 +tinys3.menu.UploadSpeed.256000.upload.speed=256000 +tinys3.menu.UploadSpeed.230400.windows.upload.speed=256000 +tinys3.menu.UploadSpeed.230400=230400 +tinys3.menu.UploadSpeed.230400.upload.speed=230400 +tinys3.menu.UploadSpeed.460800.linux=460800 +tinys3.menu.UploadSpeed.460800.macosx=460800 +tinys3.menu.UploadSpeed.460800.upload.speed=460800 +tinys3.menu.UploadSpeed.512000.windows=512000 +tinys3.menu.UploadSpeed.512000.upload.speed=512000 + +tinys3.menu.DebugLevel.none=None +tinys3.menu.DebugLevel.none.build.code_debug=0 +tinys3.menu.DebugLevel.error=Error +tinys3.menu.DebugLevel.error.build.code_debug=1 +tinys3.menu.DebugLevel.warn=Warn +tinys3.menu.DebugLevel.warn.build.code_debug=2 +tinys3.menu.DebugLevel.info=Info +tinys3.menu.DebugLevel.info.build.code_debug=3 +tinys3.menu.DebugLevel.debug=Debug +tinys3.menu.DebugLevel.debug.build.code_debug=4 +tinys3.menu.DebugLevel.verbose=Verbose +tinys3.menu.DebugLevel.verbose.build.code_debug=5 + +############################################################## + +pros3.name=UM PROS3 +pros3.vid.0=0x303a +pros3.pid.0=0x80D3 + +pros3.bootloader.tool=esptool_py +pros3.bootloader.tool.default=esptool_py + +pros3.upload.tool=esptool_py +pros3.upload.tool.default=esptool_py +pros3.upload.tool.network=esp_ota + +pros3.upload.maximum_size=1310720 +pros3.upload.maximum_data_size=327680 +pros3.upload.flags= +pros3.upload.extra_flags= +pros3.upload.use_1200bps_touch=false +pros3.upload.wait_for_upload_port=false + +pros3.serial.disableDTR=false +pros3.serial.disableRTS=false + +pros3.build.tarch=xtensa +pros3.build.bootloader_addr=0x0 +pros3.build.target=esp32s3 +pros3.build.mcu=esp32s3 +pros3.build.core=esp32 +pros3.build.variant=um_pros3 +pros3.build.board=PROS3 + +pros3.build.usb_mode=1 +pros3.build.cdc_on_boot=0 +pros3.build.msc_on_boot=0 +pros3.build.dfu_on_boot=0 +pros3.build.f_cpu=240000000L +pros3.build.flash_size=16MB +pros3.build.flash_freq=80m +pros3.build.flash_mode=dio +pros3.build.boot=qio +pros3.build.partitions=default +pros3.build.defines= +pros3.build.loop_core= +pros3.build.event_core= +pros3.build.flash_type=qspi +pros3.build.psram_type=qspi +pros3.build.memory_type=qspi_qspi + +pros3.menu.LoopCore.1=Core 1 +pros3.menu.LoopCore.1.build.loop_core=-DARDUINO_RUNNING_CORE=1 +pros3.menu.LoopCore.0=Core 0 +pros3.menu.LoopCore.0.build.loop_core=-DARDUINO_RUNNING_CORE=0 + +pros3.menu.EventsCore.1=Core 1 +pros3.menu.EventsCore.1.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1 +pros3.menu.EventsCore.0=Core 0 +pros3.menu.EventsCore.0.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=0 + +pros3.menu.USBMode.default=USB-OTG (TinyUSB) +pros3.menu.USBMode.default.build.usb_mode=0 +pros3.menu.USBMode.hwcdc=Hardware CDC and JTAG +pros3.menu.USBMode.hwcdc.build.usb_mode=1 + +pros3.menu.CDCOnBoot.cdc=Enabled +pros3.menu.CDCOnBoot.cdc.build.cdc_on_boot=1 +pros3.menu.CDCOnBoot.default=Disabled +pros3.menu.CDCOnBoot.default.build.cdc_on_boot=0 + +pros3.menu.MSCOnBoot.default=Disabled +pros3.menu.MSCOnBoot.default.build.msc_on_boot=0 +pros3.menu.MSCOnBoot.msc=Enabled (Requires USB-OTG Mode) +pros3.menu.MSCOnBoot.msc.build.msc_on_boot=1 + +pros3.menu.DFUOnBoot.default=Disabled +pros3.menu.DFUOnBoot.default.build.dfu_on_boot=0 +pros3.menu.DFUOnBoot.dfu=Enabled (Requires USB-OTG Mode) +pros3.menu.DFUOnBoot.dfu.build.dfu_on_boot=1 + +pros3.menu.UploadMode.cdc=USB-OTG CDC (TinyUSB) +pros3.menu.UploadMode.cdc.upload.use_1200bps_touch=true +pros3.menu.UploadMode.cdc.upload.wait_for_upload_port=true +pros3.menu.UploadMode.default=UART0 / Hardware CDC +pros3.menu.UploadMode.default.upload.use_1200bps_touch=false +pros3.menu.UploadMode.default.upload.wait_for_upload_port=false + +pros3.menu.PSRAM.enabled=Enabled +pros3.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM +pros3.menu.PSRAM.disabled=Disabled +pros3.menu.PSRAM.disabled.build.defines= + +pros3.menu.PartitionScheme.default_16MB=Default (6.25MB APP/3.43MB SPIFFS) +pros3.menu.PartitionScheme.default_16MB.build.partitions=default_16MB +pros3.menu.PartitionScheme.default_16MB.upload.maximum_size=6553600 +pros3.menu.PartitionScheme.tinyuf2=TinyUF2 Compatibility (2MB APP/12MB FFAT) +pros3.menu.PartitionScheme.tinyuf2.build.custom_bootloader=bootloader_tinyuf2 +pros3.menu.PartitionScheme.tinyuf2.build.custom_partitions=partitions_tinyuf2 +pros3.menu.PartitionScheme.tinyuf2.upload.extra_flags=0x410000 "{runtime.platform.path}/variants/{build.variant}/tinyuf2.bin" +pros3.menu.PartitionScheme.tinyuf2.upload.maximum_size=2097152 +pros3.menu.PartitionScheme.large_spiffs=Large SPIFFS (4.5MB APP/6.93MB SPIFFS) +pros3.menu.PartitionScheme.large_spiffs.build.partitions=large_spiffs_16MB +pros3.menu.PartitionScheme.large_spiffs.upload.maximum_size=4718592 +pros3.menu.PartitionScheme.app3M_fat9M_16MB=FFAT (3MB APP/9MB FATFS) +pros3.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB +pros3.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 +pros3.menu.PartitionScheme.fatflash=Large FFAT (2MB APP/12.5MB FATFS) +pros3.menu.PartitionScheme.fatflash.build.partitions=ffat +pros3.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 + +pros3.menu.CPUFreq.240=240MHz (WiFi) +pros3.menu.CPUFreq.240.build.f_cpu=240000000L +pros3.menu.CPUFreq.160=160MHz (WiFi) +pros3.menu.CPUFreq.160.build.f_cpu=160000000L +pros3.menu.CPUFreq.80=80MHz (WiFi) +pros3.menu.CPUFreq.80.build.f_cpu=80000000L +pros3.menu.CPUFreq.40=40MHz +pros3.menu.CPUFreq.40.build.f_cpu=40000000L +pros3.menu.CPUFreq.20=20MHz +pros3.menu.CPUFreq.20.build.f_cpu=20000000L +pros3.menu.CPUFreq.10=10MHz +pros3.menu.CPUFreq.10.build.f_cpu=10000000L + +pros3.menu.FlashMode.qio=QIO +pros3.menu.FlashMode.qio.build.flash_mode=dio +pros3.menu.FlashMode.qio.build.boot=qio +pros3.menu.FlashMode.dio=DIO +pros3.menu.FlashMode.dio.build.flash_mode=dio +pros3.menu.FlashMode.dio.build.boot=dio + +pros3.menu.UploadSpeed.921600=921600 +pros3.menu.UploadSpeed.921600.upload.speed=921600 +pros3.menu.UploadSpeed.115200=115200 +pros3.menu.UploadSpeed.115200.upload.speed=115200 +pros3.menu.UploadSpeed.256000.windows=256000 +pros3.menu.UploadSpeed.256000.upload.speed=256000 +pros3.menu.UploadSpeed.230400.windows.upload.speed=256000 +pros3.menu.UploadSpeed.230400=230400 +pros3.menu.UploadSpeed.230400.upload.speed=230400 +pros3.menu.UploadSpeed.460800.linux=460800 +pros3.menu.UploadSpeed.460800.macosx=460800 +pros3.menu.UploadSpeed.460800.upload.speed=460800 +pros3.menu.UploadSpeed.512000.windows=512000 +pros3.menu.UploadSpeed.512000.upload.speed=512000 + +pros3.menu.DebugLevel.none=None +pros3.menu.DebugLevel.none.build.code_debug=0 +pros3.menu.DebugLevel.error=Error +pros3.menu.DebugLevel.error.build.code_debug=1 +pros3.menu.DebugLevel.warn=Warn +pros3.menu.DebugLevel.warn.build.code_debug=2 +pros3.menu.DebugLevel.info=Info +pros3.menu.DebugLevel.info.build.code_debug=3 +pros3.menu.DebugLevel.debug=Debug +pros3.menu.DebugLevel.debug.build.code_debug=4 +pros3.menu.DebugLevel.verbose=Verbose +pros3.menu.DebugLevel.verbose.build.code_debug=5 + +############################################################## + +feathers3.name=UM FeatherS3 +feathers3.vid.0=0x303a +feathers3.pid.0=0x80D6 + +feathers3.bootloader.tool=esptool_py +feathers3.bootloader.tool.default=esptool_py + +feathers3.upload.tool=esptool_py +feathers3.upload.tool.default=esptool_py +feathers3.upload.tool.network=esp_ota + +feathers3.upload.maximum_size=1310720 +feathers3.upload.maximum_data_size=327680 +feathers3.upload.flags= +feathers3.upload.extra_flags= +feathers3.upload.use_1200bps_touch=false +feathers3.upload.wait_for_upload_port=false + +feathers3.serial.disableDTR=false +feathers3.serial.disableRTS=false + +feathers3.build.tarch=xtensa +feathers3.build.bootloader_addr=0x0 +feathers3.build.target=esp32s3 +feathers3.build.mcu=esp32s3 +feathers3.build.core=esp32 +feathers3.build.variant=um_feathers3 +feathers3.build.board=FEATHERS3 + +feathers3.build.usb_mode=1 +feathers3.build.cdc_on_boot=0 +feathers3.build.msc_on_boot=0 +feathers3.build.dfu_on_boot=0 +feathers3.build.f_cpu=240000000L +feathers3.build.flash_size=16MB +feathers3.build.flash_freq=80m +feathers3.build.flash_mode=dio +feathers3.build.boot=qio +feathers3.build.partitions=default +feathers3.build.defines= +feathers3.build.loop_core= +feathers3.build.event_core= +feathers3.build.flash_type=qspi +feathers3.build.psram_type=qspi +feathers3.build.memory_type=qspi_qspi + +feathers3.menu.LoopCore.1=Core 1 +feathers3.menu.LoopCore.1.build.loop_core=-DARDUINO_RUNNING_CORE=1 +feathers3.menu.LoopCore.0=Core 0 +feathers3.menu.LoopCore.0.build.loop_core=-DARDUINO_RUNNING_CORE=0 + +feathers3.menu.EventsCore.1=Core 1 +feathers3.menu.EventsCore.1.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1 +feathers3.menu.EventsCore.0=Core 0 +feathers3.menu.EventsCore.0.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=0 + +feathers3.menu.USBMode.default=USB-OTG (TinyUSB) +feathers3.menu.USBMode.default.build.usb_mode=0 +feathers3.menu.USBMode.hwcdc=Hardware CDC and JTAG +feathers3.menu.USBMode.hwcdc.build.usb_mode=1 + +feathers3.menu.CDCOnBoot.cdc=Enabled +feathers3.menu.CDCOnBoot.cdc.build.cdc_on_boot=1 +feathers3.menu.CDCOnBoot.default=Disabled +feathers3.menu.CDCOnBoot.default.build.cdc_on_boot=0 + +feathers3.menu.MSCOnBoot.default=Disabled +feathers3.menu.MSCOnBoot.default.build.msc_on_boot=0 +feathers3.menu.MSCOnBoot.msc=Enabled (Requires USB-OTG Mode) +feathers3.menu.MSCOnBoot.msc.build.msc_on_boot=1 + +feathers3.menu.DFUOnBoot.default=Disabled +feathers3.menu.DFUOnBoot.default.build.dfu_on_boot=0 +feathers3.menu.DFUOnBoot.dfu=Enabled (Requires USB-OTG Mode) +feathers3.menu.DFUOnBoot.dfu.build.dfu_on_boot=1 + +feathers3.menu.UploadMode.cdc=USB-OTG CDC (TinyUSB) +feathers3.menu.UploadMode.cdc.upload.use_1200bps_touch=true +feathers3.menu.UploadMode.cdc.upload.wait_for_upload_port=true +feathers3.menu.UploadMode.default=UART0 / Hardware CDC +feathers3.menu.UploadMode.default.upload.use_1200bps_touch=false +feathers3.menu.UploadMode.default.upload.wait_for_upload_port=false + +feathers3.menu.PSRAM.enabled=Enabled +feathers3.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM +feathers3.menu.PSRAM.disabled=Disabled +feathers3.menu.PSRAM.disabled.build.defines= + +feathers3.menu.PartitionScheme.default_16MB=Default (6.25MB APP/3.43MB SPIFFS) +feathers3.menu.PartitionScheme.default_16MB.build.partitions=default_16MB +feathers3.menu.PartitionScheme.default_16MB.upload.maximum_size=6553600 +feathers3.menu.PartitionScheme.tinyuf2=TinyUF2 Compatibility (2MB APP/12MB FFAT) +feathers3.menu.PartitionScheme.tinyuf2.build.custom_bootloader=bootloader_tinyuf2 +feathers3.menu.PartitionScheme.tinyuf2.build.custom_partitions=partitions_tinyuf2 +feathers3.menu.PartitionScheme.tinyuf2.upload.extra_flags=0x410000 "{runtime.platform.path}/variants/{build.variant}/tinyuf2.bin" +feathers3.menu.PartitionScheme.tinyuf2.upload.maximum_size=2097152 +feathers3.menu.PartitionScheme.large_spiffs=Large SPIFFS (4.5MB APP/6.93MB SPIFFS) +feathers3.menu.PartitionScheme.large_spiffs.build.partitions=large_spiffs_16MB +feathers3.menu.PartitionScheme.large_spiffs.upload.maximum_size=4718592 +feathers3.menu.PartitionScheme.app3M_fat9M_16MB=FFAT (3MB APP/9MB FATFS) +feathers3.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB +feathers3.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 +feathers3.menu.PartitionScheme.fatflash=Large FFAT (2MB APP/12.5MB FATFS) +feathers3.menu.PartitionScheme.fatflash.build.partitions=ffat +feathers3.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 + +feathers3.menu.CPUFreq.240=240MHz (WiFi) +feathers3.menu.CPUFreq.240.build.f_cpu=240000000L +feathers3.menu.CPUFreq.160=160MHz (WiFi) +feathers3.menu.CPUFreq.160.build.f_cpu=160000000L +feathers3.menu.CPUFreq.80=80MHz (WiFi) +feathers3.menu.CPUFreq.80.build.f_cpu=80000000L +feathers3.menu.CPUFreq.40=40MHz +feathers3.menu.CPUFreq.40.build.f_cpu=40000000L +feathers3.menu.CPUFreq.20=20MHz +feathers3.menu.CPUFreq.20.build.f_cpu=20000000L +feathers3.menu.CPUFreq.10=10MHz +feathers3.menu.CPUFreq.10.build.f_cpu=10000000L + +feathers3.menu.FlashMode.qio=QIO +feathers3.menu.FlashMode.qio.build.flash_mode=dio +feathers3.menu.FlashMode.qio.build.boot=qio +feathers3.menu.FlashMode.dio=DIO +feathers3.menu.FlashMode.dio.build.flash_mode=dio +feathers3.menu.FlashMode.dio.build.boot=dio + +feathers3.menu.UploadSpeed.921600=921600 +feathers3.menu.UploadSpeed.921600.upload.speed=921600 +feathers3.menu.UploadSpeed.115200=115200 +feathers3.menu.UploadSpeed.115200.upload.speed=115200 +feathers3.menu.UploadSpeed.256000.windows=256000 +feathers3.menu.UploadSpeed.256000.upload.speed=256000 +feathers3.menu.UploadSpeed.230400.windows.upload.speed=256000 +feathers3.menu.UploadSpeed.230400=230400 +feathers3.menu.UploadSpeed.230400.upload.speed=230400 +feathers3.menu.UploadSpeed.460800.linux=460800 +feathers3.menu.UploadSpeed.460800.macosx=460800 +feathers3.menu.UploadSpeed.460800.upload.speed=460800 +feathers3.menu.UploadSpeed.512000.windows=512000 +feathers3.menu.UploadSpeed.512000.upload.speed=512000 + +feathers3.menu.DebugLevel.none=None +feathers3.menu.DebugLevel.none.build.code_debug=0 +feathers3.menu.DebugLevel.error=Error +feathers3.menu.DebugLevel.error.build.code_debug=1 +feathers3.menu.DebugLevel.warn=Warn +feathers3.menu.DebugLevel.warn.build.code_debug=2 +feathers3.menu.DebugLevel.info=Info +feathers3.menu.DebugLevel.info.build.code_debug=3 +feathers3.menu.DebugLevel.debug=Debug +feathers3.menu.DebugLevel.debug.build.code_debug=4 +feathers3.menu.DebugLevel.verbose=Verbose +feathers3.menu.DebugLevel.verbose.build.code_debug=5 + +############################################################## + S_ODI_Ultra.name=S.ODI Ultra v1 +S_ODI_Ultra.bootloader.tool=esptool_py +S_ODI_Ultra.bootloader.tool.default=esptool_py + S_ODI_Ultra.upload.tool=esptool_py +S_ODI_Ultra.upload.tool.default=esptool_py +S_ODI_Ultra.upload.tool.network=esp_ota + S_ODI_Ultra.upload.maximum_size=1310720 S_ODI_Ultra.upload.maximum_data_size=327680 S_ODI_Ultra.upload.wait_for_upload_port=true @@ -1415,7 +2782,13 @@ micros2.name=microS2 micros2.vid.0=0x239A micros2.pid.0=0x80C5 +micros2.bootloader.tool=esptool_py +micros2.bootloader.tool.default=esptool_py + micros2.upload.tool=esptool_py +micros2.upload.tool.default=esptool_py +micros2.upload.tool.network=esp_ota + micros2.upload.maximum_size=1310720 micros2.upload.maximum_data_size=327680 micros2.upload.flags= @@ -1550,9 +2923,16 @@ micros2.menu.DebugLevel.verbose=Verbose micros2.menu.DebugLevel.verbose.build.code_debug=5 ############################################################## + magicbit.name=MagicBit +magicbit.bootloader.tool=esptool_py +magicbit.bootloader.tool.default=esptool_py + magicbit.upload.tool=esptool_py +magicbit.upload.tool.default=esptool_py +magicbit.upload.tool.network=esp_ota + magicbit.upload.maximum_size=1310720 magicbit.upload.maximum_data_size=327680 magicbit.upload.flags= @@ -1588,10 +2968,31 @@ magicbit.menu.UploadSpeed.921600=921600 magicbit.menu.UploadSpeed.921600.upload.speed=921600 magicbit.menu.UploadSpeed.115200=115200 magicbit.menu.UploadSpeed.115200.upload.speed=115200 + +magicbit.menu.DebugLevel.none=None +magicbit.menu.DebugLevel.none.build.code_debug=0 +magicbit.menu.DebugLevel.error=Error +magicbit.menu.DebugLevel.error.build.code_debug=1 +magicbit.menu.DebugLevel.warn=Warn +magicbit.menu.DebugLevel.warn.build.code_debug=2 +magicbit.menu.DebugLevel.info=Info +magicbit.menu.DebugLevel.info.build.code_debug=3 +magicbit.menu.DebugLevel.debug=Debug +magicbit.menu.DebugLevel.debug.build.code_debug=4 +magicbit.menu.DebugLevel.verbose=Verbose +magicbit.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## + turta_iot_node.name=Turta IoT Node +turta_iot_node.bootloader.tool=esptool_py +turta_iot_node.bootloader.tool.default=esptool_py + turta_iot_node.upload.tool=esptool_py +turta_iot_node.upload.tool.default=esptool_py +turta_iot_node.upload.tool.network=esp_ota + turta_iot_node.upload.maximum_size=1310720 turta_iot_node.upload.maximum_data_size=327680 turta_iot_node.upload.flags= @@ -1636,10 +3037,15 @@ turta_iot_node.menu.DebugLevel.verbose.build.code_debug=5 ############################################################## - ttgo-lora32.name=TTGO LoRa32-OLED +ttgo-lora32.bootloader.tool=esptool_py +ttgo-lora32.bootloader.tool.default=esptool_py + ttgo-lora32.upload.tool=esptool_py +ttgo-lora32.upload.tool.default=esptool_py +ttgo-lora32.upload.tool.network=esp_ota + ttgo-lora32.upload.maximum_size=1310720 ttgo-lora32.upload.maximum_data_size=294912 ttgo-lora32.upload.flags= @@ -1706,12 +3112,17 @@ ttgo-lora32.menu.DebugLevel.debug.build.code_debug=4 ttgo-lora32.menu.DebugLevel.verbose=Verbose ttgo-lora32.menu.DebugLevel.verbose.build.code_debug=5 - ############################################################## ttgo-t1.name=TTGO T1 +ttgo-t1.bootloader.tool=esptool_py +ttgo-t1.bootloader.tool.default=esptool_py + ttgo-t1.upload.tool=esptool_py +ttgo-t1.upload.tool.default=esptool_py +ttgo-t1.upload.tool.network=esp_ota + ttgo-t1.upload.maximum_size=1310720 ttgo-t1.upload.maximum_data_size=327680 ttgo-t1.upload.flags= @@ -1837,7 +3248,13 @@ ttgo-t1.menu.DebugLevel.verbose.build.code_debug=5 ttgo-t7-v13-mini32.name=TTGO T7 V1.3 Mini32 +ttgo-t7-v13-mini32.bootloader.tool=esptool_py +ttgo-t7-v13-mini32.bootloader.tool.default=esptool_py + ttgo-t7-v13-mini32.upload.tool=esptool_py +ttgo-t7-v13-mini32.upload.tool.default=esptool_py +ttgo-t7-v13-mini32.upload.tool.network=esp_ota + ttgo-t7-v13-mini32.upload.maximum_size=1310720 ttgo-t7-v13-mini32.upload.maximum_data_size=327680 ttgo-t7-v13-mini32.upload.wait_for_upload_port=true @@ -1958,7 +3375,13 @@ ttgo-t7-v13-mini32.menu.DebugLevel.verbose.build.code_debug=5 ttgo-t7-v14-mini32.name=TTGO T7 V1.4 Mini32 +ttgo-t7-v14-mini32.bootloader.tool=esptool_py +ttgo-t7-v14-mini32.bootloader.tool.default=esptool_py + ttgo-t7-v14-mini32.upload.tool=esptool_py +ttgo-t7-v14-mini32.upload.tool.default=esptool_py +ttgo-t7-v14-mini32.upload.tool.network=esp_ota + ttgo-t7-v14-mini32.upload.maximum_size=1310720 ttgo-t7-v14-mini32.upload.maximum_data_size=327680 ttgo-t7-v14-mini32.upload.wait_for_upload_port=true @@ -2079,7 +3502,13 @@ ttgo-t7-v14-mini32.menu.DebugLevel.verbose.build.code_debug=5 ttgo-t-oi-plus.name=TTGO T-OI PLUS RISC-V ESP32-C3 +ttgo-t-oi-plus.bootloader.tool=esptool_py +ttgo-t-oi-plus.bootloader.tool.default=esptool_py + ttgo-t-oi-plus.upload.tool=esptool_py +ttgo-t-oi-plus.upload.tool.default=esptool_py +ttgo-t-oi-plus.upload.tool.network=esp_ota + ttgo-t-oi-plus.upload.maximum_size=1310720 ttgo-t-oi-plus.upload.maximum_data_size=327680 ttgo-t-oi-plus.upload.flags= @@ -2130,7 +3559,6 @@ ttgo-t-oi-plus.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OT ttgo-t-oi-plus.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs ttgo-t-oi-plus.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 - ttgo-t-oi-plus.menu.CPUFreq.160=160MHz (WiFi) ttgo-t-oi-plus.menu.CPUFreq.160.build.f_cpu=160000000L ttgo-t-oi-plus.menu.CPUFreq.80=80MHz (WiFi) @@ -2195,7 +3623,13 @@ ttgo-t-oi-plus.menu.DebugLevel.verbose.build.code_debug=5 cw02.name=XinaBox CW02 +cw02.bootloader.tool=esptool_py +cw02.bootloader.tool.default=esptool_py + cw02.upload.tool=esptool_py +cw02.upload.tool.default=esptool_py +cw02.upload.tool.network=esp_ota + cw02.upload.maximum_size=1310720 cw02.upload.maximum_data_size=294912 cw02.upload.flags= @@ -2275,7 +3709,13 @@ cw02.menu.DebugLevel.verbose.build.code_debug=5 esp32thing.name=SparkFun ESP32 Thing +esp32thing.bootloader.tool=esptool_py +esp32thing.bootloader.tool.default=esptool_py + esp32thing.upload.tool=esptool_py +esp32thing.upload.tool.default=esptool_py +esp32thing.upload.tool.network=esp_ota + esp32thing.upload.maximum_size=1310720 esp32thing.upload.maximum_data_size=327680 esp32thing.upload.flags= @@ -2345,7 +3785,13 @@ esp32thing.menu.DebugLevel.verbose.build.code_debug=5 esp32thing_plus.name=SparkFun ESP32 Thing Plus +esp32thing_plus.bootloader.tool=esptool_py +esp32thing_plus.bootloader.tool.default=esptool_py + esp32thing_plus.upload.tool=esptool_py +esp32thing_plus.upload.tool.default=esptool_py +esp32thing_plus.upload.tool.network=esp_ota + esp32thing_plus.upload.maximum_size=1310720 esp32thing_plus.upload.maximum_data_size=327680 esp32thing_plus.upload.wait_for_upload_port=true @@ -2416,7 +3862,13 @@ sparkfun_esp32s2_thing_plus.name=SparkFun ESP32-S2 Thing Plus sparkfun_esp32s2_thing_plus.vid.0=0x1B4F sparkfun_esp32s2_thing_plus.pid.0=0x0027 +sparkfun_esp32s2_thing_plus.bootloader.tool=esptool_py +sparkfun_esp32s2_thing_plus.bootloader.tool.default=esptool_py + sparkfun_esp32s2_thing_plus.upload.tool=esptool_py +sparkfun_esp32s2_thing_plus.upload.tool.default=esptool_py +sparkfun_esp32s2_thing_plus.upload.tool.network=esp_ota + sparkfun_esp32s2_thing_plus.upload.maximum_size=1310720 sparkfun_esp32s2_thing_plus.upload.maximum_data_size=327680 sparkfun_esp32s2_thing_plus.upload.flags= @@ -2574,7 +4026,13 @@ sparkfun_esp32s2_thing_plus.menu.DebugLevel.verbose.build.code_debug=5 esp32micromod.name=SparkFun ESP32 MicroMod +esp32micromod.bootloader.tool=esptool_py +esp32micromod.bootloader.tool.default=esptool_py + esp32micromod.upload.tool=esptool_py +esp32micromod.upload.tool.default=esptool_py +esp32micromod.upload.tool.network=esp_ota + esp32micromod.upload.maximum_size=1310720 esp32micromod.upload.maximum_data_size=327680 esp32micromod.upload.wait_for_upload_port=true @@ -2717,7 +4175,13 @@ esp32micromod.menu.DebugLevel.verbose.build.code_debug=5 sparkfun_lora_gateway_1-channel.name=SparkFun LoRa Gateway 1-Channel +sparkfun_lora_gateway_1-channel.bootloader.tool=esptool_py +sparkfun_lora_gateway_1-channel.bootloader.tool.default=esptool_py + sparkfun_lora_gateway_1-channel.upload.tool=esptool_py +sparkfun_lora_gateway_1-channel.upload.tool.default=esptool_py +sparkfun_lora_gateway_1-channel.upload.tool.network=esp_ota + sparkfun_lora_gateway_1-channel.upload.maximum_size=1310720 sparkfun_lora_gateway_1-channel.upload.maximum_data_size=294912 sparkfun_lora_gateway_1-channel.upload.flags= @@ -2788,11 +4252,30 @@ sparkfun_lora_gateway_1-channel.menu.UploadSpeed.460800.upload.speed=460800 sparkfun_lora_gateway_1-channel.menu.UploadSpeed.512000.windows=512000 sparkfun_lora_gateway_1-channel.menu.UploadSpeed.512000.upload.speed=512000 +sparkfun_lora_gateway_1-channel.menu.DebugLevel.none=None +sparkfun_lora_gateway_1-channel.menu.DebugLevel.none.build.code_debug=0 +sparkfun_lora_gateway_1-channel.menu.DebugLevel.error=Error +sparkfun_lora_gateway_1-channel.menu.DebugLevel.error.build.code_debug=1 +sparkfun_lora_gateway_1-channel.menu.DebugLevel.warn=Warn +sparkfun_lora_gateway_1-channel.menu.DebugLevel.warn.build.code_debug=2 +sparkfun_lora_gateway_1-channel.menu.DebugLevel.info=Info +sparkfun_lora_gateway_1-channel.menu.DebugLevel.info.build.code_debug=3 +sparkfun_lora_gateway_1-channel.menu.DebugLevel.debug=Debug +sparkfun_lora_gateway_1-channel.menu.DebugLevel.debug.build.code_debug=4 +sparkfun_lora_gateway_1-channel.menu.DebugLevel.verbose=Verbose +sparkfun_lora_gateway_1-channel.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## nina_w10.name=u-blox NINA-W10 series (ESP32) +nina_w10.bootloader.tool=esptool_py +nina_w10.bootloader.tool.default=esptool_py + nina_w10.upload.tool=esptool_py +nina_w10.upload.tool.default=esptool_py +nina_w10.upload.tool.network=esp_ota + nina_w10.upload.maximum_size=1310720 nina_w10.upload.maximum_data_size=327680 nina_w10.upload.flags= @@ -2831,11 +4314,30 @@ nina_w10.menu.UploadSpeed.460800.upload.speed=460800 nina_w10.menu.UploadSpeed.512000.windows=512000 nina_w10.menu.UploadSpeed.512000.upload.speed=512000 +nina_w10.menu.DebugLevel.none=None +nina_w10.menu.DebugLevel.none.build.code_debug=0 +nina_w10.menu.DebugLevel.error=Error +nina_w10.menu.DebugLevel.error.build.code_debug=1 +nina_w10.menu.DebugLevel.warn=Warn +nina_w10.menu.DebugLevel.warn.build.code_debug=2 +nina_w10.menu.DebugLevel.info=Info +nina_w10.menu.DebugLevel.info.build.code_debug=3 +nina_w10.menu.DebugLevel.debug=Debug +nina_w10.menu.DebugLevel.debug.build.code_debug=4 +nina_w10.menu.DebugLevel.verbose=Verbose +nina_w10.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## widora-air.name=Widora AIR +widora-air.bootloader.tool=esptool_py +widora-air.bootloader.tool.default=esptool_py + widora-air.upload.tool=esptool_py +widora-air.upload.tool.default=esptool_py +widora-air.upload.tool.network=esp_ota + widora-air.upload.maximum_size=1310720 widora-air.upload.maximum_data_size=327680 widora-air.upload.flags= @@ -2879,11 +4381,30 @@ widora-air.menu.UploadSpeed.460800.upload.speed=460800 widora-air.menu.UploadSpeed.512000.windows=512000 widora-air.menu.UploadSpeed.512000.upload.speed=512000 +widora-air.menu.DebugLevel.none=None +widora-air.menu.DebugLevel.none.build.code_debug=0 +widora-air.menu.DebugLevel.error=Error +widora-air.menu.DebugLevel.error.build.code_debug=1 +widora-air.menu.DebugLevel.warn=Warn +widora-air.menu.DebugLevel.warn.build.code_debug=2 +widora-air.menu.DebugLevel.info=Info +widora-air.menu.DebugLevel.info.build.code_debug=3 +widora-air.menu.DebugLevel.debug=Debug +widora-air.menu.DebugLevel.debug.build.code_debug=4 +widora-air.menu.DebugLevel.verbose=Verbose +widora-air.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## esp320.name=Electronic SweetPeas - ESP320 +esp320.bootloader.tool=esptool_py +esp320.bootloader.tool.default=esptool_py + esp320.upload.tool=esptool_py +esp320.upload.tool.default=esptool_py +esp320.upload.tool.network=esp_ota + esp320.upload.maximum_size=1310720 esp320.upload.maximum_data_size=327680 esp320.upload.flags= @@ -2927,11 +4448,30 @@ esp320.menu.UploadSpeed.460800.upload.speed=460800 esp320.menu.UploadSpeed.512000.windows=512000 esp320.menu.UploadSpeed.512000.upload.speed=512000 +esp320.menu.DebugLevel.none=None +esp320.menu.DebugLevel.none.build.code_debug=0 +esp320.menu.DebugLevel.error=Error +esp320.menu.DebugLevel.error.build.code_debug=1 +esp320.menu.DebugLevel.warn=Warn +esp320.menu.DebugLevel.warn.build.code_debug=2 +esp320.menu.DebugLevel.info=Info +esp320.menu.DebugLevel.info.build.code_debug=3 +esp320.menu.DebugLevel.debug=Debug +esp320.menu.DebugLevel.debug.build.code_debug=4 +esp320.menu.DebugLevel.verbose=Verbose +esp320.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## nano32.name=Nano32 +nano32.bootloader.tool=esptool_py +nano32.bootloader.tool.default=esptool_py + nano32.upload.tool=esptool_py +nano32.upload.tool.default=esptool_py +nano32.upload.tool.network=esp_ota + nano32.upload.maximum_size=1310720 nano32.upload.maximum_data_size=327680 nano32.upload.flags= @@ -2975,11 +4515,30 @@ nano32.menu.UploadSpeed.460800.upload.speed=460800 nano32.menu.UploadSpeed.512000.windows=512000 nano32.menu.UploadSpeed.512000.upload.speed=512000 +nano32.menu.DebugLevel.none=None +nano32.menu.DebugLevel.none.build.code_debug=0 +nano32.menu.DebugLevel.error=Error +nano32.menu.DebugLevel.error.build.code_debug=1 +nano32.menu.DebugLevel.warn=Warn +nano32.menu.DebugLevel.warn.build.code_debug=2 +nano32.menu.DebugLevel.info=Info +nano32.menu.DebugLevel.info.build.code_debug=3 +nano32.menu.DebugLevel.debug=Debug +nano32.menu.DebugLevel.debug.build.code_debug=4 +nano32.menu.DebugLevel.verbose=Verbose +nano32.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## d32.name=LOLIN D32 +d32.bootloader.tool=esptool_py +d32.bootloader.tool.default=esptool_py + d32.upload.tool=esptool_py +d32.upload.tool.default=esptool_py +d32.upload.tool.network=esp_ota + d32.upload.maximum_size=1310720 d32.upload.maximum_data_size=327680 d32.upload.flags= @@ -3015,15 +4574,11 @@ d32.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (Large APPS with OTA) d32.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs d32.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 - - d32.menu.FlashFreq.80=80MHz d32.menu.FlashFreq.80.build.flash_freq=80m d32.menu.FlashFreq.40=40MHz d32.menu.FlashFreq.40.build.flash_freq=40m - - d32.menu.UploadSpeed.921600=921600 d32.menu.UploadSpeed.921600.upload.speed=921600 d32.menu.UploadSpeed.115200=115200 @@ -3056,7 +4611,13 @@ d32.menu.DebugLevel.verbose.build.code_debug=5 d32_pro.name=LOLIN D32 PRO +d32_pro.bootloader.tool=esptool_py +d32_pro.bootloader.tool.default=esptool_py + d32_pro.upload.tool=esptool_py +d32_pro.upload.tool.default=esptool_py +d32_pro.upload.tool.network=esp_ota + d32_pro.upload.maximum_size=1310720 d32_pro.upload.maximum_data_size=327680 d32_pro.upload.flags= @@ -3099,15 +4660,11 @@ d32_pro.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (Large APPS with OTA) d32_pro.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs d32_pro.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 - - d32_pro.menu.FlashFreq.80=80MHz d32_pro.menu.FlashFreq.80.build.flash_freq=80m d32_pro.menu.FlashFreq.40=40MHz d32_pro.menu.FlashFreq.40.build.flash_freq=40m - - d32_pro.menu.UploadSpeed.921600=921600 d32_pro.menu.UploadSpeed.921600.upload.speed=921600 d32_pro.menu.UploadSpeed.115200=115200 @@ -3140,9 +4697,313 @@ d32_pro.menu.DebugLevel.verbose.build.code_debug=5 ############################################################## +lolin_c3_mini.name=LOLIN C3 Mini +lolin_c3_mini.vid.0=0x303a +lolin_c3_mini.pid.0=0x1001 + +lolin_c3_mini.bootloader.tool=esptool_py +lolin_c3_mini.bootloader.tool.default=esptool_py + +lolin_c3_mini.upload.tool=esptool_py +lolin_c3_mini.upload.tool.default=esptool_py +lolin_c3_mini.upload.tool.network=esp_ota + +lolin_c3_mini.upload.maximum_size=1310720 +lolin_c3_mini.upload.maximum_data_size=327680 +lolin_c3_mini.upload.flags= +lolin_c3_mini.upload.extra_flags= +lolin_c3_mini.upload.use_1200bps_touch=false +lolin_c3_mini.upload.wait_for_upload_port=false + +lolin_c3_mini.serial.disableDTR=true +lolin_c3_mini.serial.disableRTS=true + +lolin_c3_mini.build.tarch=riscv32 +lolin_c3_mini.build.target=esp +lolin_c3_mini.build.mcu=esp32c3 +lolin_c3_mini.build.core=esp32 +lolin_c3_mini.build.variant=lolin_c3_mini +lolin_c3_mini.build.board=LOLIN_C3_MINI +lolin_c3_mini.build.bootloader_addr=0x0 + +lolin_c3_mini.build.cdc_on_boot=1 +lolin_c3_mini.build.f_cpu=160000000L +lolin_c3_mini.build.flash_size=4MB +lolin_c3_mini.build.flash_freq=80m +lolin_c3_mini.build.flash_mode=dio +lolin_c3_mini.build.boot=qio +lolin_c3_mini.build.partitions=default +lolin_c3_mini.build.defines= + +lolin_c3_mini.menu.CDCOnBoot.default=Enabled +lolin_c3_mini.menu.CDCOnBoot.default.build.cdc_on_boot=1 +lolin_c3_mini.menu.CDCOnBoot.dis_cdc=Disabled +lolin_c3_mini.menu.CDCOnBoot.dis_cdc.build.cdc_on_boot=0 + +lolin_c3_mini.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +lolin_c3_mini.menu.PartitionScheme.default.build.partitions=default +lolin_c3_mini.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +lolin_c3_mini.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +lolin_c3_mini.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +lolin_c3_mini.menu.PartitionScheme.no_ota.build.partitions=no_ota +lolin_c3_mini.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +lolin_c3_mini.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +lolin_c3_mini.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +lolin_c3_mini.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +lolin_c3_mini.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +lolin_c3_mini.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +lolin_c3_mini.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +lolin_c3_mini.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +lolin_c3_mini.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +lolin_c3_mini.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +lolin_c3_mini.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +lolin_c3_mini.menu.PartitionScheme.huge_app.build.partitions=huge_app +lolin_c3_mini.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 + + +lolin_c3_mini.menu.CPUFreq.160=160MHz (WiFi) +lolin_c3_mini.menu.CPUFreq.160.build.f_cpu=160000000L +lolin_c3_mini.menu.CPUFreq.80=80MHz (WiFi) +lolin_c3_mini.menu.CPUFreq.80.build.f_cpu=80000000L +lolin_c3_mini.menu.CPUFreq.40=40MHz +lolin_c3_mini.menu.CPUFreq.40.build.f_cpu=40000000L +lolin_c3_mini.menu.CPUFreq.20=20MHz +lolin_c3_mini.menu.CPUFreq.20.build.f_cpu=20000000L +lolin_c3_mini.menu.CPUFreq.10=10MHz +lolin_c3_mini.menu.CPUFreq.10.build.f_cpu=10000000L + + + +lolin_c3_mini.menu.FlashFreq.80=80MHz +lolin_c3_mini.menu.FlashFreq.80.build.flash_freq=80m +lolin_c3_mini.menu.FlashFreq.40=40MHz +lolin_c3_mini.menu.FlashFreq.40.build.flash_freq=40m + +lolin_c3_mini.menu.UploadSpeed.921600=921600 +lolin_c3_mini.menu.UploadSpeed.921600.upload.speed=921600 +lolin_c3_mini.menu.UploadSpeed.115200=115200 +lolin_c3_mini.menu.UploadSpeed.115200.upload.speed=115200 +lolin_c3_mini.menu.UploadSpeed.256000.windows=256000 +lolin_c3_mini.menu.UploadSpeed.256000.upload.speed=256000 +lolin_c3_mini.menu.UploadSpeed.230400.windows.upload.speed=256000 +lolin_c3_mini.menu.UploadSpeed.230400=230400 +lolin_c3_mini.menu.UploadSpeed.230400.upload.speed=230400 +lolin_c3_mini.menu.UploadSpeed.460800.linux=460800 +lolin_c3_mini.menu.UploadSpeed.460800.macosx=460800 +lolin_c3_mini.menu.UploadSpeed.460800.upload.speed=460800 +lolin_c3_mini.menu.UploadSpeed.512000.windows=512000 +lolin_c3_mini.menu.UploadSpeed.512000.upload.speed=512000 + +lolin_c3_mini.menu.DebugLevel.none=None +lolin_c3_mini.menu.DebugLevel.none.build.code_debug=0 +lolin_c3_mini.menu.DebugLevel.error=Error +lolin_c3_mini.menu.DebugLevel.error.build.code_debug=1 +lolin_c3_mini.menu.DebugLevel.warn=Warn +lolin_c3_mini.menu.DebugLevel.warn.build.code_debug=2 +lolin_c3_mini.menu.DebugLevel.info=Info +lolin_c3_mini.menu.DebugLevel.info.build.code_debug=3 +lolin_c3_mini.menu.DebugLevel.debug=Debug +lolin_c3_mini.menu.DebugLevel.debug.build.code_debug=4 +lolin_c3_mini.menu.DebugLevel.verbose=Verbose +lolin_c3_mini.menu.DebugLevel.verbose.build.code_debug=5 + +############################################################## + +lolin_s2_mini.name=LOLIN S2 Mini +lolin_s2_mini.vid.0=0x303a +lolin_s2_mini.pid.0=0x80C2 + +lolin_s2_mini.bootloader.tool=esptool_py +lolin_s2_mini.bootloader.tool.default=esptool_py + +lolin_s2_mini.upload.tool=esptool_py +lolin_s2_mini.upload.tool.default=esptool_py +lolin_s2_mini.upload.tool.network=esp_ota + +lolin_s2_mini.upload.maximum_size=1310720 +lolin_s2_mini.upload.maximum_data_size=327680 +lolin_s2_mini.upload.flags= +lolin_s2_mini.upload.extra_flags= +lolin_s2_mini.upload.use_1200bps_touch=true +lolin_s2_mini.upload.wait_for_upload_port=true +lolin_s2_mini.upload.speed=921600 + +lolin_s2_mini.serial.disableDTR=false +lolin_s2_mini.serial.disableRTS=false + +lolin_s2_mini.build.tarch=xtensa +lolin_s2_mini.build.bootloader_addr=0x1000 +lolin_s2_mini.build.target=esp32s2 +lolin_s2_mini.build.mcu=esp32s2 +lolin_s2_mini.build.core=esp32 +lolin_s2_mini.build.variant=lolin_s2_mini +lolin_s2_mini.build.board=LOLIN_S2_MINI + +lolin_s2_mini.build.cdc_on_boot=1 +lolin_s2_mini.build.msc_on_boot=1 +lolin_s2_mini.build.dfu_on_boot=1 +lolin_s2_mini.build.f_cpu=240000000L +lolin_s2_mini.build.flash_size=4MB +lolin_s2_mini.build.flash_freq=80m +lolin_s2_mini.build.flash_mode=dio +lolin_s2_mini.build.boot=qio +lolin_s2_mini.build.partitions=default +lolin_s2_mini.build.defines= + +lolin_s2_mini.build.defines=-DBOARD_HAS_PSRAM + +lolin_s2_mini.menu.CDCOnBoot.default=Enabled +lolin_s2_mini.menu.CDCOnBoot.default.build.cdc_on_boot=1 +lolin_s2_mini.menu.CDCOnBoot.dis_cdc=Disabled +lolin_s2_mini.menu.CDCOnBoot.dis_cdc.build.cdc_on_boot=0 + +lolin_s2_mini.menu.MSCOnBoot.default=Disabled +lolin_s2_mini.menu.MSCOnBoot.default.build.msc_on_boot=0 +lolin_s2_mini.menu.MSCOnBoot.msc=Enabled +lolin_s2_mini.menu.MSCOnBoot.msc.build.msc_on_boot=1 + +lolin_s2_mini.menu.DFUOnBoot.default=Disabled +lolin_s2_mini.menu.DFUOnBoot.default.build.dfu_on_boot=0 +lolin_s2_mini.menu.DFUOnBoot.dfu=Enabled +lolin_s2_mini.menu.DFUOnBoot.dfu.build.dfu_on_boot=1 + +lolin_s2_mini.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +lolin_s2_mini.menu.PartitionScheme.default.build.partitions=default +lolin_s2_mini.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +lolin_s2_mini.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +lolin_s2_mini.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +lolin_s2_mini.menu.PartitionScheme.no_ota.build.partitions=no_ota +lolin_s2_mini.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +lolin_s2_mini.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +lolin_s2_mini.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +lolin_s2_mini.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +lolin_s2_mini.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +lolin_s2_mini.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +lolin_s2_mini.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +lolin_s2_mini.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +lolin_s2_mini.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +lolin_s2_mini.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +lolin_s2_mini.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +lolin_s2_mini.menu.PartitionScheme.huge_app.build.partitions=huge_app +lolin_s2_mini.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 + +lolin_s2_mini.menu.DebugLevel.none=None +lolin_s2_mini.menu.DebugLevel.none.build.code_debug=0 +lolin_s2_mini.menu.DebugLevel.error=Error +lolin_s2_mini.menu.DebugLevel.error.build.code_debug=1 +lolin_s2_mini.menu.DebugLevel.warn=Warn +lolin_s2_mini.menu.DebugLevel.warn.build.code_debug=2 +lolin_s2_mini.menu.DebugLevel.info=Info +lolin_s2_mini.menu.DebugLevel.info.build.code_debug=3 +lolin_s2_mini.menu.DebugLevel.debug=Debug +lolin_s2_mini.menu.DebugLevel.debug.build.code_debug=4 +lolin_s2_mini.menu.DebugLevel.verbose=Verbose +lolin_s2_mini.menu.DebugLevel.verbose.build.code_debug=5 + +############################################################## + +lolin_s2_pico.name=LOLIN S2 PICO +lolin_s2_pico.vid.0=0x303a +lolin_s2_pico.pid.0=0x80C5 + +lolin_s2_pico.bootloader.tool=esptool_py +lolin_s2_pico.bootloader.tool.default=esptool_py + +lolin_s2_pico.upload.tool=esptool_py +lolin_s2_pico.upload.tool.default=esptool_py +lolin_s2_pico.upload.tool.network=esp_ota + +lolin_s2_pico.upload.maximum_size=1310720 +lolin_s2_pico.upload.maximum_data_size=327680 +lolin_s2_pico.upload.flags= +lolin_s2_pico.upload.extra_flags= +lolin_s2_pico.upload.use_1200bps_touch=true +lolin_s2_pico.upload.wait_for_upload_port=true +lolin_s2_pico.upload.speed=921600 + +lolin_s2_pico.serial.disableDTR=false +lolin_s2_pico.serial.disableRTS=false + +lolin_s2_pico.build.tarch=xtensa +lolin_s2_pico.build.bootloader_addr=0x1000 +lolin_s2_pico.build.target=esp32s2 +lolin_s2_pico.build.mcu=esp32s2 +lolin_s2_pico.build.core=esp32 +lolin_s2_pico.build.variant=lolin_s2_pico +lolin_s2_pico.build.board=LOLIN_S2_PICO + +lolin_s2_pico.build.cdc_on_boot=1 +lolin_s2_pico.build.msc_on_boot=1 +lolin_s2_pico.build.dfu_on_boot=1 +lolin_s2_pico.build.f_cpu=240000000L +lolin_s2_pico.build.flash_size=4MB +lolin_s2_pico.build.flash_freq=80m +lolin_s2_pico.build.flash_mode=dio +lolin_s2_pico.build.boot=qio +lolin_s2_pico.build.partitions=default +lolin_s2_pico.build.defines= + +lolin_s2_pico.build.defines=-DBOARD_HAS_PSRAM + +lolin_s2_pico.menu.CDCOnBoot.default=Enabled +lolin_s2_pico.menu.CDCOnBoot.default.build.cdc_on_boot=1 +lolin_s2_pico.menu.CDCOnBoot.dis_cdc=Disabled +lolin_s2_pico.menu.CDCOnBoot.dis_cdc.build.cdc_on_boot=0 + +lolin_s2_pico.menu.MSCOnBoot.default=Disabled +lolin_s2_pico.menu.MSCOnBoot.default.build.msc_on_boot=0 +lolin_s2_pico.menu.MSCOnBoot.msc=Enabled +lolin_s2_pico.menu.MSCOnBoot.msc.build.msc_on_boot=1 + +lolin_s2_pico.menu.DFUOnBoot.default=Disabled +lolin_s2_pico.menu.DFUOnBoot.default.build.dfu_on_boot=0 +lolin_s2_pico.menu.DFUOnBoot.dfu=Enabled +lolin_s2_pico.menu.DFUOnBoot.dfu.build.dfu_on_boot=1 + +lolin_s2_pico.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +lolin_s2_pico.menu.PartitionScheme.default.build.partitions=default +lolin_s2_pico.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +lolin_s2_pico.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +lolin_s2_pico.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +lolin_s2_pico.menu.PartitionScheme.no_ota.build.partitions=no_ota +lolin_s2_pico.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +lolin_s2_pico.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +lolin_s2_pico.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +lolin_s2_pico.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +lolin_s2_pico.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +lolin_s2_pico.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +lolin_s2_pico.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +lolin_s2_pico.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +lolin_s2_pico.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +lolin_s2_pico.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +lolin_s2_pico.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +lolin_s2_pico.menu.PartitionScheme.huge_app.build.partitions=huge_app +lolin_s2_pico.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 + +lolin_s2_pico.menu.DebugLevel.none=None +lolin_s2_pico.menu.DebugLevel.none.build.code_debug=0 +lolin_s2_pico.menu.DebugLevel.error=Error +lolin_s2_pico.menu.DebugLevel.error.build.code_debug=1 +lolin_s2_pico.menu.DebugLevel.warn=Warn +lolin_s2_pico.menu.DebugLevel.warn.build.code_debug=2 +lolin_s2_pico.menu.DebugLevel.info=Info +lolin_s2_pico.menu.DebugLevel.info.build.code_debug=3 +lolin_s2_pico.menu.DebugLevel.debug=Debug +lolin_s2_pico.menu.DebugLevel.debug.build.code_debug=4 +lolin_s2_pico.menu.DebugLevel.verbose=Verbose +lolin_s2_pico.menu.DebugLevel.verbose.build.code_debug=5 + +############################################################## + lolin32.name=WEMOS LOLIN32 +lolin32.bootloader.tool=esptool_py +lolin32.bootloader.tool.default=esptool_py + lolin32.upload.tool=esptool_py +lolin32.upload.tool.default=esptool_py +lolin32.upload.tool.network=esp_ota + lolin32.upload.maximum_size=1310720 lolin32.upload.maximum_data_size=327680 lolin32.upload.flags= @@ -3212,11 +5073,30 @@ lolin32.menu.UploadSpeed.460800.upload.speed=460800 lolin32.menu.UploadSpeed.512000.windows=512000 lolin32.menu.UploadSpeed.512000.upload.speed=512000 +lolin32.menu.DebugLevel.none=None +lolin32.menu.DebugLevel.none.build.code_debug=0 +lolin32.menu.DebugLevel.error=Error +lolin32.menu.DebugLevel.error.build.code_debug=1 +lolin32.menu.DebugLevel.warn=Warn +lolin32.menu.DebugLevel.warn.build.code_debug=2 +lolin32.menu.DebugLevel.info=Info +lolin32.menu.DebugLevel.info.build.code_debug=3 +lolin32.menu.DebugLevel.debug=Debug +lolin32.menu.DebugLevel.debug.build.code_debug=4 +lolin32.menu.DebugLevel.verbose=Verbose +lolin32.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## lolin32-lite.name=WEMOS LOLIN32 Lite +lolin32-lite.bootloader.tool=esptool_py +lolin32-lite.bootloader.tool.default=esptool_py + lolin32-lite.upload.tool=esptool_py +lolin32-lite.upload.tool.default=esptool_py +lolin32-lite.upload.tool.network=esp_ota + lolin32-lite.upload.maximum_size=1310720 lolin32-lite.upload.maximum_data_size=327680 lolin32-lite.upload.wait_for_upload_port=true @@ -3287,11 +5167,30 @@ lolin32-lite.menu.UploadSpeed.460800.upload.speed=460800 lolin32-lite.menu.UploadSpeed.512000.windows=512000 lolin32-lite.menu.UploadSpeed.512000.upload.speed=512000 +lolin32-lite.menu.DebugLevel.none=None +lolin32-lite.menu.DebugLevel.none.build.code_debug=0 +lolin32-lite.menu.DebugLevel.error=Error +lolin32-lite.menu.DebugLevel.error.build.code_debug=1 +lolin32-lite.menu.DebugLevel.warn=Warn +lolin32-lite.menu.DebugLevel.warn.build.code_debug=2 +lolin32-lite.menu.DebugLevel.info=Info +lolin32-lite.menu.DebugLevel.info.build.code_debug=3 +lolin32-lite.menu.DebugLevel.debug=Debug +lolin32-lite.menu.DebugLevel.debug.build.code_debug=4 +lolin32-lite.menu.DebugLevel.verbose=Verbose +lolin32-lite.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## pocket_32.name=Dongsen Tech Pocket 32 +pocket_32.bootloader.tool=esptool_py +pocket_32.bootloader.tool.default=esptool_py + pocket_32.upload.tool=esptool_py +pocket_32.upload.tool.default=esptool_py +pocket_32.upload.tool.network=esp_ota + pocket_32.upload.maximum_size=1310720 pocket_32.upload.maximum_data_size=327680 pocket_32.upload.flags= @@ -3335,11 +5234,30 @@ pocket_32.menu.UploadSpeed.460800.upload.speed=460800 pocket_32.menu.UploadSpeed.512000.windows=512000 pocket_32.menu.UploadSpeed.512000.upload.speed=512000 +pocket_32.menu.DebugLevel.none=None +pocket_32.menu.DebugLevel.none.build.code_debug=0 +pocket_32.menu.DebugLevel.error=Error +pocket_32.menu.DebugLevel.error.build.code_debug=1 +pocket_32.menu.DebugLevel.warn=Warn +pocket_32.menu.DebugLevel.warn.build.code_debug=2 +pocket_32.menu.DebugLevel.info=Info +pocket_32.menu.DebugLevel.info.build.code_debug=3 +pocket_32.menu.DebugLevel.debug=Debug +pocket_32.menu.DebugLevel.debug.build.code_debug=4 +pocket_32.menu.DebugLevel.verbose=Verbose +pocket_32.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## WeMosBat.name=WeMos WiFi&Bluetooth Battery +WeMosBat.bootloader.tool=esptool_py +WeMosBat.bootloader.tool.default=esptool_py + WeMosBat.upload.tool=esptool_py +WeMosBat.upload.tool.default=esptool_py +WeMosBat.upload.tool.network=esp_ota + WeMosBat.upload.maximum_size=1310720 WeMosBat.upload.maximum_data_size=327680 WeMosBat.upload.flags= @@ -3363,6 +5281,43 @@ WeMosBat.build.boot=dio WeMosBat.build.partitions=default WeMosBat.build.defines= +WeMosBat.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +WeMosBat.menu.PartitionScheme.default.build.partitions=default +WeMosBat.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +WeMosBat.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +WeMosBat.menu.PartitionScheme.default_8MB=8M Flash (3MB APP/1.5MB FAT) +WeMosBat.menu.PartitionScheme.default_8MB.build.partitions=default_8MB +WeMosBat.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 +WeMosBat.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS) +WeMosBat.menu.PartitionScheme.minimal.build.partitions=minimal +WeMosBat.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +WeMosBat.menu.PartitionScheme.no_ota.build.partitions=no_ota +WeMosBat.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +WeMosBat.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +WeMosBat.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +WeMosBat.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +WeMosBat.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +WeMosBat.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +WeMosBat.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +WeMosBat.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +WeMosBat.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +WeMosBat.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +WeMosBat.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +WeMosBat.menu.PartitionScheme.huge_app.build.partitions=huge_app +WeMosBat.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 +WeMosBat.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS) +WeMosBat.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +WeMosBat.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 +WeMosBat.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FAT) +WeMosBat.menu.PartitionScheme.fatflash.build.partitions=ffat +WeMosBat.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 +WeMosBat.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9MB FATFS) +WeMosBat.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB +WeMosBat.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 +WeMosBat.menu.PartitionScheme.rainmaker=RainMaker +WeMosBat.menu.PartitionScheme.rainmaker.build.partitions=rainmaker +WeMosBat.menu.PartitionScheme.rainmaker.upload.maximum_size=3145728 + WeMosBat.menu.FlashFreq.80=80MHz WeMosBat.menu.FlashFreq.80.build.flash_freq=80m WeMosBat.menu.FlashFreq.40=40MHz @@ -3400,7 +5355,13 @@ WeMosBat.menu.DebugLevel.verbose.build.code_debug=5 espea32.name=ESPea32 +espea32.bootloader.tool=esptool_py +espea32.bootloader.tool.default=esptool_py + espea32.upload.tool=esptool_py +espea32.upload.tool.default=esptool_py +espea32.upload.tool.network=esp_ota + espea32.upload.maximum_size=1310720 espea32.upload.maximum_data_size=327680 espea32.upload.flags= @@ -3444,11 +5405,30 @@ espea32.menu.UploadSpeed.460800.upload.speed=460800 espea32.menu.UploadSpeed.512000.windows=512000 espea32.menu.UploadSpeed.512000.upload.speed=512000 +espea32.menu.DebugLevel.none=None +espea32.menu.DebugLevel.none.build.code_debug=0 +espea32.menu.DebugLevel.error=Error +espea32.menu.DebugLevel.error.build.code_debug=1 +espea32.menu.DebugLevel.warn=Warn +espea32.menu.DebugLevel.warn.build.code_debug=2 +espea32.menu.DebugLevel.info=Info +espea32.menu.DebugLevel.info.build.code_debug=3 +espea32.menu.DebugLevel.debug=Debug +espea32.menu.DebugLevel.debug.build.code_debug=4 +espea32.menu.DebugLevel.verbose=Verbose +espea32.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## quantum.name=Noduino Quantum +quantum.bootloader.tool=esptool_py +quantum.bootloader.tool.default=esptool_py + quantum.upload.tool=esptool_py +quantum.upload.tool.default=esptool_py +quantum.upload.tool.network=esp_ota + quantum.upload.maximum_size=1310720 quantum.upload.maximum_data_size=327680 quantum.upload.flags= @@ -3492,11 +5472,30 @@ quantum.menu.UploadSpeed.460800.upload.speed=460800 quantum.menu.UploadSpeed.512000.windows=512000 quantum.menu.UploadSpeed.512000.upload.speed=512000 +quantum.menu.DebugLevel.none=None +quantum.menu.DebugLevel.none.build.code_debug=0 +quantum.menu.DebugLevel.error=Error +quantum.menu.DebugLevel.error.build.code_debug=1 +quantum.menu.DebugLevel.warn=Warn +quantum.menu.DebugLevel.warn.build.code_debug=2 +quantum.menu.DebugLevel.info=Info +quantum.menu.DebugLevel.info.build.code_debug=3 +quantum.menu.DebugLevel.debug=Debug +quantum.menu.DebugLevel.debug.build.code_debug=4 +quantum.menu.DebugLevel.verbose=Verbose +quantum.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## node32s.name=Node32s +node32s.bootloader.tool=esptool_py +node32s.bootloader.tool.default=esptool_py + node32s.upload.tool=esptool_py +node32s.upload.tool.default=esptool_py +node32s.upload.tool.network=esp_ota + node32s.upload.maximum_size=1310720 node32s.upload.maximum_data_size=327680 node32s.upload.flags= @@ -3566,7 +5565,13 @@ node32s.menu.DebugLevel.verbose.build.code_debug=5 hornbill32dev.name=Hornbill ESP32 Dev +hornbill32dev.bootloader.tool=esptool_py +hornbill32dev.bootloader.tool.default=esptool_py + hornbill32dev.upload.tool=esptool_py +hornbill32dev.upload.tool.default=esptool_py +hornbill32dev.upload.tool.network=esp_ota + hornbill32dev.upload.maximum_size=1310720 hornbill32dev.upload.maximum_data_size=327680 hornbill32dev.upload.flags= @@ -3610,11 +5615,30 @@ hornbill32dev.menu.UploadSpeed.460800.upload.speed=460800 hornbill32dev.menu.UploadSpeed.512000.windows=512000 hornbill32dev.menu.UploadSpeed.512000.upload.speed=512000 +hornbill32dev.menu.DebugLevel.none=None +hornbill32dev.menu.DebugLevel.none.build.code_debug=0 +hornbill32dev.menu.DebugLevel.error=Error +hornbill32dev.menu.DebugLevel.error.build.code_debug=1 +hornbill32dev.menu.DebugLevel.warn=Warn +hornbill32dev.menu.DebugLevel.warn.build.code_debug=2 +hornbill32dev.menu.DebugLevel.info=Info +hornbill32dev.menu.DebugLevel.info.build.code_debug=3 +hornbill32dev.menu.DebugLevel.debug=Debug +hornbill32dev.menu.DebugLevel.debug.build.code_debug=4 +hornbill32dev.menu.DebugLevel.verbose=Verbose +hornbill32dev.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## hornbill32minima.name=Hornbill ESP32 Minima +hornbill32minima.bootloader.tool=esptool_py +hornbill32minima.bootloader.tool.default=esptool_py + hornbill32minima.upload.tool=esptool_py +hornbill32minima.upload.tool.default=esptool_py +hornbill32minima.upload.tool.network=esp_ota + hornbill32minima.upload.maximum_size=1310720 hornbill32minima.upload.maximum_data_size=327680 hornbill32minima.upload.flags= @@ -3657,11 +5681,30 @@ hornbill32minima.menu.UploadSpeed.460800.upload.speed=460800 hornbill32minima.menu.UploadSpeed.512000.windows=512000 hornbill32minima.menu.UploadSpeed.512000.upload.speed=512000 +hornbill32minima.menu.DebugLevel.none=None +hornbill32minima.menu.DebugLevel.none.build.code_debug=0 +hornbill32minima.menu.DebugLevel.error=Error +hornbill32minima.menu.DebugLevel.error.build.code_debug=1 +hornbill32minima.menu.DebugLevel.warn=Warn +hornbill32minima.menu.DebugLevel.warn.build.code_debug=2 +hornbill32minima.menu.DebugLevel.info=Info +hornbill32minima.menu.DebugLevel.info.build.code_debug=3 +hornbill32minima.menu.DebugLevel.debug=Debug +hornbill32minima.menu.DebugLevel.debug.build.code_debug=4 +hornbill32minima.menu.DebugLevel.verbose=Verbose +hornbill32minima.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## firebeetle32.name=FireBeetle-ESP32 +firebeetle32.bootloader.tool=esptool_py +firebeetle32.bootloader.tool.default=esptool_py + firebeetle32.upload.tool=esptool_py +firebeetle32.upload.tool.default=esptool_py +firebeetle32.upload.tool.network=esp_ota + firebeetle32.upload.maximum_size=1310720 firebeetle32.upload.maximum_data_size=327680 firebeetle32.upload.flags= @@ -3705,11 +5748,30 @@ firebeetle32.menu.UploadSpeed.460800.upload.speed=460800 firebeetle32.menu.UploadSpeed.512000.windows=512000 firebeetle32.menu.UploadSpeed.512000.upload.speed=512000 +firebeetle32.menu.DebugLevel.none=None +firebeetle32.menu.DebugLevel.none.build.code_debug=0 +firebeetle32.menu.DebugLevel.error=Error +firebeetle32.menu.DebugLevel.error.build.code_debug=1 +firebeetle32.menu.DebugLevel.warn=Warn +firebeetle32.menu.DebugLevel.warn.build.code_debug=2 +firebeetle32.menu.DebugLevel.info=Info +firebeetle32.menu.DebugLevel.info.build.code_debug=3 +firebeetle32.menu.DebugLevel.debug=Debug +firebeetle32.menu.DebugLevel.debug.build.code_debug=4 +firebeetle32.menu.DebugLevel.verbose=Verbose +firebeetle32.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## intorobot-fig.name=IntoRobot Fig +intorobot-fig.bootloader.tool=esptool_py +intorobot-fig.bootloader.tool.default=esptool_py + intorobot-fig.upload.tool=esptool_py +intorobot-fig.upload.tool.default=esptool_py +intorobot-fig.upload.tool.network=esp_ota + intorobot-fig.upload.maximum_size=1310720 intorobot-fig.upload.maximum_data_size=327680 intorobot-fig.upload.flags= @@ -3753,11 +5815,30 @@ intorobot-fig.menu.UploadSpeed.460800.upload.speed=460800 intorobot-fig.menu.UploadSpeed.512000.windows=512000 intorobot-fig.menu.UploadSpeed.512000.upload.speed=512000 +intorobot-fig.menu.DebugLevel.none=None +intorobot-fig.menu.DebugLevel.none.build.code_debug=0 +intorobot-fig.menu.DebugLevel.error=Error +intorobot-fig.menu.DebugLevel.error.build.code_debug=1 +intorobot-fig.menu.DebugLevel.warn=Warn +intorobot-fig.menu.DebugLevel.warn.build.code_debug=2 +intorobot-fig.menu.DebugLevel.info=Info +intorobot-fig.menu.DebugLevel.info.build.code_debug=3 +intorobot-fig.menu.DebugLevel.debug=Debug +intorobot-fig.menu.DebugLevel.debug.build.code_debug=4 +intorobot-fig.menu.DebugLevel.verbose=Verbose +intorobot-fig.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## onehorse32dev.name=Onehorse ESP32 Dev Module +onehorse32dev.bootloader.tool=esptool_py +onehorse32dev.bootloader.tool.default=esptool_py + onehorse32dev.upload.tool=esptool_py +onehorse32dev.upload.tool.default=esptool_py +onehorse32dev.upload.tool.network=esp_ota + onehorse32dev.upload.maximum_size=1310720 onehorse32dev.upload.maximum_data_size=327680 onehorse32dev.upload.flags= @@ -3801,11 +5882,30 @@ onehorse32dev.menu.UploadSpeed.460800.upload.speed=460800 onehorse32dev.menu.UploadSpeed.512000.windows=512000 onehorse32dev.menu.UploadSpeed.512000.upload.speed=512000 +onehorse32dev.menu.DebugLevel.none=None +onehorse32dev.menu.DebugLevel.none.build.code_debug=0 +onehorse32dev.menu.DebugLevel.error=Error +onehorse32dev.menu.DebugLevel.error.build.code_debug=1 +onehorse32dev.menu.DebugLevel.warn=Warn +onehorse32dev.menu.DebugLevel.warn.build.code_debug=2 +onehorse32dev.menu.DebugLevel.info=Info +onehorse32dev.menu.DebugLevel.info.build.code_debug=3 +onehorse32dev.menu.DebugLevel.debug=Debug +onehorse32dev.menu.DebugLevel.debug.build.code_debug=4 +onehorse32dev.menu.DebugLevel.verbose=Verbose +onehorse32dev.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## featheresp32.name=Adafruit ESP32 Feather +featheresp32.bootloader.tool=esptool_py +featheresp32.bootloader.tool.default=esptool_py + featheresp32.upload.tool=esptool_py +featheresp32.upload.tool.default=esptool_py +featheresp32.upload.tool.network=esp_ota + featheresp32.upload.maximum_size=1310720 featheresp32.upload.maximum_data_size=327680 featheresp32.upload.flags= @@ -3881,7 +5981,13 @@ adafruit_metro_esp32s2.pid.1=0x00DF adafruit_metro_esp32s2.vid.1=0x239A adafruit_metro_esp32s2.pid.1=0x80E0 +adafruit_metro_esp32s2.bootloader.tool=esptool_py +adafruit_metro_esp32s2.bootloader.tool.default=esptool_py + adafruit_metro_esp32s2.upload.tool=esptool_py +adafruit_metro_esp32s2.upload.tool.default=esptool_py +adafruit_metro_esp32s2.upload.tool.network=esp_ota + adafruit_metro_esp32s2.upload.maximum_size=1310720 adafruit_metro_esp32s2.upload.maximum_data_size=327680 adafruit_metro_esp32s2.upload.flags= @@ -4042,7 +6148,6 @@ adafruit_metro_esp32s2.menu.DebugLevel.debug.build.code_debug=4 adafruit_metro_esp32s2.menu.DebugLevel.verbose=Verbose adafruit_metro_esp32s2.menu.DebugLevel.verbose.build.code_debug=5 - ############################################################## adafruit_magtag29_esp32s2.name=Adafruit MagTag 2.9" @@ -4053,7 +6158,13 @@ adafruit_magtag29_esp32s2.pid.1=0x00E5 adafruit_magtag29_esp32s2.vid.1=0x239A adafruit_magtag29_esp32s2.pid.1=0x80E6 +adafruit_magtag29_esp32s2.bootloader.tool=esptool_py +adafruit_magtag29_esp32s2.bootloader.tool.default=esptool_py + adafruit_magtag29_esp32s2.upload.tool=esptool_py +adafruit_magtag29_esp32s2.upload.tool.default=esptool_py +adafruit_magtag29_esp32s2.upload.tool.network=esp_ota + adafruit_magtag29_esp32s2.upload.maximum_size=1310720 adafruit_magtag29_esp32s2.upload.maximum_data_size=327680 adafruit_magtag29_esp32s2.upload.flags= @@ -4214,7 +6325,6 @@ adafruit_magtag29_esp32s2.menu.DebugLevel.debug.build.code_debug=4 adafruit_magtag29_esp32s2.menu.DebugLevel.verbose=Verbose adafruit_magtag29_esp32s2.menu.DebugLevel.verbose.build.code_debug=5 - ############################################################## adafruit_funhouse_esp32s2.name=Adafruit FunHouse @@ -4225,7 +6335,13 @@ adafruit_funhouse_esp32s2.pid.1=0x00F9 adafruit_funhouse_esp32s2.vid.1=0x239A adafruit_funhouse_esp32s2.pid.1=0x80FA +adafruit_funhouse_esp32s2.bootloader.tool=esptool_py +adafruit_funhouse_esp32s2.bootloader.tool.default=esptool_py + adafruit_funhouse_esp32s2.upload.tool=esptool_py +adafruit_funhouse_esp32s2.upload.tool.default=esptool_py +adafruit_funhouse_esp32s2.upload.tool.network=esp_ota + adafruit_funhouse_esp32s2.upload.maximum_size=1310720 adafruit_funhouse_esp32s2.upload.maximum_data_size=327680 adafruit_funhouse_esp32s2.upload.flags= @@ -4386,7 +6502,6 @@ adafruit_funhouse_esp32s2.menu.DebugLevel.debug.build.code_debug=4 adafruit_funhouse_esp32s2.menu.DebugLevel.verbose=Verbose adafruit_funhouse_esp32s2.menu.DebugLevel.verbose.build.code_debug=5 - ############################################################## adafruit_feather_esp32s2.name=Adafruit Feather ESP32-S2 @@ -4397,7 +6512,13 @@ adafruit_feather_esp32s2.pid.1=0x00EB adafruit_feather_esp32s2.vid.1=0x239A adafruit_feather_esp32s2.pid.1=0x80EC +adafruit_feather_esp32s2.bootloader.tool=esptool_py +adafruit_feather_esp32s2.bootloader.tool.default=esptool_py + adafruit_feather_esp32s2.upload.tool=esptool_py +adafruit_feather_esp32s2.upload.tool.default=esptool_py +adafruit_feather_esp32s2.upload.tool.network=esp_ota + adafruit_feather_esp32s2.upload.maximum_size=1310720 adafruit_feather_esp32s2.upload.maximum_data_size=327680 adafruit_feather_esp32s2.upload.flags= @@ -4568,7 +6689,13 @@ adafruit_feather_esp32s2_tft.pid.1=0x010F adafruit_feather_esp32s2_tft.vid.1=0x239A adafruit_feather_esp32s2_tft.pid.1=0x8110 +adafruit_feather_esp32s2_tft.bootloader.tool=esptool_py +adafruit_feather_esp32s2_tft.bootloader.tool.default=esptool_py + adafruit_feather_esp32s2_tft.upload.tool=esptool_py +adafruit_feather_esp32s2_tft.upload.tool.default=esptool_py +adafruit_feather_esp32s2_tft.upload.tool.network=esp_ota + adafruit_feather_esp32s2_tft.upload.maximum_size=1310720 adafruit_feather_esp32s2_tft.upload.maximum_data_size=327680 adafruit_feather_esp32s2_tft.upload.flags= @@ -4732,7 +6859,13 @@ adafruit_qtpy_esp32s2.pid.1=0x0111 adafruit_qtpy_esp32s2.vid.1=0x239A adafruit_qtpy_esp32s2.pid.1=0x8112 +adafruit_qtpy_esp32s2.bootloader.tool=esptool_py +adafruit_qtpy_esp32s2.bootloader.tool.default=esptool_py + adafruit_qtpy_esp32s2.upload.tool=esptool_py +adafruit_qtpy_esp32s2.upload.tool.default=esptool_py +adafruit_qtpy_esp32s2.upload.tool.network=esp_ota + adafruit_qtpy_esp32s2.upload.maximum_size=1310720 adafruit_qtpy_esp32s2.upload.maximum_data_size=327680 adafruit_qtpy_esp32s2.upload.flags= @@ -4886,11 +7019,607 @@ adafruit_qtpy_esp32s2.menu.DebugLevel.debug.build.code_debug=4 adafruit_qtpy_esp32s2.menu.DebugLevel.verbose=Verbose adafruit_qtpy_esp32s2.menu.DebugLevel.verbose.build.code_debug=5 +############################################################## + +adafruit_qtpy_esp32c3.name=Adafruit QT Py ESP32-C3 +adafruit_qtpy_esp32c3.vid.0=0x303a +adafruit_qtpy_esp32c3.pid.0=0x1001 + +adafruit_qtpy_esp32c3.bootloader.tool=esptool_py +adafruit_qtpy_esp32c3.bootloader.tool.default=esptool_py + +adafruit_qtpy_esp32c3.upload.tool=esptool_py +adafruit_qtpy_esp32c3.upload.tool.default=esptool_py +adafruit_qtpy_esp32c3.upload.tool.network=esp_ota + +adafruit_qtpy_esp32c3.upload.maximum_size=1310720 +adafruit_qtpy_esp32c3.upload.maximum_data_size=327680 +adafruit_qtpy_esp32c3.upload.flags= +adafruit_qtpy_esp32c3.upload.extra_flags= +adafruit_qtpy_esp32c3.upload.use_1200bps_touch=false +adafruit_qtpy_esp32c3.upload.wait_for_upload_port=false + +adafruit_qtpy_esp32c3.serial.disableDTR=false +adafruit_qtpy_esp32c3.serial.disableRTS=false + +adafruit_qtpy_esp32c3.build.tarch=riscv32 +adafruit_qtpy_esp32c3.build.target=esp +adafruit_qtpy_esp32c3.build.mcu=esp32c3 +adafruit_qtpy_esp32c3.build.core=esp32 +adafruit_qtpy_esp32c3.build.variant=adafruit_qtpy_esp32c3 +adafruit_qtpy_esp32c3.build.board=ADAFRUIT_QTPY_ESP32C3 +adafruit_qtpy_esp32c3.build.bootloader_addr=0x0 + +adafruit_qtpy_esp32c3.build.cdc_on_boot=0 +adafruit_qtpy_esp32c3.build.f_cpu=160000000L +adafruit_qtpy_esp32c3.build.flash_size=4MB +adafruit_qtpy_esp32c3.build.flash_freq=80m +adafruit_qtpy_esp32c3.build.flash_mode=dout +adafruit_qtpy_esp32c3.build.boot=dout +adafruit_qtpy_esp32c3.build.partitions=default +adafruit_qtpy_esp32c3.build.defines= + +adafruit_qtpy_esp32c3.menu.CDCOnBoot.cdc=Enabled +adafruit_qtpy_esp32c3.menu.CDCOnBoot.cdc.build.cdc_on_boot=1 +adafruit_qtpy_esp32c3.menu.CDCOnBoot.default=Disabled +adafruit_qtpy_esp32c3.menu.CDCOnBoot.default.build.cdc_on_boot=0 + +adafruit_qtpy_esp32c3.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +adafruit_qtpy_esp32c3.menu.PartitionScheme.default.build.partitions=default +adafruit_qtpy_esp32c3.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +adafruit_qtpy_esp32c3.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +adafruit_qtpy_esp32c3.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS) +adafruit_qtpy_esp32c3.menu.PartitionScheme.minimal.build.partitions=minimal +adafruit_qtpy_esp32c3.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +adafruit_qtpy_esp32c3.menu.PartitionScheme.no_ota.build.partitions=no_ota +adafruit_qtpy_esp32c3.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +adafruit_qtpy_esp32c3.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +adafruit_qtpy_esp32c3.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +adafruit_qtpy_esp32c3.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +adafruit_qtpy_esp32c3.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +adafruit_qtpy_esp32c3.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +adafruit_qtpy_esp32c3.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +adafruit_qtpy_esp32c3.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +adafruit_qtpy_esp32c3.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +adafruit_qtpy_esp32c3.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +adafruit_qtpy_esp32c3.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +adafruit_qtpy_esp32c3.menu.PartitionScheme.huge_app.build.partitions=huge_app +adafruit_qtpy_esp32c3.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 +adafruit_qtpy_esp32c3.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS) +adafruit_qtpy_esp32c3.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +adafruit_qtpy_esp32c3.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 + +adafruit_qtpy_esp32c3.menu.CPUFreq.160=160MHz (WiFi) +adafruit_qtpy_esp32c3.menu.CPUFreq.160.build.f_cpu=160000000L +adafruit_qtpy_esp32c3.menu.CPUFreq.80=80MHz (WiFi) +adafruit_qtpy_esp32c3.menu.CPUFreq.80.build.f_cpu=80000000L +adafruit_qtpy_esp32c3.menu.CPUFreq.40=40MHz +adafruit_qtpy_esp32c3.menu.CPUFreq.40.build.f_cpu=40000000L +adafruit_qtpy_esp32c3.menu.CPUFreq.20=20MHz +adafruit_qtpy_esp32c3.menu.CPUFreq.20.build.f_cpu=20000000L +adafruit_qtpy_esp32c3.menu.CPUFreq.10=10MHz +adafruit_qtpy_esp32c3.menu.CPUFreq.10.build.f_cpu=10000000L + +adafruit_qtpy_esp32c3.menu.FlashMode.dout=DOUT +adafruit_qtpy_esp32c3.menu.FlashMode.dout.build.flash_mode=dout +adafruit_qtpy_esp32c3.menu.FlashMode.dout.build.boot=dout +adafruit_qtpy_esp32c3.menu.FlashMode.qio=QIO +adafruit_qtpy_esp32c3.menu.FlashMode.qio.build.flash_mode=dio +adafruit_qtpy_esp32c3.menu.FlashMode.qio.build.boot=qio +adafruit_qtpy_esp32c3.menu.FlashMode.dio=DIO +adafruit_qtpy_esp32c3.menu.FlashMode.dio.build.flash_mode=dio +adafruit_qtpy_esp32c3.menu.FlashMode.dio.build.boot=dio +adafruit_qtpy_esp32c3.menu.FlashMode.qout=QOUT +adafruit_qtpy_esp32c3.menu.FlashMode.qout.build.flash_mode=dout +adafruit_qtpy_esp32c3.menu.FlashMode.qout.build.boot=qout + +adafruit_qtpy_esp32c3.menu.FlashFreq.80=80MHz +adafruit_qtpy_esp32c3.menu.FlashFreq.80.build.flash_freq=80m +adafruit_qtpy_esp32c3.menu.FlashFreq.40=40MHz +adafruit_qtpy_esp32c3.menu.FlashFreq.40.build.flash_freq=40m + +adafruit_qtpy_esp32c3.menu.FlashSize.4M=4MB (32Mb) +adafruit_qtpy_esp32c3.menu.FlashSize.4M.build.flash_size=4MB +adafruit_qtpy_esp32c3.menu.FlashSize.2M=2MB (16Mb) +adafruit_qtpy_esp32c3.menu.FlashSize.2M.build.flash_size=2MB +adafruit_qtpy_esp32c3.menu.FlashSize.2M.build.partitions=minimal + +adafruit_qtpy_esp32c3.menu.UploadSpeed.115200=115200 +adafruit_qtpy_esp32c3.menu.UploadSpeed.115200.upload.speed=115200 +adafruit_qtpy_esp32c3.menu.UploadSpeed.921600=921600 +adafruit_qtpy_esp32c3.menu.UploadSpeed.921600.upload.speed=921600 +adafruit_qtpy_esp32c3.menu.UploadSpeed.921600=921600 +adafruit_qtpy_esp32c3.menu.UploadSpeed.921600.upload.speed=921600 +adafruit_qtpy_esp32c3.menu.UploadSpeed.115200=115200 +adafruit_qtpy_esp32c3.menu.UploadSpeed.115200.upload.speed=115200 +adafruit_qtpy_esp32c3.menu.UploadSpeed.256000.windows=256000 +adafruit_qtpy_esp32c3.menu.UploadSpeed.256000.upload.speed=256000 +adafruit_qtpy_esp32c3.menu.UploadSpeed.230400.windows.upload.speed=256000 +adafruit_qtpy_esp32c3.menu.UploadSpeed.230400=230400 +adafruit_qtpy_esp32c3.menu.UploadSpeed.230400.upload.speed=230400 +adafruit_qtpy_esp32c3.menu.UploadSpeed.460800.linux=460800 +adafruit_qtpy_esp32c3.menu.UploadSpeed.460800.macosx=460800 +adafruit_qtpy_esp32c3.menu.UploadSpeed.460800.upload.speed=460800 +adafruit_qtpy_esp32c3.menu.UploadSpeed.512000.windows=512000 +adafruit_qtpy_esp32c3.menu.UploadSpeed.512000.upload.speed=512000 + +adafruit_qtpy_esp32c3.menu.DebugLevel.none=None +adafruit_qtpy_esp32c3.menu.DebugLevel.none.build.code_debug=0 +adafruit_qtpy_esp32c3.menu.DebugLevel.error=Error +adafruit_qtpy_esp32c3.menu.DebugLevel.error.build.code_debug=1 +adafruit_qtpy_esp32c3.menu.DebugLevel.warn=Warn +adafruit_qtpy_esp32c3.menu.DebugLevel.warn.build.code_debug=2 +adafruit_qtpy_esp32c3.menu.DebugLevel.info=Info +adafruit_qtpy_esp32c3.menu.DebugLevel.info.build.code_debug=3 +adafruit_qtpy_esp32c3.menu.DebugLevel.debug=Debug +adafruit_qtpy_esp32c3.menu.DebugLevel.debug.build.code_debug=4 +adafruit_qtpy_esp32c3.menu.DebugLevel.verbose=Verbose +adafruit_qtpy_esp32c3.menu.DebugLevel.verbose.build.code_debug=5 + + +adafruit_qtpy_esp32_pico.name=Adafruit QT Py ESP32 + +adafruit_qtpy_esp32_pico.bootloader.tool=esptool_py +adafruit_qtpy_esp32_pico.bootloader.tool.default=esptool_py + +adafruit_qtpy_esp32_pico.upload.tool=esptool_py +adafruit_qtpy_esp32_pico.upload.tool.default=esptool_py +adafruit_qtpy_esp32_pico.upload.tool.network=esp_ota + +adafruit_qtpy_esp32_pico.upload.maximum_size=1310720 +adafruit_qtpy_esp32_pico.upload.maximum_data_size=327680 +adafruit_qtpy_esp32_pico.upload.flags= +adafruit_qtpy_esp32_pico.upload.extra_flags= + +adafruit_qtpy_esp32_pico.serial.disableDTR=true +adafruit_qtpy_esp32_pico.serial.disableRTS=true + +adafruit_qtpy_esp32_pico.build.tarch=xtensa +adafruit_qtpy_esp32_pico.build.bootloader_addr=0x1000 +adafruit_qtpy_esp32_pico.build.target=esp32 +adafruit_qtpy_esp32_pico.build.mcu=esp32 +adafruit_qtpy_esp32_pico.build.core=esp32 +adafruit_qtpy_esp32_pico.build.variant=adafruit_qtpy_esp32 +adafruit_qtpy_esp32_pico.build.board=ADAFRUIT_QTPY_ESP32_PICO + +adafruit_qtpy_esp32_pico.build.f_cpu=240000000L +adafruit_qtpy_esp32_pico.build.flash_size=8MB +adafruit_qtpy_esp32_pico.build.flash_freq=80m +adafruit_qtpy_esp32_pico.build.flash_mode=dio +adafruit_qtpy_esp32_pico.build.boot=dio +adafruit_qtpy_esp32_pico.build.partitions=default +adafruit_qtpy_esp32_pico.build.defines= + +adafruit_qtpy_esp32_pico.menu.PartitionScheme.default=Default +adafruit_qtpy_esp32_pico.menu.PartitionScheme.default.build.partitions=default +adafruit_qtpy_esp32_pico.menu.PartitionScheme.no_ota=No OTA (Large APP) +adafruit_qtpy_esp32_pico.menu.PartitionScheme.no_ota.build.partitions=no_ota +adafruit_qtpy_esp32_pico.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +adafruit_qtpy_esp32_pico.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (Large APPS with OTA) +adafruit_qtpy_esp32_pico.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +adafruit_qtpy_esp32_pico.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 + +adafruit_qtpy_esp32_pico.menu.UploadSpeed.921600=921600 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.921600.upload.speed=921600 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.115200=115200 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.115200.upload.speed=115200 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.256000.windows=256000 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.256000.upload.speed=256000 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.230400.windows.upload.speed=256000 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.230400=230400 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.230400.upload.speed=230400 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.460800.linux=460800 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.460800.macosx=460800 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.460800.upload.speed=460800 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.512000.windows=512000 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.512000.upload.speed=512000 + +adafruit_qtpy_esp32_pico.menu.PSRAM.enabled=Enabled +adafruit_qtpy_esp32_pico.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue -mfix-esp32-psram-cache-strategy=memw +adafruit_qtpy_esp32_pico.menu.PSRAM.enabled.build.extra_libs= +adafruit_qtpy_esp32_pico.menu.PSRAM.disabled=Disabled +adafruit_qtpy_esp32_pico.menu.PSRAM.disabled.build.defines= +adafruit_qtpy_esp32_pico.menu.PSRAM.disabled.build.extra_libs= + +adafruit_qtpy_esp32_pico.menu.DebugLevel.none=None +adafruit_qtpy_esp32_pico.menu.DebugLevel.none.build.code_debug=0 +adafruit_qtpy_esp32_pico.menu.DebugLevel.error=Error +adafruit_qtpy_esp32_pico.menu.DebugLevel.error.build.code_debug=1 +adafruit_qtpy_esp32_pico.menu.DebugLevel.warn=Warn +adafruit_qtpy_esp32_pico.menu.DebugLevel.warn.build.code_debug=2 +adafruit_qtpy_esp32_pico.menu.DebugLevel.info=Info +adafruit_qtpy_esp32_pico.menu.DebugLevel.info.build.code_debug=3 +adafruit_qtpy_esp32_pico.menu.DebugLevel.debug=Debug +adafruit_qtpy_esp32_pico.menu.DebugLevel.debug.build.code_debug=4 +adafruit_qtpy_esp32_pico.menu.DebugLevel.verbose=Verbose +adafruit_qtpy_esp32_pico.menu.DebugLevel.verbose.build.code_debug=5 + + + +adafruit_feather_esp32_v2.name=Adafruit Feather ESP32 V2 + +adafruit_feather_esp32_v2.bootloader.tool=esptool_py +adafruit_feather_esp32_v2.bootloader.tool.default=esptool_py + +adafruit_feather_esp32_v2.upload.tool=esptool_py +adafruit_feather_esp32_v2.upload.tool.default=esptool_py +adafruit_feather_esp32_v2.upload.tool.network=esp_ota + +adafruit_feather_esp32_v2.upload.maximum_size=1310720 +adafruit_feather_esp32_v2.upload.maximum_data_size=327680 +adafruit_feather_esp32_v2.upload.flags= +adafruit_feather_esp32_v2.upload.extra_flags= + +adafruit_feather_esp32_v2.serial.disableDTR=true +adafruit_feather_esp32_v2.serial.disableRTS=true + +adafruit_feather_esp32_v2.build.tarch=xtensa +adafruit_feather_esp32_v2.build.bootloader_addr=0x1000 +adafruit_feather_esp32_v2.build.target=esp32 +adafruit_feather_esp32_v2.build.mcu=esp32 +adafruit_feather_esp32_v2.build.core=esp32 +adafruit_feather_esp32_v2.build.variant=adafruit_feather_esp32_v2 +adafruit_feather_esp32_v2.build.board=ADAFRUIT_FEATHER_ESP32_V2 + +adafruit_feather_esp32_v2.build.f_cpu=240000000L +adafruit_feather_esp32_v2.build.flash_size=8MB +adafruit_feather_esp32_v2.build.flash_freq=80m +adafruit_feather_esp32_v2.build.flash_mode=dio +adafruit_feather_esp32_v2.build.boot=dio +adafruit_feather_esp32_v2.build.partitions=default +adafruit_feather_esp32_v2.build.defines= + +adafruit_feather_esp32_v2.menu.PartitionScheme.default=Default +adafruit_feather_esp32_v2.menu.PartitionScheme.default.build.partitions=default +adafruit_feather_esp32_v2.menu.PartitionScheme.no_ota=No OTA (Large APP) +adafruit_feather_esp32_v2.menu.PartitionScheme.no_ota.build.partitions=no_ota +adafruit_feather_esp32_v2.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +adafruit_feather_esp32_v2.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (Large APPS with OTA) +adafruit_feather_esp32_v2.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +adafruit_feather_esp32_v2.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 + +adafruit_feather_esp32_v2.menu.UploadSpeed.921600=921600 +adafruit_feather_esp32_v2.menu.UploadSpeed.921600.upload.speed=921600 +adafruit_feather_esp32_v2.menu.UploadSpeed.115200=115200 +adafruit_feather_esp32_v2.menu.UploadSpeed.115200.upload.speed=115200 +adafruit_feather_esp32_v2.menu.UploadSpeed.256000.windows=256000 +adafruit_feather_esp32_v2.menu.UploadSpeed.256000.upload.speed=256000 +adafruit_feather_esp32_v2.menu.UploadSpeed.230400.windows.upload.speed=256000 +adafruit_feather_esp32_v2.menu.UploadSpeed.230400=230400 +adafruit_feather_esp32_v2.menu.UploadSpeed.230400.upload.speed=230400 +adafruit_feather_esp32_v2.menu.UploadSpeed.460800.linux=460800 +adafruit_feather_esp32_v2.menu.UploadSpeed.460800.macosx=460800 +adafruit_feather_esp32_v2.menu.UploadSpeed.460800.upload.speed=460800 +adafruit_feather_esp32_v2.menu.UploadSpeed.512000.windows=512000 +adafruit_feather_esp32_v2.menu.UploadSpeed.512000.upload.speed=512000 + +adafruit_feather_esp32_v2.menu.PSRAM.enabled=Enabled +adafruit_feather_esp32_v2.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue -mfix-esp32-psram-cache-strategy=memw +adafruit_feather_esp32_v2.menu.PSRAM.enabled.build.extra_libs= +adafruit_feather_esp32_v2.menu.PSRAM.disabled=Disabled +adafruit_feather_esp32_v2.menu.PSRAM.disabled.build.defines= +adafruit_feather_esp32_v2.menu.PSRAM.disabled.build.extra_libs= + +adafruit_feather_esp32_v2.menu.DebugLevel.none=None +adafruit_feather_esp32_v2.menu.DebugLevel.none.build.code_debug=0 +adafruit_feather_esp32_v2.menu.DebugLevel.error=Error +adafruit_feather_esp32_v2.menu.DebugLevel.error.build.code_debug=1 +adafruit_feather_esp32_v2.menu.DebugLevel.warn=Warn +adafruit_feather_esp32_v2.menu.DebugLevel.warn.build.code_debug=2 +adafruit_feather_esp32_v2.menu.DebugLevel.info=Info +adafruit_feather_esp32_v2.menu.DebugLevel.info.build.code_debug=3 +adafruit_feather_esp32_v2.menu.DebugLevel.debug=Debug +adafruit_feather_esp32_v2.menu.DebugLevel.debug.build.code_debug=4 +adafruit_feather_esp32_v2.menu.DebugLevel.verbose=Verbose +adafruit_feather_esp32_v2.menu.DebugLevel.verbose.build.code_debug=5 + + +############################################################## + +adafruit_feather_esp32s3.name=Adafruit Feather ESP32-S3 No PSRAM +adafruit_feather_esp32s3.vid.0=0x239A +adafruit_feather_esp32s3.pid.0=0x8113 +adafruit_feather_esp32s3.vid.1=0x239A +adafruit_feather_esp32s3.pid.1=0x0113 +adafruit_feather_esp32s3.vid.1=0x239A +adafruit_feather_esp32s3.pid.1=0x8114 + +adafruit_feather_esp32s3.bootloader.tool=esptool_py +adafruit_feather_esp32s3.bootloader.tool.default=esptool_py + +adafruit_feather_esp32s3.upload.tool=esptool_py +adafruit_feather_esp32s3.upload.tool.default=esptool_py +adafruit_feather_esp32s3.upload.tool.network=esp_ota + +adafruit_feather_esp32s3.upload.maximum_size=1310720 +adafruit_feather_esp32s3.upload.maximum_data_size=327680 +adafruit_feather_esp32s3.upload.flags= +adafruit_feather_esp32s3.upload.extra_flags=0x410000 "{runtime.platform.path}/variants/{build.variant}/tinyuf2.bin" +adafruit_feather_esp32s3.upload.use_1200bps_touch=true +adafruit_feather_esp32s3.upload.wait_for_upload_port=true + +adafruit_feather_esp32s3.serial.disableDTR=false +adafruit_feather_esp32s3.serial.disableRTS=false + +adafruit_feather_esp32s3.build.tarch=xtensa +adafruit_feather_esp32s3.build.bootloader_addr=0x0 +adafruit_feather_esp32s3.build.target=esp32s3 +adafruit_feather_esp32s3.build.mcu=esp32s3 +adafruit_feather_esp32s3.build.core=esp32 +adafruit_feather_esp32s3.build.variant=adafruit_feather_esp32s3_nopsram +adafruit_feather_esp32s3.build.board=ADAFRUIT_FEATHER_ESP32S3_NOPSRAM + +adafruit_feather_esp32s3.build.usb_mode=1 +adafruit_feather_esp32s3.build.cdc_on_boot=1 +adafruit_feather_esp32s3.build.msc_on_boot=0 +adafruit_feather_esp32s3.build.dfu_on_boot=0 +adafruit_feather_esp32s3.build.f_cpu=240000000L +adafruit_feather_esp32s3.build.flash_size=8MB +adafruit_feather_esp32s3.build.flash_freq=80m +adafruit_feather_esp32s3.build.flash_mode=dio +adafruit_feather_esp32s3.build.boot=qio +adafruit_feather_esp32s3.build.partitions=default +adafruit_feather_esp32s3.build.defines= +adafruit_feather_esp32s3.build.loop_core=-DARDUINO_RUNNING_CORE=1 +adafruit_feather_esp32s3.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1 + +adafruit_feather_esp32s3.menu.USBMode.default=USB-OTG +adafruit_feather_esp32s3.menu.USBMode.default.build.usb_mode=0 +adafruit_feather_esp32s3.menu.USBMode.default.upload.use_1200bps_touch=true +adafruit_feather_esp32s3.menu.USBMode.default.upload.wait_for_upload_port=true +adafruit_feather_esp32s3.menu.USBMode.hwcdc=Hardware CDC and JTAG +adafruit_feather_esp32s3.menu.USBMode.hwcdc.build.usb_mode=1 +adafruit_feather_esp32s3.menu.USBMode.hwcdc.upload.use_1200bps_touch=false +adafruit_feather_esp32s3.menu.USBMode.hwcdc.upload.wait_for_upload_port=false + +adafruit_feather_esp32s3.menu.CDCOnBoot.cdc=Enabled +adafruit_feather_esp32s3.menu.CDCOnBoot.cdc.build.cdc_on_boot=1 +adafruit_feather_esp32s3.menu.CDCOnBoot.default=Disabled +adafruit_feather_esp32s3.menu.CDCOnBoot.default.build.cdc_on_boot=0 + +adafruit_feather_esp32s3.menu.MSCOnBoot.default=Disabled +adafruit_feather_esp32s3.menu.MSCOnBoot.default.build.msc_on_boot=0 +adafruit_feather_esp32s3.menu.MSCOnBoot.msc=Enabled +adafruit_feather_esp32s3.menu.MSCOnBoot.msc.build.msc_on_boot=1 + +adafruit_feather_esp32s3.menu.DFUOnBoot.default=Disabled +adafruit_feather_esp32s3.menu.DFUOnBoot.default.build.dfu_on_boot=0 +adafruit_feather_esp32s3.menu.DFUOnBoot.dfu=Enabled +adafruit_feather_esp32s3.menu.DFUOnBoot.dfu.build.dfu_on_boot=1 + +adafruit_feather_esp32s3.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +adafruit_feather_esp32s3.menu.PartitionScheme.default.build.partitions=default +adafruit_feather_esp32s3.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +adafruit_feather_esp32s3.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +adafruit_feather_esp32s3.menu.PartitionScheme.default_8MB=8M Flash (3MB APP/1.5MB FAT) +adafruit_feather_esp32s3.menu.PartitionScheme.default_8MB.build.partitions=default_8MB +adafruit_feather_esp32s3.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 +adafruit_feather_esp32s3.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS) +adafruit_feather_esp32s3.menu.PartitionScheme.minimal.build.partitions=minimal +adafruit_feather_esp32s3.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +adafruit_feather_esp32s3.menu.PartitionScheme.no_ota.build.partitions=no_ota +adafruit_feather_esp32s3.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +adafruit_feather_esp32s3.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +adafruit_feather_esp32s3.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +adafruit_feather_esp32s3.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +adafruit_feather_esp32s3.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +adafruit_feather_esp32s3.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +adafruit_feather_esp32s3.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +adafruit_feather_esp32s3.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +adafruit_feather_esp32s3.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +adafruit_feather_esp32s3.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +adafruit_feather_esp32s3.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +adafruit_feather_esp32s3.menu.PartitionScheme.huge_app.build.partitions=huge_app +adafruit_feather_esp32s3.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 +adafruit_feather_esp32s3.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS) +adafruit_feather_esp32s3.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +adafruit_feather_esp32s3.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 +adafruit_feather_esp32s3.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FAT) +adafruit_feather_esp32s3.menu.PartitionScheme.fatflash.build.partitions=ffat +adafruit_feather_esp32s3.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 +adafruit_feather_esp32s3.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9MB FATFS) +adafruit_feather_esp32s3.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB +adafruit_feather_esp32s3.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 + +adafruit_feather_esp32s3.menu.CPUFreq.240=240MHz (WiFi) +adafruit_feather_esp32s3.menu.CPUFreq.240.build.f_cpu=240000000L +adafruit_feather_esp32s3.menu.CPUFreq.160=160MHz (WiFi) +adafruit_feather_esp32s3.menu.CPUFreq.160.build.f_cpu=160000000L +adafruit_feather_esp32s3.menu.CPUFreq.80=80MHz (WiFi) +adafruit_feather_esp32s3.menu.CPUFreq.80.build.f_cpu=80000000L +adafruit_feather_esp32s3.menu.CPUFreq.40=40MHz +adafruit_feather_esp32s3.menu.CPUFreq.40.build.f_cpu=40000000L +adafruit_feather_esp32s3.menu.CPUFreq.20=20MHz +adafruit_feather_esp32s3.menu.CPUFreq.20.build.f_cpu=20000000L +adafruit_feather_esp32s3.menu.CPUFreq.10=10MHz +adafruit_feather_esp32s3.menu.CPUFreq.10.build.f_cpu=10000000L + +adafruit_feather_esp32s3.menu.FlashFreq.80=80MHz +adafruit_feather_esp32s3.menu.FlashFreq.80.build.flash_freq=80m +adafruit_feather_esp32s3.menu.FlashFreq.40=40MHz +adafruit_feather_esp32s3.menu.FlashFreq.40.build.flash_freq=40m + +adafruit_feather_esp32s3.menu.UploadSpeed.921600=921600 +adafruit_feather_esp32s3.menu.UploadSpeed.921600.upload.speed=921600 +adafruit_feather_esp32s3.menu.UploadSpeed.115200=115200 +adafruit_feather_esp32s3.menu.UploadSpeed.115200.upload.speed=115200 +adafruit_feather_esp32s3.menu.UploadSpeed.256000.windows=256000 +adafruit_feather_esp32s3.menu.UploadSpeed.256000.upload.speed=256000 +adafruit_feather_esp32s3.menu.UploadSpeed.230400.windows.upload.speed=256000 +adafruit_feather_esp32s3.menu.UploadSpeed.230400=230400 +adafruit_feather_esp32s3.menu.UploadSpeed.230400.upload.speed=230400 +adafruit_feather_esp32s3.menu.UploadSpeed.460800.linux=460800 +adafruit_feather_esp32s3.menu.UploadSpeed.460800.macosx=460800 +adafruit_feather_esp32s3.menu.UploadSpeed.460800.upload.speed=460800 +adafruit_feather_esp32s3.menu.UploadSpeed.512000.windows=512000 +adafruit_feather_esp32s3.menu.UploadSpeed.512000.upload.speed=512000 + +adafruit_feather_esp32s3.menu.DebugLevel.none=None +adafruit_feather_esp32s3.menu.DebugLevel.none.build.code_debug=0 +adafruit_feather_esp32s3.menu.DebugLevel.error=Error +adafruit_feather_esp32s3.menu.DebugLevel.error.build.code_debug=1 +adafruit_feather_esp32s3.menu.DebugLevel.warn=Warn +adafruit_feather_esp32s3.menu.DebugLevel.warn.build.code_debug=2 +adafruit_feather_esp32s3.menu.DebugLevel.info=Info +adafruit_feather_esp32s3.menu.DebugLevel.info.build.code_debug=3 +adafruit_feather_esp32s3.menu.DebugLevel.debug=Debug +adafruit_feather_esp32s3.menu.DebugLevel.debug.build.code_debug=4 +adafruit_feather_esp32s3.menu.DebugLevel.verbose=Verbose +adafruit_feather_esp32s3.menu.DebugLevel.verbose.build.code_debug=5 + + +############################################################## + +adafruit_qtpy_esp32s3.name=Adafruit QT Py ESP32-S3 No PSRAM +adafruit_qtpy_esp32s3.vid.0=0x239A +adafruit_qtpy_esp32s3.pid.0=0x8119 +adafruit_qtpy_esp32s3.vid.1=0x239A +adafruit_qtpy_esp32s3.pid.1=0x0119 +adafruit_qtpy_esp32s3.vid.1=0x239A +adafruit_qtpy_esp32s3.pid.1=0x811A + +adafruit_qtpy_esp32s3.bootloader.tool=esptool_py +adafruit_qtpy_esp32s3.bootloader.tool.default=esptool_py + +adafruit_qtpy_esp32s3.upload.tool=esptool_py +adafruit_qtpy_esp32s3.upload.tool.default=esptool_py +adafruit_qtpy_esp32s3.upload.tool.network=esp_ota + +adafruit_qtpy_esp32s3.upload.maximum_size=1310720 +adafruit_qtpy_esp32s3.upload.maximum_data_size=327680 +adafruit_qtpy_esp32s3.upload.flags= +adafruit_qtpy_esp32s3.upload.extra_flags=0x410000 "{runtime.platform.path}/variants/{build.variant}/tinyuf2.bin" +adafruit_qtpy_esp32s3.upload.use_1200bps_touch=true +adafruit_qtpy_esp32s3.upload.wait_for_upload_port=true +adafruit_qtpy_esp32s3.upload.speed=921600 + +adafruit_qtpy_esp32s3.serial.disableDTR=false +adafruit_qtpy_esp32s3.serial.disableRTS=false + +adafruit_qtpy_esp32s3.build.tarch=xtensa +adafruit_qtpy_esp32s3.build.bootloader_addr=0x0 +adafruit_qtpy_esp32s3.build.target=esp32s3 +adafruit_qtpy_esp32s3.build.mcu=esp32s3 +adafruit_qtpy_esp32s3.build.core=esp32 +adafruit_qtpy_esp32s3.build.variant=adafruit_qtpy_esp32s3_nopsram +adafruit_qtpy_esp32s3.build.board=ADAFRUIT_QTPY_ESP32S3_NOPSRAM + +adafruit_qtpy_esp32s3.build.usb_mode=1 +adafruit_qtpy_esp32s3.build.cdc_on_boot=1 +adafruit_qtpy_esp32s3.build.msc_on_boot=0 +adafruit_qtpy_esp32s3.build.dfu_on_boot=0 +adafruit_qtpy_esp32s3.build.f_cpu=240000000L +adafruit_qtpy_esp32s3.build.flash_size=8MB +adafruit_qtpy_esp32s3.build.flash_freq=80m +adafruit_qtpy_esp32s3.build.flash_mode=dio +adafruit_qtpy_esp32s3.build.boot=qio +adafruit_qtpy_esp32s3.build.partitions=default_8MB +adafruit_qtpy_esp32s3.build.defines= +adafruit_qtpy_esp32s3.build.loop_core=-DARDUINO_RUNNING_CORE=1 +adafruit_qtpy_esp32s3.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1 + +adafruit_qtpy_esp32s3.menu.USBMode.default=USB-OTG +adafruit_qtpy_esp32s3.menu.USBMode.default.build.usb_mode=0 +adafruit_qtpy_esp32s3.menu.USBMode.default.upload.use_1200bps_touch=true +adafruit_qtpy_esp32s3.menu.USBMode.default.upload.wait_for_upload_port=true +adafruit_qtpy_esp32s3.menu.USBMode.hwcdc=Hardware CDC and JTAG +adafruit_qtpy_esp32s3.menu.USBMode.hwcdc.build.usb_mode=1 +adafruit_qtpy_esp32s3.menu.USBMode.hwcdc.upload.use_1200bps_touch=false +adafruit_qtpy_esp32s3.menu.USBMode.hwcdc.upload.wait_for_upload_port=false + +adafruit_qtpy_esp32s3.menu.CDCOnBoot.cdc=Enabled +adafruit_qtpy_esp32s3.menu.CDCOnBoot.cdc.build.cdc_on_boot=1 +adafruit_qtpy_esp32s3.menu.CDCOnBoot.default=Disabled +adafruit_qtpy_esp32s3.menu.CDCOnBoot.default.build.cdc_on_boot=0 + +adafruit_qtpy_esp32s3.menu.MSCOnBoot.default=Disabled +adafruit_qtpy_esp32s3.menu.MSCOnBoot.default.build.msc_on_boot=0 +adafruit_qtpy_esp32s3.menu.MSCOnBoot.msc=Enabled +adafruit_qtpy_esp32s3.menu.MSCOnBoot.msc.build.msc_on_boot=1 + +adafruit_qtpy_esp32s3.menu.DFUOnBoot.default=Disabled +adafruit_qtpy_esp32s3.menu.DFUOnBoot.default.build.dfu_on_boot=0 +adafruit_qtpy_esp32s3.menu.DFUOnBoot.dfu=Enabled +adafruit_qtpy_esp32s3.menu.DFUOnBoot.dfu.build.dfu_on_boot=1 + +adafruit_qtpy_esp32s3.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +adafruit_qtpy_esp32s3.menu.PartitionScheme.default.build.partitions=default +adafruit_qtpy_esp32s3.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +adafruit_qtpy_esp32s3.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +adafruit_qtpy_esp32s3.menu.PartitionScheme.default_8MB=8M Flash (3MB APP/1.5MB FAT) +adafruit_qtpy_esp32s3.menu.PartitionScheme.default_8MB.build.partitions=default_8MB +adafruit_qtpy_esp32s3.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 +adafruit_qtpy_esp32s3.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS) +adafruit_qtpy_esp32s3.menu.PartitionScheme.minimal.build.partitions=minimal +adafruit_qtpy_esp32s3.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +adafruit_qtpy_esp32s3.menu.PartitionScheme.no_ota.build.partitions=no_ota +adafruit_qtpy_esp32s3.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +adafruit_qtpy_esp32s3.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +adafruit_qtpy_esp32s3.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +adafruit_qtpy_esp32s3.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +adafruit_qtpy_esp32s3.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +adafruit_qtpy_esp32s3.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +adafruit_qtpy_esp32s3.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +adafruit_qtpy_esp32s3.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +adafruit_qtpy_esp32s3.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +adafruit_qtpy_esp32s3.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +adafruit_qtpy_esp32s3.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +adafruit_qtpy_esp32s3.menu.PartitionScheme.huge_app.build.partitions=huge_app +adafruit_qtpy_esp32s3.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 +adafruit_qtpy_esp32s3.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS) +adafruit_qtpy_esp32s3.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +adafruit_qtpy_esp32s3.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 +adafruit_qtpy_esp32s3.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FAT) +adafruit_qtpy_esp32s3.menu.PartitionScheme.fatflash.build.partitions=ffat +adafruit_qtpy_esp32s3.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 +adafruit_qtpy_esp32s3.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9MB FATFS) +adafruit_qtpy_esp32s3.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB +adafruit_qtpy_esp32s3.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 + +adafruit_qtpy_esp32s3.menu.CPUFreq.240=240MHz (WiFi) +adafruit_qtpy_esp32s3.menu.CPUFreq.240.build.f_cpu=240000000L +adafruit_qtpy_esp32s3.menu.CPUFreq.160=160MHz (WiFi) +adafruit_qtpy_esp32s3.menu.CPUFreq.160.build.f_cpu=160000000L +adafruit_qtpy_esp32s3.menu.CPUFreq.80=80MHz (WiFi) +adafruit_qtpy_esp32s3.menu.CPUFreq.80.build.f_cpu=80000000L +adafruit_qtpy_esp32s3.menu.CPUFreq.40=40MHz +adafruit_qtpy_esp32s3.menu.CPUFreq.40.build.f_cpu=40000000L +adafruit_qtpy_esp32s3.menu.CPUFreq.20=20MHz +adafruit_qtpy_esp32s3.menu.CPUFreq.20.build.f_cpu=20000000L +adafruit_qtpy_esp32s3.menu.CPUFreq.10=10MHz +adafruit_qtpy_esp32s3.menu.CPUFreq.10.build.f_cpu=10000000L + +adafruit_qtpy_esp32s3.menu.FlashFreq.80=80MHz +adafruit_qtpy_esp32s3.menu.FlashFreq.80.build.flash_freq=80m +adafruit_qtpy_esp32s3.menu.FlashFreq.40=40MHz +adafruit_qtpy_esp32s3.menu.FlashFreq.40.build.flash_freq=40m + +adafruit_qtpy_esp32s3.menu.DebugLevel.none=None +adafruit_qtpy_esp32s3.menu.DebugLevel.none.build.code_debug=0 +adafruit_qtpy_esp32s3.menu.DebugLevel.error=Error +adafruit_qtpy_esp32s3.menu.DebugLevel.error.build.code_debug=1 +adafruit_qtpy_esp32s3.menu.DebugLevel.warn=Warn +adafruit_qtpy_esp32s3.menu.DebugLevel.warn.build.code_debug=2 +adafruit_qtpy_esp32s3.menu.DebugLevel.info=Info +adafruit_qtpy_esp32s3.menu.DebugLevel.info.build.code_debug=3 +adafruit_qtpy_esp32s3.menu.DebugLevel.debug=Debug +adafruit_qtpy_esp32s3.menu.DebugLevel.debug.build.code_debug=4 +adafruit_qtpy_esp32s3.menu.DebugLevel.verbose=Verbose +adafruit_qtpy_esp32s3.menu.DebugLevel.verbose.build.code_debug=5 + + + ############################################################## nodemcu-32s.name=NodeMCU-32S +nodemcu-32s.bootloader.tool=esptool_py +nodemcu-32s.bootloader.tool.default=esptool_py + nodemcu-32s.upload.tool=esptool_py +nodemcu-32s.upload.tool.default=esptool_py +nodemcu-32s.upload.tool.network=esp_ota + nodemcu-32s.upload.maximum_size=1310720 nodemcu-32s.upload.maximum_data_size=327680 nodemcu-32s.upload.flags= @@ -4934,11 +7663,30 @@ nodemcu-32s.menu.UploadSpeed.460800.upload.speed=460800 nodemcu-32s.menu.UploadSpeed.512000.windows=512000 nodemcu-32s.menu.UploadSpeed.512000.upload.speed=512000 +nodemcu-32s.menu.DebugLevel.none=None +nodemcu-32s.menu.DebugLevel.none.build.code_debug=0 +nodemcu-32s.menu.DebugLevel.error=Error +nodemcu-32s.menu.DebugLevel.error.build.code_debug=1 +nodemcu-32s.menu.DebugLevel.warn=Warn +nodemcu-32s.menu.DebugLevel.warn.build.code_debug=2 +nodemcu-32s.menu.DebugLevel.info=Info +nodemcu-32s.menu.DebugLevel.info.build.code_debug=3 +nodemcu-32s.menu.DebugLevel.debug=Debug +nodemcu-32s.menu.DebugLevel.debug.build.code_debug=4 +nodemcu-32s.menu.DebugLevel.verbose=Verbose +nodemcu-32s.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## mhetesp32devkit.name=MH ET LIVE ESP32DevKIT +mhetesp32devkit.bootloader.tool=esptool_py +mhetesp32devkit.bootloader.tool.default=esptool_py + mhetesp32devkit.upload.tool=esptool_py +mhetesp32devkit.upload.tool.default=esptool_py +mhetesp32devkit.upload.tool.network=esp_ota + mhetesp32devkit.upload.maximum_size=1310720 mhetesp32devkit.upload.maximum_data_size=327680 mhetesp32devkit.upload.flags= @@ -5008,7 +7756,13 @@ mhetesp32devkit.menu.DebugLevel.verbose.build.code_debug=5 mhetesp32minikit.name=MH ET LIVE ESP32MiniKit +mhetesp32minikit.bootloader.tool=esptool_py +mhetesp32minikit.bootloader.tool.default=esptool_py + mhetesp32minikit.upload.tool=esptool_py +mhetesp32minikit.upload.tool.default=esptool_py +mhetesp32minikit.upload.tool.network=esp_ota + mhetesp32minikit.upload.maximum_size=1310720 mhetesp32minikit.upload.maximum_data_size=327680 mhetesp32minikit.upload.flags= @@ -5076,11 +7830,17 @@ mhetesp32minikit.menu.DebugLevel.debug.build.code_debug=4 mhetesp32minikit.menu.DebugLevel.verbose=Verbose mhetesp32minikit.menu.DebugLevel.verbose.build.code_debug=5 -################################################################# +############################################################## esp32vn-iot-uno.name=ESP32vn IoT Uno +esp32vn-iot-uno.bootloader.tool=esptool_py +esp32vn-iot-uno.bootloader.tool.default=esptool_py + esp32vn-iot-uno.upload.tool=esptool_py +esp32vn-iot-uno.upload.tool.default=esptool_py +esp32vn-iot-uno.upload.tool.network=esp_ota + esp32vn-iot-uno.upload.maximum_size=1310720 esp32vn-iot-uno.upload.maximum_data_size=327680 esp32vn-iot-uno.upload.flags= @@ -5124,11 +7884,30 @@ esp32vn-iot-uno.menu.UploadSpeed.460800.upload.speed=460800 esp32vn-iot-uno.menu.UploadSpeed.512000.windows=512000 esp32vn-iot-uno.menu.UploadSpeed.512000.upload.speed=512000 +esp32vn-iot-uno.menu.DebugLevel.none=None +esp32vn-iot-uno.menu.DebugLevel.none.build.code_debug=0 +esp32vn-iot-uno.menu.DebugLevel.error=Error +esp32vn-iot-uno.menu.DebugLevel.error.build.code_debug=1 +esp32vn-iot-uno.menu.DebugLevel.warn=Warn +esp32vn-iot-uno.menu.DebugLevel.warn.build.code_debug=2 +esp32vn-iot-uno.menu.DebugLevel.info=Info +esp32vn-iot-uno.menu.DebugLevel.info.build.code_debug=3 +esp32vn-iot-uno.menu.DebugLevel.debug=Debug +esp32vn-iot-uno.menu.DebugLevel.debug.build.code_debug=4 +esp32vn-iot-uno.menu.DebugLevel.verbose=Verbose +esp32vn-iot-uno.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## esp32doit-devkit-v1.name=DOIT ESP32 DEVKIT V1 +esp32doit-devkit-v1.bootloader.tool=esptool_py +esp32doit-devkit-v1.bootloader.tool.default=esptool_py + esp32doit-devkit-v1.upload.tool=esptool_py +esp32doit-devkit-v1.upload.tool.default=esptool_py +esp32doit-devkit-v1.upload.tool.network=esp_ota + esp32doit-devkit-v1.upload.maximum_size=1310720 esp32doit-devkit-v1.upload.maximum_data_size=327680 esp32doit-devkit-v1.upload.flags= @@ -5187,7 +7966,7 @@ esp32doit-devkit-v1.menu.DebugLevel.debug.build.code_debug=4 esp32doit-espduino.name=DOIT ESPduino32 -esp32doit-espduino.upload.tool=esptool +esp32doit-espduino.upload.tool=esptool_py esp32doit-espduino.upload.maximum_size=1310720 esp32doit-espduino.upload.maximum_data_size=327680 esp32doit-espduino.upload.wait_for_upload_port=true @@ -5247,7 +8026,13 @@ esp32doit-espduino.menu.DebugLevel.debug.build.code_debug=4 esp32-evb.name=OLIMEX ESP32-EVB +esp32-evb.bootloader.tool=esptool_py +esp32-evb.bootloader.tool.default=esptool_py + esp32-evb.upload.tool=esptool_py +esp32-evb.upload.tool.default=esptool_py +esp32-evb.upload.tool.network=esp_ota + esp32-evb.upload.maximum_size=1310720 esp32-evb.upload.maximum_data_size=327680 esp32-evb.upload.flags= @@ -5276,7 +8061,6 @@ esp32-evb.menu.FlashFreq.80.build.flash_freq=80m esp32-evb.menu.FlashFreq.40=40MHz esp32-evb.menu.FlashFreq.40.build.flash_freq=40m - esp32-evb.menu.UploadSpeed.115200=115200 esp32-evb.menu.UploadSpeed.115200.upload.speed=115200 @@ -5289,11 +8073,30 @@ esp32-evb.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (Large APPS with OTA) esp32-evb.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs esp32-evb.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 +esp32-evb.menu.DebugLevel.none=None +esp32-evb.menu.DebugLevel.none.build.code_debug=0 +esp32-evb.menu.DebugLevel.error=Error +esp32-evb.menu.DebugLevel.error.build.code_debug=1 +esp32-evb.menu.DebugLevel.warn=Warn +esp32-evb.menu.DebugLevel.warn.build.code_debug=2 +esp32-evb.menu.DebugLevel.info=Info +esp32-evb.menu.DebugLevel.info.build.code_debug=3 +esp32-evb.menu.DebugLevel.debug=Debug +esp32-evb.menu.DebugLevel.debug.build.code_debug=4 +esp32-evb.menu.DebugLevel.verbose=Verbose +esp32-evb.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## esp32-gateway.name=OLIMEX ESP32-GATEWAY +esp32-gateway.bootloader.tool=esptool_py +esp32-gateway.bootloader.tool.default=esptool_py + esp32-gateway.upload.tool=esptool_py +esp32-gateway.upload.tool.default=esptool_py +esp32-gateway.upload.tool.network=esp_ota + esp32-gateway.upload.maximum_size=1310720 esp32-gateway.upload.maximum_data_size=327680 esp32-gateway.upload.flags= @@ -5328,7 +8131,6 @@ esp32-gateway.menu.FlashFreq.80.build.flash_freq=80m esp32-gateway.menu.FlashFreq.40=40MHz esp32-gateway.menu.FlashFreq.40.build.flash_freq=40m - esp32-gateway.menu.UploadSpeed.115200=115200 esp32-gateway.menu.UploadSpeed.115200.upload.speed=115200 @@ -5341,11 +8143,30 @@ esp32-gateway.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (Large APPS with OT esp32-gateway.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs esp32-gateway.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 +esp32-gateway.menu.DebugLevel.none=None +esp32-gateway.menu.DebugLevel.none.build.code_debug=0 +esp32-gateway.menu.DebugLevel.error=Error +esp32-gateway.menu.DebugLevel.error.build.code_debug=1 +esp32-gateway.menu.DebugLevel.warn=Warn +esp32-gateway.menu.DebugLevel.warn.build.code_debug=2 +esp32-gateway.menu.DebugLevel.info=Info +esp32-gateway.menu.DebugLevel.info.build.code_debug=3 +esp32-gateway.menu.DebugLevel.debug=Debug +esp32-gateway.menu.DebugLevel.debug.build.code_debug=4 +esp32-gateway.menu.DebugLevel.verbose=Verbose +esp32-gateway.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## esp32-poe.name=OLIMEX ESP32-PoE +esp32-poe.bootloader.tool=esptool_py +esp32-poe.bootloader.tool.default=esptool_py + esp32-poe.upload.tool=esptool_py +esp32-poe.upload.tool.default=esptool_py +esp32-poe.upload.tool.network=esp_ota + esp32-poe.upload.maximum_size=1310720 esp32-poe.upload.maximum_data_size=327680 esp32-poe.upload.flags= @@ -5374,7 +8195,6 @@ esp32-poe.menu.FlashFreq.80.build.flash_freq=80m esp32-poe.menu.FlashFreq.40=40MHz esp32-poe.menu.FlashFreq.40.build.flash_freq=40m - esp32-poe.menu.UploadSpeed.115200=115200 esp32-poe.menu.UploadSpeed.115200.upload.speed=115200 @@ -5387,11 +8207,30 @@ esp32-poe.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (Large APPS with OTA) esp32-poe.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs esp32-poe.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 +esp32-poe.menu.DebugLevel.none=None +esp32-poe.menu.DebugLevel.none.build.code_debug=0 +esp32-poe.menu.DebugLevel.error=Error +esp32-poe.menu.DebugLevel.error.build.code_debug=1 +esp32-poe.menu.DebugLevel.warn=Warn +esp32-poe.menu.DebugLevel.warn.build.code_debug=2 +esp32-poe.menu.DebugLevel.info=Info +esp32-poe.menu.DebugLevel.info.build.code_debug=3 +esp32-poe.menu.DebugLevel.debug=Debug +esp32-poe.menu.DebugLevel.debug.build.code_debug=4 +esp32-poe.menu.DebugLevel.verbose=Verbose +esp32-poe.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## esp32-poe-iso.name=OLIMEX ESP32-PoE-ISO +esp32-poe-iso.bootloader.tool=esptool_py +esp32-poe-iso.bootloader.tool.default=esptool_py + esp32-poe-iso.upload.tool=esptool_py +esp32-poe-iso.upload.tool.default=esptool_py +esp32-poe-iso.upload.tool.network=esp_ota + esp32-poe-iso.upload.maximum_size=1310720 esp32-poe-iso.upload.maximum_data_size=327680 esp32-poe-iso.upload.flags= @@ -5420,7 +8259,6 @@ esp32-poe-iso.menu.FlashFreq.80.build.flash_freq=80m esp32-poe-iso.menu.FlashFreq.40=40MHz esp32-poe-iso.menu.FlashFreq.40.build.flash_freq=40m - esp32-poe-iso.menu.UploadSpeed.115200=115200 esp32-poe-iso.menu.UploadSpeed.115200.upload.speed=115200 @@ -5433,11 +8271,30 @@ esp32-poe-iso.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (Large APPS with OT esp32-poe-iso.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs esp32-poe-iso.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 +esp32-poe-iso.menu.DebugLevel.none=None +esp32-poe-iso.menu.DebugLevel.none.build.code_debug=0 +esp32-poe-iso.menu.DebugLevel.error=Error +esp32-poe-iso.menu.DebugLevel.error.build.code_debug=1 +esp32-poe-iso.menu.DebugLevel.warn=Warn +esp32-poe-iso.menu.DebugLevel.warn.build.code_debug=2 +esp32-poe-iso.menu.DebugLevel.info=Info +esp32-poe-iso.menu.DebugLevel.info.build.code_debug=3 +esp32-poe-iso.menu.DebugLevel.debug=Debug +esp32-poe-iso.menu.DebugLevel.debug.build.code_debug=4 +esp32-poe-iso.menu.DebugLevel.verbose=Verbose +esp32-poe-iso.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## esp32-DevKitLipo.name=OLIMEX ESP32-DevKit-LiPo +esp32-DevKitLipo.bootloader.tool=esptool_py +esp32-DevKitLipo.bootloader.tool.default=esptool_py + esp32-DevKitLipo.upload.tool=esptool_py +esp32-DevKitLipo.upload.tool.default=esptool_py +esp32-DevKitLipo.upload.tool.network=esp_ota + esp32-DevKitLipo.upload.maximum_size=1310720 esp32-DevKitLipo.upload.maximum_data_size=327680 esp32-DevKitLipo.upload.flags= @@ -5510,11 +8367,31 @@ esp32-DevKitLipo.menu.UploadSpeed.460800.macosx=460800 esp32-DevKitLipo.menu.UploadSpeed.460800.upload.speed=460800 esp32-DevKitLipo.menu.UploadSpeed.512000.windows=512000 esp32-DevKitLipo.menu.UploadSpeed.512000.upload.speed=512000 + +esp32-DevKitLipo.menu.DebugLevel.none=None +esp32-DevKitLipo.menu.DebugLevel.none.build.code_debug=0 +esp32-DevKitLipo.menu.DebugLevel.error=Error +esp32-DevKitLipo.menu.DebugLevel.error.build.code_debug=1 +esp32-DevKitLipo.menu.DebugLevel.warn=Warn +esp32-DevKitLipo.menu.DebugLevel.warn.build.code_debug=2 +esp32-DevKitLipo.menu.DebugLevel.info=Info +esp32-DevKitLipo.menu.DebugLevel.info.build.code_debug=3 +esp32-DevKitLipo.menu.DebugLevel.debug=Debug +esp32-DevKitLipo.menu.DebugLevel.debug.build.code_debug=4 +esp32-DevKitLipo.menu.DebugLevel.verbose=Verbose +esp32-DevKitLipo.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## espino32.name=ThaiEasyElec's ESPino32 +espino32.bootloader.tool=esptool_py +espino32.bootloader.tool.default=esptool_py + espino32.upload.tool=esptool_py +espino32.upload.tool.default=esptool_py +espino32.upload.tool.network=esp_ota + espino32.upload.maximum_size=1310720 espino32.upload.maximum_data_size=327680 espino32.upload.flags= @@ -5558,11 +8435,30 @@ espino32.menu.UploadSpeed.460800.upload.speed=460800 espino32.menu.UploadSpeed.512000.windows=512000 espino32.menu.UploadSpeed.512000.upload.speed=512000 +espino32.menu.DebugLevel.none=None +espino32.menu.DebugLevel.none.build.code_debug=0 +espino32.menu.DebugLevel.error=Error +espino32.menu.DebugLevel.error.build.code_debug=1 +espino32.menu.DebugLevel.warn=Warn +espino32.menu.DebugLevel.warn.build.code_debug=2 +espino32.menu.DebugLevel.info=Info +espino32.menu.DebugLevel.info.build.code_debug=3 +espino32.menu.DebugLevel.debug=Debug +espino32.menu.DebugLevel.debug.build.code_debug=4 +espino32.menu.DebugLevel.verbose=Verbose +espino32.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## m5stack-core-esp32.name=M5Stack-Core-ESP32 +m5stack-core-esp32.bootloader.tool=esptool_py +m5stack-core-esp32.bootloader.tool.default=esptool_py + m5stack-core-esp32.upload.tool=esptool_py +m5stack-core-esp32.upload.tool.default=esptool_py +m5stack-core-esp32.upload.tool.network=esp_ota + m5stack-core-esp32.upload.maximum_size=1310720 m5stack-core-esp32.upload.maximum_data_size=327680 m5stack-core-esp32.upload.flags= @@ -5645,7 +8541,13 @@ m5stack-core-esp32.menu.DebugLevel.verbose.build.code_debug=5 m5stack-fire.name=M5Stack-FIRE +m5stack-fire.bootloader.tool=esptool_py +m5stack-fire.bootloader.tool.default=esptool_py + m5stack-fire.upload.tool=esptool_py +m5stack-fire.upload.tool.default=esptool_py +m5stack-fire.upload.tool.network=esp_ota + m5stack-fire.upload.maximum_size=6553600 m5stack-fire.upload.maximum_data_size=4521984 m5stack-fire.upload.flags= @@ -5716,7 +8618,13 @@ m5stack-fire.menu.DebugLevel.verbose.build.code_debug=5 m5stick-c.name=M5Stick-C +m5stick-c.bootloader.tool=esptool_py +m5stick-c.bootloader.tool.default=esptool_py + m5stick-c.upload.tool=esptool_py +m5stick-c.upload.tool.default=esptool_py +m5stick-c.upload.tool.network=esp_ota + m5stick-c.upload.maximum_size=1310720 m5stick-c.upload.maximum_data_size=327680 m5stick-c.upload.flags= @@ -5750,7 +8658,6 @@ m5stick-c.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (Large APPS with OTA) m5stick-c.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs m5stick-c.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 - m5stick-c.menu.UploadSpeed.1500000=1500000 m5stick-c.menu.UploadSpeed.1500000.upload.speed=1500000 m5stick-c.menu.UploadSpeed.750000=750000 @@ -5762,8 +8669,6 @@ m5stick-c.menu.UploadSpeed.250000.upload.speed=250000 m5stick-c.menu.UploadSpeed.115200=115200 m5stick-c.menu.UploadSpeed.115200.upload.speed=115200 - - m5stick-c.menu.DebugLevel.none=None m5stick-c.menu.DebugLevel.none.build.code_debug=0 m5stick-c.menu.DebugLevel.error=Error @@ -5781,7 +8686,13 @@ m5stick-c.menu.DebugLevel.verbose.build.code_debug=5 m5stack-atom.name=M5Stack-ATOM +m5stack-atom.bootloader.tool=esptool_py +m5stack-atom.bootloader.tool.default=esptool_py + m5stack-atom.upload.tool=esptool_py +m5stack-atom.upload.tool.default=esptool_py +m5stack-atom.upload.tool.network=esp_ota + m5stack-atom.upload.maximum_size=1310720 m5stack-atom.upload.maximum_data_size=327680 m5stack-atom.upload.flags= @@ -5815,7 +8726,6 @@ m5stack-atom.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (Large APPS with OTA m5stack-atom.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs m5stack-atom.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 - m5stack-atom.menu.UploadSpeed.1500000=1500000 m5stack-atom.menu.UploadSpeed.1500000.upload.speed=1500000 m5stack-atom.menu.UploadSpeed.750000=750000 @@ -5827,8 +8737,6 @@ m5stack-atom.menu.UploadSpeed.250000.upload.speed=250000 m5stack-atom.menu.UploadSpeed.115200=115200 m5stack-atom.menu.UploadSpeed.115200.upload.speed=115200 - - m5stack-atom.menu.DebugLevel.none=None m5stack-atom.menu.DebugLevel.none.build.code_debug=0 m5stack-atom.menu.DebugLevel.error=Error @@ -5842,12 +8750,17 @@ m5stack-atom.menu.DebugLevel.debug.build.code_debug=4 m5stack-atom.menu.DebugLevel.verbose=Verbose m5stack-atom.menu.DebugLevel.verbose.build.code_debug=5 - ############################################################## m5stack-core2.name=M5Stack-Core2 +m5stack-core2.bootloader.tool=esptool_py +m5stack-core2.bootloader.tool.default=esptool_py + m5stack-core2.upload.tool=esptool_py +m5stack-core2.upload.tool.default=esptool_py +m5stack-core2.upload.tool.network=esp_ota + m5stack-core2.upload.maximum_size=6553600 m5stack-core2.upload.maximum_data_size=4521984 m5stack-core2.upload.wait_for_upload_port=true @@ -5953,7 +8866,13 @@ m5stack-core2.menu.DebugLevel.verbose.build.code_debug=5 m5stack-timer-cam.name=M5Stack-Timer-CAM +m5stack-timer-cam.bootloader.tool=esptool_py +m5stack-timer-cam.bootloader.tool.default=esptool_py + m5stack-timer-cam.upload.tool=esptool_py +m5stack-timer-cam.upload.tool.default=esptool_py +m5stack-timer-cam.upload.tool.network=esp_ota + m5stack-timer-cam.upload.maximum_size=1310720 m5stack-timer-cam.upload.maximum_data_size=327680 m5stack-timer-cam.upload.wait_for_upload_port=true @@ -6051,7 +8970,13 @@ m5stack-timer-cam.menu.DebugLevel.verbose.build.code_debug=5 m5stack-coreink.name=M5Stack-CoreInk +m5stack-coreink.bootloader.tool=esptool_py +m5stack-coreink.bootloader.tool.default=esptool_py + m5stack-coreink.upload.tool=esptool_py +m5stack-coreink.upload.tool.default=esptool_py +m5stack-coreink.upload.tool.network=esp_ota + m5stack-coreink.upload.maximum_size=1310720 m5stack-coreink.upload.maximum_data_size=327680 m5stack-coreink.upload.wait_for_upload_port=true @@ -6120,7 +9045,13 @@ m5stack-coreink.menu.DebugLevel.verbose.build.code_debug=5 odroid_esp32.name=ODROID ESP32 +odroid_esp32.bootloader.tool=esptool_py +odroid_esp32.bootloader.tool.default=esptool_py + odroid_esp32.upload.tool=esptool_py +odroid_esp32.upload.tool.default=esptool_py +odroid_esp32.upload.tool.network=esp_ota + odroid_esp32.upload.maximum_size=1310720 odroid_esp32.upload.maximum_data_size=327680 odroid_esp32.upload.flags= @@ -6204,7 +9135,13 @@ odroid_esp32.menu.DebugLevel.verbose.build.code_debug=5 heltec_wifi_kit_32.name=Heltec WiFi Kit 32 +heltec_wifi_kit_32.bootloader.tool=esptool_py +heltec_wifi_kit_32.bootloader.tool.default=esptool_py + heltec_wifi_kit_32.upload.tool=esptool_py +heltec_wifi_kit_32.upload.tool.default=esptool_py +heltec_wifi_kit_32.upload.tool.network=esp_ota + heltec_wifi_kit_32.upload.maximum_size=1310720 heltec_wifi_kit_32.upload.maximum_data_size=327680 heltec_wifi_kit_32.upload.flags= @@ -6277,7 +9214,13 @@ heltec_wifi_kit_32.menu.DebugLevel.verbose.build.code_debug=5 heltec_wifi_lora_32.name=Heltec WiFi LoRa 32 +heltec_wifi_lora_32.bootloader.tool=esptool_py +heltec_wifi_lora_32.bootloader.tool.default=esptool_py + heltec_wifi_lora_32.upload.tool=esptool_py +heltec_wifi_lora_32.upload.tool.default=esptool_py +heltec_wifi_lora_32.upload.tool.network=esp_ota + heltec_wifi_lora_32.upload.maximum_size=1310720 heltec_wifi_lora_32.upload.maximum_data_size=327680 heltec_wifi_lora_32.upload.flags= @@ -6378,7 +9321,13 @@ heltec_wifi_lora_32.menu.LoRaWanDebugLevel.3.build.LoRaWanDebugLevel=3 heltec_wifi_lora_32_V2.name=Heltec WiFi LoRa 32(V2) +heltec_wifi_lora_32_V2.bootloader.tool=esptool_py +heltec_wifi_lora_32_V2.bootloader.tool.default=esptool_py + heltec_wifi_lora_32_V2.upload.tool=esptool_py +heltec_wifi_lora_32_V2.upload.tool.default=esptool_py +heltec_wifi_lora_32_V2.upload.tool.network=esp_ota + heltec_wifi_lora_32_V2.upload.maximum_size=3342336 heltec_wifi_lora_32_V2.upload.maximum_data_size=327680 heltec_wifi_lora_32_V2.upload.flags= @@ -6479,7 +9428,13 @@ heltec_wifi_lora_32_V2.menu.LoRaWanDebugLevel.3.build.LoRaWanDebugLevel=3 heltec_wireless_stick.name=Heltec Wireless Stick +heltec_wireless_stick.bootloader.tool=esptool_py +heltec_wireless_stick.bootloader.tool.default=esptool_py + heltec_wireless_stick.upload.tool=esptool_py +heltec_wireless_stick.upload.tool.default=esptool_py +heltec_wireless_stick.upload.tool.network=esp_ota + heltec_wireless_stick.upload.maximum_size=3342336 heltec_wireless_stick.upload.maximum_data_size=327680 heltec_wireless_stick.upload.flags= @@ -6580,7 +9535,13 @@ heltec_wireless_stick.menu.LoRaWanDebugLevel.3.build.LoRaWanDebugLevel=3 heltec_wireless_stick_lite.name=Heltec Wireless Stick Lite +heltec_wireless_stick_lite.bootloader.tool=esptool_py +heltec_wireless_stick_lite.bootloader.tool.default=esptool_py + heltec_wireless_stick_lite.upload.tool=esptool_py +heltec_wireless_stick_lite.upload.tool.default=esptool_py +heltec_wireless_stick_lite.upload.tool.network=esp_ota + heltec_wireless_stick_lite.upload.maximum_size=1310720 heltec_wireless_stick_lite.upload.maximum_data_size=327680 heltec_wireless_stick_lite.upload.wait_for_upload_port=true @@ -6682,7 +9643,13 @@ heltec_wireless_stick_lite.menu.LoRaWanDebugLevel.3.build.LoRaWanDebugLevel=3 espectro32.name=ESPectro32 +espectro32.bootloader.tool=esptool_py +espectro32.bootloader.tool.default=esptool_py + espectro32.upload.tool=esptool_py +espectro32.upload.tool.default=esptool_py +espectro32.upload.tool.network=esp_ota + espectro32.upload.maximum_size=1310720 espectro32.upload.maximum_data_size=327680 espectro32.upload.flags= @@ -6758,11 +9725,17 @@ espectro32.menu.DebugLevel.debug.build.code_debug=4 espectro32.menu.DebugLevel.verbose=Verbose espectro32.menu.DebugLevel.verbose.build.code_debug=5 - ############################################################## + CoreESP32.name=Microduino-CoreESP32 +CoreESP32.bootloader.tool=esptool_py +CoreESP32.bootloader.tool.default=esptool_py + CoreESP32.upload.tool=esptool_py +CoreESP32.upload.tool.default=esptool_py +CoreESP32.upload.tool.network=esp_ota + CoreESP32.upload.maximum_size=1310720 CoreESP32.upload.maximum_data_size=327680 CoreESP32.upload.flags= @@ -6841,10 +9814,15 @@ CoreESP32.menu.DebugLevel.verbose.build.code_debug=5 ############################################################## - alksesp32.name=ALKS ESP32 +alksesp32.bootloader.tool=esptool_py +alksesp32.bootloader.tool.default=esptool_py + alksesp32.upload.tool=esptool_py +alksesp32.upload.tool.default=esptool_py +alksesp32.upload.tool.network=esp_ota + alksesp32.upload.maximum_size=1310720 alksesp32.upload.maximum_data_size=327680 alksesp32.upload.flags= @@ -6977,10 +9955,15 @@ alksesp32.menu.DebugLevel.verbose.build.code_debug=5 ############################################################## - wipy3.name=WiPy 3.0 +wipy3.bootloader.tool=esptool_py +wipy3.bootloader.tool.default=esptool_py + wipy3.upload.tool=esptool_py +wipy3.upload.tool.default=esptool_py +wipy3.upload.tool.network=esp_ota + wipy3.upload.maximum_size=1310720 wipy3.upload.maximum_data_size=294912 wipy3.upload.flags= @@ -7041,7 +10024,13 @@ wipy3.menu.DebugLevel.verbose.build.code_debug=5 wt32-eth01.name=WT32-ETH01 Ethernet Module +wt32-eth01.bootloader.tool=esptool_py +wt32-eth01.bootloader.tool.default=esptool_py + wt32-eth01.upload.tool=esptool_py +wt32-eth01.upload.tool.default=esptool_py +wt32-eth01.upload.tool.network=esp_ota + wt32-eth01.upload.maximum_size=8388608 wt32-eth01.upload.maximum_data_size=327680 wt32-eth01.upload.flags= @@ -7055,7 +10044,7 @@ wt32-eth01.build.bootloader_addr=0x1000 wt32-eth01.build.target=esp32 wt32-eth01.build.mcu=esp32 wt32-eth01.build.core=esp32 -wt32-eth01.build.variant=wt32-eth0 +wt32-eth01.build.variant=wt32-eth01 wt32-eth01.build.board=WT32_ETH01 wt32-eth01.build.f_cpu=240000000L @@ -7136,7 +10125,13 @@ wt32-eth01.menu.DebugLevel.verbose.build.code_debug=5 bpi-bit.name=BPI-BIT +bpi-bit.bootloader.tool=esptool_py +bpi-bit.bootloader.tool.default=esptool_py + bpi-bit.upload.tool=esptool_py +bpi-bit.upload.tool.default=esptool_py +bpi-bit.upload.tool.network=esp_ota + bpi-bit.upload.maximum_size=1310720 bpi-bit.upload.maximum_data_size=294912 bpi-bit.upload.flags= @@ -7179,11 +10174,30 @@ bpi-bit.menu.UploadSpeed.460800.upload.speed=460800 bpi-bit.menu.UploadSpeed.512000.windows=512000 bpi-bit.menu.UploadSpeed.512000.upload.speed=512000 +bpi-bit.menu.DebugLevel.none=None +bpi-bit.menu.DebugLevel.none.build.code_debug=0 +bpi-bit.menu.DebugLevel.error=Error +bpi-bit.menu.DebugLevel.error.build.code_debug=1 +bpi-bit.menu.DebugLevel.warn=Warn +bpi-bit.menu.DebugLevel.warn.build.code_debug=2 +bpi-bit.menu.DebugLevel.info=Info +bpi-bit.menu.DebugLevel.info.build.code_debug=3 +bpi-bit.menu.DebugLevel.debug=Debug +bpi-bit.menu.DebugLevel.debug.build.code_debug=4 +bpi-bit.menu.DebugLevel.verbose=Verbose +bpi-bit.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## wesp32.name=Silicognition wESP32 +wesp32.bootloader.tool=esptool_py +wesp32.bootloader.tool.default=esptool_py + wesp32.upload.tool=esptool_py +wesp32.upload.tool.default=esptool_py +wesp32.upload.tool.network=esp_ota + wesp32.upload.maximum_size=1310720 wesp32.upload.maximum_data_size=327680 wesp32.upload.flags= @@ -7244,7 +10258,13 @@ wesp32.menu.DebugLevel.verbose.build.code_debug=5 t-beam.name=T-Beam +t-beam.bootloader.tool=esptool_py +t-beam.bootloader.tool.default=esptool_py + t-beam.upload.tool=esptool_py +t-beam.upload.tool.default=esptool_py +t-beam.upload.tool.network=esp_ota + t-beam.upload.maximum_size=1310720 t-beam.upload.maximum_data_size=327680 t-beam.upload.flags= @@ -7311,7 +10331,13 @@ t-beam.menu.DebugLevel.verbose.build.code_debug=5 d-duino-32.name=D-duino-32 +d-duino-32.bootloader.tool=esptool_py +d-duino-32.bootloader.tool.default=esptool_py + d-duino-32.upload.tool=esptool_py +d-duino-32.upload.tool.default=esptool_py +d-duino-32.upload.tool.network=esp_ota + d-duino-32.upload.maximum_size=1310720 d-duino-32.upload.maximum_data_size=327680 d-duino-32.upload.flags= @@ -7386,7 +10412,13 @@ d-duino-32.menu.DebugLevel.verbose.build.code_debug=5 lopy.name=LoPy +lopy.bootloader.tool=esptool_py +lopy.bootloader.tool.default=esptool_py + lopy.upload.tool=esptool_py +lopy.upload.tool.default=esptool_py +lopy.upload.tool.network=esp_ota + lopy.upload.maximum_size=1310720 lopy.upload.maximum_data_size=327680 lopy.upload.flags= @@ -7446,7 +10478,13 @@ lopy.menu.DebugLevel.verbose.build.code_debug=5 lopy4.name=LoPy4 +lopy4.bootloader.tool=esptool_py +lopy4.bootloader.tool.default=esptool_py + lopy4.upload.tool=esptool_py +lopy4.upload.tool.default=esptool_py +lopy4.upload.tool.network=esp_ota + lopy4.upload.maximum_size=1310720 lopy4.upload.maximum_data_size=327680 lopy4.upload.flags= @@ -7513,7 +10551,13 @@ lopy4.menu.DebugLevel.verbose.build.code_debug=5 oroca_edubot.name=OROCA EduBot +oroca_edubot.bootloader.tool=esptool_py +oroca_edubot.bootloader.tool.default=esptool_py + oroca_edubot.upload.tool=esptool_py +oroca_edubot.upload.tool.default=esptool_py +oroca_edubot.upload.tool.network=esp_ota + oroca_edubot.upload.maximum_size=3145728 oroca_edubot.upload.maximum_data_size=327680 oroca_edubot.upload.flags= @@ -7577,8 +10621,6 @@ oroca_edubot.menu.DebugLevel.debug.build.code_debug=4 oroca_edubot.menu.DebugLevel.verbose=Verbose oroca_edubot.menu.DebugLevel.verbose.build.code_debug=5 - - ############################################################## fm-devkit.name=ESP32 FM DevKit @@ -7640,7 +10682,13 @@ fm-devkit.menu.DebugLevel.verbose.build.code_debug=5 frogboard.name=Frog Board ESP32 +frogboard.bootloader.tool=esptool_py +frogboard.bootloader.tool.default=esptool_py + frogboard.upload.tool=esptool_py +frogboard.upload.tool.default=esptool_py +frogboard.upload.tool.network=esp_ota + frogboard.upload.maximum_size=1310720 frogboard.upload.maximum_data_size=327680 frogboard.upload.flags= @@ -7736,7 +10784,13 @@ frogboard.menu.DebugLevel.verbose.build.code_debug=5 esp32cam.name=AI Thinker ESP32-CAM +esp32cam.bootloader.tool=esptool_py +esp32cam.bootloader.tool.default=esptool_py + esp32cam.upload.tool=esptool_py +esp32cam.upload.tool.default=esptool_py +esp32cam.upload.tool.network=esp_ota + esp32cam.upload.maximum_size=3145728 esp32cam.upload.maximum_data_size=327680 esp32cam.upload.flags= @@ -7789,16 +10843,60 @@ esp32cam.menu.FlashMode.dout=DOUT esp32cam.menu.FlashMode.dout.build.flash_mode=dout esp32cam.menu.FlashMode.dout.build.boot=dout +esp32cam.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +esp32cam.menu.PartitionScheme.huge_app.build.partitions=huge_app +esp32cam.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 +esp32cam.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS) +esp32cam.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +esp32cam.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 +esp32cam.menu.PartitionScheme.default=Regular 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +esp32cam.menu.PartitionScheme.default.build.partitions=default +esp32cam.menu.PartitionScheme.defaultffat=Regular 4MB with ffat (1.2MB APP/1.5MB FATFS) +esp32cam.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +esp32cam.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS) +esp32cam.menu.PartitionScheme.minimal.build.partitions=minimal +esp32cam.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +esp32cam.menu.PartitionScheme.no_ota.build.partitions=no_ota +esp32cam.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +esp32cam.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +esp32cam.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +esp32cam.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +esp32cam.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +esp32cam.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +esp32cam.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +esp32cam.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +esp32cam.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +esp32cam.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 + esp32cam.menu.FlashFreq.80=80MHz esp32cam.menu.FlashFreq.80.build.flash_freq=80m esp32cam.menu.FlashFreq.40=40MHz esp32cam.menu.FlashFreq.40.build.flash_freq=40m +esp32cam.menu.DebugLevel.none=None +esp32cam.menu.DebugLevel.none.build.code_debug=0 +esp32cam.menu.DebugLevel.error=Error +esp32cam.menu.DebugLevel.error.build.code_debug=1 +esp32cam.menu.DebugLevel.warn=Warn +esp32cam.menu.DebugLevel.warn.build.code_debug=2 +esp32cam.menu.DebugLevel.info=Info +esp32cam.menu.DebugLevel.info.build.code_debug=3 +esp32cam.menu.DebugLevel.debug=Debug +esp32cam.menu.DebugLevel.debug.build.code_debug=4 +esp32cam.menu.DebugLevel.verbose=Verbose +esp32cam.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## twatch.name=TTGO T-Watch +twatch.bootloader.tool=esptool_py +twatch.bootloader.tool.default=esptool_py + twatch.upload.tool=esptool_py +twatch.upload.tool.default=esptool_py +twatch.upload.tool.network=esp_ota + twatch.upload.maximum_size=6553600 twatch.upload.maximum_data_size=4521984 twatch.upload.wait_for_upload_port=true @@ -7883,7 +10981,13 @@ twatch.menu.DebugLevel.verbose.build.code_debug=5 d1_mini32.name=WEMOS D1 MINI ESP32 +d1_mini32.bootloader.tool=esptool_py +d1_mini32.bootloader.tool.default=esptool_py + d1_mini32.upload.tool=esptool_py +d1_mini32.upload.tool.default=esptool_py +d1_mini32.upload.tool.network=esp_ota + d1_mini32.upload.maximum_size=1310720 d1_mini32.upload.maximum_data_size=327680 d1_mini32.upload.flags= @@ -7953,11 +11057,30 @@ d1_mini32.menu.UploadSpeed.460800.upload.speed=460800 d1_mini32.menu.UploadSpeed.512000.windows=512000 d1_mini32.menu.UploadSpeed.512000.upload.speed=512000 +d1_mini32.menu.DebugLevel.none=None +d1_mini32.menu.DebugLevel.none.build.code_debug=0 +d1_mini32.menu.DebugLevel.error=Error +d1_mini32.menu.DebugLevel.error.build.code_debug=1 +d1_mini32.menu.DebugLevel.warn=Warn +d1_mini32.menu.DebugLevel.warn.build.code_debug=2 +d1_mini32.menu.DebugLevel.info=Info +d1_mini32.menu.DebugLevel.info.build.code_debug=3 +d1_mini32.menu.DebugLevel.debug=Debug +d1_mini32.menu.DebugLevel.debug.build.code_debug=4 +d1_mini32.menu.DebugLevel.verbose=Verbose +d1_mini32.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## gpy.name=Pycom GPy +gpy.bootloader.tool=esptool_py +gpy.bootloader.tool.default=esptool_py + gpy.upload.tool=esptool_py +gpy.upload.tool.default=esptool_py +gpy.upload.tool.network=esp_ota + gpy.upload.maximum_size=1310720 gpy.upload.maximum_data_size=327680 gpy.upload.flags= @@ -8017,7 +11140,13 @@ gpy.menu.DebugLevel.verbose.build.code_debug=5 vintlabs-devkit-v1.name=VintLabs ESP32 Devkit +vintlabs-devkit-v1.bootloader.tool=esptool_py +vintlabs-devkit-v1.bootloader.tool.default=esptool_py + vintlabs-devkit-v1.upload.tool=esptool_py +vintlabs-devkit-v1.upload.tool.default=esptool_py +vintlabs-devkit-v1.upload.tool.network=esp_ota + vintlabs-devkit-v1.upload.maximum_size=1310720 vintlabs-devkit-v1.upload.maximum_data_size=327680 vintlabs-devkit-v1.upload.flags= @@ -8123,7 +11252,13 @@ vintlabs-devkit-v1.menu.DebugLevel.debug.build.code_debug=4 honeylemon.name=HONEYLemon +honeylemon.bootloader.tool=esptool_py +honeylemon.bootloader.tool.default=esptool_py + honeylemon.upload.tool=esptool_py +honeylemon.upload.tool.default=esptool_py +honeylemon.upload.tool.network=esp_ota + honeylemon.upload.maximum_size=1310720 honeylemon.upload.maximum_data_size=327680 honeylemon.upload.flags= @@ -8167,11 +11302,30 @@ honeylemon.menu.UploadSpeed.460800.upload.speed=460800 honeylemon.menu.UploadSpeed.512000.windows=512000 honeylemon.menu.UploadSpeed.512000.upload.speed=512000 +honeylemon.menu.DebugLevel.none=None +honeylemon.menu.DebugLevel.none.build.code_debug=0 +honeylemon.menu.DebugLevel.error=Error +honeylemon.menu.DebugLevel.error.build.code_debug=1 +honeylemon.menu.DebugLevel.warn=Warn +honeylemon.menu.DebugLevel.warn.build.code_debug=2 +honeylemon.menu.DebugLevel.info=Info +honeylemon.menu.DebugLevel.info.build.code_debug=3 +honeylemon.menu.DebugLevel.debug=Debug +honeylemon.menu.DebugLevel.debug.build.code_debug=4 +honeylemon.menu.DebugLevel.verbose=Verbose +honeylemon.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## mgbot-iotik32a.name=MGBOT IOTIK 32A +mgbot-iotik32a.bootloader.tool=esptool_py +mgbot-iotik32a.bootloader.tool.default=esptool_py + mgbot-iotik32a.upload.tool=esptool_py +mgbot-iotik32a.upload.tool.default=esptool_py +mgbot-iotik32a.upload.tool.network=esp_ota + mgbot-iotik32a.upload.maximum_size=1310720 mgbot-iotik32a.upload.maximum_data_size=327680 mgbot-iotik32a.upload.flags= @@ -8315,7 +11469,13 @@ mgbot-iotik32a.menu.DebugLevel.verbose.build.code_debug=5 mgbot-iotik32b.name=MGBOT IOTIK 32B +mgbot-iotik32b.bootloader.tool=esptool_py +mgbot-iotik32b.bootloader.tool.default=esptool_py + mgbot-iotik32b.upload.tool=esptool_py +mgbot-iotik32b.upload.tool.default=esptool_py +mgbot-iotik32b.upload.tool.network=esp_ota + mgbot-iotik32b.upload.maximum_size=1310720 mgbot-iotik32b.upload.maximum_data_size=327680 mgbot-iotik32b.upload.flags= @@ -8456,9 +11616,16 @@ mgbot-iotik32b.menu.DebugLevel.verbose=Verbose mgbot-iotik32b.menu.DebugLevel.verbose.build.code_debug=5 ############################################################## + piranha_esp-32.name=Piranha ESP-32 +piranha_esp-32.bootloader.tool=esptool_py +piranha_esp-32.bootloader.tool.default=esptool_py + piranha_esp-32.upload.tool=esptool_py +piranha_esp-32.upload.tool.default=esptool_py +piranha_esp-32.upload.tool.network=esp_ota + piranha_esp-32.upload.maximum_size=1310720 piranha_esp-32.upload.maximum_data_size=327680 piranha_esp-32.upload.flags= @@ -8528,7 +11695,13 @@ piranha_esp-32.menu.DebugLevel.verbose.build.code_debug=5 metro_esp-32.name=Metro ESP-32 +metro_esp-32.bootloader.tool=esptool_py +metro_esp-32.bootloader.tool.default=esptool_py + metro_esp-32.upload.tool=esptool_py +metro_esp-32.upload.tool.default=esptool_py +metro_esp-32.upload.tool.network=esp_ota + metro_esp-32.upload.maximum_size=1310720 metro_esp-32.upload.maximum_data_size=327680 metro_esp-32.upload.flags= @@ -8595,9 +11768,16 @@ metro_esp-32.menu.DebugLevel.verbose=Verbose metro_esp-32.menu.DebugLevel.verbose.build.code_debug=5 ############################################################## + sensesiot_weizen.name=Senses's WEIZEN +sensesiot_weizen.bootloader.tool=esptool_py +sensesiot_weizen.bootloader.tool.default=esptool_py + sensesiot_weizen.upload.tool=esptool_py +sensesiot_weizen.upload.tool.default=esptool_py +sensesiot_weizen.upload.tool.network=esp_ota + sensesiot_weizen.upload.maximum_size=1310720 sensesiot_weizen.upload.maximum_data_size=327680 sensesiot_weizen.upload.flags= @@ -8641,10 +11821,30 @@ sensesiot_weizen.menu.UploadSpeed.460800.upload.speed=460800 sensesiot_weizen.menu.UploadSpeed.512000.windows=512000 sensesiot_weizen.menu.UploadSpeed.512000.upload.speed=512000 +sensesiot_weizen.menu.DebugLevel.none=None +sensesiot_weizen.menu.DebugLevel.none.build.code_debug=0 +sensesiot_weizen.menu.DebugLevel.error=Error +sensesiot_weizen.menu.DebugLevel.error.build.code_debug=1 +sensesiot_weizen.menu.DebugLevel.warn=Warn +sensesiot_weizen.menu.DebugLevel.warn.build.code_debug=2 +sensesiot_weizen.menu.DebugLevel.info=Info +sensesiot_weizen.menu.DebugLevel.info.build.code_debug=3 +sensesiot_weizen.menu.DebugLevel.debug=Debug +sensesiot_weizen.menu.DebugLevel.debug.build.code_debug=4 +sensesiot_weizen.menu.DebugLevel.verbose=Verbose +sensesiot_weizen.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## + kits-edu.name=KITS ESP32 EDU +kits-edu.bootloader.tool=esptool_py +kits-edu.bootloader.tool.default=esptool_py + kits-edu.upload.tool=esptool_py +kits-edu.upload.tool.default=esptool_py +kits-edu.upload.tool.network=esp_ota + kits-edu.upload.maximum_size=1310720 kits-edu.upload.maximum_data_size=327680 kits-edu.upload.wait_for_upload_port=true @@ -8710,7 +11910,13 @@ kits-edu.menu.DebugLevel.verbose.build.code_debug=5 ############################################################## mPython.name=Labplus mPython +mPython.bootloader.tool=esptool_py +mPython.bootloader.tool.default=esptool_py + mPython.upload.tool=esptool_py +mPython.upload.tool.default=esptool_py +mPython.upload.tool.network=esp_ota + mPython.upload.maximum_size=1310720 mPython.upload.maximum_data_size=327680 mPython.upload.flags= @@ -8772,7 +11978,6 @@ mPython.menu.PartitionScheme.fatflash.build.partitions=ffat mPython.menu.CPUFreq.240=240MHz (WiFi/BT) mPython.menu.CPUFreq.240.build.f_cpu=240000000L - mPython.menu.FlashMode.qio=QIO mPython.menu.FlashMode.qio.build.flash_mode=dio mPython.menu.FlashMode.qio.build.boot=qio @@ -8794,7 +11999,6 @@ mPython.menu.FlashFreq.40.build.flash_freq=40m mPython.menu.FlashSize.8M=8MB (64Mb) mPython.menu.FlashSize.8M.build.flash_size=8MB - mPython.menu.UploadSpeed.921600=921600 mPython.menu.UploadSpeed.921600.upload.speed=921600 mPython.menu.UploadSpeed.115200=115200 @@ -8827,7 +12031,13 @@ mPython.menu.DebugLevel.verbose.build.code_debug=5 OpenKB.name=INEX OpenKB +OpenKB.bootloader.tool=esptool_py +OpenKB.bootloader.tool.default=esptool_py + OpenKB.upload.tool=esptool_py +OpenKB.upload.tool.default=esptool_py +OpenKB.upload.tool.network=esp_ota + OpenKB.upload.maximum_size=1310720 OpenKB.upload.maximum_data_size=327680 OpenKB.upload.wait_for_upload_port=true @@ -8872,11 +12082,30 @@ OpenKB.menu.UploadSpeed.460800.upload.speed=460800 OpenKB.menu.UploadSpeed.512000.windows=512000 OpenKB.menu.UploadSpeed.512000.upload.speed=512000 +OpenKB.menu.DebugLevel.none=None +OpenKB.menu.DebugLevel.none.build.code_debug=0 +OpenKB.menu.DebugLevel.error=Error +OpenKB.menu.DebugLevel.error.build.code_debug=1 +OpenKB.menu.DebugLevel.warn=Warn +OpenKB.menu.DebugLevel.warn.build.code_debug=2 +OpenKB.menu.DebugLevel.info=Info +OpenKB.menu.DebugLevel.info.build.code_debug=3 +OpenKB.menu.DebugLevel.debug=Debug +OpenKB.menu.DebugLevel.debug.build.code_debug=4 +OpenKB.menu.DebugLevel.verbose=Verbose +OpenKB.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## wifiduino32.name=WiFiduino32 +wifiduino32.bootloader.tool=esptool_py +wifiduino32.bootloader.tool.default=esptool_py + wifiduino32.upload.tool=esptool_py +wifiduino32.upload.tool.default=esptool_py +wifiduino32.upload.tool.network=esp_ota + wifiduino32.upload.maximum_size=1310720 wifiduino32.upload.maximum_data_size=327680 wifiduino32.upload.wait_for_upload_port=true @@ -8943,12 +12172,17 @@ wifiduino32.menu.DebugLevel.debug.build.code_debug=4 wifiduino32.menu.DebugLevel.verbose=Verbose wifiduino32.menu.DebugLevel.verbose.build.code_debug=5 - ############################################################## imbrios-logsens-v1p1.name=IMBRIOS LOGSENS_V1P1 +imbrios-logsens-v1p1.bootloader.tool=esptool_py +imbrios-logsens-v1p1.bootloader.tool.default=esptool_py + imbrios-logsens-v1p1.upload.tool=esptool_py +imbrios-logsens-v1p1.upload.tool.default=esptool_py +imbrios-logsens-v1p1.upload.tool.network=esp_ota + imbrios-logsens-v1p1.upload.maximum_size=1310720 imbrios-logsens-v1p1.upload.maximum_data_size=327680 imbrios-logsens-v1p1.upload.wait_for_upload_port=true @@ -9019,11 +12253,30 @@ imbrios-logsens-v1p1.menu.UploadSpeed.460800.upload.speed=460800 imbrios-logsens-v1p1.menu.UploadSpeed.512000.windows=512000 imbrios-logsens-v1p1.menu.UploadSpeed.512000.upload.speed=512000 +imbrios-logsens-v1p1.menu.DebugLevel.none=None +imbrios-logsens-v1p1.menu.DebugLevel.none.build.code_debug=0 +imbrios-logsens-v1p1.menu.DebugLevel.error=Error +imbrios-logsens-v1p1.menu.DebugLevel.error.build.code_debug=1 +imbrios-logsens-v1p1.menu.DebugLevel.warn=Warn +imbrios-logsens-v1p1.menu.DebugLevel.warn.build.code_debug=2 +imbrios-logsens-v1p1.menu.DebugLevel.info=Info +imbrios-logsens-v1p1.menu.DebugLevel.info.build.code_debug=3 +imbrios-logsens-v1p1.menu.DebugLevel.debug=Debug +imbrios-logsens-v1p1.menu.DebugLevel.debug.build.code_debug=4 +imbrios-logsens-v1p1.menu.DebugLevel.verbose=Verbose +imbrios-logsens-v1p1.menu.DebugLevel.verbose.build.code_debug=5 + ############################################################## healthypi4.name=ProtoCentral HealthyPi 4 +healthypi4.bootloader.tool=esptool_py +healthypi4.bootloader.tool.default=esptool_py + healthypi4.upload.tool=esptool_py +healthypi4.upload.tool.default=esptool_py +healthypi4.upload.tool.network=esp_ota + healthypi4.upload.maximum_size=1310720 healthypi4.upload.maximum_data_size=327680 healthypi4.upload.wait_for_upload_port=true @@ -9092,10 +12345,15 @@ healthypi4.menu.DebugLevel.verbose.build.code_debug=5 ############################################################## - ET-Board.name=ET-Board +ET-Board.bootloader.tool=esptool_py +ET-Board.bootloader.tool.default=esptool_py + ET-Board.upload.tool=esptool_py +ET-Board.upload.tool.default=esptool_py +ET-Board.upload.tool.network=esp_ota + ET-Board.upload.maximum_size=1310720 ET-Board.upload.maximum_data_size=327680 ET-Board.upload.wait_for_upload_port=true @@ -9165,7 +12423,13 @@ ET-Board.menu.DebugLevel.verbose.build.code_debug=5 ch_denky.name=Denky +ch_denky.bootloader.tool=esptool_py +ch_denky.bootloader.tool.default=esptool_py + ch_denky.upload.tool=esptool_py +ch_denky.upload.tool.default=esptool_py +ch_denky.upload.tool.network=esp_ota + ch_denky.upload.maximum_size=1310720 ch_denky.upload.maximum_data_size=327680 ch_denky.upload.flags= @@ -9245,7 +12509,13 @@ ch_denky.menu.DebugLevel.verbose.build.code_debug=5 uPesy_wrover.name=uPesy ESP32 Wrover DevKit +uPesy_wrover.bootloader.tool=esptool_py +uPesy_wrover.bootloader.tool.default=esptool_py + uPesy_wrover.upload.tool=esptool_py +uPesy_wrover.upload.tool.default=esptool_py +uPesy_wrover.upload.tool.network=esp_ota + uPesy_wrover.upload.maximum_size=1310720 uPesy_wrover.upload.maximum_data_size=327680 uPesy_wrover.upload.flags= @@ -9351,7 +12621,13 @@ uPesy_wrover.menu.DebugLevel.verbose.build.code_debug=5 uPesy_wroom.name=uPesy ESP32 Wroom DevKit +uPesy_wroom.bootloader.tool=esptool_py +uPesy_wroom.bootloader.tool.default=esptool_py + uPesy_wroom.upload.tool=esptool_py +uPesy_wroom.upload.tool.default=esptool_py +uPesy_wroom.upload.tool.network=esp_ota + uPesy_wroom.upload.maximum_size=1310720 uPesy_wroom.upload.maximum_data_size=327680 uPesy_wroom.upload.flags= @@ -9450,7 +12726,13 @@ uPesy_wroom.menu.DebugLevel.verbose.build.code_debug=5 kb32.name=KB32-FT +kb32.bootloader.tool=esptool_py +kb32.bootloader.tool.default=esptool_py + kb32.upload.tool=esptool_py +kb32.upload.tool.default=esptool_py +kb32.upload.tool.network=esp_ota + kb32.upload.maximum_size=1310720 kb32.upload.maximum_data_size=327680 kb32.upload.flags= @@ -9609,7 +12891,13 @@ kb32.menu.DebugLevel.verbose.build.code_debug=5 deneyapkart.name=Deneyap Kart +deneyapkart.bootloader.tool=esptool_py +deneyapkart.bootloader.tool.default=esptool_py + deneyapkart.upload.tool=esptool_py +deneyapkart.upload.tool.default=esptool_py +deneyapkart.upload.tool.network=esp_ota + deneyapkart.upload.maximum_size=1310720 deneyapkart.upload.maximum_data_size=327680 deneyapkart.upload.wait_for_upload_port=true @@ -9664,6 +12952,11 @@ deneyapkart.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs deneyapkart.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 deneyapkart.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FAT) deneyapkart.menu.PartitionScheme.fatflash.build.partitions=ffat +deneyapkart.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB +deneyapkart.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 +deneyapkart.menu.PartitionScheme.rainmaker=RainMaker +deneyapkart.menu.PartitionScheme.rainmaker.build.partitions=rainmaker +deneyapkart.menu.PartitionScheme.rainmaker.upload.maximum_size=3145728 deneyapkart.menu.CPUFreq.240=240MHz (WiFi/BT) deneyapkart.menu.CPUFreq.240.build.f_cpu=240000000L @@ -9728,7 +13021,13 @@ deneyapkart.menu.DebugLevel.verbose.build.code_debug=5 esp32-trueverit-iot-driver.name=Trueverit ESP32 Universal IoT Driver +esp32-trueverit-iot-driver.bootloader.tool=esptool_py +esp32-trueverit-iot-driver.bootloader.tool.default=esptool_py + esp32-trueverit-iot-driver.upload.tool=esptool_py +esp32-trueverit-iot-driver.upload.tool.default=esptool_py +esp32-trueverit-iot-driver.upload.tool.network=esp_ota + esp32-trueverit-iot-driver.upload.maximum_size=1310720 esp32-trueverit-iot-driver.upload.maximum_data_size=327680 esp32-trueverit-iot-driver.upload.flags= @@ -9785,7 +13084,13 @@ esp32-trueverit-iot-driver.menu.DebugLevel.verbose.build.code_debug=5 esp32-trueverit-iot-driver-mkii.name=Trueverit ESP32 Universal IoT Driver MK II +esp32-trueverit-iot-driver-mkii.bootloader.tool=esptool_py +esp32-trueverit-iot-driver-mkii.bootloader.tool.default=esptool_py + esp32-trueverit-iot-driver-mkii.upload.tool=esptool_py +esp32-trueverit-iot-driver-mkii.upload.tool.default=esptool_py +esp32-trueverit-iot-driver-mkii.upload.tool.network=esp_ota + esp32-trueverit-iot-driver-mkii.upload.maximum_size=1310720 esp32-trueverit-iot-driver-mkii.upload.maximum_data_size=327680 esp32-trueverit-iot-driver-mkii.upload.flags= @@ -9844,7 +13149,13 @@ atmegazero_esp32s2.name=ATMegaZero ESP32-S2 atmegazero_esp32s2.vid.0=0x239A atmegazero_esp32s2.pid.0=0x800A +atmegazero_esp32s2.bootloader.tool=esptool_py +atmegazero_esp32s2.bootloader.tool.default=esptool_py + atmegazero_esp32s2.upload.tool=esptool_py +atmegazero_esp32s2.upload.tool.default=esptool_py +atmegazero_esp32s2.upload.tool.network=esp_ota + atmegazero_esp32s2.upload.maximum_size=1310720 atmegazero_esp32s2.upload.maximum_data_size=327680 atmegazero_esp32s2.upload.flags= @@ -10006,7 +13317,13 @@ deneyapmini.name=Deneyap Mini deneyapmini.vid.0=0x303a deneyapmini.pid.0=0x0002 +deneyapmini.bootloader.tool=esptool_py +deneyapmini.bootloader.tool.default=esptool_py + deneyapmini.upload.tool=esptool_py +deneyapmini.upload.tool.default=esptool_py +deneyapmini.upload.tool.network=esp_ota + deneyapmini.upload.maximum_size=1310720 deneyapmini.upload.maximum_data_size=327680 deneyapmini.upload.flags= @@ -10173,7 +13490,13 @@ franzininho_wifi_esp32s2.name=Franzininho WiFi franzininho_wifi_esp32s2.vid.0=0x303A franzininho_wifi_esp32s2.pid.0=0x80A9 +franzininho_wifi_esp32s2.bootloader.tool=esptool_py +franzininho_wifi_esp32s2.bootloader.tool.default=esptool_py + franzininho_wifi_esp32s2.upload.tool=esptool_py +franzininho_wifi_esp32s2.upload.tool.default=esptool_py +franzininho_wifi_esp32s2.upload.tool.network=esp_ota + franzininho_wifi_esp32s2.upload.maximum_size=1310720 franzininho_wifi_esp32s2.upload.maximum_data_size=327680 franzininho_wifi_esp32s2.upload.flags= @@ -10270,7 +13593,13 @@ franzininho_wifi_msc_esp32s2.name=Franzininho WiFi MSC franzininho_wifi_msc_esp32s2.vid.0=0x303A franzininho_wifi_msc_esp32s2.pid.0=0x80A9 +franzininho_wifi_msc_esp32s2.bootloader.tool=esptool_py +franzininho_wifi_msc_esp32s2.bootloader.tool.default=esptool_py + franzininho_wifi_msc_esp32s2.upload.tool=esptool_py +franzininho_wifi_msc_esp32s2.upload.tool.default=esptool_py +franzininho_wifi_msc_esp32s2.upload.tool.network=esp_ota + franzininho_wifi_msc_esp32s2.upload.maximum_size=1310720 franzininho_wifi_msc_esp32s2.upload.maximum_data_size=327680 franzininho_wifi_msc_esp32s2.upload.flags= @@ -10365,7 +13694,13 @@ franzininho_wifi_msc_esp32s2.menu.DebugLevel.verbose.build.code_debug=5 dpu_esp32.name=DPU ESP32 +dpu_esp32.bootloader.tool=esptool_py +dpu_esp32.bootloader.tool.default=esptool_py + dpu_esp32.upload.tool=esptool_py +dpu_esp32.upload.tool.default=esptool_py +dpu_esp32.upload.tool.network=esp_ota + dpu_esp32.upload.maximum_size=3342336 dpu_esp32.upload.maximum_data_size=327680 dpu_esp32.upload.flags= @@ -10474,7 +13809,13 @@ dpu_esp32.menu.DebugLevel.verbose.build.code_debug=5 sonoff_dualr3.name=Sonoff DUALR3 +sonoff_dualr3.bootloader.tool=esptool_py +sonoff_dualr3.bootloader.tool.default=esptool_py + sonoff_dualr3.upload.tool=esptool_py +sonoff_dualr3.upload.tool.default=esptool_py +sonoff_dualr3.upload.tool.network=esp_ota + sonoff_dualr3.upload.maximum_size=1310720 sonoff_dualr3.upload.maximum_data_size=327680 sonoff_dualr3.upload.flags= @@ -10572,3 +13913,465 @@ sonoff_dualr3.menu.DebugLevel.verbose=Verbose sonoff_dualr3.menu.DebugLevel.verbose.build.code_debug=5 ############################################################## +lionbit.name=Lion:Bit Dev Board + +lionbit.bootloader.tool=esptool_py +lionbit.bootloader.tool.default=esptool_py + +lionbit.upload.tool=esptool_py +lionbit.upload.tool.default=esptool_py +lionbit.upload.tool.network=esp_ota + +lionbit.upload.maximum_size=1310720 +lionbit.upload.maximum_data_size=327680 +lionbit.upload.flags= +lionbit.upload.extra_flags= + +lionbit.serial.disableDTR=true +lionbit.serial.disableRTS=true + +lionbit.build.tarch=xtensa +lionbit.build.bootloader_addr=0x1000 +lionbit.build.target=esp32 +lionbit.build.mcu=esp32 +lionbit.build.core=esp32 +lionbit.build.variant=lionbit +lionbit.build.board=Lion:Bit_Dev_Board + +lionbit.build.f_cpu=240000000L +lionbit.build.flash_size=4MB +lionbit.build.flash_freq=80m +lionbit.build.flash_mode=dio +lionbit.build.boot=dio +lionbit.build.partitions=default +lionbit.build.defines= +lionbit.build.loop_core= +lionbit.build.event_core= + + +lionbit.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +lionbit.menu.PartitionScheme.default.build.partitions=default +lionbit.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +lionbit.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +lionbit.menu.PartitionScheme.default_8MB=8M Flash (3MB APP/1.5MB FAT) +lionbit.menu.PartitionScheme.default_8MB.build.partitions=default_8MB +lionbit.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 +lionbit.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS) +lionbit.menu.PartitionScheme.minimal.build.partitions=minimal +lionbit.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +lionbit.menu.PartitionScheme.no_ota.build.partitions=no_ota +lionbit.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +lionbit.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +lionbit.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +lionbit.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +lionbit.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +lionbit.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +lionbit.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +lionbit.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +lionbit.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +lionbit.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +lionbit.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +lionbit.menu.PartitionScheme.huge_app.build.partitions=huge_app +lionbit.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 +lionbit.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS) +lionbit.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +lionbit.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 +lionbit.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FAT) +lionbit.menu.PartitionScheme.fatflash.build.partitions=ffat +lionbit.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 +lionbit.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9MB FATFS) +lionbit.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB +lionbit.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 +lionbit.menu.PartitionScheme.rainmaker=RainMaker +lionbit.menu.PartitionScheme.rainmaker.build.partitions=rainmaker +lionbit.menu.PartitionScheme.rainmaker.upload.maximum_size=3145728 + +lionbit.menu.CPUFreq.240=240MHz (WiFi/BT) +lionbit.menu.CPUFreq.240.build.f_cpu=240000000L +lionbit.menu.CPUFreq.160=160MHz (WiFi/BT) +lionbit.menu.CPUFreq.160.build.f_cpu=160000000L +lionbit.menu.CPUFreq.80=80MHz (WiFi/BT) +lionbit.menu.CPUFreq.80.build.f_cpu=80000000L +lionbit.menu.CPUFreq.40=40MHz (40MHz XTAL) +lionbit.menu.CPUFreq.40.build.f_cpu=40000000L +lionbit.menu.CPUFreq.26=26MHz (26MHz XTAL) +lionbit.menu.CPUFreq.26.build.f_cpu=26000000L +lionbit.menu.CPUFreq.20=20MHz (40MHz XTAL) +lionbit.menu.CPUFreq.20.build.f_cpu=20000000L +lionbit.menu.CPUFreq.13=13MHz (26MHz XTAL) +lionbit.menu.CPUFreq.13.build.f_cpu=13000000L +lionbit.menu.CPUFreq.10=10MHz (40MHz XTAL) +lionbit.menu.CPUFreq.10.build.f_cpu=10000000L + + +lionbit.menu.FlashMode.dio=DIO +lionbit.menu.FlashMode.dio.build.flash_mode=dio +lionbit.menu.FlashMode.dio.build.boot=dio +lionbit.menu.FlashMode.qio=QIO +lionbit.menu.FlashMode.qio.build.flash_mode=dio +lionbit.menu.FlashMode.qio.build.boot=qio +lionbit.menu.FlashMode.qout=QOUT +lionbit.menu.FlashMode.qout.build.flash_mode=dout +lionbit.menu.FlashMode.qout.build.boot=qout +lionbit.menu.FlashMode.dout=DOUT +lionbit.menu.FlashMode.dout.build.flash_mode=dout +lionbit.menu.FlashMode.dout.build.boot=dout + +lionbit.menu.FlashFreq.80=80MHz +lionbit.menu.FlashFreq.80.build.flash_freq=80m +lionbit.menu.FlashFreq.40=40MHz +lionbit.menu.FlashFreq.40.build.flash_freq=40m + +lionbit.menu.FlashSize.4M=4MB (32Mb) +lionbit.menu.FlashSize.4M.build.flash_size=4MB +lionbit.menu.FlashSize.4M.build.partitions=default + + + +lionbit.menu.UploadSpeed.115200=115200 +lionbit.menu.UploadSpeed.115200.upload.speed=115200 +lionbit.menu.UploadSpeed.256000.windows=256000 +lionbit.menu.UploadSpeed.256000.upload.speed=256000 +lionbit.menu.UploadSpeed.230400.windows.upload.speed=256000 +lionbit.menu.UploadSpeed.230400=230400 +lionbit.menu.UploadSpeed.230400.upload.speed=230400 +lionbit.menu.UploadSpeed.460800.linux=460800 +lionbit.menu.UploadSpeed.460800.macosx=460800 +lionbit.menu.UploadSpeed.460800.upload.speed=460800 + + +lionbit.menu.LoopCore.1=Core 1 +lionbit.menu.LoopCore.1.build.loop_core=-DARDUINO_RUNNING_CORE=1 +lionbit.menu.LoopCore.0=Core 0 +lionbit.menu.LoopCore.0.build.loop_core=-DARDUINO_RUNNING_CORE=0 + +lionbit.menu.EventsCore.1=Core 1 +lionbit.menu.EventsCore.1.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1 +lionbit.menu.EventsCore.0=Core 0 +lionbit.menu.EventsCore.0.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=0 + +lionbit.menu.DebugLevel.none=None +lionbit.menu.DebugLevel.none.build.code_debug=0 +lionbit.menu.DebugLevel.error=Error +lionbit.menu.DebugLevel.error.build.code_debug=1 +lionbit.menu.DebugLevel.warn=Warn +lionbit.menu.DebugLevel.warn.build.code_debug=2 +lionbit.menu.DebugLevel.info=Info +lionbit.menu.DebugLevel.info.build.code_debug=3 +lionbit.menu.DebugLevel.debug=Debug +lionbit.menu.DebugLevel.debug.build.code_debug=4 +lionbit.menu.DebugLevel.verbose=Verbose +lionbit.menu.DebugLevel.verbose.build.code_debug=5 + +############################################################## + +watchy.name=Watchy + +watchy.bootloader.tool=esptool_py +watchy.bootloader.tool.default=esptool_py + +watchy.upload.tool=esptool_py +watchy.upload.tool.default=esptool_py +watchy.upload.tool.network=esp_ota + +watchy.upload.maximum_size=1310720 +watchy.upload.maximum_data_size=327680 +watchy.upload.flags= +watchy.upload.extra_flags= + +watchy.serial.disableDTR=true +watchy.serial.disableRTS=true + +watchy.build.tarch=xtensa +watchy.build.bootloader_addr=0x1000 +watchy.build.target=esp32 +watchy.build.mcu=esp32 +watchy.build.core=esp32 +watchy.build.variant=watchy +watchy.build.board=WATCHY + +watchy.build.f_cpu=240000000L +watchy.build.flash_size=4MB +watchy.build.flash_freq=80m +watchy.build.flash_mode=dio +watchy.build.boot=qio +watchy.build.partitions=min_spiffs +watchy.build.defines= + +watchy.menu.Revision.v10=Watchy v1.0 +watchy.menu.Revision.v10.build.board=WATCHY_V10 +watchy.menu.Revision.v15=Watchy v1.5 +watchy.menu.Revision.v15.build.board=WATCHY_V15 +watchy.menu.Revision.v20=Watchy v2.0 +watchy.menu.Revision.v20.build.board=WATCHY_V20 + +watchy.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +watchy.menu.PartitionScheme.huge_app.build.partitions=huge_app +watchy.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 +watchy.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS) +watchy.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +watchy.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 + +watchy.menu.UploadSpeed.921600=921600 +watchy.menu.UploadSpeed.921600.upload.speed=921600 +watchy.menu.UploadSpeed.115200=115200 +watchy.menu.UploadSpeed.115200.upload.speed=115200 +watchy.menu.UploadSpeed.256000.windows=256000 +watchy.menu.UploadSpeed.256000.upload.speed=256000 +watchy.menu.UploadSpeed.230400.windows.upload.speed=256000 +watchy.menu.UploadSpeed.230400=230400 +watchy.menu.UploadSpeed.230400.upload.speed=230400 +watchy.menu.UploadSpeed.460800.linux=460800 +watchy.menu.UploadSpeed.460800.macosx=460800 +watchy.menu.UploadSpeed.460800.upload.speed=460800 +watchy.menu.UploadSpeed.512000.windows=512000 +watchy.menu.UploadSpeed.512000.upload.speed=512000 + +watchy.menu.DebugLevel.none=None +watchy.menu.DebugLevel.none.build.code_debug=0 +watchy.menu.DebugLevel.error=Error +watchy.menu.DebugLevel.error.build.code_debug=1 +watchy.menu.DebugLevel.warn=Warn +watchy.menu.DebugLevel.warn.build.code_debug=2 +watchy.menu.DebugLevel.info=Info +watchy.menu.DebugLevel.info.build.code_debug=3 +watchy.menu.DebugLevel.debug=Debug +watchy.menu.DebugLevel.debug.build.code_debug=4 +watchy.menu.DebugLevel.verbose=Verbose +watchy.menu.DebugLevel.verbose.build.code_debug=5 + +############################################################## + +deneyapkart1A.name=Deneyap Kart 1A + +deneyapkart1A.bootloader.tool=esptool_py +deneyapkart1A.bootloader.tool.default=esptool_py + +deneyapkart1A.upload.tool=esptool_py +deneyapkart1A.upload.tool.default=esptool_py +deneyapkart1A.upload.tool.network=esp_ota + +deneyapkart1A.upload.maximum_size=1310720 +deneyapkart1A.upload.maximum_data_size=327680 +deneyapkart1A.upload.wait_for_upload_port=true +deneyapkart1A.upload.flags= +deneyapkart1A.upload.extra_flags= + +deneyapkart1A.serial.disableDTR=true +deneyapkart1A.serial.disableRTS=true + +deneyapkart1A.build.tarch=xtensa +deneyapkart1A.build.bootloader_addr=0x1000 +deneyapkart1A.build.target=esp32 +deneyapkart1A.build.mcu=esp32 +deneyapkart1A.build.core=esp32 +deneyapkart1A.build.variant=deneyapkart1A +deneyapkart1A.build.board=DYDK1A + +deneyapkart1A.build.f_cpu=240000000L +deneyapkart1A.build.flash_size=4MB +deneyapkart1A.build.flash_freq=40m +deneyapkart1A.build.flash_mode=dio +deneyapkart1A.build.boot=dio +deneyapkart1A.build.partitions=default +deneyapkart1A.build.defines=-DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue -mfix-esp32-psram-cache-strategy=memw +deneyapkart1A.build.extra_libs= + +deneyapkart1A.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +deneyapkart1A.menu.PartitionScheme.default.build.partitions=default +deneyapkart1A.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +deneyapkart1A.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +deneyapkart1A.menu.PartitionScheme.default_8MB=8M Flash (3MB APP/1.5MB FAT) +deneyapkart1A.menu.PartitionScheme.default_8MB.build.partitions=default_8MB +deneyapkart1A.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 +deneyapkart1A.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS) +deneyapkart1A.menu.PartitionScheme.minimal.build.partitions=minimal +deneyapkart1A.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +deneyapkart1A.menu.PartitionScheme.no_ota.build.partitions=no_ota +deneyapkart1A.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +deneyapkart1A.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +deneyapkart1A.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +deneyapkart1A.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +deneyapkart1A.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +deneyapkart1A.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +deneyapkart1A.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +deneyapkart1A.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +deneyapkart1A.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +deneyapkart1A.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +deneyapkart1A.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +deneyapkart1A.menu.PartitionScheme.huge_app.build.partitions=huge_app +deneyapkart1A.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 +deneyapkart1A.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS) +deneyapkart1A.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +deneyapkart1A.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 +deneyapkart1A.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FAT) +deneyapkart1A.menu.PartitionScheme.fatflash.build.partitions=ffat +deneyapkart1A.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 +deneyapkart1A.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9MB FATFS) +deneyapkart1A.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB +deneyapkart1A.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 +deneyapkart1A.menu.PartitionScheme.rainmaker=RainMaker +deneyapkart1A.menu.PartitionScheme.rainmaker.build.partitions=rainmaker +deneyapkart1A.menu.PartitionScheme.rainmaker.upload.maximum_size=3145728 + +deneyapkart1A.menu.CPUFreq.240=240MHz (WiFi/BT) +deneyapkart1A.menu.CPUFreq.240.build.f_cpu=240000000L +deneyapkart1A.menu.CPUFreq.160=160MHz (WiFi/BT) +deneyapkart1A.menu.CPUFreq.160.build.f_cpu=160000000L +deneyapkart1A.menu.CPUFreq.80=80MHz (WiFi/BT) +deneyapkart1A.menu.CPUFreq.80.build.f_cpu=80000000L +deneyapkart1A.menu.CPUFreq.40=40MHz +deneyapkart1A.menu.CPUFreq.40.build.f_cpu=40000000L +deneyapkart1A.menu.CPUFreq.20=20MHz +deneyapkart1A.menu.CPUFreq.20.build.f_cpu=20000000L +deneyapkart1A.menu.CPUFreq.10=10MHz +deneyapkart1A.menu.CPUFreq.10.build.f_cpu=10000000L + +deneyapkart1A.menu.FlashMode.qio=QIO +deneyapkart1A.menu.FlashMode.qio.build.flash_mode=dio +deneyapkart1A.menu.FlashMode.qio.build.boot=qio +deneyapkart1A.menu.FlashMode.dio=DIO +deneyapkart1A.menu.FlashMode.dio.build.flash_mode=dio +deneyapkart1A.menu.FlashMode.dio.build.boot=dio +deneyapkart1A.menu.FlashMode.qout=QOUT +deneyapkart1A.menu.FlashMode.qout.build.flash_mode=dout +deneyapkart1A.menu.FlashMode.qout.build.boot=qout +deneyapkart1A.menu.FlashMode.dout=DOUT +deneyapkart1A.menu.FlashMode.dout.build.flash_mode=dout +deneyapkart1A.menu.FlashMode.dout.build.boot=dout + +deneyapkart1A.menu.FlashFreq.80=80MHz +deneyapkart1A.menu.FlashFreq.80.build.flash_freq=80m +deneyapkart1A.menu.FlashFreq.40=40MHz +deneyapkart1A.menu.FlashFreq.40.build.flash_freq=40m + +deneyapkart1A.menu.UploadSpeed.921600=921600 +deneyapkart1A.menu.UploadSpeed.921600.upload.speed=921600 +deneyapkart1A.menu.UploadSpeed.115200=115200 +deneyapkart1A.menu.UploadSpeed.115200.upload.speed=115200 +deneyapkart1A.menu.UploadSpeed.256000.windows=256000 +deneyapkart1A.menu.UploadSpeed.256000.upload.speed=256000 +deneyapkart1A.menu.UploadSpeed.230400.windows.upload.speed=256000 +deneyapkart1A.menu.UploadSpeed.230400=230400 +deneyapkart1A.menu.UploadSpeed.230400.upload.speed=230400 +deneyapkart1A.menu.UploadSpeed.460800.linux=460800 +deneyapkart1A.menu.UploadSpeed.460800.macosx=460800 +deneyapkart1A.menu.UploadSpeed.460800.upload.speed=460800 +deneyapkart1A.menu.UploadSpeed.512000.windows=512000 +deneyapkart1A.menu.UploadSpeed.512000.upload.speed=512000 + +deneyapkart1A.menu.DebugLevel.none=None +deneyapkart1A.menu.DebugLevel.none.build.code_debug=0 +deneyapkart1A.menu.DebugLevel.error=Error +deneyapkart1A.menu.DebugLevel.error.build.code_debug=1 +deneyapkart1A.menu.DebugLevel.warn=Warn +deneyapkart1A.menu.DebugLevel.warn.build.code_debug=2 +deneyapkart1A.menu.DebugLevel.info=Info +deneyapkart1A.menu.DebugLevel.info.build.code_debug=3 +deneyapkart1A.menu.DebugLevel.debug=Debug +deneyapkart1A.menu.DebugLevel.debug.build.code_debug=4 +deneyapkart1A.menu.DebugLevel.verbose=Verbose +deneyapkart1A.menu.DebugLevel.verbose.build.code_debug=5 + +############################################################## + +AirM2M_CORE_ESP32C3.name=AirM2M_CORE_ESP32C3 +AirM2M_CORE_ESP32C3.vid.0=0x303a +AirM2M_CORE_ESP32C3.pid.0=0x1001 + +AirM2M_CORE_ESP32C3.upload.tool=esptool_py +AirM2M_CORE_ESP32C3.upload.maximum_size=1310720 +AirM2M_CORE_ESP32C3.upload.maximum_data_size=327680 +AirM2M_CORE_ESP32C3.upload.flags= +AirM2M_CORE_ESP32C3.upload.extra_flags= +AirM2M_CORE_ESP32C3.upload.use_1200bps_touch=false +AirM2M_CORE_ESP32C3.upload.wait_for_upload_port=false + +AirM2M_CORE_ESP32C3.serial.disableDTR=false +AirM2M_CORE_ESP32C3.serial.disableRTS=false + +AirM2M_CORE_ESP32C3.build.tarch=riscv32 +AirM2M_CORE_ESP32C3.build.target=esp +AirM2M_CORE_ESP32C3.build.mcu=esp32c3 +AirM2M_CORE_ESP32C3.build.core=esp32 +AirM2M_CORE_ESP32C3.build.variant=AirM2M_CORE_ESP32C3 +AirM2M_CORE_ESP32C3.build.board=AirM2M_CORE_ESP32C3 +AirM2M_CORE_ESP32C3.build.bootloader_addr=0x0 + +AirM2M_CORE_ESP32C3.build.cdc_on_boot=0 +AirM2M_CORE_ESP32C3.build.f_cpu=160000000L +AirM2M_CORE_ESP32C3.build.flash_size=4MB +AirM2M_CORE_ESP32C3.build.flash_freq=80m +AirM2M_CORE_ESP32C3.build.flash_mode=dio +AirM2M_CORE_ESP32C3.build.boot=dio +AirM2M_CORE_ESP32C3.build.partitions=default +AirM2M_CORE_ESP32C3.build.defines= + +AirM2M_CORE_ESP32C3.menu.CDCOnBoot.default=Disabled +AirM2M_CORE_ESP32C3.menu.CDCOnBoot.default.build.cdc_on_boot=0 +AirM2M_CORE_ESP32C3.menu.CDCOnBoot.cdc=Enabled +AirM2M_CORE_ESP32C3.menu.CDCOnBoot.cdc.build.cdc_on_boot=1 + +AirM2M_CORE_ESP32C3.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +AirM2M_CORE_ESP32C3.menu.PartitionScheme.default.build.partitions=default +AirM2M_CORE_ESP32C3.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +AirM2M_CORE_ESP32C3.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +AirM2M_CORE_ESP32C3.menu.PartitionScheme.default_8MB=8M Flash (3MB APP/1.5MB FAT) +AirM2M_CORE_ESP32C3.menu.PartitionScheme.default_8MB.build.partitions=default_8MB +AirM2M_CORE_ESP32C3.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 +AirM2M_CORE_ESP32C3.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS) +AirM2M_CORE_ESP32C3.menu.PartitionScheme.minimal.build.partitions=minimal +AirM2M_CORE_ESP32C3.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +AirM2M_CORE_ESP32C3.menu.PartitionScheme.no_ota.build.partitions=no_ota +AirM2M_CORE_ESP32C3.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +AirM2M_CORE_ESP32C3.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +AirM2M_CORE_ESP32C3.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +AirM2M_CORE_ESP32C3.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +AirM2M_CORE_ESP32C3.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +AirM2M_CORE_ESP32C3.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +AirM2M_CORE_ESP32C3.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +AirM2M_CORE_ESP32C3.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +AirM2M_CORE_ESP32C3.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +AirM2M_CORE_ESP32C3.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +AirM2M_CORE_ESP32C3.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +AirM2M_CORE_ESP32C3.menu.PartitionScheme.huge_app.build.partitions=huge_app +AirM2M_CORE_ESP32C3.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 + +AirM2M_CORE_ESP32C3.menu.CPUFreq.160=160MHz (WiFi) +AirM2M_CORE_ESP32C3.menu.CPUFreq.160.build.f_cpu=160000000L +AirM2M_CORE_ESP32C3.menu.CPUFreq.80=80MHz (WiFi) +AirM2M_CORE_ESP32C3.menu.CPUFreq.80.build.f_cpu=80000000L +AirM2M_CORE_ESP32C3.menu.CPUFreq.40=40MHz +AirM2M_CORE_ESP32C3.menu.CPUFreq.40.build.f_cpu=40000000L +AirM2M_CORE_ESP32C3.menu.CPUFreq.20=20MHz +AirM2M_CORE_ESP32C3.menu.CPUFreq.20.build.f_cpu=20000000L +AirM2M_CORE_ESP32C3.menu.CPUFreq.10=10MHz +AirM2M_CORE_ESP32C3.menu.CPUFreq.10.build.f_cpu=10000000L + +AirM2M_CORE_ESP32C3.menu.FlashFreq.80=80MHz +AirM2M_CORE_ESP32C3.menu.FlashFreq.80.build.flash_freq=80m +AirM2M_CORE_ESP32C3.menu.FlashFreq.40=40MHz +AirM2M_CORE_ESP32C3.menu.FlashFreq.40.build.flash_freq=40m + +AirM2M_CORE_ESP32C3.menu.UploadSpeed.921600=921600 +AirM2M_CORE_ESP32C3.menu.UploadSpeed.921600.upload.speed=921600 +AirM2M_CORE_ESP32C3.menu.UploadSpeed.115200=115200 +AirM2M_CORE_ESP32C3.menu.UploadSpeed.115200.upload.speed=115200 +AirM2M_CORE_ESP32C3.menu.UploadSpeed.1152000=1152000 +AirM2M_CORE_ESP32C3.menu.UploadSpeed.1152000.upload.speed=1152000 + + +AirM2M_CORE_ESP32C3.menu.DebugLevel.none=None +AirM2M_CORE_ESP32C3.menu.DebugLevel.none.build.code_debug=0 +AirM2M_CORE_ESP32C3.menu.DebugLevel.error=Error +AirM2M_CORE_ESP32C3.menu.DebugLevel.error.build.code_debug=1 +AirM2M_CORE_ESP32C3.menu.DebugLevel.warn=Warn +AirM2M_CORE_ESP32C3.menu.DebugLevel.warn.build.code_debug=2 +AirM2M_CORE_ESP32C3.menu.DebugLevel.info=Info +AirM2M_CORE_ESP32C3.menu.DebugLevel.info.build.code_debug=3 +AirM2M_CORE_ESP32C3.menu.DebugLevel.debug=Debug +AirM2M_CORE_ESP32C3.menu.DebugLevel.debug.build.code_debug=4 +AirM2M_CORE_ESP32C3.menu.DebugLevel.verbose=Verbose +AirM2M_CORE_ESP32C3.menu.DebugLevel.verbose.build.code_debug=5 + +############################################################# diff --git a/component.mk b/component.mk deleted file mode 100644 index 4b85ee4f217..00000000000 --- a/component.mk +++ /dev/null @@ -1,36 +0,0 @@ -ARDUINO_ALL_LIBRARIES := $(patsubst $(COMPONENT_PATH)/libraries/%,%,$(wildcard $(COMPONENT_PATH)/libraries/*)) - -# Macro returns non-empty if Arduino library $(1) should be included in the build -# (either because selective compilation is of, or this library is enabled -define ARDUINO_LIBRARY_ENABLED -$(if $(CONFIG_ARDUINO_SELECTIVE_COMPILATION),$(CONFIG_ARDUINO_SELECTIVE_$(1)),y) -endef - -ARDUINO_ENABLED_LIBRARIES := $(foreach LIBRARY,$(sort $(ARDUINO_ALL_LIBRARIES)),$(if $(call ARDUINO_LIBRARY_ENABLED,$(LIBRARY)),$(LIBRARY))) - -$(info Arduino libraries in build: $(ARDUINO_ENABLED_LIBRARIES)) - -# Expand all subdirs under $(1) -define EXPAND_SUBDIRS -$(sort $(dir $(wildcard $(1)/* $(1)/*/* $(1)/*/*/* $(1)/*/*/*/* $(1)/*/*/*/*/*))) -endef - -# Macro returns SRCDIRS for library -define ARDUINO_LIBRARY_GET_SRCDIRS - $(if $(wildcard $(COMPONENT_PATH)/libraries/$(1)/src/.), \ - $(call EXPAND_SUBDIRS,$(COMPONENT_PATH)/libraries/$(1)/src), \ - $(filter-out $(call EXPAND_SUBDIRS,$(COMPONENT_PATH)/libraries/$(1)/examples), \ - $(call EXPAND_SUBDIRS,$(COMPONENT_PATH)/libraries/$(1)) \ - ) \ - ) -endef - -# Make a list of all srcdirs in enabled libraries -ARDUINO_LIBRARY_SRCDIRS := $(patsubst $(COMPONENT_PATH)/%,%,$(foreach LIBRARY,$(ARDUINO_ENABLED_LIBRARIES),$(call ARDUINO_LIBRARY_GET_SRCDIRS,$(LIBRARY)))) - -#$(info Arduino libraries src dirs: $(ARDUINO_LIBRARY_SRCDIRS)) - -COMPONENT_ADD_INCLUDEDIRS := cores/esp32 variants/esp32 $(ARDUINO_LIBRARY_SRCDIRS) -COMPONENT_PRIV_INCLUDEDIRS := cores/esp32/libb64 -COMPONENT_SRCDIRS := cores/esp32/libb64 cores/esp32 variants/esp32 $(ARDUINO_LIBRARY_SRCDIRS) -CXXFLAGS += -fno-rtti diff --git a/cores/esp32/Arduino.h b/cores/esp32/Arduino.h index 8014d3c8342..c8be9222b39 100644 --- a/cores/esp32/Arduino.h +++ b/cores/esp32/Arduino.h @@ -166,6 +166,7 @@ void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val); #include "Udp.h" #include "HardwareSerial.h" #include "Esp.h" +#include "esp32/spiram.h" using std::abs; using std::isinf; @@ -181,7 +182,10 @@ uint16_t makeWord(uint8_t h, uint8_t l); size_t getArduinoLoopTaskStackSize(void); #define SET_LOOP_TASK_STACK_SIZE(sz) size_t getArduinoLoopTaskStackSize() { return sz;} - + +// allows user to bypass esp_spiram_test() +#define BYPASS_SPIRAM_TEST(bypass) bool testSPIRAM(void) { if (bypass) return true; else return esp_spiram_test(); } + unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); @@ -191,6 +195,10 @@ extern "C" void configTime(long gmtOffset_sec, int daylightOffset_sec, extern "C" void configTzTime(const char* tz, const char* server1, const char* server2 = nullptr, const char* server3 = nullptr); +void setToneChannel(uint8_t channel = 0); +void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0); +void noTone(uint8_t _pin); + // WMath prototypes long random(long); #endif /* __cplusplus */ diff --git a/cores/esp32/Esp.cpp b/cores/esp32/Esp.cpp index 49126b881a5..6cca85ac64c 100644 --- a/cores/esp32/Esp.cpp +++ b/cores/esp32/Esp.cpp @@ -40,6 +40,10 @@ extern "C" { #include "esp32s2/rom/spi_flash.h" #include "soc/efuse_reg.h" #define ESP_FLASH_IMAGE_BASE 0x1000 +#elif CONFIG_IDF_TARGET_ESP32S3 +#include "esp32s3/rom/spi_flash.h" +#include "soc/efuse_reg.h" +#define ESP_FLASH_IMAGE_BASE 0x0000 // Esp32s3 is located at 0x0000 #elif CONFIG_IDF_TARGET_ESP32C3 #include "esp32c3/rom/spi_flash.h" #define ESP_FLASH_IMAGE_BASE 0x0000 // Esp32c3 is located at 0x0000 diff --git a/cores/esp32/HWCDC.cpp b/cores/esp32/HWCDC.cpp index 3f6927dda27..8912fed9330 100644 --- a/cores/esp32/HWCDC.cpp +++ b/cores/esp32/HWCDC.cpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. #include "USB.h" -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 #include "esp32-hal.h" #include "HWCDC.h" @@ -167,19 +167,21 @@ void HWCDC::begin(unsigned long baud) setRxBufferSize(256);//default if not preset setTxBufferSize(256);//default if not preset - usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT | USB_SERIAL_JTAG_INTR_BUS_RESET); + usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_LL_INTR_MASK); + usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_LL_INTR_MASK); usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT | USB_SERIAL_JTAG_INTR_BUS_RESET); if(!intr_handle && esp_intr_alloc(ETS_USB_SERIAL_JTAG_INTR_SOURCE, 0, hw_cdc_isr_handler, NULL, &intr_handle) != ESP_OK){ isr_log_e("HW USB CDC failed to init interrupts"); end(); return; } + usb_serial_jtag_ll_txfifo_flush(); } void HWCDC::end() { //Disable tx/rx interrupt. - usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT | USB_SERIAL_JTAG_INTR_BUS_RESET); + usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_LL_INTR_MASK); esp_intr_free(intr_handle); intr_handle = NULL; if(tx_lock != NULL) { @@ -379,10 +381,12 @@ void HWCDC::setDebugOutput(bool en) } } -#if ARDUINO_HW_CDC_ON_BOOT //Serial used for USB CDC +#if ARDUINO_USB_MODE +#if ARDUINO_USB_CDC_ON_BOOT//Serial used for USB CDC HWCDC Serial; #else HWCDC USBSerial; #endif +#endif #endif /* CONFIG_TINYUSB_CDC_ENABLED */ diff --git a/cores/esp32/HWCDC.h b/cores/esp32/HWCDC.h index 81a334b76b9..5878ad0377f 100644 --- a/cores/esp32/HWCDC.h +++ b/cores/esp32/HWCDC.h @@ -14,7 +14,7 @@ #pragma once #include "sdkconfig.h" -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 #include #include "esp_event.h" @@ -98,10 +98,12 @@ class HWCDC: public Stream }; -#if ARDUINO_HW_CDC_ON_BOOT //Serial used for USB CDC +#if ARDUINO_USB_MODE +#if ARDUINO_USB_CDC_ON_BOOT//Serial used for USB CDC extern HWCDC Serial; #else extern HWCDC USBSerial; #endif +#endif #endif /* CONFIG_IDF_TARGET_ESP32C3 */ diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index aed14b19c72..323482a6bbf 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -6,11 +6,13 @@ #include "pins_arduino.h" #include "HardwareSerial.h" #include "soc/soc_caps.h" +#include "driver/uart.h" +#include "freertos/queue.h" #ifndef SOC_RX0 #if CONFIG_IDF_TARGET_ESP32 #define SOC_RX0 3 -#elif CONFIG_IDF_TARGET_ESP32S2 +#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 #define SOC_RX0 44 #elif CONFIG_IDF_TARGET_ESP32C3 #define SOC_RX0 20 @@ -20,7 +22,7 @@ #ifndef SOC_TX0 #if CONFIG_IDF_TARGET_ESP32 #define SOC_TX0 1 -#elif CONFIG_IDF_TARGET_ESP32S2 +#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 #define SOC_TX0 43 #elif CONFIG_IDF_TARGET_ESP32C3 #define SOC_TX0 21 @@ -39,6 +41,8 @@ void serialEvent(void) {} #define RX1 18 #elif CONFIG_IDF_TARGET_ESP32C3 #define RX1 18 +#elif CONFIG_IDF_TARGET_ESP32S3 +#define RX1 15 #endif #endif @@ -49,6 +53,8 @@ void serialEvent(void) {} #define TX1 17 #elif CONFIG_IDF_TARGET_ESP32C3 #define TX1 19 +#elif CONFIG_IDF_TARGET_ESP32S3 +#define TX1 16 #endif #endif @@ -60,12 +66,16 @@ void serialEvent1(void) {} #ifndef RX2 #if CONFIG_IDF_TARGET_ESP32 #define RX2 16 +#elif CONFIG_IDF_TARGET_ESP32S3 +#define RX2 19 #endif #endif #ifndef TX2 #if CONFIG_IDF_TARGET_ESP32 #define TX2 17 +#elif CONFIG_IDF_TARGET_ESP32S3 +#define TX2 20 #endif #endif @@ -76,8 +86,6 @@ void serialEvent2(void) {} #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL) #if ARDUINO_USB_CDC_ON_BOOT //Serial used for USB CDC HardwareSerial Serial0(0); -#elif ARDUINO_HW_CDC_ON_BOOT -HardwareSerial Serial0(0); #else HardwareSerial Serial(0); #endif @@ -92,8 +100,6 @@ void serialEventRun(void) { #if ARDUINO_USB_CDC_ON_BOOT //Serial used for USB CDC if(Serial0.available()) serialEvent(); -#elif ARDUINO_HW_CDC_ON_BOOT - if(Serial0.available()) serialEvent(); #else if(Serial.available()) serialEvent(); #endif @@ -106,8 +112,167 @@ void serialEventRun(void) } #endif +#if !CONFIG_DISABLE_HAL_LOCKS +#define HSERIAL_MUTEX_LOCK() do {} while (xSemaphoreTake(_lock, portMAX_DELAY) != pdPASS) +#define HSERIAL_MUTEX_UNLOCK() xSemaphoreGive(_lock) +#else +#define HSERIAL_MUTEX_LOCK() +#define HSERIAL_MUTEX_UNLOCK() +#endif + +HardwareSerial::HardwareSerial(int uart_nr) : +_uart_nr(uart_nr), +_uart(NULL), +_rxBufferSize(256), +_txBufferSize(0), +_onReceiveCB(NULL), +_onReceiveErrorCB(NULL), +_onReceiveTimeout(true), +_rxTimeout(10), +_eventTask(NULL) +#if !CONFIG_DISABLE_HAL_LOCKS + ,_lock(NULL) +#endif +{ +#if !CONFIG_DISABLE_HAL_LOCKS + if(_lock == NULL){ + _lock = xSemaphoreCreateMutex(); + if(_lock == NULL){ + log_e("xSemaphoreCreateMutex failed"); + return; + } + } +#endif +} + +HardwareSerial::~HardwareSerial() +{ + end(); +#if !CONFIG_DISABLE_HAL_LOCKS + if(_lock != NULL){ + vSemaphoreDelete(_lock); + } +#endif +} + + +void HardwareSerial::_createEventTask(void *args) +{ + // Creating UART event Task + xTaskCreate(_uartEventTask, "uart_event_task", 2048, this, configMAX_PRIORITIES - 1, &_eventTask); + if (_eventTask == NULL) { + log_e(" -- UART%d Event Task not Created!", _uart_nr); + } +} + +void HardwareSerial::_destroyEventTask(void) +{ + if (_eventTask != NULL) { + vTaskDelete(_eventTask); + _eventTask = NULL; + } +} -HardwareSerial::HardwareSerial(int uart_nr) : _uart_nr(uart_nr), _uart(NULL), _rxBufferSize(256) {} +void HardwareSerial::onReceiveError(OnReceiveErrorCb function) +{ + HSERIAL_MUTEX_LOCK(); + // function may be NULL to cancel onReceive() from its respective task + _onReceiveErrorCB = function; + // this can be called after Serial.begin(), therefore it shall create the event task + if (function != NULL && _uart != NULL && _eventTask == NULL) { + _createEventTask(this); + } + HSERIAL_MUTEX_UNLOCK(); +} + +void HardwareSerial::onReceive(OnReceiveCb function, bool onlyOnTimeout) +{ + HSERIAL_MUTEX_LOCK(); + // function may be NULL to cancel onReceive() from its respective task + _onReceiveCB = function; + // When Rx timeout is Zero (disabled), there is only one possible option that is callback when FIFO reaches 120 bytes + _onReceiveTimeout = _rxTimeout > 0 ? onlyOnTimeout : false; + + // this can be called after Serial.begin(), therefore it shall create the event task + if (function != NULL && _uart != NULL && _eventTask == NULL) { + _createEventTask(this); // Create event task + } + HSERIAL_MUTEX_UNLOCK(); +} + +// timout is calculates in time to receive UART symbols at the UART baudrate. +// the estimation is about 11 bits per symbol (SERIAL_8N1) +void HardwareSerial::setRxTimeout(uint8_t symbols_timeout) +{ + HSERIAL_MUTEX_LOCK(); + + // Zero disables timeout, thus, onReceive callback will only be called when RX FIFO reaches 120 bytes + // Any non-zero value will activate onReceive callback based on UART baudrate with about 11 bits per symbol + _rxTimeout = symbols_timeout; + if (!symbols_timeout) _onReceiveTimeout = false; // only when RX timeout is disabled, we also must disable this flag + + if(_uart != NULL) uart_set_rx_timeout(_uart_nr, _rxTimeout); // Set new timeout + + HSERIAL_MUTEX_UNLOCK(); +} + +void HardwareSerial::eventQueueReset() +{ + QueueHandle_t uartEventQueue = NULL; + if (_uart == NULL) { + return; + } + uartGetEventQueue(_uart, &uartEventQueue); + if (uartEventQueue != NULL) { + xQueueReset(uartEventQueue); + } +} + +void HardwareSerial::_uartEventTask(void *args) +{ + HardwareSerial *uart = (HardwareSerial *)args; + uart_event_t event; + QueueHandle_t uartEventQueue = NULL; + uartGetEventQueue(uart->_uart, &uartEventQueue); + if (uartEventQueue != NULL) { + for(;;) { + //Waiting for UART event. + if(xQueueReceive(uartEventQueue, (void * )&event, (portTickType)portMAX_DELAY)) { + switch(event.type) { + case UART_DATA: + if(uart->_onReceiveCB && uart->available() > 0 && + ((uart->_onReceiveTimeout && event.timeout_flag) || !uart->_onReceiveTimeout) ) + uart->_onReceiveCB(); + break; + case UART_FIFO_OVF: + log_w("UART%d FIFO Overflow. Consider adding Hardware Flow Control to your Application.", uart->_uart_nr); + if(uart->_onReceiveErrorCB) uart->_onReceiveErrorCB(UART_FIFO_OVF_ERROR); + break; + case UART_BUFFER_FULL: + log_w("UART%d Buffer Full. Consider increasing your buffer size of your Application.", uart->_uart_nr); + if(uart->_onReceiveErrorCB) uart->_onReceiveErrorCB(UART_BUFFER_FULL_ERROR); + break; + case UART_BREAK: + log_w("UART%d RX break.", uart->_uart_nr); + if(uart->_onReceiveErrorCB) uart->_onReceiveErrorCB(UART_BREAK_ERROR); + break; + case UART_PARITY_ERR: + log_w("UART%d parity error.", uart->_uart_nr); + if(uart->_onReceiveErrorCB) uart->_onReceiveErrorCB(UART_PARITY_ERROR); + break; + case UART_FRAME_ERR: + log_w("UART%d frame error.", uart->_uart_nr); + if(uart->_onReceiveErrorCB) uart->_onReceiveErrorCB(UART_FRAME_ERROR); + break; + default: + log_w("UART%d unknown event type %d.", uart->_uart_nr, event.type); + break; + } + } + } + } + vTaskDelete(NULL); +} void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t txPin, bool invert, unsigned long timeout_ms, uint8_t rxfifo_full_thrhd) { @@ -115,29 +280,54 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in log_e("Serial number is invalid, please use numers from 0 to %u", SOC_UART_NUM - 1); return; } + +#if !CONFIG_DISABLE_HAL_LOCKS + if(_lock == NULL){ + log_e("MUTEX Lock failed. Can't begin."); + return; + } +#endif + + HSERIAL_MUTEX_LOCK(); + // First Time or after end() --> set default Pins + if (!uartIsDriverInstalled(_uart)) { + switch (_uart_nr) { + case UART_NUM_0: + if (rxPin < 0 && txPin < 0) { + rxPin = SOC_RX0; + txPin = SOC_TX0; + } + break; +#if SOC_UART_NUM > 1 // may save some flash bytes... + case UART_NUM_1: + if (rxPin < 0 && txPin < 0) { + rxPin = RX1; + txPin = TX1; + } + break; +#endif +#if SOC_UART_NUM > 2 // may save some flash bytes... + case UART_NUM_2: + if (rxPin < 0 && txPin < 0) { + rxPin = RX2; + txPin = TX2; + } + break; +#endif + default: + log_e("Bad UART Number"); + return; + } + } + if(_uart) { // in this case it is a begin() over a previous begin() - maybe to change baud rate // thus do not disable debug output end(false); } - if(_uart_nr == 0 && rxPin < 0 && txPin < 0) { - rxPin = SOC_RX0; - txPin = SOC_TX0; - } -#if SOC_UART_NUM > 1 - if(_uart_nr == 1 && rxPin < 0 && txPin < 0) { - rxPin = RX1; - txPin = TX1; - } -#endif -#if SOC_UART_NUM > 2 - if(_uart_nr == 2 && rxPin < 0 && txPin < 0) { - rxPin = RX2; - txPin = TX2; - } -#endif - _uart = uartBegin(_uart_nr, baud ? baud : 9600, config, rxPin, txPin, _rxBufferSize, invert, rxfifo_full_thrhd); + // IDF UART driver keeps Pin setting on restarting. Negative Pin number will keep it unmodified. + _uart = uartBegin(_uart_nr, baud ? baud : 9600, config, rxPin, txPin, _rxBufferSize, _txBufferSize, invert, rxfifo_full_thrhd); if (!baud) { // using baud rate as zero, forces it to try to detect the current baud rate in place uartStartDetectBaudrate(_uart); @@ -151,12 +341,24 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in if(detectedBaudRate) { delay(100); // Give some time... - _uart = uartBegin(_uart_nr, detectedBaudRate, config, rxPin, txPin, _rxBufferSize, invert, rxfifo_full_thrhd); + _uart = uartBegin(_uart_nr, detectedBaudRate, config, rxPin, txPin, _rxBufferSize, _txBufferSize, invert, rxfifo_full_thrhd); } else { log_e("Could not detect baudrate. Serial data at the port must be present within the timeout for detection to be possible"); _uart = NULL; } } + // create a task to deal with Serial Events when, for example, calling begin() twice to change the baudrate, + // or when setting the callback before calling begin() + if (_uart != NULL && (_onReceiveCB != NULL || _onReceiveErrorCB != NULL) && _eventTask == NULL) { + _createEventTask(this); + } + + // Set UART RX timeout + if (_uart != NULL) { + uart_set_rx_timeout(_uart_nr, _rxTimeout); + } + + HSERIAL_MUTEX_UNLOCK(); } void HardwareSerial::updateBaudRate(unsigned long baud) @@ -164,14 +366,21 @@ void HardwareSerial::updateBaudRate(unsigned long baud) uartSetBaudRate(_uart, baud); } -void HardwareSerial::end(bool turnOffDebug) +void HardwareSerial::end(bool fullyTerminate) { - if(turnOffDebug && uartGetDebug() == _uart_nr) { - uartSetDebug(0); + // default Serial.end() will completely disable HardwareSerial, + // including any tasks or debug message channel (log_x()) - but not for IDF log messages! + if(fullyTerminate) { + _onReceiveCB = NULL; + _onReceiveErrorCB = NULL; + if (uartGetDebug() == _uart_nr) { + uartSetDebug(0); + } } delay(10); uartEnd(_uart); _uart = 0; + _destroyEventTask(); } void HardwareSerial::setDebugOutput(bool en) @@ -267,9 +476,16 @@ void HardwareSerial::setRxInvert(bool invert) uartSetRxInvert(_uart, invert); } -void HardwareSerial::setPins(uint8_t rxPin, uint8_t txPin) +// negative Pin value will keep it unmodified +void HardwareSerial::setPins(int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin) { - uartSetPins(_uart, rxPin, txPin); + uartSetPins(_uart, rxPin, txPin, ctsPin, rtsPin); +} + +// Enables or disables Hardware Flow Control using RTS and/or CTS pins (must use setAllPins() before) +void HardwareSerial::setHwFlowCtrlMode(uint8_t mode, uint8_t threshold) +{ + uartSetHwFlowCtrlMode(_uart, mode, threshold); } size_t HardwareSerial::setRxBufferSize(size_t new_size) { @@ -280,10 +496,26 @@ size_t HardwareSerial::setRxBufferSize(size_t new_size) { } if (new_size <= SOC_UART_FIFO_LEN) { - log_e("RX Buffer must be higher than %d.\n", SOC_UART_FIFO_LEN); + log_e("RX Buffer must be higher than %d.\n", SOC_UART_FIFO_LEN); // ESP32, S2, S3 and C3 means higher than 128 return 0; } _rxBufferSize = new_size; return _rxBufferSize; } + +size_t HardwareSerial::setTxBufferSize(size_t new_size) { + + if (_uart) { + log_e("TX Buffer can't be resized when Serial is already running.\n"); + return 0; + } + + if (new_size <= SOC_UART_FIFO_LEN) { + log_e("TX Buffer must be higher than %d.\n", SOC_UART_FIFO_LEN); // ESP32, S2, S3 and C3 means higher than 128 + return 0; + } + + _txBufferSize = new_size; + return _txBufferSize; +} diff --git a/cores/esp32/HardwareSerial.h b/cores/esp32/HardwareSerial.h index 40282361bf5..b7aafb68520 100644 --- a/cores/esp32/HardwareSerial.h +++ b/cores/esp32/HardwareSerial.h @@ -46,19 +46,61 @@ #define HardwareSerial_h #include - +#include #include "Stream.h" #include "esp32-hal.h" #include "soc/soc_caps.h" #include "HWCDC.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/semphr.h" + +typedef enum { + UART_BREAK_ERROR, + UART_BUFFER_FULL_ERROR, + UART_FIFO_OVF_ERROR, + UART_FRAME_ERROR, + UART_PARITY_ERROR +} hardwareSerial_error_t; + +typedef std::function OnReceiveCb; +typedef std::function OnReceiveErrorCb; + class HardwareSerial: public Stream { public: HardwareSerial(int uart_nr); - + ~HardwareSerial(); + + // setRxTimeout sets the timeout after which onReceive callback will be called (after receiving data, it waits for this time of UART rx inactivity to call the callback fnc) + // param symbols_timeout defines a timeout threshold in uart symbol periods. Setting 0 symbol timeout disables the callback call by timeout. + // Maximum timeout setting is calculacted automatically by IDF. If set above the maximum, it is ignored and an error is printed on Serial0 (check console). + // Examples: Maximum for 11 bits symbol is 92 (SERIAL_8N2, SERIAL_8E1, SERIAL_8O1, etc), Maximum for 10 bits symbol is 101 (SERIAL_8N1). + // For example symbols_timeout=1 defines a timeout equal to transmission time of one symbol (~11 bit) on current baudrate. + // For a baudrate of 9600, SERIAL_8N1 (10 bit symbol) and symbols_timeout = 3, the timeout would be 3 / (9600 / 10) = 3.125 ms + void setRxTimeout(uint8_t symbols_timeout); + + // onReceive will setup a callback that will be called whenever an UART interruption occurs (UART_INTR_RXFIFO_FULL or UART_INTR_RXFIFO_TOUT) + // UART_INTR_RXFIFO_FULL interrupt triggers at UART_FULL_THRESH_DEFAULT bytes received (defined as 120 bytes by default in IDF) + // UART_INTR_RXFIFO_TOUT interrupt triggers at UART_TOUT_THRESH_DEFAULT symbols passed without any reception (defined as 10 symbos by default in IDF) + // onlyOnTimeout parameter will define how onReceive will behave: + // Default: true -- The callback will only be called when RX Timeout happens. + // Whole stream of bytes will be ready for being read on the callback function at once. + // This option may lead to Rx Overflow depending on the Rx Buffer Size and number of bytes received in the streaming + // false -- The callback will be called when FIFO reaches 120 bytes and also on RX Timeout. + // The stream of incommig bytes will be "split" into blocks of 120 bytes on each callback. + // This option avoid any sort of Rx Overflow, but leaves the UART packet reassembling work to the Application. + void onReceive(OnReceiveCb function, bool onlyOnTimeout = true); + + // onReceive will be called on error events (see hardwareSerial_error_t) + void onReceiveError(OnReceiveErrorCb function); + + // eventQueueReset clears all events in the queue (the events that trigger onReceive and onReceiveError) - maybe usefull in some use cases + void eventQueueReset(); + void begin(unsigned long baud, uint32_t config=SERIAL_8N1, int8_t rxPin=-1, int8_t txPin=-1, bool invert=false, unsigned long timeout_ms = 20000UL, uint8_t rxfifo_full_thrhd = 112); - void end(bool turnOffDebug = true); + void end(bool fullyTerminate = true); void updateBaudRate(unsigned long baud); int available(void); int availableForWrite(void); @@ -103,13 +145,34 @@ class HardwareSerial: public Stream void setDebugOutput(bool); void setRxInvert(bool); - void setPins(uint8_t rxPin, uint8_t txPin); + + // Negative Pin Number will keep it unmodified, thus this function can set individual pins + // SetPins shall be called after Serial begin() + void setPins(int8_t rxPin, int8_t txPin, int8_t ctsPin = -1, int8_t rtsPin = -1); + // Enables or disables Hardware Flow Control using RTS and/or CTS pins (must use setAllPins() before) + void setHwFlowCtrlMode(uint8_t mode = HW_FLOWCTRL_CTS_RTS, uint8_t threshold = 64); // 64 is half FIFO Length + size_t setRxBufferSize(size_t new_size); + size_t setTxBufferSize(size_t new_size); protected: int _uart_nr; uart_t* _uart; size_t _rxBufferSize; + size_t _txBufferSize; + OnReceiveCb _onReceiveCB; + OnReceiveErrorCb _onReceiveErrorCB; + // _onReceive and _rxTimeout have be consistent when timeout is disabled + bool _onReceiveTimeout; + uint8_t _rxTimeout; + TaskHandle_t _eventTask; +#if !CONFIG_DISABLE_HAL_LOCKS + SemaphoreHandle_t _lock; +#endif + + void _createEventTask(void *args); + void _destroyEventTask(void); + static void _uartEventTask(void *args); }; extern void serialEventRun(void) __attribute__((weak)); @@ -119,10 +182,10 @@ extern void serialEventRun(void) __attribute__((weak)); #define ARDUINO_USB_CDC_ON_BOOT 0 #endif #if ARDUINO_USB_CDC_ON_BOOT //Serial used for USB CDC +#if !ARDUINO_USB_MODE #include "USB.h" #include "USBCDC.h" -extern HardwareSerial Serial0; -#elif ARDUINO_HW_CDC_ON_BOOT +#endif extern HardwareSerial Serial0; #else extern HardwareSerial Serial; diff --git a/cores/esp32/IPAddress.cpp b/cores/esp32/IPAddress.cpp index cabfdf32d26..0575363f254 100644 --- a/cores/esp32/IPAddress.cpp +++ b/cores/esp32/IPAddress.cpp @@ -120,3 +120,6 @@ bool IPAddress::fromString(const char *address) _address.bytes[3] = acc; return true; } + +// declared one time - as external in IPAddress.h +IPAddress INADDR_NONE(0, 0, 0, 0); diff --git a/cores/esp32/IPAddress.h b/cores/esp32/IPAddress.h index aa1d10cee29..3bedd4f8749 100644 --- a/cores/esp32/IPAddress.h +++ b/cores/esp32/IPAddress.h @@ -91,6 +91,6 @@ class IPAddress: public Printable friend class DNSClient; }; -const IPAddress INADDR_NONE(0, 0, 0, 0); - +// changed to extern because const declaration creates copies in BSS of INADDR_NONE for each CPP unit that includes it +extern IPAddress INADDR_NONE; #endif diff --git a/cores/esp32/Print.h b/cores/esp32/Print.h index 4493d4f819f..7aa1a2d00a2 100644 --- a/cores/esp32/Print.h +++ b/cores/esp32/Print.h @@ -108,6 +108,9 @@ class Print size_t println(const Printable&); size_t println(struct tm * timeinfo, const char * format = NULL); size_t println(void); + + virtual void flush() { /* Empty implementation for backward compatibility */ } + }; #endif diff --git a/cores/esp32/Stream.h b/cores/esp32/Stream.h index 2debee7e4f9..8df8226d730 100644 --- a/cores/esp32/Stream.h +++ b/cores/esp32/Stream.h @@ -48,7 +48,6 @@ class Stream: public Print virtual int available() = 0; virtual int read() = 0; virtual int peek() = 0; - virtual void flush() = 0; Stream():_startMillis(0) { diff --git a/cores/esp32/Tone.cpp b/cores/esp32/Tone.cpp new file mode 100644 index 00000000000..ca69c10c13b --- /dev/null +++ b/cores/esp32/Tone.cpp @@ -0,0 +1,131 @@ +#include +#include "esp32-hal-ledc.h" +#include "freertos/task.h" +#include "freertos/queue.h" +#include "freertos/semphr.h" + +static TaskHandle_t _tone_task = NULL; +static QueueHandle_t _tone_queue = NULL; +static uint8_t _channel = 0; + +typedef enum{ + TONE_START, + TONE_END, + TONE_SET_CHANNEL +} tone_cmd_t; + +typedef struct{ + tone_cmd_t tone_cmd; + uint8_t pin; + unsigned int frequency; + unsigned long duration; + uint8_t channel; +} tone_msg_t; + +static void tone_task(void*){ + tone_msg_t tone_msg; + while(1){ + xQueueReceive(_tone_queue, &tone_msg, portMAX_DELAY); + switch(tone_msg.tone_cmd){ + case TONE_START: + log_d("Task received from queue TONE_START: _pin=%d, frequency=%u Hz, duration=%u ms", tone_msg.pin, tone_msg.frequency, tone_msg.duration); + + log_d("Setup LED controll on channel %d", _channel); + // ledcSetup(_channel, tone_msg.frequency, 11); + // ledcAttachPin(tone_msg.pin, _channel); + // ledcWrite(_channel, 1024); + ledcWriteTone(_channel, tone_msg.frequency); + ledcAttachPin(tone_msg.pin, _channel); + + if(tone_msg.duration){ + delay(tone_msg.duration); + ledcDetachPin(tone_msg.pin); + ledcWriteTone(_channel, 0); + } + break; + + case TONE_END: + log_d("Task received from queue TONE_END: pin=%d", tone_msg.pin); + ledcDetachPin(tone_msg.pin); + ledcWriteTone(_channel, 0); + break; + + case TONE_SET_CHANNEL: + log_d("Task received from queue TONE_SET_CHANNEL: channel=%d", tone_msg.channel); + _channel = tone_msg.channel; + break; + + default: ; // do nothing + } // switch + } // infinite loop +} + +static int tone_init(){ + if(_tone_queue == NULL){ + log_v("Creating tone queue"); + _tone_queue = xQueueCreate(128, sizeof(tone_msg_t)); + if(_tone_queue == NULL){ + log_e("Could not create tone queue"); + return 0; // ERR + } + log_v("Tone queue created"); + } + + if(_tone_task == NULL){ + log_v("Creating tone task"); + xTaskCreate( + tone_task, // Function to implement the task + "toneTask", // Name of the task + 3500, // Stack size in words + NULL, // Task input parameter + 1, // Priority of the task + &_tone_task // Task handle. + ); + if(_tone_task == NULL){ + log_e("Could not create tone task"); + return 0; // ERR + } + log_v("Tone task created"); + } + return 1; // OK +} + +void setToneChannel(uint8_t channel){ + log_d("channel=%d", channel); + if(tone_init()){ + tone_msg_t tone_msg = { + .tone_cmd = TONE_SET_CHANNEL, + .channel = channel + }; + xQueueSend(_tone_queue, &tone_msg, portMAX_DELAY); + } +} + +void noTone(uint8_t _pin){ + log_d("noTone was called"); + if(tone_init()){ + tone_msg_t tone_msg = { + .tone_cmd = TONE_END, + .pin = _pin + }; + xQueueSend(_tone_queue, &tone_msg, portMAX_DELAY); + } +} + +// parameters: +// _pin - pin number which will output the signal +// frequency - PWM frequency in Hz +// duration - time in ms - how long will the signal be outputted. +// If not provided, or 0 you must manually call noTone to end output +void tone(uint8_t _pin, unsigned int frequency, unsigned long duration){ + log_d("_pin=%d, frequency=%u Hz, duration=%u ms", _pin, frequency, duration); + if(tone_init()){ + tone_msg_t tone_msg = { + .tone_cmd = TONE_START, + .pin = _pin, + .frequency = frequency, + .duration = duration + }; + xQueueSend(_tone_queue, &tone_msg, portMAX_DELAY); + } +} diff --git a/cores/esp32/USB.cpp b/cores/esp32/USB.cpp index 5bf78b3bc27..a1fe50944db 100644 --- a/cores/esp32/USB.cpp +++ b/cores/esp32/USB.cpp @@ -19,6 +19,7 @@ #include "esp32-hal.h" #include "esp32-hal-tinyusb.h" #include "common/tusb_common.h" +#include "StreamString.h" #ifndef USB_VID #define USB_VID USB_ESPRESSIF_VID @@ -33,8 +34,12 @@ #define USB_PRODUCT ARDUINO_BOARD #endif #ifndef USB_SERIAL +#if CONFIG_IDF_TARGET_ESP32S3 +#define USB_SERIAL "__MAC__" +#else #define USB_SERIAL "0" #endif +#endif #ifndef USB_WEBUSB_ENABLED #define USB_WEBUSB_ENABLED false #endif @@ -155,6 +160,15 @@ ESPUSB::~ESPUSB(){ bool ESPUSB::begin(){ if(!_started){ +#if CONFIG_IDF_TARGET_ESP32S3 + if(serial_number == "__MAC__"){ + StreamString s; + uint8_t m[6]; + esp_efuse_mac_get_default(m); + s.printf("%02X:%02X:%02X:%02X:%02X:%02X", m[0], m[1], m[2], m[3], m[4], m[5]); + serial_number = s; + } +#endif tinyusb_device_config_t tinyusb_device_config = { .vid = vid, .pid = pid, diff --git a/cores/esp32/USBCDC.cpp b/cores/esp32/USBCDC.cpp index a7b75eada4f..ccf5180d7c7 100644 --- a/cores/esp32/USBCDC.cpp +++ b/cores/esp32/USBCDC.cpp @@ -114,16 +114,42 @@ void USBCDC::onEvent(arduino_usb_cdc_event_t event, esp_event_handler_t callback } size_t USBCDC::setRxBufferSize(size_t rx_queue_len){ - if(rx_queue){ - if(!rx_queue_len){ - vQueueDelete(rx_queue); - rx_queue = NULL; + size_t currentQueueSize = rx_queue ? + uxQueueSpacesAvailable(rx_queue) + uxQueueMessagesWaiting(rx_queue) : 0; + + if (rx_queue_len != currentQueueSize) { + xQueueHandle new_rx_queue = NULL; + if (rx_queue_len) { + new_rx_queue = xQueueCreate(rx_queue_len, sizeof(uint8_t)); + if(!new_rx_queue){ + log_e("CDC Queue creation failed."); + return 0; + } + if (rx_queue) { + size_t copySize = uxQueueMessagesWaiting(rx_queue); + if (copySize > 0) { + for(size_t i = 0; i < copySize; i++) { + uint8_t ch = 0; + xQueueReceive(rx_queue, &ch, 0); + if (!xQueueSend(new_rx_queue, &ch, 0)) { + arduino_usb_cdc_event_data_t p; + p.rx_overflow.dropped_bytes = copySize - i; + arduino_usb_event_post(ARDUINO_USB_CDC_EVENTS, ARDUINO_USB_CDC_RX_OVERFLOW_EVENT, &p, sizeof(arduino_usb_cdc_event_data_t), portMAX_DELAY); + log_e("CDC RX Overflow."); + break; + } + } + } + vQueueDelete(rx_queue); + } + rx_queue = new_rx_queue; + return rx_queue_len; + } else { + if (rx_queue) { + vQueueDelete(rx_queue); + rx_queue = NULL; + } } - return 0; - } - rx_queue = xQueueCreate(rx_queue_len, sizeof(uint8_t)); - if(!rx_queue){ - return 0; } return rx_queue_len; } @@ -133,7 +159,8 @@ void USBCDC::begin(unsigned long baud) if(tx_lock == NULL) { tx_lock = xSemaphoreCreateMutex(); } - setRxBufferSize(256);//default if not preset + // if rx_queue was set before begin(), keep it + if (!rx_queue) setRxBufferSize(256); //default if not preset devices[itf] = this; } @@ -144,6 +171,7 @@ void USBCDC::end() setRxBufferSize(0); if(tx_lock != NULL) { vSemaphoreDelete(tx_lock); + tx_lock = NULL; } } @@ -244,16 +272,22 @@ void USBCDC::_onLineCoding(uint32_t _bit_rate, uint8_t _stop_bits, uint8_t _pari } void USBCDC::_onRX(){ + arduino_usb_cdc_event_data_t p; uint8_t buf[CONFIG_TINYUSB_CDC_RX_BUFSIZE+1]; uint32_t count = tud_cdc_n_read(itf, buf, CONFIG_TINYUSB_CDC_RX_BUFSIZE); for(uint32_t i=0; i #include "WString.h" #include "stdlib_noniso.h" +#include "esp32-hal-log.h" /*********************************************/ /* Constructors */ @@ -112,16 +113,28 @@ String::String(unsigned long value, unsigned char base) { *this = buf; } -String::String(float value, unsigned char decimalPlaces) { +String::String(float value, unsigned int decimalPlaces) { init(); - char buf[33]; - *this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf); + char *buf = (char*)malloc(decimalPlaces + 42); + if (buf) { + *this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf); + free(buf); + } else { + *this = "nan"; + log_e("No enought memory for the operation."); + } } -String::String(double value, unsigned char decimalPlaces) { +String::String(double value, unsigned int decimalPlaces) { init(); - char buf[33]; - *this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf); + char *buf = (char*)malloc(decimalPlaces + 312); + if (buf) { + *this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf); + free(buf); + } else { + *this = "nan"; + log_e("No enought memory for the operation."); + } } String::~String() { @@ -761,8 +774,10 @@ void String::replace(const String& find, const String& replace) { } if(size == len()) return; - if(size > capacity() && !changeBuffer(size)) - return; // XXX: tell user! + if(size > capacity() && !changeBuffer(size)) { + log_w("String.Replace() Insufficient space to replace string"); + return; + } int index = len() - 1; while(index >= 0 && (index = lastIndexOf(find, index)) >= 0) { readFrom = wbuffer() + index + find.len(); diff --git a/cores/esp32/WString.h b/cores/esp32/WString.h index 958b01792e8..3190a247dda 100644 --- a/cores/esp32/WString.h +++ b/cores/esp32/WString.h @@ -71,8 +71,8 @@ class String { explicit String(unsigned int, unsigned char base = 10); explicit String(long, unsigned char base = 10); explicit String(unsigned long, unsigned char base = 10); - explicit String(float, unsigned char decimalPlaces = 2); - explicit String(double, unsigned char decimalPlaces = 2); + explicit String(float, unsigned int decimalPlaces = 2); + explicit String(double, unsigned int decimalPlaces = 2); ~String(void); // memory management diff --git a/cores/esp32/esp32-hal-adc.c b/cores/esp32/esp32-hal-adc.c index 674554fcce9..1d2fa17988a 100644 --- a/cores/esp32/esp32-hal-adc.c +++ b/cores/esp32/esp32-hal-adc.c @@ -27,6 +27,7 @@ #include "soc/rtc_io_reg.h" #include "esp32/rom/ets_sys.h" #include "esp_intr_alloc.h" +#include "soc/dac_channel.h" #define DEFAULT_VREF 1100 static esp_adc_cal_characteristics_t *__analogCharacteristics[2] = {NULL, NULL}; static uint16_t __analogVRef = 0; @@ -35,6 +36,11 @@ static uint8_t __analogVRefPin = 0; #include "esp32s2/rom/ets_sys.h" #include "soc/sens_reg.h" #include "soc/rtc_io_reg.h" +#include "soc/dac_channel.h" +#elif CONFIG_IDF_TARGET_ESP32S3 +#include "esp32s3/rom/ets_sys.h" +#include "soc/sens_reg.h" +#include "soc/rtc_io_reg.h" #elif CONFIG_IDF_TARGET_ESP32C3 #include "esp32c3/rom/ets_sys.h" #else @@ -141,10 +147,10 @@ bool __adcAttachPin(uint8_t pin){ } #endif } -#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 - else if(pin == 25){ +#if SOC_DAC_SUPPORTED + else if(pin == DAC_CHANNEL_1_GPIO_NUM){ CLEAR_PERI_REG_MASK(RTC_IO_PAD_DAC1_REG, RTC_IO_PDAC1_XPD_DAC | RTC_IO_PDAC1_DAC_XPD_FORCE);//stop dac1 - } else if(pin == 26){ + } else if(pin == DAC_CHANNEL_2_GPIO_NUM){ CLEAR_PERI_REG_MASK(RTC_IO_PAD_DAC2_REG, RTC_IO_PDAC2_XPD_DAC | RTC_IO_PDAC2_DAC_XPD_FORCE);//stop dac2 } #endif diff --git a/cores/esp32/esp32-hal-cpu.c b/cores/esp32/esp32-hal-cpu.c index 34124db1249..d79803f6124 100644 --- a/cores/esp32/esp32-hal-cpu.c +++ b/cores/esp32/esp32-hal-cpu.c @@ -33,6 +33,9 @@ #elif CONFIG_IDF_TARGET_ESP32S2 #include "freertos/xtensa_timer.h" #include "esp32s2/rom/rtc.h" +#elif CONFIG_IDF_TARGET_ESP32S3 +#include "freertos/xtensa_timer.h" +#include "esp32s3/rom/rtc.h" #elif CONFIG_IDF_TARGET_ESP32C3 #include "esp32c3/rom/rtc.h" #else @@ -144,7 +147,7 @@ bool removeApbChangeCallback(void * arg, apb_change_cb_t cb){ } static uint32_t calculateApb(rtc_cpu_freq_config_t * conf){ -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 return APB_CLK_FREQ; #else if(conf->freq_mhz >= 80){ @@ -228,6 +231,8 @@ bool setCpuFrequencyMhz(uint32_t cpu_freq_mhz){ //Update FreeRTOS Tick Divisor #if CONFIG_IDF_TARGET_ESP32C3 +#elif CONFIG_IDF_TARGET_ESP32S3 + #else uint32_t fcpu = (conf.freq_mhz >= 80)?(conf.freq_mhz * MHZ):(apb); _xt_tick_divisor = fcpu / XT_TICK_PER_SEC; diff --git a/cores/esp32/esp32-hal-gpio.c b/cores/esp32/esp32-hal-gpio.c index 552126b848d..e21063a8596 100644 --- a/cores/esp32/esp32-hal-gpio.c +++ b/cores/esp32/esp32-hal-gpio.c @@ -13,167 +13,70 @@ // limitations under the License. #include "esp32-hal-gpio.h" -#include "pins_arduino.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "esp_attr.h" -#include "soc/gpio_reg.h" -#include "soc/io_mux_reg.h" -#include "soc/gpio_struct.h" -#include "driver/gpio.h" -#include "esp_system.h" +#include "hal/gpio_hal.h" +#include "soc/soc_caps.h" -#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ -#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 -#include "esp32/rom/ets_sys.h" -#include "esp32/rom/gpio.h" -#include "esp_intr_alloc.h" -#include "soc/rtc_io_reg.h" -#define GPIO_FUNC 2 -#elif CONFIG_IDF_TARGET_ESP32S2 -#include "esp32s2/rom/ets_sys.h" -#include "esp32s2/rom/gpio.h" -#include "esp_intr_alloc.h" -#include "soc/periph_defs.h" -#include "soc/rtc_io_reg.h" -#define GPIO_FUNC 1 -#elif CONFIG_IDF_TARGET_ESP32C3 -#include "esp32c3/rom/ets_sys.h" -#include "esp32c3/rom/gpio.h" -#include "esp_intr_alloc.h" -#include "soc/periph_defs.h" -#define USE_ESP_IDF_GPIO 1 +// It fixes lack of pin definition for S3 and for any future SoC +// this function works for ESP32, ESP32-S2 and ESP32-S3 - including the C3, it will return -1 for any pin +#if SOC_TOUCH_SENSOR_NUM > 0 +#include "soc/touch_sensor_periph.h" + +int8_t digitalPinToTouchChannel(uint8_t pin) +{ + int8_t ret = -1; + if (pin < SOC_GPIO_PIN_COUNT) { + for (uint8_t i = 0; i < SOC_TOUCH_SENSOR_NUM; i++) { + if (touch_sensor_channel_io_map[i] == pin) { + ret = i; + break; + } + } + } + return ret; +} #else -#define USE_ESP_IDF_GPIO 1 -#endif -#else // ESP32 Before IDF 4.0 -#include "rom/ets_sys.h" -#include "rom/gpio.h" -#include "esp_intr.h" +// No Touch Sensor available +int8_t digitalPinToTouchChannel(uint8_t pin) +{ + return -1; +} #endif -#if CONFIG_IDF_TARGET_ESP32 -const int8_t esp32_adc2gpio[20] = {36, 37, 38, 39, 32, 33, 34, 35, -1, -1, 4, 0, 2, 15, 13, 12, 14, 27, 25, 26}; -#elif CONFIG_IDF_TARGET_ESP32S2 -const int8_t esp32_adc2gpio[20] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; -#endif +#ifdef SOC_ADC_SUPPORTED +#include "soc/adc_periph.h" + +int8_t digitalPinToAnalogChannel(uint8_t pin) +{ + uint8_t channel = 0; + if (pin < SOC_GPIO_PIN_COUNT) { + for (uint8_t i = 0; i < SOC_ADC_PERIPH_NUM; i++) { + for (uint8_t j = 0; j < SOC_ADC_MAX_CHANNEL_NUM; j++) { + if (adc_channel_io_map[i][j] == pin) { + return channel; + } + channel++; + } + } + } + return -1; +} -const DRAM_ATTR esp32_gpioMux_t esp32_gpioMux[SOC_GPIO_PIN_COUNT]={ -#if CONFIG_IDF_TARGET_ESP32 - {0x44, 11, 11, 1}, - {0x88, -1, -1, -1}, - {0x40, 12, 12, 2}, - {0x84, -1, -1, -1}, - {0x48, 10, 10, 0}, - {0x6c, -1, -1, -1}, - {0x60, -1, -1, -1}, - {0x64, -1, -1, -1}, - {0x68, -1, -1, -1}, - {0x54, -1, -1, -1}, - {0x58, -1, -1, -1}, - {0x5c, -1, -1, -1}, - {0x34, 15, 15, 5}, - {0x38, 14, 14, 4}, - {0x30, 16, 16, 6}, - {0x3c, 13, 13, 3}, - {0x4c, -1, -1, -1}, - {0x50, -1, -1, -1}, - {0x70, -1, -1, -1}, - {0x74, -1, -1, -1}, - {0x78, -1, -1, -1}, - {0x7c, -1, -1, -1}, - {0x80, -1, -1, -1}, - {0x8c, -1, -1, -1}, - {0, -1, -1, -1}, - {0x24, 6, 18, -1}, //DAC1 - {0x28, 7, 19, -1}, //DAC2 - {0x2c, 17, 17, 7}, - {0, -1, -1, -1}, - {0, -1, -1, -1}, - {0, -1, -1, -1}, - {0, -1, -1, -1}, - {0x1c, 9, 4, 8}, - {0x20, 8, 5, 9}, - {0x14, 4, 6, -1}, - {0x18, 5, 7, -1}, - {0x04, 0, 0, -1}, - {0x08, 1, 1, -1}, - {0x0c, 2, 2, -1}, - {0x10, 3, 3, -1} -#elif CONFIG_IDF_TARGET_ESP32S2 - {0x04, 0, -1, -1}, - {0x08, 1, 0, 1}, - {0x0c, 2, 1, 2}, - {0x10, 3, 2, 3}, - {0x14, 4, 3, 4}, - {0x18, 5, 4, 5}, - {0x1c, 6, 5, 6}, - {0x20, 7, 6, 7}, - {0x24, 8, 7, 8}, - {0x28, 9, 8, 9},//FSPI_HD - {0x2c, 10, 9, 10},//FSPI_CS0 / FSPI_D4 - {0x30, 11, 10, 11},//FSPI_D / FSPI_D5 - {0x34, 12, 11, 12},//FSPI_CLK / FSPI_D6 - {0x38, 13, 12, 13},//FSPI_Q / FSPI_D7 - {0x3c, 14, 13, 14},//FSPI_WP / FSPI_DQS - {0x40, 15, 14, -1},//32K+ / RTS0 - {0x44, 16, 15, -1},//32K- / CTS0 - {0x48, 17, 16, -1},//DAC1 / TXD1 - {0x4c, 18, 17, -1},//DAC2 / RXD1 - {0x50, 19, 18, -1},//USB D- / RTS1 - {0x54, 20, 19, -1},//USB D+ / CTS1 - {0x58, 21, -1, -1},//SDA? - { 0, -1, -1, -1},//UNAVAILABLE - { 0, -1, -1, -1},//UNAVAILABLE - { 0, -1, -1, -1},//UNAVAILABLE - { 0, -1, -1, -1},//UNAVAILABLE - {0x6c, -1, -1, -1},//RESERVED SPI_CS1 - {0x70, -1, -1, -1},//RESERVED SPI_HD - {0x74, -1, -1, -1},//RESERVED SPI_WP - {0x78, -1, -1, -1},//RESERVED SPI_CS0 - {0x7c, -1, -1, -1},//RESERVED SPI_CLK - {0x80, -1, -1, -1},//RESERVED SPI_Q - {0x84, -1, -1, -1},//RESERVED SPI_D - {0x88, -1, -1, -1},//FSPI_HD - {0x8c, -1, -1, -1},//FSPI_CS0 - {0x90, -1, -1, -1},//FSPI_D - {0x94, -1, -1, -1},//FSPI_CLK - {0x98, -1, -1, -1},//FSPI_Q - {0x9c, -1, -1, -1},//FSPI_WP - {0xa0, -1, -1, -1},//MTCK - {0xa4, -1, -1, -1},//MTDO - {0xa8, -1, -1, -1},//MTDI - {0xac, -1, -1, -1},//MTMS - {0xb0, -1, -1, -1},//TXD0 - {0xb4, -1, -1, -1},//RXD0 - {0xb8, -1, -1, -1},//SCL? - {0xbc, -1, -1, -1},//INPUT ONLY - {0, -1, -1, -1} -#elif CONFIG_IDF_TARGET_ESP32C3 - {0x04, -1, 0, -1}, // ADC1_CH0 - {0x08, -1, 1, -1}, // ADC1_CH1 - {0x0c, -1, 2, -1}, // ADC1_CH2 | FSPIQ - {0x10, -1, 3, -1}, // ADC1_CH3 - {0x14, -1, 4, -1}, // MTMS | ADC1_CH4 | FSPIHD - {0x18, -1, 5, -1}, // MTDI | ADC2_CH0 | FSPIWP - {0x1c, -1, -1, -1}, // MTCK | FSPICLK - {0x20, -1, -1, -1}, // MTDO | FSPID - {0x24, -1, -1, -1}, // - {0x28, -1, -1, -1}, // - {0x2c, -1, -1, -1}, // FSPICSO - {0x30, -1, -1, -1}, // - {0x34, -1, -1, -1}, // SPIHD - {0x38, -1, -1, -1}, // SPIWP - {0x3c, -1, -1, -1}, // SPICSO - {0x40, -1, -1, -1}, // SPICLK - {0x44, -1, -1, -1}, // SPID - {0x48, -1, -1, -1}, // SPIQ - {0x4c, -1, -1, -1}, // USB- - {0x50, -1, -1, -1}, // USB+ - {0x54, -1, -1, -1}, // U0RXD - {0x58, -1, -1, -1}, // U0TXD +int8_t analogChannelToDigitalPin(uint8_t channel) +{ + if (channel >= (SOC_ADC_PERIPH_NUM * SOC_ADC_MAX_CHANNEL_NUM)) { + return -1; + } + uint8_t adc_unit = (channel / SOC_ADC_MAX_CHANNEL_NUM); + uint8_t adc_chan = (channel % SOC_ADC_MAX_CHANNEL_NUM); + return adc_channel_io_map[adc_unit][adc_chan]; +} +#else +// No Analog channels availible +int8_t analogChannelToDigitalPin(uint8_t channel) +{ + return -1; +} #endif -}; typedef void (*voidFuncPtr)(void); typedef void (*voidFuncPtrArg)(void*); @@ -188,8 +91,8 @@ static InterruptHandle_t __pinInterruptHandlers[SOC_GPIO_PIN_COUNT] = {0,}; extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode) { -#if USE_ESP_IDF_GPIO if (!GPIO_IS_VALID_GPIO(pin)) { + log_e("Invalid pin selected"); return; } gpio_config_t conf = { @@ -211,157 +114,23 @@ extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode) conf.pull_down_en = GPIO_PULLDOWN_ENABLE; } } - gpio_config(&conf); - - if(mode == SPECIAL){ -#if CONFIG_IDF_TARGET_ESP32 - PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[pin], (uint32_t)(((pin)==RX||(pin)==TX)?0:1)); -#elif CONFIG_IDF_TARGET_ESP32S2 - PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[pin], (uint32_t)(((pin)==RX||(pin)==TX)?0:2)); -#endif - } else if(mode == ANALOG){ -#if !CONFIG_IDF_TARGET_ESP32C3 - //adc_gpio_init(ADC_UNIT_1, ADC_CHANNEL_0); -#endif - } else if(mode >= 0x20 && mode < ANALOG) {//function - PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[pin], mode >> 5); - } -#else - if(!digitalPinIsValid(pin)) { - return; - } - - int8_t rtc_io = esp32_gpioMux[pin].rtc; - uint32_t rtc_reg = (rtc_io != -1)?rtc_io_desc[rtc_io].reg:0; - if(mode == ANALOG) { - if(!rtc_reg) { - return;//not rtc pin - } -#if CONFIG_IDF_TARGET_ESP32S2 - SENS.sar_io_mux_conf.iomux_clk_gate_en = 1; -#endif - SET_PERI_REG_MASK(rtc_io_desc[rtc_io].reg, (rtc_io_desc[rtc_io].mux)); - SET_PERI_REG_BITS(rtc_io_desc[rtc_io].reg, RTC_IO_TOUCH_PAD1_FUN_SEL_V, 0, rtc_io_desc[rtc_io].func); - - RTCIO.pin[rtc_io].pad_driver = 0;//OD = 1 - RTCIO.enable_w1tc.w1tc = (1U << rtc_io); - CLEAR_PERI_REG_MASK(rtc_io_desc[rtc_io].reg, rtc_io_desc[rtc_io].ie); - - if (rtc_io_desc[rtc_io].pullup) { - CLEAR_PERI_REG_MASK(rtc_io_desc[rtc_io].reg, rtc_io_desc[rtc_io].pullup); - } - if (rtc_io_desc[rtc_io].pulldown) { - CLEAR_PERI_REG_MASK(rtc_io_desc[rtc_io].reg, rtc_io_desc[rtc_io].pulldown); - } - ESP_REG(DR_REG_IO_MUX_BASE + esp32_gpioMux[pin].reg) = ((uint32_t)GPIO_FUNC << MCU_SEL_S) | ((uint32_t)2 << FUN_DRV_S) | FUN_IE; + if(gpio_config(&conf) != ESP_OK) + { + log_e("GPIO config failed"); return; } - - //RTC pins PULL settings - if(rtc_reg) { - ESP_REG(rtc_reg) = ESP_REG(rtc_reg) & ~(rtc_io_desc[rtc_io].mux); - if(mode & PULLUP) { - ESP_REG(rtc_reg) = (ESP_REG(rtc_reg) | rtc_io_desc[rtc_io].pullup) & ~(rtc_io_desc[rtc_io].pulldown); - } else if(mode & PULLDOWN) { - ESP_REG(rtc_reg) = (ESP_REG(rtc_reg) | rtc_io_desc[rtc_io].pulldown) & ~(rtc_io_desc[rtc_io].pullup); - } else { - ESP_REG(rtc_reg) = ESP_REG(rtc_reg) & ~(rtc_io_desc[rtc_io].pullup | rtc_io_desc[rtc_io].pulldown); - } - } - - uint32_t pinFunction = 0, pinControl = 0; - - if(mode & INPUT) { - if(pin < 32) { - GPIO.enable_w1tc = ((uint32_t)1 << pin); - } else { - GPIO.enable1_w1tc.val = ((uint32_t)1 << (pin - 32)); - } - } else if(mode & OUTPUT) { - if(pin >= NUM_OUPUT_PINS){ - return; - } else if(pin < 32) { - GPIO.enable_w1ts = ((uint32_t)1 << pin); - } else { - GPIO.enable1_w1ts.val = ((uint32_t)1 << (pin - 32)); - } - } - - if(mode & PULLUP) { - pinFunction |= FUN_PU; - } else if(mode & PULLDOWN) { - pinFunction |= FUN_PD; - } - - pinFunction |= ((uint32_t)2 << FUN_DRV_S);//what are the drivers? - pinFunction |= FUN_IE;//input enable but required for output as well? - - if(mode & (INPUT | OUTPUT)) { - pinFunction |= ((uint32_t)PIN_FUNC_GPIO << MCU_SEL_S); - } else if(mode == SPECIAL) { -#if CONFIG_IDF_TARGET_ESP32 - pinFunction |= ((uint32_t)(((pin)==RX||(pin)==TX)?0:1) << MCU_SEL_S); -#elif CONFIG_IDF_TARGET_ESP32S2 - pinFunction |= ((uint32_t)(((pin)==RX||(pin)==TX)?0:2) << MCU_SEL_S); -#endif - } else { - pinFunction |= ((uint32_t)(mode >> 5) << MCU_SEL_S); - } - - ESP_REG(DR_REG_IO_MUX_BASE + esp32_gpioMux[pin].reg) = pinFunction; - - if(mode & OPEN_DRAIN) { - pinControl = (1 << GPIO_PIN0_PAD_DRIVER_S); - } - - GPIO.pin[pin].val = pinControl; -#endif } extern void ARDUINO_ISR_ATTR __digitalWrite(uint8_t pin, uint8_t val) { -#if USE_ESP_IDF_GPIO gpio_set_level((gpio_num_t)pin, val); -#elif CONFIG_IDF_TARGET_ESP32C3 - if (val) { - GPIO.out_w1ts.out_w1ts = (1 << pin); - } else { - GPIO.out_w1tc.out_w1tc = (1 << pin); - } -#else - if(val) { - if(pin < 32) { - GPIO.out_w1ts = ((uint32_t)1 << pin); - } else if(pin < NUM_OUPUT_PINS) { - GPIO.out1_w1ts.val = ((uint32_t)1 << (pin - 32)); - } - } else { - if(pin < 32) { - GPIO.out_w1tc = ((uint32_t)1 << pin); - } else if(pin < NUM_OUPUT_PINS) { - GPIO.out1_w1tc.val = ((uint32_t)1 << (pin - 32)); - } - } -#endif } extern int ARDUINO_ISR_ATTR __digitalRead(uint8_t pin) { -#if USE_ESP_IDF_GPIO return gpio_get_level((gpio_num_t)pin); -#elif CONFIG_IDF_TARGET_ESP32C3 - return (GPIO.in.data >> pin) & 0x1; -#else - if(pin < 32) { - return (GPIO.in >> pin) & 0x1; - } else if(pin < GPIO_PIN_COUNT) { - return (GPIO.in1.val >> (pin - 32)) & 0x1; - } - return 0; -#endif } -#if USE_ESP_IDF_GPIO static void ARDUINO_ISR_ATTR __onPinInterrupt(void * arg) { InterruptHandle_t * isr = (InterruptHandle_t*)arg; if(isr->fn) { @@ -372,49 +141,6 @@ static void ARDUINO_ISR_ATTR __onPinInterrupt(void * arg) { } } } -#else -static intr_handle_t gpio_intr_handle = NULL; - -static void ARDUINO_ISR_ATTR __onPinInterrupt() -{ - uint32_t gpio_intr_status_l=0; - uint32_t gpio_intr_status_h=0; - - gpio_intr_status_l = GPIO.status; - gpio_intr_status_h = GPIO.status1.val; - GPIO.status_w1tc = gpio_intr_status_l;//Clear intr for gpio0-gpio31 - GPIO.status1_w1tc.val = gpio_intr_status_h;//Clear intr for gpio32-39 - - uint8_t pin=0; - if(gpio_intr_status_l) { - do { - if(gpio_intr_status_l & ((uint32_t)1 << pin)) { - if(__pinInterruptHandlers[pin].fn) { - if(__pinInterruptHandlers[pin].arg){ - ((voidFuncPtrArg)__pinInterruptHandlers[pin].fn)(__pinInterruptHandlers[pin].arg); - } else { - __pinInterruptHandlers[pin].fn(); - } - } - } - } while(++pin<32); - } - if(gpio_intr_status_h) { - pin=32; - do { - if(gpio_intr_status_h & ((uint32_t)1 << (pin - 32))) { - if(__pinInterruptHandlers[pin].fn) { - if(__pinInterruptHandlers[pin].arg){ - ((voidFuncPtrArg)__pinInterruptHandlers[pin].fn)(__pinInterruptHandlers[pin].arg); - } else { - __pinInterruptHandlers[pin].fn(); - } - } - } - } while(++pinsr.stretch_cause; #elif CONFIG_IDF_TARGET_ESP32S2 return hw->status_reg.stretch_cause; @@ -164,7 +164,7 @@ static inline void i2c_ll_stretch_clr(i2c_dev_t *hw) static inline bool i2c_ll_slave_addressed(i2c_dev_t *hw) { -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 return hw->sr.slave_addressed; #else return hw->status_reg.slave_addressed; @@ -173,7 +173,7 @@ static inline bool i2c_ll_slave_addressed(i2c_dev_t *hw) static inline bool i2c_ll_slave_rw(i2c_dev_t *hw)//not exposed by hal_ll { -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 return hw->sr.slave_rw; #else return hw->status_reg.slave_rw; @@ -360,10 +360,12 @@ esp_err_t i2cSlaveDeinit(uint8_t num){ } i2c_slave_struct_t * i2c = &_i2c_bus_array[num]; +#if !CONFIG_DISABLE_HAL_LOCKS if(!i2c->lock){ log_e("Lock is not initialized! Did you call i2c_slave_init()?"); return ESP_ERR_NO_MEM; } +#endif I2C_SLAVE_MUTEX_LOCK(); i2c_slave_free_resources(i2c); I2C_SLAVE_MUTEX_UNLOCK(); @@ -377,10 +379,12 @@ size_t i2cSlaveWrite(uint8_t num, const uint8_t *buf, uint32_t len, uint32_t tim } size_t to_queue = 0, to_fifo = 0; i2c_slave_struct_t * i2c = &_i2c_bus_array[num]; +#if !CONFIG_DISABLE_HAL_LOCKS if(!i2c->lock){ log_e("Lock is not initialized! Did you call i2c_slave_init()?"); return ESP_ERR_NO_MEM; } +#endif if(!i2c->tx_queue){ return 0; } @@ -715,10 +719,12 @@ static void i2c_slave_isr_handler(void* arg) } if(slave_rw){ // READ #if CONFIG_IDF_TARGET_ESP32 - //SEND TX Event - i2c_slave_queue_event_t event; - event.event = I2C_SLAVE_EVT_TX; - pxHigherPriorityTaskWoken |= i2c_slave_send_event(i2c, &event); + if(i2c->dev->status_reg.scl_main_state_last == 6){ + //SEND TX Event + i2c_slave_queue_event_t event; + event.event = I2C_SLAVE_EVT_TX; + pxHigherPriorityTaskWoken |= i2c_slave_send_event(i2c, &event); + } #else //reset TX data i2c_ll_txfifo_rst(i2c->dev); diff --git a/cores/esp32/esp32-hal-i2c.c b/cores/esp32/esp32-hal-i2c.c index c4ec85e732c..f01b501a020 100644 --- a/cores/esp32/esp32-hal-i2c.c +++ b/cores/esp32/esp32-hal-i2c.c @@ -317,6 +317,8 @@ esp_err_t i2cSetClock(uint8_t i2c_num, uint32_t frequency){ hal.dev = I2C_LL_GET_HW(i2c_num); i2c_hal_set_bus_timing(&(hal), frequency, src_clk); bus[i2c_num].frequency = frequency; + //Clock Stretching Timeout: 20b:esp32, 5b:esp32-c3, 24b:esp32-s2 + i2c_set_timeout((i2c_port_t)i2c_num, I2C_LL_MAX_TIMEOUT); } end: diff --git a/cores/esp32/esp32-hal-ledc.c b/cores/esp32/esp32-hal-ledc.c index 6274ed0708c..44a3667333d 100644 --- a/cores/esp32/esp32-hal-ledc.c +++ b/cores/esp32/esp32-hal-ledc.c @@ -54,12 +54,13 @@ uint8_t channels_resolution[LEDC_CHANNELS] = {0}; -double ledcSetup(uint8_t chan, double freq, uint8_t bit_num) +uint32_t ledcSetup(uint8_t chan, uint32_t freq, uint8_t bit_num) { - if(chan >= LEDC_CHANNELS){ - log_e("No more LEDC channels available! You can have maximum %u", LEDC_CHANNELS); + if(chan >= LEDC_CHANNELS || bit_num > LEDC_MAX_BIT_WIDTH){ + log_e("No more LEDC channels available! (maximum %u) or bit width too big (maximum %u)", LEDC_CHANNELS, LEDC_MAX_BIT_WIDTH); return 0; } + uint8_t group=(chan/8), timer=((chan/2)%4); ledc_timer_config_t ledc_timer = { @@ -69,9 +70,12 @@ double ledcSetup(uint8_t chan, double freq, uint8_t bit_num) .freq_hz = freq, .clk_cfg = LEDC_DEFAULT_CLK }; - ledc_timer_config(&ledc_timer); + if(ledc_timer_config(&ledc_timer) != ESP_OK) + { + log_e("ledc setup failed!"); + return 0; + } channels_resolution[chan] = bit_num; - return ledc_get_freq(group,timer); } @@ -95,14 +99,14 @@ void ledcWrite(uint8_t chan, uint32_t duty) uint32_t ledcRead(uint8_t chan) { - if(chan >= LEDC_CHANNELS){ + if(chan >= LEDC_CHANNELS){ return 0; } uint8_t group=(chan/8), channel=(chan%8); return ledc_get_duty(group,channel); } -double ledcReadFreq(uint8_t chan) +uint32_t ledcReadFreq(uint8_t chan) { if(!ledcRead(chan)){ return 0; @@ -111,7 +115,7 @@ double ledcReadFreq(uint8_t chan) return ledc_get_freq(group,timer); } -double ledcWriteTone(uint8_t chan, double freq) +uint32_t ledcWriteTone(uint8_t chan, uint32_t freq) { if(chan >= LEDC_CHANNELS){ return 0; @@ -130,15 +134,20 @@ double ledcWriteTone(uint8_t chan, double freq) .freq_hz = freq, .clk_cfg = LEDC_DEFAULT_CLK }; - ledc_timer_config(&ledc_timer); + + if(ledc_timer_config(&ledc_timer) != ESP_OK) + { + log_e("ledcSetup failed!"); + return 0; + } channels_resolution[chan] = 10; - double res_freq = ledc_get_freq(group,timer); + uint32_t res_freq = ledc_get_freq(group,timer); ledcWrite(chan, 0x1FF); return res_freq; } -double ledcWriteNote(uint8_t chan, note_t note, uint8_t octave){ +uint32_t ledcWriteNote(uint8_t chan, note_t note, uint8_t octave){ const uint16_t noteFrequencyBase[12] = { // C C# D Eb E F F# G G# A Bb B 4186, 4435, 4699, 4978, 5274, 5588, 5920, 6272, 6645, 7040, 7459, 7902 @@ -147,13 +156,13 @@ double ledcWriteNote(uint8_t chan, note_t note, uint8_t octave){ if(octave > 8 || note >= NOTE_MAX){ return 0; } - double noteFreq = (double)noteFrequencyBase[note] / (double)(1 << (8-octave)); + uint32_t noteFreq = (uint32_t)noteFrequencyBase[note] / (uint32_t)(1 << (8-octave)); return ledcWriteTone(chan, noteFreq); } void ledcAttachPin(uint8_t pin, uint8_t chan) { - if(chan >= LEDC_CHANNELS){ + if(chan >= LEDC_CHANNELS){ return; } uint8_t group=(chan/8), channel=(chan%8), timer=((chan/2)%4); @@ -175,9 +184,10 @@ void ledcDetachPin(uint8_t pin) pinMatrixOutDetach(pin, false, false); } -double ledcChangeFrequency(uint8_t chan, double freq, uint8_t bit_num) +uint32_t ledcChangeFrequency(uint8_t chan, uint32_t freq, uint8_t bit_num) { - if(chan >= LEDC_CHANNELS){ + if(chan >= LEDC_CHANNELS || bit_num > LEDC_MAX_BIT_WIDTH){ + log_e("LEDC channel not available! (maximum %u) or bit width too big (maximum %u)", LEDC_CHANNELS, LEDC_MAX_BIT_WIDTH); return 0; } uint8_t group=(chan/8), timer=((chan/2)%4); @@ -189,9 +199,13 @@ double ledcChangeFrequency(uint8_t chan, double freq, uint8_t bit_num) .freq_hz = freq, .clk_cfg = LEDC_DEFAULT_CLK }; - ledc_timer_config(&ledc_timer); - channels_resolution[chan] = bit_num; + if(ledc_timer_config(&ledc_timer) != ESP_OK) + { + log_e("ledcChangeFrequency failed!"); + return 0; + } + channels_resolution[chan] = bit_num; return ledc_get_freq(group,timer); } diff --git a/cores/esp32/esp32-hal-ledc.h b/cores/esp32/esp32-hal-ledc.h index 1d640b32eae..4b8bc7d712a 100644 --- a/cores/esp32/esp32-hal-ledc.h +++ b/cores/esp32/esp32-hal-ledc.h @@ -27,15 +27,15 @@ typedef enum { } note_t; //channel 0-15 resolution 1-16bits freq limits depend on resolution -double ledcSetup(uint8_t channel, double freq, uint8_t resolution_bits); +uint32_t ledcSetup(uint8_t channel, uint32_t freq, uint8_t resolution_bits); void ledcWrite(uint8_t channel, uint32_t duty); -double ledcWriteTone(uint8_t channel, double freq); -double ledcWriteNote(uint8_t channel, note_t note, uint8_t octave); +uint32_t ledcWriteTone(uint8_t channel, uint32_t freq); +uint32_t ledcWriteNote(uint8_t channel, note_t note, uint8_t octave); uint32_t ledcRead(uint8_t channel); -double ledcReadFreq(uint8_t channel); +uint32_t ledcReadFreq(uint8_t channel); void ledcAttachPin(uint8_t pin, uint8_t channel); void ledcDetachPin(uint8_t pin); -double ledcChangeFrequency(uint8_t channel, double freq, uint8_t resolution_bits); +uint32_t ledcChangeFrequency(uint8_t channel, uint32_t freq, uint8_t resolution_bits); #ifdef __cplusplus diff --git a/cores/esp32/esp32-hal-log.h b/cores/esp32/esp32-hal-log.h index 7f6d554213f..3198387fdd8 100644 --- a/cores/esp32/esp32-hal-log.h +++ b/cores/esp32/esp32-hal-log.h @@ -38,9 +38,11 @@ extern "C" #else #define ARDUHAL_LOG_LEVEL CORE_DEBUG_LEVEL #ifdef USE_ESP_IDF_LOG +#ifndef LOG_LOCAL_LEVEL #define LOG_LOCAL_LEVEL CORE_DEBUG_LEVEL #endif #endif +#endif #ifndef CONFIG_ARDUHAL_LOG_COLORS #define CONFIG_ARDUHAL_LOG_COLORS 0 @@ -158,7 +160,7 @@ void log_print_buf(const uint8_t *b, size_t len); #define isr_log_e(format, ...) ets_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__) #define log_buf_e(b,l) do{ARDUHAL_LOG_COLOR_PRINT(E);log_print_buf(b,l);ARDUHAL_LOG_COLOR_PRINT_END;}while(0) #else -#define log_e(format, ...) do {log_to_esp(TAG, ESP_LOG_ERROR, format, ##__VA_ARGS__);}while(0) +#define log_e(format, ...) do {ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR, TAG, format, ##__VA_ARGS__);}while(0) #define isr_log_e(format, ...) do {ets_printf(LOG_FORMAT(E, format), esp_log_timestamp(), TAG, ##__VA_ARGS__);}while(0) #define log_buf_e(b,l) do {ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_ERROR);}while(0) #endif @@ -187,9 +189,9 @@ void log_print_buf(const uint8_t *b, size_t len); #include "esp_log.h" #ifdef USE_ESP_IDF_LOG -#ifndef TAG -#define TAG "ARDUINO" -#endif +//#ifndef TAG +//#define TAG "ARDUINO" +//#endif //#define log_n(format, ...) myLog(ESP_LOG_NONE, format, ##__VA_ARGS__) #else #ifdef CONFIG_ARDUHAL_ESP_LOG @@ -204,16 +206,16 @@ void log_print_buf(const uint8_t *b, size_t len); #undef ESP_EARLY_LOGD #undef ESP_EARLY_LOGV -#define ESP_LOGE(tag, ...) log_e(__VA_ARGS__) -#define ESP_LOGW(tag, ...) log_w(__VA_ARGS__) -#define ESP_LOGI(tag, ...) log_i(__VA_ARGS__) -#define ESP_LOGD(tag, ...) log_d(__VA_ARGS__) -#define ESP_LOGV(tag, ...) log_v(__VA_ARGS__) -#define ESP_EARLY_LOGE(tag, ...) isr_log_e(__VA_ARGS__) -#define ESP_EARLY_LOGW(tag, ...) isr_log_w(__VA_ARGS__) -#define ESP_EARLY_LOGI(tag, ...) isr_log_i(__VA_ARGS__) -#define ESP_EARLY_LOGD(tag, ...) isr_log_d(__VA_ARGS__) -#define ESP_EARLY_LOGV(tag, ...) isr_log_v(__VA_ARGS__) +#define ESP_LOGE(tag, format, ...) log_e("[%s] " format, tag, ##__VA_ARGS__) +#define ESP_LOGW(tag, format, ...) log_w("[%s] " format, tag, ##__VA_ARGS__) +#define ESP_LOGI(tag, format, ...) log_i("[%s] " format, tag, ##__VA_ARGS__) +#define ESP_LOGD(tag, format, ...) log_d("[%s] " format, tag, ##__VA_ARGS__) +#define ESP_LOGV(tag, format, ...) log_v("[%s] " format, tag, ##__VA_ARGS__) +#define ESP_EARLY_LOGE(tag, format, ...) isr_log_e("[%s] " format, tag, ##__VA_ARGS__) +#define ESP_EARLY_LOGW(tag, format, ...) isr_log_w("[%s] " format, tag, ##__VA_ARGS__) +#define ESP_EARLY_LOGI(tag, format, ...) isr_log_i("[%s] " format, tag, ##__VA_ARGS__) +#define ESP_EARLY_LOGD(tag, format, ...) isr_log_d("[%s] " format, tag, ##__VA_ARGS__) +#define ESP_EARLY_LOGV(tag, format, ...) isr_log_v("[%s] " format, tag, ##__VA_ARGS__) #endif #endif diff --git a/cores/esp32/esp32-hal-matrix.c b/cores/esp32/esp32-hal-matrix.c index 3d6069b8b63..869761a9ac7 100644 --- a/cores/esp32/esp32-hal-matrix.c +++ b/cores/esp32/esp32-hal-matrix.c @@ -21,6 +21,8 @@ #include "esp32/rom/gpio.h" #elif CONFIG_IDF_TARGET_ESP32S2 #include "esp32s2/rom/gpio.h" +#elif CONFIG_IDF_TARGET_ESP32S3 +#include "esp32s3/rom/gpio.h" #elif CONFIG_IDF_TARGET_ESP32C3 #include "esp32c3/rom/gpio.h" #else diff --git a/cores/esp32/esp32-hal-misc.c b/cores/esp32/esp32-hal-misc.c index 102ff6947a4..d50885b32dd 100644 --- a/cores/esp32/esp32-hal-misc.c +++ b/cores/esp32/esp32-hal-misc.c @@ -41,6 +41,9 @@ #elif CONFIG_IDF_TARGET_ESP32S2 #include "esp32s2/rom/rtc.h" #include "driver/temp_sensor.h" +#elif CONFIG_IDF_TARGET_ESP32S3 +#include "esp32s3/rom/rtc.h" +#include "driver/temp_sensor.h" #elif CONFIG_IDF_TARGET_ESP32C3 #include "esp32c3/rom/rtc.h" #include "driver/temp_sensor.h" @@ -232,7 +235,7 @@ void initArduino() #endif esp_log_level_set("*", CONFIG_LOG_DEFAULT_LEVEL); esp_err_t err = nvs_flash_init(); - if(err == ESP_ERR_NVS_NO_FREE_PAGES){ + if(err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND){ const esp_partition_t* partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, NULL); if (partition != NULL) { err = esp_partition_erase_range(partition, 0, partition->size); @@ -241,6 +244,8 @@ void initArduino() } else { log_e("Failed to format the broken NVS partition!"); } + } else { + log_e("Could not find NVS partition"); } } if(err) { diff --git a/cores/esp32/esp32-hal-psram.c b/cores/esp32/esp32-hal-psram.c index 7a8cc0befef..424499e0058 100644 --- a/cores/esp32/esp32-hal-psram.c +++ b/cores/esp32/esp32-hal-psram.c @@ -25,6 +25,9 @@ #elif CONFIG_IDF_TARGET_ESP32S2 #include "esp32s2/spiram.h" #include "esp32s2/rom/cache.h" +#elif CONFIG_IDF_TARGET_ESP32S3 +#include "esp32s3/spiram.h" +#include "esp32s3/rom/cache.h" #else #error Target CONFIG_IDF_TARGET is not supported #endif @@ -35,6 +38,13 @@ static volatile bool spiramDetected = false; static volatile bool spiramFailed = false; +//allows user to bypass SPI RAM test routine +__attribute__((weak)) bool testSPIRAM(void) +{ + return esp_spiram_test(); +} + + bool psramInit(){ if (spiramDetected) { return true; @@ -60,13 +70,16 @@ bool psramInit(){ spiramFailed = true; log_w("PSRAM init failed!"); #if CONFIG_IDF_TARGET_ESP32 - pinMatrixOutDetach(16, false, false); - pinMatrixOutDetach(17, false, false); + if (pkg_ver != EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4) { + pinMatrixOutDetach(16, false, false); + pinMatrixOutDetach(17, false, false); + } #endif return false; } esp_spiram_init_cache(); - if (!esp_spiram_test()) { + //testSPIRAM() allows user to bypass SPI RAM test routine + if (!testSPIRAM()) { spiramFailed = true; log_e("PSRAM test failed!"); return false; @@ -76,12 +89,12 @@ bool psramInit(){ log_e("PSRAM could not be added to the heap!"); return false; } -#if CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL && !CONFIG_ARDUINO_ISR_IRAM - heap_caps_malloc_extmem_enable(CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL); -#endif +#if CONFIG_SPIRAM_USE_MALLOC && !CONFIG_ARDUINO_ISR_IRAM + heap_caps_malloc_extmem_enable(CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL); #endif +#endif /* CONFIG_SPIRAM_BOOT_INIT */ + log_i("PSRAM enabled"); spiramDetected = true; - log_d("PSRAM enabled"); return true; } diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 9c619eea2c8..a220119d316 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -96,6 +96,7 @@ struct rmt_obj_s void * arg; TaskHandle_t rxTaskHandle; bool rx_completed; + bool tx_not_rx; }; /** @@ -109,15 +110,15 @@ static xSemaphoreHandle g_rmt_objlocks[MAX_CHANNELS] = { }; static rmt_obj_t g_rmt_objects[MAX_CHANNELS] = { - { false, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, true}, - { false, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, true}, - { false, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, true}, - { false, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, true}, + { false, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, true, true}, + { false, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, true, true}, + { false, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, true, true}, + { false, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, true, true}, #if MAX_CHANNELS > 4 - { false, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, true}, - { false, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, true}, - { false, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, true}, - { false, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, true}, + { false, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, true, true}, + { false, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, true, true}, + { false, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, true, true}, + { false, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, true, true}, #endif }; @@ -248,6 +249,26 @@ static bool _rmtCreateRxTask(rmt_obj_t* rmt) return true; } +// Helper function to test if an RMT channel is correctly assigned to TX or RX, issuing an error message if necessary +// Also test RMT pointer for NULL and returns false in case it is NULL +// return true when it is correctly assigned, false otherwise +static bool _rmtCheckTXnotRX(rmt_obj_t* rmt, bool tx_not_rx) +{ + if (!rmt) { // also returns false on NULL + return false; + } + + if (rmt->tx_not_rx == tx_not_rx) { // matches expected RX/TX channel + return true; + } + + if (tx_not_rx) { // expected TX channel + log_e("Can't write on a RX RMT Channel"); + } else{ // expected RX channel + log_e("Can't read on a TX RMT Channel"); + } + return false; // missmatched +} /** * Public method definitions @@ -255,7 +276,7 @@ static bool _rmtCreateRxTask(rmt_obj_t* rmt) bool rmtSetCarrier(rmt_obj_t* rmt, bool carrier_en, bool carrier_level, uint32_t low, uint32_t high) { - if (!rmt || low > 0xFFFF || high > 0xFFFF) { + if (!_rmtCheckTXnotRX(rmt, RMT_TX_MODE) || low > 0xFFFF || high > 0xFFFF) { return false; } size_t channel = rmt->channel; @@ -268,7 +289,7 @@ bool rmtSetCarrier(rmt_obj_t* rmt, bool carrier_en, bool carrier_level, uint32_t bool rmtSetFilter(rmt_obj_t* rmt, bool filter_en, uint32_t filter_level) { - if (!rmt || filter_level > 0xFF) { + if (!_rmtCheckTXnotRX(rmt, RMT_RX_MODE) || filter_level > 0xFF) { return false; } size_t channel = rmt->channel; @@ -281,7 +302,7 @@ bool rmtSetFilter(rmt_obj_t* rmt, bool filter_en, uint32_t filter_level) bool rmtSetRxThreshold(rmt_obj_t* rmt, uint32_t value) { - if (!rmt || value > 0xFFFF) { + if (!_rmtCheckTXnotRX(rmt, RMT_RX_MODE) || value > 0xFFFF) { return false; } size_t channel = rmt->channel; @@ -306,14 +327,17 @@ bool rmtDeinit(rmt_obj_t *rmt) RMT_MUTEX_LOCK(rmt->channel); // force stopping rmt processing - rmt_rx_stop(rmt->channel); - rmt_tx_stop(rmt->channel); + if (rmt->tx_not_rx) { + rmt_tx_stop(rmt->channel); + } else { + rmt_rx_stop(rmt->channel); + if(rmt->rxTaskHandle){ + vTaskDelete(rmt->rxTaskHandle); + rmt->rxTaskHandle = NULL; + } + } - if(rmt->rxTaskHandle){ - vTaskDelete(rmt->rxTaskHandle); - rmt->rxTaskHandle = NULL; - } - rmt_driver_uninstall(rmt->channel); + rmt_driver_uninstall(rmt->channel); size_t from = rmt->channel; size_t to = rmt->buffers + rmt->channel; @@ -330,6 +354,7 @@ bool rmtDeinit(rmt_obj_t *rmt) #if !CONFIG_DISABLE_HAL_LOCKS if(g_rmt_objlocks[from] != NULL) { vSemaphoreDelete(g_rmt_objlocks[from]); + g_rmt_objlocks[from] = NULL; } #endif @@ -338,10 +363,9 @@ bool rmtDeinit(rmt_obj_t *rmt) bool rmtLoop(rmt_obj_t* rmt, rmt_data_t* data, size_t size) { - if (!rmt) { + if (!_rmtCheckTXnotRX(rmt, RMT_TX_MODE)) { return false; } - int channel = rmt->channel; RMT_MUTEX_LOCK(channel); rmt_tx_stop(channel); @@ -353,10 +377,9 @@ bool rmtLoop(rmt_obj_t* rmt, rmt_data_t* data, size_t size) bool rmtWrite(rmt_obj_t* rmt, rmt_data_t* data, size_t size) { - if (!rmt) { + if (!_rmtCheckTXnotRX(rmt, RMT_TX_MODE)) { return false; } - int channel = rmt->channel; RMT_MUTEX_LOCK(channel); rmt_tx_stop(channel); @@ -368,10 +391,9 @@ bool rmtWrite(rmt_obj_t* rmt, rmt_data_t* data, size_t size) bool rmtWriteBlocking(rmt_obj_t* rmt, rmt_data_t* data, size_t size) { - if (!rmt) { + if (!_rmtCheckTXnotRX(rmt, RMT_TX_MODE)) { return false; } - int channel = rmt->channel; RMT_MUTEX_LOCK(channel); rmt_tx_stop(channel); @@ -383,10 +405,9 @@ bool rmtWriteBlocking(rmt_obj_t* rmt, rmt_data_t* data, size_t size) bool rmtReadData(rmt_obj_t* rmt, uint32_t* data, size_t size) { - if (!rmt) { + if (!_rmtCheckTXnotRX(rmt, RMT_RX_MODE)) { return false; } - rmtReadAsync(rmt, (rmt_data_t*) data, size, NULL, false, 0); return true; } @@ -394,7 +415,7 @@ bool rmtReadData(rmt_obj_t* rmt, uint32_t* data, size_t size) bool rmtBeginReceive(rmt_obj_t* rmt) { - if (!rmt) { + if (!_rmtCheckTXnotRX(rmt, RMT_RX_MODE)) { return false; } int channel = rmt->channel; @@ -418,7 +439,7 @@ bool rmtReceiveCompleted(rmt_obj_t* rmt) bool rmtRead(rmt_obj_t* rmt, rmt_rx_data_cb_t cb, void * arg) { - if (!rmt || !cb) { + if (!_rmtCheckTXnotRX(rmt, RMT_RX_MODE)) { return false; } int channel = rmt->channel; @@ -449,15 +470,19 @@ bool rmtEnd(rmt_obj_t* rmt) int channel = rmt->channel; RMT_MUTEX_LOCK(channel); - rmt_rx_stop(channel); - rmt->rx_completed = true; + if (rmt->tx_not_rx) { + rmt_tx_stop(channel); + } else { + rmt_rx_stop(channel); + rmt->rx_completed = true; + } RMT_MUTEX_UNLOCK(channel); return true; } bool rmtReadAsync(rmt_obj_t* rmt, rmt_data_t* data, size_t size, void* eventFlag, bool waitForData, uint32_t timeout) { - if (!rmt) { + if (!_rmtCheckTXnotRX(rmt, RMT_RX_MODE)) { return false; } int channel = rmt->channel; @@ -568,6 +593,7 @@ rmt_obj_t* rmtInit(int pin, bool tx_not_rx, rmt_reserve_memsize_t memsize) rmt->data_size = 0; rmt->rx_completed = false; rmt->events = NULL; + rmt->tx_not_rx = tx_not_rx; #if !CONFIG_DISABLE_HAL_LOCKS if(g_rmt_objlocks[channel] == NULL) { diff --git a/cores/esp32/esp32-hal-spi.c b/cores/esp32/esp32-hal-spi.c index c2671836a07..39ad027be55 100644 --- a/cores/esp32/esp32-hal-spi.c +++ b/cores/esp32/esp32-hal-spi.c @@ -37,6 +37,11 @@ #include "esp32s2/rom/ets_sys.h" #include "esp32s2/rom/gpio.h" #include "esp_intr_alloc.h" +#elif CONFIG_IDF_TARGET_ESP32S3 +#include "soc/dport_reg.h" +#include "esp32s3/rom/ets_sys.h" +#include "esp32s3/rom/gpio.h" +#include "esp_intr_alloc.h" #elif CONFIG_IDF_TARGET_ESP32C3 #include "esp32c3/rom/ets_sys.h" #include "esp32c3/rom/gpio.h" @@ -71,10 +76,20 @@ struct spi_struct_t { #define SPI_FSPI_SS_IDX(n) ((n==0)?FSPICS0_OUT_IDX:((n==1)?FSPICS1_OUT_IDX:((n==2)?FSPICS2_OUT_IDX:FSPICS0_OUT_IDX))) #define SPI_SS_IDX(p, n) ((p==0)?SPI_SPI_SS_IDX(n):((p==1)?SPI_SPI_SS_IDX(n):((p==2)?SPI_HSPI_SS_IDX(n):0))) -#define SPI_INTR_SOURCE(u) ((u==0)?ETS_SPI1_INTR_SOURCE:((u==1)?ETS_SPI2_INTR_SOURCE:((u==2)?ETS_SPI3_INTR_SOURCE:0))) +#elif CONFIG_IDF_TARGET_ESP32S3 +// ESP32S3 +#define SPI_COUNT (2) + +#define SPI_CLK_IDX(p) ((p==0)?FSPICLK_OUT_IDX:((p==1)?SPI3_CLK_OUT_IDX:0)) +#define SPI_MISO_IDX(p) ((p==0)?FSPIQ_OUT_IDX:((p==1)?SPI3_Q_OUT_IDX:0)) +#define SPI_MOSI_IDX(p) ((p==0)?FSPID_IN_IDX:((p==1)?SPI3_D_IN_IDX:0)) + +#define SPI_HSPI_SS_IDX(n) ((n==0)?SPI3_CS0_OUT_IDX:((n==1)?SPI3_CS1_OUT_IDX:0)) +#define SPI_FSPI_SS_IDX(n) ((n==0)?FSPICS0_OUT_IDX:((n==1)?FSPICS1_OUT_IDX:0)) +#define SPI_SS_IDX(p, n) ((p==0)?SPI_FSPI_SS_IDX(n):((p==1)?SPI_HSPI_SS_IDX(n):0)) #elif CONFIG_IDF_TARGET_ESP32C3 -// ESP32S2 +// ESP32C3 #define SPI_COUNT (1) #define SPI_CLK_IDX(p) FSPICLK_OUT_IDX @@ -84,8 +99,6 @@ struct spi_struct_t { #define SPI_SPI_SS_IDX(n) ((n==0)?FSPICS0_OUT_IDX:((n==1)?FSPICS1_OUT_IDX:((n==2)?FSPICS2_OUT_IDX:FSPICS0_OUT_IDX))) #define SPI_SS_IDX(p, n) SPI_SPI_SS_IDX(n) -#define SPI_INTR_SOURCE(u) ETS_SPI2_INTR_SOURCE - #else // ESP32 #define SPI_COUNT (4) @@ -99,8 +112,6 @@ struct spi_struct_t { #define SPI_VSPI_SS_IDX(n) ((n==0)?VSPICS0_OUT_IDX:((n==1)?VSPICS1_OUT_IDX:((n==2)?VSPICS2_OUT_IDX:VSPICS0_OUT_IDX))) #define SPI_SS_IDX(p, n) ((p==0)?SPI_SPI_SS_IDX(n):((p==1)?SPI_SPI_SS_IDX(n):((p==2)?SPI_HSPI_SS_IDX(n):((p==3)?SPI_VSPI_SS_IDX(n):0)))) -#define SPI_INTR_SOURCE(u) ((u==0)?ETS_SPI0_INTR_SOURCE:((u==1)?ETS_SPI1_INTR_SOURCE:((u==2)?ETS_SPI2_INTR_SOURCE:((p==3)?ETS_SPI3_INTR_SOURCE:0)))) - #endif #if CONFIG_DISABLE_HAL_LOCKS @@ -112,6 +123,11 @@ static spi_t _spi_bus_array[] = { {(volatile spi_dev_t *)(DR_REG_SPI1_BASE), 0}, {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 1}, {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), 2} +#elif CONFIG_IDF_TARGET_ESP32S3 + {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 0}, + {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), 1} +#elif CONFIG_IDF_TARGET_ESP32C3 + {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 0} #else {(volatile spi_dev_t *)(DR_REG_SPI0_BASE), 0}, {(volatile spi_dev_t *)(DR_REG_SPI1_BASE), 1}, @@ -128,8 +144,11 @@ static spi_t _spi_bus_array[] = { {(volatile spi_dev_t *)(DR_REG_SPI1_BASE), NULL, 0}, {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 1}, {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), NULL, 2} +#elif CONFIG_IDF_TARGET_ESP32S3 + {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0}, + {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), NULL, 1} #elif CONFIG_IDF_TARGET_ESP32C3 - {(volatile spi_dev_t *)(&GPSPI2), NULL, FSPI} + {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0} #else {(volatile spi_dev_t *)(DR_REG_SPI0_BASE), NULL, 0}, {(volatile spi_dev_t *)(DR_REG_SPI1_BASE), NULL, 1}, @@ -152,6 +171,13 @@ void spiAttachSCK(spi_t * spi, int8_t sck) log_e("HSPI Does not have default pins on ESP32S2!"); return; } +#elif CONFIG_IDF_TARGET_ESP32S3 + if(spi->num == FSPI) { + sck = 12; + } else { + log_e("HSPI Does not have default pins on ESP32S3!"); + return; + } #elif CONFIG_IDF_TARGET_ESP32 if(spi->num == HSPI) { sck = 14; @@ -182,6 +208,13 @@ void spiAttachMISO(spi_t * spi, int8_t miso) log_e("HSPI Does not have default pins on ESP32S2!"); return; } +#elif CONFIG_IDF_TARGET_ESP32S3 + if(spi->num == FSPI) { + miso = 13; + } else { + log_e("HSPI Does not have default pins on ESP32S3!"); + return; + } #elif CONFIG_IDF_TARGET_ESP32 if(spi->num == HSPI) { miso = 12; @@ -207,13 +240,20 @@ void spiAttachMOSI(spi_t * spi, int8_t mosi) return; } if(mosi < 0) { -#if CONFIG_IDF_TARGET_ESP32S2 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 if(spi->num == FSPI) { mosi = 35; } else { log_e("HSPI Does not have default pins on ESP32S2!"); return; } +#elif CONFIG_IDF_TARGET_ESP32S3 + if(spi->num == FSPI) { + mosi = 11; + } else { + log_e("HSPI Does not have default pins on ESP32S3!"); + return; + } #elif CONFIG_IDF_TARGET_ESP32 if(spi->num == HSPI) { mosi = 13; @@ -237,13 +277,20 @@ void spiDetachSCK(spi_t * spi, int8_t sck) return; } if(sck < 0) { -#if CONFIG_IDF_TARGET_ESP32S2 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 if(spi->num == FSPI) { sck = 36; } else { log_e("HSPI Does not have default pins on ESP32S2!"); return; } +#elif CONFIG_IDF_TARGET_ESP32S3 + if(spi->num == FSPI) { + sck = 12; + } else { + log_e("HSPI Does not have default pins on ESP32S3!"); + return; + } #elif CONFIG_IDF_TARGET_ESP32 if(spi->num == HSPI) { sck = 14; @@ -267,13 +314,20 @@ void spiDetachMISO(spi_t * spi, int8_t miso) return; } if(miso < 0) { -#if CONFIG_IDF_TARGET_ESP32S2 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 if(spi->num == FSPI) { miso = 37; } else { log_e("HSPI Does not have default pins on ESP32S2!"); return; } +#elif CONFIG_IDF_TARGET_ESP32S3 + if(spi->num == FSPI) { + miso = 13; + } else { + log_e("HSPI Does not have default pins on ESP32S3!"); + return; + } #elif CONFIG_IDF_TARGET_ESP32 if(spi->num == HSPI) { miso = 12; @@ -297,13 +351,20 @@ void spiDetachMOSI(spi_t * spi, int8_t mosi) return; } if(mosi < 0) { -#if CONFIG_IDF_TARGET_ESP32S2 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 if(spi->num == FSPI) { mosi = 35; } else { log_e("HSPI Does not have default pins on ESP32S2!"); return; } +#elif CONFIG_IDF_TARGET_ESP32S3 + if(spi->num == FSPI) { + mosi = 11; + } else { + log_e("HSPI Does not have default pins on ESP32S3!"); + return; + } #elif CONFIG_IDF_TARGET_ESP32 if(spi->num == HSPI) { mosi = 13; @@ -338,6 +399,13 @@ void spiAttachSS(spi_t * spi, uint8_t cs_num, int8_t ss) log_e("HSPI Does not have default pins on ESP32S2!"); return; } +#elif CONFIG_IDF_TARGET_ESP32S3 + if(spi->num == FSPI) { + ss = 10; + } else { + log_e("HSPI Does not have default pins on ESP32S3!"); + return; + } #elif CONFIG_IDF_TARGET_ESP32 if(spi->num == HSPI) { ss = 15; @@ -369,6 +437,13 @@ void spiDetachSS(spi_t * spi, int8_t ss) log_e("HSPI Does not have default pins on ESP32S2!"); return; } +#elif CONFIG_IDF_TARGET_ESP32S3 + if(spi->num == FSPI) { + ss = 10; + } else { + log_e("HSPI Does not have default pins on ESP32S3!"); + return; + } #elif CONFIG_IDF_TARGET_ESP32 if(spi->num == HSPI) { ss = 15; @@ -392,7 +467,7 @@ void spiEnableSSPins(spi_t * spi, uint8_t cs_mask) return; } SPI_MUTEX_LOCK(); -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 spi->dev->misc.val &= ~(cs_mask & SPI_CS_MASK_ALL); #else spi->dev->pin.val &= ~(cs_mask & SPI_CS_MASK_ALL); @@ -406,7 +481,7 @@ void spiDisableSSPins(spi_t * spi, uint8_t cs_mask) return; } SPI_MUTEX_LOCK(); -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 spi->dev->misc.val |= (cs_mask & SPI_CS_MASK_ALL); #else spi->dev->pin.val |= (cs_mask & SPI_CS_MASK_ALL); @@ -442,7 +517,7 @@ void spiSSSet(spi_t * spi) return; } SPI_MUTEX_LOCK(); -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 spi->dev->misc.cs_keep_active = 1; #else spi->dev->pin.cs_keep_active = 1; @@ -456,7 +531,7 @@ void spiSSClear(spi_t * spi) return; } SPI_MUTEX_LOCK(); -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 spi->dev->misc.cs_keep_active = 0; #else spi->dev->pin.cs_keep_active = 0; @@ -487,7 +562,7 @@ uint8_t spiGetDataMode(spi_t * spi) if(!spi) { return 0; } -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 bool idleEdge = spi->dev->misc.ck_idle_edge; #else bool idleEdge = spi->dev->pin.ck_idle_edge; @@ -513,7 +588,7 @@ void spiSetDataMode(spi_t * spi, uint8_t dataMode) SPI_MUTEX_LOCK(); switch (dataMode) { case SPI_MODE1: -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 spi->dev->misc.ck_idle_edge = 0; #else spi->dev->pin.ck_idle_edge = 0; @@ -521,7 +596,7 @@ void spiSetDataMode(spi_t * spi, uint8_t dataMode) spi->dev->user.ck_out_edge = 1; break; case SPI_MODE2: -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 spi->dev->misc.ck_idle_edge = 1; #else spi->dev->pin.ck_idle_edge = 1; @@ -529,7 +604,7 @@ void spiSetDataMode(spi_t * spi, uint8_t dataMode) spi->dev->user.ck_out_edge = 1; break; case SPI_MODE3: -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 spi->dev->misc.ck_idle_edge = 1; #else spi->dev->pin.ck_idle_edge = 1; @@ -538,7 +613,7 @@ void spiSetDataMode(spi_t * spi, uint8_t dataMode) break; case SPI_MODE0: default: -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 spi->dev->misc.ck_idle_edge = 0; #else spi->dev->pin.ck_idle_edge = 0; @@ -587,11 +662,11 @@ static void _on_apb_change(void * arg, apb_change_ev_t ev_type, uint32_t old_apb static void spiInitBus(spi_t * spi) { -#ifndef CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->slave.trans_done = 0; #endif spi->dev->slave.val = 0; -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 spi->dev->misc.val = 0; #else spi->dev->pin.val = 0; @@ -599,7 +674,7 @@ static void spiInitBus(spi_t * spi) spi->dev->user.val = 0; spi->dev->user1.val = 0; spi->dev->ctrl.val = 0; -#ifndef CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->ctrl1.val = 0; spi->dev->ctrl2.val = 0; #else @@ -652,6 +727,14 @@ spi_t * spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_ DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI01_CLK_EN); DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI01_RST); } +#elif CONFIG_IDF_TARGET_ESP32S3 + if(spi_num == FSPI) { + periph_module_reset( PERIPH_SPI2_MODULE ); + periph_module_enable( PERIPH_SPI2_MODULE ); + } else if(spi_num == HSPI) { + periph_module_reset( PERIPH_SPI3_MODULE ); + periph_module_enable( PERIPH_SPI3_MODULE ); + } #elif CONFIG_IDF_TARGET_ESP32 if(spi_num == HSPI) { DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI2_CLK_EN); @@ -670,7 +753,7 @@ spi_t * spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_ SPI_MUTEX_LOCK(); spiInitBus(spi); -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->clk_gate.clk_en = 1; spi->dev->clk_gate.mst_clk_sel = 1; spi->dev->clk_gate.mst_clk_active = 1; @@ -707,7 +790,7 @@ void spiWaitReady(spi_t * spi) #if CONFIG_IDF_TARGET_ESP32S2 #define usr_mosi_dbitlen usr_mosi_bit_len #define usr_miso_dbitlen usr_miso_bit_len -#elif CONFIG_IDF_TARGET_ESP32C3 +#elif CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 #define usr_mosi_dbitlen ms_data_bitlen #define usr_miso_dbitlen ms_data_bitlen #define mosi_dlen ms_dlen @@ -725,13 +808,13 @@ void spiWrite(spi_t * spi, const uint32_t *data, uint8_t len) } SPI_MUTEX_LOCK(); spi->dev->mosi_dlen.usr_mosi_dbitlen = (len * 32) - 1; -#ifndef CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif for(i=0; idev->data_buf[i] = data[i]; } -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -755,7 +838,7 @@ void spiTransfer(spi_t * spi, uint32_t *data, uint8_t len) for(i=0; idev->data_buf[i] = data[i]; } -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -774,11 +857,11 @@ void spiWriteByte(spi_t * spi, uint8_t data) } SPI_MUTEX_LOCK(); spi->dev->mosi_dlen.usr_mosi_dbitlen = 7; -#ifndef CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -796,7 +879,7 @@ uint8_t spiTransferByte(spi_t * spi, uint8_t data) spi->dev->mosi_dlen.usr_mosi_dbitlen = 7; spi->dev->miso_dlen.usr_miso_dbitlen = 7; spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -827,11 +910,11 @@ void spiWriteWord(spi_t * spi, uint16_t data) } SPI_MUTEX_LOCK(); spi->dev->mosi_dlen.usr_mosi_dbitlen = 15; -#ifndef CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -852,7 +935,7 @@ uint16_t spiTransferWord(spi_t * spi, uint16_t data) spi->dev->mosi_dlen.usr_mosi_dbitlen = 15; spi->dev->miso_dlen.usr_miso_dbitlen = 15; spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -876,11 +959,11 @@ void spiWriteLong(spi_t * spi, uint32_t data) } SPI_MUTEX_LOCK(); spi->dev->mosi_dlen.usr_mosi_dbitlen = 31; -#ifndef CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -901,7 +984,7 @@ uint32_t spiTransferLong(spi_t * spi, uint32_t data) spi->dev->mosi_dlen.usr_mosi_dbitlen = 31; spi->dev->miso_dlen.usr_miso_dbitlen = 31; spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -944,7 +1027,7 @@ static void __spiTransferBytes(spi_t * spi, const uint8_t * data, uint8_t * out, spi->dev->data_buf[i] = wordsBuf[i]; //copy buffer to spi fifo } -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1012,7 +1095,7 @@ void spiTransaction(spi_t * spi, uint32_t clockDiv, uint8_t dataMode, uint8_t bi spi->dev->clock.val = clockDiv; switch (dataMode) { case SPI_MODE1: -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 spi->dev->misc.ck_idle_edge = 0; #else spi->dev->pin.ck_idle_edge = 0; @@ -1020,7 +1103,7 @@ void spiTransaction(spi_t * spi, uint32_t clockDiv, uint8_t dataMode, uint8_t bi spi->dev->user.ck_out_edge = 1; break; case SPI_MODE2: -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 spi->dev->misc.ck_idle_edge = 1; #else spi->dev->pin.ck_idle_edge = 1; @@ -1028,7 +1111,7 @@ void spiTransaction(spi_t * spi, uint32_t clockDiv, uint8_t dataMode, uint8_t bi spi->dev->user.ck_out_edge = 1; break; case SPI_MODE3: -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 spi->dev->misc.ck_idle_edge = 1; #else spi->dev->pin.ck_idle_edge = 1; @@ -1037,7 +1120,7 @@ void spiTransaction(spi_t * spi, uint32_t clockDiv, uint8_t dataMode, uint8_t bi break; case SPI_MODE0: default: -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 spi->dev->misc.ck_idle_edge = 0; #else spi->dev->pin.ck_idle_edge = 0; @@ -1076,11 +1159,11 @@ void ARDUINO_ISR_ATTR spiWriteByteNL(spi_t * spi, uint8_t data) return; } spi->dev->mosi_dlen.usr_mosi_dbitlen = 7; -#ifndef CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1096,7 +1179,7 @@ uint8_t spiTransferByteNL(spi_t * spi, uint8_t data) spi->dev->mosi_dlen.usr_mosi_dbitlen = 7; spi->dev->miso_dlen.usr_miso_dbitlen = 7; spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1115,11 +1198,11 @@ void ARDUINO_ISR_ATTR spiWriteShortNL(spi_t * spi, uint16_t data) MSB_16_SET(data, data); } spi->dev->mosi_dlen.usr_mosi_dbitlen = 15; -#ifndef CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1138,7 +1221,7 @@ uint16_t spiTransferShortNL(spi_t * spi, uint16_t data) spi->dev->mosi_dlen.usr_mosi_dbitlen = 15; spi->dev->miso_dlen.usr_miso_dbitlen = 15; spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1160,11 +1243,11 @@ void ARDUINO_ISR_ATTR spiWriteLongNL(spi_t * spi, uint32_t data) MSB_32_SET(data, data); } spi->dev->mosi_dlen.usr_mosi_dbitlen = 31; -#ifndef CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1183,7 +1266,7 @@ uint32_t spiTransferLongNL(spi_t * spi, uint32_t data) spi->dev->mosi_dlen.usr_mosi_dbitlen = 31; spi->dev->miso_dlen.usr_miso_dbitlen = 31; spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1212,13 +1295,13 @@ void spiWriteNL(spi_t * spi, const void * data_in, uint32_t len){ c_longs = (longs > 16)?16:longs; spi->dev->mosi_dlen.usr_mosi_dbitlen = (c_len*8)-1; -#ifndef CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif for (int i=0; idev->data_buf[i] = data[i]; } -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1258,7 +1341,7 @@ void spiTransferBytesNL(spi_t * spi, const void * data_in, uint8_t * data_out, u spi->dev->data_buf[i] = 0xFFFFFFFF; } } -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1317,7 +1400,7 @@ void spiTransferBitsNL(spi_t * spi, uint32_t data, uint32_t * out, uint8_t bits) spi->dev->mosi_dlen.usr_mosi_dbitlen = (bits - 1); spi->dev->miso_dlen.usr_miso_dbitlen = (bits - 1); spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1353,7 +1436,7 @@ void ARDUINO_ISR_ATTR spiWritePixelsNL(spi_t * spi, const void * data_in, uint32 l_bytes = (c_len & 3); spi->dev->mosi_dlen.usr_mosi_dbitlen = (c_len*8)-1; -#ifndef CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif for (int i=0; idev->data_buf[i] = data[i]; } } -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1397,7 +1480,7 @@ typedef union { uint32_t clkcnt_l: 6; /*it must be equal to spi_clkcnt_N.*/ uint32_t clkcnt_h: 6; /*it must be floor((spi_clkcnt_N+1)/2-1).*/ uint32_t clkcnt_n: 6; /*it is the divider of spi_clk. So spi_clk frequency is system/(spi_clkdiv_pre+1)/(spi_clkcnt_N+1)*/ -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 uint32_t clkdiv_pre: 4; /*it is pre-divider of spi_clk.*/ uint32_t reserved: 9; /*reserved*/ #else @@ -1444,7 +1527,7 @@ uint32_t spiFrequencyToClockDiv(uint32_t freq) while(calPreVari++ <= 1) { calPre = (((apb_freq / (reg.clkcnt_n + 1)) / freq) - 1) + calPreVari; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 if(calPre > 0xF) { reg.clkdiv_pre = 0xF; #else @@ -1475,4 +1558,3 @@ uint32_t spiFrequencyToClockDiv(uint32_t freq) } return bestReg.value; } - diff --git a/cores/esp32/esp32-hal-spi.h b/cores/esp32/esp32-hal-spi.h index 6fbb7b3dca7..89ceefccd60 100644 --- a/cores/esp32/esp32-hal-spi.h +++ b/cores/esp32/esp32-hal-spi.h @@ -25,7 +25,7 @@ extern "C" { #define SPI_HAS_TRANSACTION -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 #define FSPI 0 #define HSPI 1 #else diff --git a/cores/esp32/esp32-hal-time.c b/cores/esp32/esp32-hal-time.c index 2d0276ff3e3..e7048307284 100644 --- a/cores/esp32/esp32-hal-time.c +++ b/cores/esp32/esp32-hal-time.c @@ -44,8 +44,6 @@ static void setTimeZone(long offset, int daylight) /* * configTime * Source: https://github.com/esp8266/Arduino/blob/master/cores/esp8266/time.c - * Note: Bundled Arduino lwip supports only ONE ntp server, 2nd and 3rd options are silently ignored - * see CONFIG_LWIP_DHCP_MAX_NTP_SERVERS define in ./tools/sdk/esp32/sdkconfig * */ void configTime(long gmtOffset_sec, int daylightOffset_sec, const char* server1, const char* server2, const char* server3) { @@ -65,8 +63,6 @@ void configTime(long gmtOffset_sec, int daylightOffset_sec, const char* server1, /* * configTzTime * sntp setup using TZ environment variable - * Note: Bundled Arduino lwip supports only ONE ntp server, 2nd and 3rd options are silently ignored - * see CONFIG_LWIP_DHCP_MAX_NTP_SERVERS define in ./tools/sdk/esp32/sdkconfig * */ void configTzTime(const char* tz, const char* server1, const char* server2, const char* server3) { diff --git a/cores/esp32/esp32-hal-timer.h b/cores/esp32/esp32-hal-timer.h index 7d0fe1f6336..5bbed623586 100644 --- a/cores/esp32/esp32-hal-timer.h +++ b/cores/esp32/esp32-hal-timer.h @@ -58,7 +58,7 @@ bool timerGetAutoReload(hw_timer_t *timer); void timerAlarmEnable(hw_timer_t *timer); void timerAlarmDisable(hw_timer_t *timer); -void timerAlarmWrite(hw_timer_t *timer, uint64_t interruptAt, bool autoreload); +void timerAlarmWrite(hw_timer_t *timer, uint64_t alarm_value, bool autoreload); bool timerAlarmEnabled(hw_timer_t *timer); uint64_t timerAlarmRead(hw_timer_t *timer); diff --git a/cores/esp32/esp32-hal-tinyusb.c b/cores/esp32/esp32-hal-tinyusb.c index a413c75260e..c34af2a9ef6 100644 --- a/cores/esp32/esp32-hal-tinyusb.c +++ b/cores/esp32/esp32-hal-tinyusb.c @@ -34,9 +34,16 @@ #include "esp32-hal.h" #include "esp32-hal-tinyusb.h" +#if CONFIG_IDF_TARGET_ESP32S2 #include "esp32s2/rom/usb/usb_persist.h" #include "esp32s2/rom/usb/usb_dc.h" #include "esp32s2/rom/usb/chip_usb_dw_wrapper.h" +#elif CONFIG_IDF_TARGET_ESP32S3 +#include "hal/usb_serial_jtag_ll.h" +#include "esp32s3/rom/usb/usb_persist.h" +#include "esp32s3/rom/usb/usb_dc.h" +#include "esp32s3/rom/usb/chip_usb_dw_wrapper.h" +#endif typedef enum{ TINYUSB_USBDEV_0, @@ -370,6 +377,120 @@ __attribute__ ((weak)) int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_ static bool usb_persist_enabled = false; static restart_type_t usb_persist_mode = RESTART_NO_PERSIST; +#if CONFIG_IDF_TARGET_ESP32S3 + +static void hw_cdc_reset_handler(void *arg) { + portBASE_TYPE xTaskWoken = 0; + uint32_t usbjtag_intr_status = usb_serial_jtag_ll_get_intsts_mask(); + usb_serial_jtag_ll_clr_intsts_mask(usbjtag_intr_status); + + if (usbjtag_intr_status & USB_SERIAL_JTAG_INTR_BUS_RESET) { + xSemaphoreGiveFromISR((xSemaphoreHandle)arg, &xTaskWoken); + } + + if (xTaskWoken == pdTRUE) { + portYIELD_FROM_ISR(); + } +} + +static void usb_switch_to_cdc_jtag(){ + // Disable USB-OTG + periph_module_reset(PERIPH_USB_MODULE); + //periph_module_enable(PERIPH_USB_MODULE); + periph_module_disable(PERIPH_USB_MODULE); + + // Switch to hardware CDC+JTAG + CLEAR_PERI_REG_MASK(RTC_CNTL_USB_CONF_REG, (RTC_CNTL_SW_HW_USB_PHY_SEL|RTC_CNTL_SW_USB_PHY_SEL|RTC_CNTL_USB_PAD_ENABLE)); + + // Do not use external PHY + CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_PHY_SEL); + + // Release GPIO pins from CDC+JTAG + CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_USB_PAD_ENABLE); + + // Force the host to re-enumerate (BUS_RESET) + pinMode(USBPHY_DM_NUM, OUTPUT_OPEN_DRAIN); + pinMode(USBPHY_DP_NUM, OUTPUT_OPEN_DRAIN); + digitalWrite(USBPHY_DM_NUM, LOW); + digitalWrite(USBPHY_DP_NUM, LOW); + + // Initialize CDC+JTAG ISR to listen for BUS_RESET + usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_LL_INTR_MASK); + usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_LL_INTR_MASK); + usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_BUS_RESET); + intr_handle_t intr_handle = NULL; + xSemaphoreHandle reset_sem = xSemaphoreCreateBinary(); + if(reset_sem){ + if(esp_intr_alloc(ETS_USB_SERIAL_JTAG_INTR_SOURCE, 0, hw_cdc_reset_handler, reset_sem, &intr_handle) != ESP_OK){ + vSemaphoreDelete(reset_sem); + reset_sem = NULL; + log_e("HW USB CDC failed to init interrupts"); + } + } else { + log_e("reset_sem init failed"); + } + + // Connect GPIOs to integrated CDC+JTAG + SET_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_USB_PAD_ENABLE); + + // Wait for BUS_RESET to give us back the semaphore + if(reset_sem){ + if(xSemaphoreTake(reset_sem, 1000 / portTICK_PERIOD_MS) != pdPASS){ + log_e("reset_sem timeout"); + } + usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_LL_INTR_MASK); + esp_intr_free(intr_handle); + vSemaphoreDelete(reset_sem); + } +} +#endif + +static void IRAM_ATTR usb_persist_shutdown_handler(void) +{ + if(usb_persist_mode != RESTART_NO_PERSIST){ + if (usb_persist_enabled) { + usb_dc_prepare_persist(); + } + if (usb_persist_mode == RESTART_BOOTLOADER) { + //USB CDC Download + if (usb_persist_enabled) { + chip_usb_set_persist_flags(USBDC_PERSIST_ENA); +#if CONFIG_IDF_TARGET_ESP32S2 + } else { + periph_module_reset(PERIPH_USB_MODULE); + periph_module_enable(PERIPH_USB_MODULE); +#endif + } + REG_WRITE(RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT); + } else if (usb_persist_mode == RESTART_BOOTLOADER_DFU) { + //DFU Download +#if CONFIG_IDF_TARGET_ESP32S2 + // Reset USB Core + USB0.grstctl |= USB_CSFTRST; + while ((USB0.grstctl & USB_CSFTRST) == USB_CSFTRST){} +#endif + chip_usb_set_persist_flags(USBDC_BOOT_DFU); + REG_WRITE(RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT); + } else if (usb_persist_enabled) { + //USB Persist reboot + chip_usb_set_persist_flags(USBDC_PERSIST_ENA); + } + } +} + +void usb_persist_restart(restart_type_t mode) +{ + if (mode < RESTART_TYPE_MAX && esp_register_shutdown_handler(usb_persist_shutdown_handler) == ESP_OK) { + usb_persist_mode = mode; +#if CONFIG_IDF_TARGET_ESP32S3 + if (mode == RESTART_BOOTLOADER) { + usb_switch_to_cdc_jtag(); + } +#endif + esp_restart(); + } +} + static bool tinyusb_reserve_in_endpoint(uint8_t endpoint){ if(endpoint > 6 || (tinyusb_endpoints.in & BIT(endpoint)) != 0){ return false; @@ -515,35 +636,6 @@ static void tinyusb_apply_device_config(tinyusb_device_config_t *config){ tinyusb_device_descriptor.bDeviceProtocol = config->usb_protocol; } -static void IRAM_ATTR usb_persist_shutdown_handler(void) -{ - if(usb_persist_mode != RESTART_NO_PERSIST){ - if (usb_persist_enabled) { - usb_dc_prepare_persist(); - } - if (usb_persist_mode == RESTART_BOOTLOADER) { - //USB CDC Download - if (usb_persist_enabled) { - chip_usb_set_persist_flags(USBDC_PERSIST_ENA); - } else { - periph_module_reset(PERIPH_USB_MODULE); - periph_module_enable(PERIPH_USB_MODULE); - } - REG_WRITE(RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT); - } else if (usb_persist_mode == RESTART_BOOTLOADER_DFU) { - //DFU Download - // Reset USB Core - USB0.grstctl |= USB_CSFTRST; - while ((USB0.grstctl & USB_CSFTRST) == USB_CSFTRST){} - chip_usb_set_persist_flags(USBDC_BOOT_DFU); - REG_WRITE(RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT); - } else if (usb_persist_enabled) { - //USB Persist reboot - chip_usb_set_persist_flags(USBDC_PERSIST_ENA); - } - } -} - // USB Device Driver task // This top level thread processes all usb events and invokes callbacks static void usb_device_task(void *param) { @@ -607,11 +699,6 @@ esp_err_t tinyusb_init(tinyusb_device_config_t *config) { periph_module_enable(PERIPH_USB_MODULE); } - if (esp_register_shutdown_handler(usb_persist_shutdown_handler) != ESP_OK) { - tinyusb_is_initialized = false; - return ESP_FAIL; - } - tinyusb_config_t tusb_cfg = { .external_phy = false // In the most cases you need to use a `false` value }; @@ -624,14 +711,6 @@ esp_err_t tinyusb_init(tinyusb_device_config_t *config) { return err; } -void usb_persist_restart(restart_type_t mode) -{ - if (mode < RESTART_TYPE_MAX) { - usb_persist_mode = mode; - esp_restart(); - } -} - uint8_t tinyusb_add_string_descriptor(const char * str){ if(str == NULL || tinyusb_string_descriptor_len >= MAX_STRING_DESCRIPTORS){ return 0; diff --git a/cores/esp32/esp32-hal-tinyusb.h b/cores/esp32/esp32-hal-tinyusb.h index 7332887a2b0..84e156e874d 100644 --- a/cores/esp32/esp32-hal-tinyusb.h +++ b/cores/esp32/esp32-hal-tinyusb.h @@ -15,7 +15,6 @@ #include "esp32-hal.h" -#if CONFIG_IDF_TARGET_ESP32S2 #if CONFIG_TINYUSB_ENABLED #ifdef __cplusplus @@ -105,4 +104,3 @@ uint8_t tinyusb_get_free_out_endpoint(void); #endif #endif /* CONFIG_TINYUSB_ENABLED */ -#endif /* CONFIG_IDF_TARGET_ESP32S2 */ diff --git a/cores/esp32/esp32-hal-touch.c b/cores/esp32/esp32-hal-touch.c index 1492eff78a8..539c0004f98 100644 --- a/cores/esp32/esp32-hal-touch.c +++ b/cores/esp32/esp32-hal-touch.c @@ -12,219 +12,268 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "esp32-hal-touch.h" -#ifndef CONFIG_IDF_TARGET_ESP32C3 -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "esp_attr.h" -#include "soc/rtc_io_reg.h" -#include "soc/sens_reg.h" -#include "soc/sens_struct.h" -#include "soc/rtc_cntl_reg.h" +#include "soc/soc_caps.h" +#if SOC_TOUCH_SENSOR_NUM > 0 + #include "driver/touch_sensor.h" +#include "esp32-hal-touch.h" -#include "esp_system.h" -#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ -#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 -#include "esp32/rom/ets_sys.h" -#include "esp_intr_alloc.h" -#elif CONFIG_IDF_TARGET_ESP32S2 -#include "esp32s2/rom/ets_sys.h" -#include "esp_intr_alloc.h" -#include "soc/periph_defs.h" -#else -#error Target CONFIG_IDF_TARGET is not supported -#endif -#else // ESP32 Before IDF 4.0 -#include "rom/ets_sys.h" -#include "esp_intr.h" -#endif +/* + Internal Private Touch Data Structure and Functions +*/ +#if SOC_TOUCH_VERSION_1 // ESP32 static uint16_t __touchSleepCycles = 0x1000; static uint16_t __touchMeasureCycles = 0x1000; +#elif SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3 +static uint16_t __touchSleepCycles = TOUCH_PAD_SLEEP_CYCLE_DEFAULT; +static uint16_t __touchMeasureCycles = TOUCH_PAD_MEASURE_CYCLE_DEFAULT; +#endif typedef void (*voidFuncPtr)(void); -static voidFuncPtr __touchInterruptHandlers[10] = {0,}; -static intr_handle_t touch_intr_handle = NULL; +typedef void (*voidArgFuncPtr)(void *); + +typedef struct { + voidFuncPtr fn; + bool callWithArgs; + void* arg; +#if SOC_TOUCH_VERSION_2 // Only for ESP32S2 and ESP32S3 + bool lastStatusIsPressed; +#endif +} TouchInterruptHandle_t; -void ARDUINO_ISR_ATTR __touchISR(void * arg) +static TouchInterruptHandle_t __touchInterruptHandlers[SOC_TOUCH_SENSOR_NUM] = {0,}; + +static void ARDUINO_ISR_ATTR __touchISR(void * arg) { -#if CONFIG_IDF_TARGET_ESP32 - uint32_t pad_intr = READ_PERI_REG(SENS_SAR_TOUCH_CTRL2_REG) & 0x3ff; - uint32_t rtc_intr = READ_PERI_REG(RTC_CNTL_INT_ST_REG); - uint8_t i = 0; +#if SOC_TOUCH_VERSION_1 // ESP32 + uint32_t pad_intr = touch_pad_get_status(); //clear interrupt - WRITE_PERI_REG(RTC_CNTL_INT_CLR_REG, rtc_intr); - SET_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_MEAS_EN_CLR); - - if (rtc_intr & RTC_CNTL_TOUCH_INT_ST) { - for (i = 0; i < 10; ++i) { - if ((pad_intr >> i) & 0x01) { - if(__touchInterruptHandlers[i]){ - __touchInterruptHandlers[i](); + touch_pad_clear_status(); + // call Pad ISR User callback + for (int i = 0; i < SOC_TOUCH_SENSOR_NUM; i++) { + if ((pad_intr >> i) & 0x01) { + if(__touchInterruptHandlers[i].fn){ + // keeping backward compatibility with "void cb(void)" and with new "void cb(vooid *)" + if (__touchInterruptHandlers[i].callWithArgs) { + ((voidArgFuncPtr)__touchInterruptHandlers[i].fn)(__touchInterruptHandlers[i].arg); + } else { + __touchInterruptHandlers[i].fn(); } } } } +#elif SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3 + touch_pad_intr_mask_t evt = touch_pad_read_intr_status_mask(); + uint8_t pad_num = touch_pad_get_current_meas_channel(); + if (evt & TOUCH_PAD_INTR_MASK_ACTIVE) { + // touch has been pressed / touched + __touchInterruptHandlers[pad_num].lastStatusIsPressed = true; + } + if (evt & TOUCH_PAD_INTR_MASK_INACTIVE) { + // touch has been released / untouched + __touchInterruptHandlers[pad_num].lastStatusIsPressed = false; + } + if(__touchInterruptHandlers[pad_num].fn){ + // keeping backward compatibility with "void cb(void)" and with new "void cb(vooid *)" + if (__touchInterruptHandlers[pad_num].callWithArgs) { + ((voidArgFuncPtr)__touchInterruptHandlers[pad_num].fn)(__touchInterruptHandlers[pad_num].arg); + } else { + __touchInterruptHandlers[pad_num].fn(); + } + } #endif } -void __touchSetCycles(uint16_t measure, uint16_t sleep) + + +static void __touchSetCycles(uint16_t measure, uint16_t sleep) { __touchSleepCycles = sleep; __touchMeasureCycles = measure; -#if CONFIG_IDF_TARGET_ESP32 - //Touch pad SleepCycle Time - SET_PERI_REG_BITS(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_SLEEP_CYCLES, __touchSleepCycles, SENS_TOUCH_SLEEP_CYCLES_S); - //Touch Pad Measure Time - SET_PERI_REG_BITS(SENS_SAR_TOUCH_CTRL1_REG, SENS_TOUCH_MEAS_DELAY, __touchMeasureCycles, SENS_TOUCH_MEAS_DELAY_S); -#else touch_pad_set_meas_time(sleep, measure); -#endif } -void __touchInit() + + +static void __touchInit() { static bool initialized = false; if(initialized){ return; } - initialized = true; -#if CONFIG_IDF_TARGET_ESP32 - SET_PERI_REG_BITS(RTC_IO_TOUCH_CFG_REG, RTC_IO_TOUCH_XPD_BIAS, 1, RTC_IO_TOUCH_XPD_BIAS_S); - SET_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_MEAS_EN_CLR); - //clear touch enable - WRITE_PERI_REG(SENS_SAR_TOUCH_ENABLE_REG, 0x0); - SET_PERI_REG_MASK(RTC_CNTL_STATE0_REG, RTC_CNTL_TOUCH_SLP_TIMER_EN); - __touchSetCycles(__touchMeasureCycles, __touchSleepCycles); - esp_intr_alloc(ETS_RTC_CORE_INTR_SOURCE, (int)ARDUINO_ISR_FLAG, __touchISR, NULL, &touch_intr_handle); -#else - touch_pad_init(); - touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_0V5); - touch_pad_set_idle_channel_connect(TOUCH_PAD_CONN_GND); - __touchSetCycles(__touchMeasureCycles, __touchSleepCycles); + + esp_err_t err = ESP_OK; + +#if SOC_TOUCH_VERSION_1 // ESP32 + err = touch_pad_init(); + if (err != ESP_OK) { + goto err; + } + // the next two lines will drive the touch reading values -- both will return ESP_OK + touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_0V); + touch_pad_set_meas_time(__touchMeasureCycles, __touchSleepCycles); + // Touch Sensor Timer initiated + touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); // returns ESP_OK + err = touch_pad_filter_start(10); + if (err != ESP_OK) { + goto err; + } + // keep ISR activated - it can run all together (ISR + touchRead()) + err = touch_pad_isr_register(__touchISR, NULL); + if (err != ESP_OK) { + goto err; + } + touch_pad_intr_enable(); // returns ESP_OK +#elif SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3 + err = touch_pad_init(); + if (err != ESP_OK) { + goto err; + } + // the next lines will drive the touch reading values -- all os them return ESP_OK + touch_pad_set_meas_time(__touchSleepCycles, __touchMeasureCycles); + touch_pad_set_voltage(TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD, TOUCH_PAD_LOW_VOLTAGE_THRESHOLD, TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD); + touch_pad_set_idle_channel_connect(TOUCH_PAD_IDLE_CH_CONNECT_DEFAULT); touch_pad_denoise_t denoise = { .grade = TOUCH_PAD_DENOISE_BIT4, .cap_level = TOUCH_PAD_DENOISE_CAP_L4, }; touch_pad_denoise_set_config(&denoise); touch_pad_denoise_enable(); - touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); - touch_pad_fsm_start(); + // Touch Sensor Timer initiated + touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); // returns ESP_OK + touch_pad_fsm_start(); // returns ESP_OK + //ISR setup moved to __touchChannelInit +#endif + + initialized = true; + return; +err: + log_e(" Touch sensor initialization error."); + initialized = false; + return; +} + +static void __touchChannelInit(int pad) +{ + static bool channels_initialized[SOC_TOUCH_SENSOR_NUM] = { false }; + if(channels_initialized[pad]){ + return; + } + +#if SOC_TOUCH_VERSION_1 // ESP32 + // Initial no Threshold and setup + __touchInterruptHandlers[pad].fn = NULL; + touch_pad_config(pad, SOC_TOUCH_PAD_THRESHOLD_MAX); // returns ESP_OK +#elif SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3 + // Initial no Threshold and setup + __touchInterruptHandlers[pad].fn = NULL; + touch_pad_config(pad); // returns ESP_OK + // keep ISR activated - it can run all together (ISR + touchRead()) + esp_err_t err = touch_pad_isr_register(__touchISR, NULL, TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE); + if (err != ESP_OK) { + log_e(" Touch sensor initialization error."); + return; + } + touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE); // returns ESP_OK #endif + + channels_initialized[pad] = true; + delay(20); //delay needed before reading from touch channel after config } -uint16_t __touchRead(uint8_t pin) +static touch_value_t __touchRead(uint8_t pin) { int8_t pad = digitalPinToTouchChannel(pin); if(pad < 0){ return 0; } - pinMode(pin, ANALOG); - __touchInit(); + __touchChannelInit(pad); -#if CONFIG_IDF_TARGET_ESP32 - uint32_t v0 = READ_PERI_REG(SENS_SAR_TOUCH_ENABLE_REG); - //Disable Intr & enable touch pad - WRITE_PERI_REG(SENS_SAR_TOUCH_ENABLE_REG, - (v0 & ~((1 << (pad + SENS_TOUCH_PAD_OUTEN2_S)) | (1 << (pad + SENS_TOUCH_PAD_OUTEN1_S)))) - | (1 << (pad + SENS_TOUCH_PAD_WORKEN_S))); - - SET_PERI_REG_MASK(SENS_SAR_TOUCH_ENABLE_REG, (1 << (pad + SENS_TOUCH_PAD_WORKEN_S))); - - uint32_t rtc_tio_reg = RTC_IO_TOUCH_PAD0_REG + pad * 4; - WRITE_PERI_REG(rtc_tio_reg, (READ_PERI_REG(rtc_tio_reg) - & ~(RTC_IO_TOUCH_PAD0_DAC_M)) - | (7 << RTC_IO_TOUCH_PAD0_DAC_S)//Touch Set Slope - | RTC_IO_TOUCH_PAD0_TIE_OPT_M //Enable Tie,Init Level - | RTC_IO_TOUCH_PAD0_START_M //Enable Touch Pad IO - | RTC_IO_TOUCH_PAD0_XPD_M); //Enable Touch Pad Power on - - //force oneTime test start - SET_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_START_EN_M|SENS_TOUCH_START_FORCE_M); - - SET_PERI_REG_BITS(SENS_SAR_TOUCH_CTRL1_REG, SENS_TOUCH_XPD_WAIT, 10, SENS_TOUCH_XPD_WAIT_S); + touch_value_t touch_value; + touch_pad_read_raw_data(pad, &touch_value); - while (GET_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_MEAS_DONE) == 0) {}; - - uint16_t touch_value = READ_PERI_REG(SENS_SAR_TOUCH_OUT1_REG + (pad / 2) * 4) >> ((pad & 1) ? SENS_TOUCH_MEAS_OUT1_S : SENS_TOUCH_MEAS_OUT0_S); - - //clear touch force ,select the Touch mode is Timer - CLEAR_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_START_EN_M|SENS_TOUCH_START_FORCE_M); - - //restore previous value - WRITE_PERI_REG(SENS_SAR_TOUCH_ENABLE_REG, v0); return touch_value; -#else - static uint32_t chan_mask = 0; - uint32_t value = 0; - if((chan_mask & (1 << pad)) == 0){ - if(touch_pad_set_thresh((touch_pad_t)pad, TOUCH_PAD_THRESHOLD_MAX) != ESP_OK){ - log_e("touch_pad_set_thresh failed"); - } else if(touch_pad_config((touch_pad_t)pad) != ESP_OK){ - log_e("touch_pad_config failed"); - } else { - chan_mask |= (1 << pad); - } - } - if((chan_mask & (1 << pad)) != 0) { - if(touch_pad_read_raw_data((touch_pad_t)pad, &value) != ESP_OK){ - log_e("touch_pad_read_raw_data failed"); - } - } - return value; -#endif } -void __touchAttachInterrupt(uint8_t pin, void (*userFunc)(void), uint16_t threshold) +static void __touchConfigInterrupt(uint8_t pin, void (*userFunc)(void), void *Args, touch_value_t threshold, bool callWithArgs) { int8_t pad = digitalPinToTouchChannel(pin); if(pad < 0){ return; } - pinMode(pin, ANALOG); + if (userFunc == NULL) { + // dettach ISR User Call + __touchInterruptHandlers[pad].fn = NULL; + threshold = SOC_TOUCH_PAD_THRESHOLD_MAX; // deactivate the ISR with SOC_TOUCH_PAD_THRESHOLD_MAX + } else { + // attach ISR User Call + __touchInit(); + #if SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3 + __touchChannelInit(pad); + #endif + __touchInterruptHandlers[pad].fn = userFunc; + __touchInterruptHandlers[pad].callWithArgs = callWithArgs; + __touchInterruptHandlers[pad].arg = Args; + } - __touchInit(); +#if SOC_TOUCH_VERSION_1 // ESP32 + touch_pad_config(pad, threshold); +#elif SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3 + touch_pad_set_thresh(pad, threshold); +#endif +} - __touchInterruptHandlers[pad] = userFunc; - -#if CONFIG_IDF_TARGET_ESP32 - //clear touch force ,select the Touch mode is Timer - CLEAR_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_START_EN_M|SENS_TOUCH_START_FORCE_M); - - //interrupt when touch value < threshold - CLEAR_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL1_REG, SENS_TOUCH_OUT_SEL); - //Intr will give ,when SET0 < threshold - SET_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL1_REG, SENS_TOUCH_OUT_1EN); - //Enable Rtc Touch Module Intr,the Interrupt need Rtc out Enable - SET_PERI_REG_MASK(RTC_CNTL_INT_ENA_REG, RTC_CNTL_TOUCH_INT_ENA); - - //set threshold - uint8_t shift = (pad & 1) ? SENS_TOUCH_OUT_TH1_S : SENS_TOUCH_OUT_TH0_S; - SET_PERI_REG_BITS((SENS_SAR_TOUCH_THRES1_REG + (pad / 2) * 4), SENS_TOUCH_OUT_TH0, threshold, shift); - - uint32_t rtc_tio_reg = RTC_IO_TOUCH_PAD0_REG + pad * 4; - WRITE_PERI_REG(rtc_tio_reg, (READ_PERI_REG(rtc_tio_reg) - & ~(RTC_IO_TOUCH_PAD0_DAC_M)) - | (7 << RTC_IO_TOUCH_PAD0_DAC_S)//Touch Set Slope - | RTC_IO_TOUCH_PAD0_TIE_OPT_M //Enable Tie,Init Level - | RTC_IO_TOUCH_PAD0_START_M //Enable Touch Pad IO - | RTC_IO_TOUCH_PAD0_XPD_M); //Enable Touch Pad Power on - - //Enable Digital rtc control :work mode and out mode - SET_PERI_REG_MASK(SENS_SAR_TOUCH_ENABLE_REG, - (1 << (pad + SENS_TOUCH_PAD_WORKEN_S)) | \ - (1 << (pad + SENS_TOUCH_PAD_OUTEN2_S)) | \ - (1 << (pad + SENS_TOUCH_PAD_OUTEN1_S))); -#else +// it keeps backwards compatibility +static void __touchAttachInterrupt(uint8_t pin, void (*userFunc)(void), touch_value_t threshold) +{ + __touchConfigInterrupt(pin, userFunc, NULL, threshold, false); +} -#endif +// new additional version of the API with User Args +static void __touchAttachArgsInterrupt(uint8_t pin, void (*userFunc)(void), void *args, touch_value_t threshold) +{ + __touchConfigInterrupt(pin, userFunc, args, threshold, true); +} + +// new additional API to dettach touch ISR +static void __touchDettachInterrupt(uint8_t pin) +{ + __touchConfigInterrupt(pin, NULL, NULL, 0, false); // userFunc as NULL acts as dettaching +} + + +/* + External Public Touch API Functions +*/ + +#if SOC_TOUCH_VERSION_1 // Only for ESP32 SoC +void touchInterruptSetThresholdDirection(bool mustbeLower) { + if (mustbeLower) { + touch_pad_set_trigger_mode(TOUCH_TRIGGER_BELOW); + } else { + touch_pad_set_trigger_mode(TOUCH_TRIGGER_ABOVE); + } } +#elif SOC_TOUCH_VERSION_2 // Only for ESP32S2 and ESP32S3 +// returns true if touch pad has been and continues pressed and false otherwise +bool touchInterruptGetLastStatus(uint8_t pin) { + int8_t pad = digitalPinToTouchChannel(pin); + if(pad < 0){ + return false; + } -extern uint16_t touchRead(uint8_t pin) __attribute__ ((weak, alias("__touchRead"))); -extern void touchAttachInterrupt(uint8_t pin, void (*userFunc)(void), uint16_t threshold) __attribute__ ((weak, alias("__touchAttachInterrupt"))); -extern void touchSetCycles(uint16_t measure, uint16_t sleep) __attribute__ ((weak, alias("__touchSetCycles"))); + return __touchInterruptHandlers[pad].lastStatusIsPressed; +} #endif + +extern touch_value_t touchRead(uint8_t) __attribute__ ((weak, alias("__touchRead"))); +extern void touchAttachInterrupt(uint8_t, voidFuncPtr, touch_value_t) __attribute__ ((weak, alias("__touchAttachInterrupt"))); +extern void touchAttachInterruptArg(uint8_t, voidArgFuncPtr, void *, touch_value_t) __attribute__ ((weak, alias("__touchAttachArgsInterrupt"))); +extern void touchDetachInterrupt(uint8_t) __attribute__ ((weak, alias("__touchDettachInterrupt"))); +extern void touchSetCycles(uint16_t, uint16_t) __attribute__ ((weak, alias("__touchSetCycles"))); + +#endif // #if SOC_TOUCH_SENSOR_NUM > 0 diff --git a/cores/esp32/esp32-hal-touch.h b/cores/esp32/esp32-hal-touch.h index 6f3b0fd0f7d..a8cda191c31 100644 --- a/cores/esp32/esp32-hal-touch.h +++ b/cores/esp32/esp32-hal-touch.h @@ -24,8 +24,21 @@ extern "C" { #endif +#include "soc/soc_caps.h" #include "esp32-hal.h" +#if SOC_TOUCH_SENSOR_NUM > 0 + +#if !defined(SOC_TOUCH_VERSION_1) && !defined(SOC_TOUCH_VERSION_2) +#error Touch IDF driver Not supported! +#endif + +#if SOC_TOUCH_VERSION_1 // ESP32 +typedef uint16_t touch_value_t; +#elif SOC_TOUCH_VERSION_2 // ESP32S2 ESP32S3 +typedef uint32_t touch_value_t; +#endif + /* * Set cycles that measurement operation takes * The result from touchRead, threshold and detection @@ -40,17 +53,44 @@ void touchSetCycles(uint16_t measure, uint16_t sleep); * You can use this method to chose a good threshold value * to use as value for touchAttachInterrupt * */ -uint16_t touchRead(uint8_t pin); +touch_value_t touchRead(uint8_t pin); /* - * Set function to be called if touch pad value falls - * below the given threshold. Use touchRead to determine - * a proper threshold between touched and untouched state + * Set function to be called if touch pad value falls (ESP32) + * below the given threshold / rises (ESP32-S2/S3) by given increment (threshold). + * Use touchRead to determine a proper threshold between touched and untouched state * */ -void touchAttachInterrupt(uint8_t pin, void (*userFunc)(void), uint16_t threshold); +void touchAttachInterrupt(uint8_t pin, void (*userFunc)(void), touch_value_t threshold); +void touchAttachInterruptArg(uint8_t pin, void (*userFunc)(void*), void *arg, touch_value_t threshold); +void touchDetachInterrupt(uint8_t pin); + +/* + * Specific functions to ESP32 + * Tells the driver if it shall activate the ISR if the sensor is Lower or Higher than the Threshold + * Default if Lower. + **/ + +#if SOC_TOUCH_VERSION_1 // Only for ESP32 SoC +void touchInterruptSetThresholdDirection(bool mustbeLower); +#endif + + +/* + * Specific functions to ESP32-S2 and ESP32-S3 + * Returns true when the latest ISR status for the Touchpad is that it is touched (Active) + * and false when the Touchpad is untoouched (Inactive) + * This function can be used in conjunction with ISR User callback in order to take action + * as soon as the touchpad is touched and/or released + **/ + +#if SOC_TOUCH_VERSION_2 // Only for ESP32S2 and ESP32S3 +// returns true if touch pad has been and continues pressed and false otherwise +bool touchInterruptGetLastStatus(uint8_t pin); +#endif + +#endif // SOC_TOUCH_SENSOR_NUM > 0 #ifdef __cplusplus } #endif - #endif /* MAIN_ESP32_HAL_TOUCH_H_ */ diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index c34c54b1a25..80030b8fabc 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -34,7 +34,7 @@ struct uart_struct_t { uint8_t num; bool has_peek; uint8_t peek_byte; - + QueueHandle_t uart_event_queue; // export it by some uartGetEventQueue() function }; #if CONFIG_DISABLE_HAL_LOCKS @@ -43,12 +43,12 @@ struct uart_struct_t { #define UART_MUTEX_UNLOCK() static uart_t _uart_bus_array[] = { - {0, false, 0}, + {0, false, 0, NULL}, #if SOC_UART_NUM > 1 - {1, false, 0}, + {1, false, 0, NULL}, #endif #if SOC_UART_NUM > 2 - {2, false, 0}, + {2, false, 0, NULL}, #endif }; @@ -58,12 +58,12 @@ static uart_t _uart_bus_array[] = { #define UART_MUTEX_UNLOCK() xSemaphoreGive(uart->lock) static uart_t _uart_bus_array[] = { - {NULL, 0, false, 0}, + {NULL, 0, false, 0, NULL}, #if SOC_UART_NUM > 1 - {NULL, 1, false, 0}, + {NULL, 1, false, 0, NULL}, #endif #if SOC_UART_NUM > 2 - {NULL, 2, false, 0}, + {NULL, 2, false, 0, NULL}, #endif }; @@ -82,10 +82,22 @@ uint32_t _get_effective_baudrate(uint32_t baudrate) } } +// Routines that take care of UART events will be in the HardwareSerial Class code +void uartGetEventQueue(uart_t* uart, QueueHandle_t *q) +{ + // passing back NULL for the Queue pointer when UART is not initialized yet + *q = NULL; + if(uart == NULL) { + return; + } + *q = uart->uart_event_queue; + return; +} + bool uartIsDriverInstalled(uart_t* uart) { if(uart == NULL) { - return 0; + return false; } if (uart_is_driver_installed(uart->num)) { @@ -94,28 +106,36 @@ bool uartIsDriverInstalled(uart_t* uart) return false; } -void uartSetPins(uart_t* uart, uint8_t rxPin, uint8_t txPin) +// Valid pin UART_PIN_NO_CHANGE is defined to (-1) +// Negative Pin Number will keep it unmodified, thus this function can set individual pins +void uartSetPins(uart_t* uart, int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin) { - if(uart == NULL || rxPin >= SOC_GPIO_PIN_COUNT || txPin >= SOC_GPIO_PIN_COUNT) { + if(uart == NULL) { return; } UART_MUTEX_LOCK(); - ESP_ERROR_CHECK(uart_set_pin(uart->num, txPin, rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE)); - UART_MUTEX_UNLOCK(); - + // IDF uart_set_pin() will issue necessary Error Message and take care of all GPIO Number validation. + uart_set_pin(uart->num, txPin, rxPin, ctsPin, rtsPin); + UART_MUTEX_UNLOCK(); } +// +void uartSetHwFlowCtrlMode(uart_t *uart, uint8_t mode, uint8_t threshold) { + if(uart == NULL) { + return; + } + // IDF will issue corresponding error message when mode or threshold are wrong and prevent crashing + // IDF will check (mode > HW_FLOWCTRL_CTS_RTS || threshold >= SOC_UART_FIFO_LEN) + uart_set_hw_flow_ctrl(uart->num, (uart_hw_flowcontrol_t) mode, threshold); +} -uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t queueLen, bool inverted, uint8_t rxfifo_full_thrhd) + +uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t rx_buffer_size, uint16_t tx_buffer_size, bool inverted, uint8_t rxfifo_full_thrhd) { if(uart_nr >= SOC_UART_NUM) { return NULL; } - if(rxPin == -1 && txPin == -1) { - return NULL; - } - uart_t* uart = &_uart_bus_array[uart_nr]; if (uart_is_driver_installed(uart_nr)) { @@ -143,7 +163,7 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx uart_config.source_clk = UART_SCLK_APB; - ESP_ERROR_CHECK(uart_driver_install(uart_nr, 2*queueLen, 0, 0, NULL, 0)); + ESP_ERROR_CHECK(uart_driver_install(uart_nr, rx_buffer_size, tx_buffer_size, 20, &(uart->uart_event_queue), 0)); ESP_ERROR_CHECK(uart_param_config(uart_nr, &uart_config)); ESP_ERROR_CHECK(uart_set_pin(uart_nr, txPin, rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE)); @@ -153,9 +173,6 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx ESP_ERROR_CHECK(uart_set_line_inverse(uart_nr, UART_SIGNAL_TXD_INV | UART_SIGNAL_RXD_INV)); } - // Set RS485 half duplex mode on UART. This shall force flush to wait up to sending all bits out - ESP_ERROR_CHECK(uart_set_mode(uart_nr, UART_MODE_RS485_HALF_DUPLEX)); - UART_MUTEX_UNLOCK(); uartFlush(uart); @@ -306,7 +323,7 @@ void uartFlushTxOnly(uart_t* uart, bool txOnly) } UART_MUTEX_LOCK(); - ESP_ERROR_CHECK(uart_wait_tx_done(uart->num, portMAX_DELAY)); + while(!uart_ll_is_tx_idle(UART_LL_GET_HW(uart->num))); if ( !txOnly ) { ESP_ERROR_CHECK(uart_flush_input(uart->num)); @@ -404,11 +421,12 @@ int log_printf(const char *format, ...) va_list copy; va_start(arg, format); va_copy(copy, arg); - len = vsnprintf(NULL, 0, format, arg); + len = vsnprintf(NULL, 0, format, copy); va_end(copy); if(len >= sizeof(loc_buf)){ temp = (char*)malloc(len+1); if(temp == NULL) { + va_end(arg); return 0; } } @@ -470,6 +488,7 @@ void log_print_buf(const uint8_t *b, size_t len){ */ unsigned long uartBaudrateDetect(uart_t *uart, bool flg) { +#ifndef CONFIG_IDF_TARGET_ESP32S3 if(uart == NULL) { return 0; } @@ -487,6 +506,9 @@ unsigned long uartBaudrateDetect(uart_t *uart, bool flg) UART_MUTEX_UNLOCK(); return ret; +#else + return 0; +#endif } @@ -531,7 +553,7 @@ void uartStartDetectBaudrate(uart_t *uart) { //hw->rx_filt.glitch_filt_en = 1; //hw->conf0.autobaud_en = 0; //hw->conf0.autobaud_en = 1; - +#elif CONFIG_IDF_TARGET_ESP32S3 #else hw->auto_baud.glitch_filt = 0x08; hw->auto_baud.en = 0; @@ -568,6 +590,7 @@ uartDetectBaudrate(uart_t *uart) #ifdef CONFIG_IDF_TARGET_ESP32C3 //hw->conf0.autobaud_en = 0; +#elif CONFIG_IDF_TARGET_ESP32S3 #else hw->auto_baud.en = 0; #endif diff --git a/cores/esp32/esp32-hal-uart.h b/cores/esp32/esp32-hal-uart.h index 609f380f59e..ec7912c3d7a 100644 --- a/cores/esp32/esp32-hal-uart.h +++ b/cores/esp32/esp32-hal-uart.h @@ -22,6 +22,8 @@ extern "C" { #include #include #include +#include "freertos/FreeRTOS.h" +#include "freertos/queue.h" #define SERIAL_5N1 0x8000010 #define SERIAL_6N1 0x8000014 @@ -48,12 +50,23 @@ extern "C" { #define SERIAL_7O2 0x800003b #define SERIAL_8O2 0x800003f +// These are Hardware Flow Contol possible usage +// equivalent to UDF enum uart_hw_flowcontrol_t from +// https://github.com/espressif/esp-idf/blob/master/components/hal/include/hal/uart_types.h#L75-L81 +#define HW_FLOWCTRL_DISABLE 0x0 // disable HW Flow Control +#define HW_FLOWCTRL_RTS 0x1 // use only RTS PIN for HW Flow Control +#define HW_FLOWCTRL_CTS 0x2 // use only CTS PIN for HW Flow Control +#define HW_FLOWCTRL_CTS_RTS 0x3 // use both CTS and RTS PIN for HW Flow Control + struct uart_struct_t; typedef struct uart_struct_t uart_t; -uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t queueLen, bool inverted, uint8_t rxfifo_full_thrhd); +uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t rx_buffer_size, uint16_t tx_buffer_size, bool inverted, uint8_t rxfifo_full_thrhd); void uartEnd(uart_t* uart); +// This is used to retrieve the Event Queue pointer from a UART IDF Driver in order to allow user to deal with its events +void uartGetEventQueue(uart_t* uart, QueueHandle_t *q); + uint32_t uartAvailable(uart_t* uart); uint32_t uartAvailableForWrite(uart_t* uart); uint8_t uartRead(uart_t* uart); @@ -74,7 +87,12 @@ void uartSetDebug(uart_t* uart); int uartGetDebug(); bool uartIsDriverInstalled(uart_t* uart); -void uartSetPins(uart_t* uart, uint8_t rxPin, uint8_t txPin); + +// Negative Pin Number will keep it unmodified, thus this function can set individual pins +void uartSetPins(uart_t* uart, int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin); + +// Enables or disables HW Flow Control function -- needs also to set CTS and/or RTS pins +void uartSetHwFlowCtrlMode(uart_t *uart, uint8_t mode, uint8_t threshold); void uartStartDetectBaudrate(uart_t *uart); unsigned long uartDetectBaudrate(uart_t *uart); diff --git a/cores/esp32/esp32-hal.h b/cores/esp32/esp32-hal.h index 115a050b172..55e9f95769b 100644 --- a/cores/esp32/esp32-hal.h +++ b/cores/esp32/esp32-hal.h @@ -95,6 +95,9 @@ void analogWrite(uint8_t pin, int value); //returns chip temperature in Celsius float temperatureRead(); +//allows user to bypass SPI RAM test routine +bool testSPIRAM(void); + #if CONFIG_AUTOSTART_ARDUINO //enable/disable WDT for Arduino's setup and loop functions void enableLoopWDT(); diff --git a/cores/esp32/esp_arduino_version.h b/cores/esp32/esp_arduino_version.h index 03fbeea2396..9b053df2640 100644 --- a/cores/esp32/esp_arduino_version.h +++ b/cores/esp32/esp_arduino_version.h @@ -23,7 +23,7 @@ extern "C" { /** Minor version number (x.X.x) */ #define ESP_ARDUINO_VERSION_MINOR 0 /** Patch version number (x.x.X) */ -#define ESP_ARDUINO_VERSION_PATCH 0 +#define ESP_ARDUINO_VERSION_PATCH 3 /** * Macro to convert ARDUINO version number into an integer diff --git a/cores/esp32/main.cpp b/cores/esp32/main.cpp index f4e79844818..27b92948d5d 100644 --- a/cores/esp32/main.cpp +++ b/cores/esp32/main.cpp @@ -2,7 +2,7 @@ #include "freertos/task.h" #include "esp_task_wdt.h" #include "Arduino.h" -#if (ARDUINO_USB_CDC_ON_BOOT|ARDUINO_USB_MSC_ON_BOOT|ARDUINO_USB_DFU_ON_BOOT) +#if (ARDUINO_USB_CDC_ON_BOOT|ARDUINO_USB_MSC_ON_BOOT|ARDUINO_USB_DFU_ON_BOOT) && !ARDUINO_USB_MODE #include "USB.h" #if ARDUINO_USB_MSC_ON_BOOT #include "FirmwareMSC.h" @@ -54,16 +54,16 @@ void loopTask(void *pvParameters) extern "C" void app_main() { -#if ARDUINO_USB_CDC_ON_BOOT +#if ARDUINO_USB_CDC_ON_BOOT && !ARDUINO_USB_MODE Serial.begin(); #endif -#if ARDUINO_USB_MSC_ON_BOOT +#if ARDUINO_USB_MSC_ON_BOOT && !ARDUINO_USB_MODE MSC_Update.begin(); #endif -#if ARDUINO_USB_DFU_ON_BOOT +#if ARDUINO_USB_DFU_ON_BOOT && !ARDUINO_USB_MODE USB.enableDFU(); #endif -#if ARDUINO_USB_ON_BOOT +#if ARDUINO_USB_ON_BOOT && !ARDUINO_USB_MODE USB.begin(); #endif loopTaskWDTEnabled = false; diff --git a/cores/esp32/stdlib_noniso.c b/cores/esp32/stdlib_noniso.c index 8f24520dac3..e66edace7e3 100644 --- a/cores/esp32/stdlib_noniso.c +++ b/cores/esp32/stdlib_noniso.c @@ -88,7 +88,7 @@ char* ultoa(unsigned long value, char* result, int base) { return result; } -char * dtostrf(double number, signed char width, unsigned char prec, char *s) { +char * dtostrf(double number, signed int width, unsigned int prec, char *s) { bool negative = false; if (isnan(number)) { @@ -117,7 +117,7 @@ char * dtostrf(double number, signed char width, unsigned char prec, char *s) { // Round correctly so that print(1.999, 2) prints as "2.00" // I optimized out most of the divisions double rounding = 2.0; - for (uint8_t i = 0; i < prec; ++i) + for (uint32_t i = 0; i < prec; ++i) rounding *= 10.0; rounding = 1.0 / rounding; diff --git a/cores/esp32/stdlib_noniso.h b/cores/esp32/stdlib_noniso.h index 3df2cc2a1b6..e5bb44e563a 100644 --- a/cores/esp32/stdlib_noniso.h +++ b/cores/esp32/stdlib_noniso.h @@ -39,7 +39,7 @@ char* utoa (unsigned int val, char *s, int radix); char* ultoa (unsigned long val, char *s, int radix); -char* dtostrf (double val, signed char width, unsigned char prec, char *s); +char* dtostrf (double val, signed int width, unsigned int prec, char *s); #ifdef __cplusplus } // extern "C" diff --git a/docs/ISSUE_TEMPLATE.md b/docs/ISSUE_TEMPLATE.md deleted file mode 100644 index 5cf96ef213b..00000000000 --- a/docs/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,47 +0,0 @@ -Make your question, not a Statement, inclusive. Include all pertinent information: - -What you are trying to do -Describe your system (Hardware, computer, O/S, core version, environment) -Describe what is failing -Show the shortest possible code that will duplicate the error -Show the EXACT error message (it doesn't work is not enough) -Then if someone is interested and knowledgeable you might get a answer. All of this work on your part shows us that you have worked to solve YOUR problem. The more complete your issue posting is, the more likely someone will volunteer their time to help you. - -If you have a Guru Meditation Error or Backtrace, ***please decode it***: -[ExceptionDecoder](https://github.com/me-no-dev/EspExceptionDecoder) - ------------------------------ Remove above ----------------------------- - - -### Hardware: -||||||| -|:---|---|---|---|---|---| -|Board|ESP32 Dev Module|node32|ttgo_lora|ESP32-S2-Saola|Custom w/ ESP32-S2-WROVER 16MB| -|Version/Date|1.0.4|2.0.0|0badbeef|11/jul/2017|today's master| -|IDE name|Arduino IDE|Atom + Platform.io|IDF component|VSCode| -|Flash Frequency|40Mhz|80Mhz| -|PSRAM enabled|yes|no| -|Upload Speed|115200| -|Computer OS|Windows 10|Mac OSX|Ubuntu| - -### Description: -Describe your problem here - - -### Sketch: (leave the backquotes for [code formatting](https://help.github.com/articles/creating-and-highlighting-code-blocks/)) -```cpp - -//Change the code below by your sketch -#include - -void setup() { -} - -void loop() { -} -``` - -### Debug Messages: -``` -Enable Core debug level: Debug on tools menu of Arduino IDE, then put the serial output here -``` diff --git a/docs/requirements.txt b/docs/requirements.txt index 0e4fb8ab59c..9e40946ec2b 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -3,3 +3,4 @@ # # matplotlib is currently required only by the script generate_chart.py sphinx-copybutton==0.3.0 +sphinx-tabs==3.2.0 \ No newline at end of file diff --git a/docs/source/_static/logo_arduino.png b/docs/source/_static/logo_arduino.png new file mode 100644 index 00000000000..a3a7cd942e9 Binary files /dev/null and b/docs/source/_static/logo_arduino.png differ diff --git a/docs/source/_static/logo_pio.png b/docs/source/_static/logo_pio.png new file mode 100644 index 00000000000..a64c1563964 Binary files /dev/null and b/docs/source/_static/logo_pio.png differ diff --git a/docs/source/_static/usb_msc_drive.png b/docs/source/_static/usb_msc_drive.png new file mode 100644 index 00000000000..de0796c3980 Binary files /dev/null and b/docs/source/_static/usb_msc_drive.png differ diff --git a/docs/source/api/adc.rst b/docs/source/api/adc.rst new file mode 100644 index 00000000000..1947fdcf990 --- /dev/null +++ b/docs/source/api/adc.rst @@ -0,0 +1,208 @@ +### +ADC +### + +About +----- + +ADC (analog to digital converter) is a very common peripheral used to convert an analog signal such as voltage +to a digital form so that it can be read and processed by a microcontroller. + +ADCs are very useful in control and monitoring applications since most sensors +(e.g., temperature, pressure, force) produce analogue output voltages. + +.. note:: Each SoC or module has a different number of ADC's with a different number of channels and pins availible. Refer to datasheet of each board for more info. + +Arduino-ESP32 ADC API +--------------------- + +ADC common API +************** + +analogRead +^^^^^^^^^^ + +This function is used to get the ADC raw value for a given pin/ADC channel. + +.. code-block:: arduino + + uint16_t analogRead(uint8_t pin); + +* ``pin`` GPIO pin to read analog value + +This function will return analog raw value. + +analogReadMillivolts +^^^^^^^^^^^^^^^^^^^^ + +This function is used to get ADC value for a given pin/ADC channel in millivolts. + +.. code-block:: arduino + + uint32_t analogReadMilliVolts(uint8_t pin); + +* ``pin`` GPIO pin to read analog value + +This function will return analog value in millivolts. + +analogReadResolution +^^^^^^^^^^^^^^^^^^^^ + +This function is used to set the resolution of ``analogRead`` return value. Default is 12 bits (range from 0 to 4096) +for all chips except ESP32S3 where default is 13 bits (range from 0 to 8192). +When different resolution is set, the values read will be shifted to match the given resolution. + +Range is 1 - 16 .The default value will be used, if this function is not used. + +.. note:: For the ESP32, the resolution is between 9 to12 and it will change the ADC hardware resolution. Else value will be shifted. + +.. code-block:: arduino + + void analogReadResolution(uint8_t bits); + +* ``bits`` sets analog read resolution + +analogSetClockDiv +^^^^^^^^^^^^^^^^^ + +This function is used to set the divider for the ADC clock. + +Range is 1 - 255. Default value is 1. + +.. code-block:: arduino + + void analogSetClockDiv(uint8_t clockDiv); + +* ``clockDiv`` sets the divider for ADC clock. + +analogSetAttenuation +^^^^^^^^^^^^^^^^^^^^ + +This function is used to set the attenuation for all channels. + +Input voltages can be attenuated before being input to the ADCs. +There are 4 available attenuation options, the higher the attenuation is, the higher the measurable input voltage could be. + +The measurable input voltage differs for each chip, see table below for detailed information. + +.. tabs:: + + .. tab:: ESP32 + + ===================== =========================================== + Attenuation Measurable input voltage range + ===================== =========================================== + ``ADC_ATTEN_DB_0`` 100 mV ~ 950 mV + ``ADC_ATTEN_DB_2_5`` 100 mV ~ 1250 mV + ``ADC_ATTEN_DB_6`` 150 mV ~ 1750 mV + ``ADC_ATTEN_DB_11`` 150 mV ~ 2450 mV + ===================== =========================================== + + .. tab:: ESP32-S2 + + ===================== =========================================== + Attenuation Measurable input voltage range + ===================== =========================================== + ``ADC_ATTEN_DB_0`` 0 mV ~ 750 mV + ``ADC_ATTEN_DB_2_5`` 0 mV ~ 1050 mV + ``ADC_ATTEN_DB_6`` 0 mV ~ 1300 mV + ``ADC_ATTEN_DB_11`` 0 mV ~ 2500 mV + ===================== =========================================== + + .. tab:: ESP32-C3 + + ===================== =========================================== + Attenuation Measurable input voltage range + ===================== =========================================== + ``ADC_ATTEN_DB_0`` 0 mV ~ 750 mV + ``ADC_ATTEN_DB_2_5`` 0 mV ~ 1050 mV + ``ADC_ATTEN_DB_6`` 0 mV ~ 1300 mV + ``ADC_ATTEN_DB_11`` 0 mV ~ 2500 mV + ===================== =========================================== + + .. tab:: ESP32-S3 + + ===================== =========================================== + Attenuation Measurable input voltage range + ===================== =========================================== + ``ADC_ATTEN_DB_0`` 0 mV ~ 950 mV + ``ADC_ATTEN_DB_2_5`` 0 mV ~ 1250 mV + ``ADC_ATTEN_DB_6`` 0 mV ~ 1750 mV + ``ADC_ATTEN_DB_11`` 0 mV ~ 3100 mV + ===================== =========================================== + +.. code-block:: arduino + + void analogSetAttenuation(adc_attenuation_t attenuation); + +* ``attenuation`` sets the attenuation. + +analogSetPinAttenuation +^^^^^^^^^^^^^^^^^^^^^^^ + +This function is used to set the attenuation for a specific pin/ADC channel. For more information refer to `analogSetAttenuation`_. + +.. code-block:: arduino + + void analogSetPinAttenuation(uint8_t pin, adc_attenuation_t attenuation); + +* ``pin`` selects specific pin for attenuation settings. +* ``attenuation`` sets the attenuation. + +adcAttachPin +^^^^^^^^^^^^ + +This function is used to attach the pin to ADC (it will also clear any other analog mode that could be on) + +.. code-block:: arduino + + bool adcAttachPin(uint8_t pin); + +This function will return ``true`` if configuration is successful. Else returns ``false``. + +ADC API specific for ESP32 chip +******************************* + +analogSetWidth +^^^^^^^^^^^^^^ + +This function is used to set the hardware sample bits and read resolution. +Default is 12bit (0 - 4095). +Range is 9 - 12. + +.. code-block:: arduino + + void analogSetWidth(uint8_t bits); + +analogSetVRefPin +^^^^^^^^^^^^^^^^ + +This function is used to set pin to use for ADC calibration if the esp is not already calibrated (pins 25, 26 or 27). + +.. code-block:: arduino + + void analogSetVRefPin(uint8_t pin); + +* ``pin`` GPIO pin to set VRefPin for ADC calibration + +hallRead +^^^^^^^^ + +This function is used to get the ADC value of the HALL sensor conneted to pins 36(SVP) and 39(SVN). + +.. code-block:: arduino + + int hallRead(); + +This function will return the hall sensor value. + + +Example Applications +******************** + +Here is an example of how to use the ADC. + +.. literalinclude:: ../../../libraries/ESP32/examples/AnalogRead/AnalogRead.ino + :language: arduino + +Or you can run Arduino example 01.Basics -> AnalogReadSerial. \ No newline at end of file diff --git a/docs/source/api/dac.rst b/docs/source/api/dac.rst new file mode 100644 index 00000000000..9fd91feeefd --- /dev/null +++ b/docs/source/api/dac.rst @@ -0,0 +1,47 @@ +### +DAC +### + +About +----- + +DAC (digital to analog converter) is a very common peripheral used to convert a digital signal to an +analog form. + +ESP32 and ESP32-S2 have two 8-bit DAC channels. The DAC driver allows these channels to be set to arbitrary voltages. + +DACs can be used for generating a specific (and dynamic) reference voltage for external sensors, +controlling transistors, etc. + +========= ========= ========= +ESP32 SoC DAC_1 pin DAC_2 pin +========= ========= ========= +ESP32 GPIO 25 GPIO 26 +ESP32-S2 GPIO 17 GPIO 18 +========= ========= ========= + +Arduino-ESP32 DAC API +--------------------- + +dacWrite +******** + +This function is used to set the DAC value for a given pin/DAC channel. + +.. code-block:: arduino + + void dacWrite(uint8_t pin, uint8_t value); + +* ``pin`` GPIO pin. +* ``value`` to be set. Range is 0 - 255 (equals 0V - 3.3V). + +dacDisable +********** + +This function is used to disable DAC output on a given pin/DAC channel. + +.. code-block:: arduino + + void dacDisable(uint8_t pin); + +* ``pin`` GPIO pin. \ No newline at end of file diff --git a/docs/source/api/i2c.rst b/docs/source/api/i2c.rst index 4c690488e28..f53d8f27a3c 100644 --- a/docs/source/api/i2c.rst +++ b/docs/source/api/i2c.rst @@ -381,4 +381,4 @@ Here is an example of how to use the I2C in Slave Mode. .. literalinclude:: ../../../libraries/Wire/examples/WireSlave/WireSlave.ino :language: arduino -.. _Arduino Wire Library: https://www.arduino.cc/en/reference/wire \ No newline at end of file +.. _Arduino Wire Library: https://www.arduino.cc/en/reference/wire diff --git a/docs/source/api/i2s.rst b/docs/source/api/i2s.rst new file mode 100644 index 00000000000..02539fb3f2b --- /dev/null +++ b/docs/source/api/i2s.rst @@ -0,0 +1,566 @@ +### +I2S +### + +About +----- + +I2S - Inter-IC Sound, correctly written I²S pronounced "eye-squared-ess", alternative notation is IIS. I²S is an electrical serial bus interface standard used for connecting digital audio devices together. + +It is used to communicate PCM (Pulse-Code Modulation) audio data between integrated circuits in an electronic device. The I²S bus separates clock and serial data signals, resulting in simpler receivers than those required for asynchronous communications systems that need to recover the clock from the data stream. + +Despite the similar name, I²S is unrelated and incompatible with the bidirectional I²C (IIC) bus. + +The I²S bus consists of at least three lines: + +.. note:: All lines can be attached to almost any pin and this change can occur even during operation. + +* **Bit clock line** + + * Officially "continuous serial clock (SCK)". Typically written "bit clock (BCLK)". + * In this library function parameter ``sckPin`` or constant ``PIN_I2S_SCK``. + +* **Word clock line** + + * Officially "word select (WS)". Typically called "left-right clock (LRCLK)" or "frame sync (FS)". + * 0 = Left channel, 1 = Right channel + * In this library function parameter ``fsPin`` or constant ``PIN_I2S_FS``. + +* **Data line** + + * Officially "serial data (SD)", but can be called SDATA, SDIN, SDOUT, DACDAT, ADCDAT, etc. + * Unlike Arduino I2S with single data pin switching between input and output, in ESP core driver use separate data line for input and output. + * For backward compatibility, the shared data pin is ``sdPin`` or constant ``PIN_I2S_SD`` when using simplex mode. + + * When using in duplex mode, there are two data lines: + + * Output data line is called ``outSdPin`` for function parameter, or constant ``PIN_I2S_SD_OUT`` + * Input data line is called ``inSdPin`` for function parameter, or constant ``PIN_I2S_SD_IN`` + +I2S Modes +--------- + +The I2S can be set up in three groups of modes: + +* Master (default) or Slave. +* Simplex (default) or Duplex. +* Operation modes (Philips standard, ADC/DAC, PDM) + + * Most of them are dual-channel, some can be single channel + +.. note:: Officially supported operation mode is only ``I2S_PHILIPS_MODE``. Other modes are implemented, but we cannot guarantee flawless execution and behavior. + +Master / Slave Mode +******************* + +In **Master mode** (default) the device is generating clock signal ``sckPin`` and word select signal on ``fsPin``. + +In **Slave mode** the device listens on attached pins for the clock signal and word select - i.e. unless externally driven the pins will remain LOW. + +How to enter either mode is described in the function section. + +Operation Modes +*************** + +Setting the operation mode is done with function ``begin`` (see API section) + +* ``I2S_PHILIPS_MODE`` + * Currently the only official* ``PIN_I2S_SCK`` +* ``PIN_I2S_FS`` +* ``PIN_I2S_SD`` +* ``PIN_I2S_SD_OUT`` only need to send one channel data but the data will be copied for another channel automatically, then both channels will transmit same data. + +* ``ADC_DAC_MODE`` + The output will be an analog signal on pins ``25`` (L or R?) and ``26`` (L or R?). + Input will be received on pin ``_inSdPin``. + The data are sampled in 12 bits and stored in a 16 bits, with the 4 most significant bits set to zero. + +* ``PDM_STEREO_MODE`` + Pulse-density-modulation is similar to PWM, but instead, the pulses have constant width. The signal is modulated with the number of ones or zeroes in sequence. + +* ``PDM_MONO_MODE`` + Single-channel version of PDM mode described above. + +Simplex / Duplex Mode +********************* + +The **Simplex** mode is the default after driver initialization. Simplex mode uses the shared data pin ``sdPin`` or constant ``PIN_I2S_SD`` for both output and input, but can only read or write. This is the same behavior as in original Arduino library. + +The **Duplex** mode uses two separate data pins: + +* Output pin ``outSdPin`` for function parameter, or constant ``PIN_I2S_SD_OUT`` +* Input pin ``inSdPin`` for function parameter, or constant ``PIN_I2S_SD_IN`` + +In this mode, the driver is able to read and write simultaneously on each line and is suitable for applications like walkie-talkie or phone. + +Switching between these modes is performed simply by calling setDuplex() or setSimplex() (see APi section for details and more functions). + +Arduino-ESP32 I2S API +--------------------- + +The ESP32 I2S library is based on the Arduino I2S Library and implements a few more APIs, described in this `documentation `_. + +Initialization and deinitialization +*********************************** + +Before initialization, choose which pins you want to use. In DAC mode you can use only pins `25` and `26` for the output. + +begin (Master Mode) +^^^^^^^^^^^^^^^^^^^ + +Before usage choose which pins you want to use. In DAC mode you can use only pins 25 and 26 as output. + +.. code-block:: arduino + + int begin(int mode, int sampleRate, int bitsPerSample) + +Parameters: + +* [in] ``mode`` one of above mentioned operation mode, for example ``I2S_PHILIPS_MODE``. + +* [in] ``sampleRate`` is the sampling rate in Hz. Currently officially supported value is only 16000 - other than this value will print warning, but continue to operate, however the resulting audio quality may suffer and the app may crash. + +* [in] ``bitsPerSample`` is the number of bits in a channel sample. + +Currently, the supported value is only 16 - other than this value will print a warning, but continues to operate, however, the resulting audio quality may suffer and the application may crash. + +For ``ADC_DAC_MODE`` the only possible value will remain 16. + +This function will return ``true`` on success or ``fail`` in case of failure. + +When failed, an error message will be printed if subscribed. + +begin (Slave Mode) +^^^^^^^^^^^^^^^^^^ + +Performs initialization before use - creates buffers, task handling underlying driver messages, configuring and starting the driver operation. + +This version initializes I2S in SLAVE mode (see previous entry for MASTER mode). + +.. code-block:: arduino + + int begin(int mode, int bitsPerSample) + +Parameters: + +* [in] ``mode`` one of above mentioned modes for example ``I2S_PHILIPS_MODE``. + +* [in] ``bitsPerSample`` is the umber of bits in a channel sample. Currently, the only supported value is only 16 - other than this value will print warning, but continue to operate, however the resulting audio quality may suffer and the app may crash. + +For ``ADC_DAC_MODE`` the only possible value will remain 16. + +This function will return ``true`` on success or ``fail`` in case of failure. + +When failed, an error message will be printed if subscribed. + +end +^^^ + +Performs safe deinitialization - free buffers, destroy task, end driver operation, etc. + +.. code-block:: arduino + + void end() + +Pin setup +********* + +Pins can be changed in two ways- 1st constants, 2nd functions. + +.. note:: Shared data pin can be equal to any other data pin, but must not be equal to clock pin nor frame sync pin! Input and Output pins must not be equal, but one of them can be equal to shared data pin! + +.. code-block:: arduino + + sckPin != fsPin != outSdPin != inSdPin + +.. code-block:: arduino + + sckPin != fsPin != sdPin + +By default, the pin numbers are defined in constants in the header file. You can redefine any of those constants before including ``I2S.h``. This way the driver will use these new default values and you will not need to specify pins in your code. The constants and their default values are: + +* ``PIN_I2S_SCK`` 14 +* ``PIN_I2S_FS`` 25 +* ``PIN_I2S_SD`` 26 +* ``PIN_I2S_SD_OUT`` 26 +* ``PIN_I2S_SD_IN`` 35 + +The second option to change pins is using the following functions. These functions can be called on either on initialized or uninitialized object. + +If called on the initialized object (after calling ``begin``) the pins will change during operation. +If called on the uninitialized object (before calling ``begin``, or after calling ``end``) the new pin setup will be used on next initialization. + +setSckPin +^^^^^^^^^ + +Set and apply clock pin. + +.. code-block:: arduino + + int setSckPin(int sckPin) + +This function will return ``true`` on success or ``fail`` in case of failure. + +setFsPin +^^^^^^^^ + +Set and apply frame sync pin. + +.. code-block:: arduino + + int setFsPin(int fsPin) + +This function will return ``true`` on success or ``fail`` in case of failure. + +setDataPin +^^^^^^^^^^ + +Set and apply shared data pin used in simplex mode. + +.. code-block:: arduino + + int setDataPin(int sdPin) + +This function will return ``true`` on success or ``fail`` in case of failure. + +setDataInPin +^^^^^^^^^^^^ + +Set and apply data input pin. + +.. code-block:: arduino + + int setDataInPin(int inSdPin) + +This function will return ``true`` on success or ``fail`` in case of failure. + +setDataOutPin +^^^^^^^^^^^^^ + +Set and apply data output pin. + +.. code-block:: arduino + + int setDataOutPin(int outSdPin) + +This function will return ``true`` on success or ``fail`` in case of failure. + +setAllPins +^^^^^^^^^^ + +Set all pins using given values in parameters. This is simply a wrapper of four functions mentioned above. + +.. code-block:: arduino + + int setAllPins(int sckPin, int fsPin, int sdPin, int outSdPin, int inSdPin) + +Set all pins to default i.e. take values from constants mentioned above. This simply calls the the function with the following constants. + +* ``PIN_I2S_SCK`` 14 +* ``PIN_I2S_FS`` 25 +* ``PIN_I2S_SD`` 26 +* ``PIN_I2S_SD_OUT`` 26 +* ``PIN_I2S_SD_IN`` 35 + +.. code-block:: arduino + + int setAllPins() + +getSckPin +^^^^^^^^^ + +Get the current value of the clock pin. + +.. code-block:: arduino + + int getSckPin() + +getFsPin +^^^^^^^^ + +Get the current value of frame sync pin. + +.. code-block:: arduino + + int getFsPin() + +getDataPin +^^^^^^^^^^ + +Get the current value of shared data pin. + +.. code-block:: arduino + + int getDataPin() + +getDataInPin +^^^^^^^^^^^^ + +Get the current value of data input pin. + +.. code-block:: arduino + + int getDataInPin() + +getDataOutPin +^^^^^^^^^^^^^ + +Get the current value of data output pin. + +.. code-block:: arduino + + int getDataOutPin() + +onTransmit +^^^^^^^^^^ + +Register the function to be called on each successful transmit event. + +.. code-block:: arduino + + void onTransmit(void(*)(void)) + +onReceive +^^^^^^^^^ + +Register the function to be called on each successful receives event. + +.. code-block:: arduino + + void onReceive(void(*)(void)) + +setBufferSize +^^^^^^^^^^^^^ + +Set the size of buffer. + +.. code-block:: arduino + + int setBufferSize(int bufferSize) + +This function can be called on both the initialized or uninitialized driver. + +If called on initialized, it will change internal values for buffer size and re-initialize driver with new value. +If called on uninitialized, it will only change the internal values which will be used for next initialization. + +Parameter ``bufferSize`` must be in range from 8 to 1024 and the unit is sample words. The default value is 128. + +Example: 16 bit sample, dual channel, buffer size for input: + + ``128 = 2B sample * 2 channels * 128 buffer size * buffer count (default 2) = 1024B`` + +And more ```1024B`` for output buffer in total of ``2kB`` used. + +This function always assumes dual-channel, keeping the same size even for MONO modes. + +This function will return ``true`` on success or ``fail`` in case of failure. + +When failed, an error message will be printed. + +getBufferSize +^^^^^^^^^^^^^ + +Get current buffer sizes in sample words (see description for ``setBufferSize``). + +.. code-block:: arduino + + int getBufferSize() + +Duplex vs Simplex +***************** + +Original Arduino I2S library supports only *simplex* mode (only transmit or only receive at a time). For compatibility, we kept this behavior, but ESP natively supports *duplex* mode (receive and transmit simultaneously on separate pins). +By default this library is initialized in simplex mode as it would in Arduino, switching input and output on ``sdPin`` (constant ``PIN_I2S_SD`` default pin 26). + +setDuplex +^^^^^^^^^ + +Switch to duplex mode and use separate pins: + +.. code-block:: arduino + + int setDuplex() + +input: inSdPin (constant PIN_I2S_SD_IN, default 35) +output: outSdPin (constant PIN_I2S_SD, default 26) + +setSimplex +^^^^^^^^^^ + +(Default mode) + +Switch to simplex mode using shared data pin sdPin (constant PIN_I2S_SD, default 26). + +.. code-block:: arduino + + int setSimplex() + +isDuplex +^^^^^^^^ + +Returns 1 if current mode is duplex, 0 if current mode is simplex (default). + +.. code-block:: arduino + + int isDuplex() + +Data stream +*********** + +available +^^^^^^^^^ + +Returns number of **bytes** ready to read. + +.. code-block:: arduino + + int available() + +read +^^^^ + +Read ``size`` bytes from internal buffer if possible. + +.. code-block:: arduino + + int read(void* buffer, size_t size) + +This function is non-blocking, i.e. if the requested number of bytes is not available, it will return as much as possible without waiting. + +Hint: use ``available()`` before calling this function. + +Parameters: + +[out] ``void* buffer`` buffer into which will be copied data read from internal buffer. WARNING: this buffer must be allocated before use! + +[in] ``size_t size`` number of bytes required to be read. + +Returns number of successfully bytes read. Returns ``false``` in case of reading error. + +Read one sample. + +.. code-block:: arduino + + int read() + +peek +^^^^ + +Read one sample from the internal buffer and returns it. + +.. code-block:: arduino + + int peek() + +Repeated peeks will be returned in the same sample until ``read`` is called. + +flush +^^^^^ + +Force write internal buffer to driver. + +.. code-block:: arduino + + void flush() + +write +^^^^^ + +Write a single byte. + +.. code-block:: arduino + + size_t write(uint8_t) + +Single-sample writes are blocking - waiting until there is free space in the internal buffer to be written into. + +Returns number of successfully written bytes, in this case, 1. Returns 0 on error. + +Write single sample. + +.. code-block:: arduino + + size_t write(int32_t) + +Single-sample writes are blocking - waiting until there is free space in the internal buffer to be written into. + +Returns number of successfully written bytes. Returns 0 on error. + +Expected return number is ``bitsPerSample/8``. + +Write buffer of supplied size; + +.. code-block:: arduino + + size_t write(const void *buffer, size_t size) + +Parameters: + +[in] ``const void *buffer`` buffer to be written +[in] ``size_t size`` size of buffer in bytes + +Returns number of successfully written bytes. Returns 0 in case of error. +The expected return number is equal to ``size``. + +write +^^^^^ + +This is a wrapper of the previous function performing typecast from `uint8_t*`` to ``void*``. + +.. code-block:: arduino + + size_t write(const uint8_t *buffer, size_t size) + +availableForWrite +^^^^^^^^^^^^^^^^^ + +Returns number of bytes available for write. + +.. code-block:: arduino + + int availableForWrite() + +write_blocking +^^^^^^^^^^^^^^ + +Core function implementing blocking write, i.e. waits until all requested data are written. + +.. code-block:: arduino + + size_t write_blocking(const void *buffer, size_t size) + +WARNING: If too many bytes are requested, this can cause WatchDog Trigger Reset! + +Returns number of successfully written bytes. Returns 0 on error. + +write_nonblocking +^^^^^^^^^^^^^^^^^ + +Core function implementing non-blocking write, i.e. writes as much as possible and exits. + +.. code-block:: arduino + + size_t write_nonblocking(const void *buffer, size_t size) + +Returns number of successfully written bytes. Returns 0 on error. + +Sample code +----------- + +.. code-block:: c + + #include + const int buff_size = 128; + int available, read; + uint8_t buffer[buff_size]; + + I2S.begin(I2S_PHILIPS_MODE, 16000, 16); + I2S.read(); // Switch the driver in simplex mode to receive + available = I2S.available(); + if(available < buff_size){ + read = I2S.read(buffer, available); + }else{ + read = I2S.read(buffer, buff_size); + } + I2S.write(buffer, read); + I2S.end(); diff --git a/docs/source/api/ledc.rst b/docs/source/api/ledc.rst new file mode 100644 index 00000000000..b6c72821304 --- /dev/null +++ b/docs/source/api/ledc.rst @@ -0,0 +1,183 @@ +################## +LED Control (LEDC) +################## + +About +----- +The LED control (LEDC) peripheral is primarly designed to control the intensity of LEDs, +although it can also be used to generate PWM signals for other purposes. + +ESP32 SoCs has from 6 to 16 channels (variates on socs, see table below) which can generate independent waveforms, that can be used for example to drive RGB LED devices. + +========= ======================= +ESP32 SoC Number of LEDC channels +========= ======================= +ESP32 16 +ESP32-S2 8 +ESP32-C3 6 +ESP32-S3 8 +========= ======================= + +Arduino-ESP32 LEDC API +---------------------- + +ledcSetup +********* + +This function is used to setup the LEDC channel frequency and resolution. + +.. code-block:: arduino + + double ledcSetup(uint8_t channel, double freq, uint8_t resolution_bits); + +* ``channel`` select LEDC channel to config. +* ``freq`` select frequency of pwm. +* ``resolution_bits`` select resolution for ledc channel. + + * range is 1-14 bits (1-20 bits for ESP32). + +This function will return ``frequency`` configured for LEDC channel. +If ``0`` is returned, error occurs and ledc channel was not configured. + +ledcWrite +********* + +This function is used to set duty for the LEDC channel. + +.. code-block:: arduino + + void ledcWrite(uint8_t chan, uint32_t duty); + +* ``chan`` select the LEDC channel for writing duty. +* ``duty`` select duty to be set for selected channel. + +ledcRead +******** + +This function is used to get configured duty for the LEDC channel. + +.. code-block:: arduino + + uint32_t ledcRead(uint8_t chan); + +* ``chan`` select LEDC channel to read the configured duty. + +This function will return ``duty`` set for selected LEDC channel. + +ledcReadFreq +************ + +This function is used to get configured frequency for the LEDC channel. + +.. code-block:: arduino + + double ledcReadFreq(uint8_t chan); + +* ``chan`` select the LEDC channel to read the configured frequency. + +This function will return ``frequency`` configured for selected LEDC channel. + +ledcWriteTone +************* + +This function is used to setup the LEDC channel to 50 % PWM tone on selected frequency. + +.. code-block:: arduino + + double ledcWriteTone(uint8_t chan, double freq); + +* ``chan`` select LEDC channel. +* ``freq`` select frequency of pwm signal. + +This function will return ``frequency`` set for channel. +If ``0`` is returned, error occurs and ledc cahnnel was not configured. + +ledcWriteNote +************* + +This function is used to setup the LEDC channel to specific note. + +.. code-block:: arduino + + double ledcWriteNote(uint8_t chan, note_t note, uint8_t octave); + +* ``chan`` select LEDC channel. +* ``note`` select note to be set. + +======= ======= ======= ======= ======= ====== +NOTE_C NOTE_Cs NOTE_D NOTE_Eb NOTE_E NOTE_F +NOTE_Fs NOTE_G NOTE_Gs NOTE_A NOTE_Bb NOTE_B +======= ======= ======= ======= ======= ====== + +* ``octave`` select octave for note. + +This function will return ``frequency`` configured for the LEDC channel according to note and octave inputs. +If ``0`` is returned, error occurs and the LEDC channel was not configured. + +ledcAttachPin +************* + +This function is used to attach the pin to the LEDC channel. + +.. code-block:: arduino + + void ledcAttachPin(uint8_t pin, uint8_t chan); + +* ``pin`` select GPIO pin. +* ``chan`` select LEDC channel. + +ledcDetachPin +************* + +This function is used to detach the pin from LEDC. + +.. code-block:: arduino + + void ledcDetachPin(uint8_t pin); + +* ``pin`` select GPIO pin. + +ledcChangeFrequency +******************* + +This function is used to set frequency for the LEDC channel. + +.. code-block:: arduino + + double ledcChangeFrequency(uint8_t chan, double freq, uint8_t bit_num); + +* ``channel`` select LEDC channel. +* ``freq`` select frequency of pwm. +* ``bit_num`` select resolution for LEDC channel. + + * range is 1-14 bits (1-20 bits for ESP32). + +This function will return ``frequency`` configured for the LEDC channel. +If ``0`` is returned, error occurs and the LEDC channel frequency was not set. + +analogWrite +*********** + +This function is used to write an analog value (PWM wave) on the pin. +It is compatible with Arduinos analogWrite function. + +.. code-block:: arduino + + void analogWrite(uint8_t pin, int value); + +* ``pin`` select the GPIO pin. +* ``value`` select the duty cycle of pwm. + * range is from 0 (always off) to 255 (always on). + +Example Applications +******************** + +LEDC software fade example: + +.. literalinclude:: ../../../libraries/ESP32/examples/AnalogOut/LEDCSoftwareFade/LEDCSoftwareFade.ino + :language: arduino + +LEDC Write RGB example: + +.. literalinclude:: ../../../libraries/ESP32/examples/AnalogOut/ledcWrite_RGB/ledcWrite_RGB.ino + :language: arduino diff --git a/docs/source/api/preferences.rst b/docs/source/api/preferences.rst new file mode 100644 index 00000000000..86268cfc507 --- /dev/null +++ b/docs/source/api/preferences.rst @@ -0,0 +1,701 @@ +########### +Preferences +########### + +About +----- + +The Preferences library is unique to arduino-esp32. It should be considered as the replacement for the Arduino EEPROM library. + +It uses a portion of the on-board non-volatile memory (NVS) of the ESP32 to store data. This data is retained across restarts and loss of power events to the system. + +Preferences works best for storing many small values, rather than a few large values. If large amounts of data are to be stored, consider using a file system library such as LitteFS. + +The Preferences library is usable by all ESP32 variants. + + +Header File +----------- + +.. code-block:: arduino + + #include +.. + + +Overview +-------- + +Library methods are provided to: + - create a namespace; + - open and close a namespace; + - store and retrieve data within a namespace for supported data types; + - determine if a key value has been initialized; + - delete a ``key-value`` pair; + - delete all ``key-value`` pairs in a namespace; + - determine data types stored against a key; + - determine the number of key entries in the namespace. + +Preferences directly supports the following data types: + +.. table:: **Table 1 — Preferences Data Types** + :align: center + + +-------------------+-------------------+---------------+ + | Preferences Type | Data Type | Size (bytes) | + +===================+===================+===============+ + | Bool | bool | 1 | + +-------------------+-------------------+---------------+ + | Char | int8_t | 1 | + +-------------------+-------------------+---------------+ + | UChar | uint8_t | 1 | + +-------------------+-------------------+---------------+ + | Short | int16_t | 2 | + +-------------------+-------------------+---------------+ + | UShort | uint16_t | 2 | + +-------------------+-------------------+---------------+ + | Int | int32_t | 4 | + +-------------------+-------------------+---------------+ + | UInt | uint32_t | 4 | + +-------------------+-------------------+---------------+ + | Long | int32_t | 4 | + +-------------------+-------------------+---------------+ + | ULong | uint32_t | 4 | + +-------------------+-------------------+---------------+ + | Long64 | int64_t | 8 | + +-------------------+-------------------+---------------+ + | ULong64 | uint64_t | 8 | + +-------------------+-------------------+---------------+ + | Float | float_t | 8 | + +-------------------+-------------------+---------------+ + | Double | double_t | 8 | + +-------------------+-------------------+---------------+ + | | const char* | variable | + | String +-------------------+ | + | | String | | + +-------------------+-------------------+---------------+ + | Bytes | uint8_t | variable | + +-------------------+-------------------+---------------+ + +String values can be stored and retrieved either as an Arduino String or as a null terminated ``char`` array (c-string). + +Bytes type is used for storing and retrieving an arbitrary number of bytes in a namespace. + + +Arduino-esp32 Preferences API +----------------------------- + +``begin`` +********** + + Open non-volatile storage with a given namespace name from an NVS partition. + + .. code-block:: arduino + + bool begin(const char * name, bool readOnly=false, const char* partition_label=NULL) + .. + + **Parameters** + * ``name`` (Required) + - Namespace name. Maximum length is 15 characters. + + * ``readOnly`` (Optional) + - ``false`` will open the namespace in read-write mode. + - ``true`` will open the namespace in read-only mode. + - if omitted, the namespace is opened in read-write mode. + + * ``partition_label`` (Optional) + - name of the NVS partition in which to open the namespace. + - if omitted, the namespace is opened in the "``nvs``" partition. + + **Returns** + * ``true`` if the namespace was opened successfully; ``false`` otherwise. + + **Notes** + * If the namespace does not exist within the partition, it is first created. + * Attempting to write a key value to a namespace open in read-only mode will fail. + * A message providing the reason for a failed call is sent to the arduino-esp32 ``log_e`` facility. + + +``end`` +********* + + Close the currently opened namespace. + + .. code-block:: arduino + + void end() + .. + + **Parameters** + * None + + **Returns** + * Nothing + + **Note** + * After closing a namespace, methods used to access it will fail. + + +``clear`` +********** + + Delete all keys and values from the currently opened namespace. + + .. code-block:: arduino + + bool clear() + .. + + **Parameters** + * None + + **Returns** + * ``true`` if all keys and values were deleted; ``false`` otherwise. + + **Note** + * the namespace name still exists afterward. + * A message providing the reason for a failed call is sent to the arduino-esp32 ``log_e`` facility. + + +``remove`` +************* + + Delete a key-value pair from the currently open namespace. + + .. code-block:: arduino + + bool remove(const char * key) + .. + + **Parameters** + * ``key`` (Required) + - the name of the key to be deleted. + + **Returns** + * ``true`` if key-value pair was deleted; ``false`` otherwise. + + **Note** + * A message providing the reason for a failed call is sent to the arduino-esp32 ``log_e`` facility. + + +``putChar, putUChar`` +********************** + + Store a value against a given key in the currently open namespace. + + .. code-block:: arduino + + size_t putChar(const char* key, int8_t value) + size_t putUChar(const char* key, uint8_t value) + + .. + + **Parameters** + * ``key`` (Required) + - if the key does not exist in the currently opened namespace it is first created. + + * ``value`` (Required) + - must match the data type of the method. + + **Returns** + * ``1`` (the number of bytes stored for these data types) if the call is successful; ``0`` otherwise. + + **Notes** + * Attempting to store a value without a namespace being open in read-write mode will fail. + * A message providing the reason for a failed call is sent to the arduino-esp32 ``log_e`` facility. + + +``putShort, putUShort`` +************************ + + Store a value against a given key in the currently open namespace. + + .. code-block:: arduino + + size_t putShort(const char* key, int16_t value) + size_t putUShort(const char* key, uint16_t value) + + .. + + **Parameters** + * ``key`` (Required) + - if the key does not exist in the currently opened namespace it is first created. + + * ``value`` (Required) + - must match the data type of the method. + + **Returns** + * ``2`` (the number of bytes stored for these data types) if the call is successful; ``0`` otherwise. + + **Notes** + * Attempting to store a value without a namespace being open in read-write mode will fail. + * A message providing the reason for a failed call is sent to the arduino-esp32 ``log_e`` facility. + + + +``putInt, putUInt`` +******************** +``putLong, putULong`` +********************** + + Store a value against a given key in the currently open namespace. + + .. code-block:: arduino + + size_t putInt(const char* key, int32_t value) + size_t putUInt(const char* key, uint32_t value) + size_t putLong(const char* key, int32_t value) + size_t putULong(const char* key, uint32_t value) + + .. + + **Parameters** + * ``key`` (Required) + - if the key does not exist in the currently opened namespace it is first created. + + * ``value`` (Required) + - must match the data type of the method. + + **Returns** + * ``4`` (the number of bytes stored for these data types) if the call is successful; ``0`` otherwise. + + **Notes** + * Attempting to store a value without a namespace being open in read-write mode will fail. + * A message providing the reason for a failed call is sent to the arduino-esp32 ``log_e`` facility. + + +``putLong64, putULong64`` +************************* +``putFloat, putDouble`` +*********************** + + Store a value against a given key in the currently open namespace. + + .. code-block:: arduino + + size_t putLong64(const char* key, int64_t value) + size_t putULong64(const char* key, uint64_t value) + size_t putFloat(const char* key, float_t value) + size_t putDouble(const char* key, double_t value) + + .. + + **Parameters** + * ``key`` (Required) + - if the key does not exist in the currently opened namespace it is first created. + + * ``value`` (Required) + - must match the data type of the method. + + **Returns** + * ``8`` (the number of bytes stored for these data types) if the call is successful; ``0`` otherwise. + + **Notes** + * Attempting to store a value without a namespace being open in read-write mode will fail. + * A message providing the reason for a failed call is sent to the arduino-esp32 ``log_e`` facility. + + +``putBool`` +*********** + + Store a value against a given key in the currently open namespace. + + .. code-block:: arduino + + size_t putBool(const char* key, bool value) + + .. + + **Parameters** + * ``key`` (Required) + - if the key does not exist in the currently opened namespace it is first created. + + * ``value`` (Required) + - must match the data type of the method. + + **Returns** + * ``true`` if successful; ``false`` otherwise. + + **Notes** + * Attempting to store a value without a namespace being open in read-write mode will fail. + * A message providing the reason for a failed call is sent to the arduino-esp32 ``log_e`` facility. + + +``putString`` +************** + + Store a variable length value against a given key in the currently open namespace. + + .. code-block:: arduino + + size_t putString(const char* key, const char* value); + size_t putString(const char* key, String value); + + .. + + **Parameters** + * ``key`` (Required) + - if the key does not exist in the currently opened namespace it is first created. + + * ``value`` (Required) + - if ``const char*``, a null-terminated (c-string) character array. + - if ``String``, a valid Arduino String type. + + **Returns** + * if successful: the number of bytes stored; ``0`` otherwise. + + **Notes** + * Attempting to store a value without a namespace being open in read-write mode will fail. + * A message providing the reason for a failed call is sent to the arduino-esp32 ``log_e`` facility. + + +``putBytes`` +************ + + Store a variable number of bytes against a given key in the currently open namespace. + + .. code-block:: arduino + + size_t putBytes(const char* key, const void* value, size_t len); + + .. + + **Parameters** + * ``key`` (Required) + - if the key does not exist in the currently opened namespace it is first created. + + * ``value`` (Required) + - pointer to an array or buffer containing the bytes to be stored. + + * ``len`` (Required) + - the number of bytes from ``value`` to be stored. + + **Returns** + * if successful: the number of bytes stored; ``0`` otherwise. + + **Notes** + * Attempting to store a value without a namespace being open in read-write mode will fail. + * This method operates on the bytes used by the underlying data type, not the number of elements of a given data type. The data type of ``value`` is not retained by the Preferences library afterward. + * A message providing the reason for a failed call is sent to the arduino-esp32 ``log_e`` facility. + + +``getChar, getUChar`` +********************* + + Retrieve a value stored against a given key in the currently open namespace. + + .. code-block:: arduino + + int8_t getChar(const char* key, int8_t defaultValue = 0) + uint8_t getUChar(const char* key, uint8_t defaultValue = 0) + + .. + + **Parameters** + * ``key`` (Required) + + * ``defaultValue`` (Optional) + - must match the data type of the method if provided. + + **Returns** + * the value stored against ``key`` if the call is successful. + * ``defaultValue``, if it is provided; ``0`` otherwise. + + **Notes** + * Attempting to retrieve a key without a namespace being available will fail. + * Attempting to retrieve value from a non existant key will fail. + * A message providing the reason for a failed call is sent to the arduino-esp32 ``log_e`` facility. + + +``getShort, getUShort`` +**************************** + + Retrieve a value stored against a given key in the currently open namespace. + + .. code-block:: arduino + + int16_t getShort(const char* key, int16_t defaultValue = 0) + uint16_t getUShort(const char* key, uint16_t defaultValue = 0) + .. + + Except for the data type returned, behaves exactly like ``getChar``. + + + +``getInt, getUInt`` +******************* + + Retrieve a value stored against a given key in the currently open namespace. + + .. code-block:: arduino + + int32_t getInt(const char* key, int32_t defaultValue = 0) + uint32_t getUInt(const char* key, uint32_t defaultValue = 0) + + .. + + Except for the data type returned, behaves exactly like ``getChar``. + + +``getLong, getULong`` +********************* + + Retrieve a value stored against a given key in the currently open namespace. + + .. code-block:: arduino + + int32_t getLong(const char* key, int32_t defaultValue = 0) + uint32_t getULong(const char* key, uint32_t defaultValue = 0) + + .. + + Except for the data type returned, behaves exactly like ``getChar``. + + +``getLong64, getULong64`` +************************* + + Retrieve a value stored against a given key in the currently open namespace. + + .. code-block:: arduino + + int64_t getLong64(const char* key, int64_t defaultValue = 0) + uint64_t getULong64(const char* key, uint64_t defaultValue = 0) + + .. + + Except for the data type returned, behaves exactly like ``getChar``. + + +``getFloat`` +************* + + Retrieve a value stored against a given key in the currently open namespace. + + .. code-block:: arduino + + float_t getFloat(const char* key, float_t defaultValue = NAN) + + .. + + Except for the data type returned and the value of ``defaultValue``, behaves exactly like ``getChar``. + + +``getDouble`` +************* + + Retrieve a value stored against a given key in the currently open namespace. + + .. code-block:: arduino + + double_t getDouble(const char* key, double_t defaultValue = NAN) + + .. + + Except for the data type returned and the value of ``defaultValue``, behaves exactly like ``getChar``. + + +``getBool`` +************ + + Retrieve a value stored against a given key in the currently open namespace. + + .. code-block:: arduino + + uint8_t getUChar(const char* key, uint8_t defaultValue = 0); + + .. + + Except for the data type returned, behaves exactly like ``getChar``. + + +``getString`` +************* + + Copy a string of ``char`` stored against a given key in the currently open namespace to a buffer. + +.. code-block:: arduino + + size_t getString(const char* key, char* value, size_t len); +.. + + **Parameters** + * ``key`` (Required) + * ``value`` (Required) + - a buffer of a size large enough to hold ``len`` bytes + * ``len`` (Required) + - the number of type ``char``` to be written to the buffer pointed to by ``value`` + + **Returns** + * if successful; the number of bytes equal to ``len`` is written to the buffer pointed to by ``value``, and the method returns ``1``. + * if the method fails, nothing is written to the buffer pointed to by ``value`` and the method returns ``0``. + + **Notes** + * ``len`` must equal the number of bytes stored against the key or the call will fail. + * A message providing the reason for a failed call is sent to the arduino-esp32 ``log_e`` facility. + + +``getString`` +************* + + Retrieve an Arduino String value stored against a given key in the currently open namespace. + +.. code-block:: arduino + + String getString(const char* key, String defaultValue = String()); + +.. + + **Parameters** + * ``key`` (Required) + * ``defaultValue`` (Optional) + + **Returns** + * the value stored against ``key`` if the call if successful + * if the method fails: it returns ``defaultValue``, if provided; ``""`` (an empty String) otherwise. + + **Notes** + * ``defaultValue`` must be of type ``String``. + + +``getBytes`` +************* + +Copy a series of bytes stored against a given key in the currently open namespace to a buffer. + +.. code-block:: arduino + + size_t getBytes(const char* key, void * buf, size_t len); + +.. + + **Parameters** + * ``key`` (Required) + * ``buf`` (Required) + - a buffer of a size large enough to hold ``len`` bytes. + * ``len`` (Required) + - the number of bytes to be written to the buffer pointed to by ``buf`` + + **Returns** + * if successful, the number of bytes equal to ``len`` is written to buffer ``buf``, and the method returns ``1``. + * if the method fails, nothing is written to the buffer and the method returns ``0``. + + **Notes** + * ``len`` must equal the number of bytes stored against the key or the call will fail. + * A message providing the reason for a failed call is sent to the arduino-esp32 ``log_e`` facility. + + +``getBytesLength`` +****************** + +Get the number of bytes stored in the value against a key of type ``Bytes`` in the currently open namespace. + +.. code-block:: arduino + + size_t getBytesLength(const char* key) + +.. + + **Parameters** + * ``key`` (Required) + + **Returns** + * if successful: the number of bytes in the value stored against ``key``; ``0`` otherwise. + + **Notes** + * This method will fail if ``key`` is not of type ``Bytes``. + * A message providing the reason for a failed call is sent to the arduino-esp32 ``log_e`` facility. + + +``getType`` +*********** + +Get the Preferences data type of a given key within the currently open namespace. + +.. code-block:: arduino + + PreferenceType getType(const char* key) + +.. + + **Parameters** + * ``key`` (Required) + + **Returns** + * an ``int`` value as per Table 2 below. + * a value of ``10`` (PT_INVALID) if the call fails. + + **Notes** + * The return values are enumerated in ``Preferences.h``. Table 2 includes the enumerated values for information. + * A return value can map to more than one Prefs Type. + * The method will fail if: the namespace is not open; the key does not exist; the provided key exceeds 15 characters. + +.. table:: **Table 2 — getType Return Values** + :align: center + + +---------------+---------------+-------------------+-----------------------+ + | Return value | Prefs Type | Data Type | Enumerated Value | + +===============+===============+===================+=======================+ + | 0 | Char | int8_t | PT_I8 | + +---------------+---------------+-------------------+-----------------------+ + | 1 | UChar | uint8_t | PT_U8 | + | +---------------+-------------------+ | + | | Bool | bool | | + +---------------+---------------+-------------------+-----------------------+ + | 2 | Short | int16_t | PT_I16 | + +---------------+---------------+-------------------+-----------------------+ + | 3 | UShort | uint16_t | PT_U16 | + +---------------+---------------+-------------------+-----------------------+ + | 4 | Int | int32_t | PT_I32 | + | +---------------+ | | + | | Long | | | + +---------------+---------------+-------------------+-----------------------+ + | 5 | UInt | uint32_t | PT_U32 | + | +---------------+ | | + | | ULong | | | + +---------------+---------------+-------------------+-----------------------+ + | 6 | Long64 | int64_t | PT_I64 | + +---------------+---------------+-------------------+-----------------------+ + | 7 | ULong64 | uint64_t | PT_U64 | + +---------------+---------------+-------------------+-----------------------+ + | 8 | String | String | PT_STR | + | | +-------------------+ | + | | | \*char | | + +---------------+---------------+-------------------+-----------------------+ + | 9 | Double | double_t | PT_BLOB | + | +---------------+-------------------+ | + | | Float | float_t | | + | +---------------+-------------------+ | + | | Bytes | uint8_t | | + +---------------+---------------+-------------------+-----------------------+ + | 10 | \- | \- | PT_INVALID | + +---------------+---------------+-------------------+-----------------------+ + + +``freeEntries`` +*************** + +Get the number of free entries available in the key table of the currently open namespace. + +.. code-block:: arduino + + size_t freeEntries() + +.. + + **Parameters** + * none + + **Returns** + * if successful: the number of free entries available in the key table of the currently open namespace; ``0`` otherwise. + + **Notes** + * keys storing values of type ``Bool``, ``Char``, ``UChar``, ``Short``, ``UShort``, ``Int``, ``UInt``, ``Long``, ``ULong``, ``Long64``, ``ULong64`` use one entry in the key table. + * keys storing values of type ``Float`` and ``Double`` use three entries in the key table. + * Arduino or c-string ``String`` types use a minimum of two key table entries with the number of entries increasing with the length of the string. + * keys storing values of type ``Bytes`` use a minimum of three key table entries with the number of entries increasing with the number of bytes stored. + * A message providing the reason for a failed call is sent to the arduino-esp32 ``log_e`` facility. + + +.. --- EOF ---- \ No newline at end of file diff --git a/docs/source/api/sigmadelta.rst b/docs/source/api/sigmadelta.rst new file mode 100644 index 00000000000..d5036a38487 --- /dev/null +++ b/docs/source/api/sigmadelta.rst @@ -0,0 +1,84 @@ +########## +SigmaDelta +########## + +About +----- + +ESP32 provides a second-order sigma delta modulation module and 8 (4 for ESP32-C3) +independent modulation channels. The channels are capable to output 1-bit +signals (output index: 100 ~ 107) with sigma delta modulation. + +========= ============================= +ESP32 SoC Number of SigmaDelta channels +========= ============================= +ESP32 8 +ESP32-S2 8 +ESP32-C3 4 +ESP32-S3 8 +========= ============================= + +Arduino-ESP32 SigmaDelta API +---------------------------- + +sigmaDeltaSetup +*************** + +This function is used to setup the SigmaDelta channel frequency and resolution. + +.. code-block:: arduino + + double ledcSetup(uint8_t channel, double freq, uint8_t resolution_bits); + +* ``pin`` select GPIO pin. +* ``channel`` select SigmaDelta channel. +* ``freq`` select frequency. + + * range is 1-14 bits (1-20 bits for ESP32). + +This function will return ``frequency`` configured for the SigmaDelta channel. +If ``0`` is returned, error occurs and the SigmaDelta channel was not configured. + +sigmaDeltaWrite +*************** + +This function is used to set duty for the SigmaDelta channel. + +.. code-block:: arduino + + void sigmaDeltaWrite(uint8_t channel, uint8_t duty); + +* ``channel`` select SigmaDelta channel. +* ``duty`` select duty to be set for selected channel. + +sigmaDeltaRead +************** + +This function is used to get configured duty for the SigmaDelta channel. + +.. code-block:: arduino + + uint8_t sigmaDeltaRead(uint8_t channel) + +* ``channnel`` select SigmaDelta channel. + +This function will return ``duty`` configured for the selected SigmaDelta channel. + +sigmaDeltaDetachPin +******************* + +This function is used to detach pin from SigmaDelta. + +.. code-block:: arduino + + void sigmaDeltaDetachPin(uint8_t pin); + +* ``pin`` select GPIO pin. + +Example Applications +******************** + +Here is example use of SigmaDelta: + +.. literalinclude:: ../../../libraries/ESP32/examples/AnalogOut/SigmaDelta/SigmaDelta.ino + :language: arduino diff --git a/docs/source/api/timer.rst b/docs/source/api/timer.rst new file mode 100644 index 00000000000..67bdd65effa --- /dev/null +++ b/docs/source/api/timer.rst @@ -0,0 +1,377 @@ +########## +Timer +########## + +About +----- + +The ESP32 SoCs contains from 2 to 4 hardware timers. +They are all 64-bit (54-bit for ESP32-C3) generic timers based on 16-bit pre-scalers and 64-bit (54-bit for ESP32-C3) +up / down counters which are capable of being auto-reloaded. + +========= ================ +ESP32 SoC Number of timers +========= ================ +ESP32 4 +ESP32-S2 4 +ESP32-C3 2 +ESP32-S3 4 +========= ================ + +Arduino-ESP32 Timer API +---------------------------- + +timerBegin +********** + +This function is used to configure the timer. After successful setup the timer will automatically start. + +.. code-block:: arduino + + hw_timer_t * timerBegin(uint8_t num, uint16_t divider, bool countUp); + +* ``num`` select timer number. +* ``divider`` select timer divider. +* ``resolution`` select timer resolution. + + * range is 1-14 bits (1-20 bits for ESP32). + +This function will return ``timer`` structure if configuration is successful. +If ``NULL`` is returned, error occurs and the timer was not configured. + +timerEnd +******** + +This function is used to end timer. + +.. code-block:: arduino + + void timerEnd(hw_timer_t *timer); + +* ``timer`` timer struct. + +timerSetConfig +************** + +This function is used to configure initialized timer (timerBegin() called). + +.. code-block:: arduino + + uint32_t timerGetConfig(hw_timer_t *timer); + +* ``timer`` timer struct. + +This function will return ``configuration`` as uint32_t number. +This can be translated by inserting it to struct ``timer_cfg_t.val``. + +timerAttachInterrupt +******************** + +This function is used to attach interrupt to timer. + +.. code-block:: arduino + + void timerAttachInterrupt(hw_timer_t *timer, void (*fn)(void), bool edge); + +* ``timer`` timer struct. +* ``fn`` funtion to be called when interrupt is triggered. +* ``edge`` select edge to trigger interrupt (only LEVEL trigger is currently supported). + +timerDetachInterrupt +******************** + +This function is used to detach interrupt from timer. + +.. code-block:: arduino + + void timerDetachInterrupt(hw_timer_t *timer); + +* ``timer`` timer struct. + +timerStart +********** + +This function is used to start counter of the timer. + +.. code-block:: arduino + + void timerStart(hw_timer_t *timer); + +* ``timer`` timer struct. + +timerStop +********* + +This function is used to stop counter of the timer. + +.. code-block:: arduino + + void timerStop(hw_timer_t *timer); + +* ``timer`` timer struct. + +timerRestart +************ + +This function is used to restart counter of the timer. + +.. code-block:: arduino + + void timerRestart(hw_timer_t *timer); + +* ``timer`` timer struct. + +timerWrite +********** + +This function is used to set counter value of the timer. + +.. code-block:: arduino + + void timerWrite(hw_timer_t *timer, uint64_t val); + +* ``timer`` timer struct. +* ``val`` counter value to be set. + +timerSetDivider +*************** + +This function is used to set the divider of the timer. + +.. code-block:: arduino + + void timerSetDivider(hw_timer_t *timer, uint16_t divider); + +* ``timer`` timer struct. +* ``divider`` divider to be set. + +timerSetCountUp +*************** + +This function is used to configure counting direction of the timer. + +.. code-block:: arduino + + void timerSetCountUp(hw_timer_t *timer, bool countUp); + +* ``timer`` timer struct. +* ``countUp`` select counting direction (``true`` = increment). + +timerSetAutoReload +****************** + +This function is used to set counter value of the timer. + +.. code-block:: arduino + + void timerSetAutoReload(hw_timer_t *timer, bool autoreload); + +* ``timer`` timer struct. +* ``autoreload`` select autoreload (``true`` = enabled). + +timerStarted +************ + +This function is used to get if the timer is running. + +.. code-block:: arduino + + bool timerStarted(hw_timer_t *timer); + +* ``timer`` timer struct. + +This function will return ``true`` if the timer is running. If ``false`` is returned, timer is stopped. + +timerRead +********* + +This function is used to read counter value of the timer. + +.. code-block:: arduino + + uint64_t timerRead(hw_timer_t *timer); + +* ``timer`` timer struct. + +This function will return ``counter value`` of the timer. + +timerReadMicros +*************** + +This function is used to read counter value in microseconds of the timer. + +.. code-block:: arduino + + uint64_t timerReadMicros(hw_timer_t *timer); + +* ``timer`` timer struct. + +This function will return ``counter value`` of the timer in microseconds. + +timerReadMilis +************** + +This function is used to read counter value in miliseconds of the timer. + +.. code-block:: arduino + + uint64_t timerReadMilis(hw_timer_t *timer); + +* ``timer`` timer struct. + +This function will return ``counter value`` of the timer in miliseconds. + +timerReadSeconds +**************** + +This function is used to read counter value in seconds of the timer. + +.. code-block:: arduino + + double timerReadSeconds(hw_timer_t *timer); + +* ``timer`` timer struct. + +This function will return ``counter value`` of the timer in seconds. + +timerGetDivider +*************** + +This function is used to get divider of the timer. + +.. code-block:: arduino + + uint16_t timerGetDivider(hw_timer_t *timer); + +* ``timer`` timer struct. + +This function will return ``divider`` of the timer. + +timerGetCountUp +*************** + +This function is used get counting direction of the timer. + +.. code-block:: arduino + + bool timerGetCountUp(hw_timer_t *timer); + +* ``timer`` timer struct. + +This function will return ``true`` if the timer counting direction is UP (incrementing). +If ``false`` returned, the timer counting direction is DOWN (decrementing). + +timerGetAutoReload +****************** + +This function is used to get configuration of auto reload of the timer. + +.. code-block:: arduino + + bool timerGetAutoReload(hw_timer_t *timer); + +* ``timer`` timer struct. + +This function will return ``true`` if the timer auto reload is enabled. +If ``false`` returned, the timer auto reload is disabled. + +timerAlarmEnable +**************** + +This function is used to enable generation of timer alarm events. + +.. code-block:: arduino + + void timerAlarmEnable(hw_timer_t *timer); + +* ``timer`` timer struct. + +timerAlarmDisable +***************** + +This function is used to disable generation of timer alarm events. + +.. code-block:: arduino + + void timerAlarmDisable(hw_timer_t *timer); + +* ``timer`` timer struct. + +timerAlarmWrite +*************** + +This function is used to configure alarm value and autoreload of the timer. + +.. code-block:: arduino + + void timerAlarmWrite(hw_timer_t *timer, uint64_t alarm_value, bool autoreload); + +* ``timer`` timer struct. +* ``alarm_value`` alarm value to generate event. +* ``autoreload`` enabled/disabled autorealod. + +timerAlarmEnabled +***************** + +This function is used to get status of timer alarm. + +.. code-block:: arduino + + bool timerAlarmEnabled(hw_timer_t *timer); + +* ``timer`` timer struct. + +This function will return ``true`` if the timer alarm is enabled. +If ``false`` returned, the timer alarm is disabled. + +timerAlarmRead +************** + +This function is used to read alarm value of the timer. + +.. code-block:: arduino + + uint64_t timerAlarmRead(hw_timer_t *timer); + +* ``timer`` timer struct. + +timerAlarmReadMicros +******************** + +This function is used to read alarm value of the timer in microseconds. + +.. code-block:: arduino + + uint64_t timerAlarmReadMicros(hw_timer_t *timer); + +* ``timer`` timer struct. + +This function will return ``alarm value`` of the timer in microseconds. + +timerAlarmReadSeconds +********************* + +This function is used to read alarm value of the timer in seconds. + +.. code-block:: arduino + + double timerAlarmReadSeconds(hw_timer_t *timer); + +* ``timer`` timer struct. + +This function will return ``alarm value`` of the timer in seconds. + +Example Applications +******************** + +There are 2 examples uses of Timer: + +Repeat timer example: + +.. literalinclude:: ../../../libraries/ESP32/examples/Timer/RepeatTimer/RepeatTimer.ino + :language: arduino + +Watchdog timer example: + +.. literalinclude:: ../../../libraries/ESP32/examples/Timer/WatchdogTimer/WatchdogTimer.ino + :language: arduino \ No newline at end of file diff --git a/docs/source/api/usb_cdc.rst b/docs/source/api/usb_cdc.rst index 1c0b04f2f3c..7d700b955a8 100644 --- a/docs/source/api/usb_cdc.rst +++ b/docs/source/api/usb_cdc.rst @@ -34,6 +34,7 @@ Where ``event`` can be: * ARDUINO_USB_CDC_LINE_CODING_EVENT * ARDUINO_USB_CDC_RX_EVENT * ARDUINO_USB_CDC_TX_EVENT +* ARDUINO_USB_CDC_RX_OVERFLOW_EVENT * ARDUINO_USB_CDC_MAX_EVENT setRxBufferSize diff --git a/docs/source/api/wifi.rst b/docs/source/api/wifi.rst index b5214838084..5f1d100493e 100644 --- a/docs/source/api/wifi.rst +++ b/docs/source/api/wifi.rst @@ -67,6 +67,35 @@ Use static allocation if you want to have more performance and if your applicati By default, the memory allocation will be set to **dynamic** if this function is not being used. +setDualAntennaConfig +******************** + +Configures the Dual antenna functionallity. This function should be used only on the **ESP32-WROOM-DA** module or any other ESP32 with RF switch. + +.. code-block:: arduino + + bool setDualAntennaConfig(uint8_t gpio_ant1, uint8_t gpio_ant2, wifi_rx_ant_t rx_mode, wifi_tx_ant_t tx_mode); + + +* ``gpio_ant1`` Configure the GPIO number for the antenna 1 connected to the RF switch (default ``GPIO2`` on ESP32-WROOM-DA) +* ``gpio_ant2`` Configure the GPIO number for the antenna 2 connected to the RF switch (default ``GPIO25`` on ESP32-WROOM-DA) +* ``rx_mode`` Set the RX antenna mode. See wifi_rx_ant_t for the options. +* ``tx_mode`` Set the TX antenna mode. See wifi_tx_ant_t for the options. + +Return ``true`` if the configuration was successful. + +For the ``rx_mode`` you can use the following configuration: + +* ``WIFI_RX_ANT0`` Selects the antenna 1 for all RX activity. +* ``WIFI_RX_ANT1`` Selects the antenna 2 for all RX activity. +* ``WIFI_RX_ANT_AUTO`` Selects the antenna for RX automatically. + +For the ``tx_mode`` you can use the following configuration: + +* ``WIFI_TX_ANT0`` Selects the antenna 1 for all TX activity. +* ``WIFI_TX_ANT1`` Selects the antenna 2 for all TX activity. +* ``WIFI_TX_ANT_AUTO`` Selects the antenna for TX automatically. + WiFiAP ------ diff --git a/docs/source/boards/boards.rst b/docs/source/boards/boards.rst index 12dbe4b175d..b0376f9c398 100644 --- a/docs/source/boards/boards.rst +++ b/docs/source/boards/boards.rst @@ -98,18 +98,13 @@ Generic Vendor .. note:: Create one file per board or one file with multiple boards. Do not add board information/description on this file. +.. include:: ../common/datasheet.inc + Resources --------- -* `ESP32 Datasheet`_ (Datasheet) -* `ESP32-S2 Datasheet`_ (Datasheet) -* `ESP32-C3 Datasheet`_ (Datasheet) - .. _Espressif Systems: https://www.espressif.com .. _Espressif Product Selector: https://products.espressif.com/ -.. _ESP32 Datasheet: https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf -.. _ESP32-S2 Datasheet: https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf -.. _ESP32-C3 Datasheet: https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf .. |board_lolin_d32| raw:: html diff --git a/docs/source/boards/generic.rst b/docs/source/boards/generic.rst index 95bbcbeda4f..8ca4a79eace 100644 --- a/docs/source/boards/generic.rst +++ b/docs/source/boards/generic.rst @@ -26,9 +26,4 @@ Pin Layout Add here the pin layout image (not required). -Resources ---------- - -* `ESP32`_ (Datasheet) - -.. _ESP32: https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf +.. include:: ../common/datasheet.inc diff --git a/docs/source/common/datasheet.inc b/docs/source/common/datasheet.inc new file mode 100644 index 00000000000..5f68b0115ff --- /dev/null +++ b/docs/source/common/datasheet.inc @@ -0,0 +1,13 @@ +Datasheet +--------- + +* `ESP32`_ (Datasheet) +* `ESP32-S2`_ (Datasheet) +* `ESP32-C3`_ (Datasheet) +* `ESP32-S3`_ (Datasheet) + +.. _Espressif Product Selector: https://products.espressif.com/ +.. _ESP32: https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf +.. _ESP32-S2: https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf +.. _ESP32-C3: https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf +.. _ESP32-S3: https://www.espressif.com/sites/default/files/documentation/esp32-s3_datasheet_en.pdf diff --git a/docs/source/conf.py b/docs/source/conf.py index 33b42328007..7fd7e721150 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -18,11 +18,11 @@ # -- Project information ----------------------------------------------------- project = 'Arduino-ESP32' -copyright = '2021, Espressif' +copyright = '2022, Espressif' author = 'Espressif' # The full version, including alpha/beta/rc tags -release = '2.0.0' +release = '2.0.2' # -- General configuration --------------------------------------------------- @@ -30,7 +30,8 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx_copybutton' + 'sphinx_copybutton', + 'sphinx_tabs.tabs' ] # Add any paths that contain templates here, relative to this directory. diff --git a/docs/source/esp-idf_component.rst b/docs/source/esp-idf_component.rst index 3be9d85575d..f153f267e6b 100644 --- a/docs/source/esp-idf_component.rst +++ b/docs/source/esp-idf_component.rst @@ -1,20 +1,31 @@ -############################## -Arduino as a ESP-IDF component -############################## +############################### +Arduino as an ESP-IDF component +############################### + +This method is recommended for advanced users. To use this method, you will need to have the ESP-IDF toolchain installed. + +For a simplified method, see `Installing using Boards Manager `_. ESP32 Arduino lib-builder ------------------------- -For a simplified method, see `lib-builder `_. +If you don't need any modifications in the default Arduino ESP32 core, we recommend you to install using the Boards Manager. + +Arduino Lib Builder is the tool that integrates ESP-IDF into Arduino. It allows you to customize the default settings used by Espressif and try them in Arduino IDE. + +For more information see `Arduino lib builder `_ + Installation ------------ -.. note:: Latest Arduino Core ESP32 version is now compatible with `ESP-IDF v4.4 `_. Please consider this compability when using Arduino as component in ESP-IDF. +.. note:: Latest Arduino Core ESP32 version is now compatible with `ESP-IDF v4.4 `_. Please consider this compatibility when using Arduino as a component in ESP-IDF. + +#. Download and install `ESP-IDF `_. -- Download and install `ESP-IDF `_. -- Create blank ESP-IDF project (use sample_project from /examples/get-started) or choose one of the examples. -- In the project folder, create a new folder called `components` and clone this repository inside the new created folder. + * For more information see `Get Started `_. +#. Create a blank ESP-IDF project (use sample_project from /examples/get-started) or choose one of the examples. +#. In the project folder, create a new folder called ``components`` and clone this repository inside the newly created folder. .. code-block:: bash @@ -26,19 +37,33 @@ Installation cd ../.. && \ idf.py menuconfig +Configuration +------------- + +Depending on one of the two following options, in the menuconfig set the appropriate settings. + +Go to the section ``Arduino Configuration --->`` + +1. For usage of ``app_main()`` function - Turn off ``Autostart Arduino setup and loop on boot`` +2. For usage of ``setup()`` and ``loop()`` functions - Turn on ``Autostart Arduino setup and loop on boot`` + +Experienced users can explore other options in the Arduino section. + +After the setup you can save and exit: + +- Save [S] +- Confirm default filename [Enter] +- Close confirmation window [Enter] or [Space] or [Esc] +- Quit [Q] + Option 1. Using Arduino setup() and loop() ****************************************** -- The `idf.py menuconfig` has some Arduino options. - - Turn on `Autostart Arduino setup and loop on boot`. - - In main folder rename file `main.c` to `main.cpp`. - - In main folder open file `CMakeList.txt` and change `main.c` to `main.cpp` as described below. - -.. code-block:: bash +- In main folder rename file `main.c` to `main.cpp`. - idf_component_register(SRCS "main.cpp" INCLUDE_DIRS ".") +- In main folder open file `CMakeList.txt` and change `main.c` to `main.cpp` as described below. -- Your main.cpp should be formated like any other sketch. +- Your main.cpp should be formatted like any other sketch. .. code-block:: c @@ -46,7 +71,10 @@ Option 1. Using Arduino setup() and loop() #include "Arduino.h" void setup(){ - Serial.begin(115200); + Serial.begin(115200); + while(!Serial){ + ; // wait for serial port to connect + } } void loop(){ @@ -57,10 +85,10 @@ Option 1. Using Arduino setup() and loop() Option 2. Using ESP-IDF appmain() ********************************* -- You need to implement ``app_main()`` and call ``initArduino();`` in it. +In main.c or main.cpp you need to implement ``app_main()`` and call ``initArduino();`` in it. Keep in mind that setup() and loop() will not be called in this case. -If you plan to base your code on examples provided in `examples `_, please make sure to move the app_main() function in main.cpp from the files in the example. +Furthermore the ``app_main()`` is single execution as a normal function so if you need an infinite loop as in Arduino place it there. .. code-block:: cpp @@ -69,28 +97,39 @@ If you plan to base your code on examples provided in `examples flash monitor`` -- It will build, upload and open serial monitor to your board. + +- The project will build, upload and open the serial monitor to your board + + - Some boards require button combo press on the board: press-and-hold Boot button + press-and-release RST button, release Boot button + + - After a successful flash, you may need to press the RST button again + + - To terminate the serial monitor press [Ctrl] + [ ] ] Logging To Serial ----------------- -If you are writing code that does not require Arduino to compile and you want your `ESP_LOGx` macros to work in Arduino IDE, you can enable the compatibility by adding the following lines after: +If you are writing code that does not require Arduino to compile and you want your `ESP_LOGx` macros to work in Arduino IDE, you can enable the compatibility by adding the following lines: .. code-block:: c @@ -107,4 +146,4 @@ To fix that behavior, you need to set FreeRTOS tick rate to 1000Hz in `make menu Compilation Errors ------------------ -As commits are made to esp-idf and submodules, the codebases can develop incompatibilities which cause compilation errors. If you have problems compiling, follow the instructions in `Issue #1142 `_ to roll esp-idf back to a different version. +As commits are made to esp-idf and submodules, the codebases can develop incompatibilities that cause compilation errors. If you have problems compiling, follow the instructions in `Issue #1142 `_ to roll esp-idf back to a different version. diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index 91b66b343a3..e69373ea499 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -26,6 +26,9 @@ power consumption. The ESP32 series is available as a chip or module. + +.. _supported_socs: + Supported SoC's --------------- @@ -34,10 +37,10 @@ Here are the ESP32 series supported by the Arduino-ESP32 project: ======== ====== =========== =================================== SoC Stable Development Datasheet ======== ====== =========== =================================== -ESP32 Yes Yes `ESP32 Datasheet`_ -ESP32-S2 Yes Yes `ESP32-S2 Datasheet`_ -ESP32-C3 Yes Yes `ESP32-C3 Datasheet`_ -ESP32-S3 No No `ESP32-S3 Datasheet`_ +ESP32 Yes Yes `ESP32`_ +ESP32-S2 Yes Yes `ESP32-S2`_ +ESP32-C3 Yes Yes `ESP32-C3`_ +ESP32-S3 No Yes `ESP32-S3`_ ======== ====== =========== =================================== See `Boards `_ for more details about ESP32 development boards. @@ -63,6 +66,20 @@ Supported Operating Systems .. |linux-logo| image:: _static/logo_linux.png .. |macos-logo| image:: _static/logo_macos.png +Supported IDEs +--------------------------- + +Here is the list of supported IDE for Arduino ESP32 support integration. + ++-------------------+-------------------+ +| |arduino-logo| | |pio-logo| | ++-------------------+-------------------+ +| Arduino IDE | PlatformIO | ++-------------------+-------------------+ + +.. |arduino-logo| image:: _static/logo_arduino.png +.. |pio-logo| image:: _static/logo_pio.png + See `Installing Guides `_ for more details on how to install the Arduino ESP32 support. Support @@ -91,7 +108,9 @@ Before opening a new issue, please read this: Be sure to search for a similar reported issue. This avoids duplicating or creating noise in the GitHub Issues reporting. We also have the troubleshooting guide to save your time on the most common issues reported by users. -For more details, see the `Issue Template `_. +For more details about creating new Issue, see the `Issue Template `_. + +If you have any new idea, see the `Feature request Template `_. First Steps ----------- @@ -114,15 +133,14 @@ in the examples menu or inside each library folder. https://github.com/espressif/arduino-esp32/tree/master/libraries + +.. include:: common/datasheet.inc + Resources --------- .. _Espressif Systems: https://www.espressif.com .. _Espressif Product Selector: https://products.espressif.com/ -.. _ESP32 Datasheet: https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf -.. _ESP32-S2 Datasheet: https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf -.. _ESP32-C3 Datasheet: https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf -.. _ESP32-S3 Datasheet: https://www.espressif.com/sites/default/files/documentation/esp32-s3_datasheet_en.pdf .. _Arduino.cc: https://www.arduino.cc/en/Main/Software .. _Arduino Reference: https://www.arduino.cc/reference/en/ .. _ESP32 Forum: https://esp32.com diff --git a/docs/source/guides/docs_contributing.rst b/docs/source/guides/docs_contributing.rst new file mode 100644 index 00000000000..be5a54e4b37 --- /dev/null +++ b/docs/source/guides/docs_contributing.rst @@ -0,0 +1,334 @@ +##################################### +Documentation Contribution Guidelines +##################################### + +Introduction +------------ + +This is a guideline for the Arduino ESP32 project documentation. The idea for this guideline is to show how to start collaborating on the project. + +The guideline works to give you the directions and to keep the documentation more concise, helping users to better understand the structure. + +About Documentation +------------------- + +We all know how important documentation is. This project is no different. + +This documentation was created in a collaborative and open way, letting everyone contribute, from a small typo fix to a new chapter writing. We try to motivate our community by giving all the support needed through this guide. + +The documentation is in **English only**. Future translations can be added when we finish the essential content in English first. + +How to Collaborate +------------------ + +Everyone with some knowledge to share is welcome to collaborate. + +One thing you need to consider is the fact that your contribution must be concise and assertive since it will be used by people developing projects. The information is very important for everyone, be sure you are not making the developer's life harder! + +Documentation Guide +------------------- + +This documentation is based on the `Sphinx`_ with `reStructuredText`_ and hosted by `ReadTheDocs`_. + +If you want to get started with `Sphinx`_, see the official documentation: + +* `Documentation Index `_ +* `Basics `_ +* `Directives `_ + +First Steps +*********** + +Before starting your collaboration, you need to get the documentation source code from the Arduino-ESP32 project. + +* **Step 1** - Fork the `Arduino-ESP32`_ to your GitHub account. +* **Step 2** - Check out the recently created fork. +* **Step 3** - Create a new branch for the changes/addition to the docs. +* **Step 4** - Write! + +Requirements +************ + +To properly work with the documentation, you need to install some packages in your system. + +.. code-block:: + + pip install -U Sphinx + pip install -r requirements.txt + +The requirements file is under the ``docs`` folder. + +Using Visual Studio Code +************************ + +If you are using the Visual Studio Code, you can install some extensions to help you while writing documentation. + +`reStructuredText Pack `_ + +We also recommend you install to grammar check extension to help you to review English grammar. + +`Grammarly `_ + +Building +******** + +To build the documentation and generate the HTLM files, you can use the following command inside the ``docs`` folder. After a successful build, you can check the files inside the `build/html` folder. + +.. code-block:: + + make html + +This step is essential to ensure that there are no syntax errors and also to see the final result. + +If everything is ok, you will see some output logs similar to this one: + +.. code-block:: + + Running Sphinx v2.3.1 + loading pickled environment... done + building [mo]: targets for 0 po files that are out of date + building [html]: targets for 35 source files that are out of date + updating environment: [extensions changed ('sphinx_tabs.tabs')] 41 added, 3 changed, 0 removed + reading sources... [100%] tutorials/tutorials + looking for now-outdated files... none found + pickling environment... done + checking consistency... done + preparing documents... done + writing output... [100%] tutorials/tutorials + generating indices... genindexdone + writing additional pages... searchdone + copying images... [100%] tutorials/../_static/tutorials/peripherals/tutorial_peripheral_diagram.png + copying static files... ... done + copying extra files... done + dumping search index in English (code: en)... done + dumping object inventory... done + build succeeded. + +The HTML pages are in build/html. + +Sections +-------- + +The Arduino ESP32 is structured in some sections to make it easier to maintain. Here is a brief description of this structure. + +API +*** + +In this section, you will include all the documentation about drivers, libraries, and any other related to the core. + +In this section, we do not add general information. For more general information, we have sections for other related parts, like the FAQ, library builder, troubleshooting, etc. + +Boards +****** + +Here is the place to add any special guide on the development boards, pin layout, schematics, and any other relevant content. + +Common +****** + +In this folder, you can add all common information used in several different places. This helps to make documentation easily maintainable. + + +Guides +****** + +This is the place to add the guides for common applications, IDEs configuration, and any other information that can be used as a guideline. + +Tutorials +********* + +If you want to add a specific tutorial related to the Arduino core for ESP32, this is the place. The intention is not to create a blog or a demo area, but this can be used to add some complex description or to add some more information about APIs. + +Images and Assets +***************** + +All the files used on the documentation must be stored in the ``_static`` folder. Be sure that the content used is not with any copyright restriction. + +Documentation Rules +------------------- + +Here are some guidelines to help you. We also recommend copying a sample file from the same category you are creating. + +This will help you to follow the structure as well as to get inspired. + +Basic Structure +*************** + +To help you create a new section from scratch, we recommend you include this structure in your content if it applies. + +* **About** - Brief description of the document. + * Description of the peripheral, driver, protocol, including all different modes and configurations. +* **API** - Description of each public function, macros, and structs. +* **Basic Usage** +* **Example Application** + +About Section +^^^^^^^^^^^^^ + +In this section, you need to add a brief description of the API. If you are describing a peripheral API, you should explain a little bit about the peripheral and the working modes, if it's applicable. + +API Functions +^^^^^^^^^^^^^ + +To add a new function description, you must know that the users only have access to the public functions. + + +Here is an example of how to add the function description from `I2C API `_: + +.. code-block:: + + setPins + ^^^^^^^ + + This function is used to define the ``SDA`` and ``SCL`` pins. + + .. note:: Call this function before ``begin`` to change the pins from the default ones. + + .. code-block:: arduino + + bool setPins(int sdaPin, int sclPin); + + * ``sdaPin`` sets the GPIO to be used as the I2C peripheral data line. + + * ``sclPin`` sets the GPIO to be used as the I2C peripheral clock line. + + The default pins may vary from board to board. On the *Generic ESP32* the default I2C pins are: + + * ``sdaPin`` **GPIO21** + + * ``sclPin`` **GPIO22** + + This function will return ``true`` if the peripheral was configured correctly. + +Be sure to include a very comprehensive description, add all the parameters in and out, and describe the desired output. + +If the function uses a specific structure, you can also describe the structure in the same function block or add a specific section if the structure is shared with other functions. + +Basic Usage +^^^^^^^^^^^ + +Some APIs are more complex to use or require more steps in order to configure or initialize. If the API is not straightforward in terms of usability, please consider adding a how-to-use section describing all the steps to get the API configured. + +Here is an example: + +.. code-block:: + + Basic Usage + ^^^^^^^^^^^ + + To start using I2C as slave mode on the Arduino, the first step is to include the ``Wire.h`` header to the sketch. + + .. code-block:: arduino + + #include "Wire.h" + + Before calling ``begin``, you must create two callback functions to handle the communication with the master device. + + .. code-block:: arduino + + Wire.onReceive(onReceive); + + and + + .. code-block:: arduino + + Wire.onRequest(onRequest); + + The ``onReceive`` will handle the request from the ``master`` device upon a slave read request and the ``onRequest`` will handle the answer to the master. + + Now, we can start the peripheral configuration by calling ``begin`` function with the device address. + + .. code-block:: arduino + + Wire.begin((uint8_t)I2C_DEV_ADDR); + + By using ``begin`` without any arguments, all the settings will be done by using the default values. To set the values on your own, see the function description. This function is described here: `i2c begin`_ + + + +Example Application +^^^^^^^^^^^^^^^^^^^ +It is very important to include at least one application example or a code snippet to help people using the API. + +If the API does not have any application example, you can embed the code directly. However, if the example is available, you must include it as a literal block. + +.. code-block:: + + .. literalinclude:: ../../../libraries/WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino + :language: arduino + + +Sphinx Basics +------------- + +Heading Levels +************** + +The heading levels used on this documentation are: + +* **H1**: - (Dash) +* **H2**: * (Asterisk) +* **H3**: ^ (Circumflex) +* **H4**: # (Sharp) + +Code Block +********** + +To add a code block, you can use the following structure: + +.. code-block:: + + .. code-block:: arduino + bool begin(); //Code example + +Links +***** + +To include links to external content, you can use two ways. + +* First option: + +.. code-block:: + + `Arduino Wire Library`_ + + _Arduino Wire Library: https://www.arduino.cc/en/reference/wire + +* Second option: + +.. code-block:: + + `Arduino Wire Library `_ + +Images +****** + +To include images in the docs, first, add all the files into the ``_static`` folder with a filename that makes sense for the topic. + +After that, you can use the following structure to include the image in the docs. + +.. code-block:: + + .. figure:: ../_static/arduino_i2c_master.png + :align: center + :width: 720 + :figclass: align-center + +You can adjust the ``width`` according to the image size. + +Be sure the file size does not exceed 600kB. + +Support +******* + +If you need support on the documentation, you can ask a question in the discussion `here `_. + +Additional Guidelines +--------------------- + +If you want to contribute with code on the Arduino ESP32 core, be sure to follow the `ESP-IDF Documenting Code `_ as a reference. + +.. _Arduino-ESP32: https://github.com/espressif/arduino-esp32 +.. _Sphinx: https://www.sphinx-doc.org/en/master/ +.. _ReadTheDocs: https://readthedocs.org/ +.. _reStructuredText: https://docutils.sourceforge.io/rst.html diff --git a/docs/source/guides/guides.rst b/docs/source/guides/guides.rst new file mode 100644 index 00000000000..4aa538a7e22 --- /dev/null +++ b/docs/source/guides/guides.rst @@ -0,0 +1,10 @@ +###### +Guides +###### + +.. toctree:: + :caption: Guides: + :maxdepth: 1 + :glob: + + * diff --git a/docs/source/guides/tools_menu.rst b/docs/source/guides/tools_menu.rst new file mode 100644 index 00000000000..432511c191e --- /dev/null +++ b/docs/source/guides/tools_menu.rst @@ -0,0 +1,248 @@ +###################### +Arduino IDE Tools Menu +###################### + +Introduction +------------ + +This guide is a walkthrough of the Arduino IDE configuration menu for the ESP32 System on Chip (SoC's). In this guide, you will see the most relevant configuration +to get your project optimized and working. + +Since some boards and SoC's may vary in terms of hardware configuration, be sure you know all the board characteristics that you are using, like flash memory size, SoC variant (ESP32 family), PSRAM, etc. + +.. note:: To help you identify the characteristics, you can see the `Espressif Product Selector`_. + +Arduino IDE +----------- + +The Arduino IDE is widely used for ESP32 on Arduino development and offers a wide variety of configurations. + +Tools Menu +---------- + +To properly configure your project build and flash, some settings must be done in order to get it compiled and flashed without any issues. +Some boards are natively supported and almost no configuration is required. However, if your is not yet supported or you have a custom board, you need to configure the environment by yourself. + +For more details or to add a new board, see the `boards.txt`_ file. + +Generic Options +--------------- + +Most of the options are available for every ESP32 family. Some options will be available only for specific targets, like the USB configuration. + +Board +***** + +This option is the target board and must be selected in order to get all the default configuration settings. Once you select the correct board, you will see that some configurations will be automatically selected, but be aware that some boards can have multiple versions (i.e different flash sizes). + +To select the board, go to ``Tools -> Board -> ESP32 Arduino`` and select the target board. + +If your board is not present on this list, you can select the generic ``ESP32-XX Dev Module``. + +Currently, we have one generic development module for each of the supported targets. + +If the board selected belongs to another SoC family, you will see the following information at the build output: + + ``A fatal error occurred: This chip is ESP32 not ESP32-S2. Wrong --chip argument?`` + +Upload Speed +************ + +To select the flashing speed, change the ``Tools -> Upload Speed``. This value will be used for flashing the code to the device. + +.. note:: If you have issues while flashing the device at high speed, try to decrease this value. This could be due to the external serial-to-USB chip limitations. + +CPU Frequency +************* + +On this option, you can select the CPU clock frequency. This option is critical and must be selected according to the high-frequency crystal present on the board and the radio usage (Wi-Fi and Bluetooth). + +In some applications, reducing the CPU clock frequency is recommended in order to reduce power consumption. + +If you don't know why you should change this frequency, leave the default option. + +Flash Frequency +*************** + +Use this function to select the flash memory frequency. The frequency will be dependent on the memory model. + +* **40MHz** +* **80MHz** + +If you don't know if your memory supports **80Mhz**, you can try to upload the sketch using the **80MHz** option and watch the log output via the serial monitor. + +.. note:: In some boards/SoC, the flash frequency is automatically selected according to the flash mode. In some cases (i.e ESP32-S3), the flash frequency is up to 120MHz. + +Flash Mode +********** + +This option is used to select the SPI communication mode with the flash memory. + +Depending on the application, this mode can be changed in order to increase the flash communication speed. + +* **QIO** - Quad I/O Fast Read + * Four SPI pins are used to write to the flash and to read from the flash. + +* **DIO** - Dual I/O Fast Read + * Two SPI pins are used to write to the flash and to read from the flash. + +* **QOUT** - Quad Output Fast Read + * Four SPI pins are used to read the flash data. + +* **DOUT** - Dual Output Fast Read + * Two SPI pins are used to read flash data. + +* **OPI** - Octal I/O + * Eight SPI pins are used to write and to read from the flash. + +If you don't know how the board flash is physically connected or the flash memory model, try the **QIO** at **80MHz** first. + +Flash Size +********** + +This option is used to select the flash size. The flash size should be selected according to the flash model used on your board. + +* **2MB** (16Mb) +* **4MB** (32Mb) +* **8MB** (64Mb) +* **16MB** (128Mb) + +If you choose the wrong size, you may have issues when selecting the partition scheme. + +Embedded Flash +^^^^^^^^^^^^^^ + +Some SoC has embedded flash. The ESP32-S3 is a good example. + +.. note:: Check the manufacturer part number of your SoC/module to see the right version. + +Example: **ESP32-S3FH4R2** + +This particular ESP32-S3 variant comes with 4MB Flash and 2MB PSRAM. + +**Options for Embedded Flash** + +* **Fx4** 4MB Flash (*QIO*) +* **Fx8** 8MB Flash (*QIO*) +* **V** 1.8V SPI + +The **x** stands for the temperature range specification. + +* **H** High Temperature (*-40 to 85ºC*) +* **N** Low Temeprature (*-40 to 65ºC*) + +For more details, please see the corresponding datasheet at `Espressif Product Selector`_. + +Partition Scheme +**************** + +This option is used to select the partition model according to the flash size and the resources needed, like storage area and OTA (Over The Air updates). + +.. note:: Be careful selecting the right partition according to the flash size. If you select the wrong partition, the system will crash. + +Core Debug Level +**************** + +This option is used to select the Arduino core debugging level to be printed to the serial debug. + +* **None** - Prints nothing. +* **Error** - Only at error level. +* **Warning** - Only at warning level and above. +* **Info** - Only at info level and above. +* **Debug** - Only at debug level and above. +* **Verbose** - Prints everything. + +PSRAM +***** + +The PSRAM is an internal or external extended RAM present on some boards, modules or SoC. + +This option can be used to ``Enable`` or ``Disable`` PSRAM. In some SoCs, you can select the PSRAM mode as the following. + +* **QSPI PSRAM** - Quad PSRAM +* **OPI PSRAM** - Octal PSRAM + +Embedded PSRAM +^^^^^^^^^^^^^^ + +Some SoC has embedded PSRAM. The ESP32-S3 is a good example. + +Example: **ESP32-S3FH4R2** + +This particular ESP32-S3 comes with 4MB Flash and 2MB PSRAM. + +**Options for Embedded Flash and PSRAM** + +* **R2** 2MB PSRAM (*QSPI*) +* **R8** 8MB PSRAM (*OPI*) +* **V** 1.8V SPI + +The **x** stands for the temperature range specification. + +* **H** High Temperature (*-40 to 85ºC*) +* **N** Low Temeprature (*-40 to 65ºC*) + +For more details, please see the corresponding datasheet at `Espressif Product Selector`_. + +Arduino Runs On +*************** + +This function is used to select the core that runs the Arduino core. This is only valid if the target SoC has 2 cores. + +When you have some heavy task running, you might want to run this task on a different core than the Arduino tasks. For this reason, you have this configuration to select the right core. + +Events Run On +************* + +This function is also used to select the core that runs the Arduino events. This is only valid if the target SoC has 2 cores. + +Port +**** + +This option is used to select the serial port to be used on the flashing and monitor. + +USB Options +----------- + +Some ESP32 families have a USB peripheral. This peripheral can be used for flashing and debugging. + +To see the supported list for each SoC, see this section: `Libraries <../libraries.html>`_. + +The USB option will be available only if the correct target is selected. + +USB CDC On Boot +*************** + +The USB Communications Device Class, or USB CDC, is a class used for basic communication to be used as a regular serial controller (like RS-232). + +This class is used for flashing the device without any other external device attached to the SoC. + +This option can be used to ``Enable`` or ``Disable`` this function at the boot. If this option is ``Enabled``, once the device is connected via USB, one new serial port will appear in the list of the serial ports. +Use this new serial port for flashing the device. + +This option can be used as well for debugging via the ``Serial Monitor`` using **CDC** instead of the **UART0**. + +To use the UART as serial output, you can use ``Serial0.print("Hello World!");`` instead of ``Serial.print("Hello World!");`` which will be printed using USB CDC. + +USB Firmware MSC On Boot +************************ + +The USB Mass Storage Class, or USB MSC, is a class used for storage devices, like a USB flash drive. + +This option can be used to ``Enable`` or ``Disable`` this function at the boot. If this option is ``Enabled``, once the device is connected via USB, one new storage device will appear in the system as a storage drive. +Use this new storage drive to write and read files or to drop a new firmware binary to flash the device. + +.. figure:: ../_static/usb_msc_drive.png + :align: center + :width: 720 + :figclass: align-center + +USB DFU On Boot +*************** + +The USB Device Firmware Upgrade is a class used for flashing the device through USB. + +This option can be used to ``Enable`` or ``Disable`` this function at the boot. If this option is ``Enabled``, once the device is connected via USB, the device will appear as a USB DFU capable device. + +.. _Espressif Product Selector: https://products.espressif.com/ +.. _boards.txt: https://github.com/espressif/arduino-esp32/blob/master/boards.txt diff --git a/docs/source/index.rst b/docs/source/index.rst index 60d39d8442a..48f30396270 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -8,11 +8,12 @@ Here you will find all the relevant information about the project. This is a work in progress documentation and we will appreciate your help! We are looking for contributors! .. toctree:: - :maxdepth: 2 + :maxdepth: 1 :caption: Contents: Getting Started Libraries + Guides Tutorials Advanced Utilities FAQ diff --git a/docs/source/installing.rst b/docs/source/installing.rst index 59028fcbf1b..6120973fb87 100644 --- a/docs/source/installing.rst +++ b/docs/source/installing.rst @@ -7,16 +7,21 @@ This guide will show how to install the Arduino-ESP32 support. Before Installing ----------------- -We recommend you install the support using the Boards Manager, but other options are available depending on your operating system. +We recommend you install the support using your favorite IDE, but other options are available depending on your operating system. To install Arduino-ESP32 support, you can use one of the following options. -Installing using Boards Manager -------------------------------- +Installing using Arduino IDE +---------------------------- -This is the preferred and easiest way to install Arduino-ESP32. +.. figure:: _static/logo_arduino.png + :align: center + :width: 200 + :figclass: align-center + +This is the way to install Arduino-ESP32 directly from the Arduino IDE. .. note:: - Currently, the support for new chips (ESP32-S2 and ESP32-C3) is in the development release. Consider installing the development release if you need to test the new supported SoC in beta. + For overview of SoC's support, take a look on `Supported Soc's table `_ where you can find if the particular chip is under stable or development release. - Stable release link:: @@ -58,8 +63,92 @@ To start the installation process using the Boards Managaer, follow these steps: - Restart Arduino IDE. -Windows -------- +Installing using PlatformIO +--------------------------- + +.. figure:: _static/logo_pio.png + :align: center + :width: 200 + :figclass: align-center + +PlatformIO is a professional collaborative platform for embedded development. It has out-of-the-box support for ESP32 SoCs and allows working with Arduino ESP32 as well as ESP-IDF from Espressif without changing your development environment. PlatformIO includes lots of instruments for the most common development tasks such as debugging, unit testing, and static code analysis. + +A detailed overview of the PlatformIO ecosystem and its philosophy can be found in `the official documentation `_. + +PlatformIO can be used in two flavors: + +- `PlatformIO IDE `_ is a toolset for embedded C/C++ development available on Windows, macOS and Linux platforms + +- `PlatformIO Core (CLI) `_ is a command-line tool that consists of a multi-platform build system, platform and library managers and other integration components. It can be used with a variety of code development environments and allows integration with cloud platforms and web services + +To install PlatformIO, you can follow this Getting Started, provided at `docs.platformio.org`_. + +Using the stable code +********************* + +.. note:: + A detailed overview of supported development boards, examples and frameworks can be found on `the official Espressif32 dev-platform page `_ in the PlatformIO Registry. + +The most reliable and easiest way to get started is to use the latest stable version of the ESP32 development platform that passed all tests/verifications and can be used in production. + +Create a new project and select one of the available boards. You can change after by changing the `platformio.ini `_ file. + +- For ESP32 + +.. code-block:: bash + + [env:esp32dev] + platform = espressif32 + board = esp32dev + framework = arduino + +- For ESP32-S2 (ESP32-S2-Saola-1 board) + +.. code-block:: bash + + [env:esp32-s2-saola-1] + platform = espressif32 + board = esp32-s2-saola-1 + framework = arduino + +- For ESP32-C3 (ESP32-C3-DevKitM-1 board) + +.. code-block:: bash + + [env:esp32-c3-devkitm-1] + platform = espressif32 + board = esp32-c3-devkitm-1 + framework = arduino + +How to update to the latest code +******************************** + +To test the latest Arduino ESP32, you need to change your project *platformio.ini* accordingly. +The following configuration uses the upstream version of the Espressif development platform and the latest Arduino core directly from the Espressif GitHub repository: + +.. code-block:: bash + + [env:esp32-c3-devkitm-1] + platform = https://github.com/platformio/platform-espressif32.git + board = esp32-c3-devkitm-1 + framework = arduino + platform_packages = + framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32#master + + +To get more information about PlatformIO, see the following links: + +- `PlatformIO Core (CLI) `_ + +- `PlatformIO Home `_ + +- `Tutorials and Examples `_ + +- `Library Management `_ + + +Windows (manual installation) +----------------------------- .. warning:: Arduino ESP32 core v2.x.x cannot be used on Windows 8.x x86 (32 bits), Windows 7 or earlier. The Windows 32 bits OS is no longer supported by this toolchain. @@ -150,6 +239,11 @@ How to update to the latest code Linux ----- +.. figure:: _static/logo_linux.png + :align: center + :width: 200 + :figclass: align-center + Debian/Ubuntu ************* @@ -263,20 +357,5 @@ Where ``~/Documents/Arduino`` represents your sketch book location as per "Ardui - Restart Arduino IDE. -PlatformIO ----------- - -- `What is PlatformIO? `_ - -- `PlatformIO IDE `_ - -- `PlatformIO Core `_ - -- `Advanced usage `_: Custom settings, uploading to SPIFFS, Over-the-Air (OTA), staging version - -- `Integration with Cloud and Standalone IDEs `_: Cloud9, Codeanywhere, Eclipse Che (Codenvy), Atom, CLion, Eclipse, Emacs, NetBeans, Qt Creator, Sublime Text, VIM, Visual Studio, and VSCode - -- `Project Examples `_ - - .. _Arduino.cc: https://www.arduino.cc/en/Main/Software +.. _docs.platformio.org: https://docs.platformio.org/en/latest/integration/ide/pioide.html diff --git a/docs/source/lib_builder.rst b/docs/source/lib_builder.rst index e9a270362d2..5c62aafe55d 100644 --- a/docs/source/lib_builder.rst +++ b/docs/source/lib_builder.rst @@ -2,37 +2,178 @@ Library Builder ############### -How to Use Library Builder --------------------------- +About +----- -Espressif has provided a `tool `_ to simplify building your own compiled libraries for use in Arduino IDE (or your favorite IDE). -To generate custom libraries, follow these steps: +Espressif provides a `tool `_ to simplify building your own compiled libraries for use in Arduino IDE (or your favorite IDE). +This tool can be used to change the project or a specific configuration according to your needs. -- Step 1 - Clone the ESP32 Arduino lib builder:: +Installing +---------- + +To install the Library Builder into your environment, please, follow the instructions below. + +- Clone the ESP32 Arduino lib builder: + +.. code-block:: bash git clone https://github.com/espressif/esp32-arduino-lib-builder -- Step 2 - Go to the ``esp32-arduino-lib-builder`` folder:: +- Go to the ``esp32-arduino-lib-builder`` folder: + +.. code-block:: bash cd esp32-arduino-lib-builder -- Step 3 - Run the ``update-components`` script:: +- Build: + +.. code-block:: bash + + ./build.sh + +If everything works, you may see the following message: ``Successfully created esp32 image.`` + +Dependencies +************ + +To build the library you will need to install some dependencies. Maybe you already have installed it, but it is a good idea to check before building. + +- Install all dependencies (**Ubuntu**): + +.. code-block:: bash + + sudo apt-get install git wget curl libssl-dev libncurses-dev flex bison gperf cmake ninja-build ccache jq + +- Install Python and upgrade pip: + +.. code-block:: bash + + sudo apt-get install python3 + sudo pip install --upgrade pip + +- Install all required packages: + +.. code-block:: bash + + pip install --user setuptools pyserial click cryptography future pyparsing pyelftools + +Building +-------- + +If you have all the dependencies met, it is time to build the libraries. + +To build using the default configuration: + +.. code-block:: bash + + ./build.sh + +Custom Build +************ + +There are some options to help you create custom libraries. You can use the following options: + +Usage +^^^^^ + +.. code-block:: bash + + build.sh [-s] [-A arduino_branch] [-I idf_branch] [-i idf_commit] [-c path] [-t ] [-b ] [config ...] + +Skip Install/Update +^^^^^^^^^^^^^^^^^^^ + +Skip installing/updating of ESP-IDF and all components + +.. code-block:: bash + + ./build.sh -s + +This option can be used if you already have the ESP-IDF and all components already in your environment. + +Set Arduino-ESP32 Branch +^^^^^^^^^^^^^^^^^^^^^^^^ + +Set which branch of arduino-esp32 to be used for compilation + +.. code-block:: bash + + ./build.sh -A + +Set ESP-IDF Branch +^^^^^^^^^^^^^^^^^^ + +Set which branch of ESP-IDF is to be used for compilation + +.. code-block:: bash + + ./build.sh -I + +Set the ESP-IDF Commit +^^^^^^^^^^^^^^^^^^^^^^ + +Set which commit of ESP-IDF to be used for compilation + +.. code-block:: bash + + ./build.sh -i + +Deploy +^^^^^^ + +Deploy the build to github arduino-esp32 + +.. code-block:: bash + + ./build.sh -d + +Set the Arduino-ESP32 Destination Folder +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Set the arduino-esp32 folder to copy the result to. ex. '$HOME/Arduino/hardware/espressif/esp32' + +.. code-block:: bash + + ./build.sh -c + +This function is used to copy the compiled libraries to the Arduino folder. + +Set the Target +^^^^^^^^^^^^^^ + +Set the build target(chip). ex. 'esp32s3' + +.. code-block:: bash + + ./build.sh -t + +This build command will build for the ESP32-S3 target. You can specify other targets. + +* esp32 +* esp32s2 +* esp32c3 +* esp32s3 + +Set Build Type +^^^^^^^^^^^^^^ + +Set the build type. ex. 'build' to build the project and prepare for uploading to a board. + +.. note:: This command depends on the ``-t`` argument. - ./tools/update-components.sh` +.. code-block:: bash -- Step 4 - Run ``install-esp-idf`` installation script (if you already have an ``$IDF_PATH`` defined, it will use your local copy of the repository):: + ./build.sh -t esp32 -b - ./tools/install-esp-idf.sh +Additional Configuration +^^^^^^^^^^^^^^^^^^^^^^^^ -- Step 5 - Copy the configuration (recommended) or directly edit sdkconfig using ``idf.py menuconfig``:: +Specify additional configs to be applied. ex. 'qio 80m' to compile for QIO Flash@80MHz. Requires -b - cp sdkconfig.esp32s2 sdkconfig +.. note:: This command requires the ``-b`` to work properly. -- Step 6 - Build:: - idf.py build +.. code-block:: bash -The script automates the process of building `Arduino as an ESP-IDF component `_. -Once it is complete, you can cherry pick the needed libraries from ``out/tools/sdk/lib``, or run ``tools/copy-to-arduino.sh`` to copy the entire built system. -``tools/config.sh`` contains a number of variables that control the process, particularly the ``$IDF_BRANCH`` variable. You can adjust this to try building against newer versions, but there are absolutely no guarantees that any components will work or even successfully compile against a newer IDF. + ./build.sh -t esp32 -b idf_libs qio 80m diff --git a/docs/source/libraries.rst b/docs/source/libraries.rst index 12dd8cfd37f..d9febb08a1a 100644 --- a/docs/source/libraries.rst +++ b/docs/source/libraries.rst @@ -28,7 +28,7 @@ Currently, the Arduino ESP32 supports the following peripherals with Arduino API +---------------+---------------+---------------+---------------+-------------------------------+ | I2C | Yes | Yes | Yes | | +---------------+---------------+---------------+---------------+-------------------------------+ -| I2S | No | No | No | WIP | +| I2S | Yes | No | No | WIP | +---------------+---------------+---------------+---------------+-------------------------------+ | LEDC | Yes | Yes | Yes | | +---------------+---------------+---------------+---------------+-------------------------------+ @@ -64,12 +64,7 @@ Notes .. note:: Some peripherals are not available for all ESP32 families. To see more details about it, see the corresponding SoC at `Product Selector `_ page. -Datasheet -^^^^^^^^^ - -* `ESP32 `_ -* `ESP32-S2 `_ -* `ESP32-C3 `_ +.. include:: common/datasheet.inc APIs ---- @@ -78,13 +73,6 @@ The Arduino ESP32 offers some unique APIs, described in this section: .. toctree:: :maxdepth: 1 - - Bluetooth - Deep Sleep - ESPNOW - GPIO - I2C - RainMaker - Reset Reason - USB - Wi-Fi + :glob: + + api/* diff --git a/docs/source/tutorials/io_mux.rst b/docs/source/tutorials/io_mux.rst index 547be0e184b..8bdbb0799c3 100644 --- a/docs/source/tutorials/io_mux.rst +++ b/docs/source/tutorials/io_mux.rst @@ -62,7 +62,7 @@ JTAG Dedicated GPIOs SD/SDIO/MMC HostController Dedicated GPIOs Motor PWM Any GPIO SDIO/SPI SlaveController Dedicated GPIOs -UART Any GPIO +UART Any GPIO[1] I2C Any GPIO I2S Any GPIO LED PWM Any GPIO @@ -72,8 +72,11 @@ Parallel QSPI Dedicated GPIOs EMAC Dedicated GPIOs Pulse Counter Any GPIO TWAI Any GPIO +USB Dedicated GPIOs ============================== =================================== +[1] except for the download/programming mode decided by the bootloader. + This table is present on each datasheet provided by Espressif. Usage Examples @@ -106,16 +109,11 @@ To change the pins, we must call the ``Wire.setPins(int sda, int scl);`` functio A similar approach also applies for the other peripherals. +.. include:: ../common/datasheet.inc + Resources --------- -* `ESP32`_ (Datasheet) -* `ESP32-S2`_ (Datasheet) -* `ESP32-C3`_ (Datasheet) - .. _Espressif Systems: https://www.espressif.com .. _Espressif Product Selector: https://products.espressif.com/ -.. _ESP32: https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf -.. _ESP32-S2: https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf -.. _ESP32-C3: https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf .. _IO MUX GPIO: https://www.espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf#iomuxgpio diff --git a/docs/source/tutorials/preferences.rst b/docs/source/tutorials/preferences.rst new file mode 100644 index 00000000000..eb0397af543 --- /dev/null +++ b/docs/source/tutorials/preferences.rst @@ -0,0 +1,697 @@ +########### +Preferences +########### + + +Introduction +------------ + +The Preferences library is unique to arduino-esp32. It should be considered as the replacement for the Arduino EEPROM library. + +It uses a portion of the on-board non-volatile memory (NVS) of the ESP32 to store data. This data is retained across restarts and loss of power events to the system. + +Preferences works best for storing many small values, rather than a few large values. If you need to store large amounts of data, consider using a file system library such as LitteFS. + +The Preferences library is usable by all ESP32 variants. + + +Preferences Attributes +---------------------- + +Preferences data is stored in NVS in sections called a "``namespace``". Within each namespace are a set of ``key-value`` pairs. The "``key``" is the name of the data item and the "``value``" is, well, the value of that piece of data. Kind of like variables. The key is the name of the variable and the value is its value. Like variables, a ``key-value`` pair has a data type. + +Multiple namespaces are permitted within NVS. The name of each namespace must be unique. The keys within that namespace are unique to that namespace. Meaning the same key name can be used in multiple namespaces without conflict. + +Namespace and key names are case sensitive. + +Each key name must be unique within a namespace. + +Namespace and key names are character strings and are limited to a maximum of 15 characters. + +Only one namespace can be open (in use) at a time. + + +Library Overview +---------------- + +Library methods are provided to: + - create a namespace; + - open and close a namespace; + - store and retrieve data within a namespace for supported data types; + - determine if a key value has been initialized; + - delete a ``key-value`` pair; + - delete all ``key-value`` pairs in a namespace; + - determine data types stored against a key; + - determine the number of key entries available in the namespace. + +Preferences directly suports the following data types: + +.. table:: **Table 1 — Preferences Types** + :align: center + + +-------------------+-------------------+---------------+ + | Preferences Type | Data Type | Size (bytes) | + +===================+===================+===============+ + | Bool | bool | 1 | + +-------------------+-------------------+---------------+ + | Char | int8_t | 1 | + +-------------------+-------------------+---------------+ + | UChar | uint8_t | 1 | + +-------------------+-------------------+---------------+ + | Short | int16_t | 2 | + +-------------------+-------------------+---------------+ + | UShort | uint16_t | 2 | + +-------------------+-------------------+---------------+ + | Int | int32_t | 4 | + +-------------------+-------------------+---------------+ + | UInt | uint32_t | 4 | + +-------------------+-------------------+---------------+ + | Long | int32_t | 4 | + +-------------------+-------------------+---------------+ + | ULong | uint32_t | 4 | + +-------------------+-------------------+---------------+ + | Long64 | int64_t | 8 | + +-------------------+-------------------+---------------+ + | ULong64 | uint64_t | 8 | + +-------------------+-------------------+---------------+ + | Float | float_t | 8 | + +-------------------+-------------------+---------------+ + | Double | double_t | 8 | + +-------------------+-------------------+---------------+ + | | const char* | | + | String +-------------------+ variable | + | | String | | + +-------------------+-------------------+---------------+ + | Bytes | uint8_t | variable | + +-------------------+-------------------+---------------+ + +String values can be stored and retrieved either as an Arduino String or as a null terminated ``char`` array (C-string). + +Bytes type is used for storing and retrieving an arbitrary number of bytes in a namespace. + + +Workflow +-------- + +Preferences workflow, once everything is initialized, is pretty simple. + +To store a value: + - Open the namespace in read-write mode. + - Put the value into the key. + - Close the namespace. + +To retrieve a value: + - Open the namespace in read-only mode. + - Use the key to get the value. + - Close the namespace. + +*(Technically, you can retrieve a value if the namespace is open in either read-only or read-write mode but it's good practice to open the namespace in read-only mode if you are only retrieving values.)* + +When storing information, a "``put[PreferencesType]``" method referenced to its key is used. + +When retrieving information a "``get[PreferencesType]``" method referenced to its key is used. + +Ensuring that the data types of your “``get``'s” and “``put``'s” all match, you’re good to go. + +The nuance is in initializing everything at the start. + +Before you can store or retrieve anything using Preferences, both the namespace and the key within that namespace need to exist. So the workflow is: + +#. Create or open the namespace. +#. Test for the existence of a key that should exist if the namespace has been initialized. +#. If that key does not exist, create the key(s). +#. Carry on with the rest of your sketch where data can now be stored and retrieved from the namespace. + +Each step is discussed below. + +.. note:: + + From here on when referring in general to a method used to store or retrieve data we'll use the shorthand "``putX``" and "``getX``" where the "``X``" is understood to be a Preferences Type; Bool, UInt, Char, and so on from the Preferences Types table above. + +.. + + +Create or Open the Namespace +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +In your sketch, first insert a declaration of a ``Preferences`` object by including a line like; + +.. code-block:: arduino + + Preferences mySketchPrefs; // "mySketchPrefs" is the name of the Preferences object. + // Can be whatever you want. + +This object is used with the Preferences methods to access the namespace and the key-value pairs it contains. + +A namespace is made available for use with the ``.begin`` method: + +.. code-block:: arduino + + mySketchPrefs.begin("myPrefs", false) + +If the namespace does not yet exist, this will create and then open the namespace ``myPrefs``. + +If the namespace already exists, this will open the namespace ``myPrefs``. + +If the second argument is ``false`` the namespace is opened in read-write (RW) mode — values can be stored in to and retrieved from the namespace. If it is ``true`` the namespace is opened in read-only (RO) mode — values can be retrieved from the namespace but nothing can be stored. + + +Test for Initial Existence of Your Key(s) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +When the ESP32 boots, there is no inherent way to know if this is the very first time it has ever powered on or if it is a subsequent launch and it has run its sketch before. We can use Preferences to store information that is retained across reboots that we can read, and based on that, decide if this is a first-time run and take the required actions if so. + +We do this by testing for the existence of a certain key within a namespace. If that key exists, it is safe to assume the key was created during the first-time run of the sketch and so the namespace has already been initialized. + +To determine if a key exists, use: + +.. code-block:: arduino + + isKey("myTestKey") + +This returns ``true`` if ``"myTestKey"`` exists in the namespace, and ``false`` if it does not. + +By example, consider this code segment: + +.. code-block:: arduino + + Preferences mySketchPrefs; + String doesExist; + + mySketchPrefs.begin("myPrefs", false); // open (or create and then open if it does not + // yet exist) the namespace "myPrefs" in RW mode. + + bool doesExist = mySketchPrefs.isKey("myTestKey"); + + if (doesExist == false) { + /* + If doesExist is false, we will need to create our + namespace key(s) and store a value into them. + */ + + // Insert your "first time run" code to create your keys & assign their values below here. + } + else { + /* + If doesExist is true, the key(s) we need have been created before + and so we can access their values as needed during startup. + */ + + // Insert your "we've been here before" startup code below here. + } + + + +Creating Namespace Keys and Storing Values +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +To create a key, we use one of the ``.putX`` methods, matching ``"X"`` to the Preferences Type of the data we wish to store: + +.. code-block:: arduino + + myPreferences.putX("myKeyName", value) + +If ``"myKeyName"`` does not exist in the namespace, it is first created and then ``value`` is stored against that keyname. The namespace must be open in RW mode to do this. Note that ``value`` is not optional and must be provided with every "``.putX``" statement. Thus every key within a namespace will always hold a valid value. + +An example is: + +.. code-block:: arduino + + myPreferences.putFloat("pi", 3.14159265359); // stores an float_t data type + // against the key "pi". + +Reading Values From a Namespace +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Once a key exists in a namespace and the namespace is open, its value is retrieved using one of the ``getX`` methods, matching ``"X"`` to the type of data stored against that key. + +.. code-block:: arduino + + myPreferences.getX("myKeyName") + +Like so: + +.. code-block:: arduino + + String myString = myPreferences.getString("myStringKey"); + +This will retrieve the String value from the namespace key ``"myStringKey"`` and assign it to the String type variable ``myString``. + + +Summary +~~~~~~~ + +So the basics of using Preferences are: + + #. You cannot store into or retrieve from a ``key-value`` pair until a namespace is created and opened and the key exists in that namespace. + + #. If the key already exists, it was created the first time the sketch was run. + + #. A key value can be retrieved regardless of the mode in which the namespace was opened, but a value can only be stored if the namespace is open in read-write mode. + + #. Data types of the “``get``'s” and “``put``'s” must match. + + #. Remember the 15 character limit for namespace and key names. + + +Real World Example +------------------ + +Here is part of a ``setup()`` function that uses Preferences. + +Its purpose is to set either a factory default configuration if the system has never run before, or use the last configuration if it has. + +When started, the system has no way of knowing which of the above conditions is true. So the first thing it does after opening the namespace is check for the existence of a key that we have predetermined can only exist if we have previously run the sketch. Based on its existence we decide if a factory default set of operating parameters should be used (and in so doing create the namespace keys and populate the values with defaults) or if we should use operating parameters from the last time the system was running. + +.. code-block:: arduino + + #include + + #define RW_MODE false + #define RO_MODE true + + Preferences stcPrefs; + + void setup() { + + // not the complete setup(), but in setup(), include this... + + stcPrefs.begin("STCPrefs", RO_MODE); // Open our namespace (or create it + // if it doesn't exist) in in RO mode. + + bool tpInit = stcPrefs.isKey("nvsInit"); // Test for the existence of the "already initialized" key. + + if (tpInit == false) { + // If tpInit is 'false', the key "nvsInit" does not yet exist therefore this + // must be our first-time run. We need to set up our Preferences namespace keys. So... + stcPrefs.end(); // close the namespace in RO mode and... + stcPrefs.begin("STCPrefs", RW_MODE); // reopen it in RW mode. + + + // The .begin() method created the "STCPrefs" namespace and since this is our + // first-time run we will create our keys and store the initial "factory default" values. + stcPrefs.putUChar("curBright", 10); + stcPrefs.putString("talChan", "one"); + stcPrefs.putLong("talMax", -220226); + stcPrefs.putBool("ctMde", true); + + stcPrefs.putBool("nvsInit", true); // Create the "already initialized" key and store a value. + + // The "factory defaults" are created and stored so... + stcPrefs.end(); // Close the namespace in RW mode and... + stcPrefs.begin("STCPrefs", RO_MODE); // reopen it in RO mode so the setup code + // outside this first-time run 'if' block + // can retrieve the run-time values + // from the "STCPrefs" namespace. + } + + // Retrieve the operational parameters from the namespace + // and save them into their run-time variables. + currentBrightness = stcPrefs.getUChar("curBright"); // + tChannel = stcPrefs.getString("talChan"); // The LHS variables were defined + tChanMax = stcPrefs.getLong("talMax"); // earlier in the sketch. + ctMode = stcPrefs.getBool("ctMde"); // + + // All done. Last run state (or the factory default) is now restored. + stcPrefs.end(); // Close our preferences namespace. + + // Carry on with the rest of your setup code... + + // When the sketch is running, it updates any changes to an operational parameter + // to the appropriate key-value pair in the namespace. + + } + + +Utility Functions +----------------- + +There are a few other functions useful when working with namespaces. + +Deleting key-value Pairs +~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: arduino + + preferences.clear(); + +.. + + - Deletes *all* the key-value pairs in the currently opened namespace. + + - The namespace still exists. + + - The namespace must be open in read-write mode for this to work. + +.. code-block:: arduino + + preferences.remove("keyname"); + +.. + + - Deletes the "keyname" and value associated with it from the currently opened namespace. + + - The namespace must be open in read-write mode for this to work. + - Tip: use this to remove the "test key" to force a "factory reset" during the next reboot (see the *Real World Example* above). + +If either of the above are used, the ``key-value`` pair will need to be recreated before using it again. + + +Determining the Number of Available Keys +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +For each namespace, Preferences keeps track of the keys in a key table. There must be an open entry in the table before a key can be created. This method will return the number of entires available in the table. + +.. code-block:: arduino + + freeEntries() + +.. + +To send to the serial monitor the number of available entries the following could be used. + +.. code-block:: arduino + + Preferences mySketchPrefs; + + mySketchPrefs.begin("myPrefs", true); + size_t whatsLeft = freeEntries(); // this method works regardless of the mode in which the namespace is opened. + Serial.printf("There are: %u entries available in the namespace table.\n, whatsLeft); + mySketchPrefs.end(); + +.. + +The number of available entries in the key table changes depending on the number of keys in the namespace and also the dynamic size of certain types of data stored in the namespace. Details are in the `Preferences API Reference`_. + +Do note that the number of entries in the key table does not guarantee that there is room in the opened NVS namespace for all the data to be stored in that namespace. Refer to the espressif `Non-volatile storage library`_ documentation for full details. + + +Determining the Type of a key-value Pair +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Keeping track of the data types stored against a key-value pair is one of the bookkeeping tasks left to you. Should you want to discover the Preferences data type stored against a given key, use this method: + +.. code-block:: arduino + + getType("myKey") + +.. + +As in: + +.. code-block:: arduino + + PreferenceType whatType = getType("myKey"); + +.. + +The value returned is a ``PreferenceType`` value that maps to a Preferences Type. Refer to the description in the `Preferences API Reference`_ for details. + + + +Working with Large Data +----------------------- + +Recall that the Preferences library works best for storing many small values, rather than a few large values. Regardless, it may be desirable to store larger amounts of arbitrary data than what is provided by the basic types in the Preferences Types table above. + +The library provides the following methods to facilitate this. + +.. code-block:: arduino + + putBytes("myBytesKey", value, valueLen) + getBytes("myBytesKey", buffer, valueLen) + getBytesLength("myBytesKey") + +.. + +The ``put`` and ``get`` ``Bytes`` methods store and retrieve the data. The ``getBytesLength`` method is used to find the size of the data stored against the key (which is needed to retrieve ``Bytes`` data). + +As the names of the methods imply, they operate on variable length bytes of data (often referred to as a "blob") and not on individual elements of a certain data type. + +Meaning if you store for example an array of type ``int16_t`` against a ``Bytes`` type key, the value of that key becomes a series of bytes with no associated data type. Or if you like, all data stored as a blob gets converted to a series of ``uint8_t`` type bytes. + +As a result, when using the ``getBytes`` method to retrieve the value of the key, what is returned to the buffer is a series of ``uint8_t`` bytes. It is up to you to manage the data types and size of the arrays and buffers when retrieving ``Bytes`` data. + +Fortunately this is not as difficult as it may sound as the ``getBytesLength`` method and the ``sizeof`` operator help with keeping track of it all. + +This is best explained with an example. Here the ``Bytes`` methods are used to store and retrieve an array, while ensuring the data type is preserved. + +.. code-block:: arduino + + /* + * An example sketch using the Preferences "Bytes" methods + * to store and retrieve an arbitrary number of bytes in + * a namespace. + */ + + #include + + #define RO_MODE true + #define RW_MODE false + + void setup() { + + Preferences mySketchPrefs; + + Serial.begin(115200); + delay(250); + + mySketchPrefs.begin("myPrefs", RW_MODE); // open (or create) the namespace "myPrefs" in RW mode + mySketchPrefs.clear(); // delete any previous keys in this namespace + + // Create an array of test values. We're using hex numbers throughout to better show how the bytes move around. + int16_t myArray[] = { 0x1112, 0x2122, 0x3132, 0x4142, 0x5152, 0x6162, 0x7172 }; + + Serial.println("Printing myArray..."); + for (int i = 0; i < sizeof(myArray) / sizeof(int16_t); i++) { + Serial.print(myArray[i], HEX); Serial.print(", "); + } + Serial.println("\r\n"); + + // In the next statement, the second sizeof() needs to match the data type of the elements of myArray + Serial.print("The number of elements in myArray is: "); Serial.println( sizeof(myArray) / sizeof(int16_t) ); + Serial.print("But the size of myArray in bytes is: "); Serial.println( sizeof(myArray) ); + Serial.println(""); + + Serial.println("Storing myArray into the Preferences namespace \"myPrefs\" against the key \"myPrefsBytes\"."); + // Note: in the next statement, to store the entire array, we must use the + // size of the arrray in bytes, not the number of elements in the array. + mySketchPrefs.putBytes( "myPrefsBytes", myArray, sizeof(myArray) ); + Serial.print("The size of \"myPrefsBytes\" is (in bytes): "); Serial.println( mySketchPrefs.getBytesLength("myPrefsBytes") ); + Serial.println(""); + + int16_t myIntBuffer[20] = {}; // No magic about 20. Just making a buffer (array) big enough. + Serial.println("Retrieving the value of myPrefsBytes into myIntBuffer."); + Serial.println(" - Note the data type of myIntBuffer matches that of myArray"); + mySketchPrefs.getBytes( "myPrefsBytes", myIntBuffer, mySketchPrefs.getBytesLength("myPrefsBytes") ); + + Serial.println("Printing myIntBuffer..."); + // In the next statement, sizeof() needs to match the data type of the elements of myArray + for (int i = 0; i < mySketchPrefs.getBytesLength("myPrefsBytes") / sizeof(int16_t); i++) { + Serial.print(myIntBuffer[i], HEX); Serial.print(", "); + } + Serial.println("\r\n"); + + Serial.println("We can see how the data from myArray is actually stored in the namespace as follows."); + uint8_t myByteBuffer[40] = {}; // No magic about 40. Just making a buffer (array) big enough. + mySketchPrefs.getBytes( "myPrefsBytes", myByteBuffer, mySketchPrefs.getBytesLength("myPrefsBytes") ); + + Serial.println("Printing myByteBuffer..."); + for (int i = 0; i < mySketchPrefs.getBytesLength("myPrefsBytes"); i++) { + Serial.print(myByteBuffer[i], HEX); Serial.print(", "); + } + Serial.println(""); + + } + + void loop() { + ; + } + +.. + +The resulting output is: +:: + + Printing myArray... + 1112, 2122, 3132, 4142, 5152, 6162, 7172, + + The number of elements in myArray is: 7 + But the size of myArray in bytes is: 14 + + Storing myArray into the Preferences namespace "myPrefs" against the key "myPrefsBytes". + The size of "myPrefsBytes" is (in bytes): 14 + + Retrieving the value of myPrefsBytes into myIntBuffer. + - Note the data type of myIntBuffer matches that of myArray + Printing myIntBuffer... + 1112, 2122, 3132, 4142, 5152, 6162, 7172, + + We can see how the data from myArray is actually stored in the namespace as follows. + Printing myByteBuffer... + 12, 11, 22, 21, 32, 31, 42, 41, 52, 51, 62, 61, 72, 71, + +You can copy the sketch and change the data type and values in ``myArray`` and follow along with the code and output to see how the ``Bytes`` methods work. The data type of ``myIntBuffer`` should be changed to match that of ``myArray`` (and check the "``sizeof()``'s" where indicated in the comments). + +The main takeaway is to remember you're working with bytes and so attention needs to be paid to store all the data based on the size of its type and to manage the buffer size and data type for the value retrieved. + + +Multiple Namespaces +------------------- + +As stated earlier, multiple namespaces can exist in the Preferences NVS partition. However, only one namespace at a time can be open (in use). + +If you need to access a different namespace, close the one before opening the other. For example: + +.. code-block:: arduino + + Preferences currentNamespace; + + currentNamespace.begin("myNamespace", false); + // do stuff... + + currentNamespace.end(); // closes 'myNamespace' + + currentNamespace.begin("myOtherNamespace", false); // opens a different Preferences namesspace. + // do other stuff... + + currentNamespace.end(); // closes 'myOtherNamespace' + +Here the "``currentNamespace``" object is reused, but different Preferences objects can be declared and used. Just remember to keep it all straight as all "``putX``'s" and "``getX``'s", etc. will only operate on the single currently opened namespace. + + +A Closer Look at ``getX`` +-------------------------- + +Methods in the Preferences library return a status code that can be used to determine if the method completed successfully. This is described in the `Preferences API Reference`_. + +Assume we have a key named "``favourites``" that contains a value of a ``String`` data type. + +After executing the statement: + +.. code-block:: arduino + + dessert = mySketchPrefs.getString("favourites"); + +.. + +the variable ``dessert`` will contain the value of the string stored against the key ``"favourites"``. + +But what if something went wrong and the ``getString`` call failed to retrieve the key value? How would we be able to detect the error? + +With Preferences, the ``getX`` methods listed in Table 2 below will return a default value if an error is encountered. + +.. table:: **Table 2 — getX Methods Defaults** + :align: center + + +------------------+-----------------+ + | Preferences | Default Return | + | Type | Value | + +==================+=================+ + | Char, UChar, | 0 | + | | | + | Short, UShort, | | + | | | + | Int, UInt, | | + | | | + | Long, ULong, | | + | | | + | Long64, ULong64 | | + +------------------+-----------------+ + | Bool | false | + +------------------+-----------------+ + | Float | NAN | + | | | + | Double | | + +------------------+-----------------+ + | String (String) | "" | + +------------------+-----------------+ + | String (* buf) | \\0 | + +------------------+-----------------+ + +Thus to detect an error we could compare the value returned against its default return value and if they are equal assume an error occurred and take the appropriate action. + +But what if a method default return value is also a potential legitimate value? How can we then know if an error occurred? + +As it turns out, the complete form of the ``getX`` methods for each of the Preferences Types in Table 2 is: + +.. code-block:: arduino + + preferences.getX("myKey", myDefault) + +.. + +In this form the method will return either the value associated with "``myKey``" or, if an error occurred, return the value ``myDefault``, where ``myDefault`` must be the same data type as the ``getX``. + +Returning to the example above: + +.. code-block:: arduino + + dessert = mySketchPrefs.getString("favourites", "gravel"); + +.. + +will assign to the variable ``dessert`` the String ``gravel`` if an error occurred, or the value stored against the key ``favourites`` if not. + +If we predetermine a default value that is outside all legitimate values, we now have a way to test if an error actually occurred. + +In summary, if you need to confirm that a value was retrieved without error from a namespace, use the complete form of the ``getX`` method with a predetermined default "this can only happen if an error" value and compare that against the value returned by the call. Otherwise, you can omit the default value as the call will return the default for that particular ``getX`` method. + +Additional detail is given in the `Preferences API Reference`_. + + +Advanced Item +------------- + +In the arduino-esp32 implementation of Preferences there is no method to completely remove a namespace. As a result, over the course of a number of projects, it is possible that the ESP32 NVS Preferences partition becomes cluttered or full. + +To completely erase and reformat the NVS memory used by Preferences, create and run a sketch that contains: + +.. code-block:: arduino + + #include + + void setup() { + + nvs_flash_erase(); // erase the NVS partition and... + nvs_flash_init(); // initialize the NVS partition. + while (true); + + } + + void loop() { + ; + } + +.. + +.. warning:: + **You should download a new sketch to your board immediately after running the above or else it will reformat the NVS partition every time it is powered up or restarted!** + + +Resources +--------- + +* `Preferences API Reference <../api/preferences.html>`_ +* `Non-volatile storage library`_ (espressif-IDF API Reference) +* `Official ESP-IDF documentation`_ (espressif-IDF Reference) + + +.. _Non-volatile storage library: https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/storage/nvs_flash.html +.. _Official ESP-IDF documentation: https://docs.espressif.com/projects/esp-idf/en/stable + + +Contribute +---------- + +.. ==*Do not change! Keep as is.*== + +To contribute to this project, see `How to contribute`_. + +If you have any **feedback** or **issue** to report on this tutorial, please open an issue or fix it by creating a new PR. Contributions are more than welcome! + +Before creating a new issue, be sure to try the Troubleshooting and to check if the same issue was already created by someone else. + +.. _How to Contribute: https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst + +.. ---- EOF ---- diff --git a/docs/source/tutorials/tutorials.rst b/docs/source/tutorials/tutorials.rst index 57eead06f31..9fca4ac3ce5 100644 --- a/docs/source/tutorials/tutorials.rst +++ b/docs/source/tutorials/tutorials.rst @@ -3,10 +3,8 @@ Tutorials ######### .. toctree:: - :maxdepth: 2 :caption: Tutorials: + :maxdepth: 1 + :glob: - Blink - Basic - DFU - GPIO Matrix and Pin Mux + * diff --git a/idf_component.yml b/idf_component.yml new file mode 100644 index 00000000000..9894a2ce923 --- /dev/null +++ b/idf_component.yml @@ -0,0 +1,21 @@ +description: "Arduino core for ESP32, ESP32-S and ESP32-C series of SoCs" +url: "https://github.com/espressif/arduino-esp32" +targets: + - esp32 + - esp32s2 + - esp32s3 + - esp32c3 +tags: + - arduino +files: + include: + - "cores/**/*" + - "variants/esp32/**/*" + - "variants/esp32s2/**/*" + - "variants/esp32s3/**/*" + - "variants/esp32c3/**/*" + - "libraries/**/*" + - "CMakeLists.txt" + - "Kconfig.projbuild" + exclude: + - "**/*" diff --git a/libraries/AsyncUDP/src/AsyncUDP.h b/libraries/AsyncUDP/src/AsyncUDP.h index 3f3724a8af8..be04c01ffaa 100644 --- a/libraries/AsyncUDP/src/AsyncUDP.h +++ b/libraries/AsyncUDP/src/AsyncUDP.h @@ -4,9 +4,9 @@ #include "IPAddress.h" #include "IPv6Address.h" #include "Print.h" +#include "Stream.h" #include extern "C" { -#include "lwip/ip_addr.h" #include "esp_netif.h" #include "freertos/queue.h" #include "freertos/semphr.h" diff --git a/libraries/BLE/src/BLEAddress.cpp b/libraries/BLE/src/BLEAddress.cpp index 7ba677f0642..f9abae1803b 100644 --- a/libraries/BLE/src/BLEAddress.cpp +++ b/libraries/BLE/src/BLEAddress.cpp @@ -71,7 +71,7 @@ bool BLEAddress::operator!=(const BLEAddress& otherAddress) const { } bool BLEAddress::operator<(const BLEAddress& otherAddress) const { - return memcmp(otherAddress.m_address, m_address, ESP_BD_ADDR_LEN) < 0; + return memcmp(m_address, otherAddress.m_address, ESP_BD_ADDR_LEN) < 0; } bool BLEAddress::operator<=(const BLEAddress& otherAddress) const { @@ -83,7 +83,7 @@ bool BLEAddress::operator>=(const BLEAddress& otherAddress) const { } bool BLEAddress::operator>(const BLEAddress& otherAddress) const { - return memcmp(otherAddress.m_address, m_address, ESP_BD_ADDR_LEN) > 0; + return memcmp(m_address, otherAddress.m_address, ESP_BD_ADDR_LEN) > 0; } /** diff --git a/libraries/BLE/examples/BLE_Beacon_Scanner/.skip.esp32c3 b/libraries/BluetoothSerial/examples/DiscoverConnect/.skip.esp32c3 similarity index 100% rename from libraries/BLE/examples/BLE_Beacon_Scanner/.skip.esp32c3 rename to libraries/BluetoothSerial/examples/DiscoverConnect/.skip.esp32c3 diff --git a/libraries/RainMaker/examples/RMakerCustom/.skip.esp32s2 b/libraries/BluetoothSerial/examples/DiscoverConnect/.skip.esp32s2 similarity index 100% rename from libraries/RainMaker/examples/RMakerCustom/.skip.esp32s2 rename to libraries/BluetoothSerial/examples/DiscoverConnect/.skip.esp32s2 diff --git a/libraries/BLE/examples/BLE_EddystoneTLM_Beacon/.skip.esp32c3 b/libraries/BluetoothSerial/examples/DiscoverConnect/.skip.esp32s3 similarity index 100% rename from libraries/BLE/examples/BLE_EddystoneTLM_Beacon/.skip.esp32c3 rename to libraries/BluetoothSerial/examples/DiscoverConnect/.skip.esp32s3 diff --git a/libraries/BluetoothSerial/examples/DiscoverConnect/DiscoverConnect.ino b/libraries/BluetoothSerial/examples/DiscoverConnect/DiscoverConnect.ino new file mode 100644 index 00000000000..168ea9d19c4 --- /dev/null +++ b/libraries/BluetoothSerial/examples/DiscoverConnect/DiscoverConnect.ino @@ -0,0 +1,114 @@ +/** + * Bluetooth Classic Example + * Scan for devices - asyncronously, print device as soon as found + * query devices for SPP - SDP profile + * connect to first device offering a SPP connection + * + * Example python server: + * source: https://gist.github.com/ukBaz/217875c83c2535d22a16ba38fc8f2a91 + * + * Tested with Raspberry Pi onboard Wifi/BT, USB BT 4.0 dongles, USB BT 1.1 dongles, + * 202202: does NOT work with USB BT 2.0 dongles when esp32 aduino lib is compiled with SSP support! + * see https://github.com/espressif/esp-idf/issues/8394 + * + * use ESP_SPP_SEC_ENCRYPT|ESP_SPP_SEC_AUTHENTICATE in connect() if remote side requests 'RequireAuthentication': dbus.Boolean(True), + * use ESP_SPP_SEC_NONE or ESP_SPP_SEC_ENCRYPT|ESP_SPP_SEC_AUTHENTICATE in connect() if remote side has Authentication: False + */ + +#include +#include + +#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED) +#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it +#endif + +#if !defined(CONFIG_BT_SPP_ENABLED) +#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip. +#endif + +BluetoothSerial SerialBT; + + +#define BT_DISCOVER_TIME 10000 +esp_spp_sec_t sec_mask=ESP_SPP_SEC_NONE; // or ESP_SPP_SEC_ENCRYPT|ESP_SPP_SEC_AUTHENTICATE to request pincode confirmation +esp_spp_role_t role=ESP_SPP_ROLE_SLAVE; // or ESP_SPP_ROLE_MASTER + +// std::map btDeviceList; + +void setup() { + Serial.begin(115200); + if(! SerialBT.begin("ESP32test", true) ) { + Serial.println("========== serialBT failed!"); + abort(); + } + // SerialBT.setPin("1234"); // doesn't seem to change anything + // SerialBT.enableSSP(); // doesn't seem to change anything + + + Serial.println("Starting discoverAsync..."); + BTScanResults* btDeviceList = SerialBT.getScanResults(); // maybe accessing from different threads! + if (SerialBT.discoverAsync([](BTAdvertisedDevice* pDevice) { + // BTAdvertisedDeviceSet*set = reinterpret_cast(pDevice); + // btDeviceList[pDevice->getAddress()] = * set; + Serial.printf(">>>>>>>>>>>Found a new device asynchronously: %s\n", pDevice->toString().c_str()); + } ) + ) { + delay(BT_DISCOVER_TIME); + Serial.print("Stopping discoverAsync... "); + SerialBT.discoverAsyncStop(); + Serial.println("discoverAsync stopped"); + delay(5000); + if(btDeviceList->getCount() > 0) { + BTAddress addr; + int channel=0; + Serial.println("Found devices:"); + for (int i=0; i < btDeviceList->getCount(); i++) { + BTAdvertisedDevice *device=btDeviceList->getDevice(i); + Serial.printf(" ----- %s %s %d\n", device->getAddress().toString().c_str(), device->getName().c_str(), device->getRSSI()); + std::map channels=SerialBT.getChannels(device->getAddress()); + Serial.printf("scanned for services, found %d\n", channels.size()); + for(auto const &entry : channels) { + Serial.printf(" channel %d (%s)\n", entry.first, entry.second.c_str()); + } + if(channels.size() > 0) { + addr = device->getAddress(); + channel=channels.begin()->first; + } + } + if(addr) { + Serial.printf("connecting to %s - %d\n", addr.toString().c_str(), channel); + SerialBT.connect(addr, channel, sec_mask, role); + } + } else { + Serial.println("Didn't find any devices"); + } + } else { + Serial.println("Error on discoverAsync f.e. not workin after a \"connect\""); + } +} + + +String sendData="Hi from esp32!\n"; + +void loop() { + if(! SerialBT.isClosed() && SerialBT.connected()) { + if( SerialBT.write((const uint8_t*) sendData.c_str(),sendData.length()) != sendData.length()) { + Serial.println("tx: error"); + } else { + Serial.printf("tx: %s",sendData.c_str()); + } + if(SerialBT.available()) { + Serial.print("rx: "); + while(SerialBT.available()) { + int c=SerialBT.read(); + if(c >= 0) { + Serial.print((char) c); + } + } + Serial.println(); + } + } else { + Serial.println("not connected"); + } + delay(1000); +} diff --git a/libraries/BLE/examples/BLE_EddystoneURL_Beacon/.skip.esp32c3 b/libraries/BluetoothSerial/examples/SerialToSerialBT/.skip.esp32s3 similarity index 100% rename from libraries/BLE/examples/BLE_EddystoneURL_Beacon/.skip.esp32c3 rename to libraries/BluetoothSerial/examples/SerialToSerialBT/.skip.esp32s3 diff --git a/libraries/BluetoothSerial/examples/SerialToSerialBT/SerialToSerialBT.ino b/libraries/BluetoothSerial/examples/SerialToSerialBT/SerialToSerialBT.ino index d779c6d349e..86cbe168a14 100644 --- a/libraries/BluetoothSerial/examples/SerialToSerialBT/SerialToSerialBT.ino +++ b/libraries/BluetoothSerial/examples/SerialToSerialBT/SerialToSerialBT.ino @@ -10,6 +10,10 @@ #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it #endif +#if !defined(CONFIG_BT_SPP_ENABLED) +#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip. +#endif + BluetoothSerial SerialBT; void setup() { diff --git a/libraries/BLE/examples/BLE_client/.skip.esp32c3 b/libraries/BluetoothSerial/examples/SerialToSerialBTM/.skip.esp32s3 similarity index 100% rename from libraries/BLE/examples/BLE_client/.skip.esp32c3 rename to libraries/BluetoothSerial/examples/SerialToSerialBTM/.skip.esp32s3 diff --git a/libraries/BluetoothSerial/examples/SerialToSerialBTM/SerialToSerialBTM.ino b/libraries/BluetoothSerial/examples/SerialToSerialBTM/SerialToSerialBTM.ino index 3d17fb9005a..fc650059fb7 100644 --- a/libraries/BluetoothSerial/examples/SerialToSerialBTM/SerialToSerialBTM.ino +++ b/libraries/BluetoothSerial/examples/SerialToSerialBTM/SerialToSerialBTM.ino @@ -8,6 +8,10 @@ #include "BluetoothSerial.h" +#if !defined(CONFIG_BT_SPP_ENABLED) +#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip. +#endif + BluetoothSerial SerialBT; String MACadd = "AA:BB:CC:11:22:33"; diff --git a/libraries/BLE/examples/BLE_iBeacon/.skip.esp32c3 b/libraries/BluetoothSerial/examples/SerialToSerialBT_SSP_pairing/.skip.esp32s3 similarity index 100% rename from libraries/BLE/examples/BLE_iBeacon/.skip.esp32c3 rename to libraries/BluetoothSerial/examples/SerialToSerialBT_SSP_pairing/.skip.esp32s3 diff --git a/libraries/BluetoothSerial/examples/SerialToSerialBT_SSP_pairing/SerialToSerialBT_SSP_pairing.ino b/libraries/BluetoothSerial/examples/SerialToSerialBT_SSP_pairing/SerialToSerialBT_SSP_pairing.ino index 8791b6c7a02..c440545fcf3 100644 --- a/libraries/BluetoothSerial/examples/SerialToSerialBT_SSP_pairing/SerialToSerialBT_SSP_pairing.ino +++ b/libraries/BluetoothSerial/examples/SerialToSerialBT_SSP_pairing/SerialToSerialBT_SSP_pairing.ino @@ -10,6 +10,10 @@ #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it #endif +#if !defined(CONFIG_BT_SPP_ENABLED) +#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip. +#endif + BluetoothSerial SerialBT; boolean confirmRequestPending = true; diff --git a/libraries/BLE/examples/BLE_notify/.skip.esp32c3 b/libraries/BluetoothSerial/examples/bt_classic_device_discovery/.skip.esp32s3 similarity index 100% rename from libraries/BLE/examples/BLE_notify/.skip.esp32c3 rename to libraries/BluetoothSerial/examples/bt_classic_device_discovery/.skip.esp32s3 diff --git a/libraries/BluetoothSerial/examples/bt_classic_device_discovery/bt_classic_device_discovery.ino b/libraries/BluetoothSerial/examples/bt_classic_device_discovery/bt_classic_device_discovery.ino index b3ec78ccf2a..8d44f262174 100644 --- a/libraries/BluetoothSerial/examples/bt_classic_device_discovery/bt_classic_device_discovery.ino +++ b/libraries/BluetoothSerial/examples/bt_classic_device_discovery/bt_classic_device_discovery.ino @@ -4,6 +4,10 @@ #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it #endif +#if !defined(CONFIG_BT_SPP_ENABLED) +#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip. +#endif + BluetoothSerial SerialBT; diff --git a/libraries/BLE/examples/BLE_scan/.skip.esp32c3 b/libraries/BluetoothSerial/examples/bt_remove_paired_devices/.skip.esp32s3 similarity index 100% rename from libraries/BLE/examples/BLE_scan/.skip.esp32c3 rename to libraries/BluetoothSerial/examples/bt_remove_paired_devices/.skip.esp32s3 diff --git a/libraries/BluetoothSerial/examples/bt_remove_paired_devices/bt_remove_paired_devices.ino b/libraries/BluetoothSerial/examples/bt_remove_paired_devices/bt_remove_paired_devices.ino index c316a73b2bc..0d49fe46414 100755 --- a/libraries/BluetoothSerial/examples/bt_remove_paired_devices/bt_remove_paired_devices.ino +++ b/libraries/BluetoothSerial/examples/bt_remove_paired_devices/bt_remove_paired_devices.ino @@ -15,6 +15,10 @@ #include"esp_gap_bt_api.h" #include "esp_err.h" +#if !defined(CONFIG_BT_SPP_ENABLED) +#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip. +#endif + #define REMOVE_BONDED_DEVICES 0 // <- Set to 0 to view all bonded devices addresses, set to 1 to remove #define PAIR_MAX_DEVICES 20 diff --git a/libraries/BluetoothSerial/src/BTAddress.cpp b/libraries/BluetoothSerial/src/BTAddress.cpp index 7ef1eb1a85e..72fe7587b72 100644 --- a/libraries/BluetoothSerial/src/BTAddress.cpp +++ b/libraries/BluetoothSerial/src/BTAddress.cpp @@ -29,6 +29,9 @@ BTAddress::BTAddress(esp_bd_addr_t address) { memcpy(m_address, address, ESP_BD_ADDR_LEN); } // BTAddress +BTAddress::BTAddress() { + bzero(m_address, ESP_BD_ADDR_LEN); +} // BTAddress /** * @brief Create an address from a hex string @@ -64,13 +67,20 @@ bool BTAddress::equals(BTAddress otherAddress) { return memcmp(otherAddress.getNative(), m_address, 6) == 0; } // equals +BTAddress::operator bool () const { + for(int i = 0; i < ESP_BD_ADDR_LEN; i++){ + if(this->m_address[i]) + return true; + } + return false; +} // operator () /** * @brief Return the native representation of the address. * @return The native representation of the address. */ -esp_bd_addr_t *BTAddress::getNative() { - return &m_address; +esp_bd_addr_t *BTAddress::getNative() const { + return const_cast(&m_address); } // getNative @@ -85,7 +95,7 @@ esp_bd_addr_t *BTAddress::getNative() { * * @return The string representation of the address. */ -std::string BTAddress::toString() { +std::string BTAddress::toString() const { auto size = 18; char *res = (char*)malloc(size); snprintf(res, size, "%02x:%02x:%02x:%02x:%02x:%02x", m_address[0], m_address[1], m_address[2], m_address[3], m_address[4], m_address[5]); diff --git a/libraries/BluetoothSerial/src/BTAddress.h b/libraries/BluetoothSerial/src/BTAddress.h index 6213d01fdf2..3e51d053ebb 100644 --- a/libraries/BluetoothSerial/src/BTAddress.h +++ b/libraries/BluetoothSerial/src/BTAddress.h @@ -22,11 +22,14 @@ */ class BTAddress { public: + BTAddress(); BTAddress(esp_bd_addr_t address); BTAddress(std::string stringAddress); bool equals(BTAddress otherAddress); - esp_bd_addr_t* getNative(); - std::string toString(); + operator bool () const; + + esp_bd_addr_t* getNative() const; + std::string toString() const; private: esp_bd_addr_t m_address; diff --git a/libraries/BluetoothSerial/src/BTAdvertisedDevice.h b/libraries/BluetoothSerial/src/BTAdvertisedDevice.h index 07e93622e92..918946f1910 100644 --- a/libraries/BluetoothSerial/src/BTAdvertisedDevice.h +++ b/libraries/BluetoothSerial/src/BTAdvertisedDevice.h @@ -16,14 +16,14 @@ class BTAdvertisedDevice { virtual ~BTAdvertisedDevice() = default; virtual BTAddress getAddress(); - virtual uint32_t getCOD(); - virtual std::string getName(); - virtual int8_t getRSSI(); + virtual uint32_t getCOD() const; + virtual std::string getName() const; + virtual int8_t getRSSI() const; - virtual bool haveCOD(); - virtual bool haveName(); - virtual bool haveRSSI(); + virtual bool haveCOD() const; + virtual bool haveName() const; + virtual bool haveRSSI() const; virtual std::string toString(); }; @@ -35,14 +35,14 @@ class BTAdvertisedDeviceSet : public virtual BTAdvertisedDevice { BTAddress getAddress(); - uint32_t getCOD(); - std::string getName(); - int8_t getRSSI(); + uint32_t getCOD() const; + std::string getName() const; + int8_t getRSSI() const; - bool haveCOD(); - bool haveName(); - bool haveRSSI(); + bool haveCOD() const; + bool haveName() const; + bool haveRSSI() const; std::string toString(); @@ -62,4 +62,4 @@ class BTAdvertisedDeviceSet : public virtual BTAdvertisedDevice { int8_t m_rssi; }; -#endif \ No newline at end of file +#endif diff --git a/libraries/BluetoothSerial/src/BTAdvertisedDeviceSet.cpp b/libraries/BluetoothSerial/src/BTAdvertisedDeviceSet.cpp index c8f28e9c39e..8a9e26e4d5a 100644 --- a/libraries/BluetoothSerial/src/BTAdvertisedDeviceSet.cpp +++ b/libraries/BluetoothSerial/src/BTAdvertisedDeviceSet.cpp @@ -25,14 +25,14 @@ BTAdvertisedDeviceSet::BTAdvertisedDeviceSet() { } // BTAdvertisedDeviceSet BTAddress BTAdvertisedDeviceSet::getAddress() { return m_address; } -uint32_t BTAdvertisedDeviceSet::getCOD() { return m_cod; } -std::string BTAdvertisedDeviceSet::getName() { return m_name; } -int8_t BTAdvertisedDeviceSet::getRSSI() { return m_rssi; } +uint32_t BTAdvertisedDeviceSet::getCOD() const { return m_cod; } +std::string BTAdvertisedDeviceSet::getName() const { return m_name; } +int8_t BTAdvertisedDeviceSet::getRSSI() const { return m_rssi; } -bool BTAdvertisedDeviceSet::haveCOD() { return m_haveCOD; } -bool BTAdvertisedDeviceSet::haveName() { return m_haveName; } -bool BTAdvertisedDeviceSet::haveRSSI() { return m_haveRSSI; } +bool BTAdvertisedDeviceSet::haveCOD() const { return m_haveCOD; } +bool BTAdvertisedDeviceSet::haveName() const { return m_haveName; } +bool BTAdvertisedDeviceSet::haveRSSI() const { return m_haveRSSI; } /** * @brief Create a string representation of this device. diff --git a/libraries/BluetoothSerial/src/BTScan.h b/libraries/BluetoothSerial/src/BTScan.h index 3650d41625b..2851fdd3626 100644 --- a/libraries/BluetoothSerial/src/BTScan.h +++ b/libraries/BluetoothSerial/src/BTScan.h @@ -24,14 +24,14 @@ class BTScanResults { virtual void dump(Print *print = nullptr); virtual int getCount(); - virtual BTAdvertisedDevice* getDevice(uint32_t i); + virtual BTAdvertisedDevice* getDevice(int i); }; class BTScanResultsSet : public BTScanResults { public: void dump(Print *print = nullptr); int getCount(); - BTAdvertisedDevice* getDevice(uint32_t i); + BTAdvertisedDevice* getDevice(int i); bool add(BTAdvertisedDeviceSet advertisedDevice, bool unique = true); void clear(); @@ -39,4 +39,4 @@ class BTScanResultsSet : public BTScanResults { std::map m_vectorAdvertisedDevices; }; -#endif \ No newline at end of file +#endif diff --git a/libraries/BluetoothSerial/src/BTScanResultsSet.cpp b/libraries/BluetoothSerial/src/BTScanResultsSet.cpp index 79d23e463cd..e347228c848 100644 --- a/libraries/BluetoothSerial/src/BTScanResultsSet.cpp +++ b/libraries/BluetoothSerial/src/BTScanResultsSet.cpp @@ -63,11 +63,11 @@ int BTScanResultsSet::getCount() { * @param [in] i The index of the device. * @return The device at the specified index. */ -BTAdvertisedDevice* BTScanResultsSet::getDevice(uint32_t i) { +BTAdvertisedDevice* BTScanResultsSet::getDevice(int i) { if (i < 0) return nullptr; - uint32_t x = 0; + int x = 0; BTAdvertisedDeviceSet* pDev = &m_vectorAdvertisedDevices.begin()->second; for (auto it = m_vectorAdvertisedDevices.begin(); it != m_vectorAdvertisedDevices.end(); it++) { pDev = &it->second; @@ -92,4 +92,4 @@ bool BTScanResultsSet::add(BTAdvertisedDeviceSet advertisedDevice, bool unique) return false; } -#endif \ No newline at end of file +#endif diff --git a/libraries/BluetoothSerial/src/BluetoothSerial.cpp b/libraries/BluetoothSerial/src/BluetoothSerial.cpp index b20452c186a..ea72f787ebf 100644 --- a/libraries/BluetoothSerial/src/BluetoothSerial.cpp +++ b/libraries/BluetoothSerial/src/BluetoothSerial.cpp @@ -72,18 +72,30 @@ static esp_bt_pin_code_t _pin_code; static int _pin_len; static bool _isPinSet; static bool _enableSSP; +static esp_spp_sec_t _sec_mask; +static esp_spp_role_t _role; +// start connect on ESP_SPP_DISCOVERY_COMP_EVT or save entry for getChannels +static bool _doConnect; +static std::map sdpRecords; static BTScanResultsSet scanResults; static BTAdvertisedDeviceCb advertisedDeviceCb = nullptr; +// _spp_event_group #define SPP_RUNNING 0x01 #define SPP_CONNECTED 0x02 #define SPP_CONGESTED 0x04 +// true until OPEN successful, changes to false on CLOSE #define SPP_DISCONNECTED 0x08 +// true until connect(), changes to true on CLOSE +#define SPP_CLOSED 0x10 +// _bt_event_group #define BT_DISCOVERY_RUNNING 0x01 #define BT_DISCOVERY_COMPLETED 0x02 +#define BT_SDP_RUNNING 0x04 +#define BT_SDP_COMPLETED 0x08 typedef struct { size_t len; @@ -98,7 +110,7 @@ static char *bda2str(esp_bd_addr_t bda, char *str, size_t size) } uint8_t *p = bda; - sprintf(str, "%02x:%02x:%02x:%02x:%02x:%02x", + snprintf(str, size, "%02x:%02x:%02x:%02x:%02x:%02x", p[0], p[1], p[2], p[3], p[4], p[5]); return str; } @@ -280,13 +292,15 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) case ESP_SPP_CLOSE_EVT://Client connection closed if ((param->close.async == false && param->close.status == ESP_SPP_SUCCESS) || param->close.async) { - log_i("ESP_SPP_CLOSE_EVT: %u", secondConnectionAttempt); + log_i("ESP_SPP_CLOSE_EVT status:%d handle:%d close_by_remote:%d attempt %u", param->close.status, + param->close.handle, param->close.async, secondConnectionAttempt); if(secondConnectionAttempt) { secondConnectionAttempt = false; } else { _spp_client = 0; xEventGroupSetBits(_spp_event_group, SPP_DISCONNECTED); xEventGroupSetBits(_spp_event_group, SPP_CONGESTED); + xEventGroupSetBits(_spp_event_group, SPP_CLOSED); } xEventGroupClearBits(_spp_event_group, SPP_CONNECTED); } else { @@ -333,13 +347,37 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) break; case ESP_SPP_DISCOVERY_COMP_EVT://discovery complete - log_i("ESP_SPP_DISCOVERY_COMP_EVT"); + log_i("ESP_SPP_DISCOVERY_COMP_EVT num=%d", param->disc_comp.scn_num); if (param->disc_comp.status == ESP_SPP_SUCCESS) { - log_i("ESP_SPP_DISCOVERY_COMP_EVT: spp connect to remote"); - esp_spp_connect(ESP_SPP_SEC_AUTHENTICATE, ESP_SPP_ROLE_MASTER, param->disc_comp.scn[0], _peer_bd_addr); + for(int i=0; i < param->disc_comp.scn_num; i++) { + log_d("ESP_SPP_DISCOVERY_COMP_EVT: spp [%d] channel: %d service name:%s", i, param->disc_comp.scn[i], param->disc_comp.service_name[0]); + } + if(_doConnect) { + if(param->disc_comp.scn_num > 0) { +#if (ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO) + char bda_str[18]; + log_i("ESP_SPP_DISCOVERY_COMP_EVT: spp connect to remote %s channel %d", + bda2str(_peer_bd_addr, bda_str, sizeof(bda_str)), + param->disc_comp.scn[0]); +#endif + xEventGroupClearBits(_spp_event_group, SPP_CLOSED); + if(esp_spp_connect(_sec_mask, _role, param->disc_comp.scn[0], _peer_bd_addr) != ESP_OK) { + log_e("ESP_SPP_DISCOVERY_COMP_EVT connect failed"); + xEventGroupSetBits(_spp_event_group, SPP_CLOSED); + } + } else { + log_e("ESP_SPP_DISCOVERY_COMP_EVT remote doesn't offer an SPP channel"); + xEventGroupSetBits(_spp_event_group, SPP_CLOSED); + } + } else { + for(int i=0; i < param->disc_comp.scn_num; i++) { + sdpRecords[param->disc_comp.scn[i]] = param->disc_comp.service_name[0]; + } + } } else { log_e("ESP_SPP_DISCOVERY_COMP_EVT failed!, status:%d", param->disc_comp.status); } + xEventGroupSetBits(_bt_event_group, BT_SDP_COMPLETED); break; case ESP_SPP_OPEN_EVT://Client connection open @@ -360,10 +398,15 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) break; case ESP_SPP_CL_INIT_EVT://client initiated a connection - log_i("ESP_SPP_CL_INIT_EVT"); + if (param->cl_init.status == ESP_SPP_SUCCESS) { + log_i("ESP_SPP_CL_INIT_EVT handle:%d sec_id:%d", param->cl_init.handle, param->cl_init.sec_id); + } else { + log_i("ESP_SPP_CL_INIT_EVT status:%d", param->cl_init.status); + } break; default: + log_i("ESP_SPP_* event unhandled %d", event); break; } if(custom_spp_callback)(*custom_spp_callback)(event, param); @@ -377,7 +420,7 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa { switch(event){ case ESP_BT_GAP_DISC_RES_EVT: { - log_i("ESP_BT_GAP_DISC_RES_EVT"); + log_i("ESP_BT_GAP_DISC_RES_EVT properties=%d", param->disc_res.num_prop); #if (ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO) char bda_str[18]; log_i("Scanned device: %s", bda2str(param->disc_res.bda, bda_str, 18)); @@ -417,28 +460,29 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa break; case ESP_BT_GAP_DEV_PROP_COD: - log_d("ESP_BT_GAP_DEV_PROP_COD"); if (param->disc_res.prop[i].len <= sizeof(int)) { uint32_t cod = 0; memcpy(&cod, param->disc_res.prop[i].val, param->disc_res.prop[i].len); advertisedDevice.setCOD(cod); + log_d("ESP_BT_GAP_DEV_PROP_COD 0x%x", cod); } else { - log_d("Value size larger than integer"); + log_d("ESP_BT_GAP_DEV_PROP_COD invalid COD: Value size larger than integer"); } break; case ESP_BT_GAP_DEV_PROP_RSSI: - log_d("ESP_BT_GAP_DEV_PROP_RSSI"); if (param->disc_res.prop[i].len <= sizeof(int)) { uint8_t rssi = 0; memcpy(&rssi, param->disc_res.prop[i].val, param->disc_res.prop[i].len); + log_d("ESP_BT_GAP_DEV_PROP_RSSI %d", rssi); advertisedDevice.setRSSI(rssi); } else { - log_d("Value size larger than integer"); + log_d("ESP_BT_GAP_DEV_PROP_RSSI invalid RSSI: Value size larger than integer"); } break; default: + log_i("ESP_BT_GAP_DISC_RES_EVT unknown property [%d]:type:%d", i, param->disc_res.prop[i].type); break; } if (_isRemoteAddressSet) @@ -455,11 +499,12 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa break; case ESP_BT_GAP_DISC_STATE_CHANGED_EVT: - log_i("ESP_BT_GAP_DISC_STATE_CHANGED_EVT"); if (param->disc_st_chg.state == ESP_BT_GAP_DISCOVERY_STOPPED) { + log_i("ESP_BT_GAP_DISC_STATE_CHANGED_EVT stopped"); xEventGroupClearBits(_bt_event_group, BT_DISCOVERY_RUNNING); xEventGroupSetBits(_bt_event_group, BT_DISCOVERY_COMPLETED); } else { // ESP_BT_GAP_DISCOVERY_STARTED + log_i("ESP_BT_GAP_DISC_STATE_CHANGED_EVT started"); xEventGroupClearBits(_bt_event_group, BT_DISCOVERY_COMPLETED); xEventGroupSetBits(_bt_event_group, BT_DISCOVERY_RUNNING); } @@ -522,7 +567,24 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa log_i("ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!"); break; + case ESP_BT_GAP_CONFIG_EIR_DATA_EVT: + log_i("ESP_BT_GAP_CONFIG_EIR_DATA_EVT: stat:%d num:%d", param->config_eir_data.stat, param->config_eir_data.eir_type_num); + break; + + case ESP_BT_GAP_READ_REMOTE_NAME_EVT: + if (param->read_rmt_name.stat == ESP_BT_STATUS_SUCCESS ) { + log_i("ESP_BT_GAP_READ_REMOTE_NAME_EVT: %s", param->read_rmt_name.rmt_name); + } else { + log_i("ESP_BT_GAP_READ_REMOTE_NAME_EVT: no success stat:%d", param->read_rmt_name.stat); + } + break; + + case ESP_BT_GAP_MODE_CHG_EVT: + log_i("ESP_BT_GAP_MODE_CHG_EVT: mode: %d", param->mode_chg.mode); + break; + default: + log_i("ESP-BT_GAP_* unknown message: %d", event); break; } } @@ -546,6 +608,7 @@ static bool _init_bt(const char *deviceName) xEventGroupClearBits(_spp_event_group, 0xFFFFFF); xEventGroupSetBits(_spp_event_group, SPP_CONGESTED); xEventGroupSetBits(_spp_event_group, SPP_DISCONNECTED); + xEventGroupSetBits(_spp_event_group, SPP_CLOSED); } if (_spp_rx_queue == NULL){ _spp_rx_queue = xQueueCreate(RX_QUEUE_SIZE, sizeof(uint8_t)); //initialize the queue @@ -623,6 +686,7 @@ static bool _init_bt(const char *deviceName) esp_bt_dev_set_device_name(deviceName); if (_isPinSet) { + log_i("pin set"); btSetPin(); } @@ -690,7 +754,16 @@ static bool _stop_bt() static bool waitForConnect(int timeout) { TickType_t xTicksToWait = timeout / portTICK_PERIOD_MS; - return (xEventGroupWaitBits(_spp_event_group, SPP_CONNECTED, pdFALSE, pdTRUE, xTicksToWait) & SPP_CONNECTED) != 0; + // wait for connected or closed + EventBits_t rc = xEventGroupWaitBits(_spp_event_group, SPP_CONNECTED | SPP_CLOSED, pdFALSE, pdFALSE, xTicksToWait); + if((rc & SPP_CONNECTED) != 0) + return true; + else if((rc & SPP_CLOSED) != 0) { + log_d("connection closed!"); + return false; + } + log_d("timeout"); + return false; } static bool waitForDiscovered(int timeout) { @@ -698,6 +771,11 @@ static bool waitForDiscovered(int timeout) { return (xEventGroupWaitBits(_spp_event_group, BT_DISCOVERY_COMPLETED, pdFALSE, pdTRUE, xTicksToWait) & BT_DISCOVERY_COMPLETED) != 0; } +static bool waitForSDPRecord(int timeout) { + TickType_t xTicksToWait = timeout / portTICK_PERIOD_MS; + return (xEventGroupWaitBits(_bt_event_group, BT_SDP_COMPLETED, pdFALSE, pdTRUE, xTicksToWait) & BT_SDP_COMPLETED) != 0; +} + /* * Serial Bluetooth Arduino * @@ -713,6 +791,9 @@ BluetoothSerial::~BluetoothSerial(void) _stop_bt(); } +/** + * @Param isMaster set to true if you want to connect to an other device + */ bool BluetoothSerial::begin(String localName, bool isMaster) { _isMaster = isMaster; @@ -733,7 +814,7 @@ int BluetoothSerial::available(void) int BluetoothSerial::peek(void) { uint8_t c; - if (_spp_rx_queue && xQueuePeek(_spp_rx_queue, &c, 0)){ + if (_spp_rx_queue && xQueuePeek(_spp_rx_queue, &c, this->timeoutTicks)){ return c; } return -1; @@ -744,16 +825,24 @@ bool BluetoothSerial::hasClient(void) return _spp_client > 0; } -int BluetoothSerial::read(void) +int BluetoothSerial::read() { uint8_t c = 0; - if (_spp_rx_queue && xQueueReceive(_spp_rx_queue, &c, 0)){ + if (_spp_rx_queue && xQueueReceive(_spp_rx_queue, &c, this->timeoutTicks)){ return c; } return -1; } +/** + * Set timeout for read / peek + */ +void BluetoothSerial::setTimeout(int timeoutMS) +{ + this->timeoutTicks=timeoutMS / portTICK_PERIOD_MS; +} + size_t BluetoothSerial::write(uint8_t c) { return write(&c, 1); @@ -812,6 +901,7 @@ void BluetoothSerial::enableSSP() { * Use fixed pin code */ bool BluetoothSerial::setPin(const char *pin) { + log_i("pin: %s", pin); bool isEmpty = !(pin && *pin); if (isEmpty && !_isPinSet) { return true; // nothing to do @@ -837,7 +927,10 @@ bool BluetoothSerial::connect(String remoteName) return false; } disconnect(); + _doConnect = true; _isRemoteAddressSet = false; + _sec_mask = ESP_SPP_SEC_ENCRYPT|ESP_SPP_SEC_AUTHENTICATE; + _role = ESP_SPP_ROLE_MASTER; strncpy(_remote_name, remoteName.c_str(), ESP_BT_GAP_MAX_BDNAME_LEN); _remote_name[ESP_BT_GAP_MAX_BDNAME_LEN] = 0; log_i("master : remoteName"); @@ -847,13 +940,23 @@ bool BluetoothSerial::connect(String remoteName) #else esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE); #endif + xEventGroupClearBits(_spp_event_group, SPP_CLOSED); if (esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, INQ_LEN, INQ_NUM_RSPS) == ESP_OK) { return waitForConnect(SCAN_TIMEOUT); } return false; } -bool BluetoothSerial::connect(uint8_t remoteAddress[]) +/** + * @Param channel: specify channel or 0 for auto-detect + * @Param sec_mask: + * ESP_SPP_SEC_ENCRYPT|ESP_SPP_SEC_AUTHENTICATE + * ESP_SPP_SEC_NONE + * @Param role: + * ESP_SPP_ROLE_MASTER master can handle up to 7 connections to slaves + * ESP_SPP_ROLE_SLAVE can only have one connection to a master + */ +bool BluetoothSerial::connect(uint8_t remoteAddress[], int channel, esp_spp_sec_t sec_mask, esp_spp_role_t role) { if (!isReady(true, READY_TIMEOUT)) return false; if (!remoteAddress) { @@ -861,10 +964,35 @@ bool BluetoothSerial::connect(uint8_t remoteAddress[]) return false; } disconnect(); + _doConnect = true; _remote_name[0] = 0; _isRemoteAddressSet = true; + _sec_mask = sec_mask; + _role = role; memcpy(_peer_bd_addr, remoteAddress, ESP_BD_ADDR_LEN); log_i("master : remoteAddress"); + xEventGroupClearBits(_spp_event_group, SPP_CLOSED); + if (channel > 0) { + char bda_str[18]; + log_i("spp connect to remote %s channel %d", + bda2str(_peer_bd_addr, bda_str, sizeof(bda_str)), + channel); + if(esp_spp_connect(sec_mask, role, channel, _peer_bd_addr) != ESP_OK ) { + log_e("spp connect failed"); + return false; + } + bool rc=waitForConnect(READY_TIMEOUT); + if(rc) { + log_i("connected"); + } else { + if(this->isClosed()) { + log_e("connect failed"); + } else { + log_e("connect timed out after %dms", READY_TIMEOUT); + } + } + return rc; + } if (esp_spp_start_discovery(_peer_bd_addr) == ESP_OK) { return waitForConnect(READY_TIMEOUT); } @@ -874,6 +1002,7 @@ bool BluetoothSerial::connect(uint8_t remoteAddress[]) bool BluetoothSerial::connect() { if (!isReady(true, READY_TIMEOUT)) return false; + _doConnect = true; if (_isRemoteAddressSet){ disconnect(); // use resolved or set address first @@ -924,6 +1053,13 @@ bool BluetoothSerial::connected(int timeout) { return waitForConnect(timeout); } +/** + * true if a connection terminated or a connection attempt failed + */ +bool BluetoothSerial::isClosed() { + return xEventGroupGetBits(_spp_event_group) & SPP_CLOSED; +} + bool BluetoothSerial::isReady(bool checkMaster, int timeout) { if (checkMaster && !_isMaster) { log_e("Master mode is not active. Call begin(localName, true) to enable Master mode"); @@ -956,6 +1092,7 @@ BTScanResults* BluetoothSerial::discover(int timeoutMs) { esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE); if (esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, timeout, 0) == ESP_OK) { waitForDiscovered(timeoutMs); + log_i("gap_cancel_discovery()"); esp_bt_gap_cancel_discovery(); } return &scanResults; @@ -1008,4 +1145,31 @@ BluetoothSerial::operator bool() const { return true; } + +/** + * SDP scan address + * esp_spp_start_discovery doesn't tell us the btAddress in the callback, so we have to wait until it's finished + */ +std::map BluetoothSerial::getChannels(const BTAddress &remoteAddress) { + if(xEventGroupGetBits(_bt_event_group) & BT_SDP_RUNNING) { + log_e("getChannels failed - already running"); + } + xEventGroupSetBits(_bt_event_group, BT_SDP_RUNNING); + xEventGroupClearBits(_bt_event_group, BT_SDP_COMPLETED); + _doConnect = false; + sdpRecords.clear(); + log_d("esp_spp_start_discovery"); + if (esp_spp_start_discovery(*remoteAddress.getNative()) != ESP_OK) { + log_e("esp_spp_start_discovery failed"); + } else { + if(! waitForSDPRecord(READY_TIMEOUT)) { + log_e("getChannels failed timeout"); + } + log_d("esp_spp_start_discovery wait for BT_SDP_COMPLETED done (%dms)", READY_TIMEOUT); + } + log_d("esp_spp_start_discovery done, found %d services", sdpRecords.size()); + xEventGroupClearBits(_bt_event_group, BT_SDP_RUNNING); + return sdpRecords; +} + #endif diff --git a/libraries/BluetoothSerial/src/BluetoothSerial.h b/libraries/BluetoothSerial/src/BluetoothSerial.h index cfb8b823045..0c087b06360 100644 --- a/libraries/BluetoothSerial/src/BluetoothSerial.h +++ b/libraries/BluetoothSerial/src/BluetoothSerial.h @@ -24,6 +24,7 @@ #include #include #include +#include #include "BTScan.h" typedef std::function BluetoothSerialDataCb; @@ -50,6 +51,7 @@ class BluetoothSerial: public Stream size_t write(const uint8_t *buffer, size_t size); void flush(); void end(void); + void setTimeout(int timeoutMS); void onData(BluetoothSerialDataCb cb); esp_err_t register_callback(esp_spp_cb_t * callback); @@ -60,9 +62,12 @@ class BluetoothSerial: public Stream void enableSSP(); bool setPin(const char *pin); bool connect(String remoteName); - bool connect(uint8_t remoteAddress[]); + bool connect(uint8_t remoteAddress[], int channel=0, esp_spp_sec_t sec_mask=(ESP_SPP_SEC_ENCRYPT|ESP_SPP_SEC_AUTHENTICATE), esp_spp_role_t role=ESP_SPP_ROLE_MASTER); + bool connect(const BTAddress &remoteAddress, int channel=0, esp_spp_sec_t sec_mask=(ESP_SPP_SEC_ENCRYPT|ESP_SPP_SEC_AUTHENTICATE), esp_spp_role_t role=ESP_SPP_ROLE_MASTER) { + return connect(*remoteAddress.getNative(), channel, sec_mask); }; bool connect(); bool connected(int timeout=0); + bool isClosed(); bool isReady(bool checkMaster=false, int timeout=0); bool disconnect(); bool unpairDevice(uint8_t remoteAddress[]); @@ -73,6 +78,8 @@ class BluetoothSerial: public Stream void discoverClear(); BTScanResults* getScanResults(); + std::map getChannels(const BTAddress &remoteAddress); + const int INQ_TIME = 1280; // Inquire Time unit 1280 ms const int MIN_INQ_TIME = (ESP_BT_GAP_MIN_INQ_LEN * INQ_TIME); const int MAX_INQ_TIME = (ESP_BT_GAP_MAX_INQ_LEN * INQ_TIME); @@ -80,7 +87,7 @@ class BluetoothSerial: public Stream operator bool() const; private: String local_name; - + int timeoutTicks=0; }; #endif diff --git a/libraries/DNSServer/src/DNSServer.h b/libraries/DNSServer/src/DNSServer.h index a10ef9eaaf1..f237a4e358d 100644 --- a/libraries/DNSServer/src/DNSServer.h +++ b/libraries/DNSServer/src/DNSServer.h @@ -66,8 +66,8 @@ struct DNSHeader struct DNSQuestion { - uint8_t QName[255] ; - int8_t QNameLength ; + uint8_t QName[256] ; //need 1 Byte for zero termination! + uint16_t QNameLength ; uint16_t QType ; uint16_t QClass ; } ; @@ -106,4 +106,4 @@ class DNSServer void replyWithIP(); void replyWithCustomCode(); }; -#endif \ No newline at end of file +#endif diff --git a/libraries/ESP32/examples/AnalogOut/LEDCSoftwareFade/LEDCSoftwareFade.ino b/libraries/ESP32/examples/AnalogOut/LEDCSoftwareFade/LEDCSoftwareFade.ino index a4f2e5b41ba..c8b3e139396 100644 --- a/libraries/ESP32/examples/AnalogOut/LEDCSoftwareFade/LEDCSoftwareFade.ino +++ b/libraries/ESP32/examples/AnalogOut/LEDCSoftwareFade/LEDCSoftwareFade.ino @@ -13,8 +13,8 @@ // use first channel of 16 channels (started from zero) #define LEDC_CHANNEL_0 0 -// use 13 bit precission for LEDC timer -#define LEDC_TIMER_13_BIT 13 +// use 12 bit precission for LEDC timer +#define LEDC_TIMER_12_BIT 12 // use 5000 Hz as a LEDC base frequency #define LEDC_BASE_FREQ 5000 @@ -28,8 +28,8 @@ int fadeAmount = 5; // how many points to fade the LED by // Arduino like analogWrite // value has to be between 0 and valueMax void ledcAnalogWrite(uint8_t channel, uint32_t value, uint32_t valueMax = 255) { - // calculate duty, 8191 from 2 ^ 13 - 1 - uint32_t duty = (8191 / valueMax) * min(value, valueMax); + // calculate duty, 4095 from 2 ^ 12 - 1 + uint32_t duty = (4095 / valueMax) * min(value, valueMax); // write duty to LEDC ledcWrite(channel, duty); @@ -37,7 +37,7 @@ void ledcAnalogWrite(uint8_t channel, uint32_t value, uint32_t valueMax = 255) { void setup() { // Setup timer and attach timer to a led pin - ledcSetup(LEDC_CHANNEL_0, LEDC_BASE_FREQ, LEDC_TIMER_13_BIT); + ledcSetup(LEDC_CHANNEL_0, LEDC_BASE_FREQ, LEDC_TIMER_12_BIT); ledcAttachPin(LED_PIN, LEDC_CHANNEL_0); } diff --git a/libraries/ESP32/examples/AnalogRead/AnalogRead.ino b/libraries/ESP32/examples/AnalogRead/AnalogRead.ino new file mode 100644 index 00000000000..c238517d380 --- /dev/null +++ b/libraries/ESP32/examples/AnalogRead/AnalogRead.ino @@ -0,0 +1,19 @@ +void setup() { + // initialize serial communication at 115200 bits per second: + Serial.begin(115200); + + //set the resolution to 12 bits (0-4096) + analogReadResolution(12); +} + +void loop() { + // read the analog / millivolts value for pin 2: + int analogValue = analogRead(2); + int analogVolts = analogReadMilliVolts(2); + + // print out the values you read: + Serial.printf("ADC analog value = %d\n",analogValue); + Serial.printf("ADC millivolts value = %d\n",analogVolts); + + delay(100); // delay in between reads for clear read from serial +} diff --git a/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino b/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino index 44ff625bf05..0e268b4fefa 100644 --- a/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino +++ b/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino @@ -6,22 +6,35 @@ // Ensure ESP32 Wrover Module or other board with PSRAM is selected // Partial images will be transmitted if image exceeds buffer size // +// You must select partition scheme from the board menu that has at least 3MB APP space. +// Face Recognition is DISABLED for ESP32 and ESP32-S2, because it takes up from 15 +// seconds to process single frame. Face Detection is ENABLED if PSRAM is enabled as well +// =================== // Select camera model -#define CAMERA_MODEL_WROVER_KIT // Has PSRAM +// =================== +//#define CAMERA_MODEL_WROVER_KIT // Has PSRAM //#define CAMERA_MODEL_ESP_EYE // Has PSRAM +//#define CAMERA_MODEL_ESP32S3_EYE // Has PSRAM //#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM //#define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM //#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM //#define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM //#define CAMERA_MODEL_M5STACK_UNITCAM // No PSRAM -//#define CAMERA_MODEL_AI_THINKER // Has PSRAM +#define CAMERA_MODEL_AI_THINKER // Has PSRAM //#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM +// ** Espressif Internal Boards ** +//#define CAMERA_MODEL_ESP32_CAM_BOARD +//#define CAMERA_MODEL_ESP32S2_CAM_BOARD +//#define CAMERA_MODEL_ESP32S3_CAM_LCD #include "camera_pins.h" -const char* ssid = "*********"; -const char* password = "*********"; +// =========================== +// Enter your WiFi credentials +// =========================== +const char* ssid = "**********"; +const char* password = "**********"; void startCameraServer(); @@ -50,18 +63,32 @@ void setup() { config.pin_pwdn = PWDN_GPIO_NUM; config.pin_reset = RESET_GPIO_NUM; config.xclk_freq_hz = 20000000; - config.pixel_format = PIXFORMAT_JPEG; + config.frame_size = FRAMESIZE_UXGA; + config.pixel_format = PIXFORMAT_JPEG; // for streaming + //config.pixel_format = PIXFORMAT_RGB565; // for face detection/recognition + config.grab_mode = CAMERA_GRAB_WHEN_EMPTY; + config.fb_location = CAMERA_FB_IN_PSRAM; + config.jpeg_quality = 12; + config.fb_count = 1; // if PSRAM IC present, init with UXGA resolution and higher JPEG quality // for larger pre-allocated frame buffer. - if(psramFound()){ - config.frame_size = FRAMESIZE_UXGA; - config.jpeg_quality = 10; - config.fb_count = 2; + if(config.pixel_format == PIXFORMAT_JPEG){ + if(psramFound()){ + config.jpeg_quality = 10; + config.fb_count = 2; + config.grab_mode = CAMERA_GRAB_LATEST; + } else { + // Limit the frame size when PSRAM is not available + config.frame_size = FRAMESIZE_SVGA; + config.fb_location = CAMERA_FB_IN_DRAM; + } } else { - config.frame_size = FRAMESIZE_SVGA; - config.jpeg_quality = 12; - config.fb_count = 1; + // Best option for face detection/recognition + config.frame_size = FRAMESIZE_240X240; +#if CONFIG_IDF_TARGET_ESP32S3 + config.fb_count = 2; +#endif } #if defined(CAMERA_MODEL_ESP_EYE) @@ -84,14 +111,21 @@ void setup() { s->set_saturation(s, -2); // lower the saturation } // drop down frame size for higher initial frame rate - s->set_framesize(s, FRAMESIZE_QVGA); + if(config.pixel_format == PIXFORMAT_JPEG){ + s->set_framesize(s, FRAMESIZE_QVGA); + } #if defined(CAMERA_MODEL_M5STACK_WIDE) || defined(CAMERA_MODEL_M5STACK_ESP32CAM) s->set_vflip(s, 1); s->set_hmirror(s, 1); #endif +#if defined(CAMERA_MODEL_ESP32S3_EYE) + s->set_vflip(s, 1); +#endif + WiFi.begin(ssid, password); + WiFi.setSleep(false); while (WiFi.status() != WL_CONNECTED) { delay(500); @@ -108,6 +142,6 @@ void setup() { } void loop() { - // put your main code here, to run repeatedly: + // Do nothing. Everything is done in another task by the web server delay(10000); } diff --git a/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp b/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp index 278964720f1..79ff0ba6aa1 100644 --- a/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp +++ b/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp @@ -17,7 +17,6 @@ #include "img_converters.h" #include "fb_gfx.h" #include "driver/ledc.h" -//#include "camera_index.h" #include "sdkconfig.h" #include "camera_index.h" @@ -29,14 +28,37 @@ static const char *TAG = "camera_httpd"; #endif +// Face Detection will not work on boards without (or with disabled) PSRAM +#ifdef BOARD_HAS_PSRAM +#define CONFIG_ESP_FACE_DETECT_ENABLED 1 +// Face Recognition takes upward from 15 seconds per frame on chips other than ESP32S3 +// Makes no sense to have it enabled for them +#if CONFIG_IDF_TARGET_ESP32S3 +#define CONFIG_ESP_FACE_RECOGNITION_ENABLED 1 +#else +#define CONFIG_ESP_FACE_RECOGNITION_ENABLED 0 +#endif +#else +#define CONFIG_ESP_FACE_DETECT_ENABLED 0 +#define CONFIG_ESP_FACE_RECOGNITION_ENABLED 0 +#endif + #if CONFIG_ESP_FACE_DETECT_ENABLED -#include "fd_forward.h" +#include +#include "human_face_detect_msr01.hpp" +#include "human_face_detect_mnp01.hpp" + +#define TWO_STAGE 1 /* very large firmware, very slow, reboots when streaming... -#define ENROLL_CONFIRM_TIMES 5 #define FACE_ID_SAVE_NUMBER 7 #endif @@ -78,12 +100,24 @@ httpd_handle_t camera_httpd = NULL; static int8_t detection_enabled = 0; -static mtmn_config_t mtmn_config = {0}; +// #if TWO_STAGE +// static HumanFaceDetectMSR01 s1(0.1F, 0.5F, 10, 0.2F); +// static HumanFaceDetectMNP01 s2(0.5F, 0.3F, 5); +// #else +// static HumanFaceDetectMSR01 s1(0.3F, 0.5F, 10, 0.2F); +// #endif #if CONFIG_ESP_FACE_RECOGNITION_ENABLED static int8_t recognition_enabled = 0; static int8_t is_enrolling = 0; -static face_id_list id_list = {0}; + +#if QUANT_TYPE + // S16 model + FaceRecognition112V1S16 recognizer; +#else + // S8 model + FaceRecognition112V1S8 recognizer; +#endif #endif #endif @@ -134,18 +168,12 @@ static int ra_filter_run(ra_filter_t *filter, int value) #if CONFIG_ESP_FACE_DETECT_ENABLED #if CONFIG_ESP_FACE_RECOGNITION_ENABLED -static void rgb_print(dl_matrix3du_t *image_matrix, uint32_t color, const char *str) +static void rgb_print(fb_data_t *fb, uint32_t color, const char *str) { - fb_data_t fb; - fb.width = image_matrix->w; - fb.height = image_matrix->h; - fb.data = image_matrix->item; - fb.bytes_per_pixel = 3; - fb.format = FB_BGR888; - fb_gfx_print(&fb, (fb.width - (strlen(str) * 14)) / 2, 10, color, str); + fb_gfx_print(fb, (fb->width - (strlen(str) * 14)) / 2, 10, color, str); } -static int rgb_printf(dl_matrix3du_t *image_matrix, uint32_t color, const char *format, ...) +static int rgb_printf(fb_data_t *fb, uint32_t color, const char *format, ...) { char loc_buf[64]; char *temp = loc_buf; @@ -166,7 +194,7 @@ static int rgb_printf(dl_matrix3du_t *image_matrix, uint32_t color, const char * } vsnprintf(temp, len + 1, format, arg); va_end(arg); - rgb_print(image_matrix, color, temp); + rgb_print(fb, color, temp); if (len > 64) { free(temp); @@ -174,9 +202,9 @@ static int rgb_printf(dl_matrix3du_t *image_matrix, uint32_t color, const char * return len; } #endif -static void draw_face_boxes(dl_matrix3du_t *image_matrix, box_array_t *boxes, int face_id) +static void draw_face_boxes(fb_data_t *fb, std::list *results, int face_id) { - int x, y, w, h, i; + int x, y, w, h; uint32_t color = FACE_COLOR_YELLOW; if (face_id < 0) { @@ -186,89 +214,64 @@ static void draw_face_boxes(dl_matrix3du_t *image_matrix, box_array_t *boxes, in { color = FACE_COLOR_GREEN; } - fb_data_t fb; - fb.width = image_matrix->w; - fb.height = image_matrix->h; - fb.data = image_matrix->item; - fb.bytes_per_pixel = 3; - fb.format = FB_BGR888; - for (i = 0; i < boxes->len; i++) + if(fb->bytes_per_pixel == 2){ + //color = ((color >> 8) & 0xF800) | ((color >> 3) & 0x07E0) | (color & 0x001F); + color = ((color >> 16) & 0x001F) | ((color >> 3) & 0x07E0) | ((color << 8) & 0xF800); + } + int i = 0; + for (std::list::iterator prediction = results->begin(); prediction != results->end(); prediction++, i++) { // rectangle box - x = (int)boxes->box[i].box_p[0]; - y = (int)boxes->box[i].box_p[1]; - w = (int)boxes->box[i].box_p[2] - x + 1; - h = (int)boxes->box[i].box_p[3] - y + 1; - fb_gfx_drawFastHLine(&fb, x, y, w, color); - fb_gfx_drawFastHLine(&fb, x, y + h - 1, w, color); - fb_gfx_drawFastVLine(&fb, x, y, h, color); - fb_gfx_drawFastVLine(&fb, x + w - 1, y, h, color); -#if 0 - // landmark + x = (int)prediction->box[0]; + y = (int)prediction->box[1]; + w = (int)prediction->box[2] - x + 1; + h = (int)prediction->box[3] - y + 1; + if((x + w) > fb->width){ + w = fb->width - x; + } + if((y + h) > fb->height){ + h = fb->height - y; + } + fb_gfx_drawFastHLine(fb, x, y, w, color); + fb_gfx_drawFastHLine(fb, x, y + h - 1, w, color); + fb_gfx_drawFastVLine(fb, x, y, h, color); + fb_gfx_drawFastVLine(fb, x + w - 1, y, h, color); +#if TWO_STAGE + // landmarks (left eye, mouth left, nose, right eye, mouth right) int x0, y0, j; for (j = 0; j < 10; j+=2) { - x0 = (int)boxes->landmark[i].landmark_p[j]; - y0 = (int)boxes->landmark[i].landmark_p[j+1]; - fb_gfx_fillRect(&fb, x0, y0, 3, 3, color); + x0 = (int)prediction->keypoint[j]; + y0 = (int)prediction->keypoint[j+1]; + fb_gfx_fillRect(fb, x0, y0, 3, 3, color); } #endif } } #if CONFIG_ESP_FACE_RECOGNITION_ENABLED -static int run_face_recognition(dl_matrix3du_t *image_matrix, box_array_t *net_boxes) +static int run_face_recognition(fb_data_t *fb, std::list *results) { - dl_matrix3du_t *aligned_face = NULL; - int matched_id = 0; + std::vector landmarks = results->front().keypoint; + int id = -1; - aligned_face = dl_matrix3du_alloc(1, FACE_WIDTH, FACE_HEIGHT, 3); - if (!aligned_face) - { - ESP_LOGE(TAG, "Could not allocate face recognition buffer"); - return matched_id; - } - if (align_face(net_boxes, image_matrix, aligned_face) == ESP_OK) - { - if (is_enrolling == 1) - { - int8_t left_sample_face = enroll_face(&id_list, aligned_face); + Tensor tensor; + tensor.set_element((uint8_t *)fb->data).set_shape({fb->height, fb->width, 3}).set_auto_free(false); - if (left_sample_face == (ENROLL_CONFIRM_TIMES - 1)) - { - ESP_LOGD(TAG, "Enrolling Face ID: %d", id_list.tail); - } - ESP_LOGD(TAG, "Enrolling Face ID: %d sample %d", id_list.tail, ENROLL_CONFIRM_TIMES - left_sample_face); - rgb_printf(image_matrix, FACE_COLOR_CYAN, "ID[%u] Sample[%u]", id_list.tail, ENROLL_CONFIRM_TIMES - left_sample_face); - if (left_sample_face == 0) - { - is_enrolling = 0; - ESP_LOGD(TAG, "Enrolled Face ID: %d", id_list.tail); - } - } - else - { - matched_id = recognize_face(&id_list, aligned_face); - if (matched_id >= 0) - { - ESP_LOGW(TAG, "Match Face ID: %u", matched_id); - rgb_printf(image_matrix, FACE_COLOR_GREEN, "Hello Subject %u", matched_id); - } - else - { - ESP_LOGW(TAG, "No Match Found"); - rgb_print(image_matrix, FACE_COLOR_RED, "Intruder Alert!"); - matched_id = -1; - } - } - } - else - { - ESP_LOGW(TAG, "Face Not Aligned"); - //rgb_print(image_matrix, FACE_COLOR_YELLOW, "Human Detected"); + int enrolled_count = recognizer.get_enrolled_id_num(); + + if (enrolled_count < FACE_ID_SAVE_NUMBER && is_enrolling){ + id = recognizer.enroll_id(tensor, landmarks, "", true); + ESP_LOGI(TAG, "Enrolled ID: %d", id); + rgb_printf(fb, FACE_COLOR_CYAN, "ID[%u]", id); } - dl_matrix3du_free(aligned_face); - return matched_id; + face_info_t recognize = recognizer.recognize(tensor, landmarks); + if(recognize.id >= 0){ + rgb_printf(fb, FACE_COLOR_GREEN, "ID[%u]: %.2f", recognize.id, recognize.similarity); + } else { + rgb_print(fb, FACE_COLOR_RED, "Intruder Alert!"); + } + return recognize.id; } #endif #endif @@ -399,55 +402,88 @@ static esp_err_t capture_handler(httpd_req_t *req) #if CONFIG_ESP_FACE_DETECT_ENABLED } - dl_matrix3du_t *image_matrix = dl_matrix3du_alloc(1, fb->width, fb->height, 3); - if (!image_matrix) - { - esp_camera_fb_return(fb); - ESP_LOGE(TAG, "dl_matrix3du_alloc failed"); - httpd_resp_send_500(req); - return ESP_FAIL; - } - - out_buf = image_matrix->item; - out_len = fb->width * fb->height * 3; - out_width = fb->width; - out_height = fb->height; + jpg_chunking_t jchunk = {req, 0}; - s = fmt2rgb888(fb->buf, fb->len, fb->format, out_buf); - esp_camera_fb_return(fb); - if (!s) + if (fb->format == PIXFORMAT_RGB565 +#if CONFIG_ESP_FACE_RECOGNITION_ENABLED + && !recognition_enabled +#endif + ){ +#if TWO_STAGE + HumanFaceDetectMSR01 s1(0.1F, 0.5F, 10, 0.2F); + HumanFaceDetectMNP01 s2(0.5F, 0.3F, 5); + std::list &candidates = s1.infer((uint16_t *)fb->buf, {(int)fb->height, (int)fb->width, 3}); + std::list &results = s2.infer((uint16_t *)fb->buf, {(int)fb->height, (int)fb->width, 3}, candidates); +#else + HumanFaceDetectMSR01 s1(0.3F, 0.5F, 10, 0.2F); + std::list &results = s1.infer((uint16_t *)fb->buf, {(int)fb->height, (int)fb->width, 3}); +#endif + if (results.size() > 0) { + fb_data_t rfb; + rfb.width = fb->width; + rfb.height = fb->height; + rfb.data = fb->buf; + rfb.bytes_per_pixel = 2; + rfb.format = FB_RGB565; + detected = true; + draw_face_boxes(&rfb, &results, face_id); + } + s = fmt2jpg_cb(fb->buf, fb->len, fb->width, fb->height, PIXFORMAT_RGB565, 90, jpg_encode_stream, &jchunk); + esp_camera_fb_return(fb); + } else { - dl_matrix3du_free(image_matrix); - ESP_LOGE(TAG, "to rgb888 failed"); - httpd_resp_send_500(req); - return ESP_FAIL; - } + out_len = fb->width * fb->height * 3; + out_width = fb->width; + out_height = fb->height; + out_buf = (uint8_t*)malloc(out_len); + if (!out_buf) { + ESP_LOGE(TAG, "out_buf malloc failed"); + httpd_resp_send_500(req); + return ESP_FAIL; + } + s = fmt2rgb888(fb->buf, fb->len, fb->format, out_buf); + esp_camera_fb_return(fb); + if (!s) { + free(out_buf); + ESP_LOGE(TAG, "to rgb888 failed"); + httpd_resp_send_500(req); + return ESP_FAIL; + } - box_array_t *net_boxes = face_detect(image_matrix, &mtmn_config); + fb_data_t rfb; + rfb.width = out_width; + rfb.height = out_height; + rfb.data = out_buf; + rfb.bytes_per_pixel = 3; + rfb.format = FB_BGR888; + +#if TWO_STAGE + HumanFaceDetectMSR01 s1(0.1F, 0.5F, 10, 0.2F); + HumanFaceDetectMNP01 s2(0.5F, 0.3F, 5); + std::list &candidates = s1.infer((uint8_t *)out_buf, {(int)out_height, (int)out_width, 3}); + std::list &results = s2.infer((uint8_t *)out_buf, {(int)out_height, (int)out_width, 3}, candidates); +#else + HumanFaceDetectMSR01 s1(0.3F, 0.5F, 10, 0.2F); + std::list &results = s1.infer((uint8_t *)out_buf, {(int)out_height, (int)out_width, 3}); +#endif - if (net_boxes) - { - detected = true; + if (results.size() > 0) { + detected = true; #if CONFIG_ESP_FACE_RECOGNITION_ENABLED - if (recognition_enabled) - { - face_id = run_face_recognition(image_matrix, net_boxes); - } + if (recognition_enabled) { + face_id = run_face_recognition(&rfb, &results); + } #endif - draw_face_boxes(image_matrix, net_boxes, face_id); - dl_lib_free(net_boxes->score); - dl_lib_free(net_boxes->box); - if (net_boxes->landmark != NULL) - dl_lib_free(net_boxes->landmark); - dl_lib_free(net_boxes); + draw_face_boxes(&rfb, &results, face_id); + } + + s = fmt2jpg_cb(out_buf, out_len, out_width, out_height, PIXFORMAT_RGB888, 90, jpg_encode_stream, &jchunk); + free(out_buf); } - jpg_chunking_t jchunk = {req, 0}; - s = fmt2jpg_cb(out_buf, out_len, out_width, out_height, PIXFORMAT_RGB888, 90, jpg_encode_stream, &jchunk); - dl_matrix3du_free(image_matrix); - if (!s) - { + if (!s) { ESP_LOGE(TAG, "JPEG compression failed"); + httpd_resp_send_500(req); return ESP_FAIL; } @@ -466,7 +502,6 @@ static esp_err_t stream_handler(httpd_req_t *req) uint8_t *_jpg_buf = NULL; char *part_buf[128]; #if CONFIG_ESP_FACE_DETECT_ENABLED - dl_matrix3du_t *image_matrix = NULL; bool detected = false; int face_id = 0; int64_t fr_start = 0; @@ -474,6 +509,16 @@ static esp_err_t stream_handler(httpd_req_t *req) int64_t fr_face = 0; int64_t fr_recognize = 0; int64_t fr_encode = 0; + + size_t out_len = 0, out_width = 0, out_height = 0; + uint8_t *out_buf = NULL; + bool s = false; +#if TWO_STAGE + HumanFaceDetectMSR01 s1(0.1F, 0.5F, 10, 0.2F); + HumanFaceDetectMNP01 s2(0.5F, 0.3F, 5); +#else + HumanFaceDetectMSR01 s1(0.3F, 0.5F, 10, 0.2F); +#endif #endif static int64_t last_frame = 0; @@ -542,65 +587,94 @@ static esp_err_t stream_handler(httpd_req_t *req) } else { - - image_matrix = dl_matrix3du_alloc(1, fb->width, fb->height, 3); - - if (!image_matrix) - { - ESP_LOGE(TAG, "dl_matrix3du_alloc failed"); - res = ESP_FAIL; - } - else - { - if (!fmt2rgb888(fb->buf, fb->len, fb->format, image_matrix->item)) - { - ESP_LOGE(TAG, "fmt2rgb888 failed"); + if (fb->format == PIXFORMAT_RGB565 +#if CONFIG_ESP_FACE_RECOGNITION_ENABLED + && !recognition_enabled +#endif + ){ + fr_ready = esp_timer_get_time(); +#if TWO_STAGE + std::list &candidates = s1.infer((uint16_t *)fb->buf, {(int)fb->height, (int)fb->width, 3}); + std::list &results = s2.infer((uint16_t *)fb->buf, {(int)fb->height, (int)fb->width, 3}, candidates); +#else + std::list &results = s1.infer((uint16_t *)fb->buf, {(int)fb->height, (int)fb->width, 3}); +#endif + fr_face = esp_timer_get_time(); + fr_recognize = fr_face; + if (results.size() > 0) { + fb_data_t rfb; + rfb.width = fb->width; + rfb.height = fb->height; + rfb.data = fb->buf; + rfb.bytes_per_pixel = 2; + rfb.format = FB_RGB565; + detected = true; + draw_face_boxes(&rfb, &results, face_id); + } + s = fmt2jpg(fb->buf, fb->len, fb->width, fb->height, PIXFORMAT_RGB565, 80, &_jpg_buf, &_jpg_buf_len); + esp_camera_fb_return(fb); + fb = NULL; + if (!s) { + ESP_LOGE(TAG, "fmt2jpg failed"); res = ESP_FAIL; } - else - { - fr_ready = esp_timer_get_time(); - box_array_t *net_boxes = NULL; - if (detection_enabled) - { - net_boxes = face_detect(image_matrix, &mtmn_config); - } - fr_face = esp_timer_get_time(); - fr_recognize = fr_face; - if (net_boxes || fb->format != PIXFORMAT_JPEG) - { - if (net_boxes) - { + fr_encode = esp_timer_get_time(); + } else + { + out_len = fb->width * fb->height * 3; + out_width = fb->width; + out_height = fb->height; + out_buf = (uint8_t*)malloc(out_len); + if (!out_buf) { + ESP_LOGE(TAG, "out_buf malloc failed"); + res = ESP_FAIL; + } else { + s = fmt2rgb888(fb->buf, fb->len, fb->format, out_buf); + esp_camera_fb_return(fb); + fb = NULL; + if (!s) { + free(out_buf); + ESP_LOGE(TAG, "to rgb888 failed"); + res = ESP_FAIL; + } else { + fr_ready = esp_timer_get_time(); + + fb_data_t rfb; + rfb.width = out_width; + rfb.height = out_height; + rfb.data = out_buf; + rfb.bytes_per_pixel = 3; + rfb.format = FB_BGR888; + +#if TWO_STAGE + std::list &candidates = s1.infer((uint8_t *)out_buf, {(int)out_height, (int)out_width, 3}); + std::list &results = s2.infer((uint8_t *)out_buf, {(int)out_height, (int)out_width, 3}, candidates); +#else + std::list &results = s1.infer((uint8_t *)out_buf, {(int)out_height, (int)out_width, 3}); +#endif + + fr_face = esp_timer_get_time(); + fr_recognize = fr_face; + + if (results.size() > 0) { detected = true; #if CONFIG_ESP_FACE_RECOGNITION_ENABLED - if (recognition_enabled) - { - face_id = run_face_recognition(image_matrix, net_boxes); + if (recognition_enabled) { + face_id = run_face_recognition(&rfb, &results); + fr_recognize = esp_timer_get_time(); } - fr_recognize = esp_timer_get_time(); #endif - draw_face_boxes(image_matrix, net_boxes, face_id); - dl_lib_free(net_boxes->score); - dl_lib_free(net_boxes->box); - if (net_boxes->landmark != NULL) - dl_lib_free(net_boxes->landmark); - dl_lib_free(net_boxes); + draw_face_boxes(&rfb, &results, face_id); } - if (!fmt2jpg(image_matrix->item, fb->width * fb->height * 3, fb->width, fb->height, PIXFORMAT_RGB888, 90, &_jpg_buf, &_jpg_buf_len)) - { + s = fmt2jpg(out_buf, out_len, out_width, out_height, PIXFORMAT_RGB888, 90, &_jpg_buf, &_jpg_buf_len); + free(out_buf); + if (!s) { ESP_LOGE(TAG, "fmt2jpg failed"); + res = ESP_FAIL; } - esp_camera_fb_return(fb); - fb = NULL; + fr_encode = esp_timer_get_time(); } - else - { - _jpg_buf = fb->buf; - _jpg_buf_len = fb->len; - } - fr_encode = esp_timer_get_time(); } - dl_matrix3du_free(image_matrix); } } #endif @@ -631,6 +705,7 @@ static esp_err_t stream_handler(httpd_req_t *req) } if (res != ESP_OK) { + ESP_LOGE(TAG, "send frame failed failed"); break; } int64_t fr_end = esp_timer_get_time(); @@ -785,8 +860,10 @@ static esp_err_t cmd_handler(httpd_req_t *req) #endif } #if CONFIG_ESP_FACE_RECOGNITION_ENABLED - else if (!strcmp(variable, "face_enroll")) - is_enrolling = val; + else if (!strcmp(variable, "face_enroll")){ + is_enrolling = !is_enrolling; + ESP_LOGI(TAG, "Enrolling: %s", is_enrolling?"true":"false"); + } else if (!strcmp(variable, "face_recognize")) { recognition_enabled = val; if (recognition_enabled) { @@ -1151,26 +1228,11 @@ void startCameraServer() ra_filter_init(&ra_filter, 20); -#if CONFIG_ESP_FACE_DETECT_ENABLED - - mtmn_config.type = FAST; - mtmn_config.min_face = 80; - mtmn_config.pyramid = 0.707; - mtmn_config.pyramid_times = 4; - mtmn_config.p_threshold.score = 0.6; - mtmn_config.p_threshold.nms = 0.7; - mtmn_config.p_threshold.candidate_number = 20; - mtmn_config.r_threshold.score = 0.7; - mtmn_config.r_threshold.nms = 0.7; - mtmn_config.r_threshold.candidate_number = 10; - mtmn_config.o_threshold.score = 0.7; - mtmn_config.o_threshold.nms = 0.7; - mtmn_config.o_threshold.candidate_number = 1; - #if CONFIG_ESP_FACE_RECOGNITION_ENABLED - face_id_init(&id_list, FACE_ID_SAVE_NUMBER, ENROLL_CONFIRM_TIMES); -#endif + recognizer.set_partition(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, "fr"); + // load ids from flash partition + recognizer.set_ids_from_flash(); #endif ESP_LOGI(TAG, "Starting web server on port: '%d'", config.server_port); if (httpd_start(&camera_httpd, &config) == ESP_OK) diff --git a/libraries/ESP32/examples/Camera/CameraWebServer/camera_pins.h b/libraries/ESP32/examples/Camera/CameraWebServer/camera_pins.h index 8b7e1d88c5a..e1be287fc53 100644 --- a/libraries/ESP32/examples/Camera/CameraWebServer/camera_pins.h +++ b/libraries/ESP32/examples/Camera/CameraWebServer/camera_pins.h @@ -170,6 +170,104 @@ #define HREF_GPIO_NUM 26 #define PCLK_GPIO_NUM 21 + +#elif defined(CAMERA_MODEL_ESP32_CAM_BOARD) +// The 18 pin header on the board has Y5 and Y3 swapped +#define USE_BOARD_HEADER 0 +#define PWDN_GPIO_NUM 32 +#define RESET_GPIO_NUM 33 +#define XCLK_GPIO_NUM 4 +#define SIOD_GPIO_NUM 18 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 36 +#define Y8_GPIO_NUM 19 +#define Y7_GPIO_NUM 21 +#define Y6_GPIO_NUM 39 +#if USE_BOARD_HEADER +#define Y5_GPIO_NUM 13 +#else +#define Y5_GPIO_NUM 35 +#endif +#define Y4_GPIO_NUM 14 +#if USE_BOARD_HEADER +#define Y3_GPIO_NUM 35 +#else +#define Y3_GPIO_NUM 13 +#endif +#define Y2_GPIO_NUM 34 +#define VSYNC_GPIO_NUM 5 +#define HREF_GPIO_NUM 27 +#define PCLK_GPIO_NUM 25 + +#elif defined(CAMERA_MODEL_ESP32S3_CAM_LCD) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 40 +#define SIOD_GPIO_NUM 17 +#define SIOC_GPIO_NUM 18 + +#define Y9_GPIO_NUM 39 +#define Y8_GPIO_NUM 41 +#define Y7_GPIO_NUM 42 +#define Y6_GPIO_NUM 12 +#define Y5_GPIO_NUM 3 +#define Y4_GPIO_NUM 14 +#define Y3_GPIO_NUM 47 +#define Y2_GPIO_NUM 13 +#define VSYNC_GPIO_NUM 21 +#define HREF_GPIO_NUM 38 +#define PCLK_GPIO_NUM 11 + +#elif defined(CAMERA_MODEL_ESP32S2_CAM_BOARD) +// The 18 pin header on the board has Y5 and Y3 swapped +#define USE_BOARD_HEADER 0 +#define PWDN_GPIO_NUM 1 +#define RESET_GPIO_NUM 2 +#define XCLK_GPIO_NUM 42 +#define SIOD_GPIO_NUM 41 +#define SIOC_GPIO_NUM 18 + +#define Y9_GPIO_NUM 16 +#define Y8_GPIO_NUM 39 +#define Y7_GPIO_NUM 40 +#define Y6_GPIO_NUM 15 +#if USE_BOARD_HEADER +#define Y5_GPIO_NUM 12 +#else +#define Y5_GPIO_NUM 13 +#endif +#define Y4_GPIO_NUM 5 +#if USE_BOARD_HEADER +#define Y3_GPIO_NUM 13 +#else +#define Y3_GPIO_NUM 12 +#endif +#define Y2_GPIO_NUM 14 +#define VSYNC_GPIO_NUM 38 +#define HREF_GPIO_NUM 4 +#define PCLK_GPIO_NUM 3 + +#elif defined(CAMERA_MODEL_ESP32S3_EYE) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 15 +#define SIOD_GPIO_NUM 4 +#define SIOC_GPIO_NUM 5 + +#define Y2_GPIO_NUM 11 +#define Y3_GPIO_NUM 9 +#define Y4_GPIO_NUM 8 +#define Y5_GPIO_NUM 10 +#define Y6_GPIO_NUM 12 +#define Y7_GPIO_NUM 18 +#define Y8_GPIO_NUM 17 +#define Y9_GPIO_NUM 16 + +#define VSYNC_GPIO_NUM 6 +#define HREF_GPIO_NUM 7 +#define PCLK_GPIO_NUM 13 + #else #error "Camera model not selected" #endif diff --git a/libraries/ESP32/examples/Camera/CameraWebServer/partitions.csv b/libraries/ESP32/examples/Camera/CameraWebServer/partitions.csv new file mode 100644 index 00000000000..4f76ca6d746 --- /dev/null +++ b/libraries/ESP32/examples/Camera/CameraWebServer/partitions.csv @@ -0,0 +1,5 @@ +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x5000, +otadata, data, ota, 0xe000, 0x2000, +app0, app, ota_0, 0x10000, 0x3d0000, +fr, data, , 0x3e0000, 0x20000, diff --git a/libraries/BLE/examples/BLE_server/.skip.esp32c3 b/libraries/ESP32/examples/HallSensor/.skip.esp32s3 similarity index 100% rename from libraries/BLE/examples/BLE_server/.skip.esp32c3 rename to libraries/ESP32/examples/HallSensor/.skip.esp32s3 diff --git a/libraries/BLE/examples/BLE_server_multiconnect/.skip.esp32c3 b/libraries/ESP32/examples/I2S/HiFreq_ADC/.skip.esp32s3 similarity index 100% rename from libraries/BLE/examples/BLE_server_multiconnect/.skip.esp32c3 rename to libraries/ESP32/examples/I2S/HiFreq_ADC/.skip.esp32s3 diff --git a/libraries/ESP32/examples/RMT/RMTCallback/RMTCallback.ino b/libraries/ESP32/examples/RMT/RMTCallback/RMTCallback.ino index 7fd56d8a453..de28da6c85d 100644 --- a/libraries/ESP32/examples/RMT/RMTCallback/RMTCallback.ino +++ b/libraries/ESP32/examples/RMT/RMTCallback/RMTCallback.ino @@ -12,7 +12,10 @@ class MyProcessor { public: MyProcessor(uint8_t pin, float nanoTicks) { - assert((rmt_recv = rmtInit(21, RMT_RX_MODE, RMT_MEM_192))); + if ((rmt_recv = rmtInit(pin, RMT_RX_MODE, RMT_MEM_192)) == NULL) + { + Serial.println("init receiver failed\n"); + } realNanoTick = rmtSetTick(rmt_recv, nanoTicks); }; @@ -59,6 +62,6 @@ void setup() void loop() { - Serial.printf("GPIO 4: %08x 5: %08x 6: %08x\n", mp1.val(), mp2.val(), mp3.val()); + Serial.printf("GPIO 4: %08x 5: %08x 10: %08x\n", mp1.val(), mp2.val(), mp3.val()); delay(500); } \ No newline at end of file diff --git a/libraries/ESP32/examples/RMT/RMTWriteNeoPixel/RMTWriteNeoPixel.ino b/libraries/ESP32/examples/RMT/RMTWriteNeoPixel/RMTWriteNeoPixel.ino index 094e5f0fc1d..11f659f8895 100644 --- a/libraries/ESP32/examples/RMT/RMTWriteNeoPixel/RMTWriteNeoPixel.ino +++ b/libraries/ESP32/examples/RMT/RMTWriteNeoPixel/RMTWriteNeoPixel.ino @@ -5,6 +5,17 @@ #include "esp32-hal.h" +// The effect seen in ESP32C3, ESP32S2 and ESP32S3 is like a Blink of RGB LED +#if CONFIG_IDF_TARGET_ESP32S2 +#define BUILTIN_RGBLED_PIN 18 +#elif CONFIG_IDF_TARGET_ESP32S3 +#define BUILTIN_RGBLED_PIN 48 +#elif CONFIG_IDF_TARGET_ESP32C3 +#define BUILTIN_RGBLED_PIN 8 +#else +#define BUILTIN_RGBLED_PIN 21 // ESP32 has no builtin RGB LED +#endif + #define NR_OF_LEDS 8*4 #define NR_OF_ALL_BITS 24*NR_OF_LEDS @@ -41,7 +52,7 @@ void setup() { Serial.begin(115200); - if ((rmt_send = rmtInit(18, RMT_TX_MODE, RMT_MEM_64)) == NULL) + if ((rmt_send = rmtInit(BUILTIN_RGBLED_PIN, RMT_TX_MODE, RMT_MEM_64)) == NULL) { Serial.println("init sender failed\n"); } diff --git a/libraries/ESP32/examples/ResetReason/ResetReason.ino b/libraries/ESP32/examples/ResetReason/ResetReason.ino index 628895874ae..608edde31e0 100644 --- a/libraries/ESP32/examples/ResetReason/ResetReason.ino +++ b/libraries/ESP32/examples/ResetReason/ResetReason.ino @@ -19,6 +19,8 @@ #include "esp32s2/rom/rtc.h" #elif CONFIG_IDF_TARGET_ESP32C3 #include "esp32c3/rom/rtc.h" +#elif CONFIG_IDF_TARGET_ESP32S3 +#include "esp32s3/rom/rtc.h" #else #error Target CONFIG_IDF_TARGET is not supported #endif diff --git a/libraries/ESP32/examples/Time/SimpleTime/SimpleTime.ino b/libraries/ESP32/examples/Time/SimpleTime/SimpleTime.ino index 988c2a4d83b..427deb014de 100644 --- a/libraries/ESP32/examples/Time/SimpleTime/SimpleTime.ino +++ b/libraries/ESP32/examples/Time/SimpleTime/SimpleTime.ino @@ -1,27 +1,65 @@ #include #include "time.h" +#include "sntp.h" const char* ssid = "YOUR_SSID"; const char* password = "YOUR_PASS"; -const char* ntpServer = "pool.ntp.org"; +const char* ntpServer1 = "pool.ntp.org"; +const char* ntpServer2 = "time.nist.gov"; const long gmtOffset_sec = 3600; const int daylightOffset_sec = 3600; +const char* time_zone = "CET-1CEST,M3.5.0,M10.5.0/3"; // TimeZone rule for Europe/Rome including daylight adjustment rules (optional) + void printLocalTime() { struct tm timeinfo; if(!getLocalTime(&timeinfo)){ - Serial.println("Failed to obtain time"); + Serial.println("No time available (yet)"); return; } Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S"); } +// Callback function (get's called when time adjusts via NTP) +void timeavailable(struct timeval *t) +{ + Serial.println("Got time adjustment from NTP!"); + printLocalTime(); +} + void setup() { Serial.begin(115200); - + + // set notification call-back function + sntp_set_time_sync_notification_cb( timeavailable ); + + /** + * NTP server address could be aquired via DHCP, + * + * NOTE: This call should be made BEFORE esp32 aquires IP address via DHCP, + * otherwise SNTP option 42 would be rejected by default. + * NOTE: configTime() function call if made AFTER DHCP-client run + * will OVERRIDE aquired NTP server address + */ + sntp_servermode_dhcp(1); // (optional) + + /** + * This will set configured ntp servers and constant TimeZone/daylightOffset + * should be OK if your time zone does not need to adjust daylightOffset twice a year, + * in such a case time adjustment won't be handled automagicaly. + */ + configTime(gmtOffset_sec, daylightOffset_sec, ntpServer1, ntpServer2); + + /** + * A more convenient approach to handle TimeZones with daylightOffset + * would be to specify a environmnet variable with TimeZone definition including daylight adjustmnet rules. + * A list of rules for your zone could be obtained from https://github.com/esp8266/Arduino/blob/master/cores/esp8266/TZ.h + */ + //configTzTime(time_zone, ntpServer1, ntpServer2); + //connect to WiFi Serial.printf("Connecting to %s ", ssid); WiFi.begin(ssid, password); @@ -30,18 +68,11 @@ void setup() Serial.print("."); } Serial.println(" CONNECTED"); - - //init and get the time - configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); - printLocalTime(); - //disconnect WiFi as it's no longer needed - WiFi.disconnect(true); - WiFi.mode(WIFI_OFF); } void loop() { - delay(1000); - printLocalTime(); + delay(5000); + printLocalTime(); // it will take some time to sync time :) } diff --git a/libraries/BLE/examples/BLE_uart/.skip.esp32c3 b/libraries/ESP32/examples/Touch/TouchButton/.skip.esp32c3 similarity index 100% rename from libraries/BLE/examples/BLE_uart/.skip.esp32c3 rename to libraries/ESP32/examples/Touch/TouchButton/.skip.esp32c3 diff --git a/libraries/RainMaker/examples/RMakerSonoffDualR3/.skip.esp32s2 b/libraries/ESP32/examples/Touch/TouchButton/.skip.esp32s2 similarity index 100% rename from libraries/RainMaker/examples/RMakerSonoffDualR3/.skip.esp32s2 rename to libraries/ESP32/examples/Touch/TouchButton/.skip.esp32s2 diff --git a/libraries/BLE/examples/BLE_write/.skip.esp32c3 b/libraries/ESP32/examples/Touch/TouchButton/.skip.esp32s3 similarity index 100% rename from libraries/BLE/examples/BLE_write/.skip.esp32c3 rename to libraries/ESP32/examples/Touch/TouchButton/.skip.esp32s3 diff --git a/libraries/ESP32/examples/Touch/TouchButton/TouchButton.ino b/libraries/ESP32/examples/Touch/TouchButton/TouchButton.ino new file mode 100644 index 00000000000..b1dbc63fdcb --- /dev/null +++ b/libraries/ESP32/examples/Touch/TouchButton/TouchButton.ino @@ -0,0 +1,46 @@ +/* + +This is an example how to use Touch Intrrerupts +The sketh will tell when it is touched and then relesased as like a push-button + +This method based on touchInterruptSetThresholdDirection() is only available for ESP32 +*/ + +#include "Arduino.h" + +int threshold = 40; +bool touchActive = false; +bool lastTouchActive = false; +bool testingLower = true; + +void gotTouchEvent(){ + if (lastTouchActive != testingLower) { + touchActive = !touchActive; + testingLower = !testingLower; + // Touch ISR will be inverted: Lower <--> Higher than the Threshold after ISR event is noticed + touchInterruptSetThresholdDirection(testingLower); + } +} + +void setup() { + Serial.begin(115200); + delay(1000); // give me time to bring up serial monitor + Serial.println("ESP32 Touch Interrupt Test"); + touchAttachInterrupt(T2, gotTouchEvent, threshold); + + // Touch ISR will be activated when touchRead is lower than the Threshold + touchInterruptSetThresholdDirection(testingLower); +} + +void loop(){ + if(lastTouchActive != touchActive){ + lastTouchActive = touchActive; + if (touchActive) { + Serial.println(" ---- Touch was Pressed"); + } else { + Serial.println(" ---- Touch was Released"); + } + } + Serial.printf("T2 pin2 = %d \n", touchRead(T2)); + delay(125); +} diff --git a/libraries/LittleFS/examples/LITTLEFS_test/.skip.esp32c3 b/libraries/ESP32/examples/Touch/TouchButtonV2/.skip.esp32 similarity index 100% rename from libraries/LittleFS/examples/LITTLEFS_test/.skip.esp32c3 rename to libraries/ESP32/examples/Touch/TouchButtonV2/.skip.esp32 diff --git a/libraries/LittleFS/examples/LITTLEFS_time/.skip.esp32c3 b/libraries/ESP32/examples/Touch/TouchButtonV2/.skip.esp32c3 similarity index 100% rename from libraries/LittleFS/examples/LITTLEFS_time/.skip.esp32c3 rename to libraries/ESP32/examples/Touch/TouchButtonV2/.skip.esp32c3 diff --git a/libraries/ESP32/examples/Touch/TouchButtonV2/TouchButtonV2.ino b/libraries/ESP32/examples/Touch/TouchButtonV2/TouchButtonV2.ino new file mode 100644 index 00000000000..640fd2d3b59 --- /dev/null +++ b/libraries/ESP32/examples/Touch/TouchButtonV2/TouchButtonV2.ino @@ -0,0 +1,53 @@ +/* + +This is an example how to use Touch Intrrerupts +The sketh will tell when it is touched and then relesased as like a push-button + +This method based on touchInterruptGetLastStatus() is only available for ESP32 S2 and S3 +*/ + +#include "Arduino.h" + +int threshold = 1500; // ESP32S2 +bool touch1detected = false; +bool touch2detected = false; + +void gotTouch1() { + touch1detected = true; +} + +void gotTouch2() { + touch2detected = true; +} + +void setup() { + Serial.begin(115200); + delay(1000); // give me time to bring up serial monitor + + Serial.println("\n ESP32 Touch Interrupt Test\n"); + touchAttachInterrupt(T1, gotTouch1, threshold); + touchAttachInterrupt(T2, gotTouch2, threshold); +} + +void loop() { + static uint32_t count = 0; + + if (touch1detected) { + touch1detected = false; + if (touchInterruptGetLastStatus(T1)) { + Serial.println(" --- T1 Touched"); + } else { + Serial.println(" --- T1 Released"); + } + } + if (touch2detected) { + touch2detected = false; + if (touchInterruptGetLastStatus(T2)) { + Serial.println(" --- T2 Touched"); + } else { + Serial.println(" --- T2 Released"); + } + } + + delay(80); +} diff --git a/libraries/RainMaker/examples/RMakerCustom/.skip.esp32c3 b/libraries/Ethernet/examples/ETH_LAN8720/.skip.esp32c3 similarity index 100% rename from libraries/RainMaker/examples/RMakerCustom/.skip.esp32c3 rename to libraries/Ethernet/examples/ETH_LAN8720/.skip.esp32c3 diff --git a/libraries/RainMaker/examples/RMakerSonoffDualR3/.skip.esp32c3 b/libraries/Ethernet/examples/ETH_LAN8720/.skip.esp32s3 similarity index 100% rename from libraries/RainMaker/examples/RMakerSonoffDualR3/.skip.esp32c3 rename to libraries/Ethernet/examples/ETH_LAN8720/.skip.esp32s3 diff --git a/libraries/RainMaker/examples/RMakerSwitch/.skip.esp32c3 b/libraries/Ethernet/examples/ETH_TLK110/.skip.esp32c3 similarity index 100% rename from libraries/RainMaker/examples/RMakerSwitch/.skip.esp32c3 rename to libraries/Ethernet/examples/ETH_TLK110/.skip.esp32c3 diff --git a/libraries/RainMaker/examples/RMakerSwitch/.skip.esp32s2 b/libraries/Ethernet/examples/ETH_TLK110/.skip.esp32s3 similarity index 100% rename from libraries/RainMaker/examples/RMakerSwitch/.skip.esp32s2 rename to libraries/Ethernet/examples/ETH_TLK110/.skip.esp32s3 diff --git a/libraries/Ethernet/src/ETH.cpp b/libraries/Ethernet/src/ETH.cpp index 851eb846170..86c804fd6e5 100644 --- a/libraries/Ethernet/src/ETH.cpp +++ b/libraries/Ethernet/src/ETH.cpp @@ -123,7 +123,7 @@ static esp_err_t on_lowlevel_init_done(esp_eth_handle_t eth_handle){ //gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_EMAC_TX_CLK); //PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[0]); pinMode(0, INPUT); - pinMode(0, FUNCTION_6); + PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[0], 5); EMAC_EXT.ex_clk_ctrl.ext_en = 1; EMAC_EXT.ex_clk_ctrl.int_en = 0; EMAC_EXT.ex_oscclk_conf.clk_sel = 1; @@ -135,7 +135,7 @@ static esp_err_t on_lowlevel_init_done(esp_eth_handle_t eth_handle){ //gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1); //PIN_INPUT_DISABLE(GPIO_PIN_MUX_REG[0]); pinMode(0, OUTPUT); - pinMode(0, FUNCTION_2); + PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[0], 1); // Choose the APLL clock to output on GPIO REG_WRITE(PIN_CTRL, 6); #endif @@ -145,7 +145,7 @@ static esp_err_t on_lowlevel_init_done(esp_eth_handle_t eth_handle){ //gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO16_U, FUNC_GPIO16_EMAC_CLK_OUT); //PIN_INPUT_DISABLE(GPIO_PIN_MUX_REG[16]); pinMode(16, OUTPUT); - pinMode(16, FUNCTION_6); + PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[16], 5); #endif } else if(eth_clock_mode == ETH_CLOCK_GPIO17_OUT){ #if CONFIG_ETH_RMII_CLK_OUT_GPIO != 17 @@ -153,7 +153,7 @@ static esp_err_t on_lowlevel_init_done(esp_eth_handle_t eth_handle){ //gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO17_U, FUNC_GPIO17_EMAC_CLK_OUT_180); //PIN_INPUT_DISABLE(GPIO_PIN_MUX_REG[17]); pinMode(17, OUTPUT); - pinMode(17, FUNCTION_6); + PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[17], 5); #endif } #if CONFIG_ETH_RMII_CLK_INPUT @@ -226,12 +226,19 @@ ETHClass::ETHClass() ETHClass::~ETHClass() {} -bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_type_t type, eth_clock_mode_t clock_mode) +bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_type_t type, eth_clock_mode_t clock_mode, bool use_mac_from_efuse) { #if ESP_IDF_VERSION_MAJOR > 3 eth_clock_mode = clock_mode; tcpipInit(); + if (use_mac_from_efuse) + { + uint8_t p[6] = { 0x00,0x00,0x00,0x00,0x00,0x00 }; + esp_efuse_mac_get_custom(p); + esp_base_mac_addr_set(p); + } + tcpip_adapter_set_default_eth_handlers(); esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH(); @@ -245,6 +252,8 @@ bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_typ #endif #if CONFIG_ETH_USE_ESP32_EMAC eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); + mac_config.clock_config.rmii.clock_mode = (eth_clock_mode) ? EMAC_CLK_OUT : EMAC_CLK_EXT_IN; + mac_config.clock_config.rmii.clock_gpio = (1 == eth_clock_mode) ? EMAC_APPL_CLK_OUT_GPIO : (2 == eth_clock_mode) ? EMAC_CLK_OUT_GPIO : (3 == eth_clock_mode) ? EMAC_CLK_OUT_180_GPIO : EMAC_CLK_IN_GPIO; mac_config.smi_mdc_gpio_num = mdc; mac_config.smi_mdio_gpio_num = mdio; mac_config.sw_reset_timeout_ms = 1000; @@ -281,6 +290,13 @@ bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_typ eth_phy = esp_eth_phy_new_dm9051(&phy_config); break; #endif + case ETH_PHY_KSZ8041: +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4,4,0) + eth_phy = esp_eth_phy_new_ksz8041(&phy_config); +#else + log_e("unsupported ethernet type 'ETH_PHY_KSZ8041'"); +#endif + break; case ETH_PHY_KSZ8081: #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4,4,0) eth_phy = esp_eth_phy_new_ksz8081(&phy_config); @@ -298,7 +314,7 @@ bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_typ eth_handle = NULL; esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(eth_mac, eth_phy); - eth_config.on_lowlevel_init_done = on_lowlevel_init_done; + //eth_config.on_lowlevel_init_done = on_lowlevel_init_done; //eth_config.on_lowlevel_deinit_done = on_lowlevel_deinit_done; if(esp_eth_driver_install(ð_config, ð_handle) != ESP_OK || eth_handle == NULL){ log_e("esp_eth_driver_install failed"); @@ -354,6 +370,14 @@ bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_typ } tcpipInit(); + + if (use_mac_from_efuse) + { + uint8_t p[6] = { 0x00,0x00,0x00,0x00,0x00,0x00 }; + esp_efuse_mac_get_custom(p); + esp_base_mac_addr_set(p); + } + err = esp_eth_init(ð_config); if(!err){ initialized = true; @@ -379,7 +403,7 @@ bool ETHClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, I { esp_err_t err = ESP_OK; tcpip_adapter_ip_info_t info; - + if(local_ip != (uint32_t)0x00000000 && local_ip != INADDR_NONE){ info.ip.addr = static_cast(local_ip); info.gw.addr = static_cast(gateway); diff --git a/libraries/Ethernet/src/ETH.h b/libraries/Ethernet/src/ETH.h index 918cd357d94..647b59848d6 100644 --- a/libraries/Ethernet/src/ETH.h +++ b/libraries/Ethernet/src/ETH.h @@ -53,7 +53,7 @@ typedef enum { ETH_CLOCK_GPIO0_IN, ETH_CLOCK_GPIO0_OUT, ETH_CLOCK_GPIO16_OUT, ETH_CLOCK_GPIO17_OUT } eth_clock_mode_t; #endif -typedef enum { ETH_PHY_LAN8720, ETH_PHY_TLK110, ETH_PHY_RTL8201, ETH_PHY_DP83848, ETH_PHY_DM9051, ETH_PHY_KSZ8081, ETH_PHY_MAX } eth_phy_type_t; +typedef enum { ETH_PHY_LAN8720, ETH_PHY_TLK110, ETH_PHY_RTL8201, ETH_PHY_DP83848, ETH_PHY_DM9051, ETH_PHY_KSZ8041, ETH_PHY_KSZ8081, ETH_PHY_MAX } eth_phy_type_t; #define ETH_PHY_IP101 ETH_PHY_TLK110 class ETHClass { @@ -75,7 +75,7 @@ class ETHClass { ETHClass(); ~ETHClass(); - bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); + bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE, bool use_mac_from_efuse=false); bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000); diff --git a/libraries/FFat/examples/FFat_time/FFat_time.ino b/libraries/FFat/examples/FFat_time/FFat_time.ino index 090a3bbc767..475cfea026b 100644 --- a/libraries/FFat/examples/FFat_time/FFat_time.ino +++ b/libraries/FFat/examples/FFat_time/FFat_time.ino @@ -148,10 +148,6 @@ void setup(){ Serial.println("IP address: "); Serial.println(WiFi.localIP()); Serial.println("Contacting Time Server"); - /* - Note: Bundled Arduino lwip supports only ONE ntp server, 2nd and 3rd options are silently ignored - see CONFIG_LWIP_DHCP_MAX_NTP_SERVERS define in ./tools/sdk/esp32/sdkconfig - */ configTime(3600*timezone, daysavetime*3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org"); struct tm tmstruct ; delay(2000); diff --git a/libraries/FS/src/FS.cpp b/libraries/FS/src/FS.cpp index f5e9a8ab2cc..80d0958a759 100644 --- a/libraries/FS/src/FS.cpp +++ b/libraries/FS/src/FS.cpp @@ -130,6 +130,15 @@ size_t File::size() const return _p->size(); } +bool File::setBufferSize(size_t size) +{ + if (!*this) { + return 0; + } + + return _p->setBufferSize(size); +} + void File::close() { if (_p) { diff --git a/libraries/FS/src/FS.h b/libraries/FS/src/FS.h index c3a1c51c5ec..64e630c4577 100644 --- a/libraries/FS/src/FS.h +++ b/libraries/FS/src/FS.h @@ -70,6 +70,7 @@ class File : public Stream } size_t position() const; size_t size() const; + bool setBufferSize(size_t size); void close(); operator bool() const; time_t getLastWrite(); diff --git a/libraries/FS/src/FSImpl.h b/libraries/FS/src/FSImpl.h index 4c5c9786840..bb20cd499ae 100644 --- a/libraries/FS/src/FSImpl.h +++ b/libraries/FS/src/FSImpl.h @@ -36,6 +36,7 @@ class FileImpl virtual bool seek(uint32_t pos, SeekMode mode) = 0; virtual size_t position() const = 0; virtual size_t size() const = 0; + virtual bool setBufferSize(size_t size) = 0; virtual void close() = 0; virtual time_t getLastWrite() = 0; virtual const char* path() const = 0; diff --git a/libraries/FS/src/vfs_api.cpp b/libraries/FS/src/vfs_api.cpp index e43b4397452..25a27c70bcf 100644 --- a/libraries/FS/src/vfs_api.cpp +++ b/libraries/FS/src/vfs_api.cpp @@ -16,6 +16,8 @@ using namespace fs; +#define DEFAULT_FILE_BUFFER_SIZE 4096 + FileImplPtr VFSImpl::open(const char* fpath, const char* mode, const bool create) { if(!_mountpoint) { @@ -280,6 +282,10 @@ VFSFileImpl::VFSFileImpl(VFSImpl* fs, const char* fpath, const char* mode) if(!_f) { log_e("fopen(%s) failed", temp); } + if(_f && (_stat.st_blksize == 0)) + { + setvbuf(_f,NULL,_IOFBF,DEFAULT_FILE_BUFFER_SIZE); + } } else if(S_ISDIR(_stat.st_mode)) { _isDirectory = true; _d = opendir(temp); @@ -307,6 +313,10 @@ VFSFileImpl::VFSFileImpl(VFSImpl* fs, const char* fpath, const char* mode) if(!_f) { log_e("fopen(%s) failed", temp); } + if(_f && (_stat.st_blksize == 0)) + { + setvbuf(_f,NULL,_IOFBF,DEFAULT_FILE_BUFFER_SIZE); + } } } free(temp); @@ -415,6 +425,19 @@ size_t VFSFileImpl::size() const return _stat.st_size; } +/* +* Change size of files internal buffer used for read / write operations. +* Need to be called right after opening file before any other operation! +*/ +bool VFSFileImpl::setBufferSize(size_t size) +{ + if(_isDirectory || !_f) { + return 0; + } + int res = setvbuf(_f,NULL,_IOFBF,size); + return res == 0; +} + const char* VFSFileImpl::path() const { return (const char*) _path; diff --git a/libraries/FS/src/vfs_api.h b/libraries/FS/src/vfs_api.h index f79852cdcfe..780c334aa5c 100644 --- a/libraries/FS/src/vfs_api.h +++ b/libraries/FS/src/vfs_api.h @@ -65,10 +65,11 @@ class VFSFileImpl : public FileImpl bool seek(uint32_t pos, SeekMode mode) override; size_t position() const override; size_t size() const override; + bool setBufferSize(size_t size); void close() override; const char* path() const override; const char* name() const override; - time_t getLastWrite() override; + time_t getLastWrite() override; boolean isDirectory(void) override; FileImplPtr openNextFile(const char* mode) override; void rewindDirectory(void) override; diff --git a/libraries/HTTPClient/src/HTTPClient.cpp b/libraries/HTTPClient/src/HTTPClient.cpp index a7bf13e89f5..7e967be9f35 100644 --- a/libraries/HTTPClient/src/HTTPClient.cpp +++ b/libraries/HTTPClient/src/HTTPClient.cpp @@ -39,6 +39,9 @@ #include "HTTPClient.h" +/// Cookie jar support +#include + #ifdef HTTPCLIENT_1_1_COMPATIBLE class TransportTraits { @@ -157,6 +160,7 @@ bool HTTPClient::begin(WiFiClient &client, String url) { } _port = (protocol == "https" ? 443 : 80); + _secure = (protocol == "https"); return beginInternal(url, protocol.c_str()); } @@ -187,6 +191,7 @@ bool HTTPClient::begin(WiFiClient &client, String host, uint16_t port, String ur _port = port; _uri = uri; _protocol = (https ? "https" : "http"); + _secure = https; return true; } @@ -255,7 +260,7 @@ bool HTTPClient::beginInternal(String url, const char* expectedProtocol) _protocol = url.substring(0, index); if (_protocol != expectedProtocol) { - log_w("unexpected protocol: %s, expected %s", _protocol.c_str(), expectedProtocol); + log_d("unexpected protocol: %s, expected %s", _protocol.c_str(), expectedProtocol); return false; } @@ -381,9 +386,7 @@ void HTTPClient::disconnect(bool preserveClient) if(connected()) { if(_client->available() > 0) { log_d("still data in buffer (%d), clean up.\n", _client->available()); - while(_client->available() > 0) { - _client->read(); - } + _client->flush(); } if(_reuse && _canReuse) { @@ -603,6 +606,12 @@ int HTTPClient::sendRequest(const char * type, uint8_t * payload, size_t size) addHeader(F("Content-Length"), String(size)); } + // add cookies to header, if present + String cookie_string; + if(generateCookieString(&cookie_string)) { + addHeader("Cookie", cookie_string); + } + // send Header if(!sendHeader(type)) { return returnError(HTTPC_ERROR_SEND_HEADER_FAILED); @@ -706,6 +715,12 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size) addHeader("Content-Length", String(size)); } + // add cookies to header, if present + String cookie_string; + if(generateCookieString(&cookie_string)) { + addHeader("Cookie", cookie_string); + } + // send Header if(!sendHeader(type)) { return returnError(HTTPC_ERROR_SEND_HEADER_FAILED); @@ -1222,6 +1237,7 @@ int HTTPClient::handleHeaderResponse() _transferEncoding = HTTPC_TE_IDENTITY; unsigned long lastDataTime = millis(); bool firstLine = true; + String date; while(connected()) { size_t len = _client->available(); @@ -1234,7 +1250,7 @@ int HTTPClient::handleHeaderResponse() log_v("RX: '%s'", headerLine.c_str()); if(firstLine) { - firstLine = false; + firstLine = false; if(_canReuse && headerLine.startsWith("HTTP/1.")) { _canReuse = (headerLine[sizeof "HTTP/1." - 1] != '0'); } @@ -1245,6 +1261,10 @@ int HTTPClient::handleHeaderResponse() String headerValue = headerLine.substring(headerLine.indexOf(':') + 1); headerValue.trim(); + if(headerName.equalsIgnoreCase("Date")) { + date = headerValue; + } + if(headerName.equalsIgnoreCase("Content-Length")) { _size = headerValue.toInt(); } @@ -1263,12 +1283,24 @@ int HTTPClient::handleHeaderResponse() _location = headerValue; } - for(size_t i = 0; i < _headerKeysCount; i++) { - if(_currentHeaders[i].key.equalsIgnoreCase(headerName)) { + if (headerName.equalsIgnoreCase("Set-Cookie")) { + setCookie(date, headerValue); + } + + for (size_t i = 0; i < _headerKeysCount; i++) { + if (_currentHeaders[i].key.equalsIgnoreCase(headerName)) { + // Uncomment the following lines if you need to add support for multiple headers with the same key: + // if (!_currentHeaders[i].value.isEmpty()) { + // // Existing value, append this one with a comma + // _currentHeaders[i].value += ','; + // _currentHeaders[i].value += headerValue; + // } else { _currentHeaders[i].value = headerValue; - break; + // } + break; // We found a match, stop looking } } + } if(headerLine == "") { @@ -1491,3 +1523,171 @@ const String &HTTPClient::getLocation(void) { return _location; } + +void HTTPClient::setCookieJar(CookieJar* cookieJar) +{ + _cookieJar = cookieJar; +} + +void HTTPClient::resetCookieJar() +{ + _cookieJar = nullptr; +} + +void HTTPClient::clearAllCookies() +{ + if (_cookieJar) _cookieJar->clear(); +} + +void HTTPClient::setCookie(String date, String headerValue) +{ + if (!_cookieJar) + { + return; + } + #define HTTP_TIME_PATTERN "%a, %d %b %Y %H:%M:%S" + + Cookie cookie; + String value; + int pos1, pos2; + + headerValue.toLowerCase(); + + struct tm tm; + strptime(date.c_str(), HTTP_TIME_PATTERN, &tm); + cookie.date = mktime(&tm); + + pos1 = headerValue.indexOf('='); + pos2 = headerValue.indexOf(';'); + + if (pos1 >= 0 && pos2 > pos1){ + cookie.name = headerValue.substring(0, pos1); + cookie.value = headerValue.substring(pos1 + 1, pos2); + } else { + return; // invalid cookie header + } + + // expires + if (headerValue.indexOf("expires=") >= 0){ + pos1 = headerValue.indexOf("expires=") + strlen("expires="); + pos2 = headerValue.indexOf(';', pos1); + + if (pos2 > pos1) + value = headerValue.substring(pos1, pos2); + else + value = headerValue.substring(pos1); + + strptime(value.c_str(), HTTP_TIME_PATTERN, &tm); + cookie.expires.date = mktime(&tm); + cookie.expires.valid = true; + } + + // max-age + if (headerValue.indexOf("max-age=") >= 0){ + pos1 = headerValue.indexOf("max-age=") + strlen("max-age="); + pos2 = headerValue.indexOf(';', pos1); + + if (pos2 > pos1) + value = headerValue.substring(pos1, pos2); + else + value = headerValue.substring(pos1); + + cookie.max_age.duration = value.toInt(); + cookie.max_age.valid = true; + } + + // domain + if (headerValue.indexOf("domain=") >= 0){ + pos1 = headerValue.indexOf("domain=") + strlen("domain="); + pos2 = headerValue.indexOf(';', pos1); + + if (pos2 > pos1) + value = headerValue.substring(pos1, pos2); + else + value = headerValue.substring(pos1); + + if (value.startsWith(".")) value.remove(0, 1); + + if (_host.indexOf(value) >= 0) { + cookie.domain = value; + } else { + return; // server tries to set a cookie on a different domain; ignore it + } + } else { + pos1 = _host.lastIndexOf('.', _host.lastIndexOf('.') - 1); + if (pos1 >= 0) + cookie.domain = _host.substring(pos1 + 1); + else + cookie.domain = _host; + } + + // path + if (headerValue.indexOf("path=") >= 0){ + pos1 = headerValue.indexOf("path=") + strlen("path="); + pos2 = headerValue.indexOf(';', pos1); + + if (pos2 > pos1) + cookie.path = headerValue.substring(pos1, pos2); + else + cookie.path = headerValue.substring(pos1); + } + + // HttpOnly + cookie.http_only = (headerValue.indexOf("httponly") >= 0); + + // secure + cookie.secure = (headerValue.indexOf("secure") >= 0); + + // overwrite or delete cookie in/from cookie jar + time_t now_local = time(NULL); + time_t now_gmt = mktime(gmtime(&now_local)); + + bool found = false; + + for (auto c = _cookieJar->begin(); c != _cookieJar->end(); ++c) { + if (c->domain == cookie.domain && c->name == cookie.name) { + // when evaluating, max-age takes precedence over expires if both are defined + if ((cookie.max_age.valid && ((cookie.date + cookie.max_age.duration) < now_gmt)) || cookie.max_age.duration <= 0 + || (!cookie.max_age.valid && cookie.expires.valid && cookie.expires.date < now_gmt)) { + _cookieJar->erase(c); + c--; + } else { + *c = cookie; + } + found = true; + } + } + + // add cookie to jar + if (!found && !(cookie.max_age.valid && cookie.max_age.duration <= 0)) + _cookieJar->push_back(cookie); + +} + +bool HTTPClient::generateCookieString(String *cookieString) +{ + time_t now_local = time(NULL); + time_t now_gmt = mktime(gmtime(&now_local)); + + *cookieString = ""; + bool found = false; + + if (!_cookieJar) + { + return false; + } + for (auto c = _cookieJar->begin(); c != _cookieJar->end(); ++c) { + if ((c->max_age.valid && ((c->date + c->max_age.duration) < now_gmt)) || (!c->max_age.valid && c->expires.valid && c->expires.date < now_gmt)) { + _cookieJar->erase(c); + c--; + } else if (_host.indexOf(c->domain) >= 0 && (!c->secure || _secure) ) { + if (*cookieString == "") + *cookieString = c->name + "=" + c->value; + else + *cookieString += " ;" + c->name + "=" + c->value; + found = true; + } + } + + return found; +} diff --git a/libraries/HTTPClient/src/HTTPClient.h b/libraries/HTTPClient/src/HTTPClient.h index 1bb84d6d6b5..6a17c0e65f5 100644 --- a/libraries/HTTPClient/src/HTTPClient.h +++ b/libraries/HTTPClient/src/HTTPClient.h @@ -27,13 +27,18 @@ #ifndef HTTPClient_H_ #define HTTPClient_H_ +#ifndef HTTPCLIENT_1_1_COMPATIBLE #define HTTPCLIENT_1_1_COMPATIBLE +#endif #include #include #include #include +/// Cookie jar support +#include + #define HTTPCLIENT_DEFAULT_TCP_TIMEOUT (5000) /// HTTP client errors @@ -142,6 +147,28 @@ class TransportTraits; typedef std::unique_ptr TransportTraitsPtr; #endif +// cookie jar support +typedef struct { + String host; // host which tries to set the cookie + time_t date; // timestamp of the response that set the cookie + String name; + String value; + String domain; + String path = ""; + struct { + time_t date = 0; + bool valid = false; + } expires; + struct { + time_t duration = 0; + bool valid = false; + } max_age; + bool http_only = false; + bool secure = false; +} Cookie; +typedef std::vector CookieJar; + + class HTTPClient { public: @@ -215,6 +242,11 @@ class HTTPClient static String errorToString(int error); + /// Cookie jar support + void setCookieJar(CookieJar* cookieJar); + void resetCookieJar(); + void clearAllCookies(); + protected: struct RequestArgument { String key; @@ -230,6 +262,9 @@ class HTTPClient int handleHeaderResponse(); int writeToStreamDataBlock(Stream * stream, int len); + /// Cookie jar support + void setCookie(String date, String headerValue); + bool generateCookieString(String *cookieString); #ifdef HTTPCLIENT_1_1_COMPATIBLE TransportTraitsPtr _transportTraits; @@ -241,7 +276,7 @@ class HTTPClient /// request handling String _host; uint16_t _port = 0; - int32_t _connectTimeout = -1; + int32_t _connectTimeout = HTTPCLIENT_DEFAULT_TCP_TIMEOUT; bool _reuse = true; uint16_t _tcpTimeout = HTTPCLIENT_DEFAULT_TCP_TIMEOUT; bool _useHTTP10 = false; @@ -265,6 +300,10 @@ class HTTPClient uint16_t _redirectLimit = 10; String _location; transferEncoding_t _transferEncoding = HTTPC_TE_IDENTITY; + + /// Cookie jar support + CookieJar* _cookieJar = nullptr; + }; diff --git a/libraries/HTTPUpdate/examples/httpUpdateSecure/httpUpdateSecure.ino b/libraries/HTTPUpdate/examples/httpUpdateSecure/httpUpdateSecure.ino index cff8f45cec9..1c85ace02a5 100644 --- a/libraries/HTTPUpdate/examples/httpUpdateSecure/httpUpdateSecure.ino +++ b/libraries/HTTPUpdate/examples/httpUpdateSecure/httpUpdateSecure.ino @@ -17,10 +17,6 @@ WiFiMulti WiFiMulti; // Set time via NTP, as required for x.509 validation void setClock() { - /* - Note: Bundled Arduino lwip supports only ONE ntp server, 2nd and 3rd options are silently ignored - see CONFIG_LWIP_DHCP_MAX_NTP_SERVERS define in ./tools/sdk/esp32/sdkconfig - */ configTime(0, 0, "pool.ntp.org", "time.nist.gov"); // UTC Serial.print(F("Waiting for NTP time sync: ")); diff --git a/libraries/I2S/examples/ADCPlotter/.skip.esp32c3 b/libraries/I2S/examples/ADCPlotter/.skip.esp32c3 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/I2S/examples/ADCPlotter/ADCPlotter.ino b/libraries/I2S/examples/ADCPlotter/ADCPlotter.ino new file mode 100644 index 00000000000..5f3bd93ca9d --- /dev/null +++ b/libraries/I2S/examples/ADCPlotter/ADCPlotter.ino @@ -0,0 +1,86 @@ +/* + This example is only for ESP devices. + + This example demonstrates usage of integrated Digital to Analog Converter (DAC) + You can display sound wave from audio device, or just measure voltage. + + To display audio prepare circuit found in following link or drafted as ASCII art + https://forum.arduino.cc/index.php?topic=567581.0 + (!) Note that unlike in the link we are connecting the supply line to 3.3V (not 5V) + because ADC can measure only up to around 3V. Anything above 3V will be very inaccurate. + + ^ +3.3V + | + _ + | |10k + |_| + | | |10uF + GPIO34-------------*------------| |----------- line in +(Default ADC pin) | +| | + | + _ + | |10k + |_| + | + | + V GND + +Connect hot wire of your audio to Line in and GNd wire of audio cable to common ground (GND) + +Second option to measure voltage on trimmer / potentiometer has following connection + ^ +3.3V + | + _ + | | + GPIO34----------->| | +(Default ADC pin) |_| + | + | + _ + | | optional resistor + |_| + | + | + V GND + Optional resistor will decrease read value. + + Steps to run: + 1. Select target board: + Tools -> Board -> ESP32 Arduino -> your board + 2. Upload sketch + Press upload button (arrow in top left corner) + When you see in console line like this: "Connecting........_____.....__" + On your board press and hold Boot button and press EN button shortly. Now you can release both buttons. + You should see lines like this: "Writing at 0x00010000... (12 %)" with rising percentage on each line. + If this fails, try the board buttons right after pressing upload button, or reconnect the USB cable. + 3. Open plotter + Tools -> Serial Plotter + Enjoy + +Created by Tomas Pilny +on 17th June 2021 +*/ + +#include + +void setup() { + // Open serial communications and wait for port to open: + // A baud rate of 115200 is used instead of 9600 for a faster data rate + // on non-native USB ports + Serial.begin(115200); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start I2S at 8 kHz with 32-bits per sample + if (!I2S.begin(ADC_DAC_MODE, 8000, 16)) { + Serial.println("Failed to initialize I2S!"); + while (1); // do nothing + } +} + +void loop() { + // read a sample + int sample = I2S.read(); + Serial.println(sample); +} diff --git a/libraries/I2S/examples/FullDuplex/.skip.esp32c3 b/libraries/I2S/examples/FullDuplex/.skip.esp32c3 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/I2S/examples/FullDuplex/FullDuplex.ino b/libraries/I2S/examples/FullDuplex/FullDuplex.ino new file mode 100644 index 00000000000..9b3625fbd60 --- /dev/null +++ b/libraries/I2S/examples/FullDuplex/FullDuplex.ino @@ -0,0 +1,59 @@ +/* + This example is only for ESP + This example demonstrates simultaneous usage of microphone and speaker using single I2S module. + The application transfers data from input to output + + Circuit: + * ESP32 + * GND connected GND + * VIN connected 5V + * SCK 5 + * FS 25 + * DIN 35 + * DOUT 26 + * I2S microphone + * I2S decoder + headphones / speaker + + created 8 October 2021 + by Tomas Pilny + */ + +#include +const long sampleRate = 16000; +const int bitsPerSample = 32; +uint8_t *buffer; + +void setup() { + Serial.begin(115200); + //I2S.setAllPins(5, 25, 35, 26); // you can change default pins; order of pins = (CLK, WS, IN, OUT) + if(!I2S.setDuplex()){ + Serial.println("ERROR - could not set duplex"); + while(true){ + vTaskDelay(10); // Cannot continue + } + } + if (!I2S.begin(I2S_PHILIPS_MODE, sampleRate, bitsPerSample)) { + Serial.println("Failed to initialize I2S!"); + while(true){ + vTaskDelay(10); // Cannot continue + } + } + buffer = (uint8_t*) malloc(I2S.getBufferSize() * (bitsPerSample / 8)); + if(buffer == NULL){ + Serial.println("Failed to allocate buffer!"); + while(true){ + vTaskDelay(10); // Cannot continue + } + } + Serial.println("Setup done"); +} + +void loop() { + //I2S.write(I2S.read()); // primitive implementation sample-by-sample + + // Buffer based implementation + I2S.read(buffer, I2S.getBufferSize() * (bitsPerSample / 8)); + I2S.write(buffer, I2S.getBufferSize() * (bitsPerSample / 8)); + + //optimistic_yield(1000); // yield if last yield occurred before CPU clock cycles ago +} diff --git a/libraries/I2S/examples/InputSerialPlotter/.skip.esp32c3 b/libraries/I2S/examples/InputSerialPlotter/.skip.esp32c3 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/I2S/examples/InputSerialPlotter/InputSerialPlotter.ino b/libraries/I2S/examples/InputSerialPlotter/InputSerialPlotter.ino new file mode 100644 index 00000000000..db9f7d0d4f8 --- /dev/null +++ b/libraries/I2S/examples/InputSerialPlotter/InputSerialPlotter.ino @@ -0,0 +1,44 @@ +/* + This example reads audio data from an Invensense's ICS43432 I2S microphone + breakout board, and prints out the samples to the Serial console. The + Serial Plotter built into the Arduino IDE can be used to plot the audio + data (Tools -> Serial Plotter) + + Circuit: + * Arduino/Genuino Zero, MKR family and Nano 33 IoT + * ICS43432: + * GND connected GND + * 3.3V connected to 3.3V (Zero, Nano, ESP32), VCC (MKR) + * WS connected to pin 0 (Zero) or 3 (MKR), A2 (Nano) or 25 (ESP32) + * CLK connected to pin 1 (Zero) or 2 (MKR), A3 (Nano) or 5 (ESP32) + * SD connected to pin 9 (Zero) or A6 (MKR), 4 (Nano) or 26 (ESP32) + created 17 November 2016 + by Sandeep Mistry + */ + +#include + +void setup() { + // Open serial communications and wait for port to open: + // A baud rate of 115200 is used instead of 9600 for a faster data rate + // on non-native USB ports + Serial.begin(115200); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start I2S at 8 kHz with 32-bits per sample + if (!I2S.begin(I2S_PHILIPS_MODE, 8000, 32)) { + Serial.println("Failed to initialize I2S!"); + while (1); // do nothing + } +} + +void loop() { + // read a sample + int sample = I2S.read(); + + if (sample && sample != -1 && sample != 1) { + Serial.println(sample); + } +} diff --git a/libraries/I2S/examples/SimpleTone/.skip.esp32c3 b/libraries/I2S/examples/SimpleTone/.skip.esp32c3 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/I2S/examples/SimpleTone/SimpleTone.ino b/libraries/I2S/examples/SimpleTone/SimpleTone.ino new file mode 100644 index 00000000000..dd312cf8a82 --- /dev/null +++ b/libraries/I2S/examples/SimpleTone/SimpleTone.ino @@ -0,0 +1,79 @@ +/* + This example generates a square wave based tone at a specified frequency + and sample rate. Then outputs the data using the I2S interface to a + MAX08357 I2S Amp Breakout board. + + I2S Circuit: + * Arduino/Genuino Zero, MKR family and Nano 33 IoT + * MAX08357: + * GND connected GND + * VIN connected 5V + * LRC connected to pin 0 (Zero) or 3 (MKR), A2 (Nano) or 25 (ESP32) + * BCLK connected to pin 1 (Zero) or 2 (MKR), A3 (Nano) or 5 (ESP32) + * DIN connected to pin 9 (Zero) or A6 (MKR), 4 (Nano) or 26 (ESP32) + + DAC Circuit: + * ESP32 or ESP32-S2 + * Audio amplifier + - Note: + - ESP32 has DAC on GPIO pins 25 and 26. + - ESP32-S2 has DAC on GPIO pins 17 and 18. + - Connect speaker(s) or headphones. + + created 17 November 2016 + by Sandeep Mistry + For ESP extended + Tomas Pilny + 2nd September 2021 + */ + +#include +const int frequency = 440; // frequency of square wave in Hz +const int amplitude = 500; // amplitude of square wave +const int sampleRate = 8000; // sample rate in Hz +const int bps = 16; + +const int halfWavelength = (sampleRate / frequency); // half wavelength of square wave + +short sample = amplitude; // current sample value +int count = 0; + +i2s_mode_t mode = I2S_PHILIPS_MODE; // I2S decoder is needed +// i2s_mode_t mode = ADC_DAC_MODE; // Audio amplifier is needed + +// Mono channel input +// This is ESP specific implementation - +// samples will be automatically copied to both channels inside I2S driver +// If you want to have true mono output use I2S_PHILIPS_MODE and interlay +// second channel with 0-value samples. +// The order of channels is RIGH followed by LEFT +//i2s_mode_t mode = I2S_RIGHT_JUSTIFIED_MODE; // I2S decoder is needed + +void setup() { + Serial.begin(115200); + Serial.println("I2S simple tone"); + + // start I2S at the sample rate with 16-bits per sample + if (!I2S.begin(mode, sampleRate, bps)) { + Serial.println("Failed to initialize I2S!"); + while (1); // do nothing + } +} + +void loop() { + if (count % halfWavelength == 0 ) { + // invert the sample every half wavelength count multiple to generate square wave + sample = -1 * sample; + } + + if(mode == I2S_PHILIPS_MODE || mode == ADC_DAC_MODE){ // write the same sample twice, once for Right and once for Left channel + I2S.write(sample); // Right channel + I2S.write(sample); // Left channel + }else if(mode == I2S_RIGHT_JUSTIFIED_MODE || mode == I2S_LEFT_JUSTIFIED_MODE){ + // write the same only once - it will be automatically copied to the other channel + I2S.write(sample); + } + + // increment the counter for the next sample + count++; +} diff --git a/libraries/I2S/keywords.txt b/libraries/I2S/keywords.txt new file mode 100644 index 00000000000..ad1b8028d42 --- /dev/null +++ b/libraries/I2S/keywords.txt @@ -0,0 +1,61 @@ +####################################### +# Syntax Coloring Map I2S +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +I2S KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### +I2SClass KEYWORD2 +begin KEYWORD2 +end KEYWORD2 + +onReceive KEYWORD2 +onTransmit KEYWORD2 + +setSckPin KEYWORD2 +setFsPin KEYWORD2 +setDataInPin KEYWORD2 +setDataOutPin KEYWORD2 +setAllPins KEYWORD2 + +getSckPin KEYWORD2 +getFsPin KEYWORD2 +getDataPin KEYWORD2 +getDataInPin KEYWORD2 +getDataOutPin KEYWORD2 + +setDuplex KEYWORD2 +setSimplex KEYWORD2 +isDuplex KEYWORD2 + +setBufferSize KEYWORD2 +getBufferSize KEYWORD2 + +write KEYWORD2 +availableForWrite KEYWORD2 + +read KEYWORD2 +available KEYWORD2 + +gpioToAdcUnit KEYWORD2 +gpioToAdcChannel KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### +I2S_PHILIPS_MODE LITERAL1 +I2S_RIGHT_JUSTIFIED_MODE LITERAL1 +I2S_LEFT_JUSTIFIED_MODE LITERAL1 +I2S_ADC_DAC LITERAL1 +I2S_PDM LITERAL1 + +PIN_I2S_SCK LITERAL1 +PIN_I2S_FS LITERAL1 +PIN_I2S_SD LITERAL1 +PIN_I2S_SD_OUT LITERAL1 diff --git a/libraries/I2S/library.properties b/libraries/I2S/library.properties new file mode 100644 index 00000000000..bb77e306158 --- /dev/null +++ b/libraries/I2S/library.properties @@ -0,0 +1,9 @@ +name=I2S +version=1.0 +author=Tomas Pilny +maintainer=Tomas Pilny +sentence=Enables the communication with devices that use the Inter-IC Sound (I2S) Bus. Specific implementation for ESP. +paragraph= +category=Communication +url=http://www.arduino.cc/en/Reference/I2S +architectures=esp32 diff --git a/libraries/I2S/src/I2S.cpp b/libraries/I2S/src/I2S.cpp new file mode 100644 index 00000000000..393052c136f --- /dev/null +++ b/libraries/I2S/src/I2S.cpp @@ -0,0 +1,1209 @@ +/* + Copyright (c) 2016 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include +#include +#include "I2S.h" +#include "freertos/semphr.h" + +#define _I2S_EVENT_QUEUE_LENGTH 16 +#define _I2S_DMA_BUFFER_COUNT 2 // BUFFER COUNT must be between 2 and 128 +#define I2S_INTERFACES_COUNT SOC_I2S_NUM + +#ifndef I2S_DEVICE + #define I2S_DEVICE 0 +#endif + +#ifndef I2S_CLOCK_GENERATOR + #define I2S_CLOCK_GENERATOR 0 // does nothing for ESP +#endif + +I2SClass::I2SClass(uint8_t deviceIndex, uint8_t clockGenerator, uint8_t sdPin, uint8_t sckPin, uint8_t fsPin) : + _deviceIndex(deviceIndex), + _sdPin(sdPin), // shared data pin + _inSdPin(PIN_I2S_SD_IN), // input data pin + _outSdPin(PIN_I2S_SD), // output data pin + _sckPin(sckPin), // clock pin + _fsPin(fsPin), // frame (word) select pin + + _state(I2S_STATE_IDLE), + _bitsPerSample(0), + _sampleRate(0), + _mode(I2S_PHILIPS_MODE), + + _buffer_byte_size(0), + + _driverInstalled(false), + _initialized(false), + _callbackTaskHandle(NULL), + _i2sEventQueue(NULL), + _i2s_general_mutex(NULL), + _input_ring_buffer(NULL), + _output_ring_buffer(NULL), + _i2s_dma_buffer_size(128), // Number of frames in each DMA buffer. Frame size = number of channels * Bytes per sample; Must be between 8 and 1024 + _driveClock(true), + _peek_buff(0), + _peek_buff_valid(false), + _nesting_counter(0), + + _onTransmit(NULL), + _onReceive(NULL) +{ + _i2s_general_mutex = xSemaphoreCreateMutex(); + if(_i2s_general_mutex == NULL){ + log_e("I2S could not create internal mutex!"); + } +} + +int I2SClass::_createCallbackTask(){ + int stack_size = 20000; + if(_callbackTaskHandle != NULL){ + log_e("Callback task already exists!"); + return 0; // ERR + } + + xTaskCreate( + onDmaTransferComplete, // Function to implement the task + "onDmaTransferComplete", // Name of the task + stack_size, // Stack size in words + NULL, // Task input parameter + 2, // Priority of the task + &_callbackTaskHandle // Task handle. + ); + if(_callbackTaskHandle == NULL){ + log_e("Could not create callback task"); + return 0; // ERR + } + return 1; // OK +} + +int I2SClass::_installDriver(){ + if(_driverInstalled){ + log_e("I2S driver is already installed"); + return 0; // ERR + } + + esp_i2s::i2s_mode_t i2s_mode = (esp_i2s::i2s_mode_t)(esp_i2s::I2S_MODE_RX | esp_i2s::I2S_MODE_TX); + + if(_driveClock){ + i2s_mode = (esp_i2s::i2s_mode_t)(i2s_mode | esp_i2s::I2S_MODE_MASTER); + }else{ + i2s_mode = (esp_i2s::i2s_mode_t)(i2s_mode | esp_i2s::I2S_MODE_SLAVE); + } + + if(_mode == ADC_DAC_MODE){ + #if (SOC_I2S_SUPPORTS_ADC && SOC_I2S_SUPPORTS_DAC) + if(_bitsPerSample != 16){ // ADC/DAC can only work in 16-bit sample mode + log_e("ERROR invalid bps for ADC/DAC. Allowed only 16, requested %d", _bitsPerSample); + return 0; // ERR + } + i2s_mode = (esp_i2s::i2s_mode_t)(i2s_mode | esp_i2s::I2S_MODE_DAC_BUILT_IN | esp_i2s::I2S_MODE_ADC_BUILT_IN); + #else + log_e("This chip does not support ADC / DAC mode"); + return 0; // ERR + #endif + }else if(_mode == I2S_PHILIPS_MODE || + _mode == I2S_RIGHT_JUSTIFIED_MODE || + _mode == I2S_LEFT_JUSTIFIED_MODE){ // End of ADC/DAC mode; start of Normal Philips mode + if(_bitsPerSample != 8 && _bitsPerSample != 16 && _bitsPerSample != 24 && _bitsPerSample != 32){ + log_e("Invalid bits per sample for normal mode (requested %d)\nAllowed bps = 8 | 16 | 24 | 32", _bitsPerSample); + return 0; // ERR + } + if(_bitsPerSample == 24){ + log_w("Original Arduino library does not support 24 bits per sample.\nKeep that in mind if you should switch back to Arduino"); + } + }else if(_mode == PDM_STEREO_MODE || _mode == PDM_MONO_MODE){ // end of Normal Philips mode; start of PDM mode + #if (SOC_I2S_SUPPORTS_PDM_TX && SOC_I2S_SUPPORTS_PDM_RX) + i2s_mode = (esp_i2s::i2s_mode_t)(i2s_mode | esp_i2s::I2S_MODE_PDM); + #else + log_e("This chip does not support PDM"); + return 0; // ERR + #endif + } // Mode + esp_i2s::i2s_config_t i2s_config = { + .mode = i2s_mode, + .sample_rate = _sampleRate, + .bits_per_sample = (esp_i2s::i2s_bits_per_sample_t)_bitsPerSample, + .channel_format = esp_i2s::I2S_CHANNEL_FMT_RIGHT_LEFT, + .communication_format = (esp_i2s::i2s_comm_format_t)(esp_i2s::I2S_COMM_FORMAT_STAND_I2S), + .intr_alloc_flags = ESP_INTR_FLAG_LEVEL2, + .dma_buf_count = _I2S_DMA_BUFFER_COUNT, + .dma_buf_len = _i2s_dma_buffer_size, + .use_apll = false + }; + + if(_driveClock == false){ + i2s_config.use_apll = true; + i2s_config.fixed_mclk = 512*_sampleRate; + } + + // Install and start i2s driver + while(ESP_OK != esp_i2s::i2s_driver_install((esp_i2s::i2s_port_t) _deviceIndex, &i2s_config, _I2S_EVENT_QUEUE_LENGTH, &_i2sEventQueue)){ + // increase buffer size + if(2*_i2s_dma_buffer_size <= 1024){ + log_w("WARNING i2s driver install failed.\nTrying to increase I2S DMA buffer size from %d to %d\n", _i2s_dma_buffer_size, 2*_i2s_dma_buffer_size); + setBufferSize(2*_i2s_dma_buffer_size); + }else if(_i2s_dma_buffer_size < 1024){ + log_w("WARNING i2s driver install failed.\nTrying to decrease I2S DMA buffer size from %d to 1024\n", _i2s_dma_buffer_size); + setBufferSize(1024); + }else{ // install failed with max buffer size + log_e("ERROR i2s driver install failed"); + return 0; // ERR + } + } //try installing with increasing size + + if(_mode == I2S_RIGHT_JUSTIFIED_MODE || _mode == I2S_LEFT_JUSTIFIED_MODE || _mode == PDM_MONO_MODE){ // mono/single channel + // Set the clock for MONO. Stereo is not supported yet. + if(ESP_OK != esp_i2s::i2s_set_clk((esp_i2s::i2s_port_t) _deviceIndex, _sampleRate, (esp_i2s::i2s_bits_per_sample_t)_bitsPerSample, esp_i2s::I2S_CHANNEL_MONO)){ + log_e("Setting the I2S Clock has failed!\n"); + return 0; // ERR + } + } // mono channel mode + +#if (SOC_I2S_SUPPORTS_ADC && SOC_I2S_SUPPORTS_DAC) + if(_mode == ADC_DAC_MODE){ + esp_i2s::i2s_set_dac_mode(esp_i2s::I2S_DAC_CHANNEL_BOTH_EN); + esp_i2s::adc_unit_t adc_unit; + if(!_gpioToAdcUnit((gpio_num_t)_inSdPin, &adc_unit)){ + log_e("pin to adc unit conversion failed"); + return 0; // ERR + } + esp_i2s::adc_channel_t adc_channel; + if(!_gpioToAdcChannel((gpio_num_t)_inSdPin, &adc_channel)){ + log_e("pin to adc channel conversion failed"); + return 0; // ERR + } + if(ESP_OK != esp_i2s::i2s_set_adc_mode(adc_unit, (esp_i2s::adc1_channel_t)adc_channel)){ + log_e("i2s_set_adc_mode failed"); + return 0; // ERR + } + if(ESP_OK != esp_i2s::i2s_set_pin((esp_i2s::i2s_port_t) _deviceIndex, NULL)){ + log_e("i2s_set_pin failed"); + return 0; // ERR + } + + if(adc_unit == esp_i2s::ADC_UNIT_1){ + esp_i2s::adc1_config_width(esp_i2s::ADC_WIDTH_BIT_12); + esp_i2s::adc1_config_channel_atten((esp_i2s::adc1_channel_t)adc_channel, esp_i2s::ADC_ATTEN_DB_11); + }else if(adc_unit == esp_i2s::ADC_UNIT_2){ + esp_i2s::adc2_config_channel_atten((esp_i2s::adc2_channel_t)adc_channel, esp_i2s::ADC_ATTEN_DB_11); + } + + esp_i2s::i2s_adc_enable((esp_i2s::i2s_port_t) _deviceIndex); + _driverInstalled = true; + }else // End of ADC/DAC mode +#endif // SOC_I2S_SUPPORTS_ADC_DAC + if(_mode == I2S_PHILIPS_MODE || _mode == I2S_RIGHT_JUSTIFIED_MODE || _mode == I2S_LEFT_JUSTIFIED_MODE || _mode == PDM_STEREO_MODE || _mode == PDM_MONO_MODE){ // if I2S mode + _driverInstalled = true; // IDF I2S driver must be installed before calling _applyPinSetting + if(!_applyPinSetting()){ + log_e("could not apply pin setting during driver install"); + _uninstallDriver(); + return 0; // ERR + } + } // if I2S _mode + return 1; // OK +} + +// Init in MASTER mode: the SCK and FS pins are driven as outputs using the sample rate +int I2SClass::begin(int mode, int sampleRate, int bitsPerSample){ + _take_if_not_holding(); + // master mode (driving clock and frame select pins - output) + int ret = begin(mode, sampleRate, bitsPerSample, true); + _give_if_top_call(); + return ret; +} + +// Init in SLAVE mode: the SCK and FS pins are inputs, other side controls sample rate +int I2SClass::begin(int mode, int bitsPerSample){ + _take_if_not_holding(); + // slave mode (not driving clock and frame select pin - input) + int ret = begin(mode, 96000, bitsPerSample, false); + _give_if_top_call(); + return ret; +} + + +// Core function +int I2SClass::begin(int mode, int sampleRate, int bitsPerSample, bool driveClock){ + _take_if_not_holding(); + if(_initialized){ + log_e("ERROR: Object already initialized! Call I2S.end() to disable"); + _give_if_top_call(); + return 0; // ERR + } + _driveClock = driveClock; + _mode = mode; + _sampleRate = (uint32_t)sampleRate; + _bitsPerSample = bitsPerSample; + + // There is work in progress on this library. + if(_bitsPerSample == 16 && _sampleRate > 16000 && driveClock){ + log_w("This sample rate is not officially supported - audio might be noisy.\nTry using sample rate below or equal to 16000"); + } + if(_bitsPerSample != 16){ + log_w("This bit-per-sample is not officially supported - audio quality might suffer.\nTry using 16bps, with sample rate below or equal 16000"); + } + if(_mode != I2S_PHILIPS_MODE){ + log_w("This mode is not officially supported - audio quality might suffer.\nAt the moment the only supported mode is I2S_PHILIPS_MODE"); + } + + if (_state != I2S_STATE_IDLE && _state != I2S_STATE_DUPLEX) { + log_e("Error: unexpected _state (%d)", _state); + _give_if_top_call(); + return 0; // ERR + } + + switch (mode) { + case I2S_PHILIPS_MODE: + case I2S_RIGHT_JUSTIFIED_MODE: + case I2S_LEFT_JUSTIFIED_MODE: + + #if (SOC_I2S_SUPPORTS_ADC && SOC_I2S_SUPPORTS_DAC) + case ADC_DAC_MODE: + #endif + + case PDM_STEREO_MODE: + case PDM_MONO_MODE: + break; + + default: // invalid mode + log_e("ERROR: unknown mode"); + _give_if_top_call(); + return 0; // ERR + } + + if(!_installDriver()){ + log_e("ERROR: failed to install driver"); + end(); + _give_if_top_call(); + return 0; // ERR + } + + _buffer_byte_size = _i2s_dma_buffer_size * (_bitsPerSample / 8) * _I2S_DMA_BUFFER_COUNT * 2; + _input_ring_buffer = xRingbufferCreate(_buffer_byte_size, RINGBUF_TYPE_BYTEBUF); + _output_ring_buffer = xRingbufferCreate(_buffer_byte_size, RINGBUF_TYPE_BYTEBUF); + if(_input_ring_buffer == NULL || _output_ring_buffer == NULL){ + log_e("ERROR: could not create one or both internal buffers. Requested size = %d\n", _buffer_byte_size); + _give_if_top_call(); + return 0; // ERR + } + + if(!_createCallbackTask()){ + log_e("ERROR: failed to create callback task"); + end(); + _give_if_top_call(); + return 0; // ERR + } + _initialized = true; + _give_if_top_call(); + return 1; // OK +} + +int I2SClass::_applyPinSetting(){ + if(_driverInstalled){ + esp_i2s::i2s_pin_config_t pin_config = { + .bck_io_num = _sckPin, + .ws_io_num = _fsPin, + .data_out_num = I2S_PIN_NO_CHANGE, + .data_in_num = I2S_PIN_NO_CHANGE + }; + if (_state == I2S_STATE_DUPLEX){ // duplex + pin_config.data_out_num = _outSdPin; + pin_config.data_in_num = _inSdPin; + }else{ // simplex + if(_state == I2S_STATE_RECEIVER){ + pin_config.data_out_num = I2S_PIN_NO_CHANGE; + pin_config.data_in_num = _sdPin; + }else if(_state == I2S_STATE_TRANSMITTER){ + pin_config.data_out_num = _sdPin; + pin_config.data_in_num = I2S_PIN_NO_CHANGE; + }else{ + pin_config.data_out_num = I2S_PIN_NO_CHANGE; + pin_config.data_in_num = _sdPin; + } + } + if(ESP_OK != esp_i2s::i2s_set_pin((esp_i2s::i2s_port_t) _deviceIndex, &pin_config)){ + log_e("i2s_set_pin failed; attempted settings: SCK=%d; FS=%d; DIN=%d; DOUT=%d", pin_config.bck_io_num, pin_config.ws_io_num, pin_config.data_in_num, pin_config.data_out_num); + return 0; // ERR + }else{ + return 1; // OK + } + } // if(_driverInstalled) + return 1; // OK +} + +void I2SClass::_setSckPin(int sckPin){ + _take_if_not_holding(); + if(sckPin >= 0){ + _sckPin = sckPin; + }else{ + _sckPin = PIN_I2S_SCK; + } + _give_if_top_call(); +} + +int I2SClass::setSckPin(int sckPin){ + _take_if_not_holding(); + _setSckPin(sckPin); + int ret = _applyPinSetting(); + _applyPinSetting(); + _give_if_top_call(); + return ret; +} + +void I2SClass::_setFsPin(int fsPin){ + if(fsPin >= 0){ + _fsPin = fsPin; + }else{ + _fsPin = PIN_I2S_FS; + } +} + +int I2SClass::setFsPin(int fsPin){ + _take_if_not_holding(); + _setFsPin(fsPin); + int ret = _applyPinSetting(); + _give_if_top_call(); + return ret; +} + +// shared data pin for simplex +void I2SClass::_setDataPin(int sdPin){ + if(sdPin >= 0){ + _sdPin = sdPin; + }else{ + _sdPin = PIN_I2S_SD; + } +} + +// shared data pin for simplex +int I2SClass::setDataPin(int sdPin){ + _take_if_not_holding(); + _setDataPin(sdPin); + int ret = _applyPinSetting(); + _give_if_top_call(); + return ret; +} + +void I2SClass::_setDataInPin(int inSdPin){ + if(inSdPin >= 0){ + _inSdPin = inSdPin; + }else{ + _inSdPin = PIN_I2S_SD_IN; + } +} + +int I2SClass::setDataInPin(int inSdPin){ + _take_if_not_holding(); + _setDataInPin(inSdPin); + int ret = _applyPinSetting(); + _give_if_top_call(); + return ret; +} + +void I2SClass::_setDataOutPin(int outSdPin){ + if(outSdPin >= 0){ + _outSdPin = outSdPin; + }else{ + _outSdPin = PIN_I2S_SD; + } +} + +int I2SClass::setDataOutPin(int outSdPin){ + _take_if_not_holding(); + _setDataOutPin(outSdPin); + int ret = _applyPinSetting(); + _give_if_top_call(); + return ret; +} + +int I2SClass::setAllPins(){ + _take_if_not_holding(); + int ret = setAllPins(PIN_I2S_SCK, PIN_I2S_FS, PIN_I2S_SD, PIN_I2S_SD_OUT, PIN_I2S_SD_IN); + _give_if_top_call(); + return ret; +} + +int I2SClass::setAllPins(int sckPin, int fsPin, int sdPin, int outSdPin, int inSdPin){ + _take_if_not_holding(); + _setSckPin(sckPin); + _setFsPin(fsPin); + _setDataPin(sdPin); + _setDataOutPin(outSdPin); + _setDataInPin(inSdPin); + int ret = _applyPinSetting(); + _give_if_top_call(); + return ret; +} + +int I2SClass::setDuplex(){ + _take_if_not_holding(); + _state = I2S_STATE_DUPLEX; + _give_if_top_call(); + return 1; +} + +int I2SClass::setSimplex(){ + _take_if_not_holding(); + _state = I2S_STATE_IDLE; + _give_if_top_call(); + return 1; +} + +int I2SClass::isDuplex(){ + _take_if_not_holding(); + int ret = (int)(_state == I2S_STATE_DUPLEX); + _give_if_top_call(); + return ret; +} + +int I2SClass::getSckPin(){ + _take_if_not_holding(); + int ret = _sckPin; + _give_if_top_call(); + return ret; +} + +int I2SClass::getFsPin(){ + _take_if_not_holding(); + int ret = _fsPin; + _give_if_top_call(); + return ret; +} + +int I2SClass::getDataPin(){ + _take_if_not_holding(); + int ret = _sdPin; + _give_if_top_call(); + return ret; +} + +int I2SClass::getDataInPin(){ + _take_if_not_holding(); + int ret = _inSdPin; + _give_if_top_call(); + return ret; +} + +int I2SClass::getDataOutPin(){ + _take_if_not_holding(); + int ret = _outSdPin; + _give_if_top_call(); + return ret; +} + +void I2SClass::_uninstallDriver(){ + if(_driverInstalled){ + #if (SOC_I2S_SUPPORTS_ADC && SOC_I2S_SUPPORTS_DAC) + if(_mode == ADC_DAC_MODE){ + esp_i2s::i2s_adc_disable((esp_i2s::i2s_port_t) _deviceIndex); + } + #endif + esp_i2s::i2s_driver_uninstall((esp_i2s::i2s_port_t) _deviceIndex); + + if(_state != I2S_STATE_DUPLEX){ + _state = I2S_STATE_IDLE; + } + _driverInstalled = false; + } // if(_driverInstalled) +} + +void I2SClass::end(){ + _take_if_not_holding(); + if(xTaskGetCurrentTaskHandle() != _callbackTaskHandle){ + if(_callbackTaskHandle){ + vTaskDelete(_callbackTaskHandle); + _callbackTaskHandle = NULL; // prevent secondary termination to non-existing task + } + _uninstallDriver(); + _onTransmit = NULL; + _onReceive = NULL; + if(_input_ring_buffer != NULL){ + vRingbufferDelete(_input_ring_buffer); + _input_ring_buffer = NULL; + } + if(_output_ring_buffer != NULL){ + vRingbufferDelete(_output_ring_buffer); + _output_ring_buffer = NULL; + } + _initialized = false; + }else{ + log_w("WARNING: ending I2SClass from callback task not permitted, but attempted!"); + } + _give_if_top_call(); +} + +// Bytes available to read +int I2SClass::available(){ + _take_if_not_holding(); + int ret = 0; + if(_input_ring_buffer != NULL){ + ret = _buffer_byte_size - (int)xRingbufferGetCurFreeSize(_input_ring_buffer); + } + _give_if_top_call(); + return ret; +} + +union i2s_sample_t { + uint8_t b8; + int16_t b16; + int32_t b32; +}; + +int I2SClass::read(){ + _take_if_not_holding(); + i2s_sample_t sample; + sample.b32 = 0; + if(_initialized){ + read(&sample, _bitsPerSample / 8); + + if (_bitsPerSample == 32) { + _give_if_top_call(); + return sample.b32; + } else if (_bitsPerSample == 16) { + _give_if_top_call(); + return sample.b16; + } else if (_bitsPerSample == 8) { + _give_if_top_call(); + return sample.b8; + } else { + _give_if_top_call(); + return 0; // sample value + } + } // if(_initialized) + _give_if_top_call(); + return 0; // sample value +} + +int I2SClass::read(void* buffer, size_t size){ + _take_if_not_holding(); + size_t requested_size = size; + if(_initialized){ + if(!_enableReceiver()){ + _give_if_top_call(); + return 0; // There was an error switching to receiver + } // _enableReceiver succeeded ? + + size_t item_size = 0; + void *tmp_buffer; + if(_input_ring_buffer != NULL){ + if(_peek_buff_valid){ + memcpy(buffer, &_peek_buff, _bitsPerSample/8); + _peek_buff_valid = false; + requested_size -= _bitsPerSample/8; + } + tmp_buffer = xRingbufferReceiveUpTo(_input_ring_buffer, &item_size, pdMS_TO_TICKS(1000), requested_size); + if(tmp_buffer != NULL){ + memcpy(buffer, tmp_buffer, item_size); + #if (SOC_I2S_SUPPORTS_ADC && SOC_I2S_SUPPORTS_DAC) + if(_mode == ADC_DAC_MODE){ + for(size_t i = 0; i < item_size / 2; ++i){ + ((uint16_t*)buffer)[i] = ((uint16_t*)buffer)[i] & 0x0FFF; + } + } // ADC/DAC mode + #endif + vRingbufferReturnItem(_input_ring_buffer, tmp_buffer); + _give_if_top_call(); + return item_size; + }else{ + log_w("input buffer is empty - timed out"); + _give_if_top_call(); + return 0; // 0 Bytes read / ERR + } // tmp buffer not NULL ? + } // ring buffer not NULL ? + } // if(_initialized) + _give_if_top_call(); + return 0; // 0 Bytes read / ERR +} + +size_t I2SClass::write(uint8_t data){ + _take_if_not_holding(); + size_t ret = 0; + if(_initialized){ + ret = write_blocking((int32_t*)&data, 1); + } + _give_if_top_call(); + return ret; +} + +size_t I2SClass::write(int32_t sample){ + _take_if_not_holding(); + size_t ret = 0; + if(_initialized){ + ret = write_blocking(&sample, _bitsPerSample/8); + } + _give_if_top_call(); + return ret; +} + +size_t I2SClass::write(const uint8_t *buffer, size_t size){ + _take_if_not_holding(); + size_t ret = 0; + if(_initialized){ + ret = write((const void*)buffer, size); + } + _give_if_top_call(); + return ret; +} + +size_t I2SClass::write(const void *buffer, size_t size){ + _take_if_not_holding(); + size_t ret = 0; + if(_initialized){ + //size_t ret = write_blocking(buffer, size); + ret = write_nonblocking(buffer, size); + } // if(_initialized) + _give_if_top_call(); + return ret; +} + +// blocking version of write +// This version of write will wait indefinitely to write requested samples +// into output buffer +size_t I2SClass::write_blocking(const void *buffer, size_t size){ + _take_if_not_holding(); + if(_initialized){ + if(!_enableTransmitter()){ + _give_if_top_call(); + return 0; // There was an error switching to transmitter + } // _enableTransmitter succeeded ? + + if(_output_ring_buffer != NULL){ + int ret = xRingbufferSend(_output_ring_buffer, buffer, size, portMAX_DELAY); + if(pdTRUE == ret){ + _give_if_top_call(); + return size; + }else{ + log_e("xRingbufferSend() with infinite wait returned with error"); + _give_if_top_call(); + return 0; + } // ring buffer send ok ? + } // ring buffer not NULL ? + } // if(_initialized) + return 0; + log_w("I2S not initialized"); + _give_if_top_call(); + return 0; +} + +// non-blocking version of write +// In case there is not enough space in buffer to write requested size +// this function will try to flush the buffer and write requested data with 0 time-out +size_t I2SClass::write_nonblocking(const void *buffer, size_t size){ + _take_if_not_holding(); + if(_initialized){ + if(_state != I2S_STATE_TRANSMITTER && _state != I2S_STATE_DUPLEX){ + if(!_enableTransmitter()){ + _give_if_top_call(); + return 0; // There was an error switching to transmitter + } + } + if(availableForWrite() < size){ + flush(); + } + if(_output_ring_buffer != NULL){ + if(pdTRUE == xRingbufferSend(_output_ring_buffer, buffer, size, 0)){ + _give_if_top_call(); + return size; + }else{ + log_w("I2S could not write all data into ring buffer!"); + _give_if_top_call(); + return 0; + } + } + } // if(_initialized) + return 0; + _give_if_top_call(); // this should not be needed +} + +/* + Read 1 sample from internal buffer and return it. + Repeated peeks will return the same sample until read is called. +*/ +int I2SClass::peek(){ + _take_if_not_holding(); + int ret = 0; + if(_initialized && _input_ring_buffer != NULL && !_peek_buff_valid){ + size_t item_size = 0; + void *item = NULL; + + item = xRingbufferReceiveUpTo(_input_ring_buffer, &item_size, 0, _bitsPerSample/8); // fetch 1 sample + if (item != NULL && item_size == _bitsPerSample/8){ + _peek_buff = *((int*)item); + vRingbufferReturnItem(_input_ring_buffer, item); + _peek_buff_valid = true; + } + + } // if(_initialized) + if(_peek_buff_valid){ + ret = _peek_buff; + } + _give_if_top_call(); + return ret; +} + +void I2SClass::flush(){ + _take_if_not_holding(); + if(_initialized){ + const size_t single_dma_buf = _i2s_dma_buffer_size*(_bitsPerSample/8)*2; + size_t item_size = 0; + void *item = NULL; + if(_output_ring_buffer != NULL){ + item = xRingbufferReceiveUpTo(_output_ring_buffer, &item_size, 0, single_dma_buf); + if (item != NULL){ + _fix_and_write(item, item_size); + vRingbufferReturnItem(_output_ring_buffer, item); + } + } + } // if(_initialized) + _give_if_top_call(); +} + +// Bytes available to write +int I2SClass::availableForWrite(){ + _take_if_not_holding(); + int ret = 0; + if(_initialized){ + if(_output_ring_buffer != NULL){ + ret = (int)xRingbufferGetCurFreeSize(_output_ring_buffer); + } + } // if(_initialized) + _give_if_top_call(); + return ret; +} + +void I2SClass::onTransmit(void(*function)(void)){ + _take_if_not_holding(); + _onTransmit = function; + _give_if_top_call(); +} + +void I2SClass::onReceive(void(*function)(void)){ + _take_if_not_holding(); + _onReceive = function; + _give_if_top_call(); +} + +int I2SClass::setBufferSize(int bufferSize){ + _take_if_not_holding(); + int ret = 0; + if(bufferSize >= 8 && bufferSize <= 1024){ + _i2s_dma_buffer_size = bufferSize; + }else{ + log_e("setBufferSize: wrong input! Buffer size must be between 8 and 1024. Requested %d", bufferSize); + _give_if_top_call(); + return 0; // ERR + } // check requested buffer size + + if(_initialized){ + _uninstallDriver(); + ret = _installDriver(); + _give_if_top_call(); + return ret; + }else{ // check requested buffer size + _give_if_top_call(); + return 1; // It's ok to change buffer size for uninitialized driver - new size will be used on begin() + } // if(_initialized) + _give_if_top_call(); + return 0; // ERR +} + +int I2SClass::getBufferSize(){ + _take_if_not_holding(); + int ret = _i2s_dma_buffer_size; + _give_if_top_call(); + return ret; +} + +int I2SClass::_enableTransmitter(){ + if(_state != I2S_STATE_DUPLEX && _state != I2S_STATE_TRANSMITTER){ + _state = I2S_STATE_TRANSMITTER; + return _applyPinSetting(); + } + return 1; // Ok +} + +int I2SClass::_enableReceiver(){ + if(_state != I2S_STATE_DUPLEX && _state != I2S_STATE_RECEIVER){ + _state = I2S_STATE_RECEIVER; + return _applyPinSetting(); + } + return 1; // Ok +} + +void I2SClass::_tx_done_routine(uint8_t* prev_item){ + static bool prev_item_valid = false; + const size_t single_dma_buf = _i2s_dma_buffer_size*(_bitsPerSample/8)*2; // *2 for stereo - it has double number of samples for 2 channels + static size_t item_size = 0; + static size_t prev_item_size = 0; + static void *item = NULL; + static int prev_item_offset = 0; + static size_t bytes_written = 0; + + if(prev_item_valid){ // use item from previous round + _fix_and_write(prev_item+prev_item_offset, prev_item_size, &bytes_written); + if(prev_item_size == bytes_written){ + prev_item_valid = false; + } // write size check + prev_item_offset = bytes_written; + prev_item_size -= bytes_written; + } // prev_item_valid + + if(_output_ring_buffer != NULL && (_buffer_byte_size - xRingbufferGetCurFreeSize(_output_ring_buffer) >= single_dma_buf)){ // fill up the I2S DMA buffer + bytes_written = 0; + item_size = 0; + if(_buffer_byte_size - xRingbufferGetCurFreeSize(_output_ring_buffer) >= _i2s_dma_buffer_size*(_bitsPerSample/8)){ // don't read from almost empty buffer + item = xRingbufferReceiveUpTo(_output_ring_buffer, &item_size, pdMS_TO_TICKS(0), single_dma_buf); + if (item != NULL){ + _fix_and_write(item, item_size, &bytes_written); + if(item_size != bytes_written){ // save item that was not written correctly for later + memcpy(prev_item, (void*)&((uint8_t*)item)[bytes_written], item_size-bytes_written); + prev_item_size = item_size - bytes_written; + prev_item_offset = 0; + prev_item_valid = true; + } // save item that was not written correctly for later + vRingbufferReturnItem(_output_ring_buffer, item); + } // Check received item + } // don't read from almost empty buffer + } // fill up the I2S DMA buffer + if(_onTransmit){ + _onTransmit(); + } // user callback +} + +void I2SClass::_rx_done_routine(){ + size_t bytes_read = 0; + const size_t single_dma_buf = _i2s_dma_buffer_size*(_bitsPerSample/8); + + if(_input_ring_buffer != NULL){ + uint8_t *_inputBuffer = (uint8_t*)malloc(_i2s_dma_buffer_size*4); + size_t avail = xRingbufferGetCurFreeSize(_input_ring_buffer); + if(avail > 0){ + esp_err_t ret = esp_i2s::i2s_read((esp_i2s::i2s_port_t) _deviceIndex, _inputBuffer, avail <= single_dma_buf ? avail : single_dma_buf, (size_t*) &bytes_read, 0); + if(ret != ESP_OK){ + log_w("i2s_read returned with error %d", ret); + } + _post_read_data_fix(_inputBuffer, &bytes_read); + } + + if(bytes_read > 0){ // when read more than 0, then send to ring buffer + if(pdTRUE != xRingbufferSend(_input_ring_buffer, _inputBuffer, bytes_read, 0)){ + log_w("I2S failed to send item from DMA to internal buffer\n"); + } // xRingbufferSendComplete + } // if(bytes_read > 0) + free(_inputBuffer); + if (_onReceive && avail < _buffer_byte_size){ // when user callback is registered && and there is some data in ring buffer to read + _onReceive(); + } // user callback + } +} + +void I2SClass::_onTransferComplete(){ + uint8_t prev_item[_i2s_dma_buffer_size*4]; + esp_i2s::i2s_event_t i2s_event; + + while(true){ + xQueueReceive(_i2sEventQueue, &i2s_event, portMAX_DELAY); + if(i2s_event.type == esp_i2s::I2S_EVENT_TX_DONE){ + _tx_done_routine(prev_item); + }else if(i2s_event.type == esp_i2s::I2S_EVENT_RX_DONE){ + _rx_done_routine(); + } // RX Done + } // infinite loop +} + +void I2SClass::onDmaTransferComplete(void*){ + I2S._onTransferComplete(); +} + +void I2SClass::_take_if_not_holding(){ + TaskHandle_t mutex_holder = xSemaphoreGetMutexHolder(_i2s_general_mutex); + if(mutex_holder != NULL && mutex_holder == xTaskGetCurrentTaskHandle()){ + ++_nesting_counter; + return; // we are already holding this mutex - no need to take it + } + + // we are not holding the mutex - wait for it and take it + if(xSemaphoreTake(_i2s_general_mutex, portMAX_DELAY) != pdTRUE ){ + log_e("I2S internal mutex take returned with error"); + } + //_give_if_top_call(); // call after this function +} + +void I2SClass::_give_if_top_call(){ + if(_nesting_counter){ + --_nesting_counter; + }else{ + if(xSemaphoreGive(_i2s_general_mutex) != pdTRUE){ + log_e("I2S internal mutex give error"); + } + } +} + + +// Fixes data in-situ received from esp i2s driver. After fixing they reflect what was on the bus. +// input - bytes as received from i2s_read - this serves as input and output buffer +// size - number of bytes (this may be changed during operation) +void I2SClass::_post_read_data_fix(void *input, size_t *size){ + ulong dst_ptr = 0; + switch(_bitsPerSample){ + case 8: + for(int i = 0; i < *size; i+=4){ + ((uint8_t*)input)[dst_ptr++] = ((uint8_t*)input)[i+3]; + ((uint8_t*)input)[dst_ptr++] = ((uint8_t*)input)[i+1]; + } + *size /= 2; + break; + case 16: + uint16_t tmp; + for(int i = 0; i < *size/2; i+=2){ + tmp = ((uint16_t*)input)[i]; + ((uint16_t*)input)[dst_ptr++] = ((uint16_t*)input)[i+1]; + ((uint16_t*)input)[dst_ptr++] = tmp; + } + break; + default: ; // Do nothing + } // switch +} + +// Prepares data and writes them to IDF i2s driver. +// This counters possible bug in ESP IDF I2S driver +// output - bytes to be sent +// size - number of bytes in original buffer +// bytes_written - number of bytes used from original buffer +// actual_bytes_written - number of bytes written by i2s_write after fix +void I2SClass::_fix_and_write(void *output, size_t size, size_t *bytes_written, size_t *actual_bytes_written){ + long start = millis(); + ulong src_ptr = 0; + uint8_t* buff = NULL; + size_t buff_size = size; + switch(_bitsPerSample){ + case 8: + buff_size = size *2; + buff = (uint8_t*)calloc(buff_size, sizeof(uint8_t)); + if(buff == NULL){ + log_e("callock error"); + if(bytes_written != NULL){ *bytes_written = 0; } + return; + } + for(int i = 0; i < buff_size ; i+=4){ + ((uint8_t*)buff)[i+3] = (uint16_t)((uint8_t*)output)[src_ptr++]; + ((uint8_t*)buff)[i+1] = (uint16_t)((uint8_t*)output)[src_ptr++]; + } + break; + case 16: + buff = (uint8_t*)malloc(buff_size); + if(buff == NULL){ + log_e("malloc error"); + if(bytes_written != NULL){ *bytes_written = 0; } + return; + } + for(int i = 0; i < size/2; i += 2 ){ + ((uint16_t*)buff)[i] = ((uint16_t*)output)[i+1]; // [1] <- [0] + ((uint16_t*)buff)[i+1] = ((uint16_t*)output)[i]; // [0] <- [1] + } + break; + case 24: + buff = (uint8_t*)output; + break; + case 32: + buff = (uint8_t*)output; + break; + default: ; // Do nothing + } // switch + + size_t _bytes_written; + esp_err_t ret = esp_i2s::i2s_write((esp_i2s::i2s_port_t) _deviceIndex, buff, buff_size, &_bytes_written, 0); // fixed + if(ret != ESP_OK){ + log_e("Error: writing data to i2s - function returned with err code %d", ret); + } + if(ret == ESP_OK && buff_size != _bytes_written){ + log_w("Warning: writing data to i2s - written %d B instead of requested %d B", _bytes_written, buff_size); + } + // free if the buffer was actually allocated + if(_bitsPerSample == 8 || _bitsPerSample == 16){ + free(buff); + } + if(bytes_written != NULL){ + *bytes_written = _bitsPerSample == 8 ? _bytes_written/2 : _bytes_written; + } + if(actual_bytes_written != NULL){ + *actual_bytes_written = _bytes_written; + } +} + + +#if (SOC_I2S_SUPPORTS_ADC && SOC_I2S_SUPPORTS_DAC) +int I2SClass::_gpioToAdcUnit(gpio_num_t gpio_num, esp_i2s::adc_unit_t* adc_unit){ + switch(gpio_num){ +#if CONFIG_IDF_TARGET_ESP32 + // ADC 1 + case GPIO_NUM_36: + case GPIO_NUM_37: + case GPIO_NUM_38: + case GPIO_NUM_39: + case GPIO_NUM_32: + case GPIO_NUM_33: + case GPIO_NUM_34: + case GPIO_NUM_35: + *adc_unit = esp_i2s::ADC_UNIT_1; + return 1; // OK + + // ADC 2 + case GPIO_NUM_0: + log_w("GPIO 0 for ADC should not be used for dev boards due to external auto program circuits."); + case GPIO_NUM_4: + case GPIO_NUM_2: + case GPIO_NUM_15: + case GPIO_NUM_13: + case GPIO_NUM_12: + case GPIO_NUM_14: + case GPIO_NUM_27: + case GPIO_NUM_25: + case GPIO_NUM_26: + *adc_unit = esp_i2s::ADC_UNIT_2; + return 1; // OK +#endif + +#if (CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3) + case GPIO_NUM_1: + case GPIO_NUM_2: + case GPIO_NUM_3: + case GPIO_NUM_4: + case GPIO_NUM_5: + case GPIO_NUM_6: + case GPIO_NUM_7: + case GPIO_NUM_8: + case GPIO_NUM_9: + case GPIO_NUM_10: + *adc_unit = esp_i2s::ADC_UNIT_1; + return 1; // OK +#endif + +#if CONFIG_IDF_TARGET_ESP32S2 + case GPIO_NUM_11: + case GPIO_NUM_12: + case GPIO_NUM_13: + case GPIO_NUM_14: + case GPIO_NUM_15: + case GPIO_NUM_16: + case GPIO_NUM_17: + case GPIO_NUM_18: + case GPIO_NUM_19: + case GPIO_NUM_20: + *adc_unit = esp_i2s::ADC_UNIT_2; + return 1; // OK +#endif + +#if (CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2) + case GPIO_NUM_0: + case GPIO_NUM_1: + case GPIO_NUM_2: + case GPIO_NUM_3: + case GPIO_NUM_4: + *adc_unit = esp_i2s::ADC_UNIT_1; + return 1; // OK + case GPIO_NUM_5: + *adc_unit = esp_i2s::ADC_UNIT_2; + return 1; // OK +#endif + default: + log_e("GPIO %d not usable for ADC!", gpio_num); + log_i("Please refer to documentation https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/gpio.html"); + return 0; // ERR + } +} + +int I2SClass::_gpioToAdcChannel(gpio_num_t gpio_num, esp_i2s::adc_channel_t* adc_channel){ + switch(gpio_num){ +#if CONFIG_IDF_TARGET_ESP32 + // ADC 1 + case GPIO_NUM_36: *adc_channel = esp_i2s::ADC_CHANNEL_0; return 1; // OK + case GPIO_NUM_37: *adc_channel = esp_i2s::ADC_CHANNEL_1; return 1; // OK + case GPIO_NUM_38: *adc_channel = esp_i2s::ADC_CHANNEL_2; return 1; // OK + case GPIO_NUM_39: *adc_channel = esp_i2s::ADC_CHANNEL_3; return 1; // OK + case GPIO_NUM_32: *adc_channel = esp_i2s::ADC_CHANNEL_4; return 1; // OK + case GPIO_NUM_33: *adc_channel = esp_i2s::ADC_CHANNEL_5; return 1; // OK + case GPIO_NUM_34: *adc_channel = esp_i2s::ADC_CHANNEL_6; return 1; // OK + case GPIO_NUM_35: *adc_channel = esp_i2s::ADC_CHANNEL_7; return 1; // OK + + // ADC 2 + case GPIO_NUM_0: + log_w("GPIO 0 for ADC should not be used for dev boards due to external auto program circuits."); + *adc_channel = esp_i2s::ADC_CHANNEL_1; return 1; // OK + case GPIO_NUM_4: *adc_channel = esp_i2s::ADC_CHANNEL_0; return 1; // OK + case GPIO_NUM_2: *adc_channel = esp_i2s::ADC_CHANNEL_2; return 1; // OK + case GPIO_NUM_15: *adc_channel = esp_i2s::ADC_CHANNEL_3; return 1; // OK + case GPIO_NUM_13: *adc_channel = esp_i2s::ADC_CHANNEL_4; return 1; // OK + case GPIO_NUM_12: *adc_channel = esp_i2s::ADC_CHANNEL_5; return 1; // OK + case GPIO_NUM_14: *adc_channel = esp_i2s::ADC_CHANNEL_6; return 1; // OK + case GPIO_NUM_27: *adc_channel = esp_i2s::ADC_CHANNEL_7; return 1; // OK + case GPIO_NUM_25: *adc_channel = esp_i2s::ADC_CHANNEL_8; return 1; // OK + case GPIO_NUM_26: *adc_channel = esp_i2s::ADC_CHANNEL_9; return 1; // OK +#endif + +#if (CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3) + case GPIO_NUM_1: *adc_channel = esp_i2s::ADC_CHANNEL_0; return 1; // OK + case GPIO_NUM_2: *adc_channel = esp_i2s::ADC_CHANNEL_1; return 1; // OK + case GPIO_NUM_3: *adc_channel = esp_i2s::ADC_CHANNEL_2; return 1; // OK + case GPIO_NUM_4: *adc_channel = esp_i2s::ADC_CHANNEL_3; return 1; // OK + case GPIO_NUM_5: *adc_channel = esp_i2s::ADC_CHANNEL_4; return 1; // OK + case GPIO_NUM_6: *adc_channel = esp_i2s::ADC_CHANNEL_5; return 1; // OK + case GPIO_NUM_7: *adc_channel = esp_i2s::ADC_CHANNEL_6; return 1; // OK + case GPIO_NUM_8: *adc_channel = esp_i2s::ADC_CHANNEL_7; return 1; // OK + case GPIO_NUM_9: *adc_channel = esp_i2s::ADC_CHANNEL_8; return 1; // OK + case GPIO_NUM_10: *adc_channel = esp_i2s::ADC_CHANNEL_9; return 1; // OK +#endif + +#if CONFIG_IDF_TARGET_ESP32S2 + case GPIO_NUM_11: *adc_channel = esp_i2s::ADC_CHANNEL_0; return 1; // OK + case GPIO_NUM_12: *adc_channel = esp_i2s::ADC_CHANNEL_1; return 1; // OK + case GPIO_NUM_13: *adc_channel = esp_i2s::ADC_CHANNEL_2; return 1; // OK + case GPIO_NUM_14: *adc_channel = esp_i2s::ADC_CHANNEL_3; return 1; // OK + case GPIO_NUM_15: *adc_channel = esp_i2s::ADC_CHANNEL_4; return 1; // OK + case GPIO_NUM_16: *adc_channel = esp_i2s::ADC_CHANNEL_5; return 1; // OK + case GPIO_NUM_17: *adc_channel = esp_i2s::ADC_CHANNEL_6; return 1; // OK + case GPIO_NUM_18: *adc_channel = esp_i2s::ADC_CHANNEL_7; return 1; // OK + case GPIO_NUM_19: *adc_channel = esp_i2s::ADC_CHANNEL_8; return 1; // OK + case GPIO_NUM_20: *adc_channel = esp_i2s::ADC_CHANNEL_9; return 1; // OK +#endif + +#if (CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2) + case GPIO_NUM_0: *adc_channel = esp_i2s::ADC_CHANNEL_0; return 1; // OK + case GPIO_NUM_1: *adc_channel = esp_i2s::ADC_CHANNEL_1; return 1; // OK + case GPIO_NUM_2: *adc_channel = esp_i2s::ADC_CHANNEL_2; return 1; // OK + case GPIO_NUM_3: *adc_channel = esp_i2s::ADC_CHANNEL_3; return 1; // OK + case GPIO_NUM_4: *adc_channel = esp_i2s::ADC_CHANNEL_4; return 1; // OK + case GPIO_NUM_5: *adc_channel = esp_i2s::ADC_CHANNEL_0; return 1; // OK +#endif + default: + log_e("GPIO %d not usable for ADC!", gpio_num); + log_i("Please refer to documentation https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/gpio.html"); + return 0; // ERR + } +} +#endif // SOC_I2S_SUPPORTS_ADC_DAC + +#if I2S_INTERFACES_COUNT > 0 + I2SClass I2S(I2S_DEVICE, I2S_CLOCK_GENERATOR, PIN_I2S_SD, PIN_I2S_SCK, PIN_I2S_FS); // default - half duplex +#endif + +#if I2S_INTERFACES_COUNT > 1 + // TODO set default pins for second module + //I2SClass I2S1(I2S_DEVICE+1, I2S_CLOCK_GENERATOR, PIN_I2S_SD, PIN_I2S_SCK, PIN_I2S_FS); // default - half duplex +#endif diff --git a/libraries/I2S/src/I2S.h b/libraries/I2S/src/I2S.h new file mode 100644 index 00000000000..623fa8917b4 --- /dev/null +++ b/libraries/I2S/src/I2S.h @@ -0,0 +1,195 @@ +/* + Copyright (c) 2016 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _I2S_H_INCLUDED +#define _I2S_H_INCLUDED + +#include +#include "freertos/ringbuf.h" + +namespace esp_i2s { + #include "driver/i2s.h" // ESP specific i2s driver +} + +// Default pins +#ifndef PIN_I2S_SCK + #define PIN_I2S_SCK 14 +#endif + +#ifndef PIN_I2S_FS + #if CONFIG_IDF_TARGET_ESP32S2 + #define PIN_I2S_FS 27 + #else + #define PIN_I2S_FS 25 + #endif +#endif + +#ifndef PIN_I2S_SD + #define PIN_I2S_SD 26 +#endif + +#ifndef PIN_I2S_SD_OUT + #define PIN_I2S_SD_OUT 26 +#endif + +#ifndef PIN_I2S_SD_IN + #define PIN_I2S_SD_IN 35 // Pin 35 is only input! +#endif + +typedef enum { + I2S_PHILIPS_MODE, + I2S_RIGHT_JUSTIFIED_MODE, + I2S_LEFT_JUSTIFIED_MODE, + ADC_DAC_MODE, + PDM_STEREO_MODE, + PDM_MONO_MODE +} i2s_mode_t; + +class I2SClass : public Stream +{ +public: + // The device index and pins must map to the "COM" pads in Table 6-1 of the datasheet + I2SClass(uint8_t deviceIndex, uint8_t clockGenerator, uint8_t sdPin, uint8_t sckPin, uint8_t fsPin); + + // Init in MASTER mode: the SCK and FS pins are driven as outputs using the sample rate + int begin(int mode, int sampleRate, int bitsPerSample); + + // Init in SLAVE mode: the SCK and FS pins are inputs, other side controls sample rate + int begin(int mode, int bitsPerSample); + + // change pin setup and mode (default is Half Duplex) + // Can be called only on initialized object (after begin) + int setSckPin(int sckPin); + int setFsPin(int fsPin); + int setDataPin(int sdPin); // shared data pin for simplex + int setDataOutPin(int outSdPin); + int setDataInPin(int inSdPin); + + int setAllPins(); + int setAllPins(int sckPin, int fsPin, int sdPin, int outSdPin, int inSdPin); + + int getSckPin(); + int getFsPin(); + int getDataPin(); + int getDataOutPin(); + int getDataInPin(); + + int setDuplex(); + int setSimplex(); + int isDuplex(); + + void end(); + + // from Stream + virtual int available(); + virtual int read(); + virtual int peek(); + virtual void flush(); + + // from Print + virtual size_t write(uint8_t); + virtual size_t write(const uint8_t *buffer, size_t size); + + virtual int availableForWrite(); + + int read(void* buffer, size_t size); + + //size_t write(int); + size_t write(int32_t); + size_t write(const void *buffer, size_t size); + size_t write_blocking(const void *buffer, size_t size); + size_t write_nonblocking(const void *buffer, size_t size); + + void onTransmit(void(*)(void)); + void onReceive(void(*)(void)); + + int setBufferSize(int bufferSize); + int getBufferSize(); +private: + #if (SOC_I2S_SUPPORTS_ADC && SOC_I2S_SUPPORTS_DAC) + int _gpioToAdcUnit(gpio_num_t gpio_num, esp_i2s::adc_unit_t* adc_unit); + int _gpioToAdcChannel(gpio_num_t gpio_num, esp_i2s::adc_channel_t* adc_channel); + #endif + int begin(int mode, int sampleRate, int bitsPerSample, bool driveClock); + + int _enableTransmitter(); + int _enableReceiver(); + void _onTransferComplete(); + + int _createCallbackTask(); + + static void onDmaTransferComplete(void*); + int _installDriver(); + void _uninstallDriver(); + void _setSckPin(int sckPin); + void _setFsPin(int fsPin); + void _setDataPin(int sdPin); + void _setDataOutPin(int outSdPin); + void _setDataInPin(int inSdPin); + int _applyPinSetting(); + +private: + typedef enum { + I2S_STATE_IDLE, + I2S_STATE_TRANSMITTER, + I2S_STATE_RECEIVER, + I2S_STATE_DUPLEX + } i2s_state_t; + + int _deviceIndex; + int _sdPin; + int _inSdPin; + int _outSdPin; + int _sckPin; + int _fsPin; + + i2s_state_t _state; + int _bitsPerSample; + uint32_t _sampleRate; + int _mode; + + uint16_t _buffer_byte_size; + + bool _driverInstalled; // Is IDF I2S driver installed? + bool _initialized; // Is everything initialized (callback task, I2S driver, ring buffers)? + TaskHandle_t _callbackTaskHandle; + QueueHandle_t _i2sEventQueue; + SemaphoreHandle_t _i2s_general_mutex; + RingbufHandle_t _input_ring_buffer; + RingbufHandle_t _output_ring_buffer; + int _i2s_dma_buffer_size; + bool _driveClock; + uint32_t _peek_buff; + bool _peek_buff_valid; + + void _tx_done_routine(uint8_t* prev_item); + void _rx_done_routine(); + + uint16_t _nesting_counter; + void _take_if_not_holding(); + void _give_if_top_call(); + void _post_read_data_fix(void *input, size_t *size); + void _fix_and_write(void *output, size_t size, size_t *bytes_written = NULL, size_t *actual_bytes_written = NULL); + + void (*_onTransmit)(void); + void (*_onReceive)(void); +}; + +extern I2SClass I2S; + +#endif diff --git a/libraries/LittleFS/examples/LITTLEFS_PlatformIO/platformio.ini b/libraries/LittleFS/examples/LITTLEFS_PlatformIO/platformio.ini index 43e34ec0d34..4d3087a3012 100644 --- a/libraries/LittleFS/examples/LITTLEFS_PlatformIO/platformio.ini +++ b/libraries/LittleFS/examples/LITTLEFS_PlatformIO/platformio.ini @@ -16,17 +16,6 @@ framework = arduino [env:esp32] platform = espressif32 -;platform = https://github.com/platformio/platform-espressif32.git -;board_build.mcu = esp32 -platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git - -build_flags = - ${env.build_flags} - -D=${PIOENV} - ;-D CONFIG_LITTLEFS_FOR_IDF_3_2 - -lib_deps = https://github.com/lorol/LITTLEFS.git - board = esp32dev ;board_build.partitions = partitions_custom.csv monitor_filters = esp32_exception_decoder diff --git a/libraries/LittleFS/examples/LITTLEFS_time/LITTLEFS_time.ino b/libraries/LittleFS/examples/LITTLEFS_time/LITTLEFS_time.ino index bb5b9c3ae91..038261b1127 100644 --- a/libraries/LittleFS/examples/LITTLEFS_time/LITTLEFS_time.ino +++ b/libraries/LittleFS/examples/LITTLEFS_time/LITTLEFS_time.ino @@ -160,10 +160,6 @@ void setup(){ Serial.println("IP address: "); Serial.println(WiFi.localIP()); Serial.println("Contacting Time Server"); - /* - Note: Bundled Arduino lwip supports only ONE ntp server, 2nd and 3rd options are silently ignored - see CONFIG_LWIP_DHCP_MAX_NTP_SERVERS define in ./tools/sdk/esp32/sdkconfig - */ configTime(3600*timezone, daysavetime*3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org"); struct tm tmstruct ; delay(2000); diff --git a/libraries/README.md b/libraries/README.md index e7c77efbad5..5edeebba424 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -12,7 +12,9 @@ arduino-esp32 includes libraries for Arduino compatibility along with some objec Bluetooth Low Energy v4.2 client/server framework ### BluetoothSerial - Serial to Bluetooth redirection server + Serial to Bluetooth redirection server\ + Note: This library depends on Bluetooth Classic which is only available for ESP32\ + (Bluetoothserial is **not available** for ESP32-S2, ESP32-C3, ESP32-S3). ### DNSServer A basic UDP DNS daemon (includes captive portal demo) diff --git a/libraries/RainMaker/examples/README.md b/libraries/RainMaker/examples/README.md index 6c5bded09ac..0b978040085 100644 --- a/libraries/RainMaker/examples/README.md +++ b/libraries/RainMaker/examples/README.md @@ -1,10 +1,13 @@ # ESP RainMaker Examples While building any examples for ESP RainMaker, take care of the following: + 1. Change partition scheme in Arduino IDE to RainMaker (Tools -> Partition Scheme -> RainMaker). 2. Once ESP RainMaker gets started, compulsorily call `WiFi.beginProvision()` which is responsible for user-node mapping. -3. Use appropriate provisioning scheme as per the board. +3. Use the appropriate provisioning scheme as per the board. - ESP32 Board: BLE Provisioning - - ESP32S2 Board: SoftAP Provisioning -4. Set debug level to Info (Tools -> Core Debug Level -> Info). This is recommended, but not mandatory. + - ESP32-C3 Board: BLE Provisioning + - ESP32-S3 Board: BLE Provisioning + - ESP32-S2 Board: SoftAP Provisioning +4. Set debug level to Info (Tools -> Core Debug Level -> Info). This is recommended debug level but not mandatory to run RainMaker. diff --git a/libraries/RainMaker/examples/RMakerCustom/RMakerCustom.ino b/libraries/RainMaker/examples/RMakerCustom/RMakerCustom.ino index 55012e413c6..892f285415f 100644 --- a/libraries/RainMaker/examples/RMakerCustom/RMakerCustom.ino +++ b/libraries/RainMaker/examples/RMakerCustom/RMakerCustom.ino @@ -9,10 +9,15 @@ const char *service_name = "PROV_1234"; const char *pop = "abcd1234"; //GPIO for push button -static int gpio_0 = 0; +#if CONFIG_IDF_TARGET_ESP32C3 +static int gpio_0 = 9; +static int gpio_dimmer = 7; +#else //GPIO for virtual device +static int gpio_0 = 0; static int gpio_dimmer = 16; -/* Variable for reading pin status*/ +#endif + bool dimmer_state = true; // The framework provides some standard device types like switch, lightbulb, fan, temperature sensor. @@ -23,12 +28,12 @@ void sysProvEvent(arduino_event_t *sys_event) { switch (sys_event->event_id) { case ARDUINO_EVENT_PROV_START: -#if CONFIG_IDF_TARGET_ESP32 - Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop); - printQR(service_name, pop, "ble"); -#else +#if CONFIG_IDF_TARGET_ESP32S2 Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop); printQR(service_name, pop, "softap"); +#else + Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop); + printQR(service_name, pop, "ble"); #endif break; } @@ -89,10 +94,10 @@ void setup() RMaker.start(); WiFi.onEvent(sysProvEvent); -#if CONFIG_IDF_TARGET_ESP32 - WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, pop, service_name); -#else +#if CONFIG_IDF_TARGET_ESP32S2 WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_HANDLER_NONE, WIFI_PROV_SECURITY_1, pop, service_name); +#else + WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, pop, service_name); #endif } diff --git a/libraries/RainMaker/examples/RMakerSwitch/RMakerSwitch.ino b/libraries/RainMaker/examples/RMakerSwitch/RMakerSwitch.ino index e486bd200fb..11f11a586bd 100644 --- a/libraries/RainMaker/examples/RMakerSwitch/RMakerSwitch.ino +++ b/libraries/RainMaker/examples/RMakerSwitch/RMakerSwitch.ino @@ -8,9 +8,15 @@ const char *service_name = "PROV_1234"; const char *pop = "abcd1234"; //GPIO for push button -static int gpio_0 = 0; +#if CONFIG_IDF_TARGET_ESP32C3 +static int gpio_0 = 9; +static int gpio_switch = 7; +#else //GPIO for virtual device +static int gpio_0 = 0; static int gpio_switch = 16; +#endif + /* Variable for reading pin status*/ bool switch_state = true; @@ -21,13 +27,13 @@ void sysProvEvent(arduino_event_t *sys_event) { switch (sys_event->event_id) { case ARDUINO_EVENT_PROV_START: -#if CONFIG_IDF_TARGET_ESP32 - Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop); - printQR(service_name, pop, "ble"); -#else +#if CONFIG_IDF_TARGET_ESP32S2 Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop); printQR(service_name, pop, "softap"); -#endif +#else + Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop); + printQR(service_name, pop, "ble"); +#endif break; } } @@ -74,10 +80,10 @@ void setup() RMaker.start(); WiFi.onEvent(sysProvEvent); -#if CONFIG_IDF_TARGET_ESP32 - WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, pop, service_name); -#else +#if CONFIG_IDF_TARGET_ESP32S2 WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_HANDLER_NONE, WIFI_PROV_SECURITY_1, pop, service_name); +#else + WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, pop, service_name); #endif } diff --git a/libraries/RainMaker/src/RMaker.cpp b/libraries/RainMaker/src/RMaker.cpp index de6903c0538..2fda954c1ea 100644 --- a/libraries/RainMaker/src/RMaker.cpp +++ b/libraries/RainMaker/src/RMaker.cpp @@ -1,11 +1,12 @@ +#include "sdkconfig.h" +#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK #include "RMaker.h" -#if ESP_IDF_VERSION_MAJOR >= 4 && CONFIG_ESP_RMAKER_TASK_STACK && CONFIG_IDF_TARGET_ESP32 #include #include bool wifiLowLevelInit(bool persistent); static esp_err_t err; -static void event_handler(void *arg, esp_event_base_t event_base, int event_id, void *event_data) +static void event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) { if (event_base == RMAKER_EVENT) { switch (event_id) { diff --git a/libraries/RainMaker/src/RMaker.h b/libraries/RainMaker/src/RMaker.h index 53c60bce189..dbfbe5c49f5 100644 --- a/libraries/RainMaker/src/RMaker.h +++ b/libraries/RainMaker/src/RMaker.h @@ -1,6 +1,20 @@ +// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#pragma once +#include "sdkconfig.h" +#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK #include "esp_system.h" -#if ESP_IDF_VERSION_MAJOR >= 4 && CONFIG_ESP_RMAKER_TASK_STACK && CONFIG_IDF_TARGET_ESP32 - #include "Arduino.h" #include "RMakerNode.h" #include "RMakerQR.h" @@ -26,5 +40,4 @@ class RMakerClass }; extern RMakerClass RMaker; - -#endif +#endif \ No newline at end of file diff --git a/libraries/RainMaker/src/RMakerDevice.cpp b/libraries/RainMaker/src/RMakerDevice.cpp index e0108c32963..dd1a3ba4ea4 100644 --- a/libraries/RainMaker/src/RMakerDevice.cpp +++ b/libraries/RainMaker/src/RMakerDevice.cpp @@ -1,5 +1,6 @@ +#include "sdkconfig.h" +#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK #include "RMakerDevice.h" -#if ESP_IDF_VERSION_MAJOR >= 4 && CONFIG_ESP_RMAKER_TASK_STACK && CONFIG_IDF_TARGET_ESP32 static esp_err_t err; typedef void (*deviceWriteCb)(Device*, Param*, const param_val_t val, void *priv_data, write_ctx_t *ctx); @@ -205,5 +206,4 @@ esp_err_t Device::updateAndReportParam(const char *param_name, const char *my_va } return ESP_OK; } - #endif diff --git a/libraries/RainMaker/src/RMakerDevice.h b/libraries/RainMaker/src/RMakerDevice.h index 13cb67ac302..f813359a25a 100644 --- a/libraries/RainMaker/src/RMakerDevice.h +++ b/libraries/RainMaker/src/RMakerDevice.h @@ -1,6 +1,20 @@ +// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#pragma once +#include "sdkconfig.h" +#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK #include "esp_system.h" -#if ESP_IDF_VERSION_MAJOR >= 4 && CONFIG_ESP_RMAKER_TASK_STACK && CONFIG_IDF_TARGET_ESP32 - #include "RMakerParam.h" #include #include @@ -150,5 +164,4 @@ class TemperatureSensor : public Device } } }; - #endif \ No newline at end of file diff --git a/libraries/RainMaker/src/RMakerNode.cpp b/libraries/RainMaker/src/RMakerNode.cpp index 3f2555f8b05..5cae9e8dea9 100644 --- a/libraries/RainMaker/src/RMakerNode.cpp +++ b/libraries/RainMaker/src/RMakerNode.cpp @@ -1,5 +1,6 @@ +#include "sdkconfig.h" +#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK #include "RMakerNode.h" -#if ESP_IDF_VERSION_MAJOR >= 4 && CONFIG_ESP_RMAKER_TASK_STACK && CONFIG_IDF_TARGET_ESP32 static esp_err_t err; esp_err_t Node::addDevice(Device device) @@ -38,4 +39,4 @@ esp_err_t Node::addNodeAttr(const char *attr_name, const char *val) } return err; } -#endif +#endif \ No newline at end of file diff --git a/libraries/RainMaker/src/RMakerNode.h b/libraries/RainMaker/src/RMakerNode.h index 733ca407f96..d169870f591 100644 --- a/libraries/RainMaker/src/RMakerNode.h +++ b/libraries/RainMaker/src/RMakerNode.h @@ -1,6 +1,20 @@ +// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#pragma once +#include "sdkconfig.h" +#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK #include "esp_system.h" -#if ESP_IDF_VERSION_MAJOR >= 4 && CONFIG_ESP_RMAKER_TASK_STACK && CONFIG_IDF_TARGET_ESP32 - #include "RMakerDevice.h" class Node @@ -29,5 +43,4 @@ class Node node_info_t *getNodeInfo(); esp_err_t addNodeAttr(const char *attr_name, const char *val); }; - #endif \ No newline at end of file diff --git a/libraries/RainMaker/src/RMakerParam.cpp b/libraries/RainMaker/src/RMakerParam.cpp index e1de774017f..50a994c7590 100644 --- a/libraries/RainMaker/src/RMakerParam.cpp +++ b/libraries/RainMaker/src/RMakerParam.cpp @@ -1,5 +1,6 @@ +#include "sdkconfig.h" +#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK #include "RMakerParam.h" -#if ESP_IDF_VERSION_MAJOR >= 4 && CONFIG_ESP_RMAKER_TASK_STACK && CONFIG_IDF_TARGET_ESP32 static esp_err_t err; @@ -29,5 +30,4 @@ esp_err_t Param::updateAndReport(param_val_t val) } return err; } - -#endif \ No newline at end of file +#endif diff --git a/libraries/RainMaker/src/RMakerParam.h b/libraries/RainMaker/src/RMakerParam.h index 0bd9aedb116..d1b4ea6d9d6 100644 --- a/libraries/RainMaker/src/RMakerParam.h +++ b/libraries/RainMaker/src/RMakerParam.h @@ -1,6 +1,20 @@ +// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#pragma once +#include "sdkconfig.h" +#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK #include "esp_system.h" -#if ESP_IDF_VERSION_MAJOR >= 4 && CONFIG_ESP_RMAKER_TASK_STACK && CONFIG_IDF_TARGET_ESP32 - #include "RMakerType.h" class Param @@ -34,5 +48,4 @@ class Param esp_err_t addBounds(param_val_t min, param_val_t max, param_val_t step); esp_err_t updateAndReport(param_val_t val); }; - #endif \ No newline at end of file diff --git a/libraries/RainMaker/src/RMakerQR.h b/libraries/RainMaker/src/RMakerQR.h index fd5053d0dde..7b666557fcd 100644 --- a/libraries/RainMaker/src/RMakerQR.h +++ b/libraries/RainMaker/src/RMakerQR.h @@ -1,6 +1,20 @@ +// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#pragma once +#include "sdkconfig.h" +#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK #include "esp_system.h" -#if ESP_IDF_VERSION_MAJOR >= 4 && CONFIG_ESP_RMAKER_TASK_STACK && CONFIG_IDF_TARGET_ESP32 - #include #define PROV_QR_VERSION "v1" @@ -20,5 +34,4 @@ static void printQR(const char *name, const char *pop, const char *transport) qrcode_display(payload); Serial.printf("If QR code is not visible, copy paste the below URL in a browser.\n%s?data=%s\n", QRCODE_BASE_URL, payload); } - -#endif +#endif \ No newline at end of file diff --git a/libraries/RainMaker/src/RMakerType.cpp b/libraries/RainMaker/src/RMakerType.cpp index a4f6f2f381f..d94337cec4c 100644 --- a/libraries/RainMaker/src/RMakerType.cpp +++ b/libraries/RainMaker/src/RMakerType.cpp @@ -1,5 +1,6 @@ +#include "sdkconfig.h" +#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK #include "RMakerType.h" -#if ESP_IDF_VERSION_MAJOR >= 4 && CONFIG_ESP_RMAKER_TASK_STACK && CONFIG_IDF_TARGET_ESP32 param_val_t value(int ival) { @@ -20,5 +21,4 @@ param_val_t value(float fval) { return esp_rmaker_float(fval); } - #endif \ No newline at end of file diff --git a/libraries/RainMaker/src/RMakerType.h b/libraries/RainMaker/src/RMakerType.h index 09029f9e8a0..003bd32a523 100644 --- a/libraries/RainMaker/src/RMakerType.h +++ b/libraries/RainMaker/src/RMakerType.h @@ -1,6 +1,20 @@ +// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#pragma once +#include "sdkconfig.h" +#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK #include "esp_system.h" -#if ESP_IDF_VERSION_MAJOR >= 4 && CONFIG_ESP_RMAKER_TASK_STACK && CONFIG_IDF_TARGET_ESP32 - #include #include #include @@ -19,5 +33,4 @@ param_val_t value(int); param_val_t value(bool); param_val_t value(char *); param_val_t value(float); - #endif \ No newline at end of file diff --git a/libraries/RainMaker/src/RMakerUtils.h b/libraries/RainMaker/src/RMakerUtils.h index 41745d2e027..710b0e9a8a4 100644 --- a/libraries/RainMaker/src/RMakerUtils.h +++ b/libraries/RainMaker/src/RMakerUtils.h @@ -1,16 +1,29 @@ +// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#pragma once +#include "sdkconfig.h" +#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK #include "esp_system.h" -#if ESP_IDF_VERSION_MAJOR >= 4 && CONFIG_ESP_RMAKER_TASK_STACK && CONFIG_IDF_TARGET_ESP32 - #include static void RMakerFactoryReset(int seconds) { - esp_rmaker_factory_reset(seconds); + esp_rmaker_factory_reset(0, seconds); } static void RMakerWiFiReset(int seconds) { - esp_rmaker_wifi_reset(seconds); + esp_rmaker_wifi_reset(0, seconds); } - -#endif +#endif \ No newline at end of file diff --git a/libraries/SD/examples/SD_time/SD_time.ino b/libraries/SD/examples/SD_time/SD_time.ino index ff35d673448..cef80dd600c 100644 --- a/libraries/SD/examples/SD_time/SD_time.ino +++ b/libraries/SD/examples/SD_time/SD_time.ino @@ -164,10 +164,6 @@ void setup(){ Serial.println("IP address: "); Serial.println(WiFi.localIP()); Serial.println("Contacting Time Server"); - /* - Note: Bundled Arduino lwip supports only ONE ntp server, 2nd and 3rd options are silently ignored - see CONFIG_LWIP_DHCP_MAX_NTP_SERVERS define in ./tools/sdk/esp32/sdkconfig - */ configTime(3600*timezone, daysavetime*3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org"); struct tm tmstruct ; delay(2000); diff --git a/libraries/SD/src/SD.cpp b/libraries/SD/src/SD.cpp index 8e2b6d234e5..b1731f155ba 100644 --- a/libraries/SD/src/SD.cpp +++ b/libraries/SD/src/SD.cpp @@ -75,6 +75,22 @@ uint64_t SDFS::cardSize() return (uint64_t)sectors * sectorSize; } +size_t SDFS::numSectors() +{ + if(_pdrv == 0xFF) { + return 0; + } + return sdcard_num_sectors(_pdrv); +} + +size_t SDFS::sectorSize() +{ + if(_pdrv == 0xFF) { + return 0; + } + return sdcard_sector_size(_pdrv); +} + uint64_t SDFS::totalBytes() { FATFS* fsinfo; diff --git a/libraries/SD/src/SD.h b/libraries/SD/src/SD.h index 665b33370e4..a5548579bd7 100644 --- a/libraries/SD/src/SD.h +++ b/libraries/SD/src/SD.h @@ -32,6 +32,8 @@ class SDFS : public FS void end(); sdcard_type_t cardType(); uint64_t cardSize(); + size_t numSectors(); + size_t sectorSize(); uint64_t totalBytes(); uint64_t usedBytes(); bool readRAW(uint8_t* buffer, uint32_t sector); diff --git a/libraries/SD/src/sd_diskio.cpp b/libraries/SD/src/sd_diskio.cpp index e69050a74f1..038c26ade36 100644 --- a/libraries/SD/src/sd_diskio.cpp +++ b/libraries/SD/src/sd_diskio.cpp @@ -121,7 +121,7 @@ bool sdSelectCard(uint8_t pdrv) { ardu_sdcard_t * card = s_cards[pdrv]; digitalWrite(card->ssPin, LOW); - bool s = sdWait(pdrv, 300); + bool s = sdWait(pdrv, 500); if (!s) { log_e("Select Failed"); digitalWrite(card->ssPin, HIGH); @@ -506,10 +506,17 @@ DSTATUS ff_sd_initialize(uint8_t pdrv) card->spi->transfer(0XFF); } - if (sdTransaction(pdrv, GO_IDLE_STATE, 0, NULL) != 1) { + // Fix mount issue - sdWait fail ignored before command GO_IDLE_STATE + digitalWrite(card->ssPin, LOW); + if(!sdWait(pdrv, 500)){ + log_w("sdWait fail ignored, card initialize continues"); + } + if (sdCommand(pdrv, GO_IDLE_STATE, 0, NULL) != 1){ + sdDeselectCard(pdrv); log_w("GO_IDLE_STATE failed"); goto unknown_card; } + sdDeselectCard(pdrv); token = sdTransaction(pdrv, CRC_ON_OFF, 1, NULL); if (token == 0x5) { @@ -609,7 +616,7 @@ DSTATUS ff_sd_initialize(uint8_t pdrv) DSTATUS ff_sd_status(uint8_t pdrv) { - if(sdCommand(pdrv, SEND_STATUS, 0, NULL) == 0xFF) + if(sdTransaction(pdrv, SEND_STATUS, 0, NULL)) { log_e("Check status failed"); return STA_NOINIT; diff --git a/libraries/SD_MMC/examples/SDMMC_time/SDMMC_time.ino b/libraries/SD_MMC/examples/SDMMC_time/SDMMC_time.ino index c15a1648a3c..4472f8c6c37 100644 --- a/libraries/SD_MMC/examples/SDMMC_time/SDMMC_time.ino +++ b/libraries/SD_MMC/examples/SDMMC_time/SDMMC_time.ino @@ -164,10 +164,6 @@ void setup(){ Serial.println("IP address: "); Serial.println(WiFi.localIP()); Serial.println("Contacting Time Server"); - /* - Note: Bundled Arduino lwip supports only ONE ntp server, 2nd and 3rd options are silently ignored - see CONFIG_LWIP_DHCP_MAX_NTP_SERVERS define in ./tools/sdk/esp32/sdkconfig - */ configTime(3600*timezone, daysavetime*3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org"); struct tm tmstruct ; delay(2000); diff --git a/libraries/SD_MMC/src/SD_MMC.cpp b/libraries/SD_MMC/src/SD_MMC.cpp index ba06c261cf9..07fab237942 100644 --- a/libraries/SD_MMC/src/SD_MMC.cpp +++ b/libraries/SD_MMC/src/SD_MMC.cpp @@ -1,4 +1,4 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,29 +12,77 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "pins_arduino.h" #include "SD_MMC.h" -#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) //SDMMC does not work on ESP32S2 +#ifdef SOC_SDMMC_HOST_SUPPORTED #include "vfs_api.h" -extern "C" { -#include -#include #include #include "esp_vfs_fat.h" #include "driver/sdmmc_host.h" #include "driver/sdmmc_defs.h" #include "sdmmc_cmd.h" -} +#include "soc/sdmmc_pins.h" #include "ff.h" using namespace fs; -/* -*/ SDMMCFS::SDMMCFS(FSImplPtr impl) - : FS(impl), _card(NULL) -{} + : FS(impl), _card(nullptr) +{ +#if defined(SOC_SDMMC_USE_GPIO_MATRIX) && defined(BOARD_HAS_SDMMC) + _pin_clk = SDMMC_CLK; + _pin_cmd = SDMMC_CMD; + _pin_d0 = SDMMC_D0; +#ifndef BOARD_HAS_1BIT_SDMMC + _pin_d1 = SDMMC_D1; + _pin_d2 = SDMMC_D2; + _pin_d3 = SDMMC_D3; +#endif // BOARD_HAS_1BIT_SDMMC +#endif // defined(SOC_SDMMC_USE_GPIO_MATRIX) && defined(BOARD_HAS_SDMMC) +} + +bool SDMMCFS::setPins(int clk, int cmd, int d0) +{ + return setPins(clk, cmd, d0, GPIO_NUM_NC, GPIO_NUM_NC, GPIO_NUM_NC); +} + +bool SDMMCFS::setPins(int clk, int cmd, int d0, int d1, int d2, int d3) +{ + if (_card != nullptr) { + log_e("SD_MMC.setPins must be called before SD_MMC.begin"); + return false; + } +#ifdef SOC_SDMMC_USE_GPIO_MATRIX + // SoC supports SDMMC pin configuration via GPIO matrix. Save the pins for later use in SDMMCFS::begin. + _pin_clk = (int8_t) clk; + _pin_cmd = (int8_t) cmd; + _pin_d0 = (int8_t) d0; + _pin_d1 = (int8_t) d1; + _pin_d2 = (int8_t) d2; + _pin_d3 = (int8_t) d3; + return true; +#elif CONFIG_IDF_TARGET_ESP32 + // ESP32 doesn't support SDMMC pin configuration via GPIO matrix. + // Since SDMMCFS::begin hardcodes the usage of slot 1, only check if + // the pins match slot 1 pins. + bool pins_ok = (clk == (int)SDMMC_SLOT1_IOMUX_PIN_NUM_CLK) && + (cmd == (int)SDMMC_SLOT1_IOMUX_PIN_NUM_CMD) && + (d0 == (int)SDMMC_SLOT1_IOMUX_PIN_NUM_D0) && + (((d1 == -1) && (d2 == -1) && (d3 == -1)) || + ((d1 == (int)SDMMC_SLOT1_IOMUX_PIN_NUM_D1) && + (d1 == (int)SDMMC_SLOT1_IOMUX_PIN_NUM_D2) && + (d1 == (int)SDMMC_SLOT1_IOMUX_PIN_NUM_D3))); + if (!pins_ok) { + log_e("SDMMCFS: specified pins are not supported by this chip."); + return false; + } + return true; +#else +#error SoC not supported +#endif +} bool SDMMCFS::begin(const char * mountpoint, bool mode1bit, bool format_if_mount_failed, int sdmmc_frequency) { @@ -43,27 +91,33 @@ bool SDMMCFS::begin(const char * mountpoint, bool mode1bit, bool format_if_mount } //mount sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT(); - sdmmc_host_t host; +#ifdef SOC_SDMMC_USE_GPIO_MATRIX + // SoC supports SDMMC pin configuration via GPIO matrix. + // Chech that the pins have been set either in the constructor or setPins function. + if (_pin_cmd == -1 || _pin_clk == -1 || _pin_d0 == -1 + || (!mode1bit && (_pin_d1 == -1 || _pin_d2 == -1 || _pin_d3 == -1))) { + log_e("SDMMCFS: some SD pins are not set"); + return false; + } + + slot_config.clk = (gpio_num_t) _pin_clk; + slot_config.cmd = (gpio_num_t) _pin_cmd; + slot_config.d0 = (gpio_num_t) _pin_d0; + slot_config.d1 = (gpio_num_t) _pin_d1; + slot_config.d2 = (gpio_num_t) _pin_d2; + slot_config.d3 = (gpio_num_t) _pin_d3; + slot_config.width = 4; +#endif // SOC_SDMMC_USE_GPIO_MATRIX + sdmmc_host_t host = SDMMC_HOST_DEFAULT(); host.flags = SDMMC_HOST_FLAG_4BIT; host.slot = SDMMC_HOST_SLOT_1; host.max_freq_khz = sdmmc_frequency; - host.io_voltage = 3.3f; - host.init = &sdmmc_host_init; - host.set_bus_width = &sdmmc_host_set_bus_width; - host.get_bus_width = &sdmmc_host_get_slot_width; - host.set_bus_ddr_mode = &sdmmc_host_set_bus_ddr_mode; - host.set_card_clk = &sdmmc_host_set_card_clk; - host.do_transaction = &sdmmc_host_do_transaction; - host.deinit = &sdmmc_host_deinit; - host.io_int_enable = &sdmmc_host_io_int_enable; - host.io_int_wait = &sdmmc_host_io_int_wait; - host.command_timeout_ms = 0; #ifdef BOARD_HAS_1BIT_SDMMC mode1bit = true; #endif if(mode1bit) { host.flags = SDMMC_HOST_FLAG_1BIT; //use 1-line SD mode - slot_config.width = 1; + slot_config.width = 1; } esp_vfs_fat_sdmmc_mount_config_t mount_config = { @@ -81,7 +135,7 @@ bool SDMMCFS::begin(const char * mountpoint, bool mode1bit, bool format_if_mount log_w("SD Already mounted"); return true; } else { - log_e("Failed to initialize the card (%d). Make sure SD card lines have pull-up resistors in place.", ret); + log_e("Failed to initialize the card (0x%x). Make sure SD card lines have pull-up resistors in place.", ret); } _card = NULL; return false; @@ -144,4 +198,4 @@ uint64_t SDMMCFS::usedBytes() } SDMMCFS SD_MMC = SDMMCFS(FSImplPtr(new VFSImpl())); -#endif /* CONFIG_IDF_TARGET_ESP32 */ +#endif /* SOC_SDMMC_HOST_SUPPORTED */ diff --git a/libraries/SD_MMC/src/SD_MMC.h b/libraries/SD_MMC/src/SD_MMC.h index e8540b32fc4..8386b23c030 100644 --- a/libraries/SD_MMC/src/SD_MMC.h +++ b/libraries/SD_MMC/src/SD_MMC.h @@ -15,7 +15,8 @@ #define _SDMMC_H_ #include "sdkconfig.h" -#ifndef CONFIG_IDF_TARGET_ESP32S2 +#include "soc/soc_caps.h" +#ifdef SOC_SDMMC_HOST_SUPPORTED #include "FS.h" #include "driver/sdmmc_types.h" @@ -36,8 +37,19 @@ class SDMMCFS : public FS protected: sdmmc_card_t* _card; +#ifdef SOC_SDMMC_USE_GPIO_MATRIX + int8_t _pin_clk = -1; + int8_t _pin_cmd = -1; + int8_t _pin_d0 = -1; + int8_t _pin_d1 = -1; + int8_t _pin_d2 = -1; + int8_t _pin_d3 = -1; +#endif + public: SDMMCFS(FSImplPtr impl); + bool setPins(int clk, int cmd, int d0); + bool setPins(int clk, int cmd, int d0, int d1, int d2, int d3); bool begin(const char * mountpoint="/sdcard", bool mode1bit=false, bool format_if_mount_failed=false, int sdmmc_frequency=BOARD_MAX_SDMMC_FREQ); void end(); sdcard_type_t cardType(); @@ -50,5 +62,5 @@ class SDMMCFS : public FS extern fs::SDMMCFS SD_MMC; -#endif /* CONFIG_IDF_TARGET_ESP32S2 */ +#endif /* SOC_SDMMC_HOST_SUPPORTED */ #endif /* _SDMMC_H_ */ diff --git a/libraries/SPI/examples/SPI_Multiple_Buses/SPI_Multiple_Buses.ino b/libraries/SPI/examples/SPI_Multiple_Buses/SPI_Multiple_Buses.ino index dcd6f7ed648..b0991d5fe3f 100644 --- a/libraries/SPI/examples/SPI_Multiple_Buses/SPI_Multiple_Buses.ino +++ b/libraries/SPI/examples/SPI_Multiple_Buses/SPI_Multiple_Buses.ino @@ -39,7 +39,7 @@ #define HSPI_SS 15 #endif -#if CONFIG_IDF_TARGET_ESP32S2 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 #define VSPI FSPI #endif diff --git a/libraries/SPI/src/SPI.cpp b/libraries/SPI/src/SPI.cpp index 5e938f02f7c..90d54a4bb60 100644 --- a/libraries/SPI/src/SPI.cpp +++ b/libraries/SPI/src/SPI.cpp @@ -50,7 +50,7 @@ void SPIClass::begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss) } if(sck == -1 && miso == -1 && mosi == -1 && ss == -1) { -#if CONFIG_IDF_TARGET_ESP32S2 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 _sck = (_spi_num == FSPI) ? SCK : -1; _miso = (_spi_num == FSPI) ? MISO : -1; _mosi = (_spi_num == FSPI) ? MOSI : -1; diff --git a/libraries/SPIFFS/examples/SPIFFS_time/SPIFFS_time.ino b/libraries/SPIFFS/examples/SPIFFS_time/SPIFFS_time.ino index 60cd6484dfd..a86759693a9 100644 --- a/libraries/SPIFFS/examples/SPIFFS_time/SPIFFS_time.ino +++ b/libraries/SPIFFS/examples/SPIFFS_time/SPIFFS_time.ino @@ -148,10 +148,6 @@ void setup(){ Serial.println("IP address: "); Serial.println(WiFi.localIP()); Serial.println("Contacting Time Server"); - /* - Note: Bundled Arduino lwip supports only ONE ntp server, 2nd and 3rd options are silently ignored - see CONFIG_LWIP_DHCP_MAX_NTP_SERVERS define in ./tools/sdk/esp32/sdkconfig - */ configTime(3600*timezone, daysavetime*3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org"); struct tm tmstruct ; delay(2000); diff --git a/libraries/Ticker/src/Ticker.cpp b/libraries/Ticker/src/Ticker.cpp index 1deeb7fb69f..629361b2dd0 100644 --- a/libraries/Ticker/src/Ticker.cpp +++ b/libraries/Ticker/src/Ticker.cpp @@ -56,3 +56,8 @@ void Ticker::detach() { _timer = nullptr; } } + +bool Ticker::active() { + if (!_timer) return false; + return esp_timer_is_active(_timer); +} diff --git a/libraries/USB/examples/CompositeDevice/CompositeDevice.ino b/libraries/USB/examples/CompositeDevice/CompositeDevice.ino index af811420590..4c1021bc57b 100644 --- a/libraries/USB/examples/CompositeDevice/CompositeDevice.ino +++ b/libraries/USB/examples/CompositeDevice/CompositeDevice.ino @@ -1,3 +1,8 @@ +#if ARDUINO_USB_MODE +#warning This sketch should be used when USB is in OTG mode +void setup(){} +void loop(){} +#else #include "USB.h" #include "USBHIDMouse.h" #include "USBHIDKeyboard.h" @@ -73,7 +78,10 @@ static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t eve } HWSerial.println(); break; - + case ARDUINO_USB_CDC_RX_OVERFLOW_EVENT: + HWSerial.printf("CDC RX Overflow of %d bytes", data->rx_overflow.dropped_bytes); + break; + default: break; } @@ -211,3 +219,4 @@ void loop() { } } } +#endif /* ARDUINO_USB_MODE */ diff --git a/libraries/USB/examples/ConsumerControl/ConsumerControl.ino b/libraries/USB/examples/ConsumerControl/ConsumerControl.ino index ab6fb19d9ca..d2747f8a428 100644 --- a/libraries/USB/examples/ConsumerControl/ConsumerControl.ino +++ b/libraries/USB/examples/ConsumerControl/ConsumerControl.ino @@ -1,3 +1,8 @@ +#if ARDUINO_USB_MODE +#warning This sketch should be used when USB is in OTG mode +void setup(){} +void loop(){} +#else #include "USB.h" #include "USBHIDConsumerControl.h" USBHIDConsumerControl ConsumerControl; @@ -19,3 +24,4 @@ void loop() { } previousButtonState = buttonState; } +#endif /* ARDUINO_USB_MODE */ diff --git a/libraries/USB/examples/CustomHIDDevice/CustomHIDDevice.ino b/libraries/USB/examples/CustomHIDDevice/CustomHIDDevice.ino index 15d69b6a63b..3644b167fed 100644 --- a/libraries/USB/examples/CustomHIDDevice/CustomHIDDevice.ino +++ b/libraries/USB/examples/CustomHIDDevice/CustomHIDDevice.ino @@ -1,3 +1,8 @@ +#if ARDUINO_USB_MODE +#warning This sketch should be used when USB is in OTG mode +void setup(){} +void loop(){} +#else #include "USB.h" #include "USBHID.h" USBHID HID; @@ -50,6 +55,7 @@ public: }; CustomHIDDevice Device; +#endif /* ARDUINO_USB_MODE */ const int buttonPin = 0; int previousButtonState = HIGH; diff --git a/libraries/USB/examples/FirmwareMSC/FirmwareMSC.ino b/libraries/USB/examples/FirmwareMSC/FirmwareMSC.ino index afcd2783b40..4b82cad5f66 100644 --- a/libraries/USB/examples/FirmwareMSC/FirmwareMSC.ino +++ b/libraries/USB/examples/FirmwareMSC/FirmwareMSC.ino @@ -1,3 +1,8 @@ +#if ARDUINO_USB_MODE +#warning This sketch should be used when USB is in OTG mode +void setup(){} +void loop(){} +#else #include "USB.h" #include "FirmwareMSC.h" @@ -72,3 +77,4 @@ void setup() { void loop() { // put your main code here, to run repeatedly } +#endif /* ARDUINO_USB_MODE */ diff --git a/libraries/USB/examples/Gamepad/Gamepad.ino b/libraries/USB/examples/Gamepad/Gamepad.ino index da9ff69e9dd..dad75723797 100644 --- a/libraries/USB/examples/Gamepad/Gamepad.ino +++ b/libraries/USB/examples/Gamepad/Gamepad.ino @@ -1,3 +1,8 @@ +#if ARDUINO_USB_MODE +#warning This sketch should be used when USB is in OTG mode +void setup(){} +void loop(){} +#else #include "USB.h" #include "USBHIDGamepad.h" USBHIDGamepad Gamepad; @@ -19,3 +24,4 @@ void loop() { } previousButtonState = buttonState; } +#endif /* ARDUINO_USB_MODE */ diff --git a/libraries/USB/examples/HIDVendor/HIDVendor.ino b/libraries/USB/examples/HIDVendor/HIDVendor.ino index 223edba1d90..01b91596026 100644 --- a/libraries/USB/examples/HIDVendor/HIDVendor.ino +++ b/libraries/USB/examples/HIDVendor/HIDVendor.ino @@ -1,3 +1,8 @@ +#if ARDUINO_USB_MODE +#warning This sketch should be used when USB is in OTG mode +void setup(){} +void loop(){} +#else #include "USB.h" #include "USBHIDVendor.h" USBHIDVendor Vendor; @@ -50,3 +55,4 @@ void loop() { Serial.write(Vendor.read()); } } +#endif /* ARDUINO_USB_MODE */ diff --git a/libraries/USB/examples/Keyboard/KeyboardLogout/KeyboardLogout.ino b/libraries/USB/examples/Keyboard/KeyboardLogout/KeyboardLogout.ino index a7f8214b78a..b4b21180031 100644 --- a/libraries/USB/examples/Keyboard/KeyboardLogout/KeyboardLogout.ino +++ b/libraries/USB/examples/Keyboard/KeyboardLogout/KeyboardLogout.ino @@ -24,6 +24,11 @@ http://www.arduino.cc/en/Tutorial/KeyboardLogout */ +#if ARDUINO_USB_MODE +#warning This sketch should be used when USB is in OTG mode +void setup(){} +void loop(){} +#else #define OSX 0 #define WINDOWS 1 @@ -90,3 +95,4 @@ void loop() { // do nothing: while (true) delay(1000); } +#endif /* ARDUINO_USB_MODE */ diff --git a/libraries/USB/examples/Keyboard/KeyboardMessage/KeyboardMessage.ino b/libraries/USB/examples/Keyboard/KeyboardMessage/KeyboardMessage.ino index 30f92a47821..d87a3384613 100644 --- a/libraries/USB/examples/Keyboard/KeyboardMessage/KeyboardMessage.ino +++ b/libraries/USB/examples/Keyboard/KeyboardMessage/KeyboardMessage.ino @@ -19,6 +19,11 @@ http://www.arduino.cc/en/Tutorial/KeyboardMessage */ +#if ARDUINO_USB_MODE +#warning This sketch should be used when USB is in OTG mode +void setup(){} +void loop(){} +#else #include "USB.h" #include "USBHIDKeyboard.h" @@ -53,3 +58,4 @@ void loop() { // save the current button state for comparison next time: previousButtonState = buttonState; } +#endif /* ARDUINO_USB_MODE */ diff --git a/libraries/USB/examples/Keyboard/KeyboardReprogram/KeyboardReprogram.ino b/libraries/USB/examples/Keyboard/KeyboardReprogram/KeyboardReprogram.ino index 3c6520556fe..e1a28add531 100644 --- a/libraries/USB/examples/Keyboard/KeyboardReprogram/KeyboardReprogram.ino +++ b/libraries/USB/examples/Keyboard/KeyboardReprogram/KeyboardReprogram.ino @@ -24,6 +24,11 @@ http://www.arduino.cc/en/Tutorial/KeyboardReprogram */ +#if ARDUINO_USB_MODE +#warning This sketch should be used when USB is in OTG mode +void setup(){} +void loop(){} +#else #include "USB.h" #include "USBHIDKeyboard.h" @@ -104,3 +109,4 @@ void loop() { // wait for the sweet oblivion of reprogramming: while (true)delay(1000); } +#endif /* ARDUINO_USB_MODE */ diff --git a/libraries/USB/examples/Keyboard/KeyboardSerial/KeyboardSerial.ino b/libraries/USB/examples/Keyboard/KeyboardSerial/KeyboardSerial.ino index e3bb8769737..2517634b1e8 100644 --- a/libraries/USB/examples/Keyboard/KeyboardSerial/KeyboardSerial.ino +++ b/libraries/USB/examples/Keyboard/KeyboardSerial/KeyboardSerial.ino @@ -16,6 +16,11 @@ http://www.arduino.cc/en/Tutorial/KeyboardSerial */ +#if ARDUINO_USB_MODE +#warning This sketch should be used when USB is in OTG mode +void setup(){} +void loop(){} +#else #include "USB.h" #include "USBHIDKeyboard.h" @@ -38,3 +43,4 @@ void loop() { Keyboard.write(inChar + 1); } } +#endif /* ARDUINO_USB_MODE */ diff --git a/libraries/USB/examples/KeyboardAndMouseControl/KeyboardAndMouseControl.ino b/libraries/USB/examples/KeyboardAndMouseControl/KeyboardAndMouseControl.ino index 6cf564bbc9f..b836e4f6bfe 100644 --- a/libraries/USB/examples/KeyboardAndMouseControl/KeyboardAndMouseControl.ino +++ b/libraries/USB/examples/KeyboardAndMouseControl/KeyboardAndMouseControl.ino @@ -18,6 +18,11 @@ http://www.arduino.cc/en/Tutorial/KeyboardAndMouseControl */ +#if ARDUINO_USB_MODE +#warning This sketch should be used when USB is in OTG mode +void setup(){} +void loop(){} +#else #include "USB.h" #include "USBHIDMouse.h" @@ -93,3 +98,4 @@ void loop() { } delay(5); } +#endif /* ARDUINO_USB_MODE */ diff --git a/libraries/USB/examples/Mouse/ButtonMouseControl/ButtonMouseControl.ino b/libraries/USB/examples/Mouse/ButtonMouseControl/ButtonMouseControl.ino index 0a7ee0caa34..02ccb8885db 100644 --- a/libraries/USB/examples/Mouse/ButtonMouseControl/ButtonMouseControl.ino +++ b/libraries/USB/examples/Mouse/ButtonMouseControl/ButtonMouseControl.ino @@ -20,6 +20,11 @@ http://www.arduino.cc/en/Tutorial/ButtonMouseControl */ +#if ARDUINO_USB_MODE +#warning This sketch should be used when USB is in OTG mode +void setup(){} +void loop(){} +#else #include "USB.h" #include "USBHIDMouse.h" @@ -84,3 +89,4 @@ void loop() { // a delay so the mouse doesn't move too fast: delay(responseDelay); } +#endif /* ARDUINO_USB_MODE */ diff --git a/libraries/USB/examples/SystemControl/SystemControl.ino b/libraries/USB/examples/SystemControl/SystemControl.ino index 7d644ea9164..2e91a28b353 100644 --- a/libraries/USB/examples/SystemControl/SystemControl.ino +++ b/libraries/USB/examples/SystemControl/SystemControl.ino @@ -1,3 +1,8 @@ +#if ARDUINO_USB_MODE +#warning This sketch should be used when USB is in OTG mode +void setup(){} +void loop(){} +#else #include "USB.h" #include "USBHIDSystemControl.h" USBHIDSystemControl SystemControl; @@ -19,3 +24,4 @@ void loop() { } previousButtonState = buttonState; } +#endif /* ARDUINO_USB_MODE */ diff --git a/libraries/USB/examples/USBMSC/USBMSC.ino b/libraries/USB/examples/USBMSC/USBMSC.ino index 0249c3ce14e..67378109985 100644 --- a/libraries/USB/examples/USBMSC/USBMSC.ino +++ b/libraries/USB/examples/USBMSC/USBMSC.ino @@ -1,3 +1,8 @@ +#if ARDUINO_USB_MODE +#warning This sketch should be used when USB is in OTG mode +void setup(){} +void loop(){} +#else #include "USB.h" #include "USBMSC.h" @@ -190,3 +195,4 @@ void setup() { void loop() { // put your main code here, to run repeatedly: } +#endif /* ARDUINO_USB_MODE */ diff --git a/libraries/USB/examples/USBSerial/USBSerial.ino b/libraries/USB/examples/USBSerial/USBSerial.ino index bb23418f507..0f57e2b1b1d 100644 --- a/libraries/USB/examples/USBSerial/USBSerial.ino +++ b/libraries/USB/examples/USBSerial/USBSerial.ino @@ -1,3 +1,8 @@ +#if ARDUINO_USB_MODE +#warning This sketch should be used when USB is in OTG mode +void setup(){} +void loop(){} +#else #include "USB.h" #if ARDUINO_USB_CDC_ON_BOOT @@ -52,7 +57,10 @@ static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t eve } HWSerial.println(); break; - + case ARDUINO_USB_CDC_RX_OVERFLOW_EVENT: + HWSerial.printf("CDC RX Overflow of %d bytes", data->rx_overflow.dropped_bytes); + break; + default: break; } @@ -78,3 +86,4 @@ void loop() { USBSerial.write(b, l); } } +#endif /* ARDUINO_USB_MODE */ diff --git a/libraries/USB/examples/USBVendor/USBVendor.ino b/libraries/USB/examples/USBVendor/USBVendor.ino index f8976a07e85..9dbb54fb6e2 100644 --- a/libraries/USB/examples/USBVendor/USBVendor.ino +++ b/libraries/USB/examples/USBVendor/USBVendor.ino @@ -1,3 +1,8 @@ +#if ARDUINO_USB_MODE +#warning This sketch should be used when USB is in OTG mode +void setup(){} +void loop(){} +#else #include "USB.h" #include "USBVendor.h" @@ -189,3 +194,4 @@ void loop() { Vendor.write(b, l); } } +#endif /* ARDUINO_USB_MODE */ diff --git a/libraries/USB/src/USBHIDKeyboard.h b/libraries/USB/src/USBHIDKeyboard.h index 5f9fdfc4696..41b6db9d8fc 100644 --- a/libraries/USB/src/USBHIDKeyboard.h +++ b/libraries/USB/src/USBHIDKeyboard.h @@ -114,7 +114,6 @@ class USBHIDKeyboard: public USBHIDDevice, public Print private: USBHID hid; KeyReport _keyReport; - void sendReport(KeyReport* keys); public: USBHIDKeyboard(void); void begin(void); @@ -124,6 +123,7 @@ class USBHIDKeyboard: public USBHIDDevice, public Print size_t press(uint8_t k); size_t release(uint8_t k); void releaseAll(void); + void sendReport(KeyReport* keys); //raw functions work with TinyUSB's HID_KEY_* macros size_t pressRaw(uint8_t k); diff --git a/libraries/Update/src/HttpsOTAUpdate.h b/libraries/Update/src/HttpsOTAUpdate.h index bc52a3055ce..c2030a96477 100644 --- a/libraries/Update/src/HttpsOTAUpdate.h +++ b/libraries/Update/src/HttpsOTAUpdate.h @@ -1,3 +1,5 @@ +#ifndef HTPSPOTUADATE_H +#define HTPSPOTUADATE_H #include "esp_http_client.h" #define HttpEvent_t esp_http_client_event_t @@ -19,3 +21,4 @@ class HttpsOTAUpdateClass { }; extern HttpsOTAUpdateClass HttpsOTA; +#endif diff --git a/libraries/WebServer/examples/SDWebServer/SdRoot/edit/index.htm b/libraries/WebServer/examples/SDWebServer/SdRoot/edit/index.htm index f535601e7d7..bca3dd05dd7 100644 --- a/libraries/WebServer/examples/SDWebServer/SdRoot/edit/index.htm +++ b/libraries/WebServer/examples/SDWebServer/SdRoot/edit/index.htm @@ -375,7 +375,7 @@ function createTreeLeaf(path, name, size){ var leaf = document.createElement("li"); - leaf.id = (((path == "/")?"":path)+"/"+name).toLowerCase(); + leaf.id = name.toLowerCase(); var label = document.createElement("span"); label.textContent = name.toLowerCase(); leaf.appendChild(label); @@ -398,7 +398,7 @@ var leaf = document.createElement("li"); var check = document.createElement("input"); check.type = "checkbox"; - check.id = (((path == "/")?"":path)+"/"+name).toLowerCase(); + check.id = name.toLowerCase(); if(typeof disabled !== "undefined" && disabled) check.disabled = "disabled"; leaf.appendChild(check); var label = document.createElement("label"); diff --git a/libraries/WebServer/src/WebServer.h b/libraries/WebServer/src/WebServer.h index c169da82229..0293a09f209 100644 --- a/libraries/WebServer/src/WebServer.h +++ b/libraries/WebServer/src/WebServer.h @@ -85,13 +85,13 @@ class WebServer void requestAuthentication(HTTPAuthMethod mode = BASIC_AUTH, const char* realm = NULL, const String& authFailMsg = String("") ); typedef std::function THandlerFunction; - void on(const Uri &uri, THandlerFunction handler); - void on(const Uri &uri, HTTPMethod method, THandlerFunction fn); - void on(const Uri &uri, HTTPMethod method, THandlerFunction fn, THandlerFunction ufn); + void on(const Uri &uri, THandlerFunction fn); + void on(const Uri &uri, HTTPMethod method, THandlerFunction fn); + void on(const Uri &uri, HTTPMethod method, THandlerFunction fn, THandlerFunction ufn); //ufn handles file uploads void addHandler(RequestHandler* handler); void serveStatic(const char* uri, fs::FS& fs, const char* path, const char* cache_header = NULL ); void onNotFound(THandlerFunction fn); //called when handler is not assigned - void onFileUpload(THandlerFunction fn); //handle file uploads + void onFileUpload(THandlerFunction ufn); //handle file uploads String uri() { return _currentUri; } HTTPMethod method() { return _currentMethod; } diff --git a/libraries/WebServer/src/detail/RequestHandlersImpl.h b/libraries/WebServer/src/detail/RequestHandlersImpl.h index 699015746b3..4a7c28e58ae 100644 --- a/libraries/WebServer/src/detail/RequestHandlersImpl.h +++ b/libraries/WebServer/src/detail/RequestHandlersImpl.h @@ -68,7 +68,8 @@ class StaticRequestHandler : public RequestHandler { , _path(path) , _cache_header(cache_header) { - _isFile = fs.exists(path); + File f = fs.open(path); + _isFile = (f && (! f.isDirectory())); log_v("StaticRequestHandler: path=%s uri=%s isFile=%d, cache_header=%s\r\n", path, uri, _isFile, cache_header ? cache_header : ""); // issue 5506 - cache_header can be nullptr _baseUriLength = _uri.length(); } diff --git a/libraries/WiFi/examples/WiFiClientEnterprise/WiFiClientEnterprise.ino b/libraries/WiFi/examples/WiFiClientEnterprise/WiFiClientEnterprise.ino index d7a2d0ad3cf..caaa2139170 100644 --- a/libraries/WiFi/examples/WiFiClientEnterprise/WiFiClientEnterprise.ino +++ b/libraries/WiFi/examples/WiFiClientEnterprise/WiFiClientEnterprise.ino @@ -1,10 +1,22 @@ #include //Wifi library #include "esp_wpa2.h" //wpa2 library for connections to Enterprise networks #define EAP_IDENTITY "login" //if connecting from another corporation, use identity@organisation.domain in Eduroam +#define EAP_USERNAME "login" //oftentimes just a repeat of the identity #define EAP_PASSWORD "password" //your Eduroam password const char* ssid = "eduroam"; // Eduroam SSID const char* host = "arduino.php5.sk"; //external server domain for HTTP connection after authentification int counter = 0; + +// NOTE: For some systems, various certification keys are required to connect to the wifi system. +// Usually you are provided these by the IT department of your organization when certs are required +// and you can't connect with just an identity and password. +// Most eduroam setups we have seen do not require this level of authentication, but you should contact +// your IT department to verify. +// You should uncomment these and populate with the contents of the files if this is required for your scenario (See Example 2 and Example 3 below). +//const char *ca_pem = "insert your CA cert from your .pem file here"; +//const char *client_cert = "insert your client cert from your .crt file here"; +//const char *client_key = "insert your client key from your .key file here"; + void setup() { Serial.begin(115200); delay(10); @@ -13,11 +25,17 @@ void setup() { Serial.println(ssid); WiFi.disconnect(true); //disconnect form wifi to set new wifi connection WiFi.mode(WIFI_STA); //init wifi mode - esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide identity - esp_wifi_sta_wpa2_ent_set_username((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide username --> identity and username is same - esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD)); //provide password - esp_wifi_sta_wpa2_ent_enable(); - WiFi.begin(ssid); //connect to wifi + + // Example1 (most common): a cert-file-free eduroam with PEAP (or TTLS) + WiFi.begin(ssid, WPA2_AUTH_PEAP, EAP_IDENTITY, EAP_USERNAME, EAP_PASSWORD); + + // Example 2: a cert-file WPA2 Enterprise with PEAP + //WiFi.begin(ssid, WPA2_AUTH_PEAP, EAP_IDENTITY, EAP_USERNAME, EAP_PASSWORD, ca_pem, client_cert, client_key); + + // Example 3: TLS with cert-files and no password + //WiFi.begin(ssid, WPA2_AUTH_TLS, EAP_IDENTITY, NULL, NULL, ca_pem, client_cert, client_key); + + while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); diff --git a/libraries/WiFi/examples/WiFiScanDualAntenna/README.md b/libraries/WiFi/examples/WiFiScanDualAntenna/README.md new file mode 100644 index 00000000000..32131a2b6ac --- /dev/null +++ b/libraries/WiFi/examples/WiFiScanDualAntenna/README.md @@ -0,0 +1,70 @@ +# WiFiScan Example + +This example demonstrates how to use the WiFi library to scan available WiFi networks and print the results. + +This example shows the basic functionality of the dual antenna capability. + +# Supported Targets + +This example is compatible with the ESP32-WROOM-DA. + +## How to Use Example + +* How to install the Arduino IDE: [Install Arduino IDE](https://github.com/espressif/arduino-esp32/tree/master/docs/arduino-ide). + +#### Using Arduino IDE + +* Before Compile/Verify, select the correct board: `Tools -> Board`. +* Select the COM port: `Tools -> Port: xxx` where the `xxx` is the detected COM port. + +#### Using Platform IO + +* Select the COM port: `Devices` or set the `upload_port` option on the `platformio.ini` file. + +## Example/Log Output + +``` +ets Jul 29 2019 12:21:46 + +rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) +configsip: 0, SPIWP:0xee +clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 +mode:DIO, clock div:1 +load:0x3fff0030,len:1412 +load:0x40078000,len:13400 +load:0x40080400,len:3672 +entry 0x400805f8 +Setup done +scan start +scan done +17 networks found +1: IoTNetwork (-62)* +2: WiFiSSID (-62)* +3: B3A7992 (-63)* +4: WiFi (-63) +5: IoTNetwork2 (-64)* +... +``` + +## Troubleshooting + +***Important: Be sure you're using a good quality USB cable and you have enough power source for your project.*** + +* **Programming Fail:** If the programming/flash procedure fails, try to reduce the serial connection speed. +* **COM port not detected:** Check the USB cable connection and the USB to Serial driver installation. + +If the error persists, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute). + +## Contribute + +To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst) + +If you have any **feedback** or **issue** to report on this example/library, please open an issue or fix it by creating a new PR. Contributions are more than welcome! + +Before creating a new issue, be sure to try the Troubleshooting and to check if the same issue was already created by someone else. + +## Resources + +* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32) +* ESP32 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf) +* ESP32-WROOM-DA Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-wroom-da_datasheet_en.pdf) diff --git a/libraries/WiFi/examples/WiFiScanDualAntenna/WiFiScanDualAntenna.ino b/libraries/WiFi/examples/WiFiScanDualAntenna/WiFiScanDualAntenna.ino new file mode 100644 index 00000000000..344778ff3df --- /dev/null +++ b/libraries/WiFi/examples/WiFiScanDualAntenna/WiFiScanDualAntenna.ino @@ -0,0 +1,79 @@ +/* + * This sketch demonstrates how to scan WiFi networks. + * The API is almost the same as with the WiFi Shield library, + * the most obvious difference being the different file you need to include: + */ +#include "WiFi.h" + +/* These are the GPIOs connected to the antenna switch on the ESP32-WROOM-DA. + * Both GPIOs are not exposed to the module pins and cannot be used except to + * control the antnnas switch. + * + * For more details, see the datashhet at: + * https://www.espressif.com/sites/default/files/documentation/esp32-wroom-da_datasheet_en.pdf + */ + +#define GPIO_ANT1 2 // GPIO for antenna 1 +#define GPIO_ANT2 25 // GPIO for antenna 2 (default) + +void setup() +{ + bool err = ESP_FAIL; + Serial.begin(115200); + + // Set WiFi to station mode and disconnect from an AP if it was previously connected + WiFi.mode(WIFI_STA); + + /* Attention: This is the manual prodecure for the dual antenna configuration. + * If you choose the ESP32-WROOM-DA module from the Tools -> Board, this configuration + * is not necessary! + * + * Set WiFi dual antenna configuration by passing the GPIO and antenna mode for RX ant TX + */ + err = WiFi.setDualAntennaConfig(GPIO_ANT1, GPIO_ANT2, WIFI_RX_ANT_AUTO, WIFI_TX_ANT_AUTO); + + /* For more details on how to use this feature, see our docs: + * https://docs.espressif.com/projects/arduino-esp32/en/latest/api/wifi.html + */ + + if(err == ESP_FAIL) { + Serial.println("Dual Antenna configuration failed!"); + } else { + Serial.println("Dual Antenna configuration successfuly done!"); + } + + WiFi.disconnect(); + delay(100); + + Serial.println("Setup done"); +} + +void loop() +{ + Serial.println("scan start"); + + // WiFi.scanNetworks will return the number of networks found + int n = WiFi.scanNetworks(); + Serial.println("scan done"); + if (n == 0) { + Serial.println("no networks found"); + } else { + Serial.print(n); + Serial.println(" networks found"); + for (int i = 0; i < n; ++i) { + // Print SSID and RSSI for each network found + Serial.print(i + 1); + Serial.print(": "); + Serial.print(WiFi.SSID(i)); + Serial.print(" ("); + Serial.print(WiFi.RSSI(i)); + Serial.print(")"); + Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*"); + delay(10); + } + } + Serial.println(""); + + // Wait a bit before scanning again + delay(5000); +} diff --git a/libraries/WiFi/src/WiFiClient.cpp b/libraries/WiFi/src/WiFiClient.cpp index c3e9fc86b29..69a691995bd 100644 --- a/libraries/WiFi/src/WiFiClient.cpp +++ b/libraries/WiFi/src/WiFiClient.cpp @@ -175,11 +175,11 @@ class WiFiClientSocketHandle { } }; -WiFiClient::WiFiClient():_connected(false),next(NULL) +WiFiClient::WiFiClient():_connected(false),_timeout(WIFI_CLIENT_DEF_CONN_TIMEOUT_MS),next(NULL) { } -WiFiClient::WiFiClient(int fd):_connected(true),next(NULL) +WiFiClient::WiFiClient(int fd):_connected(true),_timeout(WIFI_CLIENT_DEF_CONN_TIMEOUT_MS),next(NULL) { clientSocketHandle.reset(new WiFiClientSocketHandle(fd)); _rxBuffer.reset(new WiFiClientRxBuffer(fd)); @@ -208,10 +208,11 @@ void WiFiClient::stop() int WiFiClient::connect(IPAddress ip, uint16_t port) { - return connect(ip,port,WIFI_CLIENT_DEF_CONN_TIMEOUT_MS); - } - int WiFiClient::connect(IPAddress ip, uint16_t port, int32_t timeout ) + return connect(ip,port,_timeout); +} +int WiFiClient::connect(IPAddress ip, uint16_t port, int32_t timeout) { + _timeout = timeout; int sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) { log_e("socket: %d", errno); @@ -229,8 +230,8 @@ int WiFiClient::connect(IPAddress ip, uint16_t port) struct timeval tv; FD_ZERO(&fdset); FD_SET(sockfd, &fdset); - tv.tv_sec = 0; - tv.tv_usec = timeout * 1000; + tv.tv_sec = _timeout / 1000; + tv.tv_usec = 0; #ifdef ESP_IDF_VERSION_MAJOR int res = lwip_connect(sockfd, (struct sockaddr*)&serveraddr, sizeof(serveraddr)); @@ -243,13 +244,13 @@ int WiFiClient::connect(IPAddress ip, uint16_t port) return 0; } - res = select(sockfd + 1, nullptr, &fdset, nullptr, timeout<0 ? nullptr : &tv); + res = select(sockfd + 1, nullptr, &fdset, nullptr, _timeout<0 ? nullptr : &tv); if (res < 0) { log_e("select on fd %d, errno: %d, \"%s\"", sockfd, errno, strerror(errno)); close(sockfd); return 0; } else if (res == 0) { - log_i("select returned due to timeout %d ms for fd %d", timeout, sockfd); + log_i("select returned due to timeout %d ms for fd %d", _timeout, sockfd); close(sockfd); return 0; } else { @@ -270,18 +271,28 @@ int WiFiClient::connect(IPAddress ip, uint16_t port) } } +#define ROE_WIFICLIENT(x,msg) { if (((x)<0)) { log_e("Setsockopt '" msg "'' on fd %d failed. errno: %d, \"%s\"", sockfd, errno, strerror(errno)); return 0; }} + ROE_WIFICLIENT(setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)),"SO_SNDTIMEO"); + ROE_WIFICLIENT(setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)),"SO_RCVTIMEO"); + + // These are also set in WiFiClientSecure, should be set here too? + //ROE_WIFICLIENT(setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, &enable, sizeof(enable)),"TCP_NODELAY"); + //ROE_WIFICLIENT (setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, &enable, sizeof(enable)),"SO_KEEPALIVE"); + fcntl( sockfd, F_SETFL, fcntl( sockfd, F_GETFL, 0 ) & (~O_NONBLOCK) ); clientSocketHandle.reset(new WiFiClientSocketHandle(sockfd)); _rxBuffer.reset(new WiFiClientRxBuffer(sockfd)); + _connected = true; return 1; } int WiFiClient::connect(const char *host, uint16_t port) { - return connect(host,port,WIFI_CLIENT_DEF_CONN_TIMEOUT_MS); - } - int WiFiClient::connect(const char *host, uint16_t port, int32_t timeout ) + return connect(host,port,_timeout); +} + +int WiFiClient::connect(const char *host, uint16_t port, int32_t timeout) { IPAddress srv((uint32_t)0); if(!WiFiGenericClass::hostByName(host, srv)){ @@ -301,14 +312,20 @@ int WiFiClient::setSocketOption(int option, char* value, size_t len) int WiFiClient::setTimeout(uint32_t seconds) { - Client::setTimeout(seconds * 1000); - struct timeval tv; - tv.tv_sec = seconds; - tv.tv_usec = 0; - if(setSocketOption(SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0) { - return -1; + Client::setTimeout(seconds * 1000); // This should be here? + _timeout = seconds * 1000; + if(fd() >= 0) { + struct timeval tv; + tv.tv_sec = seconds; + tv.tv_usec = 0; + if(setSocketOption(SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0) { + return -1; + } + return setSocketOption(SO_SNDTIMEO, (char *)&tv, sizeof(struct timeval)); + } + else { + return 0; } - return setSocketOption(SO_SNDTIMEO, (char *)&tv, sizeof(struct timeval)); } int WiFiClient::setOption(int option, int *value) diff --git a/libraries/WiFi/src/WiFiClient.h b/libraries/WiFi/src/WiFiClient.h index 4915cfd5203..5aaa6ba115e 100644 --- a/libraries/WiFi/src/WiFiClient.h +++ b/libraries/WiFi/src/WiFiClient.h @@ -42,6 +42,7 @@ class WiFiClient : public ESPLwIPClient std::shared_ptr clientSocketHandle; std::shared_ptr _rxBuffer; bool _connected; + int _timeout; public: WiFiClient *next; diff --git a/libraries/WiFi/src/WiFiGeneric.cpp b/libraries/WiFi/src/WiFiGeneric.cpp index 838c23bf5cd..5d31341481a 100644 --- a/libraries/WiFi/src/WiFiGeneric.cpp +++ b/libraries/WiFi/src/WiFiGeneric.cpp @@ -138,9 +138,20 @@ esp_err_t set_esp_interface_ip(esp_interface_t interface, IPAddress local_ip=IPA dhcps_lease_t lease; lease.enable = true; - lease.start_ip.addr = static_cast(local_ip) + (1 << 24); - lease.end_ip.addr = static_cast(local_ip) + (11 << 24); - + uint32_t dhcp_ipaddr = static_cast(local_ip); + // prevents DHCP lease range to overflow subnet/24 range + // there will be 11 addresses for DHCP to lease + uint8_t leaseStart = (uint8_t)(~subnet[3] - 12); + if ((local_ip[3]) < leaseStart) { + lease.start_ip.addr = dhcp_ipaddr + (1 << 24); + lease.end_ip.addr = dhcp_ipaddr + (11 << 24); + } else { + // make range stay in the begining of the netmask range + dhcp_ipaddr = (dhcp_ipaddr & 0x00FFFFFF); + lease.start_ip.addr = dhcp_ipaddr + (1 << 24); + lease.end_ip.addr = dhcp_ipaddr + (11 << 24); + } + log_v("DHCP Server Range: %s to %s", IPAddress(lease.start_ip.addr).toString(), IPAddress(lease.end_ip.addr).toString()); err = tcpip_adapter_dhcps_option( (tcpip_adapter_dhcp_option_mode_t)TCPIP_ADAPTER_OP_SET, (tcpip_adapter_dhcp_option_id_t)REQUESTED_IP_ADDRESS, @@ -555,6 +566,10 @@ void WiFiGenericClass::useStaticBuffers(bool bufferMode){ _wifiUseStaticBuffers = bufferMode; } +// Temporary fix to ensure that CDC+JTAG stay on on ESP32-C3 +#if CONFIG_IDF_TARGET_ESP32C3 +extern "C" void phy_bbpll_en_usb(bool en); +#endif bool wifiLowLevelInit(bool persistent){ if(!lowLevelInitDone){ @@ -587,6 +602,10 @@ bool wifiLowLevelInit(bool persistent){ lowLevelInitDone = false; return lowLevelInitDone; } +// Temporary fix to ensure that CDC+JTAG stay on on ESP32-C3 +#if CONFIG_IDF_TARGET_ESP32C3 + phy_bbpll_en_usb(true); +#endif if(!persistent){ lowLevelInitDone = esp_wifi_set_storage(WIFI_STORAGE_RAM) == ESP_OK; } @@ -827,6 +846,8 @@ const char * system_event_reasons[] = { "UNSPECIFIED", "AUTH_EXPIRE", "AUTH_LEAV #endif esp_err_t WiFiGenericClass::_eventCallback(arduino_event_t *event) { + static bool first_connect = true; + if(event->event_id < ARDUINO_EVENT_MAX) { log_d("Arduino Event: %d - %s", event->event_id, arduino_event_names[event->event_id]); } @@ -852,7 +873,7 @@ esp_err_t WiFiGenericClass::_eventCallback(arduino_event_t *event) log_w("Reason: %u - %s", reason, reason2str(reason)); if(reason == WIFI_REASON_NO_AP_FOUND) { WiFiSTAClass::_setStatus(WL_NO_SSID_AVAIL); - } else if(reason == WIFI_REASON_AUTH_FAIL || reason == WIFI_REASON_ASSOC_FAIL) { + } else if((reason == WIFI_REASON_AUTH_FAIL) && !first_connect){ WiFiSTAClass::_setStatus(WL_CONNECT_FAILED); } else if(reason == WIFI_REASON_BEACON_TIMEOUT || reason == WIFI_REASON_HANDSHAKE_TIMEOUT) { WiFiSTAClass::_setStatus(WL_CONNECTION_LOST); @@ -862,12 +883,25 @@ esp_err_t WiFiGenericClass::_eventCallback(arduino_event_t *event) WiFiSTAClass::_setStatus(WL_DISCONNECTED); } clearStatusBits(STA_CONNECTED_BIT | STA_HAS_IP_BIT | STA_HAS_IP6_BIT); - if(((reason == WIFI_REASON_AUTH_EXPIRE) || - (reason >= WIFI_REASON_BEACON_TIMEOUT && reason != WIFI_REASON_AUTH_FAIL)) && - WiFi.getAutoReconnect()) + if(first_connect && ((reason == WIFI_REASON_AUTH_EXPIRE) || + (reason >= WIFI_REASON_BEACON_TIMEOUT))) { + log_d("WiFi Reconnect Running"); WiFi.disconnect(); WiFi.begin(); + first_connect = false; + } + else if(WiFi.getAutoReconnect()){ + if((reason == WIFI_REASON_AUTH_EXPIRE) || + (reason >= WIFI_REASON_BEACON_TIMEOUT && reason != WIFI_REASON_AUTH_FAIL)) + { + log_d("WiFi AutoReconnect Running"); + WiFi.disconnect(); + WiFi.begin(); + } + } + else if (reason == WIFI_REASON_ASSOC_FAIL){ + WiFiSTAClass::_setStatus(WL_CONNECT_FAILED); } } else if(event->event_id == ARDUINO_EVENT_WIFI_STA_GOT_IP) { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG @@ -1038,6 +1072,14 @@ bool WiFiGenericClass::mode(wifi_mode_t m) if(!espWiFiStart()){ return false; } + + #ifdef BOARD_HAS_DUAL_ANTENNA + if(!setDualAntennaConfig(ANT1, ANT2, WIFI_RX_ANT_AUTO, WIFI_TX_ANT_AUTO)){ + log_e("Dual Antenna Config failed!"); + return false; + } + #endif + return true; } @@ -1187,6 +1229,94 @@ bool WiFiGenericClass::initiateFTM(uint8_t frm_count, uint16_t burst_period, uin return true; } +/** + * Configure Dual antenna. + * @param gpio_ant1 Configure the GPIO number for the antenna 1 connected to the RF switch (default GPIO2 on ESP32-WROOM-DA) + * @param gpio_ant2 Configure the GPIO number for the antenna 2 connected to the RF switch (default GPIO25 on ESP32-WROOM-DA) + * @param rx_mode Set the RX antenna mode. See wifi_rx_ant_t for the options. + * @param tx_mode Set the TX antenna mode. See wifi_tx_ant_t for the options. + * @return true on success + */ +bool WiFiGenericClass::setDualAntennaConfig(uint8_t gpio_ant1, uint8_t gpio_ant2, wifi_rx_ant_t rx_mode, wifi_tx_ant_t tx_mode) { + + wifi_ant_gpio_config_t wifi_ant_io; + + if (ESP_OK != esp_wifi_get_ant_gpio(&wifi_ant_io)) { + log_e("Failed to get antenna configuration"); + return false; + } + + wifi_ant_io.gpio_cfg[0].gpio_num = gpio_ant1; + wifi_ant_io.gpio_cfg[0].gpio_select = 1; + wifi_ant_io.gpio_cfg[1].gpio_num = gpio_ant2; + wifi_ant_io.gpio_cfg[1].gpio_select = 1; + + if (ESP_OK != esp_wifi_set_ant_gpio(&wifi_ant_io)) { + log_e("Failed to set antenna GPIO configuration"); + return false; + } + + // Set antenna default configuration + wifi_ant_config_t ant_config = { + .rx_ant_mode = WIFI_ANT_MODE_AUTO, + .tx_ant_mode = WIFI_ANT_MODE_AUTO, + .enabled_ant0 = 0, + .enabled_ant1 = 1, + }; + + switch (rx_mode) + { + case WIFI_RX_ANT0: + ant_config.rx_ant_mode = WIFI_ANT_MODE_ANT0; + break; + case WIFI_RX_ANT1: + ant_config.rx_ant_mode = WIFI_ANT_MODE_ANT1; + break; + case WIFI_RX_ANT_AUTO: + log_i("TX Antenna will be automatically selected"); + ant_config.rx_ant_default = WIFI_ANT_ANT0; + ant_config.rx_ant_mode = WIFI_ANT_MODE_AUTO; + // Force TX for AUTO if RX is AUTO + ant_config.tx_ant_mode = WIFI_ANT_MODE_AUTO; + goto set_ant; + break; + default: + log_e("Invalid default antenna! Falling back to AUTO"); + ant_config.rx_ant_mode = WIFI_ANT_MODE_AUTO; + break; + } + + switch (tx_mode) + { + case WIFI_TX_ANT0: + ant_config.tx_ant_mode = WIFI_ANT_MODE_ANT0; + break; + case WIFI_TX_ANT1: + ant_config.tx_ant_mode = WIFI_ANT_MODE_ANT1; + break; + case WIFI_TX_ANT_AUTO: + log_i("RX Antenna will be automatically selected"); + ant_config.rx_ant_default = WIFI_ANT_ANT0; + ant_config.tx_ant_mode = WIFI_ANT_MODE_AUTO; + // Force RX for AUTO if RX is AUTO + ant_config.rx_ant_mode = WIFI_ANT_MODE_AUTO; + break; + default: + log_e("Invalid default antenna! Falling back to AUTO"); + ant_config.rx_ant_default = WIFI_ANT_ANT0; + ant_config.tx_ant_mode = WIFI_ANT_MODE_AUTO; + break; + } + +set_ant: + if (ESP_OK != esp_wifi_set_ant(&ant_config)) { + log_e("Failed to set antenna configuration"); + return false; + } + + return true; +} + // ----------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------ Generic Network function --------------------------------------------- // ----------------------------------------------------------------------------------------------------------------------- diff --git a/libraries/WiFi/src/WiFiGeneric.h b/libraries/WiFi/src/WiFiGeneric.h index 7079c032993..62642b43dc7 100644 --- a/libraries/WiFi/src/WiFiGeneric.h +++ b/libraries/WiFi/src/WiFiGeneric.h @@ -139,6 +139,18 @@ static const int WIFI_SCAN_DONE_BIT= BIT12; static const int WIFI_DNS_IDLE_BIT = BIT13; static const int WIFI_DNS_DONE_BIT = BIT14; +typedef enum { + WIFI_RX_ANT0 = 0, + WIFI_RX_ANT1, + WIFI_RX_ANT_AUTO +} wifi_rx_ant_t; + +typedef enum { + WIFI_TX_ANT0 = 0, + WIFI_TX_ANT1, + WIFI_TX_ANT_AUTO +} wifi_tx_ant_t; + class WiFiGenericClass { public: @@ -174,6 +186,8 @@ class WiFiGenericClass bool initiateFTM(uint8_t frm_count=16, uint16_t burst_period=2, uint8_t channel=1, const uint8_t * mac=NULL); + static bool setDualAntennaConfig(uint8_t gpio_ant1, uint8_t gpio_ant2, wifi_rx_ant_t rx_mode, wifi_tx_ant_t tx_mode); + static const char * getHostname(); static bool setHostname(const char * hostname); static bool hostname(const String& aHostname) { return setHostname(aHostname.c_str()); } diff --git a/libraries/WiFi/src/WiFiSTA.cpp b/libraries/WiFi/src/WiFiSTA.cpp index dd468823607..7734f5d79b5 100644 --- a/libraries/WiFi/src/WiFiSTA.cpp +++ b/libraries/WiFi/src/WiFiSTA.cpp @@ -42,6 +42,7 @@ extern "C" { #include "lwip/dns.h" #include #include +#include "esp_wpa2.h" } // ----------------------------------------------------------------------------------------------------------------------- @@ -82,7 +83,7 @@ static bool sta_config_equal(const wifi_config_t& lhs, const wifi_config_t& rhs) return true; } -static void wifi_sta_config(wifi_config_t * wifi_config, const char * ssid=NULL, const char * password=NULL, const uint8_t * bssid=NULL, uint8_t channel=0, wifi_scan_method_t scan_method=WIFI_ALL_CHANNEL_SCAN, wifi_sort_method_t sort_method=WIFI_CONNECT_AP_BY_SIGNAL, uint16_t listen_interval=0, bool pmf_required=false){ +static void wifi_sta_config(wifi_config_t * wifi_config, const char * ssid=NULL, const char * password=NULL, const uint8_t * bssid=NULL, uint8_t channel=0, wifi_auth_mode_t min_security=WIFI_AUTH_WPA2_PSK, wifi_scan_method_t scan_method=WIFI_ALL_CHANNEL_SCAN, wifi_sort_method_t sort_method=WIFI_CONNECT_AP_BY_SIGNAL, uint16_t listen_interval=0, bool pmf_required=false){ wifi_config->sta.channel = channel; wifi_config->sta.listen_interval = listen_interval; wifi_config->sta.scan_method = scan_method;//WIFI_ALL_CHANNEL_SCAN or WIFI_FAST_SCAN @@ -98,7 +99,7 @@ static void wifi_sta_config(wifi_config_t * wifi_config, const char * ssid=NULL, if(ssid != NULL && ssid[0] != 0){ _wifi_strncpy((char*)wifi_config->sta.ssid, ssid, 32); if(password != NULL && password[0] != 0){ - wifi_config->sta.threshold.authmode = WIFI_AUTH_WPA2_PSK; + wifi_config->sta.threshold.authmode = min_security; _wifi_strncpy((char*)wifi_config->sta.password, password, 64); } if(bssid != NULL){ @@ -114,6 +115,9 @@ static void wifi_sta_config(wifi_config_t * wifi_config, const char * ssid=NULL, bool WiFiSTAClass::_autoReconnect = true; bool WiFiSTAClass::_useStaticIp = false; +wifi_auth_mode_t WiFiSTAClass::_minSecurity = WIFI_AUTH_WPA2_PSK; +wifi_scan_method_t WiFiSTAClass::_scanMethod = WIFI_FAST_SCAN; +wifi_sort_method_t WiFiSTAClass::_sortMethod = WIFI_CONNECT_AP_BY_SIGNAL; static wl_status_t _sta_status = WL_NO_SHIELD; static EventGroupHandle_t _sta_status_group = NULL; @@ -145,6 +149,67 @@ wl_status_t WiFiSTAClass::status() return (wl_status_t)xEventGroupClearBits(_sta_status_group, 0); } +/** + * Start Wifi connection with a WPA2 Enterprise AP + * if passphrase is set the most secure supported mode will be automatically selected + * @param ssid const char* Pointer to the SSID string. + * @param method wpa2_method_t The authentication method of WPA2 (WPA2_AUTH_TLS, WPA2_AUTH_PEAP, WPA2_AUTH_TTLS) + * @param wpa2_identity const char* Pointer to the entity + * @param wpa2_username const char* Pointer to the username + * @param password const char * Pointer to the password. + * @param ca_pem const char* Pointer to a string with the contents of a .pem file with CA cert + * @param client_crt const char* Pointer to a string with the contents of a .crt file with client cert + * @param client_key const char* Pointer to a string with the contants of a .key file with client key + * @param bssid uint8_t[6] Optional. BSSID / MAC of AP + * @param channel Optional. Channel of AP + * @param connect Optional. call connect + * @return + */ +wl_status_t WiFiSTAClass::begin(const char* wpa2_ssid, wpa2_auth_method_t method, const char* wpa2_identity, const char* wpa2_username, const char *wpa2_password, const char* ca_pem, const char* client_crt, const char* client_key, int32_t channel, const uint8_t* bssid, bool connect) +{ + if(!WiFi.enableSTA(true)) { + log_e("STA enable failed!"); + return WL_CONNECT_FAILED; + } + + if(!wpa2_ssid || *wpa2_ssid == 0x00 || strlen(wpa2_ssid) > 32) { + log_e("SSID too long or missing!"); + return WL_CONNECT_FAILED; + } + + if(wpa2_identity && strlen(wpa2_identity) > 64) { + log_e("identity too long!"); + return WL_CONNECT_FAILED; + } + + if(wpa2_username && strlen(wpa2_username) > 64) { + log_e("username too long!"); + return WL_CONNECT_FAILED; + } + + if(wpa2_password && strlen(wpa2_password) > 64) { + log_e("password too long!"); + } + + if(ca_pem) { + esp_wifi_sta_wpa2_ent_set_ca_cert((uint8_t *)ca_pem, strlen(ca_pem)); + } + + if(client_crt) { + esp_wifi_sta_wpa2_ent_set_cert_key((uint8_t *)client_crt, strlen(client_crt), (uint8_t *)client_key, strlen(client_key), NULL, 0); + } + + esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)wpa2_identity, strlen(wpa2_identity)); + if(method == WPA2_AUTH_PEAP || method == WPA2_AUTH_TTLS) { + esp_wifi_sta_wpa2_ent_set_username((uint8_t *)wpa2_username, strlen(wpa2_username)); + esp_wifi_sta_wpa2_ent_set_password((uint8_t *)wpa2_password, strlen(wpa2_password)); + } + esp_wifi_sta_wpa2_ent_enable(); //set config settings to enable function + WiFi.begin(wpa2_ssid); //connect to wifi + + return status(); +} + /** * Start Wifi connection * if passphrase is set the most secure supported mode will be automatically selected @@ -181,12 +246,7 @@ wl_status_t WiFiSTAClass::begin(const char* ssid, const char *passphrase, int32_ _wifi_strncpy(reinterpret_cast(conf.sta.password), passphrase, 64); } - if(channel == 0) { - // If no specific channel specified, then do an slower WIFI_ALL_CHANNEL_SCAN - wifi_sta_config(&conf, ssid, passphrase, bssid, channel, WIFI_ALL_CHANNEL_SCAN); - } - else - wifi_sta_config(&conf, ssid, passphrase, bssid, channel, WIFI_FAST_SCAN); + wifi_sta_config(&conf, ssid, passphrase, bssid, channel, _minSecurity, _scanMethod, _sortMethod); wifi_config_t current_conf; if(esp_wifi_get_config((wifi_interface_t)ESP_IF_WIFI_STA, ¤t_conf) != ESP_OK){ @@ -342,6 +402,37 @@ bool WiFiSTAClass::isConnected() return (status() == WL_CONNECTED); } +/** + * Set the minimum security for AP to be considered connectable + * Must be called before WiFi.begin() + * @param minSecurity wifi_auth_mode_t + */ +void WiFiSTAClass::setMinSecurity(wifi_auth_mode_t minSecurity) +{ + _minSecurity = minSecurity; +} + +/** + * Set the way that AP is chosen. + * First SSID match[WIFI_FAST_SCAN] or Sorted[WIFI_ALL_CHANNEL_SCAN] (RSSI or Security) + * Must be called before WiFi.begin() + * @param scanMethod wifi_scan_method_t + */ +void WiFiSTAClass::setScanMethod(wifi_scan_method_t scanMethod) +{ + _scanMethod = scanMethod; +} + +/** + * Set the way that AP is sorted. (requires scanMethod WIFI_ALL_CHANNEL_SCAN) + * By SSID[WIFI_CONNECT_AP_BY_SIGNAL] or Security[WIFI_CONNECT_AP_BY_SECURITY] + * Must be called before WiFi.begin() + * @param sortMethod wifi_sort_method_t + */ +void WiFiSTAClass::setSortMethod(wifi_sort_method_t sortMethod) +{ + _sortMethod = sortMethod; +} /** * Setting the ESP32 station to connect to the AP (which is recorded) @@ -655,8 +746,15 @@ IPv6Address WiFiSTAClass::localIPv6() bool WiFiSTAClass::_smartConfigStarted = false; bool WiFiSTAClass::_smartConfigDone = false; - -bool WiFiSTAClass::beginSmartConfig() { +/** + * @brief + * + * @param type Select type of SmartConfig. Default type is SC_TYPE_ESPTOUCH + * @param crypt_key When using type SC_TYPE_ESPTOUTCH_V2 crypt key needed, else ignored. Lenght should be 16 chars. + * @return true if configuration is successful. + * @return false if configuration fails. + */ +bool WiFiSTAClass::beginSmartConfig(smartconfig_type_t type, char* crypt_key) { esp_err_t err; if (_smartConfigStarted) { return false; @@ -668,7 +766,13 @@ bool WiFiSTAClass::beginSmartConfig() { esp_wifi_disconnect(); smartconfig_start_config_t conf = SMARTCONFIG_START_CONFIG_DEFAULT(); - err = esp_smartconfig_set_type(SC_TYPE_ESPTOUCH); + + if (type == SC_TYPE_ESPTOUCH_V2){ + conf.esp_touch_v2_enable_crypt = true; + conf.esp_touch_v2_key = crypt_key; + } + + err = esp_smartconfig_set_type(type); if (err != ESP_OK) { log_e("SmartConfig Set Type Failed!"); return false; diff --git a/libraries/WiFi/src/WiFiSTA.h b/libraries/WiFi/src/WiFiSTA.h index afd641f7eb3..b8bb855c198 100644 --- a/libraries/WiFi/src/WiFiSTA.h +++ b/libraries/WiFi/src/WiFiSTA.h @@ -30,6 +30,11 @@ #include "esp_event.h" #endif +typedef enum { + WPA2_AUTH_TLS = 0, + WPA2_AUTH_PEAP = 1, + WPA2_AUTH_TTLS = 2 +} wpa2_auth_method_t; class WiFiSTAClass { @@ -39,6 +44,7 @@ class WiFiSTAClass public: + wl_status_t begin(const char* wpa2_ssid, wpa2_auth_method_t method, const char* wpa2_identity=NULL, const char* wpa2_username=NULL, const char *wpa2_password=NULL, const char* ca_pem=NULL, const char* client_crt=NULL, const char* client_key=NULL, int32_t channel=0, const uint8_t* bssid=0, bool connect=true); wl_status_t begin(const char* ssid, const char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true); wl_status_t begin(char* ssid, char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true); wl_status_t begin(); @@ -58,6 +64,11 @@ class WiFiSTAClass uint8_t waitForConnectResult(unsigned long timeoutLength = 60000); + // Next group functions must be called before WiFi.begin() + void setMinSecurity(wifi_auth_mode_t minSecurity);// Default is WIFI_AUTH_WPA2_PSK + void setScanMethod(wifi_scan_method_t scanMethod);// Default is WIFI_FAST_SCAN + void setSortMethod(wifi_sort_method_t sortMethod);// Default is WIFI_CONNECT_AP_BY_SIGNAL + // STA network info IPAddress localIP(); @@ -90,9 +101,12 @@ class WiFiSTAClass protected: static bool _useStaticIp; static bool _autoReconnect; + static wifi_auth_mode_t _minSecurity; + static wifi_scan_method_t _scanMethod; + static wifi_sort_method_t _sortMethod; public: - bool beginSmartConfig(); + bool beginSmartConfig(smartconfig_type_t type = SC_TYPE_ESPTOUCH, char* crypt_key = NULL); bool stopSmartConfig(); bool smartConfigDone(); diff --git a/libraries/WiFi/src/WiFiScan.cpp b/libraries/WiFi/src/WiFiScan.cpp index f34badb16dc..5b0c6732a64 100644 --- a/libraries/WiFi/src/WiFiScan.cpp +++ b/libraries/WiFi/src/WiFiScan.cpp @@ -81,7 +81,7 @@ void* WiFiScanClass::_scanResult = 0; * @param show_hidden show hidden networks * @return Number of discovered networks */ -int16_t WiFiScanClass::scanNetworks(bool async, bool show_hidden, bool passive, uint32_t max_ms_per_chan, uint8_t channel) +int16_t WiFiScanClass::scanNetworks(bool async, bool show_hidden, bool passive, uint32_t max_ms_per_chan, uint8_t channel, const char * ssid, const uint8_t * bssid) { if(WiFiGenericClass::getStatusBits() & WIFI_SCANNING_BIT) { return WIFI_SCAN_RUNNING; @@ -95,8 +95,8 @@ int16_t WiFiScanClass::scanNetworks(bool async, bool show_hidden, bool passive, scanDelete(); wifi_scan_config_t config; - config.ssid = 0; - config.bssid = 0; + config.ssid = (uint8_t*)ssid; + config.bssid = (uint8_t*)bssid; config.channel = channel; config.show_hidden = show_hidden; if(passive){ diff --git a/libraries/WiFi/src/WiFiScan.h b/libraries/WiFi/src/WiFiScan.h index 1929e46627b..b838dc17574 100644 --- a/libraries/WiFi/src/WiFiScan.h +++ b/libraries/WiFi/src/WiFiScan.h @@ -31,7 +31,7 @@ class WiFiScanClass public: - int16_t scanNetworks(bool async = false, bool show_hidden = false, bool passive = false, uint32_t max_ms_per_chan = 300, uint8_t channel = 0); + int16_t scanNetworks(bool async = false, bool show_hidden = false, bool passive = false, uint32_t max_ms_per_chan = 300, uint8_t channel = 0, const char * ssid=nullptr, const uint8_t * bssid=nullptr); int16_t scanComplete(); void scanDelete(); diff --git a/libraries/WiFi/src/WiFiServer.h b/libraries/WiFi/src/WiFiServer.h index f5b7eaa7bf3..346986abad5 100644 --- a/libraries/WiFi/src/WiFiServer.h +++ b/libraries/WiFi/src/WiFiServer.h @@ -22,7 +22,6 @@ #include "Arduino.h" #include "Server.h" #include "WiFiClient.h" -#include "arpa/inet.h" #include "IPAddress.h" class WiFiServer : public Server { @@ -38,7 +37,8 @@ class WiFiServer : public Server { public: void listenOnLocalhost(){} - WiFiServer(uint16_t port=80, uint8_t max_clients=4):sockfd(-1),_accepted_sockfd(-1),_addr(INADDR_ANY),_port(port),_max_clients(max_clients),_listening(false),_noDelay(false) { + // _addr(INADDR_ANY) is the same as _addr() ==> 0.0.0.0 + WiFiServer(uint16_t port=80, uint8_t max_clients=4):sockfd(-1),_accepted_sockfd(-1),_addr(),_port(port),_max_clients(max_clients),_listening(false),_noDelay(false) { log_v("WiFiServer::WiFiServer(port=%d, ...)", port); } WiFiServer(const IPAddress& addr, uint16_t port=80, uint8_t max_clients=4):sockfd(-1),_accepted_sockfd(-1),_addr(addr),_port(port),_max_clients(max_clients),_listening(false),_noDelay(false) { diff --git a/libraries/WiFi/src/WiFiType.h b/libraries/WiFi/src/WiFiType.h index ee8cfdd2498..9b7b00e2c3a 100644 --- a/libraries/WiFi/src/WiFiType.h +++ b/libraries/WiFi/src/WiFiType.h @@ -23,6 +23,8 @@ #ifndef ESP32WIFITYPE_H_ #define ESP32WIFITYPE_H_ +#include "esp_wifi_types.h" + #define WIFI_SCAN_RUNNING (-1) #define WIFI_SCAN_FAILED (-2) diff --git a/libraries/WiFiClientSecure/README.md b/libraries/WiFiClientSecure/README.md index fd5f4f51938..aa5199d2a49 100644 --- a/libraries/WiFiClientSecure/README.md +++ b/libraries/WiFiClientSecure/README.md @@ -26,6 +26,32 @@ Then: Please see the WiFiClientSecure example. +Using a bundle of root certificate authority certificates +--------------------------------------------------------- +This method is similar to the single root certificate verfication above, but it uses a standard set of +root certificates from Mozilla to authenticate against, while the previous method only accepts a single +certificate for a given server. This allows the client to connect to all public SSL servers. + +To use this feature in PlatformIO: +1. create a certificate bundle as described in the document below, or obtain a pre-built one you trust: +https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/protocols/esp_crt_bundle.htm +(gen_crt_bundle.py can be found in the /tools folder) + a. note: the full bundle will take up around 64k of flash space, but has minimal RAM usage, as only + the index of the certificates is kept in RAM +2. Place the bundle under the file name "data/cert/x509_crt_bundle.bin" in your platformio project +3. add "board_build.embed_files = data/cert/x509_crt_bundle.bin" in your platformio.ini +4. add the following global declaration in your project: + extern const uint8_t rootca_crt_bundle_start[] asm("_binary_data_cert_x509_crt_bundle_bin_start"); +5. before initiating the first SSL connection, call + my_client.setCACertBundle(rootca_crt_bundle_start); + +To use this feature in Android IDE: +If the Arduino IDE added support for embedding files in the meantime, then follow the instructions above. +If not, you have three choices: +1. convert your project to PlatformIO +2. create a makefile where you can add the idf_component_register() declaration to include the certificate bundle +3. Store the bundle as a SPIFFS file, but then you have to load it into RAM in runtime and waste 64k of precious memory + Using a root CA cert and client cert/keys ----------------------------------------- This method authenticates the server and additionally also authenticates diff --git a/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp b/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp index 4f19d57a4d0..cf22082af06 100644 --- a/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp +++ b/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp @@ -19,6 +19,7 @@ */ #include "WiFiClientSecure.h" +#include "esp_crt_bundle.h" #include #include #include @@ -31,6 +32,7 @@ WiFiClientSecure::WiFiClientSecure() { _connected = false; + _timeout = 30000; // Same default as ssl_client sslclient = new sslclient_context; ssl_init(sslclient); @@ -44,13 +46,14 @@ WiFiClientSecure::WiFiClientSecure() _psKey = NULL; next = NULL; _alpn_protos = NULL; + _use_ca_bundle = false; } WiFiClientSecure::WiFiClientSecure(int sock) { _connected = false; - _timeout = 0; + _timeout = 30000; // Same default as ssl_client sslclient = new sslclient_context; ssl_init(sslclient); @@ -126,10 +129,7 @@ int WiFiClientSecure::connect(IPAddress ip, uint16_t port, const char *CA_cert, int WiFiClientSecure::connect(const char *host, uint16_t port, const char *CA_cert, const char *cert, const char *private_key) { - if(_timeout > 0){ - sslclient->handshake_timeout = _timeout; - } - int ret = start_ssl_client(sslclient, host, port, _timeout, CA_cert, cert, private_key, NULL, NULL, _use_insecure, _alpn_protos); + int ret = start_ssl_client(sslclient, host, port, _timeout, CA_cert, _use_ca_bundle, cert, private_key, NULL, NULL, _use_insecure, _alpn_protos); _lastError = ret; if (ret < 0) { log_e("start_ssl_client: %d", ret); @@ -146,10 +146,7 @@ int WiFiClientSecure::connect(IPAddress ip, uint16_t port, const char *pskIdent, int WiFiClientSecure::connect(const char *host, uint16_t port, const char *pskIdent, const char *psKey) { log_v("start_ssl_client with PSK"); - if(_timeout > 0){ - sslclient->handshake_timeout = _timeout; - } - int ret = start_ssl_client(sslclient, host, port, _timeout, NULL, NULL, NULL, pskIdent, psKey, _use_insecure, _alpn_protos); + int ret = start_ssl_client(sslclient, host, port, _timeout, NULL, false, NULL, NULL, pskIdent, psKey, _use_insecure, _alpn_protos); _lastError = ret; if (ret < 0) { log_e("start_ssl_client: %d", ret); @@ -263,6 +260,18 @@ void WiFiClientSecure::setCACert (const char *rootCA) _CA_cert = rootCA; } + void WiFiClientSecure::setCACertBundle(const uint8_t * bundle) + { + if (bundle != NULL) + { + esp_crt_bundle_set(bundle); + _use_ca_bundle = true; + } else { + esp_crt_bundle_detach(NULL); + _use_ca_bundle = false; + } + } + void WiFiClientSecure::setCertificate (const char *client_ca) { _cert = client_ca; @@ -301,6 +310,7 @@ char *WiFiClientSecure::_streamLoad(Stream& stream, size_t size) { } bool WiFiClientSecure::loadCACert(Stream& stream, size_t size) { + if (_CA_cert != NULL) free(const_cast(_CA_cert)); char *dest = _streamLoad(stream, size); bool ret = false; if (dest) { @@ -311,6 +321,7 @@ bool WiFiClientSecure::loadCACert(Stream& stream, size_t size) { } bool WiFiClientSecure::loadCertificate(Stream& stream, size_t size) { + if (_cert != NULL) free(const_cast(_cert)); char *dest = _streamLoad(stream, size); bool ret = false; if (dest) { @@ -321,6 +332,7 @@ bool WiFiClientSecure::loadCertificate(Stream& stream, size_t size) { } bool WiFiClientSecure::loadPrivateKey(Stream& stream, size_t size) { + if (_private_key != NULL) free(const_cast(_private_key)); char *dest = _streamLoad(stream, size); bool ret = false; if (dest) { @@ -348,3 +360,27 @@ void WiFiClientSecure::setAlpnProtocols(const char **alpn_protos) { _alpn_protos = alpn_protos; } +int WiFiClientSecure::setTimeout(uint32_t seconds) +{ + _timeout = seconds * 1000; + if (sslclient->socket >= 0) { + struct timeval tv; + tv.tv_sec = seconds; + tv.tv_usec = 0; + if(setSocketOption(SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0) { + return -1; + } + return setSocketOption(SO_SNDTIMEO, (char *)&tv, sizeof(struct timeval)); + } + else { + return 0; + } +} +int WiFiClientSecure::setSocketOption(int option, char* value, size_t len) +{ + int res = setsockopt(sslclient->socket, SOL_SOCKET, option, value, len); + if(res < 0) { + log_e("%X : %d", option, errno); + } + return res; +} diff --git a/libraries/WiFiClientSecure/src/WiFiClientSecure.h b/libraries/WiFiClientSecure/src/WiFiClientSecure.h index bba94ceffbc..9ea0c04eb4e 100644 --- a/libraries/WiFiClientSecure/src/WiFiClientSecure.h +++ b/libraries/WiFiClientSecure/src/WiFiClientSecure.h @@ -32,7 +32,7 @@ class WiFiClientSecure : public WiFiClient int _lastError = 0; int _peek = -1; - int _timeout = 0; + int _timeout; bool _use_insecure; const char *_CA_cert; const char *_cert; @@ -40,6 +40,7 @@ class WiFiClientSecure : public WiFiClient const char *_pskIdent; // identity for PSK cipher suites const char *_psKey; // key in hex for PSK cipher suites const char **_alpn_protos; + bool _use_ca_bundle; public: WiFiClientSecure *next; @@ -70,6 +71,7 @@ class WiFiClientSecure : public WiFiClient void setCertificate(const char *client_ca); void setPrivateKey (const char *private_key); bool loadCACert(Stream& stream, size_t size); + void setCACertBundle(const uint8_t * bundle); bool loadCertificate(Stream& stream, size_t size); bool loadPrivateKey(Stream& stream, size_t size); bool verify(const char* fingerprint, const char* domain_name); @@ -77,7 +79,8 @@ class WiFiClientSecure : public WiFiClient void setAlpnProtocols(const char **alpn_protos); const mbedtls_x509_crt* getPeerCertificate() { return mbedtls_ssl_get_peer_cert(&sslclient->ssl_ctx); }; bool getFingerprintSHA256(uint8_t sha256_result[32]) { return get_peer_fingerprint(sslclient, sha256_result); }; - int setTimeout(uint32_t seconds){ return 0; } + int setTimeout(uint32_t seconds); + int setSocketOption(int option, char* value, size_t len); operator bool() { diff --git a/libraries/WiFiClientSecure/src/esp_crt_bundle.c b/libraries/WiFiClientSecure/src/esp_crt_bundle.c new file mode 100644 index 00000000000..747f86239d5 --- /dev/null +++ b/libraries/WiFiClientSecure/src/esp_crt_bundle.c @@ -0,0 +1,218 @@ +// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +#include +#include +#include +#include "esp_crt_bundle.h" +#include "esp_err.h" + +#define BUNDLE_HEADER_OFFSET 2 +#define CRT_HEADER_OFFSET 4 + +static const char *TAG = "esp-x509-crt-bundle"; + +/* a dummy certificate so that + * cacert_ptr passes non-NULL check during handshake */ +static mbedtls_x509_crt s_dummy_crt; + + +typedef struct crt_bundle_t { + const uint8_t **crts; + uint16_t num_certs; + size_t x509_crt_bundle_len; +} crt_bundle_t; + +static crt_bundle_t s_crt_bundle; + +static int esp_crt_verify_callback(void *buf, mbedtls_x509_crt *crt, int data, uint32_t *flags); +static int esp_crt_check_signature(mbedtls_x509_crt *child, const uint8_t *pub_key_buf, size_t pub_key_len); + + +static int esp_crt_check_signature(mbedtls_x509_crt *child, const uint8_t *pub_key_buf, size_t pub_key_len) +{ + int ret = 0; + mbedtls_x509_crt parent; + const mbedtls_md_info_t *md_info; + unsigned char hash[MBEDTLS_MD_MAX_SIZE]; + + mbedtls_x509_crt_init(&parent); + + if ( (ret = mbedtls_pk_parse_public_key(&parent.pk, pub_key_buf, pub_key_len) ) != 0) { + log_e("PK parse failed with error %X", ret); + goto cleanup; + } + + + // Fast check to avoid expensive computations when not necessary + if (!mbedtls_pk_can_do(&parent.pk, child->sig_pk)) { + log_e("Simple compare failed"); + ret = -1; + goto cleanup; + } + + md_info = mbedtls_md_info_from_type(child->sig_md); + if ( (ret = mbedtls_md( md_info, child->tbs.p, child->tbs.len, hash )) != 0 ) { + log_e("Internal mbedTLS error %X", ret); + goto cleanup; + } + + if ( (ret = mbedtls_pk_verify_ext( child->sig_pk, child->sig_opts, &parent.pk, + child->sig_md, hash, mbedtls_md_get_size( md_info ), + child->sig.p, child->sig.len )) != 0 ) { + + log_e("PK verify failed with error %X", ret); + goto cleanup; + } +cleanup: + mbedtls_x509_crt_free(&parent); + + return ret; +} + + +/* This callback is called for every certificate in the chain. If the chain + * is proper each intermediate certificate is validated through its parent + * in the x509_crt_verify_chain() function. So this callback should + * only verify the first untrusted link in the chain is signed by the + * root certificate in the trusted bundle +*/ +int esp_crt_verify_callback(void *buf, mbedtls_x509_crt *crt, int depth, uint32_t *flags) +{ + mbedtls_x509_crt *child = crt; + + /* It's OK for a trusted cert to have a weak signature hash alg. + as we already trust this certificate */ + uint32_t flags_filtered = *flags & ~(MBEDTLS_X509_BADCERT_BAD_MD); + + if (flags_filtered != MBEDTLS_X509_BADCERT_NOT_TRUSTED) { + return 0; + } + + + if (s_crt_bundle.crts == NULL) { + log_e("No certificates in bundle"); + return MBEDTLS_ERR_X509_FATAL_ERROR; + } + + log_d("%d certificates in bundle", s_crt_bundle.num_certs); + + size_t name_len = 0; + const uint8_t *crt_name; + + bool crt_found = false; + int start = 0; + int end = s_crt_bundle.num_certs - 1; + int middle = (end - start) / 2; + + /* Look for the certificate using binary search on subject name */ + while (start <= end) { + name_len = s_crt_bundle.crts[middle][0] << 8 | s_crt_bundle.crts[middle][1]; + crt_name = s_crt_bundle.crts[middle] + CRT_HEADER_OFFSET; + + int cmp_res = memcmp(child->issuer_raw.p, crt_name, name_len ); + if (cmp_res == 0) { + crt_found = true; + break; + } else if (cmp_res < 0) { + end = middle - 1; + } else { + start = middle + 1; + } + middle = (start + end) / 2; + } + + int ret = MBEDTLS_ERR_X509_FATAL_ERROR; + if (crt_found) { + size_t key_len = s_crt_bundle.crts[middle][2] << 8 | s_crt_bundle.crts[middle][3]; + ret = esp_crt_check_signature(child, s_crt_bundle.crts[middle] + CRT_HEADER_OFFSET + name_len, key_len); + } + + if (ret == 0) { + log_i("Certificate validated"); + *flags = 0; + return 0; + } + + log_e("Failed to verify certificate"); + return MBEDTLS_ERR_X509_FATAL_ERROR; +} + + +/* Initialize the bundle into an array so we can do binary search for certs, + the bundle generated by the python utility is already presorted by subject name + */ +static esp_err_t esp_crt_bundle_init(const uint8_t *x509_bundle) +{ + s_crt_bundle.num_certs = (x509_bundle[0] << 8) | x509_bundle[1]; + s_crt_bundle.crts = calloc(s_crt_bundle.num_certs, sizeof(x509_bundle)); + + if (s_crt_bundle.crts == NULL) { + log_e("Unable to allocate memory for bundle"); + return ESP_ERR_NO_MEM; + } + + const uint8_t *cur_crt; + cur_crt = x509_bundle + BUNDLE_HEADER_OFFSET; + + for (int i = 0; i < s_crt_bundle.num_certs; i++) { + s_crt_bundle.crts[i] = cur_crt; + + size_t name_len = cur_crt[0] << 8 | cur_crt[1]; + size_t key_len = cur_crt[2] << 8 | cur_crt[3]; + cur_crt = cur_crt + CRT_HEADER_OFFSET + name_len + key_len; + } + + return ESP_OK; +} + +esp_err_t esp_crt_bundle_attach(void *conf) +{ + esp_err_t ret = ESP_OK; + // If no bundle has been set by the user then use the bundle embedded in the binary + if (s_crt_bundle.crts == NULL) { + log_e("Failed to attach bundle"); + return ret; + } + + if (conf) { + /* point to a dummy certificate + * This is only required so that the + * cacert_ptr passes non-NULL check during handshake + */ + mbedtls_ssl_config *ssl_conf = (mbedtls_ssl_config *)conf; + mbedtls_x509_crt_init(&s_dummy_crt); + mbedtls_ssl_conf_ca_chain(ssl_conf, &s_dummy_crt, NULL); + mbedtls_ssl_conf_verify(ssl_conf, esp_crt_verify_callback, NULL); + } + + return ret; +} + +void esp_crt_bundle_detach(mbedtls_ssl_config *conf) +{ + free(s_crt_bundle.crts); + s_crt_bundle.crts = NULL; + if (conf) { + mbedtls_ssl_conf_verify(conf, NULL, NULL); + } +} + +void esp_crt_bundle_set(const uint8_t *x509_bundle) +{ + // Free any previously used bundle + free(s_crt_bundle.crts); + esp_crt_bundle_init(x509_bundle); +} diff --git a/libraries/WiFiClientSecure/src/esp_crt_bundle.h b/libraries/WiFiClientSecure/src/esp_crt_bundle.h new file mode 100644 index 00000000000..33fb98b9969 --- /dev/null +++ b/libraries/WiFiClientSecure/src/esp_crt_bundle.h @@ -0,0 +1,68 @@ +// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +#ifndef _ESP_CRT_BUNDLE_H_ +#define _ESP_CRT_BUNDLE_H_ + +#include "mbedtls/ssl.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @brief Attach and enable use of a bundle for certificate verification + * + * Attach and enable use of a bundle for certificate verification through a verification callback. + * If no specific bundle has been set through esp_crt_bundle_set() it will default to the + * bundle defined in menuconfig and embedded in the binary. + * + * @param[in] conf The config struct for the SSL connection. + * + * @return + * - ESP_OK if adding certificates was successful. + * - Other if an error occured or an action must be taken by the calling process. + */ +esp_err_t esp_crt_bundle_attach(void *conf); + + +/** + * @brief Disable and dealloc the certification bundle + * + * Removes the certificate verification callback and deallocates used resources + * + * @param[in] conf The config struct for the SSL connection. + */ +void esp_crt_bundle_detach(mbedtls_ssl_config *conf); + + +/** + * @brief Set the default certificate bundle used for verification + * + * Overrides the default certificate bundle. In most use cases the bundle should be + * set through menuconfig. The bundle needs to be sorted by subject name since binary search is + * used to find certificates. + * + * @param[in] x509_bundle A pointer to the certificate bundle. + */ +void esp_crt_bundle_set(const uint8_t *x509_bundle); + + +#ifdef __cplusplus +} +#endif + +#endif //_ESP_CRT_BUNDLE_H_ diff --git a/libraries/WiFiClientSecure/src/ssl_client.cpp b/libraries/WiFiClientSecure/src/ssl_client.cpp index 38783aee2e4..6ab9b10570d 100644 --- a/libraries/WiFiClientSecure/src/ssl_client.cpp +++ b/libraries/WiFiClientSecure/src/ssl_client.cpp @@ -17,9 +17,10 @@ #include #include #include "ssl_client.h" +#include "esp_crt_bundle.h" #include "WiFi.h" -#ifndef MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED +#if !defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED) # warning "Please configure IDF framework to include mbedTLS -> Enable pre-shared-key ciphersuites and activate at least one cipher" #else @@ -53,14 +54,14 @@ void ssl_init(sslclient_context *ssl_client) } -int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t port, int timeout, const char *rootCABuff, const char *cli_cert, const char *cli_key, const char *pskIdent, const char *psKey, bool insecure, const char **alpn_protos) +int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t port, int timeout, const char *rootCABuff, bool useRootCABundle, const char *cli_cert, const char *cli_key, const char *pskIdent, const char *psKey, bool insecure, const char **alpn_protos) { char buf[512]; int ret, flags; int enable = 1; log_v("Free internal heap before TLS %u", ESP.getFreeHeap()); - if (rootCABuff == NULL && pskIdent == NULL && psKey == NULL && !insecure) { + if (rootCABuff == NULL && pskIdent == NULL && psKey == NULL && !insecure && !useRootCABundle) { return -1; } @@ -170,7 +171,7 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p if (insecure) { mbedtls_ssl_conf_authmode(&ssl_client->ssl_conf, MBEDTLS_SSL_VERIFY_NONE); - log_i("WARNING: Skipping SSL Verification. INSECURE!"); + log_d("WARNING: Skipping SSL Verification. INSECURE!"); } else if (rootCABuff != NULL) { log_v("Loading CA cert"); mbedtls_x509_crt_init(&ssl_client->ca_cert); @@ -183,6 +184,13 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p mbedtls_x509_crt_free(&ssl_client->ca_cert); return handle_error(ret); } + } else if (useRootCABundle) { + log_v("Attaching root CA cert bundle"); + ret = esp_crt_bundle_attach(&ssl_client->ssl_conf); + + if (ret < 0) { + return handle_error(ret); + } } else if (pskIdent != NULL && psKey != NULL) { log_v("Setting up PSK"); // convert PSK from hex to binary @@ -327,8 +335,13 @@ void stop_ssl_socket(sslclient_context *ssl_client, const char *rootCABuff, cons mbedtls_ssl_config_free(&ssl_client->ssl_conf); mbedtls_ctr_drbg_free(&ssl_client->drbg_ctx); mbedtls_entropy_free(&ssl_client->entropy_ctx); + + // save only interesting field + int timeout = ssl_client->handshake_timeout; // reset embedded pointers to zero memset(ssl_client, 0, sizeof(sslclient_context)); + + ssl_client->handshake_timeout = timeout; } diff --git a/libraries/WiFiClientSecure/src/ssl_client.h b/libraries/WiFiClientSecure/src/ssl_client.h index d6be76d18a1..ea89e6bb50a 100644 --- a/libraries/WiFiClientSecure/src/ssl_client.h +++ b/libraries/WiFiClientSecure/src/ssl_client.h @@ -29,7 +29,7 @@ typedef struct sslclient_context { void ssl_init(sslclient_context *ssl_client); -int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t port, int timeout, const char *rootCABuff, const char *cli_cert, const char *cli_key, const char *pskIdent, const char *psKey, bool insecure, const char **alpn_protos); +int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t port, int timeout, const char *rootCABuff, bool useRootCABundle, const char *cli_cert, const char *cli_key, const char *pskIdent, const char *psKey, bool insecure, const char **alpn_protos); void stop_ssl_socket(sslclient_context *ssl_client, const char *rootCABuff, const char *cli_cert, const char *cli_key); int data_to_read(sslclient_context *ssl_client); int send_ssl_data(sslclient_context *ssl_client, const uint8_t *data, size_t len); diff --git a/libraries/WiFiProv/src/WiFiProv.h b/libraries/WiFiProv/src/WiFiProv.h index 11dfd2e47e1..bbcab41a6f8 100644 --- a/libraries/WiFiProv/src/WiFiProv.h +++ b/libraries/WiFiProv/src/WiFiProv.h @@ -17,6 +17,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef WiFiProv_h +#define WiFiProv_h + #include "WiFi.h" #include "wifi_provisioning/manager.h" //Select the scheme using which you want to provision @@ -48,3 +51,5 @@ class WiFiProvClass }; extern WiFiProvClass WiFiProv; + +#endif diff --git a/package.json b/package.json index 8b4729f1fa5..8204d5e4511 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "framework-arduinoespressif32", - "version": "0.0.0", + "version": "2.0.3", "description": "Arduino Wiring-based Framework for the Espressif ESP32, ESP32-S and ESP32-C series of SoCs", "keywords": [ "framework", diff --git a/package/package_esp32_index.template.json b/package/package_esp32_index.template.json index 565baf483bc..3c035f97ce8 100644 --- a/package/package_esp32_index.template.json +++ b/package/package_esp32_index.template.json @@ -28,6 +28,9 @@ { "name": "ESP32-S2 Dev Board" }, + { + "name": "ESP32-S3 Dev Board" + }, { "name": "ESP32-C3 Dev Board" } @@ -36,22 +39,27 @@ { "packager": "esp32", "name": "riscv32-esp-elf-gcc", - "version": "gcc8_4_0-esp-2021r2" + "version": "gcc8_4_0-esp-2021r2-patch3" }, { "packager": "esp32", "name": "xtensa-esp32-elf-gcc", - "version": "gcc8_4_0-esp-2021r2" + "version": "gcc8_4_0-esp-2021r2-patch3" }, { "packager": "esp32", "name": "xtensa-esp32s2-elf-gcc", - "version": "gcc8_4_0-esp-2021r2" + "version": "gcc8_4_0-esp-2021r2-patch3" + }, + { + "packager": "esp32", + "name": "xtensa-esp32s3-elf-gcc", + "version": "gcc8_4_0-esp-2021r2-patch3" }, { "packager": "esp32", "name": "esptool_py", - "version": "3.1.0" + "version": "3.3.0" }, { "packager": "esp32", @@ -69,214 +77,276 @@ "tools": [ { "name": "riscv32-esp-elf-gcc", - "version": "gcc8_4_0-esp-2021r2", + "version": "gcc8_4_0-esp-2021r2-patch3", "systems": [ { "host": "x86_64-pc-linux-gnu", - "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2/riscv32-esp-elf-gcc8_4_0-esp-2021r2-linux-amd64.tar.gz", - "archiveFileName": "riscv32-esp-elf-gcc8_4_0-esp-2021r2-linux-amd64.tar.gz", - "checksum": "SHA-256:812d735063da9d063b374b59f55832a96c41fbd27ddaef19000a75de8607ba21", - "size": "106837189" + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/riscv32-esp-elf-gcc8_4_0-esp-2021r2-patch3-linux-amd64.tar.gz", + "archiveFileName": "riscv32-esp-elf-gcc8_4_0-esp-2021r2-patch3-linux-amd64.tar.gz", + "checksum": "SHA-256:179cbad579790ad35e0f414a18d90017c0f158c397022411a8e9867db2174f15", + "size": "106843321" }, { "host": "aarch64-linux-gnu", - "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2/riscv32-esp-elf-gcc8_4_0-esp-2021r2-linux-arm64.tar.gz", - "archiveFileName": "riscv32-esp-elf-gcc8_4_0-esp-2021r2-linux-arm64.tar.gz", - "checksum": "SHA-256:712f1fbc3e08304a6f32aa18b346b16bbcb413b507b3d4c7c3211bf0d7dc4813", - "size": "103273444" + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/riscv32-esp-elf-gcc8_4_0-esp-2021r2-patch3-linux-arm64.tar.gz", + "archiveFileName": "riscv32-esp-elf-gcc8_4_0-esp-2021r2-patch3-linux-arm64.tar.gz", + "checksum": "SHA-256:fb339d476c79c76db8f903b265cab6bb6950d5ed954dec644445252d3378023c", + "size": "103277393" }, { "host": "arm-linux-gnueabihf", - "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2/riscv32-esp-elf-gcc8_4_0-esp-2021r2-linux-armel.tar.gz", - "archiveFileName": "riscv32-esp-elf-gcc8_4_0-esp-2021r2-linux-armel.tar.gz", - "checksum": "SHA-256:80a3342cda2cd4b6b75ebb2b36d5d12fce7d375cfadadcff01ec3a907f0a16a2", - "size": "103058744" + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/riscv32-esp-elf-gcc8_4_0-esp-2021r2-patch3-linux-armel.tar.gz", + "archiveFileName": "riscv32-esp-elf-gcc8_4_0-esp-2021r2-patch3-linux-armel.tar.gz", + "checksum": "SHA-256:51a6296d8334b7452dba44b2b62e87afd7fd1c74bafa1aa29b1f4ab72cb9e5e0", + "size": "103062256" }, { "host": "i686-pc-linux-gnu", - "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2/riscv32-esp-elf-gcc8_4_0-esp-2021r2-linux-i686.tar.gz", - "archiveFileName": "riscv32-esp-elf-gcc8_4_0-esp-2021r2-linux-i686.tar.gz", - "checksum": "SHA-256:7f0162a81558ab0ed09d6c5d356def25b5cb3d5c2d61358f20152fa260ccc8ae", - "size": "109447789" + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/riscv32-esp-elf-gcc8_4_0-esp-2021r2-patch3-linux-i686.tar.gz", + "archiveFileName": "riscv32-esp-elf-gcc8_4_0-esp-2021r2-patch3-linux-i686.tar.gz", + "checksum": "SHA-256:fef60f7ef37ffaa50416d8f244cdbd710d6729dae41ef06c4ec0e50a1f3b7dd7", + "size": "109460025" }, { "host": "x86_64-apple-darwin", - "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2/riscv32-esp-elf-gcc8_4_0-esp-2021r2-macos.tar.gz", - "archiveFileName": "riscv32-esp-elf-gcc8_4_0-esp-2021r2-macos.tar.gz", - "checksum": "SHA-256:3ff7e5427907cf8e271c1f959b70fb01e39625c3caf61a6567e7b38aa0c11578", - "size": "113672945" + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/riscv32-esp-elf-gcc8_4_0-esp-2021r2-patch3-macos.tar.gz", + "archiveFileName": "riscv32-esp-elf-gcc8_4_0-esp-2021r2-patch3-macos.tar.gz", + "checksum": "SHA-256:4aacc1742a76349d790b1ac8e9e9d963daefda5346dbd6741cfe8e7a35a44e4e", + "size": "113703959" }, { "host": "i686-mingw32", - "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2/riscv32-esp-elf-gcc8_4_0-esp-2021r2-win32.zip", - "archiveFileName": "riscv32-esp-elf-gcc8_4_0-esp-2021r2-win32.zip", - "checksum": "SHA-256:c8ff08883c1456c278fad85e1c43b7c6e251d525683214168655550e85c5b82e", - "size": "140809778" + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/riscv32-esp-elf-gcc8_4_0-esp-2021r2-patch3-win32.zip", + "archiveFileName": "riscv32-esp-elf-gcc8_4_0-esp-2021r2-patch3-win32.zip", + "checksum": "SHA-256:eb2a442d7f551ebeb842995ec372ec4b364314ca2d7aae779399a74972f7d6bc", + "size": "144711970" }, { "host": "x86_64-mingw32", - "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2/riscv32-esp-elf-gcc8_4_0-esp-2021r2-win64.zip", - "archiveFileName": "riscv32-esp-elf-gcc8_4_0-esp-2021r2-win64.zip", - "checksum": "SHA-256:6c04cb4728db928ec6473e63146b695b6dec686a0d40dd73dd3353f05247b19e", - "size": "142365782" + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/riscv32-esp-elf-gcc8_4_0-esp-2021r2-patch3-win64.zip", + "archiveFileName": "riscv32-esp-elf-gcc8_4_0-esp-2021r2-patch3-win64.zip", + "checksum": "SHA-256:f5607e5187317d521f0474cade83f8eb590f2d165d95c3779b6ce11fbac21d1f", + "size": "146606480" } ] }, { "name": "xtensa-esp32-elf-gcc", - "version": "gcc8_4_0-esp-2021r2", + "version": "gcc8_4_0-esp-2021r2-patch3", "systems": [ { "host": "x86_64-pc-linux-gnu", - "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2/xtensa-esp32-elf-gcc8_4_0-esp-2021r2-linux-amd64.tar.gz", - "archiveFileName": "xtensa-esp32-elf-gcc8_4_0-esp-2021r2-linux-amd64.tar.gz", - "checksum": "SHA-256:3eb3d68b27fa6ba5af6f88da21cb8face9be0094daaa8960793cfe570ab785ff", - "size": "90565318" + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/xtensa-esp32-elf-gcc8_4_0-esp-2021r2-patch3-linux-amd64.tar.gz", + "archiveFileName": "xtensa-esp32-elf-gcc8_4_0-esp-2021r2-patch3-linux-amd64.tar.gz", + "checksum": "SHA-256:9edd1e77627688f435561922d14299f6a0021ba1f6ff67e472e1108695a69e53", + "size": "90569312" }, { "host": "aarch64-linux-gnu", - "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2/xtensa-esp32-elf-gcc8_4_0-esp-2021r2-linux-arm64.tar.gz", - "archiveFileName": "xtensa-esp32-elf-gcc8_4_0-esp-2021r2-linux-arm64.tar.gz", - "checksum": "SHA-256:aa534be24e45e06b7080a6a3bb8cd9e3cfb818f5f8bce2244d7cfb5e91336541", - "size": "86860292" + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/xtensa-esp32-elf-gcc8_4_0-esp-2021r2-patch3-linux-arm64.tar.gz", + "archiveFileName": "xtensa-esp32-elf-gcc8_4_0-esp-2021r2-patch3-linux-arm64.tar.gz", + "checksum": "SHA-256:3a21a3e310e6b1e7d7bed1f3e59698a5bd29ed3a5ca79fba9265d7dd2f1e0cd2", + "size": "86838362" }, { "host": "arm-linux-gnueabihf", - "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2/xtensa-esp32-elf-gcc8_4_0-esp-2021r2-linux-armel.tar.gz", - "archiveFileName": "xtensa-esp32-elf-gcc8_4_0-esp-2021r2-linux-armel.tar.gz", - "checksum": "SHA-256:f0e49ce06fe7833ff5d76961dc2dac5449d320f823bb8c05a302cf85a3a6eb04", - "size": "86183421" + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/xtensa-esp32-elf-gcc8_4_0-esp-2021r2-patch3-linux-armel.tar.gz", + "archiveFileName": "xtensa-esp32-elf-gcc8_4_0-esp-2021r2-patch3-linux-armel.tar.gz", + "checksum": "SHA-256:89313c4c1d8db1b01624f31b58bf3fbe527160569828ac4301e9daa75c52716d", + "size": "86187540" }, { "host": "i686-pc-linux-gnu", - "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2/xtensa-esp32-elf-gcc8_4_0-esp-2021r2-linux-i686.tar.gz", - "archiveFileName": "xtensa-esp32-elf-gcc8_4_0-esp-2021r2-linux-i686.tar.gz", - "checksum": "SHA-256:06de09b74652de43e5b22db3b7fc992623044baa75e9faaab68317a986715ba3", - "size": "92582250" + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/xtensa-esp32-elf-gcc8_4_0-esp-2021r2-patch3-linux-i686.tar.gz", + "archiveFileName": "xtensa-esp32-elf-gcc8_4_0-esp-2021r2-patch3-linux-i686.tar.gz", + "checksum": "SHA-256:a1f165a836f175daa6fbfde4ca99cb93b377f021fbfc41f79a700bd4df965a9a", + "size": "92580267" }, { "host": "x86_64-apple-darwin", - "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2/xtensa-esp32-elf-gcc8_4_0-esp-2021r2-macos.tar.gz", - "archiveFileName": "xtensa-esp32-elf-gcc8_4_0-esp-2021r2-macos.tar.gz", - "checksum": "SHA-256:96443f69c8569417c780ee749d91ef33cffe22153fffa30a0fbf12107d87381b", - "size": "97808961" + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/xtensa-esp32-elf-gcc8_4_0-esp-2021r2-patch3-macos.tar.gz", + "archiveFileName": "xtensa-esp32-elf-gcc8_4_0-esp-2021r2-patch3-macos.tar.gz", + "checksum": "SHA-256:dda3d7a43efd995d9a51d5a5741626dbf915df46078aef0b5aea7163ac82398b", + "size": "97807647" }, { "host": "i686-mingw32", - "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2/xtensa-esp32-elf-gcc8_4_0-esp-2021r2-win32.zip", - "archiveFileName": "xtensa-esp32-elf-gcc8_4_0-esp-2021r2-win32.zip", - "checksum": "SHA-256:076a4171bdc33e5ced3952efffb233d70263dfa760e636704050597a9edf61db", - "size": "112578260" + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/xtensa-esp32-elf-gcc8_4_0-esp-2021r2-patch3-win32.zip", + "archiveFileName": "xtensa-esp32-elf-gcc8_4_0-esp-2021r2-patch3-win32.zip", + "checksum": "SHA-256:fd147592928ef2d7092ba34b01ecd776fe26ba3d7e3f9b6b215a3b46e981ee2c", + "size": "116464819" }, { "host": "x86_64-mingw32", - "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2/xtensa-esp32-elf-gcc8_4_0-esp-2021r2-win64.zip", - "archiveFileName": "xtensa-esp32-elf-gcc8_4_0-esp-2021r2-win64.zip", - "checksum": "SHA-256:c35b7998f7f503e0cb22055d1e279ae14b6b0e09bb3ff3846b17d552ece9c247", - "size": "115278695" + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/xtensa-esp32-elf-gcc8_4_0-esp-2021r2-patch3-win64.zip", + "archiveFileName": "xtensa-esp32-elf-gcc8_4_0-esp-2021r2-patch3-win64.zip", + "checksum": "SHA-256:9395315c07de0b9f05c9a6616ba1f05e76ab651053f2f40479163a8e03cfa830", + "size": "119511910" } ] }, { "name": "xtensa-esp32s2-elf-gcc", - "version": "gcc8_4_0-esp-2021r2", + "version": "gcc8_4_0-esp-2021r2-patch3", "systems": [ { "host": "x86_64-pc-linux-gnu", - "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2/xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-linux-amd64.tar.gz", - "archiveFileName": "xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-linux-amd64.tar.gz", - "checksum": "SHA-256:a6e0947c92b823ca04f062522249f0a428357e0b056f1ff4c6bcabef83cf63a7", - "size": "90901736" + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-patch3-linux-amd64.tar.gz", + "archiveFileName": "xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-patch3-linux-amd64.tar.gz", + "checksum": "SHA-256:a32451a8edc1104b83cd9971178e61826e957d7db9ad9f81798a8969fd5a954e", + "size": "90894048" }, { "host": "aarch64-linux-gnu", - "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2/xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-linux-arm64.tar.gz", - "archiveFileName": "xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-linux-arm64.tar.gz", - "checksum": "SHA-256:d2e5600fc194b508bd393b236a09fd62ed70afb6c36619d4b106b696a56ca66d", - "size": "87176557" + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-patch3-linux-arm64.tar.gz", + "archiveFileName": "xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-patch3-linux-arm64.tar.gz", + "checksum": "SHA-256:2ac2c94a533a99a091d2159c678c611c712c494b5f68d97913254712047260f9", + "size": "87178224" }, { "host": "arm-linux-gnueabihf", - "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2/xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-linux-armel.tar.gz", - "archiveFileName": "xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-linux-armel.tar.gz", - "checksum": "SHA-256:3fff4199e986dd74660f17ca27d9414cb98f1b911a7f13bb3b22e784cb1156cf", - "size": "86581102" + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-patch3-linux-armel.tar.gz", + "archiveFileName": "xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-patch3-linux-armel.tar.gz", + "checksum": "SHA-256:da49afee1e2e03eaab3f492718789442d33b562800e2a892679f95b50be24d14", + "size": "86569314" }, { "host": "i686-pc-linux-gnu", - "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2/xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-linux-i686.tar.gz", - "archiveFileName": "xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-linux-i686.tar.gz", - "checksum": "SHA-256:7732f9fb371d36b6b324820e300beecc33c2719921a61cf1cdb5bc625016b346", - "size": "92875986" + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-patch3-linux-i686.tar.gz", + "archiveFileName": "xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-patch3-linux-i686.tar.gz", + "checksum": "SHA-256:36d3c4990a5feb68aa8534463bc9e8ee367fe23886f78e1d726f4411c7571462", + "size": "92884013" }, { "host": "x86_64-apple-darwin", - "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2/xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-macos.tar.gz", - "archiveFileName": "xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-macos.tar.gz", - "checksum": "SHA-256:e6dd32782fcff8f633299b97d1c671d6b6513390aca2ddbd7543c2cc62e72d7e", - "size": "98212907" + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-patch3-macos.tar.gz", + "archiveFileName": "xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-patch3-macos.tar.gz", + "checksum": "SHA-256:de9af641678c93775e932ee5ec4f478f8925cfc1ebc22e41adc4fb85430a0c35", + "size": "98224709" }, { "host": "i686-mingw32", - "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2/xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-win32.zip", - "archiveFileName": "xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-win32.zip", - "checksum": "SHA-256:41b917b35f6fbe7d30b7de91c32cf348c406acfa729a1eabc450d040dc46fbe2", - "size": "113022469" + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-patch3-win32.zip", + "archiveFileName": "xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-patch3-win32.zip", + "checksum": "SHA-256:ccf08afe60046f87b0e81ca17dc5073eda68ab5e7522c163dd5b583d713b7b39", + "size": "116924759" }, { "host": "x86_64-mingw32", - "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2/xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-win64.zip", - "archiveFileName": "xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-win64.zip", - "checksum": "SHA-256:a764c1a0ee743d69f8cbfadbe4426a2c15c0e233b0894244c7cadf3b4d7dd32a", - "size": "115696999" + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-patch3-win64.zip", + "archiveFileName": "xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2-patch3-win64.zip", + "checksum": "SHA-256:37c91490b8fc75e638c23785e261eaf553be2dcd106cf6cff5b76981fa02955b", + "size": "119912142" + } + ] + }, + { + "name": "xtensa-esp32s3-elf-gcc", + "version": "gcc8_4_0-esp-2021r2-patch3", + "systems": [ + { + "host": "x86_64-pc-linux-gnu", + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/xtensa-esp32s3-elf-gcc8_4_0-esp-2021r2-patch3-linux-amd64.tar.gz", + "archiveFileName": "xtensa-esp32s3-elf-gcc8_4_0-esp-2021r2-patch3-linux-amd64.tar.gz", + "checksum": "SHA-256:59b271d014ff3915b6db1b43b610a45eea15fe5d6877d12cae8a191cc996ed37", + "size": "90903617" + }, + { + "host": "aarch64-linux-gnu", + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/xtensa-esp32s3-elf-gcc8_4_0-esp-2021r2-patch3-linux-arm64.tar.gz", + "archiveFileName": "xtensa-esp32s3-elf-gcc8_4_0-esp-2021r2-patch3-linux-arm64.tar.gz", + "checksum": "SHA-256:7051b32483e61f98606d71c98e372929428a5165df791dcd5830ed9517763152", + "size": "87065204" + }, + { + "host": "arm-linux-gnueabihf", + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/xtensa-esp32s3-elf-gcc8_4_0-esp-2021r2-patch3-linux-armel.tar.gz", + "archiveFileName": "xtensa-esp32s3-elf-gcc8_4_0-esp-2021r2-patch3-linux-armel.tar.gz", + "checksum": "SHA-256:48c8dbbf96eec691a812327dc580042d9718fe989e60c2111ebfd692ac710081", + "size": "86455731" + }, + { + "host": "i686-pc-linux-gnu", + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/xtensa-esp32s3-elf-gcc8_4_0-esp-2021r2-patch3-linux-i686.tar.gz", + "archiveFileName": "xtensa-esp32s3-elf-gcc8_4_0-esp-2021r2-patch3-linux-i686.tar.gz", + "checksum": "SHA-256:552dca3f4302ab7ca88a934b0391200198c9d10a4d8ac413fe604cbf8601f950", + "size": "92906274" + }, + { + "host": "x86_64-apple-darwin", + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/xtensa-esp32s3-elf-gcc8_4_0-esp-2021r2-patch3-macos.tar.gz", + "archiveFileName": "xtensa-esp32s3-elf-gcc8_4_0-esp-2021r2-patch3-macos.tar.gz", + "checksum": "SHA-256:e5af78f05d3af07617805d06ebb45ff2fe9b6aed6970a84c35eea28a5d8d5e53", + "size": "98553473" + }, + { + "host": "i686-mingw32", + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/xtensa-esp32s3-elf-gcc8_4_0-esp-2021r2-patch3-win32.zip", + "archiveFileName": "xtensa-esp32s3-elf-gcc8_4_0-esp-2021r2-patch3-win32.zip", + "checksum": "SHA-256:1b70163acccc5655449de1d149427a54f384156bd35816ec60c422d76d033f05", + "size": "116847008" + }, + { + "host": "x86_64-mingw32", + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/xtensa-esp32s3-elf-gcc8_4_0-esp-2021r2-patch3-win64.zip", + "archiveFileName": "xtensa-esp32s3-elf-gcc8_4_0-esp-2021r2-patch3-win64.zip", + "checksum": "SHA-256:58e58575d1938879fd51e822181e54bcb343aa846eb3fca8f616c2cde7bd0041", + "size": "120066269" } ] }, { "name": "esptool_py", - "version": "3.1.0", + "version": "3.3.0", "systems": [ { "host": "i686-mingw32", - "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.0-alpha1/esptool-3.1.0-windows.zip", - "archiveFileName": "esptool-3.1.0-windows.zip", - "checksum": "SHA-256:c9b4f9bc6e94db136c2545c87c00c7ab1441644ca0bac50811bc3c014e22514b", - "size": "7411889" + "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.2/esptool-3.3-windows.zip", + "archiveFileName": "esptool-3.3-windows.zip", + "checksum": "SHA-256:55a1d7165414bf4dbd2bb16ca094e555d671958450f5d1536b457a518d2b15df", + "size": "7436864" + }, + { + "host": "x86_64-mingw32", + "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.2/esptool-3.3-windows.zip", + "archiveFileName": "esptool-3.3-windows.zip", + "checksum": "SHA-256:55a1d7165414bf4dbd2bb16ca094e555d671958450f5d1536b457a518d2b15df", + "size": "7436864" }, { "host": "x86_64-apple-darwin", - "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.0-alpha1/esptool-3.1.0-macos.tar.gz", - "archiveFileName": "esptool-3.1.0-macos.tar.gz", - "checksum": "SHA-256:1dffcb884665fb616779aea62a68f517aac251ea6dfe95560906c364d6ef3065", - "size": "6776909" + "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.2/esptool-3.3-macos.tar.gz", + "archiveFileName": "esptool-3.3-macos.tar.gz", + "checksum": "SHA-256:3e5f7b521ae33c8c63f3b48efc909c08f37bef1a083c0eafa408312c09900afd", + "size": "6944975" }, { "host": "x86_64-pc-linux-gnu", - "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.0-alpha1/esptool-3.1.0-linux.tar.gz", - "archiveFileName": "esptool-3.1.0-linux.tar.gz", - "checksum": "SHA-256:15eca9896a30e804aa24be6f7a06e39397541b8b09a7a4c48deb65f826e7baad", - "size": "80550" + "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.2/esptool-3.3-linux.tar.gz", + "archiveFileName": "esptool-3.3-linux.tar.gz", + "checksum": "SHA-256:fbe91a49e5f5deca4881f5eed32e8903faf97bfd365fe2d0d1512b80bdb67f5e", + "size": "97026" }, { "host": "i686-pc-linux-gnu", - "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.0-alpha1/esptool-3.1.0-linux.tar.gz", - "archiveFileName": "esptool-3.1.0-linux.tar.gz", - "checksum": "SHA-256:15eca9896a30e804aa24be6f7a06e39397541b8b09a7a4c48deb65f826e7baad", - "size": "80550" + "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.2/esptool-3.3-linux.tar.gz", + "archiveFileName": "esptool-3.3-linux.tar.gz", + "checksum": "SHA-256:fbe91a49e5f5deca4881f5eed32e8903faf97bfd365fe2d0d1512b80bdb67f5e", + "size": "97026" }, { "host": "arm-linux-gnueabihf", - "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.0-alpha1/esptool-3.1.0-linux.tar.gz", - "archiveFileName": "esptool-3.1.0-linux.tar.gz", - "checksum": "SHA-256:15eca9896a30e804aa24be6f7a06e39397541b8b09a7a4c48deb65f826e7baad", - "size": "80550" + "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.2/esptool-3.3-linux.tar.gz", + "archiveFileName": "esptool-3.3-linux.tar.gz", + "checksum": "SHA-256:fbe91a49e5f5deca4881f5eed32e8903faf97bfd365fe2d0d1512b80bdb67f5e", + "size": "97026" }, { "host": "aarch64-linux-gnu", - "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.0-alpha1/esptool-3.1.0-linux.tar.gz", - "archiveFileName": "esptool-3.1.0-linux.tar.gz", - "checksum": "SHA-256:15eca9896a30e804aa24be6f7a06e39397541b8b09a7a4c48deb65f826e7baad", - "size": "80550" + "url": "https://github.com/espressif/arduino-esp32/releases/download/2.0.2/esptool-3.3-linux.tar.gz", + "archiveFileName": "esptool-3.3-linux.tar.gz", + "checksum": "SHA-256:fbe91a49e5f5deca4881f5eed32e8903faf97bfd365fe2d0d1512b80bdb67f5e", + "size": "97026" } ] }, diff --git a/platform.txt b/platform.txt index 2a8a3283b1d..351889e1a22 100644 --- a/platform.txt +++ b/platform.txt @@ -1,8 +1,9 @@ name=ESP32 Arduino -version=2.0.0 +version=2.0.3 runtime.tools.xtensa-esp32-elf-gcc.path={runtime.platform.path}/tools/xtensa-esp32-elf runtime.tools.xtensa-esp32s2-elf-gcc.path={runtime.platform.path}/tools/xtensa-esp32s2-elf +runtime.tools.xtensa-esp32s3-elf-gcc.path={runtime.platform.path}/tools/xtensa-esp32s3-elf runtime.tools.riscv32-esp-elf-gcc.path={runtime.platform.path}/tools/riscv32-esp-elf tools.esptool_py.path={runtime.platform.path}/tools/esptool @@ -10,10 +11,13 @@ tools.esptool_py.cmd=esptool tools.esptool_py.cmd.linux=esptool.py tools.esptool_py.cmd.windows=esptool.exe -tools.esptool_py.network_cmd=python "{runtime.platform.path}/tools/espota.py" -r +tools.esptool_py.network_cmd=python3 "{runtime.platform.path}/tools/espota.py" -r tools.esptool_py.network_cmd.windows="{runtime.platform.path}/tools/espota.exe" -r -tools.gen_esp32part.cmd=python "{runtime.platform.path}/tools/gen_esp32part.py" +tools.esp_ota.cmd=python3 "{runtime.platform.path}/tools/espota.py" -r +tools.esp_ota.cmd.windows="{runtime.platform.path}/tools/espota.exe" -r + +tools.gen_esp32part.cmd=python3 "{runtime.platform.path}/tools/gen_esp32part.py" tools.gen_esp32part.cmd.windows="{runtime.platform.path}/tools/gen_esp32part.exe" compiler.path={runtime.tools.{build.tarch}-{build.target}-elf-gcc.path}/bin/ @@ -23,29 +27,44 @@ compiler.prefix={build.tarch}-{build.target}-elf- # # ESP32 Support Start # -compiler.cpreprocessor.flags.esp32=-DHAVE_CONFIG_H -DMBEDTLS_CONFIG_FILE="mbedtls/esp_config.h" -DUNITY_INCLUDE_CONFIG_H -DWITH_POSIX -D_GNU_SOURCE -DIDF_VER="v4.4-beta1-189-ga79dc75f0a" -DESP_PLATFORM -D_POSIX_READER_WRITER_LOCKS "-I{compiler.sdk.path}/include/config" "-I{compiler.sdk.path}/include/newlib/platform_include" "-I{compiler.sdk.path}/include/freertos/include" "-I{compiler.sdk.path}/include/freertos/include/esp_additions/freertos" "-I{compiler.sdk.path}/include/freertos/port/xtensa/include" "-I{compiler.sdk.path}/include/freertos/include/esp_additions" "-I{compiler.sdk.path}/include/esp_hw_support/include" "-I{compiler.sdk.path}/include/esp_hw_support/include/soc" "-I{compiler.sdk.path}/include/esp_hw_support/include/soc/esp32" "-I{compiler.sdk.path}/include/esp_hw_support/port/esp32" "-I{compiler.sdk.path}/include/heap/include" "-I{compiler.sdk.path}/include/log/include" "-I{compiler.sdk.path}/include/lwip/include/apps" "-I{compiler.sdk.path}/include/lwip/include/apps/sntp" "-I{compiler.sdk.path}/include/lwip/lwip/src/include" "-I{compiler.sdk.path}/include/lwip/port/esp32/include" "-I{compiler.sdk.path}/include/lwip/port/esp32/include/arch" "-I{compiler.sdk.path}/include/soc/include" "-I{compiler.sdk.path}/include/soc/esp32" "-I{compiler.sdk.path}/include/soc/esp32/include" "-I{compiler.sdk.path}/include/hal/esp32/include" "-I{compiler.sdk.path}/include/hal/include" "-I{compiler.sdk.path}/include/hal/platform_port/include" "-I{compiler.sdk.path}/include/esp_rom/include" "-I{compiler.sdk.path}/include/esp_rom/include/esp32" "-I{compiler.sdk.path}/include/esp_rom/esp32" "-I{compiler.sdk.path}/include/esp_common/include" "-I{compiler.sdk.path}/include/esp_system/include" "-I{compiler.sdk.path}/include/esp_system/port/soc" "-I{compiler.sdk.path}/include/esp_system/port/public_compat" "-I{compiler.sdk.path}/include/esp32/include" "-I{compiler.sdk.path}/include/xtensa/include" "-I{compiler.sdk.path}/include/xtensa/esp32/include" "-I{compiler.sdk.path}/include/driver/include" "-I{compiler.sdk.path}/include/driver/esp32/include" "-I{compiler.sdk.path}/include/esp_pm/include" "-I{compiler.sdk.path}/include/esp_ringbuf/include" "-I{compiler.sdk.path}/include/efuse/include" "-I{compiler.sdk.path}/include/efuse/esp32/include" "-I{compiler.sdk.path}/include/vfs/include" "-I{compiler.sdk.path}/include/esp_wifi/include" "-I{compiler.sdk.path}/include/esp_event/include" "-I{compiler.sdk.path}/include/esp_netif/include" "-I{compiler.sdk.path}/include/esp_eth/include" "-I{compiler.sdk.path}/include/tcpip_adapter/include" "-I{compiler.sdk.path}/include/esp_phy/include" "-I{compiler.sdk.path}/include/esp_phy/esp32/include" "-I{compiler.sdk.path}/include/esp_ipc/include" "-I{compiler.sdk.path}/include/app_trace/include" "-I{compiler.sdk.path}/include/esp_timer/include" "-I{compiler.sdk.path}/include/mbedtls/port/include" "-I{compiler.sdk.path}/include/mbedtls/mbedtls/include" "-I{compiler.sdk.path}/include/mbedtls/esp_crt_bundle/include" "-I{compiler.sdk.path}/include/app_update/include" "-I{compiler.sdk.path}/include/spi_flash/include" "-I{compiler.sdk.path}/include/bootloader_support/include" "-I{compiler.sdk.path}/include/nvs_flash/include" "-I{compiler.sdk.path}/include/pthread/include" "-I{compiler.sdk.path}/include/esp_gdbstub/include" "-I{compiler.sdk.path}/include/esp_gdbstub/xtensa" "-I{compiler.sdk.path}/include/esp_gdbstub/esp32" "-I{compiler.sdk.path}/include/espcoredump/include" "-I{compiler.sdk.path}/include/espcoredump/include/port/xtensa" "-I{compiler.sdk.path}/include/wpa_supplicant/include" "-I{compiler.sdk.path}/include/wpa_supplicant/port/include" "-I{compiler.sdk.path}/include/wpa_supplicant/esp_supplicant/include" "-I{compiler.sdk.path}/include/ieee802154/include" "-I{compiler.sdk.path}/include/console" "-I{compiler.sdk.path}/include/asio/asio/asio/include" "-I{compiler.sdk.path}/include/asio/port/include" "-I{compiler.sdk.path}/include/bt/common/osi/include" "-I{compiler.sdk.path}/include/bt/include/esp32/include" "-I{compiler.sdk.path}/include/bt/common/api/include/api" "-I{compiler.sdk.path}/include/bt/common/btc/profile/esp/blufi/include" "-I{compiler.sdk.path}/include/bt/common/btc/profile/esp/include" "-I{compiler.sdk.path}/include/bt/host/bluedroid/api/include/api" "-I{compiler.sdk.path}/include/cbor/port/include" "-I{compiler.sdk.path}/include/unity/include" "-I{compiler.sdk.path}/include/unity/unity/src" "-I{compiler.sdk.path}/include/cmock/CMock/src" "-I{compiler.sdk.path}/include/coap/port/include" "-I{compiler.sdk.path}/include/coap/libcoap/include" "-I{compiler.sdk.path}/include/nghttp/port/include" "-I{compiler.sdk.path}/include/nghttp/nghttp2/lib/includes" "-I{compiler.sdk.path}/include/esp-tls" "-I{compiler.sdk.path}/include/esp-tls/esp-tls-crypto" "-I{compiler.sdk.path}/include/esp_adc_cal/include" "-I{compiler.sdk.path}/include/esp_hid/include" "-I{compiler.sdk.path}/include/tcp_transport/include" "-I{compiler.sdk.path}/include/esp_http_client/include" "-I{compiler.sdk.path}/include/esp_http_server/include" "-I{compiler.sdk.path}/include/esp_https_ota/include" "-I{compiler.sdk.path}/include/esp_lcd/include" "-I{compiler.sdk.path}/include/esp_lcd/interface" "-I{compiler.sdk.path}/include/protobuf-c/protobuf-c" "-I{compiler.sdk.path}/include/protocomm/include/common" "-I{compiler.sdk.path}/include/protocomm/include/security" "-I{compiler.sdk.path}/include/protocomm/include/transports" "-I{compiler.sdk.path}/include/mdns/include" "-I{compiler.sdk.path}/include/esp_local_ctrl/include" "-I{compiler.sdk.path}/include/sdmmc/include" "-I{compiler.sdk.path}/include/esp_serial_slave_link/include" "-I{compiler.sdk.path}/include/esp_websocket_client/include" "-I{compiler.sdk.path}/include/expat/expat/expat/lib" "-I{compiler.sdk.path}/include/expat/port/include" "-I{compiler.sdk.path}/include/wear_levelling/include" "-I{compiler.sdk.path}/include/fatfs/diskio" "-I{compiler.sdk.path}/include/fatfs/vfs" "-I{compiler.sdk.path}/include/fatfs/src" "-I{compiler.sdk.path}/include/freemodbus/common/include" "-I{compiler.sdk.path}/include/idf_test/include" "-I{compiler.sdk.path}/include/idf_test/include/esp32" "-I{compiler.sdk.path}/include/jsmn/include" "-I{compiler.sdk.path}/include/json/cJSON" "-I{compiler.sdk.path}/include/libsodium/libsodium/src/libsodium/include" "-I{compiler.sdk.path}/include/libsodium/port_include" "-I{compiler.sdk.path}/include/mqtt/esp-mqtt/include" "-I{compiler.sdk.path}/include/openssl/include" "-I{compiler.sdk.path}/include/perfmon/include" "-I{compiler.sdk.path}/include/spiffs/include" "-I{compiler.sdk.path}/include/ulp/include" "-I{compiler.sdk.path}/include/wifi_provisioning/include" "-I{compiler.sdk.path}/include/button/button/include" "-I{compiler.sdk.path}/include/json_parser" "-I{compiler.sdk.path}/include/json_parser/jsmn/include" "-I{compiler.sdk.path}/include/json_generator" "-I{compiler.sdk.path}/include/esp_schedule/include" "-I{compiler.sdk.path}/include/esp_rainmaker/include" "-I{compiler.sdk.path}/include/qrcode/include" "-I{compiler.sdk.path}/include/ws2812_led" "-I{compiler.sdk.path}/include/esp_littlefs/src" "-I{compiler.sdk.path}/include/esp_littlefs/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/dotprod/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/support/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/hann/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/blackman/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/blackman_harris/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/blackman_nuttall/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/nuttall/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/flat_top/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/iir/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/fir/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/add/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/sub/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/mul/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/addc/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/mulc/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/sqrt/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/matrix/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/fft/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/dct/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/conv/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/common/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/kalman/ekf/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/kalman/ekf_imu13states/include" "-I{compiler.sdk.path}/include/esp-face/include" "-I{compiler.sdk.path}/include/esp-face/include/tool" "-I{compiler.sdk.path}/include/esp-face/include/typedef" "-I{compiler.sdk.path}/include/esp-face/include/image" "-I{compiler.sdk.path}/include/esp-face/include/math" "-I{compiler.sdk.path}/include/esp-face/include/nn" "-I{compiler.sdk.path}/include/esp-face/include/layer" "-I{compiler.sdk.path}/include/esp-face/include/detect" "-I{compiler.sdk.path}/include/esp-face/include/model_zoo" "-I{compiler.sdk.path}/include/esp32-camera/driver/include" "-I{compiler.sdk.path}/include/esp32-camera/conversions/include" "-I{compiler.sdk.path}/include/fb_gfx/include" -compiler.c.elf.libs.esp32=-lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lasio -lbt -lcbor -lunity -lcmock -lcoap -lnghttp -lesp-tls -lesp_adc_cal -lesp_hid -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lesp_lcd -lprotobuf-c -lprotocomm -lmdns -lesp_local_ctrl -lsdmmc -lesp_serial_slave_link -lesp_websocket_client -lexpat -lwear_levelling -lfatfs -lfreemodbus -ljsmn -ljson -llibsodium -lmqtt -lopenssl -lperfmon -lspiffs -lulp -lwifi_provisioning -lbutton -ljson_parser -ljson_generator -lesp_schedule -lesp_rainmaker -lqrcode -lws2812_led -lesp-dsp -lesp32-camera -lesp_littlefs -lfb_gfx -lasio -lcbor -lcmock -lunity -lcoap -lesp_lcd -lesp_local_ctrl -lesp_websocket_client -lexpat -lfreemodbus -ljsmn -llibsodium -lperfmon -lesp_adc_cal -lesp_hid -lfatfs -lwear_levelling -lopenssl -lspiffs -lesp_rainmaker -lmqtt -lwifi_provisioning -lprotocomm -lbt -lbtdm_app -lprotobuf-c -lmdns -ljson -ljson_parser -ljson_generator -lesp_schedule -lqrcode -lcat_face_detect -lhuman_face_detect -lcolor_detect -lmfn -ldl -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lphy -lrtc -lesp_phy -lphy -lrtc -lesp_phy -lphy -lrtc -lxt_hal -lm -lnewlib -lstdc++ -lpthread -lgcc -lcxx -lapp_trace -lgcov -lapp_trace -lgcov -lc +compiler.cpreprocessor.flags.esp32=-DHAVE_CONFIG_H -DMBEDTLS_CONFIG_FILE="mbedtls/esp_config.h" -DUNITY_INCLUDE_CONFIG_H -DWITH_POSIX -D_GNU_SOURCE -DIDF_VER="v4.4.1-1-gb8050b365e" -DESP_PLATFORM -D_POSIX_READER_WRITER_LOCKS "-I{compiler.sdk.path}/include/config" "-I{compiler.sdk.path}/include/newlib/platform_include" "-I{compiler.sdk.path}/include/freertos/include" "-I{compiler.sdk.path}/include/freertos/include/esp_additions/freertos" "-I{compiler.sdk.path}/include/freertos/port/xtensa/include" "-I{compiler.sdk.path}/include/freertos/include/esp_additions" "-I{compiler.sdk.path}/include/esp_hw_support/include" "-I{compiler.sdk.path}/include/esp_hw_support/include/soc" "-I{compiler.sdk.path}/include/esp_hw_support/include/soc/esp32" "-I{compiler.sdk.path}/include/esp_hw_support/port/esp32" "-I{compiler.sdk.path}/include/esp_hw_support/port/esp32/private_include" "-I{compiler.sdk.path}/include/heap/include" "-I{compiler.sdk.path}/include/log/include" "-I{compiler.sdk.path}/include/lwip/include/apps" "-I{compiler.sdk.path}/include/lwip/include/apps/sntp" "-I{compiler.sdk.path}/include/lwip/lwip/src/include" "-I{compiler.sdk.path}/include/lwip/port/esp32/include" "-I{compiler.sdk.path}/include/lwip/port/esp32/include/arch" "-I{compiler.sdk.path}/include/soc/include" "-I{compiler.sdk.path}/include/soc/esp32" "-I{compiler.sdk.path}/include/soc/esp32/include" "-I{compiler.sdk.path}/include/hal/esp32/include" "-I{compiler.sdk.path}/include/hal/include" "-I{compiler.sdk.path}/include/hal/platform_port/include" "-I{compiler.sdk.path}/include/esp_rom/include" "-I{compiler.sdk.path}/include/esp_rom/include/esp32" "-I{compiler.sdk.path}/include/esp_rom/esp32" "-I{compiler.sdk.path}/include/esp_common/include" "-I{compiler.sdk.path}/include/esp_system/include" "-I{compiler.sdk.path}/include/esp_system/port/soc" "-I{compiler.sdk.path}/include/esp_system/port/public_compat" "-I{compiler.sdk.path}/include/esp32/include" "-I{compiler.sdk.path}/include/xtensa/include" "-I{compiler.sdk.path}/include/xtensa/esp32/include" "-I{compiler.sdk.path}/include/driver/include" "-I{compiler.sdk.path}/include/driver/esp32/include" "-I{compiler.sdk.path}/include/esp_pm/include" "-I{compiler.sdk.path}/include/esp_ringbuf/include" "-I{compiler.sdk.path}/include/efuse/include" "-I{compiler.sdk.path}/include/efuse/esp32/include" "-I{compiler.sdk.path}/include/vfs/include" "-I{compiler.sdk.path}/include/esp_wifi/include" "-I{compiler.sdk.path}/include/esp_event/include" "-I{compiler.sdk.path}/include/esp_netif/include" "-I{compiler.sdk.path}/include/esp_eth/include" "-I{compiler.sdk.path}/include/tcpip_adapter/include" "-I{compiler.sdk.path}/include/esp_phy/include" "-I{compiler.sdk.path}/include/esp_phy/esp32/include" "-I{compiler.sdk.path}/include/esp_ipc/include" "-I{compiler.sdk.path}/include/app_trace/include" "-I{compiler.sdk.path}/include/esp_timer/include" "-I{compiler.sdk.path}/include/mbedtls/port/include" "-I{compiler.sdk.path}/include/mbedtls/mbedtls/include" "-I{compiler.sdk.path}/include/mbedtls/esp_crt_bundle/include" "-I{compiler.sdk.path}/include/app_update/include" "-I{compiler.sdk.path}/include/spi_flash/include" "-I{compiler.sdk.path}/include/bootloader_support/include" "-I{compiler.sdk.path}/include/nvs_flash/include" "-I{compiler.sdk.path}/include/pthread/include" "-I{compiler.sdk.path}/include/esp_gdbstub/include" "-I{compiler.sdk.path}/include/esp_gdbstub/xtensa" "-I{compiler.sdk.path}/include/esp_gdbstub/esp32" "-I{compiler.sdk.path}/include/espcoredump/include" "-I{compiler.sdk.path}/include/espcoredump/include/port/xtensa" "-I{compiler.sdk.path}/include/wpa_supplicant/include" "-I{compiler.sdk.path}/include/wpa_supplicant/port/include" "-I{compiler.sdk.path}/include/wpa_supplicant/esp_supplicant/include" "-I{compiler.sdk.path}/include/ieee802154/include" "-I{compiler.sdk.path}/include/console" "-I{compiler.sdk.path}/include/asio/asio/asio/include" "-I{compiler.sdk.path}/include/asio/port/include" "-I{compiler.sdk.path}/include/bt/common/osi/include" "-I{compiler.sdk.path}/include/bt/include/esp32/include" "-I{compiler.sdk.path}/include/bt/common/api/include/api" "-I{compiler.sdk.path}/include/bt/common/btc/profile/esp/blufi/include" "-I{compiler.sdk.path}/include/bt/common/btc/profile/esp/include" "-I{compiler.sdk.path}/include/bt/host/bluedroid/api/include/api" "-I{compiler.sdk.path}/include/cbor/port/include" "-I{compiler.sdk.path}/include/unity/include" "-I{compiler.sdk.path}/include/unity/unity/src" "-I{compiler.sdk.path}/include/cmock/CMock/src" "-I{compiler.sdk.path}/include/coap/port/include" "-I{compiler.sdk.path}/include/coap/libcoap/include" "-I{compiler.sdk.path}/include/nghttp/port/include" "-I{compiler.sdk.path}/include/nghttp/nghttp2/lib/includes" "-I{compiler.sdk.path}/include/esp-tls" "-I{compiler.sdk.path}/include/esp-tls/esp-tls-crypto" "-I{compiler.sdk.path}/include/esp_adc_cal/include" "-I{compiler.sdk.path}/include/esp_hid/include" "-I{compiler.sdk.path}/include/tcp_transport/include" "-I{compiler.sdk.path}/include/esp_http_client/include" "-I{compiler.sdk.path}/include/esp_http_server/include" "-I{compiler.sdk.path}/include/esp_https_ota/include" "-I{compiler.sdk.path}/include/esp_lcd/include" "-I{compiler.sdk.path}/include/esp_lcd/interface" "-I{compiler.sdk.path}/include/protobuf-c/protobuf-c" "-I{compiler.sdk.path}/include/protocomm/include/common" "-I{compiler.sdk.path}/include/protocomm/include/security" "-I{compiler.sdk.path}/include/protocomm/include/transports" "-I{compiler.sdk.path}/include/mdns/include" "-I{compiler.sdk.path}/include/esp_local_ctrl/include" "-I{compiler.sdk.path}/include/sdmmc/include" "-I{compiler.sdk.path}/include/esp_serial_slave_link/include" "-I{compiler.sdk.path}/include/esp_websocket_client/include" "-I{compiler.sdk.path}/include/expat/expat/expat/lib" "-I{compiler.sdk.path}/include/expat/port/include" "-I{compiler.sdk.path}/include/wear_levelling/include" "-I{compiler.sdk.path}/include/fatfs/diskio" "-I{compiler.sdk.path}/include/fatfs/vfs" "-I{compiler.sdk.path}/include/fatfs/src" "-I{compiler.sdk.path}/include/freemodbus/common/include" "-I{compiler.sdk.path}/include/idf_test/include" "-I{compiler.sdk.path}/include/idf_test/include/esp32" "-I{compiler.sdk.path}/include/jsmn/include" "-I{compiler.sdk.path}/include/json/cJSON" "-I{compiler.sdk.path}/include/libsodium/libsodium/src/libsodium/include" "-I{compiler.sdk.path}/include/libsodium/port_include" "-I{compiler.sdk.path}/include/mqtt/esp-mqtt/include" "-I{compiler.sdk.path}/include/openssl/include" "-I{compiler.sdk.path}/include/perfmon/include" "-I{compiler.sdk.path}/include/spiffs/include" "-I{compiler.sdk.path}/include/ulp/include" "-I{compiler.sdk.path}/include/wifi_provisioning/include" "-I{compiler.sdk.path}/include/button/button/include" "-I{compiler.sdk.path}/include/rmaker_common/include" "-I{compiler.sdk.path}/include/json_parser/upstream/include" "-I{compiler.sdk.path}/include/json_parser/upstream" "-I{compiler.sdk.path}/include/json_generator/upstream" "-I{compiler.sdk.path}/include/esp_schedule/include" "-I{compiler.sdk.path}/include/esp_rainmaker/include" "-I{compiler.sdk.path}/include/qrcode/include" "-I{compiler.sdk.path}/include/ws2812_led" "-I{compiler.sdk.path}/include/esp-dsp/modules/dotprod/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/support/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/hann/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/blackman/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/blackman_harris/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/blackman_nuttall/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/nuttall/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/flat_top/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/iir/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/fir/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/add/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/sub/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/mul/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/addc/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/mulc/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/sqrt/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/matrix/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/fft/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/dct/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/conv/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/common/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/kalman/ekf/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/kalman/ekf_imu13states/include" "-I{compiler.sdk.path}/include/esp_littlefs/src" "-I{compiler.sdk.path}/include/esp_littlefs/include" "-I{compiler.sdk.path}/include/esp-dl/include" "-I{compiler.sdk.path}/include/esp-dl/include/tool" "-I{compiler.sdk.path}/include/esp-dl/include/typedef" "-I{compiler.sdk.path}/include/esp-dl/include/image" "-I{compiler.sdk.path}/include/esp-dl/include/math" "-I{compiler.sdk.path}/include/esp-dl/include/nn" "-I{compiler.sdk.path}/include/esp-dl/include/layer" "-I{compiler.sdk.path}/include/esp-dl/include/detect" "-I{compiler.sdk.path}/include/esp-dl/include/model_zoo" "-I{compiler.sdk.path}/include/esp-sr/esp-tts/esp_tts_chinese/include" "-I{compiler.sdk.path}/include/esp-sr/include/esp32" "-I{compiler.sdk.path}/include/esp32-camera/driver/include" "-I{compiler.sdk.path}/include/esp32-camera/conversions/include" "-I{compiler.sdk.path}/include/fb_gfx/include" +compiler.c.elf.libs.esp32=-lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lasio -lbt -lcbor -lunity -lcmock -lcoap -lnghttp -lesp-tls -lesp_adc_cal -lesp_hid -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lesp_lcd -lprotobuf-c -lprotocomm -lmdns -lesp_local_ctrl -lsdmmc -lesp_serial_slave_link -lesp_websocket_client -lexpat -lwear_levelling -lfatfs -lfreemodbus -ljsmn -ljson -llibsodium -lmqtt -lopenssl -lperfmon -lspiffs -lulp -lwifi_provisioning -lbutton -lrmaker_common -ljson_parser -ljson_generator -lesp_schedule -lesp_rainmaker -lqrcode -lws2812_led -lesp-dsp -lesp-sr -lesp32-camera -lesp_littlefs -lfb_gfx -lasio -lcbor -lcmock -lunity -lcoap -lesp_lcd -lesp_websocket_client -lexpat -lfreemodbus -ljsmn -llibsodium -lperfmon -lesp_adc_cal -lesp_hid -lfatfs -lwear_levelling -lopenssl -lesp_rainmaker -lesp_local_ctrl -lwifi_provisioning -lprotocomm -lbt -lbtdm_app -lprotobuf-c -lmdns -lrmaker_common -lmqtt -ljson_parser -ljson_generator -lesp_schedule -lqrcode -lcat_face_detect -lhuman_face_detect -lcolor_detect -lmfn -ldl -lwakenet -lmultinet -lesp_audio_processor -lesp_audio_front_end -lesp-sr -lwakenet -lmultinet -lesp_audio_processor -lesp_audio_front_end -ljson -lspiffs -ldl_lib -lc_speech_features -lhilexin_wn5 -lhilexin_wn5X2 -lhilexin_wn5X3 -lnihaoxiaozhi_wn5 -lnihaoxiaozhi_wn5X2 -lnihaoxiaozhi_wn5X3 -lnihaoxiaoxin_wn5X3 -lcustomized_word_wn5 -lmultinet2_ch -lesp_tts_chinese -lvoice_set_xiaole -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lphy -lrtc -lesp_phy -lphy -lrtc -lesp_phy -lphy -lrtc -lxt_hal -lm -lnewlib -lstdc++ -lpthread -lgcc -lcxx -lapp_trace -lgcov -lapp_trace -lgcov -lc compiler.c.flags.esp32=-mlongcalls -Wno-frame-address -ffunction-sections -fdata-sections -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -ggdb -Os -freorder-blocks -Wwrite-strings -fstack-protector -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -fno-jump-tables -fno-tree-switch-conversion -std=gnu99 -Wno-old-style-declaration -MMD -c compiler.cpp.flags.esp32=-mlongcalls -Wno-frame-address -ffunction-sections -fdata-sections -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -ggdb -Os -freorder-blocks -Wwrite-strings -fstack-protector -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -fno-jump-tables -fno-tree-switch-conversion -std=gnu++11 -fexceptions -fno-rtti -MMD -c compiler.S.flags.esp32=-ffunction-sections -fdata-sections -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -ggdb -Os -freorder-blocks -Wwrite-strings -fstack-protector -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -fno-jump-tables -fno-tree-switch-conversion -x assembler-with-cpp -MMD -c -compiler.c.elf.flags.esp32=-T esp32.rom.redefined.ld -T memory.ld -T sections.ld -T esp32.rom.ld -T esp32.rom.api.ld -T esp32.rom.libgcc.ld -T esp32.rom.newlib-data.ld -T esp32.rom.syscalls.ld -T esp32.peripherals.ld -mlongcalls -Wno-frame-address -Wl,--cref -Wl,--gc-sections -fno-rtti -fno-lto -u ld_include_hli_vectors_bt -u _Z5setupv -u _Z4loopv -u esp_app_desc -u pthread_include_pthread_impl -u pthread_include_pthread_cond_impl -u pthread_include_pthread_local_storage_impl -u pthread_include_pthread_rwlock_impl -u ld_include_highint_hdl -u start_app -u start_app_other_cores -u __ubsan_include -Wl,--wrap=longjmp -u __assert_func -u vfs_include_syscalls_impl -Wl,--undefined=uxTopUsedPriority -u app_main -u newlib_include_heap_impl -u newlib_include_syscalls_impl -u newlib_include_pthread_impl -u newlib_include_assert_impl -u __cxa_guard_dummy +compiler.c.elf.flags.esp32=-T esp32.rom.redefined.ld -T memory.ld -T sections.ld -T esp32.rom.ld -T esp32.rom.api.ld -T esp32.rom.libgcc.ld -T esp32.rom.newlib-data.ld -T esp32.rom.syscalls.ld -T esp32.peripherals.ld -mlongcalls -Wno-frame-address -Wl,--cref -Wl,--gc-sections -fno-rtti -fno-lto -u ld_include_hli_vectors_bt -u _Z5setupv -u _Z4loopv -u esp_app_desc -u pthread_include_pthread_impl -u pthread_include_pthread_cond_impl -u pthread_include_pthread_local_storage_impl -u pthread_include_pthread_rwlock_impl -u include_esp_phy_override -u ld_include_highint_hdl -u start_app -u start_app_other_cores -u __ubsan_include -Wl,--wrap=longjmp -u __assert_func -u vfs_include_syscalls_impl -Wl,--undefined=uxTopUsedPriority -u app_main -u newlib_include_heap_impl -u newlib_include_syscalls_impl -u newlib_include_pthread_impl -u newlib_include_assert_impl -u __cxa_guard_dummy compiler.ar.flags.esp32=cr build.extra_flags.esp32=-DARDUINO_USB_CDC_ON_BOOT=0 # # ESP32 Support End # +# +# ESP32S3 Support Start +# +compiler.cpreprocessor.flags.esp32s3=-DHAVE_CONFIG_H -DMBEDTLS_CONFIG_FILE="mbedtls/esp_config.h" -DUNITY_INCLUDE_CONFIG_H -DWITH_POSIX -D_GNU_SOURCE -DIDF_VER="v4.4.1-1-gb8050b365e" -DESP_PLATFORM -D_POSIX_READER_WRITER_LOCKS "-I{compiler.sdk.path}/include/config" "-I{compiler.sdk.path}/include/newlib/platform_include" "-I{compiler.sdk.path}/include/freertos/include" "-I{compiler.sdk.path}/include/freertos/include/esp_additions/freertos" "-I{compiler.sdk.path}/include/freertos/port/xtensa/include" "-I{compiler.sdk.path}/include/freertos/include/esp_additions" "-I{compiler.sdk.path}/include/esp_hw_support/include" "-I{compiler.sdk.path}/include/esp_hw_support/include/soc" "-I{compiler.sdk.path}/include/esp_hw_support/include/soc/esp32s3" "-I{compiler.sdk.path}/include/esp_hw_support/port/esp32s3" "-I{compiler.sdk.path}/include/esp_hw_support/port/esp32s3/private_include" "-I{compiler.sdk.path}/include/heap/include" "-I{compiler.sdk.path}/include/log/include" "-I{compiler.sdk.path}/include/lwip/include/apps" "-I{compiler.sdk.path}/include/lwip/include/apps/sntp" "-I{compiler.sdk.path}/include/lwip/lwip/src/include" "-I{compiler.sdk.path}/include/lwip/port/esp32/include" "-I{compiler.sdk.path}/include/lwip/port/esp32/include/arch" "-I{compiler.sdk.path}/include/soc/include" "-I{compiler.sdk.path}/include/soc/esp32s3" "-I{compiler.sdk.path}/include/soc/esp32s3/include" "-I{compiler.sdk.path}/include/hal/esp32s3/include" "-I{compiler.sdk.path}/include/hal/include" "-I{compiler.sdk.path}/include/hal/platform_port/include" "-I{compiler.sdk.path}/include/esp_rom/include" "-I{compiler.sdk.path}/include/esp_rom/include/esp32s3" "-I{compiler.sdk.path}/include/esp_rom/esp32s3" "-I{compiler.sdk.path}/include/esp_common/include" "-I{compiler.sdk.path}/include/esp_system/include" "-I{compiler.sdk.path}/include/esp_system/port/soc" "-I{compiler.sdk.path}/include/esp_system/port/public_compat" "-I{compiler.sdk.path}/include/xtensa/include" "-I{compiler.sdk.path}/include/xtensa/esp32s3/include" "-I{compiler.sdk.path}/include/driver/include" "-I{compiler.sdk.path}/include/driver/esp32s3/include" "-I{compiler.sdk.path}/include/esp_pm/include" "-I{compiler.sdk.path}/include/esp_ringbuf/include" "-I{compiler.sdk.path}/include/efuse/include" "-I{compiler.sdk.path}/include/efuse/esp32s3/include" "-I{compiler.sdk.path}/include/vfs/include" "-I{compiler.sdk.path}/include/esp_wifi/include" "-I{compiler.sdk.path}/include/esp_event/include" "-I{compiler.sdk.path}/include/esp_netif/include" "-I{compiler.sdk.path}/include/esp_eth/include" "-I{compiler.sdk.path}/include/tcpip_adapter/include" "-I{compiler.sdk.path}/include/esp_phy/include" "-I{compiler.sdk.path}/include/esp_phy/esp32s3/include" "-I{compiler.sdk.path}/include/esp_ipc/include" "-I{compiler.sdk.path}/include/app_trace/include" "-I{compiler.sdk.path}/include/esp_timer/include" "-I{compiler.sdk.path}/include/mbedtls/port/include" "-I{compiler.sdk.path}/include/mbedtls/mbedtls/include" "-I{compiler.sdk.path}/include/mbedtls/esp_crt_bundle/include" "-I{compiler.sdk.path}/include/app_update/include" "-I{compiler.sdk.path}/include/spi_flash/include" "-I{compiler.sdk.path}/include/bootloader_support/include" "-I{compiler.sdk.path}/include/nvs_flash/include" "-I{compiler.sdk.path}/include/pthread/include" "-I{compiler.sdk.path}/include/esp_gdbstub/include" "-I{compiler.sdk.path}/include/esp_gdbstub/xtensa" "-I{compiler.sdk.path}/include/esp_gdbstub/esp32s3" "-I{compiler.sdk.path}/include/espcoredump/include" "-I{compiler.sdk.path}/include/espcoredump/include/port/xtensa" "-I{compiler.sdk.path}/include/wpa_supplicant/include" "-I{compiler.sdk.path}/include/wpa_supplicant/port/include" "-I{compiler.sdk.path}/include/wpa_supplicant/esp_supplicant/include" "-I{compiler.sdk.path}/include/ieee802154/include" "-I{compiler.sdk.path}/include/console" "-I{compiler.sdk.path}/include/asio/asio/asio/include" "-I{compiler.sdk.path}/include/asio/port/include" "-I{compiler.sdk.path}/include/bt/common/osi/include" "-I{compiler.sdk.path}/include/bt/include/esp32s3/include" "-I{compiler.sdk.path}/include/bt/common/api/include/api" "-I{compiler.sdk.path}/include/bt/common/btc/profile/esp/blufi/include" "-I{compiler.sdk.path}/include/bt/common/btc/profile/esp/include" "-I{compiler.sdk.path}/include/bt/host/bluedroid/api/include/api" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/mesh_common/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/mesh_common/tinycrypt/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/mesh_core" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/mesh_core/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/mesh_core/storage" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/btc/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/mesh_models/common/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/mesh_models/client/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/mesh_models/server/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/api/core/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/api/models/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/api" "-I{compiler.sdk.path}/include/cbor/port/include" "-I{compiler.sdk.path}/include/unity/include" "-I{compiler.sdk.path}/include/unity/unity/src" "-I{compiler.sdk.path}/include/cmock/CMock/src" "-I{compiler.sdk.path}/include/coap/port/include" "-I{compiler.sdk.path}/include/coap/libcoap/include" "-I{compiler.sdk.path}/include/nghttp/port/include" "-I{compiler.sdk.path}/include/nghttp/nghttp2/lib/includes" "-I{compiler.sdk.path}/include/esp-tls" "-I{compiler.sdk.path}/include/esp-tls/esp-tls-crypto" "-I{compiler.sdk.path}/include/esp_adc_cal/include" "-I{compiler.sdk.path}/include/esp_hid/include" "-I{compiler.sdk.path}/include/tcp_transport/include" "-I{compiler.sdk.path}/include/esp_http_client/include" "-I{compiler.sdk.path}/include/esp_http_server/include" "-I{compiler.sdk.path}/include/esp_https_ota/include" "-I{compiler.sdk.path}/include/esp_https_server/include" "-I{compiler.sdk.path}/include/esp_lcd/include" "-I{compiler.sdk.path}/include/esp_lcd/interface" "-I{compiler.sdk.path}/include/protobuf-c/protobuf-c" "-I{compiler.sdk.path}/include/protocomm/include/common" "-I{compiler.sdk.path}/include/protocomm/include/security" "-I{compiler.sdk.path}/include/protocomm/include/transports" "-I{compiler.sdk.path}/include/mdns/include" "-I{compiler.sdk.path}/include/esp_local_ctrl/include" "-I{compiler.sdk.path}/include/sdmmc/include" "-I{compiler.sdk.path}/include/esp_serial_slave_link/include" "-I{compiler.sdk.path}/include/esp_websocket_client/include" "-I{compiler.sdk.path}/include/expat/expat/expat/lib" "-I{compiler.sdk.path}/include/expat/port/include" "-I{compiler.sdk.path}/include/wear_levelling/include" "-I{compiler.sdk.path}/include/fatfs/diskio" "-I{compiler.sdk.path}/include/fatfs/vfs" "-I{compiler.sdk.path}/include/fatfs/src" "-I{compiler.sdk.path}/include/freemodbus/common/include" "-I{compiler.sdk.path}/include/idf_test/include" "-I{compiler.sdk.path}/include/idf_test/include/esp32s3" "-I{compiler.sdk.path}/include/jsmn/include" "-I{compiler.sdk.path}/include/json/cJSON" "-I{compiler.sdk.path}/include/libsodium/libsodium/src/libsodium/include" "-I{compiler.sdk.path}/include/libsodium/port_include" "-I{compiler.sdk.path}/include/mqtt/esp-mqtt/include" "-I{compiler.sdk.path}/include/openssl/include" "-I{compiler.sdk.path}/include/perfmon/include" "-I{compiler.sdk.path}/include/spiffs/include" "-I{compiler.sdk.path}/include/usb/include" "-I{compiler.sdk.path}/include/ulp/include" "-I{compiler.sdk.path}/include/wifi_provisioning/include" "-I{compiler.sdk.path}/include/button/button/include" "-I{compiler.sdk.path}/include/rmaker_common/include" "-I{compiler.sdk.path}/include/json_parser/upstream/include" "-I{compiler.sdk.path}/include/json_parser/upstream" "-I{compiler.sdk.path}/include/json_generator/upstream" "-I{compiler.sdk.path}/include/esp_schedule/include" "-I{compiler.sdk.path}/include/esp_rainmaker/include" "-I{compiler.sdk.path}/include/qrcode/include" "-I{compiler.sdk.path}/include/ws2812_led" "-I{compiler.sdk.path}/include/esp-dsp/modules/dotprod/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/support/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/hann/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/blackman/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/blackman_harris/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/blackman_nuttall/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/nuttall/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/flat_top/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/iir/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/fir/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/add/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/sub/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/mul/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/addc/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/mulc/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/sqrt/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/matrix/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/fft/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/dct/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/conv/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/common/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/kalman/ekf/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/kalman/ekf_imu13states/include" "-I{compiler.sdk.path}/include/freertos/include/freertos" "-I{compiler.sdk.path}/include/arduino_tinyusb/tinyusb/src" "-I{compiler.sdk.path}/include/arduino_tinyusb/include" "-I{compiler.sdk.path}/include/esp_littlefs/src" "-I{compiler.sdk.path}/include/esp_littlefs/include" "-I{compiler.sdk.path}/include/esp-dl/include" "-I{compiler.sdk.path}/include/esp-dl/include/tool" "-I{compiler.sdk.path}/include/esp-dl/include/typedef" "-I{compiler.sdk.path}/include/esp-dl/include/image" "-I{compiler.sdk.path}/include/esp-dl/include/math" "-I{compiler.sdk.path}/include/esp-dl/include/nn" "-I{compiler.sdk.path}/include/esp-dl/include/layer" "-I{compiler.sdk.path}/include/esp-dl/include/detect" "-I{compiler.sdk.path}/include/esp-dl/include/model_zoo" "-I{compiler.sdk.path}/include/esp-sr/esp-tts/esp_tts_chinese/include" "-I{compiler.sdk.path}/include/esp-sr/include/esp32s3" "-I{compiler.sdk.path}/include/esp32-camera/driver/include" "-I{compiler.sdk.path}/include/esp32-camera/conversions/include" "-I{compiler.sdk.path}/include/fb_gfx/include" +compiler.c.elf.libs.esp32s3=-lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lasio -lbt -lcbor -lunity -lcmock -lcoap -lnghttp -lesp-tls -lesp_adc_cal -lesp_hid -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lesp_https_server -lesp_lcd -lprotobuf-c -lprotocomm -lmdns -lesp_local_ctrl -lsdmmc -lesp_serial_slave_link -lesp_websocket_client -lexpat -lwear_levelling -lfatfs -lfreemodbus -ljsmn -ljson -llibsodium -lmqtt -lopenssl -lperfmon -lspiffs -lusb -lulp -lwifi_provisioning -lbutton -lrmaker_common -ljson_parser -ljson_generator -lesp_schedule -lesp_rainmaker -lqrcode -lws2812_led -lesp-dsp -lesp-sr -lesp32-camera -lesp_littlefs -lfb_gfx -lasio -lcbor -lcmock -lunity -lcoap -lesp_lcd -lesp_websocket_client -lexpat -lfreemodbus -ljsmn -llibsodium -lperfmon -lusb -lesp_adc_cal -lesp_hid -lfatfs -lwear_levelling -lopenssl -lesp_rainmaker -lesp_local_ctrl -lesp_https_server -lwifi_provisioning -lprotocomm -lbt -lbtdm_app -lprotobuf-c -lmdns -lrmaker_common -lmqtt -ljson_parser -ljson_generator -lesp_schedule -lqrcode -larduino_tinyusb -lcat_face_detect -lhuman_face_detect -lcolor_detect -lmfn -ldl -lwakenet -lhufzip -lesp_audio_front_end -lesp_audio_processor -lmultinet -lesp-sr -lwakenet -lhufzip -lesp_audio_front_end -lesp_audio_processor -lmultinet -ljson -lspiffs -ldl_lib -lc_speech_features -lesp_tts_chinese -lvoice_set_xiaole -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lphy -lbtbb -lesp_phy -lphy -lbtbb -lesp_phy -lphy -lbtbb -lxt_hal -lm -lnewlib -lstdc++ -lpthread -lgcc -lcxx -lapp_trace -lgcov -lapp_trace -lgcov -lc +compiler.c.flags.esp32s3=-mlongcalls -ffunction-sections -fdata-sections -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -ggdb -Os -freorder-blocks -Wwrite-strings -fstack-protector -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -fno-jump-tables -fno-tree-switch-conversion -std=gnu99 -Wno-old-style-declaration -MMD -c +compiler.cpp.flags.esp32s3=-mlongcalls -ffunction-sections -fdata-sections -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -ggdb -Os -freorder-blocks -Wwrite-strings -fstack-protector -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -fno-jump-tables -fno-tree-switch-conversion -std=gnu++11 -fexceptions -fno-rtti -MMD -c +compiler.S.flags.esp32s3=-ffunction-sections -fdata-sections -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -ggdb -Os -freorder-blocks -Wwrite-strings -fstack-protector -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -fno-jump-tables -fno-tree-switch-conversion -x assembler-with-cpp -MMD -c +compiler.c.elf.flags.esp32s3=-T memory.ld -T sections.ld -T esp32s3.rom.ld -T esp32s3.rom.api.ld -T esp32s3.rom.libgcc.ld -T esp32s3.rom.newlib.ld -T esp32s3.rom.version.ld -T esp32s3.rom.newlib-time.ld -T esp32s3.peripherals.ld -mlongcalls -Wl,--cref -Wl,--gc-sections -fno-rtti -fno-lto -u _Z5setupv -u _Z4loopv -u esp_app_desc -u pthread_include_pthread_impl -u pthread_include_pthread_cond_impl -u pthread_include_pthread_local_storage_impl -u pthread_include_pthread_rwlock_impl -u include_esp_phy_override -u ld_include_highint_hdl -u start_app -u start_app_other_cores -u __ubsan_include -Wl,--wrap=longjmp -u __assert_func -u vfs_include_syscalls_impl -Wl,--undefined=uxTopUsedPriority -u app_main -u newlib_include_heap_impl -u newlib_include_syscalls_impl -u newlib_include_pthread_impl -u newlib_include_assert_impl -u __cxa_guard_dummy +compiler.ar.flags.esp32s3=cr +build.extra_flags.esp32s3=-DARDUINO_USB_MODE={build.usb_mode} -DARDUINO_USB_CDC_ON_BOOT={build.cdc_on_boot} -DARDUINO_USB_MSC_ON_BOOT={build.msc_on_boot} -DARDUINO_USB_DFU_ON_BOOT={build.dfu_on_boot} +# +# ESP32S3 Support End +# + # # ESP32S2 Support Start # -compiler.cpreprocessor.flags.esp32s2=-DHAVE_CONFIG_H -DMBEDTLS_CONFIG_FILE="mbedtls/esp_config.h" -DUNITY_INCLUDE_CONFIG_H -DWITH_POSIX -D_GNU_SOURCE -DIDF_VER="v4.4-beta1-189-ga79dc75f0a" -DESP_PLATFORM -D_POSIX_READER_WRITER_LOCKS "-I{compiler.sdk.path}/include/config" "-I{compiler.sdk.path}/include/newlib/platform_include" "-I{compiler.sdk.path}/include/freertos/include" "-I{compiler.sdk.path}/include/freertos/include/esp_additions/freertos" "-I{compiler.sdk.path}/include/freertos/port/xtensa/include" "-I{compiler.sdk.path}/include/freertos/include/esp_additions" "-I{compiler.sdk.path}/include/esp_hw_support/include" "-I{compiler.sdk.path}/include/esp_hw_support/include/soc" "-I{compiler.sdk.path}/include/esp_hw_support/include/soc/esp32s2" "-I{compiler.sdk.path}/include/esp_hw_support/port/esp32s2" "-I{compiler.sdk.path}/include/esp_hw_support/port/esp32s2/private_include" "-I{compiler.sdk.path}/include/heap/include" "-I{compiler.sdk.path}/include/log/include" "-I{compiler.sdk.path}/include/lwip/include/apps" "-I{compiler.sdk.path}/include/lwip/include/apps/sntp" "-I{compiler.sdk.path}/include/lwip/lwip/src/include" "-I{compiler.sdk.path}/include/lwip/port/esp32/include" "-I{compiler.sdk.path}/include/lwip/port/esp32/include/arch" "-I{compiler.sdk.path}/include/soc/include" "-I{compiler.sdk.path}/include/soc/esp32s2" "-I{compiler.sdk.path}/include/soc/esp32s2/include" "-I{compiler.sdk.path}/include/hal/esp32s2/include" "-I{compiler.sdk.path}/include/hal/include" "-I{compiler.sdk.path}/include/hal/platform_port/include" "-I{compiler.sdk.path}/include/esp_rom/include" "-I{compiler.sdk.path}/include/esp_rom/include/esp32s2" "-I{compiler.sdk.path}/include/esp_rom/esp32s2" "-I{compiler.sdk.path}/include/esp_common/include" "-I{compiler.sdk.path}/include/esp_system/include" "-I{compiler.sdk.path}/include/esp_system/port/soc" "-I{compiler.sdk.path}/include/esp_system/port/public_compat" "-I{compiler.sdk.path}/include/xtensa/include" "-I{compiler.sdk.path}/include/xtensa/esp32s2/include" "-I{compiler.sdk.path}/include/driver/include" "-I{compiler.sdk.path}/include/driver/esp32s2/include" "-I{compiler.sdk.path}/include/esp_pm/include" "-I{compiler.sdk.path}/include/esp_ringbuf/include" "-I{compiler.sdk.path}/include/efuse/include" "-I{compiler.sdk.path}/include/efuse/esp32s2/include" "-I{compiler.sdk.path}/include/vfs/include" "-I{compiler.sdk.path}/include/esp_wifi/include" "-I{compiler.sdk.path}/include/esp_event/include" "-I{compiler.sdk.path}/include/esp_netif/include" "-I{compiler.sdk.path}/include/esp_eth/include" "-I{compiler.sdk.path}/include/tcpip_adapter/include" "-I{compiler.sdk.path}/include/esp_phy/include" "-I{compiler.sdk.path}/include/esp_phy/esp32s2/include" "-I{compiler.sdk.path}/include/esp_ipc/include" "-I{compiler.sdk.path}/include/app_trace/include" "-I{compiler.sdk.path}/include/esp_timer/include" "-I{compiler.sdk.path}/include/mbedtls/port/include" "-I{compiler.sdk.path}/include/mbedtls/mbedtls/include" "-I{compiler.sdk.path}/include/mbedtls/esp_crt_bundle/include" "-I{compiler.sdk.path}/include/app_update/include" "-I{compiler.sdk.path}/include/spi_flash/include" "-I{compiler.sdk.path}/include/bootloader_support/include" "-I{compiler.sdk.path}/include/nvs_flash/include" "-I{compiler.sdk.path}/include/pthread/include" "-I{compiler.sdk.path}/include/esp_gdbstub/include" "-I{compiler.sdk.path}/include/esp_gdbstub/xtensa" "-I{compiler.sdk.path}/include/esp_gdbstub/esp32s2" "-I{compiler.sdk.path}/include/espcoredump/include" "-I{compiler.sdk.path}/include/espcoredump/include/port/xtensa" "-I{compiler.sdk.path}/include/wpa_supplicant/include" "-I{compiler.sdk.path}/include/wpa_supplicant/port/include" "-I{compiler.sdk.path}/include/wpa_supplicant/esp_supplicant/include" "-I{compiler.sdk.path}/include/ieee802154/include" "-I{compiler.sdk.path}/include/console" "-I{compiler.sdk.path}/include/asio/asio/asio/include" "-I{compiler.sdk.path}/include/asio/port/include" "-I{compiler.sdk.path}/include/cbor/port/include" "-I{compiler.sdk.path}/include/unity/include" "-I{compiler.sdk.path}/include/unity/unity/src" "-I{compiler.sdk.path}/include/cmock/CMock/src" "-I{compiler.sdk.path}/include/coap/port/include" "-I{compiler.sdk.path}/include/coap/libcoap/include" "-I{compiler.sdk.path}/include/nghttp/port/include" "-I{compiler.sdk.path}/include/nghttp/nghttp2/lib/includes" "-I{compiler.sdk.path}/include/esp-tls" "-I{compiler.sdk.path}/include/esp-tls/esp-tls-crypto" "-I{compiler.sdk.path}/include/esp_adc_cal/include" "-I{compiler.sdk.path}/include/esp_hid/include" "-I{compiler.sdk.path}/include/tcp_transport/include" "-I{compiler.sdk.path}/include/esp_http_client/include" "-I{compiler.sdk.path}/include/esp_http_server/include" "-I{compiler.sdk.path}/include/esp_https_ota/include" "-I{compiler.sdk.path}/include/esp_https_server/include" "-I{compiler.sdk.path}/include/esp_lcd/include" "-I{compiler.sdk.path}/include/esp_lcd/interface" "-I{compiler.sdk.path}/include/protobuf-c/protobuf-c" "-I{compiler.sdk.path}/include/protocomm/include/common" "-I{compiler.sdk.path}/include/protocomm/include/security" "-I{compiler.sdk.path}/include/protocomm/include/transports" "-I{compiler.sdk.path}/include/mdns/include" "-I{compiler.sdk.path}/include/esp_local_ctrl/include" "-I{compiler.sdk.path}/include/sdmmc/include" "-I{compiler.sdk.path}/include/esp_serial_slave_link/include" "-I{compiler.sdk.path}/include/esp_websocket_client/include" "-I{compiler.sdk.path}/include/expat/expat/expat/lib" "-I{compiler.sdk.path}/include/expat/port/include" "-I{compiler.sdk.path}/include/wear_levelling/include" "-I{compiler.sdk.path}/include/fatfs/diskio" "-I{compiler.sdk.path}/include/fatfs/vfs" "-I{compiler.sdk.path}/include/fatfs/src" "-I{compiler.sdk.path}/include/freemodbus/common/include" "-I{compiler.sdk.path}/include/idf_test/include" "-I{compiler.sdk.path}/include/idf_test/include/esp32s2" "-I{compiler.sdk.path}/include/jsmn/include" "-I{compiler.sdk.path}/include/json/cJSON" "-I{compiler.sdk.path}/include/libsodium/libsodium/src/libsodium/include" "-I{compiler.sdk.path}/include/libsodium/port_include" "-I{compiler.sdk.path}/include/mqtt/esp-mqtt/include" "-I{compiler.sdk.path}/include/openssl/include" "-I{compiler.sdk.path}/include/perfmon/include" "-I{compiler.sdk.path}/include/spiffs/include" "-I{compiler.sdk.path}/include/usb/include" "-I{compiler.sdk.path}/include/touch_element/include" "-I{compiler.sdk.path}/include/ulp/include" "-I{compiler.sdk.path}/include/wifi_provisioning/include" "-I{compiler.sdk.path}/include/freertos/include/freertos" "-I{compiler.sdk.path}/include/arduino_tinyusb/tinyusb/src" "-I{compiler.sdk.path}/include/arduino_tinyusb/include" "-I{compiler.sdk.path}/include/esp_littlefs/src" "-I{compiler.sdk.path}/include/esp_littlefs/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/dotprod/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/support/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/hann/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/blackman/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/blackman_harris/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/blackman_nuttall/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/nuttall/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/flat_top/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/iir/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/fir/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/add/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/sub/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/mul/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/addc/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/mulc/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/sqrt/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/matrix/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/fft/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/dct/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/conv/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/common/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/kalman/ekf/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/kalman/ekf_imu13states/include" "-I{compiler.sdk.path}/include/esp-face/include" "-I{compiler.sdk.path}/include/esp-face/include/tool" "-I{compiler.sdk.path}/include/esp-face/include/typedef" "-I{compiler.sdk.path}/include/esp-face/include/image" "-I{compiler.sdk.path}/include/esp-face/include/math" "-I{compiler.sdk.path}/include/esp-face/include/nn" "-I{compiler.sdk.path}/include/esp-face/include/layer" "-I{compiler.sdk.path}/include/esp-face/include/detect" "-I{compiler.sdk.path}/include/esp-face/include/model_zoo" "-I{compiler.sdk.path}/include/esp32-camera/driver/include" "-I{compiler.sdk.path}/include/esp32-camera/conversions/include" "-I{compiler.sdk.path}/include/fb_gfx/include" -compiler.c.elf.libs.esp32s2=-lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lasio -lcbor -lunity -lcmock -lcoap -lnghttp -lesp-tls -lesp_adc_cal -lesp_hid -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lesp_https_server -lesp_lcd -lprotobuf-c -lprotocomm -lmdns -lesp_local_ctrl -lsdmmc -lesp_serial_slave_link -lesp_websocket_client -lexpat -lwear_levelling -lfatfs -lfreemodbus -ljsmn -ljson -llibsodium -lmqtt -lopenssl -lperfmon -lspiffs -lusb -ltouch_element -lulp -lwifi_provisioning -lesp-dsp -lesp32-camera -lesp_littlefs -lfb_gfx -lasio -lcbor -lcmock -lunity -lcoap -lesp_lcd -lesp_local_ctrl -lesp_https_server -lesp_websocket_client -lexpat -lfreemodbus -ljsmn -llibsodium -lmqtt -lperfmon -lusb -ltouch_element -lesp_adc_cal -lesp_hid -lfatfs -lwear_levelling -lopenssl -lspiffs -lwifi_provisioning -lprotocomm -lprotobuf-c -lmdns -ljson -larduino_tinyusb -lcat_face_detect -lhuman_face_detect -lcolor_detect -lmfn -ldl -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lphy -lesp_phy -lphy -lesp_phy -lphy -lxt_hal -lm -lnewlib -lstdc++ -lpthread -lgcc -lcxx -lapp_trace -lgcov -lapp_trace -lgcov -lc +compiler.cpreprocessor.flags.esp32s2=-DHAVE_CONFIG_H -DMBEDTLS_CONFIG_FILE="mbedtls/esp_config.h" -DUNITY_INCLUDE_CONFIG_H -DWITH_POSIX -D_GNU_SOURCE -DIDF_VER="v4.4.1-1-gb8050b365e" -DESP_PLATFORM -D_POSIX_READER_WRITER_LOCKS "-I{compiler.sdk.path}/include/config" "-I{compiler.sdk.path}/include/newlib/platform_include" "-I{compiler.sdk.path}/include/freertos/include" "-I{compiler.sdk.path}/include/freertos/include/esp_additions/freertos" "-I{compiler.sdk.path}/include/freertos/port/xtensa/include" "-I{compiler.sdk.path}/include/freertos/include/esp_additions" "-I{compiler.sdk.path}/include/esp_hw_support/include" "-I{compiler.sdk.path}/include/esp_hw_support/include/soc" "-I{compiler.sdk.path}/include/esp_hw_support/include/soc/esp32s2" "-I{compiler.sdk.path}/include/esp_hw_support/port/esp32s2" "-I{compiler.sdk.path}/include/esp_hw_support/port/esp32s2/private_include" "-I{compiler.sdk.path}/include/heap/include" "-I{compiler.sdk.path}/include/log/include" "-I{compiler.sdk.path}/include/lwip/include/apps" "-I{compiler.sdk.path}/include/lwip/include/apps/sntp" "-I{compiler.sdk.path}/include/lwip/lwip/src/include" "-I{compiler.sdk.path}/include/lwip/port/esp32/include" "-I{compiler.sdk.path}/include/lwip/port/esp32/include/arch" "-I{compiler.sdk.path}/include/soc/include" "-I{compiler.sdk.path}/include/soc/esp32s2" "-I{compiler.sdk.path}/include/soc/esp32s2/include" "-I{compiler.sdk.path}/include/hal/esp32s2/include" "-I{compiler.sdk.path}/include/hal/include" "-I{compiler.sdk.path}/include/hal/platform_port/include" "-I{compiler.sdk.path}/include/esp_rom/include" "-I{compiler.sdk.path}/include/esp_rom/include/esp32s2" "-I{compiler.sdk.path}/include/esp_rom/esp32s2" "-I{compiler.sdk.path}/include/esp_common/include" "-I{compiler.sdk.path}/include/esp_system/include" "-I{compiler.sdk.path}/include/esp_system/port/soc" "-I{compiler.sdk.path}/include/esp_system/port/public_compat" "-I{compiler.sdk.path}/include/xtensa/include" "-I{compiler.sdk.path}/include/xtensa/esp32s2/include" "-I{compiler.sdk.path}/include/driver/include" "-I{compiler.sdk.path}/include/driver/esp32s2/include" "-I{compiler.sdk.path}/include/esp_pm/include" "-I{compiler.sdk.path}/include/esp_ringbuf/include" "-I{compiler.sdk.path}/include/efuse/include" "-I{compiler.sdk.path}/include/efuse/esp32s2/include" "-I{compiler.sdk.path}/include/vfs/include" "-I{compiler.sdk.path}/include/esp_wifi/include" "-I{compiler.sdk.path}/include/esp_event/include" "-I{compiler.sdk.path}/include/esp_netif/include" "-I{compiler.sdk.path}/include/esp_eth/include" "-I{compiler.sdk.path}/include/tcpip_adapter/include" "-I{compiler.sdk.path}/include/esp_phy/include" "-I{compiler.sdk.path}/include/esp_phy/esp32s2/include" "-I{compiler.sdk.path}/include/esp_ipc/include" "-I{compiler.sdk.path}/include/app_trace/include" "-I{compiler.sdk.path}/include/esp_timer/include" "-I{compiler.sdk.path}/include/mbedtls/port/include" "-I{compiler.sdk.path}/include/mbedtls/mbedtls/include" "-I{compiler.sdk.path}/include/mbedtls/esp_crt_bundle/include" "-I{compiler.sdk.path}/include/app_update/include" "-I{compiler.sdk.path}/include/spi_flash/include" "-I{compiler.sdk.path}/include/bootloader_support/include" "-I{compiler.sdk.path}/include/nvs_flash/include" "-I{compiler.sdk.path}/include/pthread/include" "-I{compiler.sdk.path}/include/esp_gdbstub/include" "-I{compiler.sdk.path}/include/esp_gdbstub/xtensa" "-I{compiler.sdk.path}/include/esp_gdbstub/esp32s2" "-I{compiler.sdk.path}/include/espcoredump/include" "-I{compiler.sdk.path}/include/espcoredump/include/port/xtensa" "-I{compiler.sdk.path}/include/wpa_supplicant/include" "-I{compiler.sdk.path}/include/wpa_supplicant/port/include" "-I{compiler.sdk.path}/include/wpa_supplicant/esp_supplicant/include" "-I{compiler.sdk.path}/include/ieee802154/include" "-I{compiler.sdk.path}/include/console" "-I{compiler.sdk.path}/include/asio/asio/asio/include" "-I{compiler.sdk.path}/include/asio/port/include" "-I{compiler.sdk.path}/include/cbor/port/include" "-I{compiler.sdk.path}/include/unity/include" "-I{compiler.sdk.path}/include/unity/unity/src" "-I{compiler.sdk.path}/include/cmock/CMock/src" "-I{compiler.sdk.path}/include/coap/port/include" "-I{compiler.sdk.path}/include/coap/libcoap/include" "-I{compiler.sdk.path}/include/nghttp/port/include" "-I{compiler.sdk.path}/include/nghttp/nghttp2/lib/includes" "-I{compiler.sdk.path}/include/esp-tls" "-I{compiler.sdk.path}/include/esp-tls/esp-tls-crypto" "-I{compiler.sdk.path}/include/esp_adc_cal/include" "-I{compiler.sdk.path}/include/esp_hid/include" "-I{compiler.sdk.path}/include/tcp_transport/include" "-I{compiler.sdk.path}/include/esp_http_client/include" "-I{compiler.sdk.path}/include/esp_http_server/include" "-I{compiler.sdk.path}/include/esp_https_ota/include" "-I{compiler.sdk.path}/include/esp_https_server/include" "-I{compiler.sdk.path}/include/esp_lcd/include" "-I{compiler.sdk.path}/include/esp_lcd/interface" "-I{compiler.sdk.path}/include/protobuf-c/protobuf-c" "-I{compiler.sdk.path}/include/protocomm/include/common" "-I{compiler.sdk.path}/include/protocomm/include/security" "-I{compiler.sdk.path}/include/protocomm/include/transports" "-I{compiler.sdk.path}/include/mdns/include" "-I{compiler.sdk.path}/include/esp_local_ctrl/include" "-I{compiler.sdk.path}/include/sdmmc/include" "-I{compiler.sdk.path}/include/esp_serial_slave_link/include" "-I{compiler.sdk.path}/include/esp_websocket_client/include" "-I{compiler.sdk.path}/include/expat/expat/expat/lib" "-I{compiler.sdk.path}/include/expat/port/include" "-I{compiler.sdk.path}/include/wear_levelling/include" "-I{compiler.sdk.path}/include/fatfs/diskio" "-I{compiler.sdk.path}/include/fatfs/vfs" "-I{compiler.sdk.path}/include/fatfs/src" "-I{compiler.sdk.path}/include/freemodbus/common/include" "-I{compiler.sdk.path}/include/idf_test/include" "-I{compiler.sdk.path}/include/idf_test/include/esp32s2" "-I{compiler.sdk.path}/include/jsmn/include" "-I{compiler.sdk.path}/include/json/cJSON" "-I{compiler.sdk.path}/include/libsodium/libsodium/src/libsodium/include" "-I{compiler.sdk.path}/include/libsodium/port_include" "-I{compiler.sdk.path}/include/mqtt/esp-mqtt/include" "-I{compiler.sdk.path}/include/openssl/include" "-I{compiler.sdk.path}/include/perfmon/include" "-I{compiler.sdk.path}/include/spiffs/include" "-I{compiler.sdk.path}/include/usb/include" "-I{compiler.sdk.path}/include/touch_element/include" "-I{compiler.sdk.path}/include/ulp/include" "-I{compiler.sdk.path}/include/wifi_provisioning/include" "-I{compiler.sdk.path}/include/button/button/include" "-I{compiler.sdk.path}/include/rmaker_common/include" "-I{compiler.sdk.path}/include/json_parser/upstream/include" "-I{compiler.sdk.path}/include/json_parser/upstream" "-I{compiler.sdk.path}/include/json_generator/upstream" "-I{compiler.sdk.path}/include/esp_schedule/include" "-I{compiler.sdk.path}/include/esp_rainmaker/include" "-I{compiler.sdk.path}/include/qrcode/include" "-I{compiler.sdk.path}/include/ws2812_led" "-I{compiler.sdk.path}/include/esp-dsp/modules/dotprod/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/support/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/hann/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/blackman/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/blackman_harris/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/blackman_nuttall/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/nuttall/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/flat_top/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/iir/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/fir/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/add/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/sub/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/mul/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/addc/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/mulc/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/sqrt/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/matrix/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/fft/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/dct/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/conv/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/common/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/kalman/ekf/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/kalman/ekf_imu13states/include" "-I{compiler.sdk.path}/include/freertos/include/freertos" "-I{compiler.sdk.path}/include/arduino_tinyusb/tinyusb/src" "-I{compiler.sdk.path}/include/arduino_tinyusb/include" "-I{compiler.sdk.path}/include/esp_littlefs/src" "-I{compiler.sdk.path}/include/esp_littlefs/include" "-I{compiler.sdk.path}/include/esp-dl/include" "-I{compiler.sdk.path}/include/esp-dl/include/tool" "-I{compiler.sdk.path}/include/esp-dl/include/typedef" "-I{compiler.sdk.path}/include/esp-dl/include/image" "-I{compiler.sdk.path}/include/esp-dl/include/math" "-I{compiler.sdk.path}/include/esp-dl/include/nn" "-I{compiler.sdk.path}/include/esp-dl/include/layer" "-I{compiler.sdk.path}/include/esp-dl/include/detect" "-I{compiler.sdk.path}/include/esp-dl/include/model_zoo" "-I{compiler.sdk.path}/include/esp-sr/esp-tts/esp_tts_chinese/include" "-I{compiler.sdk.path}/include/esp-sr/include/esp32" "-I{compiler.sdk.path}/include/esp32-camera/driver/include" "-I{compiler.sdk.path}/include/esp32-camera/conversions/include" "-I{compiler.sdk.path}/include/fb_gfx/include" +compiler.c.elf.libs.esp32s2=-lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lasio -lcbor -lunity -lcmock -lcoap -lnghttp -lesp-tls -lesp_adc_cal -lesp_hid -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lesp_https_server -lesp_lcd -lprotobuf-c -lprotocomm -lmdns -lesp_local_ctrl -lsdmmc -lesp_serial_slave_link -lesp_websocket_client -lexpat -lwear_levelling -lfatfs -lfreemodbus -ljsmn -ljson -llibsodium -lmqtt -lopenssl -lperfmon -lspiffs -lusb -ltouch_element -lulp -lwifi_provisioning -lbutton -lrmaker_common -ljson_parser -ljson_generator -lesp_schedule -lesp_rainmaker -lqrcode -lws2812_led -lesp-dsp -lesp-sr -lesp32-camera -lesp_littlefs -lfb_gfx -lasio -lcbor -lcmock -lunity -lcoap -lesp_lcd -lesp_websocket_client -lexpat -lfreemodbus -ljsmn -llibsodium -lperfmon -lusb -ltouch_element -lesp_adc_cal -lesp_hid -lfatfs -lwear_levelling -lopenssl -lesp_rainmaker -lesp_local_ctrl -lesp_https_server -lwifi_provisioning -lprotocomm -lprotobuf-c -lmdns -lrmaker_common -lmqtt -ljson_parser -ljson_generator -lesp_schedule -lqrcode -larduino_tinyusb -lcat_face_detect -lhuman_face_detect -lcolor_detect -lmfn -ldl -ljson -lspiffs -lesp_tts_chinese -lvoice_set_xiaole -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lphy -lesp_phy -lphy -lesp_phy -lphy -lxt_hal -lm -lnewlib -lstdc++ -lpthread -lgcc -lcxx -lapp_trace -lgcov -lapp_trace -lgcov -lc compiler.c.flags.esp32s2=-mlongcalls -ffunction-sections -fdata-sections -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -ggdb -Os -freorder-blocks -Wwrite-strings -fstack-protector -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -fno-jump-tables -fno-tree-switch-conversion -std=gnu99 -Wno-old-style-declaration -MMD -c compiler.cpp.flags.esp32s2=-mlongcalls -ffunction-sections -fdata-sections -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -ggdb -Os -freorder-blocks -Wwrite-strings -fstack-protector -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -fno-jump-tables -fno-tree-switch-conversion -std=gnu++11 -fexceptions -fno-rtti -MMD -c compiler.S.flags.esp32s2=-ffunction-sections -fdata-sections -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -ggdb -Os -freorder-blocks -Wwrite-strings -fstack-protector -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -fno-jump-tables -fno-tree-switch-conversion -x assembler-with-cpp -MMD -c -compiler.c.elf.flags.esp32s2=-T memory.ld -T sections.ld -T esp32s2.rom.ld -T esp32s2.rom.api.ld -T esp32s2.rom.libgcc.ld -T esp32s2.rom.newlib-funcs.ld -T esp32s2.rom.newlib-data.ld -T esp32s2.rom.spiflash.ld -T esp32s2.peripherals.ld -mlongcalls -Wl,--cref -Wl,--gc-sections -fno-rtti -fno-lto -u _Z5setupv -u _Z4loopv -u esp_app_desc -u pthread_include_pthread_impl -u pthread_include_pthread_cond_impl -u pthread_include_pthread_local_storage_impl -u pthread_include_pthread_rwlock_impl -u ld_include_highint_hdl -u start_app -u __ubsan_include -Wl,--wrap=longjmp -u __assert_func -u vfs_include_syscalls_impl -Wl,--undefined=uxTopUsedPriority -u app_main -u newlib_include_heap_impl -u newlib_include_syscalls_impl -u newlib_include_pthread_impl -u newlib_include_assert_impl -u __cxa_guard_dummy +compiler.c.elf.flags.esp32s2=-T memory.ld -T sections.ld -T esp32s2.rom.ld -T esp32s2.rom.api.ld -T esp32s2.rom.libgcc.ld -T esp32s2.rom.newlib-funcs.ld -T esp32s2.rom.newlib-data.ld -T esp32s2.rom.spiflash.ld -T esp32s2.rom.newlib-time.ld -T esp32s2.peripherals.ld -mlongcalls -Wl,--cref -Wl,--gc-sections -fno-rtti -fno-lto -u _Z5setupv -u _Z4loopv -u esp_app_desc -u pthread_include_pthread_impl -u pthread_include_pthread_cond_impl -u pthread_include_pthread_local_storage_impl -u pthread_include_pthread_rwlock_impl -u include_esp_phy_override -u ld_include_highint_hdl -u start_app -u __ubsan_include -Wl,--wrap=longjmp -u __assert_func -u vfs_include_syscalls_impl -Wl,--undefined=uxTopUsedPriority -u app_main -u newlib_include_heap_impl -u newlib_include_syscalls_impl -u newlib_include_pthread_impl -u newlib_include_assert_impl -u __cxa_guard_dummy compiler.ar.flags.esp32s2=cr -build.extra_flags.esp32s2=-DARDUINO_USB_CDC_ON_BOOT={build.cdc_on_boot} -DARDUINO_USB_MSC_ON_BOOT={build.msc_on_boot} -DARDUINO_USB_DFU_ON_BOOT={build.dfu_on_boot} +build.extra_flags.esp32s2=-DARDUINO_USB_MODE=0 -DARDUINO_USB_CDC_ON_BOOT={build.cdc_on_boot} -DARDUINO_USB_MSC_ON_BOOT={build.msc_on_boot} -DARDUINO_USB_DFU_ON_BOOT={build.dfu_on_boot} # # ESP32S2 Support End # @@ -53,20 +72,20 @@ build.extra_flags.esp32s2=-DARDUINO_USB_CDC_ON_BOOT={build.cdc_on_boot} -DARDUIN # # ESP32C3 Support Start # -compiler.cpreprocessor.flags.esp32c3=-DHAVE_CONFIG_H -DMBEDTLS_CONFIG_FILE="mbedtls/esp_config.h" -DUNITY_INCLUDE_CONFIG_H -DWITH_POSIX -D_GNU_SOURCE -DIDF_VER="v4.4-beta1-189-ga79dc75f0a" -DESP_PLATFORM -D_POSIX_READER_WRITER_LOCKS "-I{compiler.sdk.path}/include/config" "-I{compiler.sdk.path}/include/newlib/platform_include" "-I{compiler.sdk.path}/include/freertos/include" "-I{compiler.sdk.path}/include/freertos/include/esp_additions/freertos" "-I{compiler.sdk.path}/include/freertos/port/riscv/include" "-I{compiler.sdk.path}/include/freertos/include/esp_additions" "-I{compiler.sdk.path}/include/esp_hw_support/include" "-I{compiler.sdk.path}/include/esp_hw_support/include/soc" "-I{compiler.sdk.path}/include/esp_hw_support/include/soc/esp32c3" "-I{compiler.sdk.path}/include/esp_hw_support/port/esp32c3" "-I{compiler.sdk.path}/include/esp_hw_support/port/esp32c3/private_include" "-I{compiler.sdk.path}/include/heap/include" "-I{compiler.sdk.path}/include/log/include" "-I{compiler.sdk.path}/include/lwip/include/apps" "-I{compiler.sdk.path}/include/lwip/include/apps/sntp" "-I{compiler.sdk.path}/include/lwip/lwip/src/include" "-I{compiler.sdk.path}/include/lwip/port/esp32/include" "-I{compiler.sdk.path}/include/lwip/port/esp32/include/arch" "-I{compiler.sdk.path}/include/soc/include" "-I{compiler.sdk.path}/include/soc/esp32c3" "-I{compiler.sdk.path}/include/soc/esp32c3/include" "-I{compiler.sdk.path}/include/hal/esp32c3/include" "-I{compiler.sdk.path}/include/hal/include" "-I{compiler.sdk.path}/include/hal/platform_port/include" "-I{compiler.sdk.path}/include/esp_rom/include" "-I{compiler.sdk.path}/include/esp_rom/include/esp32c3" "-I{compiler.sdk.path}/include/esp_rom/esp32c3" "-I{compiler.sdk.path}/include/esp_common/include" "-I{compiler.sdk.path}/include/esp_system/include" "-I{compiler.sdk.path}/include/esp_system/port/soc" "-I{compiler.sdk.path}/include/esp_system/port/include/riscv" "-I{compiler.sdk.path}/include/esp_system/port/public_compat" "-I{compiler.sdk.path}/include/riscv/include" "-I{compiler.sdk.path}/include/driver/include" "-I{compiler.sdk.path}/include/driver/esp32c3/include" "-I{compiler.sdk.path}/include/esp_pm/include" "-I{compiler.sdk.path}/include/esp_ringbuf/include" "-I{compiler.sdk.path}/include/efuse/include" "-I{compiler.sdk.path}/include/efuse/esp32c3/include" "-I{compiler.sdk.path}/include/vfs/include" "-I{compiler.sdk.path}/include/esp_wifi/include" "-I{compiler.sdk.path}/include/esp_event/include" "-I{compiler.sdk.path}/include/esp_netif/include" "-I{compiler.sdk.path}/include/esp_eth/include" "-I{compiler.sdk.path}/include/tcpip_adapter/include" "-I{compiler.sdk.path}/include/esp_phy/include" "-I{compiler.sdk.path}/include/esp_phy/esp32c3/include" "-I{compiler.sdk.path}/include/esp_ipc/include" "-I{compiler.sdk.path}/include/app_trace/include" "-I{compiler.sdk.path}/include/esp_timer/include" "-I{compiler.sdk.path}/include/mbedtls/port/include" "-I{compiler.sdk.path}/include/mbedtls/mbedtls/include" "-I{compiler.sdk.path}/include/mbedtls/esp_crt_bundle/include" "-I{compiler.sdk.path}/include/app_update/include" "-I{compiler.sdk.path}/include/spi_flash/include" "-I{compiler.sdk.path}/include/bootloader_support/include" "-I{compiler.sdk.path}/include/nvs_flash/include" "-I{compiler.sdk.path}/include/pthread/include" "-I{compiler.sdk.path}/include/esp_gdbstub/include" "-I{compiler.sdk.path}/include/esp_gdbstub/riscv" "-I{compiler.sdk.path}/include/esp_gdbstub/esp32c3" "-I{compiler.sdk.path}/include/espcoredump/include" "-I{compiler.sdk.path}/include/espcoredump/include/port/riscv" "-I{compiler.sdk.path}/include/wpa_supplicant/include" "-I{compiler.sdk.path}/include/wpa_supplicant/port/include" "-I{compiler.sdk.path}/include/wpa_supplicant/esp_supplicant/include" "-I{compiler.sdk.path}/include/ieee802154/include" "-I{compiler.sdk.path}/include/console" "-I{compiler.sdk.path}/include/asio/asio/asio/include" "-I{compiler.sdk.path}/include/asio/port/include" "-I{compiler.sdk.path}/include/bt/common/osi/include" "-I{compiler.sdk.path}/include/bt/include/esp32c3/include" "-I{compiler.sdk.path}/include/bt/common/api/include/api" "-I{compiler.sdk.path}/include/bt/common/btc/profile/esp/blufi/include" "-I{compiler.sdk.path}/include/bt/common/btc/profile/esp/include" "-I{compiler.sdk.path}/include/bt/host/bluedroid/api/include/api" "-I{compiler.sdk.path}/include/cbor/port/include" "-I{compiler.sdk.path}/include/unity/include" "-I{compiler.sdk.path}/include/unity/unity/src" "-I{compiler.sdk.path}/include/cmock/CMock/src" "-I{compiler.sdk.path}/include/coap/port/include" "-I{compiler.sdk.path}/include/coap/libcoap/include" "-I{compiler.sdk.path}/include/nghttp/port/include" "-I{compiler.sdk.path}/include/nghttp/nghttp2/lib/includes" "-I{compiler.sdk.path}/include/esp-tls" "-I{compiler.sdk.path}/include/esp-tls/esp-tls-crypto" "-I{compiler.sdk.path}/include/esp_adc_cal/include" "-I{compiler.sdk.path}/include/esp_hid/include" "-I{compiler.sdk.path}/include/tcp_transport/include" "-I{compiler.sdk.path}/include/esp_http_client/include" "-I{compiler.sdk.path}/include/esp_http_server/include" "-I{compiler.sdk.path}/include/esp_https_ota/include" "-I{compiler.sdk.path}/include/esp_https_server/include" "-I{compiler.sdk.path}/include/esp_lcd/include" "-I{compiler.sdk.path}/include/esp_lcd/interface" "-I{compiler.sdk.path}/include/protobuf-c/protobuf-c" "-I{compiler.sdk.path}/include/protocomm/include/common" "-I{compiler.sdk.path}/include/protocomm/include/security" "-I{compiler.sdk.path}/include/protocomm/include/transports" "-I{compiler.sdk.path}/include/mdns/include" "-I{compiler.sdk.path}/include/esp_local_ctrl/include" "-I{compiler.sdk.path}/include/sdmmc/include" "-I{compiler.sdk.path}/include/esp_serial_slave_link/include" "-I{compiler.sdk.path}/include/esp_websocket_client/include" "-I{compiler.sdk.path}/include/expat/expat/expat/lib" "-I{compiler.sdk.path}/include/expat/port/include" "-I{compiler.sdk.path}/include/wear_levelling/include" "-I{compiler.sdk.path}/include/fatfs/diskio" "-I{compiler.sdk.path}/include/fatfs/vfs" "-I{compiler.sdk.path}/include/fatfs/src" "-I{compiler.sdk.path}/include/freemodbus/common/include" "-I{compiler.sdk.path}/include/idf_test/include" "-I{compiler.sdk.path}/include/idf_test/include/esp32c3" "-I{compiler.sdk.path}/include/jsmn/include" "-I{compiler.sdk.path}/include/json/cJSON" "-I{compiler.sdk.path}/include/libsodium/libsodium/src/libsodium/include" "-I{compiler.sdk.path}/include/libsodium/port_include" "-I{compiler.sdk.path}/include/mqtt/esp-mqtt/include" "-I{compiler.sdk.path}/include/openssl/include" "-I{compiler.sdk.path}/include/spiffs/include" "-I{compiler.sdk.path}/include/wifi_provisioning/include" "-I{compiler.sdk.path}/include/esp_littlefs/src" "-I{compiler.sdk.path}/include/esp_littlefs/include" "-I{compiler.sdk.path}/include/esp-face/include" "-I{compiler.sdk.path}/include/esp-face/include/tool" "-I{compiler.sdk.path}/include/esp-face/include/typedef" "-I{compiler.sdk.path}/include/esp-face/include/image" "-I{compiler.sdk.path}/include/esp-face/include/math" "-I{compiler.sdk.path}/include/esp-face/include/nn" "-I{compiler.sdk.path}/include/esp-face/include/layer" "-I{compiler.sdk.path}/include/esp-face/include/detect" "-I{compiler.sdk.path}/include/esp-face/include/model_zoo" "-I{compiler.sdk.path}/include/fb_gfx/include" -compiler.c.elf.libs.esp32c3=-lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lriscv -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lasio -lbt -lcbor -lunity -lcmock -lcoap -lnghttp -lesp-tls -lesp_adc_cal -lesp_hid -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lesp_https_server -lesp_lcd -lprotobuf-c -lprotocomm -lmdns -lesp_local_ctrl -lsdmmc -lesp_serial_slave_link -lesp_websocket_client -lexpat -lwear_levelling -lfatfs -lfreemodbus -ljsmn -ljson -llibsodium -lmqtt -lopenssl -lspiffs -lwifi_provisioning -lesp_littlefs -lfb_gfx -lasio -lcbor -lcmock -lunity -lcoap -lesp_lcd -lesp_local_ctrl -lesp_https_server -lesp_websocket_client -lexpat -lfreemodbus -ljsmn -llibsodium -lmqtt -lesp_adc_cal -lesp_hid -lfatfs -lwear_levelling -lopenssl -lspiffs -lwifi_provisioning -lprotocomm -lbt -lbtdm_app -lprotobuf-c -lmdns -ljson -lcat_face_detect -lhuman_face_detect -lcolor_detect -lmfn -ldl -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lriscv -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lriscv -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lriscv -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lriscv -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lriscv -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lriscv -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lphy -lbtbb -lesp_phy -lphy -lbtbb -lesp_phy -lphy -lbtbb -lm -lnewlib -lstdc++ -lpthread -lgcc -lcxx -lapp_trace -lgcov -lapp_trace -lgcov -lc -compiler.c.flags.esp32c3=-march=rv32imc -ffunction-sections -fdata-sections -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -ggdb -Wno-error=format= -nostartfiles -Wno-format -Os -freorder-blocks -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -fno-jump-tables -fno-tree-switch-conversion -std=gnu99 -Wno-old-style-declaration -MMD -c -compiler.cpp.flags.esp32c3=-march=rv32imc -ffunction-sections -fdata-sections -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -ggdb -Wno-error=format= -nostartfiles -Wno-format -Os -freorder-blocks -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -fno-jump-tables -fno-tree-switch-conversion -std=gnu++11 -fno-exceptions -fno-rtti -MMD -c -compiler.S.flags.esp32c3=-ffunction-sections -fdata-sections -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -ggdb -Wno-error=format= -nostartfiles -Wno-format -Os -freorder-blocks -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -fno-jump-tables -fno-tree-switch-conversion -x assembler-with-cpp -MMD -c -compiler.c.elf.flags.esp32c3=-T memory.ld -T sections.ld -T esp32c3.rom.ld -T esp32c3.rom.api.ld -T esp32c3.rom.libgcc.ld -T esp32c3.rom.newlib.ld -T esp32c3.rom.version.ld -T esp32c3.rom.eco3.ld -T esp32c3.peripherals.ld -nostartfiles -march=rv32imc --specs=nosys.specs -Wl,--cref -Wl,--gc-sections -fno-rtti -fno-lto -u _Z5setupv -u _Z4loopv -u esp_app_desc -u pthread_include_pthread_impl -u pthread_include_pthread_cond_impl -u pthread_include_pthread_local_storage_impl -u pthread_include_pthread_rwlock_impl -u start_app -u __ubsan_include -u __assert_func -u vfs_include_syscalls_impl -Wl,--undefined=uxTopUsedPriority -u app_main -u newlib_include_heap_impl -u newlib_include_syscalls_impl -u newlib_include_pthread_impl -u newlib_include_assert_impl -Wl,--wrap=_Unwind_SetEnableExceptionFdeSorting -Wl,--wrap=__register_frame_info_bases -Wl,--wrap=__register_frame_info -Wl,--wrap=__register_frame -Wl,--wrap=__register_frame_info_table_bases -Wl,--wrap=__register_frame_info_table -Wl,--wrap=__register_frame_table -Wl,--wrap=__deregister_frame_info_bases -Wl,--wrap=__deregister_frame_info -Wl,--wrap=_Unwind_Find_FDE -Wl,--wrap=_Unwind_GetGR -Wl,--wrap=_Unwind_GetCFA -Wl,--wrap=_Unwind_GetIP -Wl,--wrap=_Unwind_GetIPInfo -Wl,--wrap=_Unwind_GetRegionStart -Wl,--wrap=_Unwind_GetDataRelBase -Wl,--wrap=_Unwind_GetTextRelBase -Wl,--wrap=_Unwind_SetIP -Wl,--wrap=_Unwind_SetGR -Wl,--wrap=_Unwind_GetLanguageSpecificData -Wl,--wrap=_Unwind_FindEnclosingFunction -Wl,--wrap=_Unwind_Resume -Wl,--wrap=_Unwind_RaiseException -Wl,--wrap=_Unwind_DeleteException -Wl,--wrap=_Unwind_ForcedUnwind -Wl,--wrap=_Unwind_Resume_or_Rethrow -Wl,--wrap=_Unwind_Backtrace -Wl,--wrap=__cxa_call_unexpected -Wl,--wrap=__gxx_personality_v0 -u __cxa_guard_dummy -u __cxx_fatal_exception +compiler.cpreprocessor.flags.esp32c3=-DHAVE_CONFIG_H -DMBEDTLS_CONFIG_FILE="mbedtls/esp_config.h" -DUNITY_INCLUDE_CONFIG_H -DWITH_POSIX -D_GNU_SOURCE -DIDF_VER="v4.4.1-1-gb8050b365e" -DESP_PLATFORM -D_POSIX_READER_WRITER_LOCKS "-I{compiler.sdk.path}/include/config" "-I{compiler.sdk.path}/include/newlib/platform_include" "-I{compiler.sdk.path}/include/freertos/include" "-I{compiler.sdk.path}/include/freertos/include/esp_additions/freertos" "-I{compiler.sdk.path}/include/freertos/port/riscv/include" "-I{compiler.sdk.path}/include/freertos/include/esp_additions" "-I{compiler.sdk.path}/include/esp_hw_support/include" "-I{compiler.sdk.path}/include/esp_hw_support/include/soc" "-I{compiler.sdk.path}/include/esp_hw_support/include/soc/esp32c3" "-I{compiler.sdk.path}/include/esp_hw_support/port/esp32c3" "-I{compiler.sdk.path}/include/esp_hw_support/port/esp32c3/private_include" "-I{compiler.sdk.path}/include/heap/include" "-I{compiler.sdk.path}/include/log/include" "-I{compiler.sdk.path}/include/lwip/include/apps" "-I{compiler.sdk.path}/include/lwip/include/apps/sntp" "-I{compiler.sdk.path}/include/lwip/lwip/src/include" "-I{compiler.sdk.path}/include/lwip/port/esp32/include" "-I{compiler.sdk.path}/include/lwip/port/esp32/include/arch" "-I{compiler.sdk.path}/include/soc/include" "-I{compiler.sdk.path}/include/soc/esp32c3" "-I{compiler.sdk.path}/include/soc/esp32c3/include" "-I{compiler.sdk.path}/include/hal/esp32c3/include" "-I{compiler.sdk.path}/include/hal/include" "-I{compiler.sdk.path}/include/hal/platform_port/include" "-I{compiler.sdk.path}/include/esp_rom/include" "-I{compiler.sdk.path}/include/esp_rom/include/esp32c3" "-I{compiler.sdk.path}/include/esp_rom/esp32c3" "-I{compiler.sdk.path}/include/esp_common/include" "-I{compiler.sdk.path}/include/esp_system/include" "-I{compiler.sdk.path}/include/esp_system/port/soc" "-I{compiler.sdk.path}/include/esp_system/port/include/riscv" "-I{compiler.sdk.path}/include/esp_system/port/public_compat" "-I{compiler.sdk.path}/include/riscv/include" "-I{compiler.sdk.path}/include/driver/include" "-I{compiler.sdk.path}/include/driver/esp32c3/include" "-I{compiler.sdk.path}/include/esp_pm/include" "-I{compiler.sdk.path}/include/esp_ringbuf/include" "-I{compiler.sdk.path}/include/efuse/include" "-I{compiler.sdk.path}/include/efuse/esp32c3/include" "-I{compiler.sdk.path}/include/vfs/include" "-I{compiler.sdk.path}/include/esp_wifi/include" "-I{compiler.sdk.path}/include/esp_event/include" "-I{compiler.sdk.path}/include/esp_netif/include" "-I{compiler.sdk.path}/include/esp_eth/include" "-I{compiler.sdk.path}/include/tcpip_adapter/include" "-I{compiler.sdk.path}/include/esp_phy/include" "-I{compiler.sdk.path}/include/esp_phy/esp32c3/include" "-I{compiler.sdk.path}/include/esp_ipc/include" "-I{compiler.sdk.path}/include/app_trace/include" "-I{compiler.sdk.path}/include/esp_timer/include" "-I{compiler.sdk.path}/include/mbedtls/port/include" "-I{compiler.sdk.path}/include/mbedtls/mbedtls/include" "-I{compiler.sdk.path}/include/mbedtls/esp_crt_bundle/include" "-I{compiler.sdk.path}/include/app_update/include" "-I{compiler.sdk.path}/include/spi_flash/include" "-I{compiler.sdk.path}/include/bootloader_support/include" "-I{compiler.sdk.path}/include/nvs_flash/include" "-I{compiler.sdk.path}/include/pthread/include" "-I{compiler.sdk.path}/include/esp_gdbstub/include" "-I{compiler.sdk.path}/include/esp_gdbstub/riscv" "-I{compiler.sdk.path}/include/esp_gdbstub/esp32c3" "-I{compiler.sdk.path}/include/espcoredump/include" "-I{compiler.sdk.path}/include/espcoredump/include/port/riscv" "-I{compiler.sdk.path}/include/wpa_supplicant/include" "-I{compiler.sdk.path}/include/wpa_supplicant/port/include" "-I{compiler.sdk.path}/include/wpa_supplicant/esp_supplicant/include" "-I{compiler.sdk.path}/include/ieee802154/include" "-I{compiler.sdk.path}/include/console" "-I{compiler.sdk.path}/include/asio/asio/asio/include" "-I{compiler.sdk.path}/include/asio/port/include" "-I{compiler.sdk.path}/include/bt/common/osi/include" "-I{compiler.sdk.path}/include/bt/include/esp32c3/include" "-I{compiler.sdk.path}/include/bt/common/api/include/api" "-I{compiler.sdk.path}/include/bt/common/btc/profile/esp/blufi/include" "-I{compiler.sdk.path}/include/bt/common/btc/profile/esp/include" "-I{compiler.sdk.path}/include/bt/host/bluedroid/api/include/api" "-I{compiler.sdk.path}/include/cbor/port/include" "-I{compiler.sdk.path}/include/unity/include" "-I{compiler.sdk.path}/include/unity/unity/src" "-I{compiler.sdk.path}/include/cmock/CMock/src" "-I{compiler.sdk.path}/include/coap/port/include" "-I{compiler.sdk.path}/include/coap/libcoap/include" "-I{compiler.sdk.path}/include/nghttp/port/include" "-I{compiler.sdk.path}/include/nghttp/nghttp2/lib/includes" "-I{compiler.sdk.path}/include/esp-tls" "-I{compiler.sdk.path}/include/esp-tls/esp-tls-crypto" "-I{compiler.sdk.path}/include/esp_adc_cal/include" "-I{compiler.sdk.path}/include/esp_hid/include" "-I{compiler.sdk.path}/include/tcp_transport/include" "-I{compiler.sdk.path}/include/esp_http_client/include" "-I{compiler.sdk.path}/include/esp_http_server/include" "-I{compiler.sdk.path}/include/esp_https_ota/include" "-I{compiler.sdk.path}/include/esp_https_server/include" "-I{compiler.sdk.path}/include/esp_lcd/include" "-I{compiler.sdk.path}/include/esp_lcd/interface" "-I{compiler.sdk.path}/include/protobuf-c/protobuf-c" "-I{compiler.sdk.path}/include/protocomm/include/common" "-I{compiler.sdk.path}/include/protocomm/include/security" "-I{compiler.sdk.path}/include/protocomm/include/transports" "-I{compiler.sdk.path}/include/mdns/include" "-I{compiler.sdk.path}/include/esp_local_ctrl/include" "-I{compiler.sdk.path}/include/sdmmc/include" "-I{compiler.sdk.path}/include/esp_serial_slave_link/include" "-I{compiler.sdk.path}/include/esp_websocket_client/include" "-I{compiler.sdk.path}/include/expat/expat/expat/lib" "-I{compiler.sdk.path}/include/expat/port/include" "-I{compiler.sdk.path}/include/wear_levelling/include" "-I{compiler.sdk.path}/include/fatfs/diskio" "-I{compiler.sdk.path}/include/fatfs/vfs" "-I{compiler.sdk.path}/include/fatfs/src" "-I{compiler.sdk.path}/include/freemodbus/common/include" "-I{compiler.sdk.path}/include/idf_test/include" "-I{compiler.sdk.path}/include/idf_test/include/esp32c3" "-I{compiler.sdk.path}/include/jsmn/include" "-I{compiler.sdk.path}/include/json/cJSON" "-I{compiler.sdk.path}/include/libsodium/libsodium/src/libsodium/include" "-I{compiler.sdk.path}/include/libsodium/port_include" "-I{compiler.sdk.path}/include/mqtt/esp-mqtt/include" "-I{compiler.sdk.path}/include/openssl/include" "-I{compiler.sdk.path}/include/spiffs/include" "-I{compiler.sdk.path}/include/wifi_provisioning/include" "-I{compiler.sdk.path}/include/button/button/include" "-I{compiler.sdk.path}/include/rmaker_common/include" "-I{compiler.sdk.path}/include/json_parser/upstream/include" "-I{compiler.sdk.path}/include/json_parser/upstream" "-I{compiler.sdk.path}/include/json_generator/upstream" "-I{compiler.sdk.path}/include/esp_schedule/include" "-I{compiler.sdk.path}/include/esp_rainmaker/include" "-I{compiler.sdk.path}/include/qrcode/include" "-I{compiler.sdk.path}/include/ws2812_led" "-I{compiler.sdk.path}/include/esp-dsp/modules/dotprod/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/support/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/hann/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/blackman/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/blackman_harris/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/blackman_nuttall/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/nuttall/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/flat_top/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/iir/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/fir/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/add/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/sub/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/mul/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/addc/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/mulc/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/sqrt/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/matrix/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/fft/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/dct/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/conv/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/common/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/kalman/ekf/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/kalman/ekf_imu13states/include" "-I{compiler.sdk.path}/include/esp_littlefs/src" "-I{compiler.sdk.path}/include/esp_littlefs/include" "-I{compiler.sdk.path}/include/esp-dl/include" "-I{compiler.sdk.path}/include/esp-dl/include/tool" "-I{compiler.sdk.path}/include/esp-dl/include/typedef" "-I{compiler.sdk.path}/include/esp-dl/include/image" "-I{compiler.sdk.path}/include/esp-dl/include/math" "-I{compiler.sdk.path}/include/esp-dl/include/nn" "-I{compiler.sdk.path}/include/esp-dl/include/layer" "-I{compiler.sdk.path}/include/esp-dl/include/detect" "-I{compiler.sdk.path}/include/esp-dl/include/model_zoo" "-I{compiler.sdk.path}/include/fb_gfx/include" +compiler.c.elf.libs.esp32c3=-lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lriscv -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lasio -lbt -lcbor -lunity -lcmock -lcoap -lnghttp -lesp-tls -lesp_adc_cal -lesp_hid -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lesp_https_server -lesp_lcd -lprotobuf-c -lprotocomm -lmdns -lesp_local_ctrl -lsdmmc -lesp_serial_slave_link -lesp_websocket_client -lexpat -lwear_levelling -lfatfs -lfreemodbus -ljsmn -ljson -llibsodium -lmqtt -lopenssl -lspiffs -lwifi_provisioning -lbutton -lrmaker_common -ljson_parser -ljson_generator -lesp_schedule -lesp_rainmaker -lqrcode -lws2812_led -lesp-dsp -lesp_littlefs -lfb_gfx -lasio -lcbor -lcmock -lunity -lcoap -lesp_lcd -lesp_websocket_client -lexpat -lfreemodbus -ljsmn -llibsodium -lesp_adc_cal -lesp_hid -lfatfs -lwear_levelling -lopenssl -lspiffs -lesp_rainmaker -lesp_local_ctrl -lesp_https_server -lwifi_provisioning -lprotocomm -lbt -lbtdm_app -lprotobuf-c -lmdns -ljson -lrmaker_common -lmqtt -ljson_parser -ljson_generator -lesp_schedule -lqrcode -lcat_face_detect -lhuman_face_detect -lcolor_detect -lmfn -ldl -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lriscv -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lriscv -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lriscv -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lriscv -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lriscv -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lriscv -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lphy -lbtbb -lesp_phy -lphy -lbtbb -lesp_phy -lphy -lbtbb -lm -lnewlib -lstdc++ -lpthread -lgcc -lcxx -lapp_trace -lgcov -lapp_trace -lgcov -lc +compiler.c.flags.esp32c3=-march=rv32imc -ffunction-sections -fdata-sections -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -ggdb -Wno-error=format= -nostartfiles -Wno-format -Os -freorder-blocks -Wwrite-strings -fstack-protector -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -fno-jump-tables -fno-tree-switch-conversion -std=gnu99 -Wno-old-style-declaration -MMD -c +compiler.cpp.flags.esp32c3=-march=rv32imc -ffunction-sections -fdata-sections -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -ggdb -Wno-error=format= -nostartfiles -Wno-format -Os -freorder-blocks -Wwrite-strings -fstack-protector -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -fno-jump-tables -fno-tree-switch-conversion -std=gnu++11 -fexceptions -fno-rtti -MMD -c +compiler.S.flags.esp32c3=-ffunction-sections -fdata-sections -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -ggdb -Wno-error=format= -nostartfiles -Wno-format -Os -freorder-blocks -Wwrite-strings -fstack-protector -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -fno-jump-tables -fno-tree-switch-conversion -x assembler-with-cpp -MMD -c +compiler.c.elf.flags.esp32c3=-T memory.ld -T sections.ld -T esp32c3.rom.ld -T esp32c3.rom.api.ld -T esp32c3.rom.libgcc.ld -T esp32c3.rom.newlib.ld -T esp32c3.rom.version.ld -T esp32c3.rom.newlib-time.ld -T esp32c3.rom.eco3.ld -T esp32c3.peripherals.ld -nostartfiles -march=rv32imc --specs=nosys.specs -Wl,--cref -Wl,--gc-sections -fno-rtti -fno-lto -u _Z5setupv -u _Z4loopv -u esp_app_desc -u pthread_include_pthread_impl -u pthread_include_pthread_cond_impl -u pthread_include_pthread_local_storage_impl -u pthread_include_pthread_rwlock_impl -u include_esp_phy_override -u start_app -u __ubsan_include -u __assert_func -u vfs_include_syscalls_impl -Wl,--undefined=uxTopUsedPriority -u app_main -u newlib_include_heap_impl -u newlib_include_syscalls_impl -u newlib_include_pthread_impl -u newlib_include_assert_impl -u __cxa_guard_dummy compiler.ar.flags.esp32c3=cr -build.extra_flags.esp32c3=-DARDUINO_HW_CDC_ON_BOOT={build.cdc_on_boot} +build.extra_flags.esp32c3=-DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT={build.cdc_on_boot} # # ESP32C3 Support End # # Compile Flags -compiler.cpreprocessor.flags={compiler.cpreprocessor.flags.{build.mcu}} +compiler.cpreprocessor.flags={compiler.cpreprocessor.flags.{build.mcu}} "-I{compiler.sdk.path}/{build.memory_type}/include" compiler.c.flags={compiler.c.flags.{build.mcu}} compiler.cpp.flags={compiler.cpp.flags.{build.mcu}} compiler.S.flags={compiler.S.flags.{build.mcu}} @@ -101,15 +120,21 @@ compiler.elf2hex.extra_flags= compiler.libraries.ldflags= # This can be overriden in boards.txt +build.memory_type=qspi_qspi build.flash_size=4MB build.flash_mode=dio -build.boot=bootloader +build.flash_freq=80m +build.boot=qio +build.boot_freq={build.flash_freq} build.bootloader_addr=0x1000 +build.custom_bootloader=bootloader +build.custom_partitions=partitions build.code_debug=0 build.defines= build.loop_core= build.event_core= build.extra_flags=-DESP32 -DCORE_DEBUG_LEVEL={build.code_debug} {build.loop_core} {build.event_core} {build.defines} {build.extra_flags.{build.mcu}} +build.extra_libs= # Custom build options build.opt.name=build_opt.h @@ -117,16 +142,16 @@ build.opt.path={build.path}/{build.opt.name} # Check if custom partitions exist: source > variant > build.partitions recipe.hooks.prebuild.1.pattern=bash -c "[ ! -f "{build.source.path}"/partitions.csv ] || cp -f "{build.source.path}"/partitions.csv "{build.path}"/partitions.csv" -recipe.hooks.prebuild.2.pattern=bash -c "[ -f "{build.path}"/partitions.csv ] || [ ! -f "{build.variant.path}"/partitions.csv ] || cp "{build.variant.path}"/partitions.csv "{build.path}"/partitions.csv" +recipe.hooks.prebuild.2.pattern=bash -c "[ -f "{build.path}"/partitions.csv ] || [ ! -f "{build.variant.path}"/{build.custom_partitions}.csv ] || cp "{build.variant.path}"/{build.custom_partitions}.csv "{build.path}"/partitions.csv" recipe.hooks.prebuild.3.pattern=bash -c "[ -f "{build.path}"/partitions.csv ] || cp "{runtime.platform.path}"/tools/partitions/{build.partitions}.csv "{build.path}"/partitions.csv" recipe.hooks.prebuild.1.pattern.windows=cmd /c if exist "{build.source.path}\partitions.csv" COPY /y "{build.source.path}\partitions.csv" "{build.path}\partitions.csv" -recipe.hooks.prebuild.2.pattern.windows=cmd /c if not exist "{build.path}\partitions.csv" if exist "{build.variant.path}\partitions.csv" COPY "{build.variant.path}\partitions.csv" "{build.path}\partitions.csv" +recipe.hooks.prebuild.2.pattern.windows=cmd /c if not exist "{build.path}\partitions.csv" if exist "{build.variant.path}\{build.custom_partitions}.csv" COPY "{build.variant.path}\{build.custom_partitions}.csv" "{build.path}\partitions.csv" recipe.hooks.prebuild.3.pattern.windows=cmd /c if not exist "{build.path}\partitions.csv" COPY "{runtime.platform.path}\tools\partitions\{build.partitions}.csv" "{build.path}\partitions.csv" # Check if custom bootloader exist: source > variant > build.boot -recipe.hooks.prebuild.4.pattern=bash -c "[ -f "{build.source.path}"/bootloader.bin ] && cp -f "{build.source.path}"/bootloader.bin "{build.path}"/{build.project_name}.bootloader.bin || ( [ -f "{build.variant.path}"/bootloader.bin ] && cp "{build.variant.path}"/bootloader.bin "{build.path}"/{build.project_name}.bootloader.bin || cp -f "{runtime.platform.path}"/tools/sdk/{build.mcu}/bin/bootloader_{build.boot}_{build.flash_freq}.bin "{build.path}"/{build.project_name}.bootloader.bin )" -recipe.hooks.prebuild.4.pattern.windows=cmd /c IF EXIST "{build.source.path}\bootloader.bin" ( COPY /y "{build.source.path}\bootloader.bin" "{build.path}\{build.project_name}.bootloader.bin" ) ELSE ( IF EXIST "{build.variant.path}\bootloader.bin" ( COPY "{build.variant.path}\bootloader.bin" "{build.path}\{build.project_name}.bootloader.bin" ) ELSE ( COPY /y "{runtime.platform.path}\tools\sdk\{build.mcu}\bin\bootloader_{build.boot}_{build.flash_freq}.bin" "{build.path}\{build.project_name}.bootloader.bin" ) ) +recipe.hooks.prebuild.4.pattern=bash -c "[ -f "{build.source.path}"/bootloader.bin ] && cp -f "{build.source.path}"/bootloader.bin "{build.path}"/{build.project_name}.bootloader.bin || ( [ -f "{build.variant.path}"/{build.custom_bootloader}.bin ] && cp "{build.variant.path}"/{build.custom_bootloader}.bin "{build.path}"/{build.project_name}.bootloader.bin || cp -f "{runtime.platform.path}"/tools/sdk/{build.mcu}/bin/bootloader_{build.boot}_{build.boot_freq}.bin "{build.path}"/{build.project_name}.bootloader.bin )" +recipe.hooks.prebuild.4.pattern.windows=cmd /c IF EXIST "{build.source.path}\bootloader.bin" ( COPY /y "{build.source.path}\bootloader.bin" "{build.path}\{build.project_name}.bootloader.bin" ) ELSE ( IF EXIST "{build.variant.path}\{build.custom_bootloader}.bin" ( COPY "{build.variant.path}\{build.custom_bootloader}.bin" "{build.path}\{build.project_name}.bootloader.bin" ) ELSE ( COPY /y "{runtime.platform.path}\tools\sdk\{build.mcu}\bin\bootloader_{build.boot}_{build.boot_freq}.bin" "{build.path}\{build.project_name}.bootloader.bin" ) ) # Check if custom build options exist in the sketch folder recipe.hooks.prebuild.5.pattern=bash -c "[ ! -f "{build.source.path}"/build_opt.h ] || cp -f "{build.source.path}"/build_opt.h "{build.path}"/build_opt.h" @@ -148,7 +173,7 @@ recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.fla recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}" ## Combine gc-sections, archives, and objects -recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-Wl,--Map={build.path}/{build.project_name}.map" "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} {build.extra_flags} -Wl,--start-group {object_files} "{archive_file_path}" {compiler.c.elf.libs} {compiler.libraries.ldflags} -Wl,--end-group -Wl,-EL -o "{build.path}/{build.project_name}.elf" +recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-Wl,--Map={build.path}/{build.project_name}.map" "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" "-L{compiler.sdk.path}/{build.memory_type}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} {build.extra_flags} -Wl,--start-group {object_files} "{archive_file_path}" {build.extra_libs} {compiler.c.elf.libs} {compiler.libraries.ldflags} -Wl,--end-group -Wl,-EL -o "{build.path}/{build.project_name}.elf" ## Create partitions.bin recipe.objcopy.partitions.bin.pattern={tools.gen_esp32part.cmd} -q "{build.path}/partitions.csv" "{build.path}/{build.project_name}.partitions.bin" @@ -156,7 +181,7 @@ recipe.objcopy.partitions.bin.pattern={tools.gen_esp32part.cmd} -q "{build.path} ## Create bin recipe.objcopy.bin.pattern_args=--chip {build.mcu} elf2image --flash_mode "{build.flash_mode}" --flash_freq "{build.flash_freq}" --flash_size "{build.flash_size}" -o "{build.path}/{build.project_name}.bin" "{build.path}/{build.project_name}.elf" recipe.objcopy.bin.pattern="{tools.esptool_py.path}/{tools.esptool_py.cmd}" {recipe.objcopy.bin.pattern_args} -recipe.objcopy.bin.pattern.linux=python "{tools.esptool_py.path}/{tools.esptool_py.cmd}" {recipe.objcopy.bin.pattern_args} +recipe.objcopy.bin.pattern.linux=python3 "{tools.esptool_py.path}/{tools.esptool_py.cmd}" {recipe.objcopy.bin.pattern_args} ## Save bin recipe.output.tmp_file={build.project_name}.bin @@ -167,12 +192,65 @@ recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build recipe.size.regex=^(?:\.iram0\.text|\.iram0\.vectors|\.dram0\.data|\.flash\.text|\.flash\.rodata|)\s+([0-9]+).* recipe.size.regex.data=^(?:\.dram0\.data|\.dram0\.bss|\.noinit)\s+([0-9]+).* -# ------------------------------ +## Required discoveries and monitors +## --------------------------------- +pluggable_discovery.required.0=builtin:serial-discovery +pluggable_discovery.required.1=builtin:mdns-discovery +pluggable_monitor.required.serial=builtin:serial-monitor + +## ------------------ +## Upload/Debug tools +## ------------------ -tools.esptool_py.upload.protocol=esp32 +## +## ESPTool +## + +## Upload Sketch +## ------------- +tools.esptool_py.upload.protocol=serial tools.esptool_py.upload.params.verbose= tools.esptool_py.upload.params.quiet= -tools.esptool_py.upload.pattern_args=--chip {build.mcu} --port "{serial.port}" --baud {upload.speed} {upload.flags} --before default_reset --after hard_reset write_flash -z --flash_mode {build.flash_mode} --flash_freq {build.flash_freq} --flash_size {build.flash_size} 0xe000 "{runtime.platform.path}/tools/partitions/boot_app0.bin" {build.bootloader_addr} "{build.path}/{build.project_name}.bootloader.bin" 0x10000 "{build.path}/{build.project_name}.bin" 0x8000 "{build.path}/{build.project_name}.partitions.bin" {upload.extra_flags} +tools.esptool_py.upload.pattern_args=--chip {build.mcu} --port "{serial.port}" --baud {upload.speed} {upload.flags} --before default_reset --after hard_reset write_flash -z --flash_mode {build.flash_mode} --flash_freq {build.flash_freq} --flash_size {build.flash_size} {build.bootloader_addr} "{build.path}/{build.project_name}.bootloader.bin" 0x8000 "{build.path}/{build.project_name}.partitions.bin" 0xe000 "{runtime.platform.path}/tools/partitions/boot_app0.bin" 0x10000 "{build.path}/{build.project_name}.bin" {upload.extra_flags} tools.esptool_py.upload.pattern="{path}/{cmd}" {upload.pattern_args} -tools.esptool_py.upload.pattern.linux=python "{path}/{cmd}" {upload.pattern_args} +tools.esptool_py.upload.pattern.linux=python3 "{path}/{cmd}" {upload.pattern_args} + +## Program Application +## ------------------- +tools.esptool_py.program.params.verbose= +tools.esptool_py.program.params.quiet= +tools.esptool_py.program.pattern_args=--chip {build.mcu} --port "{serial.port}" --baud {upload.speed} {upload.flags} --before default_reset --after hard_reset write_flash -z --flash_mode {build.flash_mode} --flash_freq {build.flash_freq} --flash_size {build.flash_size} 0x10000 "{build.path}/{build.project_name}.bin" +tools.esptool_py.program.pattern="{path}/{cmd}" {program.pattern_args} +tools.esptool_py.program.pattern.linux=python3 "{path}/{cmd}" {program.pattern_args} + +## Erase Chip (before burning the bootloader) +## ------------------------------------------ +tools.esptool_py.erase.protocol=serial +tools.esptool_py.erase.params.verbose= +tools.esptool_py.erase.params.quiet= +tools.esptool_py.erase.pattern_args=--chip {build.mcu} --port "{serial.port}" --baud {upload.speed} {upload.flags} --before default_reset --after hard_reset erase_flash +tools.esptool_py.erase.pattern="{path}/{cmd}" {erase.pattern_args} +tools.esptool_py.erase.pattern.linux=python3 "{path}/{cmd}" {erase.pattern_args} + +## Burn Bootloader +## --------------- +tools.esptool_py.bootloader.protocol=serial +tools.esptool_py.bootloader.params.verbose= +tools.esptool_py.bootloader.params.quiet= +tools.esptool_py.bootloader.pattern= + +## Upload Sketch Through OTA (Arduino IDE 1.x) +## ------------------------------------------- +## The following rule is deprecated by pluggable discovery. +## We keep it to avoid breaking compatibility with the Arduino Java IDE. tools.esptool_py.upload.network_pattern={network_cmd} -i "{serial.port}" -p "{network.port}" "--auth={network.password}" -f "{build.path}/{build.project_name}.bin" + +## Upload Sketch Through OTA (Arduino IDE 2.x) +## ------------------------------------------- +tools.esp_ota.upload.protocol=network +## Following command does not work currently, because port properties are lost and auth dialog does not permit empty fields +#tools.esp_ota.upload.field.password=Password +#tools.esp_ota.upload.field.password.secret=true +#tools.esp_ota.upload.pattern={cmd} -i "{upload.port.address}" -p "{upload.port.properties.port}" "--auth={upload.field.password}" -f "{build.path}/{build.project_name}.bin" +## So we do basic default OTA on port 3232 and no auth +tools.esp_ota.upload.pattern={cmd} -i "{upload.port.address}" -f "{build.path}/{build.project_name}.bin" diff --git a/programmers.txt b/programmers.txt index e69de29bb2d..8148c185a52 100644 --- a/programmers.txt +++ b/programmers.txt @@ -0,0 +1,8 @@ +esptool.name=Esptool +esptool.communication=serial +esptool.protocol=serial +esptool.program.protocol=serial +esptool.program.tool=esptool_py +esptool.program.tool.default=esptool_py +esptool.program.extra_params= +esptool.extra_params= diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 00000000000..3d433392930 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,2 @@ +build/ +__pycache__/ diff --git a/tests/hello_world/hello_world.ino b/tests/hello_world/hello_world.ino new file mode 100644 index 00000000000..0cc110d42a5 --- /dev/null +++ b/tests/hello_world/hello_world.ino @@ -0,0 +1,12 @@ +void setup(){ + // Open serial communications and wait for port to open: + Serial.begin(115200); + while (!Serial) { + ; + } + + Serial.println("Hello Arduino!"); +} + +void loop(){ +} diff --git a/tests/hello_world/test_hello_world.py b/tests/hello_world/test_hello_world.py new file mode 100644 index 00000000000..f7ed50cde40 --- /dev/null +++ b/tests/hello_world/test_hello_world.py @@ -0,0 +1,2 @@ +def test_hello_world(dut): + dut.expect('Hello Arduino!') diff --git a/tests/pytest.ini b/tests/pytest.ini new file mode 100644 index 00000000000..ef7e6d7c5ae --- /dev/null +++ b/tests/pytest.ini @@ -0,0 +1,13 @@ +[pytest] +addopts = --embedded-services esp,arduino + +# log related +log_cli = True +log_cli_level = INFO +log_cli_format = %(asctime)s %(levelname)s %(message)s +log_cli_date_format = %Y-%m-%d %H:%M:%S + +log_file = test.log +log_file_level = INFO +log_file_format = %(asctime)s %(levelname)s %(message)s +log_file_date_format = %Y-%m-%d %H:%M:%S diff --git a/tests/requirements.txt b/tests/requirements.txt new file mode 100644 index 00000000000..c4095ef6c49 --- /dev/null +++ b/tests/requirements.txt @@ -0,0 +1,13 @@ +pyserial>=3.0 +esptool>=3.1 +pytest-cov +cryptography<3.4; platform_machine == "armv7l" + +pytest>=6.2.0 +pexpect>=4.4 + +pytest-embedded>=0.5.1 +pytest-embedded-serial>=0.5.1 +pytest-embedded-serial-esp>=0.5.1 +pytest-embedded-arduino>=0.5.1 + diff --git a/tests/unity/test_unity.py b/tests/unity/test_unity.py new file mode 100644 index 00000000000..a5a391cc5af --- /dev/null +++ b/tests/unity/test_unity.py @@ -0,0 +1,2 @@ +def test_unity(dut): + dut.expect_unity_test_output(timeout=240) diff --git a/tests/unity/unity.ino b/tests/unity/unity.ino new file mode 100644 index 00000000000..2a1c131ca74 --- /dev/null +++ b/tests/unity/unity.ino @@ -0,0 +1,33 @@ +#include + + +/* These functions are intended to be called before and after each test. */ +void setUp(void) { +} + +void tearDown(void){ +} + + +void test_pass(void){ + TEST_ASSERT_EQUAL(1, 1); +} + +void test_fail(void){ + TEST_ASSERT_EQUAL(1, 1); +} + +void setup() { + Serial.begin(115200); + while (!Serial) { + ; + } + + UNITY_BEGIN(); + RUN_TEST(test_pass); + RUN_TEST(test_fail); + UNITY_END(); +} + +void loop() { +} diff --git a/tools/esptool.py b/tools/esptool.py index 7b8a32fc8d3..beb06a3098d 100755 --- a/tools/esptool.py +++ b/tools/esptool.py @@ -1,20 +1,8 @@ #!/usr/bin/env python # -# ESP8266 & ESP32 family ROM Bootloader Utility -# Copyright (C) 2014-2021 Fredrik Ahlberg, Angus Gratton, Espressif Systems (Shanghai) CO LTD, other contributors as noted. -# https://github.com/espressif/esptool +# SPDX-FileCopyrightText: 2014-2022 Fredrik Ahlberg, Angus Gratton, Espressif Systems (Shanghai) CO LTD, other contributors as noted. # -# This program is free software; you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with -# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin -# Street, Fifth Floor, Boston, MA 02110-1301 USA. +# SPDX-License-Identifier: GPL-2.0-or-later from __future__ import division, print_function @@ -69,7 +57,7 @@ raise -__version__ = "3.2-dev" +__version__ = "3.3-dev" MAX_UINT32 = 0xffffffff MAX_UINT24 = 0xffffff @@ -86,6 +74,8 @@ DEFAULT_SERIAL_WRITE_TIMEOUT = 10 # timeout for serial port write DEFAULT_CONNECT_ATTEMPTS = 7 # default number of times to try connection +SUPPORTED_CHIPS = ['esp8266', 'esp32', 'esp32s2', 'esp32s3beta2', 'esp32s3', 'esp32c3', 'esp32c6beta', 'esp32h2beta1', 'esp32h2beta2', 'esp32c2'] + def timeout_per_mb(seconds_per_mb, size_bytes): """ Scales timeouts which are size-specific """ @@ -104,7 +94,9 @@ def _chip_to_rom_loader(chip): 'esp32s3': ESP32S3ROM, 'esp32c3': ESP32C3ROM, 'esp32c6beta': ESP32C6BETAROM, - 'esp32h2': ESP32H2ROM, + 'esp32h2beta1': ESP32H2BETA1ROM, + 'esp32h2beta2': ESP32H2BETA2ROM, + 'esp32c2': ESP32C2ROM, }[chip] @@ -132,7 +124,7 @@ def get_default_connected_device(serial_list, port, connect_attempts, initial_ba DETECTED_FLASH_SIZES = {0x12: '256KB', 0x13: '512KB', 0x14: '1MB', 0x15: '2MB', 0x16: '4MB', 0x17: '8MB', - 0x18: '16MB', 0x19: '32MB', 0x1a: '64MB'} + 0x18: '16MB', 0x19: '32MB', 0x1a: '64MB', 0x21: '128MB'} def check_supported_function(func, check_func): @@ -141,8 +133,8 @@ def check_supported_function(func, check_func): bootloader function to check if it's supported. This is used to capture the multidimensional differences in - functionality between the ESP8266 & ESP32/32S2/32S3/32C3 ROM loaders, and the - software stub that runs on both. Not possible to do this cleanly + functionality between the ESP8266 & ESP32 (and later chips) ROM loaders, and the + software stub that runs on these. Not possible to do this cleanly via inheritance alone. """ def inner(*args, **kwargs): @@ -154,18 +146,23 @@ def inner(*args, **kwargs): return inner +def esp8266_function_only(func): + """ Attribute for a function only supported on ESP8266 """ + return check_supported_function(func, lambda o: o.CHIP_NAME == "ESP8266") + + def stub_function_only(func): """ Attribute for a function only supported in the software stub loader """ return check_supported_function(func, lambda o: o.IS_STUB) def stub_and_esp32_function_only(func): - """ Attribute for a function only supported by software stubs or ESP32/32S2/32S3/32C3 ROM """ + """ Attribute for a function only supported by software stubs or ESP32 and later chips ROM """ return check_supported_function(func, lambda o: o.IS_STUB or isinstance(o, ESP32ROM)) def esp32s3_or_newer_function_only(func): - """ Attribute for a function only supported by ESP32S3/32C3 ROM """ + """ Attribute for a function only supported by ESP32S3 and later chips ROM """ return check_supported_function(func, lambda o: isinstance(o, ESP32S3ROM) or isinstance(o, ESP32C3ROM)) @@ -211,14 +208,9 @@ def _mask_to_shift(mask): return shift -def esp8266_function_only(func): - """ Attribute for a function only supported on ESP8266 """ - return check_supported_function(func, lambda o: o.CHIP_NAME == "ESP8266") - - class ESPLoader(object): """ Base class providing access to ESP ROM & software stub bootloaders. - Subclasses provide ESP8266 & ESP32 specific functionality. + Subclasses provide ESP8266 & ESP32 Family specific functionality. Don't instantiate this base class directly, either instantiate a subclass or call ESPLoader.detect_chip() which will interrogate the chip and return the @@ -232,6 +224,8 @@ class ESPLoader(object): DEFAULT_PORT = "/dev/ttyUSB0" + USES_RFC2217 = False + # Commands supported by ESP8266 ROM bootloader ESP_FLASH_BEGIN = 0x02 ESP_FLASH_DATA = 0x03 @@ -243,7 +237,7 @@ class ESPLoader(object): ESP_WRITE_REG = 0x09 ESP_READ_REG = 0x0a - # Some comands supported by ESP32 ROM bootloader (or -8266 w/ stub) + # Some comands supported by ESP32 and later chips ROM bootloader (or -8266 w/ stub) ESP_SPI_SET_PARAMS = 0x0B ESP_SPI_ATTACH = 0x0D ESP_READ_FLASH_SLOW = 0x0e # ROM only, much slower than the stub flash read @@ -253,7 +247,7 @@ class ESPLoader(object): ESP_FLASH_DEFL_END = 0x12 ESP_SPI_FLASH_MD5 = 0x13 - # Commands supported by ESP32-S2/S3/C3/C6 ROM bootloader only + # Commands supported by ESP32-S2 and later chips ROM bootloader only ESP_GET_SECURITY_INFO = 0x14 # Some commands supported by stub only @@ -367,6 +361,8 @@ def detect_chip(port=DEFAULT_PORT, baud=ESP_ROM_BAUD, connect_mode='default_rese """ inst = None detect_port = ESPLoader(port, baud, trace_enabled=trace_enabled) + if detect_port.serial_port.startswith("rfc2217:"): + detect_port.USES_RFC2217 = True detect_port.connect(connect_mode, connect_attempts, detecting=True) try: print('Detecting chip type...', end='') @@ -374,20 +370,27 @@ def detect_chip(port=DEFAULT_PORT, baud=ESP_ROM_BAUD, connect_mode='default_rese res = struct.unpack(" 0: self.write_reg(SPI_MISO_DLEN_REG, miso_bits - 1) + flags = 0 + if dummy_len > 0: + flags |= (dummy_len - 1) + if addr_len > 0: + flags |= (addr_len - 1) << SPI_USR_ADDR_LEN_SHIFT + if flags: + self.write_reg(SPI_USR1_REG, flags) else: - def set_data_lengths(mosi_bits, miso_bits): SPI_DATA_LEN_REG = SPI_USR1_REG SPI_MOSI_BITLEN_S = 17 SPI_MISO_BITLEN_S = 8 mosi_mask = 0 if (mosi_bits == 0) else (mosi_bits - 1) miso_mask = 0 if (miso_bits == 0) else (miso_bits - 1) - self.write_reg(SPI_DATA_LEN_REG, - (miso_mask << SPI_MISO_BITLEN_S) | ( - mosi_mask << SPI_MOSI_BITLEN_S)) + flags = (miso_mask << SPI_MISO_BITLEN_S) | (mosi_mask << SPI_MOSI_BITLEN_S) + if dummy_len > 0: + flags |= (dummy_len - 1) + if addr_len > 0: + flags |= (addr_len - 1) << SPI_USR_ADDR_LEN_SHIFT + self.write_reg(SPI_DATA_LEN_REG, flags) # SPI peripheral "command" bitmasks for SPI_CMD_REG SPI_CMD_USR = (1 << 18) # shift values SPI_USR2_COMMAND_LEN_SHIFT = 28 + SPI_USR_ADDR_LEN_SHIFT = 26 if read_bits > 32: raise FatalError("Reading more than 32 bits back from a SPI flash operation is unsupported") @@ -1106,10 +1127,16 @@ def set_data_lengths(mosi_bits, miso_bits): flags |= SPI_USR_MISO if data_bits > 0: flags |= SPI_USR_MOSI + if addr_len > 0: + flags |= SPI_USR_ADDR + if dummy_len > 0: + flags |= SPI_USR_DUMMY set_data_lengths(data_bits, read_bits) self.write_reg(SPI_USR_REG, flags) self.write_reg(SPI_USR2_REG, (7 << SPI_USR2_COMMAND_LEN_SHIFT) | spiflash_command) + if addr and addr_len > 0: + self.write_reg(SPI_ADDR_REG, addr) if data_bits == 0: self.write_reg(SPI_W0_REG, 0) # clear data register before we read it else: @@ -1134,6 +1161,10 @@ def wait_done(): self.write_reg(SPI_USR2_REG, old_spi_usr2) return status + def read_spiflash_sfdp(self, addr, read_bits): + CMD_RDSFDP = 0x5A + return self.run_spiflash_command(CMD_RDSFDP, read_bits=read_bits, addr=addr, addr_len=24, dummy_len=8) + def read_status(self, num_bytes=2): """Read up to 24 bits (num_bytes) of SPI flash status register contents via RDSR, RDSR2, RDSR3 commands @@ -1455,7 +1486,10 @@ class ESP32ROM(ESPLoader): '2MB': 0x10, '4MB': 0x20, '8MB': 0x30, - '16MB': 0x40 + '16MB': 0x40, + '32MB': 0x50, + '64MB': 0x60, + '128MB': 0x70 } BOOTLOADER_FLASH_OFFSET = 0x1000 @@ -2223,8 +2257,8 @@ def is_flash_encryption_key_valid(self): return any(p == self.PURPOSE_VAL_XTS_AES128_KEY for p in purposes) -class ESP32H2ROM(ESP32ROM): - CHIP_NAME = "ESP32-H2" +class ESP32H2BETA1ROM(ESP32ROM): + CHIP_NAME = "ESP32-H2(beta1)" IMAGE_CHIP_ID = 10 IROM_MAP_START = 0x42000000 @@ -2301,7 +2335,7 @@ def get_chip_features(self): return ["BLE/802.15.4"] def get_crystal_freq(self): - return 40 + return 32 def override_vddsdio(self, new_voltage): raise NotImplementedInROMError("VDD_SDIO overrides are not supported for ESP32-H2") @@ -2337,6 +2371,41 @@ def is_flash_encryption_key_valid(self): return any(p == self.PURPOSE_VAL_XTS_AES128_KEY for p in purposes) +class ESP32H2BETA2ROM(ESP32H2BETA1ROM): + CHIP_NAME = "ESP32-H2(beta2)" + IMAGE_CHIP_ID = 14 + + +class ESP32C2ROM(ESP32C3ROM): + CHIP_NAME = "ESP32-C2" + IMAGE_CHIP_ID = 12 + + IROM_MAP_START = 0x42000000 + IROM_MAP_END = 0x42400000 + DROM_MAP_START = 0x3c000000 + DROM_MAP_END = 0x3c400000 + + CHIP_DETECT_MAGIC_VALUE = [0x6f51306f] + + EFUSE_BASE = 0x60008800 + MAC_EFUSE_REG = EFUSE_BASE + 0x040 + + def get_pkg_version(self): + num_word = 3 + block1_addr = self.EFUSE_BASE + 0x044 + word3 = self.read_reg(block1_addr + (4 * num_word)) + pkg_version = (word3 >> 21) & 0x0F + return pkg_version + + def get_chip_description(self): + chip_name = { + 0: "ESP32-C2", + }.get(self.get_pkg_version(), "unknown ESP32-C2") + chip_revision = self.get_chip_revision() + + return "%s (revision %d)" % (chip_name, chip_revision) + + class ESP32C6BETAROM(ESP32C3ROM): CHIP_NAME = "ESP32-C6(beta)" IMAGE_CHIP_ID = 7 @@ -2459,8 +2528,8 @@ def __init__(self, rom_loader): ESP32C3ROM.STUB_CLASS = ESP32C3StubLoader -class ESP32H2StubLoader(ESP32H2ROM): - """ Access class for ESP32H2 stub loader, runs on top of ROM. +class ESP32H2BETA1StubLoader(ESP32H2BETA1ROM): + """ Access class for ESP32H2BETA1 stub loader, runs on top of ROM. (Basically the same as ESP32StubLoader, but different base class. Can possibly be made into a mixin.) @@ -2476,7 +2545,47 @@ def __init__(self, rom_loader): self.flush_input() # resets _slip_reader -ESP32H2ROM.STUB_CLASS = ESP32H2StubLoader +ESP32H2BETA1ROM.STUB_CLASS = ESP32H2BETA1StubLoader + + +class ESP32H2BETA2StubLoader(ESP32H2BETA2ROM): + """ Access class for ESP32H2BETA2 stub loader, runs on top of ROM. + + (Basically the same as ESP32StubLoader, but different base class. + Can possibly be made into a mixin.) + """ + FLASH_WRITE_SIZE = 0x4000 # matches MAX_WRITE_BLOCK in stub_loader.c + STATUS_BYTES_LENGTH = 2 # same as ESP8266, different to ESP32 ROM + IS_STUB = True + + def __init__(self, rom_loader): + self.secure_download_mode = rom_loader.secure_download_mode + self._port = rom_loader._port + self._trace_enabled = rom_loader._trace_enabled + self.flush_input() # resets _slip_reader + + +ESP32H2BETA2ROM.STUB_CLASS = ESP32H2BETA2StubLoader + + +class ESP32C2StubLoader(ESP32C2ROM): + """ Access class for ESP32C2 stub loader, runs on top of ROM. + + (Basically the same as ESP32StubLoader, but different base class. + Can possibly be made into a mixin.) + """ + FLASH_WRITE_SIZE = 0x4000 # matches MAX_WRITE_BLOCK in stub_loader.c + STATUS_BYTES_LENGTH = 2 # same as ESP8266, different to ESP32 ROM + IS_STUB = True + + def __init__(self, rom_loader): + self.secure_download_mode = rom_loader.secure_download_mode + self._port = rom_loader._port + self._trace_enabled = rom_loader._trace_enabled + self.flush_input() # resets _slip_reader + + +ESP32C2ROM.STUB_CLASS = ESP32C2StubLoader class ESPBOOTLOADER(object): @@ -2511,8 +2620,12 @@ def LoadFirmwareImage(chip, filename): return ESP32C3FirmwareImage(f) elif chip == 'esp32c6beta': return ESP32C6BETAFirmwareImage(f) - elif chip == 'esp32h2': - return ESP32H2FirmwareImage(f) + elif chip == 'esp32h2beta1': + return ESP32H2BETA1FirmwareImage(f) + elif chip == 'esp32h2beta2': + return ESP32H2BETA2FirmwareImage(f) + elif chip == 'esp32c2': + return ESP32C2FirmwareImage(f) else: # Otherwise, ESP8266 so look at magic to determine the image type magic = ord(f.read(1)) f.seek(0) @@ -2729,6 +2842,10 @@ def merge_adjacent_segments(self): # script will have produced any adjacent sections in linear order in the ELF, anyhow. self.segments = segments + def set_mmu_page_size(self, size): + """ If supported, this should be overridden by the chip-specific class. Gets called in elf2image. """ + print('WARNING: Changing MMU page size is not supported on {}! Defaulting to 64KB.'.format(self.ROM_LOADER.CHIP_NAME)) + class ESP8266ROMFirmwareImage(BaseFirmwareImage): """ 'Version 1' firmware image, segments loaded directly by the ROM bootloader. """ @@ -2862,11 +2979,6 @@ def save(self, filename): f.write(struct.pack(b' ESP8266ROM.IROM_MAP_START) + + def save(self, filename): + total_segments = 0 + with io.BytesIO() as f: # write file to memory first + self.write_common_header(f, self.segments) + + checksum = ESPLoader.ESP_CHECKSUM_MAGIC + + # split segments into flash-mapped vs ram-loaded, and take copies so we can mutate them + flash_segments = [copy.deepcopy(s) for s in sorted(self.segments, key=lambda s:s.addr) if self.is_flash_addr(s.addr) and len(s.data)] + ram_segments = [copy.deepcopy(s) for s in sorted(self.segments, key=lambda s:s.addr) if not self.is_flash_addr(s.addr) and len(s.data)] + + # check for multiple ELF sections that are mapped in the same flash mapping region. + # this is usually a sign of a broken linker script, but if you have a legitimate + # use case then let us know + if len(flash_segments) > 0: + last_addr = flash_segments[0].addr + for segment in flash_segments[1:]: + if segment.addr // self.IROM_ALIGN == last_addr // self.IROM_ALIGN: + raise FatalError(("Segment loaded at 0x%08x lands in same 64KB flash mapping as segment loaded at 0x%08x. " + "Can't generate binary. Suggest changing linker script or ELF to merge sections.") % + (segment.addr, last_addr)) + last_addr = segment.addr + + # try to fit each flash segment on a 64kB aligned boundary + # by padding with parts of the non-flash segments... + while len(flash_segments) > 0: + segment = flash_segments[0] + # remove 8 bytes empty data for insert segment header + if segment.name == '.flash.rodata': + segment.data = segment.data[8:] + # write the flash segment + checksum = self.save_segment(f, segment, checksum) + flash_segments.pop(0) + total_segments += 1 + + # flash segments all written, so write any remaining RAM segments + for segment in ram_segments: + checksum = self.save_segment(f, segment, checksum) + total_segments += 1 + + # done writing segments + self.append_checksum(f, checksum) + image_length = f.tell() + + # kinda hacky: go back to the initial header and write the new segment count + # that includes padding segments. This header is not checksummed + f.seek(1) + try: + f.write(chr(total_segments)) + except TypeError: # Python 3 + f.write(bytes([total_segments])) + + if self.append_digest: + # calculate the SHA256 of the whole file and append it + f.seek(0) + digest = hashlib.sha256() + digest.update(f.read(image_length)) + f.write(digest.digest()) + + with open(filename, 'wb') as real_file: + real_file.write(f.getvalue()) + + def load_extended_header(self, load_file): + def split_byte(n): + return (n & 0x0F, (n >> 4) & 0x0F) + + fields = list(struct.unpack(self.EXTENDED_HEADER_STRUCT_FMT, load_file.read(16))) + + self.wp_pin = fields[0] + + # SPI pin drive stengths are two per byte + self.clk_drv, self.q_drv = split_byte(fields[1]) + self.d_drv, self.cs_drv = split_byte(fields[2]) + self.hd_drv, self.wp_drv = split_byte(fields[3]) + + if fields[15] in [0, 1]: + self.append_digest = (fields[15] == 1) + else: + raise RuntimeError("Invalid value for append_digest field (0x%02x). Should be 0 or 1.", fields[15]) + + # remaining fields in the middle should all be zero + if any(f for f in fields[4:15] if f != 0): + print("Warning: some reserved header fields have non-zero values. This image may be from a newer esptool.py?") + + ESP32ROM.BOOTLOADER_IMAGE = ESP32FirmwareImage @@ -3161,17 +3367,42 @@ class ESP32C6BETAFirmwareImage(ESP32FirmwareImage): ESP32C6BETAROM.BOOTLOADER_IMAGE = ESP32C6BETAFirmwareImage -class ESP32H2FirmwareImage(ESP32FirmwareImage): +class ESP32H2BETA1FirmwareImage(ESP32FirmwareImage): + """ ESP32H2 Firmware Image almost exactly the same as ESP32FirmwareImage """ + ROM_LOADER = ESP32H2BETA1ROM + + +ESP32H2BETA1ROM.BOOTLOADER_IMAGE = ESP32H2BETA1FirmwareImage + + +class ESP32H2BETA2FirmwareImage(ESP32FirmwareImage): """ ESP32H2 Firmware Image almost exactly the same as ESP32FirmwareImage """ - ROM_LOADER = ESP32H2ROM + ROM_LOADER = ESP32H2BETA2ROM + + +ESP32H2BETA2ROM.BOOTLOADER_IMAGE = ESP32H2BETA2FirmwareImage + + +class ESP32C2FirmwareImage(ESP32FirmwareImage): + """ ESP32C2 Firmware Image almost exactly the same as ESP32FirmwareImage """ + ROM_LOADER = ESP32C2ROM + def set_mmu_page_size(self, size): + if size not in [16384, 32768, 65536]: + raise FatalError("{} is not a valid page size.".format(size)) + self.IROM_ALIGN = size -ESP32H2ROM.BOOTLOADER_IMAGE = ESP32H2FirmwareImage + +ESP32C2ROM.BOOTLOADER_IMAGE = ESP32C2FirmwareImage class ELFFile(object): SEC_TYPE_PROGBITS = 0x01 SEC_TYPE_STRTAB = 0x03 + SEC_TYPE_INITARRAY = 0x0e + SEC_TYPE_FINIARRAY = 0x0f + + PROG_SEC_TYPES = (SEC_TYPE_PROGBITS, SEC_TYPE_INITARRAY, SEC_TYPE_FINIARRAY) LEN_SEC_HEADER = 0x28 @@ -3228,7 +3459,7 @@ def read_section_header(offs): name_offs, sec_type, _flags, lma, sec_offs, size = struct.unpack_from("H", result[:2]) + message += " (result was {}: {})".format(hexify(result), err_defs.get(err_code[0], 'Unknown result')) return FatalError(message) @@ -3622,7 +3878,7 @@ def write_flash(esp, args): argfile.seek(0, os.SEEK_END) if address + argfile.tell() > flash_end: raise FatalError(("File %s (length %d) at offset %d will not fit in %d bytes of flash. " - "Use --flash-size argument, or change flashing address.") + "Use --flash_size argument, or change flashing address.") % (argfile.name, argfile.tell(), address, flash_end)) argfile.seek(0) @@ -3828,9 +4084,10 @@ def make_image(args): def elf2image(args): e = ELFFile(args.input) if args.chip == 'auto': # Default to ESP8266 for backwards compatibility - print("Creating image for ESP8266...") args.chip = 'esp8266' + print("Creating {} image...".format(args.chip)) + if args.chip == 'esp32': image = ESP32FirmwareImage() if args.secure_pad: @@ -3857,20 +4114,33 @@ def elf2image(args): image = ESP32C6BETAFirmwareImage() if args.secure_pad_v2: image.secure_pad = '2' - elif args.chip == 'esp32h2': - image = ESP32H2FirmwareImage() + elif args.chip == 'esp32h2beta1': + image = ESP32H2BETA1FirmwareImage() + if args.secure_pad_v2: + image.secure_pad = '2' + elif args.chip == 'esp32h2beta2': + image = ESP32H2BETA2FirmwareImage() + if args.secure_pad_v2: + image.secure_pad = '2' + elif args.chip == 'esp32c2': + image = ESP32C2FirmwareImage() if args.secure_pad_v2: image.secure_pad = '2' elif args.version == '1': # ESP8266 image = ESP8266ROMFirmwareImage() - else: + elif args.version == '2': image = ESP8266V2FirmwareImage() + else: + image = ESP8266V3FirmwareImage() image.entrypoint = e.entrypoint image.flash_mode = {'qio': 0, 'qout': 1, 'dio': 2, 'dout': 3}[args.flash_mode] if args.chip != 'esp8266': image.min_rev = int(args.min_rev) + if args.flash_mmu_page_size: + image.set_mmu_page_size(flash_size_bytes(args.flash_mmu_page_size)) + # ELFSection is a subclass of ImageSegment, so can use interchangeably image.segments = e.segments if args.use_segments else e.sections @@ -3893,6 +4163,8 @@ def elf2image(args): args.output = image.default_output_name(args.input) image.save(args.output) + print("Successfully created {} image.".format(args.chip)) + def read_mac(esp, args): mac = esp.read_mac() @@ -4020,7 +4292,12 @@ def get_security_info(esp, args): def merge_bin(args): - chip_class = _chip_to_rom_loader(args.chip) + try: + chip_class = _chip_to_rom_loader(args.chip) + except KeyError: + msg = "Please specify the chip argument" if args.chip == "auto" else "Invalid chip choice: '{}'".format(args.chip) + msg = msg + " (choose from {})".format(', '.join(SUPPORTED_CHIPS)) + raise FatalError(msg) # sort the files by offset. The AddrFilenamePairAction has already checked for overlap input_files = sorted(args.addr_filename, key=lambda x: x[0]) @@ -4068,12 +4345,12 @@ def main(argv=None, esp=None): external_esp = esp is not None - parser = argparse.ArgumentParser(description='esptool.py v%s - ESP8266 ROM Bootloader Utility' % __version__, prog='esptool') + parser = argparse.ArgumentParser(description='esptool.py v%s - Espressif chips ROM Bootloader Utility' % __version__, prog='esptool') parser.add_argument('--chip', '-c', help='Target chip type', - type=lambda c: c.lower().replace('-', ''), # support ESP32-S2, etc. - choices=['auto', 'esp8266', 'esp32', 'esp32s2', 'esp32s3beta2', 'esp32s3', 'esp32c3', 'esp32c6beta', 'esp32h2'], + type=format_chip_name, # support ESP32-S2, etc. + choices=['auto'] + SUPPORTED_CHIPS, default=os.environ.get('ESPTOOL_CHIP', 'auto')) parser.add_argument( @@ -4174,7 +4451,7 @@ def add_spi_flash_subparsers(parent, allow_keep, auto_detect): parent.add_argument('--flash_mode', '-fm', help='SPI Flash mode', choices=extra_keep_args + ['qio', 'qout', 'dio', 'dout'], default=os.environ.get('ESPTOOL_FM', 'keep' if allow_keep else 'qio')) - parent.add_argument('--flash_size', '-fs', help='SPI Flash size in MegaBytes (1MB, 2MB, 4MB, 8MB, 16M)' + parent.add_argument('--flash_size', '-fs', help='SPI Flash size in MegaBytes (1MB, 2MB, 4MB, 8MB, 16MB, 32MB, 64MB, 128MB)' ' plus ESP8266-only (256KB, 512KB, 2MB-c1, 4MB-c1)' + extra_fs_message, action=FlashSizeAction, auto_detect=auto_detect, default=os.environ.get('ESPTOOL_FS', 'keep' if allow_keep else '1MB')) @@ -4231,7 +4508,7 @@ def add_spi_flash_subparsers(parent, allow_keep, auto_detect): help='Create an application image from ELF file') parser_elf2image.add_argument('input', help='Input ELF file') parser_elf2image.add_argument('--output', '-o', help='Output filename prefix (for version 1 image), or filename (for version 2 single image)', type=str) - parser_elf2image.add_argument('--version', '-e', help='Output image version', choices=['1', '2'], default='1') + parser_elf2image.add_argument('--version', '-e', help='Output image version', choices=['1', '2', '3'], default='1') parser_elf2image.add_argument('--min-rev', '-r', help='Minimum chip revision', choices=['0', '1', '2', '3'], default='0') parser_elf2image.add_argument('--secure-pad', action='store_true', help='Pad image so once signed it will end on a 64KB boundary. For Secure Boot v1 images only.') @@ -4242,6 +4519,7 @@ def add_spi_flash_subparsers(parent, allow_keep, auto_detect): type=arg_auto_int, default=None) parser_elf2image.add_argument('--use_segments', help='If set, ELF segments will be used instead of ELF sections to genereate the image.', action='store_true') + parser_elf2image.add_argument('--flash-mmu-page-size', help="Change flash MMU page size.", choices=['64KB', '32KB', '16KB']) add_spi_flash_subparsers(parser_elf2image, allow_keep=False, auto_detect=False) @@ -4320,11 +4598,10 @@ def add_spi_flash_subparsers(parent, allow_keep, auto_detect): help='Address followed by binary filename, separated by space', action=AddrFilenamePairAction) - subparsers.add_parser( - 'version', help='Print esptool version') - subparsers.add_parser('get_security_info', help='Get some security-related data') + subparsers.add_parser('version', help='Print esptool version') + # internal sanity check - every operation matches a module function of the same name for operation in subparsers.choices.keys(): assert operation in globals(), "%s should be a module function" % operation @@ -4412,11 +4689,84 @@ def add_spi_flash_subparsers(parent, allow_keep, auto_detect): # ROM loader doesn't enable flash unless we explicitly do it esp.flash_spi_attach(0) + # XMC chip startup sequence + XMC_VENDOR_ID = 0x20 + + def is_xmc_chip_strict(): + id = esp.flash_id() + rdid = ((id & 0xff) << 16) | ((id >> 16) & 0xff) | (id & 0xff00) + + vendor_id = ((rdid >> 16) & 0xFF) + mfid = ((rdid >> 8) & 0xFF) + cpid = (rdid & 0xFF) + + if vendor_id != XMC_VENDOR_ID: + return False + + matched = False + if mfid == 0x40: + if cpid >= 0x13 and cpid <= 0x20: + matched = True + elif mfid == 0x41: + if cpid >= 0x17 and cpid <= 0x20: + matched = True + elif mfid == 0x50: + if cpid >= 0x15 and cpid <= 0x16: + matched = True + return matched + + def flash_xmc_startup(): + # If the RDID value is a valid XMC one, may skip the flow + fast_check = True + if fast_check and is_xmc_chip_strict(): + return # Successful XMC flash chip boot-up detected by RDID, skipping. + + sfdp_mfid_addr = 0x10 + mf_id = esp.read_spiflash_sfdp(sfdp_mfid_addr, 8) + if mf_id != XMC_VENDOR_ID: # Non-XMC chip detected by SFDP Read, skipping. + return + + print("WARNING: XMC flash chip boot-up failure detected! Running XMC25QHxxC startup flow") + esp.run_spiflash_command(0xB9) # Enter DPD + esp.run_spiflash_command(0x79) # Enter UDPD + esp.run_spiflash_command(0xFF) # Exit UDPD + time.sleep(0.002) # Delay tXUDPD + esp.run_spiflash_command(0xAB) # Release Power-Down + time.sleep(0.00002) + # Check for success + if not is_xmc_chip_strict(): + print("WARNING: XMC flash boot-up fix failed.") + print("XMC flash chip boot-up fix successful!") + + # Check flash chip connection + if not esp.secure_download_mode: + try: + flash_id = esp.flash_id() + if flash_id in (0xffffff, 0x000000): + print('WARNING: Failed to communicate with the flash chip, read/write operations will fail. ' + 'Try checking the chip connections or removing any other hardware connected to IOs.') + except Exception as e: + esp.trace('Unable to verify flash chip connection ({}).'.format(e)) + + # Check if XMC SPI flash chip booted-up successfully, fix if not + if not esp.secure_download_mode: + try: + flash_xmc_startup() + except Exception as e: + esp.trace('Unable to perform XMC flash chip startup sequence ({}).'.format(e)) + if hasattr(args, "flash_size"): print("Configuring flash size...") detect_flash_size(esp, args) if args.flash_size != 'keep': # TODO: should set this even with 'keep' esp.flash_set_parameters(flash_size_bytes(args.flash_size)) + # Check if stub supports chosen flash size + if esp.IS_STUB and args.flash_size in ('32MB', '64MB', '128MB'): + print("WARNING: Flasher stub doesn't fully support flash size larger than 16MB, in case of failure use --no-stub.") + + if esp.IS_STUB and hasattr(args, "address") and hasattr(args, "size"): + if args.address + args.size > 0x1000000: + print("WARNING: Flasher stub doesn't fully support flash size larger than 16MB, in case of failure use --no-stub.") try: operation_func(esp, args) @@ -4814,107 +5164,174 @@ def __call__(self, parser, namespace, values, option_string=None): """))) ESP32C3ROM.STUB_CODE = eval(zlib.decompress(base64.b64decode(b""" eNqVWmt7EzcW/itpEkjhaXcley4aaINNbZwLsNCHkg1rtsxoZlJomy3BLGG3+e+r91xGYwcb9kNiW9LoHJ3re47mv3uL5nKxd2er2hvPL63dnl/65Gb4N5hfmix8hr8qz8OP5BXmZ/PL2oXhKk9krMon4be7N5+P\ -5peFnV+6ij+b8FQ1GG2H6WIwCbsbTIZ9nQnfXVjthvPLkvYOf2HQDt/PL9s0/Gh5ZREm6xQ0+Glr5Tv+zKsjEA7fsE0RnqBRMF8+Buc/4ixyjAYH8/I0kQust/VpfsTMX3rzEAwswmhCDFyEEwSe2sGomuwEAm6X\ -eagGh4GpweT+4XZ41qRlPJSTQ+3Nz9ce6CqMBgJN4NkW4UsbZnxgvmrz8Bz4+vM4rKtZjni2bfN8zYSSHrNoVGF1ndNJeT8wn4nMBp3woIKwHXQ5xOcPV8KLOyG1gflppGPCpyuWlLhKtLh3JaSZwqjHg1KKv63/\ -AQrg3QO961uTKZJxFUE/xZD3DRoNOir8sVIWYy3Dw759mVsWpx2ynnm5dQeBSB2M19lJsII6Y/MkMSQTzEF7TKVKWEXGPALd9B6YnfQFZ3n/AvRpLGyZh2M0GS8gI8vE0MNfUbAt6ThvorJ4wioASXxW+c1OZPdJ\ -KeOZOBQeS2dYiuOU7B/Ws5mDiGtkH7fB9eywdxQPWY7DfxuMqkl51In3OhArsL/9Ch4ASzJsC1jWFif7WNTz6nTm2Q9Vuq54gJEg3lpG2vqEFQ9pQN42ly1t5K0y8D9vZbMhmxr4axtsOlOn6RlGeATnyMTjjNic\ -jUv0xK2N1KGPmqgRY0RqwFGn9de3AGO/M+Eqn5Jtih9ghUunMDc2zKf3/KGcjILorGfJOJVXEQ17DirhrMZq/OhFkPtYMub1Vjgn2RnMZJgZ7EDhsrXLYCA7TKTU4/c3L+xZZIfIJ5EIZBlk3WrYwJ4UKVVHyn+J\ -XdQazcph1OTp5OtlQL8lkJgEpDt3kvDFRxILrPUHDsukvuKZYJOsRCN2ACWuhhfZsu5v2QjDNVnmSmwrhE34FeIVOYc4N3GJUOlSTRCjoDObQlIpfzFmU+T0ac4DwdAupn12rUiU6Z6JvIcIBV/EYQgidQORS/70\ -aX/3Wjzok9E3br0cL6CbMoYKmkzVYWt7Lw55GoqbNwWbw7KPk8NV0be9zeMW4phpp5Lr8OR24DhEvErifZVKPMY2heCK9SgEelP0QZ6aIOY3dY/TVE/+sY9DCE58MjkR/sDXmUIPghiPe8KUvIRIhDQiFMpGjlKQ\ -7AJztyYyA4xR3OQYb4enHPxI/P7A/xS2Mfpz4n+GE8BnYZF3KSUfjG6KezVspuutpV0BLWo1fMIRxc85PQi4V7LlzYnh+YTVgDMU+WjCaYnwkwAmAU9LmKlK7zZshgrwlvCaLe4KYvPNvd/6Njdh1je5Zt1IDoMP\ -NmT7Mz4KRbV8a5+UcnG3D0tmGrRGn6CGtOBaSbqEb6frWaBIVUEouSROxZOSNnuCGCu41QhJiZ5NfIcTu0aoXuxcMHsIZL6f8yijnl2xF0CMXoIIZmAdrr7DhgfTwmdlOe07LK52eIK9fgxPKDgNsjCecBpdjRvv\ -38LS7dU7rHkNBaY3hXTDyqiRWQV/1aWcL79acEwpYp5dMHGnGEe8BqbVlvvs2ewV2yxKdZ5P62KLE8ry5iZ9EymQ4ZazMbsfI62zHnKgPzBaSExgVtawWAiLy4/3qDWQ+vZnnNF6WeEtrCyl/IKAlfoosKoc3UZs\ -Kyfz8+BbbXbavoCAXxx2tgXnL/w7LNJI9/qIAwIU4dLHn2EE8exaVGjqpT02HobNn4yx5CjGgWJ3/LofacFa9hOigX179e552HqIs9h/AtoHR/K14LV2G2HtJtzrCHnsMXzgR7gnKpjqDXzovPMDFVbG5m1XlEJY\ -30kObesPCmb2xffUE1onNlf+hWuwaiCf9u4KxhxEj+nKVWQss/8FUgIkTM88UuMHDl0urVHDgE01Qad1bN6rBJa8BIu6ovhoE90tKPXqP0piPQE6o7/DIYRs2F9fHLi4YEunVfKos4f7Ur2mq6Azj5R5OdnGTELL\ -8FvEXlBqs4C8TaUAHklu+BOEVgro7KwwaGQ8lJxXUiLcKIAR6nXKZaV8MrnXjL4qYbYqUCi1A2FdZkx+dyypJqGM/kFgII0sMfH8M1qoiiU/e8Ro9P8S2M43rAkYa6h1EekfEWRc6Hi72QTJDMsrARHDacLfmlIk\ -W+/7kaCiAaO3ZsCKpcqMvG3VjPK+Gckg0/+RS5RzLlCI6ZQZVbTYAXpYtwJ66kNhELVQk0jPhmgnkfZy4K6ynhH3AvgXBW59+MsCd9tekfdPaeFh8RJ6tcVqMOAg0awWqIP9z23vV3JAWz558wwZ9dnRKcR8evsF\ -bPnF/PwfmDx+8xCTD48eYfLRrT76yk/Gh+DjbVQXsBGEEXLNvkDGjA28lPRdSvpGMKduYCMpHfNJ73tJEJ5rkIYtBWgEJROehVHhdE2zqYgZMWGGRu5e/mGlhlTBaVwnVy09b99QgL9RQFDTX2AbBDFTUUZX1C4X\ -pF+d7ZNhbglS1EI2d6OuYchPwOQqWldq7+dI+CshBlolohImz7k76GPVYQddq8y/mgKAOgZ1Lp1OpxvkAsERYyk6j8Y+0DaE1i2bn25jY9cf59GrtSJvqFFgBO5Wn2FkXURBLdM2okBubKFI0YaO+jVJHha9Ujkj\ -jk0/E6+odj7Lj0Xy6C7ZfLly5bTajluVWOzlEagqKESGQy4QM3/NH6qaN9QX1BrDySvNjWzfXVdHAA/sB0dEdUXjSRwP9Qm3I86lGQEFIL9RATdkuXA7cr7AUhyqkXkkvv56Qw74iJpwqVYMT+nnUH/ews+i6bXo\ -iEgS+0M+35W6U7oraBRQ1WPp2TQ+W3hgT//DPujafahiesDC9ul3ul3SJyR7FxYgzuQveevOmdFNgbkhFzQCK/pNhrfJcofhtPebYHszRiBPE0D5XDuWyq4VklW6xnEa5tmm080GXTfxGmI+n630CgbqP2KHhkrk\ -XIrQGmaqqmTVlVwCL+s71dapz7/x5wAkOB6iNU1QCZrBLWnCzS9oWNp/1vnfZCaZL2gGUZaay/Ywpj1qHXRVP119fJ/oT0CA9gZqLSiTsnAWH1vm9nsyMyS0fOJ/ReDM1GLAU5M/A+f0k9ptz+cXksQL6cYjiNCe\ -6acMxkpg49QkxpkKRKqlPEXaRP6uLcu5sHRyavbtwnQfCMmUAyyitgeYMOnUcyBuWWFs2rU72NnV4L6zzTnFGMmFZapyDbsj4XiROCEimkMGzL+GXyjlVihn/abKwHNAJOKNOnL4Xk8oPtFh7XQK5aYA4PUg+ppc\ -KXk7UBVCwQbor5QWX1n0OEVqWpUDEBfpCr045aL2D9FQAHrAjUNhDhDfACrdZAM+cQZNuQIhnLse1KP7lj2uZo1oExciQ7tNDDWcLioMRi1pXKVasVQLnoYx+k6w0gghg04n0kOm9E2XHBCVPSOngBN4gwYVRsNh\ -pGvlBJoVNkHg8ASaqVucSKVn2ClwLN95YcdKJ9WKBxvfWddEryZyBPooxMp+B3yuiDXbokuM7oCwC7qFzGJUkRuki868eog3I9u9WFYuBFiScunyQ68Z0qn0Tsu6z4HsTGZ6XwdH3Z657InUNZxxxhSFUl1SkueM\ -Y++6TA4lpINW0wdrSbyScXYWj0AqJOHV8kSjqeRZPzJMNIcf9lMJz9VinINrMwvp268kNyonHIu6SSKHVjgEyKDuMnqBBF7aPwRWUFNGQQpsBCCgnzFIhWXEPDVhUTzbtHxcggZOvJYDdN3R+z22OrGWmnhLEOj3\ -YdLrMGpuG7JqnYiZLL4annG4VCUUhMpQiLSU4Qe3EF3GaN8V9RWXKG19pUVTPZKqxcmRKcLk0j1cx2Fp3nBwbutzLrAaYbIafrjB8Zxqu3z8OlJCznPU6L76GEc/IipvpLf1iwTT4oiJdRcIm3hsTBuv/0CrNWQB\ -u2PpZOTkRXK7ZNiRmmQlnbI9Pw3LK/F92DBCsAaCeJ3ZahrwB14sQTK8xiU85VhfVS5XZG2H1B7wAHVJUqlTrfSKa7nTVhdlU/BtD5jKFQKWNsMdcbIq3kGK436v1x7UuZ+yHmGYheTNXnkuwYY471D7p4Xt1XTg\ -9h8kLBlmiyxx+HLWS/xJtGPipK1fgu6Cd6nrg8km/3hCVyN/h+0moyv4u1xT64VOYSTUeSmA8TygmWsVoDoJJul8MWZd6/0ZCUIzrRveOJILP7qCEo+ne5R2yVhecVyhC0cr741QRKfasFGUTTjhgwJYeWHCDL/W\ -tQJfQwAVH2kBaSu1Fr0Pa4oYfBspG6iXmgHW1AxwdqXbKTVVVa3YnDWPFURDZiqRB9KuacVDolFIBq4pfu9Glq3ccXXNF3KbQP9cgBZ9AkF0dzmptNuiANG39GOW3pITOg3ZqbQJ+5OFZhyaPIyoFTbiBf2YZKrg\ -VColdIDWV0pLNmqvV05UXNTSR6bXaQ5XPZFZuohvjPihn+DiwvoTfodFC9o/SFasqqaIKi20XdtrYPFpT5kjflwgRiX20HXEY44v9OUtOWVyHY8j4SYvGf+s97vj+HIWHxJekfh39CrVtgi+u5SpTD/wGAreVrZi\ -US0ISTyPF54qQk4T/gmZ6nlMq3A5b96zl9Heqe7tstgsUbWtO4kxM+oOLF+Eigraos/LoYSxUl6+gNyXV6gsuEG/N6by/9YmBkZTdO4CHG16dWb6tidcVZBZGwa38qVX55BEj1ffSJIiigRzIv13yob5ezbjSt4+\ -U7OWzvgec0J4AEN0S6pYeq1IXTyMM/vrV3rsjcAHu/5UIaLKpk8noUszqvkX52Kkfn5r5996w6q2k3FrekM/UN6uavfltkufpJIAr/SFDc+518nXHyHp60VNEimY9EDu/FtGYBcH99H5vMMa7J+jyrdngwN5w0jv\ -D/6UylRgsraarP4NJfSaap00X+H/4IQOvyfAAnbjNWUgvxDGq+W8CCrV4ASpgUAF13baCZc2hOm9AuFjpqKIJy8Q0FtCFF1KzkpNJjcRemzgrzqRjk2hHikoWLLJgpvHhNU1DflIXNJI3y9fyr2Dn8TgRo+VSvlv\ -5JDXfGuNG0Fs62Hu7adMjrA2RTYnWccpub9K0+Tzpr91Q1xIarSKCuEnLVr92bMHaPVnpzfR6s9ewCLQ7M+OW5Tr2cMHCBnZo/mi6/bvfbNFL/v+/G5RXuCVX2vyPLHWJSbMNOeLi4/d4DBxLgzW5aKkd4Mh1hG5\ -xp4M93cxNksKk1z9D2WAtrU=\ +5peFnV+6ij+b8FQ1GG2H6WIwCbsbTIZ9nQnfXVjthvPLkvYOf2HQDt/PL9s0/Gh5ZREm6xQ0+Glr5Tv+zKsjEA7fsE0RnqBRMF8+Buc/4ixyjAYH8/I0kQust/VpfsTMX3rzEAwswmhyb34R2A8MtYNRNdkJu7td\ +ZqAaHAaOBpP7h9vhQZOW8UROTrQ3P197mqswGog3gWFbhC9tmPGB86rNw3Ng6s/jsK5mIeLZts3zNRNKesxyUW3VdU7H5P3AfCYCG3SSg/zDdlDkEJ8/XAkv7oR0BuankY4Jn65Y0uAq0eLelZBmCqMeD0op/rb+\ +B0ifdw/0rm9NdkiWVQTlFEPeN6gzKKjwx0pZLLUMD/v2ZW5ZnHbISubl1h0EInWwXGcnwQTqjG2TxJBMMAftMZUqYRUZ8wh003tgdtIXnOX9C9CnsbBlHo7RZLyALCwTKw9/RcG2pOO8icriCasAJPFZ5Tc7kd0n\ +pYxn4k14LJ1hKY5TsnNYzzYOIq6RfdwGv7PD3lE8ZDkO/20wqiblUSeu60CswP72K3gALMmwLWBZW5zsY1HPpdOZZydU6briAUaCeGsZaesTVjykAXnbXLa0kbfKwP+8lc2GbGrgr22w6UydpmcY4RGcIxOPM2Jz\ +Ni7RE7c2Uoc+aqJGjBGpAYec1l/fAoz9zoSrfEq2KX6AFS6dwtzYMJ/e84dyMoqgs54l41ReRTTsOajEshqr8aMXQe5jyZjXW+GcZGcwk2FmsAOFy9Yug4HsMJFSj9/fvLBnkR0in0QikGWQdathA3tSmFQdKf8l\ +dlFrNCuHUZOnk6+XAf2WQGISkO7cScIXH0kssNYfOCyT+opngk2yEo3YAZS4Gl5ky7q/ZSMM12SZK7GtEDbhV4hX5Bzi3MQlQqVLNUGMgs5sCkml/MWYTZHTpzkPBEO7mPbZtSJRpnsm8h4iFHwRhyGI1A1ELsnT\ +p/3da/GgT0bfuPVyvIBuyhgqaDJVh63tvTjkaShu3hRsDss+Tg5XRd/2No9biGOmnUquY5PbgeMQ8SqJ91Uq8RjbFAIq1kMQ6E2hB3lqgpjf1D1OUz35xz4IISzxyeRE4ANfZ4o7CF887glT8hIiEdKIUCgbOUpB\ +sgvM3ZrIDDBGcZNjvB2ecvAj8fsD/1PYxujPif8ZTgCfhUXepZR8MLop7tWwma63lnYFtKjV8AlHFD/n9CCwXsmWNyeG5xNWA85Q5KMJpyXCTwKYBDwtYaYqvduwGSq6WwJrtrgrcM03937r29yEWd/kmnUjOQw+\ +2JDtz/goFNXyrX1SysXdPiyZadAafYIa0oJrJekSuJ2uZ4EiVQWh5JI4FU9K2uwJYqzIViMkJXo28R1O7BqherFzwewhkPl+zqOMenbFXgAxegkimIF1uPoOGx5MC5+V5bTvsLja4Qn2+jE8oeA0yMJ4wml0NW68\ +fwtLt1fvsOY1FJjeFNINK6NGZhX8VZdyvvxqwTGliHl2wcSdYhzxGphWW+6zZ7NXbLMo1Xk+rYstTijLm5v0TaRAhlvOxux+jLTOesiB/sBoITGBWVnDYiEsLj/eo9ZA6tufcUbrZYW3sLKU8gsCVuqjwKpydBux\ +rZzMz4Nvtdlp+wICfnHY2Racv/DvsEgj3esjDghQhEsff4YRxLNrUaGpl/bYeBg2fzLGkqMYB4rd8et+pAVr2U+IBvbt1bvnYeshzmL/CWgfHMnXgtfabYS1m3CvI+Sxx/CBH+GeqGCqN/Ch884PVFgZm7ddUQph\ +fSc5tK0/KJjZF99TT2id2Fz5F67BqoF82rsrGHMQPaarVZGxzP4XSAmQMD3zSI0fOHS5tEYNAzbVBJ0WsXmvEljyEizqKuKjTXS3oNSr/yiJ9QTojP4OhxCyYX99ceDigi2dVsmjzh7uS/WaroLOPFLm5WQbMwkt\ +w28Re0GpzQLyNpUCeCS54U8QWimgs7PCoJHxUHJeSYlwowBGqNcpl5XyyeReM/qqhNmqQKHUDoR1mTH53bGkmoQy+geBgTSyxMTzz2ihKpb87BGj0f9LYDvfsCZgrKHWRaR/RJBxoePtZhMkMyyvBEQMpwl/a0qR\ +bL3vR4KKBozemgErlioz8rZVM8r7ZiSDTP9HLlHOuUAhplNmVNFiB+hh3QroqQmFQdRCDVhM1NOTSHs5cFdZz4h7AfyLArc+/GWBu22vyPuntPCweAm92mI1GHCQaFYL1MH+57b3KzmgLZ+8eYaM+uzoFGI+vf0C\ +tvxifv4PTB6/eYjJh0ePMPnoVh995SfjQ/DxNqoL2AjCCLlmXyBjxgZeSvouJX0jmFMrsJGUjvmk970kCM81SMOWAjSCkgnPwqhwuqbZVMSMmDBDI3cv/7BSQ6rgNK6Tq5aet28owN8oIKjpL7ANgpipKKMrapcL\ +0q/O9skwtwQpaiGbu1HXLeQnYHIVrSu193Mk/JUQA60SUQmT59wd9LHqsIOuVeZfTQFAHYM6l06n0w1ygeCIsRSdR2MfaBtC65bNT7exq+uP8+jVWpE31CgwAnerzzCyLqKglmkbUSA3tlCkaENH/ZokD4teqZwR\ +x6afiVdUO5/lxyJ5dJdsvly5clptx61KLPbyCFQVFCLDIReImb/mD1XNG+oLao3h5JXmRrbvrqsjgAf2gyOiuqLxJI6H+oTbEefSjIACkN+ogBuyXLgdOV9gKQ7VyDwSX3+9IQd8RE24VCuGp/RzqD9v4WfR9Fp0\ +RCSJ/SGf70rdKd0VNAqo6rH0bBqfLTywp/9hH3TtPlQxPWBh+/Q73S7pE5K9CwsQZ/KXvHXnzOimwNyQCxqBFf0mw9tkucNw2vtNsL0ZI5CnCaB8rh1LZdcKySpd4zgN82zT6WaDrpt4BzGfz1Z6BQP1H7FDQyVy\ +LkVoDTNVVbLqSi6Bl/WdauvU59/4cwASHA/RmiaoBM3gljTh5hc0LO0/6/xvMpPMFzSDKEvNZXsY0x61DrqqH3Tb7xP9CQjQ3kCtBWVSFs7iY8vcfk9mhoSWT/yvCJyZWgx4avJn4Jx+Urvt+fxCkngh3XgEEdoz\ +/ZTBWAlsnJrEOFOBSLWUp0ibyN+1ZTkXlk5Ozb5dmO4DIZlygEXU9gATJp16DsQtK4xNu3YHO7sa3He2OacYI7mwTFWuYXckHC8SJ0REc8iA+dfwC6XcCuWs31QZeA6IRLxRRw7f6wnFJzqsnU6h3BQAvB5EX5Mr\ +JW8HqkIo2AD9ldLiK4sep0hNq3IA4iJdoRenXNT+IRoKQA+4cSjMAeIbQKWbbMAnzqApVyCEc9eDenTfssfVrBFt4kJkaLeJoYbTRYXBqCWNq1QrlmrB0zBG3wlWGiFk0OlEesiUvumSA6KyZ+QUcAJv0KDCaDiM\ +dK2cQLPCJggcnkAzdYsTqfQMOwWO5Tsv7FjppFrxYOM765ro1USOQB+FWNnvgM8VsWZbdInRHRB2QbeQWYwqcoN00ZlXD/FmZLsXy8qFAEtSLl1+6DVDOpXeaVn3OZCdyUzv6+Co2zOXPZG6hjPOmKJQqktK8pxx\ +7F2XyaGEdNBq+mAtiVcyzs7iEUiFJLxanmg0lTzrR4aJ5vDDfirhuVqMc3BtZiF9+5XkRuWEY1E3SeTQCocAGdRdRi+QwEv7h8AKasooSIGNAAT0MwapsIyYpyYsimeblo9L0MCJ13KArjt6v8dWJ9ZSE28JAv0+\ +THodRs1tQ1atEzGTxVfDMw6XqoSCUBkKkZYy/OAWossY7buivuISpa2vtGiqR1K1ODkyRZhcuofrOCzNGw7ObX3OBVYjTFbDDzc4nlNtl49fR0rIeY4a3Vcf4+hHROWN9LZ+kWBaHDGx7gJhE4+NaeP1H2i1hixg\ +dyydjJy8SG6XDDtSk6ykU7bnp2F5Jb4PG0YI1kAQrzNbTQP+wIslSIbXuISnHOuryuWKrO2Q2gMeoC5JKnWqlV5xLXfa6qJsCr7tAVO5QsDSZrgjTlbFO0hx3O/12oM691PWIwyzkLzZK88l2BDnHWr/tLC9mg7c\ +/oOEJcNskSUOX856iT+JdkyctPVL0F3wLnV9MNnkH0/oauTvsN1kdAV/l2tqvdApjIQ6LwUwngc0c60CVCfBJJ0vxqxrvT8jQWimdcMbR3LhR1dQ4vF0j9IuGcsrjit04WjlvRGK6FQbNoqyCSd8UAArL0yY4de6\ +VuBrCKDiIy0gbaXWovdhTRGDbyNlA/VSM8CamgHOrnQ7paaqqhWbs+axgmjITCXyQNo1rXhINArJwDXF793IspU7rq75Qm4T6J8L0KJPIIjuLieVdlsUIPqWfszSW3JCpyE7lTZhf7LQjEOThxG1wka8oB+TTBWc\ +SqWEDtD6SmnJRu31yomKi1r6yPQ6zeGqJzJLF/GNET/0E1xcWH/C77BoQfsHyYpV1RRRpYW2a3sNLD7tKXPEjwvEqMQeuo54zPGFvrklp0yu43Ek3OQl45/1fncc38ziQ8IrEv+OXqXaFsF3lzKV6QceQ8HbylYs\ +qgUhiefxwlNFyGnCPyFTPY9pFS7nzXv2Mto71b1dFpslqrZ1JzFmRt2B5YtQUUFb9Hk5lDBWyssXkPvyCpUFN+j3xlT+39rEwGiKzl2Ao02vzkzf9oSrCjJrw+BWvvTeHJLo8eobSVJEkWBOpP9O2TB/z2Zcydtn\ +atbSGd9jTggPYIhuSRVLrxWpi4dxZn/9So+9Efhg158qRFTZ9OkkdGlGNf/iXIzUz2/t/FtvWNV2Mm5Nb+gHyttV7b7cdumTVBLglb6w4Tn3Ovn6IyR9vahJIgWTHsidf8sI7OLgPjqfd1iD/XNU+fZscCBvGOn9\ +wZ9SmQpM1laT1b+hhF5TrZPmK/wfnNDh9wRYwG68pgzkF8J4tZwXQaUanCA1EKjg2k474dKGML1XIHzMVBTx5AUCekuIokvJWanJ5CZCjw38VSfSsSnUIwUFSzZZcPOYsLqmIR+JSxrp++VLuXfwkxjc6LFSKf+N\ +HPKab61xI4htPcy9/ZTJEdamyOYk6zgl91dpmnze9LduiAtJjVZRIfykRas/e/YArf7s9CZa/dkLWASa/dlxi3I9e/gAISN7NF903f69b7boTd+f3y3KC7zva02eJ9a6xISZ5nxx8bEbHCbOhcG6XJT0YjDEOiLX\ +2JPh/i7GZklhkqv/AdnBtYo=\ """))) ESP32C6BETAROM.STUB_CODE = eval(zlib.decompress(base64.b64decode(b""" -eNrFWmt7E8cV/ivGNnZC87Qz0t6GBCOBjGzAlKQE11S07M7uuuSiJxg5mDb67533XDQr2ZL51g+ypdndmTPnvOc9l9n/7s+aq9n+/a1qf3Jl7OTKhk+Vh+/4mHdPJ1e+CN/6k6vSTa4KGt0Lg+WL8Cf7IfxJwlAW\ -/jfb4Y+XpxN6enLV1mc5zfEw/DHPw/z9WRjF5XZyMblqTPjVG1SjnbBAscsyVL3jyVXdGz063g7PmrQMC/fCJ9xbFIPwpz/Zn0yxAua7DDOkNB/d5fJ5GA0LNEFm68KXNlzxQfiqzSf7JNcfz8J9dbi/4mfbNs/X\ -XNClh6wa2mn41HVOO+X5IHwmOustlBc+QXUufHwf/x/PRZbiFHscQPjDuI4J/ws3ZBXcvKh7OJeleYVBRwZdKf62/jEMwLOH9a5PDYsl+QjqCfZxfZ43WDTYyPlnujLsHR4qw8O+fZtbVqfts535dlschUXqcZjb\ -jgIK6vBko2pIRrgG6/EqVcImMuYE66YPIeyoqzjL8zusT2Nhyjxso8n4BgJZxpjAb+cYSzrOk6guXrIJsCT+V/neQmWPyCjDILezPIVJx7gV2ykBJ8jGMMciRSPzFKTT7bAz1xstqVZUo1vx0OUw/LUBVE3Ko4Vl\ -9RRYzGF+ewceACQZxgJua93pAW6KUwfpPPuhardwTzAS1FvLSFufsuGhDejb5jKljbJVBv7nrUzWZ6hBvrbBpGN1mg4wwiPYRyYeZwRzNt6iO25tXB32qGk1EoyWCrupsZS/PgUE+5UXrvJDwqb4Ae4o0kPAjYH5\ -/UN/LDvLcPe4g2TsyquK+h0HFTqrcTd+dBjkEW4Z8v1WJCfdGVzJcKW3A4PL1EUGgOzwIqVuvzu5s+dRHFo+iYtAl0HXrdIG5iSmVBup/CVmUTSalc0o5Gnn63VAv4VITIKlF+4k9MVbEgTW+gOb5aXu8JWASTai\ -ERzAiKv0IlPW3SkbEbgWZHK4oahxIwdRmMHXsUYYiiQveA9d+gHgwBYCyhIADpcqR5gNGvt6JFcQStweu7LtnzHGKY74I/9jmMboz5H/F/YK0yCOPCDmPRrsiRYbdksn2gUdgGbJpw0TSeNXwhM27FPd5IA8ZULP\ -TgasrzDdhGSegDH7vA2XD0ZMQBQpJTRKmOxGx4u0Yb/RQN6Jy5ffSlj2zcNfNHTi8RELvm4jtJlKiMqmzBBVb8y7IOjmWwdsksZ+240+Y8Xm4Ib14P1FK9wKr+8drhNiK3wBE4XQxuSoOYNQY0cFQ01g1AuIzJks\ -dpi8FYUd/5ixbACr7/Iaseb5nDkAqQ2Ch5crgEZR32fUAVf4X1mm9gI3Vzt8gXlxiEDimOpYEy+ZKm+MzDHoL8cSQMpIGOnpRErm62yIsbof7/Z0d1zXCqvwc+cdGuutxgsi7yLGiY1L2rgk8z+0W+Ux9ZDEgrd6\ -T5xW/LpKJexDOpdI2F8XcQ0yKSN3UUBIDhHWiGouP4A47PwjLr3HyumeGDNsoW54o7VkLXUpEuVzAKPkzECIacbKKDQzEGEheFsesKBMMtsMTuWimxX1bm91ZpP+FKcnBijHQ6YyTk7OO8GWPpDSiZpZjjXyOZFv\ -+fHOarBnur2Z2EqzI3d4e4gvcDJ8M6mP2qrKwT3YqRxNpoGk2uysfQPtvjleuCqI1PmPuEmt9v4pkyusUKQvbhNEEbbCsE29NM327USNIIxI45yS7u7wPZMX4xfSZT8ytyqiNdO50XkIW/bDh/nH1yCCN2CjfwJS\ -lVAMxcZt0OAefPMp9oLA1qKiqlEk9H9irmgEoqWYVVW8JEfvz1yzVFBtlTEBgSB875atF1DPucfoJ560SGuFVKGl3GbIb99uKZvP/7N+TkKkv8+kSjD0128OC1/wI0S9mg3Z4wOp2dLVVCtf8SRKJKykgzUCEdZp\ -k5Btmsp/YC8jJoHIZZprnAdW0yH8K81fMLjKLwGXRj3M4lAxO+d/f894qZRXHWqDtidyL678ach2L0jG/icpjWlkSYbXtwPcL/vJCedgX6owhDHPdmgBF3uMyBcmKXGP0yvt7XJUvbnkVFBKmvCPpuQnG3fg/xpB\ -jVDT9B5IEb5eVhokJPzA2fiUc3GSNQWvajGyyFxRwGnmau2YB6FR5BnUnPh/0yyhp/gxjVx7+e2HB6tevyFjoiJ4mZJf3nsFGL6aTM8g/vFPYJ3y6dNnuPjs3nNcfD6ZnoCv3550mi5Vfjo8RvbyIdoAmR+2G7j/\ -QNwkE6KSWFpKLAWz1oXE2kxibdL5XlJ6QM/inqbHyRZqEzwLeGB7IEKfbXa20mvyVzwEny1VQppFaUaDsaqUlTCLTe7CJPbw35wiFqztlNGzqM6WK6s75wcEuy3JhrUiS4uBdtLwrSsESNfYJ1rQqkUXjTKbHtJ0\ -EhjXpA7hR6dRN5mMr6OjoilVB7TFnBLICUu/Fj1tuZHOp6Jl7qGgUKKdiLFFx9NFi076CpAOXkd6AywtDab8hbsih5sJpKROyXn+TLaFJofNl5Nk5MdF2g5bNURsKVGiEkSdISjjb1H/nD9Xs65TcylxwFUaqRig\ -i85CLvsueH8I3zSexPFQPnFJPJWCGOYBL+E/bva5tsQmM9yKHTVyHTzbvd+QB51QI6iSiib7nn46/fk1frqm0yaiRZKY3Pt8V5xGKvzaSUlm6dk0Pus8kjn/+IA916KYKO3hEZT9QOlc5y66czvbbmP2tzz1wgvA\ -Tij9WpXwC4uZATckliuZTSTaTZUogd5QtKBX4MBEqeV+ZZVrP04VYSkUcHXinRqKDXPJgFu2ZkrNOSR0+TcAQ5sxQi137cBpeeYrvhCQckHD4iW28L/IlWQyoysQM/+K8p4Yd6hr0WqM5+Z62MCBjjgeKdODMycR\ -0MiT1+D3IMJq5H8FqWUKCfB9k7+C8GORsslfTy4kgDrp8bQKgvQmRFjhPA4egr5UMpJacpX07nfSaSBCpp2jc4RJXPpE1ku5ZgdZeURxkx56JpOWaY6BWxdHO7tKp6heGvp2yWuXqeq1zvcQDFrROKJrTddQGELn\ -pdWVW1k56zZzel7QkHNJYXrqLiOlnnWYhobojqZO7kABAJp6GJ1n2IO52BmGN3YkUR1m7TSAd5HZqpQ9kRJmIwOCdFW62iPgF88h4xGMdwRWG0HRo825fOFRqjsQN7djpHK3EihrGzUKh/NchwuMAyzo8qI76Nkg\ -qvOqjtbmXrNfqF2mJDWko277lJrs0JY99z9jDAW+QdsMo2FL0ksrhGtM+h2ntTNtgCZSQRl2Z+zMs2KrjigL3Yp8jV9gbxSxN42qvExQThTaCd+iDvpid4AMHYEp4PqL44sLofO6068yTB4Xy/aF9kqyr6liEhKc\ -QexSpl0JZGYkYOi68uBgMWcicyJm9cccJ4XBNHUJTjWMdW+ZHAuXMz10cqwkVsmFHcctkP0aiaL0RKMx5FWXMUYauY+7MYSv1YLP3rUrMykfVqJaI7wDVTdJlNCqhE56TukIoGja3ySVoOaGei/gAalXE5Pwf8aM\ -VVP6yE26nngqfPZiMf2vsePaGmkmLk33uZ90Op3iVaTrWnjTCLqr/jl7vurcUVpm73JD3NdoRrb1EE0vV8+5A9nWc61j6gEPNYXssaJSSbqY6yQ0Bq0CuHQ9Zcg0ImTV/3SXaZ3Kq3z4Pq7kp1ItmvnnOPoZ/HzL\ -eoWZieTuKa/XaiNx/WODjxLpZK3WkMF3h9JlyMlp5CTDst80yUpgZfii/1aJn/uaSVedPh6dtRoQ/FE3jDSRg+YFG6vKpdxsF+nYEx6g7kQqjQHL+QHtte64I+PAt53sUw4xQLNNf0ccqoqHXeKkD/TghQ4ODtmI\ -HGLHMrIoj4VYKBos8vIb1PwbvxnAh32fhH8My9RSTvJ23In8SUQwidHWb7HoJc9S10ejdSu9Q9Vi/ejvwGwymMOt5ShUT5MczumcpDOtPA02L1pNQAvhjHQyG7KNaz3lhA5K+VH07z6lrr30n6WEoROcdgkk76Qg\ -qMVieDeBSiFqXjeaRVOm8EnTSDmUN/2v9F6pCANPKl6pflSgaDO8cZFjCbl6vpohsak5xdmVcwcj+6lW4GbNC01lOaiyRp7IOUsrnhHxYAQPBNXdKLKVA7ZF/4PcJaw/lVSL/iNRWJwJ1NLfigrckmOQVPpvXf8r\ -9AD9povOdJ60x936x3qvoTA51PRUqvyq2FQMLYHUXi+OqIKpeYzf2jhe9UNOjS/iiwm+70dbIAl/yq9KaMH6G6mLrdW4aFW0/IgCOm0k3u0ZS8SPSzKhJaDX8RjN5S0DzEO7TK5n5AityVvOcteHpNP4DhBvEo6R\ -+I/0xs62KL5PZcaMo2SkHUOkbYXLWVUzyhlexwNXVSFHCP+S0DoVHpXyxpeXjCCaO9W5iyx2UtRsayjkb1T6Lx/Biv5b1xXkWEislAN+KH35DlUE90D3h1Tef71pdcT07+WtilDONZ1+Tfqho1+1kRltCsGPl97T\ -QhR9tvr6ixRTpJ5T6X1bwvMlg7mSV50U3BWX5/vCK5QQ9OWsNo8Nx5sh8jjupzAHm5TwkBmw8jfXHmpyEC36A8hfgWAdL1tWUmH1LZHf9bRXQZTx6xIb2nbyNk97IOdE+iSVAKjww4RTbkzywUMgeD0VSeIKJj2S\ -lw9azsIujh6hTXmfRWSR/wJDbI97R/I6C8OpSP+QIlU4XHtKVj994WBE8nXa9NB70WP/3Jf8goo0DR+Upw041tN+kUBVvVOECTofpfpND15SObw2nXcxfIxaRH3yGgO9lUI0U3KEajI5A1BL4X/dkx6KU9eUnIMi\ -C9EF9V/1LCGPpz8mX4SUZR+lkN2T8l6JTp8065MVfLLrnrceqWsBv5V9ZgBQGt4QQigmFbcIYEzyRX4y0AZ/Iq0oKpFftq+A11dPQhyosrO9NwhrbwCff+DysxblfPb8yQkun0xmnSY+UYLZ/2aL3vj818dZeYH3\ -Pq3J88TaIjHhSjOdXXxeDPb7vSIM1uWs1BdEAargTPsy3J3F2CxxJpn/D+2ZEsk=\ +eNrNWlt7G7cR/SuyJEuJm68FyL3BiSXSpkTJtzqpY9Uu3XoX2FWdC79YpmK5Df97cebCXVIi5cc+UCKxu8Bg5syZC/a/+7P6arZ/f6van1wZO7my8VPl8Ts+5t3jyZUv4rf+5Kp0k6uCRvfiYPk8/sl+iH+SOJTF\ +//V2/OPl6YSenlw14XVOcxzGP+ZpnL8/i6PJ4eRiclWb+LU3qEY7cfZilwWoeqeTq9AbPTzdjg+atIyr9uIn3lsUg/inP9mfTDE9JruMM6TxR8N3uXweR+PidRTYuviliVd8lLxq8sk+CfXHk3hfiPdX/GzT5Pma\ +C7r0kPVC24yfEHLaJs8H4TNRWG+hufiJenPx4/v4/2gushRn2OMAwh+165j4v3BDVsHNi7rDuSzNKww6MuhK7W/rH0H7PHtc7/rUMFeSj6CeaBzX53mjOaOBnH+iK8PY8aEyPuybt7llddo+G5lvt8VJXCSM49x2\ +FCEQ4pO1qiEZ4Rqsx6tUCZvImGdYNz2EsKOu4izP77A+jcUp87iNOuMbCGEZYwK/nWMs6ThPorp4wSbAkvhf5XsLlT0kowyj3M7yFCYd41ZspwScIBtjHIsUtcxTkE63485cb7SkWlGNbsVDl8P410ZQ1SmPFpbV\ +U2Axh/ntHXgAkGQYC7itcWcHuKmdOkrn2QlVu4U7xkhUb5CRJpyx4aEN6NvmMqVtZasM/M9bmazPUIN8TY1Jx+o0HWDER7CPTDzOCOZse4vuuLHt6rBHoNVIMFoq7iZgKX99Cgj2Ky9c5UeETfED3FGkR4AbA/P7\ +Q38qO8tw97iDZOzKq4r6HQcVLgu4Gz86DPIQtwz5fiuSk+4MrmS40tuBwWXqIgNAdniRUrffndzZ81YcWj5pF4Euo64bpQ3MSTSpNlL5S8yiaDQrm1HI087X64B+C5GYBEsv3Enoi7ckCAz6A5vlpe7wlYhJNqIR\ +HMCIq/QiU4bulLUIHASZHGsoZNzIQRRj8HWs4YXCyHPeQ5d+ADiwhYCyBIDjpcoRZqPGvh7JFYQSt8eubPuvGeMUR/yJ/zFOY/TnyP8Le4VpEEceEPOeDPZEizW7pRPtgg5As+TThomk9ivhCRv2qW5yQJ4yoWcn\ +A9ZXnG5CMk/AmH3ehssHIyYgipQSGiVMdqPjRVqz32gU7wTly28lJvv68BcNnXh8xIKv2whtphKisikzRNUb8y4IuvnWAZuktt92o89YsTm4YT14f9EIt8Lre0frhNiKX8BEMbQxOWrOINTYUcFQsxf1AiJzJosd\ +Jm9FYcc/ZiwbwOq7vEaseT5nDkBeg+Dh5QqgUYT7jDrgCv8ry9Re4OZqhy8wLw4RSBxTHWviBVPljZG5DfrLsQSQMhJGejqRkvk6G2Is9Nu7Pd3drmuFVfi58w6N9VbjBZF30caJjUvadknmf2i3ytvUQxIL3uo9\ +cVrx6yqVsA/pXCJhf13ENcikjNxFASE5Qlgjqrn8AOKw84+49B4rp3tizLiFUPNGg2QtoRSJ8jmAUXJmIMQ0Y2UUmhmIsBC8KQ9YUCaZbQanctHNinq3tzqzSX9qpycGKMdDpjJOTs47wZY+kNKJmlmONfI5kW/5\ +8c5qsGe6vZnYSrMjd3h7hC9wMnwzqW+1VZWDe7BTOZpMI0k12evmDbT75nThqiBS5z/iJrXa+8dMrrBCkT6/TRBF2ArD1mFpmu3biRpBGJHGOSXd3eF7Ji/GL6TLfmRuVURrpnOj8xC27IcP84+vQARvwEb/BKQq\ +oRiKjdugwT345mPsBYGtQTkVUCT0f2KuqAWipZhVVbwkR+/PXLNUUG2VMQGBIHzvlq0XUM+5x+gnnrRIg0Kq0DpuM+S3b7eUzef/WT8nIdLfZ1IlGPrrN8eFL/gRol7NhuzpgdRs6Wqqla94EiUSVtLBgECEdZok\ +Zpum8h/Yy4hJIHKZ5hrngdV0CP9K8+cMrvJLwKVRD7M4lMvO+d/fM14q5VWH2qDpidyLK38ast0LkrH/SUpjGlmS4dXtAPfLfvKMc7AvVRjCmGc7NICLPUXki5OUuMfpleZ2OareXHIqKCVN+Edd8pO1O/B/bUGN\ +UFP3HkgRvl5WGiQk/MDZ+JRzcZI1Ba9qMbLIXFHAaeZq7ZgHoVHkGU3yf0CzhJ7ix7Tl2stvPzxY9foNGRMVwcuU/OLeS8Dw5WT6GuKf/gTWKR8/foKLT+49xcWnk+kz8PXbZ52mS5WfDU+RvXxobYDMD9uN3H8g\ +bpIJUUksLSWWgllDIbE2k1ibdL6XlB7Qs7in7nGyhdoEzwIe2B6I0Gebna30mvwVh+CzpUpIsyjNaDBWlbISZrHJXZjEHv2bU8SCtZ0yehbV2XJldef8gGC3JdmwVmRpMdA2Gr51hQDpGnusBa1adNEls+kRTSeB\ +cU3qEH90unSTyfg6OiqaUnVAW8wpgZyw9GvR05Qb6XwqWuYeCgol2okYW3Q8XbTopK8A6eB1pDfA0tJgyl+4K3K0mUBK6pSc509kW2hy2Hw5SUZ+XKTNsFFDtC0lSlSiqDMEZfwtws/5UzXrOjWXEgdcpZGKAbro\ +LOSy74L3h/BN40k7HssnLomnUhDDPOAl/MfNPteW2GSGW7GjWq6DZ7v3G/KgZ9QIqqSiyb6nn05/fo2fru60iWiRpE3ufb4rTiMVfnBSkll6Nm2fdR7JnH90wJ5rUUyU9ugEyn6gdK5zF925nW22MftbnnrhBWAn\ +lH6NSviFxcyAGxLLlcwmEu2mSpRAbyha0CtwYKLUcr+yyrUfp4qwFAq4OvFODcWGuWTALVszpeYcErr8G4ChyRihlrt24LQ88xVfiEi5oGHxElv4X+RKMpnRFYiZf0V5Txt3qGvRaIxP+EcVDnTE8UiZHrx2EgGN\ +PHkNfg9aWI38ryC1TCEBvq/zlxB+LFLW+avJhQRQJz2eRkGQ3oQIK5zHwUPQl0pGEiRXSe9+J50GImTaOTpHmMSlx7JeyjU7yMojipv0yDOZNExzDNxQnOzsKp2ieqnp2yWvXaaq15DvIRg0onFE10DXUBhC56XV\ +lRtZOes2c3pe0JBzSWF66i4jpZ51mIaG6I46JHegAABNPYzOM+zBXOwMwxs7kqgOs3YawLvIbFXKnkgJs5EBQboqXfAI+MVTyHgC452A1UZQ9GhzLl94lOoOxM3tGKncrQTKYFuNwuE81+EC4wgLurzoDno2iOq8\ +Cq21udfsF2qXKUkN6ajbPqUmO7Rlz/3PGEOBb9A2w2jckvTSCuEak37Hae1MG6CJVFCG3Rk786zYqiPKQrciX+0X2Bu12Ju2qrxMUE4U2gnfog76YneADB2BKeD6i+OLC6Hz0OlXGSaPi2X7Qnsl2ddUbRISnUHs\ +UqZdCWRmJGDouvLgYDFnInMiZvXHHCeFwTR1iU41bOveMjkVLmd66ORYSVslF3bcboHsV0sUpSdqjSEvu4wx0sh92o0hfC0IPnvXrsykfFiJarXwDlRdJ62EViV00nNKRwBF3fwmqQQ1N9R7AQ9IvZqYxP8zZqxA\ +6SM36XriqfDZi8X0v7Yd18ZIM3Fpus/9pNPpFK8iXQfhTSPorvrn7Pmqc0dpmb3LDXEf0IxswhBNLxfm3IFswlzrmDDgobqQPVZUKkkXc52ExqBVAJcOU4ZMLUJW/U93mdapvMqH79uV/FSqRTP/3I5+Bj/fsl5h\ +ZiK5e8zrNdpIXP/Y4KNEOlmrMWTw3aF0GXJyGjnJsOw3dbISWBm+6L9V4uc+MOmq07dHZ40GBH/SDSN1y0Hzgo1V5VJuNot07JgHqDuRSmPAcn5Aew0dd2Qc+KaTfcohBmi27u+IQ1XtYZc46QM9eKGDgyM2IofY\ +sYwsymMhFooGi7z8BjX/xq8F8GHfJ+EfwzI1lJO8HXcif9IimMRowlssesmzhHAyWrfSO1Qt1o/+DswmgzncWo5C9TTJ4ZzOSTrTyNNg86LRBLQQzkgnsyHbOOgpJ3RQyo+if/cxde2l/ywlDJ3gNEsgeScFQRCL\ +4d0EKoWoeV1rFk2ZwidNI+VQ3vS/0nulIow8qXil+lGBos3w2rUcS8jV89UMiU3gFGdXzh2M7KdagZs1zzWV5aDKGjmWc5ZGPKPFgxE8EFR3W5GtHLAt+h/kLnH9qaRa9B+JwuJMIEh/q1XglhyDpNJ/6/pfoQfo\ +N110pvOkPe3WP9Z7DYXJkaanUuVXxaZiaAmk9npxRBVM4DF+a+N01Q85Nb5oX0zwfT/aAkn4M35VQgvW30hdbK3atVZFy48ooNNG4t2+Zon4cUkmtAT0Ot5Gc3nLAPPQLpPrGTlCa/KWs9z1IemsfQGINwnHSPxH\ +emNnWxTfpzJjxlGypR1DpG2Fy1lVM8oZXrUHrqpCjhD+BaF1Kjwq5Y0vLxlBNHeqcxdZ20lRs62hkL9R6b98BCv6b1xXkFMhsVIO+KH05TtUEdwD3R9Sef/1ptUR07+XtypiOVd3+jXph45+1UZmtCkEP1p6SQtR\ +9Mnq6y9STJF6zqT3bQnPlwzmSl51UnBXXJ7vC69QQtCXs9q8bTjeDJFH7X4Kc7BJCYfMgJW/ufZQk4No0R9A/goE63jZsJIKq2+J/K6nvQqijF+X2NC2k7d5mgM5J9InqQRAhR8nnHJjkg8eIsHrqUjSrmDSE3n5\ +oOEs7OLkIdqU91lEFvkvMMT2uHcir7MwnIr0DylShcO1p2T10xcORiRfp00PvRc99s99yS+oSNPwQXnagGM97RcJVNU7Q5ig81Gq3/TgJZXDa9N5F8O3UYuoT15joLdSiGZKjlB1JmcAain8Dz3poTh1Tck5KLIQ\ +XVD/Vc8S8vb0x+SLkLLsoxSye1LeK9Hpk2Z9soJPdt3z1iN1LeC3ss8MAErDa0IIxaTiFgGMSb7ITwba4E+kFUUl8ovmJfD68jjGgSp7vfcGYe0N4PMPXH7SoJzPnh4/w+Vnk1mniU+UYPa/2aLXPf/1cVZe4KVP\ +a/I8sbZITLxST2cXnxeD/X6viIOhnJX6dihAFZ1pX4a7sxibJc4k8/8BksMRng==\ """))) -ESP32H2ROM.STUB_CODE = eval(zlib.decompress(base64.b64decode(b""" +ESP32H2BETA1ROM.STUB_CODE = eval(zlib.decompress(base64.b64decode(b""" eNrFWmtbG8cV/isYMCRunnZG2ts4MUi2QFyM66SOKa7cend2lzoXnoBFjNvov3fec9GsAMn+1g8CaXZ35sw573nPZfa/29PmZrr9eK3antwYO7mx4VPl4Ts+5t3R5MYX4Vt/clO6yU1Bo1thsHwR/mQ/hD9JGMrC\ -/2Y9/PHydEJPT27a+iynOXbDH/M8zN+fhlFcbidXk5vGhF+9QTXaCAsUmyxD1Tuc3NS90dPD9fCsScuwcC98wr1FMQh/+pPtyQVWwHzXYYaU5qO7XD4Lo2GBJshsXfjShis+CF+1+WSb5PrjONxXh/srfrZt83zJ\ -BV16yKqhnYZPXee0U54Pwmeis95ceeETVOfCx/fx/9lMZClOsccBhN+L65jwv3BDVsH9i7rdmSzNKww6MuhK8bf1z2AAnj2sd3dqWCzJR1BPsI/r87zBosFGzh/ryrB3eKgMD/v2bW5ZnbbPdubbbXEQFqnHYW47\ -Ciiow5ONqiEZ4Rqsx6tUCZvImBOsm+5C2FFXcZbnd1ifxsKUedhGk/ENBLKMMYHfzjGWdJwnUV28ZBNgSfyv8q25yp6SUYZBbmd5CpOOcSu2UwJOkI1hjkWKRuYpSKfrYWeuN1pQrahGt+Khy2H4awOompRHC8vq\ -KbCYw/z2ATwASDKMBdzWutMd3BSnDtJ59kPVbuH2MRLUW8tIW5+y4aEN6NvmMqWNslUG/uetTNZnqEG+tsGkY3WaDjDCI9hHJh5nBHM23qI7bm1cHfaoaTUSjJYKu6mxlL87BQT7lReu8j3CpvgB7ijSPcCNgfn9\ -rj+UnWW4e9xBMnblVUX9joMKndW4Gz86DPIUtwz5fiuSk+4MrmS40tuAwWXqIgNANniRUrffndzZ8ygOLZ/ERaDLoOtWaQNzElOqjVT+ErMoGs2tzSjkaefLdUC/hUhMgqXn7iT0xVsSBNb6A5vlpR7wlYBJNqIR\ -HMCIt+lFpqy7UzYicC3I5HBDUeNeDqIwg69jjTAUSV7wHrr0A8CBLQSUJQAcLlWOMBs09vVIriCUuC12Zds/Y4xTHPEH/scwjdGfI/8v7BWmQRx5Qsx7MNgSLTbslk60CzoAzZJPGyaSxt8KT9iwT3WTA/KUCT07\ -GbC+wnQTknkCxuzzNlw+GDEBUaSU0Chhshsdr9KG/UYDeScuX38rYdk3u79o6BTfkRi5bC+0n0q4yqZMElVvzBsh9OZrO2yVxn7bDUBjhefg/iXBAUUrDAvf7+0tk2MtfAEfhQDHFKmZgxBkRxFDTWPUF4jSmTI2\ -mMIVix0vmbJ4gKzvshtx5/mMmQAJDkKIlysASFE/ZuwBXfhfWSb4AjdXG3yB2XGIcOKY8FgZL5kw743PMfQvRhQAy0gw6UWtMqUvMyPG6n6829PdcV0r3MLPnXfIrHc7ahCFFzFarFzSxiU5CkC7VR4TEEkveKuP\ -xHXFu6tUgj+kc4kE/2Vx1yCfMnIX42wPwY0I5/oS9GFnH3DpPVZOt8SYYQt1wxutJXepS5EonwEYJecHQk9TVkah+YEIC8HbcocFZapZZ3AqIy2D9vbtqU36U5yfiKAcD5nROEc578Rc+kBMJ3pmQZYI6ETAxcc7\ -q8Gg6foqfnu3KZe93cMXuBi+mdRHXVXl4BGsVI4mF4Go2uysfQPdvjmcOyrI1PkPuElt9v6ICRY2KNIXq1m2nOPrFss29cI065+fBtEQ0cY5Jd7N4XtmL0YvpMt+ZH6d05hkO/e6DiHLXl7OPrwGDbwBF/0TgKqE\ -YCg+roMEt+CZR9gLgluLqqqGPP2fmCkaAWgpNlUVL8jR+zPXLRVUW2VMP6AH3/vM1sFh6bnH6EeetEhrxVOh5dxqwK/GC+hi9p/lExIW/WPmUwKgv3tzWPWKHyHW1XTIHu5I0ZbezrXyWz5EmYSVfLAeYSKkDklI\ -N03lL9m/iESglzLNNdADqOkQnpXmLxhZ5Zcgy0vMwywOJbNz/vf3DJZKKdWhOGh7Ivf8yp+GbPSCZOx/lNqYRhZkeP35VMQvOskJJ2FfqjBEMC9Bu0BoO0TQC5OUuMfplfbzclS9mSRVUEqa8I+m5Ccbt+P/GhGN\ -KNP0nkgVvlxWGiQk/MDp+AUn4yRrCkbVamSeuqKC09TV2jEPQqNIMag78f8l2MFk+mMaOfb628snt719taKpBl5k45ePXgGEryYXZxD+8CcQTnl0dIyLx4+e4+LzycUJqPrtSafnUuWnw0PQxGW0ALI+bDbQ/o44\ -SSYcJUG0lCAKUq0LCbKZBNmk872kvICexT1Nj7MslCZ4FuDADsGBPluda5Res75iF1S2UAhp+qSpDMaqUlbCLDZ5CIPYvX9zbliwwlPGzrw4WyysHpzvEOjWJBPWgiwtBtpIw7euEMicjN3XelaNOu+T2XSPppOY\ -uDQdbn3s000m47sAqWhK1QFtMafMccLSrwJQW64gc1OJnrmJgkqJ9iLmFi1fzHt00liAfPA6khvAtDSY8hdui+ytFqukVsl5fiwbQ5fD5ov5MVLjIm2HrZoi9pQoSwmiThGR8beof86fq2GXbbeUOOAqjVQM0Xlr\ -IZd9F7w/xG4aT+J4KJ64Jr6QihgGAi/hP272ufbEJlPcih01ch08273fkA+dUCeokmIm+55+Ov35NX66ptMnokWSmNf7fFPcRkr82kk1ZunZND7rPDI5/2yHfdeijijt3gGU/UTpXOcuunM7265j9rc89dwPwE+o\ -+lqV8AvrmAF3JBaLmFWVazdPImZsVodrBy5KLTcsq1wbcqoIS6GACxPv1FBsmGsG3KI1U+rOIZvLvwEY2owRarltB1bLM1/xhYCUKxoWL7GF/0WuJJMpXYGY+VeU98S4Q22LVmM8d9fDBnZ0xPFIme6cOYmARp68\ -A78nEVYj/ytoLVNIgPGb/BWEH4uUTf56ciUB1EmTp1UQpPchwgrrcfgQ9KWSkdSSq6QPv5M+A1Ey7RytI0zi0n1ZL+VyHVzlEcVNuueZTFomOgZuXRxsbCqhbqxzTDHmmtcuU9VrnW8hHLSicYTYmq6hJoTOS6sr\ -t7Jy1u3m9LygIefGnumpu4yUepZhGhqiO5o6eQAFAGjqYXSgYXdmYmcY3tiRxHWYtdMB3kRmq1L2REqYjQwI0lXpao+QXzyHjAcw3gFYbQRFj1YXDIVHle5A3NyJkaLdSqisbdQoHM5zCS4wDrCgy/P2oGeDqM6r\ -Olqbm81+rnaZktSQjrr9U+qyQ1v23P+MMdT2Bn0zjIYtSTOtEK4x6Xec1k61A5pI+WTYnbEzz4qtOqLMdSvyNX6OvVHE3kVU5XWCcqLQVvgatdDnuwNkKNwq4Prz84srofO606oyTB5Xi/aF9kqyLwKzpiHBGcQu\ -ZdqVQGZGCoa2Kw8O5nMmMidiVn/McVIYTJOX4FTDWPSWyaFwOdNDJ8tKYolc2HHcAtmvkShKTzQaQ151GWOkkfuwG0P4Wi347N25MpXy4VZUa4R3oOomiRJaldBJuykdARRN+5ukEtTZUO+1hnvGi4nJlJ4AHVH2\ -yM25nrgpHPZqPvevsdnaGmkiLsz1qZ90OpziUqToWkjTCLSr/jm7vSrcUU5mH3I73NdoQrb1EM0uV8+40m/rmRYx9YCHmkI2WFGdJN3LZRIagyYB/Lm+YLw0ImTV//iQOZ1qq3z4Pq7kL6RUNLNPcfQTyPkz6xVm\ -KpK7I16v1Qbi8scGHyTMyVqtIWtvDqXFkJPHyDmGZadpkltRlbGLtlslTu5rZlz1+Hhw1mo08AfdGNJEApoVbKwql1qznedi+zxArYlUugKWkwPaa93xRcaBbzuppxxhgGOb/oZ4UxWPusRDn+ixCx0b7LEROb6O\ -ZWReGwurUCiYJ+X3qPk3fi+Aj/o+Cvl0XMT23447YT+JCCYx2votFr3mWer6YLRspXcoWqwf/R2YTQYz+LQchOpZksMpnZNcppWnQeVFq9lnIYSRTqZDtnGtZ5zQQSk/iv7DI+rWS99Z6hc6v2kXQPJOqoFaLIY3\ -E6gOoqZ1oyk0pQkfNYeUI3nT/0rvlYIwkKTilcpHBYo2wRsXCZaQq6erGbKamvObTTlvMLKf6hbcrHmheSxHVNbIvpyvtOIZEQ9G8EBQ3YwiWxcbXNT8IHcJ619InkX/kSXMzwJqaW5FBa7J8Ucqzbeu/xV6fH7f\ -RWc6T9rDbvFjvdc4mOxpbipFflWsqoQWQGrvVkZUvtQ8xu9sHN72Q86Lr+JrCb7vR2sgCX/KL0potfobqYut1bhoVfT7iAI6PSTe7RlLxI9LJqH1n9fxGMrlHQPMQ7tM7qbjiKvJW05xl4ek0/gGEG8SjpH4D/S+\ -zroovk81xpQzqEg7hkjbCpezqqaUMLyOx62qQo4Q/iWh9UJ4VGobX14zgmjuVOcusthIUbMtoZC/Ud2/eAAr+m9dV5BDIbFSjveh9MU7VBHcAN0eUm3/9arVEdO/l3cqQi3XdNo16WVHv2ojM1oVgp8tvKWFKHp8\ -++UXqaRIPafS+LaE52sGcyUvOim4K67Nt4VXKCHoyxltHluO90PkWdxPYXZWKWGXGbDy9xceanIQLZoDSF6BYB0vW1ZSYfUdkd/1lFdBlPHLEiu6dvIuT7sjJ0T6JOX/KO/DhBfcl+RTh0Dweh6SxBVMeiCvHrSc\ -hV0dPEWX8jGLyCL/BYZYH/cO5GUWhlOR/iEVqnC4NpSsfvrCwYjky7Tpofeix/65LfkFVWgaPihPG3Csp/0igap6pwgTdC5KxZueuqRyaG06b2L4GLWI+uQlBnonhWim5AjVZHIAoJbC/7onDRSnrik5B0UWogtq\ -v+pBQh6Pfkw+DymLPkohuye1vRKdPmmWJyv4ZHc9bzlSlwJ+LfvEAKA0vCGEUEwqPiOAMckX+clAW/yJ9KGoPn7ZvgJeX+2HOFBlZ1tvENbeAD7/wOXjFrV89nz/BJdPJtNOD58owWx/s0bve/7rw7S8wluf1uR5\ -Ym2RmHCluZhefZoP9vu9IgzW5bTU10MBquBM2zLcncXYLHEmmf0PTRUSUg==\ +/2Y9/PHydEJPT27a+iynOXbDH/M8zN+fhtFkd3I1uWlM+NobVKONMHuxyQJUvcPJTd0bPT1cDw+atAyr9sIn3FsUg/CnP9meXGB6THYdZkjDj5bvcvksjIbFmyCwdeFLG674IHnV5pNtEuqP43BfHe6v+Nm2zfMl\ +F3TpIeuFthk+dZ3TNnk+CJ+JwnpzzYVP0JsLH9/H/2czkaU4xR4HEH4vrmPC/8INWQX3L+p2Z7I0rzDoyKArxd/WP4P2efaw3t2pYa4kH0E9wTiuz/MGcwYDOX+sK8PY4aEyPOzbt7llddo+G5lvt8VBWKQeh7nt\ +KECgDk82qoZkhGuwHq9SJWwiY06wbroLYUddxVme32F9GgtT5mEbTcY3EMIyxgR+O8dY0nGeRHXxkk2AJfG/yrfmKntKRhkGuZ3lKUw6xq3YTgk4QTbGOBYpGpmnIJ2uh5253mhBtaIa3YqHLofhrw2galIeLSyr\ +p8BiDvPbB/AAIMkwFnBb6053cFOcOkjn2QlVu4Xbx0hQby0jbX3Khoc2oG+by5Q2ylYZ+J+3MlmfoQb52gaTjtVpOsAIj2AfmXicEczZeIvuuLVxddijptVIMFoq7KbGUv7uFBDsV164yvcIm+IHuKNI9wA3Bub3\ +u/5Qdpbh7nEHydiVVxX1Ow4qXFbjbvzoMMhT3DLk+61ITrozuJLhSm8DBpepiwwA2eBFSt1+d3Jnz6M4tHwSF4Eug65bpQ3MSTSpNlL5S8yiaDS3NqOQp50v1wH9FiIxCZaeu5PQF29JEFjrD2yWl3rAVwIm2YhG\ +cAAj3qYXmbLuTtmIwLUgk2MNhYx7OYhiDL6ONbxQGHnBe+jSDwAHthBQlgBwuFQ5wmzQ2NcjuYJQ4rbYlW3/jDFOccQf+B/DNEZ/jvy/sFeYBnHkCTHvwWBLtNiwWzrRLugANEs+bZhIGn8rPGHDPtVNDshTJvTs\ +ZMD6CtNNSOYJGLPP23D5YMQERJFSQqOEyW50vEob9huN4p2gfP2txGTf7P6ioVN8R2Lksr3QfirhKpsySVS9MW+E0Juv7bBVGvttNwCNFZ6D+5cEBxStMCx8v7e3TI618AV8FAIcU6RmDkKQHUUMNYdRXyBKZ8rY\ +YApXLHa8ZMriAbK+y27EneczZgJkNwghXq4AIEX9mLEHdOF/ZZngC9xcbfAFZschwoljwmNlvGTCvDc+x9C/GFEALCPBpBe1ypS+zIwYq/vxbk93x3WtcAs/d94hs97tqEEUXsRosXJJG5fkKADtVnlMQCS94K0+\ +EtcV765SCf6QziUS/JfFXYN8yshdjLM9BDcinOtL0IedfcCl91g53RJjhi3UDW+0ltylLkWifAZglJwfCD1NWRmF5gciLARvyx0WlKlmncGpjLQM2tu3pzbpT3F+IoJyPGRG4xzlvBNz6QMxneiZBVkioBMBFx/v\ +rAaDpuur+O3dplz2dg9f4GL4ZlIfdVWVg0ewUjmaXASiarOz9g10++Zw7qggU+c/4Ca12fsjJljYoEhfrGbZco6vWyzb1AvTrH9+GkRDRBvnlHg3h++ZvRi9kC77kfl1TmOS7dzrOoQse3k5+/AaNPAGXPRPAKoS\ +gqH4uA4S3IJnHmEvCG4tSqoa8vR/YqZoBKCl2FRVvCBH789ct1RQbZUx/YAefO8zWweHpeceox950iKtFU+F1nKrAb8aL6CL2X+WT0hY9I+ZTwmA/u7NYdUrfoRYV9Mhe7gjRVt6O9fKb/kQZRJW8sF6hImQOiQh\ +3TSVv2T/IhKBXso010APoKZDeFaav2BklV+CLC8xD7M41MvO+d/fM1gqpVSH4qDtidzzK38astELkrH/UWpjGlmQ4fXnUxG/6CQnnIR9qcIQwbwE7QKh7RBBL0xS4h6nV9rPy1H1ZpJUQSlpwj+akp9s3I7/a0Q0\ +okzTeyJV+HJZaZCQ8AOn4xecjJOsKRhVq5F56ooKTlNXa8c8CI0ixWiT/zvBDibTH9PIsdffXj657e2rFU018CIbv3z0CiB8Nbk4g/CHP4FwyqOjY1w8fvQcF59PLk5A1W9POj2XKj8dHoImLqMFkPVhs4H2d8RJ\ +MuEoCaKlBFGQal1IkM0kyCad7yXlBfQs7ml6nGWhNMGzAAd2CA702epco/Sa9RW7oLKFQkjTJ01lMFaVshJmsclDGMTu/Ztzw4IVnjJ25sXZYmH14HyHQLcmmbAWZGkx0C4avnWFQOZk7L7Ws2rUeZPMpns0ncTE\ +pelw62OTbjIZ3wVIRVOqDmiLOWWOE5Z+FYDacgWZm0r0zE0UVEq0FzG3aPli3qOTxgLkg9eR3ACmpcGUv3BbZG+1WCW1Ss7zY9kYuhw2X8yPkRoXaTts1RSxp0RZShB1ioiMv0X9c/5cDbtsu6XEAVdppGKIzlsL\ +uey74P0hdtN4EsdD8cQ18YVUxDAQeAn/cbPPtSc2meJW7KiR6+DZ7v2GfOiEOkGVFDPZ9/TT6c+v8dM1nT4RLZLEvN7nm+I2UuLXTqoxS8+m8Vnnkcn5ZzvsuxZ1RGn3DqDsJ0rnOnfRndvZdh2zv+Wp534AfkLV\ +16qEX1jHDLgjsVjErKpcu3kSMWOzOlw7cFFquWFZ5dqQU0VYCgVcmHinhmLDXDPgFq2ZUncO2Vz+DcDQZoxQy207sFqe+YovBKRc0bB4iS38L3IlmUzpCsTMv6K8J8Ydalu0GuMT/lHVOzrieKRMd86cREAjT96B\ +35MIq5H/FbSWKSTA+E3+CsKPRcomfz25kgDqpMnTKgjS+xBhhfU4fAj6UslIaslV0offSZ+BKJl2jtYRJnHpvqyXcrkOrvKI4ibd80wmLRMdA7cuDjY2lVA31jmmGHPNa5ep6rXOtxAOWtE4QmxN11ATQuel1ZVb\ +WTnrdnN6XtCQc2PP9NRdRko9yzANDdEdTZ08gAIANPUwOtCwOzOxMwxv7EjiOsza6QBvIrNVKXsiJcxGBgTpqnS1R8gvnkPGAxjvAKw2gqJHqwuGwqNKdyBu7sRI0W4lVNY2ahQO57kEFxgHWNDleXvQs0FU51Ud\ +rc3NZj9Xu0xJakhH3f4pddmhLXvuf8YYanuDvhlGw5akmVYI15j0O05rp9oBTaR8MuzO2JlnxVYdUea6FfkaP8feKGLvIqryOkE5UWgrfI1a6PPdATIUbhVw/fn5xZXQed1pVRkmj6tF+0J7JdkXgVnTkOAMYpcy\ +7UogMyMFQ9uVBwfzOROZEzGrP+Y4KQymyUtwqmEsesvkULic6aGTZSWxRC7sOG6B7NdIFKUnGo0hr7qMMdLIfdiNIXytFnz27lyZSvlwK6o1wjtQdZNECa1K6KTdlI4Aiqb9TVIJ6myo91rDPePFxGRKT4COKHvk\ +5lxP3BQOezWf+9fYbG2NNBEX5vrUTzodTnEpUnQtpGkE2lX/nN1eFe4oJ7MPuR3uazQh23qIZperZ1zpt/VMi5h6wENNIRusqE6S7uUyCY1BkwD+XF8wXhoRsup/fMicTrVVPnwfV/IXUiqa2ac4+gnk/Jn1CjMV\ +yd0Rr9dqA3H5Y4MPEuZkrdaQtTeH0mLIyWPkHMOy0zTJrajK2EXbrRIn9zUzrnp8PDhrNRr4g24MaSIBzQo2VpVLrdnOc7F9HqDWRCpdAcvJAe217vgi48C3ndRTjjDAsU1/Q7ypikdd4qFP9NiFjg322IgcX8cy\ +Mq+NhVUoFMyT8nvU/Bu/FMBHfR+FfDouYvtvx52wn0QEkxht/RaLXvMsdX0wWrbSOxQt1o/+Dswmgxl8Wg5C9SzJ4ZTOSS7TytOg8qLV7LMQwkgn0yHbuNYzTuiglB9F/+ERdeul7yz1C53ftAsgeSfVQC0Ww5sJ\ +VAdR07rRFJrShI+aQ8qRvOl/pfdKQRhIUvFK5aMCRZvgjYsES8jV09UMWU3N+c2mnDcY2U91C27WvNA8liMqa2Rfzlda8YyIByN4IKhuRpGtiw0uan6Qu4T1LyTPov/IEuZnAbU0t6IC1+T4I5XmW9f/Cj0+v++i\ +M50n7WG3+LHeaxxM9jQ3lSK/KlZVQgsgtXcrIypfah7jdzYOb/sh58VX8bUE3/ejNZCEP+UXJbRa/Y3UxdZqXLQq+n1EAZ0eEu/2jCXixyWT0PrP63gM5fKOAeahXSZ303HE1eQtp7jLQ9JpfP2HNwnHSPwHel9n\ +XRTfpxpjyhlUpB1DpG2Fy1lVU0oYXsfjVlUhRwj/ktB6ITwqtY0vrxlBNHeqcxdZbKSo2ZZQyN+o7l88gBX9t64ryKGQWCnH+1D64h2qCG6Abg+ptv961eqI6d/LOxWhlms67Zr0sqNftZEZrQrBzxZe0UIUPb79\ +8otUUqSeU2l8W8LzNYO5khedFNwV1+bbwiuUEPTljDaPLcf7IfIs7qcwO6uUsMsMWPn7Cw81OYgWzQEkr0CwjpctK6mw+o7I73rKqyDK+GWJFV07eZen3ZETIn2S8n+U92HCC+5L8qlDIHg9D0niCiY9kFcPWs7C\ +rg6eokv5mEVkkf8CQ6yPewfyMgvDqUj/kApVOFwbSlY/feFgRPJl2vTQe9Fj/9yW/IIqNA0flKcNONbTfpFAVb1ThAk6F6XiTU9dUjm0Np03MXyMWkR98hIDvZNCNFNyhGoyOQBQS+F/3ZMGilPXlJyDIgvRBbVf\ +9SAhj0c/Jp+HlEUfpZDdk9peiU6fNMuTFXyyu563HKlLAb+WfWIAUBreEEIoJhWfEcCY5Iv8ZKAt/kT6UFQfv2xfAa+v9kMcqLKzrTcIa28An3/g8nGLWj57vn+CyyeTaaeHT5Rgtr9Zo5c9//VhWl7hlU9r8jyx\ +tkhMuNJcTK8+zQf7/V4RButyWuq7oQBVcKZtGe7OYmyWOJPM/gf0hhEn\ +"""))) +ESP32H2BETA2ROM.STUB_CODE = eval(zlib.decompress(base64.b64decode(b""" +eNrNWmtb20YW/isECLTZ24yt26QbsFMbY0iyaTcpSx/TVhpJbLotz0JMQ3br/77znoskG+zk434w2KPRmTNn3vOei/Tf/Xl1N99/ulXsz+6Mnd3Z8CnS8B0f89PJ7M5n4Vt/dpe72V1Go3thMH8V/iTfhj9RGErC\ +/2o7/PFyd0R3z+7q8jwlGYfhj3kR5PfnYTQ6nN3M7ioTvvYGxWgnSM92WYGiN53dlb3R8+l2uNHEeVi1Fz5hbpYNwp/+bH92BfEQdhskxOFHzbNcugijYfEqKGxd+FKHKz5oXtTpbJ+U+v00zCvD/ILvres0XXNB\ +lx6yXWib4VOWKW2T5UH5RAzWaywXPsFuLnx8H/+/Xogu2Rn2OIDy43YdE/5nbsgmeHhRd7iQpXmFQUcHXan9bf3XsD5LD+vdF43jitIRzBMOx/VZbjjOcEDOn+rKOOxwUx5u9vVFatmcts+HzNNtdhwWKSdBth0F\ +CJThzkrNEI1wDafHqxQRH5ExL7FufAhlR13DWZbvsD6NBZFp2EaV8ARCWMKYwG/nGEs6zkLUFq/5CLAk/hfpXmOy53Qow6C3syzCxBNMxXZywAm6McaxSFaJnIxsuh125nqjJdOKaXQrHrYchr82gKqKeTSzbJ4M\ +iznIt4/gAUCSYSxgWu3ODjCpFR208+yEat3MHWEkmLeUkbo844OHNWBvm4pI2+pWGPiftyKsz1CDfnUFoRN1mg4wwi3YRyIeZwRztp2iO65tuzrOo6TVSDFaKuymxFL+vggo9isvXKRjwqb4AWZk8RhwY2B+c+in\ +srMEsycdJGNXXk3U7ziocFmJ2fjRYZDnmDLk+VY0J9sZXElwpbeDAxfRWQKA7PAiuW6/K9zZy1YdWj5qF4Etg61rpQ3IJJrUM1L9c0hRNJqVzSjkaefrbUC/hUhMhKUbdxL64i0JAkv9gc3yUo/4SsAkH6IRHOAQ\ +V+lFRJZdkZUoXAoyOdZQyHiQgyjG4OtEwwuFkVe8hy79AHBgCwFlDgCHS4UjzAaLfTmSKwglbo9d2fbPGeMUR/yxfxvEGP058j9irzgaxJFnxLzHgz2xYsVu6cS6oAPQLPk0mKXyK7EJu/Wx7nBAbjKjG2cDNlaQ\ +NSOFZ6DLPu/BpYMRsw+FSYmLEiO7ofEmrthpNIR3IvLtVxKQfXX4i8ZNcRwJkA9vhMeqQojKxswQRW/CGyHoplsHfCSV/aobfSaKzcHDS4IAslroFY7fG6/XgwAEtIcAxxSpmYMQZMcWQ81h1BeI0pkydpjCFYsd\ +L5mzhoCs77IbceflgpkA2Q1CiJcrAEhWPmXsAV34X1gm+AyTix2+wOw4RDhxTHhsj9dMmA/G5zb0L0cUYMtIMOm1hmVKX2dBeELZme1pdruuFW7h+y5FCCxyL2oQhWdttNi4ZOfkOQrAukXaJiCSXvBWn4jrincX\ +sQR/aOciCf7r4q5BPmVkFkNtjOBGhHN7Dfqwi/e49A4rx3tymGELZcXWKSV3KXPRKF0AGDnnB0JPczZGpvmBKAvF6/yAFWWq2WZwKiOtoYudVckm/rkVT1SQT4ZMaJyiXHZCLn2gpRMzsx5r9HOi3/LtndVwnvH2\ +JnqDA27JDG/H+AInwzcT+9ZaRT54gnPKR7OrwFZ1cl5/D+t+P21cFXTq/HtM0lN7d8IUi1PI4lebFNlScK7wbFUuyfjEZmBR5GYINogLTL27w3fMXwxeqJa8ZYZtiEySnQc9BzmEt9fXi/ffgQW+BxX9ADwVwi8U\ +HrdBg8EIZf8Ee0Fsq1FRlagT+j8zUVSCz1zOVO27pEfvz1y2FLBrkTD7gB187xNbB2LiS4/RDyw0i0vFU6al3Ga8fxIvyJoX/1kvk+DonzKjEgb9/clh4Ru+hXhXEyI7PZCyLV7NttIVN6JcwkpGWI4gCMlDFBJO\ +U/hrdjGiEaicx6mGegA1HpKp0lcMrvxzwEWBz7AUh4rZOf/bO8ZLoaTqUB7UPdG7ufKHIZ97Rjr2P0h1TCNLOnz3iWTELzvJS87BPtdaCGBewnaGyDZFzAtCcsxxeqX+NASK3kJyKjhHHPGPKuc7K3fg/9YiGkGm\ +6j2TIny9rjRIMPiWs/ErzsVJ1xiMqsVIk7migNPM1doJD8KclQMY/g8Ilku9t3HLsrdfXT9bdfkNvGj698j49ZM3wOCb2dU51J/+DMrJT05OcfH0yQtcfDG7egmmvnjZaboU6dlwen7dHgDSPuw1UP6BOIiQbY4Q\ +Gkny32NOLQX+XkKslxBL13LWHTCnFLLHyS4KExAXsOHNFU/YlGbkhSZ82SFobKkG0sxJsxiMFcB0JV0KGz3GYdjxPzktzNjOMeOmqcuWa6pHlwcEuC3Jg7UWi7OBNtDwrasEkiZjj7SU1bNs+mM2HpM4CYZrHbpu\ +d/XTbDa5j4uCRKoNaIspEdGMtV+Lmzrd7MLEV1TdUv8ERRLtJefzFCtfNe056SlAP3gcWQ6QtDQY8xfuiIw3bDinFslleiq7QnfDpst5MWg2i+threfQ9pIoNwl6zhGK8Tcr/5W+0FPdEBxzqfVcoSGK8dt0FVLZ\ +d8b7Q9ym8agdD6UTl8NXUgwTX1o+KEoTUm2HzeaYSmWWXM/7y/PxKZOX1AQqpI5JvqGfTn9+iZ+u6rSIaJGo7U/4dFcKYqnuSye1mKV74/Ze55HC+a8P2Gltid3Z8Rew9zOlcpWddWU7W29D+gWLbvwAPQfUfLVq\ ++NklDEm9V8I8PHuwnCNR2lxtJlyHciW23Kss0p0W8bwdCgNck3inB8UHc8uYWz7NWBtzPn0CMNQJg9Ryx64iw/mCLwSk3LTz0WXzv8iVaDanK5kaFxFYYw51LGqN7xH/KMoDHXE8kscH506in5E778HvWQur5/5X\ +kEGkkADdV+m3UJ5+EkLezG4keDrp79QKgvghRFhhPY4dgr5YspFS8pT48V+ly0CUfCSLUyuJsHkkS8Y8CLL0COImHnvuJhAdV4LdMjve2VVO3dnmmEJlpJTseazHEfJxBIVa7I74Wh6JSUo0jXOri9eyeNLt6PSw\ +finrJ+qsGBspB21ANkxFk6oyegRLAHHqavRQwx4s5MCBAGNHEtpxvowpL0VFXqqiPVEU50cniRhUS1e79Ij62QsE7WOc4jHobQSsjTYEicyjTHegb27FSNVuKWC+VJMxsHypMB4eCU2t4Btn0egrLZia2p6CLiM5\ +B51hF/xNuzlmp/V8lHI4JpoqPCXOo5LK+hOOAl5Mn3IbtqFzJy0HajekuzuMJVO0veM8IvM/5u1zj3uLeuNo+5QUaT1zeAOkfvNggublomLSXrJNb8UVfBVIzenQjO+gKh4/UR+a3oqfkAyRTSB4roODRqoXqdmK\ +EZI2OQkeM2wLWtln4/6dLKpj/MxO2k0QOtH8xLFX4occI950GWGkwXnajRF8rRTY9e5dmUtpsBK1KH0XmFVRq6FVDR3Dw8SjsbSKBWLUw2sTjd/7kUJ6Kt1UKhTF3JRrUnP2khdUczjKiCwXKze9PyFBGaLH5MoF\ +N/zqcqHFQzngoSoTf88p3EjT8GHN8PkIOJVXDMxKctOi/+ExkykVNOnwXbuMv5L6zCw+tqMfQYmfWMyYDxLd3AmvV2vTbtNt3txqUKQT2B0yp8OQRNE4MAqfzNcjCUgCbhIp7PMWuU/cubWdHbWznT/2Engktnp/\ +LOxVo+7I9FlDc3fOd1dVc7fyUyWnqyKkA59JilLajCvhuT4ziaTjIs/zilSqyLrJtI7Eu6xk+6k0hytpSpZK5fGYn65zzJvICCks8YSqZOyrSZQfPribZ/rQ7oNQhtTSaG1BAXaQi0knJEctvkmdurzAPb+xTmV9\ +PFq34uAHelbyD0A6GizgjvJ4Up/wOCNM5JXEa06asloTw0x8PRTrQ3bcUp88WunX0NPj/uMT6qFLN5hLC6T09VJY+Em6cla6GHhbgAiXWF1LPmbeD10DSZe+JMb6Qu+Rio1YrtATptpCfKrOBp5bB1VHmtEnnxly\ +jpKzj115FmDE6YsVxFjzShNNzqnYLkcsnuL8MjjEppTd9ndbla08+mo6E8SEYf0ryYLoPwK4Zh94GlMUS4ZEG6HpiXXDLkv75oErzug9dtotSqynPJeC8nglKOPB5voKZQmg9n7F4oT7TaqvUUwfiOXB+27aNwV8\ +34+2gBB/xu8uaCH5b7ISH1LlOtDw4rxJ29fhrZ6zRny75ABal3kdb0OwPPaHHNpldD9NRjyMLjiMrwlT5+3rOLzDISVa76k22Bar9ynxn3NHuI3mhgjdSlBhO80pyn/XPv5U+3H08K8JoVeSGkvB4f0tZ+4kO1bZ\ +WdJ2N/TM1rFVZd6Q/y4/FhX7166ry1TCby5P3GH05RlqC25K7g+p5v5ykwJbf+c0pQgFVtXpocTXHfvqAZnRprg3WnplCl5/uvoyipQ3ZJ4zoTVLYL5lJBfy4pEiu+CCeV+4BLSPIXpsmrbtv4cUys243U9mDtYi\ +aRigVPiH0389bOppmJxf29HBvOaGXWb1VY3f9GGrYidh197QQZNXauoDbgw2qKOgilI7CLxqHiHe0Gnpc4moXcHEx/IGQM052c3xc2j3VHqJpPJf4Pbbk96xvFPCEAoonXHioAmsdnesfvrCtygA1gRBPALrndHW\ +9yXnAGT8QA4RIZyyvlJ2S/3h3hniAeUBVEDpg49YnhybzusQopSTQllfJqAXQzR2IShVibTh9Zzwv4ykleHUH0vONCiEEEdQVNR2fsrdI11cYseyV9JLHD0psZXa9E6zPkUZZPd9bQ02o03EQY2YXFyvInBQ/Mk3\ +ro758Wd5BnYp7TYXfRQkJ6/30EJPUMkkaKIn0xpN9OTkCO6enO6hnE5e4DLa6L2LqtNGJxow+3/cohcuf3w/z2/w2qU1aRpZm0UmXKmu5jcfm8F+v5eFwTKf5/p+JjAVPGlfhrtSjE0iZ6LF/wCAbuTq\ +"""))) +ESP32C2ROM.STUB_CODE = eval(zlib.decompress(base64.b64decode(b""" +eNq1Wmt7E8cV/iuObXBC8/SZ0V4HgpFARrbBFFKCCxUNuzO7LklwYyMH00b/vfOei3YlWyb90A+ypdmZM2fO5T2X2f/szJrL2c7djXpnemns9NLGT13E7/iYd4fTS1/Gb8n0snLTy5JGb8fB6ln8k38f/6RxKI//\ +m834x8vqlFZPL9vwugCN6kH8Y55G+sksjqYPpufTy8bEr4NhPd6K1MttZqAeHEwvw2D88GAzLjRZFXcdxE+cW5bD+CeZ7kxPQR7ELiKFLP5oeZYr5nE0bt5Ehq2LX9r4xEfO67aY7hBTvz+J80KcX/Pati2KNQ90\ +6xHLhY4ZPyEUdEymB+ZzEdhgIbn4iXJz8eMT/H80F17KY5xxCOb3un1M/F+6EYvg+k3dg7lszTsMezzoTt1v6x9B+kw97neVNNSVFuP4t47KcQnTjeqMCnL+ie4MZcdFVVzs27eFZXHahJXM0225HzcJk0jbjqMJ\ +hLiyUTGkYzyD9niXOmUVGXOEfbMHYHbcF5xl+g7701gkWcRjNDlPIAvL2Sbw2zm2JR1nIiqL56wCbIn/dXF7IbKHpJRR5NtZJmGyCabiOBXMCbyxjWOTshE6Jcl0M57MDcZLohXR6FE8ZDmKf200qibj0dKyeEps\ +5kDffgUPgCUZtgVMa93xLiZ1pCN3np1QpVu6xxiJ4g0y0oZjVjykAXnbQkjajrfawP+8FWIJmxr4axsQnajT9AwjLsE5cvE4IzZnuyl64tZ2u0MfgXYjxmireJqArfxVEmDsA29cF3tkm+IHmFFmezA3NswXD/yB\ +nCzH7EnPknEqryJKeg4qWBYwGz96CPIQU0Y83wrnJDuDJzmeDLagcCFd5jCQLd6k0uP3iTt70rFD26fdJpBllHWrsAGaBJOqI+W/AhW1RrNyGDV5Ovl6GdBvARKTYuuFOwl88ZHEAoP+wGF5q6/4SbRJVqIRO4AS\ +V+FFSIY+yUYYDmKZHGsoZFyLQRRj8HWi4YVC0TM+Qx9+YHBACzHKCgYcH9WObDZK7JuxPEEocbfZlW3ymm2c4ojf9z9EMkZ/jv2POCtUgzhyn5B3f3hbpNiwWzqRLuAAMEs+beS8YSU84cA+00MOyVOmtHY6ZHlF\ +clPieQrETPgYrhiOGYAoUkpolDDZj47nWcN+o1G8F5Qv7klM9s2DXzR0YvmYGV93EMiv8QJUNmOEqAcTPgWZbrGxyypp7L1+9JmobQ6v2Q/eX7aCrfD6wd46JiKxpoI4CgFHzRkEGnsiGGn2ol5AYM5gscXgrVbY\ +848Z8wZj9X1cI9Q8mTMGIK9B8PDyBKZRhrtsdbAr/K8tQ3uJyfUWP2BcHCGQOIY6lsRzhsprI3MX9JdjCfzWSBgZKCEF85t0GHqzPc3u9rWCKrzuRIhAIlfiBYF32cWJG7c03ZaM/5BuXXSphyQWfNQ74rTi13Um\ +YR/cuVTC/rqIa5BJGZlFASHdK9gF6+LiDMBh5x/x6D12zm6LMuMRQsPSCZK1hEo4KuYwjIozAwGmGQuj1MxAmAXjbbXLjDLIbLJxKha5AlKpr0EJv0rcZD91OxAIVJMRoxnnJye9eEuf+UWPlUxskwgIS8vTV/jP\ +ZFEcqyDObJeN2QGiVlmmJEsP5+0evsDP8M1kvhNYXQ3vQFXVeHoacarNX7dvIOA3BwtvBZY6/xGTVHHvDxlfoYgye3YTyL5To15B2CYs0dhUGmsOU3kOM4gIjLjbo/eMXCwd8JX/wMCq8tI051rPQfbg7dnZ/OMr\ +bPkGQeYfsKda8IUC4yYwMEogJIdwNES1FrVUQIWQ/MRA0Yh9kklVnXCX+Bj8mQuWGkKtc0YfoIMf3BSgKPs88Rj6xBTLLMDkF+lK+kVjXwjXXC/cEOb/Xk+QrNLfZXutG06EVyfHXc95SWfVUPTBrpRq2WqGVax4\ +D+UPVrLAgPiDfdo0Jpmm9mfsWQQg8McqKzS8wz6zEblH8YxtqvqiTXG+xiQcSmTn/G/v2UxqxVKHeqAdCNOLJ38asbpLYjD5JOUwjSwx8OrL2Ydf9o0jzrv+qLS22DGghLZETDtAtItEKsxx+qT9Mh/1YC55FNwi\ +S/kHAjpWNm7X/6WzZYSXZnBfCu/1vNIgmcH3nIGfcv5NvGYAUi1AFtkqijbNVq2d8CAk2jgYw/8TVwVPGVzXmA0Cpmt+yDpkvbh3dn/V09eLujHbVwD4+Z2XsMGX09PXYOPgJyBNdXj4BA+f3HmKh0+np0dA57dH\ +vS5LXRyPDpCunHUKQKoHz49IvysOkgs4SfCsJHgCTUMpwTWX4Jr2vlecG2At5jQDzq5QjGAtbAPHA/j5/OYco6o126seAMaWSh9NmzSFwVgNs26kGrHpLejD7v2Tc8KSpZ2x6SzKseVS6quTXbK5DUl/tQTLyqH2\ +zfDN2MfLnFhNOjPV6KItZrM9Iidh8PoDb0C1XVtuOp2sWkfxpCcAOl9B6eKUWV9vOswcyZFy97L8EcLYw9gh0TyD11dcAdgk4y838lohjqFuRSPCFsuJLHLYMmtHrcqua/tQJhEPMCMfmQF2fi6eqibW7laJcMX+\ +RO2n2iYkNK415LC9LToDhawpGSEQgWk87cZj+cMl7akUtPBFYAz+U8AvtKU1nWEqTtvIc2Bmf74hhziiRk4tFUn+gn46/fkNfrqm1+ahTdKux+CLbYk2UqEHJyWVpbVZt9Z5ZGL+0S454vk9RKi9fVZDBawwfeJl\ +n7iz7SbIv2XaC4NG4wC1W6ss/k/ViLtSjaybbVZmUwa8tvAYMvT5zHHDsS60oaaSwGGLD/zUO9UUa+aCrXFZnRl112DMxbewhjZnuVluuwGjipzQPCdTOafhTEiU/hd5kk5n9AQ8F19TBtMFF2o7tBqwsW/7Ptef\ +iJ3ti/zISiAzsuaK5d3vLGrsPwCecrUGIHdTvATbE+GvKV5NzyUOOgHEVtWfXWcLVtCLw4AYXiaJRZDSlgA1lT4B/aBjo+8DOi57LFtmXHED9Dziscn2PK9vGbbYbEO5v7Wt2Li1yeHBmAvevspUqKG4DWRvRdwI\ +lYGeoayDwCurO7eyc95vxQy8mELBXTkjUcsiY2RQusGgISeaFMJ3kLmbzlznZXQjcSufi6KheWPHEqZb+GDXwt1GkqqcDoRTyJP0iOCuHAaPCF4+BZ/70OE+cG0MYY9vRvuyQbHtgOPcUJHa20rkC7aTKtzNcyUt\ +dhytgx4v+nuelaJyr0Once4W+4XohSSJIRv3G6DUJoe07In/GWMo0Q0aXxiNR5JuGKHPIPuOM9SZ9i9TqYEMOzNlwCzVusfHQrDCXOMXxjfujO+0k2PzHcqCUhvZG9QAXxxtILnEwuKSxe3DuaB56LWbDEPH+bJy\ +IbqKlGvqLqWI3iBKqbI+B0IZ6RSapjw4XNBMhSZCVjLhECr4tchBPJonWrlW6YEgOUNEL2NKuzq3tJPuCKS8RoIorWg0grzso8ZYg/pBP4LwsyDGObjyZCaVwEpQawR7IOom7Ti0yqGTllE2hlE07a+SZVBjQt0X\ +9ufDUhfhHk0HGFEaiDUhuysOClc9XxD+0LVKWyNdwKVq53OS9lqU4kwk5SCoacSo6+SEHV6l7Sj5sre4k90GdBHbMEK3yoU5tw7bMNe6Igx5CIqm09VU70j78XoOh5dAM5A5ZUtphMM6+XSLEZ0KpGL0vtvGn0q9\ +Z+afu9HPwOUbN8M5L4Rtd8j7tdr+u2kZQXuTdBG/NaTq7ZH0CQpyF7mCsOwxTboSUNlw0TWrxcOh9rrt3L2782o1Fvj9fgRpOuhBkWhYX3UhZWO7SMUe8wC1GDIp8C2nBnTi0PNFNgXf9jJPuYAAwDbJlnhT3V1U\ +iYfe10sTavrvsSo5wE5kZFHmCqoQ56Xa/jUGcc5X+nxR90nAxzBPLaUjbye90J92RkxstOEtNr1gKiHsj9ertaEyxPrx32C56XAOt5abTL0Mcrhmc5LStEIAaF62mn6Wghmxxh+xpoNeUkIMlfwok1uH1HSX9rHc\ +bNIFTLtkKu+kHgiiNLxaQFUE9Z4bTaIpVfikSaQgiEm+1rlS70WcVKulalBtRXvZjeswluxXr0dzZDaBc5xtuTYwcp56xeKseaaJrCAaSeQxk6d8YtkkjJgEWet2x7KV+7FFi4OcJu5/KrkW/UeWoJk4Xd0lSwLc\ +kFuMTPpofS8s9f77uofO9Fbag375Y73XUJjuaYoqLxTU5U210JKd2qu1EdUvgcf4pYuDVVfk9Pi8e6/AJ36M4tv6Y37TQWvZX0lcrK3GdVpF945QoNch4tO+Zo54uSQTWgF6He+iubwkADp0yvRqVo7Qmr7lNHd9\ +YDru3t/hQ8IxUv+RXrjZFMEnVIPMOInqkMcQelt5/4ZFNaOc4VV3X6oi5FDhn5O1ngqaGvY6X12wBRHtTGmXedcXUbVdf5KNv1JXYPkGVeTfuj4jB4JjldzPQ+jLM1QQ3M7cGVF1/81Nu797IW9ExEqu6bVesrOe\ +cFVB5gYoLM2jpResEEufrL66ItUUyeZYGtiWjPmCLbmW15TUsmuuzHcEVCgnSOSeteh6h9eca9zrV5rdtcIfMvDV/vp6QzUNXrAKaSsMl8f/xXorrb7Y8Zte0Krh5PyGww2NN3kBp92Vqx1dSWk/3vqKBE8X147n\ +BOp6nZF2O5hs32uWxan6/kM0Gu+y+vQcDeUKm5PBvryEog3c36U4FejWTpLVTyLQixi+PsmB2AbsljuSWUB4XqMG5WlDjvJ0ZCRQ9eAY0YFuNalm03uTTK6cTe8NCt8FK0I8efmA3iUhdKk4MDW5dPH15OjchUQa\ +J049UrINCiiEEmjXNnobUHSXN6ZYRJJl16RIPZCyXvFNV5r1aQq1Sq/63BozTdY+KT6zAVAC3pCFUBwqv7B7adI/5CGgrF36VPpPVBY/b1/CZF8+jvBf569vv0E0ewPz+TseP2lRwudPHx/h8dF01uvEE0Gz8+0G\ +vaT548dZdY5XNa0pitTaMjXxSXM6O/+8GEySQRkHQzWr9J1OGFX0px0Z7lMxA5e5Ip//FwVa/vk=\ """))) diff --git a/tools/gen_crt_bundle.py b/tools/gen_crt_bundle.py new file mode 100644 index 00000000000..87e29e61fa4 --- /dev/null +++ b/tools/gen_crt_bundle.py @@ -0,0 +1,227 @@ +#!/usr/bin/env python +# +# ESP32 x509 certificate bundle generation utility +# +# Converts PEM and DER certificates to a custom bundle format which stores just the +# subject name and public key to reduce space +# +# The bundle will have the format: number of certificates; crt 1 subject name length; crt 1 public key length; +# crt 1 subject name; crt 1 public key; crt 2... +# +# Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http:#www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import with_statement + +import argparse +import csv +import os +import re +import struct +import sys +from io import open + +try: + from cryptography import x509 + from cryptography.hazmat.backends import default_backend + from cryptography.hazmat.primitives import serialization +except ImportError: + print('The cryptography package is not installed.' + 'Please refer to the Get Started section of the ESP-IDF Programming Guide for ' + 'setting up the required packages.') + raise + +ca_bundle_bin_file = 'x509_crt_bundle' + +quiet = False + + +def status(msg): + """ Print status message to stderr """ + if not quiet: + critical(msg) + + +def critical(msg): + """ Print critical message to stderr """ + sys.stderr.write('gen_crt_bundle.py: ') + sys.stderr.write(msg) + sys.stderr.write('\n') + + +class CertificateBundle: + def __init__(self): + self.certificates = [] + self.compressed_crts = [] + + if os.path.isfile(ca_bundle_bin_file): + os.remove(ca_bundle_bin_file) + + def add_from_path(self, crts_path): + + found = False + for file_path in os.listdir(crts_path): + found |= self.add_from_file(os.path.join(crts_path, file_path)) + + if found is False: + raise InputError('No valid x509 certificates found in %s' % crts_path) + + def add_from_file(self, file_path): + try: + if file_path.endswith('.pem'): + status('Parsing certificates from %s' % file_path) + with open(file_path, 'r', encoding='utf-8') as f: + crt_str = f.read() + self.add_from_pem(crt_str) + return True + + elif file_path.endswith('.der'): + status('Parsing certificates from %s' % file_path) + with open(file_path, 'rb') as f: + crt_str = f.read() + self.add_from_der(crt_str) + return True + + except ValueError: + critical('Invalid certificate in %s' % file_path) + raise InputError('Invalid certificate') + + return False + + def add_from_pem(self, crt_str): + """ A single PEM file may have multiple certificates """ + + crt = '' + count = 0 + start = False + + for strg in crt_str.splitlines(True): + if strg == '-----BEGIN CERTIFICATE-----\n' and start is False: + crt = '' + start = True + elif strg == '-----END CERTIFICATE-----\n' and start is True: + crt += strg + '\n' + start = False + self.certificates.append(x509.load_pem_x509_certificate(crt.encode(), default_backend())) + count += 1 + if start is True: + crt += strg + + if(count == 0): + raise InputError('No certificate found') + + status('Successfully added %d certificates' % count) + + def add_from_der(self, crt_str): + self.certificates.append(x509.load_der_x509_certificate(crt_str, default_backend())) + status('Successfully added 1 certificate') + + def create_bundle(self): + # Sort certificates in order to do binary search when looking up certificates + self.certificates = sorted(self.certificates, key=lambda cert: cert.subject.public_bytes(default_backend())) + + bundle = struct.pack('>H', len(self.certificates)) + + for crt in self.certificates: + """ Read the public key as DER format """ + pub_key = crt.public_key() + pub_key_der = pub_key.public_bytes(serialization.Encoding.DER, serialization.PublicFormat.SubjectPublicKeyInfo) + + """ Read the subject name as DER format """ + sub_name_der = crt.subject.public_bytes(default_backend()) + + name_len = len(sub_name_der) + key_len = len(pub_key_der) + len_data = struct.pack('>HH', name_len, key_len) + + bundle += len_data + bundle += sub_name_der + bundle += pub_key_der + + return bundle + + def add_with_filter(self, crts_path, filter_path): + + filter_set = set() + with open(filter_path, 'r', encoding='utf-8') as f: + csv_reader = csv.reader(f, delimiter=',') + + # Skip header + next(csv_reader) + for row in csv_reader: + filter_set.add(row[1]) + + status('Parsing certificates from %s' % crts_path) + crt_str = [] + with open(crts_path, 'r', encoding='utf-8') as f: + crt_str = f.read() + + # Split all certs into a list of (name, certificate string) tuples + pem_crts = re.findall(r'(^.+?)\n(=+\n[\s\S]+?END CERTIFICATE-----\n)', crt_str, re.MULTILINE) + + filtered_crts = '' + for name, crt in pem_crts: + if name in filter_set: + filtered_crts += crt + + self.add_from_pem(filtered_crts) + + +class InputError(RuntimeError): + def __init__(self, e): + super(InputError, self).__init__(e) + + +def main(): + global quiet + + parser = argparse.ArgumentParser(description='ESP-IDF x509 certificate bundle utility') + + parser.add_argument('--quiet', '-q', help="Don't print non-critical status messages to stderr", action='store_true') + parser.add_argument('--input', '-i', nargs='+', required=True, + help='Paths to the custom certificate folders or files to parse, parses all .pem or .der files') + parser.add_argument('--filter', '-f', help='Path to CSV-file where the second columns contains the name of the certificates \ + that should be included from cacrt_all.pem') + + args = parser.parse_args() + + quiet = args.quiet + + bundle = CertificateBundle() + + for path in args.input: + if os.path.isfile(path): + if os.path.basename(path) == 'cacrt_all.pem' and args.filter: + bundle.add_with_filter(path, args.filter) + else: + bundle.add_from_file(path) + elif os.path.isdir(path): + bundle.add_from_path(path) + else: + raise InputError('Invalid --input=%s, is neither file nor folder' % args.input) + + status('Successfully added %d certificates in total' % len(bundle.certificates)) + + crt_bundle = bundle.create_bundle() + + with open(ca_bundle_bin_file, 'wb') as f: + f.write(crt_bundle) + + +if __name__ == '__main__': + try: + main() + except InputError as e: + print(e) + sys.exit(2) diff --git a/tools/platformio-build-esp32.py b/tools/platformio-build-esp32.py index fbbfcf3d8e5..fe6775d543d 100644 --- a/tools/platformio-build-esp32.py +++ b/tools/platformio-build-esp32.py @@ -24,7 +24,7 @@ # Extends: https://github.com/platformio/platform-espressif32/blob/develop/builder/main.py -from os.path import abspath, isdir, isfile, join, basename +from os.path import abspath, basename, isdir, isfile, join from SCons.Script import DefaultEnvironment @@ -100,6 +100,7 @@ "-u", "pthread_include_pthread_cond_impl", "-u", "pthread_include_pthread_local_storage_impl", "-u", "pthread_include_pthread_rwlock_impl", + "-u", "include_esp_phy_override", "-u", "ld_include_highint_hdl", "-u", "start_app", "-u", "start_app_other_cores", @@ -112,7 +113,7 @@ "-u", "newlib_include_pthread_impl", "-u", "newlib_include_assert_impl", "-u", "__cxa_guard_dummy", - '-Wl,-Map="%s"' % join("$BUILD_DIR", basename(env.subst("${PROJECT_DIR}.map"))) + '-Wl,-Map="%s"' % join("${BUILD_DIR}", "${PROGNAME}.map") ], CPPPATH=[ @@ -126,6 +127,7 @@ join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp_hw_support", "include", "soc"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp_hw_support", "include", "soc", "esp32"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp_hw_support", "port", "esp32"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp_hw_support", "port", "esp32", "private_include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "heap", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "log", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "lwip", "include", "apps"), @@ -239,15 +241,14 @@ join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "ulp", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "wifi_provisioning", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "button", "button", "include"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "json_parser"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "json_parser", "jsmn", "include"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "json_generator"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "rmaker_common", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "json_parser", "upstream", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "json_parser", "upstream"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "json_generator", "upstream"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp_schedule", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp_rainmaker", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "qrcode", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "ws2812_led"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp_littlefs", "src"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp_littlefs", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-dsp", "modules", "dotprod", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-dsp", "modules", "support", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-dsp", "modules", "windows", "include"), @@ -273,28 +274,34 @@ join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-dsp", "modules", "common", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-dsp", "modules", "kalman", "ekf", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-dsp", "modules", "kalman", "ekf_imu13states", "include"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-face", "include"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-face", "include", "tool"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-face", "include", "typedef"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-face", "include", "image"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-face", "include", "math"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-face", "include", "nn"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-face", "include", "layer"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-face", "include", "detect"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-face", "include", "model_zoo"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp_littlefs", "src"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp_littlefs", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-dl", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-dl", "include", "tool"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-dl", "include", "typedef"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-dl", "include", "image"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-dl", "include", "math"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-dl", "include", "nn"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-dl", "include", "layer"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-dl", "include", "detect"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-dl", "include", "model_zoo"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-sr", "esp-tts", "esp_tts_chinese", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp-sr", "include", "esp32"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp32-camera", "driver", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "esp32-camera", "conversions", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "include", "fb_gfx", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32", env.BoardConfig().get("build.arduino.memory_type", "qspi_qspi"), "include"), join(FRAMEWORK_DIR, "cores", env.BoardConfig().get("build.core")) ], LIBPATH=[ join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "lib"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "ld") + join(FRAMEWORK_DIR, "tools", "sdk", "esp32", "ld"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32", env.BoardConfig().get("build.arduino.memory_type", "qspi_qspi")) ], LIBS=[ - "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lasio", "-lbt", "-lcbor", "-lunity", "-lcmock", "-lcoap", "-lnghttp", "-lesp-tls", "-lesp_adc_cal", "-lesp_hid", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lesp_lcd", "-lprotobuf-c", "-lprotocomm", "-lmdns", "-lesp_local_ctrl", "-lsdmmc", "-lesp_serial_slave_link", "-lesp_websocket_client", "-lexpat", "-lwear_levelling", "-lfatfs", "-lfreemodbus", "-ljsmn", "-ljson", "-llibsodium", "-lmqtt", "-lopenssl", "-lperfmon", "-lspiffs", "-lulp", "-lwifi_provisioning", "-lbutton", "-ljson_parser", "-ljson_generator", "-lesp_schedule", "-lesp_rainmaker", "-lqrcode", "-lws2812_led", "-lesp-dsp", "-lesp32-camera", "-lesp_littlefs", "-lfb_gfx", "-lasio", "-lcbor", "-lcmock", "-lunity", "-lcoap", "-lesp_lcd", "-lesp_local_ctrl", "-lesp_websocket_client", "-lexpat", "-lfreemodbus", "-ljsmn", "-llibsodium", "-lperfmon", "-lesp_adc_cal", "-lesp_hid", "-lfatfs", "-lwear_levelling", "-lopenssl", "-lspiffs", "-lesp_rainmaker", "-lmqtt", "-lwifi_provisioning", "-lprotocomm", "-lbt", "-lbtdm_app", "-lprotobuf-c", "-lmdns", "-ljson", "-ljson_parser", "-ljson_generator", "-lesp_schedule", "-lqrcode", "-lcat_face_detect", "-lhuman_face_detect", "-lcolor_detect", "-lmfn", "-ldl", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lphy", "-lrtc", "-lesp_phy", "-lphy", "-lrtc", "-lesp_phy", "-lphy", "-lrtc", "-lxt_hal", "-lm", "-lnewlib", "-lstdc++", "-lpthread", "-lgcc", "-lcxx", "-lapp_trace", "-lgcov", "-lapp_trace", "-lgcov", "-lc" + "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lasio", "-lbt", "-lcbor", "-lunity", "-lcmock", "-lcoap", "-lnghttp", "-lesp-tls", "-lesp_adc_cal", "-lesp_hid", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lesp_lcd", "-lprotobuf-c", "-lprotocomm", "-lmdns", "-lesp_local_ctrl", "-lsdmmc", "-lesp_serial_slave_link", "-lesp_websocket_client", "-lexpat", "-lwear_levelling", "-lfatfs", "-lfreemodbus", "-ljsmn", "-ljson", "-llibsodium", "-lmqtt", "-lopenssl", "-lperfmon", "-lspiffs", "-lulp", "-lwifi_provisioning", "-lbutton", "-lrmaker_common", "-ljson_parser", "-ljson_generator", "-lesp_schedule", "-lesp_rainmaker", "-lqrcode", "-lws2812_led", "-lesp-dsp", "-lesp-sr", "-lesp32-camera", "-lesp_littlefs", "-lfb_gfx", "-lasio", "-lcbor", "-lcmock", "-lunity", "-lcoap", "-lesp_lcd", "-lesp_websocket_client", "-lexpat", "-lfreemodbus", "-ljsmn", "-llibsodium", "-lperfmon", "-lesp_adc_cal", "-lesp_hid", "-lfatfs", "-lwear_levelling", "-lopenssl", "-lesp_rainmaker", "-lesp_local_ctrl", "-lwifi_provisioning", "-lprotocomm", "-lbt", "-lbtdm_app", "-lprotobuf-c", "-lmdns", "-lrmaker_common", "-lmqtt", "-ljson_parser", "-ljson_generator", "-lesp_schedule", "-lqrcode", "-lcat_face_detect", "-lhuman_face_detect", "-lcolor_detect", "-lmfn", "-ldl", "-lwakenet", "-lmultinet", "-lesp_audio_processor", "-lesp_audio_front_end", "-lesp-sr", "-lwakenet", "-lmultinet", "-lesp_audio_processor", "-lesp_audio_front_end", "-ljson", "-lspiffs", "-ldl_lib", "-lc_speech_features", "-lhilexin_wn5", "-lhilexin_wn5X2", "-lhilexin_wn5X3", "-lnihaoxiaozhi_wn5", "-lnihaoxiaozhi_wn5X2", "-lnihaoxiaozhi_wn5X3", "-lnihaoxiaoxin_wn5X3", "-lcustomized_word_wn5", "-lmultinet2_ch", "-lesp_tts_chinese", "-lvoice_set_xiaole", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lphy", "-lrtc", "-lesp_phy", "-lphy", "-lrtc", "-lesp_phy", "-lphy", "-lrtc", "-lxt_hal", "-lm", "-lnewlib", "-lstdc++", "-lpthread", "-lgcc", "-lcxx", "-lapp_trace", "-lgcov", "-lapp_trace", "-lgcov", "-lc" ], CPPDEFINES=[ @@ -303,7 +310,7 @@ "UNITY_INCLUDE_CONFIG_H", "WITH_POSIX", "_GNU_SOURCE", - ("IDF_VER", '\\"v4.4-beta1-189-ga79dc75f0a\\"'), + ("IDF_VER", '\\"v4.4.1-1-gb8050b365e\\"'), "ESP_PLATFORM", "_POSIX_READER_WRITER_LOCKS", "ARDUINO_ARCH_ESP32", @@ -312,7 +319,8 @@ ("ARDUINO", 10812), ("ARDUINO_VARIANT", '\\"%s\\"' % env.BoardConfig().get("build.variant").replace('"', "")), ("ARDUINO_BOARD", '\\"%s\\"' % env.BoardConfig().get("name").replace('"', "")), - "ARDUINO_PARTITION_%s" % env.BoardConfig().get("build.partitions", "default.csv").replace(".csv", "") + "ARDUINO_PARTITION_%s" % basename(env.BoardConfig().get( + "build.partitions", "default.csv")).replace(".csv", "").replace("-", "_") ], LIBSOURCE_DIRS=[ @@ -324,6 +332,12 @@ ("0x8000", join(env.subst("$BUILD_DIR"), "partitions.bin")), ("0xe000", join(FRAMEWORK_DIR, "tools", "partitions", "boot_app0.bin")) ] + + [ + (offset, join(FRAMEWORK_DIR, img)) + for offset, img in env.BoardConfig().get( + "upload.arduino.flash_extra_images", [] + ) + ], ) # diff --git a/tools/platformio-build-esp32c3.py b/tools/platformio-build-esp32c3.py index f0f86d5ba9e..1557a0806c7 100644 --- a/tools/platformio-build-esp32c3.py +++ b/tools/platformio-build-esp32c3.py @@ -24,7 +24,7 @@ # Extends: https://github.com/platformio/platform-espressif32/blob/develop/builder/main.py -from os.path import abspath, isdir, isfile, join, basename +from os.path import abspath, basename, isdir, isfile, join from SCons.Script import DefaultEnvironment @@ -48,7 +48,7 @@ CXXFLAGS=[ "-march=rv32imc", "-std=gnu++11", - "-fno-exceptions", + "-fexceptions", "-fno-rtti" ], @@ -66,6 +66,8 @@ "-Wno-format", "-Os", "-freorder-blocks", + "-Wwrite-strings", + "-fstack-protector", "-fstrict-volatile-bitfields", "-Wno-error=unused-but-set-variable", "-fno-jump-tables", @@ -82,35 +84,6 @@ "-fno-rtti", "-fno-lto", "-Wl,--undefined=uxTopUsedPriority", - "-Wl,--wrap=_Unwind_SetEnableExceptionFdeSorting", - "-Wl,--wrap=__register_frame_info_bases", - "-Wl,--wrap=__register_frame_info", - "-Wl,--wrap=__register_frame", - "-Wl,--wrap=__register_frame_info_table_bases", - "-Wl,--wrap=__register_frame_info_table", - "-Wl,--wrap=__register_frame_table", - "-Wl,--wrap=__deregister_frame_info_bases", - "-Wl,--wrap=__deregister_frame_info", - "-Wl,--wrap=_Unwind_Find_FDE", - "-Wl,--wrap=_Unwind_GetGR", - "-Wl,--wrap=_Unwind_GetCFA", - "-Wl,--wrap=_Unwind_GetIP", - "-Wl,--wrap=_Unwind_GetIPInfo", - "-Wl,--wrap=_Unwind_GetRegionStart", - "-Wl,--wrap=_Unwind_GetDataRelBase", - "-Wl,--wrap=_Unwind_GetTextRelBase", - "-Wl,--wrap=_Unwind_SetIP", - "-Wl,--wrap=_Unwind_SetGR", - "-Wl,--wrap=_Unwind_GetLanguageSpecificData", - "-Wl,--wrap=_Unwind_FindEnclosingFunction", - "-Wl,--wrap=_Unwind_Resume", - "-Wl,--wrap=_Unwind_RaiseException", - "-Wl,--wrap=_Unwind_DeleteException", - "-Wl,--wrap=_Unwind_ForcedUnwind", - "-Wl,--wrap=_Unwind_Resume_or_Rethrow", - "-Wl,--wrap=_Unwind_Backtrace", - "-Wl,--wrap=__cxa_call_unexpected", - "-Wl,--wrap=__gxx_personality_v0", "-T", "memory.ld", "-T", "sections.ld", "-T", "esp32c3.rom.ld", @@ -118,6 +91,7 @@ "-T", "esp32c3.rom.libgcc.ld", "-T", "esp32c3.rom.newlib.ld", "-T", "esp32c3.rom.version.ld", + "-T", "esp32c3.rom.newlib-time.ld", "-T", "esp32c3.rom.eco3.ld", "-T", "esp32c3.peripherals.ld", "-u", "_Z5setupv", @@ -127,6 +101,7 @@ "-u", "pthread_include_pthread_cond_impl", "-u", "pthread_include_pthread_local_storage_impl", "-u", "pthread_include_pthread_rwlock_impl", + "-u", "include_esp_phy_override", "-u", "start_app", "-u", "__ubsan_include", "-u", "__assert_func", @@ -137,8 +112,7 @@ "-u", "newlib_include_pthread_impl", "-u", "newlib_include_assert_impl", "-u", "__cxa_guard_dummy", - "-u", "__cxx_fatal_exception", - '-Wl,-Map="%s"' % join("$BUILD_DIR", basename(env.subst("${PROJECT_DIR}.map"))) + '-Wl,-Map="%s"' % join("${BUILD_DIR}", "${PROGNAME}.map") ], CPPPATH=[ @@ -263,28 +237,64 @@ join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "openssl", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "spiffs", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "wifi_provisioning", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "button", "button", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "rmaker_common", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "json_parser", "upstream", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "json_parser", "upstream"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "json_generator", "upstream"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp_schedule", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp_rainmaker", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "qrcode", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "ws2812_led"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dsp", "modules", "dotprod", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dsp", "modules", "support", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dsp", "modules", "windows", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dsp", "modules", "windows", "hann", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dsp", "modules", "windows", "blackman", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dsp", "modules", "windows", "blackman_harris", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dsp", "modules", "windows", "blackman_nuttall", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dsp", "modules", "windows", "nuttall", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dsp", "modules", "windows", "flat_top", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dsp", "modules", "iir", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dsp", "modules", "fir", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dsp", "modules", "math", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dsp", "modules", "math", "add", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dsp", "modules", "math", "sub", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dsp", "modules", "math", "mul", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dsp", "modules", "math", "addc", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dsp", "modules", "math", "mulc", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dsp", "modules", "math", "sqrt", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dsp", "modules", "matrix", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dsp", "modules", "fft", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dsp", "modules", "dct", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dsp", "modules", "conv", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dsp", "modules", "common", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dsp", "modules", "kalman", "ekf", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dsp", "modules", "kalman", "ekf_imu13states", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp_littlefs", "src"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp_littlefs", "include"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-face", "include"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-face", "include", "tool"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-face", "include", "typedef"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-face", "include", "image"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-face", "include", "math"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-face", "include", "nn"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-face", "include", "layer"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-face", "include", "detect"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-face", "include", "model_zoo"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dl", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dl", "include", "tool"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dl", "include", "typedef"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dl", "include", "image"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dl", "include", "math"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dl", "include", "nn"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dl", "include", "layer"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dl", "include", "detect"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "esp-dl", "include", "model_zoo"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "include", "fb_gfx", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", env.BoardConfig().get("build.arduino.memory_type", "qspi_qspi"), "include"), join(FRAMEWORK_DIR, "cores", env.BoardConfig().get("build.core")) ], LIBPATH=[ join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "lib"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "ld") + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", "ld"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32c3", env.BoardConfig().get("build.arduino.memory_type", "qspi_qspi")) ], LIBS=[ - "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lriscv", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lasio", "-lbt", "-lcbor", "-lunity", "-lcmock", "-lcoap", "-lnghttp", "-lesp-tls", "-lesp_adc_cal", "-lesp_hid", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lesp_https_server", "-lesp_lcd", "-lprotobuf-c", "-lprotocomm", "-lmdns", "-lesp_local_ctrl", "-lsdmmc", "-lesp_serial_slave_link", "-lesp_websocket_client", "-lexpat", "-lwear_levelling", "-lfatfs", "-lfreemodbus", "-ljsmn", "-ljson", "-llibsodium", "-lmqtt", "-lopenssl", "-lspiffs", "-lwifi_provisioning", "-lesp_littlefs", "-lfb_gfx", "-lasio", "-lcbor", "-lcmock", "-lunity", "-lcoap", "-lesp_lcd", "-lesp_local_ctrl", "-lesp_https_server", "-lesp_websocket_client", "-lexpat", "-lfreemodbus", "-ljsmn", "-llibsodium", "-lmqtt", "-lesp_adc_cal", "-lesp_hid", "-lfatfs", "-lwear_levelling", "-lopenssl", "-lspiffs", "-lwifi_provisioning", "-lprotocomm", "-lbt", "-lbtdm_app", "-lprotobuf-c", "-lmdns", "-ljson", "-lcat_face_detect", "-lhuman_face_detect", "-lcolor_detect", "-lmfn", "-ldl", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lriscv", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lriscv", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lriscv", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lriscv", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lriscv", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lriscv", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lphy", "-lbtbb", "-lesp_phy", "-lphy", "-lbtbb", "-lesp_phy", "-lphy", "-lbtbb", "-lm", "-lnewlib", "-lstdc++", "-lpthread", "-lgcc", "-lcxx", "-lapp_trace", "-lgcov", "-lapp_trace", "-lgcov", "-lc" + "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lriscv", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lasio", "-lbt", "-lcbor", "-lunity", "-lcmock", "-lcoap", "-lnghttp", "-lesp-tls", "-lesp_adc_cal", "-lesp_hid", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lesp_https_server", "-lesp_lcd", "-lprotobuf-c", "-lprotocomm", "-lmdns", "-lesp_local_ctrl", "-lsdmmc", "-lesp_serial_slave_link", "-lesp_websocket_client", "-lexpat", "-lwear_levelling", "-lfatfs", "-lfreemodbus", "-ljsmn", "-ljson", "-llibsodium", "-lmqtt", "-lopenssl", "-lspiffs", "-lwifi_provisioning", "-lbutton", "-lrmaker_common", "-ljson_parser", "-ljson_generator", "-lesp_schedule", "-lesp_rainmaker", "-lqrcode", "-lws2812_led", "-lesp-dsp", "-lesp_littlefs", "-lfb_gfx", "-lasio", "-lcbor", "-lcmock", "-lunity", "-lcoap", "-lesp_lcd", "-lesp_websocket_client", "-lexpat", "-lfreemodbus", "-ljsmn", "-llibsodium", "-lesp_adc_cal", "-lesp_hid", "-lfatfs", "-lwear_levelling", "-lopenssl", "-lspiffs", "-lesp_rainmaker", "-lesp_local_ctrl", "-lesp_https_server", "-lwifi_provisioning", "-lprotocomm", "-lbt", "-lbtdm_app", "-lprotobuf-c", "-lmdns", "-ljson", "-lrmaker_common", "-lmqtt", "-ljson_parser", "-ljson_generator", "-lesp_schedule", "-lqrcode", "-lcat_face_detect", "-lhuman_face_detect", "-lcolor_detect", "-lmfn", "-ldl", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lriscv", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lriscv", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lriscv", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lriscv", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lriscv", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lriscv", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lphy", "-lbtbb", "-lesp_phy", "-lphy", "-lbtbb", "-lesp_phy", "-lphy", "-lbtbb", "-lm", "-lnewlib", "-lstdc++", "-lpthread", "-lgcc", "-lcxx", "-lapp_trace", "-lgcov", "-lapp_trace", "-lgcov", "-lc" ], CPPDEFINES=[ @@ -293,7 +303,7 @@ "UNITY_INCLUDE_CONFIG_H", "WITH_POSIX", "_GNU_SOURCE", - ("IDF_VER", '\\"v4.4-beta1-189-ga79dc75f0a\\"'), + ("IDF_VER", '\\"v4.4.1-1-gb8050b365e\\"'), "ESP_PLATFORM", "_POSIX_READER_WRITER_LOCKS", "ARDUINO_ARCH_ESP32", @@ -302,7 +312,8 @@ ("ARDUINO", 10812), ("ARDUINO_VARIANT", '\\"%s\\"' % env.BoardConfig().get("build.variant").replace('"', "")), ("ARDUINO_BOARD", '\\"%s\\"' % env.BoardConfig().get("name").replace('"', "")), - "ARDUINO_PARTITION_%s" % env.BoardConfig().get("build.partitions", "default.csv").replace(".csv", "") + "ARDUINO_PARTITION_%s" % basename(env.BoardConfig().get( + "build.partitions", "default.csv")).replace(".csv", "").replace("-", "_") ], LIBSOURCE_DIRS=[ @@ -314,6 +325,12 @@ ("0x8000", join(env.subst("$BUILD_DIR"), "partitions.bin")), ("0xe000", join(FRAMEWORK_DIR, "tools", "partitions", "boot_app0.bin")) ] + + [ + (offset, join(FRAMEWORK_DIR, img)) + for offset, img in env.BoardConfig().get( + "upload.arduino.flash_extra_images", [] + ) + ], ) # diff --git a/tools/platformio-build-esp32s2.py b/tools/platformio-build-esp32s2.py index 5e4d496de6e..3aff44ad516 100644 --- a/tools/platformio-build-esp32s2.py +++ b/tools/platformio-build-esp32s2.py @@ -24,7 +24,7 @@ # Extends: https://github.com/platformio/platform-espressif32/blob/develop/builder/main.py -from os.path import abspath, isdir, isfile, join, basename +from os.path import abspath, basename, isdir, isfile, join from SCons.Script import DefaultEnvironment @@ -88,6 +88,7 @@ "-T", "esp32s2.rom.newlib-funcs.ld", "-T", "esp32s2.rom.newlib-data.ld", "-T", "esp32s2.rom.spiflash.ld", + "-T", "esp32s2.rom.newlib-time.ld", "-T", "esp32s2.peripherals.ld", "-u", "_Z5setupv", "-u", "_Z4loopv", @@ -96,6 +97,7 @@ "-u", "pthread_include_pthread_cond_impl", "-u", "pthread_include_pthread_local_storage_impl", "-u", "pthread_include_pthread_rwlock_impl", + "-u", "include_esp_phy_override", "-u", "ld_include_highint_hdl", "-u", "start_app", "-u", "__ubsan_include", @@ -107,7 +109,7 @@ "-u", "newlib_include_pthread_impl", "-u", "newlib_include_assert_impl", "-u", "__cxa_guard_dummy", - '-Wl,-Map="%s"' % join("$BUILD_DIR", basename(env.subst("${PROJECT_DIR}.map"))) + '-Wl,-Map="%s"' % join("${BUILD_DIR}", "${PROGNAME}.map") ], CPPPATH=[ @@ -230,11 +232,15 @@ join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "touch_element", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "ulp", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "wifi_provisioning", "include"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "freertos", "include", "freertos"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "arduino_tinyusb", "tinyusb", "src"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "arduino_tinyusb", "include"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp_littlefs", "src"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp_littlefs", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "button", "button", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "rmaker_common", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "json_parser", "upstream", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "json_parser", "upstream"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "json_generator", "upstream"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp_schedule", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp_rainmaker", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "qrcode", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "ws2812_led"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-dsp", "modules", "dotprod", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-dsp", "modules", "support", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-dsp", "modules", "windows", "include"), @@ -260,28 +266,37 @@ join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-dsp", "modules", "common", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-dsp", "modules", "kalman", "ekf", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-dsp", "modules", "kalman", "ekf_imu13states", "include"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-face", "include"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-face", "include", "tool"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-face", "include", "typedef"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-face", "include", "image"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-face", "include", "math"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-face", "include", "nn"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-face", "include", "layer"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-face", "include", "detect"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-face", "include", "model_zoo"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "freertos", "include", "freertos"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "arduino_tinyusb", "tinyusb", "src"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "arduino_tinyusb", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp_littlefs", "src"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp_littlefs", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-dl", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-dl", "include", "tool"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-dl", "include", "typedef"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-dl", "include", "image"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-dl", "include", "math"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-dl", "include", "nn"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-dl", "include", "layer"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-dl", "include", "detect"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-dl", "include", "model_zoo"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-sr", "esp-tts", "esp_tts_chinese", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp-sr", "include", "esp32"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp32-camera", "driver", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "esp32-camera", "conversions", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "include", "fb_gfx", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", env.BoardConfig().get("build.arduino.memory_type", "qspi_qspi"), "include"), join(FRAMEWORK_DIR, "cores", env.BoardConfig().get("build.core")) ], LIBPATH=[ join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "lib"), - join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "ld") + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", "ld"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s2", env.BoardConfig().get("build.arduino.memory_type", "qspi_qspi")) ], LIBS=[ - "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lasio", "-lcbor", "-lunity", "-lcmock", "-lcoap", "-lnghttp", "-lesp-tls", "-lesp_adc_cal", "-lesp_hid", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lesp_https_server", "-lesp_lcd", "-lprotobuf-c", "-lprotocomm", "-lmdns", "-lesp_local_ctrl", "-lsdmmc", "-lesp_serial_slave_link", "-lesp_websocket_client", "-lexpat", "-lwear_levelling", "-lfatfs", "-lfreemodbus", "-ljsmn", "-ljson", "-llibsodium", "-lmqtt", "-lopenssl", "-lperfmon", "-lspiffs", "-lusb", "-ltouch_element", "-lulp", "-lwifi_provisioning", "-lesp-dsp", "-lesp32-camera", "-lesp_littlefs", "-lfb_gfx", "-lasio", "-lcbor", "-lcmock", "-lunity", "-lcoap", "-lesp_lcd", "-lesp_local_ctrl", "-lesp_https_server", "-lesp_websocket_client", "-lexpat", "-lfreemodbus", "-ljsmn", "-llibsodium", "-lmqtt", "-lperfmon", "-lusb", "-ltouch_element", "-lesp_adc_cal", "-lesp_hid", "-lfatfs", "-lwear_levelling", "-lopenssl", "-lspiffs", "-lwifi_provisioning", "-lprotocomm", "-lprotobuf-c", "-lmdns", "-ljson", "-larduino_tinyusb", "-lcat_face_detect", "-lhuman_face_detect", "-lcolor_detect", "-lmfn", "-ldl", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lphy", "-lesp_phy", "-lphy", "-lesp_phy", "-lphy", "-lxt_hal", "-lm", "-lnewlib", "-lstdc++", "-lpthread", "-lgcc", "-lcxx", "-lapp_trace", "-lgcov", "-lapp_trace", "-lgcov", "-lc" + "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lasio", "-lcbor", "-lunity", "-lcmock", "-lcoap", "-lnghttp", "-lesp-tls", "-lesp_adc_cal", "-lesp_hid", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lesp_https_server", "-lesp_lcd", "-lprotobuf-c", "-lprotocomm", "-lmdns", "-lesp_local_ctrl", "-lsdmmc", "-lesp_serial_slave_link", "-lesp_websocket_client", "-lexpat", "-lwear_levelling", "-lfatfs", "-lfreemodbus", "-ljsmn", "-ljson", "-llibsodium", "-lmqtt", "-lopenssl", "-lperfmon", "-lspiffs", "-lusb", "-ltouch_element", "-lulp", "-lwifi_provisioning", "-lbutton", "-lrmaker_common", "-ljson_parser", "-ljson_generator", "-lesp_schedule", "-lesp_rainmaker", "-lqrcode", "-lws2812_led", "-lesp-dsp", "-lesp-sr", "-lesp32-camera", "-lesp_littlefs", "-lfb_gfx", "-lasio", "-lcbor", "-lcmock", "-lunity", "-lcoap", "-lesp_lcd", "-lesp_websocket_client", "-lexpat", "-lfreemodbus", "-ljsmn", "-llibsodium", "-lperfmon", "-lusb", "-ltouch_element", "-lesp_adc_cal", "-lesp_hid", "-lfatfs", "-lwear_levelling", "-lopenssl", "-lesp_rainmaker", "-lesp_local_ctrl", "-lesp_https_server", "-lwifi_provisioning", "-lprotocomm", "-lprotobuf-c", "-lmdns", "-lrmaker_common", "-lmqtt", "-ljson_parser", "-ljson_generator", "-lesp_schedule", "-lqrcode", "-larduino_tinyusb", "-lcat_face_detect", "-lhuman_face_detect", "-lcolor_detect", "-lmfn", "-ldl", "-ljson", "-lspiffs", "-lesp_tts_chinese", "-lvoice_set_xiaole", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lphy", "-lesp_phy", "-lphy", "-lesp_phy", "-lphy", "-lxt_hal", "-lm", "-lnewlib", "-lstdc++", "-lpthread", "-lgcc", "-lcxx", "-lapp_trace", "-lgcov", "-lapp_trace", "-lgcov", "-lc" ], CPPDEFINES=[ @@ -290,7 +305,7 @@ "UNITY_INCLUDE_CONFIG_H", "WITH_POSIX", "_GNU_SOURCE", - ("IDF_VER", '\\"v4.4-beta1-189-ga79dc75f0a\\"'), + ("IDF_VER", '\\"v4.4.1-1-gb8050b365e\\"'), "ESP_PLATFORM", "_POSIX_READER_WRITER_LOCKS", "ARDUINO_ARCH_ESP32", @@ -299,7 +314,8 @@ ("ARDUINO", 10812), ("ARDUINO_VARIANT", '\\"%s\\"' % env.BoardConfig().get("build.variant").replace('"', "")), ("ARDUINO_BOARD", '\\"%s\\"' % env.BoardConfig().get("name").replace('"', "")), - "ARDUINO_PARTITION_%s" % env.BoardConfig().get("build.partitions", "default.csv").replace(".csv", "") + "ARDUINO_PARTITION_%s" % basename(env.BoardConfig().get( + "build.partitions", "default.csv")).replace(".csv", "").replace("-", "_") ], LIBSOURCE_DIRS=[ @@ -311,6 +327,12 @@ ("0x8000", join(env.subst("$BUILD_DIR"), "partitions.bin")), ("0xe000", join(FRAMEWORK_DIR, "tools", "partitions", "boot_app0.bin")) ] + + [ + (offset, join(FRAMEWORK_DIR, img)) + for offset, img in env.BoardConfig().get( + "upload.arduino.flash_extra_images", [] + ) + ], ) # diff --git a/tools/platformio-build-esp32s3.py b/tools/platformio-build-esp32s3.py new file mode 100644 index 00000000000..1733393ee11 --- /dev/null +++ b/tools/platformio-build-esp32s3.py @@ -0,0 +1,403 @@ +# Copyright 2014-present PlatformIO +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Arduino + +Arduino Wiring-based Framework allows writing cross-platform software to +control devices attached to a wide range of Arduino boards to create all +kinds of creative coding, interactive objects, spaces or physical experiences. + +http://arduino.cc/en/Reference/HomePage +""" + +# Extends: https://github.com/platformio/platform-espressif32/blob/develop/builder/main.py + +from os.path import abspath, basename, isdir, isfile, join + +from SCons.Script import DefaultEnvironment + +env = DefaultEnvironment() +platform = env.PioPlatform() + +FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32") +assert isdir(FRAMEWORK_DIR) + +env.Append( + ASFLAGS=[ + "-x", "assembler-with-cpp" + ], + + CFLAGS=[ + "-mlongcalls", + "-std=gnu99", + "-Wno-old-style-declaration" + ], + + CXXFLAGS=[ + "-mlongcalls", + "-std=gnu++11", + "-fexceptions", + "-fno-rtti" + ], + + CCFLAGS=[ + "-ffunction-sections", + "-fdata-sections", + "-Wno-error=unused-function", + "-Wno-error=unused-variable", + "-Wno-error=deprecated-declarations", + "-Wno-unused-parameter", + "-Wno-sign-compare", + "-ggdb", + "-Os", + "-freorder-blocks", + "-Wwrite-strings", + "-fstack-protector", + "-fstrict-volatile-bitfields", + "-Wno-error=unused-but-set-variable", + "-fno-jump-tables", + "-fno-tree-switch-conversion", + "-MMD" + ], + + LINKFLAGS=[ + "-mlongcalls", + "-Wl,--cref", + "-Wl,--gc-sections", + "-fno-rtti", + "-fno-lto", + "-Wl,--wrap=longjmp", + "-Wl,--undefined=uxTopUsedPriority", + "-T", "memory.ld", + "-T", "sections.ld", + "-T", "esp32s3.rom.ld", + "-T", "esp32s3.rom.api.ld", + "-T", "esp32s3.rom.libgcc.ld", + "-T", "esp32s3.rom.newlib.ld", + "-T", "esp32s3.rom.version.ld", + "-T", "esp32s3.rom.newlib-time.ld", + "-T", "esp32s3.peripherals.ld", + "-u", "_Z5setupv", + "-u", "_Z4loopv", + "-u", "esp_app_desc", + "-u", "pthread_include_pthread_impl", + "-u", "pthread_include_pthread_cond_impl", + "-u", "pthread_include_pthread_local_storage_impl", + "-u", "pthread_include_pthread_rwlock_impl", + "-u", "include_esp_phy_override", + "-u", "ld_include_highint_hdl", + "-u", "start_app", + "-u", "start_app_other_cores", + "-u", "__ubsan_include", + "-u", "__assert_func", + "-u", "vfs_include_syscalls_impl", + "-u", "app_main", + "-u", "newlib_include_heap_impl", + "-u", "newlib_include_syscalls_impl", + "-u", "newlib_include_pthread_impl", + "-u", "newlib_include_assert_impl", + "-u", "__cxa_guard_dummy", + '-Wl,-Map="%s"' % join("${BUILD_DIR}", "${PROGNAME}.map") + ], + + CPPPATH=[ + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "config"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "newlib", "platform_include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "freertos", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "freertos", "include", "esp_additions", "freertos"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "freertos", "port", "xtensa", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "freertos", "include", "esp_additions"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_hw_support", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_hw_support", "include", "soc"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_hw_support", "include", "soc", "esp32s3"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_hw_support", "port", "esp32s3"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_hw_support", "port", "esp32s3", "private_include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "heap", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "log", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "lwip", "include", "apps"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "lwip", "include", "apps", "sntp"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "lwip", "lwip", "src", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "lwip", "port", "esp32", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "lwip", "port", "esp32", "include", "arch"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "soc", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "soc", "esp32s3"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "soc", "esp32s3", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "hal", "esp32s3", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "hal", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "hal", "platform_port", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_rom", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_rom", "include", "esp32s3"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_rom", "esp32s3"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_common", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_system", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_system", "port", "soc"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_system", "port", "public_compat"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "xtensa", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "xtensa", "esp32s3", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "driver", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "driver", "esp32s3", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_pm", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_ringbuf", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "efuse", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "efuse", "esp32s3", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "vfs", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_wifi", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_event", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_netif", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_eth", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "tcpip_adapter", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_phy", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_phy", "esp32s3", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_ipc", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "app_trace", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_timer", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "mbedtls", "port", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "mbedtls", "mbedtls", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "mbedtls", "esp_crt_bundle", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "app_update", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "spi_flash", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "bootloader_support", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "nvs_flash", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "pthread", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_gdbstub", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_gdbstub", "xtensa"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_gdbstub", "esp32s3"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "espcoredump", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "espcoredump", "include", "port", "xtensa"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "wpa_supplicant", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "wpa_supplicant", "port", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "wpa_supplicant", "esp_supplicant", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "ieee802154", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "console"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "asio", "asio", "asio", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "asio", "port", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "bt", "common", "osi", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "bt", "include", "esp32s3", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "bt", "common", "api", "include", "api"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "bt", "common", "btc", "profile", "esp", "blufi", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "bt", "common", "btc", "profile", "esp", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "bt", "host", "bluedroid", "api", "include", "api"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "bt", "esp_ble_mesh", "mesh_common", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "bt", "esp_ble_mesh", "mesh_common", "tinycrypt", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "bt", "esp_ble_mesh", "mesh_core"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "bt", "esp_ble_mesh", "mesh_core", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "bt", "esp_ble_mesh", "mesh_core", "storage"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "bt", "esp_ble_mesh", "btc", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "bt", "esp_ble_mesh", "mesh_models", "common", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "bt", "esp_ble_mesh", "mesh_models", "client", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "bt", "esp_ble_mesh", "mesh_models", "server", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "bt", "esp_ble_mesh", "api", "core", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "bt", "esp_ble_mesh", "api", "models", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "bt", "esp_ble_mesh", "api"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "cbor", "port", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "unity", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "unity", "unity", "src"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "cmock", "CMock", "src"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "coap", "port", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "coap", "libcoap", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "nghttp", "port", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "nghttp", "nghttp2", "lib", "includes"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-tls"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-tls", "esp-tls-crypto"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_adc_cal", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_hid", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "tcp_transport", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_http_client", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_http_server", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_https_ota", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_https_server", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_lcd", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_lcd", "interface"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "protobuf-c", "protobuf-c"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "protocomm", "include", "common"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "protocomm", "include", "security"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "protocomm", "include", "transports"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "mdns", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_local_ctrl", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "sdmmc", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_serial_slave_link", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_websocket_client", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "expat", "expat", "expat", "lib"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "expat", "port", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "wear_levelling", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "fatfs", "diskio"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "fatfs", "vfs"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "fatfs", "src"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "freemodbus", "common", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "idf_test", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "idf_test", "include", "esp32s3"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "jsmn", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "json", "cJSON"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "libsodium", "libsodium", "src", "libsodium", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "libsodium", "port_include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "mqtt", "esp-mqtt", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "openssl", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "perfmon", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "spiffs", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "usb", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "ulp", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "wifi_provisioning", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "button", "button", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "rmaker_common", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "json_parser", "upstream", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "json_parser", "upstream"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "json_generator", "upstream"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_schedule", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_rainmaker", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "qrcode", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "ws2812_led"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dsp", "modules", "dotprod", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dsp", "modules", "support", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dsp", "modules", "windows", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dsp", "modules", "windows", "hann", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dsp", "modules", "windows", "blackman", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dsp", "modules", "windows", "blackman_harris", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dsp", "modules", "windows", "blackman_nuttall", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dsp", "modules", "windows", "nuttall", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dsp", "modules", "windows", "flat_top", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dsp", "modules", "iir", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dsp", "modules", "fir", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dsp", "modules", "math", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dsp", "modules", "math", "add", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dsp", "modules", "math", "sub", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dsp", "modules", "math", "mul", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dsp", "modules", "math", "addc", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dsp", "modules", "math", "mulc", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dsp", "modules", "math", "sqrt", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dsp", "modules", "matrix", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dsp", "modules", "fft", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dsp", "modules", "dct", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dsp", "modules", "conv", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dsp", "modules", "common", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dsp", "modules", "kalman", "ekf", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dsp", "modules", "kalman", "ekf_imu13states", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "freertos", "include", "freertos"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "arduino_tinyusb", "tinyusb", "src"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "arduino_tinyusb", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_littlefs", "src"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp_littlefs", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dl", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dl", "include", "tool"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dl", "include", "typedef"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dl", "include", "image"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dl", "include", "math"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dl", "include", "nn"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dl", "include", "layer"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dl", "include", "detect"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-dl", "include", "model_zoo"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-sr", "esp-tts", "esp_tts_chinese", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp-sr", "include", "esp32s3"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp32-camera", "driver", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "esp32-camera", "conversions", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "include", "fb_gfx", "include"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", env.BoardConfig().get("build.arduino.memory_type", "qspi_qspi"), "include"), + join(FRAMEWORK_DIR, "cores", env.BoardConfig().get("build.core")) + ], + + LIBPATH=[ + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "lib"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "ld"), + join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", env.BoardConfig().get("build.arduino.memory_type", "qspi_qspi")) + ], + + LIBS=[ + "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lasio", "-lbt", "-lcbor", "-lunity", "-lcmock", "-lcoap", "-lnghttp", "-lesp-tls", "-lesp_adc_cal", "-lesp_hid", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lesp_https_server", "-lesp_lcd", "-lprotobuf-c", "-lprotocomm", "-lmdns", "-lesp_local_ctrl", "-lsdmmc", "-lesp_serial_slave_link", "-lesp_websocket_client", "-lexpat", "-lwear_levelling", "-lfatfs", "-lfreemodbus", "-ljsmn", "-ljson", "-llibsodium", "-lmqtt", "-lopenssl", "-lperfmon", "-lspiffs", "-lusb", "-lulp", "-lwifi_provisioning", "-lbutton", "-lrmaker_common", "-ljson_parser", "-ljson_generator", "-lesp_schedule", "-lesp_rainmaker", "-lqrcode", "-lws2812_led", "-lesp-dsp", "-lesp-sr", "-lesp32-camera", "-lesp_littlefs", "-lfb_gfx", "-lasio", "-lcbor", "-lcmock", "-lunity", "-lcoap", "-lesp_lcd", "-lesp_websocket_client", "-lexpat", "-lfreemodbus", "-ljsmn", "-llibsodium", "-lperfmon", "-lusb", "-lesp_adc_cal", "-lesp_hid", "-lfatfs", "-lwear_levelling", "-lopenssl", "-lesp_rainmaker", "-lesp_local_ctrl", "-lesp_https_server", "-lwifi_provisioning", "-lprotocomm", "-lbt", "-lbtdm_app", "-lprotobuf-c", "-lmdns", "-lrmaker_common", "-lmqtt", "-ljson_parser", "-ljson_generator", "-lesp_schedule", "-lqrcode", "-larduino_tinyusb", "-lcat_face_detect", "-lhuman_face_detect", "-lcolor_detect", "-lmfn", "-ldl", "-lwakenet", "-lhufzip", "-lesp_audio_front_end", "-lesp_audio_processor", "-lmultinet", "-lesp-sr", "-lwakenet", "-lhufzip", "-lesp_audio_front_end", "-lesp_audio_processor", "-lmultinet", "-ljson", "-lspiffs", "-ldl_lib", "-lc_speech_features", "-lesp_tts_chinese", "-lvoice_set_xiaole", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lesp_ringbuf", "-lefuse", "-lesp_ipc", "-ldriver", "-lesp_pm", "-lmbedtls", "-lapp_update", "-lbootloader_support", "-lspi_flash", "-lnvs_flash", "-lpthread", "-lesp_gdbstub", "-lespcoredump", "-lesp_phy", "-lesp_system", "-lesp_rom", "-lhal", "-lvfs", "-lesp_eth", "-ltcpip_adapter", "-lesp_netif", "-lesp_event", "-lwpa_supplicant", "-lesp_wifi", "-lconsole", "-llwip", "-llog", "-lheap", "-lsoc", "-lesp_hw_support", "-lxtensa", "-lesp_common", "-lesp_timer", "-lfreertos", "-lnewlib", "-lcxx", "-lapp_trace", "-lnghttp", "-lesp-tls", "-ltcp_transport", "-lesp_http_client", "-lesp_http_server", "-lesp_https_ota", "-lsdmmc", "-lesp_serial_slave_link", "-lulp", "-lmbedtls", "-lmbedcrypto", "-lmbedx509", "-lcoexist", "-lcore", "-lespnow", "-lmesh", "-lnet80211", "-lpp", "-lsmartconfig", "-lwapi", "-lphy", "-lbtbb", "-lesp_phy", "-lphy", "-lbtbb", "-lesp_phy", "-lphy", "-lbtbb", "-lxt_hal", "-lm", "-lnewlib", "-lstdc++", "-lpthread", "-lgcc", "-lcxx", "-lapp_trace", "-lgcov", "-lapp_trace", "-lgcov", "-lc" + ], + + CPPDEFINES=[ + "HAVE_CONFIG_H", + ("MBEDTLS_CONFIG_FILE", '\\"mbedtls/esp_config.h\\"'), + "UNITY_INCLUDE_CONFIG_H", + "WITH_POSIX", + "_GNU_SOURCE", + ("IDF_VER", '\\"v4.4.1-1-gb8050b365e\\"'), + "ESP_PLATFORM", + "_POSIX_READER_WRITER_LOCKS", + "ARDUINO_ARCH_ESP32", + "ESP32", + ("F_CPU", "$BOARD_F_CPU"), + ("ARDUINO", 10812), + ("ARDUINO_VARIANT", '\\"%s\\"' % env.BoardConfig().get("build.variant").replace('"', "")), + ("ARDUINO_BOARD", '\\"%s\\"' % env.BoardConfig().get("name").replace('"', "")), + "ARDUINO_PARTITION_%s" % basename(env.BoardConfig().get( + "build.partitions", "default.csv")).replace(".csv", "").replace("-", "_") + ], + + LIBSOURCE_DIRS=[ + join(FRAMEWORK_DIR, "libraries") + ], + + FLASH_EXTRA_IMAGES=[ + ("0x0000", join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "bin", "bootloader_${BOARD_FLASH_MODE}_${__get_board_f_flash(__env__)}.bin")), + ("0x8000", join(env.subst("$BUILD_DIR"), "partitions.bin")), + ("0xe000", join(FRAMEWORK_DIR, "tools", "partitions", "boot_app0.bin")) + ] + + [ + (offset, join(FRAMEWORK_DIR, img)) + for offset, img in env.BoardConfig().get( + "upload.arduino.flash_extra_images", [] + ) + ], +) + +# +# Target: Build Core Library +# + +libs = [] + +variants_dir = join(FRAMEWORK_DIR, "variants") + +if "build.variants_dir" in env.BoardConfig(): + variants_dir = join("$PROJECT_DIR", env.BoardConfig().get("build.variants_dir")) + +if "build.variant" in env.BoardConfig(): + env.Append( + CPPPATH=[ + join(variants_dir, env.BoardConfig().get("build.variant")) + ] + ) + libs.append(env.BuildLibrary( + join("$BUILD_DIR", "FrameworkArduinoVariant"), + join(variants_dir, env.BoardConfig().get("build.variant")) + )) + +envsafe = env.Clone() + +libs.append(envsafe.BuildLibrary( + join("$BUILD_DIR", "FrameworkArduino"), + join(FRAMEWORK_DIR, "cores", env.BoardConfig().get("build.core")) +)) + +env.Prepend(LIBS=libs) + +# +# Generate partition table +# + +fwpartitions_dir = join(FRAMEWORK_DIR, "tools", "partitions") +partitions_csv = env.BoardConfig().get("build.partitions", "default.csv") +env.Replace( + PARTITIONS_TABLE_CSV=abspath( + join(fwpartitions_dir, partitions_csv) if isfile( + join(fwpartitions_dir, partitions_csv)) else partitions_csv)) + +partition_table = env.Command( + join("$BUILD_DIR", "partitions.bin"), + "$PARTITIONS_TABLE_CSV", + env.VerboseAction('"$PYTHONEXE" "%s" -q $SOURCE $TARGET' % join( + FRAMEWORK_DIR, "tools", "gen_esp32part.py"), + "Generating partitions $TARGET")) +env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", partition_table) diff --git a/tools/sdk/esp32/bin/bootloader_dio_40m.bin b/tools/sdk/esp32/bin/bootloader_dio_40m.bin index ee6d1d320b2..b134810d704 100644 Binary files a/tools/sdk/esp32/bin/bootloader_dio_40m.bin and b/tools/sdk/esp32/bin/bootloader_dio_40m.bin differ diff --git a/tools/sdk/esp32/bin/bootloader_dio_80m.bin b/tools/sdk/esp32/bin/bootloader_dio_80m.bin index 238c5578b7b..2f35e47d98d 100644 Binary files a/tools/sdk/esp32/bin/bootloader_dio_80m.bin and b/tools/sdk/esp32/bin/bootloader_dio_80m.bin differ diff --git a/tools/sdk/esp32/bin/bootloader_dout_40m.bin b/tools/sdk/esp32/bin/bootloader_dout_40m.bin index 488a7bbb3fe..685f655930a 100644 Binary files a/tools/sdk/esp32/bin/bootloader_dout_40m.bin and b/tools/sdk/esp32/bin/bootloader_dout_40m.bin differ diff --git a/tools/sdk/esp32/bin/bootloader_dout_80m.bin b/tools/sdk/esp32/bin/bootloader_dout_80m.bin index 77ed1d3e630..7a11199ee36 100644 Binary files a/tools/sdk/esp32/bin/bootloader_dout_80m.bin and b/tools/sdk/esp32/bin/bootloader_dout_80m.bin differ diff --git a/tools/sdk/esp32/bin/bootloader_qio_40m.bin b/tools/sdk/esp32/bin/bootloader_qio_40m.bin index 59b2b6e4413..d316c3b852f 100644 Binary files a/tools/sdk/esp32/bin/bootloader_qio_40m.bin and b/tools/sdk/esp32/bin/bootloader_qio_40m.bin differ diff --git a/tools/sdk/esp32/bin/bootloader_qio_80m.bin b/tools/sdk/esp32/bin/bootloader_qio_80m.bin index 15bf321d2ca..82fd51d672a 100644 Binary files a/tools/sdk/esp32/bin/bootloader_qio_80m.bin and b/tools/sdk/esp32/bin/bootloader_qio_80m.bin differ diff --git a/tools/sdk/esp32/bin/bootloader_qout_40m.bin b/tools/sdk/esp32/bin/bootloader_qout_40m.bin index 27f59601fc6..4bb8709cbee 100644 Binary files a/tools/sdk/esp32/bin/bootloader_qout_40m.bin and b/tools/sdk/esp32/bin/bootloader_qout_40m.bin differ diff --git a/tools/sdk/esp32/bin/bootloader_qout_80m.bin b/tools/sdk/esp32/bin/bootloader_qout_80m.bin index 2af6988c83c..311266e9179 100644 Binary files a/tools/sdk/esp32/bin/bootloader_qout_80m.bin and b/tools/sdk/esp32/bin/bootloader_qout_80m.bin differ diff --git a/tools/sdk/esp32/include/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h b/tools/sdk/esp32/include/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h index 73c8605e078..285cbb028cf 100644 --- a/tools/sdk/esp32/include/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h +++ b/tools/sdk/esp32/include/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h @@ -236,7 +236,7 @@ typedef enum { #define ESP_BT_GAP_MIN_INQ_LEN (0x01) /*!< Minimum inquiry duration, unit is 1.28s */ #define ESP_BT_GAP_MAX_INQ_LEN (0x30) /*!< Maximum inquiry duration, unit is 1.28s */ -/// A2DP state callback parameters +/// GAP state callback parameters typedef union { /** * @brief ESP_BT_GAP_DISC_RES_EVT diff --git a/tools/sdk/esp32/include/bt/host/bluedroid/api/include/api/esp_hf_client_api.h b/tools/sdk/esp32/include/bt/host/bluedroid/api/include/api/esp_hf_client_api.h index 3c5c05b178c..55569bc5c84 100644 --- a/tools/sdk/esp32/include/bt/host/bluedroid/api/include/api/esp_hf_client_api.h +++ b/tools/sdk/esp32/include/bt/host/bluedroid/api/include/api/esp_hf_client_api.h @@ -60,6 +60,9 @@ typedef enum { #define ESP_HF_CLIENT_PEER_FEAT_ECC 0x80 /* Enhanced Call Control */ #define ESP_HF_CLIENT_PEER_FEAT_EXTERR 0x100 /* Extended error codes */ #define ESP_HF_CLIENT_PEER_FEAT_CODEC 0x200 /* Codec Negotiation */ +/* HFP 1.7+ */ +#define ESP_HF_CLIENT_PEER_FEAT_HF_IND 0x400 /* HF Indicators */ +#define ESP_HF_CLIENT_PEER_FEAT_ESCO_S4 0x800 /* eSCO S4 Setting Supported */ /* CHLD feature masks of AG */ #define ESP_HF_CLIENT_CHLD_FEAT_REL 0x01 /* 0 Release waiting call or held calls */ diff --git a/tools/sdk/esp32/include/driver/esp32/include/driver/adc.h b/tools/sdk/esp32/include/driver/esp32/include/driver/adc.h deleted file mode 100644 index c8f05fc9000..00000000000 --- a/tools/sdk/esp32/include/driver/esp32/include/driver/adc.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include "driver/adc_common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/*--------------------------------------------------------------- - Digital controller setting ----------------------------------------------------------------*/ - -/** - * @brief Set I2S data source - * @param src I2S DMA data source, I2S DMA can get data from digital signals or from ADC. - * @return - * - ESP_OK success - */ -esp_err_t adc_set_i2s_data_source(adc_i2s_source_t src); - -/** - * @brief Initialize I2S ADC mode - * @param adc_unit ADC unit index - * @param channel ADC channel index - * @return - * - ESP_OK success - * - ESP_ERR_INVALID_ARG Parameter error - */ -esp_err_t adc_i2s_mode_init(adc_unit_t adc_unit, adc_channel_t channel); - -/*--------------------------------------------------------------- - RTC controller setting ----------------------------------------------------------------*/ - -/** - * @brief Read Hall Sensor - * - * @note When the power switch of SARADC1, SARADC2, HALL sensor and AMP sensor is turned on, - * the input of GPIO36 and GPIO39 will be pulled down for about 80ns. - * When enabling power for any of these peripherals, ignore input from GPIO36 and GPIO39. - * Please refer to section 3.11 of 'ECO_and_Workarounds_for_Bugs_in_ESP32' for the description of this issue. - * - * @note The Hall Sensor uses channels 0 and 3 of ADC1. Do not configure - * these channels for use as ADC channels. - * - * @note The ADC1 module must be enabled by calling - * adc1_config_width() before calling hall_sensor_read(). ADC1 - * should be configured for 12 bit readings, as the hall sensor - * readings are low values and do not cover the full range of the - * ADC. - * - * @return The hall sensor reading. - */ -int hall_sensor_read(void); - -#ifdef __cplusplus -} -#endif diff --git a/tools/sdk/esp32/include/driver/include/driver/adc.h b/tools/sdk/esp32/include/driver/include/driver/adc.h new file mode 100644 index 00000000000..5cd19dacd7d --- /dev/null +++ b/tools/sdk/esp32/include/driver/include/driver/adc.h @@ -0,0 +1,646 @@ +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include "esp_err.h" +#include "sdkconfig.h" +#include "driver/gpio.h" +#include "hal/adc_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if CONFIG_IDF_TARGET_ESP32 +/**** `adc1_channel_t` will be deprecated functions, combine into `adc_channel_t` ********/ +typedef enum { + ADC1_CHANNEL_0 = 0, /*!< ADC1 channel 0 is GPIO36 */ + ADC1_CHANNEL_1, /*!< ADC1 channel 1 is GPIO37 */ + ADC1_CHANNEL_2, /*!< ADC1 channel 2 is GPIO38 */ + ADC1_CHANNEL_3, /*!< ADC1 channel 3 is GPIO39 */ + ADC1_CHANNEL_4, /*!< ADC1 channel 4 is GPIO32 */ + ADC1_CHANNEL_5, /*!< ADC1 channel 5 is GPIO33 */ + ADC1_CHANNEL_6, /*!< ADC1 channel 6 is GPIO34 */ + ADC1_CHANNEL_7, /*!< ADC1 channel 7 is GPIO35 */ + ADC1_CHANNEL_MAX, +} adc1_channel_t; +#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 // TODO ESP32-S3 channels are wrong IDF-1776 +/**** `adc1_channel_t` will be deprecated functions, combine into `adc_channel_t` ********/ +typedef enum { + ADC1_CHANNEL_0 = 0, /*!< ADC1 channel 0 is GPIO1 */ + ADC1_CHANNEL_1, /*!< ADC1 channel 1 is GPIO2 */ + ADC1_CHANNEL_2, /*!< ADC1 channel 2 is GPIO3 */ + ADC1_CHANNEL_3, /*!< ADC1 channel 3 is GPIO4 */ + ADC1_CHANNEL_4, /*!< ADC1 channel 4 is GPIO5 */ + ADC1_CHANNEL_5, /*!< ADC1 channel 5 is GPIO6 */ + ADC1_CHANNEL_6, /*!< ADC1 channel 6 is GPIO7 */ + ADC1_CHANNEL_7, /*!< ADC1 channel 7 is GPIO8 */ + ADC1_CHANNEL_8, /*!< ADC1 channel 8 is GPIO9 */ + ADC1_CHANNEL_9, /*!< ADC1 channel 9 is GPIO10 */ + ADC1_CHANNEL_MAX, +} adc1_channel_t; +#elif CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2 +/**** `adc1_channel_t` will be deprecated functions, combine into `adc_channel_t` ********/ +typedef enum { + ADC1_CHANNEL_0 = 0, /*!< ADC1 channel 0 is GPIO0 */ + ADC1_CHANNEL_1, /*!< ADC1 channel 1 is GPIO1 */ + ADC1_CHANNEL_2, /*!< ADC1 channel 2 is GPIO2 */ + ADC1_CHANNEL_3, /*!< ADC1 channel 3 is GPIO3 */ + ADC1_CHANNEL_4, /*!< ADC1 channel 4 is GPIO4 */ + ADC1_CHANNEL_MAX, +} adc1_channel_t; +#endif // CONFIG_IDF_TARGET_* + +#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 // TODO ESP32-S3 channels are wrong IDF-1776 +/**** `adc2_channel_t` will be deprecated functions, combine into `adc_channel_t` ********/ +typedef enum { + ADC2_CHANNEL_0 = 0, /*!< ADC2 channel 0 is GPIO4 (ESP32), GPIO11 (ESP32-S2) */ + ADC2_CHANNEL_1, /*!< ADC2 channel 1 is GPIO0 (ESP32), GPIO12 (ESP32-S2) */ + ADC2_CHANNEL_2, /*!< ADC2 channel 2 is GPIO2 (ESP32), GPIO13 (ESP32-S2) */ + ADC2_CHANNEL_3, /*!< ADC2 channel 3 is GPIO15 (ESP32), GPIO14 (ESP32-S2) */ + ADC2_CHANNEL_4, /*!< ADC2 channel 4 is GPIO13 (ESP32), GPIO15 (ESP32-S2) */ + ADC2_CHANNEL_5, /*!< ADC2 channel 5 is GPIO12 (ESP32), GPIO16 (ESP32-S2) */ + ADC2_CHANNEL_6, /*!< ADC2 channel 6 is GPIO14 (ESP32), GPIO17 (ESP32-S2) */ + ADC2_CHANNEL_7, /*!< ADC2 channel 7 is GPIO27 (ESP32), GPIO18 (ESP32-S2) */ + ADC2_CHANNEL_8, /*!< ADC2 channel 8 is GPIO25 (ESP32), GPIO19 (ESP32-S2) */ + ADC2_CHANNEL_9, /*!< ADC2 channel 9 is GPIO26 (ESP32), GPIO20 (ESP32-S2) */ + ADC2_CHANNEL_MAX, +} adc2_channel_t; +#elif CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2 +/**** `adc2_channel_t` will be deprecated functions, combine into `adc_channel_t` ********/ +typedef enum { + ADC2_CHANNEL_0 = 0, /*!< ADC2 channel 0 is GPIO5 */ + ADC2_CHANNEL_MAX, +} adc2_channel_t; +#endif + + +/** + * @brief ADC rtc controller attenuation option. + * + * @note This definitions are only for being back-compatible + */ +#define ADC_ATTEN_0db ADC_ATTEN_DB_0 +#define ADC_ATTEN_2_5db ADC_ATTEN_DB_2_5 +#define ADC_ATTEN_6db ADC_ATTEN_DB_6 +#define ADC_ATTEN_11db ADC_ATTEN_DB_11 + +/** + * The default (max) bit width of the ADC of current version. You can also get the maximum bitwidth + * by `SOC_ADC_MAX_BITWIDTH` defined in soc_caps.h. + */ +#define ADC_WIDTH_BIT_DEFAULT (ADC_WIDTH_MAX-1) + +//this definitions are only for being back-compatible +#define ADC_WIDTH_9Bit ADC_WIDTH_BIT_9 +#define ADC_WIDTH_10Bit ADC_WIDTH_BIT_10 +#define ADC_WIDTH_11Bit ADC_WIDTH_BIT_11 +#define ADC_WIDTH_12Bit ADC_WIDTH_BIT_12 + +/** + * @brief ADC digital controller encode option. + * + * @deprecated The ESP32-S2 doesn't use I2S DMA. Call ``adc_digi_output_format_t`` instead. + */ +typedef enum { + ADC_ENCODE_12BIT, /*!< ADC to DMA data format, , [15:12]-channel [11:0]-12 bits ADC data */ + ADC_ENCODE_11BIT, /*!< ADC to DMA data format, [15]-unit, [14:11]-channel [10:0]-11 bits ADC data */ + ADC_ENCODE_MAX, +} adc_i2s_encode_t; + +/*--------------------------------------------------------------- + Common setting +---------------------------------------------------------------*/ + +/** + * @brief Enable ADC power + * @deprecated Use adc_power_acquire and adc_power_release instead. + */ +void adc_power_on(void) __attribute__((deprecated)); + +/** + * @brief Power off SAR ADC + * @deprecated Use adc_power_acquire and adc_power_release instead. + * This function will force power down for ADC. + * This function is deprecated because forcing power ADC power off may + * disrupt operation of other components which may be using the ADC. + */ +void adc_power_off(void) __attribute__((deprecated)); + +/** + * @brief Increment the usage counter for ADC module. + * ADC will stay powered on while the counter is greater than 0. + * Call adc_power_release when done using the ADC. + */ +void adc_power_acquire(void); + +/** + * @brief Decrement the usage counter for ADC module. + * ADC will stay powered on while the counter is greater than 0. + * Call this function when done using the ADC. + */ +void adc_power_release(void); + +/*--------------------------------------------------------------- + ADC Single Read Setting +---------------------------------------------------------------*/ +/** + * @brief Get the GPIO number of a specific ADC1 channel. + * + * @param channel Channel to get the GPIO number + * @param gpio_num output buffer to hold the GPIO number + * + * @return + * - ESP_OK if success + * - ESP_ERR_INVALID_ARG if channel not valid + */ +esp_err_t adc1_pad_get_io_num(adc1_channel_t channel, gpio_num_t *gpio_num); + +/** + * @brief Set the attenuation of a particular channel on ADC1, and configure its associated GPIO pin mux. + * + * The default ADC voltage is for attenuation 0 dB and listed in the table below. + * By setting higher attenuation it is possible to read higher voltages. + * + * Due to ADC characteristics, most accurate results are obtained within the "suggested range" + * shown in the following table. + * + * +----------+-------------+-----------------+ + * | | attenuation | suggested range | + * | SoC | (dB) | (mV) | + * +==========+=============+=================+ + * | | 0 | 100 ~ 950 | + * | +-------------+-----------------+ + * | | 2.5 | 100 ~ 1250 | + * | ESP32 +-------------+-----------------+ + * | | 6 | 150 ~ 1750 | + * | +-------------+-----------------+ + * | | 11 | 150 ~ 2450 | + * +----------+-------------+-----------------+ + * | | 0 | 0 ~ 750 | + * | +-------------+-----------------+ + * | | 2.5 | 0 ~ 1050 | + * | ESP32-S2 +-------------+-----------------+ + * | | 6 | 0 ~ 1300 | + * | +-------------+-----------------+ + * | | 11 | 0 ~ 2500 | + * +----------+-------------+-----------------+ + * + * For maximum accuracy, use the ADC calibration APIs and measure voltages within these recommended ranges. + * + * @note For any given channel, this function must be called before the first time ``adc1_get_raw()`` is called for that channel. + * + * @note This function can be called multiple times to configure multiple + * ADC channels simultaneously. You may call ``adc1_get_raw()`` only after configuring a channel. + * + * @param channel ADC1 channel to configure + * @param atten Attenuation level + * + * @return + * - ESP_OK success + * - ESP_ERR_INVALID_ARG Parameter error + */ +esp_err_t adc1_config_channel_atten(adc1_channel_t channel, adc_atten_t atten); + +/** + * @brief Configure ADC1 capture width, meanwhile enable output invert for ADC1. + * The configuration is for all channels of ADC1 + * @param width_bit Bit capture width for ADC1 + * + * @return + * - ESP_OK success + * - ESP_ERR_INVALID_ARG Parameter error + */ +esp_err_t adc1_config_width(adc_bits_width_t width_bit); + +/** + * @brief Take an ADC1 reading from a single channel. + * @note ESP32: + * When the power switch of SARADC1, SARADC2, HALL sensor and AMP sensor is turned on, + * the input of GPIO36 and GPIO39 will be pulled down for about 80ns. + * When enabling power for any of these peripherals, ignore input from GPIO36 and GPIO39. + * Please refer to section 3.11 of 'ECO_and_Workarounds_for_Bugs_in_ESP32' for the description of this issue. + * As a workaround, call adc_power_acquire() in the app. This will result in higher power consumption (by ~1mA), + * but will remove the glitches on GPIO36 and GPIO39. + * + * @note Call ``adc1_config_width()`` before the first time this + * function is called. + * + * @note For any given channel, adc1_config_channel_atten(channel) + * must be called before the first time this function is called. Configuring + * a new channel does not prevent a previously configured channel from being read. + * + * @param channel ADC1 channel to read + * + * @return + * - -1: Parameter error + * - Other: ADC1 channel reading. + */ +int adc1_get_raw(adc1_channel_t channel); + +#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 +//TODO IDF-3610, replace these with proper caps +/** + * @brief Set ADC data invert + * @param adc_unit ADC unit index + * @param inv_en whether enable data invert + * @return + * - ESP_OK success + * - ESP_ERR_INVALID_ARG Parameter error + */ +esp_err_t adc_set_data_inv(adc_unit_t adc_unit, bool inv_en); + +/** + * @brief Set ADC source clock + * @param clk_div ADC clock divider, ADC clock is divided from APB clock + * @return + * - ESP_OK success + */ +esp_err_t adc_set_clk_div(uint8_t clk_div); + +/** + * @brief Configure ADC capture width. + * + * @param adc_unit ADC unit index + * @param width_bit Bit capture width for ADC unit. + * + * @return + * - ESP_OK success + * - ESP_ERR_INVALID_ARG Parameter error + */ +esp_err_t adc_set_data_width(adc_unit_t adc_unit, adc_bits_width_t width_bit); + +/** + * @brief Configure ADC1 to be usable by the ULP + * + * This function reconfigures ADC1 to be controlled by the ULP. + * Effect of this function can be reverted using ``adc1_get_raw()`` function. + * + * Note that adc1_config_channel_atten, ``adc1_config_width()`` functions need + * to be called to configure ADC1 channels, before ADC1 is used by the ULP. + */ +void adc1_ulp_enable(void); +#endif //#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 + +/** + * @brief Get the GPIO number of a specific ADC2 channel. + * + * @param channel Channel to get the GPIO number + * + * @param gpio_num output buffer to hold the GPIO number + * + * @return + * - ESP_OK if success + * - ESP_ERR_INVALID_ARG if channel not valid + */ +esp_err_t adc2_pad_get_io_num(adc2_channel_t channel, gpio_num_t *gpio_num); + +/** + * @brief Configure the ADC2 channel, including setting attenuation. + * + * The default ADC voltage is for attenuation 0 dB and listed in the table below. + * By setting higher attenuation it is possible to read higher voltages. + * + * Due to ADC characteristics, most accurate results are obtained within the "suggested range" + * shown in the following table. + * + * +----------+-------------+-----------------+ + * | | attenuation | suggested range | + * | SoC | (dB) | (mV) | + * +==========+=============+=================+ + * | | 0 | 100 ~ 950 | + * | +-------------+-----------------+ + * | | 2.5 | 100 ~ 1250 | + * | ESP32 +-------------+-----------------+ + * | | 6 | 150 ~ 1750 | + * | +-------------+-----------------+ + * | | 11 | 150 ~ 2450 | + * +----------+-------------+-----------------+ + * | | 0 | 0 ~ 750 | + * | +-------------+-----------------+ + * | | 2.5 | 0 ~ 1050 | + * | ESP32-S2 +-------------+-----------------+ + * | | 6 | 0 ~ 1300 | + * | +-------------+-----------------+ + * | | 11 | 0 ~ 2500 | + * +----------+-------------+-----------------+ + * + * For maximum accuracy, use the ADC calibration APIs and measure voltages within these recommended ranges. + * + * @note This function also configures the input GPIO pin mux to + * connect it to the ADC2 channel. It must be called before calling + * ``adc2_get_raw()`` for this channel. + * + * @note For any given channel, this function must be called before the first time ``adc2_get_raw()`` is called for that channel. + * + * @param channel ADC2 channel to configure + * @param atten Attenuation level + * + * @return + * - ESP_OK success + * - ESP_ERR_INVALID_ARG Parameter error + */ +esp_err_t adc2_config_channel_atten(adc2_channel_t channel, adc_atten_t atten); + +/** + * @brief Take an ADC2 reading on a single channel + * + * @note ESP32: + * When the power switch of SARADC1, SARADC2, HALL sensor and AMP sensor is turned on, + * the input of GPIO36 and GPIO39 will be pulled down for about 80ns. + * When enabling power for any of these peripherals, ignore input from GPIO36 and GPIO39. + * Please refer to section 3.11 of 'ECO_and_Workarounds_for_Bugs_in_ESP32' for the description of this issue. + * As a workaround, call adc_power_acquire() in the app. This will result in higher power consumption (by ~1mA), + * but will remove the glitches on GPIO36 and GPIO39. + * + * + * @note ESP32: + * For a given channel, ``adc2_config_channel_atten()`` + * must be called before the first time this function is called. If Wi-Fi is started via ``esp_wifi_start()``, this + * function will always fail with ``ESP_ERR_TIMEOUT``. + * + * @note ESP32-S2: + * ADC2 support hardware arbiter. The arbiter is to improve the use efficiency of ADC2. After the control right is robbed by the high priority, + * the low priority controller will read the invalid ADC2 data. Default priority: Wi-Fi > RTC > Digital; + * + * @param channel ADC2 channel to read + * @param width_bit Bit capture width for ADC2 + * @param raw_out the variable to hold the output data. + * + * @return + * - ESP_OK if success + * - ESP_ERR_TIMEOUT ADC2 is being used by other controller and the request timed out. + * - ESP_ERR_INVALID_STATE The controller status is invalid. Please try again. + */ +esp_err_t adc2_get_raw(adc2_channel_t channel, adc_bits_width_t width_bit, int *raw_out); + +/** + * @brief Output ADC1 or ADC2's reference voltage to ``adc2_channe_t``'s IO. + * + * This function routes the internal reference voltage of ADCn to one of + * ADC2's channels. This reference voltage can then be manually measured + * for calibration purposes. + * + * @note ESP32 only supports output of ADC2's internal reference voltage. + * @param[in] adc_unit ADC unit index + * @param[in] gpio GPIO number (Only ADC2's channels IO are supported) + * + * @return + * - ESP_OK: v_ref successfully routed to selected GPIO + * - ESP_ERR_INVALID_ARG: Unsupported GPIO + */ +esp_err_t adc_vref_to_gpio(adc_unit_t adc_unit, gpio_num_t gpio); + +/** + * @brief Output ADC2 reference voltage to ``adc2_channe_t``'s IO. + * + * This function routes the internal reference voltage of ADCn to one of + * ADC2's channels. This reference voltage can then be manually measured + * for calibration purposes. + * + * @deprecated Use ``adc_vref_to_gpio`` instead. + * + * @param[in] gpio GPIO number (ADC2's channels are supported) + * + * @return + * - ESP_OK: v_ref successfully routed to selected GPIO + * - ESP_ERR_INVALID_ARG: Unsupported GPIO + */ +esp_err_t adc2_vref_to_gpio(gpio_num_t gpio) __attribute__((deprecated)); + +/*--------------------------------------------------------------- + DMA setting +---------------------------------------------------------------*/ +/** + * @brief Digital ADC DMA read max timeout value, it may make the ``adc_digi_read_bytes`` block forever if the OS supports + */ +#define ADC_MAX_DELAY UINT32_MAX + +/** + * @brief ADC DMA driver configuration + */ +typedef struct adc_digi_init_config_s { + uint32_t max_store_buf_size; ///< Max length of the converted data that driver can store before they are processed. + uint32_t conv_num_each_intr; ///< Bytes of data that can be converted in 1 interrupt. + uint32_t adc1_chan_mask; ///< Channel list of ADC1 to be initialized. + uint32_t adc2_chan_mask; ///< Channel list of ADC2 to be initialized. +} adc_digi_init_config_t; + +/** + * @brief ADC digital controller settings + */ +typedef struct { + bool conv_limit_en; ///< To limit ADC conversion times. Conversion stops after finishing `conv_limit_num` times conversion + uint32_t conv_limit_num; ///< Set the upper limit of the number of ADC conversion triggers. Range: 1 ~ 255. + uint32_t pattern_num; ///< Number of ADC channels that will be used + adc_digi_pattern_config_t *adc_pattern; ///< List of configs for each ADC channel that will be used + uint32_t sample_freq_hz; /*!< The expected ADC sampling frequency in Hz. Range: 611Hz ~ 83333Hz + Fs = Fd / interval / 2 + Fs: sampling frequency; + Fd: digital controller frequency, no larger than 5M for better performance + interval: interval between 2 measurement trigger signal, the smallest interval should not be smaller than the ADC measurement period, the largest interval should not be larger than 4095 */ + adc_digi_convert_mode_t conv_mode; ///< ADC DMA conversion mode, see `adc_digi_convert_mode_t`. + adc_digi_output_format_t format; ///< ADC DMA conversion output format, see `adc_digi_output_format_t`. +} adc_digi_configuration_t; + +/** + * @brief Initialize the Digital ADC. + * + * @param init_config Pointer to Digital ADC initilization config. Refer to ``adc_digi_init_config_t``. + * + * @return + * - ESP_ERR_INVALID_ARG If the combination of arguments is invalid. + * - ESP_ERR_NOT_FOUND No free interrupt found with the specified flags + * - ESP_ERR_NO_MEM If out of memory + * - ESP_OK On success + */ +esp_err_t adc_digi_initialize(const adc_digi_init_config_t *init_config); + +/** + * @brief Read bytes from Digital ADC through DMA. + * + * @param[out] buf Buffer to read from ADC. + * @param[in] length_max Expected length of data read from the ADC. + * @param[out] out_length Real length of data read from the ADC via this API. + * @param[in] timeout_ms Time to wait for data via this API, in millisecond. + * + * @return + * - ESP_ERR_INVALID_STATE Driver state is invalid. Usually it means the ADC sampling rate is faster than the task processing rate. + * - ESP_ERR_TIMEOUT Operation timed out + * - ESP_OK On success + */ +esp_err_t adc_digi_read_bytes(uint8_t *buf, uint32_t length_max, uint32_t *out_length, uint32_t timeout_ms); + +/** + * @brief Start the Digital ADC and DMA peripherals. After this, the hardware starts working. + * + * @return + * - ESP_ERR_INVALID_STATE Driver state is invalid. + * - ESP_OK On success + */ +esp_err_t adc_digi_start(void); + +/** + * @brief Stop the Digital ADC and DMA peripherals. After this, the hardware stops working. + * + * @return + * - ESP_ERR_INVALID_STATE Driver state is invalid. + * - ESP_OK On success + */ +esp_err_t adc_digi_stop(void); + +/** + * @brief Deinitialize the Digital ADC. + * + * @return + * - ESP_ERR_INVALID_STATE Driver state is invalid. + * - ESP_OK On success + */ +esp_err_t adc_digi_deinitialize(void); + +/** + * @brief Setting the digital controller. + * + * @param config Pointer to digital controller paramter. Refer to ``adc_digi_config_t``. + * + * @return + * - ESP_ERR_INVALID_STATE Driver state is invalid. + * - ESP_ERR_INVALID_ARG If the combination of arguments is invalid. + * - ESP_OK On success + */ +esp_err_t adc_digi_controller_configure(const adc_digi_configuration_t *config); + + +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 +//TODO IDF-3610 +/** + * @brief Reset adc digital controller filter. + * + * @param idx Filter index. + * + * @return + * - ESP_OK Success + */ +esp_err_t adc_digi_filter_reset(adc_digi_filter_idx_t idx); + +/** + * @brief Set adc digital controller filter configuration. + * + * @note For ESP32S2, Filter IDX0/IDX1 can only be used to filter all enabled channels of ADC1/ADC2 unit at the same time. + * + * @param idx Filter index. + * @param config See ``adc_digi_filter_t``. + * + * @return + * - ESP_OK Success + */ +esp_err_t adc_digi_filter_set_config(adc_digi_filter_idx_t idx, adc_digi_filter_t *config); + +/** + * @brief Get adc digital controller filter configuration. + * + * @note For ESP32S2, Filter IDX0/IDX1 can only be used to filter all enabled channels of ADC1/ADC2 unit at the same time. + * + * @param idx Filter index. + * @param config See ``adc_digi_filter_t``. + * + * @return + * - ESP_OK Success + */ +esp_err_t adc_digi_filter_get_config(adc_digi_filter_idx_t idx, adc_digi_filter_t *config); + +/** + * @brief Enable/disable adc digital controller filter. + * Filtering the ADC data to obtain smooth data at higher sampling rates. + * + * @note For ESP32S2, Filter IDX0/IDX1 can only be used to filter all enabled channels of ADC1/ADC2 unit at the same time. + * + * @param idx Filter index. + * @param enable Enable/Disable filter. + * + * @return + * - ESP_OK Success + */ +esp_err_t adc_digi_filter_enable(adc_digi_filter_idx_t idx, bool enable); + +/** + * @brief Config monitor of adc digital controller. + * + * @note For ESP32S2, The monitor will monitor all the enabled channel data of the each ADC unit at the same time. + * + * @param idx Monitor index. + * @param config See ``adc_digi_monitor_t``. + * + * @return + * - ESP_OK Success + */ +esp_err_t adc_digi_monitor_set_config(adc_digi_monitor_idx_t idx, adc_digi_monitor_t *config); + +/** + * @brief Enable/disable monitor of adc digital controller. + * + * @note For ESP32S2, The monitor will monitor all the enabled channel data of the each ADC unit at the same time. + * + * @param idx Monitor index. + * @param enable True or false enable monitor. + * + * @return + * - ESP_OK Success + */ +esp_err_t adc_digi_monitor_enable(adc_digi_monitor_idx_t idx, bool enable); +#endif //#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 + +#if CONFIG_IDF_TARGET_ESP32 +//TODO IDF-3610 +/** + * @brief Read Hall Sensor + * + * @note When the power switch of SARADC1, SARADC2, HALL sensor and AMP sensor is turned on, + * the input of GPIO36 and GPIO39 will be pulled down for about 80ns. + * When enabling power for any of these peripherals, ignore input from GPIO36 and GPIO39. + * Please refer to section 3.11 of 'ECO_and_Workarounds_for_Bugs_in_ESP32' for the description of this issue. + * + * @note The Hall Sensor uses channels 0 and 3 of ADC1. Do not configure + * these channels for use as ADC channels. + * + * @note The ADC1 module must be enabled by calling + * adc1_config_width() before calling hall_sensor_read(). ADC1 + * should be configured for 12 bit readings, as the hall sensor + * readings are low values and do not cover the full range of the + * ADC. + * + * @return The hall sensor reading. + */ +int hall_sensor_read(void); + +/*--------------------------------------------------------------- + To Be Deprecated TODO: IDF-3610 +---------------------------------------------------------------*/ +/** + * @brief Set I2S data source + * @param src I2S DMA data source, I2S DMA can get data from digital signals or from ADC. + * @return + * - ESP_OK success + */ +esp_err_t adc_set_i2s_data_source(adc_i2s_source_t src); + +/** + * @brief Initialize I2S ADC mode + * @param adc_unit ADC unit index + * @param channel ADC channel index + * @return + * - ESP_OK success + * - ESP_ERR_INVALID_ARG Parameter error + */ +esp_err_t adc_i2s_mode_init(adc_unit_t adc_unit, adc_channel_t channel); +#endif + +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/esp32/include/driver/include/driver/adc_common.h b/tools/sdk/esp32/include/driver/include/driver/adc_common.h index 392eb8a15dc..e081f28d154 100644 --- a/tools/sdk/esp32/include/driver/include/driver/adc_common.h +++ b/tools/sdk/esp32/include/driver/include/driver/adc_common.h @@ -1,544 +1,11 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ -#pragma once - -#include -#include -#include "esp_err.h" -#include "sdkconfig.h" -#include "driver/gpio.h" -#include "hal/adc_types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#if CONFIG_IDF_TARGET_ESP32 -/**** `adc1_channel_t` will be deprecated functions, combine into `adc_channel_t` ********/ -typedef enum { - ADC1_CHANNEL_0 = 0, /*!< ADC1 channel 0 is GPIO36 */ - ADC1_CHANNEL_1, /*!< ADC1 channel 1 is GPIO37 */ - ADC1_CHANNEL_2, /*!< ADC1 channel 2 is GPIO38 */ - ADC1_CHANNEL_3, /*!< ADC1 channel 3 is GPIO39 */ - ADC1_CHANNEL_4, /*!< ADC1 channel 4 is GPIO32 */ - ADC1_CHANNEL_5, /*!< ADC1 channel 5 is GPIO33 */ - ADC1_CHANNEL_6, /*!< ADC1 channel 6 is GPIO34 */ - ADC1_CHANNEL_7, /*!< ADC1 channel 7 is GPIO35 */ - ADC1_CHANNEL_MAX, -} adc1_channel_t; -#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 // TODO ESP32-S3 channels are wrong IDF-1776 -/**** `adc1_channel_t` will be deprecated functions, combine into `adc_channel_t` ********/ -typedef enum { - ADC1_CHANNEL_0 = 0, /*!< ADC1 channel 0 is GPIO1 */ - ADC1_CHANNEL_1, /*!< ADC1 channel 1 is GPIO2 */ - ADC1_CHANNEL_2, /*!< ADC1 channel 2 is GPIO3 */ - ADC1_CHANNEL_3, /*!< ADC1 channel 3 is GPIO4 */ - ADC1_CHANNEL_4, /*!< ADC1 channel 4 is GPIO5 */ - ADC1_CHANNEL_5, /*!< ADC1 channel 5 is GPIO6 */ - ADC1_CHANNEL_6, /*!< ADC1 channel 6 is GPIO7 */ - ADC1_CHANNEL_7, /*!< ADC1 channel 7 is GPIO8 */ - ADC1_CHANNEL_8, /*!< ADC1 channel 8 is GPIO9 */ - ADC1_CHANNEL_9, /*!< ADC1 channel 9 is GPIO10 */ - ADC1_CHANNEL_MAX, -} adc1_channel_t; -#elif CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2 -/**** `adc1_channel_t` will be deprecated functions, combine into `adc_channel_t` ********/ -typedef enum { - ADC1_CHANNEL_0 = 0, /*!< ADC1 channel 0 is GPIO0 */ - ADC1_CHANNEL_1, /*!< ADC1 channel 1 is GPIO1 */ - ADC1_CHANNEL_2, /*!< ADC1 channel 2 is GPIO2 */ - ADC1_CHANNEL_3, /*!< ADC1 channel 3 is GPIO3 */ - ADC1_CHANNEL_4, /*!< ADC1 channel 4 is GPIO4 */ - ADC1_CHANNEL_MAX, -} adc1_channel_t; -#endif // CONFIG_IDF_TARGET_* - -#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 // TODO ESP32-S3 channels are wrong IDF-1776 -/**** `adc2_channel_t` will be deprecated functions, combine into `adc_channel_t` ********/ -typedef enum { - ADC2_CHANNEL_0 = 0, /*!< ADC2 channel 0 is GPIO4 (ESP32), GPIO11 (ESP32-S2) */ - ADC2_CHANNEL_1, /*!< ADC2 channel 1 is GPIO0 (ESP32), GPIO12 (ESP32-S2) */ - ADC2_CHANNEL_2, /*!< ADC2 channel 2 is GPIO2 (ESP32), GPIO13 (ESP32-S2) */ - ADC2_CHANNEL_3, /*!< ADC2 channel 3 is GPIO15 (ESP32), GPIO14 (ESP32-S2) */ - ADC2_CHANNEL_4, /*!< ADC2 channel 4 is GPIO13 (ESP32), GPIO15 (ESP32-S2) */ - ADC2_CHANNEL_5, /*!< ADC2 channel 5 is GPIO12 (ESP32), GPIO16 (ESP32-S2) */ - ADC2_CHANNEL_6, /*!< ADC2 channel 6 is GPIO14 (ESP32), GPIO17 (ESP32-S2) */ - ADC2_CHANNEL_7, /*!< ADC2 channel 7 is GPIO27 (ESP32), GPIO18 (ESP32-S2) */ - ADC2_CHANNEL_8, /*!< ADC2 channel 8 is GPIO25 (ESP32), GPIO19 (ESP32-S2) */ - ADC2_CHANNEL_9, /*!< ADC2 channel 9 is GPIO26 (ESP32), GPIO20 (ESP32-S2) */ - ADC2_CHANNEL_MAX, -} adc2_channel_t; -#elif CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2 -/**** `adc2_channel_t` will be deprecated functions, combine into `adc_channel_t` ********/ -typedef enum { - ADC2_CHANNEL_0 = 0, /*!< ADC2 channel 0 is GPIO5 */ - ADC2_CHANNEL_MAX, -} adc2_channel_t; -#endif - - -/** - * @brief ADC rtc controller attenuation option. - * - * @note This definitions are only for being back-compatible - */ -#define ADC_ATTEN_0db ADC_ATTEN_DB_0 -#define ADC_ATTEN_2_5db ADC_ATTEN_DB_2_5 -#define ADC_ATTEN_6db ADC_ATTEN_DB_6 -#define ADC_ATTEN_11db ADC_ATTEN_DB_11 - /** - * The default (max) bit width of the ADC of current version. You can also get the maximum bitwidth - * by `SOC_ADC_MAX_BITWIDTH` defined in soc_caps.h. + * This file is only a wrapper for `driver/adc.h` for back-compatability. */ -#define ADC_WIDTH_BIT_DEFAULT (ADC_WIDTH_MAX-1) - -//this definitions are only for being back-compatible -#define ADC_WIDTH_9Bit ADC_WIDTH_BIT_9 -#define ADC_WIDTH_10Bit ADC_WIDTH_BIT_10 -#define ADC_WIDTH_11Bit ADC_WIDTH_BIT_11 -#define ADC_WIDTH_12Bit ADC_WIDTH_BIT_12 - -#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2 -/** - * @brief Digital ADC DMA read max timeout value, it may make the ``adc_digi_read_bytes`` block forever if the OS supports - */ -#define ADC_MAX_DELAY UINT32_MAX -#endif - -/** - * @brief ADC digital controller encode option. - * - * @deprecated The ESP32-S2 doesn't use I2S DMA. Call ``adc_digi_output_format_t`` instead. - */ -typedef enum { - ADC_ENCODE_12BIT, /*!< ADC to DMA data format, , [15:12]-channel [11:0]-12 bits ADC data */ - ADC_ENCODE_11BIT, /*!< ADC to DMA data format, [15]-unit, [14:11]-channel [10:0]-11 bits ADC data */ - ADC_ENCODE_MAX, -} adc_i2s_encode_t; - -#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2 -//This feature is currently supported on ESP32C3, will be supported on other chips soon -/** - * @brief Digital ADC DMA configuration - */ -typedef struct adc_digi_init_config_s { - uint32_t max_store_buf_size; ///< Max length of the converted data that driver can store before they are processed. - uint32_t conv_num_each_intr; ///< Bytes of data that can be converted in 1 interrupt. - uint32_t adc1_chan_mask; ///< Channel list of ADC1 to be initialized. - uint32_t adc2_chan_mask; ///< Channel list of ADC2 to be initialized. -} adc_digi_init_config_t; -#endif - -/*--------------------------------------------------------------- - Common setting ----------------------------------------------------------------*/ - -/** - * @brief Enable ADC power - * @deprecated Use adc_power_acquire and adc_power_release instead. - */ -void adc_power_on(void) __attribute__((deprecated)); - -/** - * @brief Power off SAR ADC - * @deprecated Use adc_power_acquire and adc_power_release instead. - * This function will force power down for ADC. - * This function is deprecated because forcing power ADC power off may - * disrupt operation of other components which may be using the ADC. - */ -void adc_power_off(void) __attribute__((deprecated)); - -/** - * @brief Increment the usage counter for ADC module. - * ADC will stay powered on while the counter is greater than 0. - * Call adc_power_release when done using the ADC. - */ -void adc_power_acquire(void); - -/** - * @brief Decrement the usage counter for ADC module. - * ADC will stay powered on while the counter is greater than 0. - * Call this function when done using the ADC. - */ -void adc_power_release(void); - -#if !CONFIG_IDF_TARGET_ESP32C3 && !CONFIG_IDF_TARGET_ESP32H2 -/** - * @brief Initialize ADC pad - * @param adc_unit ADC unit index - * @param channel ADC channel index - * @return - * - ESP_OK success - * - ESP_ERR_INVALID_ARG Parameter error - */ -esp_err_t adc_gpio_init(adc_unit_t adc_unit, adc_channel_t channel); -#endif //#if !CONFIG_IDF_TARGET_ESP32C3 && !CONFIG_IDF_TARGET_ESP32H2 - -/*--------------------------------------------------------------- - ADC Single Read Setting ----------------------------------------------------------------*/ -/** - * @brief Get the GPIO number of a specific ADC1 channel. - * - * @param channel Channel to get the GPIO number - * @param gpio_num output buffer to hold the GPIO number - * - * @return - * - ESP_OK if success - * - ESP_ERR_INVALID_ARG if channel not valid - */ -esp_err_t adc1_pad_get_io_num(adc1_channel_t channel, gpio_num_t *gpio_num); - -/** - * @brief Set the attenuation of a particular channel on ADC1, and configure its associated GPIO pin mux. - * - * The default ADC voltage is for attenuation 0 dB and listed in the table below. - * By setting higher attenuation it is possible to read higher voltages. - * - * Due to ADC characteristics, most accurate results are obtained within the "suggested range" - * shown in the following table. - * - * +----------+-------------+-----------------+ - * | | attenuation | suggested range | - * | SoC | (dB) | (mV) | - * +==========+=============+=================+ - * | | 0 | 100 ~ 950 | - * | +-------------+-----------------+ - * | | 2.5 | 100 ~ 1250 | - * | ESP32 +-------------+-----------------+ - * | | 6 | 150 ~ 1750 | - * | +-------------+-----------------+ - * | | 11 | 150 ~ 2450 | - * +----------+-------------+-----------------+ - * | | 0 | 0 ~ 750 | - * | +-------------+-----------------+ - * | | 2.5 | 0 ~ 1050 | - * | ESP32-S2 +-------------+-----------------+ - * | | 6 | 0 ~ 1300 | - * | +-------------+-----------------+ - * | | 11 | 0 ~ 2500 | - * +----------+-------------+-----------------+ - * - * For maximum accuracy, use the ADC calibration APIs and measure voltages within these recommended ranges. - * - * @note For any given channel, this function must be called before the first time ``adc1_get_raw()`` is called for that channel. - * - * @note This function can be called multiple times to configure multiple - * ADC channels simultaneously. You may call ``adc1_get_raw()`` only after configuring a channel. - * - * @param channel ADC1 channel to configure - * @param atten Attenuation level - * - * @return - * - ESP_OK success - * - ESP_ERR_INVALID_ARG Parameter error - */ -esp_err_t adc1_config_channel_atten(adc1_channel_t channel, adc_atten_t atten); - -/** - * @brief Configure ADC1 capture width, meanwhile enable output invert for ADC1. - * The configuration is for all channels of ADC1 - * @param width_bit Bit capture width for ADC1 - * - * @return - * - ESP_OK success - * - ESP_ERR_INVALID_ARG Parameter error - */ -esp_err_t adc1_config_width(adc_bits_width_t width_bit); - -/** - * @brief Take an ADC1 reading from a single channel. - * @note ESP32: - * When the power switch of SARADC1, SARADC2, HALL sensor and AMP sensor is turned on, - * the input of GPIO36 and GPIO39 will be pulled down for about 80ns. - * When enabling power for any of these peripherals, ignore input from GPIO36 and GPIO39. - * Please refer to section 3.11 of 'ECO_and_Workarounds_for_Bugs_in_ESP32' for the description of this issue. - * As a workaround, call adc_power_acquire() in the app. This will result in higher power consumption (by ~1mA), - * but will remove the glitches on GPIO36 and GPIO39. - * - * @note Call ``adc1_config_width()`` before the first time this - * function is called. - * - * @note For any given channel, adc1_config_channel_atten(channel) - * must be called before the first time this function is called. Configuring - * a new channel does not prevent a previously configured channel from being read. - * - * @param channel ADC1 channel to read - * - * @return - * - -1: Parameter error - * - Other: ADC1 channel reading. - */ -int adc1_get_raw(adc1_channel_t channel); - -#if !CONFIG_IDF_TARGET_ESP32C3 && !CONFIG_IDF_TARGET_ESP32H2 -/** - * @brief Set ADC data invert - * @param adc_unit ADC unit index - * @param inv_en whether enable data invert - * @return - * - ESP_OK success - * - ESP_ERR_INVALID_ARG Parameter error - */ -esp_err_t adc_set_data_inv(adc_unit_t adc_unit, bool inv_en); - -/** - * @brief Set ADC source clock - * @param clk_div ADC clock divider, ADC clock is divided from APB clock - * @return - * - ESP_OK success - */ -esp_err_t adc_set_clk_div(uint8_t clk_div); - -/** - * @brief Configure ADC capture width. - * - * @param adc_unit ADC unit index - * @param width_bit Bit capture width for ADC unit. - * - * @return - * - ESP_OK success - * - ESP_ERR_INVALID_ARG Parameter error - */ -esp_err_t adc_set_data_width(adc_unit_t adc_unit, adc_bits_width_t width_bit); - -/** - * @brief Configure ADC1 to be usable by the ULP - * - * This function reconfigures ADC1 to be controlled by the ULP. - * Effect of this function can be reverted using ``adc1_get_raw()`` function. - * - * Note that adc1_config_channel_atten, ``adc1_config_width()`` functions need - * to be called to configure ADC1 channels, before ADC1 is used by the ULP. - */ -void adc1_ulp_enable(void); -#endif //#if !CONFIG_IDF_TARGET_ESP32C3 && !CONFIG_IDF_TARGET_ESP32H2 - -/** - * @brief Get the GPIO number of a specific ADC2 channel. - * - * @param channel Channel to get the GPIO number - * - * @param gpio_num output buffer to hold the GPIO number - * - * @return - * - ESP_OK if success - * - ESP_ERR_INVALID_ARG if channel not valid - */ -esp_err_t adc2_pad_get_io_num(adc2_channel_t channel, gpio_num_t *gpio_num); - -/** - * @brief Configure the ADC2 channel, including setting attenuation. - * - * The default ADC voltage is for attenuation 0 dB and listed in the table below. - * By setting higher attenuation it is possible to read higher voltages. - * - * Due to ADC characteristics, most accurate results are obtained within the "suggested range" - * shown in the following table. - * - * +----------+-------------+-----------------+ - * | | attenuation | suggested range | - * | SoC | (dB) | (mV) | - * +==========+=============+=================+ - * | | 0 | 100 ~ 950 | - * | +-------------+-----------------+ - * | | 2.5 | 100 ~ 1250 | - * | ESP32 +-------------+-----------------+ - * | | 6 | 150 ~ 1750 | - * | +-------------+-----------------+ - * | | 11 | 150 ~ 2450 | - * +----------+-------------+-----------------+ - * | | 0 | 0 ~ 750 | - * | +-------------+-----------------+ - * | | 2.5 | 0 ~ 1050 | - * | ESP32-S2 +-------------+-----------------+ - * | | 6 | 0 ~ 1300 | - * | +-------------+-----------------+ - * | | 11 | 0 ~ 2500 | - * +----------+-------------+-----------------+ - * - * For maximum accuracy, use the ADC calibration APIs and measure voltages within these recommended ranges. - * - * @note This function also configures the input GPIO pin mux to - * connect it to the ADC2 channel. It must be called before calling - * ``adc2_get_raw()`` for this channel. - * - * @note For any given channel, this function must be called before the first time ``adc2_get_raw()`` is called for that channel. - * - * @param channel ADC2 channel to configure - * @param atten Attenuation level - * - * @return - * - ESP_OK success - * - ESP_ERR_INVALID_ARG Parameter error - */ -esp_err_t adc2_config_channel_atten(adc2_channel_t channel, adc_atten_t atten); - -/** - * @brief Take an ADC2 reading on a single channel - * - * @note ESP32: - * When the power switch of SARADC1, SARADC2, HALL sensor and AMP sensor is turned on, - * the input of GPIO36 and GPIO39 will be pulled down for about 80ns. - * When enabling power for any of these peripherals, ignore input from GPIO36 and GPIO39. - * Please refer to section 3.11 of 'ECO_and_Workarounds_for_Bugs_in_ESP32' for the description of this issue. - * As a workaround, call adc_power_acquire() in the app. This will result in higher power consumption (by ~1mA), - * but will remove the glitches on GPIO36 and GPIO39. - * - * - * @note ESP32: - * For a given channel, ``adc2_config_channel_atten()`` - * must be called before the first time this function is called. If Wi-Fi is started via ``esp_wifi_start()``, this - * function will always fail with ``ESP_ERR_TIMEOUT``. - * - * @note ESP32-S2: - * ADC2 support hardware arbiter. The arbiter is to improve the use efficiency of ADC2. After the control right is robbed by the high priority, - * the low priority controller will read the invalid ADC2 data. Default priority: Wi-Fi > RTC > Digital; - * - * @param channel ADC2 channel to read - * @param width_bit Bit capture width for ADC2 - * @param raw_out the variable to hold the output data. - * - * @return - * - ESP_OK if success - * - ESP_ERR_TIMEOUT ADC2 is being used by other controller and the request timed out. - * - ESP_ERR_INVALID_STATE The controller status is invalid. Please try again. - */ -esp_err_t adc2_get_raw(adc2_channel_t channel, adc_bits_width_t width_bit, int *raw_out); - -/** - * @brief Output ADC1 or ADC2's reference voltage to ``adc2_channe_t``'s IO. - * - * This function routes the internal reference voltage of ADCn to one of - * ADC2's channels. This reference voltage can then be manually measured - * for calibration purposes. - * - * @note ESP32 only supports output of ADC2's internal reference voltage. - * @param[in] adc_unit ADC unit index - * @param[in] gpio GPIO number (Only ADC2's channels IO are supported) - * - * @return - * - ESP_OK: v_ref successfully routed to selected GPIO - * - ESP_ERR_INVALID_ARG: Unsupported GPIO - */ -esp_err_t adc_vref_to_gpio(adc_unit_t adc_unit, gpio_num_t gpio); - -/** - * @brief Output ADC2 reference voltage to ``adc2_channe_t``'s IO. - * - * This function routes the internal reference voltage of ADCn to one of - * ADC2's channels. This reference voltage can then be manually measured - * for calibration purposes. - * - * @deprecated Use ``adc_vref_to_gpio`` instead. - * - * @param[in] gpio GPIO number (ADC2's channels are supported) - * - * @return - * - ESP_OK: v_ref successfully routed to selected GPIO - * - ESP_ERR_INVALID_ARG: Unsupported GPIO - */ -esp_err_t adc2_vref_to_gpio(gpio_num_t gpio) __attribute__((deprecated)); - -/*--------------------------------------------------------------- - Digital controller setting ----------------------------------------------------------------*/ -#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 -//These APIs are only supported on ESP32 and ESP32-S2. On ESP32-C3 and later chips, please use ``adc_digi_initialize`` and ``adc_digi_deinitialize`` -/** - * @brief ADC digital controller initialization. - * @return - * - ESP_OK Success - */ -esp_err_t adc_digi_init(void); - -/** - * @brief ADC digital controller deinitialization. - * @return - * - ESP_OK Success - */ -esp_err_t adc_digi_deinit(void); -#endif - -/** - * @brief Setting the digital controller. - * - * @param config Pointer to digital controller paramter. Refer to ``adc_digi_config_t``. - * - * @return - * - ESP_ERR_INVALID_STATE Driver state is invalid. - * - ESP_ERR_INVALID_ARG If the combination of arguments is invalid. - * - ESP_OK On success - */ -esp_err_t adc_digi_controller_config(const adc_digi_config_t *config); - -#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2 -//This feature is currently supported on ESP32C3, will be supported on other chips soon -/*--------------------------------------------------------------- - DMA setting ----------------------------------------------------------------*/ -/** - * @brief Initialize the Digital ADC. - * - * @param init_config Pointer to Digital ADC initilization config. Refer to ``adc_digi_init_config_t``. - * - * @return - * - ESP_ERR_INVALID_ARG If the combination of arguments is invalid. - * - ESP_ERR_NOT_FOUND No free interrupt found with the specified flags - * - ESP_ERR_NO_MEM If out of memory - * - ESP_OK On success - */ -esp_err_t adc_digi_initialize(const adc_digi_init_config_t *init_config); - -/** - * @brief Start the Digital ADC and DMA peripherals. After this, the hardware starts working. - * - * @return - * - ESP_ERR_INVALID_STATE Driver state is invalid. - * - ESP_OK On success - */ -esp_err_t adc_digi_start(void); - -/** - * @brief Stop the Digital ADC and DMA peripherals. After this, the hardware stops working. - * - * @return - * - ESP_ERR_INVALID_STATE Driver state is invalid. - * - ESP_OK On success - */ -esp_err_t adc_digi_stop(void); - -/** - * @brief Read bytes from Digital ADC through DMA. - * - * @param[out] buf Buffer to read from ADC. - * @param[in] length_max Expected length of data read from the ADC. - * @param[out] out_length Real length of data read from the ADC via this API. - * @param[in] timeout_ms Time to wait for data via this API, in millisecond. - * - * @return - * - ESP_ERR_INVALID_STATE Driver state is invalid. Usually it means the ADC sampling rate is faster than the task processing rate. - * - ESP_ERR_TIMEOUT Operation timed out - * - ESP_OK On success - */ -esp_err_t adc_digi_read_bytes(uint8_t *buf, uint32_t length_max, uint32_t *out_length, uint32_t timeout_ms); - -/** - * @brief Deinitialize the Digital ADC. - * - * @return - * - ESP_ERR_INVALID_STATE Driver state is invalid. - * - ESP_OK On success - */ -esp_err_t adc_digi_deinitialize(void); - -#endif //#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2 -#ifdef __cplusplus -} -#endif +#include "adc.h" diff --git a/tools/sdk/esp32/include/driver/include/driver/adc_deprecated.h b/tools/sdk/esp32/include/driver/include/driver/adc_deprecated.h new file mode 100644 index 00000000000..bdd0547c06a --- /dev/null +++ b/tools/sdk/esp32/include/driver/include/driver/adc_deprecated.h @@ -0,0 +1,163 @@ +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/*---------------------------------------------------------------------------------- + This file contains Deprecated ADC APIs +-----------------------------------------------------------------------------------*/ + +#pragma once +#include "esp_err.h" +#include "hal/adc_types.h" +#include "driver/adc_types_deprecated.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +#if CONFIG_IDF_TARGET_ESP32S2 +/*--------------------------------------------------------------- + ESP32S2 Deprecated ADC APIs +---------------------------------------------------------------*/ +/** + * @brief Config ADC module arbiter. + * The arbiter is to improve the use efficiency of ADC2. After the control right is robbed by the high priority, + * the low priority controller will read the invalid ADC2 data, and the validity of the data can be judged by the flag bit in the data. + * + * @note Only ADC2 support arbiter. + * @note Default priority: Wi-Fi > RTC > Digital; + * @note In normal use, there is no need to call this interface to config arbiter. + * + * @param adc_unit ADC unit. + * @param config Refer to `adc_arbiter_t`. + * + * @return + * - ESP_OK Success + * - ESP_ERR_NOT_SUPPORTED ADC unit not support arbiter. + */ +esp_err_t adc_arbiter_config(adc_unit_t adc_unit, adc_arbiter_t *config) __attribute__((deprecated)); + +/** + * @brief Enable interrupt of adc digital controller by bitmask. + * + * @param adc_unit ADC unit. + * @param intr_mask Interrupt bitmask. See ``adc_digi_intr_t``. + * + * @return + * - ESP_OK Success + */ +esp_err_t adc_digi_intr_enable(adc_unit_t adc_unit, adc_digi_intr_t intr_mask) __attribute__((deprecated)); + +/** + * @brief Disable interrupt of adc digital controller by bitmask. + * + * @param adc_unit ADC unit. + * @param intr_mask Interrupt bitmask. See ``adc_digi_intr_t``. + * + * @return + * - ESP_OK Success + */ +esp_err_t adc_digi_intr_disable(adc_unit_t adc_unit, adc_digi_intr_t intr_mask) __attribute__((deprecated)); + +/** + * @brief Clear interrupt of adc digital controller by bitmask. + * + * @param adc_unit ADC unit. + * @param intr_mask Interrupt bitmask. See ``adc_digi_intr_t``. + * + * @return + * - ESP_OK Success + */ +esp_err_t adc_digi_intr_clear(adc_unit_t adc_unit, adc_digi_intr_t intr_mask) __attribute__((deprecated)); + +/** + * @brief Get interrupt status mask of adc digital controller. + * + * @param adc_unit ADC unit. + * @return + * - intr Interrupt bitmask, See ``adc_digi_intr_t``. + */ +uint32_t adc_digi_intr_get_status(adc_unit_t adc_unit) __attribute__((deprecated)); + +/** + * @brief Register ADC interrupt handler, the handler is an ISR. + * The handler will be attached to the same CPU core that this function is running on. + * + * @param fn Interrupt handler function. + * @param arg Parameter for handler function + * @param intr_alloc_flags Flags used to allocate the interrupt. One or multiple (ORred) + * ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info. + * + * @return + * - ESP_OK Success + * - ESP_ERR_NOT_FOUND Can not find the interrupt that matches the flags. + * - ESP_ERR_INVALID_ARG Function pointer error. + */ +esp_err_t adc_digi_isr_register(void (*fn)(void *), void *arg, int intr_alloc_flags) __attribute__((deprecated)); + +/** + * @brief Deregister ADC interrupt handler, the handler is an ISR. + * + * @return + * - ESP_OK Success + * - ESP_ERR_INVALID_ARG hander error. + * - ESP_FAIL ISR not be registered. + */ +esp_err_t adc_digi_isr_deregister(void) __attribute__((deprecated)); +#endif // #if CONFIG_IDF_TARGET_ESP32S2 + + +#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 +/*--------------------------------------------------------------- + ESP32, ESP32S2 Deprecated ADC APIs +---------------------------------------------------------------*/ +/** + * @brief ADC digital controller initialization. + * @return + * - ESP_OK Success + */ +esp_err_t adc_digi_init(void) __attribute__((deprecated)); + +/** + * @brief ADC digital controller deinitialization. + * @return + * - ESP_OK Success + */ +esp_err_t adc_digi_deinit(void) __attribute__((deprecated)); +#endif //#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 + + +#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 +/*--------------------------------------------------------------- + ESP32, ESP32S2, ESP32C3 Deprecated ADC APIs +---------------------------------------------------------------*/ +/** + * @brief Setting the digital controller. + * + * @param config Pointer to digital controller paramter. Refer to ``adc_digi_config_t``. + * + * @return + * - ESP_ERR_INVALID_STATE Driver state is invalid. + * - ESP_ERR_INVALID_ARG If the combination of arguments is invalid. + * - ESP_OK On success + */ +esp_err_t adc_digi_controller_config(const adc_digi_config_t *config) __attribute__((deprecated)); + +/** + * @brief Initialize ADC pad + * @param adc_unit ADC unit index + * @param channel ADC channel index + * @return + * - ESP_OK success + * - ESP_ERR_INVALID_ARG Parameter error + */ +esp_err_t adc_gpio_init(adc_unit_t adc_unit, adc_channel_t channel) __attribute__((deprecated));; +#endif //#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 + + +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/esp32/include/driver/include/driver/adc_types_deprecated.h b/tools/sdk/esp32/include/driver/include/driver/adc_types_deprecated.h new file mode 100644 index 00000000000..5d0e0dc2327 --- /dev/null +++ b/tools/sdk/esp32/include/driver/include/driver/adc_types_deprecated.h @@ -0,0 +1,203 @@ +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once +#include "esp_err.h" +#include "hal/adc_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if CONFIG_IDF_TARGET_ESP32 +/*--------------------------------------------------------------- + ESP32 Deprecated Types +---------------------------------------------------------------*/ +/** + * @brief ADC digital controller (DMA mode) conversion rules setting. + */ +typedef struct { + union { + struct { + uint8_t atten: 2; /*!< ADC sampling voltage attenuation configuration. Modification of attenuation affects the range of measurements. + 0: measurement range 0 - 800mV, + 1: measurement range 0 - 1100mV, + 2: measurement range 0 - 1350mV, + 3: measurement range 0 - 2600mV. */ + uint8_t bit_width: 2; /*!< ADC resolution. +- 0: 9 bit; +- 1: 10 bit; +- 2: 11 bit; +- 3: 12 bit. */ + int8_t channel: 4; /*!< ADC channel index. */ + }; + uint8_t val; /*! 0, then the clock output for i2s is fixed and equal to the fixed_mclk value. If fixed_mclk set, mclk_multiple won't take effect */ diff --git a/tools/sdk/esp32/include/driver/include/driver/ledc.h b/tools/sdk/esp32/include/driver/include/driver/ledc.h index bc8328cdd20..7b22f3d1779 100644 --- a/tools/sdk/esp32/include/driver/include/driver/ledc.h +++ b/tools/sdk/esp32/include/driver/include/driver/ledc.h @@ -85,6 +85,7 @@ esp_err_t ledc_timer_config(const ledc_timer_config_t* timer_conf); * @brief LEDC update channel parameters * @note Call this function to activate the LEDC updated parameters. * After ledc_set_duty, we need to call this function to update the settings. + * And the new LEDC parameters don't take effect until the next PWM cycle. * @note ledc_set_duty, ledc_set_duty_with_hpoint and ledc_update_duty are not thread-safe, do not call these functions to * control one LEDC channel in different tasks at the same time. * A thread-safe version of API is ledc_set_duty_and_update @@ -203,6 +204,9 @@ esp_err_t ledc_set_duty(ledc_mode_t speed_mode, ledc_channel_t channel, uint32_t /** * @brief LEDC get duty + * This function returns the duty at the present PWM cycle. + * You shouldn't expect the function to return the new duty in the same cycle of calling ledc_update_duty, + * because duty update doesn't take effect until the next cycle. * * @param speed_mode Select the LEDC channel group with specified speed mode. Note that not all targets support high speed mode. * @param channel LEDC channel (0 - LEDC_CHANNEL_MAX-1), select from ledc_channel_t @@ -385,7 +389,8 @@ void ledc_fade_func_uninstall(void); * Other duty operations will have to wait until the fade operation has finished. * @param speed_mode Select the LEDC channel group with specified speed mode. Note that not all targets support high speed mode. * @param channel LEDC channel number - * @param fade_mode Whether to block until fading done. + * @param fade_mode Whether to block until fading done. See ledc_types.h ledc_fade_mode_t for more info. + * Note that this function will not return until fading to the target duty if LEDC_FADE_WAIT_DONE mode is selected. * * @return * - ESP_OK Success @@ -443,9 +448,6 @@ esp_err_t ledc_set_fade_time_and_start(ledc_mode_t speed_mode, ledc_channel_t ch * - ESP_FAIL Fade function init error */ esp_err_t ledc_set_fade_step_and_start(ledc_mode_t speed_mode, ledc_channel_t channel, uint32_t target_duty, uint32_t scale, uint32_t cycle_num, ledc_fade_mode_t fade_mode); -#ifdef __cplusplus -} -#endif /** * @brief LEDC callback registration function @@ -461,3 +463,6 @@ esp_err_t ledc_set_fade_step_and_start(ledc_mode_t speed_mode, ledc_channel_t ch * - ESP_FAIL Fade function init error */ esp_err_t ledc_cb_register(ledc_mode_t speed_mode, ledc_channel_t channel, ledc_cbs_t *cbs, void *user_arg); +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/esp32/include/driver/include/driver/spi_common_internal.h b/tools/sdk/esp32/include/driver/include/driver/spi_common_internal.h index 90826c0a8e9..0704c7ddd87 100644 --- a/tools/sdk/esp32/include/driver/include/driver/spi_common_internal.h +++ b/tools/sdk/esp32/include/driver/include/driver/spi_common_internal.h @@ -110,7 +110,7 @@ bool spicommon_periph_in_use(spi_host_device_t host); bool spicommon_periph_free(spi_host_device_t host); /** - * @brief Alloc DMA for SPI Slave + * @brief Alloc DMA for SPI * * @param host_id SPI host ID * @param dma_chan DMA channel to be used @@ -122,17 +122,17 @@ bool spicommon_periph_free(spi_host_device_t host); * - ESP_ERR_NO_MEM: No enough memory * - ESP_ERR_NOT_FOUND: There is no available DMA channel */ -esp_err_t spicommon_slave_dma_chan_alloc(spi_host_device_t host_id, spi_dma_chan_t dma_chan, uint32_t *out_actual_tx_dma_chan, uint32_t *out_actual_rx_dma_chan); +esp_err_t spicommon_dma_chan_alloc(spi_host_device_t host_id, spi_dma_chan_t dma_chan, uint32_t *out_actual_tx_dma_chan, uint32_t *out_actual_rx_dma_chan); /** - * @brief Free DMA for SPI Slave + * @brief Free DMA for SPI * * @param host_id SPI host ID * * @return * - ESP_OK: On success */ -esp_err_t spicommon_slave_free_dma(spi_host_device_t host_id); +esp_err_t spicommon_dma_chan_free(spi_host_device_t host_id); /** * @brief Connect a SPI peripheral to GPIO pins diff --git a/tools/sdk/esp32/include/driver/include/driver/spi_master.h b/tools/sdk/esp32/include/driver/include/driver/spi_master.h index d6a202f848a..eaf391c8213 100644 --- a/tools/sdk/esp32/include/driver/include/driver/spi_master.h +++ b/tools/sdk/esp32/include/driver/include/driver/spi_master.h @@ -197,7 +197,7 @@ esp_err_t spi_bus_remove_device(spi_device_handle_t handle); * @param ticks_to_wait Ticks to wait until there's room in the queue; use portMAX_DELAY to * never time out. * @return - * - ESP_ERR_INVALID_ARG if parameter is invalid. This can happen if SPI_DEVICE_CS_KEEP_LOW flag is specified while + * - ESP_ERR_INVALID_ARG if parameter is invalid. This can happen if SPI_TRANS_CS_KEEP_ACTIVE flag is specified while * the bus was not acquired (`spi_device_acquire_bus()` should be called first) * - ESP_ERR_TIMEOUT if there was no room in the queue before ticks_to_wait expired * - ESP_ERR_NO_MEM if allocating DMA-capable temporary buffer failed @@ -261,7 +261,7 @@ esp_err_t spi_device_transmit(spi_device_handle_t handle, spi_transaction_t *tra * currently only portMAX_DELAY is supported. * * @return - * - ESP_ERR_INVALID_ARG if parameter is invalid. This can happen if SPI_DEVICE_CS_KEEP_LOW flag is specified while + * - ESP_ERR_INVALID_ARG if parameter is invalid. This can happen if SPI_TRANS_CS_KEEP_ACTIVE flag is specified while * the bus was not acquired (`spi_device_acquire_bus()` should be called first) * - ESP_ERR_TIMEOUT if the device cannot get control of the bus before ``ticks_to_wait`` expired * - ESP_ERR_NO_MEM if allocating DMA-capable temporary buffer failed diff --git a/tools/sdk/esp32/include/driver/include/driver/uart.h b/tools/sdk/esp32/include/driver/include/driver/uart.h index 76aa424fa27..4524516338b 100644 --- a/tools/sdk/esp32/include/driver/include/driver/uart.h +++ b/tools/sdk/esp32/include/driver/include/driver/uart.h @@ -328,7 +328,7 @@ esp_err_t uart_enable_rx_intr(uart_port_t uart_num); esp_err_t uart_disable_rx_intr(uart_port_t uart_num); /** - * @brief Disable UART TX interrupt (TX_FULL & TX_TIMEOUT INTERRUPT) + * @brief Disable UART TX interrupt (TXFIFO_EMPTY INTERRUPT) * * @param uart_num UART port number * @@ -339,7 +339,7 @@ esp_err_t uart_disable_rx_intr(uart_port_t uart_num); esp_err_t uart_disable_tx_intr(uart_port_t uart_num); /** - * @brief Enable UART TX interrupt (TX_FULL & TX_TIMEOUT INTERRUPT) + * @brief Enable UART TX interrupt (TXFIFO_EMPTY INTERRUPT) * * @param uart_num UART port number, the max port number is (UART_NUM_MAX -1). * @param enable 1: enable; 0: disable diff --git a/tools/sdk/esp32/include/esp-face/include/detect/dl_detect_define.hpp b/tools/sdk/esp32/include/esp-dl/include/detect/dl_detect_define.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/detect/dl_detect_define.hpp rename to tools/sdk/esp32/include/esp-dl/include/detect/dl_detect_define.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/dl_define.hpp b/tools/sdk/esp32/include/esp-dl/include/dl_define.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/dl_define.hpp rename to tools/sdk/esp32/include/esp-dl/include/dl_define.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/image/dl_image.hpp b/tools/sdk/esp32/include/esp-dl/include/image/dl_image.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/image/dl_image.hpp rename to tools/sdk/esp32/include/esp-dl/include/image/dl_image.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/layer/dl_layer_add2d.hpp b/tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_add2d.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/layer/dl_layer_add2d.hpp rename to tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_add2d.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/layer/dl_layer_avg_pool2d.hpp b/tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_avg_pool2d.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/layer/dl_layer_avg_pool2d.hpp rename to tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_avg_pool2d.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/layer/dl_layer_base.hpp b/tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_base.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/layer/dl_layer_base.hpp rename to tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_base.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/layer/dl_layer_concat.hpp b/tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_concat.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/layer/dl_layer_concat.hpp rename to tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_concat.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/layer/dl_layer_concat2d.hpp b/tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_concat2d.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/layer/dl_layer_concat2d.hpp rename to tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_concat2d.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/layer/dl_layer_conv2d.hpp b/tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_conv2d.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/layer/dl_layer_conv2d.hpp rename to tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_conv2d.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/layer/dl_layer_depthwise_conv2d.hpp b/tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_depthwise_conv2d.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/layer/dl_layer_depthwise_conv2d.hpp rename to tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_depthwise_conv2d.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/layer/dl_layer_expand_dims.hpp b/tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_expand_dims.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/layer/dl_layer_expand_dims.hpp rename to tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_expand_dims.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/layer/dl_layer_flatten.hpp b/tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_flatten.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/layer/dl_layer_flatten.hpp rename to tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_flatten.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/layer/dl_layer_fullyconnected.hpp b/tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_fullyconnected.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/layer/dl_layer_fullyconnected.hpp rename to tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_fullyconnected.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/layer/dl_layer_global_avg_pool2d.hpp b/tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_global_avg_pool2d.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/layer/dl_layer_global_avg_pool2d.hpp rename to tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_global_avg_pool2d.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/layer/dl_layer_global_max_pool2d.hpp b/tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_global_max_pool2d.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/layer/dl_layer_global_max_pool2d.hpp rename to tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_global_max_pool2d.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/layer/dl_layer_leakyrelu.hpp b/tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_leakyrelu.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/layer/dl_layer_leakyrelu.hpp rename to tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_leakyrelu.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/layer/dl_layer_max2d.hpp b/tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_max2d.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/layer/dl_layer_max2d.hpp rename to tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_max2d.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/layer/dl_layer_max_pool2d.hpp b/tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_max_pool2d.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/layer/dl_layer_max_pool2d.hpp rename to tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_max_pool2d.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/layer/dl_layer_min2d.hpp b/tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_min2d.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/layer/dl_layer_min2d.hpp rename to tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_min2d.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/layer/dl_layer_model.hpp b/tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_model.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/layer/dl_layer_model.hpp rename to tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_model.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/layer/dl_layer_mul2d.hpp b/tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_mul2d.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/layer/dl_layer_mul2d.hpp rename to tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_mul2d.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/layer/dl_layer_pad.hpp b/tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_pad.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/layer/dl_layer_pad.hpp rename to tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_pad.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/layer/dl_layer_prelu.hpp b/tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_prelu.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/layer/dl_layer_prelu.hpp rename to tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_prelu.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/layer/dl_layer_relu.hpp b/tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_relu.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/layer/dl_layer_relu.hpp rename to tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_relu.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/layer/dl_layer_reshape.hpp b/tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_reshape.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/layer/dl_layer_reshape.hpp rename to tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_reshape.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/layer/dl_layer_squeeze.hpp b/tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_squeeze.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/layer/dl_layer_squeeze.hpp rename to tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_squeeze.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/layer/dl_layer_sub2d.hpp b/tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_sub2d.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/layer/dl_layer_sub2d.hpp rename to tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_sub2d.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/layer/dl_layer_transpose.hpp b/tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_transpose.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/layer/dl_layer_transpose.hpp rename to tools/sdk/esp32/include/esp-dl/include/layer/dl_layer_transpose.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/math/dl_math.hpp b/tools/sdk/esp32/include/esp-dl/include/math/dl_math.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/math/dl_math.hpp rename to tools/sdk/esp32/include/esp-dl/include/math/dl_math.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/math/dl_math_matrix.hpp b/tools/sdk/esp32/include/esp-dl/include/math/dl_math_matrix.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/math/dl_math_matrix.hpp rename to tools/sdk/esp32/include/esp-dl/include/math/dl_math_matrix.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/model_zoo/cat_face_detect_mn03.hpp b/tools/sdk/esp32/include/esp-dl/include/model_zoo/cat_face_detect_mn03.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/model_zoo/cat_face_detect_mn03.hpp rename to tools/sdk/esp32/include/esp-dl/include/model_zoo/cat_face_detect_mn03.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/model_zoo/color_detector.hpp b/tools/sdk/esp32/include/esp-dl/include/model_zoo/color_detector.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/model_zoo/color_detector.hpp rename to tools/sdk/esp32/include/esp-dl/include/model_zoo/color_detector.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/model_zoo/face_recognition_112_v1_s16.hpp b/tools/sdk/esp32/include/esp-dl/include/model_zoo/face_recognition_112_v1_s16.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/model_zoo/face_recognition_112_v1_s16.hpp rename to tools/sdk/esp32/include/esp-dl/include/model_zoo/face_recognition_112_v1_s16.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/model_zoo/face_recognition_112_v1_s8.hpp b/tools/sdk/esp32/include/esp-dl/include/model_zoo/face_recognition_112_v1_s8.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/model_zoo/face_recognition_112_v1_s8.hpp rename to tools/sdk/esp32/include/esp-dl/include/model_zoo/face_recognition_112_v1_s8.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/model_zoo/face_recognition_tool.hpp b/tools/sdk/esp32/include/esp-dl/include/model_zoo/face_recognition_tool.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/model_zoo/face_recognition_tool.hpp rename to tools/sdk/esp32/include/esp-dl/include/model_zoo/face_recognition_tool.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/model_zoo/face_recognizer.hpp b/tools/sdk/esp32/include/esp-dl/include/model_zoo/face_recognizer.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/model_zoo/face_recognizer.hpp rename to tools/sdk/esp32/include/esp-dl/include/model_zoo/face_recognizer.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/model_zoo/human_face_detect_mnp01.hpp b/tools/sdk/esp32/include/esp-dl/include/model_zoo/human_face_detect_mnp01.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/model_zoo/human_face_detect_mnp01.hpp rename to tools/sdk/esp32/include/esp-dl/include/model_zoo/human_face_detect_mnp01.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/model_zoo/human_face_detect_msr01.hpp b/tools/sdk/esp32/include/esp-dl/include/model_zoo/human_face_detect_msr01.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/model_zoo/human_face_detect_msr01.hpp rename to tools/sdk/esp32/include/esp-dl/include/model_zoo/human_face_detect_msr01.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/nn/dl_nn.hpp b/tools/sdk/esp32/include/esp-dl/include/nn/dl_nn.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/nn/dl_nn.hpp rename to tools/sdk/esp32/include/esp-dl/include/nn/dl_nn.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/nn/dl_nn_add2d.hpp b/tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_add2d.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/nn/dl_nn_add2d.hpp rename to tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_add2d.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/nn/dl_nn_avg_pool2d.hpp b/tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_avg_pool2d.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/nn/dl_nn_avg_pool2d.hpp rename to tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_avg_pool2d.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/nn/dl_nn_concat.hpp b/tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_concat.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/nn/dl_nn_concat.hpp rename to tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_concat.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/nn/dl_nn_concat2d.hpp b/tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_concat2d.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/nn/dl_nn_concat2d.hpp rename to tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_concat2d.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/nn/dl_nn_conv2d.hpp b/tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_conv2d.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/nn/dl_nn_conv2d.hpp rename to tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_conv2d.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/nn/dl_nn_depthwise_conv2d.hpp b/tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_depthwise_conv2d.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/nn/dl_nn_depthwise_conv2d.hpp rename to tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_depthwise_conv2d.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/nn/dl_nn_fully_connected.hpp b/tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_fully_connected.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/nn/dl_nn_fully_connected.hpp rename to tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_fully_connected.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/nn/dl_nn_global_avg_pool2d.hpp b/tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_global_avg_pool2d.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/nn/dl_nn_global_avg_pool2d.hpp rename to tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_global_avg_pool2d.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/nn/dl_nn_global_max_pool2d.hpp b/tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_global_max_pool2d.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/nn/dl_nn_global_max_pool2d.hpp rename to tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_global_max_pool2d.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/nn/dl_nn_leakyrelu.hpp b/tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_leakyrelu.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/nn/dl_nn_leakyrelu.hpp rename to tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_leakyrelu.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/nn/dl_nn_max2d.hpp b/tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_max2d.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/nn/dl_nn_max2d.hpp rename to tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_max2d.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/nn/dl_nn_max_pool2d.hpp b/tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_max_pool2d.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/nn/dl_nn_max_pool2d.hpp rename to tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_max_pool2d.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/nn/dl_nn_min2d.hpp b/tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_min2d.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/nn/dl_nn_min2d.hpp rename to tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_min2d.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/nn/dl_nn_mul2d.hpp b/tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_mul2d.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/nn/dl_nn_mul2d.hpp rename to tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_mul2d.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/nn/dl_nn_pad.hpp b/tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_pad.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/nn/dl_nn_pad.hpp rename to tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_pad.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/nn/dl_nn_prelu.hpp b/tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_prelu.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/nn/dl_nn_prelu.hpp rename to tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_prelu.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/nn/dl_nn_relu.hpp b/tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_relu.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/nn/dl_nn_relu.hpp rename to tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_relu.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/nn/dl_nn_sub2d.hpp b/tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_sub2d.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/nn/dl_nn_sub2d.hpp rename to tools/sdk/esp32/include/esp-dl/include/nn/dl_nn_sub2d.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/tool/dl_tool.hpp b/tools/sdk/esp32/include/esp-dl/include/tool/dl_tool.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/tool/dl_tool.hpp rename to tools/sdk/esp32/include/esp-dl/include/tool/dl_tool.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/tool/dl_tool_cache.hpp b/tools/sdk/esp32/include/esp-dl/include/tool/dl_tool_cache.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/tool/dl_tool_cache.hpp rename to tools/sdk/esp32/include/esp-dl/include/tool/dl_tool_cache.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/typedef/dl_constant.hpp b/tools/sdk/esp32/include/esp-dl/include/typedef/dl_constant.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/typedef/dl_constant.hpp rename to tools/sdk/esp32/include/esp-dl/include/typedef/dl_constant.hpp diff --git a/tools/sdk/esp32/include/esp-face/include/typedef/dl_variable.hpp b/tools/sdk/esp32/include/esp-dl/include/typedef/dl_variable.hpp similarity index 100% rename from tools/sdk/esp32/include/esp-face/include/typedef/dl_variable.hpp rename to tools/sdk/esp32/include/esp-dl/include/typedef/dl_variable.hpp diff --git a/tools/sdk/esp32/include/esp-dsp/modules/common/include/dsp_common.h b/tools/sdk/esp32/include/esp-dsp/modules/common/include/dsp_common.h index 68cfc5c694d..da7b001f3d4 100644 --- a/tools/sdk/esp32/include/esp-dsp/modules/common/include/dsp_common.h +++ b/tools/sdk/esp32/include/esp-dsp/modules/common/include/dsp_common.h @@ -18,7 +18,12 @@ #include #include "dsp_err.h" #include "esp_idf_version.h" + +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0) +#include "esp_cpu.h" +#else #include "soc/cpu.h" +#endif #ifdef __cplusplus extern "C" @@ -58,4 +63,4 @@ int dsp_power_of_two(int x); #define dsp_get_cpu_cycle_count xthal_get_ccount #endif -#endif // _dsp_common_H_ \ No newline at end of file +#endif // _dsp_common_H_ diff --git a/tools/sdk/esp32/include/esp-dsp/modules/common/include/dsp_platform.h b/tools/sdk/esp32/include/esp-dsp/modules/common/include/dsp_platform.h index d04f9dc783b..239b325bd52 100644 --- a/tools/sdk/esp32/include/esp-dsp/modules/common/include/dsp_platform.h +++ b/tools/sdk/esp32/include/esp-dsp/modules/common/include/dsp_platform.h @@ -15,11 +15,16 @@ #ifndef dsp_platform_h_ #define dsp_platform_h_ +#include "esp_idf_version.h" +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0) +#include "esp_cpu.h" +#else #include "soc/cpu.h" +#endif #include "freertos/FreeRTOS.h" #include "freertos/portable.h" #include "freertos/task.h" #include "freertos/semphr.h" -#endif // dsp_platform_h_ \ No newline at end of file +#endif // dsp_platform_h_ diff --git a/tools/sdk/esp32/include/esp-dsp/modules/conv/include/dsps_conv.h b/tools/sdk/esp32/include/esp-dsp/modules/conv/include/dsps_conv.h index 7dc9e517bfa..07dbf7a2b30 100644 --- a/tools/sdk/esp32/include/esp-dsp/modules/conv/include/dsps_conv.h +++ b/tools/sdk/esp32/include/esp-dsp/modules/conv/include/dsps_conv.h @@ -43,7 +43,7 @@ extern "C" */ esp_err_t dsps_conv_f32_ae32(const float *Signal, const int siglen, const float *Kernel, const int kernlen, float *convout); esp_err_t dsps_conv_f32_ansi(const float *Signal, const int siglen, const float *Kernel, const int kernlen, float *convout); -/**}@*/ +/**@}*/ #ifdef __cplusplus } diff --git a/tools/sdk/esp32/include/esp-dsp/modules/conv/include/dsps_corr.h b/tools/sdk/esp32/include/esp-dsp/modules/conv/include/dsps_corr.h index 7104d30c4b7..06f62ca8d81 100644 --- a/tools/sdk/esp32/include/esp-dsp/modules/conv/include/dsps_corr.h +++ b/tools/sdk/esp32/include/esp-dsp/modules/conv/include/dsps_corr.h @@ -43,7 +43,7 @@ extern "C" */ esp_err_t dsps_corr_f32_ansi(const float *Signal, const int siglen, const float *Pattern, const int patlen, float *dest); esp_err_t dsps_corr_f32_ae32(const float *Signal, const int siglen, const float *Pattern, const int patlen, float *dest); -/**}@*/ +/**@}*/ #ifdef __cplusplus } diff --git a/tools/sdk/esp32/include/esp-dsp/modules/fft/include/dsps_fft2r.h b/tools/sdk/esp32/include/esp-dsp/modules/fft/include/dsps_fft2r.h index da306bf13b3..e1302f83e46 100644 --- a/tools/sdk/esp32/include/esp-dsp/modules/fft/include/dsps_fft2r.h +++ b/tools/sdk/esp32/include/esp-dsp/modules/fft/include/dsps_fft2r.h @@ -69,8 +69,6 @@ esp_err_t dsps_fft2r_init_sc16(int16_t *fft_table_buff, int table_size); * Free resources of Complex FFT. This function delete coefficients table if it was allocated by dsps_fft2r_init_fc32. * The implementation use ANSI C and could be compiled and run on any platform * - * - * @return */ void dsps_fft2r_deinit_fc32(void); void dsps_fft2r_deinit_sc16(void); @@ -128,13 +126,13 @@ esp_err_t dsps_fft2r_sc16_aes3_(int16_t *data, int N, int16_t *w); esp_err_t dsps_bit_rev_fc32_ansi(float *data, int N); esp_err_t dsps_bit_rev_sc16_ansi(int16_t *data, int N); esp_err_t dsps_bit_rev2r_fc32(float *data, int N); - -/**@{*/ +/**@}*/ esp_err_t dsps_bit_rev_lookup_fc32_ansi(float *data, int reverse_size, uint16_t *reverse_tab); esp_err_t dsps_bit_rev_lookup_fc32_ae32(float *data, int reverse_size, uint16_t *reverse_tab); esp_err_t dsps_bit_rev_lookup_fc32_aes3(float *data, int reverse_size, uint16_t *reverse_tab); +/**@{*/ /** * @brief Generate coefficients table for the FFT radix 2 * diff --git a/tools/sdk/esp32/include/esp-dsp/modules/fft/include/dsps_fft2r_platform.h b/tools/sdk/esp32/include/esp-dsp/modules/fft/include/dsps_fft2r_platform.h index 17506e7dc40..04e088d87aa 100644 --- a/tools/sdk/esp32/include/esp-dsp/modules/fft/include/dsps_fft2r_platform.h +++ b/tools/sdk/esp32/include/esp-dsp/modules/fft/include/dsps_fft2r_platform.h @@ -30,7 +30,7 @@ #if CONFIG_IDF_TARGET_ESP32S3 #define dsps_fft2r_fc32_aes3_enabled 1 #define dsps_fft2r_sc16_aes3_enabled 1 -#endif +#endif #endif // _dsps_fft2r_platform_H_ \ No newline at end of file diff --git a/tools/sdk/esp32/include/esp-dsp/modules/fft/include/dsps_fft4r.h b/tools/sdk/esp32/include/esp-dsp/modules/fft/include/dsps_fft4r.h index 0f87b6f0f5d..6443dc80d18 100644 --- a/tools/sdk/esp32/include/esp-dsp/modules/fft/include/dsps_fft4r.h +++ b/tools/sdk/esp32/include/esp-dsp/modules/fft/include/dsps_fft4r.h @@ -65,7 +65,6 @@ esp_err_t dsps_fft4r_init_fc32(float *fft_table_buff, int max_fft_size); * The implementation use ANSI C and could be compiled and run on any platform * * - * @return */ void dsps_fft4r_deinit_fc32(void); /**@}*/ @@ -115,7 +114,7 @@ esp_err_t dsps_bit_rev4r_fc32(float *data, int N); esp_err_t dsps_bit_rev4r_fc32_ae32(float *data, int N); esp_err_t dsps_bit_rev4r_direct_fc32_ansi(float *data, int N); esp_err_t dsps_bit_rev4r_sc16_ansi(int16_t *data, int N); - +/**@}*/ /**@{*/ /** diff --git a/tools/sdk/esp32/include/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts.h b/tools/sdk/esp32/include/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts.h new file mode 100644 index 00000000000..ad800303a17 --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts.h @@ -0,0 +1,135 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License +#ifndef _ESP_TTS_H_ +#define _ESP_TTS_H_ + +#include "stdlib.h" +#include "stdio.h" +#include "esp_tts_voice.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + NONE_MODE = 0, //do not play any word before playing a specific number + ALI_PAY_MODE, //play zhi fu bao shou kuan before playing a specific number + WEIXIN_PAY_MODE //play wei xin shou kuan before playing a specific number +} pay_mode_t; + +typedef void * esp_tts_handle_t; + + +/** + * @brief Init an instance of the TTS voice set structure. + * + * @param template The const esp_tts_voice_template. + * @param data The customize voice data + * @return + * - NULL: Init failed + * - Others: The instance of voice set + */ +esp_tts_voice_t *esp_tts_voice_set_init(const esp_tts_voice_t *template, void *data); + +/** + * @brief Init an instance of the TTS voice set structure. + * + * @param template The const esp_tts_voice_template. + * @param data The customize voice data + * @return + * - NULL: Init failed + * - Others: The instance of voice set + */ +void esp_tts_voice_set_free(esp_tts_voice_t *voice); + +/** + * @brief Creates an instance of the TTS structure. + * + * @param voice Voice set containing all basic phonemes. + * @return + * - NULL: Create failed + * - Others: The instance of TTS structure + */ +esp_tts_handle_t esp_tts_create(esp_tts_voice_t *voice); + +/** + * @brief parse money pronuciation. + * + * @param tts_handle Instance of TTS + * @param yuan The number of yuan + * @param jiao The number of jiao + * @param fen The number of fen + * @param mode The pay mode: please refer to pay_mode_t + * @return + * - 0: failed + * - 1: succeeded + */ +int esp_tts_parse_money(esp_tts_handle_t tts_handle, int yuan, int jiao, int fen, pay_mode_t mode); + +/** + * @brief parse Chinese PinYin pronuciation. + * + * @param tts_handle Instance of TTS + * @param pinyin PinYin string, like this "da4 jia1 hao3" + * @return + * - 0: failed + * - 1: succeeded + */ +int esp_tts_parse_pinyin(esp_tts_handle_t tts_handle, const char *pinyin); + +/** + * @brief parse Chinese string. + * + * @param tts_handle Instance of TTS + * @param str Chinese string, like this "大家好" + * @return + * - 0: failed + * - 1: succeeded + */ +int esp_tts_parse_chinese(esp_tts_handle_t tts_handle, const char *str); + +/** + * @brief output TTS voice data by stream. + * + * @Warning The output data should not be freed. + Once the output length is 0, the all voice data has been output. + * + * @param tts_handle Instance of TTS + * @param len The length of output data + * @param speed The speech speed speed of synthesized speech, + range:0~5, 0: the slowest speed, 5: the fastest speech + * @return + * - voice raw data + */ +short* esp_tts_stream_play(esp_tts_handle_t tts_handle, int *len, unsigned int speed); + +/** + * @brief reset tts stream and clean all cache of TTS instance. + * + * @param tts_handle Instance of TTS + */ +void esp_tts_stream_reset(esp_tts_handle_t tts_handle); + +/** + * @brief Free the TTS instance + * + * @param tts_handle The instance of TTS. + */ +void esp_tts_destroy(esp_tts_handle_t tts_handle); + +#ifdef __cplusplus +extern "C" { +#endif + +#endif \ No newline at end of file diff --git a/tools/sdk/esp32/include/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts_parser.h b/tools/sdk/esp32/include/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts_parser.h new file mode 100644 index 00000000000..ce71b04e319 --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts_parser.h @@ -0,0 +1,25 @@ +#ifndef _ESP_TTS_PARSER_H_ +#define _ESP_TTS_PARSER_H_ + +#include "stdlib.h" +#include "esp_tts_voice.h" + + +typedef struct { + int *syll_idx; + int syll_num; + int total_num; + esp_tts_voice_t *voice; +}esp_tts_utt_t; + +esp_tts_utt_t* esp_tts_parser_chinese (const char* str, esp_tts_voice_t *voice); + +esp_tts_utt_t* esp_tts_parser_money(char *play_tag, int yuan, int jiao, int fen, esp_tts_voice_t *voice); + +esp_tts_utt_t* esp_tts_parser_pinyin(char* pinyin, esp_tts_voice_t *voice); + +esp_tts_utt_t* esp_tts_utt_alloc(int syll_num, esp_tts_voice_t *voice); + +void esp_tts_utt_free(esp_tts_utt_t *utt); + +#endif \ No newline at end of file diff --git a/tools/sdk/esp32/include/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts_player.h b/tools/sdk/esp32/include/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts_player.h new file mode 100644 index 00000000000..2070011af41 --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts_player.h @@ -0,0 +1,67 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License +#ifndef _ESP_TTS_PLAYER_H_ +#define _ESP_TTS_PLAYER_H_ + +#include "stdlib.h" +#include "stdio.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef void * esp_tts_player_handle_t; + +/** + * @brief Creates an instance of the TTS Player structure. + * + * @param mode mode of player, default:0 + * @return + * - NULL: Create failed + * - Others: The instance of TTS Player + */ +esp_tts_player_handle_t esp_tts_player_create(int mode); + + + +/** + * @brief Concatenate audio files. + * + * @Warning Just support mono audio data. + * + * @param player The handle of TTS player + * @param file_list The dir of files + * @param file_num The number of file + * @param len The length of return audio buffer + * @param sample_rate The sample rate of input audio file + * @param sample_width The sample width of input audio file, sample_width=1:8-bit, sample_width=2:16-bit,... + * @return + * - audio data buffer + */ +unsigned char* esp_tts_stream_play_by_concat(esp_tts_player_handle_t player, const char **file_list, int file_num, int *len, int *sample_rate, int *sample_width); + + +/** + * @brief Free the TTS Player instance + * + * @param player The instance of TTS Player. + */ +void esp_tts_player_destroy(esp_tts_player_handle_t player); + +#ifdef __cplusplus +extern "C" { +#endif + +#endif \ No newline at end of file diff --git a/tools/sdk/esp32/include/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts_stretcher.h b/tools/sdk/esp32/include/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts_stretcher.h new file mode 100644 index 00000000000..ab47b272c0d --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts_stretcher.h @@ -0,0 +1,48 @@ +//////////////////////////////////////////////////////////////////////////// +// **** AUDIO-STRETCH **** // +// Time Domain Harmonic Scaler // +// Copyright (c) 2019 David Bryant // +// All Rights Reserved. // +// Distributed under the BSD Software License (see license.txt) // +//////////////////////////////////////////////////////////////////////////// + +// stretch.h + +// Time Domain Harmonic Compression and Expansion +// +// This library performs time domain harmonic scaling with pitch detection +// to stretch the timing of a 16-bit PCM signal (either mono or stereo) from +// 1/2 to 2 times its original length. This is done without altering any of +// its tonal characteristics. + +#ifndef STRETCH_H +#define STRETCH_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void *StretchHandle; + +/* extern function */ +StretchHandle stretch_init (int shortest_period, int longest_period, int num_chans, int fast_mode); +int stretch_samples (StretchHandle handle, short *samples, int num_samples, short *output, float ratio); +int stretch_flush (StretchHandle handle, short *output); +void stretch_deinit (StretchHandle handle); + +/* internel function */ +StretchHandle stretcher_init_internal(int shortest_period, int longest_period, int buff_len); +void stretcher_deinit (StretchHandle handle); +int stretcher_is_empty(StretchHandle handle); +int stretcher_is_full(StretchHandle handle, int num_samples); +int stretcher_push_data(StretchHandle handle, short *samples, int num_samples); +int stretcher_stretch_samples(StretchHandle handle, short *output, float ratio); +int stretcher_stretch_samples_flash(StretchHandle handle, short *output, float ratio, const short *period_data, + int *start_idx, int end_idx); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/tools/sdk/esp32/include/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts_voice.h b/tools/sdk/esp32/include/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts_voice.h new file mode 100644 index 00000000000..77f263e3935 --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts_voice.h @@ -0,0 +1,20 @@ +#ifndef _ESP_TTS_VOICE_H_ +#define _ESP_TTS_VOICE_H_ + +typedef struct { + char *voice_name; // voice set name + char *format; // the format of voice data, currently support pcm and amrwb + int sample_rate; // the sample rate of voice data, just for pcm format + int bit_width; // the bit width of voice data, just for pcm format + int syll_num; // the syllable mumber + char **sylls; // the syllable names + int *syll_pos; // the position of syllable in syllable audio data array + short *pinyin_idx; // the index of pinyin + short *phrase_dict; // the pinyin dictionary of common phrase + short *extern_idx; // the idx of extern phrases + short *extern_dict; // the extern phrase dictionary + unsigned char *data; // the audio data of all syllables +} esp_tts_voice_t; + + +#endif \ No newline at end of file diff --git a/tools/sdk/esp32/include/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts_voice_template.h b/tools/sdk/esp32/include/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts_voice_template.h new file mode 100644 index 00000000000..ce5f5b6f455 --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts_voice_template.h @@ -0,0 +1,5 @@ +#pragma once + + +#include "esp_tts.h" +extern const esp_tts_voice_t esp_tts_voice_template; diff --git a/tools/sdk/esp32/include/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts_voice_xiaole.h b/tools/sdk/esp32/include/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts_voice_xiaole.h new file mode 100644 index 00000000000..f87866ae6cb --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts_voice_xiaole.h @@ -0,0 +1,5 @@ +#pragma once + + +#include "esp_tts.h" +extern const esp_tts_voice_t esp_tts_voice_xiaole; diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/customized_word_wn5.h b/tools/sdk/esp32/include/esp-sr/include/esp32/customized_word_wn5.h new file mode 100644 index 00000000000..57199e5abe0 --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/customized_word_wn5.h @@ -0,0 +1,8 @@ +//Generated by mkmodel +#pragma once +#include +#include "dl_lib_coefgetter_if.h" +#include "dl_lib_matrix.h" +#include "dl_lib_matrixq.h" + +extern const model_coeff_getter_t get_coeff_customized_word_wn5; diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/dl_lib.h b/tools/sdk/esp32/include/esp-sr/include/esp32/dl_lib.h new file mode 100644 index 00000000000..d7b6d8fbe77 --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/dl_lib.h @@ -0,0 +1,411 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef DL_LIB_H +#define DL_LIB_H + +#include "dl_lib_matrix.h" +#include "dl_lib_matrixq.h" +#include "dl_lib_matrixq8.h" + +#ifdef ESP_PLATFORM +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/queue.h" +#include "esp_system.h" +#include "esp_heap_caps.h" +#include "sdkconfig.h" +#define DL_SPIRAM_SUPPORT 1 +#endif + +#ifdef CONFIG_IDF_TARGET_ESP32S3 +#include "esp32s3/rom/cache.h" +#endif + +typedef int padding_state; + +// /** +// * @brief Allocate a chunk of memory which has the given capabilities. +// * Equivalent semantics to libc malloc(), for capability-aware memory. +// * In IDF, malloc(p) is equivalent to heap_caps_malloc(p, MALLOC_CAP_8BIT). +// * +// * @param size In bytes, of the amount of memory to allocate +// * @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type of memory to be returned +// * MALLOC_CAP_SPIRAM: Memory must be in SPI RAM +// * MALLOC_CAP_INTERNAL: Memory must be internal; specifically it should not disappear when flash/spiram cache is switched off +// * MALLOC_CAP_DMA: Memory must be able to accessed by DMA +// * MALLOC_CAP_DEFAULT: Memory can be returned in a non-capability-specific memory allocation +// * @return Pointer to currently allocated heap memory +// **/ +// void *heap_caps_malloc(size_t size, uint32_t caps); + +/** + * @brief Allocate aligned memory from internal memory or external memory. + * if cnt*size > CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL, allocate memory from internal RAM + * else, allocate memory from PSRAM + * + * @param cnt Number of continuing chunks of memory to allocate + * @param size Size, in bytes, of a chunk of memory to allocate + * @param align Aligned size, in bits + * @return Pointer to currently allocated heap memory + */ +void *dl_lib_calloc(int cnt, int size, int align); + +/** + * @brief Always allocate aligned memory from external memory. + * + * @param cnt Number of continuing chunks of memory to allocate + * @param size Size, in bytes, of a chunk of memory to allocate + * @param align Aligned size, in bits + * @return Pointer to currently aligned heap memory + */ +void *dl_lib_calloc_psram(int cnt, int size, int align); + +/** + * @brief Free aligned memory allocated by `dl_lib_calloc` or `dl_lib_calloc_psram` + * + * @param prt Pointer to free + */ +void dl_lib_free(void *ptr); + +/** + * @brief Does a fast version of the exp() operation on a floating point number. + * + * As described in https://codingforspeed.com/using-faster-exponential-approximation/ + * Should be good til an input of 5 or so with a steps factor of 8. + * + * @param in Floating point input + * @param steps Approximation steps. More is more precise. 8 or 10 should be good enough for most purposes. + * @return Exp()'ed output + */ +fptp_t fast_exp(double x, int steps); + +/** + * @brief Does a fast version of the exp() operation on a floating point number. + * + * @param in Floating point input + * @return Exp()'ed output + */ +double fast_exp_pro(double x); + +/** + * @brief Does a softmax operation on a matrix. + * + * @param in Input matrix + * @param out Output matrix. Can be the same as the input matrix; if so, output results overwrite the input. + */ +void dl_softmax(const dl_matrix2d_t *in, dl_matrix2d_t *out); + + +/** + * @brief Does a softmax operation on a quantized matrix. + * + * @param in Input matrix + * @param out Output matrix. Can be the same as the input matrix; if so, output results overwrite the input. + */ +void dl_softmax_q(const dl_matrix2dq_t *in, dl_matrix2dq_t *out); + +/** + * @brief Does a sigmoid operation on a floating point number + * + * @param in Floating point input + * @return Sigmoid output + */ + +fptp_t dl_sigmoid_op(fptp_t in); + + +/** + * @brief Does a sigmoid operation on a matrix. + * + * @param in Input matrix + * @param out Output matrix. Can be the same as the input matrix; if so, output results overwrite the input. + */ +void dl_sigmoid(const dl_matrix2d_t *in, dl_matrix2d_t *out); + +/** + * @brief Does a tanh operation on a floating point number + * + * @param in Floating point input number + * @return Tanh value + */ +fptp_t dl_tanh_op(fptp_t v); + +/** + * @brief Does a tanh operation on a matrix. + * + * @param in Input matrix + * @param out Output matrix. Can be the same as the input matrix; if so, output results overwrite the input. + */ +void dl_tanh(const dl_matrix2d_t *in, dl_matrix2d_t *out); + + +/** + * @brief Does a relu (Rectifier Linear Unit) operation on a floating point number + * + * @param in Floating point input + * @param clip If value is higher than this, it will be clipped to this value + * @return Relu output + */ +fptp_t dl_relu_op(fptp_t in, fptp_t clip); + +/** + * @brief Does a ReLu operation on a matrix. + * + * @param in Input matrix + * @param clip If values are higher than this, they will be clipped to this value + * @param out Output matrix. Can be the same as the input matrix; if so, output results overwrite the input. + */ +void dl_relu(const dl_matrix2d_t *in, fptp_t clip, dl_matrix2d_t *out); + +/** + * @brief Fully connected layer operation + * + * @param in Input vector + * @param weight Weights of the neurons + * @param bias Biases for the neurons. Can be NULL if a bias of 0 is required. + * @param out Output array. Outputs are placed here. Needs to be an initialized, weight->w by in->h in size, matrix. + */ +void dl_fully_connect_layer(const dl_matrix2d_t *in, const dl_matrix2d_t *weight, const dl_matrix2d_t *bias, dl_matrix2d_t *out); + +/** + * @brief Pre-calculate the sqrtvari variable for the batch_normalize function. + * The sqrtvari matrix depends on the variance and epsilon values, which normally are constant. Hence, + * this matrix only needs to be calculated once. This function does that. + * + * @param + * @return + */ +void dl_batch_normalize_get_sqrtvar(const dl_matrix2d_t *variance, fptp_t epsilon, dl_matrix2d_t *out); + +/** + * @brief Batch-normalize a matrix + * + * @param m The matrix to normalize + * @param offset Offset matrix + * @param scale Scale matrix + * @param mean Mean matrix + * @param sqrtvari Matrix precalculated using dl_batch_normalize_get_sqrtvar + * @return + */ +void dl_batch_normalize(dl_matrix2d_t *m, const dl_matrix2d_t *offset, const dl_matrix2d_t *scale, + const dl_matrix2d_t *mean, const dl_matrix2d_t *sqrtvari); + +/** + * @brief Do a basic LSTM layer pass. + * + * @warning Returns state_h pointer, so do not free result. + + * @param in Input vector + * @param state_c Internal state of the LSTM network + * @param state_h Internal state (previous output values) of the LSTM network + * @param weights Weights for the neurons + * @param bias Bias for the neurons. Can be NULL if no bias is required + * @return Output values of the neurons + */ +dl_matrix2d_t *dl_basic_lstm_layer(const dl_matrix2d_t *in, dl_matrix2d_t *state_c, dl_matrix2d_t *state_h, + const dl_matrix2d_t *weight, const dl_matrix2d_t *bias); + +/** + * @brief Do a basic LSTM layer pass, partial quantized version. + * This LSTM function accepts 16-bit fixed-point weights and 32-bit float-point bias. + * + * @warning Returns state_h pointer, so do not free result. + + * @param in Input vector + * @param state_c Internal state of the LSTM network + * @param state_h Internal state (previous output values) of the LSTM network + * @param weights Weights for the neurons, need to be quantised + * @param bias Bias for the neurons. Can be NULL if no bias is required + * @return Output values of the neurons + */ +dl_matrix2dq_t *dl_basic_lstm_layer_quantised_weights(const dl_matrix2d_t *in, dl_matrix2d_t *state_c, dl_matrix2d_t *state_h, + const dl_matrix2dq_t *weight, const dl_matrix2d_t *bias); + +/** + * @brief Do a fully-connected layer pass, fully-quantized version. + * + * @param in Input vector + * @param weight Weights of the neurons + * @param bias Bias values of the neurons. Can be NULL if no bias is needed. + * @param shift Number of bits to shift the result back by. See dl_lib_matrixq.h for more info + * @return Output values of the neurons + */ +void dl_fully_connect_layer_q(const dl_matrix2dq_t *in, const dl_matrix2dq_t *weight, const dl_matrix2dq_t *bias, dl_matrix2dq_t *out, int shift); + +/** + * @brief Do a basic LSTM layer pass, fully-quantized version + * + * @warning Returns state_h pointer, so do not free result. + + * @param in Input vector + * @param state_c Internal state of the LSTM network + * @param state_h Internal state (previous output values) of the LSTM network + * @param weights Weights for the neurons + * @param bias Bias for the neurons. Can be NULL if no bias is required + * @param shift Number of bits to shift the result back by. See dl_lib_matrixq.h for more info + * @return Output values of the neurons + */ +dl_matrix2dq_t *dl_basic_lstm_layer_q(const dl_matrix2dq_t *in, dl_matrix2dq_t *state_c, dl_matrix2dq_t *state_h, + const dl_matrix2dq_t *weight, const dl_matrix2dq_t *bias, int shift); + +/** + * @brief Batch-normalize a matrix, fully-quantized version + * + * @param m The matrix to normalize + * @param offset Offset matrix + * @param scale Scale matrix + * @param mean Mean matrix + * @param sqrtvari Matrix precalculated using dl_batch_normalize_get_sqrtvar + * @param shift Number of bits to shift the result back by. See dl_lib_matrixq.h for more info + * @return + */ +void dl_batch_normalize_q(dl_matrix2dq_t *m, const dl_matrix2dq_t *offset, const dl_matrix2dq_t *scale, + const dl_matrix2dq_t *mean, const dl_matrix2dq_t *sqrtvari, int shift); + +/** + * @brief Does a relu (Rectifier Linear Unit) operation on a fixed-point number + * This accepts and returns fixed-point 32-bit number with the last 15 bits being the bits after the decimal + * point. (Equivalent to a mantissa in a quantized matrix with exponent -15.) + * + * @param in Fixed-point input + * @param clip If value is higher than this, it will be clipped to this value + * @return Relu output + */ +qtp_t dl_relu_q_op(qtp_t in, qtp_t clip); + +/** + * @brief Does a ReLu operation on a matrix, quantized version + * + * @param in Input matrix + * @param clip If values are higher than this, they will be clipped to this value + * @param out Output matrix. Can be the same as the input matrix; if so, output results overwrite the input. + */ +void dl_relu_q(const dl_matrix2dq_t *in, fptp_t clip, dl_matrix2dq_t *out); + +/** + * @brief Does a sigmoid operation on a fixed-point number. + * This accepts and returns a fixed-point 32-bit number with the last 15 bits being the bits after the decimal + * point. (Equivalent to a mantissa in a quantized matrix with exponent -15.) + * + * @param in Fixed-point input + * @return Sigmoid output + */ +int dl_sigmoid_op_q(const int in); +int16_t dl_sigmoid_op_q8(const int16_t in); +/** + * @brief Does a sigmoid operation on a matrix, quantized version + * + * @param in Input matrix + * @param out Output matrix. Can be the same as the input matrix; if so, output results overwrite the input. + */ +void dl_sigmoid_q(const dl_matrix2dq_t *in, dl_matrix2dq_t *out); + +/** + * @brief Does a tanh operation on a matrix, quantized version + * + * @param in Input matrix + * @param out Output matrix. Can be the same as the input matrix; if so, output results overwrite the input. + */ +void dl_tanh_q(const dl_matrix2dq_t *in, dl_matrix2dq_t *out); + +/** + * @brief Does a tanh operation on a fixed-point number. + * This accepts and returns a fixed-point 32-bit number with the last 15 bits being the bits after the decimal + * point. (Equivalent to a mantissa in a quantized matrix with exponent -15.) + * + * @param in Fixed-point input + * @return tanh output + */ +int dl_tanh_op_q(int v); +int16_t dl_tanh_op_q8(int16_t v); + +void load_mat_psram_mn4(void); +void load_mat_psram_mn3(void); +void free_mat_psram_mn4(void); +void free_mat_psram_mn3(void); +qtp_t dl_hard_sigmoid_op(qtp_t in, int exponent); +qtp_t dl_hard_tanh_op(qtp_t in, int exponent); + +int16_t dl_table_tanh_op(int16_t in, int exponent); +int16_t dl_table_sigmoid_op(int16_t in, int exponent); + +void dl_hard_sigmoid_q(const dl_matrix2dq_t *in, dl_matrix2dq_t *out); +void dl_hard_tanh_q(const dl_matrix2dq_t *in, dl_matrix2dq_t *out); + +void dl_table_sigmoid_q(const dl_matrix2dq_t *in, dl_matrix2dq_t *out); +void dl_table_tanh_q(const dl_matrix2dq_t *in, dl_matrix2dq_t *out); + + +/** + * @brief Filter out the number greater than clip in the matrix, quantized version + * + * @param in Input matrix + * @param clip If values are higher than this, they will be clipped to this value + * @param out Output matrix. Can be the same as the input matrix; if so, output results overwrite the input. + */ +void dl_minimum(const dl_matrix2d_t *in, fptp_t clip, dl_matrix2d_t *out); + +/** + * @brief Filter out the number greater than clip in the matrix, float version + * + * @param in Input matrix + * @param clip If values are higher than this, they will be clipped to this value + * @param out Output matrix. Can be the same as the input matrix; if so, output results overwrite the input. + */ +void dl_minimum_q(const dl_matrix2dq_t *in, fptp_t clip, dl_matrix2dq_t *out); +/** + * @brief Do a basic CNN layer pass. + * + * @Warning This just supports the single channel input image, and the output is single row matrix. + That is to say, the height of output is 1, and the weight of output is out_channels*out_image_width*out_image_height + * + * @param in Input single channel image + * @param weight Weights of the neurons, weight->w = out_channels, weight->h = filter_width*filter_height + * @param bias Bias for the CNN layer. + * @param filter_height The height of convolution kernel + * @param filter_width The width of convolution kernel + * @param out_channels The number of output channels of convolution kernel + * @param stride_x The step length of the convolution window in x(width) direction + * @param stride_y The step length of the convolution window in y(height) direction + * @param pad One of `"VALID"` or `"SAME"`, 0 is "VALID" and the other is "SAME" + * @param out The result of CNN layer, out->h=1. + * @return The result of CNN layer. + */ +dl_matrix2d_t *dl_basic_conv_layer(const dl_matrix2d_t *in, const dl_matrix2d_t *weight, const dl_matrix2d_t *bias, int filter_width, int filter_height, + const int out_channels, const int stride_x, const int stride_y, padding_state pad, const dl_matrix2d_t* out); + + +/** + * @brief Do a basic CNN layer pass, quantised wersion. + * + * @Warning This just supports the single channel input image, and the output is single row matrix. + That is to say, the height of output is 1, and the weight of output is out_channels*out_image_width*out_image_height + * + * @param in Input single channel image + * @param weight Weights of the neurons, weight->w = out_channels, weight->h = filter_width*filter_height, + * @param bias Bias of the neurons. + * @param filter_height The height of convolution kernel + * @param filter_width The width of convolution kernel + * @param out_channels The number of output channels of convolution kernel + * @param stride_x The step length of the convolution window in x(width) direction + * @param stride_y The step length of the convolution window in y(height) direction + * @param pad One of `"VALID"` or `"SAME"`, 0 is "VALID" and the other is "SAME" + * @param out The result of CNN layer, out->h=1 + * @return The result of CNN layer + */ +dl_matrix2d_t *dl_basic_conv_layer_quantised_weight(const dl_matrix2d_t *in, const dl_matrix2dq_t *weight, const dl_matrix2d_t *bias, int filter_width, int filter_height, + const int out_channels, const int stride_x, const int stride_y, padding_state pad, const dl_matrix2d_t* out); + +#endif + diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/dl_lib_coefgetter_if.h b/tools/sdk/esp32/include/esp-sr/include/esp32/dl_lib_coefgetter_if.h new file mode 100644 index 00000000000..f1a937343bf --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/dl_lib_coefgetter_if.h @@ -0,0 +1,72 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef DL_LIB_COEFGETTER_IF_H +#define DL_LIB_COEFGETTER_IF_H + +#include "dl_lib_matrix.h" +#include "dl_lib_matrixq.h" +#include "dl_lib_matrixq8.h" +#include "cJSON.h" + +//Set this if the coefficient requested is a batch-normalization popvar matrix which needs to be preprocessed by +//dl_batch_normalize_get_sqrtvar first. +#define COEF_GETTER_HINT_BNVAR (1<<0) + +/* +This struct describes the basic information of model data: +word_num: the number of wake words or speech commands +word_list: the name list of wake words or speech commands +thres_list: the threshold list of wake words or speech commands +info_str: the string used to reflect the version and information of model data + which consist of the architecture of network, the version of model data, wake words and their threshold +*/ +typedef struct { + int word_num; + char **word_list; + int *win_list; + float *thresh_list; + char *info_str; +} model_info_t; + +/* +Alphabet struct describes the basic grapheme or phoneme. +item_num: the number of baisc item(grapheme or phonemr) +items: the list of basic item +*/ +typedef struct { + int item_num; + char **items; +}alphabet_t; + +/* +This struct describes a generic coefficient getter: a way to get the constant coefficients needed for a neural network. +For the two getters, the name describes the name of the coefficient matrix, usually the same as the Numpy filename the +coefficient was originally stored in. The arg argument can be used to optionally pass an additional user-defined argument +to the getter (e.g. the directory to look for files in the case of the Numpy file loader getter). The hint argument +is a bitwise OR of the COEF_GETTER_HINT_* flags or 0 when none is needed. Use the free_f/free_q functions to release the +memory for the returned matrices, when applicable. +*/ +typedef struct { + const dl_matrix2d_t* (*getter_f)(const char *name, void *arg, int hint); + const dl_matrix2dq_t* (*getter_q)(const char *name, void *arg, int hint); + const dl_matrix2dq8_t* (*getter_q8)(const char *name, void *arg, int hint); + void (*free_f)(const dl_matrix2d_t *m); + void (*free_q)(const dl_matrix2dq_t *m); + void (*free_q8)(const dl_matrix2dq8_t *m); + const model_info_t* (*getter_info)(void *arg); + const alphabet_t* (*getter_alphabet)(void *arg); + const cJSON* (*getter_config)(void *arg); +} model_coeff_getter_t; + +#endif \ No newline at end of file diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/dl_lib_conv_queue.h b/tools/sdk/esp32/include/esp-sr/include/esp32/dl_lib_conv_queue.h new file mode 100644 index 00000000000..e0ca0a1d457 --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/dl_lib_conv_queue.h @@ -0,0 +1,164 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef DL_LIB_CONV_QUEUE_H +#define DL_LIB_CONV_QUEUE_H + + +#include "dl_lib_matrix.h" +typedef float fptp_t; + + +//Flags for matrices +#define DL_MF_FOREIGNDATA (1<<0) /*< Matrix *item data actually points to another matrix and should not be freed */ + +//Float convolution FIFO queue. +typedef struct { + int n; /*< the length of queue */ + int c; /*< the channel number of queue element*/ + int front; /*< the front(top) position of queue */ + int flag; /*< not used*/ + fptp_t *item; /*< Pointer to item array */ +} dl_conv_queue_t; + +/** + * @brief Allocate a convolution queue + * + * @param n The length of queue + * @param c The channel number of elements in the queue + * @return The convolution queue, or NULL if out of memory + */ +dl_conv_queue_t *dl_conv_queue_alloc(int n, int c); + +/** + * @brief Free a convolution queue + * + * @param cq The convolution queue to free + */ +void dl_conv_queue_free(dl_conv_queue_t *cq); + +void dl_conv_to_matrix2d(dl_conv_queue_t *cq, dl_matrix2d_t* out); + +/** + * @brief Move the front pointer of queue forward, + the First(oldest) element become the last(newest) element, + * + * @param cq Input convolution queue + * @return Pointer of oldest element + */ +fptp_t *dl_conv_queue_pop(dl_conv_queue_t *cq); + +/** + * @brief Remove the oldest element, then insert the input element at the end of queue + * + * @param cq Input convolution queue + * @param item The new element + */ +void dl_conv_queue_push(dl_conv_queue_t *cq, fptp_t* item); + + +/** + * @brief Get the pointer of element in the queue by offset + * + * @param cq Input convolution queue + * @param offset Offset from the front of the queue + * @return Pointer of the element + */ +fptp_t *dl_get_queue_item(dl_conv_queue_t *cq, int offset); + +/** + * @brief Does a sigmoid operation on the one of element in the convolution queue. + * Gets the pointer of element in the convolution queue by offset, and does a sigmoid operation + * by this pointer, then return the pointer + * + * @param cq Input convolution queue + * @param offset Offset from the front of the queue + * @return Pointer of the element + */ +fptp_t *dl_sigmoid_step(dl_conv_queue_t *cq, int offset); + +/** + * @brief Does a tanh operation on the one of element in the convolution queue. + * Gets the pointer of element in the convolution queue by offset, and does a tanh operation + * by this pointer, then return the pointer + * + * @param cq Input convolution queue + * @param offset Offset from the front of the queue + * @return Pointer of the element + */ +fptp_t *dl_tanh_step(dl_conv_queue_t *cq, int offset); + +/** + * @brief Does a softmax operation on the one of element in the convolution queue. + * Gets the pointer of element in the convolution queue by offset, and does a softmax operation + * by this pointer, then return the pointer + * + * @param cq Input convolution queue + * @param offset Offset from the front of the queue + * @return Pointer of the element + */ +fptp_t *dl_softmax_step(dl_conv_queue_t *cq, int offset); + +fptp_t *dl_relu_step(dl_conv_queue_t *cq, int offset); +fptp_t *dl_relu_look(dl_matrix2d_t *cq, int offset); +dl_matrix2d_t *dl_matrix_concat1(const dl_conv_queue_t *a, const dl_matrix2d_t *b); +dl_matrix2d_t *dl_basic_lstm_layer1(const dl_conv_queue_t *in, dl_matrix2d_t *state_c, dl_matrix2d_t *state_h, + const dl_matrix2d_t *weight, const dl_matrix2d_t *bias); +/** + * @brief Fast implement for 1D atrous convolution (a.k.a. convolution with holes or dilated convolution) + * based on convolution queue. + * + * @Warning All input and output convolution queue and matrix should be allocated. The return pointer + * is first element of output queue and should not be freed separately. + * + * @param in Input convolution queue + * @param out Output convolution queue + * @param rate A positive int, the stride with which we sample input value + * @param size A positive int, the size of 1D-filter + * @param kernel The kernel matrix of filter + * @param bias The bias matrix of filter. Can be NULL if a bias of 0 is required. + * @return The result of atrous convolution + */ +fptp_t *dl_atrous_conv1d_step(dl_conv_queue_t *in, dl_conv_queue_t *out, int rate, int size, + dl_matrix2d_t* kernel, dl_matrix2d_t* bias); +fptp_t *dl_look_conv_step(dl_conv_queue_t *in, dl_matrix2d_t *out, int rate, int size, + dl_matrix2d_t* kernel, dl_matrix2d_t* bias); + +/** + * @brief Fast implement of dilation layer as follows + * + * |-> [gate(sigmoid)] -| + * input - | |-> (*) - output + * |-> [filter(tanh)] -| + * + * @Warning All input and output convolution queue and matrix should be allocated. The return pointer + * is first element of output queue and should not be freed separately. + * + * @param in Input convolution queue + * @param out Output convolution queue + * @param rate A positive int, the stride with which we sample input value + * @param size A positive int, the size of 1D-filter + * @param filter_kernel The kernel matrix of filter + * @param filter_bias The bias matrix of filter. Can be NULL if a bias of 0 is required. + * @param gate_kernel The kernel matrix of gate + * @param gate_bias The bias matrix of gate. Can be NULL if a bias of 0 is required. + * @return The result of dilation layer + */ +fptp_t *dl_dilation_layer(dl_conv_queue_t *in, dl_conv_queue_t *out, int rate, int size, + dl_matrix2d_t* filter_kernel, dl_matrix2d_t* filter_bias, + dl_matrix2d_t* gate_kernel, dl_matrix2d_t* gate_bias); + + +void test_atrous_conv(int size, int rate, int in_channel, int out_channel); + +#endif \ No newline at end of file diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/dl_lib_convq8_queue.h b/tools/sdk/esp32/include/esp-sr/include/esp32/dl_lib_convq8_queue.h new file mode 100644 index 00000000000..c5964195f81 --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/dl_lib_convq8_queue.h @@ -0,0 +1,251 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef DL_LIB_CONVQ8_QUEUE_H +#define DL_LIB_CONVQ8_QUEUE_H + + +#include "dl_lib_matrixq.h" +#include "dl_lib_matrixq8.h" +#include "dl_lib_conv_queue.h" +#include "dl_lib_convq_queue.h" + +//[nch, n, c] +typedef struct { + int n; /*< the length of queue */ + int c; /*< the number of queue element*/ + int front; /*< the front(top) position of queue */ + int nch; /*< the channel of queue */ + int exponent; /*< The values in items should be multiplied by pow(2,exponent) + to get the real values */ + q8tp_t *itemq; /*< Pointer to item array */ +} dl_convq8_queue_t; + +/** + * @brief Allocate a fixed-point convolution queue + * + * @param n The length of queue + * @param c The number of elements in the queue + * @return The convolution queue, or NULL if out of memory + */ +dl_convq8_queue_t *dl_convq8_queue_alloc(int n, int c); + +/** + * @brief Allocate a fixed-point convolution queue + * + * @param n The length of queue + * @param c The number of elements in the queue + * @param c The channel of queue + * @return The convolution queue, or NULL if out of memory + */ +dl_convq8_queue_t *dl_convq8_queue_alloc_mc(int n, int c, int nch); + +/** + * @brief Free a fixed-point convolution queue + * + * @param cq The fixed-point convolution queue to free + */ +void dl_convq8_queue_free(dl_convq8_queue_t *cq); + +/** + * @brief Set itemq of convolution queue to 0 + * + * @param cq The fixed-point convolution queue to free + */ +void dl_convq8_queue_bzero(dl_convq8_queue_t *cqm); + +/** + * @brief Insert the float-point element at the end of queue. + * The precision of fixed-point numbers is described by the Qm.f notation, + * + * @param cq Input fixed-point convolution queue + * @param item The float-point element + * @param m_bit The number of integer bits including the sign bits + * @param f_bit The number of fractional bits + */ +void dl_convq8_queue_push_by_qmf(dl_convq8_queue_t *cq, fptp_t* item, int m_bit, int f_bit); + +/** + * @brief Get the pointer of element in the queue by offset + * + * @param cq Input fixed-point convolution queue + * @param offset Offset from the front of the queue + * @return Pointer of the element + */ +q8tp_t *dl_get_queue_itemq8(dl_convq8_queue_t *cq, int offset); + +/** + * @brief Get the pointer of element in the queue by offset + * + * @param cq Input fixed-point convolution queue + * @param offset Offset from the front of the queue + * @param ch Channel index of queue + * @return Pointer of the element + */ +q8tp_t *dl_get_queue_itemq8_mc(dl_convq8_queue_t *cq, int offset, int ch); + +/** + * @brief Fast and quantised implement for 1D atrous convolution (a.k.a. convolution with holes or dilated convolution) + * based on convolution queue. + * + * @Warning All input and output convolution queue and matrix should be allocated. The return pointer + * is last element of output queue and should not be freed separately. + * + * @param in Input fixed-point convolution queue + * @param out Output fixed-point convolution queue + * @param rate A positive int, the stride with which we sample input value + * @param size A positive int, the size of 1D-filter + * @param kernel Kernel matrix of filter + * @param bias The bias matrix of filter. Can be NULL if a bias of 0 is required. + * @param out_exponent Shift ratio used in dot operation between two 16-bit fixed point vector + * @param offset Offset used to calculate the beginning of input conv queue + * @param prenum The num to control the parameter size of preload operation + * @return The result of atrous convolution + */ +void dl_atrous_conv1dq8_steps(dl_convq8_queue_t *in, dl_convq8_queue_t *out, int rate, int size, + dl_matrix2dq8_t* kernel, dl_matrix2dq8_t* bias, + int out_exponent, int offset, int prenum); + +/** + * @brief Fast implement of dilation layer as follows + * + * |-> [gate(sigmoid)] -| + * input - | |-> (*) - output + * |-> [filter(tanh)] -| + * + * @Warning All input and output convolution queue and matrix should be allocated. The return pointer + * is last element of output queue and should not be freed separately. + * + * @param in Input fixed-point convolution queue + * @param out Output fixed-point convolution queue + * @param rate A positive int, the stride with which we sample input value + * @param size A positive int, the size of 1D-filter + * @param filter_kernel The kernel matrix of filter + * @param filter_bias The bias matrix of filter. Can be NULL if a bias of 0 is required. + * @param gate_kernel The kernel matrix of gate + * @param gate_bias The bias matrix of gate. Can be NULL if a bias of 0 is required. + * @param offset Offset used to calculate the beginning of input conv queue + * @param prenum The num to control the parameter size of preload operation + * @return The result of dilation layer + */ +void dl_dilation_layerq8_steps(dl_convq8_queue_t *in, dl_convq8_queue_t *out, int rate, int size, + dl_matrix2dq8_t* filter_kernel, dl_matrix2dq8_t* filter_bias, + dl_matrix2dq8_t* gate_kernel, dl_matrix2dq8_t* gate_bias, + int offset, int prenum); + + + + +dl_conv_queue_t *dl_convq8_queue_add(dl_convq8_queue_t *cq1, dl_convq8_queue_t *cq2); + +int8_t dl_sigmoid_lutq8(int in); +/** + * @brief Allocate a 8-bit fixed-point Multi-Channel convolution queue + * + * @param n The length of queue + * @param c The number of elements in the queue + * @param nch  The channel number + * @return The convolution queue, or NULL if out of memory + */ +dl_convq8_queue_t **dl_convq8_queue_mc_alloc(int n, int c, int nch); + +/** + * @brief Free a 8-bit fixed-point Multi-Channel convolution queue + * + * @param cqm The fixed-point convolution queue to free + * @param nch The channel number + */ +void dl_convq8_queue_mc_free(dl_convq8_queue_t **cqm, int nch); + +/** + * @brief Tanh activation function for 8-bit fixed-point Multi-Channel convolution queue input + * + * @param cqm Input 8-bit fixed-point Multi-Channel convolution queue + * @param offset Offset used to calculate the beginning of input conv queue + * @param nch The channel number + */ +void dl_tanh_convq8_mc(dl_convq8_queue_t **cqm, int offset, int nch); + +/** + * @brief Fast and quantised 16-bit implement for Multi-channel 1D atrous convolution (a.k.a. convolution with holes or dilated convolution) + * Usually, this layer is used as first layer for 8-bit network. + * + * @Warning All input and output convolution queue and matrix should be allocated. The return pointer + * Input is a 16-bit queue point, Output is an 8-bit queue point. + * + * @param in Input 16bit fixed-point convolution queue array + * @param out Output 8bit fixed-point convolution queue array + * @param rate A positive int, the stride with which we sample input value + * @param size A positive int, the size of 1D-filter + * @param kernel The kernel matrix of filter + * @param bias The bias matrix of filter. Can be NULL if a bias of 0 is required. + * @param out_exponent Exponent of output + * @param offset Offset used to calculate the beginning of input conv queue + * @param prenum The num to control the parameter size of preload operation + */ +void dl_atrous_conv1dq8_16in_mc_steps(dl_convq_queue_t **in, dl_convq8_queue_t **out, int nch, int rate, int size, + dl_matrix2dq_t* kernel, dl_matrix2dq_t* bias, int out_exponent, int offset, int prenum); + +/** + * @brief Fast and quantised 8-bit implement for Multi-channel 1D atrous convolution (a.k.a. convolution with holes or dilated convolution) + * based on convolution queue. + * + * @Warning All input and output convolution queue and matrix should be allocated. The return pointer + * is last element of output queue and should not be freed separately. + * + * @param in Input 8bit fixed-point convolution queue array + * @param out Output 8bit fixed-point convolution queue array + * @param rate A positive int, the stride with which we sample input value + * @param size A positive int, the size of 1D-filter + * @param kernel The kernel matrix of filter + * @param bias The bias matrix of filter. Can be NULL if a bias of 0 is required. + * @param out_exponent Exponent of output + * @param offset Offset used to calculate the beginning of input conv queue + * @param prenum The num to control the parameter size of preload operation + */ +void dl_atrous_conv1dq8_mc_steps(dl_convq8_queue_t **in, dl_convq8_queue_t **out, + int nch, int rate, int size, + dl_matrix2dq8_t* kernel, dl_matrix2dq8_t* bias, + int out_exponent, int offset, int prenum); + +/** + * @brief Fast implement of 8-bit dilation layer as follows + * + * |-> [gate(sigmoid)] -| + * input - | |-> (*) - output + * |-> [filter(tanh)] -| + * + * @Warning All input and output convolution queue and matrix should be allocated. The return pointer + * is last element of output queue and should not be freed separately. + * + * @param in Input 8-bit fixed-point convolution queue + * @param out Output 8-bit fixed-point convolution queue + * @param rate A positive int, the stride with which we sample input value + * @param size A positive int, the size of 1D-filter + * @param filter_kernel The kernel matrix of filter + * @param filter_bias The bias matrix of filter. Can be NULL if a bias of 0 is required. + * @param gate_kernel The kernel matrix of gate + * @param gate_bias The bias matrix of gate. Can be NULL if a bias of 0 is required. + * @param offset Offset used to calculate the beginning of input conv queue + * @param prenum The num to control the parameter size of preload operation + */ +void dl_dilation_layerq8_mc_steps(dl_convq8_queue_t **in, dl_convq8_queue_t **out, int nch, int rate, int size, + dl_matrix2dq8_t* filter_kernel, dl_matrix2dq8_t* filter_bias, + dl_matrix2dq8_t* gate_kernel, dl_matrix2dq8_t* gate_bias, + int offset, int prenum); + +void dl_convq8_queue_mc_bzero(dl_convq8_queue_t **cqm, int nch); + +void print_convq8(dl_convq8_queue_t *cq, int offset); +void print_convq(dl_convq_queue_t *cq, int offset); +#endif \ No newline at end of file diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/dl_lib_convq_queue.h b/tools/sdk/esp32/include/esp-sr/include/esp32/dl_lib_convq_queue.h new file mode 100644 index 00000000000..80693718f95 --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/dl_lib_convq_queue.h @@ -0,0 +1,375 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef DL_LIB_CONVQ_QUEUE_H +#define DL_LIB_CONVQ_QUEUE_H + +#include "dl_lib_matrixq.h" +#include "dl_lib_conv_queue.h" +#include "dl_lib.h" + + +//fixed-point convolution FIFO queue. +//[nch, n, c] +typedef struct { + int n; /*< the length of queue */ + int c; /*< the number of queue element*/ + int front; /*< the front(top) position of queue */ + int nch; /*< the multiple of queue*/ + int exponent; /*< The values in items should be multiplied by pow(2,exponent) + to get the real values */ + qtp_t *itemq; /*< Pointer to item array */ +} dl_convq_queue_t; + +/** + * @brief Allocate a fixed-point convolution queue + * + * @param n The length of queue + * @param c The number of elements in the queue + * @return The convolution queue, or NULL if out of memory + */ +dl_convq_queue_t *dl_convq_queue_alloc(int n, int c); + +/** + * @brief Allocate a fixed-point convolution queue from PSRAM + * + * @param n The length of queue + * @param c The number of elements in the queue + * @return The convolution queue, or NULL if out of memory + */ +dl_convq_queue_t *dl_convq_queue_alloc_from_psram(int n, int c); + +/** + * @brief Allocate a fixed-point multi-channel convolution queue + * + * @param n The length of queue + * @param c The number of elements in the queue + * @param nch The channel of conv queue + * @return The convolution queue, or NULL if out of memory + */ +dl_convq_queue_t *dl_convq_queue_alloc_mc(int n, int c, int nch); + +/** + * @brief Allocate a fixed-point multi-channel convolution queue from PSRAM + * + * @param n The length of queue + * @param c The number of elements in the queue + * @param nch The channel of conv queue + * @return The convolution queue, or NULL if out of memory + */ +dl_convq_queue_t *dl_convq_queue_alloc_mc_from_psram(int n, int c, int nch); + + +void dl_convq_to_matrix2dq(dl_convq_queue_t *cq, dl_matrix2dq_t* out, int row); + +/** + * @brief Free a fixed-point convolution queue + * + * @param cq The fixed-point convolution queue to free + */ +void dl_convq_queue_free(dl_convq_queue_t *cq); + +/** + * @brief Set itemq of convolution queue to 0 + * + * @param cq The fixed-point convolution queue point + */ +void dl_convq_queue_bzero(dl_convq_queue_t *cq); + +/** + * @brief Move the front pointer of queue forward, + the First(oldest) element become the last(newest) element, + * + * @param cq Input fixed-point convolution queue + * @return Pointer of oldest element + */ +inline qtp_t *dl_convq_queue_pop(dl_convq_queue_t *cq); +inline qtp_t *dl_convq_queue_popn(dl_convq_queue_t *cq, int n); +/** + * @brief Remove the oldest element, then insert the input element at the end of queue + * + * @param cq Input fixed-point convolution queue + * @param item The new element + */ +void dl_convq_queue_push(dl_convq_queue_t *cq, dl_matrix2dq_t *a, int shift); + +/** + * @brief Insert the float-point element at the end of queue. + * The precision of fixed-point numbers is described by the Qm.f notation, + * + * @param cq Input fixed-point convolution queue + * @param item The float-point element + * @param m_bit The number of integer bits including the sign bits + * @param f_bit The number of fractional bits + */ +void dl_convq_queue_push_by_qmf(dl_convq_queue_t *cq, fptp_t* item, int m_bit, int f_bit); + +void dl_convq16_queue_push_by_qmf(dl_convq_queue_t *cq, fptp_t* item, int m_bit, int f_bit); + +dl_conv_queue_t *dl_queue_from_convq(dl_convq_queue_t *cq1); + +/** + * @brief Get the pointer of element in the queue by offset + * + * @param cq Input fixed-point convolution queue + * @param last_num Offset from the front of the queue + * @return Pointer of the element + */ +inline qtp_t *dl_get_queue_itemq(dl_convq_queue_t *cq, int last_num); + +/** + * @brief Get the pointer of element in the queue by offset + * + * @param cq Input fixed-point convolution queue + * @param offset Offset from the front of the queue + * @param ch Channel index of convolution queue + * @return Pointer of the element + */ +qtp_t *dl_get_queue_itemq_mc(dl_convq_queue_t *cq, int offset, int ch); + +/** + * @brief Does a tanh operation on the one of element in the convolution queue. + * Gets the pointer of element in the convolution queue by offset, and does a + * tanh operation by this pointer, then return the pointer + * + * @param cq Input fixed-point convolution queue + * @param offset Offset from the front of the queue + * @return Pointer of the element + */ +void dl_tanh_convq(dl_convq_queue_t *cq, int offset); + +/** + * @brief Does a tanh operation on the one of element in multi channel convolution queue. + * Gets the pointer of element in the convolution queue by offset, and does a + * tanh operation by this pointer, then return the pointer + * + * @param cq Input fixed-point multi channnel convolution queue + * @param offset Offset from the front of the queue + * @param nch The channel number of cqm + * @return Pointer of the element + */ +void dl_tanh_convq_mc(dl_convq_queue_t **cqm, int offset, int nch); + +/** + * @brief Does a relu operation on the one of element in the convolution queue. + * Gets the pointer of element in the convolution queue by offset, and does a + * relu operation by this pointer, then return the pointer + * + * @param cq Input fixed-point convolution queue + * @param offset Offset from the front of the queue + * @return Pointer of the element + */ +void dl_relu_convq(dl_convq_queue_t *cq, fptp_t clip, int last_num); + +/** + * @brief Does a softmax operation on the one of element in the convolution queue. + * Gets the pointer of element in the convolution queue by offset, input data + stay as it is. Results are saved into the *out* array. + * + * @param cq Input fixed-point convolution queue + * @param offset Offset from the front of the queue + * @param out Old array to re-use. Passing NULL will allocate a new matrix. + * @return softmax results + */ +fptp_t * dl_softmax_step_q(dl_convq_queue_t *cq, int offset, fptp_t *out); + +/** + * @brief Fast and quantised implement for 1D atrous convolution (a.k.a. convolution with holes or dilated convolution) + * based on convolution queue. + * + * @Warning All input and output convolution queue and matrix should be allocated. The return pointer + * is last element of output queue and should not be freed separately. + * + * @param in Input fixed-point convolution queue + * @param out Output fixed-point convolution queue + * @param rate A positive int, the stride with which we sample input value + * @param size A positive int, the size of 1D-filter + * @param kernel The kernel matrix of filter + * @param bias The bias matrix of filter. Can be NULL if a bias of 0 is required. + * @param shift Shift ratio used in dot operation between two 16-bit fixed point vector + * @return The result of atrous convolution + */ +qtp_t * dl_atrous_conv1dq(dl_convq_queue_t *in, dl_convq_queue_t *out, int rate, int size, + dl_matrix2dq_t* kernel, dl_matrix2dq_t* bias, int shift, int prenum); + +/** + * @brief Fast implement of dilation layer as follows + * + * |-> [gate(sigmoid)] -| + * input - | |-> (*) - output + * |-> [filter(tanh)] -| + * + * @Warning All input and output convolution queue and matrix should be allocated. The return pointer + * is last element of output queue and should not be freed separately. + * + * @param in Input fixed-point convolution queue + * @param out Output fixed-point convolution queue + * @param rate A positive int, the stride with which we sample input value + * @param size A positive int, the size of 1D-filter + * @param filter_kernel The kernel matrix of filter + * @param filter_bias The bias matrix of filter. Can be NULL if a bias of 0 is required. + * @param gate_kernel The kernel matrix of gate + * @param gate_bias The bias matrix of gate. Can be NULL if a bias of 0 is required. + * @param filter_shift Shift ratio used in filter operation between two 16-bit fixed point vector + * @param gate_shift Shift ratio used in gate operation between two 16-bit fixed point vector + * @return The result of dilation layer + */ +qtp_t *dl_dilation_layerq_steps(dl_convq_queue_t *in, dl_convq_queue_t *out, int rate, int size, + dl_matrix2dq_t* filter_kernel, dl_matrix2dq_t* filter_bias, + dl_matrix2dq_t* gate_kernel, dl_matrix2dq_t* gate_bias, + int filter_shift, int gate_shift, int offset, int prenum); + + +qtp_t *dl_dilation_layerq(dl_convq_queue_t *in, dl_convq_queue_t *out, int rate, int size, + dl_matrix2dq_t* filter_kernel, dl_matrix2dq_t* filter_bias, + dl_matrix2dq_t* gate_kernel, dl_matrix2dq_t* gate_bias, + int filter_shift, int gate_shift, int prenum); + +qtp_t *dl_dilation_layerq16(dl_convq_queue_t *in, dl_convq_queue_t *out, int rate, int size, + dl_matrix2dq_t* filter_kernel, dl_matrix2dq_t* filter_bias, + dl_matrix2dq_t* gate_kernel, dl_matrix2dq_t* gate_bias, int prenum); + + +qtp_t *dl_atrous_conv1dq_steps(dl_convq_queue_t *in, dl_convq_queue_t *out, int rate, int size, + dl_matrix2dq_t* kernel, dl_matrix2dq_t* bias, int shift, int offset, int prenum); + +/** + * @brief Add a pair of fixed-point convolution queue item-by-item, and return float-point convolution queue + * + * @param cq1 First fixed-point convolution queue + * @param cq2 Seconf fixed-point convolution queue + * @return The result of float-point convolution queue + */ +dl_conv_queue_t *dl_convq_queue_add(dl_convq_queue_t *cq1, dl_convq_queue_t *cq2); + +/** + * @brief Fast implement of LSTM layer by dl_atrous_conv1dq function + * + * @Warning LSTM kernel is split into two part, the first part input is the last layer output, + * and kernel is parameter *in_weight*. The second part input is the last frame LSTM output, + * the kernel is parameters *h_weight*. + * + * @param in Input fixed-point convolution queue + * @param out Output fixed-point convolution queue + * @param state_c Internal state of the LSTM network + * @param state_h Internal state (previous output values) of the LSTM network + * @param in_weight the LSTM kernel needed by first part + * @param h_weight the LSTM kernel needed by second part + * @param bias The bias matrix of LSTM. Can be NULL if a bias of 0 is required. + * @in_shift Shift ratio used in first part + * @h_shift Shift ratio used in second part + * @return The result of LSTM layer + */ +dl_matrix2dq_t *dl_convq_lstm_layer(const dl_convq_queue_t *in, dl_convq_queue_t *out, dl_matrix2dq_t *state_c, + dl_matrix2dq_t *state_h, const dl_matrix2dq_t *in_weight, const dl_matrix2dq_t *h_weight, + const dl_matrix2dq_t *bias, int in_shift, int h_shift, int prenum); +dl_matrix2dq_t *dl_basic_lstm_layer1_q(const dl_convq_queue_t *in, dl_matrix2dq_t *state_c, dl_matrix2dq_t *state_h, + const dl_matrix2dq_t *weight, const dl_matrix2dq_t *bias, int step, int shift); + +dl_matrix2dq_t *dl_convq16_lstm_layer(const dl_convq_queue_t *in, dl_convq_queue_t *out, dl_matrix2dq_t *state_c, + dl_matrix2dq_t *state_h, const dl_matrix2dq_t *in_weight, const dl_matrix2dq_t *h_weight, + const dl_matrix2dq_t *bias, int prenum); + +/** + * @brief Allocate a fixed-point multi channel convolution queue + * + * @param n The length of queue + * @param c The channel number of elements in the queue + * @param nch the channel numbet of convolution queue + * @return The convolution queue, or NULL if out of memory + */ +dl_convq_queue_t **dl_convq_queue_mc_alloc(int n, int c, int nch); + +/** + * @brief Free a fixed-point multi channel convolution queue + * + * @param cqm The fixed-point convolution queue to free + * @param nch The channel number of cqm + */ +void dl_convq_queue_mc_free(dl_convq_queue_t **cqm, int nch); + +/** + * @brief Fast and quantised implement for 1D atrous convolution (a.k.a. convolution with holes or dilated convolution) + * based on convolution queue. + * + * @Warning All input and output convolution queue and matrix should be allocated. The return pointer + * is last element of output queue and should not be freed separately. + * + * @param in Input fixed-point convolution queue + * @param out Output fixed-point convolution queue + * @param nch The channel number of input + * @param rate A positive int, the stride with which we sample input value + * @param size A positive int, the size of 1D-filter + * @param kernel The kernel matrix of filter + * @param bias The bias matrix of filter. Can be NULL if a bias of 0 is required. + * @param shift Shift ratio used in dot operation between two 16-bit fixed point vector + * @param offset the offset to calculate input convq + * @param prenum the preload size, 0: do not use preload function + * @return The result of atrous convolution + */ +qtp_t *dl_atrous_conv1dq_mc_steps( dl_convq_queue_t **in, + dl_convq_queue_t **out, + int nch, + int rate, + int size, + dl_matrix2dq_t* kernel, + dl_matrix2dq_t* bias, + int shift, + int offset, + int prenum); + +/** + * @brief Fast implement of dilation layer as follows for multi channel input + * + * |-> [gate(sigmoid)] -| + * input - | |-> (*) - output + * |-> [filter(tanh)] -| + * + * @Warning All input and output convolution queue and matrix should be allocated. The return pointer + * is last element of output queue and should not be freed separately. + * + * @param in Input fixed-point convolution queue + * @param out Output fixed-point convolution queue + * @param nch The channel number of input + * @param rate A positive int, the stride with which we sample input value + * @param size A positive int, the size of 1D-filter + * @param filter_kernel The kernel matrix of filter + * @param filter_bias The bias matrix of filter. Can be NULL if a bias of 0 is required. + * @param gate_kernel The kernel matrix of gate + * @param gate_bias The bias matrix of gate. Can be NULL if a bias of 0 is required. + * @param filter_shift Shift ratio used in filter operation between two 16-bit fixed point vector + * @param gate_shift Shift ratio used in gate operation between two 16-bit fixed point vector + * @param offset The offset to calculate input convq + * @param prenum The preload size, 0: do not use preload function + * @return The result of dilation layer + */ +qtp_t *dl_dilation_layerq_mc_steps( dl_convq_queue_t **in, + dl_convq_queue_t **out, + int nch, + int rate, + int size, + dl_matrix2dq_t* filter_kernel, + dl_matrix2dq_t* filter_bias, + dl_matrix2dq_t* gate_kernel, + dl_matrix2dq_t* gate_bias, + int filter_shift, + int gate_shift, + int offset, + int prenum); + +void test_atrous_convq(int size, int rate, int in_channel, int out_channel); +void test_lstm_convq(int size, int in_dim, int lstm_cell); +void dl_nn_tanh_i162(dl_convq_queue_t **cqm, int offset, int nch); +void dl_copy_queue_item_by_qmf(dl_convq_queue_t *cq, fptp_t* item, int m_bit, int f_bit, int offset, int ch); +void dl_convq_queue_mc_bzero(dl_convq_queue_t **cqm, int nch); +#endif \ No newline at end of file diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/dl_lib_matrix.h b/tools/sdk/esp32/include/esp-sr/include/esp32/dl_lib_matrix.h new file mode 100644 index 00000000000..d046e2452f7 --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/dl_lib_matrix.h @@ -0,0 +1,252 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef DL_LIB_MATRIX_H +#define DL_LIB_MATRIX_H + +#ifdef ESP_PLATFORM +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/queue.h" +#include "esp_system.h" +#endif + +// #ifdef CONFIG_IDF_TARGET_ESP32S3 +// #include "dl_tie728_bzero.h" +// #endif + +typedef float fptp_t; + +#if CONFIG_BT_SHARE_MEM_REUSE +extern multi_heap_handle_t gst_heap; +#endif + +//Flags for matrices +#define DL_MF_FOREIGNDATA (1<<0) /*< Matrix *item data actually points to another matrix and should not be freed */ + +//'Normal' float matrix +typedef struct { + int w; /*< Width */ + int h; /*< Height */ + int stride; /*< Row stride, essentially how many items to skip to get to the same position in the next row */ + int flags; /*< Flags. OR of DL_MF_* values */ + fptp_t *item; /*< Pointer to item array */ +} dl_matrix2d_t; + +//Macro to quickly access the raw items in a matrix +#define DL_ITM(m, x, y) m->item[(x)+(y)*m->stride] + + +/** + * @brief Allocate a matrix + * + * @param w Width of the matrix + * @param h Height of the matrix + * @return The matrix, or NULL if out of memory + */ +dl_matrix2d_t *dl_matrix_alloc(int w, int h); + + +/** + * @brief Free a matrix + * Frees the matrix structure and (if it doesn't have the DL_MF_FOREIGNDATA flag set) the m->items space as well. + * + * @param m Matrix to free + */ +void dl_matrix_free(dl_matrix2d_t *m); + +/** + * @brief Zero out the matrix + * Sets all entries in the matrix to 0. + * + * @param m Matrix to zero + */ +void dl_matrix_zero(dl_matrix2d_t *m); + +/** + * @brief Copy the matrix into psram + * Copy the matrix from flash or iram/psram into psram + * + * @param m Matrix to zero + */ +dl_matrix2d_t *dl_matrix_copy_to_psram(const dl_matrix2d_t *m); + +/** + * @brief Generate a new matrix using a range of items from an existing matrix. + * When using this, the data of the new matrix is not allocated/copied but it re-uses a pointer + * to the existing data. Changing the data in the resulting matrix, as a result, will also change + * the data in the existing matrix that has been sliced. + * + * @param x X-offset of the origin of the returned matrix within the sliced matrix + * @param y Y-offset of the origin of the returned matrix within the sliced matrix + * @param w Width of the resulting matrix + * @param h Height of the resulting matrix + * @param in Old matrix (with foreign data) to re-use. Passing NULL will allocate a new matrix. + * @return The resulting slice matrix, or NULL if out of memory + */ +dl_matrix2d_t *dl_matrix_slice(const dl_matrix2d_t *src, int x, int y, int w, int h, dl_matrix2d_t *in); + +/** + * @brief select a range of items from an existing matrix and flatten them into one dimension. + * + * @Warning The results are flattened in row-major order. + * + * @param x X-offset of the origin of the returned matrix within the sliced matrix + * @param y Y-offset of the origin of the returned matrix within the sliced matrix + * @param w Width of the resulting matrix + * @param h Height of the resulting matrix + * @param in Old matrix to re-use. Passing NULL will allocate a new matrix. + * @return The resulting flatten matrix, or NULL if out of memory + */ +dl_matrix2d_t *dl_matrix_flatten(const dl_matrix2d_t *src, int x, int y, int w, int h, dl_matrix2d_t *in); + +/** + * @brief Generate a matrix from existing floating-point data + * + * @param w Width of resulting matrix + * @param h Height of resulting matrix + * @param data Data to populate matrix with + * @return A newaly allocated matrix populated with the given input data, or NULL if out of memory. + */ +dl_matrix2d_t *dl_matrix_from_data(int w, int h, int stride, const void *data); + + +/** + * @brief Multiply a pair of matrices item-by-item: res=a*b + * + * @param a First multiplicand + * @param b Second multiplicand + * @param res Multiplicated data. Can be equal to a or b to overwrite that. + */ +void dl_matrix_mul(const dl_matrix2d_t *a, const dl_matrix2d_t *b, dl_matrix2d_t *res); + +/** + * @brief Do a dotproduct of two matrices : res=a.b + * + * @param a First multiplicand + * @param b Second multiplicand + * @param res Dotproduct data. *Must* be a *different* matrix from a or b! + */ +void dl_matrix_dot(const dl_matrix2d_t *a, const dl_matrix2d_t *b, dl_matrix2d_t *res); + +/** + * @brief Add a pair of matrices item-by-item: res=a-b + * + * @param a First matrix + * @param b Second matrix + * @param res Added data. Can be equal to a or b to overwrite that. + */ +void dl_matrix_add(const dl_matrix2d_t *a, const dl_matrix2d_t *b, dl_matrix2d_t *out); + + +/** + * @brief Divide a pair of matrices item-by-item: res=a/b + * + * @param a First matrix + * @param b Second matrix + * @param res Divided data. Can be equal to a or b to overwrite that. + */ +void dl_matrix_div(const dl_matrix2d_t *a, const dl_matrix2d_t *b, dl_matrix2d_t *out); + +/** + * @brief Subtract a matrix from another, item-by-item: res=a-b + * + * @param a First matrix + * @param b Second matrix + * @param res Subtracted data. Can be equal to a or b to overwrite that. + */ +void dl_matrix_sub(const dl_matrix2d_t *a, const dl_matrix2d_t *b, dl_matrix2d_t *out); + +/** + * @brief Add a constant to every item of the matrix + * + * @param subj Matrix to add the constant to + * @param add The constant + */ +void dl_matrix_add_const(dl_matrix2d_t *subj, const fptp_t add); + + +/** + * @brief Concatenate the rows of two matrices into a new matrix + * + * @param a First matrix + * @param b Second matrix + * @return A newly allocated array with as avlues a|b + */ +dl_matrix2d_t *dl_matrix_concat(const dl_matrix2d_t *a, const dl_matrix2d_t *b); + +dl_matrix2d_t *dl_matrix_concat_h( dl_matrix2d_t *a, const dl_matrix2d_t *b); + +/** + * @brief Print the contents of a matrix to stdout. Used for debugging. + * + * @param a The matrix to print. + */ +void dl_printmatrix(const dl_matrix2d_t *a); + +/** + * @brief Return the average square error given a correct and a test matrix. + * + * ...Well, more or less. If anything, it gives an indication of the error between + * the two. Check the code for the exact implementation. + * + * @param a First of the two matrices to compare + * @param b Second of the two matrices to compare + * @return value indicating the relative difference between matrices + */ +float dl_matrix_get_avg_sq_err(const dl_matrix2d_t *a, const dl_matrix2d_t *b); + + + +/** + * @brief Check if two matrices have the same shape, that is, the same amount of rows and columns + * + * @param a First of the two matrices to compare + * @param b Second of the two matrices to compare + * @return true if the two matrices are shaped the same, false otherwise. + */ +int dl_matrix_same_shape(const dl_matrix2d_t *a, const dl_matrix2d_t *b); + + +/** + * @brief Get a specific item from the matrix + * + * Please use these for external matrix access instead of DL_ITM + * + * @param m Matrix to access + * @param x Column address + * @param y Row address + * @return Value in that position + */ +inline static fptp_t dl_matrix_get(const dl_matrix2d_t *m, const int x, const int y) { + return DL_ITM(m, x, y); +} + +/** + * @brief Set a specific item in the matrix to the given value + * + * Please use these for external matrix access instead of DL_ITM + * + * @param m Matrix to access + * @param x Column address + * @param y Row address + * @param val Value to write to that position + */ +inline static void dl_matrix_set(dl_matrix2d_t *m, const int x, const int y, fptp_t val) { + DL_ITM(m, x, y)=val; +} + +void matrix_get_range(const dl_matrix2d_t *m, fptp_t *rmin, fptp_t *rmax); + +#endif + diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/dl_lib_matrixq.h b/tools/sdk/esp32/include/esp-sr/include/esp32/dl_lib_matrixq.h new file mode 100644 index 00000000000..5f0474a08fd --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/dl_lib_matrixq.h @@ -0,0 +1,378 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef DL_LIB_MATRIXQ_H +#define DL_LIB_MATRIXQ_H + +#include +#include "dl_lib_matrix.h" + +typedef int16_t qtp_t; + +//Quantized matrix. Uses fixed numbers and has the storage for the rows/columns inverted +//for easy use as a multiplicand without stressing out the flash cache too much. +typedef struct { + int w; + int h; + int stride; //Normally equals h, not w! + int flags; + int exponent; //The values in items should be multiplied by pow(2,exponent) to get the real values. + qtp_t *itemq; +} dl_matrix2dq_t; + +#define DL_QTP_SHIFT 15 +#define DL_QTP_RANGE ((1<itemq[(y)+(x)*m->stride] +#define DL_QTP_EXP_NA 255 //non-applicable exponent because matrix is null + +#define DL_SHIFT_AUTO 32 + +/** + * @info About quantized matrices and shift values + * + * Grab a coffee (or tea, or hot water) and sit down when you read this for the first + * time. Quantized matrices can speed up your operations, but come with some quirks, and + * it's good to understand how they work before using them. + * + * The data in the quantized matrix type is stored similarily to floating-point types: + * when storing a real value, the value is stored as a mantissa (base number) and an + * exponent. The 'real' value that can be re-derived from those two numbers is something + * similar to mantissa*2^exponent. Up to this point, there's not that much difference from + * the standard floating point implementations like e.g. IEEE-754. + * + * The difference with respect to quantized matrices is that for a quantized matrix, it is + * assumed all values stored have more-or-less the same order of magnitude. This allows the + * matrix to only store all the mantissas, while the exponents are shared; there is only one + * exponent for the entire matrix. This makes it quicker to handle matrix operations - the + * logic to fix the exponents only needs to happen once, while the rest can be done in simple + * integer arithmetic. It also nets us some memory savings - while normally a floating point + * number is 32-bit, storing only 16-bit mantissas as the matrix items almost halves the + * memory requirements. + * + * While most of the details of handling the intricacies of the quantized matrixes are done + * transparently by the code in dl_lib_matrixq.c, some implementation details leak out, + * specifically in places where addition/subtraction/division happens. + * + * The problem is that the routines do not know what the size of the resulting operation is. For + * instance, when adding two matrices of numbers, the resulting numbers *could* be large enough + * to overflow the mantissa of the result if the exponent is the same. However, if by default we + * assume the mantissas needs to be scaled back, we may lose precision. + * + * In order to counter this, all operations that have this issue have a ``shift`` argument. If + * the argument is zero, the routine will be conservative, that is, increase the exponent of + * the result to such an extent it's mathematically impossible a value in the result will exceed + * the maximum value that can be stored. However, when this argument is larger than zero, the + * algorithm will hold back on this scaling by the indicated amount of bits, preserving precision + * but increasing the chance of some of the calculated values not fitting in the mantissa anymore. + * If this happens, the value will be clipped to the largest (or, for negative values, smallest) + * value possible. (Neural networks usually are okay with this happening for a limited amount + * of matrix indices). + * + * For deciding on these shift values, it is recommended to start with a shift value of one, then + * use dl_matrixq_check_sanity on the result. If this indicates clipping, lower the shift value. + * If it indicates bits are under-used, increase it. Note that for adding and subtraction, only + * shift values of 0 or 1 make sense; these routines will error out if you try to do something + * else. + * + * For neural networks and other noise-tolerant applications, note that even when + * dl_matrixq_check_sanity does not indicate any problems, twiddling with the shift value may lead + * to slightly improved precision. Feel free to experiment. + **/ + + +/** + * @brief Allocate a matrix + * + * @param w Width of the matrix + * @param h Height of the matrix + * @return The matrix, or NULL if out of memory + */ +dl_matrix2dq_t *dl_matrixq_alloc(int w, int h); +dl_matrix2dq_t *dl_matrixq_alloc_psram(int w, int h); +/** + * @brief Convert a floating-point matrix to a quantized matrix + * + * @param m Floating-point matrix to convert + * @param out Quantized matrix to re-use. If NULL, allocate a new one. + * @Return The quantized version of the floating-point matrix + */ +dl_matrix2dq_t *dl_matrixq_from_matrix2d(const dl_matrix2d_t *m, dl_matrix2dq_t *out); + +/** + * TODO: DESCRIBE THIS FUNCTION + */ +dl_matrix2dq_t *dl_matrixq_from_matrix2d_by_qmf(const dl_matrix2d_t *m, dl_matrix2dq_t *out, int m_bit, int f_bit); + + +/** + * @brief Convert a quantized matrix to a floating-point one. + * + * @param m Floating-point matrix to convert + * @param out Quantized matrix to re-use. If NULL, allocate a new one. + * @Return The quantized version of the floating-point matrix + **/ +dl_matrix2d_t *dl_matrix2d_from_matrixq(const dl_matrix2dq_t *m, dl_matrix2d_t *out); + + +/** + * @brief Free a quantized matrix + * Frees the matrix structure and (if it doesn't have the DL_MF_FOREIGNDATA flag set) the m->items space as well. + * + * @param m Matrix to free + */ +void dl_matrixq_free(dl_matrix2dq_t *m); + +/** + * @brief Zero out the matrix + * Sets all entries in the matrix to 0. + * + * @param m Matrix to zero + */ +void dl_matrixq_zero(dl_matrix2dq_t *m); + +/** + * @brief Copy the matrix into psram + * Copy the matrix from flash or iram/psram into psram + * + * @param m Matrix to copy + */ +dl_matrix2dq_t *dl_matrixq_copy_to_psram(const dl_matrix2dq_t *m); + +/** + * @brief Do a dotproduct of two quantized matrices : res=a.b, Result is a fixed-point matrix. + * + * @param a First multiplicand + * @param b Second multiplicand + * @param res Dotproduct data. *Must* be a *different* matrix from a or b! + * @param shift Shift ratio + */ +void dl_matrixq_dot(const dl_matrix2dq_t *a, const dl_matrix2dq_t *b, dl_matrix2dq_t *res, int shift); + +/** + * @brief Do a dotproduct of two quantized matrices: res=a.b, Result is a floating-point matrix. + * + * @param a First multiplicand + * @param b Second multiplicand + * @param res Dotproduct data. *Must* be a *different* matrix from a or b! + */ +void dl_matrixq_dot_matrix_out(const dl_matrix2dq_t *a, const dl_matrix2dq_t *b, dl_matrix2d_t *res); + +/** + * @brief Do a dotproduct of two quantized matrices : res=a.b. This always uses the simple & stupid C algo for the dot product. + * + * Result is a fixed-point matrix. + * + * Use this only if you expect something is wrong with the accelerated routines that dl_matrixq_dot calls; this function can be + * much slower than dl_matrixq_dot . + * + * @param a First multiplicand + * @param b Second multiplicand + * @param res Dotproduct data. *Must* be a *different* matrix from a or b! + * @param shift Shift ratio + */ +void dl_matrixq_dot_c_impl(const dl_matrix2dq_t *a, const dl_matrix2dq_t *b, dl_matrix2dq_t *res, int shift); + +/** + * @brief Do a dotproduct of two quantized matrices : res=a.b. This always uses the simple & stupid C algo for the dot product. + * + * Result is a floating-point matrix. + * + * Use this only if you expect something is wrong with the accelerated routines that dl_matrixq_dot_matrix_out calls; this function can be + * much slower than dl_matrixq_dot_matrix_out. + * + * @param a First multiplicand + * @param b Second multiplicand + * @param res Dotproduct data. *Must* be a *different* matrix from a or b! + */ +void dl_matrixq_dot_matrix_out_c_impl(const dl_matrix2dq_t *a, const dl_matrix2dq_t *b, dl_matrix2d_t *res); + +/** + * @brief Do a dotproduct of a floating point and a quantized matrix. Result is a floating-point matrix. + * + * @param a First multiplicand; float matrix + * @param b Second multiplicand; quantized matrix + * @param res Dotproduct data; float matrix. *Must* be a *different* matrix from a or b! + */ +void dl_matrix_matrixq_dot(const dl_matrix2d_t *a, const dl_matrix2dq_t *b, dl_matrix2d_t *res); + + +/** + * @brief Print the contents of a quantized matrix to stdout. Used for debugging. + * + * @param a The matrix to print. + */ +void dl_printmatrixq(const dl_matrix2dq_t *a); + + +/** + * @brief Add a pair of quantizedmatrices item-by-item: res=a-b + * + * @param a First matrix + * @param b Second matrix + * @param res Added data. Can be equal to a or b to overwrite that. + * @param shift Shift value. Only 0 or 1 makes sense here. + */ +void dl_matrixq_add(const dl_matrix2dq_t *a, const dl_matrix2dq_t *b, dl_matrix2dq_t *res, int shift); + +/** + * @brief Generate a new matrix using a range of items from an existing matrix. + * When using this, the data of the new matrix is not allocated/copied but it re-uses a pointer + * to the existing data. Changing the data in the resulting matrix, as a result, will also change + * the data in the existing matrix that has been sliced. + * + * @Warning In contrast to the floating point equivalent of this function, the fixed-point version + * of this has the issue that as soon as the output exponent of one of the slices changes, the data + * in the sliced matrix gets corrupted (because the exponent of that matrix is still the same.) If you + * use this function, either treat the slices as read-only, or assume the sliced matrix contains + * garbage after modifying the data in one of the slices. + * + * @param x X-offset of the origin of the returned matrix within the sliced matrix + * @param y Y-offset of the origin of the returned matrix within the sliced matrix + * @param w Width of the resulting matrix + * @param h Height of the resulting matrix + * @param in Old matrix (with foreign data) to re-use. Passing NULL will allocate a new matrix. + * @return The resulting slice matrix, or NULL if out of memory + */ +dl_matrix2dq_t *dl_matrixq_slice(const dl_matrix2dq_t *src, int x, int y, int w, int h, dl_matrix2dq_t *in); + +/** + * @brief select a range of items from an existing matrix and flatten them into one dimension. + * + * @Warning The results are flattened in row-major order. + * + * @param x X-offset of the origin of the returned matrix within the sliced matrix + * @param y Y-offset of the origin of the returned matrix within the sliced matrix + * @param w Width of the resulting matrix + * @param h Height of the resulting matrix + * @param in Old matrix to re-use. Passing NULL will allocate a new matrix. + * @return The resulting flatten matrix, or NULL if out of memory + */ +dl_matrix2dq_t *dl_matrixq_flatten(const dl_matrix2dq_t *src, int x, int y, int w, int h, dl_matrix2dq_t *in); + +/** + * @brief Subtract a quantized matrix from another, item-by-item: res=a-b + * + * @param a First matrix + * @param b Second matrix + * @param res Subtracted data. Can be equal to a or b to overwrite that. + * @param shift Shift value. Only 0 or 1 makes sense here. + */ +void dl_matrixq_sub(const dl_matrix2dq_t *a, const dl_matrix2dq_t *b, dl_matrix2dq_t *res, int shift); + +/** + * @brief Multiply a pair of quantized matrices item-by-item: res=a*b + * + * @param a First multiplicand + * @param b Second multiplicand + * @param res Multiplicated data. Can be equal to a or b to overwrite that matrix. + */ +void dl_matrixq_mul( dl_matrix2dq_t *a, dl_matrix2dq_t *b, dl_matrix2dq_t *res); + +/** + * @brief Divide a pair of quantized matrices item-by-item: res=a/b + * + * @param a First matrix + * @param b Second matrix + * @param res Divided data. Can be equal to a or b to overwrite that. + */ +void dl_matrixq_div(const dl_matrix2dq_t *a, const dl_matrix2dq_t *b, dl_matrix2dq_t *out, int shift); + +/** + * @brief Check if two quantized matrices have the same shape, that is, the same amount of + * rows and columns + * + * @param a First of the two matrices to compare + * @param b Second of the two matrices to compare + * @return true if the two matrices are shaped the same, false otherwise. + */ +int dl_matrixq_same_shape(const dl_matrix2dq_t *a, const dl_matrix2dq_t *b); + +/** + * @brief Concatenate the rows of two quantized matrices into a new matrix + * + * @param a First matrix + * @param b Second matrix + * @return A newly allocated quantized matrix with as values a|b + */ +dl_matrix2dq_t *dl_matrixq_concat(const dl_matrix2dq_t *a, const dl_matrix2dq_t *b); + +/** + * @brief Add a constant to every item of the quantized matrix + * + * @param subj Matrix to add the constant to + * @param add The constant + */ +void dl_matrixq_add_const(dl_matrix2dq_t *subj, const fptp_t add, int shift); + +/** + * @brief Check the sanity of a quantized matrix + * + * Due to the nature of quantized matrices, depending on the calculations a quantized + * matrix is the result of and the shift values chosen in those calculations, a quantized + * matrix may have an exponent and mantissas that lead to a loss of precision, either because + * most significant mantissa bits are unused, or because a fair amount of mantissas are + * clipped. This function checks if this is the case and will report a message to stdout + * if significant loss of precision is detected. + * + * @param m The quantized matrix to check + * @param name A string to be displayed in the message if the sanity check fails + * @return True if matrix is sane, false otherwise + **/ + +int dl_matrixq_check_sanity(dl_matrix2dq_t *m, const char *name); + +/** + * @brief re-adjust the exponent of the matrix to fit the mantissa better + * + * This function will shift up all the data in the mantissas so there are no + * most-significant bits that are unused in all mantissas. It will also adjust + * the exponent to keep the actua values in the matrix the same. + * + * Some operations done on a matrix, especially operations that re-use the + * result of earlier operations done in the same way, can lead to the loss of + * data because the exponent of the quantized matrix is never re-adjusted. You + * can do that implicitely by calling this function. + * + * @param m The matrix to re-adjust +**/ +void dl_matrixq_readjust_exp(dl_matrix2dq_t *m); + + + +/** + * @brief Get the floating-point value of a specific item from the quantized matrix + * + * @param m Matrix to access + * @param x Column address + * @param y Row address + * @return Value in that position + */ +fptp_t dl_matrixq_get(const dl_matrix2dq_t *m, const int x, const int y); + +/** + * @brief Set a specific item in the quantized matrix to the given + * floating-point value + * + * @warning If the given value is more than the exponent in the quantized matrix + * allows for, all mantissas in the matrix will be shifted down to make the value + * 'fit'. If, however, the exponent is such that the value would result in a + * quantized mantissa of 0, nothing is done. + * + * @param m Matrix to access + * @param x Column address + * @param y Row address + * @param val Value to write to that position + */ +void dl_matrixq_set(dl_matrix2dq_t *m, const int x, const int y, fptp_t val); + +#endif diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/dl_lib_matrixq8.h b/tools/sdk/esp32/include/esp-sr/include/esp32/dl_lib_matrixq8.h new file mode 100644 index 00000000000..579b1c08aaf --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/dl_lib_matrixq8.h @@ -0,0 +1,71 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef DL_LIB_MATRIXQ8_H +#define DL_LIB_MATRIXQ8_H + +#include +#include "dl_lib_matrix.h" +#include "dl_lib.h" +#include "dl_lib_matrixq.h" + +typedef int8_t q8tp_t; + +typedef struct { + int w; + int h; + int stride; //Normally equals h, not w! + int flags; + int exponent; //The values in items should be multiplied by pow(2,exponent) to get the real values. + q8tp_t *itemq; +} dl_matrix2dq8_t; + +#define DL_Q8TP_SHIFT 7 +#define DL_Q8TP_RANGE ((1<itemq[(y)+(x)*m->stride] + +/** + * @brief Allocate a matrix + * + * @param w Width of the matrix + * @param h Height of the matrix + * @return The matrix, or NULL if out of memory + */ +dl_matrix2dq8_t *dl_matrixq8_alloc(int w, int h); + +/** + * @brief Free a quantized matrix + * Frees the matrix structure and (if it doesn't have the DL_MF_FOREIGNDATA flag set) the m->items space as well. + * + * @param m Matrix to free + */ +void dl_matrixq8_free(dl_matrix2dq8_t *m); + +/** + * @brief Copy a quantized matrix + * Copy a quantized matrix from flash or iram/psram + * + * @param m Matrix to copy + */ +dl_matrix2dq8_t *dl_matrixq8_copy_to_psram(const dl_matrix2dq8_t *m); + +/** + * @brief Convert a floating-point matrix to a quantized matrix + * + * @param m Floating-point matrix to convert + * @param out Quantized matrix to re-use. If NULL, allocate a new one. + * @Return The quantized version of the floating-point matrix + */ +dl_matrix2dq8_t *dl_matrixq8_from_matrix2d(const dl_matrix2d_t *m, dl_matrix2dq8_t *out); + +#endif \ No newline at end of file diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/esp_aec.h b/tools/sdk/esp32/include/esp-sr/include/esp32/esp_aec.h new file mode 100644 index 00000000000..03afc90ff04 --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/esp_aec.h @@ -0,0 +1,112 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License +#ifndef _ESP_AEC_H_ +#define _ESP_AEC_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define USE_AEC_FFT // Not kiss_fft +#define AEC_USE_SPIRAM 0 +#define AEC_SAMPLE_RATE 16000 // Only Support 16000Hz +#define AEC_FRAME_LENGTH_MS 16 +#define AEC_FILTER_LENGTH 1200 // Number of samples of echo to cancel + +typedef void* aec_handle_t; + +/** + * @brief Creates an instance to the AEC structure. + * + * @deprecated This API will be deprecated after version 1.0, please use aec_pro_create + * + * @param sample_rate The Sampling frequency (Hz) must be 16000. + * + * @param frame_length The length of the audio processing must be 16ms. + * + * @param filter_length Number of samples of echo to cancel. + * + * @return + * - NULL: Create failed + * - Others: The instance of AEC + */ +aec_handle_t aec_create(int sample_rate, int frame_length, int filter_length); + +/** + * @brief Creates an instance to the AEC structure. + * + * @deprecated This API will be deprecated after version 1.0, please use aec_pro_create + * + * @param sample_rate The Sampling frequency (Hz) must be 16000. + * + * @param frame_length The length of the audio processing must be 16ms. + * + * @param filter_length Number of samples of echo to cancel. + * + * @param nch Number of input signal channel. + * + * @return + * - NULL: Create failed + * - Others: The instance of AEC + */ +aec_handle_t aec_create_multimic(int sample_rate, int frame_length, int filter_length, int nch); + +/** + * @brief Creates an instance of more powerful AEC. + * + * @param frame_length Length of input signal. Must be 16ms if mode is 0; otherwise could be 16ms or 32ms. Length of input signal to aec_process must be modified accordingly. + * + * @param nch Number of microphones. + * + * @param mode Mode of AEC (0 to 5), indicating aggressiveness and RAM allocation. 0: mild; 1 or 2: medium (1: internal RAM, 2: SPIRAM); 3 and 4: aggressive (3: internal RAM, 4: SPIRAM); 5: agressive, accelerated for ESP32-S3. + * + * @return + * - NULL: Create failed + * - Others: An Instance of AEC + */ +aec_handle_t aec_pro_create(int frame_length, int nch, int mode); + +/** + * @brief Performs echo cancellation a frame, based on the audio sent to the speaker and frame from mic. + * + * @param inst The instance of AEC. + * + * @param indata An array of 16-bit signed audio samples from mic. + * + * @param refdata An array of 16-bit signed audio samples sent to the speaker. + * + * @param outdata Returns near-end signal with echo removed. + * + * @return None + * + */ +void aec_process(const aec_handle_t inst, int16_t *indata, int16_t *refdata, int16_t *outdata); + +/** + * @brief Free the AEC instance + * + * @param inst The instance of AEC. + * + * @return None + * + */ +void aec_destroy(aec_handle_t inst); + +#ifdef __cplusplus +} +#endif + +#endif //_ESP_AEC_H_ diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/esp_afe_sr_iface.h b/tools/sdk/esp32/include/esp-sr/include/esp32/esp_afe_sr_iface.h new file mode 100644 index 00000000000..73f60c3c11f --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/esp_afe_sr_iface.h @@ -0,0 +1,245 @@ +#pragma once +#include "stdint.h" +#include "esp_wn_iface.h" +#include "esp_wn_models.h" + +//AFE: Audio Front-End +//SR: Speech Recognition +//afe_sr/AFE_SR: the audio front-end for speech recognition + +//Opaque AFE_SR data container +typedef struct esp_afe_sr_data_t esp_afe_sr_data_t; + +//Set AFE_SR mode +typedef enum { + SR_MODE_LOW_COST = 0, + SR_MODE_HIGH_PERF = 1 +} afe_sr_mode_t; + +// the output state of fetch function +typedef enum { + AFE_FETCH_CHANNEL_VERIFIED = -2, // wwe state: output channel is verified + AFE_FETCH_NOISE = -1, // vad state: noise or silence + AFE_FETCH_SPEECH = 0, // vad state: speech + AFE_FETCH_WWE_DETECTED = 1 // wwe state: wake word is detected +} afe_fetch_mode_t; + +typedef enum { + AFE_PSRAM_LOW_COST = 1, + AFE_PSRAM_MEDIA_COST = 2, + AFE_PSRAM_HIGH_COST = 3 +} afe_use_psram_mode_t; + +typedef struct { + bool aec_init; + bool se_init; + bool vad_init; + bool wakenet_init; + int vad_mode; + const esp_wn_iface_t *wakenet_model; + const model_coeff_getter_t *wakenet_coeff; + det_mode_t wakenet_mode; + afe_sr_mode_t afe_mode; + int afe_perferred_core; + int afe_perferred_priority; + int afe_ringbuf_size; + int alloc_from_psram; + int agc_mode; +} afe_config_t; + + +#if CONFIG_IDF_TARGET_ESP32 +#define AFE_CONFIG_DEFAULT() { \ + .aec_init = true, \ + .se_init = true, \ + .vad_init = true, \ + .wakenet_init = true, \ + .vad_mode = 3, \ + .wakenet_model = &WAKENET_MODEL, \ + .wakenet_coeff = &WAKENET_COEFF, \ + .wakenet_mode = DET_MODE_90, \ + .afe_mode = SR_MODE_HIGH_PERF, \ + .afe_perferred_core = 0, \ + .afe_perferred_priority = 5, \ + .afe_ringbuf_size = 50, \ + .alloc_from_psram = 1, \ + .agc_mode = 2, \ +} +#elif CONFIG_IDF_TARGET_ESP32S3 +#define AFE_CONFIG_DEFAULT() { \ + .aec_init = true, \ + .se_init = true, \ + .vad_init = true, \ + .wakenet_init = true, \ + .vad_mode = 3, \ + .wakenet_model = &WAKENET_MODEL, \ + .wakenet_coeff = &WAKENET_COEFF, \ + .wakenet_mode = DET_MODE_2CH_90, \ + .afe_mode = SR_MODE_LOW_COST, \ + .afe_perferred_core = 0, \ + .afe_perferred_priority = 5, \ + .afe_ringbuf_size = 50, \ + .alloc_from_psram = AFE_PSRAM_MEDIA_COST, \ + .agc_mode = 2, \ +} +#endif +/** + * @brief Function to initialze a AFE_SR instance with a specified mode + * + * @param mode The mode of AFE_SR + * @param perferred_core The perferred core to be pinned. + * If all task in AFE_SR can not run in real time by only one core, the another core would be used. + * @returns Handle to the AFE_SR data + */ +typedef esp_afe_sr_data_t* (*esp_afe_sr_iface_op_create_t)(afe_sr_mode_t mode, int perferred_cor); + +/** + * @brief Function to initialze a AFE_SR instance + * + * @param afe_config The config of AFE_SR + * @returns Handle to the AFE_SR data + */ +typedef esp_afe_sr_data_t* (*esp_afe_sr_iface_op_create_from_config_t)(afe_config_t *afe_config); + +/** + * @brief Get the amount of each channel samples per frame that need to be passed to the function + * + * Every speech enhancement AFE_SR processes a certain number of samples at the same time. This function + * can be used to query that amount. Note that the returned amount is in 16-bit samples, not in bytes. + * + * @param afe The AFE_SR object to query + * @return The amount of samples to feed the fetch function + */ +typedef int (*esp_afe_sr_iface_op_get_samp_chunksize_t)(esp_afe_sr_data_t *afe); + +/** + * @brief Get the channel number of samples that need to be passed to the fetch function + * + * @param afe The AFE_SR object to query + * @return The amount of samples to feed the fetch function + */ +typedef int (*esp_afe_sr_iface_op_get_channel_num_t)(esp_afe_sr_data_t *afe); + +/** + * @brief Get the sample rate of the samples to feed to the function + * + * @param afe The AFE_SR object to query + * @return The sample rate, in hz + */ +typedef int (*esp_afe_sr_iface_op_get_samp_rate_t)(esp_afe_sr_data_t *afe); + +/** + * @brief Feed samples of an audio stream to the AFE_SR + * + * @Warning The input data should be arranged in the format of [CH0_0, CH1_0, ..., CHN_0, CH0_1, CH1_1, ..., CHN_1, ...]. + * The last channel is reference signal or far-end signal. + * + * @param afe The AFE_SR object to queryq + * + * @param in The input microphone signal, only support signed 16-bit @ 16 KHZ. The frame size can be queried by the + * `get_samp_chunksize`. The channel number can be queried `get_channel_num`. + * @return The size of input + */ +typedef int (*esp_afe_sr_iface_op_feed_t)(esp_afe_sr_data_t *afe, const int16_t* in); + +/** + * @brief fetch enhanced samples of an audio stream from the AFE_SR + * + * @Warning The output is single channel data, no matter how many channels the input is. + * + * @param afe The AFE_SR object to query + * @param out The output enhanced signal. The frame size can be queried by the `get_samp_chunksize`. + * @return The state of output, please refer to the definition of `afe_fetch_mode_t` + */ +typedef afe_fetch_mode_t (*esp_afe_sr_iface_op_fetch_t)(esp_afe_sr_data_t *afe, int16_t* out); + +/** + * @brief Initial wakenet and wake words coefficient, or reset wakenet and wake words coefficient + * when wakenet has been initialized. + * + * @param afe The AFE_SR object to query + * @param wakenet The pointer of wakenet + * @param model_coeff The coefficient of wake word model + * @return 0: fail, 1: success + */ +typedef int (*esp_afe_sr_iface_op_set_wakenet_t)(esp_afe_sr_data_t *afe, + esp_wn_iface_t *wakenet, + const model_coeff_getter_t *model_coeff); + +/** + * @brief Disable wakenet model. + * + * @param afe The AFE_SR object to query + * @return 0: fail, 1: success + */ +typedef int (*esp_afe_sr_iface_op_disable_wakenet_t)(esp_afe_sr_data_t *afe); + +/** + * @brief Enable wakenet model. + * + * @param afe The AFE_SR object to query + * @return 0: fail, 1: success + */ +typedef int (*esp_afe_sr_iface_op_enable_wakenet_t)(esp_afe_sr_data_t *afe); + +/** + * @brief Disable AEC algorithm. + * + * @param afe The AFE_SR object to query + * @return 0: fail, 1: success + */ +typedef int (*esp_afe_sr_iface_op_disable_aec_t)(esp_afe_sr_data_t *afe); + +/** + * @brief Enable AEC algorithm. + * + * @param afe The AFE_SR object to query + * @return 0: fail, 1: success + */ +typedef int (*esp_afe_sr_iface_op_enable_aec_t)(esp_afe_sr_data_t *afe); + +/** + * @brief Disable SE algorithm. + * + * @param afe The AFE_SR object to query + * @return 0: fail, 1: success + */ +typedef int (*esp_afe_sr_iface_op_disable_se_t)(esp_afe_sr_data_t *afe); + +/** + * @brief Enable SE algorithm. + * + * @param afe The AFE_SR object to query + * @return 0: fail, 1: success + */ +typedef int (*esp_afe_sr_iface_op_enable_se_t)(esp_afe_sr_data_t *afe); + +/** + * @brief Destroy a AFE_SR instance + * + * @param afe AFE_SR object to destroy + */ +typedef void (*esp_afe_sr_iface_op_destroy_t)(esp_afe_sr_data_t *afe); + + +/** + * This structure contains the functions used to do operations on a AFE_SR. + */ +typedef struct { + esp_afe_sr_iface_op_create_t create; + esp_afe_sr_iface_op_create_from_config_t create_from_config; + esp_afe_sr_iface_op_feed_t feed; + esp_afe_sr_iface_op_fetch_t fetch; + esp_afe_sr_iface_op_get_samp_chunksize_t get_feed_chunksize; + esp_afe_sr_iface_op_get_samp_chunksize_t get_fetch_chunksize; + esp_afe_sr_iface_op_get_channel_num_t get_channel_num; + esp_afe_sr_iface_op_get_samp_rate_t get_samp_rate; + esp_afe_sr_iface_op_set_wakenet_t set_wakenet; + esp_afe_sr_iface_op_disable_wakenet_t disable_wakenet; + esp_afe_sr_iface_op_enable_wakenet_t enable_wakenet; + esp_afe_sr_iface_op_disable_aec_t disable_aec; + esp_afe_sr_iface_op_enable_aec_t enable_aec; + esp_afe_sr_iface_op_disable_se_t disable_se; + esp_afe_sr_iface_op_enable_se_t enable_se; + esp_afe_sr_iface_op_destroy_t destroy; +} esp_afe_sr_iface_t; diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/esp_afe_sr_models.h b/tools/sdk/esp32/include/esp-sr/include/esp32/esp_afe_sr_models.h new file mode 100644 index 00000000000..5424134ab1e --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/esp_afe_sr_models.h @@ -0,0 +1,6 @@ +#pragma once +#include "esp_afe_sr_iface.h" + +extern const esp_afe_sr_iface_t esp_afe_sr_2mic; +extern const esp_afe_sr_iface_t esp_afe_sr_1mic; + diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/esp_agc.h b/tools/sdk/esp32/include/esp-sr/include/esp32/esp_agc.h new file mode 100644 index 00000000000..20b0e3f2259 --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/esp_agc.h @@ -0,0 +1,39 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License +#ifndef _ESP_AGC_H_ +#define _ESP_AGC_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +////all positive value is valid, negective is error +typedef enum { + ESP_AGC_SUCCESS = 0, ////success + ESP_AGC_FAIL = -1, ////agc fail + ESP_AGC_SAMPLE_RATE_ERROR = -2, ///sample rate can be only 8khz, 16khz, 32khz + ESP_AGC_FRAME_SIZE_ERROR = -3, ////the input frame size should be only 10ms, so should together with sample-rate to get the frame size +} ESP_AGE_ERR; + + +void *esp_agc_open(int agc_mode, int sample_rate); +void set_agc_config(void *agc_handle, int gain_dB, int limiter_enable, int target_level_dbfs); +int esp_agc_process(void *agc_handle, short *in_pcm, short *out_pcm, int frame_size, int sample_rate); +void esp_agc_close(void *agc_handle); + +#ifdef __cplusplus +} +#endif + +#endif // _ESP_AGC_H_ diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/esp_map.h b/tools/sdk/esp32/include/esp-sr/include/esp32/esp_map.h new file mode 100644 index 00000000000..794afdc54c8 --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/esp_map.h @@ -0,0 +1,90 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License +#ifndef _ESP_MAP_H_ +#define _ESP_MAP_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#define MAP_SAMPLE_RATE 16000 // Supports 16kHz only +#define MAP_FRAME_SIZE 16 // Supports 16ms only +#define MAP_MIC_DISTANCE 50 // According to physical design of mic-array +#define MAP_AEC_ON true +#define MAP_AEC_OFF false +#define MAP_AEC_FILTER_LENGTH 1200 // Number of samples of echo to cancel + +/** + * @brief Sets mic-array type, currently 2-mic line array and 3-mic circular array + * are supported. + */ +typedef enum { + TWO_MIC_LINE = 0, + THREE_MIC_CIRCLE = 1 +} map_mic_array_type_t; + +typedef void* mic_array_processor_t; + +/** + * @brief Creates an instance to the MAP structure. + * + * @param sample_rate The sampling frequency (Hz) must be 16000. + * + * @param frame_size The length of the audio processing must be 16ms. + * + * @param array_type '0' for 2-mic line array and '1' for 3-mic circular array. + * + * @param mic_distance The distance between neiboring microphones in mm. + * + * @param aec_on Decides whether to turn on AEC. + * + * @param filter_length Number of samples of echo to cancel, effective when AEC is on. + * + * @return + * - NULL: Create failed + * - Others: An instance of MAP + */ +mic_array_processor_t map_create(int fs, int frame_size, int array_type, float mic_distance, bool aec_on, int filter_length); + +/** + * @brief Performs mic array processing for one frame. + * + * @param inst The instance of MAP. + * + * @param in An array of 16-bit signed audio samples from mic. + * + * @param far_end An array of 16-bit signed audio samples sent to the speaker, can be none when AEC is turned off. + * + * @param dsp_out Returns enhanced signal. + * + * @return None + * + */ +void map_process(mic_array_processor_t st, int16_t *in, int16_t *far_end, int16_t *dsp_out); + +/** + * @brief Free the MAP instance + * + * @param inst The instance of MAP. + * + * @return None + * + */ +void map_destory(mic_array_processor_t st); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/esp_mase.h b/tools/sdk/esp32/include/esp-sr/include/esp32/esp_mase.h new file mode 100644 index 00000000000..3cf403f5646 --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/esp_mase.h @@ -0,0 +1,94 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License + +#ifndef _ESP_MASE_H_ +#define _ESP_MASE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#define MASE_SAMPLE_RATE 16000 // Supports 16kHz only +#define MASE_FRAME_SIZE 16 // Supports 16ms only +#define MASE_MIC_DISTANCE 65 // According to physical design of mic-array + +/** + * @brief Sets mic-array type, currently 2-mic line array and 3-mic circular array + * are supported. + */ +typedef enum { + TWO_MIC_LINE = 0, + THREE_MIC_CIRCLE = 1 +} mase_mic_array_type_t; + +/** + * @brief Sets operating mode, supporting normal mode and wake-up enhancement mode + */ +typedef enum { + NORMAL_ENHANCEMENT_MODE = 0, + WAKE_UP_ENHANCEMENT_MODE = 1 +} mase_op_mode_t; + +typedef void* mase_handle_t; + +/** + * @brief Creates an instance to the MASE structure. + * + * @param sample_rate The sampling frequency (Hz) must be 16000. + * + * @param frame_size The length of the audio processing must be 16ms. + * + * @param array_type '0' for 2-mic line array and '1' for 3-mic circular array. + * + * @param mic_distance The distance between neiboring microphones in mm. + * + * @param operating_mode '0' for normal mode and '1' for wake-up enhanced mode. + * + * @param filter_strength Strengh of the mic-array speech enhancement, must be 0, 1, 2 or 3. + * + * @return + * - NULL: Create failed + * - Others: An instance of MASE + */ +mase_handle_t mase_create(int fs, int frame_size, int array_type, float mic_distance, int operating_mode, int filter_strength); + +/** + * @brief Performs mic array processing for one frame. + * + * @param inst The instance of MASE. + * + * @param in An array of 16-bit signed audio samples from mic. + * + * @param dsp_out Returns enhanced signal. + * + * @return None + * + */ +void mase_process(mase_handle_t st, int16_t *in, int16_t *dsp_out); + +/** + * @brief Free the MASE instance + * + * @param inst The instance of MASE. + * + * @return None + * + */ +void mase_destory(mase_handle_t st); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/esp_mn_iface.h b/tools/sdk/esp32/include/esp-sr/include/esp32/esp_mn_iface.h new file mode 100644 index 00000000000..d4e5aa3f86c --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/esp_mn_iface.h @@ -0,0 +1,109 @@ +#pragma once +#include "stdint.h" +// #include "esp_err.h" +#include "dl_lib_coefgetter_if.h" +#include "esp_wn_iface.h" +// //Opaque model data container +// typedef struct model_iface_data_t model_iface_data_t; + +/** + * @brief Initialze a model instance with specified model coefficient. + * + * @param coeff The wakenet model coefficient. + * @param coeff The wakenet model coefficient. + * @parm sample_length Audio length for speech recognition, in ms. + * @returns Handle to the model data. + */ +typedef model_iface_data_t* (*esp_mn_iface_op_create_t)(const model_coeff_getter_t *coeff, int sample_length); + + +/** + * @brief Callback function type to fetch the amount of samples that need to be passed to the detect function + * + * Every speech recognition model processes a certain number of samples at the same time. This function + * can be used to query that amount. Note that the returned amount is in 16-bit samples, not in bytes. + * + * @param model The model object to query + * @return The amount of samples to feed the detect function + */ +typedef int (*esp_mn_iface_op_get_samp_chunksize_t)(model_iface_data_t *model); + +/** + * @brief Callback function type to fetch the number of frames recognized by the command word + * + * @param model The model object to query + * @return The number of the frames recognized by the command word + */ +typedef int (*esp_mn_iface_op_get_samp_chunknum_t)(model_iface_data_t *model); + +/** + * @brief Set the detection threshold to manually abjust the probability + * + * @param model The model object to query + * @param det_treshold The threshold to trigger speech commands, the range of det_threshold is 0.0~0.9999 + */ +typedef int (*esp_mn_iface_op_set_det_threshold_t)(model_iface_data_t *model, float det_threshold); +/** + * @brief Set the detection threshold to manually abjust the probability + * + * @param model The model object to query + * @param phrase_id The ID of speech command phrase + * @param det_treshold The threshold to trigger speech command phrases + */ +typedef void (*esp_mn_iface_op_set_command_det_threshold_t)(model_iface_data_t *model, int phrase_id, float det_threshold); + +/** + * @brief Get the detection threshold by phrase ID + * + * @param model The model object to query + * @param phrase_id The ID of speech command phrase + * + * @return The threshold of speech command phrases + */ +typedef float (*esp_mn_iface_op_get_command_det_threshold_t)(model_iface_data_t *model, int phrase_id); + +/** + * @brief Get the sample rate of the samples to feed to the detect function + * + * @param model The model object to query + * @return The sample rate, in hz + */ +typedef int (*esp_mn_iface_op_get_samp_rate_t)(model_iface_data_t *model); + +/** + * @brief Feed samples of an audio stream to the speech recognition model and detect if there is a speech command found. + * + * @param model The model object to query. + * @param samples An array of 16-bit signed audio samples. The array size used can be queried by the + * get_samp_chunksize function. + * @return The command id, return 0 if no command word is detected, + */ +typedef int (*esp_mn_iface_op_detect_t)(model_iface_data_t *model, int16_t *samples); + + +/** + * @brief Destroy a speech commands recognition model + * + * @param model The Model object to destroy + */ +typedef void (*esp_mn_iface_op_destroy_t)(model_iface_data_t *model); + +/** + * @brief Reset the speech commands recognition model + * + */ +typedef void (*esp_mn_iface_op_reset_t)(model_iface_data_t *model_data, char *command_str, char *err_phrase_id); + + +typedef struct { + esp_mn_iface_op_create_t create; + esp_mn_iface_op_get_samp_rate_t get_samp_rate; + esp_mn_iface_op_get_samp_chunksize_t get_samp_chunksize; + esp_mn_iface_op_get_samp_chunknum_t get_samp_chunknum; + esp_mn_iface_op_set_det_threshold_t set_det_threshold; + esp_mn_iface_op_set_command_det_threshold_t set_command_det_threshold; + esp_mn_iface_op_get_command_det_threshold_t get_command_det_threshold; + esp_mn_iface_op_detect_t detect; + esp_mn_iface_op_destroy_t destroy; + esp_mn_iface_op_reset_t reset; +} esp_mn_iface_t; diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/esp_mn_models.h b/tools/sdk/esp32/include/esp-sr/include/esp32/esp_mn_models.h new file mode 100644 index 00000000000..5b186541f5b --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/esp_mn_models.h @@ -0,0 +1,77 @@ +#pragma once +#include "esp_mn_iface.h" + +//Contains declarations of all available speech recognion models. Pair this up with the right coefficients and you have a model that can recognize +//a specific phrase or word. +extern const esp_mn_iface_t esp_sr_multinet1_single_quantized_en; +extern const esp_mn_iface_t esp_sr_multinet3_single_quantized_en; +extern const esp_mn_iface_t esp_sr_multinet2_single_quantized_cn; +extern const esp_mn_iface_t esp_sr_multinet3_single_quantized_cn; +extern const esp_mn_iface_t esp_sr_multinet4_single_quantized_cn; +extern const esp_mn_iface_t esp_sr_multinet3_continuous_quantized_cn; +extern const esp_mn_iface_t esp_sr_multinet5_quantized; +extern const esp_mn_iface_t esp_sr_multinet5_quantized8; + +/* + Configure wake word to use based on what's selected in menuconfig. +*/ +#if defined CONFIG_USE_MULTINET +#ifdef CONFIG_SR_MN_EN_MULTINET1_SINGLE_RECOGNITION +#include "multinet1_en.h" +#define MULTINET_MODEL esp_sr_multinet1_single_quantized_en +#define MULTINET_COEFF get_coeff_multinet1_en +#elif CONFIG_SR_MN_EN_MULTINET3_SINGLE_RECOGNITION +#include "multinet3_en.h" +#define MULTINET_MODEL esp_sr_multinet3_single_quantized_en +#define MULTINET_COEFF get_coeff_multinet3_en +#elif CONFIG_SR_MN_CN_MULTINET2_SINGLE_RECOGNITION +#include "multinet2_ch.h" +#define MULTINET_MODEL esp_sr_multinet2_single_quantized_cn +#define MULTINET_COEFF get_coeff_multinet2_ch +#elif CONFIG_SR_MN_CN_MULTINET2_CONTINUOUS_RECOGNITION + +#elif CONFIG_SR_MN_CN_MULTINET3_SINGLE_RECOGNITION +#define MULTINET_MODEL esp_sr_multinet3_single_quantized_cn +#define MULTINET_COEFF "mn3cn" +#elif CONFIG_SR_MN_CN_MULTINET4_SINGLE_RECOGNITION +#define MULTINET_MODEL esp_sr_multinet4_single_quantized_cn +#define MULTINET_COEFF "mn4cn" +#elif CONFIG_SR_MN_CN_MULTINET3_CONTINUOUS_RECOGNITION +#define MULTINET_MODEL esp_sr_multinet3_continuous_quantized_cn +#define MULTINET_COEFF "mn3cn" +#elif CONFIG_SR_MN_EN_MULTINET5_SINGLE_RECOGNITION +#define MULTINET_MODEL esp_sr_multinet5_quantized +#define MULTINET_COEFF "mn5en" +#elif CONFIG_SR_MN_EN_MULTINET5_SINGLE_RECOGNITION_QUANT8 +#define MULTINET_MODEL esp_sr_multinet5_quantized8 +#define MULTINET_COEFF "mn5q8en" +#else +#error No valid wake word selected. +#endif +#else +#define MULTINET_MODEL "NULL" +#define MULTINET_COEFF "NULL" +#endif +/* example + +static const esp_mn_iface_t *multinet = &MULTINET_MODEL; + +//Initialize MultiNet model data +model_iface_data_t *model_data = multinet->create(&MULTINET_COEFF); +add_speech_commands(multinet, model_data); + +//Set parameters of buffer +int audio_chunksize=model->get_samp_chunksize(model_data); +int frequency = model->get_samp_rate(model_data); +int16_t *buffer=malloc(audio_chunksize*sizeof(int16_t)); + +//Detect +int r=model->detect(model_data, buffer); +if (r>0) { + printf("Detection triggered output %d.\n", r); +} + +//Destroy model +model->destroy(model_data) + +*/ diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/esp_ns.h b/tools/sdk/esp32/include/esp-sr/include/esp32/esp_ns.h new file mode 100644 index 00000000000..1932600b72f --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/esp_ns.h @@ -0,0 +1,85 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License +#ifndef _ESP_NS_H_ +#define _ESP_NS_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define NS_USE_SPIARM 0 +#define NS_FRAME_LENGTH_MS 10 //Supports 10ms, 20ms, 30ms + +/** +* The Sampling frequency (Hz) must be 16000Hz +*/ + +typedef void* ns_handle_t; + +/** + * @brief Creates an instance to the NS structure. + * + * @param frame_length The length of the audio processing can be 10ms, 20ms, 30ms. + * + * @return + * - NULL: Create failed + * - Others: The instance of NS + */ +ns_handle_t ns_create(int frame_length); + +/** + * @brief Creates an instance of the more powerful noise suppression algorithm. + * + * @warning frame_length only supports be 10 ms. + * + * @param frame_length The length of the audio processing can only be 10ms. + * @param mode 0: Mild, 1: Medium, 2: Aggressive + * + * @return + * - NULL: Create failed + * - Others: The instance of NS + */ +ns_handle_t ns_pro_create(int frame_length, int mode); + +/** + * @brief Feed samples of an audio stream to the NS and get the audio stream after Noise suppression. + * + * @param inst The instance of NS. + * + * @param indata An array of 16-bit signed audio samples. + * + * @param outdata An array of 16-bit signed audio samples after noise suppression. + * + * @return None + * + */ +void ns_process(ns_handle_t inst, int16_t *indata, int16_t *outdata); + +/** + * @brief Free the NS instance + * + * @param inst The instance of NS. + * + * @return None + * + */ +void ns_destroy(ns_handle_t inst); + +#ifdef __cplusplus +} +#endif + +#endif //_ESP_NS_H_ diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/esp_vad.h b/tools/sdk/esp32/include/esp-sr/include/esp32/esp_vad.h new file mode 100644 index 00000000000..e1a76cf4072 --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/esp_vad.h @@ -0,0 +1,104 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License +#ifndef _ESP_VAD_H_ +#define _ESP_VAD_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define SAMPLE_RATE_HZ 16000 //Supports 32000, 16000, 8000 +#define VAD_FRAME_LENGTH_MS 30 //Supports 10ms, 20ms, 30ms + +/** + * @brief Sets the VAD operating mode. A more aggressive (higher mode) VAD is more + * restrictive in reporting speech. + */ +typedef enum { + VAD_MODE_0 = 0, + VAD_MODE_1, + VAD_MODE_2, + VAD_MODE_3, + VAD_MODE_4 +} vad_mode_t; + +typedef enum { + VAD_SILENCE = 0, + VAD_SPEECH +} vad_state_t; + +typedef void* vad_handle_t; + +/** + * @brief Creates an instance to the VAD structure. + * + * @param vad_mode Sets the VAD operating mode. + * + * @param sample_rate_hz The Sampling frequency (Hz) can be 32000, 16000, 8000, default: 16000. + * + * @param one_frame_ms The length of the audio processing can be 10ms, 20ms, 30ms, default: 30. + * + * @return + * - NULL: Create failed + * - Others: The instance of VAD + */ +vad_handle_t vad_create(vad_mode_t vad_mode, int sample_rate_hz, int one_frame_ms); + +/** + * @brief Feed samples of an audio stream to the VAD and check if there is someone speaking. + * + * @param inst The instance of VAD. + * + * @param data An array of 16-bit signed audio samples. + * + * @return + * - VAD_SILENCE if no voice + * - VAD_SPEECH if voice is detected + * + */ +vad_state_t vad_process(vad_handle_t inst, int16_t *data); + +/** + * @brief Free the VAD instance + * + * @param inst The instance of VAD. + * + * @return None + * + */ +void vad_destroy(vad_handle_t inst); + +/* +* Programming Guide: +* +* @code{c} +* vad_handle_t vad_inst = vad_create(VAD_MODE_3, SAMPLE_RATE_HZ, VAD_FRAME_LENGTH_MS); // Creates an instance to the VAD structure. +* +* while (1) { +* //Use buffer to receive the audio data from MIC. +* vad_state_t vad_state = vad_process(vad_inst, buffer); // Feed samples to the VAD process and get the result. +* } +* +* vad_destroy(vad_inst); // Free the VAD instance at the end of whole VAD process +* +* @endcode +*/ + +#ifdef __cplusplus +} +#endif + +#endif //_ESP_VAD_H_ diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/esp_wn_iface.h b/tools/sdk/esp32/include/esp-sr/include/esp32/esp_wn_iface.h new file mode 100644 index 00000000000..6843af19d5d --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/esp_wn_iface.h @@ -0,0 +1,164 @@ +#pragma once +#include "stdint.h" +#include "dl_lib_coefgetter_if.h" + +//Opaque model data container +typedef struct model_iface_data_t model_iface_data_t; + +//Set wake words recognition operating mode +//The probability of being wake words is increased with increasing mode, +//As a consequence also the false alarm rate goes up +typedef enum { + DET_MODE_90 = 0, // Normal + DET_MODE_95 = 1, // Aggressive + DET_MODE_2CH_90 = 2, + DET_MODE_2CH_95 = 3, + DET_MODE_3CH_90 = 4, + DET_MODE_3CH_95 = 5, +} det_mode_t; + +typedef struct { + int wake_word_num; //The number of all wake words + char **wake_word_list; //The name list of wake words +} wake_word_info_t; + +/** + * @brief Easy function type to initialze a model instance with a detection mode and specified wake word coefficient + * + * @param det_mode The wake words detection mode to trigger wake words, DET_MODE_90 or DET_MODE_95 + * @param model_coeff The specified wake word model coefficient + * @returns Handle to the model data + */ +typedef model_iface_data_t* (*esp_wn_iface_op_create_t)(const model_coeff_getter_t *model_coeff, det_mode_t det_mode); + +/** + * @brief Callback function type to fetch the amount of samples that need to be passed to the detect function + * + * Every speech recognition model processes a certain number of samples at the same time. This function + * can be used to query that amount. Note that the returned amount is in 16-bit samples, not in bytes. + * + * @param model The model object to query + * @return The amount of samples to feed the detect function + */ +typedef int (*esp_wn_iface_op_get_samp_chunksize_t)(model_iface_data_t *model); + +/** + * @brief Callback function type to fetch the channel number of samples that need to be passed to the detect function + * + * Every speech recognition model processes a certain number of samples at the same time. This function + * can be used to query that amount. Note that the returned amount is in 16-bit samples, not in bytes. + * + * @param model The model object to query + * @return The amount of samples to feed the detect function + */ +typedef int (*esp_wn_iface_op_get_channel_num_t)(model_iface_data_t *model); + + +/** + * @brief Get the sample rate of the samples to feed to the detect function + * + * @param model The model object to query + * @return The sample rate, in hz + */ +typedef int (*esp_wn_iface_op_get_samp_rate_t)(model_iface_data_t *model); + +/** + * @brief Get the number of wake words + * + * @param model The model object to query + * @returns the number of wake words + */ +typedef int (*esp_wn_iface_op_get_word_num_t)(model_iface_data_t *model); + +/** + * @brief Get the name of wake word by index + * + * @Warning The index of wake word start with 1 + + * @param model The model object to query + * @param word_index The index of wake word + * @returns the detection threshold + */ +typedef char* (*esp_wn_iface_op_get_word_name_t)(model_iface_data_t *model, int word_index); + +/** + * @brief Set the detection threshold to manually abjust the probability + * + * @param model The model object to query + * @param det_treshold The threshold to trigger wake words, the range of det_threshold is 0.5~0.9999 + * @param word_index The index of wake word + * @return 0: setting failed, 1: setting success + */ +typedef int (*esp_wn_iface_op_set_det_threshold_t)(model_iface_data_t *model, float det_threshold, int word_index); + +/** + * @brief Get the wake word detection threshold of different modes + * + * @param model The model object to query + * @param word_index The index of wake word + * @returns the detection threshold + */ +typedef float (*esp_wn_iface_op_get_det_threshold_t)(model_iface_data_t *model, int word_index); + +/** + * @brief Feed samples of an audio stream to the keyword detection model and detect if there is a keyword found. + * + * @Warning The index of wake word start with 1, 0 means no wake words is detected. + * + * @param model The model object to query + * @param samples An array of 16-bit signed audio samples. The array size used can be queried by the + * get_samp_chunksize function. + * @return The index of wake words, return 0 if no wake word is detected, else the index of the wake words. + */ +typedef int (*esp_wn_iface_op_detect_t)(model_iface_data_t *model, int16_t *samples); + +/** + * @brief Get the volume gain + * + * @param model The model object to query + * @param target_db The target dB to calculate volume gain + * @returns the volume gain + */ +typedef float (*esp_wn_iface_op_get_vol_gain_t)(model_iface_data_t *model, float target_db); + +/** + * @brief Get the triggered channel index. Channel index starts from zero + * + * @param model The model object to query + * @return The channel index + */ +typedef int (*esp_wn_iface_op_get_triggered_channel_t)(model_iface_data_t *model); + +/** + * @brief Clean all states of model + * + * @param model The model object to query + */ +typedef void (*esp_wn_iface_op_clean_t)(model_iface_data_t *model); + +/** + * @brief Destroy a speech recognition model + * + * @param model Model object to destroy + */ +typedef void (*esp_wn_iface_op_destroy_t)(model_iface_data_t *model); + + +/** + * This structure contains the functions used to do operations on a wake word detection model. + */ +typedef struct { + esp_wn_iface_op_create_t create; + esp_wn_iface_op_get_samp_chunksize_t get_samp_chunksize; + esp_wn_iface_op_get_channel_num_t get_channel_num; + esp_wn_iface_op_get_samp_rate_t get_samp_rate; + esp_wn_iface_op_get_word_num_t get_word_num; + esp_wn_iface_op_get_word_name_t get_word_name; + esp_wn_iface_op_set_det_threshold_t set_det_threshold; + esp_wn_iface_op_get_det_threshold_t get_det_threshold; + esp_wn_iface_op_get_triggered_channel_t get_triggered_channel; + esp_wn_iface_op_get_vol_gain_t get_vol_gain; + esp_wn_iface_op_detect_t detect; + esp_wn_iface_op_clean_t clean; + esp_wn_iface_op_destroy_t destroy; +} esp_wn_iface_t; diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/esp_wn_models.h b/tools/sdk/esp32/include/esp-sr/include/esp32/esp_wn_models.h new file mode 100644 index 00000000000..225456fc728 --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/esp_wn_models.h @@ -0,0 +1,127 @@ +#pragma once +#include "esp_wn_iface.h" + +//Contains declarations of all available speech recognion models. Pair this up with the right coefficients and you have a model that can recognize +//a specific phrase or word. + +extern const esp_wn_iface_t esp_sr_wakenet5_quantized; +extern const esp_wn_iface_t esp_sr_wakenet7_quantized; +extern const esp_wn_iface_t esp_sr_wakenet7_quantized8; +extern const esp_wn_iface_t esp_sr_wakenet8_quantized; +extern const esp_wn_iface_t esp_sr_wakenet8_quantized8; +/* + Configure network to use based on what's selected in menuconfig. +*/ +#if defined CONFIG_USE_WAKENET +#if CONFIG_SR_WN_MODEL_WN5_QUANT +#define WAKENET_MODEL esp_sr_wakenet5_quantized +#elif CONFIG_SR_WN_MODEL_WN7_QUANT +#define WAKENET_MODEL esp_sr_wakenet7_quantized +#elif CONFIG_SR_WN_MODEL_WN7_QUANT8 +#define WAKENET_MODEL esp_sr_wakenet7_quantized8 +#elif CONFIG_SR_WN_MODEL_WN8_QUANT +#define WAKENET_MODEL esp_sr_wakenet8_quantized +#elif CONFIG_SR_WN_MODEL_WN8_QUANT8 +#define WAKENET_MODEL esp_sr_wakenet8_quantized8 +#else +#error No valid neural network model selected. +#endif + +/* + Configure wake word to use based on what's selected in menuconfig. +*/ +#if CONFIG_SR_WN_WN5_HILEXIN & CONFIG_SR_WN_MODEL_WN5_QUANT +#include "hilexin_wn5.h" +#define WAKENET_COEFF get_coeff_hilexin_wn5 + +#elif CONFIG_SR_WN_WN5X2_HILEXIN & CONFIG_SR_WN_MODEL_WN5_QUANT +#include "hilexin_wn5X2.h" +#define WAKENET_COEFF get_coeff_hilexin_wn5X2 + +#elif CONFIG_SR_WN_WN5X3_HILEXIN & CONFIG_SR_WN_MODEL_WN5_QUANT +#include "hilexin_wn5X3.h" +#define WAKENET_COEFF get_coeff_hilexin_wn5X3 + +#elif CONFIG_SR_WN_WN5_NIHAOXIAOZHI & CONFIG_SR_WN_MODEL_WN5_QUANT +#include "nihaoxiaozhi_wn5.h" +#define WAKENET_COEFF get_coeff_nihaoxiaozhi_wn5 + +#elif CONFIG_SR_WN_WN5X2_NIHAOXIAOZHI & CONFIG_SR_WN_MODEL_WN5_QUANT +#include "nihaoxiaozhi_wn5X2.h" +#define WAKENET_COEFF get_coeff_nihaoxiaozhi_wn5X2 + +#elif CONFIG_SR_WN_WN5X3_NIHAOXIAOZHI & CONFIG_SR_WN_MODEL_WN5_QUANT +#include "nihaoxiaozhi_wn5X3.h" +#define WAKENET_COEFF get_coeff_nihaoxiaozhi_wn5X3 + +#elif CONFIG_SR_WN_WN5X3_NIHAOXIAOXIN & CONFIG_SR_WN_MODEL_WN5_QUANT +#include "nihaoxiaoxin_wn5X3.h" +#define WAKENET_COEFF get_coeff_nihaoxiaoxin_wn5X3 + +#elif CONFIG_SR_WN_WN5X3_HIJESON & CONFIG_SR_WN_MODEL_WN5_QUANT +#include "hijeson_wn5X3.h" +#define WAKENET_COEFF get_coeff_hijeson_wn5X3 + +#elif CONFIG_SR_WN_WN5_CUSTOMIZED_WORD +#include "customized_word_wn5.h" +#define WAKENET_COEFF get_coeff_customized_word_wn5 + +#elif CONFIG_SR_WN_WN7_CUSTOMIZED_WORD +#define WAKENET_COEFF "custom7" + +#elif CONFIG_SR_WN_WN7_XIAOAITONGXUE & CONFIG_SR_WN_MODEL_WN7_QUANT +#define WAKENET_COEFF "xiaoaitongxue7" + +#elif CONFIG_SR_WN_WN7_XIAOAITONGXUE & CONFIG_SR_WN_MODEL_WN7_QUANT8 +#define WAKENET_COEFF "xiaoaitongxue7q8" + +#elif CONFIG_SR_WN_WN7_HILEXIN & CONFIG_SR_WN_MODEL_WN7_QUANT +#define WAKENET_COEFF "hilexin7" + +#elif CONFIG_SR_WN_WN7_HILEXIN & CONFIG_SR_WN_MODEL_WN7_QUANT8 +#define WAKENET_COEFF "hilexin7q8" + +#elif CONFIG_SR_WN_WN7_ALEXA & CONFIG_SR_WN_MODEL_WN7_QUANT +#define WAKENET_COEFF "alexa7" + +#elif CONFIG_SR_WN_WN8_ALEXA & CONFIG_SR_WN_MODEL_WN8_QUANT +#define WAKENET_COEFF "alexa8" + +#elif CONFIG_SR_WN_WN7_ALEXA & CONFIG_SR_WN_MODEL_WN7_QUANT8 +#define WAKENET_COEFF "alexa7q8" + +#elif CONFIG_SR_WN_WN8_HIESP & CONFIG_SR_WN_MODEL_WN8_QUANT +#define WAKENET_COEFF "hiesp8" + +#elif CONFIG_SR_WN_WN8_HIESP & CONFIG_SR_WN_MODEL_WN8_QUANT8 +#define WAKENET_COEFF "hiesp8q8" + +#else +#error No valid wake word selected. +#endif +#else +#define WAKENET_MODEL "NULL" +#define WAKENET_COEFF "NULL" +#endif +/* example + +static const sr_model_iface_t *model = &WAKENET_MODEL; + +//Initialize wakeNet model data +static model_iface_data_t *model_data=model->create(DET_MODE_90); + +//Set parameters of buffer +int audio_chunksize=model->get_samp_chunksize(model_data); +int frequency = model->get_samp_rate(model_data); +int16_t *buffer=malloc(audio_chunksize*sizeof(int16_t)); + +//Detect +int r=model->detect(model_data, buffer); +if (r>0) { + printf("Detection triggered output %d.\n", r); +} + +//Destroy model +model->destroy(model_data) + +*/ diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/hijeson_wn5X3.h b/tools/sdk/esp32/include/esp-sr/include/esp32/hijeson_wn5X3.h new file mode 100644 index 00000000000..c2e343880ed --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/hijeson_wn5X3.h @@ -0,0 +1,8 @@ +//Generated by mkmodel +#pragma once +#include +#include "dl_lib_coefgetter_if.h" +#include "dl_lib_matrix.h" +#include "dl_lib_matrixq.h" + +extern const model_coeff_getter_t get_coeff_hijeson_wn5X3; diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/hilexin_wn5.h b/tools/sdk/esp32/include/esp-sr/include/esp32/hilexin_wn5.h new file mode 100644 index 00000000000..d922a6aaed4 --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/hilexin_wn5.h @@ -0,0 +1,8 @@ +//Generated by mkmodel +#pragma once +#include +#include "dl_lib_coefgetter_if.h" +#include "dl_lib_matrix.h" +#include "dl_lib_matrixq.h" + +extern const model_coeff_getter_t get_coeff_hilexin_wn5; diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/hilexin_wn5X2.h b/tools/sdk/esp32/include/esp-sr/include/esp32/hilexin_wn5X2.h new file mode 100644 index 00000000000..5ca6bbca5ba --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/hilexin_wn5X2.h @@ -0,0 +1,8 @@ +//Generated by mkmodel +#pragma once +#include +#include "dl_lib_coefgetter_if.h" +#include "dl_lib_matrix.h" +#include "dl_lib_matrixq.h" + +extern const model_coeff_getter_t get_coeff_hilexin_wn5X2; diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/hilexin_wn5X3.h b/tools/sdk/esp32/include/esp-sr/include/esp32/hilexin_wn5X3.h new file mode 100644 index 00000000000..c78a64d2b77 --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/hilexin_wn5X3.h @@ -0,0 +1,8 @@ +//Generated by mkmodel +#pragma once +#include +#include "dl_lib_coefgetter_if.h" +#include "dl_lib_matrix.h" +#include "dl_lib_matrixq.h" + +extern const model_coeff_getter_t get_coeff_hilexin_wn5X3; diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/mn_process_commands.h b/tools/sdk/esp32/include/esp-sr/include/esp32/mn_process_commands.h new file mode 100644 index 00000000000..692137a3b78 --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/mn_process_commands.h @@ -0,0 +1,408 @@ +#pragma once +#include "esp_mn_iface.h" +#define SPEECH_COMMANDS_NUM 99 +#if CONFIG_SR_MN_CHINESE +#define MN_SPEECH_COMMAND_ID0 CONFIG_CN_SPEECH_COMMAND_ID0 +#define MN_SPEECH_COMMAND_ID1 CONFIG_CN_SPEECH_COMMAND_ID1 +#define MN_SPEECH_COMMAND_ID2 CONFIG_CN_SPEECH_COMMAND_ID2 +#define MN_SPEECH_COMMAND_ID3 CONFIG_CN_SPEECH_COMMAND_ID3 +#define MN_SPEECH_COMMAND_ID4 CONFIG_CN_SPEECH_COMMAND_ID4 +#define MN_SPEECH_COMMAND_ID5 CONFIG_CN_SPEECH_COMMAND_ID5 +#define MN_SPEECH_COMMAND_ID6 CONFIG_CN_SPEECH_COMMAND_ID6 +#define MN_SPEECH_COMMAND_ID7 CONFIG_CN_SPEECH_COMMAND_ID7 +#define MN_SPEECH_COMMAND_ID8 CONFIG_CN_SPEECH_COMMAND_ID8 +#define MN_SPEECH_COMMAND_ID9 CONFIG_CN_SPEECH_COMMAND_ID9 +#define MN_SPEECH_COMMAND_ID10 CONFIG_CN_SPEECH_COMMAND_ID10 +#define MN_SPEECH_COMMAND_ID11 CONFIG_CN_SPEECH_COMMAND_ID11 +#define MN_SPEECH_COMMAND_ID12 CONFIG_CN_SPEECH_COMMAND_ID12 +#define MN_SPEECH_COMMAND_ID13 CONFIG_CN_SPEECH_COMMAND_ID13 +#define MN_SPEECH_COMMAND_ID14 CONFIG_CN_SPEECH_COMMAND_ID14 +#define MN_SPEECH_COMMAND_ID15 CONFIG_CN_SPEECH_COMMAND_ID15 +#define MN_SPEECH_COMMAND_ID16 CONFIG_CN_SPEECH_COMMAND_ID16 +#define MN_SPEECH_COMMAND_ID17 CONFIG_CN_SPEECH_COMMAND_ID17 +#define MN_SPEECH_COMMAND_ID18 CONFIG_CN_SPEECH_COMMAND_ID18 +#define MN_SPEECH_COMMAND_ID19 CONFIG_CN_SPEECH_COMMAND_ID19 +#define MN_SPEECH_COMMAND_ID20 CONFIG_CN_SPEECH_COMMAND_ID20 +#define MN_SPEECH_COMMAND_ID21 CONFIG_CN_SPEECH_COMMAND_ID21 +#define MN_SPEECH_COMMAND_ID22 CONFIG_CN_SPEECH_COMMAND_ID22 +#define MN_SPEECH_COMMAND_ID23 CONFIG_CN_SPEECH_COMMAND_ID23 +#define MN_SPEECH_COMMAND_ID24 CONFIG_CN_SPEECH_COMMAND_ID24 +#define MN_SPEECH_COMMAND_ID25 CONFIG_CN_SPEECH_COMMAND_ID25 +#define MN_SPEECH_COMMAND_ID26 CONFIG_CN_SPEECH_COMMAND_ID26 +#define MN_SPEECH_COMMAND_ID27 CONFIG_CN_SPEECH_COMMAND_ID27 +#define MN_SPEECH_COMMAND_ID28 CONFIG_CN_SPEECH_COMMAND_ID28 +#define MN_SPEECH_COMMAND_ID29 CONFIG_CN_SPEECH_COMMAND_ID29 +#define MN_SPEECH_COMMAND_ID30 CONFIG_CN_SPEECH_COMMAND_ID30 +#define MN_SPEECH_COMMAND_ID31 CONFIG_CN_SPEECH_COMMAND_ID31 +#define MN_SPEECH_COMMAND_ID32 CONFIG_CN_SPEECH_COMMAND_ID32 +#define MN_SPEECH_COMMAND_ID33 CONFIG_CN_SPEECH_COMMAND_ID33 +#define MN_SPEECH_COMMAND_ID34 CONFIG_CN_SPEECH_COMMAND_ID34 +#define MN_SPEECH_COMMAND_ID35 CONFIG_CN_SPEECH_COMMAND_ID35 +#define MN_SPEECH_COMMAND_ID36 CONFIG_CN_SPEECH_COMMAND_ID36 +#define MN_SPEECH_COMMAND_ID37 CONFIG_CN_SPEECH_COMMAND_ID37 +#define MN_SPEECH_COMMAND_ID38 CONFIG_CN_SPEECH_COMMAND_ID38 +#define MN_SPEECH_COMMAND_ID39 CONFIG_CN_SPEECH_COMMAND_ID39 +#define MN_SPEECH_COMMAND_ID40 CONFIG_CN_SPEECH_COMMAND_ID40 +#define MN_SPEECH_COMMAND_ID41 CONFIG_CN_SPEECH_COMMAND_ID41 +#define MN_SPEECH_COMMAND_ID42 CONFIG_CN_SPEECH_COMMAND_ID42 +#define MN_SPEECH_COMMAND_ID43 CONFIG_CN_SPEECH_COMMAND_ID43 +#define MN_SPEECH_COMMAND_ID44 CONFIG_CN_SPEECH_COMMAND_ID44 +#define MN_SPEECH_COMMAND_ID45 CONFIG_CN_SPEECH_COMMAND_ID45 +#define MN_SPEECH_COMMAND_ID46 CONFIG_CN_SPEECH_COMMAND_ID46 +#define MN_SPEECH_COMMAND_ID47 CONFIG_CN_SPEECH_COMMAND_ID47 +#define MN_SPEECH_COMMAND_ID48 CONFIG_CN_SPEECH_COMMAND_ID48 +#define MN_SPEECH_COMMAND_ID49 CONFIG_CN_SPEECH_COMMAND_ID49 +#define MN_SPEECH_COMMAND_ID50 CONFIG_CN_SPEECH_COMMAND_ID50 +#define MN_SPEECH_COMMAND_ID51 CONFIG_CN_SPEECH_COMMAND_ID51 +#define MN_SPEECH_COMMAND_ID52 CONFIG_CN_SPEECH_COMMAND_ID52 +#define MN_SPEECH_COMMAND_ID53 CONFIG_CN_SPEECH_COMMAND_ID53 +#define MN_SPEECH_COMMAND_ID54 CONFIG_CN_SPEECH_COMMAND_ID54 +#define MN_SPEECH_COMMAND_ID55 CONFIG_CN_SPEECH_COMMAND_ID55 +#define MN_SPEECH_COMMAND_ID56 CONFIG_CN_SPEECH_COMMAND_ID56 +#define MN_SPEECH_COMMAND_ID57 CONFIG_CN_SPEECH_COMMAND_ID57 +#define MN_SPEECH_COMMAND_ID58 CONFIG_CN_SPEECH_COMMAND_ID58 +#define MN_SPEECH_COMMAND_ID59 CONFIG_CN_SPEECH_COMMAND_ID59 +#define MN_SPEECH_COMMAND_ID60 CONFIG_CN_SPEECH_COMMAND_ID60 +#define MN_SPEECH_COMMAND_ID61 CONFIG_CN_SPEECH_COMMAND_ID61 +#define MN_SPEECH_COMMAND_ID62 CONFIG_CN_SPEECH_COMMAND_ID62 +#define MN_SPEECH_COMMAND_ID63 CONFIG_CN_SPEECH_COMMAND_ID63 +#define MN_SPEECH_COMMAND_ID64 CONFIG_CN_SPEECH_COMMAND_ID64 +#define MN_SPEECH_COMMAND_ID65 CONFIG_CN_SPEECH_COMMAND_ID65 +#define MN_SPEECH_COMMAND_ID66 CONFIG_CN_SPEECH_COMMAND_ID66 +#define MN_SPEECH_COMMAND_ID67 CONFIG_CN_SPEECH_COMMAND_ID67 +#define MN_SPEECH_COMMAND_ID68 CONFIG_CN_SPEECH_COMMAND_ID68 +#define MN_SPEECH_COMMAND_ID69 CONFIG_CN_SPEECH_COMMAND_ID69 +#define MN_SPEECH_COMMAND_ID70 CONFIG_CN_SPEECH_COMMAND_ID70 +#define MN_SPEECH_COMMAND_ID71 CONFIG_CN_SPEECH_COMMAND_ID71 +#define MN_SPEECH_COMMAND_ID72 CONFIG_CN_SPEECH_COMMAND_ID72 +#define MN_SPEECH_COMMAND_ID73 CONFIG_CN_SPEECH_COMMAND_ID73 +#define MN_SPEECH_COMMAND_ID74 CONFIG_CN_SPEECH_COMMAND_ID74 +#define MN_SPEECH_COMMAND_ID75 CONFIG_CN_SPEECH_COMMAND_ID75 +#define MN_SPEECH_COMMAND_ID76 CONFIG_CN_SPEECH_COMMAND_ID76 +#define MN_SPEECH_COMMAND_ID77 CONFIG_CN_SPEECH_COMMAND_ID77 +#define MN_SPEECH_COMMAND_ID78 CONFIG_CN_SPEECH_COMMAND_ID78 +#define MN_SPEECH_COMMAND_ID79 CONFIG_CN_SPEECH_COMMAND_ID79 +#define MN_SPEECH_COMMAND_ID80 CONFIG_CN_SPEECH_COMMAND_ID80 +#define MN_SPEECH_COMMAND_ID81 CONFIG_CN_SPEECH_COMMAND_ID81 +#define MN_SPEECH_COMMAND_ID82 CONFIG_CN_SPEECH_COMMAND_ID82 +#define MN_SPEECH_COMMAND_ID83 CONFIG_CN_SPEECH_COMMAND_ID83 +#define MN_SPEECH_COMMAND_ID84 CONFIG_CN_SPEECH_COMMAND_ID84 +#define MN_SPEECH_COMMAND_ID85 CONFIG_CN_SPEECH_COMMAND_ID85 +#define MN_SPEECH_COMMAND_ID86 CONFIG_CN_SPEECH_COMMAND_ID86 +#define MN_SPEECH_COMMAND_ID87 CONFIG_CN_SPEECH_COMMAND_ID87 +#define MN_SPEECH_COMMAND_ID88 CONFIG_CN_SPEECH_COMMAND_ID88 +#define MN_SPEECH_COMMAND_ID89 CONFIG_CN_SPEECH_COMMAND_ID89 +#define MN_SPEECH_COMMAND_ID90 CONFIG_CN_SPEECH_COMMAND_ID90 +#define MN_SPEECH_COMMAND_ID91 CONFIG_CN_SPEECH_COMMAND_ID91 +#define MN_SPEECH_COMMAND_ID92 CONFIG_CN_SPEECH_COMMAND_ID92 +#define MN_SPEECH_COMMAND_ID93 CONFIG_CN_SPEECH_COMMAND_ID93 +#define MN_SPEECH_COMMAND_ID94 CONFIG_CN_SPEECH_COMMAND_ID94 +#define MN_SPEECH_COMMAND_ID95 CONFIG_CN_SPEECH_COMMAND_ID95 +#define MN_SPEECH_COMMAND_ID96 CONFIG_CN_SPEECH_COMMAND_ID96 +#define MN_SPEECH_COMMAND_ID97 CONFIG_CN_SPEECH_COMMAND_ID97 +#define MN_SPEECH_COMMAND_ID98 CONFIG_CN_SPEECH_COMMAND_ID98 +#define MN_SPEECH_COMMAND_ID99 CONFIG_CN_SPEECH_COMMAND_ID99 +#define MN_SPEECH_COMMAND_ID100 CONFIG_CN_SPEECH_COMMAND_ID100 +#define MN_SPEECH_COMMAND_ID101 CONFIG_CN_SPEECH_COMMAND_ID101 +#define MN_SPEECH_COMMAND_ID102 CONFIG_CN_SPEECH_COMMAND_ID102 +#define MN_SPEECH_COMMAND_ID103 CONFIG_CN_SPEECH_COMMAND_ID103 +#define MN_SPEECH_COMMAND_ID104 CONFIG_CN_SPEECH_COMMAND_ID104 +#define MN_SPEECH_COMMAND_ID105 CONFIG_CN_SPEECH_COMMAND_ID105 +#define MN_SPEECH_COMMAND_ID106 CONFIG_CN_SPEECH_COMMAND_ID106 +#define MN_SPEECH_COMMAND_ID107 CONFIG_CN_SPEECH_COMMAND_ID107 +#define MN_SPEECH_COMMAND_ID108 CONFIG_CN_SPEECH_COMMAND_ID108 +#define MN_SPEECH_COMMAND_ID109 CONFIG_CN_SPEECH_COMMAND_ID109 +#define MN_SPEECH_COMMAND_ID110 CONFIG_CN_SPEECH_COMMAND_ID110 +#define MN_SPEECH_COMMAND_ID111 CONFIG_CN_SPEECH_COMMAND_ID111 +#define MN_SPEECH_COMMAND_ID112 CONFIG_CN_SPEECH_COMMAND_ID112 +#define MN_SPEECH_COMMAND_ID113 CONFIG_CN_SPEECH_COMMAND_ID113 +#define MN_SPEECH_COMMAND_ID114 CONFIG_CN_SPEECH_COMMAND_ID114 +#define MN_SPEECH_COMMAND_ID115 CONFIG_CN_SPEECH_COMMAND_ID115 +#define MN_SPEECH_COMMAND_ID116 CONFIG_CN_SPEECH_COMMAND_ID116 +#define MN_SPEECH_COMMAND_ID117 CONFIG_CN_SPEECH_COMMAND_ID117 +#define MN_SPEECH_COMMAND_ID118 CONFIG_CN_SPEECH_COMMAND_ID118 +#define MN_SPEECH_COMMAND_ID119 CONFIG_CN_SPEECH_COMMAND_ID119 +#define MN_SPEECH_COMMAND_ID120 CONFIG_CN_SPEECH_COMMAND_ID120 +#define MN_SPEECH_COMMAND_ID121 CONFIG_CN_SPEECH_COMMAND_ID121 +#define MN_SPEECH_COMMAND_ID122 CONFIG_CN_SPEECH_COMMAND_ID122 +#define MN_SPEECH_COMMAND_ID123 CONFIG_CN_SPEECH_COMMAND_ID123 +#define MN_SPEECH_COMMAND_ID124 CONFIG_CN_SPEECH_COMMAND_ID124 +#define MN_SPEECH_COMMAND_ID125 CONFIG_CN_SPEECH_COMMAND_ID125 +#define MN_SPEECH_COMMAND_ID126 CONFIG_CN_SPEECH_COMMAND_ID126 +#define MN_SPEECH_COMMAND_ID127 CONFIG_CN_SPEECH_COMMAND_ID127 +#define MN_SPEECH_COMMAND_ID128 CONFIG_CN_SPEECH_COMMAND_ID128 +#define MN_SPEECH_COMMAND_ID129 CONFIG_CN_SPEECH_COMMAND_ID129 +#define MN_SPEECH_COMMAND_ID130 CONFIG_CN_SPEECH_COMMAND_ID130 +#define MN_SPEECH_COMMAND_ID131 CONFIG_CN_SPEECH_COMMAND_ID131 +#define MN_SPEECH_COMMAND_ID132 CONFIG_CN_SPEECH_COMMAND_ID132 +#define MN_SPEECH_COMMAND_ID133 CONFIG_CN_SPEECH_COMMAND_ID133 +#define MN_SPEECH_COMMAND_ID134 CONFIG_CN_SPEECH_COMMAND_ID134 +#define MN_SPEECH_COMMAND_ID135 CONFIG_CN_SPEECH_COMMAND_ID135 +#define MN_SPEECH_COMMAND_ID136 CONFIG_CN_SPEECH_COMMAND_ID136 +#define MN_SPEECH_COMMAND_ID137 CONFIG_CN_SPEECH_COMMAND_ID137 +#define MN_SPEECH_COMMAND_ID138 CONFIG_CN_SPEECH_COMMAND_ID138 +#define MN_SPEECH_COMMAND_ID139 CONFIG_CN_SPEECH_COMMAND_ID139 +#define MN_SPEECH_COMMAND_ID140 CONFIG_CN_SPEECH_COMMAND_ID140 +#define MN_SPEECH_COMMAND_ID141 CONFIG_CN_SPEECH_COMMAND_ID141 +#define MN_SPEECH_COMMAND_ID142 CONFIG_CN_SPEECH_COMMAND_ID142 +#define MN_SPEECH_COMMAND_ID143 CONFIG_CN_SPEECH_COMMAND_ID143 +#define MN_SPEECH_COMMAND_ID144 CONFIG_CN_SPEECH_COMMAND_ID144 +#define MN_SPEECH_COMMAND_ID145 CONFIG_CN_SPEECH_COMMAND_ID145 +#define MN_SPEECH_COMMAND_ID146 CONFIG_CN_SPEECH_COMMAND_ID146 +#define MN_SPEECH_COMMAND_ID147 CONFIG_CN_SPEECH_COMMAND_ID147 +#define MN_SPEECH_COMMAND_ID148 CONFIG_CN_SPEECH_COMMAND_ID148 +#define MN_SPEECH_COMMAND_ID149 CONFIG_CN_SPEECH_COMMAND_ID149 +#define MN_SPEECH_COMMAND_ID150 CONFIG_CN_SPEECH_COMMAND_ID150 +#define MN_SPEECH_COMMAND_ID151 CONFIG_CN_SPEECH_COMMAND_ID151 +#define MN_SPEECH_COMMAND_ID152 CONFIG_CN_SPEECH_COMMAND_ID152 +#define MN_SPEECH_COMMAND_ID153 CONFIG_CN_SPEECH_COMMAND_ID153 +#define MN_SPEECH_COMMAND_ID154 CONFIG_CN_SPEECH_COMMAND_ID154 +#define MN_SPEECH_COMMAND_ID155 CONFIG_CN_SPEECH_COMMAND_ID155 +#define MN_SPEECH_COMMAND_ID156 CONFIG_CN_SPEECH_COMMAND_ID156 +#define MN_SPEECH_COMMAND_ID157 CONFIG_CN_SPEECH_COMMAND_ID157 +#define MN_SPEECH_COMMAND_ID158 CONFIG_CN_SPEECH_COMMAND_ID158 +#define MN_SPEECH_COMMAND_ID159 CONFIG_CN_SPEECH_COMMAND_ID159 +#define MN_SPEECH_COMMAND_ID160 CONFIG_CN_SPEECH_COMMAND_ID160 +#define MN_SPEECH_COMMAND_ID161 CONFIG_CN_SPEECH_COMMAND_ID161 +#define MN_SPEECH_COMMAND_ID162 CONFIG_CN_SPEECH_COMMAND_ID162 +#define MN_SPEECH_COMMAND_ID163 CONFIG_CN_SPEECH_COMMAND_ID163 +#define MN_SPEECH_COMMAND_ID164 CONFIG_CN_SPEECH_COMMAND_ID164 +#define MN_SPEECH_COMMAND_ID165 CONFIG_CN_SPEECH_COMMAND_ID165 +#define MN_SPEECH_COMMAND_ID166 CONFIG_CN_SPEECH_COMMAND_ID166 +#define MN_SPEECH_COMMAND_ID167 CONFIG_CN_SPEECH_COMMAND_ID167 +#define MN_SPEECH_COMMAND_ID168 CONFIG_CN_SPEECH_COMMAND_ID168 +#define MN_SPEECH_COMMAND_ID169 CONFIG_CN_SPEECH_COMMAND_ID169 +#define MN_SPEECH_COMMAND_ID170 CONFIG_CN_SPEECH_COMMAND_ID170 +#define MN_SPEECH_COMMAND_ID171 CONFIG_CN_SPEECH_COMMAND_ID171 +#define MN_SPEECH_COMMAND_ID172 CONFIG_CN_SPEECH_COMMAND_ID172 +#define MN_SPEECH_COMMAND_ID173 CONFIG_CN_SPEECH_COMMAND_ID173 +#define MN_SPEECH_COMMAND_ID174 CONFIG_CN_SPEECH_COMMAND_ID174 +#define MN_SPEECH_COMMAND_ID175 CONFIG_CN_SPEECH_COMMAND_ID175 +#define MN_SPEECH_COMMAND_ID176 CONFIG_CN_SPEECH_COMMAND_ID176 +#define MN_SPEECH_COMMAND_ID177 CONFIG_CN_SPEECH_COMMAND_ID177 +#define MN_SPEECH_COMMAND_ID178 CONFIG_CN_SPEECH_COMMAND_ID178 +#define MN_SPEECH_COMMAND_ID179 CONFIG_CN_SPEECH_COMMAND_ID179 +#define MN_SPEECH_COMMAND_ID180 CONFIG_CN_SPEECH_COMMAND_ID180 +#define MN_SPEECH_COMMAND_ID181 CONFIG_CN_SPEECH_COMMAND_ID181 +#define MN_SPEECH_COMMAND_ID182 CONFIG_CN_SPEECH_COMMAND_ID182 +#define MN_SPEECH_COMMAND_ID183 CONFIG_CN_SPEECH_COMMAND_ID183 +#define MN_SPEECH_COMMAND_ID184 CONFIG_CN_SPEECH_COMMAND_ID184 +#define MN_SPEECH_COMMAND_ID185 CONFIG_CN_SPEECH_COMMAND_ID185 +#define MN_SPEECH_COMMAND_ID186 CONFIG_CN_SPEECH_COMMAND_ID186 +#define MN_SPEECH_COMMAND_ID187 CONFIG_CN_SPEECH_COMMAND_ID187 +#define MN_SPEECH_COMMAND_ID188 CONFIG_CN_SPEECH_COMMAND_ID188 +#define MN_SPEECH_COMMAND_ID189 CONFIG_CN_SPEECH_COMMAND_ID189 +#define MN_SPEECH_COMMAND_ID190 CONFIG_CN_SPEECH_COMMAND_ID190 +#define MN_SPEECH_COMMAND_ID191 CONFIG_CN_SPEECH_COMMAND_ID191 +#define MN_SPEECH_COMMAND_ID192 CONFIG_CN_SPEECH_COMMAND_ID192 +#define MN_SPEECH_COMMAND_ID193 CONFIG_CN_SPEECH_COMMAND_ID193 +#define MN_SPEECH_COMMAND_ID194 CONFIG_CN_SPEECH_COMMAND_ID194 +#define MN_SPEECH_COMMAND_ID195 CONFIG_CN_SPEECH_COMMAND_ID195 +#define MN_SPEECH_COMMAND_ID196 CONFIG_CN_SPEECH_COMMAND_ID196 +#define MN_SPEECH_COMMAND_ID197 CONFIG_CN_SPEECH_COMMAND_ID197 +#define MN_SPEECH_COMMAND_ID198 CONFIG_CN_SPEECH_COMMAND_ID198 +#define MN_SPEECH_COMMAND_ID199 CONFIG_CN_SPEECH_COMMAND_ID199 +#elif CONFIG_SR_MN_ENGLISH +#define MN_SPEECH_COMMAND_ID0 CONFIG_EN_SPEECH_COMMAND_ID0 +#define MN_SPEECH_COMMAND_ID1 CONFIG_EN_SPEECH_COMMAND_ID1 +#define MN_SPEECH_COMMAND_ID2 CONFIG_EN_SPEECH_COMMAND_ID2 +#define MN_SPEECH_COMMAND_ID3 CONFIG_EN_SPEECH_COMMAND_ID3 +#define MN_SPEECH_COMMAND_ID4 CONFIG_EN_SPEECH_COMMAND_ID4 +#define MN_SPEECH_COMMAND_ID5 CONFIG_EN_SPEECH_COMMAND_ID5 +#define MN_SPEECH_COMMAND_ID6 CONFIG_EN_SPEECH_COMMAND_ID6 +#define MN_SPEECH_COMMAND_ID7 CONFIG_EN_SPEECH_COMMAND_ID7 +#define MN_SPEECH_COMMAND_ID8 CONFIG_EN_SPEECH_COMMAND_ID8 +#define MN_SPEECH_COMMAND_ID9 CONFIG_EN_SPEECH_COMMAND_ID9 +#define MN_SPEECH_COMMAND_ID10 CONFIG_EN_SPEECH_COMMAND_ID10 +#define MN_SPEECH_COMMAND_ID11 CONFIG_EN_SPEECH_COMMAND_ID11 +#define MN_SPEECH_COMMAND_ID12 CONFIG_EN_SPEECH_COMMAND_ID12 +#define MN_SPEECH_COMMAND_ID13 CONFIG_EN_SPEECH_COMMAND_ID13 +#define MN_SPEECH_COMMAND_ID14 CONFIG_EN_SPEECH_COMMAND_ID14 +#define MN_SPEECH_COMMAND_ID15 CONFIG_EN_SPEECH_COMMAND_ID15 +#define MN_SPEECH_COMMAND_ID16 CONFIG_EN_SPEECH_COMMAND_ID16 +#define MN_SPEECH_COMMAND_ID17 CONFIG_EN_SPEECH_COMMAND_ID17 +#define MN_SPEECH_COMMAND_ID18 CONFIG_EN_SPEECH_COMMAND_ID18 +#define MN_SPEECH_COMMAND_ID19 CONFIG_EN_SPEECH_COMMAND_ID19 +#define MN_SPEECH_COMMAND_ID20 CONFIG_EN_SPEECH_COMMAND_ID20 +#define MN_SPEECH_COMMAND_ID21 CONFIG_EN_SPEECH_COMMAND_ID21 +#define MN_SPEECH_COMMAND_ID22 CONFIG_EN_SPEECH_COMMAND_ID22 +#define MN_SPEECH_COMMAND_ID23 CONFIG_EN_SPEECH_COMMAND_ID23 +#define MN_SPEECH_COMMAND_ID24 CONFIG_EN_SPEECH_COMMAND_ID24 +#define MN_SPEECH_COMMAND_ID25 CONFIG_EN_SPEECH_COMMAND_ID25 +#define MN_SPEECH_COMMAND_ID26 CONFIG_EN_SPEECH_COMMAND_ID26 +#define MN_SPEECH_COMMAND_ID27 CONFIG_EN_SPEECH_COMMAND_ID27 +#define MN_SPEECH_COMMAND_ID28 CONFIG_EN_SPEECH_COMMAND_ID28 +#define MN_SPEECH_COMMAND_ID29 CONFIG_EN_SPEECH_COMMAND_ID29 +#define MN_SPEECH_COMMAND_ID30 CONFIG_EN_SPEECH_COMMAND_ID30 +#define MN_SPEECH_COMMAND_ID31 CONFIG_EN_SPEECH_COMMAND_ID31 +#define MN_SPEECH_COMMAND_ID32 CONFIG_EN_SPEECH_COMMAND_ID32 +#define MN_SPEECH_COMMAND_ID33 CONFIG_EN_SPEECH_COMMAND_ID33 +#define MN_SPEECH_COMMAND_ID34 CONFIG_EN_SPEECH_COMMAND_ID34 +#define MN_SPEECH_COMMAND_ID35 CONFIG_EN_SPEECH_COMMAND_ID35 +#define MN_SPEECH_COMMAND_ID36 CONFIG_EN_SPEECH_COMMAND_ID36 +#define MN_SPEECH_COMMAND_ID37 CONFIG_EN_SPEECH_COMMAND_ID37 +#define MN_SPEECH_COMMAND_ID38 CONFIG_EN_SPEECH_COMMAND_ID38 +#define MN_SPEECH_COMMAND_ID39 CONFIG_EN_SPEECH_COMMAND_ID39 +#define MN_SPEECH_COMMAND_ID40 CONFIG_EN_SPEECH_COMMAND_ID40 +#define MN_SPEECH_COMMAND_ID41 CONFIG_EN_SPEECH_COMMAND_ID41 +#define MN_SPEECH_COMMAND_ID42 CONFIG_EN_SPEECH_COMMAND_ID42 +#define MN_SPEECH_COMMAND_ID43 CONFIG_EN_SPEECH_COMMAND_ID43 +#define MN_SPEECH_COMMAND_ID44 CONFIG_EN_SPEECH_COMMAND_ID44 +#define MN_SPEECH_COMMAND_ID45 CONFIG_EN_SPEECH_COMMAND_ID45 +#define MN_SPEECH_COMMAND_ID46 CONFIG_EN_SPEECH_COMMAND_ID46 +#define MN_SPEECH_COMMAND_ID47 CONFIG_EN_SPEECH_COMMAND_ID47 +#define MN_SPEECH_COMMAND_ID48 CONFIG_EN_SPEECH_COMMAND_ID48 +#define MN_SPEECH_COMMAND_ID49 CONFIG_EN_SPEECH_COMMAND_ID49 +#define MN_SPEECH_COMMAND_ID50 CONFIG_EN_SPEECH_COMMAND_ID50 +#define MN_SPEECH_COMMAND_ID51 CONFIG_EN_SPEECH_COMMAND_ID51 +#define MN_SPEECH_COMMAND_ID52 CONFIG_EN_SPEECH_COMMAND_ID52 +#define MN_SPEECH_COMMAND_ID53 CONFIG_EN_SPEECH_COMMAND_ID53 +#define MN_SPEECH_COMMAND_ID54 CONFIG_EN_SPEECH_COMMAND_ID54 +#define MN_SPEECH_COMMAND_ID55 CONFIG_EN_SPEECH_COMMAND_ID55 +#define MN_SPEECH_COMMAND_ID56 CONFIG_EN_SPEECH_COMMAND_ID56 +#define MN_SPEECH_COMMAND_ID57 CONFIG_EN_SPEECH_COMMAND_ID57 +#define MN_SPEECH_COMMAND_ID58 CONFIG_EN_SPEECH_COMMAND_ID58 +#define MN_SPEECH_COMMAND_ID59 CONFIG_EN_SPEECH_COMMAND_ID59 +#define MN_SPEECH_COMMAND_ID60 CONFIG_EN_SPEECH_COMMAND_ID60 +#define MN_SPEECH_COMMAND_ID61 CONFIG_EN_SPEECH_COMMAND_ID61 +#define MN_SPEECH_COMMAND_ID62 CONFIG_EN_SPEECH_COMMAND_ID62 +#define MN_SPEECH_COMMAND_ID63 CONFIG_EN_SPEECH_COMMAND_ID63 +#define MN_SPEECH_COMMAND_ID64 CONFIG_EN_SPEECH_COMMAND_ID64 +#define MN_SPEECH_COMMAND_ID65 CONFIG_EN_SPEECH_COMMAND_ID65 +#define MN_SPEECH_COMMAND_ID66 CONFIG_EN_SPEECH_COMMAND_ID66 +#define MN_SPEECH_COMMAND_ID67 CONFIG_EN_SPEECH_COMMAND_ID67 +#define MN_SPEECH_COMMAND_ID68 CONFIG_EN_SPEECH_COMMAND_ID68 +#define MN_SPEECH_COMMAND_ID69 CONFIG_EN_SPEECH_COMMAND_ID69 +#define MN_SPEECH_COMMAND_ID70 CONFIG_EN_SPEECH_COMMAND_ID70 +#define MN_SPEECH_COMMAND_ID71 CONFIG_EN_SPEECH_COMMAND_ID71 +#define MN_SPEECH_COMMAND_ID72 CONFIG_EN_SPEECH_COMMAND_ID72 +#define MN_SPEECH_COMMAND_ID73 CONFIG_EN_SPEECH_COMMAND_ID73 +#define MN_SPEECH_COMMAND_ID74 CONFIG_EN_SPEECH_COMMAND_ID74 +#define MN_SPEECH_COMMAND_ID75 CONFIG_EN_SPEECH_COMMAND_ID75 +#define MN_SPEECH_COMMAND_ID76 CONFIG_EN_SPEECH_COMMAND_ID76 +#define MN_SPEECH_COMMAND_ID77 CONFIG_EN_SPEECH_COMMAND_ID77 +#define MN_SPEECH_COMMAND_ID78 CONFIG_EN_SPEECH_COMMAND_ID78 +#define MN_SPEECH_COMMAND_ID79 CONFIG_EN_SPEECH_COMMAND_ID79 +#define MN_SPEECH_COMMAND_ID80 CONFIG_EN_SPEECH_COMMAND_ID80 +#define MN_SPEECH_COMMAND_ID81 CONFIG_EN_SPEECH_COMMAND_ID81 +#define MN_SPEECH_COMMAND_ID82 CONFIG_EN_SPEECH_COMMAND_ID82 +#define MN_SPEECH_COMMAND_ID83 CONFIG_EN_SPEECH_COMMAND_ID83 +#define MN_SPEECH_COMMAND_ID84 CONFIG_EN_SPEECH_COMMAND_ID84 +#define MN_SPEECH_COMMAND_ID85 CONFIG_EN_SPEECH_COMMAND_ID85 +#define MN_SPEECH_COMMAND_ID86 CONFIG_EN_SPEECH_COMMAND_ID86 +#define MN_SPEECH_COMMAND_ID87 CONFIG_EN_SPEECH_COMMAND_ID87 +#define MN_SPEECH_COMMAND_ID88 CONFIG_EN_SPEECH_COMMAND_ID88 +#define MN_SPEECH_COMMAND_ID89 CONFIG_EN_SPEECH_COMMAND_ID89 +#define MN_SPEECH_COMMAND_ID90 CONFIG_EN_SPEECH_COMMAND_ID90 +#define MN_SPEECH_COMMAND_ID91 CONFIG_EN_SPEECH_COMMAND_ID91 +#define MN_SPEECH_COMMAND_ID92 CONFIG_EN_SPEECH_COMMAND_ID92 +#define MN_SPEECH_COMMAND_ID93 CONFIG_EN_SPEECH_COMMAND_ID93 +#define MN_SPEECH_COMMAND_ID94 CONFIG_EN_SPEECH_COMMAND_ID94 +#define MN_SPEECH_COMMAND_ID95 CONFIG_EN_SPEECH_COMMAND_ID95 +#define MN_SPEECH_COMMAND_ID96 CONFIG_EN_SPEECH_COMMAND_ID96 +#define MN_SPEECH_COMMAND_ID97 CONFIG_EN_SPEECH_COMMAND_ID97 +#define MN_SPEECH_COMMAND_ID98 CONFIG_EN_SPEECH_COMMAND_ID98 +#define MN_SPEECH_COMMAND_ID99 CONFIG_EN_SPEECH_COMMAND_ID99 +#define MN_SPEECH_COMMAND_ID100 CONFIG_EN_SPEECH_COMMAND_ID100 +#define MN_SPEECH_COMMAND_ID101 CONFIG_EN_SPEECH_COMMAND_ID101 +#define MN_SPEECH_COMMAND_ID102 CONFIG_EN_SPEECH_COMMAND_ID102 +#define MN_SPEECH_COMMAND_ID103 CONFIG_EN_SPEECH_COMMAND_ID103 +#define MN_SPEECH_COMMAND_ID104 CONFIG_EN_SPEECH_COMMAND_ID104 +#define MN_SPEECH_COMMAND_ID105 CONFIG_EN_SPEECH_COMMAND_ID105 +#define MN_SPEECH_COMMAND_ID106 CONFIG_EN_SPEECH_COMMAND_ID106 +#define MN_SPEECH_COMMAND_ID107 CONFIG_EN_SPEECH_COMMAND_ID107 +#define MN_SPEECH_COMMAND_ID108 CONFIG_EN_SPEECH_COMMAND_ID108 +#define MN_SPEECH_COMMAND_ID109 CONFIG_EN_SPEECH_COMMAND_ID109 +#define MN_SPEECH_COMMAND_ID110 CONFIG_EN_SPEECH_COMMAND_ID110 +#define MN_SPEECH_COMMAND_ID111 CONFIG_EN_SPEECH_COMMAND_ID111 +#define MN_SPEECH_COMMAND_ID112 CONFIG_EN_SPEECH_COMMAND_ID112 +#define MN_SPEECH_COMMAND_ID113 CONFIG_EN_SPEECH_COMMAND_ID113 +#define MN_SPEECH_COMMAND_ID114 CONFIG_EN_SPEECH_COMMAND_ID114 +#define MN_SPEECH_COMMAND_ID115 CONFIG_EN_SPEECH_COMMAND_ID115 +#define MN_SPEECH_COMMAND_ID116 CONFIG_EN_SPEECH_COMMAND_ID116 +#define MN_SPEECH_COMMAND_ID117 CONFIG_EN_SPEECH_COMMAND_ID117 +#define MN_SPEECH_COMMAND_ID118 CONFIG_EN_SPEECH_COMMAND_ID118 +#define MN_SPEECH_COMMAND_ID119 CONFIG_EN_SPEECH_COMMAND_ID119 +#define MN_SPEECH_COMMAND_ID120 CONFIG_EN_SPEECH_COMMAND_ID120 +#define MN_SPEECH_COMMAND_ID121 CONFIG_EN_SPEECH_COMMAND_ID121 +#define MN_SPEECH_COMMAND_ID122 CONFIG_EN_SPEECH_COMMAND_ID122 +#define MN_SPEECH_COMMAND_ID123 CONFIG_EN_SPEECH_COMMAND_ID123 +#define MN_SPEECH_COMMAND_ID124 CONFIG_EN_SPEECH_COMMAND_ID124 +#define MN_SPEECH_COMMAND_ID125 CONFIG_EN_SPEECH_COMMAND_ID125 +#define MN_SPEECH_COMMAND_ID126 CONFIG_EN_SPEECH_COMMAND_ID126 +#define MN_SPEECH_COMMAND_ID127 CONFIG_EN_SPEECH_COMMAND_ID127 +#define MN_SPEECH_COMMAND_ID128 CONFIG_EN_SPEECH_COMMAND_ID128 +#define MN_SPEECH_COMMAND_ID129 CONFIG_EN_SPEECH_COMMAND_ID129 +#define MN_SPEECH_COMMAND_ID130 CONFIG_EN_SPEECH_COMMAND_ID130 +#define MN_SPEECH_COMMAND_ID131 CONFIG_EN_SPEECH_COMMAND_ID131 +#define MN_SPEECH_COMMAND_ID132 CONFIG_EN_SPEECH_COMMAND_ID132 +#define MN_SPEECH_COMMAND_ID133 CONFIG_EN_SPEECH_COMMAND_ID133 +#define MN_SPEECH_COMMAND_ID134 CONFIG_EN_SPEECH_COMMAND_ID134 +#define MN_SPEECH_COMMAND_ID135 CONFIG_EN_SPEECH_COMMAND_ID135 +#define MN_SPEECH_COMMAND_ID136 CONFIG_EN_SPEECH_COMMAND_ID136 +#define MN_SPEECH_COMMAND_ID137 CONFIG_EN_SPEECH_COMMAND_ID137 +#define MN_SPEECH_COMMAND_ID138 CONFIG_EN_SPEECH_COMMAND_ID138 +#define MN_SPEECH_COMMAND_ID139 CONFIG_EN_SPEECH_COMMAND_ID139 +#define MN_SPEECH_COMMAND_ID140 CONFIG_EN_SPEECH_COMMAND_ID140 +#define MN_SPEECH_COMMAND_ID141 CONFIG_EN_SPEECH_COMMAND_ID141 +#define MN_SPEECH_COMMAND_ID142 CONFIG_EN_SPEECH_COMMAND_ID142 +#define MN_SPEECH_COMMAND_ID143 CONFIG_EN_SPEECH_COMMAND_ID143 +#define MN_SPEECH_COMMAND_ID144 CONFIG_EN_SPEECH_COMMAND_ID144 +#define MN_SPEECH_COMMAND_ID145 CONFIG_EN_SPEECH_COMMAND_ID145 +#define MN_SPEECH_COMMAND_ID146 CONFIG_EN_SPEECH_COMMAND_ID146 +#define MN_SPEECH_COMMAND_ID147 CONFIG_EN_SPEECH_COMMAND_ID147 +#define MN_SPEECH_COMMAND_ID148 CONFIG_EN_SPEECH_COMMAND_ID148 +#define MN_SPEECH_COMMAND_ID149 CONFIG_EN_SPEECH_COMMAND_ID149 +#define MN_SPEECH_COMMAND_ID150 CONFIG_EN_SPEECH_COMMAND_ID150 +#define MN_SPEECH_COMMAND_ID151 CONFIG_EN_SPEECH_COMMAND_ID151 +#define MN_SPEECH_COMMAND_ID152 CONFIG_EN_SPEECH_COMMAND_ID152 +#define MN_SPEECH_COMMAND_ID153 CONFIG_EN_SPEECH_COMMAND_ID153 +#define MN_SPEECH_COMMAND_ID154 CONFIG_EN_SPEECH_COMMAND_ID154 +#define MN_SPEECH_COMMAND_ID155 CONFIG_EN_SPEECH_COMMAND_ID155 +#define MN_SPEECH_COMMAND_ID156 CONFIG_EN_SPEECH_COMMAND_ID156 +#define MN_SPEECH_COMMAND_ID157 CONFIG_EN_SPEECH_COMMAND_ID157 +#define MN_SPEECH_COMMAND_ID158 CONFIG_EN_SPEECH_COMMAND_ID158 +#define MN_SPEECH_COMMAND_ID159 CONFIG_EN_SPEECH_COMMAND_ID159 +#define MN_SPEECH_COMMAND_ID160 CONFIG_EN_SPEECH_COMMAND_ID160 +#define MN_SPEECH_COMMAND_ID161 CONFIG_EN_SPEECH_COMMAND_ID161 +#define MN_SPEECH_COMMAND_ID162 CONFIG_EN_SPEECH_COMMAND_ID162 +#define MN_SPEECH_COMMAND_ID163 CONFIG_EN_SPEECH_COMMAND_ID163 +#define MN_SPEECH_COMMAND_ID164 CONFIG_EN_SPEECH_COMMAND_ID164 +#define MN_SPEECH_COMMAND_ID165 CONFIG_EN_SPEECH_COMMAND_ID165 +#define MN_SPEECH_COMMAND_ID166 CONFIG_EN_SPEECH_COMMAND_ID166 +#define MN_SPEECH_COMMAND_ID167 CONFIG_EN_SPEECH_COMMAND_ID167 +#define MN_SPEECH_COMMAND_ID168 CONFIG_EN_SPEECH_COMMAND_ID168 +#define MN_SPEECH_COMMAND_ID169 CONFIG_EN_SPEECH_COMMAND_ID169 +#define MN_SPEECH_COMMAND_ID170 CONFIG_EN_SPEECH_COMMAND_ID170 +#define MN_SPEECH_COMMAND_ID171 CONFIG_EN_SPEECH_COMMAND_ID171 +#define MN_SPEECH_COMMAND_ID172 CONFIG_EN_SPEECH_COMMAND_ID172 +#define MN_SPEECH_COMMAND_ID173 CONFIG_EN_SPEECH_COMMAND_ID173 +#define MN_SPEECH_COMMAND_ID174 CONFIG_EN_SPEECH_COMMAND_ID174 +#define MN_SPEECH_COMMAND_ID175 CONFIG_EN_SPEECH_COMMAND_ID175 +#define MN_SPEECH_COMMAND_ID176 CONFIG_EN_SPEECH_COMMAND_ID176 +#define MN_SPEECH_COMMAND_ID177 CONFIG_EN_SPEECH_COMMAND_ID177 +#define MN_SPEECH_COMMAND_ID178 CONFIG_EN_SPEECH_COMMAND_ID178 +#define MN_SPEECH_COMMAND_ID179 CONFIG_EN_SPEECH_COMMAND_ID179 +#define MN_SPEECH_COMMAND_ID180 CONFIG_EN_SPEECH_COMMAND_ID180 +#define MN_SPEECH_COMMAND_ID181 CONFIG_EN_SPEECH_COMMAND_ID181 +#define MN_SPEECH_COMMAND_ID182 CONFIG_EN_SPEECH_COMMAND_ID182 +#define MN_SPEECH_COMMAND_ID183 CONFIG_EN_SPEECH_COMMAND_ID183 +#define MN_SPEECH_COMMAND_ID184 CONFIG_EN_SPEECH_COMMAND_ID184 +#define MN_SPEECH_COMMAND_ID185 CONFIG_EN_SPEECH_COMMAND_ID185 +#define MN_SPEECH_COMMAND_ID186 CONFIG_EN_SPEECH_COMMAND_ID186 +#define MN_SPEECH_COMMAND_ID187 CONFIG_EN_SPEECH_COMMAND_ID187 +#define MN_SPEECH_COMMAND_ID188 CONFIG_EN_SPEECH_COMMAND_ID188 +#define MN_SPEECH_COMMAND_ID189 CONFIG_EN_SPEECH_COMMAND_ID189 +#define MN_SPEECH_COMMAND_ID190 CONFIG_EN_SPEECH_COMMAND_ID190 +#define MN_SPEECH_COMMAND_ID191 CONFIG_EN_SPEECH_COMMAND_ID191 +#define MN_SPEECH_COMMAND_ID192 CONFIG_EN_SPEECH_COMMAND_ID192 +#define MN_SPEECH_COMMAND_ID193 CONFIG_EN_SPEECH_COMMAND_ID193 +#define MN_SPEECH_COMMAND_ID194 CONFIG_EN_SPEECH_COMMAND_ID194 +#define MN_SPEECH_COMMAND_ID195 CONFIG_EN_SPEECH_COMMAND_ID195 +#define MN_SPEECH_COMMAND_ID196 CONFIG_EN_SPEECH_COMMAND_ID196 +#define MN_SPEECH_COMMAND_ID197 CONFIG_EN_SPEECH_COMMAND_ID197 +#define MN_SPEECH_COMMAND_ID198 CONFIG_EN_SPEECH_COMMAND_ID198 +#define MN_SPEECH_COMMAND_ID199 CONFIG_EN_SPEECH_COMMAND_ID199 +#endif +char *get_id_name(int i); +void reset_speech_commands(model_iface_data_t *model_data, char* command_str, char *err_phrase_id); \ No newline at end of file diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/model_path.h b/tools/sdk/esp32/include/esp-sr/include/esp32/model_path.h new file mode 100644 index 00000000000..b9cdc302ad8 --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/model_path.h @@ -0,0 +1,3 @@ +#pragma once +char *get_model_base_path(void); +void srmodel_spiffs_init(void); \ No newline at end of file diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/multinet2_ch.h b/tools/sdk/esp32/include/esp-sr/include/esp32/multinet2_ch.h new file mode 100644 index 00000000000..2cee215dca7 --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/multinet2_ch.h @@ -0,0 +1,9 @@ +//Generated by mkmodel_py +#pragma once +#include +#include "dl_lib_coefgetter_if.h" +#include "dl_lib_matrix.h" +#include "dl_lib_matrixq.h" +#include "dl_lib_matrixq8.h" + +extern const model_coeff_getter_t get_coeff_multinet2_ch; \ No newline at end of file diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/nihaoxiaoxin_wn5X3.h b/tools/sdk/esp32/include/esp-sr/include/esp32/nihaoxiaoxin_wn5X3.h new file mode 100644 index 00000000000..b767bfc435d --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/nihaoxiaoxin_wn5X3.h @@ -0,0 +1,8 @@ +//Generated by mkmodel +#pragma once +#include +#include "dl_lib_coefgetter_if.h" +#include "dl_lib_matrix.h" +#include "dl_lib_matrixq.h" + +extern const model_coeff_getter_t get_coeff_nihaoxiaoxin_wn5X3; diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/nihaoxiaoxin_wn6.h b/tools/sdk/esp32/include/esp-sr/include/esp32/nihaoxiaoxin_wn6.h new file mode 100644 index 00000000000..c365e6d97df --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/nihaoxiaoxin_wn6.h @@ -0,0 +1,8 @@ +//Generated by mkmodel +#pragma once +#include +#include "dl_lib_coefgetter_if.h" +#include "dl_lib_matrix.h" +#include "dl_lib_matrixq.h" + +extern const model_coeff_getter_t get_coeff_nihaoxiaoxin_wn6; diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/nihaoxiaozhi_wn5.h b/tools/sdk/esp32/include/esp-sr/include/esp32/nihaoxiaozhi_wn5.h new file mode 100644 index 00000000000..04fa268d1f9 --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/nihaoxiaozhi_wn5.h @@ -0,0 +1,8 @@ +//Generated by mkmodel +#pragma once +#include +#include "dl_lib_coefgetter_if.h" +#include "dl_lib_matrix.h" +#include "dl_lib_matrixq.h" + +extern const model_coeff_getter_t get_coeff_nihaoxiaozhi_wn5; diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/nihaoxiaozhi_wn5X2.h b/tools/sdk/esp32/include/esp-sr/include/esp32/nihaoxiaozhi_wn5X2.h new file mode 100644 index 00000000000..6c5f2b39e8d --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/nihaoxiaozhi_wn5X2.h @@ -0,0 +1,8 @@ +//Generated by mkmodel +#pragma once +#include +#include "dl_lib_coefgetter_if.h" +#include "dl_lib_matrix.h" +#include "dl_lib_matrixq.h" + +extern const model_coeff_getter_t get_coeff_nihaoxiaozhi_wn5X2; diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/nihaoxiaozhi_wn5X3.h b/tools/sdk/esp32/include/esp-sr/include/esp32/nihaoxiaozhi_wn5X3.h new file mode 100644 index 00000000000..190556e1bab --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/nihaoxiaozhi_wn5X3.h @@ -0,0 +1,8 @@ +//Generated by mkmodel +#pragma once +#include +#include "dl_lib_coefgetter_if.h" +#include "dl_lib_matrix.h" +#include "dl_lib_matrixq.h" + +extern const model_coeff_getter_t get_coeff_nihaoxiaozhi_wn5X3; diff --git a/tools/sdk/esp32/include/esp-sr/include/esp32/sr_flash.h b/tools/sdk/esp32/include/esp-sr/include/esp32/sr_flash.h new file mode 100644 index 00000000000..6c97e51e574 --- /dev/null +++ b/tools/sdk/esp32/include/esp-sr/include/esp32/sr_flash.h @@ -0,0 +1,12 @@ +#pragma once + +#define SR_FLASH_TYPE 32 +#define SR_FLASH_SUBTYPE 32 +#define SR_FLASH_PARTITION_NAME "fr" +#define SR_FLASH_INFO_FLAG 12138 + +int8_t speech_command_flash_init(void); +int8_t enroll_speech_command_to_flash_with_id(char *phrase, int mn_command_id); +int get_use_flag_from_flash(); +int get_enroll_num_from_flash(); +char *read_speech_command_from_flash(int i); \ No newline at end of file diff --git a/tools/sdk/esp32/include/esp32-camera/driver/include/sensor.h b/tools/sdk/esp32/include/esp32-camera/driver/include/sensor.h index 1f99c154185..26afeec3fd5 100755 --- a/tools/sdk/esp32/include/esp32-camera/driver/include/sensor.h +++ b/tools/sdk/esp32/include/esp32-camera/driver/include/sensor.h @@ -26,6 +26,8 @@ typedef enum { GC2145_PID = 0x2145, GC032A_PID = 0x232a, GC0308_PID = 0x9b, + BF3005_PID = 0x30, + BF20A6_PID = 0x20a6, } camera_pid_t; typedef enum { @@ -38,6 +40,8 @@ typedef enum { CAMERA_GC2145, CAMERA_GC032A, CAMERA_GC0308, + CAMERA_BF3005, + CAMERA_BF20A6, CAMERA_MODEL_MAX, CAMERA_NONE, } camera_model_t; @@ -52,6 +56,8 @@ typedef enum { GC2145_SCCB_ADDR = 0x3C,// 0x78 >> 1 GC032A_SCCB_ADDR = 0x21,// 0x42 >> 1 GC0308_SCCB_ADDR = 0x21,// 0x42 >> 1 + BF3005_SCCB_ADDR = 0x6E, + BF20A6_SCCB_ADDR = 0x6E, } camera_sccb_addr_t; typedef enum { diff --git a/tools/sdk/esp32/include/esp_adc_cal/include/esp_adc_cal.h b/tools/sdk/esp32/include/esp_adc_cal/include/esp_adc_cal.h index 171b2ed8501..445b7f65d34 100644 --- a/tools/sdk/esp32/include/esp_adc_cal/include/esp_adc_cal.h +++ b/tools/sdk/esp32/include/esp_adc_cal/include/esp_adc_cal.h @@ -1,16 +1,8 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #ifndef __ESP_ADC_CAL_H__ #define __ESP_ADC_CAL_H__ diff --git a/tools/sdk/esp32/include/esp_common/include/esp_attr.h b/tools/sdk/esp32/include/esp_common/include/esp_attr.h index 7b73af76634..106a686b5e4 100644 --- a/tools/sdk/esp32/include/esp_common/include/esp_attr.h +++ b/tools/sdk/esp32/include/esp_common/include/esp_attr.h @@ -1,17 +1,9 @@ +/* + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. #ifndef __ESP_ATTR_H__ #define __ESP_ATTR_H__ @@ -33,17 +25,24 @@ extern "C" { // Forces data into DRAM instead of flash #define DRAM_ATTR _SECTION_ATTR_IMPL(".dram1", __COUNTER__) -#ifdef CONFIG_ESP32_IRAM_AS_8BIT_ACCESSIBLE_MEMORY +// IRAM can only be accessed as an 8-bit memory on ESP32, when CONFIG_ESP32_IRAM_AS_8BIT_ACCESSIBLE_MEMORY is set +#define IRAM_8BIT_ACCESSIBLE (CONFIG_IDF_TARGET_ESP32 && CONFIG_ESP32_IRAM_AS_8BIT_ACCESSIBLE_MEMORY) + +// Make sure that IRAM is accessible as an 8-bit memory on ESP32. +// If that's not the case, coredump cannot dump data from IRAM. +#if IRAM_8BIT_ACCESSIBLE // Forces data into IRAM instead of DRAM #define IRAM_DATA_ATTR __attribute__((section(".iram.data"))) // Forces data into IRAM instead of DRAM and map it to coredump -#define COREDUMP_IRAM_DATA_ATTR _SECTION_ATTR_IMPL(".iram.data.coredump", __COUNTER__) +#define COREDUMP_IRAM_DATA_ATTR _SECTION_ATTR_IMPL(".iram2.coredump", __COUNTER__) // Forces bss into IRAM instead of DRAM #define IRAM_BSS_ATTR __attribute__((section(".iram.bss"))) #else -#define COREDUMP_IRAM_DATA_ATTR + +// IRAM is not accessible as an 8-bit memory, put IRAM coredump variables in DRAM +#define COREDUMP_IRAM_DATA_ATTR COREDUMP_DRAM_ATTR #define IRAM_DATA_ATTR #define IRAM_BSS_ATTR @@ -103,7 +102,9 @@ extern "C" { #define RTC_NOINIT_ATTR _SECTION_ATTR_IMPL(".rtc_noinit", __COUNTER__) // Forces code into DRAM instead of flash and map it to coredump -#define COREDUMP_DRAM_ATTR _SECTION_ATTR_IMPL(".dram1.coredump", __COUNTER__) +// Use dram2 instead of dram1 to make sure this section will not be included +// by dram1 section in the linker script +#define COREDUMP_DRAM_ATTR _SECTION_ATTR_IMPL(".dram2.coredump", __COUNTER__) // Forces data into RTC memory and map it to coredump #define COREDUMP_RTC_DATA_ATTR _SECTION_ATTR_IMPL(".rtc.coredump", __COUNTER__) diff --git a/tools/sdk/esp32/include/esp_common/include/esp_check.h b/tools/sdk/esp32/include/esp_common/include/esp_check.h index 524cb376a38..d0e09cf28f0 100644 --- a/tools/sdk/esp32/include/esp_common/include/esp_check.h +++ b/tools/sdk/esp32/include/esp_common/include/esp_check.h @@ -25,6 +25,7 @@ extern "C" { */ #if defined(CONFIG_COMPILER_OPTIMIZATION_CHECKS_SILENT) #define ESP_RETURN_ON_ERROR(x, log_tag, format, ...) do { \ + (void)log_tag; \ esp_err_t err_rc_ = (x); \ if (unlikely(err_rc_ != ESP_OK)) { \ return err_rc_; \ @@ -35,6 +36,7 @@ extern "C" { * A version of ESP_RETURN_ON_ERROR() macro that can be called from ISR. */ #define ESP_RETURN_ON_ERROR_ISR(x, log_tag, format, ...) do { \ + (void)log_tag; \ esp_err_t err_rc_ = (x); \ if (unlikely(err_rc_ != ESP_OK)) { \ return err_rc_; \ @@ -46,6 +48,7 @@ extern "C" { * sets the local variable 'ret' to the code, and then exits by jumping to 'goto_tag'. */ #define ESP_GOTO_ON_ERROR(x, goto_tag, log_tag, format, ...) do { \ + (void)log_tag; \ esp_err_t err_rc_ = (x); \ if (unlikely(err_rc_ != ESP_OK)) { \ ret = err_rc_; \ @@ -57,6 +60,7 @@ extern "C" { * A version of ESP_GOTO_ON_ERROR() macro that can be called from ISR. */ #define ESP_GOTO_ON_ERROR_ISR(x, goto_tag, log_tag, format, ...) do { \ + (void)log_tag; \ esp_err_t err_rc_ = (x); \ if (unlikely(err_rc_ != ESP_OK)) { \ ret = err_rc_; \ @@ -69,6 +73,7 @@ extern "C" { * and returns with the supplied 'err_code'. */ #define ESP_RETURN_ON_FALSE(a, err_code, log_tag, format, ...) do { \ + (void)log_tag; \ if (unlikely(!(a))) { \ return err_code; \ } \ @@ -78,6 +83,7 @@ extern "C" { * A version of ESP_RETURN_ON_FALSE() macro that can be called from ISR. */ #define ESP_RETURN_ON_FALSE_ISR(a, err_code, log_tag, format, ...) do { \ + (void)log_tag; \ if (unlikely(!(a))) { \ return err_code; \ } \ @@ -88,6 +94,7 @@ extern "C" { * sets the local variable 'ret' to the supplied 'err_code', and then exits by jumping to 'goto_tag'. */ #define ESP_GOTO_ON_FALSE(a, err_code, goto_tag, log_tag, format, ...) do { \ + (void)log_tag; \ if (unlikely(!(a))) { \ ret = err_code; \ goto goto_tag; \ @@ -98,6 +105,7 @@ extern "C" { * A version of ESP_GOTO_ON_FALSE() macro that can be called from ISR. */ #define ESP_GOTO_ON_FALSE_ISR(a, err_code, goto_tag, log_tag, format, ...) do { \ + (void)log_tag; \ if (unlikely(!(a))) { \ ret = err_code; \ goto goto_tag; \ diff --git a/tools/sdk/esp32/include/esp_common/include/esp_err.h b/tools/sdk/esp32/include/esp_common/include/esp_err.h index d31bb9a0753..f317f8a09f5 100644 --- a/tools/sdk/esp32/include/esp_common/include/esp_err.h +++ b/tools/sdk/esp32/include/esp_common/include/esp_err.h @@ -1,16 +1,9 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + #pragma once #include @@ -46,6 +39,7 @@ typedef int esp_err_t; #define ESP_ERR_MESH_BASE 0x4000 /*!< Starting number of MESH error codes */ #define ESP_ERR_FLASH_BASE 0x6000 /*!< Starting number of flash error codes */ #define ESP_ERR_HW_CRYPTO_BASE 0xc000 /*!< Starting number of HW cryptography module error codes */ +#define ESP_ERR_MEMPROT_BASE 0xd000 /*!< Starting number of Memory Protection API error codes */ /** * @brief Returns string for esp_err_t error codes diff --git a/tools/sdk/esp32/include/esp_common/include/esp_idf_version.h b/tools/sdk/esp32/include/esp_common/include/esp_idf_version.h index 7637b814b65..db04f85f90a 100644 --- a/tools/sdk/esp32/include/esp_common/include/esp_idf_version.h +++ b/tools/sdk/esp32/include/esp_common/include/esp_idf_version.h @@ -23,7 +23,7 @@ extern "C" { /** Minor version number (x.X.x) */ #define ESP_IDF_VERSION_MINOR 4 /** Patch version number (x.x.X) */ -#define ESP_IDF_VERSION_PATCH 0 +#define ESP_IDF_VERSION_PATCH 1 /** * Macro to convert IDF version number into an integer diff --git a/tools/sdk/esp32/include/esp_hw_support/include/esp_chip_info.h b/tools/sdk/esp32/include/esp_hw_support/include/esp_chip_info.h index 69d23c08d36..0b081d37e1b 100644 --- a/tools/sdk/esp32/include/esp_hw_support/include/esp_chip_info.h +++ b/tools/sdk/esp32/include/esp_hw_support/include/esp_chip_info.h @@ -33,6 +33,7 @@ typedef enum { #define CHIP_FEATURE_BLE BIT(4) //!< Chip has Bluetooth LE #define CHIP_FEATURE_BT BIT(5) //!< Chip has Bluetooth Classic #define CHIP_FEATURE_IEEE802154 BIT(6) //!< Chip has IEEE 802.15.4 +#define CHIP_FEATURE_EMB_PSRAM BIT(7) //!< Chip has embedded psram /** * @brief The structure represents information about the chip diff --git a/tools/sdk/esp32/include/esp_hw_support/include/esp_memprot.h b/tools/sdk/esp32/include/esp_hw_support/include/esp_memprot.h new file mode 100644 index 00000000000..c9557eae935 --- /dev/null +++ b/tools/sdk/esp32/include/esp_hw_support/include/esp_memprot.h @@ -0,0 +1,199 @@ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +///////////////////////////////////////////////////////////////////////////////////////// +// ESP Memory Protection API (PMS) +// - allows configuration and violation-interrupt handling of the PMS module operations +// - not intended for public use. + +#pragma once + +#include "sdkconfig.h" +#if CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_MEMPROT_TEST + +#include +#include +#include "esp_err.h" +#include "esp_memprot_err.h" +#include "soc_memprot_types.h" +#include "esp_memprot_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ESP_MEMPROT_ERR_CHECK(retval, fnc) if ((retval=fnc) != ESP_OK) { return retval; } + +/** +* @brief Basic PMS interrupt source info +*/ +typedef struct { + esp_mprot_mem_t mem_type; /*!< Memory type containing the faulting address */ + int core; /*!< CPU/Core ID running the faulting instruction */ +} esp_memp_intr_source_t; + +/** + * @brief Clears current interrupt ON flag for given Memory type and CPU/Core ID + * + * This operation is non-atomic for some chips by PMS module design + * In such a case the interrupt clearing happens in two steps: + * 1. Interrupt CLR flag is set (clears interrupt-ON status and inhibits linked interrupt processing) + * 2. Interrupt CLR flag is reset (resumes the interrupt monitoring) + * + * @param mem_type Memory type (see esp_mprot_mem_t enum) + * @param core Target CPU/Core ID (see *_CPU_NUM defs in soc.h). Can be NULL on 1-CPU systems + * + * @return ESP_OK on success + * ESP_ERR_INVALID_ARG on passing invalid pointer + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + */ +esp_err_t esp_mprot_monitor_clear_intr(const esp_mprot_mem_t mem_type, int const *const core); + +/** + * @brief Checks whether any of the PMS settings is locked + * + * @param[out] locked Any lock on? (true/false) + * + * @return ESP_OK on success + * ESP_ERR_INVALID_ARG on invalid locked ptr + * Other failures: error code of any failing esp_mprot_get_*_lock() routine (called internally) + */ +esp_err_t esp_mprot_is_conf_locked_any(bool *locked); + +/** + * @brief Checks whether any PMS violation-interrupt monitoring is enabled + * + * @param[out] locked Any PMS violation interrupt monitor is enabled (true/false) + * + * @return ESP_OK on success + * ESP_ERR_INVALID_ARG on invalid enabled ptr + * Other failures: error code of esp_mprot_get_monitor_en() routine (called internally for all Memory types) + */ +esp_err_t esp_mprot_is_intr_ena_any(bool *enabled); + +/** + * @brief Returns active PMS violation-interrupt Memory type if any (MEMPROT_TYPE_NONE when none detected) + * and the CPU/CoreID which was running the faulty code (-1 when no interrupt available) + * + * If there are more interrupts indicated on (shouldn't happen), the order of precedence is given by 'esp_mprot_mem_t' enum definition (low->high) + * + * @param[out] mem_type Out-pointer for Memory type given by the faulting address (see esp_mprot_mem_t enum) + * @param[out] core Out-pointer for CPU/Core ID (see *_CPU_NUM defs in soc.h) + * + * @return ESP_OK on success + * ESP_ERR_INVALID_ARG on passing invalid pointer(s) + */ +esp_err_t esp_mprot_get_active_intr(esp_memp_intr_source_t *active_memp_intr); + +/** + * @brief Returns the address which caused the violation interrupt for given Memory type and CPU/Core ID. + * This function is to be called after a basic resolving of (current) interrupt's parameters (ie corresponding + * Memory type and CPU ID see esp_mprot_get_active_intr()). This is to minimize processing time of actual exception + * as this API is typicaly used in a panic-handling code. + * If there is no active interrupt available for the Memory type/CPU ID required, fault_addr is set to NULL. + * + * @param mem_type memory type + * @param[out] fault_addr Address of the operation which caused the PMS violation interrupt + * @param core Faulting instruction CPU/Core ID (see *_CPU_NUM defs in soc.h). Can be NULL on 1-CPU systems + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + * ESP_ERR_INVALID_ARG on invalid fault_addr pointer + */ +esp_err_t esp_mprot_get_violate_addr(const esp_mprot_mem_t mem_type, void **fault_addr, int const *const core); + +/** + * @brief Returns PMS World identifier of the code causing the violation interrupt + * + * The value is read from appropriate PMS violation status register and thus might be 0 if the interrupt is not currently active. + * + * @param mem_type Memory type + * @param[out] world PMS World type (see esp_mprot_pms_world_t) + * @param core Faulting instruction CPU/Core ID (see *_CPU_NUM defs in soc.h). Can be NULL on 1-CPU systems + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + * ESP_ERR_INVALID_ARG on passing invalid pointer(s) + * ESP_ERR_MEMPROT_WORLD_INVALID on invalid World identifier fetched from the register + */ +esp_err_t esp_mprot_get_violate_world(const esp_mprot_mem_t mem_type, esp_mprot_pms_world_t *world, int const *const core); + +/** + * @brief Returns an operation type which caused the violation interrupt + * + * The operation resolving is processed over various PMS status register flags, according to given Memory type argument. + * If the interrupt is not active the result returned is irrelevant (likely evaluated to MEMPROT_OP_READ). + * + * @param mem_type Memory type + * @param[out] oper Operation type (see MEMPROT_OP_* defines) + * @param core Faulting instruction CPU/Core ID (see *_CPU_NUM defs in soc.h). Can be NULL on 1-CPU systems + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + * ESP_ERR_INVALID_ARG on invalid oper pointer + */ +esp_err_t esp_mprot_get_violate_operation(const esp_mprot_mem_t mem_type, uint32_t *oper, int const *const core); + +/** + * @brief Checks whether given memory type supports byte-enables info + * + * Byte-enables status is available only for DMA/DRAM operations + * + * @param mem_type memory type + * + * @return byte-enables info available true/false + */ +bool esp_mprot_has_byte_enables(const esp_mprot_mem_t mem_type); + +/** + * @brief Returns byte-enables for the address which caused the violation interrupt + * + * The value is taken from appropriate PMS violation status register, based on given Memory type + * + * @param mem_type Memory type (MEMPROT_TYPE_DRAM0_SRAM) + * @param[out] byte_en Byte-enables bits + * @param core Faulting instruction CPU/Core ID (see *_CPU_NUM defs in soc.h). Can be NULL on 1-CPU systems + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + * ESP_ERR_INVALID_ARGUMENT on invalid byte_en pointer + */ +esp_err_t esp_mprot_get_violate_byte_enables(const esp_mprot_mem_t mem_type, uint32_t *byte_en, int const *const core); + +/** + * @brief Convenient routine for setting the PMS defaults + * + * Called on system startup, depending on ESP_SYSTEM_MEMPROT_FEATURE Kconfig value + * + * @param memp_config pointer to Memprot configuration structure (esp_memp_config_t). The structure si chip-specific, + * for details and defaults see appropriate [target-chip]/soc_memprot_types.h + * + * @return ESP_OK on success + * Other failures: error code of the failing routine called internally. No specific error processing provided in such a case + * due to large number of embedded calls (ie no global unique error table is provided and thus one error code can have different meanings, + * depending on the routine issuing the error) + */ +esp_err_t esp_mprot_set_prot(const esp_memp_config_t *memp_config); + +/** + * @brief Generates PMS configuration string of actual device (diagnostics) + * + * The functions generates a string from current configuration, control and status registers of the PMS (or similar) module of actual device. + * The values are fetched using HAL LL calls to help finding possible errors in the Memprot API implementation + * + * @param[out] dump_info_string configuration string buffer pointer. The string is allocated by the callee and must be freed by the caller. + * + * @return ESP_OK on success + * ESP_ERR_NO_MEM on buffer allocation failure + * ESP_ERR_INVALID_ARGUMENT on invalid dump_info_string pointer + */ +esp_err_t esp_mprot_dump_configuration(char **dump_info_string); + +#ifdef __cplusplus +} +#endif + +#endif //CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_MEMPROT_TEST diff --git a/tools/sdk/esp32/include/esp_hw_support/include/esp_memprot_err.h b/tools/sdk/esp32/include/esp_hw_support/include/esp_memprot_err.h new file mode 100644 index 00000000000..5556d2c8894 --- /dev/null +++ b/tools/sdk/esp32/include/esp_hw_support/include/esp_memprot_err.h @@ -0,0 +1,28 @@ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD +* +* SPDX-License-Identifier: Apache-2.0 +*/ + +#pragma once + +#include "esp_err.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** +* @brief ESP Memprot API error code definition +*/ +#define ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID (ESP_ERR_MEMPROT_BASE + 1) /**< Memory type invalid in given context */ +#define ESP_ERR_MEMPROT_SPLIT_ADDR_INVALID (ESP_ERR_MEMPROT_BASE + 2) /**< Splitting address invalid in given context */ +#define ESP_ERR_MEMPROT_SPLIT_ADDR_OUT_OF_RANGE (ESP_ERR_MEMPROT_BASE + 3) /**< Splitting address out of range */ +#define ESP_ERR_MEMPROT_SPLIT_ADDR_UNALIGNED (ESP_ERR_MEMPROT_BASE + 4) /**< Splitting address not aligned to required boundaries */ +#define ESP_ERR_MEMPROT_UNIMGMT_BLOCK_INVALID (ESP_ERR_MEMPROT_BASE + 5) /**< Required unified-management block is not valid */ +#define ESP_ERR_MEMPROT_WORLD_INVALID (ESP_ERR_MEMPROT_BASE + 6) /**< Required World identifier is not valid */ +#define ESP_ERR_MEMPROT_AREA_INVALID (ESP_ERR_MEMPROT_BASE + 7) /**< Required Area identifier is not valid */ + +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/esp32/include/esp_hw_support/include/esp_memprot_types.h b/tools/sdk/esp32/include/esp_hw_support/include/esp_memprot_types.h new file mode 100644 index 00000000000..e37fee54578 --- /dev/null +++ b/tools/sdk/esp32/include/esp_hw_support/include/esp_memprot_types.h @@ -0,0 +1,36 @@ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief PMS World type (attribute per PMS area, similar to x86 Ring scheme) + */ +typedef enum { + MEMPROT_PMS_WORLD_NONE = 0x00000000, + MEMPROT_PMS_WORLD_0 = 0x00000001, + MEMPROT_PMS_WORLD_1 = 0x00000002, + MEMPROT_PMS_WORLD_2 = 0x00000004, + MEMPROT_PMS_WORLD_ALL = 0x7FFFFFFF, + MEMPROT_PMS_WORLD_INVALID = 0x80000000 +} esp_mprot_pms_world_t; + +/** + * @brief Memory operation/permission type recognized by PMS + */ +#define MEMPROT_OP_NONE 0x00000000 +#define MEMPROT_OP_READ 0x00000001 +#define MEMPROT_OP_WRITE 0x00000002 +#define MEMPROT_OP_EXEC 0x00000004 +#define MEMPROT_OP_INVALID 0x80000000 + +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/esp32/include/esp_hw_support/include/esp_private/esp_memprot_internal.h b/tools/sdk/esp32/include/esp_hw_support/include/esp_private/esp_memprot_internal.h new file mode 100644 index 00000000000..caeb7584862 --- /dev/null +++ b/tools/sdk/esp32/include/esp_hw_support/include/esp_private/esp_memprot_internal.h @@ -0,0 +1,199 @@ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include "sdkconfig.h" +#if CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_MEMPROT_TEST + +#include +#include +#include "esp_err.h" +#include "esp_memprot_err.h" +#include "hal/memprot_types.h" +#include "soc_memprot_types.h" +#include "esp_memprot_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** +* @brief Convert Memprot low level errors to esp_err_t +*/ +esp_err_t esp_mprot_ll_err_to_esp_err(const memprot_ll_err_t err); + +/** + * @brief Convert Memprot low level PMS World IDs to esp_mprot_pms_world_t + */ +esp_mprot_pms_world_t esp_mprot_ll_world_to_hl_world(const memprot_ll_world_t world); + +/** + * @brief Converts operation type to string, no combination of operations allowed + * + * @param oper_type PMS operation type + */ +const char *esp_mprot_oper_type_to_str(const uint32_t oper_type); + +/** + * @brief Converts PMS World type to string + * + * @param area_type PMS World type + */ +const char *esp_mprot_pms_world_to_str(const esp_mprot_pms_world_t world_type); + +/** + * @brief Sets splitting address for given line type in the target Memory type + * + * @param mem_type memory type + * @param line_type split address type + * @param line_addr target address from a memory range relevant to given line_addr + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + * ESP_ERR_MEMPROT_SPLIT_ADDR_INVALID on invalid line_type + * ESP_ERR_MEMPROT_SPLIT_ADDR_OUT_OF_RANGE on splitting line out of given memory-type range + * ESP_ERR_MEMPROT_SPLIT_ADDR_UNALIGNED on splitting line not aligned to PMS-required boundaries + */ +esp_err_t esp_mprot_set_split_addr(const esp_mprot_mem_t mem_type, const esp_mprot_split_addr_t line_type, const void *line_addr); + +/** + * @brief Gets PMS splitting address for given split_addr type + * + * The value is read from the PMS configuration registers + * + * @param mem_type memory type + * @param line_type Split line type (see esp_mprot_split_addr_t enum) + * @param[out] line_addr Split line address from the configuration register + * + * @return ESP_OK on success + * ESP_ERR_INVALID_ARG on line_addr is pointer + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + * ESP_ERR_MEMPROT_SPLIT_ADDR_INVALID on invalid line_type + */ +esp_err_t esp_mprot_get_split_addr(const esp_mprot_mem_t mem_type, const esp_mprot_split_addr_t line_type, void **line_addr); + +/** + * @brief Returns default main I/D splitting address for given Memory type + * + * @param mem_type memory type + * @param[out] def_split_addr Main I/D splitting address of required mem_type + * + * @return ESP_OK on success + * ESP_ERR_INVALID_ARG on invalid def_split_addr pointer + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + */ +esp_err_t esp_mprot_get_default_main_split_addr(const esp_mprot_mem_t mem_type, void **def_split_addr); + +/** + * @brief Sets a lock for the main IRAM/DRAM splitting addresses + * Locks can be unlocked only by digital system reset + * + * @param mem_type memory type + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + */ +esp_err_t esp_mprot_set_split_addr_lock(const esp_mprot_mem_t mem_type); + +/** + * @brief Gets a lock status for the splitting address configuration of given Memory type + * + * @param mem_type memory type + * @param[out] locked mem_type related lock status + * + * @return ESP_OK on success + * ESP_ERR_INVALID_ARGUMENT on invalid locked pointer + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + */ +esp_err_t esp_mprot_get_split_addr_lock(const esp_mprot_mem_t mem_type, bool *locked); + +/** + * @brief Sets a lock for PMS Area settings of required Memory type + * Locks can be unlocked only by digital system reset + * + * @param mem_type memory type + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + */ +esp_err_t esp_mprot_set_pms_lock(const esp_mprot_mem_t mem_type); + +/** + * @brief Gets a lock status for PMS Area settings of required Memory type + * + * @param mem_type memory type + * @param[out] locked mem_type related lock status + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + * ESP_ERR_INVALID_ARGUMENT on invalid locked pointer + */ +esp_err_t esp_mprot_get_pms_lock(const esp_mprot_mem_t mem_type, bool *locked); + +/** + * @brief Sets permissions for given PMS Area + * + * @param area_type PMS area type + * @param flags combination of MEMPROT_OP_* defines + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + */ +esp_err_t esp_mprot_set_pms_area(const esp_mprot_pms_area_t area_type, const uint32_t flags); + +/** + * @brief Gets current permissions for given PMS Area + * + * @param area_type PMS area type + * @param[out] flags combination of MEMPROT_OP_* defines + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + * ESP_ERR_INVALID_ARG on invalid flags pointer + */ +esp_err_t esp_mprot_get_pms_area(const esp_mprot_pms_area_t area_type, uint32_t *flags); + +/** + * @brief Sets a lock for PMS interrupt monitor settings of required Memory type + * + * Locks can be unlocked only by digital system reset + * + * @param mem_type memory type (see esp_mprot_mem_t enum) + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + */ +esp_err_t esp_mprot_set_monitor_lock(const esp_mprot_mem_t mem_type); + +/** + * @brief Gets a lock status for PMS interrupt monitor settings of required Memory type + * + * @param mem_type memory type + * @param[out] locked mem_type related lock status + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + * ESP_ERR_INVALID_ARG on invalid locked pointer + */ +esp_err_t esp_mprot_get_monitor_lock(const esp_mprot_mem_t mem_type, bool *locked); + +/** + * @brief Enable PMS violation interrupt monitoring of required Memory type + * + * @param mem_type memory type + * @param enable enable/disable violation interrupt monitoring + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + */ +esp_err_t esp_mprot_set_monitor_en(const esp_mprot_mem_t mem_type, const bool enable); + +#ifdef __cplusplus +} +#endif + +#endif //CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_MEMPROT_TEST diff --git a/tools/sdk/esp32/include/esp_hw_support/include/soc/esp32c3/memprot.h b/tools/sdk/esp32/include/esp_hw_support/include/soc/esp32c3/memprot.h deleted file mode 100644 index 818cd677dc8..00000000000 --- a/tools/sdk/esp32/include/esp_hw_support/include/soc/esp32c3/memprot.h +++ /dev/null @@ -1,449 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - - -/* INTERNAL API - * generic interface to PMS memory protection features - */ - -#pragma once - -#include -#include - -#include "esp_attr.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef IRAM_SRAM_START -#define IRAM_SRAM_START 0x4037C000 -#endif - -#ifndef DRAM_SRAM_START -#define DRAM_SRAM_START 0x3FC7C000 -#endif - -#ifndef MAP_DRAM_TO_IRAM -#define MAP_DRAM_TO_IRAM(addr) (addr - DRAM_SRAM_START + IRAM_SRAM_START) -#endif - -#ifndef MAP_IRAM_TO_DRAM -#define MAP_IRAM_TO_DRAM(addr) (addr - IRAM_SRAM_START + DRAM_SRAM_START) -#endif - -typedef enum { - MEMPROT_NONE = 0x00000000, - MEMPROT_IRAM0_SRAM = 0x00000001, - MEMPROT_DRAM0_SRAM = 0x00000002, - MEMPROT_ALL = 0xFFFFFFFF -} mem_type_prot_t; - -typedef enum { - MEMPROT_SPLITLINE_NONE = 0, - MEMPROT_IRAM0_DRAM0_SPLITLINE, - MEMPROT_IRAM0_LINE_0_SPLITLINE, - MEMPROT_IRAM0_LINE_1_SPLITLINE, - MEMPROT_DRAM0_DMA_LINE_0_SPLITLINE, - MEMPROT_DRAM0_DMA_LINE_1_SPLITLINE -} split_line_t; - -typedef enum { - MEMPROT_PMS_AREA_NONE = 0, - MEMPROT_IRAM0_PMS_AREA_0, - MEMPROT_IRAM0_PMS_AREA_1, - MEMPROT_IRAM0_PMS_AREA_2, - MEMPROT_IRAM0_PMS_AREA_3, - MEMPROT_DRAM0_PMS_AREA_0, - MEMPROT_DRAM0_PMS_AREA_1, - MEMPROT_DRAM0_PMS_AREA_2, - MEMPROT_DRAM0_PMS_AREA_3 -} pms_area_t; - -typedef enum -{ - MEMPROT_PMS_WORLD_0 = 0, - MEMPROT_PMS_WORLD_1, - MEMPROT_PMS_WORLD_2, - MEMPROT_PMS_WORLD_INVALID = 0xFFFFFFFF -} pms_world_t; - -typedef enum -{ - MEMPROT_PMS_OP_READ = 0, - MEMPROT_PMS_OP_WRITE, - MEMPROT_PMS_OP_FETCH, - MEMPROT_PMS_OP_INVALID = 0xFFFFFFFF -} pms_operation_type_t; - -/** - * @brief Converts Memory protection type to string - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - */ -const char *esp_memprot_mem_type_to_str(mem_type_prot_t mem_type); - -/** - * @brief Converts Split line type to string - * - * @param line_type Split line type (see split_line_t enum) - */ -const char *esp_memprot_split_line_to_str(split_line_t line_type); - -/** - * @brief Converts PMS Area type to string - * - * @param area_type PMS Area type (see pms_area_t enum) - */ -const char *esp_memprot_pms_to_str(pms_area_t area_type); - -/** - * @brief Returns PMS splitting address for given Split line type - * - * The value is taken from PMS configuration registers (IRam0 range) - * For details on split lines see 'esp_memprot_set_prot_int' function description - * - * @param line_type Split line type (see split_line_t enum) - * - * @return appropriate split line address - */ -uint32_t *esp_memprot_get_split_addr(split_line_t line_type); - -/** - * @brief Returns default main IRAM/DRAM splitting address - * - * The address value is given by _iram_text_end global (IRam0 range) - - * @return Main I/D split line (IRam0_DRam0_Split_Addr) - */ -void *esp_memprot_get_default_main_split_addr(void); - -/** - * @brief Sets a lock for the main IRAM/DRAM splitting address - * - * Locks can be unlocked only by digital system reset - */ -void esp_memprot_set_split_line_lock(void); - -/** - * @brief Gets a lock status for the main IRAM/DRAM splitting address - * - * @return true/false (locked/unlocked) - */ -bool esp_memprot_get_split_line_lock(void); - -/** - * @brief Sets required split line address - * - * @param line_type Split line type (see split_line_t enum) - * @param line_addr target address from a memory range relevant to given line_type (IRAM/DRAM) - */ -void esp_memprot_set_split_line(split_line_t line_type, const void *line_addr); - -/** - * @brief Sets a lock for PMS Area settings of required Memory type - * - * Locks can be unlocked only by digital system reset - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - */ -void esp_memprot_set_pms_lock(mem_type_prot_t mem_type); - -/** - * @brief Gets a lock status for PMS Area settings of required Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return true/false (locked/unlocked) - */ -bool esp_memprot_get_pms_lock(mem_type_prot_t mem_type); - -/** - * @brief Sets permissions for given PMS Area in IRam0 memory range (MEMPROT_IRAM0_SRAM) - * - * @param area_type IRam0 PMS Area type (see pms_area_t enum) - * @param r Read permission flag - * @param w Write permission flag - * @param x Execute permission flag - */ -void esp_memprot_iram_set_pms_area(pms_area_t area_type, bool r, bool w, bool x); - -/** - * @brief Gets current permissions for given PMS Area in IRam0 memory range (MEMPROT_IRAM0_SRAM) - * - * @param area_type IRam0 PMS Area type (see pms_area_t enum) - * @param r Read permission flag holder - * @param w Write permission flag holder - * @param x Execute permission flag holder - */ -void esp_memprot_iram_get_pms_area(pms_area_t area_type, bool *r, bool *w, bool *x); - -/** - * @brief Sets permissions for given PMS Area in DRam0 memory range (MEMPROT_DRAM0_SRAM) - * - * @param area_type DRam0 PMS Area type (see pms_area_t enum) - * @param r Read permission flag - * @param w Write permission flag - */ -void esp_memprot_dram_set_pms_area(pms_area_t area_type, bool r, bool w); - -/** - * @brief Gets current permissions for given PMS Area in DRam0 memory range (MEMPROT_DRAM0_SRAM) - * - * @param area_type DRam0 PMS Area type (see pms_area_t enum) - * @param r Read permission flag holder - * @param w Write permission flag holder - */ -void esp_memprot_dram_get_pms_area(pms_area_t area_type, bool *r, bool *w); - -/** - * @brief Sets a lock for PMS interrupt monitor settings of required Memory type - * - * Locks can be unlocked only by digital system reset - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - */ -void esp_memprot_set_monitor_lock(mem_type_prot_t mem_type); - -/** - * @brief Gets a lock status for PMS interrupt monitor settings of required Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return true/false (locked/unlocked) - */ -bool esp_memprot_get_monitor_lock(mem_type_prot_t mem_type); - -/** - * @brief Enable PMS violation interrupt monitoring of required Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * @param enable/disable - */ -void esp_memprot_set_monitor_en(mem_type_prot_t mem_type, bool enable); - -/** - * @brief Gets enable/disable status for PMS interrupt monitor settings of required Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return true/false (enabled/disabled) - */ -bool esp_memprot_get_monitor_en(mem_type_prot_t mem_type); - -/** - * @brief Gets CPU ID for currently active PMS violation interrupt - * - * @return CPU ID (CPU_PRO for ESP32C3) - */ -int IRAM_ATTR esp_memprot_intr_get_cpuid(void); - -/** - * @brief Clears current interrupt ON flag for given Memory type - * - * Interrupt clearing happens in two steps: - * 1. Interrupt CLR flag is set (to clear the interrupt ON status) - * 2. Interrupt CLR flag is reset (to allow further monitoring) - * This operation is non-atomic by PMS module design - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - */ -void IRAM_ATTR esp_memprot_monitor_clear_intr(mem_type_prot_t mem_type); - -/** - * @brief Returns active PMS violation interrupt (if any) - * - * This function iterates through supported Memory type status registers - * and returns the first interrupt-on flag. If none is found active, - * MEMPROT_NONE is returned. - * Order of checking (in current version): - * 1. MEMPROT_IRAM0_SRAM - * 2. MEMPROT_DRAM0_SRAM - * - * @return mem_type Memory protection type related to active interrupt found (see mem_type_prot_t enum) - */ -mem_type_prot_t IRAM_ATTR esp_memprot_get_active_intr_memtype(void); - -/** - * @brief Checks whether any violation interrupt is active - * - * @return true/false (yes/no) - */ -bool IRAM_ATTR esp_memprot_is_locked_any(void); - -/** - * @brief Checks whether any violation interrupt is enabled - * - * @return true/false (yes/no) - */ -bool IRAM_ATTR esp_memprot_is_intr_ena_any(void); - -/** - * @brief Checks whether any violation interrupt is enabled - * - * @return true/false (yes/no) - */ -bool IRAM_ATTR esp_memprot_get_violate_intr_on(mem_type_prot_t mem_type); - -/** - * @brief Returns the address which caused the violation interrupt (if any) - * - * The address is taken from appropriate PMS violation status register, based given Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return faulting address - */ -uint32_t IRAM_ATTR esp_memprot_get_violate_addr(mem_type_prot_t mem_type); - -/** - * @brief Returns the World identifier of the code causing the violation interrupt (if any) - * - * The value is taken from appropriate PMS violation status register, based given Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return World identifier (see pms_world_t enum) - */ -pms_world_t IRAM_ATTR esp_memprot_get_violate_world(mem_type_prot_t mem_type); - -/** - * @brief Returns Read or Write operation type which caused the violation interrupt (if any) - * - * The value (bit) is taken from appropriate PMS violation status register, based given Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return PMS operation type relevant to mem_type parameter (se pms_operation_type_t) - */ -pms_operation_type_t IRAM_ATTR esp_memprot_get_violate_wr(mem_type_prot_t mem_type); - -/** - * @brief Returns LoadStore flag of the operation type which caused the violation interrupt (if any) - * - * The value (bit) is taken from appropriate PMS violation status register, based given Memory type - * Effective only on IRam0 access - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return true/false (LoadStore bit on/off) - */ -bool IRAM_ATTR esp_memprot_get_violate_loadstore(mem_type_prot_t mem_type); - -/** - * @brief Returns byte-enables for the address which caused the violation interrupt (if any) - * - * The value is taken from appropriate PMS violation status register, based given Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return byte-enables - */ -uint32_t IRAM_ATTR esp_memprot_get_violate_byte_en(mem_type_prot_t mem_type); - -/** - * @brief Returns raw contents of DRam0 status register 1 - * - * @return 32-bit register value - */ -uint32_t IRAM_ATTR esp_memprot_get_dram_status_reg_1(void); - -/** - * @brief Returns raw contents of DRam0 status register 2 - * - * @return 32-bit register value - */ -uint32_t IRAM_ATTR esp_memprot_get_dram_status_reg_2(void); - -/** - * @brief Returns raw contents of IRam0 status register - * - * @return 32-bit register value - */ -uint32_t IRAM_ATTR esp_memprot_get_iram_status_reg(void); - -/** - * @brief Register PMS violation interrupt in global interrupt matrix for given Memory type - * - * Memory protection components uses specific interrupt number, see ETS_MEMPROT_ERR_INUM - * The registration makes the panic-handler routine being called when the interrupt appears - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - */ -void esp_memprot_set_intr_matrix(mem_type_prot_t mem_type); - -/** - * @brief Convenient routine for setting the PMS defaults - * - * Called on application startup, depending on CONFIG_ESP_SYSTEM_MEMPROT_FEATURE Kconfig settings - * For implementation details see 'esp_memprot_set_prot_int' description - * - * @param invoke_panic_handler register all interrupts for panic handling (true/false) - * @param lock_feature lock the defaults to prevent further PMS settings changes (true/false) - * @param mem_type_mask 32-bit field of specific PMS parts to configure (see 'esp_memprot_set_prot_int') - */ -void esp_memprot_set_prot(bool invoke_panic_handler, bool lock_feature, uint32_t *mem_type_mask); - -/** - * @brief Internal routine for setting the PMS defaults - * - * Called on application startup from within 'esp_memprot_set_prot'. Allows setting a specific splitting address - * (main I/D split line) - see the parameter 'split_addr'. If the 'split_addr' equals to NULL, default I/D split line - * is used (&_iram_text_end) and all the remaining lines share the same address. - * The function sets all the split lines and PMS areas to the same space, - * ie there is a single instruction space and single data space at the end. - * The PMS split lines and permission areas scheme described below: - * - * DRam0/DMA IRam0 - * ----------------------------------------------- - * ... | IRam0_PMS_0 | - * DRam0_PMS_0 ----------------------------------------------- IRam0_line1_Split_addr - * ... | IRam0_PMS_1 | - * ... ----------------------------------------------- IRam0_line0_Split_addr - * | IRam0_PMS_2 | - * =============================================== IRam0_DRam0_Split_addr (main I/D) - * | DRam0_PMS_1 | - * DRam0_DMA_line0_Split_addr ----------------------------------------------- ... - * | DRam0_PMS_2 | ... - * DRam0_DMA_line1_Split_addr ----------------------------------------------- IRam0_PMS_3 - * | DRam0_PMS_3 | ... - * ----------------------------------------------- - * - * Default settings provided by 'esp_memprot_set_prot_int' are as follows: - * - * DRam0/DMA IRam0 - * ----------------------------------------------- - * | IRam0_PMS_0 = IRam0_PMS_1 = IRam0_PMS_2 | - * | DRam0_PMS_0 | IRam0_line1_Split_addr - * DRam0_DMA_line0_Split_addr | | = - * = =============================================== IRam0_line0_Split_addr - * DRam0_DMA_line1_Split_addr | | = - * | DRam0_PMS_1 = DRam0_PMS_2 = DRam0_PMS_3 | IRam0_DRam0_Split_addr (main I/D) - * | IRam0_PMS_3 | - * ----------------------------------------------- - * - * Once the memprot feature is locked, it can be unlocked only by digital system reset - * - * @param invoke_panic_handler register all the violation interrupts for panic handling (true/false) - * @param lock_feature lock the defaults to prevent further PMS settings changes (true/false) - * @param split_addr specific main I/D adrees or NULL to use default ($_iram_text_end) - * @param mem_type_mask 32-bit field of specific PMS parts to configure (members of mem_type_prot_t) - */ -void esp_memprot_set_prot_int(bool invoke_panic_handler, bool lock_feature, void *split_addr, uint32_t *mem_type_mask); - -/** - * @brief Returns raw contents of PMS interrupt monitor register for given Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return 32-bit register value - */ -uint32_t esp_memprot_get_monitor_enable_reg(mem_type_prot_t mem_type); - -#ifdef __cplusplus -} -#endif diff --git a/tools/sdk/esp32/include/esp_hw_support/include/soc/esp32c3/soc_memprot_types.h b/tools/sdk/esp32/include/esp_hw_support/include/soc/esp32c3/soc_memprot_types.h new file mode 100644 index 00000000000..318c6109617 --- /dev/null +++ b/tools/sdk/esp32/include/esp_hw_support/include/soc/esp32c3/soc_memprot_types.h @@ -0,0 +1,175 @@ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +////////////////////////////////////////////////////////// +// ESP32-C3 PMS memory protection types +// + +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Memory types recognized by PMS + */ +typedef enum { + MEMPROT_TYPE_NONE = 0x00000000, + MEMPROT_TYPE_IRAM0_SRAM = 0x00000001, + MEMPROT_TYPE_DRAM0_SRAM = 0x00000002, + MEMPROT_TYPE_IRAM0_RTCFAST = 0x00000004, + MEMPROT_TYPE_ALL = 0x7FFFFFFF, + MEMPROT_TYPE_INVALID = 0x80000000, + MEMPROT_TYPE_IRAM0_ANY = MEMPROT_TYPE_IRAM0_SRAM | MEMPROT_TYPE_IRAM0_RTCFAST +} esp_mprot_mem_t; + +/** + * @brief Splitting address (line) type + */ +typedef enum { + MEMPROT_SPLIT_ADDR_NONE = 0x00000000, + MEMPROT_SPLIT_ADDR_IRAM0_DRAM0 = 0x00000001, + MEMPROT_SPLIT_ADDR_IRAM0_LINE_0 = 0x00000002, + MEMPROT_SPLIT_ADDR_IRAM0_LINE_1 = 0x00000004, + MEMPROT_SPLIT_ADDR_DRAM0_DMA_LINE_0 = 0x00000008, + MEMPROT_SPLIT_ADDR_DRAM0_DMA_LINE_1 = 0x00000010, + MEMPROT_SPLIT_ADDR_ALL = 0x7FFFFFFF, + MEMPROT_SPLIT_ADDR_INVALID = 0x80000000, + MEMPROT_SPLIT_ADDR_MAIN = MEMPROT_SPLIT_ADDR_IRAM0_DRAM0 +} esp_mprot_split_addr_t; + +/** + * @brief PMS area type (memory space between adjacent splitting addresses or above/below the main splt.address) + */ +typedef enum { + MEMPROT_PMS_AREA_NONE = 0x00000000, + MEMPROT_PMS_AREA_IRAM0_0 = 0x00000001, + MEMPROT_PMS_AREA_IRAM0_1 = 0x00000002, + MEMPROT_PMS_AREA_IRAM0_2 = 0x00000004, + MEMPROT_PMS_AREA_IRAM0_3 = 0x00000008, + MEMPROT_PMS_AREA_DRAM0_0 = 0x00000010, + MEMPROT_PMS_AREA_DRAM0_1 = 0x00000020, + MEMPROT_PMS_AREA_DRAM0_2 = 0x00000040, + MEMPROT_PMS_AREA_DRAM0_3 = 0x00000080, + MEMPROT_PMS_AREA_IRAM0_RTCFAST_LO = 0x00000100, + MEMPROT_PMS_AREA_IRAM0_RTCFAST_HI = 0x00000200, + MEMPROT_PMS_AREA_ALL = 0x7FFFFFFF, + MEMPROT_PMS_AREA_INVALID = 0x80000000 +} esp_mprot_pms_area_t; + +/** +* @brief Memory protection configuration +*/ +typedef struct { + bool invoke_panic_handler; /*!< Register PMS violation interrupt for panic-handling */ + bool lock_feature; /*!< Lock all PMS settings */ + void *split_addr; /*!< Main I/D splitting address */ + uint32_t mem_type_mask; /*!< Memory types required to protect. See esp_mprot_mem_t enum */ +} esp_memp_config_t; + +#define ESP_MEMPROT_DEFAULT_CONFIG() { \ + .invoke_panic_handler = true, \ + .lock_feature = true, \ + .split_addr = NULL, \ + .mem_type_mask = MEMPROT_TYPE_ALL \ +} + +/** + * @brief Converts Memory protection type to string + * + * @param mem_type Memory protection type + */ +static inline const char *esp_mprot_mem_type_to_str(const esp_mprot_mem_t mem_type) +{ + switch (mem_type) { + case MEMPROT_TYPE_NONE: + return "NONE"; + case MEMPROT_TYPE_IRAM0_SRAM: + return "IRAM0_SRAM"; + case MEMPROT_TYPE_DRAM0_SRAM: + return "DRAM0_SRAM"; + case MEMPROT_TYPE_IRAM0_RTCFAST: + return "IRAM0_RTCFAST"; + case MEMPROT_TYPE_IRAM0_ANY: + return "IRAM0_ANY"; + case MEMPROT_TYPE_ALL: + return "ALL"; + default: + return "INVALID"; + } +} + +/** + * @brief Converts Splitting address type to string + * + * @param line_type Split line type + */ +static inline const char *esp_mprot_split_addr_to_str(const esp_mprot_split_addr_t line_type) +{ + switch (line_type) { + case MEMPROT_SPLIT_ADDR_NONE: + return "SPLIT_ADDR_NONE"; + case MEMPROT_SPLIT_ADDR_IRAM0_DRAM0: + return "SPLIT_ADDR_IRAM0_DRAM0"; + case MEMPROT_SPLIT_ADDR_IRAM0_LINE_0: + return "SPLIT_ADDR_IRAM0_LINE_0"; + case MEMPROT_SPLIT_ADDR_IRAM0_LINE_1: + return "SPLIT_ADDR_IRAM0_LINE_1"; + case MEMPROT_SPLIT_ADDR_DRAM0_DMA_LINE_0: + return "SPLIT_ADDR_DRAM0_DMA_LINE_0"; + case MEMPROT_SPLIT_ADDR_DRAM0_DMA_LINE_1: + return "SPLIT_ADDR_DRAM0_DMA_LINE_1"; + case MEMPROT_SPLIT_ADDR_ALL: + return "SPLIT_ADDR_ALL"; + default: + return "SPLIT_ADDR_INVALID"; + } +} + +/** + * @brief Converts PMS Area type to string + * + * @param area_type PMS Area type + */ +static inline const char *esp_mprot_pms_area_to_str(const esp_mprot_pms_area_t area_type) +{ + switch (area_type) { + case MEMPROT_PMS_AREA_NONE: + return "PMS_AREA_NONE"; + case MEMPROT_PMS_AREA_IRAM0_0: + return "PMS_AREA_IRAM0_0"; + case MEMPROT_PMS_AREA_IRAM0_1: + return "PMS_AREA_IRAM0_1"; + case MEMPROT_PMS_AREA_IRAM0_2: + return "PMS_AREA_IRAM0_2"; + case MEMPROT_PMS_AREA_IRAM0_3: + return "PMS_AREA_IRAM0_3"; + case MEMPROT_PMS_AREA_DRAM0_0: + return "PMS_AREA_DRAM0_0"; + case MEMPROT_PMS_AREA_DRAM0_1: + return "PMS_AREA_DRAM0_1"; + case MEMPROT_PMS_AREA_DRAM0_2: + return "PMS_AREA_DRAM0_2"; + case MEMPROT_PMS_AREA_DRAM0_3: + return "PMS_AREA_DRAM0_3"; + case MEMPROT_PMS_AREA_IRAM0_RTCFAST_LO: + return "PMS_AREA_IRAM0_RTCFAST_LO"; + case MEMPROT_PMS_AREA_IRAM0_RTCFAST_HI: + return "PMS_AREA_IRAM0_RTCFAST_HI"; + case MEMPROT_PMS_AREA_ALL: + return "PMS_AREA_ALL"; + default: + return "PMS_AREA_INVALID"; + } +} + +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/esp32/include/esp_hw_support/include/soc/esp32h2/memprot.h b/tools/sdk/esp32/include/esp_hw_support/include/soc/esp32h2/memprot.h deleted file mode 100644 index 75228580ffd..00000000000 --- a/tools/sdk/esp32/include/esp_hw_support/include/soc/esp32h2/memprot.h +++ /dev/null @@ -1,448 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - - -/* INTERNAL API - * generic interface to PMS memory protection features - */ - -#pragma once - -#include -#include -#include "esp_attr.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef IRAM_SRAM_START -#define IRAM_SRAM_START 0x4037C000 -#endif - -#ifndef DRAM_SRAM_START -#define DRAM_SRAM_START 0x3FC7C000 -#endif - -#ifndef MAP_DRAM_TO_IRAM -#define MAP_DRAM_TO_IRAM(addr) (addr - DRAM_SRAM_START + IRAM_SRAM_START) -#endif - -#ifndef MAP_IRAM_TO_DRAM -#define MAP_IRAM_TO_DRAM(addr) (addr - IRAM_SRAM_START + DRAM_SRAM_START) -#endif - -typedef enum { - MEMPROT_NONE = 0x00000000, - MEMPROT_IRAM0_SRAM = 0x00000001, - MEMPROT_DRAM0_SRAM = 0x00000002, - MEMPROT_ALL = 0xFFFFFFFF -} mem_type_prot_t; - -typedef enum { - MEMPROT_SPLITLINE_NONE = 0, - MEMPROT_IRAM0_DRAM0_SPLITLINE, - MEMPROT_IRAM0_LINE_0_SPLITLINE, - MEMPROT_IRAM0_LINE_1_SPLITLINE, - MEMPROT_DRAM0_DMA_LINE_0_SPLITLINE, - MEMPROT_DRAM0_DMA_LINE_1_SPLITLINE -} split_line_t; - -typedef enum { - MEMPROT_PMS_AREA_NONE = 0, - MEMPROT_IRAM0_PMS_AREA_0, - MEMPROT_IRAM0_PMS_AREA_1, - MEMPROT_IRAM0_PMS_AREA_2, - MEMPROT_IRAM0_PMS_AREA_3, - MEMPROT_DRAM0_PMS_AREA_0, - MEMPROT_DRAM0_PMS_AREA_1, - MEMPROT_DRAM0_PMS_AREA_2, - MEMPROT_DRAM0_PMS_AREA_3 -} pms_area_t; - -typedef enum -{ - MEMPROT_PMS_WORLD_0 = 0, - MEMPROT_PMS_WORLD_1, - MEMPROT_PMS_WORLD_2, - MEMPROT_PMS_WORLD_INVALID = 0xFFFFFFFF -} pms_world_t; - -typedef enum -{ - MEMPROT_PMS_OP_READ = 0, - MEMPROT_PMS_OP_WRITE, - MEMPROT_PMS_OP_FETCH, - MEMPROT_PMS_OP_INVALID = 0xFFFFFFFF -} pms_operation_type_t; - -/** - * @brief Converts Memory protection type to string - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - */ -const char *esp_memprot_mem_type_to_str(mem_type_prot_t mem_type); - -/** - * @brief Converts Split line type to string - * - * @param line_type Split line type (see split_line_t enum) - */ -const char *esp_memprot_split_line_to_str(split_line_t line_type); - -/** - * @brief Converts PMS Area type to string - * - * @param area_type PMS Area type (see pms_area_t enum) - */ -const char *esp_memprot_pms_to_str(pms_area_t area_type); - -/** - * @brief Returns PMS splitting address for given Split line type - * - * The value is taken from PMS configuration registers (IRam0 range) - * For details on split lines see 'esp_memprot_set_prot_int' function description - * - * @param line_type Split line type (see split_line_t enum) - * - * @return appropriate split line address - */ -uint32_t *esp_memprot_get_split_addr(split_line_t line_type); - -/** - * @brief Returns default main IRAM/DRAM splitting address - * - * The address value is given by _iram_text_end global (IRam0 range) - - * @return Main I/D split line (IRam0_DRam0_Split_Addr) - */ -void *esp_memprot_get_default_main_split_addr(void); - -/** - * @brief Sets a lock for the main IRAM/DRAM splitting address - * - * Locks can be unlocked only by digital system reset - */ -void esp_memprot_set_split_line_lock(void); - -/** - * @brief Gets a lock status for the main IRAM/DRAM splitting address - * - * @return true/false (locked/unlocked) - */ -bool esp_memprot_get_split_line_lock(void); - -/** - * @brief Sets required split line address - * - * @param line_type Split line type (see split_line_t enum) - * @param line_addr target address from a memory range relevant to given line_type (IRAM/DRAM) - */ -void esp_memprot_set_split_line(split_line_t line_type, const void *line_addr); - -/** - * @brief Sets a lock for PMS Area settings of required Memory type - * - * Locks can be unlocked only by digital system reset - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - */ -void esp_memprot_set_pms_lock(mem_type_prot_t mem_type); - -/** - * @brief Gets a lock status for PMS Area settings of required Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return true/false (locked/unlocked) - */ -bool esp_memprot_get_pms_lock(mem_type_prot_t mem_type); - -/** - * @brief Sets permissions for given PMS Area in IRam0 memory range (MEMPROT_IRAM0_SRAM) - * - * @param area_type IRam0 PMS Area type (see pms_area_t enum) - * @param r Read permission flag - * @param w Write permission flag - * @param x Execute permission flag - */ -void esp_memprot_iram_set_pms_area(pms_area_t area_type, bool r, bool w, bool x); - -/** - * @brief Gets current permissions for given PMS Area in IRam0 memory range (MEMPROT_IRAM0_SRAM) - * - * @param area_type IRam0 PMS Area type (see pms_area_t enum) - * @param r Read permission flag holder - * @param w Write permission flag holder - * @param x Execute permission flag holder - */ -void esp_memprot_iram_get_pms_area(pms_area_t area_type, bool *r, bool *w, bool *x); - -/** - * @brief Sets permissions for given PMS Area in DRam0 memory range (MEMPROT_DRAM0_SRAM) - * - * @param area_type DRam0 PMS Area type (see pms_area_t enum) - * @param r Read permission flag - * @param w Write permission flag - */ -void esp_memprot_dram_set_pms_area(pms_area_t area_type, bool r, bool w); - -/** - * @brief Gets current permissions for given PMS Area in DRam0 memory range (MEMPROT_DRAM0_SRAM) - * - * @param area_type DRam0 PMS Area type (see pms_area_t enum) - * @param r Read permission flag holder - * @param w Write permission flag holder - */ -void esp_memprot_dram_get_pms_area(pms_area_t area_type, bool *r, bool *w); - -/** - * @brief Sets a lock for PMS interrupt monitor settings of required Memory type - * - * Locks can be unlocked only by digital system reset - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - */ -void esp_memprot_set_monitor_lock(mem_type_prot_t mem_type); - -/** - * @brief Gets a lock status for PMS interrupt monitor settings of required Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return true/false (locked/unlocked) - */ -bool esp_memprot_get_monitor_lock(mem_type_prot_t mem_type); - -/** - * @brief Enable PMS violation interrupt monitoring of required Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * @param enable/disable - */ -void esp_memprot_set_monitor_en(mem_type_prot_t mem_type, bool enable); - -/** - * @brief Gets enable/disable status for PMS interrupt monitor settings of required Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return true/false (enabled/disabled) - */ -bool esp_memprot_get_monitor_en(mem_type_prot_t mem_type); - -/** - * @brief Gets CPU ID for currently active PMS violation interrupt - * - * @return CPU ID (CPU_PRO for ESP32H2) - */ -int IRAM_ATTR esp_memprot_intr_get_cpuid(void); - -/** - * @brief Clears current interrupt ON flag for given Memory type - * - * Interrupt clearing happens in two steps: - * 1. Interrupt CLR flag is set (to clear the interrupt ON status) - * 2. Interrupt CLR flag is reset (to allow further monitoring) - * This operation is non-atomic by PMS module design - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - */ -void IRAM_ATTR esp_memprot_monitor_clear_intr(mem_type_prot_t mem_type); - -/** - * @brief Returns active PMS violation interrupt (if any) - * - * This function iterates through supported Memory type status registers - * and returns the first interrupt-on flag. If none is found active, - * MEMPROT_NONE is returned. - * Order of checking (in current version): - * 1. MEMPROT_IRAM0_SRAM - * 2. MEMPROT_DRAM0_SRAM - * - * @return mem_type Memory protection type related to active interrupt found (see mem_type_prot_t enum) - */ -mem_type_prot_t IRAM_ATTR esp_memprot_get_active_intr_memtype(void); - -/** - * @brief Checks whether any violation interrupt is active - * - * @return true/false (yes/no) - */ -bool IRAM_ATTR esp_memprot_is_locked_any(void); - -/** - * @brief Checks whether any violation interrupt is enabled - * - * @return true/false (yes/no) - */ -bool IRAM_ATTR esp_memprot_is_intr_ena_any(void); - -/** - * @brief Checks whether any violation interrupt is enabled - * - * @return true/false (yes/no) - */ -bool IRAM_ATTR esp_memprot_get_violate_intr_on(mem_type_prot_t mem_type); - -/** - * @brief Returns the address which caused the violation interrupt (if any) - * - * The address is taken from appropriate PMS violation status register, based given Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return faulting address - */ -uint32_t IRAM_ATTR esp_memprot_get_violate_addr(mem_type_prot_t mem_type); - -/** - * @brief Returns the World identifier of the code causing the violation interrupt (if any) - * - * The value is taken from appropriate PMS violation status register, based given Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return World identifier (see pms_world_t enum) - */ -pms_world_t IRAM_ATTR esp_memprot_get_violate_world(mem_type_prot_t mem_type); - -/** - * @brief Returns Read or Write operation type which caused the violation interrupt (if any) - * - * The value (bit) is taken from appropriate PMS violation status register, based given Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return PMS operation type relevant to mem_type parameter (se pms_operation_type_t) - */ -pms_operation_type_t IRAM_ATTR esp_memprot_get_violate_wr(mem_type_prot_t mem_type); - -/** - * @brief Returns LoadStore flag of the operation type which caused the violation interrupt (if any) - * - * The value (bit) is taken from appropriate PMS violation status register, based given Memory type - * Effective only on IRam0 access - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return true/false (LoadStore bit on/off) - */ -bool IRAM_ATTR esp_memprot_get_violate_loadstore(mem_type_prot_t mem_type); - -/** - * @brief Returns byte-enables for the address which caused the violation interrupt (if any) - * - * The value is taken from appropriate PMS violation status register, based given Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return byte-enables - */ -uint32_t IRAM_ATTR esp_memprot_get_violate_byte_en(mem_type_prot_t mem_type); - -/** - * @brief Returns raw contents of DRam0 status register 1 - * - * @return 32-bit register value - */ -uint32_t IRAM_ATTR esp_memprot_get_dram_status_reg_1(void); - -/** - * @brief Returns raw contents of DRam0 status register 2 - * - * @return 32-bit register value - */ -uint32_t IRAM_ATTR esp_memprot_get_dram_status_reg_2(void); - -/** - * @brief Returns raw contents of IRam0 status register - * - * @return 32-bit register value - */ -uint32_t IRAM_ATTR esp_memprot_get_iram_status_reg(void); - -/** - * @brief Register PMS violation interrupt in global interrupt matrix for given Memory type - * - * Memory protection components uses specific interrupt number, see ETS_MEMPROT_ERR_INUM - * The registration makes the panic-handler routine being called when the interrupt appears - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - */ -void esp_memprot_set_intr_matrix(mem_type_prot_t mem_type); - -/** - * @brief Convenient routine for setting the PMS defaults - * - * Called on application startup, depending on CONFIG_ESP_SYSTEM_MEMPROT_FEATURE Kconfig settings - * For implementation details see 'esp_memprot_set_prot_int' description - * - * @param invoke_panic_handler register all interrupts for panic handling (true/false) - * @param lock_feature lock the defaults to prevent further PMS settings changes (true/false) - * @param mem_type_mask 32-bit field of specific PMS parts to configure (see 'esp_memprot_set_prot_int') - */ -void esp_memprot_set_prot(bool invoke_panic_handler, bool lock_feature, uint32_t *mem_type_mask); - -/** - * @brief Internal routine for setting the PMS defaults - * - * Called on application startup from within 'esp_memprot_set_prot'. Allows setting a specific splitting address - * (main I/D split line) - see the parameter 'split_addr'. If the 'split_addr' equals to NULL, default I/D split line - * is used (&_iram_text_end) and all the remaining lines share the same address. - * The function sets all the split lines and PMS areas to the same space, - * ie there is a single instruction space and single data space at the end. - * The PMS split lines and permission areas scheme described below: - * - * DRam0/DMA IRam0 - * ----------------------------------------------- - * ... | IRam0_PMS_0 | - * DRam0_PMS_0 ----------------------------------------------- IRam0_line1_Split_addr - * ... | IRam0_PMS_1 | - * ... ----------------------------------------------- IRam0_line0_Split_addr - * | IRam0_PMS_2 | - * =============================================== IRam0_DRam0_Split_addr (main I/D) - * | DRam0_PMS_1 | - * DRam0_DMA_line0_Split_addr ----------------------------------------------- ... - * | DRam0_PMS_2 | ... - * DRam0_DMA_line1_Split_addr ----------------------------------------------- IRam0_PMS_3 - * | DRam0_PMS_3 | ... - * ----------------------------------------------- - * - * Default settings provided by 'esp_memprot_set_prot_int' are as follows: - * - * DRam0/DMA IRam0 - * ----------------------------------------------- - * | IRam0_PMS_0 = IRam0_PMS_1 = IRam0_PMS_2 | - * | DRam0_PMS_0 | IRam0_line1_Split_addr - * DRam0_DMA_line0_Split_addr | | = - * = =============================================== IRam0_line0_Split_addr - * DRam0_DMA_line1_Split_addr | | = - * | DRam0_PMS_1 = DRam0_PMS_2 = DRam0_PMS_3 | IRam0_DRam0_Split_addr (main I/D) - * | IRam0_PMS_3 | - * ----------------------------------------------- - * - * Once the memprot feature is locked, it can be unlocked only by digital system reset - * - * @param invoke_panic_handler register all the violation interrupts for panic handling (true/false) - * @param lock_feature lock the defaults to prevent further PMS settings changes (true/false) - * @param split_addr specific main I/D adrees or NULL to use default ($_iram_text_end) - * @param mem_type_mask 32-bit field of specific PMS parts to configure (members of mem_type_prot_t) - */ -void esp_memprot_set_prot_int(bool invoke_panic_handler, bool lock_feature, void *split_addr, uint32_t *mem_type_mask); - -/** - * @brief Returns raw contents of PMS interrupt monitor register for given Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return 32-bit register value - */ -uint32_t esp_memprot_get_monitor_enable_reg(mem_type_prot_t mem_type); - -#ifdef __cplusplus -} -#endif diff --git a/tools/sdk/esp32/include/esp_hw_support/include/soc/esp32h2/soc_memprot_types.h b/tools/sdk/esp32/include/esp_hw_support/include/soc/esp32h2/soc_memprot_types.h new file mode 100644 index 00000000000..3048088eba4 --- /dev/null +++ b/tools/sdk/esp32/include/esp_hw_support/include/soc/esp32h2/soc_memprot_types.h @@ -0,0 +1,117 @@ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +////////////////////////////////////////////////////////// +// ESP32-H2 PMS memory protection types +// + +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Memory types recognized by PMS + */ +typedef enum { + MEMPROT_TYPE_NONE = 0x00000000, + MEMPROT_TYPE_ALL = 0x7FFFFFFF, + MEMPROT_TYPE_INVALID = 0x80000000 +} esp_mprot_mem_t; + +/** + * @brief Splitting address (line) type + */ +typedef enum { + MEMPROT_SPLIT_ADDR_NONE = 0x00000000, + MEMPROT_SPLIT_ADDR_ALL = 0x7FFFFFFF, + MEMPROT_SPLIT_ADDR_INVALID = 0x80000000 +} esp_mprot_split_addr_t; + +/** + * @brief PMS area type (memory space between adjacent splitting addresses or above/below the main splt.address) + */ +typedef enum { + MEMPROT_PMS_AREA_NONE = 0x00000000, + MEMPROT_PMS_AREA_ALL = 0x7FFFFFFF, + MEMPROT_PMS_AREA_INVALID = 0x80000000 +} esp_mprot_pms_area_t; + +/** +* @brief Memory protection configuration +*/ +typedef struct { + bool invoke_panic_handler; /*!< Register PMS violation interrupt for panic-handling */ + bool lock_feature; /*!< Lock all PMS settings */ + void *split_addr; /*!< Main I/D splitting address */ + uint32_t mem_type_mask; /*!< Memory types required to protect. See esp_mprot_mem_t enum */ +} esp_memp_config_t; + +#define ESP_MEMPROT_DEFAULT_CONFIG() {\ + .invoke_panic_handler = true, \ + .lock_feature = true, \ + .split_addr = NULL, \ + .mem_type_mask = MEMPROT_TYPE_ALL \ +} + +/** + * @brief Converts Memory protection type to string + * + * @param mem_type Memory protection type + */ +static inline const char *esp_mprot_mem_type_to_str(const esp_mprot_mem_t mem_type) +{ + switch (mem_type) { + case MEMPROT_TYPE_NONE: + return "MEMPROT_TYPE_NONE"; + case MEMPROT_TYPE_ALL: + return "MEMPROT_TYPE_ALL"; + default: + return "MEMPROT_TYPE_INVALID"; + } +} + +/** + * @brief Converts Splitting address type to string + * + * @param line_type Split line type + */ +static inline const char *esp_mprot_split_addr_to_str(const esp_mprot_split_addr_t line_type) +{ + switch (line_type) { + case MEMPROT_SPLIT_ADDR_NONE: + return "MEMPROT_SPLIT_ADDR_NONE"; + case MEMPROT_SPLIT_ADDR_ALL: + return "MEMPROT_SPLIT_ADDR_ALL"; + default: + return "MEMPROT_SPLIT_ADDR_INVALID"; + } +} + +/** + * @brief Converts PMS Area type to string + * + * @param area_type PMS Area type + */ +static inline const char *esp_mprot_pms_area_to_str(const esp_mprot_pms_area_t area_type) +{ + switch (area_type) { + case MEMPROT_PMS_AREA_NONE: + return "MEMPROT_PMS_AREA_NONE"; + case MEMPROT_PMS_AREA_ALL: + return "MEMPROT_PMS_AREA_ALL"; + default: + return "MEMPROT_PMS_AREA_INVALID"; + } +} + +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/esp32/include/esp_hw_support/include/soc/esp32s2/soc_memprot_types.h b/tools/sdk/esp32/include/esp_hw_support/include/soc/esp32s2/soc_memprot_types.h new file mode 100644 index 00000000000..f17e2143133 --- /dev/null +++ b/tools/sdk/esp32/include/esp_hw_support/include/soc/esp32s2/soc_memprot_types.h @@ -0,0 +1,117 @@ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +////////////////////////////////////////////////////////// +// ESP32-S2 PMS memory protection types +// + +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Memory types recognized by PMS + */ +typedef enum { + MEMPROT_TYPE_NONE = 0x00000000, + MEMPROT_TYPE_ALL = 0x7FFFFFFF, + MEMPROT_TYPE_INVALID = 0x80000000 +} esp_mprot_mem_t; + +/** + * @brief Splitting address (line) type + */ +typedef enum { + MEMPROT_SPLIT_ADDR_NONE = 0x00000000, + MEMPROT_SPLIT_ADDR_ALL = 0x7FFFFFFF, + MEMPROT_SPLIT_ADDR_INVALID = 0x80000000 +} esp_mprot_split_addr_t; + +/** + * @brief PMS area type (memory space between adjacent splitting addresses or above/below the main splt.address) + */ +typedef enum { + MEMPROT_PMS_AREA_NONE = 0x00000000, + MEMPROT_PMS_AREA_ALL = 0x7FFFFFFF, + MEMPROT_PMS_AREA_INVALID = 0x80000000 +} esp_mprot_pms_area_t; + +/** +* @brief Memory protection configuration +*/ +typedef struct { + bool invoke_panic_handler; /*!< Register PMS violation interrupt for panic-handling */ + bool lock_feature; /*!< Lock all PMS settings */ + void *split_addr; /*!< Main I/D splitting address */ + uint32_t mem_type_mask; /*!< Memory types required to protect. See esp_mprot_mem_t enum */ +} esp_memp_config_t; + +#define ESP_MEMPROT_DEFAULT_CONFIG() { \ + .invoke_panic_handler = true, \ + .lock_feature = true, \ + .split_addr = NULL, \ + .mem_type_mask = MEMPROT_TYPE_ALL \ +} + +/** + * @brief Converts Memory protection type to string + * + * @param mem_type Memory protection type + */ +static inline const char *esp_mprot_mem_type_to_str(const esp_mprot_mem_t mem_type) +{ + switch (mem_type) { + case MEMPROT_TYPE_NONE: + return "MEMPROT_TYPE_NONE"; + case MEMPROT_TYPE_ALL: + return "MEMPROT_TYPE_ALL"; + default: + return "MEMPROT_TYPE_INVALID"; + } +} + +/** + * @brief Converts Splitting address type to string + * + * @param line_type Split line type + */ +static inline const char *esp_mprot_split_addr_to_str(const esp_mprot_split_addr_t line_type) +{ + switch (line_type) { + case MEMPROT_SPLIT_ADDR_NONE: + return "MEMPROT_SPLIT_ADDR_NONE"; + case MEMPROT_SPLIT_ADDR_ALL: + return "MEMPROT_SPLIT_ADDR_ALL"; + default: + return "MEMPROT_SPLIT_ADDR_INVALID"; + } +} + +/** + * @brief Converts PMS Area type to string + * + * @param area_type PMS Area type + */ +static inline const char *esp_mprot_pms_area_to_str(const esp_mprot_pms_area_t area_type) +{ + switch (area_type) { + case MEMPROT_PMS_AREA_NONE: + return "MEMPROT_PMS_AREA_NONE"; + case MEMPROT_PMS_AREA_ALL: + return "MEMPROT_PMS_AREA_ALL"; + default: + return "MEMPROT_PMS_AREA_INVALID"; + } +} + +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/esp32/include/esp_hw_support/include/soc/esp32s3/memprot.h b/tools/sdk/esp32/include/esp_hw_support/include/soc/esp32s3/memprot.h deleted file mode 100644 index 948e0676680..00000000000 --- a/tools/sdk/esp32/include/esp_hw_support/include/soc/esp32s3/memprot.h +++ /dev/null @@ -1,484 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - - -/* INTERNAL API - * generic interface to MMU memory protection features - */ - -#pragma once -#include -#include -#include "esp_attr.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef enum { - MEMPROT_NONE = 0x00000000, - MEMPROT_IRAM0_SRAM = 0x00000001, - MEMPROT_DRAM0_SRAM = 0x00000002, - MEMPROT_IRAM0_RTCFAST = 0x00000004, - MEMPROT_DRAM0_RTCFAST = 0x00000008, - MEMPROT_PERI1_RTCSLOW = 0x00000010, - MEMPROT_PERI2_RTCSLOW_0 = 0x00000020, - MEMPROT_PERI2_RTCSLOW_1 = 0x00000040, - MEMPROT_ALL = 0xFFFFFFFF -} mem_type_prot_t; - - -/** - * @brief Returns splitting address for required memory region - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * - * @return Splitting address for the memory region required. - * The address is given by region-specific global symbol exported from linker script, - * it is not read out from related configuration register. - */ -uint32_t *IRAM_ATTR esp_memprot_get_split_addr(mem_type_prot_t mem_type); - -/** - * @brief Initializes illegal memory access control (MMU) for required memory section. - * - * All memory access interrupts share ETS_MEMACCESS_ERR_INUM input channel, it is caller's - * responsibility to properly detect actual intr. source as well as possible prioritization in case - * of multiple source reported during one intr.handling routine run - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - */ -void esp_memprot_intr_init(mem_type_prot_t mem_type); - -/** - * @brief Enable/disable the memory protection interrupt - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param enable enable/disable - */ -void esp_memprot_intr_ena(mem_type_prot_t mem_type, bool enable); - -/** - * @brief Sets a request for clearing interrupt-on flag for specified memory region (register write) - * - * @note When called without actual interrupt-on flag set, subsequent occurrence of related interrupt is ignored. - * Should be used only after the real interrupt appears, typically as the last step in interrupt handler's routine. - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - */ -void esp_memprot_clear_intr(mem_type_prot_t mem_type); - -/** - * @brief Detects which memory protection interrupt is active - * - * @note Check order - * MEMPROT_IRAM0_SRAM - * MEMPROT_IRAM0_RTCFAST - * MEMPROT_DRAM0_SRAM - * MEMPROT_DRAM0_RTCFAST - * - * @return Memory protection area type (see mem_type_prot_t enum) - */ -mem_type_prot_t IRAM_ATTR esp_memprot_get_active_intr_memtype(void); - -/** - * @brief Gets interrupt status register contents for specified memory region - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * - * @return Contents of status register - */ -uint32_t esp_memprot_get_fault_reg(mem_type_prot_t mem_type); - -/** - * @brief Get details of given interrupt status - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param faulting_address Faulting address causing the interrupt [out] - * @param op_type Operation being processed at the faulting address [out] - * IRAM0: 0 - read, 1 - write - * DRAM0: 0 - read, 1 - write - * @param op_subtype Additional info for op_type [out] - * IRAM0: 0 - instruction segment access, 1 - data segment access - * DRAM0: 0 - non-atomic operation, 1 - atomic operation - */ -void IRAM_ATTR esp_memprot_get_fault_status(mem_type_prot_t mem_type, uint32_t **faulting_address, uint32_t *op_type, uint32_t *op_subtype); - -/** - * @brief Gets string representation of required memory region identifier - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * - * @return mem_type as string - */ -const char *IRAM_ATTR esp_memprot_type_to_str(mem_type_prot_t mem_type); - -/** - * @brief Detects whether any of the interrupt locks is active (requires digital system reset to unlock) - * - * @return true/false - */ -bool esp_memprot_is_locked_any(void); - -/** - * @brief Sets lock for specified memory region. - * - * Locks can be unlocked only by digital system reset - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - */ -void esp_memprot_set_lock(mem_type_prot_t mem_type); - -/** - * @brief Gets lock status for required memory region - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * - * @return true/false (locked/unlocked) - */ -bool esp_memprot_get_lock(mem_type_prot_t mem_type); - -/** - * @brief Gets permission control configuration register contents for required memory region - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * - * @return Permission control register contents - */ -uint32_t esp_memprot_get_conf_reg(mem_type_prot_t mem_type); - -/** - * @brief Gets interrupt permission settings for unified management block - * - * Gets interrupt permission settings register contents for required memory region, returns settings for unified management blocks - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * - * @return Permission settings register contents - */ -uint32_t esp_memprot_get_perm_uni_reg(mem_type_prot_t mem_type); - -/** - * @brief Gets interrupt permission settings for split management block - * - * Gets interrupt permission settings register contents for required memory region, returns settings for split management blocks - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * - * @return Permission settings register contents - */ -uint32_t esp_memprot_get_perm_split_reg(mem_type_prot_t mem_type); - -/** - * @brief Detects whether any of the memory protection interrupts is enabled - * - * @return true/false - */ -bool esp_memprot_is_intr_ena_any(void); - -/** - * @brief Gets interrupt-enabled flag for given memory region - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * - * @return Interrupt-enabled value - */ -uint32_t esp_memprot_get_intr_ena_bit(mem_type_prot_t mem_type); - -/** - * @brief Gets interrupt-active flag for given memory region - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * - * @return Interrupt-active value - */ -uint32_t esp_memprot_get_intr_on_bit(mem_type_prot_t mem_type); - -/** - * @brief Gets interrupt-clear request flag for given memory region - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * - * @return Interrupt-clear request value - */ -uint32_t esp_memprot_get_intr_clr_bit(mem_type_prot_t mem_type); - -/** - * @brief Gets read permission value for specified block and memory region - * - * Returns read permission bit value for required unified-management block (0-3) in given memory region. - * Applicable to all memory types. - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param block Memory block identifier (0-3) - * - * @return Read permission value for required block - */ -uint32_t esp_memprot_get_uni_block_read_bit(mem_type_prot_t mem_type, uint32_t block); - -/** - * @brief Gets write permission value for specified block and memory region - * - * Returns write permission bit value for required unified-management block (0-3) in given memory region. - * Applicable to all memory types. - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param block Memory block identifier (0-3) - * - * @return Write permission value for required block - */ -uint32_t esp_memprot_get_uni_block_write_bit(mem_type_prot_t mem_type, uint32_t block); - -/** - * @brief Gets execute permission value for specified block and memory region - * - * Returns execute permission bit value for required unified-management block (0-3) in given memory region. - * Applicable only to IRAM memory types - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param block Memory block identifier (0-3) - * - * @return Execute permission value for required block - */ -uint32_t esp_memprot_get_uni_block_exec_bit(mem_type_prot_t mem_type, uint32_t block); - -/** - * @brief Sets permissions for specified block in DRAM region - * - * Sets Read and Write permission for specified unified-management block (0-3) in given memory region. - * Applicable only to DRAM memory types - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param block Memory block identifier (0-3) - * @param write_perm Write permission flag - * @param read_perm Read permission flag - */ -void esp_memprot_set_uni_block_perm_dram(mem_type_prot_t mem_type, uint32_t block, bool write_perm, bool read_perm); - -/** - * @brief Sets permissions for high and low memory segment in DRAM region - * - * Sets Read and Write permission for both low and high memory segments given by splitting address. - * The splitting address must be equal to or higher then beginning of block 5 - * Applicable only to DRAM memory types - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param split_addr Address to split the memory region to lower and higher segment - * @param lw Low segment Write permission flag - * @param lr Low segment Read permission flag - * @param hw High segment Write permission flag - * @param hr High segment Read permission flag - */ -void esp_memprot_set_prot_dram(mem_type_prot_t mem_type, uint32_t *split_addr, bool lw, bool lr, bool hw, bool hr); - -/** - * @brief Sets permissions for specified block in IRAM region - * - * Sets Read, Write and Execute permission for specified unified-management block (0-3) in given memory region. - * Applicable only to IRAM memory types - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param block Memory block identifier (0-3) - * @param write_perm Write permission flag - * @param exec_perm Execute permission flag - */ -void esp_memprot_set_uni_block_perm_iram(mem_type_prot_t mem_type, uint32_t block, bool write_perm, bool read_perm, bool exec_perm); - -/** - * @brief Sets permissions for high and low memory segment in IRAM region - * - * Sets Read, Write and Execute permission for both low and high memory segments given by splitting address. - * The splitting address must be equal to or higher then beginning of block 5 - * Applicable only to IRAM memory types - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param split_addr Address to split the memory region to lower and higher segment - * @param lw Low segment Write permission flag - * @param lr Low segment Read permission flag - * @param lx Low segment Execute permission flag - * @param hw High segment Write permission flag - * @param hr High segment Read permission flag - * @param hx High segment Execute permission flag - */ -void esp_memprot_set_prot_iram(mem_type_prot_t mem_type, uint32_t *split_addr, bool lw, bool lr, bool lx, bool hw, bool hr, bool hx); - -/** - * @brief Activates memory protection for all supported memory region types - * - * @note The feature is disabled when JTAG interface is connected - * - * @param invoke_panic_handler map mem.prot interrupt to ETS_MEMACCESS_ERR_INUM and thus invokes panic handler when fired ('true' not suitable for testing) - * @param lock_feature sets LOCK bit, see esp_memprot_set_lock() ('true' not suitable for testing) - * @param mem_type_mask holds a set of required memory protection types (bitmask built of mem_type_prot_t). NULL means default (MEMPROT_ALL in this version) - */ -void esp_memprot_set_prot(bool invoke_panic_handler, bool lock_feature, uint32_t *mem_type_mask); - -/** - * @brief Get permission settings bits for IRAM0 split mgmt. Only IRAM0 memory types allowed - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param lw Low segment Write permission flag - * @param lr Low segment Read permission flag - * @param lx Low segment Execute permission flag - * @param hw High segment Write permission flag - * @param hr High segment Read permission flag - * @param hx High segment Execute permission flag - */ -void esp_memprot_get_perm_split_bits_iram(mem_type_prot_t mem_type, bool *lw, bool *lr, bool *lx, bool *hw, bool *hr, bool *hx); - -/** - * @brief Get permission settings bits for DRAM0 split mgmt. Only DRAM0 memory types allowed - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param lw Low segment Write permission flag - * @param lr Low segment Read permission flag - * @param hw High segment Write permission flag - * @param hr High segment Read permission flag - */ -void esp_memprot_get_perm_split_bits_dram(mem_type_prot_t mem_type, bool *lw, bool *lr, bool *hw, bool *hr); - -/** - * @brief Sets permissions for high and low memory segment in PERIBUS1 region - * - * Sets Read and Write permission for both low and high memory segments given by splitting address. - * Applicable only to PERIBUS1 memory types - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param split_addr Address to split the memory region to lower and higher segment - * @param lw Low segment Write permission flag - * @param lr Low segment Read permission flag - * @param hw High segment Write permission flag - * @param hr High segment Read permission flag - */ -void esp_memprot_set_prot_peri1(mem_type_prot_t mem_type, uint32_t *split_addr, bool lw, bool lr, bool hw, bool hr); - -/** - * @brief Get permission settings bits for PERIBUS1 split mgmt. Only PERIBUS1 memory types allowed - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param lw Low segment Write permission flag - * @param lr Low segment Read permission flag - * @param hw High segment Write permission flag - * @param hr High segment Read permission flag - */ -void esp_memprot_get_perm_split_bits_peri1(mem_type_prot_t mem_type, bool *lw, bool *lr, bool *hw, bool *hr); - -/** - * @brief Get permission settings bits for PERIBUS2 split mgmt. Only PERIBUS2 memory types allowed - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param lw Low segment Write permission flag - * @param lr Low segment Read permission flag - * @param lx Low segment Execute permission flag - * @param hw High segment Write permission flag - * @param hr High segment Read permission flag - * @param hx High segment Execute permission flag - */ -void esp_memprot_get_perm_split_bits_peri2(mem_type_prot_t mem_type, bool *lw, bool *lr, bool *lx, bool *hw, bool *hr, bool *hx); - -/** - * @brief Sets permissions for high and low memory segment in PERIBUS2 region - * - * Sets Read Write permission for both low and high memory segments given by splitting address. - * Applicable only to PERIBUS2 memory types - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param split_addr Address to split the memory region to lower and higher segment - * @param lw Low segment Write permission flag - * @param lr Low segment Read permission flag - * @param lx Low segment Execute permission flag - * @param hw High segment Write permission flag - * @param hr High segment Read permission flag - * @param hx High segment Execute permission flag - */ -void esp_memprot_set_prot_peri2(mem_type_prot_t mem_type, uint32_t *split_addr, bool lw, bool lr, bool lx, bool hw, bool hr, bool hx); - -/** - * @brief Get permissions for specified memory type. Irrelevant bits are ignored - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param lw Low segment Write permission flag - * @param lr Low segment Read permission flag - * @param lx Low segment Execute permission flag - * @param hw High segment Write permission flag - * @param hr High segment Read permission flag - * @param hx High segment Execute permission flag - */ -void esp_memprot_get_permissions(mem_type_prot_t mem_type, bool *lw, bool *lr, bool *lx, bool *hw, bool *hr, bool *hx); - -/** - * @brief Get Read permission settings for low and high regions of given memory type - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param lr Low segment Read permission flag - * @param hr High segment Read permission flag - */ -void esp_memprot_get_perm_read(mem_type_prot_t mem_type, bool *lr, bool *hr); - -/** - * @brief Get Write permission settings for low and high regions of given memory type - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param lr Low segment Write permission flag - * @param hr High segment Write permission flag - */ -void esp_memprot_get_perm_write(mem_type_prot_t mem_type, bool *lw, bool *hw); - -/** - * @brief Get Execute permission settings for low and high regions of given memory type - * Applicable only to IBUS-compatible memory types - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param lr Low segment Exec permission flag - * @param hr High segment Exec permission flag - */ -void esp_memprot_get_perm_exec(mem_type_prot_t mem_type, bool *lx, bool *hx); - -/** - * @brief Returns the lowest address in required memory region - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - */ -uint32_t esp_memprot_get_low_limit(mem_type_prot_t mem_type); - -/** - * @brief Returns the highest address in required memory region - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - */ -uint32_t esp_memprot_get_high_limit(mem_type_prot_t mem_type); - -/** - * @brief Sets READ permission bit for required memory region - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param lr Low segment Read permission flag - * @param hr High segment Read permission flag - */ -void esp_memprot_set_read_perm(mem_type_prot_t mem_type, bool lr, bool hr); - -/** - * @brief Sets WRITE permission bit for required memory region - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param lr Low segment Write permission flag - * @param hr High segment Write permission flag - */ -void esp_memprot_set_write_perm(mem_type_prot_t mem_type, bool lw, bool hw); - -/** - * @brief Sets EXECUTE permission bit for required memory region - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param lr Low segment Exec permission flag - * @param hr High segment Exec permission flag - */ -void esp_memprot_set_exec_perm(mem_type_prot_t mem_type, bool lx, bool hx); - - -#ifdef __cplusplus -} -#endif diff --git a/tools/sdk/esp32/include/esp_hw_support/include/soc/esp32s3/soc_memprot_types.h b/tools/sdk/esp32/include/esp_hw_support/include/soc/esp32s3/soc_memprot_types.h new file mode 100644 index 00000000000..06dde33ffad --- /dev/null +++ b/tools/sdk/esp32/include/esp_hw_support/include/soc/esp32s3/soc_memprot_types.h @@ -0,0 +1,119 @@ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +////////////////////////////////////////////////////////// +// ESP32-S3 PMS memory protection types +// + +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Memory types recognized by PMS + */ +typedef enum { + MEMPROT_TYPE_NONE = 0x00000000, + MEMPROT_TYPE_ALL = 0x7FFFFFFF, + MEMPROT_TYPE_INVALID = 0x80000000 +} esp_mprot_mem_t; + +/** + * @brief Splitting address (line) type + */ +typedef enum { + MEMPROT_SPLIT_ADDR_NONE = 0x00000000, + MEMPROT_SPLIT_ADDR_ALL = 0x7FFFFFFF, + MEMPROT_SPLIT_ADDR_INVALID = 0x80000000 +} esp_mprot_split_addr_t; + +/** + * @brief PMS area type (memory space between adjacent splitting addresses or above/below the main splt.address) + */ +typedef enum { + MEMPROT_PMS_AREA_NONE = 0x00000000, + MEMPROT_PMS_AREA_ALL = 0x7FFFFFFF, + MEMPROT_PMS_AREA_INVALID = 0x80000000 +} esp_mprot_pms_area_t; + +/** +* @brief Memory protection configuration +*/ +typedef struct { + bool invoke_panic_handler; /*!< Register PMS violation interrupt for panic-handling */ + bool lock_feature; /*!< Lock all PMS settings */ + void *split_addr; /*!< Main I/D splitting address */ + uint32_t mem_type_mask; /*!< Memory types required to protect. See esp_mprot_mem_t enum */ + int target_cpu[]; /*!< Array of CPU/core IDs required to receive given PMS protection */ +} esp_memp_config_t; + +#define ESP_MEMPROT_DEFAULT_CONFIG() { \ + .invoke_panic_handler = true, \ + .lock_feature = true, \ + .split_addr = NULL, \ + .mem_type_mask = MEMPROT_TYPE_ALL,\ + .target_cpu[] = {PRO_CPU_NUM, APP_CPU_NUM} \ +} + +/** + * @brief Converts Memory protection type to string + * + * @param mem_type Memory protection type + */ +static inline const char *esp_mprot_mem_type_to_str(const esp_mprot_mem_t mem_type) +{ + switch (mem_type) { + case MEMPROT_TYPE_NONE: + return "MEMPROT_TYPE_NONE"; + case MEMPROT_TYPE_ALL: + return "MEMPROT_TYPE_ALL"; + default: + return "MEMPROT_TYPE_INVALID"; + } +} + +/** + * @brief Converts Splitting address type to string + * + * @param line_type Split line type + */ +static inline const char *esp_mprot_split_addr_to_str(const esp_mprot_split_addr_t line_type) +{ + switch (line_type) { + case MEMPROT_SPLIT_ADDR_NONE: + return "MEMPROT_SPLIT_ADDR_NONE"; + case MEMPROT_SPLIT_ADDR_ALL: + return "MEMPROT_SPLIT_ADDR_ALL"; + default: + return "MEMPROT_SPLIT_ADDR_INVALID"; + } +} + +/** + * @brief Converts PMS Area type to string + * + * @param area_type PMS Area type + */ +static inline const char *esp_mprot_pms_area_to_str(const esp_mprot_pms_area_t area_type) +{ + switch (area_type) { + case MEMPROT_PMS_AREA_NONE: + return "MEMPROT_PMS_AREA_NONE"; + case MEMPROT_PMS_AREA_ALL: + return "MEMPROT_PMS_AREA_ALL"; + default: + return "MEMPROT_PMS_AREA_INVALID"; + } +} + +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/esp32/include/esp_hw_support/port/esp32/regi2c_ctrl.h b/tools/sdk/esp32/include/esp_hw_support/port/esp32/regi2c_ctrl.h index ea2870e99b1..236e49b69e3 100644 --- a/tools/sdk/esp32/include/esp_hw_support/port/esp32/regi2c_ctrl.h +++ b/tools/sdk/esp32/include/esp_hw_support/port/esp32/regi2c_ctrl.h @@ -52,6 +52,10 @@ uint8_t regi2c_ctrl_read_reg_mask(uint8_t block, uint8_t host_id, uint8_t reg_ad void regi2c_ctrl_write_reg(uint8_t block, uint8_t host_id, uint8_t reg_add, uint8_t data); void regi2c_ctrl_write_reg_mask(uint8_t block, uint8_t host_id, uint8_t reg_add, uint8_t msb, uint8_t lsb, uint8_t data); +/* enter the critical section that protects internal registers. Don't use it in SDK. Use the functions above. */ +void regi2c_enter_critical(void); +void regi2c_exit_critical(void); + #endif // BOOTLOADER_BUILD /* Convenience macros for the above functions, these use register definitions diff --git a/tools/sdk/esp32/include/esp_ipc/include/esp_ipc.h b/tools/sdk/esp32/include/esp_ipc/include/esp_ipc.h index 5e02c460bce..5307cbcdab1 100644 --- a/tools/sdk/esp32/include/esp_ipc/include/esp_ipc.h +++ b/tools/sdk/esp32/include/esp_ipc/include/esp_ipc.h @@ -12,8 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef __ESP_IPC_H__ -#define __ESP_IPC_H__ +#pragma once #include @@ -23,30 +22,30 @@ extern "C" { #if !defined(CONFIG_FREERTOS_UNICORE) || defined(CONFIG_APPTRACE_GCOV_ENABLE) -/** @cond */ -typedef void (*esp_ipc_func_t)(void* arg); -/** @endcond */ /* * Inter-processor call APIs * - * FreeRTOS provides several APIs which can be used to communicate between - * different tasks, including tasks running on different CPUs. - * This module provides additional APIs to run some code on the other CPU. + * FreeRTOS provides several APIs which can be used to communicate between different tasks, including tasks running on + * different CPUs. This module provides additional APIs to run some code on the other CPU. These APIs can only be used + * when FreeRTOS scheduler is running. + */ + +/** + * @brief IPC Callback * - * These APIs can only be used when FreeRTOS scheduler is running. + * A callback of this type should be provided as an argument when calling esp_ipc_call() or esp_ipc_call_blocking(). */ +typedef void (*esp_ipc_func_t)(void* arg); /** - * @brief Execute a function on the given CPU + * @brief Execute a callback on a given CPU + * + * Execute a given callback on a particular CPU. The callback must be of type "esp_ipc_func_t" and will be invoked in + * the context of the target CPU's IPC task. * - * Run a given function on a particular CPU. The given function must accept a - * void* argument and return void. The given function is run in the context of - * the IPC task of the CPU specified by the cpu_id parameter. The calling task - * will be blocked until the IPC task begins executing the given function. If - * another IPC call is ongoing, the calling task will block until the other IPC - * call completes. The stack size allocated for the IPC task can be configured - * in the "Inter-Processor Call (IPC) task stack size" setting in menuconfig. - * Increase this setting if the given function requires more stack than default. + * - This function will block the target CPU's IPC task has begun execution of the callback + * - If another IPC call is ongoing, this function will block until the ongoing IPC call completes + * - The stack size of the IPC task can be configured via the CONFIG_ESP_IPC_TASK_STACK_SIZE option * * @note In single-core mode, returns ESP_ERR_INVALID_ARG for cpu_id 1. * @@ -63,17 +62,10 @@ esp_err_t esp_ipc_call(uint32_t cpu_id, esp_ipc_func_t func, void* arg); /** - * @brief Execute a function on the given CPU and blocks until it completes + * @brief Execute a callback on a given CPU until and block until it completes * - * Run a given function on a particular CPU. The given function must accept a - * void* argument and return void. The given function is run in the context of - * the IPC task of the CPU specified by the cpu_id parameter. The calling task - * will be blocked until the IPC task completes execution of the given function. - * If another IPC call is ongoing, the calling task will block until the other - * IPC call completes. The stack size allocated for the IPC task can be - * configured in the "Inter-Processor Call (IPC) task stack size" setting in - * menuconfig. Increase this setting if the given function requires more stack - * than default. + * This function is identical to esp_ipc_call() except that this function will block until the execution of the callback + * completes. * * @note In single-core mode, returns ESP_ERR_INVALID_ARG for cpu_id 1. * @@ -88,10 +80,8 @@ esp_err_t esp_ipc_call(uint32_t cpu_id, esp_ipc_func_t func, void* arg); */ esp_err_t esp_ipc_call_blocking(uint32_t cpu_id, esp_ipc_func_t func, void* arg); -#endif // not CONFIG_FREERTOS_UNICORE or CONFIG_APPTRACE_GCOV_ENABLE +#endif // !defined(CONFIG_FREERTOS_UNICORE) || defined(CONFIG_APPTRACE_GCOV_ENABLE) #ifdef __cplusplus } #endif - -#endif /* __ESP_IPC_H__ */ diff --git a/tools/sdk/esp32/include/esp_ipc/include/esp_ipc_isr.h b/tools/sdk/esp32/include/esp_ipc/include/esp_ipc_isr.h index 7b6e060f1d5..22fa5b10b03 100644 --- a/tools/sdk/esp32/include/esp_ipc/include/esp_ipc_isr.h +++ b/tools/sdk/esp32/include/esp_ipc/include/esp_ipc_isr.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -14,31 +14,24 @@ extern "C" { #ifdef CONFIG_ESP_IPC_ISR_ENABLE -/** @cond */ -typedef void (*esp_ipc_isr_func_t)(void* arg); -/** @endcond */ - /** - * @brief Initialize inter-processor call module which based on #4 high-interrupt. - * - * This function is called on CPU start and should not be called from the application. + * @brief IPC ISR Callback * - * This function starts two tasks, one on each CPU. These tasks register - * #4 High-interrupt and after that, the tasks are deleted. - * The next API functions work with this functionality: - * esp_ipc_isr_asm_call - * esp_ipc_isr_asm_call_blocking - * They allow to run an asm function on other CPU. + * A callback of this type should be provided as an argument when calling esp_ipc_isr_asm_call() or + * esp_ipc_isr_asm_call_blocking(). */ -void esp_ipc_isr_init(void); +typedef void (*esp_ipc_isr_func_t)(void* arg); /** - * @brief Execute an asm function on the other CPU (uses the #4 high-priority interrupt) + * @brief Execute an assembly callback on the other CPU + * + * Execute a given callback on the other CPU in the context of a High Priority Interrupt. + * + * - This function will busy-wait in a critical section until the other CPU has started execution of the callback + * - The callback must be written in assembly, is invoked using a CALLX0 instruction, and has a2, a3, a4 as scratch + * registers. See docs for more details * - * @note In single-core mode, it is not available. - * This function calls the #4 high-priority interrupt on the other CPU. - * The given function is called in the context of the interrupt by CALLX0 command and - * operates with registers a2, a3, a4. + * @note This function is not available in single-core mode. * * @param[in] func Pointer to a function of type void func(void* arg) to be executed * @param[in] arg Arbitrary argument of type void* to be passed into the function @@ -46,11 +39,12 @@ void esp_ipc_isr_init(void); void esp_ipc_isr_asm_call(esp_ipc_isr_func_t func, void* arg); /** - * @brief Execute an asm function on the other CPU and blocks until it completes (uses the #4 high-priority interrupt) + * @brief Execute an assembly callback on the other CPU and busy-wait until it completes * - * @note In single-core mode, it is not available. - * This function calls the #4 high-priority interrupt on the other CPU. - * The given function is called in the context of the interrupt by CALLX0 command. + * This function is identical to esp_ipc_isr_asm_call() except that this function will busy-wait until the execution of + * the callback completes. + * + * @note This function is not available in single-core mode. * * @param[in] func Pointer to a function of type void func(void* arg) to be executed * @param[in] arg Arbitrary argument of type void* to be passed into the function @@ -58,51 +52,60 @@ void esp_ipc_isr_asm_call(esp_ipc_isr_func_t func, void* arg); void esp_ipc_isr_asm_call_blocking(esp_ipc_isr_func_t func, void* arg); /** - * @brief Stall the other CPU and the current CPU disables interrupts with level 3 and lower. + * @brief Stall the other CPU * - * @note In single-core mode, it is not available. - * This function calls the #4 high-priority interrupt on the other CPU. - * The esp_ipc_isr_finish_cmd() function is called on the other CPU in the context of the #4 high-priority interrupt. - * The esp_ipc_isr_finish_cmd is called by CALLX0 command. - * It is waiting for the end command. The command will be sent by esp_ipc_isr_release_other_cpu(). - * This function is used for DPORT workaround. + * This function will stall the other CPU. The other CPU is stalled by busy-waiting in the context of a High Priority + * Interrupt. The other CPU will not be resumed until esp_ipc_isr_release_other_cpu() is called. * - * This function blocks other CPU until the release call esp_ipc_isr_release_other_cpu(). + * - This function is internally implemented using IPC ISR + * - This function is used for DPORT workaround. + * - If the stall feature is paused using esp_ipc_isr_stall_pause(), this function will have no effect * - * This fucntion is used for the DPORT workaround: stall other cpu that this cpu is pending to access dport register start. + * @note This function is not available in single-core mode. */ void esp_ipc_isr_stall_other_cpu(void); /** * @brief Release the other CPU * - * @note In single-core mode, it is not available. - * This function will send the end command to release the stall other CPU. - * This function is used for DPORT workaround: stall other cpu that this cpu is pending to access dport register end. + * This function will release the other CPU that was previously stalled from calling esp_ipc_isr_stall_other_cpu() + * + * - This function is used for DPORT workaround. + * - If the stall feature is paused using esp_ipc_isr_stall_pause(), this function will have no effect * + * @note This function is not available in single-core mode. */ void esp_ipc_isr_release_other_cpu(void); /** - * @brief Pause stall the other CPU + * @brief Puase the CPU stall feature + * + * This function will pause the CPU stall feature. Once paused, calls to esp_ipc_isr_stall_other_cpu() and + * esp_ipc_isr_release_other_cpu() will have no effect. If a IPC ISR call is already in progress, this function will + * busy-wait until the call completes before pausing the CPU stall feature. */ void esp_ipc_isr_stall_pause(void); /** - * @brief Abort stall the other CPU + * @brief Abort a CPU stall * - * This routine does not stop the stall routines in any way that is recoverable. - * Please only call in case of panic(). - * Used in panic code: the enter_critical stuff may be messed up so we just stop everything without checking the mux. + * This function will abort any stalling routine of the other CPU due to a pervious call to + * esp_ipc_isr_stall_other_cpu(). This function aborts the stall in a non-recoverable manner, thus should only be called + * in case of a panic(). + * + * - This function is used in panic handling code */ void esp_ipc_isr_stall_abort(void); /** - * @brief Resume stall the other CPU + * @brief Resume the CPU stall feature + * + * This function will resume the CPU stall feature that was previously paused by calling esp_ipc_isr_stall_pause(). Once + * resumed, calls to esp_ipc_isr_stall_other_cpu() and esp_ipc_isr_release_other_cpu() will have effect again. */ void esp_ipc_isr_stall_resume(void); -#else // not CONFIG_ESP_IPC_ISR_ENABLE +#else // CONFIG_ESP_IPC_ISR_ENABLE #define esp_ipc_isr_stall_other_cpu() #define esp_ipc_isr_release_other_cpu() diff --git a/tools/sdk/esp32/include/esp_lcd/include/esp_lcd_panel_rgb.h b/tools/sdk/esp32/include/esp_lcd/include/esp_lcd_panel_rgb.h index 0c264545ee2..6f06deb8165 100644 --- a/tools/sdk/esp32/include/esp_lcd/include/esp_lcd_panel_rgb.h +++ b/tools/sdk/esp32/include/esp_lcd/include/esp_lcd_panel_rgb.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -64,7 +64,7 @@ typedef struct { unsigned int hsync_idle_low: 1; /*!< The hsync signal is low in IDLE state */ unsigned int vsync_idle_low: 1; /*!< The vsync signal is low in IDLE state */ unsigned int de_idle_high: 1; /*!< The de signal is high in IDLE state */ - unsigned int pclk_active_neg: 1; /*!< The display will write data lines when there's a falling edge on PCLK */ + unsigned int pclk_active_neg: 1; /*!< Whether the display data is clocked out at the falling edge of PCLK */ unsigned int pclk_idle_high: 1; /*!< The PCLK stays at high level in IDLE phase */ } flags; } esp_lcd_rgb_timing_t; @@ -92,6 +92,8 @@ typedef struct { lcd_clock_source_t clk_src; /*!< Clock source for the RGB LCD peripheral */ esp_lcd_rgb_timing_t timings; /*!< RGB timing parameters */ size_t data_width; /*!< Number of data lines */ + size_t sram_trans_align; /*!< Alignment for framebuffer that allocated in SRAM */ + size_t psram_trans_align; /*!< Alignment for framebuffer that allocated in PSRAM */ int hsync_gpio_num; /*!< GPIO used for HSYNC signal */ int vsync_gpio_num; /*!< GPIO used for VSYNC signal */ int de_gpio_num; /*!< GPIO used for DE signal, set to -1 if it's not used */ diff --git a/tools/sdk/esp32/include/esp_littlefs/include/esp_littlefs.h b/tools/sdk/esp32/include/esp_littlefs/include/esp_littlefs.h index 7b5abe9248f..07f35231291 100644 --- a/tools/sdk/esp32/include/esp_littlefs/include/esp_littlefs.h +++ b/tools/sdk/esp32/include/esp_littlefs/include/esp_littlefs.h @@ -1,24 +1,9 @@ #ifndef ESP_LITTLEFS_H__ #define ESP_LITTLEFS_H__ -#include -#include -#include -#include -#include -#include "freertos/FreeRTOS.h" -#include "freertos/semphr.h" #include "esp_err.h" -#include -#include -#include -#include -#include -#include -#include -#include "sdkconfig.h" - #include "littlefs/lfs.h" +#include "sdkconfig.h" #ifdef __cplusplus extern "C" { diff --git a/tools/sdk/esp32/include/esp_phy/include/phy.h b/tools/sdk/esp32/include/esp_phy/include/phy.h index e6aa21db50e..c8d1018288d 100644 --- a/tools/sdk/esp32/include/esp_phy/include/phy.h +++ b/tools/sdk/esp32/include/esp_phy/include/phy.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -99,6 +99,13 @@ void phy_freq_mem_backup(bool backup_en, uint32_t *mem); void phy_bbpll_en_usb(bool en); #endif +#if CONFIG_IDF_TARGET_ESP32S2 +/** + * @brief Phy version select for ESP32S2 + */ +void phy_eco_version_sel(uint8_t chip_ver); +#endif + #ifdef __cplusplus } #endif diff --git a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_core.h b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_core.h index 86625f0beb3..9dbdbae658b 100644 --- a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_core.h +++ b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_core.h @@ -24,10 +24,13 @@ extern "C" #define ESP_RMAKER_CONFIG_VERSION "2020-03-20" -#define MAX_VERSION_STRING_LEN 16 +/* Maximum length of the alert message that can be passed to esp_rmaker_raise_alert() */ +#define ESP_RMAKER_MAX_ALERT_LEN 100 +/** @cond **/ /** ESP RainMaker Event Base */ ESP_EVENT_DECLARE_BASE(RMAKER_EVENT); +/** @endcond **/ /** ESP RainMaker Events */ typedef enum { @@ -39,14 +42,15 @@ typedef enum { RMAKER_EVENT_CLAIM_SUCCESSFUL, /** Self Claiming Failed */ RMAKER_EVENT_CLAIM_FAILED, - /** Node reboot has been triggered. The associated event data is the time in seconds - * (type: uint8_t) after which the node will reboot. Note that this time may not be - * accurate as the events are received asynchronously.*/ - RMAKER_EVENT_REBOOT, - /** Wi-Fi credentials reset. Triggered after calling esp_rmaker_wifi_reset() */ - RMAKER_EVENT_WIFI_RESET, - /** Node reset to factory defaults. Triggered after calling esp_rmaker_factory_reset() */ - RMAKER_EVENT_FACTORY_RESET + /** Node side communication for User-Node mapping done. + * Actual mapping state will be managed by the ESP RainMaker cloud based on the user side communication. + * Associated data is the NULL terminated user id. + */ + RMAKER_EVENT_USER_NODE_MAPPING_DONE, + /** Local control started. Associated data is the NULL terminated Service Name */ + RMAKER_EVENT_LOCAL_CTRL_STARTED, + /* User reset request successfully sent to ESP RainMaker Cloud */ + RMAKER_EVENT_USER_NODE_MAPPING_RESET, } esp_rmaker_event_t; /** ESP RainMaker Node information */ @@ -116,6 +120,18 @@ typedef enum { PROP_FLAG_PERSIST = (1 << 3) } esp_param_property_flags_t; +/** System Service Reboot Flag */ +#define SYSTEM_SERV_FLAG_REBOOT (1 << 0) + +/** System Service Factory Reset Flag */ +#define SYSTEM_SERV_FLAG_FACTORY_RESET (1 << 1) + +/** System Service Wi-Fi Reset Flag */ +#define SYSTEM_SERV_FLAG_WIFI_RESET (1 << 2) + +/** System Service All Flags */ +#define SYSTEM_SERV_FLAGS_ALL (SYSTEM_SERV_FLAG_REBOOT | SYSTEM_SERV_FLAG_FACTORY_RESET | SYSTEM_SERV_FLAG_WIFI_RESET) + /** Generic ESP RainMaker handle */ typedef size_t esp_rmaker_handle_t; @@ -138,6 +154,16 @@ typedef enum { ESP_RMAKER_REQ_SRC_CLOUD, /** Request received when a schedule has triggered */ ESP_RMAKER_REQ_SRC_SCHEDULE, + /** Request received when a scene has been activated */ + ESP_RMAKER_REQ_SRC_SCENE_ACTIVATE, + /** Request received when a scene has been deactivated */ + ESP_RMAKER_REQ_SRC_SCENE_DEACTIVATE, + /** Request received from a local controller */ + ESP_RMAKER_REQ_SRC_LOCAL, + /** This will always be the last value. Any value equal to or + * greater than this should be considered invalid. + */ + ESP_RMAKER_REQ_SRC_MAX, } esp_rmaker_req_src_t; /** Write request Context */ @@ -152,6 +178,32 @@ typedef struct { esp_rmaker_req_src_t src; } esp_rmaker_read_ctx_t; +/** System service configuration */ +typedef struct { + /** Logical OR of system service flags (SYSTEM_SERV_FLAG_REBOOT, + * SYSTEM_SERV_FLAG_FACTORY_RESET, SYSTEM_SERV_FLAG_WIFI_RESET) as required + * or SYSTEM_SERV_FLAGS_ALL. + */ + uint16_t flags; + /** Time in seconds after which the device should reboot. + * Value of zero would trigger an immediate reboot if a write is received for + * the Reboot parameter. + * Recommended value: 2 + */ + int8_t reboot_seconds; + /** Time in seconds after which the device should reset (Wi-Fi or factory). + * Value of zero would trigger an immediate action if a write is received for + * the Wi-Fi reset or Factory reset parameter. + * Recommended value: 2 + */ + int8_t reset_seconds; + /** Time in seconds after which the device should reboot after it has been reset. + * Value of zero would mean that there won't be any reboot after the reset. + * Recommended value: 2 + */ + int8_t reset_reboot_seconds; +} esp_rmaker_system_serv_config_t; + /** Callback for parameter value write requests. * * The callback should call the esp_rmaker_param_update_and_report() API if the new value is to be set @@ -188,6 +240,28 @@ typedef esp_err_t (*esp_rmaker_device_write_cb_t)(const esp_rmaker_device_t *dev typedef esp_err_t (*esp_rmaker_device_read_cb_t)(const esp_rmaker_device_t *device, const esp_rmaker_param_t *param, void *priv_data, esp_rmaker_read_ctx_t *ctx); +/** Convert device callback source to string + * + * Device read/write callback can be via different sources. This is a helper API + * to give the source in string format for printing. + * + * Example Usage: + * @code{c} + * static esp_err_t write_cb(const esp_rmaker_device_t *device, const esp_rmaker_param_t *param, + * const esp_rmaker_param_val_t val, void *priv_data, esp_rmaker_write_ctx_t *ctx) +{ + if (ctx) { + ESP_LOGI(TAG, "Received write request via : %s", esp_rmaker_device_cb_src_to_str(ctx->src)); + } + * @endcode + * + * @param[in] src The src field as received in the callback context. + * + * @return NULL terminated source string on success + * @return NULL on failure + */ +const char *esp_rmaker_device_cb_src_to_str(esp_rmaker_req_src_t src); + /** * Initialise a Boolean value * @@ -311,7 +385,7 @@ esp_err_t esp_rmaker_node_deinit(const esp_rmaker_node_t *node); const esp_rmaker_node_t *esp_rmaker_get_node(void); /** Get Node Id - * + * * Returns pointer to the NULL terminated Node ID string. * * @return Pointer to a NULL terminated Node ID string. @@ -458,12 +532,24 @@ esp_err_t esp_rmaker_node_add_device(const esp_rmaker_node_t *node, const esp_rm */ esp_err_t esp_rmaker_node_remove_device(const esp_rmaker_node_t *node, const esp_rmaker_device_t *device); +/** Get device by name + * + * Get handle for a device based on the name. + * + * @param[in] node Node handle. + * @param[in] device_name Device name to search. + * + * @return Device handle on success. + * @return NULL in case of failure. + */ +esp_rmaker_device_t *esp_rmaker_node_get_device_by_name(const esp_rmaker_node_t *node, const char *device_name); + /** Add a Device attribute * * @note Device attributes are reported only once after a boot-up as part of the node * configuration. * Eg. Serial Number - * + * * @param[in] device Device handle. * @param[in] attr_name Name of the attribute. * @param[in] val Value of the attribute. @@ -473,6 +559,19 @@ esp_err_t esp_rmaker_node_remove_device(const esp_rmaker_node_t *node, const esp */ esp_err_t esp_rmaker_device_add_attribute(const esp_rmaker_device_t *device, const char *attr_name, const char *val); +/** Add a Device subtype + * + * This can be something like esp.subtype.rgb-light for a device of type esp.device.lightbulb. + * This would primarily be used by the phone apps to render different icons for the same device type. + * + * @param[in] device Device handle. + * @param[in] subtype String describing the sub type. + * + * @return ESP_OK if the subtype was added successfully. + * @return error in case of failure. + */ +esp_err_t esp_rmaker_device_add_subtype(const esp_rmaker_device_t *device, const char *subtype); + /** Get device name from handle * * @param[in] device Device handle. @@ -489,7 +588,7 @@ char *esp_rmaker_device_get_name(const esp_rmaker_device_t *device); * @return NULL terminated device type string on success. * @return NULL in case of failure, or if the type wasn't provided while creating the device. */ -char *esp_rmaker_device_get_name(const esp_rmaker_device_t *device); +char *esp_rmaker_device_get_type(const esp_rmaker_device_t *device); /** * Add a parameter to a device/service @@ -638,6 +737,30 @@ esp_err_t esp_rmaker_param_add_valid_str_list(const esp_rmaker_param_t *param, c */ esp_err_t esp_rmaker_param_add_array_max_count(const esp_rmaker_param_t *param, int count); + +/* Update a parameter + * + * This will just update the value of a parameter with esp rainmaker core, without actually reporting + * it. This can be used when multiple parameters need to be reported together. + * Eg. If x parameters are to be reported, this API can be used for the first x -1 parameters + * and the last one can be updated using esp_rmaker_param_update_and_report(). + * This will report all parameters which were updated prior to this call. + * + * Sample: + * + * esp_rmaker_param_update(param1, esp_rmaker_float(10.2)); + * esp_rmaker_param_update(param2, esp_rmaker_int(55)); + * esp_rmaker_param_update(param3, esp_rmaker_int(95)); + * esp_rmaker_param_update_and_report(param1, esp_rmaker_bool(true)); + * + * @param[in] param Parameter handle. + * @param[in] val New value of the parameter. + * + * @return ESP_OK if the parameter was updated successfully. + * @return error in case of failure. + */ +esp_err_t esp_rmaker_param_update(const esp_rmaker_param_t *param, esp_rmaker_param_val_t val); + /** Update and report a parameter * * Calling this API will update the parameter and report it to ESP RainMaker cloud. @@ -651,6 +774,46 @@ esp_err_t esp_rmaker_param_add_array_max_count(const esp_rmaker_param_t *param, */ esp_err_t esp_rmaker_param_update_and_report(const esp_rmaker_param_t *param, esp_rmaker_param_val_t val); +/** Update and notify a parameter + * + * Calling this API will update the parameter and report it to ESP RainMaker cloud similar to + * esp_rmaker_param_update_and_report(). However, additionally, it will also trigger a notification + * on the phone apps (if enabled). + * + * @note This should be used only when some local change requires explicit notification even when the + * phone app is in background, not otherwise. + * Eg. Alarm got triggered, temperature exceeded some threshold, etc. + * + * Alternatively, the esp_rmaker_raise_alert() API can also be used to trigger notification + * on the phone apps with pre-formatted text. + * + * @param[in] param Parameter handle. + * @param[in] val New value of the parameter. + * + * @return ESP_OK if the parameter was updated successfully. + * @return error in case of failure. + */ +esp_err_t esp_rmaker_param_update_and_notify(const esp_rmaker_param_t *param, esp_rmaker_param_val_t val); + +/** Trigger an alert on the phone app + * + * This API will trigger a notification alert on the phone apps (if enabled) using the formatted text + * provided. Note that this does not send a notification directly to the phone, but reports the alert + * to the ESP RainMaker cloud which then uses the Notification framework to send notifications to the + * phone apps. The value does not get stored anywhere, nor is it linked to any node parameters. + * + * @note This should be used only if some event requires explicitly alerting the user even when the + * phone app is in background, not otherwise. + * Eg. "Motion Detected", "Fire alarm triggered" + * + * @param[in] alert_str NULL terminated pre-formatted alert string. + * Maximum length can be ESP_RMAKER_MAX_ALERT_LEN, excluding NULL character. + * + * @return ESP_OK on success. + * @return error in case of failure. + */ +esp_err_t esp_rmaker_raise_alert(const char *alert_str); + /** Get parameter name from handle * * @param[in] param Parameter handle. @@ -669,11 +832,18 @@ char *esp_rmaker_param_get_name(const esp_rmaker_param_t *param); */ char *esp_rmaker_param_get_type(const esp_rmaker_param_t *param); -/** Prototype for ESP RainMaker Work Queue Function +/** Get parameter value * - * @param[in] priv_data The private data associated with the work function. + * This gives the parameter value that is stored in the RainMaker core. + * + * @note This does not call any explicit functions to read value from hardware/driver. + * + * @param[in] param Parameter handle + * + * @return Pointer to parameter value on success. + * @return NULL in case of failure. */ -typedef void (*esp_rmaker_work_fn_t)(void *priv_data); +esp_rmaker_param_val_t *esp_rmaker_param_get_val(esp_rmaker_param_t *param); /** Report the node details to the cloud * @@ -689,17 +859,38 @@ typedef void (*esp_rmaker_work_fn_t)(void *priv_data); */ esp_err_t esp_rmaker_report_node_details(void); -/** Queue execution of a function in ESP RainMaker's context +/** Enable Timezone Service + * + * This enables the ESP RainMaker standard timezone service which can be used to set + * timezone, either in POSIX or location string format. Please refer the specifications + * for additional details. + * + * @return ESP_OK on success + * @return error on failure + */ +esp_err_t esp_rmaker_timezone_service_enable(void); + +/** Enable System Service * - * This API queues a work function for execution in the ESP RainMaker Task's context. + * This enables the ESP RainMaker standard system service which can be + * used for operations like reboot, factory reset and Wi-Fi reset. * - * @param[in] work_fn The Work function to be queued. - * @param[in] priv_data Private data to be passed to the work function. + * Please refer the specifications for additional details. * - * @return ESP_OK on success. - * @return error in case of failure. + * @param[in] config Configuration for the system service. + * + * @return ESP_OK on success + * @return error on failure + */ +esp_err_t esp_rmaker_system_service_enable(esp_rmaker_system_serv_config_t *config); + +/** + * Check if local_ctrl service has started + * + * @return true if service has started + * @return false if the service has not started */ -esp_err_t esp_rmaker_queue_work(esp_rmaker_work_fn_t work_fn, void *priv_data); +bool esp_rmaker_local_ctrl_service_started(void); #ifdef __cplusplus } diff --git a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_mqtt.h b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_mqtt.h index cb724829dae..1cc6cd5156e 100644 --- a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_mqtt.h +++ b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_mqtt.h @@ -14,34 +14,14 @@ #pragma once #include #include +#include #ifdef __cplusplus extern "C" { #endif -/** ESP RainMaker MQTT Configuration */ -typedef struct { - /** MQTT Host */ - char *mqtt_host; - /** Client ID */ - char *client_id; - /** Client Certificate in NULL terminate PEM format */ - char *client_cert; - /** Client Key in NULL terminate PEM format */ - char *client_key; - /** Server Certificate in NULL terminate PEM format */ - char *server_cert; -} esp_rmaker_mqtt_config_t; - -/** ESP RainMaker MQTT Subscribe callback prototype - * - * @param[in] topic Topic on which the message was received - * @param[in] payload Data received in the message - * @param[in] payload_len Length of the data - * @param[in] priv_data The private data passed during subscription - */ -typedef void (*esp_rmaker_mqtt_subscribe_cb_t) (const char *topic, void *payload, size_t payload_len, void *priv_data); +esp_rmaker_mqtt_conn_params_t *esp_rmaker_mqtt_get_conn_params(void); /** Initialize ESP RainMaker MQTT * @@ -50,7 +30,7 @@ typedef void (*esp_rmaker_mqtt_subscribe_cb_t) (const char *topic, void *payload * @return ESP_OK on success. * @return error in case of any error. */ -esp_err_t esp_rmaker_mqtt_init(esp_rmaker_mqtt_config_t *config); +esp_err_t esp_rmaker_mqtt_init(esp_rmaker_mqtt_conn_params_t *conn_params); /** MQTT Connect * @@ -77,22 +57,24 @@ esp_err_t esp_rmaker_mqtt_disconnect(void); * @param[in] topic The MQTT topic on which the message should be published. * @param[in] data Data to be published * @param[in] data_len Length of the data + * @param[in] qos Quality of Service for the Publish. Can be 0, 1 or 2. Also depends on what the MQTT broker supports. * * @return ESP_OK on success. * @return error in case of any error. */ -esp_err_t esp_rmaker_mqtt_publish(const char *topic, void *data, size_t data_len); +esp_err_t esp_rmaker_mqtt_publish(const char *topic, void *data, size_t data_len, uint8_t qos, int *msg_id); /** Subscribe to MQTT topic * * @param[in] topic The topic to be subscribed to. * @param[in] cb The callback to be invoked when a message is received on the given topic. * @param[in] priv_data Optional private data to be passed to the callback + * @param[in] qos Quality of Service for the Subscription. Can be 0, 1 or 2. Also depends on what the MQTT broker supports. * * @return ESP_OK on success. * @return error in case of any error. */ -esp_err_t esp_rmaker_mqtt_subscribe(const char *topic, esp_rmaker_mqtt_subscribe_cb_t cb, void *priv_data); +esp_err_t esp_rmaker_mqtt_subscribe(const char *topic, esp_rmaker_mqtt_subscribe_cb_t cb, uint8_t qos, void *priv_data); /** Unsubscribe from MQTT topic * @@ -102,7 +84,7 @@ esp_err_t esp_rmaker_mqtt_subscribe(const char *topic, esp_rmaker_mqtt_subscribe * @return error in case of any error. */ esp_err_t esp_rmaker_mqtt_unsubscribe(const char *topic); - +esp_err_t esp_rmaker_mqtt_setup(esp_rmaker_mqtt_config_t mqtt_config); #ifdef __cplusplus } #endif diff --git a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_ota.h b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_ota.h index 2def84ebc5d..e66b95705bc 100644 --- a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_ota.h +++ b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_ota.h @@ -104,7 +104,7 @@ typedef struct { * The certificate to be passed to the OTA callback for server authentication. * This is mandatory, unless you have disabled it in ESP HTTPS OTA config option. * If you are using the ESP RainMaker OTA Service, you can just set this to - * `ESP_RMAKER_DEFAULT_OTA_SERVER_CERT`. + * `ESP_RMAKER_OTA_DEFAULT_SERVER_CERT`. */ const char *server_cert; /** Private Data. diff --git a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_scenes.h b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_scenes.h new file mode 100644 index 00000000000..f2f81f51a02 --- /dev/null +++ b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_scenes.h @@ -0,0 +1,38 @@ +// Copyright 2022 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include + +/** Enable Scenes + * + * This API enables the scenes service for the node. For more information, + * check [here](https://rainmaker.espressif.com/docs/scenes.html) + * + * @note This API should be called after esp_rmaker_node_init() but before esp_rmaker_start(). + * + * @return ESP_OK on success. + * @return error in case of failure. + */ +esp_err_t esp_rmaker_scenes_enable(void); + +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_schedule.h b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_schedule.h index 6d63a5b78da..383c0949188 100644 --- a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_schedule.h +++ b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_schedule.h @@ -26,6 +26,8 @@ extern "C" * * It is recommended to set the timezone while using schedules. Check [here](https://rainmaker.espressif.com/docs/time-service.html#time-zone) for more information on timezones * + * @note This API should be called after esp_rmaker_node_init() but before esp_rmaker_start(). + * * @return ESP_OK on success. * @return error in case of failure. */ diff --git a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_standard_params.h b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_standard_params.h index 5a5ad856b80..944118c0f68 100644 --- a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_standard_params.h +++ b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_standard_params.h @@ -45,6 +45,12 @@ extern "C" #define ESP_RMAKER_DEF_TIMEZONE_NAME "TZ" #define ESP_RMAKER_DEF_TIMEZONE_POSIX_NAME "TZ-POSIX" #define ESP_RMAKER_DEF_SCHEDULE_NAME "Schedules" +#define ESP_RMAKER_DEF_SCENES_NAME "Scenes" +#define ESP_RMAKER_DEF_REBOOT_NAME "Reboot" +#define ESP_RMAKER_DEF_FACTORY_RESET_NAME "Factory-Reset" +#define ESP_RMAKER_DEF_WIFI_RESET_NAME "Wi-Fi-Reset" +#define ESP_RMAKER_DEF_LOCAL_CONTROL_POP "POP" +#define ESP_RMAKER_DEF_LOCAL_CONTROL_TYPE "Type" /** * Create standard name param @@ -247,7 +253,7 @@ esp_rmaker_param_t *esp_rmaker_timezone_param_create(const char *param_name, con esp_rmaker_param_t *esp_rmaker_timezone_posix_param_create(const char *param_name, const char *val); /** - * Create standard schedules param + * Create standard Schedules param * * This will create the standard schedules parameter. Default value * is set internally. @@ -260,6 +266,85 @@ esp_rmaker_param_t *esp_rmaker_timezone_posix_param_create(const char *param_nam */ esp_rmaker_param_t *esp_rmaker_schedules_param_create(const char *param_name, int max_schedules); +/** + * Create standard Scenes param + * + * This will create the standard scenes parameter. Default value + * is set internally. + * + * @param[in] param_name Name of the parameter + * @param[in] max_scenes Maximum number of scenes allowed + * + * @return Parameter handle on success. + * @return NULL in case of failures. + */ +esp_rmaker_param_t *esp_rmaker_scenes_param_create(const char *param_name, int max_scenes); + +/** + * Create standard Reboot param + * + * This will create the standard reboot parameter. + * Set value to true (via write param) for the action to trigger. + * + * @param[in] param_name Name of the parameter + * + * @return Parameter handle on success. + * @return NULL in case of failures. + */ +esp_rmaker_param_t *esp_rmaker_reboot_param_create(const char *param_name); + +/** + * Create standard Factory Reset param + * + * This will create the standard factory reset parameter. + * Set value to true (via write param) for the action to trigger. + * + * @param[in] param_name Name of the parameter + * + * @return Parameter handle on success. + * @return NULL in case of failures. + */ +esp_rmaker_param_t *esp_rmaker_factory_reset_param_create(const char *param_name); + +/** + * Create standard Wi-Fi Reset param + * + * This will create the standard Wi-Fi Reset parameter. + * Set value to true (via write param) for the action to trigger. + * + * @param[in] param_name Name of the parameter + * + * @return Parameter handle on success. + * @return NULL in case of failures. + */ +esp_rmaker_param_t *esp_rmaker_wifi_reset_param_create(const char *param_name); + +/** + * Create standard Local Control POP param + * + * This will create the standard Local Control POP parameter. + * + * @param[in] param_name Name of the parameter + * @param[in] val Default Value of the parameter (Eg. "abcd1234"). Can be kept NULL. + * + * @return Parameter handle on success. + * @return NULL in case of failures. + */ +esp_rmaker_param_t *esp_rmaker_local_control_pop_param_create(const char *param_name, const char *val); + +/** + * Create standard Local Control Type param + * + * This will create the standard Local Control security type parameter. + * + * @param[in] param_name Name of the parameter + * @param[in] val Default Value of the parameter + * + * @return Parameter handle on success. + * @return NULL in case of failures. + */ +esp_rmaker_param_t *esp_rmaker_local_control_type_param_create(const char *param_name, int val); + #ifdef __cplusplus } #endif diff --git a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_standard_services.h b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_standard_services.h index 348505c1486..687df733f46 100644 --- a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_standard_services.h +++ b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_standard_services.h @@ -71,6 +71,54 @@ esp_rmaker_device_t *esp_rmaker_time_service_create(const char *serv_name, const */ esp_rmaker_device_t *esp_rmaker_create_schedule_service(const char *serv_name, esp_rmaker_device_write_cb_t write_cb, esp_rmaker_device_read_cb_t read_cb, int max_schedules, void *priv_data); +/** Create a standard Scenes service + * + * This creates a Scenes service with the mandatory parameters. The default parameter names will be used. + * Refer \ref esp_rmaker_standard_params.h for default names. + * + * @param[in] serv_name The unique service name + * @param[in] write_cb Write callback. + * @param[in] read_cb Read callback. + * @param[in] max_scenes Maximum number of scenes supported. + * @param[in] deactivation_support Deactivation callback support. + * @param[in] priv_data (Optional) Private data associated with the service. This should stay + * allocated throughout the lifetime of the service. + * + * @return service_handle on success. + * @return NULL in case of any error. + */ +esp_rmaker_device_t *esp_rmaker_create_scenes_service(const char *serv_name, esp_rmaker_device_write_cb_t write_cb, esp_rmaker_device_read_cb_t read_cb, int max_scenes, bool deactivation_support, void *priv_data); + +/** Create a standard System service + * + * This creates an empty System service. Appropriate parameters should be added by the caller. + * + * @param[in] serv_name The unique service name + * @param[in] priv_data (Optional) Private data associated with the service. This should stay + * allocated throughout the lifetime of the service. + * + * @return service_handle on success. + * @return NULL in case of any error. + */ + +esp_rmaker_device_t *esp_rmaker_create_system_service(const char *serv_name, void *priv_data); + +/** Create a standard Local Control service + * + * This creates a Local Control service with the mandatory parameters. The default parameter names will be used. + * Refer \ref esp_rmaker_standard_params.h for default names. + * + * @param[in] serv_name The unique service name + * @param[in] pop Proof of possession + * @param[in] sec_type Security type + * @param[in] priv_data (Optional) Private data associated with the service. This should stay + * allocated throughout the lifetime of the service. + * + * @return service_handle on success. + * @return NULL in case of any error. + */ +esp_rmaker_device_t *esp_rmaker_create_local_control_service(const char *serv_name, const char *pop, int sec_type, void *priv_data); + #ifdef __cplusplus } #endif diff --git a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_standard_types.h b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_standard_types.h index 73cbec85b89..4dc99eab401 100644 --- a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_standard_types.h +++ b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_standard_types.h @@ -24,7 +24,7 @@ extern "C" #define ESP_RMAKER_UI_SLIDER "esp.ui.slider" #define ESP_RMAKER_UI_DROPDOWN "esp.ui.dropdown" #define ESP_RMAKER_UI_TEXT "esp.ui.text" - +#define ESP_RMAKER_UI_HUE_SLIDER "esp.ui.hue-slider" /********** STANDARD PARAM TYPES **********/ @@ -44,6 +44,12 @@ extern "C" #define ESP_RMAKER_PARAM_TIMEZONE "esp.param.tz" #define ESP_RMAKER_PARAM_TIMEZONE_POSIX "esp.param.tz_posix" #define ESP_RMAKER_PARAM_SCHEDULES "esp.param.schedules" +#define ESP_RMAKER_PARAM_SCENES "esp.param.scenes" +#define ESP_RMAKER_PARAM_REBOOT "esp.param.reboot" +#define ESP_RMAKER_PARAM_FACTORY_RESET "esp.param.factory-reset" +#define ESP_RMAKER_PARAM_WIFI_RESET "esp.param.wifi-reset" +#define ESP_RMAKER_PARAM_LOCAL_CONTROL_POP "esp.param.local_control_pop" +#define ESP_RMAKER_PARAM_LOCAL_CONTROL_TYPE "esp.param.local_control_type" /********** STANDARD DEVICE TYPES **********/ @@ -58,6 +64,9 @@ extern "C" #define ESP_RMAKER_SERVICE_OTA "esp.service.ota" #define ESP_RMAKER_SERVICE_TIME "esp.service.time" #define ESP_RMAKER_SERVICE_SCHEDULE "esp.service.schedule" +#define ESP_RMAKER_SERVICE_SCENES "esp.service.scenes" +#define ESP_RMAKER_SERVICE_SYSTEM "esp.service.system" +#define ESP_RMAKER_SERVICE_LOCAL_CONTROL "esp.service.local_control" #ifdef __cplusplus } diff --git a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_user_mapping.h b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_user_mapping.h index a763561f3c2..77a153b02f2 100644 --- a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_user_mapping.h +++ b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_user_mapping.h @@ -19,6 +19,25 @@ extern "C" { #endif +/** User-Node Mapping states */ +typedef enum { + /** Mapping does not exist or is not initialized */ + ESP_RMAKER_USER_MAPPING_RESET = 0, + /** Mapping has started */ + ESP_RMAKER_USER_MAPPING_STARTED, + /** Mapping is done */ + ESP_RMAKER_USER_MAPPING_DONE, +} esp_rmaker_user_mapping_state_t; + +/** + * Get User-Node mapping state + * + * This returns the current user-node mapping state. + * + * @return user mapping state + */ +esp_rmaker_user_mapping_state_t esp_rmaker_user_node_mapping_get_state(void); + /** * Create User Mapping Endpoint * diff --git a/tools/sdk/esp32/include/esp_rom/include/esp32/rom/secure_boot.h b/tools/sdk/esp32/include/esp_rom/include/esp32/rom/secure_boot.h index 1eb69e25378..50a3fcd4948 100644 --- a/tools/sdk/esp32/include/esp_rom/include/esp32/rom/secure_boot.h +++ b/tools/sdk/esp32/include/esp_rom/include/esp32/rom/secure_boot.h @@ -1,21 +1,12 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include "sdkconfig.h" -#ifndef _ROM_SECURE_BOOT_H_ -#define _ROM_SECURE_BOOT_H_ +#pragma once #include #include "ets_sys.h" @@ -128,5 +119,3 @@ bool ets_use_secure_boot_v2(void); #ifdef __cplusplus } #endif - -#endif /* _ROM_SECURE_BOOT_H_ */ diff --git a/tools/sdk/esp32/include/esp_rom/include/esp32c3/rom/secure_boot.h b/tools/sdk/esp32/include/esp_rom/include/esp32c3/rom/secure_boot.h index 71cf7250d29..a9d417283b7 100644 --- a/tools/sdk/esp32/include/esp_rom/include/esp32c3/rom/secure_boot.h +++ b/tools/sdk/esp32/include/esp_rom/include/esp32c3/rom/secure_boot.h @@ -1,19 +1,10 @@ -// Copyright 2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef _ROM_SECURE_BOOT_H_ -#define _ROM_SECURE_BOOT_H_ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once #include #include @@ -24,9 +15,6 @@ extern "C" { #endif -struct ets_secure_boot_sig_block; -struct ets_secure_boot_signature_t; - typedef struct ets_secure_boot_sig_block ets_secure_boot_sig_block_t; typedef struct ets_secure_boot_signature ets_secure_boot_signature_t; typedef struct ets_secure_boot_key_digests ets_secure_boot_key_digests_t; @@ -127,5 +115,3 @@ struct ets_secure_boot_key_digests { #ifdef __cplusplus } #endif - -#endif /* _ROM_SECURE_BOOT_H_ */ diff --git a/tools/sdk/esp32/include/esp_rom/include/esp32h2/rom/rtc.h b/tools/sdk/esp32/include/esp_rom/include/esp32h2/rom/rtc.h index ad4f45c2ca7..e3a8d9d63e2 100644 --- a/tools/sdk/esp32/include/esp_rom/include/esp32h2/rom/rtc.h +++ b/tools/sdk/esp32/include/esp_rom/include/esp32h2/rom/rtc.h @@ -1,16 +1,8 @@ -// Copyright 2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #ifndef _ROM_RTC_H_ #define _ROM_RTC_H_ @@ -124,7 +116,7 @@ _Static_assert((soc_reset_reason_t)EFUSE_RESET == RESET_REASON_CORE_EFUSE_CRC, " _Static_assert((soc_reset_reason_t)USB_UART_CHIP_RESET == RESET_REASON_CORE_USB_UART, "USB_UART_CHIP_RESET != RESET_REASON_CORE_USB_UART"); _Static_assert((soc_reset_reason_t)USB_JTAG_CHIP_RESET == RESET_REASON_CORE_USB_JTAG, "USB_JTAG_CHIP_RESET != RESET_REASON_CORE_USB_JTAG"); _Static_assert((soc_reset_reason_t)POWER_GLITCH_RESET == RESET_REASON_CORE_PWR_GLITCH, "POWER_GLITCH_RESET != RESET_REASON_CORE_PWR_GLITCH"); -_Static_assert((soc_reset_reason_t)JTAG_RESET == RESET_REASON_CPU_JTAG, "JTAG_RESET != RESET_REASON_CPU_JTAG"); +_Static_assert((soc_reset_reason_t)JTAG_RESET == RESET_REASON_CPU0_JTAG, "JTAG_RESET != RESET_REASON_CPU0_JTAG"); typedef enum { NO_SLEEP = 0, diff --git a/tools/sdk/esp32/include/esp_rom/include/esp32h2/rom/secure_boot.h b/tools/sdk/esp32/include/esp_rom/include/esp32h2/rom/secure_boot.h index 71cf7250d29..36a490d8584 100644 --- a/tools/sdk/esp32/include/esp_rom/include/esp32h2/rom/secure_boot.h +++ b/tools/sdk/esp32/include/esp_rom/include/esp32h2/rom/secure_boot.h @@ -1,19 +1,10 @@ -// Copyright 2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef _ROM_SECURE_BOOT_H_ -#define _ROM_SECURE_BOOT_H_ +/* + * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once #include #include @@ -24,9 +15,6 @@ extern "C" { #endif -struct ets_secure_boot_sig_block; -struct ets_secure_boot_signature_t; - typedef struct ets_secure_boot_sig_block ets_secure_boot_sig_block_t; typedef struct ets_secure_boot_signature ets_secure_boot_signature_t; typedef struct ets_secure_boot_key_digests ets_secure_boot_key_digests_t; @@ -127,5 +115,3 @@ struct ets_secure_boot_key_digests { #ifdef __cplusplus } #endif - -#endif /* _ROM_SECURE_BOOT_H_ */ diff --git a/tools/sdk/esp32/include/esp_rom/include/esp32s2/rom/secure_boot.h b/tools/sdk/esp32/include/esp_rom/include/esp32s2/rom/secure_boot.h index 8e880817860..a0fcecfd3c5 100644 --- a/tools/sdk/esp32/include/esp_rom/include/esp32s2/rom/secure_boot.h +++ b/tools/sdk/esp32/include/esp_rom/include/esp32s2/rom/secure_boot.h @@ -1,19 +1,10 @@ -// Copyright 2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef _ROM_SECURE_BOOT_H_ -#define _ROM_SECURE_BOOT_H_ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once #include #include "ets_sys.h" @@ -23,9 +14,6 @@ extern "C" { #endif -struct ets_secure_boot_sig_block; -struct ets_secure_boot_signature_t; - typedef struct ets_secure_boot_sig_block ets_secure_boot_sig_block_t; typedef struct ets_secure_boot_signature ets_secure_boot_signature_t; typedef struct ets_secure_boot_key_digests ets_secure_boot_key_digests_t; @@ -126,5 +114,3 @@ struct ets_secure_boot_key_digests { #ifdef __cplusplus } #endif - -#endif /* _ROM_SECURE_BOOT_H_ */ diff --git a/tools/sdk/esp32/include/esp_rom/include/esp32s3/rom/secure_boot.h b/tools/sdk/esp32/include/esp_rom/include/esp32s3/rom/secure_boot.h index e720697b3e6..a372517b7a1 100644 --- a/tools/sdk/esp32/include/esp_rom/include/esp32s3/rom/secure_boot.h +++ b/tools/sdk/esp32/include/esp_rom/include/esp32s3/rom/secure_boot.h @@ -1,16 +1,8 @@ -// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once @@ -23,9 +15,6 @@ extern "C" { #endif -struct ets_secure_boot_sig_block; -struct ets_secure_boot_signature_t; - typedef struct ets_secure_boot_sig_block ets_secure_boot_sig_block_t; typedef struct ets_secure_boot_signature ets_secure_boot_signature_t; typedef struct ets_secure_boot_key_digests ets_secure_boot_key_digests_t; diff --git a/tools/sdk/esp32/include/esp_schedule/include/esp_schedule.h b/tools/sdk/esp32/include/esp_schedule/include/esp_schedule.h index d4bc7478363..4b611830a7d 100644 --- a/tools/sdk/esp32/include/esp_schedule/include/esp_schedule.h +++ b/tools/sdk/esp32/include/esp_schedule/include/esp_schedule.h @@ -51,6 +51,7 @@ typedef enum esp_schedule_type { ESP_SCHEDULE_TYPE_INVALID = 0, ESP_SCHEDULE_TYPE_DAYS_OF_WEEK, ESP_SCHEDULE_TYPE_DATE, + ESP_SCHEDULE_TYPE_RELATIVE, } esp_schedule_type_t; /** Schedule days. Used for ESP_SCHEDULE_TYPE_DAYS_OF_WEEK. */ @@ -108,6 +109,11 @@ typedef struct esp_schedule_trigger { /** If the schedule is to be repeated every year. */ bool repeat_every_year; } date; + /** For type ESP_SCHEDULE_TYPE_SECONDS */ + int relative_seconds; + /** Used for passing the next schedule timestamp for + * ESP_SCHEDULE_TYPE_RELATIVE */ + time_t next_scheduled_time_utc; } esp_schedule_trigger_t; /** Schedule config */ diff --git a/tools/sdk/esp32/include/esp_serial_slave_link/include/essl_spi/esp32h2_defs.h b/tools/sdk/esp32/include/esp_serial_slave_link/include/essl_spi/esp32h2_defs.h index 3dfd4a14b75..e69de29bb2d 100644 --- a/tools/sdk/esp32/include/esp_serial_slave_link/include/essl_spi/esp32h2_defs.h +++ b/tools/sdk/esp32/include/esp_serial_slave_link/include/essl_spi/esp32h2_defs.h @@ -1,38 +0,0 @@ -// Copyright 2010-2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - - -#pragma once - -// NOTE: From the view of master -#define CMD_HD_WRBUF_REG 0x01 -#define CMD_HD_RDBUF_REG 0x02 -#define CMD_HD_WRDMA_REG 0x03 -#define CMD_HD_RDDMA_REG 0x04 - -#define CMD_HD_ONEBIT_MODE 0x00 -#define CMD_HD_DOUT_MODE 0x10 -#define CMD_HD_QOUT_MODE 0x20 -#define CMD_HD_DIO_MODE 0x50 -#define CMD_HD_QIO_MODE 0xA0 - -#define CMD_HD_SEG_END_REG 0x05 -#define CMD_HD_EN_QPI_REG 0x06 -#define CMD_HD_WR_END_REG 0x07 -#define CMD_HD_INT0_REG 0x08 -#define CMD_HD_INT1_REG 0x09 -#define CMD_HD_INT2_REG 0x0A -#define CMD_HD_EX_QPI_REG 0xDD - -#define SPI_SLAVE_HD_BUFFER_SIZE 64 diff --git a/tools/sdk/esp32/include/esp_system/include/esp_private/esp_ipc_isr.h b/tools/sdk/esp32/include/esp_system/include/esp_private/esp_ipc_isr.h new file mode 100644 index 00000000000..ccdfe1deaa2 --- /dev/null +++ b/tools/sdk/esp32/include/esp_system/include/esp_private/esp_ipc_isr.h @@ -0,0 +1,37 @@ +/* + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include "sdkconfig.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef CONFIG_ESP_IPC_ISR_ENABLE + +/** + * @brief Initialize the IPC ISR feature, must be called for each CPU + * + * @note This function is called from ipc_task(). + * + * This function initializes the IPC ISR feature and must be called before any other esp_ipc_isr...() functions. + * The IPC ISR feature allows for callbacks (written in assembly) to be run on a particular CPU in the context of a + * High Priority Interrupt. + * + * - This function will register a High Priority Interrupt for a CPU where it is called. The priority of the interrupts is dependent on + * the CONFIG_ESP_SYSTEM_CHECK_INT_LEVEL option. + * - Callbacks written in assembly can then run in context of the registered High Priority Interrupts + * - Callbacks can be executed by calling esp_ipc_isr_asm_call() or esp_ipc_isr_asm_call_blocking() + */ +void esp_ipc_isr_init(void); + +#endif // CONFIG_ESP_IPC_ISR_ENABLE + +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/esp32/include/esp_wifi/include/esp_wifi.h b/tools/sdk/esp32/include/esp_wifi/include/esp_wifi.h index 2d671591765..bcd10c77a10 100644 --- a/tools/sdk/esp32/include/esp_wifi/include/esp_wifi.h +++ b/tools/sdk/esp32/include/esp_wifi/include/esp_wifi.h @@ -228,21 +228,21 @@ extern uint64_t g_wifi_feature_caps; .feature_caps = g_wifi_feature_caps, \ .sta_disconnected_pm = WIFI_STA_DISCONNECTED_PM_ENABLED, \ .magic = WIFI_INIT_CONFIG_MAGIC\ -}; +} /** - * @brief Init WiFi - * Alloc resource for WiFi driver, such as WiFi control structure, RX/TX buffer, - * WiFi NVS structure etc, this WiFi also start WiFi task + * @brief Initialize WiFi + * Allocate resource for WiFi driver, such as WiFi control structure, RX/TX buffer, + * WiFi NVS structure etc. This WiFi also starts WiFi task * * @attention 1. This API must be called before all other WiFi API can be called - * @attention 2. Always use WIFI_INIT_CONFIG_DEFAULT macro to init the config to default values, this can - * guarantee all the fields got correct value when more fields are added into wifi_init_config_t - * in future release. If you want to set your owner initial values, overwrite the default values - * which are set by WIFI_INIT_CONFIG_DEFAULT, please be notified that the field 'magic' of + * @attention 2. Always use WIFI_INIT_CONFIG_DEFAULT macro to initialize the configuration to default values, this can + * guarantee all the fields get correct value when more fields are added into wifi_init_config_t + * in future release. If you want to set your own initial values, overwrite the default values + * which are set by WIFI_INIT_CONFIG_DEFAULT. Please be notified that the field 'magic' of * wifi_init_config_t should always be WIFI_INIT_CONFIG_MAGIC! * - * @param config pointer to WiFi init configuration structure; can point to a temporary variable. + * @param config pointer to WiFi initialized configuration structure; can point to a temporary variable. * * @return * - ESP_OK: succeed diff --git a/tools/sdk/esp32/include/esp_wifi/include/esp_wifi_types.h b/tools/sdk/esp32/include/esp_wifi/include/esp_wifi_types.h index ae574416b9c..47f5c79281b 100644 --- a/tools/sdk/esp32/include/esp_wifi/include/esp_wifi_types.h +++ b/tools/sdk/esp32/include/esp_wifi/include/esp_wifi_types.h @@ -215,7 +215,7 @@ typedef enum { /** Configuration structure for Protected Management Frame */ typedef struct { - bool capable; /**< Advertizes support for Protected Management Frame. Device will prefer to connect in PMF mode if other device also advertizes PMF capability. */ + bool capable; /**< Deprecated variable. Device will always connect in PMF mode if other device also advertizes PMF capability. */ bool required; /**< Advertizes that Protected Management Frame is required. Device will not associate to non-PMF capable devices. */ } wifi_pmf_config_t; diff --git a/tools/sdk/esp32/include/expat/expat/expat/lib/expat.h b/tools/sdk/esp32/include/expat/expat/expat/lib/expat.h index b7d6d354801..0f021e25def 100644 --- a/tools/sdk/esp32/include/expat/expat/expat/lib/expat.h +++ b/tools/sdk/esp32/include/expat/expat/expat/lib/expat.h @@ -11,7 +11,7 @@ Copyright (c) 2000-2005 Fred L. Drake, Jr. Copyright (c) 2001-2002 Greg Stein Copyright (c) 2002-2016 Karl Waclawek - Copyright (c) 2016-2021 Sebastian Pipping + Copyright (c) 2016-2022 Sebastian Pipping Copyright (c) 2016 Cristian Rodríguez Copyright (c) 2016 Thomas Beutlich Copyright (c) 2017 Rhodri James @@ -1041,7 +1041,7 @@ XML_SetBillionLaughsAttackProtectionActivationThreshold( */ #define XML_MAJOR_VERSION 2 #define XML_MINOR_VERSION 4 -#define XML_MICRO_VERSION 1 +#define XML_MICRO_VERSION 3 #ifdef __cplusplus } diff --git a/tools/sdk/esp32/include/expat/port/include/expat_config.h b/tools/sdk/esp32/include/expat/port/include/expat_config.h index b6b927a19bb..468910220f4 100644 --- a/tools/sdk/esp32/include/expat/port/include/expat_config.h +++ b/tools/sdk/esp32/include/expat/port/include/expat_config.h @@ -63,7 +63,7 @@ #define PACKAGE_NAME "expat" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "expat 2.2.5" +#define PACKAGE_STRING "expat 2.4.3" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "expat" @@ -72,13 +72,13 @@ #define PACKAGE_URL "" /* Define to the version of this package. */ -#define PACKAGE_VERSION "2.2.5" +#define PACKAGE_VERSION "2.4.3" /* Define to 1 if you have the ANSI C header files. */ #define STDC_HEADERS 1 /* Version number of package */ -#define VERSION "2.2.5" +#define VERSION "2.4.3" /* whether byteorder is bigendian */ /* #undef WORDS_BIGENDIAN */ diff --git a/tools/sdk/esp32/include/fb_gfx/include/fb_gfx.h b/tools/sdk/esp32/include/fb_gfx/include/fb_gfx.h index 079ff7bfe4a..158c80f6bf4 100644 --- a/tools/sdk/esp32/include/fb_gfx/include/fb_gfx.h +++ b/tools/sdk/esp32/include/fb_gfx/include/fb_gfx.h @@ -19,7 +19,7 @@ extern "C" { #endif typedef enum { - FB_RGB888, FB_BGR888, FB_RGB565, FB_BGR565 + FB_RGB888, FB_BGR888, FB_RGB565, FB_BGR565, FB_GRAY } fb_format_t; typedef struct { diff --git a/tools/sdk/esp32/include/freemodbus/common/include/esp_modbus_common.h b/tools/sdk/esp32/include/freemodbus/common/include/esp_modbus_common.h index 398af0ba9db..9c65f08b90d 100644 --- a/tools/sdk/esp32/include/freemodbus/common/include/esp_modbus_common.h +++ b/tools/sdk/esp32/include/freemodbus/common/include/esp_modbus_common.h @@ -22,6 +22,24 @@ extern "C" { #endif +#if __has_include("esp_check.h") +#include "esp_check.h" + +#define MB_RETURN_ON_FALSE(a, err_code, tag, format, ...) ESP_RETURN_ON_FALSE(a, err_code, tag, format __VA_OPT__(,) __VA_ARGS__) + +#else + +// if cannot include esp_check then use custom check macro + +#define MB_RETURN_ON_FALSE(a, err_code, tag, format, ...) do { \ + if (!(a)) { \ + ESP_LOGE(tag, "%s(%d): " format, __FUNCTION__, __LINE__ __VA_OPT__(,) __VA_ARGS__); \ + return err_code; \ + } \ +} while(0) + +#endif + #define MB_CONTROLLER_STACK_SIZE (CONFIG_FMB_CONTROLLER_STACK_SIZE) // Stack size for Modbus controller #define MB_CONTROLLER_PRIORITY (CONFIG_FMB_PORT_TASK_PRIO - 1) // priority of MB controller task diff --git a/tools/sdk/esp32/include/freemodbus/common/include/esp_modbus_master.h b/tools/sdk/esp32/include/freemodbus/common/include/esp_modbus_master.h index 5d7539b08d9..8084e689027 100644 --- a/tools/sdk/esp32/include/freemodbus/common/include/esp_modbus_master.h +++ b/tools/sdk/esp32/include/freemodbus/common/include/esp_modbus_master.h @@ -25,6 +25,12 @@ extern "C" { #endif +#define MB_MASTER_CHECK(a, err_code, format, ...) MB_RETURN_ON_FALSE(a, err_code, TAG, format __VA_OPT__(,) __VA_ARGS__) + +#define MB_MASTER_ASSERT(con) do { \ + if (!(con)) { ESP_LOGE(TAG, "assert errno:%d, errno_str: !(%s)", errno, strerror(errno)); assert(0 && #con); } \ + } while (0) + /*! * \brief Modbus descriptor table parameter type defines. */ diff --git a/tools/sdk/esp32/include/freemodbus/common/include/esp_modbus_slave.h b/tools/sdk/esp32/include/freemodbus/common/include/esp_modbus_slave.h index fa6a53bc44e..040d18265bf 100644 --- a/tools/sdk/esp32/include/freemodbus/common/include/esp_modbus_slave.h +++ b/tools/sdk/esp32/include/freemodbus/common/include/esp_modbus_slave.h @@ -28,6 +28,12 @@ extern "C" { #endif +#define MB_SLAVE_CHECK(a, err_code, format, ...) MB_RETURN_ON_FALSE(a, err_code, TAG, format __VA_OPT__(,) __VA_ARGS__) + +#define MB_SLAVE_ASSERT(con) do { \ + if (!(con)) { ESP_LOGE(TAG, "assert errno:%d, errno_str: !(%s)", errno, strerror(errno)); assert(0 && #con); } \ + } while (0) + /** * @brief Parameter access event information type */ diff --git a/tools/sdk/esp32/include/freertos/include/esp_additions/freertos/FreeRTOSConfig.h b/tools/sdk/esp32/include/freertos/include/esp_additions/freertos/FreeRTOSConfig.h index aa87e1b4db2..6bb81894593 100644 --- a/tools/sdk/esp32/include/freertos/include/esp_additions/freertos/FreeRTOSConfig.h +++ b/tools/sdk/esp32/include/freertos/include/esp_additions/freertos/FreeRTOSConfig.h @@ -250,8 +250,12 @@ #define INCLUDE_pcTaskGetTaskName 1 #define INCLUDE_xTaskGetIdleTaskHandle 1 #define INCLUDE_pxTaskGetStackStart 1 - +#define INCLUDE_eTaskGetState 1 +#define INCLUDE_xTaskAbortDelay 1 +#define INCLUDE_xTaskGetHandle 1 #define INCLUDE_xSemaphoreGetMutexHolder 1 +#define INCLUDE_xTimerPendFunctionCall 1 +#define INCLUDE_xTimerGetTimerDaemonTaskHandle 0 //Currently there is no need for this API /* The priority at which the tick interrupt runs. This should probably be kept at 1. */ @@ -278,8 +282,6 @@ extern void vPortCleanUpTCB ( void *pxTCB ); #define configTIMER_QUEUE_LENGTH CONFIG_FREERTOS_TIMER_QUEUE_LENGTH #define configTIMER_TASK_STACK_DEPTH CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH -#define INCLUDE_xTimerPendFunctionCall 1 -#define INCLUDE_eTaskGetState 1 #define configUSE_QUEUE_SETS 1 #define configUSE_TICKLESS_IDLE CONFIG_FREERTOS_USE_TICKLESS_IDLE diff --git a/tools/sdk/esp32/include/freertos/include/freertos/projdefs.h b/tools/sdk/esp32/include/freertos/include/freertos/projdefs.h index ec8022ca0b0..1949e6e30b3 100644 --- a/tools/sdk/esp32/include/freertos/include/freertos/projdefs.h +++ b/tools/sdk/esp32/include/freertos/include/freertos/projdefs.h @@ -41,7 +41,7 @@ typedef void (* TaskFunction_t)( void * ); #endif #ifdef ESP_PLATFORM #ifndef pdTICKS_TO_MS - #define pdTICKS_TO_MS( xTicks ) ( ( uint32_t ) ( xTicks ) * 1000 / configTICK_RATE_HZ ) + #define pdTICKS_TO_MS( xTicks ) ( ( TickType_t ) ( ( uint64_t ) ( xTicks ) * 1000 / configTICK_RATE_HZ ) ) #endif #endif // ESP_PLATFORM diff --git a/tools/sdk/esp32/include/freertos/port/xtensa/include/freertos/portmacro.h b/tools/sdk/esp32/include/freertos/port/xtensa/include/freertos/portmacro.h index 934f056816c..2ee4c12c2b8 100644 --- a/tools/sdk/esp32/include/freertos/port/xtensa/include/freertos/portmacro.h +++ b/tools/sdk/esp32/include/freertos/port/xtensa/include/freertos/portmacro.h @@ -558,14 +558,14 @@ static inline void __attribute__((always_inline)) uxPortCompareSetExtram(volatil // --------------------- Interrupts ------------------------ -static inline UBaseType_t xPortSetInterruptMaskFromISR(void) +static inline UBaseType_t __attribute__((always_inline)) xPortSetInterruptMaskFromISR(void) { UBaseType_t prev_int_level = XTOS_SET_INTLEVEL(XCHAL_EXCM_LEVEL); portbenchmarkINTERRUPT_DISABLE(); return prev_int_level; } -static inline void vPortClearInterruptMaskFromISR(UBaseType_t prev_level) +static inline void __attribute__((always_inline)) vPortClearInterruptMaskFromISR(UBaseType_t prev_level) { portbenchmarkINTERRUPT_RESTORE(prev_level); XTOS_RESTORE_JUST_INTLEVEL(prev_level); diff --git a/tools/sdk/esp32/include/hal/esp32/include/hal/adc_hal.h b/tools/sdk/esp32/include/hal/esp32/include/hal/adc_hal.h index 50e3c9138ce..53da0e034bf 100644 --- a/tools/sdk/esp32/include/hal/esp32/include/hal/adc_hal.h +++ b/tools/sdk/esp32/include/hal/esp32/include/hal/adc_hal.h @@ -1,16 +1,8 @@ -// Copyright 2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /******************************************************************************* * NOTICE @@ -31,35 +23,9 @@ extern "C" { #endif -/*--------------------------------------------------------------- - Digital controller setting ----------------------------------------------------------------*/ - -/** - * Set I2S DMA data source for digital controller. - * - * @param src i2s data source. - */ -#define adc_hal_digi_set_data_source(src) adc_ll_digi_set_data_source(src) - -/*--------------------------------------------------------------- - Common setting ----------------------------------------------------------------*/ - /*--------------------------------------------------------------- Hall sensor setting ---------------------------------------------------------------*/ - -/** - * Enable hall sensor. - */ -#define adc_hal_hall_enable() adc_ll_hall_enable() - -/** - * Disable hall sensor. - */ -#define adc_hal_hall_disable() adc_ll_hall_disable() - /** * Start hall convert and return the hall value. * diff --git a/tools/sdk/esp32/include/hal/esp32/include/hal/adc_ll.h b/tools/sdk/esp32/include/hal/esp32/include/hal/adc_ll.h index 1b5969ac433..6e648733bed 100644 --- a/tools/sdk/esp32/include/hal/esp32/include/hal/adc_ll.h +++ b/tools/sdk/esp32/include/hal/esp32/include/hal/adc_ll.h @@ -1,3 +1,9 @@ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + #pragma once #include "soc/adc_periph.h" @@ -27,20 +33,48 @@ typedef enum { } adc_ll_power_t; typedef enum { - ADC_HALL_CTRL_ULP = 0x0,/*!< Hall sensor controlled by ULP */ - ADC_HALL_CTRL_RTC = 0x1 /*!< Hall sensor controlled by RTC */ -} adc_ll_hall_controller_t ; + ADC_RTC_DATA_OK = 0, +} adc_ll_rtc_raw_data_t; typedef enum { - ADC_CTRL_RTC = 0, - ADC_CTRL_ULP = 1, - ADC_CTRL_DIG = 2, - ADC2_CTRL_PWDET = 3, -} adc_hal_controller_t ; + ADC_LL_CTRL_RTC = 0, ///< For ADC1 and ADC2. Select RTC controller. + ADC_LL_CTRL_ULP = 1, ///< For ADC1 and ADC2. Select ULP controller. + ADC_LL_CTRL_DIG = 2, ///< For ADC1 and ADC2. Select DIG controller. + ADC_LL_CTRL_PWDET = 3, ///< For ADC2. Select PWDET controller. +} adc_ll_controller_t; +/** + * @brief ADC digital controller (DMA mode) work mode. + * + * @note The conversion mode affects the sampling frequency: + * SINGLE_UNIT_1: When the measurement is triggered, only ADC1 is sampled once. + * SINGLE_UNIT_2: When the measurement is triggered, only ADC2 is sampled once. + * BOTH_UNIT : When the measurement is triggered, ADC1 and ADC2 are sampled at the same time. + * ALTER_UNIT : When the measurement is triggered, ADC1 or ADC2 samples alternately. + */ typedef enum { - ADC_RTC_DATA_OK = 0, -} adc_ll_rtc_raw_data_t; + ADC_LL_DIGI_CONV_ONLY_ADC1 = 0, // Only use ADC1 for conversion + ADC_LL_DIGI_CONV_ONLY_ADC2 = 1, // Only use ADC2 for conversion + ADC_LL_DIGI_CONV_BOTH_UNIT = 2, // Use Both ADC1 and ADC2 for conversion simultaneously + ADC_LL_DIGI_CONV_ALTER_UNIT = 3 // Use both ADC1 and ADC2 for conversion by turn. e.g. ADC1 -> ADC2 -> ADC1 -> ADC2 ..... +} adc_ll_digi_convert_mode_t; + +//Need a unit test for bit_width +typedef struct { + union { + struct { + uint8_t atten: 2; + uint8_t bit_width: 2; //ADC resolution. 0: 9 bit; 1: 10 bit; 2: 11 bit; 3: 12 bit + uint8_t channel: 4; + }; + uint8_t val; + }; +} __attribute__((packed)) adc_ll_digi_pattern_table_t; + +typedef enum { + ADC_HALL_CTRL_ULP = 0x0,/*!< Hall sensor controlled by ULP */ + ADC_HALL_CTRL_RTC = 0x1 /*!< Hall sensor controlled by RTC */ +} adc_ll_hall_controller_t ; /*--------------------------------------------------------------- Digital controller setting @@ -85,16 +119,6 @@ static inline void adc_ll_digi_set_clk_div(uint32_t div) HAL_FORCE_MODIFY_U32_REG_FIELD(SYSCON.saradc_ctrl, sar_clk_div, div); } -/** - * Set adc output data format for digital controller. - * - * @param format Output data format, see ``adc_digi_output_format_t``. - */ -static inline void adc_ll_digi_set_output_format(adc_digi_output_format_t format) -{ - SYSCON.saradc_ctrl.data_sar_sel = format; -} - /** * Set adc max conversion number for digital controller. * If the number of ADC conversion is equal to the maximum, the conversion is stopped. @@ -128,21 +152,28 @@ static inline void adc_ll_digi_convert_limit_disable(void) * Set adc conversion mode for digital controller. * * @note ESP32 only support ADC1 single mode. + * @note For `data_sar_sel` register: + * 1: [15] unit, [14:11] channel, [10:0] data, 11-bit-width at most. Only work under `ADC_LL_DIGI_CONV_BOTH_UNIT` or `ADC_LL_DIGI_CONV_ALTER_UNIT` mode. + * 0: [15:12] channel, [11:0] data, 12-bit-width at most. Only work under `ADC_LL_DIGI_CONV_ONLY_ADC1` or `ADC_LL_DIGI_CONV_ONLY_ADC2` mode * - * @param mode Conversion mode select, see ``adc_digi_convert_mode_t``. + * @param mode Conversion mode select. */ -static inline void adc_ll_digi_set_convert_mode(adc_digi_convert_mode_t mode) +static inline void adc_ll_digi_set_convert_mode(adc_ll_digi_convert_mode_t mode) { - if (mode == ADC_CONV_SINGLE_UNIT_1) { + if (mode == ADC_LL_DIGI_CONV_ONLY_ADC1) { SYSCON.saradc_ctrl.work_mode = 0; SYSCON.saradc_ctrl.sar_sel = 0; - } else if (mode == ADC_CONV_SINGLE_UNIT_2) { + SYSCON.saradc_ctrl.data_sar_sel = 0; + } else if (mode == ADC_LL_DIGI_CONV_ONLY_ADC2) { SYSCON.saradc_ctrl.work_mode = 0; SYSCON.saradc_ctrl.sar_sel = 1; - } else if (mode == ADC_CONV_BOTH_UNIT) { + SYSCON.saradc_ctrl.data_sar_sel = 0; + } else if (mode == ADC_LL_DIGI_CONV_BOTH_UNIT) { SYSCON.saradc_ctrl.work_mode = 1; - } else if (mode == ADC_CONV_ALTER_UNIT) { + SYSCON.saradc_ctrl.data_sar_sel = 1; + } else if (mode == ADC_LL_DIGI_CONV_ALTER_UNIT) { SYSCON.saradc_ctrl.work_mode = 2; + SYSCON.saradc_ctrl.data_sar_sel = 1; } } @@ -163,11 +194,10 @@ static inline void adc_ll_digi_output_invert(adc_ll_num_t adc_n, bool inv_en) /** * Set I2S DMA data source for digital controller. * - * @param src i2s data source, see ``adc_i2s_source_t``. + * @param src 1: I2S input data is from SAR ADC (for DMA) 0: I2S input data is from GPIO matrix */ -static inline void adc_ll_digi_set_data_source(adc_i2s_source_t src) +static inline void adc_ll_digi_set_data_source(bool src) { - /* 1: I2S input data is from SAR ADC (for DMA) 0: I2S input data is from GPIO matrix */ SYSCON.saradc_ctrl.data_to_i2s = src; } @@ -199,12 +229,33 @@ static inline void adc_ll_digi_set_pattern_table_len(adc_ll_num_t adc_n, uint32_ * @param pattern_index Items index. Range: 0 ~ 15. * @param pattern Stored conversion rules, see ``adc_digi_pattern_table_t``. */ -static inline void adc_ll_digi_set_pattern_table(adc_ll_num_t adc_n, uint32_t pattern_index, adc_digi_pattern_table_t pattern) +static inline void adc_ll_digi_set_pattern_table(adc_ll_num_t adc_n, uint32_t pattern_index, adc_digi_pattern_config_t table) { uint32_t tab; uint8_t index = pattern_index / 4; uint8_t offset = (pattern_index % 4) * 8; - if (adc_n == ADC_NUM_1) { + adc_ll_digi_pattern_table_t pattern = {0}; + uint8_t bit_width; + + switch (table.bit_width) { + case 9: + bit_width = 0x0; + break; + case 10: + bit_width = 0x1; + break; + case 11: + bit_width = 0x2; + break; + case 12: + bit_width = 0x3; + break; + default: + bit_width = 0x3; + } + pattern.val = (table.atten & 0x3) | ((bit_width) << 2) | ((table.channel & 0xF) << 4); + + if (table.unit == ADC_NUM_1) { tab = SYSCON.saradc_sar1_patt_tab[index]; // Read old register value tab &= (~(0xFF000000 >> offset)); // clear old data tab |= ((uint32_t)pattern.val << 24) >> offset; // Fill in the new data @@ -233,6 +284,15 @@ static inline void adc_ll_digi_clear_pattern_table(adc_ll_num_t adc_n) } } +/** + * Disable clock for ADC digital controller. + * @note Not used for esp32 + */ +static inline void adc_ll_digi_controller_clk_disable(void) +{ + //Leave here for compatibility +} + /*--------------------------------------------------------------- PWDET(Power detect) controller setting ---------------------------------------------------------------*/ @@ -263,6 +323,20 @@ static inline uint32_t adc_ll_pwdet_get_cct(void) /*--------------------------------------------------------------- RTC controller setting ---------------------------------------------------------------*/ +/** + * ADC SAR clock division factor setting. ADC SAR clock divided from `RTC_FAST_CLK`. + * + * @param div Division factor. + */ +static inline void adc_ll_set_sar_clk_div(adc_ll_num_t adc_n, uint32_t div) +{ + if (adc_n == ADC_NUM_1) { + HAL_FORCE_MODIFY_U32_REG_FIELD(SENS.sar_read_ctrl, sar1_clk_div, div); + } else { // adc_n == ADC_NUM_2 + HAL_FORCE_MODIFY_U32_REG_FIELD(SENS.sar_read_ctrl2, sar2_clk_div, div); + } +} + /** * Set adc output data format for RTC controller. * @@ -398,62 +472,6 @@ static inline adc_ll_rtc_raw_data_t adc_ll_rtc_analysis_raw_data(adc_ll_num_t ad return ADC_RTC_DATA_OK; } -/*--------------------------------------------------------------- - Common setting ----------------------------------------------------------------*/ -/** - * Set ADC module power management. - * - * @param manage Set ADC power status. - */ -static inline void adc_ll_set_power_manage(adc_ll_power_t manage) -{ - /* Bit1 0:Fsm 1: SW mode - Bit0 0:SW mode power down 1: SW mode power on */ - if (manage == ADC_POWER_SW_ON) { - SENS.sar_meas_wait2.force_xpd_sar = SENS_FORCE_XPD_SAR_PU; - } else if (manage == ADC_POWER_BY_FSM) { - SENS.sar_meas_wait2.force_xpd_sar = SENS_FORCE_XPD_SAR_FSM; - } else if (manage == ADC_POWER_SW_OFF) { - SENS.sar_meas_wait2.force_xpd_sar = SENS_FORCE_XPD_SAR_PD; - } -} - -/** - * Get ADC module power management. - * - * @return - * - ADC power status. - */ -static inline adc_ll_power_t adc_ll_get_power_manage(void) -{ - /* Bit1 0:Fsm 1: SW mode - Bit0 0:SW mode power down 1: SW mode power on */ - adc_ll_power_t manage; - if (SENS.sar_meas_wait2.force_xpd_sar == SENS_FORCE_XPD_SAR_PU) { - manage = ADC_POWER_SW_ON; - } else if (SENS.sar_meas_wait2.force_xpd_sar == SENS_FORCE_XPD_SAR_PD) { - manage = ADC_POWER_SW_OFF; - } else { - manage = ADC_POWER_BY_FSM; - } - return manage; -} - -/** - * ADC SAR clock division factor setting. ADC SAR clock divided from `RTC_FAST_CLK`. - * - * @param div Division factor. - */ -static inline void adc_ll_set_sar_clk_div(adc_ll_num_t adc_n, uint32_t div) -{ - if (adc_n == ADC_NUM_1) { - HAL_FORCE_MODIFY_U32_REG_FIELD(SENS.sar_read_ctrl, sar1_clk_div, div); - } else { // adc_n == ADC_NUM_2 - HAL_FORCE_MODIFY_U32_REG_FIELD(SENS.sar_read_ctrl2, sar2_clk_div, div); - } -} - /** * Set the attenuation of a particular channel on ADCn. */ @@ -482,6 +500,27 @@ static inline adc_atten_t adc_ll_get_atten(adc_ll_num_t adc_n, adc_channel_t cha } } +/*--------------------------------------------------------------- + Common setting +---------------------------------------------------------------*/ +/** + * Set ADC module power management. + * + * @param manage Set ADC power status. + */ +static inline void adc_ll_set_power_manage(adc_ll_power_t manage) +{ + /* Bit1 0:Fsm 1: SW mode + Bit0 0:SW mode power down 1: SW mode power on */ + if (manage == ADC_POWER_SW_ON) { + SENS.sar_meas_wait2.force_xpd_sar = SENS_FORCE_XPD_SAR_PU; + } else if (manage == ADC_POWER_BY_FSM) { + SENS.sar_meas_wait2.force_xpd_sar = SENS_FORCE_XPD_SAR_FSM; + } else if (manage == ADC_POWER_SW_OFF) { + SENS.sar_meas_wait2.force_xpd_sar = SENS_FORCE_XPD_SAR_PD; + } +} + /** * Set ADC module controller. * There are five SAR ADC controllers: @@ -492,25 +531,25 @@ static inline adc_atten_t adc_ll_get_atten(adc_ll_num_t adc_n, adc_channel_t cha * @param adc_n ADC unit. * @param ctrl ADC controller. */ -static inline void adc_ll_set_controller(adc_ll_num_t adc_n, adc_hal_controller_t ctrl) +static inline void adc_ll_set_controller(adc_ll_num_t adc_n, adc_ll_controller_t ctrl) { if (adc_n == ADC_NUM_1) { switch ( ctrl ) { - case ADC_CTRL_RTC: + case ADC_LL_CTRL_RTC: SENS.sar_read_ctrl.sar1_dig_force = 0; // 1: Select digital control; 0: Select RTC control. SENS.sar_meas_start1.meas1_start_force = 1; // 1: SW control RTC ADC start; 0: ULP control RTC ADC start. SENS.sar_meas_start1.sar1_en_pad_force = 1; // 1: SW control RTC ADC bit map; 0: ULP control RTC ADC bit map; SENS.sar_touch_ctrl1.xpd_hall_force = 1; // 1: SW control HALL power; 0: ULP FSM control HALL power. SENS.sar_touch_ctrl1.hall_phase_force = 1; // 1: SW control HALL phase; 0: ULP FSM control HALL phase. break; - case ADC_CTRL_ULP: + case ADC_LL_CTRL_ULP: SENS.sar_read_ctrl.sar1_dig_force = 0; // 1: Select digital control; 0: Select RTC control. SENS.sar_meas_start1.meas1_start_force = 0; // 1: SW control RTC ADC start; 0: ULP control RTC ADC start. SENS.sar_meas_start1.sar1_en_pad_force = 0; // 1: SW control RTC ADC bit map; 0: ULP control RTC ADC bit map; SENS.sar_touch_ctrl1.xpd_hall_force = 0; // 1: SW control HALL power; 0: ULP FSM control HALL power. SENS.sar_touch_ctrl1.hall_phase_force = 0; // 1: SW control HALL phase; 0: ULP FSM control HALL phase. break; - case ADC_CTRL_DIG: + case ADC_LL_CTRL_DIG: SENS.sar_read_ctrl.sar1_dig_force = 1; // 1: Select digital control; 0: Select RTC control. SENS.sar_meas_start1.meas1_start_force = 1; // 1: SW control RTC ADC start; 0: ULP control RTC ADC start. SENS.sar_meas_start1.sar1_en_pad_force = 1; // 1: SW control RTC ADC bit map; 0: ULP control RTC ADC bit map; @@ -522,28 +561,28 @@ static inline void adc_ll_set_controller(adc_ll_num_t adc_n, adc_hal_controller_ } } else { // adc_n == ADC_NUM_2 switch ( ctrl ) { - case ADC_CTRL_RTC: + case ADC_LL_CTRL_RTC: SENS.sar_meas_start2.meas2_start_force = 1; // 1: SW control RTC ADC start; 0: ULP control RTC ADC start. SENS.sar_meas_start2.sar2_en_pad_force = 1; // 1: SW control RTC ADC bit map; 0: ULP control RTC ADC bit map; SENS.sar_read_ctrl2.sar2_dig_force = 0; // 1: Select digital control; 0: Select RTC control. SENS.sar_read_ctrl2.sar2_pwdet_force = 0; // 1: Select power detect control; 0: Select RTC control. SYSCON.saradc_ctrl.sar2_mux = 1; // 1: Select digital control; 0: Select power detect control. break; - case ADC_CTRL_ULP: + case ADC_LL_CTRL_ULP: SENS.sar_meas_start2.meas2_start_force = 0; // 1: SW control RTC ADC start; 0: ULP control RTC ADC start. SENS.sar_meas_start2.sar2_en_pad_force = 0; // 1: SW control RTC ADC bit map; 0: ULP control RTC ADC bit map; SENS.sar_read_ctrl2.sar2_dig_force = 0; // 1: Select digital control; 0: Select RTC control. SENS.sar_read_ctrl2.sar2_pwdet_force = 0; // 1: Select power detect control; 0: Select RTC control. SYSCON.saradc_ctrl.sar2_mux = 1; // 1: Select digital control; 0: Select power detect control. break; - case ADC_CTRL_DIG: + case ADC_LL_CTRL_DIG: SENS.sar_meas_start2.meas2_start_force = 1; // 1: SW control RTC ADC start; 0: ULP control RTC ADC start. SENS.sar_meas_start2.sar2_en_pad_force = 1; // 1: SW control RTC ADC bit map; 0: ULP control RTC ADC bit map; SENS.sar_read_ctrl2.sar2_dig_force = 1; // 1: Select digital control; 0: Select RTC control. SENS.sar_read_ctrl2.sar2_pwdet_force = 0; // 1: Select power detect control; 0: Select RTC control. SYSCON.saradc_ctrl.sar2_mux = 1; // 1: Select digital control; 0: Select power detect control. break; - case ADC2_CTRL_PWDET: // currently only used by Wi-Fi + case ADC_LL_CTRL_PWDET: // currently only used by Wi-Fi SENS.sar_meas_start2.meas2_start_force = 1; // 1: SW control RTC ADC start; 0: ULP control RTC ADC start. SENS.sar_meas_start2.sar2_en_pad_force = 1; // 1: SW control RTC ADC bit map; 0: ULP control RTC ADC bit map; SENS.sar_read_ctrl2.sar2_dig_force = 0; // 1: Select digital control; 0: Select RTC control. diff --git a/tools/sdk/esp32/include/hal/esp32/include/hal/emac_ll.h b/tools/sdk/esp32/include/hal/esp32/include/hal/emac_ll.h index 625687b6a09..cd341b1c5f8 100644 --- a/tools/sdk/esp32/include/hal/esp32/include/hal/emac_ll.h +++ b/tools/sdk/esp32/include/hal/esp32/include/hal/emac_ll.h @@ -1,16 +1,8 @@ -// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /******************************************************************************* * NOTICE @@ -344,6 +336,17 @@ static inline void emac_ll_clear(emac_mac_dev_t *mac_regs) mac_regs->gmacfc.val = 0; } +/* emacdebug */ +static inline uint32_t emac_ll_transmit_frame_ctrl_status(emac_mac_dev_t *mac_regs) +{ + return mac_regs->emacdebug.mactfcs; +} + +static inline uint32_t emac_ll_receive_read_ctrl_state(emac_mac_dev_t *mac_regs) +{ + return mac_regs->emacdebug.mtlrfrcs; +} + /* emacmiidata */ static inline void emac_ll_set_phy_data(emac_mac_dev_t *mac_regs, uint32_t data) { diff --git a/tools/sdk/esp32/include/hal/esp32/include/hal/gpio_ll.h b/tools/sdk/esp32/include/hal/esp32/include/hal/gpio_ll.h index 59a2858ce91..fcff6a22bd6 100644 --- a/tools/sdk/esp32/include/hal/esp32/include/hal/gpio_ll.h +++ b/tools/sdk/esp32/include/hal/esp32/include/hal/gpio_ll.h @@ -567,7 +567,7 @@ static inline void gpio_ll_iomux_in(gpio_dev_t *hw, uint32_t gpio, uint32_t sign * @param pin_name Pin name to configure * @param func Function to assign to the pin */ -static inline void gpio_ll_iomux_func_sel(uint32_t pin_name, uint32_t func) +static inline __attribute__((always_inline)) void gpio_ll_iomux_func_sel(uint32_t pin_name, uint32_t func) { PIN_FUNC_SELECT(pin_name, func); } diff --git a/tools/sdk/esp32/include/hal/include/hal/adc_hal.h b/tools/sdk/esp32/include/hal/include/hal/adc_hal.h index 807d620c639..b8455e27ecd 100644 --- a/tools/sdk/esp32/include/hal/include/hal/adc_hal.h +++ b/tools/sdk/esp32/include/hal/include/hal/adc_hal.h @@ -1,21 +1,51 @@ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + #pragma once +#include "esp_err.h" #include "soc/soc_caps.h" +#include "hal/dma_types.h" #include "hal/adc_types.h" #include "hal/adc_ll.h" #include "esp_err.h" -#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2 +#if SOC_GDMA_SUPPORTED #include "soc/gdma_struct.h" #include "hal/gdma_ll.h" -#include "hal/dma_types.h" -#include "hal/adc_ll.h" -#include "hal/dma_types.h" -#include "esp_err.h" +#endif + +#if CONFIG_IDF_TARGET_ESP32S2 +//ADC utilises SPI3 DMA on ESP32S2 +#include "hal/spi_ll.h" +#endif + +#if CONFIG_IDF_TARGET_ESP32 +//ADC utilises I2S0 DMA on ESP32 +#include "hal/i2s_ll.h" +#endif + +#if SOC_GDMA_SUPPORTED +#define ADC_HAL_DMA_INTR_MASK GDMA_LL_EVENT_RX_SUC_EOF +#elif CONFIG_IDF_TARGET_ESP32S2 +#define ADC_HAL_DMA_INTR_MASK SPI_LL_INTR_IN_SUC_EOF +#else //CONFIG_IDF_TARGET_ESP32 +#define ADC_HAL_DMA_INTR_MASK BIT(9) +#endif //For ADC module, each conversion contains 4 bytes #define ADC_HAL_DATA_LEN_PER_CONV 4 +typedef enum adc_hal_work_mode_t { + ADC_HAL_ULP_MODE, + ADC_HAL_SINGLE_READ_MODE, + ADC_HAL_CONTINUOUS_READ_MODE, + ADC_HAL_PWDET_MODE +} adc_hal_work_mode_t; + /** * @brief Enum for DMA descriptor status */ @@ -29,6 +59,7 @@ typedef enum adc_hal_dma_desc_status_t { * @brief Configuration of the HAL */ typedef struct adc_hal_config_t { + void *dev; ///< DMA peripheral address uint32_t desc_max_num; ///< Number of the descriptors linked once uint32_t dma_chan; ///< DMA channel to be used uint32_t eof_num; ///< Bytes between 2 in_suc_eof interrupts @@ -42,25 +73,30 @@ typedef struct adc_hal_context_t { dma_descriptor_t *rx_desc; ///< DMA descriptors /**< these will be assigned by hal layer itself */ - gdma_dev_t *dev; ///< GDMA address dma_descriptor_t desc_dummy_head; ///< Dummy DMA descriptor for ``cur_desc_ptr`` to start dma_descriptor_t *cur_desc_ptr; ///< Pointer to the current descriptor /**< these need to be configured by `adc_hal_config_t` via driver layer*/ + void *dev; ///< DMA address uint32_t desc_max_num; ///< Number of the descriptors linked once uint32_t dma_chan; ///< DMA channel to be used uint32_t eof_num; ///< Words between 2 in_suc_eof interrupts } adc_hal_context_t; -#endif + +typedef struct adc_hal_digi_ctrlr_cfg_t { + bool conv_limit_en; //1: adc conversion will stop when `conv_limit_num` reaches. 0: won't stop. NOTE: esp32 should always be set to 1. + uint32_t conv_limit_num; //see `conv_limit_en` + uint32_t adc_pattern_len; //total pattern item number, including ADC1 and ADC2 + adc_digi_pattern_config_t *adc_pattern; //pattern item + uint32_t sample_freq_hz; //ADC sample frequency + adc_digi_convert_mode_t conv_mode; //controller work mode + uint32_t bit_width; //output data width +} adc_hal_digi_ctrlr_cfg_t; + /*--------------------------------------------------------------- Common setting ---------------------------------------------------------------*/ -/** - * ADC module initialization. - */ -void adc_hal_init(void); - /** * Set ADC module power management. * @@ -68,51 +104,7 @@ void adc_hal_init(void); */ #define adc_hal_set_power_manage(manage) adc_ll_set_power_manage(manage) -/** - * ADC module clock division factor setting. ADC clock devided from APB clock. - * - * @prarm div Division factor. - */ -#define adc_hal_digi_set_clk_div(div) adc_ll_digi_set_clk_div(div) - -#if !CONFIG_IDF_TARGET_ESP32C3 && !CONFIG_IDF_TARGET_ESP32H2 -/** - * ADC SAR clock division factor setting. ADC SAR clock devided from `RTC_FAST_CLK`. - * - * @prarm div Division factor. - */ -#define adc_hal_set_sar_clk_div(adc_n, div) adc_ll_set_sar_clk_div(adc_n, div) - -/** - * Set ADC module controller. - * There are five SAR ADC controllers: - * Two digital controller: Continuous conversion mode (DMA). High performance with multiple channel scan modes; - * Two RTC controller: Single conversion modes (Polling). For low power purpose working during deep sleep; - * the other is dedicated for Power detect (PWDET / PKDET), Only support ADC2. - * - * @prarm adc_n ADC unit. - * @prarm ctrl ADC controller. - */ -#define adc_hal_set_controller(adc_n, ctrl) adc_ll_set_controller(adc_n, ctrl) -#endif //#if !CONFIG_IDF_TARGET_ESP32C3 && !CONFIG_IDF_TARGET_ESP32H2 - -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 -/** - * Get the attenuation of a particular channel on ADCn. - * - * @param adc_n ADC unit. - * @param channel ADCn channel number. - * @return atten The attenuation option. - */ -#define adc_hal_get_atten(adc_n, channel) adc_ll_get_atten(adc_n, channel) -#endif - -#if CONFIG_IDF_TARGET_ESP32 -/** - * Close ADC AMP module if don't use it for power save. - */ -#define adc_hal_amp_disable() adc_ll_amp_disable() -#endif +void adc_hal_set_controller(adc_ll_num_t unit, adc_hal_work_mode_t work_mode); #if SOC_ADC_ARBITER_SUPPORTED //No ADC2 controller arbiter on ESP32 @@ -133,7 +125,6 @@ void adc_hal_arbiter_config(adc_arbiter_t *config); /*--------------------------------------------------------------- PWDET(Power detect) controller setting ---------------------------------------------------------------*/ - /** * Set adc cct for PWDET controller. * @@ -150,26 +141,6 @@ void adc_hal_arbiter_config(adc_arbiter_t *config); */ #define adc_hal_pwdet_get_cct() adc_ll_pwdet_get_cct() -/*--------------------------------------------------------------- - RTC controller setting ----------------------------------------------------------------*/ -#if !CONFIG_IDF_TARGET_ESP32C3 && !CONFIG_IDF_TARGET_ESP32H2 -/** - * Set adc output data format for RTC controller. - * - * @prarm adc_n ADC unit. - * @prarm bits Output data bits width option. - */ -#define adc_hal_rtc_set_output_format(adc_n, bits) adc_ll_rtc_set_output_format(adc_n, bits) - -/** - * ADC module output data invert or not. - * - * @prarm adc_n ADC unit. - */ -#define adc_hal_rtc_output_invert(adc_n, inv_en) adc_ll_rtc_output_invert(adc_n, inv_en) -#endif //#if !CONFIG_IDF_TARGET_ESP32C3 && !CONFIG_IDF_TARGET_ESP32H2 - /** * Enable/disable the output of ADCn's internal reference voltage to one of ADC2's channels. * @@ -187,29 +158,109 @@ void adc_hal_arbiter_config(adc_arbiter_t *config); /*--------------------------------------------------------------- Digital controller setting ---------------------------------------------------------------*/ +/** + * ADC module initialization. + */ +void adc_hal_init(void); + /** * Digital controller deinitialization. + * + * @param hal Context of the HAL */ -void adc_hal_digi_deinit(void); +void adc_hal_digi_deinit(adc_hal_context_t *hal); + +/** + * @brief Initialize the hal context + * + * @param hal Context of the HAL + * @param config Configuration of the HAL + */ +void adc_hal_context_config(adc_hal_context_t *hal, const adc_hal_config_t *config); + +/** + * @brief Initialize the HW + * + * @param hal Context of the HAL + */ +void adc_hal_digi_init(adc_hal_context_t *hal); /** * Setting the digital controller. * - * @param cfg Pointer to digital controller paramter. + * @param hal Context of the HAL + * @param cfg Pointer to digital controller paramter. + */ +void adc_hal_digi_controller_config(adc_hal_context_t *hal, const adc_hal_digi_ctrlr_cfg_t *cfg); + +/** + * @brief Start Conversion + * + * @param hal Context of the HAL + * @param data_buf Pointer to the data buffer, the length should be multiple of ``desc_max_num`` and ``eof_num`` in ``adc_hal_context_t`` */ -void adc_hal_digi_controller_config(const adc_digi_config_t *cfg); +void adc_hal_digi_start(adc_hal_context_t *hal, uint8_t *data_buf); +#if !SOC_GDMA_SUPPORTED /** - * Reset the pattern table pointer, then take the measurement rule from table header in next measurement. + * @brief Get the DMA descriptor that Hardware has finished processing. * - * @param adc_n ADC unit. + * @param hal Context of the HAL + * + * @return DMA descriptor address */ -#define adc_hal_digi_clear_pattern_table(adc_n) adc_ll_digi_clear_pattern_table(adc_n) +intptr_t adc_hal_get_desc_addr(adc_hal_context_t *hal); + +/** + * @brief Check the hardware interrupt event + * + * @param hal Context of the HAL + * @param mask Event mask + * + * @return True: the event is triggered. False: the event is not triggered yet. + */ +bool adc_hal_check_event(adc_hal_context_t *hal, uint32_t mask); +#endif + +/** + * @brief Get the ADC reading result + * + * @param hal Context of the HAL + * @param eof_desc_addr The last descriptor that is finished by HW. Should be got from DMA + * @param[out] cur_desc The descriptor with ADC reading result (from the 1st one to the last one (``eof_desc_addr``)) + * + * @return See ``adc_hal_dma_desc_status_t`` + */ +adc_hal_dma_desc_status_t adc_hal_get_reading_result(adc_hal_context_t *hal, const intptr_t eof_desc_addr, dma_descriptor_t **cur_desc); + +/** + * @brief Clear interrupt + * + * @param hal Context of the HAL + * @param mask mask of the interrupt + */ +void adc_hal_digi_clr_intr(adc_hal_context_t *hal, uint32_t mask); + +/** + * @brief Enable interrupt + * + * @param hal Context of the HAL + * @param mask mask of the interrupt + */ +void adc_hal_digi_dis_intr(adc_hal_context_t *hal, uint32_t mask); + +/** + * @brief Stop conversion + * + * @param hal Context of the HAL + */ +void adc_hal_digi_stop(adc_hal_context_t *hal); + /*--------------------------------------------------------------- ADC Single Read ---------------------------------------------------------------*/ -#if !CONFIG_IDF_TARGET_ESP32C3 && !CONFIG_IDF_TARGET_ESP32H2 +#if SOC_ADC_RTC_CTRL_SUPPORTED /** * Set the attenuation of a particular channel on ADCn. * @@ -245,7 +296,7 @@ void adc_hal_digi_controller_config(const adc_digi_config_t *cfg); */ #define adc_hal_set_atten(adc_n, channel, atten) adc_ll_set_atten(adc_n, channel, atten) -#else // CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2 +#else // #if !SOC_ADC_RTC_CTRL_SUPPORTED /** * Set the attenuation for ADC to single read * @@ -256,7 +307,7 @@ void adc_hal_digi_controller_config(const adc_digi_config_t *cfg); * @param atten ADC attenuation. See ``adc_atten_t`` */ #define adc_hal_set_atten(adc_n, channel, atten) adc_ll_onetime_set_atten(atten) -#endif +#endif //#if SOC_ADC_RTC_CTRL_SUPPORTED /** * Start an ADC conversion and get the converted value. @@ -277,7 +328,6 @@ esp_err_t adc_hal_convert(adc_ll_num_t adc_n, int channel, int *out_raw); ADC calibration setting ---------------------------------------------------------------*/ #if SOC_ADC_CALIBRATION_V1_SUPPORTED -// ESP32-S2, C3 and H2 support HW offset calibration. /** * @brief Initialize default parameter for the calibration block. @@ -314,86 +364,21 @@ uint32_t adc_hal_self_calibration(adc_ll_num_t adc_n, adc_channel_t channel, adc #endif //SOC_ADC_CALIBRATION_V1_SUPPORTED -#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2 + /*--------------------------------------------------------------- - DMA setting + RTC controller setting ---------------------------------------------------------------*/ /** - * @brief Initialize the hal context - * - * @param hal Context of the HAL - * @param config Configuration of the HAL - */ -void adc_hal_context_config(adc_hal_context_t *hal, const adc_hal_config_t *config); - -/** - * @brief Initialize the HW - * - * @param hal Context of the HAL - */ -void adc_hal_digi_init(adc_hal_context_t *hal); - -/** - * @brief Reset ADC / DMA fifo - * - * @param hal Context of the HAL - */ -void adc_hal_fifo_reset(adc_hal_context_t *hal); - -/** - * @brief Start DMA - * - * @param hal Context of the HAL - * @param data_buf Pointer to the data buffer, the length should be multiple of ``desc_max_num`` and ``eof_num`` in ``adc_hal_context_t`` - */ -void adc_hal_digi_rxdma_start(adc_hal_context_t *hal, uint8_t *data_buf); - -/** - * @brief Start ADC - * - * @param hal Context of the HAL - */ -void adc_hal_digi_start(adc_hal_context_t *hal); - -/** - * @brief Get the ADC reading result - * - * @param hal Context of the HAL - * @param eof_desc_addr The last descriptor that is finished by HW. Should be got from DMA - * @param[out] cur_desc The descriptor with ADC reading result (from the 1st one to the last one (``eof_desc_addr``)) - * - * @return See ``adc_hal_dma_desc_status_t`` - */ -adc_hal_dma_desc_status_t adc_hal_get_reading_result(adc_hal_context_t *hal, const intptr_t eof_desc_addr, dma_descriptor_t **cur_desc); - -/** - * @brief Stop DMA - * - * @param hal Context of the HAL - */ -void adc_hal_digi_rxdma_stop(adc_hal_context_t *hal); - -/** - * @brief Clear interrupt - * - * @param hal Context of the HAL - * @param mask mask of the interrupt - */ -void adc_hal_digi_clr_intr(adc_hal_context_t *hal, uint32_t mask); - -/** - * @brief Enable interrupt + * Set adc output data format for RTC controller. * - * @param hal Context of the HAL - * @param mask mask of the interrupt + * @prarm adc_n ADC unit. + * @prarm bits Output data bits width option. */ -void adc_hal_digi_dis_intr(adc_hal_context_t *hal, uint32_t mask); +#define adc_hal_rtc_set_output_format(adc_n, bits) adc_ll_rtc_set_output_format(adc_n, bits) /** - * @brief Stop ADC + * ADC module output data invert or not. * - * @param hal Context of the HAL + * @prarm adc_n ADC unit. */ -void adc_hal_digi_stop(adc_hal_context_t *hal); - -#endif //#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2 +#define adc_hal_rtc_output_invert(adc_n, inv_en) adc_ll_rtc_output_invert(adc_n, inv_en) diff --git a/tools/sdk/esp32/include/hal/include/hal/adc_types.h b/tools/sdk/esp32/include/hal/include/hal/adc_types.h index c0f6661f145..f5efb1d4273 100644 --- a/tools/sdk/esp32/include/hal/include/hal/adc_types.h +++ b/tools/sdk/esp32/include/hal/include/hal/adc_types.h @@ -1,16 +1,8 @@ -// Copyright 2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once #include @@ -62,26 +54,9 @@ typedef enum { ADC_ATTEN_MAX, } adc_atten_t; -#ifdef CONFIG_IDF_TARGET_ESP32 -/** - * @brief ESP32 ADC DMA source selection. - */ -#else -/** - * @brief ESP32 ADC DMA source selection. - * - * @deprecated Not applicable on ESP32-S2 because ESP32-S2 doesn't use I2S DMA. - */ -#endif -typedef enum { - ADC_I2S_DATA_SRC_IO_SIG = 0, /*!< I2S data from GPIO matrix signal */ - ADC_I2S_DATA_SRC_ADC = 1, /*!< I2S data from ADC */ - ADC_I2S_DATA_SRC_MAX, -} adc_i2s_source_t; - /** * @brief ADC resolution setting option. - * + * @note Only used in single read mode */ typedef enum { #if CONFIG_IDF_TARGET_ESP32 @@ -97,82 +72,56 @@ typedef enum { ADC_WIDTH_MAX, } adc_bits_width_t; - /** * @brief ADC digital controller (DMA mode) work mode. - * - * @note The conversion mode affects the sampling frequency: - * SINGLE_UNIT_1: When the measurement is triggered, only ADC1 is sampled once. - * SINGLE_UNIT_2: When the measurement is triggered, only ADC2 is sampled once. - * BOTH_UNIT : When the measurement is triggered, ADC1 and ADC2 are sampled at the same time. - * ALTER_UNIT : When the measurement is triggered, ADC1 or ADC2 samples alternately. */ typedef enum { - ADC_CONV_SINGLE_UNIT_1 = 1, /*!< SAR ADC 1. */ - ADC_CONV_SINGLE_UNIT_2 = 2, /*!< SAR ADC 2. */ - ADC_CONV_BOTH_UNIT = 3, /*!< SAR ADC 1 and 2. */ - ADC_CONV_ALTER_UNIT = 7, /*!< SAR ADC 1 and 2 alternative mode. */ + ADC_CONV_SINGLE_UNIT_1 = 1, ///< Only use ADC1 for conversion + ADC_CONV_SINGLE_UNIT_2 = 2, ///< Only use ADC2 for conversion + ADC_CONV_BOTH_UNIT = 3, ///< Use Both ADC1 and ADC2 for conversion simultaneously + ADC_CONV_ALTER_UNIT = 7, ///< Use both ADC1 and ADC2 for conversion by turn. e.g. ADC1 -> ADC2 -> ADC1 -> ADC2 ..... ADC_CONV_UNIT_MAX, } adc_digi_convert_mode_t; -/** - * @brief ADC digital controller (DMA mode) conversion rules setting. - */ -typedef struct { - union { - struct { - uint8_t atten: 2; /*!< ADC sampling voltage attenuation configuration. Modification of attenuation affects the range of measurements. - 0: measurement range 0 - 800mV, - 1: measurement range 0 - 1100mV, - 2: measurement range 0 - 1350mV, - 3: measurement range 0 - 2600mV. */ -#if CONFIG_IDF_TARGET_ESP32 - uint8_t bit_width: 2; /*!< ADC resolution. -- 0: 9 bit; -- 1: 10 bit; -- 2: 11 bit; -- 3: 12 bit. */ - int8_t channel: 4; /*!< ADC channel index. */ -#elif CONFIG_IDF_TARGET_ESP32S2 - uint8_t reserved: 2; /*!< reserved0 */ - uint8_t channel: 4; /*!< ADC channel index. */ -#elif CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2 - uint8_t channel: 3; /*!< ADC channel index. */ - uint8_t unit: 1; /*!< ADC unit index. */ - uint8_t reserved: 2; /*!< reserved0 */ -#endif - }; - uint8_t val; /*! ADC_CHANNEL_MAX), The data is invalid. */ - } type1; /*! ADC_CHANNEL_MAX), The data is invalid. */ + uint32_t unit: 1; /*! 0 /** diff --git a/tools/sdk/esp32/include/hal/include/hal/emac_hal.h b/tools/sdk/esp32/include/hal/include/hal/emac_hal.h index f661e58985a..27cd38456dc 100644 --- a/tools/sdk/esp32/include/hal/include/hal/emac_hal.h +++ b/tools/sdk/esp32/include/hal/include/hal/emac_hal.h @@ -1,16 +1,8 @@ -// Copyright 2021 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once @@ -220,9 +212,23 @@ uint32_t emac_hal_get_phy_data(emac_hal_context_t *hal); void emac_hal_set_address(emac_hal_context_t *hal, uint8_t *mac_addr); +/** + * @brief Starts EMAC Transmission & Reception + * + * @param hal EMAC HAL context infostructure + */ void emac_hal_start(emac_hal_context_t *hal); -void emac_hal_stop(emac_hal_context_t *hal); +/** + * @brief Stops EMAC Transmission & Reception + * + * @param hal EMAC HAL context infostructure + * @return + * - ESP_OK: succeed + * - ESP_ERR_INVALID_STATE: previous frame transmission/reception is not completed. When this error occurs, + * wait and reapeat the EMAC stop again. + */ +esp_err_t emac_hal_stop(emac_hal_context_t *hal); uint32_t emac_hal_get_tx_desc_owner(emac_hal_context_t *hal); diff --git a/tools/sdk/esp32/include/hal/include/hal/gpio_types.h b/tools/sdk/esp32/include/hal/include/hal/gpio_types.h index a9b56f7c6a3..1678689961f 100644 --- a/tools/sdk/esp32/include/hal/include/hal/gpio_types.h +++ b/tools/sdk/esp32/include/hal/include/hal/gpio_types.h @@ -302,7 +302,6 @@ typedef enum { GPIO_NUM_19 = 19, /*!< GPIO19, input and output */ GPIO_NUM_20 = 20, /*!< GPIO20, input and output */ GPIO_NUM_21 = 21, /*!< GPIO21, input and output */ - GPIO_NUM_22 = 22, /*!< GPIO22, input and output */ GPIO_NUM_MAX, /** @endcond */ } gpio_num_t; diff --git a/tools/sdk/esp32/include/hal/include/hal/i2s_types.h b/tools/sdk/esp32/include/hal/include/hal/i2s_types.h index 48d745eb2fa..dcf0ab4d0b8 100644 --- a/tools/sdk/esp32/include/hal/include/hal/i2s_types.h +++ b/tools/sdk/esp32/include/hal/include/hal/i2s_types.h @@ -1,16 +1,8 @@ -// Copyright 2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once @@ -52,31 +44,31 @@ typedef enum { * */ typedef enum { - I2S_CHANNEL_MONO = (0x01 << 31) | 0x03, /*!< I2S channel (mono), two channel enabled. In this mode, you only need to send one channel data but the fifo will copy same data for another channel automatically, then both channels will transmit same data. The highest bit is for differentiating I2S_CHANNEL_STEREO since they both use two channels */ - I2S_CHANNEL_STEREO = 0x03, /*!< I2S channel (stereo), two channel enabled. In this mode, two channels will transmit different data. */ + I2S_CHANNEL_MONO = 1, /*!< I2S channel (mono), one channel activated. In this mode, you only need to send one channel data but the fifo will copy same data for the other unactivated channels automatically, then both channels will transmit same data. */ + I2S_CHANNEL_STEREO = 2, /*!< I2S channel (stereo), two (or more) channels activated. In this mode, these channels will transmit different data. */ #if SOC_I2S_SUPPORTS_TDM - // Bit map of active chan. + // Bit map of activated chan. // There are 16 channels in TDM mode. - // For TX module, only the active channel send the audio data, the inactive channel send a constant(configurable) or will be skiped if 'skip_msk' is set. - // For RX module, only receive the audio data in active channels, the data in inactive channels will be ignored. - // the bit map of active channel can not exceed (0x1< #include #include "soc/usbh_struct.h" -#include "soc/usb_wrap_struct.h" #include "hal/usbh_ll.h" #include "hal/usb_types_private.h" #include "hal/assert.h" @@ -152,7 +151,6 @@ typedef struct { typedef struct { //Context usbh_dev_t *dev; /**< Pointer to base address of DWC_OTG registers */ - usb_wrap_dev_t *wrap_dev; /**< Pointer to base address of USB Wrapper registers */ //Host Port related uint32_t *periodic_frame_list; /**< Pointer to scheduling frame list */ usb_hal_frame_list_len_t frame_list_len; /**< Length of the periodic scheduling frame list */ @@ -181,6 +179,7 @@ typedef struct { * * Entry: * - The peripheral must have been reset and clock un-gated + * - The USB PHY (internal or external) and associated GPIOs must already be configured * - GPIO pins configured * - Interrupt allocated but DISABLED (in case of an unknown interupt state) * Exit: @@ -495,7 +494,7 @@ static inline void usbh_hal_disable_debounce_lock(usbh_hal_context_t *hal) hal->flags.dbnc_lock_enabled = 0; //Clear Conenction and disconenction interrupt in case it triggered again usb_ll_intr_clear(hal->dev, USB_LL_INTR_CORE_DISCONNINT); - usbh_ll_hprt_intr_clear(hal->dev, USBH_LL_INTR_HPRT_PRTENCHNG); + usbh_ll_hprt_intr_clear(hal->dev, USBH_LL_INTR_HPRT_PRTCONNDET); //Reenable the hprt (connection) and disconnection interrupts usb_ll_en_intrs(hal->dev, USB_LL_INTR_CORE_PRTINT | USB_LL_INTR_CORE_DISCONNINT); } diff --git a/tools/sdk/esp32/include/hal/include/hal/usbh_ll.h b/tools/sdk/esp32/include/hal/include/hal/usbh_ll.h index 63f7b8219d1..4320ead0a3b 100644 --- a/tools/sdk/esp32/include/hal/include/hal/usbh_ll.h +++ b/tools/sdk/esp32/include/hal/include/hal/usbh_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -13,7 +13,6 @@ extern "C" { #include #include #include "soc/usbh_struct.h" -#include "soc/usb_wrap_struct.h" #include "hal/usb_types_private.h" #include "hal/misc.h" @@ -153,25 +152,6 @@ typedef struct { uint8_t *buffer; } usbh_ll_dma_qtd_t; -/* ----------------------------------------------------------------------------- ------------------------------- USB Wrap Registers ------------------------------ ------------------------------------------------------------------------------ */ - -/** - * @brief Configures the internal PHY to operate as HOST - * - * @param hw Start address of the USB Wrap registers - */ -static inline void usbh_ll_internal_phy_conf(usb_wrap_dev_t *hw) -{ - //Enable internal PHY - hw->otg_conf.pad_enable = 1; - hw->otg_conf.phy_sel = 0; - //Set pulldowns on D+ and D- - hw->otg_conf.pad_pull_override = 1; - hw->otg_conf.dp_pulldown = 1; - hw->otg_conf.dm_pulldown = 1; -} /* ----------------------------------------------------------------------------- ------------------------------- Global Registers ------------------------------- @@ -431,7 +411,7 @@ static inline void usbh_ll_hcfg_set_fsls_pclk_sel(usbh_dev_t *hw) /** * @brief Sets some default values to HCFG to operate in Host mode with scatter/gather DMA * - * @param hw Start address of the USB Wrap registers + * @param hw Start address of the DWC_OTG registers * @param speed Speed to initialize the host port at */ static inline void usbh_ll_hcfg_set_defaults(usbh_dev_t *hw, usb_priv_speed_t speed) diff --git a/tools/sdk/esp32/include/idf_test/include/esp32/idf_performance_target.h b/tools/sdk/esp32/include/idf_test/include/esp32/idf_performance_target.h index 5700d9f39ed..d6b64df99a7 100644 --- a/tools/sdk/esp32/include/idf_test/include/esp32/idf_performance_target.h +++ b/tools/sdk/esp32/include/idf_test/include/esp32/idf_performance_target.h @@ -33,88 +33,6 @@ #define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING 30 #define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING_NO_DMA 27 -/* - * Flash Performance value - * 4 subsections: legacy, normal (new driver after v4.0), SPI1 (external but on SPI1), external (SPI2) - * These thresholds are set to about 70% of the average test data, under certain condition. - * Contact Espressif for details. - */ -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_4B -//The single_core config is much faster than other configs. Use the value of other configs -//Collect data and correct it later -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_4B -//The single_core config is much faster than other configs. Use the value of other configs -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_4B 35300 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_2KB (697*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_2KB (6780*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_ERASE 11200 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_4B -//The single_core config is much faster than other configs. Use the value of other configs -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_4B 20100 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_4B -//The single_core config is much faster than other configs. Use the value of other configs -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_4B 35200 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_2KB (754*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_2KB (6650*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_ERASE 45300 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_4B -//The single_core config is much faster than other configs. Use the value of other configs -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_4B 16200 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_4B -//The single_core config is much faster than other configs. Use the value of other configs -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_4B 33600 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_2KB (484*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_2KB (1512*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_ERASE 49600 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_4B -//Collect data and correct it later -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_4B (261*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_2KB (470*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_2KB (261*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_ERASE 30900 -#endif - // floating point instructions per divide and per sqrt (configured for worst-case with PSRAM workaround) #define IDF_PERFORMANCE_MAX_CYCLES_PER_DIV 70 #define IDF_PERFORMANCE_MAX_CYCLES_PER_SQRT 140 diff --git a/tools/sdk/esp32/include/idf_test/include/esp32c3/idf_performance_target.h b/tools/sdk/esp32/include/idf_test/include/esp32c3/idf_performance_target.h index c77e3efb1ec..7fbf8b9eaf5 100644 --- a/tools/sdk/esp32/include/idf_test/include/esp32c3/idf_performance_target.h +++ b/tools/sdk/esp32/include/idf_test/include/esp32c3/idf_performance_target.h @@ -29,85 +29,6 @@ #define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING 32 #define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING_NO_DMA 30 -/* - * Flash Performance value - * 4 subsections: legacy, normal (new driver after v4.0), SPI1 (external but on SPI1), external (SPI2) - * These thresholds are set to about 70% of the average test data, under certain condition. - * Contact Espressif for details. - */ -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_4B -// rom options is much slower. use its 70% -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_4B 42200 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_4B -// legacy & suspend config are much faster. use the 70% of slower configs -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_4B (179*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_2KB (622*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_2KB (6536*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_ERASE 23700 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_4B 46400 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_4B -// legacy & suspend config are much faster. use the 70% of slower configs -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_4B (183*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_2KB (605*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_2KB (6676*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_ERASE 22900 -#endif - -// No SPI1 tests for C3 -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_2KB 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_2KB 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_ERASE 0 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_4B 43300 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_4B -// rom options is much slower. use its 70% -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_4B 99500 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_2KB (300*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_2KB (754*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_ERASE 33900 -#endif - // floating point instructions per divide and per sqrt (configured for worst-case with PSRAM workaround) #define IDF_PERFORMANCE_MAX_CYCLES_PER_DIV 70 #define IDF_PERFORMANCE_MAX_CYCLES_PER_SQRT 140 diff --git a/tools/sdk/esp32/include/idf_test/include/esp32h2/idf_performance_target.h b/tools/sdk/esp32/include/idf_test/include/esp32h2/idf_performance_target.h index af5738d1fcd..7fbf8b9eaf5 100644 --- a/tools/sdk/esp32/include/idf_test/include/esp32h2/idf_performance_target.h +++ b/tools/sdk/esp32/include/idf_test/include/esp32h2/idf_performance_target.h @@ -29,42 +29,6 @@ #define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING 32 #define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING_NO_DMA 30 -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_4B 53400 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_2KB (701*1000) -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_4B 53600 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_ERASE -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_ERASE 44300 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_4B 24400 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_4B 64900 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_4B (309*1000) -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_2KB (1697*1000) -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_ERASE -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_ERASE 76600 -#endif - // floating point instructions per divide and per sqrt (configured for worst-case with PSRAM workaround) #define IDF_PERFORMANCE_MAX_CYCLES_PER_DIV 70 #define IDF_PERFORMANCE_MAX_CYCLES_PER_SQRT 140 diff --git a/tools/sdk/esp32/include/idf_test/include/esp32s2/idf_performance_target.h b/tools/sdk/esp32/include/idf_test/include/esp32s2/idf_performance_target.h index dc8a060f54b..cd037bb47d7 100644 --- a/tools/sdk/esp32/include/idf_test/include/esp32s2/idf_performance_target.h +++ b/tools/sdk/esp32/include/idf_test/include/esp32s2/idf_performance_target.h @@ -25,82 +25,3 @@ #define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING 32 #define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING_NO_DMA 30 - -/* - * Flash Performance value - * 4 subsections: legacy, normal (new driver after v4.0), SPI1 (external but on SPI1), external (SPI2) - * These thresholds are set to about 70% of the average test data, under certain condition. - * Contact Espressif for details. - */ -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_4B -//Great variation, use the 70% of min value -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_4B 33300 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_4B -// legacy config is much faster. use the 70% of slower configs -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_4B (239*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_2KB -// Weird data. Use 70% average of slower configs. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_2KB (546*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_2KB (1191*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_ERASE 19500 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_4B -//release config is much faster than other configs. Use 70% average of other configs -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_4B 46300 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_4B (249*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_2KB (851*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_2KB (11480*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_ERASE 40100 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_4B 30500 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_4B (183*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_2KB (474*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_2KB (1283*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_ERASE 44100 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_4B 47800 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_4B (252*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_2KB -// write with large RAM buffer tests has lower performance value than normal performance tests -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_2KB (398*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_2KB (1204*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_ERASE 22100 -#endif diff --git a/tools/sdk/esp32/include/idf_test/include/esp32s3/idf_performance_target.h b/tools/sdk/esp32/include/idf_test/include/esp32s3/idf_performance_target.h index b744cda8fa0..d735bb27023 100644 --- a/tools/sdk/esp32/include/idf_test/include/esp32s3/idf_performance_target.h +++ b/tools/sdk/esp32/include/idf_test/include/esp32s3/idf_performance_target.h @@ -24,82 +24,6 @@ #define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING 32 #define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING_NO_DMA 30 -/* - * Flash Performance value - * 4 subsections: legacy, normal (new driver after v4.0), SPI1 (external but on SPI1), external (SPI2) - * These thresholds are set to about 70% of the average test data, under certain condition. - * Contact Espressif for details. - * - * Currently all performance data on S3 are set to 0 for now. Update to a proper value later. - */ -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_2KB 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_2KB 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_ERASE 0 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_2KB 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_2KB 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_ERASE 0 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_2KB 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_2KB 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_ERASE 0 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_2KB 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_2KB 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_ERASE 0 -#endif - // floating point instructions per divide and per sqrt (configured for worst-case with PSRAM workaround) #define IDF_PERFORMANCE_MAX_CYCLES_PER_DIV 70 #define IDF_PERFORMANCE_MAX_CYCLES_PER_SQRT 140 diff --git a/tools/sdk/esp32/include/json_generator/json_generator.h b/tools/sdk/esp32/include/json_generator/upstream/json_generator.h old mode 100755 new mode 100644 similarity index 90% rename from tools/sdk/esp32/include/json_generator/json_generator.h rename to tools/sdk/esp32/include/json_generator/upstream/json_generator.h index 2dc527d0e95..e3aa92eeecf --- a/tools/sdk/esp32/include/json_generator/json_generator.h +++ b/tools/sdk/esp32/include/json_generator/upstream/json_generator.h @@ -1,11 +1,26 @@ -/** \file json_gen_generator.h - * \brief JSON String Generator +/* + * Copyright 2020 Piyush Shah + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * JSON String Generator * * This module can be used to create JSON strings with a facility * to flush out data if the destination buffer is full. All commas * and colons as required are automatically added by the APIs * - * Code taken from: https://github.com/shahpiyushv/json_gen_generator */ #ifndef _JSON_GENERATOR_H #define _JSON_GENERATOR_H @@ -18,7 +33,10 @@ extern "C" { #endif +/** Float precision i.e. number of digits after decimal point */ +#ifndef JSON_FLOAT_PRECISION #define JSON_FLOAT_PRECISION 5 +#endif /** JSON string flush callback prototype * @@ -38,12 +56,20 @@ typedef void (*json_gen_flush_cb_t) (char *buf, void *priv); * Just define this structure and pass a pointer to it in the APIs below */ typedef struct { + /** Pointer to the JSON buffer provided by the calling function */ char *buf; + /** Size of the above buffer */ int buf_size; + /** (Optional) callback function to invoke when the buffer gets full */ json_gen_flush_cb_t flush_cb; + /** (Optional) Private data to pass to the callback function */ void *priv; + /** (For Internal use only) */ bool comma_req; + /** (For Internal use only) */ char *free_ptr; + /** Total length */ + int total_len; } json_gen_str_t; /** Start a JSON String @@ -58,11 +84,11 @@ typedef struct { * \param[out] buf Pointer to an allocated buffer into which the JSON * string will be written * \param[in] buf_size Size of the buffer - * \param[in] Pointer to the flushing function of type \ref json_gen_flush_cb_t + * \param[in] flush_cb Pointer to the flushing function of type \ref json_gen_flush_cb_t * which will be invoked either when the buffer is full or when json_gen_str_end() * is invoked. Can be left NULL. * \param[in] priv Private data to be passed to the flushing function callback. - * Can be something like a session identifier (Eg. socket). Can be left NULL + * Can be something like a session identifier (Eg. socket). Can be left NULL. */ void json_gen_str_start(json_gen_str_t *jstr, char *buf, int buf_size, json_gen_flush_cb_t flush_cb, void *priv); @@ -72,16 +98,18 @@ void json_gen_str_start(json_gen_str_t *jstr, char *buf, int buf_size, * This should be the last function to be called after the entire JSON string * has been generated. * - * \param[in] jstr Pointer to the \ref json_gen_str_t structure initilised by + * \param[in] jstr Pointer to the \ref json_gen_str_t structure initialised by * json_gen_str_start() + * + * \return Total length of the JSON created, including the NULL termination byte. */ -void json_gen_str_end(json_gen_str_t *jstr); +int json_gen_str_end(json_gen_str_t *jstr); /** Start a JSON object * * This starts a JSON object by adding a '{' * - * \param[in] jstr Pointer to the \ref json_gen_str_t structure initilised by + * \param[in] jstr Pointer to the \ref json_gen_str_t structure initialised by * json_gen_str_start() * * \return 0 on Success @@ -95,7 +123,7 @@ int json_gen_start_object(json_gen_str_t *jstr); * * This ends a JSON object by adding a '}' * - * \param[in] jstr Pointer to the \ref json_gen_str_t structure initilised by + * \param[in] jstr Pointer to the \ref json_gen_str_t structure initialised by * json_gen_str_start() * * \return 0 on Success @@ -109,7 +137,7 @@ int json_gen_end_object(json_gen_str_t *jstr); * * This starts a JSON object by adding a '[' * - * \param[in] jstr Pointer to the \ref json_gen_str_t structure initilised by + * \param[in] jstr Pointer to the \ref json_gen_str_t structure initialised by * json_gen_str_start() * * \return 0 on Success @@ -123,7 +151,7 @@ int json_gen_start_array(json_gen_str_t *jstr); * * This ends a JSON object by adding a ']' * - * \param[in] jstr Pointer to the \ref json_gen_str_t structure initilised by + * \param[in] jstr Pointer to the \ref json_gen_str_t structure initialised by * json_gen_str_start() * * \return 0 on Success @@ -137,7 +165,7 @@ int json_gen_end_array(json_gen_str_t *jstr); * * This adds a JSON object like "name":{ * - * \param[in] jstr Pointer to the \ref json_gen_str_t structure initilised by + * \param[in] jstr Pointer to the \ref json_gen_str_t structure initialised by * json_gen_str_start() * \param[in] name Name of the object * @@ -153,7 +181,7 @@ int json_gen_push_object(json_gen_str_t *jstr, char *name); * This ends a JSON object by adding a '}'. This is basically same as * json_gen_end_object() but included so as to complement json_gen_push_object() * - * \param[in] jstr Pointer to the \ref json_gen_str_t structure initilised by + * \param[in] jstr Pointer to the \ref json_gen_str_t structure initialised by * json_gen_str_start() * * \return 0 on Success @@ -170,7 +198,7 @@ int json_gen_pop_object(json_gen_str_t *jstr); * Eg. json_gen_push_object_str(jstr, "pre-formatted", "{\"a\":1,\"b\":2}"); * This will add "pre-formatted":{"a":1,"b":2} * - * \param[in] jstr Pointer to the \ref json_gen_str_t structure initilised by + * \param[in] jstr Pointer to the \ref json_gen_str_t structure initialised by * json_gen_str_start() * \param[in] name Name of the JSON object string * \param[in] object_str The pre-formatted JSON object string @@ -186,7 +214,7 @@ int json_gen_push_object_str(json_gen_str_t *jstr, char *name, char *object_str) * * This adds a JSON array like "name":[ * - * \param[in] jstr Pointer to the \ref json_gen_str_t structure initilised by + * \param[in] jstr Pointer to the \ref json_gen_str_t structure initialised by * json_gen_str_start() * \param[in] name Name of the array * @@ -202,7 +230,7 @@ int json_gen_push_array(json_gen_str_t *jstr, char *name); * This ends a JSON array by adding a ']'. This is basically same as * json_gen_end_array() but included so as to complement json_gen_push_array() * - * \param[in] jstr Pointer to the \ref json_gen_str_t structure initilised by + * \param[in] jstr Pointer to the \ref json_gen_str_t structure initialised by * json_gen_str_start() * * \return 0 on Success @@ -219,7 +247,7 @@ int json_gen_pop_array(json_gen_str_t *jstr); * Eg. json_gen_push_object_str(jstr, "pre-formatted", "[1,2,3]"); * This will add "pre-formatted":[1,2,3] * - * \param[in] jstr Pointer to the \ref json_gen_str_t structure initilised by + * \param[in] jstr Pointer to the \ref json_gen_str_t structure initialised by * json_gen_str_start() * \param[in] name Name of the JSON array string * \param[in] array_str The pre-formatted JSON array string @@ -238,7 +266,7 @@ int json_gen_push_array_str(json_gen_str_t *jstr, char *name, char *array_str); * \note This must be called between json_gen_start_object()/json_gen_push_object() * and json_gen_end_object()/json_gen_pop_object() * - * \param[in] jstr Pointer to the \ref json_gen_str_t structure initilised by + * \param[in] jstr Pointer to the \ref json_gen_str_t structure initialised by * json_gen_str_start() * \param[in] name Name of the element * \param[in] val Boolean value of the element @@ -257,7 +285,7 @@ int json_gen_obj_set_bool(json_gen_str_t *jstr, char *name, bool val); * \note This must be called between json_gen_start_object()/json_gen_push_object() * and json_gen_end_object()/json_gen_pop_object() * - * \param[in] jstr Pointer to the \ref json_gen_str_t structure initilised by + * \param[in] jstr Pointer to the \ref json_gen_str_t structure initialised by * json_gen_str_start() * \param[in] name Name of the element * \param[in] val Integer value of the element @@ -276,7 +304,7 @@ int json_gen_obj_set_int(json_gen_str_t *jstr, char *name, int val); * \note This must be called between json_gen_start_object()/json_gen_push_object() * and json_gen_end_object()/json_gen_pop_object() * - * \param[in] jstr Pointer to the \ref json_gen_str_t structure initilised by + * \param[in] jstr Pointer to the \ref json_gen_str_t structure initialised by * json_gen_str_start() * \param[in] name Name of the element * \param[in] val Float value of the element @@ -295,7 +323,7 @@ int json_gen_obj_set_float(json_gen_str_t *jstr, char *name, float val); * \note This must be called between json_gen_start_object()/json_gen_push_object() * and json_gen_end_object()/json_gen_pop_object() * - * \param[in] jstr Pointer to the \ref json_gen_str_t structure initilised by + * \param[in] jstr Pointer to the \ref json_gen_str_t structure initialised by * json_gen_str_start() * \param[in] name Name of the element * \param[in] val Null terminated string value of the element @@ -314,7 +342,7 @@ int json_gen_obj_set_string(json_gen_str_t *jstr, char *name, char *val); * \note This must be called between json_gen_start_object()/json_gen_push_object() * and json_gen_end_object()/json_gen_pop_object() * - * \param[in] jstr Pointer to the \ref json_gen_str_t structure initilised by + * \param[in] jstr Pointer to the \ref json_gen_str_t structure initialised by * json_gen_str_start() * \param[in] name Name of the element * @@ -330,7 +358,7 @@ int json_gen_obj_set_null(json_gen_str_t *jstr, char *name); * \note This must be called between json_gen_start_array()/json_gen_push_array() * and json_gen_end_array()/json_gen_pop_array() * - * \param[in] jstr Pointer to the \ref json_gen_str_t structure initilised by + * \param[in] jstr Pointer to the \ref json_gen_str_t structure initialised by * json_gen_str_start() * \param[in] val Boolean value of the element * @@ -346,7 +374,7 @@ int json_gen_arr_set_bool(json_gen_str_t *jstr, bool val); * \note This must be called between json_gen_start_array()/json_gen_push_array() * and json_gen_end_array()/json_gen_pop_array() * - * \param[in] jstr Pointer to the \ref json_gen_str_t structure initilised by + * \param[in] jstr Pointer to the \ref json_gen_str_t structure initialised by * json_gen_str_start() * \param[in] val Integer value of the element * @@ -362,7 +390,7 @@ int json_gen_arr_set_int(json_gen_str_t *jstr, int val); * \note This must be called between json_gen_start_array()/json_gen_push_array() * and json_gen_end_array()/json_gen_pop_array() * - * \param[in] jstr Pointer to the \ref json_gen_str_t structure initilised by + * \param[in] jstr Pointer to the \ref json_gen_str_t structure initialised by * json_gen_str_start() * \param[in] val Float value of the element * @@ -378,7 +406,7 @@ int json_gen_arr_set_float(json_gen_str_t *jstr, float val); * \note This must be called between json_gen_start_array()/json_gen_push_array() * and json_gen_end_array()/json_gen_pop_array() * - * \param[in] jstr Pointer to the \ref json_gen_str_t structure initilised by + * \param[in] jstr Pointer to the \ref json_gen_str_t structure initialised by * json_gen_str_start() * \param[in] val Null terminated string value of the element * @@ -394,7 +422,7 @@ int json_gen_arr_set_string(json_gen_str_t *jstr, char *val); * \note This must be called between json_gen_start_array()/json_gen_push_array() * and json_gen_end_array()/json_gen_pop_array() * - * \param[in] jstr Pointer to the \ref json_gen_str_t structure initilised by + * \param[in] jstr Pointer to the \ref json_gen_str_t structure initialised by * json_gen_str_start() * * \return 0 on Success @@ -414,7 +442,7 @@ int json_gen_arr_set_null(json_gen_str_t *jstr); * \note This must be called between json_gen_start_object()/json_gen_push_object() * and json_gen_end_object()/json_gen_pop_object() * - * \param[in] jstr Pointer to the \ref json_gen_str_t structure initilised by + * \param[in] jstr Pointer to the \ref json_gen_str_t structure initialised by * json_gen_str_start() * \param[in] name Name of the element * \param[in] val Null terminated initial part of the string value. It can also be NULL @@ -436,7 +464,7 @@ int json_gen_obj_start_long_string(json_gen_str_t *jstr, char *name, char *val); * \note This must be called between json_gen_start_array()/json_gen_push_array() * and json_gen_end_array()/json_gen_pop_array() * - * \param[in] jstr Pointer to the \ref json_gen_str_t structure initilised by + * \param[in] jstr Pointer to the \ref json_gen_str_t structure initialised by * json_gen_str_start() * \param[in] val Null terminated initial part of the string value. It can also be NULL * @@ -453,7 +481,7 @@ int json_gen_arr_start_long_string(json_gen_str_t *jstr, char *val); * json_gen_arr_start_long_string(). After the entire string is created, it should be terminated * with json_gen_end_long_string(). * - * \param[in] jstr Pointer to the \ref json_gen_str_t structure initilised by json_gen_str_start() + * \param[in] jstr Pointer to the \ref json_gen_str_t structure initialised by json_gen_str_start() * \param[in] val Null terminated extending part of the string value. * * \return 0 on Success @@ -468,7 +496,7 @@ int json_gen_add_to_long_string(json_gen_str_t *jstr, char *val); * This ends the string initialised by json_gen_obj_start_long_string() or * json_gen_arr_start_long_string() by adding the ending quotes. * - * \param[in] jstr Pointer to the \ref json_gen_str_t structure initilised by json_gen_str_start() + * \param[in] jstr Pointer to the \ref json_gen_str_t structure initialised by json_gen_str_start() * * * \return 0 on Success @@ -477,9 +505,7 @@ int json_gen_add_to_long_string(json_gen_str_t *jstr, char *val); * added after that */ int json_gen_end_long_string(json_gen_str_t *jstr); - #ifdef __cplusplus } #endif - #endif diff --git a/tools/sdk/esp32/include/json_parser/json_parser.h b/tools/sdk/esp32/include/json_parser/upstream/include/json_parser.h old mode 100755 new mode 100644 similarity index 73% rename from tools/sdk/esp32/include/json_parser/json_parser.h rename to tools/sdk/esp32/include/json_parser/upstream/include/json_parser.h index 7233caa3f3e..3e982fe14eb --- a/tools/sdk/esp32/include/json_parser/json_parser.h +++ b/tools/sdk/esp32/include/json_parser/upstream/include/json_parser.h @@ -1,8 +1,23 @@ -/* Code taken from: https://github.com/shahpiyushv/json_parser */ +/* + * Copyright 2020 Piyush Shah + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #ifndef _JSON_PARSER_H_ #define _JSON_PARSER_H_ -#include +#define JSMN_HEADER +#include #include #include @@ -14,8 +29,8 @@ extern "C" #define OS_SUCCESS 0 #define OS_FAIL -1 -typedef _jsmn_parser json_parser_t; -typedef _jsmntok_t json_tok_t; +typedef jsmn_parser json_parser_t; +typedef jsmntok_t json_tok_t; typedef struct { json_parser_t parser; diff --git a/tools/sdk/esp32/include/json_parser/upstream/jsmn/jsmn.h b/tools/sdk/esp32/include/json_parser/upstream/jsmn/jsmn.h new file mode 100644 index 00000000000..3178dcc977f --- /dev/null +++ b/tools/sdk/esp32/include/json_parser/upstream/jsmn/jsmn.h @@ -0,0 +1,471 @@ +/* + * MIT License + * + * Copyright (c) 2010 Serge Zaitsev + * + * 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. + */ +#ifndef JSMN_H +#define JSMN_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef JSMN_STATIC +#define JSMN_API static +#else +#define JSMN_API extern +#endif + +/** + * JSON type identifier. Basic types are: + * o Object + * o Array + * o String + * o Other primitive: number, boolean (true/false) or null + */ +typedef enum { + JSMN_UNDEFINED = 0, + JSMN_OBJECT = 1, + JSMN_ARRAY = 2, + JSMN_STRING = 3, + JSMN_PRIMITIVE = 4 +} jsmntype_t; + +enum jsmnerr { + /* Not enough tokens were provided */ + JSMN_ERROR_NOMEM = -1, + /* Invalid character inside JSON string */ + JSMN_ERROR_INVAL = -2, + /* The string is not a full JSON packet, more bytes expected */ + JSMN_ERROR_PART = -3 +}; + +/** + * JSON token description. + * type type (object, array, string etc.) + * start start position in JSON data string + * end end position in JSON data string + */ +typedef struct jsmntok { + jsmntype_t type; + int start; + int end; + int size; +#ifdef JSMN_PARENT_LINKS + int parent; +#endif +} jsmntok_t; + +/** + * JSON parser. Contains an array of token blocks available. Also stores + * the string being parsed now and current position in that string. + */ +typedef struct jsmn_parser { + unsigned int pos; /* offset in the JSON string */ + unsigned int toknext; /* next token to allocate */ + int toksuper; /* superior token node, e.g. parent object or array */ +} jsmn_parser; + +/** + * Create JSON parser over an array of tokens + */ +JSMN_API void jsmn_init(jsmn_parser *parser); + +/** + * Run JSON parser. It parses a JSON data string into and array of tokens, each + * describing + * a single JSON object. + */ +JSMN_API int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len, + jsmntok_t *tokens, const unsigned int num_tokens); + +#ifndef JSMN_HEADER +/** + * Allocates a fresh unused token from the token pool. + */ +static jsmntok_t *jsmn_alloc_token(jsmn_parser *parser, jsmntok_t *tokens, + const size_t num_tokens) { + jsmntok_t *tok; + if (parser->toknext >= num_tokens) { + return NULL; + } + tok = &tokens[parser->toknext++]; + tok->start = tok->end = -1; + tok->size = 0; +#ifdef JSMN_PARENT_LINKS + tok->parent = -1; +#endif + return tok; +} + +/** + * Fills token type and boundaries. + */ +static void jsmn_fill_token(jsmntok_t *token, const jsmntype_t type, + const int start, const int end) { + token->type = type; + token->start = start; + token->end = end; + token->size = 0; +} + +/** + * Fills next available token with JSON primitive. + */ +static int jsmn_parse_primitive(jsmn_parser *parser, const char *js, + const size_t len, jsmntok_t *tokens, + const size_t num_tokens) { + jsmntok_t *token; + int start; + + start = parser->pos; + + for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) { + switch (js[parser->pos]) { +#ifndef JSMN_STRICT + /* In strict mode primitive must be followed by "," or "}" or "]" */ + case ':': +#endif + case '\t': + case '\r': + case '\n': + case ' ': + case ',': + case ']': + case '}': + goto found; + default: + /* to quiet a warning from gcc*/ + break; + } + if (js[parser->pos] < 32 || js[parser->pos] >= 127) { + parser->pos = start; + return JSMN_ERROR_INVAL; + } + } +#ifdef JSMN_STRICT + /* In strict mode primitive must be followed by a comma/object/array */ + parser->pos = start; + return JSMN_ERROR_PART; +#endif + +found: + if (tokens == NULL) { + parser->pos--; + return 0; + } + token = jsmn_alloc_token(parser, tokens, num_tokens); + if (token == NULL) { + parser->pos = start; + return JSMN_ERROR_NOMEM; + } + jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos); +#ifdef JSMN_PARENT_LINKS + token->parent = parser->toksuper; +#endif + parser->pos--; + return 0; +} + +/** + * Fills next token with JSON string. + */ +static int jsmn_parse_string(jsmn_parser *parser, const char *js, + const size_t len, jsmntok_t *tokens, + const size_t num_tokens) { + jsmntok_t *token; + + int start = parser->pos; + + parser->pos++; + + /* Skip starting quote */ + for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) { + char c = js[parser->pos]; + + /* Quote: end of string */ + if (c == '\"') { + if (tokens == NULL) { + return 0; + } + token = jsmn_alloc_token(parser, tokens, num_tokens); + if (token == NULL) { + parser->pos = start; + return JSMN_ERROR_NOMEM; + } + jsmn_fill_token(token, JSMN_STRING, start + 1, parser->pos); +#ifdef JSMN_PARENT_LINKS + token->parent = parser->toksuper; +#endif + return 0; + } + + /* Backslash: Quoted symbol expected */ + if (c == '\\' && parser->pos + 1 < len) { + int i; + parser->pos++; + switch (js[parser->pos]) { + /* Allowed escaped symbols */ + case '\"': + case '/': + case '\\': + case 'b': + case 'f': + case 'r': + case 'n': + case 't': + break; + /* Allows escaped symbol \uXXXX */ + case 'u': + parser->pos++; + for (i = 0; i < 4 && parser->pos < len && js[parser->pos] != '\0'; + i++) { + /* If it isn't a hex character we have an error */ + if (!((js[parser->pos] >= 48 && js[parser->pos] <= 57) || /* 0-9 */ + (js[parser->pos] >= 65 && js[parser->pos] <= 70) || /* A-F */ + (js[parser->pos] >= 97 && js[parser->pos] <= 102))) { /* a-f */ + parser->pos = start; + return JSMN_ERROR_INVAL; + } + parser->pos++; + } + parser->pos--; + break; + /* Unexpected symbol */ + default: + parser->pos = start; + return JSMN_ERROR_INVAL; + } + } + } + parser->pos = start; + return JSMN_ERROR_PART; +} + +/** + * Parse JSON string and fill tokens. + */ +JSMN_API int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len, + jsmntok_t *tokens, const unsigned int num_tokens) { + int r; + int i; + jsmntok_t *token; + int count = parser->toknext; + + for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) { + char c; + jsmntype_t type; + + c = js[parser->pos]; + switch (c) { + case '{': + case '[': + count++; + if (tokens == NULL) { + break; + } + token = jsmn_alloc_token(parser, tokens, num_tokens); + if (token == NULL) { + return JSMN_ERROR_NOMEM; + } + if (parser->toksuper != -1) { + jsmntok_t *t = &tokens[parser->toksuper]; +#ifdef JSMN_STRICT + /* In strict mode an object or array can't become a key */ + if (t->type == JSMN_OBJECT) { + return JSMN_ERROR_INVAL; + } +#endif + t->size++; +#ifdef JSMN_PARENT_LINKS + token->parent = parser->toksuper; +#endif + } + token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY); + token->start = parser->pos; + parser->toksuper = parser->toknext - 1; + break; + case '}': + case ']': + if (tokens == NULL) { + break; + } + type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY); +#ifdef JSMN_PARENT_LINKS + if (parser->toknext < 1) { + return JSMN_ERROR_INVAL; + } + token = &tokens[parser->toknext - 1]; + for (;;) { + if (token->start != -1 && token->end == -1) { + if (token->type != type) { + return JSMN_ERROR_INVAL; + } + token->end = parser->pos + 1; + parser->toksuper = token->parent; + break; + } + if (token->parent == -1) { + if (token->type != type || parser->toksuper == -1) { + return JSMN_ERROR_INVAL; + } + break; + } + token = &tokens[token->parent]; + } +#else + for (i = parser->toknext - 1; i >= 0; i--) { + token = &tokens[i]; + if (token->start != -1 && token->end == -1) { + if (token->type != type) { + return JSMN_ERROR_INVAL; + } + parser->toksuper = -1; + token->end = parser->pos + 1; + break; + } + } + /* Error if unmatched closing bracket */ + if (i == -1) { + return JSMN_ERROR_INVAL; + } + for (; i >= 0; i--) { + token = &tokens[i]; + if (token->start != -1 && token->end == -1) { + parser->toksuper = i; + break; + } + } +#endif + break; + case '\"': + r = jsmn_parse_string(parser, js, len, tokens, num_tokens); + if (r < 0) { + return r; + } + count++; + if (parser->toksuper != -1 && tokens != NULL) { + tokens[parser->toksuper].size++; + } + break; + case '\t': + case '\r': + case '\n': + case ' ': + break; + case ':': + parser->toksuper = parser->toknext - 1; + break; + case ',': + if (tokens != NULL && parser->toksuper != -1 && + tokens[parser->toksuper].type != JSMN_ARRAY && + tokens[parser->toksuper].type != JSMN_OBJECT) { +#ifdef JSMN_PARENT_LINKS + parser->toksuper = tokens[parser->toksuper].parent; +#else + for (i = parser->toknext - 1; i >= 0; i--) { + if (tokens[i].type == JSMN_ARRAY || tokens[i].type == JSMN_OBJECT) { + if (tokens[i].start != -1 && tokens[i].end == -1) { + parser->toksuper = i; + break; + } + } + } +#endif + } + break; +#ifdef JSMN_STRICT + /* In strict mode primitives are: numbers and booleans */ + case '-': + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 't': + case 'f': + case 'n': + /* And they must not be keys of the object */ + if (tokens != NULL && parser->toksuper != -1) { + const jsmntok_t *t = &tokens[parser->toksuper]; + if (t->type == JSMN_OBJECT || + (t->type == JSMN_STRING && t->size != 0)) { + return JSMN_ERROR_INVAL; + } + } +#else + /* In non-strict mode every unquoted value is a primitive */ + default: +#endif + r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens); + if (r < 0) { + return r; + } + count++; + if (parser->toksuper != -1 && tokens != NULL) { + tokens[parser->toksuper].size++; + } + break; + +#ifdef JSMN_STRICT + /* Unexpected char in strict mode */ + default: + return JSMN_ERROR_INVAL; +#endif + } + } + + if (tokens != NULL) { + for (i = parser->toknext - 1; i >= 0; i--) { + /* Unmatched opened object or array */ + if (tokens[i].start != -1 && tokens[i].end == -1) { + return JSMN_ERROR_PART; + } + } + } + + return count; +} + +/** + * Creates a new parser based over a given buffer with an array of tokens + * available. + */ +JSMN_API void jsmn_init(jsmn_parser *parser) { + parser->pos = 0; + parser->toknext = 0; + parser->toksuper = -1; +} + +#endif /* JSMN_HEADER */ + +#ifdef __cplusplus +} +#endif + +#endif /* JSMN_H */ diff --git a/tools/sdk/esp32/include/json_parser/upstream/jsmn/test/test.h b/tools/sdk/esp32/include/json_parser/upstream/jsmn/test/test.h new file mode 100644 index 00000000000..a1c0957a74a --- /dev/null +++ b/tools/sdk/esp32/include/json_parser/upstream/jsmn/test/test.h @@ -0,0 +1,31 @@ +#ifndef __TEST_H__ +#define __TEST_H__ + +static int test_passed = 0; +static int test_failed = 0; + +/* Terminate current test with error */ +#define fail() return __LINE__ + +/* Successful end of the test case */ +#define done() return 0 + +/* Check single condition */ +#define check(cond) \ + do { \ + if (!(cond)) \ + fail(); \ + } while (0) + +/* Test runner */ +static void test(int (*func)(void), const char *name) { + int r = func(); + if (r == 0) { + test_passed++; + } else { + test_failed++; + printf("FAILED: %s (at line %d)\n", name, r); + } +} + +#endif /* __TEST_H__ */ diff --git a/tools/sdk/esp32/include/json_parser/upstream/jsmn/test/testutil.h b/tools/sdk/esp32/include/json_parser/upstream/jsmn/test/testutil.h new file mode 100644 index 00000000000..bdee13934b1 --- /dev/null +++ b/tools/sdk/esp32/include/json_parser/upstream/jsmn/test/testutil.h @@ -0,0 +1,96 @@ +#ifndef __TEST_UTIL_H__ +#define __TEST_UTIL_H__ + +#include "../jsmn.h" + +static int vtokeq(const char *s, jsmntok_t *t, unsigned long numtok, + va_list ap) { + if (numtok > 0) { + unsigned long i; + int start, end, size; + jsmntype_t type; + char *value; + + size = -1; + value = NULL; + for (i = 0; i < numtok; i++) { + type = va_arg(ap, jsmntype_t); + if (type == JSMN_STRING) { + value = va_arg(ap, char *); + size = va_arg(ap, int); + start = end = -1; + } else if (type == JSMN_PRIMITIVE) { + value = va_arg(ap, char *); + start = end = size = -1; + } else { + start = va_arg(ap, int); + end = va_arg(ap, int); + size = va_arg(ap, int); + value = NULL; + } + if (t[i].type != type) { + printf("token %lu type is %d, not %d\n", i, t[i].type, type); + return 0; + } + if (start != -1 && end != -1) { + if (t[i].start != start) { + printf("token %lu start is %d, not %d\n", i, t[i].start, start); + return 0; + } + if (t[i].end != end) { + printf("token %lu end is %d, not %d\n", i, t[i].end, end); + return 0; + } + } + if (size != -1 && t[i].size != size) { + printf("token %lu size is %d, not %d\n", i, t[i].size, size); + return 0; + } + + if (s != NULL && value != NULL) { + const char *p = s + t[i].start; + if (strlen(value) != (unsigned long)(t[i].end - t[i].start) || + strncmp(p, value, t[i].end - t[i].start) != 0) { + printf("token %lu value is %.*s, not %s\n", i, t[i].end - t[i].start, + s + t[i].start, value); + return 0; + } + } + } + } + return 1; +} + +static int tokeq(const char *s, jsmntok_t *tokens, unsigned long numtok, ...) { + int ok; + va_list args; + va_start(args, numtok); + ok = vtokeq(s, tokens, numtok, args); + va_end(args); + return ok; +} + +static int parse(const char *s, int status, unsigned long numtok, ...) { + int r; + int ok = 1; + va_list args; + jsmn_parser p; + jsmntok_t *t = malloc(numtok * sizeof(jsmntok_t)); + + jsmn_init(&p); + r = jsmn_parse(&p, s, strlen(s), t, numtok); + if (r != status) { + printf("status is %d, not %d\n", r, status); + return 0; + } + + if (status >= 0) { + va_start(args, numtok); + ok = vtokeq(s, t, numtok, args); + va_end(args); + } + free(t); + return ok; +} + +#endif /* __TEST_UTIL_H__ */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/aes.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/aes.h index 4468b6623ac..e280dbb1c66 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/aes.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/aes.h @@ -22,13 +22,7 @@ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -41,37 +35,17 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_AES_H #define MBEDTLS_AES_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif +#include "mbedtls/platform_util.h" #include #include @@ -81,17 +55,22 @@ #define MBEDTLS_AES_DECRYPT 0 /**< AES decryption. */ /* Error codes in range 0x0020-0x0022 */ -#define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020 /**< Invalid key length. */ -#define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022 /**< Invalid data input length. */ +/** Invalid key length. */ +#define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020 +/** Invalid data input length. */ +#define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022 /* Error codes in range 0x0021-0x0025 */ -#define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021 /**< Invalid input data. */ +/** Invalid input data. */ +#define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021 /* MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE is deprecated and should not be used. */ -#define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023 /**< Feature not available. For example, an unsupported AES key size. */ +/** Feature not available. For example, an unsupported AES key size. */ +#define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023 /* MBEDTLS_ERR_AES_HW_ACCEL_FAILED is deprecated and should not be used. */ -#define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025 /**< AES hardware accelerator failed. */ +/** AES hardware accelerator failed. */ +#define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025 #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ !defined(inline) && !defined(__cplusplus) @@ -196,6 +175,7 @@ void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx ); * \return \c 0 on success. * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key, unsigned int keybits ); @@ -214,6 +194,7 @@ int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key, * \return \c 0 on success. * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key, unsigned int keybits ); @@ -234,6 +215,7 @@ int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key, * \return \c 0 on success. * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx, const unsigned char *key, unsigned int keybits ); @@ -254,6 +236,7 @@ int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx, * \return \c 0 on success. * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx, const unsigned char *key, unsigned int keybits ); @@ -282,6 +265,7 @@ int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx, * \return \c 0 on success. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx, int mode, const unsigned char input[16], @@ -329,6 +313,7 @@ int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx, * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH * on failure. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx, int mode, size_t length, @@ -373,6 +358,7 @@ int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx, * smaller than an AES block in size (16 Bytes) or if \p * length is larger than 2^20 blocks (16 MiB). */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx, int mode, size_t length, @@ -421,6 +407,7 @@ int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx, * * \return \c 0 on success. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx, int mode, size_t length, @@ -465,6 +452,7 @@ int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx, * * \return \c 0 on success. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx, int mode, size_t length, @@ -519,6 +507,7 @@ int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx, * * \return \c 0 on success. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx, size_t length, size_t *iv_off, @@ -533,10 +522,6 @@ int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx, * \brief This function performs an AES-CTR encryption or decryption * operation. * - * This function performs the operation defined in the \p mode - * parameter (encrypt/decrypt), on the input data buffer - * defined in the \p input parameter. - * * Due to the nature of CTR, you must use the same key schedule * for both encryption and decryption operations. Therefore, you * must use the context initialized with mbedtls_aes_setkey_enc() @@ -605,6 +590,7 @@ int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx, * * \return \c 0 on success. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx, size_t length, size_t *nc_off, @@ -625,6 +611,7 @@ int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx, * * \return \c 0 on success. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx, const unsigned char input[16], unsigned char output[16] ); @@ -640,6 +627,7 @@ int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx, * * \return \c 0 on success. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx, const unsigned char input[16], unsigned char output[16] ); @@ -689,6 +677,7 @@ MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx, * \return \c 0 on success. * \return \c 1 on failure. */ +MBEDTLS_CHECK_RETURN_CRITICAL int mbedtls_aes_self_test( int verbose ); #endif /* MBEDTLS_SELF_TEST */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/aesni.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/aesni.h index 9b63a0010a0..c1d22f59af3 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/aesni.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/aesni.h @@ -8,13 +8,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -27,38 +21,17 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_AESNI_H #define MBEDTLS_AESNI_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "aes.h" +#include "mbedtls/aes.h" #define MBEDTLS_AESNI_AES 0x02000000u #define MBEDTLS_AESNI_CLMUL 0x00000002u diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/arc4.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/arc4.h index 6334a9cc1e2..f4b0f9f3508 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/arc4.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/arc4.h @@ -8,13 +8,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -28,33 +22,12 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** - * */ #ifndef MBEDTLS_ARC4_H #define MBEDTLS_ARC4_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif @@ -62,7 +35,8 @@ #include /* MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED is deprecated and should not be used. */ -#define MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED -0x0019 /**< ARC4 hardware accelerator failed. */ +/** ARC4 hardware accelerator failed. */ +#define MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED -0x0019 #ifdef __cplusplus extern "C" { diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/aria.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/aria.h index 20f43f2256d..226e2dbf3c8 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/aria.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/aria.h @@ -11,13 +11,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -30,34 +24,13 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_ARIA_H #define MBEDTLS_ARIA_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif @@ -65,7 +38,7 @@ #include #include -#include "platform_util.h" +#include "mbedtls/platform_util.h" #define MBEDTLS_ARIA_ENCRYPT 1 /**< ARIA encryption. */ #define MBEDTLS_ARIA_DECRYPT 0 /**< ARIA decryption. */ @@ -77,16 +50,20 @@ #if !defined(MBEDTLS_DEPRECATED_REMOVED) #define MBEDTLS_ERR_ARIA_INVALID_KEY_LENGTH MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( -0x005C ) #endif /* !MBEDTLS_DEPRECATED_REMOVED */ -#define MBEDTLS_ERR_ARIA_BAD_INPUT_DATA -0x005C /**< Bad input data. */ +/** Bad input data. */ +#define MBEDTLS_ERR_ARIA_BAD_INPUT_DATA -0x005C -#define MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH -0x005E /**< Invalid data input length. */ +/** Invalid data input length. */ +#define MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH -0x005E /* MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE is deprecated and should not be used. */ -#define MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE -0x005A /**< Feature not available. For example, an unsupported ARIA key size. */ +/** Feature not available. For example, an unsupported ARIA key size. */ +#define MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE -0x005A /* MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED is deprecated and should not be used. */ -#define MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED -0x0058 /**< ARIA hardware accelerator failed. */ +/** ARIA hardware accelerator failed. */ +#define MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED -0x0058 #ifdef __cplusplus extern "C" { diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/asn1.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/asn1.h index 0e596bca2cd..10f7905b7e6 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/asn1.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/asn1.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,33 +18,12 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_ASN1_H #define MBEDTLS_ASN1_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif @@ -58,7 +31,7 @@ #include #if defined(MBEDTLS_BIGNUM_C) -#include "bignum.h" +#include "mbedtls/bignum.h" #endif /** @@ -73,13 +46,20 @@ * ASN1 is a standard to specify data structures. * \{ */ -#define MBEDTLS_ERR_ASN1_OUT_OF_DATA -0x0060 /**< Out of data when parsing an ASN1 data structure. */ -#define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG -0x0062 /**< ASN1 tag was of an unexpected value. */ -#define MBEDTLS_ERR_ASN1_INVALID_LENGTH -0x0064 /**< Error when trying to determine the length or invalid length. */ -#define MBEDTLS_ERR_ASN1_LENGTH_MISMATCH -0x0066 /**< Actual length differs from expected length. */ -#define MBEDTLS_ERR_ASN1_INVALID_DATA -0x0068 /**< Data is invalid. (not used) */ -#define MBEDTLS_ERR_ASN1_ALLOC_FAILED -0x006A /**< Memory allocation failed */ -#define MBEDTLS_ERR_ASN1_BUF_TOO_SMALL -0x006C /**< Buffer too small when writing ASN.1 data structure. */ +/** Out of data when parsing an ASN1 data structure. */ +#define MBEDTLS_ERR_ASN1_OUT_OF_DATA -0x0060 +/** ASN1 tag was of an unexpected value. */ +#define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG -0x0062 +/** Error when trying to determine the length or invalid length. */ +#define MBEDTLS_ERR_ASN1_INVALID_LENGTH -0x0064 +/** Actual length differs from expected length. */ +#define MBEDTLS_ERR_ASN1_LENGTH_MISMATCH -0x0066 +/** Data is invalid. */ +#define MBEDTLS_ERR_ASN1_INVALID_DATA -0x0068 +/** Memory allocation failed */ +#define MBEDTLS_ERR_ASN1_ALLOC_FAILED -0x006A +/** Buffer too small when writing ASN.1 data structure. */ +#define MBEDTLS_ERR_ASN1_BUF_TOO_SMALL -0x006C /* \} name */ @@ -100,6 +80,7 @@ #define MBEDTLS_ASN1_OCTET_STRING 0x04 #define MBEDTLS_ASN1_NULL 0x05 #define MBEDTLS_ASN1_OID 0x06 +#define MBEDTLS_ASN1_ENUMERATED 0x0A #define MBEDTLS_ASN1_UTF8_STRING 0x0C #define MBEDTLS_ASN1_SEQUENCE 0x10 #define MBEDTLS_ASN1_SET 0x11 @@ -114,6 +95,18 @@ #define MBEDTLS_ASN1_CONSTRUCTED 0x20 #define MBEDTLS_ASN1_CONTEXT_SPECIFIC 0x80 +/* Slightly smaller way to check if tag is a string tag + * compared to canonical implementation. */ +#define MBEDTLS_ASN1_IS_STRING_TAG( tag ) \ + ( ( tag ) < 32u && ( \ + ( ( 1u << ( tag ) ) & ( ( 1u << MBEDTLS_ASN1_BMP_STRING ) | \ + ( 1u << MBEDTLS_ASN1_UTF8_STRING ) | \ + ( 1u << MBEDTLS_ASN1_T61_STRING ) | \ + ( 1u << MBEDTLS_ASN1_IA5_STRING ) | \ + ( 1u << MBEDTLS_ASN1_UNIVERSAL_STRING ) | \ + ( 1u << MBEDTLS_ASN1_PRINTABLE_STRING ) | \ + ( 1u << MBEDTLS_ASN1_BIT_STRING ) ) ) != 0 ) ) + /* * Bit masks for each of the components of an ASN.1 tag as specified in * ITU X.690 (08/2015), section 8.1 "General rules for encoding", @@ -144,6 +137,10 @@ ( ( MBEDTLS_OID_SIZE(oid_str) != (oid_buf)->len ) || \ memcmp( (oid_str), (oid_buf)->p, (oid_buf)->len) != 0 ) +#define MBEDTLS_OID_CMP_RAW(oid_str, oid_buf, oid_buf_len) \ + ( ( MBEDTLS_OID_SIZE(oid_str) != (oid_buf_len) ) || \ + memcmp( (oid_str), (oid_buf), (oid_buf_len) ) != 0 ) + #ifdef __cplusplus extern "C" { #endif @@ -201,119 +198,342 @@ mbedtls_asn1_named_data; * \brief Get the length of an ASN.1 element. * Updates the pointer to immediately behind the length. * - * \param p The position in the ASN.1 data - * \param end End of data - * \param len The variable that will receive the value - * - * \return 0 if successful, MBEDTLS_ERR_ASN1_OUT_OF_DATA on reaching - * end of data, MBEDTLS_ERR_ASN1_INVALID_LENGTH if length is - * unparseable. + * \param p On entry, \c *p points to the first byte of the length, + * i.e. immediately after the tag. + * On successful completion, \c *p points to the first byte + * after the length, i.e. the first byte of the content. + * On error, the value of \c *p is undefined. + * \param end End of data. + * \param len On successful completion, \c *len contains the length + * read from the ASN.1 input. + * + * \return 0 if successful. + * \return #MBEDTLS_ERR_ASN1_OUT_OF_DATA if the ASN.1 element + * would end beyond \p end. + * \return #MBEDTLS_ERR_ASN1_INVALID_LENGTH if the length is unparseable. */ int mbedtls_asn1_get_len( unsigned char **p, - const unsigned char *end, - size_t *len ); + const unsigned char *end, + size_t *len ); /** - * \brief Get the tag and length of the tag. Check for the requested tag. + * \brief Get the tag and length of the element. + * Check for the requested tag. * Updates the pointer to immediately behind the tag and length. * - * \param p The position in the ASN.1 data - * \param end End of data - * \param len The variable that will receive the length - * \param tag The expected tag - * - * \return 0 if successful, MBEDTLS_ERR_ASN1_UNEXPECTED_TAG if tag did - * not match requested tag, or another specific ASN.1 error code. + * \param p On entry, \c *p points to the start of the ASN.1 element. + * On successful completion, \c *p points to the first byte + * after the length, i.e. the first byte of the content. + * On error, the value of \c *p is undefined. + * \param end End of data. + * \param len On successful completion, \c *len contains the length + * read from the ASN.1 input. + * \param tag The expected tag. + * + * \return 0 if successful. + * \return #MBEDTLS_ERR_ASN1_UNEXPECTED_TAG if the data does not start + * with the requested tag. + * \return #MBEDTLS_ERR_ASN1_OUT_OF_DATA if the ASN.1 element + * would end beyond \p end. + * \return #MBEDTLS_ERR_ASN1_INVALID_LENGTH if the length is unparseable. */ int mbedtls_asn1_get_tag( unsigned char **p, - const unsigned char *end, - size_t *len, int tag ); + const unsigned char *end, + size_t *len, int tag ); /** * \brief Retrieve a boolean ASN.1 tag and its value. * Updates the pointer to immediately behind the full tag. * - * \param p The position in the ASN.1 data - * \param end End of data - * \param val The variable that will receive the value + * \param p On entry, \c *p points to the start of the ASN.1 element. + * On successful completion, \c *p points to the first byte + * beyond the ASN.1 element. + * On error, the value of \c *p is undefined. + * \param end End of data. + * \param val On success, the parsed value (\c 0 or \c 1). * - * \return 0 if successful or a specific ASN.1 error code. + * \return 0 if successful. + * \return An ASN.1 error code if the input does not start with + * a valid ASN.1 BOOLEAN. */ int mbedtls_asn1_get_bool( unsigned char **p, - const unsigned char *end, - int *val ); + const unsigned char *end, + int *val ); /** * \brief Retrieve an integer ASN.1 tag and its value. * Updates the pointer to immediately behind the full tag. * - * \param p The position in the ASN.1 data - * \param end End of data - * \param val The variable that will receive the value - * - * \return 0 if successful or a specific ASN.1 error code. + * \param p On entry, \c *p points to the start of the ASN.1 element. + * On successful completion, \c *p points to the first byte + * beyond the ASN.1 element. + * On error, the value of \c *p is undefined. + * \param end End of data. + * \param val On success, the parsed value. + * + * \return 0 if successful. + * \return An ASN.1 error code if the input does not start with + * a valid ASN.1 INTEGER. + * \return #MBEDTLS_ERR_ASN1_INVALID_LENGTH if the parsed value does + * not fit in an \c int. */ int mbedtls_asn1_get_int( unsigned char **p, - const unsigned char *end, - int *val ); + const unsigned char *end, + int *val ); /** - * \brief Retrieve a bitstring ASN.1 tag and its value. + * \brief Retrieve an enumerated ASN.1 tag and its value. * Updates the pointer to immediately behind the full tag. * - * \param p The position in the ASN.1 data - * \param end End of data - * \param bs The variable that will receive the value + * \param p On entry, \c *p points to the start of the ASN.1 element. + * On successful completion, \c *p points to the first byte + * beyond the ASN.1 element. + * On error, the value of \c *p is undefined. + * \param end End of data. + * \param val On success, the parsed value. + * + * \return 0 if successful. + * \return An ASN.1 error code if the input does not start with + * a valid ASN.1 ENUMERATED. + * \return #MBEDTLS_ERR_ASN1_INVALID_LENGTH if the parsed value does + * not fit in an \c int. + */ +int mbedtls_asn1_get_enum( unsigned char **p, + const unsigned char *end, + int *val ); + +/** + * \brief Retrieve a bitstring ASN.1 tag and its value. + * Updates the pointer to immediately behind the full tag. * - * \return 0 if successful or a specific ASN.1 error code. + * \param p On entry, \c *p points to the start of the ASN.1 element. + * On successful completion, \c *p is equal to \p end. + * On error, the value of \c *p is undefined. + * \param end End of data. + * \param bs On success, ::mbedtls_asn1_bitstring information about + * the parsed value. + * + * \return 0 if successful. + * \return #MBEDTLS_ERR_ASN1_LENGTH_MISMATCH if the input contains + * extra data after a valid BIT STRING. + * \return An ASN.1 error code if the input does not start with + * a valid ASN.1 BIT STRING. */ int mbedtls_asn1_get_bitstring( unsigned char **p, const unsigned char *end, - mbedtls_asn1_bitstring *bs); + mbedtls_asn1_bitstring *bs ); /** * \brief Retrieve a bitstring ASN.1 tag without unused bits and its * value. * Updates the pointer to the beginning of the bit/octet string. * - * \param p The position in the ASN.1 data - * \param end End of data - * \param len Length of the actual bit/octect string in bytes - * - * \return 0 if successful or a specific ASN.1 error code. + * \param p On entry, \c *p points to the start of the ASN.1 element. + * On successful completion, \c *p points to the first byte + * of the content of the BIT STRING. + * On error, the value of \c *p is undefined. + * \param end End of data. + * \param len On success, \c *len is the length of the content in bytes. + * + * \return 0 if successful. + * \return #MBEDTLS_ERR_ASN1_INVALID_DATA if the input starts with + * a valid BIT STRING with a nonzero number of unused bits. + * \return An ASN.1 error code if the input does not start with + * a valid ASN.1 BIT STRING. */ -int mbedtls_asn1_get_bitstring_null( unsigned char **p, const unsigned char *end, - size_t *len ); +int mbedtls_asn1_get_bitstring_null( unsigned char **p, + const unsigned char *end, + size_t *len ); /** - * \brief Parses and splits an ASN.1 "SEQUENCE OF " - * Updated the pointer to immediately behind the full sequence tag. - * - * \param p The position in the ASN.1 data - * \param end End of data - * \param cur First variable in the chain to fill - * \param tag Type of sequence - * - * \return 0 if successful or a specific ASN.1 error code. + * \brief Parses and splits an ASN.1 "SEQUENCE OF ". + * Updates the pointer to immediately behind the full sequence tag. + * + * This function allocates memory for the sequence elements. You can free + * the allocated memory with mbedtls_asn1_sequence_free(). + * + * \note On error, this function may return a partial list in \p cur. + * You must set `cur->next = NULL` before calling this function! + * Otherwise it is impossible to distinguish a previously non-null + * pointer from a pointer to an object allocated by this function. + * + * \note If the sequence is empty, this function does not modify + * \c *cur. If the sequence is valid and non-empty, this + * function sets `cur->buf.tag` to \p tag. This allows + * callers to distinguish between an empty sequence and + * a one-element sequence. + * + * \param p On entry, \c *p points to the start of the ASN.1 element. + * On successful completion, \c *p is equal to \p end. + * On error, the value of \c *p is undefined. + * \param end End of data. + * \param cur A ::mbedtls_asn1_sequence which this function fills. + * When this function returns, \c *cur is the head of a linked + * list. Each node in this list is allocated with + * mbedtls_calloc() apart from \p cur itself, and should + * therefore be freed with mbedtls_free(). + * The list describes the content of the sequence. + * The head of the list (i.e. \c *cur itself) describes the + * first element, `*cur->next` describes the second element, etc. + * For each element, `buf.tag == tag`, `buf.len` is the length + * of the content of the content of the element, and `buf.p` + * points to the first byte of the content (i.e. immediately + * past the length of the element). + * Note that list elements may be allocated even on error. + * \param tag Each element of the sequence must have this tag. + * + * \return 0 if successful. + * \return #MBEDTLS_ERR_ASN1_LENGTH_MISMATCH if the input contains + * extra data after a valid SEQUENCE OF \p tag. + * \return #MBEDTLS_ERR_ASN1_UNEXPECTED_TAG if the input starts with + * an ASN.1 SEQUENCE in which an element has a tag that + * is different from \p tag. + * \return #MBEDTLS_ERR_ASN1_ALLOC_FAILED if a memory allocation failed. + * \return An ASN.1 error code if the input does not start with + * a valid ASN.1 SEQUENCE. */ int mbedtls_asn1_get_sequence_of( unsigned char **p, - const unsigned char *end, - mbedtls_asn1_sequence *cur, - int tag); + const unsigned char *end, + mbedtls_asn1_sequence *cur, + int tag ); +/** + * \brief Free a heap-allocated linked list presentation of + * an ASN.1 sequence, including the first element. + * + * There are two common ways to manage the memory used for the representation + * of a parsed ASN.1 sequence: + * - Allocate a head node `mbedtls_asn1_sequence *head` with mbedtls_calloc(). + * Pass this node as the `cur` argument to mbedtls_asn1_get_sequence_of(). + * When you have finished processing the sequence, + * call mbedtls_asn1_sequence_free() on `head`. + * - Allocate a head node `mbedtls_asn1_sequence *head` in any manner, + * for example on the stack. Make sure that `head->next == NULL`. + * Pass `head` as the `cur` argument to mbedtls_asn1_get_sequence_of(). + * When you have finished processing the sequence, + * call mbedtls_asn1_sequence_free() on `head->cur`, + * then free `head` itself in the appropriate manner. + * + * \param seq The address of the first sequence component. This may + * be \c NULL, in which case this functions returns + * immediately. + */ +void mbedtls_asn1_sequence_free( mbedtls_asn1_sequence *seq ); + +/** + * \brief Traverse an ASN.1 SEQUENCE container and + * call a callback for each entry. + * + * This function checks that the input is a SEQUENCE of elements that + * each have a "must" tag, and calls a callback function on the elements + * that have a "may" tag. + * + * For example, to validate that the input is a SEQUENCE of `tag1` and call + * `cb` on each element, use + * ``` + * mbedtls_asn1_traverse_sequence_of(&p, end, 0xff, tag1, 0, 0, cb, ctx); + * ``` + * + * To validate that the input is a SEQUENCE of ANY and call `cb` on + * each element, use + * ``` + * mbedtls_asn1_traverse_sequence_of(&p, end, 0, 0, 0, 0, cb, ctx); + * ``` + * + * To validate that the input is a SEQUENCE of CHOICE {NULL, OCTET STRING} + * and call `cb` on each element that is an OCTET STRING, use + * ``` + * mbedtls_asn1_traverse_sequence_of(&p, end, 0xfe, 0x04, 0xff, 0x04, cb, ctx); + * ``` + * + * The callback is called on the elements with a "may" tag from left to + * right. If the input is not a valid SEQUENCE of elements with a "must" tag, + * the callback is called on the elements up to the leftmost point where + * the input is invalid. + * + * \warning This function is still experimental and may change + * at any time. + * + * \param p The address of the pointer to the beginning of + * the ASN.1 SEQUENCE header. This is updated to + * point to the end of the ASN.1 SEQUENCE container + * on a successful invocation. + * \param end The end of the ASN.1 SEQUENCE container. + * \param tag_must_mask A mask to be applied to the ASN.1 tags found within + * the SEQUENCE before comparing to \p tag_must_value. + * \param tag_must_val The required value of each ASN.1 tag found in the + * SEQUENCE, after masking with \p tag_must_mask. + * Mismatching tags lead to an error. + * For example, a value of \c 0 for both \p tag_must_mask + * and \p tag_must_val means that every tag is allowed, + * while a value of \c 0xFF for \p tag_must_mask means + * that \p tag_must_val is the only allowed tag. + * \param tag_may_mask A mask to be applied to the ASN.1 tags found within + * the SEQUENCE before comparing to \p tag_may_value. + * \param tag_may_val The desired value of each ASN.1 tag found in the + * SEQUENCE, after masking with \p tag_may_mask. + * Mismatching tags will be silently ignored. + * For example, a value of \c 0 for \p tag_may_mask and + * \p tag_may_val means that any tag will be considered, + * while a value of \c 0xFF for \p tag_may_mask means + * that all tags with value different from \p tag_may_val + * will be ignored. + * \param cb The callback to trigger for each component + * in the ASN.1 SEQUENCE that matches \p tag_may_val. + * The callback function is called with the following + * parameters: + * - \p ctx. + * - The tag of the current element. + * - A pointer to the start of the current element's + * content inside the input. + * - The length of the content of the current element. + * If the callback returns a non-zero value, + * the function stops immediately, + * forwarding the callback's return value. + * \param ctx The context to be passed to the callback \p cb. + * + * \return \c 0 if successful the entire ASN.1 SEQUENCE + * was traversed without parsing or callback errors. + * \return #MBEDTLS_ERR_ASN1_LENGTH_MISMATCH if the input + * contains extra data after a valid SEQUENCE + * of elements with an accepted tag. + * \return #MBEDTLS_ERR_ASN1_UNEXPECTED_TAG if the input starts + * with an ASN.1 SEQUENCE in which an element has a tag + * that is not accepted. + * \return An ASN.1 error code if the input does not start with + * a valid ASN.1 SEQUENCE. + * \return A non-zero error code forwarded from the callback + * \p cb in case the latter returns a non-zero value. + */ +int mbedtls_asn1_traverse_sequence_of( + unsigned char **p, + const unsigned char *end, + unsigned char tag_must_mask, unsigned char tag_must_val, + unsigned char tag_may_mask, unsigned char tag_may_val, + int (*cb)( void *ctx, int tag, + unsigned char* start, size_t len ), + void *ctx ); #if defined(MBEDTLS_BIGNUM_C) /** - * \brief Retrieve a MPI value from an integer ASN.1 tag. + * \brief Retrieve an integer ASN.1 tag and its value. * Updates the pointer to immediately behind the full tag. * - * \param p The position in the ASN.1 data - * \param end End of data - * \param X The MPI that will receive the value - * - * \return 0 if successful or a specific ASN.1 or MPI error code. + * \param p On entry, \c *p points to the start of the ASN.1 element. + * On successful completion, \c *p points to the first byte + * beyond the ASN.1 element. + * On error, the value of \c *p is undefined. + * \param end End of data. + * \param X On success, the parsed value. + * + * \return 0 if successful. + * \return An ASN.1 error code if the input does not start with + * a valid ASN.1 INTEGER. + * \return #MBEDTLS_ERR_ASN1_INVALID_LENGTH if the parsed value does + * not fit in an \c int. + * \return An MPI error code if the parsed value is too large. */ int mbedtls_asn1_get_mpi( unsigned char **p, - const unsigned char *end, - mbedtls_mpi *X ); + const unsigned char *end, + mbedtls_mpi *X ); #endif /* MBEDTLS_BIGNUM_C */ /** @@ -321,10 +541,14 @@ int mbedtls_asn1_get_mpi( unsigned char **p, * Updates the pointer to immediately behind the full * AlgorithmIdentifier. * - * \param p The position in the ASN.1 data - * \param end End of data - * \param alg The buffer to receive the OID - * \param params The buffer to receive the params (if any) + * \param p On entry, \c *p points to the start of the ASN.1 element. + * On successful completion, \c *p points to the first byte + * beyond the AlgorithmIdentifier element. + * On error, the value of \c *p is undefined. + * \param end End of data. + * \param alg The buffer to receive the OID. + * \param params The buffer to receive the parameters. + * This is zeroized if there are no parameters. * * \return 0 if successful or a specific ASN.1 or MPI error code. */ @@ -338,9 +562,12 @@ int mbedtls_asn1_get_alg( unsigned char **p, * Updates the pointer to immediately behind the full * AlgorithmIdentifier. * - * \param p The position in the ASN.1 data - * \param end End of data - * \param alg The buffer to receive the OID + * \param p On entry, \c *p points to the start of the ASN.1 element. + * On successful completion, \c *p points to the first byte + * beyond the AlgorithmIdentifier element. + * On error, the value of \c *p is undefined. + * \param end End of data. + * \param alg The buffer to receive the OID. * * \return 0 if successful or a specific ASN.1 or MPI error code. */ @@ -364,15 +591,19 @@ mbedtls_asn1_named_data *mbedtls_asn1_find_named_data( mbedtls_asn1_named_data * /** * \brief Free a mbedtls_asn1_named_data entry * - * \param entry The named data entry to free + * \param entry The named data entry to free. + * This function calls mbedtls_free() on + * `entry->oid.p` and `entry->val.p`. */ void mbedtls_asn1_free_named_data( mbedtls_asn1_named_data *entry ); /** - * \brief Free all entries in a mbedtls_asn1_named_data list - * Head will be set to NULL + * \brief Free all entries in a mbedtls_asn1_named_data list. * - * \param head Pointer to the head of the list of named data entries to free + * \param head Pointer to the head of the list of named data entries to free. + * This function calls mbedtls_asn1_free_named_data() and + * mbedtls_free() on each list element and + * sets \c *head to \c NULL. */ void mbedtls_asn1_free_named_data_list( mbedtls_asn1_named_data **head ); diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/asn1write.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/asn1write.h index 3c7cdd6b469..44afae0e560 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/asn1write.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/asn1write.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,38 +18,17 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_ASN1_WRITE_H #define MBEDTLS_ASN1_WRITE_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "asn1.h" +#include "mbedtls/asn1.h" #define MBEDTLS_ASN1_CHK_ADD(g, f) \ do \ @@ -125,6 +98,7 @@ int mbedtls_asn1_write_raw_buffer( unsigned char **p, unsigned char *start, * \param p The reference to the current position pointer. * \param start The start of the buffer, for bounds-checking. * \param X The MPI to write. + * It must be non-negative. * * \return The number of bytes written to \p p on success. * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure. @@ -209,12 +183,28 @@ int mbedtls_asn1_write_bool( unsigned char **p, unsigned char *start, * \param p The reference to the current position pointer. * \param start The start of the buffer, for bounds-checking. * \param val The integer value to write. + * It must be non-negative. * * \return The number of bytes written to \p p on success. * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure. */ int mbedtls_asn1_write_int( unsigned char **p, unsigned char *start, int val ); +/** + * \brief Write an enum tag (#MBEDTLS_ASN1_ENUMERATED) and value + * in ASN.1 format. + * + * \note This function works backwards in data buffer. + * + * \param p The reference to the current position pointer. + * \param start The start of the buffer, for bounds-checking. + * \param val The integer value to write. + * + * \return The number of bytes written to \p p on success. + * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure. + */ +int mbedtls_asn1_write_enum( unsigned char **p, unsigned char *start, int val ); + /** * \brief Write a string in ASN.1 format using a specific * string encoding tag. @@ -257,7 +247,7 @@ int mbedtls_asn1_write_printable_string( unsigned char **p, /** * \brief Write a UTF8 string in ASN.1 format using the UTF8String - * string encoding tag (#MBEDTLS_ASN1_PRINTABLE_STRING). + * string encoding tag (#MBEDTLS_ASN1_UTF8_STRING). * * \note This function works backwards in data buffer. * @@ -308,6 +298,28 @@ int mbedtls_asn1_write_ia5_string( unsigned char **p, unsigned char *start, int mbedtls_asn1_write_bitstring( unsigned char **p, unsigned char *start, const unsigned char *buf, size_t bits ); +/** + * \brief This function writes a named bitstring tag + * (#MBEDTLS_ASN1_BIT_STRING) and value in ASN.1 format. + * + * As stated in RFC 5280 Appendix B, trailing zeroes are + * omitted when encoding named bitstrings in DER. + * + * \note This function works backwards within the data buffer. + * + * \param p The reference to the current position pointer. + * \param start The start of the buffer which is used for bounds-checking. + * \param buf The bitstring to write. + * \param bits The total number of bits in the bitstring. + * + * \return The number of bytes written to \p p on success. + * \return A negative error code on failure. + */ +int mbedtls_asn1_write_named_bitstring( unsigned char **p, + unsigned char *start, + const unsigned char *buf, + size_t bits ); + /** * \brief Write an octet string tag (#MBEDTLS_ASN1_OCTET_STRING) * and value in ASN.1 format. @@ -335,9 +347,13 @@ int mbedtls_asn1_write_octet_string( unsigned char **p, unsigned char *start, * through (will be updated in case of a new entry). * \param oid The OID to look for. * \param oid_len The size of the OID. - * \param val The data to store (can be \c NULL if you want to fill - * it by hand). + * \param val The associated data to store. If this is \c NULL, + * no data is copied to the new or existing buffer. * \param val_len The minimum length of the data buffer needed. + * If this is 0, do not allocate a buffer for the associated + * data. + * If the OID was already present, enlarge, shrink or free + * the existing buffer to fit \p val_len. * * \return A pointer to the new / existing entry on success. * \return \c NULL if if there was a memory allocation error. diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/base64.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/base64.h index cbed6887ee6..cf4149e731d 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/base64.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/base64.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,41 +18,22 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_BASE64_H #define MBEDTLS_BASE64_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif #include -#define MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL -0x002A /**< Output buffer too small. */ -#define MBEDTLS_ERR_BASE64_INVALID_CHARACTER -0x002C /**< Invalid character in input. */ +/** Output buffer too small. */ +#define MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL -0x002A +/** Invalid character in input. */ +#define MBEDTLS_ERR_BASE64_INVALID_CHARACTER -0x002C #ifdef __cplusplus extern "C" { diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/bignum.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/bignum.h index 3deedfedd9c..4de452980b8 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/bignum.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/bignum.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,33 +18,12 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_BIGNUM_H #define MBEDTLS_BIGNUM_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif @@ -62,14 +35,22 @@ #include #endif -#define MBEDTLS_ERR_MPI_FILE_IO_ERROR -0x0002 /**< An error occurred while reading from or writing to a file. */ -#define MBEDTLS_ERR_MPI_BAD_INPUT_DATA -0x0004 /**< Bad input parameters to function. */ -#define MBEDTLS_ERR_MPI_INVALID_CHARACTER -0x0006 /**< There is an invalid character in the digit string. */ -#define MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL -0x0008 /**< The buffer is too small to write to. */ -#define MBEDTLS_ERR_MPI_NEGATIVE_VALUE -0x000A /**< The input arguments are negative or result in illegal output. */ -#define MBEDTLS_ERR_MPI_DIVISION_BY_ZERO -0x000C /**< The input argument for division is zero, which is not allowed. */ -#define MBEDTLS_ERR_MPI_NOT_ACCEPTABLE -0x000E /**< The input arguments are not acceptable. */ -#define MBEDTLS_ERR_MPI_ALLOC_FAILED -0x0010 /**< Memory allocation failed. */ +/** An error occurred while reading from or writing to a file. */ +#define MBEDTLS_ERR_MPI_FILE_IO_ERROR -0x0002 +/** Bad input parameters to function. */ +#define MBEDTLS_ERR_MPI_BAD_INPUT_DATA -0x0004 +/** There is an invalid character in the digit string. */ +#define MBEDTLS_ERR_MPI_INVALID_CHARACTER -0x0006 +/** The buffer is too small to write to. */ +#define MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL -0x0008 +/** The input arguments are negative or result in illegal output. */ +#define MBEDTLS_ERR_MPI_NEGATIVE_VALUE -0x000A +/** The input argument for division is zero, which is not allowed. */ +#define MBEDTLS_ERR_MPI_DIVISION_BY_ZERO -0x000C +/** The input arguments are not acceptable. */ +#define MBEDTLS_ERR_MPI_NOT_ACCEPTABLE -0x000E +/** Memory allocation failed. */ +#define MBEDTLS_ERR_MPI_ALLOC_FAILED -0x0010 #define MBEDTLS_MPI_CHK(f) \ do \ @@ -156,7 +137,8 @@ defined(__ppc64__) || defined(__powerpc64__) || \ defined(__ia64__) || defined(__alpha__) || \ ( defined(__sparc__) && defined(__arch64__) ) || \ - defined(__s390x__) || defined(__mips64) ) + defined(__s390x__) || defined(__mips64) || \ + defined(__aarch64__) ) #if !defined(MBEDTLS_HAVE_INT64) #define MBEDTLS_HAVE_INT64 #endif /* MBEDTLS_HAVE_INT64 */ @@ -522,8 +504,24 @@ int mbedtls_mpi_read_binary( mbedtls_mpi *X, const unsigned char *buf, size_t buflen ); /** - * \brief Export an MPI into unsigned big endian binary data - * of fixed size. + * \brief Import X from unsigned binary data, little endian + * + * \param X The destination MPI. This must point to an initialized MPI. + * \param buf The input buffer. This must be a readable buffer of length + * \p buflen Bytes. + * \param buflen The length of the input buffer \p p in Bytes. + * + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed. + * \return Another negative error code on different kinds of failure. + */ +int mbedtls_mpi_read_binary_le( mbedtls_mpi *X, + const unsigned char *buf, size_t buflen ); + +/** + * \brief Export X into unsigned binary data, big endian. + * Always fills the whole buffer, which will start with zeros + * if the number is smaller. * * \param X The source MPI. This must point to an initialized MPI. * \param buf The output buffer. This must be a writable buffer of length @@ -538,6 +536,24 @@ int mbedtls_mpi_read_binary( mbedtls_mpi *X, const unsigned char *buf, int mbedtls_mpi_write_binary( const mbedtls_mpi *X, unsigned char *buf, size_t buflen ); +/** + * \brief Export X into unsigned binary data, little endian. + * Always fills the whole buffer, which will end with zeros + * if the number is smaller. + * + * \param X The source MPI. This must point to an initialized MPI. + * \param buf The output buffer. This must be a writable buffer of length + * \p buflen Bytes. + * \param buflen The size of the output buffer \p buf in Bytes. + * + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p buf isn't + * large enough to hold the value of \p X. + * \return Another negative error code on different kinds of failure. + */ +int mbedtls_mpi_write_binary_le( const mbedtls_mpi *X, + unsigned char *buf, size_t buflen ); + /** * \brief Perform a left-shift on an MPI: X <<= count * @@ -823,14 +839,14 @@ int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A, * \param E The exponent MPI. This must point to an initialized MPI. * \param N The base for the modular reduction. This must point to an * initialized MPI. - * \param _RR A helper MPI depending solely on \p N which can be used to + * \param prec_RR A helper MPI depending solely on \p N which can be used to * speed-up multiple modular exponentiations for the same value * of \p N. This may be \c NULL. If it is not \c NULL, it must * point to an initialized MPI. If it hasn't been used after * the call to mbedtls_mpi_init(), this function will compute - * the helper value and store it in \p _RR for reuse on + * the helper value and store it in \p prec_RR for reuse on * subsequent calls to this function. Otherwise, the function - * will assume that \p _RR holds the helper value set by a + * will assume that \p prec_RR holds the helper value set by a * previous call to mbedtls_mpi_exp_mod(), and reuse it. * * \return \c 0 if successful. @@ -842,7 +858,7 @@ int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A, */ int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *E, const mbedtls_mpi *N, - mbedtls_mpi *_RR ); + mbedtls_mpi *prec_RR ); /** * \brief Fill an MPI with a number of random bytes. @@ -865,6 +881,44 @@ int mbedtls_mpi_fill_random( mbedtls_mpi *X, size_t size, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); +/** Generate a random number uniformly in a range. + * + * This function generates a random number between \p min inclusive and + * \p N exclusive. + * + * The procedure complies with RFC 6979 §3.3 (deterministic ECDSA) + * when the RNG is a suitably parametrized instance of HMAC_DRBG + * and \p min is \c 1. + * + * \note There are `N - min` possible outputs. The lower bound + * \p min can be reached, but the upper bound \p N cannot. + * + * \param X The destination MPI. This must point to an initialized MPI. + * \param min The minimum value to return. + * It must be nonnegative. + * \param N The upper bound of the range, exclusive. + * In other words, this is one plus the maximum value to return. + * \p N must be strictly larger than \p min. + * \param f_rng The RNG function to use. This must not be \c NULL. + * \param p_rng The RNG parameter to be passed to \p f_rng. + * + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. + * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p min or \p N is invalid + * or if they are incompatible. + * \return #MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if the implementation was + * unable to find a suitable value within a limited number + * of attempts. This has a negligible probability if \p N + * is significantly larger than \p min, which is the case + * for all usual cryptographic applications. + * \return Another negative error code on failure. + */ +int mbedtls_mpi_random( mbedtls_mpi *X, + mbedtls_mpi_sint min, + const mbedtls_mpi *N, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); + /** * \brief Compute the greatest common divisor: G = gcd(A, B) * diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/blowfish.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/blowfish.h index 945bd426a9f..77dca70d314 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/blowfish.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/blowfish.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,33 +18,12 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_BLOWFISH_H #define MBEDTLS_BLOWFISH_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif @@ -58,7 +31,7 @@ #include #include -#include "platform_util.h" +#include "mbedtls/platform_util.h" #define MBEDTLS_BLOWFISH_ENCRYPT 1 #define MBEDTLS_BLOWFISH_DECRYPT 0 @@ -70,13 +43,16 @@ #if !defined(MBEDTLS_DEPRECATED_REMOVED) #define MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( -0x0016 ) #endif /* !MBEDTLS_DEPRECATED_REMOVED */ -#define MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA -0x0016 /**< Bad input data. */ +/** Bad input data. */ +#define MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA -0x0016 -#define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018 /**< Invalid data input length. */ +/** Invalid data input length. */ +#define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018 /* MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED is deprecated and should not be used. */ -#define MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED -0x0017 /**< Blowfish hardware accelerator failed. */ +/** Blowfish hardware accelerator failed. */ +#define MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED -0x0017 #ifdef __cplusplus extern "C" { diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/bn_mul.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/bn_mul.h index 6f1201bf50a..31137cd4c23 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/bn_mul.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/bn_mul.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,27 +18,6 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ /* * Multiply source vector [s] with b, add result @@ -64,12 +37,12 @@ #define MBEDTLS_BN_MUL_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "bignum.h" +#include "mbedtls/bignum.h" /* @@ -256,13 +229,37 @@ "addq $8, %%rdi\n" #define MULADDC_STOP \ - : "+c" (c), "+D" (d), "+S" (s) \ - : "b" (b) \ - : "rax", "rdx", "r8" \ + : "+c" (c), "+D" (d), "+S" (s), "+m" (*(uint64_t (*)[16]) d) \ + : "b" (b), "m" (*(const uint64_t (*)[16]) s) \ + : "rax", "rdx", "r8" \ ); #endif /* AMD64 */ +#if defined(__aarch64__) + +#define MULADDC_INIT \ + asm( + +#define MULADDC_CORE \ + "ldr x4, [%2], #8 \n\t" \ + "ldr x5, [%1] \n\t" \ + "mul x6, x4, %4 \n\t" \ + "umulh x7, x4, %4 \n\t" \ + "adds x5, x5, x6 \n\t" \ + "adc x7, x7, xzr \n\t" \ + "adds x5, x5, %0 \n\t" \ + "adc %0, x7, xzr \n\t" \ + "str x5, [%1], #8 \n\t" + +#define MULADDC_STOP \ + : "+r" (c), "+r" (d), "+r" (s), "+m" (*(uint64_t (*)[16]) d) \ + : "r" (b), "m" (*(const uint64_t (*)[16]) s) \ + : "x4", "x5", "x6", "x7", "cc" \ + ); + +#endif /* Aarch64 */ + #if defined(__mc68020__) || defined(__mcpu32__) #define MULADDC_INIT \ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/camellia.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/camellia.h index 38871288e4b..925a623e47e 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/camellia.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/camellia.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,33 +18,12 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_CAMELLIA_H #define MBEDTLS_CAMELLIA_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif @@ -58,7 +31,7 @@ #include #include -#include "platform_util.h" +#include "mbedtls/platform_util.h" #define MBEDTLS_CAMELLIA_ENCRYPT 1 #define MBEDTLS_CAMELLIA_DECRYPT 0 @@ -66,13 +39,16 @@ #if !defined(MBEDTLS_DEPRECATED_REMOVED) #define MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( -0x0024 ) #endif /* !MBEDTLS_DEPRECATED_REMOVED */ -#define MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA -0x0024 /**< Bad input data. */ +/** Bad input data. */ +#define MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA -0x0024 -#define MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0026 /**< Invalid data input length. */ +/** Invalid data input length. */ +#define MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0026 /* MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED is deprecated and should not be used. */ -#define MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED -0x0027 /**< Camellia hardware accelerator failed. */ +/** Camellia hardware accelerator failed. */ +#define MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED -0x0027 #ifdef __cplusplus extern "C" { diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ccm.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ccm.h index d50c6ec9939..ece5a901cb6 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ccm.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ccm.h @@ -29,13 +29,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -48,45 +42,27 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_CCM_H #define MBEDTLS_CCM_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "cipher.h" +#include "mbedtls/cipher.h" -#define MBEDTLS_ERR_CCM_BAD_INPUT -0x000D /**< Bad input parameters to the function. */ -#define MBEDTLS_ERR_CCM_AUTH_FAILED -0x000F /**< Authenticated decryption failed. */ +/** Bad input parameters to the function. */ +#define MBEDTLS_ERR_CCM_BAD_INPUT -0x000D +/** Authenticated decryption failed. */ +#define MBEDTLS_ERR_CCM_AUTH_FAILED -0x000F /* MBEDTLS_ERR_CCM_HW_ACCEL_FAILED is deprecated and should not be used. */ -#define MBEDTLS_ERR_CCM_HW_ACCEL_FAILED -0x0011 /**< CCM hardware accelerator failed. */ +/** CCM hardware accelerator failed. */ +#define MBEDTLS_ERR_CCM_HW_ACCEL_FAILED -0x0011 #ifdef __cplusplus extern "C" { diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/certs.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/certs.h index 8472a6f38ce..c93c741c7ff 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/certs.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/certs.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,33 +18,12 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_CERTS_H #define MBEDTLS_CERTS_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/chacha20.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/chacha20.h index 8c9c2af6ffb..03b48714780 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/chacha20.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/chacha20.h @@ -14,13 +14,7 @@ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -33,34 +27,13 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_CHACHA20_H #define MBEDTLS_CHACHA20_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif @@ -68,15 +41,18 @@ #include #include -#define MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA -0x0051 /**< Invalid input parameter(s). */ +/** Invalid input parameter(s). */ +#define MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA -0x0051 /* MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE is deprecated and should not be * used. */ -#define MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE -0x0053 /**< Feature not available. For example, s part of the API is not implemented. */ +/** Feature not available. For example, s part of the API is not implemented. */ +#define MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE -0x0053 /* MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED is deprecated and should not be used. */ -#define MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED -0x0055 /**< Chacha20 hardware accelerator failed. */ +/** Chacha20 hardware accelerator failed. */ +#define MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED -0x0055 #ifdef __cplusplus extern "C" { diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/chachapoly.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/chachapoly.h index 5f6cb6e0306..c4ec7b5f2a9 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/chachapoly.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/chachapoly.h @@ -14,13 +14,7 @@ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -33,43 +27,24 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_CHACHAPOLY_H #define MBEDTLS_CHACHAPOLY_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif /* for shared error codes */ -#include "poly1305.h" +#include "mbedtls/poly1305.h" -#define MBEDTLS_ERR_CHACHAPOLY_BAD_STATE -0x0054 /**< The requested operation is not permitted in the current state. */ -#define MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED -0x0056 /**< Authenticated decryption failed: data was not authentic. */ +/** The requested operation is not permitted in the current state. */ +#define MBEDTLS_ERR_CHACHAPOLY_BAD_STATE -0x0054 +/** Authenticated decryption failed: data was not authentic. */ +#define MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED -0x0056 #ifdef __cplusplus extern "C" { @@ -84,7 +59,7 @@ mbedtls_chachapoly_mode_t; #if !defined(MBEDTLS_CHACHAPOLY_ALT) -#include "chacha20.h" +#include "mbedtls/chacha20.h" typedef struct mbedtls_chachapoly_context { diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/check_config.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/check_config.h index 2bbd7a80ffe..396fe7dfc2b 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/check_config.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/check_config.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,27 +18,6 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ /* @@ -70,16 +43,20 @@ #endif /* Fix the config here. Not convenient to put an #ifdef _WIN32 in config.h as - * it would confuse config.pl. */ + * it would confuse config.py. */ #if !defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) && \ !defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO) #define MBEDTLS_PLATFORM_SNPRINTF_ALT #endif + +#if !defined(MBEDTLS_PLATFORM_VSNPRINTF_ALT) && \ + !defined(MBEDTLS_PLATFORM_VSNPRINTF_MACRO) +#define MBEDTLS_PLATFORM_VSNPRINTF_ALT +#endif #endif /* _WIN32 */ -#if defined(TARGET_LIKE_MBED) && \ - ( defined(MBEDTLS_NET_C) || defined(MBEDTLS_TIMING_C) ) -#error "The NET and TIMING modules are not available for mbed OS - please use the network and timing functions provided by mbed OS" +#if defined(TARGET_LIKE_MBED) && defined(MBEDTLS_NET_C) +#error "The NET module is not available for mbed OS - please use the network functions provided by Mbed OS" #endif #if defined(MBEDTLS_DEPRECATED_WARNING) && \ @@ -123,6 +100,17 @@ #if defined(MBEDTLS_ECDSA_C) && \ ( !defined(MBEDTLS_ECP_C) || \ + !( defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) || \ + defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) || \ + defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) || \ + defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) || \ + defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) || \ + defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) || \ + defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) || \ + defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) || \ + defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) || \ + defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) || \ + defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) ) || \ !defined(MBEDTLS_ASN1_PARSE_C) || \ !defined(MBEDTLS_ASN1_WRITE_C) ) #error "MBEDTLS_ECDSA_C defined, but not all prerequisites" @@ -134,14 +122,25 @@ #endif #if defined(MBEDTLS_ECP_RESTARTABLE) && \ - ( defined(MBEDTLS_ECDH_COMPUTE_SHARED_ALT) || \ + ( defined(MBEDTLS_USE_PSA_CRYPTO) || \ + defined(MBEDTLS_ECDH_COMPUTE_SHARED_ALT) || \ defined(MBEDTLS_ECDH_GEN_PUBLIC_ALT) || \ defined(MBEDTLS_ECDSA_SIGN_ALT) || \ defined(MBEDTLS_ECDSA_VERIFY_ALT) || \ defined(MBEDTLS_ECDSA_GENKEY_ALT) || \ defined(MBEDTLS_ECP_INTERNAL_ALT) || \ defined(MBEDTLS_ECP_ALT) ) -#error "MBEDTLS_ECP_RESTARTABLE defined, but it cannot coexist with an alternative ECP implementation" +#error "MBEDTLS_ECP_RESTARTABLE defined, but it cannot coexist with an alternative or PSA-based ECP implementation" +#endif + +#if defined(MBEDTLS_ECP_RESTARTABLE) && \ + ! defined(MBEDTLS_ECDH_LEGACY_CONTEXT) +#error "MBEDTLS_ECP_RESTARTABLE defined, but not MBEDTLS_ECDH_LEGACY_CONTEXT" +#endif + +#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED) && \ + defined(MBEDTLS_ECDH_LEGACY_CONTEXT) +#error "MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED defined, but MBEDTLS_ECDH_LEGACY_CONTEXT not disabled" #endif #if defined(MBEDTLS_ECDSA_DETERMINISTIC) && !defined(MBEDTLS_HMAC_DRBG_C) @@ -169,10 +168,8 @@ defined(MBEDTLS_ECP_ALT) || \ defined(MBEDTLS_CTR_DRBG_C) || \ defined(MBEDTLS_HMAC_DRBG_C) || \ - defined(MBEDTLS_SHA512_C) || \ - defined(MBEDTLS_SHA256_C) || \ defined(MBEDTLS_ECP_NO_INTERNAL_RNG)) -#error "MBEDTLS_ECP_C requires a DRBG or SHA-2 module unless MBEDTLS_ECP_NO_INTERNAL_RNG is defined or an alternative implementation is used" +#error "MBEDTLS_ECP_C requires a DRBG module unless MBEDTLS_ECP_NO_INTERNAL_RNG is defined or an alternative implementation is used" #endif #if defined(MBEDTLS_PK_PARSE_C) && !defined(MBEDTLS_ASN1_PARSE_C) @@ -218,7 +215,7 @@ #endif #if defined(MBEDTLS_GCM_C) && ( \ - !defined(MBEDTLS_AES_C) && !defined(MBEDTLS_CAMELLIA_C) ) + !defined(MBEDTLS_AES_C) && !defined(MBEDTLS_CAMELLIA_C) && !defined(MBEDTLS_ARIA_C) ) #error "MBEDTLS_GCM_C defined, but not all prerequisites" #endif @@ -254,6 +251,10 @@ #error "MBEDTLS_ECP_NORMALIZE_MXZ_ALT defined, but not all prerequisites" #endif +#if defined(MBEDTLS_ECP_NO_FALLBACK) && !defined(MBEDTLS_ECP_INTERNAL_ALT) +#error "MBEDTLS_ECP_NO_FALLBACK defined, but no alternative implementation enabled" +#endif + #if defined(MBEDTLS_HAVEGE_C) && !defined(MBEDTLS_TIMING_C) #error "MBEDTLS_HAVEGE_C defined, but not all prerequisites" #endif @@ -267,12 +268,14 @@ #endif #if defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) && \ - ( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) ) + ( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_ECDSA_C) || \ + !defined(MBEDTLS_X509_CRT_PARSE_C) ) #error "MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED defined, but not all prerequisites" #endif #if defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) && \ - ( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) ) + ( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_RSA_C) || \ + !defined(MBEDTLS_X509_CRT_PARSE_C) ) #error "MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED defined, but not all prerequisites" #endif @@ -321,6 +324,14 @@ #error "MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED defined, but not all prerequisites" #endif +#if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED) && \ + !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE) && \ + ( !defined(MBEDTLS_SHA256_C) && \ + !defined(MBEDTLS_SHA512_C) && \ + !defined(MBEDTLS_SHA1_C) ) +#error "!MBEDTLS_SSL_KEEP_PEER_CERTIFICATE requires MBEDTLS_SHA512_C, MBEDTLS_SHA256_C or MBEDTLS_SHA1_C" +#endif + #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \ ( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY) ) #error "MBEDTLS_MEMORY_BUFFER_ALLOC_C defined, but not all prerequisites" @@ -363,6 +374,14 @@ #error "MBEDTLS_PKCS11_C defined, but not all prerequisites" #endif +#if defined(MBEDTLS_PKCS11_C) +#if defined(MBEDTLS_DEPRECATED_REMOVED) +#error "MBEDTLS_PKCS11_C is deprecated and will be removed in a future version of Mbed TLS" +#elif defined(MBEDTLS_DEPRECATED_WARNING) +#warning "MBEDTLS_PKCS11_C is deprecated and will be removed in a future version of Mbed TLS" +#endif +#endif /* MBEDTLS_PKCS11_C */ + #if defined(MBEDTLS_PLATFORM_EXIT_ALT) && !defined(MBEDTLS_PLATFORM_C) #error "MBEDTLS_PLATFORM_EXIT_ALT defined, but not all prerequisites" #endif @@ -490,10 +509,6 @@ #error "MBEDTLS_PLATFORM_STD_CALLOC defined, but not all prerequisites" #endif -#if defined(MBEDTLS_PLATFORM_STD_CALLOC) && !defined(MBEDTLS_PLATFORM_MEMORY) -#error "MBEDTLS_PLATFORM_STD_CALLOC defined, but not all prerequisites" -#endif - #if defined(MBEDTLS_PLATFORM_STD_FREE) && !defined(MBEDTLS_PLATFORM_MEMORY) #error "MBEDTLS_PLATFORM_STD_FREE defined, but not all prerequisites" #endif @@ -556,6 +571,54 @@ #error "MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO and MBEDTLS_PLATFORM_STD_NV_SEED_WRITE cannot be defined simultaneously" #endif +#if defined(MBEDTLS_PSA_CRYPTO_C) && \ + !( ( ( defined(MBEDTLS_CTR_DRBG_C) || defined(MBEDTLS_HMAC_DRBG_C) ) && \ + defined(MBEDTLS_ENTROPY_C) ) || \ + defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) ) +#error "MBEDTLS_PSA_CRYPTO_C defined, but not all prerequisites (missing RNG)" +#endif + +#if defined(MBEDTLS_PSA_CRYPTO_SPM) && !defined(MBEDTLS_PSA_CRYPTO_C) +#error "MBEDTLS_PSA_CRYPTO_SPM defined, but not all prerequisites" +#endif + +#if defined(MBEDTLS_PSA_CRYPTO_SE_C) && \ + ! ( defined(MBEDTLS_PSA_CRYPTO_C) && \ + defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) ) +#error "MBEDTLS_PSA_CRYPTO_SE_C defined, but not all prerequisites" +#endif + +#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) && \ + ! defined(MBEDTLS_PSA_CRYPTO_C) +#error "MBEDTLS_PSA_CRYPTO_STORAGE_C defined, but not all prerequisites" +#endif + +#if defined(MBEDTLS_PSA_INJECT_ENTROPY) && \ + !( defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) && \ + defined(MBEDTLS_ENTROPY_NV_SEED) ) +#error "MBEDTLS_PSA_INJECT_ENTROPY defined, but not all prerequisites" +#endif + +#if defined(MBEDTLS_PSA_INJECT_ENTROPY) && \ + !defined(MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES) +#error "MBEDTLS_PSA_INJECT_ENTROPY is not compatible with actual entropy sources" +#endif + +#if defined(MBEDTLS_PSA_INJECT_ENTROPY) && \ + defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) +#error "MBEDTLS_PSA_INJECT_ENTROPY is not compatible with MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG" +#endif + +#if defined(MBEDTLS_PSA_ITS_FILE_C) && \ + !defined(MBEDTLS_FS_IO) +#error "MBEDTLS_PSA_ITS_FILE_C defined, but not all prerequisites" +#endif + +#if defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER) && \ + defined(MBEDTLS_USE_PSA_CRYPTO) +#error "MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER defined, but it cannot coexist with MBEDTLS_USE_PSA_CRYPTO." +#endif + #if defined(MBEDTLS_RSA_C) && ( !defined(MBEDTLS_BIGNUM_C) || \ !defined(MBEDTLS_OID_C) ) #error "MBEDTLS_RSA_C defined, but not all prerequisites" @@ -571,6 +634,10 @@ #error "MBEDTLS_X509_RSASSA_PSS_SUPPORT defined, but not all prerequisites" #endif +#if defined(MBEDTLS_SHA512_NO_SHA384) && !defined(MBEDTLS_SHA512_C) +#error "MBEDTLS_SHA512_NO_SHA384 defined without MBEDTLS_SHA512_C" +#endif + #if defined(MBEDTLS_SSL_PROTO_SSL3) && ( !defined(MBEDTLS_MD5_C) || \ !defined(MBEDTLS_SHA1_C) ) #error "MBEDTLS_SSL_PROTO_SSL3 defined, but not all prerequisites" @@ -591,6 +658,11 @@ #error "MBEDTLS_SSL_PROTO_TLS1_2 defined, but not all prerequisites" #endif +#if defined(MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL) && ( !defined(MBEDTLS_HKDF_C) && \ + !defined(MBEDTLS_SHA256_C) && !defined(MBEDTLS_SHA512_C) ) +#error "MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL defined, but not all prerequisites" +#endif + #if (defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \ defined(MBEDTLS_SSL_PROTO_TLS1_1) || defined(MBEDTLS_SSL_PROTO_TLS1_2)) && \ !(defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || \ @@ -663,6 +735,23 @@ #error "MBEDTLS_SSL_DTLS_ANTI_REPLAY defined, but not all prerequisites" #endif +#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) && \ + ( !defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_PROTO_DTLS) ) +#error "MBEDTLS_SSL_DTLS_CONNECTION_ID defined, but not all prerequisites" +#endif + +#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) && \ + defined(MBEDTLS_SSL_CID_IN_LEN_MAX) && \ + MBEDTLS_SSL_CID_IN_LEN_MAX > 255 +#error "MBEDTLS_SSL_CID_IN_LEN_MAX too large (max 255)" +#endif + +#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) && \ + defined(MBEDTLS_SSL_CID_OUT_LEN_MAX) && \ + MBEDTLS_SSL_CID_OUT_LEN_MAX > 255 +#error "MBEDTLS_SSL_CID_OUT_LEN_MAX too large (max 255)" +#endif + #if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT) && \ ( !defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_PROTO_DTLS) ) #error "MBEDTLS_SSL_DTLS_BADMAC_LIMIT defined, but not all prerequisites" @@ -715,6 +804,10 @@ #endif #undef MBEDTLS_THREADING_IMPL +#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_PSA_CRYPTO_C) +#error "MBEDTLS_USE_PSA_CRYPTO defined, but not all prerequisites" +#endif + #if defined(MBEDTLS_VERSION_FEATURES) && !defined(MBEDTLS_VERSION_C) #error "MBEDTLS_VERSION_FEATURES defined, but not all prerequisites" #endif @@ -764,6 +857,38 @@ #error "MBEDTLS_HAVE_INT32/MBEDTLS_HAVE_INT64 and MBEDTLS_HAVE_ASM cannot be defined simultaneously" #endif /* (MBEDTLS_HAVE_INT32 || MBEDTLS_HAVE_INT64) && MBEDTLS_HAVE_ASM */ +#if defined(MBEDTLS_SSL_PROTO_SSL3) +#if defined(MBEDTLS_DEPRECATED_REMOVED) +#error "MBEDTLS_SSL_PROTO_SSL3 is deprecated and will be removed in a future version of Mbed TLS" +#elif defined(MBEDTLS_DEPRECATED_WARNING) +#warning "MBEDTLS_SSL_PROTO_SSL3 is deprecated and will be removed in a future version of Mbed TLS" +#endif +#endif /* MBEDTLS_SSL_PROTO_SSL3 */ + +#if defined(MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO) +#if defined(MBEDTLS_DEPRECATED_REMOVED) +#error "MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO is deprecated and will be removed in a future version of Mbed TLS" +#elif defined(MBEDTLS_DEPRECATED_WARNING) +#warning "MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO is deprecated and will be removed in a future version of Mbed TLS" +#endif +#endif /* MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO */ + +#if defined(MBEDTLS_SSL_HW_RECORD_ACCEL) +#if defined(MBEDTLS_DEPRECATED_REMOVED) +#error "MBEDTLS_SSL_HW_RECORD_ACCEL is deprecated and will be removed in a future version of Mbed TLS" +#elif defined(MBEDTLS_DEPRECATED_WARNING) +#warning "MBEDTLS_SSL_HW_RECORD_ACCEL is deprecated and will be removed in a future version of Mbed TLS" +#endif /* MBEDTLS_DEPRECATED_REMOVED */ +#endif /* MBEDTLS_SSL_HW_RECORD_ACCEL */ + +#if defined(MBEDTLS_SSL_DTLS_SRTP) && ( !defined(MBEDTLS_SSL_PROTO_DTLS) ) +#error "MBEDTLS_SSL_DTLS_SRTP defined, but not all prerequisites" +#endif + +#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH) && ( !defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) ) +#error "MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH defined, but not all prerequisites" +#endif + /* * Avoid warning from -pedantic. This is a convenient place for this * workaround since this is included by every single file before the diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/cipher.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/cipher.h index 1f41b528c48..6d83da8827e 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/cipher.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/cipher.h @@ -9,13 +9,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -28,40 +22,19 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_CIPHER_H #define MBEDTLS_CIPHER_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif #include -#include "platform_util.h" +#include "mbedtls/platform_util.h" #if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CCM_C) || defined(MBEDTLS_CHACHAPOLY_C) #define MBEDTLS_CIPHER_MODE_AEAD @@ -81,16 +54,24 @@ #define inline __inline #endif -#define MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE -0x6080 /**< The selected feature is not available. */ -#define MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA -0x6100 /**< Bad input parameters. */ -#define MBEDTLS_ERR_CIPHER_ALLOC_FAILED -0x6180 /**< Failed to allocate memory. */ -#define MBEDTLS_ERR_CIPHER_INVALID_PADDING -0x6200 /**< Input data contains invalid padding and is rejected. */ -#define MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED -0x6280 /**< Decryption of block requires a full block. */ -#define MBEDTLS_ERR_CIPHER_AUTH_FAILED -0x6300 /**< Authentication failed (for AEAD modes). */ -#define MBEDTLS_ERR_CIPHER_INVALID_CONTEXT -0x6380 /**< The context is invalid. For example, because it was freed. */ +/** The selected feature is not available. */ +#define MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE -0x6080 +/** Bad input parameters. */ +#define MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA -0x6100 +/** Failed to allocate memory. */ +#define MBEDTLS_ERR_CIPHER_ALLOC_FAILED -0x6180 +/** Input data contains invalid padding and is rejected. */ +#define MBEDTLS_ERR_CIPHER_INVALID_PADDING -0x6200 +/** Decryption of block requires a full block. */ +#define MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED -0x6280 +/** Authentication failed (for AEAD modes). */ +#define MBEDTLS_ERR_CIPHER_AUTH_FAILED -0x6300 +/** The context is invalid. For example, because it was freed. */ +#define MBEDTLS_ERR_CIPHER_INVALID_CONTEXT -0x6380 /* MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED is deprecated and should not be used. */ -#define MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED -0x6400 /**< Cipher hardware accelerator failed. */ +/** Cipher hardware accelerator failed. */ +#define MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED -0x6400 #define MBEDTLS_CIPHER_VARIABLE_IV_LEN 0x01 /**< Cipher accepts IVs of variable length. */ #define MBEDTLS_CIPHER_VARIABLE_KEY_LEN 0x02 /**< Cipher accepts keys of variable length. */ @@ -201,21 +182,29 @@ typedef enum { MBEDTLS_CIPHER_AES_256_XTS, /**< AES 256-bit cipher in XTS block mode. */ MBEDTLS_CIPHER_CHACHA20, /**< ChaCha20 stream cipher. */ MBEDTLS_CIPHER_CHACHA20_POLY1305, /**< ChaCha20-Poly1305 AEAD cipher. */ + MBEDTLS_CIPHER_AES_128_KW, /**< AES cipher with 128-bit NIST KW mode. */ + MBEDTLS_CIPHER_AES_192_KW, /**< AES cipher with 192-bit NIST KW mode. */ + MBEDTLS_CIPHER_AES_256_KW, /**< AES cipher with 256-bit NIST KW mode. */ + MBEDTLS_CIPHER_AES_128_KWP, /**< AES cipher with 128-bit NIST KWP mode. */ + MBEDTLS_CIPHER_AES_192_KWP, /**< AES cipher with 192-bit NIST KWP mode. */ + MBEDTLS_CIPHER_AES_256_KWP, /**< AES cipher with 256-bit NIST KWP mode. */ } mbedtls_cipher_type_t; /** Supported cipher modes. */ typedef enum { - MBEDTLS_MODE_NONE = 0, /**< None. */ - MBEDTLS_MODE_ECB, /**< The ECB cipher mode. */ - MBEDTLS_MODE_CBC, /**< The CBC cipher mode. */ - MBEDTLS_MODE_CFB, /**< The CFB cipher mode. */ - MBEDTLS_MODE_OFB, /**< The OFB cipher mode. */ - MBEDTLS_MODE_CTR, /**< The CTR cipher mode. */ - MBEDTLS_MODE_GCM, /**< The GCM cipher mode. */ - MBEDTLS_MODE_STREAM, /**< The stream cipher mode. */ - MBEDTLS_MODE_CCM, /**< The CCM cipher mode. */ - MBEDTLS_MODE_XTS, /**< The XTS cipher mode. */ + MBEDTLS_MODE_NONE = 0, /**< None. */ + MBEDTLS_MODE_ECB, /**< The ECB cipher mode. */ + MBEDTLS_MODE_CBC, /**< The CBC cipher mode. */ + MBEDTLS_MODE_CFB, /**< The CFB cipher mode. */ + MBEDTLS_MODE_OFB, /**< The OFB cipher mode. */ + MBEDTLS_MODE_CTR, /**< The CTR cipher mode. */ + MBEDTLS_MODE_GCM, /**< The GCM cipher mode. */ + MBEDTLS_MODE_STREAM, /**< The stream cipher mode. */ + MBEDTLS_MODE_CCM, /**< The CCM cipher mode. */ + MBEDTLS_MODE_XTS, /**< The XTS cipher mode. */ MBEDTLS_MODE_CHACHAPOLY, /**< The ChaCha-Poly cipher mode. */ + MBEDTLS_MODE_KW, /**< The SP800-38F KW mode */ + MBEDTLS_MODE_KWP, /**< The SP800-38F KWP mode */ } mbedtls_cipher_mode_t; /** Supported cipher padding types. */ @@ -246,10 +235,30 @@ enum { }; /** Maximum length of any IV, in Bytes. */ +/* This should ideally be derived automatically from list of ciphers. + * This should be kept in sync with MBEDTLS_SSL_MAX_IV_LENGTH defined + * in ssl_internal.h. */ #define MBEDTLS_MAX_IV_LENGTH 16 + /** Maximum block size of any cipher, in Bytes. */ +/* This should ideally be derived automatically from list of ciphers. + * This should be kept in sync with MBEDTLS_SSL_MAX_BLOCK_LENGTH defined + * in ssl_internal.h. */ #define MBEDTLS_MAX_BLOCK_LENGTH 16 +/** Maximum key length, in Bytes. */ +/* This should ideally be derived automatically from list of ciphers. + * For now, only check whether XTS is enabled which uses 64 Byte keys, + * and use 32 Bytes as an upper bound for the maximum key length otherwise. + * This should be kept in sync with MBEDTLS_SSL_MAX_BLOCK_LENGTH defined + * in ssl_internal.h, which however deliberately ignores the case of XTS + * since the latter isn't used in SSL/TLS. */ +#if defined(MBEDTLS_CIPHER_MODE_XTS) +#define MBEDTLS_MAX_KEY_LENGTH 64 +#else +#define MBEDTLS_MAX_KEY_LENGTH 32 +#endif /* MBEDTLS_CIPHER_MODE_XTS */ + /** * Base cipher information (opaque struct). */ @@ -347,14 +356,32 @@ typedef struct mbedtls_cipher_context_t /** CMAC-specific context. */ mbedtls_cmac_context_t *cmac_ctx; #endif + +#if defined(MBEDTLS_USE_PSA_CRYPTO) + /** Indicates whether the cipher operations should be performed + * by Mbed TLS' own crypto library or an external implementation + * of the PSA Crypto API. + * This is unset if the cipher context was established through + * mbedtls_cipher_setup(), and set if it was established through + * mbedtls_cipher_setup_psa(). + */ + unsigned char psa_enabled; +#endif /* MBEDTLS_USE_PSA_CRYPTO */ + } mbedtls_cipher_context_t; /** - * \brief This function retrieves the list of ciphers supported by the generic - * cipher module. + * \brief This function retrieves the list of ciphers supported + * by the generic cipher module. + * + * For any cipher identifier in the returned list, you can + * obtain the corresponding generic cipher information structure + * via mbedtls_cipher_info_from_type(), which can then be used + * to prepare a cipher context via mbedtls_cipher_setup(). * - * \return A statically-allocated array of ciphers. The last entry - * is zero. + * + * \return A statically-allocated array of cipher identifiers + * of type cipher_type_t. The last entry is zero. */ const int *mbedtls_cipher_list( void ); @@ -421,9 +448,8 @@ void mbedtls_cipher_free( mbedtls_cipher_context_t *ctx ); /** - * \brief This function initializes and fills the cipher-context - * structure with the appropriate values. It also clears - * the structure. + * \brief This function initializes a cipher context for + * use with the given cipher primitive. * * \param ctx The context to initialize. This must be initialized. * \param cipher_info The cipher to use. @@ -441,6 +467,33 @@ void mbedtls_cipher_free( mbedtls_cipher_context_t *ctx ); int mbedtls_cipher_setup( mbedtls_cipher_context_t *ctx, const mbedtls_cipher_info_t *cipher_info ); +#if defined(MBEDTLS_USE_PSA_CRYPTO) +/** + * \brief This function initializes a cipher context for + * PSA-based use with the given cipher primitive. + * + * \note See #MBEDTLS_USE_PSA_CRYPTO for information on PSA. + * + * \param ctx The context to initialize. May not be \c NULL. + * \param cipher_info The cipher to use. + * \param taglen For AEAD ciphers, the length in bytes of the + * authentication tag to use. Subsequent uses of + * mbedtls_cipher_auth_encrypt() or + * mbedtls_cipher_auth_decrypt() must provide + * the same tag length. + * For non-AEAD ciphers, the value must be \c 0. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on + * parameter-verification failure. + * \return #MBEDTLS_ERR_CIPHER_ALLOC_FAILED if allocation of the + * cipher-specific context fails. + */ +int mbedtls_cipher_setup_psa( mbedtls_cipher_context_t *ctx, + const mbedtls_cipher_info_t *cipher_info, + size_t taglen ); +#endif /* MBEDTLS_USE_PSA_CRYPTO */ + /** * \brief This function returns the block size of the given cipher. * @@ -663,7 +716,7 @@ int mbedtls_cipher_reset( mbedtls_cipher_context_t *ctx ); * \param ctx The generic cipher context. This must be initialized. * \param ad The additional data to use. This must be a readable * buffer of at least \p ad_len Bytes. - * \param ad_len the Length of \p ad Bytes. + * \param ad_len The length of \p ad in Bytes. * * \return \c 0 on success. * \return A specific error code on failure. @@ -706,8 +759,10 @@ int mbedtls_cipher_update_ad( mbedtls_cipher_context_t *ctx, * unsupported mode for a cipher. * \return A cipher-specific error code on failure. */ -int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, const unsigned char *input, - size_t ilen, unsigned char *output, size_t *olen ); +int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, + const unsigned char *input, + size_t ilen, unsigned char *output, + size_t *olen ); /** * \brief The generic cipher finalization function. If data still @@ -810,30 +865,52 @@ int mbedtls_cipher_crypt( mbedtls_cipher_context_t *ctx, unsigned char *output, size_t *olen ); #if defined(MBEDTLS_CIPHER_MODE_AEAD) +#if ! defined(MBEDTLS_DEPRECATED_REMOVED) +#if defined(MBEDTLS_DEPRECATED_WARNING) +#define MBEDTLS_DEPRECATED __attribute__((deprecated)) +#else +#define MBEDTLS_DEPRECATED +#endif /* MBEDTLS_DEPRECATED_WARNING */ /** - * \brief The generic autenticated encryption (AEAD) function. + * \brief The generic authenticated encryption (AEAD) function. + * + * \deprecated Superseded by mbedtls_cipher_auth_encrypt_ext(). + * + * \note This function only supports AEAD algorithms, not key + * wrapping algorithms such as NIST_KW; for this, see + * mbedtls_cipher_auth_encrypt_ext(). * * \param ctx The generic cipher context. This must be initialized and - * bound to a key. - * \param iv The IV to use, or NONCE_COUNTER for CTR-mode ciphers. - * This must be a readable buffer of at least \p iv_len - * Bytes. - * \param iv_len The IV length for ciphers with variable-size IV. - * This parameter is discarded by ciphers with fixed-size IV. + * bound to a key associated with an AEAD algorithm. + * \param iv The nonce to use. This must be a readable buffer of + * at least \p iv_len Bytes and must not be \c NULL. + * \param iv_len The length of the nonce. This must satisfy the + * constraints imposed by the AEAD cipher used. * \param ad The additional data to authenticate. This must be a - * readable buffer of at least \p ad_len Bytes. + * readable buffer of at least \p ad_len Bytes, and may + * be \c NULL is \p ad_len is \c 0. * \param ad_len The length of \p ad. * \param input The buffer holding the input data. This must be a - * readable buffer of at least \p ilen Bytes. + * readable buffer of at least \p ilen Bytes, and may be + * \c NULL if \p ilen is \c 0. * \param ilen The length of the input data. - * \param output The buffer for the output data. This must be able to - * hold at least \p ilen Bytes. - * \param olen The length of the output data, to be updated with the - * actual number of Bytes written. This must not be - * \c NULL. + * \param output The buffer for the output data. This must be a + * writable buffer of at least \p ilen Bytes, and must + * not be \c NULL. + * \param olen This will be filled with the actual number of Bytes + * written to the \p output buffer. This must point to a + * writable object of type \c size_t. * \param tag The buffer for the authentication tag. This must be a - * writable buffer of at least \p tag_len Bytes. - * \param tag_len The desired length of the authentication tag. + * writable buffer of at least \p tag_len Bytes. See note + * below regarding restrictions with PSA-based contexts. + * \param tag_len The desired length of the authentication tag. This + * must match the constraints imposed by the AEAD cipher + * used, and in particular must not be \c 0. + * + * \note If the context is based on PSA (that is, it was set up + * with mbedtls_cipher_setup_psa()), then it is required + * that \c tag == output + ilen. That is, the tag must be + * appended to the ciphertext as recommended by RFC 5116. * * \return \c 0 on success. * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on @@ -845,36 +922,53 @@ int mbedtls_cipher_auth_encrypt( mbedtls_cipher_context_t *ctx, const unsigned char *ad, size_t ad_len, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen, - unsigned char *tag, size_t tag_len ); + unsigned char *tag, size_t tag_len ) + MBEDTLS_DEPRECATED; /** - * \brief The generic autenticated decryption (AEAD) function. + * \brief The generic authenticated decryption (AEAD) function. + * + * \deprecated Superseded by mbedtls_cipher_auth_decrypt_ext(). + * + * \note This function only supports AEAD algorithms, not key + * wrapping algorithms such as NIST_KW; for this, see + * mbedtls_cipher_auth_decrypt_ext(). * * \note If the data is not authentic, then the output buffer * is zeroed out to prevent the unauthentic plaintext being * used, making this interface safer. * * \param ctx The generic cipher context. This must be initialized and - * and bound to a key. - * \param iv The IV to use, or NONCE_COUNTER for CTR-mode ciphers. - * This must be a readable buffer of at least \p iv_len - * Bytes. - * \param iv_len The IV length for ciphers with variable-size IV. - * This parameter is discarded by ciphers with fixed-size IV. - * \param ad The additional data to be authenticated. This must be a - * readable buffer of at least \p ad_len Bytes. + * bound to a key associated with an AEAD algorithm. + * \param iv The nonce to use. This must be a readable buffer of + * at least \p iv_len Bytes and must not be \c NULL. + * \param iv_len The length of the nonce. This must satisfy the + * constraints imposed by the AEAD cipher used. + * \param ad The additional data to authenticate. This must be a + * readable buffer of at least \p ad_len Bytes, and may + * be \c NULL is \p ad_len is \c 0. * \param ad_len The length of \p ad. * \param input The buffer holding the input data. This must be a - * readable buffer of at least \p ilen Bytes. + * readable buffer of at least \p ilen Bytes, and may be + * \c NULL if \p ilen is \c 0. * \param ilen The length of the input data. - * \param output The buffer for the output data. - * This must be able to hold at least \p ilen Bytes. - * \param olen The length of the output data, to be updated with the - * actual number of Bytes written. This must not be - * \c NULL. - * \param tag The buffer holding the authentication tag. This must be - * a readable buffer of at least \p tag_len Bytes. - * \param tag_len The length of the authentication tag. + * \param output The buffer for the output data. This must be a + * writable buffer of at least \p ilen Bytes, and must + * not be \c NULL. + * \param olen This will be filled with the actual number of Bytes + * written to the \p output buffer. This must point to a + * writable object of type \c size_t. + * \param tag The buffer for the authentication tag. This must be a + * readable buffer of at least \p tag_len Bytes. See note + * below regarding restrictions with PSA-based contexts. + * \param tag_len The length of the authentication tag. This must match + * the constraints imposed by the AEAD cipher used, and in + * particular must not be \c 0. + * + * \note If the context is based on PSA (that is, it was set up + * with mbedtls_cipher_setup_psa()), then it is required + * that \c tag == input + len. That is, the tag must be + * appended to the ciphertext as recommended by RFC 5116. * * \return \c 0 on success. * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on @@ -887,9 +981,120 @@ int mbedtls_cipher_auth_decrypt( mbedtls_cipher_context_t *ctx, const unsigned char *ad, size_t ad_len, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen, - const unsigned char *tag, size_t tag_len ); + const unsigned char *tag, size_t tag_len ) + MBEDTLS_DEPRECATED; +#undef MBEDTLS_DEPRECATED +#endif /* MBEDTLS_DEPRECATED_REMOVED */ #endif /* MBEDTLS_CIPHER_MODE_AEAD */ +#if defined(MBEDTLS_CIPHER_MODE_AEAD) || defined(MBEDTLS_NIST_KW_C) +/** + * \brief The authenticated encryption (AEAD/NIST_KW) function. + * + * \note For AEAD modes, the tag will be appended to the + * ciphertext, as recommended by RFC 5116. + * (NIST_KW doesn't have a separate tag.) + * + * \param ctx The generic cipher context. This must be initialized and + * bound to a key, with an AEAD algorithm or NIST_KW. + * \param iv The nonce to use. This must be a readable buffer of + * at least \p iv_len Bytes and may be \c NULL if \p + * iv_len is \c 0. + * \param iv_len The length of the nonce. For AEAD ciphers, this must + * satisfy the constraints imposed by the cipher used. + * For NIST_KW, this must be \c 0. + * \param ad The additional data to authenticate. This must be a + * readable buffer of at least \p ad_len Bytes, and may + * be \c NULL is \p ad_len is \c 0. + * \param ad_len The length of \p ad. For NIST_KW, this must be \c 0. + * \param input The buffer holding the input data. This must be a + * readable buffer of at least \p ilen Bytes, and may be + * \c NULL if \p ilen is \c 0. + * \param ilen The length of the input data. + * \param output The buffer for the output data. This must be a + * writable buffer of at least \p output_len Bytes, and + * must not be \c NULL. + * \param output_len The length of the \p output buffer in Bytes. For AEAD + * ciphers, this must be at least \p ilen + \p tag_len. + * For NIST_KW, this must be at least \p ilen + 8 + * (rounded up to a multiple of 8 if KWP is used); + * \p ilen + 15 is always a safe value. + * \param olen This will be filled with the actual number of Bytes + * written to the \p output buffer. This must point to a + * writable object of type \c size_t. + * \param tag_len The desired length of the authentication tag. For AEAD + * ciphers, this must match the constraints imposed by + * the cipher used, and in particular must not be \c 0. + * For NIST_KW, this must be \c 0. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on + * parameter-verification failure. + * \return A cipher-specific error code on failure. + */ +int mbedtls_cipher_auth_encrypt_ext( mbedtls_cipher_context_t *ctx, + const unsigned char *iv, size_t iv_len, + const unsigned char *ad, size_t ad_len, + const unsigned char *input, size_t ilen, + unsigned char *output, size_t output_len, + size_t *olen, size_t tag_len ); + +/** + * \brief The authenticated encryption (AEAD/NIST_KW) function. + * + * \note If the data is not authentic, then the output buffer + * is zeroed out to prevent the unauthentic plaintext being + * used, making this interface safer. + * + * \note For AEAD modes, the tag must be appended to the + * ciphertext, as recommended by RFC 5116. + * (NIST_KW doesn't have a separate tag.) + * + * \param ctx The generic cipher context. This must be initialized and + * bound to a key, with an AEAD algorithm or NIST_KW. + * \param iv The nonce to use. This must be a readable buffer of + * at least \p iv_len Bytes and may be \c NULL if \p + * iv_len is \c 0. + * \param iv_len The length of the nonce. For AEAD ciphers, this must + * satisfy the constraints imposed by the cipher used. + * For NIST_KW, this must be \c 0. + * \param ad The additional data to authenticate. This must be a + * readable buffer of at least \p ad_len Bytes, and may + * be \c NULL is \p ad_len is \c 0. + * \param ad_len The length of \p ad. For NIST_KW, this must be \c 0. + * \param input The buffer holding the input data. This must be a + * readable buffer of at least \p ilen Bytes, and may be + * \c NULL if \p ilen is \c 0. + * \param ilen The length of the input data. For AEAD ciphers this + * must be at least \p tag_len. For NIST_KW this must be + * at least \c 8. + * \param output The buffer for the output data. This must be a + * writable buffer of at least \p output_len Bytes, and + * may be \c NULL if \p output_len is \c 0. + * \param output_len The length of the \p output buffer in Bytes. For AEAD + * ciphers, this must be at least \p ilen - \p tag_len. + * For NIST_KW, this must be at least \p ilen - 8. + * \param olen This will be filled with the actual number of Bytes + * written to the \p output buffer. This must point to a + * writable object of type \c size_t. + * \param tag_len The actual length of the authentication tag. For AEAD + * ciphers, this must match the constraints imposed by + * the cipher used, and in particular must not be \c 0. + * For NIST_KW, this must be \c 0. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on + * parameter-verification failure. + * \return #MBEDTLS_ERR_CIPHER_AUTH_FAILED if data is not authentic. + * \return A cipher-specific error code on failure. + */ +int mbedtls_cipher_auth_decrypt_ext( mbedtls_cipher_context_t *ctx, + const unsigned char *iv, size_t iv_len, + const unsigned char *ad, size_t ad_len, + const unsigned char *input, size_t ilen, + unsigned char *output, size_t output_len, + size_t *olen, size_t tag_len ); +#endif /* MBEDTLS_CIPHER_MODE_AEAD || MBEDTLS_NIST_KW_C */ #ifdef __cplusplus } #endif diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/cipher_internal.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/cipher_internal.h index 88282ec9d20..2484c01c7a4 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/cipher_internal.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/cipher_internal.h @@ -7,13 +7,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -26,38 +20,21 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_CIPHER_WRAP_H #define MBEDTLS_CIPHER_WRAP_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "cipher.h" +#include "mbedtls/cipher.h" + +#if defined(MBEDTLS_USE_PSA_CRYPTO) +#include "psa/crypto.h" +#endif /* MBEDTLS_USE_PSA_CRYPTO */ #ifdef __cplusplus extern "C" { @@ -139,6 +116,29 @@ typedef struct const mbedtls_cipher_info_t *info; } mbedtls_cipher_definition_t; +#if defined(MBEDTLS_USE_PSA_CRYPTO) +typedef enum +{ + MBEDTLS_CIPHER_PSA_KEY_UNSET = 0, + MBEDTLS_CIPHER_PSA_KEY_OWNED, /* Used for PSA-based cipher contexts which */ + /* use raw key material internally imported */ + /* as a volatile key, and which hence need */ + /* to destroy that key when the context is */ + /* freed. */ + MBEDTLS_CIPHER_PSA_KEY_NOT_OWNED, /* Used for PSA-based cipher contexts */ + /* which use a key provided by the */ + /* user, and which hence will not be */ + /* destroyed when the context is freed. */ +} mbedtls_cipher_psa_key_ownership; + +typedef struct +{ + psa_algorithm_t alg; + psa_key_id_t slot; + mbedtls_cipher_psa_key_ownership slot_state; +} mbedtls_cipher_context_psa; +#endif /* MBEDTLS_USE_PSA_CRYPTO */ + extern const mbedtls_cipher_definition_t mbedtls_cipher_definitions[]; extern int mbedtls_cipher_supported[]; diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/cmac.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/cmac.h index 5a7c9b246f0..8934886af74 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/cmac.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/cmac.h @@ -8,13 +8,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -27,46 +21,26 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_CMAC_H #define MBEDTLS_CMAC_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "cipher.h" +#include "mbedtls/cipher.h" #ifdef __cplusplus extern "C" { #endif /* MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED is deprecated and should not be used. */ -#define MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED -0x007A /**< CMAC hardware accelerator failed. */ +/** CMAC hardware accelerator failed. */ +#define MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED -0x007A #define MBEDTLS_AES_BLOCK_SIZE 16 #define MBEDTLS_DES3_BLOCK_SIZE 8 @@ -100,9 +74,23 @@ struct mbedtls_cmac_context_t #endif /* !MBEDTLS_CMAC_ALT */ /** - * \brief This function sets the CMAC key, and prepares to authenticate + * \brief This function starts a new CMAC computation + * by setting the CMAC key, and preparing to authenticate * the input data. - * Must be called with an initialized cipher context. + * It must be called with an initialized cipher context. + * + * Once this function has completed, data can be supplied + * to the CMAC computation by calling + * mbedtls_cipher_cmac_update(). + * + * To start a CMAC computation using the same key as a previous + * CMAC computation, use mbedtls_cipher_cmac_finish(). + * + * \note When the CMAC implementation is supplied by an alternate + * implementation (through #MBEDTLS_CMAC_ALT), some ciphers + * may not be supported by that implementation, and thus + * return an error. Alternate implementations must support + * AES-128 and AES-256, and may support AES-192 and 3DES. * * \param ctx The cipher context used for the CMAC operation, initialized * as one of the following types: MBEDTLS_CIPHER_AES_128_ECB, @@ -122,9 +110,15 @@ int mbedtls_cipher_cmac_starts( mbedtls_cipher_context_t *ctx, * \brief This function feeds an input buffer into an ongoing CMAC * computation. * - * It is called between mbedtls_cipher_cmac_starts() or - * mbedtls_cipher_cmac_reset(), and mbedtls_cipher_cmac_finish(). - * Can be called repeatedly. + * The CMAC computation must have previously been started + * by calling mbedtls_cipher_cmac_starts() or + * mbedtls_cipher_cmac_reset(). + * + * Call this function as many times as needed to input the + * data to be authenticated. + * Once all of the required data has been input, + * call mbedtls_cipher_cmac_finish() to obtain the result + * of the CMAC operation. * * \param ctx The cipher context used for the CMAC operation. * \param input The buffer holding the input data. @@ -138,12 +132,13 @@ int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx, const unsigned char *input, size_t ilen ); /** - * \brief This function finishes the CMAC operation, and writes - * the result to the output buffer. + * \brief This function finishes an ongoing CMAC operation, and + * writes the result to the output buffer. * - * It is called after mbedtls_cipher_cmac_update(). - * It can be followed by mbedtls_cipher_cmac_reset() and - * mbedtls_cipher_cmac_update(), or mbedtls_cipher_free(). + * It should be followed either by + * mbedtls_cipher_cmac_reset(), which starts another CMAC + * operation with the same key, or mbedtls_cipher_free(), + * which clears the cipher context. * * \param ctx The cipher context used for the CMAC operation. * \param output The output buffer for the CMAC checksum result. @@ -156,12 +151,14 @@ int mbedtls_cipher_cmac_finish( mbedtls_cipher_context_t *ctx, unsigned char *output ); /** - * \brief This function prepares the authentication of another - * message with the same key as the previous CMAC - * operation. + * \brief This function starts a new CMAC operation with the same + * key as the previous one. * - * It is called after mbedtls_cipher_cmac_finish() - * and before mbedtls_cipher_cmac_update(). + * It should be called after finishing the previous CMAC + * operation with mbedtls_cipher_cmac_finish(). + * After calling this function, + * call mbedtls_cipher_cmac_update() to supply the new + * CMAC operation with data. * * \param ctx The cipher context used for the CMAC operation. * @@ -181,6 +178,11 @@ int mbedtls_cipher_cmac_reset( mbedtls_cipher_context_t *ctx ); * The CMAC result is calculated as * output = generic CMAC(cmac key, input buffer). * + * \note When the CMAC implementation is supplied by an alternate + * implementation (through #MBEDTLS_CMAC_ALT), some ciphers + * may not be supported by that implementation, and thus + * return an error. Alternate implementations must support + * AES-128 and AES-256, and may support AES-192 and 3DES. * * \param cipher_info The cipher information. * \param key The CMAC key. @@ -225,6 +227,13 @@ int mbedtls_aes_cmac_prf_128( const unsigned char *key, size_t key_len, /** * \brief The CMAC checkup routine. * + * \note In case the CMAC routines are provided by an alternative + * implementation (i.e. #MBEDTLS_CMAC_ALT is defined), the + * checkup routine will succeed even if the implementation does + * not support the less widely used AES-192 or 3DES primitives. + * The self-test requires at least AES-128 and AES-256 to be + * supported by the underlying implementation. + * * \return \c 0 on success. * \return \c 1 on failure. */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/compat-1.3.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/compat-1.3.h index 45e5a1cf77c..40177512cab 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/compat-1.3.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/compat-1.3.h @@ -8,13 +8,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -27,31 +21,10 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif @@ -1275,9 +1248,9 @@ #define POLARSSL_KEY_EXCHANGE_PSK MBEDTLS_KEY_EXCHANGE_PSK #define POLARSSL_KEY_EXCHANGE_RSA MBEDTLS_KEY_EXCHANGE_RSA #define POLARSSL_KEY_EXCHANGE_RSA_PSK MBEDTLS_KEY_EXCHANGE_RSA_PSK -#define POLARSSL_KEY_EXCHANGE__SOME__ECDHE_ENABLED MBEDTLS_KEY_EXCHANGE__SOME__ECDHE_ENABLED -#define POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED -#define POLARSSL_KEY_EXCHANGE__WITH_CERT__ENABLED MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED +#define POLARSSL_KEY_EXCHANGE__SOME__ECDHE_ENABLED MBEDTLS_KEY_EXCHANGE_SOME_ECDHE_ENABLED +#define POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED +#define POLARSSL_KEY_EXCHANGE__WITH_CERT__ENABLED MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED #define POLARSSL_KEY_LENGTH_DES MBEDTLS_KEY_LENGTH_DES #define POLARSSL_KEY_LENGTH_DES_EDE MBEDTLS_KEY_LENGTH_DES_EDE #define POLARSSL_KEY_LENGTH_DES_EDE3 MBEDTLS_KEY_LENGTH_DES_EDE3 diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/config.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/config.h index b1d67f7a931..87b4e9192e7 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/config.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/config.h @@ -9,13 +9,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -28,27 +22,6 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_CONFIG_H @@ -251,33 +224,34 @@ //#define MBEDTLS_PLATFORM_FPRINTF_ALT //#define MBEDTLS_PLATFORM_PRINTF_ALT //#define MBEDTLS_PLATFORM_SNPRINTF_ALT +//#define MBEDTLS_PLATFORM_VSNPRINTF_ALT //#define MBEDTLS_PLATFORM_NV_SEED_ALT //#define MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT /** * \def MBEDTLS_DEPRECATED_WARNING * - * Mark deprecated functions so that they generate a warning if used. - * Functions deprecated in one version will usually be removed in the next - * version. You can enable this to help you prepare the transition to a new - * major version by making sure your code is not using these functions. + * Mark deprecated functions and features so that they generate a warning if + * used. Functionality deprecated in one version will usually be removed in the + * next version. You can enable this to help you prepare the transition to a + * new major version by making sure your code is not using this functionality. * * This only works with GCC and Clang. With other compilers, you may want to * use MBEDTLS_DEPRECATED_REMOVED * - * Uncomment to get warnings on using deprecated functions. + * Uncomment to get warnings on using deprecated functions and features. */ //#define MBEDTLS_DEPRECATED_WARNING /** * \def MBEDTLS_DEPRECATED_REMOVED * - * Remove deprecated functions so that they generate an error if used. - * Functions deprecated in one version will usually be removed in the next - * version. You can enable this to help you prepare the transition to a new - * major version by making sure your code is not using these functions. + * Remove deprecated functions and features so that they generate an error if + * used. Functionality deprecated in one version will usually be removed in the + * next version. You can enable this to help you prepare the transition to a + * new major version by making sure your code is not using this functionality. * - * Uncomment to get errors on using deprecated functions. + * Uncomment to get errors on using deprecated functions and features. */ //#define MBEDTLS_DEPRECATED_REMOVED @@ -319,7 +293,7 @@ * the function mbedtls_param_failed() in your application. * See `platform_util.h` for its prototype. * - If you enable the macro #MBEDTLS_CHECK_PARAMS_ASSERT, then the - * library defines #MBEDTLS_PARAM_FAILED(\c cond) to be `assert(cond)`. + * library defines MBEDTLS_PARAM_FAILED(\c cond) to be `assert(cond)`. * You can still supply an alternative definition of * MBEDTLS_PARAM_FAILED(), which may call `assert`. * - If you define a macro MBEDTLS_PARAM_FAILED() before including `config.h` @@ -510,6 +484,11 @@ * is still present and it is used for group structures not supported by the * alternative. * + * The original implementation can in addition be removed by setting the + * MBEDTLS_ECP_NO_FALLBACK option, in which case any function for which the + * corresponding MBEDTLS_ECP__FUNCTION_NAME__ALT macro is defined will not be + * able to fallback to curves not supported by the alternative implementation. + * * Any of these options become available by defining MBEDTLS_ECP_INTERNAL_ALT * and implementing the following functions: * unsigned char mbedtls_internal_ecp_grp_capable( @@ -523,21 +502,28 @@ * called before and after each point operation and provide an opportunity to * implement optimized set up and tear down instructions. * - * Example: In case you uncomment MBEDTLS_ECP_INTERNAL_ALT and - * MBEDTLS_ECP_DOUBLE_JAC_ALT, mbed TLS will still provide the ecp_double_jac - * function, but will use your mbedtls_internal_ecp_double_jac if the group is - * supported (your mbedtls_internal_ecp_grp_capable function returns 1 when - * receives it as an argument). If the group is not supported then the original - * implementation is used. The other functions and the definition of - * mbedtls_ecp_group and mbedtls_ecp_point will not change, so your - * implementation of mbedtls_internal_ecp_double_jac and - * mbedtls_internal_ecp_grp_capable must be compatible with this definition. + * Example: In case you set MBEDTLS_ECP_INTERNAL_ALT and + * MBEDTLS_ECP_DOUBLE_JAC_ALT, mbed TLS will still provide the ecp_double_jac() + * function, but will use your mbedtls_internal_ecp_double_jac() if the group + * for the operation is supported by your implementation (i.e. your + * mbedtls_internal_ecp_grp_capable() function returns 1 for this group). If the + * group is not supported by your implementation, then the original mbed TLS + * implementation of ecp_double_jac() is used instead, unless this fallback + * behaviour is disabled by setting MBEDTLS_ECP_NO_FALLBACK (in which case + * ecp_double_jac() will return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE). + * + * The function prototypes and the definition of mbedtls_ecp_group and + * mbedtls_ecp_point will not change based on MBEDTLS_ECP_INTERNAL_ALT, so your + * implementation of mbedtls_internal_ecp__function_name__ must be compatible + * with their definitions. * * Uncomment a macro to enable alternate implementation of the corresponding * function. */ /* Required for all the functions in this section */ //#define MBEDTLS_ECP_INTERNAL_ALT +/* Turn off software fallback for curves not supported in hardware */ +//#define MBEDTLS_ECP_NO_FALLBACK /* Support for Weierstrass curves with Jacobi representation */ //#define MBEDTLS_ECP_RANDOMIZE_JAC_ALT //#define MBEDTLS_ECP_ADD_MIXED_ALT @@ -549,42 +535,6 @@ //#define MBEDTLS_ECP_RANDOMIZE_MXZ_ALT //#define MBEDTLS_ECP_NORMALIZE_MXZ_ALT -/** - * \def MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - * - * Enable testing of the constant-flow nature of some sensitive functions with - * clang's MemorySanitizer. This causes some existing tests to also test - * this non-functional property of the code under test. - * - * This setting requires compiling with clang -fsanitize=memory. The test - * suites can then be run normally. - * - * \warning This macro is only used for extended testing; it is not considered - * part of the library's API, so it may change or disappear at any time. - * - * Uncomment to enable testing of the constant-flow nature of selected code. - */ -//#define MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - -/** - * \def MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - * - * Enable testing of the constant-flow nature of some sensitive functions with - * valgrind's memcheck tool. This causes some existing tests to also test - * this non-functional property of the code under test. - * - * This setting requires valgrind headers for building, and is only useful for - * testing if the tests suites are run with valgrind's memcheck. This can be - * done for an individual test suite with 'valgrind ./test_suite_xxx', or when - * using CMake, this can be done for all test suites with 'make memcheck'. - * - * \warning This macro is only used for extended testing; it is not considered - * part of the library's API, so it may change or disappear at any time. - * - * Uncomment to enable testing of the constant-flow nature of selected code. - */ -//#define MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - /** * \def MBEDTLS_TEST_NULL_ENTROPY * @@ -666,6 +616,29 @@ */ //#define MBEDTLS_CAMELLIA_SMALL_MEMORY +/** + * \def MBEDTLS_CHECK_RETURN_WARNING + * + * If this macro is defined, emit a compile-time warning if application code + * calls a function without checking its return value, but the return value + * should generally be checked in portable applications. + * + * This is only supported on platforms where #MBEDTLS_CHECK_RETURN is + * implemented. Otherwise this option has no effect. + * + * Uncomment to get warnings on using fallible functions without checking + * their return value. + * + * \note This feature is a work in progress. + * Warnings will be added to more functions in the future. + * + * \note A few functions are considered critical, and ignoring the return + * value of these functions will trigger a warning even if this + * macro is not defined. To completely disable return value check + * warnings, define #MBEDTLS_CHECK_RETURN with an empty expansion. + */ +//#define MBEDTLS_CHECK_RETURN_WARNING + /** * \def MBEDTLS_CIPHER_MODE_CBC * @@ -816,6 +789,7 @@ * * Comment macros to disable the curve and functions for it */ +/* Short Weierstrass curves (supporting ECP, ECDH, ECDSA) */ #define MBEDTLS_ECP_DP_SECP192R1_ENABLED #define MBEDTLS_ECP_DP_SECP224R1_ENABLED #define MBEDTLS_ECP_DP_SECP256R1_ENABLED @@ -827,6 +801,7 @@ #define MBEDTLS_ECP_DP_BP256R1_ENABLED #define MBEDTLS_ECP_DP_BP384R1_ENABLED #define MBEDTLS_ECP_DP_BP512R1_ENABLED +/* Montgomery curves (supporting ECP) */ #define MBEDTLS_ECP_DP_CURVE25519_ENABLED #define MBEDTLS_ECP_DP_CURVE448_ENABLED @@ -849,11 +824,11 @@ * against some side-channel attacks. * * This protection introduces a dependency of the ECP module on one of the - * DRBG or SHA modules (HMAC-DRBG, CTR-DRBG, SHA-512 or SHA-256.) For very - * constrained applications that don't require this protection (for example, - * because you're only doing signature verification, so not manipulating any - * secret, or because local/physical side-channel attacks are outside your - * threat model), it might be desirable to get rid of that dependency. + * DRBG modules. For very constrained implementations that don't require this + * protection (for example, because you're only doing signature verification, + * so not manipulating any secret, or because local/physical side-channel + * attacks are outside your threat model), it might be desirable to get rid of + * that dependency. * * \warning Enabling this option makes some uses of ECP vulnerable to some * side-channel attacks. Only enable it if you know that's not a problem for @@ -883,10 +858,39 @@ * * \note This option only works with the default software implementation of * elliptic curve functionality. It is incompatible with - * MBEDTLS_ECP_ALT, MBEDTLS_ECDH_XXX_ALT and MBEDTLS_ECDSA_XXX_ALT. + * MBEDTLS_ECP_ALT, MBEDTLS_ECDH_XXX_ALT, MBEDTLS_ECDSA_XXX_ALT + * and MBEDTLS_ECDH_LEGACY_CONTEXT. */ //#define MBEDTLS_ECP_RESTARTABLE +/** + * \def MBEDTLS_ECDH_LEGACY_CONTEXT + * + * Use a backward compatible ECDH context. + * + * Mbed TLS supports two formats for ECDH contexts (#mbedtls_ecdh_context + * defined in `ecdh.h`). For most applications, the choice of format makes + * no difference, since all library functions can work with either format, + * except that the new format is incompatible with MBEDTLS_ECP_RESTARTABLE. + + * The new format used when this option is disabled is smaller + * (56 bytes on a 32-bit platform). In future versions of the library, it + * will support alternative implementations of ECDH operations. + * The new format is incompatible with applications that access + * context fields directly and with restartable ECP operations. + * + * Define this macro if you enable MBEDTLS_ECP_RESTARTABLE or if you + * want to access ECDH context fields directly. Otherwise you should + * comment out this macro definition. + * + * This option has no effect if #MBEDTLS_ECDH_C is not enabled. + * + * \note This configuration option is experimental. Future versions of the + * library may modify the way the ECDH context layout is configured + * and may modify the layout of the new context type. + */ +#define MBEDTLS_ECDH_LEGACY_CONTEXT + /** * \def MBEDTLS_ECDSA_DETERMINISTIC * @@ -895,7 +899,7 @@ * may result in a compromise of the long-term signing key. This is avoided by * the deterministic variant. * - * Requires: MBEDTLS_HMAC_DRBG_C + * Requires: MBEDTLS_HMAC_DRBG_C, MBEDTLS_ECDSA_C * * Comment this macro to disable deterministic ECDSA. */ @@ -1114,7 +1118,7 @@ * * Enable the ECDH-ECDSA based ciphersuite modes in SSL / TLS. * - * Requires: MBEDTLS_ECDH_C, MBEDTLS_X509_CRT_PARSE_C + * Requires: MBEDTLS_ECDH_C, MBEDTLS_ECDSA_C, MBEDTLS_X509_CRT_PARSE_C * * This enables the following ciphersuites (if other requisites are * enabled as well): @@ -1138,7 +1142,7 @@ * * Enable the ECDH-RSA based ciphersuite modes in SSL / TLS. * - * Requires: MBEDTLS_ECDH_C, MBEDTLS_X509_CRT_PARSE_C + * Requires: MBEDTLS_ECDH_C, MBEDTLS_RSA_C, MBEDTLS_X509_CRT_PARSE_C * * This enables the following ciphersuites (if other requisites are * enabled as well): @@ -1289,6 +1293,18 @@ */ //#define MBEDTLS_ENTROPY_NV_SEED +/* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER + * + * Enable key identifiers that encode a key owner identifier. + * + * The owner of a key is identified by a value of type ::mbedtls_key_owner_id_t + * which is currently hard-coded to be int32_t. + * + * Note that this option is meant for internal use only and may be removed + * without notice. It is incompatible with MBEDTLS_USE_PSA_CRYPTO. + */ +//#define MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER + /** * \def MBEDTLS_MEMORY_DEBUG * @@ -1345,6 +1361,114 @@ */ #define MBEDTLS_PKCS1_V21 +/** \def MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS + * + * Enable support for platform built-in keys. If you enable this feature, + * you must implement the function mbedtls_psa_platform_get_builtin_key(). + * See the documentation of that function for more information. + * + * Built-in keys are typically derived from a hardware unique key or + * stored in a secure element. + * + * Requires: MBEDTLS_PSA_CRYPTO_C. + * + * \warning This interface is experimental and may change or be removed + * without notice. + */ +//#define MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS + +/** \def MBEDTLS_PSA_CRYPTO_CLIENT + * + * Enable support for PSA crypto client. + * + * \note This option allows to include the code necessary for a PSA + * crypto client when the PSA crypto implementation is not included in + * the library (MBEDTLS_PSA_CRYPTO_C disabled). The code included is the + * code to set and get PSA key attributes. + * The development of PSA drivers partially relying on the library to + * fulfill the hardware gaps is another possible usage of this option. + * + * \warning This interface is experimental and may change or be removed + * without notice. + */ +//#define MBEDTLS_PSA_CRYPTO_CLIENT + +/** \def MBEDTLS_PSA_CRYPTO_DRIVERS + * + * Enable support for the experimental PSA crypto driver interface. + * + * Requires: MBEDTLS_PSA_CRYPTO_C + * + * \warning This interface is experimental and may change or be removed + * without notice. + */ +//#define MBEDTLS_PSA_CRYPTO_DRIVERS + +/** \def MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG + * + * Make the PSA Crypto module use an external random generator provided + * by a driver, instead of Mbed TLS's entropy and DRBG modules. + * + * \note This random generator must deliver random numbers with cryptographic + * quality and high performance. It must supply unpredictable numbers + * with a uniform distribution. The implementation of this function + * is responsible for ensuring that the random generator is seeded + * with sufficient entropy. If you have a hardware TRNG which is slow + * or delivers non-uniform output, declare it as an entropy source + * with mbedtls_entropy_add_source() instead of enabling this option. + * + * If you enable this option, you must configure the type + * ::mbedtls_psa_external_random_context_t in psa/crypto_platform.h + * and define a function called mbedtls_psa_external_get_random() + * with the following prototype: + * ``` + * psa_status_t mbedtls_psa_external_get_random( + * mbedtls_psa_external_random_context_t *context, + * uint8_t *output, size_t output_size, size_t *output_length); + * ); + * ``` + * The \c context value is initialized to 0 before the first call. + * The function must fill the \c output buffer with \p output_size bytes + * of random data and set \c *output_length to \p output_size. + * + * Requires: MBEDTLS_PSA_CRYPTO_C + * + * \warning If you enable this option, code that uses the PSA cryptography + * interface will not use any of the entropy sources set up for + * the entropy module, nor the NV seed that MBEDTLS_ENTROPY_NV_SEED + * enables. + * + * \note This option is experimental and may be removed without notice. + */ +//#define MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG + +/** + * \def MBEDTLS_PSA_CRYPTO_SPM + * + * When MBEDTLS_PSA_CRYPTO_SPM is defined, the code is built for SPM (Secure + * Partition Manager) integration which separates the code into two parts: a + * NSPE (Non-Secure Process Environment) and an SPE (Secure Process + * Environment). + * + * Module: library/psa_crypto.c + * Requires: MBEDTLS_PSA_CRYPTO_C + * + */ +//#define MBEDTLS_PSA_CRYPTO_SPM + +/** + * \def MBEDTLS_PSA_INJECT_ENTROPY + * + * Enable support for entropy injection at first boot. This feature is + * required on systems that do not have a built-in entropy source (TRNG). + * This feature is currently not supported on systems that have a built-in + * entropy source. + * + * Requires: MBEDTLS_PSA_CRYPTO_STORAGE_C, MBEDTLS_ENTROPY_NV_SEED + * + */ +//#define MBEDTLS_PSA_INJECT_ENTROPY + /** * \def MBEDTLS_RSA_NO_CRT * @@ -1379,6 +1503,28 @@ */ //#define MBEDTLS_SHA256_SMALLER +/** + * \def MBEDTLS_SHA512_SMALLER + * + * Enable an implementation of SHA-512 that has lower ROM footprint but also + * lower performance. + * + * Uncomment to enable the smaller implementation of SHA512. + */ +//#define MBEDTLS_SHA512_SMALLER + +/** + * \def MBEDTLS_SHA512_NO_SHA384 + * + * Disable the SHA-384 option of the SHA-512 module. Use this to save some + * code size on devices that don't use SHA-384. + * + * Requires: MBEDTLS_SHA512_C + * + * Uncomment to disable SHA-384 + */ +//#define MBEDTLS_SHA512_NO_SHA384 + /** * \def MBEDTLS_SSL_ALL_ALERT_MESSAGES * @@ -1393,6 +1539,48 @@ */ #define MBEDTLS_SSL_ALL_ALERT_MESSAGES +/** + * \def MBEDTLS_SSL_RECORD_CHECKING + * + * Enable the function mbedtls_ssl_check_record() which can be used to check + * the validity and authenticity of an incoming record, to verify that it has + * not been seen before. These checks are performed without modifying the + * externally visible state of the SSL context. + * + * See mbedtls_ssl_check_record() for more information. + * + * Uncomment to enable support for record checking. + */ +#define MBEDTLS_SSL_RECORD_CHECKING + +/** + * \def MBEDTLS_SSL_DTLS_CONNECTION_ID + * + * Enable support for the DTLS Connection ID extension + * (version draft-ietf-tls-dtls-connection-id-05, + * https://tools.ietf.org/html/draft-ietf-tls-dtls-connection-id-05) + * which allows to identify DTLS connections across changes + * in the underlying transport. + * + * Setting this option enables the SSL APIs `mbedtls_ssl_set_cid()`, + * `mbedtls_ssl_get_peer_cid()` and `mbedtls_ssl_conf_cid()`. + * See the corresponding documentation for more information. + * + * \warning The Connection ID extension is still in draft state. + * We make no stability promises for the availability + * or the shape of the API controlled by this option. + * + * The maximum lengths of outgoing and incoming CIDs can be configured + * through the options + * - MBEDTLS_SSL_CID_OUT_LEN_MAX + * - MBEDTLS_SSL_CID_IN_LEN_MAX. + * + * Requires: MBEDTLS_SSL_PROTO_DTLS + * + * Uncomment to enable the Connection ID extension. + */ +//#define MBEDTLS_SSL_DTLS_CONNECTION_ID + /** * \def MBEDTLS_SSL_ASYNC_PRIVATE * @@ -1404,6 +1592,33 @@ */ //#define MBEDTLS_SSL_ASYNC_PRIVATE +/** + * \def MBEDTLS_SSL_CONTEXT_SERIALIZATION + * + * Enable serialization of the TLS context structures, through use of the + * functions mbedtls_ssl_context_save() and mbedtls_ssl_context_load(). + * + * This pair of functions allows one side of a connection to serialize the + * context associated with the connection, then free or re-use that context + * while the serialized state is persisted elsewhere, and finally deserialize + * that state to a live context for resuming read/write operations on the + * connection. From a protocol perspective, the state of the connection is + * unaffected, in particular this is entirely transparent to the peer. + * + * Note: this is distinct from TLS session resumption, which is part of the + * protocol and fully visible by the peer. TLS session resumption enables + * establishing new connections associated to a saved session with shorter, + * lighter handshakes, while context serialization is a local optimization in + * handling a single, potentially long-lived connection. + * + * Enabling these APIs makes some SSL structures larger, as 64 extra bytes are + * saved after the handshake to allow for more efficient serialization, so if + * you don't need this feature you'll save RAM by disabling it. + * + * Comment to disable the context serialization APIs. + */ +#define MBEDTLS_SSL_CONTEXT_SERIALIZATION + /** * \def MBEDTLS_SSL_DEBUG_ALL * @@ -1440,8 +1655,8 @@ /** \def MBEDTLS_SSL_EXTENDED_MASTER_SECRET * - * Enable support for Extended Master Secret, aka Session Hash - * (draft-ietf-tls-session-hash-02). + * Enable support for RFC 7627: Session Hash and Extended Master Secret + * Extension. * * This was introduced as "the proper fix" to the Triple Handshake familiy of * attacks, but it is recommended to always use it (even if you disable @@ -1459,7 +1674,8 @@ /** * \def MBEDTLS_SSL_FALLBACK_SCSV * - * Enable support for FALLBACK_SCSV (draft-ietf-tls-downgrade-scsv-00). + * Enable support for RFC 7507: Fallback Signaling Cipher Suite Value (SCSV) + * for Preventing Protocol Downgrade Attacks. * * For servers, it is recommended to always enable this, unless you support * only one version of TLS, or know for sure that none of your clients @@ -1473,12 +1689,37 @@ */ #define MBEDTLS_SSL_FALLBACK_SCSV +/** + * \def MBEDTLS_SSL_KEEP_PEER_CERTIFICATE + * + * This option controls the availability of the API mbedtls_ssl_get_peer_cert() + * giving access to the peer's certificate after completion of the handshake. + * + * Unless you need mbedtls_ssl_peer_cert() in your application, it is + * recommended to disable this option for reduced RAM usage. + * + * \note If this option is disabled, mbedtls_ssl_get_peer_cert() is still + * defined, but always returns \c NULL. + * + * \note This option has no influence on the protection against the + * triple handshake attack. Even if it is disabled, Mbed TLS will + * still ensure that certificates do not change during renegotiation, + * for exaple by keeping a hash of the peer's certificate. + * + * Comment this macro to disable storing the peer's certificate + * after the handshake. + */ +#define MBEDTLS_SSL_KEEP_PEER_CERTIFICATE + /** * \def MBEDTLS_SSL_HW_RECORD_ACCEL * * Enable hooking functions in SSL module for hardware acceleration of * individual records. * + * \deprecated This option is deprecated and will be removed in a future + * version of Mbed TLS. + * * Uncomment this macro to enable hooking functions. */ //#define MBEDTLS_SSL_HW_RECORD_ACCEL @@ -1523,6 +1764,9 @@ * Enable support for receiving and parsing SSLv2 Client Hello messages for the * SSL Server module (MBEDTLS_SSL_SRV_C). * + * \deprecated This option is deprecated and will be removed in a future + * version of Mbed TLS. + * * Uncomment this macro to enable support for SSLv2 Client Hello messages. */ //#define MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO @@ -1554,6 +1798,9 @@ * Requires: MBEDTLS_MD5_C * MBEDTLS_SHA1_C * + * \deprecated This option is deprecated and will be removed in a future + * version of Mbed TLS. + * * Comment this macro to disable support for SSL 3.0 */ //#define MBEDTLS_SSL_PROTO_SSL3 @@ -1594,6 +1841,25 @@ */ #define MBEDTLS_SSL_PROTO_TLS1_2 +/** + * \def MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL + * + * This macro is used to selectively enable experimental parts + * of the code that contribute to the ongoing development of + * the prototype TLS 1.3 and DTLS 1.3 implementation, and provide + * no other purpose. + * + * \warning TLS 1.3 and DTLS 1.3 aren't yet supported in Mbed TLS, + * and no feature exposed through this macro is part of the + * public API. In particular, features under the control + * of this macro are experimental and don't come with any + * stability guarantees. + * + * Uncomment this macro to enable experimental and partial + * functionality specific to TLS 1.3. + */ +//#define MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL + /** * \def MBEDTLS_SSL_PROTO_DTLS * @@ -1651,6 +1917,37 @@ */ #define MBEDTLS_SSL_DTLS_HELLO_VERIFY +/** + * \def MBEDTLS_SSL_DTLS_SRTP + * + * Enable support for negotiation of DTLS-SRTP (RFC 5764) + * through the use_srtp extension. + * + * \note This feature provides the minimum functionality required + * to negotiate the use of DTLS-SRTP and to allow the derivation of + * the associated SRTP packet protection key material. + * In particular, the SRTP packet protection itself, as well as the + * demultiplexing of RTP and DTLS packets at the datagram layer + * (see Section 5 of RFC 5764), are not handled by this feature. + * Instead, after successful completion of a handshake negotiating + * the use of DTLS-SRTP, the extended key exporter API + * mbedtls_ssl_conf_export_keys_ext_cb() should be used to implement + * the key exporter described in Section 4.2 of RFC 5764 and RFC 5705 + * (this is implemented in the SSL example programs). + * The resulting key should then be passed to an SRTP stack. + * + * Setting this option enables the runtime API + * mbedtls_ssl_conf_dtls_srtp_protection_profiles() + * through which the supported DTLS-SRTP protection + * profiles can be configured. You must call this API at + * runtime if you wish to negotiate the use of DTLS-SRTP. + * + * Requires: MBEDTLS_SSL_PROTO_DTLS + * + * Uncomment this to enable support for use_srtp extension. + */ +//#define MBEDTLS_SSL_DTLS_SRTP + /** * \def MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE * @@ -1727,8 +2024,8 @@ * * Fallback to old (pre-2.7), non-conforming implementation of the truncated * HMAC extension which also truncates the HMAC key. Note that this option is - * only meant for a transitory upgrade period and is likely to be removed in - * a future version of the library. + * only meant for a transitory upgrade period and will be removed in a future + * version of the library. * * \warning The old implementation is non-compliant and has a security weakness * (2^80 brute force attack on the HMAC key used for a single, @@ -1737,7 +2034,7 @@ * bandwidth, and (2) the peer is an Mbed TLS stack that doesn't use * the fixed implementation yet (pre-2.7). * - * \deprecated This option is deprecated and will likely be removed in a + * \deprecated This option is deprecated and will be removed in a * future version of Mbed TLS. * * Uncomment to fallback to old, non-compliant truncated HMAC implementation. @@ -1746,6 +2043,52 @@ */ //#define MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT +/** + * \def MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH + * + * When this option is enabled, the SSL buffer will be resized automatically + * based on the negotiated maximum fragment length in each direction. + * + * Requires: MBEDTLS_SSL_MAX_FRAGMENT_LENGTH + */ +//#define MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH + +/** + * \def MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN + * + * Enable testing of the constant-flow nature of some sensitive functions with + * clang's MemorySanitizer. This causes some existing tests to also test + * this non-functional property of the code under test. + * + * This setting requires compiling with clang -fsanitize=memory. The test + * suites can then be run normally. + * + * \warning This macro is only used for extended testing; it is not considered + * part of the library's API, so it may change or disappear at any time. + * + * Uncomment to enable testing of the constant-flow nature of selected code. + */ +//#define MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN + +/** + * \def MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND + * + * Enable testing of the constant-flow nature of some sensitive functions with + * valgrind's memcheck tool. This causes some existing tests to also test + * this non-functional property of the code under test. + * + * This setting requires valgrind headers for building, and is only useful for + * testing if the tests suites are run with valgrind's memcheck. This can be + * done for an individual test suite with 'valgrind ./test_suite_xxx', or when + * using CMake, this can be done for all test suites with 'make memcheck'. + * + * \warning This macro is only used for extended testing; it is not considered + * part of the library's API, so it may change or disappear at any time. + * + * Uncomment to enable testing of the constant-flow nature of selected code. + */ +//#define MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND + /** * \def MBEDTLS_TEST_HOOKS * @@ -1759,6 +2102,9 @@ * risk of vulnerabilities, and more gadgets that can make exploits easier. * Therefore this feature must never be enabled in production. * + * See `docs/architecture/testing/mbed-crypto-invasive-testing.md` for more + * information. + * * Uncomment to enable invasive tests. */ //#define MBEDTLS_TEST_HOOKS @@ -1785,6 +2131,49 @@ */ //#define MBEDTLS_THREADING_PTHREAD +/** + * \def MBEDTLS_USE_PSA_CRYPTO + * + * Make the X.509 and TLS library use PSA for cryptographic operations, and + * enable new APIs for using keys handled by PSA Crypto. + * + * \note Development of this option is currently in progress, and parts of Mbed + * TLS's X.509 and TLS modules are not ported to PSA yet. However, these parts + * will still continue to work as usual, so enabling this option should not + * break backwards compatibility. + * + * \note See docs/use-psa-crypto.md for a complete description of what this + * option currently does, and of parts that are not affected by it so far. + * + * \warning This option enables new Mbed TLS APIs which are currently + * considered experimental and may change in incompatible ways at any time. + * That is, the APIs enabled by this option are not covered by the usual + * promises of API stability. + * + * Requires: MBEDTLS_PSA_CRYPTO_C. + * + * Uncomment this to enable internal use of PSA Crypto and new associated APIs. + */ +//#define MBEDTLS_USE_PSA_CRYPTO + +/** + * \def MBEDTLS_PSA_CRYPTO_CONFIG + * + * This setting allows support for cryptographic mechanisms through the PSA + * API to be configured separately from support through the mbedtls API. + * + * Uncomment this to enable use of PSA Crypto configuration settings which + * can be found in include/psa/crypto_config.h. + * + * If you enable this option and write your own configuration file, you must + * include mbedtls/config_psa.h in your configuration file. The default + * provided mbedtls/config.h contains the necessary inclusion. + * + * This feature is still experimental and is not ready for production since + * it is not completed. + */ +//#define MBEDTLS_PSA_CRYPTO_CONFIG + /** * \def MBEDTLS_VERSION_FEATURES * @@ -1820,6 +2209,25 @@ */ //#define MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION +/** + * \def MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK + * + * If set, this enables the X.509 API `mbedtls_x509_crt_verify_with_ca_cb()` + * and the SSL API `mbedtls_ssl_conf_ca_cb()` which allow users to configure + * the set of trusted certificates through a callback instead of a linked + * list. + * + * This is useful for example in environments where a large number of trusted + * certificates is present and storing them in a linked list isn't efficient + * enough, or when the set of trusted certificates changes frequently. + * + * See the documentation of `mbedtls_x509_crt_verify_with_ca_cb()` and + * `mbedtls_ssl_conf_ca_cb()` for more information. + * + * Uncomment to enable trusted certificate callbacks. + */ +//#define MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK + /** * \def MBEDTLS_X509_CHECK_KEY_USAGE * @@ -2244,6 +2652,11 @@ * Enable the CMAC (Cipher-based Message Authentication Code) mode for block * ciphers. * + * \note When #MBEDTLS_CMAC_ALT is active, meaning that the underlying + * implementation of the CMAC algorithm is provided by an alternate + * implementation, that alternate implementation may opt to not support + * AES-192 or 3DES as underlying block ciphers for the CMAC operation. + * * Module: library/cmac.c * * Requires: MBEDTLS_AES_C or MBEDTLS_DES_C @@ -2362,7 +2775,9 @@ * This module is used by the following key exchanges: * ECDHE-ECDSA * - * Requires: MBEDTLS_ECP_C, MBEDTLS_ASN1_WRITE_C, MBEDTLS_ASN1_PARSE_C + * Requires: MBEDTLS_ECP_C, MBEDTLS_ASN1_WRITE_C, MBEDTLS_ASN1_PARSE_C, + * and at least one MBEDTLS_ECP_DP_XXX_ENABLED for a + * short Weierstrass curve. */ #define MBEDTLS_ECDSA_C @@ -2428,11 +2843,11 @@ /** * \def MBEDTLS_GCM_C * - * Enable the Galois/Counter Mode (GCM) for AES. + * Enable the Galois/Counter Mode (GCM). * * Module: library/gcm.c * - * Requires: MBEDTLS_AES_C or MBEDTLS_CAMELLIA_C + * Requires: MBEDTLS_AES_C or MBEDTLS_CAMELLIA_C or MBEDTLS_ARIA_C * * This module enables the AES-GCM and CAMELLIA-GCM ciphersuites, if other * requisites are enabled as well. @@ -2739,7 +3154,10 @@ /** * \def MBEDTLS_PKCS11_C * - * Enable wrapper for PKCS#11 smartcard support. + * Enable wrapper for PKCS#11 smartcard support via the pkcs11-helper library. + * + * \deprecated This option is deprecated and will be removed in a future + * version of Mbed TLS. * * Module: library/pkcs11.c * Caller: library/pk.c @@ -2797,6 +3215,61 @@ */ #define MBEDTLS_POLY1305_C +/** + * \def MBEDTLS_PSA_CRYPTO_C + * + * Enable the Platform Security Architecture cryptography API. + * + * Module: library/psa_crypto.c + * + * Requires: either MBEDTLS_CTR_DRBG_C and MBEDTLS_ENTROPY_C, + * or MBEDTLS_HMAC_DRBG_C and MBEDTLS_ENTROPY_C, + * or MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG. + * + */ +#define MBEDTLS_PSA_CRYPTO_C + +/** + * \def MBEDTLS_PSA_CRYPTO_SE_C + * + * Enable secure element support in the Platform Security Architecture + * cryptography API. + * + * \warning This feature is not yet suitable for production. It is provided + * for API evaluation and testing purposes only. + * + * Module: library/psa_crypto_se.c + * + * Requires: MBEDTLS_PSA_CRYPTO_C, MBEDTLS_PSA_CRYPTO_STORAGE_C + * + */ +//#define MBEDTLS_PSA_CRYPTO_SE_C + +/** + * \def MBEDTLS_PSA_CRYPTO_STORAGE_C + * + * Enable the Platform Security Architecture persistent key storage. + * + * Module: library/psa_crypto_storage.c + * + * Requires: MBEDTLS_PSA_CRYPTO_C, + * either MBEDTLS_PSA_ITS_FILE_C or a native implementation of + * the PSA ITS interface + */ +#define MBEDTLS_PSA_CRYPTO_STORAGE_C + +/** + * \def MBEDTLS_PSA_ITS_FILE_C + * + * Enable the emulation of the Platform Security Architecture + * Internal Trusted Storage (PSA ITS) over files. + * + * Module: library/psa_its_file.c + * + * Requires: MBEDTLS_FS_IO + */ +#define MBEDTLS_PSA_ITS_FILE_C + /** * \def MBEDTLS_RIPEMD160_C * @@ -3160,8 +3633,8 @@ //#define MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT 384 /**< Maximum size of (re)seed buffer */ /* ECP options */ -//#define MBEDTLS_ECP_MAX_BITS 521 /**< Maximum bit size of groups */ -//#define MBEDTLS_ECP_WINDOW_SIZE 6 /**< Maximum window size used */ +//#define MBEDTLS_ECP_MAX_BITS 521 /**< Maximum bit size of groups. Normally determined automatically from the configured curves. */ +//#define MBEDTLS_ECP_WINDOW_SIZE 4 /**< Maximum window size used */ //#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 /**< Enable fixed-point speed-up */ /* Entropy options */ @@ -3199,6 +3672,7 @@ //#define MBEDTLS_PLATFORM_PRINTF_MACRO printf /**< Default printf macro to use, can be undefined */ /* Note: your snprintf must correctly zero-terminate the buffer! */ //#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf /**< Default snprintf macro to use, can be undefined */ +//#define MBEDTLS_PLATFORM_VSNPRINTF_MACRO vsnprintf /**< Default vsnprintf macro to use, can be undefined */ //#define MBEDTLS_PLATFORM_NV_SEED_READ_MACRO mbedtls_platform_std_nv_seed_read /**< Default nv_seed_read function to use, can be undefined */ //#define MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO mbedtls_platform_std_nv_seed_write /**< Default nv_seed_write function to use, can be undefined */ @@ -3238,6 +3712,53 @@ */ //#define MBEDTLS_PARAM_FAILED( cond ) assert( cond ) +/** \def MBEDTLS_CHECK_RETURN + * + * This macro is used at the beginning of the declaration of a function + * to indicate that its return value should be checked. It should + * instruct the compiler to emit a warning or an error if the function + * is called without checking its return value. + * + * There is a default implementation for popular compilers in platform_util.h. + * You can override the default implementation by defining your own here. + * + * If the implementation here is empty, this will effectively disable the + * checking of functions' return values. + */ +//#define MBEDTLS_CHECK_RETURN __attribute__((__warn_unused_result__)) + +/** \def MBEDTLS_IGNORE_RETURN + * + * This macro requires one argument, which should be a C function call. + * If that function call would cause a #MBEDTLS_CHECK_RETURN warning, this + * warning is suppressed. + */ +//#define MBEDTLS_IGNORE_RETURN( result ) ((void) !(result)) + +/* PSA options */ +/** + * Use HMAC_DRBG with the specified hash algorithm for HMAC_DRBG for the + * PSA crypto subsystem. + * + * If this option is unset: + * - If CTR_DRBG is available, the PSA subsystem uses it rather than HMAC_DRBG. + * - Otherwise, the PSA subsystem uses HMAC_DRBG with either + * #MBEDTLS_MD_SHA512 or #MBEDTLS_MD_SHA256 based on availability and + * on unspecified heuristics. + */ +//#define MBEDTLS_PSA_HMAC_DRBG_MD_TYPE MBEDTLS_MD_SHA256 + +/** \def MBEDTLS_PSA_KEY_SLOT_COUNT + * Restrict the PSA library to supporting a maximum amount of simultaneously + * loaded keys. A loaded key is a key stored by the PSA Crypto core as a + * volatile key, or a persistent key which is loaded temporarily by the + * library as part of a crypto operation in flight. + * + * If this option is unset, the library will fall back to a default value of + * 32 keys. + */ +//#define MBEDTLS_PSA_KEY_SLOT_COUNT 32 + /* SSL Cache options */ //#define MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT 86400 /**< 1 day */ //#define MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES 50 /**< Maximum entries in cache */ @@ -3295,6 +3816,53 @@ */ //#define MBEDTLS_SSL_IN_CONTENT_LEN 16384 +/** \def MBEDTLS_SSL_CID_IN_LEN_MAX + * + * The maximum length of CIDs used for incoming DTLS messages. + * + */ +//#define MBEDTLS_SSL_CID_IN_LEN_MAX 32 + +/** \def MBEDTLS_SSL_CID_OUT_LEN_MAX + * + * The maximum length of CIDs used for outgoing DTLS messages. + * + */ +//#define MBEDTLS_SSL_CID_OUT_LEN_MAX 32 + +/** \def MBEDTLS_SSL_CID_PADDING_GRANULARITY + * + * This option controls the use of record plaintext padding + * when using the Connection ID extension in DTLS 1.2. + * + * The padding will always be chosen so that the length of the + * padded plaintext is a multiple of the value of this option. + * + * Note: A value of \c 1 means that no padding will be used + * for outgoing records. + * + * Note: On systems lacking division instructions, + * a power of two should be preferred. + * + */ +//#define MBEDTLS_SSL_CID_PADDING_GRANULARITY 16 + +/** \def MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY + * + * This option controls the use of record plaintext padding + * in TLS 1.3. + * + * The padding will always be chosen so that the length of the + * padded plaintext is a multiple of the value of this option. + * + * Note: A value of \c 1 means that no padding will be used + * for outgoing records. + * + * Note: On systems lacking division instructions, + * a power of two should be preferred. + */ +//#define MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY 1 + /** \def MBEDTLS_SSL_OUT_CONTENT_LEN * * Maximum length (in bytes) of outgoing plaintext fragments. @@ -3324,7 +3892,7 @@ * Maximum number of heap-allocated bytes for the purpose of * DTLS handshake message reassembly and future message buffering. * - * This should be at least 9/8 * MBEDTLSSL_IN_CONTENT_LEN + * This should be at least 9/8 * MBEDTLS_SSL_IN_CONTENT_LEN * to account for a reassembled handshake message of maximum size, * together with its reassembly bitmap. * @@ -3340,6 +3908,17 @@ //#define MBEDTLS_PSK_MAX_LEN 32 /**< Max size of TLS pre-shared keys, in bytes (default 256 bits) */ //#define MBEDTLS_SSL_COOKIE_TIMEOUT 60 /**< Default expiration delay of DTLS cookies, in seconds if HAVE_TIME, or in number of cookies issued */ +/** \def MBEDTLS_TLS_EXT_CID + * + * At the time of writing, the CID extension has not been assigned its + * final value. Set this configuration option to make Mbed TLS use a + * different value. + * + * A future minor revision of Mbed TLS may change the default value of + * this option to match evolving standards and usage. + */ +//#define MBEDTLS_TLS_EXT_CID 254 + /** * Complete list of ciphersuites to use, in order of preference. * @@ -3358,20 +3937,6 @@ //#define MBEDTLS_X509_MAX_INTERMEDIATE_CA 8 /**< Maximum number of intermediate CAs in a verification chain. */ //#define MBEDTLS_X509_MAX_FILE_PATH_LEN 512 /**< Maximum length of a path/filename string in bytes including the null terminator character ('\0'). */ -/** - * Allow SHA-1 in the default TLS configuration for certificate signing. - * Without this build-time option, SHA-1 support must be activated explicitly - * through mbedtls_ssl_conf_cert_profile. Turning on this option is not - * recommended because of it is possible to generate SHA-1 collisions, however - * this may be safe for legacy infrastructure where additional controls apply. - * - * \warning SHA-1 is considered a weak message digest and its use constitutes - * a security risk. If possible, we recommend avoiding dependencies - * on it, and considering stronger message digests instead. - * - */ -// #define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES - /** * Allow SHA-1 in the default TLS configuration for TLS 1.2 handshake * signature and ciphersuite selection. Without this build-time option, SHA-1 @@ -3387,7 +3952,7 @@ * on it, and considering stronger message digests instead. * */ -#define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE +//#define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE /** * Uncomment the macro to let mbed TLS use your alternate implementation of @@ -3428,6 +3993,15 @@ */ //#define MBEDTLS_PLATFORM_GMTIME_R_ALT +/** + * Enable the verified implementations of ECDH primitives from Project Everest + * (currently only Curve25519). This feature changes the layout of ECDH + * contexts and therefore is a compatibility break for applications that access + * fields of a mbedtls_ecdh_context structure directly. See also + * MBEDTLS_ECDH_LEGACY_CONTEXT in include/mbedtls/ecdh.h. + */ +//#define MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED + /* \} name SECTION: Customisation configuration options */ /* Target and application specific configurations @@ -3439,6 +4013,10 @@ #include MBEDTLS_USER_CONFIG_FILE #endif -#include "check_config.h" +#if defined(MBEDTLS_PSA_CRYPTO_CONFIG) +#include "mbedtls/config_psa.h" +#endif + +#include "mbedtls/check_config.h" #endif /* MBEDTLS_CONFIG_H */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/config_psa.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/config_psa.h new file mode 100644 index 00000000000..189f6c21734 --- /dev/null +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/config_psa.h @@ -0,0 +1,836 @@ +/** + * \file mbedtls/config_psa.h + * \brief PSA crypto configuration options (set of defines) + * + * This set of compile-time options takes settings defined in + * include/mbedtls/config.h and include/psa/crypto_config.h and uses + * those definitions to define symbols used in the library code. + * + * Users and integrators should not edit this file, please edit + * include/mbedtls/config.h for MBETLS_XXX settings or + * include/psa/crypto_config.h for PSA_WANT_XXX settings. + */ +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MBEDTLS_CONFIG_PSA_H +#define MBEDTLS_CONFIG_PSA_H + +#if defined(MBEDTLS_PSA_CRYPTO_CONFIG) +#include "psa/crypto_config.h" +#endif /* defined(MBEDTLS_PSA_CRYPTO_CONFIG) */ + +#ifdef __cplusplus +extern "C" { +#endif + + + +/****************************************************************/ +/* De facto synonyms */ +/****************************************************************/ + +#if defined(PSA_WANT_ALG_ECDSA_ANY) && !defined(PSA_WANT_ALG_ECDSA) +#define PSA_WANT_ALG_ECDSA PSA_WANT_ALG_ECDSA_ANY +#elif !defined(PSA_WANT_ALG_ECDSA_ANY) && defined(PSA_WANT_ALG_ECDSA) +#define PSA_WANT_ALG_ECDSA_ANY PSA_WANT_ALG_ECDSA +#endif + +#if defined(PSA_WANT_ALG_RSA_PKCS1V15_SIGN_RAW) && !defined(PSA_WANT_ALG_RSA_PKCS1V15_SIGN) +#define PSA_WANT_ALG_RSA_PKCS1V15_SIGN PSA_WANT_ALG_RSA_PKCS1V15_SIGN_RAW +#elif !defined(PSA_WANT_ALG_RSA_PKCS1V15_SIGN_RAW) && defined(PSA_WANT_ALG_RSA_PKCS1V15_SIGN) +#define PSA_WANT_ALG_RSA_PKCS1V15_SIGN_RAW PSA_WANT_ALG_RSA_PKCS1V15_SIGN +#endif + +#if defined(PSA_WANT_ALG_RSA_PSS_ANY_SALT) && !defined(PSA_WANT_ALG_RSA_PSS) +#define PSA_WANT_ALG_RSA_PSS PSA_WANT_ALG_RSA_PSS_ANY_SALT +#elif !defined(PSA_WANT_ALG_RSA_PSS_ANY_SALT) && defined(PSA_WANT_ALG_RSA_PSS) +#define PSA_WANT_ALG_RSA_PSS_ANY_SALT PSA_WANT_ALG_RSA_PSS +#endif + + + +/****************************************************************/ +/* Require built-in implementations based on PSA requirements */ +/****************************************************************/ + +#if defined(MBEDTLS_PSA_CRYPTO_CONFIG) + +#if defined(PSA_WANT_ALG_DETERMINISTIC_ECDSA) +#if !defined(MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA) +#define MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA 1 +#define MBEDTLS_ECDSA_DETERMINISTIC +#define MBEDTLS_ECDSA_C +#define MBEDTLS_HMAC_DRBG_C +#define MBEDTLS_MD_C +#endif /* !MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA */ +#endif /* PSA_WANT_ALG_DETERMINISTIC_ECDSA */ + +#if defined(PSA_WANT_ALG_ECDH) +#if !defined(MBEDTLS_PSA_ACCEL_ALG_ECDH) +#define MBEDTLS_PSA_BUILTIN_ALG_ECDH 1 +#define MBEDTLS_ECDH_C +#define MBEDTLS_ECP_C +#define MBEDTLS_BIGNUM_C +#endif /* !MBEDTLS_PSA_ACCEL_ALG_ECDH */ +#endif /* PSA_WANT_ALG_ECDH */ + +#if defined(PSA_WANT_ALG_ECDSA) +#if !defined(MBEDTLS_PSA_ACCEL_ALG_ECDSA) +#define MBEDTLS_PSA_BUILTIN_ALG_ECDSA 1 +#define MBEDTLS_ECDSA_C +#define MBEDTLS_ECP_C +#define MBEDTLS_BIGNUM_C +#define MBEDTLS_ASN1_PARSE_C +#define MBEDTLS_ASN1_WRITE_C +#endif /* !MBEDTLS_PSA_ACCEL_ALG_ECDSA */ +#endif /* PSA_WANT_ALG_ECDSA */ + +#if defined(PSA_WANT_ALG_HKDF) +#if !defined(MBEDTLS_PSA_ACCEL_ALG_HKDF) +#define MBEDTLS_PSA_BUILTIN_ALG_HMAC 1 +#define MBEDTLS_PSA_BUILTIN_ALG_HKDF 1 +#endif /* !MBEDTLS_PSA_ACCEL_ALG_HKDF */ +#endif /* PSA_WANT_ALG_HKDF */ + +#if defined(PSA_WANT_ALG_HMAC) +#if !defined(MBEDTLS_PSA_ACCEL_ALG_HMAC) +#define MBEDTLS_PSA_BUILTIN_ALG_HMAC 1 +#endif /* !MBEDTLS_PSA_ACCEL_ALG_HMAC */ +#endif /* PSA_WANT_ALG_HMAC */ + +#if defined(PSA_WANT_ALG_MD2) && !defined(MBEDTLS_PSA_ACCEL_ALG_MD2) +#define MBEDTLS_PSA_BUILTIN_ALG_MD2 1 +#define MBEDTLS_MD2_C +#endif + +#if defined(PSA_WANT_ALG_MD4) && !defined(MBEDTLS_PSA_ACCEL_ALG_MD4) +#define MBEDTLS_PSA_BUILTIN_ALG_MD4 1 +#define MBEDTLS_MD4_C +#endif + +#if defined(PSA_WANT_ALG_MD5) && !defined(MBEDTLS_PSA_ACCEL_ALG_MD5) +#define MBEDTLS_PSA_BUILTIN_ALG_MD5 1 +#define MBEDTLS_MD5_C +#endif + +#if defined(PSA_WANT_ALG_RIPEMD160) && !defined(MBEDTLS_PSA_ACCEL_ALG_RIPEMD160) +#define MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160 1 +#define MBEDTLS_RIPEMD160_C +#endif + +#if defined(PSA_WANT_ALG_RSA_OAEP) +#if !defined(MBEDTLS_PSA_ACCEL_ALG_RSA_OAEP) +#define MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP 1 +#define MBEDTLS_RSA_C +#define MBEDTLS_BIGNUM_C +#define MBEDTLS_OID_C +#define MBEDTLS_PKCS1_V21 +#define MBEDTLS_MD_C +#endif /* !MBEDTLS_PSA_ACCEL_ALG_RSA_OAEP */ +#endif /* PSA_WANT_ALG_RSA_OAEP */ + +#if defined(PSA_WANT_ALG_RSA_PKCS1V15_CRYPT) +#if !defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT) +#define MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT 1 +#define MBEDTLS_RSA_C +#define MBEDTLS_BIGNUM_C +#define MBEDTLS_OID_C +#define MBEDTLS_PKCS1_V15 +#endif /* !MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT */ +#endif /* PSA_WANT_ALG_RSA_PKCS1V15_CRYPT */ + +#if defined(PSA_WANT_ALG_RSA_PKCS1V15_SIGN) +#if !defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN) +#define MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN 1 +#define MBEDTLS_RSA_C +#define MBEDTLS_BIGNUM_C +#define MBEDTLS_OID_C +#define MBEDTLS_PKCS1_V15 +#define MBEDTLS_MD_C +#endif /* !MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN */ +#endif /* PSA_WANT_ALG_RSA_PKCS1V15_SIGN */ + +#if defined(PSA_WANT_ALG_RSA_PSS) +#if !defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PSS) +#define MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS 1 +#define MBEDTLS_RSA_C +#define MBEDTLS_BIGNUM_C +#define MBEDTLS_OID_C +#define MBEDTLS_PKCS1_V21 +#define MBEDTLS_MD_C +#endif /* !MBEDTLS_PSA_ACCEL_ALG_RSA_PSS */ +#endif /* PSA_WANT_ALG_RSA_PSS */ + +#if defined(PSA_WANT_ALG_SHA_1) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA_1) +#define MBEDTLS_PSA_BUILTIN_ALG_SHA_1 1 +#define MBEDTLS_SHA1_C +#endif + +#if defined(PSA_WANT_ALG_SHA_224) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224) +#define MBEDTLS_PSA_BUILTIN_ALG_SHA_224 1 +#define MBEDTLS_SHA256_C +#endif + +#if defined(PSA_WANT_ALG_SHA_256) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256) +#define MBEDTLS_PSA_BUILTIN_ALG_SHA_256 1 +#define MBEDTLS_SHA256_C +#endif + +#if defined(PSA_WANT_ALG_SHA_384) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384) +#define MBEDTLS_PSA_BUILTIN_ALG_SHA_384 1 +#define MBEDTLS_SHA512_C +#endif + +#if defined(PSA_WANT_ALG_SHA_512) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512) +#define MBEDTLS_PSA_BUILTIN_ALG_SHA_512 1 +#define MBEDTLS_SHA512_C +#endif + +#if defined(PSA_WANT_ALG_TLS12_PRF) +#if !defined(MBEDTLS_PSA_ACCEL_ALG_TLS12_PRF) +#define MBEDTLS_PSA_BUILTIN_ALG_TLS12_PRF 1 +#endif /* !MBEDTLS_PSA_ACCEL_ALG_TLS12_PRF */ +#endif /* PSA_WANT_ALG_TLS12_PRF */ + +#if defined(PSA_WANT_ALG_TLS12_PSK_TO_MS) +#if !defined(MBEDTLS_PSA_ACCEL_ALG_TLS12_PSK_TO_MS) +#define MBEDTLS_PSA_BUILTIN_ALG_TLS12_PSK_TO_MS 1 +#endif /* !MBEDTLS_PSA_ACCEL_ALG_TLS12_PSK_TO_MS */ +#endif /* PSA_WANT_ALG_TLS12_PSK_TO_MS */ + +#if defined(PSA_WANT_KEY_TYPE_ECC_KEY_PAIR) +#if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) +#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR 1 +#define MBEDTLS_ECP_C +#define MBEDTLS_BIGNUM_C +#endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR */ +#endif /* PSA_WANT_KEY_TYPE_ECC_KEY_PAIR */ + +#if defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY) +#if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY) +#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY 1 +#define MBEDTLS_ECP_C +#define MBEDTLS_BIGNUM_C +#endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY */ +#endif /* PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY */ + +#if defined(PSA_WANT_KEY_TYPE_RSA_KEY_PAIR) +#if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR) +#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR 1 +#define MBEDTLS_RSA_C +#define MBEDTLS_BIGNUM_C +#define MBEDTLS_OID_C +#define MBEDTLS_GENPRIME +#define MBEDTLS_PK_PARSE_C +#define MBEDTLS_PK_WRITE_C +#define MBEDTLS_PK_C +#define MBEDTLS_ASN1_PARSE_C +#define MBEDTLS_ASN1_WRITE_C +#endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR */ +#endif /* PSA_WANT_KEY_TYPE_RSA_KEY_PAIR */ + +#if defined(PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY) +#if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY) +#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY 1 +#define MBEDTLS_RSA_C +#define MBEDTLS_BIGNUM_C +#define MBEDTLS_OID_C +#define MBEDTLS_PK_PARSE_C +#define MBEDTLS_PK_WRITE_C +#define MBEDTLS_PK_C +#define MBEDTLS_ASN1_PARSE_C +#define MBEDTLS_ASN1_WRITE_C +#endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY */ +#endif /* PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY */ + +/* If any of the block modes are requested that don't have an + * associated HW assist, define PSA_HAVE_SOFT_BLOCK_MODE for checking + * in the block cipher key types. */ +#if (defined(PSA_WANT_ALG_CTR) && !defined(MBEDTLS_PSA_ACCEL_ALG_CTR)) || \ + (defined(PSA_WANT_ALG_CFB) && !defined(MBEDTLS_PSA_ACCEL_ALG_CFB)) || \ + (defined(PSA_WANT_ALG_OFB) && !defined(MBEDTLS_PSA_ACCEL_ALG_OFB)) || \ + (defined(PSA_WANT_ALG_XTS) && !defined(MBEDTLS_PSA_ACCEL_ALG_XTS)) || \ + defined(PSA_WANT_ALG_ECB_NO_PADDING) || \ + (defined(PSA_WANT_ALG_CBC_NO_PADDING) && \ + !defined(MBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING)) || \ + (defined(PSA_WANT_ALG_CBC_PKCS7) && \ + !defined(MBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7)) || \ + (defined(PSA_WANT_ALG_CMAC) && !defined(MBEDTLS_PSA_ACCEL_ALG_CMAC)) +#define PSA_HAVE_SOFT_BLOCK_MODE 1 +#endif + +#if (defined(PSA_WANT_ALG_GCM) && !defined(MBEDTLS_PSA_ACCEL_ALG_GCM)) || \ + (defined(PSA_WANT_ALG_CCM) && !defined(MBEDTLS_PSA_ACCEL_ALG_CCM)) +#define PSA_HAVE_SOFT_BLOCK_AEAD 1 +#endif + +#if defined(PSA_WANT_KEY_TYPE_AES) +#if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_AES) +#define PSA_HAVE_SOFT_KEY_TYPE_AES 1 +#endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_AES */ +#if defined(PSA_HAVE_SOFT_KEY_TYPE_AES) || \ + defined(PSA_HAVE_SOFT_BLOCK_MODE) || \ + defined(PSA_HAVE_SOFT_BLOCK_AEAD) +#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_AES 1 +#define MBEDTLS_AES_C +#endif /* PSA_HAVE_SOFT_KEY_TYPE_AES || PSA_HAVE_SOFT_BLOCK_MODE */ +#endif /* PSA_WANT_KEY_TYPE_AES */ + +#if defined(PSA_WANT_KEY_TYPE_ARC4) +#if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ARC4) +#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ARC4 1 +#define MBEDTLS_ARC4_C +#endif /*!MBEDTLS_PSA_ACCEL_KEY_TYPE_ARC4 */ +#endif /* PSA_WANT_KEY_TYPE_ARC4 */ + +#if defined(PSA_WANT_KEY_TYPE_ARIA) +#if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ARIA) +#define PSA_HAVE_SOFT_KEY_TYPE_ARIA 1 +#endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_ARIA */ +#if defined(PSA_HAVE_SOFT_KEY_TYPE_ARIA) || \ + defined(PSA_HAVE_SOFT_BLOCK_MODE) || \ + defined(PSA_HAVE_SOFT_BLOCK_AEAD) +#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ARIA 1 +#define MBEDTLS_ARIA_C +#endif /* PSA_HAVE_SOFT_KEY_TYPE_ARIA || PSA_HAVE_SOFT_BLOCK_MODE */ +#endif /* PSA_WANT_KEY_TYPE_ARIA */ + +#if defined(PSA_WANT_KEY_TYPE_CAMELLIA) +#if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_CAMELLIA) +#define PSA_HAVE_SOFT_KEY_TYPE_CAMELLIA 1 +#endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_CAMELLIA */ +#if defined(PSA_HAVE_SOFT_KEY_TYPE_CAMELLIA) || \ + defined(PSA_HAVE_SOFT_BLOCK_MODE) || \ + defined(PSA_HAVE_SOFT_BLOCK_AEAD) +#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_CAMELLIA 1 +#define MBEDTLS_CAMELLIA_C +#endif /* PSA_HAVE_SOFT_KEY_TYPE_CAMELLIA || PSA_HAVE_SOFT_BLOCK_MODE */ +#endif /* PSA_WANT_KEY_TYPE_CAMELLIA */ + +#if defined(PSA_WANT_KEY_TYPE_DES) +#if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_DES) +#define PSA_HAVE_SOFT_KEY_TYPE_DES 1 +#endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_DES */ +#if defined(PSA_HAVE_SOFT_KEY_TYPE_DES) || \ + defined(PSA_HAVE_SOFT_BLOCK_MODE) +#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_DES 1 +#define MBEDTLS_DES_C +#endif /*PSA_HAVE_SOFT_KEY_TYPE_DES || PSA_HAVE_SOFT_BLOCK_MODE */ +#endif /* PSA_WANT_KEY_TYPE_DES */ + +#if defined(PSA_WANT_KEY_TYPE_CHACHA20) +#if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_CHACHA20) +#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_CHACHA20 1 +#define MBEDTLS_CHACHA20_C +#endif /*!MBEDTLS_PSA_ACCEL_KEY_TYPE_CHACHA20 */ +#endif /* PSA_WANT_KEY_TYPE_CHACHA20 */ + +/* If any of the software block ciphers are selected, define + * PSA_HAVE_SOFT_BLOCK_CIPHER, which can be used in any of these + * situations. */ +#if defined(PSA_HAVE_SOFT_KEY_TYPE_AES) || \ + defined(PSA_HAVE_SOFT_KEY_TYPE_ARIA) || \ + defined(PSA_HAVE_SOFT_KEY_TYPE_DES) || \ + defined(PSA_HAVE_SOFT_KEY_TYPE_CAMELLIA) +#define PSA_HAVE_SOFT_BLOCK_CIPHER 1 +#endif + +#if defined(PSA_WANT_ALG_STREAM_CIPHER) +#define MBEDTLS_PSA_BUILTIN_ALG_STREAM_CIPHER 1 +#endif /* PSA_WANT_ALG_STREAM_CIPHER */ + +#if defined(PSA_WANT_ALG_CBC_MAC) +#if !defined(MBEDTLS_PSA_ACCEL_ALG_CBC_MAC) +#error "CBC-MAC is not yet supported via the PSA API in Mbed TLS." +#define MBEDTLS_PSA_BUILTIN_ALG_CBC_MAC 1 +#endif /* !MBEDTLS_PSA_ACCEL_ALG_CBC_MAC */ +#endif /* PSA_WANT_ALG_CBC_MAC */ + +#if defined(PSA_WANT_ALG_CMAC) +#if !defined(MBEDTLS_PSA_ACCEL_ALG_CMAC) || \ + defined(PSA_HAVE_SOFT_BLOCK_CIPHER) +#define MBEDTLS_PSA_BUILTIN_ALG_CMAC 1 +#define MBEDTLS_CMAC_C +#endif /* !MBEDTLS_PSA_ACCEL_ALG_CMAC */ +#endif /* PSA_WANT_ALG_CMAC */ + +#if defined(PSA_WANT_ALG_CTR) +#if !defined(MBEDTLS_PSA_ACCEL_ALG_CTR) || \ + defined(PSA_HAVE_SOFT_BLOCK_CIPHER) +#define MBEDTLS_PSA_BUILTIN_ALG_CTR 1 +#define MBEDTLS_CIPHER_MODE_CTR +#endif +#endif /* PSA_WANT_ALG_CTR */ + +#if defined(PSA_WANT_ALG_CFB) +#if !defined(MBEDTLS_PSA_ACCEL_ALG_CFB) || \ + defined(PSA_HAVE_SOFT_BLOCK_CIPHER) +#define MBEDTLS_PSA_BUILTIN_ALG_CFB 1 +#define MBEDTLS_CIPHER_MODE_CFB +#endif +#endif /* PSA_WANT_ALG_CFB */ + +#if defined(PSA_WANT_ALG_OFB) +#if !defined(MBEDTLS_PSA_ACCEL_ALG_OFB) || \ + defined(PSA_HAVE_SOFT_BLOCK_CIPHER) +#define MBEDTLS_PSA_BUILTIN_ALG_OFB 1 +#define MBEDTLS_CIPHER_MODE_OFB +#endif +#endif /* PSA_WANT_ALG_OFB */ + +#if defined(PSA_WANT_ALG_XTS) +#if !defined(MBEDTLS_PSA_ACCEL_ALG_XTS) || \ + defined(PSA_HAVE_SOFT_BLOCK_CIPHER) +#define MBEDTLS_PSA_BUILTIN_ALG_XTS 1 +#define MBEDTLS_CIPHER_MODE_XTS +#endif +#endif /* PSA_WANT_ALG_XTS */ + +#if defined(PSA_WANT_ALG_ECB_NO_PADDING) +#define MBEDTLS_PSA_BUILTIN_ALG_ECB_NO_PADDING 1 +#endif + +#if defined(PSA_WANT_ALG_CBC_NO_PADDING) +#if !defined(MBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING) || \ + defined(PSA_HAVE_SOFT_BLOCK_CIPHER) +#define MBEDTLS_CIPHER_MODE_CBC +#define MBEDTLS_PSA_BUILTIN_ALG_CBC_NO_PADDING 1 +#endif +#endif /* PSA_WANT_ALG_CBC_NO_PADDING */ + +#if defined(PSA_WANT_ALG_CBC_PKCS7) +#if !defined(MBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7) || \ + defined(PSA_HAVE_SOFT_BLOCK_CIPHER) +#define MBEDTLS_CIPHER_MODE_CBC +#define MBEDTLS_PSA_BUILTIN_ALG_CBC_PKCS7 1 +#define MBEDTLS_CIPHER_PADDING_PKCS7 +#endif +#endif /* PSA_WANT_ALG_CBC_PKCS7 */ + +#if defined(PSA_WANT_ALG_CCM) +#if !defined(MBEDTLS_PSA_ACCEL_ALG_CCM) || \ + defined(PSA_HAVE_SOFT_KEY_TYPE_AES) || \ + defined(PSA_HAVE_SOFT_KEY_TYPE_ARIA) || \ + defined(PSA_HAVE_SOFT_KEY_TYPE_CAMELLIA) +#define MBEDTLS_PSA_BUILTIN_ALG_CCM 1 +#define MBEDTLS_CCM_C +#endif +#endif /* PSA_WANT_ALG_CCM */ + +#if defined(PSA_WANT_ALG_GCM) +#if !defined(MBEDTLS_PSA_ACCEL_ALG_GCM) || \ + defined(PSA_HAVE_SOFT_KEY_TYPE_AES) || \ + defined(PSA_HAVE_SOFT_KEY_TYPE_ARIA) || \ + defined(PSA_HAVE_SOFT_KEY_TYPE_CAMELLIA) +#define MBEDTLS_PSA_BUILTIN_ALG_GCM 1 +#define MBEDTLS_GCM_C +#endif +#endif /* PSA_WANT_ALG_GCM */ + +#if defined(PSA_WANT_ALG_CHACHA20_POLY1305) +#if !defined(MBEDTLS_PSA_ACCEL_ALG_CHACHA20_POLY1305) +#if defined(PSA_WANT_KEY_TYPE_CHACHA20) +#define MBEDTLS_CHACHAPOLY_C +#define MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 1 +#endif /* PSA_WANT_KEY_TYPE_CHACHA20 */ +#endif /* !MBEDTLS_PSA_ACCEL_ALG_CHACHA20_POLY1305 */ +#endif /* PSA_WANT_ALG_CHACHA20_POLY1305 */ + +#if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_256) +#if !defined(MBEDTLS_PSA_ACCEL_ECC_BRAINPOOL_P_R1_256) +#define MBEDTLS_ECP_DP_BP256R1_ENABLED +#define MBEDTLS_PSA_BUILTIN_ECC_BRAINPOOL_P_R1_256 1 +#endif /* !MBEDTLS_PSA_ACCEL_ECC_BRAINPOOL_P_R1_256 */ +#endif /* PSA_WANT_ECC_BRAINPOOL_P_R1_256 */ + +#if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_384) +#if !defined(MBEDTLS_PSA_ACCEL_ECC_BRAINPOOL_P_R1_384) +#define MBEDTLS_ECP_DP_BP384R1_ENABLED +#define MBEDTLS_PSA_BUILTIN_ECC_BRAINPOOL_P_R1_384 1 +#endif /* !MBEDTLS_PSA_ACCEL_ECC_BRAINPOOL_P_R1_384 */ +#endif /* PSA_WANT_ECC_BRAINPOOL_P_R1_384 */ + +#if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_512) +#if !defined(MBEDTLS_PSA_ACCEL_ECC_BRAINPOOL_P_R1_512) +#define MBEDTLS_ECP_DP_BP512R1_ENABLED +#define MBEDTLS_PSA_BUILTIN_ECC_BRAINPOOL_P_R1_512 1 +#endif /* !MBEDTLS_PSA_ACCEL_ECC_BRAINPOOL_P_R1_512 */ +#endif /* PSA_WANT_ECC_BRAINPOOL_P_R1_512 */ + +#if defined(PSA_WANT_ECC_MONTGOMERY_255) +#if !defined(MBEDTLS_PSA_ACCEL_ECC_MONTGOMERY_255) +#define MBEDTLS_ECP_DP_CURVE25519_ENABLED +#define MBEDTLS_PSA_BUILTIN_ECC_MONTGOMERY_255 1 +#endif /* !MBEDTLS_PSA_ACCEL_ECC_MONTGOMERY_255 */ +#endif /* PSA_WANT_ECC_MONTGOMERY_255 */ + +#if defined(PSA_WANT_ECC_MONTGOMERY_448) +#if !defined(MBEDTLS_PSA_ACCEL_ECC_MONTGOMERY_448) +/* + * Curve448 is not yet supported via the PSA API in Mbed TLS + * (https://github.com/ARMmbed/mbedtls/issues/4249). + */ +#error "Curve448 is not yet supported via the PSA API in Mbed TLS." +#define MBEDTLS_ECP_DP_CURVE448_ENABLED +#define MBEDTLS_PSA_BUILTIN_ECC_MONTGOMERY_448 1 +#endif /* !MBEDTLS_PSA_ACCEL_ECC_MONTGOMERY_448 */ +#endif /* PSA_WANT_ECC_MONTGOMERY_448 */ + +#if defined(PSA_WANT_ECC_SECP_R1_192) +#if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_192) +#define MBEDTLS_ECP_DP_SECP192R1_ENABLED +#define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_192 1 +#endif /* !MBEDTLS_PSA_ACCEL_ECC_SECP_R1_192 */ +#endif /* PSA_WANT_ECC_SECP_R1_192 */ + +#if defined(PSA_WANT_ECC_SECP_R1_224) +#if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_224) +#define MBEDTLS_ECP_DP_SECP224R1_ENABLED +#define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_224 1 +#endif /* !MBEDTLS_PSA_ACCEL_ECC_SECP_R1_224 */ +#endif /* PSA_WANT_ECC_SECP_R1_224 */ + +#if defined(PSA_WANT_ECC_SECP_R1_256) +#if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_256) +#define MBEDTLS_ECP_DP_SECP256R1_ENABLED +#define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_256 1 +#endif /* !MBEDTLS_PSA_ACCEL_ECC_SECP_R1_256 */ +#endif /* PSA_WANT_ECC_SECP_R1_256 */ + +#if defined(PSA_WANT_ECC_SECP_R1_384) +#if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_384) +#define MBEDTLS_ECP_DP_SECP384R1_ENABLED +#define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_384 1 +#endif /* !MBEDTLS_PSA_ACCEL_ECC_SECP_R1_384 */ +#endif /* PSA_WANT_ECC_SECP_R1_384 */ + +#if defined(PSA_WANT_ECC_SECP_R1_521) +#if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_521) +#define MBEDTLS_ECP_DP_SECP521R1_ENABLED +#define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_521 1 +#endif /* !MBEDTLS_PSA_ACCEL_ECC_SECP_R1_521 */ +#endif /* PSA_WANT_ECC_SECP_R1_521 */ + +#if defined(PSA_WANT_ECC_SECP_K1_192) +#if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_K1_192) +#define MBEDTLS_ECP_DP_SECP192K1_ENABLED +#define MBEDTLS_PSA_BUILTIN_ECC_SECP_K1_192 1 +#endif /* !MBEDTLS_PSA_ACCEL_ECC_SECP_K1_192 */ +#endif /* PSA_WANT_ECC_SECP_K1_192 */ + +#if defined(PSA_WANT_ECC_SECP_K1_224) +#if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_K1_224) +/* + * SECP224K1 is buggy via the PSA API in Mbed TLS + * (https://github.com/ARMmbed/mbedtls/issues/3541). + */ +#error "SECP224K1 is buggy via the PSA API in Mbed TLS." +#define MBEDTLS_ECP_DP_SECP224K1_ENABLED +#define MBEDTLS_PSA_BUILTIN_ECC_SECP_K1_224 1 +#endif /* !MBEDTLS_PSA_ACCEL_ECC_SECP_K1_224 */ +#endif /* PSA_WANT_ECC_SECP_K1_224 */ + +#if defined(PSA_WANT_ECC_SECP_K1_256) +#if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_K1_256) +#define MBEDTLS_ECP_DP_SECP256K1_ENABLED +#define MBEDTLS_PSA_BUILTIN_ECC_SECP_K1_256 1 +#endif /* !MBEDTLS_PSA_ACCEL_ECC_SECP_K1_256 */ +#endif /* PSA_WANT_ECC_SECP_K1_256 */ + + + +/****************************************************************/ +/* Infer PSA requirements from Mbed TLS capabilities */ +/****************************************************************/ + +#else /* MBEDTLS_PSA_CRYPTO_CONFIG */ + +/* + * Ensure PSA_WANT_* defines are setup properly if MBEDTLS_PSA_CRYPTO_CONFIG + * is not defined + */ + +#if defined(MBEDTLS_CCM_C) +#define MBEDTLS_PSA_BUILTIN_ALG_CCM 1 +#define PSA_WANT_ALG_CCM 1 +#endif /* MBEDTLS_CCM_C */ + +#if defined(MBEDTLS_CMAC_C) +#define MBEDTLS_PSA_BUILTIN_ALG_CMAC 1 +#define PSA_WANT_ALG_CMAC 1 +#endif /* MBEDTLS_CMAC_C */ + +#if defined(MBEDTLS_ECDH_C) +#define MBEDTLS_PSA_BUILTIN_ALG_ECDH 1 +#define PSA_WANT_ALG_ECDH 1 +#endif /* MBEDTLS_ECDH_C */ + +#if defined(MBEDTLS_ECDSA_C) +#define MBEDTLS_PSA_BUILTIN_ALG_ECDSA 1 +#define PSA_WANT_ALG_ECDSA 1 +#define PSA_WANT_ALG_ECDSA_ANY 1 + +// Only add in DETERMINISTIC support if ECDSA is also enabled +#if defined(MBEDTLS_ECDSA_DETERMINISTIC) +#define MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA 1 +#define PSA_WANT_ALG_DETERMINISTIC_ECDSA 1 +#endif /* MBEDTLS_ECDSA_DETERMINISTIC */ + +#endif /* MBEDTLS_ECDSA_C */ + +#if defined(MBEDTLS_ECP_C) +#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR 1 +#define PSA_WANT_KEY_TYPE_ECC_KEY_PAIR 1 +#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY 1 +#define PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1 +#endif /* MBEDTLS_ECP_C */ + +#if defined(MBEDTLS_GCM_C) +#define MBEDTLS_PSA_BUILTIN_ALG_GCM 1 +#define PSA_WANT_ALG_GCM 1 +#endif /* MBEDTLS_GCM_C */ + +#if defined(MBEDTLS_HKDF_C) +#define MBEDTLS_PSA_BUILTIN_ALG_HMAC 1 +#define PSA_WANT_ALG_HMAC 1 +#define MBEDTLS_PSA_BUILTIN_ALG_HKDF 1 +#define PSA_WANT_ALG_HKDF 1 +#endif /* MBEDTLS_HKDF_C */ + +#if defined(MBEDTLS_MD_C) +#define MBEDTLS_PSA_BUILTIN_ALG_HMAC 1 +#define PSA_WANT_ALG_HMAC 1 +#define PSA_WANT_KEY_TYPE_HMAC +#define MBEDTLS_PSA_BUILTIN_ALG_TLS12_PRF 1 +#define PSA_WANT_ALG_TLS12_PRF 1 +#define MBEDTLS_PSA_BUILTIN_ALG_TLS12_PSK_TO_MS 1 +#define PSA_WANT_ALG_TLS12_PSK_TO_MS 1 +#endif /* MBEDTLS_MD_C */ + +#if defined(MBEDTLS_MD2_C) +#define MBEDTLS_PSA_BUILTIN_ALG_MD2 1 +#define PSA_WANT_ALG_MD2 1 +#endif + +#if defined(MBEDTLS_MD4_C) +#define MBEDTLS_PSA_BUILTIN_ALG_MD4 1 +#define PSA_WANT_ALG_MD4 1 +#endif + +#if defined(MBEDTLS_MD5_C) +#define MBEDTLS_PSA_BUILTIN_ALG_MD5 1 +#define PSA_WANT_ALG_MD5 1 +#endif + +#if defined(MBEDTLS_RIPEMD160_C) +#define MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160 1 +#define PSA_WANT_ALG_RIPEMD160 1 +#endif + +#if defined(MBEDTLS_RSA_C) +#if defined(MBEDTLS_PKCS1_V15) +#define MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT 1 +#define PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1 +#define MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN 1 +#define PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1 +#define PSA_WANT_ALG_RSA_PKCS1V15_SIGN_RAW 1 +#endif /* MBEDTLS_PKCS1_V15 */ +#if defined(MBEDTLS_PKCS1_V21) +#define MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP 1 +#define PSA_WANT_ALG_RSA_OAEP 1 +#define MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS 1 +#define PSA_WANT_ALG_RSA_PSS 1 +#endif /* MBEDTLS_PKCS1_V21 */ +#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR 1 +#define PSA_WANT_KEY_TYPE_RSA_KEY_PAIR 1 +#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY 1 +#define PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1 +#endif /* MBEDTLS_RSA_C */ + +#if defined(MBEDTLS_SHA1_C) +#define MBEDTLS_PSA_BUILTIN_ALG_SHA_1 1 +#define PSA_WANT_ALG_SHA_1 1 +#endif + +#if defined(MBEDTLS_SHA256_C) +#define MBEDTLS_PSA_BUILTIN_ALG_SHA_224 1 +#define MBEDTLS_PSA_BUILTIN_ALG_SHA_256 1 +#define PSA_WANT_ALG_SHA_224 1 +#define PSA_WANT_ALG_SHA_256 1 +#endif + +#if defined(MBEDTLS_SHA512_C) +#if !defined(MBEDTLS_SHA512_NO_SHA384) +#define MBEDTLS_PSA_BUILTIN_ALG_SHA_384 1 +#define PSA_WANT_ALG_SHA_384 1 +#endif +#define MBEDTLS_PSA_BUILTIN_ALG_SHA_512 1 +#define PSA_WANT_ALG_SHA_512 1 +#endif + +#if defined(MBEDTLS_AES_C) +#define PSA_WANT_KEY_TYPE_AES 1 +#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_AES 1 +#endif + +#if defined(MBEDTLS_ARC4_C) +#define PSA_WANT_KEY_TYPE_ARC4 1 +#define PSA_WANT_ALG_STREAM_CIPHER 1 +#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ARC4 1 +#define MBEDTLS_PSA_BUILTIN_ALG_STREAM_CIPHER 1 +#endif + +#if defined(MBEDTLS_ARIA_C) +#define PSA_WANT_KEY_TYPE_ARIA 1 +#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ARIA 1 +#endif + +#if defined(MBEDTLS_CAMELLIA_C) +#define PSA_WANT_KEY_TYPE_CAMELLIA 1 +#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_CAMELLIA 1 +#endif + +#if defined(MBEDTLS_DES_C) +#define PSA_WANT_KEY_TYPE_DES 1 +#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_DES 1 +#endif + +#if defined(MBEDTLS_CHACHA20_C) +#define PSA_WANT_KEY_TYPE_CHACHA20 1 +#define PSA_WANT_ALG_STREAM_CIPHER 1 +#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_CHACHA20 1 +#define MBEDTLS_PSA_BUILTIN_ALG_STREAM_CIPHER 1 +#if defined(MBEDTLS_CHACHAPOLY_C) +#define PSA_WANT_ALG_CHACHA20_POLY1305 1 +#define MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 1 +#endif +#endif + +#if defined(MBEDTLS_CIPHER_MODE_CBC) +#define MBEDTLS_PSA_BUILTIN_ALG_CBC_NO_PADDING 1 +#define PSA_WANT_ALG_CBC_NO_PADDING 1 +#if defined(MBEDTLS_CIPHER_PADDING_PKCS7) +#define MBEDTLS_PSA_BUILTIN_ALG_CBC_PKCS7 1 +#define PSA_WANT_ALG_CBC_PKCS7 1 +#endif +#endif + +#if defined(MBEDTLS_AES_C) || defined(MBEDTLS_DES_C) || \ + defined(MBEDTLS_ARIA_C) || defined(MBEDTLS_CAMELLIA_C) +#define MBEDTLS_PSA_BUILTIN_ALG_ECB_NO_PADDING 1 +#define PSA_WANT_ALG_ECB_NO_PADDING 1 +#endif + +#if defined(MBEDTLS_CIPHER_MODE_CFB) +#define MBEDTLS_PSA_BUILTIN_ALG_CFB 1 +#define PSA_WANT_ALG_CFB 1 +#endif + +#if defined(MBEDTLS_CIPHER_MODE_CTR) +#define MBEDTLS_PSA_BUILTIN_ALG_CTR 1 +#define PSA_WANT_ALG_CTR 1 +#endif + +#if defined(MBEDTLS_CIPHER_MODE_OFB) +#define MBEDTLS_PSA_BUILTIN_ALG_OFB 1 +#define PSA_WANT_ALG_OFB 1 +#endif + +#if defined(MBEDTLS_CIPHER_MODE_XTS) +#define MBEDTLS_PSA_BUILTIN_ALG_XTS 1 +#define PSA_WANT_ALG_XTS 1 +#endif + +#if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) +#define MBEDTLS_PSA_BUILTIN_ECC_BRAINPOOL_P_R1_256 1 +#define PSA_WANT_ECC_BRAINPOOL_P_R1_256 +#endif + +#if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) +#define MBEDTLS_PSA_BUILTIN_ECC_BRAINPOOL_P_R1_384 1 +#define PSA_WANT_ECC_BRAINPOOL_P_R1_384 +#endif + +#if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) +#define MBEDTLS_PSA_BUILTIN_ECC_BRAINPOOL_P_R1_512 1 +#define PSA_WANT_ECC_BRAINPOOL_P_R1_512 +#endif + +#if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) +#define MBEDTLS_PSA_BUILTIN_ECC_MONTGOMERY_255 1 +#define PSA_WANT_ECC_MONTGOMERY_255 +#endif + +/* Curve448 is not yet supported via the PSA API (https://github.com/ARMmbed/mbedtls/issues/4249) */ +#if 0 && defined(MBEDTLS_ECP_DP_CURVE448_ENABLED) +#define MBEDTLS_PSA_BUILTIN_ECC_MONTGOMERY_448 1 +#define PSA_WANT_ECC_MONTGOMERY_448 +#endif + +#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) +#define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_192 1 +#define PSA_WANT_ECC_SECP_R1_192 +#endif + +#if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) +#define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_224 1 +#define PSA_WANT_ECC_SECP_R1_224 +#endif + +#if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) +#define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_256 1 +#define PSA_WANT_ECC_SECP_R1_256 +#endif + +#if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) +#define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_384 1 +#define PSA_WANT_ECC_SECP_R1_384 +#endif + +#if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) +#define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_521 1 +#define PSA_WANT_ECC_SECP_R1_521 +#endif + +#if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) +#define MBEDTLS_PSA_BUILTIN_ECC_SECP_K1_192 1 +#define PSA_WANT_ECC_SECP_K1_192 +#endif + +/* SECP224K1 is buggy via the PSA API (https://github.com/ARMmbed/mbedtls/issues/3541) */ +#if 0 && defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) +#define MBEDTLS_PSA_BUILTIN_ECC_SECP_K1_224 1 +#define PSA_WANT_ECC_SECP_K1_224 +#endif + +#if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) +#define MBEDTLS_PSA_BUILTIN_ECC_SECP_K1_256 1 +#define PSA_WANT_ECC_SECP_K1_256 +#endif + +#endif /* MBEDTLS_PSA_CRYPTO_CONFIG */ + +/* These features are always enabled. */ +#define PSA_WANT_KEY_TYPE_DERIVE 1 +#define PSA_WANT_KEY_TYPE_RAW_DATA 1 + +#ifdef __cplusplus +} +#endif + +#endif /* MBEDTLS_CONFIG_PSA_H */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/constant_time.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/constant_time.h new file mode 100644 index 00000000000..c5de57a01f0 --- /dev/null +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/constant_time.h @@ -0,0 +1,45 @@ +/** + * Constant-time functions + * + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MBEDTLS_CONSTANT_TIME_H +#define MBEDTLS_CONSTANT_TIME_H + +#include + + +/** Constant-time buffer comparison without branches. + * + * This is equivalent to the standard memcmp function, but is likely to be + * compiled to code using bitwise operation rather than a branch. + * + * This function can be used to write constant-time code by replacing branches + * with bit operations using masks. + * + * \param a Pointer to the first buffer. + * \param b Pointer to the second buffer. + * \param n The number of bytes to compare in the buffer. + * + * \return Zero if the content of the two buffer is the same, + * otherwise non-zero. + */ +int mbedtls_ct_memcmp( const void *a, + const void *b, + size_t n ); + +#endif /* MBEDTLS_CONSTANT_TIME_H */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ctr_drbg.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ctr_drbg.h index 6c099adf4d3..dc4adc896d4 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ctr_drbg.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ctr_drbg.h @@ -12,40 +12,18 @@ * The Mbed TLS implementation of CTR_DRBG uses AES-256 (default) or AES-128 * (if \c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY is enabled at compile time) * as the underlying block cipher, with a derivation function. - * The initial seeding grabs #MBEDTLS_CTR_DRBG_ENTROPY_LEN bytes of entropy. - * See the documentation of mbedtls_ctr_drbg_seed() for more details. - * - * Based on NIST SP 800-90A §10.2.1 table 3 and NIST SP 800-57 part 1 table 2, - * here are the security strengths achieved in typical configuration: - * - 256 bits under the default configuration of the library, with AES-256 - * and with #MBEDTLS_CTR_DRBG_ENTROPY_LEN set to 48 or more. - * - 256 bits if AES-256 is used, #MBEDTLS_CTR_DRBG_ENTROPY_LEN is set - * to 32 or more, and the DRBG is initialized with an explicit - * nonce in the \c custom parameter to mbedtls_ctr_drbg_seed(). - * - 128 bits if AES-256 is used but #MBEDTLS_CTR_DRBG_ENTROPY_LEN is - * between 24 and 47 and the DRBG is not initialized with an explicit - * nonce (see mbedtls_ctr_drbg_seed()). - * - 128 bits if AES-128 is used (\c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY enabled) - * and #MBEDTLS_CTR_DRBG_ENTROPY_LEN is set to 24 or more (which is - * always the case unless it is explicitly set to a different value - * in config.h). - * - * Note that the value of #MBEDTLS_CTR_DRBG_ENTROPY_LEN defaults to: - * - \c 48 if the module \c MBEDTLS_SHA512_C is enabled and the symbol - * \c MBEDTLS_ENTROPY_FORCE_SHA256 is disabled at compile time. - * This is the default configuration of the library. - * - \c 32 if the module \c MBEDTLS_SHA512_C is disabled at compile time. - * - \c 32 if \c MBEDTLS_ENTROPY_FORCE_SHA256 is enabled at compile time. + * + * The security strength as defined in NIST SP 800-90A is + * 128 bits when AES-128 is used (\c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY enabled) + * and 256 bits otherwise, provided that #MBEDTLS_CTR_DRBG_ENTROPY_LEN is + * kept at its default value (and not overridden in config.h) and that the + * DRBG instance is set up with default parameters. + * See the documentation of mbedtls_ctr_drbg_seed() for more + * information. */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -58,48 +36,31 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_CTR_DRBG_H #define MBEDTLS_CTR_DRBG_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "aes.h" +#include "mbedtls/aes.h" #if defined(MBEDTLS_THREADING_C) -#include "threading.h" +#include "mbedtls/threading.h" #endif -#define MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED -0x0034 /**< The entropy source failed. */ -#define MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG -0x0036 /**< The requested random buffer length is too big. */ -#define MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG -0x0038 /**< The input (entropy + additional data) is too large. */ -#define MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR -0x003A /**< Read or write error in file. */ +/** The entropy source failed. */ +#define MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED -0x0034 +/** The requested random buffer length is too big. */ +#define MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG -0x0036 +/** The input (entropy + additional data) is too large. */ +#define MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG -0x0038 +/** Read or write error in file. */ +#define MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR -0x003A #define MBEDTLS_CTR_DRBG_BLOCKSIZE 16 /**< The block size used by the cipher. */ @@ -188,20 +149,49 @@ extern "C" { #endif +#if MBEDTLS_CTR_DRBG_ENTROPY_LEN >= MBEDTLS_CTR_DRBG_KEYSIZE * 3 / 2 +/** The default length of the nonce read from the entropy source. + * + * This is \c 0 because a single read from the entropy source is sufficient + * to include a nonce. + * See the documentation of mbedtls_ctr_drbg_seed() for more information. + */ +#define MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN 0 +#else +/** The default length of the nonce read from the entropy source. + * + * This is half of the default entropy length because a single read from + * the entropy source does not provide enough material to form a nonce. + * See the documentation of mbedtls_ctr_drbg_seed() for more information. + */ +#define MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN ( MBEDTLS_CTR_DRBG_ENTROPY_LEN + 1 ) / 2 +#endif + /** * \brief The CTR_DRBG context structure. */ typedef struct mbedtls_ctr_drbg_context { unsigned char counter[16]; /*!< The counter (V). */ - int reseed_counter; /*!< The reseed counter. */ + int reseed_counter; /*!< The reseed counter. + * This is the number of requests that have + * been made since the last (re)seeding, + * minus one. + * Before the initial seeding, this field + * contains the amount of entropy in bytes + * to use as a nonce for the initial seeding, + * or -1 if no nonce length has been explicitly + * set (see mbedtls_ctr_drbg_set_nonce_len()). + */ int prediction_resistance; /*!< This determines whether prediction resistance is enabled, that is whether to systematically reseed before each random generation. */ size_t entropy_len; /*!< The amount of entropy grabbed on each - seed or reseed operation. */ - int reseed_interval; /*!< The reseed interval. */ + seed or reseed operation, in bytes. */ + int reseed_interval; /*!< The reseed interval. + * This is the maximum number of requests + * that can be made between reseedings. */ mbedtls_aes_context aes_ctx; /*!< The AES context. */ @@ -254,34 +244,35 @@ void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx ); * The entropy length is #MBEDTLS_CTR_DRBG_ENTROPY_LEN by default. * You can override it by calling mbedtls_ctr_drbg_set_entropy_len(). * - * You can provide a personalization string in addition to the + * The entropy nonce length is: + * - \c 0 if the entropy length is at least 3/2 times the entropy length, + * which guarantees that the security strength is the maximum permitted + * by the key size and entropy length according to NIST SP 800-90A §10.2.1; + * - Half the entropy length otherwise. + * You can override it by calling mbedtls_ctr_drbg_set_nonce_len(). + * With the default entropy length, the entropy nonce length is + * #MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN. + * + * You can provide a nonce and personalization string in addition to the * entropy source, to make this instantiation as unique as possible. + * See SP 800-90A §8.6.7 for more details about nonces. * - * \note The _seed_material_ value passed to the derivation - * function in the CTR_DRBG Instantiate Process - * described in NIST SP 800-90A §10.2.1.3.2 - * is the concatenation of the string obtained from - * calling \p f_entropy and the \p custom string. - * The origin of the nonce depends on the value of - * the entropy length relative to the security strength. - * - If the entropy length is at least 1.5 times the - * security strength then the nonce is taken from the - * string obtained with \p f_entropy. - * - If the entropy length is less than the security - * strength, then the nonce is taken from \p custom. - * In this case, for compliance with SP 800-90A, - * you must pass a unique value of \p custom at - * each invocation. See SP 800-90A §8.6.7 for more - * details. - */ -#if MBEDTLS_CTR_DRBG_ENTROPY_LEN < MBEDTLS_CTR_DRBG_KEYSIZE * 3 / 2 -/** \warning When #MBEDTLS_CTR_DRBG_ENTROPY_LEN is less than - * #MBEDTLS_CTR_DRBG_KEYSIZE * 3 / 2, to achieve the - * maximum security strength permitted by CTR_DRBG, - * you must pass a value of \p custom that is a nonce: - * this value must never be repeated in subsequent - * runs of the same application or on a different - * device. + * The _seed_material_ value passed to the derivation function in + * the CTR_DRBG Instantiate Process described in NIST SP 800-90A §10.2.1.3.2 + * is the concatenation of the following strings: + * - A string obtained by calling \p f_entropy function for the entropy + * length. + */ +#if MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN == 0 +/** + * - If mbedtls_ctr_drbg_set_nonce_len() has been called, a string + * obtained by calling \p f_entropy function for the specified length. + */ +#else +/** + * - A string obtained by calling \p f_entropy function for the entropy nonce + * length. If the entropy nonce length is \c 0, this function does not + * make a second call to \p f_entropy. */ #endif #if defined(MBEDTLS_THREADING_C) @@ -294,6 +285,23 @@ void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx ); */ #endif /* MBEDTLS_THREADING_C */ /** + * - The \p custom string. + * + * \note To achieve the nominal security strength permitted + * by CTR_DRBG, the entropy length must be: + * - at least 16 bytes for a 128-bit strength + * (maximum achievable strength when using AES-128); + * - at least 32 bytes for a 256-bit strength + * (maximum achievable strength when using AES-256). + * + * In addition, if you do not pass a nonce in \p custom, + * the sum of the entropy length + * and the entropy nonce length must be: + * - at least 24 bytes for a 128-bit strength + * (maximum achievable strength when using AES-128); + * - at least 48 bytes for a 256-bit strength + * (maximum achievable strength when using AES-256). + * * \param ctx The CTR_DRBG context to seed. * It must have been initialized with * mbedtls_ctr_drbg_init(). @@ -308,7 +316,7 @@ void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx ); * \p p_entropy context, the buffer to fill, and the * length of the buffer. * \p f_entropy is always called with a buffer size - * equal to the entropy length. + * less than or equal to the entropy length. * \param p_entropy The entropy context to pass to \p f_entropy. * \param custom The personalization string. * This can be \c NULL, in which case the personalization @@ -371,11 +379,35 @@ void mbedtls_ctr_drbg_set_prediction_resistance( mbedtls_ctr_drbg_context *ctx, * * \param ctx The CTR_DRBG context. * \param len The amount of entropy to grab, in bytes. - * This must be at most #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT. + * This must be at most #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT + * and at most the maximum length accepted by the + * entropy function that is set in the context. */ void mbedtls_ctr_drbg_set_entropy_len( mbedtls_ctr_drbg_context *ctx, size_t len ); +/** + * \brief This function sets the amount of entropy grabbed + * as a nonce for the initial seeding. + * + * Call this function before calling mbedtls_ctr_drbg_seed() to read + * a nonce from the entropy source during the initial seeding. + * + * \param ctx The CTR_DRBG context. + * \param len The amount of entropy to grab for the nonce, in bytes. + * This must be at most #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT + * and at most the maximum length accepted by the + * entropy function that is set in the context. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG if \p len is + * more than #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT. + * \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED + * if the initial seeding has already taken place. + */ +int mbedtls_ctr_drbg_set_nonce_len( mbedtls_ctr_drbg_context *ctx, + size_t len ); + /** * \brief This function sets the reseed interval. * @@ -417,10 +449,10 @@ int mbedtls_ctr_drbg_reseed( mbedtls_ctr_drbg_context *ctx, /** * \brief This function updates the state of the CTR_DRBG context. * - * \note This function is not thread-safe. It is not safe - * to call this function if another thread might be - * concurrently obtaining random numbers from the same - * context or updating or reseeding the same context. + * \note This function is not thread-safe. It is not safe + * to call this function if another thread might be + * concurrently obtaining random numbers from the same + * context or updating or reseeding the same context. * * \param ctx The CTR_DRBG context. * \param additional The data to update the state with. This must not be @@ -572,11 +604,6 @@ int mbedtls_ctr_drbg_self_test( int verbose ); #endif /* MBEDTLS_SELF_TEST */ -/* Internal functions (do not call directly) */ -int mbedtls_ctr_drbg_seed_entropy_len( mbedtls_ctr_drbg_context *, - int (*)(void *, unsigned char *, size_t), void *, - const unsigned char *, size_t, size_t ); - #ifdef __cplusplus } #endif diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/debug.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/debug.h index abc2d4f07ca..3c08244f3da 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/debug.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/debug.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,41 +18,20 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_DEBUG_H #define MBEDTLS_DEBUG_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "ssl.h" +#include "mbedtls/ssl.h" #if defined(MBEDTLS_ECP_C) -#include "ecp.h" +#include "mbedtls/ecp.h" #endif #if defined(MBEDTLS_DEBUG_C) @@ -107,6 +80,55 @@ #endif /* MBEDTLS_DEBUG_C */ +/** + * \def MBEDTLS_PRINTF_ATTRIBUTE + * + * Mark a function as having printf attributes, and thus enable checking + * via -wFormat and other flags. This does nothing on builds with compilers + * that do not support the format attribute + * + * Module: library/debug.c + * Caller: + * + * This module provides debugging functions. + */ +#if defined(__has_attribute) +#if __has_attribute(format) +#if defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 1 +#define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check) \ + __attribute__((__format__ (gnu_printf, string_index, first_to_check))) +#else /* defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 1 */ +#define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check) \ + __attribute__((format(printf, string_index, first_to_check))) +#endif +#else /* __has_attribute(format) */ +#define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check) +#endif /* __has_attribute(format) */ +#else /* defined(__has_attribute) */ +#define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check) +#endif + +/** + * \def MBEDTLS_PRINTF_SIZET + * + * MBEDTLS_PRINTF_xxx: Due to issues with older window compilers + * and MinGW we need to define the printf specifier for size_t + * and long long per platform. + * + * Module: library/debug.c + * Caller: + * + * This module provides debugging functions. + */ +#if (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800) + #include + #define MBEDTLS_PRINTF_SIZET PRIuPTR + #define MBEDTLS_PRINTF_LONGLONG "I64d" +#else /* (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800) */ + #define MBEDTLS_PRINTF_SIZET "zu" + #define MBEDTLS_PRINTF_LONGLONG "lld" +#endif /* (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800) */ + #ifdef __cplusplus extern "C" { #endif @@ -145,7 +167,7 @@ void mbedtls_debug_set_threshold( int threshold ); */ void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level, const char *file, int line, - const char *format, ... ); + const char *format, ... ) MBEDTLS_PRINTF_ATTRIBUTE(5, 6); /** * \brief Print the return value of a function to the debug output. This @@ -287,4 +309,3 @@ void mbedtls_debug_printf_ecdh( const mbedtls_ssl_context *ssl, int level, #endif #endif /* debug.h */ - diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/des.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/des.h index ee24f659459..325aab53644 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/des.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/des.h @@ -9,13 +9,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -29,36 +23,16 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** - * */ #ifndef MBEDTLS_DES_H #define MBEDTLS_DES_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif +#include "mbedtls/platform_util.h" #include #include @@ -66,10 +40,12 @@ #define MBEDTLS_DES_ENCRYPT 1 #define MBEDTLS_DES_DECRYPT 0 -#define MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH -0x0032 /**< The data input has an invalid length. */ +/** The data input has an invalid length. */ +#define MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH -0x0032 /* MBEDTLS_ERR_DES_HW_ACCEL_FAILED is deprecated and should not be used. */ -#define MBEDTLS_ERR_DES_HW_ACCEL_FAILED -0x0033 /**< DES hardware accelerator failed. */ +/** DES hardware accelerator failed. */ +#define MBEDTLS_ERR_DES_HW_ACCEL_FAILED -0x0033 #define MBEDTLS_DES_KEY_SIZE 8 @@ -171,6 +147,7 @@ void mbedtls_des_key_set_parity( unsigned char key[MBEDTLS_DES_KEY_SIZE] ); * security risk. We recommend considering stronger ciphers * instead. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_des_key_check_key_parity( const unsigned char key[MBEDTLS_DES_KEY_SIZE] ); /** @@ -184,6 +161,7 @@ int mbedtls_des_key_check_key_parity( const unsigned char key[MBEDTLS_DES_KEY_SI * security risk. We recommend considering stronger ciphers * instead. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_des_key_check_weak( const unsigned char key[MBEDTLS_DES_KEY_SIZE] ); /** @@ -198,6 +176,7 @@ int mbedtls_des_key_check_weak( const unsigned char key[MBEDTLS_DES_KEY_SIZE] ); * security risk. We recommend considering stronger ciphers * instead. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_des_setkey_enc( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] ); /** @@ -212,6 +191,7 @@ int mbedtls_des_setkey_enc( mbedtls_des_context *ctx, const unsigned char key[MB * security risk. We recommend considering stronger ciphers * instead. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_des_setkey_dec( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] ); /** @@ -222,6 +202,7 @@ int mbedtls_des_setkey_dec( mbedtls_des_context *ctx, const unsigned char key[MB * * \return 0 */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_des3_set2key_enc( mbedtls_des3_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] ); @@ -233,6 +214,7 @@ int mbedtls_des3_set2key_enc( mbedtls_des3_context *ctx, * * \return 0 */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_des3_set2key_dec( mbedtls_des3_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] ); @@ -244,6 +226,7 @@ int mbedtls_des3_set2key_dec( mbedtls_des3_context *ctx, * * \return 0 */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_des3_set3key_enc( mbedtls_des3_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] ); @@ -255,6 +238,7 @@ int mbedtls_des3_set3key_enc( mbedtls_des3_context *ctx, * * \return 0 */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_des3_set3key_dec( mbedtls_des3_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] ); @@ -271,6 +255,7 @@ int mbedtls_des3_set3key_dec( mbedtls_des3_context *ctx, * security risk. We recommend considering stronger ciphers * instead. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_des_crypt_ecb( mbedtls_des_context *ctx, const unsigned char input[8], unsigned char output[8] ); @@ -298,6 +283,7 @@ int mbedtls_des_crypt_ecb( mbedtls_des_context *ctx, * security risk. We recommend considering stronger ciphers * instead. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_des_crypt_cbc( mbedtls_des_context *ctx, int mode, size_t length, @@ -315,6 +301,7 @@ int mbedtls_des_crypt_cbc( mbedtls_des_context *ctx, * * \return 0 if successful */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_des3_crypt_ecb( mbedtls_des3_context *ctx, const unsigned char input[8], unsigned char output[8] ); @@ -340,6 +327,7 @@ int mbedtls_des3_crypt_ecb( mbedtls_des3_context *ctx, * * \return 0 if successful, or MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx, int mode, size_t length, @@ -370,6 +358,7 @@ void mbedtls_des_setkey( uint32_t SK[32], * * \return 0 if successful, or 1 if the test failed */ +MBEDTLS_CHECK_RETURN_CRITICAL int mbedtls_des_self_test( int verbose ); #endif /* MBEDTLS_SELF_TEST */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/dhm.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/dhm.h index 11042efb556..c4b15a2c452 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/dhm.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/dhm.h @@ -45,13 +45,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -64,56 +58,46 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_DHM_H #define MBEDTLS_DHM_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "bignum.h" +#include "mbedtls/bignum.h" /* * DHM Error codes */ -#define MBEDTLS_ERR_DHM_BAD_INPUT_DATA -0x3080 /**< Bad input parameters. */ -#define MBEDTLS_ERR_DHM_READ_PARAMS_FAILED -0x3100 /**< Reading of the DHM parameters failed. */ -#define MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED -0x3180 /**< Making of the DHM parameters failed. */ -#define MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED -0x3200 /**< Reading of the public values failed. */ -#define MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED -0x3280 /**< Making of the public value failed. */ -#define MBEDTLS_ERR_DHM_CALC_SECRET_FAILED -0x3300 /**< Calculation of the DHM secret failed. */ -#define MBEDTLS_ERR_DHM_INVALID_FORMAT -0x3380 /**< The ASN.1 data is not formatted correctly. */ -#define MBEDTLS_ERR_DHM_ALLOC_FAILED -0x3400 /**< Allocation of memory failed. */ -#define MBEDTLS_ERR_DHM_FILE_IO_ERROR -0x3480 /**< Read or write of file failed. */ +/** Bad input parameters. */ +#define MBEDTLS_ERR_DHM_BAD_INPUT_DATA -0x3080 +/** Reading of the DHM parameters failed. */ +#define MBEDTLS_ERR_DHM_READ_PARAMS_FAILED -0x3100 +/** Making of the DHM parameters failed. */ +#define MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED -0x3180 +/** Reading of the public values failed. */ +#define MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED -0x3200 +/** Making of the public value failed. */ +#define MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED -0x3280 +/** Calculation of the DHM secret failed. */ +#define MBEDTLS_ERR_DHM_CALC_SECRET_FAILED -0x3300 +/** The ASN.1 data is not formatted correctly. */ +#define MBEDTLS_ERR_DHM_INVALID_FORMAT -0x3380 +/** Allocation of memory failed. */ +#define MBEDTLS_ERR_DHM_ALLOC_FAILED -0x3400 +/** Read or write of file failed. */ +#define MBEDTLS_ERR_DHM_FILE_IO_ERROR -0x3480 /* MBEDTLS_ERR_DHM_HW_ACCEL_FAILED is deprecated and should not be used. */ -#define MBEDTLS_ERR_DHM_HW_ACCEL_FAILED -0x3500 /**< DHM hardware accelerator failed. */ +/** DHM hardware accelerator failed. */ +#define MBEDTLS_ERR_DHM_HW_ACCEL_FAILED -0x3500 -#define MBEDTLS_ERR_DHM_SET_GROUP_FAILED -0x3580 /**< Setting the modulus and generator failed. */ +/** Setting the modulus and generator failed. */ +#define MBEDTLS_ERR_DHM_SET_GROUP_FAILED -0x3580 #ifdef __cplusplus extern "C" { @@ -323,7 +307,6 @@ int mbedtls_dhm_calc_secret( mbedtls_dhm_context *ctx, void mbedtls_dhm_free( mbedtls_dhm_context *ctx ); #if defined(MBEDTLS_ASN1_PARSE_C) -/** \ingroup x509_module */ /** * \brief This function parses DHM parameters in PEM or DER format. * @@ -342,7 +325,6 @@ int mbedtls_dhm_parse_dhm( mbedtls_dhm_context *dhm, const unsigned char *dhmin, size_t dhminlen ); #if defined(MBEDTLS_FS_IO) -/** \ingroup x509_module */ /** * \brief This function loads and parses DHM parameters from a file. * diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ecdh.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ecdh.h index b9324bc4964..05855cdf10b 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ecdh.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ecdh.h @@ -14,13 +14,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -33,51 +27,23 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_ECDH_H #define MBEDTLS_ECDH_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "ecp.h" +#include "mbedtls/ecp.h" -/* - * Use a backward compatible ECDH context. - * - * This flag is always enabled for now and future versions might add a - * configuration option that conditionally undefines this flag. - * The configuration option in question may have a different name. - * - * Features undefining this flag, must have a warning in their description in - * config.h stating that the feature breaks backward compatibility. - */ -#define MBEDTLS_ECDH_LEGACY_CONTEXT +#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED) +#undef MBEDTLS_ECDH_LEGACY_CONTEXT +#include "everest/everest.h" +#endif #ifdef __cplusplus extern "C" { @@ -103,6 +69,9 @@ typedef enum { MBEDTLS_ECDH_VARIANT_NONE = 0, /*!< Implementation not defined. */ MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0,/*!< The default Mbed TLS implementation */ +#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED) + MBEDTLS_ECDH_VARIANT_EVEREST /*!< Everest implementation */ +#endif } mbedtls_ecdh_variant; /** @@ -156,6 +125,9 @@ typedef struct mbedtls_ecdh_context union { mbedtls_ecdh_context_mbed mbed_ecdh; +#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED) + mbedtls_ecdh_context_everest everest_ecdh; +#endif } ctx; /*!< Implementation-specific context. The context in use is specified by the \c var field. */ @@ -170,6 +142,15 @@ typedef struct mbedtls_ecdh_context } mbedtls_ecdh_context; +/** + * \brief Check whether a given group can be used for ECDH. + * + * \param gid The ECP group ID to check. + * + * \return \c 1 if the group can be used, \c 0 otherwise + */ +int mbedtls_ecdh_can_do( mbedtls_ecp_group_id gid ); + /** * \brief This function generates an ECDH keypair on an elliptic * curve. diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ecdsa.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ecdsa.h index da02b278643..264a638bb52 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ecdsa.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ecdsa.h @@ -12,13 +12,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -31,60 +25,44 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_ECDSA_H #define MBEDTLS_ECDSA_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "ecp.h" -#include "md.h" +#include "mbedtls/ecp.h" +#include "mbedtls/md.h" -/* - * RFC-4492 page 20: +/** + * \brief Maximum ECDSA signature size for a given curve bit size * + * \param bits Curve size in bits + * \return Maximum signature size in bytes + * + * \note This macro returns a compile-time constant if its argument + * is one. It may evaluate its argument multiple times. + */ +/* * Ecdsa-Sig-Value ::= SEQUENCE { * r INTEGER, * s INTEGER * } * - * Size is at most - * 1 (tag) + 1 (len) + 1 (initial 0) + ECP_MAX_BYTES for each of r and s, - * twice that + 1 (tag) + 2 (len) for the sequence - * (assuming ECP_MAX_BYTES is less than 126 for r and s, - * and less than 124 (total len <= 255) for the sequence) + * For each of r and s, the value (V) may include an extra initial "0" bit. */ -#if MBEDTLS_ECP_MAX_BYTES > 124 -#error "MBEDTLS_ECP_MAX_BYTES bigger than expected, please fix MBEDTLS_ECDSA_MAX_LEN" -#endif +#define MBEDTLS_ECDSA_MAX_SIG_LEN( bits ) \ + ( /*T,L of SEQUENCE*/ ( ( bits ) >= 61 * 8 ? 3 : 2 ) + \ + /*T,L of r,s*/ 2 * ( ( ( bits ) >= 127 * 8 ? 3 : 2 ) + \ + /*V of r,s*/ ( ( bits ) + 8 ) / 8 ) ) + /** The maximal size of an ECDSA signature in Bytes. */ -#define MBEDTLS_ECDSA_MAX_LEN ( 3 + 2 * ( 3 + MBEDTLS_ECP_MAX_BYTES ) ) +#define MBEDTLS_ECDSA_MAX_LEN MBEDTLS_ECDSA_MAX_SIG_LEN( MBEDTLS_ECP_MAX_BITS ) #ifdef __cplusplus extern "C" { @@ -145,6 +123,16 @@ typedef void mbedtls_ecdsa_restart_ctx; #endif /* MBEDTLS_ECP_RESTARTABLE */ +/** + * \brief This function checks whether a given group can be used + * for ECDSA. + * + * \param gid The ECP group ID to check. + * + * \return \c 1 if the group can be used, \c 0 otherwise + */ +int mbedtls_ecdsa_can_do( mbedtls_ecp_group_id gid ); + /** * \brief This function computes the ECDSA signature of a * previously-hashed message. @@ -186,6 +174,12 @@ int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); #if defined(MBEDTLS_ECDSA_DETERMINISTIC) +#if ! defined(MBEDTLS_DEPRECATED_REMOVED) +#if defined(MBEDTLS_DEPRECATED_WARNING) +#define MBEDTLS_DEPRECATED __attribute__((deprecated)) +#else +#define MBEDTLS_DEPRECATED +#endif /** * \brief This function computes the ECDSA signature of a * previously-hashed message, deterministic version. @@ -237,7 +231,10 @@ int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s, int mbedtls_ecdsa_sign_det( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s, const mbedtls_mpi *d, const unsigned char *buf, size_t blen, - mbedtls_md_type_t md_alg ); + mbedtls_md_type_t md_alg ) MBEDTLS_DEPRECATED; +#undef MBEDTLS_DEPRECATED +#endif /* MBEDTLS_DEPRECATED_REMOVED */ + /** * \brief This function computes the ECDSA signature of a * previously-hashed message, deterministic version. @@ -278,12 +275,11 @@ int mbedtls_ecdsa_sign_det( mbedtls_ecp_group *grp, mbedtls_mpi *r, * error code on failure. */ int mbedtls_ecdsa_sign_det_ext( mbedtls_ecp_group *grp, mbedtls_mpi *r, - mbedtls_mpi *s, const mbedtls_mpi *d, - const unsigned char *buf, size_t blen, - mbedtls_md_type_t md_alg, - int (*f_rng_blind)(void *, unsigned char *, - size_t), - void *p_rng_blind ); + mbedtls_mpi *s, const mbedtls_mpi *d, + const unsigned char *buf, size_t blen, + mbedtls_md_type_t md_alg, + int (*f_rng_blind)(void *, unsigned char *, size_t), + void *p_rng_blind ); #endif /* MBEDTLS_ECDSA_DETERMINISTIC */ /** @@ -362,7 +358,8 @@ int mbedtls_ecdsa_verify( mbedtls_ecp_group *grp, * the signature written. Must not be \c NULL. * \param f_rng The RNG function. This must not be \c NULL if * #MBEDTLS_ECDSA_DETERMINISTIC is unset. Otherwise, - * it is unused and may be set to \c NULL. + * it is used only for blinding and may be set to \c NULL, but + * doing so is DEPRECATED. * \param p_rng The RNG context to be passed to \p f_rng. This may be * \c NULL if \p f_rng is \c NULL or doesn't use a context. * diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ecjpake.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ecjpake.h index a9b68d00c61..891705d8c4f 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ecjpake.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ecjpake.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,27 +18,6 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_ECJPAKE_H #define MBEDTLS_ECJPAKE_H @@ -66,13 +39,13 @@ * also be use outside TLS. */ #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "ecp.h" -#include "md.h" +#include "mbedtls/ecp.h" +#include "mbedtls/md.h" #ifdef __cplusplus extern "C" { diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ecp.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ecp.h index e4a1ed81cf0..0924341e002 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ecp.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ecp.h @@ -16,13 +16,7 @@ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -35,56 +29,65 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_ECP_H #define MBEDTLS_ECP_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "bignum.h" +#include "mbedtls/bignum.h" /* * ECP error codes */ -#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA -0x4F80 /**< Bad input parameters to function. */ -#define MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL -0x4F00 /**< The buffer is too small to write to. */ -#define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE -0x4E80 /**< The requested feature is not available, for example, the requested curve is not supported. */ -#define MBEDTLS_ERR_ECP_VERIFY_FAILED -0x4E00 /**< The signature is not valid. */ -#define MBEDTLS_ERR_ECP_ALLOC_FAILED -0x4D80 /**< Memory allocation failed. */ -#define MBEDTLS_ERR_ECP_RANDOM_FAILED -0x4D00 /**< Generation of random value, such as ephemeral key, failed. */ -#define MBEDTLS_ERR_ECP_INVALID_KEY -0x4C80 /**< Invalid private or public key. */ -#define MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH -0x4C00 /**< The buffer contains a valid signature followed by more data. */ +/** Bad input parameters to function. */ +#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA -0x4F80 +/** The buffer is too small to write to. */ +#define MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL -0x4F00 +/** The requested feature is not available, for example, the requested curve is not supported. */ +#define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE -0x4E80 +/** The signature is not valid. */ +#define MBEDTLS_ERR_ECP_VERIFY_FAILED -0x4E00 +/** Memory allocation failed. */ +#define MBEDTLS_ERR_ECP_ALLOC_FAILED -0x4D80 +/** Generation of random value, such as ephemeral key, failed. */ +#define MBEDTLS_ERR_ECP_RANDOM_FAILED -0x4D00 +/** Invalid private or public key. */ +#define MBEDTLS_ERR_ECP_INVALID_KEY -0x4C80 +/** The buffer contains a valid signature followed by more data. */ +#define MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH -0x4C00 /* MBEDTLS_ERR_ECP_HW_ACCEL_FAILED is deprecated and should not be used. */ -#define MBEDTLS_ERR_ECP_HW_ACCEL_FAILED -0x4B80 /**< The ECP hardware accelerator failed. */ - -#define MBEDTLS_ERR_ECP_IN_PROGRESS -0x4B00 /**< Operation in progress, call again with the same parameters to continue. */ +/** The ECP hardware accelerator failed. */ +#define MBEDTLS_ERR_ECP_HW_ACCEL_FAILED -0x4B80 + +/** Operation in progress, call again with the same parameters to continue. */ +#define MBEDTLS_ERR_ECP_IN_PROGRESS -0x4B00 + +/* Flags indicating whether to include code that is specific to certain + * types of curves. These flags are for internal library use only. */ +#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) || \ + defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) || \ + defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) || \ + defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) || \ + defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) || \ + defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) || \ + defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) || \ + defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) || \ + defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) || \ + defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) || \ + defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) +#define MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED +#endif +#if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) || \ + defined(MBEDTLS_ECP_DP_CURVE448_ENABLED) +#define MBEDTLS_ECP_MONTGOMERY_ENABLED +#endif #ifdef __cplusplus extern "C" { @@ -99,6 +102,21 @@ extern "C" { * parameters. Therefore, only standardized domain parameters from trusted * sources should be used. See mbedtls_ecp_group_load(). */ +/* Note: when adding a new curve: + * - Add it at the end of this enum, otherwise you'll break the ABI by + * changing the numerical value for existing curves. + * - Increment MBEDTLS_ECP_DP_MAX below if needed. + * - Update the calculation of MBEDTLS_ECP_MAX_BITS_MIN below. + * - Add the corresponding MBEDTLS_ECP_DP_xxx_ENABLED macro definition to + * config.h. + * - List the curve as a dependency of MBEDTLS_ECP_C and + * MBEDTLS_ECDSA_C if supported in check_config.h. + * - Add the curve to the appropriate curve type macro + * MBEDTLS_ECP_yyy_ENABLED above. + * - Add the necessary definitions to ecp_curves.c. + * - Add the curve to the ecp_supported_curves array in ecp.c. + * - Add the curve to applicable profiles in x509_crt.c if applicable. + */ typedef enum { MBEDTLS_ECP_DP_NONE = 0, /*!< Curve not defined. */ @@ -124,6 +142,16 @@ typedef enum */ #define MBEDTLS_ECP_DP_MAX 12 +/* + * Curve types + */ +typedef enum +{ + MBEDTLS_ECP_TYPE_NONE = 0, + MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS, /* y^2 = x^3 + a x + b */ + MBEDTLS_ECP_TYPE_MONTGOMERY, /* y^2 = x^3 + a x^2 + x */ +} mbedtls_ecp_curve_type; + /** * Curve information, for use by other modules. */ @@ -268,11 +296,17 @@ mbedtls_ecp_group; #error "MBEDTLS_ECP_MAX_BITS is smaller than the largest supported curve" #endif -#else +#elif defined(MBEDTLS_ECP_C) /** * The maximum size of the groups, that is, of \c N and \c P. */ -#define MBEDTLS_ECP_MAX_BITS 521 /**< The maximum size of groups, in bits. */ +#define MBEDTLS_ECP_MAX_BITS MBEDTLS_ECP_MAX_BITS_MIN + +#else +/* MBEDTLS_ECP_MAX_BITS is not relevant without MBEDTLS_ECP_C, but set it + * to a nonzero value so that code that unconditionally allocates an array + * of a size based on it keeps working if built without ECC support. */ +#define MBEDTLS_ECP_MAX_BITS 1 #endif #define MBEDTLS_ECP_MAX_BYTES ( ( MBEDTLS_ECP_MAX_BITS + 7 ) / 8 ) @@ -281,7 +315,8 @@ mbedtls_ecp_group; #if !defined(MBEDTLS_ECP_WINDOW_SIZE) /* * Maximum "window" size used for point multiplication. - * Default: 6. + * Default: a point where higher memory usage yields disminishing performance + * returns. * Minimum value: 2. Maximum value: 7. * * Result is an array of at most ( 1 << ( MBEDTLS_ECP_WINDOW_SIZE - 1 ) ) @@ -298,7 +333,7 @@ mbedtls_ecp_group; * 224 475 475 453 398 342 * 192 640 640 633 587 476 */ -#define MBEDTLS_ECP_WINDOW_SIZE 6 /**< The maximum window size used. */ +#define MBEDTLS_ECP_WINDOW_SIZE 4 /**< The maximum window size used. */ #endif /* MBEDTLS_ECP_WINDOW_SIZE */ #if !defined(MBEDTLS_ECP_FIXED_POINT_OPTIM) @@ -482,10 +517,20 @@ void mbedtls_ecp_set_max_ops( unsigned max_ops ); int mbedtls_ecp_restart_is_enabled( void ); #endif /* MBEDTLS_ECP_RESTARTABLE */ +/* + * Get the type of a curve + */ +mbedtls_ecp_curve_type mbedtls_ecp_get_type( const mbedtls_ecp_group *grp ); + /** * \brief This function retrieves the information defined in - * mbedtls_ecp_curve_info() for all supported curves in order - * of preference. + * mbedtls_ecp_curve_info() for all supported curves. + * + * \note This function returns information about all curves + * supported by the library. Some curves may not be + * supported for all algorithms. Call mbedtls_ecdh_can_do() + * or mbedtls_ecdsa_can_do() to check if a curve is + * supported for ECDH or ECDSA. * * \return A statically allocated array. The last entry is 0. */ @@ -496,6 +541,12 @@ const mbedtls_ecp_curve_info *mbedtls_ecp_curve_list( void ); * identifiers of all supported curves in the order of * preference. * + * \note This function returns information about all curves + * supported by the library. Some curves may not be + * supported for all algorithms. Call mbedtls_ecdh_can_do() + * or mbedtls_ecdsa_can_do() to check if a curve is + * supported for ECDH or ECDSA. + * * \return A statically allocated array, * terminated with MBEDTLS_ECP_DP_NONE. */ @@ -691,6 +742,9 @@ int mbedtls_ecp_point_read_string( mbedtls_ecp_point *P, int radix, * \param P The point to export. This must be initialized. * \param format The point format. This must be either * #MBEDTLS_ECP_PF_COMPRESSED or #MBEDTLS_ECP_PF_UNCOMPRESSED. + * (For groups without these formats, this parameter is + * ignored. But it still has to be either of the above + * values.) * \param olen The address at which to store the length of * the output in Bytes. This must not be \c NULL. * \param buf The output buffer. This must be a writable buffer @@ -700,11 +754,14 @@ int mbedtls_ecp_point_read_string( mbedtls_ecp_point *P, int radix, * \return \c 0 on success. * \return #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL if the output buffer * is too small to hold the point. + * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the point format + * or the export for the given group is not implemented. * \return Another negative error code on other kinds of failure. */ -int mbedtls_ecp_point_write_binary( const mbedtls_ecp_group *grp, const mbedtls_ecp_point *P, - int format, size_t *olen, - unsigned char *buf, size_t buflen ); +int mbedtls_ecp_point_write_binary( const mbedtls_ecp_group *grp, + const mbedtls_ecp_point *P, + int format, size_t *olen, + unsigned char *buf, size_t buflen ); /** * \brief This function imports a point from unsigned binary data. @@ -725,8 +782,8 @@ int mbedtls_ecp_point_write_binary( const mbedtls_ecp_group *grp, const mbedtls_ * \return \c 0 on success. * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the input is invalid. * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure. - * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the point format - * is not implemented. + * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the import for the + * given group is not implemented. */ int mbedtls_ecp_point_read_binary( const mbedtls_ecp_group *grp, mbedtls_ecp_point *P, @@ -938,6 +995,7 @@ int mbedtls_ecp_mul_restartable( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, mbedtls_ecp_restart_ctx *rs_ctx ); +#if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED) /** * \brief This function performs multiplication and addition of two * points by integers: \p R = \p m * \p P + \p n * \p Q @@ -947,6 +1005,10 @@ int mbedtls_ecp_mul_restartable( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, * \note In contrast to mbedtls_ecp_mul(), this function does not * guarantee a constant execution flow and timing. * + * \note This function is only defined for short Weierstrass curves. + * It may not be included in builds without any short + * Weierstrass curve. + * * \param grp The ECP group to use. * This must be initialized and have group parameters * set, for example through mbedtls_ecp_group_load(). @@ -965,6 +1027,8 @@ int mbedtls_ecp_mul_restartable( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, * valid private keys, or \p P or \p Q are not valid public * keys. * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure. + * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if \p grp does not + * designate a short Weierstrass curve. * \return Another negative error code on other kinds of failure. */ int mbedtls_ecp_muladd( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, @@ -982,6 +1046,10 @@ int mbedtls_ecp_muladd( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, * but it can return early and restart according to the limit * set with \c mbedtls_ecp_set_max_ops() to reduce blocking. * + * \note This function is only defined for short Weierstrass curves. + * It may not be included in builds without any short + * Weierstrass curve. + * * \param grp The ECP group to use. * This must be initialized and have group parameters * set, for example through mbedtls_ecp_group_load(). @@ -1001,6 +1069,8 @@ int mbedtls_ecp_muladd( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, * valid private keys, or \p P or \p Q are not valid public * keys. * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure. + * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if \p grp does not + * designate a short Weierstrass curve. * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of * operations was reached: see \c mbedtls_ecp_set_max_ops(). * \return Another negative error code on other kinds of failure. @@ -1010,6 +1080,7 @@ int mbedtls_ecp_muladd_restartable( const mbedtls_mpi *m, const mbedtls_ecp_point *P, const mbedtls_mpi *n, const mbedtls_ecp_point *Q, mbedtls_ecp_restart_ctx *rs_ctx ); +#endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */ /** * \brief This function checks that a point is a valid public key @@ -1161,6 +1232,46 @@ int mbedtls_ecp_gen_key( mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); +/** + * \brief This function reads an elliptic curve private key. + * + * \param grp_id The ECP group identifier. + * \param key The destination key. + * \param buf The buffer containing the binary representation of the + * key. (Big endian integer for Weierstrass curves, byte + * string for Montgomery curves.) + * \param buflen The length of the buffer in bytes. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_ECP_INVALID_KEY error if the key is + * invalid. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed. + * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the operation for + * the group is not implemented. + * \return Another negative error code on different kinds of failure. + */ +int mbedtls_ecp_read_key( mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key, + const unsigned char *buf, size_t buflen ); + +/** + * \brief This function exports an elliptic curve private key. + * + * \param key The private key. + * \param buf The output buffer for containing the binary representation + * of the key. (Big endian integer for Weierstrass curves, byte + * string for Montgomery curves.) + * \param buflen The total length of the buffer in bytes. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL if the \p key + representation is larger than the available space in \p buf. + * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the operation for + * the group is not implemented. + * \return Another negative error code on different kinds of failure. + */ +int mbedtls_ecp_write_key( mbedtls_ecp_keypair *key, + unsigned char *buf, size_t buflen ); + /** * \brief This function checks that the keypair objects * \p pub and \p prv have the same group and the diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ecp_internal.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ecp_internal.h index 0047bd4ef91..6a47a8ff27e 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ecp_internal.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ecp_internal.h @@ -6,13 +6,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -25,27 +19,6 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ /* @@ -87,7 +60,7 @@ #define MBEDTLS_ECP_INTERNAL_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif @@ -130,7 +103,7 @@ int mbedtls_internal_ecp_init( const mbedtls_ecp_group *grp ); */ void mbedtls_internal_ecp_free( const mbedtls_ecp_group *grp ); -#if defined(ECP_SHORTWEIERSTRASS) +#if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED) #if defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT) /** @@ -270,9 +243,9 @@ int mbedtls_internal_ecp_normalize_jac( const mbedtls_ecp_group *grp, mbedtls_ecp_point *pt ); #endif -#endif /* ECP_SHORTWEIERSTRASS */ +#endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */ -#if defined(ECP_MONTGOMERY) +#if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED) #if defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT) int mbedtls_internal_ecp_double_add_mxz( const mbedtls_ecp_group *grp, @@ -316,7 +289,7 @@ int mbedtls_internal_ecp_normalize_mxz( const mbedtls_ecp_group *grp, mbedtls_ecp_point *P ); #endif -#endif /* ECP_MONTGOMERY */ +#endif /* MBEDTLS_ECP_MONTGOMERY_ENABLED */ #endif /* MBEDTLS_ECP_INTERNAL_ALT */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/entropy.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/entropy.h index 1d6e9b821bf..deb3c50300b 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/entropy.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/entropy.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,33 +18,12 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_ENTROPY_H #define MBEDTLS_ENTROPY_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif @@ -58,28 +31,33 @@ #include #if defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256) -#include "sha512.h" +#include "mbedtls/sha512.h" #define MBEDTLS_ENTROPY_SHA512_ACCUMULATOR #else #if defined(MBEDTLS_SHA256_C) #define MBEDTLS_ENTROPY_SHA256_ACCUMULATOR -#include "sha256.h" +#include "mbedtls/sha256.h" #endif #endif #if defined(MBEDTLS_THREADING_C) -#include "threading.h" +#include "mbedtls/threading.h" #endif #if defined(MBEDTLS_HAVEGE_C) -#include "havege.h" +#include "mbedtls/havege.h" #endif -#define MBEDTLS_ERR_ENTROPY_SOURCE_FAILED -0x003C /**< Critical entropy source failure. */ -#define MBEDTLS_ERR_ENTROPY_MAX_SOURCES -0x003E /**< No more sources can be added. */ -#define MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED -0x0040 /**< No sources have been added to poll. */ -#define MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE -0x003D /**< No strong sources have been added to poll. */ -#define MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR -0x003F /**< Read/write error in file. */ +/** Critical entropy source failure. */ +#define MBEDTLS_ERR_ENTROPY_SOURCE_FAILED -0x003C +/** No more sources can be added. */ +#define MBEDTLS_ERR_ENTROPY_MAX_SOURCES -0x003E +/** No sources have been added to poll. */ +#define MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED -0x0040 +/** No strong sources have been added to poll. */ +#define MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE -0x003D +/** Read/write error in file. */ +#define MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR -0x003F /** * \name SECTION: Module settings @@ -152,7 +130,7 @@ typedef struct mbedtls_entropy_context * -1 after free. */ #if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR) mbedtls_sha512_context accumulator; -#else +#elif defined(MBEDTLS_ENTROPY_SHA256_ACCUMULATOR) mbedtls_sha256_context accumulator; #endif int source_count; /* Number of entries used in source. */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/entropy_poll.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/entropy_poll.h index c348fe52d42..e1d7491aa21 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/entropy_poll.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/entropy_poll.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,33 +18,12 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_ENTROPY_POLL_H #define MBEDTLS_ENTROPY_POLL_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/error.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/error.h index fa8582a3914..50f25385080 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/error.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/error.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,39 +18,23 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_ERROR_H #define MBEDTLS_ERROR_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif #include +#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ + !defined(inline) && !defined(__cplusplus) +#define inline __inline +#endif + /** * Error code layout. * @@ -77,9 +55,10 @@ * For historical reasons, low-level error codes are divided in even and odd, * even codes were assigned first, and -1 is reserved for other errors. * - * Low-level module errors (0x0002-0x007E, 0x0003-0x007F) + * Low-level module errors (0x0002-0x007E, 0x0001-0x007F) * * Module Nr Codes assigned + * ERROR 2 0x006E 0x0001 * MPI 7 0x0002-0x0010 * GCM 3 0x0012-0x0014 0x0013-0x0013 * BLOWFISH 3 0x0016-0x0018 0x0017-0x0017 @@ -111,7 +90,7 @@ * CHACHA20 3 0x0051-0x0055 * POLY1305 3 0x0057-0x005B * CHACHAPOLY 2 0x0054-0x0056 - * PLATFORM 1 0x0070-0x0072 + * PLATFORM 2 0x0070-0x0072 * * High-level module nr (3 bits - 0x0...-0x7...) * Name ID Nr of Errors @@ -125,9 +104,9 @@ * ECP 4 10 (Started from top) * MD 5 5 * HKDF 5 1 (Started from top) - * SSL 5 1 (Started from 0x5E80) - * CIPHER 6 8 - * SSL 6 23 (Started from top) + * SSL 5 2 (Started from 0x5F00) + * CIPHER 6 8 (Started from 0x6080) + * SSL 6 24 (Started from top, plus 0x6000) * SSL 7 32 * * Module dependent error code (5 bits 0x.00.-0x.F8.) @@ -137,6 +116,59 @@ extern "C" { #endif +/** Generic error */ +#define MBEDTLS_ERR_ERROR_GENERIC_ERROR -0x0001 +/** This is a bug in the library */ +#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E + +/** + * \brief Combines a high-level and low-level error code together. + * + * Wrapper macro for mbedtls_error_add(). See that function for + * more details. + */ +#define MBEDTLS_ERROR_ADD( high, low ) \ + mbedtls_error_add( high, low, __FILE__, __LINE__ ) + +#if defined(MBEDTLS_TEST_HOOKS) +/** + * \brief Testing hook called before adding/combining two error codes together. + * Only used when invasive testing is enabled via MBEDTLS_TEST_HOOKS. + */ +extern void (*mbedtls_test_hook_error_add)( int, int, const char *, int ); +#endif + +/** + * \brief Combines a high-level and low-level error code together. + * + * This function can be called directly however it is usually + * called via the #MBEDTLS_ERROR_ADD macro. + * + * While a value of zero is not a negative error code, it is still an + * error code (that denotes success) and can be combined with both a + * negative error code or another value of zero. + * + * \note When invasive testing is enabled via #MBEDTLS_TEST_HOOKS, also try to + * call \link mbedtls_test_hook_error_add \endlink. + * + * \param high high-level error code. See error.h for more details. + * \param low low-level error code. See error.h for more details. + * \param file file where this error code addition occurred. + * \param line line where this error code addition occurred. + */ +static inline int mbedtls_error_add( int high, int low, + const char *file, int line ) +{ +#if defined(MBEDTLS_TEST_HOOKS) + if( *mbedtls_test_hook_error_add != NULL ) + ( *mbedtls_test_hook_error_add )( high, low, file, line ); +#endif + (void)file; + (void)line; + + return( high + low ); +} + /** * \brief Translate a mbed TLS error code into a string representation, * Result is truncated if necessary and always includes a terminating @@ -148,6 +180,36 @@ extern "C" { */ void mbedtls_strerror( int errnum, char *buffer, size_t buflen ); +/** + * \brief Translate the high-level part of an Mbed TLS error code into a string + * representation. + * + * This function returns a const pointer to an un-modifiable string. The caller + * must not try to modify the string. It is intended to be used mostly for + * logging purposes. + * + * \param error_code error code + * + * \return The string representation of the error code, or \c NULL if the error + * code is unknown. + */ +const char * mbedtls_high_level_strerr( int error_code ); + +/** + * \brief Translate the low-level part of an Mbed TLS error code into a string + * representation. + * + * This function returns a const pointer to an un-modifiable string. The caller + * must not try to modify the string. It is intended to be used mostly for + * logging purposes. + * + * \param error_code error code + * + * \return The string representation of the error code, or \c NULL if the error + * code is unknown. + */ +const char * mbedtls_low_level_strerr( int error_code ); + #ifdef __cplusplus } #endif diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/gcm.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/gcm.h index 1201fbd4f10..9723a17b65f 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/gcm.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/gcm.h @@ -13,13 +13,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -32,51 +26,33 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_GCM_H #define MBEDTLS_GCM_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "cipher.h" +#include "mbedtls/cipher.h" #include #define MBEDTLS_GCM_ENCRYPT 1 #define MBEDTLS_GCM_DECRYPT 0 -#define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012 /**< Authenticated decryption failed. */ +/** Authenticated decryption failed. */ +#define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012 /* MBEDTLS_ERR_GCM_HW_ACCEL_FAILED is deprecated and should not be used. */ -#define MBEDTLS_ERR_GCM_HW_ACCEL_FAILED -0x0013 /**< GCM hardware accelerator failed. */ +/** GCM hardware accelerator failed. */ +#define MBEDTLS_ERR_GCM_HW_ACCEL_FAILED -0x0013 -#define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014 /**< Bad input parameters to function. */ +/** Bad input parameters to function. */ +#define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014 #ifdef __cplusplus extern "C" { diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/havege.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/havege.h index e90839ddeb4..7d27039e8c7 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/havege.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/havege.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,38 +18,18 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_HAVEGE_H #define MBEDTLS_HAVEGE_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif #include +#include #define MBEDTLS_HAVEGE_COLLECT_SIZE 1024 @@ -68,9 +42,9 @@ extern "C" { */ typedef struct mbedtls_havege_state { - int PT1, PT2, offset[2]; - int pool[MBEDTLS_HAVEGE_COLLECT_SIZE]; - int WALK[8192]; + uint32_t PT1, PT2, offset[2]; + uint32_t pool[MBEDTLS_HAVEGE_COLLECT_SIZE]; + uint32_t WALK[8192]; } mbedtls_havege_state; diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/hkdf.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/hkdf.h index 07ffe83b23d..223004b8ede 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/hkdf.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/hkdf.h @@ -8,13 +8,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -27,44 +21,24 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_HKDF_H #define MBEDTLS_HKDF_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "md.h" +#include "mbedtls/md.h" /** * \name HKDF Error codes * \{ */ -#define MBEDTLS_ERR_HKDF_BAD_INPUT_DATA -0x5F80 /**< Bad input parameters to function. */ +/** Bad input parameters to function. */ +#define MBEDTLS_ERR_HKDF_BAD_INPUT_DATA -0x5F80 /* \} name */ #ifdef __cplusplus diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/hmac_drbg.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/hmac_drbg.h index 5718e187a9f..79132d4d910 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/hmac_drbg.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/hmac_drbg.h @@ -9,13 +9,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -28,50 +22,33 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_HMAC_DRBG_H #define MBEDTLS_HMAC_DRBG_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "md.h" +#include "mbedtls/md.h" #if defined(MBEDTLS_THREADING_C) -#include "threading.h" +#include "mbedtls/threading.h" #endif /* * Error codes */ -#define MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG -0x0003 /**< Too many random requested in single call. */ -#define MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG -0x0005 /**< Input too large (Entropy + additional). */ -#define MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR -0x0007 /**< Read/write error in file. */ -#define MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED -0x0009 /**< The entropy source failed. */ +/** Too many random requested in single call. */ +#define MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG -0x0003 +/** Input too large (Entropy + additional). */ +#define MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG -0x0005 +/** Read/write error in file. */ +#define MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR -0x0007 +/** The entropy source failed. */ +#define MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED -0x0009 /** * \name SECTION: Module settings diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/md.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/md.h index 2ba8d9e7a91..84fafd2ac77 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/md.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/md.h @@ -7,13 +7,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -26,27 +20,6 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_MD_H @@ -55,18 +28,24 @@ #include #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif +#include "mbedtls/platform_util.h" -#define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080 /**< The selected feature is not available. */ -#define MBEDTLS_ERR_MD_BAD_INPUT_DATA -0x5100 /**< Bad input parameters to function. */ -#define MBEDTLS_ERR_MD_ALLOC_FAILED -0x5180 /**< Failed to allocate memory. */ -#define MBEDTLS_ERR_MD_FILE_IO_ERROR -0x5200 /**< Opening or reading of file failed. */ +/** The selected feature is not available. */ +#define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080 +/** Bad input parameters to function. */ +#define MBEDTLS_ERR_MD_BAD_INPUT_DATA -0x5100 +/** Failed to allocate memory. */ +#define MBEDTLS_ERR_MD_ALLOC_FAILED -0x5180 +/** Opening or reading of file failed. */ +#define MBEDTLS_ERR_MD_FILE_IO_ERROR -0x5200 /* MBEDTLS_ERR_MD_HW_ACCEL_FAILED is deprecated and should not be used. */ -#define MBEDTLS_ERR_MD_HW_ACCEL_FAILED -0x5280 /**< MD hardware accelerator failed. */ +/** MD hardware accelerator failed. */ +#define MBEDTLS_ERR_MD_HW_ACCEL_FAILED -0x5280 #ifdef __cplusplus extern "C" { @@ -99,6 +78,12 @@ typedef enum { #define MBEDTLS_MD_MAX_SIZE 32 /* longest known is SHA256 or less */ #endif +#if defined(MBEDTLS_SHA512_C) +#define MBEDTLS_MD_MAX_BLOCK_SIZE 128 +#else +#define MBEDTLS_MD_MAX_BLOCK_SIZE 64 +#endif + /** * Opaque struct defined in md_internal.h. */ @@ -226,6 +211,7 @@ int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_ * failure. * \return #MBEDTLS_ERR_MD_ALLOC_FAILED on memory-allocation failure. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac ); /** @@ -247,6 +233,7 @@ int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_inf * \return \c 0 on success. * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification failure. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_md_clone( mbedtls_md_context_t *dst, const mbedtls_md_context_t *src ); @@ -296,6 +283,7 @@ const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info ); * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification * failure. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_md_starts( mbedtls_md_context_t *ctx ); /** @@ -314,6 +302,7 @@ int mbedtls_md_starts( mbedtls_md_context_t *ctx ); * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification * failure. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen ); /** @@ -334,6 +323,7 @@ int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, si * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification * failure. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output ); /** @@ -354,6 +344,7 @@ int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output ); * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification * failure. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen, unsigned char *output ); @@ -375,6 +366,7 @@ int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, si * the file pointed by \p path. * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA if \p md_info was NULL. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path, unsigned char *output ); #endif /* MBEDTLS_FS_IO */ @@ -397,6 +389,7 @@ int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path, * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification * failure. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key, size_t keylen ); @@ -419,6 +412,7 @@ int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key, * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification * failure. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen ); @@ -440,6 +434,7 @@ int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *inpu * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification * failure. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output); /** @@ -457,6 +452,7 @@ int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output); * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification * failure. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx ); /** @@ -481,11 +477,13 @@ int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx ); * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification * failure. */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char *output ); /* Internal use */ +MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data ); #ifdef __cplusplus diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/md2.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/md2.h index 9607df66baf..7f3d5cf446c 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/md2.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/md2.h @@ -9,13 +9,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -29,33 +23,12 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** - * */ #ifndef MBEDTLS_MD2_H #define MBEDTLS_MD2_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif @@ -63,7 +36,8 @@ #include /* MBEDTLS_ERR_MD2_HW_ACCEL_FAILED is deprecated and should not be used. */ -#define MBEDTLS_ERR_MD2_HW_ACCEL_FAILED -0x002B /**< MD2 hardware accelerator failed */ +/** MD2 hardware accelerator failed */ +#define MBEDTLS_ERR_MD2_HW_ACCEL_FAILED -0x002B #ifdef __cplusplus extern "C" { diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/md4.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/md4.h index 6ceaf7a2f69..0238c6723a6 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/md4.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/md4.h @@ -9,13 +9,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -29,33 +23,12 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** - * */ #ifndef MBEDTLS_MD4_H #define MBEDTLS_MD4_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif @@ -64,7 +37,8 @@ #include /* MBEDTLS_ERR_MD4_HW_ACCEL_FAILED is deprecated and should not be used. */ -#define MBEDTLS_ERR_MD4_HW_ACCEL_FAILED -0x002D /**< MD4 hardware accelerator failed */ +/** MD4 hardware accelerator failed */ +#define MBEDTLS_ERR_MD4_HW_ACCEL_FAILED -0x002D #ifdef __cplusplus extern "C" { diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/md5.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/md5.h index b9d0ca929a0..73e4dd2c2a7 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/md5.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/md5.h @@ -9,13 +9,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -28,33 +22,12 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_MD5_H #define MBEDTLS_MD5_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif @@ -63,7 +36,8 @@ #include /* MBEDTLS_ERR_MD5_HW_ACCEL_FAILED is deprecated and should not be used. */ -#define MBEDTLS_ERR_MD5_HW_ACCEL_FAILED -0x002F /**< MD5 hardware accelerator failed */ +/** MD5 hardware accelerator failed */ +#define MBEDTLS_ERR_MD5_HW_ACCEL_FAILED -0x002F #ifdef __cplusplus extern "C" { diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/md_internal.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/md_internal.h index 847f50aa0a8..f33cdf6086d 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/md_internal.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/md_internal.h @@ -9,13 +9,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -28,38 +22,17 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_MD_WRAP_H #define MBEDTLS_MD_WRAP_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "md.h" +#include "mbedtls/md.h" #ifdef __cplusplus extern "C" { @@ -71,42 +44,17 @@ extern "C" { */ struct mbedtls_md_info_t { - /** Digest identifier */ - mbedtls_md_type_t type; - /** Name of the message digest */ const char * name; + /** Digest identifier */ + mbedtls_md_type_t type; + /** Output length of the digest function in bytes */ - int size; + unsigned char size; /** Block length of the digest function in bytes */ - int block_size; - - /** Digest initialisation function */ - int (*starts_func)( void *ctx ); - - /** Digest update function */ - int (*update_func)( void *ctx, const unsigned char *input, size_t ilen ); - - /** Digest finalisation function */ - int (*finish_func)( void *ctx, unsigned char *output ); - - /** Generic digest function */ - int (*digest_func)( const unsigned char *input, size_t ilen, - unsigned char *output ); - - /** Allocate a new context */ - void * (*ctx_alloc_func)( void ); - - /** Free the given context */ - void (*ctx_free_func)( void *ctx ); - - /** Clone state from a context */ - void (*clone_func)( void *dst, const void *src ); - - /** Internal use only */ - int (*process_func)( void *ctx, const unsigned char *input ); + unsigned char block_size; }; #if defined(MBEDTLS_MD2_C) @@ -129,7 +77,9 @@ extern const mbedtls_md_info_t mbedtls_sha224_info; extern const mbedtls_md_info_t mbedtls_sha256_info; #endif #if defined(MBEDTLS_SHA512_C) +#if !defined(MBEDTLS_SHA512_NO_SHA384) extern const mbedtls_md_info_t mbedtls_sha384_info; +#endif extern const mbedtls_md_info_t mbedtls_sha512_info; #endif diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/memory_buffer_alloc.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/memory_buffer_alloc.h index 89c06174957..233977252a3 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/memory_buffer_alloc.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/memory_buffer_alloc.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,33 +18,12 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_MEMORY_BUFFER_ALLOC_H #define MBEDTLS_MEMORY_BUFFER_ALLOC_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/net.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/net.h index 6c7a49d3bdf..66921887da0 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/net.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/net.h @@ -7,13 +7,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -26,36 +20,15 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif #if !defined(MBEDTLS_DEPRECATED_REMOVED) -#include "net_sockets.h" +#include "mbedtls/net_sockets.h" #if defined(MBEDTLS_DEPRECATED_WARNING) #warning "Deprecated header file: Superseded by mbedtls/net_sockets.h" #endif /* MBEDTLS_DEPRECATED_WARNING */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/net_sockets.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/net_sockets.h index c6e1a0270e8..ceb7d5f6527 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/net_sockets.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/net_sockets.h @@ -21,13 +21,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -40,55 +34,47 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_NET_SOCKETS_H #define MBEDTLS_NET_SOCKETS_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "ssl.h" +#include "mbedtls/ssl.h" #include #include -#define MBEDTLS_ERR_NET_SOCKET_FAILED -0x0042 /**< Failed to open a socket. */ -#define MBEDTLS_ERR_NET_CONNECT_FAILED -0x0044 /**< The connection to the given server / port failed. */ -#define MBEDTLS_ERR_NET_BIND_FAILED -0x0046 /**< Binding of the socket failed. */ -#define MBEDTLS_ERR_NET_LISTEN_FAILED -0x0048 /**< Could not listen on the socket. */ -#define MBEDTLS_ERR_NET_ACCEPT_FAILED -0x004A /**< Could not accept the incoming connection. */ -#define MBEDTLS_ERR_NET_RECV_FAILED -0x004C /**< Reading information from the socket failed. */ -#define MBEDTLS_ERR_NET_SEND_FAILED -0x004E /**< Sending information through the socket failed. */ -#define MBEDTLS_ERR_NET_CONN_RESET -0x0050 /**< Connection was reset by peer. */ -#define MBEDTLS_ERR_NET_UNKNOWN_HOST -0x0052 /**< Failed to get an IP address for the given hostname. */ -#define MBEDTLS_ERR_NET_BUFFER_TOO_SMALL -0x0043 /**< Buffer is too small to hold the data. */ -#define MBEDTLS_ERR_NET_INVALID_CONTEXT -0x0045 /**< The context is invalid, eg because it was free()ed. */ -#define MBEDTLS_ERR_NET_POLL_FAILED -0x0047 /**< Polling the net context failed. */ -#define MBEDTLS_ERR_NET_BAD_INPUT_DATA -0x0049 /**< Input invalid. */ +/** Failed to open a socket. */ +#define MBEDTLS_ERR_NET_SOCKET_FAILED -0x0042 +/** The connection to the given server / port failed. */ +#define MBEDTLS_ERR_NET_CONNECT_FAILED -0x0044 +/** Binding of the socket failed. */ +#define MBEDTLS_ERR_NET_BIND_FAILED -0x0046 +/** Could not listen on the socket. */ +#define MBEDTLS_ERR_NET_LISTEN_FAILED -0x0048 +/** Could not accept the incoming connection. */ +#define MBEDTLS_ERR_NET_ACCEPT_FAILED -0x004A +/** Reading information from the socket failed. */ +#define MBEDTLS_ERR_NET_RECV_FAILED -0x004C +/** Sending information through the socket failed. */ +#define MBEDTLS_ERR_NET_SEND_FAILED -0x004E +/** Connection was reset by peer. */ +#define MBEDTLS_ERR_NET_CONN_RESET -0x0050 +/** Failed to get an IP address for the given hostname. */ +#define MBEDTLS_ERR_NET_UNKNOWN_HOST -0x0052 +/** Buffer is too small to hold the data. */ +#define MBEDTLS_ERR_NET_BUFFER_TOO_SMALL -0x0043 +/** The context is invalid, eg because it was free()ed. */ +#define MBEDTLS_ERR_NET_INVALID_CONTEXT -0x0045 +/** Polling the net context failed. */ +#define MBEDTLS_ERR_NET_POLL_FAILED -0x0047 +/** Input invalid. */ +#define MBEDTLS_ERR_NET_BAD_INPUT_DATA -0x0049 #define MBEDTLS_NET_LISTEN_BACKLOG 10 /**< The backlog that listen() should use. */ @@ -294,6 +280,13 @@ int mbedtls_net_send( void *ctx, const unsigned char *buf, size_t len ); int mbedtls_net_recv_timeout( void *ctx, unsigned char *buf, size_t len, uint32_t timeout ); +/** + * \brief Closes down the connection and free associated data + * + * \param ctx The context to close + */ +void mbedtls_net_close( mbedtls_net_context *ctx ); + /** * \brief Gracefully shutdown the connection and free associated data * diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/nist_kw.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/nist_kw.h index 94356569942..7f3e64a525d 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/nist_kw.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/nist_kw.h @@ -17,13 +17,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -36,39 +30,18 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_NIST_KW_H #define MBEDTLS_NIST_KW_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "cipher.h" +#include "mbedtls/cipher.h" #ifdef __cplusplus extern "C" { diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/oid.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/oid.h index 4a7e3b4b3fd..1c39186a491 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/oid.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/oid.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,56 +18,55 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_OID_H #define MBEDTLS_OID_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "asn1.h" -#include "pk.h" +#include "mbedtls/asn1.h" +#include "mbedtls/pk.h" #include #if defined(MBEDTLS_CIPHER_C) -#include "cipher.h" +#include "mbedtls/cipher.h" #endif #if defined(MBEDTLS_MD_C) -#include "md.h" +#include "mbedtls/md.h" #endif -#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C) -#include "x509.h" -#endif +/** OID is not found. */ +#define MBEDTLS_ERR_OID_NOT_FOUND -0x002E +/** output buffer is too small */ +#define MBEDTLS_ERR_OID_BUF_TOO_SMALL -0x000B -#define MBEDTLS_ERR_OID_NOT_FOUND -0x002E /**< OID is not found. */ -#define MBEDTLS_ERR_OID_BUF_TOO_SMALL -0x000B /**< output buffer is too small */ +/* This is for the benefit of X.509, but defined here in order to avoid + * having a "backwards" include of x.509.h here */ +/* + * X.509 extension types (internal, arbitrary values for bitsets) + */ +#define MBEDTLS_OID_X509_EXT_AUTHORITY_KEY_IDENTIFIER (1 << 0) +#define MBEDTLS_OID_X509_EXT_SUBJECT_KEY_IDENTIFIER (1 << 1) +#define MBEDTLS_OID_X509_EXT_KEY_USAGE (1 << 2) +#define MBEDTLS_OID_X509_EXT_CERTIFICATE_POLICIES (1 << 3) +#define MBEDTLS_OID_X509_EXT_POLICY_MAPPINGS (1 << 4) +#define MBEDTLS_OID_X509_EXT_SUBJECT_ALT_NAME (1 << 5) +#define MBEDTLS_OID_X509_EXT_ISSUER_ALT_NAME (1 << 6) +#define MBEDTLS_OID_X509_EXT_SUBJECT_DIRECTORY_ATTRS (1 << 7) +#define MBEDTLS_OID_X509_EXT_BASIC_CONSTRAINTS (1 << 8) +#define MBEDTLS_OID_X509_EXT_NAME_CONSTRAINTS (1 << 9) +#define MBEDTLS_OID_X509_EXT_POLICY_CONSTRAINTS (1 << 10) +#define MBEDTLS_OID_X509_EXT_EXTENDED_KEY_USAGE (1 << 11) +#define MBEDTLS_OID_X509_EXT_CRL_DISTRIBUTION_POINTS (1 << 12) +#define MBEDTLS_OID_X509_EXT_INIHIBIT_ANYPOLICY (1 << 13) +#define MBEDTLS_OID_X509_EXT_FRESHEST_CRL (1 << 14) +#define MBEDTLS_OID_X509_EXT_NS_CERT_TYPE (1 << 16) /* * Top level OID tuples @@ -129,7 +122,8 @@ * { iso(1) identified-organization(3) dod(6) internet(1) * security(5) mechanisms(5) pkix(7) } */ -#define MBEDTLS_OID_PKIX MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_ORG_DOD "\x01\x05\x05\x07" +#define MBEDTLS_OID_INTERNET MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_ORG_DOD "\x01" +#define MBEDTLS_OID_PKIX MBEDTLS_OID_INTERNET "\x05\x05\x07" /* * Arc for standard naming attributes @@ -174,6 +168,11 @@ #define MBEDTLS_OID_INIHIBIT_ANYPOLICY MBEDTLS_OID_ID_CE "\x36" /**< id-ce-inhibitAnyPolicy OBJECT IDENTIFIER ::= { id-ce 54 } */ #define MBEDTLS_OID_FRESHEST_CRL MBEDTLS_OID_ID_CE "\x2E" /**< id-ce-freshestCRL OBJECT IDENTIFIER ::= { id-ce 46 } */ +/* + * Certificate policies + */ +#define MBEDTLS_OID_ANY_POLICY MBEDTLS_OID_CERTIFICATE_POLICIES "\x00" /**< anyPolicy OBJECT IDENTIFIER ::= { id-ce-certificatePolicies 0 } */ + /* * Netscape certificate extensions */ @@ -208,6 +207,16 @@ #define MBEDTLS_OID_TIME_STAMPING MBEDTLS_OID_KP "\x08" /**< id-kp-timeStamping OBJECT IDENTIFIER ::= { id-kp 8 } */ #define MBEDTLS_OID_OCSP_SIGNING MBEDTLS_OID_KP "\x09" /**< id-kp-OCSPSigning OBJECT IDENTIFIER ::= { id-kp 9 } */ +/** + * Wi-SUN Alliance Field Area Network + * { iso(1) identified-organization(3) dod(6) internet(1) + * private(4) enterprise(1) WiSUN(45605) FieldAreaNetwork(1) } + */ +#define MBEDTLS_OID_WISUN_FAN MBEDTLS_OID_INTERNET "\x04\x01\x82\xe4\x25\x01" + +#define MBEDTLS_OID_ON MBEDTLS_OID_PKIX "\x08" /**< id-on OBJECT IDENTIFIER ::= { id-pkix 8 } */ +#define MBEDTLS_OID_ON_HW_MODULE_NAME MBEDTLS_OID_ON "\x04" /**< id-on-hardwareModuleName OBJECT IDENTIFIER ::= { id-on 4 } */ + /* * PKCS definition OIDs */ @@ -253,6 +262,8 @@ #define MBEDTLS_OID_DIGEST_ALG_SHA512 MBEDTLS_OID_NIST_ALG "\x02\x03" /**< id-mbedtls_sha512 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistalgorithm(4) hashalgs(2) 3 } */ +#define MBEDTLS_OID_DIGEST_ALG_RIPEMD160 MBEDTLS_OID_TELETRUST "\x03\x02\x01" /**< id-ripemd160 OBJECT IDENTIFIER :: { iso(1) identified-organization(3) teletrust(36) algorithm(3) hashAlgorithm(2) ripemd160(1) } */ + #define MBEDTLS_OID_HMAC_SHA1 MBEDTLS_OID_RSA_COMPANY "\x02\x07" /**< id-hmacWithSHA1 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 7 } */ #define MBEDTLS_OID_HMAC_SHA224 MBEDTLS_OID_RSA_COMPANY "\x02\x08" /**< id-hmacWithSHA224 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 8 } */ @@ -449,7 +460,6 @@ typedef struct mbedtls_oid_descriptor_t */ int mbedtls_oid_get_numeric_string( char *buf, size_t size, const mbedtls_asn1_buf *oid ); -#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C) /** * \brief Translate an X.509 extension OID into local values * @@ -459,7 +469,6 @@ int mbedtls_oid_get_numeric_string( char *buf, size_t size, const mbedtls_asn1_b * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND */ int mbedtls_oid_get_x509_ext_type( const mbedtls_asn1_buf *oid, int *ext_type ); -#endif /** * \brief Translate an X.509 attribute type OID into the short name @@ -585,6 +594,16 @@ int mbedtls_oid_get_md_hmac( const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_ */ int mbedtls_oid_get_extended_key_usage( const mbedtls_asn1_buf *oid, const char **desc ); +/** + * \brief Translate certificate policies OID into description + * + * \param oid OID to use + * \param desc place to store string pointer + * + * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND + */ +int mbedtls_oid_get_certificate_policies( const mbedtls_asn1_buf *oid, const char **desc ); + /** * \brief Translate md_type into hash algorithm OID * diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/padlock.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/padlock.h index 0e4a6bbf69f..624d02dff55 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/padlock.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/padlock.h @@ -9,13 +9,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -28,40 +22,20 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_PADLOCK_H #define MBEDTLS_PADLOCK_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "aes.h" +#include "mbedtls/aes.h" -#define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */ +/** Input data should be aligned. */ +#define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 #if defined(__has_feature) #if __has_feature(address_sanitizer) diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/pem.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/pem.h index c9df7ca6e86..dfb4ff218e6 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/pem.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/pem.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,33 +18,12 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_PEM_H #define MBEDTLS_PEM_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif @@ -63,15 +36,24 @@ * PEM data. * \{ */ -#define MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT -0x1080 /**< No PEM header or footer found. */ -#define MBEDTLS_ERR_PEM_INVALID_DATA -0x1100 /**< PEM string is not as expected. */ -#define MBEDTLS_ERR_PEM_ALLOC_FAILED -0x1180 /**< Failed to allocate memory. */ -#define MBEDTLS_ERR_PEM_INVALID_ENC_IV -0x1200 /**< RSA IV is not in hex-format. */ -#define MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG -0x1280 /**< Unsupported key encryption algorithm. */ -#define MBEDTLS_ERR_PEM_PASSWORD_REQUIRED -0x1300 /**< Private key password can't be empty. */ -#define MBEDTLS_ERR_PEM_PASSWORD_MISMATCH -0x1380 /**< Given private key password does not allow for correct decryption. */ -#define MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE -0x1400 /**< Unavailable feature, e.g. hashing/encryption combination. */ -#define MBEDTLS_ERR_PEM_BAD_INPUT_DATA -0x1480 /**< Bad input parameters to function. */ +/** No PEM header or footer found. */ +#define MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT -0x1080 +/** PEM string is not as expected. */ +#define MBEDTLS_ERR_PEM_INVALID_DATA -0x1100 +/** Failed to allocate memory. */ +#define MBEDTLS_ERR_PEM_ALLOC_FAILED -0x1180 +/** RSA IV is not in hex-format. */ +#define MBEDTLS_ERR_PEM_INVALID_ENC_IV -0x1200 +/** Unsupported key encryption algorithm. */ +#define MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG -0x1280 +/** Private key password can't be empty. */ +#define MBEDTLS_ERR_PEM_PASSWORD_REQUIRED -0x1300 +/** Given private key password does not allow for correct decryption. */ +#define MBEDTLS_ERR_PEM_PASSWORD_MISMATCH -0x1380 +/** Unavailable feature, e.g. hashing/encryption combination. */ +#define MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE -0x1400 +/** Bad input parameters to function. */ +#define MBEDTLS_ERR_PEM_BAD_INPUT_DATA -0x1480 /* \} name */ #ifdef __cplusplus diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/pk.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/pk.h index 20d51d4f38c..8f2abf2a608 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/pk.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/pk.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,50 +18,33 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_PK_H #define MBEDTLS_PK_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "md.h" +#include "mbedtls/md.h" #if defined(MBEDTLS_RSA_C) -#include "rsa.h" +#include "mbedtls/rsa.h" #endif #if defined(MBEDTLS_ECP_C) -#include "ecp.h" +#include "mbedtls/ecp.h" #endif #if defined(MBEDTLS_ECDSA_C) -#include "ecdsa.h" +#include "mbedtls/ecdsa.h" +#endif + +#if defined(MBEDTLS_USE_PSA_CRYPTO) +#include "psa/crypto.h" #endif #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ @@ -75,23 +52,38 @@ #define inline __inline #endif -#define MBEDTLS_ERR_PK_ALLOC_FAILED -0x3F80 /**< Memory allocation failed. */ -#define MBEDTLS_ERR_PK_TYPE_MISMATCH -0x3F00 /**< Type mismatch, eg attempt to encrypt with an ECDSA key */ -#define MBEDTLS_ERR_PK_BAD_INPUT_DATA -0x3E80 /**< Bad input parameters to function. */ -#define MBEDTLS_ERR_PK_FILE_IO_ERROR -0x3E00 /**< Read/write of file failed. */ -#define MBEDTLS_ERR_PK_KEY_INVALID_VERSION -0x3D80 /**< Unsupported key version */ -#define MBEDTLS_ERR_PK_KEY_INVALID_FORMAT -0x3D00 /**< Invalid key tag or value. */ -#define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG -0x3C80 /**< Key algorithm is unsupported (only RSA and EC are supported). */ -#define MBEDTLS_ERR_PK_PASSWORD_REQUIRED -0x3C00 /**< Private key password can't be empty. */ -#define MBEDTLS_ERR_PK_PASSWORD_MISMATCH -0x3B80 /**< Given private key password does not allow for correct decryption. */ -#define MBEDTLS_ERR_PK_INVALID_PUBKEY -0x3B00 /**< The pubkey tag or value is invalid (only RSA and EC are supported). */ -#define MBEDTLS_ERR_PK_INVALID_ALG -0x3A80 /**< The algorithm tag or value is invalid. */ -#define MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE -0x3A00 /**< Elliptic curve is unsupported (only NIST curves are supported). */ -#define MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE -0x3980 /**< Unavailable feature, e.g. RSA disabled for RSA key. */ -#define MBEDTLS_ERR_PK_SIG_LEN_MISMATCH -0x3900 /**< The buffer contains a valid signature followed by more data. */ +/** Memory allocation failed. */ +#define MBEDTLS_ERR_PK_ALLOC_FAILED -0x3F80 +/** Type mismatch, eg attempt to encrypt with an ECDSA key */ +#define MBEDTLS_ERR_PK_TYPE_MISMATCH -0x3F00 +/** Bad input parameters to function. */ +#define MBEDTLS_ERR_PK_BAD_INPUT_DATA -0x3E80 +/** Read/write of file failed. */ +#define MBEDTLS_ERR_PK_FILE_IO_ERROR -0x3E00 +/** Unsupported key version */ +#define MBEDTLS_ERR_PK_KEY_INVALID_VERSION -0x3D80 +/** Invalid key tag or value. */ +#define MBEDTLS_ERR_PK_KEY_INVALID_FORMAT -0x3D00 +/** Key algorithm is unsupported (only RSA and EC are supported). */ +#define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG -0x3C80 +/** Private key password can't be empty. */ +#define MBEDTLS_ERR_PK_PASSWORD_REQUIRED -0x3C00 +/** Given private key password does not allow for correct decryption. */ +#define MBEDTLS_ERR_PK_PASSWORD_MISMATCH -0x3B80 +/** The pubkey tag or value is invalid (only RSA and EC are supported). */ +#define MBEDTLS_ERR_PK_INVALID_PUBKEY -0x3B00 +/** The algorithm tag or value is invalid. */ +#define MBEDTLS_ERR_PK_INVALID_ALG -0x3A80 +/** Elliptic curve is unsupported (only NIST curves are supported). */ +#define MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE -0x3A00 +/** Unavailable feature, e.g. RSA disabled for RSA key. */ +#define MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE -0x3980 +/** The buffer contains a valid signature followed by more data. */ +#define MBEDTLS_ERR_PK_SIG_LEN_MISMATCH -0x3900 /* MBEDTLS_ERR_PK_HW_ACCEL_FAILED is deprecated and should not be used. */ -#define MBEDTLS_ERR_PK_HW_ACCEL_FAILED -0x3880 /**< PK hardware accelerator failed. */ +/** PK hardware accelerator failed. */ +#define MBEDTLS_ERR_PK_HW_ACCEL_FAILED -0x3880 #ifdef __cplusplus extern "C" { @@ -108,6 +100,7 @@ typedef enum { MBEDTLS_PK_ECDSA, MBEDTLS_PK_RSA_ALT, MBEDTLS_PK_RSASSA_PSS, + MBEDTLS_PK_OPAQUE, } mbedtls_pk_type_t; /** @@ -121,6 +114,58 @@ typedef struct mbedtls_pk_rsassa_pss_options } mbedtls_pk_rsassa_pss_options; +/** + * \brief Maximum size of a signature made by mbedtls_pk_sign(). + */ +/* We need to set MBEDTLS_PK_SIGNATURE_MAX_SIZE to the maximum signature + * size among the supported signature types. Do it by starting at 0, + * then incrementally increasing to be large enough for each supported + * signature mechanism. + * + * The resulting value can be 0, for example if MBEDTLS_ECDH_C is enabled + * (which allows the pk module to be included) but neither MBEDTLS_ECDSA_C + * nor MBEDTLS_RSA_C nor any opaque signature mechanism (PSA or RSA_ALT). + */ +#define MBEDTLS_PK_SIGNATURE_MAX_SIZE 0 + +#if ( defined(MBEDTLS_RSA_C) || defined(MBEDTLS_PK_RSA_ALT_SUPPORT) ) && \ + MBEDTLS_MPI_MAX_SIZE > MBEDTLS_PK_SIGNATURE_MAX_SIZE +/* For RSA, the signature can be as large as the bignum module allows. + * For RSA_ALT, the signature size is not necessarily tied to what the + * bignum module can do, but in the absence of any specific setting, + * we use that (rsa_alt_sign_wrap in pk_wrap will check). */ +#undef MBEDTLS_PK_SIGNATURE_MAX_SIZE +#define MBEDTLS_PK_SIGNATURE_MAX_SIZE MBEDTLS_MPI_MAX_SIZE +#endif + +#if defined(MBEDTLS_ECDSA_C) && \ + MBEDTLS_ECDSA_MAX_LEN > MBEDTLS_PK_SIGNATURE_MAX_SIZE +/* For ECDSA, the ecdsa module exports a constant for the maximum + * signature size. */ +#undef MBEDTLS_PK_SIGNATURE_MAX_SIZE +#define MBEDTLS_PK_SIGNATURE_MAX_SIZE MBEDTLS_ECDSA_MAX_LEN +#endif + +#if defined(MBEDTLS_USE_PSA_CRYPTO) +#if PSA_SIGNATURE_MAX_SIZE > MBEDTLS_PK_SIGNATURE_MAX_SIZE +/* PSA_SIGNATURE_MAX_SIZE is the maximum size of a signature made + * through the PSA API in the PSA representation. */ +#undef MBEDTLS_PK_SIGNATURE_MAX_SIZE +#define MBEDTLS_PK_SIGNATURE_MAX_SIZE PSA_SIGNATURE_MAX_SIZE +#endif + +#if PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE + 11 > MBEDTLS_PK_SIGNATURE_MAX_SIZE +/* The Mbed TLS representation is different for ECDSA signatures: + * PSA uses the raw concatenation of r and s, + * whereas Mbed TLS uses the ASN.1 representation (SEQUENCE of two INTEGERs). + * Add the overhead of ASN.1: up to (1+2) + 2 * (1+2+1) for the + * types, lengths (represented by up to 2 bytes), and potential leading + * zeros of the INTEGERs and the SEQUENCE. */ +#undef MBEDTLS_PK_SIGNATURE_MAX_SIZE +#define MBEDTLS_PK_SIGNATURE_MAX_SIZE ( PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE + 11 ) +#endif +#endif /* defined(MBEDTLS_USE_PSA_CRYPTO) */ + /** * \brief Types for interfacing with the debug module */ @@ -234,6 +279,11 @@ void mbedtls_pk_init( mbedtls_pk_context *ctx ); * * \param ctx The context to clear. It must have been initialized. * If this is \c NULL, this function does nothing. + * + * \note For contexts that have been set up with + * mbedtls_pk_setup_opaque(), this does not free the underlying + * PSA key and you still need to call psa_destroy_key() + * independently if you want to destroy that key. */ void mbedtls_pk_free( mbedtls_pk_context *ctx ); @@ -272,6 +322,39 @@ void mbedtls_pk_restart_free( mbedtls_pk_restart_ctx *ctx ); */ int mbedtls_pk_setup( mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info ); +#if defined(MBEDTLS_USE_PSA_CRYPTO) +/** + * \brief Initialize a PK context to wrap a PSA key. + * + * \note This function replaces mbedtls_pk_setup() for contexts + * that wrap a (possibly opaque) PSA key instead of + * storing and manipulating the key material directly. + * + * \param ctx The context to initialize. It must be empty (type NONE). + * \param key The PSA key to wrap, which must hold an ECC key pair + * (see notes below). + * + * \note The wrapped key must remain valid as long as the + * wrapping PK context is in use, that is at least between + * the point this function is called and the point + * mbedtls_pk_free() is called on this context. The wrapped + * key might then be independently used or destroyed. + * + * \note This function is currently only available for ECC key + * pairs (that is, ECC keys containing private key material). + * Support for other key types may be added later. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_PK_BAD_INPUT_DATA on invalid input + * (context already used, invalid key identifier). + * \return #MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE if the key is not an + * ECC key pair. + * \return #MBEDTLS_ERR_PK_ALLOC_FAILED on allocation failure. + */ +int mbedtls_pk_setup_opaque( mbedtls_pk_context *ctx, + const psa_key_id_t key ); +#endif /* MBEDTLS_USE_PSA_CRYPTO */ + #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) /** * \brief Initialize an RSA-alt context @@ -425,8 +508,13 @@ int mbedtls_pk_verify_ext( mbedtls_pk_type_t type, const void *options, * \param md_alg Hash algorithm used (see notes) * \param hash Hash of the message to sign * \param hash_len Hash length or 0 (see notes) - * \param sig Place to write the signature - * \param sig_len Number of bytes written + * \param sig Place to write the signature. + * It must have enough room for the signature. + * #MBEDTLS_PK_SIGNATURE_MAX_SIZE is always enough. + * You may use a smaller buffer if it is large enough + * given the key type. + * \param sig_len On successful return, + * the number of bytes written to \p sig. * \param f_rng RNG function * \param p_rng RNG parameter * @@ -441,10 +529,6 @@ int mbedtls_pk_verify_ext( mbedtls_pk_type_t type, const void *options, * * \note For RSA, md_alg may be MBEDTLS_MD_NONE if hash_len != 0. * For ECDSA, md_alg may never be MBEDTLS_MD_NONE. - * - * \note In order to ensure enough space for the signature, the - * \p sig buffer size must be of at least - * `max(MBEDTLS_ECDSA_MAX_LEN, MBEDTLS_MPI_MAX_SIZE)` bytes. */ int mbedtls_pk_sign( mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, const unsigned char *hash, size_t hash_len, @@ -459,22 +543,23 @@ int mbedtls_pk_sign( mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, * \c mbedtls_ecp_set_max_ops() to reduce blocking for ECC * operations. For RSA, same as \c mbedtls_pk_sign(). * - * \note In order to ensure enough space for the signature, the - * \p sig buffer size must be of at least - * `max(MBEDTLS_ECDSA_MAX_LEN, MBEDTLS_MPI_MAX_SIZE)` bytes. - * * \param ctx The PK context to use. It must have been set up * with a private key. - * \param md_alg Hash algorithm used (see notes) + * \param md_alg Hash algorithm used (see notes for mbedtls_pk_sign()) * \param hash Hash of the message to sign - * \param hash_len Hash length or 0 (see notes) - * \param sig Place to write the signature - * \param sig_len Number of bytes written + * \param hash_len Hash length or 0 (see notes for mbedtls_pk_sign()) + * \param sig Place to write the signature. + * It must have enough room for the signature. + * #MBEDTLS_PK_SIGNATURE_MAX_SIZE is always enough. + * You may use a smaller buffer if it is large enough + * given the key type. + * \param sig_len On successful return, + * the number of bytes written to \p sig. * \param f_rng RNG function * \param p_rng RNG parameter * \param rs_ctx Restart context (NULL to disable restart) * - * \return See \c mbedtls_pk_sign(), or + * \return See \c mbedtls_pk_sign(). * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of * operations was reached: see \c mbedtls_ecp_set_max_ops(). */ @@ -534,7 +619,11 @@ int mbedtls_pk_encrypt( mbedtls_pk_context *ctx, * \param pub Context holding a public key. * \param prv Context holding a private (and public) key. * - * \return 0 on success or MBEDTLS_ERR_PK_BAD_INPUT_DATA + * \return \c 0 on success (keys were checked and match each other). + * \return #MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE if the keys could not + * be checked - in that case they may or may not match. + * \return #MBEDTLS_ERR_PK_BAD_INPUT_DATA if a context is invalid. + * \return Another non-zero value if the keys do not match. */ int mbedtls_pk_check_pair( const mbedtls_pk_context *pub, const mbedtls_pk_context *prv ); @@ -773,6 +862,32 @@ int mbedtls_pk_write_pubkey( unsigned char **p, unsigned char *start, int mbedtls_pk_load_file( const char *path, unsigned char **buf, size_t *n ); #endif +#if defined(MBEDTLS_USE_PSA_CRYPTO) +/** + * \brief Turn an EC key into an opaque one. + * + * \warning This is a temporary utility function for tests. It might + * change or be removed at any time without notice. + * + * \note Only ECDSA keys are supported so far. Signing with the + * specified hash is the only allowed use of that key. + * + * \param pk Input: the EC key to import to a PSA key. + * Output: a PK context wrapping that PSA key. + * \param key Output: a PSA key identifier. + * It's the caller's responsibility to call + * psa_destroy_key() on that key identifier after calling + * mbedtls_pk_free() on the PK context. + * \param hash_alg The hash algorithm to allow for use with that key. + * + * \return \c 0 if successful. + * \return An Mbed TLS error code otherwise. + */ +int mbedtls_pk_wrap_as_opaque( mbedtls_pk_context *pk, + psa_key_id_t *key, + psa_algorithm_t hash_alg ); +#endif /* MBEDTLS_USE_PSA_CRYPTO */ + #ifdef __cplusplus } #endif diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/pk_internal.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/pk_internal.h index 3f84cdf7489..47f7767700c 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/pk_internal.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/pk_internal.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,39 +18,18 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_PK_WRAP_H #define MBEDTLS_PK_WRAP_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "pk.h" +#include "mbedtls/pk.h" struct mbedtls_pk_info_t { @@ -160,4 +133,8 @@ extern const mbedtls_pk_info_t mbedtls_ecdsa_info; extern const mbedtls_pk_info_t mbedtls_rsa_alt_info; #endif +#if defined(MBEDTLS_USE_PSA_CRYPTO) +extern const mbedtls_pk_info_t mbedtls_pk_opaque_info; +#endif + #endif /* MBEDTLS_PK_WRAP_H */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/pkcs11.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/pkcs11.h index 3874d4a05ee..3530ee16889 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/pkcs11.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/pkcs11.h @@ -7,13 +7,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -26,40 +20,19 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_PKCS11_H #define MBEDTLS_PKCS11_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif #if defined(MBEDTLS_PKCS11_C) -#include "x509_crt.h" +#include "mbedtls/x509_crt.h" #include @@ -72,6 +45,8 @@ extern "C" { #endif +#if defined(MBEDTLS_DEPRECATED_REMOVED) + /** * Context for PKCS #11 private keys. */ @@ -81,47 +56,71 @@ typedef struct mbedtls_pkcs11_context int len; } mbedtls_pkcs11_context; +#if defined(MBEDTLS_DEPRECATED_WARNING) +#define MBEDTLS_DEPRECATED __attribute__((deprecated)) +#else +#define MBEDTLS_DEPRECATED +#endif + /** * Initialize a mbedtls_pkcs11_context. * (Just making memory references valid.) + * + * \deprecated This function is deprecated and will be removed in a + * future version of the library. */ -void mbedtls_pkcs11_init( mbedtls_pkcs11_context *ctx ); +MBEDTLS_DEPRECATED void mbedtls_pkcs11_init( mbedtls_pkcs11_context *ctx ); /** * Fill in a mbed TLS certificate, based on the given PKCS11 helper certificate. * + * \deprecated This function is deprecated and will be removed in a + * future version of the library. + * * \param cert X.509 certificate to fill * \param pkcs11h_cert PKCS #11 helper certificate * * \return 0 on success. */ -int mbedtls_pkcs11_x509_cert_bind( mbedtls_x509_crt *cert, pkcs11h_certificate_t pkcs11h_cert ); +MBEDTLS_DEPRECATED int mbedtls_pkcs11_x509_cert_bind( mbedtls_x509_crt *cert, + pkcs11h_certificate_t pkcs11h_cert ); /** * Set up a mbedtls_pkcs11_context storing the given certificate. Note that the * mbedtls_pkcs11_context will take over control of the certificate, freeing it when * done. * + * \deprecated This function is deprecated and will be removed in a + * future version of the library. + * * \param priv_key Private key structure to fill. * \param pkcs11_cert PKCS #11 helper certificate * * \return 0 on success */ -int mbedtls_pkcs11_priv_key_bind( mbedtls_pkcs11_context *priv_key, - pkcs11h_certificate_t pkcs11_cert ); +MBEDTLS_DEPRECATED int mbedtls_pkcs11_priv_key_bind( + mbedtls_pkcs11_context *priv_key, + pkcs11h_certificate_t pkcs11_cert ); /** * Free the contents of the given private key context. Note that the structure * itself is not freed. * + * \deprecated This function is deprecated and will be removed in a + * future version of the library. + * * \param priv_key Private key structure to cleanup */ -void mbedtls_pkcs11_priv_key_free( mbedtls_pkcs11_context *priv_key ); +MBEDTLS_DEPRECATED void mbedtls_pkcs11_priv_key_free( + mbedtls_pkcs11_context *priv_key ); /** * \brief Do an RSA private key decrypt, then remove the message * padding * + * \deprecated This function is deprecated and will be removed in a future + * version of the library. + * * \param ctx PKCS #11 context * \param mode must be MBEDTLS_RSA_PRIVATE, for compatibility with rsa.c's signature * \param input buffer holding the encrypted data @@ -135,15 +134,18 @@ void mbedtls_pkcs11_priv_key_free( mbedtls_pkcs11_context *priv_key ); * of ctx->N (eg. 128 bytes if RSA-1024 is used) otherwise * an error is thrown. */ -int mbedtls_pkcs11_decrypt( mbedtls_pkcs11_context *ctx, - int mode, size_t *olen, - const unsigned char *input, - unsigned char *output, - size_t output_max_len ); +MBEDTLS_DEPRECATED int mbedtls_pkcs11_decrypt( mbedtls_pkcs11_context *ctx, + int mode, size_t *olen, + const unsigned char *input, + unsigned char *output, + size_t output_max_len ); /** * \brief Do a private RSA to sign a message digest * + * \deprecated This function is deprecated and will be removed in a future + * version of the library. + * * \param ctx PKCS #11 context * \param mode must be MBEDTLS_RSA_PRIVATE, for compatibility with rsa.c's signature * \param md_alg a MBEDTLS_MD_XXX (use MBEDTLS_MD_NONE for signing raw data) @@ -157,28 +159,58 @@ int mbedtls_pkcs11_decrypt( mbedtls_pkcs11_context *ctx, * \note The "sig" buffer must be as large as the size * of ctx->N (eg. 128 bytes if RSA-1024 is used). */ -int mbedtls_pkcs11_sign( mbedtls_pkcs11_context *ctx, - int mode, - mbedtls_md_type_t md_alg, - unsigned int hashlen, - const unsigned char *hash, - unsigned char *sig ); +MBEDTLS_DEPRECATED int mbedtls_pkcs11_sign( mbedtls_pkcs11_context *ctx, + int mode, + mbedtls_md_type_t md_alg, + unsigned int hashlen, + const unsigned char *hash, + unsigned char *sig ); /** * SSL/TLS wrappers for PKCS#11 functions + * + * \deprecated This function is deprecated and will be removed in a future + * version of the library. */ -static inline int mbedtls_ssl_pkcs11_decrypt( void *ctx, int mode, size_t *olen, - const unsigned char *input, unsigned char *output, - size_t output_max_len ) +MBEDTLS_DEPRECATED static inline int mbedtls_ssl_pkcs11_decrypt( void *ctx, + int mode, size_t *olen, + const unsigned char *input, unsigned char *output, + size_t output_max_len ) { return mbedtls_pkcs11_decrypt( (mbedtls_pkcs11_context *) ctx, mode, olen, input, output, output_max_len ); } -static inline int mbedtls_ssl_pkcs11_sign( void *ctx, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, - int mode, mbedtls_md_type_t md_alg, unsigned int hashlen, - const unsigned char *hash, unsigned char *sig ) +/** + * \brief This function signs a message digest using RSA. + * + * \deprecated This function is deprecated and will be removed in a future + * version of the library. + * + * \param ctx The PKCS #11 context. + * \param f_rng The RNG function. This parameter is unused. + * \param p_rng The RNG context. This parameter is unused. + * \param mode The operation to run. This must be set to + * MBEDTLS_RSA_PRIVATE, for compatibility with rsa.c's + * signature. + * \param md_alg The message digest algorithm. One of the MBEDTLS_MD_XXX + * must be passed to this function and MBEDTLS_MD_NONE can be + * used for signing raw data. + * \param hashlen The message digest length (for MBEDTLS_MD_NONE only). + * \param hash The buffer holding the message digest. + * \param sig The buffer that will hold the ciphertext. + * + * \return \c 0 if the signing operation was successful. + * \return A non-zero error code on failure. + * + * \note The \p sig buffer must be as large as the size of + * ctx->N. For example, 128 bytes if RSA-1024 is + * used. + */ +MBEDTLS_DEPRECATED static inline int mbedtls_ssl_pkcs11_sign( void *ctx, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, + int mode, mbedtls_md_type_t md_alg, unsigned int hashlen, + const unsigned char *hash, unsigned char *sig ) { ((void) f_rng); ((void) p_rng); @@ -186,11 +218,25 @@ static inline int mbedtls_ssl_pkcs11_sign( void *ctx, hashlen, hash, sig ); } -static inline size_t mbedtls_ssl_pkcs11_key_len( void *ctx ) +/** + * This function gets the length of the private key. + * + * \deprecated This function is deprecated and will be removed in a future + * version of the library. + * + * \param ctx The PKCS #11 context. + * + * \return The length of the private key. + */ +MBEDTLS_DEPRECATED static inline size_t mbedtls_ssl_pkcs11_key_len( void *ctx ) { return ( (mbedtls_pkcs11_context *) ctx )->len; } +#undef MBEDTLS_DEPRECATED + +#endif /* MBEDTLS_DEPRECATED_REMOVED */ + #ifdef __cplusplus } #endif diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/pkcs12.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/pkcs12.h index 9cbcb173055..d9e85b1d126 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/pkcs12.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/pkcs12.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,47 +18,30 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_PKCS12_H #define MBEDTLS_PKCS12_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "md.h" -#include "cipher.h" -#include "asn1.h" +#include "mbedtls/md.h" +#include "mbedtls/cipher.h" +#include "mbedtls/asn1.h" #include -#define MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA -0x1F80 /**< Bad input parameters to function. */ -#define MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE -0x1F00 /**< Feature not available, e.g. unsupported encryption scheme. */ -#define MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT -0x1E80 /**< PBE ASN.1 data not as expected. */ -#define MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH -0x1E00 /**< Given private key password does not allow for correct decryption. */ +/** Bad input parameters to function. */ +#define MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA -0x1F80 +/** Feature not available, e.g. unsupported encryption scheme. */ +#define MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE -0x1F00 +/** PBE ASN.1 data not as expected. */ +#define MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT -0x1E80 +/** Given private key password does not allow for correct decryption. */ +#define MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH -0x1E00 #define MBEDTLS_PKCS12_DERIVE_KEY 1 /**< encryption/decryption key */ #define MBEDTLS_PKCS12_DERIVE_IV 2 /**< initialization vector */ @@ -102,11 +79,13 @@ int mbedtls_pkcs12_pbe_sha1_rc4_128( mbedtls_asn1_buf *pbe_params, int mode, * \brief PKCS12 Password Based function (encryption / decryption) * for cipher-based and mbedtls_md-based PBE's * - * \param pbe_params an ASN1 buffer containing the pkcs-12PbeParams structure - * \param mode either MBEDTLS_PKCS12_PBE_ENCRYPT or MBEDTLS_PKCS12_PBE_DECRYPT + * \param pbe_params an ASN1 buffer containing the pkcs-12 PbeParams structure + * \param mode either #MBEDTLS_PKCS12_PBE_ENCRYPT or + * #MBEDTLS_PKCS12_PBE_DECRYPT * \param cipher_type the cipher used - * \param md_type the mbedtls_md used - * \param pwd the password used (may be NULL if no password is used) + * \param md_type the mbedtls_md used + * \param pwd Latin1-encoded password used. This may only be \c NULL when + * \p pwdlen is 0. No null terminator should be used. * \param pwdlen length of the password (may be 0) * \param input the input data * \param len data length @@ -127,18 +106,24 @@ int mbedtls_pkcs12_pbe( mbedtls_asn1_buf *pbe_params, int mode, * to produce pseudo-random bits for a particular "purpose". * * Depending on the given id, this function can produce an - * encryption/decryption key, an nitialization vector or an + * encryption/decryption key, an initialization vector or an * integrity key. * * \param data buffer to store the derived data in - * \param datalen length to fill - * \param pwd password to use (may be NULL if no password is used) - * \param pwdlen length of the password (may be 0) - * \param salt salt buffer to use - * \param saltlen length of the salt - * \param mbedtls_md mbedtls_md type to use during the derivation - * \param id id that describes the purpose (can be MBEDTLS_PKCS12_DERIVE_KEY, - * MBEDTLS_PKCS12_DERIVE_IV or MBEDTLS_PKCS12_DERIVE_MAC_KEY) + * \param datalen length of buffer to fill + * \param pwd The password to use. For compliance with PKCS#12 §B.1, this + * should be a BMPString, i.e. a Unicode string where each + * character is encoded as 2 bytes in big-endian order, with + * no byte order mark and with a null terminator (i.e. the + * last two bytes should be 0x00 0x00). + * \param pwdlen length of the password (may be 0). + * \param salt Salt buffer to use This may only be \c NULL when + * \p saltlen is 0. + * \param saltlen length of the salt (may be zero) + * \param mbedtls_md mbedtls_md type to use during the derivation + * \param id id that describes the purpose (can be + * #MBEDTLS_PKCS12_DERIVE_KEY, #MBEDTLS_PKCS12_DERIVE_IV or + * #MBEDTLS_PKCS12_DERIVE_MAC_KEY) * \param iterations number of iterations * * \return 0 if successful, or a MD, BIGNUM type error. diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/pkcs5.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/pkcs5.h index 328633c492d..696930f745f 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/pkcs5.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/pkcs5.h @@ -7,13 +7,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -26,47 +20,30 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_PKCS5_H #define MBEDTLS_PKCS5_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "asn1.h" -#include "md.h" +#include "mbedtls/asn1.h" +#include "mbedtls/md.h" #include #include -#define MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA -0x2f80 /**< Bad input parameters to function. */ -#define MBEDTLS_ERR_PKCS5_INVALID_FORMAT -0x2f00 /**< Unexpected ASN.1 data. */ -#define MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE -0x2e80 /**< Requested encryption or digest alg not available. */ -#define MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH -0x2e00 /**< Given private key password does not allow for correct decryption. */ +/** Bad input parameters to function. */ +#define MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA -0x2f80 +/** Unexpected ASN.1 data. */ +#define MBEDTLS_ERR_PKCS5_INVALID_FORMAT -0x2f00 +/** Requested encryption or digest alg not available. */ +#define MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE -0x2e80 +/** Given private key password does not allow for correct decryption. */ +#define MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH -0x2e00 #define MBEDTLS_PKCS5_DECRYPT 0 #define MBEDTLS_PKCS5_ENCRYPT 1 diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/platform.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/platform.h index 689cfc6ec79..bdef07498d7 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/platform.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/platform.h @@ -14,13 +14,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -33,43 +27,24 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_PLATFORM_H #define MBEDTLS_PLATFORM_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif #if defined(MBEDTLS_HAVE_TIME) -#include "platform_time.h" +#include "mbedtls/platform_time.h" #endif -#define MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED -0x0070 /**< Hardware accelerator failed */ -#define MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED -0x0072 /**< The requested feature is not supported by the platform */ +/** Hardware accelerator failed */ +#define MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED -0x0070 +/** The requested feature is not supported by the platform */ +#define MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED -0x0072 #ifdef __cplusplus extern "C" { @@ -83,17 +58,33 @@ extern "C" { * \{ */ +/* The older Microsoft Windows common runtime provides non-conforming + * implementations of some standard library functions, including snprintf + * and vsnprintf. This affects MSVC and MinGW builds. + */ +#if defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER <= 1900) +#define MBEDTLS_PLATFORM_HAS_NON_CONFORMING_SNPRINTF +#define MBEDTLS_PLATFORM_HAS_NON_CONFORMING_VSNPRINTF +#endif + #if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS) #include #include #include #if !defined(MBEDTLS_PLATFORM_STD_SNPRINTF) -#if defined(_WIN32) +#if defined(MBEDTLS_PLATFORM_HAS_NON_CONFORMING_SNPRINTF) #define MBEDTLS_PLATFORM_STD_SNPRINTF mbedtls_platform_win32_snprintf /**< The default \c snprintf function to use. */ #else #define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< The default \c snprintf function to use. */ #endif #endif +#if !defined(MBEDTLS_PLATFORM_STD_VSNPRINTF) +#if defined(MBEDTLS_PLATFORM_HAS_NON_CONFORMING_VSNPRINTF) +#define MBEDTLS_PLATFORM_STD_VSNPRINTF mbedtls_platform_win32_vsnprintf /**< The default \c vsnprintf function to use. */ +#else +#define MBEDTLS_PLATFORM_STD_VSNPRINTF vsnprintf /**< The default \c vsnprintf function to use. */ +#endif +#endif #if !defined(MBEDTLS_PLATFORM_STD_PRINTF) #define MBEDTLS_PLATFORM_STD_PRINTF printf /**< The default \c printf function to use. */ #endif @@ -229,7 +220,7 @@ int mbedtls_platform_set_printf( int (*printf_func)( const char *, ... ) ); * - however it is acceptable to return -1 instead of the required length when * the destination buffer is too short. */ -#if defined(_WIN32) +#if defined(MBEDTLS_PLATFORM_HAS_NON_CONFORMING_SNPRINTF) /* For Windows (inc. MSYS2), we provide our own fixed implementation */ int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... ); #endif @@ -255,6 +246,42 @@ int mbedtls_platform_set_snprintf( int (*snprintf_func)( char * s, size_t n, #endif /* MBEDTLS_PLATFORM_SNPRINTF_MACRO */ #endif /* MBEDTLS_PLATFORM_SNPRINTF_ALT */ +/* + * The function pointers for vsnprintf + * + * The vsnprintf implementation should conform to C99: + * - it *must* always correctly zero-terminate the buffer + * (except when n == 0, then it must leave the buffer untouched) + * - however it is acceptable to return -1 instead of the required length when + * the destination buffer is too short. + */ +#if defined(MBEDTLS_PLATFORM_HAS_NON_CONFORMING_VSNPRINTF) +#include +/* For Older Windows (inc. MSYS2), we provide our own fixed implementation */ +int mbedtls_platform_win32_vsnprintf( char *s, size_t n, const char *fmt, va_list arg ); +#endif + +#if defined(MBEDTLS_PLATFORM_VSNPRINTF_ALT) +#include +extern int (*mbedtls_vsnprintf)( char * s, size_t n, const char * format, va_list arg ); + +/** + * \brief Set your own snprintf function pointer + * + * \param vsnprintf_func The \c vsnprintf function implementation + * + * \return \c 0 + */ +int mbedtls_platform_set_vsnprintf( int (*vsnprintf_func)( char * s, size_t n, + const char * format, va_list arg ) ); +#else /* MBEDTLS_PLATFORM_VSNPRINTF_ALT */ +#if defined(MBEDTLS_PLATFORM_VSNPRINTF_MACRO) +#define mbedtls_vsnprintf MBEDTLS_PLATFORM_VSNPRINTF_MACRO +#else +#define mbedtls_vsnprintf vsnprintf +#endif /* MBEDTLS_PLATFORM_VSNPRINTF_MACRO */ +#endif /* MBEDTLS_PLATFORM_VSNPRINTF_ALT */ + /* * The function pointers for exit */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/platform_time.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/platform_time.h index e132f6a688c..7e7daab6920 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/platform_time.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/platform_time.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,33 +18,12 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_PLATFORM_TIME_H #define MBEDTLS_PLATFORM_TIME_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/platform_util.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/platform_util.h index 426afaf0401..f982db8c01c 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/platform_util.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/platform_util.h @@ -6,13 +6,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -25,40 +19,19 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_PLATFORM_UTIL_H #define MBEDTLS_PLATFORM_UTIL_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif #include #if defined(MBEDTLS_HAVE_TIME_DATE) -#include "platform_time.h" +#include "mbedtls/platform_time.h" #include #endif /* MBEDTLS_HAVE_TIME_DATE */ @@ -159,6 +132,95 @@ MBEDTLS_DEPRECATED typedef int mbedtls_deprecated_numeric_constant_t; #endif /* MBEDTLS_DEPRECATED_WARNING */ #endif /* MBEDTLS_DEPRECATED_REMOVED */ +/* Implementation of the check-return facility. + * See the user documentation in config.h. + * + * Do not use this macro directly to annotate function: instead, + * use one of MBEDTLS_CHECK_RETURN_CRITICAL or MBEDTLS_CHECK_RETURN_TYPICAL + * depending on how important it is to check the return value. + */ +#if !defined(MBEDTLS_CHECK_RETURN) +#if defined(__GNUC__) +#define MBEDTLS_CHECK_RETURN __attribute__((__warn_unused_result__)) +#elif defined(_MSC_VER) && _MSC_VER >= 1700 +#include +#define MBEDTLS_CHECK_RETURN _Check_return_ +#else +#define MBEDTLS_CHECK_RETURN +#endif +#endif + +/** Critical-failure function + * + * This macro appearing at the beginning of the declaration of a function + * indicates that its return value should be checked in all applications. + * Omitting the check is very likely to indicate a bug in the application + * and will result in a compile-time warning if #MBEDTLS_CHECK_RETURN + * is implemented for the compiler in use. + * + * \note The use of this macro is a work in progress. + * This macro may be added to more functions in the future. + * Such an extension is not considered an API break, provided that + * there are near-unavoidable circumstances under which the function + * can fail. For example, signature/MAC/AEAD verification functions, + * and functions that require a random generator, are considered + * return-check-critical. + */ +#define MBEDTLS_CHECK_RETURN_CRITICAL MBEDTLS_CHECK_RETURN + +/** Ordinary-failure function + * + * This macro appearing at the beginning of the declaration of a function + * indicates that its return value should be generally be checked in portable + * applications. Omitting the check will result in a compile-time warning if + * #MBEDTLS_CHECK_RETURN is implemented for the compiler in use and + * #MBEDTLS_CHECK_RETURN_WARNING is enabled in the compile-time configuration. + * + * You can use #MBEDTLS_IGNORE_RETURN to explicitly ignore the return value + * of a function that is annotated with #MBEDTLS_CHECK_RETURN. + * + * \note The use of this macro is a work in progress. + * This macro will be added to more functions in the future. + * Eventually this should appear before most functions returning + * an error code (as \c int in the \c mbedtls_xxx API or + * as ::psa_status_t in the \c psa_xxx API). + */ +#if defined(MBEDTLS_CHECK_RETURN_WARNING) +#define MBEDTLS_CHECK_RETURN_TYPICAL MBEDTLS_CHECK_RETURN +#else +#define MBEDTLS_CHECK_RETURN_TYPICAL +#endif + +/** Benign-failure function + * + * This macro appearing at the beginning of the declaration of a function + * indicates that it is rarely useful to check its return value. + * + * This macro has an empty expansion. It exists for documentation purposes: + * a #MBEDTLS_CHECK_RETURN_OPTIONAL annotation indicates that the function + * has been analyzed for return-check usefuless, whereas the lack of + * an annotation indicates that the function has not been analyzed and its + * return-check usefulness is unknown. + */ +#define MBEDTLS_CHECK_RETURN_OPTIONAL + +/** \def MBEDTLS_IGNORE_RETURN + * + * Call this macro with one argument, a function call, to suppress a warning + * from #MBEDTLS_CHECK_RETURN due to that function call. + */ +#if !defined(MBEDTLS_IGNORE_RETURN) +/* GCC doesn't silence the warning with just (void)(result). + * (void)!(result) is known to work up at least up to GCC 10, as well + * as with Clang and MSVC. + * + * https://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/Non_002dbugs.html + * https://stackoverflow.com/questions/40576003/ignoring-warning-wunused-result + * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425#c34 + */ +#define MBEDTLS_IGNORE_RETURN(result) ( (void) !( result ) ) +#endif + /** * \brief Securely zeroize a buffer * diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/poly1305.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/poly1305.h index b337aa841ca..a69ede98b5e 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/poly1305.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/poly1305.h @@ -14,13 +14,7 @@ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -33,34 +27,13 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_POLY1305_H #define MBEDTLS_POLY1305_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif @@ -68,15 +41,18 @@ #include #include -#define MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA -0x0057 /**< Invalid input parameter(s). */ +/** Invalid input parameter(s). */ +#define MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA -0x0057 /* MBEDTLS_ERR_POLY1305_FEATURE_UNAVAILABLE is deprecated and should not be * used. */ -#define MBEDTLS_ERR_POLY1305_FEATURE_UNAVAILABLE -0x0059 /**< Feature not available. For example, s part of the API is not implemented. */ +/** Feature not available. For example, s part of the API is not implemented. */ +#define MBEDTLS_ERR_POLY1305_FEATURE_UNAVAILABLE -0x0059 /* MBEDTLS_ERR_POLY1305_HW_ACCEL_FAILED is deprecated and should not be used. */ -#define MBEDTLS_ERR_POLY1305_HW_ACCEL_FAILED -0x005B /**< Poly1305 hardware accelerator failed. */ +/** Poly1305 hardware accelerator failed. */ +#define MBEDTLS_ERR_POLY1305_HW_ACCEL_FAILED -0x005B #ifdef __cplusplus extern "C" { diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/psa_util.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/psa_util.h new file mode 100644 index 00000000000..af7a809e40b --- /dev/null +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/psa_util.h @@ -0,0 +1,512 @@ +/** + * \file psa_util.h + * + * \brief Utility functions for the use of the PSA Crypto library. + * + * \warning This function is not part of the public API and may + * change at any time. + */ +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MBEDTLS_PSA_UTIL_H +#define MBEDTLS_PSA_UTIL_H + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls/config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#if defined(MBEDTLS_USE_PSA_CRYPTO) + +#include "psa/crypto.h" + +#include "mbedtls/ecp.h" +#include "mbedtls/md.h" +#include "mbedtls/pk.h" +#include "mbedtls/oid.h" + +#include + +/* Translations for symmetric crypto. */ + +static inline psa_key_type_t mbedtls_psa_translate_cipher_type( + mbedtls_cipher_type_t cipher ) +{ + switch( cipher ) + { + case MBEDTLS_CIPHER_AES_128_CCM: + case MBEDTLS_CIPHER_AES_192_CCM: + case MBEDTLS_CIPHER_AES_256_CCM: + case MBEDTLS_CIPHER_AES_128_GCM: + case MBEDTLS_CIPHER_AES_192_GCM: + case MBEDTLS_CIPHER_AES_256_GCM: + case MBEDTLS_CIPHER_AES_128_CBC: + case MBEDTLS_CIPHER_AES_192_CBC: + case MBEDTLS_CIPHER_AES_256_CBC: + case MBEDTLS_CIPHER_AES_128_ECB: + case MBEDTLS_CIPHER_AES_192_ECB: + case MBEDTLS_CIPHER_AES_256_ECB: + return( PSA_KEY_TYPE_AES ); + + /* ARIA not yet supported in PSA. */ + /* case MBEDTLS_CIPHER_ARIA_128_CCM: + case MBEDTLS_CIPHER_ARIA_192_CCM: + case MBEDTLS_CIPHER_ARIA_256_CCM: + case MBEDTLS_CIPHER_ARIA_128_GCM: + case MBEDTLS_CIPHER_ARIA_192_GCM: + case MBEDTLS_CIPHER_ARIA_256_GCM: + case MBEDTLS_CIPHER_ARIA_128_CBC: + case MBEDTLS_CIPHER_ARIA_192_CBC: + case MBEDTLS_CIPHER_ARIA_256_CBC: + return( PSA_KEY_TYPE_ARIA ); */ + + default: + return( 0 ); + } +} + +static inline psa_algorithm_t mbedtls_psa_translate_cipher_mode( + mbedtls_cipher_mode_t mode, size_t taglen ) +{ + switch( mode ) + { + case MBEDTLS_MODE_ECB: + return( PSA_ALG_ECB_NO_PADDING ); + case MBEDTLS_MODE_GCM: + return( PSA_ALG_AEAD_WITH_SHORTENED_TAG( PSA_ALG_GCM, taglen ) ); + case MBEDTLS_MODE_CCM: + return( PSA_ALG_AEAD_WITH_SHORTENED_TAG( PSA_ALG_CCM, taglen ) ); + case MBEDTLS_MODE_CBC: + if( taglen == 0 ) + return( PSA_ALG_CBC_NO_PADDING ); + else + return( 0 ); + default: + return( 0 ); + } +} + +static inline psa_key_usage_t mbedtls_psa_translate_cipher_operation( + mbedtls_operation_t op ) +{ + switch( op ) + { + case MBEDTLS_ENCRYPT: + return( PSA_KEY_USAGE_ENCRYPT ); + case MBEDTLS_DECRYPT: + return( PSA_KEY_USAGE_DECRYPT ); + default: + return( 0 ); + } +} + +/* Translations for hashing. */ + +static inline psa_algorithm_t mbedtls_psa_translate_md( mbedtls_md_type_t md_alg ) +{ + switch( md_alg ) + { +#if defined(MBEDTLS_MD2_C) + case MBEDTLS_MD_MD2: + return( PSA_ALG_MD2 ); +#endif +#if defined(MBEDTLS_MD4_C) + case MBEDTLS_MD_MD4: + return( PSA_ALG_MD4 ); +#endif +#if defined(MBEDTLS_MD5_C) + case MBEDTLS_MD_MD5: + return( PSA_ALG_MD5 ); +#endif +#if defined(MBEDTLS_SHA1_C) + case MBEDTLS_MD_SHA1: + return( PSA_ALG_SHA_1 ); +#endif +#if defined(MBEDTLS_SHA256_C) + case MBEDTLS_MD_SHA224: + return( PSA_ALG_SHA_224 ); + case MBEDTLS_MD_SHA256: + return( PSA_ALG_SHA_256 ); +#endif +#if defined(MBEDTLS_SHA512_C) + case MBEDTLS_MD_SHA384: + return( PSA_ALG_SHA_384 ); + case MBEDTLS_MD_SHA512: + return( PSA_ALG_SHA_512 ); +#endif +#if defined(MBEDTLS_RIPEMD160_C) + case MBEDTLS_MD_RIPEMD160: + return( PSA_ALG_RIPEMD160 ); +#endif + case MBEDTLS_MD_NONE: + return( 0 ); + default: + return( 0 ); + } +} + +/* Translations for ECC. */ + +static inline int mbedtls_psa_get_ecc_oid_from_id( + psa_ecc_family_t curve, size_t bits, + char const **oid, size_t *oid_len ) +{ + switch( curve ) + { + case PSA_ECC_FAMILY_SECP_R1: + switch( bits ) + { +#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) + case 192: + *oid = MBEDTLS_OID_EC_GRP_SECP192R1; + *oid_len = MBEDTLS_OID_SIZE( MBEDTLS_OID_EC_GRP_SECP192R1 ); + return( 0 ); +#endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */ +#if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) + case 224: + *oid = MBEDTLS_OID_EC_GRP_SECP224R1; + *oid_len = MBEDTLS_OID_SIZE( MBEDTLS_OID_EC_GRP_SECP224R1 ); + return( 0 ); +#endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED */ +#if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) + case 256: + *oid = MBEDTLS_OID_EC_GRP_SECP256R1; + *oid_len = MBEDTLS_OID_SIZE( MBEDTLS_OID_EC_GRP_SECP256R1 ); + return( 0 ); +#endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED */ +#if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) + case 384: + *oid = MBEDTLS_OID_EC_GRP_SECP384R1; + *oid_len = MBEDTLS_OID_SIZE( MBEDTLS_OID_EC_GRP_SECP384R1 ); + return( 0 ); +#endif /* MBEDTLS_ECP_DP_SECP384R1_ENABLED */ +#if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) + case 521: + *oid = MBEDTLS_OID_EC_GRP_SECP521R1; + *oid_len = MBEDTLS_OID_SIZE( MBEDTLS_OID_EC_GRP_SECP521R1 ); + return( 0 ); +#endif /* MBEDTLS_ECP_DP_SECP521R1_ENABLED */ + } + break; + case PSA_ECC_FAMILY_SECP_K1: + switch( bits ) + { +#if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) + case 192: + *oid = MBEDTLS_OID_EC_GRP_SECP192K1; + *oid_len = MBEDTLS_OID_SIZE( MBEDTLS_OID_EC_GRP_SECP192K1 ); + return( 0 ); +#endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED */ +#if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) + case 224: + *oid = MBEDTLS_OID_EC_GRP_SECP224K1; + *oid_len = MBEDTLS_OID_SIZE( MBEDTLS_OID_EC_GRP_SECP224K1 ); + return( 0 ); +#endif /* MBEDTLS_ECP_DP_SECP224K1_ENABLED */ +#if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) + case 256: + *oid = MBEDTLS_OID_EC_GRP_SECP256K1; + *oid_len = MBEDTLS_OID_SIZE( MBEDTLS_OID_EC_GRP_SECP256K1 ); + return( 0 ); +#endif /* MBEDTLS_ECP_DP_SECP256K1_ENABLED */ + } + break; + case PSA_ECC_FAMILY_BRAINPOOL_P_R1: + switch( bits ) + { +#if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) + case 256: + *oid = MBEDTLS_OID_EC_GRP_BP256R1; + *oid_len = MBEDTLS_OID_SIZE( MBEDTLS_OID_EC_GRP_BP256R1 ); + return( 0 ); +#endif /* MBEDTLS_ECP_DP_BP256R1_ENABLED */ +#if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) + case 384: + *oid = MBEDTLS_OID_EC_GRP_BP384R1; + *oid_len = MBEDTLS_OID_SIZE( MBEDTLS_OID_EC_GRP_BP384R1 ); + return( 0 ); +#endif /* MBEDTLS_ECP_DP_BP384R1_ENABLED */ +#if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) + case 512: + *oid = MBEDTLS_OID_EC_GRP_BP512R1; + *oid_len = MBEDTLS_OID_SIZE( MBEDTLS_OID_EC_GRP_BP512R1 ); + return( 0 ); +#endif /* MBEDTLS_ECP_DP_BP512R1_ENABLED */ + } + break; + } + (void) oid; + (void) oid_len; + return( -1 ); +} + +#define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH 1 + +#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) +#if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 192 + 7 ) / 8 ) + 1 ) +#undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH +#define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 192 + 7 ) / 8 ) + 1 ) +#endif +#endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */ + +#if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) +#if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 224 + 7 ) / 8 ) + 1 ) +#undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH +#define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 224 + 7 ) / 8 ) + 1 ) +#endif +#endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED */ + +#if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) +#if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 256 + 7 ) / 8 ) + 1 ) +#undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH +#define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 256 + 7 ) / 8 ) + 1 ) +#endif +#endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED */ + +#if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) +#if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 384 + 7 ) / 8 ) + 1 ) +#undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH +#define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 384 + 7 ) / 8 ) + 1 ) +#endif +#endif /* MBEDTLS_ECP_DP_SECP384R1_ENABLED */ + +#if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) +#if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 521 + 7 ) / 8 ) + 1 ) +#undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH +#define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 521 + 7 ) / 8 ) + 1 ) +#endif +#endif /* MBEDTLS_ECP_DP_SECP521R1_ENABLED */ + +#if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) +#if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 192 + 7 ) / 8 ) + 1 ) +#undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH +#define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 192 + 7 ) / 8 ) + 1 ) +#endif +#endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED */ + +#if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) +#if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 224 + 7 ) / 8 ) + 1 ) +#undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH +#define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 224 + 7 ) / 8 ) + 1 ) +#endif +#endif /* MBEDTLS_ECP_DP_SECP224K1_ENABLED */ + +#if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) +#if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 256 + 7 ) / 8 ) + 1 ) +#undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH +#define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 256 + 7 ) / 8 ) + 1 ) +#endif +#endif /* MBEDTLS_ECP_DP_SECP256K1_ENABLED */ + +#if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) +#if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 256 + 7 ) / 8 ) + 1 ) +#undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH +#define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 256 + 7 ) / 8 ) + 1 ) +#endif +#endif /* MBEDTLS_ECP_DP_BP256R1_ENABLED */ + +#if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) +#if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 384 + 7 ) / 8 ) + 1 ) +#undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH +#define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 384 + 7 ) / 8 ) + 1 ) +#endif +#endif /* MBEDTLS_ECP_DP_BP384R1_ENABLED */ + +#if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) +#if MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH < ( 2 * ( ( 512 + 7 ) / 8 ) + 1 ) +#undef MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH +#define MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ( 2 * ( ( 512 + 7 ) / 8 ) + 1 ) +#endif +#endif /* MBEDTLS_ECP_DP_BP512R1_ENABLED */ + + +/* Translations for PK layer */ + +static inline int mbedtls_psa_err_translate_pk( psa_status_t status ) +{ + switch( status ) + { + case PSA_SUCCESS: + return( 0 ); + case PSA_ERROR_NOT_SUPPORTED: + return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ); + case PSA_ERROR_INSUFFICIENT_MEMORY: + return( MBEDTLS_ERR_PK_ALLOC_FAILED ); + case PSA_ERROR_INSUFFICIENT_ENTROPY: + return( MBEDTLS_ERR_ECP_RANDOM_FAILED ); + case PSA_ERROR_BAD_STATE: + return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + /* All other failures */ + case PSA_ERROR_COMMUNICATION_FAILURE: + case PSA_ERROR_HARDWARE_FAILURE: + case PSA_ERROR_CORRUPTION_DETECTED: + return( MBEDTLS_ERR_PK_HW_ACCEL_FAILED ); + default: /* We return the same as for the 'other failures', + * but list them separately nonetheless to indicate + * which failure conditions we have considered. */ + return( MBEDTLS_ERR_PK_HW_ACCEL_FAILED ); + } +} + +/* Translations for ECC */ + +/* This function transforms an ECC group identifier from + * https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8 + * into a PSA ECC group identifier. */ +#if defined(MBEDTLS_ECP_C) +static inline psa_key_type_t mbedtls_psa_parse_tls_ecc_group( + uint16_t tls_ecc_grp_reg_id, size_t *bits ) +{ + const mbedtls_ecp_curve_info *curve_info = + mbedtls_ecp_curve_info_from_tls_id( tls_ecc_grp_reg_id ); + if( curve_info == NULL ) + return( 0 ); + return( PSA_KEY_TYPE_ECC_KEY_PAIR( + mbedtls_ecc_group_to_psa( curve_info->grp_id, bits ) ) ); +} +#endif /* MBEDTLS_ECP_C */ + +/* This function takes a buffer holding an EC public key + * exported through psa_export_public_key(), and converts + * it into an ECPoint structure to be put into a ClientKeyExchange + * message in an ECDHE exchange. + * + * Both the present and the foreseeable future format of EC public keys + * used by PSA have the ECPoint structure contained in the exported key + * as a subbuffer, and the function merely selects this subbuffer instead + * of making a copy. + */ +static inline int mbedtls_psa_tls_psa_ec_to_ecpoint( unsigned char *src, + size_t srclen, + unsigned char **dst, + size_t *dstlen ) +{ + *dst = src; + *dstlen = srclen; + return( 0 ); +} + +/* This function takes a buffer holding an ECPoint structure + * (as contained in a TLS ServerKeyExchange message for ECDHE + * exchanges) and converts it into a format that the PSA key + * agreement API understands. + */ +static inline int mbedtls_psa_tls_ecpoint_to_psa_ec( unsigned char const *src, + size_t srclen, + unsigned char *dst, + size_t dstlen, + size_t *olen ) +{ + if( srclen > dstlen ) + return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL ); + + memcpy( dst, src, srclen ); + *olen = srclen; + return( 0 ); +} + +#endif /* MBEDTLS_USE_PSA_CRYPTO */ + +/* Expose whatever RNG the PSA subsystem uses to applications using the + * mbedtls_xxx API. The declarations and definitions here need to be + * consistent with the implementation in library/psa_crypto_random_impl.h. + * See that file for implementation documentation. */ +#if defined(MBEDTLS_PSA_CRYPTO_C) + +/* The type of a `f_rng` random generator function that many library functions + * take. + * + * This type name is not part of the Mbed TLS stable API. It may be renamed + * or moved without warning. + */ +typedef int mbedtls_f_rng_t( void *p_rng, unsigned char *output, size_t output_size ); + +#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) + +/** The random generator function for the PSA subsystem. + * + * This function is suitable as the `f_rng` random generator function + * parameter of many `mbedtls_xxx` functions. Use #MBEDTLS_PSA_RANDOM_STATE + * to obtain the \p p_rng parameter. + * + * The implementation of this function depends on the configuration of the + * library. + * + * \note Depending on the configuration, this may be a function or + * a pointer to a function. + * + * \note This function may only be used if the PSA crypto subsystem is active. + * This means that you must call psa_crypto_init() before any call to + * this function, and you must not call this function after calling + * mbedtls_psa_crypto_free(). + * + * \param p_rng The random generator context. This must be + * #MBEDTLS_PSA_RANDOM_STATE. No other state is + * supported. + * \param output The buffer to fill. It must have room for + * \c output_size bytes. + * \param output_size The number of bytes to write to \p output. + * This function may fail if \p output_size is too + * large. It is guaranteed to accept any output size + * requested by Mbed TLS library functions. The + * maximum request size depends on the library + * configuration. + * + * \return \c 0 on success. + * \return An `MBEDTLS_ERR_ENTROPY_xxx`, + * `MBEDTLS_ERR_PLATFORM_xxx, + * `MBEDTLS_ERR_CTR_DRBG_xxx` or + * `MBEDTLS_ERR_HMAC_DRBG_xxx` on error. + */ +int mbedtls_psa_get_random( void *p_rng, + unsigned char *output, + size_t output_size ); + +/** The random generator state for the PSA subsystem. + * + * This macro expands to an expression which is suitable as the `p_rng` + * random generator state parameter of many `mbedtls_xxx` functions. + * It must be used in combination with the random generator function + * mbedtls_psa_get_random(). + * + * The implementation of this macro depends on the configuration of the + * library. Do not make any assumption on its nature. + */ +#define MBEDTLS_PSA_RANDOM_STATE NULL + +#else /* !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) */ + +#if defined(MBEDTLS_CTR_DRBG_C) +#include "mbedtls/ctr_drbg.h" +typedef mbedtls_ctr_drbg_context mbedtls_psa_drbg_context_t; +static mbedtls_f_rng_t *const mbedtls_psa_get_random = mbedtls_ctr_drbg_random; +#elif defined(MBEDTLS_HMAC_DRBG_C) +#include "mbedtls/hmac_drbg.h" +typedef mbedtls_hmac_drbg_context mbedtls_psa_drbg_context_t; +static mbedtls_f_rng_t *const mbedtls_psa_get_random = mbedtls_hmac_drbg_random; +#endif +extern mbedtls_psa_drbg_context_t *const mbedtls_psa_random_state; + +#define MBEDTLS_PSA_RANDOM_STATE mbedtls_psa_random_state + +#endif /* !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) */ + +#endif /* MBEDTLS_PSA_CRYPTO_C */ + +#endif /* MBEDTLS_PSA_UTIL_H */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ripemd160.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ripemd160.h index 31c6637d6dc..63270d12394 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ripemd160.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ripemd160.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,33 +18,12 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_RIPEMD160_H #define MBEDTLS_RIPEMD160_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif @@ -60,7 +33,8 @@ /* MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED is deprecated and should not be used. */ -#define MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED -0x0031 /**< RIPEMD160 hardware accelerator failed */ +/** RIPEMD160 hardware accelerator failed */ +#define MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED -0x0031 #ifdef __cplusplus extern "C" { @@ -82,7 +56,7 @@ typedef struct mbedtls_ripemd160_context mbedtls_ripemd160_context; #else /* MBEDTLS_RIPEMD160_ALT */ -#include "ripemd160.h" +#include "ripemd160_alt.h" #endif /* MBEDTLS_RIPEMD160_ALT */ /** diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/rsa.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/rsa.h index b2f65334fe7..3c481e12a17 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/rsa.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/rsa.h @@ -11,13 +11,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -30,63 +24,53 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_RSA_H #define MBEDTLS_RSA_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "bignum.h" -#include "md.h" +#include "mbedtls/bignum.h" +#include "mbedtls/md.h" #if defined(MBEDTLS_THREADING_C) -#include "threading.h" +#include "mbedtls/threading.h" #endif /* * RSA Error codes */ -#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA -0x4080 /**< Bad input parameters to function. */ -#define MBEDTLS_ERR_RSA_INVALID_PADDING -0x4100 /**< Input data contains invalid padding and is rejected. */ -#define MBEDTLS_ERR_RSA_KEY_GEN_FAILED -0x4180 /**< Something failed during generation of a key. */ -#define MBEDTLS_ERR_RSA_KEY_CHECK_FAILED -0x4200 /**< Key failed to pass the validity check of the library. */ -#define MBEDTLS_ERR_RSA_PUBLIC_FAILED -0x4280 /**< The public key operation failed. */ -#define MBEDTLS_ERR_RSA_PRIVATE_FAILED -0x4300 /**< The private key operation failed. */ -#define MBEDTLS_ERR_RSA_VERIFY_FAILED -0x4380 /**< The PKCS#1 verification failed. */ -#define MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE -0x4400 /**< The output buffer for decryption is not large enough. */ -#define MBEDTLS_ERR_RSA_RNG_FAILED -0x4480 /**< The random generator failed to generate non-zeros. */ +/** Bad input parameters to function. */ +#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA -0x4080 +/** Input data contains invalid padding and is rejected. */ +#define MBEDTLS_ERR_RSA_INVALID_PADDING -0x4100 +/** Something failed during generation of a key. */ +#define MBEDTLS_ERR_RSA_KEY_GEN_FAILED -0x4180 +/** Key failed to pass the validity check of the library. */ +#define MBEDTLS_ERR_RSA_KEY_CHECK_FAILED -0x4200 +/** The public key operation failed. */ +#define MBEDTLS_ERR_RSA_PUBLIC_FAILED -0x4280 +/** The private key operation failed. */ +#define MBEDTLS_ERR_RSA_PRIVATE_FAILED -0x4300 +/** The PKCS#1 verification failed. */ +#define MBEDTLS_ERR_RSA_VERIFY_FAILED -0x4380 +/** The output buffer for decryption is not large enough. */ +#define MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE -0x4400 +/** The random generator failed to generate non-zeros. */ +#define MBEDTLS_ERR_RSA_RNG_FAILED -0x4480 /* MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION is deprecated and should not be used. */ -#define MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION -0x4500 /**< The implementation does not offer the requested operation, for example, because of security violations or lack of functionality. */ +/** The implementation does not offer the requested operation, for example, because of security violations or lack of functionality. */ +#define MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION -0x4500 /* MBEDTLS_ERR_RSA_HW_ACCEL_FAILED is deprecated and should not be used. */ -#define MBEDTLS_ERR_RSA_HW_ACCEL_FAILED -0x4580 /**< RSA hardware accelerator failed. */ +/** RSA hardware accelerator failed. */ +#define MBEDTLS_ERR_RSA_HW_ACCEL_FAILED -0x4580 /* * RSA constants @@ -630,7 +614,8 @@ int mbedtls_rsa_private( mbedtls_rsa_context *ctx, * #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE (deprecated). * \param ilen The length of the plaintext in Bytes. * \param input The input data to encrypt. This must be a readable - * buffer of size \p ilen Bytes. This must not be \c NULL. + * buffer of size \p ilen Bytes. It may be \c NULL if + * `ilen == 0`. * \param output The output buffer. This must be a writable buffer * of length \c ctx->len Bytes. For example, \c 256 Bytes * for an 2048-bit RSA modulus. @@ -670,7 +655,8 @@ int mbedtls_rsa_pkcs1_encrypt( mbedtls_rsa_context *ctx, * #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE (deprecated). * \param ilen The length of the plaintext in Bytes. * \param input The input data to encrypt. This must be a readable - * buffer of size \p ilen Bytes. This must not be \c NULL. + * buffer of size \p ilen Bytes. It may be \c NULL if + * `ilen == 0`. * \param output The output buffer. This must be a writable buffer * of length \c ctx->len Bytes. For example, \c 256 Bytes * for an 2048-bit RSA modulus. @@ -714,7 +700,8 @@ int mbedtls_rsa_rsaes_pkcs1_v15_encrypt( mbedtls_rsa_context *ctx, * \param label_len The length of the label in Bytes. * \param ilen The length of the plaintext buffer \p input in Bytes. * \param input The input data to encrypt. This must be a readable - * buffer of size \p ilen Bytes. This must not be \c NULL. + * buffer of size \p ilen Bytes. It may be \c NULL if + * `ilen == 0`. * \param output The output buffer. This must be a writable buffer * of length \c ctx->len Bytes. For example, \c 256 Bytes * for an 2048-bit RSA modulus. @@ -1000,12 +987,69 @@ int mbedtls_rsa_rsassa_pkcs1_v15_sign( mbedtls_rsa_context *ctx, * \brief This function performs a PKCS#1 v2.1 PSS signature * operation (RSASSA-PSS-SIGN). * - * \note The \p hash_id in the RSA context is the one used for the - * encoding. \p md_alg in the function call is the type of hash - * that is encoded. According to RFC-3447: Public-Key + * \note The \c hash_id set in \p ctx (when calling + * mbedtls_rsa_init() or by calling mbedtls_rsa_set_padding() + * afterwards) selects the hash used for the + * encoding operation and for the mask generation function + * (MGF1). For more details on the encoding operation and the + * mask generation function, consult RFC-3447: Public-Key + * Cryptography Standards (PKCS) #1 v2.1: RSA Cryptography + * Specifications. + * + * \note This function enforces that the provided salt length complies + * with FIPS 186-4 §5.5 (e) and RFC 8017 (PKCS#1 v2.2) §9.1.1 + * step 3. The constraint is that the hash length plus the salt + * length plus 2 bytes must be at most the key length. If this + * constraint is not met, this function returns + * #MBEDTLS_ERR_RSA_BAD_INPUT_DATA. + * + * \param ctx The initialized RSA context to use. + * \param f_rng The RNG function. It must not be \c NULL. + * \param p_rng The RNG context to be passed to \p f_rng. This may be \c NULL + * if \p f_rng doesn't need a context argument. + * \param md_alg The message-digest algorithm used to hash the original data. + * Use #MBEDTLS_MD_NONE for signing raw data. + * \param hashlen The length of the message digest. + * Ths is only used if \p md_alg is #MBEDTLS_MD_NONE. + * \param hash The buffer holding the message digest or raw data. + * If \p md_alg is #MBEDTLS_MD_NONE, this must be a readable + * buffer of length \p hashlen Bytes. If \p md_alg is not + * #MBEDTLS_MD_NONE, it must be a readable buffer of length + * the size of the hash corresponding to \p md_alg. + * \param saltlen The length of the salt that should be used. + * If passed #MBEDTLS_RSA_SALT_LEN_ANY, the function will use + * the largest possible salt length up to the hash length, + * which is the largest permitted by some standards including + * FIPS 186-4 §5.5. + * \param sig The buffer to hold the signature. This must be a writable + * buffer of length \c ctx->len Bytes. For example, \c 256 Bytes + * for an 2048-bit RSA modulus. A buffer length of + * #MBEDTLS_MPI_MAX_SIZE is always safe. + * + * \return \c 0 if the signing operation was successful. + * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure. + */ +int mbedtls_rsa_rsassa_pss_sign_ext( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + mbedtls_md_type_t md_alg, + unsigned int hashlen, + const unsigned char *hash, + int saltlen, + unsigned char *sig ); + +/** + * \brief This function performs a PKCS#1 v2.1 PSS signature + * operation (RSASSA-PSS-SIGN). + * + * \note The \c hash_id set in \p ctx (when calling + * mbedtls_rsa_init() or by calling mbedtls_rsa_set_padding() + * afterwards) selects the hash used for the + * encoding operation and for the mask generation function + * (MGF1). For more details on the encoding operation and the + * mask generation function, consult RFC-3447: Public-Key * Cryptography Standards (PKCS) #1 v2.1: RSA Cryptography - * Specifications it is advised to keep both hashes the - * same. + * Specifications. * * \note This function always uses the maximum possible salt size, * up to the length of the payload hash. This choice of salt @@ -1035,7 +1079,7 @@ int mbedtls_rsa_rsassa_pkcs1_v15_sign( mbedtls_rsa_context *ctx, * \param md_alg The message-digest algorithm used to hash the original data. * Use #MBEDTLS_MD_NONE for signing raw data. * \param hashlen The length of the message digest. - * Ths is only used if \p md_alg is #MBEDTLS_MD_NONE. + * This is only used if \p md_alg is #MBEDTLS_MD_NONE. * \param hash The buffer holding the message digest or raw data. * If \p md_alg is #MBEDTLS_MD_NONE, this must be a readable * buffer of length \p hashlen Bytes. If \p md_alg is not @@ -1161,16 +1205,15 @@ int mbedtls_rsa_rsassa_pkcs1_v15_verify( mbedtls_rsa_context *ctx, * \brief This function performs a PKCS#1 v2.1 PSS verification * operation (RSASSA-PSS-VERIFY). * - * The hash function for the MGF mask generating function - * is that specified in the RSA context. - * - * \note The \p hash_id in the RSA context is the one used for the - * verification. \p md_alg in the function call is the type of - * hash that is verified. According to RFC-3447: Public-Key + * \note The \c hash_id set in \p ctx (when calling + * mbedtls_rsa_init() or by calling mbedtls_rsa_set_padding() + * afterwards) selects the hash used for the + * encoding operation and for the mask generation function + * (MGF1). For more details on the encoding operation and the + * mask generation function, consult RFC-3447: Public-Key * Cryptography Standards (PKCS) #1 v2.1: RSA Cryptography - * Specifications it is advised to keep both hashes the - * same. If \p hash_id in the RSA context is unset, - * the \p md_alg from the function call is used. + * Specifications. If the \c hash_id set in \p ctx is + * #MBEDTLS_MD_NONE, the \p md_alg parameter is used. * * \deprecated It is deprecated and discouraged to call this function * in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library @@ -1218,13 +1261,12 @@ int mbedtls_rsa_rsassa_pss_verify( mbedtls_rsa_context *ctx, * \brief This function performs a PKCS#1 v2.1 PSS verification * operation (RSASSA-PSS-VERIFY). * - * The hash function for the MGF mask generating function - * is that specified in \p mgf1_hash_id. - * * \note The \p sig buffer must be as large as the size * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used. * - * \note The \p hash_id in the RSA context is ignored. + * \note The \c hash_id set in \p ctx (when calling + * mbedtls_rsa_init() or by calling mbedtls_rsa_set_padding() + * afterwards) is ignored. * * \param ctx The initialized RSA public key context to use. * \param f_rng The RNG function to use. If \p mode is #MBEDTLS_RSA_PRIVATE, @@ -1243,7 +1285,13 @@ int mbedtls_rsa_rsassa_pss_verify( mbedtls_rsa_context *ctx, * buffer of length \p hashlen Bytes. If \p md_alg is not * #MBEDTLS_MD_NONE, it must be a readable buffer of length * the size of the hash corresponding to \p md_alg. - * \param mgf1_hash_id The message digest used for mask generation. + * \param mgf1_hash_id The message digest algorithm used for the + * verification operation and the mask generation + * function (MGF1). For more details on the encoding + * operation and the mask generation function, consult + * RFC-3447: Public-Key Cryptography Standards + * (PKCS) #1 v2.1: RSA Cryptography + * Specifications. * \param expected_salt_len The length of the salt used in padding. Use * #MBEDTLS_RSA_SALT_LEN_ANY to accept any salt length. * \param sig The buffer holding the signature. This must be a readable diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/rsa_internal.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/rsa_internal.h index 953cb7b81d7..d55492bb16b 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/rsa_internal.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/rsa_internal.h @@ -36,13 +36,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -56,39 +50,18 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** - * */ #ifndef MBEDTLS_RSA_INTERNAL_H #define MBEDTLS_RSA_INTERNAL_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "bignum.h" +#include "mbedtls/bignum.h" #ifdef __cplusplus extern "C" { diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/sha1.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/sha1.h index 60c514a49ec..4c3251b4a12 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/sha1.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/sha1.h @@ -12,13 +12,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -31,33 +25,12 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_SHA1_H #define MBEDTLS_SHA1_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif @@ -66,8 +39,10 @@ #include /* MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED is deprecated and should not be used. */ -#define MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED -0x0035 /**< SHA-1 hardware accelerator failed */ -#define MBEDTLS_ERR_SHA1_BAD_INPUT_DATA -0x0073 /**< SHA-1 input data was malformed. */ +/** SHA-1 hardware accelerator failed */ +#define MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED -0x0035 +/** SHA-1 input data was malformed. */ +#define MBEDTLS_ERR_SHA1_BAD_INPUT_DATA -0x0073 #ifdef __cplusplus extern "C" { diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/sha256.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/sha256.h index b1881e183c4..5b54be21425 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/sha256.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/sha256.h @@ -8,13 +8,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -27,33 +21,12 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_SHA256_H #define MBEDTLS_SHA256_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif @@ -62,8 +35,10 @@ #include /* MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED is deprecated and should not be used. */ -#define MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED -0x0037 /**< SHA-256 hardware accelerator failed */ -#define MBEDTLS_ERR_SHA256_BAD_INPUT_DATA -0x0074 /**< SHA-256 input data was malformed. */ +/** SHA-256 hardware accelerator failed */ +#define MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED -0x0037 +/** SHA-256 input data was malformed. */ +#define MBEDTLS_ERR_SHA256_BAD_INPUT_DATA -0x0074 #ifdef __cplusplus extern "C" { @@ -262,6 +237,9 @@ MBEDTLS_DEPRECATED void mbedtls_sha256_process( mbedtls_sha256_context *ctx, * be a writable buffer of length \c 32 Bytes. * \param is224 Determines which function to use. This must be * either \c 0 for SHA-256, or \c 1 for SHA-224. + * + * \return \c 0 on success. + * \return A negative error code on failure. */ int mbedtls_sha256_ret( const unsigned char *input, size_t ilen, diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/sha512.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/sha512.h index 5e5a15e0008..cca47c2fe62 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/sha512.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/sha512.h @@ -7,13 +7,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -26,33 +20,12 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_SHA512_H #define MBEDTLS_SHA512_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif @@ -61,8 +34,10 @@ #include /* MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED is deprecated and should not be used. */ -#define MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED -0x0039 /**< SHA-512 hardware accelerator failed */ -#define MBEDTLS_ERR_SHA512_BAD_INPUT_DATA -0x0075 /**< SHA-512 input data was malformed. */ +/** SHA-512 hardware accelerator failed */ +#define MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED -0x0039 +/** SHA-512 input data was malformed. */ +#define MBEDTLS_ERR_SHA512_BAD_INPUT_DATA -0x0075 #ifdef __cplusplus extern "C" { @@ -84,8 +59,10 @@ typedef struct mbedtls_sha512_context uint64_t total[2]; /*!< The number of Bytes processed. */ uint64_t state[8]; /*!< The intermediate digest state. */ unsigned char buffer[128]; /*!< The data block being processed. */ +#if !defined(MBEDTLS_SHA512_NO_SHA384) int is384; /*!< Determines which function to use: 0: Use SHA-512, or 1: Use SHA-384. */ +#endif } mbedtls_sha512_context; @@ -126,7 +103,11 @@ void mbedtls_sha512_clone( mbedtls_sha512_context *dst, * * \param ctx The SHA-512 context to use. This must be initialized. * \param is384 Determines which function to use. This must be - * either \c for SHA-512, or \c 1 for SHA-384. + * either \c 0 for SHA-512, or \c 1 for SHA-384. + * + * \note When \c MBEDTLS_SHA512_NO_SHA384 is defined, \p is384 must + * be \c 0, or the function will return + * #MBEDTLS_ERR_SHA512_BAD_INPUT_DATA. * * \return \c 0 on success. * \return A negative error code on failure. @@ -194,6 +175,9 @@ int mbedtls_internal_sha512_process( mbedtls_sha512_context *ctx, * \param ctx The SHA-512 context to use. This must be initialized. * \param is384 Determines which function to use. This must be either * \c 0 for SHA-512 or \c 1 for SHA-384. + * + * \note When \c MBEDTLS_SHA512_NO_SHA384 is defined, \p is384 must + * be \c 0, or the function will fail to work. */ MBEDTLS_DEPRECATED void mbedtls_sha512_starts( mbedtls_sha512_context *ctx, int is384 ); @@ -264,6 +248,10 @@ MBEDTLS_DEPRECATED void mbedtls_sha512_process( * \param is384 Determines which function to use. This must be either * \c 0 for SHA-512, or \c 1 for SHA-384. * + * \note When \c MBEDTLS_SHA512_NO_SHA384 is defined, \p is384 must + * be \c 0, or the function will return + * #MBEDTLS_ERR_SHA512_BAD_INPUT_DATA. + * * \return \c 0 on success. * \return A negative error code on failure. */ @@ -298,6 +286,9 @@ int mbedtls_sha512_ret( const unsigned char *input, * be a writable buffer of length \c 64 Bytes. * \param is384 Determines which function to use. This must be either * \c 0 for SHA-512, or \c 1 for SHA-384. + * + * \note When \c MBEDTLS_SHA512_NO_SHA384 is defined, \p is384 must + * be \c 0, or the function will fail to work. */ MBEDTLS_DEPRECATED void mbedtls_sha512( const unsigned char *input, size_t ilen, diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ssl.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ssl.h index 0abeb430e49..209dbf6053c 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ssl.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ssl.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,53 +18,37 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_SSL_H #define MBEDTLS_SSL_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "bignum.h" -#include "ecp.h" +#include "mbedtls/bignum.h" +#include "mbedtls/ecp.h" -#include "ssl_ciphersuites.h" +#include "mbedtls/ssl_ciphersuites.h" #if defined(MBEDTLS_X509_CRT_PARSE_C) -#include "x509_crt.h" -#include "x509_crl.h" +#include "mbedtls/x509_crt.h" +#include "mbedtls/x509_crl.h" #endif #if defined(MBEDTLS_DHM_C) -#include "dhm.h" +#include "mbedtls/dhm.h" #endif -#if defined(MBEDTLS_ECDH_C) -#include "ecdh.h" +/* Adding guard for MBEDTLS_ECDSA_C to ensure no compile errors due + * to guards also being in ssl_srv.c and ssl_cli.c. There is a gap + * in functionality that access to ecdh_ctx structure is needed for + * MBEDTLS_ECDSA_C which does not seem correct. + */ +#if defined(MBEDTLS_ECDH_C) || defined(MBEDTLS_ECDSA_C) +#include "mbedtls/ecdh.h" #endif #if defined(MBEDTLS_ZLIB_SUPPORT) @@ -87,68 +65,132 @@ #endif #if defined(MBEDTLS_HAVE_TIME) -#include "platform_time.h" +#include "mbedtls/platform_time.h" #endif +#if defined(MBEDTLS_USE_PSA_CRYPTO) +#include "psa/crypto.h" +#endif /* MBEDTLS_USE_PSA_CRYPTO */ + /* * SSL Error codes */ -#define MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE -0x7080 /**< The requested feature is not available. */ -#define MBEDTLS_ERR_SSL_BAD_INPUT_DATA -0x7100 /**< Bad input parameters to function. */ -#define MBEDTLS_ERR_SSL_INVALID_MAC -0x7180 /**< Verification of the message MAC failed. */ -#define MBEDTLS_ERR_SSL_INVALID_RECORD -0x7200 /**< An invalid SSL record was received. */ -#define MBEDTLS_ERR_SSL_CONN_EOF -0x7280 /**< The connection indicated an EOF. */ -#define MBEDTLS_ERR_SSL_UNKNOWN_CIPHER -0x7300 /**< An unknown cipher was received. */ -#define MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN -0x7380 /**< The server has no ciphersuites in common with the client. */ -#define MBEDTLS_ERR_SSL_NO_RNG -0x7400 /**< No RNG was provided to the SSL module. */ -#define MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE -0x7480 /**< No client certification received from the client, but required by the authentication mode. */ -#define MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE -0x7500 /**< Our own certificate(s) is/are too large to send in an SSL message. */ -#define MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED -0x7580 /**< The own certificate is not set, but needed by the server. */ -#define MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED -0x7600 /**< The own private key or pre-shared key is not set, but needed. */ -#define MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED -0x7680 /**< No CA Chain is set, but required to operate. */ -#define MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE -0x7700 /**< An unexpected message was received from our peer. */ -#define MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE -0x7780 /**< A fatal alert message was received from our peer. */ -#define MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED -0x7800 /**< Verification of our peer failed. */ -#define MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY -0x7880 /**< The peer notified us that the connection is going to be closed. */ -#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO -0x7900 /**< Processing of the ClientHello handshake message failed. */ -#define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO -0x7980 /**< Processing of the ServerHello handshake message failed. */ -#define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE -0x7A00 /**< Processing of the Certificate handshake message failed. */ -#define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST -0x7A80 /**< Processing of the CertificateRequest handshake message failed. */ -#define MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE -0x7B00 /**< Processing of the ServerKeyExchange handshake message failed. */ -#define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE -0x7B80 /**< Processing of the ServerHelloDone handshake message failed. */ -#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE -0x7C00 /**< Processing of the ClientKeyExchange handshake message failed. */ -#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP -0x7C80 /**< Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public. */ -#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS -0x7D00 /**< Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret. */ -#define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY -0x7D80 /**< Processing of the CertificateVerify handshake message failed. */ -#define MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC -0x7E00 /**< Processing of the ChangeCipherSpec handshake message failed. */ -#define MBEDTLS_ERR_SSL_BAD_HS_FINISHED -0x7E80 /**< Processing of the Finished handshake message failed. */ -#define MBEDTLS_ERR_SSL_ALLOC_FAILED -0x7F00 /**< Memory allocation failed */ -#define MBEDTLS_ERR_SSL_HW_ACCEL_FAILED -0x7F80 /**< Hardware acceleration function returned with error */ -#define MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH -0x6F80 /**< Hardware acceleration function skipped / left alone data */ -#define MBEDTLS_ERR_SSL_COMPRESSION_FAILED -0x6F00 /**< Processing of the compression / decompression failed */ -#define MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION -0x6E80 /**< Handshake protocol not within min/max boundaries */ -#define MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET -0x6E00 /**< Processing of the NewSessionTicket handshake message failed. */ -#define MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED -0x6D80 /**< Session ticket has expired. */ -#define MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH -0x6D00 /**< Public key type mismatch (eg, asked for RSA key exchange and presented EC key) */ -#define MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY -0x6C80 /**< Unknown identity received (eg, PSK identity) */ -#define MBEDTLS_ERR_SSL_INTERNAL_ERROR -0x6C00 /**< Internal error (eg, unexpected failure in lower-level module) */ -#define MBEDTLS_ERR_SSL_COUNTER_WRAPPING -0x6B80 /**< A counter would wrap (eg, too many messages exchanged). */ -#define MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO -0x6B00 /**< Unexpected message at ServerHello in renegotiation. */ -#define MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED -0x6A80 /**< DTLS client must retry for hello verification */ -#define MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL -0x6A00 /**< A buffer is too small to receive or write a message */ -#define MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE -0x6980 /**< None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages). */ -#define MBEDTLS_ERR_SSL_WANT_READ -0x6900 /**< No data of requested type currently available on underlying transport. */ -#define MBEDTLS_ERR_SSL_WANT_WRITE -0x6880 /**< Connection requires a write call. */ -#define MBEDTLS_ERR_SSL_TIMEOUT -0x6800 /**< The operation timed out. */ -#define MBEDTLS_ERR_SSL_CLIENT_RECONNECT -0x6780 /**< The client initiated a reconnect from the same port. */ -#define MBEDTLS_ERR_SSL_UNEXPECTED_RECORD -0x6700 /**< Record header looks valid but is not expected. */ -#define MBEDTLS_ERR_SSL_NON_FATAL -0x6680 /**< The alert message received indicates a non-fatal error. */ -#define MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH -0x6600 /**< Couldn't set the hash for verifying CertificateVerify */ -#define MBEDTLS_ERR_SSL_CONTINUE_PROCESSING -0x6580 /**< Internal-only message signaling that further message-processing should be done */ -#define MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS -0x6500 /**< The asynchronous operation is not completed yet. */ -#define MBEDTLS_ERR_SSL_EARLY_MESSAGE -0x6480 /**< Internal-only message signaling that a message arrived early. */ -#define MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS -0x7000 /**< A cryptographic operation is in progress. Try again later. */ -#define MBEDTLS_ERR_SSL_BAD_CONFIG -0x5E80 /**< Invalid value in SSL config */ +/** The requested feature is not available. */ +#define MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE -0x7080 +/** Bad input parameters to function. */ +#define MBEDTLS_ERR_SSL_BAD_INPUT_DATA -0x7100 +/** Verification of the message MAC failed. */ +#define MBEDTLS_ERR_SSL_INVALID_MAC -0x7180 +/** An invalid SSL record was received. */ +#define MBEDTLS_ERR_SSL_INVALID_RECORD -0x7200 +/** The connection indicated an EOF. */ +#define MBEDTLS_ERR_SSL_CONN_EOF -0x7280 +/** An unknown cipher was received. */ +#define MBEDTLS_ERR_SSL_UNKNOWN_CIPHER -0x7300 +/** The server has no ciphersuites in common with the client. */ +#define MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN -0x7380 +/** No RNG was provided to the SSL module. */ +#define MBEDTLS_ERR_SSL_NO_RNG -0x7400 +/** No client certification received from the client, but required by the authentication mode. */ +#define MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE -0x7480 +/** Our own certificate(s) is/are too large to send in an SSL message. */ +#define MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE -0x7500 +/** The own certificate is not set, but needed by the server. */ +#define MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED -0x7580 +/** The own private key or pre-shared key is not set, but needed. */ +#define MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED -0x7600 +/** No CA Chain is set, but required to operate. */ +#define MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED -0x7680 +/** An unexpected message was received from our peer. */ +#define MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE -0x7700 +/** A fatal alert message was received from our peer. */ +#define MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE -0x7780 +/** Verification of our peer failed. */ +#define MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED -0x7800 +/** The peer notified us that the connection is going to be closed. */ +#define MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY -0x7880 +/** Processing of the ClientHello handshake message failed. */ +#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO -0x7900 +/** Processing of the ServerHello handshake message failed. */ +#define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO -0x7980 +/** Processing of the Certificate handshake message failed. */ +#define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE -0x7A00 +/** Processing of the CertificateRequest handshake message failed. */ +#define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST -0x7A80 +/** Processing of the ServerKeyExchange handshake message failed. */ +#define MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE -0x7B00 +/** Processing of the ServerHelloDone handshake message failed. */ +#define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE -0x7B80 +/** Processing of the ClientKeyExchange handshake message failed. */ +#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE -0x7C00 +/** Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public. */ +#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP -0x7C80 +/** Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret. */ +#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS -0x7D00 +/** Processing of the CertificateVerify handshake message failed. */ +#define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY -0x7D80 +/** Processing of the ChangeCipherSpec handshake message failed. */ +#define MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC -0x7E00 +/** Processing of the Finished handshake message failed. */ +#define MBEDTLS_ERR_SSL_BAD_HS_FINISHED -0x7E80 +/** Memory allocation failed */ +#define MBEDTLS_ERR_SSL_ALLOC_FAILED -0x7F00 +/** Hardware acceleration function returned with error */ +#define MBEDTLS_ERR_SSL_HW_ACCEL_FAILED -0x7F80 +/** Hardware acceleration function skipped / left alone data */ +#define MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH -0x6F80 +/** Processing of the compression / decompression failed */ +#define MBEDTLS_ERR_SSL_COMPRESSION_FAILED -0x6F00 +/** Handshake protocol not within min/max boundaries */ +#define MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION -0x6E80 +/** Processing of the NewSessionTicket handshake message failed. */ +#define MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET -0x6E00 +/** Session ticket has expired. */ +#define MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED -0x6D80 +/** Public key type mismatch (eg, asked for RSA key exchange and presented EC key) */ +#define MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH -0x6D00 +/** Unknown identity received (eg, PSK identity) */ +#define MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY -0x6C80 +/** Internal error (eg, unexpected failure in lower-level module) */ +#define MBEDTLS_ERR_SSL_INTERNAL_ERROR -0x6C00 +/** A counter would wrap (eg, too many messages exchanged). */ +#define MBEDTLS_ERR_SSL_COUNTER_WRAPPING -0x6B80 +/** Unexpected message at ServerHello in renegotiation. */ +#define MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO -0x6B00 +/** DTLS client must retry for hello verification */ +#define MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED -0x6A80 +/** A buffer is too small to receive or write a message */ +#define MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL -0x6A00 +/** None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages). */ +#define MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE -0x6980 +/** No data of requested type currently available on underlying transport. */ +#define MBEDTLS_ERR_SSL_WANT_READ -0x6900 +/** Connection requires a write call. */ +#define MBEDTLS_ERR_SSL_WANT_WRITE -0x6880 +/** The operation timed out. */ +#define MBEDTLS_ERR_SSL_TIMEOUT -0x6800 +/** The client initiated a reconnect from the same port. */ +#define MBEDTLS_ERR_SSL_CLIENT_RECONNECT -0x6780 +/** Record header looks valid but is not expected. */ +#define MBEDTLS_ERR_SSL_UNEXPECTED_RECORD -0x6700 +/** The alert message received indicates a non-fatal error. */ +#define MBEDTLS_ERR_SSL_NON_FATAL -0x6680 +/** Couldn't set the hash for verifying CertificateVerify */ +#define MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH -0x6600 +/** Internal-only message signaling that further message-processing should be done */ +#define MBEDTLS_ERR_SSL_CONTINUE_PROCESSING -0x6580 +/** The asynchronous operation is not completed yet. */ +#define MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS -0x6500 +/** Internal-only message signaling that a message arrived early. */ +#define MBEDTLS_ERR_SSL_EARLY_MESSAGE -0x6480 +/** An encrypted DTLS-frame with an unexpected CID was received. */ +#define MBEDTLS_ERR_SSL_UNEXPECTED_CID -0x6000 +/** An operation failed due to an unexpected version or configuration. */ +#define MBEDTLS_ERR_SSL_VERSION_MISMATCH -0x5F00 +/** A cryptographic operation is in progress. Try again later. */ +#define MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS -0x7000 +/** Invalid value in SSL config */ +#define MBEDTLS_ERR_SSL_BAD_CONFIG -0x5E80 /* * Various constants @@ -158,6 +200,7 @@ #define MBEDTLS_SSL_MINOR_VERSION_1 1 /*!< TLS v1.0 */ #define MBEDTLS_SSL_MINOR_VERSION_2 2 /*!< TLS v1.1 */ #define MBEDTLS_SSL_MINOR_VERSION_3 3 /*!< TLS v1.2 */ +#define MBEDTLS_SSL_MINOR_VERSION_4 4 /*!< TLS v1.3 (experimental) */ #define MBEDTLS_SSL_TRANSPORT_STREAM 0 /*!< TLS */ #define MBEDTLS_SSL_TRANSPORT_DATAGRAM 1 /*!< DTLS */ @@ -185,6 +228,9 @@ #define MBEDTLS_SSL_EXTENDED_MS_DISABLED 0 #define MBEDTLS_SSL_EXTENDED_MS_ENABLED 1 +#define MBEDTLS_SSL_CID_DISABLED 0 +#define MBEDTLS_SSL_CID_ENABLED 1 + #define MBEDTLS_SSL_ETM_DISABLED 0 #define MBEDTLS_SSL_ETM_ENABLED 1 @@ -231,6 +277,9 @@ #define MBEDTLS_SSL_CERT_REQ_CA_LIST_ENABLED 1 #define MBEDTLS_SSL_CERT_REQ_CA_LIST_DISABLED 0 +#define MBEDTLS_SSL_DTLS_SRTP_MKI_UNSUPPORTED 0 +#define MBEDTLS_SSL_DTLS_SRTP_MKI_SUPPORTED 1 + /* * Default range for DTLS retransmission timer value, in milliseconds. * RFC 6347 4.2.4.1 says from 1 second to 60 seconds. @@ -281,6 +330,25 @@ #define MBEDTLS_SSL_DTLS_MAX_BUFFERING 32768 #endif +/* + * Maximum length of CIDs for incoming and outgoing messages. + */ +#if !defined(MBEDTLS_SSL_CID_IN_LEN_MAX) +#define MBEDTLS_SSL_CID_IN_LEN_MAX 32 +#endif + +#if !defined(MBEDTLS_SSL_CID_OUT_LEN_MAX) +#define MBEDTLS_SSL_CID_OUT_LEN_MAX 32 +#endif + +#if !defined(MBEDTLS_SSL_CID_PADDING_GRANULARITY) +#define MBEDTLS_SSL_CID_PADDING_GRANULARITY 16 +#endif + +#if !defined(MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY) +#define MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY 1 +#endif + /* \} name SECTION: Module settings */ /* @@ -328,6 +396,7 @@ #define MBEDTLS_SSL_MSG_ALERT 21 #define MBEDTLS_SSL_MSG_HANDSHAKE 22 #define MBEDTLS_SSL_MSG_APPLICATION_DATA 23 +#define MBEDTLS_SSL_MSG_CID 25 #define MBEDTLS_SSL_ALERT_LEVEL_WARNING 1 #define MBEDTLS_SSL_ALERT_LEVEL_FATAL 2 @@ -390,6 +459,8 @@ #define MBEDTLS_TLS_EXT_SIG_ALG 13 +#define MBEDTLS_TLS_EXT_USE_SRTP 14 + #define MBEDTLS_TLS_EXT_ALPN 16 #define MBEDTLS_TLS_EXT_ENCRYPT_THEN_MAC 22 /* 0x16 */ @@ -397,6 +468,17 @@ #define MBEDTLS_TLS_EXT_SESSION_TICKET 35 +/* The value of the CID extension is still TBD as of + * draft-ietf-tls-dtls-connection-id-05 + * (https://tools.ietf.org/html/draft-ietf-tls-dtls-connection-id-05). + * + * A future minor revision of Mbed TLS may change the default value of + * this option to match evolving standards and usage. + */ +#if !defined(MBEDTLS_TLS_EXT_CID) +#define MBEDTLS_TLS_EXT_CID 254 /* TBD */ +#endif + #define MBEDTLS_TLS_EXT_ECJPAKE_KKPP 256 /* experimental */ #define MBEDTLS_TLS_EXT_RENEGOTIATION_INFO 0xFF01 @@ -475,6 +557,18 @@ typedef enum } mbedtls_ssl_states; +/* + * The tls_prf function types. + */ +typedef enum +{ + MBEDTLS_SSL_TLS_PRF_NONE, + MBEDTLS_SSL_TLS_PRF_SSL3, + MBEDTLS_SSL_TLS_PRF_TLS1, + MBEDTLS_SSL_TLS_PRF_SHA384, + MBEDTLS_SSL_TLS_PRF_SHA256 +} +mbedtls_tls_prf_types; /** * \brief Callback type: send data on the network. * @@ -506,10 +600,11 @@ typedef int mbedtls_ssl_send_t( void *ctx, * \param buf Buffer to write the received data to * \param len Length of the receive buffer * - * \return The callback must return the number of bytes received, - * or a non-zero error code. - * If performing non-blocking I/O, \c MBEDTLS_ERR_SSL_WANT_READ + * \returns If data has been received, the positive number of bytes received. + * \returns \c 0 if the connection has been closed. + * \returns If performing non-blocking I/O, \c MBEDTLS_ERR_SSL_WANT_READ * must be returned when the operation would block. + * \returns Another negative error code on other kinds of failures. * * \note The callback may receive fewer bytes than the length of the * buffer. It must always return the number of bytes actually @@ -812,11 +907,77 @@ typedef int mbedtls_ssl_async_resume_t( mbedtls_ssl_context *ssl, typedef void mbedtls_ssl_async_cancel_t( mbedtls_ssl_context *ssl ); #endif /* MBEDTLS_SSL_ASYNC_PRIVATE */ +#if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED) && \ + !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE) +#define MBEDTLS_SSL_PEER_CERT_DIGEST_MAX_LEN 48 +#if defined(MBEDTLS_SHA256_C) +#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE MBEDTLS_MD_SHA256 +#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN 32 +#elif defined(MBEDTLS_SHA512_C) +#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE MBEDTLS_MD_SHA384 +#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN 48 +#elif defined(MBEDTLS_SHA1_C) +#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE MBEDTLS_MD_SHA1 +#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN 20 +#else +/* This is already checked in check_config.h, but be sure. */ +#error "Bad configuration - need SHA-1, SHA-256 or SHA-512 enabled to compute digest of peer CRT." +#endif +#endif /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED && + !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */ + +#if defined(MBEDTLS_SSL_DTLS_SRTP) + +#define MBEDTLS_TLS_SRTP_MAX_MKI_LENGTH 255 +#define MBEDTLS_TLS_SRTP_MAX_PROFILE_LIST_LENGTH 4 +/* + * For code readability use a typedef for DTLS-SRTP profiles + * + * Use_srtp extension protection profiles values as defined in + * http://www.iana.org/assignments/srtp-protection/srtp-protection.xhtml + * + * Reminder: if this list is expanded mbedtls_ssl_check_srtp_profile_value + * must be updated too. + */ +#define MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80 ( (uint16_t) 0x0001) +#define MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32 ( (uint16_t) 0x0002) +#define MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80 ( (uint16_t) 0x0005) +#define MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32 ( (uint16_t) 0x0006) +/* This one is not iana defined, but for code readability. */ +#define MBEDTLS_TLS_SRTP_UNSET ( (uint16_t) 0x0000) + +typedef uint16_t mbedtls_ssl_srtp_profile; + +typedef struct mbedtls_dtls_srtp_info_t +{ + /*! The SRTP profile that was negotiated. */ + mbedtls_ssl_srtp_profile chosen_dtls_srtp_profile; + /*! The length of mki_value. */ + uint16_t mki_len; + /*! The mki_value used, with max size of 256 bytes. */ + unsigned char mki_value[MBEDTLS_TLS_SRTP_MAX_MKI_LENGTH]; +} +mbedtls_dtls_srtp_info; + +#endif /* MBEDTLS_SSL_DTLS_SRTP */ + /* * This structure is used for storing current session data. + * + * Note: when changing this definition, we need to check and update: + * - in tests/suites/test_suite_ssl.function: + * ssl_populate_session() and ssl_serialize_session_save_load() + * - in library/ssl_tls.c: + * mbedtls_ssl_session_init() and mbedtls_ssl_session_free() + * mbedtls_ssl_session_save() and ssl_session_load() + * ssl_session_copy() */ struct mbedtls_ssl_session { +#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) + unsigned char mfl_code; /*!< MaxFragmentLength negotiated by peer */ +#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */ + #if defined(MBEDTLS_HAVE_TIME) mbedtls_time_t start; /*!< starting time */ #endif @@ -827,7 +988,15 @@ struct mbedtls_ssl_session unsigned char master[48]; /*!< the master secret */ #if defined(MBEDTLS_X509_CRT_PARSE_C) - mbedtls_x509_crt *peer_cert; /*!< peer X.509 cert chain */ +#if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE) + mbedtls_x509_crt *peer_cert; /*!< peer X.509 cert chain */ +#else /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */ + /*! The digest of the peer's end-CRT. This must be kept to detect CRT + * changes during renegotiation, mitigating the triple handshake attack. */ + unsigned char *peer_cert_digest; + size_t peer_cert_digest_len; + mbedtls_md_type_t peer_cert_digest_type; +#endif /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */ #endif /* MBEDTLS_X509_CRT_PARSE_C */ uint32_t verify_result; /*!< verification result */ @@ -837,10 +1006,6 @@ struct mbedtls_ssl_session uint32_t ticket_lifetime; /*!< ticket lifetime hint */ #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */ -#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) - unsigned char mfl_code; /*!< MaxFragmentLength negotiated by peer */ -#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */ - #if defined(MBEDTLS_SSL_TRUNCATED_HMAC) int trunc_hmac; /*!< flag for truncated hmac activation */ #endif /* MBEDTLS_SSL_TRUNCATED_HMAC */ @@ -855,7 +1020,98 @@ struct mbedtls_ssl_session */ struct mbedtls_ssl_config { - /* Group items by size (largest first) to minimize padding overhead */ + /* Group items by size and reorder them to maximize usage of immediate offset access. */ + + /* + * Numerical settings (char) + */ + + unsigned char max_major_ver; /*!< max. major version used */ + unsigned char max_minor_ver; /*!< max. minor version used */ + unsigned char min_major_ver; /*!< min. major version used */ + unsigned char min_minor_ver; /*!< min. minor version used */ + + /* + * Flags (could be bit-fields to save RAM, but separate bytes make + * the code smaller on architectures with an instruction for direct + * byte access). + */ + + uint8_t endpoint /*bool*/; /*!< 0: client, 1: server */ + uint8_t transport /*bool*/; /*!< stream (TLS) or datagram (DTLS) */ + uint8_t authmode /*2 bits*/; /*!< MBEDTLS_SSL_VERIFY_XXX */ + /* needed even with renego disabled for LEGACY_BREAK_HANDSHAKE */ + uint8_t allow_legacy_renegotiation /*2 bits*/; /*!< MBEDTLS_LEGACY_XXX */ +#if defined(MBEDTLS_ARC4_C) + uint8_t arc4_disabled /*bool*/; /*!< blacklist RC4 ciphersuites? */ +#endif +#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) + uint8_t mfl_code /*3 bits*/; /*!< desired fragment length */ +#endif +#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC) + uint8_t encrypt_then_mac /*bool*/; /*!< negotiate encrypt-then-mac? */ +#endif +#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET) + uint8_t extended_ms /*bool*/; /*!< negotiate extended master secret? */ +#endif +#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY) + uint8_t anti_replay /*bool*/; /*!< detect and prevent replay? */ +#endif +#if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING) + uint8_t cbc_record_splitting /*bool*/; /*!< do cbc record splitting */ +#endif +#if defined(MBEDTLS_SSL_RENEGOTIATION) + uint8_t disable_renegotiation /*bool*/; /*!< disable renegotiation? */ +#endif +#if defined(MBEDTLS_SSL_TRUNCATED_HMAC) + uint8_t trunc_hmac /*bool*/; /*!< negotiate truncated hmac? */ +#endif +#if defined(MBEDTLS_SSL_SESSION_TICKETS) + uint8_t session_tickets /*bool*/; /*!< use session tickets? */ +#endif +#if defined(MBEDTLS_SSL_FALLBACK_SCSV) && defined(MBEDTLS_SSL_CLI_C) + uint8_t fallback /*bool*/; /*!< is this a fallback? */ +#endif +#if defined(MBEDTLS_SSL_SRV_C) + uint8_t cert_req_ca_list /*bool*/; /*!< enable sending CA list in + Certificate Request messages? */ +#endif +#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) + uint8_t ignore_unexpected_cid /*bool*/; /*!< Determines whether DTLS + * record with unexpected CID + * should lead to failure. */ +#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ +#if defined(MBEDTLS_SSL_DTLS_SRTP) + uint8_t dtls_srtp_mki_support /*bool*/; /*!< support having mki_value + in the use_srtp extension? */ +#endif + + /* + * Numerical settings (int or larger) + */ + + uint32_t read_timeout; /*!< timeout for mbedtls_ssl_read (ms) */ + +#if defined(MBEDTLS_SSL_PROTO_DTLS) + uint32_t hs_timeout_min; /*!< initial value of the handshake + retransmission timeout (ms) */ + uint32_t hs_timeout_max; /*!< maximum value of the handshake + retransmission timeout (ms) */ +#endif + +#if defined(MBEDTLS_SSL_RENEGOTIATION) + int renego_max_records; /*!< grace period for renegotiation */ + unsigned char renego_period[8]; /*!< value of the record counters + that triggers renegotiation */ +#endif + +#if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT) + unsigned int badmac_limit; /*!< limit of records with a bad MAC */ +#endif + +#if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C) + unsigned int dhm_min_bitlen; /*!< min. bit length of the DHM prime */ +#endif /* * Pointers @@ -889,7 +1145,7 @@ struct mbedtls_ssl_config void *p_vrfy; /*!< context for X.509 verify calllback */ #endif -#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED) +#if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED) /** Callback to retrieve PSK key from identity */ int (*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *, size_t); void *p_psk; /*!< context for PSK callback */ @@ -918,14 +1174,28 @@ struct mbedtls_ssl_config /** Callback to export key block and master secret */ int (*f_export_keys)( void *, const unsigned char *, const unsigned char *, size_t, size_t, size_t ); + /** Callback to export key block, master secret, + * tls_prf and random bytes. Should replace f_export_keys */ + int (*f_export_keys_ext)( void *, const unsigned char *, + const unsigned char *, size_t, size_t, size_t, + const unsigned char[32], const unsigned char[32], + mbedtls_tls_prf_types ); void *p_export_keys; /*!< context for key export callback */ #endif +#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) + size_t cid_len; /*!< The length of CIDs for incoming DTLS records. */ +#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ + #if defined(MBEDTLS_X509_CRT_PARSE_C) const mbedtls_x509_crt_profile *cert_profile; /*!< verification profile */ mbedtls_ssl_key_cert *key_cert; /*!< own certificate/key pair(s) */ mbedtls_x509_crt *ca_chain; /*!< trusted CAs */ mbedtls_x509_crl *ca_crl; /*!< trusted CAs CRLs */ +#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK) + mbedtls_x509_crt_ca_cb_t f_ca_cb; + void *p_ca_cb; +#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */ #endif /* MBEDTLS_X509_CRT_PARSE_C */ #if defined(MBEDTLS_SSL_ASYNC_PRIVATE) @@ -938,7 +1208,7 @@ struct mbedtls_ssl_config void *p_async_config_data; /*!< Configuration data set by mbedtls_ssl_conf_async_private_cb(). */ #endif /* MBEDTLS_SSL_ASYNC_PRIVATE */ -#if defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED) +#if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED) const int *sig_hashes; /*!< allowed signature hashes */ #endif @@ -951,103 +1221,52 @@ struct mbedtls_ssl_config mbedtls_mpi dhm_G; /*!< generator for DHM */ #endif -#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED) - unsigned char *psk; /*!< pre-shared key. This field should - only be set via - mbedtls_ssl_conf_psk() */ - size_t psk_len; /*!< length of the pre-shared key. This - field should only be set via - mbedtls_ssl_conf_psk() */ - unsigned char *psk_identity; /*!< identity for PSK negotiation. This - field should only be set via - mbedtls_ssl_conf_psk() */ - size_t psk_identity_len;/*!< length of identity. This field should - only be set via - mbedtls_ssl_conf_psk() */ -#endif +#if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED) + +#if defined(MBEDTLS_USE_PSA_CRYPTO) + psa_key_id_t psk_opaque; /*!< PSA key slot holding opaque PSK. This field + * should only be set via + * mbedtls_ssl_conf_psk_opaque(). + * If either no PSK or a raw PSK have been + * configured, this has value \c 0. + */ +#endif /* MBEDTLS_USE_PSA_CRYPTO */ + + unsigned char *psk; /*!< The raw pre-shared key. This field should + * only be set via mbedtls_ssl_conf_psk(). + * If either no PSK or an opaque PSK + * have been configured, this has value NULL. */ + size_t psk_len; /*!< The length of the raw pre-shared key. + * This field should only be set via + * mbedtls_ssl_conf_psk(). + * Its value is non-zero if and only if + * \c psk is not \c NULL. */ + + unsigned char *psk_identity; /*!< The PSK identity for PSK negotiation. + * This field should only be set via + * mbedtls_ssl_conf_psk(). + * This is set if and only if either + * \c psk or \c psk_opaque are set. */ + size_t psk_identity_len;/*!< The length of PSK identity. + * This field should only be set via + * mbedtls_ssl_conf_psk(). + * Its value is non-zero if and only if + * \c psk is not \c NULL or \c psk_opaque + * is not \c 0. */ +#endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */ #if defined(MBEDTLS_SSL_ALPN) const char **alpn_list; /*!< ordered list of protocols */ #endif - /* - * Numerical settings (int then char) - */ - - uint32_t read_timeout; /*!< timeout for mbedtls_ssl_read (ms) */ - -#if defined(MBEDTLS_SSL_PROTO_DTLS) - uint32_t hs_timeout_min; /*!< initial value of the handshake - retransmission timeout (ms) */ - uint32_t hs_timeout_max; /*!< maximum value of the handshake - retransmission timeout (ms) */ -#endif - -#if defined(MBEDTLS_SSL_RENEGOTIATION) - int renego_max_records; /*!< grace period for renegotiation */ - unsigned char renego_period[8]; /*!< value of the record counters - that triggers renegotiation */ -#endif - -#if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT) - unsigned int badmac_limit; /*!< limit of records with a bad MAC */ -#endif - -#if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C) - unsigned int dhm_min_bitlen; /*!< min. bit length of the DHM prime */ -#endif - - unsigned char max_major_ver; /*!< max. major version used */ - unsigned char max_minor_ver; /*!< max. minor version used */ - unsigned char min_major_ver; /*!< min. major version used */ - unsigned char min_minor_ver; /*!< min. minor version used */ - - /* - * Flags (bitfields) - */ - - unsigned int endpoint : 1; /*!< 0: client, 1: server */ - unsigned int transport : 1; /*!< stream (TLS) or datagram (DTLS) */ - unsigned int authmode : 2; /*!< MBEDTLS_SSL_VERIFY_XXX */ - /* needed even with renego disabled for LEGACY_BREAK_HANDSHAKE */ - unsigned int allow_legacy_renegotiation : 2 ; /*!< MBEDTLS_LEGACY_XXX */ -#if defined(MBEDTLS_ARC4_C) - unsigned int arc4_disabled : 1; /*!< blacklist RC4 ciphersuites? */ -#endif -#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) - unsigned int mfl_code : 3; /*!< desired fragment length */ -#endif -#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC) - unsigned int encrypt_then_mac : 1 ; /*!< negotiate encrypt-then-mac? */ -#endif -#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET) - unsigned int extended_ms : 1; /*!< negotiate extended master secret? */ -#endif -#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY) - unsigned int anti_replay : 1; /*!< detect and prevent replay? */ -#endif -#if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING) - unsigned int cbc_record_splitting : 1; /*!< do cbc record splitting */ -#endif -#if defined(MBEDTLS_SSL_RENEGOTIATION) - unsigned int disable_renegotiation : 1; /*!< disable renegotiation? */ -#endif -#if defined(MBEDTLS_SSL_TRUNCATED_HMAC) - unsigned int trunc_hmac : 1; /*!< negotiate truncated hmac? */ -#endif -#if defined(MBEDTLS_SSL_SESSION_TICKETS) - unsigned int session_tickets : 1; /*!< use session tickets? */ -#endif -#if defined(MBEDTLS_SSL_FALLBACK_SCSV) && defined(MBEDTLS_SSL_CLI_C) - unsigned int fallback : 1; /*!< is this a fallback? */ -#endif -#if defined(MBEDTLS_SSL_SRV_C) - unsigned int cert_req_ca_list : 1; /*!< enable sending CA list in - Certificate Request messages? */ -#endif +#if defined(MBEDTLS_SSL_DTLS_SRTP) + /*! ordered list of supported srtp profile */ + const mbedtls_ssl_srtp_profile *dtls_srtp_profile_list; + /*! number of supported profiles */ + size_t dtls_srtp_profile_list_len; +#endif /* MBEDTLS_SSL_DTLS_SRTP */ }; - struct mbedtls_ssl_context { const mbedtls_ssl_config *conf; /*!< configuration information */ @@ -1070,6 +1289,12 @@ struct mbedtls_ssl_context unsigned badmac_seen; /*!< records with a bad MAC received */ #endif /* MBEDTLS_SSL_DTLS_BADMAC_LIMIT */ +#if defined(MBEDTLS_X509_CRT_PARSE_C) + /** Callback to customize X.509 certificate chain verification */ + int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *); + void *p_vrfy; /*!< context for X.509 verify callback */ +#endif + mbedtls_ssl_send_t *f_send; /*!< Callback for network send */ mbedtls_ssl_recv_t *f_recv; /*!< Callback for network receive */ mbedtls_ssl_recv_timeout_t *f_recv_timeout; @@ -1112,6 +1337,10 @@ struct mbedtls_ssl_context TLS: maintained by us DTLS: read from peer */ unsigned char *in_hdr; /*!< start of record header */ +#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) + unsigned char *in_cid; /*!< The start of the CID; + * (the end is marked by in_len). */ +#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ unsigned char *in_len; /*!< two-bytes message length field */ unsigned char *in_iv; /*!< ivlen-byte IV */ unsigned char *in_msg; /*!< message contents (in_iv+ivlen) */ @@ -1120,6 +1349,9 @@ struct mbedtls_ssl_context int in_msgtype; /*!< record header: message type */ size_t in_msglen; /*!< record header: message length */ size_t in_left; /*!< amount of data read so far */ +#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH) + size_t in_buf_len; /*!< length of input buffer */ +#endif #if defined(MBEDTLS_SSL_PROTO_DTLS) uint16_t in_epoch; /*!< DTLS epoch for incoming records */ size_t next_record_offset; /*!< offset of the next record in datagram @@ -1148,6 +1380,10 @@ struct mbedtls_ssl_context unsigned char *out_buf; /*!< output buffer */ unsigned char *out_ctr; /*!< 64-bit outgoing message counter */ unsigned char *out_hdr; /*!< start of record header */ +#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) + unsigned char *out_cid; /*!< The start of the CID; + * (the end is marked by in_len). */ +#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ unsigned char *out_len; /*!< two-bytes message length field */ unsigned char *out_iv; /*!< ivlen-byte IV */ unsigned char *out_msg; /*!< message contents (out_iv+ivlen) */ @@ -1155,6 +1391,9 @@ struct mbedtls_ssl_context int out_msgtype; /*!< record header: message type */ size_t out_msglen; /*!< record header: message length */ size_t out_left; /*!< amount of data not yet written */ +#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH) + size_t out_buf_len; /*!< length of output buffer */ +#endif unsigned char cur_out_ctr[8]; /*!< Outgoing record sequence number. */ @@ -1186,6 +1425,13 @@ struct mbedtls_ssl_context const char *alpn_chosen; /*!< negotiated protocol */ #endif /* MBEDTLS_SSL_ALPN */ +#if defined(MBEDTLS_SSL_DTLS_SRTP) + /* + * use_srtp extension + */ + mbedtls_dtls_srtp_info dtls_srtp_info; +#endif /* MBEDTLS_SSL_DTLS_SRTP */ + /* * Information for DTLS hello verify */ @@ -1205,25 +1451,59 @@ struct mbedtls_ssl_context char own_verify_data[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN]; /*!< previous handshake verify data */ char peer_verify_data[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN]; /*!< previous handshake verify data */ #endif /* MBEDTLS_SSL_RENEGOTIATION */ + +#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) + /* CID configuration to use in subsequent handshakes. */ + + /*! The next incoming CID, chosen by the user and applying to + * all subsequent handshakes. This may be different from the + * CID currently used in case the user has re-configured the CID + * after an initial handshake. */ + unsigned char own_cid[ MBEDTLS_SSL_CID_IN_LEN_MAX ]; + uint8_t own_cid_len; /*!< The length of \c own_cid. */ + uint8_t negotiate_cid; /*!< This indicates whether the CID extension should + * be negotiated in the next handshake or not. + * Possible values are #MBEDTLS_SSL_CID_ENABLED + * and #MBEDTLS_SSL_CID_DISABLED. */ +#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ }; #if defined(MBEDTLS_SSL_HW_RECORD_ACCEL) -#define MBEDTLS_SSL_CHANNEL_OUTBOUND 0 -#define MBEDTLS_SSL_CHANNEL_INBOUND 1 - -extern int (*mbedtls_ssl_hw_record_init)(mbedtls_ssl_context *ssl, - const unsigned char *key_enc, const unsigned char *key_dec, - size_t keylen, - const unsigned char *iv_enc, const unsigned char *iv_dec, - size_t ivlen, - const unsigned char *mac_enc, const unsigned char *mac_dec, - size_t maclen); -extern int (*mbedtls_ssl_hw_record_activate)(mbedtls_ssl_context *ssl, int direction); -extern int (*mbedtls_ssl_hw_record_reset)(mbedtls_ssl_context *ssl); -extern int (*mbedtls_ssl_hw_record_write)(mbedtls_ssl_context *ssl); -extern int (*mbedtls_ssl_hw_record_read)(mbedtls_ssl_context *ssl); -extern int (*mbedtls_ssl_hw_record_finish)(mbedtls_ssl_context *ssl); +#if !defined(MBEDTLS_DEPRECATED_REMOVED) + +#define MBEDTLS_SSL_CHANNEL_OUTBOUND MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( 0 ) +#define MBEDTLS_SSL_CHANNEL_INBOUND MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( 1 ) + +#if defined(MBEDTLS_DEPRECATED_WARNING) +#define MBEDTLS_DEPRECATED __attribute__((deprecated)) +#else +#define MBEDTLS_DEPRECATED +#endif /* MBEDTLS_DEPRECATED_WARNING */ + +MBEDTLS_DEPRECATED extern int (*mbedtls_ssl_hw_record_init)( + mbedtls_ssl_context *ssl, + const unsigned char *key_enc, const unsigned char *key_dec, + size_t keylen, + const unsigned char *iv_enc, const unsigned char *iv_dec, + size_t ivlen, + const unsigned char *mac_enc, const unsigned char *mac_dec, + size_t maclen); +MBEDTLS_DEPRECATED extern int (*mbedtls_ssl_hw_record_activate)( + mbedtls_ssl_context *ssl, + int direction ); +MBEDTLS_DEPRECATED extern int (*mbedtls_ssl_hw_record_reset)( + mbedtls_ssl_context *ssl ); +MBEDTLS_DEPRECATED extern int (*mbedtls_ssl_hw_record_write)( + mbedtls_ssl_context *ssl ); +MBEDTLS_DEPRECATED extern int (*mbedtls_ssl_hw_record_read)( + mbedtls_ssl_context *ssl ); +MBEDTLS_DEPRECATED extern int (*mbedtls_ssl_hw_record_finish)( + mbedtls_ssl_context *ssl ); + +#undef MBEDTLS_DEPRECATED +#endif /* !MBEDTLS_DEPRECATED_REMOVED */ + #endif /* MBEDTLS_SSL_HW_RECORD_ACCEL */ /** @@ -1346,13 +1626,17 @@ void mbedtls_ssl_conf_authmode( mbedtls_ssl_config *conf, int authmode ); /** * \brief Set the verification callback (Optional). * - * If set, the verify callback is called for each - * certificate in the chain. For implementation - * information, please see \c mbedtls_x509_crt_verify() + * If set, the provided verify callback is called for each + * certificate in the peer's CRT chain, including the trusted + * root. For more information, please see the documentation of + * \c mbedtls_x509_crt_verify(). * - * \param conf SSL configuration - * \param f_vrfy verification function - * \param p_vrfy verification parameter + * \note For per context callbacks and contexts, please use + * mbedtls_ssl_set_verify() instead. + * + * \param conf The SSL configuration to use. + * \param f_vrfy The verification callback to use during CRT verification. + * \param p_vrfy The opaque context to be passed to the callback. */ void mbedtls_ssl_conf_verify( mbedtls_ssl_config *conf, int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *), @@ -1425,6 +1709,142 @@ void mbedtls_ssl_set_bio( mbedtls_ssl_context *ssl, mbedtls_ssl_recv_timeout_t *f_recv_timeout ); #if defined(MBEDTLS_SSL_PROTO_DTLS) + +#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) + + +/** + * \brief Configure the use of the Connection ID (CID) + * extension in the next handshake. + * + * Reference: draft-ietf-tls-dtls-connection-id-05 + * https://tools.ietf.org/html/draft-ietf-tls-dtls-connection-id-05 + * + * The DTLS CID extension allows the reliable association of + * DTLS records to DTLS connections across changes in the + * underlying transport (changed IP and Port metadata) by + * adding explicit connection identifiers (CIDs) to the + * headers of encrypted DTLS records. The desired CIDs are + * configured by the application layer and are exchanged in + * new `ClientHello` / `ServerHello` extensions during the + * handshake, where each side indicates the CID it wants the + * peer to use when writing encrypted messages. The CIDs are + * put to use once records get encrypted: the stack discards + * any incoming records that don't include the configured CID + * in their header, and adds the peer's requested CID to the + * headers of outgoing messages. + * + * This API enables or disables the use of the CID extension + * in the next handshake and sets the value of the CID to + * be used for incoming messages. + * + * \param ssl The SSL context to configure. This must be initialized. + * \param enable This value determines whether the CID extension should + * be used or not. Possible values are: + * - MBEDTLS_SSL_CID_ENABLED to enable the use of the CID. + * - MBEDTLS_SSL_CID_DISABLED (default) to disable the use + * of the CID. + * \param own_cid The address of the readable buffer holding the CID we want + * the peer to use when sending encrypted messages to us. + * This may be \c NULL if \p own_cid_len is \c 0. + * This parameter is unused if \p enabled is set to + * MBEDTLS_SSL_CID_DISABLED. + * \param own_cid_len The length of \p own_cid. + * This parameter is unused if \p enabled is set to + * MBEDTLS_SSL_CID_DISABLED. + * + * \note The value of \p own_cid_len must match the value of the + * \c len parameter passed to mbedtls_ssl_conf_cid() + * when configuring the ::mbedtls_ssl_config that \p ssl + * is bound to. + * + * \note This CID configuration applies to subsequent handshakes + * performed on the SSL context \p ssl, but does not trigger + * one. You still have to call `mbedtls_ssl_handshake()` + * (for the initial handshake) or `mbedtls_ssl_renegotiate()` + * (for a renegotiation handshake) explicitly after a + * successful call to this function to run the handshake. + * + * \note This call cannot guarantee that the use of the CID + * will be successfully negotiated in the next handshake, + * because the peer might not support it. Specifically: + * - On the Client, enabling the use of the CID through + * this call implies that the `ClientHello` in the next + * handshake will include the CID extension, thereby + * offering the use of the CID to the server. Only if + * the `ServerHello` contains the CID extension, too, + * the CID extension will actually be put to use. + * - On the Server, enabling the use of the CID through + * this call implies that that the server will look for + * the CID extension in a `ClientHello` from the client, + * and, if present, reply with a CID extension in its + * `ServerHello`. + * + * \note To check whether the use of the CID was negotiated + * after the subsequent handshake has completed, please + * use the API mbedtls_ssl_get_peer_cid(). + * + * \warning If the use of the CID extension is enabled in this call + * and the subsequent handshake negotiates its use, Mbed TLS + * will silently drop every packet whose CID does not match + * the CID configured in \p own_cid. It is the responsibility + * of the user to adapt the underlying transport to take care + * of CID-based demultiplexing before handing datagrams to + * Mbed TLS. + * + * \return \c 0 on success. In this case, the CID configuration + * applies to the next handshake. + * \return A negative error code on failure. + */ +int mbedtls_ssl_set_cid( mbedtls_ssl_context *ssl, + int enable, + unsigned char const *own_cid, + size_t own_cid_len ); + +/** + * \brief Get information about the use of the CID extension + * in the current connection. + * + * \param ssl The SSL context to query. + * \param enabled The address at which to store whether the CID extension + * is currently in use or not. If the CID is in use, + * `*enabled` is set to MBEDTLS_SSL_CID_ENABLED; + * otherwise, it is set to MBEDTLS_SSL_CID_DISABLED. + * \param peer_cid The address of the buffer in which to store the CID + * chosen by the peer (if the CID extension is used). + * This may be \c NULL in case the value of peer CID + * isn't needed. If it is not \c NULL, \p peer_cid_len + * must not be \c NULL. + * \param peer_cid_len The address at which to store the size of the CID + * chosen by the peer (if the CID extension is used). + * This is also the number of Bytes in \p peer_cid that + * have been written. + * This may be \c NULL in case the length of the peer CID + * isn't needed. If it is \c NULL, \p peer_cid must be + * \c NULL, too. + * + * \note This applies to the state of the CID negotiated in + * the last complete handshake. If a handshake is in + * progress, this function will attempt to complete + * the handshake first. + * + * \note If CID extensions have been exchanged but both client + * and server chose to use an empty CID, this function + * sets `*enabled` to #MBEDTLS_SSL_CID_DISABLED + * (the rationale for this is that the resulting + * communication is the same as if the CID extensions + * hadn't been used). + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_ssl_get_peer_cid( mbedtls_ssl_context *ssl, + int *enabled, + unsigned char peer_cid[ MBEDTLS_SSL_CID_OUT_LEN_MAX ], + size_t *peer_cid_len ); + +#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ + /** * \brief Set the Maximum Tranport Unit (MTU). * Special value: 0 means unset (no limit). @@ -1470,6 +1890,30 @@ void mbedtls_ssl_set_bio( mbedtls_ssl_context *ssl, void mbedtls_ssl_set_mtu( mbedtls_ssl_context *ssl, uint16_t mtu ); #endif /* MBEDTLS_SSL_PROTO_DTLS */ +#if defined(MBEDTLS_X509_CRT_PARSE_C) +/** + * \brief Set a connection-specific verification callback (optional). + * + * If set, the provided verify callback is called for each + * certificate in the peer's CRT chain, including the trusted + * root. For more information, please see the documentation of + * \c mbedtls_x509_crt_verify(). + * + * \note This call is analogous to mbedtls_ssl_conf_verify() but + * binds the verification callback and context to an SSL context + * as opposed to an SSL configuration. + * If mbedtls_ssl_conf_verify() and mbedtls_ssl_set_verify() + * are both used, mbedtls_ssl_set_verify() takes precedence. + * + * \param ssl The SSL context to use. + * \param f_vrfy The verification callback to use during CRT verification. + * \param p_vrfy The opaque context to be passed to the callback. + */ +void mbedtls_ssl_set_verify( mbedtls_ssl_context *ssl, + int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *), + void *p_vrfy ); +#endif /* MBEDTLS_X509_CRT_PARSE_C */ + /** * \brief Set the timeout period for mbedtls_ssl_read() * (Default: no timeout.) @@ -1488,6 +1932,56 @@ void mbedtls_ssl_set_mtu( mbedtls_ssl_context *ssl, uint16_t mtu ); */ void mbedtls_ssl_conf_read_timeout( mbedtls_ssl_config *conf, uint32_t timeout ); +#if defined(MBEDTLS_SSL_RECORD_CHECKING) +/** + * \brief Check whether a buffer contains a valid and authentic record + * that has not been seen before. (DTLS only). + * + * This function does not change the user-visible state + * of the SSL context. Its sole purpose is to provide + * an indication of the legitimacy of an incoming record. + * + * This can be useful e.g. in distributed server environments + * using the DTLS Connection ID feature, in which connections + * might need to be passed between service instances on a change + * of peer address, but where such disruptive operations should + * only happen after the validity of incoming records has been + * confirmed. + * + * \param ssl The SSL context to use. + * \param buf The address of the buffer holding the record to be checked. + * This must be a read/write buffer of length \p buflen Bytes. + * \param buflen The length of \p buf in Bytes. + * + * \note This routine only checks whether the provided buffer begins + * with a valid and authentic record that has not been seen + * before, but does not check potential data following the + * initial record. In particular, it is possible to pass DTLS + * datagrams containing multiple records, in which case only + * the first record is checked. + * + * \note This function modifies the input buffer \p buf. If you need + * to preserve the original record, you have to maintain a copy. + * + * \return \c 0 if the record is valid and authentic and has not been + * seen before. + * \return MBEDTLS_ERR_SSL_INVALID_MAC if the check completed + * successfully but the record was found to be not authentic. + * \return MBEDTLS_ERR_SSL_INVALID_RECORD if the check completed + * successfully but the record was found to be invalid for + * a reason different from authenticity checking. + * \return MBEDTLS_ERR_SSL_UNEXPECTED_RECORD if the check completed + * successfully but the record was found to be unexpected + * in the state of the SSL context, including replayed records. + * \return Another negative error code on different kinds of failure. + * In this case, the SSL context becomes unusable and needs + * to be freed or reset before reuse. + */ +int mbedtls_ssl_check_record( mbedtls_ssl_context const *ssl, + unsigned char *buf, + size_t buflen ); +#endif /* MBEDTLS_SSL_RECORD_CHECKING */ + /** * \brief Set the timer callbacks (Mandatory for DTLS.) * @@ -1566,6 +2060,41 @@ typedef int mbedtls_ssl_export_keys_t( void *p_expkey, size_t maclen, size_t keylen, size_t ivlen ); + +/** + * \brief Callback type: Export key block, master secret, + * handshake randbytes and the tls_prf function + * used to derive keys. + * + * \note This is required for certain uses of TLS, e.g. EAP-TLS + * (RFC 5216) and Thread. The key pointers are ephemeral and + * therefore must not be stored. The master secret and keys + * should not be used directly except as an input to a key + * derivation function. + * + * \param p_expkey Context for the callback. + * \param ms Pointer to master secret (fixed length: 48 bytes). + * \param kb Pointer to key block, see RFC 5246 section 6.3. + * (variable length: 2 * maclen + 2 * keylen + 2 * ivlen). + * \param maclen MAC length. + * \param keylen Key length. + * \param ivlen IV length. + * \param client_random The client random bytes. + * \param server_random The server random bytes. + * \param tls_prf_type The tls_prf enum type. + * + * \return 0 if successful, or + * a specific MBEDTLS_ERR_XXX code. + */ +typedef int mbedtls_ssl_export_keys_ext_t( void *p_expkey, + const unsigned char *ms, + const unsigned char *kb, + size_t maclen, + size_t keylen, + size_t ivlen, + const unsigned char client_random[32], + const unsigned char server_random[32], + mbedtls_tls_prf_types tls_prf_type ); #endif /* MBEDTLS_SSL_EXPORT_KEYS */ /** @@ -1631,6 +2160,22 @@ void mbedtls_ssl_conf_session_tickets_cb( mbedtls_ssl_config *conf, void mbedtls_ssl_conf_export_keys_cb( mbedtls_ssl_config *conf, mbedtls_ssl_export_keys_t *f_export_keys, void *p_export_keys ); + +/** + * \brief Configure extended key export callback. + * (Default: none.) + * + * \note See \c mbedtls_ssl_export_keys_ext_t. + * \warning Exported key material must not be used for any purpose + * before the (D)TLS handshake is completed + * + * \param conf SSL configuration context + * \param f_export_keys_ext Callback for exporting keys + * \param p_export_keys Context for the callback + */ +void mbedtls_ssl_conf_export_keys_ext_cb( mbedtls_ssl_config *conf, + mbedtls_ssl_export_keys_ext_t *f_export_keys_ext, + void *p_export_keys ); #endif /* MBEDTLS_SSL_EXPORT_KEYS */ #if defined(MBEDTLS_SSL_ASYNC_PRIVATE) @@ -1981,6 +2526,90 @@ void mbedtls_ssl_conf_session_cache( mbedtls_ssl_config *conf, int mbedtls_ssl_set_session( mbedtls_ssl_context *ssl, const mbedtls_ssl_session *session ); #endif /* MBEDTLS_SSL_CLI_C */ +/** + * \brief Load serialized session data into a session structure. + * On client, this can be used for loading saved sessions + * before resuming them with mbedstls_ssl_set_session(). + * On server, this can be used for alternative implementations + * of session cache or session tickets. + * + * \warning If a peer certificate chain is associated with the session, + * the serialized state will only contain the peer's + * end-entity certificate and the result of the chain + * verification (unless verification was disabled), but not + * the rest of the chain. + * + * \see mbedtls_ssl_session_save() + * \see mbedtls_ssl_set_session() + * + * \param session The session structure to be populated. It must have been + * initialised with mbedtls_ssl_session_init() but not + * populated yet. + * \param buf The buffer holding the serialized session data. It must be a + * readable buffer of at least \p len bytes. + * \param len The size of the serialized data in bytes. + * + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_SSL_ALLOC_FAILED if memory allocation failed. + * \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA if input data is invalid. + * \return #MBEDTLS_ERR_SSL_VERSION_MISMATCH if the serialized data + * was generated in a different version or configuration of + * Mbed TLS. + * \return Another negative value for other kinds of errors (for + * example, unsupported features in the embedded certificate). + */ +int mbedtls_ssl_session_load( mbedtls_ssl_session *session, + const unsigned char *buf, + size_t len ); + +/** + * \brief Save session structure as serialized data in a buffer. + * On client, this can be used for saving session data, + * potentially in non-volatile storage, for resuming later. + * On server, this can be used for alternative implementations + * of session cache or session tickets. + * + * \see mbedtls_ssl_session_load() + * \see mbedtls_ssl_get_session_pointer() + * + * \param session The session structure to be saved. + * \param buf The buffer to write the serialized data to. It must be a + * writeable buffer of at least \p len bytes, or may be \c + * NULL if \p len is \c 0. + * \param buf_len The number of bytes available for writing in \p buf. + * \param olen The size in bytes of the data that has been or would have + * been written. It must point to a valid \c size_t. + * + * \note \p olen is updated to the correct value regardless of + * whether \p buf_len was large enough. This makes it possible + * to determine the necessary size by calling this function + * with \p buf set to \c NULL and \p buf_len to \c 0. + * + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL if \p buf is too small. + */ +int mbedtls_ssl_session_save( const mbedtls_ssl_session *session, + unsigned char *buf, + size_t buf_len, + size_t *olen ); + +/** + * \brief Get a pointer to the current session structure, for example + * to serialize it. + * + * \warning Ownership of the session remains with the SSL context, and + * the returned pointer is only guaranteed to be valid until + * the next API call operating on the same \p ssl context. + * + * \see mbedtls_ssl_session_save() + * + * \param ssl The SSL context. + * + * \return A pointer to the current session if successful. + * \return \c NULL if no session is active. + */ +const mbedtls_ssl_session *mbedtls_ssl_get_session_pointer( const mbedtls_ssl_context *ssl ); + /** * \brief Set the list of allowed ciphersuites and the preference * order. First in the list has the highest preference. @@ -1999,6 +2628,45 @@ int mbedtls_ssl_set_session( mbedtls_ssl_context *ssl, const mbedtls_ssl_session void mbedtls_ssl_conf_ciphersuites( mbedtls_ssl_config *conf, const int *ciphersuites ); +#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) +#define MBEDTLS_SSL_UNEXPECTED_CID_IGNORE 0 +#define MBEDTLS_SSL_UNEXPECTED_CID_FAIL 1 +/** + * \brief Specify the length of Connection IDs for incoming + * encrypted DTLS records, as well as the behaviour + * on unexpected CIDs. + * + * By default, the CID length is set to \c 0, + * and unexpected CIDs are silently ignored. + * + * \param conf The SSL configuration to modify. + * \param len The length in Bytes of the CID fields in encrypted + * DTLS records using the CID mechanism. This must + * not be larger than #MBEDTLS_SSL_CID_OUT_LEN_MAX. + * \param ignore_other_cids This determines the stack's behaviour when + * receiving a record with an unexpected CID. + * Possible values are: + * - #MBEDTLS_SSL_UNEXPECTED_CID_IGNORE + * In this case, the record is silently ignored. + * - #MBEDTLS_SSL_UNEXPECTED_CID_FAIL + * In this case, the stack fails with the specific + * error code #MBEDTLS_ERR_SSL_UNEXPECTED_CID. + * + * \note The CID specification allows implementations to either + * use a common length for all incoming connection IDs or + * allow variable-length incoming IDs. Mbed TLS currently + * requires a common length for all connections sharing the + * same SSL configuration; this allows simpler parsing of + * record headers. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA if \p own_cid_len + * is too large. + */ +int mbedtls_ssl_conf_cid( mbedtls_ssl_config *conf, size_t len, + int ignore_other_cids ); +#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ + /** * \brief Set the list of allowed ciphersuites and the * preference order for a specific version of the protocol. @@ -2051,6 +2719,63 @@ void mbedtls_ssl_conf_ca_chain( mbedtls_ssl_config *conf, mbedtls_x509_crt *ca_chain, mbedtls_x509_crl *ca_crl ); +#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK) +/** + * \brief Set the trusted certificate callback. + * + * This API allows to register the set of trusted certificates + * through a callback, instead of a linked list as configured + * by mbedtls_ssl_conf_ca_chain(). + * + * This is useful for example in contexts where a large number + * of CAs are used, and the inefficiency of maintaining them + * in a linked list cannot be tolerated. It is also useful when + * the set of trusted CAs needs to be modified frequently. + * + * See the documentation of `mbedtls_x509_crt_ca_cb_t` for + * more information. + * + * \param conf The SSL configuration to register the callback with. + * \param f_ca_cb The trusted certificate callback to use when verifying + * certificate chains. + * \param p_ca_cb The context to be passed to \p f_ca_cb (for example, + * a reference to a trusted CA database). + * + * \note This API is incompatible with mbedtls_ssl_conf_ca_chain(): + * Any call to this function overwrites the values set through + * earlier calls to mbedtls_ssl_conf_ca_chain() or + * mbedtls_ssl_conf_ca_cb(). + * + * \note This API is incompatible with CA indication in + * CertificateRequest messages: A server-side SSL context which + * is bound to an SSL configuration that uses a CA callback + * configured via mbedtls_ssl_conf_ca_cb(), and which requires + * client authentication, will send an empty CA list in the + * corresponding CertificateRequest message. + * + * \note This API is incompatible with mbedtls_ssl_set_hs_ca_chain(): + * If an SSL context is bound to an SSL configuration which uses + * CA callbacks configured via mbedtls_ssl_conf_ca_cb(), then + * calls to mbedtls_ssl_set_hs_ca_chain() have no effect. + * + * \note The use of this API disables the use of restartable ECC + * during X.509 CRT signature verification (but doesn't affect + * other uses). + * + * \warning This API is incompatible with the use of CRLs. Any call to + * mbedtls_ssl_conf_ca_cb() unsets CRLs configured through + * earlier calls to mbedtls_ssl_conf_ca_chain(). + * + * \warning In multi-threaded environments, the callback \p f_ca_cb + * must be thread-safe, and it is the user's responsibility + * to guarantee this (for example through a mutex + * contained in the callback context pointed to by \p p_ca_cb). + */ +void mbedtls_ssl_conf_ca_cb( mbedtls_ssl_config *conf, + mbedtls_x509_crt_ca_cb_t f_ca_cb, + void *p_ca_cb ); +#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */ + /** * \brief Set own certificate chain and private key * @@ -2092,76 +2817,172 @@ int mbedtls_ssl_conf_own_cert( mbedtls_ssl_config *conf, mbedtls_pk_context *pk_key ); #endif /* MBEDTLS_X509_CRT_PARSE_C */ -#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED) +#if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED) /** - * \brief Set the Pre Shared Key (PSK) and the expected identity name + * \brief Configure a pre-shared key (PSK) and identity + * to be used in PSK-based ciphersuites. * * \note This is mainly useful for clients. Servers will usually * want to use \c mbedtls_ssl_conf_psk_cb() instead. * - * \note Currently clients can only register one pre-shared key. - * In other words, the servers' identity hint is ignored. + * \note A PSK set by \c mbedtls_ssl_set_hs_psk() in the PSK callback + * takes precedence over a PSK configured by this function. + * + * \warning Currently, clients can only register a single pre-shared key. + * Calling this function or mbedtls_ssl_conf_psk_opaque() more + * than once will overwrite values configured in previous calls. * Support for setting multiple PSKs on clients and selecting - * one based on the identity hint is not a planned feature but - * feedback is welcomed. + * one based on the identity hint is not a planned feature, + * but feedback is welcomed. * - * \param conf SSL configuration - * \param psk pointer to the pre-shared key - * \param psk_len pre-shared key length - * \param psk_identity pointer to the pre-shared key identity - * \param psk_identity_len identity key length + * \param conf The SSL configuration to register the PSK with. + * \param psk The pointer to the pre-shared key to use. + * \param psk_len The length of the pre-shared key in bytes. + * \param psk_identity The pointer to the pre-shared key identity. + * \param psk_identity_len The length of the pre-shared key identity + * in bytes. * - * \return 0 if successful or MBEDTLS_ERR_SSL_ALLOC_FAILED + * \note The PSK and its identity are copied internally and + * hence need not be preserved by the caller for the lifetime + * of the SSL configuration. + * + * \return \c 0 if successful. + * \return An \c MBEDTLS_ERR_SSL_XXX error code on failure. */ int mbedtls_ssl_conf_psk( mbedtls_ssl_config *conf, const unsigned char *psk, size_t psk_len, const unsigned char *psk_identity, size_t psk_identity_len ); +#if defined(MBEDTLS_USE_PSA_CRYPTO) +/** + * \brief Configure an opaque pre-shared key (PSK) and identity + * to be used in PSK-based ciphersuites. + * + * \note This is mainly useful for clients. Servers will usually + * want to use \c mbedtls_ssl_conf_psk_cb() instead. + * + * \note An opaque PSK set by \c mbedtls_ssl_set_hs_psk_opaque() in + * the PSK callback takes precedence over an opaque PSK + * configured by this function. + * + * \warning Currently, clients can only register a single pre-shared key. + * Calling this function or mbedtls_ssl_conf_psk() more than + * once will overwrite values configured in previous calls. + * Support for setting multiple PSKs on clients and selecting + * one based on the identity hint is not a planned feature, + * but feedback is welcomed. + * + * \param conf The SSL configuration to register the PSK with. + * \param psk The identifier of the key slot holding the PSK. + * Until \p conf is destroyed or this function is successfully + * called again, the key slot \p psk must be populated with a + * key of type PSA_ALG_CATEGORY_KEY_DERIVATION whose policy + * allows its use for the key derivation algorithm applied + * in the handshake. + * \param psk_identity The pointer to the pre-shared key identity. + * \param psk_identity_len The length of the pre-shared key identity + * in bytes. + * + * \note The PSK identity hint is copied internally and hence need + * not be preserved by the caller for the lifetime of the + * SSL configuration. + * + * \return \c 0 if successful. + * \return An \c MBEDTLS_ERR_SSL_XXX error code on failure. + */ +int mbedtls_ssl_conf_psk_opaque( mbedtls_ssl_config *conf, + psa_key_id_t psk, + const unsigned char *psk_identity, + size_t psk_identity_len ); +#endif /* MBEDTLS_USE_PSA_CRYPTO */ /** - * \brief Set the Pre Shared Key (PSK) for the current handshake + * \brief Set the pre-shared Key (PSK) for the current handshake. * * \note This should only be called inside the PSK callback, - * ie the function passed to \c mbedtls_ssl_conf_psk_cb(). + * i.e. the function passed to \c mbedtls_ssl_conf_psk_cb(). * - * \param ssl SSL context - * \param psk pointer to the pre-shared key - * \param psk_len pre-shared key length + * \note A PSK set by this function takes precedence over a PSK + * configured by \c mbedtls_ssl_conf_psk(). + * + * \param ssl The SSL context to configure a PSK for. + * \param psk The pointer to the pre-shared key. + * \param psk_len The length of the pre-shared key in bytes. * - * \return 0 if successful or MBEDTLS_ERR_SSL_ALLOC_FAILED + * \return \c 0 if successful. + * \return An \c MBEDTLS_ERR_SSL_XXX error code on failure. */ int mbedtls_ssl_set_hs_psk( mbedtls_ssl_context *ssl, const unsigned char *psk, size_t psk_len ); +#if defined(MBEDTLS_USE_PSA_CRYPTO) +/** + * \brief Set an opaque pre-shared Key (PSK) for the current handshake. + * + * \note This should only be called inside the PSK callback, + * i.e. the function passed to \c mbedtls_ssl_conf_psk_cb(). + * + * \note An opaque PSK set by this function takes precedence over an + * opaque PSK configured by \c mbedtls_ssl_conf_psk_opaque(). + * + * \param ssl The SSL context to configure a PSK for. + * \param psk The identifier of the key slot holding the PSK. + * For the duration of the current handshake, the key slot + * must be populated with a key of type + * PSA_ALG_CATEGORY_KEY_DERIVATION whose policy allows its + * use for the key derivation algorithm + * applied in the handshake. + * + * \return \c 0 if successful. + * \return An \c MBEDTLS_ERR_SSL_XXX error code on failure. + */ +int mbedtls_ssl_set_hs_psk_opaque( mbedtls_ssl_context *ssl, + psa_key_id_t psk ); +#endif /* MBEDTLS_USE_PSA_CRYPTO */ + /** * \brief Set the PSK callback (server-side only). * * If set, the PSK callback is called for each - * handshake where a PSK ciphersuite was negotiated. + * handshake where a PSK-based ciphersuite was negotiated. * The caller provides the identity received and wants to * receive the actual PSK data and length. * - * The callback has the following parameters: (void *parameter, - * mbedtls_ssl_context *ssl, const unsigned char *psk_identity, - * size_t identity_len) + * The callback has the following parameters: + * - \c void*: The opaque pointer \p p_psk. + * - \c mbedtls_ssl_context*: The SSL context to which + * the operation applies. + * - \c const unsigned char*: The PSK identity + * selected by the client. + * - \c size_t: The length of the PSK identity + * selected by the client. + * * If a valid PSK identity is found, the callback should use - * \c mbedtls_ssl_set_hs_psk() on the ssl context to set the - * correct PSK and return 0. + * \c mbedtls_ssl_set_hs_psk() or + * \c mbedtls_ssl_set_hs_psk_opaque() + * on the SSL context to set the correct PSK and return \c 0. * Any other return value will result in a denied PSK identity. * - * \note If you set a PSK callback using this function, then you - * don't need to set a PSK key and identity using - * \c mbedtls_ssl_conf_psk(). - * - * \param conf SSL configuration - * \param f_psk PSK identity function - * \param p_psk PSK identity parameter + * \note A dynamic PSK (i.e. set by the PSK callback) takes + * precedence over a static PSK (i.e. set by + * \c mbedtls_ssl_conf_psk() or + * \c mbedtls_ssl_conf_psk_opaque()). + * This means that if you set a PSK callback using this + * function, you don't need to set a PSK using + * \c mbedtls_ssl_conf_psk() or + * \c mbedtls_ssl_conf_psk_opaque()). + * + * \param conf The SSL configuration to register the callback with. + * \param f_psk The callback for selecting and setting the PSK based + * in the PSK identity chosen by the client. + * \param p_psk A pointer to an opaque structure to be passed to + * the callback, for example a PSK store. */ void mbedtls_ssl_conf_psk_cb( mbedtls_ssl_config *conf, int (*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *, size_t), void *p_psk ); -#endif /* MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED */ +#endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */ #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_SRV_C) @@ -2237,7 +3058,9 @@ void mbedtls_ssl_conf_dhm_min_bitlen( mbedtls_ssl_config *conf, #if defined(MBEDTLS_ECP_C) /** * \brief Set the allowed curves in order of preference. - * (Default: all defined curves in order of decreasing size.) + * (Default: all defined curves in order of decreasing size, + * except that Montgomery curves come last. This order + * is likely to change in a future version.) * * On server: this only affects selection of the ECDHE curve; * the curves used for ECDH and ECDSA are determined by the @@ -2266,7 +3089,7 @@ void mbedtls_ssl_conf_curves( mbedtls_ssl_config *conf, const mbedtls_ecp_group_id *curves ); #endif /* MBEDTLS_ECP_C */ -#if defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED) +#if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED) /** * \brief Set the allowed hashes for signatures during the handshake. * (Default: all SHA-2 hashes, largest first. Also SHA-1 if @@ -2289,7 +3112,7 @@ void mbedtls_ssl_conf_curves( mbedtls_ssl_config *conf, */ void mbedtls_ssl_conf_sig_hashes( mbedtls_ssl_config *conf, const int *hashes ); -#endif /* MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED */ +#endif /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED */ #if defined(MBEDTLS_X509_CRT_PARSE_C) /** @@ -2437,6 +3260,105 @@ int mbedtls_ssl_conf_alpn_protocols( mbedtls_ssl_config *conf, const char **prot const char *mbedtls_ssl_get_alpn_protocol( const mbedtls_ssl_context *ssl ); #endif /* MBEDTLS_SSL_ALPN */ +#if defined(MBEDTLS_SSL_DTLS_SRTP) +#if defined(MBEDTLS_DEBUG_C) +static inline const char *mbedtls_ssl_get_srtp_profile_as_string( mbedtls_ssl_srtp_profile profile ) +{ + switch( profile ) + { + case MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80: + return( "MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80" ); + case MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32: + return( "MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" ); + case MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80: + return( "MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80" ); + case MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32: + return( "MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32" ); + default: break; + } + return( "" ); +} +#endif /* MBEDTLS_DEBUG_C */ +/** + * \brief Manage support for mki(master key id) value + * in use_srtp extension. + * MKI is an optional part of SRTP used for key management + * and re-keying. See RFC3711 section 3.1 for details. + * The default value is + * #MBEDTLS_SSL_DTLS_SRTP_MKI_UNSUPPORTED. + * + * \param conf The SSL configuration to manage mki support. + * \param support_mki_value Enable or disable mki usage. Values are + * #MBEDTLS_SSL_DTLS_SRTP_MKI_UNSUPPORTED + * or #MBEDTLS_SSL_DTLS_SRTP_MKI_SUPPORTED. + */ +void mbedtls_ssl_conf_srtp_mki_value_supported( mbedtls_ssl_config *conf, + int support_mki_value ); + +/** + * \brief Set the supported DTLS-SRTP protection profiles. + * + * \param conf SSL configuration + * \param profiles Pointer to a List of MBEDTLS_TLS_SRTP_UNSET terminated + * supported protection profiles + * in decreasing preference order. + * The pointer to the list is recorded by the library + * for later reference as required, so the lifetime + * of the table must be at least as long as the lifetime + * of the SSL configuration structure. + * The list must not hold more than + * MBEDTLS_TLS_SRTP_MAX_PROFILE_LIST_LENGTH elements + * (excluding the terminating MBEDTLS_TLS_SRTP_UNSET). + * + * \return 0 on success + * \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA when the list of + * protection profiles is incorrect. + */ +int mbedtls_ssl_conf_dtls_srtp_protection_profiles + ( mbedtls_ssl_config *conf, + const mbedtls_ssl_srtp_profile *profiles ); + +/** + * \brief Set the mki_value for the current DTLS-SRTP session. + * + * \param ssl SSL context to use. + * \param mki_value The MKI value to set. + * \param mki_len The length of the MKI value. + * + * \note This function is relevant on client side only. + * The server discovers the mki value during handshake. + * A mki value set on server side using this function + * is ignored. + * + * \return 0 on success + * \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA + * \return #MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE + */ +int mbedtls_ssl_dtls_srtp_set_mki_value( mbedtls_ssl_context *ssl, + unsigned char *mki_value, + uint16_t mki_len ); +/** + * \brief Get the negotiated DTLS-SRTP informations: + * Protection profile and MKI value. + * + * \warning This function must be called after the handshake is + * completed. The value returned by this function must + * not be trusted or acted upon before the handshake completes. + * + * \param ssl The SSL context to query. + * \param dtls_srtp_info The negotiated DTLS-SRTP informations: + * - Protection profile in use. + * A direct mapping of the iana defined value for protection + * profile on an uint16_t. + http://www.iana.org/assignments/srtp-protection/srtp-protection.xhtml + * #MBEDTLS_TLS_SRTP_UNSET if the use of SRTP was not negotiated + * or peer's Hello packet was not parsed yet. + * - mki size and value( if size is > 0 ). + */ +void mbedtls_ssl_get_dtls_srtp_negotiation_result( const mbedtls_ssl_context *ssl, + mbedtls_dtls_srtp_info *dtls_srtp_info ); +#endif /* MBEDTLS_SSL_DTLS_SRTP */ + /** * \brief Set the maximum supported version sent from the client side * and/or accepted at the server side @@ -2536,7 +3458,7 @@ void mbedtls_ssl_conf_extended_master_secret( mbedtls_ssl_config *conf, char ems * \warning Use of RC4 in DTLS/TLS has been prohibited by RFC 7465 * for security reasons. Use at your own risk. * - * \note This function is deprecated and will likely be removed in + * \note This function is deprecated and will be removed in * a future version of the library. * RC4 is disabled by default at compile time and needs to be * actively enabled for use with legacy systems. @@ -2577,14 +3499,14 @@ void mbedtls_ssl_conf_cert_req_ca_list( mbedtls_ssl_config *conf, * been set via this function to a value different than * #MBEDTLS_SSL_MAX_FRAG_LEN_NONE. * - * \note This sets the maximum length for a record's payload, - * excluding record overhead that will be added to it, see - * \c mbedtls_ssl_get_record_expansion(). - * * \note With TLS, this currently only affects ApplicationData (sent * with \c mbedtls_ssl_read()), not handshake messages. * With DTLS, this affects both ApplicationData and handshake. * + * \note This sets the maximum length for a record's payload, + * excluding record overhead that will be added to it, see + * \c mbedtls_ssl_get_record_expansion(). + * * \note For DTLS, it is also possible to set a limit for the total * size of daragrams passed to the transport layer, including * record overhead, see \c mbedtls_ssl_set_mtu(). @@ -2735,7 +3657,7 @@ void mbedtls_ssl_conf_renegotiation_enforced( mbedtls_ssl_config *conf, int max_ * (Default: 2^48 - 1) * * Renegotiation is automatically triggered when a record - * counter (outgoing or ingoing) crosses the defined + * counter (outgoing or incoming) crosses the defined * threshold. The default value is meant to prevent the * connection from being closed when the counter is about to * reached its maximal value (it is not allowed to wrap). @@ -2865,18 +3787,61 @@ int mbedtls_ssl_get_record_expansion( const mbedtls_ssl_context *ssl ); #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) /** - * \brief Return the maximum fragment length (payload, in bytes). - * This is the value negotiated with peer if any, - * or the locally configured value. + * \brief Return the maximum fragment length (payload, in bytes) for + * the output buffer. For the client, this is the configured + * value. For the server, it is the minimum of two - the + * configured value and the negotiated one. * * \sa mbedtls_ssl_conf_max_frag_len() * \sa mbedtls_ssl_get_max_record_payload() * * \param ssl SSL context * - * \return Current maximum fragment length. + * \return Current maximum fragment length for the output buffer. + */ +size_t mbedtls_ssl_get_output_max_frag_len( const mbedtls_ssl_context *ssl ); + +/** + * \brief Return the maximum fragment length (payload, in bytes) for + * the input buffer. This is the negotiated maximum fragment + * length, or, if there is none, MBEDTLS_SSL_MAX_CONTENT_LEN. + * If it is not defined either, the value is 2^14. This function + * works as its predecessor, \c mbedtls_ssl_get_max_frag_len(). + * + * \sa mbedtls_ssl_conf_max_frag_len() + * \sa mbedtls_ssl_get_max_record_payload() + * + * \param ssl SSL context + * + * \return Current maximum fragment length for the output buffer. + */ +size_t mbedtls_ssl_get_input_max_frag_len( const mbedtls_ssl_context *ssl ); + +#if !defined(MBEDTLS_DEPRECATED_REMOVED) + +#if defined(MBEDTLS_DEPRECATED_WARNING) +#define MBEDTLS_DEPRECATED __attribute__((deprecated)) +#else +#define MBEDTLS_DEPRECATED +#endif + +/** + * \brief This function is a deprecated approach to getting the max + * fragment length. Its an alias for + * \c mbedtls_ssl_get_output_max_frag_len(), as the behaviour + * is the same. See \c mbedtls_ssl_get_output_max_frag_len() for + * more detail. + * + * \sa mbedtls_ssl_get_input_max_frag_len() + * \sa mbedtls_ssl_get_output_max_frag_len() + * + * \param ssl SSL context + * + * \return Current maximum fragment length for the output buffer. */ -size_t mbedtls_ssl_get_max_frag_len( const mbedtls_ssl_context *ssl ); +MBEDTLS_DEPRECATED size_t mbedtls_ssl_get_max_frag_len( + const mbedtls_ssl_context *ssl ); +#endif /* MBEDTLS_DEPRECATED_REMOVED */ #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */ /** @@ -2897,7 +3862,8 @@ size_t mbedtls_ssl_get_max_frag_len( const mbedtls_ssl_context *ssl ); * when record compression is enabled. * * \sa mbedtls_ssl_set_mtu() - * \sa mbedtls_ssl_get_max_frag_len() + * \sa mbedtls_ssl_get_output_max_frag_len() + * \sa mbedtls_ssl_get_input_max_frag_len() * \sa mbedtls_ssl_get_record_expansion() * * \param ssl SSL context @@ -2909,18 +3875,34 @@ int mbedtls_ssl_get_max_out_record_payload( const mbedtls_ssl_context *ssl ); #if defined(MBEDTLS_X509_CRT_PARSE_C) /** - * \brief Return the peer certificate from the current connection - * - * Note: Can be NULL in case no certificate was sent during - * the handshake. Different calls for the same connection can - * return the same or different pointers for the same - * certificate and even a different certificate altogether. - * The peer cert CAN change in a single connection if - * renegotiation is performed. - * - * \param ssl SSL context - * - * \return the current peer certificate + * \brief Return the peer certificate from the current connection. + * + * \param ssl The SSL context to use. This must be initialized and setup. + * + * \return The current peer certificate, if available. + * The returned certificate is owned by the SSL context and + * is valid only until the next call to the SSL API. + * \return \c NULL if no peer certificate is available. This might + * be because the chosen ciphersuite doesn't use CRTs + * (PSK-based ciphersuites, for example), or because + * #MBEDTLS_SSL_KEEP_PEER_CERTIFICATE has been disabled, + * allowing the stack to free the peer's CRT to save memory. + * + * \note For one-time inspection of the peer's certificate during + * the handshake, consider registering an X.509 CRT verification + * callback through mbedtls_ssl_conf_verify() instead of calling + * this function. Using mbedtls_ssl_conf_verify() also comes at + * the benefit of allowing you to influence the verification + * process, for example by masking expected and tolerated + * verification failures. + * + * \warning You must not use the pointer returned by this function + * after any further call to the SSL API, including + * mbedtls_ssl_read() and mbedtls_ssl_write(); this is + * because the pointer might change during renegotiation, + * which happens transparently to the user. + * If you want to use the certificate across API calls, + * you must make a copy. */ const mbedtls_x509_crt *mbedtls_ssl_get_peer_cert( const mbedtls_ssl_context *ssl ); #endif /* MBEDTLS_X509_CRT_PARSE_C */ @@ -3065,7 +4047,14 @@ int mbedtls_ssl_renegotiate( mbedtls_ssl_context *ssl ); * * \return The (positive) number of bytes read if successful. * \return \c 0 if the read end of the underlying transport was closed - * - in this case you must stop using the context (see below). + * without sending a CloseNotify beforehand, which might happen + * because of various reasons (internal error of an underlying + * stack, non-conformant peer not sending a CloseNotify and + * such) - in this case you must stop using the context + * (see below). + * \return #MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY if the underlying + * transport is still functional, but the peer has + * acknowledged to not send anything anymore. * \return #MBEDTLS_ERR_SSL_WANT_READ or #MBEDTLS_ERR_SSL_WANT_WRITE * if the handshake is incomplete and waiting for data to * be available for reading from or writing to the underlying @@ -3182,8 +4171,8 @@ int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len ) * or negotiated with the peer), then: * - with TLS, less bytes than requested are written. * - with DTLS, MBEDTLS_ERR_SSL_BAD_INPUT_DATA is returned. - * \c mbedtls_ssl_get_max_frag_len() may be used to query the - * active maximum fragment length. + * \c mbedtls_ssl_get_output_max_frag_len() may be used to + * query the active maximum fragment length. * * \note Attempting to write 0 bytes will result in an empty TLS * application record being sent. @@ -3231,6 +4220,130 @@ int mbedtls_ssl_close_notify( mbedtls_ssl_context *ssl ); */ void mbedtls_ssl_free( mbedtls_ssl_context *ssl ); +#if defined(MBEDTLS_SSL_CONTEXT_SERIALIZATION) +/** + * \brief Save an active connection as serialized data in a buffer. + * This allows the freeing or re-using of the SSL context + * while still picking up the connection later in a way that + * it entirely transparent to the peer. + * + * \see mbedtls_ssl_context_load() + * + * \note This feature is currently only available under certain + * conditions, see the documentation of the return value + * #MBEDTLS_ERR_SSL_BAD_INPUT_DATA for details. + * + * \note When this function succeeds, it calls + * mbedtls_ssl_session_reset() on \p ssl which as a result is + * no longer associated with the connection that has been + * serialized. This avoids creating copies of the connection + * state. You're then free to either re-use the context + * structure for a different connection, or call + * mbedtls_ssl_free() on it. See the documentation of + * mbedtls_ssl_session_reset() for more details. + * + * \param ssl The SSL context to save. On success, it is no longer + * associated with the connection that has been serialized. + * \param buf The buffer to write the serialized data to. It must be a + * writeable buffer of at least \p buf_len bytes, or may be \c + * NULL if \p buf_len is \c 0. + * \param buf_len The number of bytes available for writing in \p buf. + * \param olen The size in bytes of the data that has been or would have + * been written. It must point to a valid \c size_t. + * + * \note \p olen is updated to the correct value regardless of + * whether \p buf_len was large enough. This makes it possible + * to determine the necessary size by calling this function + * with \p buf set to \c NULL and \p buf_len to \c 0. However, + * the value of \p olen is only guaranteed to be correct when + * the function returns #MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL or + * \c 0. If the return value is different, then the value of + * \p olen is undefined. + * + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL if \p buf is too small. + * \return #MBEDTLS_ERR_SSL_ALLOC_FAILED if memory allocation failed + * while reseting the context. + * \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA if a handshake is in + * progress, or there is pending data for reading or sending, + * or the connection does not use DTLS 1.2 with an AEAD + * ciphersuite, or renegotiation is enabled. + */ +int mbedtls_ssl_context_save( mbedtls_ssl_context *ssl, + unsigned char *buf, + size_t buf_len, + size_t *olen ); + +/** + * \brief Load serialized connection data to an SSL context. + * + * \see mbedtls_ssl_context_save() + * + * \warning The same serialized data must never be loaded into more + * that one context. In order to ensure that, after + * successfully loading serialized data to an SSL context, you + * should immediately destroy or invalidate all copies of the + * serialized data that was loaded. Loading the same data in + * more than one context would cause severe security failures + * including but not limited to loss of confidentiality. + * + * \note Before calling this function, the SSL context must be + * prepared in one of the two following ways. The first way is + * to take a context freshly initialised with + * mbedtls_ssl_init() and call mbedtls_ssl_setup() on it with + * the same ::mbedtls_ssl_config structure that was used in + * the original connection. The second way is to + * call mbedtls_ssl_session_reset() on a context that was + * previously prepared as above but used in the meantime. + * Either way, you must not use the context to perform a + * handshake between calling mbedtls_ssl_setup() or + * mbedtls_ssl_session_reset() and calling this function. You + * may however call other setter functions in that time frame + * as indicated in the note below. + * + * \note Before or after calling this function successfully, you + * also need to configure some connection-specific callbacks + * and settings before you can use the connection again + * (unless they were already set before calling + * mbedtls_ssl_session_reset() and the values are suitable for + * the present connection). Specifically, you want to call + * at least mbedtls_ssl_set_bio() and + * mbedtls_ssl_set_timer_cb(). All other SSL setter functions + * are not necessary to call, either because they're only used + * in handshakes, or because the setting is already saved. You + * might choose to call them anyway, for example in order to + * share code between the cases of establishing a new + * connection and the case of loading an already-established + * connection. + * + * \note If you have new information about the path MTU, you want to + * call mbedtls_ssl_set_mtu() after calling this function, as + * otherwise this function would overwrite your + * newly-configured value with the value that was active when + * the context was saved. + * + * \note When this function returns an error code, it calls + * mbedtls_ssl_free() on \p ssl. In this case, you need to + * prepare the context with the usual sequence starting with a + * call to mbedtls_ssl_init() if you want to use it again. + * + * \param ssl The SSL context structure to be populated. It must have + * been prepared as described in the note above. + * \param buf The buffer holding the serialized connection data. It must + * be a readable buffer of at least \p len bytes. + * \param len The size of the serialized data in bytes. + * + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_SSL_ALLOC_FAILED if memory allocation failed. + * \return #MBEDTLS_ERR_SSL_VERSION_MISMATCH if the serialized data + * comes from a different Mbed TLS version or build. + * \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA if input data is invalid. + */ +int mbedtls_ssl_context_load( mbedtls_ssl_context *ssl, + const unsigned char *buf, + size_t len ); +#endif /* MBEDTLS_SSL_CONTEXT_SERIALIZATION */ + /** * \brief Initialize an SSL configuration context * Just makes the context ready for @@ -3286,6 +4399,27 @@ void mbedtls_ssl_session_init( mbedtls_ssl_session *session ); */ void mbedtls_ssl_session_free( mbedtls_ssl_session *session ); +/** + * \brief TLS-PRF function for key derivation. + * + * \param prf The tls_prf type function type to be used. + * \param secret Secret for the key derivation function. + * \param slen Length of the secret. + * \param label String label for the key derivation function, + * terminated with null character. + * \param random Random bytes. + * \param rlen Length of the random bytes buffer. + * \param dstbuf The buffer holding the derived key. + * \param dlen Length of the output buffer. + * + * \return 0 on success. An SSL specific error on failure. + */ +int mbedtls_ssl_tls_prf( const mbedtls_tls_prf_types prf, + const unsigned char *secret, size_t slen, + const char *label, + const unsigned char *random, size_t rlen, + unsigned char *dstbuf, size_t dlen ); + #ifdef __cplusplus } #endif diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ssl_cache.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ssl_cache.h index 612d81776ef..c6ef2960f4d 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ssl_cache.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ssl_cache.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,41 +18,20 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_SSL_CACHE_H #define MBEDTLS_SSL_CACHE_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "ssl.h" +#include "mbedtls/ssl.h" #if defined(MBEDTLS_THREADING_C) -#include "threading.h" +#include "mbedtls/threading.h" #endif /** @@ -95,7 +68,8 @@ struct mbedtls_ssl_cache_entry mbedtls_time_t timestamp; /*!< entry timestamp */ #endif mbedtls_ssl_session session; /*!< entry session */ -#if defined(MBEDTLS_X509_CRT_PARSE_C) +#if defined(MBEDTLS_X509_CRT_PARSE_C) && \ + defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE) mbedtls_x509_buf peer_cert; /*!< entry peer_cert */ #endif mbedtls_ssl_cache_entry *next; /*!< chain pointer */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ssl_ciphersuites.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ssl_ciphersuites.h index ab8e601db71..93c32a5edac 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ssl_ciphersuites.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ssl_ciphersuites.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,40 +18,19 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_SSL_CIPHERSUITES_H #define MBEDTLS_SSL_CIPHERSUITES_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "pk.h" -#include "cipher.h" -#include "md.h" +#include "mbedtls/pk.h" +#include "mbedtls/cipher.h" +#include "mbedtls/md.h" #ifdef __cplusplus extern "C" { @@ -337,7 +310,7 @@ typedef enum { defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) || \ defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \ defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) -#define MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED +#define MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED #endif /* Key exchanges allowing client certificate requests */ @@ -347,28 +320,28 @@ typedef enum { defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \ defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) || \ defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) -#define MBEDTLS_KEY_EXCHANGE__CERT_REQ_ALLOWED__ENABLED +#define MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED #endif /* Key exchanges involving server signature in ServerKeyExchange */ #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \ defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \ defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) -#define MBEDTLS_KEY_EXCHANGE__WITH_SERVER_SIGNATURE__ENABLED +#define MBEDTLS_KEY_EXCHANGE_WITH_SERVER_SIGNATURE_ENABLED #endif /* Key exchanges using ECDH */ #if defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \ defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) -#define MBEDTLS_KEY_EXCHANGE__SOME__ECDH_ENABLED +#define MBEDTLS_KEY_EXCHANGE_SOME_ECDH_ENABLED #endif /* Key exchanges that don't involve ephemeral keys */ #if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || \ defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) || \ defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) || \ - defined(MBEDTLS_KEY_EXCHANGE__SOME__ECDH_ENABLED) -#define MBEDTLS_KEY_EXCHANGE__SOME_NON_PFS__ENABLED + defined(MBEDTLS_KEY_EXCHANGE_SOME_ECDH_ENABLED) +#define MBEDTLS_KEY_EXCHANGE_SOME_NON_PFS_ENABLED #endif /* Key exchanges that involve ephemeral keys */ @@ -378,7 +351,7 @@ typedef enum { defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) || \ defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \ defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) -#define MBEDTLS_KEY_EXCHANGE__SOME_PFS__ENABLED +#define MBEDTLS_KEY_EXCHANGE_SOME_PFS_ENABLED #endif /* Key exchanges using a PSK */ @@ -386,20 +359,20 @@ typedef enum { defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) || \ defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) || \ defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) -#define MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED +#define MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED #endif /* Key exchanges using DHE */ #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \ defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) -#define MBEDTLS_KEY_EXCHANGE__SOME__DHE_ENABLED +#define MBEDTLS_KEY_EXCHANGE_SOME_DHE_ENABLED #endif /* Key exchanges using ECDHE */ #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \ defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \ defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) -#define MBEDTLS_KEY_EXCHANGE__SOME__ECDHE_ENABLED +#define MBEDTLS_KEY_EXCHANGE_SOME_ECDHE_ENABLED #endif typedef struct mbedtls_ssl_ciphersuite_t mbedtls_ssl_ciphersuite_t; @@ -442,7 +415,7 @@ mbedtls_pk_type_t mbedtls_ssl_get_ciphersuite_sig_alg( const mbedtls_ssl_ciphers int mbedtls_ssl_ciphersuite_uses_ec( const mbedtls_ssl_ciphersuite_t *info ); int mbedtls_ssl_ciphersuite_uses_psk( const mbedtls_ssl_ciphersuite_t *info ); -#if defined(MBEDTLS_KEY_EXCHANGE__SOME_PFS__ENABLED) +#if defined(MBEDTLS_KEY_EXCHANGE_SOME_PFS_ENABLED) static inline int mbedtls_ssl_ciphersuite_has_pfs( const mbedtls_ssl_ciphersuite_t *info ) { switch( info->key_exchange ) @@ -459,9 +432,9 @@ static inline int mbedtls_ssl_ciphersuite_has_pfs( const mbedtls_ssl_ciphersuite return( 0 ); } } -#endif /* MBEDTLS_KEY_EXCHANGE__SOME_PFS__ENABLED */ +#endif /* MBEDTLS_KEY_EXCHANGE_SOME_PFS_ENABLED */ -#if defined(MBEDTLS_KEY_EXCHANGE__SOME_NON_PFS__ENABLED) +#if defined(MBEDTLS_KEY_EXCHANGE_SOME_NON_PFS_ENABLED) static inline int mbedtls_ssl_ciphersuite_no_pfs( const mbedtls_ssl_ciphersuite_t *info ) { switch( info->key_exchange ) @@ -477,9 +450,9 @@ static inline int mbedtls_ssl_ciphersuite_no_pfs( const mbedtls_ssl_ciphersuite_ return( 0 ); } } -#endif /* MBEDTLS_KEY_EXCHANGE__SOME_NON_PFS__ENABLED */ +#endif /* MBEDTLS_KEY_EXCHANGE_SOME_NON_PFS_ENABLED */ -#if defined(MBEDTLS_KEY_EXCHANGE__SOME__ECDH_ENABLED) +#if defined(MBEDTLS_KEY_EXCHANGE_SOME_ECDH_ENABLED) static inline int mbedtls_ssl_ciphersuite_uses_ecdh( const mbedtls_ssl_ciphersuite_t *info ) { switch( info->key_exchange ) @@ -492,7 +465,7 @@ static inline int mbedtls_ssl_ciphersuite_uses_ecdh( const mbedtls_ssl_ciphersui return( 0 ); } } -#endif /* MBEDTLS_KEY_EXCHANGE__SOME__ECDH_ENABLED */ +#endif /* MBEDTLS_KEY_EXCHANGE_SOME_ECDH_ENABLED */ static inline int mbedtls_ssl_ciphersuite_cert_req_allowed( const mbedtls_ssl_ciphersuite_t *info ) { @@ -511,7 +484,25 @@ static inline int mbedtls_ssl_ciphersuite_cert_req_allowed( const mbedtls_ssl_ci } } -#if defined(MBEDTLS_KEY_EXCHANGE__SOME__DHE_ENABLED) +static inline int mbedtls_ssl_ciphersuite_uses_srv_cert( const mbedtls_ssl_ciphersuite_t *info ) +{ + switch( info->key_exchange ) + { + case MBEDTLS_KEY_EXCHANGE_RSA: + case MBEDTLS_KEY_EXCHANGE_RSA_PSK: + case MBEDTLS_KEY_EXCHANGE_DHE_RSA: + case MBEDTLS_KEY_EXCHANGE_ECDH_RSA: + case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA: + case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA: + case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA: + return( 1 ); + + default: + return( 0 ); + } +} + +#if defined(MBEDTLS_KEY_EXCHANGE_SOME_DHE_ENABLED) static inline int mbedtls_ssl_ciphersuite_uses_dhe( const mbedtls_ssl_ciphersuite_t *info ) { switch( info->key_exchange ) @@ -524,9 +515,9 @@ static inline int mbedtls_ssl_ciphersuite_uses_dhe( const mbedtls_ssl_ciphersuit return( 0 ); } } -#endif /* MBEDTLS_KEY_EXCHANGE__SOME__DHE_ENABLED) */ +#endif /* MBEDTLS_KEY_EXCHANGE_SOME_DHE_ENABLED) */ -#if defined(MBEDTLS_KEY_EXCHANGE__SOME__ECDHE_ENABLED) +#if defined(MBEDTLS_KEY_EXCHANGE_SOME_ECDHE_ENABLED) static inline int mbedtls_ssl_ciphersuite_uses_ecdhe( const mbedtls_ssl_ciphersuite_t *info ) { switch( info->key_exchange ) @@ -540,9 +531,9 @@ static inline int mbedtls_ssl_ciphersuite_uses_ecdhe( const mbedtls_ssl_ciphersu return( 0 ); } } -#endif /* MBEDTLS_KEY_EXCHANGE__SOME__ECDHE_ENABLED) */ +#endif /* MBEDTLS_KEY_EXCHANGE_SOME_ECDHE_ENABLED) */ -#if defined(MBEDTLS_KEY_EXCHANGE__WITH_SERVER_SIGNATURE__ENABLED) +#if defined(MBEDTLS_KEY_EXCHANGE_WITH_SERVER_SIGNATURE_ENABLED) static inline int mbedtls_ssl_ciphersuite_uses_server_signature( const mbedtls_ssl_ciphersuite_t *info ) { switch( info->key_exchange ) @@ -556,7 +547,7 @@ static inline int mbedtls_ssl_ciphersuite_uses_server_signature( const mbedtls_s return( 0 ); } } -#endif /* MBEDTLS_KEY_EXCHANGE__WITH_SERVER_SIGNATURE__ENABLED */ +#endif /* MBEDTLS_KEY_EXCHANGE_WITH_SERVER_SIGNATURE_ENABLED */ #ifdef __cplusplus } diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ssl_cookie.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ssl_cookie.h index 9c2d5b62a43..0a238708e59 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ssl_cookie.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ssl_cookie.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,41 +18,20 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_SSL_COOKIE_H #define MBEDTLS_SSL_COOKIE_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "ssl.h" +#include "mbedtls/ssl.h" #if defined(MBEDTLS_THREADING_C) -#include "threading.h" +#include "mbedtls/threading.h" #endif /** diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ssl_internal.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ssl_internal.h index 6ba6c2af09d..6913dc0f668 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ssl_internal.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ssl_internal.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,60 +18,48 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_SSL_INTERNAL_H #define MBEDTLS_SSL_INTERNAL_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "ssl.h" -#include "cipher.h" +#include "mbedtls/ssl.h" +#include "mbedtls/cipher.h" + +#if defined(MBEDTLS_USE_PSA_CRYPTO) +#include "psa/crypto.h" +#endif #if defined(MBEDTLS_MD5_C) -#include "md5.h" +#include "mbedtls/md5.h" #endif #if defined(MBEDTLS_SHA1_C) -#include "sha1.h" +#include "mbedtls/sha1.h" #endif #if defined(MBEDTLS_SHA256_C) -#include "sha256.h" +#include "mbedtls/sha256.h" #endif #if defined(MBEDTLS_SHA512_C) -#include "sha512.h" +#include "mbedtls/sha512.h" #endif #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) -#include "ecjpake.h" +#include "mbedtls/ecjpake.h" #endif +#if defined(MBEDTLS_USE_PSA_CRYPTO) +#include "psa/crypto.h" +#include "mbedtls/psa_util.h" +#endif /* MBEDTLS_USE_PSA_CRYPTO */ + #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ !defined(inline) && !defined(__cplusplus) #define inline __inline @@ -129,7 +111,7 @@ defined(MBEDTLS_SSL_CLI_C) && \ defined(MBEDTLS_SSL_PROTO_TLS1_2) && \ defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) -#define MBEDTLS_SSL__ECP_RESTARTABLE +#define MBEDTLS_SSL_ECP_RESTARTABLE_ENABLED #endif #define MBEDTLS_SSL_INITIAL_HANDSHAKE 0 @@ -150,6 +132,18 @@ #define MBEDTLS_SSL_RETRANS_WAITING 2 #define MBEDTLS_SSL_RETRANS_FINISHED 3 +/* + * Allow extra bytes for record, authentication and encryption overhead: + * counter (8) + header (5) + IV(16) + MAC (16-48) + padding (0-256) + * and allow for a maximum of 1024 of compression expansion if + * enabled. + */ +#if defined(MBEDTLS_ZLIB_SUPPORT) +#define MBEDTLS_SSL_COMPRESSION_ADD 1024 +#else +#define MBEDTLS_SSL_COMPRESSION_ADD 0 +#endif + /* This macro determines whether CBC is supported. */ #if defined(MBEDTLS_CIPHER_MODE_CBC) && \ ( defined(MBEDTLS_AES_C) || \ @@ -168,19 +162,12 @@ #define MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC #endif -/* - * Allow extra bytes for record, authentication and encryption overhead: - * counter (8) + header (5) + IV(16) + MAC (16-48) + padding (0-256) - * and allow for a maximum of 1024 of compression expansion if - * enabled. - */ -#if defined(MBEDTLS_ZLIB_SUPPORT) -#define MBEDTLS_SSL_COMPRESSION_ADD 1024 -#else -#define MBEDTLS_SSL_COMPRESSION_ADD 0 +#if defined(MBEDTLS_ARC4_C) || defined(MBEDTLS_CIPHER_NULL_CIPHER) || \ + defined(MBEDTLS_SSL_SOME_SUITES_USE_CBC) +#define MBEDTLS_SSL_SOME_MODES_USE_MAC #endif -#if defined(MBEDTLS_ARC4_C) || defined(MBEDTLS_CIPHER_MODE_CBC) +#if defined(MBEDTLS_SSL_SOME_MODES_USE_MAC) /* Ciphersuites using HMAC */ #if defined(MBEDTLS_SHA512_C) #define MBEDTLS_SSL_MAC_ADD 48 /* SHA-384 used for HMAC */ @@ -189,7 +176,7 @@ #else #define MBEDTLS_SSL_MAC_ADD 20 /* SHA-1 used for HMAC */ #endif -#else +#else /* MBEDTLS_SSL_SOME_MODES_USE_MAC */ /* AEAD ciphersuites: GCM and CCM use a 128 bits tag */ #define MBEDTLS_SSL_MAC_ADD 16 #endif @@ -200,10 +187,17 @@ #define MBEDTLS_SSL_PADDING_ADD 0 #endif +#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) +#define MBEDTLS_SSL_MAX_CID_EXPANSION MBEDTLS_SSL_CID_PADDING_GRANULARITY +#else +#define MBEDTLS_SSL_MAX_CID_EXPANSION 0 +#endif + #define MBEDTLS_SSL_PAYLOAD_OVERHEAD ( MBEDTLS_SSL_COMPRESSION_ADD + \ MBEDTLS_MAX_IV_LENGTH + \ MBEDTLS_SSL_MAC_ADD + \ - MBEDTLS_SSL_PADDING_ADD \ + MBEDTLS_SSL_PADDING_ADD + \ + MBEDTLS_SSL_MAX_CID_EXPANSION \ ) #define MBEDTLS_SSL_IN_PAYLOAD_LEN ( MBEDTLS_SSL_PAYLOAD_OVERHEAD + \ @@ -262,11 +256,49 @@ implicit sequence number. */ #define MBEDTLS_SSL_HEADER_LEN 13 +#if !defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) #define MBEDTLS_SSL_IN_BUFFER_LEN \ ( ( MBEDTLS_SSL_HEADER_LEN ) + ( MBEDTLS_SSL_IN_PAYLOAD_LEN ) ) +#else +#define MBEDTLS_SSL_IN_BUFFER_LEN \ + ( ( MBEDTLS_SSL_HEADER_LEN ) + ( MBEDTLS_SSL_IN_PAYLOAD_LEN ) \ + + ( MBEDTLS_SSL_CID_IN_LEN_MAX ) ) +#endif +#if !defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) #define MBEDTLS_SSL_OUT_BUFFER_LEN \ ( ( MBEDTLS_SSL_HEADER_LEN ) + ( MBEDTLS_SSL_OUT_PAYLOAD_LEN ) ) +#else +#define MBEDTLS_SSL_OUT_BUFFER_LEN \ + ( ( MBEDTLS_SSL_HEADER_LEN ) + ( MBEDTLS_SSL_OUT_PAYLOAD_LEN ) \ + + ( MBEDTLS_SSL_CID_OUT_LEN_MAX ) ) +#endif + +#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH) +static inline size_t mbedtls_ssl_get_output_buflen( const mbedtls_ssl_context *ctx ) +{ +#if defined (MBEDTLS_SSL_DTLS_CONNECTION_ID) + return mbedtls_ssl_get_output_max_frag_len( ctx ) + + MBEDTLS_SSL_HEADER_LEN + MBEDTLS_SSL_PAYLOAD_OVERHEAD + + MBEDTLS_SSL_CID_OUT_LEN_MAX; +#else + return mbedtls_ssl_get_output_max_frag_len( ctx ) + + MBEDTLS_SSL_HEADER_LEN + MBEDTLS_SSL_PAYLOAD_OVERHEAD; +#endif +} + +static inline size_t mbedtls_ssl_get_input_buflen( const mbedtls_ssl_context *ctx ) +{ +#if defined (MBEDTLS_SSL_DTLS_CONNECTION_ID) + return mbedtls_ssl_get_input_max_frag_len( ctx ) + + MBEDTLS_SSL_HEADER_LEN + MBEDTLS_SSL_PAYLOAD_OVERHEAD + + MBEDTLS_SSL_CID_IN_LEN_MAX; +#else + return mbedtls_ssl_get_input_max_frag_len( ctx ) + + MBEDTLS_SSL_HEADER_LEN + MBEDTLS_SSL_PAYLOAD_OVERHEAD; +#endif +} +#endif #ifdef MBEDTLS_ZLIB_SUPPORT /* Compression buffer holds both IN and OUT buffers, so should be size of the larger */ @@ -325,7 +357,7 @@ extern "C" { #endif #if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \ - defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED) + defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED) /* * Abstraction for a grid of allowed signature-hash-algorithm pairs. */ @@ -340,7 +372,54 @@ struct mbedtls_ssl_sig_hash_set_t mbedtls_md_type_t ecdsa; }; #endif /* MBEDTLS_SSL_PROTO_TLS1_2 && - MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED */ + MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED */ + +typedef int mbedtls_ssl_tls_prf_cb( const unsigned char *secret, size_t slen, + const char *label, + const unsigned char *random, size_t rlen, + unsigned char *dstbuf, size_t dlen ); + +/* cipher.h exports the maximum IV, key and block length from + * all ciphers enabled in the config, regardless of whether those + * ciphers are actually usable in SSL/TLS. Notably, XTS is enabled + * in the default configuration and uses 64 Byte keys, but it is + * not used for record protection in SSL/TLS. + * + * In order to prevent unnecessary inflation of key structures, + * we introduce SSL-specific variants of the max-{key,block,IV} + * macros here which are meant to only take those ciphers into + * account which can be negotiated in SSL/TLS. + * + * Since the current definitions of MBEDTLS_MAX_{KEY|BLOCK|IV}_LENGTH + * in cipher.h are rough overapproximations of the real maxima, here + * we content ourselves with replicating those overapproximations + * for the maximum block and IV length, and excluding XTS from the + * computation of the maximum key length. */ +#define MBEDTLS_SSL_MAX_BLOCK_LENGTH 16 +#define MBEDTLS_SSL_MAX_IV_LENGTH 16 +#define MBEDTLS_SSL_MAX_KEY_LENGTH 32 + +/** + * \brief The data structure holding the cryptographic material (key and IV) + * used for record protection in TLS 1.3. + */ +struct mbedtls_ssl_key_set +{ + /*! The key for client->server records. */ + unsigned char client_write_key[ MBEDTLS_SSL_MAX_KEY_LENGTH ]; + /*! The key for server->client records. */ + unsigned char server_write_key[ MBEDTLS_SSL_MAX_KEY_LENGTH ]; + /*! The IV for client->server records. */ + unsigned char client_write_iv[ MBEDTLS_SSL_MAX_IV_LENGTH ]; + /*! The IV for server->client records. */ + unsigned char server_write_iv[ MBEDTLS_SSL_MAX_IV_LENGTH ]; + + size_t key_len; /*!< The length of client_write_key and + * server_write_key, in Bytes. */ + size_t iv_len; /*!< The length of client_write_iv and + * server_write_iv, in Bytes. */ +}; +typedef struct mbedtls_ssl_key_set mbedtls_ssl_key_set; /* * This structure contains the parameters only needed during handshake. @@ -351,16 +430,80 @@ struct mbedtls_ssl_handshake_params * Handshake specific crypto variables */ -#if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \ - defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED) + uint8_t max_major_ver; /*!< max. major version client*/ + uint8_t max_minor_ver; /*!< max. minor version client*/ + uint8_t resume; /*!< session resume indicator*/ + uint8_t cli_exts; /*!< client extension presence*/ + +#if defined(MBEDTLS_X509_CRT_PARSE_C) && \ + defined(MBEDTLS_SSL_SERVER_NAME_INDICATION) + uint8_t sni_authmode; /*!< authmode from SNI callback */ +#endif + +#if defined(MBEDTLS_SSL_SESSION_TICKETS) + uint8_t new_session_ticket; /*!< use NewSessionTicket? */ +#endif /* MBEDTLS_SSL_SESSION_TICKETS */ + +#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET) + uint8_t extended_ms; /*!< use Extended Master Secret? */ +#endif + +#if defined(MBEDTLS_SSL_ASYNC_PRIVATE) + uint8_t async_in_progress; /*!< an asynchronous operation is in progress */ +#endif /* MBEDTLS_SSL_ASYNC_PRIVATE */ + +#if defined(MBEDTLS_SSL_PROTO_DTLS) + unsigned char retransmit_state; /*!< Retransmission state */ +#endif + +#if defined(MBEDTLS_SSL_ECP_RESTARTABLE_ENABLED) + uint8_t ecrs_enabled; /*!< Handshake supports EC restart? */ + enum { /* this complements ssl->state with info on intra-state operations */ + ssl_ecrs_none = 0, /*!< nothing going on (yet) */ + ssl_ecrs_crt_verify, /*!< Certificate: crt_verify() */ + ssl_ecrs_ske_start_processing, /*!< ServerKeyExchange: pk_verify() */ + ssl_ecrs_cke_ecdh_calc_secret, /*!< ClientKeyExchange: ECDH step 2 */ + ssl_ecrs_crt_vrfy_sign, /*!< CertificateVerify: pk_sign() */ + } ecrs_state; /*!< current (or last) operation */ + mbedtls_x509_crt *ecrs_peer_cert; /*!< The peer's CRT chain. */ + size_t ecrs_n; /*!< place for saving a length */ +#endif + +#if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \ + defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED) mbedtls_ssl_sig_hash_set_t hash_algs; /*!< Set of suitable sig-hash pairs */ #endif + + size_t pmslen; /*!< premaster length */ + + mbedtls_ssl_ciphersuite_t const *ciphersuite_info; + + void (*update_checksum)(mbedtls_ssl_context *, const unsigned char *, size_t); + void (*calc_verify)(const mbedtls_ssl_context *, unsigned char *, size_t *); + void (*calc_finished)(mbedtls_ssl_context *, unsigned char *, int); + mbedtls_ssl_tls_prf_cb *tls_prf; + #if defined(MBEDTLS_DHM_C) mbedtls_dhm_context dhm_ctx; /*!< DHM key exchange */ #endif -#if defined(MBEDTLS_ECDH_C) + +/* Adding guard for MBEDTLS_ECDSA_C to ensure no compile errors due + * to guards also being in ssl_srv.c and ssl_cli.c. There is a gap + * in functionality that access to ecdh_ctx structure is needed for + * MBEDTLS_ECDSA_C which does not seem correct. + */ +#if defined(MBEDTLS_ECDH_C) || defined(MBEDTLS_ECDSA_C) mbedtls_ecdh_context ecdh_ctx; /*!< ECDH key exchange */ -#endif + +#if defined(MBEDTLS_USE_PSA_CRYPTO) + psa_key_type_t ecdh_psa_type; + uint16_t ecdh_bits; + psa_key_id_t ecdh_psa_privkey; + unsigned char ecdh_psa_peerkey[MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH]; + size_t ecdh_psa_peerkey_len; +#endif /* MBEDTLS_USE_PSA_CRYPTO */ +#endif /* MBEDTLS_ECDH_C || MBEDTLS_ECDSA_C */ + #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) mbedtls_ecjpake_context ecjpake_ctx; /*!< EC J-PAKE key exchange */ #if defined(MBEDTLS_SSL_CLI_C) @@ -368,56 +511,39 @@ struct mbedtls_ssl_handshake_params size_t ecjpake_cache_len; /*!< Length of cached data */ #endif #endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */ -#if defined(MBEDTLS_ECDH_C) || defined(MBEDTLS_ECDSA_C) || \ + +#if defined(MBEDTLS_ECDH_C) || defined(MBEDTLS_ECDSA_C) || \ defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) const mbedtls_ecp_curve_info **curves; /*!< Supported elliptic curves */ #endif -#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED) + +#if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED) +#if defined(MBEDTLS_USE_PSA_CRYPTO) + psa_key_id_t psk_opaque; /*!< Opaque PSK from the callback */ +#endif /* MBEDTLS_USE_PSA_CRYPTO */ unsigned char *psk; /*!< PSK from the callback */ size_t psk_len; /*!< Length of PSK from callback */ -#endif +#endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */ + #if defined(MBEDTLS_X509_CRT_PARSE_C) mbedtls_ssl_key_cert *key_cert; /*!< chosen key/cert pair (server) */ #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION) - int sni_authmode; /*!< authmode from SNI callback */ mbedtls_ssl_key_cert *sni_key_cert; /*!< key/cert list from SNI */ mbedtls_x509_crt *sni_ca_chain; /*!< trusted CAs from SNI callback */ mbedtls_x509_crl *sni_ca_crl; /*!< trusted CAs CRLs from SNI */ #endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */ #endif /* MBEDTLS_X509_CRT_PARSE_C */ -#if defined(MBEDTLS_SSL__ECP_RESTARTABLE) - int ecrs_enabled; /*!< Handshake supports EC restart? */ + +#if defined(MBEDTLS_SSL_ECP_RESTARTABLE_ENABLED) mbedtls_x509_crt_restart_ctx ecrs_ctx; /*!< restart context */ - enum { /* this complements ssl->state with info on intra-state operations */ - ssl_ecrs_none = 0, /*!< nothing going on (yet) */ - ssl_ecrs_crt_verify, /*!< Certificate: crt_verify() */ - ssl_ecrs_ske_start_processing, /*!< ServerKeyExchange: pk_verify() */ - ssl_ecrs_cke_ecdh_calc_secret, /*!< ClientKeyExchange: ECDH step 2 */ - ssl_ecrs_crt_vrfy_sign, /*!< CertificateVerify: pk_sign() */ - } ecrs_state; /*!< current (or last) operation */ - size_t ecrs_n; /*!< place for saving a length */ #endif -#if defined(MBEDTLS_SSL_PROTO_DTLS) - unsigned int out_msg_seq; /*!< Outgoing handshake sequence number */ - unsigned int in_msg_seq; /*!< Incoming handshake sequence number */ - - unsigned char *verify_cookie; /*!< Cli: HelloVerifyRequest cookie - Srv: unused */ - unsigned char verify_cookie_len; /*!< Cli: cookie length - Srv: flag for sending a cookie */ - uint32_t retransmit_timeout; /*!< Current value of timeout */ - unsigned char retransmit_state; /*!< Retransmission state */ - mbedtls_ssl_flight_item *flight; /*!< Current outgoing flight */ - mbedtls_ssl_flight_item *cur_msg; /*!< Current message in flight */ - unsigned char *cur_msg_p; /*!< Position in current message */ - unsigned int in_flight_start_seq; /*!< Minimum message sequence in the - flight being received */ - mbedtls_ssl_transform *alt_transform_out; /*!< Alternative transform for - resending messages */ - unsigned char alt_out_ctr[8]; /*!< Alternative record epoch/counter - for resending messages */ +#if defined(MBEDTLS_X509_CRT_PARSE_C) && \ + !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE) + mbedtls_pk_context peer_pubkey; /*!< The public key from the peer. */ +#endif /* MBEDTLS_X509_CRT_PARSE_C && !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */ +#if defined(MBEDTLS_SSL_PROTO_DTLS) struct { size_t total_bytes_buffered; /*!< Cumulative size of heap allocated @@ -444,6 +570,37 @@ struct mbedtls_ssl_handshake_params } buffering; + unsigned int out_msg_seq; /*!< Outgoing handshake sequence number */ + unsigned int in_msg_seq; /*!< Incoming handshake sequence number */ + + unsigned char *verify_cookie; /*!< Cli: HelloVerifyRequest cookie + Srv: unused */ + unsigned char verify_cookie_len; /*!< Cli: cookie length + Srv: flag for sending a cookie */ + + uint32_t retransmit_timeout; /*!< Current value of timeout */ + mbedtls_ssl_flight_item *flight; /*!< Current outgoing flight */ + mbedtls_ssl_flight_item *cur_msg; /*!< Current message in flight */ + unsigned char *cur_msg_p; /*!< Position in current message */ + unsigned int in_flight_start_seq; /*!< Minimum message sequence in the + flight being received */ + mbedtls_ssl_transform *alt_transform_out; /*!< Alternative transform for + resending messages */ + unsigned char alt_out_ctr[8]; /*!< Alternative record epoch/counter + for resending messages */ + +#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) + /* The state of CID configuration in this handshake. */ + + uint8_t cid_in_use; /*!< This indicates whether the use of the CID extension + * has been negotiated. Possible values are + * #MBEDTLS_SSL_CID_ENABLED and + * #MBEDTLS_SSL_CID_DISABLED. */ + unsigned char peer_cid[ MBEDTLS_SSL_CID_OUT_LEN_MAX ]; /*! The peer's CID */ + uint8_t peer_cid_len; /*!< The length of + * \c peer_cid. */ +#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ + uint16_t mtu; /*!< Handshake mtu, used to fragment outgoing messages */ #endif /* MBEDTLS_SSL_PROTO_DTLS */ @@ -452,47 +609,30 @@ struct mbedtls_ssl_handshake_params */ #if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \ defined(MBEDTLS_SSL_PROTO_TLS1_1) - mbedtls_md5_context fin_md5; - mbedtls_sha1_context fin_sha1; + mbedtls_md5_context fin_md5; + mbedtls_sha1_context fin_sha1; #endif #if defined(MBEDTLS_SSL_PROTO_TLS1_2) #if defined(MBEDTLS_SHA256_C) +#if defined(MBEDTLS_USE_PSA_CRYPTO) + psa_hash_operation_t fin_sha256_psa; +#else mbedtls_sha256_context fin_sha256; #endif +#endif #if defined(MBEDTLS_SHA512_C) +#if defined(MBEDTLS_USE_PSA_CRYPTO) + psa_hash_operation_t fin_sha384_psa; +#else mbedtls_sha512_context fin_sha512; #endif +#endif #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */ - void (*update_checksum)(mbedtls_ssl_context *, const unsigned char *, size_t); - void (*calc_verify)(mbedtls_ssl_context *, unsigned char *); - void (*calc_finished)(mbedtls_ssl_context *, unsigned char *, int); - int (*tls_prf)(const unsigned char *, size_t, const char *, - const unsigned char *, size_t, - unsigned char *, size_t); - - size_t pmslen; /*!< premaster length */ - unsigned char randbytes[64]; /*!< random bytes */ unsigned char premaster[MBEDTLS_PREMASTER_SIZE]; /*!< premaster secret */ - int resume; /*!< session resume indicator*/ - int max_major_ver; /*!< max. major version client*/ - int max_minor_ver; /*!< max. minor version client*/ - int cli_exts; /*!< client extension presence*/ - -#if defined(MBEDTLS_SSL_SESSION_TICKETS) - int new_session_ticket; /*!< use NewSessionTicket? */ -#endif /* MBEDTLS_SSL_SESSION_TICKETS */ -#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET) - int extended_ms; /*!< use Extended Master Secret? */ -#endif - -#if defined(MBEDTLS_SSL_ASYNC_PRIVATE) - unsigned int async_in_progress : 1; /*!< an asynchronous operation is in progress */ -#endif /* MBEDTLS_SSL_ASYNC_PRIVATE */ - #if defined(MBEDTLS_SSL_ASYNC_PRIVATE) /** Asynchronous operation context. This field is meant for use by the * asynchronous operation callbacks (mbedtls_ssl_config::f_async_sign_start, @@ -506,25 +646,120 @@ struct mbedtls_ssl_handshake_params typedef struct mbedtls_ssl_hs_buffer mbedtls_ssl_hs_buffer; /* - * This structure contains a full set of runtime transform parameters - * either in negotiation or active. + * Representation of decryption/encryption transformations on records + * + * There are the following general types of record transformations: + * - Stream transformations (TLS versions <= 1.2 only) + * Transformation adding a MAC and applying a stream-cipher + * to the authenticated message. + * - CBC block cipher transformations ([D]TLS versions <= 1.2 only) + * In addition to the distinction of the order of encryption and + * authentication, there's a fundamental difference between the + * handling in SSL3 & TLS 1.0 and TLS 1.1 and TLS 1.2: For SSL3 + * and TLS 1.0, the final IV after processing a record is used + * as the IV for the next record. No explicit IV is contained + * in an encrypted record. The IV for the first record is extracted + * at key extraction time. In contrast, for TLS 1.1 and 1.2, no + * IV is generated at key extraction time, but every encrypted + * record is explicitly prefixed by the IV with which it was encrypted. + * - AEAD transformations ([D]TLS versions >= 1.2 only) + * These come in two fundamentally different versions, the first one + * used in TLS 1.2, excluding ChaChaPoly ciphersuites, and the second + * one used for ChaChaPoly ciphersuites in TLS 1.2 as well as for TLS 1.3. + * In the first transformation, the IV to be used for a record is obtained + * as the concatenation of an explicit, static 4-byte IV and the 8-byte + * record sequence number, and explicitly prepending this sequence number + * to the encrypted record. In contrast, in the second transformation + * the IV is obtained by XOR'ing a static IV obtained at key extraction + * time with the 8-byte record sequence number, without prepending the + * latter to the encrypted record. + * + * Additionally, DTLS 1.2 + CID as well as TLS 1.3 use an inner plaintext + * which allows to add flexible length padding and to hide a record's true + * content type. + * + * In addition to type and version, the following parameters are relevant: + * - The symmetric cipher algorithm to be used. + * - The (static) encryption/decryption keys for the cipher. + * - For stream/CBC, the type of message digest to be used. + * - For stream/CBC, (static) encryption/decryption keys for the digest. + * - For AEAD transformations, the size (potentially 0) of an explicit, + * random initialization vector placed in encrypted records. + * - For some transformations (currently AEAD and CBC in SSL3 and TLS 1.0) + * an implicit IV. It may be static (e.g. AEAD) or dynamic (e.g. CBC) + * and (if present) is combined with the explicit IV in a transformation- + * dependent way (e.g. appending in TLS 1.2 and XOR'ing in TLS 1.3). + * - For stream/CBC, a flag determining the order of encryption and MAC. + * - The details of the transformation depend on the SSL/TLS version. + * - The length of the authentication tag. + * + * Note: Except for CBC in SSL3 and TLS 1.0, these parameters are + * constant across multiple encryption/decryption operations. + * For CBC, the implicit IV needs to be updated after each + * operation. + * + * The struct below refines this abstract view as follows: + * - The cipher underlying the transformation is managed in + * cipher contexts cipher_ctx_{enc/dec}, which must have the + * same cipher type. The mode of these cipher contexts determines + * the type of the transformation in the sense above: e.g., if + * the type is MBEDTLS_CIPHER_AES_256_CBC resp. MBEDTLS_CIPHER_AES_192_GCM + * then the transformation has type CBC resp. AEAD. + * - The cipher keys are never stored explicitly but + * are maintained within cipher_ctx_{enc/dec}. + * - For stream/CBC transformations, the message digest contexts + * used for the MAC's are stored in md_ctx_{enc/dec}. These contexts + * are unused for AEAD transformations. + * - For stream/CBC transformations and versions > SSL3, the + * MAC keys are not stored explicitly but maintained within + * md_ctx_{enc/dec}. + * - For stream/CBC transformations and version SSL3, the MAC + * keys are stored explicitly in mac_enc, mac_dec and have + * a fixed size of 20 bytes. These fields are unused for + * AEAD transformations or transformations >= TLS 1.0. + * - For transformations using an implicit IV maintained within + * the transformation context, its contents are stored within + * iv_{enc/dec}. + * - The value of ivlen indicates the length of the IV. + * This is redundant in case of stream/CBC transformations + * which always use 0 resp. the cipher's block length as the + * IV length, but is needed for AEAD ciphers and may be + * different from the underlying cipher's block length + * in this case. + * - The field fixed_ivlen is nonzero for AEAD transformations only + * and indicates the length of the static part of the IV which is + * constant throughout the communication, and which is stored in + * the first fixed_ivlen bytes of the iv_{enc/dec} arrays. + * Note: For CBC in SSL3 and TLS 1.0, the fields iv_{enc/dec} + * still store IV's for continued use across multiple transformations, + * so it is not true that fixed_ivlen == 0 means that iv_{enc/dec} are + * not being used! + * - minor_ver denotes the SSL/TLS version + * - For stream/CBC transformations, maclen denotes the length of the + * authentication tag, while taglen is unused and 0. + * - For AEAD transformations, taglen denotes the length of the + * authentication tag, while maclen is unused and 0. + * - For CBC transformations, encrypt_then_mac determines the + * order of encryption and authentication. This field is unused + * in other transformations. + * */ struct mbedtls_ssl_transform { /* * Session specific crypto layer */ - const mbedtls_ssl_ciphersuite_t *ciphersuite_info; - /*!< Chosen cipersuite_info */ - unsigned int keylen; /*!< symmetric key length (bytes) */ size_t minlen; /*!< min. ciphertext length */ size_t ivlen; /*!< IV length */ size_t fixed_ivlen; /*!< Fixed part of IV (AEAD) */ - size_t maclen; /*!< MAC length */ + size_t maclen; /*!< MAC(CBC) len */ + size_t taglen; /*!< TAG(AEAD) len */ unsigned char iv_enc[16]; /*!< IV (encryption) */ unsigned char iv_dec[16]; /*!< IV (decryption) */ +#if defined(MBEDTLS_SSL_SOME_MODES_USE_MAC) + #if defined(MBEDTLS_SSL_PROTO_SSL3) /* Needed only for SSL v3.0 secret */ unsigned char mac_enc[20]; /*!< SSL v3.0 secret (enc) */ @@ -534,8 +769,22 @@ struct mbedtls_ssl_transform mbedtls_md_context_t md_ctx_enc; /*!< MAC (encryption) */ mbedtls_md_context_t md_ctx_dec; /*!< MAC (decryption) */ +#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC) + int encrypt_then_mac; /*!< flag for EtM activation */ +#endif + +#endif /* MBEDTLS_SSL_SOME_MODES_USE_MAC */ + mbedtls_cipher_context_t cipher_ctx_enc; /*!< encryption context */ mbedtls_cipher_context_t cipher_ctx_dec; /*!< decryption context */ + int minor_ver; + +#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) + uint8_t in_cid_len; + uint8_t out_cid_len; + unsigned char in_cid [ MBEDTLS_SSL_CID_OUT_LEN_MAX ]; + unsigned char out_cid[ MBEDTLS_SSL_CID_OUT_LEN_MAX ]; +#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ /* * Session specific compression layer @@ -544,8 +793,83 @@ struct mbedtls_ssl_transform z_stream ctx_deflate; /*!< compression context */ z_stream ctx_inflate; /*!< decompression context */ #endif + +#if defined(MBEDTLS_SSL_CONTEXT_SERIALIZATION) + /* We need the Hello random bytes in order to re-derive keys from the + * Master Secret and other session info, see ssl_populate_transform() */ + unsigned char randbytes[64]; /*!< ServerHello.random+ClientHello.random */ +#endif /* MBEDTLS_SSL_CONTEXT_SERIALIZATION */ }; +/* + * Return 1 if the transform uses an AEAD cipher, 0 otherwise. + * Equivalently, return 0 if a separate MAC is used, 1 otherwise. + */ +static inline int mbedtls_ssl_transform_uses_aead( + const mbedtls_ssl_transform *transform ) +{ +#if defined(MBEDTLS_SSL_SOME_MODES_USE_MAC) + return( transform->maclen == 0 && transform->taglen != 0 ); +#else + (void) transform; + return( 1 ); +#endif +} + +/* + * Internal representation of record frames + * + * Instances come in two flavors: + * (1) Encrypted + * These always have data_offset = 0 + * (2) Unencrypted + * These have data_offset set to the amount of + * pre-expansion during record protection. Concretely, + * this is the length of the fixed part of the explicit IV + * used for encryption, or 0 if no explicit IV is used + * (e.g. for CBC in TLS 1.0, or stream ciphers). + * + * The reason for the data_offset in the unencrypted case + * is to allow for in-place conversion of an unencrypted to + * an encrypted record. If the offset wasn't included, the + * encrypted content would need to be shifted afterwards to + * make space for the fixed IV. + * + */ +#if MBEDTLS_SSL_CID_OUT_LEN_MAX > MBEDTLS_SSL_CID_IN_LEN_MAX +#define MBEDTLS_SSL_CID_LEN_MAX MBEDTLS_SSL_CID_OUT_LEN_MAX +#else +#define MBEDTLS_SSL_CID_LEN_MAX MBEDTLS_SSL_CID_IN_LEN_MAX +#endif + +typedef struct +{ + uint8_t ctr[8]; /* In TLS: The implicit record sequence number. + * In DTLS: The 2-byte epoch followed by + * the 6-byte sequence number. + * This is stored as a raw big endian byte array + * as opposed to a uint64_t because we rarely + * need to perform arithmetic on this, but do + * need it as a Byte array for the purpose of + * MAC computations. */ + uint8_t type; /* The record content type. */ + uint8_t ver[2]; /* SSL/TLS version as present on the wire. + * Convert to internal presentation of versions + * using mbedtls_ssl_read_version() and + * mbedtls_ssl_write_version(). + * Keep wire-format for MAC computations. */ + + unsigned char *buf; /* Memory buffer enclosing the record content */ + size_t buf_len; /* Buffer length */ + size_t data_offset; /* Offset of record content */ + size_t data_len; /* Length of record content */ + +#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) + uint8_t cid_len; /* Length of the CID (0 if not present) */ + unsigned char cid[ MBEDTLS_SSL_CID_LEN_MAX ]; /* The CID */ +#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ +} mbedtls_record; + #if defined(MBEDTLS_X509_CRT_PARSE_C) /* * List of certificate + private key pairs @@ -572,7 +896,7 @@ struct mbedtls_ssl_flight_item #endif /* MBEDTLS_SSL_PROTO_DTLS */ #if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \ - defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED) + defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED) /* Find an entry in a signature-hash set matching a given hash algorithm. */ mbedtls_md_type_t mbedtls_ssl_sig_hash_set_find( mbedtls_ssl_sig_hash_set_t *set, @@ -592,7 +916,7 @@ static inline void mbedtls_ssl_sig_hash_set_init( mbedtls_ssl_sig_hash_set_t *se } #endif /* MBEDTLS_SSL_PROTO_TLS1_2) && - MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED */ + MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED */ /** * \brief Free referenced items in an SSL transform context and clear @@ -719,9 +1043,62 @@ int mbedtls_ssl_write_finished( mbedtls_ssl_context *ssl ); void mbedtls_ssl_optimize_checksum( mbedtls_ssl_context *ssl, const mbedtls_ssl_ciphersuite_t *ciphersuite_info ); -#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED) +#if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED) int mbedtls_ssl_psk_derive_premaster( mbedtls_ssl_context *ssl, mbedtls_key_exchange_type_t key_ex ); -#endif + +/** + * Get the first defined PSK by order of precedence: + * 1. handshake PSK set by \c mbedtls_ssl_set_hs_psk() in the PSK callback + * 2. static PSK configured by \c mbedtls_ssl_conf_psk() + * Return a code and update the pair (PSK, PSK length) passed to this function + */ +static inline int mbedtls_ssl_get_psk( const mbedtls_ssl_context *ssl, + const unsigned char **psk, size_t *psk_len ) +{ + if( ssl->handshake->psk != NULL && ssl->handshake->psk_len > 0 ) + { + *psk = ssl->handshake->psk; + *psk_len = ssl->handshake->psk_len; + } + + else if( ssl->conf->psk != NULL && ssl->conf->psk_len > 0 ) + { + *psk = ssl->conf->psk; + *psk_len = ssl->conf->psk_len; + } + + else + { + *psk = NULL; + *psk_len = 0; + return( MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED ); + } + + return( 0 ); +} + +#if defined(MBEDTLS_USE_PSA_CRYPTO) +/** + * Get the first defined opaque PSK by order of precedence: + * 1. handshake PSK set by \c mbedtls_ssl_set_hs_psk_opaque() in the PSK + * callback + * 2. static PSK configured by \c mbedtls_ssl_conf_psk_opaque() + * Return an opaque PSK + */ +static inline psa_key_id_t mbedtls_ssl_get_opaque_psk( + const mbedtls_ssl_context *ssl ) +{ + if( ! mbedtls_svc_key_id_is_null( ssl->handshake->psk_opaque ) ) + return( ssl->handshake->psk_opaque ); + + if( ! mbedtls_svc_key_id_is_null( ssl->conf->psk_opaque ) ) + return( ssl->conf->psk_opaque ); + + return( MBEDTLS_SVC_KEY_ID_INIT ); +} +#endif /* MBEDTLS_USE_PSA_CRYPTO */ + +#endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */ #if defined(MBEDTLS_PK_C) unsigned char mbedtls_ssl_sig_from_pk( mbedtls_pk_context *pk ); @@ -737,11 +1114,28 @@ int mbedtls_ssl_set_calc_verify_md( mbedtls_ssl_context *ssl, int md ); int mbedtls_ssl_check_curve( const mbedtls_ssl_context *ssl, mbedtls_ecp_group_id grp_id ); #endif -#if defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED) +#if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED) int mbedtls_ssl_check_sig_hash( const mbedtls_ssl_context *ssl, mbedtls_md_type_t md ); #endif +#if defined(MBEDTLS_SSL_DTLS_SRTP) +static inline mbedtls_ssl_srtp_profile mbedtls_ssl_check_srtp_profile_value + ( const uint16_t srtp_profile_value ) +{ + switch( srtp_profile_value ) + { + case MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80: + case MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32: + case MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80: + case MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32: + return srtp_profile_value; + default: break; + } + return( MBEDTLS_TLS_SRTP_UNSET ); +} +#endif + #if defined(MBEDTLS_X509_CRT_PARSE_C) static inline mbedtls_pk_context *mbedtls_ssl_own_key( mbedtls_ssl_context *ssl ) { @@ -787,15 +1181,27 @@ void mbedtls_ssl_write_version( int major, int minor, int transport, void mbedtls_ssl_read_version( int *major, int *minor, int transport, const unsigned char ver[2] ); -static inline size_t mbedtls_ssl_hdr_len( const mbedtls_ssl_context *ssl ) +static inline size_t mbedtls_ssl_in_hdr_len( const mbedtls_ssl_context *ssl ) { +#if !defined(MBEDTLS_SSL_PROTO_DTLS) + ((void) ssl); +#endif + #if defined(MBEDTLS_SSL_PROTO_DTLS) if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM ) + { return( 13 ); -#else - ((void) ssl); -#endif - return( 5 ); + } + else +#endif /* MBEDTLS_SSL_PROTO_DTLS */ + { + return( 5 ); + } +} + +static inline size_t mbedtls_ssl_out_hdr_len( const mbedtls_ssl_context *ssl ) +{ + return( (size_t) ( ssl->out_iv - ssl->out_hdr ) ); } static inline size_t mbedtls_ssl_hs_hdr_len( const mbedtls_ssl_context *ssl ) @@ -818,29 +1224,12 @@ int mbedtls_ssl_flight_transmit( mbedtls_ssl_context *ssl ); /* Visible for testing purposes only */ #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY) -int mbedtls_ssl_dtls_replay_check( mbedtls_ssl_context *ssl ); +int mbedtls_ssl_dtls_replay_check( mbedtls_ssl_context const *ssl ); void mbedtls_ssl_dtls_replay_update( mbedtls_ssl_context *ssl ); #endif -/* constant-time buffer comparison */ -static inline int mbedtls_ssl_safer_memcmp( const void *a, const void *b, size_t n ) -{ - size_t i; - volatile const unsigned char *A = (volatile const unsigned char *) a; - volatile const unsigned char *B = (volatile const unsigned char *) b; - volatile unsigned char diff = 0; - - for( i = 0; i < n; i++ ) - { - /* Read volatile data in order before computing diff. - * This avoids IAR compiler warning: - * 'the order of volatile accesses is undefined ..' */ - unsigned char x = A[i], y = B[i]; - diff |= x ^ y; - } - - return( diff ); -} +int mbedtls_ssl_session_copy( mbedtls_ssl_session *dst, + const mbedtls_ssl_session *src ); #if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \ defined(MBEDTLS_SSL_PROTO_TLS1_1) @@ -852,6 +1241,7 @@ int mbedtls_ssl_get_key_exchange_md_ssl_tls( mbedtls_ssl_context *ssl, #if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || \ defined(MBEDTLS_SSL_PROTO_TLS1_2) +/* The hash buffer must have at least MBEDTLS_MD_MAX_SIZE bytes of length. */ int mbedtls_ssl_get_key_exchange_md_tls1_2( mbedtls_ssl_context *ssl, unsigned char *hash, size_t *hashlen, unsigned char *data, size_t data_len, @@ -859,75 +1249,60 @@ int mbedtls_ssl_get_key_exchange_md_tls1_2( mbedtls_ssl_context *ssl, #endif /* MBEDTLS_SSL_PROTO_TLS1 || MBEDTLS_SSL_PROTO_TLS1_1 || \ MBEDTLS_SSL_PROTO_TLS1_2 */ -#if defined(MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC) -/** \brief Compute the HMAC of variable-length data with constant flow. - * - * This function computes the HMAC of the concatenation of \p add_data and \p - * data, and does with a code flow and memory access pattern that does not - * depend on \p data_len_secret, but only on \p min_data_len and \p - * max_data_len. In particular, this function always reads exactly \p - * max_data_len bytes from \p data. - * - * \param ctx The HMAC context. It must have keys configured - * with mbedtls_md_hmac_starts() and use one of the - * following hashes: SHA-384, SHA-256, SHA-1 or MD-5. - * It is reset using mbedtls_md_hmac_reset() after - * the computation is complete to prepare for the - * next computation. - * \param add_data The additional data prepended to \p data. This - * must point to a readable buffer of \p add_data_len - * bytes. - * \param add_data_len The length of \p add_data in bytes. - * \param data The data appended to \p add_data. This must point - * to a readable buffer of \p max_data_len bytes. - * \param data_len_secret The length of the data to process in \p data. - * This must be no less than \p min_data_len and no - * greater than \p max_data_len. - * \param min_data_len The minimal length of \p data in bytes. - * \param max_data_len The maximal length of \p data in bytes. - * \param output The HMAC will be written here. This must point to - * a writable buffer of sufficient size to hold the - * HMAC value. - * - * \retval 0 - * Success. - * \retval MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED - * The hardware accelerator failed. - */ -int mbedtls_ssl_cf_hmac( - mbedtls_md_context_t *ctx, - const unsigned char *add_data, size_t add_data_len, - const unsigned char *data, size_t data_len_secret, - size_t min_data_len, size_t max_data_len, - unsigned char *output ); - -/** \brief Copy data from a secret position with constant flow. - * - * This function copies \p len bytes from \p src_base + \p offset_secret to \p - * dst, with a code flow and memory access pattern that does not depend on \p - * offset_secret, but only on \p offset_min, \p offset_max and \p len. - * - * \param dst The destination buffer. This must point to a writable - * buffer of at least \p len bytes. - * \param src_base The base of the source buffer. This must point to a - * readable buffer of at least \p offset_max + \p len - * bytes. - * \param offset_secret The offset in the source buffer from which to copy. - * This must be no less than \p offset_min and no greater - * than \p offset_max. - * \param offset_min The minimal value of \p offset_secret. - * \param offset_max The maximal value of \p offset_secret. - * \param len The number of bytes to copy. - */ -void mbedtls_ssl_cf_memcpy_offset( unsigned char *dst, - const unsigned char *src_base, - size_t offset_secret, - size_t offset_min, size_t offset_max, - size_t len ); -#endif /* MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC */ - #ifdef __cplusplus } #endif +void mbedtls_ssl_transform_init( mbedtls_ssl_transform *transform ); +int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl, + mbedtls_ssl_transform *transform, + mbedtls_record *rec, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); +int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl, + mbedtls_ssl_transform *transform, + mbedtls_record *rec ); + +/* Length of the "epoch" field in the record header */ +static inline size_t mbedtls_ssl_ep_len( const mbedtls_ssl_context *ssl ) +{ +#if defined(MBEDTLS_SSL_PROTO_DTLS) + if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM ) + return( 2 ); +#else + ((void) ssl); +#endif + return( 0 ); +} + +#if defined(MBEDTLS_SSL_PROTO_DTLS) +int mbedtls_ssl_resend_hello_request( mbedtls_ssl_context *ssl ); +#endif /* MBEDTLS_SSL_PROTO_DTLS */ + +void mbedtls_ssl_set_timer( mbedtls_ssl_context *ssl, uint32_t millisecs ); +int mbedtls_ssl_check_timer( mbedtls_ssl_context *ssl ); + +void mbedtls_ssl_reset_in_out_pointers( mbedtls_ssl_context *ssl ); +void mbedtls_ssl_update_out_pointers( mbedtls_ssl_context *ssl, + mbedtls_ssl_transform *transform ); +void mbedtls_ssl_update_in_pointers( mbedtls_ssl_context *ssl ); + +int mbedtls_ssl_session_reset_int( mbedtls_ssl_context *ssl, int partial ); + +#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY) +void mbedtls_ssl_dtls_replay_reset( mbedtls_ssl_context *ssl ); +#endif + +void mbedtls_ssl_handshake_wrapup_free_hs_transform( mbedtls_ssl_context *ssl ); + +#if defined(MBEDTLS_SSL_RENEGOTIATION) +int mbedtls_ssl_start_renegotiation( mbedtls_ssl_context *ssl ); +#endif /* MBEDTLS_SSL_RENEGOTIATION */ + +#if defined(MBEDTLS_SSL_PROTO_DTLS) +size_t mbedtls_ssl_get_current_mtu( const mbedtls_ssl_context *ssl ); +void mbedtls_ssl_buffering_free( mbedtls_ssl_context *ssl ); +void mbedtls_ssl_flight_free( mbedtls_ssl_flight_item *flight ); +#endif /* MBEDTLS_SSL_PROTO_DTLS */ + #endif /* ssl_internal.h */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ssl_ticket.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ssl_ticket.h index a83f5e66623..a882eed23b9 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ssl_ticket.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/ssl_ticket.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,33 +18,12 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_SSL_TICKET_H #define MBEDTLS_SSL_TICKET_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif @@ -61,11 +34,11 @@ * secrecy, when MBEDTLS_HAVE_TIME is defined. */ -#include "ssl.h" -#include "cipher.h" +#include "mbedtls/ssl.h" +#include "mbedtls/cipher.h" #if defined(MBEDTLS_THREADING_C) -#include "threading.h" +#include "mbedtls/threading.h" #endif #ifdef __cplusplus diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/threading.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/threading.h index 45161ce467c..d147c73f066 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/threading.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/threading.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,33 +18,12 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_THREADING_H #define MBEDTLS_THREADING_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif @@ -63,10 +36,13 @@ extern "C" { /* MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE is deprecated and should not be * used. */ -#define MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE -0x001A /**< The selected feature is not available. */ +/** The selected feature is not available. */ +#define MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE -0x001A -#define MBEDTLS_ERR_THREADING_BAD_INPUT_DATA -0x001C /**< Bad input parameters to function. */ -#define MBEDTLS_ERR_THREADING_MUTEX_ERROR -0x001E /**< Locking / unlocking / free failed with error code. */ +/** Bad input parameters to function. */ +#define MBEDTLS_ERR_THREADING_BAD_INPUT_DATA -0x001C +/** Locking / unlocking / free failed with error code. */ +#define MBEDTLS_ERR_THREADING_MUTEX_ERROR -0x001E #if defined(MBEDTLS_THREADING_PTHREAD) #include diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/timing.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/timing.h index 8611ba9a4e5..b7290cfcabc 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/timing.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/timing.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,33 +18,12 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_TIMING_H #define MBEDTLS_TIMING_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/version.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/version.h index 49cbeb003a8..b1a92b2bcf3 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/version.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/version.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,27 +18,6 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ /* * This set of compile-time defines and run-time variables can be used to @@ -54,7 +27,7 @@ #define MBEDTLS_VERSION_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif @@ -64,17 +37,17 @@ * Major, Minor, Patchlevel */ #define MBEDTLS_VERSION_MAJOR 2 -#define MBEDTLS_VERSION_MINOR 16 -#define MBEDTLS_VERSION_PATCH 11 +#define MBEDTLS_VERSION_MINOR 28 +#define MBEDTLS_VERSION_PATCH 0 /** * The single version number has the following structure: * MMNNPP00 * Major version | Minor version | Patch version */ -#define MBEDTLS_VERSION_NUMBER 0x02100B00 -#define MBEDTLS_VERSION_STRING "2.16.11" -#define MBEDTLS_VERSION_STRING_FULL "mbed TLS 2.16.11" +#define MBEDTLS_VERSION_NUMBER 0x021C0000 +#define MBEDTLS_VERSION_STRING "2.28.0" +#define MBEDTLS_VERSION_STRING_FULL "mbed TLS 2.28.0" #if defined(MBEDTLS_VERSION_C) diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/x509.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/x509.h index 5bb9b00292f..c1775014300 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/x509.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/x509.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,42 +18,21 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_X509_H #define MBEDTLS_X509_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "asn1.h" -#include "pk.h" +#include "mbedtls/asn1.h" +#include "mbedtls/pk.h" #if defined(MBEDTLS_RSA_C) -#include "rsa.h" +#include "mbedtls/rsa.h" #endif /** @@ -83,26 +56,46 @@ * \name X509 Error codes * \{ */ -#define MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE -0x2080 /**< Unavailable feature, e.g. RSA hashing/encryption combination. */ -#define MBEDTLS_ERR_X509_UNKNOWN_OID -0x2100 /**< Requested OID is unknown. */ -#define MBEDTLS_ERR_X509_INVALID_FORMAT -0x2180 /**< The CRT/CRL/CSR format is invalid, e.g. different type expected. */ -#define MBEDTLS_ERR_X509_INVALID_VERSION -0x2200 /**< The CRT/CRL/CSR version element is invalid. */ -#define MBEDTLS_ERR_X509_INVALID_SERIAL -0x2280 /**< The serial tag or value is invalid. */ -#define MBEDTLS_ERR_X509_INVALID_ALG -0x2300 /**< The algorithm tag or value is invalid. */ -#define MBEDTLS_ERR_X509_INVALID_NAME -0x2380 /**< The name tag or value is invalid. */ -#define MBEDTLS_ERR_X509_INVALID_DATE -0x2400 /**< The date tag or value is invalid. */ -#define MBEDTLS_ERR_X509_INVALID_SIGNATURE -0x2480 /**< The signature tag or value invalid. */ -#define MBEDTLS_ERR_X509_INVALID_EXTENSIONS -0x2500 /**< The extension tag or value is invalid. */ -#define MBEDTLS_ERR_X509_UNKNOWN_VERSION -0x2580 /**< CRT/CRL/CSR has an unsupported version number. */ -#define MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG -0x2600 /**< Signature algorithm (oid) is unsupported. */ -#define MBEDTLS_ERR_X509_SIG_MISMATCH -0x2680 /**< Signature algorithms do not match. (see \c ::mbedtls_x509_crt sig_oid) */ -#define MBEDTLS_ERR_X509_CERT_VERIFY_FAILED -0x2700 /**< Certificate verification failed, e.g. CRL, CA or signature check failed. */ -#define MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT -0x2780 /**< Format not recognized as DER or PEM. */ -#define MBEDTLS_ERR_X509_BAD_INPUT_DATA -0x2800 /**< Input invalid. */ -#define MBEDTLS_ERR_X509_ALLOC_FAILED -0x2880 /**< Allocation of memory failed. */ -#define MBEDTLS_ERR_X509_FILE_IO_ERROR -0x2900 /**< Read/write of file failed. */ -#define MBEDTLS_ERR_X509_BUFFER_TOO_SMALL -0x2980 /**< Destination buffer is too small. */ -#define MBEDTLS_ERR_X509_FATAL_ERROR -0x3000 /**< A fatal error occurred, eg the chain is too long or the vrfy callback failed. */ +/** Unavailable feature, e.g. RSA hashing/encryption combination. */ +#define MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE -0x2080 +/** Requested OID is unknown. */ +#define MBEDTLS_ERR_X509_UNKNOWN_OID -0x2100 +/** The CRT/CRL/CSR format is invalid, e.g. different type expected. */ +#define MBEDTLS_ERR_X509_INVALID_FORMAT -0x2180 +/** The CRT/CRL/CSR version element is invalid. */ +#define MBEDTLS_ERR_X509_INVALID_VERSION -0x2200 +/** The serial tag or value is invalid. */ +#define MBEDTLS_ERR_X509_INVALID_SERIAL -0x2280 +/** The algorithm tag or value is invalid. */ +#define MBEDTLS_ERR_X509_INVALID_ALG -0x2300 +/** The name tag or value is invalid. */ +#define MBEDTLS_ERR_X509_INVALID_NAME -0x2380 +/** The date tag or value is invalid. */ +#define MBEDTLS_ERR_X509_INVALID_DATE -0x2400 +/** The signature tag or value invalid. */ +#define MBEDTLS_ERR_X509_INVALID_SIGNATURE -0x2480 +/** The extension tag or value is invalid. */ +#define MBEDTLS_ERR_X509_INVALID_EXTENSIONS -0x2500 +/** CRT/CRL/CSR has an unsupported version number. */ +#define MBEDTLS_ERR_X509_UNKNOWN_VERSION -0x2580 +/** Signature algorithm (oid) is unsupported. */ +#define MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG -0x2600 +/** Signature algorithms do not match. (see \c ::mbedtls_x509_crt sig_oid) */ +#define MBEDTLS_ERR_X509_SIG_MISMATCH -0x2680 +/** Certificate verification failed, e.g. CRL, CA or signature check failed. */ +#define MBEDTLS_ERR_X509_CERT_VERIFY_FAILED -0x2700 +/** Format not recognized as DER or PEM. */ +#define MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT -0x2780 +/** Input invalid. */ +#define MBEDTLS_ERR_X509_BAD_INPUT_DATA -0x2800 +/** Allocation of memory failed. */ +#define MBEDTLS_ERR_X509_ALLOC_FAILED -0x2880 +/** Read/write of file failed. */ +#define MBEDTLS_ERR_X509_FILE_IO_ERROR -0x2900 +/** Destination buffer is too small. */ +#define MBEDTLS_ERR_X509_BUFFER_TOO_SMALL -0x2980 +/** A fatal error occurred, eg the chain is too long or the vrfy callback failed. */ +#define MBEDTLS_ERR_X509_FATAL_ERROR -0x3000 /* \} name */ /** @@ -134,6 +127,28 @@ /* \} name */ /* \} addtogroup x509_module */ +/* + * X.509 v3 Subject Alternative Name types. + * otherName [0] OtherName, + * rfc822Name [1] IA5String, + * dNSName [2] IA5String, + * x400Address [3] ORAddress, + * directoryName [4] Name, + * ediPartyName [5] EDIPartyName, + * uniformResourceIdentifier [6] IA5String, + * iPAddress [7] OCTET STRING, + * registeredID [8] OBJECT IDENTIFIER + */ +#define MBEDTLS_X509_SAN_OTHER_NAME 0 +#define MBEDTLS_X509_SAN_RFC822_NAME 1 +#define MBEDTLS_X509_SAN_DNS_NAME 2 +#define MBEDTLS_X509_SAN_X400_ADDRESS_NAME 3 +#define MBEDTLS_X509_SAN_DIRECTORY_NAME 4 +#define MBEDTLS_X509_SAN_EDI_PARTY_NAME 5 +#define MBEDTLS_X509_SAN_UNIFORM_RESOURCE_IDENTIFIER 6 +#define MBEDTLS_X509_SAN_IP_ADDRESS 7 +#define MBEDTLS_X509_SAN_REGISTERED_ID 8 + /* * X.509 v3 Key Usage Extension flags * Reminder: update x509_info_key_usage() when adding new flags. @@ -167,24 +182,26 @@ * * Comments refer to the status for using certificates. Status can be * different for writing certificates or reading CRLs or CSRs. + * + * Those are defined in oid.h as oid.c needs them in a data structure. Since + * these were previously defined here, let's have aliases for compatibility. */ -#define MBEDTLS_X509_EXT_AUTHORITY_KEY_IDENTIFIER (1 << 0) -#define MBEDTLS_X509_EXT_SUBJECT_KEY_IDENTIFIER (1 << 1) -#define MBEDTLS_X509_EXT_KEY_USAGE (1 << 2) -#define MBEDTLS_X509_EXT_CERTIFICATE_POLICIES (1 << 3) -#define MBEDTLS_X509_EXT_POLICY_MAPPINGS (1 << 4) -#define MBEDTLS_X509_EXT_SUBJECT_ALT_NAME (1 << 5) /* Supported (DNS) */ -#define MBEDTLS_X509_EXT_ISSUER_ALT_NAME (1 << 6) -#define MBEDTLS_X509_EXT_SUBJECT_DIRECTORY_ATTRS (1 << 7) -#define MBEDTLS_X509_EXT_BASIC_CONSTRAINTS (1 << 8) /* Supported */ -#define MBEDTLS_X509_EXT_NAME_CONSTRAINTS (1 << 9) -#define MBEDTLS_X509_EXT_POLICY_CONSTRAINTS (1 << 10) -#define MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE (1 << 11) -#define MBEDTLS_X509_EXT_CRL_DISTRIBUTION_POINTS (1 << 12) -#define MBEDTLS_X509_EXT_INIHIBIT_ANYPOLICY (1 << 13) -#define MBEDTLS_X509_EXT_FRESHEST_CRL (1 << 14) - -#define MBEDTLS_X509_EXT_NS_CERT_TYPE (1 << 16) +#define MBEDTLS_X509_EXT_AUTHORITY_KEY_IDENTIFIER MBEDTLS_OID_X509_EXT_AUTHORITY_KEY_IDENTIFIER +#define MBEDTLS_X509_EXT_SUBJECT_KEY_IDENTIFIER MBEDTLS_OID_X509_EXT_SUBJECT_KEY_IDENTIFIER +#define MBEDTLS_X509_EXT_KEY_USAGE MBEDTLS_OID_X509_EXT_KEY_USAGE +#define MBEDTLS_X509_EXT_CERTIFICATE_POLICIES MBEDTLS_OID_X509_EXT_CERTIFICATE_POLICIES +#define MBEDTLS_X509_EXT_POLICY_MAPPINGS MBEDTLS_OID_X509_EXT_POLICY_MAPPINGS +#define MBEDTLS_X509_EXT_SUBJECT_ALT_NAME MBEDTLS_OID_X509_EXT_SUBJECT_ALT_NAME /* Supported (DNS) */ +#define MBEDTLS_X509_EXT_ISSUER_ALT_NAME MBEDTLS_OID_X509_EXT_ISSUER_ALT_NAME +#define MBEDTLS_X509_EXT_SUBJECT_DIRECTORY_ATTRS MBEDTLS_OID_X509_EXT_SUBJECT_DIRECTORY_ATTRS +#define MBEDTLS_X509_EXT_BASIC_CONSTRAINTS MBEDTLS_OID_X509_EXT_BASIC_CONSTRAINTS /* Supported */ +#define MBEDTLS_X509_EXT_NAME_CONSTRAINTS MBEDTLS_OID_X509_EXT_NAME_CONSTRAINTS +#define MBEDTLS_X509_EXT_POLICY_CONSTRAINTS MBEDTLS_OID_X509_EXT_POLICY_CONSTRAINTS +#define MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE MBEDTLS_OID_X509_EXT_EXTENDED_KEY_USAGE +#define MBEDTLS_X509_EXT_CRL_DISTRIBUTION_POINTS MBEDTLS_OID_X509_EXT_CRL_DISTRIBUTION_POINTS +#define MBEDTLS_X509_EXT_INIHIBIT_ANYPOLICY MBEDTLS_OID_X509_EXT_INIHIBIT_ANYPOLICY +#define MBEDTLS_X509_EXT_FRESHEST_CRL MBEDTLS_OID_X509_EXT_FRESHEST_CRL +#define MBEDTLS_X509_EXT_NS_CERT_TYPE MBEDTLS_OID_X509_EXT_NS_CERT_TYPE /* * Storage format identifiers diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/x509_crl.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/x509_crl.h index 2ade47c89db..7e9e8885f41 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/x509_crl.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/x509_crl.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,38 +18,17 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_X509_CRL_H #define MBEDTLS_X509_CRL_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "x509.h" +#include "mbedtls/x509.h" #ifdef __cplusplus extern "C" { diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/x509_crt.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/x509_crt.h index 30da1909b74..64ccb433ba8 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/x509_crt.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/x509_crt.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,39 +18,19 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_X509_CRT_H #define MBEDTLS_X509_CRT_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "x509.h" -#include "x509_crl.h" +#include "mbedtls/x509.h" +#include "mbedtls/x509_crl.h" +#include "mbedtls/bignum.h" /** * \addtogroup x509_module @@ -77,6 +51,8 @@ extern "C" { */ typedef struct mbedtls_x509_crt { + int own_buffer; /**< Indicates if \c raw is owned + * by the structure or not. */ mbedtls_x509_buf raw; /**< The raw certificate data (DER). */ mbedtls_x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */ @@ -93,12 +69,15 @@ typedef struct mbedtls_x509_crt mbedtls_x509_time valid_from; /**< Start time of certificate validity. */ mbedtls_x509_time valid_to; /**< End time of certificate validity. */ + mbedtls_x509_buf pk_raw; mbedtls_pk_context pk; /**< Container for the public key context. */ mbedtls_x509_buf issuer_id; /**< Optional X.509 v2/v3 issuer unique identifier. */ mbedtls_x509_buf subject_id; /**< Optional X.509 v2/v3 subject unique identifier. */ mbedtls_x509_buf v3_ext; /**< Optional X.509 v3 extensions. */ - mbedtls_x509_sequence subject_alt_names; /**< Optional list of Subject Alternative Names (Only dNSName supported). */ + mbedtls_x509_sequence subject_alt_names; /**< Optional list of raw entries of Subject Alternative Names extension (currently only dNSName and OtherName are listed). */ + + mbedtls_x509_sequence certificate_policies; /**< Optional list of certificate policies (Only anyPolicy is printed and enforced, however the rest of the policies are still listed). */ int ext_types; /**< Bit string containing detected and parsed extensions */ int ca_istrue; /**< Optional Basic Constraint extension value: 1 if this certificate belongs to a CA, 0 otherwise. */ @@ -119,6 +98,53 @@ typedef struct mbedtls_x509_crt } mbedtls_x509_crt; +/** + * From RFC 5280 section 4.2.1.6: + * OtherName ::= SEQUENCE { + * type-id OBJECT IDENTIFIER, + * value [0] EXPLICIT ANY DEFINED BY type-id } + */ +typedef struct mbedtls_x509_san_other_name +{ + /** + * The type_id is an OID as deifned in RFC 5280. + * To check the value of the type id, you should use + * \p MBEDTLS_OID_CMP with a known OID mbedtls_x509_buf. + */ + mbedtls_x509_buf type_id; /**< The type id. */ + union + { + /** + * From RFC 4108 section 5: + * HardwareModuleName ::= SEQUENCE { + * hwType OBJECT IDENTIFIER, + * hwSerialNum OCTET STRING } + */ + struct + { + mbedtls_x509_buf oid; /**< The object identifier. */ + mbedtls_x509_buf val; /**< The named value. */ + } + hardware_module_name; + } + value; +} +mbedtls_x509_san_other_name; + +/** + * A structure for holding the parsed Subject Alternative Name, according to type + */ +typedef struct mbedtls_x509_subject_alternative_name +{ + int type; /**< The SAN type, value of MBEDTLS_X509_SAN_XXX. */ + union { + mbedtls_x509_san_other_name other_name; /**< The otherName supported type. */ + mbedtls_x509_buf unstructured_name; /**< The buffer for the un constructed types. Only dnsName currently supported */ + } + san; /**< A union of the supported SAN types */ +} +mbedtls_x509_subject_alternative_name; + /** * Build flag from an algorithm/curve identifier (pk, md, ecp) * Since 0 is always XXX_NONE, ignore it. @@ -188,6 +214,14 @@ typedef struct { mbedtls_x509_crt_verify_chain_item items[MBEDTLS_X509_MAX_VERIFY_CHAIN_SIZE]; unsigned len; + +#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK) + /* This stores the list of potential trusted signers obtained from + * the CA callback used for the CRT verification, if configured. + * We must track it somewhere because the callback passes its + * ownership to the caller. */ + mbedtls_x509_crt *trust_ca_cb_result; +#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */ } mbedtls_x509_crt_verify_chain; #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) @@ -254,16 +288,142 @@ extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb; /** * \brief Parse a single DER formatted certificate and add it - * to the chained list. - * - * \param chain points to the start of the chain - * \param buf buffer holding the certificate DER data - * \param buflen size of the buffer - * - * \return 0 if successful, or a specific X509 or PEM error code + * to the end of the provided chained list. + * + * \param chain The pointer to the start of the CRT chain to attach to. + * When parsing the first CRT in a chain, this should point + * to an instance of ::mbedtls_x509_crt initialized through + * mbedtls_x509_crt_init(). + * \param buf The buffer holding the DER encoded certificate. + * \param buflen The size in Bytes of \p buf. + * + * \note This function makes an internal copy of the CRT buffer + * \p buf. In particular, \p buf may be destroyed or reused + * after this call returns. To avoid duplicating the CRT + * buffer (at the cost of stricter lifetime constraints), + * use mbedtls_x509_crt_parse_der_nocopy() instead. + * + * \return \c 0 if successful. + * \return A negative error code on failure. + */ +int mbedtls_x509_crt_parse_der( mbedtls_x509_crt *chain, + const unsigned char *buf, + size_t buflen ); + +/** + * \brief The type of certificate extension callbacks. + * + * Callbacks of this type are passed to and used by the + * mbedtls_x509_crt_parse_der_with_ext_cb() routine when + * it encounters either an unsupported extension or a + * "certificate policies" extension containing any + * unsupported certificate policies. + * Future versions of the library may invoke the callback + * in other cases, if and when the need arises. + * + * \param p_ctx An opaque context passed to the callback. + * \param crt The certificate being parsed. + * \param oid The OID of the extension. + * \param critical Whether the extension is critical. + * \param p Pointer to the start of the extension value + * (the content of the OCTET STRING). + * \param end End of extension value. + * + * \note The callback must fail and return a negative error code + * if it can not parse or does not support the extension. + * When the callback fails to parse a critical extension + * mbedtls_x509_crt_parse_der_with_ext_cb() also fails. + * When the callback fails to parse a non critical extension + * mbedtls_x509_crt_parse_der_with_ext_cb() simply skips + * the extension and continues parsing. + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +typedef int (*mbedtls_x509_crt_ext_cb_t)( void *p_ctx, + mbedtls_x509_crt const *crt, + mbedtls_x509_buf const *oid, + int critical, + const unsigned char *p, + const unsigned char *end ); + +/** + * \brief Parse a single DER formatted certificate and add it + * to the end of the provided chained list. + * + * \param chain The pointer to the start of the CRT chain to attach to. + * When parsing the first CRT in a chain, this should point + * to an instance of ::mbedtls_x509_crt initialized through + * mbedtls_x509_crt_init(). + * \param buf The buffer holding the DER encoded certificate. + * \param buflen The size in Bytes of \p buf. + * \param make_copy When not zero this function makes an internal copy of the + * CRT buffer \p buf. In particular, \p buf may be destroyed + * or reused after this call returns. + * When zero this function avoids duplicating the CRT buffer + * by taking temporary ownership thereof until the CRT + * is destroyed (like mbedtls_x509_crt_parse_der_nocopy()) + * \param cb A callback invoked for every unsupported certificate + * extension. + * \param p_ctx An opaque context passed to the callback. + * + * \note This call is functionally equivalent to + * mbedtls_x509_crt_parse_der(), and/or + * mbedtls_x509_crt_parse_der_nocopy() + * but it calls the callback with every unsupported + * certificate extension and additionally the + * "certificate policies" extension if it contains any + * unsupported certificate policies. + * The callback must return a negative error code if it + * does not know how to handle such an extension. + * When the callback fails to parse a critical extension + * mbedtls_x509_crt_parse_der_with_ext_cb() also fails. + * When the callback fails to parse a non critical extension + * mbedtls_x509_crt_parse_der_with_ext_cb() simply skips + * the extension and continues parsing. + * Future versions of the library may invoke the callback + * in other cases, if and when the need arises. + * + * \return \c 0 if successful. + * \return A negative error code on failure. + */ +int mbedtls_x509_crt_parse_der_with_ext_cb( mbedtls_x509_crt *chain, + const unsigned char *buf, + size_t buflen, + int make_copy, + mbedtls_x509_crt_ext_cb_t cb, + void *p_ctx ); + +/** + * \brief Parse a single DER formatted certificate and add it + * to the end of the provided chained list. This is a + * variant of mbedtls_x509_crt_parse_der() which takes + * temporary ownership of the CRT buffer until the CRT + * is destroyed. + * + * \param chain The pointer to the start of the CRT chain to attach to. + * When parsing the first CRT in a chain, this should point + * to an instance of ::mbedtls_x509_crt initialized through + * mbedtls_x509_crt_init(). + * \param buf The address of the readable buffer holding the DER encoded + * certificate to use. On success, this buffer must be + * retained and not be changed for the liftetime of the + * CRT chain \p chain, that is, until \p chain is destroyed + * through a call to mbedtls_x509_crt_free(). + * \param buflen The size in Bytes of \p buf. + * + * \note This call is functionally equivalent to + * mbedtls_x509_crt_parse_der(), but it avoids creating a + * copy of the input buffer at the cost of stronger lifetime + * constraints. This is useful in constrained environments + * where duplication of the CRT cannot be tolerated. + * + * \return \c 0 if successful. + * \return A negative error code on failure. */ -int mbedtls_x509_crt_parse_der( mbedtls_x509_crt *chain, const unsigned char *buf, - size_t buflen ); +int mbedtls_x509_crt_parse_der_nocopy( mbedtls_x509_crt *chain, + const unsigned char *buf, + size_t buflen ); /** * \brief Parse one DER-encoded or one or more concatenated PEM-encoded @@ -327,8 +487,37 @@ int mbedtls_x509_crt_parse_file( mbedtls_x509_crt *chain, const char *path ); * if partly successful or a specific X509 or PEM error code */ int mbedtls_x509_crt_parse_path( mbedtls_x509_crt *chain, const char *path ); -#endif /* MBEDTLS_FS_IO */ +#endif /* MBEDTLS_FS_IO */ +/** + * \brief This function parses an item in the SubjectAlternativeNames + * extension. + * + * \param san_buf The buffer holding the raw data item of the subject + * alternative name. + * \param san The target structure to populate with the parsed presentation + * of the subject alternative name encoded in \p san_raw. + * + * \note Only "dnsName" and "otherName" of type hardware_module_name + * as defined in RFC 4180 is supported. + * + * \note This function should be called on a single raw data of + * subject alternative name. For example, after successful + * certificate parsing, one must iterate on every item in the + * \p crt->subject_alt_names sequence, and pass it to + * this function. + * + * \warning The target structure contains pointers to the raw data of the + * parsed certificate, and its lifetime is restricted by the + * lifetime of the certificate. + * + * \return \c 0 on success + * \return #MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE for an unsupported + * SAN type. + * \return Another negative value for any other failure. + */ +int mbedtls_x509_parse_subject_alt_name( const mbedtls_x509_buf *san_buf, + mbedtls_x509_subject_alternative_name *san ); /** * \brief Returns an informational string about the * certificate. @@ -360,7 +549,7 @@ int mbedtls_x509_crt_verify_info( char *buf, size_t size, const char *prefix, uint32_t flags ); /** - * \brief Verify the certificate signature + * \brief Verify a chain of certificates. * * The verify callback is a user-supplied callback that * can clear / modify / add flags for a certificate. If set, @@ -400,22 +589,30 @@ int mbedtls_x509_crt_verify_info( char *buf, size_t size, const char *prefix, * specific peers you know) - in that case, the self-signed * certificate doesn't need to have the CA bit set. * - * \param crt a certificate (chain) to be verified - * \param trust_ca the list of trusted CAs (see note above) - * \param ca_crl the list of CRLs for trusted CAs (see note above) - * \param cn expected Common Name (can be set to - * NULL if the CN must not be verified) - * \param flags result of the verification - * \param f_vrfy verification function - * \param p_vrfy verification parameter - * - * \return 0 (and flags set to 0) if the chain was verified and valid, - * MBEDTLS_ERR_X509_CERT_VERIFY_FAILED if the chain was verified - * but found to be invalid, in which case *flags will have one - * or more MBEDTLS_X509_BADCERT_XXX or MBEDTLS_X509_BADCRL_XXX - * flags set, or another error (and flags set to 0xffffffff) - * in case of a fatal error encountered during the - * verification process. + * \param crt The certificate chain to be verified. + * \param trust_ca The list of trusted CAs. + * \param ca_crl The list of CRLs for trusted CAs. + * \param cn The expected Common Name. This will be checked to be + * present in the certificate's subjectAltNames extension or, + * if this extension is absent, as a CN component in its + * Subject name. Currently only DNS names are supported. This + * may be \c NULL if the CN need not be verified. + * \param flags The address at which to store the result of the verification. + * If the verification couldn't be completed, the flag value is + * set to (uint32_t) -1. + * \param f_vrfy The verification callback to use. See the documentation + * of mbedtls_x509_crt_verify() for more information. + * \param p_vrfy The context to be passed to \p f_vrfy. + * + * \return \c 0 if the chain is valid with respect to the + * passed CN, CAs, CRLs and security profile. + * \return #MBEDTLS_ERR_X509_CERT_VERIFY_FAILED in case the + * certificate chain verification failed. In this case, + * \c *flags will have one or more + * \c MBEDTLS_X509_BADCERT_XXX or \c MBEDTLS_X509_BADCRL_XXX + * flags set. + * \return Another negative error code in case of a fatal error + * encountered during the verification process. */ int mbedtls_x509_crt_verify( mbedtls_x509_crt *crt, mbedtls_x509_crt *trust_ca, @@ -425,7 +622,8 @@ int mbedtls_x509_crt_verify( mbedtls_x509_crt *crt, void *p_vrfy ); /** - * \brief Verify the certificate signature according to profile + * \brief Verify a chain of certificates with respect to + * a configurable security profile. * * \note Same as \c mbedtls_x509_crt_verify(), but with explicit * security profile. @@ -434,22 +632,28 @@ int mbedtls_x509_crt_verify( mbedtls_x509_crt *crt, * for ECDSA) apply to all certificates: trusted root, * intermediate CAs if any, and end entity certificate. * - * \param crt a certificate (chain) to be verified - * \param trust_ca the list of trusted CAs - * \param ca_crl the list of CRLs for trusted CAs - * \param profile security profile for verification - * \param cn expected Common Name (can be set to - * NULL if the CN must not be verified) - * \param flags result of the verification - * \param f_vrfy verification function - * \param p_vrfy verification parameter - * - * \return 0 if successful or MBEDTLS_ERR_X509_CERT_VERIFY_FAILED - * in which case *flags will have one or more - * MBEDTLS_X509_BADCERT_XXX or MBEDTLS_X509_BADCRL_XXX flags - * set, - * or another error in case of a fatal error encountered - * during the verification process. + * \param crt The certificate chain to be verified. + * \param trust_ca The list of trusted CAs. + * \param ca_crl The list of CRLs for trusted CAs. + * \param profile The security profile to use for the verification. + * \param cn The expected Common Name. This may be \c NULL if the + * CN need not be verified. + * \param flags The address at which to store the result of the verification. + * If the verification couldn't be completed, the flag value is + * set to (uint32_t) -1. + * \param f_vrfy The verification callback to use. See the documentation + * of mbedtls_x509_crt_verify() for more information. + * \param p_vrfy The context to be passed to \p f_vrfy. + * + * \return \c 0 if the chain is valid with respect to the + * passed CN, CAs, CRLs and security profile. + * \return #MBEDTLS_ERR_X509_CERT_VERIFY_FAILED in case the + * certificate chain verification failed. In this case, + * \c *flags will have one or more + * \c MBEDTLS_X509_BADCERT_XXX or \c MBEDTLS_X509_BADCRL_XXX + * flags set. + * \return Another negative error code in case of a fatal error + * encountered during the verification process. */ int mbedtls_x509_crt_verify_with_profile( mbedtls_x509_crt *crt, mbedtls_x509_crt *trust_ca, @@ -466,16 +670,20 @@ int mbedtls_x509_crt_verify_with_profile( mbedtls_x509_crt *crt, * but can return early and restart according to the limit * set with \c mbedtls_ecp_set_max_ops() to reduce blocking. * - * \param crt a certificate (chain) to be verified - * \param trust_ca the list of trusted CAs - * \param ca_crl the list of CRLs for trusted CAs - * \param profile security profile for verification - * \param cn expected Common Name (can be set to - * NULL if the CN must not be verified) - * \param flags result of the verification - * \param f_vrfy verification function - * \param p_vrfy verification parameter - * \param rs_ctx restart context (NULL to disable restart) + * \param crt The certificate chain to be verified. + * \param trust_ca The list of trusted CAs. + * \param ca_crl The list of CRLs for trusted CAs. + * \param profile The security profile to use for the verification. + * \param cn The expected Common Name. This may be \c NULL if the + * CN need not be verified. + * \param flags The address at which to store the result of the verification. + * If the verification couldn't be completed, the flag value is + * set to (uint32_t) -1. + * \param f_vrfy The verification callback to use. See the documentation + * of mbedtls_x509_crt_verify() for more information. + * \param p_vrfy The context to be passed to \p f_vrfy. + * \param rs_ctx The restart context to use. This may be set to \c NULL + * to disable restartable ECC. * * \return See \c mbedtls_crt_verify_with_profile(), or * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of @@ -490,6 +698,73 @@ int mbedtls_x509_crt_verify_restartable( mbedtls_x509_crt *crt, void *p_vrfy, mbedtls_x509_crt_restart_ctx *rs_ctx ); +/** + * \brief The type of trusted certificate callbacks. + * + * Callbacks of this type are passed to and used by the CRT + * verification routine mbedtls_x509_crt_verify_with_ca_cb() + * when looking for trusted signers of a given certificate. + * + * On success, the callback returns a list of trusted + * certificates to be considered as potential signers + * for the input certificate. + * + * \param p_ctx An opaque context passed to the callback. + * \param child The certificate for which to search a potential signer. + * This will point to a readable certificate. + * \param candidate_cas The address at which to store the address of the first + * entry in the generated linked list of candidate signers. + * This will not be \c NULL. + * + * \note The callback must only return a non-zero value on a + * fatal error. If, in contrast, the search for a potential + * signer completes without a single candidate, the + * callback must return \c 0 and set \c *candidate_cas + * to \c NULL. + * + * \return \c 0 on success. In this case, \c *candidate_cas points + * to a heap-allocated linked list of instances of + * ::mbedtls_x509_crt, and ownership of this list is passed + * to the caller. + * \return A negative error code on failure. + */ +typedef int (*mbedtls_x509_crt_ca_cb_t)( void *p_ctx, + mbedtls_x509_crt const *child, + mbedtls_x509_crt **candidate_cas ); + +#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK) +/** + * \brief Version of \c mbedtls_x509_crt_verify_with_profile() which + * uses a callback to acquire the list of trusted CA + * certificates. + * + * \param crt The certificate chain to be verified. + * \param f_ca_cb The callback to be used to query for potential signers + * of a given child certificate. See the documentation of + * ::mbedtls_x509_crt_ca_cb_t for more information. + * \param p_ca_cb The opaque context to be passed to \p f_ca_cb. + * \param profile The security profile for the verification. + * \param cn The expected Common Name. This may be \c NULL if the + * CN need not be verified. + * \param flags The address at which to store the result of the verification. + * If the verification couldn't be completed, the flag value is + * set to (uint32_t) -1. + * \param f_vrfy The verification callback to use. See the documentation + * of mbedtls_x509_crt_verify() for more information. + * \param p_vrfy The context to be passed to \p f_vrfy. + * + * \return See \c mbedtls_crt_verify_with_profile(). + */ +int mbedtls_x509_crt_verify_with_ca_cb( mbedtls_x509_crt *crt, + mbedtls_x509_crt_ca_cb_t f_ca_cb, + void *p_ca_cb, + const mbedtls_x509_crt_profile *profile, + const char *cn, uint32_t *flags, + int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *), + void *p_vrfy ); + +#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */ + #if defined(MBEDTLS_X509_CHECK_KEY_USAGE) /** * \brief Check usage of certificate against keyUsage extension. diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/x509_csr.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/x509_csr.h index 5dfb4213e8d..b1dfc21f1fb 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/x509_csr.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/x509_csr.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,38 +18,17 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_X509_CSR_H #define MBEDTLS_X509_CSR_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif -#include "x509.h" +#include "mbedtls/x509.h" #ifdef __cplusplus extern "C" { diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/xtea.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/xtea.h index cd6d3753d13..4bdc711fda0 100644 --- a/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/xtea.h +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/xtea.h @@ -5,13 +5,7 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - * - * This file is provided under the Apache License 2.0, or the - * GNU General Public License v2.0 or later. - * - * ********** - * Apache License 2.0: + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. @@ -24,33 +18,12 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ********** - * - * ********** - * GNU General Public License v2.0 or later: - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * ********** */ #ifndef MBEDTLS_XTEA_H #define MBEDTLS_XTEA_H #if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" +#include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif @@ -61,10 +34,12 @@ #define MBEDTLS_XTEA_ENCRYPT 1 #define MBEDTLS_XTEA_DECRYPT 0 -#define MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH -0x0028 /**< The data input has an invalid length. */ +/** The data input has an invalid length. */ +#define MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH -0x0028 /* MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED is deprecated and should not be used. */ -#define MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED -0x0029 /**< XTEA hardware accelerator failed. */ +/** XTEA hardware accelerator failed. */ +#define MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED -0x0029 #ifdef __cplusplus extern "C" { diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto.h new file mode 100644 index 00000000000..b0b57c3a6ba --- /dev/null +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto.h @@ -0,0 +1,3956 @@ +/** + * \file psa/crypto.h + * \brief Platform Security Architecture cryptography module + */ +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PSA_CRYPTO_H +#define PSA_CRYPTO_H + +#include "crypto_platform.h" + +#include + +#ifdef __DOXYGEN_ONLY__ +/* This __DOXYGEN_ONLY__ block contains mock definitions for things that + * must be defined in the crypto_platform.h header. These mock definitions + * are present in this file as a convenience to generate pretty-printed + * documentation that includes those definitions. */ + +/** \defgroup platform Implementation-specific definitions + * @{ + */ + +/**@}*/ +#endif /* __DOXYGEN_ONLY__ */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* The file "crypto_types.h" declares types that encode errors, + * algorithms, key types, policies, etc. */ +#include "crypto_types.h" + +/** \defgroup version API version + * @{ + */ + +/** + * The major version of this implementation of the PSA Crypto API + */ +#define PSA_CRYPTO_API_VERSION_MAJOR 1 + +/** + * The minor version of this implementation of the PSA Crypto API + */ +#define PSA_CRYPTO_API_VERSION_MINOR 0 + +/**@}*/ + +/* The file "crypto_values.h" declares macros to build and analyze values + * of integral types defined in "crypto_types.h". */ +#include "crypto_values.h" + +/** \defgroup initialization Library initialization + * @{ + */ + +/** + * \brief Library initialization. + * + * Applications must call this function before calling any other + * function in this module. + * + * Applications may call this function more than once. Once a call + * succeeds, subsequent calls are guaranteed to succeed. + * + * If the application calls other functions before calling psa_crypto_init(), + * the behavior is undefined. Implementations are encouraged to either perform + * the operation as if the library had been initialized or to return + * #PSA_ERROR_BAD_STATE or some other applicable error. In particular, + * implementations should not return a success status if the lack of + * initialization may have security implications, for example due to improper + * seeding of the random number generator. + * + * \retval #PSA_SUCCESS + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_INSUFFICIENT_STORAGE + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_DATA_INVALID + * \retval #PSA_ERROR_DATA_CORRUPT + */ +psa_status_t psa_crypto_init(void); + +/**@}*/ + +/** \addtogroup attributes + * @{ + */ + +/** \def PSA_KEY_ATTRIBUTES_INIT + * + * This macro returns a suitable initializer for a key attribute structure + * of type #psa_key_attributes_t. + */ +#ifdef __DOXYGEN_ONLY__ +/* This is an example definition for documentation purposes. + * Implementations should define a suitable value in `crypto_struct.h`. + */ +#define PSA_KEY_ATTRIBUTES_INIT {0} +#endif + +/** Return an initial value for a key attributes structure. + */ +static psa_key_attributes_t psa_key_attributes_init(void); + +/** Declare a key as persistent and set its key identifier. + * + * If the attribute structure currently declares the key as volatile (which + * is the default content of an attribute structure), this function sets + * the lifetime attribute to #PSA_KEY_LIFETIME_PERSISTENT. + * + * This function does not access storage, it merely stores the given + * value in the structure. + * The persistent key will be written to storage when the attribute + * structure is passed to a key creation function such as + * psa_import_key(), psa_generate_key(), + * psa_key_derivation_output_key() or psa_copy_key(). + * + * This function may be declared as `static` (i.e. without external + * linkage). This function may be provided as a function-like macro, + * but in this case it must evaluate each of its arguments exactly once. + * + * \param[out] attributes The attribute structure to write to. + * \param key The persistent identifier for the key. + */ +static void psa_set_key_id( psa_key_attributes_t *attributes, + mbedtls_svc_key_id_t key ); + +#ifdef MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER +/** Set the owner identifier of a key. + * + * When key identifiers encode key owner identifiers, psa_set_key_id() does + * not allow to define in key attributes the owner of volatile keys as + * psa_set_key_id() enforces the key to be persistent. + * + * This function allows to set in key attributes the owner identifier of a + * key. It is intended to be used for volatile keys. For persistent keys, + * it is recommended to use the PSA Cryptography API psa_set_key_id() to define + * the owner of a key. + * + * \param[out] attributes The attribute structure to write to. + * \param owner The key owner identifier. + */ +static void mbedtls_set_key_owner_id( psa_key_attributes_t *attributes, + mbedtls_key_owner_id_t owner ); +#endif + +/** Set the location of a persistent key. + * + * To make a key persistent, you must give it a persistent key identifier + * with psa_set_key_id(). By default, a key that has a persistent identifier + * is stored in the default storage area identifier by + * #PSA_KEY_LIFETIME_PERSISTENT. Call this function to choose a storage + * area, or to explicitly declare the key as volatile. + * + * This function does not access storage, it merely stores the given + * value in the structure. + * The persistent key will be written to storage when the attribute + * structure is passed to a key creation function such as + * psa_import_key(), psa_generate_key(), + * psa_key_derivation_output_key() or psa_copy_key(). + * + * This function may be declared as `static` (i.e. without external + * linkage). This function may be provided as a function-like macro, + * but in this case it must evaluate each of its arguments exactly once. + * + * \param[out] attributes The attribute structure to write to. + * \param lifetime The lifetime for the key. + * If this is #PSA_KEY_LIFETIME_VOLATILE, the + * key will be volatile, and the key identifier + * attribute is reset to 0. + */ +static void psa_set_key_lifetime(psa_key_attributes_t *attributes, + psa_key_lifetime_t lifetime); + +/** Retrieve the key identifier from key attributes. + * + * This function may be declared as `static` (i.e. without external + * linkage). This function may be provided as a function-like macro, + * but in this case it must evaluate its argument exactly once. + * + * \param[in] attributes The key attribute structure to query. + * + * \return The persistent identifier stored in the attribute structure. + * This value is unspecified if the attribute structure declares + * the key as volatile. + */ +static mbedtls_svc_key_id_t psa_get_key_id( + const psa_key_attributes_t *attributes); + +/** Retrieve the lifetime from key attributes. + * + * This function may be declared as `static` (i.e. without external + * linkage). This function may be provided as a function-like macro, + * but in this case it must evaluate its argument exactly once. + * + * \param[in] attributes The key attribute structure to query. + * + * \return The lifetime value stored in the attribute structure. + */ +static psa_key_lifetime_t psa_get_key_lifetime( + const psa_key_attributes_t *attributes); + +/** Declare usage flags for a key. + * + * Usage flags are part of a key's usage policy. They encode what + * kind of operations are permitted on the key. For more details, + * refer to the documentation of the type #psa_key_usage_t. + * + * This function overwrites any usage flags + * previously set in \p attributes. + * + * This function may be declared as `static` (i.e. without external + * linkage). This function may be provided as a function-like macro, + * but in this case it must evaluate each of its arguments exactly once. + * + * \param[out] attributes The attribute structure to write to. + * \param usage_flags The usage flags to write. + */ +static void psa_set_key_usage_flags(psa_key_attributes_t *attributes, + psa_key_usage_t usage_flags); + +/** Retrieve the usage flags from key attributes. + * + * This function may be declared as `static` (i.e. without external + * linkage). This function may be provided as a function-like macro, + * but in this case it must evaluate its argument exactly once. + * + * \param[in] attributes The key attribute structure to query. + * + * \return The usage flags stored in the attribute structure. + */ +static psa_key_usage_t psa_get_key_usage_flags( + const psa_key_attributes_t *attributes); + +/** Declare the permitted algorithm policy for a key. + * + * The permitted algorithm policy of a key encodes which algorithm or + * algorithms are permitted to be used with this key. The following + * algorithm policies are supported: + * - 0 does not allow any cryptographic operation with the key. The key + * may be used for non-cryptographic actions such as exporting (if + * permitted by the usage flags). + * - An algorithm value permits this particular algorithm. + * - An algorithm wildcard built from #PSA_ALG_ANY_HASH allows the specified + * signature scheme with any hash algorithm. + * - An algorithm built from #PSA_ALG_AT_LEAST_THIS_LENGTH_MAC allows + * any MAC algorithm from the same base class (e.g. CMAC) which + * generates/verifies a MAC length greater than or equal to the length + * encoded in the wildcard algorithm. + * - An algorithm built from #PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG + * allows any AEAD algorithm from the same base class (e.g. CCM) which + * generates/verifies a tag length greater than or equal to the length + * encoded in the wildcard algorithm. + * + * This function overwrites any algorithm policy + * previously set in \p attributes. + * + * This function may be declared as `static` (i.e. without external + * linkage). This function may be provided as a function-like macro, + * but in this case it must evaluate each of its arguments exactly once. + * + * \param[out] attributes The attribute structure to write to. + * \param alg The permitted algorithm policy to write. + */ +static void psa_set_key_algorithm(psa_key_attributes_t *attributes, + psa_algorithm_t alg); + + +/** Retrieve the algorithm policy from key attributes. + * + * This function may be declared as `static` (i.e. without external + * linkage). This function may be provided as a function-like macro, + * but in this case it must evaluate its argument exactly once. + * + * \param[in] attributes The key attribute structure to query. + * + * \return The algorithm stored in the attribute structure. + */ +static psa_algorithm_t psa_get_key_algorithm( + const psa_key_attributes_t *attributes); + +/** Declare the type of a key. + * + * This function overwrites any key type + * previously set in \p attributes. + * + * This function may be declared as `static` (i.e. without external + * linkage). This function may be provided as a function-like macro, + * but in this case it must evaluate each of its arguments exactly once. + * + * \param[out] attributes The attribute structure to write to. + * \param type The key type to write. + * If this is 0, the key type in \p attributes + * becomes unspecified. + */ +static void psa_set_key_type(psa_key_attributes_t *attributes, + psa_key_type_t type); + + +/** Declare the size of a key. + * + * This function overwrites any key size previously set in \p attributes. + * + * This function may be declared as `static` (i.e. without external + * linkage). This function may be provided as a function-like macro, + * but in this case it must evaluate each of its arguments exactly once. + * + * \param[out] attributes The attribute structure to write to. + * \param bits The key size in bits. + * If this is 0, the key size in \p attributes + * becomes unspecified. Keys of size 0 are + * not supported. + */ +static void psa_set_key_bits(psa_key_attributes_t *attributes, + size_t bits); + +/** Retrieve the key type from key attributes. + * + * This function may be declared as `static` (i.e. without external + * linkage). This function may be provided as a function-like macro, + * but in this case it must evaluate its argument exactly once. + * + * \param[in] attributes The key attribute structure to query. + * + * \return The key type stored in the attribute structure. + */ +static psa_key_type_t psa_get_key_type(const psa_key_attributes_t *attributes); + +/** Retrieve the key size from key attributes. + * + * This function may be declared as `static` (i.e. without external + * linkage). This function may be provided as a function-like macro, + * but in this case it must evaluate its argument exactly once. + * + * \param[in] attributes The key attribute structure to query. + * + * \return The key size stored in the attribute structure, in bits. + */ +static size_t psa_get_key_bits(const psa_key_attributes_t *attributes); + +/** Retrieve the attributes of a key. + * + * This function first resets the attribute structure as with + * psa_reset_key_attributes(). It then copies the attributes of + * the given key into the given attribute structure. + * + * \note This function may allocate memory or other resources. + * Once you have called this function on an attribute structure, + * you must call psa_reset_key_attributes() to free these resources. + * + * \param[in] key Identifier of the key to query. + * \param[in,out] attributes On success, the attributes of the key. + * On failure, equivalent to a + * freshly-initialized structure. + * + * \retval #PSA_SUCCESS + * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_DATA_CORRUPT + * \retval #PSA_ERROR_DATA_INVALID + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_get_key_attributes(mbedtls_svc_key_id_t key, + psa_key_attributes_t *attributes); + +/** Reset a key attribute structure to a freshly initialized state. + * + * You must initialize the attribute structure as described in the + * documentation of the type #psa_key_attributes_t before calling this + * function. Once the structure has been initialized, you may call this + * function at any time. + * + * This function frees any auxiliary resources that the structure + * may contain. + * + * \param[in,out] attributes The attribute structure to reset. + */ +void psa_reset_key_attributes(psa_key_attributes_t *attributes); + +/**@}*/ + +/** \defgroup key_management Key management + * @{ + */ + +/** Remove non-essential copies of key material from memory. + * + * If the key identifier designates a volatile key, this functions does not do + * anything and returns successfully. + * + * If the key identifier designates a persistent key, then this function will + * free all resources associated with the key in volatile memory. The key + * data in persistent storage is not affected and the key can still be used. + * + * \param key Identifier of the key to purge. + * + * \retval #PSA_SUCCESS + * The key material will have been removed from memory if it is not + * currently required. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \p key is not a valid key identifier. + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_purge_key(mbedtls_svc_key_id_t key); + +/** Make a copy of a key. + * + * Copy key material from one location to another. + * + * This function is primarily useful to copy a key from one location + * to another, since it populates a key using the material from + * another key which may have a different lifetime. + * + * This function may be used to share a key with a different party, + * subject to implementation-defined restrictions on key sharing. + * + * The policy on the source key must have the usage flag + * #PSA_KEY_USAGE_COPY set. + * This flag is sufficient to permit the copy if the key has the lifetime + * #PSA_KEY_LIFETIME_VOLATILE or #PSA_KEY_LIFETIME_PERSISTENT. + * Some secure elements do not provide a way to copy a key without + * making it extractable from the secure element. If a key is located + * in such a secure element, then the key must have both usage flags + * #PSA_KEY_USAGE_COPY and #PSA_KEY_USAGE_EXPORT in order to make + * a copy of the key outside the secure element. + * + * The resulting key may only be used in a way that conforms to + * both the policy of the original key and the policy specified in + * the \p attributes parameter: + * - The usage flags on the resulting key are the bitwise-and of the + * usage flags on the source policy and the usage flags in \p attributes. + * - If both allow the same algorithm or wildcard-based + * algorithm policy, the resulting key has the same algorithm policy. + * - If either of the policies allows an algorithm and the other policy + * allows a wildcard-based algorithm policy that includes this algorithm, + * the resulting key allows the same algorithm. + * - If the policies do not allow any algorithm in common, this function + * fails with the status #PSA_ERROR_INVALID_ARGUMENT. + * + * The effect of this function on implementation-defined attributes is + * implementation-defined. + * + * \param source_key The key to copy. It must allow the usage + * #PSA_KEY_USAGE_COPY. If a private or secret key is + * being copied outside of a secure element it must + * also allow #PSA_KEY_USAGE_EXPORT. + * \param[in] attributes The attributes for the new key. + * They are used as follows: + * - The key type and size may be 0. If either is + * nonzero, it must match the corresponding + * attribute of the source key. + * - The key location (the lifetime and, for + * persistent keys, the key identifier) is + * used directly. + * - The policy constraints (usage flags and + * algorithm policy) are combined from + * the source key and \p attributes so that + * both sets of restrictions apply, as + * described in the documentation of this function. + * \param[out] target_key On success, an identifier for the newly created + * key. For persistent keys, this is the key + * identifier defined in \p attributes. + * \c 0 on failure. + * + * \retval #PSA_SUCCESS + * \retval #PSA_ERROR_INVALID_HANDLE + * \p source_key is invalid. + * \retval #PSA_ERROR_ALREADY_EXISTS + * This is an attempt to create a persistent key, and there is + * already a persistent key with the given identifier. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * The lifetime or identifier in \p attributes are invalid. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * The policy constraints on the source and specified in + * \p attributes are incompatible. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \p attributes specifies a key type or key size + * which does not match the attributes of the source key. + * \retval #PSA_ERROR_NOT_PERMITTED + * The source key does not have the #PSA_KEY_USAGE_COPY usage flag. + * \retval #PSA_ERROR_NOT_PERMITTED + * The source key is not exportable and its lifetime does not + * allow copying it to the target's lifetime. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_INSUFFICIENT_STORAGE + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_DATA_INVALID + * \retval #PSA_ERROR_DATA_CORRUPT + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_copy_key(mbedtls_svc_key_id_t source_key, + const psa_key_attributes_t *attributes, + mbedtls_svc_key_id_t *target_key); + + +/** + * \brief Destroy a key. + * + * This function destroys a key from both volatile + * memory and, if applicable, non-volatile storage. Implementations shall + * make a best effort to ensure that that the key material cannot be recovered. + * + * This function also erases any metadata such as policies and frees + * resources associated with the key. + * + * If a key is currently in use in a multipart operation, then destroying the + * key will cause the multipart operation to fail. + * + * \param key Identifier of the key to erase. If this is \c 0, do nothing and + * return #PSA_SUCCESS. + * + * \retval #PSA_SUCCESS + * \p key was a valid identifier and the key material that it + * referred to has been erased. Alternatively, \p key is \c 0. + * \retval #PSA_ERROR_NOT_PERMITTED + * The key cannot be erased because it is + * read-only, either due to a policy or due to physical restrictions. + * \retval #PSA_ERROR_INVALID_HANDLE + * \p key is not a valid identifier nor \c 0. + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * There was an failure in communication with the cryptoprocessor. + * The key material may still be present in the cryptoprocessor. + * \retval #PSA_ERROR_DATA_INVALID + * This error is typically a result of either storage corruption on a + * cleartext storage backend, or an attempt to read data that was + * written by an incompatible version of the library. + * \retval #PSA_ERROR_STORAGE_FAILURE + * The storage is corrupted. Implementations shall make a best effort + * to erase key material even in this stage, however applications + * should be aware that it may be impossible to guarantee that the + * key material is not recoverable in such cases. + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * An unexpected condition which is not a storage corruption or + * a communication failure occurred. The cryptoprocessor may have + * been compromised. + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_destroy_key(mbedtls_svc_key_id_t key); + +/**@}*/ + +/** \defgroup import_export Key import and export + * @{ + */ + +/** + * \brief Import a key in binary format. + * + * This function supports any output from psa_export_key(). Refer to the + * documentation of psa_export_public_key() for the format of public keys + * and to the documentation of psa_export_key() for the format for + * other key types. + * + * The key data determines the key size. The attributes may optionally + * specify a key size; in this case it must match the size determined + * from the key data. A key size of 0 in \p attributes indicates that + * the key size is solely determined by the key data. + * + * Implementations must reject an attempt to import a key of size 0. + * + * This specification supports a single format for each key type. + * Implementations may support other formats as long as the standard + * format is supported. Implementations that support other formats + * should ensure that the formats are clearly unambiguous so as to + * minimize the risk that an invalid input is accidentally interpreted + * according to a different format. + * + * \param[in] attributes The attributes for the new key. + * The key size is always determined from the + * \p data buffer. + * If the key size in \p attributes is nonzero, + * it must be equal to the size from \p data. + * \param[out] key On success, an identifier to the newly created key. + * For persistent keys, this is the key identifier + * defined in \p attributes. + * \c 0 on failure. + * \param[in] data Buffer containing the key data. The content of this + * buffer is interpreted according to the type declared + * in \p attributes. + * All implementations must support at least the format + * described in the documentation + * of psa_export_key() or psa_export_public_key() for + * the chosen type. Implementations may allow other + * formats, but should be conservative: implementations + * should err on the side of rejecting content if it + * may be erroneous (e.g. wrong type or truncated data). + * \param data_length Size of the \p data buffer in bytes. + * + * \retval #PSA_SUCCESS + * Success. + * If the key is persistent, the key material and the key's metadata + * have been saved to persistent storage. + * \retval #PSA_ERROR_ALREADY_EXISTS + * This is an attempt to create a persistent key, and there is + * already a persistent key with the given identifier. + * \retval #PSA_ERROR_NOT_SUPPORTED + * The key type or key size is not supported, either by the + * implementation in general or in this particular persistent location. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * The key attributes, as a whole, are invalid. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * The key data is not correctly formatted. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * The size in \p attributes is nonzero and does not match the size + * of the key data. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_INSUFFICIENT_STORAGE + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_DATA_CORRUPT + * \retval #PSA_ERROR_DATA_INVALID + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_import_key(const psa_key_attributes_t *attributes, + const uint8_t *data, + size_t data_length, + mbedtls_svc_key_id_t *key); + + + +/** + * \brief Export a key in binary format. + * + * The output of this function can be passed to psa_import_key() to + * create an equivalent object. + * + * If the implementation of psa_import_key() supports other formats + * beyond the format specified here, the output from psa_export_key() + * must use the representation specified here, not the original + * representation. + * + * For standard key types, the output format is as follows: + * + * - For symmetric keys (including MAC keys), the format is the + * raw bytes of the key. + * - For DES, the key data consists of 8 bytes. The parity bits must be + * correct. + * - For Triple-DES, the format is the concatenation of the + * two or three DES keys. + * - For RSA key pairs (#PSA_KEY_TYPE_RSA_KEY_PAIR), the format + * is the non-encrypted DER encoding of the representation defined by + * PKCS\#1 (RFC 8017) as `RSAPrivateKey`, version 0. + * ``` + * RSAPrivateKey ::= SEQUENCE { + * version INTEGER, -- must be 0 + * modulus INTEGER, -- n + * publicExponent INTEGER, -- e + * privateExponent INTEGER, -- d + * prime1 INTEGER, -- p + * prime2 INTEGER, -- q + * exponent1 INTEGER, -- d mod (p-1) + * exponent2 INTEGER, -- d mod (q-1) + * coefficient INTEGER, -- (inverse of q) mod p + * } + * ``` + * - For elliptic curve key pairs (key types for which + * #PSA_KEY_TYPE_IS_ECC_KEY_PAIR is true), the format is + * a representation of the private value as a `ceiling(m/8)`-byte string + * where `m` is the bit size associated with the curve, i.e. the bit size + * of the order of the curve's coordinate field. This byte string is + * in little-endian order for Montgomery curves (curve types + * `PSA_ECC_FAMILY_CURVEXXX`), and in big-endian order for Weierstrass + * curves (curve types `PSA_ECC_FAMILY_SECTXXX`, `PSA_ECC_FAMILY_SECPXXX` + * and `PSA_ECC_FAMILY_BRAINPOOL_PXXX`). + * For Weierstrass curves, this is the content of the `privateKey` field of + * the `ECPrivateKey` format defined by RFC 5915. For Montgomery curves, + * the format is defined by RFC 7748, and output is masked according to §5. + * For twisted Edwards curves, the private key is as defined by RFC 8032 + * (a 32-byte string for Edwards25519, a 57-byte string for Edwards448). + * - For Diffie-Hellman key exchange key pairs (key types for which + * #PSA_KEY_TYPE_IS_DH_KEY_PAIR is true), the + * format is the representation of the private key `x` as a big-endian byte + * string. The length of the byte string is the private key size in bytes + * (leading zeroes are not stripped). + * - For public keys (key types for which #PSA_KEY_TYPE_IS_PUBLIC_KEY is + * true), the format is the same as for psa_export_public_key(). + * + * The policy on the key must have the usage flag #PSA_KEY_USAGE_EXPORT set. + * + * \param key Identifier of the key to export. It must allow the + * usage #PSA_KEY_USAGE_EXPORT, unless it is a public + * key. + * \param[out] data Buffer where the key data is to be written. + * \param data_size Size of the \p data buffer in bytes. + * \param[out] data_length On success, the number of bytes + * that make up the key data. + * + * \retval #PSA_SUCCESS + * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_NOT_PERMITTED + * The key does not have the #PSA_KEY_USAGE_EXPORT flag. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \retval #PSA_ERROR_BUFFER_TOO_SMALL + * The size of the \p data buffer is too small. You can determine a + * sufficient buffer size by calling + * #PSA_EXPORT_KEY_OUTPUT_SIZE(\c type, \c bits) + * where \c type is the key type + * and \c bits is the key size in bits. + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_export_key(mbedtls_svc_key_id_t key, + uint8_t *data, + size_t data_size, + size_t *data_length); + +/** + * \brief Export a public key or the public part of a key pair in binary format. + * + * The output of this function can be passed to psa_import_key() to + * create an object that is equivalent to the public key. + * + * This specification supports a single format for each key type. + * Implementations may support other formats as long as the standard + * format is supported. Implementations that support other formats + * should ensure that the formats are clearly unambiguous so as to + * minimize the risk that an invalid input is accidentally interpreted + * according to a different format. + * + * For standard key types, the output format is as follows: + * - For RSA public keys (#PSA_KEY_TYPE_RSA_PUBLIC_KEY), the DER encoding of + * the representation defined by RFC 3279 §2.3.1 as `RSAPublicKey`. + * ``` + * RSAPublicKey ::= SEQUENCE { + * modulus INTEGER, -- n + * publicExponent INTEGER } -- e + * ``` + * - For elliptic curve keys on a twisted Edwards curve (key types for which + * #PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY is true and #PSA_KEY_TYPE_ECC_GET_FAMILY + * returns #PSA_ECC_FAMILY_TWISTED_EDWARDS), the public key is as defined + * by RFC 8032 + * (a 32-byte string for Edwards25519, a 57-byte string for Edwards448). + * - For other elliptic curve public keys (key types for which + * #PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY is true), the format is the uncompressed + * representation defined by SEC1 §2.3.3 as the content of an ECPoint. + * Let `m` be the bit size associated with the curve, i.e. the bit size of + * `q` for a curve over `F_q`. The representation consists of: + * - The byte 0x04; + * - `x_P` as a `ceiling(m/8)`-byte string, big-endian; + * - `y_P` as a `ceiling(m/8)`-byte string, big-endian. + * - For Diffie-Hellman key exchange public keys (key types for which + * #PSA_KEY_TYPE_IS_DH_PUBLIC_KEY is true), + * the format is the representation of the public key `y = g^x mod p` as a + * big-endian byte string. The length of the byte string is the length of the + * base prime `p` in bytes. + * + * Exporting a public key object or the public part of a key pair is + * always permitted, regardless of the key's usage flags. + * + * \param key Identifier of the key to export. + * \param[out] data Buffer where the key data is to be written. + * \param data_size Size of the \p data buffer in bytes. + * \param[out] data_length On success, the number of bytes + * that make up the key data. + * + * \retval #PSA_SUCCESS + * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_INVALID_ARGUMENT + * The key is neither a public key nor a key pair. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \retval #PSA_ERROR_BUFFER_TOO_SMALL + * The size of the \p data buffer is too small. You can determine a + * sufficient buffer size by calling + * #PSA_EXPORT_KEY_OUTPUT_SIZE(#PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(\c type), \c bits) + * where \c type is the key type + * and \c bits is the key size in bits. + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_export_public_key(mbedtls_svc_key_id_t key, + uint8_t *data, + size_t data_size, + size_t *data_length); + + + +/**@}*/ + +/** \defgroup hash Message digests + * @{ + */ + +/** Calculate the hash (digest) of a message. + * + * \note To verify the hash of a message against an + * expected value, use psa_hash_compare() instead. + * + * \param alg The hash algorithm to compute (\c PSA_ALG_XXX value + * such that #PSA_ALG_IS_HASH(\p alg) is true). + * \param[in] input Buffer containing the message to hash. + * \param input_length Size of the \p input buffer in bytes. + * \param[out] hash Buffer where the hash is to be written. + * \param hash_size Size of the \p hash buffer in bytes. + * \param[out] hash_length On success, the number of bytes + * that make up the hash value. This is always + * #PSA_HASH_LENGTH(\p alg). + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \p alg is not supported or is not a hash algorithm. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \retval #PSA_ERROR_BUFFER_TOO_SMALL + * \p hash_size is too small + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_hash_compute(psa_algorithm_t alg, + const uint8_t *input, + size_t input_length, + uint8_t *hash, + size_t hash_size, + size_t *hash_length); + +/** Calculate the hash (digest) of a message and compare it with a + * reference value. + * + * \param alg The hash algorithm to compute (\c PSA_ALG_XXX value + * such that #PSA_ALG_IS_HASH(\p alg) is true). + * \param[in] input Buffer containing the message to hash. + * \param input_length Size of the \p input buffer in bytes. + * \param[out] hash Buffer containing the expected hash value. + * \param hash_length Size of the \p hash buffer in bytes. + * + * \retval #PSA_SUCCESS + * The expected hash is identical to the actual hash of the input. + * \retval #PSA_ERROR_INVALID_SIGNATURE + * The hash of the message was calculated successfully, but it + * differs from the expected hash. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \p alg is not supported or is not a hash algorithm. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \p input_length or \p hash_length do not match the hash size for \p alg + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_hash_compare(psa_algorithm_t alg, + const uint8_t *input, + size_t input_length, + const uint8_t *hash, + size_t hash_length); + +/** The type of the state data structure for multipart hash operations. + * + * Before calling any function on a hash operation object, the application must + * initialize it by any of the following means: + * - Set the structure to all-bits-zero, for example: + * \code + * psa_hash_operation_t operation; + * memset(&operation, 0, sizeof(operation)); + * \endcode + * - Initialize the structure to logical zero values, for example: + * \code + * psa_hash_operation_t operation = {0}; + * \endcode + * - Initialize the structure to the initializer #PSA_HASH_OPERATION_INIT, + * for example: + * \code + * psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT; + * \endcode + * - Assign the result of the function psa_hash_operation_init() + * to the structure, for example: + * \code + * psa_hash_operation_t operation; + * operation = psa_hash_operation_init(); + * \endcode + * + * This is an implementation-defined \c struct. Applications should not + * make any assumptions about the content of this structure except + * as directed by the documentation of a specific implementation. */ +typedef struct psa_hash_operation_s psa_hash_operation_t; + +/** \def PSA_HASH_OPERATION_INIT + * + * This macro returns a suitable initializer for a hash operation object + * of type #psa_hash_operation_t. + */ +#ifdef __DOXYGEN_ONLY__ +/* This is an example definition for documentation purposes. + * Implementations should define a suitable value in `crypto_struct.h`. + */ +#define PSA_HASH_OPERATION_INIT {0} +#endif + +/** Return an initial value for a hash operation object. + */ +static psa_hash_operation_t psa_hash_operation_init(void); + +/** Set up a multipart hash operation. + * + * The sequence of operations to calculate a hash (message digest) + * is as follows: + * -# Allocate an operation object which will be passed to all the functions + * listed here. + * -# Initialize the operation object with one of the methods described in the + * documentation for #psa_hash_operation_t, e.g. #PSA_HASH_OPERATION_INIT. + * -# Call psa_hash_setup() to specify the algorithm. + * -# Call psa_hash_update() zero, one or more times, passing a fragment + * of the message each time. The hash that is calculated is the hash + * of the concatenation of these messages in order. + * -# To calculate the hash, call psa_hash_finish(). + * To compare the hash with an expected value, call psa_hash_verify(). + * + * If an error occurs at any step after a call to psa_hash_setup(), the + * operation will need to be reset by a call to psa_hash_abort(). The + * application may call psa_hash_abort() at any time after the operation + * has been initialized. + * + * After a successful call to psa_hash_setup(), the application must + * eventually terminate the operation. The following events terminate an + * operation: + * - A successful call to psa_hash_finish() or psa_hash_verify(). + * - A call to psa_hash_abort(). + * + * \param[in,out] operation The operation object to set up. It must have + * been initialized as per the documentation for + * #psa_hash_operation_t and not yet in use. + * \param alg The hash algorithm to compute (\c PSA_ALG_XXX value + * such that #PSA_ALG_IS_HASH(\p alg) is true). + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \p alg is not a supported hash algorithm. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \p alg is not a hash algorithm. + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be inactive). + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_hash_setup(psa_hash_operation_t *operation, + psa_algorithm_t alg); + +/** Add a message fragment to a multipart hash operation. + * + * The application must call psa_hash_setup() before calling this function. + * + * If this function returns an error status, the operation enters an error + * state and must be aborted by calling psa_hash_abort(). + * + * \param[in,out] operation Active hash operation. + * \param[in] input Buffer containing the message fragment to hash. + * \param input_length Size of the \p input buffer in bytes. + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it muct be active). + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_hash_update(psa_hash_operation_t *operation, + const uint8_t *input, + size_t input_length); + +/** Finish the calculation of the hash of a message. + * + * The application must call psa_hash_setup() before calling this function. + * This function calculates the hash of the message formed by concatenating + * the inputs passed to preceding calls to psa_hash_update(). + * + * When this function returns successfuly, the operation becomes inactive. + * If this function returns an error status, the operation enters an error + * state and must be aborted by calling psa_hash_abort(). + * + * \warning Applications should not call this function if they expect + * a specific value for the hash. Call psa_hash_verify() instead. + * Beware that comparing integrity or authenticity data such as + * hash values with a function such as \c memcmp is risky + * because the time taken by the comparison may leak information + * about the hashed data which could allow an attacker to guess + * a valid hash and thereby bypass security controls. + * + * \param[in,out] operation Active hash operation. + * \param[out] hash Buffer where the hash is to be written. + * \param hash_size Size of the \p hash buffer in bytes. + * \param[out] hash_length On success, the number of bytes + * that make up the hash value. This is always + * #PSA_HASH_LENGTH(\c alg) where \c alg is the + * hash algorithm that is calculated. + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be active). + * \retval #PSA_ERROR_BUFFER_TOO_SMALL + * The size of the \p hash buffer is too small. You can determine a + * sufficient buffer size by calling #PSA_HASH_LENGTH(\c alg) + * where \c alg is the hash algorithm that is calculated. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_hash_finish(psa_hash_operation_t *operation, + uint8_t *hash, + size_t hash_size, + size_t *hash_length); + +/** Finish the calculation of the hash of a message and compare it with + * an expected value. + * + * The application must call psa_hash_setup() before calling this function. + * This function calculates the hash of the message formed by concatenating + * the inputs passed to preceding calls to psa_hash_update(). It then + * compares the calculated hash with the expected hash passed as a + * parameter to this function. + * + * When this function returns successfuly, the operation becomes inactive. + * If this function returns an error status, the operation enters an error + * state and must be aborted by calling psa_hash_abort(). + * + * \note Implementations shall make the best effort to ensure that the + * comparison between the actual hash and the expected hash is performed + * in constant time. + * + * \param[in,out] operation Active hash operation. + * \param[in] hash Buffer containing the expected hash value. + * \param hash_length Size of the \p hash buffer in bytes. + * + * \retval #PSA_SUCCESS + * The expected hash is identical to the actual hash of the message. + * \retval #PSA_ERROR_INVALID_SIGNATURE + * The hash of the message was calculated successfully, but it + * differs from the expected hash. + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be active). + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_hash_verify(psa_hash_operation_t *operation, + const uint8_t *hash, + size_t hash_length); + +/** Abort a hash operation. + * + * Aborting an operation frees all associated resources except for the + * \p operation structure itself. Once aborted, the operation object + * can be reused for another operation by calling + * psa_hash_setup() again. + * + * You may call this function any time after the operation object has + * been initialized by one of the methods described in #psa_hash_operation_t. + * + * In particular, calling psa_hash_abort() after the operation has been + * terminated by a call to psa_hash_abort(), psa_hash_finish() or + * psa_hash_verify() is safe and has no effect. + * + * \param[in,out] operation Initialized hash operation. + * + * \retval #PSA_SUCCESS + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_hash_abort(psa_hash_operation_t *operation); + +/** Clone a hash operation. + * + * This function copies the state of an ongoing hash operation to + * a new operation object. In other words, this function is equivalent + * to calling psa_hash_setup() on \p target_operation with the same + * algorithm that \p source_operation was set up for, then + * psa_hash_update() on \p target_operation with the same input that + * that was passed to \p source_operation. After this function returns, the + * two objects are independent, i.e. subsequent calls involving one of + * the objects do not affect the other object. + * + * \param[in] source_operation The active hash operation to clone. + * \param[in,out] target_operation The operation object to set up. + * It must be initialized but not active. + * + * \retval #PSA_SUCCESS + * \retval #PSA_ERROR_BAD_STATE + * The \p source_operation state is not valid (it must be active). + * \retval #PSA_ERROR_BAD_STATE + * The \p target_operation state is not valid (it must be inactive). + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_hash_clone(const psa_hash_operation_t *source_operation, + psa_hash_operation_t *target_operation); + +/**@}*/ + +/** \defgroup MAC Message authentication codes + * @{ + */ + +/** Calculate the MAC (message authentication code) of a message. + * + * \note To verify the MAC of a message against an + * expected value, use psa_mac_verify() instead. + * Beware that comparing integrity or authenticity data such as + * MAC values with a function such as \c memcmp is risky + * because the time taken by the comparison may leak information + * about the MAC value which could allow an attacker to guess + * a valid MAC and thereby bypass security controls. + * + * \param key Identifier of the key to use for the operation. It + * must allow the usage PSA_KEY_USAGE_SIGN_MESSAGE. + * \param alg The MAC algorithm to compute (\c PSA_ALG_XXX value + * such that #PSA_ALG_IS_MAC(\p alg) is true). + * \param[in] input Buffer containing the input message. + * \param input_length Size of the \p input buffer in bytes. + * \param[out] mac Buffer where the MAC value is to be written. + * \param mac_size Size of the \p mac buffer in bytes. + * \param[out] mac_length On success, the number of bytes + * that make up the MAC value. + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_NOT_PERMITTED + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \p key is not compatible with \p alg. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \p alg is not supported or is not a MAC algorithm. + * \retval #PSA_ERROR_BUFFER_TOO_SMALL + * \p mac_size is too small + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * The key could not be retrieved from storage. + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_mac_compute(mbedtls_svc_key_id_t key, + psa_algorithm_t alg, + const uint8_t *input, + size_t input_length, + uint8_t *mac, + size_t mac_size, + size_t *mac_length); + +/** Calculate the MAC of a message and compare it with a reference value. + * + * \param key Identifier of the key to use for the operation. It + * must allow the usage PSA_KEY_USAGE_VERIFY_MESSAGE. + * \param alg The MAC algorithm to compute (\c PSA_ALG_XXX value + * such that #PSA_ALG_IS_MAC(\p alg) is true). + * \param[in] input Buffer containing the input message. + * \param input_length Size of the \p input buffer in bytes. + * \param[out] mac Buffer containing the expected MAC value. + * \param mac_length Size of the \p mac buffer in bytes. + * + * \retval #PSA_SUCCESS + * The expected MAC is identical to the actual MAC of the input. + * \retval #PSA_ERROR_INVALID_SIGNATURE + * The MAC of the message was calculated successfully, but it + * differs from the expected value. + * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_NOT_PERMITTED + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \p key is not compatible with \p alg. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \p alg is not supported or is not a MAC algorithm. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * The key could not be retrieved from storage. + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_mac_verify(mbedtls_svc_key_id_t key, + psa_algorithm_t alg, + const uint8_t *input, + size_t input_length, + const uint8_t *mac, + size_t mac_length); + +/** The type of the state data structure for multipart MAC operations. + * + * Before calling any function on a MAC operation object, the application must + * initialize it by any of the following means: + * - Set the structure to all-bits-zero, for example: + * \code + * psa_mac_operation_t operation; + * memset(&operation, 0, sizeof(operation)); + * \endcode + * - Initialize the structure to logical zero values, for example: + * \code + * psa_mac_operation_t operation = {0}; + * \endcode + * - Initialize the structure to the initializer #PSA_MAC_OPERATION_INIT, + * for example: + * \code + * psa_mac_operation_t operation = PSA_MAC_OPERATION_INIT; + * \endcode + * - Assign the result of the function psa_mac_operation_init() + * to the structure, for example: + * \code + * psa_mac_operation_t operation; + * operation = psa_mac_operation_init(); + * \endcode + * + * This is an implementation-defined \c struct. Applications should not + * make any assumptions about the content of this structure except + * as directed by the documentation of a specific implementation. */ +typedef struct psa_mac_operation_s psa_mac_operation_t; + +/** \def PSA_MAC_OPERATION_INIT + * + * This macro returns a suitable initializer for a MAC operation object of type + * #psa_mac_operation_t. + */ +#ifdef __DOXYGEN_ONLY__ +/* This is an example definition for documentation purposes. + * Implementations should define a suitable value in `crypto_struct.h`. + */ +#define PSA_MAC_OPERATION_INIT {0} +#endif + +/** Return an initial value for a MAC operation object. + */ +static psa_mac_operation_t psa_mac_operation_init(void); + +/** Set up a multipart MAC calculation operation. + * + * This function sets up the calculation of the MAC + * (message authentication code) of a byte string. + * To verify the MAC of a message against an + * expected value, use psa_mac_verify_setup() instead. + * + * The sequence of operations to calculate a MAC is as follows: + * -# Allocate an operation object which will be passed to all the functions + * listed here. + * -# Initialize the operation object with one of the methods described in the + * documentation for #psa_mac_operation_t, e.g. #PSA_MAC_OPERATION_INIT. + * -# Call psa_mac_sign_setup() to specify the algorithm and key. + * -# Call psa_mac_update() zero, one or more times, passing a fragment + * of the message each time. The MAC that is calculated is the MAC + * of the concatenation of these messages in order. + * -# At the end of the message, call psa_mac_sign_finish() to finish + * calculating the MAC value and retrieve it. + * + * If an error occurs at any step after a call to psa_mac_sign_setup(), the + * operation will need to be reset by a call to psa_mac_abort(). The + * application may call psa_mac_abort() at any time after the operation + * has been initialized. + * + * After a successful call to psa_mac_sign_setup(), the application must + * eventually terminate the operation through one of the following methods: + * - A successful call to psa_mac_sign_finish(). + * - A call to psa_mac_abort(). + * + * \param[in,out] operation The operation object to set up. It must have + * been initialized as per the documentation for + * #psa_mac_operation_t and not yet in use. + * \param key Identifier of the key to use for the operation. It + * must remain valid until the operation terminates. + * It must allow the usage PSA_KEY_USAGE_SIGN_MESSAGE. + * \param alg The MAC algorithm to compute (\c PSA_ALG_XXX value + * such that #PSA_ALG_IS_MAC(\p alg) is true). + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_NOT_PERMITTED + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \p key is not compatible with \p alg. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \p alg is not supported or is not a MAC algorithm. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * The key could not be retrieved from storage. + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be inactive). + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_mac_sign_setup(psa_mac_operation_t *operation, + mbedtls_svc_key_id_t key, + psa_algorithm_t alg); + +/** Set up a multipart MAC verification operation. + * + * This function sets up the verification of the MAC + * (message authentication code) of a byte string against an expected value. + * + * The sequence of operations to verify a MAC is as follows: + * -# Allocate an operation object which will be passed to all the functions + * listed here. + * -# Initialize the operation object with one of the methods described in the + * documentation for #psa_mac_operation_t, e.g. #PSA_MAC_OPERATION_INIT. + * -# Call psa_mac_verify_setup() to specify the algorithm and key. + * -# Call psa_mac_update() zero, one or more times, passing a fragment + * of the message each time. The MAC that is calculated is the MAC + * of the concatenation of these messages in order. + * -# At the end of the message, call psa_mac_verify_finish() to finish + * calculating the actual MAC of the message and verify it against + * the expected value. + * + * If an error occurs at any step after a call to psa_mac_verify_setup(), the + * operation will need to be reset by a call to psa_mac_abort(). The + * application may call psa_mac_abort() at any time after the operation + * has been initialized. + * + * After a successful call to psa_mac_verify_setup(), the application must + * eventually terminate the operation through one of the following methods: + * - A successful call to psa_mac_verify_finish(). + * - A call to psa_mac_abort(). + * + * \param[in,out] operation The operation object to set up. It must have + * been initialized as per the documentation for + * #psa_mac_operation_t and not yet in use. + * \param key Identifier of the key to use for the operation. It + * must remain valid until the operation terminates. + * It must allow the usage + * PSA_KEY_USAGE_VERIFY_MESSAGE. + * \param alg The MAC algorithm to compute (\c PSA_ALG_XXX value + * such that #PSA_ALG_IS_MAC(\p alg) is true). + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_NOT_PERMITTED + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \c key is not compatible with \c alg. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \c alg is not supported or is not a MAC algorithm. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * The key could not be retrieved from storage + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be inactive). + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_mac_verify_setup(psa_mac_operation_t *operation, + mbedtls_svc_key_id_t key, + psa_algorithm_t alg); + +/** Add a message fragment to a multipart MAC operation. + * + * The application must call psa_mac_sign_setup() or psa_mac_verify_setup() + * before calling this function. + * + * If this function returns an error status, the operation enters an error + * state and must be aborted by calling psa_mac_abort(). + * + * \param[in,out] operation Active MAC operation. + * \param[in] input Buffer containing the message fragment to add to + * the MAC calculation. + * \param input_length Size of the \p input buffer in bytes. + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be active). + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_mac_update(psa_mac_operation_t *operation, + const uint8_t *input, + size_t input_length); + +/** Finish the calculation of the MAC of a message. + * + * The application must call psa_mac_sign_setup() before calling this function. + * This function calculates the MAC of the message formed by concatenating + * the inputs passed to preceding calls to psa_mac_update(). + * + * When this function returns successfuly, the operation becomes inactive. + * If this function returns an error status, the operation enters an error + * state and must be aborted by calling psa_mac_abort(). + * + * \warning Applications should not call this function if they expect + * a specific value for the MAC. Call psa_mac_verify_finish() instead. + * Beware that comparing integrity or authenticity data such as + * MAC values with a function such as \c memcmp is risky + * because the time taken by the comparison may leak information + * about the MAC value which could allow an attacker to guess + * a valid MAC and thereby bypass security controls. + * + * \param[in,out] operation Active MAC operation. + * \param[out] mac Buffer where the MAC value is to be written. + * \param mac_size Size of the \p mac buffer in bytes. + * \param[out] mac_length On success, the number of bytes + * that make up the MAC value. This is always + * #PSA_MAC_LENGTH(\c key_type, \c key_bits, \c alg) + * where \c key_type and \c key_bits are the type and + * bit-size respectively of the key and \c alg is the + * MAC algorithm that is calculated. + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be an active mac sign + * operation). + * \retval #PSA_ERROR_BUFFER_TOO_SMALL + * The size of the \p mac buffer is too small. You can determine a + * sufficient buffer size by calling PSA_MAC_LENGTH(). + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_mac_sign_finish(psa_mac_operation_t *operation, + uint8_t *mac, + size_t mac_size, + size_t *mac_length); + +/** Finish the calculation of the MAC of a message and compare it with + * an expected value. + * + * The application must call psa_mac_verify_setup() before calling this function. + * This function calculates the MAC of the message formed by concatenating + * the inputs passed to preceding calls to psa_mac_update(). It then + * compares the calculated MAC with the expected MAC passed as a + * parameter to this function. + * + * When this function returns successfuly, the operation becomes inactive. + * If this function returns an error status, the operation enters an error + * state and must be aborted by calling psa_mac_abort(). + * + * \note Implementations shall make the best effort to ensure that the + * comparison between the actual MAC and the expected MAC is performed + * in constant time. + * + * \param[in,out] operation Active MAC operation. + * \param[in] mac Buffer containing the expected MAC value. + * \param mac_length Size of the \p mac buffer in bytes. + * + * \retval #PSA_SUCCESS + * The expected MAC is identical to the actual MAC of the message. + * \retval #PSA_ERROR_INVALID_SIGNATURE + * The MAC of the message was calculated successfully, but it + * differs from the expected MAC. + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be an active mac verify + * operation). + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_mac_verify_finish(psa_mac_operation_t *operation, + const uint8_t *mac, + size_t mac_length); + +/** Abort a MAC operation. + * + * Aborting an operation frees all associated resources except for the + * \p operation structure itself. Once aborted, the operation object + * can be reused for another operation by calling + * psa_mac_sign_setup() or psa_mac_verify_setup() again. + * + * You may call this function any time after the operation object has + * been initialized by one of the methods described in #psa_mac_operation_t. + * + * In particular, calling psa_mac_abort() after the operation has been + * terminated by a call to psa_mac_abort(), psa_mac_sign_finish() or + * psa_mac_verify_finish() is safe and has no effect. + * + * \param[in,out] operation Initialized MAC operation. + * + * \retval #PSA_SUCCESS + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_mac_abort(psa_mac_operation_t *operation); + +/**@}*/ + +/** \defgroup cipher Symmetric ciphers + * @{ + */ + +/** Encrypt a message using a symmetric cipher. + * + * This function encrypts a message with a random IV (initialization + * vector). Use the multipart operation interface with a + * #psa_cipher_operation_t object to provide other forms of IV. + * + * \param key Identifier of the key to use for the operation. + * It must allow the usage #PSA_KEY_USAGE_ENCRYPT. + * \param alg The cipher algorithm to compute + * (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_CIPHER(\p alg) is true). + * \param[in] input Buffer containing the message to encrypt. + * \param input_length Size of the \p input buffer in bytes. + * \param[out] output Buffer where the output is to be written. + * The output contains the IV followed by + * the ciphertext proper. + * \param output_size Size of the \p output buffer in bytes. + * \param[out] output_length On success, the number of bytes + * that make up the output. + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_NOT_PERMITTED + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \p key is not compatible with \p alg. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \p alg is not supported or is not a cipher algorithm. + * \retval #PSA_ERROR_BUFFER_TOO_SMALL + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_cipher_encrypt(mbedtls_svc_key_id_t key, + psa_algorithm_t alg, + const uint8_t *input, + size_t input_length, + uint8_t *output, + size_t output_size, + size_t *output_length); + +/** Decrypt a message using a symmetric cipher. + * + * This function decrypts a message encrypted with a symmetric cipher. + * + * \param key Identifier of the key to use for the operation. + * It must remain valid until the operation + * terminates. It must allow the usage + * #PSA_KEY_USAGE_DECRYPT. + * \param alg The cipher algorithm to compute + * (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_CIPHER(\p alg) is true). + * \param[in] input Buffer containing the message to decrypt. + * This consists of the IV followed by the + * ciphertext proper. + * \param input_length Size of the \p input buffer in bytes. + * \param[out] output Buffer where the plaintext is to be written. + * \param output_size Size of the \p output buffer in bytes. + * \param[out] output_length On success, the number of bytes + * that make up the output. + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_NOT_PERMITTED + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \p key is not compatible with \p alg. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \p alg is not supported or is not a cipher algorithm. + * \retval #PSA_ERROR_BUFFER_TOO_SMALL + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_cipher_decrypt(mbedtls_svc_key_id_t key, + psa_algorithm_t alg, + const uint8_t *input, + size_t input_length, + uint8_t *output, + size_t output_size, + size_t *output_length); + +/** The type of the state data structure for multipart cipher operations. + * + * Before calling any function on a cipher operation object, the application + * must initialize it by any of the following means: + * - Set the structure to all-bits-zero, for example: + * \code + * psa_cipher_operation_t operation; + * memset(&operation, 0, sizeof(operation)); + * \endcode + * - Initialize the structure to logical zero values, for example: + * \code + * psa_cipher_operation_t operation = {0}; + * \endcode + * - Initialize the structure to the initializer #PSA_CIPHER_OPERATION_INIT, + * for example: + * \code + * psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT; + * \endcode + * - Assign the result of the function psa_cipher_operation_init() + * to the structure, for example: + * \code + * psa_cipher_operation_t operation; + * operation = psa_cipher_operation_init(); + * \endcode + * + * This is an implementation-defined \c struct. Applications should not + * make any assumptions about the content of this structure except + * as directed by the documentation of a specific implementation. */ +typedef struct psa_cipher_operation_s psa_cipher_operation_t; + +/** \def PSA_CIPHER_OPERATION_INIT + * + * This macro returns a suitable initializer for a cipher operation object of + * type #psa_cipher_operation_t. + */ +#ifdef __DOXYGEN_ONLY__ +/* This is an example definition for documentation purposes. + * Implementations should define a suitable value in `crypto_struct.h`. + */ +#define PSA_CIPHER_OPERATION_INIT {0} +#endif + +/** Return an initial value for a cipher operation object. + */ +static psa_cipher_operation_t psa_cipher_operation_init(void); + +/** Set the key for a multipart symmetric encryption operation. + * + * The sequence of operations to encrypt a message with a symmetric cipher + * is as follows: + * -# Allocate an operation object which will be passed to all the functions + * listed here. + * -# Initialize the operation object with one of the methods described in the + * documentation for #psa_cipher_operation_t, e.g. + * #PSA_CIPHER_OPERATION_INIT. + * -# Call psa_cipher_encrypt_setup() to specify the algorithm and key. + * -# Call either psa_cipher_generate_iv() or psa_cipher_set_iv() to + * generate or set the IV (initialization vector). You should use + * psa_cipher_generate_iv() unless the protocol you are implementing + * requires a specific IV value. + * -# Call psa_cipher_update() zero, one or more times, passing a fragment + * of the message each time. + * -# Call psa_cipher_finish(). + * + * If an error occurs at any step after a call to psa_cipher_encrypt_setup(), + * the operation will need to be reset by a call to psa_cipher_abort(). The + * application may call psa_cipher_abort() at any time after the operation + * has been initialized. + * + * After a successful call to psa_cipher_encrypt_setup(), the application must + * eventually terminate the operation. The following events terminate an + * operation: + * - A successful call to psa_cipher_finish(). + * - A call to psa_cipher_abort(). + * + * \param[in,out] operation The operation object to set up. It must have + * been initialized as per the documentation for + * #psa_cipher_operation_t and not yet in use. + * \param key Identifier of the key to use for the operation. + * It must remain valid until the operation + * terminates. It must allow the usage + * #PSA_KEY_USAGE_ENCRYPT. + * \param alg The cipher algorithm to compute + * (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_CIPHER(\p alg) is true). + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_NOT_PERMITTED + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \p key is not compatible with \p alg. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \p alg is not supported or is not a cipher algorithm. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be inactive). + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_cipher_encrypt_setup(psa_cipher_operation_t *operation, + mbedtls_svc_key_id_t key, + psa_algorithm_t alg); + +/** Set the key for a multipart symmetric decryption operation. + * + * The sequence of operations to decrypt a message with a symmetric cipher + * is as follows: + * -# Allocate an operation object which will be passed to all the functions + * listed here. + * -# Initialize the operation object with one of the methods described in the + * documentation for #psa_cipher_operation_t, e.g. + * #PSA_CIPHER_OPERATION_INIT. + * -# Call psa_cipher_decrypt_setup() to specify the algorithm and key. + * -# Call psa_cipher_set_iv() with the IV (initialization vector) for the + * decryption. If the IV is prepended to the ciphertext, you can call + * psa_cipher_update() on a buffer containing the IV followed by the + * beginning of the message. + * -# Call psa_cipher_update() zero, one or more times, passing a fragment + * of the message each time. + * -# Call psa_cipher_finish(). + * + * If an error occurs at any step after a call to psa_cipher_decrypt_setup(), + * the operation will need to be reset by a call to psa_cipher_abort(). The + * application may call psa_cipher_abort() at any time after the operation + * has been initialized. + * + * After a successful call to psa_cipher_decrypt_setup(), the application must + * eventually terminate the operation. The following events terminate an + * operation: + * - A successful call to psa_cipher_finish(). + * - A call to psa_cipher_abort(). + * + * \param[in,out] operation The operation object to set up. It must have + * been initialized as per the documentation for + * #psa_cipher_operation_t and not yet in use. + * \param key Identifier of the key to use for the operation. + * It must remain valid until the operation + * terminates. It must allow the usage + * #PSA_KEY_USAGE_DECRYPT. + * \param alg The cipher algorithm to compute + * (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_CIPHER(\p alg) is true). + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_NOT_PERMITTED + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \p key is not compatible with \p alg. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \p alg is not supported or is not a cipher algorithm. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be inactive). + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_cipher_decrypt_setup(psa_cipher_operation_t *operation, + mbedtls_svc_key_id_t key, + psa_algorithm_t alg); + +/** Generate an IV for a symmetric encryption operation. + * + * This function generates a random IV (initialization vector), nonce + * or initial counter value for the encryption operation as appropriate + * for the chosen algorithm, key type and key size. + * + * The application must call psa_cipher_encrypt_setup() before + * calling this function. + * + * If this function returns an error status, the operation enters an error + * state and must be aborted by calling psa_cipher_abort(). + * + * \param[in,out] operation Active cipher operation. + * \param[out] iv Buffer where the generated IV is to be written. + * \param iv_size Size of the \p iv buffer in bytes. + * \param[out] iv_length On success, the number of bytes of the + * generated IV. + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be active, with no IV set). + * \retval #PSA_ERROR_BUFFER_TOO_SMALL + * The size of the \p iv buffer is too small. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_cipher_generate_iv(psa_cipher_operation_t *operation, + uint8_t *iv, + size_t iv_size, + size_t *iv_length); + +/** Set the IV for a symmetric encryption or decryption operation. + * + * This function sets the IV (initialization vector), nonce + * or initial counter value for the encryption or decryption operation. + * + * The application must call psa_cipher_encrypt_setup() before + * calling this function. + * + * If this function returns an error status, the operation enters an error + * state and must be aborted by calling psa_cipher_abort(). + * + * \note When encrypting, applications should use psa_cipher_generate_iv() + * instead of this function, unless implementing a protocol that requires + * a non-random IV. + * + * \param[in,out] operation Active cipher operation. + * \param[in] iv Buffer containing the IV to use. + * \param iv_length Size of the IV in bytes. + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be an active cipher + * encrypt operation, with no IV set). + * \retval #PSA_ERROR_INVALID_ARGUMENT + * The size of \p iv is not acceptable for the chosen algorithm, + * or the chosen algorithm does not use an IV. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_cipher_set_iv(psa_cipher_operation_t *operation, + const uint8_t *iv, + size_t iv_length); + +/** Encrypt or decrypt a message fragment in an active cipher operation. + * + * Before calling this function, you must: + * 1. Call either psa_cipher_encrypt_setup() or psa_cipher_decrypt_setup(). + * The choice of setup function determines whether this function + * encrypts or decrypts its input. + * 2. If the algorithm requires an IV, call psa_cipher_generate_iv() + * (recommended when encrypting) or psa_cipher_set_iv(). + * + * If this function returns an error status, the operation enters an error + * state and must be aborted by calling psa_cipher_abort(). + * + * \param[in,out] operation Active cipher operation. + * \param[in] input Buffer containing the message fragment to + * encrypt or decrypt. + * \param input_length Size of the \p input buffer in bytes. + * \param[out] output Buffer where the output is to be written. + * \param output_size Size of the \p output buffer in bytes. + * \param[out] output_length On success, the number of bytes + * that make up the returned output. + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be active, with an IV set + * if required for the algorithm). + * \retval #PSA_ERROR_BUFFER_TOO_SMALL + * The size of the \p output buffer is too small. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_cipher_update(psa_cipher_operation_t *operation, + const uint8_t *input, + size_t input_length, + uint8_t *output, + size_t output_size, + size_t *output_length); + +/** Finish encrypting or decrypting a message in a cipher operation. + * + * The application must call psa_cipher_encrypt_setup() or + * psa_cipher_decrypt_setup() before calling this function. The choice + * of setup function determines whether this function encrypts or + * decrypts its input. + * + * This function finishes the encryption or decryption of the message + * formed by concatenating the inputs passed to preceding calls to + * psa_cipher_update(). + * + * When this function returns successfuly, the operation becomes inactive. + * If this function returns an error status, the operation enters an error + * state and must be aborted by calling psa_cipher_abort(). + * + * \param[in,out] operation Active cipher operation. + * \param[out] output Buffer where the output is to be written. + * \param output_size Size of the \p output buffer in bytes. + * \param[out] output_length On success, the number of bytes + * that make up the returned output. + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * The total input size passed to this operation is not valid for + * this particular algorithm. For example, the algorithm is a based + * on block cipher and requires a whole number of blocks, but the + * total input size is not a multiple of the block size. + * \retval #PSA_ERROR_INVALID_PADDING + * This is a decryption operation for an algorithm that includes + * padding, and the ciphertext does not contain valid padding. + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be active, with an IV set + * if required for the algorithm). + * \retval #PSA_ERROR_BUFFER_TOO_SMALL + * The size of the \p output buffer is too small. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_cipher_finish(psa_cipher_operation_t *operation, + uint8_t *output, + size_t output_size, + size_t *output_length); + +/** Abort a cipher operation. + * + * Aborting an operation frees all associated resources except for the + * \p operation structure itself. Once aborted, the operation object + * can be reused for another operation by calling + * psa_cipher_encrypt_setup() or psa_cipher_decrypt_setup() again. + * + * You may call this function any time after the operation object has + * been initialized as described in #psa_cipher_operation_t. + * + * In particular, calling psa_cipher_abort() after the operation has been + * terminated by a call to psa_cipher_abort() or psa_cipher_finish() + * is safe and has no effect. + * + * \param[in,out] operation Initialized cipher operation. + * + * \retval #PSA_SUCCESS + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_cipher_abort(psa_cipher_operation_t *operation); + +/**@}*/ + +/** \defgroup aead Authenticated encryption with associated data (AEAD) + * @{ + */ + +/** Process an authenticated encryption operation. + * + * \param key Identifier of the key to use for the + * operation. It must allow the usage + * #PSA_KEY_USAGE_ENCRYPT. + * \param alg The AEAD algorithm to compute + * (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_AEAD(\p alg) is true). + * \param[in] nonce Nonce or IV to use. + * \param nonce_length Size of the \p nonce buffer in bytes. + * \param[in] additional_data Additional data that will be authenticated + * but not encrypted. + * \param additional_data_length Size of \p additional_data in bytes. + * \param[in] plaintext Data that will be authenticated and + * encrypted. + * \param plaintext_length Size of \p plaintext in bytes. + * \param[out] ciphertext Output buffer for the authenticated and + * encrypted data. The additional data is not + * part of this output. For algorithms where the + * encrypted data and the authentication tag + * are defined as separate outputs, the + * authentication tag is appended to the + * encrypted data. + * \param ciphertext_size Size of the \p ciphertext buffer in bytes. + * This must be appropriate for the selected + * algorithm and key: + * - A sufficient output size is + * #PSA_AEAD_ENCRYPT_OUTPUT_SIZE(\c key_type, + * \p alg, \p plaintext_length) where + * \c key_type is the type of \p key. + * - #PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(\p + * plaintext_length) evaluates to the maximum + * ciphertext size of any supported AEAD + * encryption. + * \param[out] ciphertext_length On success, the size of the output + * in the \p ciphertext buffer. + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_NOT_PERMITTED + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \p key is not compatible with \p alg. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \p alg is not supported or is not an AEAD algorithm. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_BUFFER_TOO_SMALL + * \p ciphertext_size is too small. + * #PSA_AEAD_ENCRYPT_OUTPUT_SIZE(\c key_type, \p alg, + * \p plaintext_length) or + * #PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(\p plaintext_length) can be used to + * determine the required buffer size. + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_aead_encrypt(mbedtls_svc_key_id_t key, + psa_algorithm_t alg, + const uint8_t *nonce, + size_t nonce_length, + const uint8_t *additional_data, + size_t additional_data_length, + const uint8_t *plaintext, + size_t plaintext_length, + uint8_t *ciphertext, + size_t ciphertext_size, + size_t *ciphertext_length); + +/** Process an authenticated decryption operation. + * + * \param key Identifier of the key to use for the + * operation. It must allow the usage + * #PSA_KEY_USAGE_DECRYPT. + * \param alg The AEAD algorithm to compute + * (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_AEAD(\p alg) is true). + * \param[in] nonce Nonce or IV to use. + * \param nonce_length Size of the \p nonce buffer in bytes. + * \param[in] additional_data Additional data that has been authenticated + * but not encrypted. + * \param additional_data_length Size of \p additional_data in bytes. + * \param[in] ciphertext Data that has been authenticated and + * encrypted. For algorithms where the + * encrypted data and the authentication tag + * are defined as separate inputs, the buffer + * must contain the encrypted data followed + * by the authentication tag. + * \param ciphertext_length Size of \p ciphertext in bytes. + * \param[out] plaintext Output buffer for the decrypted data. + * \param plaintext_size Size of the \p plaintext buffer in bytes. + * This must be appropriate for the selected + * algorithm and key: + * - A sufficient output size is + * #PSA_AEAD_DECRYPT_OUTPUT_SIZE(\c key_type, + * \p alg, \p ciphertext_length) where + * \c key_type is the type of \p key. + * - #PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE(\p + * ciphertext_length) evaluates to the maximum + * plaintext size of any supported AEAD + * decryption. + * \param[out] plaintext_length On success, the size of the output + * in the \p plaintext buffer. + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_INVALID_SIGNATURE + * The ciphertext is not authentic. + * \retval #PSA_ERROR_NOT_PERMITTED + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \p key is not compatible with \p alg. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \p alg is not supported or is not an AEAD algorithm. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_BUFFER_TOO_SMALL + * \p plaintext_size is too small. + * #PSA_AEAD_DECRYPT_OUTPUT_SIZE(\c key_type, \p alg, + * \p ciphertext_length) or + * #PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE(\p ciphertext_length) can be used + * to determine the required buffer size. + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_aead_decrypt(mbedtls_svc_key_id_t key, + psa_algorithm_t alg, + const uint8_t *nonce, + size_t nonce_length, + const uint8_t *additional_data, + size_t additional_data_length, + const uint8_t *ciphertext, + size_t ciphertext_length, + uint8_t *plaintext, + size_t plaintext_size, + size_t *plaintext_length); + +/** The type of the state data structure for multipart AEAD operations. + * + * Before calling any function on an AEAD operation object, the application + * must initialize it by any of the following means: + * - Set the structure to all-bits-zero, for example: + * \code + * psa_aead_operation_t operation; + * memset(&operation, 0, sizeof(operation)); + * \endcode + * - Initialize the structure to logical zero values, for example: + * \code + * psa_aead_operation_t operation = {0}; + * \endcode + * - Initialize the structure to the initializer #PSA_AEAD_OPERATION_INIT, + * for example: + * \code + * psa_aead_operation_t operation = PSA_AEAD_OPERATION_INIT; + * \endcode + * - Assign the result of the function psa_aead_operation_init() + * to the structure, for example: + * \code + * psa_aead_operation_t operation; + * operation = psa_aead_operation_init(); + * \endcode + * + * This is an implementation-defined \c struct. Applications should not + * make any assumptions about the content of this structure except + * as directed by the documentation of a specific implementation. */ +typedef struct psa_aead_operation_s psa_aead_operation_t; + +/** \def PSA_AEAD_OPERATION_INIT + * + * This macro returns a suitable initializer for an AEAD operation object of + * type #psa_aead_operation_t. + */ +#ifdef __DOXYGEN_ONLY__ +/* This is an example definition for documentation purposes. + * Implementations should define a suitable value in `crypto_struct.h`. + */ +#define PSA_AEAD_OPERATION_INIT {0} +#endif + +/** Return an initial value for an AEAD operation object. + */ +static psa_aead_operation_t psa_aead_operation_init(void); + +/** Set the key for a multipart authenticated encryption operation. + * + * The sequence of operations to encrypt a message with authentication + * is as follows: + * -# Allocate an operation object which will be passed to all the functions + * listed here. + * -# Initialize the operation object with one of the methods described in the + * documentation for #psa_aead_operation_t, e.g. + * #PSA_AEAD_OPERATION_INIT. + * -# Call psa_aead_encrypt_setup() to specify the algorithm and key. + * -# If needed, call psa_aead_set_lengths() to specify the length of the + * inputs to the subsequent calls to psa_aead_update_ad() and + * psa_aead_update(). See the documentation of psa_aead_set_lengths() + * for details. + * -# Call either psa_aead_generate_nonce() or psa_aead_set_nonce() to + * generate or set the nonce. You should use + * psa_aead_generate_nonce() unless the protocol you are implementing + * requires a specific nonce value. + * -# Call psa_aead_update_ad() zero, one or more times, passing a fragment + * of the non-encrypted additional authenticated data each time. + * -# Call psa_aead_update() zero, one or more times, passing a fragment + * of the message to encrypt each time. + * -# Call psa_aead_finish(). + * + * If an error occurs at any step after a call to psa_aead_encrypt_setup(), + * the operation will need to be reset by a call to psa_aead_abort(). The + * application may call psa_aead_abort() at any time after the operation + * has been initialized. + * + * After a successful call to psa_aead_encrypt_setup(), the application must + * eventually terminate the operation. The following events terminate an + * operation: + * - A successful call to psa_aead_finish(). + * - A call to psa_aead_abort(). + * + * \param[in,out] operation The operation object to set up. It must have + * been initialized as per the documentation for + * #psa_aead_operation_t and not yet in use. + * \param key Identifier of the key to use for the operation. + * It must remain valid until the operation + * terminates. It must allow the usage + * #PSA_KEY_USAGE_ENCRYPT. + * \param alg The AEAD algorithm to compute + * (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_AEAD(\p alg) is true). + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be inactive). + * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_NOT_PERMITTED + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \p key is not compatible with \p alg. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \p alg is not supported or is not an AEAD algorithm. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_aead_encrypt_setup(psa_aead_operation_t *operation, + mbedtls_svc_key_id_t key, + psa_algorithm_t alg); + +/** Set the key for a multipart authenticated decryption operation. + * + * The sequence of operations to decrypt a message with authentication + * is as follows: + * -# Allocate an operation object which will be passed to all the functions + * listed here. + * -# Initialize the operation object with one of the methods described in the + * documentation for #psa_aead_operation_t, e.g. + * #PSA_AEAD_OPERATION_INIT. + * -# Call psa_aead_decrypt_setup() to specify the algorithm and key. + * -# If needed, call psa_aead_set_lengths() to specify the length of the + * inputs to the subsequent calls to psa_aead_update_ad() and + * psa_aead_update(). See the documentation of psa_aead_set_lengths() + * for details. + * -# Call psa_aead_set_nonce() with the nonce for the decryption. + * -# Call psa_aead_update_ad() zero, one or more times, passing a fragment + * of the non-encrypted additional authenticated data each time. + * -# Call psa_aead_update() zero, one or more times, passing a fragment + * of the ciphertext to decrypt each time. + * -# Call psa_aead_verify(). + * + * If an error occurs at any step after a call to psa_aead_decrypt_setup(), + * the operation will need to be reset by a call to psa_aead_abort(). The + * application may call psa_aead_abort() at any time after the operation + * has been initialized. + * + * After a successful call to psa_aead_decrypt_setup(), the application must + * eventually terminate the operation. The following events terminate an + * operation: + * - A successful call to psa_aead_verify(). + * - A call to psa_aead_abort(). + * + * \param[in,out] operation The operation object to set up. It must have + * been initialized as per the documentation for + * #psa_aead_operation_t and not yet in use. + * \param key Identifier of the key to use for the operation. + * It must remain valid until the operation + * terminates. It must allow the usage + * #PSA_KEY_USAGE_DECRYPT. + * \param alg The AEAD algorithm to compute + * (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_AEAD(\p alg) is true). + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be inactive). + * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_NOT_PERMITTED + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \p key is not compatible with \p alg. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \p alg is not supported or is not an AEAD algorithm. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_aead_decrypt_setup(psa_aead_operation_t *operation, + mbedtls_svc_key_id_t key, + psa_algorithm_t alg); + +/** Generate a random nonce for an authenticated encryption operation. + * + * This function generates a random nonce for the authenticated encryption + * operation with an appropriate size for the chosen algorithm, key type + * and key size. + * + * The application must call psa_aead_encrypt_setup() before + * calling this function. + * + * If this function returns an error status, the operation enters an error + * state and must be aborted by calling psa_aead_abort(). + * + * \param[in,out] operation Active AEAD operation. + * \param[out] nonce Buffer where the generated nonce is to be + * written. + * \param nonce_size Size of the \p nonce buffer in bytes. + * \param[out] nonce_length On success, the number of bytes of the + * generated nonce. + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be an active aead encrypt + * operation, with no nonce set). + * \retval #PSA_ERROR_BUFFER_TOO_SMALL + * The size of the \p nonce buffer is too small. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_aead_generate_nonce(psa_aead_operation_t *operation, + uint8_t *nonce, + size_t nonce_size, + size_t *nonce_length); + +/** Set the nonce for an authenticated encryption or decryption operation. + * + * This function sets the nonce for the authenticated + * encryption or decryption operation. + * + * The application must call psa_aead_encrypt_setup() or + * psa_aead_decrypt_setup() before calling this function. + * + * If this function returns an error status, the operation enters an error + * state and must be aborted by calling psa_aead_abort(). + * + * \note When encrypting, applications should use psa_aead_generate_nonce() + * instead of this function, unless implementing a protocol that requires + * a non-random IV. + * + * \param[in,out] operation Active AEAD operation. + * \param[in] nonce Buffer containing the nonce to use. + * \param nonce_length Size of the nonce in bytes. + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be active, with no nonce + * set). + * \retval #PSA_ERROR_INVALID_ARGUMENT + * The size of \p nonce is not acceptable for the chosen algorithm. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_aead_set_nonce(psa_aead_operation_t *operation, + const uint8_t *nonce, + size_t nonce_length); + +/** Declare the lengths of the message and additional data for AEAD. + * + * The application must call this function before calling + * psa_aead_update_ad() or psa_aead_update() if the algorithm for + * the operation requires it. If the algorithm does not require it, + * calling this function is optional, but if this function is called + * then the implementation must enforce the lengths. + * + * You may call this function before or after setting the nonce with + * psa_aead_set_nonce() or psa_aead_generate_nonce(). + * + * - For #PSA_ALG_CCM, calling this function is required. + * - For the other AEAD algorithms defined in this specification, calling + * this function is not required. + * - For vendor-defined algorithm, refer to the vendor documentation. + * + * If this function returns an error status, the operation enters an error + * state and must be aborted by calling psa_aead_abort(). + * + * \param[in,out] operation Active AEAD operation. + * \param ad_length Size of the non-encrypted additional + * authenticated data in bytes. + * \param plaintext_length Size of the plaintext to encrypt in bytes. + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be active, and + * psa_aead_update_ad() and psa_aead_update() must not have been + * called yet). + * \retval #PSA_ERROR_INVALID_ARGUMENT + * At least one of the lengths is not acceptable for the chosen + * algorithm. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_aead_set_lengths(psa_aead_operation_t *operation, + size_t ad_length, + size_t plaintext_length); + +/** Pass additional data to an active AEAD operation. + * + * Additional data is authenticated, but not encrypted. + * + * You may call this function multiple times to pass successive fragments + * of the additional data. You may not call this function after passing + * data to encrypt or decrypt with psa_aead_update(). + * + * Before calling this function, you must: + * 1. Call either psa_aead_encrypt_setup() or psa_aead_decrypt_setup(). + * 2. Set the nonce with psa_aead_generate_nonce() or psa_aead_set_nonce(). + * + * If this function returns an error status, the operation enters an error + * state and must be aborted by calling psa_aead_abort(). + * + * \warning When decrypting, until psa_aead_verify() has returned #PSA_SUCCESS, + * there is no guarantee that the input is valid. Therefore, until + * you have called psa_aead_verify() and it has returned #PSA_SUCCESS, + * treat the input as untrusted and prepare to undo any action that + * depends on the input if psa_aead_verify() returns an error status. + * + * \param[in,out] operation Active AEAD operation. + * \param[in] input Buffer containing the fragment of + * additional data. + * \param input_length Size of the \p input buffer in bytes. + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be active, have a nonce + * set, have lengths set if required by the algorithm, and + * psa_aead_update() must not have been called yet). + * \retval #PSA_ERROR_INVALID_ARGUMENT + * The total input length overflows the additional data length that + * was previously specified with psa_aead_set_lengths(). + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_aead_update_ad(psa_aead_operation_t *operation, + const uint8_t *input, + size_t input_length); + +/** Encrypt or decrypt a message fragment in an active AEAD operation. + * + * Before calling this function, you must: + * 1. Call either psa_aead_encrypt_setup() or psa_aead_decrypt_setup(). + * The choice of setup function determines whether this function + * encrypts or decrypts its input. + * 2. Set the nonce with psa_aead_generate_nonce() or psa_aead_set_nonce(). + * 3. Call psa_aead_update_ad() to pass all the additional data. + * + * If this function returns an error status, the operation enters an error + * state and must be aborted by calling psa_aead_abort(). + * + * \warning When decrypting, until psa_aead_verify() has returned #PSA_SUCCESS, + * there is no guarantee that the input is valid. Therefore, until + * you have called psa_aead_verify() and it has returned #PSA_SUCCESS: + * - Do not use the output in any way other than storing it in a + * confidential location. If you take any action that depends + * on the tentative decrypted data, this action will need to be + * undone if the input turns out not to be valid. Furthermore, + * if an adversary can observe that this action took place + * (for example through timing), they may be able to use this + * fact as an oracle to decrypt any message encrypted with the + * same key. + * - In particular, do not copy the output anywhere but to a + * memory or storage space that you have exclusive access to. + * + * This function does not require the input to be aligned to any + * particular block boundary. If the implementation can only process + * a whole block at a time, it must consume all the input provided, but + * it may delay the end of the corresponding output until a subsequent + * call to psa_aead_update(), psa_aead_finish() or psa_aead_verify() + * provides sufficient input. The amount of data that can be delayed + * in this way is bounded by #PSA_AEAD_UPDATE_OUTPUT_SIZE. + * + * \param[in,out] operation Active AEAD operation. + * \param[in] input Buffer containing the message fragment to + * encrypt or decrypt. + * \param input_length Size of the \p input buffer in bytes. + * \param[out] output Buffer where the output is to be written. + * \param output_size Size of the \p output buffer in bytes. + * This must be appropriate for the selected + * algorithm and key: + * - A sufficient output size is + * #PSA_AEAD_UPDATE_OUTPUT_SIZE(\c key_type, + * \c alg, \p input_length) where + * \c key_type is the type of key and \c alg is + * the algorithm that were used to set up the + * operation. + * - #PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(\p + * input_length) evaluates to the maximum + * output size of any supported AEAD + * algorithm. + * \param[out] output_length On success, the number of bytes + * that make up the returned output. + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be active, have a nonce + * set, and have lengths set if required by the algorithm). + * \retval #PSA_ERROR_BUFFER_TOO_SMALL + * The size of the \p output buffer is too small. + * #PSA_AEAD_UPDATE_OUTPUT_SIZE(\c key_type, \c alg, \p input_length) or + * #PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(\p input_length) can be used to + * determine the required buffer size. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * The total length of input to psa_aead_update_ad() so far is + * less than the additional data length that was previously + * specified with psa_aead_set_lengths(). + * \retval #PSA_ERROR_INVALID_ARGUMENT + * The total input length overflows the plaintext length that + * was previously specified with psa_aead_set_lengths(). + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_aead_update(psa_aead_operation_t *operation, + const uint8_t *input, + size_t input_length, + uint8_t *output, + size_t output_size, + size_t *output_length); + +/** Finish encrypting a message in an AEAD operation. + * + * The operation must have been set up with psa_aead_encrypt_setup(). + * + * This function finishes the authentication of the additional data + * formed by concatenating the inputs passed to preceding calls to + * psa_aead_update_ad() with the plaintext formed by concatenating the + * inputs passed to preceding calls to psa_aead_update(). + * + * This function has two output buffers: + * - \p ciphertext contains trailing ciphertext that was buffered from + * preceding calls to psa_aead_update(). + * - \p tag contains the authentication tag. + * + * When this function returns successfuly, the operation becomes inactive. + * If this function returns an error status, the operation enters an error + * state and must be aborted by calling psa_aead_abort(). + * + * \param[in,out] operation Active AEAD operation. + * \param[out] ciphertext Buffer where the last part of the ciphertext + * is to be written. + * \param ciphertext_size Size of the \p ciphertext buffer in bytes. + * This must be appropriate for the selected + * algorithm and key: + * - A sufficient output size is + * #PSA_AEAD_FINISH_OUTPUT_SIZE(\c key_type, + * \c alg) where \c key_type is the type of key + * and \c alg is the algorithm that were used to + * set up the operation. + * - #PSA_AEAD_FINISH_OUTPUT_MAX_SIZE evaluates to + * the maximum output size of any supported AEAD + * algorithm. + * \param[out] ciphertext_length On success, the number of bytes of + * returned ciphertext. + * \param[out] tag Buffer where the authentication tag is + * to be written. + * \param tag_size Size of the \p tag buffer in bytes. + * This must be appropriate for the selected + * algorithm and key: + * - The exact tag size is #PSA_AEAD_TAG_LENGTH(\c + * key_type, \c key_bits, \c alg) where + * \c key_type and \c key_bits are the type and + * bit-size of the key, and \c alg is the + * algorithm that were used in the call to + * psa_aead_encrypt_setup(). + * - #PSA_AEAD_TAG_MAX_SIZE evaluates to the + * maximum tag size of any supported AEAD + * algorithm. + * \param[out] tag_length On success, the number of bytes + * that make up the returned tag. + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be an active encryption + * operation with a nonce set). + * \retval #PSA_ERROR_BUFFER_TOO_SMALL + * The size of the \p ciphertext or \p tag buffer is too small. + * #PSA_AEAD_FINISH_OUTPUT_SIZE(\c key_type, \c alg) or + * #PSA_AEAD_FINISH_OUTPUT_MAX_SIZE can be used to determine the + * required \p ciphertext buffer size. #PSA_AEAD_TAG_LENGTH(\c key_type, + * \c key_bits, \c alg) or #PSA_AEAD_TAG_MAX_SIZE can be used to + * determine the required \p tag buffer size. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * The total length of input to psa_aead_update_ad() so far is + * less than the additional data length that was previously + * specified with psa_aead_set_lengths(). + * \retval #PSA_ERROR_INVALID_ARGUMENT + * The total length of input to psa_aead_update() so far is + * less than the plaintext length that was previously + * specified with psa_aead_set_lengths(). + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_aead_finish(psa_aead_operation_t *operation, + uint8_t *ciphertext, + size_t ciphertext_size, + size_t *ciphertext_length, + uint8_t *tag, + size_t tag_size, + size_t *tag_length); + +/** Finish authenticating and decrypting a message in an AEAD operation. + * + * The operation must have been set up with psa_aead_decrypt_setup(). + * + * This function finishes the authenticated decryption of the message + * components: + * + * - The additional data consisting of the concatenation of the inputs + * passed to preceding calls to psa_aead_update_ad(). + * - The ciphertext consisting of the concatenation of the inputs passed to + * preceding calls to psa_aead_update(). + * - The tag passed to this function call. + * + * If the authentication tag is correct, this function outputs any remaining + * plaintext and reports success. If the authentication tag is not correct, + * this function returns #PSA_ERROR_INVALID_SIGNATURE. + * + * When this function returns successfuly, the operation becomes inactive. + * If this function returns an error status, the operation enters an error + * state and must be aborted by calling psa_aead_abort(). + * + * \note Implementations shall make the best effort to ensure that the + * comparison between the actual tag and the expected tag is performed + * in constant time. + * + * \param[in,out] operation Active AEAD operation. + * \param[out] plaintext Buffer where the last part of the plaintext + * is to be written. This is the remaining data + * from previous calls to psa_aead_update() + * that could not be processed until the end + * of the input. + * \param plaintext_size Size of the \p plaintext buffer in bytes. + * This must be appropriate for the selected algorithm and key: + * - A sufficient output size is + * #PSA_AEAD_VERIFY_OUTPUT_SIZE(\c key_type, + * \c alg) where \c key_type is the type of key + * and \c alg is the algorithm that were used to + * set up the operation. + * - #PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE evaluates to + * the maximum output size of any supported AEAD + * algorithm. + * \param[out] plaintext_length On success, the number of bytes of + * returned plaintext. + * \param[in] tag Buffer containing the authentication tag. + * \param tag_length Size of the \p tag buffer in bytes. + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_INVALID_SIGNATURE + * The calculations were successful, but the authentication tag is + * not correct. + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be an active decryption + * operation with a nonce set). + * \retval #PSA_ERROR_BUFFER_TOO_SMALL + * The size of the \p plaintext buffer is too small. + * #PSA_AEAD_VERIFY_OUTPUT_SIZE(\c key_type, \c alg) or + * #PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE can be used to determine the + * required buffer size. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * The total length of input to psa_aead_update_ad() so far is + * less than the additional data length that was previously + * specified with psa_aead_set_lengths(). + * \retval #PSA_ERROR_INVALID_ARGUMENT + * The total length of input to psa_aead_update() so far is + * less than the plaintext length that was previously + * specified with psa_aead_set_lengths(). + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_aead_verify(psa_aead_operation_t *operation, + uint8_t *plaintext, + size_t plaintext_size, + size_t *plaintext_length, + const uint8_t *tag, + size_t tag_length); + +/** Abort an AEAD operation. + * + * Aborting an operation frees all associated resources except for the + * \p operation structure itself. Once aborted, the operation object + * can be reused for another operation by calling + * psa_aead_encrypt_setup() or psa_aead_decrypt_setup() again. + * + * You may call this function any time after the operation object has + * been initialized as described in #psa_aead_operation_t. + * + * In particular, calling psa_aead_abort() after the operation has been + * terminated by a call to psa_aead_abort(), psa_aead_finish() or + * psa_aead_verify() is safe and has no effect. + * + * \param[in,out] operation Initialized AEAD operation. + * + * \retval #PSA_SUCCESS + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_aead_abort(psa_aead_operation_t *operation); + +/**@}*/ + +/** \defgroup asymmetric Asymmetric cryptography + * @{ + */ + +/** + * \brief Sign a message with a private key. For hash-and-sign algorithms, + * this includes the hashing step. + * + * \note To perform a multi-part hash-and-sign signature algorithm, first use + * a multi-part hash operation and then pass the resulting hash to + * psa_sign_hash(). PSA_ALG_GET_HASH(\p alg) can be used to determine the + * hash algorithm to use. + * + * \param[in] key Identifier of the key to use for the operation. + * It must be an asymmetric key pair. The key must + * allow the usage #PSA_KEY_USAGE_SIGN_MESSAGE. + * \param[in] alg An asymmetric signature algorithm (PSA_ALG_XXX + * value such that #PSA_ALG_IS_SIGN_MESSAGE(\p alg) + * is true), that is compatible with the type of + * \p key. + * \param[in] input The input message to sign. + * \param[in] input_length Size of the \p input buffer in bytes. + * \param[out] signature Buffer where the signature is to be written. + * \param[in] signature_size Size of the \p signature buffer in bytes. This + * must be appropriate for the selected + * algorithm and key: + * - The required signature size is + * #PSA_SIGN_OUTPUT_SIZE(\c key_type, \c key_bits, \p alg) + * where \c key_type and \c key_bits are the type and + * bit-size respectively of key. + * - #PSA_SIGNATURE_MAX_SIZE evaluates to the + * maximum signature size of any supported + * signature algorithm. + * \param[out] signature_length On success, the number of bytes that make up + * the returned signature value. + * + * \retval #PSA_SUCCESS + * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_NOT_PERMITTED + * The key does not have the #PSA_KEY_USAGE_SIGN_MESSAGE flag, + * or it does not permit the requested algorithm. + * \retval #PSA_ERROR_BUFFER_TOO_SMALL + * The size of the \p signature buffer is too small. You can + * determine a sufficient buffer size by calling + * #PSA_SIGN_OUTPUT_SIZE(\c key_type, \c key_bits, \p alg) + * where \c key_type and \c key_bits are the type and bit-size + * respectively of \p key. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_DATA_CORRUPT + * \retval #PSA_ERROR_DATA_INVALID + * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_sign_message( mbedtls_svc_key_id_t key, + psa_algorithm_t alg, + const uint8_t * input, + size_t input_length, + uint8_t * signature, + size_t signature_size, + size_t * signature_length ); + +/** \brief Verify the signature of a message with a public key, using + * a hash-and-sign verification algorithm. + * + * \note To perform a multi-part hash-and-sign signature verification + * algorithm, first use a multi-part hash operation to hash the message + * and then pass the resulting hash to psa_verify_hash(). + * PSA_ALG_GET_HASH(\p alg) can be used to determine the hash algorithm + * to use. + * + * \param[in] key Identifier of the key to use for the operation. + * It must be a public key or an asymmetric key + * pair. The key must allow the usage + * #PSA_KEY_USAGE_VERIFY_MESSAGE. + * \param[in] alg An asymmetric signature algorithm (PSA_ALG_XXX + * value such that #PSA_ALG_IS_SIGN_MESSAGE(\p alg) + * is true), that is compatible with the type of + * \p key. + * \param[in] input The message whose signature is to be verified. + * \param[in] input_length Size of the \p input buffer in bytes. + * \param[out] signature Buffer containing the signature to verify. + * \param[in] signature_length Size of the \p signature buffer in bytes. + * + * \retval #PSA_SUCCESS + * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_NOT_PERMITTED + * The key does not have the #PSA_KEY_USAGE_SIGN_MESSAGE flag, + * or it does not permit the requested algorithm. + * \retval #PSA_ERROR_INVALID_SIGNATURE + * The calculation was performed successfully, but the passed signature + * is not a valid signature. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_DATA_CORRUPT + * \retval #PSA_ERROR_DATA_INVALID + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_verify_message( mbedtls_svc_key_id_t key, + psa_algorithm_t alg, + const uint8_t * input, + size_t input_length, + const uint8_t * signature, + size_t signature_length ); + +/** + * \brief Sign a hash or short message with a private key. + * + * Note that to perform a hash-and-sign signature algorithm, you must + * first calculate the hash by calling psa_hash_setup(), psa_hash_update() + * and psa_hash_finish(), or alternatively by calling psa_hash_compute(). + * Then pass the resulting hash as the \p hash + * parameter to this function. You can use #PSA_ALG_SIGN_GET_HASH(\p alg) + * to determine the hash algorithm to use. + * + * \param key Identifier of the key to use for the operation. + * It must be an asymmetric key pair. The key must + * allow the usage #PSA_KEY_USAGE_SIGN_HASH. + * \param alg A signature algorithm (PSA_ALG_XXX + * value such that #PSA_ALG_IS_SIGN_HASH(\p alg) + * is true), that is compatible with + * the type of \p key. + * \param[in] hash The hash or message to sign. + * \param hash_length Size of the \p hash buffer in bytes. + * \param[out] signature Buffer where the signature is to be written. + * \param signature_size Size of the \p signature buffer in bytes. + * \param[out] signature_length On success, the number of bytes + * that make up the returned signature value. + * + * \retval #PSA_SUCCESS + * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_NOT_PERMITTED + * \retval #PSA_ERROR_BUFFER_TOO_SMALL + * The size of the \p signature buffer is too small. You can + * determine a sufficient buffer size by calling + * #PSA_SIGN_OUTPUT_SIZE(\c key_type, \c key_bits, \p alg) + * where \c key_type and \c key_bits are the type and bit-size + * respectively of \p key. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_sign_hash(mbedtls_svc_key_id_t key, + psa_algorithm_t alg, + const uint8_t *hash, + size_t hash_length, + uint8_t *signature, + size_t signature_size, + size_t *signature_length); + +/** + * \brief Verify the signature of a hash or short message using a public key. + * + * Note that to perform a hash-and-sign signature algorithm, you must + * first calculate the hash by calling psa_hash_setup(), psa_hash_update() + * and psa_hash_finish(), or alternatively by calling psa_hash_compute(). + * Then pass the resulting hash as the \p hash + * parameter to this function. You can use #PSA_ALG_SIGN_GET_HASH(\p alg) + * to determine the hash algorithm to use. + * + * \param key Identifier of the key to use for the operation. It + * must be a public key or an asymmetric key pair. The + * key must allow the usage + * #PSA_KEY_USAGE_VERIFY_HASH. + * \param alg A signature algorithm (PSA_ALG_XXX + * value such that #PSA_ALG_IS_SIGN_HASH(\p alg) + * is true), that is compatible with + * the type of \p key. + * \param[in] hash The hash or message whose signature is to be + * verified. + * \param hash_length Size of the \p hash buffer in bytes. + * \param[in] signature Buffer containing the signature to verify. + * \param signature_length Size of the \p signature buffer in bytes. + * + * \retval #PSA_SUCCESS + * The signature is valid. + * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_NOT_PERMITTED + * \retval #PSA_ERROR_INVALID_SIGNATURE + * The calculation was perfomed successfully, but the passed + * signature is not a valid signature. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_verify_hash(mbedtls_svc_key_id_t key, + psa_algorithm_t alg, + const uint8_t *hash, + size_t hash_length, + const uint8_t *signature, + size_t signature_length); + +/** + * \brief Encrypt a short message with a public key. + * + * \param key Identifer of the key to use for the operation. + * It must be a public key or an asymmetric key + * pair. It must allow the usage + * #PSA_KEY_USAGE_ENCRYPT. + * \param alg An asymmetric encryption algorithm that is + * compatible with the type of \p key. + * \param[in] input The message to encrypt. + * \param input_length Size of the \p input buffer in bytes. + * \param[in] salt A salt or label, if supported by the + * encryption algorithm. + * If the algorithm does not support a + * salt, pass \c NULL. + * If the algorithm supports an optional + * salt and you do not want to pass a salt, + * pass \c NULL. + * + * - For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is + * supported. + * \param salt_length Size of the \p salt buffer in bytes. + * If \p salt is \c NULL, pass 0. + * \param[out] output Buffer where the encrypted message is to + * be written. + * \param output_size Size of the \p output buffer in bytes. + * \param[out] output_length On success, the number of bytes + * that make up the returned output. + * + * \retval #PSA_SUCCESS + * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_NOT_PERMITTED + * \retval #PSA_ERROR_BUFFER_TOO_SMALL + * The size of the \p output buffer is too small. You can + * determine a sufficient buffer size by calling + * #PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(\c key_type, \c key_bits, \p alg) + * where \c key_type and \c key_bits are the type and bit-size + * respectively of \p key. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_asymmetric_encrypt(mbedtls_svc_key_id_t key, + psa_algorithm_t alg, + const uint8_t *input, + size_t input_length, + const uint8_t *salt, + size_t salt_length, + uint8_t *output, + size_t output_size, + size_t *output_length); + +/** + * \brief Decrypt a short message with a private key. + * + * \param key Identifier of the key to use for the operation. + * It must be an asymmetric key pair. It must + * allow the usage #PSA_KEY_USAGE_DECRYPT. + * \param alg An asymmetric encryption algorithm that is + * compatible with the type of \p key. + * \param[in] input The message to decrypt. + * \param input_length Size of the \p input buffer in bytes. + * \param[in] salt A salt or label, if supported by the + * encryption algorithm. + * If the algorithm does not support a + * salt, pass \c NULL. + * If the algorithm supports an optional + * salt and you do not want to pass a salt, + * pass \c NULL. + * + * - For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is + * supported. + * \param salt_length Size of the \p salt buffer in bytes. + * If \p salt is \c NULL, pass 0. + * \param[out] output Buffer where the decrypted message is to + * be written. + * \param output_size Size of the \c output buffer in bytes. + * \param[out] output_length On success, the number of bytes + * that make up the returned output. + * + * \retval #PSA_SUCCESS + * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_NOT_PERMITTED + * \retval #PSA_ERROR_BUFFER_TOO_SMALL + * The size of the \p output buffer is too small. You can + * determine a sufficient buffer size by calling + * #PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(\c key_type, \c key_bits, \p alg) + * where \c key_type and \c key_bits are the type and bit-size + * respectively of \p key. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY + * \retval #PSA_ERROR_INVALID_PADDING + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_asymmetric_decrypt(mbedtls_svc_key_id_t key, + psa_algorithm_t alg, + const uint8_t *input, + size_t input_length, + const uint8_t *salt, + size_t salt_length, + uint8_t *output, + size_t output_size, + size_t *output_length); + +/**@}*/ + +/** \defgroup key_derivation Key derivation and pseudorandom generation + * @{ + */ + +/** The type of the state data structure for key derivation operations. + * + * Before calling any function on a key derivation operation object, the + * application must initialize it by any of the following means: + * - Set the structure to all-bits-zero, for example: + * \code + * psa_key_derivation_operation_t operation; + * memset(&operation, 0, sizeof(operation)); + * \endcode + * - Initialize the structure to logical zero values, for example: + * \code + * psa_key_derivation_operation_t operation = {0}; + * \endcode + * - Initialize the structure to the initializer #PSA_KEY_DERIVATION_OPERATION_INIT, + * for example: + * \code + * psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT; + * \endcode + * - Assign the result of the function psa_key_derivation_operation_init() + * to the structure, for example: + * \code + * psa_key_derivation_operation_t operation; + * operation = psa_key_derivation_operation_init(); + * \endcode + * + * This is an implementation-defined \c struct. Applications should not + * make any assumptions about the content of this structure except + * as directed by the documentation of a specific implementation. + */ +typedef struct psa_key_derivation_s psa_key_derivation_operation_t; + +/** \def PSA_KEY_DERIVATION_OPERATION_INIT + * + * This macro returns a suitable initializer for a key derivation operation + * object of type #psa_key_derivation_operation_t. + */ +#ifdef __DOXYGEN_ONLY__ +/* This is an example definition for documentation purposes. + * Implementations should define a suitable value in `crypto_struct.h`. + */ +#define PSA_KEY_DERIVATION_OPERATION_INIT {0} +#endif + +/** Return an initial value for a key derivation operation object. + */ +static psa_key_derivation_operation_t psa_key_derivation_operation_init(void); + +/** Set up a key derivation operation. + * + * A key derivation algorithm takes some inputs and uses them to generate + * a byte stream in a deterministic way. + * This byte stream can be used to produce keys and other + * cryptographic material. + * + * To derive a key: + * -# Start with an initialized object of type #psa_key_derivation_operation_t. + * -# Call psa_key_derivation_setup() to select the algorithm. + * -# Provide the inputs for the key derivation by calling + * psa_key_derivation_input_bytes() or psa_key_derivation_input_key() + * as appropriate. Which inputs are needed, in what order, and whether + * they may be keys and if so of what type depends on the algorithm. + * -# Optionally set the operation's maximum capacity with + * psa_key_derivation_set_capacity(). You may do this before, in the middle + * of or after providing inputs. For some algorithms, this step is mandatory + * because the output depends on the maximum capacity. + * -# To derive a key, call psa_key_derivation_output_key(). + * To derive a byte string for a different purpose, call + * psa_key_derivation_output_bytes(). + * Successive calls to these functions use successive output bytes + * calculated by the key derivation algorithm. + * -# Clean up the key derivation operation object with + * psa_key_derivation_abort(). + * + * If this function returns an error, the key derivation operation object is + * not changed. + * + * If an error occurs at any step after a call to psa_key_derivation_setup(), + * the operation will need to be reset by a call to psa_key_derivation_abort(). + * + * Implementations must reject an attempt to derive a key of size 0. + * + * \param[in,out] operation The key derivation operation object + * to set up. It must + * have been initialized but not set up yet. + * \param alg The key derivation algorithm to compute + * (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_KEY_DERIVATION(\p alg) is true). + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \c alg is not a key derivation algorithm. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \c alg is not supported or is not a key derivation algorithm. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be inactive). + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_key_derivation_setup( + psa_key_derivation_operation_t *operation, + psa_algorithm_t alg); + +/** Retrieve the current capacity of a key derivation operation. + * + * The capacity of a key derivation is the maximum number of bytes that it can + * return. When you get *N* bytes of output from a key derivation operation, + * this reduces its capacity by *N*. + * + * \param[in] operation The operation to query. + * \param[out] capacity On success, the capacity of the operation. + * + * \retval #PSA_SUCCESS + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be active). + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_key_derivation_get_capacity( + const psa_key_derivation_operation_t *operation, + size_t *capacity); + +/** Set the maximum capacity of a key derivation operation. + * + * The capacity of a key derivation operation is the maximum number of bytes + * that the key derivation operation can return from this point onwards. + * + * \param[in,out] operation The key derivation operation object to modify. + * \param capacity The new capacity of the operation. + * It must be less or equal to the operation's + * current capacity. + * + * \retval #PSA_SUCCESS + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \p capacity is larger than the operation's current capacity. + * In this case, the operation object remains valid and its capacity + * remains unchanged. + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be active). + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_key_derivation_set_capacity( + psa_key_derivation_operation_t *operation, + size_t capacity); + +/** Use the maximum possible capacity for a key derivation operation. + * + * Use this value as the capacity argument when setting up a key derivation + * to indicate that the operation should have the maximum possible capacity. + * The value of the maximum possible capacity depends on the key derivation + * algorithm. + */ +#define PSA_KEY_DERIVATION_UNLIMITED_CAPACITY ((size_t)(-1)) + +/** Provide an input for key derivation or key agreement. + * + * Which inputs are required and in what order depends on the algorithm. + * Refer to the documentation of each key derivation or key agreement + * algorithm for information. + * + * This function passes direct inputs, which is usually correct for + * non-secret inputs. To pass a secret input, which should be in a key + * object, call psa_key_derivation_input_key() instead of this function. + * Refer to the documentation of individual step types + * (`PSA_KEY_DERIVATION_INPUT_xxx` values of type ::psa_key_derivation_step_t) + * for more information. + * + * If this function returns an error status, the operation enters an error + * state and must be aborted by calling psa_key_derivation_abort(). + * + * \param[in,out] operation The key derivation operation object to use. + * It must have been set up with + * psa_key_derivation_setup() and must not + * have produced any output yet. + * \param step Which step the input data is for. + * \param[in] data Input data to use. + * \param data_length Size of the \p data buffer in bytes. + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \c step is not compatible with the operation's algorithm. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \c step does not allow direct inputs. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid for this input \p step. + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_key_derivation_input_bytes( + psa_key_derivation_operation_t *operation, + psa_key_derivation_step_t step, + const uint8_t *data, + size_t data_length); + +/** Provide an input for key derivation in the form of a key. + * + * Which inputs are required and in what order depends on the algorithm. + * Refer to the documentation of each key derivation or key agreement + * algorithm for information. + * + * This function obtains input from a key object, which is usually correct for + * secret inputs or for non-secret personalization strings kept in the key + * store. To pass a non-secret parameter which is not in the key store, + * call psa_key_derivation_input_bytes() instead of this function. + * Refer to the documentation of individual step types + * (`PSA_KEY_DERIVATION_INPUT_xxx` values of type ::psa_key_derivation_step_t) + * for more information. + * + * If this function returns an error status, the operation enters an error + * state and must be aborted by calling psa_key_derivation_abort(). + * + * \param[in,out] operation The key derivation operation object to use. + * It must have been set up with + * psa_key_derivation_setup() and must not + * have produced any output yet. + * \param step Which step the input data is for. + * \param key Identifier of the key. It must have an + * appropriate type for step and must allow the + * usage #PSA_KEY_USAGE_DERIVE. + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_NOT_PERMITTED + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \c step is not compatible with the operation's algorithm. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \c step does not allow key inputs of the given type + * or does not allow key inputs at all. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid for this input \p step. + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_key_derivation_input_key( + psa_key_derivation_operation_t *operation, + psa_key_derivation_step_t step, + mbedtls_svc_key_id_t key); + +/** Perform a key agreement and use the shared secret as input to a key + * derivation. + * + * A key agreement algorithm takes two inputs: a private key \p private_key + * a public key \p peer_key. + * The result of this function is passed as input to a key derivation. + * The output of this key derivation can be extracted by reading from the + * resulting operation to produce keys and other cryptographic material. + * + * If this function returns an error status, the operation enters an error + * state and must be aborted by calling psa_key_derivation_abort(). + * + * \param[in,out] operation The key derivation operation object to use. + * It must have been set up with + * psa_key_derivation_setup() with a + * key agreement and derivation algorithm + * \c alg (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_KEY_AGREEMENT(\c alg) is true + * and #PSA_ALG_IS_RAW_KEY_AGREEMENT(\c alg) + * is false). + * The operation must be ready for an + * input of the type given by \p step. + * \param step Which step the input data is for. + * \param private_key Identifier of the private key to use. It must + * allow the usage #PSA_KEY_USAGE_DERIVE. + * \param[in] peer_key Public key of the peer. The peer key must be in the + * same format that psa_import_key() accepts for the + * public key type corresponding to the type of + * private_key. That is, this function performs the + * equivalent of + * #psa_import_key(..., + * `peer_key`, `peer_key_length`) where + * with key attributes indicating the public key + * type corresponding to the type of `private_key`. + * For example, for EC keys, this means that peer_key + * is interpreted as a point on the curve that the + * private key is on. The standard formats for public + * keys are documented in the documentation of + * psa_export_public_key(). + * \param peer_key_length Size of \p peer_key in bytes. + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid for this key agreement \p step. + * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_NOT_PERMITTED + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \c private_key is not compatible with \c alg, + * or \p peer_key is not valid for \c alg or not compatible with + * \c private_key. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \c alg is not supported or is not a key derivation algorithm. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \c step does not allow an input resulting from a key agreement. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_key_derivation_key_agreement( + psa_key_derivation_operation_t *operation, + psa_key_derivation_step_t step, + mbedtls_svc_key_id_t private_key, + const uint8_t *peer_key, + size_t peer_key_length); + +/** Read some data from a key derivation operation. + * + * This function calculates output bytes from a key derivation algorithm and + * return those bytes. + * If you view the key derivation's output as a stream of bytes, this + * function destructively reads the requested number of bytes from the + * stream. + * The operation's capacity decreases by the number of bytes read. + * + * If this function returns an error status other than + * #PSA_ERROR_INSUFFICIENT_DATA, the operation enters an error + * state and must be aborted by calling psa_key_derivation_abort(). + * + * \param[in,out] operation The key derivation operation object to read from. + * \param[out] output Buffer where the output will be written. + * \param output_length Number of bytes to output. + * + * \retval #PSA_SUCCESS + * \retval #PSA_ERROR_INSUFFICIENT_DATA + * The operation's capacity was less than + * \p output_length bytes. Note that in this case, + * no output is written to the output buffer. + * The operation's capacity is set to 0, thus + * subsequent calls to this function will not + * succeed, even with a smaller output buffer. + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be active and completed + * all required input steps). + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_key_derivation_output_bytes( + psa_key_derivation_operation_t *operation, + uint8_t *output, + size_t output_length); + +/** Derive a key from an ongoing key derivation operation. + * + * This function calculates output bytes from a key derivation algorithm + * and uses those bytes to generate a key deterministically. + * The key's location, usage policy, type and size are taken from + * \p attributes. + * + * If you view the key derivation's output as a stream of bytes, this + * function destructively reads as many bytes as required from the + * stream. + * The operation's capacity decreases by the number of bytes read. + * + * If this function returns an error status other than + * #PSA_ERROR_INSUFFICIENT_DATA, the operation enters an error + * state and must be aborted by calling psa_key_derivation_abort(). + * + * How much output is produced and consumed from the operation, and how + * the key is derived, depends on the key type and on the key size + * (denoted \c bits below): + * + * - For key types for which the key is an arbitrary sequence of bytes + * of a given size, this function is functionally equivalent to + * calling #psa_key_derivation_output_bytes + * and passing the resulting output to #psa_import_key. + * However, this function has a security benefit: + * if the implementation provides an isolation boundary then + * the key material is not exposed outside the isolation boundary. + * As a consequence, for these key types, this function always consumes + * exactly (\c bits / 8) bytes from the operation. + * The following key types defined in this specification follow this scheme: + * + * - #PSA_KEY_TYPE_AES; + * - #PSA_KEY_TYPE_ARC4; + * - #PSA_KEY_TYPE_ARIA; + * - #PSA_KEY_TYPE_CAMELLIA; + * - #PSA_KEY_TYPE_DERIVE; + * - #PSA_KEY_TYPE_HMAC. + * + * - For ECC keys on a Montgomery elliptic curve + * (#PSA_KEY_TYPE_ECC_KEY_PAIR(\c curve) where \c curve designates a + * Montgomery curve), this function always draws a byte string whose + * length is determined by the curve, and sets the mandatory bits + * accordingly. That is: + * + * - Curve25519 (#PSA_ECC_FAMILY_MONTGOMERY, 255 bits): draw a 32-byte + * string and process it as specified in RFC 7748 §5. + * - Curve448 (#PSA_ECC_FAMILY_MONTGOMERY, 448 bits): draw a 56-byte + * string and process it as specified in RFC 7748 §5. + * + * - For key types for which the key is represented by a single sequence of + * \c bits bits with constraints as to which bit sequences are acceptable, + * this function draws a byte string of length (\c bits / 8) bytes rounded + * up to the nearest whole number of bytes. If the resulting byte string + * is acceptable, it becomes the key, otherwise the drawn bytes are discarded. + * This process is repeated until an acceptable byte string is drawn. + * The byte string drawn from the operation is interpreted as specified + * for the output produced by psa_export_key(). + * The following key types defined in this specification follow this scheme: + * + * - #PSA_KEY_TYPE_DES. + * Force-set the parity bits, but discard forbidden weak keys. + * For 2-key and 3-key triple-DES, the three keys are generated + * successively (for example, for 3-key triple-DES, + * if the first 8 bytes specify a weak key and the next 8 bytes do not, + * discard the first 8 bytes, use the next 8 bytes as the first key, + * and continue reading output from the operation to derive the other + * two keys). + * - Finite-field Diffie-Hellman keys (#PSA_KEY_TYPE_DH_KEY_PAIR(\c group) + * where \c group designates any Diffie-Hellman group) and + * ECC keys on a Weierstrass elliptic curve + * (#PSA_KEY_TYPE_ECC_KEY_PAIR(\c curve) where \c curve designates a + * Weierstrass curve). + * For these key types, interpret the byte string as integer + * in big-endian order. Discard it if it is not in the range + * [0, *N* - 2] where *N* is the boundary of the private key domain + * (the prime *p* for Diffie-Hellman, the subprime *q* for DSA, + * or the order of the curve's base point for ECC). + * Add 1 to the resulting integer and use this as the private key *x*. + * This method allows compliance to NIST standards, specifically + * the methods titled "key-pair generation by testing candidates" + * in NIST SP 800-56A §5.6.1.1.4 for Diffie-Hellman, + * in FIPS 186-4 §B.1.2 for DSA, and + * in NIST SP 800-56A §5.6.1.2.2 or + * FIPS 186-4 §B.4.2 for elliptic curve keys. + * + * - For other key types, including #PSA_KEY_TYPE_RSA_KEY_PAIR, + * the way in which the operation output is consumed is + * implementation-defined. + * + * In all cases, the data that is read is discarded from the operation. + * The operation's capacity is decreased by the number of bytes read. + * + * For algorithms that take an input step #PSA_KEY_DERIVATION_INPUT_SECRET, + * the input to that step must be provided with psa_key_derivation_input_key(). + * Future versions of this specification may include additional restrictions + * on the derived key based on the attributes and strength of the secret key. + * + * \param[in] attributes The attributes for the new key. + * \param[in,out] operation The key derivation operation object to read from. + * \param[out] key On success, an identifier for the newly created + * key. For persistent keys, this is the key + * identifier defined in \p attributes. + * \c 0 on failure. + * + * \retval #PSA_SUCCESS + * Success. + * If the key is persistent, the key material and the key's metadata + * have been saved to persistent storage. + * \retval #PSA_ERROR_ALREADY_EXISTS + * This is an attempt to create a persistent key, and there is + * already a persistent key with the given identifier. + * \retval #PSA_ERROR_INSUFFICIENT_DATA + * There was not enough data to create the desired key. + * Note that in this case, no output is written to the output buffer. + * The operation's capacity is set to 0, thus subsequent calls to + * this function will not succeed, even with a smaller output buffer. + * \retval #PSA_ERROR_NOT_SUPPORTED + * The key type or key size is not supported, either by the + * implementation in general or in this particular location. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * The provided key attributes are not valid for the operation. + * \retval #PSA_ERROR_NOT_PERMITTED + * The #PSA_KEY_DERIVATION_INPUT_SECRET input was not provided through + * a key. + * \retval #PSA_ERROR_BAD_STATE + * The operation state is not valid (it must be active and completed + * all required input steps). + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_INSUFFICIENT_STORAGE + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_DATA_INVALID + * \retval #PSA_ERROR_DATA_CORRUPT + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_key_derivation_output_key( + const psa_key_attributes_t *attributes, + psa_key_derivation_operation_t *operation, + mbedtls_svc_key_id_t *key); + +/** Abort a key derivation operation. + * + * Aborting an operation frees all associated resources except for the \c + * operation structure itself. Once aborted, the operation object can be reused + * for another operation by calling psa_key_derivation_setup() again. + * + * This function may be called at any time after the operation + * object has been initialized as described in #psa_key_derivation_operation_t. + * + * In particular, it is valid to call psa_key_derivation_abort() twice, or to + * call psa_key_derivation_abort() on an operation that has not been set up. + * + * \param[in,out] operation The operation to abort. + * + * \retval #PSA_SUCCESS + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_key_derivation_abort( + psa_key_derivation_operation_t *operation); + +/** Perform a key agreement and return the raw shared secret. + * + * \warning The raw result of a key agreement algorithm such as finite-field + * Diffie-Hellman or elliptic curve Diffie-Hellman has biases and should + * not be used directly as key material. It should instead be passed as + * input to a key derivation algorithm. To chain a key agreement with + * a key derivation, use psa_key_derivation_key_agreement() and other + * functions from the key derivation interface. + * + * \param alg The key agreement algorithm to compute + * (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_RAW_KEY_AGREEMENT(\p alg) + * is true). + * \param private_key Identifier of the private key to use. It must + * allow the usage #PSA_KEY_USAGE_DERIVE. + * \param[in] peer_key Public key of the peer. It must be + * in the same format that psa_import_key() + * accepts. The standard formats for public + * keys are documented in the documentation + * of psa_export_public_key(). + * \param peer_key_length Size of \p peer_key in bytes. + * \param[out] output Buffer where the decrypted message is to + * be written. + * \param output_size Size of the \c output buffer in bytes. + * \param[out] output_length On success, the number of bytes + * that make up the returned output. + * + * \retval #PSA_SUCCESS + * Success. + * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_NOT_PERMITTED + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \p alg is not a key agreement algorithm + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \p private_key is not compatible with \p alg, + * or \p peer_key is not valid for \p alg or not compatible with + * \p private_key. + * \retval #PSA_ERROR_BUFFER_TOO_SMALL + * \p output_size is too small + * \retval #PSA_ERROR_NOT_SUPPORTED + * \p alg is not a supported key agreement algorithm. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_raw_key_agreement(psa_algorithm_t alg, + mbedtls_svc_key_id_t private_key, + const uint8_t *peer_key, + size_t peer_key_length, + uint8_t *output, + size_t output_size, + size_t *output_length); + +/**@}*/ + +/** \defgroup random Random generation + * @{ + */ + +/** + * \brief Generate random bytes. + * + * \warning This function **can** fail! Callers MUST check the return status + * and MUST NOT use the content of the output buffer if the return + * status is not #PSA_SUCCESS. + * + * \note To generate a key, use psa_generate_key() instead. + * + * \param[out] output Output buffer for the generated data. + * \param output_size Number of bytes to generate and output. + * + * \retval #PSA_SUCCESS + * \retval #PSA_ERROR_NOT_SUPPORTED + * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_generate_random(uint8_t *output, + size_t output_size); + +/** + * \brief Generate a key or key pair. + * + * The key is generated randomly. + * Its location, usage policy, type and size are taken from \p attributes. + * + * Implementations must reject an attempt to generate a key of size 0. + * + * The following type-specific considerations apply: + * - For RSA keys (#PSA_KEY_TYPE_RSA_KEY_PAIR), + * the public exponent is 65537. + * The modulus is a product of two probabilistic primes + * between 2^{n-1} and 2^n where n is the bit size specified in the + * attributes. + * + * \param[in] attributes The attributes for the new key. + * \param[out] key On success, an identifier for the newly created + * key. For persistent keys, this is the key + * identifier defined in \p attributes. + * \c 0 on failure. + * + * \retval #PSA_SUCCESS + * Success. + * If the key is persistent, the key material and the key's metadata + * have been saved to persistent storage. + * \retval #PSA_ERROR_ALREADY_EXISTS + * This is an attempt to create a persistent key, and there is + * already a persistent key with the given identifier. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_INSUFFICIENT_STORAGE + * \retval #PSA_ERROR_DATA_INVALID + * \retval #PSA_ERROR_DATA_CORRUPT + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_generate_key(const psa_key_attributes_t *attributes, + mbedtls_svc_key_id_t *key); + +/**@}*/ + +#ifdef __cplusplus +} +#endif + +/* The file "crypto_sizes.h" contains definitions for size calculation + * macros whose definitions are implementation-specific. */ +#include "crypto_sizes.h" + +/* The file "crypto_struct.h" contains definitions for + * implementation-specific structs that are declared above. */ +#include "crypto_struct.h" + +/* The file "crypto_extra.h" contains vendor-specific definitions. This + * can include vendor-defined algorithms, extra functions, etc. */ +#include "crypto_extra.h" + +#endif /* PSA_CRYPTO_H */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_builtin_composites.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_builtin_composites.h new file mode 100644 index 00000000000..a875b237041 --- /dev/null +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_builtin_composites.h @@ -0,0 +1,79 @@ +/* + * Context structure declaration of the Mbed TLS software-based PSA drivers + * called through the PSA Crypto driver dispatch layer. + * This file contains the context structures of those algorithms which need to + * rely on other algorithms, i.e. are 'composite' algorithms. + * + * \note This file may not be included directly. Applications must + * include psa/crypto.h. + * + * \note This header and its content is not part of the Mbed TLS API and + * applications must not depend on it. Its main purpose is to define the + * multi-part state objects of the Mbed TLS software-based PSA drivers. The + * definition of these objects are then used by crypto_struct.h to define the + * implementation-defined types of PSA multi-part state objects. + */ +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PSA_CRYPTO_BUILTIN_COMPOSITES_H +#define PSA_CRYPTO_BUILTIN_COMPOSITES_H + +#include + +/* + * MAC multi-part operation definitions. + */ +#if defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC) || \ + defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC) +#define MBEDTLS_PSA_BUILTIN_MAC +#endif + +#if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC) || defined(PSA_CRYPTO_DRIVER_TEST) +typedef struct +{ + /** The HMAC algorithm in use */ + psa_algorithm_t alg; + /** The hash context. */ + struct psa_hash_operation_s hash_ctx; + /** The HMAC part of the context. */ + uint8_t opad[PSA_HMAC_MAX_HASH_BLOCK_SIZE]; +} mbedtls_psa_hmac_operation_t; + +#define MBEDTLS_PSA_HMAC_OPERATION_INIT {0, PSA_HASH_OPERATION_INIT, {0}} +#endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC */ + +#include "mbedtls/cmac.h" + +typedef struct +{ + psa_algorithm_t alg; + union + { + unsigned dummy; /* Make the union non-empty even with no supported algorithms. */ +#if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC) || defined(PSA_CRYPTO_DRIVER_TEST) + mbedtls_psa_hmac_operation_t hmac; +#endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC */ +#if defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC) || defined(PSA_CRYPTO_DRIVER_TEST) + mbedtls_cipher_context_t cmac; +#endif /* MBEDTLS_PSA_BUILTIN_ALG_CMAC */ + } ctx; +} mbedtls_psa_mac_operation_t; + +#define MBEDTLS_PSA_MAC_OPERATION_INIT {0, {0}} + +#endif /* PSA_CRYPTO_BUILTIN_COMPOSITES_H */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_builtin_primitives.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_builtin_primitives.h new file mode 100644 index 00000000000..62a0e6f3704 --- /dev/null +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_builtin_primitives.h @@ -0,0 +1,126 @@ +/* + * Context structure declaration of the Mbed TLS software-based PSA drivers + * called through the PSA Crypto driver dispatch layer. + * This file contains the context structures of those algorithms which do not + * rely on other algorithms, i.e. are 'primitive' algorithms. + * + * \note This file may not be included directly. Applications must + * include psa/crypto.h. + * + * \note This header and its content is not part of the Mbed TLS API and + * applications must not depend on it. Its main purpose is to define the + * multi-part state objects of the Mbed TLS software-based PSA drivers. The + * definition of these objects are then used by crypto_struct.h to define the + * implementation-defined types of PSA multi-part state objects. + */ +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PSA_CRYPTO_BUILTIN_PRIMITIVES_H +#define PSA_CRYPTO_BUILTIN_PRIMITIVES_H + +#include + +/* + * Hash multi-part operation definitions. + */ + +#include "mbedtls/md2.h" +#include "mbedtls/md4.h" +#include "mbedtls/md5.h" +#include "mbedtls/ripemd160.h" +#include "mbedtls/sha1.h" +#include "mbedtls/sha256.h" +#include "mbedtls/sha512.h" + +#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD2) || \ + defined(MBEDTLS_PSA_BUILTIN_ALG_MD4) || \ + defined(MBEDTLS_PSA_BUILTIN_ALG_MD5) || \ + defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160) || \ + defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1) || \ + defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224) || \ + defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256) || \ + defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384) || \ + defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512) +#define MBEDTLS_PSA_BUILTIN_HASH +#endif + +typedef struct +{ + psa_algorithm_t alg; + union + { + unsigned dummy; /* Make the union non-empty even with no supported algorithms. */ +#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD2) + mbedtls_md2_context md2; +#endif +#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD4) + mbedtls_md4_context md4; +#endif +#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD5) + mbedtls_md5_context md5; +#endif +#if defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160) + mbedtls_ripemd160_context ripemd160; +#endif +#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1) + mbedtls_sha1_context sha1; +#endif +#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256) || \ + defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224) + mbedtls_sha256_context sha256; +#endif +#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512) || \ + defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384) + mbedtls_sha512_context sha512; +#endif + } ctx; +} mbedtls_psa_hash_operation_t; + +#define MBEDTLS_PSA_HASH_OPERATION_INIT {0, {0}} + +/* + * Cipher multi-part operation definitions. + */ + +#include "mbedtls/cipher.h" + +#if defined(MBEDTLS_PSA_BUILTIN_ALG_STREAM_CIPHER) || \ + defined(MBEDTLS_PSA_BUILTIN_ALG_CTR) || \ + defined(MBEDTLS_PSA_BUILTIN_ALG_CFB) || \ + defined(MBEDTLS_PSA_BUILTIN_ALG_OFB) || \ + defined(MBEDTLS_PSA_BUILTIN_ALG_XTS) || \ + defined(MBEDTLS_PSA_BUILTIN_ALG_ECB_NO_PADDING) || \ + defined(MBEDTLS_PSA_BUILTIN_ALG_CBC_NO_PADDING) || \ + defined(MBEDTLS_PSA_BUILTIN_ALG_CBC_PKCS7) +#define MBEDTLS_PSA_BUILTIN_CIPHER 1 +#endif + +typedef struct { + /* Context structure for the Mbed TLS cipher implementation. */ + psa_algorithm_t alg; + uint8_t iv_length; + uint8_t block_length; + union { + unsigned int dummy; + mbedtls_cipher_context_t cipher; + } ctx; +} mbedtls_psa_cipher_operation_t; + +#define MBEDTLS_PSA_CIPHER_OPERATION_INIT {0, 0, 0, {0}} + +#endif /* PSA_CRYPTO_BUILTIN_PRIMITIVES_H */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_compat.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_compat.h new file mode 100644 index 00000000000..09ac488398f --- /dev/null +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_compat.h @@ -0,0 +1,528 @@ +/** + * \file psa/crypto_compat.h + * + * \brief PSA cryptography module: Backward compatibility aliases + * + * This header declares alternative names for macro and functions. + * New application code should not use these names. + * These names may be removed in a future version of Mbed Crypto. + * + * \note This file may not be included directly. Applications must + * include psa/crypto.h. + */ +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PSA_CRYPTO_COMPAT_H +#define PSA_CRYPTO_COMPAT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * To support both openless APIs and psa_open_key() temporarily, define + * psa_key_handle_t to be equal to mbedtls_svc_key_id_t. Do not mark the + * type and its utility macros and functions deprecated yet. This will be done + * in a subsequent phase. + */ +typedef mbedtls_svc_key_id_t psa_key_handle_t; + +#define PSA_KEY_HANDLE_INIT MBEDTLS_SVC_KEY_ID_INIT + +/** Check whether an handle is null. + * + * \param handle Handle + * + * \return Non-zero if the handle is null, zero otherwise. + */ +static inline int psa_key_handle_is_null( psa_key_handle_t handle ) +{ + return( mbedtls_svc_key_id_is_null( handle ) ); +} + +#if !defined(MBEDTLS_DEPRECATED_REMOVED) + +/* + * Mechanism for declaring deprecated values + */ +#if defined(MBEDTLS_DEPRECATED_WARNING) && !defined(MBEDTLS_PSA_DEPRECATED) +#define MBEDTLS_PSA_DEPRECATED __attribute__((deprecated)) +#else +#define MBEDTLS_PSA_DEPRECATED +#endif + +typedef MBEDTLS_PSA_DEPRECATED size_t mbedtls_deprecated_size_t; +typedef MBEDTLS_PSA_DEPRECATED psa_status_t mbedtls_deprecated_psa_status_t; +typedef MBEDTLS_PSA_DEPRECATED psa_key_usage_t mbedtls_deprecated_psa_key_usage_t; +typedef MBEDTLS_PSA_DEPRECATED psa_ecc_family_t mbedtls_deprecated_psa_ecc_family_t; +typedef MBEDTLS_PSA_DEPRECATED psa_dh_family_t mbedtls_deprecated_psa_dh_family_t; +typedef MBEDTLS_PSA_DEPRECATED psa_ecc_family_t psa_ecc_curve_t; +typedef MBEDTLS_PSA_DEPRECATED psa_dh_family_t psa_dh_group_t; +typedef MBEDTLS_PSA_DEPRECATED psa_algorithm_t mbedtls_deprecated_psa_algorithm_t; + +#define PSA_KEY_TYPE_GET_CURVE PSA_KEY_TYPE_ECC_GET_FAMILY +#define PSA_KEY_TYPE_GET_GROUP PSA_KEY_TYPE_DH_GET_FAMILY + +#define MBEDTLS_DEPRECATED_CONSTANT( type, value ) \ + ( (mbedtls_deprecated_##type) ( value ) ) + +/* + * Deprecated PSA Crypto error code definitions (PSA Crypto API <= 1.0 beta2) + */ +#define PSA_ERROR_UNKNOWN_ERROR \ + MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_GENERIC_ERROR ) +#define PSA_ERROR_OCCUPIED_SLOT \ + MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_ALREADY_EXISTS ) +#define PSA_ERROR_EMPTY_SLOT \ + MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_DOES_NOT_EXIST ) +#define PSA_ERROR_INSUFFICIENT_CAPACITY \ + MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_INSUFFICIENT_DATA ) +#define PSA_ERROR_TAMPERING_DETECTED \ + MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_CORRUPTION_DETECTED ) + +/* + * Deprecated PSA Crypto numerical encodings (PSA Crypto API <= 1.0 beta3) + */ +#define PSA_KEY_USAGE_SIGN \ + MBEDTLS_DEPRECATED_CONSTANT( psa_key_usage_t, PSA_KEY_USAGE_SIGN_HASH ) +#define PSA_KEY_USAGE_VERIFY \ + MBEDTLS_DEPRECATED_CONSTANT( psa_key_usage_t, PSA_KEY_USAGE_VERIFY_HASH ) + +/* + * Deprecated PSA Crypto size calculation macros (PSA Crypto API <= 1.0 beta3) + */ +#define PSA_ASYMMETRIC_SIGNATURE_MAX_SIZE \ + MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_SIGNATURE_MAX_SIZE ) +#define PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE( key_type, key_bits, alg ) \ + MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_SIGN_OUTPUT_SIZE( key_type, key_bits, alg ) ) +#define PSA_KEY_EXPORT_MAX_SIZE( key_type, key_bits ) \ + MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_EXPORT_KEY_OUTPUT_SIZE( key_type, key_bits ) ) +#define PSA_BLOCK_CIPHER_BLOCK_SIZE( type ) \ + MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_BLOCK_CIPHER_BLOCK_LENGTH( type ) ) +#define PSA_MAX_BLOCK_CIPHER_BLOCK_SIZE \ + MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE ) +#define PSA_HASH_SIZE( alg ) \ + MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_HASH_LENGTH( alg ) ) +#define PSA_MAC_FINAL_SIZE( key_type, key_bits, alg ) \ + MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_MAC_LENGTH( key_type, key_bits, alg ) ) +#define PSA_ALG_TLS12_PSK_TO_MS_MAX_PSK_LEN \ + MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_TLS12_PSK_TO_MS_PSK_MAX_SIZE ) + +/* + * Deprecated PSA Crypto function names (PSA Crypto API <= 1.0 beta3) + */ +MBEDTLS_PSA_DEPRECATED static inline psa_status_t psa_asymmetric_sign( psa_key_handle_t key, + psa_algorithm_t alg, + const uint8_t *hash, + size_t hash_length, + uint8_t *signature, + size_t signature_size, + size_t *signature_length ) +{ + return psa_sign_hash( key, alg, hash, hash_length, signature, signature_size, signature_length ); +} + +MBEDTLS_PSA_DEPRECATED static inline psa_status_t psa_asymmetric_verify( psa_key_handle_t key, + psa_algorithm_t alg, + const uint8_t *hash, + size_t hash_length, + const uint8_t *signature, + size_t signature_length ) +{ + return psa_verify_hash( key, alg, hash, hash_length, signature, signature_length ); +} + +/* + * Size-specific elliptic curve families. + */ +#define PSA_ECC_CURVE_SECP160K1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 ) +#define PSA_ECC_CURVE_SECP192K1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 ) +#define PSA_ECC_CURVE_SECP224K1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 ) +#define PSA_ECC_CURVE_SECP256K1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 ) +#define PSA_ECC_CURVE_SECP160R1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 ) +#define PSA_ECC_CURVE_SECP192R1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 ) +#define PSA_ECC_CURVE_SECP224R1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 ) +#define PSA_ECC_CURVE_SECP256R1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 ) +#define PSA_ECC_CURVE_SECP384R1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 ) +#define PSA_ECC_CURVE_SECP521R1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 ) +#define PSA_ECC_CURVE_SECP160R2 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R2 ) +#define PSA_ECC_CURVE_SECT163K1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 ) +#define PSA_ECC_CURVE_SECT233K1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 ) +#define PSA_ECC_CURVE_SECT239K1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 ) +#define PSA_ECC_CURVE_SECT283K1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 ) +#define PSA_ECC_CURVE_SECT409K1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 ) +#define PSA_ECC_CURVE_SECT571K1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 ) +#define PSA_ECC_CURVE_SECT163R1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 ) +#define PSA_ECC_CURVE_SECT193R1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 ) +#define PSA_ECC_CURVE_SECT233R1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 ) +#define PSA_ECC_CURVE_SECT283R1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 ) +#define PSA_ECC_CURVE_SECT409R1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 ) +#define PSA_ECC_CURVE_SECT571R1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 ) +#define PSA_ECC_CURVE_SECT163R2 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R2 ) +#define PSA_ECC_CURVE_SECT193R2 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R2 ) +#define PSA_ECC_CURVE_BRAINPOOL_P256R1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1 ) +#define PSA_ECC_CURVE_BRAINPOOL_P384R1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1 ) +#define PSA_ECC_CURVE_BRAINPOOL_P512R1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1 ) +#define PSA_ECC_CURVE_CURVE25519 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_MONTGOMERY ) +#define PSA_ECC_CURVE_CURVE448 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_MONTGOMERY ) + +/* + * Curves that changed name due to PSA specification. + */ +#define PSA_ECC_CURVE_SECP_K1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 ) +#define PSA_ECC_CURVE_SECP_R1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 ) +#define PSA_ECC_CURVE_SECP_R2 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R2 ) +#define PSA_ECC_CURVE_SECT_K1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 ) +#define PSA_ECC_CURVE_SECT_R1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 ) +#define PSA_ECC_CURVE_SECT_R2 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R2 ) +#define PSA_ECC_CURVE_BRAINPOOL_P_R1 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1 ) +#define PSA_ECC_CURVE_MONTGOMERY \ + MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_MONTGOMERY ) + +/* + * Finite-field Diffie-Hellman families. + */ +#define PSA_DH_GROUP_FFDHE2048 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 ) +#define PSA_DH_GROUP_FFDHE3072 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 ) +#define PSA_DH_GROUP_FFDHE4096 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 ) +#define PSA_DH_GROUP_FFDHE6144 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 ) +#define PSA_DH_GROUP_FFDHE8192 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 ) + +/* + * Diffie-Hellman families that changed name due to PSA specification. + */ +#define PSA_DH_GROUP_RFC7919 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 ) +#define PSA_DH_GROUP_CUSTOM \ + MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_CUSTOM ) + +/* + * Deprecated PSA Crypto stream cipher algorithms (PSA Crypto API <= 1.0 beta3) + */ +#define PSA_ALG_ARC4 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_algorithm_t, PSA_ALG_STREAM_CIPHER ) +#define PSA_ALG_CHACHA20 \ + MBEDTLS_DEPRECATED_CONSTANT( psa_algorithm_t, PSA_ALG_STREAM_CIPHER ) + +/* + * Renamed AEAD tag length macros (PSA Crypto API <= 1.0 beta3) + */ +#define PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH( aead_alg ) \ + MBEDTLS_DEPRECATED_CONSTANT( psa_algorithm_t, PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG( aead_alg ) ) +#define PSA_ALG_AEAD_WITH_TAG_LENGTH( aead_alg, tag_length ) \ + MBEDTLS_DEPRECATED_CONSTANT( psa_algorithm_t, PSA_ALG_AEAD_WITH_SHORTENED_TAG( aead_alg, tag_length ) ) + +/* + * Deprecated PSA AEAD output size macros (PSA Crypto API <= 1.0 beta3) + */ + +/** The tag size for an AEAD algorithm, in bytes. + * + * \param alg An AEAD algorithm + * (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_AEAD(\p alg) is true). + * + * \return The tag size for the specified algorithm. + * If the AEAD algorithm does not have an identified + * tag that can be distinguished from the rest of + * the ciphertext, return 0. + * If the AEAD algorithm is not recognized, return 0. + */ +#define PSA_AEAD_TAG_LENGTH_1_ARG( alg ) \ + MBEDTLS_DEPRECATED_CONSTANT( size_t, \ + PSA_ALG_IS_AEAD( alg ) ? \ + PSA_ALG_AEAD_GET_TAG_LENGTH( alg ) : \ + 0 ) + +/** The maximum size of the output of psa_aead_encrypt(), in bytes. + * + * If the size of the ciphertext buffer is at least this large, it is + * guaranteed that psa_aead_encrypt() will not fail due to an + * insufficient buffer size. Depending on the algorithm, the actual size of + * the ciphertext may be smaller. + * + * \warning This macro may evaluate its arguments multiple times or + * zero times, so you should not pass arguments that contain + * side effects. + * + * \param alg An AEAD algorithm + * (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_AEAD(\p alg) is true). + * \param plaintext_length Size of the plaintext in bytes. + * + * \return The AEAD ciphertext size for the specified + * algorithm. + * If the AEAD algorithm is not recognized, return 0. + */ +#define PSA_AEAD_ENCRYPT_OUTPUT_SIZE_2_ARG( alg, plaintext_length ) \ + MBEDTLS_DEPRECATED_CONSTANT( size_t, \ + PSA_ALG_IS_AEAD( alg ) ? \ + (plaintext_length) + PSA_ALG_AEAD_GET_TAG_LENGTH( alg ) : \ + 0 ) + +/** The maximum size of the output of psa_aead_decrypt(), in bytes. + * + * If the size of the plaintext buffer is at least this large, it is + * guaranteed that psa_aead_decrypt() will not fail due to an + * insufficient buffer size. Depending on the algorithm, the actual size of + * the plaintext may be smaller. + * + * \warning This macro may evaluate its arguments multiple times or + * zero times, so you should not pass arguments that contain + * side effects. + * + * \param alg An AEAD algorithm + * (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_AEAD(\p alg) is true). + * \param ciphertext_length Size of the plaintext in bytes. + * + * \return The AEAD ciphertext size for the specified + * algorithm. + * If the AEAD algorithm is not recognized, return 0. + */ +#define PSA_AEAD_DECRYPT_OUTPUT_SIZE_2_ARG( alg, ciphertext_length ) \ + MBEDTLS_DEPRECATED_CONSTANT( size_t, \ + PSA_ALG_IS_AEAD( alg ) && \ + (ciphertext_length) > PSA_ALG_AEAD_GET_TAG_LENGTH( alg ) ? \ + (ciphertext_length) - PSA_ALG_AEAD_GET_TAG_LENGTH( alg ) : \ + 0 ) + +/** A sufficient output buffer size for psa_aead_update(). + * + * If the size of the output buffer is at least this large, it is + * guaranteed that psa_aead_update() will not fail due to an + * insufficient buffer size. The actual size of the output may be smaller + * in any given call. + * + * \warning This macro may evaluate its arguments multiple times or + * zero times, so you should not pass arguments that contain + * side effects. + * + * \param alg An AEAD algorithm + * (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_AEAD(\p alg) is true). + * \param input_length Size of the input in bytes. + * + * \return A sufficient output buffer size for the specified + * algorithm. + * If the AEAD algorithm is not recognized, return 0. + */ +/* For all the AEAD modes defined in this specification, it is possible + * to emit output without delay. However, hardware may not always be + * capable of this. So for modes based on a block cipher, allow the + * implementation to delay the output until it has a full block. */ +#define PSA_AEAD_UPDATE_OUTPUT_SIZE_2_ARG( alg, input_length ) \ + MBEDTLS_DEPRECATED_CONSTANT( size_t, \ + PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER( alg ) ? \ + PSA_ROUND_UP_TO_MULTIPLE( PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE, (input_length) ) : \ + (input_length) ) + +/** A sufficient ciphertext buffer size for psa_aead_finish(). + * + * If the size of the ciphertext buffer is at least this large, it is + * guaranteed that psa_aead_finish() will not fail due to an + * insufficient ciphertext buffer size. The actual size of the output may + * be smaller in any given call. + * + * \param alg An AEAD algorithm + * (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_AEAD(\p alg) is true). + * + * \return A sufficient ciphertext buffer size for the + * specified algorithm. + * If the AEAD algorithm is not recognized, return 0. + */ +#define PSA_AEAD_FINISH_OUTPUT_SIZE_1_ARG( alg ) \ + MBEDTLS_DEPRECATED_CONSTANT( size_t, \ + PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER( alg ) ? \ + PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE : \ + 0 ) + +/** A sufficient plaintext buffer size for psa_aead_verify(). + * + * If the size of the plaintext buffer is at least this large, it is + * guaranteed that psa_aead_verify() will not fail due to an + * insufficient plaintext buffer size. The actual size of the output may + * be smaller in any given call. + * + * \param alg An AEAD algorithm + * (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_AEAD(\p alg) is true). + * + * \return A sufficient plaintext buffer size for the + * specified algorithm. + * If the AEAD algorithm is not recognized, return 0. + */ +#define PSA_AEAD_VERIFY_OUTPUT_SIZE_1_ARG( alg ) \ + MBEDTLS_DEPRECATED_CONSTANT( size_t, \ + PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER( alg ) ? \ + PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE : \ + 0 ) + +#endif /* MBEDTLS_DEPRECATED_REMOVED */ + +/** Open a handle to an existing persistent key. + * + * Open a handle to a persistent key. A key is persistent if it was created + * with a lifetime other than #PSA_KEY_LIFETIME_VOLATILE. A persistent key + * always has a nonzero key identifier, set with psa_set_key_id() when + * creating the key. Implementations may provide additional pre-provisioned + * keys that can be opened with psa_open_key(). Such keys have an application + * key identifier in the vendor range, as documented in the description of + * #psa_key_id_t. + * + * The application must eventually close the handle with psa_close_key() or + * psa_destroy_key() to release associated resources. If the application dies + * without calling one of these functions, the implementation should perform + * the equivalent of a call to psa_close_key(). + * + * Some implementations permit an application to open the same key multiple + * times. If this is successful, each call to psa_open_key() will return a + * different key handle. + * + * \note This API is not part of the PSA Cryptography API Release 1.0.0 + * specification. It was defined in the 1.0 Beta 3 version of the + * specification but was removed in the 1.0.0 released version. This API is + * kept for the time being to not break applications relying on it. It is not + * deprecated yet but will be in the near future. + * + * \note Applications that rely on opening a key multiple times will not be + * portable to implementations that only permit a single key handle to be + * opened. See also :ref:\`key-handles\`. + * + * + * \param key The persistent identifier of the key. + * \param[out] handle On success, a handle to the key. + * + * \retval #PSA_SUCCESS + * Success. The application can now use the value of `*handle` + * to access the key. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * The implementation does not have sufficient resources to open the + * key. This can be due to reaching an implementation limit on the + * number of open keys, the number of open key handles, or available + * memory. + * \retval #PSA_ERROR_DOES_NOT_EXIST + * There is no persistent key with key identifier \p key. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \p key is not a valid persistent key identifier. + * \retval #PSA_ERROR_NOT_PERMITTED + * The specified key exists, but the application does not have the + * permission to access it. Note that this specification does not + * define any way to create such a key, but it may be possible + * through implementation-specific means. + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_DATA_INVALID + * \retval #PSA_ERROR_DATA_CORRUPT + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_open_key( mbedtls_svc_key_id_t key, + psa_key_handle_t *handle ); + +/** Close a key handle. + * + * If the handle designates a volatile key, this will destroy the key material + * and free all associated resources, just like psa_destroy_key(). + * + * If this is the last open handle to a persistent key, then closing the handle + * will free all resources associated with the key in volatile memory. The key + * data in persistent storage is not affected and can be opened again later + * with a call to psa_open_key(). + * + * Closing the key handle makes the handle invalid, and the key handle + * must not be used again by the application. + * + * \note This API is not part of the PSA Cryptography API Release 1.0.0 + * specification. It was defined in the 1.0 Beta 3 version of the + * specification but was removed in the 1.0.0 released version. This API is + * kept for the time being to not break applications relying on it. It is not + * deprecated yet but will be in the near future. + * + * \note If the key handle was used to set up an active + * :ref:\`multipart operation \`, then closing the + * key handle can cause the multipart operation to fail. Applications should + * maintain the key handle until after the multipart operation has finished. + * + * \param handle The key handle to close. + * If this is \c 0, do nothing and return \c PSA_SUCCESS. + * + * \retval #PSA_SUCCESS + * \p handle was a valid handle or \c 0. It is now closed. + * \retval #PSA_ERROR_INVALID_HANDLE + * \p handle is not a valid handle nor \c 0. + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_close_key(psa_key_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* PSA_CRYPTO_COMPAT_H */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_config.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_config.h new file mode 100644 index 00000000000..e2446cb26c4 --- /dev/null +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_config.h @@ -0,0 +1,129 @@ +/** + * \file psa/crypto_config.h + * \brief PSA crypto configuration options (set of defines) + * + */ +#if defined(MBEDTLS_PSA_CRYPTO_CONFIG) +/** + * When #MBEDTLS_PSA_CRYPTO_CONFIG is enabled in config.h, + * this file determines which cryptographic mechanisms are enabled + * through the PSA Cryptography API (\c psa_xxx() functions). + * + * To enable a cryptographic mechanism, uncomment the definition of + * the corresponding \c PSA_WANT_xxx preprocessor symbol. + * To disable a cryptographic mechanism, comment out the definition of + * the corresponding \c PSA_WANT_xxx preprocessor symbol. + * The names of cryptographic mechanisms correspond to values + * defined in psa/crypto_values.h, with the prefix \c PSA_WANT_ instead + * of \c PSA_. + * + * Note that many cryptographic mechanisms involve two symbols: one for + * the key type (\c PSA_WANT_KEY_TYPE_xxx) and one for the algorithm + * (\c PSA_WANT_ALG_xxx). Mechanisms with additional parameters may involve + * additional symbols. + */ +#else +/** + * When \c MBEDTLS_PSA_CRYPTO_CONFIG is disabled in config.h, + * this file is not used, and cryptographic mechanisms are supported + * through the PSA API if and only if they are supported through the + * mbedtls_xxx API. + */ +#endif +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PSA_CRYPTO_CONFIG_H +#define PSA_CRYPTO_CONFIG_H + +/* + * CBC-MAC is not yet supported via the PSA API in Mbed TLS. + */ +//#define PSA_WANT_ALG_CBC_MAC 1 +#define PSA_WANT_ALG_CBC_NO_PADDING 1 +#define PSA_WANT_ALG_CBC_PKCS7 1 +#define PSA_WANT_ALG_CCM 1 +#define PSA_WANT_ALG_CMAC 1 +#define PSA_WANT_ALG_CFB 1 +#define PSA_WANT_ALG_CHACHA20_POLY1305 1 +#define PSA_WANT_ALG_CMAC 1 +#define PSA_WANT_ALG_CTR 1 +#define PSA_WANT_ALG_DETERMINISTIC_ECDSA 1 +#define PSA_WANT_ALG_ECB_NO_PADDING 1 +#define PSA_WANT_ALG_ECDH 1 +#define PSA_WANT_ALG_ECDSA 1 +#define PSA_WANT_ALG_GCM 1 +#define PSA_WANT_ALG_HKDF 1 +#define PSA_WANT_ALG_HMAC 1 +#define PSA_WANT_ALG_MD2 1 +#define PSA_WANT_ALG_MD4 1 +#define PSA_WANT_ALG_MD5 1 +#define PSA_WANT_ALG_OFB 1 +#define PSA_WANT_ALG_RIPEMD160 1 +#define PSA_WANT_ALG_RSA_OAEP 1 +#define PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1 +#define PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1 +#define PSA_WANT_ALG_RSA_PSS 1 +#define PSA_WANT_ALG_SHA_1 1 +#define PSA_WANT_ALG_SHA_224 1 +#define PSA_WANT_ALG_SHA_256 1 +#define PSA_WANT_ALG_SHA_384 1 +#define PSA_WANT_ALG_SHA_512 1 +#define PSA_WANT_ALG_STREAM_CIPHER 1 +#define PSA_WANT_ALG_TLS12_PRF 1 +#define PSA_WANT_ALG_TLS12_PSK_TO_MS 1 +#define PSA_WANT_ALG_XTS 1 + +#define PSA_WANT_ECC_BRAINPOOL_P_R1_256 1 +#define PSA_WANT_ECC_BRAINPOOL_P_R1_384 1 +#define PSA_WANT_ECC_BRAINPOOL_P_R1_512 1 +#define PSA_WANT_ECC_MONTGOMERY_255 1 +/* + * Curve448 is not yet supported via the PSA API in Mbed TLS + * (https://github.com/ARMmbed/mbedtls/issues/4249). Thus, do not enable it by + * default. + */ +//#define PSA_WANT_ECC_MONTGOMERY_448 1 +#define PSA_WANT_ECC_SECP_K1_192 1 +/* + * SECP224K1 is buggy via the PSA API in Mbed TLS + * (https://github.com/ARMmbed/mbedtls/issues/3541). Thus, do not enable it by + * default. + */ +//#define PSA_WANT_ECC_SECP_K1_224 1 +#define PSA_WANT_ECC_SECP_K1_256 1 +#define PSA_WANT_ECC_SECP_R1_192 1 +#define PSA_WANT_ECC_SECP_R1_224 1 +#define PSA_WANT_ECC_SECP_R1_256 1 +#define PSA_WANT_ECC_SECP_R1_384 1 +#define PSA_WANT_ECC_SECP_R1_521 1 + +#define PSA_WANT_KEY_TYPE_DERIVE 1 +#define PSA_WANT_KEY_TYPE_HMAC 1 +#define PSA_WANT_KEY_TYPE_AES 1 +#define PSA_WANT_KEY_TYPE_ARC4 1 +#define PSA_WANT_KEY_TYPE_ARIA 1 +#define PSA_WANT_KEY_TYPE_CAMELLIA 1 +#define PSA_WANT_KEY_TYPE_CHACHA20 1 +#define PSA_WANT_KEY_TYPE_DES 1 +#define PSA_WANT_KEY_TYPE_ECC_KEY_PAIR 1 +#define PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1 +#define PSA_WANT_KEY_TYPE_RAW_DATA 1 +#define PSA_WANT_KEY_TYPE_RSA_KEY_PAIR 1 +#define PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1 + +#endif /* PSA_CRYPTO_CONFIG_H */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_driver_common.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_driver_common.h new file mode 100644 index 00000000000..26363c6b2f3 --- /dev/null +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_driver_common.h @@ -0,0 +1,56 @@ +/** + * \file psa/crypto_driver_common.h + * \brief Definitions for all PSA crypto drivers + * + * This file contains common definitions shared by all PSA crypto drivers. + * Do not include it directly: instead, include the header file(s) for + * the type(s) of driver that you are implementing. For example, if + * you are writing a dynamically registered driver for a secure element, + * include `psa/crypto_se_driver.h`. + * + * This file is part of the PSA Crypto Driver Model, containing functions for + * driver developers to implement to enable hardware to be called in a + * standardized way by a PSA Cryptographic API implementation. The functions + * comprising the driver model, which driver authors implement, are not + * intended to be called by application developers. + */ + +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef PSA_CRYPTO_DRIVER_COMMON_H +#define PSA_CRYPTO_DRIVER_COMMON_H + +#include +#include + +/* Include type definitions (psa_status_t, psa_algorithm_t, + * psa_key_type_t, etc.) and macros to build and analyze values + * of these types. */ +#include "crypto_types.h" +#include "crypto_values.h" +/* Include size definitions which are used to size some arrays in operation + * structures. */ +#include + +/** For encrypt-decrypt functions, whether the operation is an encryption + * or a decryption. */ +typedef enum { + PSA_CRYPTO_DRIVER_DECRYPT, + PSA_CRYPTO_DRIVER_ENCRYPT +} psa_encrypt_or_decrypt_t; + +#endif /* PSA_CRYPTO_DRIVER_COMMON_H */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_driver_contexts_composites.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_driver_contexts_composites.h new file mode 100644 index 00000000000..a7220091ea3 --- /dev/null +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_driver_contexts_composites.h @@ -0,0 +1,93 @@ +/* + * Declaration of context structures for use with the PSA driver wrapper + * interface. This file contains the context structures for 'composite' + * operations, i.e. those operations which need to make use of other operations + * from the primitives (crypto_driver_contexts_primitives.h) + * + * Warning: This file will be auto-generated in the future. + * + * \note This file may not be included directly. Applications must + * include psa/crypto.h. + * + * \note This header and its content is not part of the Mbed TLS API and + * applications must not depend on it. Its main purpose is to define the + * multi-part state objects of the PSA drivers included in the cryptographic + * library. The definition of these objects are then used by crypto_struct.h + * to define the implementation-defined types of PSA multi-part state objects. + */ +/* Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PSA_CRYPTO_DRIVER_CONTEXTS_COMPOSITES_H +#define PSA_CRYPTO_DRIVER_CONTEXTS_COMPOSITES_H + +#include "psa/crypto_driver_common.h" + +/* Include the context structure definitions for the Mbed TLS software drivers */ +#include "psa/crypto_builtin_composites.h" + +/* Include the context structure definitions for those drivers that were + * declared during the autogeneration process. */ + +#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) +#include +#endif + +#if defined(PSA_CRYPTO_DRIVER_TEST) +#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ + defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC) +typedef libtestdriver1_mbedtls_psa_mac_operation_t + mbedtls_transparent_test_driver_mac_operation_t; +typedef libtestdriver1_mbedtls_psa_mac_operation_t + mbedtls_opaque_test_driver_mac_operation_t; + +#define MBEDTLS_TRANSPARENT_TEST_DRIVER_MAC_OPERATION_INIT \ + LIBTESTDRIVER1_MBEDTLS_PSA_MAC_OPERATION_INIT +#define MBEDTLS_OPAQUE_TEST_DRIVER_MAC_OPERATION_INIT \ + LIBTESTDRIVER1_MBEDTLS_PSA_MAC_OPERATION_INIT + +#else +typedef mbedtls_psa_mac_operation_t + mbedtls_transparent_test_driver_mac_operation_t; +typedef mbedtls_psa_mac_operation_t + mbedtls_opaque_test_driver_mac_operation_t; + +#define MBEDTLS_TRANSPARENT_TEST_DRIVER_MAC_OPERATION_INIT \ + MBEDTLS_PSA_MAC_OPERATION_INIT +#define MBEDTLS_OPAQUE_TEST_DRIVER_MAC_OPERATION_INIT \ + MBEDTLS_PSA_MAC_OPERATION_INIT + +#endif /* MBEDTLS_TEST_LIBTESTDRIVER1 */ +#endif /* PSA_CRYPTO_DRIVER_TEST */ + +/* Define the context to be used for an operation that is executed through the + * PSA Driver wrapper layer as the union of all possible driver's contexts. + * + * The union members are the driver's context structures, and the member names + * are formatted as `'drivername'_ctx`. This allows for procedural generation + * of both this file and the content of psa_crypto_driver_wrappers.c */ + +typedef union { + unsigned dummy; /* Make sure this union is always non-empty */ + mbedtls_psa_mac_operation_t mbedtls_ctx; +#if defined(PSA_CRYPTO_DRIVER_TEST) + mbedtls_transparent_test_driver_mac_operation_t transparent_test_driver_ctx; + mbedtls_opaque_test_driver_mac_operation_t opaque_test_driver_ctx; +#endif +} psa_driver_mac_context_t; + +#endif /* PSA_CRYPTO_DRIVER_CONTEXTS_COMPOSITES_H */ +/* End of automatically generated file. */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_driver_contexts_primitives.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_driver_contexts_primitives.h new file mode 100644 index 00000000000..2bb01ed432f --- /dev/null +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_driver_contexts_primitives.h @@ -0,0 +1,117 @@ +/* + * Declaration of context structures for use with the PSA driver wrapper + * interface. This file contains the context structures for 'primitive' + * operations, i.e. those operations which do not rely on other contexts. + * + * Warning: This file will be auto-generated in the future. + * + * \note This file may not be included directly. Applications must + * include psa/crypto.h. + * + * \note This header and its content is not part of the Mbed TLS API and + * applications must not depend on it. Its main purpose is to define the + * multi-part state objects of the PSA drivers included in the cryptographic + * library. The definition of these objects are then used by crypto_struct.h + * to define the implementation-defined types of PSA multi-part state objects. + */ +/* Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PSA_CRYPTO_DRIVER_CONTEXTS_PRIMITIVES_H +#define PSA_CRYPTO_DRIVER_CONTEXTS_PRIMITIVES_H + +#include "psa/crypto_driver_common.h" + +/* Include the context structure definitions for the Mbed TLS software drivers */ +#include "psa/crypto_builtin_primitives.h" + +/* Include the context structure definitions for those drivers that were + * declared during the autogeneration process. */ + +#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) +#include +#endif + +#if defined(PSA_CRYPTO_DRIVER_TEST) + +#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ + defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER) +typedef libtestdriver1_mbedtls_psa_cipher_operation_t + mbedtls_transparent_test_driver_cipher_operation_t; + +#define MBEDTLS_TRANSPARENT_TEST_DRIVER_CIPHER_OPERATION_INIT \ + LIBTESTDRIVER1_MBEDTLS_PSA_CIPHER_OPERATION_INIT +#else +typedef mbedtls_psa_cipher_operation_t + mbedtls_transparent_test_driver_cipher_operation_t; + +#define MBEDTLS_TRANSPARENT_TEST_DRIVER_CIPHER_OPERATION_INIT \ + MBEDTLS_PSA_CIPHER_OPERATION_INIT +#endif /* MBEDTLS_TEST_LIBTESTDRIVER1 && + LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER */ + +#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ + defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH) +typedef libtestdriver1_mbedtls_psa_hash_operation_t + mbedtls_transparent_test_driver_hash_operation_t; + +#define MBEDTLS_TRANSPARENT_TEST_DRIVER_HASH_OPERATION_INIT \ + LIBTESTDRIVER1_MBEDTLS_PSA_HASH_OPERATION_INIT +#else +typedef mbedtls_psa_hash_operation_t + mbedtls_transparent_test_driver_hash_operation_t; + +#define MBEDTLS_TRANSPARENT_TEST_DRIVER_HASH_OPERATION_INIT \ + MBEDTLS_PSA_HASH_OPERATION_INIT +#endif /* MBEDTLS_TEST_LIBTESTDRIVER1 && + LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH */ + +typedef struct { + unsigned int initialised : 1; + mbedtls_transparent_test_driver_cipher_operation_t ctx; +} mbedtls_opaque_test_driver_cipher_operation_t; + +#define MBEDTLS_OPAQUE_TEST_DRIVER_CIPHER_OPERATION_INIT \ + { 0, MBEDTLS_TRANSPARENT_TEST_DRIVER_CIPHER_OPERATION_INIT } + +#endif /* PSA_CRYPTO_DRIVER_TEST */ + +/* Define the context to be used for an operation that is executed through the + * PSA Driver wrapper layer as the union of all possible driver's contexts. + * + * The union members are the driver's context structures, and the member names + * are formatted as `'drivername'_ctx`. This allows for procedural generation + * of both this file and the content of psa_crypto_driver_wrappers.c */ + +typedef union { + unsigned dummy; /* Make sure this union is always non-empty */ + mbedtls_psa_hash_operation_t mbedtls_ctx; +#if defined(PSA_CRYPTO_DRIVER_TEST) + mbedtls_transparent_test_driver_hash_operation_t test_driver_ctx; +#endif +} psa_driver_hash_context_t; + +typedef union { + unsigned dummy; /* Make sure this union is always non-empty */ + mbedtls_psa_cipher_operation_t mbedtls_ctx; +#if defined(PSA_CRYPTO_DRIVER_TEST) + mbedtls_transparent_test_driver_cipher_operation_t transparent_test_driver_ctx; + mbedtls_opaque_test_driver_cipher_operation_t opaque_test_driver_ctx; +#endif +} psa_driver_cipher_context_t; + +#endif /* PSA_CRYPTO_DRIVER_CONTEXTS_PRIMITIVES_H */ +/* End of automatically generated file. */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_extra.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_extra.h new file mode 100644 index 00000000000..3ee0482cbda --- /dev/null +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_extra.h @@ -0,0 +1,819 @@ +/** + * \file psa/crypto_extra.h + * + * \brief PSA cryptography module: Mbed TLS vendor extensions + * + * \note This file may not be included directly. Applications must + * include psa/crypto.h. + * + * This file is reserved for vendor-specific definitions. + */ +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PSA_CRYPTO_EXTRA_H +#define PSA_CRYPTO_EXTRA_H + +#include "mbedtls/platform_util.h" + +#include "crypto_types.h" +#include "crypto_compat.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* UID for secure storage seed */ +#define PSA_CRYPTO_ITS_RANDOM_SEED_UID 0xFFFFFF52 + +/* See config.h for definition */ +#if !defined(MBEDTLS_PSA_KEY_SLOT_COUNT) +#define MBEDTLS_PSA_KEY_SLOT_COUNT 32 +#endif + +/** \addtogroup attributes + * @{ + */ + +/** \brief Declare the enrollment algorithm for a key. + * + * An operation on a key may indifferently use the algorithm set with + * psa_set_key_algorithm() or with this function. + * + * \param[out] attributes The attribute structure to write to. + * \param alg2 A second algorithm that the key may be used + * for, in addition to the algorithm set with + * psa_set_key_algorithm(). + * + * \warning Setting an enrollment algorithm is not recommended, because + * using the same key with different algorithms can allow some + * attacks based on arithmetic relations between different + * computations made with the same key, or can escalate harmless + * side channels into exploitable ones. Use this function only + * if it is necessary to support a protocol for which it has been + * verified that the usage of the key with multiple algorithms + * is safe. + */ +static inline void psa_set_key_enrollment_algorithm( + psa_key_attributes_t *attributes, + psa_algorithm_t alg2) +{ + attributes->core.policy.alg2 = alg2; +} + +/** Retrieve the enrollment algorithm policy from key attributes. + * + * \param[in] attributes The key attribute structure to query. + * + * \return The enrollment algorithm stored in the attribute structure. + */ +static inline psa_algorithm_t psa_get_key_enrollment_algorithm( + const psa_key_attributes_t *attributes) +{ + return( attributes->core.policy.alg2 ); +} + +#if defined(MBEDTLS_PSA_CRYPTO_SE_C) + +/** Retrieve the slot number where a key is stored. + * + * A slot number is only defined for keys that are stored in a secure + * element. + * + * This information is only useful if the secure element is not entirely + * managed through the PSA Cryptography API. It is up to the secure + * element driver to decide how PSA slot numbers map to any other interface + * that the secure element may have. + * + * \param[in] attributes The key attribute structure to query. + * \param[out] slot_number On success, the slot number containing the key. + * + * \retval #PSA_SUCCESS + * The key is located in a secure element, and \p *slot_number + * indicates the slot number that contains it. + * \retval #PSA_ERROR_NOT_PERMITTED + * The caller is not permitted to query the slot number. + * Mbed Crypto currently does not return this error. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * The key is not located in a secure element. + */ +psa_status_t psa_get_key_slot_number( + const psa_key_attributes_t *attributes, + psa_key_slot_number_t *slot_number ); + +/** Choose the slot number where a key is stored. + * + * This function declares a slot number in the specified attribute + * structure. + * + * A slot number is only meaningful for keys that are stored in a secure + * element. It is up to the secure element driver to decide how PSA slot + * numbers map to any other interface that the secure element may have. + * + * \note Setting a slot number in key attributes for a key creation can + * cause the following errors when creating the key: + * - #PSA_ERROR_NOT_SUPPORTED if the selected secure element does + * not support choosing a specific slot number. + * - #PSA_ERROR_NOT_PERMITTED if the caller is not permitted to + * choose slot numbers in general or to choose this specific slot. + * - #PSA_ERROR_INVALID_ARGUMENT if the chosen slot number is not + * valid in general or not valid for this specific key. + * - #PSA_ERROR_ALREADY_EXISTS if there is already a key in the + * selected slot. + * + * \param[out] attributes The attribute structure to write to. + * \param slot_number The slot number to set. + */ +static inline void psa_set_key_slot_number( + psa_key_attributes_t *attributes, + psa_key_slot_number_t slot_number ) +{ + attributes->core.flags |= MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER; + attributes->slot_number = slot_number; +} + +/** Remove the slot number attribute from a key attribute structure. + * + * This function undoes the action of psa_set_key_slot_number(). + * + * \param[out] attributes The attribute structure to write to. + */ +static inline void psa_clear_key_slot_number( + psa_key_attributes_t *attributes ) +{ + attributes->core.flags &= ~MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER; +} + +/** Register a key that is already present in a secure element. + * + * The key must be located in a secure element designated by the + * lifetime field in \p attributes, in the slot set with + * psa_set_key_slot_number() in the attribute structure. + * This function makes the key available through the key identifier + * specified in \p attributes. + * + * \param[in] attributes The attributes of the existing key. + * + * \retval #PSA_SUCCESS + * The key was successfully registered. + * Note that depending on the design of the driver, this may or may + * not guarantee that a key actually exists in the designated slot + * and is compatible with the specified attributes. + * \retval #PSA_ERROR_ALREADY_EXISTS + * There is already a key with the identifier specified in + * \p attributes. + * \retval #PSA_ERROR_NOT_SUPPORTED + * The secure element driver for the specified lifetime does not + * support registering a key. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * The identifier in \p attributes is invalid, namely the identifier is + * not in the user range. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \p attributes specifies a lifetime which is not located + * in a secure element. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * No slot number is specified in \p attributes, + * or the specified slot number is not valid. + * \retval #PSA_ERROR_NOT_PERMITTED + * The caller is not authorized to register the specified key slot. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * \retval #PSA_ERROR_INSUFFICIENT_STORAGE + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_DATA_INVALID + * \retval #PSA_ERROR_DATA_CORRUPT + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t mbedtls_psa_register_se_key( + const psa_key_attributes_t *attributes); + +#endif /* MBEDTLS_PSA_CRYPTO_SE_C */ + +/**@}*/ + +/** + * \brief Library deinitialization. + * + * This function clears all data associated with the PSA layer, + * including the whole key store. + * + * This is an Mbed TLS extension. + */ +void mbedtls_psa_crypto_free( void ); + +/** \brief Statistics about + * resource consumption related to the PSA keystore. + * + * \note The content of this structure is not part of the stable API and ABI + * of Mbed Crypto and may change arbitrarily from version to version. + */ +typedef struct mbedtls_psa_stats_s +{ + /** Number of slots containing key material for a volatile key. */ + size_t volatile_slots; + /** Number of slots containing key material for a key which is in + * internal persistent storage. */ + size_t persistent_slots; + /** Number of slots containing a reference to a key in a + * secure element. */ + size_t external_slots; + /** Number of slots which are occupied, but do not contain + * key material yet. */ + size_t half_filled_slots; + /** Number of slots that contain cache data. */ + size_t cache_slots; + /** Number of slots that are not used for anything. */ + size_t empty_slots; + /** Number of slots that are locked. */ + size_t locked_slots; + /** Largest key id value among open keys in internal persistent storage. */ + psa_key_id_t max_open_internal_key_id; + /** Largest key id value among open keys in secure elements. */ + psa_key_id_t max_open_external_key_id; +} mbedtls_psa_stats_t; + +/** \brief Get statistics about + * resource consumption related to the PSA keystore. + * + * \note When Mbed Crypto is built as part of a service, with isolation + * between the application and the keystore, the service may or + * may not expose this function. + */ +void mbedtls_psa_get_stats( mbedtls_psa_stats_t *stats ); + +/** + * \brief Inject an initial entropy seed for the random generator into + * secure storage. + * + * This function injects data to be used as a seed for the random generator + * used by the PSA Crypto implementation. On devices that lack a trusted + * entropy source (preferably a hardware random number generator), + * the Mbed PSA Crypto implementation uses this value to seed its + * random generator. + * + * On devices without a trusted entropy source, this function must be + * called exactly once in the lifetime of the device. On devices with + * a trusted entropy source, calling this function is optional. + * In all cases, this function may only be called before calling any + * other function in the PSA Crypto API, including psa_crypto_init(). + * + * When this function returns successfully, it populates a file in + * persistent storage. Once the file has been created, this function + * can no longer succeed. + * + * If any error occurs, this function does not change the system state. + * You can call this function again after correcting the reason for the + * error if possible. + * + * \warning This function **can** fail! Callers MUST check the return status. + * + * \warning If you use this function, you should use it as part of a + * factory provisioning process. The value of the injected seed + * is critical to the security of the device. It must be + * *secret*, *unpredictable* and (statistically) *unique per device*. + * You should be generate it randomly using a cryptographically + * secure random generator seeded from trusted entropy sources. + * You should transmit it securely to the device and ensure + * that its value is not leaked or stored anywhere beyond the + * needs of transmitting it from the point of generation to + * the call of this function, and erase all copies of the value + * once this function returns. + * + * This is an Mbed TLS extension. + * + * \note This function is only available on the following platforms: + * * If the compile-time option MBEDTLS_PSA_INJECT_ENTROPY is enabled. + * Note that you must provide compatible implementations of + * mbedtls_nv_seed_read and mbedtls_nv_seed_write. + * * In a client-server integration of PSA Cryptography, on the client side, + * if the server supports this feature. + * \param[in] seed Buffer containing the seed value to inject. + * \param[in] seed_size Size of the \p seed buffer. + * The size of the seed in bytes must be greater + * or equal to both #MBEDTLS_ENTROPY_MIN_PLATFORM + * and #MBEDTLS_ENTROPY_BLOCK_SIZE. + * It must be less or equal to + * #MBEDTLS_ENTROPY_MAX_SEED_SIZE. + * + * \retval #PSA_SUCCESS + * The seed value was injected successfully. The random generator + * of the PSA Crypto implementation is now ready for use. + * You may now call psa_crypto_init() and use the PSA Crypto + * implementation. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \p seed_size is out of range. + * \retval #PSA_ERROR_STORAGE_FAILURE + * There was a failure reading or writing from storage. + * \retval #PSA_ERROR_NOT_PERMITTED + * The library has already been initialized. It is no longer + * possible to call this function. + */ +psa_status_t mbedtls_psa_inject_entropy(const uint8_t *seed, + size_t seed_size); + +/** \addtogroup crypto_types + * @{ + */ + +/** DSA public key. + * + * The import and export format is the + * representation of the public key `y = g^x mod p` as a big-endian byte + * string. The length of the byte string is the length of the base prime `p` + * in bytes. + */ +#define PSA_KEY_TYPE_DSA_PUBLIC_KEY ((psa_key_type_t)0x4002) + +/** DSA key pair (private and public key). + * + * The import and export format is the + * representation of the private key `x` as a big-endian byte string. The + * length of the byte string is the private key size in bytes (leading zeroes + * are not stripped). + * + * Determinstic DSA key derivation with psa_generate_derived_key follows + * FIPS 186-4 §B.1.2: interpret the byte string as integer + * in big-endian order. Discard it if it is not in the range + * [0, *N* - 2] where *N* is the boundary of the private key domain + * (the prime *p* for Diffie-Hellman, the subprime *q* for DSA, + * or the order of the curve's base point for ECC). + * Add 1 to the resulting integer and use this as the private key *x*. + * + */ +#define PSA_KEY_TYPE_DSA_KEY_PAIR ((psa_key_type_t)0x7002) + +/** Whether a key type is an DSA key (pair or public-only). */ +#define PSA_KEY_TYPE_IS_DSA(type) \ + (PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) == PSA_KEY_TYPE_DSA_PUBLIC_KEY) + +#define PSA_ALG_DSA_BASE ((psa_algorithm_t)0x06000400) +/** DSA signature with hashing. + * + * This is the signature scheme defined by FIPS 186-4, + * with a random per-message secret number (*k*). + * + * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_HASH(\p hash_alg) is true). + * This includes #PSA_ALG_ANY_HASH + * when specifying the algorithm in a usage policy. + * + * \return The corresponding DSA signature algorithm. + * \return Unspecified if \p hash_alg is not a supported + * hash algorithm. + */ +#define PSA_ALG_DSA(hash_alg) \ + (PSA_ALG_DSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK)) +#define PSA_ALG_DETERMINISTIC_DSA_BASE ((psa_algorithm_t)0x06000500) +#define PSA_ALG_DSA_DETERMINISTIC_FLAG PSA_ALG_ECDSA_DETERMINISTIC_FLAG +/** Deterministic DSA signature with hashing. + * + * This is the deterministic variant defined by RFC 6979 of + * the signature scheme defined by FIPS 186-4. + * + * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_HASH(\p hash_alg) is true). + * This includes #PSA_ALG_ANY_HASH + * when specifying the algorithm in a usage policy. + * + * \return The corresponding DSA signature algorithm. + * \return Unspecified if \p hash_alg is not a supported + * hash algorithm. + */ +#define PSA_ALG_DETERMINISTIC_DSA(hash_alg) \ + (PSA_ALG_DETERMINISTIC_DSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK)) +#define PSA_ALG_IS_DSA(alg) \ + (((alg) & ~PSA_ALG_HASH_MASK & ~PSA_ALG_DSA_DETERMINISTIC_FLAG) == \ + PSA_ALG_DSA_BASE) +#define PSA_ALG_DSA_IS_DETERMINISTIC(alg) \ + (((alg) & PSA_ALG_DSA_DETERMINISTIC_FLAG) != 0) +#define PSA_ALG_IS_DETERMINISTIC_DSA(alg) \ + (PSA_ALG_IS_DSA(alg) && PSA_ALG_DSA_IS_DETERMINISTIC(alg)) +#define PSA_ALG_IS_RANDOMIZED_DSA(alg) \ + (PSA_ALG_IS_DSA(alg) && !PSA_ALG_DSA_IS_DETERMINISTIC(alg)) + + +/* We need to expand the sample definition of this macro from + * the API definition. */ +#undef PSA_ALG_IS_VENDOR_HASH_AND_SIGN +#define PSA_ALG_IS_VENDOR_HASH_AND_SIGN(alg) \ + PSA_ALG_IS_DSA(alg) + +/**@}*/ + +/** \addtogroup attributes + * @{ + */ + +/** Custom Diffie-Hellman group. + * + * For keys of type #PSA_KEY_TYPE_DH_PUBLIC_KEY(#PSA_DH_FAMILY_CUSTOM) or + * #PSA_KEY_TYPE_DH_KEY_PAIR(#PSA_DH_FAMILY_CUSTOM), the group data comes + * from domain parameters set by psa_set_key_domain_parameters(). + */ +#define PSA_DH_FAMILY_CUSTOM ((psa_dh_family_t) 0x7e) + + +/** + * \brief Set domain parameters for a key. + * + * Some key types require additional domain parameters in addition to + * the key type identifier and the key size. Use this function instead + * of psa_set_key_type() when you need to specify domain parameters. + * + * The format for the required domain parameters varies based on the key type. + * + * - For RSA keys (#PSA_KEY_TYPE_RSA_PUBLIC_KEY or #PSA_KEY_TYPE_RSA_KEY_PAIR), + * the domain parameter data consists of the public exponent, + * represented as a big-endian integer with no leading zeros. + * This information is used when generating an RSA key pair. + * When importing a key, the public exponent is read from the imported + * key data and the exponent recorded in the attribute structure is ignored. + * As an exception, the public exponent 65537 is represented by an empty + * byte string. + * - For DSA keys (#PSA_KEY_TYPE_DSA_PUBLIC_KEY or #PSA_KEY_TYPE_DSA_KEY_PAIR), + * the `Dss-Parms` format as defined by RFC 3279 §2.3.2. + * ``` + * Dss-Parms ::= SEQUENCE { + * p INTEGER, + * q INTEGER, + * g INTEGER + * } + * ``` + * - For Diffie-Hellman key exchange keys + * (#PSA_KEY_TYPE_DH_PUBLIC_KEY(#PSA_DH_FAMILY_CUSTOM) or + * #PSA_KEY_TYPE_DH_KEY_PAIR(#PSA_DH_FAMILY_CUSTOM)), the + * `DomainParameters` format as defined by RFC 3279 §2.3.3. + * ``` + * DomainParameters ::= SEQUENCE { + * p INTEGER, -- odd prime, p=jq +1 + * g INTEGER, -- generator, g + * q INTEGER, -- factor of p-1 + * j INTEGER OPTIONAL, -- subgroup factor + * validationParms ValidationParms OPTIONAL + * } + * ValidationParms ::= SEQUENCE { + * seed BIT STRING, + * pgenCounter INTEGER + * } + * ``` + * + * \note This function may allocate memory or other resources. + * Once you have called this function on an attribute structure, + * you must call psa_reset_key_attributes() to free these resources. + * + * \note This is an experimental extension to the interface. It may change + * in future versions of the library. + * + * \param[in,out] attributes Attribute structure where the specified domain + * parameters will be stored. + * If this function fails, the content of + * \p attributes is not modified. + * \param type Key type (a \c PSA_KEY_TYPE_XXX value). + * \param[in] data Buffer containing the key domain parameters. + * The content of this buffer is interpreted + * according to \p type as described above. + * \param data_length Size of the \p data buffer in bytes. + * + * \retval #PSA_SUCCESS + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \retval #PSA_ERROR_NOT_SUPPORTED + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + */ +psa_status_t psa_set_key_domain_parameters(psa_key_attributes_t *attributes, + psa_key_type_t type, + const uint8_t *data, + size_t data_length); + +/** + * \brief Get domain parameters for a key. + * + * Get the domain parameters for a key with this function, if any. The format + * of the domain parameters written to \p data is specified in the + * documentation for psa_set_key_domain_parameters(). + * + * \note This is an experimental extension to the interface. It may change + * in future versions of the library. + * + * \param[in] attributes The key attribute structure to query. + * \param[out] data On success, the key domain parameters. + * \param data_size Size of the \p data buffer in bytes. + * The buffer is guaranteed to be large + * enough if its size in bytes is at least + * the value given by + * PSA_KEY_DOMAIN_PARAMETERS_SIZE(). + * \param[out] data_length On success, the number of bytes + * that make up the key domain parameters data. + * + * \retval #PSA_SUCCESS + * \retval #PSA_ERROR_BUFFER_TOO_SMALL + */ +psa_status_t psa_get_key_domain_parameters( + const psa_key_attributes_t *attributes, + uint8_t *data, + size_t data_size, + size_t *data_length); + +/** Safe output buffer size for psa_get_key_domain_parameters(). + * + * This macro returns a compile-time constant if its arguments are + * compile-time constants. + * + * \warning This function may call its arguments multiple times or + * zero times, so you should not pass arguments that contain + * side effects. + * + * \note This is an experimental extension to the interface. It may change + * in future versions of the library. + * + * \param key_type A supported key type. + * \param key_bits The size of the key in bits. + * + * \return If the parameters are valid and supported, return + * a buffer size in bytes that guarantees that + * psa_get_key_domain_parameters() will not fail with + * #PSA_ERROR_BUFFER_TOO_SMALL. + * If the parameters are a valid combination that is not supported + * by the implementation, this macro shall return either a + * sensible size or 0. + * If the parameters are not valid, the + * return value is unspecified. + */ +#define PSA_KEY_DOMAIN_PARAMETERS_SIZE(key_type, key_bits) \ + (PSA_KEY_TYPE_IS_RSA(key_type) ? sizeof(int) : \ + PSA_KEY_TYPE_IS_DH(key_type) ? PSA_DH_KEY_DOMAIN_PARAMETERS_SIZE(key_bits) : \ + PSA_KEY_TYPE_IS_DSA(key_type) ? PSA_DSA_KEY_DOMAIN_PARAMETERS_SIZE(key_bits) : \ + 0) +#define PSA_DH_KEY_DOMAIN_PARAMETERS_SIZE(key_bits) \ + (4 + (PSA_BITS_TO_BYTES(key_bits) + 5) * 3 /*without optional parts*/) +#define PSA_DSA_KEY_DOMAIN_PARAMETERS_SIZE(key_bits) \ + (4 + (PSA_BITS_TO_BYTES(key_bits) + 5) * 2 /*p, g*/ + 34 /*q*/) + +/**@}*/ + +/** \defgroup psa_tls_helpers TLS helper functions + * @{ + */ + +#if defined(MBEDTLS_ECP_C) +#include + +/** Convert an ECC curve identifier from the Mbed TLS encoding to PSA. + * + * \note This function is provided solely for the convenience of + * Mbed TLS and may be removed at any time without notice. + * + * \param grpid An Mbed TLS elliptic curve identifier + * (`MBEDTLS_ECP_DP_xxx`). + * \param[out] bits On success, the bit size of the curve. + * + * \return The corresponding PSA elliptic curve identifier + * (`PSA_ECC_FAMILY_xxx`). + * \return \c 0 on failure (\p grpid is not recognized). + */ +static inline psa_ecc_family_t mbedtls_ecc_group_to_psa( mbedtls_ecp_group_id grpid, + size_t *bits ) +{ + switch( grpid ) + { + case MBEDTLS_ECP_DP_SECP192R1: + *bits = 192; + return( PSA_ECC_FAMILY_SECP_R1 ); + case MBEDTLS_ECP_DP_SECP224R1: + *bits = 224; + return( PSA_ECC_FAMILY_SECP_R1 ); + case MBEDTLS_ECP_DP_SECP256R1: + *bits = 256; + return( PSA_ECC_FAMILY_SECP_R1 ); + case MBEDTLS_ECP_DP_SECP384R1: + *bits = 384; + return( PSA_ECC_FAMILY_SECP_R1 ); + case MBEDTLS_ECP_DP_SECP521R1: + *bits = 521; + return( PSA_ECC_FAMILY_SECP_R1 ); + case MBEDTLS_ECP_DP_BP256R1: + *bits = 256; + return( PSA_ECC_FAMILY_BRAINPOOL_P_R1 ); + case MBEDTLS_ECP_DP_BP384R1: + *bits = 384; + return( PSA_ECC_FAMILY_BRAINPOOL_P_R1 ); + case MBEDTLS_ECP_DP_BP512R1: + *bits = 512; + return( PSA_ECC_FAMILY_BRAINPOOL_P_R1 ); + case MBEDTLS_ECP_DP_CURVE25519: + *bits = 255; + return( PSA_ECC_FAMILY_MONTGOMERY ); + case MBEDTLS_ECP_DP_SECP192K1: + *bits = 192; + return( PSA_ECC_FAMILY_SECP_K1 ); + case MBEDTLS_ECP_DP_SECP224K1: + *bits = 224; + return( PSA_ECC_FAMILY_SECP_K1 ); + case MBEDTLS_ECP_DP_SECP256K1: + *bits = 256; + return( PSA_ECC_FAMILY_SECP_K1 ); + case MBEDTLS_ECP_DP_CURVE448: + *bits = 448; + return( PSA_ECC_FAMILY_MONTGOMERY ); + default: + *bits = 0; + return( 0 ); + } +} + +/** Convert an ECC curve identifier from the PSA encoding to Mbed TLS. + * + * \note This function is provided solely for the convenience of + * Mbed TLS and may be removed at any time without notice. + * + * \param curve A PSA elliptic curve identifier + * (`PSA_ECC_FAMILY_xxx`). + * \param bits The bit-length of a private key on \p curve. + * \param bits_is_sloppy If true, \p bits may be the bit-length rounded up + * to the nearest multiple of 8. This allows the caller + * to infer the exact curve from the length of a key + * which is supplied as a byte string. + * + * \return The corresponding Mbed TLS elliptic curve identifier + * (`MBEDTLS_ECP_DP_xxx`). + * \return #MBEDTLS_ECP_DP_NONE if \c curve is not recognized. + * \return #MBEDTLS_ECP_DP_NONE if \p bits is not + * correct for \p curve. + */ +mbedtls_ecp_group_id mbedtls_ecc_group_of_psa( psa_ecc_family_t curve, + size_t bits, + int bits_is_sloppy ); +#endif /* MBEDTLS_ECP_C */ + +/**@}*/ + +/** \defgroup psa_external_rng External random generator + * @{ + */ + +#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) +/** External random generator function, implemented by the platform. + * + * When the compile-time option #MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG is enabled, + * this function replaces Mbed TLS's entropy and DRBG modules for all + * random generation triggered via PSA crypto interfaces. + * + * \note This random generator must deliver random numbers with cryptographic + * quality and high performance. It must supply unpredictable numbers + * with a uniform distribution. The implementation of this function + * is responsible for ensuring that the random generator is seeded + * with sufficient entropy. If you have a hardware TRNG which is slow + * or delivers non-uniform output, declare it as an entropy source + * with mbedtls_entropy_add_source() instead of enabling this option. + * + * \param[in,out] context Pointer to the random generator context. + * This is all-bits-zero on the first call + * and preserved between successive calls. + * \param[out] output Output buffer. On success, this buffer + * contains random data with a uniform + * distribution. + * \param output_size The size of the \p output buffer in bytes. + * \param[out] output_length On success, set this value to \p output_size. + * + * \retval #PSA_SUCCESS + * Success. The output buffer contains \p output_size bytes of + * cryptographic-quality random data, and \c *output_length is + * set to \p output_size. + * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY + * The random generator requires extra entropy and there is no + * way to obtain entropy under current environment conditions. + * This error should not happen under normal circumstances since + * this function is responsible for obtaining as much entropy as + * it needs. However implementations of this function may return + * #PSA_ERROR_INSUFFICIENT_ENTROPY if there is no way to obtain + * entropy without blocking indefinitely. + * \retval #PSA_ERROR_HARDWARE_FAILURE + * A failure of the random generator hardware that isn't covered + * by #PSA_ERROR_INSUFFICIENT_ENTROPY. + */ +psa_status_t mbedtls_psa_external_get_random( + mbedtls_psa_external_random_context_t *context, + uint8_t *output, size_t output_size, size_t *output_length ); +#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */ + +/**@}*/ + +/** \defgroup psa_builtin_keys Built-in keys + * @{ + */ + +/** The minimum value for a key identifier that is built into the + * implementation. + * + * The range of key identifiers from #MBEDTLS_PSA_KEY_ID_BUILTIN_MIN + * to #MBEDTLS_PSA_KEY_ID_BUILTIN_MAX within the range from + * #PSA_KEY_ID_VENDOR_MIN and #PSA_KEY_ID_VENDOR_MAX and must not intersect + * with any other set of implementation-chosen key identifiers. + * + * This value is part of the library's ABI since changing it would invalidate + * the values of built-in key identifiers in applications. + */ +#define MBEDTLS_PSA_KEY_ID_BUILTIN_MIN ((psa_key_id_t)0x7fff0000) + +/** The maximum value for a key identifier that is built into the + * implementation. + * + * See #MBEDTLS_PSA_KEY_ID_BUILTIN_MIN for more information. + */ +#define MBEDTLS_PSA_KEY_ID_BUILTIN_MAX ((psa_key_id_t)0x7fffefff) + +/** A slot number identifying a key in a driver. + * + * Values of this type are used to identify built-in keys. + */ +typedef uint64_t psa_drv_slot_number_t; + +#if defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS) +/** Test whether a key identifier belongs to the builtin key range. + * + * \param key_id Key identifier to test. + * + * \retval 1 + * The key identifier is a builtin key identifier. + * \retval 0 + * The key identifier is not a builtin key identifier. + */ +static inline int psa_key_id_is_builtin( psa_key_id_t key_id ) +{ + return( ( key_id >= MBEDTLS_PSA_KEY_ID_BUILTIN_MIN ) && + ( key_id <= MBEDTLS_PSA_KEY_ID_BUILTIN_MAX ) ); +} + +/** Platform function to obtain the location and slot number of a built-in key. + * + * An application-specific implementation of this function must be provided if + * #MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS is enabled. This would typically be provided + * as part of a platform's system image. + * + * #MBEDTLS_SVC_KEY_ID_GET_KEY_ID(\p key_id) needs to be in the range from + * #MBEDTLS_PSA_KEY_ID_BUILTIN_MIN to #MBEDTLS_PSA_KEY_ID_BUILTIN_MAX. + * + * In a multi-application configuration + * (\c MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER is defined), + * this function should check that #MBEDTLS_SVC_KEY_ID_GET_OWNER_ID(\p key_id) + * is allowed to use the given key. + * + * \param key_id The key ID for which to retrieve the + * location and slot attributes. + * \param[out] lifetime On success, the lifetime associated with the key + * corresponding to \p key_id. Lifetime is a + * combination of which driver contains the key, + * and with what persistence level the key is + * intended to be used. If the platform + * implementation does not contain specific + * information about the intended key persistence + * level, the persistence level may be reported as + * #PSA_KEY_PERSISTENCE_DEFAULT. + * \param[out] slot_number On success, the slot number known to the driver + * registered at the lifetime location reported + * through \p lifetime which corresponds to the + * requested built-in key. + * + * \retval #PSA_SUCCESS + * The requested key identifier designates a built-in key. + * In a multi-application configuration, the requested owner + * is allowed to access it. + * \retval #PSA_ERROR_DOES_NOT_EXIST + * The requested key identifier is not a built-in key which is known + * to this function. If a key exists in the key storage with this + * identifier, the data from the storage will be used. + * \return (any other error) + * Any other error is propagated to the function that requested the key. + * Common errors include: + * - #PSA_ERROR_NOT_PERMITTED: the key exists but the requested owner + * is not allowed to access it. + */ +psa_status_t mbedtls_psa_platform_get_builtin_key( + mbedtls_svc_key_id_t key_id, + psa_key_lifetime_t *lifetime, + psa_drv_slot_number_t *slot_number ); +#endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */ + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* PSA_CRYPTO_EXTRA_H */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_platform.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_platform.h new file mode 100644 index 00000000000..66f46879305 --- /dev/null +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_platform.h @@ -0,0 +1,111 @@ +/** + * \file psa/crypto_platform.h + * + * \brief PSA cryptography module: Mbed TLS platform definitions + * + * \note This file may not be included directly. Applications must + * include psa/crypto.h. + * + * This file contains platform-dependent type definitions. + * + * In implementations with isolation between the application and the + * cryptography module, implementers should take care to ensure that + * the definitions that are exposed to applications match what the + * module implements. + */ +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PSA_CRYPTO_PLATFORM_H +#define PSA_CRYPTO_PLATFORM_H + +/* Include the Mbed TLS configuration file, the way Mbed TLS does it + * in each of its header files. */ +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls/config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +/* Translate between classic MBEDTLS_xxx feature symbols and PSA_xxx + * feature symbols. */ +#include "mbedtls/config_psa.h" + +/* PSA requires several types which C99 provides in stdint.h. */ +#include + +#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ + !defined(inline) && !defined(__cplusplus) +#define inline __inline +#endif + +#if defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER) + +/* Building for the PSA Crypto service on a PSA platform, a key owner is a PSA + * partition identifier. + * + * The function psa_its_identifier_of_slot() in psa_crypto_storage.c that + * translates a key identifier to a key storage file name assumes that + * mbedtls_key_owner_id_t is an 32 bits integer. This function thus needs + * reworking if mbedtls_key_owner_id_t is not defined as a 32 bits integer + * here anymore. + */ +typedef int32_t mbedtls_key_owner_id_t; + +/** Compare two key owner identifiers. + * + * \param id1 First key owner identifier. + * \param id2 Second key owner identifier. + * + * \return Non-zero if the two key owner identifiers are equal, zero otherwise. + */ +static inline int mbedtls_key_owner_id_equal( mbedtls_key_owner_id_t id1, + mbedtls_key_owner_id_t id2 ) +{ + return( id1 == id2 ); +} + +#endif /* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */ + +/* + * When MBEDTLS_PSA_CRYPTO_SPM is defined, the code is being built for SPM + * (Secure Partition Manager) integration which separates the code into two + * parts: NSPE (Non-Secure Processing Environment) and SPE (Secure Processing + * Environment). When building for the SPE, an additional header file should be + * included. + */ +#if defined(MBEDTLS_PSA_CRYPTO_SPM) +#define PSA_CRYPTO_SECURE 1 +#include "crypto_spe.h" +#endif // MBEDTLS_PSA_CRYPTO_SPM + +#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) +/** The type of the context passed to mbedtls_psa_external_get_random(). + * + * Mbed TLS initializes the context to all-bits-zero before calling + * mbedtls_psa_external_get_random() for the first time. + * + * The definition of this type in the Mbed TLS source code is for + * demonstration purposes. Implementers of mbedtls_psa_external_get_random() + * are expected to replace it with a custom definition. + */ +typedef struct { + uintptr_t opaque[2]; +} mbedtls_psa_external_random_context_t; +#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */ + +#endif /* PSA_CRYPTO_PLATFORM_H */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_se_driver.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_se_driver.h new file mode 100644 index 00000000000..1dc8f9b5c40 --- /dev/null +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_se_driver.h @@ -0,0 +1,1395 @@ +/** + * \file psa/crypto_se_driver.h + * \brief PSA external cryptoprocessor driver module + * + * This header declares types and function signatures for cryptography + * drivers that access key material via opaque references. + * This is meant for cryptoprocessors that have a separate key storage from the + * space in which the PSA Crypto implementation runs, typically secure + * elements (SEs). + * + * This file is part of the PSA Crypto Driver HAL (hardware abstraction layer), + * containing functions for driver developers to implement to enable hardware + * to be called in a standardized way by a PSA Cryptography API + * implementation. The functions comprising the driver HAL, which driver + * authors implement, are not intended to be called by application developers. + */ + +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef PSA_CRYPTO_SE_DRIVER_H +#define PSA_CRYPTO_SE_DRIVER_H + +#include "crypto_driver_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** \defgroup se_init Secure element driver initialization + */ +/**@{*/ + +/** \brief Driver context structure + * + * Driver functions receive a pointer to this structure. + * Each registered driver has one instance of this structure. + * + * Implementations must include the fields specified here and + * may include other fields. + */ +typedef struct { + /** A read-only pointer to the driver's persistent data. + * + * Drivers typically use this persistent data to keep track of + * which slot numbers are available. This is only a guideline: + * drivers may use the persistent data for any purpose, keeping + * in mind the restrictions on when the persistent data is saved + * to storage: the persistent data is only saved after calling + * certain functions that receive a writable pointer to the + * persistent data. + * + * The core allocates a memory buffer for the persistent data. + * The pointer is guaranteed to be suitably aligned for any data type, + * like a pointer returned by `malloc` (but the core can use any + * method to allocate the buffer, not necessarily `malloc`). + * + * The size of this buffer is in the \c persistent_data_size field of + * this structure. + * + * Before the driver is initialized for the first time, the content of + * the persistent data is all-bits-zero. After a driver upgrade, if the + * size of the persistent data has increased, the original data is padded + * on the right with zeros; if the size has decreased, the original data + * is truncated to the new size. + * + * This pointer is to read-only data. Only a few driver functions are + * allowed to modify the persistent data. These functions receive a + * writable pointer. These functions are: + * - psa_drv_se_t::p_init + * - psa_drv_se_key_management_t::p_allocate + * - psa_drv_se_key_management_t::p_destroy + * + * The PSA Cryptography core saves the persistent data from one + * session to the next. It does this before returning from API functions + * that call a driver method that is allowed to modify the persistent + * data, specifically: + * - psa_crypto_init() causes a call to psa_drv_se_t::p_init, and may call + * psa_drv_se_key_management_t::p_destroy to complete an action + * that was interrupted by a power failure. + * - Key creation functions cause a call to + * psa_drv_se_key_management_t::p_allocate, and may cause a call to + * psa_drv_se_key_management_t::p_destroy in case an error occurs. + * - psa_destroy_key() causes a call to + * psa_drv_se_key_management_t::p_destroy. + */ + const void *const persistent_data; + + /** The size of \c persistent_data in bytes. + * + * This is always equal to the value of the `persistent_data_size` field + * of the ::psa_drv_se_t structure when the driver is registered. + */ + const size_t persistent_data_size; + + /** Driver transient data. + * + * The core initializes this value to 0 and does not read or modify it + * afterwards. The driver may store whatever it wants in this field. + */ + uintptr_t transient_data; +} psa_drv_se_context_t; + +/** \brief A driver initialization function. + * + * \param[in,out] drv_context The driver context structure. + * \param[in,out] persistent_data A pointer to the persistent data + * that allows writing. + * \param location The location value for which this driver + * is registered. The driver will be invoked + * for all keys whose lifetime is in this + * location. + * + * \retval #PSA_SUCCESS + * The driver is operational. + * The core will update the persistent data in storage. + * \return + * Any other return value prevents the driver from being used in + * this session. + * The core will NOT update the persistent data in storage. + */ +typedef psa_status_t (*psa_drv_se_init_t)(psa_drv_se_context_t *drv_context, + void *persistent_data, + psa_key_location_t location); + +#if defined(__DOXYGEN_ONLY__) || !defined(MBEDTLS_PSA_CRYPTO_SE_C) +/* Mbed Crypto with secure element support enabled defines this type in + * crypto_types.h because it is also visible to applications through an + * implementation-specific extension. + * For the PSA Cryptography specification, this type is only visible + * via crypto_se_driver.h. */ +/** An internal designation of a key slot between the core part of the + * PSA Crypto implementation and the driver. The meaning of this value + * is driver-dependent. */ +typedef uint64_t psa_key_slot_number_t; +#endif /* __DOXYGEN_ONLY__ || !MBEDTLS_PSA_CRYPTO_SE_C */ + +/**@}*/ + +/** \defgroup se_mac Secure Element Message Authentication Codes + * Generation and authentication of Message Authentication Codes (MACs) using + * a secure element can be done either as a single function call (via the + * `psa_drv_se_mac_generate_t` or `psa_drv_se_mac_verify_t` functions), or in + * parts using the following sequence: + * - `psa_drv_se_mac_setup_t` + * - `psa_drv_se_mac_update_t` + * - `psa_drv_se_mac_update_t` + * - ... + * - `psa_drv_se_mac_finish_t` or `psa_drv_se_mac_finish_verify_t` + * + * If a previously started secure element MAC operation needs to be terminated, + * it should be done so by the `psa_drv_se_mac_abort_t`. Failure to do so may + * result in allocated resources not being freed or in other undefined + * behavior. + */ +/**@{*/ +/** \brief A function that starts a secure element MAC operation for a PSA + * Crypto Driver implementation + * + * \param[in,out] drv_context The driver context structure. + * \param[in,out] op_context A structure that will contain the + * hardware-specific MAC context + * \param[in] key_slot The slot of the key to be used for the + * operation + * \param[in] algorithm The algorithm to be used to underly the MAC + * operation + * + * \retval #PSA_SUCCESS + * Success. + */ +typedef psa_status_t (*psa_drv_se_mac_setup_t)(psa_drv_se_context_t *drv_context, + void *op_context, + psa_key_slot_number_t key_slot, + psa_algorithm_t algorithm); + +/** \brief A function that continues a previously started secure element MAC + * operation + * + * \param[in,out] op_context A hardware-specific structure for the + * previously-established MAC operation to be + * updated + * \param[in] p_input A buffer containing the message to be appended + * to the MAC operation + * \param[in] input_length The size in bytes of the input message buffer + */ +typedef psa_status_t (*psa_drv_se_mac_update_t)(void *op_context, + const uint8_t *p_input, + size_t input_length); + +/** \brief a function that completes a previously started secure element MAC + * operation by returning the resulting MAC. + * + * \param[in,out] op_context A hardware-specific structure for the + * previously started MAC operation to be + * finished + * \param[out] p_mac A buffer where the generated MAC will be + * placed + * \param[in] mac_size The size in bytes of the buffer that has been + * allocated for the `output` buffer + * \param[out] p_mac_length After completion, will contain the number of + * bytes placed in the `p_mac` buffer + * + * \retval #PSA_SUCCESS + * Success. + */ +typedef psa_status_t (*psa_drv_se_mac_finish_t)(void *op_context, + uint8_t *p_mac, + size_t mac_size, + size_t *p_mac_length); + +/** \brief A function that completes a previously started secure element MAC + * operation by comparing the resulting MAC against a provided value + * + * \param[in,out] op_context A hardware-specific structure for the previously + * started MAC operation to be fiinished + * \param[in] p_mac The MAC value against which the resulting MAC + * will be compared against + * \param[in] mac_length The size in bytes of the value stored in `p_mac` + * + * \retval #PSA_SUCCESS + * The operation completed successfully and the MACs matched each + * other + * \retval #PSA_ERROR_INVALID_SIGNATURE + * The operation completed successfully, but the calculated MAC did + * not match the provided MAC + */ +typedef psa_status_t (*psa_drv_se_mac_finish_verify_t)(void *op_context, + const uint8_t *p_mac, + size_t mac_length); + +/** \brief A function that aborts a previous started secure element MAC + * operation + * + * \param[in,out] op_context A hardware-specific structure for the previously + * started MAC operation to be aborted + */ +typedef psa_status_t (*psa_drv_se_mac_abort_t)(void *op_context); + +/** \brief A function that performs a secure element MAC operation in one + * command and returns the calculated MAC + * + * \param[in,out] drv_context The driver context structure. + * \param[in] p_input A buffer containing the message to be MACed + * \param[in] input_length The size in bytes of `p_input` + * \param[in] key_slot The slot of the key to be used + * \param[in] alg The algorithm to be used to underlie the MAC + * operation + * \param[out] p_mac A buffer where the generated MAC will be + * placed + * \param[in] mac_size The size in bytes of the `p_mac` buffer + * \param[out] p_mac_length After completion, will contain the number of + * bytes placed in the `output` buffer + * + * \retval #PSA_SUCCESS + * Success. + */ +typedef psa_status_t (*psa_drv_se_mac_generate_t)(psa_drv_se_context_t *drv_context, + const uint8_t *p_input, + size_t input_length, + psa_key_slot_number_t key_slot, + psa_algorithm_t alg, + uint8_t *p_mac, + size_t mac_size, + size_t *p_mac_length); + +/** \brief A function that performs a secure element MAC operation in one + * command and compares the resulting MAC against a provided value + * + * \param[in,out] drv_context The driver context structure. + * \param[in] p_input A buffer containing the message to be MACed + * \param[in] input_length The size in bytes of `input` + * \param[in] key_slot The slot of the key to be used + * \param[in] alg The algorithm to be used to underlie the MAC + * operation + * \param[in] p_mac The MAC value against which the resulting MAC will + * be compared against + * \param[in] mac_length The size in bytes of `mac` + * + * \retval #PSA_SUCCESS + * The operation completed successfully and the MACs matched each + * other + * \retval #PSA_ERROR_INVALID_SIGNATURE + * The operation completed successfully, but the calculated MAC did + * not match the provided MAC + */ +typedef psa_status_t (*psa_drv_se_mac_verify_t)(psa_drv_se_context_t *drv_context, + const uint8_t *p_input, + size_t input_length, + psa_key_slot_number_t key_slot, + psa_algorithm_t alg, + const uint8_t *p_mac, + size_t mac_length); + +/** \brief A struct containing all of the function pointers needed to + * perform secure element MAC operations + * + * PSA Crypto API implementations should populate the table as appropriate + * upon startup. + * + * If one of the functions is not implemented (such as + * `psa_drv_se_mac_generate_t`), it should be set to NULL. + * + * Driver implementers should ensure that they implement all of the functions + * that make sense for their hardware, and that they provide a full solution + * (for example, if they support `p_setup`, they should also support + * `p_update` and at least one of `p_finish` or `p_finish_verify`). + * + */ +typedef struct { + /**The size in bytes of the hardware-specific secure element MAC context + * structure + */ + size_t context_size; + /** Function that performs a MAC setup operation + */ + psa_drv_se_mac_setup_t p_setup; + /** Function that performs a MAC update operation + */ + psa_drv_se_mac_update_t p_update; + /** Function that completes a MAC operation + */ + psa_drv_se_mac_finish_t p_finish; + /** Function that completes a MAC operation with a verify check + */ + psa_drv_se_mac_finish_verify_t p_finish_verify; + /** Function that aborts a previoustly started MAC operation + */ + psa_drv_se_mac_abort_t p_abort; + /** Function that performs a MAC operation in one call + */ + psa_drv_se_mac_generate_t p_mac; + /** Function that performs a MAC and verify operation in one call + */ + psa_drv_se_mac_verify_t p_mac_verify; +} psa_drv_se_mac_t; +/**@}*/ + +/** \defgroup se_cipher Secure Element Symmetric Ciphers + * + * Encryption and Decryption using secure element keys in block modes other + * than ECB must be done in multiple parts, using the following flow: + * - `psa_drv_se_cipher_setup_t` + * - `psa_drv_se_cipher_set_iv_t` (optional depending upon block mode) + * - `psa_drv_se_cipher_update_t` + * - `psa_drv_se_cipher_update_t` + * - ... + * - `psa_drv_se_cipher_finish_t` + * + * If a previously started secure element Cipher operation needs to be + * terminated, it should be done so by the `psa_drv_se_cipher_abort_t`. Failure + * to do so may result in allocated resources not being freed or in other + * undefined behavior. + * + * In situations where a PSA Cryptographic API implementation is using a block + * mode not-supported by the underlying hardware or driver, it can construct + * the block mode itself, while calling the `psa_drv_se_cipher_ecb_t` function + * for the cipher operations. + */ +/**@{*/ + +/** \brief A function that provides the cipher setup function for a + * secure element driver + * + * \param[in,out] drv_context The driver context structure. + * \param[in,out] op_context A structure that will contain the + * hardware-specific cipher context. + * \param[in] key_slot The slot of the key to be used for the + * operation + * \param[in] algorithm The algorithm to be used in the cipher + * operation + * \param[in] direction Indicates whether the operation is an encrypt + * or decrypt + * + * \retval #PSA_SUCCESS + * \retval #PSA_ERROR_NOT_SUPPORTED + */ +typedef psa_status_t (*psa_drv_se_cipher_setup_t)(psa_drv_se_context_t *drv_context, + void *op_context, + psa_key_slot_number_t key_slot, + psa_algorithm_t algorithm, + psa_encrypt_or_decrypt_t direction); + +/** \brief A function that sets the initialization vector (if + * necessary) for an secure element cipher operation + * + * Rationale: The `psa_se_cipher_*` operation in the PSA Cryptographic API has + * two IV functions: one to set the IV, and one to generate it internally. The + * generate function is not necessary for the drivers to implement as the PSA + * Crypto implementation can do the generation using its RNG features. + * + * \param[in,out] op_context A structure that contains the previously set up + * hardware-specific cipher context + * \param[in] p_iv A buffer containing the initialization vector + * \param[in] iv_length The size (in bytes) of the `p_iv` buffer + * + * \retval #PSA_SUCCESS + */ +typedef psa_status_t (*psa_drv_se_cipher_set_iv_t)(void *op_context, + const uint8_t *p_iv, + size_t iv_length); + +/** \brief A function that continues a previously started secure element cipher + * operation + * + * \param[in,out] op_context A hardware-specific structure for the + * previously started cipher operation + * \param[in] p_input A buffer containing the data to be + * encrypted/decrypted + * \param[in] input_size The size in bytes of the buffer pointed to + * by `p_input` + * \param[out] p_output The caller-allocated buffer where the + * output will be placed + * \param[in] output_size The allocated size in bytes of the + * `p_output` buffer + * \param[out] p_output_length After completion, will contain the number + * of bytes placed in the `p_output` buffer + * + * \retval #PSA_SUCCESS + */ +typedef psa_status_t (*psa_drv_se_cipher_update_t)(void *op_context, + const uint8_t *p_input, + size_t input_size, + uint8_t *p_output, + size_t output_size, + size_t *p_output_length); + +/** \brief A function that completes a previously started secure element cipher + * operation + * + * \param[in,out] op_context A hardware-specific structure for the + * previously started cipher operation + * \param[out] p_output The caller-allocated buffer where the output + * will be placed + * \param[in] output_size The allocated size in bytes of the `p_output` + * buffer + * \param[out] p_output_length After completion, will contain the number of + * bytes placed in the `p_output` buffer + * + * \retval #PSA_SUCCESS + */ +typedef psa_status_t (*psa_drv_se_cipher_finish_t)(void *op_context, + uint8_t *p_output, + size_t output_size, + size_t *p_output_length); + +/** \brief A function that aborts a previously started secure element cipher + * operation + * + * \param[in,out] op_context A hardware-specific structure for the + * previously started cipher operation + */ +typedef psa_status_t (*psa_drv_se_cipher_abort_t)(void *op_context); + +/** \brief A function that performs the ECB block mode for secure element + * cipher operations + * + * Note: this function should only be used with implementations that do not + * provide a needed higher-level operation. + * + * \param[in,out] drv_context The driver context structure. + * \param[in] key_slot The slot of the key to be used for the operation + * \param[in] algorithm The algorithm to be used in the cipher operation + * \param[in] direction Indicates whether the operation is an encrypt or + * decrypt + * \param[in] p_input A buffer containing the data to be + * encrypted/decrypted + * \param[in] input_size The size in bytes of the buffer pointed to by + * `p_input` + * \param[out] p_output The caller-allocated buffer where the output + * will be placed + * \param[in] output_size The allocated size in bytes of the `p_output` + * buffer + * + * \retval #PSA_SUCCESS + * \retval #PSA_ERROR_NOT_SUPPORTED + */ +typedef psa_status_t (*psa_drv_se_cipher_ecb_t)(psa_drv_se_context_t *drv_context, + psa_key_slot_number_t key_slot, + psa_algorithm_t algorithm, + psa_encrypt_or_decrypt_t direction, + const uint8_t *p_input, + size_t input_size, + uint8_t *p_output, + size_t output_size); + +/** + * \brief A struct containing all of the function pointers needed to implement + * cipher operations using secure elements. + * + * PSA Crypto API implementations should populate instances of the table as + * appropriate upon startup or at build time. + * + * If one of the functions is not implemented (such as + * `psa_drv_se_cipher_ecb_t`), it should be set to NULL. + */ +typedef struct { + /** The size in bytes of the hardware-specific secure element cipher + * context structure + */ + size_t context_size; + /** Function that performs a cipher setup operation */ + psa_drv_se_cipher_setup_t p_setup; + /** Function that sets a cipher IV (if necessary) */ + psa_drv_se_cipher_set_iv_t p_set_iv; + /** Function that performs a cipher update operation */ + psa_drv_se_cipher_update_t p_update; + /** Function that completes a cipher operation */ + psa_drv_se_cipher_finish_t p_finish; + /** Function that aborts a cipher operation */ + psa_drv_se_cipher_abort_t p_abort; + /** Function that performs ECB mode for a cipher operation + * (Danger: ECB mode should not be used directly by clients of the PSA + * Crypto Client API) + */ + psa_drv_se_cipher_ecb_t p_ecb; +} psa_drv_se_cipher_t; + +/**@}*/ + +/** \defgroup se_asymmetric Secure Element Asymmetric Cryptography + * + * Since the amount of data that can (or should) be encrypted or signed using + * asymmetric keys is limited by the key size, asymmetric key operations using + * keys in a secure element must be done in single function calls. + */ +/**@{*/ + +/** + * \brief A function that signs a hash or short message with a private key in + * a secure element + * + * \param[in,out] drv_context The driver context structure. + * \param[in] key_slot Key slot of an asymmetric key pair + * \param[in] alg A signature algorithm that is compatible + * with the type of `key` + * \param[in] p_hash The hash to sign + * \param[in] hash_length Size of the `p_hash` buffer in bytes + * \param[out] p_signature Buffer where the signature is to be written + * \param[in] signature_size Size of the `p_signature` buffer in bytes + * \param[out] p_signature_length On success, the number of bytes + * that make up the returned signature value + * + * \retval #PSA_SUCCESS + */ +typedef psa_status_t (*psa_drv_se_asymmetric_sign_t)(psa_drv_se_context_t *drv_context, + psa_key_slot_number_t key_slot, + psa_algorithm_t alg, + const uint8_t *p_hash, + size_t hash_length, + uint8_t *p_signature, + size_t signature_size, + size_t *p_signature_length); + +/** + * \brief A function that verifies the signature a hash or short message using + * an asymmetric public key in a secure element + * + * \param[in,out] drv_context The driver context structure. + * \param[in] key_slot Key slot of a public key or an asymmetric key + * pair + * \param[in] alg A signature algorithm that is compatible with + * the type of `key` + * \param[in] p_hash The hash whose signature is to be verified + * \param[in] hash_length Size of the `p_hash` buffer in bytes + * \param[in] p_signature Buffer containing the signature to verify + * \param[in] signature_length Size of the `p_signature` buffer in bytes + * + * \retval #PSA_SUCCESS + * The signature is valid. + */ +typedef psa_status_t (*psa_drv_se_asymmetric_verify_t)(psa_drv_se_context_t *drv_context, + psa_key_slot_number_t key_slot, + psa_algorithm_t alg, + const uint8_t *p_hash, + size_t hash_length, + const uint8_t *p_signature, + size_t signature_length); + +/** + * \brief A function that encrypts a short message with an asymmetric public + * key in a secure element + * + * \param[in,out] drv_context The driver context structure. + * \param[in] key_slot Key slot of a public key or an asymmetric key + * pair + * \param[in] alg An asymmetric encryption algorithm that is + * compatible with the type of `key` + * \param[in] p_input The message to encrypt + * \param[in] input_length Size of the `p_input` buffer in bytes + * \param[in] p_salt A salt or label, if supported by the + * encryption algorithm + * If the algorithm does not support a + * salt, pass `NULL`. + * If the algorithm supports an optional + * salt and you do not want to pass a salt, + * pass `NULL`. + * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is + * supported. + * \param[in] salt_length Size of the `p_salt` buffer in bytes + * If `p_salt` is `NULL`, pass 0. + * \param[out] p_output Buffer where the encrypted message is to + * be written + * \param[in] output_size Size of the `p_output` buffer in bytes + * \param[out] p_output_length On success, the number of bytes that make up + * the returned output + * + * \retval #PSA_SUCCESS + */ +typedef psa_status_t (*psa_drv_se_asymmetric_encrypt_t)(psa_drv_se_context_t *drv_context, + psa_key_slot_number_t key_slot, + psa_algorithm_t alg, + const uint8_t *p_input, + size_t input_length, + const uint8_t *p_salt, + size_t salt_length, + uint8_t *p_output, + size_t output_size, + size_t *p_output_length); + +/** + * \brief A function that decrypts a short message with an asymmetric private + * key in a secure element. + * + * \param[in,out] drv_context The driver context structure. + * \param[in] key_slot Key slot of an asymmetric key pair + * \param[in] alg An asymmetric encryption algorithm that is + * compatible with the type of `key` + * \param[in] p_input The message to decrypt + * \param[in] input_length Size of the `p_input` buffer in bytes + * \param[in] p_salt A salt or label, if supported by the + * encryption algorithm + * If the algorithm does not support a + * salt, pass `NULL`. + * If the algorithm supports an optional + * salt and you do not want to pass a salt, + * pass `NULL`. + * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is + * supported. + * \param[in] salt_length Size of the `p_salt` buffer in bytes + * If `p_salt` is `NULL`, pass 0. + * \param[out] p_output Buffer where the decrypted message is to + * be written + * \param[in] output_size Size of the `p_output` buffer in bytes + * \param[out] p_output_length On success, the number of bytes + * that make up the returned output + * + * \retval #PSA_SUCCESS + */ +typedef psa_status_t (*psa_drv_se_asymmetric_decrypt_t)(psa_drv_se_context_t *drv_context, + psa_key_slot_number_t key_slot, + psa_algorithm_t alg, + const uint8_t *p_input, + size_t input_length, + const uint8_t *p_salt, + size_t salt_length, + uint8_t *p_output, + size_t output_size, + size_t *p_output_length); + +/** + * \brief A struct containing all of the function pointers needed to implement + * asymmetric cryptographic operations using secure elements. + * + * PSA Crypto API implementations should populate instances of the table as + * appropriate upon startup or at build time. + * + * If one of the functions is not implemented, it should be set to NULL. + */ +typedef struct { + /** Function that performs an asymmetric sign operation */ + psa_drv_se_asymmetric_sign_t p_sign; + /** Function that performs an asymmetric verify operation */ + psa_drv_se_asymmetric_verify_t p_verify; + /** Function that performs an asymmetric encrypt operation */ + psa_drv_se_asymmetric_encrypt_t p_encrypt; + /** Function that performs an asymmetric decrypt operation */ + psa_drv_se_asymmetric_decrypt_t p_decrypt; +} psa_drv_se_asymmetric_t; + +/**@}*/ + +/** \defgroup se_aead Secure Element Authenticated Encryption with Additional Data + * Authenticated Encryption with Additional Data (AEAD) operations with secure + * elements must be done in one function call. While this creates a burden for + * implementers as there must be sufficient space in memory for the entire + * message, it prevents decrypted data from being made available before the + * authentication operation is complete and the data is known to be authentic. + */ +/**@{*/ + +/** \brief A function that performs a secure element authenticated encryption + * operation + * + * \param[in,out] drv_context The driver context structure. + * \param[in] key_slot Slot containing the key to use. + * \param[in] algorithm The AEAD algorithm to compute + * (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_AEAD(`alg`) is true) + * \param[in] p_nonce Nonce or IV to use + * \param[in] nonce_length Size of the `p_nonce` buffer in bytes + * \param[in] p_additional_data Additional data that will be + * authenticated but not encrypted + * \param[in] additional_data_length Size of `p_additional_data` in bytes + * \param[in] p_plaintext Data that will be authenticated and + * encrypted + * \param[in] plaintext_length Size of `p_plaintext` in bytes + * \param[out] p_ciphertext Output buffer for the authenticated and + * encrypted data. The additional data is + * not part of this output. For algorithms + * where the encrypted data and the + * authentication tag are defined as + * separate outputs, the authentication + * tag is appended to the encrypted data. + * \param[in] ciphertext_size Size of the `p_ciphertext` buffer in + * bytes + * \param[out] p_ciphertext_length On success, the size of the output in + * the `p_ciphertext` buffer + * + * \retval #PSA_SUCCESS + * Success. + */ +typedef psa_status_t (*psa_drv_se_aead_encrypt_t)(psa_drv_se_context_t *drv_context, + psa_key_slot_number_t key_slot, + psa_algorithm_t algorithm, + const uint8_t *p_nonce, + size_t nonce_length, + const uint8_t *p_additional_data, + size_t additional_data_length, + const uint8_t *p_plaintext, + size_t plaintext_length, + uint8_t *p_ciphertext, + size_t ciphertext_size, + size_t *p_ciphertext_length); + +/** A function that peforms a secure element authenticated decryption operation + * + * \param[in,out] drv_context The driver context structure. + * \param[in] key_slot Slot containing the key to use + * \param[in] algorithm The AEAD algorithm to compute + * (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_AEAD(`alg`) is true) + * \param[in] p_nonce Nonce or IV to use + * \param[in] nonce_length Size of the `p_nonce` buffer in bytes + * \param[in] p_additional_data Additional data that has been + * authenticated but not encrypted + * \param[in] additional_data_length Size of `p_additional_data` in bytes + * \param[in] p_ciphertext Data that has been authenticated and + * encrypted. + * For algorithms where the encrypted data + * and the authentication tag are defined + * as separate inputs, the buffer must + * contain the encrypted data followed by + * the authentication tag. + * \param[in] ciphertext_length Size of `p_ciphertext` in bytes + * \param[out] p_plaintext Output buffer for the decrypted data + * \param[in] plaintext_size Size of the `p_plaintext` buffer in + * bytes + * \param[out] p_plaintext_length On success, the size of the output in + * the `p_plaintext` buffer + * + * \retval #PSA_SUCCESS + * Success. + */ +typedef psa_status_t (*psa_drv_se_aead_decrypt_t)(psa_drv_se_context_t *drv_context, + psa_key_slot_number_t key_slot, + psa_algorithm_t algorithm, + const uint8_t *p_nonce, + size_t nonce_length, + const uint8_t *p_additional_data, + size_t additional_data_length, + const uint8_t *p_ciphertext, + size_t ciphertext_length, + uint8_t *p_plaintext, + size_t plaintext_size, + size_t *p_plaintext_length); + +/** + * \brief A struct containing all of the function pointers needed to implement + * secure element Authenticated Encryption with Additional Data operations + * + * PSA Crypto API implementations should populate instances of the table as + * appropriate upon startup. + * + * If one of the functions is not implemented, it should be set to NULL. + */ +typedef struct { + /** Function that performs the AEAD encrypt operation */ + psa_drv_se_aead_encrypt_t p_encrypt; + /** Function that performs the AEAD decrypt operation */ + psa_drv_se_aead_decrypt_t p_decrypt; +} psa_drv_se_aead_t; +/**@}*/ + +/** \defgroup se_key_management Secure Element Key Management + * Currently, key management is limited to importing keys in the clear, + * destroying keys, and exporting keys in the clear. + * Whether a key may be exported is determined by the key policies in place + * on the key slot. + */ +/**@{*/ + +/** An enumeration indicating how a key is created. + */ +typedef enum +{ + PSA_KEY_CREATION_IMPORT, /**< During psa_import_key() */ + PSA_KEY_CREATION_GENERATE, /**< During psa_generate_key() */ + PSA_KEY_CREATION_DERIVE, /**< During psa_key_derivation_output_key() */ + PSA_KEY_CREATION_COPY, /**< During psa_copy_key() */ + +#ifndef __DOXYGEN_ONLY__ + /** A key is being registered with mbedtls_psa_register_se_key(). + * + * The core only passes this value to + * psa_drv_se_key_management_t::p_validate_slot_number, not to + * psa_drv_se_key_management_t::p_allocate. The call to + * `p_validate_slot_number` is not followed by any other call to the + * driver: the key is considered successfully registered if the call to + * `p_validate_slot_number` succeeds, or if `p_validate_slot_number` is + * null. + * + * With this creation method, the driver must return #PSA_SUCCESS if + * the given attributes are compatible with the existing key in the slot, + * and #PSA_ERROR_DOES_NOT_EXIST if the driver can determine that there + * is no key with the specified slot number. + * + * This is an Mbed Crypto extension. + */ + PSA_KEY_CREATION_REGISTER, +#endif +} psa_key_creation_method_t; + +/** \brief A function that allocates a slot for a key. + * + * To create a key in a specific slot in a secure element, the core + * first calls this function to determine a valid slot number, + * then calls a function to create the key material in that slot. + * In nominal conditions (that is, if no error occurs), + * the effect of a call to a key creation function in the PSA Cryptography + * API with a lifetime that places the key in a secure element is the + * following: + * -# The core calls psa_drv_se_key_management_t::p_allocate + * (or in some implementations + * psa_drv_se_key_management_t::p_validate_slot_number). The driver + * selects (or validates) a suitable slot number given the key attributes + * and the state of the secure element. + * -# The core calls a key creation function in the driver. + * + * The key creation functions in the PSA Cryptography API are: + * - psa_import_key(), which causes + * a call to `p_allocate` with \p method = #PSA_KEY_CREATION_IMPORT + * then a call to psa_drv_se_key_management_t::p_import. + * - psa_generate_key(), which causes + * a call to `p_allocate` with \p method = #PSA_KEY_CREATION_GENERATE + * then a call to psa_drv_se_key_management_t::p_import. + * - psa_key_derivation_output_key(), which causes + * a call to `p_allocate` with \p method = #PSA_KEY_CREATION_DERIVE + * then a call to psa_drv_se_key_derivation_t::p_derive. + * - psa_copy_key(), which causes + * a call to `p_allocate` with \p method = #PSA_KEY_CREATION_COPY + * then a call to psa_drv_se_key_management_t::p_export. + * + * In case of errors, other behaviors are possible. + * - If the PSA Cryptography subsystem dies after the first step, + * for example because the device has lost power abruptly, + * the second step may never happen, or may happen after a reset + * and re-initialization. Alternatively, after a reset and + * re-initialization, the core may call + * psa_drv_se_key_management_t::p_destroy on the slot number that + * was allocated (or validated) instead of calling a key creation function. + * - If an error occurs, the core may call + * psa_drv_se_key_management_t::p_destroy on the slot number that + * was allocated (or validated) instead of calling a key creation function. + * + * Errors and system resets also have an impact on the driver's persistent + * data. If a reset happens before the overall key creation process is + * completed (before or after the second step above), it is unspecified + * whether the persistent data after the reset is identical to what it + * was before or after the call to `p_allocate` (or `p_validate_slot_number`). + * + * \param[in,out] drv_context The driver context structure. + * \param[in,out] persistent_data A pointer to the persistent data + * that allows writing. + * \param[in] attributes Attributes of the key. + * \param method The way in which the key is being created. + * \param[out] key_slot Slot where the key will be stored. + * This must be a valid slot for a key of the + * chosen type. It must be unoccupied. + * + * \retval #PSA_SUCCESS + * Success. + * The core will record \c *key_slot as the key slot where the key + * is stored and will update the persistent data in storage. + * \retval #PSA_ERROR_NOT_SUPPORTED + * \retval #PSA_ERROR_INSUFFICIENT_STORAGE + */ +typedef psa_status_t (*psa_drv_se_allocate_key_t)( + psa_drv_se_context_t *drv_context, + void *persistent_data, + const psa_key_attributes_t *attributes, + psa_key_creation_method_t method, + psa_key_slot_number_t *key_slot); + +/** \brief A function that determines whether a slot number is valid + * for a key. + * + * To create a key in a specific slot in a secure element, the core + * first calls this function to validate the choice of slot number, + * then calls a function to create the key material in that slot. + * See the documentation of #psa_drv_se_allocate_key_t for more details. + * + * As of the PSA Cryptography API specification version 1.0, there is no way + * for applications to trigger a call to this function. However some + * implementations offer the capability to create or declare a key in + * a specific slot via implementation-specific means, generally for the + * sake of initial device provisioning or onboarding. Such a mechanism may + * be added to a future version of the PSA Cryptography API specification. + * + * This function may update the driver's persistent data through + * \p persistent_data. The core will save the updated persistent data at the + * end of the key creation process. See the description of + * ::psa_drv_se_allocate_key_t for more information. + * + * \param[in,out] drv_context The driver context structure. + * \param[in,out] persistent_data A pointer to the persistent data + * that allows writing. + * \param[in] attributes Attributes of the key. + * \param method The way in which the key is being created. + * \param[in] key_slot Slot where the key is to be stored. + * + * \retval #PSA_SUCCESS + * The given slot number is valid for a key with the given + * attributes. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * The given slot number is not valid for a key with the + * given attributes. This includes the case where the slot + * number is not valid at all. + * \retval #PSA_ERROR_ALREADY_EXISTS + * There is already a key with the specified slot number. + * Drivers may choose to return this error from the key + * creation function instead. + */ +typedef psa_status_t (*psa_drv_se_validate_slot_number_t)( + psa_drv_se_context_t *drv_context, + void *persistent_data, + const psa_key_attributes_t *attributes, + psa_key_creation_method_t method, + psa_key_slot_number_t key_slot); + +/** \brief A function that imports a key into a secure element in binary format + * + * This function can support any output from psa_export_key(). Refer to the + * documentation of psa_export_key() for the format for each key type. + * + * \param[in,out] drv_context The driver context structure. + * \param key_slot Slot where the key will be stored. + * This must be a valid slot for a key of the + * chosen type. It must be unoccupied. + * \param[in] attributes The key attributes, including the lifetime, + * the key type and the usage policy. + * Drivers should not access the key size stored + * in the attributes: it may not match the + * data passed in \p data. + * Drivers can call psa_get_key_lifetime(), + * psa_get_key_type(), + * psa_get_key_usage_flags() and + * psa_get_key_algorithm() to access this + * information. + * \param[in] data Buffer containing the key data. + * \param[in] data_length Size of the \p data buffer in bytes. + * \param[out] bits On success, the key size in bits. The driver + * must determine this value after parsing the + * key according to the key type. + * This value is not used if the function fails. + * + * \retval #PSA_SUCCESS + * Success. + */ +typedef psa_status_t (*psa_drv_se_import_key_t)( + psa_drv_se_context_t *drv_context, + psa_key_slot_number_t key_slot, + const psa_key_attributes_t *attributes, + const uint8_t *data, + size_t data_length, + size_t *bits); + +/** + * \brief A function that destroys a secure element key and restore the slot to + * its default state + * + * This function destroys the content of the key from a secure element. + * Implementations shall make a best effort to ensure that any previous content + * of the slot is unrecoverable. + * + * This function returns the specified slot to its default state. + * + * \param[in,out] drv_context The driver context structure. + * \param[in,out] persistent_data A pointer to the persistent data + * that allows writing. + * \param key_slot The key slot to erase. + * + * \retval #PSA_SUCCESS + * The slot's content, if any, has been erased. + */ +typedef psa_status_t (*psa_drv_se_destroy_key_t)( + psa_drv_se_context_t *drv_context, + void *persistent_data, + psa_key_slot_number_t key_slot); + +/** + * \brief A function that exports a secure element key in binary format + * + * The output of this function can be passed to psa_import_key() to + * create an equivalent object. + * + * If a key is created with `psa_import_key()` and then exported with + * this function, it is not guaranteed that the resulting data is + * identical: the implementation may choose a different representation + * of the same key if the format permits it. + * + * This function should generate output in the same format that + * `psa_export_key()` does. Refer to the + * documentation of `psa_export_key()` for the format for each key type. + * + * \param[in,out] drv_context The driver context structure. + * \param[in] key Slot whose content is to be exported. This must + * be an occupied key slot. + * \param[out] p_data Buffer where the key data is to be written. + * \param[in] data_size Size of the `p_data` buffer in bytes. + * \param[out] p_data_length On success, the number of bytes + * that make up the key data. + * + * \retval #PSA_SUCCESS + * \retval #PSA_ERROR_DOES_NOT_EXIST + * \retval #PSA_ERROR_NOT_PERMITTED + * \retval #PSA_ERROR_NOT_SUPPORTED + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_HARDWARE_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + */ +typedef psa_status_t (*psa_drv_se_export_key_t)(psa_drv_se_context_t *drv_context, + psa_key_slot_number_t key, + uint8_t *p_data, + size_t data_size, + size_t *p_data_length); + +/** + * \brief A function that generates a symmetric or asymmetric key on a secure + * element + * + * If the key type \c type recorded in \p attributes + * is asymmetric (#PSA_KEY_TYPE_IS_ASYMMETRIC(\c type) = 1), + * the driver may export the public key at the time of generation, + * in the format documented for psa_export_public_key() by writing it + * to the \p pubkey buffer. + * This is optional, intended for secure elements that output the + * public key at generation time and that cannot export the public key + * later. Drivers that do not need this feature should leave + * \p *pubkey_length set to 0 and should + * implement the psa_drv_key_management_t::p_export_public function. + * Some implementations do not support this feature, in which case + * \p pubkey is \c NULL and \p pubkey_size is 0. + * + * \param[in,out] drv_context The driver context structure. + * \param key_slot Slot where the key will be stored. + * This must be a valid slot for a key of the + * chosen type. It must be unoccupied. + * \param[in] attributes The key attributes, including the lifetime, + * the key type and size, and the usage policy. + * Drivers can call psa_get_key_lifetime(), + * psa_get_key_type(), psa_get_key_bits(), + * psa_get_key_usage_flags() and + * psa_get_key_algorithm() to access this + * information. + * \param[out] pubkey A buffer where the driver can write the + * public key, when generating an asymmetric + * key pair. + * This is \c NULL when generating a symmetric + * key or if the core does not support + * exporting the public key at generation time. + * \param pubkey_size The size of the `pubkey` buffer in bytes. + * This is 0 when generating a symmetric + * key or if the core does not support + * exporting the public key at generation time. + * \param[out] pubkey_length On entry, this is always 0. + * On success, the number of bytes written to + * \p pubkey. If this is 0 or unchanged on return, + * the core will not read the \p pubkey buffer, + * and will instead call the driver's + * psa_drv_key_management_t::p_export_public + * function to export the public key when needed. + */ +typedef psa_status_t (*psa_drv_se_generate_key_t)( + psa_drv_se_context_t *drv_context, + psa_key_slot_number_t key_slot, + const psa_key_attributes_t *attributes, + uint8_t *pubkey, size_t pubkey_size, size_t *pubkey_length); + +/** + * \brief A struct containing all of the function pointers needed to for secure + * element key management + * + * PSA Crypto API implementations should populate instances of the table as + * appropriate upon startup or at build time. + * + * If one of the functions is not implemented, it should be set to NULL. + */ +typedef struct { + /** Function that allocates a slot for a key. */ + psa_drv_se_allocate_key_t p_allocate; + /** Function that checks the validity of a slot for a key. */ + psa_drv_se_validate_slot_number_t p_validate_slot_number; + /** Function that performs a key import operation */ + psa_drv_se_import_key_t p_import; + /** Function that performs a generation */ + psa_drv_se_generate_key_t p_generate; + /** Function that performs a key destroy operation */ + psa_drv_se_destroy_key_t p_destroy; + /** Function that performs a key export operation */ + psa_drv_se_export_key_t p_export; + /** Function that performs a public key export operation */ + psa_drv_se_export_key_t p_export_public; +} psa_drv_se_key_management_t; + +/**@}*/ + +/** \defgroup driver_derivation Secure Element Key Derivation and Agreement + * Key derivation is the process of generating new key material using an + * existing key and additional parameters, iterating through a basic + * cryptographic function, such as a hash. + * Key agreement is a part of cryptographic protocols that allows two parties + * to agree on the same key value, but starting from different original key + * material. + * The flows are similar, and the PSA Crypto Driver Model uses the same functions + * for both of the flows. + * + * There are two different final functions for the flows, + * `psa_drv_se_key_derivation_derive` and `psa_drv_se_key_derivation_export`. + * `psa_drv_se_key_derivation_derive` is used when the key material should be + * placed in a slot on the hardware and not exposed to the caller. + * `psa_drv_se_key_derivation_export` is used when the key material should be + * returned to the PSA Cryptographic API implementation. + * + * Different key derivation algorithms require a different number of inputs. + * Instead of having an API that takes as input variable length arrays, which + * can be problemmatic to manage on embedded platforms, the inputs are passed + * to the driver via a function, `psa_drv_se_key_derivation_collateral`, that + * is called multiple times with different `collateral_id`s. Thus, for a key + * derivation algorithm that required 3 parameter inputs, the flow would look + * something like: + * ~~~~~~~~~~~~~{.c} + * psa_drv_se_key_derivation_setup(kdf_algorithm, source_key, dest_key_size_bytes); + * psa_drv_se_key_derivation_collateral(kdf_algorithm_collateral_id_0, + * p_collateral_0, + * collateral_0_size); + * psa_drv_se_key_derivation_collateral(kdf_algorithm_collateral_id_1, + * p_collateral_1, + * collateral_1_size); + * psa_drv_se_key_derivation_collateral(kdf_algorithm_collateral_id_2, + * p_collateral_2, + * collateral_2_size); + * psa_drv_se_key_derivation_derive(); + * ~~~~~~~~~~~~~ + * + * key agreement example: + * ~~~~~~~~~~~~~{.c} + * psa_drv_se_key_derivation_setup(alg, source_key. dest_key_size_bytes); + * psa_drv_se_key_derivation_collateral(DHE_PUBKEY, p_pubkey, pubkey_size); + * psa_drv_se_key_derivation_export(p_session_key, + * session_key_size, + * &session_key_length); + * ~~~~~~~~~~~~~ + */ +/**@{*/ + +/** \brief A function that Sets up a secure element key derivation operation by + * specifying the algorithm and the source key sot + * + * \param[in,out] drv_context The driver context structure. + * \param[in,out] op_context A hardware-specific structure containing any + * context information for the implementation + * \param[in] kdf_alg The algorithm to be used for the key derivation + * \param[in] source_key The key to be used as the source material for + * the key derivation + * + * \retval #PSA_SUCCESS + */ +typedef psa_status_t (*psa_drv_se_key_derivation_setup_t)(psa_drv_se_context_t *drv_context, + void *op_context, + psa_algorithm_t kdf_alg, + psa_key_slot_number_t source_key); + +/** \brief A function that provides collateral (parameters) needed for a secure + * element key derivation or key agreement operation + * + * Since many key derivation algorithms require multiple parameters, it is + * expected that this function may be called multiple times for the same + * operation, each with a different algorithm-specific `collateral_id` + * + * \param[in,out] op_context A hardware-specific structure containing any + * context information for the implementation + * \param[in] collateral_id An ID for the collateral being provided + * \param[in] p_collateral A buffer containing the collateral data + * \param[in] collateral_size The size in bytes of the collateral + * + * \retval #PSA_SUCCESS + */ +typedef psa_status_t (*psa_drv_se_key_derivation_collateral_t)(void *op_context, + uint32_t collateral_id, + const uint8_t *p_collateral, + size_t collateral_size); + +/** \brief A function that performs the final secure element key derivation + * step and place the generated key material in a slot + * + * \param[in,out] op_context A hardware-specific structure containing any + * context information for the implementation + * \param[in] dest_key The slot where the generated key material + * should be placed + * + * \retval #PSA_SUCCESS + */ +typedef psa_status_t (*psa_drv_se_key_derivation_derive_t)(void *op_context, + psa_key_slot_number_t dest_key); + +/** \brief A function that performs the final step of a secure element key + * agreement and place the generated key material in a buffer + * + * \param[out] p_output Buffer in which to place the generated key + * material + * \param[in] output_size The size in bytes of `p_output` + * \param[out] p_output_length Upon success, contains the number of bytes of + * key material placed in `p_output` + * + * \retval #PSA_SUCCESS + */ +typedef psa_status_t (*psa_drv_se_key_derivation_export_t)(void *op_context, + uint8_t *p_output, + size_t output_size, + size_t *p_output_length); + +/** + * \brief A struct containing all of the function pointers needed to for secure + * element key derivation and agreement + * + * PSA Crypto API implementations should populate instances of the table as + * appropriate upon startup. + * + * If one of the functions is not implemented, it should be set to NULL. + */ +typedef struct { + /** The driver-specific size of the key derivation context */ + size_t context_size; + /** Function that performs a key derivation setup */ + psa_drv_se_key_derivation_setup_t p_setup; + /** Function that sets key derivation collateral */ + psa_drv_se_key_derivation_collateral_t p_collateral; + /** Function that performs a final key derivation step */ + psa_drv_se_key_derivation_derive_t p_derive; + /** Function that perforsm a final key derivation or agreement and + * exports the key */ + psa_drv_se_key_derivation_export_t p_export; +} psa_drv_se_key_derivation_t; + +/**@}*/ + +/** \defgroup se_registration Secure element driver registration + */ +/**@{*/ + +/** A structure containing pointers to all the entry points of a + * secure element driver. + * + * Future versions of this specification may add extra substructures at + * the end of this structure. + */ +typedef struct { + /** The version of the driver HAL that this driver implements. + * This is a protection against loading driver binaries built against + * a different version of this specification. + * Use #PSA_DRV_SE_HAL_VERSION. + */ + uint32_t hal_version; + + /** The size of the driver's persistent data in bytes. + * + * This can be 0 if the driver does not need persistent data. + * + * See the documentation of psa_drv_se_context_t::persistent_data + * for more information about why and how a driver can use + * persistent data. + */ + size_t persistent_data_size; + + /** The driver initialization function. + * + * This function is called once during the initialization of the + * PSA Cryptography subsystem, before any other function of the + * driver is called. If this function returns a failure status, + * the driver will be unusable, at least until the next system reset. + * + * If this field is \c NULL, it is equivalent to a function that does + * nothing and returns #PSA_SUCCESS. + */ + psa_drv_se_init_t p_init; + + const psa_drv_se_key_management_t *key_management; + const psa_drv_se_mac_t *mac; + const psa_drv_se_cipher_t *cipher; + const psa_drv_se_aead_t *aead; + const psa_drv_se_asymmetric_t *asymmetric; + const psa_drv_se_key_derivation_t *derivation; +} psa_drv_se_t; + +/** The current version of the secure element driver HAL. + */ +/* 0.0.0 patchlevel 5 */ +#define PSA_DRV_SE_HAL_VERSION 0x00000005 + +/** Register an external cryptoprocessor (secure element) driver. + * + * This function is only intended to be used by driver code, not by + * application code. In implementations with separation between the + * PSA cryptography module and applications, this function should + * only be available to callers that run in the same memory space as + * the cryptography module, and should not be exposed to applications + * running in a different memory space. + * + * This function may be called before psa_crypto_init(). It is + * implementation-defined whether this function may be called + * after psa_crypto_init(). + * + * \note Implementations store metadata about keys including the lifetime + * value, which contains the driver's location indicator. Therefore, + * from one instantiation of the PSA Cryptography + * library to the next one, if there is a key in storage with a certain + * lifetime value, you must always register the same driver (or an + * updated version that communicates with the same secure element) + * with the same location value. + * + * \param location The location value through which this driver will + * be exposed to applications. + * This driver will be used for all keys such that + * `location == #PSA_KEY_LIFETIME_GET_LOCATION( lifetime )`. + * The value #PSA_KEY_LOCATION_LOCAL_STORAGE is reserved + * and may not be used for drivers. Implementations + * may reserve other values. + * \param[in] methods The method table of the driver. This structure must + * remain valid for as long as the cryptography + * module keeps running. It is typically a global + * constant. + * + * \return #PSA_SUCCESS + * The driver was successfully registered. Applications can now + * use \p location to access keys through the methods passed to + * this function. + * \return #PSA_ERROR_BAD_STATE + * This function was called after the initialization of the + * cryptography module, and this implementation does not support + * driver registration at this stage. + * \return #PSA_ERROR_ALREADY_EXISTS + * There is already a registered driver for this value of \p location. + * \return #PSA_ERROR_INVALID_ARGUMENT + * \p location is a reserved value. + * \return #PSA_ERROR_NOT_SUPPORTED + * `methods->hal_version` is not supported by this implementation. + * \return #PSA_ERROR_INSUFFICIENT_MEMORY + * \return #PSA_ERROR_NOT_PERMITTED + * \return #PSA_ERROR_STORAGE_FAILURE + * \return #PSA_ERROR_DATA_CORRUPT + */ +psa_status_t psa_register_se_driver( + psa_key_location_t location, + const psa_drv_se_t *methods); + +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* PSA_CRYPTO_SE_DRIVER_H */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_sizes.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_sizes.h new file mode 100644 index 00000000000..e2ae5965d4f --- /dev/null +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_sizes.h @@ -0,0 +1,1171 @@ +/** + * \file psa/crypto_sizes.h + * + * \brief PSA cryptography module: Mbed TLS buffer size macros + * + * \note This file may not be included directly. Applications must + * include psa/crypto.h. + * + * This file contains the definitions of macros that are useful to + * compute buffer sizes. The signatures and semantics of these macros + * are standardized, but the definitions are not, because they depend on + * the available algorithms and, in some cases, on permitted tolerances + * on buffer sizes. + * + * In implementations with isolation between the application and the + * cryptography module, implementers should take care to ensure that + * the definitions that are exposed to applications match what the + * module implements. + * + * Macros that compute sizes whose values do not depend on the + * implementation are in crypto.h. + */ +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PSA_CRYPTO_SIZES_H +#define PSA_CRYPTO_SIZES_H + +/* Include the Mbed TLS configuration file, the way Mbed TLS does it + * in each of its header files. */ +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls/config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#define PSA_BITS_TO_BYTES(bits) (((bits) + 7) / 8) +#define PSA_BYTES_TO_BITS(bytes) ((bytes) * 8) + +#define PSA_ROUND_UP_TO_MULTIPLE(block_size, length) \ + (((length) + (block_size) - 1) / (block_size) * (block_size)) + +/** The size of the output of psa_hash_finish(), in bytes. + * + * This is also the hash size that psa_hash_verify() expects. + * + * \param alg A hash algorithm (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_HASH(\p alg) is true), or an HMAC algorithm + * (#PSA_ALG_HMAC(\c hash_alg) where \c hash_alg is a + * hash algorithm). + * + * \return The hash size for the specified hash algorithm. + * If the hash algorithm is not recognized, return 0. + */ +#define PSA_HASH_LENGTH(alg) \ + ( \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_MD2 ? 16 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_MD4 ? 16 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_MD5 ? 16 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_RIPEMD160 ? 20 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_1 ? 20 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_224 ? 28 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_256 ? 32 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_384 ? 48 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512 ? 64 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512_224 ? 28 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512_256 ? 32 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_224 ? 28 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_256 ? 32 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_384 ? 48 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_512 ? 64 : \ + 0) + +/** The input block size of a hash algorithm, in bytes. + * + * Hash algorithms process their input data in blocks. Hash operations will + * retain any partial blocks until they have enough input to fill the block or + * until the operation is finished. + * This affects the output from psa_hash_suspend(). + * + * \param alg A hash algorithm (\c PSA_ALG_XXX value such that + * PSA_ALG_IS_HASH(\p alg) is true). + * + * \return The block size in bytes for the specified hash algorithm. + * If the hash algorithm is not recognized, return 0. + * An implementation can return either 0 or the correct size for a + * hash algorithm that it recognizes, but does not support. + */ +#define PSA_HASH_BLOCK_LENGTH(alg) \ + ( \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_MD2 ? 16 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_MD4 ? 64 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_MD5 ? 64 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_RIPEMD160 ? 64 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_1 ? 64 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_224 ? 64 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_256 ? 64 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_384 ? 128 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512 ? 128 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512_224 ? 128 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512_256 ? 128 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_224 ? 144 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_256 ? 136 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_384 ? 104 : \ + PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_512 ? 72 : \ + 0) + +/** \def PSA_HASH_MAX_SIZE + * + * Maximum size of a hash. + * + * This macro expands to a compile-time constant integer. This value + * is the maximum size of a hash in bytes. + */ +/* Note: for HMAC-SHA-3, the block size is 144 bytes for HMAC-SHA3-226, + * 136 bytes for HMAC-SHA3-256, 104 bytes for SHA3-384, 72 bytes for + * HMAC-SHA3-512. */ +#if defined(PSA_WANT_ALG_SHA_512) || defined(PSA_WANT_ALG_SHA_384) +#define PSA_HASH_MAX_SIZE 64 +#define PSA_HMAC_MAX_HASH_BLOCK_SIZE 128 +#else +#define PSA_HASH_MAX_SIZE 32 +#define PSA_HMAC_MAX_HASH_BLOCK_SIZE 64 +#endif + +/** \def PSA_MAC_MAX_SIZE + * + * Maximum size of a MAC. + * + * This macro expands to a compile-time constant integer. This value + * is the maximum size of a MAC in bytes. + */ +/* All non-HMAC MACs have a maximum size that's smaller than the + * minimum possible value of PSA_HASH_MAX_SIZE in this implementation. */ +/* Note that the encoding of truncated MAC algorithms limits this value + * to 64 bytes. + */ +#define PSA_MAC_MAX_SIZE PSA_HASH_MAX_SIZE + +/** The length of a tag for an AEAD algorithm, in bytes. + * + * This macro can be used to allocate a buffer of sufficient size to store the + * tag output from psa_aead_finish(). + * + * See also #PSA_AEAD_TAG_MAX_SIZE. + * + * \param key_type The type of the AEAD key. + * \param key_bits The size of the AEAD key in bits. + * \param alg An AEAD algorithm + * (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_AEAD(\p alg) is true). + * + * \return The tag length for the specified algorithm and key. + * If the AEAD algorithm does not have an identified + * tag that can be distinguished from the rest of + * the ciphertext, return 0. + * If the key type or AEAD algorithm is not + * recognized, or the parameters are incompatible, + * return 0. + */ +#define PSA_AEAD_TAG_LENGTH(key_type, key_bits, alg) \ + (PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 ? \ + PSA_ALG_AEAD_GET_TAG_LENGTH(alg) : \ + ((void) (key_bits), 0)) + +/** The maximum tag size for all supported AEAD algorithms, in bytes. + * + * See also #PSA_AEAD_TAG_LENGTH(\p key_type, \p key_bits, \p alg). + */ +#define PSA_AEAD_TAG_MAX_SIZE 16 + +/* The maximum size of an RSA key on this implementation, in bits. + * This is a vendor-specific macro. + * + * Mbed TLS does not set a hard limit on the size of RSA keys: any key + * whose parameters fit in a bignum is accepted. However large keys can + * induce a large memory usage and long computation times. Unlike other + * auxiliary macros in this file and in crypto.h, which reflect how the + * library is configured, this macro defines how the library is + * configured. This implementation refuses to import or generate an + * RSA key whose size is larger than the value defined here. + * + * Note that an implementation may set different size limits for different + * operations, and does not need to accept all key sizes up to the limit. */ +#define PSA_VENDOR_RSA_MAX_KEY_BITS 4096 + +/* The maximum size of an ECC key on this implementation, in bits. + * This is a vendor-specific macro. */ +#if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) +#define PSA_VENDOR_ECC_MAX_CURVE_BITS 521 +#elif defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) +#define PSA_VENDOR_ECC_MAX_CURVE_BITS 512 +#elif defined(MBEDTLS_ECP_DP_CURVE448_ENABLED) +#define PSA_VENDOR_ECC_MAX_CURVE_BITS 448 +#elif defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) +#define PSA_VENDOR_ECC_MAX_CURVE_BITS 384 +#elif defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) +#define PSA_VENDOR_ECC_MAX_CURVE_BITS 384 +#elif defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) +#define PSA_VENDOR_ECC_MAX_CURVE_BITS 256 +#elif defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) +#define PSA_VENDOR_ECC_MAX_CURVE_BITS 256 +#elif defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) +#define PSA_VENDOR_ECC_MAX_CURVE_BITS 256 +#elif defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) +#define PSA_VENDOR_ECC_MAX_CURVE_BITS 255 +#elif defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) +#define PSA_VENDOR_ECC_MAX_CURVE_BITS 224 +#elif defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) +#define PSA_VENDOR_ECC_MAX_CURVE_BITS 224 +#elif defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) +#define PSA_VENDOR_ECC_MAX_CURVE_BITS 192 +#elif defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) +#define PSA_VENDOR_ECC_MAX_CURVE_BITS 192 +#else +#define PSA_VENDOR_ECC_MAX_CURVE_BITS 0 +#endif + +/** This macro returns the maximum supported length of the PSK for the + * TLS-1.2 PSK-to-MS key derivation + * (#PSA_ALG_TLS12_PSK_TO_MS(\c hash_alg)). + * + * The maximum supported length does not depend on the chosen hash algorithm. + * + * Quoting RFC 4279, Sect 5.3: + * TLS implementations supporting these ciphersuites MUST support + * arbitrary PSK identities up to 128 octets in length, and arbitrary + * PSKs up to 64 octets in length. Supporting longer identities and + * keys is RECOMMENDED. + * + * Therefore, no implementation should define a value smaller than 64 + * for #PSA_TLS12_PSK_TO_MS_PSK_MAX_SIZE. + */ +#define PSA_TLS12_PSK_TO_MS_PSK_MAX_SIZE 128 + +/** The maximum size of a block cipher. */ +#define PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE 16 + +/** The size of the output of psa_mac_sign_finish(), in bytes. + * + * This is also the MAC size that psa_mac_verify_finish() expects. + * + * \warning This macro may evaluate its arguments multiple times or + * zero times, so you should not pass arguments that contain + * side effects. + * + * \param key_type The type of the MAC key. + * \param key_bits The size of the MAC key in bits. + * \param alg A MAC algorithm (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_MAC(\p alg) is true). + * + * \return The MAC size for the specified algorithm with + * the specified key parameters. + * \return 0 if the MAC algorithm is not recognized. + * \return Either 0 or the correct size for a MAC algorithm that + * the implementation recognizes, but does not support. + * \return Unspecified if the key parameters are not consistent + * with the algorithm. + */ +#define PSA_MAC_LENGTH(key_type, key_bits, alg) \ + ((alg) & PSA_ALG_MAC_TRUNCATION_MASK ? PSA_MAC_TRUNCATED_LENGTH(alg) : \ + PSA_ALG_IS_HMAC(alg) ? PSA_HASH_LENGTH(PSA_ALG_HMAC_GET_HASH(alg)) : \ + PSA_ALG_IS_BLOCK_CIPHER_MAC(alg) ? PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) : \ + ((void)(key_type), (void)(key_bits), 0)) + +/** The maximum size of the output of psa_aead_encrypt(), in bytes. + * + * If the size of the ciphertext buffer is at least this large, it is + * guaranteed that psa_aead_encrypt() will not fail due to an + * insufficient buffer size. Depending on the algorithm, the actual size of + * the ciphertext may be smaller. + * + * See also #PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(\p plaintext_length). + * + * \warning This macro may evaluate its arguments multiple times or + * zero times, so you should not pass arguments that contain + * side effects. + * + * \param key_type A symmetric key type that is + * compatible with algorithm \p alg. + * \param alg An AEAD algorithm + * (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_AEAD(\p alg) is true). + * \param plaintext_length Size of the plaintext in bytes. + * + * \return The AEAD ciphertext size for the specified + * algorithm. + * If the key type or AEAD algorithm is not + * recognized, or the parameters are incompatible, + * return 0. + */ +#define PSA_AEAD_ENCRYPT_OUTPUT_SIZE(key_type, alg, plaintext_length) \ + (PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 ? \ + (plaintext_length) + PSA_ALG_AEAD_GET_TAG_LENGTH(alg) : \ + 0) + +/** A sufficient output buffer size for psa_aead_encrypt(), for any of the + * supported key types and AEAD algorithms. + * + * If the size of the ciphertext buffer is at least this large, it is guaranteed + * that psa_aead_encrypt() will not fail due to an insufficient buffer size. + * + * \note This macro returns a compile-time constant if its arguments are + * compile-time constants. + * + * See also #PSA_AEAD_ENCRYPT_OUTPUT_SIZE(\p key_type, \p alg, + * \p plaintext_length). + * + * \param plaintext_length Size of the plaintext in bytes. + * + * \return A sufficient output buffer size for any of the + * supported key types and AEAD algorithms. + * + */ +#define PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(plaintext_length) \ + ((plaintext_length) + PSA_AEAD_TAG_MAX_SIZE) + + +/** The maximum size of the output of psa_aead_decrypt(), in bytes. + * + * If the size of the plaintext buffer is at least this large, it is + * guaranteed that psa_aead_decrypt() will not fail due to an + * insufficient buffer size. Depending on the algorithm, the actual size of + * the plaintext may be smaller. + * + * See also #PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE(\p ciphertext_length). + * + * \warning This macro may evaluate its arguments multiple times or + * zero times, so you should not pass arguments that contain + * side effects. + * + * \param key_type A symmetric key type that is + * compatible with algorithm \p alg. + * \param alg An AEAD algorithm + * (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_AEAD(\p alg) is true). + * \param ciphertext_length Size of the plaintext in bytes. + * + * \return The AEAD ciphertext size for the specified + * algorithm. + * If the key type or AEAD algorithm is not + * recognized, or the parameters are incompatible, + * return 0. + */ +#define PSA_AEAD_DECRYPT_OUTPUT_SIZE(key_type, alg, ciphertext_length) \ + (PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 && \ + (ciphertext_length) > PSA_ALG_AEAD_GET_TAG_LENGTH(alg) ? \ + (ciphertext_length) - PSA_ALG_AEAD_GET_TAG_LENGTH(alg) : \ + 0) + +/** A sufficient output buffer size for psa_aead_decrypt(), for any of the + * supported key types and AEAD algorithms. + * + * If the size of the plaintext buffer is at least this large, it is guaranteed + * that psa_aead_decrypt() will not fail due to an insufficient buffer size. + * + * \note This macro returns a compile-time constant if its arguments are + * compile-time constants. + * + * See also #PSA_AEAD_DECRYPT_OUTPUT_SIZE(\p key_type, \p alg, + * \p ciphertext_length). + * + * \param ciphertext_length Size of the ciphertext in bytes. + * + * \return A sufficient output buffer size for any of the + * supported key types and AEAD algorithms. + * + */ +#define PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE(ciphertext_length) \ + (ciphertext_length) + +/** The default nonce size for an AEAD algorithm, in bytes. + * + * This macro can be used to allocate a buffer of sufficient size to + * store the nonce output from #psa_aead_generate_nonce(). + * + * See also #PSA_AEAD_NONCE_MAX_SIZE. + * + * \note This is not the maximum size of nonce supported as input to + * #psa_aead_set_nonce(), #psa_aead_encrypt() or #psa_aead_decrypt(), + * just the default size that is generated by #psa_aead_generate_nonce(). + * + * \warning This macro may evaluate its arguments multiple times or + * zero times, so you should not pass arguments that contain + * side effects. + * + * \param key_type A symmetric key type that is compatible with + * algorithm \p alg. + * + * \param alg An AEAD algorithm (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_AEAD(\p alg) is true). + * + * \return The default nonce size for the specified key type and algorithm. + * If the key type or AEAD algorithm is not recognized, + * or the parameters are incompatible, return 0. + */ +#define PSA_AEAD_NONCE_LENGTH(key_type, alg) \ + (PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) == 16 ? \ + MBEDTLS_PSA_ALG_AEAD_EQUAL(alg, PSA_ALG_CCM) ? 13 : \ + MBEDTLS_PSA_ALG_AEAD_EQUAL(alg, PSA_ALG_GCM) ? 12 : \ + 0 : \ + (key_type) == PSA_KEY_TYPE_CHACHA20 && \ + MBEDTLS_PSA_ALG_AEAD_EQUAL(alg, PSA_ALG_CHACHA20_POLY1305) ? 12 : \ + 0) + +/** The maximum default nonce size among all supported pairs of key types and + * AEAD algorithms, in bytes. + * + * This is equal to or greater than any value that #PSA_AEAD_NONCE_LENGTH() + * may return. + * + * \note This is not the maximum size of nonce supported as input to + * #psa_aead_set_nonce(), #psa_aead_encrypt() or #psa_aead_decrypt(), + * just the largest size that may be generated by + * #psa_aead_generate_nonce(). + */ +#define PSA_AEAD_NONCE_MAX_SIZE 13 + +/** A sufficient output buffer size for psa_aead_update(). + * + * If the size of the output buffer is at least this large, it is + * guaranteed that psa_aead_update() will not fail due to an + * insufficient buffer size. The actual size of the output may be smaller + * in any given call. + * + * See also #PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(\p input_length). + * + * \warning This macro may evaluate its arguments multiple times or + * zero times, so you should not pass arguments that contain + * side effects. + * + * \param key_type A symmetric key type that is + * compatible with algorithm \p alg. + * \param alg An AEAD algorithm + * (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_AEAD(\p alg) is true). + * \param input_length Size of the input in bytes. + * + * \return A sufficient output buffer size for the specified + * algorithm. + * If the key type or AEAD algorithm is not + * recognized, or the parameters are incompatible, + * return 0. + */ +/* For all the AEAD modes defined in this specification, it is possible + * to emit output without delay. However, hardware may not always be + * capable of this. So for modes based on a block cipher, allow the + * implementation to delay the output until it has a full block. */ +#define PSA_AEAD_UPDATE_OUTPUT_SIZE(key_type, alg, input_length) \ + (PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 ? \ + PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) ? \ + PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type), (input_length)) : \ + (input_length) : \ + 0) + +/** A sufficient output buffer size for psa_aead_update(), for any of the + * supported key types and AEAD algorithms. + * + * If the size of the output buffer is at least this large, it is guaranteed + * that psa_aead_update() will not fail due to an insufficient buffer size. + * + * See also #PSA_AEAD_UPDATE_OUTPUT_SIZE(\p key_type, \p alg, \p input_length). + * + * \param input_length Size of the input in bytes. + */ +#define PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(input_length) \ + (PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE, (input_length))) + +/** A sufficient ciphertext buffer size for psa_aead_finish(). + * + * If the size of the ciphertext buffer is at least this large, it is + * guaranteed that psa_aead_finish() will not fail due to an + * insufficient ciphertext buffer size. The actual size of the output may + * be smaller in any given call. + * + * See also #PSA_AEAD_FINISH_OUTPUT_MAX_SIZE. + * + * \param key_type A symmetric key type that is + compatible with algorithm \p alg. + * \param alg An AEAD algorithm + * (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_AEAD(\p alg) is true). + * + * \return A sufficient ciphertext buffer size for the + * specified algorithm. + * If the key type or AEAD algorithm is not + * recognized, or the parameters are incompatible, + * return 0. + */ +#define PSA_AEAD_FINISH_OUTPUT_SIZE(key_type, alg) \ + (PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 && \ + PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) ? \ + PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) : \ + 0) + +/** A sufficient ciphertext buffer size for psa_aead_finish(), for any of the + * supported key types and AEAD algorithms. + * + * See also #PSA_AEAD_FINISH_OUTPUT_SIZE(\p key_type, \p alg). + */ +#define PSA_AEAD_FINISH_OUTPUT_MAX_SIZE (PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE) + +/** A sufficient plaintext buffer size for psa_aead_verify(). + * + * If the size of the plaintext buffer is at least this large, it is + * guaranteed that psa_aead_verify() will not fail due to an + * insufficient plaintext buffer size. The actual size of the output may + * be smaller in any given call. + * + * See also #PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE. + * + * \param key_type A symmetric key type that is + * compatible with algorithm \p alg. + * \param alg An AEAD algorithm + * (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_AEAD(\p alg) is true). + * + * \return A sufficient plaintext buffer size for the + * specified algorithm. + * If the key type or AEAD algorithm is not + * recognized, or the parameters are incompatible, + * return 0. + */ +#define PSA_AEAD_VERIFY_OUTPUT_SIZE(key_type, alg) \ + (PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 && \ + PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) ? \ + PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) : \ + 0) + +/** A sufficient plaintext buffer size for psa_aead_verify(), for any of the + * supported key types and AEAD algorithms. + * + * See also #PSA_AEAD_VERIFY_OUTPUT_SIZE(\p key_type, \p alg). + */ +#define PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE (PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE) + +#define PSA_RSA_MINIMUM_PADDING_SIZE(alg) \ + (PSA_ALG_IS_RSA_OAEP(alg) ? \ + 2 * PSA_HASH_LENGTH(PSA_ALG_RSA_OAEP_GET_HASH(alg)) + 1 : \ + 11 /*PKCS#1v1.5*/) + +/** + * \brief ECDSA signature size for a given curve bit size + * + * \param curve_bits Curve size in bits. + * \return Signature size in bytes. + * + * \note This macro returns a compile-time constant if its argument is one. + */ +#define PSA_ECDSA_SIGNATURE_SIZE(curve_bits) \ + (PSA_BITS_TO_BYTES(curve_bits) * 2) + +/** Sufficient signature buffer size for psa_sign_hash(). + * + * This macro returns a sufficient buffer size for a signature using a key + * of the specified type and size, with the specified algorithm. + * Note that the actual size of the signature may be smaller + * (some algorithms produce a variable-size signature). + * + * \warning This function may call its arguments multiple times or + * zero times, so you should not pass arguments that contain + * side effects. + * + * \param key_type An asymmetric key type (this may indifferently be a + * key pair type or a public key type). + * \param key_bits The size of the key in bits. + * \param alg The signature algorithm. + * + * \return If the parameters are valid and supported, return + * a buffer size in bytes that guarantees that + * psa_sign_hash() will not fail with + * #PSA_ERROR_BUFFER_TOO_SMALL. + * If the parameters are a valid combination that is not supported, + * return either a sensible size or 0. + * If the parameters are not valid, the + * return value is unspecified. + */ +#define PSA_SIGN_OUTPUT_SIZE(key_type, key_bits, alg) \ + (PSA_KEY_TYPE_IS_RSA(key_type) ? ((void)alg, PSA_BITS_TO_BYTES(key_bits)) : \ + PSA_KEY_TYPE_IS_ECC(key_type) ? PSA_ECDSA_SIGNATURE_SIZE(key_bits) : \ + ((void)alg, 0)) + +#define PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE \ + PSA_ECDSA_SIGNATURE_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS) + +/** \def PSA_SIGNATURE_MAX_SIZE + * + * Maximum size of an asymmetric signature. + * + * This macro expands to a compile-time constant integer. This value + * is the maximum size of a signature in bytes. + */ +#define PSA_SIGNATURE_MAX_SIZE \ + (PSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS) > PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE ? \ + PSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS) : \ + PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE) + +/** Sufficient output buffer size for psa_asymmetric_encrypt(). + * + * This macro returns a sufficient buffer size for a ciphertext produced using + * a key of the specified type and size, with the specified algorithm. + * Note that the actual size of the ciphertext may be smaller, depending + * on the algorithm. + * + * \warning This function may call its arguments multiple times or + * zero times, so you should not pass arguments that contain + * side effects. + * + * \param key_type An asymmetric key type (this may indifferently be a + * key pair type or a public key type). + * \param key_bits The size of the key in bits. + * \param alg The asymmetric encryption algorithm. + * + * \return If the parameters are valid and supported, return + * a buffer size in bytes that guarantees that + * psa_asymmetric_encrypt() will not fail with + * #PSA_ERROR_BUFFER_TOO_SMALL. + * If the parameters are a valid combination that is not supported, + * return either a sensible size or 0. + * If the parameters are not valid, the + * return value is unspecified. + */ +#define PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(key_type, key_bits, alg) \ + (PSA_KEY_TYPE_IS_RSA(key_type) ? \ + ((void)alg, PSA_BITS_TO_BYTES(key_bits)) : \ + 0) + +/** A sufficient output buffer size for psa_asymmetric_encrypt(), for any + * supported asymmetric encryption. + * + * See also #PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(\p key_type, \p key_bits, \p alg). + */ +/* This macro assumes that RSA is the only supported asymmetric encryption. */ +#define PSA_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE \ + (PSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS)) + +/** Sufficient output buffer size for psa_asymmetric_decrypt(). + * + * This macro returns a sufficient buffer size for a plaintext produced using + * a key of the specified type and size, with the specified algorithm. + * Note that the actual size of the plaintext may be smaller, depending + * on the algorithm. + * + * \warning This function may call its arguments multiple times or + * zero times, so you should not pass arguments that contain + * side effects. + * + * \param key_type An asymmetric key type (this may indifferently be a + * key pair type or a public key type). + * \param key_bits The size of the key in bits. + * \param alg The asymmetric encryption algorithm. + * + * \return If the parameters are valid and supported, return + * a buffer size in bytes that guarantees that + * psa_asymmetric_decrypt() will not fail with + * #PSA_ERROR_BUFFER_TOO_SMALL. + * If the parameters are a valid combination that is not supported, + * return either a sensible size or 0. + * If the parameters are not valid, the + * return value is unspecified. + */ +#define PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(key_type, key_bits, alg) \ + (PSA_KEY_TYPE_IS_RSA(key_type) ? \ + PSA_BITS_TO_BYTES(key_bits) - PSA_RSA_MINIMUM_PADDING_SIZE(alg) : \ + 0) + +/** A sufficient output buffer size for psa_asymmetric_decrypt(), for any + * supported asymmetric decryption. + * + * This macro assumes that RSA is the only supported asymmetric encryption. + * + * See also #PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(\p key_type, \p key_bits, \p alg). + */ +#define PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE \ + (PSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS)) + +/* Maximum size of the ASN.1 encoding of an INTEGER with the specified + * number of bits. + * + * This definition assumes that bits <= 2^19 - 9 so that the length field + * is at most 3 bytes. The length of the encoding is the length of the + * bit string padded to a whole number of bytes plus: + * - 1 type byte; + * - 1 to 3 length bytes; + * - 0 to 1 bytes of leading 0 due to the sign bit. + */ +#define PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE(bits) \ + ((bits) / 8 + 5) + +/* Maximum size of the export encoding of an RSA public key. + * Assumes that the public exponent is less than 2^32. + * + * RSAPublicKey ::= SEQUENCE { + * modulus INTEGER, -- n + * publicExponent INTEGER } -- e + * + * - 4 bytes of SEQUENCE overhead; + * - n : INTEGER; + * - 7 bytes for the public exponent. + */ +#define PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(key_bits) \ + (PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE(key_bits) + 11) + +/* Maximum size of the export encoding of an RSA key pair. + * Assumes thatthe public exponent is less than 2^32 and that the size + * difference between the two primes is at most 1 bit. + * + * RSAPrivateKey ::= SEQUENCE { + * version Version, -- 0 + * modulus INTEGER, -- N-bit + * publicExponent INTEGER, -- 32-bit + * privateExponent INTEGER, -- N-bit + * prime1 INTEGER, -- N/2-bit + * prime2 INTEGER, -- N/2-bit + * exponent1 INTEGER, -- N/2-bit + * exponent2 INTEGER, -- N/2-bit + * coefficient INTEGER, -- N/2-bit + * } + * + * - 4 bytes of SEQUENCE overhead; + * - 3 bytes of version; + * - 7 half-size INTEGERs plus 2 full-size INTEGERs, + * overapproximated as 9 half-size INTEGERS; + * - 7 bytes for the public exponent. + */ +#define PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(key_bits) \ + (9 * PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE((key_bits) / 2 + 1) + 14) + +/* Maximum size of the export encoding of a DSA public key. + * + * SubjectPublicKeyInfo ::= SEQUENCE { + * algorithm AlgorithmIdentifier, + * subjectPublicKey BIT STRING } -- contains DSAPublicKey + * AlgorithmIdentifier ::= SEQUENCE { + * algorithm OBJECT IDENTIFIER, + * parameters Dss-Parms } -- SEQUENCE of 3 INTEGERs + * DSAPublicKey ::= INTEGER -- public key, Y + * + * - 3 * 4 bytes of SEQUENCE overhead; + * - 1 + 1 + 7 bytes of algorithm (DSA OID); + * - 4 bytes of BIT STRING overhead; + * - 3 full-size INTEGERs (p, g, y); + * - 1 + 1 + 32 bytes for 1 sub-size INTEGER (q <= 256 bits). + */ +#define PSA_KEY_EXPORT_DSA_PUBLIC_KEY_MAX_SIZE(key_bits) \ + (PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE(key_bits) * 3 + 59) + +/* Maximum size of the export encoding of a DSA key pair. + * + * DSAPrivateKey ::= SEQUENCE { + * version Version, -- 0 + * prime INTEGER, -- p + * subprime INTEGER, -- q + * generator INTEGER, -- g + * public INTEGER, -- y + * private INTEGER, -- x + * } + * + * - 4 bytes of SEQUENCE overhead; + * - 3 bytes of version; + * - 3 full-size INTEGERs (p, g, y); + * - 2 * (1 + 1 + 32) bytes for 2 sub-size INTEGERs (q, x <= 256 bits). + */ +#define PSA_KEY_EXPORT_DSA_KEY_PAIR_MAX_SIZE(key_bits) \ + (PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE(key_bits) * 3 + 75) + +/* Maximum size of the export encoding of an ECC public key. + * + * The representation of an ECC public key is: + * - The byte 0x04; + * - `x_P` as a `ceiling(m/8)`-byte string, big-endian; + * - `y_P` as a `ceiling(m/8)`-byte string, big-endian; + * - where m is the bit size associated with the curve. + * + * - 1 byte + 2 * point size. + */ +#define PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_bits) \ + (2 * PSA_BITS_TO_BYTES(key_bits) + 1) + +/* Maximum size of the export encoding of an ECC key pair. + * + * An ECC key pair is represented by the secret value. + */ +#define PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(key_bits) \ + (PSA_BITS_TO_BYTES(key_bits)) + +/** Sufficient output buffer size for psa_export_key() or + * psa_export_public_key(). + * + * This macro returns a compile-time constant if its arguments are + * compile-time constants. + * + * \warning This macro may evaluate its arguments multiple times or + * zero times, so you should not pass arguments that contain + * side effects. + * + * The following code illustrates how to allocate enough memory to export + * a key by querying the key type and size at runtime. + * \code{c} + * psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; + * psa_status_t status; + * status = psa_get_key_attributes(key, &attributes); + * if (status != PSA_SUCCESS) handle_error(...); + * psa_key_type_t key_type = psa_get_key_type(&attributes); + * size_t key_bits = psa_get_key_bits(&attributes); + * size_t buffer_size = PSA_EXPORT_KEY_OUTPUT_SIZE(key_type, key_bits); + * psa_reset_key_attributes(&attributes); + * uint8_t *buffer = malloc(buffer_size); + * if (buffer == NULL) handle_error(...); + * size_t buffer_length; + * status = psa_export_key(key, buffer, buffer_size, &buffer_length); + * if (status != PSA_SUCCESS) handle_error(...); + * \endcode + * + * \param key_type A supported key type. + * \param key_bits The size of the key in bits. + * + * \return If the parameters are valid and supported, return + * a buffer size in bytes that guarantees that + * psa_export_key() or psa_export_public_key() will not fail with + * #PSA_ERROR_BUFFER_TOO_SMALL. + * If the parameters are a valid combination that is not supported, + * return either a sensible size or 0. + * If the parameters are not valid, the return value is unspecified. + */ +#define PSA_EXPORT_KEY_OUTPUT_SIZE(key_type, key_bits) \ + (PSA_KEY_TYPE_IS_UNSTRUCTURED(key_type) ? PSA_BITS_TO_BYTES(key_bits) : \ + (key_type) == PSA_KEY_TYPE_RSA_KEY_PAIR ? PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(key_bits) : \ + (key_type) == PSA_KEY_TYPE_RSA_PUBLIC_KEY ? PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(key_bits) : \ + (key_type) == PSA_KEY_TYPE_DSA_KEY_PAIR ? PSA_KEY_EXPORT_DSA_KEY_PAIR_MAX_SIZE(key_bits) : \ + (key_type) == PSA_KEY_TYPE_DSA_PUBLIC_KEY ? PSA_KEY_EXPORT_DSA_PUBLIC_KEY_MAX_SIZE(key_bits) : \ + PSA_KEY_TYPE_IS_ECC_KEY_PAIR(key_type) ? PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(key_bits) : \ + PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(key_type) ? PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_bits) : \ + 0) + +/** Sufficient output buffer size for psa_export_public_key(). + * + * This macro returns a compile-time constant if its arguments are + * compile-time constants. + * + * \warning This macro may evaluate its arguments multiple times or + * zero times, so you should not pass arguments that contain + * side effects. + * + * The following code illustrates how to allocate enough memory to export + * a public key by querying the key type and size at runtime. + * \code{c} + * psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; + * psa_status_t status; + * status = psa_get_key_attributes(key, &attributes); + * if (status != PSA_SUCCESS) handle_error(...); + * psa_key_type_t key_type = psa_get_key_type(&attributes); + * size_t key_bits = psa_get_key_bits(&attributes); + * size_t buffer_size = PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(key_type, key_bits); + * psa_reset_key_attributes(&attributes); + * uint8_t *buffer = malloc(buffer_size); + * if (buffer == NULL) handle_error(...); + * size_t buffer_length; + * status = psa_export_public_key(key, buffer, buffer_size, &buffer_length); + * if (status != PSA_SUCCESS) handle_error(...); + * \endcode + * + * \param key_type A public key or key pair key type. + * \param key_bits The size of the key in bits. + * + * \return If the parameters are valid and supported, return + * a buffer size in bytes that guarantees that + * psa_export_public_key() will not fail with + * #PSA_ERROR_BUFFER_TOO_SMALL. + * If the parameters are a valid combination that is not + * supported, return either a sensible size or 0. + * If the parameters are not valid, + * the return value is unspecified. + * + * If the parameters are valid and supported, + * return the same result as + * #PSA_EXPORT_KEY_OUTPUT_SIZE( + * \p #PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(\p key_type), + * \p key_bits). + */ +#define PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(key_type, key_bits) \ + (PSA_KEY_TYPE_IS_RSA(key_type) ? PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(key_bits) : \ + PSA_KEY_TYPE_IS_ECC(key_type) ? PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_bits) : \ + 0) + +/** Sufficient buffer size for exporting any asymmetric key pair. + * + * This macro expands to a compile-time constant integer. This value is + * a sufficient buffer size when calling psa_export_key() to export any + * asymmetric key pair, regardless of the exact key type and key size. + * + * See also #PSA_EXPORT_KEY_OUTPUT_SIZE(\p key_type, \p key_bits). + */ +#define PSA_EXPORT_KEY_PAIR_MAX_SIZE \ + (PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS) > \ + PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS) ? \ + PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS) : \ + PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)) + +/** Sufficient buffer size for exporting any asymmetric public key. + * + * This macro expands to a compile-time constant integer. This value is + * a sufficient buffer size when calling psa_export_key() or + * psa_export_public_key() to export any asymmetric public key, + * regardless of the exact key type and key size. + * + * See also #PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(\p key_type, \p key_bits). + */ +#define PSA_EXPORT_PUBLIC_KEY_MAX_SIZE \ + (PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS) > \ + PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS) ? \ + PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS) : \ + PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)) + +/** Sufficient output buffer size for psa_raw_key_agreement(). + * + * This macro returns a compile-time constant if its arguments are + * compile-time constants. + * + * \warning This macro may evaluate its arguments multiple times or + * zero times, so you should not pass arguments that contain + * side effects. + * + * See also #PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE. + * + * \param key_type A supported key type. + * \param key_bits The size of the key in bits. + * + * \return If the parameters are valid and supported, return + * a buffer size in bytes that guarantees that + * psa_raw_key_agreement() will not fail with + * #PSA_ERROR_BUFFER_TOO_SMALL. + * If the parameters are a valid combination that + * is not supported, return either a sensible size or 0. + * If the parameters are not valid, + * the return value is unspecified. + */ +/* FFDH is not yet supported in PSA. */ +#define PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE(key_type, key_bits) \ + (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(key_type) ? \ + PSA_BITS_TO_BYTES(key_bits) : \ + 0) + +/** Maximum size of the output from psa_raw_key_agreement(). + * + * This macro expands to a compile-time constant integer. This value is the + * maximum size of the output any raw key agreement algorithm, in bytes. + * + * See also #PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE(\p key_type, \p key_bits). + */ +#define PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE \ + (PSA_BITS_TO_BYTES(PSA_VENDOR_ECC_MAX_CURVE_BITS)) + +/** The default IV size for a cipher algorithm, in bytes. + * + * The IV that is generated as part of a call to #psa_cipher_encrypt() is always + * the default IV length for the algorithm. + * + * This macro can be used to allocate a buffer of sufficient size to + * store the IV output from #psa_cipher_generate_iv() when using + * a multi-part cipher operation. + * + * See also #PSA_CIPHER_IV_MAX_SIZE. + * + * \warning This macro may evaluate its arguments multiple times or + * zero times, so you should not pass arguments that contain + * side effects. + * + * \param key_type A symmetric key type that is compatible with algorithm \p alg. + * + * \param alg A cipher algorithm (\c PSA_ALG_XXX value such that #PSA_ALG_IS_CIPHER(\p alg) is true). + * + * \return The default IV size for the specified key type and algorithm. + * If the algorithm does not use an IV, return 0. + * If the key type or cipher algorithm is not recognized, + * or the parameters are incompatible, return 0. + */ +#define PSA_CIPHER_IV_LENGTH(key_type, alg) \ + (PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) > 1 && \ + ((alg) == PSA_ALG_CTR || \ + (alg) == PSA_ALG_CFB || \ + (alg) == PSA_ALG_OFB || \ + (alg) == PSA_ALG_XTS || \ + (alg) == PSA_ALG_CBC_NO_PADDING || \ + (alg) == PSA_ALG_CBC_PKCS7) ? PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) : \ + (key_type) == PSA_KEY_TYPE_CHACHA20 && \ + (alg) == PSA_ALG_STREAM_CIPHER ? 12 : \ + 0) + +/** The maximum IV size for all supported cipher algorithms, in bytes. + * + * See also #PSA_CIPHER_IV_LENGTH(). + */ +#define PSA_CIPHER_IV_MAX_SIZE 16 + +/** The maximum size of the output of psa_cipher_encrypt(), in bytes. + * + * If the size of the output buffer is at least this large, it is guaranteed + * that psa_cipher_encrypt() will not fail due to an insufficient buffer size. + * Depending on the algorithm, the actual size of the output might be smaller. + * + * See also #PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(\p input_length). + * + * \warning This macro may evaluate its arguments multiple times or + * zero times, so you should not pass arguments that contain + * side effects. + * + * \param key_type A symmetric key type that is compatible with algorithm + * alg. + * \param alg A cipher algorithm (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_CIPHER(\p alg) is true). + * \param input_length Size of the input in bytes. + * + * \return A sufficient output size for the specified key type and + * algorithm. If the key type or cipher algorithm is not + * recognized, or the parameters are incompatible, + * return 0. + */ +#define PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg, input_length) \ + (alg == PSA_ALG_CBC_PKCS7 ? \ + (PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) != 0 ? \ + PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type), \ + (input_length) + 1) + \ + PSA_CIPHER_IV_LENGTH((key_type), (alg)) : 0) : \ + (PSA_ALG_IS_CIPHER(alg) ? \ + (input_length) + PSA_CIPHER_IV_LENGTH((key_type), (alg)) : \ + 0)) + +/** A sufficient output buffer size for psa_cipher_encrypt(), for any of the + * supported key types and cipher algorithms. + * + * If the size of the output buffer is at least this large, it is guaranteed + * that psa_cipher_encrypt() will not fail due to an insufficient buffer size. + * + * See also #PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(\p key_type, \p alg, \p input_length). + * + * \param input_length Size of the input in bytes. + * + */ +#define PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(input_length) \ + (PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE, \ + (input_length) + 1) + \ + PSA_CIPHER_IV_MAX_SIZE) + +/** The maximum size of the output of psa_cipher_decrypt(), in bytes. + * + * If the size of the output buffer is at least this large, it is guaranteed + * that psa_cipher_decrypt() will not fail due to an insufficient buffer size. + * Depending on the algorithm, the actual size of the output might be smaller. + * + * See also #PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE(\p input_length). + * + * \param key_type A symmetric key type that is compatible with algorithm + * alg. + * \param alg A cipher algorithm (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_CIPHER(\p alg) is true). + * \param input_length Size of the input in bytes. + * + * \return A sufficient output size for the specified key type and + * algorithm. If the key type or cipher algorithm is not + * recognized, or the parameters are incompatible, + * return 0. + */ +#define PSA_CIPHER_DECRYPT_OUTPUT_SIZE(key_type, alg, input_length) \ + (PSA_ALG_IS_CIPHER(alg) && \ + ((key_type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_SYMMETRIC ? \ + (input_length) : \ + 0) + +/** A sufficient output buffer size for psa_cipher_decrypt(), for any of the + * supported key types and cipher algorithms. + * + * If the size of the output buffer is at least this large, it is guaranteed + * that psa_cipher_decrypt() will not fail due to an insufficient buffer size. + * + * See also #PSA_CIPHER_DECRYPT_OUTPUT_SIZE(\p key_type, \p alg, \p input_length). + * + * \param input_length Size of the input in bytes. + */ +#define PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE(input_length) \ + (input_length) + +/** A sufficient output buffer size for psa_cipher_update(). + * + * If the size of the output buffer is at least this large, it is guaranteed + * that psa_cipher_update() will not fail due to an insufficient buffer size. + * The actual size of the output might be smaller in any given call. + * + * See also #PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE(\p input_length). + * + * \param key_type A symmetric key type that is compatible with algorithm + * alg. + * \param alg A cipher algorithm (PSA_ALG_XXX value such that + * #PSA_ALG_IS_CIPHER(\p alg) is true). + * \param input_length Size of the input in bytes. + * + * \return A sufficient output size for the specified key type and + * algorithm. If the key type or cipher algorithm is not + * recognized, or the parameters are incompatible, return 0. + */ +#define PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type, alg, input_length) \ + (PSA_ALG_IS_CIPHER(alg) ? \ + (PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) != 0 ? \ + (((alg) == PSA_ALG_CBC_PKCS7 || \ + (alg) == PSA_ALG_CBC_NO_PADDING || \ + (alg) == PSA_ALG_ECB_NO_PADDING) ? \ + PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type), \ + input_length) : \ + (input_length)) : 0) : \ + 0) + +/** A sufficient output buffer size for psa_cipher_update(), for any of the + * supported key types and cipher algorithms. + * + * If the size of the output buffer is at least this large, it is guaranteed + * that psa_cipher_update() will not fail due to an insufficient buffer size. + * + * See also #PSA_CIPHER_UPDATE_OUTPUT_SIZE(\p key_type, \p alg, \p input_length). + * + * \param input_length Size of the input in bytes. + */ +#define PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE(input_length) \ + (PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE, input_length)) + +/** A sufficient ciphertext buffer size for psa_cipher_finish(). + * + * If the size of the ciphertext buffer is at least this large, it is + * guaranteed that psa_cipher_finish() will not fail due to an insufficient + * ciphertext buffer size. The actual size of the output might be smaller in + * any given call. + * + * See also #PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE(). + * + * \param key_type A symmetric key type that is compatible with algorithm + * alg. + * \param alg A cipher algorithm (PSA_ALG_XXX value such that + * #PSA_ALG_IS_CIPHER(\p alg) is true). + * \return A sufficient output size for the specified key type and + * algorithm. If the key type or cipher algorithm is not + * recognized, or the parameters are incompatible, return 0. + */ +#define PSA_CIPHER_FINISH_OUTPUT_SIZE(key_type, alg) \ + (PSA_ALG_IS_CIPHER(alg) ? \ + (alg == PSA_ALG_CBC_PKCS7 ? \ + PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) : \ + 0) : \ + 0) + +/** A sufficient ciphertext buffer size for psa_cipher_finish(), for any of the + * supported key types and cipher algorithms. + * + * See also #PSA_CIPHER_FINISH_OUTPUT_SIZE(\p key_type, \p alg). + */ +#define PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE \ + (PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE) + +#endif /* PSA_CRYPTO_SIZES_H */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_struct.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_struct.h new file mode 100644 index 00000000000..23a02a5d8ef --- /dev/null +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_struct.h @@ -0,0 +1,478 @@ +/** + * \file psa/crypto_struct.h + * + * \brief PSA cryptography module: Mbed TLS structured type implementations + * + * \note This file may not be included directly. Applications must + * include psa/crypto.h. + * + * This file contains the definitions of some data structures with + * implementation-specific definitions. + * + * In implementations with isolation between the application and the + * cryptography module, it is expected that the front-end and the back-end + * would have different versions of this file. + * + *

Design notes about multipart operation structures

+ * + * For multipart operations without driver delegation support, each multipart + * operation structure contains a `psa_algorithm_t alg` field which indicates + * which specific algorithm the structure is for. When the structure is not in + * use, `alg` is 0. Most of the structure consists of a union which is + * discriminated by `alg`. + * + * For multipart operations with driver delegation support, each multipart + * operation structure contains an `unsigned int id` field indicating which + * driver got assigned to do the operation. When the structure is not in use, + * 'id' is 0. The structure contains also a driver context which is the union + * of the contexts of all drivers able to handle the type of multipart + * operation. + * + * Note that when `alg` or `id` is 0, the content of other fields is undefined. + * In particular, it is not guaranteed that a freshly-initialized structure + * is all-zero: we initialize structures to something like `{0, 0}`, which + * is only guaranteed to initializes the first member of the union; + * GCC and Clang initialize the whole structure to 0 (at the time of writing), + * but MSVC and CompCert don't. + * + * In Mbed Crypto, multipart operation structures live independently from + * the key. This allows Mbed Crypto to free the key objects when destroying + * a key slot. If a multipart operation needs to remember the key after + * the setup function returns, the operation structure needs to contain a + * copy of the key. + */ +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PSA_CRYPTO_STRUCT_H +#define PSA_CRYPTO_STRUCT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Include the Mbed TLS configuration file, the way Mbed TLS does it + * in each of its header files. */ +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls/config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#include "mbedtls/cmac.h" +#include "mbedtls/gcm.h" + +/* Include the context definition for the compiled-in drivers for the primitive + * algorithms. */ +#include "psa/crypto_driver_contexts_primitives.h" + +struct psa_hash_operation_s +{ + /** Unique ID indicating which driver got assigned to do the + * operation. Since driver contexts are driver-specific, swapping + * drivers halfway through the operation is not supported. + * ID values are auto-generated in psa_driver_wrappers.h. + * ID value zero means the context is not valid or not assigned to + * any driver (i.e. the driver context is not active, in use). */ + unsigned int id; + psa_driver_hash_context_t ctx; +}; + +#define PSA_HASH_OPERATION_INIT {0, {0}} +static inline struct psa_hash_operation_s psa_hash_operation_init( void ) +{ + const struct psa_hash_operation_s v = PSA_HASH_OPERATION_INIT; + return( v ); +} + +struct psa_cipher_operation_s +{ + /** Unique ID indicating which driver got assigned to do the + * operation. Since driver contexts are driver-specific, swapping + * drivers halfway through the operation is not supported. + * ID values are auto-generated in psa_crypto_driver_wrappers.h + * ID value zero means the context is not valid or not assigned to + * any driver (i.e. none of the driver contexts are active). */ + unsigned int id; + + unsigned int iv_required : 1; + unsigned int iv_set : 1; + + uint8_t default_iv_length; + + psa_driver_cipher_context_t ctx; +}; + +#define PSA_CIPHER_OPERATION_INIT {0, 0, 0, 0, {0}} +static inline struct psa_cipher_operation_s psa_cipher_operation_init( void ) +{ + const struct psa_cipher_operation_s v = PSA_CIPHER_OPERATION_INIT; + return( v ); +} + +/* Include the context definition for the compiled-in drivers for the composite + * algorithms. */ +#include "psa/crypto_driver_contexts_composites.h" + +struct psa_mac_operation_s +{ + /** Unique ID indicating which driver got assigned to do the + * operation. Since driver contexts are driver-specific, swapping + * drivers halfway through the operation is not supported. + * ID values are auto-generated in psa_driver_wrappers.h + * ID value zero means the context is not valid or not assigned to + * any driver (i.e. none of the driver contexts are active). */ + unsigned int id; + uint8_t mac_size; + unsigned int is_sign : 1; + psa_driver_mac_context_t ctx; +}; + +#define PSA_MAC_OPERATION_INIT {0, 0, 0, {0}} +static inline struct psa_mac_operation_s psa_mac_operation_init( void ) +{ + const struct psa_mac_operation_s v = PSA_MAC_OPERATION_INIT; + return( v ); +} + +struct psa_aead_operation_s +{ + psa_algorithm_t alg; + unsigned int key_set : 1; + unsigned int iv_set : 1; + uint8_t iv_size; + uint8_t block_size; + union + { + unsigned dummy; /* Enable easier initializing of the union. */ + mbedtls_cipher_context_t cipher; + } ctx; +}; + +#define PSA_AEAD_OPERATION_INIT {0, 0, 0, 0, 0, {0}} +static inline struct psa_aead_operation_s psa_aead_operation_init( void ) +{ + const struct psa_aead_operation_s v = PSA_AEAD_OPERATION_INIT; + return( v ); +} + +#if defined(MBEDTLS_PSA_BUILTIN_ALG_HKDF) +typedef struct +{ + uint8_t *info; + size_t info_length; +#if PSA_HASH_MAX_SIZE > 0xff +#error "PSA_HASH_MAX_SIZE does not fit in uint8_t" +#endif + uint8_t offset_in_block; + uint8_t block_number; + unsigned int state : 2; + unsigned int info_set : 1; + uint8_t output_block[PSA_HASH_MAX_SIZE]; + uint8_t prk[PSA_HASH_MAX_SIZE]; + struct psa_mac_operation_s hmac; +} psa_hkdf_key_derivation_t; +#endif /* MBEDTLS_PSA_BUILTIN_ALG_HKDF */ + +#if defined(MBEDTLS_PSA_BUILTIN_ALG_TLS12_PRF) || \ + defined(MBEDTLS_PSA_BUILTIN_ALG_TLS12_PSK_TO_MS) +typedef enum +{ + PSA_TLS12_PRF_STATE_INIT, /* no input provided */ + PSA_TLS12_PRF_STATE_SEED_SET, /* seed has been set */ + PSA_TLS12_PRF_STATE_KEY_SET, /* key has been set */ + PSA_TLS12_PRF_STATE_LABEL_SET, /* label has been set */ + PSA_TLS12_PRF_STATE_OUTPUT /* output has been started */ +} psa_tls12_prf_key_derivation_state_t; + +typedef struct psa_tls12_prf_key_derivation_s +{ +#if PSA_HASH_MAX_SIZE > 0xff +#error "PSA_HASH_MAX_SIZE does not fit in uint8_t" +#endif + + /* Indicates how many bytes in the current HMAC block have + * not yet been read by the user. */ + uint8_t left_in_block; + + /* The 1-based number of the block. */ + uint8_t block_number; + + psa_tls12_prf_key_derivation_state_t state; + + uint8_t *secret; + size_t secret_length; + uint8_t *seed; + size_t seed_length; + uint8_t *label; + size_t label_length; + + uint8_t Ai[PSA_HASH_MAX_SIZE]; + + /* `HMAC_hash( prk, A(i) + seed )` in the notation of RFC 5246, Sect. 5. */ + uint8_t output_block[PSA_HASH_MAX_SIZE]; +} psa_tls12_prf_key_derivation_t; +#endif /* MBEDTLS_PSA_BUILTIN_ALG_TLS12_PRF) || + * MBEDTLS_PSA_BUILTIN_ALG_TLS12_PSK_TO_MS */ + +struct psa_key_derivation_s +{ + psa_algorithm_t alg; + unsigned int can_output_key : 1; + size_t capacity; + union + { + /* Make the union non-empty even with no supported algorithms. */ + uint8_t dummy; +#if defined(MBEDTLS_PSA_BUILTIN_ALG_HKDF) + psa_hkdf_key_derivation_t hkdf; +#endif +#if defined(MBEDTLS_PSA_BUILTIN_ALG_TLS12_PRF) || \ + defined(MBEDTLS_PSA_BUILTIN_ALG_TLS12_PSK_TO_MS) + psa_tls12_prf_key_derivation_t tls12_prf; +#endif + } ctx; +}; + +/* This only zeroes out the first byte in the union, the rest is unspecified. */ +#define PSA_KEY_DERIVATION_OPERATION_INIT {0, 0, 0, {0}} +static inline struct psa_key_derivation_s psa_key_derivation_operation_init( void ) +{ + const struct psa_key_derivation_s v = PSA_KEY_DERIVATION_OPERATION_INIT; + return( v ); +} + +struct psa_key_policy_s +{ + psa_key_usage_t usage; + psa_algorithm_t alg; + psa_algorithm_t alg2; +}; +typedef struct psa_key_policy_s psa_key_policy_t; + +#define PSA_KEY_POLICY_INIT {0, 0, 0} +static inline struct psa_key_policy_s psa_key_policy_init( void ) +{ + const struct psa_key_policy_s v = PSA_KEY_POLICY_INIT; + return( v ); +} + +/* The type used internally for key sizes. + * Public interfaces use size_t, but internally we use a smaller type. */ +typedef uint16_t psa_key_bits_t; +/* The maximum value of the type used to represent bit-sizes. + * This is used to mark an invalid key size. */ +#define PSA_KEY_BITS_TOO_LARGE ( (psa_key_bits_t) ( -1 ) ) +/* The maximum size of a key in bits. + * Currently defined as the maximum that can be represented, rounded down + * to a whole number of bytes. + * This is an uncast value so that it can be used in preprocessor + * conditionals. */ +#define PSA_MAX_KEY_BITS 0xfff8 + +/** A mask of flags that can be stored in key attributes. + * + * This type is also used internally to store flags in slots. Internal + * flags are defined in library/psa_crypto_core.h. Internal flags may have + * the same value as external flags if they are properly handled during + * key creation and in psa_get_key_attributes. + */ +typedef uint16_t psa_key_attributes_flag_t; + +#define MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER \ + ( (psa_key_attributes_flag_t) 0x0001 ) + +/* A mask of key attribute flags used externally only. + * Only meant for internal checks inside the library. */ +#define MBEDTLS_PSA_KA_MASK_EXTERNAL_ONLY ( \ + MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER | \ + 0 ) + +/* A mask of key attribute flags used both internally and externally. + * Currently there aren't any. */ +#define MBEDTLS_PSA_KA_MASK_DUAL_USE ( \ + 0 ) + +typedef struct +{ + psa_key_type_t type; + psa_key_bits_t bits; + psa_key_lifetime_t lifetime; + mbedtls_svc_key_id_t id; + psa_key_policy_t policy; + psa_key_attributes_flag_t flags; +} psa_core_key_attributes_t; + +#define PSA_CORE_KEY_ATTRIBUTES_INIT {PSA_KEY_TYPE_NONE, 0, PSA_KEY_LIFETIME_VOLATILE, MBEDTLS_SVC_KEY_ID_INIT, PSA_KEY_POLICY_INIT, 0} + +struct psa_key_attributes_s +{ + psa_core_key_attributes_t core; +#if defined(MBEDTLS_PSA_CRYPTO_SE_C) + psa_key_slot_number_t slot_number; +#endif /* MBEDTLS_PSA_CRYPTO_SE_C */ + void *domain_parameters; + size_t domain_parameters_size; +}; + +#if defined(MBEDTLS_PSA_CRYPTO_SE_C) +#define PSA_KEY_ATTRIBUTES_INIT {PSA_CORE_KEY_ATTRIBUTES_INIT, 0, NULL, 0} +#else +#define PSA_KEY_ATTRIBUTES_INIT {PSA_CORE_KEY_ATTRIBUTES_INIT, NULL, 0} +#endif + +static inline struct psa_key_attributes_s psa_key_attributes_init( void ) +{ + const struct psa_key_attributes_s v = PSA_KEY_ATTRIBUTES_INIT; + return( v ); +} + +static inline void psa_set_key_id( psa_key_attributes_t *attributes, + mbedtls_svc_key_id_t key ) +{ + psa_key_lifetime_t lifetime = attributes->core.lifetime; + + attributes->core.id = key; + + if( PSA_KEY_LIFETIME_IS_VOLATILE( lifetime ) ) + { + attributes->core.lifetime = + PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION( + PSA_KEY_LIFETIME_PERSISTENT, + PSA_KEY_LIFETIME_GET_LOCATION( lifetime ) ); + } +} + +static inline mbedtls_svc_key_id_t psa_get_key_id( + const psa_key_attributes_t *attributes) +{ + return( attributes->core.id ); +} + +#ifdef MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER +static inline void mbedtls_set_key_owner_id( psa_key_attributes_t *attributes, + mbedtls_key_owner_id_t owner ) +{ + attributes->core.id.owner = owner; +} +#endif + +static inline void psa_set_key_lifetime(psa_key_attributes_t *attributes, + psa_key_lifetime_t lifetime) +{ + attributes->core.lifetime = lifetime; + if( PSA_KEY_LIFETIME_IS_VOLATILE( lifetime ) ) + { +#ifdef MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER + attributes->core.id.key_id = 0; +#else + attributes->core.id = 0; +#endif + } +} + +static inline psa_key_lifetime_t psa_get_key_lifetime( + const psa_key_attributes_t *attributes) +{ + return( attributes->core.lifetime ); +} + +static inline void psa_extend_key_usage_flags( psa_key_usage_t *usage_flags ) +{ + if( *usage_flags & PSA_KEY_USAGE_SIGN_HASH ) + *usage_flags |= PSA_KEY_USAGE_SIGN_MESSAGE; + + if( *usage_flags & PSA_KEY_USAGE_VERIFY_HASH ) + *usage_flags |= PSA_KEY_USAGE_VERIFY_MESSAGE; +} + +static inline void psa_set_key_usage_flags(psa_key_attributes_t *attributes, + psa_key_usage_t usage_flags) +{ + psa_extend_key_usage_flags( &usage_flags ); + attributes->core.policy.usage = usage_flags; +} + +static inline psa_key_usage_t psa_get_key_usage_flags( + const psa_key_attributes_t *attributes) +{ + return( attributes->core.policy.usage ); +} + +static inline void psa_set_key_algorithm(psa_key_attributes_t *attributes, + psa_algorithm_t alg) +{ + attributes->core.policy.alg = alg; +} + +static inline psa_algorithm_t psa_get_key_algorithm( + const psa_key_attributes_t *attributes) +{ + return( attributes->core.policy.alg ); +} + +/* This function is declared in crypto_extra.h, which comes after this + * header file, but we need the function here, so repeat the declaration. */ +psa_status_t psa_set_key_domain_parameters(psa_key_attributes_t *attributes, + psa_key_type_t type, + const uint8_t *data, + size_t data_length); + +static inline void psa_set_key_type(psa_key_attributes_t *attributes, + psa_key_type_t type) +{ + if( attributes->domain_parameters == NULL ) + { + /* Common case: quick path */ + attributes->core.type = type; + } + else + { + /* Call the bigger function to free the old domain paramteres. + * Ignore any errors which may arise due to type requiring + * non-default domain parameters, since this function can't + * report errors. */ + (void) psa_set_key_domain_parameters( attributes, type, NULL, 0 ); + } +} + +static inline psa_key_type_t psa_get_key_type( + const psa_key_attributes_t *attributes) +{ + return( attributes->core.type ); +} + +static inline void psa_set_key_bits(psa_key_attributes_t *attributes, + size_t bits) +{ + if( bits > PSA_MAX_KEY_BITS ) + attributes->core.bits = PSA_KEY_BITS_TOO_LARGE; + else + attributes->core.bits = (psa_key_bits_t) bits; +} + +static inline size_t psa_get_key_bits( + const psa_key_attributes_t *attributes) +{ + return( attributes->core.bits ); +} + +#ifdef __cplusplus +} +#endif + +#endif /* PSA_CRYPTO_STRUCT_H */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_types.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_types.h new file mode 100644 index 00000000000..386c7d794b4 --- /dev/null +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_types.h @@ -0,0 +1,383 @@ +/** + * \file psa/crypto_types.h + * + * \brief PSA cryptography module: type aliases. + * + * \note This file may not be included directly. Applications must + * include psa/crypto.h. Drivers must include the appropriate driver + * header file. + * + * This file contains portable definitions of integral types for properties + * of cryptographic keys, designations of cryptographic algorithms, and + * error codes returned by the library. + * + * This header file does not declare any function. + */ +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PSA_CRYPTO_TYPES_H +#define PSA_CRYPTO_TYPES_H + +#include "crypto_platform.h" + +/* If MBEDTLS_PSA_CRYPTO_C is defined, make sure MBEDTLS_PSA_CRYPTO_CLIENT + * is defined as well to include all PSA code. + */ +#if defined(MBEDTLS_PSA_CRYPTO_C) +#define MBEDTLS_PSA_CRYPTO_CLIENT +#endif /* MBEDTLS_PSA_CRYPTO_C */ + +#include + +/** \defgroup error Error codes + * @{ + */ + +/** + * \brief Function return status. + * + * This is either #PSA_SUCCESS (which is zero), indicating success, + * or a small negative value indicating that an error occurred. Errors are + * encoded as one of the \c PSA_ERROR_xxx values defined here. */ +/* If #PSA_SUCCESS is already defined, it means that #psa_status_t + * is also defined in an external header, so prevent its multiple + * definition. + */ +#ifndef PSA_SUCCESS +typedef int32_t psa_status_t; +#endif + +/**@}*/ + +/** \defgroup crypto_types Key and algorithm types + * @{ + */ + +/** \brief Encoding of a key type. + */ +typedef uint16_t psa_key_type_t; + +/** The type of PSA elliptic curve family identifiers. + * + * The curve identifier is required to create an ECC key using the + * PSA_KEY_TYPE_ECC_KEY_PAIR() or PSA_KEY_TYPE_ECC_PUBLIC_KEY() + * macros. + * + * Values defined by this standard will never be in the range 0x80-0xff. + * Vendors who define additional families must use an encoding in this range. + */ +typedef uint8_t psa_ecc_family_t; + +/** The type of PSA Diffie-Hellman group family identifiers. + * + * The group identifier is required to create an Diffie-Hellman key using the + * PSA_KEY_TYPE_DH_KEY_PAIR() or PSA_KEY_TYPE_DH_PUBLIC_KEY() + * macros. + * + * Values defined by this standard will never be in the range 0x80-0xff. + * Vendors who define additional families must use an encoding in this range. + */ +typedef uint8_t psa_dh_family_t; + +/** \brief Encoding of a cryptographic algorithm. + * + * For algorithms that can be applied to multiple key types, this type + * does not encode the key type. For example, for symmetric ciphers + * based on a block cipher, #psa_algorithm_t encodes the block cipher + * mode and the padding mode while the block cipher itself is encoded + * via #psa_key_type_t. + */ +typedef uint32_t psa_algorithm_t; + +/**@}*/ + +/** \defgroup key_lifetimes Key lifetimes + * @{ + */ + +/** Encoding of key lifetimes. + * + * The lifetime of a key indicates where it is stored and what system actions + * may create and destroy it. + * + * Lifetime values have the following structure: + * - Bits 0-7 (#PSA_KEY_LIFETIME_GET_PERSISTENCE(\c lifetime)): + * persistence level. This value indicates what device management + * actions can cause it to be destroyed. In particular, it indicates + * whether the key is _volatile_ or _persistent_. + * See ::psa_key_persistence_t for more information. + * - Bits 8-31 (#PSA_KEY_LIFETIME_GET_LOCATION(\c lifetime)): + * location indicator. This value indicates which part of the system + * has access to the key material and can perform operations using the key. + * See ::psa_key_location_t for more information. + * + * Volatile keys are automatically destroyed when the application instance + * terminates or on a power reset of the device. Persistent keys are + * preserved until the application explicitly destroys them or until an + * integration-specific device management event occurs (for example, + * a factory reset). + * + * Persistent keys have a key identifier of type #mbedtls_svc_key_id_t. + * This identifier remains valid throughout the lifetime of the key, + * even if the application instance that created the key terminates. + * The application can call psa_open_key() to open a persistent key that + * it created previously. + * + * The default lifetime of a key is #PSA_KEY_LIFETIME_VOLATILE. The lifetime + * #PSA_KEY_LIFETIME_PERSISTENT is supported if persistent storage is + * available. Other lifetime values may be supported depending on the + * library configuration. + */ +typedef uint32_t psa_key_lifetime_t; + +/** Encoding of key persistence levels. + * + * What distinguishes different persistence levels is what device management + * events may cause keys to be destroyed. _Volatile_ keys are destroyed + * by a power reset. Persistent keys may be destroyed by events such as + * a transfer of ownership or a factory reset. What management events + * actually affect persistent keys at different levels is outside the + * scope of the PSA Cryptography specification. + * + * The PSA Cryptography specification defines the following values of + * persistence levels: + * - \c 0 = #PSA_KEY_PERSISTENCE_VOLATILE: volatile key. + * A volatile key is automatically destroyed by the implementation when + * the application instance terminates. In particular, a volatile key + * is automatically destroyed on a power reset of the device. + * - \c 1 = #PSA_KEY_PERSISTENCE_DEFAULT: + * persistent key with a default lifetime. + * - \c 2-254: currently not supported by Mbed TLS. + * - \c 255 = #PSA_KEY_PERSISTENCE_READ_ONLY: + * read-only or write-once key. + * A key with this persistence level cannot be destroyed. + * Mbed TLS does not currently offer a way to create such keys, but + * integrations of Mbed TLS can use it for built-in keys that the + * application cannot modify (for example, a hardware unique key (HUK)). + * + * \note Key persistence levels are 8-bit values. Key management + * interfaces operate on lifetimes (type ::psa_key_lifetime_t) which + * encode the persistence as the lower 8 bits of a 32-bit value. + */ +typedef uint8_t psa_key_persistence_t; + +/** Encoding of key location indicators. + * + * If an integration of Mbed TLS can make calls to external + * cryptoprocessors such as secure elements, the location of a key + * indicates which secure element performs the operations on the key. + * Depending on the design of the secure element, the key + * material may be stored either in the secure element, or + * in wrapped (encrypted) form alongside the key metadata in the + * primary local storage. + * + * The PSA Cryptography API specification defines the following values of + * location indicators: + * - \c 0: primary local storage. + * This location is always available. + * The primary local storage is typically the same storage area that + * contains the key metadata. + * - \c 1: primary secure element. + * Integrations of Mbed TLS should support this value if there is a secure + * element attached to the operating environment. + * As a guideline, secure elements may provide higher resistance against + * side channel and physical attacks than the primary local storage, but may + * have restrictions on supported key types, sizes, policies and operations + * and may have different performance characteristics. + * - \c 2-0x7fffff: other locations defined by a PSA specification. + * The PSA Cryptography API does not currently assign any meaning to these + * locations, but future versions of that specification or other PSA + * specifications may do so. + * - \c 0x800000-0xffffff: vendor-defined locations. + * No PSA specification will assign a meaning to locations in this range. + * + * \note Key location indicators are 24-bit values. Key management + * interfaces operate on lifetimes (type ::psa_key_lifetime_t) which + * encode the location as the upper 24 bits of a 32-bit value. + */ +typedef uint32_t psa_key_location_t; + +/** Encoding of identifiers of persistent keys. + * + * - Applications may freely choose key identifiers in the range + * #PSA_KEY_ID_USER_MIN to #PSA_KEY_ID_USER_MAX. + * - The implementation may define additional key identifiers in the range + * #PSA_KEY_ID_VENDOR_MIN to #PSA_KEY_ID_VENDOR_MAX. + * - 0 is reserved as an invalid key identifier. + * - Key identifiers outside these ranges are reserved for future use. + */ +typedef uint32_t psa_key_id_t; + +#if !defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER) +typedef psa_key_id_t mbedtls_svc_key_id_t; + +#else /* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */ +/* Implementation-specific: The Mbed Cryptography library can be built as + * part of a multi-client service that exposes the PSA Cryptograpy API in each + * client and encodes the client identity in the key identifier argument of + * functions such as psa_open_key(). + */ +typedef struct +{ + psa_key_id_t key_id; + mbedtls_key_owner_id_t owner; +} mbedtls_svc_key_id_t; + +#endif /* !MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */ + +/**@}*/ + +/** \defgroup policy Key policies + * @{ + */ + +/** \brief Encoding of permitted usage on a key. */ +typedef uint32_t psa_key_usage_t; + +/**@}*/ + +/** \defgroup attributes Key attributes + * @{ + */ + +/** The type of a structure containing key attributes. + * + * This is an opaque structure that can represent the metadata of a key + * object. Metadata that can be stored in attributes includes: + * - The location of the key in storage, indicated by its key identifier + * and its lifetime. + * - The key's policy, comprising usage flags and a specification of + * the permitted algorithm(s). + * - Information about the key itself: the key type and its size. + * - Additional implementation-defined attributes. + * + * The actual key material is not considered an attribute of a key. + * Key attributes do not contain information that is generally considered + * highly confidential. + * + * An attribute structure works like a simple data structure where each function + * `psa_set_key_xxx` sets a field and the corresponding function + * `psa_get_key_xxx` retrieves the value of the corresponding field. + * However, a future version of the library may report values that are + * equivalent to the original one, but have a different encoding. Invalid + * values may be mapped to different, also invalid values. + * + * An attribute structure may contain references to auxiliary resources, + * for example pointers to allocated memory or indirect references to + * pre-calculated values. In order to free such resources, the application + * must call psa_reset_key_attributes(). As an exception, calling + * psa_reset_key_attributes() on an attribute structure is optional if + * the structure has only been modified by the following functions + * since it was initialized or last reset with psa_reset_key_attributes(): + * - psa_set_key_id() + * - psa_set_key_lifetime() + * - psa_set_key_type() + * - psa_set_key_bits() + * - psa_set_key_usage_flags() + * - psa_set_key_algorithm() + * + * Before calling any function on a key attribute structure, the application + * must initialize it by any of the following means: + * - Set the structure to all-bits-zero, for example: + * \code + * psa_key_attributes_t attributes; + * memset(&attributes, 0, sizeof(attributes)); + * \endcode + * - Initialize the structure to logical zero values, for example: + * \code + * psa_key_attributes_t attributes = {0}; + * \endcode + * - Initialize the structure to the initializer #PSA_KEY_ATTRIBUTES_INIT, + * for example: + * \code + * psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; + * \endcode + * - Assign the result of the function psa_key_attributes_init() + * to the structure, for example: + * \code + * psa_key_attributes_t attributes; + * attributes = psa_key_attributes_init(); + * \endcode + * + * A freshly initialized attribute structure contains the following + * values: + * + * - lifetime: #PSA_KEY_LIFETIME_VOLATILE. + * - key identifier: 0 (which is not a valid key identifier). + * - type: \c 0 (meaning that the type is unspecified). + * - key size: \c 0 (meaning that the size is unspecified). + * - usage flags: \c 0 (which allows no usage except exporting a public key). + * - algorithm: \c 0 (which allows no cryptographic usage, but allows + * exporting). + * + * A typical sequence to create a key is as follows: + * -# Create and initialize an attribute structure. + * -# If the key is persistent, call psa_set_key_id(). + * Also call psa_set_key_lifetime() to place the key in a non-default + * location. + * -# Set the key policy with psa_set_key_usage_flags() and + * psa_set_key_algorithm(). + * -# Set the key type with psa_set_key_type(). + * Skip this step if copying an existing key with psa_copy_key(). + * -# When generating a random key with psa_generate_key() or deriving a key + * with psa_key_derivation_output_key(), set the desired key size with + * psa_set_key_bits(). + * -# Call a key creation function: psa_import_key(), psa_generate_key(), + * psa_key_derivation_output_key() or psa_copy_key(). This function reads + * the attribute structure, creates a key with these attributes, and + * outputs a key identifier to the newly created key. + * -# The attribute structure is now no longer necessary. + * You may call psa_reset_key_attributes(), although this is optional + * with the workflow presented here because the attributes currently + * defined in this specification do not require any additional resources + * beyond the structure itself. + * + * A typical sequence to query a key's attributes is as follows: + * -# Call psa_get_key_attributes(). + * -# Call `psa_get_key_xxx` functions to retrieve the attribute(s) that + * you are interested in. + * -# Call psa_reset_key_attributes() to free any resources that may be + * used by the attribute structure. + * + * Once a key has been created, it is impossible to change its attributes. + */ +typedef struct psa_key_attributes_s psa_key_attributes_t; + + +#ifndef __DOXYGEN_ONLY__ +#if defined(MBEDTLS_PSA_CRYPTO_SE_C) +/* Mbed Crypto defines this type in crypto_types.h because it is also + * visible to applications through an implementation-specific extension. + * For the PSA Cryptography specification, this type is only visible + * via crypto_se_driver.h. */ +typedef uint64_t psa_key_slot_number_t; +#endif /* MBEDTLS_PSA_CRYPTO_SE_C */ +#endif /* !__DOXYGEN_ONLY__ */ + +/**@}*/ + +/** \defgroup derivation Key derivation + * @{ + */ + +/** \brief Encoding of the step of a key derivation. */ +typedef uint16_t psa_key_derivation_step_t; + +/**@}*/ + +#endif /* PSA_CRYPTO_TYPES_H */ diff --git a/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_values.h b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_values.h new file mode 100644 index 00000000000..fafe93cf9ba --- /dev/null +++ b/tools/sdk/esp32/include/mbedtls/mbedtls/include/psa/crypto_values.h @@ -0,0 +1,2325 @@ +/** + * \file psa/crypto_values.h + * + * \brief PSA cryptography module: macros to build and analyze integer values. + * + * \note This file may not be included directly. Applications must + * include psa/crypto.h. Drivers must include the appropriate driver + * header file. + * + * This file contains portable definitions of macros to build and analyze + * values of integral types that encode properties of cryptographic keys, + * designations of cryptographic algorithms, and error codes returned by + * the library. + * + * This header file only defines preprocessor macros. + */ +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PSA_CRYPTO_VALUES_H +#define PSA_CRYPTO_VALUES_H + +/** \defgroup error Error codes + * @{ + */ + +/* PSA error codes */ + +/** The action was completed successfully. */ +#define PSA_SUCCESS ((psa_status_t)0) + +/** An error occurred that does not correspond to any defined + * failure cause. + * + * Implementations may use this error code if none of the other standard + * error codes are applicable. */ +#define PSA_ERROR_GENERIC_ERROR ((psa_status_t)-132) + +/** The requested operation or a parameter is not supported + * by this implementation. + * + * Implementations should return this error code when an enumeration + * parameter such as a key type, algorithm, etc. is not recognized. + * If a combination of parameters is recognized and identified as + * not valid, return #PSA_ERROR_INVALID_ARGUMENT instead. */ +#define PSA_ERROR_NOT_SUPPORTED ((psa_status_t)-134) + +/** The requested action is denied by a policy. + * + * Implementations should return this error code when the parameters + * are recognized as valid and supported, and a policy explicitly + * denies the requested operation. + * + * If a subset of the parameters of a function call identify a + * forbidden operation, and another subset of the parameters are + * not valid or not supported, it is unspecified whether the function + * returns #PSA_ERROR_NOT_PERMITTED, #PSA_ERROR_NOT_SUPPORTED or + * #PSA_ERROR_INVALID_ARGUMENT. */ +#define PSA_ERROR_NOT_PERMITTED ((psa_status_t)-133) + +/** An output buffer is too small. + * + * Applications can call the \c PSA_xxx_SIZE macro listed in the function + * description to determine a sufficient buffer size. + * + * Implementations should preferably return this error code only + * in cases when performing the operation with a larger output + * buffer would succeed. However implementations may return this + * error if a function has invalid or unsupported parameters in addition + * to the parameters that determine the necessary output buffer size. */ +#define PSA_ERROR_BUFFER_TOO_SMALL ((psa_status_t)-138) + +/** Asking for an item that already exists + * + * Implementations should return this error, when attempting + * to write an item (like a key) that already exists. */ +#define PSA_ERROR_ALREADY_EXISTS ((psa_status_t)-139) + +/** Asking for an item that doesn't exist + * + * Implementations should return this error, if a requested item (like + * a key) does not exist. */ +#define PSA_ERROR_DOES_NOT_EXIST ((psa_status_t)-140) + +/** The requested action cannot be performed in the current state. + * + * Multipart operations return this error when one of the + * functions is called out of sequence. Refer to the function + * descriptions for permitted sequencing of functions. + * + * Implementations shall not return this error code to indicate + * that a key either exists or not, + * but shall instead return #PSA_ERROR_ALREADY_EXISTS or #PSA_ERROR_DOES_NOT_EXIST + * as applicable. + * + * Implementations shall not return this error code to indicate that a + * key identifier is invalid, but shall return #PSA_ERROR_INVALID_HANDLE + * instead. */ +#define PSA_ERROR_BAD_STATE ((psa_status_t)-137) + +/** The parameters passed to the function are invalid. + * + * Implementations may return this error any time a parameter or + * combination of parameters are recognized as invalid. + * + * Implementations shall not return this error code to indicate that a + * key identifier is invalid, but shall return #PSA_ERROR_INVALID_HANDLE + * instead. + */ +#define PSA_ERROR_INVALID_ARGUMENT ((psa_status_t)-135) + +/** There is not enough runtime memory. + * + * If the action is carried out across multiple security realms, this + * error can refer to available memory in any of the security realms. */ +#define PSA_ERROR_INSUFFICIENT_MEMORY ((psa_status_t)-141) + +/** There is not enough persistent storage. + * + * Functions that modify the key storage return this error code if + * there is insufficient storage space on the host media. In addition, + * many functions that do not otherwise access storage may return this + * error code if the implementation requires a mandatory log entry for + * the requested action and the log storage space is full. */ +#define PSA_ERROR_INSUFFICIENT_STORAGE ((psa_status_t)-142) + +/** There was a communication failure inside the implementation. + * + * This can indicate a communication failure between the application + * and an external cryptoprocessor or between the cryptoprocessor and + * an external volatile or persistent memory. A communication failure + * may be transient or permanent depending on the cause. + * + * \warning If a function returns this error, it is undetermined + * whether the requested action has completed or not. Implementations + * should return #PSA_SUCCESS on successful completion whenever + * possible, however functions may return #PSA_ERROR_COMMUNICATION_FAILURE + * if the requested action was completed successfully in an external + * cryptoprocessor but there was a breakdown of communication before + * the cryptoprocessor could report the status to the application. + */ +#define PSA_ERROR_COMMUNICATION_FAILURE ((psa_status_t)-145) + +/** There was a storage failure that may have led to data loss. + * + * This error indicates that some persistent storage is corrupted. + * It should not be used for a corruption of volatile memory + * (use #PSA_ERROR_CORRUPTION_DETECTED), for a communication error + * between the cryptoprocessor and its external storage (use + * #PSA_ERROR_COMMUNICATION_FAILURE), or when the storage is + * in a valid state but is full (use #PSA_ERROR_INSUFFICIENT_STORAGE). + * + * Note that a storage failure does not indicate that any data that was + * previously read is invalid. However this previously read data may no + * longer be readable from storage. + * + * When a storage failure occurs, it is no longer possible to ensure + * the global integrity of the keystore. Depending on the global + * integrity guarantees offered by the implementation, access to other + * data may or may not fail even if the data is still readable but + * its integrity cannot be guaranteed. + * + * Implementations should only use this error code to report a + * permanent storage corruption. However application writers should + * keep in mind that transient errors while reading the storage may be + * reported using this error code. */ +#define PSA_ERROR_STORAGE_FAILURE ((psa_status_t)-146) + +/** A hardware failure was detected. + * + * A hardware failure may be transient or permanent depending on the + * cause. */ +#define PSA_ERROR_HARDWARE_FAILURE ((psa_status_t)-147) + +/** A tampering attempt was detected. + * + * If an application receives this error code, there is no guarantee + * that previously accessed or computed data was correct and remains + * confidential. Applications should not perform any security function + * and should enter a safe failure state. + * + * Implementations may return this error code if they detect an invalid + * state that cannot happen during normal operation and that indicates + * that the implementation's security guarantees no longer hold. Depending + * on the implementation architecture and on its security and safety goals, + * the implementation may forcibly terminate the application. + * + * This error code is intended as a last resort when a security breach + * is detected and it is unsure whether the keystore data is still + * protected. Implementations shall only return this error code + * to report an alarm from a tampering detector, to indicate that + * the confidentiality of stored data can no longer be guaranteed, + * or to indicate that the integrity of previously returned data is now + * considered compromised. Implementations shall not use this error code + * to indicate a hardware failure that merely makes it impossible to + * perform the requested operation (use #PSA_ERROR_COMMUNICATION_FAILURE, + * #PSA_ERROR_STORAGE_FAILURE, #PSA_ERROR_HARDWARE_FAILURE, + * #PSA_ERROR_INSUFFICIENT_ENTROPY or other applicable error code + * instead). + * + * This error indicates an attack against the application. Implementations + * shall not return this error code as a consequence of the behavior of + * the application itself. */ +#define PSA_ERROR_CORRUPTION_DETECTED ((psa_status_t)-151) + +/** There is not enough entropy to generate random data needed + * for the requested action. + * + * This error indicates a failure of a hardware random generator. + * Application writers should note that this error can be returned not + * only by functions whose purpose is to generate random data, such + * as key, IV or nonce generation, but also by functions that execute + * an algorithm with a randomized result, as well as functions that + * use randomization of intermediate computations as a countermeasure + * to certain attacks. + * + * Implementations should avoid returning this error after psa_crypto_init() + * has succeeded. Implementations should generate sufficient + * entropy during initialization and subsequently use a cryptographically + * secure pseudorandom generator (PRNG). However implementations may return + * this error at any time if a policy requires the PRNG to be reseeded + * during normal operation. */ +#define PSA_ERROR_INSUFFICIENT_ENTROPY ((psa_status_t)-148) + +/** The signature, MAC or hash is incorrect. + * + * Verification functions return this error if the verification + * calculations completed successfully, and the value to be verified + * was determined to be incorrect. + * + * If the value to verify has an invalid size, implementations may return + * either #PSA_ERROR_INVALID_ARGUMENT or #PSA_ERROR_INVALID_SIGNATURE. */ +#define PSA_ERROR_INVALID_SIGNATURE ((psa_status_t)-149) + +/** The decrypted padding is incorrect. + * + * \warning In some protocols, when decrypting data, it is essential that + * the behavior of the application does not depend on whether the padding + * is correct, down to precise timing. Applications should prefer + * protocols that use authenticated encryption rather than plain + * encryption. If the application must perform a decryption of + * unauthenticated data, the application writer should take care not + * to reveal whether the padding is invalid. + * + * Implementations should strive to make valid and invalid padding + * as close as possible to indistinguishable to an external observer. + * In particular, the timing of a decryption operation should not + * depend on the validity of the padding. */ +#define PSA_ERROR_INVALID_PADDING ((psa_status_t)-150) + +/** Return this error when there's insufficient data when attempting + * to read from a resource. */ +#define PSA_ERROR_INSUFFICIENT_DATA ((psa_status_t)-143) + +/** The key identifier is not valid. See also :ref:\`key-handles\`. + */ +#define PSA_ERROR_INVALID_HANDLE ((psa_status_t)-136) + +/** Stored data has been corrupted. + * + * This error indicates that some persistent storage has suffered corruption. + * It does not indicate the following situations, which have specific error + * codes: + * + * - A corruption of volatile memory - use #PSA_ERROR_CORRUPTION_DETECTED. + * - A communication error between the cryptoprocessor and its external + * storage - use #PSA_ERROR_COMMUNICATION_FAILURE. + * - When the storage is in a valid state but is full - use + * #PSA_ERROR_INSUFFICIENT_STORAGE. + * - When the storage fails for other reasons - use + * #PSA_ERROR_STORAGE_FAILURE. + * - When the stored data is not valid - use #PSA_ERROR_DATA_INVALID. + * + * \note A storage corruption does not indicate that any data that was + * previously read is invalid. However this previously read data might no + * longer be readable from storage. + * + * When a storage failure occurs, it is no longer possible to ensure the + * global integrity of the keystore. + */ +#define PSA_ERROR_DATA_CORRUPT ((psa_status_t)-152) + +/** Data read from storage is not valid for the implementation. + * + * This error indicates that some data read from storage does not have a valid + * format. It does not indicate the following situations, which have specific + * error codes: + * + * - When the storage or stored data is corrupted - use #PSA_ERROR_DATA_CORRUPT + * - When the storage fails for other reasons - use #PSA_ERROR_STORAGE_FAILURE + * - An invalid argument to the API - use #PSA_ERROR_INVALID_ARGUMENT + * + * This error is typically a result of either storage corruption on a + * cleartext storage backend, or an attempt to read data that was + * written by an incompatible version of the library. + */ +#define PSA_ERROR_DATA_INVALID ((psa_status_t)-153) + +/**@}*/ + +/** \defgroup crypto_types Key and algorithm types + * @{ + */ + +/** An invalid key type value. + * + * Zero is not the encoding of any key type. + */ +#define PSA_KEY_TYPE_NONE ((psa_key_type_t)0x0000) + +/** Vendor-defined key type flag. + * + * Key types defined by this standard will never have the + * #PSA_KEY_TYPE_VENDOR_FLAG bit set. Vendors who define additional key types + * must use an encoding with the #PSA_KEY_TYPE_VENDOR_FLAG bit set and should + * respect the bitwise structure used by standard encodings whenever practical. + */ +#define PSA_KEY_TYPE_VENDOR_FLAG ((psa_key_type_t)0x8000) + +#define PSA_KEY_TYPE_CATEGORY_MASK ((psa_key_type_t)0x7000) +#define PSA_KEY_TYPE_CATEGORY_RAW ((psa_key_type_t)0x1000) +#define PSA_KEY_TYPE_CATEGORY_SYMMETRIC ((psa_key_type_t)0x2000) +#define PSA_KEY_TYPE_CATEGORY_PUBLIC_KEY ((psa_key_type_t)0x4000) +#define PSA_KEY_TYPE_CATEGORY_KEY_PAIR ((psa_key_type_t)0x7000) + +#define PSA_KEY_TYPE_CATEGORY_FLAG_PAIR ((psa_key_type_t)0x3000) + +/** Whether a key type is vendor-defined. + * + * See also #PSA_KEY_TYPE_VENDOR_FLAG. + */ +#define PSA_KEY_TYPE_IS_VENDOR_DEFINED(type) \ + (((type) & PSA_KEY_TYPE_VENDOR_FLAG) != 0) + +/** Whether a key type is an unstructured array of bytes. + * + * This encompasses both symmetric keys and non-key data. + */ +#define PSA_KEY_TYPE_IS_UNSTRUCTURED(type) \ + (((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_RAW || \ + ((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_SYMMETRIC) + +/** Whether a key type is asymmetric: either a key pair or a public key. */ +#define PSA_KEY_TYPE_IS_ASYMMETRIC(type) \ + (((type) & PSA_KEY_TYPE_CATEGORY_MASK \ + & ~PSA_KEY_TYPE_CATEGORY_FLAG_PAIR) == \ + PSA_KEY_TYPE_CATEGORY_PUBLIC_KEY) +/** Whether a key type is the public part of a key pair. */ +#define PSA_KEY_TYPE_IS_PUBLIC_KEY(type) \ + (((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_PUBLIC_KEY) +/** Whether a key type is a key pair containing a private part and a public + * part. */ +#define PSA_KEY_TYPE_IS_KEY_PAIR(type) \ + (((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_KEY_PAIR) +/** The key pair type corresponding to a public key type. + * + * You may also pass a key pair type as \p type, it will be left unchanged. + * + * \param type A public key type or key pair type. + * + * \return The corresponding key pair type. + * If \p type is not a public key or a key pair, + * the return value is undefined. + */ +#define PSA_KEY_TYPE_KEY_PAIR_OF_PUBLIC_KEY(type) \ + ((type) | PSA_KEY_TYPE_CATEGORY_FLAG_PAIR) +/** The public key type corresponding to a key pair type. + * + * You may also pass a key pair type as \p type, it will be left unchanged. + * + * \param type A public key type or key pair type. + * + * \return The corresponding public key type. + * If \p type is not a public key or a key pair, + * the return value is undefined. + */ +#define PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) \ + ((type) & ~PSA_KEY_TYPE_CATEGORY_FLAG_PAIR) + +/** Raw data. + * + * A "key" of this type cannot be used for any cryptographic operation. + * Applications may use this type to store arbitrary data in the keystore. */ +#define PSA_KEY_TYPE_RAW_DATA ((psa_key_type_t)0x1001) + +/** HMAC key. + * + * The key policy determines which underlying hash algorithm the key can be + * used for. + * + * HMAC keys should generally have the same size as the underlying hash. + * This size can be calculated with #PSA_HASH_LENGTH(\c alg) where + * \c alg is the HMAC algorithm or the underlying hash algorithm. */ +#define PSA_KEY_TYPE_HMAC ((psa_key_type_t)0x1100) + +/** A secret for key derivation. + * + * The key policy determines which key derivation algorithm the key + * can be used for. + */ +#define PSA_KEY_TYPE_DERIVE ((psa_key_type_t)0x1200) + +/** Key for a cipher, AEAD or MAC algorithm based on the AES block cipher. + * + * The size of the key can be 16 bytes (AES-128), 24 bytes (AES-192) or + * 32 bytes (AES-256). + */ +#define PSA_KEY_TYPE_AES ((psa_key_type_t)0x2400) + +/** Key for a cipher, AEAD or MAC algorithm based on the + * ARIA block cipher. */ +#define PSA_KEY_TYPE_ARIA ((psa_key_type_t)0x2406) + +/** Key for a cipher or MAC algorithm based on DES or 3DES (Triple-DES). + * + * The size of the key can be 64 bits (single DES), 128 bits (2-key 3DES) or + * 192 bits (3-key 3DES). + * + * Note that single DES and 2-key 3DES are weak and strongly + * deprecated and should only be used to decrypt legacy data. 3-key 3DES + * is weak and deprecated and should only be used in legacy protocols. + */ +#define PSA_KEY_TYPE_DES ((psa_key_type_t)0x2301) + +/** Key for a cipher, AEAD or MAC algorithm based on the + * Camellia block cipher. */ +#define PSA_KEY_TYPE_CAMELLIA ((psa_key_type_t)0x2403) + +/** Key for the RC4 stream cipher. + * + * Note that RC4 is weak and deprecated and should only be used in + * legacy protocols. */ +#define PSA_KEY_TYPE_ARC4 ((psa_key_type_t)0x2002) + +/** Key for the ChaCha20 stream cipher or the Chacha20-Poly1305 AEAD algorithm. + * + * ChaCha20 and the ChaCha20_Poly1305 construction are defined in RFC 7539. + * + * Implementations must support 12-byte nonces, may support 8-byte nonces, + * and should reject other sizes. + */ +#define PSA_KEY_TYPE_CHACHA20 ((psa_key_type_t)0x2004) + +/** RSA public key. + * + * The size of an RSA key is the bit size of the modulus. + */ +#define PSA_KEY_TYPE_RSA_PUBLIC_KEY ((psa_key_type_t)0x4001) +/** RSA key pair (private and public key). + * + * The size of an RSA key is the bit size of the modulus. + */ +#define PSA_KEY_TYPE_RSA_KEY_PAIR ((psa_key_type_t)0x7001) +/** Whether a key type is an RSA key (pair or public-only). */ +#define PSA_KEY_TYPE_IS_RSA(type) \ + (PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) == PSA_KEY_TYPE_RSA_PUBLIC_KEY) + +#define PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE ((psa_key_type_t)0x4100) +#define PSA_KEY_TYPE_ECC_KEY_PAIR_BASE ((psa_key_type_t)0x7100) +#define PSA_KEY_TYPE_ECC_CURVE_MASK ((psa_key_type_t)0x00ff) +/** Elliptic curve key pair. + * + * The size of an elliptic curve key is the bit size associated with the curve, + * i.e. the bit size of *q* for a curve over a field *Fq*. + * See the documentation of `PSA_ECC_FAMILY_xxx` curve families for details. + * + * \param curve A value of type ::psa_ecc_family_t that + * identifies the ECC curve to be used. + */ +#define PSA_KEY_TYPE_ECC_KEY_PAIR(curve) \ + (PSA_KEY_TYPE_ECC_KEY_PAIR_BASE | (curve)) +/** Elliptic curve public key. + * + * The size of an elliptic curve public key is the same as the corresponding + * private key (see #PSA_KEY_TYPE_ECC_KEY_PAIR and the documentation of + * `PSA_ECC_FAMILY_xxx` curve families). + * + * \param curve A value of type ::psa_ecc_family_t that + * identifies the ECC curve to be used. + */ +#define PSA_KEY_TYPE_ECC_PUBLIC_KEY(curve) \ + (PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE | (curve)) + +/** Whether a key type is an elliptic curve key (pair or public-only). */ +#define PSA_KEY_TYPE_IS_ECC(type) \ + ((PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) & \ + ~PSA_KEY_TYPE_ECC_CURVE_MASK) == PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE) +/** Whether a key type is an elliptic curve key pair. */ +#define PSA_KEY_TYPE_IS_ECC_KEY_PAIR(type) \ + (((type) & ~PSA_KEY_TYPE_ECC_CURVE_MASK) == \ + PSA_KEY_TYPE_ECC_KEY_PAIR_BASE) +/** Whether a key type is an elliptic curve public key. */ +#define PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(type) \ + (((type) & ~PSA_KEY_TYPE_ECC_CURVE_MASK) == \ + PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE) + +/** Extract the curve from an elliptic curve key type. */ +#define PSA_KEY_TYPE_ECC_GET_FAMILY(type) \ + ((psa_ecc_family_t) (PSA_KEY_TYPE_IS_ECC(type) ? \ + ((type) & PSA_KEY_TYPE_ECC_CURVE_MASK) : \ + 0)) + +/** SEC Koblitz curves over prime fields. + * + * This family comprises the following curves: + * secp192k1, secp224k1, secp256k1. + * They are defined in _Standards for Efficient Cryptography_, + * _SEC 2: Recommended Elliptic Curve Domain Parameters_. + * https://www.secg.org/sec2-v2.pdf + */ +#define PSA_ECC_FAMILY_SECP_K1 ((psa_ecc_family_t) 0x17) + +/** SEC random curves over prime fields. + * + * This family comprises the following curves: + * secp192k1, secp224r1, secp256r1, secp384r1, secp521r1. + * They are defined in _Standards for Efficient Cryptography_, + * _SEC 2: Recommended Elliptic Curve Domain Parameters_. + * https://www.secg.org/sec2-v2.pdf + */ +#define PSA_ECC_FAMILY_SECP_R1 ((psa_ecc_family_t) 0x12) +/* SECP160R2 (SEC2 v1, obsolete) */ +#define PSA_ECC_FAMILY_SECP_R2 ((psa_ecc_family_t) 0x1b) + +/** SEC Koblitz curves over binary fields. + * + * This family comprises the following curves: + * sect163k1, sect233k1, sect239k1, sect283k1, sect409k1, sect571k1. + * They are defined in _Standards for Efficient Cryptography_, + * _SEC 2: Recommended Elliptic Curve Domain Parameters_. + * https://www.secg.org/sec2-v2.pdf + */ +#define PSA_ECC_FAMILY_SECT_K1 ((psa_ecc_family_t) 0x27) + +/** SEC random curves over binary fields. + * + * This family comprises the following curves: + * sect163r1, sect233r1, sect283r1, sect409r1, sect571r1. + * They are defined in _Standards for Efficient Cryptography_, + * _SEC 2: Recommended Elliptic Curve Domain Parameters_. + * https://www.secg.org/sec2-v2.pdf + */ +#define PSA_ECC_FAMILY_SECT_R1 ((psa_ecc_family_t) 0x22) + +/** SEC additional random curves over binary fields. + * + * This family comprises the following curve: + * sect163r2. + * It is defined in _Standards for Efficient Cryptography_, + * _SEC 2: Recommended Elliptic Curve Domain Parameters_. + * https://www.secg.org/sec2-v2.pdf + */ +#define PSA_ECC_FAMILY_SECT_R2 ((psa_ecc_family_t) 0x2b) + +/** Brainpool P random curves. + * + * This family comprises the following curves: + * brainpoolP160r1, brainpoolP192r1, brainpoolP224r1, brainpoolP256r1, + * brainpoolP320r1, brainpoolP384r1, brainpoolP512r1. + * It is defined in RFC 5639. + */ +#define PSA_ECC_FAMILY_BRAINPOOL_P_R1 ((psa_ecc_family_t) 0x30) + +/** Curve25519 and Curve448. + * + * This family comprises the following Montgomery curves: + * - 255-bit: Bernstein et al., + * _Curve25519: new Diffie-Hellman speed records_, LNCS 3958, 2006. + * The algorithm #PSA_ALG_ECDH performs X25519 when used with this curve. + * - 448-bit: Hamburg, + * _Ed448-Goldilocks, a new elliptic curve_, NIST ECC Workshop, 2015. + * The algorithm #PSA_ALG_ECDH performs X448 when used with this curve. + */ +#define PSA_ECC_FAMILY_MONTGOMERY ((psa_ecc_family_t) 0x41) + +/** The twisted Edwards curves Ed25519 and Ed448. + * + * These curves are suitable for EdDSA (#PSA_ALG_PURE_EDDSA for both curves, + * #PSA_ALG_ED25519PH for the 255-bit curve, + * #PSA_ALG_ED448PH for the 448-bit curve). + * + * This family comprises the following twisted Edwards curves: + * - 255-bit: Edwards25519, the twisted Edwards curve birationally equivalent + * to Curve25519. + * Bernstein et al., _Twisted Edwards curves_, Africacrypt 2008. + * - 448-bit: Edwards448, the twisted Edwards curve birationally equivalent + * to Curve448. + * Hamburg, _Ed448-Goldilocks, a new elliptic curve_, NIST ECC Workshop, 2015. + */ +#define PSA_ECC_FAMILY_TWISTED_EDWARDS ((psa_ecc_family_t) 0x42) + +#define PSA_KEY_TYPE_DH_PUBLIC_KEY_BASE ((psa_key_type_t)0x4200) +#define PSA_KEY_TYPE_DH_KEY_PAIR_BASE ((psa_key_type_t)0x7200) +#define PSA_KEY_TYPE_DH_GROUP_MASK ((psa_key_type_t)0x00ff) +/** Diffie-Hellman key pair. + * + * \param group A value of type ::psa_dh_family_t that identifies the + * Diffie-Hellman group to be used. + */ +#define PSA_KEY_TYPE_DH_KEY_PAIR(group) \ + (PSA_KEY_TYPE_DH_KEY_PAIR_BASE | (group)) +/** Diffie-Hellman public key. + * + * \param group A value of type ::psa_dh_family_t that identifies the + * Diffie-Hellman group to be used. + */ +#define PSA_KEY_TYPE_DH_PUBLIC_KEY(group) \ + (PSA_KEY_TYPE_DH_PUBLIC_KEY_BASE | (group)) + +/** Whether a key type is a Diffie-Hellman key (pair or public-only). */ +#define PSA_KEY_TYPE_IS_DH(type) \ + ((PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) & \ + ~PSA_KEY_TYPE_DH_GROUP_MASK) == PSA_KEY_TYPE_DH_PUBLIC_KEY_BASE) +/** Whether a key type is a Diffie-Hellman key pair. */ +#define PSA_KEY_TYPE_IS_DH_KEY_PAIR(type) \ + (((type) & ~PSA_KEY_TYPE_DH_GROUP_MASK) == \ + PSA_KEY_TYPE_DH_KEY_PAIR_BASE) +/** Whether a key type is a Diffie-Hellman public key. */ +#define PSA_KEY_TYPE_IS_DH_PUBLIC_KEY(type) \ + (((type) & ~PSA_KEY_TYPE_DH_GROUP_MASK) == \ + PSA_KEY_TYPE_DH_PUBLIC_KEY_BASE) + +/** Extract the group from a Diffie-Hellman key type. */ +#define PSA_KEY_TYPE_DH_GET_FAMILY(type) \ + ((psa_dh_family_t) (PSA_KEY_TYPE_IS_DH(type) ? \ + ((type) & PSA_KEY_TYPE_DH_GROUP_MASK) : \ + 0)) + +/** Diffie-Hellman groups defined in RFC 7919 Appendix A. + * + * This family includes groups with the following key sizes (in bits): + * 2048, 3072, 4096, 6144, 8192. A given implementation may support + * all of these sizes or only a subset. + */ +#define PSA_DH_FAMILY_RFC7919 ((psa_dh_family_t) 0x03) + +#define PSA_GET_KEY_TYPE_BLOCK_SIZE_EXPONENT(type) \ + (((type) >> 8) & 7) +/** The block size of a block cipher. + * + * \param type A cipher key type (value of type #psa_key_type_t). + * + * \return The block size for a block cipher, or 1 for a stream cipher. + * The return value is undefined if \p type is not a supported + * cipher key type. + * + * \note It is possible to build stream cipher algorithms on top of a block + * cipher, for example CTR mode (#PSA_ALG_CTR). + * This macro only takes the key type into account, so it cannot be + * used to determine the size of the data that #psa_cipher_update() + * might buffer for future processing in general. + * + * \note This macro returns a compile-time constant if its argument is one. + * + * \warning This macro may evaluate its argument multiple times. + */ +#define PSA_BLOCK_CIPHER_BLOCK_LENGTH(type) \ + (((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_SYMMETRIC ? \ + 1u << PSA_GET_KEY_TYPE_BLOCK_SIZE_EXPONENT(type) : \ + 0u) + +/** Vendor-defined algorithm flag. + * + * Algorithms defined by this standard will never have the #PSA_ALG_VENDOR_FLAG + * bit set. Vendors who define additional algorithms must use an encoding with + * the #PSA_ALG_VENDOR_FLAG bit set and should respect the bitwise structure + * used by standard encodings whenever practical. + */ +#define PSA_ALG_VENDOR_FLAG ((psa_algorithm_t)0x80000000) + +#define PSA_ALG_CATEGORY_MASK ((psa_algorithm_t)0x7f000000) +#define PSA_ALG_CATEGORY_HASH ((psa_algorithm_t)0x02000000) +#define PSA_ALG_CATEGORY_MAC ((psa_algorithm_t)0x03000000) +#define PSA_ALG_CATEGORY_CIPHER ((psa_algorithm_t)0x04000000) +#define PSA_ALG_CATEGORY_AEAD ((psa_algorithm_t)0x05000000) +#define PSA_ALG_CATEGORY_SIGN ((psa_algorithm_t)0x06000000) +#define PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION ((psa_algorithm_t)0x07000000) +#define PSA_ALG_CATEGORY_KEY_DERIVATION ((psa_algorithm_t)0x08000000) +#define PSA_ALG_CATEGORY_KEY_AGREEMENT ((psa_algorithm_t)0x09000000) + +/** Whether an algorithm is vendor-defined. + * + * See also #PSA_ALG_VENDOR_FLAG. + */ +#define PSA_ALG_IS_VENDOR_DEFINED(alg) \ + (((alg) & PSA_ALG_VENDOR_FLAG) != 0) + +/** Whether the specified algorithm is a hash algorithm. + * + * \param alg An algorithm identifier (value of type #psa_algorithm_t). + * + * \return 1 if \p alg is a hash algorithm, 0 otherwise. + * This macro may return either 0 or 1 if \p alg is not a supported + * algorithm identifier. + */ +#define PSA_ALG_IS_HASH(alg) \ + (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_HASH) + +/** Whether the specified algorithm is a MAC algorithm. + * + * \param alg An algorithm identifier (value of type #psa_algorithm_t). + * + * \return 1 if \p alg is a MAC algorithm, 0 otherwise. + * This macro may return either 0 or 1 if \p alg is not a supported + * algorithm identifier. + */ +#define PSA_ALG_IS_MAC(alg) \ + (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_MAC) + +/** Whether the specified algorithm is a symmetric cipher algorithm. + * + * \param alg An algorithm identifier (value of type #psa_algorithm_t). + * + * \return 1 if \p alg is a symmetric cipher algorithm, 0 otherwise. + * This macro may return either 0 or 1 if \p alg is not a supported + * algorithm identifier. + */ +#define PSA_ALG_IS_CIPHER(alg) \ + (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_CIPHER) + +/** Whether the specified algorithm is an authenticated encryption + * with associated data (AEAD) algorithm. + * + * \param alg An algorithm identifier (value of type #psa_algorithm_t). + * + * \return 1 if \p alg is an AEAD algorithm, 0 otherwise. + * This macro may return either 0 or 1 if \p alg is not a supported + * algorithm identifier. + */ +#define PSA_ALG_IS_AEAD(alg) \ + (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_AEAD) + +/** Whether the specified algorithm is an asymmetric signature algorithm, + * also known as public-key signature algorithm. + * + * \param alg An algorithm identifier (value of type #psa_algorithm_t). + * + * \return 1 if \p alg is an asymmetric signature algorithm, 0 otherwise. + * This macro may return either 0 or 1 if \p alg is not a supported + * algorithm identifier. + */ +#define PSA_ALG_IS_SIGN(alg) \ + (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_SIGN) + +/** Whether the specified algorithm is an asymmetric encryption algorithm, + * also known as public-key encryption algorithm. + * + * \param alg An algorithm identifier (value of type #psa_algorithm_t). + * + * \return 1 if \p alg is an asymmetric encryption algorithm, 0 otherwise. + * This macro may return either 0 or 1 if \p alg is not a supported + * algorithm identifier. + */ +#define PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg) \ + (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION) + +/** Whether the specified algorithm is a key agreement algorithm. + * + * \param alg An algorithm identifier (value of type #psa_algorithm_t). + * + * \return 1 if \p alg is a key agreement algorithm, 0 otherwise. + * This macro may return either 0 or 1 if \p alg is not a supported + * algorithm identifier. + */ +#define PSA_ALG_IS_KEY_AGREEMENT(alg) \ + (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_KEY_AGREEMENT) + +/** Whether the specified algorithm is a key derivation algorithm. + * + * \param alg An algorithm identifier (value of type #psa_algorithm_t). + * + * \return 1 if \p alg is a key derivation algorithm, 0 otherwise. + * This macro may return either 0 or 1 if \p alg is not a supported + * algorithm identifier. + */ +#define PSA_ALG_IS_KEY_DERIVATION(alg) \ + (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_KEY_DERIVATION) + +/** An invalid algorithm identifier value. */ +#define PSA_ALG_NONE ((psa_algorithm_t)0) + +#define PSA_ALG_HASH_MASK ((psa_algorithm_t)0x000000ff) +/** MD2 */ +#define PSA_ALG_MD2 ((psa_algorithm_t)0x02000001) +/** MD4 */ +#define PSA_ALG_MD4 ((psa_algorithm_t)0x02000002) +/** MD5 */ +#define PSA_ALG_MD5 ((psa_algorithm_t)0x02000003) +/** PSA_ALG_RIPEMD160 */ +#define PSA_ALG_RIPEMD160 ((psa_algorithm_t)0x02000004) +/** SHA1 */ +#define PSA_ALG_SHA_1 ((psa_algorithm_t)0x02000005) +/** SHA2-224 */ +#define PSA_ALG_SHA_224 ((psa_algorithm_t)0x02000008) +/** SHA2-256 */ +#define PSA_ALG_SHA_256 ((psa_algorithm_t)0x02000009) +/** SHA2-384 */ +#define PSA_ALG_SHA_384 ((psa_algorithm_t)0x0200000a) +/** SHA2-512 */ +#define PSA_ALG_SHA_512 ((psa_algorithm_t)0x0200000b) +/** SHA2-512/224 */ +#define PSA_ALG_SHA_512_224 ((psa_algorithm_t)0x0200000c) +/** SHA2-512/256 */ +#define PSA_ALG_SHA_512_256 ((psa_algorithm_t)0x0200000d) +/** SHA3-224 */ +#define PSA_ALG_SHA3_224 ((psa_algorithm_t)0x02000010) +/** SHA3-256 */ +#define PSA_ALG_SHA3_256 ((psa_algorithm_t)0x02000011) +/** SHA3-384 */ +#define PSA_ALG_SHA3_384 ((psa_algorithm_t)0x02000012) +/** SHA3-512 */ +#define PSA_ALG_SHA3_512 ((psa_algorithm_t)0x02000013) +/** The first 512 bits (64 bytes) of the SHAKE256 output. + * + * This is the prehashing for Ed448ph (see #PSA_ALG_ED448PH). For other + * scenarios where a hash function based on SHA3/SHAKE is desired, SHA3-512 + * has the same output size and a (theoretically) higher security strength. + */ +#define PSA_ALG_SHAKE256_512 ((psa_algorithm_t)0x02000015) + +/** In a hash-and-sign algorithm policy, allow any hash algorithm. + * + * This value may be used to form the algorithm usage field of a policy + * for a signature algorithm that is parametrized by a hash. The key + * may then be used to perform operations using the same signature + * algorithm parametrized with any supported hash. + * + * That is, suppose that `PSA_xxx_SIGNATURE` is one of the following macros: + * - #PSA_ALG_RSA_PKCS1V15_SIGN, #PSA_ALG_RSA_PSS, #PSA_ALG_RSA_PSS_ANY_SALT, + * - #PSA_ALG_ECDSA, #PSA_ALG_DETERMINISTIC_ECDSA. + * Then you may create and use a key as follows: + * - Set the key usage field using #PSA_ALG_ANY_HASH, for example: + * ``` + * psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH); // or VERIFY + * psa_set_key_algorithm(&attributes, PSA_xxx_SIGNATURE(PSA_ALG_ANY_HASH)); + * ``` + * - Import or generate key material. + * - Call psa_sign_hash() or psa_verify_hash(), passing + * an algorithm built from `PSA_xxx_SIGNATURE` and a specific hash. Each + * call to sign or verify a message may use a different hash. + * ``` + * psa_sign_hash(key, PSA_xxx_SIGNATURE(PSA_ALG_SHA_256), ...); + * psa_sign_hash(key, PSA_xxx_SIGNATURE(PSA_ALG_SHA_512), ...); + * psa_sign_hash(key, PSA_xxx_SIGNATURE(PSA_ALG_SHA3_256), ...); + * ``` + * + * This value may not be used to build other algorithms that are + * parametrized over a hash. For any valid use of this macro to build + * an algorithm \c alg, #PSA_ALG_IS_HASH_AND_SIGN(\c alg) is true. + * + * This value may not be used to build an algorithm specification to + * perform an operation. It is only valid to build policies. + */ +#define PSA_ALG_ANY_HASH ((psa_algorithm_t)0x020000ff) + +#define PSA_ALG_MAC_SUBCATEGORY_MASK ((psa_algorithm_t)0x00c00000) +#define PSA_ALG_HMAC_BASE ((psa_algorithm_t)0x03800000) +/** Macro to build an HMAC algorithm. + * + * For example, #PSA_ALG_HMAC(#PSA_ALG_SHA_256) is HMAC-SHA-256. + * + * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_HASH(\p hash_alg) is true). + * + * \return The corresponding HMAC algorithm. + * \return Unspecified if \p hash_alg is not a supported + * hash algorithm. + */ +#define PSA_ALG_HMAC(hash_alg) \ + (PSA_ALG_HMAC_BASE | ((hash_alg) & PSA_ALG_HASH_MASK)) + +#define PSA_ALG_HMAC_GET_HASH(hmac_alg) \ + (PSA_ALG_CATEGORY_HASH | ((hmac_alg) & PSA_ALG_HASH_MASK)) + +/** Whether the specified algorithm is an HMAC algorithm. + * + * HMAC is a family of MAC algorithms that are based on a hash function. + * + * \param alg An algorithm identifier (value of type #psa_algorithm_t). + * + * \return 1 if \p alg is an HMAC algorithm, 0 otherwise. + * This macro may return either 0 or 1 if \p alg is not a supported + * algorithm identifier. + */ +#define PSA_ALG_IS_HMAC(alg) \ + (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_MAC_SUBCATEGORY_MASK)) == \ + PSA_ALG_HMAC_BASE) + +/* In the encoding of a MAC algorithm, the bits corresponding to + * PSA_ALG_MAC_TRUNCATION_MASK encode the length to which the MAC is + * truncated. As an exception, the value 0 means the untruncated algorithm, + * whatever its length is. The length is encoded in 6 bits, so it can + * reach up to 63; the largest MAC is 64 bytes so its trivial truncation + * to full length is correctly encoded as 0 and any non-trivial truncation + * is correctly encoded as a value between 1 and 63. */ +#define PSA_ALG_MAC_TRUNCATION_MASK ((psa_algorithm_t)0x003f0000) +#define PSA_MAC_TRUNCATION_OFFSET 16 + +/* In the encoding of a MAC algorithm, the bit corresponding to + * #PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG encodes the fact that the algorithm + * is a wildcard algorithm. A key with such wildcard algorithm as permitted + * algorithm policy can be used with any algorithm corresponding to the + * same base class and having a (potentially truncated) MAC length greater or + * equal than the one encoded in #PSA_ALG_MAC_TRUNCATION_MASK. */ +#define PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG ((psa_algorithm_t)0x00008000) + +/** Macro to build a truncated MAC algorithm. + * + * A truncated MAC algorithm is identical to the corresponding MAC + * algorithm except that the MAC value for the truncated algorithm + * consists of only the first \p mac_length bytes of the MAC value + * for the untruncated algorithm. + * + * \note This macro may allow constructing algorithm identifiers that + * are not valid, either because the specified length is larger + * than the untruncated MAC or because the specified length is + * smaller than permitted by the implementation. + * + * \note It is implementation-defined whether a truncated MAC that + * is truncated to the same length as the MAC of the untruncated + * algorithm is considered identical to the untruncated algorithm + * for policy comparison purposes. + * + * \param mac_alg A MAC algorithm identifier (value of type + * #psa_algorithm_t such that #PSA_ALG_IS_MAC(\p mac_alg) + * is true). This may be a truncated or untruncated + * MAC algorithm. + * \param mac_length Desired length of the truncated MAC in bytes. + * This must be at most the full length of the MAC + * and must be at least an implementation-specified + * minimum. The implementation-specified minimum + * shall not be zero. + * + * \return The corresponding MAC algorithm with the specified + * length. + * \return Unspecified if \p mac_alg is not a supported + * MAC algorithm or if \p mac_length is too small or + * too large for the specified MAC algorithm. + */ +#define PSA_ALG_TRUNCATED_MAC(mac_alg, mac_length) \ + (((mac_alg) & ~(PSA_ALG_MAC_TRUNCATION_MASK | \ + PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG)) | \ + ((mac_length) << PSA_MAC_TRUNCATION_OFFSET & PSA_ALG_MAC_TRUNCATION_MASK)) + +/** Macro to build the base MAC algorithm corresponding to a truncated + * MAC algorithm. + * + * \param mac_alg A MAC algorithm identifier (value of type + * #psa_algorithm_t such that #PSA_ALG_IS_MAC(\p mac_alg) + * is true). This may be a truncated or untruncated + * MAC algorithm. + * + * \return The corresponding base MAC algorithm. + * \return Unspecified if \p mac_alg is not a supported + * MAC algorithm. + */ +#define PSA_ALG_FULL_LENGTH_MAC(mac_alg) \ + ((mac_alg) & ~(PSA_ALG_MAC_TRUNCATION_MASK | \ + PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG)) + +/** Length to which a MAC algorithm is truncated. + * + * \param mac_alg A MAC algorithm identifier (value of type + * #psa_algorithm_t such that #PSA_ALG_IS_MAC(\p mac_alg) + * is true). + * + * \return Length of the truncated MAC in bytes. + * \return 0 if \p mac_alg is a non-truncated MAC algorithm. + * \return Unspecified if \p mac_alg is not a supported + * MAC algorithm. + */ +#define PSA_MAC_TRUNCATED_LENGTH(mac_alg) \ + (((mac_alg) & PSA_ALG_MAC_TRUNCATION_MASK) >> PSA_MAC_TRUNCATION_OFFSET) + +/** Macro to build a MAC minimum-MAC-length wildcard algorithm. + * + * A minimum-MAC-length MAC wildcard algorithm permits all MAC algorithms + * sharing the same base algorithm, and where the (potentially truncated) MAC + * length of the specific algorithm is equal to or larger then the wildcard + * algorithm's minimum MAC length. + * + * \note When setting the minimum required MAC length to less than the + * smallest MAC length allowed by the base algorithm, this effectively + * becomes an 'any-MAC-length-allowed' policy for that base algorithm. + * + * \param mac_alg A MAC algorithm identifier (value of type + * #psa_algorithm_t such that #PSA_ALG_IS_MAC(\p mac_alg) + * is true). + * \param min_mac_length Desired minimum length of the message authentication + * code in bytes. This must be at most the untruncated + * length of the MAC and must be at least 1. + * + * \return The corresponding MAC wildcard algorithm with the + * specified minimum length. + * \return Unspecified if \p mac_alg is not a supported MAC + * algorithm or if \p min_mac_length is less than 1 or + * too large for the specified MAC algorithm. + */ +#define PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(mac_alg, min_mac_length) \ + ( PSA_ALG_TRUNCATED_MAC(mac_alg, min_mac_length) | \ + PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG ) + +#define PSA_ALG_CIPHER_MAC_BASE ((psa_algorithm_t)0x03c00000) +/** The CBC-MAC construction over a block cipher + * + * \warning CBC-MAC is insecure in many cases. + * A more secure mode, such as #PSA_ALG_CMAC, is recommended. + */ +#define PSA_ALG_CBC_MAC ((psa_algorithm_t)0x03c00100) +/** The CMAC construction over a block cipher */ +#define PSA_ALG_CMAC ((psa_algorithm_t)0x03c00200) + +/** Whether the specified algorithm is a MAC algorithm based on a block cipher. + * + * \param alg An algorithm identifier (value of type #psa_algorithm_t). + * + * \return 1 if \p alg is a MAC algorithm based on a block cipher, 0 otherwise. + * This macro may return either 0 or 1 if \p alg is not a supported + * algorithm identifier. + */ +#define PSA_ALG_IS_BLOCK_CIPHER_MAC(alg) \ + (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_MAC_SUBCATEGORY_MASK)) == \ + PSA_ALG_CIPHER_MAC_BASE) + +#define PSA_ALG_CIPHER_STREAM_FLAG ((psa_algorithm_t)0x00800000) +#define PSA_ALG_CIPHER_FROM_BLOCK_FLAG ((psa_algorithm_t)0x00400000) + +/** Whether the specified algorithm is a stream cipher. + * + * A stream cipher is a symmetric cipher that encrypts or decrypts messages + * by applying a bitwise-xor with a stream of bytes that is generated + * from a key. + * + * \param alg An algorithm identifier (value of type #psa_algorithm_t). + * + * \return 1 if \p alg is a stream cipher algorithm, 0 otherwise. + * This macro may return either 0 or 1 if \p alg is not a supported + * algorithm identifier or if it is not a symmetric cipher algorithm. + */ +#define PSA_ALG_IS_STREAM_CIPHER(alg) \ + (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_CIPHER_STREAM_FLAG)) == \ + (PSA_ALG_CATEGORY_CIPHER | PSA_ALG_CIPHER_STREAM_FLAG)) + +/** The stream cipher mode of a stream cipher algorithm. + * + * The underlying stream cipher is determined by the key type. + * - To use ChaCha20, use a key type of #PSA_KEY_TYPE_CHACHA20. + * - To use ARC4, use a key type of #PSA_KEY_TYPE_ARC4. + */ +#define PSA_ALG_STREAM_CIPHER ((psa_algorithm_t)0x04800100) + +/** The CTR stream cipher mode. + * + * CTR is a stream cipher which is built from a block cipher. + * The underlying block cipher is determined by the key type. + * For example, to use AES-128-CTR, use this algorithm with + * a key of type #PSA_KEY_TYPE_AES and a length of 128 bits (16 bytes). + */ +#define PSA_ALG_CTR ((psa_algorithm_t)0x04c01000) + +/** The CFB stream cipher mode. + * + * The underlying block cipher is determined by the key type. + */ +#define PSA_ALG_CFB ((psa_algorithm_t)0x04c01100) + +/** The OFB stream cipher mode. + * + * The underlying block cipher is determined by the key type. + */ +#define PSA_ALG_OFB ((psa_algorithm_t)0x04c01200) + +/** The XTS cipher mode. + * + * XTS is a cipher mode which is built from a block cipher. It requires at + * least one full block of input, but beyond this minimum the input + * does not need to be a whole number of blocks. + */ +#define PSA_ALG_XTS ((psa_algorithm_t)0x0440ff00) + +/** The Electronic Code Book (ECB) mode of a block cipher, with no padding. + * + * \warning ECB mode does not protect the confidentiality of the encrypted data + * except in extremely narrow circumstances. It is recommended that applications + * only use ECB if they need to construct an operating mode that the + * implementation does not provide. Implementations are encouraged to provide + * the modes that applications need in preference to supporting direct access + * to ECB. + * + * The underlying block cipher is determined by the key type. + * + * This symmetric cipher mode can only be used with messages whose lengths are a + * multiple of the block size of the chosen block cipher. + * + * ECB mode does not accept an initialization vector (IV). When using a + * multi-part cipher operation with this algorithm, psa_cipher_generate_iv() + * and psa_cipher_set_iv() must not be called. + */ +#define PSA_ALG_ECB_NO_PADDING ((psa_algorithm_t)0x04404400) + +/** The CBC block cipher chaining mode, with no padding. + * + * The underlying block cipher is determined by the key type. + * + * This symmetric cipher mode can only be used with messages whose lengths + * are whole number of blocks for the chosen block cipher. + */ +#define PSA_ALG_CBC_NO_PADDING ((psa_algorithm_t)0x04404000) + +/** The CBC block cipher chaining mode with PKCS#7 padding. + * + * The underlying block cipher is determined by the key type. + * + * This is the padding method defined by PKCS#7 (RFC 2315) §10.3. + */ +#define PSA_ALG_CBC_PKCS7 ((psa_algorithm_t)0x04404100) + +#define PSA_ALG_AEAD_FROM_BLOCK_FLAG ((psa_algorithm_t)0x00400000) + +/** Whether the specified algorithm is an AEAD mode on a block cipher. + * + * \param alg An algorithm identifier (value of type #psa_algorithm_t). + * + * \return 1 if \p alg is an AEAD algorithm which is an AEAD mode based on + * a block cipher, 0 otherwise. + * This macro may return either 0 or 1 if \p alg is not a supported + * algorithm identifier. + */ +#define PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) \ + (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_AEAD_FROM_BLOCK_FLAG)) == \ + (PSA_ALG_CATEGORY_AEAD | PSA_ALG_AEAD_FROM_BLOCK_FLAG)) + +/** The CCM authenticated encryption algorithm. + * + * The underlying block cipher is determined by the key type. + */ +#define PSA_ALG_CCM ((psa_algorithm_t)0x05500100) + +/** The GCM authenticated encryption algorithm. + * + * The underlying block cipher is determined by the key type. + */ +#define PSA_ALG_GCM ((psa_algorithm_t)0x05500200) + +/** The Chacha20-Poly1305 AEAD algorithm. + * + * The ChaCha20_Poly1305 construction is defined in RFC 7539. + * + * Implementations must support 12-byte nonces, may support 8-byte nonces, + * and should reject other sizes. + * + * Implementations must support 16-byte tags and should reject other sizes. + */ +#define PSA_ALG_CHACHA20_POLY1305 ((psa_algorithm_t)0x05100500) + +/* In the encoding of a AEAD algorithm, the bits corresponding to + * PSA_ALG_AEAD_TAG_LENGTH_MASK encode the length of the AEAD tag. + * The constants for default lengths follow this encoding. + */ +#define PSA_ALG_AEAD_TAG_LENGTH_MASK ((psa_algorithm_t)0x003f0000) +#define PSA_AEAD_TAG_LENGTH_OFFSET 16 + +/* In the encoding of an AEAD algorithm, the bit corresponding to + * #PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG encodes the fact that the algorithm + * is a wildcard algorithm. A key with such wildcard algorithm as permitted + * algorithm policy can be used with any algorithm corresponding to the + * same base class and having a tag length greater than or equal to the one + * encoded in #PSA_ALG_AEAD_TAG_LENGTH_MASK. */ +#define PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG ((psa_algorithm_t)0x00008000) + +/** Macro to build a shortened AEAD algorithm. + * + * A shortened AEAD algorithm is similar to the corresponding AEAD + * algorithm, but has an authentication tag that consists of fewer bytes. + * Depending on the algorithm, the tag length may affect the calculation + * of the ciphertext. + * + * \param aead_alg An AEAD algorithm identifier (value of type + * #psa_algorithm_t such that #PSA_ALG_IS_AEAD(\p aead_alg) + * is true). + * \param tag_length Desired length of the authentication tag in bytes. + * + * \return The corresponding AEAD algorithm with the specified + * length. + * \return Unspecified if \p aead_alg is not a supported + * AEAD algorithm or if \p tag_length is not valid + * for the specified AEAD algorithm. + */ +#define PSA_ALG_AEAD_WITH_SHORTENED_TAG(aead_alg, tag_length) \ + (((aead_alg) & ~(PSA_ALG_AEAD_TAG_LENGTH_MASK | \ + PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG)) | \ + ((tag_length) << PSA_AEAD_TAG_LENGTH_OFFSET & \ + PSA_ALG_AEAD_TAG_LENGTH_MASK)) + +/** Retrieve the tag length of a specified AEAD algorithm + * + * \param aead_alg An AEAD algorithm identifier (value of type + * #psa_algorithm_t such that #PSA_ALG_IS_AEAD(\p aead_alg) + * is true). + * + * \return The tag length specified by the input algorithm. + * \return Unspecified if \p aead_alg is not a supported + * AEAD algorithm. + */ +#define PSA_ALG_AEAD_GET_TAG_LENGTH(aead_alg) \ + (((aead_alg) & PSA_ALG_AEAD_TAG_LENGTH_MASK) >> \ + PSA_AEAD_TAG_LENGTH_OFFSET ) + +/** Calculate the corresponding AEAD algorithm with the default tag length. + * + * \param aead_alg An AEAD algorithm (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_AEAD(\p aead_alg) is true). + * + * \return The corresponding AEAD algorithm with the default + * tag length for that algorithm. + */ +#define PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(aead_alg) \ + ( \ + PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG_CASE(aead_alg, PSA_ALG_CCM) \ + PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG_CASE(aead_alg, PSA_ALG_GCM) \ + PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG_CASE(aead_alg, PSA_ALG_CHACHA20_POLY1305) \ + 0) +#define PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG_CASE(aead_alg, ref) \ + PSA_ALG_AEAD_WITH_SHORTENED_TAG(aead_alg, 0) == \ + PSA_ALG_AEAD_WITH_SHORTENED_TAG(ref, 0) ? \ + ref : + +/** Macro to build an AEAD minimum-tag-length wildcard algorithm. + * + * A minimum-tag-length AEAD wildcard algorithm permits all AEAD algorithms + * sharing the same base algorithm, and where the tag length of the specific + * algorithm is equal to or larger then the minimum tag length specified by the + * wildcard algorithm. + * + * \note When setting the minimum required tag length to less than the + * smallest tag length allowed by the base algorithm, this effectively + * becomes an 'any-tag-length-allowed' policy for that base algorithm. + * + * \param aead_alg An AEAD algorithm identifier (value of type + * #psa_algorithm_t such that + * #PSA_ALG_IS_AEAD(\p aead_alg) is true). + * \param min_tag_length Desired minimum length of the authentication tag in + * bytes. This must be at least 1 and at most the largest + * allowed tag length of the algorithm. + * + * \return The corresponding AEAD wildcard algorithm with the + * specified minimum length. + * \return Unspecified if \p aead_alg is not a supported + * AEAD algorithm or if \p min_tag_length is less than 1 + * or too large for the specified AEAD algorithm. + */ +#define PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(aead_alg, min_tag_length) \ + ( PSA_ALG_AEAD_WITH_SHORTENED_TAG(aead_alg, min_tag_length) | \ + PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG ) + +#define PSA_ALG_RSA_PKCS1V15_SIGN_BASE ((psa_algorithm_t)0x06000200) +/** RSA PKCS#1 v1.5 signature with hashing. + * + * This is the signature scheme defined by RFC 8017 + * (PKCS#1: RSA Cryptography Specifications) under the name + * RSASSA-PKCS1-v1_5. + * + * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_HASH(\p hash_alg) is true). + * This includes #PSA_ALG_ANY_HASH + * when specifying the algorithm in a usage policy. + * + * \return The corresponding RSA PKCS#1 v1.5 signature algorithm. + * \return Unspecified if \p hash_alg is not a supported + * hash algorithm. + */ +#define PSA_ALG_RSA_PKCS1V15_SIGN(hash_alg) \ + (PSA_ALG_RSA_PKCS1V15_SIGN_BASE | ((hash_alg) & PSA_ALG_HASH_MASK)) +/** Raw PKCS#1 v1.5 signature. + * + * The input to this algorithm is the DigestInfo structure used by + * RFC 8017 (PKCS#1: RSA Cryptography Specifications), §9.2 + * steps 3–6. + */ +#define PSA_ALG_RSA_PKCS1V15_SIGN_RAW PSA_ALG_RSA_PKCS1V15_SIGN_BASE +#define PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) \ + (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_PKCS1V15_SIGN_BASE) + +#define PSA_ALG_RSA_PSS_BASE ((psa_algorithm_t)0x06000300) +#define PSA_ALG_RSA_PSS_ANY_SALT_BASE ((psa_algorithm_t)0x06001300) +/** RSA PSS signature with hashing. + * + * This is the signature scheme defined by RFC 8017 + * (PKCS#1: RSA Cryptography Specifications) under the name + * RSASSA-PSS, with the message generation function MGF1, and with + * a salt length equal to the length of the hash. The specified + * hash algorithm is used to hash the input message, to create the + * salted hash, and for the mask generation. + * + * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_HASH(\p hash_alg) is true). + * This includes #PSA_ALG_ANY_HASH + * when specifying the algorithm in a usage policy. + * + * \return The corresponding RSA PSS signature algorithm. + * \return Unspecified if \p hash_alg is not a supported + * hash algorithm. + */ +#define PSA_ALG_RSA_PSS(hash_alg) \ + (PSA_ALG_RSA_PSS_BASE | ((hash_alg) & PSA_ALG_HASH_MASK)) + +/** RSA PSS signature with hashing with relaxed verification. + * + * This algorithm has the same behavior as #PSA_ALG_RSA_PSS when signing, + * but allows an arbitrary salt length (including \c 0) when verifying a + * signature. + * + * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_HASH(\p hash_alg) is true). + * This includes #PSA_ALG_ANY_HASH + * when specifying the algorithm in a usage policy. + * + * \return The corresponding RSA PSS signature algorithm. + * \return Unspecified if \p hash_alg is not a supported + * hash algorithm. + */ +#define PSA_ALG_RSA_PSS_ANY_SALT(hash_alg) \ + (PSA_ALG_RSA_PSS_ANY_SALT_BASE | ((hash_alg) & PSA_ALG_HASH_MASK)) + +/** Whether the specified algorithm is RSA PSS with standard salt. + * + * \param alg An algorithm value or an algorithm policy wildcard. + * + * \return 1 if \p alg is of the form + * #PSA_ALG_RSA_PSS(\c hash_alg), + * where \c hash_alg is a hash algorithm or + * #PSA_ALG_ANY_HASH. 0 otherwise. + * This macro may return either 0 or 1 if \p alg is not + * a supported algorithm identifier or policy. + */ +#define PSA_ALG_IS_RSA_PSS_STANDARD_SALT(alg) \ + (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_PSS_BASE) + +/** Whether the specified algorithm is RSA PSS with any salt. + * + * \param alg An algorithm value or an algorithm policy wildcard. + * + * \return 1 if \p alg is of the form + * #PSA_ALG_RSA_PSS_ANY_SALT_BASE(\c hash_alg), + * where \c hash_alg is a hash algorithm or + * #PSA_ALG_ANY_HASH. 0 otherwise. + * This macro may return either 0 or 1 if \p alg is not + * a supported algorithm identifier or policy. + */ +#define PSA_ALG_IS_RSA_PSS_ANY_SALT(alg) \ + (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_PSS_ANY_SALT_BASE) + +/** Whether the specified algorithm is RSA PSS. + * + * This includes any of the RSA PSS algorithm variants, regardless of the + * constraints on salt length. + * + * \param alg An algorithm value or an algorithm policy wildcard. + * + * \return 1 if \p alg is of the form + * #PSA_ALG_RSA_PSS(\c hash_alg) or + * #PSA_ALG_RSA_PSS_ANY_SALT_BASE(\c hash_alg), + * where \c hash_alg is a hash algorithm or + * #PSA_ALG_ANY_HASH. 0 otherwise. + * This macro may return either 0 or 1 if \p alg is not + * a supported algorithm identifier or policy. + */ +#define PSA_ALG_IS_RSA_PSS(alg) \ + (PSA_ALG_IS_RSA_PSS_STANDARD_SALT(alg) || \ + PSA_ALG_IS_RSA_PSS_ANY_SALT(alg)) + +#define PSA_ALG_ECDSA_BASE ((psa_algorithm_t)0x06000600) +/** ECDSA signature with hashing. + * + * This is the ECDSA signature scheme defined by ANSI X9.62, + * with a random per-message secret number (*k*). + * + * The representation of the signature as a byte string consists of + * the concatentation of the signature values *r* and *s*. Each of + * *r* and *s* is encoded as an *N*-octet string, where *N* is the length + * of the base point of the curve in octets. Each value is represented + * in big-endian order (most significant octet first). + * + * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_HASH(\p hash_alg) is true). + * This includes #PSA_ALG_ANY_HASH + * when specifying the algorithm in a usage policy. + * + * \return The corresponding ECDSA signature algorithm. + * \return Unspecified if \p hash_alg is not a supported + * hash algorithm. + */ +#define PSA_ALG_ECDSA(hash_alg) \ + (PSA_ALG_ECDSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK)) +/** ECDSA signature without hashing. + * + * This is the same signature scheme as #PSA_ALG_ECDSA(), but + * without specifying a hash algorithm. This algorithm may only be + * used to sign or verify a sequence of bytes that should be an + * already-calculated hash. Note that the input is padded with + * zeros on the left or truncated on the left as required to fit + * the curve size. + */ +#define PSA_ALG_ECDSA_ANY PSA_ALG_ECDSA_BASE +#define PSA_ALG_DETERMINISTIC_ECDSA_BASE ((psa_algorithm_t)0x06000700) +/** Deterministic ECDSA signature with hashing. + * + * This is the deterministic ECDSA signature scheme defined by RFC 6979. + * + * The representation of a signature is the same as with #PSA_ALG_ECDSA(). + * + * Note that when this algorithm is used for verification, signatures + * made with randomized ECDSA (#PSA_ALG_ECDSA(\p hash_alg)) with the + * same private key are accepted. In other words, + * #PSA_ALG_DETERMINISTIC_ECDSA(\p hash_alg) differs from + * #PSA_ALG_ECDSA(\p hash_alg) only for signature, not for verification. + * + * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_HASH(\p hash_alg) is true). + * This includes #PSA_ALG_ANY_HASH + * when specifying the algorithm in a usage policy. + * + * \return The corresponding deterministic ECDSA signature + * algorithm. + * \return Unspecified if \p hash_alg is not a supported + * hash algorithm. + */ +#define PSA_ALG_DETERMINISTIC_ECDSA(hash_alg) \ + (PSA_ALG_DETERMINISTIC_ECDSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK)) +#define PSA_ALG_ECDSA_DETERMINISTIC_FLAG ((psa_algorithm_t)0x00000100) +#define PSA_ALG_IS_ECDSA(alg) \ + (((alg) & ~PSA_ALG_HASH_MASK & ~PSA_ALG_ECDSA_DETERMINISTIC_FLAG) == \ + PSA_ALG_ECDSA_BASE) +#define PSA_ALG_ECDSA_IS_DETERMINISTIC(alg) \ + (((alg) & PSA_ALG_ECDSA_DETERMINISTIC_FLAG) != 0) +#define PSA_ALG_IS_DETERMINISTIC_ECDSA(alg) \ + (PSA_ALG_IS_ECDSA(alg) && PSA_ALG_ECDSA_IS_DETERMINISTIC(alg)) +#define PSA_ALG_IS_RANDOMIZED_ECDSA(alg) \ + (PSA_ALG_IS_ECDSA(alg) && !PSA_ALG_ECDSA_IS_DETERMINISTIC(alg)) + +/** Edwards-curve digital signature algorithm without prehashing (PureEdDSA), + * using standard parameters. + * + * Contexts are not supported in the current version of this specification + * because there is no suitable signature interface that can take the + * context as a parameter. A future version of this specification may add + * suitable functions and extend this algorithm to support contexts. + * + * PureEdDSA requires an elliptic curve key on a twisted Edwards curve. + * In this specification, the following curves are supported: + * - #PSA_ECC_FAMILY_TWISTED_EDWARDS, 255-bit: Ed25519 as specified + * in RFC 8032. + * The curve is Edwards25519. + * The hash function used internally is SHA-512. + * - #PSA_ECC_FAMILY_TWISTED_EDWARDS, 448-bit: Ed448 as specified + * in RFC 8032. + * The curve is Edwards448. + * The hash function used internally is the first 114 bytes of the + * SHAKE256 output. + * + * This algorithm can be used with psa_sign_message() and + * psa_verify_message(). Since there is no prehashing, it cannot be used + * with psa_sign_hash() or psa_verify_hash(). + * + * The signature format is the concatenation of R and S as defined by + * RFC 8032 §5.1.6 and §5.2.6 (a 64-byte string for Ed25519, a 114-byte + * string for Ed448). + */ +#define PSA_ALG_PURE_EDDSA ((psa_algorithm_t)0x06000800) + +#define PSA_ALG_HASH_EDDSA_BASE ((psa_algorithm_t)0x06000900) +#define PSA_ALG_IS_HASH_EDDSA(alg) \ + (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_HASH_EDDSA_BASE) + +/** Edwards-curve digital signature algorithm with prehashing (HashEdDSA), + * using SHA-512 and the Edwards25519 curve. + * + * See #PSA_ALG_PURE_EDDSA regarding context support and the signature format. + * + * This algorithm is Ed25519 as specified in RFC 8032. + * The curve is Edwards25519. + * The prehash is SHA-512. + * The hash function used internally is SHA-512. + * + * This is a hash-and-sign algorithm: to calculate a signature, + * you can either: + * - call psa_sign_message() on the message; + * - or calculate the SHA-512 hash of the message + * with psa_hash_compute() + * or with a multi-part hash operation started with psa_hash_setup(), + * using the hash algorithm #PSA_ALG_SHA_512, + * then sign the calculated hash with psa_sign_hash(). + * Verifying a signature is similar, using psa_verify_message() or + * psa_verify_hash() instead of the signature function. + */ +#define PSA_ALG_ED25519PH \ + (PSA_ALG_HASH_EDDSA_BASE | (PSA_ALG_SHA_512 & PSA_ALG_HASH_MASK)) + +/** Edwards-curve digital signature algorithm with prehashing (HashEdDSA), + * using SHAKE256 and the Edwards448 curve. + * + * See #PSA_ALG_PURE_EDDSA regarding context support and the signature format. + * + * This algorithm is Ed448 as specified in RFC 8032. + * The curve is Edwards448. + * The prehash is the first 64 bytes of the SHAKE256 output. + * The hash function used internally is the first 114 bytes of the + * SHAKE256 output. + * + * This is a hash-and-sign algorithm: to calculate a signature, + * you can either: + * - call psa_sign_message() on the message; + * - or calculate the first 64 bytes of the SHAKE256 output of the message + * with psa_hash_compute() + * or with a multi-part hash operation started with psa_hash_setup(), + * using the hash algorithm #PSA_ALG_SHAKE256_512, + * then sign the calculated hash with psa_sign_hash(). + * Verifying a signature is similar, using psa_verify_message() or + * psa_verify_hash() instead of the signature function. + */ +#define PSA_ALG_ED448PH \ + (PSA_ALG_HASH_EDDSA_BASE | (PSA_ALG_SHAKE256_512 & PSA_ALG_HASH_MASK)) + +/* Default definition, to be overridden if the library is extended with + * more hash-and-sign algorithms that we want to keep out of this header + * file. */ +#define PSA_ALG_IS_VENDOR_HASH_AND_SIGN(alg) 0 + +/** Whether the specified algorithm is a signature algorithm that can be used + * with psa_sign_hash() and psa_verify_hash(). + * + * This encompasses all strict hash-and-sign algorithms categorized by + * PSA_ALG_IS_HASH_AND_SIGN(), as well as algorithms that follow the + * paradigm more loosely: + * - #PSA_ALG_RSA_PKCS1V15_SIGN_RAW (expects its input to be an encoded hash) + * - #PSA_ALG_ECDSA_ANY (doesn't specify what kind of hash the input is) + * + * \param alg An algorithm identifier (value of type psa_algorithm_t). + * + * \return 1 if alg is a signature algorithm that can be used to sign a + * hash. 0 if alg is a signature algorithm that can only be used + * to sign a message. 0 if alg is not a signature algorithm. + * This macro can return either 0 or 1 if alg is not a + * supported algorithm identifier. + */ +#define PSA_ALG_IS_SIGN_HASH(alg) \ + (PSA_ALG_IS_RSA_PSS(alg) || PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) || \ + PSA_ALG_IS_ECDSA(alg) || PSA_ALG_IS_HASH_EDDSA(alg) || \ + PSA_ALG_IS_VENDOR_HASH_AND_SIGN(alg)) + +/** Whether the specified algorithm is a signature algorithm that can be used + * with psa_sign_message() and psa_verify_message(). + * + * \param alg An algorithm identifier (value of type #psa_algorithm_t). + * + * \return 1 if alg is a signature algorithm that can be used to sign a + * message. 0 if \p alg is a signature algorithm that can only be used + * to sign an already-calculated hash. 0 if \p alg is not a signature + * algorithm. This macro can return either 0 or 1 if \p alg is not a + * supported algorithm identifier. + */ +#define PSA_ALG_IS_SIGN_MESSAGE(alg) \ + (PSA_ALG_IS_SIGN_HASH(alg) || (alg) == PSA_ALG_PURE_EDDSA ) + +/** Whether the specified algorithm is a hash-and-sign algorithm. + * + * Hash-and-sign algorithms are asymmetric (public-key) signature algorithms + * structured in two parts: first the calculation of a hash in a way that + * does not depend on the key, then the calculation of a signature from the + * hash value and the key. Hash-and-sign algorithms encode the hash + * used for the hashing step, and you can call #PSA_ALG_SIGN_GET_HASH + * to extract this algorithm. + * + * Thus, for a hash-and-sign algorithm, + * `psa_sign_message(key, alg, input, ...)` is equivalent to + * ``` + * psa_hash_compute(PSA_ALG_SIGN_GET_HASH(alg), input, ..., hash, ...); + * psa_sign_hash(key, alg, hash, ..., signature, ...); + * ``` + * Most usefully, separating the hash from the signature allows the hash + * to be calculated in multiple steps with psa_hash_setup(), psa_hash_update() + * and psa_hash_finish(). Likewise psa_verify_message() is equivalent to + * calculating the hash and then calling psa_verify_hash(). + * + * \param alg An algorithm identifier (value of type #psa_algorithm_t). + * + * \return 1 if \p alg is a hash-and-sign algorithm, 0 otherwise. + * This macro may return either 0 or 1 if \p alg is not a supported + * algorithm identifier. + */ +#define PSA_ALG_IS_HASH_AND_SIGN(alg) \ + (PSA_ALG_IS_SIGN_HASH(alg) && \ + ((alg) & PSA_ALG_HASH_MASK) != 0) + +/** Get the hash used by a hash-and-sign signature algorithm. + * + * A hash-and-sign algorithm is a signature algorithm which is + * composed of two phases: first a hashing phase which does not use + * the key and produces a hash of the input message, then a signing + * phase which only uses the hash and the key and not the message + * itself. + * + * \param alg A signature algorithm (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_SIGN(\p alg) is true). + * + * \return The underlying hash algorithm if \p alg is a hash-and-sign + * algorithm. + * \return 0 if \p alg is a signature algorithm that does not + * follow the hash-and-sign structure. + * \return Unspecified if \p alg is not a signature algorithm or + * if it is not supported by the implementation. + */ +#define PSA_ALG_SIGN_GET_HASH(alg) \ + (PSA_ALG_IS_HASH_AND_SIGN(alg) ? \ + ((alg) & PSA_ALG_HASH_MASK) | PSA_ALG_CATEGORY_HASH : \ + 0) + +/** RSA PKCS#1 v1.5 encryption. + */ +#define PSA_ALG_RSA_PKCS1V15_CRYPT ((psa_algorithm_t)0x07000200) + +#define PSA_ALG_RSA_OAEP_BASE ((psa_algorithm_t)0x07000300) +/** RSA OAEP encryption. + * + * This is the encryption scheme defined by RFC 8017 + * (PKCS#1: RSA Cryptography Specifications) under the name + * RSAES-OAEP, with the message generation function MGF1. + * + * \param hash_alg The hash algorithm (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_HASH(\p hash_alg) is true) to use + * for MGF1. + * + * \return The corresponding RSA OAEP encryption algorithm. + * \return Unspecified if \p hash_alg is not a supported + * hash algorithm. + */ +#define PSA_ALG_RSA_OAEP(hash_alg) \ + (PSA_ALG_RSA_OAEP_BASE | ((hash_alg) & PSA_ALG_HASH_MASK)) +#define PSA_ALG_IS_RSA_OAEP(alg) \ + (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_OAEP_BASE) +#define PSA_ALG_RSA_OAEP_GET_HASH(alg) \ + (PSA_ALG_IS_RSA_OAEP(alg) ? \ + ((alg) & PSA_ALG_HASH_MASK) | PSA_ALG_CATEGORY_HASH : \ + 0) + +#define PSA_ALG_HKDF_BASE ((psa_algorithm_t)0x08000100) +/** Macro to build an HKDF algorithm. + * + * For example, `PSA_ALG_HKDF(PSA_ALG_SHA256)` is HKDF using HMAC-SHA-256. + * + * This key derivation algorithm uses the following inputs: + * - #PSA_KEY_DERIVATION_INPUT_SALT is the salt used in the "extract" step. + * It is optional; if omitted, the derivation uses an empty salt. + * - #PSA_KEY_DERIVATION_INPUT_SECRET is the secret key used in the "extract" step. + * - #PSA_KEY_DERIVATION_INPUT_INFO is the info string used in the "expand" step. + * You must pass #PSA_KEY_DERIVATION_INPUT_SALT before #PSA_KEY_DERIVATION_INPUT_SECRET. + * You may pass #PSA_KEY_DERIVATION_INPUT_INFO at any time after steup and before + * starting to generate output. + * + * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_HASH(\p hash_alg) is true). + * + * \return The corresponding HKDF algorithm. + * \return Unspecified if \p hash_alg is not a supported + * hash algorithm. + */ +#define PSA_ALG_HKDF(hash_alg) \ + (PSA_ALG_HKDF_BASE | ((hash_alg) & PSA_ALG_HASH_MASK)) +/** Whether the specified algorithm is an HKDF algorithm. + * + * HKDF is a family of key derivation algorithms that are based on a hash + * function and the HMAC construction. + * + * \param alg An algorithm identifier (value of type #psa_algorithm_t). + * + * \return 1 if \c alg is an HKDF algorithm, 0 otherwise. + * This macro may return either 0 or 1 if \c alg is not a supported + * key derivation algorithm identifier. + */ +#define PSA_ALG_IS_HKDF(alg) \ + (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_HKDF_BASE) +#define PSA_ALG_HKDF_GET_HASH(hkdf_alg) \ + (PSA_ALG_CATEGORY_HASH | ((hkdf_alg) & PSA_ALG_HASH_MASK)) + +#define PSA_ALG_TLS12_PRF_BASE ((psa_algorithm_t)0x08000200) +/** Macro to build a TLS-1.2 PRF algorithm. + * + * TLS 1.2 uses a custom pseudorandom function (PRF) for key schedule, + * specified in Section 5 of RFC 5246. It is based on HMAC and can be + * used with either SHA-256 or SHA-384. + * + * This key derivation algorithm uses the following inputs, which must be + * passed in the order given here: + * - #PSA_KEY_DERIVATION_INPUT_SEED is the seed. + * - #PSA_KEY_DERIVATION_INPUT_SECRET is the secret key. + * - #PSA_KEY_DERIVATION_INPUT_LABEL is the label. + * + * For the application to TLS-1.2 key expansion, the seed is the + * concatenation of ServerHello.Random + ClientHello.Random, + * and the label is "key expansion". + * + * For example, `PSA_ALG_TLS12_PRF(PSA_ALG_SHA256)` represents the + * TLS 1.2 PRF using HMAC-SHA-256. + * + * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_HASH(\p hash_alg) is true). + * + * \return The corresponding TLS-1.2 PRF algorithm. + * \return Unspecified if \p hash_alg is not a supported + * hash algorithm. + */ +#define PSA_ALG_TLS12_PRF(hash_alg) \ + (PSA_ALG_TLS12_PRF_BASE | ((hash_alg) & PSA_ALG_HASH_MASK)) + +/** Whether the specified algorithm is a TLS-1.2 PRF algorithm. + * + * \param alg An algorithm identifier (value of type #psa_algorithm_t). + * + * \return 1 if \c alg is a TLS-1.2 PRF algorithm, 0 otherwise. + * This macro may return either 0 or 1 if \c alg is not a supported + * key derivation algorithm identifier. + */ +#define PSA_ALG_IS_TLS12_PRF(alg) \ + (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_TLS12_PRF_BASE) +#define PSA_ALG_TLS12_PRF_GET_HASH(hkdf_alg) \ + (PSA_ALG_CATEGORY_HASH | ((hkdf_alg) & PSA_ALG_HASH_MASK)) + +#define PSA_ALG_TLS12_PSK_TO_MS_BASE ((psa_algorithm_t)0x08000300) +/** Macro to build a TLS-1.2 PSK-to-MasterSecret algorithm. + * + * In a pure-PSK handshake in TLS 1.2, the master secret is derived + * from the PreSharedKey (PSK) through the application of padding + * (RFC 4279, Section 2) and the TLS-1.2 PRF (RFC 5246, Section 5). + * The latter is based on HMAC and can be used with either SHA-256 + * or SHA-384. + * + * This key derivation algorithm uses the following inputs, which must be + * passed in the order given here: + * - #PSA_KEY_DERIVATION_INPUT_SEED is the seed. + * - #PSA_KEY_DERIVATION_INPUT_SECRET is the secret key. + * - #PSA_KEY_DERIVATION_INPUT_LABEL is the label. + * + * For the application to TLS-1.2, the seed (which is + * forwarded to the TLS-1.2 PRF) is the concatenation of the + * ClientHello.Random + ServerHello.Random, + * and the label is "master secret" or "extended master secret". + * + * For example, `PSA_ALG_TLS12_PSK_TO_MS(PSA_ALG_SHA256)` represents the + * TLS-1.2 PSK to MasterSecret derivation PRF using HMAC-SHA-256. + * + * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_HASH(\p hash_alg) is true). + * + * \return The corresponding TLS-1.2 PSK to MS algorithm. + * \return Unspecified if \p hash_alg is not a supported + * hash algorithm. + */ +#define PSA_ALG_TLS12_PSK_TO_MS(hash_alg) \ + (PSA_ALG_TLS12_PSK_TO_MS_BASE | ((hash_alg) & PSA_ALG_HASH_MASK)) + +/** Whether the specified algorithm is a TLS-1.2 PSK to MS algorithm. + * + * \param alg An algorithm identifier (value of type #psa_algorithm_t). + * + * \return 1 if \c alg is a TLS-1.2 PSK to MS algorithm, 0 otherwise. + * This macro may return either 0 or 1 if \c alg is not a supported + * key derivation algorithm identifier. + */ +#define PSA_ALG_IS_TLS12_PSK_TO_MS(alg) \ + (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_TLS12_PSK_TO_MS_BASE) +#define PSA_ALG_TLS12_PSK_TO_MS_GET_HASH(hkdf_alg) \ + (PSA_ALG_CATEGORY_HASH | ((hkdf_alg) & PSA_ALG_HASH_MASK)) + +#define PSA_ALG_KEY_DERIVATION_MASK ((psa_algorithm_t)0xfe00ffff) +#define PSA_ALG_KEY_AGREEMENT_MASK ((psa_algorithm_t)0xffff0000) + +/** Macro to build a combined algorithm that chains a key agreement with + * a key derivation. + * + * \param ka_alg A key agreement algorithm (\c PSA_ALG_XXX value such + * that #PSA_ALG_IS_KEY_AGREEMENT(\p ka_alg) is true). + * \param kdf_alg A key derivation algorithm (\c PSA_ALG_XXX value such + * that #PSA_ALG_IS_KEY_DERIVATION(\p kdf_alg) is true). + * + * \return The corresponding key agreement and derivation + * algorithm. + * \return Unspecified if \p ka_alg is not a supported + * key agreement algorithm or \p kdf_alg is not a + * supported key derivation algorithm. + */ +#define PSA_ALG_KEY_AGREEMENT(ka_alg, kdf_alg) \ + ((ka_alg) | (kdf_alg)) + +#define PSA_ALG_KEY_AGREEMENT_GET_KDF(alg) \ + (((alg) & PSA_ALG_KEY_DERIVATION_MASK) | PSA_ALG_CATEGORY_KEY_DERIVATION) + +#define PSA_ALG_KEY_AGREEMENT_GET_BASE(alg) \ + (((alg) & PSA_ALG_KEY_AGREEMENT_MASK) | PSA_ALG_CATEGORY_KEY_AGREEMENT) + +/** Whether the specified algorithm is a raw key agreement algorithm. + * + * A raw key agreement algorithm is one that does not specify + * a key derivation function. + * Usually, raw key agreement algorithms are constructed directly with + * a \c PSA_ALG_xxx macro while non-raw key agreement algorithms are + * constructed with #PSA_ALG_KEY_AGREEMENT(). + * + * \param alg An algorithm identifier (value of type #psa_algorithm_t). + * + * \return 1 if \p alg is a raw key agreement algorithm, 0 otherwise. + * This macro may return either 0 or 1 if \p alg is not a supported + * algorithm identifier. + */ +#define PSA_ALG_IS_RAW_KEY_AGREEMENT(alg) \ + (PSA_ALG_IS_KEY_AGREEMENT(alg) && \ + PSA_ALG_KEY_AGREEMENT_GET_KDF(alg) == PSA_ALG_CATEGORY_KEY_DERIVATION) + +#define PSA_ALG_IS_KEY_DERIVATION_OR_AGREEMENT(alg) \ + ((PSA_ALG_IS_KEY_DERIVATION(alg) || PSA_ALG_IS_KEY_AGREEMENT(alg))) + +/** The finite-field Diffie-Hellman (DH) key agreement algorithm. + * + * The shared secret produced by key agreement is + * `g^{ab}` in big-endian format. + * It is `ceiling(m / 8)` bytes long where `m` is the size of the prime `p` + * in bits. + */ +#define PSA_ALG_FFDH ((psa_algorithm_t)0x09010000) + +/** Whether the specified algorithm is a finite field Diffie-Hellman algorithm. + * + * This includes the raw finite field Diffie-Hellman algorithm as well as + * finite-field Diffie-Hellman followed by any supporter key derivation + * algorithm. + * + * \param alg An algorithm identifier (value of type #psa_algorithm_t). + * + * \return 1 if \c alg is a finite field Diffie-Hellman algorithm, 0 otherwise. + * This macro may return either 0 or 1 if \c alg is not a supported + * key agreement algorithm identifier. + */ +#define PSA_ALG_IS_FFDH(alg) \ + (PSA_ALG_KEY_AGREEMENT_GET_BASE(alg) == PSA_ALG_FFDH) + +/** The elliptic curve Diffie-Hellman (ECDH) key agreement algorithm. + * + * The shared secret produced by key agreement is the x-coordinate of + * the shared secret point. It is always `ceiling(m / 8)` bytes long where + * `m` is the bit size associated with the curve, i.e. the bit size of the + * order of the curve's coordinate field. When `m` is not a multiple of 8, + * the byte containing the most significant bit of the shared secret + * is padded with zero bits. The byte order is either little-endian + * or big-endian depending on the curve type. + * + * - For Montgomery curves (curve types `PSA_ECC_FAMILY_CURVEXXX`), + * the shared secret is the x-coordinate of `d_A Q_B = d_B Q_A` + * in little-endian byte order. + * The bit size is 448 for Curve448 and 255 for Curve25519. + * - For Weierstrass curves over prime fields (curve types + * `PSA_ECC_FAMILY_SECPXXX` and `PSA_ECC_FAMILY_BRAINPOOL_PXXX`), + * the shared secret is the x-coordinate of `d_A Q_B = d_B Q_A` + * in big-endian byte order. + * The bit size is `m = ceiling(log_2(p))` for the field `F_p`. + * - For Weierstrass curves over binary fields (curve types + * `PSA_ECC_FAMILY_SECTXXX`), + * the shared secret is the x-coordinate of `d_A Q_B = d_B Q_A` + * in big-endian byte order. + * The bit size is `m` for the field `F_{2^m}`. + */ +#define PSA_ALG_ECDH ((psa_algorithm_t)0x09020000) + +/** Whether the specified algorithm is an elliptic curve Diffie-Hellman + * algorithm. + * + * This includes the raw elliptic curve Diffie-Hellman algorithm as well as + * elliptic curve Diffie-Hellman followed by any supporter key derivation + * algorithm. + * + * \param alg An algorithm identifier (value of type #psa_algorithm_t). + * + * \return 1 if \c alg is an elliptic curve Diffie-Hellman algorithm, + * 0 otherwise. + * This macro may return either 0 or 1 if \c alg is not a supported + * key agreement algorithm identifier. + */ +#define PSA_ALG_IS_ECDH(alg) \ + (PSA_ALG_KEY_AGREEMENT_GET_BASE(alg) == PSA_ALG_ECDH) + +/** Whether the specified algorithm encoding is a wildcard. + * + * Wildcard values may only be used to set the usage algorithm field in + * a policy, not to perform an operation. + * + * \param alg An algorithm identifier (value of type #psa_algorithm_t). + * + * \return 1 if \c alg is a wildcard algorithm encoding. + * \return 0 if \c alg is a non-wildcard algorithm encoding (suitable for + * an operation). + * \return This macro may return either 0 or 1 if \c alg is not a supported + * algorithm identifier. + */ +#define PSA_ALG_IS_WILDCARD(alg) \ + (PSA_ALG_IS_HASH_AND_SIGN(alg) ? \ + PSA_ALG_SIGN_GET_HASH(alg) == PSA_ALG_ANY_HASH : \ + PSA_ALG_IS_MAC(alg) ? \ + (alg & PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG) != 0 : \ + PSA_ALG_IS_AEAD(alg) ? \ + (alg & PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG) != 0 : \ + (alg) == PSA_ALG_ANY_HASH) + +/**@}*/ + +/** \defgroup key_lifetimes Key lifetimes + * @{ + */ + +/** The default lifetime for volatile keys. + * + * A volatile key only exists as long as the identifier to it is not destroyed. + * The key material is guaranteed to be erased on a power reset. + * + * A key with this lifetime is typically stored in the RAM area of the + * PSA Crypto subsystem. However this is an implementation choice. + * If an implementation stores data about the key in a non-volatile memory, + * it must release all the resources associated with the key and erase the + * key material if the calling application terminates. + */ +#define PSA_KEY_LIFETIME_VOLATILE ((psa_key_lifetime_t)0x00000000) + +/** The default lifetime for persistent keys. + * + * A persistent key remains in storage until it is explicitly destroyed or + * until the corresponding storage area is wiped. This specification does + * not define any mechanism to wipe a storage area, but integrations may + * provide their own mechanism (for example to perform a factory reset, + * to prepare for device refurbishment, or to uninstall an application). + * + * This lifetime value is the default storage area for the calling + * application. Integrations of Mbed TLS may support other persistent lifetimes. + * See ::psa_key_lifetime_t for more information. + */ +#define PSA_KEY_LIFETIME_PERSISTENT ((psa_key_lifetime_t)0x00000001) + +/** The persistence level of volatile keys. + * + * See ::psa_key_persistence_t for more information. + */ +#define PSA_KEY_PERSISTENCE_VOLATILE ((psa_key_persistence_t)0x00) + +/** The default persistence level for persistent keys. + * + * See ::psa_key_persistence_t for more information. + */ +#define PSA_KEY_PERSISTENCE_DEFAULT ((psa_key_persistence_t)0x01) + +/** A persistence level indicating that a key is never destroyed. + * + * See ::psa_key_persistence_t for more information. + */ +#define PSA_KEY_PERSISTENCE_READ_ONLY ((psa_key_persistence_t)0xff) + +#define PSA_KEY_LIFETIME_GET_PERSISTENCE(lifetime) \ + ((psa_key_persistence_t)((lifetime) & 0x000000ff)) + +#define PSA_KEY_LIFETIME_GET_LOCATION(lifetime) \ + ((psa_key_location_t)((lifetime) >> 8)) + +/** Whether a key lifetime indicates that the key is volatile. + * + * A volatile key is automatically destroyed by the implementation when + * the application instance terminates. In particular, a volatile key + * is automatically destroyed on a power reset of the device. + * + * A key that is not volatile is persistent. Persistent keys are + * preserved until the application explicitly destroys them or until an + * implementation-specific device management event occurs (for example, + * a factory reset). + * + * \param lifetime The lifetime value to query (value of type + * ::psa_key_lifetime_t). + * + * \return \c 1 if the key is volatile, otherwise \c 0. + */ +#define PSA_KEY_LIFETIME_IS_VOLATILE(lifetime) \ + (PSA_KEY_LIFETIME_GET_PERSISTENCE(lifetime) == \ + PSA_KEY_PERSISTENCE_VOLATILE) + +/** Whether a key lifetime indicates that the key is read-only. + * + * Read-only keys cannot be created or destroyed through the PSA Crypto API. + * They must be created through platform-specific means that bypass the API. + * + * Some platforms may offer ways to destroy read-only keys. For example, + * consider a platform with multiple levels of privilege, where a + * low-privilege application can use a key but is not allowed to destroy + * it, and the platform exposes the key to the application with a read-only + * lifetime. High-privilege code can destroy the key even though the + * application sees the key as read-only. + * + * \param lifetime The lifetime value to query (value of type + * ::psa_key_lifetime_t). + * + * \return \c 1 if the key is read-only, otherwise \c 0. + */ +#define PSA_KEY_LIFETIME_IS_READ_ONLY(lifetime) \ + (PSA_KEY_LIFETIME_GET_PERSISTENCE(lifetime) == \ + PSA_KEY_PERSISTENCE_READ_ONLY) + +/** Construct a lifetime from a persistence level and a location. + * + * \param persistence The persistence level + * (value of type ::psa_key_persistence_t). + * \param location The location indicator + * (value of type ::psa_key_location_t). + * + * \return The constructed lifetime value. + */ +#define PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(persistence, location) \ + ((location) << 8 | (persistence)) + +/** The local storage area for persistent keys. + * + * This storage area is available on all systems that can store persistent + * keys without delegating the storage to a third-party cryptoprocessor. + * + * See ::psa_key_location_t for more information. + */ +#define PSA_KEY_LOCATION_LOCAL_STORAGE ((psa_key_location_t)0x000000) + +#define PSA_KEY_LOCATION_VENDOR_FLAG ((psa_key_location_t)0x800000) + +/** The null key identifier. + */ +#define PSA_KEY_ID_NULL ((psa_key_id_t)0) +/** The minimum value for a key identifier chosen by the application. + */ +#define PSA_KEY_ID_USER_MIN ((psa_key_id_t)0x00000001) +/** The maximum value for a key identifier chosen by the application. + */ +#define PSA_KEY_ID_USER_MAX ((psa_key_id_t)0x3fffffff) +/** The minimum value for a key identifier chosen by the implementation. + */ +#define PSA_KEY_ID_VENDOR_MIN ((psa_key_id_t)0x40000000) +/** The maximum value for a key identifier chosen by the implementation. + */ +#define PSA_KEY_ID_VENDOR_MAX ((psa_key_id_t)0x7fffffff) + + +#if !defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER) + +#define MBEDTLS_SVC_KEY_ID_INIT ( (psa_key_id_t)0 ) +#define MBEDTLS_SVC_KEY_ID_GET_KEY_ID( id ) ( id ) +#define MBEDTLS_SVC_KEY_ID_GET_OWNER_ID( id ) ( 0 ) + +/** Utility to initialize a key identifier at runtime. + * + * \param unused Unused parameter. + * \param key_id Identifier of the key. + */ +static inline mbedtls_svc_key_id_t mbedtls_svc_key_id_make( + unsigned int unused, psa_key_id_t key_id ) +{ + (void)unused; + + return( key_id ); +} + +/** Compare two key identifiers. + * + * \param id1 First key identifier. + * \param id2 Second key identifier. + * + * \return Non-zero if the two key identifier are equal, zero otherwise. + */ +static inline int mbedtls_svc_key_id_equal( mbedtls_svc_key_id_t id1, + mbedtls_svc_key_id_t id2 ) +{ + return( id1 == id2 ); +} + +/** Check whether a key identifier is null. + * + * \param key Key identifier. + * + * \return Non-zero if the key identifier is null, zero otherwise. + */ +static inline int mbedtls_svc_key_id_is_null( mbedtls_svc_key_id_t key ) +{ + return( key == 0 ); +} + +#else /* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */ + +#define MBEDTLS_SVC_KEY_ID_INIT ( (mbedtls_svc_key_id_t){ 0, 0 } ) +#define MBEDTLS_SVC_KEY_ID_GET_KEY_ID( id ) ( ( id ).key_id ) +#define MBEDTLS_SVC_KEY_ID_GET_OWNER_ID( id ) ( ( id ).owner ) + +/** Utility to initialize a key identifier at runtime. + * + * \param owner_id Identifier of the key owner. + * \param key_id Identifier of the key. + */ +static inline mbedtls_svc_key_id_t mbedtls_svc_key_id_make( + mbedtls_key_owner_id_t owner_id, psa_key_id_t key_id ) +{ + return( (mbedtls_svc_key_id_t){ .key_id = key_id, + .owner = owner_id } ); +} + +/** Compare two key identifiers. + * + * \param id1 First key identifier. + * \param id2 Second key identifier. + * + * \return Non-zero if the two key identifier are equal, zero otherwise. + */ +static inline int mbedtls_svc_key_id_equal( mbedtls_svc_key_id_t id1, + mbedtls_svc_key_id_t id2 ) +{ + return( ( id1.key_id == id2.key_id ) && + mbedtls_key_owner_id_equal( id1.owner, id2.owner ) ); +} + +/** Check whether a key identifier is null. + * + * \param key Key identifier. + * + * \return Non-zero if the key identifier is null, zero otherwise. + */ +static inline int mbedtls_svc_key_id_is_null( mbedtls_svc_key_id_t key ) +{ + return( key.key_id == 0 ); +} + +#endif /* !MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */ + +/**@}*/ + +/** \defgroup policy Key policies + * @{ + */ + +/** Whether the key may be exported. + * + * A public key or the public part of a key pair may always be exported + * regardless of the value of this permission flag. + * + * If a key does not have export permission, implementations shall not + * allow the key to be exported in plain form from the cryptoprocessor, + * whether through psa_export_key() or through a proprietary interface. + * The key may however be exportable in a wrapped form, i.e. in a form + * where it is encrypted by another key. + */ +#define PSA_KEY_USAGE_EXPORT ((psa_key_usage_t)0x00000001) + +/** Whether the key may be copied. + * + * This flag allows the use of psa_copy_key() to make a copy of the key + * with the same policy or a more restrictive policy. + * + * For lifetimes for which the key is located in a secure element which + * enforce the non-exportability of keys, copying a key outside the secure + * element also requires the usage flag #PSA_KEY_USAGE_EXPORT. + * Copying the key inside the secure element is permitted with just + * #PSA_KEY_USAGE_COPY if the secure element supports it. + * For keys with the lifetime #PSA_KEY_LIFETIME_VOLATILE or + * #PSA_KEY_LIFETIME_PERSISTENT, the usage flag #PSA_KEY_USAGE_COPY + * is sufficient to permit the copy. + */ +#define PSA_KEY_USAGE_COPY ((psa_key_usage_t)0x00000002) + +/** Whether the key may be used to encrypt a message. + * + * This flag allows the key to be used for a symmetric encryption operation, + * for an AEAD encryption-and-authentication operation, + * or for an asymmetric encryption operation, + * if otherwise permitted by the key's type and policy. + * + * For a key pair, this concerns the public key. + */ +#define PSA_KEY_USAGE_ENCRYPT ((psa_key_usage_t)0x00000100) + +/** Whether the key may be used to decrypt a message. + * + * This flag allows the key to be used for a symmetric decryption operation, + * for an AEAD decryption-and-verification operation, + * or for an asymmetric decryption operation, + * if otherwise permitted by the key's type and policy. + * + * For a key pair, this concerns the private key. + */ +#define PSA_KEY_USAGE_DECRYPT ((psa_key_usage_t)0x00000200) + +/** Whether the key may be used to sign a message. + * + * This flag allows the key to be used for a MAC calculation operation or for + * an asymmetric message signature operation, if otherwise permitted by the + * key’s type and policy. + * + * For a key pair, this concerns the private key. + */ +#define PSA_KEY_USAGE_SIGN_MESSAGE ((psa_key_usage_t)0x00000400) + +/** Whether the key may be used to verify a message. + * + * This flag allows the key to be used for a MAC verification operation or for + * an asymmetric message signature verification operation, if otherwise + * permitted by the key’s type and policy. + * + * For a key pair, this concerns the public key. + */ +#define PSA_KEY_USAGE_VERIFY_MESSAGE ((psa_key_usage_t)0x00000800) + +/** Whether the key may be used to sign a message. + * + * This flag allows the key to be used for a MAC calculation operation + * or for an asymmetric signature operation, + * if otherwise permitted by the key's type and policy. + * + * For a key pair, this concerns the private key. + */ +#define PSA_KEY_USAGE_SIGN_HASH ((psa_key_usage_t)0x00001000) + +/** Whether the key may be used to verify a message signature. + * + * This flag allows the key to be used for a MAC verification operation + * or for an asymmetric signature verification operation, + * if otherwise permitted by by the key's type and policy. + * + * For a key pair, this concerns the public key. + */ +#define PSA_KEY_USAGE_VERIFY_HASH ((psa_key_usage_t)0x00002000) + +/** Whether the key may be used to derive other keys. + */ +#define PSA_KEY_USAGE_DERIVE ((psa_key_usage_t)0x00004000) + +/**@}*/ + +/** \defgroup derivation Key derivation + * @{ + */ + +/** A secret input for key derivation. + * + * This should be a key of type #PSA_KEY_TYPE_DERIVE + * (passed to psa_key_derivation_input_key()) + * or the shared secret resulting from a key agreement + * (obtained via psa_key_derivation_key_agreement()). + * + * The secret can also be a direct input (passed to + * key_derivation_input_bytes()). In this case, the derivation operation + * may not be used to derive keys: the operation will only allow + * psa_key_derivation_output_bytes(), not psa_key_derivation_output_key(). + */ +#define PSA_KEY_DERIVATION_INPUT_SECRET ((psa_key_derivation_step_t)0x0101) + +/** A label for key derivation. + * + * This should be a direct input. + * It can also be a key of type #PSA_KEY_TYPE_RAW_DATA. + */ +#define PSA_KEY_DERIVATION_INPUT_LABEL ((psa_key_derivation_step_t)0x0201) + +/** A salt for key derivation. + * + * This should be a direct input. + * It can also be a key of type #PSA_KEY_TYPE_RAW_DATA. + */ +#define PSA_KEY_DERIVATION_INPUT_SALT ((psa_key_derivation_step_t)0x0202) + +/** An information string for key derivation. + * + * This should be a direct input. + * It can also be a key of type #PSA_KEY_TYPE_RAW_DATA. + */ +#define PSA_KEY_DERIVATION_INPUT_INFO ((psa_key_derivation_step_t)0x0203) + +/** A seed for key derivation. + * + * This should be a direct input. + * It can also be a key of type #PSA_KEY_TYPE_RAW_DATA. + */ +#define PSA_KEY_DERIVATION_INPUT_SEED ((psa_key_derivation_step_t)0x0204) + +/**@}*/ + +/** \defgroup helper_macros Helper macros + * @{ + */ + +/* Helper macros */ + +/** Check if two AEAD algorithm identifiers refer to the same AEAD algorithm + * regardless of the tag length they encode. + * + * \param aead_alg_1 An AEAD algorithm identifier. + * \param aead_alg_2 An AEAD algorithm identifier. + * + * \return 1 if both identifiers refer to the same AEAD algorithm, + * 0 otherwise. + * Unspecified if neither \p aead_alg_1 nor \p aead_alg_2 are + * a supported AEAD algorithm. + */ +#define MBEDTLS_PSA_ALG_AEAD_EQUAL(aead_alg_1, aead_alg_2) \ + (!(((aead_alg_1) ^ (aead_alg_2)) & \ + ~(PSA_ALG_AEAD_TAG_LENGTH_MASK | PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG))) + +/**@}*/ + +#endif /* PSA_CRYPTO_VALUES_H */ diff --git a/tools/sdk/esp32/include/mbedtls/port/include/mbedtls/esp_config.h b/tools/sdk/esp32/include/mbedtls/port/include/mbedtls/esp_config.h index 9c63118eb57..607d35ffc69 100644 --- a/tools/sdk/esp32/include/mbedtls/port/include/mbedtls/esp_config.h +++ b/tools/sdk/esp32/include/mbedtls/port/include/mbedtls/esp_config.h @@ -1,12 +1,13 @@ /** * - * \brief Default mbedTLS configuration options for esp-idf + * \brief Default mbedTLS configuration options for ESP-IDF * * This set of compile-time options may be used to enable * or disable features selectively, and reduce the global * memory footprint. - * - * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved + */ +/* + * Copyright The Mbed TLS Contributors * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -20,8 +21,6 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * This file is part of mbed TLS (https://tls.mbed.org) */ #ifndef ESP_CONFIG_H @@ -310,18 +309,54 @@ * * \note This option only works with the default software implementation of * elliptic curve functionality. It is incompatible with - * MBEDTLS_ECP_ALT, MBEDTLS_ECDH_XXX_ALT and MBEDTLS_ECDSA_XXX_ALT. + * MBEDTLS_ECP_ALT, MBEDTLS_ECDH_XXX_ALT, MBEDTLS_ECDSA_XXX_ALT + * and MBEDTLS_ECDH_LEGACY_CONTEXT. */ #ifdef CONFIG_MBEDTLS_ECP_RESTARTABLE #define MBEDTLS_ECP_RESTARTABLE #endif +/** + * \def MBEDTLS_ECDH_LEGACY_CONTEXT + * + * Use a backward compatible ECDH context. + * + * Mbed TLS supports two formats for ECDH contexts (#mbedtls_ecdh_context + * defined in `ecdh.h`). For most applications, the choice of format makes + * no difference, since all library functions can work with either format, + * except that the new format is incompatible with MBEDTLS_ECP_RESTARTABLE. + + * The new format used when this option is disabled is smaller + * (56 bytes on a 32-bit platform). In future versions of the library, it + * will support alternative implementations of ECDH operations. + * The new format is incompatible with applications that access + * context fields directly and with restartable ECP operations. + * + * Define this macro if you enable MBEDTLS_ECP_RESTARTABLE or if you + * want to access ECDH context fields directly. Otherwise you should + * comment out this macro definition. + * + * This option has no effect if #MBEDTLS_ECDH_C is not enabled. + * + * \note This configuration option is experimental. Future versions of the + * library may modify the way the ECDH context layout is configured + * and may modify the layout of the new context type. + */ +#ifdef CONFIG_MBEDTLS_ECDH_LEGACY_CONTEXT +#define MBEDTLS_ECDH_LEGACY_CONTEXT +#endif + /** * \def MBEDTLS_CMAC_C * * Enable the CMAC (Cipher-based Message Authentication Code) mode for block * ciphers. * + * \note When #MBEDTLS_CMAC_ALT is active, meaning that the underlying + * implementation of the CMAC algorithm is provided by an alternate + * implementation, that alternate implementation may opt to not support + * AES-192 or 3DES as underlying block ciphers for the CMAC operation. + * * Module: library/cmac.c * * Requires: MBEDTLS_AES_C or MBEDTLS_DES_C @@ -339,6 +374,7 @@ * * Comment macros to disable the curve and functions for it */ +/* Short Weierstrass curves (supporting ECP, ECDH, ECDSA) */ #ifdef CONFIG_MBEDTLS_ECP_DP_SECP192R1_ENABLED #define MBEDTLS_ECP_DP_SECP192R1_ENABLED #else @@ -394,12 +430,12 @@ #else #undef MBEDTLS_ECP_DP_BP512R1_ENABLED #endif +/* Montgomery curves (supporting ECP) */ #ifdef CONFIG_MBEDTLS_ECP_DP_CURVE25519_ENABLED #define MBEDTLS_ECP_DP_CURVE25519_ENABLED #else #undef MBEDTLS_ECP_DP_CURVE25519_ENABLED #endif - #ifdef MBEDTLS_ECP_DP_CURVE448_ENABLED #undef MBEDTLS_ECP_DP_CURVE448_ENABLED #endif @@ -427,7 +463,7 @@ * may result in a compromise of the long-term signing key. This is avoided by * the deterministic variant. * - * Requires: MBEDTLS_HMAC_DRBG_C + * Requires: MBEDTLS_HMAC_DRBG_C, MBEDTLS_ECDSA_C * * Comment this macro to disable deterministic ECDSA. */ @@ -668,7 +704,7 @@ * * Enable the ECDH-ECDSA based ciphersuite modes in SSL / TLS. * - * Requires: MBEDTLS_ECDH_C, MBEDTLS_X509_CRT_PARSE_C + * Requires: MBEDTLS_ECDH_C, MBEDTLS_ECDSA_C, MBEDTLS_X509_CRT_PARSE_C * * This enables the following ciphersuites (if other requisites are * enabled as well): @@ -696,7 +732,7 @@ * * Enable the ECDH-RSA based ciphersuite modes in SSL / TLS. * - * Requires: MBEDTLS_ECDH_C, MBEDTLS_X509_CRT_PARSE_C + * Requires: MBEDTLS_ECDH_C, MBEDTLS_RSA_C, MBEDTLS_X509_CRT_PARSE_C * * This enables the following ciphersuites (if other requisites are * enabled as well): @@ -850,6 +886,69 @@ */ #define MBEDTLS_SSL_ALL_ALERT_MESSAGES +/** + * \def MBEDTLS_SSL_DTLS_CONNECTION_ID + * + * Enable support for the DTLS Connection ID extension + * (version draft-ietf-tls-dtls-connection-id-05, + * https://tools.ietf.org/html/draft-ietf-tls-dtls-connection-id-05) + * which allows to identify DTLS connections across changes + * in the underlying transport. + * + * Setting this option enables the SSL APIs `mbedtls_ssl_set_cid()`, + * `mbedtls_ssl_get_peer_cid()` and `mbedtls_ssl_conf_cid()`. + * See the corresponding documentation for more information. + * + * \warning The Connection ID extension is still in draft state. + * We make no stability promises for the availability + * or the shape of the API controlled by this option. + * + * The maximum lengths of outgoing and incoming CIDs can be configured + * through the options + * - MBEDTLS_SSL_CID_OUT_LEN_MAX + * - MBEDTLS_SSL_CID_IN_LEN_MAX. + * + * Requires: MBEDTLS_SSL_PROTO_DTLS + * + * Uncomment to enable the Connection ID extension. + */ +#ifdef CONFIG_MBEDTLS_SSL_DTLS_CONNECTION_ID +#define MBEDTLS_SSL_DTLS_CONNECTION_ID +#else +#undef MBEDTLS_SSL_DTLS_CONNECTION_ID +#endif + +/** + * \def MBEDTLS_SSL_CONTEXT_SERIALIZATION + * + * Enable serialization of the TLS context structures, through use of the + * functions mbedtls_ssl_context_save() and mbedtls_ssl_context_load(). + * + * This pair of functions allows one side of a connection to serialize the + * context associated with the connection, then free or re-use that context + * while the serialized state is persisted elsewhere, and finally deserialize + * that state to a live context for resuming read/write operations on the + * connection. From a protocol perspective, the state of the connection is + * unaffected, in particular this is entirely transparent to the peer. + * + * Note: this is distinct from TLS session resumption, which is part of the + * protocol and fully visible by the peer. TLS session resumption enables + * establishing new connections associated to a saved session with shorter, + * lighter handshakes, while context serialization is a local optimization in + * handling a single, potentially long-lived connection. + * + * Enabling these APIs makes some SSL structures larger, as 64 extra bytes are + * saved after the handshake to allow for more efficient serialization, so if + * you don't need this feature you'll save RAM by disabling it. + * + * Comment to disable the context serialization APIs. + */ +#ifdef CONFIG_MBEDTLS_SSL_CONTEXT_SERIALIZATION +#define MBEDTLS_SSL_CONTEXT_SERIALIZATION +#else +#undef MBEDTLS_SSL_CONTEXT_SERIALIZATION +#endif + /** \def MBEDTLS_SSL_ENCRYPT_THEN_MAC * * Enable support for Encrypt-then-MAC, RFC 7366. @@ -874,8 +973,8 @@ /** \def MBEDTLS_SSL_EXTENDED_MASTER_SECRET * - * Enable support for Extended Master Secret, aka Session Hash - * (draft-ietf-tls-session-hash-02). + * Enable support for RFC 7627: Session Hash and Extended Master Secret + * Extension. * * This was introduced as "the proper fix" to the Triple Handshake familiy of * attacks, but it is recommended to always use it (even if you disable @@ -897,7 +996,8 @@ /** * \def MBEDTLS_SSL_FALLBACK_SCSV * - * Enable support for FALLBACK_SCSV (draft-ietf-tls-downgrade-scsv-00). + * Enable support for RFC 7507: Fallback Signaling Cipher Suite Value (SCSV) + * for Preventing Protocol Downgrade Attacks. * * For servers, it is recommended to always enable this, unless you support * only one version of TLS, or know for sure that none of your clients @@ -911,6 +1011,32 @@ */ #define MBEDTLS_SSL_FALLBACK_SCSV +/** + * \def MBEDTLS_SSL_KEEP_PEER_CERTIFICATE + * + * This option controls the availability of the API mbedtls_ssl_get_peer_cert() + * giving access to the peer's certificate after completion of the handshake. + * + * Unless you need mbedtls_ssl_peer_cert() in your application, it is + * recommended to disable this option for reduced RAM usage. + * + * \note If this option is disabled, mbedtls_ssl_get_peer_cert() is still + * defined, but always returns \c NULL. + * + * \note This option has no influence on the protection against the + * triple handshake attack. Even if it is disabled, Mbed TLS will + * still ensure that certificates do not change during renegotiation, + * for exaple by keeping a hash of the peer's certificate. + * + * Comment this macro to disable storing the peer's certificate + * after the handshake. + */ +#ifdef CONFIG_MBEDTLS_SSL_KEEP_PEER_CERTIFICATE +#define MBEDTLS_SSL_KEEP_PEER_CERTIFICATE +#else +#undef MBEDTLS_SSL_KEEP_PEER_CERTIFICATE +#endif + /** * \def MBEDTLS_SSL_PROTO_TLS1 * @@ -935,6 +1061,9 @@ * Requires: MBEDTLS_MD5_C * MBEDTLS_SHA1_C * + * \deprecated This option is deprecated and will be removed in a future + * version of Mbed TLS. + * * Comment this macro to disable support for SSL 3.0 */ #ifdef CONFIG_MBEDTLS_SSL_PROTO_SSL3 @@ -1092,6 +1221,41 @@ #undef MBEDTLS_SSL_DTLS_HELLO_VERIFY #endif +/** + * \def MBEDTLS_SSL_DTLS_SRTP + * + * Enable support for negotiation of DTLS-SRTP (RFC 5764) + * through the use_srtp extension. + * + * \note This feature provides the minimum functionality required + * to negotiate the use of DTLS-SRTP and to allow the derivation of + * the associated SRTP packet protection key material. + * In particular, the SRTP packet protection itself, as well as the + * demultiplexing of RTP and DTLS packets at the datagram layer + * (see Section 5 of RFC 5764), are not handled by this feature. + * Instead, after successful completion of a handshake negotiating + * the use of DTLS-SRTP, the extended key exporter API + * mbedtls_ssl_conf_export_keys_ext_cb() should be used to implement + * the key exporter described in Section 4.2 of RFC 5764 and RFC 5705 + * (this is implemented in the SSL example programs). + * The resulting key should then be passed to an SRTP stack. + * + * Setting this option enables the runtime API + * mbedtls_ssl_conf_dtls_srtp_protection_profiles() + * through which the supported DTLS-SRTP protection + * profiles can be configured. You must call this API at + * runtime if you wish to negotiate the use of DTLS-SRTP. + * + * Requires: MBEDTLS_SSL_PROTO_DTLS + * + * Uncomment this to enable support for use_srtp extension. + */ +#ifdef CONFIG_MBEDTLS_SSL_PROTO_DTLS +#define MBEDTLS_SSL_DTLS_SRTP +#else +#undef MBEDTLS_SSL_DTLS_SRTP +#endif + /** * \def MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE * @@ -1176,6 +1340,21 @@ #define MBEDTLS_SSL_TRUNCATED_HMAC /** + * \def MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH + * + * When this option is enabled, the SSL buffer will be resized automatically + * based on the negotiated maximum fragment length in each direction. + * + * Requires: MBEDTLS_SSL_MAX_FRAGMENT_LENGTH + */ +#if defined MBEDTLS_SSL_MAX_FRAGMENT_LENGTH && CONFIG_MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH +#define MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH +#else +#undef MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH +#endif + +/** + * * \def MBEDTLS_VERSION_FEATURES * * Allow run-time checking of compile-time enabled features. Thus allowing users @@ -1641,7 +1820,9 @@ * This module is used by the following key exchanges: * ECDHE-ECDSA * - * Requires: MBEDTLS_ECP_C, MBEDTLS_ASN1_WRITE_C, MBEDTLS_ASN1_PARSE_C + * Requires: MBEDTLS_ECP_C, MBEDTLS_ASN1_WRITE_C, MBEDTLS_ASN1_PARSE_C, + * and at least one MBEDTLS_ECP_DP_XXX_ENABLED for a + * short Weierstrass curve. */ #ifdef CONFIG_MBEDTLS_ECDSA_C #define MBEDTLS_ECDSA_C @@ -1719,11 +1900,11 @@ /** * \def MBEDTLS_GCM_C * - * Enable the Galois/Counter Mode (GCM) for AES. + * Enable the Galois/Counter Mode (GCM). * * Module: library/gcm.c * - * Requires: MBEDTLS_AES_C or MBEDTLS_CAMELLIA_C + * Requires: MBEDTLS_AES_C or MBEDTLS_CAMELLIA_C or MBEDTLS_ARIA_C * * This module enables the AES-GCM and CAMELLIA-GCM ciphersuites, if other * requisites are enabled as well. @@ -2323,6 +2504,29 @@ #undef MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION #endif +/** + * \def MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK + * + * If set, this enables the X.509 API `mbedtls_x509_crt_verify_with_ca_cb()` + * and the SSL API `mbedtls_ssl_conf_ca_cb()` which allow users to configure + * the set of trusted certificates through a callback instead of a linked + * list. + * + * This is useful for example in environments where a large number of trusted + * certificates is present and storing them in a linked list isn't efficient + * enough, or when the set of trusted certificates changes frequently. + * + * See the documentation of `mbedtls_x509_crt_verify_with_ca_cb()` and + * `mbedtls_ssl_conf_ca_cb()` for more information. + * + * Uncomment to enable trusted certificate callbacks. + */ +#ifdef CONFIG_MBEDTLS_X509_TRUSTED_CERT_CALLBACK +#define MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK +#else +#undef MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK +#endif + /** * \def MBEDTLS_X509_CSR_WRITE_C * @@ -2383,6 +2587,51 @@ */ #define MBEDTLS_SSL_IN_CONTENT_LEN CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN +/** \def MBEDTLS_SSL_CID_IN_LEN_MAX + * + * The maximum length of CIDs used for incoming DTLS messages. + * + */ +#ifdef CONFIG_MBEDTLS_SSL_DTLS_CONNECTION_ID +#define MBEDTLS_SSL_CID_IN_LEN_MAX CONFIG_MBEDTLS_SSL_CID_IN_LEN_MAX +#else +#undef MBEDTLS_SSL_CID_IN_LEN_MAX +#endif + + +/** \def MBEDTLS_SSL_CID_OUT_LEN_MAX + * + * The maximum length of CIDs used for outgoing DTLS messages. + * + */ +#ifdef CONFIG_MBEDTLS_SSL_DTLS_CONNECTION_ID +#define MBEDTLS_SSL_CID_OUT_LEN_MAX CONFIG_MBEDTLS_SSL_CID_OUT_LEN_MAX +#else +#undef MBEDTLS_SSL_CID_OUT_LEN_MAX +#endif + +/** \def MBEDTLS_SSL_CID_PADDING_GRANULARITY + * + * This option controls the use of record plaintext padding + * when using the Connection ID extension in DTLS 1.2. + * + * The padding will always be chosen so that the length of the + * padded plaintext is a multiple of the value of this option. + * + * Note: A value of \c 1 means that no padding will be used + * for outgoing records. + * + * Note: On systems lacking division instructions, + * a power of two should be preferred. + * + */ +#ifdef CONFIG_MBEDTLS_SSL_DTLS_CONNECTION_ID +#define MBEDTLS_SSL_CID_PADDING_GRANULARITY CONFIG_MBEDTLS_SSL_CID_PADDING_GRANULARITY +#else +#undef MBEDTLS_SSL_CID_PADDING_GRANULARITY +#endif + + /** \def MBEDTLS_SSL_OUT_CONTENT_LEN * * Maximum outgoing fragment length in bytes. @@ -2416,6 +2665,10 @@ * default. At the time of writing, there is no practical attack on the use * of SHA-1 in handshake signatures, hence this option is turned on by default * for compatibility with existing peers. + * + * \warning SHA-1 is considered a weak message digest and its use constitutes + * a security risk. If possible, we recommend avoiding dependencies + * on it, and considering stronger message digests instead. */ #define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE diff --git a/tools/sdk/esp32/include/nvs_flash/include/nvs.h b/tools/sdk/esp32/include/nvs_flash/include/nvs.h index 26183853b7c..6a45327bbae 100644 --- a/tools/sdk/esp32/include/nvs_flash/include/nvs.h +++ b/tools/sdk/esp32/include/nvs_flash/include/nvs.h @@ -1,16 +1,8 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #ifndef ESP_NVS_H #define ESP_NVS_H @@ -105,7 +97,7 @@ typedef enum { */ typedef struct { char namespace_name[16]; /*!< Namespace to which key-value belong */ - char key[16]; /*!< Key of stored key-value pair */ + char key[NVS_KEY_NAME_MAX_SIZE]; /*!< Key of stored key-value pair */ nvs_type_t type; /*!< Type of stored key-value pair */ } nvs_entry_info_t; diff --git a/tools/sdk/esp32/include/qrcode/include/qrcode.h b/tools/sdk/esp32/include/qrcode/include/qrcode.h index 94076ac51b6..27de85f5baa 100644 --- a/tools/sdk/esp32/include/qrcode/include/qrcode.h +++ b/tools/sdk/esp32/include/qrcode/include/qrcode.h @@ -26,6 +26,8 @@ extern "C" { * @attention 1. Can successfully encode a UTF-8 string of up to 2953 bytes or an alphanumeric * string of up to 4296 characters or any digit string of up to 7089 characters * + * @note This API is kept for backward compatibility + * * @param text string to encode into a QR Code. * * @return @@ -35,6 +37,86 @@ extern "C" { */ esp_err_t qrcode_display(const char *text); +/** + * @brief QR Code handle used by the display function + */ +typedef const uint8_t * esp_qrcode_handle_t; + +/** + * @brief QR Code configuration options + */ +typedef struct { + void (*display_func)(esp_qrcode_handle_t qrcode); /**< Function called for displaying the QR Code after encoding is complete */ + int max_qrcode_version; /**< Max QR Code Version to be used. Range: 2 - 40 */ + int qrcode_ecc_level; /**< Error Correction Level for QR Code */ +} esp_qrcode_config_t; + +/** + * @brief Error Correction Level in a QR Code Symbol + */ +enum { + ESP_QRCODE_ECC_LOW, /**< QR Code Error Tolerance of 7% */ + ESP_QRCODE_ECC_MED, /**< QR Code Error Tolerance of 15% */ + ESP_QRCODE_ECC_QUART, /**< QR Code Error Tolerance of 25% */ + ESP_QRCODE_ECC_HIGH /**< QR Code Error Tolerance of 30% */ +}; + +/** + * @brief Encodes the given string into a QR Code and calls the display function + * + * @attention 1. Can successfully encode a UTF-8 string of up to 2953 bytes or an alphanumeric + * string of up to 4296 characters or any digit string of up to 7089 characters + * + * @param cfg Configuration used for QR Code encoding. + * @param text String to encode into a QR Code. + * + * @return + * - ESP_OK: succeed + * - ESP_FAIL: Failed to encode string into a QR Code + * - ESP_ERR_NO_MEM: Failed to allocate buffer for given max_qrcode_version + */ +esp_err_t esp_qrcode_generate(esp_qrcode_config_t *cfg, const char *text); + +/** + * @brief Displays QR Code on the console + * + * @param qrcode QR Code handle used by the display function. + */ +void esp_qrcode_print_console(esp_qrcode_handle_t qrcode); + +/** + * @brief Returns the side length of the given QR Code + * + * @param qrcode QR Code handle used by the display function. + * + * @return + * - val[21, 177]: Side length of QR Code + */ +int esp_qrcode_get_size(esp_qrcode_handle_t qrcode); + +/** + * @brief Returns the Pixel value for the given coordinates + * False indicates White and True indicates Black + * + * @attention 1. Coordinates for top left corner are (x=0, y=0) + * @attention 2. For out of bound coordinates false (White) is returned + * + * @param qrcode QR Code handle used by the display function. + * @param x X-Coordinate of QR Code module + * @param y Y-Coordinate of QR Code module + * + * @return + * - true: (x, y) Pixel is Black + * - false: (x, y) Pixel is White + */ +bool esp_qrcode_get_module(esp_qrcode_handle_t qrcode, int x, int y); + +#define ESP_QRCODE_CONFIG_DEFAULT() (esp_qrcode_config_t) { \ + .display_func = esp_qrcode_print_console, \ + .max_qrcode_version = 10, \ + .qrcode_ecc_level = ESP_QRCODE_ECC_LOW, \ +} + #ifdef __cplusplus } #endif diff --git a/tools/sdk/esp32/include/rmaker_common/include/esp_rmaker_common_events.h b/tools/sdk/esp32/include/rmaker_common/include/esp_rmaker_common_events.h new file mode 100644 index 00000000000..b77f8a3d142 --- /dev/null +++ b/tools/sdk/esp32/include/rmaker_common/include/esp_rmaker_common_events.h @@ -0,0 +1,60 @@ +// Copyright 2021 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#pragma once +#include +#include +#ifdef __cplusplus +extern "C" +{ +#endif + +/** ESP RainMaker Common Event Base */ +ESP_EVENT_DECLARE_BASE(RMAKER_COMMON_EVENT); + +typedef enum { + /** Node reboot has been triggered. The associated event data is the time in seconds + * (type: uint8_t) after which the node will reboot. Note that this time may not be + * accurate as the events are received asynchronously.*/ + RMAKER_EVENT_REBOOT, + /** Wi-Fi credentials reset. Triggered after calling esp_rmaker_wifi_reset() */ + RMAKER_EVENT_WIFI_RESET, + /** Node reset to factory defaults. Triggered after calling esp_rmaker_factory_reset() */ + RMAKER_EVENT_FACTORY_RESET, + /** Connected to MQTT Broker */ + RMAKER_MQTT_EVENT_CONNECTED, + /** Disconnected from MQTT Broker */ + RMAKER_MQTT_EVENT_DISCONNECTED, + /** MQTT message published successfully. + * Event data will contain the message ID (integer) of published message. + */ + RMAKER_MQTT_EVENT_PUBLISHED, + /** POSIX Timezone Changed. Associated data would be NULL terminated POSIX Timezone + * Eg. "PST8PDT,M3.2.0,M11.1.0" */ + RMAKER_EVENT_TZ_POSIX_CHANGED, + /** Timezone Changed. Associated data would be NULL terminated Timezone. + * Eg. "America/Los_Angeles" + * Note that whenever this event is received, the RMAKER_EVENT_TZ_POSIX_CHANGED event + * will also be received, but not necessarily vice versa. + */ + RMAKER_EVENT_TZ_CHANGED, + /** + * MQTT message deleted from the outbox if the message couldn't have been sent and acknowledged. + * Event data will contain the message ID (integer) of deleted message. + * Valid only if CONFIG_MQTT_REPORT_DELETED_MESSAGES is enabled. + */ + RMAKER_MQTT_EVENT_MSG_DELETED, +} esp_rmaker_common_event_t; +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/esp32/include/rmaker_common/include/esp_rmaker_factory.h b/tools/sdk/esp32/include/rmaker_common/include/esp_rmaker_factory.h new file mode 100644 index 00000000000..9ef781b798b --- /dev/null +++ b/tools/sdk/esp32/include/rmaker_common/include/esp_rmaker_factory.h @@ -0,0 +1,61 @@ +// Copyright 2021 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#pragma once +#include +#include +#include +#ifdef __cplusplus +extern "C" +{ +#endif + +/** Initialize Factory NVS + * + * This initializes the Factory NVS partition which will store data + * that should not be cleared even after a reset to factory. + * + * @return ESP_OK on success. + * @return error on failure. + */ +esp_err_t esp_rmaker_factory_init(void); + +/** Get value from factory NVS + * + * This will search for the specified key in the Factory NVS partition, + * allocate the required memory to hold it, copy the value and return + * the pointer to it. It is responsibility of the caller to free the + * memory when the value is no more required. + * + * @param[in] key The key of the value to be read from factory NVS. + * + * @return pointer to the value on success. + * @return NULL on failure. + */ +void *esp_rmaker_factory_get(const char *key); + +/** Set a value in factory NVS + * + * This will write the value for the specified key into factory NVS. + * + * @param[in] key The key for the value to be set in factory NVS. + * @param[in] data Pointer to the value. + * @param[in] len Length of the value. + * + * @return ESP_OK on success. + * @return error on failure. + */ +esp_err_t esp_rmaker_factory_set(const char *key, void *value, size_t len); +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/esp32/include/rmaker_common/include/esp_rmaker_mqtt_glue.h b/tools/sdk/esp32/include/rmaker_common/include/esp_rmaker_mqtt_glue.h new file mode 100644 index 00000000000..95744bdf58c --- /dev/null +++ b/tools/sdk/esp32/include/rmaker_common/include/esp_rmaker_mqtt_glue.h @@ -0,0 +1,160 @@ +// Copyright 2021 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#pragma once +#include +#include +#include +#ifdef __cplusplus +extern "C" +{ +#endif + +#define RMAKER_MQTT_QOS0 0 +#define RMAKER_MQTT_QOS1 1 + +/** MQTT Connection parameters */ +typedef struct { + /** MQTT Host */ + char *mqtt_host; + /** Client ID */ + char *client_id; + /** Client Certificate in NULL terminated PEM format */ + char *client_cert; + /** Client Key in NULL terminated PEM format */ + char *client_key; + /** Server Certificate in NULL terminated PEM format */ + char *server_cert; +} esp_rmaker_mqtt_conn_params_t; + +/** MQTT Get Connection Parameters function prototype + * + * @return Pointer to \ref esp_rmaker_mqtt_conn_params_t on success. + * @return NULL on failure. + */ +typedef esp_rmaker_mqtt_conn_params_t *(*esp_rmaker_mqtt_get_conn_params_t)(void); + +/** MQTT Subscribe callback prototype + * + * @param[in] topic Topic on which the message was received + * @param[in] payload Data received in the message + * @param[in] payload_len Length of the data + * @param[in] priv_data The private data passed during subscription + */ +typedef void (*esp_rmaker_mqtt_subscribe_cb_t)(const char *topic, void *payload, size_t payload_len, void *priv_data); + +/** MQTT Init function prototype + * + * @param[in] conn_params The MQTT connection parameters. If NULL is passed, it should internally use the + * \ref esp_rmaker_mqtt_get_conn_params call if registered. + * + * @return ESP_OK on success. + * @return error in case of any error. + */ +typedef esp_err_t (*esp_rmaker_mqtt_init_t)(esp_rmaker_mqtt_conn_params_t *conn_params); + +/** MQTT Deinit function prototype + * + * Call this function after MQTT has disconnected. + */ +typedef void (*esp_rmaker_mqtt_deinit_t)(void); + +/** MQTT Connect function prototype + * + * Starts the connection attempts to the MQTT broker. + * This should ideally be called after successful network connection. + * + * @return ESP_OK on success. + * @return error in case of any error. + */ +typedef esp_err_t (*esp_rmaker_mqtt_connect_t)(void); + +/** MQTT Disconnect function prototype + * + * Disconnects from the MQTT broker. + * + * @return ESP_OK on success. + * @return error in case of any error. + */ +typedef esp_err_t (*esp_rmaker_mqtt_disconnect_t)(void); + +/** MQTT Publish Message function prototype + * + * @param[in] topic The MQTT topic on which the message should be published. + * @param[in] data Data to be published. + * @param[in] data_len Length of the data. + * @param[in] qos Quality of service for the message. + * @param[out] msg_id If a non NULL pointer is passed, the id of the published message will be returned in this. + * + * @return ESP_OK on success. + * @return error in case of any error. + */ +typedef esp_err_t (*esp_rmaker_mqtt_publish_t)(const char *topic, void *data, size_t data_len, uint8_t qos, int *msg_id); + +/** MQTT Subscribe function prototype + * + * @param[in] topic The topic to be subscribed to. + * @param[in] cb The callback to be invoked when a message is received on the given topic. + * @param[in] qos Quality of service for the subscription. + * @param[in] priv_data Optional private data to be passed to the callback. + * + * @return ESP_OK on success. + * @return error in case of any error. + */ +typedef esp_err_t (*esp_rmaker_mqtt_subscribe_t)(const char *topic, esp_rmaker_mqtt_subscribe_cb_t cb, uint8_t qos, void *priv_data); + +/** MQTT Unsubscribe function prototype + * + * @param[in] topic Topic from which to unsubscribe. + * + * @return ESP_OK on success. + * @return error in case of any error. + */ +typedef esp_err_t (*esp_rmaker_mqtt_unsubscribe_t)(const char *topic); + +/** MQTT configuration */ +typedef struct { + /** Flag to indicate if the MQTT config setup is done */ + bool setup_done; + /** Pointer to the Get MQTT params function. */ + esp_rmaker_mqtt_get_conn_params_t get_conn_params; + /** Pointer to MQTT Init function. */ + esp_rmaker_mqtt_init_t init; + /** Pointer to MQTT Deinit function. */ + esp_rmaker_mqtt_deinit_t deinit; + /** Pointer to MQTT Connect function. */ + esp_rmaker_mqtt_connect_t connect; + /** Pointer to MQTQ Disconnect function */ + esp_rmaker_mqtt_disconnect_t disconnect; + /** Pointer to MQTT Publish function */ + esp_rmaker_mqtt_publish_t publish; + /** Pointer to MQTT Subscribe function */ + esp_rmaker_mqtt_subscribe_t subscribe; + /** Pointer to MQTT Unsubscribe function */ + esp_rmaker_mqtt_unsubscribe_t unsubscribe; +} esp_rmaker_mqtt_config_t; + +/** Setup MQTT Glue + * + * This function initializes MQTT glue layer with all the default functions. + * + * @param[out] mqtt_config Pointer to an allocated MQTT configuration structure. + * + * @return ESP_OK on success. + * @return error in case of any error. + */ +esp_err_t esp_rmaker_mqtt_glue_setup(esp_rmaker_mqtt_config_t *mqtt_config); + +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_utils.h b/tools/sdk/esp32/include/rmaker_common/include/esp_rmaker_utils.h similarity index 60% rename from tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_utils.h rename to tools/sdk/esp32/include/rmaker_common/include/esp_rmaker_utils.h index f506bf7cf6a..86ab691d492 100644 --- a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_utils.h +++ b/tools/sdk/esp32/include/rmaker_common/include/esp_rmaker_utils.h @@ -1,4 +1,4 @@ -// Copyright 2020 Espressif Systems (Shanghai) PTE LTD +// Copyright 2021 Espressif Systems (Shanghai) PTE LTD // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,12 +15,24 @@ #include #include #include +#include +#include #ifdef __cplusplus extern "C" { #endif +#ifdef CONFIG_SPIRAM +#define MEM_ALLOC_EXTRAM(size) heap_caps_malloc(size, MALLOC_CAP_SPIRAM) +#define MEM_CALLOC_EXTRAM(num, size) heap_caps_calloc(num, size, MALLOC_CAP_SPIRAM) +#define MEM_REALLOC_EXTRAM(ptr, size) heap_caps_realloc(ptr, size, MALLOC_CAP_SPIRAM) +#else +#define MEM_ALLOC_EXTRAM(size) malloc(size) +#define MEM_CALLOC_EXTRAM(num, size) calloc(num, size) +#define MEM_REALLOC_EXTRAM(ptr, size) realloc(ptr, size) +#endif + typedef struct esp_rmaker_time_config { /** If not specified, then 'CONFIG_ESP_RMAKER_SNTP_SERVER_NAME' is used as the SNTP server. */ char *sntp_server_name; @@ -32,7 +44,7 @@ typedef struct esp_rmaker_time_config { sntp_sync_time_cb_t sync_time_cb; } esp_rmaker_time_config_t; -/** Reboot the chip after a delay +/** Reboot the device after a delay * * This API just starts a reboot timer and returns immediately. * The actual reboot is trigerred asynchronously in the timer callback. @@ -40,44 +52,54 @@ typedef struct esp_rmaker_time_config { * their operations (Eg. MQTT publish to indicate OTA success). The \ref RMAKER_EVENT_REBOOT * event is triggered when the reboot timer is started. * - * @param[in] seconds Time in seconds after which the chip should reboot. + * @param[in] seconds Time in seconds after which the device should reboot. * * @return ESP_OK on success. * @return error on failure. */ -esp_err_t esp_rmaker_reboot(uint8_t seconds); +esp_err_t esp_rmaker_reboot(int8_t seconds); -/** Reset Wi-Fi credentials and reboot +/** Reset Wi-Fi credentials and (optionally) reboot * - * This will reset just the Wi-Fi credentials and trigger a reboot. + * This will reset just the Wi-Fi credentials and (optionally) trigger a reboot. * This is useful when you want to keep all the entries in NVS memory * intact, but just change the Wi-Fi credentials. The \ref RMAKER_EVENT_WIFI_RESET - * event is triggered after the reset. + * event is triggered when this API is called. The actual reset will happen after a + * delay if reset_seconds is not zero. * - * @note This function internally calls esp_rmaker_reboot() and returns - * immediately. The reboot happens asynchronously. + * @note This reset and reboot operations will happen asynchronously depending + * on the values passed to the API. * - * @param[in] seconds Time in seconds after which the chip should reboot. + * @param[in] reset_seconds Time in seconds after which the reset should get triggered. + * This will help other modules take some actions before the device actually resets. + * If set to zero, the operation would be performed immediately. + * @param[in] reboot_seconds Time in seconds after which the device should reboot. If set + * to negative value, the device will not reboot at all. * * @return ESP_OK on success. * @return error on failure. */ -esp_err_t esp_rmaker_wifi_reset(uint8_t seconds); +esp_err_t esp_rmaker_wifi_reset(int8_t reset_seconds, int8_t reboot_seconds); /** Reset to factory defaults and reboot * - * This will clear entire NVS partition and trigger a reboot. - * The \ref RMAKER_EVENT_FACTORY_RESET event is triggered after the reset. + * This will clear entire NVS partition and (optionally) trigger a reboot. + * The \ref RMAKER_EVENT_FACTORY_RESET event is triggered when this API is called. + * The actual reset will happen after a delay if reset_seconds is not zero. * - * @note This function internally calls esp_rmaker_reboot() and returns. - * The reboot happens asynchronously. + * @note This reset and reboot operations will happen asynchronously depending + * on the values passed to the API. * - * @param[in] seconds Time in seconds after which the chip should reboot. + * @param[in] reset_seconds Time in seconds after which the reset should get triggered. + * This will help other modules take some actions before the device actually resets. + * If set to zero, the operation would be performed immediately. + * @param[in] reboot_seconds Time in seconds after which the device should reboot. If set + * to negative value, the device will not reboot at all. * * @return ESP_OK on success. * @return error on failure. */ -esp_err_t esp_rmaker_factory_reset(uint8_t seconds); +esp_err_t esp_rmaker_factory_reset(int8_t reset_seconds, int8_t reboot_seconds); /** Initialize time synchronization * @@ -142,16 +164,25 @@ esp_err_t esp_rmaker_time_set_timezone_posix(const char *tz_posix); */ esp_err_t esp_rmaker_time_set_timezone(const char *tz); -/** Enable Timezone Service +/** Get the current POSIX timezone * - * This enables the ESP RainMaker standard timezone service which can be used to set - * timezone, either in POSIX or location string format. Please refer the specifications - * for additional details. + * This fetches the current timezone in POSIX format, read from NVS. * - * @return ESP_OK on success - * @return error on failure + * @return Pointer to a NULL terminated POSIX timezone string on success. + * Freeing this is the responsibility of the caller. + * @return NULL on failure. + */ +char *esp_rmaker_time_get_timezone_posix(void); + +/** Get the current timezone + * + * This fetches the current timezone in POSIX format, read from NVS. + * + * @return Pointer to a NULL terminated timezone string on success. + * Freeing this is the responsibility of the caller. + * @return NULL on failure. */ -esp_err_t esp_rmaker_timezone_service_enable(void); +char *esp_rmaker_time_get_timezone(void); /** Get printable local time string * diff --git a/tools/sdk/esp32/include/rmaker_common/include/esp_rmaker_work_queue.h b/tools/sdk/esp32/include/rmaker_common/include/esp_rmaker_work_queue.h new file mode 100644 index 00000000000..0e696d46848 --- /dev/null +++ b/tools/sdk/esp32/include/rmaker_common/include/esp_rmaker_work_queue.h @@ -0,0 +1,82 @@ +// Copyright 2021 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#pragma once +#include +#include +#include +#ifdef __cplusplus +extern "C" +{ +#endif +/** Prototype for ESP RainMaker Work Queue Function + * + * @param[in] priv_data The private data associated with the work function. + */ +typedef void (*esp_rmaker_work_fn_t)(void *priv_data); + +/** Initializes the Work Queue + * + * This initializes the work queue, which is basically a mechanism to run + * tasks in the context of a dedicated thread. You can start queueing tasks + * after this, but they will get executed only after calling + * esp_rmaker_work_queue_start(). + * + * @return ESP_OK on success. + * @return error in case of failure. + */ +esp_err_t esp_rmaker_work_queue_init(void); + +/** De-initialize the Work Queue + * + * This de-initializes the work queue. Note that the work queue needs to + * be stopped using esp_rmaker_work_queue_stop() before calling this. + * + * @return ESP_OK on success. + * @return error in case of failure. + */ +esp_err_t esp_rmaker_work_queue_deinit(void); + +/** Start the Work Queue + * + * This starts the Work Queue thread which then starts executing the tasks queued. + * + * @return ESP_OK on success. + * @return error in case of failure. + */ +esp_err_t esp_rmaker_work_queue_start(void); + +/** Stop the Work Queue + * + * This stops a running Work Queue. + * + * @return ESP_OK on success. + * @return error in case of failure. + */ +esp_err_t esp_rmaker_work_queue_stop(void); + +/** Queue execution of a function in the Work Queue's context + * + * This API queues a work function for execution in the Work Queue Task's context. + * + * @param[in] work_fn The Work function to be queued. + * @param[in] priv_data Private data to be passed to the work function. + * + * @return ESP_OK on success. + * @return error in case of failure. + */ +esp_err_t esp_rmaker_work_queue_add_task(esp_rmaker_work_fn_t work_fn, void *priv_data); + +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/esp32/include/sdmmc/include/sdmmc_cmd.h b/tools/sdk/esp32/include/sdmmc/include/sdmmc_cmd.h index e0e7162391b..9b7319641e2 100644 --- a/tools/sdk/esp32/include/sdmmc/include/sdmmc_cmd.h +++ b/tools/sdk/esp32/include/sdmmc/include/sdmmc_cmd.h @@ -224,10 +224,10 @@ esp_err_t sdmmc_io_enable_int(sdmmc_card_t* card); esp_err_t sdmmc_io_wait_int(sdmmc_card_t* card, TickType_t timeout_ticks); /** - * Get the data of CIS region of a SDIO card. + * Get the data of CIS region of an SDIO card. * * You may provide a buffer not sufficient to store all the CIS data. In this - * case, this functions store as much data into your buffer as possible. Also, + * case, this function stores as much data into your buffer as possible. Also, * this function will try to get and return the size required for you. * * @param card pointer to card information structure previously initialized @@ -253,7 +253,7 @@ esp_err_t sdmmc_io_wait_int(sdmmc_card_t* card, TickType_t timeout_ticks); esp_err_t sdmmc_io_get_cis_data(sdmmc_card_t* card, uint8_t* out_buffer, size_t buffer_size, size_t* inout_cis_size); /** - * Parse and print the CIS information of a SDIO card. + * Parse and print the CIS information of an SDIO card. * * @note Not all the CIS codes and all kinds of tuples are supported. If you * see some unresolved code, you can add the parsing of these code in diff --git a/tools/sdk/esp32/include/soc/esp32/include/soc/efuse_reg.h b/tools/sdk/esp32/include/soc/esp32/include/soc/efuse_reg.h index 937585d9ba2..77e3b8db96d 100644 --- a/tools/sdk/esp32/include/soc/esp32/include/soc/efuse_reg.h +++ b/tools/sdk/esp32/include/soc/esp32/include/soc/efuse_reg.h @@ -1,16 +1,8 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #ifndef _SOC_EFUSE_REG_H_ #define _SOC_EFUSE_REG_H_ @@ -116,6 +108,7 @@ #define EFUSE_RD_CHIP_VER_PKG_ESP32U4WDH 4 #define EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4 5 #define EFUSE_RD_CHIP_VER_PKG_ESP32PICOV302 6 +#define EFUSE_RD_CHIP_VER_PKG_ESP32D0WDR2V3 7 /* EFUSE_RD_SPI_PAD_CONFIG_HD : RO ;bitpos:[8:4] ;default: 5'b0 ; */ /*description: read for SPI_pad_config_hd*/ #define EFUSE_RD_SPI_PAD_CONFIG_HD 0x0000001F diff --git a/tools/sdk/esp32/include/soc/esp32/include/soc/periph_defs.h b/tools/sdk/esp32/include/soc/esp32/include/soc/periph_defs.h index d3ba942bde3..d6e7f8cf00b 100644 --- a/tools/sdk/esp32/include/soc/esp32/include/soc/periph_defs.h +++ b/tools/sdk/esp32/include/soc/esp32/include/soc/periph_defs.h @@ -1,16 +1,8 @@ -// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #ifndef _SOC_PERIPH_DEFS_H_ #define _SOC_PERIPH_DEFS_H_ @@ -54,6 +46,7 @@ typedef enum { PERIPH_AES_MODULE, PERIPH_SHA_MODULE, PERIPH_RSA_MODULE, + PERIPH_SARADC_MODULE, PERIPH_MODULE_MAX } periph_module_t; diff --git a/tools/sdk/esp32/include/soc/esp32/include/soc/soc_caps.h b/tools/sdk/esp32/include/soc/esp32/include/soc/soc_caps.h index c31a12d0fe7..3449129ad06 100644 --- a/tools/sdk/esp32/include/soc/esp32/include/soc/soc_caps.h +++ b/tools/sdk/esp32/include/soc/esp32/include/soc/soc_caps.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -52,6 +52,7 @@ /*-------------------------- COMMON CAPS ---------------------------------------*/ #define SOC_CAPS_ECO_VER_MAX 3 +#define SOC_ADC_SUPPORTED 1 #define SOC_DAC_SUPPORTED 1 #define SOC_MCPWM_SUPPORTED 1 #define SOC_SDMMC_HOST_SUPPORTED 1 @@ -69,7 +70,7 @@ /*-------------------------- ADC CAPS ----------------------------------------*/ /** - * TO BE REMOVED in !14278 + * TO BE REMOVED * Check if adc support digital controller (DMA) mode. * @value * - 1 : support; @@ -79,6 +80,7 @@ /*!< SAR ADC Module*/ #define SOC_ADC_RTC_CTRL_SUPPORTED 1 +#define SOC_ADC_DIG_CTRL_SUPPORTED 1 #define SOC_ADC_PERIPH_NUM (2) #define SOC_ADC_CHANNEL_NUM(PERIPH_NUM) ((PERIPH_NUM==0)? 8: 10) #define SOC_ADC_MAX_CHANNEL_NUM (10) @@ -89,8 +91,8 @@ #define SOC_ADC_DIGI_MIN_BITWIDTH (9) #define SOC_ADC_DIGI_MAX_BITWIDTH (12) /*!< F_sample = F_digi_con / 2 / interval. F_digi_con = 5M for now. 30 <= interva <= 4095 */ -#define SOC_ADC_SAMPLE_FREQ_THRES_HIGH 83333 -#define SOC_ADC_SAMPLE_FREQ_THRES_LOW 611 +#define SOC_ADC_SAMPLE_FREQ_THRES_HIGH (2*1000*1000) +#define SOC_ADC_SAMPLE_FREQ_THRES_LOW (2000) /*!< RTC */ #define SOC_ADC_MAX_BITWIDTH (12) @@ -138,18 +140,23 @@ #define SOC_I2C_SUPPORT_APB (1) +/*-------------------------- APLL CAPS ----------------------------------------*/ +#define SOC_CLK_APLL_SUPPORTED (1) +// apll_multiplier_out = xtal_freq * (4 + sdm2 + sdm1/256 + sdm0/65536) +#define SOC_APLL_MULTIPLIER_OUT_MIN_HZ (350000000) // 350 MHz +#define SOC_APLL_MULTIPLIER_OUT_MAX_HZ (500000000) // 500 MHz +#define SOC_APLL_MIN_HZ (5303031) // 5.303031 MHz +#define SOC_APLL_MAX_HZ (125000000) // 125MHz + /*-------------------------- I2S CAPS ----------------------------------------*/ // ESP32 have 2 I2S -#define SOC_I2S_NUM (2) +#define SOC_I2S_NUM (2U) +#define SOC_I2S_SUPPORTS_APLL (1) // ESP32 support APLL #define SOC_I2S_SUPPORTS_PDM_TX (1) #define SOC_I2S_SUPPORTS_PDM_RX (1) #define SOC_I2S_SUPPORTS_ADC (1) // ESP32 support ADC and DAC #define SOC_I2S_SUPPORTS_DAC (1) -#define SOC_I2S_SUPPORTS_APLL (1)// ESP32 support APLL -#define SOC_I2S_APLL_MIN_FREQ (250000000) -#define SOC_I2S_APLL_MAX_FREQ (500000000) -#define SOC_I2S_APLL_MIN_RATE (10675) //in Hz, I2S Clock rate limited by hardware #define SOC_I2S_TRANS_SIZE_ALIGN_WORD (1) // I2S DMA transfer size must be aligned to word #define SOC_I2S_LCD_I80_VARIANT (1) // I2S has a special LCD mode that can generate Intel 8080 TX timing diff --git a/tools/sdk/esp32/include/soc/esp32/include/soc/tracemem_config.h b/tools/sdk/esp32/include/soc/esp32/include/soc/tracemem_config.h new file mode 100644 index 00000000000..4d73ecfe518 --- /dev/null +++ b/tools/sdk/esp32/include/soc/esp32/include/soc/tracemem_config.h @@ -0,0 +1,17 @@ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#define TRACEMEM_BLK0_ADDR 0x3FFFC000UL +#define TRACEMEM_BLK1_ADDR 0x3FFF8000UL + +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/esp32/include/soc/esp32/include/soc/uart_channel.h b/tools/sdk/esp32/include/soc/esp32/include/soc/uart_channel.h index 5b8dc56d5ae..89c6a8956cc 100644 --- a/tools/sdk/esp32/include/soc/esp32/include/soc/uart_channel.h +++ b/tools/sdk/esp32/include/soc/esp32/include/soc/uart_channel.h @@ -1,16 +1,10 @@ -// Copyright 2010-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +// This file defines GPIO lookup macros for available UART IO_MUX pins on ESP32. #ifndef _SOC_UART_CHANNEL_H #define _SOC_UART_CHANNEL_H diff --git a/tools/sdk/esp32/include/spi_flash/include/spi_flash_chip_th.h b/tools/sdk/esp32/include/spi_flash/include/spi_flash_chip_th.h new file mode 100644 index 00000000000..7f631faf136 --- /dev/null +++ b/tools/sdk/esp32/include/spi_flash/include/spi_flash_chip_th.h @@ -0,0 +1,13 @@ +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include "esp_flash.h" +#include "spi_flash_chip_driver.h" + +extern const spi_flash_chip_t esp_flash_chip_th; diff --git a/tools/sdk/esp32/include/wifi_provisioning/include/wifi_provisioning/wifi_config.h b/tools/sdk/esp32/include/wifi_provisioning/include/wifi_provisioning/wifi_config.h index 2fa64448d49..d477580fa99 100644 --- a/tools/sdk/esp32/include/wifi_provisioning/include/wifi_provisioning/wifi_config.h +++ b/tools/sdk/esp32/include/wifi_provisioning/include/wifi_provisioning/wifi_config.h @@ -15,7 +15,7 @@ #ifndef _WIFI_PROV_CONFIG_H_ #define _WIFI_PROV_CONFIG_H_ -#include +#include #ifdef __cplusplus extern "C" { diff --git a/tools/sdk/esp32/include/wpa_supplicant/esp_supplicant/include/esp_wpa2.h b/tools/sdk/esp32/include/wpa_supplicant/esp_supplicant/include/esp_wpa2.h index 9777a424e15..41a6a7d685c 100644 --- a/tools/sdk/esp32/include/wpa_supplicant/esp_supplicant/include/esp_wpa2.h +++ b/tools/sdk/esp32/include/wpa_supplicant/esp_supplicant/include/esp_wpa2.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -17,7 +17,13 @@ typedef enum { ESP_EAP_TTLS_PHASE2_MSCHAP, ESP_EAP_TTLS_PHASE2_PAP, ESP_EAP_TTLS_PHASE2_CHAP -} esp_eap_ttls_phase2_types ; +} esp_eap_ttls_phase2_types; + +typedef struct { + int fast_provisioning; + int fast_max_pac_list_len; + bool fast_pac_format_binary; +} esp_eap_fast_config; #ifdef __cplusplus extern "C" { @@ -211,6 +217,35 @@ esp_err_t esp_wifi_sta_wpa2_ent_set_ttls_phase2_method(esp_eap_ttls_phase2_types */ esp_err_t esp_wifi_sta_wpa2_set_suiteb_192bit_certification(bool enable); +/** + * @brief Set client pac file + * + * @attention 1. For files read from the file system, length has to be decremented by 1 byte. + * @attention 2. Disabling the WPA_MBEDTLS_CRYPTO config is required to use EAP-FAST. + * + * @param pac_file: pointer to the pac file + * pac_file_len: length of the pac file + * + * @return + * - ESP_OK: succeed + * - ESP_ERR_NO_MEM: fail(internal memory malloc fail) + */ +esp_err_t esp_wifi_sta_wpa2_ent_set_pac_file(const unsigned char *pac_file, int pac_file_len); + +/** + * @brief Set Phase 1 parameters for EAP-FAST + * + * @attention 1. Disabling the WPA_MBEDTLS_CRYPTO config is required to use EAP-FAST. + * + * @param config: eap fast phase 1 configuration + * + * @return + * - ESP_OK: succeed + * - ESP_ERR_INVALID_ARG: fail(out of bound arguments) + * - ESP_ERR_NO_MEM: fail(internal memory malloc fail) + */ +esp_err_t esp_wifi_sta_wpa2_ent_set_fast_phase1_params(esp_eap_fast_config config); + #ifdef __cplusplus } #endif diff --git a/tools/sdk/esp32/include/wpa_supplicant/include/utils/wpabuf.h b/tools/sdk/esp32/include/wpa_supplicant/include/utils/wpabuf.h index e9f4ce7b34e..092b31e08ba 100644 --- a/tools/sdk/esp32/include/wpa_supplicant/include/utils/wpabuf.h +++ b/tools/sdk/esp32/include/wpa_supplicant/include/utils/wpabuf.h @@ -1,6 +1,6 @@ /* * Dynamic data buffer - * Copyright (c) 2007-2009, Jouni Malinen + * Copyright (c) 2007-2012, Jouni Malinen * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -15,6 +15,9 @@ #ifndef WPABUF_H #define WPABUF_H +/* wpabuf::buf is a pointer to external data */ +#define WPABUF_FLAG_EXT_DATA BIT(0) + /* * Internal data structure for wpabuf. Please do not touch this directly from * elsewhere. This is only defined in header file to allow inline functions @@ -23,8 +26,8 @@ struct wpabuf { size_t size; /* total size of the allocated buffer */ size_t used; /* length of data in the buffer */ - u8 *ext_data; /* pointer to external data; NULL if data follows - * struct wpabuf */ + u8 *buf; /* pointer to the head of the buffer */ + unsigned int flags; /* optionally followed by the allocated buffer */ }; @@ -35,6 +38,7 @@ struct wpabuf * wpabuf_alloc_ext_data(u8 *data, size_t len); struct wpabuf * wpabuf_alloc_copy(const void *data, size_t len); struct wpabuf * wpabuf_dup(const struct wpabuf *src); void wpabuf_free(struct wpabuf *buf); +void wpabuf_clear_free(struct wpabuf *buf); void * wpabuf_put(struct wpabuf *buf, size_t len); struct wpabuf * wpabuf_concat(struct wpabuf *a, struct wpabuf *b); struct wpabuf * wpabuf_zeropad(struct wpabuf *buf, size_t len); @@ -78,9 +82,7 @@ static inline size_t wpabuf_tailroom(const struct wpabuf *buf) */ static inline const void * wpabuf_head(const struct wpabuf *buf) { - if (buf->ext_data) - return buf->ext_data; - return buf + 1; + return buf->buf; } static inline const u8 * wpabuf_head_u8(const struct wpabuf *buf) @@ -95,9 +97,7 @@ static inline const u8 * wpabuf_head_u8(const struct wpabuf *buf) */ static inline void * wpabuf_mhead(struct wpabuf *buf) { - if (buf->ext_data) - return buf->ext_data; - return buf + 1; + return buf->buf; } static inline u8 * wpabuf_mhead_u8(struct wpabuf *buf) @@ -156,7 +156,8 @@ static inline void wpabuf_put_buf(struct wpabuf *dst, static inline void wpabuf_set(struct wpabuf *buf, const void *data, size_t len) { - buf->ext_data = (u8 *) data; + buf->buf = (u8 *) data; + buf->flags = WPABUF_FLAG_EXT_DATA; buf->size = buf->used = len; } diff --git a/tools/sdk/esp32/include/wpa_supplicant/port/include/os.h b/tools/sdk/esp32/include/wpa_supplicant/port/include/os.h index 74e1e349e91..ce9aa559a44 100644 --- a/tools/sdk/esp32/include/wpa_supplicant/port/include/os.h +++ b/tools/sdk/esp32/include/wpa_supplicant/port/include/os.h @@ -289,6 +289,9 @@ char * ets_strdup(const char *s); #ifndef os_strlcpy #define os_strlcpy(d, s, n) strlcpy((d), (s), (n)) #endif +#ifndef os_strcat +#define os_strcat(d, s) strcat((d), (s)) +#endif #ifndef os_snprintf #ifdef _MSC_VER @@ -297,6 +300,9 @@ char * ets_strdup(const char *s); #define os_snprintf snprintf #endif #endif +#ifndef os_sprintf +#define os_sprintf sprintf +#endif static inline int os_snprintf_error(size_t size, int res) { diff --git a/tools/sdk/esp32/ld/esp32.rom.newlib-funcs.ld b/tools/sdk/esp32/ld/esp32.rom.newlib-funcs.ld index d38e4452749..79d5c5be0d8 100644 --- a/tools/sdk/esp32/ld/esp32.rom.newlib-funcs.ld +++ b/tools/sdk/esp32/ld/esp32.rom.newlib-funcs.ld @@ -43,7 +43,6 @@ _getenv_r = 0x40001fbc; isalnum = 0x40000f04; isalpha = 0x40000f18; isascii = 0x4000c20c; -_isatty_r = 0x40000ea0; isblank = 0x40000f2c; iscntrl = 0x40000f50; isdigit = 0x40000f64; @@ -77,14 +76,11 @@ __sfmoreglue = 0x40001dc8; __sfp = 0x40001e90; __sfp_lock_acquire = 0x40001e08; __sfp_lock_release = 0x40001e14; -__sfvwrite_r = 0x4005893c; __sinit = 0x40001e38; __sinit_lock_acquire = 0x40001e20; __sinit_lock_release = 0x40001e2c; -__smakebuf_r = 0x40059108; srand = 0x40001004; __sread = 0x40001118; -__srefill_r = 0x400593d4; __sseek = 0x40001184; strcasecmp = 0x400011cc; strcasestr = 0x40001210; @@ -122,7 +118,6 @@ __submore = 0x40058f3c; __swbuf = 0x40058cb4; __swbuf_r = 0x40058bec; __swrite = 0x40001150; -__swsetup_r = 0x40058cc8; toascii = 0x4000c720; tolower = 0x40001868; toupper = 0x40001884; diff --git a/tools/sdk/esp32/ld/esp32.rom.newlib-time.ld b/tools/sdk/esp32/ld/esp32.rom.newlib-time.ld index f6b222eb10c..50ec64882d7 100644 --- a/tools/sdk/esp32/ld/esp32.rom.newlib-time.ld +++ b/tools/sdk/esp32/ld/esp32.rom.newlib-time.ld @@ -27,3 +27,12 @@ _timezone = 0x3ffae0a0; _tzname = 0x3ffae030; _daylight = 0x3ffae0a4; __month_lengths = 0x3ff9609c; + +/* These functions don't use time_t, but use other structures which include time_t. + * For example, 'struct stat' contains time_t. + */ +_isatty_r = 0x40000ea0; +__sfvwrite_r = 0x4005893c; +__smakebuf_r = 0x40059108; +__srefill_r = 0x400593d4; +__swsetup_r = 0x40058cc8; diff --git a/tools/sdk/esp32/ld/libbtdm_app.a b/tools/sdk/esp32/ld/libbtdm_app.a index beeef6cd169..a6fb5cf8efa 100644 Binary files a/tools/sdk/esp32/ld/libbtdm_app.a and b/tools/sdk/esp32/ld/libbtdm_app.a differ diff --git a/tools/sdk/esp32/ld/libc_speech_features.a b/tools/sdk/esp32/ld/libc_speech_features.a new file mode 100644 index 00000000000..0baefdea487 Binary files /dev/null and b/tools/sdk/esp32/ld/libc_speech_features.a differ diff --git a/tools/sdk/esp32/ld/libcustomized_word_wn5.a b/tools/sdk/esp32/ld/libcustomized_word_wn5.a new file mode 100644 index 00000000000..7b85a4ff5c2 Binary files /dev/null and b/tools/sdk/esp32/ld/libcustomized_word_wn5.a differ diff --git a/tools/sdk/esp32/ld/libdl_lib.a b/tools/sdk/esp32/ld/libdl_lib.a new file mode 100644 index 00000000000..8da69ad24f8 Binary files /dev/null and b/tools/sdk/esp32/ld/libdl_lib.a differ diff --git a/tools/sdk/esp32/ld/libesp_tts_chinese.a b/tools/sdk/esp32/ld/libesp_tts_chinese.a new file mode 100644 index 00000000000..25dbed6cddf Binary files /dev/null and b/tools/sdk/esp32/ld/libesp_tts_chinese.a differ diff --git a/tools/sdk/esp32/ld/libhilexin_wn5.a b/tools/sdk/esp32/ld/libhilexin_wn5.a new file mode 100644 index 00000000000..1690cdf9f15 Binary files /dev/null and b/tools/sdk/esp32/ld/libhilexin_wn5.a differ diff --git a/tools/sdk/esp32/ld/libhilexin_wn5X2.a b/tools/sdk/esp32/ld/libhilexin_wn5X2.a new file mode 100644 index 00000000000..b2cb3c19045 Binary files /dev/null and b/tools/sdk/esp32/ld/libhilexin_wn5X2.a differ diff --git a/tools/sdk/esp32/ld/libhilexin_wn5X3.a b/tools/sdk/esp32/ld/libhilexin_wn5X3.a new file mode 100644 index 00000000000..fa1f5e7ac45 Binary files /dev/null and b/tools/sdk/esp32/ld/libhilexin_wn5X3.a differ diff --git a/tools/sdk/esp32/ld/libmultinet2_ch.a b/tools/sdk/esp32/ld/libmultinet2_ch.a new file mode 100644 index 00000000000..70664fca4b2 Binary files /dev/null and b/tools/sdk/esp32/ld/libmultinet2_ch.a differ diff --git a/tools/sdk/esp32/ld/libnihaoxiaoxin_wn5X3.a b/tools/sdk/esp32/ld/libnihaoxiaoxin_wn5X3.a new file mode 100644 index 00000000000..1ab173b7027 Binary files /dev/null and b/tools/sdk/esp32/ld/libnihaoxiaoxin_wn5X3.a differ diff --git a/tools/sdk/esp32/ld/libnihaoxiaozhi_wn5.a b/tools/sdk/esp32/ld/libnihaoxiaozhi_wn5.a new file mode 100644 index 00000000000..0e207efcbed Binary files /dev/null and b/tools/sdk/esp32/ld/libnihaoxiaozhi_wn5.a differ diff --git a/tools/sdk/esp32/ld/libnihaoxiaozhi_wn5X2.a b/tools/sdk/esp32/ld/libnihaoxiaozhi_wn5X2.a new file mode 100644 index 00000000000..e6edeb86d45 Binary files /dev/null and b/tools/sdk/esp32/ld/libnihaoxiaozhi_wn5X2.a differ diff --git a/tools/sdk/esp32/ld/libnihaoxiaozhi_wn5X3.a b/tools/sdk/esp32/ld/libnihaoxiaozhi_wn5X3.a new file mode 100644 index 00000000000..fe28e3ef0f7 Binary files /dev/null and b/tools/sdk/esp32/ld/libnihaoxiaozhi_wn5X3.a differ diff --git a/tools/sdk/esp32/ld/libvoice_set_xiaole.a b/tools/sdk/esp32/ld/libvoice_set_xiaole.a new file mode 100644 index 00000000000..f0b6820f301 Binary files /dev/null and b/tools/sdk/esp32/ld/libvoice_set_xiaole.a differ diff --git a/tools/sdk/esp32/lib/libapp_trace.a b/tools/sdk/esp32/lib/libapp_trace.a index 148e16886d3..abd17b9291f 100644 Binary files a/tools/sdk/esp32/lib/libapp_trace.a and b/tools/sdk/esp32/lib/libapp_trace.a differ diff --git a/tools/sdk/esp32/lib/libapp_update.a b/tools/sdk/esp32/lib/libapp_update.a index 34b6f44ca46..4b1b7b9e363 100644 Binary files a/tools/sdk/esp32/lib/libapp_update.a and b/tools/sdk/esp32/lib/libapp_update.a differ diff --git a/tools/sdk/esp32/lib/libasio.a b/tools/sdk/esp32/lib/libasio.a index 62911b4fa6e..1603aa3967e 100644 Binary files a/tools/sdk/esp32/lib/libasio.a and b/tools/sdk/esp32/lib/libasio.a differ diff --git a/tools/sdk/esp32/lib/libbt.a b/tools/sdk/esp32/lib/libbt.a index 7f819f94986..4eff2c2bd19 100644 Binary files a/tools/sdk/esp32/lib/libbt.a and b/tools/sdk/esp32/lib/libbt.a differ diff --git a/tools/sdk/esp32/lib/libbutton.a b/tools/sdk/esp32/lib/libbutton.a index 9c64e6bcda2..c9fb2ffb706 100644 Binary files a/tools/sdk/esp32/lib/libbutton.a and b/tools/sdk/esp32/lib/libbutton.a differ diff --git a/tools/sdk/esp32/lib/libcbor.a b/tools/sdk/esp32/lib/libcbor.a index f6ab7028412..b1a9682fe33 100644 Binary files a/tools/sdk/esp32/lib/libcbor.a and b/tools/sdk/esp32/lib/libcbor.a differ diff --git a/tools/sdk/esp32/lib/libcmock.a b/tools/sdk/esp32/lib/libcmock.a index 9056158fe87..7fccbc289ea 100644 Binary files a/tools/sdk/esp32/lib/libcmock.a and b/tools/sdk/esp32/lib/libcmock.a differ diff --git a/tools/sdk/esp32/lib/libcoap.a b/tools/sdk/esp32/lib/libcoap.a index 577c42f675b..1330960bbf9 100644 Binary files a/tools/sdk/esp32/lib/libcoap.a and b/tools/sdk/esp32/lib/libcoap.a differ diff --git a/tools/sdk/esp32/lib/libcoexist.a b/tools/sdk/esp32/lib/libcoexist.a index e264552b613..3e3e029cbc8 100644 Binary files a/tools/sdk/esp32/lib/libcoexist.a and b/tools/sdk/esp32/lib/libcoexist.a differ diff --git a/tools/sdk/esp32/lib/libconsole.a b/tools/sdk/esp32/lib/libconsole.a index 371e864a255..92ebbac3e67 100644 Binary files a/tools/sdk/esp32/lib/libconsole.a and b/tools/sdk/esp32/lib/libconsole.a differ diff --git a/tools/sdk/esp32/lib/libcore.a b/tools/sdk/esp32/lib/libcore.a index ff041c7699d..038e087266a 100644 Binary files a/tools/sdk/esp32/lib/libcore.a and b/tools/sdk/esp32/lib/libcore.a differ diff --git a/tools/sdk/esp32/lib/libcxx.a b/tools/sdk/esp32/lib/libcxx.a index cea577ffba2..d1b2a5e62bb 100644 Binary files a/tools/sdk/esp32/lib/libcxx.a and b/tools/sdk/esp32/lib/libcxx.a differ diff --git a/tools/sdk/esp32/lib/libdriver.a b/tools/sdk/esp32/lib/libdriver.a index e042cb61eb3..c2bd55c69e4 100644 Binary files a/tools/sdk/esp32/lib/libdriver.a and b/tools/sdk/esp32/lib/libdriver.a differ diff --git a/tools/sdk/esp32/lib/libefuse.a b/tools/sdk/esp32/lib/libefuse.a index cc38c1b835d..8136e5ec540 100644 Binary files a/tools/sdk/esp32/lib/libefuse.a and b/tools/sdk/esp32/lib/libefuse.a differ diff --git a/tools/sdk/esp32/lib/libesp-dsp.a b/tools/sdk/esp32/lib/libesp-dsp.a index cb57f58e990..2e50bbc24b1 100644 Binary files a/tools/sdk/esp32/lib/libesp-dsp.a and b/tools/sdk/esp32/lib/libesp-dsp.a differ diff --git a/tools/sdk/esp32/lib/libesp-sr.a b/tools/sdk/esp32/lib/libesp-sr.a new file mode 100644 index 00000000000..c230d3ef625 Binary files /dev/null and b/tools/sdk/esp32/lib/libesp-sr.a differ diff --git a/tools/sdk/esp32/lib/libesp-tls.a b/tools/sdk/esp32/lib/libesp-tls.a index 47011e74b98..902dd451408 100644 Binary files a/tools/sdk/esp32/lib/libesp-tls.a and b/tools/sdk/esp32/lib/libesp-tls.a differ diff --git a/tools/sdk/esp32/lib/libesp32-camera.a b/tools/sdk/esp32/lib/libesp32-camera.a index 186ff1de743..d55d7b54fa1 100644 Binary files a/tools/sdk/esp32/lib/libesp32-camera.a and b/tools/sdk/esp32/lib/libesp32-camera.a differ diff --git a/tools/sdk/esp32/lib/libesp_adc_cal.a b/tools/sdk/esp32/lib/libesp_adc_cal.a index 216029001ed..6838732cc19 100644 Binary files a/tools/sdk/esp32/lib/libesp_adc_cal.a and b/tools/sdk/esp32/lib/libesp_adc_cal.a differ diff --git a/tools/sdk/esp32/lib/libesp_audio_front_end.a b/tools/sdk/esp32/lib/libesp_audio_front_end.a new file mode 100644 index 00000000000..8e68bed696b Binary files /dev/null and b/tools/sdk/esp32/lib/libesp_audio_front_end.a differ diff --git a/tools/sdk/esp32/lib/libesp_audio_processor.a b/tools/sdk/esp32/lib/libesp_audio_processor.a new file mode 100644 index 00000000000..df49110effe Binary files /dev/null and b/tools/sdk/esp32/lib/libesp_audio_processor.a differ diff --git a/tools/sdk/esp32/lib/libesp_common.a b/tools/sdk/esp32/lib/libesp_common.a index bf9014aa2ff..57fc66bf2e3 100644 Binary files a/tools/sdk/esp32/lib/libesp_common.a and b/tools/sdk/esp32/lib/libesp_common.a differ diff --git a/tools/sdk/esp32/lib/libesp_eth.a b/tools/sdk/esp32/lib/libesp_eth.a index 73e5ab542d8..c6e24073a6c 100644 Binary files a/tools/sdk/esp32/lib/libesp_eth.a and b/tools/sdk/esp32/lib/libesp_eth.a differ diff --git a/tools/sdk/esp32/lib/libesp_event.a b/tools/sdk/esp32/lib/libesp_event.a index 6887ef71156..d85b1c2a580 100644 Binary files a/tools/sdk/esp32/lib/libesp_event.a and b/tools/sdk/esp32/lib/libesp_event.a differ diff --git a/tools/sdk/esp32/lib/libesp_gdbstub.a b/tools/sdk/esp32/lib/libesp_gdbstub.a index fc5f2e85a8b..5d4175d8a58 100644 Binary files a/tools/sdk/esp32/lib/libesp_gdbstub.a and b/tools/sdk/esp32/lib/libesp_gdbstub.a differ diff --git a/tools/sdk/esp32/lib/libesp_hid.a b/tools/sdk/esp32/lib/libesp_hid.a index 43a36ad8280..44876050176 100644 Binary files a/tools/sdk/esp32/lib/libesp_hid.a and b/tools/sdk/esp32/lib/libesp_hid.a differ diff --git a/tools/sdk/esp32/lib/libesp_http_client.a b/tools/sdk/esp32/lib/libesp_http_client.a index 85d98c486d1..5c2d6e72859 100644 Binary files a/tools/sdk/esp32/lib/libesp_http_client.a and b/tools/sdk/esp32/lib/libesp_http_client.a differ diff --git a/tools/sdk/esp32/lib/libesp_http_server.a b/tools/sdk/esp32/lib/libesp_http_server.a index e004e4f4ad2..e3f6351f275 100644 Binary files a/tools/sdk/esp32/lib/libesp_http_server.a and b/tools/sdk/esp32/lib/libesp_http_server.a differ diff --git a/tools/sdk/esp32/lib/libesp_https_ota.a b/tools/sdk/esp32/lib/libesp_https_ota.a index 91c7a1edcd8..bc0958f3ad8 100644 Binary files a/tools/sdk/esp32/lib/libesp_https_ota.a and b/tools/sdk/esp32/lib/libesp_https_ota.a differ diff --git a/tools/sdk/esp32/lib/libesp_ipc.a b/tools/sdk/esp32/lib/libesp_ipc.a index ced6b39cf53..00d0e795d2d 100644 Binary files a/tools/sdk/esp32/lib/libesp_ipc.a and b/tools/sdk/esp32/lib/libesp_ipc.a differ diff --git a/tools/sdk/esp32/lib/libesp_lcd.a b/tools/sdk/esp32/lib/libesp_lcd.a index 5e7ade52bf6..e973a8906df 100644 Binary files a/tools/sdk/esp32/lib/libesp_lcd.a and b/tools/sdk/esp32/lib/libesp_lcd.a differ diff --git a/tools/sdk/esp32/lib/libesp_littlefs.a b/tools/sdk/esp32/lib/libesp_littlefs.a index b28436b2548..190c285ef04 100644 Binary files a/tools/sdk/esp32/lib/libesp_littlefs.a and b/tools/sdk/esp32/lib/libesp_littlefs.a differ diff --git a/tools/sdk/esp32/lib/libesp_local_ctrl.a b/tools/sdk/esp32/lib/libesp_local_ctrl.a index 81eddfa489a..cd86a7fad6b 100644 Binary files a/tools/sdk/esp32/lib/libesp_local_ctrl.a and b/tools/sdk/esp32/lib/libesp_local_ctrl.a differ diff --git a/tools/sdk/esp32/lib/libesp_netif.a b/tools/sdk/esp32/lib/libesp_netif.a index 22dda939c2a..02d72af1edb 100644 Binary files a/tools/sdk/esp32/lib/libesp_netif.a and b/tools/sdk/esp32/lib/libesp_netif.a differ diff --git a/tools/sdk/esp32/lib/libesp_phy.a b/tools/sdk/esp32/lib/libesp_phy.a index 438d0c001d2..923c01151a0 100644 Binary files a/tools/sdk/esp32/lib/libesp_phy.a and b/tools/sdk/esp32/lib/libesp_phy.a differ diff --git a/tools/sdk/esp32/lib/libesp_pm.a b/tools/sdk/esp32/lib/libesp_pm.a index 411672cd44b..92a34a2ffd8 100644 Binary files a/tools/sdk/esp32/lib/libesp_pm.a and b/tools/sdk/esp32/lib/libesp_pm.a differ diff --git a/tools/sdk/esp32/lib/libesp_rainmaker.a b/tools/sdk/esp32/lib/libesp_rainmaker.a index 73f1c801fe7..ca00c2c7494 100644 Binary files a/tools/sdk/esp32/lib/libesp_rainmaker.a and b/tools/sdk/esp32/lib/libesp_rainmaker.a differ diff --git a/tools/sdk/esp32/lib/libesp_ringbuf.a b/tools/sdk/esp32/lib/libesp_ringbuf.a index 7d52bcc2570..42663cd7224 100644 Binary files a/tools/sdk/esp32/lib/libesp_ringbuf.a and b/tools/sdk/esp32/lib/libesp_ringbuf.a differ diff --git a/tools/sdk/esp32/lib/libesp_rom.a b/tools/sdk/esp32/lib/libesp_rom.a index a8ed7b9fbe5..d1a6ca27347 100644 Binary files a/tools/sdk/esp32/lib/libesp_rom.a and b/tools/sdk/esp32/lib/libesp_rom.a differ diff --git a/tools/sdk/esp32/lib/libesp_schedule.a b/tools/sdk/esp32/lib/libesp_schedule.a index c198386bcc0..83f1e3867bb 100644 Binary files a/tools/sdk/esp32/lib/libesp_schedule.a and b/tools/sdk/esp32/lib/libesp_schedule.a differ diff --git a/tools/sdk/esp32/lib/libesp_serial_slave_link.a b/tools/sdk/esp32/lib/libesp_serial_slave_link.a index 082a41ac404..3a37d13ba33 100644 Binary files a/tools/sdk/esp32/lib/libesp_serial_slave_link.a and b/tools/sdk/esp32/lib/libesp_serial_slave_link.a differ diff --git a/tools/sdk/esp32/lib/libesp_timer.a b/tools/sdk/esp32/lib/libesp_timer.a index 8182f0920b6..f85ebcda896 100644 Binary files a/tools/sdk/esp32/lib/libesp_timer.a and b/tools/sdk/esp32/lib/libesp_timer.a differ diff --git a/tools/sdk/esp32/lib/libesp_websocket_client.a b/tools/sdk/esp32/lib/libesp_websocket_client.a index 7b9c9295e86..e3251c5f5ca 100644 Binary files a/tools/sdk/esp32/lib/libesp_websocket_client.a and b/tools/sdk/esp32/lib/libesp_websocket_client.a differ diff --git a/tools/sdk/esp32/lib/libesp_wifi.a b/tools/sdk/esp32/lib/libesp_wifi.a index d1175bbaa61..ea46fd8a633 100644 Binary files a/tools/sdk/esp32/lib/libesp_wifi.a and b/tools/sdk/esp32/lib/libesp_wifi.a differ diff --git a/tools/sdk/esp32/lib/libespcoredump.a b/tools/sdk/esp32/lib/libespcoredump.a index 8e6bff5b97e..accf25d510f 100644 Binary files a/tools/sdk/esp32/lib/libespcoredump.a and b/tools/sdk/esp32/lib/libespcoredump.a differ diff --git a/tools/sdk/esp32/lib/libespnow.a b/tools/sdk/esp32/lib/libespnow.a index 6b059b57334..a2dae078755 100644 Binary files a/tools/sdk/esp32/lib/libespnow.a and b/tools/sdk/esp32/lib/libespnow.a differ diff --git a/tools/sdk/esp32/lib/libexpat.a b/tools/sdk/esp32/lib/libexpat.a index 9ab783bcec8..b2346d7c552 100644 Binary files a/tools/sdk/esp32/lib/libexpat.a and b/tools/sdk/esp32/lib/libexpat.a differ diff --git a/tools/sdk/esp32/lib/libfatfs.a b/tools/sdk/esp32/lib/libfatfs.a index a3d4d23e72c..cd92d593e63 100644 Binary files a/tools/sdk/esp32/lib/libfatfs.a and b/tools/sdk/esp32/lib/libfatfs.a differ diff --git a/tools/sdk/esp32/lib/libfb_gfx.a b/tools/sdk/esp32/lib/libfb_gfx.a index b7a6dcd6d62..0ca0df1fd47 100644 Binary files a/tools/sdk/esp32/lib/libfb_gfx.a and b/tools/sdk/esp32/lib/libfb_gfx.a differ diff --git a/tools/sdk/esp32/lib/libfreemodbus.a b/tools/sdk/esp32/lib/libfreemodbus.a index 6179afed0b4..e480acfa590 100644 Binary files a/tools/sdk/esp32/lib/libfreemodbus.a and b/tools/sdk/esp32/lib/libfreemodbus.a differ diff --git a/tools/sdk/esp32/lib/libhal.a b/tools/sdk/esp32/lib/libhal.a index 29c32dc7249..7f088db16a6 100644 Binary files a/tools/sdk/esp32/lib/libhal.a and b/tools/sdk/esp32/lib/libhal.a differ diff --git a/tools/sdk/esp32/lib/libheap.a b/tools/sdk/esp32/lib/libheap.a index cfe17cb2c24..1a1e90ec7da 100644 Binary files a/tools/sdk/esp32/lib/libheap.a and b/tools/sdk/esp32/lib/libheap.a differ diff --git a/tools/sdk/esp32/lib/libjsmn.a b/tools/sdk/esp32/lib/libjsmn.a index 32b560d553c..4506867adc6 100644 Binary files a/tools/sdk/esp32/lib/libjsmn.a and b/tools/sdk/esp32/lib/libjsmn.a differ diff --git a/tools/sdk/esp32/lib/libjson.a b/tools/sdk/esp32/lib/libjson.a index fbc79a6be18..7b75216a832 100644 Binary files a/tools/sdk/esp32/lib/libjson.a and b/tools/sdk/esp32/lib/libjson.a differ diff --git a/tools/sdk/esp32/lib/libjson_generator.a b/tools/sdk/esp32/lib/libjson_generator.a index 59ff0d4d1b9..525a9d303aa 100644 Binary files a/tools/sdk/esp32/lib/libjson_generator.a and b/tools/sdk/esp32/lib/libjson_generator.a differ diff --git a/tools/sdk/esp32/lib/libjson_parser.a b/tools/sdk/esp32/lib/libjson_parser.a index c8f5b54fa33..427b58ae3b9 100644 Binary files a/tools/sdk/esp32/lib/libjson_parser.a and b/tools/sdk/esp32/lib/libjson_parser.a differ diff --git a/tools/sdk/esp32/lib/liblibsodium.a b/tools/sdk/esp32/lib/liblibsodium.a index a34fa2f3562..b29f8159109 100644 Binary files a/tools/sdk/esp32/lib/liblibsodium.a and b/tools/sdk/esp32/lib/liblibsodium.a differ diff --git a/tools/sdk/esp32/lib/liblog.a b/tools/sdk/esp32/lib/liblog.a index 88fdc988177..bcf9a694808 100644 Binary files a/tools/sdk/esp32/lib/liblog.a and b/tools/sdk/esp32/lib/liblog.a differ diff --git a/tools/sdk/esp32/lib/liblwip.a b/tools/sdk/esp32/lib/liblwip.a index 75d915bb0f1..a352377a6c6 100644 Binary files a/tools/sdk/esp32/lib/liblwip.a and b/tools/sdk/esp32/lib/liblwip.a differ diff --git a/tools/sdk/esp32/lib/libmbedcrypto.a b/tools/sdk/esp32/lib/libmbedcrypto.a index eb815d40b37..c3d7c30e8c3 100644 Binary files a/tools/sdk/esp32/lib/libmbedcrypto.a and b/tools/sdk/esp32/lib/libmbedcrypto.a differ diff --git a/tools/sdk/esp32/lib/libmbedtls.a b/tools/sdk/esp32/lib/libmbedtls.a index 74aa87048e4..82a82e78e98 100644 Binary files a/tools/sdk/esp32/lib/libmbedtls.a and b/tools/sdk/esp32/lib/libmbedtls.a differ diff --git a/tools/sdk/esp32/lib/libmbedx509.a b/tools/sdk/esp32/lib/libmbedx509.a index 5fc1eb32e08..db4b2f075dc 100644 Binary files a/tools/sdk/esp32/lib/libmbedx509.a and b/tools/sdk/esp32/lib/libmbedx509.a differ diff --git a/tools/sdk/esp32/lib/libmdns.a b/tools/sdk/esp32/lib/libmdns.a index 3da44bdf276..b4c49baa487 100644 Binary files a/tools/sdk/esp32/lib/libmdns.a and b/tools/sdk/esp32/lib/libmdns.a differ diff --git a/tools/sdk/esp32/lib/libmesh.a b/tools/sdk/esp32/lib/libmesh.a index 6316c346889..60b26264993 100644 Binary files a/tools/sdk/esp32/lib/libmesh.a and b/tools/sdk/esp32/lib/libmesh.a differ diff --git a/tools/sdk/esp32/lib/libmqtt.a b/tools/sdk/esp32/lib/libmqtt.a index 003a9f65a1f..affca595e22 100644 Binary files a/tools/sdk/esp32/lib/libmqtt.a and b/tools/sdk/esp32/lib/libmqtt.a differ diff --git a/tools/sdk/esp32/lib/libmultinet.a b/tools/sdk/esp32/lib/libmultinet.a new file mode 100644 index 00000000000..b67af4dcaaf Binary files /dev/null and b/tools/sdk/esp32/lib/libmultinet.a differ diff --git a/tools/sdk/esp32/lib/libnet80211.a b/tools/sdk/esp32/lib/libnet80211.a index a3720ee9f58..1836c1c1cf2 100644 Binary files a/tools/sdk/esp32/lib/libnet80211.a and b/tools/sdk/esp32/lib/libnet80211.a differ diff --git a/tools/sdk/esp32/lib/libnewlib.a b/tools/sdk/esp32/lib/libnewlib.a index 9b8f2a12373..b57267ac637 100644 Binary files a/tools/sdk/esp32/lib/libnewlib.a and b/tools/sdk/esp32/lib/libnewlib.a differ diff --git a/tools/sdk/esp32/lib/libnghttp.a b/tools/sdk/esp32/lib/libnghttp.a index fd7dc5de016..3574597b695 100644 Binary files a/tools/sdk/esp32/lib/libnghttp.a and b/tools/sdk/esp32/lib/libnghttp.a differ diff --git a/tools/sdk/esp32/lib/libnvs_flash.a b/tools/sdk/esp32/lib/libnvs_flash.a index e22d19d9093..a78cb9b128a 100644 Binary files a/tools/sdk/esp32/lib/libnvs_flash.a and b/tools/sdk/esp32/lib/libnvs_flash.a differ diff --git a/tools/sdk/esp32/lib/libopenssl.a b/tools/sdk/esp32/lib/libopenssl.a index 33c365e6c4c..5c668bac5ce 100644 Binary files a/tools/sdk/esp32/lib/libopenssl.a and b/tools/sdk/esp32/lib/libopenssl.a differ diff --git a/tools/sdk/esp32/lib/libperfmon.a b/tools/sdk/esp32/lib/libperfmon.a index 0eefff1489a..421acef9eda 100644 Binary files a/tools/sdk/esp32/lib/libperfmon.a and b/tools/sdk/esp32/lib/libperfmon.a differ diff --git a/tools/sdk/esp32/lib/libpp.a b/tools/sdk/esp32/lib/libpp.a index 56c3c8a99a9..104d285c59b 100644 Binary files a/tools/sdk/esp32/lib/libpp.a and b/tools/sdk/esp32/lib/libpp.a differ diff --git a/tools/sdk/esp32/lib/libprotobuf-c.a b/tools/sdk/esp32/lib/libprotobuf-c.a index bbee5a1afd0..5da5b451942 100644 Binary files a/tools/sdk/esp32/lib/libprotobuf-c.a and b/tools/sdk/esp32/lib/libprotobuf-c.a differ diff --git a/tools/sdk/esp32/lib/libprotocomm.a b/tools/sdk/esp32/lib/libprotocomm.a index 58c3bc21e83..ce7161d0ce0 100644 Binary files a/tools/sdk/esp32/lib/libprotocomm.a and b/tools/sdk/esp32/lib/libprotocomm.a differ diff --git a/tools/sdk/esp32/lib/libpthread.a b/tools/sdk/esp32/lib/libpthread.a index 6b0507564d5..48c335c8cb4 100644 Binary files a/tools/sdk/esp32/lib/libpthread.a and b/tools/sdk/esp32/lib/libpthread.a differ diff --git a/tools/sdk/esp32/lib/libqrcode.a b/tools/sdk/esp32/lib/libqrcode.a index b0277b77fc7..7f77e49e251 100644 Binary files a/tools/sdk/esp32/lib/libqrcode.a and b/tools/sdk/esp32/lib/libqrcode.a differ diff --git a/tools/sdk/esp32/lib/librmaker_common.a b/tools/sdk/esp32/lib/librmaker_common.a new file mode 100644 index 00000000000..adde4b98017 Binary files /dev/null and b/tools/sdk/esp32/lib/librmaker_common.a differ diff --git a/tools/sdk/esp32/lib/libsdmmc.a b/tools/sdk/esp32/lib/libsdmmc.a index d15d743f3fe..81ca86dfb22 100644 Binary files a/tools/sdk/esp32/lib/libsdmmc.a and b/tools/sdk/esp32/lib/libsdmmc.a differ diff --git a/tools/sdk/esp32/lib/libsmartconfig.a b/tools/sdk/esp32/lib/libsmartconfig.a index 3fa3d0b2119..5af51c0d9e4 100644 Binary files a/tools/sdk/esp32/lib/libsmartconfig.a and b/tools/sdk/esp32/lib/libsmartconfig.a differ diff --git a/tools/sdk/esp32/lib/libsoc.a b/tools/sdk/esp32/lib/libsoc.a index 05ed5a5c4dc..fd34b4864bb 100644 Binary files a/tools/sdk/esp32/lib/libsoc.a and b/tools/sdk/esp32/lib/libsoc.a differ diff --git a/tools/sdk/esp32/lib/libspiffs.a b/tools/sdk/esp32/lib/libspiffs.a index cdcfe9ef7d7..fcf7ef8dd63 100644 Binary files a/tools/sdk/esp32/lib/libspiffs.a and b/tools/sdk/esp32/lib/libspiffs.a differ diff --git a/tools/sdk/esp32/lib/libtcp_transport.a b/tools/sdk/esp32/lib/libtcp_transport.a index c194e2ab0c8..ff1e7edc18c 100644 Binary files a/tools/sdk/esp32/lib/libtcp_transport.a and b/tools/sdk/esp32/lib/libtcp_transport.a differ diff --git a/tools/sdk/esp32/lib/libtcpip_adapter.a b/tools/sdk/esp32/lib/libtcpip_adapter.a index 4dc14d4b148..d9c5462b8b4 100644 Binary files a/tools/sdk/esp32/lib/libtcpip_adapter.a and b/tools/sdk/esp32/lib/libtcpip_adapter.a differ diff --git a/tools/sdk/esp32/lib/libulp.a b/tools/sdk/esp32/lib/libulp.a index 420dfd9d1de..849b61507af 100644 Binary files a/tools/sdk/esp32/lib/libulp.a and b/tools/sdk/esp32/lib/libulp.a differ diff --git a/tools/sdk/esp32/lib/libunity.a b/tools/sdk/esp32/lib/libunity.a index 74214ab7b1b..4deec80ec8f 100644 Binary files a/tools/sdk/esp32/lib/libunity.a and b/tools/sdk/esp32/lib/libunity.a differ diff --git a/tools/sdk/esp32/lib/libvfs.a b/tools/sdk/esp32/lib/libvfs.a index b45487e710d..b56b8f254e4 100644 Binary files a/tools/sdk/esp32/lib/libvfs.a and b/tools/sdk/esp32/lib/libvfs.a differ diff --git a/tools/sdk/esp32/lib/libwakenet.a b/tools/sdk/esp32/lib/libwakenet.a new file mode 100644 index 00000000000..674fe6f9ef2 Binary files /dev/null and b/tools/sdk/esp32/lib/libwakenet.a differ diff --git a/tools/sdk/esp32/lib/libwapi.a b/tools/sdk/esp32/lib/libwapi.a index 88f106bf99c..874379e03d6 100644 Binary files a/tools/sdk/esp32/lib/libwapi.a and b/tools/sdk/esp32/lib/libwapi.a differ diff --git a/tools/sdk/esp32/lib/libwear_levelling.a b/tools/sdk/esp32/lib/libwear_levelling.a index d298fc3052b..552923fff38 100644 Binary files a/tools/sdk/esp32/lib/libwear_levelling.a and b/tools/sdk/esp32/lib/libwear_levelling.a differ diff --git a/tools/sdk/esp32/lib/libwifi_provisioning.a b/tools/sdk/esp32/lib/libwifi_provisioning.a index 4dde5382266..0bd3f70e81e 100644 Binary files a/tools/sdk/esp32/lib/libwifi_provisioning.a and b/tools/sdk/esp32/lib/libwifi_provisioning.a differ diff --git a/tools/sdk/esp32/lib/libwpa_supplicant.a b/tools/sdk/esp32/lib/libwpa_supplicant.a index 364019779c4..151687144fb 100644 Binary files a/tools/sdk/esp32/lib/libwpa_supplicant.a and b/tools/sdk/esp32/lib/libwpa_supplicant.a differ diff --git a/tools/sdk/esp32/lib/libws2812_led.a b/tools/sdk/esp32/lib/libws2812_led.a index c6b51b381dc..7a0f5ce31ff 100644 Binary files a/tools/sdk/esp32/lib/libws2812_led.a and b/tools/sdk/esp32/lib/libws2812_led.a differ diff --git a/tools/sdk/esp32/lib/libxtensa.a b/tools/sdk/esp32/lib/libxtensa.a index e632b5d01c1..31561f17b00 100644 Binary files a/tools/sdk/esp32/lib/libxtensa.a and b/tools/sdk/esp32/lib/libxtensa.a differ diff --git a/tools/sdk/esp32/include/config/sdkconfig.h b/tools/sdk/esp32/qspi_qspi/include/sdkconfig.h similarity index 96% rename from tools/sdk/esp32/include/config/sdkconfig.h rename to tools/sdk/esp32/qspi_qspi/include/sdkconfig.h index fa51634dabd..4e41e975c26 100644 --- a/tools/sdk/esp32/include/config/sdkconfig.h +++ b/tools/sdk/esp32/qspi_qspi/include/sdkconfig.h @@ -45,22 +45,19 @@ #define CONFIG_PARTITION_TABLE_FILENAME "partitions_singleapp.csv" #define CONFIG_PARTITION_TABLE_OFFSET 0x8000 #define CONFIG_PARTITION_TABLE_MD5 1 +#define CONFIG_LIB_BUILDER_FLASHMODE "dio" +#define CONFIG_LIB_BUILDER_FLASHFREQ "40m" #define CONFIG_ESP_RMAKER_ASSISTED_CLAIM 1 +#define CONFIG_ESP_RMAKER_CLAIM_TYPE 2 #define CONFIG_ESP_RMAKER_MQTT_HOST "a1p72mufdu6064-ats.iot.us-east-1.amazonaws.com" -#define CONFIG_ESP_RMAKER_TASK_STACK 4096 -#define CONFIG_ESP_RMAKER_TASK_PRIORITY 5 -#define CONFIG_ESP_RMAKER_MAX_NODE_CONFIG_SIZE 2048 #define CONFIG_ESP_RMAKER_MAX_PARAM_DATA_SIZE 1024 -#define CONFIG_ESP_RMAKER_FACTORY_PARTITION_NAME "fctry" -#define CONFIG_ESP_RMAKER_MQTT_PORT_443 1 -#define CONFIG_ESP_RMAKER_MQTT_PORT 1 -#define CONFIG_ESP_RMAKER_DEF_TIMEZONE "" -#define CONFIG_ESP_RMAKER_SNTP_SERVER_NAME "pool.ntp.org" #define CONFIG_ESP_RMAKER_CONSOLE_UART_NUM_0 1 #define CONFIG_ESP_RMAKER_CONSOLE_UART_NUM 0 #define CONFIG_ESP_RMAKER_OTA_AUTOFETCH 1 #define CONFIG_ESP_RMAKER_OTA_AUTOFETCH_PERIOD 0 -#define CONFIG_ESP_RMAKER_SCHEDULING_MAX_SCHEDULES 5 +#define CONFIG_ESP_RMAKER_OTA_HTTP_RX_BUFFER_SIZE 1024 +#define CONFIG_ESP_RMAKER_SCHEDULING_MAX_SCHEDULES 10 +#define CONFIG_ESP_RMAKER_SCENES_MAX_SCENES 10 #define CONFIG_ENABLE_ARDUINO_DEPENDS 1 #define CONFIG_AUTOSTART_ARDUINO 1 #define CONFIG_ARDUINO_RUN_CORE1 1 @@ -68,9 +65,9 @@ #define CONFIG_ARDUINO_LOOP_STACK_SIZE 8192 #define CONFIG_ARDUINO_EVENT_RUN_CORE1 1 #define CONFIG_ARDUINO_EVENT_RUNNING_CORE 1 -#define CONFIG_ARDUINO_UDP_RUN_CORE1 1 +#define CONFIG_ARDUINO_UDP_RUN_CORE0 1 #define CONFIG_ARDUINO_UDP_TASK_PRIORITY 3 -#define CONFIG_ARDUINO_UDP_RUNNING_CORE 1 +#define CONFIG_ARDUINO_UDP_RUNNING_CORE 0 #define CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_ERROR 1 #define CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL 1 #define CONFIG_ARDUHAL_ESP_LOG 1 @@ -170,7 +167,6 @@ #define CONFIG_SPIRAM 1 #define CONFIG_SPIRAM_USE_MALLOC 1 #define CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL 4096 -#define CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP 1 #define CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL 0 #define CONFIG_SPIRAM_CACHE_WORKAROUND 1 #define CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_MEMW 1 @@ -227,7 +223,7 @@ #define CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR 1 #define CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS 1 #define CONFIG_ESP_HTTP_CLIENT_ENABLE_DIGEST_AUTH 1 -#define CONFIG_HTTPD_MAX_REQ_HDR_LEN 512 +#define CONFIG_HTTPD_MAX_REQ_HDR_LEN 1024 #define CONFIG_HTTPD_MAX_URI_LEN 512 #define CONFIG_HTTPD_ERR_RESP_NO_DELAY 1 #define CONFIG_HTTPD_PURGE_BUF_LEN 32 @@ -353,7 +349,6 @@ #define CONFIG_HAL_DEFAULT_ASSERTION_LEVEL 2 #define CONFIG_HEAP_POISONING_LIGHT 1 #define CONFIG_HEAP_TRACING_OFF 1 -#define CONFIG_LIBSODIUM_USE_MBEDTLS_SHA 1 #define CONFIG_LOG_DEFAULT_LEVEL_ERROR 1 #define CONFIG_LOG_DEFAULT_LEVEL 1 #define CONFIG_LOG_MAXIMUM_EQUALS_DEFAULT 1 @@ -417,10 +412,12 @@ #define CONFIG_LWIP_HOOK_NETCONN_EXT_RESOLVE_NONE 1 #define CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC 1 #define CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN 16384 +#define CONFIG_MBEDTLS_SSL_KEEP_PEER_CERTIFICATE 1 #define CONFIG_MBEDTLS_CERTIFICATE_BUNDLE 1 #define CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL 1 #define CONFIG_MBEDTLS_HARDWARE_AES 1 #define CONFIG_MBEDTLS_HARDWARE_MPI 1 +#define CONFIG_MBEDTLS_HARDWARE_SHA 1 #define CONFIG_MBEDTLS_ROM_MD5 1 #define CONFIG_MBEDTLS_HAVE_TIME 1 #define CONFIG_MBEDTLS_ECDSA_DETERMINISTIC 1 @@ -537,6 +534,18 @@ #define CONFIG_WIFI_PROV_AUTOSTOP_TIMEOUT 30 #define CONFIG_WPA_MBEDTLS_CRYPTO 1 #define CONFIG_IO_GLITCH_FILTER_TIME_MS 50 +#define CONFIG_ESP_RMAKER_LIB_ESP_MQTT 1 +#define CONFIG_ESP_RMAKER_MQTT_GLUE_LIB 1 +#define CONFIG_ESP_RMAKER_MQTT_PORT_443 1 +#define CONFIG_ESP_RMAKER_MQTT_PORT 1 +#define CONFIG_ESP_RMAKER_MQTT_SEND_USERNAME 1 +#define CONFIG_ESP_RMAKER_MQTT_USERNAME "?Platform=APN/1 ESPIF,RAINMAKER,v1.0" +#define CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK 4096 +#define CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_PRIORITY 5 +#define CONFIG_ESP_RMAKER_FACTORY_PARTITION_NAME "fctry" +#define CONFIG_ESP_RMAKER_FACTORY_NAMESPACE "rmaker_creds" +#define CONFIG_ESP_RMAKER_DEF_TIMEZONE "Asia/Shanghai" +#define CONFIG_ESP_RMAKER_SNTP_SERVER_NAME "pool.ntp.org" #define CONFIG_DSP_OPTIMIZATIONS_SUPPORTED 1 #define CONFIG_DSP_OPTIMIZED 1 #define CONFIG_DSP_OPTIMIZATION 1 @@ -551,7 +560,10 @@ #define CONFIG_GC2145_SUPPORT 1 #define CONFIG_GC032A_SUPPORT 1 #define CONFIG_GC0308_SUPPORT 1 +#define CONFIG_BF3005_SUPPORT 1 +#define CONFIG_BF20A6_SUPPORT 1 #define CONFIG_SCCB_HARDWARE_I2C_PORT1 1 +#define CONFIG_SCCB_CLK_FREQ 100000 #define CONFIG_GC_SENSOR_SUBSAMPLE_MODE 1 #define CONFIG_CAMERA_CORE0 1 #define CONFIG_CAMERA_DMA_BUFFER_SIZE_MAX 32768 @@ -679,5 +691,5 @@ #define CONFIG_ULP_COPROC_RESERVE_MEM CONFIG_ESP32_ULP_COPROC_RESERVE_MEM #define CONFIG_WARN_WRITE_STRINGS CONFIG_COMPILER_WARN_WRITE_STRINGS #define CONFIG_WIFI_LWIP_ALLOCATION_FROM_SPIRAM_FIRST CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP -#define CONFIG_ARDUINO_IDF_COMMIT "a79dc75f0a" +#define CONFIG_ARDUINO_IDF_COMMIT "b8050b365e" #define CONFIG_ARDUINO_IDF_BRANCH "release/v4.4" diff --git a/tools/sdk/esp32/lib/libbootloader_support.a b/tools/sdk/esp32/qspi_qspi/libbootloader_support.a similarity index 56% rename from tools/sdk/esp32/lib/libbootloader_support.a rename to tools/sdk/esp32/qspi_qspi/libbootloader_support.a index c94a3429142..94520ff940c 100644 Binary files a/tools/sdk/esp32/lib/libbootloader_support.a and b/tools/sdk/esp32/qspi_qspi/libbootloader_support.a differ diff --git a/tools/sdk/esp32/lib/libesp_hw_support.a b/tools/sdk/esp32/qspi_qspi/libesp_hw_support.a similarity index 61% rename from tools/sdk/esp32/lib/libesp_hw_support.a rename to tools/sdk/esp32/qspi_qspi/libesp_hw_support.a index 199a74d0543..b37d33791a3 100644 Binary files a/tools/sdk/esp32/lib/libesp_hw_support.a and b/tools/sdk/esp32/qspi_qspi/libesp_hw_support.a differ diff --git a/tools/sdk/esp32/lib/libesp_system.a b/tools/sdk/esp32/qspi_qspi/libesp_system.a similarity index 55% rename from tools/sdk/esp32/lib/libesp_system.a rename to tools/sdk/esp32/qspi_qspi/libesp_system.a index c002693990d..4e1e5d856c1 100644 Binary files a/tools/sdk/esp32/lib/libesp_system.a and b/tools/sdk/esp32/qspi_qspi/libesp_system.a differ diff --git a/tools/sdk/esp32/lib/libfreertos.a b/tools/sdk/esp32/qspi_qspi/libfreertos.a similarity index 54% rename from tools/sdk/esp32/lib/libfreertos.a rename to tools/sdk/esp32/qspi_qspi/libfreertos.a index ab471d6d58d..d596737dc50 100644 Binary files a/tools/sdk/esp32/lib/libfreertos.a and b/tools/sdk/esp32/qspi_qspi/libfreertos.a differ diff --git a/tools/sdk/esp32/lib/libspi_flash.a b/tools/sdk/esp32/qspi_qspi/libspi_flash.a similarity index 51% rename from tools/sdk/esp32/lib/libspi_flash.a rename to tools/sdk/esp32/qspi_qspi/libspi_flash.a index 26be7244e85..97325ba0684 100644 Binary files a/tools/sdk/esp32/lib/libspi_flash.a and b/tools/sdk/esp32/qspi_qspi/libspi_flash.a differ diff --git a/tools/sdk/esp32/ld/sections.ld b/tools/sdk/esp32/qspi_qspi/sections.ld similarity index 71% rename from tools/sdk/esp32/ld/sections.ld rename to tools/sdk/esp32/qspi_qspi/sections.ld index 40feea9f011..189d9a5ab8a 100644 --- a/tools/sdk/esp32/ld/sections.ld +++ b/tools/sdk/esp32/qspi_qspi/sections.ld @@ -351,10 +351,12 @@ SECTIONS *librtc.a:(.literal .literal.* .text .text.*) *libsoc.a:lldesc.*(.literal .literal.* .text .text.*) *libspi_flash.a:memspi_host_driver.*(.literal .literal.* .text .text.*) + *libspi_flash.a:spi_flash_chip_boya.*(.literal .literal.* .text .text.*) *libspi_flash.a:spi_flash_chip_gd.*(.literal .literal.* .text .text.*) *libspi_flash.a:spi_flash_chip_generic.*(.literal .literal.* .text .text.*) *libspi_flash.a:spi_flash_chip_issi.*(.literal .literal.* .text .text.*) *libspi_flash.a:spi_flash_chip_mxic.*(.literal .literal.* .text .text.*) + *libspi_flash.a:spi_flash_chip_th.*(.literal .literal.* .text .text.*) *libspi_flash.a:spi_flash_chip_winbond.*(.literal .literal.* .text .text.*) *libspi_flash.a:spi_flash_rom_patch.*(.literal .literal.* .text .text.*) *libxt_hal.a:(.literal .literal.* .text .text.*) @@ -383,7 +385,7 @@ SECTIONS *(EXCLUDE_FILE(*libbt.a *libbtdm_app.a *libnimble.a) .data EXCLUDE_FILE(*libbt.a *libbtdm_app.a *libnimble.a) .data.*) *(.dram1 .dram1.*) _coredump_dram_start = ABSOLUTE(.); - *(.dram1.coredump .dram1.coredump.*) + *(.dram2.coredump .dram2.coredump.*) _coredump_dram_end = ABSOLUTE(.); *libapp_trace.a:app_trace.*(.rodata .rodata.*) *libapp_trace.a:app_trace_util.*(.rodata .rodata.*) @@ -547,10 +549,12 @@ SECTIONS *libphy.a:(.rodata .rodata.*) *libsoc.a:lldesc.*(.rodata .rodata.*) *libspi_flash.a:memspi_host_driver.*(.rodata .rodata.*) + *libspi_flash.a:spi_flash_chip_boya.*(.rodata .rodata.*) *libspi_flash.a:spi_flash_chip_gd.*(.rodata .rodata.*) *libspi_flash.a:spi_flash_chip_generic.*(.rodata .rodata.*) *libspi_flash.a:spi_flash_chip_issi.*(.rodata .rodata.*) *libspi_flash.a:spi_flash_chip_mxic.*(.rodata .rodata.*) + *libspi_flash.a:spi_flash_chip_th.*(.rodata .rodata.*) *libspi_flash.a:spi_flash_chip_winbond.*(.rodata .rodata.*) *libspi_flash.a:spi_flash_rom_patch.*(.rodata .rodata.*) @@ -641,7 +645,7 @@ SECTIONS { _flash_rodata_start = ABSOLUTE(.); - *(EXCLUDE_FILE(*libgcov.a *libphy.a *libapp_trace.a:app_trace.* *libapp_trace.a:app_trace_util.* *libc.a:creat.* *libc.a:isatty.* *libc.a:lib_a-abs.* *libc.a:lib_a-asctime.* *libc.a:lib_a-asctime_r.* *libc.a:lib_a-atoi.* *libc.a:lib_a-atol.* *libc.a:lib_a-bzero.* *libc.a:lib_a-close.* *libc.a:lib_a-creat.* *libc.a:lib_a-ctime.* *libc.a:lib_a-ctime_r.* *libc.a:lib_a-ctype_.* *libc.a:lib_a-div.* *libc.a:lib_a-environ.* *libc.a:lib_a-envlock.* *libc.a:lib_a-fclose.* *libc.a:lib_a-fflush.* *libc.a:lib_a-findfp.* *libc.a:lib_a-fputwc.* *libc.a:lib_a-fvwrite.* *libc.a:lib_a-fwalk.* *libc.a:lib_a-getenv_r.* *libc.a:lib_a-gettzinfo.* *libc.a:lib_a-gmtime.* *libc.a:lib_a-gmtime_r.* *libc.a:lib_a-impure.* *libc.a:lib_a-isalnum.* *libc.a:lib_a-isalpha.* *libc.a:lib_a-isascii.* *libc.a:lib_a-isblank.* *libc.a:lib_a-iscntrl.* *libc.a:lib_a-isdigit.* *libc.a:lib_a-isgraph.* *libc.a:lib_a-islower.* *libc.a:lib_a-isprint.* *libc.a:lib_a-ispunct.* *libc.a:lib_a-isspace.* *libc.a:lib_a-isupper.* *libc.a:lib_a-itoa.* *libc.a:lib_a-labs.* *libc.a:lib_a-lcltime.* *libc.a:lib_a-lcltime_r.* *libc.a:lib_a-ldiv.* *libc.a:lib_a-longjmp.* *libc.a:lib_a-makebuf.* *libc.a:lib_a-memccpy.* *libc.a:lib_a-memchr.* *libc.a:lib_a-memcmp.* *libc.a:lib_a-memcpy.* *libc.a:lib_a-memmove.* *libc.a:lib_a-memrchr.* *libc.a:lib_a-memset.* *libc.a:lib_a-mktime.* *libc.a:lib_a-month_lengths.* *libc.a:lib_a-open.* *libc.a:lib_a-quorem.* *libc.a:lib_a-raise.* *libc.a:lib_a-rand.* *libc.a:lib_a-rand_r.* *libc.a:lib_a-read.* *libc.a:lib_a-refill.* *libc.a:lib_a-rshift.* *libc.a:lib_a-s_fpclassify.* *libc.a:lib_a-sbrk.* *libc.a:lib_a-sccl.* *libc.a:lib_a-setjmp.* *libc.a:lib_a-sf_nan.* *libc.a:lib_a-srand.* *libc.a:lib_a-stdio.* *libc.a:lib_a-strcasecmp.* *libc.a:lib_a-strcasestr.* *libc.a:lib_a-strcat.* *libc.a:lib_a-strchr.* *libc.a:lib_a-strcmp.* *libc.a:lib_a-strcoll.* *libc.a:lib_a-strcpy.* *libc.a:lib_a-strcspn.* *libc.a:lib_a-strdup.* *libc.a:lib_a-strdup_r.* *libc.a:lib_a-strftime.* *libc.a:lib_a-strlcat.* *libc.a:lib_a-strlcpy.* *libc.a:lib_a-strlen.* *libc.a:lib_a-strlwr.* *libc.a:lib_a-strncasecmp.* *libc.a:lib_a-strncat.* *libc.a:lib_a-strncmp.* *libc.a:lib_a-strncpy.* *libc.a:lib_a-strndup.* *libc.a:lib_a-strndup_r.* *libc.a:lib_a-strnlen.* *libc.a:lib_a-strptime.* *libc.a:lib_a-strrchr.* *libc.a:lib_a-strsep.* *libc.a:lib_a-strspn.* *libc.a:lib_a-strstr.* *libc.a:lib_a-strtok_r.* *libc.a:lib_a-strtol.* *libc.a:lib_a-strtoul.* *libc.a:lib_a-strupr.* *libc.a:lib_a-sysclose.* *libc.a:lib_a-sysopen.* *libc.a:lib_a-sysread.* *libc.a:lib_a-syssbrk.* *libc.a:lib_a-system.* *libc.a:lib_a-systimes.* *libc.a:lib_a-syswrite.* *libc.a:lib_a-time.* *libc.a:lib_a-timelocal.* *libc.a:lib_a-toascii.* *libc.a:lib_a-tolower.* *libc.a:lib_a-toupper.* *libc.a:lib_a-tzcalc_limits.* *libc.a:lib_a-tzlock.* *libc.a:lib_a-tzset.* *libc.a:lib_a-tzset_r.* *libc.a:lib_a-tzvars.* *libc.a:lib_a-ungetc.* *libc.a:lib_a-utoa.* *libc.a:lib_a-wbuf.* *libc.a:lib_a-wcrtomb.* *libc.a:lib_a-wctomb_r.* *libc.a:lib_a-wsetup.* *libc.a:lock.* *libesp_hw_support.a:rtc_clk.* *libesp_system.a:esp_err.* *libesp_system.a:ubsan.* *libhal.a:cpu_hal.* *libhal.a:i2c_hal_iram.* *libhal.a:ledc_hal_iram.* *libhal.a:soc_hal.* *libhal.a:spi_flash_encrypt_hal_iram.* *libhal.a:spi_flash_hal_iram.* *libhal.a:spi_hal_iram.* *libhal.a:spi_slave_hal_iram.* *libhal.a:wdt_hal_iram.* *libheap.a:heap_tlsf.* *libheap.a:multi_heap.* *libheap.a:multi_heap_poisoning.* *libnewlib.a:abort.* *libnewlib.a:assert.* *libnewlib.a:heap.* *libnewlib.a:stdatomic.* *libsoc.a:lldesc.* *libspi_flash.a:memspi_host_driver.* *libspi_flash.a:spi_flash_chip_gd.* *libspi_flash.a:spi_flash_chip_generic.* *libspi_flash.a:spi_flash_chip_issi.* *libspi_flash.a:spi_flash_chip_mxic.* *libspi_flash.a:spi_flash_chip_winbond.* *libspi_flash.a:spi_flash_rom_patch.*) .rodata EXCLUDE_FILE(*libgcov.a *libphy.a *libapp_trace.a:app_trace.* *libapp_trace.a:app_trace_util.* *libc.a:creat.* *libc.a:isatty.* *libc.a:lib_a-abs.* *libc.a:lib_a-asctime.* *libc.a:lib_a-asctime_r.* *libc.a:lib_a-atoi.* *libc.a:lib_a-atol.* *libc.a:lib_a-bzero.* *libc.a:lib_a-close.* *libc.a:lib_a-creat.* *libc.a:lib_a-ctime.* *libc.a:lib_a-ctime_r.* *libc.a:lib_a-ctype_.* *libc.a:lib_a-div.* *libc.a:lib_a-environ.* *libc.a:lib_a-envlock.* *libc.a:lib_a-fclose.* *libc.a:lib_a-fflush.* *libc.a:lib_a-findfp.* *libc.a:lib_a-fputwc.* *libc.a:lib_a-fvwrite.* *libc.a:lib_a-fwalk.* *libc.a:lib_a-getenv_r.* *libc.a:lib_a-gettzinfo.* *libc.a:lib_a-gmtime.* *libc.a:lib_a-gmtime_r.* *libc.a:lib_a-impure.* *libc.a:lib_a-isalnum.* *libc.a:lib_a-isalpha.* *libc.a:lib_a-isascii.* *libc.a:lib_a-isblank.* *libc.a:lib_a-iscntrl.* *libc.a:lib_a-isdigit.* *libc.a:lib_a-isgraph.* *libc.a:lib_a-islower.* *libc.a:lib_a-isprint.* *libc.a:lib_a-ispunct.* *libc.a:lib_a-isspace.* *libc.a:lib_a-isupper.* *libc.a:lib_a-itoa.* *libc.a:lib_a-labs.* *libc.a:lib_a-lcltime.* *libc.a:lib_a-lcltime_r.* *libc.a:lib_a-ldiv.* *libc.a:lib_a-longjmp.* *libc.a:lib_a-makebuf.* *libc.a:lib_a-memccpy.* *libc.a:lib_a-memchr.* *libc.a:lib_a-memcmp.* *libc.a:lib_a-memcpy.* *libc.a:lib_a-memmove.* *libc.a:lib_a-memrchr.* *libc.a:lib_a-memset.* *libc.a:lib_a-mktime.* *libc.a:lib_a-month_lengths.* *libc.a:lib_a-open.* *libc.a:lib_a-quorem.* *libc.a:lib_a-raise.* *libc.a:lib_a-rand.* *libc.a:lib_a-rand_r.* *libc.a:lib_a-read.* *libc.a:lib_a-refill.* *libc.a:lib_a-rshift.* *libc.a:lib_a-s_fpclassify.* *libc.a:lib_a-sbrk.* *libc.a:lib_a-sccl.* *libc.a:lib_a-setjmp.* *libc.a:lib_a-sf_nan.* *libc.a:lib_a-srand.* *libc.a:lib_a-stdio.* *libc.a:lib_a-strcasecmp.* *libc.a:lib_a-strcasestr.* *libc.a:lib_a-strcat.* *libc.a:lib_a-strchr.* *libc.a:lib_a-strcmp.* *libc.a:lib_a-strcoll.* *libc.a:lib_a-strcpy.* *libc.a:lib_a-strcspn.* *libc.a:lib_a-strdup.* *libc.a:lib_a-strdup_r.* *libc.a:lib_a-strftime.* *libc.a:lib_a-strlcat.* *libc.a:lib_a-strlcpy.* *libc.a:lib_a-strlen.* *libc.a:lib_a-strlwr.* *libc.a:lib_a-strncasecmp.* *libc.a:lib_a-strncat.* *libc.a:lib_a-strncmp.* *libc.a:lib_a-strncpy.* *libc.a:lib_a-strndup.* *libc.a:lib_a-strndup_r.* *libc.a:lib_a-strnlen.* *libc.a:lib_a-strptime.* *libc.a:lib_a-strrchr.* *libc.a:lib_a-strsep.* *libc.a:lib_a-strspn.* *libc.a:lib_a-strstr.* *libc.a:lib_a-strtok_r.* *libc.a:lib_a-strtol.* *libc.a:lib_a-strtoul.* *libc.a:lib_a-strupr.* *libc.a:lib_a-sysclose.* *libc.a:lib_a-sysopen.* *libc.a:lib_a-sysread.* *libc.a:lib_a-syssbrk.* *libc.a:lib_a-system.* *libc.a:lib_a-systimes.* *libc.a:lib_a-syswrite.* *libc.a:lib_a-time.* *libc.a:lib_a-timelocal.* *libc.a:lib_a-toascii.* *libc.a:lib_a-tolower.* *libc.a:lib_a-toupper.* *libc.a:lib_a-tzcalc_limits.* *libc.a:lib_a-tzlock.* *libc.a:lib_a-tzset.* *libc.a:lib_a-tzset_r.* *libc.a:lib_a-tzvars.* *libc.a:lib_a-ungetc.* *libc.a:lib_a-utoa.* *libc.a:lib_a-wbuf.* *libc.a:lib_a-wcrtomb.* *libc.a:lib_a-wctomb_r.* *libc.a:lib_a-wsetup.* *libc.a:lock.* *libesp_hw_support.a:rtc_clk.* *libesp_system.a:esp_err.* *libesp_system.a:ubsan.* *libhal.a:cpu_hal.* *libhal.a:i2c_hal_iram.* *libhal.a:ledc_hal_iram.* *libhal.a:soc_hal.* *libhal.a:spi_flash_encrypt_hal_iram.* *libhal.a:spi_flash_hal_iram.* *libhal.a:spi_hal_iram.* *libhal.a:spi_slave_hal_iram.* *libhal.a:wdt_hal_iram.* *libheap.a:heap_tlsf.* *libheap.a:multi_heap.* *libheap.a:multi_heap_poisoning.* *libnewlib.a:abort.* *libnewlib.a:assert.* *libnewlib.a:heap.* *libnewlib.a:stdatomic.* *libsoc.a:lldesc.* *libspi_flash.a:memspi_host_driver.* *libspi_flash.a:spi_flash_chip_gd.* *libspi_flash.a:spi_flash_chip_generic.* *libspi_flash.a:spi_flash_chip_issi.* *libspi_flash.a:spi_flash_chip_mxic.* *libspi_flash.a:spi_flash_chip_winbond.* *libspi_flash.a:spi_flash_rom_patch.*) .rodata.*) + *(EXCLUDE_FILE(*libgcov.a *libphy.a *libapp_trace.a:app_trace.* *libapp_trace.a:app_trace_util.* *libc.a:creat.* *libc.a:isatty.* *libc.a:lib_a-abs.* *libc.a:lib_a-asctime.* *libc.a:lib_a-asctime_r.* *libc.a:lib_a-atoi.* *libc.a:lib_a-atol.* *libc.a:lib_a-bzero.* *libc.a:lib_a-close.* *libc.a:lib_a-creat.* *libc.a:lib_a-ctime.* *libc.a:lib_a-ctime_r.* *libc.a:lib_a-ctype_.* *libc.a:lib_a-div.* *libc.a:lib_a-environ.* *libc.a:lib_a-envlock.* *libc.a:lib_a-fclose.* *libc.a:lib_a-fflush.* *libc.a:lib_a-findfp.* *libc.a:lib_a-fputwc.* *libc.a:lib_a-fvwrite.* *libc.a:lib_a-fwalk.* *libc.a:lib_a-getenv_r.* *libc.a:lib_a-gettzinfo.* *libc.a:lib_a-gmtime.* *libc.a:lib_a-gmtime_r.* *libc.a:lib_a-impure.* *libc.a:lib_a-isalnum.* *libc.a:lib_a-isalpha.* *libc.a:lib_a-isascii.* *libc.a:lib_a-isblank.* *libc.a:lib_a-iscntrl.* *libc.a:lib_a-isdigit.* *libc.a:lib_a-isgraph.* *libc.a:lib_a-islower.* *libc.a:lib_a-isprint.* *libc.a:lib_a-ispunct.* *libc.a:lib_a-isspace.* *libc.a:lib_a-isupper.* *libc.a:lib_a-itoa.* *libc.a:lib_a-labs.* *libc.a:lib_a-lcltime.* *libc.a:lib_a-lcltime_r.* *libc.a:lib_a-ldiv.* *libc.a:lib_a-longjmp.* *libc.a:lib_a-makebuf.* *libc.a:lib_a-memccpy.* *libc.a:lib_a-memchr.* *libc.a:lib_a-memcmp.* *libc.a:lib_a-memcpy.* *libc.a:lib_a-memmove.* *libc.a:lib_a-memrchr.* *libc.a:lib_a-memset.* *libc.a:lib_a-mktime.* *libc.a:lib_a-month_lengths.* *libc.a:lib_a-open.* *libc.a:lib_a-quorem.* *libc.a:lib_a-raise.* *libc.a:lib_a-rand.* *libc.a:lib_a-rand_r.* *libc.a:lib_a-read.* *libc.a:lib_a-refill.* *libc.a:lib_a-rshift.* *libc.a:lib_a-s_fpclassify.* *libc.a:lib_a-sbrk.* *libc.a:lib_a-sccl.* *libc.a:lib_a-setjmp.* *libc.a:lib_a-sf_nan.* *libc.a:lib_a-srand.* *libc.a:lib_a-stdio.* *libc.a:lib_a-strcasecmp.* *libc.a:lib_a-strcasestr.* *libc.a:lib_a-strcat.* *libc.a:lib_a-strchr.* *libc.a:lib_a-strcmp.* *libc.a:lib_a-strcoll.* *libc.a:lib_a-strcpy.* *libc.a:lib_a-strcspn.* *libc.a:lib_a-strdup.* *libc.a:lib_a-strdup_r.* *libc.a:lib_a-strftime.* *libc.a:lib_a-strlcat.* *libc.a:lib_a-strlcpy.* *libc.a:lib_a-strlen.* *libc.a:lib_a-strlwr.* *libc.a:lib_a-strncasecmp.* *libc.a:lib_a-strncat.* *libc.a:lib_a-strncmp.* *libc.a:lib_a-strncpy.* *libc.a:lib_a-strndup.* *libc.a:lib_a-strndup_r.* *libc.a:lib_a-strnlen.* *libc.a:lib_a-strptime.* *libc.a:lib_a-strrchr.* *libc.a:lib_a-strsep.* *libc.a:lib_a-strspn.* *libc.a:lib_a-strstr.* *libc.a:lib_a-strtok_r.* *libc.a:lib_a-strtol.* *libc.a:lib_a-strtoul.* *libc.a:lib_a-strupr.* *libc.a:lib_a-sysclose.* *libc.a:lib_a-sysopen.* *libc.a:lib_a-sysread.* *libc.a:lib_a-syssbrk.* *libc.a:lib_a-system.* *libc.a:lib_a-systimes.* *libc.a:lib_a-syswrite.* *libc.a:lib_a-time.* *libc.a:lib_a-timelocal.* *libc.a:lib_a-toascii.* *libc.a:lib_a-tolower.* *libc.a:lib_a-toupper.* *libc.a:lib_a-tzcalc_limits.* *libc.a:lib_a-tzlock.* *libc.a:lib_a-tzset.* *libc.a:lib_a-tzset_r.* *libc.a:lib_a-tzvars.* *libc.a:lib_a-ungetc.* *libc.a:lib_a-utoa.* *libc.a:lib_a-wbuf.* *libc.a:lib_a-wcrtomb.* *libc.a:lib_a-wctomb_r.* *libc.a:lib_a-wsetup.* *libc.a:lock.* *libesp_hw_support.a:rtc_clk.* *libesp_system.a:esp_err.* *libesp_system.a:ubsan.* *libhal.a:cpu_hal.* *libhal.a:i2c_hal_iram.* *libhal.a:ledc_hal_iram.* *libhal.a:soc_hal.* *libhal.a:spi_flash_encrypt_hal_iram.* *libhal.a:spi_flash_hal_iram.* *libhal.a:spi_hal_iram.* *libhal.a:spi_slave_hal_iram.* *libhal.a:wdt_hal_iram.* *libheap.a:heap_tlsf.* *libheap.a:multi_heap.* *libheap.a:multi_heap_poisoning.* *libnewlib.a:abort.* *libnewlib.a:assert.* *libnewlib.a:heap.* *libnewlib.a:stdatomic.* *libsoc.a:lldesc.* *libspi_flash.a:memspi_host_driver.* *libspi_flash.a:spi_flash_chip_boya.* *libspi_flash.a:spi_flash_chip_gd.* *libspi_flash.a:spi_flash_chip_generic.* *libspi_flash.a:spi_flash_chip_issi.* *libspi_flash.a:spi_flash_chip_mxic.* *libspi_flash.a:spi_flash_chip_th.* *libspi_flash.a:spi_flash_chip_winbond.* *libspi_flash.a:spi_flash_rom_patch.*) .rodata EXCLUDE_FILE(*libgcov.a *libphy.a *libapp_trace.a:app_trace.* *libapp_trace.a:app_trace_util.* *libc.a:creat.* *libc.a:isatty.* *libc.a:lib_a-abs.* *libc.a:lib_a-asctime.* *libc.a:lib_a-asctime_r.* *libc.a:lib_a-atoi.* *libc.a:lib_a-atol.* *libc.a:lib_a-bzero.* *libc.a:lib_a-close.* *libc.a:lib_a-creat.* *libc.a:lib_a-ctime.* *libc.a:lib_a-ctime_r.* *libc.a:lib_a-ctype_.* *libc.a:lib_a-div.* *libc.a:lib_a-environ.* *libc.a:lib_a-envlock.* *libc.a:lib_a-fclose.* *libc.a:lib_a-fflush.* *libc.a:lib_a-findfp.* *libc.a:lib_a-fputwc.* *libc.a:lib_a-fvwrite.* *libc.a:lib_a-fwalk.* *libc.a:lib_a-getenv_r.* *libc.a:lib_a-gettzinfo.* *libc.a:lib_a-gmtime.* *libc.a:lib_a-gmtime_r.* *libc.a:lib_a-impure.* *libc.a:lib_a-isalnum.* *libc.a:lib_a-isalpha.* *libc.a:lib_a-isascii.* *libc.a:lib_a-isblank.* *libc.a:lib_a-iscntrl.* *libc.a:lib_a-isdigit.* *libc.a:lib_a-isgraph.* *libc.a:lib_a-islower.* *libc.a:lib_a-isprint.* *libc.a:lib_a-ispunct.* *libc.a:lib_a-isspace.* *libc.a:lib_a-isupper.* *libc.a:lib_a-itoa.* *libc.a:lib_a-labs.* *libc.a:lib_a-lcltime.* *libc.a:lib_a-lcltime_r.* *libc.a:lib_a-ldiv.* *libc.a:lib_a-longjmp.* *libc.a:lib_a-makebuf.* *libc.a:lib_a-memccpy.* *libc.a:lib_a-memchr.* *libc.a:lib_a-memcmp.* *libc.a:lib_a-memcpy.* *libc.a:lib_a-memmove.* *libc.a:lib_a-memrchr.* *libc.a:lib_a-memset.* *libc.a:lib_a-mktime.* *libc.a:lib_a-month_lengths.* *libc.a:lib_a-open.* *libc.a:lib_a-quorem.* *libc.a:lib_a-raise.* *libc.a:lib_a-rand.* *libc.a:lib_a-rand_r.* *libc.a:lib_a-read.* *libc.a:lib_a-refill.* *libc.a:lib_a-rshift.* *libc.a:lib_a-s_fpclassify.* *libc.a:lib_a-sbrk.* *libc.a:lib_a-sccl.* *libc.a:lib_a-setjmp.* *libc.a:lib_a-sf_nan.* *libc.a:lib_a-srand.* *libc.a:lib_a-stdio.* *libc.a:lib_a-strcasecmp.* *libc.a:lib_a-strcasestr.* *libc.a:lib_a-strcat.* *libc.a:lib_a-strchr.* *libc.a:lib_a-strcmp.* *libc.a:lib_a-strcoll.* *libc.a:lib_a-strcpy.* *libc.a:lib_a-strcspn.* *libc.a:lib_a-strdup.* *libc.a:lib_a-strdup_r.* *libc.a:lib_a-strftime.* *libc.a:lib_a-strlcat.* *libc.a:lib_a-strlcpy.* *libc.a:lib_a-strlen.* *libc.a:lib_a-strlwr.* *libc.a:lib_a-strncasecmp.* *libc.a:lib_a-strncat.* *libc.a:lib_a-strncmp.* *libc.a:lib_a-strncpy.* *libc.a:lib_a-strndup.* *libc.a:lib_a-strndup_r.* *libc.a:lib_a-strnlen.* *libc.a:lib_a-strptime.* *libc.a:lib_a-strrchr.* *libc.a:lib_a-strsep.* *libc.a:lib_a-strspn.* *libc.a:lib_a-strstr.* *libc.a:lib_a-strtok_r.* *libc.a:lib_a-strtol.* *libc.a:lib_a-strtoul.* *libc.a:lib_a-strupr.* *libc.a:lib_a-sysclose.* *libc.a:lib_a-sysopen.* *libc.a:lib_a-sysread.* *libc.a:lib_a-syssbrk.* *libc.a:lib_a-system.* *libc.a:lib_a-systimes.* *libc.a:lib_a-syswrite.* *libc.a:lib_a-time.* *libc.a:lib_a-timelocal.* *libc.a:lib_a-toascii.* *libc.a:lib_a-tolower.* *libc.a:lib_a-toupper.* *libc.a:lib_a-tzcalc_limits.* *libc.a:lib_a-tzlock.* *libc.a:lib_a-tzset.* *libc.a:lib_a-tzset_r.* *libc.a:lib_a-tzvars.* *libc.a:lib_a-ungetc.* *libc.a:lib_a-utoa.* *libc.a:lib_a-wbuf.* *libc.a:lib_a-wcrtomb.* *libc.a:lib_a-wctomb_r.* *libc.a:lib_a-wsetup.* *libc.a:lock.* *libesp_hw_support.a:rtc_clk.* *libesp_system.a:esp_err.* *libesp_system.a:ubsan.* *libhal.a:cpu_hal.* *libhal.a:i2c_hal_iram.* *libhal.a:ledc_hal_iram.* *libhal.a:soc_hal.* *libhal.a:spi_flash_encrypt_hal_iram.* *libhal.a:spi_flash_hal_iram.* *libhal.a:spi_hal_iram.* *libhal.a:spi_slave_hal_iram.* *libhal.a:wdt_hal_iram.* *libheap.a:heap_tlsf.* *libheap.a:multi_heap.* *libheap.a:multi_heap_poisoning.* *libnewlib.a:abort.* *libnewlib.a:assert.* *libnewlib.a:heap.* *libnewlib.a:stdatomic.* *libsoc.a:lldesc.* *libspi_flash.a:memspi_host_driver.* *libspi_flash.a:spi_flash_chip_boya.* *libspi_flash.a:spi_flash_chip_gd.* *libspi_flash.a:spi_flash_chip_generic.* *libspi_flash.a:spi_flash_chip_issi.* *libspi_flash.a:spi_flash_chip_mxic.* *libspi_flash.a:spi_flash_chip_th.* *libspi_flash.a:spi_flash_chip_winbond.* *libspi_flash.a:spi_flash_rom_patch.*) .rodata.*) *(.rodata_wlog_error .rodata_wlog_error.*) @@ -715,7 +719,7 @@ SECTIONS _stext = .; _text_start = ABSOLUTE(.); - *(EXCLUDE_FILE(*libesp_ringbuf.a *libfreertos.a *libgcov.a *librtc.a *libxt_hal.a *libapp_trace.a:app_trace.* *libapp_trace.a:app_trace_util.* *libc.a:creat.* *libc.a:isatty.* *libc.a:lib_a-abs.* *libc.a:lib_a-asctime.* *libc.a:lib_a-asctime_r.* *libc.a:lib_a-atoi.* *libc.a:lib_a-atol.* *libc.a:lib_a-bzero.* *libc.a:lib_a-close.* *libc.a:lib_a-creat.* *libc.a:lib_a-ctime.* *libc.a:lib_a-ctime_r.* *libc.a:lib_a-ctype_.* *libc.a:lib_a-div.* *libc.a:lib_a-environ.* *libc.a:lib_a-envlock.* *libc.a:lib_a-fclose.* *libc.a:lib_a-fflush.* *libc.a:lib_a-findfp.* *libc.a:lib_a-fputwc.* *libc.a:lib_a-fvwrite.* *libc.a:lib_a-fwalk.* *libc.a:lib_a-getenv_r.* *libc.a:lib_a-gettzinfo.* *libc.a:lib_a-gmtime.* *libc.a:lib_a-gmtime_r.* *libc.a:lib_a-impure.* *libc.a:lib_a-isalnum.* *libc.a:lib_a-isalpha.* *libc.a:lib_a-isascii.* *libc.a:lib_a-isblank.* *libc.a:lib_a-iscntrl.* *libc.a:lib_a-isdigit.* *libc.a:lib_a-isgraph.* *libc.a:lib_a-islower.* *libc.a:lib_a-isprint.* *libc.a:lib_a-ispunct.* *libc.a:lib_a-isspace.* *libc.a:lib_a-isupper.* *libc.a:lib_a-itoa.* *libc.a:lib_a-labs.* *libc.a:lib_a-lcltime.* *libc.a:lib_a-lcltime_r.* *libc.a:lib_a-ldiv.* *libc.a:lib_a-longjmp.* *libc.a:lib_a-makebuf.* *libc.a:lib_a-memccpy.* *libc.a:lib_a-memchr.* *libc.a:lib_a-memcmp.* *libc.a:lib_a-memcpy.* *libc.a:lib_a-memmove.* *libc.a:lib_a-memrchr.* *libc.a:lib_a-memset.* *libc.a:lib_a-mktime.* *libc.a:lib_a-month_lengths.* *libc.a:lib_a-open.* *libc.a:lib_a-quorem.* *libc.a:lib_a-raise.* *libc.a:lib_a-rand.* *libc.a:lib_a-rand_r.* *libc.a:lib_a-read.* *libc.a:lib_a-refill.* *libc.a:lib_a-rshift.* *libc.a:lib_a-s_fpclassify.* *libc.a:lib_a-sbrk.* *libc.a:lib_a-sccl.* *libc.a:lib_a-setjmp.* *libc.a:lib_a-sf_nan.* *libc.a:lib_a-srand.* *libc.a:lib_a-stdio.* *libc.a:lib_a-strcasecmp.* *libc.a:lib_a-strcasestr.* *libc.a:lib_a-strcat.* *libc.a:lib_a-strchr.* *libc.a:lib_a-strcmp.* *libc.a:lib_a-strcoll.* *libc.a:lib_a-strcpy.* *libc.a:lib_a-strcspn.* *libc.a:lib_a-strdup.* *libc.a:lib_a-strdup_r.* *libc.a:lib_a-strftime.* *libc.a:lib_a-strlcat.* *libc.a:lib_a-strlcpy.* *libc.a:lib_a-strlen.* *libc.a:lib_a-strlwr.* *libc.a:lib_a-strncasecmp.* *libc.a:lib_a-strncat.* *libc.a:lib_a-strncmp.* *libc.a:lib_a-strncpy.* *libc.a:lib_a-strndup.* *libc.a:lib_a-strndup_r.* *libc.a:lib_a-strnlen.* *libc.a:lib_a-strptime.* *libc.a:lib_a-strrchr.* *libc.a:lib_a-strsep.* *libc.a:lib_a-strspn.* *libc.a:lib_a-strstr.* *libc.a:lib_a-strtok_r.* *libc.a:lib_a-strtol.* *libc.a:lib_a-strtoul.* *libc.a:lib_a-strupr.* *libc.a:lib_a-sysclose.* *libc.a:lib_a-sysopen.* *libc.a:lib_a-sysread.* *libc.a:lib_a-syssbrk.* *libc.a:lib_a-system.* *libc.a:lib_a-systimes.* *libc.a:lib_a-syswrite.* *libc.a:lib_a-time.* *libc.a:lib_a-timelocal.* *libc.a:lib_a-toascii.* *libc.a:lib_a-tolower.* *libc.a:lib_a-toupper.* *libc.a:lib_a-tzcalc_limits.* *libc.a:lib_a-tzlock.* *libc.a:lib_a-tzset.* *libc.a:lib_a-tzset_r.* *libc.a:lib_a-tzvars.* *libc.a:lib_a-ungetc.* *libc.a:lib_a-utoa.* *libc.a:lib_a-wbuf.* *libc.a:lib_a-wcrtomb.* *libc.a:lib_a-wctomb_r.* *libc.a:lib_a-wsetup.* *libc.a:lock.* *libesp_event.a:default_event_loop.* *libesp_event.a:esp_event.* *libesp_hw_support.a:cpu_util.* *libesp_hw_support.a:rtc_clk.* *libesp_hw_support.a:rtc_init.* *libesp_hw_support.a:rtc_pm.* *libesp_hw_support.a:rtc_sleep.* *libesp_hw_support.a:rtc_time.* *libesp_hw_support.a:rtc_wdt.* *libesp_system.a:esp_err.* *libesp_system.a:esp_system.* *libesp_system.a:ubsan.* *libgcc.a:lib2funcs.* *libhal.a:cpu_hal.* *libhal.a:i2c_hal_iram.* *libhal.a:ledc_hal_iram.* *libhal.a:soc_hal.* *libhal.a:spi_flash_encrypt_hal_iram.* *libhal.a:spi_flash_hal_iram.* *libhal.a:spi_hal_iram.* *libhal.a:spi_slave_hal_iram.* *libhal.a:wdt_hal_iram.* *libheap.a:heap_tlsf.* *libheap.a:multi_heap.* *libheap.a:multi_heap_poisoning.* *liblog.a:log.* *liblog.a:log_freertos.* *libnewlib.a:abort.* *libnewlib.a:assert.* *libnewlib.a:heap.* *libnewlib.a:stdatomic.* *libsoc.a:lldesc.* *libspi_flash.a:memspi_host_driver.* *libspi_flash.a:spi_flash_chip_gd.* *libspi_flash.a:spi_flash_chip_generic.* *libspi_flash.a:spi_flash_chip_issi.* *libspi_flash.a:spi_flash_chip_mxic.* *libspi_flash.a:spi_flash_chip_winbond.* *libspi_flash.a:spi_flash_rom_patch.* *libxtensa.a:eri.* *libxtensa.a:xtensa_intr_asm.*) .literal EXCLUDE_FILE(*libesp_ringbuf.a *libfreertos.a *libgcov.a *librtc.a *libxt_hal.a *libapp_trace.a:app_trace.* *libapp_trace.a:app_trace_util.* *libc.a:creat.* *libc.a:isatty.* *libc.a:lib_a-abs.* *libc.a:lib_a-asctime.* *libc.a:lib_a-asctime_r.* *libc.a:lib_a-atoi.* *libc.a:lib_a-atol.* *libc.a:lib_a-bzero.* *libc.a:lib_a-close.* *libc.a:lib_a-creat.* *libc.a:lib_a-ctime.* *libc.a:lib_a-ctime_r.* *libc.a:lib_a-ctype_.* *libc.a:lib_a-div.* *libc.a:lib_a-environ.* *libc.a:lib_a-envlock.* *libc.a:lib_a-fclose.* *libc.a:lib_a-fflush.* *libc.a:lib_a-findfp.* *libc.a:lib_a-fputwc.* *libc.a:lib_a-fvwrite.* *libc.a:lib_a-fwalk.* *libc.a:lib_a-getenv_r.* *libc.a:lib_a-gettzinfo.* *libc.a:lib_a-gmtime.* *libc.a:lib_a-gmtime_r.* *libc.a:lib_a-impure.* *libc.a:lib_a-isalnum.* *libc.a:lib_a-isalpha.* *libc.a:lib_a-isascii.* *libc.a:lib_a-isblank.* *libc.a:lib_a-iscntrl.* *libc.a:lib_a-isdigit.* *libc.a:lib_a-isgraph.* *libc.a:lib_a-islower.* *libc.a:lib_a-isprint.* *libc.a:lib_a-ispunct.* *libc.a:lib_a-isspace.* *libc.a:lib_a-isupper.* *libc.a:lib_a-itoa.* *libc.a:lib_a-labs.* *libc.a:lib_a-lcltime.* *libc.a:lib_a-lcltime_r.* *libc.a:lib_a-ldiv.* *libc.a:lib_a-longjmp.* *libc.a:lib_a-makebuf.* *libc.a:lib_a-memccpy.* *libc.a:lib_a-memchr.* *libc.a:lib_a-memcmp.* *libc.a:lib_a-memcpy.* *libc.a:lib_a-memmove.* *libc.a:lib_a-memrchr.* *libc.a:lib_a-memset.* *libc.a:lib_a-mktime.* *libc.a:lib_a-month_lengths.* *libc.a:lib_a-open.* *libc.a:lib_a-quorem.* *libc.a:lib_a-raise.* *libc.a:lib_a-rand.* *libc.a:lib_a-rand_r.* *libc.a:lib_a-read.* *libc.a:lib_a-refill.* *libc.a:lib_a-rshift.* *libc.a:lib_a-s_fpclassify.* *libc.a:lib_a-sbrk.* *libc.a:lib_a-sccl.* *libc.a:lib_a-setjmp.* *libc.a:lib_a-sf_nan.* *libc.a:lib_a-srand.* *libc.a:lib_a-stdio.* *libc.a:lib_a-strcasecmp.* *libc.a:lib_a-strcasestr.* *libc.a:lib_a-strcat.* *libc.a:lib_a-strchr.* *libc.a:lib_a-strcmp.* *libc.a:lib_a-strcoll.* *libc.a:lib_a-strcpy.* *libc.a:lib_a-strcspn.* *libc.a:lib_a-strdup.* *libc.a:lib_a-strdup_r.* *libc.a:lib_a-strftime.* *libc.a:lib_a-strlcat.* *libc.a:lib_a-strlcpy.* *libc.a:lib_a-strlen.* *libc.a:lib_a-strlwr.* *libc.a:lib_a-strncasecmp.* *libc.a:lib_a-strncat.* *libc.a:lib_a-strncmp.* *libc.a:lib_a-strncpy.* *libc.a:lib_a-strndup.* *libc.a:lib_a-strndup_r.* *libc.a:lib_a-strnlen.* *libc.a:lib_a-strptime.* *libc.a:lib_a-strrchr.* *libc.a:lib_a-strsep.* *libc.a:lib_a-strspn.* *libc.a:lib_a-strstr.* *libc.a:lib_a-strtok_r.* *libc.a:lib_a-strtol.* *libc.a:lib_a-strtoul.* *libc.a:lib_a-strupr.* *libc.a:lib_a-sysclose.* *libc.a:lib_a-sysopen.* *libc.a:lib_a-sysread.* *libc.a:lib_a-syssbrk.* *libc.a:lib_a-system.* *libc.a:lib_a-systimes.* *libc.a:lib_a-syswrite.* *libc.a:lib_a-time.* *libc.a:lib_a-timelocal.* *libc.a:lib_a-toascii.* *libc.a:lib_a-tolower.* *libc.a:lib_a-toupper.* *libc.a:lib_a-tzcalc_limits.* *libc.a:lib_a-tzlock.* *libc.a:lib_a-tzset.* *libc.a:lib_a-tzset_r.* *libc.a:lib_a-tzvars.* *libc.a:lib_a-ungetc.* *libc.a:lib_a-utoa.* *libc.a:lib_a-wbuf.* *libc.a:lib_a-wcrtomb.* *libc.a:lib_a-wctomb_r.* *libc.a:lib_a-wsetup.* *libc.a:lock.* *libesp_event.a:default_event_loop.* *libesp_event.a:esp_event.* *libesp_hw_support.a:cpu_util.* *libesp_hw_support.a:rtc_clk.* *libesp_hw_support.a:rtc_init.* *libesp_hw_support.a:rtc_pm.* *libesp_hw_support.a:rtc_sleep.* *libesp_hw_support.a:rtc_time.* *libesp_hw_support.a:rtc_wdt.* *libesp_system.a:esp_err.* *libesp_system.a:esp_system.* *libesp_system.a:ubsan.* *libgcc.a:lib2funcs.* *libhal.a:cpu_hal.* *libhal.a:i2c_hal_iram.* *libhal.a:ledc_hal_iram.* *libhal.a:soc_hal.* *libhal.a:spi_flash_encrypt_hal_iram.* *libhal.a:spi_flash_hal_iram.* *libhal.a:spi_hal_iram.* *libhal.a:spi_slave_hal_iram.* *libhal.a:wdt_hal_iram.* *libheap.a:heap_tlsf.* *libheap.a:multi_heap.* *libheap.a:multi_heap_poisoning.* *liblog.a:log.* *liblog.a:log_freertos.* *libnewlib.a:abort.* *libnewlib.a:assert.* *libnewlib.a:heap.* *libnewlib.a:stdatomic.* *libsoc.a:lldesc.* *libspi_flash.a:memspi_host_driver.* *libspi_flash.a:spi_flash_chip_gd.* *libspi_flash.a:spi_flash_chip_generic.* *libspi_flash.a:spi_flash_chip_issi.* *libspi_flash.a:spi_flash_chip_mxic.* *libspi_flash.a:spi_flash_chip_winbond.* *libspi_flash.a:spi_flash_rom_patch.* *libxtensa.a:eri.* *libxtensa.a:xtensa_intr_asm.*) .literal.* EXCLUDE_FILE(*libesp_ringbuf.a *libfreertos.a *libgcov.a *librtc.a *libxt_hal.a *libapp_trace.a:app_trace.* *libapp_trace.a:app_trace_util.* *libc.a:creat.* *libc.a:isatty.* *libc.a:lib_a-abs.* *libc.a:lib_a-asctime.* *libc.a:lib_a-asctime_r.* *libc.a:lib_a-atoi.* *libc.a:lib_a-atol.* *libc.a:lib_a-bzero.* *libc.a:lib_a-close.* *libc.a:lib_a-creat.* *libc.a:lib_a-ctime.* *libc.a:lib_a-ctime_r.* *libc.a:lib_a-ctype_.* *libc.a:lib_a-div.* *libc.a:lib_a-environ.* *libc.a:lib_a-envlock.* *libc.a:lib_a-fclose.* *libc.a:lib_a-fflush.* *libc.a:lib_a-findfp.* *libc.a:lib_a-fputwc.* *libc.a:lib_a-fvwrite.* *libc.a:lib_a-fwalk.* *libc.a:lib_a-getenv_r.* *libc.a:lib_a-gettzinfo.* *libc.a:lib_a-gmtime.* *libc.a:lib_a-gmtime_r.* *libc.a:lib_a-impure.* *libc.a:lib_a-isalnum.* *libc.a:lib_a-isalpha.* *libc.a:lib_a-isascii.* *libc.a:lib_a-isblank.* *libc.a:lib_a-iscntrl.* *libc.a:lib_a-isdigit.* *libc.a:lib_a-isgraph.* *libc.a:lib_a-islower.* *libc.a:lib_a-isprint.* *libc.a:lib_a-ispunct.* *libc.a:lib_a-isspace.* *libc.a:lib_a-isupper.* *libc.a:lib_a-itoa.* *libc.a:lib_a-labs.* *libc.a:lib_a-lcltime.* *libc.a:lib_a-lcltime_r.* *libc.a:lib_a-ldiv.* *libc.a:lib_a-longjmp.* *libc.a:lib_a-makebuf.* *libc.a:lib_a-memccpy.* *libc.a:lib_a-memchr.* *libc.a:lib_a-memcmp.* *libc.a:lib_a-memcpy.* *libc.a:lib_a-memmove.* *libc.a:lib_a-memrchr.* *libc.a:lib_a-memset.* *libc.a:lib_a-mktime.* *libc.a:lib_a-month_lengths.* *libc.a:lib_a-open.* *libc.a:lib_a-quorem.* *libc.a:lib_a-raise.* *libc.a:lib_a-rand.* *libc.a:lib_a-rand_r.* *libc.a:lib_a-read.* *libc.a:lib_a-refill.* *libc.a:lib_a-rshift.* *libc.a:lib_a-s_fpclassify.* *libc.a:lib_a-sbrk.* *libc.a:lib_a-sccl.* *libc.a:lib_a-setjmp.* *libc.a:lib_a-sf_nan.* *libc.a:lib_a-srand.* *libc.a:lib_a-stdio.* *libc.a:lib_a-strcasecmp.* *libc.a:lib_a-strcasestr.* *libc.a:lib_a-strcat.* *libc.a:lib_a-strchr.* *libc.a:lib_a-strcmp.* *libc.a:lib_a-strcoll.* *libc.a:lib_a-strcpy.* *libc.a:lib_a-strcspn.* *libc.a:lib_a-strdup.* *libc.a:lib_a-strdup_r.* *libc.a:lib_a-strftime.* *libc.a:lib_a-strlcat.* *libc.a:lib_a-strlcpy.* *libc.a:lib_a-strlen.* *libc.a:lib_a-strlwr.* *libc.a:lib_a-strncasecmp.* *libc.a:lib_a-strncat.* *libc.a:lib_a-strncmp.* *libc.a:lib_a-strncpy.* *libc.a:lib_a-strndup.* *libc.a:lib_a-strndup_r.* *libc.a:lib_a-strnlen.* *libc.a:lib_a-strptime.* *libc.a:lib_a-strrchr.* *libc.a:lib_a-strsep.* *libc.a:lib_a-strspn.* *libc.a:lib_a-strstr.* *libc.a:lib_a-strtok_r.* *libc.a:lib_a-strtol.* *libc.a:lib_a-strtoul.* *libc.a:lib_a-strupr.* *libc.a:lib_a-sysclose.* *libc.a:lib_a-sysopen.* *libc.a:lib_a-sysread.* *libc.a:lib_a-syssbrk.* *libc.a:lib_a-system.* *libc.a:lib_a-systimes.* *libc.a:lib_a-syswrite.* *libc.a:lib_a-time.* *libc.a:lib_a-timelocal.* *libc.a:lib_a-toascii.* *libc.a:lib_a-tolower.* *libc.a:lib_a-toupper.* *libc.a:lib_a-tzcalc_limits.* *libc.a:lib_a-tzlock.* *libc.a:lib_a-tzset.* *libc.a:lib_a-tzset_r.* *libc.a:lib_a-tzvars.* *libc.a:lib_a-ungetc.* *libc.a:lib_a-utoa.* *libc.a:lib_a-wbuf.* *libc.a:lib_a-wcrtomb.* *libc.a:lib_a-wctomb_r.* *libc.a:lib_a-wsetup.* *libc.a:lock.* *libesp_event.a:default_event_loop.* *libesp_event.a:esp_event.* *libesp_hw_support.a:cpu_util.* *libesp_hw_support.a:rtc_clk.* *libesp_hw_support.a:rtc_init.* *libesp_hw_support.a:rtc_pm.* *libesp_hw_support.a:rtc_sleep.* *libesp_hw_support.a:rtc_time.* *libesp_hw_support.a:rtc_wdt.* *libesp_system.a:esp_err.* *libesp_system.a:esp_system.* *libesp_system.a:ubsan.* *libgcc.a:lib2funcs.* *libhal.a:cpu_hal.* *libhal.a:i2c_hal_iram.* *libhal.a:ledc_hal_iram.* *libhal.a:soc_hal.* *libhal.a:spi_flash_encrypt_hal_iram.* *libhal.a:spi_flash_hal_iram.* *libhal.a:spi_hal_iram.* *libhal.a:spi_slave_hal_iram.* *libhal.a:wdt_hal_iram.* *libheap.a:heap_tlsf.* *libheap.a:multi_heap.* *libheap.a:multi_heap_poisoning.* *liblog.a:log.* *liblog.a:log_freertos.* *libnewlib.a:abort.* *libnewlib.a:assert.* *libnewlib.a:heap.* *libnewlib.a:stdatomic.* *libsoc.a:lldesc.* *libspi_flash.a:memspi_host_driver.* *libspi_flash.a:spi_flash_chip_gd.* *libspi_flash.a:spi_flash_chip_generic.* *libspi_flash.a:spi_flash_chip_issi.* *libspi_flash.a:spi_flash_chip_mxic.* *libspi_flash.a:spi_flash_chip_winbond.* *libspi_flash.a:spi_flash_rom_patch.* *libxtensa.a:eri.* *libxtensa.a:xtensa_intr_asm.*) .text EXCLUDE_FILE(*libesp_ringbuf.a *libfreertos.a *libgcov.a *librtc.a *libxt_hal.a *libapp_trace.a:app_trace.* *libapp_trace.a:app_trace_util.* *libc.a:creat.* *libc.a:isatty.* *libc.a:lib_a-abs.* *libc.a:lib_a-asctime.* *libc.a:lib_a-asctime_r.* *libc.a:lib_a-atoi.* *libc.a:lib_a-atol.* *libc.a:lib_a-bzero.* *libc.a:lib_a-close.* *libc.a:lib_a-creat.* *libc.a:lib_a-ctime.* *libc.a:lib_a-ctime_r.* *libc.a:lib_a-ctype_.* *libc.a:lib_a-div.* *libc.a:lib_a-environ.* *libc.a:lib_a-envlock.* *libc.a:lib_a-fclose.* *libc.a:lib_a-fflush.* *libc.a:lib_a-findfp.* *libc.a:lib_a-fputwc.* *libc.a:lib_a-fvwrite.* *libc.a:lib_a-fwalk.* *libc.a:lib_a-getenv_r.* *libc.a:lib_a-gettzinfo.* *libc.a:lib_a-gmtime.* *libc.a:lib_a-gmtime_r.* *libc.a:lib_a-impure.* *libc.a:lib_a-isalnum.* *libc.a:lib_a-isalpha.* *libc.a:lib_a-isascii.* *libc.a:lib_a-isblank.* *libc.a:lib_a-iscntrl.* *libc.a:lib_a-isdigit.* *libc.a:lib_a-isgraph.* *libc.a:lib_a-islower.* *libc.a:lib_a-isprint.* *libc.a:lib_a-ispunct.* *libc.a:lib_a-isspace.* *libc.a:lib_a-isupper.* *libc.a:lib_a-itoa.* *libc.a:lib_a-labs.* *libc.a:lib_a-lcltime.* *libc.a:lib_a-lcltime_r.* *libc.a:lib_a-ldiv.* *libc.a:lib_a-longjmp.* *libc.a:lib_a-makebuf.* *libc.a:lib_a-memccpy.* *libc.a:lib_a-memchr.* *libc.a:lib_a-memcmp.* *libc.a:lib_a-memcpy.* *libc.a:lib_a-memmove.* *libc.a:lib_a-memrchr.* *libc.a:lib_a-memset.* *libc.a:lib_a-mktime.* *libc.a:lib_a-month_lengths.* *libc.a:lib_a-open.* *libc.a:lib_a-quorem.* *libc.a:lib_a-raise.* *libc.a:lib_a-rand.* *libc.a:lib_a-rand_r.* *libc.a:lib_a-read.* *libc.a:lib_a-refill.* *libc.a:lib_a-rshift.* *libc.a:lib_a-s_fpclassify.* *libc.a:lib_a-sbrk.* *libc.a:lib_a-sccl.* *libc.a:lib_a-setjmp.* *libc.a:lib_a-sf_nan.* *libc.a:lib_a-srand.* *libc.a:lib_a-stdio.* *libc.a:lib_a-strcasecmp.* *libc.a:lib_a-strcasestr.* *libc.a:lib_a-strcat.* *libc.a:lib_a-strchr.* *libc.a:lib_a-strcmp.* *libc.a:lib_a-strcoll.* *libc.a:lib_a-strcpy.* *libc.a:lib_a-strcspn.* *libc.a:lib_a-strdup.* *libc.a:lib_a-strdup_r.* *libc.a:lib_a-strftime.* *libc.a:lib_a-strlcat.* *libc.a:lib_a-strlcpy.* *libc.a:lib_a-strlen.* *libc.a:lib_a-strlwr.* *libc.a:lib_a-strncasecmp.* *libc.a:lib_a-strncat.* *libc.a:lib_a-strncmp.* *libc.a:lib_a-strncpy.* *libc.a:lib_a-strndup.* *libc.a:lib_a-strndup_r.* *libc.a:lib_a-strnlen.* *libc.a:lib_a-strptime.* *libc.a:lib_a-strrchr.* *libc.a:lib_a-strsep.* *libc.a:lib_a-strspn.* *libc.a:lib_a-strstr.* *libc.a:lib_a-strtok_r.* *libc.a:lib_a-strtol.* *libc.a:lib_a-strtoul.* *libc.a:lib_a-strupr.* *libc.a:lib_a-sysclose.* *libc.a:lib_a-sysopen.* *libc.a:lib_a-sysread.* *libc.a:lib_a-syssbrk.* *libc.a:lib_a-system.* *libc.a:lib_a-systimes.* *libc.a:lib_a-syswrite.* *libc.a:lib_a-time.* *libc.a:lib_a-timelocal.* *libc.a:lib_a-toascii.* *libc.a:lib_a-tolower.* *libc.a:lib_a-toupper.* *libc.a:lib_a-tzcalc_limits.* *libc.a:lib_a-tzlock.* *libc.a:lib_a-tzset.* *libc.a:lib_a-tzset_r.* *libc.a:lib_a-tzvars.* *libc.a:lib_a-ungetc.* *libc.a:lib_a-utoa.* *libc.a:lib_a-wbuf.* *libc.a:lib_a-wcrtomb.* *libc.a:lib_a-wctomb_r.* *libc.a:lib_a-wsetup.* *libc.a:lock.* *libesp_event.a:default_event_loop.* *libesp_event.a:esp_event.* *libesp_hw_support.a:cpu_util.* *libesp_hw_support.a:rtc_clk.* *libesp_hw_support.a:rtc_init.* *libesp_hw_support.a:rtc_pm.* *libesp_hw_support.a:rtc_sleep.* *libesp_hw_support.a:rtc_time.* *libesp_hw_support.a:rtc_wdt.* *libesp_system.a:esp_err.* *libesp_system.a:esp_system.* *libesp_system.a:ubsan.* *libgcc.a:lib2funcs.* *libhal.a:cpu_hal.* *libhal.a:i2c_hal_iram.* *libhal.a:ledc_hal_iram.* *libhal.a:soc_hal.* *libhal.a:spi_flash_encrypt_hal_iram.* *libhal.a:spi_flash_hal_iram.* *libhal.a:spi_hal_iram.* *libhal.a:spi_slave_hal_iram.* *libhal.a:wdt_hal_iram.* *libheap.a:heap_tlsf.* *libheap.a:multi_heap.* *libheap.a:multi_heap_poisoning.* *liblog.a:log.* *liblog.a:log_freertos.* *libnewlib.a:abort.* *libnewlib.a:assert.* *libnewlib.a:heap.* *libnewlib.a:stdatomic.* *libsoc.a:lldesc.* *libspi_flash.a:memspi_host_driver.* *libspi_flash.a:spi_flash_chip_gd.* *libspi_flash.a:spi_flash_chip_generic.* *libspi_flash.a:spi_flash_chip_issi.* *libspi_flash.a:spi_flash_chip_mxic.* *libspi_flash.a:spi_flash_chip_winbond.* *libspi_flash.a:spi_flash_rom_patch.* *libxtensa.a:eri.* *libxtensa.a:xtensa_intr_asm.*) .text.*) + *(EXCLUDE_FILE(*libesp_ringbuf.a *libfreertos.a *libgcov.a *librtc.a *libxt_hal.a *libapp_trace.a:app_trace.* *libapp_trace.a:app_trace_util.* *libc.a:creat.* *libc.a:isatty.* *libc.a:lib_a-abs.* *libc.a:lib_a-asctime.* *libc.a:lib_a-asctime_r.* *libc.a:lib_a-atoi.* *libc.a:lib_a-atol.* *libc.a:lib_a-bzero.* *libc.a:lib_a-close.* *libc.a:lib_a-creat.* *libc.a:lib_a-ctime.* *libc.a:lib_a-ctime_r.* *libc.a:lib_a-ctype_.* *libc.a:lib_a-div.* *libc.a:lib_a-environ.* *libc.a:lib_a-envlock.* *libc.a:lib_a-fclose.* *libc.a:lib_a-fflush.* *libc.a:lib_a-findfp.* *libc.a:lib_a-fputwc.* *libc.a:lib_a-fvwrite.* *libc.a:lib_a-fwalk.* *libc.a:lib_a-getenv_r.* *libc.a:lib_a-gettzinfo.* *libc.a:lib_a-gmtime.* *libc.a:lib_a-gmtime_r.* *libc.a:lib_a-impure.* *libc.a:lib_a-isalnum.* *libc.a:lib_a-isalpha.* *libc.a:lib_a-isascii.* *libc.a:lib_a-isblank.* *libc.a:lib_a-iscntrl.* *libc.a:lib_a-isdigit.* *libc.a:lib_a-isgraph.* *libc.a:lib_a-islower.* *libc.a:lib_a-isprint.* *libc.a:lib_a-ispunct.* *libc.a:lib_a-isspace.* *libc.a:lib_a-isupper.* *libc.a:lib_a-itoa.* *libc.a:lib_a-labs.* *libc.a:lib_a-lcltime.* *libc.a:lib_a-lcltime_r.* *libc.a:lib_a-ldiv.* *libc.a:lib_a-longjmp.* *libc.a:lib_a-makebuf.* *libc.a:lib_a-memccpy.* *libc.a:lib_a-memchr.* *libc.a:lib_a-memcmp.* *libc.a:lib_a-memcpy.* *libc.a:lib_a-memmove.* *libc.a:lib_a-memrchr.* *libc.a:lib_a-memset.* *libc.a:lib_a-mktime.* *libc.a:lib_a-month_lengths.* *libc.a:lib_a-open.* *libc.a:lib_a-quorem.* *libc.a:lib_a-raise.* *libc.a:lib_a-rand.* *libc.a:lib_a-rand_r.* *libc.a:lib_a-read.* *libc.a:lib_a-refill.* *libc.a:lib_a-rshift.* *libc.a:lib_a-s_fpclassify.* *libc.a:lib_a-sbrk.* *libc.a:lib_a-sccl.* *libc.a:lib_a-setjmp.* *libc.a:lib_a-sf_nan.* *libc.a:lib_a-srand.* *libc.a:lib_a-stdio.* *libc.a:lib_a-strcasecmp.* *libc.a:lib_a-strcasestr.* *libc.a:lib_a-strcat.* *libc.a:lib_a-strchr.* *libc.a:lib_a-strcmp.* *libc.a:lib_a-strcoll.* *libc.a:lib_a-strcpy.* *libc.a:lib_a-strcspn.* *libc.a:lib_a-strdup.* *libc.a:lib_a-strdup_r.* *libc.a:lib_a-strftime.* *libc.a:lib_a-strlcat.* *libc.a:lib_a-strlcpy.* *libc.a:lib_a-strlen.* *libc.a:lib_a-strlwr.* *libc.a:lib_a-strncasecmp.* *libc.a:lib_a-strncat.* *libc.a:lib_a-strncmp.* *libc.a:lib_a-strncpy.* *libc.a:lib_a-strndup.* *libc.a:lib_a-strndup_r.* *libc.a:lib_a-strnlen.* *libc.a:lib_a-strptime.* *libc.a:lib_a-strrchr.* *libc.a:lib_a-strsep.* *libc.a:lib_a-strspn.* *libc.a:lib_a-strstr.* *libc.a:lib_a-strtok_r.* *libc.a:lib_a-strtol.* *libc.a:lib_a-strtoul.* *libc.a:lib_a-strupr.* *libc.a:lib_a-sysclose.* *libc.a:lib_a-sysopen.* *libc.a:lib_a-sysread.* *libc.a:lib_a-syssbrk.* *libc.a:lib_a-system.* *libc.a:lib_a-systimes.* *libc.a:lib_a-syswrite.* *libc.a:lib_a-time.* *libc.a:lib_a-timelocal.* *libc.a:lib_a-toascii.* *libc.a:lib_a-tolower.* *libc.a:lib_a-toupper.* *libc.a:lib_a-tzcalc_limits.* *libc.a:lib_a-tzlock.* *libc.a:lib_a-tzset.* *libc.a:lib_a-tzset_r.* *libc.a:lib_a-tzvars.* *libc.a:lib_a-ungetc.* *libc.a:lib_a-utoa.* *libc.a:lib_a-wbuf.* *libc.a:lib_a-wcrtomb.* *libc.a:lib_a-wctomb_r.* *libc.a:lib_a-wsetup.* *libc.a:lock.* *libesp_event.a:default_event_loop.* *libesp_event.a:esp_event.* *libesp_hw_support.a:cpu_util.* *libesp_hw_support.a:rtc_clk.* *libesp_hw_support.a:rtc_init.* *libesp_hw_support.a:rtc_pm.* *libesp_hw_support.a:rtc_sleep.* *libesp_hw_support.a:rtc_time.* *libesp_hw_support.a:rtc_wdt.* *libesp_system.a:esp_err.* *libesp_system.a:esp_system.* *libesp_system.a:ubsan.* *libgcc.a:lib2funcs.* *libhal.a:cpu_hal.* *libhal.a:i2c_hal_iram.* *libhal.a:ledc_hal_iram.* *libhal.a:soc_hal.* *libhal.a:spi_flash_encrypt_hal_iram.* *libhal.a:spi_flash_hal_iram.* *libhal.a:spi_hal_iram.* *libhal.a:spi_slave_hal_iram.* *libhal.a:wdt_hal_iram.* *libheap.a:heap_tlsf.* *libheap.a:multi_heap.* *libheap.a:multi_heap_poisoning.* *liblog.a:log.* *liblog.a:log_freertos.* *libnewlib.a:abort.* *libnewlib.a:assert.* *libnewlib.a:heap.* *libnewlib.a:stdatomic.* *libsoc.a:lldesc.* *libspi_flash.a:memspi_host_driver.* *libspi_flash.a:spi_flash_chip_boya.* *libspi_flash.a:spi_flash_chip_gd.* *libspi_flash.a:spi_flash_chip_generic.* *libspi_flash.a:spi_flash_chip_issi.* *libspi_flash.a:spi_flash_chip_mxic.* *libspi_flash.a:spi_flash_chip_th.* *libspi_flash.a:spi_flash_chip_winbond.* *libspi_flash.a:spi_flash_rom_patch.* *libxtensa.a:eri.* *libxtensa.a:xtensa_intr_asm.*) .literal EXCLUDE_FILE(*libesp_ringbuf.a *libfreertos.a *libgcov.a *librtc.a *libxt_hal.a *libapp_trace.a:app_trace.* *libapp_trace.a:app_trace_util.* *libc.a:creat.* *libc.a:isatty.* *libc.a:lib_a-abs.* *libc.a:lib_a-asctime.* *libc.a:lib_a-asctime_r.* *libc.a:lib_a-atoi.* *libc.a:lib_a-atol.* *libc.a:lib_a-bzero.* *libc.a:lib_a-close.* *libc.a:lib_a-creat.* *libc.a:lib_a-ctime.* *libc.a:lib_a-ctime_r.* *libc.a:lib_a-ctype_.* *libc.a:lib_a-div.* *libc.a:lib_a-environ.* *libc.a:lib_a-envlock.* *libc.a:lib_a-fclose.* *libc.a:lib_a-fflush.* *libc.a:lib_a-findfp.* *libc.a:lib_a-fputwc.* *libc.a:lib_a-fvwrite.* *libc.a:lib_a-fwalk.* *libc.a:lib_a-getenv_r.* *libc.a:lib_a-gettzinfo.* *libc.a:lib_a-gmtime.* *libc.a:lib_a-gmtime_r.* *libc.a:lib_a-impure.* *libc.a:lib_a-isalnum.* *libc.a:lib_a-isalpha.* *libc.a:lib_a-isascii.* *libc.a:lib_a-isblank.* *libc.a:lib_a-iscntrl.* *libc.a:lib_a-isdigit.* *libc.a:lib_a-isgraph.* *libc.a:lib_a-islower.* *libc.a:lib_a-isprint.* *libc.a:lib_a-ispunct.* *libc.a:lib_a-isspace.* *libc.a:lib_a-isupper.* *libc.a:lib_a-itoa.* *libc.a:lib_a-labs.* *libc.a:lib_a-lcltime.* *libc.a:lib_a-lcltime_r.* *libc.a:lib_a-ldiv.* *libc.a:lib_a-longjmp.* *libc.a:lib_a-makebuf.* *libc.a:lib_a-memccpy.* *libc.a:lib_a-memchr.* *libc.a:lib_a-memcmp.* *libc.a:lib_a-memcpy.* *libc.a:lib_a-memmove.* *libc.a:lib_a-memrchr.* *libc.a:lib_a-memset.* *libc.a:lib_a-mktime.* *libc.a:lib_a-month_lengths.* *libc.a:lib_a-open.* *libc.a:lib_a-quorem.* *libc.a:lib_a-raise.* *libc.a:lib_a-rand.* *libc.a:lib_a-rand_r.* *libc.a:lib_a-read.* *libc.a:lib_a-refill.* *libc.a:lib_a-rshift.* *libc.a:lib_a-s_fpclassify.* *libc.a:lib_a-sbrk.* *libc.a:lib_a-sccl.* *libc.a:lib_a-setjmp.* *libc.a:lib_a-sf_nan.* *libc.a:lib_a-srand.* *libc.a:lib_a-stdio.* *libc.a:lib_a-strcasecmp.* *libc.a:lib_a-strcasestr.* *libc.a:lib_a-strcat.* *libc.a:lib_a-strchr.* *libc.a:lib_a-strcmp.* *libc.a:lib_a-strcoll.* *libc.a:lib_a-strcpy.* *libc.a:lib_a-strcspn.* *libc.a:lib_a-strdup.* *libc.a:lib_a-strdup_r.* *libc.a:lib_a-strftime.* *libc.a:lib_a-strlcat.* *libc.a:lib_a-strlcpy.* *libc.a:lib_a-strlen.* *libc.a:lib_a-strlwr.* *libc.a:lib_a-strncasecmp.* *libc.a:lib_a-strncat.* *libc.a:lib_a-strncmp.* *libc.a:lib_a-strncpy.* *libc.a:lib_a-strndup.* *libc.a:lib_a-strndup_r.* *libc.a:lib_a-strnlen.* *libc.a:lib_a-strptime.* *libc.a:lib_a-strrchr.* *libc.a:lib_a-strsep.* *libc.a:lib_a-strspn.* *libc.a:lib_a-strstr.* *libc.a:lib_a-strtok_r.* *libc.a:lib_a-strtol.* *libc.a:lib_a-strtoul.* *libc.a:lib_a-strupr.* *libc.a:lib_a-sysclose.* *libc.a:lib_a-sysopen.* *libc.a:lib_a-sysread.* *libc.a:lib_a-syssbrk.* *libc.a:lib_a-system.* *libc.a:lib_a-systimes.* *libc.a:lib_a-syswrite.* *libc.a:lib_a-time.* *libc.a:lib_a-timelocal.* *libc.a:lib_a-toascii.* *libc.a:lib_a-tolower.* *libc.a:lib_a-toupper.* *libc.a:lib_a-tzcalc_limits.* *libc.a:lib_a-tzlock.* *libc.a:lib_a-tzset.* *libc.a:lib_a-tzset_r.* *libc.a:lib_a-tzvars.* *libc.a:lib_a-ungetc.* *libc.a:lib_a-utoa.* *libc.a:lib_a-wbuf.* *libc.a:lib_a-wcrtomb.* *libc.a:lib_a-wctomb_r.* *libc.a:lib_a-wsetup.* *libc.a:lock.* *libesp_event.a:default_event_loop.* *libesp_event.a:esp_event.* *libesp_hw_support.a:cpu_util.* *libesp_hw_support.a:rtc_clk.* *libesp_hw_support.a:rtc_init.* *libesp_hw_support.a:rtc_pm.* *libesp_hw_support.a:rtc_sleep.* *libesp_hw_support.a:rtc_time.* *libesp_hw_support.a:rtc_wdt.* *libesp_system.a:esp_err.* *libesp_system.a:esp_system.* *libesp_system.a:ubsan.* *libgcc.a:lib2funcs.* *libhal.a:cpu_hal.* *libhal.a:i2c_hal_iram.* *libhal.a:ledc_hal_iram.* *libhal.a:soc_hal.* *libhal.a:spi_flash_encrypt_hal_iram.* *libhal.a:spi_flash_hal_iram.* *libhal.a:spi_hal_iram.* *libhal.a:spi_slave_hal_iram.* *libhal.a:wdt_hal_iram.* *libheap.a:heap_tlsf.* *libheap.a:multi_heap.* *libheap.a:multi_heap_poisoning.* *liblog.a:log.* *liblog.a:log_freertos.* *libnewlib.a:abort.* *libnewlib.a:assert.* *libnewlib.a:heap.* *libnewlib.a:stdatomic.* *libsoc.a:lldesc.* *libspi_flash.a:memspi_host_driver.* *libspi_flash.a:spi_flash_chip_boya.* *libspi_flash.a:spi_flash_chip_gd.* *libspi_flash.a:spi_flash_chip_generic.* *libspi_flash.a:spi_flash_chip_issi.* *libspi_flash.a:spi_flash_chip_mxic.* *libspi_flash.a:spi_flash_chip_th.* *libspi_flash.a:spi_flash_chip_winbond.* *libspi_flash.a:spi_flash_rom_patch.* *libxtensa.a:eri.* *libxtensa.a:xtensa_intr_asm.*) .literal.* EXCLUDE_FILE(*libesp_ringbuf.a *libfreertos.a *libgcov.a *librtc.a *libxt_hal.a *libapp_trace.a:app_trace.* *libapp_trace.a:app_trace_util.* *libc.a:creat.* *libc.a:isatty.* *libc.a:lib_a-abs.* *libc.a:lib_a-asctime.* *libc.a:lib_a-asctime_r.* *libc.a:lib_a-atoi.* *libc.a:lib_a-atol.* *libc.a:lib_a-bzero.* *libc.a:lib_a-close.* *libc.a:lib_a-creat.* *libc.a:lib_a-ctime.* *libc.a:lib_a-ctime_r.* *libc.a:lib_a-ctype_.* *libc.a:lib_a-div.* *libc.a:lib_a-environ.* *libc.a:lib_a-envlock.* *libc.a:lib_a-fclose.* *libc.a:lib_a-fflush.* *libc.a:lib_a-findfp.* *libc.a:lib_a-fputwc.* *libc.a:lib_a-fvwrite.* *libc.a:lib_a-fwalk.* *libc.a:lib_a-getenv_r.* *libc.a:lib_a-gettzinfo.* *libc.a:lib_a-gmtime.* *libc.a:lib_a-gmtime_r.* *libc.a:lib_a-impure.* *libc.a:lib_a-isalnum.* *libc.a:lib_a-isalpha.* *libc.a:lib_a-isascii.* *libc.a:lib_a-isblank.* *libc.a:lib_a-iscntrl.* *libc.a:lib_a-isdigit.* *libc.a:lib_a-isgraph.* *libc.a:lib_a-islower.* *libc.a:lib_a-isprint.* *libc.a:lib_a-ispunct.* *libc.a:lib_a-isspace.* *libc.a:lib_a-isupper.* *libc.a:lib_a-itoa.* *libc.a:lib_a-labs.* *libc.a:lib_a-lcltime.* *libc.a:lib_a-lcltime_r.* *libc.a:lib_a-ldiv.* *libc.a:lib_a-longjmp.* *libc.a:lib_a-makebuf.* *libc.a:lib_a-memccpy.* *libc.a:lib_a-memchr.* *libc.a:lib_a-memcmp.* *libc.a:lib_a-memcpy.* *libc.a:lib_a-memmove.* *libc.a:lib_a-memrchr.* *libc.a:lib_a-memset.* *libc.a:lib_a-mktime.* *libc.a:lib_a-month_lengths.* *libc.a:lib_a-open.* *libc.a:lib_a-quorem.* *libc.a:lib_a-raise.* *libc.a:lib_a-rand.* *libc.a:lib_a-rand_r.* *libc.a:lib_a-read.* *libc.a:lib_a-refill.* *libc.a:lib_a-rshift.* *libc.a:lib_a-s_fpclassify.* *libc.a:lib_a-sbrk.* *libc.a:lib_a-sccl.* *libc.a:lib_a-setjmp.* *libc.a:lib_a-sf_nan.* *libc.a:lib_a-srand.* *libc.a:lib_a-stdio.* *libc.a:lib_a-strcasecmp.* *libc.a:lib_a-strcasestr.* *libc.a:lib_a-strcat.* *libc.a:lib_a-strchr.* *libc.a:lib_a-strcmp.* *libc.a:lib_a-strcoll.* *libc.a:lib_a-strcpy.* *libc.a:lib_a-strcspn.* *libc.a:lib_a-strdup.* *libc.a:lib_a-strdup_r.* *libc.a:lib_a-strftime.* *libc.a:lib_a-strlcat.* *libc.a:lib_a-strlcpy.* *libc.a:lib_a-strlen.* *libc.a:lib_a-strlwr.* *libc.a:lib_a-strncasecmp.* *libc.a:lib_a-strncat.* *libc.a:lib_a-strncmp.* *libc.a:lib_a-strncpy.* *libc.a:lib_a-strndup.* *libc.a:lib_a-strndup_r.* *libc.a:lib_a-strnlen.* *libc.a:lib_a-strptime.* *libc.a:lib_a-strrchr.* *libc.a:lib_a-strsep.* *libc.a:lib_a-strspn.* *libc.a:lib_a-strstr.* *libc.a:lib_a-strtok_r.* *libc.a:lib_a-strtol.* *libc.a:lib_a-strtoul.* *libc.a:lib_a-strupr.* *libc.a:lib_a-sysclose.* *libc.a:lib_a-sysopen.* *libc.a:lib_a-sysread.* *libc.a:lib_a-syssbrk.* *libc.a:lib_a-system.* *libc.a:lib_a-systimes.* *libc.a:lib_a-syswrite.* *libc.a:lib_a-time.* *libc.a:lib_a-timelocal.* *libc.a:lib_a-toascii.* *libc.a:lib_a-tolower.* *libc.a:lib_a-toupper.* *libc.a:lib_a-tzcalc_limits.* *libc.a:lib_a-tzlock.* *libc.a:lib_a-tzset.* *libc.a:lib_a-tzset_r.* *libc.a:lib_a-tzvars.* *libc.a:lib_a-ungetc.* *libc.a:lib_a-utoa.* *libc.a:lib_a-wbuf.* *libc.a:lib_a-wcrtomb.* *libc.a:lib_a-wctomb_r.* *libc.a:lib_a-wsetup.* *libc.a:lock.* *libesp_event.a:default_event_loop.* *libesp_event.a:esp_event.* *libesp_hw_support.a:cpu_util.* *libesp_hw_support.a:rtc_clk.* *libesp_hw_support.a:rtc_init.* *libesp_hw_support.a:rtc_pm.* *libesp_hw_support.a:rtc_sleep.* *libesp_hw_support.a:rtc_time.* *libesp_hw_support.a:rtc_wdt.* *libesp_system.a:esp_err.* *libesp_system.a:esp_system.* *libesp_system.a:ubsan.* *libgcc.a:lib2funcs.* *libhal.a:cpu_hal.* *libhal.a:i2c_hal_iram.* *libhal.a:ledc_hal_iram.* *libhal.a:soc_hal.* *libhal.a:spi_flash_encrypt_hal_iram.* *libhal.a:spi_flash_hal_iram.* *libhal.a:spi_hal_iram.* *libhal.a:spi_slave_hal_iram.* *libhal.a:wdt_hal_iram.* *libheap.a:heap_tlsf.* *libheap.a:multi_heap.* *libheap.a:multi_heap_poisoning.* *liblog.a:log.* *liblog.a:log_freertos.* *libnewlib.a:abort.* *libnewlib.a:assert.* *libnewlib.a:heap.* *libnewlib.a:stdatomic.* *libsoc.a:lldesc.* *libspi_flash.a:memspi_host_driver.* *libspi_flash.a:spi_flash_chip_boya.* *libspi_flash.a:spi_flash_chip_gd.* *libspi_flash.a:spi_flash_chip_generic.* *libspi_flash.a:spi_flash_chip_issi.* *libspi_flash.a:spi_flash_chip_mxic.* *libspi_flash.a:spi_flash_chip_th.* *libspi_flash.a:spi_flash_chip_winbond.* *libspi_flash.a:spi_flash_rom_patch.* *libxtensa.a:eri.* *libxtensa.a:xtensa_intr_asm.*) .text EXCLUDE_FILE(*libesp_ringbuf.a *libfreertos.a *libgcov.a *librtc.a *libxt_hal.a *libapp_trace.a:app_trace.* *libapp_trace.a:app_trace_util.* *libc.a:creat.* *libc.a:isatty.* *libc.a:lib_a-abs.* *libc.a:lib_a-asctime.* *libc.a:lib_a-asctime_r.* *libc.a:lib_a-atoi.* *libc.a:lib_a-atol.* *libc.a:lib_a-bzero.* *libc.a:lib_a-close.* *libc.a:lib_a-creat.* *libc.a:lib_a-ctime.* *libc.a:lib_a-ctime_r.* *libc.a:lib_a-ctype_.* *libc.a:lib_a-div.* *libc.a:lib_a-environ.* *libc.a:lib_a-envlock.* *libc.a:lib_a-fclose.* *libc.a:lib_a-fflush.* *libc.a:lib_a-findfp.* *libc.a:lib_a-fputwc.* *libc.a:lib_a-fvwrite.* *libc.a:lib_a-fwalk.* *libc.a:lib_a-getenv_r.* *libc.a:lib_a-gettzinfo.* *libc.a:lib_a-gmtime.* *libc.a:lib_a-gmtime_r.* *libc.a:lib_a-impure.* *libc.a:lib_a-isalnum.* *libc.a:lib_a-isalpha.* *libc.a:lib_a-isascii.* *libc.a:lib_a-isblank.* *libc.a:lib_a-iscntrl.* *libc.a:lib_a-isdigit.* *libc.a:lib_a-isgraph.* *libc.a:lib_a-islower.* *libc.a:lib_a-isprint.* *libc.a:lib_a-ispunct.* *libc.a:lib_a-isspace.* *libc.a:lib_a-isupper.* *libc.a:lib_a-itoa.* *libc.a:lib_a-labs.* *libc.a:lib_a-lcltime.* *libc.a:lib_a-lcltime_r.* *libc.a:lib_a-ldiv.* *libc.a:lib_a-longjmp.* *libc.a:lib_a-makebuf.* *libc.a:lib_a-memccpy.* *libc.a:lib_a-memchr.* *libc.a:lib_a-memcmp.* *libc.a:lib_a-memcpy.* *libc.a:lib_a-memmove.* *libc.a:lib_a-memrchr.* *libc.a:lib_a-memset.* *libc.a:lib_a-mktime.* *libc.a:lib_a-month_lengths.* *libc.a:lib_a-open.* *libc.a:lib_a-quorem.* *libc.a:lib_a-raise.* *libc.a:lib_a-rand.* *libc.a:lib_a-rand_r.* *libc.a:lib_a-read.* *libc.a:lib_a-refill.* *libc.a:lib_a-rshift.* *libc.a:lib_a-s_fpclassify.* *libc.a:lib_a-sbrk.* *libc.a:lib_a-sccl.* *libc.a:lib_a-setjmp.* *libc.a:lib_a-sf_nan.* *libc.a:lib_a-srand.* *libc.a:lib_a-stdio.* *libc.a:lib_a-strcasecmp.* *libc.a:lib_a-strcasestr.* *libc.a:lib_a-strcat.* *libc.a:lib_a-strchr.* *libc.a:lib_a-strcmp.* *libc.a:lib_a-strcoll.* *libc.a:lib_a-strcpy.* *libc.a:lib_a-strcspn.* *libc.a:lib_a-strdup.* *libc.a:lib_a-strdup_r.* *libc.a:lib_a-strftime.* *libc.a:lib_a-strlcat.* *libc.a:lib_a-strlcpy.* *libc.a:lib_a-strlen.* *libc.a:lib_a-strlwr.* *libc.a:lib_a-strncasecmp.* *libc.a:lib_a-strncat.* *libc.a:lib_a-strncmp.* *libc.a:lib_a-strncpy.* *libc.a:lib_a-strndup.* *libc.a:lib_a-strndup_r.* *libc.a:lib_a-strnlen.* *libc.a:lib_a-strptime.* *libc.a:lib_a-strrchr.* *libc.a:lib_a-strsep.* *libc.a:lib_a-strspn.* *libc.a:lib_a-strstr.* *libc.a:lib_a-strtok_r.* *libc.a:lib_a-strtol.* *libc.a:lib_a-strtoul.* *libc.a:lib_a-strupr.* *libc.a:lib_a-sysclose.* *libc.a:lib_a-sysopen.* *libc.a:lib_a-sysread.* *libc.a:lib_a-syssbrk.* *libc.a:lib_a-system.* *libc.a:lib_a-systimes.* *libc.a:lib_a-syswrite.* *libc.a:lib_a-time.* *libc.a:lib_a-timelocal.* *libc.a:lib_a-toascii.* *libc.a:lib_a-tolower.* *libc.a:lib_a-toupper.* *libc.a:lib_a-tzcalc_limits.* *libc.a:lib_a-tzlock.* *libc.a:lib_a-tzset.* *libc.a:lib_a-tzset_r.* *libc.a:lib_a-tzvars.* *libc.a:lib_a-ungetc.* *libc.a:lib_a-utoa.* *libc.a:lib_a-wbuf.* *libc.a:lib_a-wcrtomb.* *libc.a:lib_a-wctomb_r.* *libc.a:lib_a-wsetup.* *libc.a:lock.* *libesp_event.a:default_event_loop.* *libesp_event.a:esp_event.* *libesp_hw_support.a:cpu_util.* *libesp_hw_support.a:rtc_clk.* *libesp_hw_support.a:rtc_init.* *libesp_hw_support.a:rtc_pm.* *libesp_hw_support.a:rtc_sleep.* *libesp_hw_support.a:rtc_time.* *libesp_hw_support.a:rtc_wdt.* *libesp_system.a:esp_err.* *libesp_system.a:esp_system.* *libesp_system.a:ubsan.* *libgcc.a:lib2funcs.* *libhal.a:cpu_hal.* *libhal.a:i2c_hal_iram.* *libhal.a:ledc_hal_iram.* *libhal.a:soc_hal.* *libhal.a:spi_flash_encrypt_hal_iram.* *libhal.a:spi_flash_hal_iram.* *libhal.a:spi_hal_iram.* *libhal.a:spi_slave_hal_iram.* *libhal.a:wdt_hal_iram.* *libheap.a:heap_tlsf.* *libheap.a:multi_heap.* *libheap.a:multi_heap_poisoning.* *liblog.a:log.* *liblog.a:log_freertos.* *libnewlib.a:abort.* *libnewlib.a:assert.* *libnewlib.a:heap.* *libnewlib.a:stdatomic.* *libsoc.a:lldesc.* *libspi_flash.a:memspi_host_driver.* *libspi_flash.a:spi_flash_chip_boya.* *libspi_flash.a:spi_flash_chip_gd.* *libspi_flash.a:spi_flash_chip_generic.* *libspi_flash.a:spi_flash_chip_issi.* *libspi_flash.a:spi_flash_chip_mxic.* *libspi_flash.a:spi_flash_chip_th.* *libspi_flash.a:spi_flash_chip_winbond.* *libspi_flash.a:spi_flash_rom_patch.* *libxtensa.a:eri.* *libxtensa.a:xtensa_intr_asm.*) .text.*) *(.wifi0iram .wifi0iram.*) *(.wifiorslpiram .wifiorslpiram.*) *(.wifirxiram .wifirxiram.*) @@ -768,7 +772,7 @@ SECTIONS *(.iram.data .iram.data.*) _coredump_iram_start = ABSOLUTE(.); - *(.iram.data.coredump .iram.data.coredump.*) + *(.iram2.coredump .iram2.coredump.*) _coredump_iram_end = ABSOLUTE(.); _iram_data_end = ABSOLUTE(.); diff --git a/tools/sdk/esp32/sdkconfig b/tools/sdk/esp32/sdkconfig index 89a757a8462..990eab05e48 100644 --- a/tools/sdk/esp32/sdkconfig +++ b/tools/sdk/esp32/sdkconfig @@ -128,23 +128,20 @@ CONFIG_PARTITION_TABLE_OFFSET=0x8000 CONFIG_PARTITION_TABLE_MD5=y # end of Partition Table +CONFIG_LIB_BUILDER_FLASHMODE="dio" +CONFIG_LIB_BUILDER_FLASHFREQ="40m" + # # ESP RainMaker Config # +# CONFIG_ESP_RMAKER_NO_CLAIM is not set CONFIG_ESP_RMAKER_ASSISTED_CLAIM=y +CONFIG_ESP_RMAKER_CLAIM_TYPE=2 CONFIG_ESP_RMAKER_MQTT_HOST="a1p72mufdu6064-ats.iot.us-east-1.amazonaws.com" -CONFIG_ESP_RMAKER_TASK_STACK=4096 -CONFIG_ESP_RMAKER_TASK_PRIORITY=5 -CONFIG_ESP_RMAKER_MAX_NODE_CONFIG_SIZE=2048 CONFIG_ESP_RMAKER_MAX_PARAM_DATA_SIZE=1024 -CONFIG_ESP_RMAKER_FACTORY_PARTITION_NAME="fctry" -# CONFIG_RMAKER_MQTT_PERSISTENT_SESSION is not set -CONFIG_ESP_RMAKER_MQTT_PORT_443=y -# CONFIG_ESP_RMAKER_MQTT_PORT_8883 is not set -CONFIG_ESP_RMAKER_MQTT_PORT=1 -CONFIG_ESP_RMAKER_DEF_TIMEZONE="" -CONFIG_ESP_RMAKER_SNTP_SERVER_NAME="pool.ntp.org" # CONFIG_ESP_RMAKER_DISABLE_USER_MAPPING_PROV is not set +# CONFIG_ESP_RMAKER_USER_ID_CHECK is not set +# CONFIG_ESP_RMAKER_LOCAL_CTRL_ENABLE is not set CONFIG_ESP_RMAKER_CONSOLE_UART_NUM_0=y # CONFIG_ESP_RMAKER_CONSOLE_UART_NUM_1 is not set CONFIG_ESP_RMAKER_CONSOLE_UART_NUM=0 @@ -157,13 +154,21 @@ CONFIG_ESP_RMAKER_OTA_AUTOFETCH_PERIOD=0 # CONFIG_ESP_RMAKER_SKIP_COMMON_NAME_CHECK is not set # CONFIG_ESP_RMAKER_SKIP_VERSION_CHECK is not set # CONFIG_ESP_RMAKER_SKIP_PROJECT_NAME_CHECK is not set +CONFIG_ESP_RMAKER_OTA_HTTP_RX_BUFFER_SIZE=1024 # end of ESP RainMaker OTA Config # # ESP RainMaker Scheduling # -CONFIG_ESP_RMAKER_SCHEDULING_MAX_SCHEDULES=5 +CONFIG_ESP_RMAKER_SCHEDULING_MAX_SCHEDULES=10 # end of ESP RainMaker Scheduling + +# +# ESP RainMaker Scenes +# +CONFIG_ESP_RMAKER_SCENES_MAX_SCENES=10 +# CONFIG_ESP_RMAKER_SCENES_DEACTIVATE_SUPPORT is not set +# end of ESP RainMaker Scenes # end of ESP RainMaker Config # @@ -180,11 +185,11 @@ CONFIG_ARDUINO_LOOP_STACK_SIZE=8192 CONFIG_ARDUINO_EVENT_RUN_CORE1=y # CONFIG_ARDUINO_EVENT_RUN_NO_AFFINITY is not set CONFIG_ARDUINO_EVENT_RUNNING_CORE=1 -# CONFIG_ARDUINO_UDP_RUN_CORE0 is not set -CONFIG_ARDUINO_UDP_RUN_CORE1=y +CONFIG_ARDUINO_UDP_RUN_CORE0=y +# CONFIG_ARDUINO_UDP_RUN_CORE1 is not set # CONFIG_ARDUINO_UDP_RUN_NO_AFFINITY is not set CONFIG_ARDUINO_UDP_TASK_PRIORITY=3 -CONFIG_ARDUINO_UDP_RUNNING_CORE=1 +CONFIG_ARDUINO_UDP_RUNNING_CORE=0 # CONFIG_ARDUINO_ISR_IRAM is not set # CONFIG_DISABLE_HAL_LOCKS is not set @@ -217,6 +222,18 @@ CONFIG_ARDUHAL_PARTITION_SCHEME="default" # # end of Arduino TinyUSB +# +# ESP Speech Recognition +# +# CONFIG_USE_WAKENET is not set +# CONFIG_USE_MULTINET is not set + +# +# Add speech commands +# +# end of Add speech commands +# end of ESP Speech Recognition + # # Compiler options # @@ -436,6 +453,13 @@ CONFIG_SPI_SLAVE_ISR_IN_IRAM=y # # CONFIG_GPIO_ESP32_SUPPORT_SWITCH_SLP_PULL is not set # end of GPIO Configuration + +# +# GDMA Configuration +# +# CONFIG_GDMA_CTRL_FUNC_IN_IRAM is not set +# CONFIG_GDMA_ISR_IRAM_SAFE is not set +# end of GDMA Configuration # end of Driver configurations # @@ -644,7 +668,7 @@ CONFIG_ESP_HTTP_CLIENT_ENABLE_DIGEST_AUTH=y # # HTTP Server # -CONFIG_HTTPD_MAX_REQ_HDR_LEN=512 +CONFIG_HTTPD_MAX_REQ_HDR_LEN=1024 CONFIG_HTTPD_MAX_URI_LEN=512 CONFIG_HTTPD_ERR_RESP_NO_DELAY=y CONFIG_HTTPD_PURGE_BUF_LEN=32 @@ -688,6 +712,11 @@ CONFIG_ESP_SLEEP_RTC_BUS_ISO_WORKAROUND=y # CONFIG_ESP_SLEEP_PSRAM_LEAKAGE_WORKAROUND is not set # CONFIG_ESP_SLEEP_FLASH_LEAKAGE_WORKAROUND is not set # end of Sleep Config + +# +# RTC Clock Config +# +# end of RTC Clock Config # end of Hardware Settings # @@ -772,6 +801,7 @@ CONFIG_ESP_TASK_WDT_TIMEOUT_S=5 CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=y # CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 is not set # CONFIG_ESP_PANIC_HANDLER_IRAM is not set +# CONFIG_ESP_DEBUG_STUBS_ENABLE is not set CONFIG_ESP_SYSTEM_CHECK_INT_LEVEL_5=y # end of ESP System Settings @@ -975,7 +1005,6 @@ CONFIG_HEAP_TRACING_OFF=y # # libsodium # -CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y # end of libsodium # @@ -1152,9 +1181,24 @@ CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC=y # CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC is not set CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=16384 # CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN is not set -# CONFIG_MBEDTLS_DYNAMIC_BUFFER is not set # CONFIG_MBEDTLS_DEBUG is not set +# +# mbedTLS v2.28.x related +# +# CONFIG_MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH is not set +# CONFIG_MBEDTLS_X509_TRUSTED_CERT_CALLBACK is not set +# CONFIG_MBEDTLS_SSL_CONTEXT_SERIALIZATION is not set +CONFIG_MBEDTLS_SSL_KEEP_PEER_CERTIFICATE=y + +# +# DTLS-based configurations +# +# CONFIG_MBEDTLS_SSL_DTLS_CONNECTION_ID is not set +# CONFIG_MBEDTLS_SSL_DTLS_SRTP is not set +# end of DTLS-based configurations +# end of mbedTLS v2.28.x related + # # Certificate Bundle # @@ -1169,7 +1213,7 @@ CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL=y # CONFIG_MBEDTLS_CMAC_C is not set CONFIG_MBEDTLS_HARDWARE_AES=y CONFIG_MBEDTLS_HARDWARE_MPI=y -# CONFIG_MBEDTLS_HARDWARE_SHA is not set +CONFIG_MBEDTLS_HARDWARE_SHA=y CONFIG_MBEDTLS_ROM_MD5=y # CONFIG_MBEDTLS_ATCA_HW_ECDSA_SIGN is not set # CONFIG_MBEDTLS_ATCA_HW_ECDSA_VERIFY is not set @@ -1371,6 +1415,8 @@ CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=y CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=y CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=y CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=y +# CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP is not set +# CONFIG_SPI_FLASH_SUPPORT_TH_CHIP is not set # end of Auto-detect flash chips CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=y @@ -1487,6 +1533,32 @@ CONFIG_WPA_MBEDTLS_CRYPTO=y CONFIG_IO_GLITCH_FILTER_TIME_MS=50 # end of Button +# +# ESP RainMaker Common +# +CONFIG_ESP_RMAKER_LIB_ESP_MQTT=y +# CONFIG_ESP_RMAKER_LIB_AWS_IOT is not set +CONFIG_ESP_RMAKER_MQTT_GLUE_LIB=1 +CONFIG_ESP_RMAKER_MQTT_PORT_443=y +# CONFIG_ESP_RMAKER_MQTT_PORT_8883 is not set +CONFIG_ESP_RMAKER_MQTT_PORT=1 +# CONFIG_ESP_RMAKER_MQTT_PERSISTENT_SESSION is not set +CONFIG_ESP_RMAKER_MQTT_SEND_USERNAME=y +CONFIG_ESP_RMAKER_MQTT_USERNAME="?Platform=APN/1 ESPIF,RAINMAKER,v1.0" +CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK=4096 +CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_PRIORITY=5 +CONFIG_ESP_RMAKER_FACTORY_PARTITION_NAME="fctry" +CONFIG_ESP_RMAKER_FACTORY_NAMESPACE="rmaker_creds" +CONFIG_ESP_RMAKER_DEF_TIMEZONE="Asia/Shanghai" +CONFIG_ESP_RMAKER_SNTP_SERVER_NAME="pool.ntp.org" +# end of ESP RainMaker Common + +# +# WS2812 RGB LED +# +# CONFIG_WS2812_LED_ENABLE is not set +# end of WS2812 RGB LED + # # DSP Library # @@ -1516,8 +1588,11 @@ CONFIG_OV5640_SUPPORT=y CONFIG_GC2145_SUPPORT=y CONFIG_GC032A_SUPPORT=y CONFIG_GC0308_SUPPORT=y +CONFIG_BF3005_SUPPORT=y +CONFIG_BF20A6_SUPPORT=y # CONFIG_SCCB_HARDWARE_I2C_PORT0 is not set CONFIG_SCCB_HARDWARE_I2C_PORT1=y +CONFIG_SCCB_CLK_FREQ=100000 # CONFIG_GC_SENSOR_WINDOWING_MODE is not set CONFIG_GC_SENSOR_SUBSAMPLE_MODE=y CONFIG_CAMERA_CORE0=y @@ -1543,6 +1618,7 @@ CONFIG_LITTLEFS_USE_MTIME=y CONFIG_LITTLEFS_MTIME_USE_SECONDS=y # CONFIG_LITTLEFS_MTIME_USE_NONCE is not set # CONFIG_LITTLEFS_SPIFFS_COMPAT is not set +# CONFIG_LITTLEFS_FLUSH_FILE_EVERY_WRITE is not set # end of LittleFS # end of Component config @@ -1701,6 +1777,7 @@ CONFIG_TASK_WDT_PANIC=y CONFIG_TASK_WDT_TIMEOUT_S=5 CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0=y # CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1 is not set +# CONFIG_ESP32_DEBUG_STUBS_ENABLE is not set CONFIG_TIMER_TASK_STACK_SIZE=4096 CONFIG_SW_COEXIST_ENABLE=y # CONFIG_ESP32_ENABLE_COREDUMP_TO_FLASH is not set diff --git a/tools/sdk/esp32c3/bin/bootloader_dio_40m.bin b/tools/sdk/esp32c3/bin/bootloader_dio_40m.bin index 43c0ae0dbe6..f665a4a4922 100644 Binary files a/tools/sdk/esp32c3/bin/bootloader_dio_40m.bin and b/tools/sdk/esp32c3/bin/bootloader_dio_40m.bin differ diff --git a/tools/sdk/esp32c3/bin/bootloader_dio_80m.bin b/tools/sdk/esp32c3/bin/bootloader_dio_80m.bin index b45224a6717..c5a299b713d 100644 Binary files a/tools/sdk/esp32c3/bin/bootloader_dio_80m.bin and b/tools/sdk/esp32c3/bin/bootloader_dio_80m.bin differ diff --git a/tools/sdk/esp32c3/bin/bootloader_dout_40m.bin b/tools/sdk/esp32c3/bin/bootloader_dout_40m.bin index 295483bda5e..5ee9c3c6a15 100644 Binary files a/tools/sdk/esp32c3/bin/bootloader_dout_40m.bin and b/tools/sdk/esp32c3/bin/bootloader_dout_40m.bin differ diff --git a/tools/sdk/esp32c3/bin/bootloader_dout_80m.bin b/tools/sdk/esp32c3/bin/bootloader_dout_80m.bin index 0dc8cd77d92..17fc6893202 100644 Binary files a/tools/sdk/esp32c3/bin/bootloader_dout_80m.bin and b/tools/sdk/esp32c3/bin/bootloader_dout_80m.bin differ diff --git a/tools/sdk/esp32c3/bin/bootloader_qio_40m.bin b/tools/sdk/esp32c3/bin/bootloader_qio_40m.bin index 68436175ca9..aa7d259ab22 100644 Binary files a/tools/sdk/esp32c3/bin/bootloader_qio_40m.bin and b/tools/sdk/esp32c3/bin/bootloader_qio_40m.bin differ diff --git a/tools/sdk/esp32c3/bin/bootloader_qio_80m.bin b/tools/sdk/esp32c3/bin/bootloader_qio_80m.bin index f00c99359c6..68e44ed0ef8 100644 Binary files a/tools/sdk/esp32c3/bin/bootloader_qio_80m.bin and b/tools/sdk/esp32c3/bin/bootloader_qio_80m.bin differ diff --git a/tools/sdk/esp32c3/bin/bootloader_qout_40m.bin b/tools/sdk/esp32c3/bin/bootloader_qout_40m.bin index 2c937b5ebc9..497d795af1c 100644 Binary files a/tools/sdk/esp32c3/bin/bootloader_qout_40m.bin and b/tools/sdk/esp32c3/bin/bootloader_qout_40m.bin differ diff --git a/tools/sdk/esp32c3/bin/bootloader_qout_80m.bin b/tools/sdk/esp32c3/bin/bootloader_qout_80m.bin index de08fd6a52c..637df8c52c3 100644 Binary files a/tools/sdk/esp32c3/bin/bootloader_qout_80m.bin and b/tools/sdk/esp32c3/bin/bootloader_qout_80m.bin differ diff --git a/tools/sdk/esp32c3/include/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h b/tools/sdk/esp32c3/include/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h index 73c8605e078..285cbb028cf 100644 --- a/tools/sdk/esp32c3/include/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h +++ b/tools/sdk/esp32c3/include/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h @@ -236,7 +236,7 @@ typedef enum { #define ESP_BT_GAP_MIN_INQ_LEN (0x01) /*!< Minimum inquiry duration, unit is 1.28s */ #define ESP_BT_GAP_MAX_INQ_LEN (0x30) /*!< Maximum inquiry duration, unit is 1.28s */ -/// A2DP state callback parameters +/// GAP state callback parameters typedef union { /** * @brief ESP_BT_GAP_DISC_RES_EVT diff --git a/tools/sdk/esp32c3/include/bt/host/bluedroid/api/include/api/esp_hf_client_api.h b/tools/sdk/esp32c3/include/bt/host/bluedroid/api/include/api/esp_hf_client_api.h index 3c5c05b178c..55569bc5c84 100644 --- a/tools/sdk/esp32c3/include/bt/host/bluedroid/api/include/api/esp_hf_client_api.h +++ b/tools/sdk/esp32c3/include/bt/host/bluedroid/api/include/api/esp_hf_client_api.h @@ -60,6 +60,9 @@ typedef enum { #define ESP_HF_CLIENT_PEER_FEAT_ECC 0x80 /* Enhanced Call Control */ #define ESP_HF_CLIENT_PEER_FEAT_EXTERR 0x100 /* Extended error codes */ #define ESP_HF_CLIENT_PEER_FEAT_CODEC 0x200 /* Codec Negotiation */ +/* HFP 1.7+ */ +#define ESP_HF_CLIENT_PEER_FEAT_HF_IND 0x400 /* HF Indicators */ +#define ESP_HF_CLIENT_PEER_FEAT_ESCO_S4 0x800 /* eSCO S4 Setting Supported */ /* CHLD feature masks of AG */ #define ESP_HF_CLIENT_CHLD_FEAT_REL 0x01 /* 0 Release waiting call or held calls */ diff --git a/tools/sdk/esp32c3/include/bt/include/esp32c3/include/esp_bt.h b/tools/sdk/esp32c3/include/bt/include/esp32c3/include/esp_bt.h index 0e13ee90fa2..2c1af6580e4 100644 --- a/tools/sdk/esp32c3/include/bt/include/esp32c3/include/esp_bt.h +++ b/tools/sdk/esp32c3/include/bt/include/esp32c3/include/esp_bt.h @@ -18,7 +18,7 @@ extern "C" { #endif #define ESP_BT_CTRL_CONFIG_MAGIC_VAL 0x5A5AA5A5 -#define ESP_BT_CTRL_CONFIG_VERSION 0x02104270 +#define ESP_BT_CTRL_CONFIG_VERSION 0x02112280 #define ESP_BT_HCI_TL_MAGIC_VALUE 0xfadebead #define ESP_BT_HCI_TL_VERSION 0x00010000 @@ -178,6 +178,7 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status); .hw_target_code = BLE_HW_TARGET_CODE_ESP32C3_CHIP_ECO0, \ .slave_ce_len_min = SLAVE_CE_LEN_MIN_DEFAULT, \ .hw_recorrect_en = AGC_RECORRECT_EN, \ + .cca_thresh = CONFIG_BT_CTRL_HW_CCA_VAL, \ }; #else @@ -244,6 +245,7 @@ typedef struct { uint32_t hw_target_code; /*!< hardware target */ uint8_t slave_ce_len_min; uint8_t hw_recorrect_en; + uint8_t cca_thresh; /*!< cca threshold*/ } esp_bt_controller_config_t; /** diff --git a/tools/sdk/esp32c3/include/button/button/include/iot_button.h b/tools/sdk/esp32c3/include/button/button/include/iot_button.h new file mode 100644 index 00000000000..3e735133464 --- /dev/null +++ b/tools/sdk/esp32c3/include/button/button/include/iot_button.h @@ -0,0 +1,272 @@ +// Copyright 2020 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +#ifndef _IOT_BUTTON_H_ +#define _IOT_BUTTON_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +typedef void (* button_cb)(void*); +typedef void* button_handle_t; + +typedef enum { + BUTTON_ACTIVE_HIGH = 1, /*!