Skip to content

Commit c262cab

Browse files
committed
app: PIPE interface to UART
Jira: SLM-134 Implement PIPE interface to Serial Modem UART to be able to use the same UART implementation for both pure AT-commands and for CMUXed AT-commands and PPP. Signed-off-by: Markus Lassila <markus.lassila@nordicsemi.no>
1 parent aaf201c commit c262cab

16 files changed

Lines changed: 546 additions & 257 deletions

app/overlay-cmux.conf

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,6 @@ CONFIG_SM_SKIP_READY_MSG=y
1111
CONFIG_MODEM_MODULES=y
1212
CONFIG_MODEM_CMUX=y
1313

14-
# Enable Serial Modem UART backend
15-
CONFIG_MODEM_BACKEND_UART=n
16-
CONFIG_MODEM_BACKEND_UART_ASYNC=n
17-
CONFIG_MODEM_BACKEND_UART_SLM=y
18-
CONFIG_MODEM_BACKEND_UART_SLM_TRANSMIT_TIMEOUT_MS=1000
19-
20-
# These buffers are unused after AT#CMUX is enabled
21-
# so use minimal buffer size
22-
CONFIG_SM_UART_RX_BUF_COUNT=2
23-
CONFIG_SM_UART_RX_BUF_SIZE=128
24-
CONFIG_SM_UART_TX_BUF_SIZE=128
25-
2614
# debug options
2715
#CONFIG_MODEM_CMUX_LOG_LEVEL_DBG=y
2816
#CONFIG_MODEM_MODULES_LOG_LEVEL_DBG=y

app/overlay-ppp-cmux-linux.conf

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,12 @@ CONFIG_SM_CR_TERMINATION=y
1111

1212
CONFIG_MODEM_CMUX_MTU=127
1313
CONFIG_MODEM_CMUX_WORK_BUFFER_SIZE=536
14-
CONFIG_SM_CMUX_UART_BUFFER_SIZE=600
1514

16-
# Enable Serial Modem UART backend
17-
CONFIG_MODEM_BACKEND_UART=n
18-
CONFIG_MODEM_BACKEND_UART_ASYNC=n
19-
CONFIG_MODEM_BACKEND_UART_SLM=y
20-
21-
# For sending full 600 bytes at 115200 baudrate
22-
# 600 * 10 / 115200 = 52.1 ms
23-
CONFIG_MODEM_BACKEND_UART_SLM_TRANSMIT_TIMEOUT_MS=53
24-
# Assume at least baudrate 115200 for UART
25-
# so CMUX frame can be received in 12 ms (134*10/115200)
26-
CONFIG_MODEM_BACKEND_UART_SLM_RECEIVE_IDLE_TIMEOUT_MS=12
27-
28-
# These buffers are unused after AT#CMUX is enabled
29-
# so use minimal buffer size
30-
CONFIG_SM_UART_RX_BUF_COUNT=2
31-
CONFIG_SM_UART_RX_BUF_SIZE=128
32-
CONFIG_SM_UART_TX_BUF_SIZE=128
15+
# With CMUX, the UART buffers should be at least the size of the
16+
# CONFIG_MODEM_CMUX_WORK_BUFFER_SIZE
17+
CONFIG_SM_UART_RX_BUF_COUNT=3
18+
CONFIG_SM_UART_RX_BUF_SIZE=256
19+
CONFIG_SM_UART_TX_BUF_SIZE=768
3320

3421
# When using PPP, disable commands of IP-based protocols to save flash space.
3522
CONFIG_SM_FTPC=n

app/overlay-ppp-without-cmux.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
#
3+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
4+
#
5+
6+
# Enable modem UART backend
7+
CONFIG_MODEM_BACKEND_UART=y
8+
CONFIG_MODEM_BACKEND_UART_ASYNC=y

app/overlay-ppp.conf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ CONFIG_NET_L2_PPP=y
2424
CONFIG_MODEM_MODULES=y
2525
CONFIG_MODEM_PPP=y
2626

