FreeRTOS+TCP How do I reconnect?

Hello

I am using EK-RA6M3 to test TCPIP communication with FreeRTOS + TCP.
The following functions are executed repeatedly.
FreeRTOS_accept()
FreeRTOS_setsockopt()
FreeRTOS_recv()
FreeRTOS_send()
FreeRTOS_shutdown()
vPortFree()
FreeRTOS_closesocket()

If the client disconnects during FreeRTOS_recv(), it jumps to prvTaskExitError().

If I stop debugging and run it again, I cannot connect with FreeRTOS_accept().
When I stop debugging and then run it again, I cannot connect with FreeRTOS_accept().
I cannot connect even when I power cycle the board, but I can connect by restarting the PC.

Please let me know if you know the correct procedure for stopping.

Thank you in advance.

@taki

Which version of FreeRTOS+TCP are you using?

Please let me know if you know the correct procedure for stopping.

After calling FreeRTOS_shutdown(), are you making sure that shutdown is completed by calling FreeRTOS_recv to see if it returns -pdFREERTOS_ERRNO_EINVAL.

You can take a look at this sample usage here in the FreeRTOS_Plus_TCP_Minimal_Windows_Simulator - SimpleTCPEchoServer.c.

Thank you for reply.

I can’t call FreeRTOS_shutdown() because it jumps to prvTaskExitError().

If I turn off the power without doing shutdown, what should I do the next time I turn it on?

Which version of FreeRTOS+TCP are you using?
v4.0.0

thank you

If the client disconnects during FreeRTOS_recv(), return value is -pbFREERTOS_ERRNO_ENOTCONN.

Please tell me how to avoid jumping to prvTaskExitError().

Can you try updating the FreeRTOS+TCP version to v4.2.0 and check.

I understand.I will try.

”If the client disconnects during FreeRTOS_recv(), return value is -pbFREERTOS_ERRNO_ENOTCONN.”
Can you tell me if this is correct?

thank you

The reason of jumping to prvTaskExitError is because you cannot exit from a task. If you are done with the task you are supposed to call vTaskDelete. See this call in the example @tony-josi-aws has shared - FreeRTOS/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Minimal_Windows_Simulator/DemoTasks/SimpleTCPEchoServer.c at main · FreeRTOS/FreeRTOS · GitHub.

Thank you for reply.

Program does not proceed to vTaskDelete().

I was able to confirm up to FreeRTOS_recv() return “lBytes = -128”.
If I then step, it jumps to prvTaskExitError().

How can I call vTaskDelete()?

thank you

I updated to FreeRTOS-Plus-TCP v4.2.0.

When I build I get over 50 errors.

It will take some time to check the operation.

Thank you.

I am getting the following message and cannot post, so I am replying to your email.

This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.

I updated to FreeRTOS-Plus-TCP v4.2.0.

When I build I get over 50 errors.

It will take some time to check the operation.

Thank you.

@taki

Yes, pdFREERTOS_ERRNO_ENOTCONN is returned if either the connection has been closed or in the process of closing, ie, waiting for a connection termination request or waiting for a connection termination request acknowledgement from the remote TCP.

refer

I am getting the following message and cannot post, so I am replying to your email.

This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.

Now you should be able to reply here. The site is not in read only mode anymore.

Thank you for your reply.
I understand.

If the return value is correct, I want to call FreeRTOS_shutdown() without jumping to prvTaskExitError().

Thank you.

As I mentioned before, take a look at this example - FreeRTOS/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Minimal_Windows_Simulator/DemoTasks/SimpleTCPEchoServer.c at main · FreeRTOS/FreeRTOS · GitHub.

Can you share your complete task code?

I am getting the following message and cannot post, so I am replying to your email.

This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.

Thank you for reply.

Program does not proceed to vTaskDelete().

I was able to confirm up to FreeRTOS_recv() return “lBytes = -128”.
If I then step, it jumps to prvTaskExitError().

How can I call vTaskDelete()?

thank you

I upload my code.

new_thread0_entry.c (6.3 KB)

Sorry to bother you, but please check my code.

thank you

When you create a task, you supply the task function and that function needs to be:

  1. Either an infinite loop that never exits.
  2. Or needs to call vTaskDelete at some point.

Example for 1:

void TaskFunction( void * params )
{
    ( void ) params;

    for( ;; )
    {
        /* Perform task functions. */

        /* Delay for a second. */
        vTaskDelay( pdMS_TO_TICKS( 1000 ) );
    }
}

Example for 2:

void TaskFunction( void * params )
{
    ( void ) params;

    /* Perform task functions. */

    /* Delete the task as we no longer need it. */
    vTaskDelete( NULL );
}

One of the break statements in your code causes it to exit the task function which is the cause of the error. Here is the updated code - new_thread0_entry.c (5.9 KB). Hope that helps.

Thanks for reply.

I confirmed that the code you provided works.

Thank you very much.