9 years, 11 months ago.

FRDM-K64F: EthernetInterface TCPSocketServer board crash

Hello,

This simple program systematically ends in a board crash (green led stops flashing) after a few transmissions are made from a client.

Overview: the main thread initiates a server thread, and then proceeds with flashing the green led. A VB.NET client program then sends data packets to the server, but eventually causes a crash that stops the main thread from executing, leaving the led steady, either off or on, until the board is reset.

Thanks in advance for any pointers as to why this might happen.

DG

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

void server_thread(void const* arg) {
    TCPSocketServer server;
    
    server.set_blocking (true);
    server.bind(11000);    
    server.listen(1);

    while (true) {
        TCPSocketConnection client;

        int ret = server.accept(client);
        
        if (ret == 0) {
            char buffer[1024];
            while (true) {
                int n = client.receive(buffer, sizeof(buffer));
                
                if (n < 0)
                    break;
            }
        }

        client.close();
    }
}

DigitalOut heartbeatLed(LED_GREEN);

int main(void) {
    EthernetInterface eth;
    eth.init();
    eth.connect();    
    
    Thread server(&server_thread);
    
    while(true){
      Thread::wait(1000);
      // Heartbeat.
      // The board systematically crashes after a low number of sends from a client,
      // e.g. ~10 times 1000 bytes, ~2-3 times 10000 bytes, etc.
      heartbeatLed = !heartbeatLed;
    }
}

VB.NET console program used to send data to the board:

Imports System.Net
Imports System.Net.Sockets
Imports System.Text

Public Class SynchronousSocketClient

    Public Shared Sub Main()
        Dim ipAddress As New IPAddress(New Byte() {192, 168, 100, 140})
        Dim remoteEP As New IPEndPoint(ipAddress, 11000)
        Dim sender As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)

        ' Connect the socket to the remote endpoint.
        sender.Connect(remoteEP)
        sender.ReceiveTimeout = 1000 'In ms.

        ' 1000 chars.
        Dim msg As Byte() = Encoding.ASCII.GetBytes(StrDup(100, "1234567890"))

        ' Send the data through the socket.

        Dim sw As New Stopwatch()
        sw.Start()

        Dim bytesSent As Integer = sender.Send(msg)

        sw.Stop()

        Dim ms As Long = sw.ElapsedMilliseconds
        Console.WriteLine("Elapsed: " + ms.ToString + " ms.")

        ' Release the socket.
        sender.Shutdown(SocketShutdown.Both)
        sender.Close()

        Console.ReadKey()
    End Sub

End Class

Hello, thanks for sharing code. We will try to reproduce this issue.

posted by Martin Kojtal 17 May 2014

Additional information: 1. The board also crashes when being ping'ed, typically after 4 to 6 successful attempts. 2. To rule out the possibility of an internal clock frequency "oddity", I've used an oscilloscope to confirm that it is indeed accurate. 3. C++ is not my cup of tea, so do scrutinize my sample code.

posted by D G 19 May 2014

Hello. Any news? I've updated my projects with the latest mbed, mbed-rtos and EthernetInterface libraries, with no luck. Even the TCPEchoServer program cause a board freeze after about a dozen 100 bytes echoes. Is is just happening on the K64F? I'll ditch the board, just tell me on which platform it works. Thanks.

posted by D G 03 Jun 2014

Martin: thanks! It now works with EthernetInterface rev. 40 and mbed-src rev. 222.

posted by D G 06 Jun 2014
Be the first to answer this question.