2015년 7월 5일 일요일

DHCPAddressPrinter

DHCPAddressPrinter

Dynamic Host Configuration Protocol

DHCP의 자세한 내용은 아래의 링크를 참조한다.
Wikipedia:Dynamic Host Configuration Protocol

DHCP를 사용할때 필요한 개념들을 정성적으로 이해하고 실제로 Router(DHCP Server)와 ARMmbed Platform(DHCP Client)의 관계를 알아보자. 또한, 궁극적으로 ARMmbed Platform의 WIZnetInterface에서 어떻게 DHCP를 설정하고 사용하는 지 초점을 맞춘다.

DHCP 왜 사용하나?

  • Dynamic Host Configuration Protocol의 정의 처럼 동적으로 Host의 IP address를 설정하여 사용할 수 있도록한다.
  • 목적은 Network상에서 Network Administrator 과 일반 Network User가 manual로 설정을 줄이는 것이다.

우리가 일상생활에서 흔히 경험하는 가장 쉬운 예로 들어보자. Smart phone을 유무선공유기(Access Point)에 접속할때 AP의 SSID선택하고 Password 입력하면 “IP를 받아오는 중”이라는 는 문구를 볼 수 있다. 이것은 Smart Phone(DHCP Client)이 AP(DHCP Server)로 부터 IP address 할당 받는 것을 뜻한다.

우리는 DHCP server 부터 할당 받은 IP address가 무엇인지, 할당 받은 IP address를 언제까지 사용할 수 있는지 등과 같은 것들을 생각하지 않아도 된다. 이것이 DHCP를 사용하는 이유이다.

단지, 이때 주의해야 할 것은 AP가 WAN (Wide Area Network) Port로의 설정이 Internet이 가능하도록 설정되어 있냐는 것이다. AP로 부터 IP address를 할당받았으나 Google이나 Naver의 접속이 안되는 경우 즉, Internet이 안 될때가 이 경우이다. 이것을 이해하려면 공유기의 NAT기능을 알아야 한다.

  • Network Address Translation (NAT)
    일반적으로 공유기 NAT 기능을 지원한다. NAT는 Local network IP address와 Internet IP address를 Translation해주는 기능이다. 아래의 그림과 같이 NAT(공유기)는 DHCP server로 동작하여 Local network에 있는 모든 Host들에 대해 DHCP IP address를 할당한다. 그리고 NAT가 Internet Service Provider(ISP, 쉽게말해 KT, U+)로 부터 IP address를 할당 받았다면, 이 해당 NAT는 인터넷에 접속이 가능하다. 다시말하면, NAT에 연결된 모든 Host들은 Internet에 접속 할 수 있다.

    출처: http://www.h3c.com/portal/res/200808/06/20080806_659082_image001_613642_57_0.gif
    NAT의 구체적인 원리는 위의 그림에서 NAT table을 이해하면 좀 더 쉽게 알 수 있다. 이 NAT table은 Host(10.1.1.100:8)이 연결되어 있으며 외부의 Server(211.100.7.34:24)로 접속을 한 경우를 보여준다. Host는 DHCP IP address를 할당받아 Server에 자신의 Local IP address로 접속 할 수가 없다. 이때 Host는 NAT의 IP transtation기능을 이용하여 NAT의 IP address (162.105.178.65)를로 외부의 (WAN/Internet)에 연결되어 있는 Server에 접속이 가능해진다. 반대로 Server입장에서는 Host의 IP Address는 알 수 없고 NAT의 IP address만 인식할 수 있다.

How to use DHCP in WIZnetInterface ?

  • OS기반의 PC에서 DHCP를 설정한다면 아래와 같이 아주 간단하게 설정 할 수 있다.
      PC상에서 DHCP를 설정하기 일반적으로  WINDOWS를 쓴다면 아래의 그림과 같이 **제어판>>네트워크 및 인터넷>>네트워크 및 공유 센터>>로컬영역연열>>로컬영역상태>>속성>>Internet Protocol Version 4(TCP/IP속성)**에서 '자동으로 IP 주소 받기'를 클릭한다. 끝!
    
    2015-07-02_14-41-34

