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

nrf_modem_lib_shutdown takes a long time

Hello, 

We are trying to use `nrf_modem_lib_shutdown` to turn off the modem before entering system OFF mode. We are using LTE link control, with the following LTE settings: 

CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_AUTO_INIT_AND_CONNECT=n
CONFIG_LTE_NETWORK_TIMEOUT=10
CONFIG_LTE_NETWORK_USE_FALLBACK=n
CONFIG_LTE_EDRX_REQ=y
CONFIG_LTE_EDRX_REQ_VALUE="0000"

We've noticed that it seems the `nrf_modem_lib_shutdown` function takes around a minute to complete, and were wondering if there is something else impacting this time and if there's anything we can do to shorten it. The current flow of the system OFF workflow is to close any open sockets, call nrf_modem_lib_shutdown, and call nrf_regulators_system_off(NRF_REGULATORS_NS). 

We are on: ncs v1.5.0 with zephyr OS v2.4.99

  • Hi,

    Are you using NB-IoT or LTE-M?

    Before you shut down the modem lib, you must also turn off the modem.

    You can do that by calling lte_lc_power_off.

    Why do you want to shut down the modem lib?

    Best regards,

    Didrik

  • We are using LTE-M. 

    It appears in the source that lte_lc_deinit() should be called within that function, which calls lte_lc_power_off. We're shutting it down because we have a case where we want to put the device into the low power system OFF mode, and we believed this function was necessary before doing so.

    We had made some changes due to upgrading to 1.5.0. We were previously we were looking at this part of the serial_lte_modem sample in an older ncs version 1.2.0: 

    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);
    }

    The bsd_shutdown function seemed to have removed in the latest version of this sample: 

    void enter_sleep(bool wake_up)
    {
    #if defined(CONFIG_SLM_GPIO_WAKEUP)
    	/*
    	 * Due to errata 4, Always configure PIN_CNF[n].INPUT before
    	 *  PIN_CNF[n].SENSE.
    	 */
    	if (wake_up) {
    		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();
    	k_sleep(K_SECONDS(1));
    #if defined(CONFIG_SLM_GPIO_WAKEUP)
    	if (wake_up) {
    		nrf_regulators_system_off(NRF_REGULATORS_NS);
    	}
    #endif	/* CONFIG_SLM_GPIO_WAKEUP */
    }

    But we found that just removing bsd_shutdown would make the device not enter the system off mode (drawing about 4mA), and adding nrf_modem_lib_shutdown did, although it took a long time. 

    Perhaps there is a different function that is more appropriate to make the device enter system off more quickly? 

  • Hello, and sorry for the late answer,

     

    jessyan said:
    The bsd_shutdown function seemed to have removed in the latest version of this sample: 

     The bsd library has been renamed to nrf_modem.

    So bsd_shutdown is now called nrf_modem_lib_shutdown.

    Have you tried calling lte_lc_power_off and nrf_modem_lib_shutdown individually to see which function takes time?

  • should reverse do..............
    nrf_modem_lib_shutdown first 
    and 
    nrf_modem_lib_init

    if you want to shot down again
    then sys_reboot(0);

    the wait time almost 0ms

    EX: 
    void main(void)
    {
    uint32_t lasttick;

    printf("main start\n");

    printk("modem shutdown start\n");
    int modemtick = k_uptime_get_32();
    nrf_modem_lib_shutdown();
    printk("modem shutdown end time: %d\n", k_uptime_get_32()-modemtick);

    printk("nrf_modem_lib_init\n");
    nrf_modem_lib_init(NORMAL_MODE);

    printk("sys_reboot\n");
    sys_reboot(0);
    }

    also refer to this
    devzone.nordicsemi.com/.../nrf_modem_lib_shutdown-need-48-seconds-bug-report

Related