9 years, 9 months ago.

Frustrated with the FRDM-K64F

Hello,

On and off for the past month I've been trying to get a simple program (see below) working on a FRDM-K64F board. Almost every time I try the program it fails on the gEth.connect() function (line 42). On some rare occasions it does get past the connect() and things seem to work. I also have EA LPC4088 board and the example program works every time without issues.

I have been updating the relevant libraries as new releases are posted. However, the program behavior is still the same on the FRDM-K64F. I am ready to shelve the board unless I can get some insight into why it does not work.

Any help would be greatly appreciated!

include the mbed library with this snippet

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

#define LOCAL_ADDR  "195.0.0.6"
#define MASK        "255.255.255.0"
#define GATEWAY     "195.0.0.1"
#define PORT        4323

DigitalOut gLED1(LED1, 1);
DigitalOut gLED2(LED2, 1);
DigitalOut gLED3(LED3, 1);
DigitalOut gLED4(LED4, 1);
EthernetInterface gEth;
UDPSocket gSocket;

void CmdThread(const void * arg);
void HeartBeat(const void * arg);

extern "C" void mbed_mac_address(char *s);

Thread* gThreadCmd;
Thread* gThreadHeartBeat;
Timer gSysTimer;

int main() 
{
    puts("Starting\r\n");
    
    gSysTimer.start();

    puts("gEth.init\r\n");
    
    if (gEth.init(LOCAL_ADDR, MASK, GATEWAY) < 0)
    {
        error("FATAL Error: Ethernet Initialization Error\r\n");
    }

    puts("gEth.connect\r\n");
    
    if (gEth.connect(30000) < 0)
    {
        error("FATAL Error: Ethernet Connection Error\r\n");
    }
    
    puts("gSocket.bind\r\n");
    
    if (gSocket.bind(PORT))
    {
        error("FATAL Error: Unable to bind ALXT_MSG_PORT socket");
    }

    gSocket.set_broadcasting(true);
    gSocket.set_blocking(false, 2500);
    
    puts("Go!\r\n");

    Endpoint source;

    gThreadHeartBeat = new Thread(HeartBeat, NULL, osPriorityLow, DEFAULT_STACK_SIZE, NULL);

    gThreadCmd = new Thread(CmdThread, NULL, osPriorityLow, DEFAULT_STACK_SIZE*10, NULL);

    unsigned char receiveBuf[2048];
    
    while(1) 
    {
        int count = 0;
        
        count = gSocket.receiveFrom(source, (char*)receiveBuf, sizeof(receiveBuf));
        
        if (count == 0)
        {
            gLED4 = !gLED4.read();
        }
        else
        {
            printf("Recvd %d bytes from %s\r\n", count, source.get_address());
            gLED2 = !gLED2.read();
        }
    }
}

void HeartBeat(const void * arg)
{
    while (true)
    {
        gLED1 = !gLED1.read();
        gThreadHeartBeat->wait(250);
    }
}

void CmdThread(const void * arg)
{
    char cmdBuffer[256] = {0};
    unsigned int cmdBufferIndex = 0;
    char cmdChar;
    char cmd;
    USBSerial serial;
    char mac[6];

    while (true)
    {
        cmdChar = serial._getc();

        if (cmdChar == '\r')
        {
            cmd = cmdBuffer[0];

            switch(cmd)
            {
                case 'M':

                    mbed_mac_address(mac);

                    char macAddr[20];

                    sprintf(macAddr, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);

                    serial.printf("%c %s\r\n", cmd, macAddr);
                    break;

                default:
                    serial.printf("%c -1 \"Command <%s> is not valid\"\r\n", cmd, cmdBuffer);
                    break;
            }

            memset(cmdBuffer, 0, sizeof(cmdBuffer));
            cmdBufferIndex = 0;
        }
        else
        {
            if (cmdChar != '\n' && cmdBufferIndex < sizeof(cmdBuffer))
            {
                cmdBuffer[cmdBufferIndex++] = cmdChar;
            }
            else if (cmdBufferIndex >= sizeof(cmdBuffer))
            {
                ;
            }
        }
    }
}

