This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

nRF9160 DK: Failed to send AT command err: 117 and err: 9

Hello,

I am facing below AT_cmd errors after flashing my application to nRF9160 DK. Please support me how to resolve these errors asap as its blocking our product development activity.

I want to setup the MAGPIO in the main function before calling the LwM2M carrier events. But looks like AT is not getting initialized unless and until DK board is not connected with LTE via LwM2M carrier. If I send same AT command after LTE connected to network then the AT command will work and will not throw any errors which is more confusing to me. 

Errors:

<err> at_cmd: Failed to open AT socket (err:-117)

<err> at_cmd: Failed to send AT command (err:9)

Reference code: (Note: This is just a reference code where I just want to share that how exactly I am want to setup the MAGPIO in main() )

/* Standard includes files */
#include <random/rand32.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>

/* Modem/Network includes files */
#include <modem/at_cmd.h>
#include <modem/at_notif.h>
#include <modem/lte_lc.h>
#include <net/mqtt.h>
#include <net/socket.h>

/* Zephyr includes files */
#include <zephyr.h>
#include <zephyr/types.h>

/* FOTA includes files */
#include <dfu/dfu_target_mcuboot.h>
#include <dfu/mcuboot.h>
#include <modem/nrf_modem_lib.h>
#include <net/fota_download.h>

/* Driver include files */
#include <device.h>
#include <drivers/uart.h>
#include <nrfx.h>
#include <secure_services.h>
#include <drivers/clock_control.h>
#include <drivers/clock_control/nrf_clock_control.h>
#include <drivers/uart.h>

#define AT_MAGPIO   "AT%XMAGPIO=1,1,1,7,1,746,803,2,698,748,2,1710,2200,3,824,894,4,880,960,5,791,849,7,1565,1586"

const char *const at_commands_magpio[] = {
    AT_MAGPIO,
};

/* To strictly comply with UART timing, enable external XTAL oscillator */
void enable_xtal(void)
{
	struct onoff_manager *clk_mgr;
	static struct onoff_client cli = {};

	clk_mgr = z_nrf_clock_control_get_onoff(CLOCK_CONTROL_NRF_SUBSYS_HF);
	sys_notify_init_spinwait(&cli.notify);
	(void)onoff_request(clk_mgr, &cli);
}

int hubo_setup_modem_magpio(void) {
    char buf[50];
    for (int i = 0; i < ARRAY_SIZE(at_commands_magpio); i++) {
        /* send one by one AT commands to modem and check if success or failed */
        if (at_cmd_write(at_commands_magpio[i], buf, sizeof(buf), NULL) != 0) {
            LTE_DEBUG_PRINTK("AT Command: %s Failed with Response: %s\n", at_commands_magpio[i], buf);
            return -1;
        }
    }
    return 0;
}

void main(void) {  
    
    enable_xtal();

    /* control an external antenna tuner by setting MAGPIO pins to support all LTE frequncy ranges. */
    if (hubo_setup_modem_magpio() != 0) {
        printk("Failed to initialize MAGPIO Configuration.\n\n");
    }
    
    uart_task_init(); // UART setup for serial communication
    
    nvs_init(); 
   
    while (1) {
        k_sleep(K_MSEC(1000));
    }
}

Menuconfig for AT_CMD: 

prj.conf file 

CONFIG_FPU=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
CONFIG_STDOUT_CONSOLE=y
CONFIG_AT_CMD=y

# DK
CONFIG_DK_LIBRARY=y

CONFIG_LWM2M_CARRIER=y
CONFIG_NRF_MODEM_LIB_SYS_INIT=n
CONFIG_AT_CMD_THREAD_STACK_SIZE=1536

# PDN library
CONFIG_PDN=y
CONFIG_PDN_CONTEXTS_MAX=3

# Disable NB-IoT fallback
CONFIG_LTE_NETWORK_USE_FALLBACK=n

# SMS library
CONFIG_SMS=y

# LwM2M carrier is only compiled for hard-float
CONFIG_FPU=y
CONFIG_FP_HARDABI=y

# Networking
CONFIG_NETWORKING=y
CONFIG_NET_NATIVE=n
CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y

# LTE link control
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_NETWORK_MODE_LTE_M_GPS=y
CONFIG_LTE_AUTO_INIT_AND_CONNECT=n
CONFIG_LTE_PSM_REQ_RPTAU="00011111"
CONFIG_LTE_PSM_REQ_RAT="00000010"

# Modem library
CONFIG_NRF_MODEM_LIB=y

# FOTA library
CONFIG_FOTA_DOWNLOAD=y
CONFIG_REBOOT=y

# Download client
CONFIG_DOWNLOAD_CLIENT=y
CONFIG_DOWNLOAD_CLIENT_STACK_SIZE=4096

# DFU Target
CONFIG_DFU_TARGET=y

# Application Upgrade support
CONFIG_BOOTLOADER_MCUBOOT=y

# Image manager
CONFIG_IMG_MANAGER=y
CONFIG_IMG_ERASE_PROGRESSIVELY=y

# Day-Time library
CONFIG_DATE_TIME=y
CONFIG_DATE_TIME_UPDATE_INTERVAL_SECONDS=3600

