cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with UDP Data Size Limitation on STM32

CosmicWreck
Visitor

Hello all, 

I developed a UDP server/client with the objective to send and receive data simultaneously. The code has some problems in the way its written (e.g., unnecessary loops, variable definitions inside a loop...), but I'm only interested in solving one problem which is the amount of data I'm able to send from my stm32 to my pc, I want to send 3 TS packets at a time (188*3=564 bytes per UDP transmission), but the maximum number of bytes i was able to transmit is 209 bytes, if i make it 210 bytes, I receive nothing on my PC (python).

The basic flow of the data I want to send is:-

I'm initializing three buffers with TS headers:

 

uint8_t uart2_data[188] = {0x47, 0x1F, 0xFF, 0xD0, 0x03};
uint8_t uart1_data[188] = {0x47, 0x1F, 0xFF, 0xD0, 0x01};
uint8_t uart6_data[188] = {0x47, 0x1F, 0xFF, 0xD0, 0x02};

 

 

Then, to each buffer i will add "additional_data" to create a TS packet: 

 

uint8_t additional_data[183] = {
     'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd',  // ASCII text "Hello World"
     'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
     'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
     'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
     'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
     's', 't'
};
memcpy(uart2_data + 5, additional_data, 183);
memcpy(uart1_data + 5, additional_data, 183);
memcpy(uart6_data + 5, additional_data, 183);

 

After that, I will store each TS packet to one buffer (message_with_counter):

 

		    snprintf(message_with_counter, sizeof(message_with_counter), "%s%s%s", uart2_data, uart1_data, uart6_data);

 

 

The whole UDP client functions: 

 

// Initialize the UDP client to communicate with PC
void udpClient_init(void)
{
    err_t err;

    /* 1. Create a new UDP control block */
    client_upcb = udp_new();

    /* Bind the block to STM32 IP and port */
    ip_addr_t myIPaddr;
    IP_ADDR4(&myIPaddr, 192, 168, 1, 90);  // STM32 client IP address
   // udp_bind(client_upcb, &myIPaddr, 9);  // Port 8 for client

    /* Configure destination IP address and port (PC server IP and port) */
    ip_addr_t DestIPaddr;
    IP_ADDR4(&DestIPaddr, 192, 168, 1, 20);  // PC server IP
    err = udp_connect(client_upcb, &DestIPaddr, 61000);

    if (err == ERR_OK)
    {
        udp_recv(client_upcb, udp_receive_callback, NULL);  // Set receive callback
        udpClient_send();  // Start sending messages
    }
}

// Function to send data from UDP client to server (PC)
void udpClient_send(void)
{
	//struct pbuf *txBuf;
	char message_with_counter[564];  // Buffer to hold the final message with counter
	
	while (1)
	{
		 //struct pbuf *txBuf;
		struct pbuf *txBuf;
		//char message_with_counter[564];  
		 uint8_t uart2_data[188] = {0x47, 0x1F, 0xFF, 0xD0, 0x03};  
		 uint8_t uart1_data[188] = {0x47, 0x1F, 0xFF, 0xD0, 0x01};  
		 uint8_t uart6_data[188] = {0x47, 0x1F, 0xFF, 0xD0, 0x02};  


		 uint8_t additional_data[183] = {
		     'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd',  // ASCII text "Hello World"
		     'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
		     'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
		     'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
		     'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
		     's', 't'
		 };

		 memcpy(uart2_data + 5, additional_data, 183);
		 memcpy(uart1_data + 5, additional_data, 183);
		 memcpy(uart6_data + 5, additional_data, 183);

		    // Receive data from UART2 (Docklight) into the uart2_data buffer
		   // HAL_UART_Receive(&huart2, uart2_data + 5, 183, 1000);  // Timeout of 10ms
		   // HAL_UART_Receive(&huart1, uart1_data + 5, 183, 10);  // Timeout of 10ms
		   // HAL_UART_Receive(&huart, uart6_data + 5, 183, 10);  // Timeout of 10ms


		    snprintf(message_with_counter, sizeof(message_with_counter), "%s%s%s", uart2_data, uart1_data, uart6_data)

		    // Prepare the UDP pbuf with the message with counter
		    txBuf = pbuf_alloc(PBUF_TRANSPORT, strlen(message_with_counter), PBUF_RAM);

		    if (txBuf != NULL)
		    {
		        /* Copy message with counter to pbuf */
		        pbuf_take(txBuf, message_with_counter, strlen(message_with_counter));
		    	//pbuf_take(txBuf, message_with_counter, sizeof(uart2_data) + sizeof(uart1_data) + sizeof(uart6_data));


		        /* Send UDP data */
		        udp_send(client_upcb, txBuf);

		        /* Free the pbuf */
		        pbuf_free(txBuf);
		        osDelay(15);  
    }
}
}

 

 

My question is: What causes the limitation or constraint to be 209 bytes per UDP transmission? 

 

 

 
0 REPLIES 0