[전동 Skateboard 만들기]#3 Wi-Fi 모듈 연결 및 Control 어플 구현

Posted by 카이젠8501 카이젠8501
2015.11.03 09:58 IT 개발/DIY 프로젝트

[전동 Skateboard 만들기]#3 Wi-Fi 모듈 연결 및 Control 어플 구현

Hardware of Wi-Fi Receiver

Wi-Fi 수신기는 스마트폰에서 데이터를 수신하여 스케이트 보드의 속도를 조절하는 장치이며, 하드웨어 구성은 아래와 같다.

20151029_143029

아래 사진은 완성된 하드웨어 사진이다. 배터리나 다른 보드들과의 circuit short를 방지하기 위해 절연 테이트를 부착하여 조금 부족해 보이지만 동작에는 문제가 없다.

오른쪽에 3핀, 2핀이 나와 있는데, 위에 3핀은 PWM,3.3V VCC,GND 핀이고, 아래 2핀은 배터리에서 받아 올 5V VCC, GND 핀이다.

20151030_082315

Wi-Fi Receiver Firmware

Source Code

Wi-Fi Receiver firmware는 아래 그림과 같은 구조로 동작된다. 스마트폰에서 Speed Up 명령을 주면 Wi-Fi Receiver는 속도를 5% 올리고 Speed Down 명령을 주면 속도를 5% 내린다.

20151030_084225

예외 상황에서는 아래 그림과 같이 Motor를 정지 한다. 단 Motor가 정지 되어도 가속도 때문에 스케이트 보드는 계속 움직일 수는 있다.

20151030_085505

Wi-Fi 수신기에 대한 소스코드는 아래 경로에서 다운로드 할 수 있다.
https://developer.mbed.org/users/kaizen/code/Wifi_Electric_Skateboard/

#include "mbed.h"
#include "Servo.h"
#include "WizFi250Interface.h"

#define SECURE WizFi250::SEC_WPA2_MIXED
#define SSID "Kaizen_Skate"
#define PASS "qwertyuiop"

#define SERVER_PORT    5000
#define STOP_MOTOR     50


#if defined(TARGET_WIZwiki_W7500P)
    WizFi250Interface wizfi250(PC_2,PC_3,PC_13,PC_14,PC_12,NC,115200);
    Serial pc(USBTX, USBRX);
    Servo motor_speed(PC_8);      // it used to percentage value ( 0 ~ 1 )
    DigitalOut green_led(LED2);    
    DigitalOut red_led(LED1);
    DigitalOut blue_led(LED3);
#endif

#define START_MSG       "START"
#define END_MSG         "END\n"
#define CONTROL_UP      "UPXX"
#define CONTROL_DOWN    "DOWN"
#define CONTROL_CRUISER "CRUI"
#define CONTROL_STOP    "STOP"

#define STATUS_CMD_OK   "OKXX"
#define STATUS_CMD_FAIL "FAIL"

#define CONTROL_MSG_SIZE    19

// Control Pkt Format : START,CONTROL,SPEED_VALUE,END
//                      START,UPXX,500,END
// Status Pkt Format : START,CONTROL,SPEED_VALUE,STATUS,END

struct control_pkt{
    char start_msg[6];
    char control_msg[5];
    char speed_msg[4];
    char end_msg[4];
};
void parse(char buffer[], int *j, char *string);

