2023-12-21 09:27 PM
I'm trying to view the LwIP debug log to check Ethernet operation on the nucleo-f429zi board. I tested the operation after setting the code as shown below, but the LwIP debug log is not displayed. The code below is for printing debug logs.
Can you tell me the correct settings for LwIP debug log output?
/* Private define ------------------------------------------------------------*/
/* 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;
}
/* USER CODE END PD */
Solved! Go to Solution.
2023-12-25 11:05 PM
The main file I used was C++, so I changed the log output method as shown below and it worked well.
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#ifdef __cplusplus
extern "C" int _write(int32_t file, uint8_t *ptr, int32_t len) {
#else
int _write(int32_t file, uint8_t *ptr, int32_t len) {
#endif
for(int32_t i = 0; i < len; ++i) { ITM_SendChar(*ptr++); }
return len;
}
/* USER CODE END PD */
2023-12-23 05:08 PM - edited 2023-12-23 05:11 PM
> The code below is for printing debug logs.
Nope, this code is a helper to implement printf and its friends.
If you call printf or puts in main() - will it work? Is LwIP in your project configured to use printf for its debug prints?
2023-12-25 12:42 PM
If you trace into the source code of LWIP you can see what the problem is by evaluating the source code, one example:
In my case:
so UDP_DEBUG was on, that seems ok.
But if I check LWIP_DEBUGF i see:
The grayed code is not active, analysis of the code learns that LWIP_DEBUG is not defined.
In most cases I define it in LWIOPTS.H:
And then I get in my SWV ITM console window:
But in my main.c I need to add:
As you are using USART3, this code will need an alternative.
2023-12-25 11:04 PM
Johi, thank you for your explanation. By adding some modifications, the output of LwIP's debug log was successful.
2023-12-25 11:05 PM
The main file I used was C++, so I changed the log output method as shown below and it worked well.
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#ifdef __cplusplus
extern "C" int _write(int32_t file, uint8_t *ptr, int32_t len) {
#else
int _write(int32_t file, uint8_t *ptr, int32_t len) {
#endif
for(int32_t i = 0; i < len; ++i) { ITM_SendChar(*ptr++); }
return len;
}
/* USER CODE END PD */