Description
ECE 3740 Systems Engineering Principles
Introduction
The Systems Engineering Principles Project 1(SEP Project 1) is implemented by the series Assignment 1, Laboratory 1, and Assignment 2. The SEP Project 1has two main objectives: the first objective is to gain experience in using the MPLAB X IDEand the MX7cK board. You will also develop C code for controlling the LEDs through the Push Buttons on the MX7cK board. Finally, you will also develop C code to receive commands to control the LEDs and monitor the Push Button switches from a telnet session running on the Host computer.
P1.1: Part 1 of the Project 1 (P1.1) requires that students perform the following:
- Install MPLAB® X IDE, MPLAB XC32 Compiler, and PIC32 Legacy
Peripheral Libraries. - Gain familiarity with using MPLAB® X to create, edit, build, debug,
and run C programs. - Install PIC TCP/IP Stack software.
- Run networking tools and programs.
- Practice Configuration Management.
- Perform refactorization by modularization.
- Write test plan and procedure documents.
P1.1 measures the following attributes:
ET.3: Engineering use of tools
- Demonstrate installing MPLAB X IDE, XC32 compiler, peripheral libraries, and
Microchip’s TCP/IP stack - Demonstrate the use of MPLAB X IDE for developing C language code for the
PIC32MX795F512L on the MX7cK board (compiling, programming, running, and
debugging projects) - Demonstrate the use of TCP/IP networking tools, such as ping.
DE.3: Design
- Design a test plan for testing proper operation of the stack software.
CS.3: Communication skills
- Demonstrate clear and accurate explanation of the project questions.
- Write test plan and procedure to test the stack operation.
The following Steps 1 – 24 are detailed instructions for performing P1.1. Students should follow them exactly:
P1.1.1
- Download MPLAB XIDE (Integrated Development Environment) from:
https://www.microchip.com/ - Download the latest version of “MPLAB® X IDE” (In 2017, it wasv3.40), and install it on your workstation. Follow the installation directions.
- You don’t need to install the Integrated Programming Environment (IPE); so, deselect the box in the Select Programs dialog.
- The final dialog box lists some documentation which may be helpful.
- Near the end of the installation, a dialog will ask you to install the XC compiler. Ensure that the “XC compilers …” box is checked, and then click “Finish.” You don’t need to check the other two boxes.
- Your browser should take you to page:
https://www.microchip.com/mplab/compilers - Click on the tab Downloads(near bottom of page) and download and install the latest version of the MPLAB XC32 Compiler (In 2017, it was v1.42).
- Check the box to agree to the disclaimer.
- Use default selections, except, additionally, check box “Add xc32 to the PATH environment variable”.
- When the installation completes, locate the MPLAB X IDE and pin the application to your taskbar.
- After you have installed the MPLAB XC32 Compiler, you must then install the peripheral libraries. In the “Downloads” section of the XC32 web page, click on the “Perhiperal Libraries (plibs)” link. Then download and install the plibs by clicking on the download icon of the “PIC32 Legacy Peripheral Libraries – Windows” link (bottom of page). Choose the defaults for the installation, and ensure the libraries are installed under the xc32 compiler folder /xc32/v(latest version number).
- On Jumper Block J3 (See 1), AKA Power Select, connect the jumper across the DBG (debug) position. This selects powering the MX7cK board using the computer’s USB port, which is connected to the board via the “J15 DEBUG” USB connector (Page 5 of 34 [1]).
- Connect the MX7cK board to the computer by connecting one side of the USB cable to the computer and the other side to the“J15 DEBUG” USB connector on the MX7cK board. NOTE: When connecting the USB cable to the MX7cK board, grasp and hold the USB connector of the board with one hand and then connect the cable to the USB connector. The USB connector on the board is glued on the board, and continued re-connection of the USB cable to the connector without adequate support may cause the connector to dislodge from the board.Switch the board ON(Fig. 1).
| POWER SWITCH |
| J3 POWER SELECT
(DBG Jumper) |
| J15 DEBUG
USB Connector |
Fig. 1. Power selector and switch (from [1]).
STARTING MPLAB
- On your computer, start MPLAB by clicking on “MPLAB X IDE” of your task bar.
CREATING A NEW PROJECT
- Create a new project
- File->New Project, and make selections as shown in Fig. 2a; click Next
- Make selections as shown in Fig. 2b; click Next
- Make selection as shown in Fig. 2c (Your board’s SN (back of board) will be identified); click Next
- Make selection as shown in Fig. 2d; click Next
- Make selections as shown in Fig. 2e; click Finish.
(a)
(b)
(c) (d)
(e)
Fig. 2. Project creation, screens (a) – (e). Project Location and Folder is C:\Users\YourName\ECE3740\MPLABXProjects\P1\P1.1\P1.1.1
CREATING SOURCE FILES
- Create a new C source file:Right click on “Source Files” and select New->Other->Categories->C->C Main File…”; Make selections as shown in Fig. 3a, and click Next.Make selection as shown in Fig. 3b; Click Finish.
- Copy the contents of the main.c file (included inECE3740P1v11.zip)and paste it to thenew file main.c in your project (i.e., replace the current contents).
- (b)
Fig. 3. Creating a new C source file.
SELECTING DEBUGGER MODE
For the ability to debug programs, placing breakpoints, stepping through statements, and watching variables, the debugger mode of operation is selected via the Debug menuon the top menu bar of MPLAB X IDE. We will be using the Debug menu.
SELECTING PROGRAMMER MODE
For the ability to upload the program into non-volatile memory, and to enable running the program upon switching power on the board, the programmer mode of operation is selected via the Run menu.
SELECTING THE DEBUGGER
- Right-click on your project (IDEBlinking) in the project window and select Properties;
- In the properties box you should see the S/N of the licensed debugger; check this number with the number located on the back of your board.
- Click and highlight it and then select Apply, followed by Ok.
COMPILING, PROGRAMMING, RUNNING, AND DEBUGGING
- Make the project by selecting Debug->Debug Project. This will compile and build the project, download the executable onto the board, and launch the Debugger and run the program. To select these functions individually, select the menu items under Debug->Discrete Debugger operation. Wait for the download to complete successfully. You should see the message “running” and LEDs on the board rotating.
- Note that any errors or warnings are displayed in the Output window. Clicking on the error in the Output window navigates to the line in error in the source file.
- Note that many warnings of the form “#warning The PLIB functions and macros in this file will be removed from the MPLAB XC32 C/C++ Compiler in future release”. To suppress these warnings, first stop debugging by clicking on the Debug->Finish Debugger Session. Then add “_SUPPRESS_PLIB_WARNING” to the preprocessor definitions in the project settings. To do this, right click on LEDBlinking in the project window, and select “Properties”. Then select “xc32-gcc” in the Categories window. Then select “Preprocessing and …” in the “Options categories” drop down box. Then click on box to the right of “Preprocessor macros”, and then enter the string _SUPPRESS_PLIB_WARNING.
- Note also that you may get warnings of the form “Warning: configport argument for OpenADC10 only works for Port B”. This warning is just Microchip trying to stop us from using their library with ADC pins on Port A, which we don’t do, so we can just ignore this warning. To remove it, add the predefined macro “_DISABLE_OPENADC10_CONFIGPORT_WARNING” to your project’s configuration options (use the same method as to suppress the plib warning above). Click on OK.
- Now build the project again and notice the warning messages are not displayed (Debug->Discrete Debugger Operation->Build for Debugging).
- You may place breakpoints at strategic locations in the code.
- Halt (Finish Debugger Session) the LEDBlinking program. Place a breakpoint at line “PORTSetBits(LED2…);” Note: a breakpoint may be set by right clicking at the desired line and then selecting “New Data Breakpoint”, or by single clicking in the left margin (beside the desired line number).
- Run the program (Debug->Debug Project). When the program stops at line “PORTSetBits(LED2…);”, view the PORTG register. (Note the PORTG register (along with the other registers) can be viewed by selecting Window->PIC Memory Views->Peripherals. Click the magnifying glass icon and search for PORTG. Note that bit 12 of PORTG is clear, due to the statement at line “PORTClearBits(LED1…);”.
- Step through (over) line “PORTSetBits(LED2…);” by selecting Debug->Step Over (or by pressing F8). Note that PORTG bit 13 becomes set and the LED2 is switched on. Try stepping over other statements and viewing the PORTG register and the LEDs.
- Note that stepping over the delay at line “for (i = 0; i < 1000000; i++);” would take a long time, since the debugger stops at each of the 1,000,000 iterations of the for loop. Instead, right click on the desired line to stop, and select “run to cursor.”
- You may also step into functions. Try selecting Debug->Step Into. Note that the file in which the function you want to step into must be opened before you can step into that function.
CONFIGURATION MANAGEMENT
This section shows how to create new versions of the program without destroying the old version, as well as how to manage different versions of the same project. To demonstrate configuration management, we will create a new version of the LED Blinking project by refactoring the code. The main.c file can be organized in an object oriented way by creating individual source files to hold the configuration bits, defines, function prototypes, etc.All items that pertain to the same concept are gathered and stored in a single file. Different files for different concepts are created for each concept.
MODULARIZATION (REFACTORING)
- The first step is to quit MPLAB.
- Then create a new folder C:\Users\ferens\ECE3740\MPLABXProjects\P1\P1.1\P1.1.1\v1, and place all the contents of the LED Blinking project \P1.1.1\ into folder\P1.1.1\v1.
- Then create another folder C:\Users\ferens\ECE3740\MPLABXProjects\P1\P1.1\P1.1.1\v2. This is where you will create the next version by refactoring the code.
- Start MPLAB X, create a new project in the v2 folder. Call the new project “LEDBlinkingMod.”
- Using the OS, copy the main.c file from the v1 folder to the v2 folder.
- Include this v2\main.c file in your new project: Right click on Source Files, select “Add existing item,” and then select the main.c file. Note very carefully: this should be the v2\main.c file.
- Do the modularization (refactoring) as suggested and shown byFig. 4. You need to figure out what should be placed in the suggested files.
Fig. 4. Workspace after modularization.
QUESTIONS
- Where are the functions PORTSetPinsDigitalOut(), PORTClearBits(), and PORTSetBits()defined? Hint look at the Help menu, and then search for the function names within files using Windows search. Which folder should you search?
- Explain what happens when you accidentally duplicate the configuration bits settings in multiple places? For instance copy the configuration bits settings from file PICConfig.h and place them in main.c. Now try the make (Debug) the project. What is wrong?
SUBMISSION INSTRUCTIONS
- For Project P1.1.1, submit the following:
- (0.75 Mark) Submit answers to Questions 14-15.
- Submit entire MPLAB X project: modularized version. The project should be zipped, as discussed in L16TPP.pdf.
- (0.25 Mark) Correct folder structure that practises “Configuration Management”, as discussed in Slide 15 of LEDBlinking.pdf.
- Submit a TPP document:
- (0.25 Mark) Successful build of project. The TA will follow the list of steps to build your project.
- (0.5 Mark) Warning messages do not appear in output window.
- (0.25 Mark) Successful run of project. The TA will follow the list of steps to run your project. The code should rotate the LEDs as the non-modularized version does.
- (1 Mark) The TA will analyze the source code for the modularization.
P1.1.2 TCP/IP STACK INSTALLATION AND UPDATE
- Unzip the Microchip’s TCP/IP Stack from the Stack.zip file (double click on Stack.zip) included in ECE3740P1v1.zip, and save the unzipped folder TCPIPStack to folder C:\Users\ferens\ECE3740\MPLABXProjects\TCPIPStackOrg.
- Copy the TCPIPStack folder to C:\Users\ferens\ECE3740\MPLABXProjects\P1\P1.1\P1.1.2\v1\.
- Note that we made two copies, the original and the current working version in the v1 folder. We do this because if anything goes wrong with the current working version, we have a backup in TCPIPStackOrg.
- Quit MPLAB X. Then Start MPLAB X.
- Open the TCP/IP demo application by Selecting File->Open Project, and browsing to folder “C:\Users\ferens\ECE3740\MPLABXProjects\P1\P1.1\P1.1.2\v1\TCPIPStack\TCPIP\Demo App” and then selecting the XC32-PIC32_ETH_SK_ETH795.mcp project file. (Close any other projects by right clicking their name and selecting “Close”.)
- As explained in [1], all devices on an Ethernet network must have a unique address. This unique address is called a MAC address, and, for this board, it is printed on a sticker attached to the bottom of the board. In addition, all devices on an Ethernet should have a default IP address and a host name. The MAC and IP default addresses are configured in the file TCPIP ETH795.h of the XC32-PIC32_ETH_SK_ETH795.mcp project. We suggest to use the host name of mxXX, and to use the default IP address of 192.168.1.XX, where XX=LSB (Least Significant Byte) of the MAC address of the board you are programming. For example, for the board which has MAC address = 00-18-3E-01-11-79 we make the following changes to the TCPIP ETH795.h file: (note that the “79” is a Hexadecimal number, which is 121 in decimal.)
#define MY_DEFAULT_HOST_NAME “mx79”
#define MY_DEFAULT_MAC_BYTE1 (0x00) // MAC address printed on back of board
#define MY_DEFAULT_MAC_BYTE2 (0x18) //
#define MY_DEFAULT_MAC_BYTE3 (0x3E) //
#define MY_DEFAULT_MAC_BYTE4 (0x01) //
#define MY_DEFAULT_MAC_BYTE5 (0x11) //
#define MY_DEFAULT_MAC_BYTE6 (0x79) //
#define MY_DEFAULT_IP_ADDR_BYTE1 (192ul)
#define MY_DEFAULT_IP_ADDR_BYTE2 (168ul)
#define MY_DEFAULT_IP_ADDR_BYTE3 (1ul)
#define MY_DEFAULT_IP_ADDR_BYTE4 (0x79ul)
#define MY_DEFAULT_MASK_BYTE1 (255ul)
#define MY_DEFAULT_MASK_BYTE2 (255ul)
#define MY_DEFAULT_MASK_BYTE3 (255ul)
#define MY_DEFAULT_MASK_BYTE4 (0ul)
#define MY_DEFAULT_GATE_BYTE1 (192ul)
#define MY_DEFAULT_GATE_BYTE2 (168ul)
#define MY_DEFAULT_GATE_BYTE3 (1ul)
#define MY_DEFAULT_GATE_BYTE4 (121ul)
#define MY_DEFAULT_PRIMARY_DNS_BYTE1 (192ul)
#define MY_DEFAULT_PRIMARY_DNS_BYTE2 (168ul)
#define MY_DEFAULT_PRIMARY_DNS_BYTE3 (1ul)
#define MY_DEFAULT_PRIMARY_DNS_BYTE4 (121ul)
- Setting up a simple network: one host computer and one MX7cK board
- In the TCPIP ETH795.h file, select only the ICMP_SERVER, DHCP_SERVER, and ANNOUNCE modules. This can be done by commenting out all other modules except for the ICMP, DHCP_SERVER, and ANNOUNCE modules. In particular, in the “Application Level Module Selection” section of the file TCPIP ETH795.h, comment out all modules except for the following:
#define STACK_USE_ICMP_SERVER // Ping transmission capability
#define STACK_USE_DHCP_SERVER // Single host DHCP server
#define STACK_USE_ANNOUNCE // Microchip Embedded Ethernet Device Discoverer
- Ensure that the host’s TCP-IP v4 configuration is set to “obtain an IP address automatically.”
- Connect an Ethernet cable between the Host’s Ethernet port and the MX7cK’s Ethernet port. Note: normally, a “cross-over” Ethernet cable must be used to connect two devices directly. However, modern hosts can detect when another device is connected through a “straight” Ethernet cable.
- The current version of this complier XC32 v 1.40 changed a flag for the linker (ld). The previous flag for the linker was “mperhiperal-libs”. To correct this, remove the “Additional options”. To do this, right click on the project name in the project window, and select “Properties”. Then select “xc32-ld” in the Categories window. Then remove the text in the “Additional options” text box.
- Build the project, program the board, and run the program: Debug->Debug Project.
- Start a command console on the Host: Start->cmd. Ping the MX7cK board by running the ping command with the IP address noted above. For example, if the IP address of the Mx7cK board is 192.168.1.79, then run: “ping 192.68.1.121 in the command window. You should see replies such as “Reply from 192.168.1.121: bytes=32 time<1ms TTL=100.
SUBMISSION INSTRUCTIONS
- For Project P1.1.2, submit the following:
- Submit entire MPLAB X project: TCP/IP Stack test. The project should be zipped, as discussed in L16TPP.pdf.
- (0.5 Mark) Correct folder structure that practises “Configuration Management”, as discussed in Slide 15 of LEDBlinking.pdf.
- Submit a TPP document.
- (0.5 Mark) Successful build of project. The TA will follow the list of steps to build your project.
- (0.5 Mark) Warning messages do not appear in output window.
- (1 Mark) Successful run of project. The TA will follow the list of steps to run your project. The TPP should include how to setup the small network and run a ping from the workstation.
- (0.5 Mark) Successful build of project. The TA will follow the list of steps to build your project.
P1.2: Part 2 of the Project 1 (P1.2) requires that students perform the following:
- Design C software, which runs on the MX7cK board, to control the LEDs through
the Push Button (PB) switches on the MX7cK board. The software should monitor
the PB switches. If a switch is held down, then the software should light the
corresponding LED. When the switch is released the corresponding LED should be
switched off. - Gain familiarity with using MPLAB® X to create, edit, build, debug,
and run C programs. - Practice Configuration Management.
- Write test plan and procedure documents.
P1.2 measures the following attributes:
ET.3: Engineering use of tools
- Demonstrate the use of MPLAB X IDE for developing C language code for the
PIC32MX795F512L on the MX7cK board (compiling, programming, running, and
debugging projects)
PA.3: Analysis
- Demonstrate an analysis of given C code to determine how to control the LEDs
through the PBs.
DE.3: Design
- Demonstrate creating C code to control the LEDs through the PBs.
- Design a test plan for testing control the LEDs through the PBs.
CS.3: Communication skills
- Demonstrate clear and accurate explanation of the project questions.
- Write test plan and procedure documents
SUBMISSION INSTRUCTIONS
- Submit an identification video recording (in .mp4 format) showing your face and student card for approximately 5 s; orally state your name and your student number.
- Submit a video recording (in .mp4 format), showing the following in the Netbeans IDE:
- Compilation
- Demonstrate pressing buttons and observing LEDs as per the requirements.
- Demonstrate other requirements you may have.
- Requirements document.
P1.3: Part 3 of the Project 1 (P1.3) requires that students perform the following:
- Design a console control (telnet) of the LEDs and Push Buttons. Create a new MPLAB project that extends P.1.2. Use the “TCP Template Server” lecture slides as a template of how to build your own TCP server application for control/monitor of the LEDs and the Push Buttons. Use telnet on the Host to connect to your TCP code, as discussed in class.
- Gain familiarity with using MPLAB® X to create, edit, build, debug,
and run C programs. - Run networking tools and programs.
- Practice Configuration Management.
- Write and submit a test plan and procedure document for P1.3.
P1.1 measures the following attributes:
ET.3: Engineering use of tools
- Demonstrate the use of MPLAB X IDE for developing C language code for the PIC32MX795F512L on the MX7cK board (compiling, programming, running, anddebugging projects)
- Demonstrate the use of TCP/IP networking tools, such as ping and telnet.
PA.3: Analysis
- Demonstrate an analysis of given C server code to determine how to create an LED server.
DE.3: Design
- Demonstrate writing C code to implement an LED server on the MX7cK board.
- Design a test plan for testing proper operation of the LED server.
CS.3: Communication skills
- Demonstrate clear and accurate explanation of the project questions and design of the LED server.
- Write test plan and procedure document to test the console control of the LED server.
SUBMISSION INSTRUCTIONS
- Submit an identification video recording (in .mp4 format) showing your face and student card for approximately 5 s; orally state your name and your student number.
- Submit a video recording (in .mp4 format), showing the following:
- Compilation of MPLAB X project
- Connection of board to your laptop
- Starting telnet on your laptop and connecting to the server
- Demonstrate getting push button states and controlling LEDs on telne Demonstrate physically pushing a button while typing commands in telnet.
References
| [1] | Digilent Inc., “Cerebott MX7cK™ Board Reference Manual,” 3 January 2012. [Online]. Available: https://www.digilentinc.com/Products/Detail.cfm?NavPath=2,396,986&Prod=CEREBOT-MX7CK. [Accessed 4 September 2012]. |
| [2] | SMSC, “SMSC – Product Information,” 23 August 2012. [Online]. Available: https://www.smsc.com/media/Downloads_Public/Data_Sheets/8720a.pdf. [Accessed 5 September 2012]. |
| [3] | Digilent Inc., “Cerebott MX7cK™ Board Schematics,” 27 August 2011. [Online]. Available: https://www.digilentinc.com/Products/Detail.cfm?NavPath=2,396,986&Prod=CEREBOT-MX7CK. [Accessed 5 September 2012]. |

