Sending data more than 1472 bytes using UDP

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Sending data more than 1472 bytes using UDP

MTrost
I made a TCP server on STM32F407 using lwIP version 2.1.2 and it worked fine. Now for some reasons I need to run a UDP server on the MCU. I tried and it worked fine for data size below 1472 bytes. Yet the desired data length is around 16KB to 20KB.
1. I searched and found that IP_FRAG should  be  defined 1 to allow send data over MTU size. It is enabled by default. I read from an email [1] that IP_FRAG_MAX_MTU should be also changed to a proper value. However I cannot realize where it is!
2. Another approach employed by me is to send chopped data whose size are below 1472 bytes in a for loop but the for loop only executes first time and the MCU goes stop status. How I must send data in a for loop?

[1]http://lwip.100.n7.nabble.com/Sending-a-large-amount-of-data-using-UDP-td35933.html  

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Sending data more than 1472 bytes using UDP

Jon Bean

Hi Mohammad

I had to do something similar on a TI MCU. I chose to send multiple packets that were less than the MTU. Basically I called the transmit route from the LWIP interrupt. Each time the interrupt was called it would send a data packet that was not more than the MTU. I had some flags to know if I still needed to keep sending data or if I can stop. This seemed to work OK for my application.

Regards

Jon

On 06/10/2020 12:32, Mohammad Tavakoli wrote:
I made a TCP server on STM32F407 using lwIP version 2.1.2 and it worked fine. Now for some reasons I need to run a UDP server on the MCU. I tried and it worked fine for data size below 1472 bytes. Yet the desired data length is around 16KB to 20KB.
1. I searched and found that IP_FRAG should  be  defined 1 to allow send data over MTU size. It is enabled by default. I read from an email [1] that IP_FRAG_MAX_MTU should be also changed to a proper value. However I cannot realize where it is!
2. Another approach employed by me is to send chopped data whose size are below 1472 bytes in a for loop but the for loop only executes first time and the MCU goes stop status. How I must send data in a for loop?

[1]http://lwip.100.n7.nabble.com/Sending-a-large-amount-of-data-using-UDP-td35933.html  

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users

Virus-free. www.avast.com

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Sending data more than 1472 bytes using UDP

MTrost
Thank you for your answer. What do you mean by lwIP interrupt? where I can find it? I am also willing to know I should use udp_send() or udp_sendto() in that ISR.

On Tue, Oct 6, 2020 at 3:11 PM Jon Bean <[hidden email]> wrote:

Hi Mohammad

I had to do something similar on a TI MCU. I chose to send multiple packets that were less than the MTU. Basically I called the transmit route from the LWIP interrupt. Each time the interrupt was called it would send a data packet that was not more than the MTU. I had some flags to know if I still needed to keep sending data or if I can stop. This seemed to work OK for my application.

Regards

Jon

On 06/10/2020 12:32, Mohammad Tavakoli wrote:
I made a TCP server on STM32F407 using lwIP version 2.1.2 and it worked fine. Now for some reasons I need to run a UDP server on the MCU. I tried and it worked fine for data size below 1472 bytes. Yet the desired data length is around 16KB to 20KB.
1. I searched and found that IP_FRAG should  be  defined 1 to allow send data over MTU size. It is enabled by default. I read from an email [1] that IP_FRAG_MAX_MTU should be also changed to a proper value. However I cannot realize where it is!
2. Another approach employed by me is to send chopped data whose size are below 1472 bytes in a for loop but the for loop only executes first time and the MCU goes stop status. How I must send data in a for loop?

[1]http://lwip.100.n7.nabble.com/Sending-a-large-amount-of-data-using-UDP-td35933.html  

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users

Virus-free. www.avast.com
_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Sending data more than 1472 bytes using UDP

