Tcp server FreeRTOS simulation

Hi,
I tested on two different network.
Home network, 192.168.1.20 freertos, 192.168.1.9 for laptop.
Mask 255.255.255.0.
Work network 192.168.1.20 freertos
192.168.10.120 laptop (from DHCP)
The mask should be 255.255.240.0.
Maybe there is incompatibility. But first connection works.
The receiver works always. The sender stops sending after few trasmissions.
The client connects to server and send a request send data, after that the server enables the sender thread to send data.
What you should see on the client is an image with a track bar.

Hello @Marbro1965, I checked the link to RemoteDesktopWpf, but those are sources that run on a laptop.

In stead, I would like to compile the project that runs FreeRTOS. I downloaded RtosWin32, and it has many sources, but what I miss is the project files *.sln and *.vcxproj.*. Can you share them?

Ok.
I have understood.
The better way is to clone the project in a temporary directory, then copy all the content in FreeRTOSv202212.00/FreeRTOS/Win32-MingW/. And open with Eclipse 2023-09.
Excuse me, it was the starting project, so I added files an remove not to loose the link for correct compilation. I am new to this and it looks easy.
Otherwise from eclipse import project into workspace selecting rtoswin32.
But I tried just now and there are problems with paths and link. So the first solution is easier.
Thank you very much

Although it sounds complicated to run your FreeRTOS project, I will give it a try.

Here below a few more questions / remarks:

The mask should be 255.255.240.0.
Maybe there is incompatibility. But first connection works.

It probably works because you laptop has a netmask of 255.255.240.0.

The receiver works always. The sender stops sending after few transmissions.

As a side note, wouldn’t you rather handle the sending and receiving from within a single task?

The sender thread works for the first two times after the client closes connection then FreeRTOS_send fails returning a negative number.

Of course it would be interesting to know which negative number is returned. Please see projdefs.h to find a list of used errno values.

Single thread was the first version, it had the same problems. I move to two threads to try to isolate the problem. So now I know it is only in the sender side.
The returning value is -12.
It’s not complicated. I was able.
Just copy all in the win32-mingw.
I am looking for the error, where you told me to do.
Suppose everything is ok from the program side. Should be a pcap problem?

pdFREERTOS_ERRNO_ENOMEM 12
)))))
Interesting, but why.
I still was not able to vPrintResourceStats,
maybe I disabled it in some way.
Regards

I tried for a long time to get the ‘RtosWin32’ project compiled and running. The message error: 'string' is not a member of 'std' was one too much. Also I had to add many include directories.

pdFREERTOS_ERRNO_ENOMEM means that a call to pvPortMalloc() has failed. When that happens, the TCP connection can not continue.

Please check the behaviour of malloc/free in you application. It sounds like there is a memory leak.

Hi,
I am sorry. Do not waste time, please.

You make me feel guilty.

I have seen some of your post where you talk about memory heap and so far…
Let’s close this ticket.
String is not a member of Std is very nice message.
I have to work also with the sharing of the project. It is not good that’s so difficult to compile.
Best

Don’t worry, it was my own decision to try to compile your project.

But as your application running out of heap. I would investigate that. You are using heap_5.c, which is perfect. But can you change the allocation and use one big block of e.g. 256 KB, which is 4-byte aligned?

    #define configTOTAL_HEAP_SIZE    ( 256 * 1024 )
    static uint32_t ulHeap[ configTOTAL_HEAP_SIZE / 4 ];
    const HeapRegion_t xHeapRegions[] =
    {
        /* Start address and size */
        { ( uint8_t * ) ulHeap, sizeof( ulHeap ) },
        { NULL, 0 }
    };

And if it still runs out of memory, please check all calls to pvPortMalloc() and vPortFree(): see if there is a leak.

Also, as you’re using C++, make sure that the operators new and delete are defined to use the FreeRTOS heap. Make sure that the clib functions malloc()and free() are not called indirectly. You can define them and put a break in the function, just to test.

void * malloc( size_t length )
{
    _nop();  /* Put a break here */
}

Have a good weekend

Thank you very much.
I will try all suggestion.
For now one update:
If I define ipconfigUSE_TCP_WIN 0
it works. So your diagnoses is correct. There is a memory problem.
I defined in main.c vApplicationMallocFailedHook but never jump inside. Maybe I miss something.
The return value is -12.
I am using c++, I will check operators new and delete. It’s not very clear what to do. Probably need to study.
Thank you very much. Have a nice weekend too.

Definitely you are a master.
The ulHeap definition solved the problem , ipconfigUSE_TCP_WIN 1 is necessary otherwise too sloop.
Will be a nice weekend. Very :+1:

If I define ipconfigUSE_TCP_WIN 0
it works. So your diagnoses is correct. There is a memory problem.

It looks like it, yes. You can configure TCP buffer and WIN sizes using the socket option FREERTOS_SO_WIN_PROPERTIES.

As you understand, ipconfigUSE_TCP_WIN determines whether the TCP sliding windows are being used.

Remember that your WireShark sees every packet two times. Something may be wrong with the OS’s configuration.

I defined in main.c vApplicationMallocFailedHook but never jump inside. Maybe I miss something.

The problem is that vApplicationMallocFailedHook() will only be called when configUSE_MALLOC_FAILED_HOOK is defined:

    #if ( configUSE_MALLOC_FAILED_HOOK == 1 )
    {
        if( pvReturn == NULL )
        {
            vApplicationMallocFailedHook();
        }
    }

Most modern compilers will only include code for functions that are actually called. But in cases where the compiler is not so smart, configUSExxx configuration items are introduced to help keeping the code small.

The return value is -12.

Which is equal to pdFREERTOS_ERRNO_ENOMEM ( see include/projdefs.h ).

I am using c++, I will check operators new and delete. It’s not very clear what to do. Probably need to study.

    void * operator new(size_t size)
    {
        return pvPortMalloc( size );
    }
    
    void * operator new[]( size_t size )
    {
        return pvPortMalloc( size );
    }

    void operator delete( void * ptr )
    {
        vPortFree ( ptr );
    }
    
    void operator delete[]( void * ptr )
    {
        vPortFree ( ptr );
    }

I normally define the above operators globally. They will be called in all occasions where they’re used, explicitly or implicitly.

The thing is that pvPortMalloc()/vPortFree() are safe to be used in FreeRTOS tasks. The standard operators new()/delete()will probably call malloc()/free()` which may or may not be protected against re-entrance.

Thank you very much.

Welcome. I hope that you will enjoy using FreeRTOS as we do. Feel free to ask more questions in this forum.

Remind that for every function you can find a description and examples by googling for instance “FreeRTOS vTaskDelay”.