2016-10-11 10:45 AM
Hello
I send and receive data from Ethernet with cmsis library I send my data with send function each 100ms(with each timer interrupt)void send(void){
unsigned char i;
unsigned long int checksum;
char msg[200];
if(tcp_check_send(socket))
{
checksum=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10;
sprintf(msg,''%06ld%06ld%06ld%06ld%06ld%06ld%06ld%06ld%02hhd%02hhd\n\r'',data1,data2,data3,data4,data5,data6,data7,data8,data9,data10,checksum);
for(i=0;i<200;i++)
{
if(msg[i]=='\0')
{
break;
}
}
sendbuf = tcp_get_buf (i);
memcpy (sendbuf, msg, i);
tcp_send (socket, sendbuf,i);
memset(msg, '\0', sizeof(msg));
}
and receive data with call back function
uint32_t tcp_callback (int32_t soc, tcpEvent event, const uint8_t *buf, uint32_t len){
switch (event) {
case tcpEventConnect:return (1);
case tcpEventAbort:tcp_close(socket);break;
case tcpEventEstablished:break;
case tcpEventClosed:break;
case tcpEventACK:break;
case tcpEventData:
flag=1;
memset(&pcstr[0], '\0', sizeof(pcstr));
memcpy (pcstr,buf, len);
break;
}
return (0);
}
and here is my main settings
int main (void)
{
net_initialize();
socket = tcp_get_socket (TCP_TYPE_SERVER | TCP_TYPE_KEEP_ALIVE, 0, 10,tcp_callback);
if(socket!=0){
tcp_listen (socket, 5000);
}
while (1)
{
//somecode
}
}
my code works fine and send and receive data and unfortunately it hangs after for several seconds.As I debug my MCU I see that net_initialize() make it hangs(but I call it only once).
and it shows me the error line
and here is my fault report
why my bus makes fault? and what is my mistake?
2016-10-11 11:18 AM
This is not where the fault is actually occurring, you need to dig deeper and look at the registers and the assembler code immediately around the code that faults. before/after. Don't rely on the tool-chain to point to decode the stacked fault context, or understand the generated code.
Do you have an adequate stack for your local/auto allocations, call tree, and interruptions? Implement a proper Hard Fault Handler, and review the dozens of threads covering this class of failures. Observe also that sprintf() returns the length of the string it is creating.2016-10-11 12:07 PM
Thanks clive1
I'm going to correct again and I will tell you as soon as possible Thank you zillion