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
1 change: 1 addition & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ target_sources_ifdef(CONFIG_SM_CMUX app PRIVATE src/sm_cmux.c)
target_sources_ifdef(CONFIG_SM_GNSS app PRIVATE src/sm_at_gnss.c)
target_sources_ifdef(CONFIG_SM_NRF_CLOUD app PRIVATE src/sm_at_nrfcloud.c)
target_sources_ifdef(CONFIG_SM_MQTTC app PRIVATE src/sm_at_mqtt.c)
target_sources_ifdef(CONFIG_SM_BUTTONS app PRIVATE src/buttons.c)

add_subdirectory_ifdef(CONFIG_SM_CARRIER src/lwm2m_carrier)

Expand Down
36 changes: 36 additions & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ config SM_MODEM_PIPE_TIMEOUT

endif # SM_CMUX || SM_PPP

config HEAP_MEM_POOL_ADD_SIZE_SM_AT
int "Additional heap memory pool size for AT Host"
default 16384 if SM_CMUX
default 8192
help
Additional heap memory pool size required for AT Host.
This value is added to the total heap memory pool size defined in
CONFIG_HEAP_MEM_POOL_SIZE.

if SM_MQTTC

config SM_MQTTC_MESSAGE_BUFFER_LEN
Expand Down Expand Up @@ -254,6 +263,33 @@ config SM_PGPS_INJECT_FIX_DATA

endif # SM_GNSS

config SM_BUTTONS
bool "Button handling module"
depends on BOARD_NRF9151DK
depends on INPUT_GPIO_KEYS
help
Module that handles button presses to send AT commands to the modem.

if SM_BUTTONS

config SM_BUTTON0_AT
string "AT command for button 0"
default "AT+CFUN=4"

config SM_BUTTON1_AT
string "AT command for button 1"
default "AT+CFUN=1"

config SM_BUTTON2_AT
string "AT command for button 2"
default "AT+CGATT=0"

config SM_BUTTON3_AT
string "AT command for button 3"
default "AT+CGATT=1"

endif # SM_BUTTONS

module = SM
module-str = serial modem
source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config"
Expand Down
3 changes: 3 additions & 0 deletions app/boards/nrf9151dk_nrf9151_ns.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
chosen {
ncs,sm-uart = &dtr_uart0;
};
buttons {
status = "okay";
};
};

/* DTR with DK */
Expand Down
6 changes: 5 additions & 1 deletion app/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ CONFIG_AT_CMD_CUSTOM=y
# Align the max FD entry to NRF_MODEM_MAX_SOCKET_COUNT(8)
CONFIG_ZVFS_OPEN_MAX=8

# Modem pipe
CONFIG_MODEM_MODULES=y
CONFIG_MODEM_PIPE=y
CONFIG_MODEM_CMUX=y

# Handle modem fault
CONFIG_NRF_MODEM_LIB_ON_FAULT_APPLICATION_SPECIFIC=y

Expand All @@ -58,7 +63,6 @@ CONFIG_NRFX_TIMER=y

# Stacks and heaps
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_HEAP_MEM_POOL_SIZE=16384
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
CONFIG_AT_MONITOR_HEAP_SIZE=4096

Expand Down
42 changes: 42 additions & 0 deletions app/src/buttons.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
#include <zephyr/input/input.h>
#include <zephyr/logging/log.h>
#include "sm_util.h"

LOG_MODULE_REGISTER(buttons, LOG_LEVEL_DBG);

static void button_handler(struct input_event *evt, void *user_data)
{
if (evt->type != INPUT_EV_KEY || evt->value != 1) {
return;
}

int ret;
const char *at_cmd;

switch (evt->code) {
case INPUT_KEY_0:
at_cmd = CONFIG_SM_BUTTON0_AT;
break;
case INPUT_KEY_1:
at_cmd = CONFIG_SM_BUTTON1_AT;
break;
case INPUT_KEY_2:
at_cmd = CONFIG_SM_BUTTON2_AT;
break;
case INPUT_KEY_3:
at_cmd = CONFIG_SM_BUTTON3_AT;
break;
default:
return;
}

ret = sm_util_at_printf(at_cmd);
LOG_DBG("Sent AT command \"%s\" from button %d, ret=%d", at_cmd, evt->code, ret);
}

INPUT_CALLBACK_DEFINE(NULL, button_handler, NULL);
17 changes: 2 additions & 15 deletions app/src/lwm2m_carrier/sm_at_carrier.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
#include "sm_at_host.h"
#include "sm_settings.h"
#include "sm_util.h"
#include "sm_at_carrier.h"

LOG_MODULE_REGISTER(sm_carrier, CONFIG_SM_LOG_LEVEL);

/* Static variable to report the memory free resource. */
static int m_mem_free;

struct k_work_delayable reconnect_work;
static void reconnect_wk(struct k_work *work);
static K_WORK_DELAYABLE_DEFINE(reconnect_work, reconnect_wk);

/* Global functions defined in different files. */
int lte_auto_connect(void);
Expand Down Expand Up @@ -967,15 +966,3 @@ static int do_carrier_send(enum at_parser_cmd_type, struct at_parser *parser,

return lwm2m_carrier_data_send(path, path_len);
}

int sm_at_carrier_init(void)
{
k_work_init_delayable(&reconnect_work, reconnect_wk);

return 0;
}

int sm_at_carrier_uninit(void)
{
return 0;
}
35 changes: 0 additions & 35 deletions app/src/lwm2m_carrier/sm_at_carrier.h

