From e0149b626145bf61d93cb679a61da4d2630fbdb6 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Sun, 4 Aug 2024 16:54:14 -0300 Subject: [PATCH 1/9] new tests --- tests/validation/cpu/ci.json | 5 + tests/validation/cpu/cpu.ino | 35 ++++++ tests/validation/cpu/test_cpu.py | 2 + tests/validation/deep_sleep/ci.json | 5 + tests/validation/deep_sleep/deep_sleep.ino | 113 ++++++++++++++++++ .../validation/deep_sleep/test_deep_sleep.py | 2 + 6 files changed, 162 insertions(+) create mode 100644 tests/validation/cpu/ci.json create mode 100644 tests/validation/cpu/cpu.ino create mode 100644 tests/validation/cpu/test_cpu.py create mode 100644 tests/validation/deep_sleep/ci.json create mode 100644 tests/validation/deep_sleep/deep_sleep.ino create mode 100644 tests/validation/deep_sleep/test_deep_sleep.py diff --git a/tests/validation/cpu/ci.json b/tests/validation/cpu/ci.json new file mode 100644 index 00000000000..54da33b6176 --- /dev/null +++ b/tests/validation/cpu/ci.json @@ -0,0 +1,5 @@ +{ + "platforms": { + "qemu": false + } +} diff --git a/tests/validation/cpu/cpu.ino b/tests/validation/cpu/cpu.ino new file mode 100644 index 00000000000..203a3e8f2ef --- /dev/null +++ b/tests/validation/cpu/cpu.ino @@ -0,0 +1,35 @@ +/* CPU test + * + * Tests miscellaneous CPU functions like changing the CPU frequency, checking the CPU frequency, + * reading the CPU temperature, etc. + */ + +#include +#include + +/* Utility global variables */ + +/* Test functions */ + +#if SOC_TEMP_SENSOR_SUPPORTED +void get_cpu_temperature() { + float temp = temperatureRead(); + log_d("CPU temperature: %f", temp); + TEST_ASSERT_FLOAT_IS_NOT_NAN(temp); + TEST_ASSERT_FLOAT_WITHIN(40.0, 30.0, temp); +} +#endif + +/* Main functions */ + +void setup() { + UNITY_BEGIN(); + + #if SOC_TEMP_SENSOR_SUPPORTED + RUN_TEST(get_cpu_temperature); + #endif + + UNITY_END(); +} + +void loop() {} diff --git a/tests/validation/cpu/test_cpu.py b/tests/validation/cpu/test_cpu.py new file mode 100644 index 00000000000..bf9c0078999 --- /dev/null +++ b/tests/validation/cpu/test_cpu.py @@ -0,0 +1,2 @@ +def test_cpu(dut): + dut.expect_unity_test_output(timeout=120) diff --git a/tests/validation/deep_sleep/ci.json b/tests/validation/deep_sleep/ci.json new file mode 100644 index 00000000000..54da33b6176 --- /dev/null +++ b/tests/validation/deep_sleep/ci.json @@ -0,0 +1,5 @@ +{ + "platforms": { + "qemu": false + } +} diff --git a/tests/validation/deep_sleep/deep_sleep.ino b/tests/validation/deep_sleep/deep_sleep.ino new file mode 100644 index 00000000000..cb1edd0b317 --- /dev/null +++ b/tests/validation/deep_sleep/deep_sleep.ino @@ -0,0 +1,113 @@ +/* + * This sketch tests the deep sleep functionality of the ESP32 + */ + +#include + +// Timer +#define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */ +#define TIME_TO_SLEEP 5 /* Time ESP32 will go to sleep (in seconds) */ + +// Touchpad +#if CONFIG_IDF_TARGET_ESP32 +#define THRESHOLD 1000 /* Greater the value, more the sensitivity */ +#else +#define THRESHOLD 0 /* Lower the value, more the sensitivity */ +#endif + +// External wakeup +#define BUTTON_PIN_BITMASK(GPIO) (1ULL << GPIO) // 2 ^ GPIO_NUMBER in hex +#define WAKEUP_GPIO GPIO_NUM_33 // Only RTC IO are allowed - ESP32 Pin example + +RTC_DATA_ATTR int bootCount = 0; + +void print_wakeup_reason() { + esp_sleep_wakeup_cause_t wakeup_reason; + + wakeup_reason = esp_sleep_get_wakeup_cause(); + + Serial.print("Wakeup reason: "); + + switch (wakeup_reason) { + case ESP_SLEEP_WAKEUP_EXT0: Serial.println("rtc_io"); break; + case ESP_SLEEP_WAKEUP_EXT1: Serial.println("rtc_cntl"); break; + case ESP_SLEEP_WAKEUP_TIMER: Serial.println("timer"); break; + case ESP_SLEEP_WAKEUP_TOUCHPAD: Serial.println("touchpad"); break; + case ESP_SLEEP_WAKEUP_ULP: Serial.println("ulp"); break; + default: Serial.println("power_up"); break; + } +} + +void setup_timer() { + esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); +} + +void setup_touchpad() { + #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 + touchSleepWakeUpEnable(T1, THRESHOLD); + #else + esp_sleep_enable_timer_wakeup(10); + #endif +} + +void setup_rtc_io() { + #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 + esp_sleep_enable_ext0_wakeup(WAKEUP_GPIO, 1); + rtc_gpio_pullup_en(WAKEUP_GPIO); + rtc_gpio_pulldown_dis(WAKEUP_GPIO); + #else + esp_sleep_enable_timer_wakeup(10); + #endif +} + +void setup_rtc_cntl() { + #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 + esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(WAKEUP_GPIO), ESP_EXT1_WAKEUP_ANY_HIGH); + rtc_gpio_pulldown_dis(WAKEUP_GPIO); + rtc_gpio_pullup_en(WAKEUP_GPIO); + #else + esp_sleep_enable_timer_wakeup(10); + #endif +} + + + +void setup() { + Serial.begin(115200); + while (!Serial) { + delay(10); + } + + //Increment boot number and print it every reboot + ++bootCount; + Serial.println("Boot number: " + String(bootCount)); + + //Print the wakeup reason for ESP32 + print_wakeup_reason(); + Serial.flush(); + + if (bootCount == 1) { + // Timer + setup_timer(); + } else if (bootCount == 2) { + // Touchpad + setup_touchpad(); + } else if (bootCount == 3) { + // rtc_io + setup_rtc_io(); + } else if (bootCount == 4) { + // rtc_cntl + setup_rtc_cntl(); + } + else { + return; + } + + esp_deep_sleep_start(); + Serial.println("This will never be printed"); + +} + +void loop() { + //This is not going to be called +} diff --git a/tests/validation/deep_sleep/test_deep_sleep.py b/tests/validation/deep_sleep/test_deep_sleep.py new file mode 100644 index 00000000000..c942bd32e21 --- /dev/null +++ b/tests/validation/deep_sleep/test_deep_sleep.py @@ -0,0 +1,2 @@ +def test_deep_sleep(dut): + dut.expect_exact("Entering deep sleep") From c9027c56a109851017e1c6ab6d61d15f12364ae7 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Tue, 17 Sep 2024 15:47:50 -0300 Subject: [PATCH 2/9] update --- tests/validation/{cpu => cpu_misc}/ci.json | 0 .../{cpu/cpu.ino => cpu_misc/cpu_misc.ino} | 0 .../test_cpu.py => cpu_misc/test_cpu_misc.py} | 2 +- tests/validation/deep_sleep/deep_sleep.ino | 113 ------------ .../validation/deep_sleep/test_deep_sleep.py | 2 - .../validation/{deep_sleep => sleep}/ci.json | 0 tests/validation/sleep/sleep.ino | 161 ++++++++++++++++++ tests/validation/sleep/test_sleep.py | 40 +++++ 8 files changed, 202 insertions(+), 116 deletions(-) rename tests/validation/{cpu => cpu_misc}/ci.json (100%) rename tests/validation/{cpu/cpu.ino => cpu_misc/cpu_misc.ino} (100%) rename tests/validation/{cpu/test_cpu.py => cpu_misc/test_cpu_misc.py} (65%) delete mode 100644 tests/validation/deep_sleep/deep_sleep.ino delete mode 100644 tests/validation/deep_sleep/test_deep_sleep.py rename tests/validation/{deep_sleep => sleep}/ci.json (100%) create mode 100644 tests/validation/sleep/sleep.ino create mode 100644 tests/validation/sleep/test_sleep.py diff --git a/tests/validation/cpu/ci.json b/tests/validation/cpu_misc/ci.json similarity index 100% rename from tests/validation/cpu/ci.json rename to tests/validation/cpu_misc/ci.json diff --git a/tests/validation/cpu/cpu.ino b/tests/validation/cpu_misc/cpu_misc.ino similarity index 100% rename from tests/validation/cpu/cpu.ino rename to tests/validation/cpu_misc/cpu_misc.ino diff --git a/tests/validation/cpu/test_cpu.py b/tests/validation/cpu_misc/test_cpu_misc.py similarity index 65% rename from tests/validation/cpu/test_cpu.py rename to tests/validation/cpu_misc/test_cpu_misc.py index bf9c0078999..2e260ca9b49 100644 --- a/tests/validation/cpu/test_cpu.py +++ b/tests/validation/cpu_misc/test_cpu_misc.py @@ -1,2 +1,2 @@ -def test_cpu(dut): +def test_cpu_misc(dut): dut.expect_unity_test_output(timeout=120) diff --git a/tests/validation/deep_sleep/deep_sleep.ino b/tests/validation/deep_sleep/deep_sleep.ino deleted file mode 100644 index cb1edd0b317..00000000000 --- a/tests/validation/deep_sleep/deep_sleep.ino +++ /dev/null @@ -1,113 +0,0 @@ -/* - * This sketch tests the deep sleep functionality of the ESP32 - */ - -#include - -// Timer -#define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */ -#define TIME_TO_SLEEP 5 /* Time ESP32 will go to sleep (in seconds) */ - -// Touchpad -#if CONFIG_IDF_TARGET_ESP32 -#define THRESHOLD 1000 /* Greater the value, more the sensitivity */ -#else -#define THRESHOLD 0 /* Lower the value, more the sensitivity */ -#endif - -// External wakeup -#define BUTTON_PIN_BITMASK(GPIO) (1ULL << GPIO) // 2 ^ GPIO_NUMBER in hex -#define WAKEUP_GPIO GPIO_NUM_33 // Only RTC IO are allowed - ESP32 Pin example - -RTC_DATA_ATTR int bootCount = 0; - -void print_wakeup_reason() { - esp_sleep_wakeup_cause_t wakeup_reason; - - wakeup_reason = esp_sleep_get_wakeup_cause(); - - Serial.print("Wakeup reason: "); - - switch (wakeup_reason) { - case ESP_SLEEP_WAKEUP_EXT0: Serial.println("rtc_io"); break; - case ESP_SLEEP_WAKEUP_EXT1: Serial.println("rtc_cntl"); break; - case ESP_SLEEP_WAKEUP_TIMER: Serial.println("timer"); break; - case ESP_SLEEP_WAKEUP_TOUCHPAD: Serial.println("touchpad"); break; - case ESP_SLEEP_WAKEUP_ULP: Serial.println("ulp"); break; - default: Serial.println("power_up"); break; - } -} - -void setup_timer() { - esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); -} - -void setup_touchpad() { - #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 - touchSleepWakeUpEnable(T1, THRESHOLD); - #else - esp_sleep_enable_timer_wakeup(10); - #endif -} - -void setup_rtc_io() { - #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 - esp_sleep_enable_ext0_wakeup(WAKEUP_GPIO, 1); - rtc_gpio_pullup_en(WAKEUP_GPIO); - rtc_gpio_pulldown_dis(WAKEUP_GPIO); - #else - esp_sleep_enable_timer_wakeup(10); - #endif -} - -void setup_rtc_cntl() { - #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 - esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(WAKEUP_GPIO), ESP_EXT1_WAKEUP_ANY_HIGH); - rtc_gpio_pulldown_dis(WAKEUP_GPIO); - rtc_gpio_pullup_en(WAKEUP_GPIO); - #else - esp_sleep_enable_timer_wakeup(10); - #endif -} - - - -void setup() { - Serial.begin(115200); - while (!Serial) { - delay(10); - } - - //Increment boot number and print it every reboot - ++bootCount; - Serial.println("Boot number: " + String(bootCount)); - - //Print the wakeup reason for ESP32 - print_wakeup_reason(); - Serial.flush(); - - if (bootCount == 1) { - // Timer - setup_timer(); - } else if (bootCount == 2) { - // Touchpad - setup_touchpad(); - } else if (bootCount == 3) { - // rtc_io - setup_rtc_io(); - } else if (bootCount == 4) { - // rtc_cntl - setup_rtc_cntl(); - } - else { - return; - } - - esp_deep_sleep_start(); - Serial.println("This will never be printed"); - -} - -void loop() { - //This is not going to be called -} diff --git a/tests/validation/deep_sleep/test_deep_sleep.py b/tests/validation/deep_sleep/test_deep_sleep.py deleted file mode 100644 index c942bd32e21..00000000000 --- a/tests/validation/deep_sleep/test_deep_sleep.py +++ /dev/null @@ -1,2 +0,0 @@ -def test_deep_sleep(dut): - dut.expect_exact("Entering deep sleep") diff --git a/tests/validation/deep_sleep/ci.json b/tests/validation/sleep/ci.json similarity index 100% rename from tests/validation/deep_sleep/ci.json rename to tests/validation/sleep/ci.json diff --git a/tests/validation/sleep/sleep.ino b/tests/validation/sleep/sleep.ino new file mode 100644 index 00000000000..0241139c52a --- /dev/null +++ b/tests/validation/sleep/sleep.ino @@ -0,0 +1,161 @@ +/* + * This sketch tests the deep sleep functionality of the ESP32 + */ + +#include +#include "driver/rtc_io.h" +#include "driver/uart.h" + +// Timer +#define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */ +#define TIME_TO_SLEEP 1 /* Time ESP32 will go to sleep (in seconds) */ + +// Touchpad +#if CONFIG_IDF_TARGET_ESP32 +#define THRESHOLD 1000 /* Greater the value, more the sensitivity */ +#else +#define THRESHOLD 0 /* Lower the value, more the sensitivity */ +#endif + +// External wakeup +#define BUTTON_PIN_BITMASK(GPIO) (1ULL << GPIO) // 2 ^ GPIO_NUMBER in hex + +#if CONFIG_IDF_TARGET_ESP32H2 +#define WAKEUP_GPIO GPIO_NUM_7 // Only RTC IO are allowed +#else +#define WAKEUP_GPIO GPIO_NUM_4 // Only RTC IO are allowed +#endif + +RTC_DATA_ATTR int bootCount = 0; + +void print_wakeup_reason() { + esp_sleep_wakeup_cause_t wakeup_reason; + + wakeup_reason = esp_sleep_get_wakeup_cause(); + + Serial.print("Wakeup reason: "); + + switch (wakeup_reason) { + case ESP_SLEEP_WAKEUP_EXT0: Serial.println("rtc_io"); break; + case ESP_SLEEP_WAKEUP_EXT1: Serial.println("rtc_cntl"); break; + case ESP_SLEEP_WAKEUP_TIMER: Serial.println("timer"); break; + case ESP_SLEEP_WAKEUP_TOUCHPAD: Serial.println("touchpad"); break; + case ESP_SLEEP_WAKEUP_ULP: Serial.println("ulp"); break; + case ESP_SLEEP_WAKEUP_GPIO: Serial.println("gpio"); break; + case ESP_SLEEP_WAKEUP_UART: Serial.println("uart"); break; + default: Serial.println("power_up"); break; + } +} + +void setup_timer() { + esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); +} + +void setup_touchpad() { + touchSleepWakeUpEnable(T1, THRESHOLD); +} + +void setup_rtc_io() { + esp_sleep_enable_ext0_wakeup(WAKEUP_GPIO, 1); + rtc_gpio_pullup_en(WAKEUP_GPIO); + rtc_gpio_pulldown_dis(WAKEUP_GPIO); +} + +void setup_rtc_cntl() { + esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(WAKEUP_GPIO), ESP_EXT1_WAKEUP_ANY_HIGH); + rtc_gpio_pulldown_dis(WAKEUP_GPIO); + rtc_gpio_pullup_en(WAKEUP_GPIO); +} + +void setup_gpio() { + esp_sleep_pd_config(ESP_PD_DOMAIN_VDDSDIO, ESP_PD_OPTION_ON); + rtc_gpio_pullup_dis(WAKEUP_GPIO); + rtc_gpio_pulldown_en(WAKEUP_GPIO); + gpio_wakeup_enable(WAKEUP_GPIO, GPIO_INTR_HIGH_LEVEL); + esp_sleep_enable_gpio_wakeup(); +} + +void setup_uart() { + uart_set_wakeup_threshold(UART_NUM_0, 9); // wake up with "aaa" string (9 positive edges) + esp_sleep_enable_uart_wakeup(UART_NUM_0); +} + + + +void setup() { + Serial.begin(115200); + while (!Serial) { + delay(10); + } + + //Increment boot number and print it every reboot + ++bootCount; + Serial.println("Boot number: " + String(bootCount)); + + //Print the wakeup reason for ESP32 + print_wakeup_reason(); + Serial.flush(); +} + +void loop() { + // Disable all configured wakeup sources + esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL); + + if(Serial.available() > 0) { + String command = Serial.readString(); + command.trim(); + + if (command == "timer_deep") { + // Test timer wakeup from deep sleep + setup_timer(); + esp_deep_sleep_start(); + Serial.println("FAIL"); + while(1); + } else if (command == "touchpad_deep") { + // Test touchpad wakeup from deep sleep + setup_touchpad(); + esp_deep_sleep_start(); + Serial.println("FAIL"); + while(1); + } else if (command == "rtc_io_deep") { + // Test external wakeup from deep sleep using RTC IO + setup_rtc_io(); + esp_deep_sleep_start(); + Serial.println("FAIL"); + while(1); + } else if (command == "rtc_cntl_deep") { + // Test external wakeup from deep sleep using RTC controller + setup_rtc_cntl(); + esp_deep_sleep_start(); + Serial.println("FAIL"); + while(1); + } else if (command == "timer_light") { + // Test timer wakeup from light sleep + setup_timer(); + } else if (command == "touchpad_light") { + // Test touchpad wakeup from light sleep + setup_touchpad(); + } else if (command == "rtc_io_light") { + // Test external wakeup from light sleep using RTC IO + setup_rtc_io(); + } else if (command == "rtc_cntl_light") { + // Test external wakeup from light sleep using RTC controller + setup_rtc_cntl(); + } else if (command == "gpio_light") { + // Test external wakeup from light sleep using GPIO + setup_gpio(); + } else if (command == "uart_light") { + // Test external wakeup from light sleep using UART + setup_uart(); + } else { + Serial.println("FAIL"); + while(1); + } + + esp_light_sleep_start(); + Serial.println("Woke up from light sleep"); + print_wakeup_reason(); + Serial.flush(); + rtc_gpio_hold_dis(WAKEUP_GPIO); + } +} diff --git a/tests/validation/sleep/test_sleep.py b/tests/validation/sleep/test_sleep.py new file mode 100644 index 00000000000..f44c981ca6d --- /dev/null +++ b/tests/validation/sleep/test_sleep.py @@ -0,0 +1,40 @@ +import logging + +capabilities = { + "timer": ["esp32", "esp32s2", "esp32s3", "esp32c3", "esp32c6", "esp32h2"], + "touchpad": ["esp32", "esp32s2", "esp32s3", "esp32c3"], + "rtc_io": ["esp32", "esp32s2", "esp32s3", "esp32c3", "esp32c6", "esp32h2"], + "rtc_cntl": ["esp32", "esp32s2", "esp32s3", "esp32c3", "esp32c6", "esp32h2"], + "gpio": ["esp32", "esp32s2", "esp32s3"], + "uart": ["esp32", "esp32s2", "esp32s3", "esp32c3", "esp32c6", "esp32h2"] +} + +def test_sleep(dut): + LOGGER = logging.getLogger(__name__) + + # Deep Sleep + boot_count = 1 + dut.expect_exact("Boot number: {}".format(boot_count)) + dut.expect_exact("Wakeup reason: power_up") + + for capability, devices in capabilities.items(): + if dut.app.target in devices and capability not in ["gpio", "uart"]: + LOGGER.info("Testing {} deep sleep capability".format(capability)) + boot_count += 1 + dut.write("{}_deep".format(capability)) + dut.expect_exact("Boot number: {}".format(boot_count)) + dut.expect_exact("Wakeup reason: {}".format(capability)) + + # Light Sleep + for capability, devices in capabilities.items(): + if dut.app.target in devices: + LOGGER.info("Testing {} light sleep capability".format(capability)) + dut.write("{}_light".format(capability)) + if capability == "uart": + dut.write("aaa") # Send 9 positive edges + dut.expect_exact("Woke up from light sleep") + dut.expect_exact("Wakeup reason: {}".format(capability)) + + + + From 5bc8e6a055a5108f9cc7b30f6c4c0815c8347624 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Tue, 17 Sep 2024 16:20:36 -0300 Subject: [PATCH 3/9] fix --- tests/validation/sleep/sleep.ino | 12 +++++++++--- tests/validation/sleep/test_sleep.py | 6 +++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/validation/sleep/sleep.ino b/tests/validation/sleep/sleep.ino index 0241139c52a..1e1bd3e05d8 100644 --- a/tests/validation/sleep/sleep.ino +++ b/tests/validation/sleep/sleep.ino @@ -52,25 +52,31 @@ void setup_timer() { } void setup_touchpad() { +#if SOC_TOUCH_SENSOR_SUPPORTED touchSleepWakeUpEnable(T1, THRESHOLD); +#endif } void setup_rtc_io() { +#if SOC_RTCIO_WAKE_SUPPORTED esp_sleep_enable_ext0_wakeup(WAKEUP_GPIO, 1); rtc_gpio_pullup_en(WAKEUP_GPIO); rtc_gpio_pulldown_dis(WAKEUP_GPIO); +#endif } void setup_rtc_cntl() { +#if SOC_RTCIO_WAKE_SUPPORTED esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(WAKEUP_GPIO), ESP_EXT1_WAKEUP_ANY_HIGH); rtc_gpio_pulldown_dis(WAKEUP_GPIO); rtc_gpio_pullup_en(WAKEUP_GPIO); +#endif } void setup_gpio() { esp_sleep_pd_config(ESP_PD_DOMAIN_VDDSDIO, ESP_PD_OPTION_ON); - rtc_gpio_pullup_dis(WAKEUP_GPIO); - rtc_gpio_pulldown_en(WAKEUP_GPIO); + gpio_pullup_dis(WAKEUP_GPIO); + gpio_pulldown_en(WAKEUP_GPIO); gpio_wakeup_enable(WAKEUP_GPIO, GPIO_INTR_HIGH_LEVEL); esp_sleep_enable_gpio_wakeup(); } @@ -156,6 +162,6 @@ void loop() { Serial.println("Woke up from light sleep"); print_wakeup_reason(); Serial.flush(); - rtc_gpio_hold_dis(WAKEUP_GPIO); + gpio_hold_dis(WAKEUP_GPIO); } } diff --git a/tests/validation/sleep/test_sleep.py b/tests/validation/sleep/test_sleep.py index f44c981ca6d..1756abca1a5 100644 --- a/tests/validation/sleep/test_sleep.py +++ b/tests/validation/sleep/test_sleep.py @@ -2,9 +2,9 @@ capabilities = { "timer": ["esp32", "esp32s2", "esp32s3", "esp32c3", "esp32c6", "esp32h2"], - "touchpad": ["esp32", "esp32s2", "esp32s3", "esp32c3"], - "rtc_io": ["esp32", "esp32s2", "esp32s3", "esp32c3", "esp32c6", "esp32h2"], - "rtc_cntl": ["esp32", "esp32s2", "esp32s3", "esp32c3", "esp32c6", "esp32h2"], + "touchpad": ["esp32", "esp32s2", "esp32s3"], + "rtc_io": ["esp32", "esp32s2", "esp32s3", "esp32c6"], + "rtc_cntl": ["esp32", "esp32s2", "esp32s3", "esp32c6"], "gpio": ["esp32", "esp32s2", "esp32s3"], "uart": ["esp32", "esp32s2", "esp32s3", "esp32c3", "esp32c6", "esp32h2"] } From 446d2df682e683cbfb0a8963d93f2d8e4a38912c Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Tue, 17 Sep 2024 16:29:37 -0300 Subject: [PATCH 4/9] fix --- tests/validation/sleep/sleep.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/validation/sleep/sleep.ino b/tests/validation/sleep/sleep.ino index 1e1bd3e05d8..eeae60f6341 100644 --- a/tests/validation/sleep/sleep.ino +++ b/tests/validation/sleep/sleep.ino @@ -58,7 +58,7 @@ void setup_touchpad() { } void setup_rtc_io() { -#if SOC_RTCIO_WAKE_SUPPORTED +#if SOC_RTCIO_WAKE_SUPPORTED && SOC_PM_SUPPORT_EXT0_WAKEUP esp_sleep_enable_ext0_wakeup(WAKEUP_GPIO, 1); rtc_gpio_pullup_en(WAKEUP_GPIO); rtc_gpio_pulldown_dis(WAKEUP_GPIO); @@ -66,7 +66,7 @@ void setup_rtc_io() { } void setup_rtc_cntl() { -#if SOC_RTCIO_WAKE_SUPPORTED +#if SOC_RTCIO_WAKE_SUPPORTED && SOC_PM_SUPPORT_EXT1_WAKEUP esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(WAKEUP_GPIO), ESP_EXT1_WAKEUP_ANY_HIGH); rtc_gpio_pulldown_dis(WAKEUP_GPIO); rtc_gpio_pullup_en(WAKEUP_GPIO); From 105bddfe3ebd5da86b191b831f59bc94f31735ec Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Tue, 17 Sep 2024 17:50:31 -0300 Subject: [PATCH 5/9] fix --- tests/validation/sleep/ci.json | 3 ++- tests/validation/sleep/sleep.ino | 18 +++++++++++++----- tests/validation/sleep/test_sleep.py | 8 ++++---- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/tests/validation/sleep/ci.json b/tests/validation/sleep/ci.json index 54da33b6176..accee2b2135 100644 --- a/tests/validation/sleep/ci.json +++ b/tests/validation/sleep/ci.json @@ -1,5 +1,6 @@ { "platforms": { - "qemu": false + "qemu": false, + "wokwi": false } } diff --git a/tests/validation/sleep/sleep.ino b/tests/validation/sleep/sleep.ino index eeae60f6341..a2e4e004868 100644 --- a/tests/validation/sleep/sleep.ino +++ b/tests/validation/sleep/sleep.ino @@ -22,11 +22,14 @@ #if CONFIG_IDF_TARGET_ESP32H2 #define WAKEUP_GPIO GPIO_NUM_7 // Only RTC IO are allowed +#define TARGET_FREQ 32 #else #define WAKEUP_GPIO GPIO_NUM_4 // Only RTC IO are allowed +#define TARGET_FREQ 40 #endif -RTC_DATA_ATTR int bootCount = 0; +RTC_DATA_ATTR int boot_count = 0; +uint32_t orig_freq = 0; void print_wakeup_reason() { esp_sleep_wakeup_cause_t wakeup_reason; @@ -86,17 +89,17 @@ void setup_uart() { esp_sleep_enable_uart_wakeup(UART_NUM_0); } - - void setup() { Serial.begin(115200); while (!Serial) { delay(10); } + orig_freq = getCpuFrequencyMhz(); + //Increment boot number and print it every reboot - ++bootCount; - Serial.println("Boot number: " + String(bootCount)); + boot_count++; + Serial.println("Boot number: " + String(boot_count)); //Print the wakeup reason for ESP32 print_wakeup_reason(); @@ -138,6 +141,10 @@ void loop() { } else if (command == "timer_light") { // Test timer wakeup from light sleep setup_timer(); + } else if (command == "timer_freq_light") { + // Test timer wakeup from light sleep while changing CPU frequency + setCpuFrequencyMhz(TARGET_FREQ); + setup_timer(); } else if (command == "touchpad_light") { // Test touchpad wakeup from light sleep setup_touchpad(); @@ -163,5 +170,6 @@ void loop() { print_wakeup_reason(); Serial.flush(); gpio_hold_dis(WAKEUP_GPIO); + setCpuFrequencyMhz(orig_freq); } } diff --git a/tests/validation/sleep/test_sleep.py b/tests/validation/sleep/test_sleep.py index 1756abca1a5..baadd8cdd55 100644 --- a/tests/validation/sleep/test_sleep.py +++ b/tests/validation/sleep/test_sleep.py @@ -34,7 +34,7 @@ def test_sleep(dut): dut.write("aaa") # Send 9 positive edges dut.expect_exact("Woke up from light sleep") dut.expect_exact("Wakeup reason: {}".format(capability)) - - - - + if capability == "timer": + dut.write("timer_freq_light") + dut.expect_exact("Woke up from light sleep") + dut.expect_exact("Wakeup reason: timer") From 8c6164e1e4cb475abf9f2ac9ae21d885d924f968 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Sun, 29 Sep 2024 00:08:54 -0300 Subject: [PATCH 6/9] fix --- tests/validation/sleep/sleep.ino | 2 +- tests/validation/sleep/test_sleep.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/validation/sleep/sleep.ino b/tests/validation/sleep/sleep.ino index a2e4e004868..532f7772e66 100644 --- a/tests/validation/sleep/sleep.ino +++ b/tests/validation/sleep/sleep.ino @@ -80,7 +80,7 @@ void setup_gpio() { esp_sleep_pd_config(ESP_PD_DOMAIN_VDDSDIO, ESP_PD_OPTION_ON); gpio_pullup_dis(WAKEUP_GPIO); gpio_pulldown_en(WAKEUP_GPIO); - gpio_wakeup_enable(WAKEUP_GPIO, GPIO_INTR_HIGH_LEVEL); + gpio_wakeup_enable(WAKEUP_GPIO, GPIO_INTR_LOW_LEVEL); esp_sleep_enable_gpio_wakeup(); } diff --git a/tests/validation/sleep/test_sleep.py b/tests/validation/sleep/test_sleep.py index baadd8cdd55..f5db75a2bfe 100644 --- a/tests/validation/sleep/test_sleep.py +++ b/tests/validation/sleep/test_sleep.py @@ -35,6 +35,7 @@ def test_sleep(dut): dut.expect_exact("Woke up from light sleep") dut.expect_exact("Wakeup reason: {}".format(capability)) if capability == "timer": + LOGGER.info("Testing timer light sleep capability with low frequency") dut.write("timer_freq_light") dut.expect_exact("Woke up from light sleep") dut.expect_exact("Wakeup reason: timer") From 6cedad8b2db82e8b0c0002cee4d1065ddda5c565 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Sun, 29 Sep 2024 17:08:35 -0300 Subject: [PATCH 7/9] test --- tests/validation/sleep/test_sleep.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/validation/sleep/test_sleep.py b/tests/validation/sleep/test_sleep.py index f5db75a2bfe..80aa2fa0792 100644 --- a/tests/validation/sleep/test_sleep.py +++ b/tests/validation/sleep/test_sleep.py @@ -1,4 +1,5 @@ import logging +import time capabilities = { "timer": ["esp32", "esp32s2", "esp32s3", "esp32c3", "esp32c6", "esp32h2"], @@ -31,6 +32,8 @@ def test_sleep(dut): LOGGER.info("Testing {} light sleep capability".format(capability)) dut.write("{}_light".format(capability)) if capability == "uart": + time.sleep(5) + LOGGER.info("Sending 9 positive edges") dut.write("aaa") # Send 9 positive edges dut.expect_exact("Woke up from light sleep") dut.expect_exact("Wakeup reason: {}".format(capability)) From 068b2120dae050131d16450e330c1a1aa8a44ba9 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Sun, 29 Sep 2024 19:49:39 -0300 Subject: [PATCH 8/9] fix --- tests/validation/cpu_misc/cpu_misc.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/validation/cpu_misc/cpu_misc.ino b/tests/validation/cpu_misc/cpu_misc.ino index 203a3e8f2ef..e0c1864e622 100644 --- a/tests/validation/cpu_misc/cpu_misc.ino +++ b/tests/validation/cpu_misc/cpu_misc.ino @@ -11,23 +11,23 @@ /* Test functions */ -#if SOC_TEMP_SENSOR_SUPPORTED void get_cpu_temperature() { +#if SOC_TEMP_SENSOR_SUPPORTED float temp = temperatureRead(); log_d("CPU temperature: %f", temp); TEST_ASSERT_FLOAT_IS_NOT_NAN(temp); TEST_ASSERT_FLOAT_WITHIN(40.0, 30.0, temp); -} +#else + log_d("CPU temperature not supported"); #endif +} /* Main functions */ void setup() { UNITY_BEGIN(); - #if SOC_TEMP_SENSOR_SUPPORTED RUN_TEST(get_cpu_temperature); - #endif UNITY_END(); } From 47a1329725df0cea281d3f0002c8d7631bc3014e Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Mon, 30 Sep 2024 23:01:49 -0300 Subject: [PATCH 9/9] fix --- tests/validation/sleep/sleep.ino | 57 +--------------------------- tests/validation/sleep/test_sleep.py | 5 +-- 2 files changed, 2 insertions(+), 60 deletions(-) diff --git a/tests/validation/sleep/sleep.ino b/tests/validation/sleep/sleep.ino index 532f7772e66..95df48c878f 100644 --- a/tests/validation/sleep/sleep.ino +++ b/tests/validation/sleep/sleep.ino @@ -17,16 +17,7 @@ #define THRESHOLD 0 /* Lower the value, more the sensitivity */ #endif -// External wakeup -#define BUTTON_PIN_BITMASK(GPIO) (1ULL << GPIO) // 2 ^ GPIO_NUMBER in hex - -#if CONFIG_IDF_TARGET_ESP32H2 -#define WAKEUP_GPIO GPIO_NUM_7 // Only RTC IO are allowed -#define TARGET_FREQ 32 -#else -#define WAKEUP_GPIO GPIO_NUM_4 // Only RTC IO are allowed -#define TARGET_FREQ 40 -#endif +#define TARGET_FREQ CONFIG_XTAL_FREQ RTC_DATA_ATTR int boot_count = 0; uint32_t orig_freq = 0; @@ -60,30 +51,6 @@ void setup_touchpad() { #endif } -void setup_rtc_io() { -#if SOC_RTCIO_WAKE_SUPPORTED && SOC_PM_SUPPORT_EXT0_WAKEUP - esp_sleep_enable_ext0_wakeup(WAKEUP_GPIO, 1); - rtc_gpio_pullup_en(WAKEUP_GPIO); - rtc_gpio_pulldown_dis(WAKEUP_GPIO); -#endif -} - -void setup_rtc_cntl() { -#if SOC_RTCIO_WAKE_SUPPORTED && SOC_PM_SUPPORT_EXT1_WAKEUP - esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(WAKEUP_GPIO), ESP_EXT1_WAKEUP_ANY_HIGH); - rtc_gpio_pulldown_dis(WAKEUP_GPIO); - rtc_gpio_pullup_en(WAKEUP_GPIO); -#endif -} - -void setup_gpio() { - esp_sleep_pd_config(ESP_PD_DOMAIN_VDDSDIO, ESP_PD_OPTION_ON); - gpio_pullup_dis(WAKEUP_GPIO); - gpio_pulldown_en(WAKEUP_GPIO); - gpio_wakeup_enable(WAKEUP_GPIO, GPIO_INTR_LOW_LEVEL); - esp_sleep_enable_gpio_wakeup(); -} - void setup_uart() { uart_set_wakeup_threshold(UART_NUM_0, 9); // wake up with "aaa" string (9 positive edges) esp_sleep_enable_uart_wakeup(UART_NUM_0); @@ -126,18 +93,6 @@ void loop() { esp_deep_sleep_start(); Serial.println("FAIL"); while(1); - } else if (command == "rtc_io_deep") { - // Test external wakeup from deep sleep using RTC IO - setup_rtc_io(); - esp_deep_sleep_start(); - Serial.println("FAIL"); - while(1); - } else if (command == "rtc_cntl_deep") { - // Test external wakeup from deep sleep using RTC controller - setup_rtc_cntl(); - esp_deep_sleep_start(); - Serial.println("FAIL"); - while(1); } else if (command == "timer_light") { // Test timer wakeup from light sleep setup_timer(); @@ -148,15 +103,6 @@ void loop() { } else if (command == "touchpad_light") { // Test touchpad wakeup from light sleep setup_touchpad(); - } else if (command == "rtc_io_light") { - // Test external wakeup from light sleep using RTC IO - setup_rtc_io(); - } else if (command == "rtc_cntl_light") { - // Test external wakeup from light sleep using RTC controller - setup_rtc_cntl(); - } else if (command == "gpio_light") { - // Test external wakeup from light sleep using GPIO - setup_gpio(); } else if (command == "uart_light") { // Test external wakeup from light sleep using UART setup_uart(); @@ -169,7 +115,6 @@ void loop() { Serial.println("Woke up from light sleep"); print_wakeup_reason(); Serial.flush(); - gpio_hold_dis(WAKEUP_GPIO); setCpuFrequencyMhz(orig_freq); } } diff --git a/tests/validation/sleep/test_sleep.py b/tests/validation/sleep/test_sleep.py index 80aa2fa0792..b583c079821 100644 --- a/tests/validation/sleep/test_sleep.py +++ b/tests/validation/sleep/test_sleep.py @@ -4,9 +4,6 @@ capabilities = { "timer": ["esp32", "esp32s2", "esp32s3", "esp32c3", "esp32c6", "esp32h2"], "touchpad": ["esp32", "esp32s2", "esp32s3"], - "rtc_io": ["esp32", "esp32s2", "esp32s3", "esp32c6"], - "rtc_cntl": ["esp32", "esp32s2", "esp32s3", "esp32c6"], - "gpio": ["esp32", "esp32s2", "esp32s3"], "uart": ["esp32", "esp32s2", "esp32s3", "esp32c3", "esp32c6", "esp32h2"] } @@ -19,7 +16,7 @@ def test_sleep(dut): dut.expect_exact("Wakeup reason: power_up") for capability, devices in capabilities.items(): - if dut.app.target in devices and capability not in ["gpio", "uart"]: + if dut.app.target in devices and capability != "uart": LOGGER.info("Testing {} deep sleep capability".format(capability)) boot_count += 1 dut.write("{}_deep".format(capability))