AnsweredAssumed Answered

LwIP UDP stream max rate without packet loss

Question asked by Giuseppe Cannarella on Jul 20, 2017

Anyone can provide an example of STM32F437 FreeRTOS + LwIP UDP stream that no loose ethernet packets.

I've tried different implementation but, analyzing the ethernet packets, sometimes one packet is lost.

 

This is my implementation

 

void UDP_Send_Task(void const * argument)
{
  err_t error;   
 
  struct ip4_addr Sendtoipaddr;
 
  for (;;) 
  {   
    switch (Eth_MPX_Send_SM)
    {
      case CREATE_CONNECTION:
        IP4_ADDR(&Sendtoipaddr, 192, 168, 10, 124); 
        conn= udp_new();
        error = udp_bind(conn, IP_ADDR_ANY, 1234);
        if (error == ERR_OK)
        {
          PayloadCounter=0;
          Eth_MPX_Send_SM= SEND_PCKTS;//start to send pkcts
          //vTaskSuspend(NULL);
        }
      break;
      case SEND_PCKTS:         
        //HAL_GPIO_WritePin(LED5_GPIO_Port, LED5_Pin, GPIO_PIN_RESET);                       
        buf = pbuf_alloc(PBUF_TRANSPORT,sizeof(SendBuff),PBUF_REF);
       
        for (i=0; i<32; i=i+2)
        {
          SendBuff[i]= (PayloadCounter >>8)& 0xFF;
          SendBuff[i+1]= (uint8_t)PayloadCounter & 0xFF;
          PayloadCounter ++;
        }
       
        buf->payload = SendBuff;
       
        //memcpy (buf->payload, gbuf.mpx.buf, sizeof(gbuf.mpx.buf)); 
       
        TempBuf = buf->payload;
       
        First= ((uint16_t)TempBuf[0] <<8) | TempBuf[1];
        if (First != (Last+1))
        {
          ErrCount++;
        }
        Last= ((uint16_t)TempBuf[1022]<<8) | (uint16_t)TempBuf[1023];              
       
        error= udp_sendto(conn, buf, &Sendtoipaddr, 1234);
       
        if (error != ERR_OK)
        {
          NetErr++;             
        }
        //netbuf_free(buf);
        pbuf_free(buf); //De-allocate packet buffer
        vTaskDelay(pdMS_TO_TICKS(1));
        //NetDataAvailable =FALSE;
        //HAL_GPIO_WritePin(LED5_GPIO_Port, LED5_Pin, GPIO_PIN_SET);
        //vTaskSuspend(NULL);      
      break;
    }     
  } 
}
Thanks

Outcomes