int main() {    
    int recv_cnt,j;
    volatile float speed_value = 0.5;
    char recv_control_msg[100];
    char status_msg[100];
    control_pkt control;

    pc.baud(115200);
    green_led = 1; red_led = 1; blue_led = 1;

    wizfi250.init();
    wizfi250.setAntMode(WizFi250::PCB);
    wizfi250.setAddress("192.168.100.2","255.255.255.0","192.168.100.1");
    if ( wizfi250.connect(SECURE, SSID, PASS, WizFi250::WM_AP))
    {
        red_led = 0;
        return -1;
    }
    printf("IP Address is %s\r\n", wizfi250.getIPAddress());
    green_led = 0; red_led = 0; blue_led = 0;

    TCPSocketServer server;
    TCPSocketConnection client;

    while(true)
    {
        if( client.is_connected() == false )
        {
            green_led = 1; red_led = 1; blue_led = 0;            
            client.close();
            server.close();

            if(speed_value == 0.5)
            {
                server.bind(SERVER_PORT);
                server.listen();

                printf("\nWait for new connection...\r\n");
                server.accept(client);
                client.set_blocking(false, 1500);
            }
            else if(speed_value <= 0.4)
            {
                printf("Speed decrease +\r\n");

                speed_value = 0.5;
                motor_speed = speed_value;
            }
            else
            {
                printf("Speed decrease -\r\n");
                speed_value = 0.5;  motor_speed = speed_value;
            }
        }
        else
        {
            motor_speed = speed_value;

            green_led = 0; red_led = 1; blue_led = 1;
            //recv_cnt = client.receive_all((char*)recv_control_msg, sizeof(control)-1);
            recv_cnt = client.receive_all((char*)recv_control_msg, sizeof(control));

            j=0;
            parse(recv_control_msg, &j, control.start_msg);
            parse(recv_control_msg, &j, control.control_msg);
            parse(recv_control_msg, &j, control.speed_msg);
            parse(recv_control_msg, &j, control.end_msg);

            if(recv_cnt > 0)
            {
                if( (strncmp(control.start_msg,START_MSG,sizeof(control.start_msg)) != 0) || 
                    (strncmp(control.end_msg,END_MSG,sizeof(control.end_msg)) != 0) )
                {
                    printf("TEST Error\r\n");
                    sprintf(status_msg,"%s,%03d,%s,%s\n",START_MSG,int(speed_value*100),STATUS_CMD_FAIL,END_MSG);
                    client.send_all((char*)status_msg,strlen(status_msg));
                    continue;
                }

                if( strncmp(control.control_msg,CONTROL_UP,sizeof(control.control_msg)) == 0 )
                {
                    speed_value += 0.05; 
                    motor_speed = speed_value;
                    printf("TEST UP %f\r\n",speed_value); 
                }
                else if( strncmp(control.control_msg,CONTROL_DOWN,sizeof(control.control_msg)) == 0)
                {
                    speed_value -= 0.05; 
                    motor_speed = speed_value;
                    printf("TEST DOWN %f\r\n",speed_value);
                }
                else if( strncmp(control.control_msg,CONTROL_CRUISER,sizeof(control.control_msg)) == 0)
                {
                    printf("TEST CRUISER\r\n"); 
                    speed_value = (float)(atoi(control.speed_msg)) / 100;
                    motor_speed = speed_value;
                }
                else if( strncmp(control.control_msg,CONTROL_STOP,sizeof(control.control_msg)) == 0)
                {
                    printf("TEST STOP\r\n"); 
                    speed_value = 0.5;
                    motor_speed = speed_value;
                }
                else
                {
                    printf("TEST Error 1-2\r\n");
                    sprintf(status_msg,"%s,%03d,%s,%s\n",START_MSG,int(speed_value*100),STATUS_CMD_FAIL,END_MSG);
                    client.send_all((char*)status_msg,strlen(status_msg));
                    continue;
                }

                sprintf(status_msg,"%s,%03d,%s,%s\n",START_MSG,int(speed_value*100),STATUS_CMD_OK,END_MSG);
                client.send_all((char*)status_msg,strlen(status_msg));
            }
            else
            {
                sprintf(status_msg,"%s,%03d,%s,%s\n",START_MSG,int(speed_value*100),STATUS_CMD_OK,END_MSG);
                client.send_all((char*)status_msg,strlen(status_msg));
            }
        }
    }// while
}

void parse(char buffer[], int *j, char *string) {
//extracts next location string data item from buffer
    int i=0;
    for (i=0; i<=strlen(buffer); i++) {  //TOTAL SIZE OF RETURNED DATA
        if ((buffer[*j+i] == ',')||(buffer[*j+i] == '\0' )) { //IF comma or end of string
            //comma is the string field delimiter
            string[i]=0; //SETS END OF SRTRING TO 0
            *j=*j+i+1; //UPDATES to 1 after comma seperated value
            break;
        } else string[i]=buffer[*j+i]; //Keep adding to the string
    }
}

스마트폰 어플

Screenshot_2015-10-29-16-20-25

Source Code

https://github.com/kaizen8501/WiFi_Skateboard

Demo Video


저작자 표시
신고
이 댓글을 비밀 댓글로
    • ㅇㅇ
    • 2016.12.17 21:51 신고
    너무 어렵다.........
    • 안녕하세요^^

      어느 부분이 어려우신지 말씀해 주시면 제가 아는 한도 내에서 자세히 설명 해 드리도록 하겠습니다^^

전동 Skateboard 만들기 #2

Posted by 카이젠8501 카이젠8501
2015.11.03 09:57 IT 개발/DIY 프로젝트

전동 Skateboard 만들기 #2

Mortor Test

Hardware 구성

다들 아시겠지만, 서보모터는 MCU의 PWM 파형을 이용하여 구동한다. PWM 파형을 제어하기 위해 Cortex-M0 계열의 WIZwiki-W7500ECO 보드를 이용하였으며, 하드웨어 구성은 아래 그림과 같다.

20151029_143257

Test Software

Software는 mbed 환경에서 구현하였다. 서보 모터를 제어하기 위해, mbed에서는 Servo 라이브러리를 제공하며 사용방법은 아래 주소를 참고 하기 바란다. (Servo Library)

내 스케이트 보드에 장착되어 있는 보드의 모터에 어떤 값을 입력하였을 때, 전진하고 후진하는지 알아 보기 위해 아래와 같은 테스트 코드를 작성하였다. mbed Servo는 0 ~ 1 사이의 값으로 PWM 파형을 생성하며, 스케이트 보드에 장착된 모터는 0.4 ~ 0.55 값에서 중립 상태를 보인다.

#include "mbed.h"
#include "Servo.h"

