Processor Expert UDP+DHCP/LwIP demo application for FRDM-K64F target board

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Processor Expert UDP+DHCP/LwIP demo application for FRDM-K64F target board

Processor Expert UDP+DHCP/LwIP demo application for FRDM-K64F target board

This document describes the creation of the Processor Expert LwIP demo application in KDS 3.0.0  (Processor Expert with KSDK 1.2.0) that allows communication via UDP/IP protocol within local network. There is also used DHCP protocol for leasing of the IP address in the local network (DHCP server must be available).

This demo application demonstrates how to communicate with a user application on the target board via Ethernet. This demo project can be used a starting point for user’s application.

The demo application provides the following functionality:

  • LwIP stack initialization including the DHCP (DHCP is started to lease the IP address).
  • The UDP is initialized and bind to port number 7 (receiving of broadcast is enabled)
  • When a UDP packet is received the content is processed (a command is executed):

There are supported following commands:

    • LED GREEN ON – switch the green led on (the RGB led) on the FRDM-K64F board
    • LED GREEN OFF – switch the green led off (the RGB led) on the FRDM-K64F board
    • LED BLUE ON – switch the blue led on (the RGB led) on the FRDM-K64F board
    • LED BLUE OFF – switch the blue led off (the RGB led) on the FRDM-K64F board
    • LED RED ON – switch the red led on (the RGB led) on the FRDM-K64F board
    • LED RED OFF – switch the red led off (the RGB led) on the FRDM-K64F board
    • K64FIPRQ – send the IP address that is leased by DHCP in the message “IP addr: N.N.N.N”
    • EXIT – exit the demo and stop the DHCP
  • The debug logs are enabled and accessible by using a serial terminal (UART, baudrate 115200, data 8 bits, one stop bit, no flow control).

Preparation

First of all the KDS 3.0.0 and KSDK 1.2.0 must be installed. You can find instructions in the document Kinetis Design Studio Videos, Part 1: Installation of KDS and Kinetis SDK.

LwIP stack 1.3.0 introduction

LwIP is a small independent implementation of the TCP/IP protocol suite that has been developed by Adam Dunkels at the Computer and Networks Architectures (CNA) lab at the Swedish Institute of Computer Science (SICS).

The focus of the LwIP TCP/IP implementation is to reduce resource usage while still having a full scale TCP. This making LwIP suitable for use in embedded systems with tens of kilobytes of free RAM and room for around 40-100 kilobytes of code ROM.

LwIP features:

    IP (Internet Protocol) including packet forwarding over multiple network interfaces

    ICMP (Internet Control Message Protocol) for network maintenance and debugging

    IGMP (Internet Group Management Protocol) for multicast traffic management

    UDP (User Datagram Protocol) including experimental UDP-lite extensions

    TCP (Transmission Control Protocol) with congestion control, RTT estimation and fast recovery/fast retransmit

    raw/native API for enhanced performance

    Optional Berkeley-like socket API

    DNS (Domain names resolver)

    SNMP (Simple Network Management Protocol)

    DHCP (Dynamic Host Configuration Protocol)

    AUTOIP (for IPv4, conform with RFC 3927)

    PPP (Point-to-Point Protocol)

    ARP (Address Resolution Protocol) for Ethernet

pastedImage_5.png

The UDP packets are processed through the LwIP by the following way:

pastedImage_6.png

You can find LwIP documentation on webpage http://www.nongnu.org/lwip/ or LwIP wiki pages http://lwip.wikia.com/wiki/LwIP_Wiki.

New project

The project is created in the KDS 3.0.0 by the following way:

  • New Kinetis project (KSDK 1.2.0 and Processor Expert selected) for the FRDM-K64F target board is created.
  • Clock configuration:
    • System Oscillator 0 – external oscillator 50MHz
    • New Clock configuration 6 – PEE,
    • Core Clock 100Mhz, Bus Clock 50 MHz, External Bus Clock 25Mhz, Flash clock 25MHz

pastedImage_0.png

  • LwIP library (stack) is linked to the project
  • fsl_phy_driver.c/h driver is added into the project (from MQX RTCS)
  • fsl_enet component added into the PEx project
  • fsl_debug_console component added into the PEx project. It provides debug output and it is configured by the following way:

