The Freedom-K64F is an ultra-low-cost development platform for Kinetis K64, K63, and K24 MCUs.

Does the recently updated EthernetInterface library work on the K64F platform

02 May 2014

Can anyone please confirm for me that the recently updated EthernetInterface library works on the FRDM-K64F platform?

I am presently struggling to get the TCPSocket_Helloworld example application to run. It hangs when init() is called.

Thanks, Cameron

05 May 2014

Same issue here. Does anyone "on the inside" know when this driver will be ready to go?

...kevin

14 May 2014

Hello guys,

we just updated the ethernet library which should include a fix for K64F. Please test and report back.

Regards,
0xc0170

14 May 2014

Thanks !

Where can I get the demo code ?

16 May 2014

I have imported this project today this today and it still hangs at the init().

16 May 2014

Sorry, it does work, it was just a bad Ethernet cable.

16 May 2014

Regardless,

Bad cable or not, the Ethernet driver shouldn't hang indefinitely. It should timeout with an error so your program can continue.

On another note regarding EthernetInterface and the K64F. If EthernetInterface is not part of your program, the mbed Linker gets 3 errors. Once added, the errors go away. You don't have to add an #include "EthernetInterface.h" statement, the driver just has to reside in your program to remove the Linker errors.

...kevin

19 May 2014

I still cannot get init() not to hang. I have link on both ends (according to the LEDs on each end). WireShark sees no packets ever leaving the K64F

...kevin

20 May 2014

Hi Kevin, After I found my bad cable it did not seem to work straight away so I deleted the "ethernet interface" folder from my TCPSocket_Helloworld project and re-imported it from here https://mbed.org/users/mbed_official/code/EthernetInterface/ It definately works now. Regards Chris

20 May 2014

Hi Chris,

hmmm... not for me. I believe that I was already using the version of EthernetInterface from your link above, but I deleted mine and added the one in the link anyway.

Are you using fixed IP or DHCP? What revision of mbed-rtos, mbed.lbr (or mbed-src) are you using?

...kevin

20 May 2014

Hi, I'm using dhcp. The mbed is plugged into a network switch. I'm assuming the latest mbed libs as I imported the TCP project complete and simply compiled and ran. Have you updated the k64f boot loader? That's the only other thing I have done in the last week. Regards Chris

20 May 2014

Chris,

That may be the issue. According to the link: http://mbed.org/handbook/Firmware-FRDM-K64F The firmware should be at 0202. After upgrading, the bootloader seems to still be at 0201. In fact, all 3 bootloader .bin files show the same result. I'll bring it with that link

Contents of bootloader.html after upgrade to 0202:

<!-- mbed Microcontroller Website and Authentication Shortcut -->
<!-- Version: 0201 Build: Feb 25 2014 16:50:21 -->
<html>
<head>
<meta http-equiv="refresh" content="0; url=http://mbed.org/device/?code_bl=0201B1130E650415EA68"/>
<title>mbed Website Shortcut</title>
</head>
<body></body>
</html>

...kevin

22 May 2014

I'm back Chris,

The bootloader ended up being ok. The TCPSocket_HelloWorld demo program works. So what could be different?

I looked at main.cpp of TCPSocket_HelloWorld and saw a couple of things that were different.

1. EthernetInterface eth; is called inside of int main() {...} instead at the top where the hardware declarations are made.

2. I use a lot of serial communications to the Host PC, since I have a CLI user interface. So I use Serial or RawSerial. This is where I found an issue. In the HelloWorld example, I added 4 lines:

#include "mbed.h"
#include "EthernetInterface.h"

RawSerial pc(USBTX, USBRX);  //<<added line

int main() {
    pc.baud(230400);        //<<added line
    EthernetInterface eth;
    eth.init(); //Use DHCP
    eth.connect();
    printf("IP Address-a is %s\n", eth.getIPAddress());
    printf("IP Address-b is %s\n", eth.getIPAddress());     //<<added line
    printf("IP Address-c is %s\n", eth.getIPAddress());     //<<added line
    
    TCPSocketConnection sock;
    sock.connect("mbed.org", 80);
    
    char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
    sock.send_all(http_cmd, sizeof(http_cmd)-1);
    
    char buffer[300];
    int ret;
    while (true) {
        ret = sock.receive(buffer, sizeof(buffer)-1);
        if (ret <= 0)
            break;
        buffer[ret] = '\0';
        printf("Received %d chars from server:\n%s\n", ret, buffer);
    }
      
    sock.close();
    
    eth.disconnect();
    
    while(1) {}
}

So far so good. The IP Address gets printed out 3 times and serial runs at 230400 baud

Now, if I change any or all of the printf statements to pc.printf, nothing works. The K64F is hung.