int main() {    
    uint8_t ch;
    volatile float speed_value = 0.5;

    Servo myservo(PC_8);
    Serial pc(USBTX,USBRX);

    pc.baud(115200);
    wait(1);
    pc.printf("TEST Start\r\n");

    while(1)
    {
        pc.printf("speed : %f\r\n",speed_value);
        myservo = speed_value;

        ch = pc.getc();

        if(ch == 'u')
        {
            speed_value += 0.001;
        }
        else if(ch == 'd')
        {
            speed_value -= 0.001;
        }

        else if(ch == 's')
        {
            myservo = 0.5;
            wait(0.5);

            speed_value = 0.41;
            myservo = speed_value;
            wait(5);

            speed_value = 0.5;
            myservo = speed_value;

        }
    }
}

위 코드는 https://developer.mbed.org/users/kaizen/code/Servo_HelloWorld/에서 확인 및 다운로드 할 수 있다.


저작자 표시
신고
이 댓글을 비밀 댓글로

WIZwiki_W7500 CMSIS-DAP Porting

Posted by 카이젠8501 카이젠8501
2015.10.08 15:10 IT 개발/mbed

WIZwiki_W7500 CMSIS-DAP Porting

WIZwiki_W7500 Board를 개발하는 중, W7500 Chip이 Reset 되지 않는 문제를 발견하였다.
이 문제로 인해, WIZwki_W7500에 아래와 같은 문제가 발생 했다.

  • Firmware Upload 시, SWD_ERROR 발생
    • Firmware Upload 전, Target Chip(W7500)을 Reset 하는데, Reset 후 W7500이 Booting 되지 않아서 발생한 문제
  • mbed self test에서 Fail되는 현상
    • mbed test bench에서 Firmware Upload 후 CMSIS-DAP을 Reset 하는데 이 때 W7500이 Booting 되지 않아서 발생한 문제

Modified point for Software

기존 CMSIS-DAP의 Reference 대로 LPC11U35의 P1_19번 핀으로 Wizwiki Board의 Switch Reset을 Monitoring 한다.

www.life4iot.com_003

CMSIS-DAP이 Power on Reset 될 때, Target Board(W7500)이 Booting이 완료 될 때 까지 Reset을 시도 한다.

www.life4iot.com_002

www.life4iot.com_001

mbed single test result

위와 같이 CMSIS-DAP 코드를 수정해서 mbed self test를 통과 할 수 있었다.

Building library CMSIS (WIZwiki_W7500, uARM)
Building library MBED (WIZwiki_W7500, uARM)
Building project DETECT (WIZwiki_W7500, uARM)
Executing 'python host_test.py -d H:\ -f "F:\WiznetGit_Repository\W7500_Miscellaneous\mbed-master\build\test\WIZwiki_W7500\uARM\DTCT_1\detect.bin" -p COM12 -t 10 -C 1.5 -m WIZwiki_W7500'
Test::Output::Start
MBED: Instrumentation: "COM12" and disk: "H:\"
HOST: Copy image onto target...
HOST: Initialize serial port...
.......port ready!
HOST: Reset target...
HOST: Property 'timeout' = '10'
HOST: Property 'host_test_name' = 'detect_auto'
HOST: Property 'description' = 'Simple detect test'
HOST: Property 'test_id' = 'DTCT_1'
HOST: Start test...
{{start}}
HOST: Detecting target name...
MBED: Target 'WIZwiki_W7500'
HOST: MUT Target name 'WIZwiki_W7500', expected 'WIZwiki_W7500'... [OK]
MBED: Test ID 'DTCT_1'
MBED: UUID '8ded4549-9396-4b12-b4e1-d90801203d2f'


{{success}}

{{end}}
Test::Output::Finish
TargetTest::WIZwiki_W7500::uARM::DTCT_1::Simple detect test [OK] in 1.46 of 10 sec
Building project DEV_NULL (WIZwiki_W7500, uARM)
Executing 'python host_test.py -d H:\ -f "F:\WiznetGit_Repository\W7500_Miscellaneous\mbed-master\build\test\WIZwiki_W7500\uARM\EXAMPLE_1\dev_null.bin" -p COM12 -t 10 -C 1.5 -m WIZwiki_W7500'
Test::Output::Start
MBED: Instrumentation: "COM12" and disk: "H:\"
HOST: Copy image onto target...
HOST: Initialize serial port...
........port ready!
HOST: Reset target...
HOST: Property 'timeout' = '20'
HOST: Property 'host_test_name' = 'dev_null_auto'
HOST: Property 'description' = 'stdout redirected to dev null'
HOST: Property 'test_id' = 'EXAMPLE_1'
HOST: Start test...
Received 0 bytes: 


{{success}}

{{end}}
Test::Output::Finish
TargetTest::WIZwiki_W7500::uARM::EXAMPLE_1::/dev/null [OK] in 4.45 of 20 sec
Building project HELLO (WIZwiki_W7500, uARM)
Executing 'python host_test.py -d H:\ -f "F:\WiznetGit_Repository\W7500_Miscellaneous\mbed-master\build\test\WIZwiki_W7500\uARM\MBED_10\hello.bin" -p COM12 -t 10 -C 1.5 -m WIZwiki_W7500'
Test::Output::Start
MBED: Instrumentation: "COM12" and disk: "H:\"
HOST: Copy image onto target...
HOST: Initialize serial port...
........port ready!
HOST: Reset target...
HOST: Property 'timeout' = '5'
HOST: Property 'host_test_name' = 'hello_auto'
HOST: Property 'description' = 'Hello World'
HOST: Property 'test_id' = 'MBED_10'
HOST: Start test...
Read 13 bytes:
Hello World


{{success}}

{{end}}
Test::Output::Finish
TargetTest::WIZwiki_W7500::uARM::MBED_10::Hello World [OK] in 1.34 of 5 sec
Building project TICKER (WIZwiki_W7500, uARM)
Executing 'python host_test.py -d H:\ -f "F:\WiznetGit_Repository\W7500_Miscellaneous\mbed-master\build\test\WIZwiki_W7500\uARM\MBED_11\ticker.bin" -p COM12 -t 20 -C 1.5 -m WIZwiki_W7500'
Test::Output::Start
MBED: Instrumentation: "COM12" and disk: "H:\"
HOST: Copy image onto target...
HOST: Initialize serial port...
........port ready!
HOST: Reset target...
HOST: Property 'timeout' = '15'
HOST: Property 'host_test_name' = 'wait_us_auto'
HOST: Property 'description' = 'Ticker Int'
HOST: Property 'test_id' = 'MBED_11'
HOST: Start test...
* in 1.00 sec (0.00) [OK]
* in 0.98 sec (0.02) [OK]
* in 1.00 sec (0.00) [OK]
* in 1.00 sec (0.00) [OK]
* in 1.00 sec (0.00) [OK]
* in 0.98 sec (0.02) [OK]
* in 1.00 sec (0.00) [OK]
* in 1.00 sec (0.00) [OK]
* in 0.98 sec (0.02) [OK]
* in 1.00 sec (0.00) [OK]
Consecutive OK timer reads: 10
Completed in 9.94 sec


{{success}}

{{end}}
Test::Output::Finish
TargetTest::WIZwiki_W7500::uARM::MBED_11::Ticker Int [OK] in 12.29 of 15 sec
Building project CPP (WIZwiki_W7500, uARM)
Executing 'python host_test.py -d H:\ -f "F:\WiznetGit_Repository\W7500_Miscellaneous\mbed-master\build\test\WIZwiki_W7500\uARM\MBED_12\cpp.bin" -p COM12 -t 10 -C 1.5 -m WIZwiki_W7500'
Test::Output::Start
MBED: Instrumentation: "COM12" and disk: "H:\"
HOST: Copy image onto target...
HOST: Initialize serial port...
........port ready!
HOST: Reset target...
HOST: Unknown property: Static::init
HOST: Property 'timeout' = '10'
HOST: Property 'host_test_name' = 'default_auto'
HOST: Property 'description' = 'C++'
HOST: Property 'test_id' = 'MBED_12'
HOST: Start test...
Static::stack_test
Stack::init
Stack::hello
Stack::destroy
Static::check_init: OK
Heap::init
Heap::hello
Heap::check_init: OK
Heap::destroy
{{success}}
{{end}}
Test::Output::Finish
TargetTest::WIZwiki_W7500::uARM::MBED_12::C++ [OK] in 2.40 of 10 sec
Building project RTC (WIZwiki_W7500, uARM)
Executing 'python host_test.py -d H:\ -f "F:\WiznetGit_Repository\W7500_Miscellaneous\mbed-master\build\test\WIZwiki_W7500\uARM\MBED_16\rtc.bin" -p COM12 -t 15 -C 1.5 -m WIZwiki_W7500'
Test::Output::Start
MBED: Instrumentation: "COM12" and disk: "H:\"
HOST: Copy image onto target...
HOST: Initialize serial port...
........port ready!
HOST: Reset target...
HOST: Property 'timeout' = '20'
HOST: Property 'host_test_name' = 'rtc_auto'
HOST: Property 'description' = 'RTC'
HOST: Property 'test_id' = 'MBED_16'
HOST: Start test...
MBED: [0] [1970-01-01 00:00:00 AM]
HOST: [0] [1970-01-01 00:00:00 AM] received time +0 sec after 0.05 sec... FAIL
MBED: [0] [1970-01-01 00:00:00 AM]
HOST: [0] [1970-01-01 00:00:00 AM] received time +0 sec after 1.03 sec... FAIL
MBED: [0] [1970-01-01 00:00:00 AM]
HOST: [0] [1970-01-01 00:00:00 AM] received time +0 sec after 1.03 sec... FAIL
MBED: [0] [1970-01-01 00:00:00 AM]
HOST: [0] [1970-01-01 00:00:00 AM] received time +0 sec after 1.03 sec... FAIL
MBED: [0] [1970-01-01 00:00:00 AM]
HOST: [0] [1970-01-01 00:00:00 AM] received time +0 sec after 1.04 sec... FAIL


{{failure}}

