From e4575b20a14f29979ce15829265fa8403fe0bf45 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Tue, 25 Feb 2020 15:00:49 +0100 Subject: [PATCH 1/2] esp_modem: pppos_client modem to use uart with REF_TICK pppos_client example used the UART default clock configuration which might cause issues if power management enabled. Settings updated to UART_SCLK_REF_TICK Also need to explicitly disable RX interrupts in UART pattern detection mode. Closes https://github.com/espressif/esp-idf/issues/4801 --- .../pppos_client/components/modem/src/esp_modem.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/examples/protocols/pppos_client/components/modem/src/esp_modem.c b/examples/protocols/pppos_client/components/modem/src/esp_modem.c index 89f50fa3b9..5ce11d0920 100644 --- a/examples/protocols/pppos_client/components/modem/src/esp_modem.c +++ b/examples/protocols/pppos_client/components/modem/src/esp_modem.c @@ -137,6 +137,13 @@ static void esp_handle_uart_pattern(esp_modem_dte_t *esp_dte) */ static void esp_handle_uart_data(esp_modem_dte_t *esp_dte) { + if (esp_dte->parent.dce->mode != MODEM_PPP_MODE) { + ESP_LOGE(MODEM_TAG, "Error: Got data event in PPP mode"); + /* pattern detection mode -> ignore date event on uart + * (should never happen, but if it does, we could still + * read the valid data once pattern detect event fired) */ + return; + } size_t length = 0; uart_get_buffered_data_len(esp_dte->uart_port, &length); length = MIN(ESP_MODEM_LINE_BUFFER_SIZE, length); @@ -380,7 +387,7 @@ modem_dte_t *esp_modem_dte_init(const esp_modem_dte_config_t *config) .data_bits = config->data_bits, .parity = config->parity, .stop_bits = config->stop_bits, - .source_clk = UART_SCLK_APB, + .source_clk = UART_SCLK_REF_TICK, .flow_ctrl = (config->flow_control == MODEM_FLOW_CONTROL_HW) ? UART_HW_FLOWCTRL_CTS_RTS : UART_HW_FLOWCTRL_DISABLE }; /* Install UART driver and get event queue used inside driver */ @@ -410,6 +417,9 @@ modem_dte_t *esp_modem_dte_init(const esp_modem_dte_config_t *config) res = uart_enable_pattern_det_baud_intr(esp_dte->uart_port, '\n', 1, MIN_PATTERN_INTERVAL, MIN_POST_IDLE, MIN_PRE_IDLE); /* Set pattern queue size */ res |= uart_pattern_queue_reset(esp_dte->uart_port, CONFIG_EXAMPLE_UART_PATTERN_QUEUE_SIZE); + /* Starting in command mode -> explicitly disable RX interrupt */ + uart_disable_rx_intr(esp_dte->uart_port); + MODEM_CHECK(res == ESP_OK, "config uart pattern failed", err_uart_pattern); /* Create Event loop */ esp_event_loop_args_t loop_args = { From 21dc6d1bf12f5be5198a064eda955ce811883167 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Sat, 7 Mar 2020 10:25:01 +0800 Subject: [PATCH 2/2] esp_modem: Ensure uart_param_config and uart pins are set before uart_driver_install Fixes Guru Meditation Error: Core 0 panic'ed (LoadProhibited) when config with CONFIG_PM_ENABLE=y && CONFIG_PM_DFS_INIT_AUTO=y. Signed-off-by: Axel Lin Merges https://github.com/espressif/esp-idf/pull/4904 --- .../pppos_client/components/modem/src/esp_modem.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/protocols/pppos_client/components/modem/src/esp_modem.c b/examples/protocols/pppos_client/components/modem/src/esp_modem.c index 5ce11d0920..5510deda84 100644 --- a/examples/protocols/pppos_client/components/modem/src/esp_modem.c +++ b/examples/protocols/pppos_client/components/modem/src/esp_modem.c @@ -390,13 +390,6 @@ modem_dte_t *esp_modem_dte_init(const esp_modem_dte_config_t *config) .source_clk = UART_SCLK_REF_TICK, .flow_ctrl = (config->flow_control == MODEM_FLOW_CONTROL_HW) ? UART_HW_FLOWCTRL_CTS_RTS : UART_HW_FLOWCTRL_DISABLE }; - /* Install UART driver and get event queue used inside driver */ - res = uart_driver_install(esp_dte->uart_port, CONFIG_EXAMPLE_UART_RX_BUFFER_SIZE, CONFIG_EXAMPLE_UART_TX_BUFFER_SIZE, - CONFIG_EXAMPLE_UART_EVENT_QUEUE_SIZE, &(esp_dte->event_queue), 0); - MODEM_CHECK(res == ESP_OK, "install uart driver failed", err_uart_config); - res = uart_set_rx_timeout(esp_dte->uart_port, 1); - MODEM_CHECK(res == ESP_OK, "set rx timeout failed", err_uart_config); - MODEM_CHECK(uart_param_config(esp_dte->uart_port, &uart_config) == ESP_OK, "config uart parameter failed", err_uart_config); if (config->flow_control == MODEM_FLOW_CONTROL_HW) { res = uart_set_pin(esp_dte->uart_port, CONFIG_EXAMPLE_UART_MODEM_TX_PIN, CONFIG_EXAMPLE_UART_MODEM_RX_PIN, @@ -413,6 +406,13 @@ modem_dte_t *esp_modem_dte_init(const esp_modem_dte_config_t *config) res = uart_set_sw_flow_ctrl(esp_dte->uart_port, true, 8, UART_FIFO_LEN - 8); } MODEM_CHECK(res == ESP_OK, "config uart flow control failed", err_uart_config); + /* Install UART driver and get event queue used inside driver */ + res = uart_driver_install(esp_dte->uart_port, CONFIG_EXAMPLE_UART_RX_BUFFER_SIZE, CONFIG_EXAMPLE_UART_TX_BUFFER_SIZE, + CONFIG_EXAMPLE_UART_EVENT_QUEUE_SIZE, &(esp_dte->event_queue), 0); + MODEM_CHECK(res == ESP_OK, "install uart driver failed", err_uart_config); + res = uart_set_rx_timeout(esp_dte->uart_port, 1); + MODEM_CHECK(res == ESP_OK, "set rx timeout failed", err_uart_config); + /* Set pattern interrupt, used to detect the end of a line. */ res = uart_enable_pattern_det_baud_intr(esp_dte->uart_port, '\n', 1, MIN_PATTERN_INTERVAL, MIN_POST_IDLE, MIN_PRE_IDLE); /* Set pattern queue size */