pastedImage_0.png

  • fsl_hwtimer component added into the PEx project. It is configured for PIT timer to provide LwIP timing functionality. It is configured by the following way:

pastedImage_1.png

  • fsl_gpio_hal component added into the PEx project to provide GPIO access for pins driving RGB LED on the FRDM_K64F board.

The whole project contains following libraries, drivers and components:

pastedImage_3.png

For  compilation and linking of the project are necessary also following LwIP library paths:

"${PROJECT_KSDK_PATH}\middleware\tcpip\lwip"

"${PROJECT_KSDK_PATH}\middleware\tcpip\lwip\port"

"${PROJECT_KSDK_PATH}\middleware\tcpip\lwip\port\arch"

"${PROJECT_KSDK_PATH}\middleware\tcpip\lwip\src"

"${PROJECT_KSDK_PATH}\middleware\tcpip\lwip\src\include"

"${PROJECT_KSDK_PATH}\middleware\tcpip\lwip\src\include\ipv4"

"${PROJECT_KSDK_PATH}\middleware\tcpip\lwip\src\include\ipv4\lwip"

"${PROJECT_KSDK_PATH}\middleware\tcpip\lwip\src\include\ipv6"

"${PROJECT_KSDK_PATH}\middleware\tcpip\lwip\src\include\ipv6\lwip"

"${PROJECT_KSDK_PATH}\middleware\tcpip\lwip\src\include\lwip"

"${PROJECT_KSDK_PATH}\middleware\tcpip\lwip\src\include\netif"

"${PROJECT_KSDK_PATH}\middleware\tcpip\lwip\src\include\posix"

"${PROJECT_KSDK_PATH}\middleware\tcpip\lwip\src\include"

pastedImage_4.png

This project can be built and can be used for the LwIP demo application design.

Note:

This application has been created by using KSDK UDP echo demo project source code.

The UDP K64F app demo application code

The UDP K64F app demo project contains the following initialization code for UDP and DHCP:

/* initialization of LwIP stack */

/* Perform Sanity check of user-configurable values, and initialize all modules. */

lwip_init();

/* default IP addresses - DHCP is used */

IP4_ADDR(&fsl_netif0_ipaddr, 0,0,0,0);

IP4_ADDR(&fsl_netif0_netmask, 0,0,0,0);

IP4_ADDR(&fsl_netif0_gw, 0,0,0,0);

/* Add a network interface to the list of lwIP netifs. */

netif_add(&fsl_netif0, &fsl_netif0_ipaddr, &fsl_netif0_netmask, &fsl_netif0_gw, NULL, ethernetif_init, ethernet_input);

/* Set the network interface as the default network interface. */

netif_set_default(&fsl_netif0);

/* obtain the IP address, default gateway and subnet mask by using DHCP*/

if (dhcp_start(&fsl_netif0) != ERR_OK) {

         LWIP_DEBUGF(LWIP_DBG_ON, ("DHCP failed"));

}

/* initialize UDP on the port 7 */

udp_demo_init();

The udp_demo_init() initialize the pcb (protocol control block), bind the pcb to the port number 7 and set the callback function for receiving of UDP packets.

The demo application can be closed by using the exit command. When the command is executed the UDP is disconnected (unbound) and DHPC is stopped (leased IP address is released). The following code is executed:

/* UDP disconnect */

udp_demo_deinit();

/* finish the lease of the IP address */

dhcp_release(&fsl_netif0);

Please note, that the exit command does not cause the restart of the demo application. The application finish in a infinite loop and it does not reply on any command that is send by using UDP packet. The reset is necessary for restarting of this application.

The udp_echo_recv() callback function is used for receiving of UDP packets. This function process received data and execution of the following commands:

LED GREEN ON – switch the green led on (the RGB led) on the FRDM-K64F board

LED GREEN OFF – switch the green led off (the RGB led) on the FRDM-K64F board

LED BLUE ON – switch the blue led on (the RGB led) on the FRDM-K64F board

LED BLUE OFF – switch the blue led off (the RGB led) on the FRDM-K64F board

LED RED ON – switch the red led on (the RGB led) on the FRDM-K64F board

