From 96f8f5e3efe9d4ae1bb92b585059f1b4dfbcee98 Mon Sep 17 00:00:00 2001 From: Abdelatif Guettouche Date: Thu, 10 Mar 2022 13:45:26 +0100 Subject: [PATCH 01/11] Add initial hardware testing support (#6313) - Added workflow triggered by cron or label "hil_test" - Added examples with both pytest and unity --- .github/scripts/on-push.sh | 4 +- .github/scripts/sketch_utils.sh | 10 +-- .github/scripts/tests_build.sh | 56 ++++++++++++ .github/scripts/tests_run.sh | 71 +++++++++++++++ .github/workflows/hil.yml | 120 ++++++++++++++++++++++++++ .github/workflows/publish.yml | 38 ++++++++ .gitignore | 3 + tests/.gitignore | 2 + tests/hello_world/hello_world.ino | 12 +++ tests/hello_world/test_hello_world.py | 2 + tests/pytest.ini | 13 +++ tests/requirements.txt | 13 +++ tests/unity/test_unity.py | 2 + tests/unity/unity.ino | 33 +++++++ 14 files changed, 372 insertions(+), 7 deletions(-) create mode 100755 .github/scripts/tests_build.sh create mode 100755 .github/scripts/tests_run.sh create mode 100644 .github/workflows/hil.yml create mode 100644 .github/workflows/publish.yml create mode 100644 tests/.gitignore create mode 100644 tests/hello_world/hello_world.ino create mode 100644 tests/hello_world/test_hello_world.py create mode 100644 tests/pytest.ini create mode 100644 tests/requirements.txt create mode 100644 tests/unity/test_unity.py create mode 100644 tests/unity/unity.ino diff --git a/.github/scripts/on-push.sh b/.github/scripts/on-push.sh index 5d8ffe9cd3e..6e92b9be88f 100755 --- a/.github/scripts/on-push.sh +++ b/.github/scripts/on-push.sh @@ -58,7 +58,7 @@ fi SCRIPTS_DIR="./.github/scripts" if [ "$BUILD_PIO" -eq 0 ]; then - source ./.github/scripts/install-arduino-ide.sh + source ${SCRIPTS_DIR}/install-arduino-ide.sh source ${SCRIPTS_DIR}/install-arduino-core-esp32.sh FQBN_ESP32="espressif:esp32:esp32:PSRAM=enabled,PartitionScheme=huge_app" @@ -80,7 +80,7 @@ if [ "$BUILD_PIO" -eq 0 ]; then build "esp32s2" $FQBN_ESP32S2 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32XX build "esp32c3" $FQBN_ESP32C3 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32XX else - source ./${SCRIPTS_DIR}/install-platformio-esp32.sh + source ${SCRIPTS_DIR}/install-platformio-esp32.sh # PlatformIO ESP32 Test BOARD="esp32dev" OPTIONS="board_build.partitions = huge_app.csv" diff --git a/.github/scripts/sketch_utils.sh b/.github/scripts/sketch_utils.sh index abc6a0476e5..d8e4aead5a4 100755 --- a/.github/scripts/sketch_utils.sh +++ b/.github/scripts/sketch_utils.sh @@ -32,13 +32,13 @@ function build_sketch(){ # build_sketch +function count_sketches(){ # count_sketches [target] local path=$1 local target=$2 - if [ $# -lt 2 ]; then + if [ $# -lt 1 ]; then echo "ERROR: Illegal number of parameters" - echo "USAGE: ${0} count " + echo "USAGE: ${0} count [target]" fi rm -rf sketches.txt @@ -47,7 +47,7 @@ function count_sketches(){ # count_sketches return 0 fi - local sketches=$(find $path -name *.ino) + local sketches=$(find $path -name *.ino | sort) local sketchnum=0 for sketch in $sketches; do local sketchdir=$(dirname $sketch) @@ -55,7 +55,7 @@ function count_sketches(){ # count_sketches local sketchname=$(basename $sketch) if [[ "$sketchdirname.ino" != "$sketchname" ]]; then continue - elif [[ -f "$sketchdir/.skip.$target" ]]; then + elif [[ -n $target ]] && [[ -f "$sketchdir/.skip.$target" ]]; then continue else echo $sketch >> sketches.txt diff --git a/.github/scripts/tests_build.sh b/.github/scripts/tests_build.sh new file mode 100755 index 00000000000..6de547d371b --- /dev/null +++ b/.github/scripts/tests_build.sh @@ -0,0 +1,56 @@ +#!/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" + ;; +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/workflows/hil.yml b/.github/workflows/hil.yml new file mode 100644 index 00000000000..b55e686c58e --- /dev/null +++ b/.github/workflows/hil.yml @@ -0,0 +1,120 @@ +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', '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 + strategy: + fail-fast: false + matrix: + chip: ['esp32', 'esp32s2', '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: Check Artifacts + run: | + ls -R tests + cat tests/*/build/build.options.json + + - 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" + 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..686ce2f2380 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,38 @@ +name: Unit Test Results + +on: + workflow_run: + workflows: [Run tests in hardware] + + types: + - completed + +jobs: + debug: + name: Debug + runs-on: ubuntu-latest + + steps: + - name: Debug Action + uses: hmarr/debug-action@v2.0.0 + + unit-test-results: + name: Unit Test Results + runs-on: ubuntu-latest + 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 diff --git a/.gitignore b/.gitignore index 5114d19da5c..df9c98da7a5 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ boards.sloeber.txt # Ignore docs build (Sphinx) docs/build docs/source/_build + +# Test log files +*.log 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() { +} From 3a7dfa14dba387302680ef7cfba556fac97ec198 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Thu, 10 Mar 2022 10:19:15 -0300 Subject: [PATCH 02/11] Fixes rmtDeinit() and tests RX/TX before operations (#6369) * Fixes rmtDeinit() and tests RX/TX before operations * Optimizes final binary size * Typo --- cores/esp32/esp32-hal-rmt.c | 88 ++++++++++++++++++++++++------------- 1 file changed, 57 insertions(+), 31 deletions(-) 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) { From 02a3a71e7c5efba19042e4d8464de7fc4dcce6d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Barto=C5=A1ka?= <76958047+VojtechBartoska@users.noreply.github.com> Date: Thu, 10 Mar 2022 14:29:56 +0100 Subject: [PATCH 03/11] CameraWebServer fix (#6370) --- libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp b/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp index 278964720f1..420d5251224 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" From 66596fa5816e179a204b8eab0db5e584f2752eda Mon Sep 17 00:00:00 2001 From: P-R-O-C-H-Y <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Thu, 10 Mar 2022 14:30:57 +0100 Subject: [PATCH 04/11] =?UTF-8?q?Fix=20ledc=20panic=E2=80=99ed=20when=20wr?= =?UTF-8?q?ong=20setup=20of=20frequency=20and=20bit=20width=20(#6371)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixed LEDC panic when wrong bit widht / frequency set. * Fixed ledc example to be working on all SOCs --- cores/esp32/esp32-hal-ledc.c | 34 +++++++++++++------ .../LEDCSoftwareFade/LEDCSoftwareFade.ino | 10 +++--- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/cores/esp32/esp32-hal-ledc.c b/cores/esp32/esp32-hal-ledc.c index 6274ed0708c..fc5ce8680e2 100644 --- a/cores/esp32/esp32-hal-ledc.c +++ b/cores/esp32/esp32-hal-ledc.c @@ -56,10 +56,11 @@ uint8_t channels_resolution[LEDC_CHANNELS] = {0}; double ledcSetup(uint8_t chan, double 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,7 +99,7 @@ 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); @@ -130,7 +134,12 @@ 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); @@ -153,7 +162,7 @@ double ledcWriteNote(uint8_t chan, note_t note, uint8_t octave){ 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); @@ -177,7 +186,8 @@ void ledcDetachPin(uint8_t pin) double ledcChangeFrequency(uint8_t chan, double 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/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); } From 9b00d4ae6bfbe72bb8681b6b192cc619d74bbf61 Mon Sep 17 00:00:00 2001 From: Pedro Minatel Date: Thu, 10 Mar 2022 13:32:13 +0000 Subject: [PATCH 05/11] Fixed the antenna GPIO argument (#6392) --- .../WiFi/examples/WiFiScanDualAntenna/WiFiScanDualAntenna.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/WiFi/examples/WiFiScanDualAntenna/WiFiScanDualAntenna.ino b/libraries/WiFi/examples/WiFiScanDualAntenna/WiFiScanDualAntenna.ino index f1c8f3e1e42..344778ff3df 100644 --- a/libraries/WiFi/examples/WiFiScanDualAntenna/WiFiScanDualAntenna.ino +++ b/libraries/WiFi/examples/WiFiScanDualAntenna/WiFiScanDualAntenna.ino @@ -30,7 +30,7 @@ void setup() * * Set WiFi dual antenna configuration by passing the GPIO and antenna mode for RX ant TX */ - err = WiFi.setDualAntennaConfig(GPIO_ANT1, GPIO_ANT1, WIFI_RX_ANT_AUTO, WIFI_TX_ANT_AUTO); + 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 From 883241229eee3e0022d8a189bd8870215141b056 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Thu, 10 Mar 2022 10:33:27 -0300 Subject: [PATCH 06/11] Allows setting only one pin (rx or tx) in the first begin() (#6394) --- cores/esp32/HardwareSerial.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index 61c41cebfb0..7a10fe161a1 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -261,19 +261,25 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in if (!uartIsDriverInstalled(_uart)) { switch (_uart_nr) { case UART_NUM_0: - rxPin = rxPin < 0 ? SOC_RX0 : rxPin; - txPin = txPin < 0 ? SOC_TX0 : txPin; + 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: - rxPin = rxPin < 0 ? RX1 : rxPin; - txPin = txPin < 0 ? TX1 : txPin; + 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: - rxPin = rxPin < 0 ? RX2 : rxPin; - txPin = txPin < 0 ? TX2 : txPin; + if (rxPin < 0 && txPin < 0) { + rxPin = RX2; + txPin = TX2; + } break; #endif default: From 52e018198b64a17ed1b782e4d9d5d54555bd02d3 Mon Sep 17 00:00:00 2001 From: Abdelatif Guettouche Date: Thu, 10 Mar 2022 14:41:02 +0100 Subject: [PATCH 07/11] publish.yml: Remove the debug job and fix an error in the workflow. (#6408) Signed-off-by: Abdelatif Guettouche --- .github/workflows/publish.yml | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 686ce2f2380..5d2027ff7e3 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -8,14 +8,6 @@ on: - completed jobs: - debug: - name: Debug - runs-on: ubuntu-latest - - steps: - - name: Debug Action - uses: hmarr/debug-action@v2.0.0 - unit-test-results: name: Unit Test Results runs-on: ubuntu-latest @@ -35,4 +27,7 @@ jobs: - name: Publish Unit Test Results uses: EnricoMi/publish-unit-test-result-action@v1 with: - commit: ${{ github.event.workflow + commit: ${{ github.event.workflow_run.head_sha }} + event_file: artifacts/Event File/event.json + event_name: ${{ github.event.workflow_run.event }} + files: "artifacts/**/*.xml" From 86eb776a634289cc4a55babebf259b852ba54722 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Thu, 10 Mar 2022 17:23:30 +0200 Subject: [PATCH 08/11] Enable hardware test on ESP32-S3 --- .github/scripts/sketch_utils.sh | 7 ++++--- .github/workflows/hil.yml | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/scripts/sketch_utils.sh b/.github/scripts/sketch_utils.sh index d8e4aead5a4..e2066a25429 100755 --- a/.github/scripts/sketch_utils.sh +++ b/.github/scripts/sketch_utils.sh @@ -8,6 +8,7 @@ function build_sketch(){ # build_sketch Date: Thu, 10 Mar 2022 17:43:21 +0200 Subject: [PATCH 09/11] Adjust build dir for tests and sketches --- .github/scripts/on-push.sh | 2 ++ .github/scripts/sketch_utils.sh | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/scripts/on-push.sh b/.github/scripts/on-push.sh index 1a75db6aa88..676d02b77b9 100755 --- a/.github/scripts/on-push.sh +++ b/.github/scripts/on-push.sh @@ -2,6 +2,8 @@ set -e +export ARDUINO_BUILD_DIR="$HOME/.arduino/build.tmp" + function build(){ local target=$1 local fqbn=$2 diff --git a/.github/scripts/sketch_utils.sh b/.github/scripts/sketch_utils.sh index e2066a25429..72645d3c0bc 100755 --- a/.github/scripts/sketch_utils.sh +++ b/.github/scripts/sketch_utils.sh @@ -8,7 +8,11 @@ function build_sketch(){ # build_sketch Date: Thu, 10 Mar 2022 17:50:12 +0200 Subject: [PATCH 10/11] Update tests_build.sh --- .github/scripts/tests_build.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/scripts/tests_build.sh b/.github/scripts/tests_build.sh index 6de547d371b..fd0d2db2d2f 100755 --- a/.github/scripts/tests_build.sh +++ b/.github/scripts/tests_build.sh @@ -25,6 +25,8 @@ case "$target" in ;; "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 From 693459563a69c1f8483cc0a36edc5af76c8c17ad Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Thu, 10 Mar 2022 18:17:48 +0200 Subject: [PATCH 11/11] Send event also if tests fail --- .github/workflows/hil.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/hil.yml b/.github/workflows/hil.yml index 68205877798..1a2fd6e97e6 100644 --- a/.github/workflows/hil.yml +++ b/.github/workflows/hil.yml @@ -110,6 +110,7 @@ jobs: event_file: name: "Event File" + if: ${{ always() }} needs: Test runs-on: ubuntu-latest steps: