From f3a9d4a56e3c5a02037a7e5c61a5b1885e3722e7 Mon Sep 17 00:00:00 2001 From: gojimmypi Date: Wed, 6 Dec 2023 13:23:14 -0800 Subject: [PATCH] Espressif Benchmark ESP-IDF 4.4 fixes --- .../wolfssl_benchmark_IDF_v4.4_ESP32.vgdbproj | 4 ++-- wolfcrypt/benchmark/benchmark.c | 24 ++++++++++++++----- wolfcrypt/src/port/Espressif/esp32_util.c | 10 ++++++-- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/VisualGDB/wolfssl_benchmark_IDF_v4.4_ESP32.vgdbproj b/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/VisualGDB/wolfssl_benchmark_IDF_v4.4_ESP32.vgdbproj index aa22dacfd..c7e81232c 100644 --- a/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/VisualGDB/wolfssl_benchmark_IDF_v4.4_ESP32.vgdbproj +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/VisualGDB/wolfssl_benchmark_IDF_v4.4_ESP32.vgdbproj @@ -1,5 +1,5 @@ - + @@ -220,7 +220,7 @@ openocd - -f interface/tigard.cfg -c "adapter_khz 15000" -f target/esp32.cfg + -f interface/ftdi/tigard.cfg -c "adapter_khz 15000" -f target/esp32.cfg diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index 67c7b7b72..e110afcb7 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -1274,11 +1274,19 @@ static const char* bench_result_words3[][5] = { #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */ /* The ESP32 (both Xtensa and RISC-V have raw CPU counters). */ - #define HAVE_GET_CYCLES - #define INIT_CYCLE_COUNTER do { \ - ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \ - esp_cpu_set_cycle_count(0); \ - } while (0); + #if ESP_IDF_VERSION_MAJOR >= 5 + /* esp_cpu_set_cycle_count() introduced in ESP-IDF v5 */ + #define HAVE_GET_CYCLES + #define INIT_CYCLE_COUNTER do { \ + ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \ + esp_cpu_set_cycle_count(0); \ + } while (0); + #else + #define HAVE_GET_CYCLES + #define INIT_CYCLE_COUNTER do { \ + ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \ + } while (0); + #endif #define BEGIN_ESP_CYCLES do { \ ESP_LOGV(TAG, "BEGIN_ESP_CYCLES"); \ @@ -1494,7 +1502,11 @@ static const char* bench_result_words3[][5] = { * when resetting CPU cycle counter? FreeRTOS tick collison? * thisVal = esp_cpu_get_cycle_count(); See also, above * or thisVal = xthal_get_ccount(); */ - _esp_cpu_count_last = esp_cpu_get_cycle_count(); + #if ESP_IDF_VERSION_MAJOR < 5 + _esp_cpu_count_last = xthal_get_ccount(); + #else + _esp_cpu_count_last = esp_cpu_get_cycle_count(); + #endif #endif /* Return the 64 bit extended total from 32 bit counter. */ diff --git a/wolfcrypt/src/port/Espressif/esp32_util.c b/wolfcrypt/src/port/Espressif/esp32_util.c index c247125ab..28ade6ff9 100644 --- a/wolfcrypt/src/port/Espressif/esp32_util.c +++ b/wolfcrypt/src/port/Espressif/esp32_util.c @@ -34,8 +34,9 @@ /* Espressif */ #include #include -#include - +#if ESP_IDF_VERSION_MAJOR > 4 + #include +#endif /* wolfSSL */ #include /* needed to print MATH_INT_T value */ #include @@ -452,7 +453,10 @@ int esp_ShowHardwareAcclerationSettings(void) */ int ShowExtendedSystemInfo(void) { +#if ESP_IDF_VERSION_MAJOR > 4 unsigned chip_rev = -1; +#endif + #ifdef HAVE_ESP_CLK /* esp_clk.h is private */ int cpu_freq = 0; @@ -470,8 +474,10 @@ int ShowExtendedSystemInfo(void) "Some extended system details not available."); #endif /* else not HAVE_WC_INTROSPECTION */ +#if ESP_IDF_VERSION_MAJOR > 4 chip_rev = efuse_hal_chip_revision(); ESP_LOGI(TAG, "Chip revision: v%d.%d", chip_rev / 100, chip_rev % 100); +#endif #ifdef HAVE_ESP_CLK cpu_freq = esp_clk_cpu_freq();