AM261x MCU+ SDK: Enet LwIP HTTP Server On Bare Metal (No-RTOS)

| AM261x MCU+ SDK 26.00.00 |

Enet LwIP HTTP Server On Bare Metal (No-RTOS)

# 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 a simple HTTP web Server on LwIP networking stack using LwIP raw APIs on bare metal (No-RTOS) using no-rtos LwIP stack, no-rtos lwip-if and enet driver.

On AM261X, we can do ethernet based communication using CPSW peripheral

- CPSW is a IEEE 802.3 standard ethernet switch + port peripheral
- 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 the following:

- Initializes the ethernet driver for the underlying HW
- Initializes the 'NO_SYS' compiled LwIP and register event callbacks.
- Start polling for events such as Receive packets, timer event, transmit done, stack event etc.
- Web server waits for any HTTP client to send HTTP GET request on default HTTP port and sends the HTML page as a HTTP GET response

# Supported Combinations

Parameter | Value
--- | ---
CPU + OS | r5fss0-0_freertos
Toolchain | ti-arm-clang
Boards | am261x-lp, am261x-som
Example folder | source/networking/enet/core/examples/lwip/enet_cpsw_rawhttpserver

For support on am261x-lp please refer Ethernet Add-on Boards

# Packet pool configuration

To change packet pool configuration from syscfg, please refer to Ethernet Packet Pool Allocation Guidelines

# Configuring Syscfg

- Select NoRTOS in 'TI Networking' -> 'CPSW' -> 'System Integration Config' -> 'RTOS Variant'
  NoRTOS selection
- Following Syscfg option allows flexibility to configure memory footprint based on the 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) / MDIO Config | 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.
Disable Mac Port1, Disable Mac Port2 | TI Networking / Enet (CPSW) / MAC Port Config | Select which port to disable. | Default is Port1 enabled. If both Port1 and Port 2 are enabled, any port can be used and if operating in switch mode, it enables traffic switching between the two ports.
Enable Packet Pool Allocation | TI Networking / Enet (CPSW) / Packet Pool Config | 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.

# To Configure Static IP

Please refer to Ethernet LwIP TCP/IP Static IP.

# 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)
- Note to use the no-rtos variants of libraries for lwipif, lwip, notos (dpl).

## 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 connections 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.

## Sample output for CPSW example

CPSW LWIP HTTP WEB SERVER
==========================
EnetPhy_bindDriver:1718
PHY 0 is alive
Starting lwIP, local interface IP is dhcp-enabled
Host MAC address-0 : f4:84:4c:fc:33:80
[LWIPIF_LWIP] NETIF INIT SUCCESS
Enet IF UP Event. Local interface IP:0.0.0.0
Cpsw_handleLinkUp:1323
MAC Port 1: link up
Network Link UP Event
Enet IF UP Event. Local interface IP:192.168.1.10
Network is UP ...

## Steps to execute

1. Run example on EVM
2. Try to reach the EVM using ping as shown below, using a command shell on the host PC
   $ping 192.168.1.10
   "192.168.1.10" should be replaced with IP of EVM.
3. Open web browser in host PC that is on the network. Type http://192.168.1.10/index.html ("192.168.1.10" should be replaced with IP of EVM) and observe that page loads successfully, with HTTP 200 response code.

## Troubleshooting issues

- For am261x-lp, Software configures MDIO based on Board version(E1/E2) which is read from EEPROM. It expects on-board EEPROM to be pre-programmed for E2 EVMs. If EEPROM(0x51) is not programmed, the software considers EVM as "E1" version.
- If you see a valid, non-zero MAC address and continuously see "Waiting for network UP..." prints on the 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