Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions samples/softsim_static_profile_memfault/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Copyright (c) 2020 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#

cmake_minimum_required(VERSION 3.20.0)

list(APPEND OVERLAY_CONFIG "$ENV{ZEPHYR_BASE}/../modules/lib/onomondo-softsim/overlay-softsim.conf")

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(softsim)

zephyr_include_directories(config)

target_sources(app PRIVATE src/main.c)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* Application-specific metrics can be defined here.
* Please refer to https://docs.memfault.com/docs/embedded/metrics-api for more details.
*/

MEMFAULT_METRICS_KEY_DEFINE(switch_1_toggle_count, kMemfaultMetricType_Unsigned)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#pragma once

/*
* Platform overrides for the default configuration settings in the
* memfault-firmware-sdk. Default configuration settings can be found in
* "<NCS folder>/modules/lib/memfault-firmware-sdk/components/include/memfault/default_config.h"
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* Application-specific trace reasons can be defined here.
* Please refer to https://docs.memfault.com/docs/embedded/trace-events for more details.
*/

MEMFAULT_TRACE_REASON_DEFINE(switch_2_toggled)
16 changes: 16 additions & 0 deletions samples/softsim_static_profile_memfault/pm_static.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
tfm_its:
address: 0xf8000
size: 0x2000
tfm_otp_nv_counters:
address: 0xfa000
size: 0x2000
EMPTY_tfm_ps:
address: 0xfc000
size: 0x4000
tfm_storage:
address: 0xf8000
span:
- EMPTY_tfm_ps
- tfm_its
- tfm_otp_nv_counters
size: 0x8000
98 changes: 98 additions & 0 deletions samples/softsim_static_profile_memfault/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
### Onomondo SoftSIM ###
CONFIG_SOFTSIM_DEBUG=n
CONFIG_SOFTSIM_LOG_LEVEL_ERR=y
CONFIG_SOFTSIM_STATIC_PROFILE_ENABLE=y
# GSMA TS.48 USIM profile (standard test profile) replace with actual Onomondo profile
CONFIG_SOFTSIM_STATIC_PROFILE="01120809101010325406360214980010325476981032140320000000000000000000000000000000000420000102030405060708090A0B0C0D0E0F0520000102030405060708090A0B0C0D0E0F0620000102030405060708090A0B0C0D0E0F"
### Onomondo SoftSIM ###

# Log Configurations
CONFIG_DEBUG=n
CONFIG_LOG=y
CONFIG_NRF_MODEM_LOG=n

# General Configurations
CONFIG_LOG_BUFFER_SIZE=5000
CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD=5
CONFIG_LOG_DEFAULT_LEVEL=1

# Modem Configurations
CONFIG_NRF_MODEM_LIB=y

# NET Configurations
CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_NATIVE=n
CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_POSIX_API=y

# LTE Configurations
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_LC_PSM_MODULE=y
CONFIG_LTE_LC_EDRX_MODULE=y

# AT host library
CONFIG_SERIAL=y
CONFIG_AT_HOST_LIBRARY=y
CONFIG_UART_INTERRUPT_DRIVEN=y

# Reduce the size of TF-M by disabling the PS
CONFIG_TFM_PARTITION_PROTECTED_STORAGE=n
CONFIG_PSA_CRYPTO_DRIVER_CC3XX=n

# Reduce the size of the TF-M partition
# when combined with static partitioning
CONFIG_PM_PARTITION_SIZE_TFM=0x10000

# The bootloader adds a small mcuboot_pad partition,
# whose size must be subtracted from the TF-M partition
#CONFIG_BOOTLOADER_MCUBOOT=y
#CONFIG_PM_PARTITION_SIZE_TFM=0xFE00

# Memfault
CONFIG_MEMFAULT=y
# Replace with your actual Memfault project key
CONFIG_MEMFAULT_NCS_PROJECT_KEY="qcZzu5cz8Jmnxsjwtbn7H2OSl5IVGzKe"