{{end}}
Test::Output::Finish
TargetTest::WIZwiki_W7500::uARM::MBED_16::RTC [FAIL] in 5.51 of 20 sec
Building project STDIO (WIZwiki_W7500, uARM)
Executing 'python host_test.py -d H:\ -f "F:\WiznetGit_Repository\W7500_Miscellaneous\mbed-master\build\test\WIZwiki_W7500\uARM\MBED_2\stdio.bin" -p COM12 -t 20 -C 1.5 -m WIZwiki_W7500'
Test::Output::Start
MBED: Instrumentation: "COM12" and disk: "H:\"
HOST: Copy image onto target...
HOST: Initialize serial port...
........port ready!
HOST: Reset target...
HOST: Property 'timeout' = '20'
HOST: Property 'host_test_name' = 'stdio_auto'
HOST: Property 'description' = 'stdio'
HOST: Property 'test_id' = 'MBED_2'
HOST: Start test...
{{start}}

HOST: Generated number: 17349
MBED: Your value was: 17349
HOST: Number 17349 read after 0.031 sec ... [OK]
HOST: Generated number: 12660
MBED: Your value was: 12660
HOST: Number 12660 read after 0.047 sec ... [OK]
HOST: Generated number: -72654
MBED: Your value was: -72654
HOST: Number -72654 read after 0.031 sec ... [OK]
HOST: Generated number: 30812
MBED: Your value was: 30812
HOST: Number 30812 read after 0.047 sec ... [OK]
HOST: Generated number: 84634
MBED: Your value was: 84634
HOST: Number 84634 read after 0.031 sec ... [OK]
HOST: Generated number: -88020
MBED: Your value was: -88020
HOST: Number -88020 read after 0.047 sec ... [OK]
HOST: Generated number: 24709
MBED: Your value was: 24709
HOST: Number 24709 read after 0.031 sec ... [OK]
HOST: Generated number: 6023
MBED: Your value was: 6023
HOST: Number 6023 read after 0.047 sec ... [OK]
HOST: Generated number: 37272
MBED: Your value was: 37272
HOST: Number 37272 read after 0.031 sec ... [OK]
HOST: Generated number: -46512
MBED: Your value was: -46512
HOST: Number -46512 read after 0.047 sec ... [OK]


{{success}}

{{end}}
Test::Output::Finish
TargetTest::WIZwiki_W7500::uARM::MBED_2::stdio [OK] in 1.74 of 20 sec
Building project TICKER_2 (WIZwiki_W7500, uARM)
Executing 'python host_test.py -d H:\ -f "F:\WiznetGit_Repository\W7500_Miscellaneous\mbed-master\build\test\WIZwiki_W7500\uARM\MBED_23\ticker_2.bin" -p COM12 -t 15 -C 1.5 -m WIZwiki_W7500'
Test::Output::Start
MBED: Instrumentation: "COM12" and disk: "H:\"
HOST: Copy image onto target...
HOST: Initialize serial port...
........port ready!
HOST: Reset target...
HOST: Property 'timeout' = '15'
HOST: Property 'host_test_name' = 'wait_us_auto'
HOST: Property 'description' = 'Ticker Int us'
HOST: Property 'test_id' = 'MBED_23'
HOST: Start test...
* in 0.98 sec (0.02) [OK]
* in 1.00 sec (0.00) [OK]
* in 1.00 sec (0.00) [OK]
* in 0.98 sec (0.02) [OK]
* in 1.00 sec (0.00) [OK]
* in 1.00 sec (0.00) [OK]
* in 0.98 sec (0.02) [OK]
* in 1.00 sec (0.00) [OK]
* in 1.00 sec (0.00) [OK]
* in 0.98 sec (0.02) [OK]
Consecutive OK timer reads: 10
Completed in 9.92 sec


{{success}}

{{end}}
Test::Output::Finish
TargetTest::WIZwiki_W7500::uARM::MBED_23::Ticker Int us [OK] in 12.30 of 15 sec
Building project TIMEOUT (WIZwiki_W7500, uARM)
Executing 'python host_test.py -d H:\ -f "F:\WiznetGit_Repository\W7500_Miscellaneous\mbed-master\build\test\WIZwiki_W7500\uARM\MBED_24\timeout.bin" -p COM12 -t 15 -C 1.5 -m WIZwiki_W7500'
Test::Output::Start
MBED: Instrumentation: "COM12" and disk: "H:\"
HOST: Copy image onto target...
HOST: Initialize serial port...
........port ready!
HOST: Reset target...
HOST: Property 'timeout' = '15'
HOST: Property 'host_test_name' = 'wait_us_auto'
HOST: Property 'description' = 'Timeout Int us'
HOST: Property 'test_id' = 'MBED_24'
HOST: Start test...
* in 1.03 sec (0.03) [OK]
* in 1.04 sec (0.04) [OK]
* in 1.05 sec (0.05) [OK]
* in 1.03 sec (0.03) [OK]
* in 1.05 sec (0.05) [OK]
* in 1.04 sec (0.04) [OK]
* in 1.05 sec (0.05) [OK]
* in 1.03 sec (0.03) [OK]
* in 1.05 sec (0.05) [OK]
* in 1.05 sec (0.05) [OK]
Consecutive OK timer reads: 10
Completed in 10.41 sec


{{success}}

