Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
LWIP
lwip用长时间运行或者大数据收发的时候会卡死
发布于 2022-11-10 17:48:06 浏览:1804
订阅该版
lwip用iperf测试速率的时候会卡死,无法接收发送数据了,也不能识别网线插入了. 我使用了lwip好几个版本了,都是一样的结果。 主控芯片是用AT32F407RG 网络芯片IP101GR。 我DEBUG发现程序会卡在接收的pbuf_alloc这个接口上,不知道是什么原因造成的。 看看哪位大神能帮忙指导一下 以下是以太网驱动的收发接口 ```c rt_err_t rt_at32_emac_tx(rt_device_t dev, struct pbuf *p) { // struct pbuf *q; // rt_uint32_t offset; if(p == RT_NULL){ LOG_E("rt_at32_emac_tx:p == RT_NULL"); return ERR_ARG; } while ((dma_tx_desc_to_set->status & EMAC_DMATXDESC_OWN) != RESET) { rt_err_t result; rt_uint32_t level; level = rt_hw_interrupt_disable(); tx_is_waiting = RT_TRUE; rt_hw_interrupt_enable(level); /* it's own bit set, wait it */ result = rt_sem_take(&tx_wait, RT_WAITING_FOREVER); if (result == RT_EOK) break; if (result == -RT_ERROR) return -RT_ERROR; } if(p->tot_len > EMAC_MAX_PACKET_LENGTH){ LOG_E("rt_at32_emac_tx:p->tot_len > EMAC_MAX_PACKET_LENGTH"); return ERR_ARG; } pbuf_copy_partial(p, (uint8_t*)(dma_tx_desc_to_set->buf1addr), EMAC_MAX_PACKET_LENGTH, 0); // offset = 0; // for (q = p; q != NULL; q = q->next) // { // uint8_t *buffer; // // /* copy the frame to be sent into memory pointed by the current ethernet dma tx descriptor */ // buffer = (uint8_t*)((dma_tx_desc_to_set->buf1addr) + offset); // SMEMCPY(buffer, q->payload, q->len); // offset += q->len; // } #ifdef EMAC_TX_DUMP dump_hex(p->payload, p->tot_len); #endif /* prepare transmit descriptors to give to dma */ LOG_D("transmit frame length :%d", p->tot_len); /* setting the frame length: bits[12:0] */ dma_tx_desc_to_set->controlsize = (p->tot_len & EMAC_DMATXDESC_TBS1); /* Setting the last segment and first segment bits (in this case a frame is transmitted in one descriptor) */ dma_tx_desc_to_set->status |= EMAC_DMATXDESC_LS | EMAC_DMATXDESC_FS; /* enable tx completion interrupt */ dma_tx_desc_to_set->status |= EMAC_DMATXDESC_IC; /* set own bit of the tx descriptor status: gives the buffer back to ethernet dma */ dma_tx_desc_to_set->status |= EMAC_DMATXDESC_OWN; /* When Tx Buffer unavailable flag is set: clear it and resume transmission */ if(emac_dma_flag_get(EMAC_DMA_TBU_FLAG) != RESET) { emac_dma_flag_clear(EMAC_DMA_TBU_FLAG); emac_dma_poll_demand_set(EMAC_DMA_TRANSMIT, 0); } /* selects the next dma tx descriptor list for next buffer to send */ dma_tx_desc_to_set = (emac_dma_desc_type*) (dma_tx_desc_to_set->buf2nextdescaddr); return ERR_OK; } /** * @brief receive data */ struct pbuf *rt_at32_emac_rx(rt_device_t dev) { struct pbuf *p = NULL; // struct pbuf *q = NULL; // rt_uint32_t offset = 0; uint16_t len = 0; // uint8_t *buffer; /* get received frame */ len = emac_received_packet_size_get(); if(len > 0) { LOG_D("receive frame len : %d", len); /* we allocate a pbuf chain of pbufs from the lwip buffer pool */ p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL); if(p != NULL) { pbuf_take(p, (uint8_t *)dma_rx_desc_to_get->buf1addr, len); // for (q = p; q != RT_NULL; q= q->next) // { // /* get rx buffer */ // buffer = (uint8_t *)(dma_rx_desc_to_get->buf1addr); //#ifdef EMAC_RX_DUMP // dump_hex(buffer, len); //#endif // /* copy the received frame into buffer from memory pointed by the current ethernet dma rx descriptor */ // SMEMCPY(q->payload, (buffer + offset), q->len); // offset += q->len; // } } } else { return p; } /* release descriptors to dma */ dma_rx_desc_to_get->status |= EMAC_DMARXDESC_OWN; /* when rx buffer unavailable flag is set: clear it and resume reception */ if(emac_dma_flag_get(EMAC_DMA_RBU_FLAG) != RESET) { /* clear rbu ethernet dma flag */ emac_dma_flag_clear(EMAC_DMA_RBU_FLAG); /* resume dma reception */ emac_dma_poll_demand_set(EMAC_DMA_RECEIVE, 0); } /* update the ethernet dma global rx descriptor with next rx decriptor */ /* chained mode */ if((dma_rx_desc_to_get->controlsize & EMAC_DMARXDESC_RCH) != RESET) { /* selects the next dma rx descriptor list for next buffer to read */ dma_rx_desc_to_get = (emac_dma_desc_type*) (dma_rx_desc_to_get->buf2nextdescaddr); } /* ring mode */ else { if((dma_rx_desc_to_get->controlsize & EMAC_DMARXDESC_RER) != RESET) { /* selects the first dma rx descriptor for next buffer to read: last rx descriptor was used */ dma_rx_desc_to_get = (emac_dma_desc_type*) (EMAC_DMA->rdladdr); } else { /* selects the next dma rx descriptor list for next buffer to read */ dma_rx_desc_to_get = (emac_dma_desc_type*) ((uint32_t)dma_rx_desc_to_get + 0x10 + ((EMAC_DMA->bm & 0x0000007C) >> 2)); } } return p; } ``` ```c rt_err_t rt_at32_emac_tx(rt_device_t dev, struct pbuf *p) { // struct pbuf *q; // rt_uint32_t offset; if(p == RT_NULL){ LOG_E("rt_at32_emac_tx:p == RT_NULL"); return ERR_ARG; } while ((dma_tx_desc_to_set->status & EMAC_DMATXDESC_OWN) != RESET) { rt_err_t result; rt_uint32_t level; level = rt_hw_interrupt_disable(); tx_is_waiting = RT_TRUE; rt_hw_interrupt_enable(level); /* it's own bit set, wait it */ result = rt_sem_take(&tx_wait, RT_WAITING_FOREVER); if (result == RT_EOK) break; if (result == -RT_ERROR) return -RT_ERROR; } if(p->tot_len > EMAC_MAX_PACKET_LENGTH){ LOG_E("rt_at32_emac_tx:p->tot_len > EMAC_MAX_PACKET_LENGTH"); return ERR_ARG; } pbuf_copy_partial(p, (uint8_t*)(dma_tx_desc_to_set->buf1addr), EMAC_MAX_PACKET_LENGTH, 0); // offset = 0; // for (q = p; q != NULL; q = q->next) // { // uint8_t *buffer; // // /* copy the frame to be sent into memory pointed by the current ethernet dma tx descriptor */ // buffer = (uint8_t*)((dma_tx_desc_to_set->buf1addr) + offset); // SMEMCPY(buffer, q->payload, q->len); // offset += q->len; // } #ifdef EMAC_TX_DUMP dump_hex(p->payload, p->tot_len); #endif /* prepare transmit descriptors to give to dma */ LOG_D("transmit frame length :%d", p->tot_len); /* setting the frame length: bits[12:0] */ dma_tx_desc_to_set->controlsize = (p->tot_len & EMAC_DMATXDESC_TBS1); /* Setting the last segment and first segment bits (in this case a frame is transmitted in one descriptor) */ dma_tx_desc_to_set->status |= EMAC_DMATXDESC_LS | EMAC_DMATXDESC_FS; /* enable tx completion interrupt */ dma_tx_desc_to_set->status |= EMAC_DMATXDESC_IC; /* set own bit of the tx descriptor status: gives the buffer back to ethernet dma */ dma_tx_desc_to_set->status |= EMAC_DMATXDESC_OWN; /* When Tx Buffer unavailable flag is set: clear it and resume transmission */ if(emac_dma_flag_get(EMAC_DMA_TBU_FLAG) != RESET) { emac_dma_flag_clear(EMAC_DMA_TBU_FLAG); emac_dma_poll_demand_set(EMAC_DMA_TRANSMIT, 0); } /* selects the next dma tx descriptor list for next buffer to send */ dma_tx_desc_to_set = (emac_dma_desc_type*) (dma_tx_desc_to_set->buf2nextdescaddr); return ERR_OK; } /** * @brief receive data */ struct pbuf *rt_at32_emac_rx(rt_device_t dev) { struct pbuf *p = NULL; // struct pbuf *q = NULL; // rt_uint32_t offset = 0; uint16_t len = 0; // uint8_t *buffer; /* get received frame */ len = emac_received_packet_size_get(); if(len > 0) { LOG_D("receive frame len : %d", len); /* we allocate a pbuf chain of pbufs from the lwip buffer pool */ p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL); if(p != NULL) { pbuf_take(p, (uint8_t *)dma_rx_desc_to_get->buf1addr, len); // for (q = p; q != RT_NULL; q= q->next) // { // /* get rx buffer */ // buffer = (uint8_t *)(dma_rx_desc_to_get->buf1addr); //#ifdef EMAC_RX_DUMP // dump_hex(buffer, len); //#endif // /* copy the received frame into buffer from memory pointed by the current ethernet dma rx descriptor */ // SMEMCPY(q->payload, (buffer + offset), q->len); // offset += q->len; // } } } else { return p; } /* release descriptors to dma */ dma_rx_desc_to_get->status |= EMAC_DMARXDESC_OWN; /* when rx buffer unavailable flag is set: clear it and resume reception */ if(emac_dma_flag_get(EMAC_DMA_RBU_FLAG) != RESET) { /* clear rbu ethernet dma flag */ emac_dma_flag_clear(EMAC_DMA_RBU_FLAG); /* resume dma reception */ emac_dma_poll_demand_set(EMAC_DMA_RECEIVE, 0); } /* update the ethernet dma global rx descriptor with next rx decriptor */ /* chained mode */ if((dma_rx_desc_to_get->controlsize & EMAC_DMARXDESC_RCH) != RESET) { /* selects the next dma rx descriptor list for next buffer to read */ dma_rx_desc_to_get = (emac_dma_desc_type*) (dma_rx_desc_to_get->buf2nextdescaddr); } /* ring mode */ else { if((dma_rx_desc_to_get->controlsize & EMAC_DMARXDESC_RER) != RESET) { /* selects the first dma rx descriptor for next buffer to read: last rx descriptor was used */ dma_rx_desc_to_get = (emac_dma_desc_type*) (EMAC_DMA->rdladdr); } else { /* selects the next dma rx descriptor list for next buffer to read */ dma_rx_desc_to_get = (emac_dma_desc_type*) ((uint32_t)dma_rx_desc_to_get + 0x10 + ((EMAC_DMA->bm & 0x0000007C) >> 2)); } } return p; } ```
查看更多
2
个回答
默认排序
按发布时间排序
张世争
2022-11-12
学以致用
内存不够了吧,卡住后能输入 shell 命令吗?
hijxyz
2022-12-06
这家伙很懒,什么也没写!
是网络模块的DMA描述符不可用,暂停发送了。重新恢复一下接收。导致这个原因是接收缓冲区不够,加大接收缓冲区即可
撰写答案
登录
注册新账号
关注者
0
被浏览
1.8k
关于作者
hijxyz
这家伙很懒,什么也没写!
提问
14
回答
15
被采纳
2
关注TA
发私信
相关问题
1
RT-THREAD在STM32H747平台上移植lwip
2
{lwip}使能RT_LWIP_DHCP时可以获取到ip
3
stm32f103 LWIP 2.0.2 TCP收发问题
4
lwip2.1不重启修改IP
5
关于网络协议栈的测试
6
可否将LWIP升级到2.1.2 和 2.0.3?
7
socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
8
tcpclient 插拔网线问题?
9
两个tcpclient同时通讯可以吗?
10
SO_BINDTODEVICE 未定义该如何解决
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
简单两步配置RTT源码阅读环境 vsc+clangd
2
恩智浦[FRDM-MCXN947]初探 之 ADC与DAC
3
LVGL使用字库IC芯片显示中文
4
基于STM32H750和Rt-Thread的CANFD通信实现的记录(一)
5
freemodbus主机在freertos的适配,参考rtthread例程
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
I2C_IIC
WIZnet_W5500
UART
ota在线升级
PWM
cubemx
freemodbus
flash
packages_软件包
BSP
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
中断
Debug
编译报错
SFUD
msh
rt_mq_消息队列_msg_queue
keil_MDK
ulog
MicroPython
C++_cpp
本月问答贡献
出出啊
1517
个答案
342
次被采纳
小小李sunny
1443
个答案
289
次被采纳
张世争
805
个答案
174
次被采纳
crystal266
547
个答案
161
次被采纳
whj467467222
1222
个答案
148
次被采纳
本月文章贡献
出出啊
1
篇文章
4
次点赞
小小李sunny
1
篇文章
1
次点赞
张世争
1
篇文章
1
次点赞
crystal266
2
篇文章
2
次点赞
whj467467222
2
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部