diff --git a/components/esp_driver_uart/test_apps/uart/main/test_uart.c b/components/esp_driver_uart/test_apps/uart/main/test_uart.c index 6b11b39ecc..2554bb7675 100644 --- a/components/esp_driver_uart/test_apps/uart/main/test_uart.c +++ b/components/esp_driver_uart/test_apps/uart/main/test_uart.c @@ -273,7 +273,7 @@ static void uart_wakeup_set_get_test(int uart_num) printf("uart wake up set and get test\n"); int wake_up_set = 0; int wake_up_get = 0; - for (int i = 3; i < 0x3ff; i++) { + for (int i = 6; i < 0x3ff; i++) { wake_up_set = i; TEST_ESP_OK(uart_set_wakeup_threshold(uart_num, wake_up_set)); TEST_ESP_OK(uart_get_wakeup_threshold(uart_num, &wake_up_get)); diff --git a/components/esp_hal_uart/esp32p4/include/hal/uart_ll.h b/components/esp_hal_uart/esp32p4/include/hal/uart_ll.h index 86c5a26ecc..e01c325acf 100644 --- a/components/esp_hal_uart/esp32p4/include/hal/uart_ll.h +++ b/components/esp_hal_uart/esp32p4/include/hal/uart_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -1061,8 +1061,10 @@ FORCE_INLINE_ATTR void uart_ll_set_dtr_active_level(uart_dev_t *hw, int level) */ FORCE_INLINE_ATTR void uart_ll_set_wakeup_edge_thrd(uart_dev_t *hw, uint32_t wakeup_thrd) { - // System would wakeup when the number of positive edges of RxD signal is larger than or equal to (UART_ACTIVE_THRESHOLD+3) - hw->sleep_conf2.active_threshold = wakeup_thrd - UART_LL_WAKEUP_EDGE_THRED_MIN; + // System would wakeup when the number of positive edges of RxD signal is larger than or equal to (UART_ACTIVE_THRESHOLD+offset) + // HP UART: offset is 6, LP UART: offset is 3 + uint32_t offset = (hw == &LP_UART) ? UART_LL_WAKEUP_EDGE_THRED_MIN : UART_LL_WAKEUP_EDGE_THRED_MIN + 3; + hw->sleep_conf2.active_threshold = wakeup_thrd - offset; } /** @@ -1370,7 +1372,9 @@ FORCE_INLINE_ATTR void uart_ll_get_at_cmd_char(uart_dev_t *hw, uint8_t *cmd_char */ FORCE_INLINE_ATTR uint32_t uart_ll_get_wakeup_edge_thrd(uart_dev_t *hw) { - return hw->sleep_conf2.active_threshold + UART_LL_WAKEUP_EDGE_THRED_MIN; + // HP UART: offset is 6, LP UART: offset is 3 + uint32_t offset = (hw == &LP_UART) ? UART_LL_WAKEUP_EDGE_THRED_MIN : UART_LL_WAKEUP_EDGE_THRED_MIN + 3; + return hw->sleep_conf2.active_threshold + offset; } /** diff --git a/examples/system/light_sleep/main/uart_wakeup.c b/examples/system/light_sleep/main/uart_wakeup.c index 79279e0a33..69a717ce2b 100644 --- a/examples/system/light_sleep/main/uart_wakeup.c +++ b/examples/system/light_sleep/main/uart_wakeup.c @@ -26,7 +26,8 @@ #define EXAMPLE_UART_BAUDRATE 115200 #endif -#define EXAMPLE_UART_WAKEUP_EDGE_THRESHOLD 3 +/* In ESP32, the min wakeup threshold is 2; in ESP32P4, the min wakeup threshold is 6; in other targets, the min wakeup threshold is 3.*/ +#define EXAMPLE_UART_WAKEUP_EDGE_THRESHOLD 6 #define EXAMPLE_UART_WAKEUP_FIFO_THRESHOLD 8 #define EXAMPLE_UART_WAKEUP_CHARS_SEQ "ok" #define EXAMPLE_UART_WAKEUP_CHARS_SEQ_LEN SOC_UART_WAKEUP_CHARS_SEQ_MAX_LEN diff --git a/examples/system/light_sleep/pytest_light_sleep.py b/examples/system/light_sleep/pytest_light_sleep.py index 84946901af..dc56b44325 100644 --- a/examples/system/light_sleep/pytest_light_sleep.py +++ b/examples/system/light_sleep/pytest_light_sleep.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: CC0-1.0 import logging import time @@ -32,7 +32,7 @@ def test_light_sleep(dut: Dut) -> None: # enter sleep second time dut.expect_exact(ENTERING_SLEEP_STR) match = dut.expect(EXIT_SLEEP_REGEX) - logging.info('Got second sleep period, wakeup from {}, slept for {}'.format(match.group(1), match.group(3))) + logging.info(f'Got second sleep period, wakeup from {match.group(1)}, slept for {match.group(3)}') # sleep time error should be less than 1ms # TODO: Need to update sleep overhead_out time for esp32c5 (PM-209) assert ( @@ -47,7 +47,7 @@ def test_light_sleep(dut: Dut) -> None: dut.serial.proc.setDTR(True) time.sleep(1) match = dut.expect(EXIT_SLEEP_PIN_REGEX) - logging.info('Got third sleep period, wakeup from {}, slept for {}'.format(match.group(1), match.group(3))) + logging.info(f'Got third sleep period, wakeup from {match.group(1)}, slept for {match.group(3)}') assert int(match.group(3)) < WAKEUP_INTERVAL_MS dut.expect(WAITING_FOR_GPIO_STR) @@ -57,11 +57,11 @@ def test_light_sleep(dut: Dut) -> None: dut.expect_exact(ENTERING_SLEEP_STR) logging.info('Went to sleep again') - # Write 'a' to uart, 'a' in ascii is 0x61 which contains 3 rising edges in total (including the stop bit) - dut.write('a') + # Write 'tt' to uart, 'tt' in ascii is 0x74 0x74 which contains 6 rising edges in total (including the stop bit) + dut.serial.proc.write(b'tt') time.sleep(1) match = dut.expect(EXIT_SLEEP_UART_REGEX) - logging.info('Got third sleep period, wakeup from {}, slept for {}'.format(match.group(1), match.group(3))) + logging.info(f'Got third sleep period, wakeup from {match.group(1)}, slept for {match.group(3)}') assert int(match.group(3)) < WAKEUP_INTERVAL_MS logging.info('Went to sleep again')