This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

AT+CFUN=0/AT+CFUN=4 is not confirned with "OK".(NCS1.3.0)

I add lte_lc_init_and_connect() to the application "Serial LTE Modem" (SLM) v1.3.0. And then there's no reaction to AT+CFUN=0 or AT+CFUN=4.

static int modem_configure(void){
#if defined(CONFIG_BSD_LIBRARY)
	if (IS_ENABLED(CONFIG_LTE_AUTO_INIT_AND_CONNECT)) {
		/* Do nothing, modem is already turned on */
		/* and connected */
		goto connected;
	}

	LOG_INF("Connecting to LTE network.");
	LOG_INF("This may take several minutes.");

#if defined(CONFIG_LWM2M_CARRIER)
	/* Wait for the LWM2M carrier library to configure the */
	/* modem and set up the LTE connection. */
	k_sem_take(&lte_connected, K_FOREVER);
#else /* defined(CONFIG_LWM2M_CARRIER) */
	int err = lte_lc_init_and_connect();
	if (err) {
		LOG_ERR("LTE link could not be established.");
		return err;
	}
#endif /* defined(CONFIG_LWM2M_CARRIER) */

connected:
	LOG_INF("Connected to LTE network.");

#endif /* defined(CONFIG_BSD_LIBRARY) */
	return 0;
}

void start_execute(void)
{
	int err;

	LOG_INF("Serial LTE Modem");

+	while (modem_configure() != 0) {
+		LOG_WRN("Failed to establish LTE connection.");
+		LOG_WRN("Will retry in %d seconds.", 10);
+		k_sleep(K_SECONDS(10));
+	}

	err = modem_info_init();
	if (err) {
		LOG_ERR("Modem info could not be established: %d", err);
		return;
	}

	modem_info_params_init(&modem_param);

	/* Initialize AT Parser */
	err = at_params_list_init(&at_param_list, CONFIG_SLM_AT_MAX_PARAM);
	if (err) {
		LOG_ERR("Failed to init AT Parser: %d", err);
		return;
	}

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

	k_work_q_start(&slm_work_q, slm_wq_stack_area,
		K_THREAD_STACK_SIZEOF(slm_wq_stack_area), SLM_WQ_PRIORITY);
	k_work_init(&exit_idle_work, exit_idle);
}

I find that the socket_thread_fn() in at_cmd.c does not respond "OK\r\n".

It returns "+CSCON: 1\r\n" and  "+CEREG: 0,"1D2C","0D61D950",9,0,0,"11100000","11100000"\r\n"

        

So no messages are put on the queue. The program is blocked at_write().

