Hello,
as highlighted in 2015 and 2018,
forums freertos org t freertos-accept-does-not-return-unless-timed-out-stm32f7 7122
following the tutorial example
freertos org FreeRTOS-Plus FreeRTOS_Plus_TCP TCP_Networking_Tutorial_TCP_Client_and_Server html
I came to launch this program.
int main( void )
{
BaseType_t xReturn = pdFALSE;
/*
*Initialise the RTOS's TCP/IP stack. The tasks that use the network
* are created in the vApplicationIPNetworkEventHook() hook function
* below. The hook function is called when the network connects.
* */
FreeRTOS_IPInit( ucIPAddress,
ucNetMask,
ucGatewayAddress,
ucDNSServerAddress,
ucMACAddress );
xReturn = xTaskCreate( vCreateTCPServerSocket,
( const char * ) "GB",
configMINIMAL_STACK_SIZE*5,
NULL,
tskIDLE_PRIORITY + 1,
&xRxTask );
/*
* Other RTOS tasks can be created here.
*/
/* Start the RTOS scheduler. */
vTaskStartScheduler();
/* If all is well, the scheduler will now be running, and the following
line will never be reached. If the following line does execute, then
there was insufficient FreeRTOS heap memory available for the idle and/or
timer tasks to be created. */
for( ;; );
}
/***************************************************************************/
void vCreateTCPServerSocket( void * pvParameters ) {
struct freertos_sockaddr xClient, xBindAddress;
Socket_t xListeningSocket, xConnectedSocket;
socklen_t xSize = sizeof(xClient);
static const TickType_t xReceiveTimeOut = portMAX_DELAY;
const BaseType_t xBacklog = 20;
/* Attempt to open the socket. */
xListeningSocket = FreeRTOS_socket(FREERTOS_AF_INET,
FREERTOS_SOCK_STREAM, /* SOCK_STREAM for TCP. */
FREERTOS_IPPROTO_TCP);
/* Check the socket was created. */
configASSERT(xListeningSocket != FREERTOS_INVALID_SOCKET);
/* If FREERTOS_SO_RCVBUF or FREERTOS_SO_SNDBUF are to be used with
FreeRTOS_setsockopt() to change the buffer sizes from their default then do
it here!. (see the FreeRTOS_setsockopt() documentation. */
/* If ipconfigUSE_TCP_WIN is set to 1 and FREERTOS_SO_WIN_PROPERTIES is to
be used with FreeRTOS_setsockopt() to change the sliding window size from
its default then do it here! (see the FreeRTOS_setsockopt()
documentation. */
/* Set a time out so accept() will just wait for a connection. */
FreeRTOS_setsockopt(xListeningSocket, 0,
FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof(xReceiveTimeOut));
/* Set the listening port to 10000. */
xBindAddress.sin_port = (uint16_t) 10000;
xBindAddress.sin_port = FreeRTOS_htons(xBindAddress.sin_port);
/* Bind the socket to the port that the client RTOS task will send to. */
FreeRTOS_bind(xListeningSocket, &xBindAddress, sizeof(xBindAddress));
/* Set the socket into a listening state so it can accept connections.
The maximum number of simultaneous connections is limited to 20. */
FreeRTOS_listen(xListeningSocket, xBacklog);
for (;;) {
/* Wait for incoming connections. */
xConnectedSocket = FreeRTOS_accept(xListeningSocket, &xClient, &xSize);
configASSERT(xConnectedSocket != FREERTOS_INVALID_SOCKET);
/* Spawn a RTOS task to handle the connection. */
xTaskCreate(prvServerConnectionInstance, "EchoServer", usUsedStackSize,
(void *) xConnectedSocket,
tskIDLE_PRIORITY,
NULL);
}
}
/****************************************************************/
static void prvServerConnectionInstance( void *pvParameters )
{
int32_t lBytes, lSent, lTotalSent;
uint8_t cReceivedString[ ipconfigTCP_MSS ];
Socket_t xConnectedSocket;
static const TickType_t xReceiveTimeOut = pdMS_TO_TICKS( 5000 );
static const TickType_t xSendTimeOut = pdMS_TO_TICKS( 5000 );
TickType_t xTimeOnShutdown;
ulConnectionCount++;
xConnectedSocket = ( Socket_t ) pvParameters;
FreeRTOS_setsockopt( xConnectedSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
FreeRTOS_setsockopt( xConnectedSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeOut, sizeof( xReceiveTimeOut ) );
for( ;; )
{
/* Zero out the receive array so there is NULL at the end of the string
when it is printed out. */
memset( cReceivedString, 0x00, sizeof( cReceivedString ) );
/* Receive data on the socket. */
lBytes = FreeRTOS_recv( xConnectedSocket, cReceivedString, sizeof( cReceivedString ), 0 );
/* If data was received, echo it back. */
if( lBytes >= 0 )
{
lSent = 0;
lTotalSent = 0;
/* Call send() until all the data has been sent. */
while( ( lSent >= 0 ) && ( lTotalSent < lBytes ) )
{
lSent = FreeRTOS_send( xConnectedSocket, cReceivedString, lBytes - lTotalSent, 0 );
lTotalSent += lSent;
}
if( lSent < 0 )
{
/* Socket closed? */
break;
}
}
else
{
/* Socket closed? */
break;
}
}
/* Initiate a shutdown in case it has not already been initiated. */
FreeRTOS_shutdown( xConnectedSocket, FREERTOS_SHUT_RDWR );
/* Wait for the shutdown to take effect, indicated by FreeRTOS_recv()
returning an error. */
xTimeOnShutdown = xTaskGetTickCount();
do
{
if( FreeRTOS_recv( xConnectedSocket, cReceivedString, ipconfigTCP_MSS, 0 ) < 0 )
{
break;
}
} while( ( xTaskGetTickCount() - xTimeOnShutdown ) < tcpechoSHUTDOWN_DELAY );
/* Finished with the socket and the task. */
FreeRTOS_closesocket( xConnectedSocket );
vTaskDelete( NULL );
}
After successfully pinging and assigning the port I perform all the steps and put the zedboard (I am using) in the listening condition, at this point I launch the FreeRTOS_accept() (as showed in the code) command, at this point the pointer goes in the idle task not recognizing the client … I’m simulating the client first with iperf then with ncat. I need support