SmartFusion Modbus TCP Demo Using LwIP and FreeRTOS UG

Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

SmartFusion Modbus TCP Demo Using

lwIP and FreeRTOS


Users Guide
SmartFusion Modbus TCP Demo Using lwIP and FreeRTOS
Revi si on 2 2
Table of Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1 Reference Design Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Supported Modbus Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2 Modbus TCP Server on SmartFusion cSoC. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3 Modbus TCP Demo Requirement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4 Running the Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Debug Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5 References. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
List of Changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
A Product Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Customer Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Customer Technical Support Center . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Technical Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Website . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Contacting the Customer Technical Support Center . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
ITAR Technical Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Revi si on 2 3
Introduction
The SmartFusion

customizable system-on-chip (cSoC) integrates FPGA technology with the hardened


ARM

Cortex-M3 processor based microcontroller subsystem (MSS) and programmable high-


performance analog blocks built on a low power flash semiconductor process. The MSS consists of
hardened blocks, such as a 100 MHz ARM Cortex-M3 processor, peripheral DMA (PDMA), embedded
nonvolatile memory (eNVM), embedded SRAM (eSRAM), embedded FlashROM (eFROM), external
memory controller (EMC), watchdog timer, the Philips Inter-Integrated Circuit (I
2
C), serial peripheral
interface (SPI), 10/100 Ethernet controller, real-time counter (RTC), general purpose input/output (GPIO)
block, fabric interface controller (FIC), in-application programming (IAP), and system registers. The
programmable analog block contains the analog compute engine (ACE) and analog front-end (AFE),
consisting of analog-to-digital converters (ADCs), DACs, active bipolar prescalers (ABPS), comparators,
current monitors, and temperature monitors.
The ethernet media access control (MAC) in a SmartFusion cSoC is a high-speed MAC ethernet
controller with the following features:
Carrier sense multiple access with collision detection (CSMA/CD) algorithms defined by the IEEE
802.3 standard
Complies with the low-pin-count reduced media independent interface (RMII) specifications
Built in DMA controller to move data between external RAM and TX/RX FIFOs
Refer to theSmartFusion Microcontroller Subsystem Users Guide for more details on the 10/100
Ethernet MAC interface. This user guide explains how to run the demo design running the Modbus TCP
server (www.freemodbus.org) on the SmartFusion cSoC.
Modbus is an application layer messaging protocol, positioned at level 7 of the OSI model. It provides
client/server communication between the devices connected on different types of buses or networks. It is
a confirmed service protocol and offers many services specified by function codes. The Modbus function
codes are elements of Modbus Request/Reply Protocol Data Units.
Modbus is an application layer messaging protocol for client/server communication between the devices
connected on different types of buses or networks. It is currently implemented using:
TCP/IP over ethernet
Asynchronous serial transmission over a variety of media (wire: EIA/TIA-232-E, EIA-422,
EIA/TIA-485-A; fiber, radio, etc.)
Modbus PLUS, a high speed token passing network
Figure 1 illustrates the Modbus communication stack.
Figure 1 Modbus Communication Stack
MODBUS Application Layer
Modbus on TCP
TCP
IP
Ethernet II /802.3
Ethernet Physical Layer
Physical Layer
Master / Slave
EIA/TIA-232 or
EIA/TIA-485
MODBUS+ /HDLC
Other
Other
Introduction
4 Revi si on 2
The complete specification for Modbus is available at www.modbus.org.
The Modbus TCP implementation guidelines can be found in the Modbus Messaging on TCP/IP
Implementation Guide v1.0b.
The source code used for the design example in this document is from www.freemodbus.org, with
updates for the complete set of features of the Modbus layer.
This demo is designed for the SmartFusion Development Kit Board (A2F500-DEV-KIT) using lwIP and
FreeRTOS. To familiarize yourself with the Microsemi SoC Products Groups tool chain and design flow,
refer to the SmartFusion cSoC tutorials on
www.microsemi.com/soc/products/smartfusion/docs.aspx#tutorial.
Revi si on 2 5
1 Reference Design Features
The following versions of the stack are used for this demo.
1. lwIP TCP/IP stack version 1.3.2 (www.sics.se/~adam/lwip/)
2. Modbus TCP server version 1.5 (www.freemodbus.org) with enhancements for the complete
function code support as Modbus TCP server
3. FreeRTOS (www.freertos.org)
Supported Modbus Function
Based on the Free MODBUS communications stack, the reference design supports the following
Modbus functions out of the box.This design example supports all the function code required for the
Modbus slave. These function codes are verified with the Modbus conformance test tool from
www.modbus.org.
Read Input Registers (function code 0x04)
Read Holding Registers (function code 0x03)
Write Single Registers (function code 0x06)
Write Multiple Registers (function code 0x10)
Read/Write Multiple Registers (function code 0x17)
Read Coils (function code 0x01)
Write Single Coils (function code 0x05)
Write Multiple Coils (function code 0x0F)
Read Discrete Inputs (function code (0x02)
Revi si on 2 7
2 Modbus TCP Server on SmartFusion cSoC
Figure 2-1 shows the block diagram of the software stacks used in this demo design.
This demo design describes the Modbus TCP Server running on the SmartFusion Development Kit
Board and responding to the Modbus TCP client running on the development PC. The following function
codes are demonstrated on SmartFusion:
Read discrete inputs (fn code 02) for mapped global data
Read holding registers (fn code 03) for mapped global data
Read input register (fn code 04) for ACE current reading
Write multiple coils (fn code 15) for toggling the LEDs using GPIOs
Figure 2-1 Block Diagram of MODBUS TCP Server and Application on SmartFusion
Modbus TCP Server
Modbus TCP
Application
IwIP TCP/IP Stack
Firmware
SmartFusion Development Kit (HW)
FreeRTOS
Revi si on 2 9
3 Modbus TCP Demo Requirement
The SmartFusion Development Kit Board (A2F500-DEV-KIT) is issued to run the demo design. As this
demo is using the various software stacks, it is very difficult to keep them running from the internal
memories of the SmartFusion. Therefore, this demo is made to run from the external memories of the
SmartFusion Development Kit Board. Table 3-1 gives the jumper settings for the development kit to
access the external memories.
For additional information on the board, refer to the SmartFusion Development Kit Users Guide. Add the
SoftConsole installation path to the Environment Variables; for example, C:\Program
Files\Actel\SoftConsole v3.2\Sourcery-G++\bin. This is required by the host tools to create the *.bin file of
the executable from *.elf. Figure 3-1 shows the Path settings in the Environment Variables window.
Table 3-1 Jumper Settings for Accessing the External Flash and RAM
Jumper Pin Pin
JP17 2 3
JP19 2 3
JP24 1 2
JP16 2 3
Figure 3-1 Path Settings in Environment Variables
Revi si on 2 11
4 Running the Design
Download the design files from the Microsemi SoC Products Group website:
www.microsemi.com/soc/download/rsc/?f=A2F_Modbus_TCP_Ref_Design_DF.
The zipped folder for this demo design contains the following components shown in Figure 4-1.
1. A2F500: This folder consists of the Libero Verilog project for the A2F500 based SmartFusion
Development Kit Board. These project files do not work with the A2F200 based SmartFusion
Evaluation Kit Board.
The SoftConsole folder in the above directories contains a Software folder consisting of
SoftConsole projects for running the Modbus TCP/IP Server on the lwIP_1_3_2 stack on
SmartFusion and the External Flash Loader for loading images to external flash on SmartFusion
Kits.
This software works with A2F500 based SmartFusion Development Kit Board.
2. Host Tool and HostTool_ModbusClient: From the remote host, these tools are used to run this
demo.
3. Release_Images: This folder contains the GUI interface to load the Images to external flash and
execute the images from external flash. Debugging is not possible with this method. The
remainder of this section explains how to use the prebuild image that accompanies this demo.
Figure 4-1 Demo Directory Structure
Running the Design
12 Revi si on 2
4. Using the pre-build release images:
Connect the Ethernet cable and UART cable to the A2F500 Development Kit.
Program the top_level_modbus_tcp_server_A2F500.pdb using FlashPro.
Double-click the External Flash loader GUI tool (SmartFusion_Flash_Loader_V1.0.exe). This
displays the GUI for running the Modbus TCP demo (Figure 4-2).
5. From the drop-down list (Figure 4-3), select a COM port to which the A2F500-DEV-KIT is
connected.
Figure 4-2 GUI for Running the Modbus TCP Demo
Figure 4-3 COM Port Selection
SmartFusion Modbus TCP Demo Using lwIP and FreeRTOS
Revi si on 2 13
Select EMC Flash for Flash Type and Load and Run for Options (Figure 4-4). These are the
default settings for the TCP demo.
Figure 4-4 Default Settings for MODBUS TCP Demo
Running the Design
14 Revi si on 2
6. Browse for the *.elf file (FreeModbus_TCP_demo_elf_file) that is provided in the release_Images
folder, then click Start. The Command Prompt window is displayed (Figure 4-5). This programs
the external flash with the Modbus demo image and starts the demo.
7. Open a new command prompt and type the command shown in Figure 4-6 (run the Modbus
client, A2F_Modbus_TCP_Client.exe, with the IP address displayed in the above step as input):
A2F_Modbus_TCP_Client.exe 10.60.2.233.
Figure 4-5 EMC Flash Programming and Running MODBUS TCP Demo
Figure 4-6 Running the Modbus Client
SmartFusion Modbus TCP Demo Using lwIP and FreeRTOS
Revi si on 2 15
Figure 4-7 shows the current monitor values.
8. This demo shows the Modbus TCP functions for:
Reading the discrete inputs (fn code 02) for a mapped global data
Reading the holding register (fn code 03) for mapped global data
Reading the input register (fn code 04) for ACE current reading
Writing multiple coils (fn code 15) for toggling the LEDs using GPIOs. The corresponding LED
goes off as the data value shown for function 15 in Figure 4-7.
9. Vary the POT values on the A2F500-DEV-KIT. The current changes are reflected in the command
prompt window (Figure 4-7).
10. Once the test has been done, close the command prompts. This is required to close the COM
port opened by the tools.
Debug Mode
Refer to the Using UART with a SmartFusion cSoC Libero SoC and SoftConsole Flow Tutorial to
understand the flow for debugging mode.
Figure 4-7 Current Monitor Values
Revi si on 2 17
5 References
The following references were used in this document:
1. Microsemi SoC Products Group System Solutions home page:
www.microsemi.com/soc/products/solutions/default.aspx
2. Microsemi SmartFusion cSoC home page:
www.microsemi.com/soc/products/smartfusion/default.aspx
3. The Modbus Organization home page: www.modbus.org
FAQ: www.modbus.org/faq.php
Technical resources including specifications and links to free and commercial Modbus tools
and resources: www.modbus.org/tech.php
4. Wikipedia page on Modbus: http://en.wikipedia.org/wiki/Modbus
5. FreeModbus home page: www.freemodbus.berlios.de/
API Documentation: www.freemodbus.berlios.de/api/index.html
Examples using Modpoll: www.freemodbus.berlios.de/index.php?idx=1
6. Selected suggested Modbus master tools for testing and exercising the reference design:
proconX Pty Ltd Modpoll

a freeware (www.modbusdriver.com/info/LICENSE-FREE) PC
hosted command line read-only Modbus master: www.modbusdriver.com/modpoll.html
Automated Solutions Inc Modbus RTU/ASCII Master ActiveX Control and example programs:
www.automatedsolutions.com/demos/#MBACTIVEX. You can download a 30 day trial demo
version from Automated Solutions Inc:
www.automatedsolutions.com/products/modbusrtu.asp.
7. Modbus tutorials and overviews:
Automation.com introduction to the Modbus protocol: www.automation.com/resources-
tools/articles-white-papers/fieldbus-serial-bus-io-networks/introduction-to-modbus
National Instruments introduction to the Modbus protocol:
www.zone.ni.com/devzone/cda/tut/p/id/7675
AutomatedBuildings.com introduction to the Modbus protocol:
Part 1:
www.automatedbuildings.com/news/sep08/articles/cctrls/080819014909cctrls.htm
Part 2: www.automatedbuildings.com/news/dec08/articles/cctrls/081124120101cctrls.htm
8. lwIP TCP/IP stack: www.sics.se/~adam/lwip/
9. FreeRTOS stack: www.freeRTOS.org
Revi si on 2 19
List of Changes
The following table lists critical changes that were made in each revision of the chapter.
Date Changes Page
50200286-2/05.12 Replaced Figure 4-1(SAR 38390) 11
Modified the "Running the Design" section (SAR 38390) 11
50200286-1/02.12 The Figure 4-1 was updated. 11
The "Running the Design" section was revised. 11
Note: *The part number is located on the last page of the document. The digits following the slash indicate the month
and year of publication.
Revi si on 2 21
A Product Support
Microsemi SoC Products Group backs its products with various support services, including Customer
Service, Customer Technical Support Center, a website, electronic mail, and worldwide sales offices.
This appendix contains information about contacting Microsemi SoC Products Group and using these
support services.
Customer Service
Contact Customer Service for non-technical product support, such as product pricing, product upgrades,
update information, order status, and authorization.
From North America, call 800.262.1060
From the rest of the world, call 650.318.4460
Fax, from anywhere in the world, 650.318.8044
Customer Technical Support Center
Microsemi SoC Products Group staffs its Customer Technical Support Center with highly skilled
engineers who can help answer your hardware, software, and design questions about Microsemi SoC
Products. The Customer Technical Support Center spends a great deal of time creating application
notes, answers to common design cycle questions, documentation of known issues, and various FAQs.
So, before you contact us, please visit our online resources. It is very likely we have already answered
your questions.
Technical Support
Visit the Customer Support website (www.microsemi.com/soc/support/search/default.aspx) for more
information and support. Many answers available on the searchable web resource include diagrams,
illustrations, and links to other resources on the website.
Website
You can browse a variety of technical and non-technical information on the SoC home page, at
www.microsemi.com/soc.
Contacting the Customer Technical Support Center
Highly skilled engineers staff the Technical Support Center. The Technical Support Center can be
contacted by email or through the Microsemi SoC Products Group website.
Email
You can communicate your technical questions to our email address and receive answers back by email,
fax, or phone. Also, if you have design problems, you can email your design files to receive assistance.
We constantly monitor the email account throughout the day. When sending your request to us, please
be sure to include your full name, company name, and your contact information for efficient processing of
your request.
The technical support email address is [email protected].
Product Support
22 Revi si on 2
My Cases
Microsemi SoC Products Group customers may submit and track technical cases online by going to My
Cases.
Outside the U.S.
Customers needing assistance outside the US time zones can either contact technical support via email
([email protected]) or contact a local sales office. Sales office listings can be found at
www.microsemi.com/soc/company/contact/default.aspx.
ITAR Technical Support
For technical support on RH and RT FPGAs that are regulated by International Traffic in Arms
Regulations (ITAR), contact us via [email protected]. Alternatively, within My Cases, select
Yes in the ITAR drop-down list. For a complete list of ITAR-regulated Microsemi FPGAs, visit the ITAR
web page.
Revi si on 2 23
Index
C
contacting Microsemi SoC Products Group
customer service 21
email 21
web-based technical support 21
customer service 21
M
Microsemi SoC Products Group
email 21
web-based technical support 21
website 21
P
product support
customer service 21
email 21
My Cases 22
outside the U.S. 22
technical support 21
website 21
T
tech support
ITAR 22
My Cases 22
outside the U.S. 22
technical support 21
W
web-based technical support 21
50200286-2/05.12
2012 Microsemi Corporation. All rights reserved. Microsemi and the Microsemi logo are trademarks of
Microsemi Corporation. All other trademarks and service marks are the property of their respective owners.
Microsemi Corporation (NASDAQ: MSCC) offers a comprehensive portfolio of semiconductor
solutions for: aerospace, defense and security; enterprise and communications; and industrial
and alternative energy markets. Products include high-performance, high-reliability analog
and RF devices, mixed signal and RF integrated circuits, customizable SoCs, FPGAs, and
complete subsystems. Microsemi is headquartered in Aliso Viejo, Calif. Learn more at
www.microsemi.com.
Microsemi Corporate Headquarters
One Enterprise, Aliso Viejo CA 92656 USA
Within the USA: +1 (949) 380-6100
Sales: +1 (949) 380-6136
Fax: +1 (949) 215-4996

You might also like