1、问题现象描述:
在配置STM32 LWIP时,ping不通网络,但是并不影响客户端访问STM32配置的web服务器;就是除了无法PING通,网络一切都正常。
2、解决方法:
(1)启用 ICMP 协议
LWIP 默认可能未启用 ICMP 协议(ping 使用的是 ICMP 协议)。需要检查并确保 ICMP 功能已启用。在 lwipopts.h 文件中,确保以下配置已启用:
#define LWIP_ICMP 1 // 启用 ICMP 协议
#define LWIP_BROADCAST_PING 1 // 允许响应广播 Ping
#define LWIP_MULTICAST_PING 1 // 允许响应多播 Ping
(2)硬件校验和卸载
某些以太网控制器(如 STM32 的以太网外设)支持硬件校验和卸载功能,即在硬件层面自动计算和验证校验和。如果启用了硬件校验和卸载,同时又在软件层面启用了校验和生成和检查,可能会导致冲突。在软件中禁用校验和生成和检查:
#define CHECKSUM_GEN_IP 0
#define CHECKSUM_GEN_UDP 0
#define CHECKSUM_GEN_TCP 0
#define CHECKSUM_GEN_ICMP 0
#define CHECKSUM_CHECK_IP 0
#define CHECKSUM_CHECK_UDP 0
#define CHECKSUM_CHECK_TCP 0
#define CHECKSUM_CHECK_ICMP 0
(3)扩大Freertos栈分配的内存
扩大任务函数的栈内存,将原来的stack_size = 256 * 4 改为stack_size = 512* 4。
/* USER CODE END Variables */
/* Definitions for defaultTask */
osThreadId_t defaultTaskHandle;
const osThreadAttr_t defaultTask_attributes = {
.name = "defaultTask",
.priority = (osPriority_t) osPriorityHigh1,
.stack_size = 512 * 4
};
/* Definitions for name_APP1 */
osThreadId_t name_APP1Handle;
const osThreadAttr_t name_APP1_attributes = {
.name = "name_APP1",
.priority = (osPriority_t) osPriorityHigh,
.stack_size = 256 * 4
};
void StartDefaultTask(void *argument)
{
/* init code for LWIP */
MX_LWIP_Init();
/* USER CODE BEGIN StartDefaultTask */
osDelay(1000*100);
connect_to_all_server();
for(;;)
{
osDelay(500);
}
/* USER CODE END StartDefaultTask */
}
如果还不行,那就在FreeRTOSConfig.h下将堆内存(configTOTAL_HEAP_SIZE)扩大:
#define configUSE_PREEMPTION 1
#define configSUPPORT_STATIC_ALLOCATION 1
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ( SystemCoreClock )
#define configTICK_RATE_HZ ((TickType_t)100000)
#define configMAX_PRIORITIES ( 56 )
#define configMINIMAL_STACK_SIZE ((uint16_t)128)
#define configTOTAL_HEAP_SIZE ((size_t)25600)
#define configMAX_TASK_NAME_LEN ( 16 )
#define configUSE_TRACE_FACILITY 1
#define configUSE_STATS_FORMATTING_FUNCTIONS 1
#define configUSE_16_BIT_TICKS 0
#define configUSE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 8
#define configCHECK_FOR_STACK_OVERFLOW 2
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
————————————————
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qq_42737210/article/details/145189682
|