FreeRTOS TCP Xilinx Zynq undefined functions

Hi. I am trying to add FreeRTOS TCP using Vitis 2023.1. I followed the instructions for adding TCP to FreeRTOS. All seems to be compiling except for undefined reference to ulApplicationGetNextSequenceNumber and xApplicationGetRandomNumber. I understand that these are functions to be provided by the application. What can be used for these for the Zynq?

I’ll answer my own question that the default method for these functions can be provided by the rand() functions. It seems that when this function used to be defined by macro that is what was used in the FreeRTOSIPConfigDefaults.h. This is one thing the instructions for setting up the FreeRTOS TCP don’t really cover. Otherwise, the instructions are quite good.

So I have written the functions like this:

#include <stdlib.h>

extern uint32_t ulApplicationGetNextSequenceNumber( 
    uint32_t ulSourceAddress,
    uint16_t usSourcePort,
    uint32_t ulDestinationAddress,
    uint16_t usDestinationPort )
    return rand();

extern BaseType_t xApplicationGetRandomNumber( uint32_t * pulNumber )
    *pulNumber = rand();

    return pdTRUE;

This is good enough that I have a working echo server now. Seems like if randomness is very important then some FPGA logic can be written to provide it.

Thank you for following up with your solution!
This should be helpful to anyone else who may have a similar question.

1 Like

It is important to note that you should not use rand in production and instead use some TRNG.

Maybe as a comparison, does anyone know what lwip uses for its random function? Xilinx Vitis comes bundled with lwip for baremetal and FreeRTOS. I have used lwip successfully in RAW mode but was running into bugs in socket mode with FreeRTOS, which is why I wanted to implement FreeRTOS TCP, which is working with no bugs so far. As another milestone I can implement something at least as good as lwip uses.

lwIP uses a macro LWIP_RAND() to get a random value. It allows you to define you own randomiser.

Note that the randomness is needed to become unpredictable. When available, I always use a TRNG (True Random Number Generator).

Note that the rand() function is quite predictable, and often it only returns 15 “random” bits.

I have used lwip successfully in RAW mode

I found it much harder to use raw mode, because it is not compatible with any other OS. FreeRTOS+TCP only has a single interface, which is BSD compatible.

FWIW I believe I found how Xilinx configures LWIP and they also use rand function. There also doesn’t seem any way to change other than modifying the library header which you generally don’t do in Vitis.

In bsp\ps7_cortexa9_0\libsrc\lwip213_v1_0\src\contrib\ports\xilinx\include\arch\cc.h

#define LWIP_RAND rand

I am hearing everyone’s suggestion though that it can be done better and taking to heart.

No arguments here :slight_smile: . That was with a previous project with no OS just main loop. I am happy to replace it with FreeRTOS TCP.