Skip to main content
ConductedForce
Associate II
May 8, 2019 7:16 AM UTC
Solved

UDP Echo server not working

Working on a basic UDP Echo server with STM32F429ZI. I had CubeMX add lwIP into the project, but its doesn't seem to receive any packets when I send them. DHCP seems to work as I can see an IP getting assigned on the router.

void udp_echoserver_receive_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, u16_t port)
{
 
 /* Connect to the remote client */
 udp_connect(upcb, addr, UDP_CLIENT_PORT);
 
 /* Tell the client that we have accepted it */
 udp_send(upcb, p);
 
 /* free the UDP connection, so we can accept new clients */
 udp_disconnect(upcb);
 
 /* Free the p buffer */
 pbuf_free(p);
 
}
 
/**
 * @brief Initialize the server application.
 * @param None
 * @retval None
 */
void udp_echoserver_init(void)
{
 struct udp_pcb *upcb;
 err_t err;
 
 /* Create a new UDP control block */
 upcb = udp_new();
 
 if (upcb)
 {
 /* Bind the upcb to the UDP_PORT port */
 /* Using IP_ADDR_ANY allow the upcb to be used by any local interface */
 err = udp_bind(upcb, IP_ADDR_ANY, UDP_SERVER_PORT);
 
 if(err == ERR_OK)
 {
 /* Set a receive callback for the upcb */
 udp_recv(upcb, udp_echoserver_receive_callback, NULL);
 }
 }
}

These are my init and callback functions. In main I call ethernetif_input(&gnetif);

I'd like to store the packets to be read in main using the RxCmpltCallback, but I'm not sure what to do. Also despite ICMP being enabled, no pings are recieved when I use a ping program.

This topic has been closed for replies.
ConductedForce
ConductedForceBest answer
Associate II
May 10, 2019 3:56 AM UTC

Turns out that the setup for the Nucleo and non-Nucleo chips are different for the PHY address. Changed PHY address to 0 and everything started working. (For anyone wondering, PHY address is declared in stm32f4xx_hal_conf.h, or use CubeMX if you already are.)

2 replies

ConductedForce
Associate II
May 8, 2019 10:47 PM UTC

I switched to using MX_LWIP_Process(); instead of ethernetif_input(&gnetif);

I also had a suspicion that I was not actually having a full connection to the interface, as if the router was assigning an IP whether it was requested or not. I commented out MX_LWIP_Init() and my udp_echoserver_init(). An IP was still assigned, so it must be something with the interface initialization. That's my thought at the moment.

ConductedForce
ConductedForceAuthorBest answer
Associate II
May 10, 2019 3:56 AM UTC

Turns out that the setup for the Nucleo and non-Nucleo chips are different for the PHY address. Changed PHY address to 0 and everything started working. (For anyone wondering, PHY address is declared in stm32f4xx_hal_conf.h, or use CubeMX if you already are.)