{{end}}
Test::Output::Finish
TargetTest::WIZwiki_W7500::uARM::MBED_24::Timeout Int us [OK] in 12.80 of 15 sec
Building project TIME_US (WIZwiki_W7500, uARM)
Executing 'python host_test.py -d H:\ -f "F:\WiznetGit_Repository\W7500_Miscellaneous\mbed-master\build\test\WIZwiki_W7500\uARM\MBED_25\time_us.bin" -p COM12 -t 15 -C 1.5 -m WIZwiki_W7500'
Test::Output::Start
MBED: Instrumentation: "COM12" and disk: "H:\"
HOST: Copy image onto target...
HOST: Initialize serial port...
........port ready!
HOST: Reset target...
HOST: Property 'timeout' = '15'
HOST: Property 'host_test_name' = 'wait_us_auto'
HOST: Property 'description' = 'Time us'
HOST: Property 'test_id' = 'MBED_25'
HOST: Start test...
* in 1.00 sec (0.00) [OK]
* in 1.00 sec (0.00) [OK]
* in 1.00 sec (0.00) [OK]
* in 1.00 sec (0.00) [OK]
* in 1.00 sec (0.00) [OK]
* in 1.00 sec (0.00) [OK]
* in 1.00 sec (0.00) [OK]
* in 1.00 sec (0.00) [OK]
* in 1.00 sec (0.00) [OK]
* in 1.00 sec (0.00) [OK]
Consecutive OK timer reads: 10
Completed in 9.98 sec


{{success}}

{{end}}
Test::Output::Finish
TargetTest::WIZwiki_W7500::uARM::MBED_25::Time us [OK] in 12.33 of 15 sec
Building project DIV (WIZwiki_W7500, uARM)
Executing 'python host_test.py -d H:\ -f "F:\WiznetGit_Repository\W7500_Miscellaneous\mbed-master\build\test\WIZwiki_W7500\uARM\MBED_26\div.bin" -p COM12 -t 10 -C 1.5 -m WIZwiki_W7500'
Test::Output::Start
MBED: Instrumentation: "COM12" and disk: "H:\"
HOST: Copy image onto target...
HOST: Initialize serial port...
...port ready!
HOST: Reset target...
HOST: Property 'timeout' = '20'
HOST: Property 'host_test_name' = 'default_auto'
HOST: Property 'description' = 'Integer constant division'
HOST: Property 'test_id' = 'MBED_26'
HOST: Start test...
64bit: 0x7FFFFFFF8: expected 0x55555555 got 0x55555555 ... [OK]

64bit: 0x17FFFFFFE8: expected 0xFFFFFFFF got 0xFFFFFFFF ... [OK]

{{success}}
{{end}}
Test::Output::Finish
TargetTest::WIZwiki_W7500::uARM::MBED_26::Integer constant division [OK] in 2.40 of 20 sec
Building project TICKER_3 (WIZwiki_W7500, uARM)
Executing 'python host_test.py -d H:\ -f "F:\WiznetGit_Repository\W7500_Miscellaneous\mbed-master\build\test\WIZwiki_W7500\uARM\MBED_34\ticker_3.bin" -p COM12 -t 15 -C 1.5 -m WIZwiki_W7500'
Test::Output::Start
MBED: Instrumentation: "COM12" and disk: "H:\"
HOST: Copy image onto target...
HOST: Initialize serial port...
...port ready!
HOST: Reset target...
HOST: Property 'timeout' = '20'
HOST: Property 'host_test_name' = 'default_auto'
HOST: Property 'description' = 'Integer constant division'
HOST: Property 'test_id' = 'MBED_26'
HOST: Start test...
64bit: 0x7FFFFFFF8: expected 0x55555555 got 0x55555555 ... [OK]

64bit: 0x17FFFFFFE8: expected 0xFFFFFFFF got 0xFFFFFFFF ... [OK]

{{success}}
{{end}}
Test::Output::Finish
TargetTest::WIZwiki_W7500::uARM::MBED_34::Ticker Two callbacks [OK] in 2.39 of 20 sec
Building project BASIC (WIZwiki_W7500, uARM)
Executing 'python host_test.py -d H:\ -f "F:\WiznetGit_Repository\W7500_Miscellaneous\mbed-master\build\test\WIZwiki_W7500\uARM\MBED_A1\basic.bin" -p COM12 -t 10 -C 1.5 -m WIZwiki_W7500'
Test::Output::Start
MBED: Instrumentation: "COM12" and disk: "H:\"
HOST: Copy image onto target...
HOST: Initialize serial port...
........port ready!
HOST: Reset target...
HOST: Property 'timeout' = '20'
HOST: Property 'host_test_name' = 'default_auto'
HOST: Property 'description' = 'Basic'
HOST: Property 'test_id' = 'MBED_A1'
HOST: Start test...
{{success}}
{{end}}
Test::Output::Finish
TargetTest::WIZwiki_W7500::uARM::MBED_A1::Basic [OK] in 2.48 of 20 sec
Building project CALL_BEFORE_MAIN (WIZwiki_W7500, uARM)
Executing 'python host_test.py -d H:\ -f "F:\WiznetGit_Repository\W7500_Miscellaneous\mbed-master\build\test\WIZwiki_W7500\uARM\MBED_A21\call_before_main.bin" -p COM12 -t 10 -C 1.5 -m WIZwiki_W7500'
Test::Output::Start
MBED: Instrumentation: "COM12" and disk: "H:\"
HOST: Copy image onto target...
HOST: Initialize serial port...
........port ready!
HOST: Reset target...
HOST: Unknown property: MBED: mbed_main() call before main()
HOST: Property 'timeout' = '20'
HOST: Property 'host_test_name' = 'default_auto'
HOST: Property 'description' = 'Call function mbed_main before main'
HOST: Property 'test_id' = 'MBED_A21'
HOST: Start test...
MBED: main() starts now!

