FreeRTOS Echo Server application

Hello all,

I have 2 questions, the first is how one can figure out the type of heap an example application is using, in this case the example Freertos echo server project for vitis.

The second question is about the implementation of the pvPortMalloc, in my understanding im allowed to instantiate a pointer buffer using this function, this also frees or reserves the area for future use, for example -

RxBufferPtr = (uint8_t*)pvPortMalloc(sizeof(uint8_t)*MAX_PKT_LEN)

is this a more complete substitute for
RxBufferPtr = (uint8_t*)_dma_spw_section
(where dma spw section is a 32 bit aligned address in memory.)?

When I instantiate a bufferptr using the latter my xilinx dma simpletransfer succesfully transmits data even though it is garbled since its not a dynamically allocated memory buffer and being overwritten by something in freertos. The former also works however all data is 0.

@matricir

I have 2 questions, the first is how one can figure out the type of heap an example application is using, in this case the example Freertos echo server project for vitis.

Are you referring to the FreeRTOS heap allocation implementation out of the five sample memory allocation implementations provided? If thats the case, you can check which heap file is included for build in your project from the folder: <path to FreeRTOS-kernel root folder>/portable/MemMang. If you are using a pre-built binary of FreeRTOS kernel, you might need to refer to the build files for that binary to see which implementation is used; otherwise, in debug mode, try stepping in to any of the calls to pvPortMalloc to see which file is used for its definition.

Refer to FreeRTOS heap memory management - FreeRTOS™ for understanding pvPortMalloc/vPortFree.

RxBufferPtr = (uint8_t*)pvPortMalloc(sizeof(uint8_t)MAX_PKT_LEN)
is this a more complete substitute for
RxBufferPtr = (uint8_t
)_dma_spw_section

What is the use case RxBufferPtr? The alignment of memory returned by pvPortMalloc depends on portBYTE_ALIGNMENT (byte alignment requirement for memory allocation on the target hardware platform) this alignment might be different from the alignment requirement required by the MAC/network interface DMA descriptors.

If you have specific alignment requirement imposed by the hardware take a look at this page: https://www.freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/05-Buffer-management

Buffer allocation scheme 1 allows implementation of vNetworkInterfaceAllocateRAMToBuffers() which should allocate network buffers with approppriate aligment requirements.

Example Zynq: FreeRTOS-Plus-TCP/source/portable/NetworkInterface/Zynq/NetworkInterface.c at main · FreeRTOS/FreeRTOS-Plus-TCP · GitHub

1 Like

One thing to note, if there is a specific chunk of memory that the DMA can/will access, then pvPortMalloc may not be suitable if it doesn’t allocate out of that section. You likely need to allocate a buffer of the right size at the location that the DMA is configured for.

1 Like

Thank you for your answer my girst question has been resolved, its the heap_4.c that is being used. As for the second question it seems that dynamically allocated heap cant be used for dma buffers for one reason or another perhaps as the other comment mentions this. I will create a static heap at the area my DMA.

Hi thanks for your reply, I was able to solve this problem, it was a very simple issue, of course I was using the wrong input buffer thus introducing data to my output buffer.

Thank you for reporting back.