2025-05-14 7:36 AM
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.
2025-05-14 7:49 AM
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?