MTrost
I reckon that maybe it is useful to send my code:
uint32_t  aa[4001];
struct pbuf* GK_pbuf;
err_t GK_err;
int main(){
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_LWIP_Init();
  udp_echoserver_init();
  for(i = 0; i <= 4000; ++i){
      aa[i] = (i % 30) + 0x30; 
  }
GK_pbuf = pbuf_alloc(PBUF_TRANSPORT, 1600, PBUF_RAM);
  while (1)
  {
      ethernetif_input(&gnetif);
      sys_check_timeouts();
  }
}


and in  udp_echoserver_init.c file:

void udp_echoserver_init(void)
{
  ip4addr_aton("192.168.1.18", &serverIP);  
   struct udp_pcb *upcb;
   err_t err;
   upcb = udp_new();
   if (upcb)
   {
      err = udp_bind(upcb, &serverIP , 7);
      if(err == ERR_OK)
      {
        udp_recv(upcb, udp_echoserver_receive_callback, NULL);
      }
   }
}


void udp_echoserver_receive_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
{
  udp_connect(upcb, addr, port);
  ip4addr_aton("192.168.1.88", &remoteIP);
  for(iii = 0; iii <= 9; ++iii){
        GH_err = pbuf_take(GK_pbuf, aa + (iii * 1472), 1472);
        Gn_err = udp_sendto(upcb, GK_pbuf, &remoteIP, 7);
        // Gn_err = udp_send(upcb, GK_pbuf);
        HAL_Delay(50); //50ms
    }
  udp_disconnect(upcb);
  pbuf_free(p); 
}

On Tue, Oct 6, 2020 at 3:32 PM Mohammad Tavakoli <[hidden email]> wrote:
Thank you for your answer. What do you mean by lwIP interrupt? where I can find it? I am also willing to know I should use udp_send() or udp_sendto() in that ISR.

On Tue, Oct 6, 2020 at 3:11 PM Jon Bean <[hidden email]> wrote:

Hi Mohammad

I had to do something similar on a TI MCU. I chose to send multiple packets that were less than the MTU. Basically I called the transmit route from the LWIP interrupt. Each time the interrupt was called it would send a data packet that was not more than the MTU. I had some flags to know if I still needed to keep sending data or if I can stop. This seemed to work OK for my application.

Regards

Jon

On 06/10/2020 12:32, Mohammad Tavakoli wrote:
I made a TCP server on STM32F407 using lwIP version 2.1.2 and it worked fine. Now for some reasons I need to run a UDP server on the MCU. I tried and it worked fine for data size below 1472 bytes. Yet the desired data length is around 16KB to 20KB.
1. I searched and found that IP_FRAG should  be  defined 1 to allow send data over MTU size. It is enabled by default. I read from an email [1] that IP_FRAG_MAX_MTU should be also changed to a proper value. However I cannot realize where it is!
2. Another approach employed by me is to send chopped data whose size are below 1472 bytes in a for loop but the for loop only executes first time and the MCU goes stop status. How I must send data in a for loop?

[1]http://lwip.100.n7.nabble.com/Sending-a-large-amount-of-data-using-UDP-td35933.html  

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users

Virus-free. www.avast.com
_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Sending data more than 1472 bytes using UDP

Jon Bean

In my TI design, there is the following function. This is a timer interrupt that LWIP uses. I guess you should have something similar in your design. I then test a flag and do the transmit in another function. I use udp_sento function.

void lwIPHostTimerHandler(void)
{
    // Test for UDP transmit request
    if (eth_udp_tx_flag_get() == 1)
    {
        eth_udp_tx();
    }
}

On 06/10/2020 13:24, Mohammad Tavakoli wrote:
I reckon that maybe it is useful to send my code:
uint32_t  aa[4001];
struct pbuf* GK_pbuf;
err_t GK_err;
int main(){
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_LWIP_Init();
  udp_echoserver_init();
  for(i = 0; i <= 4000; ++i){
      aa[i] = (i % 30) + 0x30; 
  }
GK_pbuf = pbuf_alloc(PBUF_TRANSPORT, 1600, PBUF_RAM);
  while (1)
  {
      ethernetif_input(&gnetif);
      sys_check_timeouts();
  }
}


