# FreeRTOS + UDP + TCP

**URL:** <https://forums.freertos.org/t/freertos-udp-tcp/6806>\
**Category:** Kernel\
**Created:** [October 12, 2017, 1:53pm UTC](https://forums.freertos.org/t/freertos-udp-tcp/6806 "2017-10-12T13:53:17Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 12, 2017, 1:53pm UTC](https://forums.freertos.org/t/freertos-udp-tcp/6806/1 "2017-10-12T13:53:17Z")

</div>

**[gwesp](https://sourceforge.net/u/gwesp/)** wrote on [Thursday, October 12, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/ad4689e8/#c666):

Hi,

We’re trying to add TCP and UDP to a project. We noticed that there are huge differences in files that are required  
for both, e.g. FreeRTOS\_DHCP.c, including differing function signatures.

How can we resolve this situation? Is the combination of UDP and TCP supported or can you use only one  
of both?

We’re evaluating FreeRTOS version 9.0.0.

Thanks and kind regards  
–Gerhard Wesp  
KISS Technologies GmbH

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [October 12, 2017, 2:01pm UTC](https://forums.freertos.org/t/freertos-udp-tcp/6806/2 "2017-10-12T14:01:22Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, October 12, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/ad4689e8/#c666/63f2):

The FreeRTOS+TCP stack available from the labs download (or the FreeRTOS  
SVN repository) has both TCP and UDP. Take a look at the features list  
and API in the tables at the bottom of the following page:  
[http://www.freertos.org/FreeRTOS-Plus/FreeRTOS\_Plus\_TCP/index.html](http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/index.html)

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 12, 2017, 3:55pm UTC](https://forums.freertos.org/t/freertos-udp-tcp/6806/3 "2017-10-12T15:55:11Z")

</div>

**[gwesp](https://sourceforge.net/u/gwesp/)** wrote on [Thursday, October 12, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/ad4689e8/#c666/63f2/1b3c):

Thanks for your quick reply. I see I wasn’t specific enough in my description.

We’re currently targetting the LPC1830 Xplorer board. For this, we use the example from  
FreeRTOS-Plus/Demo/FreeRTOS\_Plus\_UDP\_and\_CLI\_LPC1830\_GCC from FreeRTOSv9.0.0 .  
This works very well, but it doesn’t include TCP.

Now when we add the FreeRTOS+TCP stack (I downloaded version 160919\_FreeRTOS\_Labs)  
you mentioned, I see now that it does indeed include UDP as well. Still, we cannot use it  
for the LPC1830 example above because some files are duplicate and have huge diffs. One  
example is:

diff ./160919\_FreeRTOS\_Labs/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS\_DHCP.c ./FreeRTOSv9.0.0/FreeRTOS-Plus/Source/FreeRTOS-Plus-UDP/FreeRTOS\_DHCP.c  
[--\> results in ca 1000 diff lines, including changed function prototypes]

The question is how to resolve these ‘merge conflicts’. Any suggestions would be greatly  
appreciated.

Actually, for the time being we’d be fine with TCP alone but we need it on the LPC1830.

Thanks and kind regards  
–Gerhard Wesp  
KISS Technologies GmbH

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [October 12, 2017, 3:57pm UTC](https://forums.freertos.org/t/freertos-udp-tcp/6806/4 "2017-10-12T15:57:57Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, October 12, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/ad4689e8/#c666/63f2/1b3c/a41a):

The UDP and TCP products are different (or, at least, the TCP product is  
an extension of the UDP product that is now different) - remove all the  
FreeRTOS+UDP code and add the FreeRTOS+TCP code - then you will have  
both UDP and TCP.

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [October 12, 2017, 4:41pm UTC](https://forums.freertos.org/t/freertos-udp-tcp/6806/5 "2017-10-12T16:41:58Z")

</div>

**[heinbali01](https://sourceforge.net/u/heinbali01/)** wrote on [Thursday, October 12, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/ad4689e8/#f400):

Hi Gerhard, once upon a time, there was `FreeRTOS_Plus_UDP`. This library could only do UDP, DHCP and ICMP(echo).  
A couple of years ago, this stack was re-engineered and extended with a few more protocols, and it was called renamed to `FreeRTOS+TCP`. The name `+TCP` is possibly misleading, it should have been called `FreeRTOS+UDP+TCP+DHCP+ICMP+FTP+HTTP+NBNS+LLMNR+etc` 🙂

In other words, what you should do is forget about the `FreeRTOS_Plus_UDP`, and work with `FreeRTOS+TCP`.

The two stack use the same principles, and they have the same kind of interface. Both stacks use a single IP-task that does all the work.

When working with `FreeRTOS+TCP`, start simple. Disable DHCP at first and give your device a fixed IP address. Try to ping it, and when that works, try DHCP and other protocols.

When you have questions, please post them here, in this thread.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 13, 2017, 7:40am UTC](https://forums.freertos.org/t/freertos-udp-tcp/6806/6 "2017-10-13T07:40:11Z")

</div>

**[gwesp](https://sourceforge.net/u/gwesp/)** wrote on [Friday, October 13, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/ad4689e8/#f400/b5f9):

Thanks Hein,

that sounds like a plan. Since the API closely resembles the BSD sockets, I suppose we can  
do what RTE suggested and just replace-merge the FreeRTOS+TCP files into the LPC1830 example.

Best  
–Gerhard

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [October 13, 2017, 10:44am UTC](https://forums.freertos.org/t/freertos-udp-tcp/6806/7 "2017-10-13T10:44:59Z")

</div>

**[heinbali01](https://sourceforge.net/u/heinbali01/)** wrote on [Friday, October 13, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/ad4689e8/#1db4):

> just replace-merge the FreeRTOS+TCP files into the LPC1830 example

Right, remove the entire UDP stack, and include the +TCP stack.

I will attach the current driver for LPC18 here below ( see `LPC18xx_2017_oct.zip` )

It is a zero-copy driver, so please add the following to your `FreeRTOSIPConfig.h`

```auto
    #define ipconfigZERO_COPY_RX_DRIVER 1
    #define ipconfigZERO_COPY_TX_DRIVER 1

```

A few parameters to tune are the following:

```auto
    #define configNUM_RX_DESCRIPTORS 6
    #define configNUM_TX_DESCRIPTORS 4
    #define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 15

```

And later on, you may want to tune some TCP parameters, [as describer here](http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/API/setsockopt.html)

The “quad” flash in the LPC18 that I used was a bit slow, and I placed some frequently-used functions in RAM:

```auto
    #ifndef configPLACE_IN_SECTION_RAM
        #define configPLACE_IN_SECTION_RAM __attribute__ ((section(".ramfunc")))
    #endif

    /* Move func() to RAM: */
    configPLACE_IN_SECTION_RAM void func()
    {
    }

```

The .LD file contains the `.ramfunc` entry, in the `RamLoc96` section:

```auto
    /* Main DATA section (RamLoc96) */
    .data : ALIGN(4)
    {
       FILL(0xff)
       _data = . ;
       *(vtable)
       *(.ramfunc*)
       *(.data*)
       . = ALIGN(4) ;
       _edata = . ;
    } > RamLoc96 AT>SPIFI_4MB

```

If you have a fast flash, there is no need to move code to RAM.

Good luck!

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 13, 2017, 5:42pm UTC](https://forums.freertos.org/t/freertos-udp-tcp/6806/8 "2017-10-13T17:42:48Z")

</div>

**[gwesp](https://sourceforge.net/u/gwesp/)** wrote on [Friday, October 13, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/ad4689e8/#d490):

Thanks a lot, Hein! We’ll definitely check that out. From our UDP example it didn’t appear that  
we’re particularly CPU bound, but it’s always good to have options.

Best  
–Gerhard

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [October 15, 2017, 5:36am UTC](https://forums.freertos.org/t/freertos-udp-tcp/6806/9 "2017-10-15T05:36:03Z")

</div>

**[heinbali01](https://sourceforge.net/u/heinbali01/)** wrote on [Sunday, October 15, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/ad4689e8/#dc67):

> From our UDP example it didn’t appear that we’re particularly CPU bound

As you probably know, the Ethernet layer needs two components:

1. Ethernet Media Access Controller (EMAC)
2. Ethernet PHY

The EMAC is often an internal peripheral of the CPU. A PHY is an external component. The EMAC and PHY communicate through a high-speed bus, MDIO or a newer protocol.

Both FreeRTOS\_Plus\_UDP as well as FreeRTOS+TCP need a driver for these two components. This driver exists of a `xxx/NetworkInterface.c` file and some (modified) drivers provided by the chip manufacturer.

I recently started to split-up the PHY-driver and make a generic driver that should work on all boards. As soon as it is well-tested, I will publish it here on this forum.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 24, 2017, 4:31pm UTC](https://forums.freertos.org/t/freertos-udp-tcp/6806/10 "2017-10-24T16:31:40Z")

</div>

**[gwesp](https://sourceforge.net/u/gwesp/)** wrote on [Tuesday, October 24, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/ad4689e8/#dc67/e2bc):

OK, let us know when you have any updates. We were able to integrate your network driver into our project with some minor modifications (Chip\_ENET\_Init() function takes two arguments) and now working on a driver for our PHY (DP83822 on our final target hardware). Thanks a lot.
