{"id":18216,"date":"2025-04-19T00:38:44","date_gmt":"2025-04-18T16:38:44","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/18216.html"},"modified":"2025-04-19T00:38:44","modified_gmt":"2025-04-18T16:38:44","slug":"cubemx%e5%ae%9e%e7%8e%b0lan8720alwipfreertostcp%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%88%9b%e5%bb%ba","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/18216.html","title":{"rendered":"Cubemx\u5b9e\u73b0LAN8720A+LWIP+Freertos+tcp\u670d\u52a1\u5668\u521b\u5efa"},"content":{"rendered":"<h2 id=\"%E4%B8%80%E3%80%81%E5%AE%9E%E9%AA%8C%E5%B9%B3%E5%8F%B0\" style=\"background-color:transparent\">\u4e00\u3001\u5b9e\u9a8c\u5e73\u53f0<\/h2>\n<p>\u7528\u7684STM32G431CBU6\u4e3b\u677f&#xff0c;\u4ee5\u592a\u7f51\u5361PHY\u5c42\u82af\u7247\u662fLAN8720A\u3002<\/p>\n<h2 id=\"%E4%BA%8C%E3%80%81%E9%85%8D%E7%BD%AE%E6%AD%A5%E9%AA%A4\" style=\"background-color:transparent\">\u4e8c\u3001\u914d\u7f6e\u6b65\u9aa4<\/h2>\n<p>\u9009\u62e9\u82af\u7247\u5c31\u7565\u8fc7\u4e86&#xff0c;\u7b2c\u4e00\u6b65\u5148\u914d\u7f6e\u4e00\u4e2a\u4e32\u53e3&#xff0c;\u76f4\u63a5\u914d\u6210\u5f02\u6b65\u6a21\u5f0f&#xff0c;\u5176\u4ed6\u9ed8\u8ba4\u3002&#xff08;\u65b9\u4fbf\u8c03\u8bd5\u7528&#xff0c;\u8bb0\u5f97\u7ed9\u4e32\u53e3\u7684\u5730\u7ebf\u63a5\u4e0a&#xff09;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"587\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163839-6802800fc75ee.png\" width=\"799\" \/><\/p>\n<p>\u56e0\u4e3a\u6dfb\u52a0\u4e86freertos\u5b9e\u65f6\u64cd\u4f5c\u7cfb\u7edf&#xff0c;\u800cfreertos\u7528\u7684\u662fsystick\u4f5c\u4e3a\u65f6\u949f\u6e90&#xff0c;\u6240\u4ee5\u8981\u5c06HAL\u5e93\u65f6\u949f\u6e90\u6539\u4e3a\u5176\u4ed6\u5b9a\u65f6\u5668\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"339\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163840-68028010066fe.png\" width=\"806\" \/><\/p>\n<p>RCC\u53ef\u4ee5\u4e0d\u914d\u7f6e&#xff0c;\u5982\u679c\u9700\u8981\u66f4\u9ad8\u9891\u7387\u4e5f\u53ef\u4ee5\u914d<\/p>\n<p>\u914d\u7f6eETH\u65f6&#xff0c;\u914d\u7f6e\u4e3aRMII&#xff08;\u5176\u4ed6\u7684\u6ca1\u6709\u8bd5\u8fc7&#xff09;&#xff0c;\u6ce8\u610fMAC\u5730\u5740\u522b\u548c\u5176\u4ed6\u9700\u8981\u8054\u673a\u901a\u8baf\u5355\u7247\u673a\u91cd\u590d\u4e86&#xff0c;PHY Address\u8981\u6839\u636e\u82af\u7247\u7684PHYAD0\u5f15\u811a\u662f\u5426\u60ac\u7a7a\u6765\u914d\u7f6e&#xff0c;\u60ac\u7a7a\u914d\u7f6e\u4e3a0&#xff0c;\u4e0d\u60ac\u7a7a\u4e3a1\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"558\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163840-680280102b8e8.png\" width=\"785\" \/><\/p>\n<p>\u914d\u7f6eLWIP&#xff1a;\u5148\u5c06DHCP\u5173\u95ed&#xff0c;\u7528\u9759\u6001\u5730\u5740\u7684\u65b9\u5f0f\u914d\u7f6eIP\u5730\u5740\u3001\u5b50\u7f51\u63a9\u7801\u3001\u7f51\u5173\u3002ICMP\u8981\u8bbe\u7f6e\u4e3a\u4f7f\u80fd&#xff0c;\u914d\u7f6e\u624d\u53ef\u4ee5ping\u901a\u3002UDP\u548cTCP\u6a21\u5f0f\u9700\u8981\u54ea\u4e2a\u5c31\u53ef\u4ee5\u914d\u7f6e\u54ea\u4e2a\u4f7f\u80fd\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"643\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163840-680280105d3e4.png\" width=\"1082\" \/><\/p>\n<p>\u914d\u7f6ePHY\u82af\u7247\u590d\u4f4d\u5f15\u811a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"609\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163840-68028010b2cdb.png\" width=\"564\" \/><\/p>\n<p>\u5728\u4ee3\u7801\u4e2d\u52a0\u5165\u8fd9\u4e00\u6bb5&#xff0c;\u5c31\u662f\u5c06\u8fde\u63a5PHY\u82af\u7247\u590d\u4f4d\u5f15\u811a\u7684\u90a3\u4e2aGPIO\u62c9\u4f4e\u62c9\u9ad8\u4e00\u4e0b\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"513\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163840-68028010d1c31.png\" width=\"702\" \/><\/p>\n<p>HAL_GPIO_WritePin(RMII_NRST_GPIO_Port, RMII_NRST_Pin, GPIO_PIN_RESET);<br \/>\nHAL_Delay(55);<br \/>\nHAL_GPIO_WritePin(RMII_NRST_GPIO_Port, RMII_NRST_Pin, GPIO_PIN_SET);<br \/>\nHAL_Delay(55); <\/p>\n<p>\u8fd8\u9700\u8981\u5728\u4ee3\u7801\u4e2d\u52a0\u4e0aMX_LWIP_Process();\u548ctcp_server_init();<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"508\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163840-68028010f37b1.png\" width=\"469\" \/><\/p>\n<p>tcp_server.c\u76f8\u5173\u51fd\u6570\u5982\u4e0b<\/p>\n<p>#include &#034;stm32f1xx_hal.h&#034;<br \/>\n#include &#034;lwip.h&#034;<br \/>\n#include &#034;tcp.h&#034;<br \/>\n#include &#034;string.h&#034;<br \/>\n#include &#034;tcp_server.h&#034;<\/p>\n<p>\/* \u5b9a\u4e49\u7aef\u53e3\u53f7 *\/<br \/>\n#define TCP_LOCAL_PORT     8000 \/* \u672c\u5730\u7aef\u53e3 *\/<\/p>\n<p>\/******************************************************************************<br \/>\n * \u63cf\u8ff0  : \u63a5\u6536\u56de\u8c03\u51fd\u6570<br \/>\n * \u53c2\u6570  : &#8211;<br \/>\n * \u8fd4\u56de  : &#8211;<br \/>\n******************************************************************************\/<br \/>\nstatic err_t tcp_server_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)<br \/>\n{<br \/>\nif (p &#061;&#061; NULL)     \/\/\u68c0\u6d4b\u5230\u5bf9\u65b9\u4e3b\u52a8\u5173\u95ed\u8fde\u63a5\u65f6&#xff0c;\u4e5f\u4f1a\u8c03\u7528recv\u51fd\u6570&#xff0c;\u6b64\u65f6p\u4e3a\u7a7a<br \/>\n{<br \/>\nprintf(&#034;ip %d:%d:%d:%d port:%d \u5ba2\u6237\u7aef\u65ad\u5f00\u8fde\u63a5\\\\r\\\\n&#034;,<br \/>\n*((uint8_t *)&amp;tpcb-&gt;remote_ip.addr),<br \/>\n*((uint8_t *)&amp;tpcb-&gt;remote_ip.addr &#043; 1),<br \/>\n*((uint8_t *)&amp;tpcb-&gt;remote_ip.addr &#043; 2),<br \/>\n*((uint8_t *)&amp;tpcb-&gt;remote_ip.addr &#043; 3),<br \/>\ntpcb-&gt;remote_port);<\/p>\n<p>\/\/tcp_write(tpcb, &#034;tcp client closed&#034;, strlen(&#034;tcp client closed&#034;), 0);<\/p>\n<p>tcp_close(tpcb);<\/p>\n<p>err &#061; ERR_CLSD;<br \/>\n}<br \/>\nelse if (err !&#061; ERR_OK)<br \/>\n{<br \/>\npbuf_free(p);<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\n\/\/\u66f4\u65b0\u7a97\u53e3<br \/>\ntcp_recved(tpcb, p-&gt;tot_len);     \/\/\u8bfb\u53d6\u6570\u636e\u7684\u63a7\u5236\u5757   \u5f97\u5230\u6240\u6709\u6570\u636e\u7684\u957f\u5ea6   <\/p>\n<p>void *p_buf&#061;p-&gt;payload;<br \/>\nuint8_t *data &#061; (uint8_t *)p_buf;<br \/>\n            printf(&#034;len:%d \\\\n&#034;,  p-&gt;tot_len);  \/\/ \u4ee5\u5341\u516d\u8fdb\u5236\u5f62\u5f0f\u6253\u5370\u6bcf\u4e2a\u5b57\u8282<br \/>\n        for (u16_t i &#061; 0; i &lt; p-&gt;tot_len; i&#043;&#043;) {<br \/>\n            printf(&#034;data[%d]&#061;%d \\\\n&#034;, i , data[i]);  \/\/ \u4ee5\u5341\u516d\u8fdb\u5236\u5f62\u5f0f\u6253\u5370\u6bcf\u4e2a\u5b57\u8282<br \/>\n        } <\/p>\n<p>\/\/tcp_write(tpcb, &#034;tcp send&#034;, strlen(&#034;tcp send&#034;), 0);<\/p>\n<p>memset(p-&gt;payload, 0 , p-&gt;tot_len);<br \/>\npbuf_free(p);<br \/>\n}<br \/>\n  return err;<br \/>\n}<\/p>\n<p>\/******************************************************************************<br \/>\n * \u63cf\u8ff0  : \u5ba2\u6237\u7aef\u63a5\u5165\u56de\u8c03\u51fd\u6570<br \/>\n * \u53c2\u6570  : &#8211;<br \/>\n * \u8fd4\u56de  : &#8211;<br \/>\n******************************************************************************\/<\/p>\n<p>static err_t tcp_server_accept(void *arg, struct tcp_pcb *newpcb, err_t err)<br \/>\n{     <\/p>\n<p>    printf(&#034;ip %d:%d:%d:%d port:%d \u5ba2\u6237\u7aef\u8fde\u63a5\\\\r\\\\n&#034;,<br \/>\n        *((uint8_t *)&amp;newpcb-&gt;remote_ip.addr),<br \/>\n        *((uint8_t *)&amp;newpcb-&gt;remote_ip.addr &#043; 1),<br \/>\n        *((uint8_t *)&amp;newpcb-&gt;remote_ip.addr &#043; 2),<br \/>\n        *((uint8_t *)&amp;newpcb-&gt;remote_ip.addr &#043; 3),<br \/>\n        newpcb-&gt;remote_port);<\/p>\n<p>    \/\/tcp_write(newpcb, &#034;tcp client connected&#034;, strlen(&#034;tcp client connected&#034;), 0);<\/p>\n<p>    \/* \u6ce8\u518c\u63a5\u6536\u56de\u8c03\u51fd\u6570 *\/<br \/>\n    tcp_recv(newpcb, tcp_server_recv);<br \/>\n    return ERR_OK;<br \/>\n}<\/p>\n<p>\/******************************************************************************<br \/>\n * \u63cf\u8ff0  : \u521b\u5efatcp\u670d\u52a1\u5668<br \/>\n * \u53c2\u6570  : \u65e0<br \/>\n * \u8fd4\u56de  : \u65e0<br \/>\n******************************************************************************\/<\/p>\n<p>void tcp_server_init(void)<br \/>\n{<br \/>\n    struct tcp_pcb *tpcb;<\/p>\n<p>    \/* \u521b\u5efatcp\u63a7\u5236\u5757 *\/<br \/>\n    tpcb &#061; tcp_new();<\/p>\n<p>    if (tpcb !&#061; NULL)<br \/>\n    {<br \/>\n        err_t err;<\/p>\n<p>        \/* \u7ed1\u5b9a\u7aef\u53e3\u63a5\u6536&#xff0c;\u63a5\u6536\u5bf9\u8c61\u4e3a\u6240\u6709ip\u5730\u5740 *\/<br \/>\n        err &#061; tcp_bind(tpcb, IP_ADDR_ANY, TCP_LOCAL_PORT);<\/p>\n<p>        if (err &#061;&#061; ERR_OK)<br \/>\n        {<br \/>\n            \/* \u76d1\u542c *\/<br \/>\n            tpcb &#061; tcp_listen(tpcb);<\/p>\n<p>            \/* \u6ce8\u518c\u63a5\u5165\u56de\u8c03\u51fd\u6570 *\/<br \/>\n            tcp_accept(tpcb, tcp_server_accept);<br \/>\n            printf(&#034;\u670d\u52a1\u5668\u521b\u5efa\u6210\u529f\\\\r\\\\n&#034;);<\/p>\n<p>        }<br \/>\n        else<br \/>\n        {<br \/>\ntcp_close(tpcb);<br \/>\n        }<\/p>\n<p>    }<br \/>\n}<\/p>\n<p>tcp_server.h\u76f8\u5173\u51fd\u6570\u5982\u4e0b<\/p>\n<p>#ifndef _TCPECHO_H_<br \/>\n#define _TCPECHO_H_<\/p>\n<p>void tcp_server_init(void);<\/p>\n<p>#endif<\/p>\n<p>\u73b0\u5728\u53ef\u4ee5\u5c1d\u8bd5ping\u901a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"258\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163841-680280111ca48.png\" width=\"424\" \/><\/p>\n<p>\u5982\u56fe\u5c31ping\u6210\u529f\u4e86<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"603\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163841-68028011354c0.png\" width=\"679\" \/><\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u5ba2\u6237\u7aef&#xff0c;\u53bb\u8fde\u63a5\u5230\u670d\u52a1\u5668\u4e0a&#xff0c;\u5f97\u5230\u4e86\u5982\u56fe\u6548\u679c\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"675\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163841-6802801156464.png\" width=\"1177\" \/><\/p>\n<p>\u63a5\u4e0b\u6765\u6dfb\u52a0freertos&#xff0c;\u6211\u8fd9\u91cc\u9009\u62e9\u7684\u65f6CMSIS_V1&#xff0c;V2\u6ca1\u8bd5\u8fc7&#xff0c;\u6ce8\u610f\u8fd9\u4e2a\u5806\u7a7a\u95f4\u5927\u5c0f\u5c3d\u91cf\u7ed9\u5927\u4e00\u70b9&#xff0c;\u4e0d\u7136\u4f1a\u51fa\u9519&#xff0c;\u8fd8\u6ca1\u627e\u5230\u539f\u56e0<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"702\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163841-68028011a93a0.png\" width=\"791\" \/><\/p>\n<p>\u6dfb\u52a0\u4e00\u4e2a\u521b\u5efatcp\u670d\u52a1\u5668\u4efb\u52a1<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"421\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163841-68028011e47f1.png\" width=\"666\" \/><\/p>\n<p>\u5c06\u539f\u5148\u4ee3\u7801\u5185\u7684\u8fd9\u4e24\u4e2a\u51fd\u6570\u5c4f\u853d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"494\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163842-680280120e53c.png\" width=\"506\" \/><\/p>\n<p>\u518d\u5728\u4efb\u52a1\u51fd\u6570\u91cc\u9762\u6dfb\u52a0\u521b\u5efa\u670d\u52a1\u5668\u51fd\u6570<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"732\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163842-680280122b980.png\" width=\"903\" \/><\/p>\n<p>\u65b0\u7684tcp_server.c\u76f8\u5173\u51fd\u6570\u5982\u4e0b<\/p>\n<p>#include &#034;tcp_server.h&#034;<br \/>\n#include &#034;lwip\/sockets.h&#034;<br \/>\n#include &lt;ctype.h&gt;<\/p>\n<p>char ReadBuff[BUFF_SIZE];<\/p>\n<p>\/* TCP\u670d\u52a1\u5668\u7aef&#xff08;server&#xff09;\u4efb\u52a1 *\/<br \/>\nvoid vTCPServer_Task(void)<br \/>\n{<br \/>\n    int sfd, cfd;<br \/>\n    int read_len;                                \/\/ \u8bfb\u7684\u6570\u636e\u957f\u5ea6<br \/>\n    struct sockaddr_in server_addr, client_addr; \/\/ \u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u7684\u7ed3\u6784\u4f53<br \/>\n    socklen_t client_addr_len;<\/p>\n<p>err_t err;<br \/>\n    \/\/ \u521b\u5efasocket<br \/>\n    sfd &#061; socket(AF_INET, SOCK_STREAM, 0); \/\/ IPV4 socker\u8fde\u63a5 \u9ed8\u8ba4\u534f\u8bae<br \/>\nif(sfd &lt; 0)<br \/>\n{<br \/>\n    printf(&#034;\u521b\u5efa\u5931\u8d25\\\\r\\\\n&#034;);<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\n    printf(&#034;\u521b\u5efa\u6210\u529f\\\\r\\\\n&#034;);<br \/>\n}<br \/>\n    server_addr.sin_family &#061; AF_INET;<br \/>\n    server_addr.sin_port &#061; htons(SERVER_PORT);<br \/>\n    server_addr.sin_addr.s_addr &#061; htonl(INADDR_ANY); \/\/ \u4ece\u672c\u673a\u83b7\u53d6<br \/>\n    \/\/ \u7ed1\u5b9asocket<br \/>\n    err &#061; bind(sfd, (struct sockaddr *)&amp;server_addr, sizeof(server_addr)); \/\/ \u6587\u4ef6\u63cf\u8ff0\u7b26 IP\u5730\u5740\u52a0\u7aef\u53e3\u53f7 addr\u957f\u5ea6 \u8fd4\u56de\u503c<br \/>\nif(err &lt; 0)<br \/>\n{<br \/>\n    printf(&#034;\u7ed1\u5b9a\u5931\u8d25\\\\r\\\\n&#034;);<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\n    printf(&#034;\u7ed1\u5b9a\u6210\u529f %d \\\\r\\\\n&#034;,err);<br \/>\n}<br \/>\n    \/\/ \u76d1\u542csocket<br \/>\n    err &#061; listen(sfd, 5); \/\/ \u6587\u4ef6\u63cf\u8ff0\u7b26 \u63e1\u624b\u961f\u5217\u603b\u548c<br \/>\nif(err &lt; 0)<br \/>\n{<br \/>\n    printf(&#034;\u76d1\u542c\u5931\u8d25\\\\r\\\\n&#034;);<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\n    printf(&#034;\u76d1\u542c\u6210\u529f %d \\\\r\\\\n&#034;,err);<br \/>\n}<\/p>\n<p> printf(&#034;\u7b49\u5f85\u5ba2\u6237\u7aef\u8fde\u63a5\\\\r\\\\n&#034;);<\/p>\n<p> while(1)<br \/>\n {<br \/>\n client_addr_len &#061; sizeof(client_addr);<br \/>\n cfd &#061; accept(sfd, (struct sockaddr *)&amp;client_addr, &amp;client_addr_len); \/\/ \u6587\u4ef6\u63cf\u8ff0\u7b26 IP\u5730\u5740\u52a0\u7aef\u53e3\u53f7 \u8fd4\u56de\u503c<\/p>\n<p>printf(&#034;IP:%s \u7aef\u53e3\u53f7%d \u5ba2\u6237\u7aef\u8fde\u63a5\u6210\u529f\\\\r\\\\n&#034;, inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));<\/p>\n<p> while (1) \/\/ \u7b49\u5f85\u5ba2\u6237\u7aef\u53d1\u9001\u6570\u636e&#xff0c;\u7136\u540e\u8fdb\u884c\u5927\u5c0f\u5199\u8f6c\u6362&#xff0c;\u518d\u5199\u56de\u5ba2\u6237\u7aef<br \/>\n {<br \/>\n read_len &#061; read(cfd, ReadBuff, BUFF_SIZE);<br \/>\n if(read_len &lt;&#061; 0)<br \/>\n {<br \/>\n break;<br \/>\n }<br \/>\n for (int i &#061; 0; i &lt; read_len; i&#043;&#043;)<br \/>\n {<br \/>\n ReadBuff[i] &#061; toupper(ReadBuff[i]); \/\/ \u5c0f\u5199\u8f6c\u6362\u4e3a\u5927\u5199<br \/>\n }<br \/>\n write(cfd, ReadBuff, read_len);<br \/>\n printf(&#034;IP:%s \u7aef\u53e3\u53f7%d \u5ba2\u6237\u7aef\u53d1\u9001\u6570\u636e %s\\\\r\\\\n&#034;, inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port),ReadBuff);<br \/>\n }<\/p>\n<p>printf(&#034;IP:%s \u7aef\u53e3\u53f7%d \u5ba2\u6237\u7aef\u65ad\u5f00\u8fde\u63a5\\\\r\\\\n&#034;, inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));<\/p>\n<p>    closesocket(cfd);<\/p>\n<p> }<br \/>\n}<\/p>\n<p>\u65b0\u7684tcp_server.h\u76f8\u5173\u51fd\u6570\u5982\u4e0b<\/p>\n<p>#ifndef __SOCKET_TCP_SERVER_H<br \/>\n#define __SOCKET_TCP_SERVER_H<\/p>\n<p>#define SERVER_PORT 8000 \/\/ \u7aef\u53e3\u53f7<br \/>\n#define BUFF_SIZE 1024<\/p>\n<p>void vTCPServer_Task(void);<\/p>\n<p>#endif<\/p>\n<p>\u6700\u7ec8\u6548\u679c\u5982\u4e0b\u56fe<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"667\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163842-6802801265fd4.png\" width=\"1200\" \/><\/p>\n<\/p>\n<p>\u5f15\u811a\u914d\u7f6e\u56fe\u548c\u65f6\u949f\u914d\u7f6e\u56fe\u5982\u4e0b<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"535\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163842-68028012de316.png\" width=\"548\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"668\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163843-6802801308af6.png\" width=\"1200\" \/><\/p>\n<h2 style=\"background-color:transparent\">\u4e09\u3001\u4ee3\u7801\u5730\u5740&#xff08;\u6682\u65e0&#xff09;<\/h2><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.4k\u6b21\uff0c\u70b9\u8d5e9\u6b21\uff0c\u6536\u85cf23\u6b21\u3002tcp_server.c\u76f8\u5173\u51fd\u6570\u5982\u4e0b\u3002_cubemx lan8720<\/p>\n","protected":false},"author":2,"featured_media":18199,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[217],"topic":[],"class_list":["post-18216","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-stm32"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Cubemx\u5b9e\u73b0LAN8720A+LWIP+Freertos+tcp\u670d\u52a1\u5668\u521b\u5efa - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/18216.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Cubemx\u5b9e\u73b0LAN8720A+LWIP+Freertos+tcp\u670d\u52a1\u5668\u521b\u5efa - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.4k\u6b21\uff0c\u70b9\u8d5e9\u6b21\uff0c\u6536\u85cf23\u6b21\u3002tcp_server.c\u76f8\u5173\u51fd\u6570\u5982\u4e0b\u3002_cubemx lan8720\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/18216.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T16:38:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163839-6802800fc75ee.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/18216.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/18216.html\",\"name\":\"Cubemx\u5b9e\u73b0LAN8720A+LWIP+Freertos+tcp\u670d\u52a1\u5668\u521b\u5efa - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T16:38:44+00:00\",\"dateModified\":\"2025-04-18T16:38:44+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/18216.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/18216.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/18216.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Cubemx\u5b9e\u73b0LAN8720A+LWIP+Freertos+tcp\u670d\u52a1\u5668\u521b\u5efa\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Cubemx\u5b9e\u73b0LAN8720A+LWIP+Freertos+tcp\u670d\u52a1\u5668\u521b\u5efa - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/18216.html","og_locale":"zh_CN","og_type":"article","og_title":"Cubemx\u5b9e\u73b0LAN8720A+LWIP+Freertos+tcp\u670d\u52a1\u5668\u521b\u5efa - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.4k\u6b21\uff0c\u70b9\u8d5e9\u6b21\uff0c\u6536\u85cf23\u6b21\u3002tcp_server.c\u76f8\u5173\u51fd\u6570\u5982\u4e0b\u3002_cubemx lan8720","og_url":"https:\/\/www.wsisp.com\/helps\/18216.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T16:38:44+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163839-6802800fc75ee.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/18216.html","url":"https:\/\/www.wsisp.com\/helps\/18216.html","name":"Cubemx\u5b9e\u73b0LAN8720A+LWIP+Freertos+tcp\u670d\u52a1\u5668\u521b\u5efa - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T16:38:44+00:00","dateModified":"2025-04-18T16:38:44+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/18216.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/18216.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/18216.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Cubemx\u5b9e\u73b0LAN8720A+LWIP+Freertos+tcp\u670d\u52a1\u5668\u521b\u5efa"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/18216","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=18216"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/18216\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/18199"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=18216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=18216"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=18216"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=18216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}