27-
# Enable Serial Modem UART backend
28-
CONFIG_MODEM_BACKEND_UART=n
29-
CONFIG_MODEM_BACKEND_UART_ASYNC=n
30-
CONFIG_MODEM_BACKEND_UART_SLM=y
31-
CONFIG_MODEM_BACKEND_UART_SLM_TRANSMIT_TIMEOUT_MS=1000
32-
3327
# L2 protocol
3428
CONFIG_NET_L2_PPP_MGMT=y
3529
CONFIG_NET_L2_PPP_OPTION_MRU=y

app/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ CONFIG_SM_EXTERNAL_XTAL=n
133133
#CONFIG_SM_LOG_LEVEL_DBG=y
134134
#CONFIG_LOG_PRINTK=n
135135
#CONFIG_LOG_MODE_IMMEDIATE=y
136+
#CONFIG_DEBUG_OPTIMIZATIONS=y
136137

137138
# For using external GNSS antenna
138139
#CONFIG_MODEM_ANTENNA=y

app/sample.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ tests:
8585
build_only: true
8686
extra_args:
8787
- EXTRA_CONF_FILE="overlay-ppp.conf"
88+
- EXTRA_CONF_FILE="overlay-ppp-without-cmux.conf"
8889
- EXTRA_DTC_OVERLAY_FILE="overlay-ppp-without-cmux.overlay"
8990
platform_allow:
9091
- nrf9160dk/nrf9160/ns
@@ -104,6 +105,7 @@ tests:
104105
build_only: true
105106
extra_args:
106107
- EXTRA_CONF_FILE="overlay-ppp.conf"
108+
- EXTRA_CONF_FILE="overlay-ppp-without-cmux.conf"
107109
- EXTRA_DTC_OVERLAY_FILE="overlay-ppp-without-cmux.overlay"
108110
extra_configs:
109111
- CONFIG_SM_POWER_PIN=31

app/src/sm_at_commands.c

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -383,34 +383,34 @@ int sm_at_init(void)
383383