# Set the device ID to IMEI.
CONFIG_MEMFAULT_NCS_DEVICE_ID_IMEI=y # might be the default option, but let's be explicit

# Combine these two configs to manually assign a device ID.
# CONFIG_MEMFAULT_NCS_DEVICE_ID_STATIC=y
# CONFIG_MEMFAULT_NCS_DEVICE_ID="bb-softsim-sample"

# Enable the modem info library to allow Memfault to collect LTE metrics
# CONFIG_MODEM_INFO=y

# Enable these for testing the integration
CONFIG_SHELL=y
CONFIG_SHELL_BACKEND_SERIAL=y
# Disable the Host AT control of the serial port with CONFIG_AT_HOST_LIBRARY=n,
# so we can access the Zephyr shell for testing.
# Some nRF-Connect SDK examples will override this setting in board-specific
# config files. The easiest way to force it off (other than editing those files)
# is to pass it when running "west build", i.e.:
# "west build ... -- -DCONFIG_AT_HOST_LIBRARY=n"
CONFIG_AT_HOST_LIBRARY=n

# CONFIG_NET_IPV6=y
CONFIG_NET_CONNECTION_MANAGER=y

# Added to make sure that the compiler doesn't complain about missing files
CONFIG_MEMFAULT_NCS_STACK_METRICS=y
CONFIG_MEMFAULT_USER_CONFIG_ENABLE=n

# For now I have copied over the configurations of overlay-memfault.conf
CONFIG_MEMFAULT_HTTP_PERIODIC_UPLOAD=y
CONFIG_MEMFAULT_NCS_LTE_METRICS=y
CONFIG_MEMFAULT_LOGGING_ENABLE=y
CONFIG_MEMFAULT_LOG_LEVEL_DBG=y

# Add to pick up support for sending Memfault data over HTTP
CONFIG_MEMFAULT_HTTP_ENABLE=y
CONFIG_NET_TCP=y
CONFIG_NET_IPV4=y

# nRF91 series only, uses modem to store root CAs
CONFIG_MEMFAULT_ROOT_CERT_STORAGE_NRF9160_MODEM=y
CONFIG_MODEM_KEY_MGMT=y
188 changes: 188 additions & 0 deletions samples/softsim_static_profile_memfault/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
#include <stdio.h>
#include <string.h>

#include <nrf_modem.h>
#include <nrf_modem_at.h>
#include <nrf_softsim.h>

#include <pm_config.h>

#include <modem/lte_lc.h>
#include <modem/nrf_modem_lib.h>

#include <zephyr/kernel.h>
#include <zephyr/net/socket.h>
#include <zephyr/drivers/clock_control.h>
#include <zephyr/drivers/clock_control/nrf_clock_control.h>
#include <zephyr/device.h>
#include <zephyr/drivers/uart.h>
#include <zephyr/logging/log.h>
#include <zephyr/logging/log_ctrl.h>
#include <zephyr/sys/reboot.h>

LOG_MODULE_REGISTER(softsim_sample, LOG_LEVEL_INF);

/* Semaphore to signal that the LTE connection is established */
K_SEM_DEFINE(lte_connected, 0, 1);

static void lte_handler(const struct lte_lc_evt *const evt);
static int server_connect(void);

static int client_fd;
static struct sockaddr_storage host_addr;
static struct k_work_delayable server_transmission_work;

static void server_transmission_work_fn(struct k_work *work)
{
char buffer[] = "{\"message\":\"Hello from Onomondo!\"}";

int err = send(client_fd, buffer, sizeof(buffer) - 1, 0);
if (err < 0) {
LOG_ERR("Failed to transmit UDP packet, %d", errno);
k_work_schedule(&server_transmission_work, K_SECONDS(2));
return;
}

k_work_schedule(&server_transmission_work, K_SECONDS(150));
}

static void work_init(void)
{
k_work_init_delayable(&server_transmission_work, server_transmission_work_fn);
}