{{success}}
{{end}}
Test::Output::Finish
TargetTest::WIZwiki_W7500::uARM::MBED_A21::Call function before main (mbed_main) [OK] in 2.45 of 20 sec
Building project ECHO (WIZwiki_W7500, uARM)
Executing 'python host_test.py -d H:\ -f "F:\WiznetGit_Repository\W7500_Miscellaneous\mbed-master\build\test\WIZwiki_W7500\uARM\MBED_A9\echo.bin" -p COM12 -t 10 -C 1.5 -m WIZwiki_W7500'
Test::Output::Start
MBED: Instrumentation: "COM12" and disk: "H:\"
HOST: Copy image onto target...
HOST: Initialize serial port...
........port ready!
HOST: Reset target...
HOST: Property 'timeout' = '20'
HOST: Property 'host_test_name' = 'echo'
HOST: Property 'description' = 'Serial Echo at 115200'
HOST: Property 'test_id' = 'MBED_A9'
HOST: Start test...
...port ready!
HOST: Starting the ECHO test
..................................................

{{success}}

{{end}}
Test::Output::Finish
TargetTest::WIZwiki_W7500::uARM::MBED_A9::Serial Echo at 115200 [OK] in 2.66 of 20 sec
Building project BUS_OUT (WIZwiki_W7500, uARM)
Executing 'python host_test.py -d H:\ -f "F:\WiznetGit_Repository\W7500_Miscellaneous\mbed-master\build\test\WIZwiki_W7500\uARM\MBED_BUSOUT\bus_out.bin" -p COM12 -t 15 -C 1.5 -m WIZwiki_W7500'
Test::Output::Start
MBED: Instrumentation: "COM12" and disk: "H:\"
HOST: Copy image onto target...
HOST: Initialize serial port...
........port ready!
HOST: Reset target...
HOST: Start test...
MBED: BusIn mask: 0xF

MBED: BusIn LED mask: 0xF

MBED: BusOut.bit[0] is connected

MBED: BusOut.bit[1] is connected

MBED: BusOut.bit[2] is connected

MBED: BusOut.bit[3] is connected

MBED: Blinking LEDs: 

AaBbCcDd

{{success}}
{{end}}
Test::Output::Finish
TargetTest::WIZwiki_W7500::uARM::MBED_BUSOUT::BusOut [OK] in 3.29 of 15 sec
Test summary:
+--------+---------------+-----------+-------------+---------------------------------------+--------------------+---------------+-------+
| Result | Target        | Toolchain | Test ID     | Test Description                      | Elapsed Time (sec) | Timeout (sec) | Loops |
+--------+---------------+-----------+-------------+---------------------------------------+--------------------+---------------+-------+
| OK     | WIZwiki_W7500 | uARM      | DTCT_1      | Simple detect test                    |        1.46        |       10      |  1/1  |
| OK     | WIZwiki_W7500 | uARM      | EXAMPLE_1   | /dev/null                             |        4.45        |       20      |  1/1  |
| OK     | WIZwiki_W7500 | uARM      | MBED_10     | Hello World                           |        1.34        |       5       |  1/1  |
| OK     | WIZwiki_W7500 | uARM      | MBED_11     | Ticker Int                            |       12.29        |       15      |  1/1  |
| OK     | WIZwiki_W7500 | uARM      | MBED_12     | C++                                   |        2.4         |       10      |  1/1  |
| FAIL   | WIZwiki_W7500 | uARM      | MBED_16     | RTC                                   |        5.51        |       20      |  0/1  |
| OK     | WIZwiki_W7500 | uARM      | MBED_2      | stdio                                 |        1.74        |       20      |  1/1  |
| OK     | WIZwiki_W7500 | uARM      | MBED_23     | Ticker Int us                         |        12.3        |       15      |  1/1  |
| OK     | WIZwiki_W7500 | uARM      | MBED_24     | Timeout Int us                        |        12.8        |       15      |  1/1  |
| OK     | WIZwiki_W7500 | uARM      | MBED_25     | Time us                               |       12.33        |       15      |  1/1  |
| OK     | WIZwiki_W7500 | uARM      | MBED_26     | Integer constant division             |        2.4         |       20      |  1/1  |
| OK     | WIZwiki_W7500 | uARM      | MBED_34     | Ticker Two callbacks                  |        2.39        |       20      |  1/1  |
| OK     | WIZwiki_W7500 | uARM      | MBED_A1     | Basic                                 |        2.48        |       20      |  1/1  |
| OK     | WIZwiki_W7500 | uARM      | MBED_A21    | Call function before main (mbed_main) |        2.45        |       20      |  1/1  |
| OK     | WIZwiki_W7500 | uARM      | MBED_A9     | Serial Echo at 115200                 |        2.66        |       20      |  1/1  |
| OK     | WIZwiki_W7500 | uARM      | MBED_BUSOUT | BusOut                                |        3.29        |       15      |  1/1  |
+--------+---------------+-----------+-------------+---------------------------------------+--------------------+---------------+-------+
Result: 1 FAIL / 15 OK

