본문 바로가기
DSP, MCU/STM32 (ARM Cortex-M)

STM32 ] lwIP 통계와 디버그 기능 활성화하기 (LWIP_STATS, LWIP_DEBUG)

by eteo 2022. 11. 11.

 

lwipopts.h 파일 수정 및 추가

/*----- Value in opt.h for LWIP_STATS: 1 -----*/
#define LWIP_STATS 1
//...
/* USER CODE BEGIN 1 */
#define LWIP_DEBUG 1
#define NETIF_DEBUG LWIP_DBG_ON
#define DHCP_DEBUG LWIP_DBG_ON
#define UDP_DEBUG  LWIP_DBG_ON
#define MEMP_DEBUG LWIP_DBG_ON
#define MEM_DEBUG LWIP_DBG_ON
#define ICMP_DEBUG LWIP_DBG_ON
/* USER CODE END 1 */

 

 

arch.h 파일에 다음과 같이 정의되어 있기 때문에 printf를 redirection 해주면 된다. 혹은 다른 입출력함수를 사용할 수 있다.

/** Platform specific diagnostic output.\n
 * Note the default implementation pulls in printf, which may
 * in turn pull in a lot of standard libary code. In resource-constrained 
 * systems, this should be defined to something less resource-consuming.
 */
#ifndef LWIP_PLATFORM_DIAG
#define LWIP_PLATFORM_DIAG(x) do {printf x;} while(0)
#include <stdio.h>
#include <stdlib.h>
#endif

 

uart를 사용하고 printf를 재정의

/* USER CODE BEGIN PD */
#ifdef __GNUC__
  /* With GCC, small printf (option LD Linker->Libraries->Small printf
     set to 'Yes') calls __io_putchar() */
  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
PUTCHAR_PROTOTYPE
{
  /* Place your implementation of fputc here */
  /* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */
  HAL_UART_Transmit(&huart3, (uint8_t *)&ch, 1, 0xFFFF);

  return ch;
}
//...
int main(void)
{
  MX_USART3_UART_Init();
  //...

 

 

Expressions 에서 lwip_stats확인

 

 

다음과 같이 로그를 볼 수 있다. 오류가 발생시 오류메시지가 뜬다.