384384
err = sm_at_tcp_proxy_init();
385385
if (err) {
386-
LOG_ERR("TCP Server could not be initialized: %d", err);
386+
LOG_ERR("%s initialization failed (%d).", "TCP Server", err);
387387
return -EFAULT;
388388
}
389389
err = sm_at_udp_proxy_init();
390390
if (err) {
391-
LOG_ERR("UDP Server could not be initialized: %d", err);
391+
LOG_ERR("%s initialization failed (%d).", "UDP Server", err);
392392
return -EFAULT;
393393
}
394394
err = sm_at_socket_init();
395395
if (err) {
396-
LOG_ERR("TCPIP could not be initialized: %d", err);
396+
LOG_ERR("%s initialization failed (%d).", "Socket", err);
397397
return -EFAULT;
398398
}
399399
err = sm_at_icmp_init();
400400
if (err) {
401-
LOG_ERR("ICMP could not be initialized: %d", err);
401+
LOG_ERR("%s initialization failed (%d).", "ICMP", err);
402402
return -EFAULT;
403403
}
404404
#if defined(CONFIG_SM_SMS)
405405
err = sm_at_sms_init();
406406
if (err) {
407-
LOG_ERR("SMS could not be initialized: %d", err);
407+
LOG_ERR("%s initialization failed (%d).", "SMS", err);
408408
return -EFAULT;
409409
}
410410
#endif
411411
err = sm_at_fota_init();
412412
if (err) {
413-
LOG_ERR("FOTA could not be initialized: %d", err);
413+
LOG_ERR("%s initialization failed (%d).", "FOTA", err);
414414
return -EFAULT;
415415
}
416416
#if defined(CONFIG_SM_NRF_CLOUD)
@@ -419,63 +419,63 @@ int sm_at_init(void)
419419
/* Allow nRF Cloud initialization to fail as sometimes JWT is missing
420420
* especially during development.
421421
*/
422-
LOG_ERR("nRF Cloud could not be initialized: %d", err);
422+
LOG_ERR("%s initialization failed (%d).", "nRF Cloud", err);
423423
err = 0;
424424
}
425425
#endif
426426
#if defined(CONFIG_SM_GNSS)
427427
err = sm_at_gnss_init();
428428
if (err) {
429-
LOG_ERR("GNSS could not be initialized: %d", err);
429+
LOG_ERR("%s initialization failed (%d).", "GNSS", err);
430430
return -EFAULT;
431431
}
432432
#endif
433433
#if defined(CONFIG_SM_FTPC)
434434
err = sm_at_ftp_init();
435435
if (err) {
436-
LOG_ERR("FTP could not be initialized: %d", err);
436+
LOG_ERR("%s initialization failed (%d).", "FTP", err);
437437
return -EFAULT;
438438
}
439439
#endif
440440
#if defined(CONFIG_SM_MQTTC)
441441
err = sm_at_mqtt_init();
442442
if (err) {
443-
LOG_ERR("MQTT could not be initialized: %d", err);
443+
LOG_ERR("%s initialization failed (%d).", "MQTT", err);
444444
return -EFAULT;
445445
}
446446
#endif
447447
#if defined(CONFIG_SM_HTTPC)
448448
err = sm_at_httpc_init();
449449
if (err) {
450-
LOG_ERR("HTTP could not be initialized: %d", err);
450+
LOG_ERR("%s initialization failed (%d).", "HTTP", err);
451451
return -EFAULT;
452452
}
453453
#endif
454454
#if defined(CONFIG_SM_GPIO)
455455
err = sm_at_gpio_init();
456456
if (err) {
457-
LOG_ERR("GPIO could not be initialized: %d", err);
457+
LOG_ERR("%s initialization failed (%d).", "GPIO", err);
458458
return -EFAULT;
459459
}
460460
#endif
461461
#if defined(CONFIG_SM_TWI)
462462
err = sm_at_twi_init();
463463
if (err) {
464-
LOG_ERR("TWI could not be initialized: %d", err);
464+
LOG_ERR("%s initialization failed (%d).", "TWI", err);
465465
return -EFAULT;
466466
}
467467
#endif
468468
#if defined(CONFIG_SM_CARRIER)
469469
err = sm_at_carrier_init();
470470
if (err) {
471-
LOG_ERR("LwM2M carrier could not be initialized: %d", err);
471+
LOG_ERR("%s initialization failed (%d).", "LwM2M carrier", err);
472472
return -EFAULT;
473473
}
474474
#endif
475475
#if defined(CONFIG_LWM2M_CARRIER_SETTINGS)
476476
err = sm_at_carrier_cfg_init();
477477
if (err) {
478-
LOG_ERR("LwM2M carrier could not be initialized: %d", err);
478+
LOG_ERR("%s initialization failed (%d).", "LwM2M carrier", err);
479479
return -EFAULT;
480480
}
481481
#endif
@@ -485,7 +485,7 @@ int sm_at_init(void)
485485
#if defined(CONFIG_SM_PPP)
486486
err = sm_ppp_init();
487487
if (err) {
488-
LOG_ERR("PPP initialization failed. (%d)", err);
488+
LOG_ERR("%s initialization failed (%d).", "PPP", err);
489489
return err;
490490
}
491491
#endif
@@ -498,76 +498,79 @@ void sm_at_uninit(void)
498498

