硬汉嵌入式论坛

 找回密码
 立即注册
查看: 116|回复: 4
收起左侧

[技术讨论] lwip接口netconn_write问题

[复制链接]

5

主题

7

回帖

22

积分

新手上路

积分
22
发表于 2025-8-1 11:07:46 | 显示全部楼层 |阅读模式
我这里采用cubemx生成的lwip工程
在调用netconn_write的时候, 第二个参数字符串数组如果传入的是static const char类型, 就会造成该函数阻塞, 暂时没定位到阻塞点
但是如果改为char类型, 就不会造成阻塞
代码如下, 希望大佬指教

[C] 纯文本查看 复制代码
char http_html_hdr[] =
    "HTTP/1.1 200 OK\r\nContent-type: text/html\r\n\r\n";
char http_index_html[] =
"<html><head><title>Congrats!</title></head>\
<body><h1 align=\"center\">Hello World!</h1>\
<h2 align=\"center\">Welcome to Fire lwIP HTTP Server!</h1>\
<p align=\"center\">This is a small test page, served by httpserver-netconn.</p>\
<p align=\"center\"><a href=\"http://www.firebbs.cn/forum.php/\">\
<font size=\"6\"> 野火电子论坛 </font> </a></p>\
<a href=\"http://www.firebbs.cn/forum.php/\">\
<p align=\"center\"><img src=\"http://www.firebbs.cn/data/attachment/portal/\
201806/05/163015rhz7mbgbt0zfujzh.jpg\" /></a>\
</body></html>";

uint8_t send_buf[]= "This is a TCP Client test...\n";
/** Serve one HTTP connection accepted in the http thread */
static void
http_server_netconn_serve(struct netconn *conn)
{
    struct netbuf *inbuf;
    char *buf;
    u16_t buflen;
    err_t err;

    /* 读取数据 */
    err = netconn_recv(conn, &inbuf);

    if (err == ERR_OK)
    {
        netbuf_data(inbuf, (void**)&buf, &buflen);

        /* 判断是不是HTTP的GET命令*/
        if (buflen>=5 &&
                buf[0]=='G' &&
                buf[1]=='E' &&
                buf[2]=='T' &&
                buf[3]==' ' &&
                buf[4]=='/' )
        {

						// netconn_write(conn,send_buf,sizeof(send_buf),0);
            /* 发送数据头 */
            netconn_write(conn, http_html_hdr,
			 					sizeof(http_html_hdr)-1, NETCONN_NOCOPY);
//            /* 发送网页数据 */
           netconn_write(conn, http_index_html,
			 				sizeof(http_index_html)-1, NETCONN_NOCOPY);
        }
    }
    netconn_close(conn); /* 关闭连接 */

    /* 释放inbuf */
    netbuf_delete(inbuf);
}

回复

使用道具 举报

5

主题

7

回帖

22

积分

新手上路

积分
22
 楼主| 发表于 2025-8-1 11:27:57 | 显示全部楼层
目前测试static char和NOCPY参数组合不会阻塞,static const char 和COPY参数组合也不会阻塞
应该是这个const关键字导致的问题
但是我看netconn_write接口的第二个参数也是const

#define netconn_write(conn, dataptr, size, apiflags) \
          netconn_write_partly(conn, dataptr, size, apiflags, NULL)
netconn_write_partly(struct netconn *conn, const void *dataptr, size_t size,
                     u8_t apiflags, size_t *bytes_written)
回复

使用道具 举报

5

主题

7

回帖

22

积分

新手上路

积分
22
 楼主| 发表于 2025-8-1 14:51:42 | 显示全部楼层
解决了, low_level_output里DMA的缓冲区直接指向了这里的const的数组ROM区,而DMA缓冲区不能指向只读区域,所以要用个RAM缓存, 此问题终结
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
117512
QQ
发表于 2025-8-1 14:53:39 | 显示全部楼层
StarAir 发表于 2025-8-1 11:27
目前测试static char和NOCPY参数组合不会阻塞,static const char 和COPY参数组合也不会阻塞
应该是这个co ...

const定义的数组是放在了Flash。

如果这样的话,是Flash上的数据无法传输,而RAM上的数据可以传输输出,是这个意思吧,按说应该没有影响的。
回复

使用道具 举报

5

主题

7

回帖

22

积分

新手上路

积分
22
 楼主| 发表于 2025-8-1 15:31:48 | 显示全部楼层
eric2013 发表于 2025-8-1 14:53
const定义的数组是放在了Flash。

如果这样的话,是Flash上的数据无法传输,而RAM上的数据可以传输输出 ...

感谢硬汉哥的回复,cubemx生成的的底层实现有点问题, DMA的缓冲区直接指向了这个数组, 所以const就会导致阻塞
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2025-8-11 21:03 , Processed in 0.042918 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表