# AT Host
CONFIG_AT_CMD_PARSER=y
CONFIG_AT_HOST_LIBRARY=y

# Serial port
CONFIG_SERIAL=y
CONFIG_UART_NRFX=y
CONFIG_UART_INTERRUPT_DRIVEN=y

# Have kernel output
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
CONFIG_UART_CONSOLE_ON_DEV_NAME="UART_0"

# MQTT
CONFIG_MQTT_LIB=y
CONFIG_MQTT_LIB_TLS=y
CONFIG_MQTT_CLEAN_SESSION=y
CONFIG_MODEM_KEY_MGMT=y

# Memory
CONFIG_MAIN_STACK_SIZE=8192
CONFIG_HEAP_MEM_POOL_SIZE=8192
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096


#GPIO required for GPS Amplifier enable/disable
CONFIG_GPIO=y

#Threads
CONFIG_MULTITHREADING=y
CONFIG_MAIN_THREAD_PRIORITY=7

#Disable UART
CONFIG_BOOT_BANNER=y
CONFIG_PRINTK=y
CONFIG_LOG=y

# Storage
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_NVS=y
CONFIG_NVS_LOG_LEVEL_DBG=y
CONFIG_REBOOT=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y

# GPS
CONFIG_NRF9160_GPS=y
CONFIG_NRF9160_GPS_LOG_LEVEL_DBG=y

# AGPS
CONFIG_AGPS=y
# CONFIG_AGPS_SRC_SUPL=y
CONFIG_AGPS_LOG_LEVEL_DBG=y
CONFIG_NRF9160_GPS_THREAD_STACK_SIZE=4608

# Compiler
CONFIG_NEWLIB_LIBC=y

Console Logs:

I: Starting bootloader
I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
I: Boot source: none
I: Swap type: none
I: Bootloader chainload address offset: 0x10000
*** Booting Zephyr OS build v2.6.0-rc1-ncs1  ***
Flash regions           Domain          Permissions
00 03 0x00000 0x20000   Secure          rwxl
04 31 0x20000 0x100000  Non-Secure      rwxl

Non-secure callable region 0 placed in flash region 3 with size 32.

SRAM region             Domain          Permissions
00 07 0x00000 0x10000   Secure          rwxl
08 31 0x10000 0x40000   Non-Secure      rwxl

Peripheral              Domain          Status
00 NRF_P0               Non-Secure      OK
01 NRF_CLOCK            Non-Secure      OK
02 NRF_RTC0             Non-Secure      OK
03 NRF_RTC1             Non-Secure      OK
04 NRF_NVMC             Non-Secure      OK
05 NRF_UARTE1           Non-Secure      OK
06 NRF_UARTE2           Secure          SKIP
07 NRF_TWIM2            Non-Secure      OK
08 NRF_SPIM3            Non-Secure      OK
09 NRF_TIMER0           Non-Secure      OK
10 NRF_TIMER1           Non-Secure      OK
11 NRF_TIMER2           Non-Secure      OK
12 NRF_SAADC            Non-Secure      OK
13 NRF_PWM0             Non-Secure      OK
14 NRF_PWM1             Non-Secure      OK
15 NRF_PWM2             Non-Secure      OK
16 NRF_PWM3             Non-Secure      OK
17 NRF_WDT              Non-Secure      OK
18 NRF_IPC              Non-Secure      OK
19 NRF_VMC              Non-Secure      OK
20 NRF_FPU              Non-Secure      OK
21 NRF_EGU1             Non-Secure      OK
22 NRF_EGU2             Non-Secure      OK
23 NRF_DPPIC            Non-Secure      OK
24 NRF_REGULATORS       Non-Secure      OK
25 NRF_PDM              Non-Secure      OK
26 NRF_I2S              Non-Secure      OK
27 NRF_GPIOTE1          Non-Secure      OK

SPM: NS image at 0x20200
SPM: NS MSP at 0x20034aa0
SPM: NS reset vector at 0x31f19
SPM: prepare to jump to Non-Secure image.
*** Booting Zephyr OS build v2.6.0-rc1-ncs1  ***

AT Command: AT%XMAGPIO=1,1,1,7,1,746,803,2,698,748,2,1710,2200,3,824,894,4,880,960,5,791,849,7,1565,1586 Failed with Response: «
Failed to initialize MAGPIO Configuration.

[00:00:00.004,760] <err> at_cmd: Failed to open AT socket (err:-117)
[00:00:00.027,618] <err> at_cmd: Failed to send AT command (err:9)
[00:00:00.022,766] <dbg> fs_nvs.nvs_recover_last_ate: Recovering last ate from sector 0
[00:00:00.027,526] <inf> fs_nvs: 3 Sectors of 4096 bytes
[00:00:00.027,526] <inf> fs_nvs: alloc wra: 0, 998
[00:00:00.027,557] <inf> fs_nvs: data wra: 0, 328

NCS version : 1.6.0

Modem Firmware version: 1.2.3

Device Revision : NRF9160_xxAA_REV2

Board Version : PCA10090

Regards,

Chetan

Related