Embedded Artists


We are the leading providers of products and services around prototyping, evaluation and OEM platforms using NXP's ARM-based microcontrollers.

You are viewing an older revision! See the latest version

LPC4088DM Using Ethernet

The display modules come with 100/10Mbps Ethernet, RJ45 connector and unique MAC address.

The MAC address is unique (read from an onboard EEPROM with EUI-48) between the display modules. The actual address is retrieved by the Ethernet Interface through the mbed_mac_address() function in the mbed SDK, which is handled in the DMSupport library. No special setup needed.

Ethernet Interface

The DMSupport library contains mbed's official EthernetInterface library providing DHCP as well as UDP and TCP sockets. For more information about the Ethernet Interface, read the page in the handbook.

The Ethernet Interface is not handled by init() in DMBoard so it must be done in user code. One example using DHCP:

#include "EthernetInterface.h"
...
EthernetInterface eth;
...
void foo() {
  RtosLog* log = DMBoard::instance().logger();
  log->printf("EthernetInterface Setting up...\n");
  if(eth.init() != 0) {
     log->printf("EthernetInterface Initialize Error\n");
     mbed_die();
  }
  while (eth.connect() != 0) {
     Thread::wait(1000);
  }

  // Now see what the DHCP server assigned us
  log->printf("IP Address is %s\n", eth.getIPAddress());
  log->printf("NetMask is %s\n", eth.getNetworkMask());
  log->printf("Gateway Address is %s\n", eth.getGateway());
  log->printf("MAC Address is %s\n", eth.getMACAddress());
}


And with a static IP address:

#include "EthernetInterface.h"
...
EthernetInterface eth;
...
void foo() {
  RtosLog* log = DMBoard::instance().logger();
  log->printf("EthernetInterface Setting up...\n");
  if(eth.init("192.168.0.10", "255.255.255.0", "192.168.0.1") != 0) {
     log->printf("EthernetInterface Initialize Error\n");
     mbed_die();
  }
  while (eth.connect() != 0) {
     Thread::wait(1000);
  }
}


HttpServer

The DMSupport library contains a fork of the HttpServer library by Yasushi TAUCHI as well as mbed's official mbed-rpc library as it is needed by the HttpServer.

The reason for forking the HttpServer and not using it directly is to replace all direct calls to printf with the thread safe RtosLog as well as adding some caching to improve performance on slower connections.

The Http server start function will run forever, so the code should be executed in it's own thread like this:

#include "EthernetInterface.h"
#include "HTTPServer.h"
#include "mbed_rpc.h"

void netTask(void const* args)
{
  RtosLog* log = DMBoard::instance().logger();

  log->printf("EthernetInterface Setting up...\n");
  if(eth.init() != 0) {
     log->printf("EthernetInterface Initialize Error\n");
     mbed_die();
  }
  while (eth.connect() != 0) {
     Thread::wait(1000);
  }

  // Now see what the DHCP server assigned us
  log->printf("IP Address is %s\n", eth.getIPAddress());
  log->printf("NetMask is %s\n", eth.getNetworkMask());
  log->printf("Gateway Address is %s\n", eth.getGateway());
  log->printf("Ethernet Setup OK\n");

  // Allow the server to handle the "/hello" URL by responding with "Hello world !"
  HTTPServerAddHandler<SimpleHandler>("/hello"); //Default handler

  // Allow the server to read files from the file system so that the URL "/myfile.txt" 
  // will return the contents of the myfile.txt on the inserted USB memory stick.
  FSHandler::mount("/usb", "/");
  HTTPServerAddHandler<FSHandler>("/");

  // Now that all is configured, run the server forever waiting for connections on
  // port 80
  HTTPServerStart(80);
}

void main() {
  ...
  Thread tNetwork(netTask, NULL, osPriorityNormal, 8192);
  ...
}



All wikipages