하지만, Embedded System의 경우 일일이 Developer가 설정해야 한다.

  • 이제부터 WIZnetInterface의 DHCP Client를 사용해보자
    • 준비단계
      • Network 구축: 공유기의 DHCP Server기능을 활성화하고 해당 공유기에 Target board(WIZwiki_W7500)와 PC를 연결한다.
      • DHCPClient코드/Library: WIZnetInterface에 DHCPClient Library를 포함하고 있다.
        dhcpdns

Do DHCPAddressPrinter

  1. Create New Program as DHCPAddressPrinter
    2015-07-03_09-35-41
  2. Confirm the created program (mbed: mbed.lib, main.c:blinky_led)
    2015-07-03_09-49-33
  3. Import WIZnetInterface by using Import Wizard:”https://developer.mbed.org/teams/WIZnet/code/WIZnetInterface/"(1)
    2015-07-03_09-51-36
  4. Set Import Library
    2015-07-03_09-56-16
  5. Confirm the imported WIZnetInterface library
    2015-07-03_09-57-27
  6. Make Codes
    2015-07-03_10-32-05
  7. Confirm COM port for mbed platform
    2015-07-03_10-49-53
  8. Set serial port for teraterm
    2015-07-03_10-51-10
  9. Display the IP address allocated from DHCP server
    2015-07-03_10-51-54
  10. Download bin files from WebIDE
    2015-07-03_10-54-44

Code Repository on ARMmbed

http://developer.mbed.org/users/embeddist/code/DHCPAddressPrinter/

Code

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

DigitalOut myled(LED1);

// Initialize the Ethernet client library
EthernetInterface eth;

int main() {
    // Enter a MAC address for your controller below.
    uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02}; 

    // initializing MAC address
    eth.init(mac_addr);

    // Check Ethenret Link
    if(eth.link() == true)
        printf("- Ethernet PHY Link-Done \r\n");
    else
        printf("- Ethernet PHY Link- Fail\r\n");

    // Start Ethernet connecting
    if ( eth.connect() < 0 )
        printf("Fail - Ethernet Connecing");
    else
    {
        // Print your local IP address:
        printf("IP=%s\n\r",eth.getIPAddress());
        printf("MASK=%s\n\r",eth.getNetworkMask());
        printf("GW=%s\n\r",eth.getGateway());
    }        

    while(1) {
        myled = 1;
        wait(0.2);
        myled = 0;
        wait(0.2);
    }
}

List of Ethernet Shield Tutorials for IoT platform

2015년 7월 1일 수요일

WIZwiki_W7500

Overview

WIZwiki-W7500은 WIZnet의 W7500을 기반으로한다. “Internet Offload Platform for IoT”을 표방하는 W7500 chip은 ARM Cortex-M0에 TCP/IP Offload Engine(TOE)를 SoC한 one-Chip Soulution이다. W7500은 TOE를 장착하고 있기 때문에 ARM Corte-M0로 Software TCP/IP의 지원없이도 Internet에 간단히 접속할 수 있습니다.

또한, WIZwiki_W7500은 Arduino Shield와 pin Compatible로 Arduino Shield를 사용하는데 용이하다. 그리고 CMSIS-DAP USB를 지원하여 ARM mbed Web-IDE에서 Programming과 Virtual-Serial Port를 지원하며, Keil/IAR의 IDE를 과는 Programming물론 Debugging이 가능하다.

Block Diagram

WIZwiki_W7500_block