and in  udp_echoserver_init.c file:

void udp_echoserver_init(void)
{
  ip4addr_aton("192.168.1.18", &serverIP);  
   struct udp_pcb *upcb;
   err_t err;
   upcb = udp_new();
   if (upcb)
   {
      err = udp_bind(upcb, &serverIP , 7);
      if(err == ERR_OK)
      {
        udp_recv(upcb, udp_echoserver_receive_callback, NULL);
      }
   }
}


void udp_echoserver_receive_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
{
  udp_connect(upcb, addr, port);
  ip4addr_aton("192.168.1.88", &remoteIP);
  for(iii = 0; iii <= 9; ++iii){
        GH_err = pbuf_take(GK_pbuf, aa + (iii * 1472), 1472);
        Gn_err = udp_sendto(upcb, GK_pbuf, &remoteIP, 7);
        // Gn_err = udp_send(upcb, GK_pbuf);
        HAL_Delay(50); //50ms
    }
  udp_disconnect(upcb);
  pbuf_free(p); 
}

On Tue, Oct 6, 2020 at 3:32 PM Mohammad Tavakoli <[hidden email]> wrote:
Thank you for your answer. What do you mean by lwIP interrupt? where I can find it? I am also willing to know I should use udp_send() or udp_sendto() in that ISR.

On Tue, Oct 6, 2020 at 3:11 PM Jon Bean <[hidden email]> wrote:

Hi Mohammad

I had to do something similar on a TI MCU. I chose to send multiple packets that were less than the MTU. Basically I called the transmit route from the LWIP interrupt. Each time the interrupt was called it would send a data packet that was not more than the MTU. I had some flags to know if I still needed to keep sending data or if I can stop. This seemed to work OK for my application.

Regards

Jon

On 06/10/2020 12:32, Mohammad Tavakoli wrote:
I made a TCP server on STM32F407 using lwIP version 2.1.2 and it worked fine. Now for some reasons I need to run a UDP server on the MCU. I tried and it worked fine for data size below 1472 bytes. Yet the desired data length is around 16KB to 20KB.
1. I searched and found that IP_FRAG should  be  defined 1 to allow send data over MTU size. It is enabled by default. I read from an email [1] that IP_FRAG_MAX_MTU should be also changed to a proper value. However I cannot realize where it is!
2. Another approach employed by me is to send chopped data whose size are below 1472 bytes in a for loop but the for loop only executes first time and the MCU goes stop status. How I must send data in a for loop?

[1]http://lwip.100.n7.nabble.com/Sending-a-large-amount-of-data-using-UDP-td35933.html  

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users

Virus-free. www.avast.com
_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Sending data more than 1472 bytes using UDP

Alister Fisher
In reply to this post by MTrost

The code you’ve sent are high software layers. Perhaps you need to check the lower software layers can send pbuf chains. If you’re using ST’s HAL and lwIP’s ethernetif.c, check out what I did for the STM32H7 at https://community.st.com/s/question/0D50X0000C6eNNSSQ2/bug-fixes-stm32h7-ethernet. The STM32F4 ethernet peripheral and driver would be different.

 

Regards

Alister

 

Alister Fisher
Senior Software Developer

Advatek Lighting

16/52 Corporate Blvd, Bayswater, VIC, 3153, AUSTRALIA
T: +61  3 8400 4566 
[hidden email]  www.advateklights.com
      

From: lwip-users <lwip-users-bounces+alister=[hidden email]> On Behalf Of Mohammad Tavakoli
Sent: Tuesday, 6 October 2020 11:24 pm
To: Mailing list for lwIP users <[hidden email]>
Subject: Re: [lwip-users] Sending data more than 1472 bytes using UDP

 

I reckon that maybe it is useful to send my code:

