Hello All,
I have ported FreeRTOS-Plus-TCP to a Microcontroller based on ARM cortex M7 core.
I have Network buffers allocated in SRAM which is limited in size(640KB). Since this SRAM is shared by 2 Cortex M7 core and one Cortex M0 core, there is limitation as to how many Network Buffer I can allocate. To overcome this limitation, we decided to move the Network buffer out of SRAM and decided to put it in External Memory.
The CPU board has LPDDR4 memory which is 1GB in size. We tried to put these Network buffer in LPDDR4 memory but after putting it inside LPDDR4, we observe that after sometime we are losing control of the MCU( as in control is going to some unknown state).
I wanted to ask if there is any limitation as to whether we can put Network buffer outside of RAM or not.
If we can allocate the memory for Network buffer outside the RAM, then is there any other reason that might cause us to lose control of the core.
Can you share what device you are using? Usually the ethernet DMA peripheral can have requirements on where the buffers have to be allocated, these requirements might be architecture/HW implementation specific, have you checked if there is anything limiting you from placing the buffers in external RAM for your device.
Does your device support caching (for external RAM), if so, does changing the buffer placement in the RAM to uncached location or turning off caching help?
Thank you for the reply.
Actually, we have not yet implemented zero copy. So how our system is working is that Ethernet is copying the frame via DMA to Ethernet buffer which is placed in external RAM and in Ethernet Interrupt/Callback we are copying that data to statically allocated Network buffer which is placed in internal RAM.
Yes, we tried turning of Cache and configured MPU for the region in external RAM where we are trying to place the Network Buffer.
I was going through the below mentioned link that talks about the Network buffer allocation schemes and it keeps mentioning RAM where the buffer is allocated and wanted to check if there is some constraint in the FreeRTOS wherein we can allocate Network buffer only in internal RAM.
Hello akash, it will indeed be very helpful if you can convey on what platform you are working on.
Network buffers allocated in SRAM which is limited in size(640KB)
640 KB allow you to allocate 426 full-size Ethernet buffers! How many buffers are you planning for? In my applications, I will typically allocate 20 buffers.
TCP can be hungry for buffers when you use big sliding windows, or when the TCP socket needs a large buffer space. Both properties can be configure per-socket with the socket option FREERTOS_SO_WIN_PROPERTIES.
In my Zynq and Ultrascale projects I do store the network buffers in external DRAM, while caching is disable for that section, see uncached_memory.c.
It is very complicated to use the cache functions like flush and invalidate, although I did get it working for the Xilinx driver.
Thank you for your reply.
I’m Sorry, I did not understand what you meant by:-
“what platform you are working on.”
I will try to elaborate on the project though. I guess that part of information is missing.
So I’m trying to capture the ethernet frame which essentially carry image frame from PC .On MCU side, I’m taking those ethernet frame, extracting the image frame data and making a full image frame from it. Please note that one full image frame will ideally consist of roughly 50 or more frame. As the resolution and complexity of image increases, this number also increases and goes as high 300 ethernet frame and sometimes higher.
Coming back to my problem, in current setup, I have 330 network buffer available and with this I see that sometimes, ethernet frame is received but there is no free network buffer to store that frame.
For this reason, we were planning to move Network buffer out of internal RAM but in doing so we are facing another issue where we are losing the control of the core.
Good to know that storing network buffer in external RAM works fine as it worked fine for you.
Then probably I’m making some mistake while moving it to external memory.
I’m Sorry, I did not understand what you meant by:-
“what platform you are working on.”
Should be the target hardware you are working on. It would be easier to guide you better when it comes to the DMA RAM/Cache requirements if its possible for you to share the hardware (board/MCU) you are using.
I have 330 network buffer available and with this I see that sometimes, ethernet frame is received but there is no free network buffer to store that frame.
It doesn’t matter how much image frames you have, as you can copy the frames to the external RAM to process it later or till all frames are obtained, thus the network buffers can still be on the internal RAM. Once you have received the packets the network buffer will be released so that it can be used again. Are you using UDP/TCP? How are you receiving the data?
There should be no need to keep all the frames until the full image is acquired. Process the data in the frames as you get it and fill in a final (or maybe an intermediary) image structure as you get the data.
As such there is no restriction in FreeRTOS-plus-TCP stack whether external LPDDR4 or internal SRAM is used.
However, even before the packet is processed by stack (in Receive path), ethernet controller DMA will copy the data from HW port to the Software buffers and the other way around for Transmit path.
Here , you will need to check the following:
If the Ethernet controller DMA can access the external LPDDR4
If yes, then this access might not be enabled by default and will have to be enabled.
If the cahing is disabled for the LPDDR4 region which is being used for ethernet controller DMA (receive and transmit buffers)