AM273x MCU+ SDK  08.05.00
Enet Lwip TCP Client Example

Introduction

Note
LwIP features are made available as is from public lwIP project. SDK configuration may only enable and exercise a subset of these features.

This example shows about how to implement simple TCP Client on LwIP networking stack using netconn interface coupled with ethernet driver (ENET)

On AM273X, we can do ethernet based communication using CPSW as HW mechanism

  • CPSW is a standard ethernet switch + port HW
  • It uses ethernet driver underneath with LwIP TCP/IP networking stack
  • CPSW can be configured in two modes: Switch or MAC. For more details, Enet CPSW Operation Modes Demo

The example does below

  • Initializes the ethernet driver for the underlying HW
  • Initializes the LwIP stack for TCP/UDP IP and Starts TCP Client task.
  • TCP Client gets server IP using UART terminal menu from USER and connect to server IP on port 8888
  • TCP client connects to server, sends data and expects the data from server.

Supported Combinations

Parameter Value
CPU + OS r5fss0-0_freertos
Toolchain ti-arm-clang
Boards am273x-evm
Example folder examples/networking/lwip/enet_cpsw_tcpclient

Configuring Syscfg

  • Following Syscfg option allows flexibility to configure memory foot print based on required use case like: Number of DMA descriptors and buffering.
  • Supported Options with default configuration
Feature Section Description

Remarks/Default Setting

Mdio Manual Mode Enable TI Networking / Enet (CPSW) Flag to enable MDIO manual mode in example. Driver support for Manual mode is enabled, so this parameter configures manual mode in the example.

Default is true. If your silicon is affected with errata i2329— MDIO interface corruption, then TI suggests to use MDIO_MANUAL_MODE as software workaround.

Enable Packet Pool Allocation TI Networking / Enet (CPSW) Flag to enable packet allocation from enet utils library. It should be disabled to avoid utils memory wastage, in case application allots packet via other mechanism. (Ex- Lwip pools)

Default is true. It is disabled for lwip based examples. If enabled size of pkt pool size depends on 'Large Pool Packet Size', 'Large Pool Packet Count', 'Medium Pool Packet Size', 'Medium Pool Packet Count', 'Small Pool Packet Size' and 'Small Pool Packet Count'.

Number of Tx Packet TI Networking / Enet (CPSW) / DMA channel config No of Tx packets required for DMA channel

Default is 16. It contributes to the size of Pkt Mem Pool, DMA ring buffer and accessories.

Number of Rx Packet TI Networking / Enet (CPSW) / DMA channel config No of Rx packets required for DMA channel

Default is 32. It contributes to the size of Pkt Mem Pool, DMA ring buffer and accessories size.

Netif instance TI Networking / Enet (CPSW) / LWIP Interface config No of netifs allocated by the example Only one netif should be set to default when more than one netif is allocated.

TCP Server using ncat tool

Ncat is a general-purpose command-line tool for reading, writing, redirecting, and encrypting data across a network. It aims to be your network Swiss Army knife, handling a wide variety of security testing and administration tasks. Ncat is suitable for interactive use or as a network-connected back end for other tools.

  • Ncat is started as server to which EVM connects.
  • Version used for this example Version 7+ ( https://nmap.org/ncat )

Steps to Run the Example

Build the example

  • When using CCS projects to build, import the CCS project for the required combination and build it using the CCS project menu (see Using SDK with CCS Projects).
  • When using makefiles to build, note the required combination and build using make command (see Using SDK with Makefiles)

HW Setup

Note
Make sure you have setup the EVM with cable connections as shown here, EVM Setup. In addition do below steps.

Create a network between EVM and host PC

  • The EVM will get an IP address using DHCP, so make sure to connect the other end of the cable to a network which has a DHCP server running.
  • To get started one can create a simple local network between the EVM and the host PC by using a home broadband/wifi router as shown below. Most such routers run a DHCP server

Local network between PC and EVM
  • To check the router connection with host PC, recommend to disconnect all other networking conenctions on the PC, sometimes you may need to disable firewall SW, and make sure the router is able to assign a IP address to your host PC
  • After we run the example on the EVM (next step), the EVM will similarly be assigned a IP address, and then host can communicate with the EVM using the assigned IP address.

Run the example

Attention
If you need to reload and run again, a CPU power-cycle is MUST
  • Launch a CCS debug session and run the example executable, see CCS Launch, Load and Run
  • You will see logs in the UART terminal as shown in the next section.
  • Note the IP address seen in the log, this is what we will use to communicate with the EVM.

Steps to execute

  1. Start TCP server using 'ncat' cmds as shown below. Below steps have been tried with a Linux Ubuntu 18.04 host PC running bash shell
  2. Install 'ncat' if not installed by doing below
    $sudo apt install ncat
  3. Invoke 'ncat' to start TCP echo server on port 8888 as below
    $ncat -e /bin/cat -kv -l 8888
  4. Then, run the example on EVM.
  5. Enter host PC IP address when example prompts on UART terminal.

Sample output for CPSW example

==========================
CPSW LWIP TCP CLIENT
==========================
Enabling clocks!
EnetAppUtils_reduceCoreMacAllocation: Reduced Mac Address Allocation for CoreId:1 From 4 To 2
Mdio_open:282
EnetPhy_bindDriver:1718
PHY 0 is alive
Starting lwIP, local interface IP is dhcp-enabled
Host MAC address: f4:84:4c:fd:a6:00
[LWIPIF_LWIP] Enet has been started successfully
[LWIPIF_LWIP] NETIF INIT SUCCESS
Enet IF UP Event. Local interface IP:0.0.0.0
Waiting for network UP ...
Cpsw_handleLinkUp:1369
MAC Port 1: link up
Network Link UP Event
Waiting for network UP ...
Enet IF UP Event. Local interface IP:192.168.1.10
Network is UP ...
TCP Client Menu:
Enter TCP server IPv4 address:(example: 192.168.101.100)
192.168.1.20
IP eneterd is: 192.168.1.20
<<<< ITERATION 1 >>>>
Connecting to: 192.168.1.20:8888
Connection with the server is established
"Greetings from Texas Instruments!" was sent to the Server
Successfully received the packet 0
Connection closed

Troubleshooting issues

  • If you see a valid, non-zero MAC address and continuosly seieing "Waiting for network UP..." prints in UART terminal
    • Make sure you see Enet IF UP Event. message, if not check the ethernet cable
    • Check the local network and check if the DHCP server is indeed running as expected
    • When using a home broadband/wifi router, its possible to check the clients connected to the DHCP server via a web browser. Check your router user manual for more details.

See Also