mbed RPC with W5500 Ethernet Shield

This post shows how to use mbed RPC with W5500 Ethernet Shield and how to port an Ethernet application used lwIP to W5500Interface.

Remote Procedure Call

In computer science, a remote procedure call (RPC) is an inter-process communication that allows a computer program to cause a subroutine or procedure to execute in another address space (commonly on another computer on a shared network) without the programmer explicitly coding the details for this remote interaction.
http://en.wikipedia.org/wiki/Remote_procedure_call

RPC
*source – http://uw714doc.sco.com/en/SDK_netapi/rpcpD.how_RPC_works.html

HW – FRDM-KL25Z + W5500 Ethernet Shield

FRDM-KL25Z + W5500 Ethernet Shield
http://developer.mbed.org/platforms/KL25Z/
http://developer.mbed.org/components/W5500-Ethernet-Kit-for-IoT/
HW connection : D10 – SCS / D11 – MOSI / D12 – MISO / D13 – SCLK

SW – mbed RPC

Server that executes remote procedure call (RPC) commands through HTTP.
mbed RPC @developer.mbed.org/handbook
In RPC libaray, a simple HTTP Server can execute RPC commands sent from HTTP Client.
This library uses EthernetInterface (lwIP) and mbedOS.

RPC command

The RPC command is encoded in this way :

  • container that wraps a skeleton’s ID
  • method that will be invoked
  • parameters that will be inputted (optional)
    • Command examples
      PUT command : “/DigitalOut/new?arg=LED2&name=led2”
      GET command : “/led2/write?arg=1”

Request handlers

To process requests, the server relies on RequestHandler. Each RequestHandler is assigned to a request type. Each type of request is assigned to a certain role :

  • PUT requests to create new objects
  • DELETE requests to delete objects
  • GET requests to call a function of an object

Porting EthernetInterface to W5500Interface

Here is a guide how to modify :

  • Folk HTTP-Server in you program workspace
  • Delete 2 Folders; EthernetInterface(lwIP) & mbed-rtos in HTTP-Server
  • Added array for MAC Address which was written at Source Hardware Address Register in W5500.
    uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02};`
    
  • Change EthernetInterface() and set SPI Interface for W5500
        /*  Use EthernetInterface
         *EthernetInterface eth;
         *if(eth.init())
         *int ret = eth.init("192.168.77.34", "255.255.255.0", "192.168.77.1");    
         */
        /* ----- Use W5500 Ethernet Shied -----*/
        SPI spi(D11, D12, D13);      /* mosi, miso, sclk */
        //spi.frequency(12500000); /* Optional : set proper SPI clock */
        EthernetInterface eth(&spi, D10, D9); /* spi, cs, reset(dummy) */
        ...
        /* ----- Use W5500 Ethernet Shied -----*/
    
  • Set Network configuration: I will use fixed Address.
        /*  in case of using W5500 Ethenret Shield */
        int ret = eth.init(mac_addr, "192.168.77.34", "255.255.255.0", "192.168.77.1");    
        /* in case of using W550io (has a unique real MAC address) */
        //int ret = eth.init("192.168.77.34", "255.255.255.0", "192.168.77.1");   
    

Repository : Users » embeddist » Code » HTTP-Server_W5500Interface

http://developer.mbed.org/users/embeddist/code/HTTP-Server_W5500Interface/

Demo – Using a browser for HTTP Client

Here is a quick guide how to run this program :

  • Compiles this program and copies it to the mbed
  • Open TeraTerm (install it if you don’t have it), select serial and choose the port named “mbed Serial Port”
  • Reset your mbed
  • The IP address should appear in teraterm. In this example, I will use 192.168.77.34
    Terminal
  • Open your browser and go to http://192.168.77.34
    connecttingl
  • If everything is ok, you should see a webpage.

  • Create Red LED as arg=LED1 and name=RLED
    RGB LED
    Create Red LED

  • To procedure, send command: RLED/write 0
    Reset Red LED

  • To procedure, send command: RLED/write 1
    Reset Red LED

Advertisements

SDFileSystem for mbed platfrom

This post shows how to use SDfile System on W5500 Ethernet Shield for mbed platfrom.

SDFile System

A library to allow SD Cards to be accessed as a filesystem, using a SPI interface

SDFileSystem @developer.mbed.org/handbook

This library supports:
– Fat12/ FAT16 / FAT32
– SD / SDHC cards up to 32Gb

HW – W5500 Ethernet Shield with MicroSD Slot

W5500 Ethernet Shield

W5500 Ethernet Shield

  • ARM mbed compatible operation
  • Arduino Pin-compatible
  • Ethernet (W5500 Hardwired TCP/IP chip)
  • MicroSD Slot
  • Ethernet port
  • I2C I/F
  • UART I/F

W5500 Ethernet Shiel Pin Map

W5500 Ethernet Shiel Pin Map

  • SPI Bus support Arduino and mbed platfrom
    MOSI MISO SCK
    D11 D12 D13
    MOSI(ICSP-4) MISO(ICSP-1) SCLK(ICSP-3)
  • SPI_CS and SD_CS pins are allowed to select as below,

    • SPI_CS : D8 / D9 / D10
    • SD_CS : D4 / D5 / D6

SW1 – SDFile System for LPC824 Xpresso (mbed platform)

/**  import SDFiles System Library **/
#include "mbed.h"
#include "SDFileSystem.h"

/*for LPC824 Xpresso */
SDFileSystem sd(D11, D12, D13, D6, "SD"); // the pinout on the mbed Cool Components workshop board
int main() {
    printf("Hello World!n");   
    mkdir("/SD/mydir", 0777);
    FILE *fp = fopen("/SD/mydir/sdtest.txt", "w");
    if(fp == NULL) {
        error("Could not open file for writen");
    }
    fprintf(fp, "Hello fun SD Card World!");
    fclose(fp); 
    printf("Goodbye World!n");
}

SW2 – SDFile System for FRDM-KL25Z (mbed platform)

/**  import SDFiles System Library **/
#include "mbed.h"
#include "SDFileSystem.h"

/*for FRDM-KL25Z */
SDFileSystem sd(D11, D12, D13, D4, "SD"); // the pinout on the mbed Cool Components workshop board
int main() {
    printf("Hello World!n");   
    mkdir("/SD/mydir", 0777);
    FILE *fp = fopen("/SD/mydir/sdtest.txt", "w");
    if(fp == NULL) {
        error("Could not open file for writen");
    }
    fprintf(fp, "Hello fun SD Card World!");
    fclose(fp); 
    printf("Goodbye World!n");
}

Demo.

Notice: SD card name shoud be same variable in sd(mosi, miso, clk, “SDname”).
* Serial terminal
minicom
* Check SD card by using card reader
read SD card
* Confirm stdtest.txt
read SD card