static inline int at_write(const char *const cmd, enum at_cmd_state *state)
{
	int bytes_sent;
	int bytes_to_send = strlen(cmd);
	struct return_state_object ret;

	LOG_DBG("Sending command %s", log_strdup(cmd));

	bytes_sent = send(common_socket_fd, cmd, bytes_to_send, 0);

	if (bytes_sent == -1) {
		LOG_ERR("Failed to send AT command (err:%d)", errno);
		ret.code  = -errno;
		ret.state = AT_CMD_ERROR;
	} else {
		LOG_DBG("Awaiting response for %s", log_strdup(cmd));
		k_msgq_get(&return_code_msq, &ret, K_FOREVER);   //It's blocked here
		LOG_DBG("Bytes sent: %d", bytes_sent);

		if (bytes_sent != bytes_to_send) {
			LOG_ERR("Bytes sent (%d) was not the "
				"same as expected (%d)",
				bytes_sent, bytes_to_send);
		}
	}

	if (state) {
		*state = ret.state;
	}

	return ret.code;
}

  • Hi,
    Please try the SLM version in NCS v1.3.1 I think this was fixed in that version.

  • I ported the program to version in NCS v1.3.1 and v1.3.2 . The issue was not resolved.

  • Hi,
    I am not able to reproduce your issue with the SLM application in v1.3.2.
    I get "OK" response after the AT-commands you mentioned.

    Did you do 'west update' after you checked out the v1.3.2 tag?


    Please verify with this precompiled .hex file that it works.

    1373.slm_1_3_2.hex

    Share the serial output log if you have any issues.

  • Did you do 'west update' after you checked out the v1.3.2 tag?

    Yes, I'm now at version 1.3.2.

    Here is main.c:

    /*
     * Copyright (c) 2019 Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
     */
    #include <logging/log.h>
    
    #include <zephyr.h>
    #include <stdio.h>
    #include <drivers/uart.h>
    #include <drivers/gpio.h>
    #include <string.h>
    #include <bsd.h>
    #include <modem/lte_lc.h>
    #include <hal/nrf_gpio.h>
    #include <hal/nrf_power.h>
    #include <hal/nrf_regulators.h>
    #include <modem/modem_info.h>
    #include "slm_at_host.h"
    
    LOG_MODULE_REGISTER(app, CONFIG_SLM_LOG_LEVEL);
    
    #define SLM_WQ_STACK_SIZE	KB(2)
    #define SLM_WQ_PRIORITY		K_LOWEST_APPLICATION_THREAD_PRIO
    static K_THREAD_STACK_DEFINE(slm_wq_stack_area, SLM_WQ_STACK_SIZE);
    
    static struct device *gpio_dev;
    static struct gpio_callback gpio_cb;
    static struct k_work exit_idle_work;
    
    /* global variable used across different files */
    struct at_param_list at_param_list;
    struct modem_param_info modem_param;
    char rsp_buf[CONFIG_AT_CMD_RESPONSE_MAX_LEN];
    struct k_work_q slm_work_q;
    
    /**@brief Recoverable BSD library error. */
    void bsd_recoverable_error_handler(uint32_t err)
    {
    	LOG_ERR("bsdlib recoverable error: %u", err);
    }
    
    static void exit_idle(struct k_work *work)
    {
    	int err;
    
    	LOG_INF("Exit Idle");
    	gpio_pin_interrupt_configure(gpio_dev, CONFIG_SLM_INTERFACE_PIN,
    				     GPIO_INT_DISABLE);
    	gpio_remove_callback(gpio_dev, &gpio_cb);
    	/* Do the same as nrf_gpio_cfg_default() */
    	gpio_pin_configure(gpio_dev, CONFIG_SLM_INTERFACE_PIN, GPIO_INPUT);
    	/* Restart SLM services */
    	err = slm_at_host_init();
    	if (err) {
    		LOG_ERR("Failed to init at_host: %d", err);
    	}
    }
    
    static void gpio_callback(struct device *dev,
    		     struct gpio_callback *gpio_cb, u32_t pins)
    {
    	k_work_submit_to_queue(&slm_work_q, &exit_idle_work);
    }
    
    void enter_idle(void)
    {
    	int err;
    
    	gpio_dev = device_get_binding(DT_LABEL(DT_NODELABEL(gpio0)));
    	if (gpio_dev == NULL) {
    		LOG_ERR("GPIO_0 bind error");
    		return;
    	}
    	err = gpio_pin_configure(gpio_dev, CONFIG_SLM_INTERFACE_PIN,
    				GPIO_INPUT | GPIO_PULL_UP);
    	if (err) {
    		LOG_ERR("GPIO_0 config error: %d", err);
    		return;
    	}
    	gpio_init_callback(&gpio_cb, gpio_callback,
    			BIT(CONFIG_SLM_INTERFACE_PIN));
    	err = gpio_add_callback(gpio_dev, &gpio_cb);
    	if (err) {
    		LOG_ERR("GPIO_0 add callback error: %d", err);
    		return;
    	}
    	err = gpio_pin_interrupt_configure(gpio_dev, CONFIG_SLM_INTERFACE_PIN,
    					   GPIO_INT_LEVEL_LOW);
    	if (err) {
    		LOG_ERR("GPIO_0 enable callback error: %d", err);
    	}
    }
    
    void enter_sleep(void)
    {
    #if defined(CONFIG_SLM_GPIO_WAKEUP)
    	/*
    	 * Due to errata 4, Always configure PIN_CNF[n].INPUT before
    	 *  PIN_CNF[n].SENSE.
    	 */
    	nrf_gpio_cfg_input(CONFIG_SLM_INTERFACE_PIN,
    		NRF_GPIO_PIN_PULLUP);
    	nrf_gpio_cfg_sense_set(CONFIG_SLM_INTERFACE_PIN,
    		NRF_GPIO_PIN_SENSE_LOW);
    #endif	/* CONFIG_SLM_GPIO_WAKEUP */
    
    	/*
    	 * The LTE modem also needs to be stopped by issuing a command
    	 * through the modem API, before entering System OFF mode.
    	 * Once the command is issued, one should wait for the modem
    	 * to respond that it actually has stopped as there may be a
    	 * delay until modem is disconnected from the network.
    	 * Refer to https://infocenter.nordicsemi.com/topic/ps_nrf9160/
    	 * pmu.html?cp=2_0_0_4_0_0_1#system_off_mode
    	 */
    	lte_lc_power_off();
    	bsd_shutdown();
    	nrf_regulators_system_off(NRF_REGULATORS_NS);
    }
    
    void start_execute(void)
    {
    	int err;
    
    	LOG_INF("Serial LTE Modem");
    
    +	while (lte_lc_init_and_connect() != 0) {
    +		LOG_WRN("Failed to establish LTE connection.");
    +		LOG_WRN("Will retry in %d seconds.", 10);
    +		k_sleep(K_SECONDS(10));
    +	}
    
    	err = modem_info_init();
    	if (err) {
    		LOG_ERR("Modem info could not be established: %d", err);
    		return;
    	}
    
    	modem_info_params_init(&modem_param);
    
    	/* Initialize AT Parser */
    	err = at_params_list_init(&at_param_list, CONFIG_SLM_AT_MAX_PARAM);
    	if (err) {
    		LOG_ERR("Failed to init AT Parser: %d", err);
    		return;
    	}
    
    	err = slm_at_host_init();
    	if (err) {
    		LOG_ERR("Failed to init at_host: %d", err);
    		return;
    	}
    
    	k_work_q_start(&slm_work_q, slm_wq_stack_area,
    		K_THREAD_STACK_SIZEOF(slm_wq_stack_area), SLM_WQ_PRIORITY);
    	k_work_init(&exit_idle_work, exit_idle);
    }
    
    #if defined(CONFIG_SLM_GPIO_WAKEUP)
    void main(void)
    {
    	u32_t rr = nrf_power_resetreas_get(NRF_POWER_NS);
    
    	LOG_DBG("RR: 0x%08x", rr);
    	if (rr & NRF_POWER_RESETREAS_OFF_MASK) {
    		nrf_power_resetreas_clear(NRF_POWER_NS, 0x70017);
    		start_execute();
    	} else {
    		LOG_INF("Sleep");
    		enter_sleep();
    	}
    }
    #else
    void main(void)
    {
    	start_execute();
    }
    #endif	/* CONFIG_SLM_GPIO_WAKEUP */
    

    Here is pri.conf:

    #
    # Copyright (c) 2019 Nordic Semiconductor ASA
    #
    # SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
    #
    # General config
    CONFIG_LOG=y
    CONFIG_LOG_DEFAULT_LEVEL=3
    CONFIG_STACK_SENTINEL=y
    CONFIG_NEWLIB_LIBC=y
    CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
    
    # Segger RTT
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_RTT_CONSOLE=y
    CONFIG_UART_CONSOLE=n
    CONFIG_LOG_BACKEND_RTT=y
    CONFIG_LOG_BACKEND_UART=n
    
    # Network
    CONFIG_NETWORKING=y
    CONFIG_NET_SOCKETS=y
    CONFIG_NET_NATIVE=n
    
    # BSD library
    CONFIG_BSD_LIBRARY=y
    # Enable below for modem trace
    #CONFIG_BSD_LIBRARY_TRACE_ENABLED=y
    
    # Use GPIO
    CONFIG_GPIO=y
    CONFIG_GPIO_NRFX=y
    CONFIG_GPIO_NRF_P0=y
    
    # UART interface
    CONFIG_SERIAL=y
    CONFIG_UART_ASYNC_API=y
    CONFIG_NRFX_TIMER2=y
    
    # LTE link control
    CONFIG_LTE_LINK_CONTROL=y
    CONFIG_LTE_AUTO_INIT_AND_CONNECT=n
    CONFIG_LTE_NETWORK_MODE_NBIOT=y      #+
    CONFIG_LTE_LEGACY_PCO_MODE=y        #+      
    
    # Stacks and heaps
    CONFIG_MAIN_STACK_SIZE=4096
    CONFIG_HEAP_MEM_POOL_SIZE=16384
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=8192
    
    # AT_CMD
    # Enable AT_CMD debug for details
    #CONFIG_AT_CMD_LOG_LEVEL_DBG=y
    
    # Device power management
    CONFIG_DEVICE_POWER_MANAGEMENT=y
    
    # Enable SUPL client support
    #CONFIG_SUPL_CLIENT_LIB=y
    
    # Application-specific
    CONFIG_SLM_LOG_LEVEL_INF=y
    # Enable GPIO wakeup if sleep is expected
    #CONFIG_SLM_GPIO_WAKEUP=y
    # Use UART_0 (when working with PC terminal)
    CONFIG_UART_0_NRF_HW_ASYNC_TIMER=2
    # Use UART_2 (when working with external MCU)
    #CONFIG_SLM_CONNECT_UART_2=y
    #CONFIG_UART_2_NRF_HW_ASYNC_TIMER=2
    # Use optional TCP/TLS Proxy
    #CONFIG_SLM_TCP_PROXY=y
    # Use optional UDP/DTLS Proxy
    #CONFIG_SLM_UDP_PROXY=y
    

    The program you gave me didn't use lte_lc_init_and_connect() at the beginning.

    I tried again, and the problem remained the same. Here is my log:

  • Hi,
    The program I sent you is the default SLM version from NCS tag 1.3.2.

    If you are using the default settings and code from the tag 1.3.2 you should have the same code as here.

    Which mfw version are you running?

    Make sure you have a newer modem firmware on the device.


    Please try to just run the application without debugging enabled and using another serial terminal, e.g. using the LTE Link monitor or Termite.


    Default behavior when resetting the board and getting the "ready" signal from SLM and then sending AT+CFUN? is that it is in offline mode (AT+CFUN=4).

    However in your case it is ON for some reason, and you also get a notification +CSCON:0, which let me to belive you are doing some additional stuff you are not mentioning in this case. (e.g. do you have several serial terminals open?)
    Anyway, please follow my suggestions mentioned at the beginning of this post)

Related