cancel
Showing results for 
Search instead for 
Did you mean: 

STM UDP freezes for 20 seconds

jasperpixelfarming
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

10 REPLIES 10
LCE
Principal II

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?

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

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.

Hi

Do you have multiple STM32 boards connected to the same network switch, using same STM32 firmware ?

If 2 boards have same MAC address then the switches will be confused.

The MAC address is configured by the software.

The default example software for ethernet on STM32 use same MAC address.

Users must find a way to have different addresses if several boards are connected to same switch.

I am currently using only one board to fix the issue but it is indeed in a system with multiple devices. I do take care to change the MAC address for each device as to not cause collision so this could not be the issue presumably.

jasperpixelfarming
Associate II

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.

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.

Guillaume K
ST Employee

In what git repository is the commit b44edf68e1bb967b2a9df4b4e71c8d2e3ff70b0f you mention ?

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