Page 1 of 1

ESP32C5 : Using esp_modem with LP_UART

Posted: Fri Mar 06, 2026 10:08 am
by guertby
Hello everyone,

I am developing a module with an ESP32C5 with esp-idf 5.5.2 framework and i need to use the LP_UART for communicate with a LTE modem.
I would like to take advantage of the C++ heritage of the esp_modem v2 component. For doing so, I develop a custom module and use this function (from esp_modem_c_api.cpp) :

Code: Select all

esp_modem_new_dev(ESP_MODEM_DCE_CUSTOM, &dte_config, &dce_config, g_stNetif);
I set the UART to LP_UART_NUM_0 and source_clk to LP_UART_SCLK_XTAL_D2.


My problem is in the esp_modem component, it uses uart_resource() (in esp_modem_term_uart.cpp). In this function, there is this code lines :

Code: Select all

    
    /* Install UART driver and get event queue used inside driver */
    res = uart_driver_install(config->port_num,
                              config->rx_buffer_size, config->tx_buffer_size,
                              config->event_queue_size, config->event_queue_size ?  event_queue : nullptr,
                              0);
    ESP_MODEM_THROW_IF_ERROR(res, "install uart driver failed");
    ESP_MODEM_THROW_IF_ERROR(uart_set_rx_timeout(config->port_num, 1), "set rx timeout failed");

    ESP_MODEM_THROW_IF_ERROR(uart_set_rx_full_threshold(config->port_num, 64), "config rx full threshold failed");

From this i got 2 question :

1. The most important for me : Why in uart_set_rx_full_threshold the threshold is set to a fix magic number 64 ?
for example in the uart_driver_install(), within the function will check whether it is an LP or HP UART and set accordingly, but here the 64 lead to an failing assert (because the 64 value is not compatible : the Rx Buffer of LP is 16 byte-length).

2. The second question is on the uart_driver_install() function : the last argument "int intr_alloc_flags" is set to 0. Shouldn't be check the config "CONFIG_UART_ISR_IN_IRAM" and set the argument accordingly to it ?



to continue making progress on my project i modifying these line like these :

Code: Select all

    int intr_alloc_flags = 0;
#if CONFIG_UART_ISR_IN_IRAM 
    intr_alloc_flags = ESP_INTR_FLAG_IRAM; 
#endif 

    /* Install UART driver and get event queue used inside driver */
    res = uart_driver_install(config->port_num,
                              config->rx_buffer_size, config->tx_buffer_size,
                              config->event_queue_size, config->event_queue_size ?  event_queue : nullptr,
                              intr_alloc_flags);
    ESP_MODEM_THROW_IF_ERROR(res, "install uart driver failed");
    ESP_MODEM_THROW_IF_ERROR(uart_set_rx_timeout(config->port_num, 1), "set rx timeout failed");

    ESP_MODEM_THROW_IF_ERROR(uart_set_rx_full_threshold(config->port_num, UART_HW_FIFO_LEN(config->port_num) / 2), "config rx full threshold failed");

But i would like to have an opinion on these. Is there a reason for the 64 hard value, like a modem is it likely to not work for a LP_UART ?

Thanks for your time.