olliiiver / esp_lte_modem

ESP32 / esp-idf LTE UART modem library for sim7600 with cmux support
MIT License
56 stars 20 forks source link

The CMUX is not activate in the code #1

Open danguyensw opened 3 years ago

danguyensw commented 3 years ago

I tried to test the CMUX support on TTGO SIM7000G board, and saw the following issues:

danguyensw commented 3 years ago

Need to apply this patch to enable the CMUX setup form modem SIM7600 without exception

diff --git a/components/modem/src/bg96.c b/components/modem/src/bg96.c
index 19eb88c..c346cc7 100644
--- a/components/modem/src/bg96.c
+++ b/components/modem/src/bg96.c
@@ -538,12 +538,14 @@ modem_dce_t *bg96_init(modem_dte_t *dte)
     /* Sync between DTE and DCE */
     DCE_CHECK(esp_modem_dce_sync(&(bg96_dce->parent)) == ESP_OK, "sync failed", err_io);

+#ifndef CONFIG_EXAMPLE_MODEM_DEVICE_SIM7600
     /* CMUX */
     if (bg96_dce->parent.dte->cmux) {
         ESP_LOGI(DCE_TAG, "CMUX setup");
- //         esp_modem_start_cmux(dte); 
- //       DCE_CHECK(bg96_dce->parent.dte->change_mode(bg96_dce->parent.dte, 2) == ESP_OK, "CMUX failed", err_io);
+        esp_modem_start_cmux(dte);
+        DCE_CHECK(bg96_dce->parent.dte->change_mode(bg96_dce->parent.dte, 2) == ESP_OK, "CMUX failed", err_io);
     }
+#endif

     /* Close echo */
     DCE_CHECK(esp_modem_dce_echo(&(bg96_dce->parent), false) == ESP_OK, "close echo mode failed", err_io);
diff --git a/components/modem/src/sim7600.c b/components/modem/src/sim7600.c
index 84f9821..ecf3561 100644
--- a/components/modem/src/sim7600.c
+++ b/components/modem/src/sim7600.c
@@ -87,5 +87,15 @@ modem_dce_t *sim7600_init(modem_dte_t *dte)
     modem_dce_t *dce = bg96_init(dte);
     dte->dce->get_battery_status = sim7600_get_battery_status;
     dte->dce->setup_cmux = esp_modem_dce_setup_cmux;
+
+    /* CMUX */
+    if (dte->cmux) {
+        ESP_LOGI(DCE_TAG, "CMUX setup");
+        esp_modem_start_cmux(dte);
+        DCE_CHECK(dte->change_mode(dte, 2) == ESP_OK, "CMUX failed", err);
+    }
+
     return dce;
+err:
+    return NULL;
 }

But later in the esp_modem_dce_setup_cmux function, I got timeout

W (26734) pppos_example: Unknow line received: AT+CMUX=0
I (26794) bg96: CMUX command success
I (26794) bg96: enter CMUX mode ok
I (26804) dce_service: setup_cmux
E (28304) esp-modem: esp_modem_dte_send_sabm(447): process command timeout
E (28304) dce_service: esp_modem_dce_setup_cmux(127): send command failed
olliiiver commented 3 years ago

Hi. There is a line in pppos_client_main.c which is used to enable CMUX mode right after the modem has been initialised.