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:
- open serial port and register rx callback
- set MAC, static/dinamic IP and stuff on W5500
- listen TCP port
- an external client connect to TCP port
- external client send a command (ex: “:12345”) length is not fixed
- W5500 get data and send it to serial port
- 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