cancel
Showing results for 
Search instead for 
Did you mean: 

why program counter goes to HardFault_Handler whenever it receive data on TCP server

vchau.2
Associate III

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.

4 REPLIES 4

Show registers and disassembly of instructions at and immediately prior to faulting instruction.

S​how stack.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..


_legacyfs_online_stmicro_images_0693W00000bimeVQAQ.png

vchau.2
Associate III

Here is it, but question is same, How to identify the issue

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..