cancel
Showing results for 
Search instead for 
Did you mean: 

Can't Send UDP Packets to Specific IP Addresses on H563

amitrahman1026
Associate

Body:

Hello STM32 Community,

I'm encountering an issue with an Ethernet application I'm developing on an STM32 platform, where I can't seem to send UDP packets to a specific IP address within my local network. Broadcast UDP packets are sent and received successfully, but directed packets do not reach their destination.

Here's a summary of the setup and issue with github gists going into deeper details below:

  • Deelopment Board: H563ZI
  • MAC Address: Manually set to 0:80:e1:0:0:0
  • Target IP: 192.168.1.99 (my notebook)
  • Broadcast IP: 192.168.1.255 (Broadcasts work fine and are received by nc -lu PORT & wireshark)
  • LwIP version: 2.1.3
  • Router: Linksys e2500 v4 router, with DHCP range 192.168.1.100 to 192.168.1.149
  • Firewall: Disabled on both router and my notebook.

Wireshark captures the broadcast packets, but not the packets directed to 192.168.1.141. However, when I use the broadcast address 192.168.1.255, the messages are received and visible in Wireshark and on the nc -lu 6543 listener on my notebook.

Attempts to ping the development board's IP (192.168.1.150) result in timeouts,

Despite the board's IP being in the destination computer's ARP table. I've also confirmed that firewalls are disabled on everywhere on the router and destination computer.

Unfortunately the router's current network management portal does not let me see list of devices connected.

The relevant code files are attached and briefly noted here. Started by initializing the network and send UDP messages, pretty standard stuff, follows the examples closely:

 
void udp_network_init(void)

{
// set device's ip address, netmask and gateway
ipaddr_aton("192.168.1.255", &broadcast_ip);
ipaddr_aton("192.168.1.150", &device_ip);
ipaddr_aton("192.168.1.99", &computer_ip);
ipaddr_aton("192.168.1.1", &router_ip);

ipaddr_aton("255.255.255.0", &netmask);
ipaddr_aton("192.168.1.1", &gateway);


// initialize the ethernet interface
eth_init();     // inits device mac adrress, starts eth clock, gpio, interrupts & checksums for ethernet packet
eth_mac_init(); // starts the ETH DMA Rx & Tx
lwip_init();    // starts network stack



// set up the network interface
if (!netif_add(&pnetif, &device_ip, &netmask, &gateway, NULL, ethernetif_init, ethernet_input)) {
ERROR("Failed to add network if");
}

netif_set_default(&pnetif);

netif_set_up(&pnetif);

udp_pcb = udp_new();

if (udp_pcb != NULL) {
err_t err = udp_bind(udp_pcb, &device_ip, UDP_PORT_SRC);
if (err != ERR_OK) {
INFO("Can't bind to device ip/ src port");
}
err = udp_connect(udp_pcb, &computer_ip, UDP_PORT_DST);
if (err != ERR_OK) {
INFO("Can't connect to computer ip");
}
udp_recv(udp_pcb, udp_recv_callback, NULL);
}


task_custom_size(ethernet_thread,
               "ethernet_thread",
                 BYTES_TO_STACK_SIZE(2048),
                 NULL, PRIORITY_MINIMUM
                 );

INFO("Ready to receive udp packets");
// udp_send_message("targetted ip test", &computer_ip, UDP_PORT_DST);
// udp_send_message("broadcast ip test", &broadcast_ip, UDP_PORT_DST);

}

void udp_send_message(const char* message, const ip_addr_t* target_ip, u16_t target_port)
{
err_t wr_err   = ERR_OK;
struct pbuf* p = pbuf_alloc(PBUF_TRANSPORT, strlen(message), PBUF_RAM);

if (p != NULL) {

memcpy(p->payload, message, strlen(message));
wr_err = udp_sendto_if(udp_pcb, p, target_ip, target_port, &pnetif);
if (wr_err) {
INFO("UDP_SENDTO_IF error %d", (int)wr_err);
}
pbuf_free(p);
}
}


static void ethernet_thread(void* v)
{
(void)v;
for (;;) {
ethernet_loop();
msleep(ETHERNET_LOOP_TIME);
}
}

void ethernet_loop(void)
{
ethernetif_input(&pnetif);
sys_check_timeouts();
}
 
I have tried a few problems/solutions that sounded applicable to my set up from this compiled list. However I have not had much success.

Here is a detailed compilations of things I have tried so far and I'm afraid I'm not getting much leads on this. It includes debug output, wireshark packets etc
 

ping test:

https://gist.github.com/amitrahman1026/945babb9c4eadcf939634e145d48de76
static arp:
https://gist.github.com/amitrahman1026/d5abb897afdb3c57be05d4075dd0c8c8

min stack size for lwip: 

https://gist.github.com/amitrahman1026/e214ff01ba8c895d8d37844d7e9de016

 

Attached are the most relevant files as well.

Considering the above, I have a few questions for the community:

  1. How should I proceed with debugging this issue
  2. Have you encountered similar issues with UDP communication on STM32 platforms, and if so, how were they resolved?
  3. Is there a potential misconfiguration that I might be overlooking in my setup or initialization code?

Any insights, suggestions, or guidance you can provide would be greatly appreciated. Thank you in advance for your time and help!


 

0 REPLIES 0