OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 2829|回复: 2

freertos+lwip2.1.x tcp_write以ROM方式(非copy)发送后整个tcpip_thread卡死

[复制链接]

1

主题

2

帖子

0

精华

新手入门

积分
14
金钱
14
注册时间
2020-7-27
在线时间
3 小时
发表于 2023-7-3 23:37:19 | 显示全部楼层 |阅读模式
static err_t tcpecho_recv(void *arg,
                          struct tcp_pcb *tpcb,
                          struct pbuf *p,
                          err_t err)
{
    if (p != NULL)
    {
        /* 更新窗口*/
        tcp_recved(tpcb, p->tot_len);

        /* 返回接收到的数据*/
        tcp_write(tpcb, "test", 4, 0);

        memset(p->payload, 0, p->tot_len);
        pbuf_free(p);
    }
    else if (err == ERR_OK)
    {
        return tcp_close(tpcb);
    }
    return ERR_OK;
}

static err_t tcpecho_accept(void *arg,
                            struct tcp_pcb *newpcb,
                            err_t err)
{
    tcp_recv(newpcb, tcpecho_recv);
    return ERR_OK;
}

void TCP_Echo_Init(void)
{
    struct tcp_pcb *pcb = NULL;

    /* 创建一个TCP控制块  */
    pcb = tcp_new();

    /* 绑定TCP控制块 */
    tcp_bind(pcb, IP_ADDR_ANY, 8080);

    /* 进入监听状态 */
    pcb = tcp_listen(pcb);

    /* 处理连接 */
    tcp_accept(pcb, tcpecho_accept);
}
void test2()
{
    TCP_Echo_Init();
}
//使用的stm32F407ZE
/***********************************************************************/
lwipopts.h


#ifndef __LWIPOPTS_H__
#define __LWIPOPTS_H__

#include "task_config.h"
/**
SYS_LIGHTWEIGHT_PROT==1:如果您确实需要任务间保护
*/
#define SYS_LIGHTWEIGHT_PROT 1

/* NO_SYS 表示无操作系统模拟层,无操作系统为1,有操作系统设置为0
   注意这个参数设置会编译不同 */
#define NO_SYS 0


/**
* NO_SYS_NO_TIMERS==1: Drop support for sys_timeout when NO_SYS==1
* Mainly for compatibility to old versions.
*/
#define NO_SYS_NO_TIMERS 0

/* ---------- 内存选项 ---------- */
/* 内存对齐,按照 4 字节对齐  */
#define MEM_ALIGNMENT 4

/* 堆内存的大小,如果需要更大的堆内存,那么设置高一点 */
#define MEM_SIZE (8 * 1024)

/* MEMP_NUM_PBUF: 设置内存池的数量  */
#define MEMP_NUM_PBUF 32
/* MEMP_NUM_UDP_PCB: UDP协议控制块的数量. */
#define MEMP_NUM_UDP_PCB 8
/* MEMP_NUM_TCP_PCB: TCP的数量. */
#define MEMP_NUM_TCP_PCB 8
/* MEMP_NUM_TCP_PCB_LISTEN: 监听TCP的数量. */
#define MEMP_NUM_TCP_PCB_LISTEN 8
/* MEMP_NUM_TCP_SEG: 同时排队的TCP的数量段. */
#define MEMP_NUM_TCP_SEG 8
/* MEMP_NUM_SYS_TIMEOUT: 超时模拟活动的数量. */
#define MEMP_NUM_SYS_TIMEOUT 6

/* ---------- Pbuf选项 ---------- */
/* PBUF_POOL 内存池中每个内存块大小 */
#define PBUF_POOL_SIZE 16
/* PBUF_POOL_BUFSIZE: pbuf池中每个pbuf的大小. */
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS + 40 + PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN)

/* ---------- TCP选项 ---------- */
#define LWIP_TCP 1
#define TCP_TTL 255

/* 控制TCP是否应该对到达的段进行排队
   秩序。如果你的设备内存不足,定义为0. */
#define TCP_QUEUE_OOSEQ 0

/* TCP最大段大小 */
// #define TCP_MSS (1500 - 40) /* TCP_MSS = (Ethernet MTU - IP header size - TCP header size) */
#define TCP_MSS (1500 - 40) /* TCP_MSS = (Ethernet MTU - IP header size - TCP header size) */

/* TCP发送者缓冲区空间(字节). */
#define TCP_SND_BUF (4 * TCP_MSS)

/*  TCP_SND_QUEUELEN: TCP发送缓冲区空间。这必须是至少
    需要(2 * TCP_SND_BUF/TCP_MSS)才能正常工作 */

#define TCP_SND_QUEUELEN (2 * TCP_SND_BUF / TCP_MSS)

/* TCP接收窗口 */
#define TCP_WND (2 * TCP_MSS)

#define LWIP_NETIF_HOSTNAME 1

/* ---------- ICMP 选项 ---------- */
#define LWIP_ICMP 1

/* ---------- DNS 选项 ---------- */

/* ---------- HTTPD选项 ---------- */
// #define LWIP_HTTPD_SUPPORT_POST 0
// #define LWIP_HTTPD_CGI_SSI 0
// #define LWIP_HTTPD_SSI 0
// #define LWIP_HTTPD_CGI 0
#define LWIP_HTTPD_DYNAMIC_FILE_READ 1
#define HTTPD_USE_CUSTOM_FSDATA 0

