From f596e42dcd46a6c05cfe815899a9317924e741c0 Mon Sep 17 00:00:00 2001 From: hebinglin Date: Thu, 5 Mar 2026 17:32:46 +0800 Subject: [PATCH] change(example): change uart wakeup mode 0 edge threshold --- components/hal/esp32p4/include/hal/uart_ll.h | 12 ++++++++---- examples/system/light_sleep/main/uart_wakeup.c | 3 ++- examples/system/light_sleep/pytest_light_sleep.py | 4 ++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/components/hal/esp32p4/include/hal/uart_ll.h b/components/hal/esp32p4/include/hal/uart_ll.h index bc76a4cd79..0e217e98f7 100644 --- a/components/hal/esp32p4/include/hal/uart_ll.h +++ b/components/hal/esp32p4/include/hal/uart_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -1026,8 +1026,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_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_MIN_WAKEUP_THRESH; + // 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_MIN_WAKEUP_THRESH : UART_LL_MIN_WAKEUP_THRESH + 3; + hw->sleep_conf2.active_threshold = wakeup_thrd - offset; } /** @@ -1229,7 +1231,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_thrd(uart_dev_t *hw) { - return hw->sleep_conf2.active_threshold + UART_LL_MIN_WAKEUP_THRESH; + // HP UART: offset is 6, LP UART: offset is 3 + uint32_t offset = (hw == &LP_UART) ? UART_LL_MIN_WAKEUP_THRESH : UART_LL_MIN_WAKEUP_THRESH + 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 40da34ded6..82fd944d30 100644 --- a/examples/system/light_sleep/main/uart_wakeup.c +++ b/examples/system/light_sleep/main/uart_wakeup.c @@ -24,7 +24,8 @@ #define EXAMPLE_UART_BAUDRATE 115200 #endif -#define EXAMPLE_UART_WAKEUP_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_THRESHOLD 6 #define EXAMPLE_READ_BUF_SIZE 1024 #define EXAMPLE_UART_BUF_SIZE (EXAMPLE_READ_BUF_SIZE * 2) diff --git a/examples/system/light_sleep/pytest_light_sleep.py b/examples/system/light_sleep/pytest_light_sleep.py index 698138469e..ae43073ae0 100644 --- a/examples/system/light_sleep/pytest_light_sleep.py +++ b/examples/system/light_sleep/pytest_light_sleep.py @@ -53,8 +53,8 @@ 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)))