# Kinetis K60/66 with FreeRTOS+TCP/IP

**URL:** <https://forums.freertos.org/t/kinetis-k60-66-with-freertos-tcp-ip/10006>\
**Category:** Libraries\
**Created:** [June 10, 2020, 5:04pm UTC](https://forums.freertos.org/t/kinetis-k60-66-with-freertos-tcp-ip/10006 "2020-06-10T17:04:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matikitorch](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@Matikitorch](https://forums.freertos.org/u/Matikitorch)\
**Post date:** [June 10, 2020, 5:04pm UTC](https://forums.freertos.org/t/kinetis-k60-66-with-freertos-tcp-ip/10006/1 "2020-06-10T17:04:54Z")

</div>

Hello,

I want to begin by saying I’m fairly new at this, apologize in advance for any dumb questions. I am attempting to use the FreeRTOS Ethernet stack on the K66 chip from NXP. I have the RTOS working, switching task, the whole job. However, I am now trying to add the TCP/IP stack from FreeRTOS and am having an extremely hard time.

Is there some sample code that I can use? I am not very familiar with MAC controllers and what’s portable and what is not. I got the external PHY initialized and working (tested this with another project, it is a KSZ8041TL). Any help is appreciated.

Thank you

---

<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:** [June 10, 2020, 7:18pm UTC](https://forums.freertos.org/t/kinetis-k60-66-with-freertos-tcp-ip/10006/2 "2020-06-10T19:18:47Z")

</div>

Hopefully somebody will post a driver, but in the mean time, just wanted to check you had seen these pages, which I suspect you have but don’t want to assume: [https://freertos.org/FreeRTOS-Plus/FreeRTOS\_Plus\_TCP/FreeRTOS\_TCP\_Porting.html](https://freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/FreeRTOS_TCP_Porting.html)

---

<div class="post-metadata">

**Author:** ![Matikitorch](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@Matikitorch](https://forums.freertos.org/u/Matikitorch)\
**Post date:** [June 10, 2020, 7:28pm UTC](https://forums.freertos.org/t/kinetis-k60-66-with-freertos-tcp-ip/10006/3 "2020-06-10T19:28:05Z")

</div>

I have seen that, Richard, thank you though. I was attempting to write my own porting code, but ran into a lot of roadblocks. Towards the end I was just guessing and didn’t know what I was doing.

---

<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:** [June 11, 2020, 7:02am UTC](https://forums.freertos.org/t/kinetis-k60-66-with-freertos-tcp-ip/10006/4 "2020-06-11T07:02:31Z")

</div>

I am trying to get a K66 development board here.  
It is recommended to take an [existing driver](https://github.com/FreeRTOS/FreeRTOS/tree/master/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface) as an example, such as the one for STM32Fxx.

That driver uses an object `xPhyObject`, that recognises and initialises the PHY. It doesn’t need to be configured: it checks all 32 addresses and it recognises all major 100 Mbps Ethernet PHY’s.

In the first instance, I would use a static IP-address ( DHCP disabled ). See `FreeRTOSConfig.h` of any demo application, which has:

```auto
    #define configIP_ADDR0 192
    #define configIP_ADDR1 168
    #define configIP_ADDR1 1
    #define configIP_ADDR1 101

```

among other defines.

Once the PHY is working, you could check on a laptop if your board is sending ARP requests every 20 seconds.  
The next test would be to send a ping to the board. See if the ARP + ICMP messages are received.  
If you want, you can always attach your ( zipped ) source code to your post and I will check it.

---

<div class="post-metadata">

**Author:** ![Matikitorch](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@Matikitorch](https://forums.freertos.org/u/Matikitorch)\
**Post date:** [June 11, 2020, 2:35pm UTC](https://forums.freertos.org/t/kinetis-k60-66-with-freertos-tcp-ip/10006/5 "2020-06-11T14:35:40Z")

</div>

Hi Hein,

Thank you for your input. I did try to convert the STM32Fxx portable code into Freescale land, I just didn’t know enough back then to know what I was doing, so I kind of gave up. I’m going to go back now though and give it an honest attempt now that I am more knowledgeable on all of this.

If you don’t mind looking at this code. This was my extremely crude implementation of the Ethernet Rx ISR. I was wondering if I got the concept correct or if I’m off here.

The function `ENET_ReadFrame` is a Freescale library that copies the data over to whatever pointer you give it, along with the length. Note that I am not doing any zero-copy interface. Does this look OK?

The other big question I have is with the struct `NetworkBufferDescriptor_t`, in the help documentation it mentions to only fill out 2 members, `xDataLength ` and `pucEthernetBuffer`, but within that struct, there are other things, like port, bound port, IP address, etc. Do all of these need to be filled out by the NetworkInterface.c code? The member `pucEthernetBuffer`, does it point to the beginning of the Ethernet packet, the MAC header? Or the start of the data?

```
void xNetworkInterfaceInput(ENET_Type *base, enet_handle_t *handle, enet_event_t event, void *userData)
{
  NetworkBufferDescriptor_t *pxNewBuffer;
  IPStackEvent_t xRxEvent;
  uint32_t len;

  if(event == kENET_RxEvent)
  {
    while(ENET_GetRxFrameSize(handle, &len) == kStatus_Success)
    {
      // Check the length first
      if(len == 0)
      {
        // 0 size packet?
      }
      else
      {    
        // Get a buffer from FreeRTOS
        pxNewBuffer = pxGetNetworkBufferWithDescriptor(ipTOTAL_ETHERNET_FRAME_SIZE, (TickType_t)0);

        // Read the frame
        ENET_ReadFrame(ENET, handle, pxNewBuffer->pucEthernetBuffer, len);
        pxNewBuffer->xDataLength = len;

        // Set up the event
        xRxEvent.eEventType = eNetworkRxEvent;
        xRxEvent.pvData = (void*)pxNewBuffer;

        xSendEventStructToIPTask(&xRxEvent, (TickType_t)0);
      }
    }
  }
  else
  {
    ENET_ReadFrame(ENET, handle, NULL, 0);
  }

  return;
}

```

Thank you!
