lwip_ipv4_ipv6_echo_freertos#
Overview#
The lwip_ipv4_ipv6_echo application demonstrates a TCP and UDP echo on the lwIP TCP/IP stack with FreeRTOS. The demo can use both TCP or UDP protocol over IPv4 or IPv6 and acts as an echo server. The application sends back the packets received from the PC, which can be used to test whether a TCP or UDP connection is available.
A few notes about IPv6#
The demo generates a link-local address after the start. To send something to this (demo) address from your computer you need to specify the interface over which the demo is reachable by appending % followed by zone index.
On Windows, the zone index is a number. You can get it from the output of the ipconfig command.
On Linux, the zone index is an interface name or a number. To connect to board with address FE80::12:13FF:FE10:1511
over interface 21 on your Windows machine specify address as FE80::12:13FF:FE10:1511%21
over interface eth0 on your Linux or Mac machine specify address as FE80::12:13FF:FE10:1511%eth0
The board might support multiple ethernet ports. To connect from board to PC with link-local address FE80::1234:5678
over interface en0 - specify address as FE80::1234:5678%en0
over interface en1 - specify address as FE80::1234:5678%en1 You don’t have to append zone index in the following situations:
On boards with single ethernet port - it will be selected automatically.
On boards with multiple ethernet ports if the application enables only one them (BOARD_NETWORK_USE_DUAL_ENET not defined).
When connecting to global (routable) IPv6 address - the outgoing port will be selected based on the advertised prefix or by selecting router from the list of default routers and using the port the selected default router is attached to.
The LwIP stack is trying to get an IPv6 address automatically by neighbor discovery in the background. This takes some time. You can print all addresses using the command print_ip_cfg any time.
Tools#
It is necessary to have installed tools capable of sending and receiving data over TCP or UDP to interact with the demo.
ncat - Recommended tool. Supports both IPv4 and IPv6. It is part of nmap tools. It can be found at https://nmap.org/download.html.
nc (netcat) - Basically, the same as ncat, but a lot of antiviruses consider this a virus.
echotool - Supports only IPv4 and only for Windows. It can be obtained from https://github.com/PavelBansky/EchoTool
Prepare the Demo#
Connect a USB cable between the PC host and the OpenSDA(or USB to Serial) USB port on the target board.
Open a serial terminal on PC for OpenSDA serial(or USB to Serial) device with these settings:
115200 baud rate
8 data bits
No parity
One stop bit
No flow control
Insert the Ethernet Cable into the target board’s RJ45 port and connect it to your PC network adapter.
Configure the host PC IP address to 192.168.0.100.
Download the program to the target board.
Either press the reset button on your board or launch the debugger in your IDE to begin running the demo.
Some boards support simultaneous use of 2 ethernet ports - refer to the board settings section. In such case, you will be able to connect another PC:
Insert the Ethernet Cable into the 2nd RJ45 port and connect it to your 2nd PC network adapter.
Configure the 2nd PC IP address to 192.168.1.200.
Running the demo#
When the demo runs, the log would be seen on the terminal like: Initializing PHY…
Copyright 2022 NXP SHELL>>
There are several options what can you do. Type help command to see them all: “help”: List all the registered commands
"exit": Exit program "echo_tcp_client ip_addr port": Connects to specified server and sends back every received data. Usage: ip_addr: IPv6 or IPv4 server address port: TCP port number "echo_tcp_server port": Listens for up to 2 incoming connections and sends back every received data. Usage: port: TCP port number "echo_udp port": Waits for datagrams and sends them back. Usage: port: UDP port number "end": Ends echo_* command. "print_ip_cfg": Prints IP configuration.TCP client echo
Launch ncat -v -l -p 10001 on your computer.
Run command echo_tcp_client 192.168.0.100 10001 in demo shell.
You should see on your PC “Ncat: Connection from 192.168.0.102.”
Type some text into ncat (not demo shell) and the demo will send your line back when you hit enter.
You can terminate connection by pressing ctrl+c in ncat or typing end to demo shell.
For IPv6 just replace 192.168.0.100 with IPv6 address of your PC and zone ID.
TCP server echo
Run command echo_tcp_server 10001 in demo shell.
Launch ncat -v 192.168.0.102 10001 on your computer.
You should see on your PC “Ncat: Connected to 192.168.0.102:10001.”
Type some text into ncat (not demo shell) and the demo will send your line back when you hit enter.
You can terminate connection by pressing ctrl+c in ncat or typing end to demo shell.
For IPv6 just replace 192.168.0.102 with IPv6 address of demo FE80::12:13FF:FE10:1511%<zone ID>.
UDP echo
Run command echo_udp 10001 in demo shell.
On your computer launch ncat -v -u 192.168.0.102 10001
You should see on your PC “Ncat: Connected to 192.168.0.102:10001.”
Type some text into ncat (not demo shell) and the demo will send your line back when you hit enter.
To terminate is necessary by doing both, pressing ctrl+c in ncat and typing end to demo shell.
For IPv6 just replace 192.168.0.102 with IPv6 address of demo FE80::12:13FF:FE10:1511%<zone ID>.
Supported Boards#
EVKB-IMXRT1050
Hardware requirements
Mini/micro USB cable
Network cable RJ45 standard
EVKB-IMXRT1050 board
Personal Computer
Board settings
No special settings are required.
MIMXRT1060-EVKB
Hardware requirements
Mini/micro USB cable
Network cable RJ45 standard
MIMXRT1060-EVKB board
Personal Computer
Board settings
No special settings are required.
MIMXRT1170-EVKB
Hardware requirements
Mini/micro USB cable
Network cable RJ45 standard
MIMXRT1170-EVKB board
Personal Computer
Optional: another network cable and another PC for simultaneous use of both ethernet interfaces.
Board settings
This example can use both 1G port(J4) and 100M port(J3). No macro definition changes needed. The 100M port(J3) uses: Interface name: en0 IPv4 address: 192.168.0.102 Subnet mask: 255.255.255.0 Gateway: 192.168.0.100 The 1G port(J4) uses: Interface name: en1 IPv4 address: 192.168.1.103 Subnet mask: 255.255.255.0 Gateway: 192.168.1.200 You can check and modify these in the app.h file. Use these IP addresses accordingly when running the demo.
MIMXRT1060-EVKC
Hardware requirements
Mini/micro USB cable
Network cable RJ45 standard
MIMXRT1060-EVKC board
Personal Computer
Board settings
No special settings are required.
FRDM-IMXRT1152
Hardware requirements
FRDM-IMXRT1152 board
USB Type-C cable
RJ45 network cable
Personal Computer
Board settings
Connect the USB Type-C cable to the FRDM-IMXRT1152 USB debug connector.
Use the Gigabit Ethernet RJ45 port (J130).
Set J134 to position 1-2 for the shared
ENET_MDIO/ETH0_RDATA3routing.
EVK-MIMXRT1020
Hardware requirements
Mini/micro USB cable
Network cable RJ45 standard
EVK-MIMXRT1020 board
Personal Computer
Board settings
No special settings are required.
Note: To debug in qspiflash, following steps are needed:
Select the flash target and compile.
Set the SW8: 1 off 2 off 3 on 4 off, then power on the board and connect USB cable to J23.
Start debugging in IDE.
Keil: Click “Download (F8)” to program the image to qspiflash first then clicking “Start/Stop Debug Session (Ctrl+F5)” to start debugging.
MIMXRT1024-EVK
Hardware requirements
Mini/micro USB cable
Network cable RJ45 standard
MIMXRT1024-EVK board
Personal Computer
Board settings
No special settings are required.
Note: To debug in qspiflash, following steps are needed:
Select the flash target and compile.
Set the SW8: 1 off 2 off 3 on 4 off, then power on the board and connect USB cable to J23.
Start debugging in IDE.
Keil: Click “Download (F8)” to program the image to qspiflash first then clicking “Start/Stop Debug Session (Ctrl+F5)” to start debugging.
MIMXRT1040-EVK
Hardware requirements
Mini/micro USB cable
Network cable RJ45 standard
MIMXRT1040-EVK board
Personal Computer
Board settings
No special settings are required.
EVK-MIMXRT1064
Hardware requirements
Mini/micro USB cable
Network cable RJ45 standard
EVK-MIMXRT1064 board
Personal Computer
Board settings
No special settings are required.
MIMXRT1160-EVK
Hardware requirements
Mini/micro USB cable
Network cable RJ45 standard
MIMXRT1160-EVK board
Personal Computer
Board settings
This example uses 1G port(J4) as default. If want to test 100M port(J3), please set the macro BOARD_NETWORK_USE_100M_ENET_PORT to 1.
MIMXRT1180-EVK
Hardware requirements
Mini/micro USB cable
Network cable RJ45 standard
MIMXRT1180-EVK board
Personal Computer
Board settings
This example uses Ethernet RJ45 port J32.
FRDM-MCXA577
Hardware requirements
Type-C USB cable
RJ45 Network cable (for 100BASE-TX mode)
10BASE-T1S network adapter and cable (optional for 10BASE-T1S mode)
FRDM-MCXA577 board
Personal Computer
Board settings
Short position 2-3 on J29.
Use with 10BASE-T1S Ethernet
The example uses 100BASE-TX Ethernet over RJ45 by default. If you want to use the internal 10BASE-T1S digital PHY, redefine BOARD_NETWORK_USE_TENBASET_PHY from board.h to 1 and rebuild. Connect to a PC with a 10BASE-T1S network adapter instead of RJ45 and enable PLCA on a PC with the following parameters: - node ID: 0 (PLCA coordinator) - node count: 8 - TO timer: 32 BT - burst count: 0 - burst timer: 128 BT
FRDM-MCXE247
Hardware requirements
USB-C cable
Network cable RJ45 standard
FRDM-MCXE247 board
Personal Computer
Board settings
No special settings are required.
FRDM-RW612
Hardware requirements
USB-C cable
Network cable RJ45 standard
FRDM-RW612 board
Personal Computer
Board settings
Make sure SJ21 and SJ22 have positions 1 and 2 soldered (default).
LPCXpresso54628
Hardware requirements
Mini/micro USB cable
RJ45 Network cable
LPCXpresso54628 board
Personal Computer
Board settings
For LPCXpresso54628 V2.0:JP11 and JP12 1-2 on.
LPCXpresso54S018
Hardware requirements
Mini/micro USB cable
RJ45 Network cable
LPCXpresso54S018 board
Personal Computer
Board settings
LPCXpresso54S018M
Hardware requirements
Mini/micro USB cable
RJ45 Network cable
LPCXpresso54S018M board
Personal Computer
Board settings
For LPCXpresso54S018M V2.0:JP11, JP12, JP14 and JP15 1-2 on.
RD-RW612-BGA
Hardware requirements
Micro USB cable
Network cable RJ45 standard
RD-RW612-BGA board
Personal Computer
Board settings
Connect JP54. Load R520, R508, R505 Remove R518, R507, R506
FRDM-IMXRT1186
Hardware requirements
Type-C USB cable
Network cable RJ45 standard
FRDM-IMXRT1186 board
Personal Computer
Board settings
Short jumpers J12 (1-2) and J13 (2-3) and connect network cable to J56A.