Can't communicate using lwIP other than with ICMP (ping)
Hello,
Sorry in advance for my English. I am also very new to embedded systems and softwares worlds.
I am currently trying the lwIP TCP/IP stack on a STM32756G-EVAL2 (STM32F756NGH) board. On one end, I have a Red Hat PC with a network interface used specifically to connect with the board through Ethernet. On the other end, the board linked to the PC with RJ-45 cable. I use STM32CubeIDE v1.5.0 as the IDE for developping my softwares, and the board is connected to the PC via ST-LINK v2.1. I am able to flash and debug my binaries without any issues.
My PC is network-configured with a static IP address (192.168.0.2), a netmask (255.255.255.0), a gateway (192.168.0.1) and a MAC address. The board is configured with a static IP address (192.168.0.10), a netmask (255.255.255.0), a gateway (192.168.0.1) and a MAC address (by default 00:80:E1:00:00:00).
To reproduce the issue as stated in the title (I will explain more specifically the issue below), here is what I do:
- First I create a new workspace, then a new STM32 project
- I choose the STM32F756NGH target, a name for the project in C, as a project type of STM32Cube. The FW package used here is the STM32Cube FW_F7 v1.16.0.
- In the ioc file, in Pinout & Configuration, I go to Connectivity, ETH and activate it as MII. There are the settings. PHY Address must be set to something different of 1 otherwise nothing works at runtime lwIP-side. I have seen some people talking about this being a bug on the STM HAL F7 Ethernet.

- In Middleware, I enable LWIP. I deactivate LWIP_DHCP in General Settings, and I enable LWIP_BROADCAST_PING and LWIP_MULTICAST_PING in Key Options (at IPv4 - ICMP Options). Other than these changes, everything else stays at default.

- Before the code is being generated, I accept the request from the automatic clock resolver, as HCLK is not set to 216 MHz. Now it is set to 216 MHz and I generate the code.
- In main.c, I copy paste my code for ping requests and UDP send process.
...
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include "lwip/pbuf.h"
#include "lwip/udp.h"
#include "lwip/tcp.h"
#include "lwip/opt.h"
#include "lwip/init.h"
#include "lwip/netif.h"
#include "lwip/timeouts.h"
#include "lwip/ip4_addr.h"
#include "netif/etharp.h"
#include "ethernetif.h"
/* USER CODE END Includes */
...
/* Private variables ---------------------------------------------------------*/
UART_HandleTypeDef huart1;
/* USER CODE BEGIN PV */
extern struct netif gnetif;
extern ip4_addr_t ipaddr;
extern ip4_addr_t netmask;
extern ip4_addr_t gw;
extern uint8_t IP_ADDRESS[4];
extern uint8_t NETMASK_ADDRESS[4];
extern uint8_t GATEWAY_ADDRESS[4];
/* USER CODE END PV */
...
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_LWIP_Init();
/* USER CODE BEGIN 2 */
char str[] = "Hello UDP World!";
err_t err = 0;
ip_addr_t dstaddr;
ip_addr_t srcaddr;
IP4_ADDR(&dstaddr, 192, 168, 0, 2);
IP4_ADDR(&srcaddr, 192, 168, 0, 10);
struct udp_pcb * pcb;
struct pbuf * pb;
pcb = udp_new();
err = udp_bind(pcb, &srcaddr, 55151);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
err = 0;
pb = pbuf_alloc(PBUF_TRANSPORT, sizeof(str), PBUF_REF);
pb->payload = str;
pb->len = pb->tot_len = sizeof(str);
err = udp_bind(pcb, &srcaddr, 55151);
err = udp_connect(pcb, &dstaddr, 55151);
err = udp_sendto(pcb, pb, &dstaddr, 55151);
udp_disconnect(pcb);
udp_remove(pcb);
pbuf_free(pb);
HAL_Delay(1000);
MX_LWIP_Process();
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
...- Now I can build my program, and debug it. I usually debug it via STLINK (OpenOCD). Here is an output of a ping command from the PC:

- If I want to listen to UDP packets coming from the board (192.168.0.10) to the PC (192.168.0.2), I use netcat but it does not seem able to receive/listen to these UDP packets (it is blank after the command line), using the next command:
nc -ul 192.168.0.2 55151- Nonetheless, with the program running on the board, I refresh an ifconfig command on my PC terminal and I can see that I indeed receive UDP packets each second approximately (as written in my program). These are not ICMP packets as I do not run the ping command for this purpose.
Thus, I do not really understand why it is not working. I tried to change a lot of settings of the ETH and LWIP in the ioc, as well as doing some little debugging with breakpoints and running through each functions. No errors returned also. I tried with Netconn API and FreeRTOS, same problem: ping requests and responses work but not UDP or TCP. I did not tried sockets but i thought that if RAW API and Netconn API didn't worked, I will be more successful with socket API.
Do you have any ideas or solutions for this kind of issue?