/* ---------- DHCP 选项 ---------- */
/* 如果您希望DHCP配置为,请将LWIP_DHCP定义为1 */
#define LWIP_DHCP 1
#define LWIP_AUTOIP 0

/* ---------- UDP 选项 ---------- */
#define LWIP_UDP 1
#define UDP_TTL 255

/* ---------- Statistics 选项 ---------- */
#define LWIP_STATS 0
#define LWIP_PROVIDE_ERRNO 1

/* ---------- 链接回调选项 ---------- */
/* WIP_NETIF_LINK_CALLBACK==1:支持来自接口的回调函数
   每当链接改变(例如,向下链接)
*/
#define LWIP_NETIF_LINK_CALLBACK 1
#define LWIP_NETIF_STATUS_CALLBACK 0
/*
   --------------------------------------
   ---------- 帧校验和选项 ----------
   --------------------------------------
*/

#define LWIP_DEBUG LWIP_DBG_ON
#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL

#define HTTPD_DEBUG LWIP_DBG_OFF
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
#define TCP_QLEN_DEBUG LWIP_DBG_ON
#define TCPIP_DEBUG LWIP_DBG_ON
/*
The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums by hardware:
- To use this feature let the following define uncommented.
- To disable it and process by CPU comment the  the checksum.
*/
#define CHECKSUM_BY_HARDWARE

#ifdef CHECKSUM_BY_HARDWARE
/* CHECKSUM_GEN_IP==0: Generate checksums by hardware for outgoing IP packets.*/
#define CHECKSUM_GEN_IP 0
/* CHECKSUM_GEN_UDP==0: Generate checksums by hardware for outgoing UDP packets.*/
#define CHECKSUM_GEN_UDP 0
/* CHECKSUM_GEN_TCP==0: Generate checksums by hardware for outgoing TCP packets.*/
#define CHECKSUM_GEN_TCP 0
/* CHECKSUM_CHECK_IP==0: Check checksums by hardware for incoming IP packets.*/
#define CHECKSUM_CHECK_IP 0
/* CHECKSUM_CHECK_UDP==0: Check checksums by hardware for incoming UDP packets.*/
#define CHECKSUM_CHECK_UDP 0
/* CHECKSUM_CHECK_TCP==0: Check checksums by hardware for incoming TCP packets.*/
#define CHECKSUM_CHECK_TCP 0
/* CHECKSUM_CHECK_ICMP==0: Check checksums by hardware for incoming ICMP packets.*/
#define CHECKSUM_GEN_ICMP 0
#else
/* CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP packets.*/
#define CHECKSUM_GEN_IP 1
/* CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets.*/
#define CHECKSUM_GEN_UDP 1
/* CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets.*/
#define CHECKSUM_GEN_TCP 1
/* CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets.*/
#define CHECKSUM_CHECK_IP 1
/* CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets.*/
#define CHECKSUM_CHECK_UDP 1
/* CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets.*/
#define CHECKSUM_CHECK_TCP 1
/* CHECKSUM_CHECK_ICMP==1: Check checksums by hardware for incoming ICMP packets.*/
#define CHECKSUM_GEN_ICMP 1
#endif

/*
   ----------------------------------------------
   ---------- 连续层的选择 ----------
   ----------------------------------------------
*/
/**
* LWIP_NETCONN==1:启用Netconn API(需要使用api_lib.c)
*/
#define LWIP_NETCONN 1

/*
   ------------------------------------
   ---------- Socket选项 ----------
   ------------------------------------
*/
/**
* LWIP_SOCKET==1:启用Socket API(要求使用Socket .c)
*/
#define LWIP_SOCKET 1

/*
   ---------------------------------
   ---------- 操作系统选项 ----------
   ---------------------------------
*/

#define DEFAULT_UDP_RECVMBOX_SIZE 10
#define DEFAULT_TCP_RECVMBOX_SIZE 10
#define DEFAULT_ACCEPTMBOX_SIZE 10
#define DEFAULT_THREAD_STACKSIZE 1024

#define TCPIP_THREAD_NAME "lwip_task"

#ifndef LWIP_TASK_STACK_SIZE
#define TCPIP_THREAD_STACKSIZE 2048
#else
#define TCPIP_THREAD_STACKSIZE LWIP_TASK_STACK_SIZE
#endif

#ifndef LWIP_TASK_PRIORITY
#define TCPIP_THREAD_PRIO 10
#else
#define TCPIP_THREAD_PRIO LWIP_TASK_PRIORITY
#endif

#define TCPIP_MBOX_SIZE 8
#define LWIP_SO_RCVTIMEO 1

/*
   ----------------------------------------
   ---------- Lwip调试选项 ----------
   ----------------------------------------
*/
#endif /* __LWIPOPTS_H__ */





正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

1

主题

2

帖子

0

精华

新手入门

积分
14
金钱
14
注册时间
2020-7-27
在线时间
3 小时
 楼主| 发表于 2023-7-3 23:40:12 | 显示全部楼层
tcp_write最后标志位为1时就可以  此问题是在webserver上发现的因为要发送网页数据  所以最后一个COPY标志为0 也就是pbuf的数据指针直接指向ROM数组的
回复 支持 反对

使用道具 举报

1

主题

2

帖子

0

精华

新手入门

积分
14
金钱
14
注册时间
2020-7-27
在线时间
3 小时
 楼主| 发表于 2023-7-6 21:28:58 | 显示全部楼层
有人嘛....
回复 支持 反对

使用道具 举报

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

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-4-18 06:56

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

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