uint32_t  aa[4001];

struct pbuf* GK_pbuf;

err_t GK_err;

int main(){

  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_LWIP_Init();
  udp_echoserver_init();
  for(i = 0; i <= 4000; ++i){
      aa[i] = (i % 30) + 0x30; 
  }
GK_pbuf = pbuf_alloc(PBUF_TRANSPORT, 1600, PBUF_RAM);

  while (1)
  {
      ethernetif_input(&gnetif);
      sys_check_timeouts();
  }

}

 

 

and in  udp_echoserver_init.c file:

 

void udp_echoserver_init(void)
{

  ip4addr_aton("192.168.1.18", &serverIP);  
   struct udp_pcb *upcb;
   err_t err;
   upcb = udp_new();
   if (upcb)
   {
      err = udp_bind(upcb, &serverIP , 7);
      if(err == ERR_OK)
      {
        udp_recv(upcb, udp_echoserver_receive_callback, NULL);
      }
   }
}

 

 

void udp_echoserver_receive_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
{
  udp_connect(upcb, addr, port);
  ip4addr_aton("192.168.1.88", &remoteIP);
  for(iii = 0; iii <= 9; ++iii){
        GH_err = pbuf_take(GK_pbuf, aa + (iii * 1472), 1472);
        Gn_err = udp_sendto(upcb, GK_pbuf, &remoteIP, 7);

        // Gn_err = udp_send(upcb, GK_pbuf);
        HAL_Delay(50); //50ms
    }
  udp_disconnect(upcb);
  pbuf_free(p); 
}

 

On Tue, Oct 6, 2020 at 3:32 PM Mohammad Tavakoli <[hidden email]> wrote:

Thank you for your answer. What do you mean by lwIP interrupt? where I can find it? I am also willing to know I should use udp_send() or udp_sendto() in that ISR.

 

On Tue, Oct 6, 2020 at 3:11 PM Jon Bean <[hidden email]> wrote:

Hi Mohammad

I had to do something similar on a TI MCU. I chose to send multiple packets that were less than the MTU. Basically I called the transmit route from the LWIP interrupt. Each time the interrupt was called it would send a data packet that was not more than the MTU. I had some flags to know if I still needed to keep sending data or if I can stop. This seemed to work OK for my application.

Regards

Jon

On 06/10/2020 12:32, Mohammad Tavakoli wrote:

I made a TCP server on STM32F407 using lwIP version 2.1.2 and it worked fine. Now for some reasons I need to run a UDP server on the MCU. I tried and it worked fine for data size below 1472 bytes. Yet the desired data length is around 16KB to 20KB.
1. I searched and found that IP_FRAG should  be  defined 1 to allow send data over MTU size. It is enabled by default. I read from an email [1] that IP_FRAG_MAX_MTU should be also changed to a proper value. However I cannot realize where it is!
2. Another approach employed by me is to send chopped data whose size are below 1472 bytes in a for loop but the for loop only executes first time and the MCU goes stop status. How I must send data in a for loop?

[1]http://lwip.100.n7.nabble.com/Sending-a-large-amount-of-data-using-UDP-td35933.html  

 

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users

 

Virus-free. www.avast.com

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users


_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Sending data more than 1472 bytes using UDP

MTrost
I am grateful for you Jon Bean and Alister Fisher. With using a pbuf chain and employing tips in the link provided by Alister I achieved to transfer data about 72 Mbps speed. Now I am curious to know why the speed is far from 100 Mbps (the expected speed).

On Wed, Oct 7, 2020 at 1:35 AM Alister Fisher <[hidden email]> wrote:

The code you’ve sent are high software layers. Perhaps you need to check the lower software layers can send pbuf chains. If you’re using ST’s HAL and lwIP’s ethernetif.c, check out what I did for the STM32H7 at https://community.st.com/s/question/0D50X0000C6eNNSSQ2/bug-fixes-stm32h7-ethernet. The STM32F4 ethernet peripheral and driver would be different.

 

