Zynq/FreeRTOS/lwip confusion

krbvroc1 wrote on Wednesday, January 18, 2017:

I am trying to come up to speed with this environment and have confused myself.
I am using the FreeRTOS 8.2.3 and LWIP1.4.1 that comes with Vivado (came with my Zybo [Zynq 7010] trainer board).

lwip says to use the RAW API for high performance TCP which I want to do. I planned on running the lwip it its own thread. The lwip RAW API examples
show a simple mainloop design that would appear to chew up 100% CPU in a tight loop polling for packets to process. I would seem a better design to invoke the receiver
from the DMA ISR (or use a task notification / semaphore) so it is interrupt / DMA driven.

It seems that in order to use the RAW API I have to define my lwip with NO_SYS even though I am running with FreeRTOS. (That is how vivado configured it).
I understand I will need to limit my interaction with lwip to a single thread and use FreeRTOS to communicate with the thread.

The very first thing I notice is that lwip says to create its threads using a sys_thread_new() call. If I am reading the lwip/Xilinx library correctly, that appears to be a wrapper for pthread_create().
How is that going to work with FreeRTOS and using xTaskCreate() and trying to communicate using a queue or task notify between the two. On the surface it doesn’t make sense and the whole thing is
confusing. Or do I ignore the lwip docs and use xTaskCreate() for my single lwip task – perhaps sys_thread_new is only when using socket/netconn API. I really just want to let lwip run in a single task and interact
with that task via the FreeRTOS stuff described in the book like task notifications, event groups, etc.

rtel wrote on Wednesday, January 18, 2017:

Not an expert of lwIP, but it was not originally designed to run
multi-threaded, so what you are saying is not a surprise. We have run
it that way too - so long as you only use the code from one thread it works.

Don’t ignore the lwIP docs. You need to use a FreeRTOS port layer so
sys_thread_new() calls xTaskCreate(). Xilinx have one, as do we, in
fact if you use the SDK wizard to create a FreeRTOS project you have the
option of adding lwIP into the mix too. Alternatively the main FreeRTOS
download has an lwIP example for the Zynq
(http://www.freertos.org/RTOS-Xilinx-Zynq.html) and we have our own
multi-threaded TCP running on the Zynq too:
http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCPIP_FAT_Examples_Xilinx_Zynq.html

krbvroc1 wrote on Wednesday, January 18, 2017:

I guess this is why I am confused. I used the SDK to create a FreeRTOS project and I added in the lwip to the BSP settings and I generated the FreeRTOS hello world example that the SDK creates for me. So far that is all I have done and the examples passes.

I would think the Xilinx SDK would have handled this. But when I look at the lwipopt include file it has NO_SYS set (and there is no mention of OS_IS_FREERTOS). I would think both of those would need to be set for the FreeRTOS layer to be present that you mention. But then the lwip documentation talks about RAW API mode is for standalone without an OS. I got the impression that FreeRTOS port layer is only for the higher level socket/netconn API, not the RAW API. That is why I was thinking maybe for RAW API only I should use xTaskCreate() and run the lwip stuff in that task. Since it is single threaded it should not be creating or communicating with any other tasks.

I don’t know if I have the liberty to use the FreeRTOS+TCP and I know I need to support multiple (x3) netif.

heinbali01 wrote on Thursday, January 19, 2017:

If you decide to use lwIP, why not the latest 2.0.0 version ?

FreeRTOS+TCP has recently been extended with the possibility to use multiple interfaces (NIC’s). That works well with IPv4 sockets. That version has not been released officially, but anyone is welcome to try out this beta release.

FreeRTOS+TCP is simple to use as it only offers a BSD socket interface and API’s. It does have optimisations like zero-copy send()/recv().

rtel wrote on Thursday, January 19, 2017:

There is an example integration here, but it is VERY OLD:
https://interactive.freertos.org/hc/en-us/community/posts/210028826-FreeRTOS-Win32-project-with-lwIP-web-server

krbvroc1 wrote on Thursday, January 19, 2017:

I did see that a 2.0.0 version of lwip was released but I thought it might be smarter to stick with what comes with the Xilinx SDK tools and with what they maintain rather than having to port something new.

Xilinx already provides the network driver layer (with DMA support) for the emacps and axiethernet MAC on 1.4.1. Does the FreeRTOS+TCP provide that currently for both those?

heinbali01 wrote on Friday, January 20, 2017:

FreeRTOS+TCP does not yet support ‘axiethernet’. If you write a networkInterface.c for it, you’ll will get free support from us :slight_smile:

epok13 wrote on Monday, February 06, 2017:

Hi,
This post just to say I ran into the same error type with Vivado 2016.4 and zynq’s ps7_ethernet.

It seems that OS_IS_FREERTOS definition is missing, but even when I manually define it (e.g. in lwipopts.h), I still obtain errors when creating a sample FreeRTOS LwIP echo server.

I’ll try manually dealing with RAW_API instead of SOCKET_API for now, as the sample echo server code for FreeRTOS seems to exclusively use sockets.

There seems to be an issue in Xilinx SDK configuration of LwIP socket + FreeRTOS. If I can’t get anywhere, I’ll go to Xilinx forums for help.