« nrf_modem_at_cmd_async » HARD_FAULT

Using the « nrf_modem_at_cmd_async » function triggered an HARD_FAULT error if it  is the first  function used in the code before another function  of the AT interface of the modem library.

If an « nrf_modem_at_cmd » is sent to modem before the « nrf_modem_at_cmd_async » it works well.

#include <string.h>
#include <zephyr.h>
#include <stdio.h>
#include <nrf_modem_at.h>
#include <modem/nrf_modem_lib.h>

static K_SEM_DEFINE(cfun_sem, 0, 1);

void at_callback(const char *at_response)
{
	printk("AT response received:\n%s\n", at_response);
	k_sem_give(&cfun_sem);
}

void main(void)
{
	int err;
	char response[64];

	nrf_modem_lib_init(NORMAL_MODE);

	/* Without this cmd or any else nrf_modem_at_... cmd the  «nrf_modem_at_cmd_async » fails */
	// err = nrf_modem_at_cmd(response, sizeof(response), "AT+CEREG?");
	// if (err) {
	// 	printk("Failed to read CEREG, err %d\n", err);
	// }
	// printk("Modem response:\n%s", response);

	err = nrf_modem_at_cmd_async(at_callback, "AT+CFUN=%i", 1);
	if (err) 
	{
		printk("Error : %i", err);
	}

	printk("Waiting for network\n");

	err = k_sem_take(&cfun_sem, K_SECONDS(20));

	printk("Shutting down modem\n");
	err = nrf_modem_at_printf("AT+CFUN=0");
	if (err) {
		printk("AT+CFUN failed\n");
		return;
	}
	nrf_modem_lib_shutdown();
	printk("Bye\n");
}

Here is the prj.conf file : 

CONFIG_NRF_MODEM_LIB=y
CONFIG_NRF_MODEM_LIB_SYS_INIT=n
CONFIG_NEWLIB_LIBC=y

CONFIG_LOG=y
CONFIG_ASSERT=y

The error when no « err = nrf_modem_at_cmd(response, sizeof(response), "AT+CEREG?"); » before  « nrf_modem_at_cmd_async » :

And the correct behavior with the line  « err = nrf_modem_at_cmd(response, sizeof(response), "AT+CEREG?"); » before  « nrf_modem_at_cmd_async » : 

I am using an nrf9160DK with NCS v1.7.0 and modem firmware v1.3.0.

Have you an idea of what cause this HARD_FAULT ?

Billy

Parents Reply Children
  • Hi Billy,

    The issue is a NULL pointer dereference and the fix is already in the PR queue. As a workaround for now(as you already figured out) you need to call any of the `nrf_modem_at` functions that do not require an async callback, then call the async function.

    It was also suggested to set CONFIG_MAIN_STACK_SIZE to '4096', however, this might not have any impact.

    Best regards,

    Håkon

Related