LED RED OFF – switch the red led off (the RGB led) on the FRDM-K64F board

K64FIPRQ – send the IP address that is leased by DHCP in the message “IP addr: N.N.N.N”

EXIT – exit the demo and stop the DHCP

Note:

The K64FIPRQ (K64F IP Request) command can be used for finding of this device in a local network. When a packet with this command is broadcasted the demo application sends the response “IP addr: N.N.N.N” and the device can communicate with demo application by using the leased IP address. See also the chapter Client demo application.

Configuration of LwIP

The default configuration of LwIP stack is available in the header file /UDP K64F app/lwip/src/include/lwip/opt.h. The UDP K64F demo application configuration parameters are available in the header file /UDP K64F app/lwip/port/lwipopts.h. There is enabled debug output (the fsl_debug_console is used) and also detailed debug for NETIF, UDP and DHCP, see the following part of the options in the lwipopts.h header file:

/*

------------------------------------

---------- Debugging options ----------

------------------------------------

*/

#define LWIP_DEBUG

. . .

/* detailed debug info for DHCP, UDP and NETIF */

#define NETIF_DEBUG                     LWIP_DBG_ON

#define UDP_DEBUG                       LWIP_DBG_ON

#define DHCP_DEBUG                      LWIP_DBG_ON

If you need not this debug output you can undefined the LWIP_DEBUG symbol and/or define the detailed debug info symbols as:

/* detailed debug info for DHCP, UDP and NETIF */

#define NETIF_DEBUG                     LWIP_DBG_OFF

#define UDP_DEBUG                       LWIP_DBG_OFF

#define DHCP_DEBUG                      LWIP_DBG_OFF

The disabling of the debug output has also impact on the code size.

The default configuration with debug output has the following code size:

'Invoking: Cross ARM GNU Print Size'

arm-none-eabi-size --format=berkeley "UDP K64F app.elf"

text         data          bss          dec          hex      filename

95308 180        75300 170788        29b24      UDP K64F app.elf

'Finished building: UDP K64F app.siz'

Teh code size without debug output is following:

arm-none-eabi-size --format=berkeley "UDP K64F app.elf"

text         data          bss          dec          hex      filename

83024 180        75252 158456        26af8      UDP K64F app.elf

'Finished building: UDP K64F app.siz'

Client demo application

The UDP client application can be created by using Eclipse Java EE IDE. I have implemented a simple client terminal application the support UDP K64F demo application commands.

This terminal application use the subnet mask and host IP address to create a broadcast IP address and send the K64FIPRQ message (command) in the UDP packet. If the FRDM-K64F target board with the demo application is connect to the local network the device send the response with IP address back to the UDP Client application. The received IP address is used for further communication by this application. When you select a command (write number and press the Enter in the terminal window) the selected command is sent and response text displayed.

Note:

You can run the application by using the Test UDP Client\Executable\TestClient_FRDM-K64F_demo.jar file or you can run the batch file Test UDP Client\Executable\TestClient_FRDM-K64F_demo.bat.

Conclusion

The LwIP stack library can be used as a static library in a Processor Expert project with embedded components (device drivers) that provides required functionality for the stack (physical layer of TCP/IP, timing and debug output). The Processor Expert allows using embedded components for rapid application development by using KSDK and therefore the demo application can be also used a starting point for customers' projects based on the K64 derivatives.

附件
评论

Hi Marek, do you have the problem that the compiler asks for the fsl_pit_driver.c and .h when compiling your source code UDP K64F app ?

Hello,

I am sorry for inconvenience, I have modified sys_arch.c program module that has been linked from KSDK 1.2.0 folder (there is used fsl_hwtimer component in Processor Expert instead of the fsl_pit_driver.c). I have updated the project. You should be able to compile the project without errors.

Best Regards,

Marek Neuzil

Hello, Marek.

I also ran into the fsl_pit_driver error. Thanks for the fix.

Now though I seem to be missing pin_mux.h

<../Sources/hardware_init.c:32:21: fatal error: pin_mux.h: No such file or directory>

How do I go about getting this? Your demo project only had the object files for this.

无评分
版本历史
最后更新:
‎09-10-2015 03:28 AM
更新人: