Skip to main content
Graduate
April 25, 2023
Question

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

  • April 25, 2023
  • 2 replies
  • 1891 views

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.

    This topic has been closed for replies.

    2 replies

    Graduate II
    April 25, 2023

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

    S​how stack.

    vchau.2Author
    Graduate
    April 25, 2023


    _legacyfs_online_stmicro_images_0693W00000bimeVQAQ.png

    vchau.2Author
    Graduate
    April 25, 2023

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

    Graduate II
    April 25, 2023

    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.