From 4b111d8b45477601f67f0b681c21d4b0821ddb9d Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Wed, 22 Oct 2025 17:56:05 +0300 Subject: [PATCH 1/4] app: apply upstream CMUX buffer Kconfig changes Upstream Kconfig options for CMUX buffer sizes have changed. Try to align to 4 x CMUX packet size as default buffer. Signed-off-by: Seppo Takalo --- app/overlay-ppp-cmux-linux.conf | 8 +++----- app/src/sm_cmux.c | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/overlay-ppp-cmux-linux.conf b/app/overlay-ppp-cmux-linux.conf index 0f42879..9cc2452 100644 --- a/app/overlay-ppp-cmux-linux.conf +++ b/app/overlay-ppp-cmux-linux.conf @@ -9,13 +9,11 @@ CONFIG_SM_CMUX=y CONFIG_SM_PPP=y CONFIG_MODEM_CMUX_MTU=127 -CONFIG_MODEM_CMUX_WORK_BUFFER_SIZE=536 +CONFIG_MODEM_CMUX_WORK_BUFFER_SIZE_EXTRA=399 -# With CMUX, the UART buffers should be at least the size of the -# CONFIG_MODEM_CMUX_WORK_BUFFER_SIZE CONFIG_SM_UART_RX_BUF_COUNT=3 -CONFIG_SM_UART_RX_BUF_SIZE=256 -CONFIG_SM_UART_TX_BUF_SIZE=768 +CONFIG_SM_UART_RX_BUF_SIZE=532 +CONFIG_SM_UART_TX_BUF_SIZE=532 # When using PPP, disable commands of IP-based protocols to save flash space. CONFIG_SM_FTPC=n diff --git a/app/src/sm_cmux.c b/app/src/sm_cmux.c index bad9550..4ac8bc9 100644 --- a/app/src/sm_cmux.c +++ b/app/src/sm_cmux.c @@ -38,8 +38,8 @@ static struct { /* CMUX */ struct modem_cmux instance; - uint8_t cmux_receive_buf[CONFIG_MODEM_CMUX_WORK_BUFFER_SIZE]; - uint8_t cmux_transmit_buf[CONFIG_MODEM_CMUX_WORK_BUFFER_SIZE]; + uint8_t cmux_receive_buf[MODEM_CMUX_WORK_BUFFER_SIZE]; + uint8_t cmux_transmit_buf[MODEM_CMUX_WORK_BUFFER_SIZE]; /* CMUX channels (Data Link Connection Identifier); index = address - 1 */ struct cmux_dlci { From 3a697f37dd60d362c7cfd68a4caa7c4c9cfd0853 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Thu, 30 Oct 2025 09:51:36 +0200 Subject: [PATCH 2/4] manifest: Test against cherry-pick PR Test against https://github.com/nrfconnect/sdk-nrf/pull/25308 Signed-off-by: Seppo Takalo --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 7c620f3..1c90013 100644 --- a/west.yml +++ b/west.yml @@ -14,5 +14,5 @@ manifest: - name: nrf remote: ncs repo-path: sdk-nrf - revision: v3.2.0-preview2 + revision: pull/25308/head import: true From b5de17359d39f1c509da109da88dbad8f1bf6836 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Thu, 30 Oct 2025 13:46:53 +0200 Subject: [PATCH 3/4] app: cmux: Drop URC when pipe is closed When there is no reading end on DLCI pipe, drop URC messages. Signed-off-by: Seppo Takalo --- app/src/sm_cmux.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/src/sm_cmux.c b/app/src/sm_cmux.c index 4ac8bc9..ffd55b0 100644 --- a/app/src/sm_cmux.c +++ b/app/src/sm_cmux.c @@ -111,6 +111,9 @@ static void dlci_pipe_event_handler(struct modem_pipe *pipe, case MODEM_PIPE_EVENT_CLOSED: LOG_INF("DLCI %u%s closed.", dlci->address, is_at ? " (AT)" : ""); + if (is_at) { + k_sem_give(&cmux.tx_sem); + } break; case MODEM_PIPE_EVENT_RECEIVE_READY: @@ -120,8 +123,7 @@ static void dlci_pipe_event_handler(struct modem_pipe *pipe, break; case MODEM_PIPE_EVENT_TRANSMIT_IDLE: - if (is_at && - cmux.dlcis[cmux.at_channel].instance.state == MODEM_CMUX_DLCI_STATE_OPEN) { + if (is_at) { k_sem_give(&cmux.tx_sem); } break; @@ -162,14 +164,15 @@ static int cmux_write_at_channel_block(const uint8_t *data, size_t *len) ret = modem_pipe_transmit(cmux.dlcis[cmux.at_channel].pipe, data + sent, *len - sent); if (ret < 0) { - if (ret != -EPERM) { - /* Pipe is open, but failed. */ - LOG_ERR("DLCI %u (AT) transmit failed (%d).", - INDEX_TO_DLCI(cmux.at_channel), ret); - } - *len = sent; + LOG_ERR("DLCI %u (AT) transmit failed (%d).", + INDEX_TO_DLCI(cmux.at_channel), ret); return ret; } else if (ret == 0) { + if (cmux.dlcis[cmux.at_channel].instance.state != + MODEM_CMUX_DLCI_STATE_OPEN) { + /* Drop URC when pipe is closed */ + return 0; + } /* Pipe TX buffer full. Wait for transmit idle event. */ k_sem_take(&cmux.tx_sem, K_FOREVER); } else { From 8c00376e64102f9cb74d272826eb14dd449e6ccb Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Thu, 30 Oct 2025 14:58:53 +0200 Subject: [PATCH 4/4] app: scripts: Try to recover CMUX if AT command fails If the "AT" "OK" sequence fails on the start up script, it might be that the modem is already in CMUX mode. Try recovering the CMUX pipe by sending flag characters followed by CMUX Close Down message. The CMUX is then re-established by SABM message normally. Signed-off-by: Seppo Takalo --- app/scripts/sm_start_ppp.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/scripts/sm_start_ppp.sh b/app/scripts/sm_start_ppp.sh index b540898..2d87d66 100755 --- a/app/scripts/sm_start_ppp.sh +++ b/app/scripts/sm_start_ppp.sh @@ -44,10 +44,17 @@ fi stty -F $MODEM $BAUD pass8 raw crtscts clocal echo "Wait modem to boot" -chat -t5 "" "AT" "OK" <$MODEM >$MODEM || true - -echo "Attach CMUX channel to modem..." -ldattach -c $'AT#XCMUX=1\r' GSM0710 $MODEM +if chat -t5 "" "AT" "OK" <$MODEM >$MODEM; then + echo "Modem is in AT mode" + echo "Attach CMUX channel to modem..." + ldattach -c $'AT#XCMUX=1\r' GSM0710 $MODEM +else + echo "Modem not responding, try CMUX resync..." + printf "\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9" > $MODEM + printf "\xF9\x03\xEF\x05\xC3\x01\xF2\xF9" > $MODEM + echo "Attach CMUX channel to modem..." + ldattach GSM0710 $MODEM +fi sleep 1 stty -F $AT_CMUX clocal @@ -58,4 +65,4 @@ chat $CHATOPT -t$TIMEOUT "" "AT#XPPP=1" "OK" >$AT_CMUX <$AT_CMUX chat $CHATOPT -t$TIMEOUT "" "AT+CFUN=1" "OK" "\c" "#XPPP: 1,0" >$AT_CMUX <$AT_CMUX pppd $PPP_CMUX noauth novj nodeflate nobsdcomp debug noipdefault passive +ipv6 noremoteip \ - local linkname nrf91 defaultroute defaultroute-metric -1 persist lcp-echo-interval 0 + local linkname nrf91 defaultroute defaultroute-metric -1 lcp-echo-interval 0