WIZwiki_W7500은 그림과 같이 크게 W7500, CMSIS-DAP, Ethernet port(RJ45)+PHY 3부분으로 구성된다.

  • W7500

     ARM® Cortex™-M0 Core기반에 다수의 peripherals포함하고 있다.  다른 Vendor의 Microcontroller들과 차이점은 peripherals 중 MAC laye가 포함된 TCP/IP Offload Engine(TOE)를 탑재하고 있다는 것이다. 
    
  • CMSIS-DAP

      간단하게 Debugger Interface로 이해하면 된다. LPC11u35칩에 W7500의 program algorithm 내장한 CMSIS-DAP는 개발용 PC와 USB Cable를 통해 연결된다. 연결된 PC쪽에서는 WIZwiki_W7500 Board를 USB Drive인식 하도록 되어 있다. 물론 이를 위에 아래에 "How to write the firmware"참고하여 CMSIS-DAP용 Driver를 PC에 인스톨해야한다. USB Driver에 Bin을 Copy하는 식으로 Firmware의 업데이트가 가능하다. 또한 CMSIS-DAP은 Virtual COM를 지원하기 때문에 USB-to-Serial Port없이 CMSIS-DAP port로 WIZwiki_W7500의  UART Output/Input를 Control할 수 있다. 
     CMSIS-DAP의 Algorithm의 변경은 LPC11u35칩의 Firmware를 update하면 되며 아래의 "How to write the firmware to CMSIS-DAP"를 참고한다. 
    
  • RJ45+PHY

      이 부분은 Ethernet PHY Layer로 W7500은 PHY를 내장하지 않기 때문에 Internet에 연결하기 위해 External PHY가 반드시 필요하다. 
    

Features

  • WIZnet W7500
  • ARM® Cortex™-M0 Core upto 48MHz
  • 128KB Flash memory
  • 16KB to 48 KB SRAM
  • Hardwired TCP/IP Core (8 Sockets, MII: Medium-Independent Interface)
  • 12-bit, 8ch ADC
  • 53 I/Os
  • 1ch Watchdog, 4ch Timers and 8ch PWM
  • 3ch UART
  • 2ch SPI
  • 2ch I2C
  • Arduino form-factor
  • Compatible with a wide range of commercially available shields
  • CMSIS-DAP interface firmware
  • Built-in USB drag ‘n’ drop FLASH programmer
  • USB Virtual COM port for serial terminal
    • CMSIS-DAP interface for programming and debugging from offline tools

Pinout

pin map

Resources on ARMmbed

ARMmbed WIZnetInterface

WIZnetInterface

WIZnet Ethernet Interface using Hardware TCP/IP chip, W5500 and TCP/IP Offload Engine, W7500.
Users » embeddist » Code » WIZnetInterface

WIZnetInterface ?

  • EthernetInterface in ARM mbed
    mbed.org는 Handbook>>Ethernet에 ARM mbed platform들이 Internet에 Connecting하기 위한 Network Library인 EthernetInterface를 제공하고 있다. EthernetInterface는 TCP/IP Software stack으로 lwIP을 채택하고 있다.
  • WIZnet TCP/IP Offload Engine
    아래의 그림과 같이 TOE는 TCP이하의 Network Layer가 Hardware적으로 설계되어 있어 Operating System과 Microcontroller의 Networking을 위한 리소스와 메모리를 최소화 해준다. 따라서, 리소스가 제한되는 Low-end IoT Device에서 TOE의 기능이 탑재한 MCU혹은 TOE를 채택한 System은 보다 Networking 이외의 기능들에 최적화 시킬 수 있다.
    TCP/IP Offload Engine
  • 과연, ARM mbed에서 이러한 TOE를 적용한 Platform혹은 Components 있나?
    있습니다. 있고요.
    Platform으로는 W7500이 적용된 WIZwiki_W7500이 있습니다.
    Component로는 W5500이 적용된 W5500 Ethernet Shield가 있습니다. 둘다 made in 대한민국!
  • 그럼, 이렇게 TOE가 적용된 Platform과 Component들도 EthernetInterface를 사용하나?
    아니요. TOE가 적용된 Platform과 Component는 WIZnetInterface를 사용해야 합니다.
    WIZnetInterface
    WIZnetInterface는 위의 그림처러 TOE Driver를 mbed Ethernet Interface기반으로 포팅하였습니다. 따라서, ARM mbed에서 EthernetInterface를 적용한 program을 WIZnetInterface로 replace하는 것이 가능합니다.