#include "mbed.h"
#include "EthernetInterface.h"

RawSerial pc(USBTX, USBRX);  //<<added line

int main() {
    pc.baud(230400);        //<<added line
    EthernetInterface eth;
    eth.init(); //Use DHCP
    eth.connect();
    printf("IP Address-a is %s\n", eth.getIPAddress());
    pc.printf("IP Address-b is %s\n", eth.getIPAddress());     //<<added line and changed to pc.printf
    printf("IP Address-c is %s\n", eth.getIPAddress());     //<<added line
    
    TCPSocketConnection sock;
    sock.connect("mbed.org", 80);
    
    char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
    sock.send_all(http_cmd, sizeof(http_cmd)-1);
    
    char buffer[300];
    int ret;
    while (true) {
        ret = sock.receive(buffer, sizeof(buffer)-1);
        if (ret <= 0)
            break;
        buffer[ret] = '\0';
        printf("Received %d chars from server:\n%s\n", ret, buffer);
    }
      
    sock.close();
    
    eth.disconnect();
    
    while(1) {}
}

Only made one additional change, and now it is dead. It doesn't matter which printf statement you change, it is frozen. It also doesn't matter whether you are using Serial or RawSerial.

There is a major conflict with the K64F, EthernetInterface and Serial. This all works on the mbed1768

...kevin

23 May 2014

Just tried to get a simple sample running - but no success. I reimported the libraries with the checkbox 'Update embeddd libraries to their latest version' and now compile failed with - Error: Identifier "TX_DESC_UPDATED_MASK" is undefined in "EthernetInterface/lwip-eth/arch/TARGET_K64F/k64f_emac.c", Line: 274, Col: 35 - Error: Identifier "TX_DESC_UPDATED_MASK" is undefined in "EthernetInterface/lwip-eth/arch/TARGET_K64F/k64f_emac.c", Line: 613, Col: 29

Regards Joerg

23 May 2014

@Joerg,

please always share a program/link or even a code snippet which we can use for testing. Thanks.

Guys, there was one bug we discovered and it should be fixed, at least in mbed-src. Thus if it's not working for you , for example init() fails, replace mbed lib by mbed-src.

23 May 2014

Thanks,

compiles now and does not stop the EthernetInterface after calling init().

Regards J.

26 May 2014

I had the same problem.