static void lte_handler(const struct lte_lc_evt *const evt)
{
switch (evt->type) {
case LTE_LC_EVT_NW_REG_STATUS:
if ((evt->nw_reg_status != LTE_LC_NW_REG_REGISTERED_HOME) &&
(evt->nw_reg_status != LTE_LC_NW_REG_REGISTERED_ROAMING)) {
break;
}

LOG_INF("Network registration status: %s",
evt->nw_reg_status == LTE_LC_NW_REG_REGISTERED_HOME ?
"Connected - home network" : "Connected - roaming");
k_sem_give(&lte_connected);
break;

case LTE_LC_EVT_PSM_UPDATE:
LOG_INF("PSM parameter update: TAU: %d, Active time: %d",
evt->psm_cfg.tau, evt->psm_cfg.active_time);
break;

case LTE_LC_EVT_EDRX_UPDATE: {
char log_buf[60];
ssize_t len;

len = snprintf(log_buf, sizeof(log_buf),
"eDRX parameter update: eDRX: %f, PTW: %f",
(double)evt->edrx_cfg.edrx, (double)evt->edrx_cfg.ptw);
if (len > 0) {
LOG_INF("%s", log_buf);
}
break;
}

case LTE_LC_EVT_RRC_UPDATE:
LOG_INF("RRC mode: %s",
evt->rrc_mode == LTE_LC_RRC_MODE_CONNECTED ? "Connected" : "Idle");
break;

case LTE_LC_EVT_CELL_UPDATE:
LOG_INF("LTE cell changed: Cell ID: %d, Tracking area: %d",
evt->cell.id, evt->cell.tac);
break;

default:
break;
}
}

static void modem_connect(void)
{
int err;

err = lte_lc_connect_async(lte_handler);
if (err) {
LOG_ERR("Connecting to LTE network failed, error: %d", err);
return;
}
}

static void server_disconnect(void)
{
(void)close(client_fd);
}

static int server_init(void)
{
struct sockaddr_in *server4 = ((struct sockaddr_in *)&host_addr);

server4->sin_family = AF_INET;
server4->sin_port = htons(4321);

inet_pton(AF_INET, "1.2.3.4", &server4->sin_addr);

return 0;
}

static int server_connect(void)
{
int err;

client_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (client_fd < 0) {
LOG_ERR("Failed to create UDP socket: %d\n", errno);
err = -errno;
goto error;
}

err = connect(client_fd, (struct sockaddr *)&host_addr,
sizeof(struct sockaddr_in));
if (err < 0) {
LOG_ERR("Connect failed, error: %d\n", errno);
goto error;
}

return 0;

error:
server_disconnect();
return err;
}

int main(void)
{
LOG_INF("SoftSIM sample started.");

int32_t err = nrf_modem_lib_init();
if (err) {
LOG_ERR("Failed to initialize modem library, error: %d\n", err);
}

work_init();
modem_connect();

LOG_INF("Waiting for LTE connect event.\n");
do {
} while (k_sem_take(&lte_connected, K_SECONDS(10)));

LOG_INF("LTE connected!");

err = server_init();
if (err) {
LOG_ERR("Not able to initialize UDP server connection\n");
return -1;
}

err = server_connect();
if (err) {
LOG_ERR("Not able to connect to UDP server, error: %d\n", err);
return -1;
}

k_work_schedule(&server_transmission_work, K_NO_WAIT);

return 0;
}
1 change: 1 addition & 0 deletions samples/softsim_static_profile_memfault/sysbuild.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SB_CONFIG_SOFTSIM_BUNDLE_TEMPLATE_HEX=y
10 changes: 9 additions & 1 deletion west.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
manifest:
remotes:
- name: nrfconnect
url-base: https://github.com/nrfconnect/
url-base: https://github.com/nrfconnect
- name: memfault
url-base: https://github.com/memfault

projects:
- name: sdk-nrf
path: nrf
revision: v3.0.2
remote: nrfconnect
import: true

- name: memfault-firmware-sdk
path: modules/lib/memfault-firmware-sdk
revision: 1.26.1
remote: memfault
self:
path: modules/lib/onomondo-softsim