Kinetis K60/66 with FreeRTOS+TCP/IP


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

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:

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.

I am trying to get a K66 development board here.
It is recommended to take an existing driver 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:

    #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.

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?
        // 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);
    ENET_ReadFrame(ENET, handle, NULL, 0);


Thank you!