Error: Identifier "TX_DESC_UPDATED_MASK" is undefined in "EthernetInterface/lwip-eth/arch/TARGET_K64F/k64f_emac.c", Line: 274, Col: 35

    if (bdPtr[i].controlExtend2 & TX_DESC_UPDATED_MASK) { // descriptor updated by uDMA

I imported mbed-src and deleted mbed and compiled OK. I downloaded and ran and nothing on USB console or DHCP server. Since this is an out-of-the box FRDM-K64F and I'm using USB console and I had earlier got a version of blinky running earlier, I added some modifications to track the progress.

On running eth.init() completed after about a minute, but hung after that. It hung on either getting the IP address or on the eth.connect() and nothing showed on my DHCP server. When it hung, the ledGrn that was flashing stopped.

Output on COM11/USB was

TCPSocket_test
<ledGrn flashing, after 1min the following>
eth.initA MAC is 00:02:f7:f0:00:00
eth.initB MAC is 00:02:f7:f0:00:00
eth.initC MAC is 00:02:f7:f0:00:00  IP Addr=
<ledGrn stopped flashing>

TCPSocket_test01

#include "mbed.h"
#include "EthernetInterface.h"
 
RawSerial pc(USBTX, USBRX); 

Ticker sysTick;
DigitalOut ledRed(LED1);//Red
DigitalOut ledGrn(LED2); //
DigitalOut ledBlue(LED3); //
EthernetInterface eth;
    
void periodicTimer() {
    ledGrn = !ledGrn;
}

int main() {
    int cnt=30;

    pc.baud(115200);// 57600 115200 230400
    
    ledRed = ledGrn = ledBlue = 1; //off
   while(cnt--) { //Delay to allow TTY to be manually connected over USB
        ledBlue= 1;
        wait(0.1);
        ledBlue = 0;
        wait(0.1);
    }
    ledBlue =1;
    sysTick.attach(&periodicTimer, 1); 
    
    pc.printf("TCPSocket_test\r\n");
    eth.init(); //Use DHCP
    pc.printf("eth.init MAC is %s ", eth.getMACAddress());
    wait(1);
    pc.printf("eth.initB MAC is %s \n\r", eth.getMACAddress());
    wait(5);
    pc.printf("eth.initC MAC is %s ", eth.getMACAddress());
    wait(1);
    pc.printf(" IP Addr=%s\n", eth.getIPAddress());
    wait(0.1);
    eth.connect();

    pc.printf("IP Address-b is %s\n", eth.getIPAddress()); 
    pc.printf("IP Address-c is %s\n", eth.getIPAddress()); 
    
    TCPSocketConnection sock;
    sock.connect("mbed.org", 80);
    
    char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
    sock.send_all(http_cmd, sizeof(http_cmd)-1);
    
    char buffer[300];
    int ret;
    while (true) {
        ret = sock.receive(buffer, sizeof(buffer)-1);
        if (ret <= 0)
            break;
        buffer[ret] = '\0';
        pc.printf("Received %d chars from server:\n%s\n", ret, buffer);
    }
      
    sock.close();
    
    eth.disconnect();
    
    while (true) {
        ledRed = !ledRed;
        wait (0.5); // flip led
    }
}
28 May 2014

Hello,

I have the same problem, eth.init() is blocking for ever with FRDM-K64F.

(i tried with the last mbed library and also with mbed-src).

The folowing code works well with LPC1768 but not with FRDM-K64F.

#include "mbed.h"
#include "EthernetInterface.h"

#define PORT   80
#define DEBUG  1

char echoHeader[1024] = {};

Serial pc(USBTX, USBRX);

TCPSocketServer svr;
bool serverIsListened = false;

TCPSocketConnection client;
bool clientIsConnected = false;

char buffer[1024] = {};


extern "C" void mbed_mac_address(char * mac)
{

// define your own MAC Address
    mac[0] = 0x00;
    mac[1] = 0x01;
    mac[2] = 0x02;
    mac[3] = 0x03;
    mac[4] = 0x04;
    mac[5] = 0x06;

};

int main()
{
    pc.printf("start\n");
    EthernetInterface eth;
    eth.init("192.168.0.2","255.255.255.0","192.168.0.254"); 
    eth.connect();
    pc.printf("IP Address is %s\n", eth.getIPAddress());
    //setup tcp socket
    if(svr.bind(PORT)< 0) {
        pc.printf("tcp server bind failed.\n\r");
        return -1;
    } else {
        pc.printf("tcp server bind successed.\n\r");
        serverIsListened = true;
    }

    if(svr.listen(1) < 0) {
        pc.printf("tcp server listen failed.\n\r");
        return -1;
    } else {
        pc.printf("tcp server is listening...\n\r");
    }

    while (serverIsListened) {
        //blocking mode(never timeout)
        if(svr.accept(client)<0) {
            pc.printf("failed to accept connection.\n\r");
        } else {
#if DEBUG == 1
            pc.printf("connection success!\n\rIP: %s\n\r",client.get_address());
#endif
            clientIsConnected = true;

            while(clientIsConnected) {

                switch(client.receive(buffer, 1023)) {
                    case 0:
                        pc.printf("recieved buffer is empty.\n\r");
                        clientIsConnected = false;
                        break;
                    case -1:
                        pc.printf("failed to read data from client.\n\r");
                        clientIsConnected = false;
                        break;
                    default:
#if DEBUG == 1
                        pc.printf("Recieved Data: %d\n\r\n\r%.*s\n\r",strlen(buffer),strlen(buffer),buffer);
#endif
                        if(buffer[0] == 'G' && buffer[1] == 'E' && buffer[2] == 'T' ) {
#if DEBUG == 1
                            pc.printf("GET request incomming.\n\r");
#endif

                            sprintf(buffer,"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\"><html><head> </head><body>Hello World !!</body></html>");
                            sprintf(echoHeader,"HTTP/1.1 200 OK\n\rContent-Length: %d\n\rConnection: Close\n\r\n\r",strlen(buffer)+1);
                            pc.printf("Header :   %s\n\n",echoHeader);
                            pc.printf("Header sent : %u\n",client.send(echoHeader,strlen(echoHeader)));
                            pc.printf("Buffer : %s\n\n",buffer);
                            pc.printf("Buffer sent : %u\n",client.send(buffer,strlen(buffer)));
                            clientIsConnected = false;
                            break;
                        }

                }
            }
#if DEBUG == 1
            printf("close connection.\n\rtcp server is listening...\n\r");
#endif
            client.close();

        }
    }
    wait(5);
    eth.disconnect();
    while(1) {}
}

28 May 2014

Guys, @Patrik and @neil

a question for verification - what revision of mbes-src did you use ?

@Patrik, you allocate quite large buffers, have you checked your stack for any overflows? but if it works with LPC1768, might be with K64F which has large memory size available.

28 May 2014

I used the mbed-src updated yesterday (05/27/1014).

Concerning the buffer size, i already used buffer larger with this kind of program (using ethernet) and it works well with the LPC1768.

28 May 2014

I'm a newbie to mbed -how do i tell what version. As per the previous instructions, I imported mbed-src for it to be able to compile. (I'm well versed in source code control and use github, but need some pointers here) thanks