What is new?

  • W7500과 W5500을 어떻게 선택하나
    eth_arch.h을 추가하여 Web-IDE에서 platform을 선택하면 Target Platform에 따라 자동적으로 W7500혹은 W5500을 적용할 수 있다. W5500과 W7500이 통합된 Library이지만 둘 중 하나를 선택하기 위해 여분의 Configuration이 필요없다.
    #if defined(TARGET_WIZwiki_W7500)
    #include "W7500x_toe.h"
    #define __DEF_USED_IC101AG__  //For using IC+101AG@WIZwiki-W7500
    #else
    #include "W5500.h"            // W5500 Ethernet Shield 
    //#define USE_WIZ550IO_MAC    // WIZ550io; using the MAC address
    #endif
    
  • PHY링크를 어떻게 설정하고 확인하나
    Ethernet PHY는 아래의 그림과 같이 RJ45의 Link LED와 Active LED를 이용하여 육안으로 확인이 가능하다. Embedded system에서는 MCU의 GPIO에 Link와 Active Signal을 연결하거나 MDIO Interface를 확인 할 수 있다.
    PHY link
    (http://www.avtech.com/Support/modules/KB/Image/Image/166_RA_LEDs/Ethernet_LEDs_NormalOperation_BothTypes.gif)
    EthernetInterface에서 이러한 기능을 위해 link()와 set_link()를 제공하고 WIZnetInterface에서도 이 API를 제공하고 있다.
    • link()
      PHY링크를 확인할 수 있는 함수 return값이 True이면 Link이고, Fail이면 Link-Fail이다
        * Check if an ethernet link is pressent or not.
        *
        * @returns true if successful
        */
        bool link(int wait_time_ms= 3*1000);
      
    • set_link()
      PHY의 Duplex/SPEED를 설정할 수 있는 함수이다.
       /*
        * Sets the speed and duplex parameters of an ethernet link.
        *
        * @returns true if successful
        */
        void set_link(PHYMode phymode);
      
  • Networking에 필수적으로 필요한 DHCP와 DNS lib를 포함
    dhcpdns

How to import

  • import and update
    • WIZnetInterface Library의 import를 위해 import하고자 하는 program에서 오른쪽 클릭 후 ‘From Import Wizard’를 클릭 한다.
      import_WIZnetInterface
    • import wizard의 검색 창에서 ‘WIZnetInterfae”를 적고 ‘Search’ button을 클릭한다. 검색 결과 창에서 ‘WIZnetInterface’을 선택한 후 거침없이 ‘Import’ button을 클릭!
      search_WIZnetInterface
    • Import Library창이 뜨면 당황하지 않고 각항목을 알맞게 ‘Import name’ 과 ‘Target path’설정 한다. 또한 최신의 Library를 import하기 위해 ‘update’ check box를 반드시 체크한다. 그리고 ‘Import’ Button을 클릭하여 WIZnetInteface의 Import를 완료한다.
      importandupdate_WIZnetInteface

Where is Clone repository

파일 버젼관린 시스템 Git과 같은 Mecurial를 ARM mbed에서 적용하고 있다.
아래의 명령어를 이용하여 WIZnetInterface를 Clone할 수 있으며 hg명령어를 이용하여 버젼관리를 할 수 있다.
hg clone https://embeddist@developer.mbed.org/users/embeddist/code/WIZnetInterface/
또한, WIZnetInterface는 ARM mbed의 Team WIZnet에서 관리하고 있으므로 https://developer.mbed.org/teams/WIZnet/를 방문하여 다운 및 다수의 예제를 활용할 수 있다.

How to use

  • make main.cpp
    • WIZwiki_W7500
      #define _DHCP_
      EthernetInterface eth;  /*1. Creat eth object from EthernetInteface class*/
      
      main()
      {
        /*2. MAC address as arr in HEX-Type*/
        uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x01, 0x02, 0x03};  
      
        /*3. Select DHCP or Fixed IP address*/
      #ifdef _DHCP_
        /*3.1 Set  MAC address, Initialize the interface with DHCP*/
        eth.init(mac_addr); 
      #else   
        /*3.2 Set  MAC address and Set MAC, IP, Gatway address and Subnet Mask as String-Type*/
        eth.init(mac_addr, "192.168.77.34", "255.255.255.0", "192.168.77.1"); 
      #endif
      
        /*4. Check Ethernet Link-Done */
        printf("Check Ethernet Link\r\n");
        if(eth.link() == true) { printf("- Ethernet PHY Link-Done \r\n"); }
        else {printf("- Ethernet PHY Link- Fail\r\n");}
      
        /*5. Set IP addresses ,start DHCP if needed  */
        if( eth.connect() == ture )
        {
            printf("Connected, IP: %s\n\r", eth.getIPAddress());
            printf("MASK: %s\n\r", eth.getNetworkMask());
            printf("GW: %s\n\r",eth.getGateway());
        }
        else
        {
            printf("eth.connect fail\n\r");
        }
        ...
      
        /* Your application 
           Visit for examples - https://developer.mbed.org/teams/WIZnet/
        */
      
      }
      
    • W5500 Ethernet Shield
      #define _DHCP_
      /* 0. Set SPI Interface with SPI API*/
      SPI spi(D11, D12, D13);                  // mosi, miso, sclk
      /*1. Creat eth object from EthernetInteface class*/
      EthernetInterface eth(&amp;spi, D10, D9);    // spi, cs, reset
      
      main()
      {
        /*2. MAC address as arr in HEX-Type*/
        uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x01, 0x02, 0x03};  
      
         /*3. Select DHCP or Fixed IP address*/
      #ifdef _DHCP_
        /*3.1 Set  MAC address, Initialize the interface with DHCP*/
        eth.init(mac_addr); 
      #else
        /*3.2 Set  MAC address and Set MAC, IP, Gatway address and Subnet Mask as String-Type */
        eth.init(mac_addr, "192.168.77.34", "255.255.255.0", "192.168.77.1"); 
      #endif
      
        /*3. Check Ethernet Link-Done */
        printf("Check Ethernet Link\r\n");
        if(eth.link() == true) { printf("- Ethernet PHY Link-Done \r\n"); }
        else {printf("- Ethernet PHY Link- Fail\r\n");}
      
        /*4. Set IP addresses ,start DHCP if needed  */
        if( eth.connect() == ture )
        {
            printf("Connected, IP: %s\n\r", eth.getIPAddress());
            printf("MASK: %s\n\r", eth.getNetworkMask());
            printf("GW: %s\n\r",eth.getGateway());
        }
        else
        {
            printf("eth.connect fail\n\r");
        }
        ...
      
        /* Your application 
           Visit for examples - https://developer.mbed.org/teams/WIZnet/
        */
      
      }
      

