Board: nrf7002
nrfConnect SDK 2.4.0 or 2.4.99
IDE: VS code
I’m working on implementing SignalR communication protocol, It uses SSE(Server-Sent Events) communication, so once connected, one socket needs to remain open to receive new data, and we also need to send other messages over an additional socket.
I’m getting a fault when using a second socket, I set it up in the same way as I made the first one. I am modifying the solution found https://devzone.nordicsemi.com/f/nordic-q-a/100826/nrf7002dk-and-tls-sockets--7100-error/433368 to do this. It always faults weather the first socket gets used or not.
Here is the code to create the sockets (changes nslookup to google from my domain):
int sock;
int sock2;
int err;
struct sockaddr_in *sa;
struct addrinfo *rp;
struct sockaddr_in *sa2;
struct addrinfo *rp2;
nslookup("google.com", &rp);
print_addrinfo_results(&rp);
nslookup("google.com", &rp2);
print_addrinfo_results(&rp2);
printk("Connecting to HTTP Server:\n");
// Load in the TLS cert for HTTPS
tls_credential_add(CA_CERTIFICATE_TAG, TLS_CREDENTIAL_CA_CERTIFICATE,
ca_certificate, sizeof(ca_certificate));
// Create Socket
sock = socket(rp->ai_family, rp->ai_socktype, IPPROTO_TLS_1_2); // IPPROTO_TCP //IPPROTO_TLS_1_2
if (sock < 0)
{
printk("Error creating socket\n");
return (-1);
}
// TLS settings
sec_tag_t sec_tag_opt[] = {
CA_CERTIFICATE_TAG,
};
err = setsockopt(sock, SOL_TLS, TLS_SEC_TAG_LIST,
sec_tag_opt, sizeof(sec_tag_opt));
if (err < 0)
{
LOG_ERR("Failed to set TLS security TAG list. Err: %d", errno);
(void)close(sock);
return -errno;
}
err = setsockopt(sock, SOL_TLS, TLS_HOSTNAME,
HTTP_HOST, sizeof(HTTP_HOST));
if (err < 0)
{
LOG_ERR("Failed to set TLS_HOSTNAME option. Err: %d", errno);
(void)close(sock);
return -errno;
}
// Iterate through until we get a successful connection
for (; rp != NULL; rp = rp->ai_next)
{
if (rp->ai_addr->sa_family == AF_INET)
{
// IPv4 Address
sa = (struct sockaddr_in *)rp->ai_addr;
sa->sin_port = htons(443);// this should be 443 (HTTPS port number)
connect(sock, (struct sockaddr *)sa, sizeof(struct sockaddr_in));
if (sock > 0)
break;
}
}
// Create Socket 2
sock2 = socket(rp2->ai_family, rp2->ai_socktype, IPPROTO_TLS_1_2); // IPPROTO_TCP //IPPROTO_TLS_1_2
if (sock2 < 0)
{
printk("Error creating socket\n");
return (-1);
}
sec_tag_t sec_tag_opt2[] = {
CA_CERTIFICATE_TAG,
};
err = setsockopt(sock2, SOL_TLS, TLS_SEC_TAG_LIST,
sec_tag_opt2, sizeof(sec_tag_opt2));
if (err < 0)
{
LOG_ERR("Failed to set TLS security TAG list. Err: %d", errno);
(void)close(sock2);
return -errno;
}
err = setsockopt(sock2, SOL_TLS, TLS_HOSTNAME,
HTTP_HOST, sizeof(HTTP_HOST));
if (err < 0)
{
LOG_ERR("Failed to set TLS_HOSTNAME option. Err: %d", errno);
(void)close(sock2);
return -errno;
}
// Iterate through until we get a successful connection
for (; rp2 != NULL; rp2 = rp2->ai_next)
{
if (rp2->ai_addr->sa_family == AF_INET)
{
// IPv4 Address
sa2 = (struct sockaddr_in *)rp2->ai_addr;
sa2->sin_port = htons(443);// this should be 443 (HTTPS port number)
connect(sock2, (struct sockaddr *)sa2, sizeof(struct sockaddr_in));
if (sock2 > 0)
break;
}
}
Here is the error log:
<err> os: ***** MPU FAULT *****
[00:00:35.620,819] <err> os: Data Access Violation
[00:00:35.620,819] <err> os: MMFAR Address: 0x0
[00:00:35.620,819] <err> os: r0/a1: 0x00000000 r1/a2: 0x00000000 r2/a3: 0x00000000
[00:00:35.620,849] <err> os: r3/a4: 0x00000000 r12/ip: 0x00000413 r14/lr: 0x00004140
[00:00:35.620,849] <err> os: xpsr: 0x29000000
[00:00:35.620,880] <err> os: Faulting instruction address (r15/pc): 0x0004e620
[00:00:35.620,910] <err> os: >>> ZEPHYR FATAL ERROR 19: Unknown error on CPU 0
[00:00:35.620,941] <err> os: Current thread: 0x200049c8 (main)
......
[00:00:37.542,816] <err> fatal_error: Resetting system
Thanks for your help