cancel
Showing results for 
Search instead for 
Did you mean: 

How to receive a 4k UDP packet when my MTU is 1500, using fragmented IP packets?

Mz.1
Associate III

Hey,

I Have STM32H743Zi

I'm new at this, so please forgive me if I'm unclear.

I'm trying to receive 4k UDP packets but I'm getting only 1k each time.

I did a Google search and understand that if I want to receive a UDP packet of 4k I need to use fragmentation due to the MTU being 1500.

I tried to enable the below parameters:

IP_REASSEMBLY - enabled

MEMP_NUM_REASSDATA - 5

IP_REASS_MAX_PBUFS - 10

MEMP_NUM_FRAG_PBUF - 4

inside my callback function, I'm trying to read all the 4k data, I'm getting 1k in the first node but the next node in the pbuf is always NULL.

I also see on Wirshak messages with 1k

while I'm sending using Hrecules 4k for sure.

this is the callback function code:

void UDP_TX_RECEIVE_CALLBACK(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)

{

 char TxUdpPacket[SPI_PACKET_SIZE] = {0, };

 // Process each received fragment

 while (p != NULL)

 {

  // Copy fragment data to appropriate position in udpPacket array

  memcpy(&TxUdpPacket[p->tot_len - p->len], p->payload, p->len);

  // Move to the next fragment

  struct pbuf *next = p->next;

  pbuf_free(p);

  p = next;

 }

}

pls, help!!

thank you 🙂

21 REPLIES 21

> I also see on Wirshak messages with 1k

> while I'm sending using Hrecules 4k for sure.

If Wireshark does not see 4k packets, why would STM32 see them?

JW

@Community member​ 

sorry you are right, my mistake.

I see 4k on Wireshark as well now.

still no change...

but if I'm adding a breakpoint in the callback method, it won't stop if the message is more than 1500 bytes.

Mz.1
Associate III

@Community member​ any idea what I'm doing wrong?

Pavel A.
Evangelist III

Depends on how the other party is connected to the network. The ETH controller of STM32743 supports jumbo (a.k.a. giant) packets up to ~9 KB. So you can send the whole 4KB in one piece if the switch allows this or the connection is direct.

Mz.1
Associate III

@Pavel A.​ 

This is interesting...

I ran the below command with Python:

>>> import psutil

>>> print(psutil.net_if_stats())

and got this information on the STM network adapter in the PC:

snicstats(isup=True, duplex=<NicDuplex.NIC_DUPLEX_FULL: 2>, speed=100, mtu=9000)

 the connection is direct to the PC (between the PC and the STM)

is this what you meant?

if so, do you have any extra information that explains this "jumbo (a.k.a. giant) packets up to ~9 KB", and how you use it?

thank you for your answer!!

Pavel A.
Evangelist III

@Mz.1​ what is 'STM network adapter in the PC'?

The jumbo packet size is not unique for the STM32 ETH. Many ethernet controllers found in desktop or notebook PCs have it too. For example Realtek PCIe GBe supports jumbo frame up to 9 KB as well.

For more info on jumbo frames in general, please google.

For STM32H743, search the ETH section of RM0433 for "jumbo".

It can be enabled by bit 16 in ETH_MACCR register.

Existing examples unfortunately do not demonstrate this feature.

Piranha
Chief II

The code in UDP_TX_RECEIVE_CALLBACK() is broken. The pbuf_free() has to be called once on the whole buffer chain, not on every segment.

While it's technically possible, nobody fragments UDP packets, because UDP does not guarantee neither the delivery, nor the order of the fragments. Therefore such a requirement sounds like just a wrong approach to the problem. If you would describe the requirements and goals, probably users would give you some better ideas for solutions. Generally with 4 KB packets, most likely one should implement an application layer protocol over TCP or UDP.

Mz.1
Associate III

@Piranha​ Hi, thanks for the answer!

Regarding the  UDP_TX_RECEIVE_CALLBACK() method, you are right but that was just an example of what I'm trying to implement and not the final code.

I will describe the task:

We have a Python code that runs on a Windows machine that sends every 1 sec UDP packet - size 4k (can be less than 4k, but the max size is 4k) to the STM32H743Zi device.

the PC and the STM are connected directly (RJ45)

The STM code uses LWIP and DMA.

I have this callback function that is called every time when there is an incoming UDP packet.

if the UDP packet the PC sends is more than 1500 bytes (due to the MTU limit) the callback function isn't called otherwise I see packets.

I need a solution for receiving UDP packets of more than 1500 bytes.

you said that packet fragmentation with UDP is not a good solution and that makes sense to me.

@Pavel A.​ mentioned above an interesting solution with the "Jumbo frames" - I looked online and I didn't find an example or lots of information about how to implement this.

if anybody has an idea/solution I would appreciate the help...

thanks 🙂

Pavel A.
Evangelist III

When you send fragmented 4K UDP, will you see at least one fragment received in the low_level_input() ?

The easiest: send from PC 3 * 1.4K packets.