Completed in 182.77 sec

Build successes:
  * uARM::WIZwiki_W7500


저작자 표시
신고
이 댓글을 비밀 댓글로

mbed RPC Library porting guide for WIZwiki-W7500

Posted by 카이젠8501 카이젠8501
2015.10.08 14:42 IT 개발/mbed

mbed RPC Library porting guide for WIZwiki-W7500

Used library in this project

Modified Point

mbed rpc를 사용하기 위한 Interface는 RPC over Serial과 RPC over HTTP로 나눌 수 있다. 본 예제에서는 HTTP를 이용하여 RPC를 사용하며, mbed platform 에는 HTTPServer가 구동되고 있다. mbed rpc를 위한 Interface에 대한 자세한 정보는 Link를 참고 하기 바란다.

WIZnetInterface

HTTPServer Library에서 아래와 같은 코드를 사용하는데, WIZnetInterface에는 init()함수가 없음 —> WIZnetLibrary에 init() 함수 추가

HTTPServer/HTTPServer.cpp ( Line 50~56 )

INFO("Initializing network\n");
if (m_pEthernet->init() != 0) {
    ERR("Failed to initialize the ethernet interface !");
    delete m_pEthernet;
    m_pEthernet = NULL;
    return false;
}

mbed-rpc

공식 mbed-rpc Library에서 WIZwiki-W7500의 Pin들을 사용할 수 있도록 아래와 같이 코드를 추가 하였다.

mbed-rpc/parse_pins.cpp

#elif defined(TARGET_WIZwiki_W7500)
    if (str[0] == 'P' && str[2] == '_') {   // Px_n
        uint32_t port = str[1] - 'A';
        uint32_t pin  = str[3] - '0';       // Px_n
        uint32_t pin2 = str[4] - '0';       // Px_nn

        if (pin2 <= 9) {
            pin = pin * 10 + pin2;
        }
        return port_pin((PortName)port, pin);
#endif

WIZwiki-W7500의 Port와 Pin들은 아래와 같은 규칙으로 정의 되어 있으므로, parse_pins.cpp 에서는 PA_0와 같은 String Data를 받아 0x000과 같은 Int Data로 변환하는 동작을 수행한다.

// In PinNames.h

// W7500x PORT[5:4] + PIN[3:0])
PA_0  = 0x000,
PA_1  = 0x001,
PA_2  = 0x002,
...
PB_9  = 0x019,
PB_10 = 0x01A,
PB_11 = 0x01B,
...
PC_0  = 0x020,
PC_1  = 0x021,
PC_2  = 0x022,
...
// In PortNames.h

typedef enum {
    PortA = 0,
    PortB = 1,
    PortC = 2,
    PortD = 3,
} PortName;

mbed rpc library에 WIZwiki-W7500을 위한 코드를 추가한 후, mbed official repository에 pull request를 보내서 코드 업데이트를 요청 하였다.

Run Simple Example

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

RpcDigitalOut led1(LED1,"led1");

EthernetInterface eth;  
HTTPServer svr;

int main() {
  //Turn the LEDs off
  uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x00, 0x00}; 
  led1.write(1);

  RPC::add_rpc_class<RpcDigitalOut>();

  printf("Setting up...\n");
  eth.init(mac_addr);
  int ethErr = eth.connect();
  if(ethErr < 0)
  {
    printf("Error %d in setup.\n", ethErr);
    return -1;
  }

  svr.addHandler<HTTPRpcRequestHandler>("/rpc");

  //attach server to port 80
  svr.start(80, &eth);

  printf("Listening...\n");

  Timer tm;
  tm.start();
  //Listen indefinitely
  while(true)
  {
    svr.poll();
    if(tm.read()>.5)
    {
      tm.start();
    }
  }
}
  • 6 : 제어를 원하는 GPIO의 RPC Name 지정
  • 19~20 : ethernet interface 초기화 및 DHCP 수행
  • 27 : HTTPRpcRequestHandler 등록
  • 30 : HTTP Server Start ( TCP Server로 80포트 리슨)


저작자 표시
신고

'IT 개발 > mbed' 카테고리의 다른 글

W7500 mbed porting Guide ( 1/6 )  (0) 2015.10.08
mbed rpc interfacing with Python  (0) 2015.10.08
mbed RPC Library porting guide for WIZwiki-W7500  (0) 2015.10.08
mbed RPC  (0) 2015.10.08
[FRDM-KL25Z]WIZ550 ioShield-A Porting Guide  (0) 2014.08.20
Eclipse에서 mbed repository 연동 하기  (0) 2014.06.15
이 댓글을 비밀 댓글로