---
title: "W5500 TCP transparent bridging"
url: "https://maker.wiznet.io/forum/15104"
markdown_url: "https://maker.wiznet.io/forum/15104/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "fabry"
created: "2023-12-29T09:15:43+09:00"
last_activity: "2023-12-30T10:45:38+09:00"
language: "en"
views: 173
replies: 3
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# W5500 TCP transparent bridging

## Question

Asked by fabry on 2023-12-29 in Ethernet Chips.

Hello,

I am writing a bare metal application for STM32F411 that uses W5500 to perform data exchange operations with the serial port.

One of these “modes” is a transparent mode where I open a listening TCP port and transfer what I receive to the serial. Consequently, everything that is sent from the serial must also be sent to the socket.

In general the flow is the following:

1. open serial port and register rx callback

2. set MAC, static/dinamic IP and stuff on W5500

3. listen TCP port

4. an external client connect to TCP port

5. external client send a command (ex: “:12345”) length is not fixed

6. W5500 get data and send it to serial port

7. serial port get bytes and send it back to socket, answer may vary in length and no termination characters are presents
   back to 5. until connection is closed

May happen that socket send a command that has no answer from serial, so it’s possible to send a command again.

My code snippets are the following:

```
while(1)
      	  			  {

      	  				  if((sockStatus = getSn_SR(CLIENT_SOCKET)) == SOCK_ESTABLISHED)
      	  				  {
      	  					  uint8_t remoteIP[4];
      	  					  uint16_t remotePort;


      	  				    		getsockopt(CLIENT_SOCKET, SO_DESTIP, remoteIP);
      	  				    		getsockopt(CLIENT_SOCKET, SO_DESTPORT, (uint8_t*)&remotePort);

      	  				        	  				    		while(1)
      	      	  				    {

      	      	  							len = recv(CLIENT_SOCKET, (uint8_t *)buffer_rx, MAX_TCP_OUT_BYTE);

      	      	  							if (len < MAX_TCP_OUT_BYTE-1)
      	      	  							{
      	      	  								strncpy( out_string, (char *)buffer_rx, len);
      	      	  								out_string[len] = '\0';
      	      	  								
      	      	  								UART_Printf(&huart2,"%s", out_string);  
      	      	  							}
      	      	  				    }

      	  					  break;
      	  				  }
      	  				  else { 
      	  					  break;
      	  				  }
      	  			  }
```

Callback for serial

```
void HAL_UART_RxCpltCallback_mcu(UART_HandleTypeDef *huart2)
{

	HAL_UART_Receive_DMA(huart2, Rx_data_mcu, 1);
	switch (mode)
	{
		case TRANSPARENT:
		{
			  
			  if(sockStatus = getSn_SR(CLIENT_SOCKET) == SOCK_ESTABLISHED)
			  {
				  send(CLIENT_SOCKET, Rx_data_mcu[0], 1);

			  }
			  

			  break;
		}
```

From socket to serial it works, but from serial to socket not.
I am clearly missing something.
Can anyone give me some help?

Thank you

## Replies

### Reply 1 by Eugeny, 2023-12-29

![](https://avatars.discourse-cdn.com/v4/letter/f/c77e96/48.png) fabry:

> From socket to serial it works, but from serial to socket not.

This is not enough. You must say what does not work (from user or process perspective) and/or how it does not work, as it is expected you have performed initial troubleshooting and research on the issue.

### Reply 2 by fabry, 2023-12-29

Ok, i try

After open the connection i try to send to W5500 the following string
![immagine](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/c/c1c194c1a79a3ad1d60b2b1d0023959c9a9426dd.png)

The W5500 get correctly the data and send it to the UART

[![immagine](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/d/dd70462f9a5ecc74634e3e08c0f929f7d164a766.png) immagine1007×495 22.5 KB](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/d/dd70462f9a5ecc74634e3e08c0f929f7d164a766.png)

The execution continue looping to the previous blocking instruction, and i think the problem is here.

```
len = recv(CLIENT_SOCKET, (uint8_t *)buffer_rx, MAX_TCP_OUT_BYTE);
```

Now if i write data to the UART by opening a serial terminal, i have that the instruction

![immagine](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/9/901195237e896056522a99a1bbc8b67785acd54f.png)

```
	  if(sockStatus = getSn_SR(CLIENT_SOCKET) == SOCK_ESTABLISHED)
```

assign to sockStatus values that can be “0”, “72” and “23”.

In case the instruction

```
send(CLIENT_SOCKET, Rx_data_mcu[0], 1);
```

is executed from the uart rx routine handler, the recv instructions becomes unlocked and return always a not zero length.

I hope I have provided clear information

### Reply 3 by Eugeny, 2023-12-30 (in reply to reply 2)

If `recv` unblocks then either there’s data received or there is an error.
Before doing anything else please review W5100 datasheet chapter 5 to ensure you know what you are doing, and also see how you can properly do the things.

---

Source: https://maker.wiznet.io/forum/15104