28 May 2014

TO get revision I do 1) Click on mbed-src folder in the online ide, and on the toolbar - revision. Click there to check what revision you are using..

I'm using revision 211 - 3days 3hrs ago So now I press update and take it to revision 217. Check revisions I see lots of updates to LPC and STM, but nothing jumps out for FRDM-K64 :)

30 May 2014

Update on EthernetInterface and pc.printf

I took out the comment on line 73: #define LWIP_DEBUG in file lwipopts.h and now pc.printf co-exists with EthernetInterface. Who knows why....

Now I get an IP address. There are two other issues remaining:

1. Pings stop after about 5 or 6, after an Ethernet connect() has been made. All of the other three RTOS threads I have are running normally. Only a hard reset will allow for a few more pings before failing again.

2. init() hangs forever if no cable is attached. There is a timeout in the mbed1768 that doesn't seem to exist in the K64F

...kevin

31 May 2014

Can you try this program http://mbed.org/users/sscaglia/code/K64F_Ether_Working/ and share the results with your application modifications?

31 May 2014

For me it does print everything ... no response to ping. I then changed it to my local network, and assigned it 10.0.0.30 Output was

Start
Init...
Connect
Server IP Address is 10.0.0.30:7

from my Win8 machine, tried ping and no response.

31 May 2014

The echo-client program in https://mbed.org/handbook/Socket#tcp-echo-client also hung. I had too the error reported by @neil. As of today and importing mbed-src, it works fine.

(PS: I am new to mbed, so I may have gotten the content of this thread wrong.)

31 May 2014

The echo-client program in https://mbed.org/handbook/Socket#tcp-echo-client also hung. I had too the error reported by @neil. As of today and importing mbed-src, it works fine.

(PS: I am new to mbed, so I may have gotten the content of this thread wrong.)

09 Jul 2014

Hello everybody, I am new to mbed and I am playing with a FRDM-K64F board. After some tests with the LEDs I am trying to make the Ethernet interface work. I tried some of the different examples in this thread but I still have some problems. First question at all: is there anybody that have the Ethernet working on this board? If yes can you kindly share a complete code example? At the moment I would like to work with the simpliest configuration at all: one Ethernet switch, my PC with IP address 192.168.0.1 and my board with IP address 192.168.0.2. Starting from an example taken from this thread this is my code:

include the mbed library with this snippet

#include "mbed.h"
#include "EthernetInterface.h"
#include "rtos.h"

const char ip[] = "192.168.0.2";
const char mask[] = "255.255.255.0";
const char gateway[] = "192.168.0.1";


int main() {
    DigitalOut led(LED_GREEN);
    EthernetInterface eth;
    Serial pc(USBTX, USBRX);
    
    pc.printf("Init...\r\n");
    pc.printf("eth.init = %i\r\n", eth.init(ip, mask, gateway));
    
    pc.printf("Connect...\r\n");
    pc.printf("eth.connect = %i\r\n", eth.connect(500));

    while(1) {
        led = !led;
        wait(0.2);
    }
}

I am able to ping the board but after the 500 ms timeout eth.connect returns -1 so an error happened. Any idea?

09 Jul 2014

Some more infos:

  • board firmware version is 0203
  • EthernetInterface revision is 41
  • mbed-rtos revision is 36
  • mbed revision is 86
09 Jul 2014

I was finally able to make the Ethernet interface work: here you are the code.

EthernetWorking.cpp

#include "mbed.h"
#include "EthernetInterface.h"
#include "rtos.h"

const char ip[] = "192.168.0.2";
const char mask[] = "255.255.255.0";
const char gateway[] = "192.168.0.1";


int main() {
    DigitalOut led(LED_GREEN);
    EthernetInterface eth;
    Serial pc(USBTX, USBRX);
    TCPSocketConnection socket;
    char buf[256];
    int n;
    
    pc.printf("Init...\r\n");
    pc.printf("eth.init = %i\r\n", eth.init(ip, mask, gateway));
    
    pc.printf("Connect...\r\n");
    pc.printf("eth.connect = %i\r\n", eth.connect(100));

    while (socket.connect("192.168.0.1", 1000) < 0) {
        pc.printf("Unable to connect to the server");
        wait(1);
    }
    
    char hello[] = "Echo;CIAO\r";
    socket.send_all(hello, sizeof(hello) - 1);

    n = socket.receive(buf, 256);
    buf[n] = '\0';
    pc.printf("%s", buf);
    
    while(1) {
    }    
    socket.close();
    eth.disconnect();
}

As you can see I lowered the timeout of the eth.connect call to 100 ms: the function ALWAYS returns -1 but the connection works. Have I to issue a bug report?

Please log in to post a reply.