499499
err = sm_at_tcp_proxy_uninit();
500500
if (err) {
501-
LOG_WRN("TCP Server could not be uninitialized: %d", err);
501+
LOG_WRN("%s uninitialization failed (%d).", "TCP Server", err);
502502
}
503503
err = sm_at_udp_proxy_uninit();
504504
if (err) {
505-
LOG_WRN("UDP Server could not be uninitialized: %d", err);
505+
LOG_WRN("%s uninitialization failed (%d).", "UDP Server", err);
506506
}
507507
err = sm_at_socket_uninit();
508508
if (err) {
509-
LOG_WRN("TCPIP could not be uninitialized: %d", err);
509+
LOG_WRN("%s uninitialization failed (%d).", "Socket", err);
510510
}
511511
err = sm_at_icmp_uninit();
512512
if (err) {
513-
LOG_WRN("ICMP could not be uninitialized: %d", err);
513+
LOG_WRN("%s uninitialization failed (%d).", "ICMP", err);
514514
}
515515
#if defined(CONFIG_SM_SMS)
516516
err = sm_at_sms_uninit();
517517
if (err) {
518-
LOG_WRN("SMS could not be uninitialized: %d", err);
518+
LOG_WRN("%s uninitialization failed (%d).", "SMS", err);
519519
}
520520
#endif
521521
err = sm_at_fota_uninit();
522522
if (err) {
523-
LOG_WRN("FOTA could not be uninitialized: %d", err);
523+
LOG_WRN("%s uninitialization failed (%d).", "FOTA", err);
524524
}
525525
#if defined(CONFIG_SM_NRF_CLOUD)
526526
err = sm_at_nrfcloud_uninit();
527527
if (err) {
528-
LOG_WRN("nRF Cloud could not be uninitialized: %d", err);
528+
LOG_WRN("%s uninitialization failed (%d).", "nRF Cloud", err);
529529
}
530530
#endif
531531
#if defined(CONFIG_SM_GNSS)
532532
err = sm_at_gnss_uninit();
533533
if (err) {
534-
LOG_WRN("GNSS could not be uninitialized: %d", err);
534+
LOG_WRN("%s uninitialization failed (%d).", "GNSS", err);
535535
}
536536
#endif
537537
#if defined(CONFIG_SM_FTPC)
538538
err = sm_at_ftp_uninit();
539539
if (err) {
540-
LOG_WRN("FTP could not be uninitialized: %d", err);
540+
LOG_WRN("%s uninitialization failed (%d).", "FTP", err);
541541
}
542542
#endif
543543
#if defined(CONFIG_SM_MQTTC)
544544
err = sm_at_mqtt_uninit();
545545
if (err) {
546-
LOG_WRN("MQTT could not be uninitialized: %d", err);
546+
LOG_WRN("%s uninitialization failed (%d).", "MQTT", err);
547547
}
548548
#endif
549549
#if defined(CONFIG_SM_HTTPC)
550550
err = sm_at_httpc_uninit();
551551
if (err) {
552-
LOG_WRN("HTTP could not be uninitialized: %d", err);
552+
LOG_WRN("%s uninitialization failed (%d).", "HTTP", err);
553553
}
554554
#endif
555555
#if defined(CONFIG_SM_TWI)
556556
err = sm_at_twi_uninit();
557557
if (err) {
558-
LOG_ERR("TWI could not be uninit: %d", err);
558+
LOG_WRN("%s uninitialization failed (%d).", "TWI", err);
559559
}
560560
#endif
561561
#if defined(CONFIG_SM_GPIO)
562562
err = sm_at_gpio_uninit();
563563
if (err) {
564-
LOG_ERR("GPIO could not be uninit: %d", err);
564+
LOG_WRN("%s uninitialization failed (%d).", "GPIO", err);
565565
}
566566
#endif
567567
#if defined(CONFIG_SM_CARRIER)
568568
err = sm_at_carrier_uninit();
569569
if (err) {
570-
LOG_ERR("LwM2M carrier could not be uninitialized: %d", err);
570+
LOG_WRN("%s uninitialization failed (%d).", "LwM2M carrier", err);
571571
}
572572
#endif
573+
#if defined(CONFIG_SM_CMUX)
574+
sm_cmux_uninit();
575+
#endif
573576
}

0 commit comments

Comments
 (0)