Skip to main content
Visitor II
July 28, 2024
Question

STM32F767 Ethernet at different rate

  • July 28, 2024
  • 7 replies
  • 3653 views

Hi everyone. I'm using stm32f767zi board with lwip stack and I need to transmit at different rate through Ethernet: 50mbit/s, 80mbit/s and 100mbit/s. When I tried to send a buffer of 6554 byte every 1ms (in order to send 6553600 byte aka 50mbit every second) lwip give me memory error: I tried to change some of its parameters but the maximum rate I got was 27mbit/s. So anyone can help me and give me some tips to solve this problem

    This topic has been closed for replies.

    7 replies

    Super User
    July 28, 2024

    Just before we begin: do you know about MTU and fragmentation? 

    Al3Author
    Visitor II
    July 28, 2024

    Hi Pavel, of course I know them

    Super User
    July 28, 2024

    In normal mode (no jumbo packets) 6554 bytes will be fragmented , this requires buffering in LwIP. Can you use smaller packets? TCP or UDP? 

    Al3Author
    Visitor II
    July 28, 2024

    I'm using TCP with an MTU of 1460 bytes, of course I can use smaller packets. How can I see if I send data at 50 Mbit/s?

    Super User
    July 28, 2024

    Capture sent packets with wireshark for some time, then calculate average per second?

    Maybe you need more TX descriptors to send large fragmented packets. By default the driver has only 4 descriptors, so after fragmentation it makes more than 4 ETH packets. So LwIP will be blocked until at least 1 ETH packet is send and a TX descriptor becomes available.

    After couple of fragments are sent, the receiving side may start ACK'ing, these packets must be received and handled. It can get complicated.

     

    Al3Author
    Visitor II
    July 28, 2024

    Sorry Pavel, what is a TX descriptors? Do you think that lwip return me memory error because of this kind of block?

    Super User
    July 28, 2024

    Not sure about specific LwIP error. Need to debug.

    TX descriptors are like tags attached to L2 TX packets, they point to data buffers and hold some control info. Their number is hardcoded in the driver. Same about the RX descriptors. The bottom line is that the driver cannot queue more ETH packets for TX than the number of descriptors, even if you have enough memory for the data.

     

    Al3Author
    Visitor II
    July 28, 2024

    Ok understood what TX are. Do you think it is a good solution increase their number? I attached the point of tcp_write function in tcp_out.c file where I get the error

    Al3Author
    Visitor II
    July 28, 2024

    Ok understood what TX are. Do you think it is a good solution increase their number? I attached the point of tcp_write function in tcp_out.c file where I get the error

    Super User
    July 28, 2024

     I attached the point of tcp_write function in tcp_out.c file where I get the error

    Unlikely error at that point is directly linked to available descriptors. But I'd try to let LwIP  map and queue all segments of a large TCP packet at once, so sending it can run in background.

     

    Al3Author
    Visitor II
    July 28, 2024

    Sorry Pavel I don't understand what do you mean

    Super User
    July 28, 2024

    I mean that this error does not look directly related to TX descriptors. Find why tcp_pbuf_prealloc fails. The memory area for LwIP pool in ST examples is defined in weird and dangerous way, make sure it does not conflict with other memory.

    Al3Author
    Visitor II
    July 28, 2024

    I tried with 32 TX descriptors and 32 RX descriptors and with the lwip configuration that I attached to this message. The max rate I got was 42,5 Mbit/s (measured through Wireshark) (I send 10486 bytes every 1ms), I also tried with other configurations of lwip parameters up to MEM_SIZE: 100*1024 bytes, TCP_SND_BUF: 70*1460, TCP_SND_QUEUELEN: 1120, TCP_WND: 70*1460, MEMP_NUM_PBUF: 64, PBUF_POOL_SIZE: 80, PBUF_POOL_BUFSIZE but the rate is fixed at 42,5 Mbit/s. I don't know what to do.

    Super User
    July 28, 2024

    > 42,5 Mbit/s (measured through Wireshark) 

    Not bad at all, considering the TCP overhead! 100 Mbit/s is the physical limit for STM32F7. 

    I don't know what to do.

    If you can get it running at that rate stable for hours - great. Measure inter-packet gaps with wireshark, try to understand where the time is spent.