|
感谢开源电子网。 |
XUZJWWSZ 发表于 2017-5-3 23:22 谢谢分享 |
|
另外我在官方FREE RTOS + LWIP的例程中找到一个开发板做服务器的例子: 用这个代码每次TCP客户端发送一组数据,作为服务器的开发板收到数据原样返回,然后它自己就主动断开连接了!这种情况下也不存在卡死的情况了 ![]() 我试着把主动断开连接的代码删掉,然后问题依旧。 [mw_shl_code=applescript,true]void another_server_netconn_thread(void *arg) { struct netconn *conn, *newconn; err_t err, accept_err; /* Create a new TCP connection handle */ conn = netconn_new(NETCONN_TCP); if (conn!= NULL) { /* Bind to port 80 (HTTP) with default IP address */ err = netconn_bind(conn, NULL, 1032); if (err == ERR_OK) { /* Put the connection into LISTEN state */ netconn_listen(conn); while(1) { /* accept any icoming connection */ accept_err = netconn_accept(conn, &newconn); if(accept_err == ERR_OK) { /* serve connection */ http_server_serve(newconn); /* delete connection */ netconn_delete(newconn); } } } else { /* delete connection */ netconn_delete(newconn); printf("can not bind netconn"); } } else { printf("can not create netconn"); } }[/mw_shl_code][mw_shl_code=applescript,true]void http_server_serve(struct netconn *conn) { struct netbuf *inbuf; err_t recv_err; char* buf; u16_t buflen; struct fs_file * file; 下面这段代码被我简化了,原本是发送网页的程序。 /* Read the data from the port, blocking if nothing yet there. We assume the request (the part we care about) is in one netbuf */ recv_err = netconn_recv(conn, &inbuf); if (recv_err == ERR_OK) { if (netconn_err(conn) == ERR_OK) { netbuf_data(inbuf, (void**)&buf, &buflen); netconn_write(conn,&buf,buflen,NETCONN_NOCOPY); } } /* Close the connection (server closes in HTTP) */ netconn_close(conn); /* Delete the buffer (netconn_recv gives us ownership, so we have to make sure to deallocate the buffer) */ netbuf_delete(inbuf); }[/mw_shl_code] |
XUZJWWSZ 发表于 2017-5-1 22:06 STLINK当然是可以在线调试的,你就在线调试,出fault之后看看调用栈,应该可以发现问题点 另外注意,你的ucos是否移植正确 再一个,检查是否在中断中调用了不能调用的API函数 |
zmingwang 发表于 2017-4-30 18:55 请看一下第5楼,我找到了导致卡死的语句,但还是想不通。 仿真调试我没用过,上网查了一下方法都不详细,能否详细说一下,我手边只有ST-LINK可以吗? |
zmingwang 发表于 2017-4-30 18:55 多谢你,我试试,昨晚不小心睡着了 ![]() |
|
跟踪TCP的FIN状态,便可知哪里出了问题 另外,在进入HardFault中断后,查看调用栈,或许会有有用的信息. |
|
我通过下面的代码暂时解决了问题,这个写法是参考一个别人分享的代码。 至于为什么用q->len==28 && q->flags == 0 && q->type == 20做判断条件我也不知,是通过实验得到的。 [mw_shl_code=applescript,true] while(1) { accept_err=netconn_accept(conn,&newconn); if (newconn) { struct netbuf *inbuf; char* buf; u16_t buflen; while(netconn_recv(newconn, &inbuf) == ERR_OK) { recv_err=ERR_OK; //sys_arch_protect();//½øÈëÁÙ½çÇø for(q=inbuf->p;q!=NULL;q=q->next) //±éÀúÍêÕû¸öpbufÁ´±í { if(q->len==28 && q->flags == 0 && q->type == 20) { recv_err=ERR_CONN; //printf("\r\n q->flags=%d ,q->ref=%d ,q->type=%d\r\n",q->flags,q->ref,q->type); break; }//ÔÝʱ½â¾öTCP¶Ï¿ªÁ¬½ÓËÀ»úµÄÎÊÌâ2015-8-17@zzh } //sys_arch_protect();//Í˳öÁÙ½çÇø if(recv_err < ERR_ISCONN)//ÔÝʱ½â¾öTCP¶Ï¿ªÁ¬½ÓËÀ»úµÄÎÊÌâ2015-8-17@zzh { netbuf_delete(inbuf); netconn_close(newconn); netconn_delete(newconn); printf("\r\n ·þÎñÆ÷¶Ï¿ªÁ¬½Ó \r\n"); break; } else { do { netbuf_data(inbuf, (void**)&buf, &buflen); commandbuf[0]=*buf; commandbuf[1]=*(buf+1); ETH_receive_Handle(commandbuf,buflen); netconn_write(newconn, buf, buflen, NETCONN_COPY); } while (netbuf_next(inbuf) >= 0); //netconn_close(newconn); netbuf_delete(inbuf); } } netconn_close(newconn); netconn_delete(newconn); } }[/mw_shl_code] |
/1
|手机版|OpenEdv-开源电子网
( 粤ICP备12000418号-1 )
GMT+8, 2026-4-23 17:37
Powered by OpenEdv-开源电子网
© 2001-2030 OpenEdv-开源电子网