Enet Lwip Socket 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 BSD-Socket API coupled with ethernet driver (ENET)
On AM62PX, 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, Basic Layer 2 Switching
The example does the following:
Initializes the ethernet driver for the underlying HW
Initializes the LwIP stack for TCP/UDP IP and Starts TCP Socket Client task.
TCP Socket Client gets server IP using UART terminal menu from USER and connect to server IP on port 8888
TCP Socket Client connects to server, sends data and expects the data from server.
Supported Combinations
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) / Packet Pool Config | Flag to enable packet buffer memory allocation from enet utils library. It should be disabled to avoid utils memory wastage, in case application allots packet via other mechanism. | Default is true. 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'. EnetMem_allocEthPkt API uses this memory to allocate the DMA Ethernet packet. |
| Only Enable Packet Info Allocation | TI Networking / Enet (CPSW) / Packet Pool Config | Flag to allocate only the DMA Packet Info structures, this does not include the buffer memory. This is useful when the buffer memory is internally allocated by the application. (Ex- Lwip pools) | Default is true. If enabled "PktInfoMem Only Count" determines the number of additional DMA Packet Info structures allocated. EnetMem_allocEthPktInfoMem uses this memory to allocate empty DMA Packet Info structures. |
| Number of Tx Packet | TI Networking / Enet (CPSW) / DMA channel config | No of Tx packets required for DMA channel | Default is 16. For LwIP example, the Tx packet buffer memory is internally allocated in lwippools.h. Only the DMA Pkt Info structures are allocated via sysCfg, so this number should match the "PktInfoMem Only Count" described in the above item. To increase the Tx packet count, user needs to update the number correspondingly at "PktInfoMem Only Count" and lwippools.h and build the libs. |
| 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. Rx packet buffer memory is completely mananged with application sysCfg, this is done by using Rx custom Pbuf in LwIP. |
| 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 a server to which EVM connects.
The version used for this example Version 7+ ( https://nmap.org/ncat )
Steps to Run the Example
To Configure Static IP
Please refer to To Configure Static IP.
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
AM64X-EVM
For CPSW based example
Connect a ethernet cable to the EVM from host PC as shown below
\imageStyle{am64x_evm_lwip_example_00.png,width:30%} \image html am64x_evm_lwip_example_00.png Ethernet cable for CPSW based ethernet
AM62X-SK
For CPSW based example
Connect a ethernet cable to the EVM from host PC as shown below

AM62LX-EVM
For CPSW based example
Connect a ethernet cable to the EVM from host PC as shown below

AM243X-EVM
For CPSW based example
Connect a ethernet cable to the EVM from host PC as shown below
\imageStyle{am64x_evm_lwip_example_00.png,width:30%} \image html am64x_evm_lwip_example_00.png Ethernet cable for CPSW based ethernet
AM243X-LP
Note
AM243X-LP has two ethernet Ports which can be configured as both CPSW ports.
For CPSW based examples
Connect a ethernet cable to the AM243X-LP from host PC as shown below
\imageStyle{am243x_lp_lwip_example_00.png,width:30%} \image html am243x_lp_lwip_example_00.png Ethernet cable for CPSW based ethernet
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

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.
To enable static IP, set the static IP in the ipAddr variable in the App_setupNetif() before passing it as arguement to initiate the netif, and stop the dhcp from starting in the App_allocateIPAddress() function.
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
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
Install ‘ncat’ if not installed by doing below
$sudo apt install ncat
Invoke ‘ncat’ to start TCP echo server on port 8888 as below
$ncat -e /bin/cat -kv -l 8888
Then, run the example on EVM.
Enter host PC IP address when example prompts on UART terminal.
Sample output for CPSW example
==========================
CPSW LWIP SIMPLE SOCKET
==========================
Enabling clocks!
EnetAppUtils_reduceCoreMacAllocation: Reduced Mac Address Allocation for CoreId:0 From 4 To 1
Open MAC port 1
EnetPhy_bindDriver:1942
Open MAC port 2
EnetPhy_bindDriver:1942
PHY 0 is alive
PHY 3 is alive
Starting lwIP, local interface IP is dhcp-enabled
[LWIPIF_LWIP] NETIF INIT SUCCESS
Host MAC address-0 : 04:25:e8:65:11:21
Enet IF UP Event. Local interface IP:0.0.0.0
[LWIPIF_LWIP] Enet has been started successfully
Waiting for network UP ...
Waiting for network UP ...
Waiting for network UP ...
Cpsw_handleLinkUp:1423
MAC Port 1: link up
Network Link UP Event
Waiting for network UP ...
Waiting for network UP ...
Waiting for network UP ...
Waiting for network UP ...
Enet IF UP Event. Local interface IP:192.168.0.150
Network is UP ...
TCP socket Menu:
Enter server IPv4 address:(example: 192.168.101.100)
192.168.0.136
<<< Iteration 1 >>>>
Connecting to: 192.168.0.136:8888
Connected to host
Message to host: Greetings from Texas Instruments!
Message from host: Greetings from Texas Instruments!
Closed Socket connection
<<< Iteration 2 >>>>
Connecting to: 192.168.0.136:8888
Connected to host
Message to host: Greetings from Texas Instruments!
Message from host: Greetings from Texas Instruments!
Closed Socket connection
<<< Iteration 3 >>>>
Connecting to: 192.168.0.136:8888
Connected to host
Message to host: Greetings from Texas Instruments!
Message from host: Greetings from Texas Instruments!
Closed Socket connection
45.498s : CPU load = 1.63 %
<<< Iteration 4 >>>>
Connecting to: 192.168.0.136:8888
Connected to host
Message to host: Greetings from Texas Instruments!
Message from host: Greetings from Texas Instruments!
Closed Socket connection
<<< Iteration 5 >>>>
Connecting to: 192.168.0.136:8888
Connected to host
Message to host: Greetings from Texas Instruments!
Message from host: Greetings from Texas Instruments!
Closed Socket connection
50.499s : CPU load = 1.76 %
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 cableCheck 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.