Skip to main content
Visitor II
May 14, 2025
Solved

STM UDP freezes for 20 seconds

  • May 14, 2025
  • 4 replies
  • 1216 views

TLDR; STM32Ethernet has udp problems where it freezes for 20 seconds after sending data for 20 seconds and 60 seconds. After this it runs smoothly. However i'd like for it to not freeze twice as it is important the data gets sent asap.

Hi, i am using a STM32-F407VET6 together with STM32Ethernet. I am using the provided EthernetUDP class to setup a udp connection. In my program i am sucesfully sending udp packets however. after sending for 20 seconds The Ethernet Link goes down and no messages are being sent out anymore. I have checked if buffers overflowed or something of the sort but to no avail. I have noticed that right at the time the data transfer stops, that an ARP gratuitous message should arrive exactly at that time as if it keeps running and suddenly works those ARP messages are sent just before the data actually started flowing again. I have checked everywhere, from what i could figure out, and saw that the ETH_DMATXDESC_OWN bit is high in low_level_output of ethernetif.cpp.

I have also tried using the LwIP pretty much directly as seen below. This example work with sending the data but runs into the same issue.

#include "lwip/init.h"
#include "lwip/udp.h"
#include "lwip/ip_addr.h"
#include "lwip/timeouts.h"
#include "lwip/pbuf.h"
#include "STM32Ethernet.h"



struct udp_pcb* pcb;
ip_addr_t dest_ip;
uint16_t port = 5000;

uint32_t lastSend = 0;

void udp_send_custom() {
 struct pbuf* p = pbuf_alloc(PBUF_TRANSPORT, 17, PBUF_RAM);
 if (!p) {
 //Serial.println("Failed to allocate pbuf");
 return;
 }
 etharp
 memcpy(p->payload, "Hello from STM32", 17);

 err_t err = udp_sendto(pcb, p, &dest_ip, port);

 if (err != ERR_OK) {
 //Serial.print("UDP send error: ");
 //Serial.println(err);
 }
 else {
 //Serial.println("Sent packet");
 }

 pbuf_free(p);
}

void setup() {

 IP4_ADDR(&dest_ip, 169, 254, 232, 48);
 
 byte mac[6] = { 0x00, 0x1A, 0x2B, 0xAA, 0x00, 0x21 };
 IPAddress localIP(169, 254, 232, 100);

 // Initialize Ethernet with static IP
 Ethernet.begin(mac, localIP);
 delay(2000);
 // Create UDP control block
 pcb = udp_new();
 if (!pcb) {
 //Serial.println("Failed to create UDP PCB");
 while (1);
 }

 //Serial.println("UDP ready");
}

void loop() {
 // Every 50 ms
 if (millis() - lastSend >= 50) {
 lastSend = millis();
 udp_send_custom();
 HAL_Delay(5);
 }
}

 

I have tried debugging, printing, other boards, but run into the same issue with all of the above.

If anyone knows what the issue might be i would be very glad to hear about as as i've been trying to fix the problem for over a week now.

    This topic has been closed for replies.
    Best answer by jasperpixelfarming

    I have tested using the current commit b44edf68e1bb967b2a9df4b4e71c8d2e3ff70b0f on their main branch.

    With the use of this version my problems seem to have been resolved. Ethernet udp no longer cuts out at specific intervals and instead just stays connected or from what i have tested it stays connected for atleast 1 hour.

    4 replies

    Graduate II
    May 14, 2025

    The OWN flag might show that you have a descriptor handling problem.

    Not sure if the F4 core has this memory barrier problem?

    And hopefully you increased the number of descriptors compared to the examples?

    Visitor II
    May 15, 2025

    I looked and the library had the basic 5 descriptors for both Tx and Rx allocated. According to what i've found whilst debugging is that at most three descriptors got used during runtime. I've increased the amount to 8 just in case at ETH_RXBUFNB and ETH_TXBUFNB in stm32f4xx_hal_conf_default.h but with no actual effect.

     

    I have included a wireshark capture

    Visitor II
    May 15, 2025

    Another discovery, the issue does NOT occur if the stm is directly connected to my laptop through ethernet. The problems start arrising whenever there is a network switch placed in between the two devices. I am currently using (not at the same time) a TL-SG108 and a Netgear FS108 and am experiencing problems with both.

    Visitor II
    May 16, 2025

    I have updated the library to the current commit (b44edf68e1bb967b2a9df4b4e71c8d2e3ff70b0f) on their main branch instead of using their release version 1.4.0. It seems that the problem has been fixed by doing this but haven't been able to test it yet in practise. I will post again with results when i have them.

    jasperpixelfarmingAuthorAnswer
    Visitor II
    May 20, 2025

    I have tested using the current commit b44edf68e1bb967b2a9df4b4e71c8d2e3ff70b0f on their main branch.

    With the use of this version my problems seem to have been resolved. Ethernet udp no longer cuts out at specific intervals and instead just stays connected or from what i have tested it stays connected for atleast 1 hour.

    ST Employee
    May 20, 2025

    In what git repository is the commit b44edf68e1bb967b2a9df4b4e71c8d2e3ff70b0f you mention ?

    Visitor II
    May 21, 2025

    The repository is STM32Ethernet (https://github.com/stm32duino/STM32Ethernet)

    ST Employee
    May 21, 2025

    So you are working on STM32duino / Arduino. It was not obvious from the beginning. It's important to indicate what software you are using (and what hardware / board ).

    Maybe you should have asked in stm32duino / arduino forums: https://www.stm32duino.com/