WIZnetInterface APIs for mbed Ethenret Interface

Ethernet 기반의 Networking을 위해 *Ethenret Interface Library를 ARM mbed에서 제공하고 있으며, 이 Library는 크게 4가지 TCP/IP Protocol layer, Ethernet, EthernetInterface and Socket로 구성되있다.
Internet에 연결하기 위해 EthernetInterface의 각각의 Layer는 APIs들로 구성되어 있다. 각각의 API는 아래의 경로에서 확인할 수 있다.

WIZnetInterface Implementation base on mbed Ethernet Interface

  • EthernetInterface- EthernetInterface Class
    Type Func. Descriptions WIZnetInterface
    static int init () Initialize the interface with DHCP. O
    static int init (const char ip, const char mask, const char *gateway) Initialize the interface with a static IP address. O
    static int connect (unsigned int timeout_ms=15000) Connect Bring the interface up, start DHCP if needed. O
    static int disconnect () Disconnect Bring the interface down. no use
    static char* getMACAddress () Get the MAC address of your Ethernet interface. O
    static char* getIPAddress () Get the IP address of your Ethernet interface. O
    static char* getGateway () Get the Gateway address of your Ethernet interface. O
    static char* getNetworkMask () Get the Network mask of your Ethernet interface. O
    void EthernetInterface (PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset) Initialize SPI SPI pins to user for SPI interface and Reset pin for W5500 0 (for W5500)
    void EthernetInterface (SPI* spi, PinName cs, PinName reset) Initialize SPI SPI pins to user for SPI interface and Reset pin for W5500 O (for W5500)
  • Socket - TCPSocketServer Class
    Type Func. Descriptions WIZnetInterface
    TCPSocketServer () Instantiate a TCP Server. O
    int bind (int port) Bind a socket to a specific port. O
    int listen (int backlog=1) Start listening for incoming connections. O
    int accept ( TCPSocketConnection &connection) Accept a new connection. O
    void set_blocking (bool blocking, unsigned int timeout=1500) Set blocking or non-blocking mode of the socket and a timeout on blocking socket operations. O
    int set_option (int level, int optname, const void *optval, socklen_t optlen) Set socket options. no use
    int get_option (int level, int optname, void optval, socklen_t optlen) Get socket options. no use
    int close (bool shutdown=true) Get socket options. O
  • Socket - TCPSocketConnection Class
    Type Func. Descriptions WIZnetInterface
    TCPSocketConnection () TCP socket connection. O
    int connect (const char *host, const int port) Connects this TCP socket to the server. O
    bool is_connected (void) Check if the socket is connected. O
    int send (char *data, int length) Send data to the remote host. O
    int send_all (char *data, int length) Send all the data to the remote host. O
    int receive (char *data, int length) Receive data from the remote host. O
    int receive_all (char *data, int length) Receive all the data from the remote host. O
    void set_blocking (bool blocking, unsigned int timeout=1500) Set blocking or non-blocking mode of the socket and a timeout on blocking socket operations. O
    int set_option (int level, int optname, const void *optval, socklen_t optlen) Set socket options. no use
    int get_option (int level, int optname, void optval, socklen_t optlen) Get socket options. no use
    int close (bool shutdown=true) Close the socket. O
    void reset_address (void) Reset the address of this endpoint. O
    int set_address (const char *host, const int port) Set the address of this endpoint. O
    char* get_address (void) Get the IP address of this endpoint. O
    int get_port (void) Get the port of this endpoint. O
  • etnerhet_api - ethernet_api Class
    Type Func. Descriptions WIZnetInterface
    Ethernet () Initialise the ethernet interface. no use
    virtual ~Ethernet () Powers the hardware down. no use
    int write (const char *data, int size) Writes into an outgoing ethernet packet. no use
    int send () Send an outgoing ethernet packet. no use
    int receive () Recevies an arrived ethernet packet. no use
    int read (const char *data, int size) Read from an recevied ethernet packet. no use
    void address (char *mac) Gives the ethernet address of the mbed. no use
    int link() Returns if an ethernet link is pressent or not. O
    void set_link(Mode mode) Sets the speed and duplex parameters of an ethernet link. O

