Ethernet Web Server Getting Started Application on SAMA7G54-EK Evaluation Kit
Download
Description
This application demonstrates the ability of the MPLAB Harmony to configure demo board as TCP IP web server. The demo board configured as web server will host webpage stored in SDCARD. The Webpage will be accessed through IP Address provided in debug window. From the webpage, LEDs on the demo board will be controlled. Temperature is read from the temp sensor on a Thermo 3 Click connected to the board using TWI/I2C protocol. The temperature value is also displayed on the webpage.
Key Highlights of SAMA7G54-EK Evaluation Kit:
- External Non-Volatile Memories like QSPI, e.MMC and SD card interfaces.
- Additional sensors can be interfaced using “click boards” through an on-board mikroBUS connector.
- Two mechanical programmable buttons.
- One User Input Switch and one RGB LED.
- UART, USB and CAN Interfaces.
- Raspberry pi connectors.
Modules/Technology Used:
- Peripheral Modules
- FLEXCOM
- TC0
- SDMMC
Hardware Used:
- SAMA7G54-EK Evaluation Kit.
- SD Card.
- Thermo 3 Click.
- RJ45 Ethernet Cable.
Jumper Settings:
Software/Tools Used:
This project has been verified to work with the following versions of software tools:
Refer Project Manifest present in harmony-manifest-success.yml under the project folder firmware/src/config/default to know the MPLAB® X IDE, MCC Plugin, libraries version.
Hardware Setup:
- Connect RJ45 ethernet cable to the J5 Connector (Gigabit Ethernet port) of SAMA7G54-EK Evaluation Kit and to Router.
- Connect Thermo 3 click board to the J10 connector (mikroBUS socket) of SAMA7G54-EK Evaluation Kit.
- Power up the SAMA7G54-EK Evaluation Kit by connecting 5V/2A power adapter to J1 connector or by connecting micro-usb cable to J7 connector.
- Press the start (nSTART switch) button on the board.
- Connect the UART port (J24) on board to the computer using a micro-usb cable (to enable debug com port).
- Connect external JTAG debugger to J27 or Onboard debugger micro-usb cable to J24. J24 will work as CDC COM Port as well as Onboard debugger.
Developing a Ethernet Web Server demo application
Details
- Open MPLAB® X IDE from the main menu.
- Create a New Project by clicking the New Project icon or by selecting File -> New Project.
-
In the New Project window, under Projects: select 32-Bit MCC Harmony Project and click Next.
-
In the Framework Path, enter the path of the folder where you would like to download the Harmony 3 framework packages and Click Next.
-
In the Project Settings dialog window, fill in or select the information needed for below:
a. Location: Enter a valid path to store the application project.
b. Folder: Enter Project Folder name.
c. Name: Enter Project Name.
d. Path: Selecting the above fields auto populates the Path.
e. Click Next
-
In the Configuration Settings dialog window, fill in or select the information for below:
a. Name: Fill configuration name as default.
b. Device Family: From drop down list select SAM.
c. Target Device: From drop down list select SAMA7G54.
d. Click Finish.
-
This creates an empty project and set this project as main project. If there are other projects open in the project explorer window, set this project as main project by right clicking on the project, choose Set as Main Project.
-
Once the project is created, MCC will be automatically launched. (To launch MCC manually, from main menu, click on Tools -> Embedded -> MPLAB® Code Configurator or click MCC button in the MPLAB® X IDE tool bar.) It will launch Content manger Wizard. Then click Select MPLAB Harmony.
-
In addition to the required packages(csp,dev_packs), download the optional packages bsp, core, net, wolfssl and then click Finish. Content download will take some time. Please wait till all the contents are downloaded.
-
Once the download is complete, click Save in Save MCC Configuration file window.
-
Now a project graph will be displayed. From Device Resources window, click add button to add Board Support Packages for SAMA7G5 Evaluation kit BSP to Project Graph.
-
In Project Graph, Select TCP/IP Configuration from plugins drop-down list.
-
Now TCP/IP Configuration window will be displayed. Click Application in TCP/IP Layers on the left side pane.
-
To add DHCP CLIENT to Active Components window, drag and drop it from Available Components. Click Yes for adding Harmony Core.
-
Click No for FreeRTOS component. This example is a Bare metal project.
-
DHCP CLIENT is moved to Active Components window.
-
Similarly add DNS CLIENT, HTTPNET SERVER and SNTP to Active Components window.
-
Click Presentation in TCP/IP Layers on the left side pane.
a. Add Presentation Layer to Active Components window by dragging and dropping it from Available Components window.
-
Click Transport in TCP/IP Layers on the left side pane.
-
Add TCP to Active Components window by dragging and dropping it from Available Components window. This will add Crypto Library also to the project.
a. Click Yes to add Crypto Library. The wolfCrypt Library will be added to the project.
b. Click Yes to add wolfCrypt Library.
c. Click Yes to connect Crypto Library and wolfCrypt Library in project graph.
d. TCP added to project.
-
Add UDP to Active Components window by dragging and dropping from Available Components window.
-
Click Network in TCP/IP Layers on the left side pane.
-
Add IPv4, ARP and ICMPv4 to Active Components window by dragging and dropping them from Available Components window.
-
Click Data Link in TCP/IP Layers on the left side pane.
-
Click next to Network Interface in Active Components window to add an Interface. This will add NETCONFIG-0 to Network Interface section in Active Components window.
-
Add GMAC0 to MAC section in Active Components window by dragging and dropping from MAC Components window.
-
Add KSZ9131 and MIIM Driver to PHY section in Active Components window by drag and drop from PHY Components window.
-
Connect NETCONFIG-0 with GMAC0 and GMAC0 with KSZ9131 in Active Components window by clicking and dragging the or button.
-
Click Basic Config in TCP/IP Layers on the left side pane.
-
Add TCPIP CMD to Active Components window by dragging and dropping from Available Components window.
-
Click Overview on the left side pane to see the complete configuration.
-
Click Config Summary on the left side pane to see the summary of configuration. The missing mandatory and optional components will be listed here.
-
Add Harmony components listed in Unsatisfied Dependencies.
a. Close TCP/IP Configuration window.
b. In Project Graph, Select Root in View: tab and add all Unsatisfied Dependencies. -
We need SDCARD to store webpages. To access SDCARD, we need to enable SDMMC module in project.
a. From Device Resources window, expand Peripherals and expand SDMMC to view SDMMC list. -
Click add button to add SDMMC1 to Project Graph.
-
SDMMC1 added to Project Graph window.
- From Device Resources window, expand System Services to view the list.
-
Click add button to add COMMAND, DEBUG, TIME and FILE SYSTEM to Project Graph.
-
COMMAND, DEBUG, TIME and FILE SYSTEM are added to Project Graph window.
-
Add SYS_CONSOLE dependency.
a. Right Click on SYS_CONSOLE button on TCP/IP STACK box.
b. Select Satisfiers → CONSOLE. -
Add COMMAND and DEBUG System Service to CONSOLE.
a. Right Click on SYS_CONSOLE button on DEBUG box.
b. Select Satisfiers → CONSOLE.
c. Right Click on SYS_CONSOLE button on COMMAND box.
d. Select Satisfiers → CONSOLE.
-
Add SDHC consumers.
a. Right Click on SDHC button on SDMMC1 box.
b. Select consumers → SDMMC.
-
Add SDMMC consumers.
a. Right Click on DRV_MEDIA button on SDMMC box.
b. Select consumers → FILE SYSTEM.
-
Add TIME satisfiers.
a. Right Click on TMR button on TIME box.
b. Select Satisfiers → TC0.
-
From Device Resources window, expand Peripherals and expand FLEXCOM to view FLEXCOM list.
a. Click add button to add FLEXCOM3 and FLEXCOM9 to Project Graph.
-
FLEXCOM3 and FLEXCOM9 added to Project Graph window.
-
In SAMA7G54-EK Evaluation Kit, Debug UART is connected to FLEXCOM3 peripheral module.
a. To add UART consumers, Right Click on UART button on FLEXCOM3 box.
b. Select consumers → CONSOLE.
-
In SAMA7G54-EK Evaluation Kit, Thermo 3 click board is connected to MikroBUS 1 Slot. I2C communication Protocol is required to access Thermo 3 click board. The I2C/TWI lines of MikroBUS 1 Slot are connected to FLEXCOM9 peripheral module.
a. To add I2C consumers, Right Click on I2C button on FLEXCOM9 box.
b. Select consumers → I2C.
-
Add wolfCrypt Library consumers.
a. Right Click on LIB_WOLFCRYPT button on wolfCrypt Library box.
b. Select consumers → wolfSSL Library.
c. Right Click on TLS Provider button on TCP/IP STACK box.
d. Select Satisfiers → wolfSSL Library.
-
Update the System Heap size and all other Stack Size.
a. Select the System in the Project Graph window.
b. In Configuration Options window, update the System Heap size and all other Stack Size as shown in the image below.
-
Start Clock Configuration from Plugins drop-down menu.
-
Verify the clock configuration. The application demo can work with default clock configuration.
a. Verify the Processor Clock (CPU_CLK) is 800,000,000 Hz.
b. Verify the Master Clock (MCK0) is 200,000,000 Hz.
c. Verify the Peripheral Clocks are enabled for FLEXCOM3, FLEXCOM9, GMAC0, SDMMC1 and TC0. Select the System in the Project Graph window. In Configuration Options, expand Clock then expand Peripheral Clocks.
d. GMAC0 requires 125,000,000 Hz clock frequency. We need to use ETHPLL as clock source. To Enable ETHPLL, select the System in the Project Graph window. In Configuration Options, expand Clock then expand ETHPLL. Now click on the check box of Enable PLL and update the value as shown below.
e. Enable GMAC0 clock. Select the System in the Project Graph window. In Configuration Options, expand Clock then expand Generic Clocks.
f. Expand GMAC0 and click on Enable check box. Update GCLKCSS as ETHPLL.
g. Enable SDMMC1 clock. Select the System in the Project Graph window. In Configuration Options, expand Clock then expand Generic Clocks.
h. Expand SDMMC1 and Click on Enable check box. Update GCLKCSS as MAINCK.
- Start interrupt Configuration from Plugins drop-down menu.
a. Verify whether FLEXCOM3, FLEXCOM9, GMAC0, SDMMC1 and TC0_CH0 interrupt is enabled.
-
Start Pin Configuration from Plugins drop-down menu.
a. Refer to the SAMA7G54-EK User’s Guide for the UART pins.
b. Configure the pins for UART as shown below.
c. Refer to the SAMA7G54-EK User’s Guide for TWI pins.
d. Configure the pins for TWI as shown below.
e. Configure the pins for SDMMC1 as shown below.
f. Refer to Gigabit Ethernet Interface Schematic in SAMA7G54-EK User’s Guide for the GMAC0 pins
g. Configure the pins for GMAC0 as shown below. -
Update HTTPNET SERVER Listening port and default HTTP NET file.
a. In Project Graph window, Select APPLICATION LAYER from the list in view: tab.
b. Click on HTTPNET SERVER box in Project Graph.
c. In Configuration Options, in HTTPNER SERVER expand Advanced Settings. Update Default HTTP NET file as index.html and update HTTP NET Listening Port as 443.
-
Enable Encryption setting.
a. In Project Graph window, Select PRESENTATION LAYER from the list in view: tab.
b. Click on Presentation Layer box in Project Graph.
c. In Configuration Options window, Enable Support Encryption? by clicking on the check box.
d. In Configuration Options window, expand Support Encryption? Update Encryption Provider as WolfSSL from list and enable Support Server Encryption? by clicking on the check box.
-
Update TCP/IP stack Dynamic RAM Size to 92160.
a. In Project Graph window, select BASIC CONFIGURATION from the list in view: tab.
b. Click on TCPIP CORE box in Project Graph.
c. In Configuration Options, expand Heap Configuration and update TCP/IP stack Dynamic RAM Size to 92160. -
Update KSZ9131 PHY Address to 7.
a. In Project Graph window, select DATA LINK LAYER from the list in view: tab.
b. Click on KSZ9131 box in Project Graph.
c. In Configuration Options window, in KSZ9131 Update PHY Address to 7. -
Now Save all. Then click generate code. This will generate code for all the Device Resource that have been added in the project graph.
-
Up to this point in the project creation process, you used MPLAB Code Configurator (MCC) to configure and generate code to initialize the device (SAMA7G54).
Refer initialization.c to find that all the device resource added in the project graph got initialized. All that is left is for the user to write the application code in the app.c file. Documentation for each of the peripheral libraries or driver libraries can be accessed as follows:
a. Peripheral libraries APIs can be accessed as a HTML file (.html) from the Harmony 3 Framework path. (/framework_path/csp/docs/index.html)
b. BSP libraries APIs can be found in bsp.h
c. TCP/IP Stack APIs can be accessed as a HTML file (.html) from the Harmony 3 Framework path. (/framework_path/net/docs/index.html) - APIs used for this application are as follows:
- LED_GREEN_On
- LED_GREEN_Off
- LED_Red_On
- LED_Red_Off
- LED_Blue_On
- LED_Blue_Off
- FLEXCOM9_TWI_CallbackRegister
- FLEXCOM9_TWI_Write
- FLEXCOM9_TWI_IsBusy
- FLEXCOM9_TWI_Read
- SYS_FS_Mount
- TCPIP_STACK_Status
- SYS_CONSOLE_PRINT
- SYS_CONSOLE_MESSAGE
- TCPIP_STACK_NumberOfNetworksGet
- TCPIP_STACK_NetAddress
- TCPIP_STACK_NetNameGet
- TCPIP_STACK_NetIsReady
- TCPIP_STACK_IndexToNet
-
Sample code can be found here app, http net app, http net print, main and Its header file can be found here app, http net print.
-
Now right click on the project and click Properties. For Connected Hardware Tool -> select connected hardware debugger used, for Compiler Toolchain -> select XC32 and click Apply.
-
From J-32/J-Link, In Option categories choose Communication and for JTAG Method, select 4-wire JTAG.
-
Select bootstrap from Categories and select the Use Bootstrap checkbox. For bootstrap file -> select the at91bootstrap.elf file from here- Click on Apply and OK.
-
By default, MPLAB X only produces ELF and Hex format output files. To generate application output in binary format, a post build step needs to be added to the project properties. To do this, right click on project and select properties, select building, click the check box Execute this line after build, then enter the below command.
${MP_CC_DIR}/xc32-objcopy -O binary ${DISTDIR}/${PROJECTNAME}.${IMAGE_TYPE}.elf ${DISTDIR}/harmony.bin
Click on Apply and OK.
-
Clean and build the project. You should see a message on the output console that the project was successfully built. This completes the development of the ethernet web server getting started application.
- The harmony.bin binaries will be available at ./firmware/sama7g54_ek.X/dist/default/production.
Debugging Application Project on MPLAB® X IDE:
- Open the project (sama7g54_ek_ethernet_web_server_getting_started/firmware/sama7g54_ek.X) in MPLAB® X IDE.
- In the project properties, ensure SAMA7G54 is selected as the Device and for Connected Hardware Tool, select the hardware debugger connected to the board to program/debug the application.
- Build and debug the code by clicking on the Debug button in MPLAB® X IDE tool bar.
- Run the application by clicking the run button in MPLAB® X IDE tool bar.
- Ensure Console Serial communications between the Host PC and the SAMA7G54-EK Evaluation Board take place through UART port J24. A terminal emulation program running on the Host PC communicates with the SAMA7G54-EK Evaluation Kit UART port. Ensure the terminal emulation program (Eg: Tera term) is configured to the COM port and settings are:
- Speed: 115200
- Data: 8
- Parity: None
- Stop Bits: 1
- Once the board is powered up, you will see the Blue LED turn ON. The following message is displayed on the console:
Running the pre-built harmony application from SD Card:
The pre-built application bin file can be programmed by following the below steps.
Steps to program the bin file on SD card
- Take an SD Card formatted with FAT32 file system.
- Copy the boot.bin, harmony.bin files from this location to the SD card.
- Copy the webpage files from this location also to the SD card.
- Insert the SD card to J4 on the SAMA7G54-EK Evaluation Kit.
Steps to run the bin file from SD card
- Press the reset button.
- The following debug messages will be displayed on the console. Note the IP Address.
- Enter the IP Address (Example: https://10.40.24.92) in web browser and press enter. The following webpage will be displayed on your browser.
- Now control each LED from webpage and view LED status updated. View the temperature displayed on the webpage.
Comments:
- This application demo builds and works out of the box by following the instructions above in “Running the Demo” section- If you need to enhance/customize this application demo, you need to use the MPLAB® Harmony v3 Software framework- Refer links below to setup and build your applications using MPLAB® Harmony.
- How to Setup MPLAB® Harmony v3 Software Development Framework
- MPLAB® Harmony v3 is also configurable through MPLAB® Code Configurator (MCC)- Refer to the below links for specific instructions to use MPLAB® Harmony v3 with MCC.
Revision:
- v1.6.0 - Released demo application