2023-04-25 04:56 AM
Dear All,
I'm using STM32F429ZI-Nucleo for Ethernet, I'm using this board as TCP server, Connecting with client Thats working fine but whenever client send data to server MCU going to HardFauld_Handler, I'm not able to identify this issue
Kindly guide why this happen.
static void tcp_server_handle (struct tcp_pcb *tpcb, struct tcp_server_struct *es)
{
struct tcp_server_struct *esTx;
/* get the Remote IP */
ip4_addr_t inIP = tpcb->remote_ip;
uint16_t inPort = tpcb->remote_port;
/* Extract the IP */
char *remIP = ipaddr_ntoa(&inIP);
esTx->state = es->state;
esTx->pcb = es->pcb;
esTx->p = es->p;
char buf[100];
memset (buf, '\0', 100);
strncpy(buf, (char *)es->p->payload, es->p->tot_len);
strcat (buf, "+ Hello from TCP SERVER\n");
esTx->p->payload = (void *)buf;
esTx->p->tot_len = (es->p->tot_len - es->p->len) + strlen (buf);
esTx->p->len = strlen (buf);
tcp_server_send(tpcb, esTx);
pbuf_free(es->p);
}
On execution the Last 4th line Its goes to HardFault.
2023-04-25 06:05 AM
Show registers and disassembly of instructions at and immediately prior to faulting instruction.
Show stack.
2023-04-25 06:10 AM - edited 2023-11-20 07:11 AM
2023-04-25 06:11 AM
Here is it, but question is same, How to identify the issue
2023-04-25 08:44 AM
That doesn't show the faulting instruction, or the MCU registers.
The MCU provides a lot of information about WHY it's faulting, you need to decode that, and review it in the context of your code.
Mostly likely here, as you aren't sanity check any of the variables or lengths, is that you're not receiving a NUL terminated string, and that what you are receiving is larger than the buffer you're placing it into.
If using the debugger, expect to go and inspect the content of related variables and buffers.
I've posted multiple times what I think a minimal Hard Fault Handler should look like and report.