lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] LWIP client code causes hard fault error


From: Funk, Artur
Subject: Re: [lwip-users] LWIP client code causes hard fault error
Date: Tue, 26 Jun 2012 15:31:55 +0200

When does it fails? While the first transfer or after several tries? If
it fails after several calls of your sending function, the problem could
be, that you don't free allocated memory or don't close the established
connection proper. If it fails on first transfer, it could be a pointer
reason. Your function seems to be incomplete isn't it?
Here is an example to close the connection after sending
   tcp_arg(pcbname, NULL);
   tcp_sent(pcbname, NULL);
   tcp_recv(pcbname, NULL);

   mem_free(data);
   tcp_close(pcbname);

void TCP_send(void)
{
      uint32_t (*ptr)[3]; // pointer to the     ADC_TDstamped_SRAM
array.
      #ifdef UserButton_InteruptFor_ADCConversion
      sprintf((char*)data, "Potentiometer value is, %d\n",
ADC3ConvertedValue);

      /* allocate pbuf */
      es->p_tx = pbuf_alloc(PBUF_TRANSPORT, strlen((char*)data) ,
PBUF_POOL);
         
      if (es->p_tx)
      {       
     
            /* copy data to pbuf */
        pbuf_take(es->p_tx, (char*)data, strlen((char*)data));
        
        /* send data */
                TCPData_send(pcb,es);
      }
}

What I can see is:
uint32_t (*ptr)[3]; <- unused

sprintf((char*)data.... <- where is data dfined?

es->p_tx = pbuf_alloc(PBUF_TRANSPORT, strlen((char*)data)  <- are u sure
the data is always null terminated?


Note if you allocate each time new memory space for you data, don't
forget to free the memory and to set the pointer to NULL.

I hope I can calm u down if I would say that such errors I have had in
the past were based on my own mistakes and not on LwIP.



Best regards


Artur




reply via email to

[Prev in Thread] Current Thread [Next in Thread]