NRF Connect Debug getting stuck at log_core.c

Hi there, I am working on setting up a HTTPS GET request with TLS credentials on the nrf7002dk. I am getting MPU Fault and Data Access Violation whenever I try to send packet to the server, I've tried to tune the memory sizes in prj.conf (didn't work, could have missed something there...), so I decided to step-through debug and see what went wrong. However, when I let the code run, it would always stop at the line shown in the attached image. I'm not really sure why this is happening, the debugger was working fine before, and I would really appreciate some help on its cause! Thank you for reading and offering any help if possible, have a fabulous day! Slight smile

  -Eric

  • Hi,

    Could you please provide more information about your application? Is it based on any of the nrf or zephyr samples? What is desired behavior of your application? Which server do you use?

    I am working on setting up a HTTPS GET request with TLS credentials on the nrf7002dk.

    Could you elaborate on this?

    the debugger was working fine before

    Was there an error in your application before?

    What happens if you remove logging from your application?

    Best regards,
    Dejan

  • Hi Dejans, thank you for replying! Yes, I can elaborate, sorry if my post description was vague. It is based on nrf's https_client example, desired behavior is sending a HTTPS request to a website and receiving response from it. I am using google.com and we intend to eventually use our own server. To elaborate on setting up the GET request, please the code block here, assuming that we have made connection to WiFi:

    int tls_setup(int fd)
    {
    	int err, verify;
    	#define TLS_SEC_TAG 42
    
    	const sec_tag_t tls_sec_tag[] = {
    		TLS_SEC_TAG,
    	};
    
    #if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
    	err = tls_credential_add(tls_sec_tag[0], TLS_CREDENTIAL_CA_CERTIFICATE, ca_certificate, sizeof(ca_certificate));
    	if (err) {
    		return err;
    	}
    #endif
    
    	// Setup TLS peer verification
    	enum {
    		NONE = 0,
    		OPTIONAL,
    		REQUIRED,
    	};
    
    	err = setsockopt(fd, SOL_TLS, TLS_PEER_VERIFY, &verify, sizeof(verify));
    	if (err)
    	{
    		LOG_ERR("Failed to setup peer verification! %d", err);
    		return err;
    	}
    
    	err = setsockopt(fd, SOL_TLS, TLS_SEC_TAG_LIST, tls_sec_tag, sizeof(tls_sec_tag));
    	if (err)
    	{
    		LOG_ERR("Failed to setup TLS sec tag! %d", err);
    		return err;
    	}
    
    	err = setsockopt(fd, SOL_TLS, TLS_HOSTNAME, HTTP_HOST, sizeof(HTTP_HOST));
    	if (err)
    	{
    		LOG_ERR("Failed to setup TLS hostname! %d", err);
    		return err;
    	}
    
    	return 0;
    }
    
    void main()
    {
    	int err;
    	int fd;
    	char *p;
    	int bytes;
    	size_t off;
    	struct addrinfo *res;
    	struct addrinfo hints = {
    		.ai_flags = AF_UNSPEC, /* Let getaddrinfo() set port */
    		.ai_socktype = SOCK_STREAM,
    	};
    	char peer_addr[INET6_ADDRSTRLEN];
    
    	LOG_INF("Looking up %s", HTTP_HOST);
    	err = getaddrinfo(HTTP_HOST, HTTP_PORT, &hints, &res);
    	if (err)
    	{
    		LOG_ERR("Error at getaddrinfo! err code %d", err);
    		return;
    	}
    	else
    	{
    		print_addrinfo_results(&res);
    	}
    
    	inet_ntop(res->ai_family, &((struct sockaddr_in *)(res->ai_addr))->sin_addr, peer_addr,
    		  INET6_ADDRSTRLEN);
    	LOG_INF("Resolved %s (%s)\n", peer_addr, net_family2str(res->ai_family));
    
    #if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
    	// FIXME: Needs socket offloading to work
    	// fd = socket(res->ai_family, SOCK_STREAM | SOCK_NATIVE_TLS, IPPROTO_TLS_1_2);
    	fd = socket(res->ai_family, SOCK_STREAM, IPPROTO_TLS_1_2);
    #else
    	fd = socket(res->ai_family, SOCK_STREAM, IPPROTO_TCP);
    #endif
    
    if (fd == -1)
    	{
    		LOG_ERR("Failed to open socket!");
    		return;
    	}
    	else
    	{
    		LOG_INF("Successfully created socket %d!", fd);
    	}
    
    	err = tls_setup(fd);
    	if (err)
    	{
    		LOG_ERR("Error while setting up TLS socket options! %d");
    	}
    	else
    	{
    		LOG_INF("TLS socket options set!");
    	}
    
        // Fault happens with we try to connect
    	err = connect(fd, res->ai_addr, res->ai_addrlen);
    	if (err)
    	{
    		LOG_ERR("connect() failed, err: %d\n", errno);
    	}
    	else
    	{
    		LOG_INF("Socket connected!");
    	}
    
    }

    What I meant by "the debugger was working fine before" was, there were a couple times when I am able to step through line by line till the fault happens, but when I try to debug again, the debugger gets stuck at log_core.c 

    I have not tried remove logging from my application, I will give it a shot tomorrow!

  • Hi,

    Which NCS version do you use?

    Could you provide full application log?

    Best regards,
    Dejan

  • Hi dejans, sorry for replying late, I am on 2.4.0 NCS. I recently changed my device tree files for nrf7002dk so I couldn't get the code running on my setup, but I used my colleague's machine and got the following output (took out some network info that shouldn't be important):

    00> [00:00:00.493,072] <inf> fs_nvs: 6 Sectors of 4096 bytes
    00> [00:00:00.493,103] <inf> fs_nvs: alloc wra: 0, fe8
    00> [00:00:00.493,133] <inf> fs_nvs: data wra: 0, 0
    00> *** Booting Zephyr OS build v3.3.99-ncs1 ***
    00> [00:00:00.493,194] <inf> net_config: Initializing network
    00> [00:00:00.493,225] <inf> net_config: Waiting interface 1 (0x20000d78) to be up...
    00> [00:00:00.493,225] <inf> net_config: Running dhcpv4 client...
    00> [00:00:00.497,436] <inf> NRF72: Hello World! nrf7002dk_nrf5340_cpuapp
    00>
    00> [00:00:00.497,467] <inf> NRF72: Sleeping for 1 second while wlan0 comes up
    00>
    00> [00:00:01.497,558] <inf> NRF72: Setting up WiFi Interface on Host: zephyr
    00>
    00> [00:00:01.497,558] <inf> NRF72: Ethernet MAC Address =
    00> [00:00:01.497,558] <inf> NRF72: F4
    00> [00:00:01.497,589] <inf> NRF72: :
    00> [00:00:01.497,589] <inf> NRF72:
    00> [00:00:01.497,619] <inf> NRF72: :
    00> [00:00:01.497,619] <inf> NRF72: 
    00> [00:00:01.497,619] <inf> NRF[00:00:02.498,931] <wrn> wifi_credentials: Cannot retrieve WiFi credentials, no entry found for the provided SSID
    00> [00:00:02.498,992] <inf> wifi_mgmt_ext: Adding statically configured WiFi network [WIFISSID] to internal list.
    00> [00:00:08.415,557] <inf> NRF72: Checking connection result
    00>
    00> [00:00:08.415,557] <inf> NRF72: Connected!
    00>
    00> [00:00:08.415,832] <inf> NRF72: Requesting WiFi Status
    00> [00:00:08.427,185] <inf> NRF72: SSID: WIFISSID
    00>
    00> [00:00:08.427,215] <inf> NRF72: Band: 5GHz
    00>
    00> [00:00:08.427,215] <inf> NRF72: Channel: 44
    00>
    00> [00:00:08.427,246] <inf> NRF72: Security: WPA2-PSK
    00>
    00> [00:00:08.427,246] <inf> NRF72: RSSI: -41
    00>
    00> [00:00:08.819,305] <inf> net_dhcpv4: Received: 
    00> [00:00:08.819,427] <inf> net_config: IPv4 address: 
    00> [00:00:08.819,458] <inf> net_config: Lease time: 7009 seconds
    00> [00:00:08.819,488] <inf> net_config: Subnet:
    00> [00:00:08.819,519] <inf> net_config: Router:
    00> [00:00:09.427,673] <inf> NRF72: Resolving IP Address...
    00> [00:00:10.452,453] <err> os: ***** USAGE FAULT *****
    00> [00:00:10.452,484] <err> os:   Unaligned memory access
    00> [00:00:10.452,484] <err> os: r0/a1:  0x00000000  r1/a2:  0xffffffff  r2/a3:  0x00000000
    00> [00:00:10.452,514] <err> os: r3/a4:  0x200689c8 r12/ip:  0x20001a10 r14/lr:  0x0003ba21
    00> [00:00:10.452,514] <err> os:  xpsr:  0x69000000
    00> [00:00:10.452,514] <err> os: Faulting instruction address (r15/pc): 0x00002a96
    00> [00:00:10.452,545] <err> os: >>> ZEPHYR FATAL ERROR 31: Unknown error on CPU 0
    00> [00:00:10.452,575] <err> os: Current thread: 0x200022b0 (unknown)
    00> [00:00:10.735,534] <err> fatal_error: Resetting system
    00> [00:00:00.492,797] <inf> fs_nvs: 6 Sectors of 4096 bytes
    00> [00:00:00.492,828] <inf> fs_nvs: alloc wra: 0, fe8
    00> [00:00:00.492,828] <inf> fs_nvs: data wra: 0, 0
    00> *** Booting Zephyr OS build v3.3.99-ncs1 ***
    00> [00:00:00.492,919] <inf> net_config: Initializing network

    Usually when I step through the code using the debugger, it enters the log_core.c before the breakpoint where the memory fault happens.

    I also will try disabling logging and see if that helps (probably use printk instead), but might have to wait a bit until I'm able to revert the device tree file changes for 7002dk on my computer. I hope it's okay for me to keep you posted on this!

    Best wishes.

    Eric

  • Hi,

    There is no official sample yet with HTTPS support for nrf7002-dk, but you could have a look at the following discussions - TLS handshake and nrf7002 sockets and TLS sockets

    Best regards,
    Dejan

Related