diff --git a/app/Kconfig b/app/Kconfig index a3e49a02..216c21a1 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -288,7 +288,7 @@ config SM_CMUX config SM_CMUX_CHANNEL_COUNT int "Number of CMUX channels" depends on SM_CMUX - default 2 + default 4 range 1 63 help Number of channels to be used by the CMUX implementation. diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt index 53759c47..c282fbdc 100644 --- a/drivers/CMakeLists.txt +++ b/drivers/CMakeLists.txt @@ -3,3 +3,4 @@ # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause add_subdirectory_ifdef(CONFIG_DTR_UART dtr_uart) +add_subdirectory_ifdef(CONFIG_MODEM_NRF91SM nrf91-sm) diff --git a/drivers/Kconfig b/drivers/Kconfig index 6c84de8a..0e3435ed 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -5,4 +5,5 @@ menu "Drivers" rsource "dtr_uart/Kconfig" +rsource "nrf91-sm/Kconfig" endmenu diff --git a/drivers/nrf91-sm/CMakeLists.txt b/drivers/nrf91-sm/CMakeLists.txt new file mode 100644 index 00000000..e10e5555 --- /dev/null +++ b/drivers/nrf91-sm/CMakeLists.txt @@ -0,0 +1,8 @@ +# +# Copyright (c) 2026 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +zephyr_library() +zephyr_library_sources(nordic_nrf91sm.c) diff --git a/drivers/nrf91-sm/Kconfig b/drivers/nrf91-sm/Kconfig new file mode 100644 index 00000000..db557719 --- /dev/null +++ b/drivers/nrf91-sm/Kconfig @@ -0,0 +1,13 @@ +# +# Copyright (c) 2026 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + +config MODEM_NRF91SM + bool "Nordic nRF91 Serial Modem support" + default y + depends on DT_HAS_NORDIC_NRF91_SM_V2_ENABLED + select MODEM_CELLULAR + help + Modem driver for Nordic nRF91 series running + the Serial Modem application v2.0.0 or later. diff --git a/drivers/nrf91-sm/nordic_nrf91sm.c b/drivers/nrf91-sm/nordic_nrf91sm.c new file mode 100644 index 00000000..b02fa62d --- /dev/null +++ b/drivers/nrf91-sm/nordic_nrf91sm.c @@ -0,0 +1,71 @@ +#include +#include + +MODEM_CELLULAR_COMMON_CHAT_MATCHES(); + +MODEM_CELLULAR_UNSOL_DEFINE(nordic_nrf91_unsol, MODEM_CELLULAR_COMMON_UNSOL_MATCHES); + +MODEM_CHAT_MATCH_DEFINE(xiccid_match, "%XICCID: ", "", modem_cellular_chat_on_iccid); +MODEM_CHAT_MATCH_DEFINE(uicc_initialized, "%XSIM: 1", "", NULL); + +MODEM_CHAT_SCRIPT_CMDS_DEFINE( + init_chat_script_cmds, MODEM_CHAT_SCRIPT_CMD_RESP("AT", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CMEE=1", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGSN", imei_match), MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGMM", cgmm_match), MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGMI", cgmi_match), MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGMR", cgmr_match), MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT#XCMUXURC=1", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT%XSIM=1", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT%XSIM?\rAT+CFUN=41", uicc_initialized), + MODEM_CHAT_SCRIPT_CMD_RESP("AT%XICCID", xiccid_match), + MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), MODEM_CHAT_SCRIPT_CMD_RESP("AT+CIMI", cimi_match), + MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), MODEM_CHAT_SCRIPT_CMD_RESP("AT%XSIM=0", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CMUX=0", ok_match)); + +MODEM_CHAT_SCRIPT_DEFINE(init_chat_script, init_chat_script_cmds, abort_matches, + modem_cellular_chat_callback_handler, 10); + +MODEM_CHAT_SCRIPT_CMDS_DEFINE(network_cmds, MODEM_CHAT_SCRIPT_CMD_RESP("AT+CEREG=1", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CEREG?", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CFUN=1", ok_match)); + +MODEM_CHAT_SCRIPT_DEFINE(network_chat_script, network_cmds, abort_matches, + modem_cellular_chat_callback_handler, 10); + +MODEM_CHAT_SCRIPT_CMDS_DEFINE(dial_chat_script_cmds, + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGDATA", connect_match)); + +MODEM_CHAT_SCRIPT_DEFINE(dial_chat_script, dial_chat_script_cmds, abort_matches, + modem_cellular_chat_callback_handler, 10); + +MODEM_CHAT_SCRIPT_CMDS_DEFINE(shutdown_chat_script_cmds, + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CEREG=0", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CFUN=0", ok_match)); + +MODEM_CHAT_SCRIPT_DEFINE(shutdown_chat_script, shutdown_chat_script_cmds, abort_matches, + modem_cellular_chat_callback_handler, 10); + +static const struct modem_cellular_config_scripts nrf91_sm_scripts = { + .init = &init_chat_script, + .network = &network_chat_script, + .dial = &dial_chat_script, + .shutdown = &shutdown_chat_script, +}; + +#define NRF91SM_DEVICE(inst) \ + MODEM_DT_INST_PPP_DEFINE(inst, MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \ + \ + static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = { \ + .chat_delimiter = "\r\n", \ + .ppp = &MODEM_CELLULAR_INST_NAME(ppp, inst), \ + }; \ + \ + MODEM_CELLULAR_DEFINE_AND_INIT_USER_PIPES(inst, (user_pipe_0, 3), (user_pipe_1, 4)) \ + \ + MODEM_CELLULAR_DEFINE_INSTANCE(inst, 0, 500, 2000, 100, true, &nrf91_sm_scripts, \ + &nordic_nrf91_unsol) + +#define DT_DRV_COMPAT nordic_nrf91_sm_v2 +DT_INST_FOREACH_STATUS_OKAY(NRF91SM_DEVICE) +#undef DT_DRV_COMPAT diff --git a/dts/bindings/dte_dtr/nordic,dtr-dte.yaml b/dts/bindings/dte_dtr/nordic,dte-dtr.yaml similarity index 100% rename from dts/bindings/dte_dtr/nordic,dtr-dte.yaml rename to dts/bindings/dte_dtr/nordic,dte-dtr.yaml diff --git a/dts/bindings/nordic,nrf91-sm-v2.yaml b/dts/bindings/nordic,nrf91-sm-v2.yaml new file mode 100644 index 00000000..3d4e1a85 --- /dev/null +++ b/dts/bindings/nordic,nrf91-sm-v2.yaml @@ -0,0 +1,22 @@ +# Copyright (c) 2026 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +title: Nordic nRF91 Serial Modem + +description: | + Nordic nRF91 series running the Serial Modem application v2.0.0 or later. + This includes the nRF91M1 module. + +compatible: "nordic,nrf91-sm-v2" + +include: zephyr,cellular-modem-device.yaml + +properties: + zephyr,use-default-pdp-ctx: + default: 1 + + zephyr,mdm-reset-behavior: + default: ["toggle_on_recovery"] + + autostarts: + required: true diff --git a/samples/sm_ppp_shell/boards/nrf54l15dk_nrf54l15_cpuapp.conf b/samples/sm_ppp_shell/boards/nrf54l15dk_nrf54l15_cpuapp.conf index ac32e696..93143ef7 100644 --- a/samples/sm_ppp_shell/boards/nrf54l15dk_nrf54l15_cpuapp.conf +++ b/samples/sm_ppp_shell/boards/nrf54l15dk_nrf54l15_cpuapp.conf @@ -13,3 +13,8 @@ CONFIG_SHELL_BACKEND_SERIAL_API_ASYNC=y # For debugging purposes, enable GPIO shell commands. CONFIG_GPIO=y CONFIG_GPIO_SHELL=y + +CONFIG_SHELL_WILDCARD=n +CONFIG_MODEM_AT_SHELL=y +CONFIG_MODEM_AT_USER_PIPE_IDX=0 +CONFIG_MODEM_CMUX_MSC_FC_THRESHOLD=32 diff --git a/samples/sm_ppp_shell/boards/nrf54l15dk_nrf54l15_cpuapp.overlay b/samples/sm_ppp_shell/boards/nrf54l15dk_nrf54l15_cpuapp.overlay index c15b76a4..d64a6d03 100644 --- a/samples/sm_ppp_shell/boards/nrf54l15dk_nrf54l15_cpuapp.overlay +++ b/samples/sm_ppp_shell/boards/nrf54l15dk_nrf54l15_cpuapp.overlay @@ -24,6 +24,9 @@ zephyr,console = &uart20; zephyr,shell-uart = &uart20; }; + aliases { + modem = &modem; + }; }; /* Zephyr modem UART <-> nRF91 Serial Modem UART */ @@ -35,7 +38,7 @@ /* Nordic nRF91 Serial Modem configuration */ modem: modem { - compatible = "nordic,nrf91-slm"; + compatible = "nordic,nrf91-sm-v2"; status = "okay"; mdm-ring-gpios = <&gpio1 12 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; mdm-dtr-gpios = <&gpio1 11 GPIO_ACTIVE_LOW>; @@ -43,6 +46,7 @@ cmux-enable-runtime-power-save; cmux-close-pipe-on-power-save; cmux-idle-timeout-ms = <5000>; + autostarts; }; }; diff --git a/samples/sm_ppp_shell/boards/nrf54l15dk_nrf54l15_cpuapp_ns.conf b/samples/sm_ppp_shell/boards/nrf54l15dk_nrf54l15_cpuapp_ns.conf index f21f5ff5..9597ab1b 100644 --- a/samples/sm_ppp_shell/boards/nrf54l15dk_nrf54l15_cpuapp_ns.conf +++ b/samples/sm_ppp_shell/boards/nrf54l15dk_nrf54l15_cpuapp_ns.conf @@ -16,3 +16,8 @@ CONFIG_GPIO_SHELL=y # When building for /NS, silence TFM logs to avoid conflicts with modem UART. CONFIG_TFM_LOG_LEVEL_SILENCE=y + +CONFIG_SHELL_WILDCARD=n +CONFIG_MODEM_AT_SHELL=y +CONFIG_MODEM_AT_USER_PIPE_IDX=0 +CONFIG_MODEM_CMUX_MSC_FC_THRESHOLD=32 diff --git a/samples/sm_ppp_shell/boards/nrf54l15dk_nrf54l15_cpuapp_ns.overlay b/samples/sm_ppp_shell/boards/nrf54l15dk_nrf54l15_cpuapp_ns.overlay index c15b76a4..d64a6d03 100644 --- a/samples/sm_ppp_shell/boards/nrf54l15dk_nrf54l15_cpuapp_ns.overlay +++ b/samples/sm_ppp_shell/boards/nrf54l15dk_nrf54l15_cpuapp_ns.overlay @@ -24,6 +24,9 @@ zephyr,console = &uart20; zephyr,shell-uart = &uart20; }; + aliases { + modem = &modem; + }; }; /* Zephyr modem UART <-> nRF91 Serial Modem UART */ @@ -35,7 +38,7 @@ /* Nordic nRF91 Serial Modem configuration */ modem: modem { - compatible = "nordic,nrf91-slm"; + compatible = "nordic,nrf91-sm-v2"; status = "okay"; mdm-ring-gpios = <&gpio1 12 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; mdm-dtr-gpios = <&gpio1 11 GPIO_ACTIVE_LOW>; @@ -43,6 +46,7 @@ cmux-enable-runtime-power-save; cmux-close-pipe-on-power-save; cmux-idle-timeout-ms = <5000>; + autostarts; }; };