w5500 RX buffer management

Hello.
I have a problem with receiving data in frames over 4096 bytes with the UDP protocol.I use interrupt. I wrote the code in a way that I receive a 16KB data at a time and then send the same data. But there are two points and problems: 1) For every 1024 bytes of sent data at the one message, an interrupt is activated. 2) Only 6000 bytes of data are received without being lost
There is no guarantee of receiving the rest of the frame data.
Although I guess that the data frame is removed from the end.
Anyway I guess it’s a problem RX buffer management.
Also, I only have one socket for UDP and buffer with a buffer size of 16 KB.
Can you tell me what is the problem??
this is my code:
#include “main.h”
#include “stm32f4xx_hal.h”
#include “socket.h”
#include “w5500.h”
#include “wizchip_conf.h”
#include “setup.h”
#include <string.h>
//********************************** UDP LAN Variable *****************************************
uint8_t remote_ip[4]={192,168,1,1};
uint16_t remote_port=5000;
uint16_t SOCK_UDPS=1;
uint16_t local_port=5000;
uint16_t len=0;
uint8_t buffer[16000];
wiz_NetInfo netInfo = {.mac = {0x00, 0x08, 0xdc, 0xab, 0xcd, 0xef}, // Mac address
.ip = {192, 168, 1, 2}, // IP address
.sn = {255, 255, 255, 0}, // Subnet mask
.gw = {192, 168, 1, 254}}; // Gateway address
uint8_t bufSize = {16,0,0,0,0,0,0,0};
int main(void)
{

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

/* MCU Configuration----------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

/* USER CODE BEGIN Init */
HAL_Delay(100);

/* USER CODE END Init */

/* Configure the system clock */
SystemClock_Config();

/* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_UART4_Init();
MX_SPI2_Init();
MX_SPI1_Init();

/* Initialize interrupts */
MX_NVIC_Init();

/* USER CODE BEGIN 2 /
__HAL_UART_ENABLE_IT(&huart4,UART_IT_RXNE);
HAL_UART_Receive_IT(&huart4,SX_Recv_Uart,SX1280_Packet_Length);
Init_5500();
/
USER CODE END 2 */

/* Infinite loop /
/
USER CODE BEGIN WHILE */
while (1)
{
}
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin==ETH_INTn_Pin)
{
if((getSn_IR(0)>>2)&getSIR())
{
setSn_IR(0, 0x04);
setSIR(0x01);
}
if((len=getSn_RX_RSR(0))>0)
{
memset(buffer,0,len+1);
len=recvfrom(0,buffer, len, remote_ip,&remote_port);
UDP_send(buffer,len);
}
}
}
void Init_5500(void)
{
// reset WIZNET chip
reset_wiznet();

// setup WIZ550io
reg_wizchip_cs_cbfunc( wiznet_sel, wiznet_desel );
reg_wizchip_spi_cbfunc( wiznet_receive_data, wiznet_send_data );

// wizchip_sw_reset();
wizchip_init(bufSize, bufSize);
wizchip_setnetinfo(&netInfo);
wizchip_getnetinfo(&netInfo);

socket(0,Sn_MR_UDP,local_port,0);
HAL_Delay(100);
UDP_send(“salam”,5);
}

Most probably 4KB UDP data is segmented into 1K packets, and for each packet sent you get “SEND_OK” interrupt. I guess (while this is not said in datasheet) size of separate packets is defined by Sn_MSSR, or just fixed to 1024 bytes. Wireshark will tell you more how it looks like from network side.

Why you defined buffer as 16000 bytes? 16 kilobytes is 16384 bytes. Not sure if it is actual anyway.

Please explain what exactly you receive. 16KB RX buffer must be able to accommodate 4096 bytes of data; but if you do not release buffer using RX_RD pointer and RECV command, all packets with their data not fitting into the buffer will be lost (discarded).

1 Like

Actually when i use pooling loopback method and when i set in example the rx buff size to 4KB i receive correct frame just when the frame length is less than rx buff size.in else the frame receives with wrong length. in example with 1024 byte length…
In other hand when i use the interrupt loopback method,the interrupt is occurred for every 1024 Byte
Actually I want to use this chip in 1mb/s data rate but I can’t.i use the Wiznet standard library to send and receive in pooling but I can’t sned the data in over than 1mb/s data rate!!!:sob::sob::sob:

Thanks for your guiding.
I tested something interesting. In the polling mode, the read data frame size is still 1024 bytes!
Of course, I also set the MSSR in 2048KB, but it is not work!!
Why is this happening ??!

Datasheet says that MSSR is only applicable for TCP more, I thought that it may be also applicable for UDP mode, and you prove me wrong.

Did you look into the Wireshark capture?

1 Like

No, but can i ask you exactly what to see in it?

Share it here.

1 Like

save.zip (1.4 کیلوبایت)

Of course your W5500 will be receiving 1024 bytes at a time because network device with IP address 192.168.1.151 (Sony 00:1d:ba:f4:69:1d) sends data this way. This division onto 1024 bytes packets is NOT performed by the W5500, but by another device. This in exactly this case you will have to assemble your larger data stream from a number of 1024 packets using device driving W5500 (microcontroller or whatever).

Why not using TCP?

1 Like

Yes you are right.
I should use UDP because I want to send online video stream on LAN.
in addition I need maximum throuput on LAN
Thank you very much for your helping