Hello, have you debugged the application to find out why it stalls in connect() ? there's KDS exporter, KDS is free tool by Freescale, which could help you to find a root cause. Let us know if you find anything.

posted by Martin Kojtal 30 Jun 2014

I'm in a similar boat - I have simple server code that gets past init() and connect(), but if I specify a static IP address, I cannot connect(). I'm running EthernetInterface r43, mbed-rtos r40, NetworkAPI r8, and Socket r19.

posted by Dave M 05 Sep 2014

1 Answer

9 years, 9 months ago.

Hi Tom,

I am also in your boat. I have run into a few Ethernet issues myself and posted to other question threads. A couple things I've learned:

- Don't use library mbed-src newer than v223

- I've been using up-to-date EthernetInterface, but with this patch: http://mbed.org/users/loopsva/code/lwip-eth-patch/ I don't remember where I found this fix, but I just recently republished it. Throw away the original lwip-eth that comes with EthernetInterface. Without this patch, my TFTP server only transfers a couple packets before it times out.

- If you don't make it past init () or connect(), then either recompile or compile-all. Trying both gets the program to eventually work. It's frustrating, but this works for me.

...kevin

@ Kevin - Have you tried your program with up to date EthernetInterface ( http://mbed.org/users/mbed_official/code/EthernetInterface/ ) and also with mbed lib version 85? I would suggest using these since they are being updated regularly. Also - mbed-src mirrors the development of the mbed SDK on github and isn't guaranteed to be stable.

posted by Sam Grove 30 Jun 2014

Yes Sam,

I look for updates all the time for fixes. I am using v41 of EthernetInterface and the most current updates from mbed-src and mbed-rtos, but not mbed.lib. It's been a couple weeks since I checked mbed.lib, and it didn't work. I understand that mbed-src is not stable, but I still look anyway - hoping for a fix.

...kevin

Sam,

I just tried using mbed.lib v85 + generic EthernetInterface v41 (no wlip-eth patch) and everything works!! Thanks...

BTW I am using RTOS with 3 threads + main loop (with a lot of Mutex's to block I2C, USB printf's and SD Flash accesses), interrupt driven serial CLI interface, SD Flash, and a couple I2C devices. Pings still fail above 8k, but are ok below that size. K64F doesn't crash as before with oversize Pings, TFTP file exchanges are good too.

Now, if only Ethernet.link() would work without a compiler error...

...kevin

posted by Kevin Braun 30 Jun 2014

Hi Kevin,

Thanks for taking the time to help. I tried your suggestions but they did not work. The program still times out when it tries to connect. I'm not sure where to go from here.

Regards,

Tom

posted by Tom Doyle 30 Jun 2014

@Tom can you publish your program with all the dependencies? I tried with importing the latest and it seems to work although all it did was blink a LED and send the MAC address when I typed M <enter> in a console.

I made some small changes for my environment such as DHCP and Serial rather than USBDevice

@Kevin I see the same failure with ping > 8k. Will keep looking into that

posted by Sam Grove 30 Jun 2014

Sam.

The program has been published to the following:

http://mbed.org/users/tedoyle/code/Test-EthernetInterface-FDRM-K64F/

I updated the libraries as you suggested to Kevin above.

Regards,

Tom Doyle

posted by Tom Doyle 01 Jul 2014

Tom,

I ran your program. Very interesting. If I compile (modifying the IP, MASK and Gateway for me), I can never get past connect() like you. However, if I use DHCP, it works every time!! Even through many compile and compile_all's. It is totally reliable as long as you use DHCP.

I have seen weird things before with EthernetInterface and fixed IP addresses and not limited to the K64F. In my code, after I get an IP address, I do an NTP request so I can sync up the local RTC. The code accesses up to 4 different NTP servers before giving up. NTP accesses always work with DHCP and never work with a fixed IP. Go figure... I've seen it on the LPC4088QS and LPC1768 as well.

...kevin

posted by Kevin Braun 01 Jul 2014

Assigned to Sergio Scaglia 9 years, 9 months ago.

This means that the question has been accepted and is being worked on.