ARMmbed Web-IDE

ARM mbed Web-IDE에서 놀자

  • Goals : ARM mbed Web-IDE에서 프로젝트를 생성하는 방법을 알고 Compile/Program을 해보면서 Web-IDE에 친해지기

    • Platform : WIZwiki_W7500
      • ARM® Cortex™-M0 Core 48MHz
      • 128KB Flash memory
      • 16KB to 48 KB SRAM
      • Hardwired TCP/IP Core (8 Sockets, MII: Medium-Independent Interface)

program workspace에서 new프로젝트 생성하기

  • mbed.org로그인 후 Develor Site >> Compiler Site로 이동!
  • Compiler Site의 Web-IDE의 메뉴바에서 왼쪽 상단의 New를 클릭하고 New program..를 연타!
    2015-07-01_15-54-16

  • Create new program wizard가 뜨면 당황하지 말고 각자에 환경에 맞게 설정!
    2015-07-01_15-28-44

    • Platform: WIZwiki-W7500의 이외의 보드를 이용할 경우 해당 Platform을 선택한다.
    • Template: 각각 platform마다 제공하는 Template예제들을 선택할 수 있다.
    • Program Name: 알맞게 Program Name을 변경할 수 있다. (아래의 그림은 mbed_blinky였던것을 0_mbed_blinky변경한 것임)
    • update check box: Default로 체크가 되어있다. import할때 최신 Library를 적용하여 import한다는 의미
    • 모든 설정을 마친 후 OK 버튼을 클릭하면 Compiler Site로 변경되며 import를 수행한다.
  • Web-IDE인 Compiler Site에 0_mbed_blinky program이 생성 되었는지 확인하자
    Program workspace 창에 Create new program wizard에서 적용한 0_mbed_blinky가 있는지 확인
    2015-07-01_15-30-04

0_mbed_blinky program 뽀개기

컴파일 전에 코드와 프로젝트 감상하고 가시겠습니다.

