[LWIP] 如何启LWIP用调试信息输出

主要在两个文件内配置opt.h和lwipopts.h。

第一步 启动调试项

cpp 复制代码
//LWIP调试选项
#define LWIP_DEBUG        LWIP_DBG_ON	 //LWIP_DBG_OFF关闭DEBUG选项 LWIP_DBG_ON

第二步 设置调试等级和类型

opt.h文件中

cpp 复制代码
 * LWIP_DBG_MIN_LEVEL: After masking, the value of the debug is
 * compared against this value. If it is smaller, then debugging
 * messages are written.
 * @see debugging_levels
 */
#if !defined LWIP_DBG_MIN_LEVEL || defined __DOXYGEN__
#define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_ALL
#endif

/**
 * LWIP_DBG_TYPES_ON: A mask that can be used to globally enable/disable
 * debug messages of certain types.
 * @see debugging_levels
 */
#if !defined LWIP_DBG_TYPES_ON || defined __DOXYGEN__
#define LWIP_DBG_TYPES_ON               LWIP_DBG_ON
#endif

LWIP_DBG_MIN_LEVEL 调试信息等级

LWIP_DBG_TYPES_ON 调试类型

调试等级LWIP_DBG_MIN_LEVEL有以下可定义

cpp 复制代码
 #define LWIP_DBG_LEVEL_ALL     0x00
/** Debug level: Warnings. bad checksums, dropped packets, ... */
#define LWIP_DBG_LEVEL_WARNING 0x01
/** Debug level: Serious. memory allocation failures, ... */
#define LWIP_DBG_LEVEL_SERIOUS 0x02
/** Debug level: Severe */
#define LWIP_DBG_LEVEL_SEVERE  0x03    

调试类型在 opt.h中定义开启比如将NETIF_DEBUG调试信息开启

cpp 复制代码
#if !defined NETIF_DEBUG || defined __DOXYGEN__
#define NETIF_DEBUG                     LWIP_DBG_ON
#endif      

第三步 定义输出信息函数

实现调试信息输出函数定义,一般是实现printf函数。

cpp 复制代码
#define LWIP_PLATFORM_DIAG(x)         do { printf x; } while(0)  // 需要实现printf

调试建议

在调试等级设置上,建议设置LWIP_DBG_LEVEL_WARNING及以上等级,如果设置ALL可能会有太多的输出信息难以查找问题。

关闭调试

只需将LWIP_DEBUG选项设置为关闭即可

cpp 复制代码
//LWIP调试选项
#define LWIP_DEBUG        LWIP_DBG_OFF  //LWIP_DBG_OFF关闭DEBUG选项 LWIP_DBG_ON
相关推荐
芯岭技术郦4 分钟前
MS32C001‑C:极致成本 32 位 MCU
c语言·开发语言·单片机
fffzd4 分钟前
STM32:定时器从模式
stm32·单片机·嵌入式·从模式·复位模式·门模式·触发模式
崇山峻岭之间8 分钟前
单片机舵机实验
单片机·嵌入式硬件
移远通信1 小时前
显示器-调试
单片机·嵌入式硬件·计算机外设
Szime9 小时前
全球首创10位40GSPS超宽带ADC选型参考:国产超高速ADC深智微科技选型支持
科技·单片机·嵌入式硬件·fpga开发
(Morgan)10 小时前
51单片机期末复习知识点总结
stm32·单片机·嵌入式硬件
榴莲llll11 小时前
应用于计时器/微波炉等产品的高亮LED数显驱动VK16K33C 数码管屏显驱动芯片
单片机
华一精品Adreamer12 小时前
T606 vs 骁龙662/RK3566:主流安卓+4G定制平板芯片横向测评指南
单片机
Zyed13 小时前
[STM32]Day9-Part1USART+串口接收+串口收发
stm32·单片机·嵌入式硬件
小慧102415 小时前
手动建立工程模板
stm32·单片机