Function esp_idf_svc::hal::sys::uart_set_wakeup_threshold
source · pub unsafe extern "C" fn uart_set_wakeup_threshold(
uart_num: u32,
wakeup_threshold: i32,
) -> i32
Expand description
@brief Set the number of RX pin signal edges for light sleep wakeup
UART can be used to wake up the system from light sleep. This feature works by counting the number of positive edges on RX pin and comparing the count to the threshold. When the count exceeds the threshold, system is woken up from light sleep. This function allows setting the threshold value.
Stop bit and parity bits (if enabled) also contribute to the number of edges. For example, letter ‘a’ with ASCII code 97 is encoded as 0100001101 on the wire (with 8n1 configuration), start and stop bits included. This sequence has 3 positive edges (transitions from 0 to 1). Therefore, to wake up the system when ‘a’ is sent, set wakeup_threshold=3.
The character that triggers wakeup is not received by UART (i.e. it can not
be obtained from UART FIFO). Depending on the baud rate, a few characters
after that will also not be received. Note that when the chip enters and exits
light sleep mode, APB frequency will be changing. To ensure that UART has
correct Baud rate all the time, it is necessary to select a source clock which has
a fixed frequency and remains active during sleep. For the supported clock sources
of the chips, please refer to uart_sclk_t
or soc_periph_uart_clk_src_legacy_t
@note in ESP32, the wakeup signal can only be input via IO_MUX (i.e. GPIO3 should be configured as function_1 to wake up UART0, GPIO9 should be configured as function_5 to wake up UART1), UART2 does not support light sleep wakeup feature.
@param uart_num UART number, the max port number is (UART_NUM_MAX -1). @param wakeup_threshold number of RX edges for light sleep wakeup, value is 3 .. 0x3ff. @return - ESP_OK on success - ESP_ERR_INVALID_ARG if uart_num is incorrect or wakeup_threshold is outside of [3, 0x3ff] range.