2015-07-01_16-01-53

  • 0_mbed_blinky program은 크게 main.cpp와 mbed.lib로 구성된다.

    • 0_mbed_blinky/main.cpp: main()가 구현되어 있는 파일
    • mbed.lib: mbed library는 ARM mbed에 등록되어 있는 모든 Cortex-M기반의 MCU의 CMSIS및 각종페리페럴의 Hardware Adapataion Layer(HAL)를 포함한다. 따라서, new program을 생성할 때 Default로 포함되어야한다. library형태라 Souce code를 확인 할 수는 없다. 코드를 참고 하기 원한다면 Code Site에 가서 mbed-src를 검색하자 mbed library를 코드 레벨로 확인할 수 있다. 그리고 주의할 점은 mbed-src는 베타버전으로 unstable할 수 있다. 반다로 mbed.lib는 stable 버젼으로 생각하면 거의(?) 된다.
  • main.cc를 보면

    • mbed.lib를 사용하기 위해 1번 Line에 #include “mbed.h”필수
    • Class나 API는 Handbook Site를 참고 하자
      • DigitalOut myled(LED1):
        • DigitalOut Class타입으로 LED1이라는 인자를 받아 myled는 인스턴스를 생성
        • DigtalOut과 같은 Class나 API들은 handbook Site를 참고 하자
      • wait(time)는 time의 인자만큼 초 단위로 wait한다.
    • 결국 이 예제는 LED1를 On으로 0.2초 OFF로 0.2초를 무한 반복하는 예제구나

Compile

  • Web-IDE의 menu중 Compile를 클릭
  • Complie이 error없이 완료되면 자동적으로 Bin를 다운로드한다.
  • Bin파일의 Name은 Program Name_platform Name.bin 형식으로 생성된다.
    2015-07-01_17-30-44

Program

  • mbed platform들은 Local PC에서 아래의 그림과 같이 드라이브(mbed)로 인식된다. 따라서 다운 받은 Bin파일을 mbed drive에 Copy하면 program은 끝!
    2015-07-01_14-25-18

ARMmbed

mbed_logo

ARM mbed는 아래의 그림처럼 IoT Device Platform을 위하 구성되는 Sillicon, Cloud, Device Partner들의 Communty를 표방한다.
arm_mbed_iot_dppage_-01-1b
Cortex-M을 제공하던 ARM사가 Cortex-M IoT Device Ecosystem을 더욱 확고히 하기위해 Operating System인 mbedOS와
IoT Cloud Server개념의 mbed Deiver Server를 포함하고 있다.
또한 ARM mbed on Site에서 IoT Device의 개발이 이루어 지도록 Web-IDE를 On-Site에서 지원하고 있으며 재발된 코드들의
버젼관리 및 배포를 할 수 있도록 Mecurial기반의 파일 버젼관리 시스템을 연동하고 있습니다. 이러한 Web-IDE를 기반으로 Official 혹은 User Library들이 공유되며 이를 바탕으로 Rapid Protypting이 가능하다.
따라서, 개발자들이 ARM mbed Site에서 IoT Device의 개발부터 IoT Cloud service의 Test를 완료 할 수 있다.

자세한 내용의 아래의 링크를 확인하세요

mbedOS

mbed-os-v2-700x467

  • 기존에는 같은 Cortex M processor를 사용하더라고 Vendor마다 각각 사용하는 방법이 달라 Function적으로는 같은 코드지만, 다른 Vendor의 MCU를 사용할 경우에는 각각의 MCU에 의존적인 부분들을 선별하여 고치는 poring작업들이 개발자들의 괴롭혔다. Fuctionc적으로는 검증되어있지만 MCU바뀌어서 벌어지는 코드 수정에 따른 무한 디버깅이 개발자들을 지치게 하죠. 이러한 문제를 해결하기 위해 Cortex Microcontroler Software Interface Standard가 등장했다.. CMSIS는 Vendor별로 존재하던 Hardware부분을 Hardware abstraction layer이용하여 각각의 다른 Vendor의 MCU를 하나의 Cortex M processor 사용하는 것 처럼 할 수 있게 하였다. 따라서 개발자들은 Hardware변경에 따라 발생하는 문제들을 줄일 수 있고 자기가 개발하려는 Function기능에 더욱 집중할 수 있게 되었다. mbedOS에도 이 CMSIS 기반으로 작성된다. 따라서, mbedOS를 이용함에 있어 Hardware에 따른 수정들이 최소화 하였다.