Regards

Alister

 

Alister Fisher
Senior Software Developer

Advatek Lighting

16/52 Corporate Blvd, Bayswater, VIC, 3153, AUSTRALIA
T: +61  3 8400 4566 
[hidden email]  www.advateklights.com
      

From: lwip-users <lwip-users-bounces+alister=[hidden email]> On Behalf Of Mohammad Tavakoli
Sent: Tuesday, 6 October 2020 11:24 pm
To: Mailing list for lwIP users <[hidden email]>
Subject: Re: [lwip-users] Sending data more than 1472 bytes using UDP

 

I reckon that maybe it is useful to send my code:

uint32_t  aa[4001];

struct pbuf* GK_pbuf;

err_t GK_err;

int main(){

  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_LWIP_Init();
  udp_echoserver_init();
  for(i = 0; i <= 4000; ++i){
      aa[i] = (i % 30) + 0x30; 
  }
GK_pbuf = pbuf_alloc(PBUF_TRANSPORT, 1600, PBUF_RAM);

  while (1)
  {
      ethernetif_input(&gnetif);
      sys_check_timeouts();
  }

}

 

 

and in  udp_echoserver_init.c file:

 

void udp_echoserver_init(void)
{

  ip4addr_aton("192.168.1.18", &serverIP);  
   struct udp_pcb *upcb;
   err_t err;
   upcb = udp_new();
   if (upcb)
   {
      err = udp_bind(upcb, &serverIP , 7);
      if(err == ERR_OK)
      {
        udp_recv(upcb, udp_echoserver_receive_callback, NULL);
      }
   }
}

 

 

void udp_echoserver_receive_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
{
  udp_connect(upcb, addr, port);
  ip4addr_aton("192.168.1.88", &remoteIP);
  for(iii = 0; iii <= 9; ++iii){
        GH_err = pbuf_take(GK_pbuf, aa + (iii * 1472), 1472);
        Gn_err = udp_sendto(upcb, GK_pbuf, &remoteIP, 7);

        // Gn_err = udp_send(upcb, GK_pbuf);
        HAL_Delay(50); //50ms
    }
  udp_disconnect(upcb);
  pbuf_free(p); 
}

 

On Tue, Oct 6, 2020 at 3:32 PM Mohammad Tavakoli <[hidden email]> wrote:

Thank you for your answer. What do you mean by lwIP interrupt? where I can find it? I am also willing to know I should use udp_send() or udp_sendto() in that ISR.

 

On Tue, Oct 6, 2020 at 3:11 PM Jon Bean <[hidden email]> wrote:

Hi Mohammad

I had to do something similar on a TI MCU. I chose to send multiple packets that were less than the MTU. Basically I called the transmit route from the LWIP interrupt. Each time the interrupt was called it would send a data packet that was not more than the MTU. I had some flags to know if I still needed to keep sending data or if I can stop. This seemed to work OK for my application.

Regards

Jon

On 06/10/2020 12:32, Mohammad Tavakoli wrote:

I made a TCP server on STM32F407 using lwIP version 2.1.2 and it worked fine. Now for some reasons I need to run a UDP server on the MCU. I tried and it worked fine for data size below 1472 bytes. Yet the desired data length is around 16KB to 20KB.
1. I searched and found that IP_FRAG should  be  defined 1 to allow send data over MTU size. It is enabled by default. I read from an email [1] that IP_FRAG_MAX_MTU should be also changed to a proper value. However I cannot realize where it is!
2. Another approach employed by me is to send chopped data whose size are below 1472 bytes in a for loop but the for loop only executes first time and the MCU goes stop status. How I must send data in a for loop?

[1]http://lwip.100.n7.nabble.com/Sending-a-large-amount-of-data-using-UDP-td35933.html  

 

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users

 

Virus-free. www.avast.com

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users