diff --git a/drivers/modem/Kconfig.gsm b/drivers/modem/Kconfig.gsm index bd6c5ffcbb3..2177ba92a65 100644 --- a/drivers/modem/Kconfig.gsm +++ b/drivers/modem/Kconfig.gsm @@ -29,9 +29,6 @@ config MODEM_GSM_SIMCOM endchoice -config MODEM_GSM_UART_NAME - string "UART device name the modem is connected to" - config MODEM_GSM_RX_STACK_SIZE int "Size of the stack allocated for receiving data from modem" default 512 diff --git a/drivers/modem/gsm_ppp.c b/drivers/modem/gsm_ppp.c index 26e7f079d96..f38ab5e7600 100644 --- a/drivers/modem/gsm_ppp.c +++ b/drivers/modem/gsm_ppp.c @@ -4,6 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +#define DT_DRV_COMPAT zephyr_gsm_ppp + #include LOG_MODULE_REGISTER(modem_gsm, CONFIG_MODEM_LOG_LEVEL); @@ -24,6 +26,7 @@ LOG_MODULE_REGISTER(modem_gsm, CONFIG_MODEM_LOG_LEVEL); #include +#define GSM_UART_NODE DT_INST_BUS(0) #define GSM_CMD_READ_BUF 128 #define GSM_CMD_AT_TIMEOUT K_SECONDS(2) #define GSM_CMD_SETUP_TIMEOUT K_SECONDS(6) @@ -522,8 +525,7 @@ static struct net_if *ppp_net_if(void) static void set_ppp_carrier_on(struct gsm_modem *gsm) { static const struct ppp_api *api; - const struct device *ppp_dev = - device_get_binding(CONFIG_NET_PPP_DRV_NAME); + const struct device *ppp_dev = DEVICE_DT_GET(DT_INST(0, zephyr_gsm_ppp)); struct net_if *iface = gsm->iface; int ret; @@ -821,7 +823,7 @@ static void mux_setup(struct k_work *work) { struct gsm_modem *gsm = CONTAINER_OF(work, struct gsm_modem, gsm_configure_work); - const struct device *uart = device_get_binding(CONFIG_MODEM_GSM_UART_NAME); + const struct device *uart = DEVICE_DT_GET(GSM_UART_NODE); int ret; /* We need to call this to reactivate mux ISR. Note: This is only called @@ -980,7 +982,7 @@ void gsm_ppp_start(const struct device *dev) /* Re-init underlying UART comms */ int r = modem_iface_uart_init_dev(&gsm->context.iface, - device_get_binding(CONFIG_MODEM_GSM_UART_NAME)); + DEVICE_DT_GET(GSM_UART_NODE)); if (r) { LOG_ERR("modem_iface_uart_init returned %d", r); return; @@ -1057,7 +1059,7 @@ static int gsm_init(const struct device *dev) gsm->gsm_data.rx_rb_buf_len = sizeof(gsm->gsm_rx_rb_buf); r = modem_iface_uart_init(&gsm->context.iface, &gsm->gsm_data, - device_get_binding(CONFIG_MODEM_GSM_UART_NAME)); + DEVICE_DT_GET(GSM_UART_NODE)); if (r < 0) { LOG_DBG("iface uart error %d", r); return r; @@ -1091,5 +1093,5 @@ static int gsm_init(const struct device *dev) return 0; } -DEVICE_DEFINE(gsm_ppp, GSM_MODEM_DEVICE_NAME, gsm_init, NULL, &gsm, NULL, - POST_KERNEL, CONFIG_MODEM_GSM_INIT_PRIORITY, NULL); +DEVICE_DT_DEFINE(DT_INST(0, zephyr_gsm_ppp), gsm_init, NULL, &gsm, NULL, + POST_KERNEL, CONFIG_MODEM_GSM_INIT_PRIORITY, NULL); diff --git a/drivers/net/ppp.c b/drivers/net/ppp.c index 8b99b061339..f38bc104abb 100644 --- a/drivers/net/ppp.c +++ b/drivers/net/ppp.c @@ -862,7 +862,7 @@ static int ppp_start(const struct device *dev) dev_name = mux->name; #elif IS_ENABLED(CONFIG_MODEM_GSM_PPP) - dev_name = CONFIG_MODEM_GSM_UART_NAME; + dev_name = DT_BUS_LABEL(DT_INST(0, zephyr_gsm_ppp)); #else dev_name = CONFIG_NET_PPP_UART_NAME; #endif diff --git a/dts/bindings/modem/zephyr,gsm-ppp.yaml b/dts/bindings/modem/zephyr,gsm-ppp.yaml new file mode 100644 index 00000000000..768173d6270 --- /dev/null +++ b/dts/bindings/modem/zephyr,gsm-ppp.yaml @@ -0,0 +1,8 @@ +# Copyright (c) 2021 G-Technologies Sdn. Bhd. +# SPDX-License-Identifier: Apache-2.0 + +description: GSM PPP modem + +compatible: "zephyr,gsm-ppp" + +include: uart-device.yaml diff --git a/include/drivers/gsm_ppp.h b/include/drivers/gsm_ppp.h index e19c711b2b2..2be4e32785b 100644 --- a/include/drivers/gsm_ppp.h +++ b/include/drivers/gsm_ppp.h @@ -7,8 +7,6 @@ #ifndef GSM_PPP_H_ #define GSM_PPP_H_ -#define GSM_MODEM_DEVICE_NAME "modem_gsm" - /** @cond INTERNAL_HIDDEN */ struct device; void gsm_ppp_start(const struct device *dev); diff --git a/samples/net/cloud/tagoio_http_post/README.rst b/samples/net/cloud/tagoio_http_post/README.rst index a63f6611def..62a8491b618 100644 --- a/samples/net/cloud/tagoio_http_post/README.rst +++ b/samples/net/cloud/tagoio_http_post/README.rst @@ -87,17 +87,27 @@ Modem The Modem support is quite similar to WIFI, you need a board with an embedded Modem support or you can add a shield. Currently, the overlay was created to allow modems with PPP support. This was tested using ``SIMcom SIM808 EVB``. -Additionally you need fill ``CONFIG_MODEM_GSM_UART_NAME`` with the UART label -``CONFIG_MODEM_GSM_APN`` with the correspondent Access Point Name (APN) at -:zephyr_file:`samples/net/cloud/tagoio_http_post/overlay-modem.conf` file. +Additionally you need fill ``CONFIG_MODEM_GSM_APN`` with the correspondent Access +Point Name (APN) at +:zephyr_file:`samples/net/cloud/tagoio_http_post/overlay-modem.conf` file. A +DTC overlay file should be used to configure the glue between the modem and the +uart port. It can reside at boards directory, with the board name, or it can be +a special designator like defined at ``arduino.overlay``. .. zephyr-app-commands:: :zephyr-app: samples/net/cloud/tagoio_http_post - :board: [sam4e_xpro | frdm_k64f] + :board: sam4e_xpro :gen-args: -DOVERLAY_CONFIG=overlay-modem.conf :goals: build flash :compact: +.. zephyr-app-commands:: + :zephyr-app: samples/net/cloud/tagoio_http_post + :board: frdm_k64f + :gen-args: -DOVERLAY_CONFIG=overlay-modem.conf -DDTC_OVERLAY_FILE=arduino.overlay + :goals: build flash + :compact: + In a terminal window you can check if communication is happen: .. code-block:: console diff --git a/samples/net/cloud/tagoio_http_post/arduino.overlay b/samples/net/cloud/tagoio_http_post/arduino.overlay new file mode 100644 index 00000000000..8a0500688b5 --- /dev/null +++ b/samples/net/cloud/tagoio_http_post/arduino.overlay @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2021 G-Technologies Sdn. Bhd. + * + * SPDX-License-Identifier: Apache-2.0 + */ + + &arduino_serial { + status = "okay"; + current-speed = <115200>; + + gsm: gsm-modem { + compatible = "zephyr,gsm-ppp"; + label = "gsm_ppp"; + }; +}; diff --git a/samples/net/cloud/tagoio_http_post/boards/sam4e_xpro.overlay b/samples/net/cloud/tagoio_http_post/boards/sam4e_xpro.overlay new file mode 100644 index 00000000000..765bc69e9fb --- /dev/null +++ b/samples/net/cloud/tagoio_http_post/boards/sam4e_xpro.overlay @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2021 G-Technologies Sdn. Bhd. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&usart1 { + status = "okay"; + current-speed = <115200>; + + gsm: gsm-modem { + compatible = "zephyr,gsm-ppp"; + label = "gsm_ppp"; + }; +}; diff --git a/samples/net/cloud/tagoio_http_post/overlay-modem.conf b/samples/net/cloud/tagoio_http_post/overlay-modem.conf index 274e8089251..cc14875d751 100644 --- a/samples/net/cloud/tagoio_http_post/overlay-modem.conf +++ b/samples/net/cloud/tagoio_http_post/overlay-modem.conf @@ -7,7 +7,6 @@ CONFIG_MODEM_SHELL=y CONFIG_MODEM_CMD_HANDLER_MAX_PARAM_COUNT=20 CONFIG_MODEM_GSM_PPP=y CONFIG_MODEM_GSM_RX_STACK_SIZE=1024 -CONFIG_MODEM_GSM_UART_NAME="" CONFIG_MODEM_GSM_APN="" # Network management events diff --git a/samples/net/cloud/tagoio_http_post/sample.yaml b/samples/net/cloud/tagoio_http_post/sample.yaml index 83f96fd3e08..cfa0e606d6c 100644 --- a/samples/net/cloud/tagoio_http_post/sample.yaml +++ b/samples/net/cloud/tagoio_http_post/sample.yaml @@ -16,4 +16,7 @@ tests: platform_allow: frdm_k64f nucleo_f767zi sample.net.cloud.tagoio_http_post.modem: extra_args: OVERLAY_CONFIG="overlay-modem.conf" - platform_allow: sam4e_xpro frdm_k64f + platform_allow: sam4e_xpro + sample.net.cloud.tagoio_http_post.modem.arduino: + extra_args: OVERLAY_CONFIG="overlay-modem.conf" DTC_OVERLAY_FILE="arduino.overlay" + platform_allow: frdm_k64f diff --git a/samples/net/gsm_modem/boards/frdm_uart2_dts.overlay b/samples/net/gsm_modem/boards/frdm_uart2_dts.overlay index 19b52ac01c1..223cf88348c 100644 --- a/samples/net/gsm_modem/boards/frdm_uart2_dts.overlay +++ b/samples/net/gsm_modem/boards/frdm_uart2_dts.overlay @@ -6,4 +6,8 @@ &uart2 { status = "okay"; current-speed = <115200>; + gsm: gsm-modem { + compatible = "zephyr,gsm-ppp"; + label = "gsm_ppp"; + }; }; diff --git a/samples/net/gsm_modem/prj.conf b/samples/net/gsm_modem/prj.conf index 390c3b55a41..36e5996e08e 100644 --- a/samples/net/gsm_modem/prj.conf +++ b/samples/net/gsm_modem/prj.conf @@ -4,7 +4,6 @@ CONFIG_SERIAL=y # GSM modem support CONFIG_MODEM=y CONFIG_MODEM_GSM_PPP=y -CONFIG_MODEM_GSM_UART_NAME="UART_1" # PPP networking support CONFIG_NET_PPP=y diff --git a/samples/net/gsm_modem/sample.yaml b/samples/net/gsm_modem/sample.yaml index ba76853d2a7..79d6bc116c5 100644 --- a/samples/net/gsm_modem/sample.yaml +++ b/samples/net/gsm_modem/sample.yaml @@ -2,6 +2,8 @@ common: harness: net depends_on: serial-net tags: net ppp modem gsm + platform_allow: frdm_k64f + extra_args: DTC_OVERLAY_FILE="boards/frdm_uart2_dts.overlay" sample: description: Sample for generic GSM modem name: Generic GSM modem using PPP diff --git a/samples/net/gsm_modem/src/main.c b/samples/net/gsm_modem/src/main.c index 1fcd553a98c..52fa17a418f 100644 --- a/samples/net/gsm_modem/src/main.c +++ b/samples/net/gsm_modem/src/main.c @@ -93,13 +93,14 @@ static void event_handler(struct net_mgmt_event_callback *cb, int main(void) { const struct device *uart_dev = - device_get_binding(CONFIG_MODEM_GSM_UART_NAME); + DEVICE_DT_GET(DT_BUS(DT_INST(0, zephyr_gsm_ppp))); - gsm_dev = device_get_binding(GSM_MODEM_DEVICE_NAME); + gsm_dev = DEVICE_DT_GET(DT_INST(0, zephyr_gsm_ppp)); LOG_INF("Board '%s' APN '%s' UART '%s' device %p (%s)", CONFIG_BOARD, CONFIG_MODEM_GSM_APN, - CONFIG_MODEM_GSM_UART_NAME, uart_dev, GSM_MODEM_DEVICE_NAME); + DT_BUS_LABEL(DT_INST(0, zephyr_gsm_ppp)), uart_dev, + gsm_dev->name); net_mgmt_init_event_callback(&mgmt_cb, event_handler, NET_EVENT_L4_CONNECTED | diff --git a/samples/subsys/mgmt/updatehub/arduino.overlay b/samples/subsys/mgmt/updatehub/arduino.overlay index 65a62ceb872..8a38feb5e54 100644 --- a/samples/subsys/mgmt/updatehub/arduino.overlay +++ b/samples/subsys/mgmt/updatehub/arduino.overlay @@ -6,7 +6,9 @@ &arduino_serial { status = "okay"; - label = "arduino_serial"; - current-speed = <115200>; + gsm: gsm-modem { + compatible = "zephyr,gsm-ppp"; + label = "gsm_ppp"; + }; }; diff --git a/samples/subsys/mgmt/updatehub/overlay-modem.conf b/samples/subsys/mgmt/updatehub/overlay-modem.conf index 721afd08afa..c21f4f1ce13 100644 --- a/samples/subsys/mgmt/updatehub/overlay-modem.conf +++ b/samples/subsys/mgmt/updatehub/overlay-modem.conf @@ -15,7 +15,6 @@ CONFIG_SERIAL=y CONFIG_MODEM=y CONFIG_MODEM_SHELL=y CONFIG_MODEM_GSM_PPP=y -CONFIG_MODEM_GSM_UART_NAME="arduino_serial" CONFIG_MODEM_GSM_APN="" # PPP networking support diff --git a/samples/subsys/mgmt/updatehub/src/main.c b/samples/subsys/mgmt/updatehub/src/main.c index 2f5c9f8b713..6b012f4671a 100644 --- a/samples/subsys/mgmt/updatehub/src/main.c +++ b/samples/subsys/mgmt/updatehub/src/main.c @@ -139,10 +139,10 @@ void main(void) #elif defined(CONFIG_MODEM_GSM_PPP) const struct device *uart_dev = - device_get_binding(CONFIG_MODEM_GSM_UART_NAME); + DEVICE_DT_GET(DT_BUS(DT_INST(0, zephyr_gsm_ppp))); LOG_INF("APN '%s' UART '%s' device %p", CONFIG_MODEM_GSM_APN, - CONFIG_MODEM_GSM_UART_NAME, uart_dev); + DT_BUS_LABEL(DT_INST(0, zephyr_gsm_ppp)), uart_dev); #endif net_mgmt_init_event_callback(&mgmt_cb, event_handler, EVENT_MASK); diff --git a/tests/drivers/build_all/modem/modem.conf b/tests/drivers/build_all/modem/modem.conf index 8971cfee4a9..7e2494597d3 100644 --- a/tests/drivers/build_all/modem/modem.conf +++ b/tests/drivers/build_all/modem/modem.conf @@ -15,4 +15,3 @@ CONFIG_MODEM_HL7800_APN_NAME="internet" CONFIG_MODEM_HL7800_RAT_M1=y CONFIG_MODEM_WNCM14A2A=y CONFIG_MODEM_GSM_PPP=y -CONFIG_MODEM_GSM_UART_NAME="TEST_UART_CTLR" diff --git a/tests/drivers/build_all/modem/uart.dtsi b/tests/drivers/build_all/modem/uart.dtsi index 47cc4de2c6a..2384b8d0183 100644 --- a/tests/drivers/build_all/modem/uart.dtsi +++ b/tests/drivers/build_all/modem/uart.dtsi @@ -45,3 +45,8 @@ test_quectel_bg9x: quectel_bg9x { mdm-power-gpios = <&test_gpio 0 0>; mdm-reset-gpios = <&test_gpio 0 0>; }; + +test_gsm_ppp: gsm_ppp { + compatible = "zephyr,gsm-ppp"; + label = "gsm_ppp"; +};