mbed Device Server

additional_diag-_3mbed_dpage2_d3-01

  • 현재 (2015.07)에는 mbed Device Server는 Beta open으로 partner만이 접근이 가능하다. Xivily, Axeda 와 같은 기존의 Cloud Service업체들의 기능들을 ARM mbed에서 수용하여 IoT Cloud Service의 제공을 준비중이다.

Web IDE

compiler-overview
KEIL와 IAR과 같은 IDE가 Web기반으로 제공되고 있다. 따라서 IDE를 설치하는 과정들이 생략되는 단점이 생긴다. 물론 Web-bwroser를 사용하기 때문에 네트워크 상황에서 또한 Web-IDE Server의 상황에따라 “렉”이 걸릴때가 있다. 이러한 문제는 Web-IDE에서 현재 작업중인 코드를 Export하는 기능을 제공하기 때문에 코드를 프로젝트단위로 Local PC로 다운로드하여 코드 작업을 할 수도있다. 다만, 있때는 자신이 사용하려는 IDE가 Local PC에 구축되어 있어야 한다.

자 여기서 궁금한점은 Remote에 있는 Web-IDE에서 Compile된 Bin파일은 어떻게 Local에 있는 Target Board에 Program시키냐는 것이다. 이문제는 아래의 두 단계에 의해 해결된다.

  • Complie이 성공적일 경우 아래의 경우처럼 Bin파일 형태로 Web-bwroser를 통해 다운받아진다. (왼쪽 밑에부분 다운로드된 Bin파일존재)
    2015-07-01_14-22-11
  • mbed platform들은 Local PC에서 아래의 그림과 같이 드라이브(mbed)로 인식된다. 따라서 다운 받은 Bin파일을 mbed drive에 Copy하면 program은 끝!
    2015-07-01_14-25-18

mbed.org 탐방

  • mbed.org에서 로그인 이후 아래의 그림 오른쪽 상단에 있는 Developer Site를 클릭!
    2015-07-01_14-09-02

  • 아래와 같이 Product까지 개발할 수 있는 Developer Site에 접속했다. 메뉴바를 보면 Platform / Components / Handbook / Cookbook등이 존재한다 하나씩 구경해보자
    2015-07-01_14-09-31

  • Platform
    ARM mbed communy에 공식적으로 등록된 platform을 소개하는 페이이며,
    각각의 platform를 클릭해서 들어가면 Pin map / Schematic / HelloWorld Code(예제코드) / 살수 있는 곳 의 형식으로 Platform에 대한 정보가 답겨 있다.
    2015-07-01_14-10-24

  • Components
    ARM mbed platform에 적용이 가능한 Actuator / Sensor / Communication 등의 module를을 소개하는 페이지 이며,
    각각의 Components 클릭해서 들어가면 Pin map / Schematic / HelloWorld Code(예제코드) / 살수 있는 곳 의 형식으로 Components 대한 정보가 답겨 있다.
    2015-07-01_14-10-36

  • Handbook
    ARM mbed platform을 이용하기 위한 Team mbed에서 official적으로 공개하는 Code / Tutorial이 담겨진 페이지이다.
    아래 그림과 같이 Analog IO제어 부터 Networking에 대한 official material이 제공된다.
    2015-07-01_14-11-12

  • Cookbook
    ARM mbed platform을 이용하는 User각자가 공개하는 Code / Tutorial이 담겨진 페이지이다.
    2015-07-01_14-12-09

  • Code
    ARM mbed community에서 존재하는 Code를 검색할 수 있는 페이지 이다.
    2015-07-01_14-12-28

  • Compiler
    ARM mbed의 Web-IDE이다. 아래와 같이 Program workspace창에서 여러개의 프로젝트를 관리할 수 있다.
    또한 Web-IDE에서 Code editing / 컴파일 / 버젼관리 (commit/publish) / import&export 등의 대표적인 기능을 지원한다.
    2015-07-01_14-13-19