Hi everyone!
Can you please help me understand the root cause of the issue I faced. I’ve been searching on the Internet for a long time by with no luck.
I’m using stm32f103 + W5500 board.
Application is running on STM32 as a TCP server and uses raw TCP to communicate with clients.
Everything works good if a TCP client consiquently sends request, receives for the whole response from server, and then sends next request and so on.
But if a client sends next request before it receives the whole response from TCP server (my STM32+W5500 board), W5500 chip goes down on recieving this request during the current response is still being sent.
I’m using this library https://github.com/Wiznet/ioLibrary_Driver/archive/master.zip
getSn_SR(TCP_SOCKET) returns 0x28 status which is not documented in the datasheet and wizphy_getphylink() returns PHY_LINK_OFF
Below is main part of the rx code in the interrupt IRQ:
irq_val = getSn_IR(TCP_SOCKET);
if (irq_val & Sn_IR_RECV) { // It means we receive a packet in socket TCP_SOCKET
if ((rcvd_size = getSn_RX_RSR(TCP_SOCKET)) > 0) {
uint16_t next_head;
char data;
while (rcvd_size--) {
ret = recv(TCP_SOCKET, (uint8_t *)&data, 1);
if (ret > 0) {
next_head = (rxbuf.head + 1) & (RX_BUFFER_SIZE - 1);
if(!hal.stream.enqueue_realtime_command(data, StreamType_Serial)) {
rxbuf.data[rxbuf.head] = data;
rxbuf.head = next_head;
}
}
}
}
setSn_IR(TCP_SOCKET, Sn_IR_RECV); // Clearing RECV interrupt flag
}
Below is tx function:
void ethWriteS (const char *s)
{
char *ptr = (char *)s;
int32_t ret;
uint16_t sent_size = 0, length = strlen(s);
while(sent_size != length) {
ret = send(TCP_SOCKET, (uint8_t *)ptr + sent_size, length - sent_size);
if (ret >=0 ) {
sent_size += ret;
}
else {
//print_debug("Send error: %d\n", ret);
close(TCP_SOCKET);
return;
}
}
}
Wireshark trace below.
192.168.1.70 is my TCP server (STM32+W5500)
192.168.1.3 is a TCP client.
192.168.1.70 was transmitting a response but unexpectedly client sends the next request (packet #411), and after that W5500 goes down with socket status 0x28.