This file was deleted.

5 changes: 4 additions & 1 deletion app/src/lwm2m_carrier/sm_at_carrier_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,11 +711,14 @@ static int do_cfg_uri(enum at_parser_cmd_type, struct at_parser *parser, uint32_
return lwm2m_settings_server_uri_set(server_uri);
}

int sm_at_carrier_cfg_init(void)
#if defined(CONFIG_SM_CARRIER_AUTO_STARTUP)
static int sm_at_carrier_cfg_init(void)
{
if (IS_ENABLED(CONFIG_SM_CARRIER_AUTO_STARTUP)) {
return lwm2m_settings_auto_startup_set(true);
}

return 0;
}
SYS_INIT(sm_at_carrier_cfg_init, APPLICATION, 0);
#endif
26 changes: 0 additions & 26 deletions app/src/lwm2m_carrier/sm_at_carrier_cfg.h

This file was deleted.

88 changes: 28 additions & 60 deletions app/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@
#include "sm_at_host.h"
#include "sm_at_dfu.h"
#include "sm_at_fota.h"
#include "sm_settings.h"
#include "sm_util.h"
#include "sm_ctrl_pin.h"
#include "sm_uart_handler.h"

LOG_MODULE_REGISTER(sm, CONFIG_SM_LOG_LEVEL);

#define SM_WQ_STACK_SIZE KB(4)
#define SM_WQ_PRIORITY K_LOWEST_APPLICATION_THREAD_PRIO
static K_THREAD_STACK_DEFINE(sm_wq_stack_area, SM_WQ_STACK_SIZE);

struct k_work_q sm_work_q;

NRF_MODEM_LIB_ON_INIT(lwm2m_init_hook, on_modem_lib_init, NULL);
Expand Down Expand Up @@ -147,22 +143,6 @@ static int bootloader_mode_init(void)
}
LOG_INF("Bootloader mode initiated successfully");

ret = sm_ctrl_pin_init();
if (ret) {
LOG_ERR("Failed to init ctrl_pin: %d", ret);
return ret;
}

k_work_queue_start(&sm_work_q, sm_wq_stack_area,
K_THREAD_STACK_SIZEOF(sm_wq_stack_area),
SM_WQ_PRIORITY, NULL);

ret = sm_at_host_bootloader_init();
if (ret) {
LOG_ERR("Failed to init at_host: %d", ret);
return ret;
}

ret = sm_at_send_str("Bootloader mode ready\r\n");
if (ret) {
LOG_ERR("Failed to send bootloader mode ready string: %d", ret);
Expand Down Expand Up @@ -236,37 +216,19 @@ int lte_auto_connect(void)
return err;
}

int start_execute(void)
int main(void)
{
int err;

LOG_INF("Serial Modem");

err = sm_ctrl_pin_init();
if (err) {
LOG_ERR("Failed to init ctrl_pin: %d", err);
return err;
}

k_work_queue_start(&sm_work_q, sm_wq_stack_area,
K_THREAD_STACK_SIZEOF(sm_wq_stack_area),
SM_WQ_PRIORITY, NULL);

/* This will send "READY" or "INIT ERROR" to UART so after this nothing
* should be done that can fail
*/
err = sm_at_host_init();
if (err) {
LOG_ERR("Failed to init at_host: %d", err);
return err;
}

(void)lte_auto_connect();
static const struct k_work_queue_config cfg = {
.name = "sm_work_q",
.essential = true,
};

k_work_queue_init(&sm_work_q);
k_work_queue_run(&sm_work_q, &cfg);
return 0;
}

int main(void)
static int sm_main(void)
{
int ret;

Expand All @@ -275,13 +237,6 @@ int main(void)
nrf_power_resetreas_clear(NRF_POWER_NS, 0x70017);
LOG_DBG("RR: 0x%08x", rr);

sm_ctrl_pin_init_gpios();

/* Init and load settings */
if (sm_settings_init() != 0) {
LOG_WRN("Failed to init sm settings");
}

if (sm_bootloader_mode_requested) {
/* Clear bootloader mode flag */
ret = bootloader_mode_request(false);
Expand All @@ -293,7 +248,7 @@ int main(void)
LOG_ERR("Failed to initialize bootloader mode: %d", ret);
goto exit_reboot;
}
goto exit;
return ret;
}
}

Expand All @@ -309,7 +264,7 @@ int main(void)
if (ret) {
LOG_ERR("Modem library init failed, err: %d", ret);
if (ret != -EAGAIN && ret != -EIO) {
goto exit;
return ret;
} else if (ret == -EIO) {
LOG_ERR("Please program full modem firmware with the bootloader or "
"external tools");
Expand All @@ -327,14 +282,27 @@ int main(void)
}
#endif

ret = start_execute();
exit:
if (ret) {
LOG_ERR("Failed to start SM (%d). It's not operational!!!", ret);
if (!IS_ENABLED(CONFIG_SM_SKIP_READY_MSG)) {
/* Send Ready string to indicate that AT host is ready */
ret = sm_at_send_str(SM_SYNC_STR);
if (ret) {
return ret;
}
}

/* This is here and not earlier because in case of firmware
* update it will send an AT response so the UART must be up.
*/
sm_fota_post_process();

(void)lte_auto_connect();

LOG_INF("Serial Modem");

return ret;

exit_reboot:
LOG_PANIC();
sys_reboot(SYS_REBOOT_COLD);
}
SYS_INIT(sm_main, APPLICATION, 100);
Loading
Loading