From 10fb64f4dc12ef9465eb69d7ea402fa4b3df9f70 Mon Sep 17 00:00:00 2001 From: Patrik Flykt Date: Wed, 22 Jan 2020 15:10:27 +0200 Subject: [PATCH] samples: net: Create sample app for GSM modems Sample app compiled with the GSM modem driver enabling PPP. This sample was tested with a Reel Board UART_1 connected via the external board/connector and a FONA 808 modem. Reel board specific suppor is found in boards/. Signed-off-by: Patrik Flykt --- samples/net/gsm_modem/CMakeLists.txt | 11 +++++ samples/net/gsm_modem/boards/reel_board.conf | 2 + samples/net/gsm_modem/frdm_uart2_dts.overlay | 9 ++++ samples/net/gsm_modem/prj.conf | 34 +++++++++++++ samples/net/gsm_modem/src/main.c | 52 ++++++++++++++++++++ 5 files changed, 108 insertions(+) create mode 100644 samples/net/gsm_modem/CMakeLists.txt create mode 100644 samples/net/gsm_modem/boards/reel_board.conf create mode 100644 samples/net/gsm_modem/frdm_uart2_dts.overlay create mode 100644 samples/net/gsm_modem/prj.conf create mode 100644 samples/net/gsm_modem/src/main.c diff --git a/samples/net/gsm_modem/CMakeLists.txt b/samples/net/gsm_modem/CMakeLists.txt new file mode 100644 index 00000000000..86b017e615b --- /dev/null +++ b/samples/net/gsm_modem/CMakeLists.txt @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: Apache-2.0 + +# DTS overlay files must include full path name +#set(DTC_OVERLAY_FILE "${CMAKE_CURRENT_SOURCE_DIR}/sam_e70_xplained.overlay") + +cmake_minimum_required(VERSION 3.13.1) + +include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) +project(fona808) + +target_sources(app PRIVATE src/main.c) diff --git a/samples/net/gsm_modem/boards/reel_board.conf b/samples/net/gsm_modem/boards/reel_board.conf new file mode 100644 index 00000000000..580da34bbe9 --- /dev/null +++ b/samples/net/gsm_modem/boards/reel_board.conf @@ -0,0 +1,2 @@ +# Reel board UART +CONFIG_UART_1_NRF_UARTE=y diff --git a/samples/net/gsm_modem/frdm_uart2_dts.overlay b/samples/net/gsm_modem/frdm_uart2_dts.overlay new file mode 100644 index 00000000000..19b52ac01c1 --- /dev/null +++ b/samples/net/gsm_modem/frdm_uart2_dts.overlay @@ -0,0 +1,9 @@ +/* + * UART 2 is configured on FRDM pins PTD0, rts; PTD1, cts; PTD2, rx; PTD3, tx + * see https://www.nxp.com/docs/en/data-sheet/K64P144M120SF5.pdf chapter 5.1, + * page 74 + */ +&uart2 { + status = "okay"; + current-speed = <115200>; +}; diff --git a/samples/net/gsm_modem/prj.conf b/samples/net/gsm_modem/prj.conf new file mode 100644 index 00000000000..896cad714ee --- /dev/null +++ b/samples/net/gsm_modem/prj.conf @@ -0,0 +1,34 @@ + +# UART support +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 +CONFIG_NET_L2_PPP=y +CONFIG_NET_NATIVE=y +CONFIG_NETWORKING=y + +CONFIG_NET_L2_PPP_TIMEOUT=10000 + +# IPv4 enables PPP IPCP support +CONFIG_NET_IPV4=y +CONFIG_NET_IPV6=n + +# Network management events +CONFIG_NET_CONNECTION_MANAGER=y + +# Log buffers, modem and PPP +CONFIG_LOG=y +CONFIG_NET_LOG=y +#CONFIG_LOG_BUFFER_SIZE=16384 +#CONFIG_LOG_STRDUP_BUF_COUNT=200 +#CONFIG_MODEM_LOG_LEVEL_DBG=y +#CONFIG_NET_PPP_LOG_LEVEL_DBG=y +#CONFIG_NET_L2_PPP_LOG_LEVEL_DBG=y +#CONFIG_NET_MGMT_EVENT_LOG_LEVEL_DBG=y +#CONFIG_NET_CONNECTION_MANAGER_LOG_LEVEL_DBG=y diff --git a/samples/net/gsm_modem/src/main.c b/samples/net/gsm_modem/src/main.c new file mode 100644 index 00000000000..334ec6a6d9b --- /dev/null +++ b/samples/net/gsm_modem/src/main.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2020, Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include + +#include +LOG_MODULE_REGISTER(sample_gsm_ppp, LOG_LEVEL_DBG); + +static struct net_mgmt_event_callback mgmt_cb; + +static void event_handler(struct net_mgmt_event_callback *cb, + u32_t mgmt_event, struct net_if *iface) +{ + if ((mgmt_event & (NET_EVENT_L4_CONNECTED + | NET_EVENT_L4_DISCONNECTED)) != mgmt_event) { + return; + } + + if (mgmt_event == NET_EVENT_L4_CONNECTED) { + LOG_INF("Network connected"); + return; + } + + if (mgmt_event == NET_EVENT_L4_DISCONNECTED) { + LOG_INF("Network disconnected"); + return; + } +} + +int main(void) +{ + struct device *uart_dev = device_get_binding(CONFIG_MODEM_GSM_UART_NAME); + + LOG_INF("%s: booted board '%s' APN '%s' UART '%s' device %p", + __func__, CONFIG_BOARD, CONFIG_MODEM_GSM_APN, + CONFIG_MODEM_GSM_UART_NAME, uart_dev); + + net_mgmt_init_event_callback(&mgmt_cb, event_handler, + NET_EVENT_L4_CONNECTED | + NET_EVENT_L4_DISCONNECTED); + net_mgmt_add_event_callback(&mgmt_cb); + + return 0; +}